perlfunc > 5.14.1 との差分

perlfunc 5.14.1 と 5.24.1 の差分

11
22=encoding euc-jp
33
44=head1 NAME
55X<function>
66
77=begin original
88
99perlfunc - Perl builtin functions
1010
1111=end original
1212
1313perlfunc - Perl 組み込み関数
1414
1515=head1 DESCRIPTION
1616
1717=begin original
1818
1919The functions in this section can serve as terms in an expression.
2020They fall into two major categories: list operators and named unary
2121operators. These differ in their precedence relationship with a
2222following comma. (See the precedence table in L<perlop>.) List
2323operators take more than one argument, while unary operators can never
2424take more than one argument. Thus, a comma terminates the argument of
2525a unary operator, but merely separates the arguments of a list
2626operator. A unary operator generally provides scalar context to its
2727argument, while a list operator may provide either scalar or list
28contexts for its arguments. If it does both, scalar arguments
28contexts for its arguments. If it does both, scalar arguments
2929come first and list argument follow, and there can only ever
30be one such list argument. For instance, splice() has three scalar
30be one such list argument. For instance,
31arguments followed by a list, whereas gethostbyname() has four scalar
31L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> has three scalar arguments
32arguments.
32followed by a list, whereas L<C<gethostbyname>|/gethostbyname NAME> has
33four scalar arguments.
3334
3435=end original
3536
3637この節の関数は、式の中で項として使うことができます。
3738これらは、大きく二つに分けられます:
3839リスト演算子と名前付き単項演算子です。
39これらの違いは、その後に出て来るコンマとの優先順位の関係にあります。 
40これらの違いは、その後に出て来るコンマとの優先順位の関係にあります。
4041(L<perlop> の優先順位の表を参照してください。)
4142リスト演算子は 2 個以上の引数をとるのに対して、単項演算子が複数の引数を
4243とることはありません。
4344つまり、コンマは単項演算子の引数の終わりとなりますが、リスト演算子の
4445場合には、引数の区切りでしかありません。
4546単項演算子は一般に、引数に対してスカラコンテキストを与えるのに対して、
4647スカラ演算子の場合には、引数に対してスカラコンテキストを与える場合も、
4748リストコンテキストを与える場合もあります。
4849一つのリスト演算子が両方のコンテキストを与える場合には、スカラ引数が
4950いくつか並び、最後にリスト引数が一つ続きます;
5051そしてそのようなリスト引数は一つだけしかありません。
51たとえば、splice() は三つのスカラ引数に一つのリスト引数が続きます。
52たとえば、L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> は三つのスカラ引数に
52方 gethostbyname() は四つのスカラ引数を持ちます
53一つの引数が続きます;
54一方 L<C<gethostbyname>|/gethostbyname NAME> は四つのスカラ引数を持ちます。
5355
5456=begin original
5557
5658In the syntax descriptions that follow, list operators that expect a
5759list (and provide list context for elements of the list) are shown
5860with LIST as an argument. Such a list may consist of any combination
5961of scalar arguments or list values; the list values will be included
6062in the list as if each individual element were interpolated at that
6163point in the list, forming a longer single-dimensional list value.
6264Commas should separate literal elements of the LIST.
6365
6466=end original
6567
6668後に載せる構文記述では、リストをとり (そのリストの要素にリストコンテキストを
67与える)リスト演算子は、引数として LIST をとるように書いています
69与える)リスト演算子は、引数として LIST をとるように書いています;
6870そのようなリストには、任意のスカラ引数の組み合わせやリスト値を
6971含めることができ、リスト値はリストの中に、個々の要素が展開されたように
7072埋め込まれます。
71731 次元の長いリスト値が形成されることになります。
7274LIST のリテラルな要素は、コンマで区切られます。
7375
7476=begin original
7577
7678Any function in the list below may be used either with or without
7779parentheses around its arguments. (The syntax descriptions omit the
78parentheses.) If you use parentheses, the simple but occasionally
80parentheses.) If you use parentheses, the simple but occasionally
7981surprising rule is this: It I<looks> like a function, therefore it I<is> a
8082function, and precedence doesn't matter. Otherwise it's a list
8183operator or unary operator, and precedence does matter. Whitespace
8284between the function and left parenthesis doesn't count, so sometimes
8385you need to be careful:
8486
8587=end original
8688
8789以下のリストの関数はすべて、引数の前後の括弧は省略可能となっています。
8890(構文記述では省略しています。)
8991括弧を使うときには、単純な、(しかし、ときには驚く結果となる規則が
9092適用できます:
9193I<関数に見える>ならば、I<それは関数>で、優先順位は関係ありません。
9294そう見えなければ、それはリスト演算子か単項演算子で、優先順位が関係します。
9395関数と開き括弧の間の空白は関係ありませんので、ときに
9496気を付けなければなりません:
9597
9698 print 1+2+4; # Prints 7.
9799 print(1+2) + 4; # Prints 3.
98100 print (1+2)+4; # Also prints 3!
99101 print +(1+2)+4; # Prints 7.
100102 print ((1+2)+4); # Prints 7.
101103
102104=begin original
103105
104If you run Perl with the B<-w> switch it can warn you about this. For
106If you run Perl with the L<C<use warnings>|warnings> pragma, it can warn
105example, the third line above produces:
107you about this. For example, the third line above produces:
106108
107109=end original
108110
109Perl に B<-w> スイッチを付けて実行すれば、こういったものには警告を
111Perl に L<C<use warnings>|warnings> プラグマを付けて実行すれば、
110出してくれます。
112こういったものには警告を出してくれます。
111113たとえば、上記の三つめは、以下のような警告が出ます:
112114
113115 print (...) interpreted as function at - line 1.
114116 Useless use of integer addition in void context at - line 1.
115117
116118=begin original
117119
118120A few functions take no arguments at all, and therefore work as neither
119unary nor list operators. These include such functions as C<time>
121unary nor list operators. These include such functions as
120and C<endpwent>. For example, C<time+86_400> always means
122L<C<time>|/time> and L<C<endpwent>|/endpwent>. For example,
121C<time() + 86_400>.
123C<time+86_400> always means C<time() + 86_400>.
122124
123125=end original
124126
125127いくつかの関数は引数を全くとらないので、単項演算子としても
126128リスト演算子としても動作しません。
127このような関数としては C<time> や C<endpwent> があります。
129このような関数としては L<C<time>|/time>L<C<endpwent>|/endpwent>
130あります。
128131例えば、C<time+86_400> は常に C<time() + 86_400> として扱われます。
129132
130133=begin original
131134
132135For functions that can be used in either a scalar or list context,
133136nonabortive failure is generally indicated in scalar context by
134137returning the undefined value, and in list context by returning the
135138empty list.
136139
137140=end original
138141
139142スカラコンテキストでも、リストコンテキストでも使える関数は、致命的でない
140143エラーを示すために、スカラコンテキストでは未定義値を返し、
141144リストコンテキストでは空リストを返します。
142145
143146=begin original
144147
145148Remember the following important rule: There is B<no rule> that relates
146149the behavior of an expression in list context to its behavior in scalar
147150context, or vice versa. It might do two totally different things.
148151Each operator and function decides which sort of value would be most
149152appropriate to return in scalar context. Some operators return the
150153length of the list that would have been returned in list context. Some
151154operators return the first value in the list. Some operators return the
152155last value in the list. Some operators return a count of successful
153156operations. In general, they do what you want, unless you want
154157consistency.
155158X<context>
156159
157160=end original
158161
159162以下に述べる重要なルールを忘れないで下さい: リストコンテキストでの
160163振る舞いとスカラコンテキストでの振る舞いの関係、あるいはその逆に
161164B<ルールはありません>。
1621652 つの全く異なったことがあります。
163166それぞれの演算子と関数は、スカラコンテキストでは、もっとも適切と
164167思われる値を返します。
165168リストコンテキストで返す時のリストの長さを返す演算子もあります。
166169リストの最初の値を返す演算子もあります。
167170リストの最後の値を返す演算子もあります。
168171成功した操作の数を返す演算子もあります。
169172一般的には、一貫性を求めない限り、こちらが求めることをします。
170173X<context>
171174
172175=begin original
173176
174177A named array in scalar context is quite different from what would at
175178first glance appear to be a list in scalar context. You can't get a list
176179like C<(1,2,3)> into being in scalar context, because the compiler knows
177180the context at compile time. It would generate the scalar comma operator
178there, not the list construction version of the comma. That means it
181there, not the list concatenation version of the comma. That means it
179182was never a list to start with.
180183
181184=end original
182185
183186スカラコンテキストでの名前付き配列は、スカラコンテキストでのリストを
184187一目見たものとは全く違います。
185188コンパイラはコンパイル時にコンテキストを知っているので、
186189C<(1,2,3)> のようなリストをスカラコンテキストで得ることはできません。
187これはスカラコンマ演算子を生成し、コンマのリスト作成版ではありません。
190これはスカラコンマ演算子を生成し、コンマのリスト結合版ではありません。
188191これは初めからリストであることはないことを意味します。
189192
190193=begin original
191194
192In general, functions in Perl that serve as wrappers for system calls ("syscalls")
195In general, functions in Perl that serve as wrappers for system calls
193of the same name (like chown(2), fork(2), closedir(2), etc.) return
196("syscalls") of the same name (like L<chown(2)>, L<fork(2)>,
194true when they succeed and C<undef> otherwise, as is usually mentioned
197L<closedir(2)>, etc.) return true when they succeed and
195in the descriptions below. This is different from the C interfaces,
198L<C<undef>|/undef EXPR> otherwise, as is usually mentioned in the
196which return C<-1> on failure. Exceptions to this rule include C<wait>,
199descriptions below. This is different from the C interfaces, which
197C<waitpid>, and C<syscall>. System calls also set the special C<$!>
200return C<-1> on failure. Exceptions to this rule include
198variable on failure. Other functions do not, except accidentally.
201L<C<wait>|/wait>, L<C<waitpid>|/waitpid PID,FLAGS>, and
202L<C<syscall>|/syscall NUMBER, LIST>. System calls also set the special
203L<C<$!>|perlvar/$!> variable on failure. Other functions do not, except
204accidentally.
199205
200206=end original
201207
202208一般的に、同じ名前のシステムコールのラッパーとして動作する Perl の関数
203(chown(2), fork(2), closedir(2) など)は、以下に述べるように、
209(L<chown(2)>, L<fork(2)>, L<closedir(2)> など)は、以下に述べるように、
204成功時に真を返し、そうでなければ C<undef> を返します。
210成功時に真を返し、そうでなければ L<C<undef>|/undef EXPR> を返します。
205211これは失敗時に C<-1> を返す C のインターフェースとは違います。
206このルールの例外は C<wait>, C<waitpid>, C<syscall> です。
212このルールの例外は L<C<wait>|/wait>, L<C<waitpid>|/waitpid PID,FLAGS>,
207システムコールは失敗時に特殊変数 C<$!> をセットします。
213L<C<syscall>|/syscall NUMBER, LIST> です。
214システムコールは失敗時に特殊変数 L<C<$!>|perlvar/$!> をセットします。
208215その他の関数は、事故を除いて、セットしません。
209216
210217=begin original
211218
212219Extension modules can also hook into the Perl parser to define new
213220kinds of keyword-headed expression. These may look like functions, but
214221may also look completely different. The syntax following the keyword
215222is defined entirely by the extension. If you are an implementor, see
216223L<perlapi/PL_keyword_plugin> for the mechanism. If you are using such
217224a module, see the module's documentation for details of the syntax that
218225it defines.
219226
220227=end original
221228
222229エクステンションモジュールは、新しい種類のキーワードが頭に付いた式を
223230定義するために Perl パーサをフックできます。
224231これらは関数のように見えるかもしれませんが、全く別物かもしれません。
225232キーワード以降の文法は完全にエクステンションによって定義されます。
226233もしあなたが実装者なら、この機構については L<perlapi/PL_keyword_plugin> を
227234参照してください。
228235もしあなたがそのようなモジュールを使っているなら、
229236定義されている文法の詳細についてはモジュールの文書を参照してください。
230237
231238=head2 Perl Functions by Category
232239X<function>
233240
234241(カテゴリ別の Perl 関数)
235242
236243=begin original
237244
238245Here are Perl's functions (including things that look like
239246functions, like some keywords and named operators)
240247arranged by category. Some functions appear in more
241248than one place.
242249
243250=end original
244251
245252以下に、カテゴリ別の関数(キーワードや名前付き演算子のような、
246253関数のように見えるものも含みます)を示します。
247254複数の場所に現れる関数もあります。
248255
249256=over 4
250257
251258=item Functions for SCALARs or strings
252259X<scalar> X<string> X<character>
253260
254261(スカラや文字列のための関数)
255262
256C<chomp>, C<chop>, C<chr>, C<crypt>, C<hex>, C<index>, C<lc>, C<lcfirst>,
263=for Pod::Functions =String
257C<length>, C<oct>, C<ord>, C<pack>, C<q//>, C<qq//>, C<reverse>,
258C<rindex>, C<sprintf>, C<substr>, C<tr///>, C<uc>, C<ucfirst>, C<y///>
259264
265L<C<chomp>|/chomp VARIABLE>, L<C<chop>|/chop VARIABLE>,
266L<C<chr>|/chr NUMBER>, L<C<crypt>|/crypt PLAINTEXT,SALT>,
267L<C<fc>|/fc EXPR>, L<C<hex>|/hex EXPR>,
268L<C<index>|/index STR,SUBSTR,POSITION>, L<C<lc>|/lc EXPR>,
269L<C<lcfirst>|/lcfirst EXPR>, L<C<length>|/length EXPR>,
270L<C<oct>|/oct EXPR>, L<C<ord>|/ord EXPR>,
271L<C<pack>|/pack TEMPLATE,LIST>,
272L<C<qE<sol>E<sol>>|/qE<sol>STRINGE<sol>>,
273L<C<qqE<sol>E<sol>>|/qqE<sol>STRINGE<sol>>, L<C<reverse>|/reverse LIST>,
274L<C<rindex>|/rindex STR,SUBSTR,POSITION>,
275L<C<sprintf>|/sprintf FORMAT, LIST>,
276L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT>,
277L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>>, L<C<uc>|/uc EXPR>,
278L<C<ucfirst>|/ucfirst EXPR>,
279L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>>
280
281=begin original
282
283L<C<fc>|/fc EXPR> is available only if the
284L<C<"fc"> feature|feature/The 'fc' feature> is enabled or if it is
285prefixed with C<CORE::>. The
286L<C<"fc"> feature|feature/The 'fc' feature> is enabled automatically
287with a C<use v5.16> (or higher) declaration in the current scope.
288
289=end original
290
291L<C<fc>|/fc EXPR> は L<C<"fc"> 機能|feature/The 'fc' feature> が有効か
292C<CORE::> が前置されたときにのみ利用可能です。
293L<C<"fc"> 機能|feature/The 'fc' feature> は現在のスコープで
294C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。
295
260296=item Regular expressions and pattern matching
261297X<regular expression> X<regex> X<regexp>
262298
263299(正規表現とパターンマッチング)
264300
265C<m//>, C<pos>, C<quotemeta>, C<s///>, C<split>, C<study>, C<qr//>
301=for Pod::Functions =Regexp
266302
303L<C<mE<sol>E<sol>>|/mE<sol>E<sol>>, L<C<pos>|/pos SCALAR>,
304L<C<qrE<sol>E<sol>>|/qrE<sol>STRINGE<sol>>,
305L<C<quotemeta>|/quotemeta EXPR>,
306L<C<sE<sol>E<sol>E<sol>>|/sE<sol>E<sol>E<sol>>,
307L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>,
308L<C<study>|/study SCALAR>
309
267310=item Numeric functions
268311X<numeric> X<number> X<trigonometric> X<trigonometry>
269312
270313(数値関数)
271314
272C<abs>, C<atan2>, C<cos>, C<exp>, C<hex>, C<int>, C<log>, C<oct>, C<rand>,
315=for Pod::Functions =Math
273C<sin>, C<sqrt>, C<srand>
274316
317L<C<abs>|/abs VALUE>, L<C<atan2>|/atan2 Y,X>, L<C<cos>|/cos EXPR>,
318L<C<exp>|/exp EXPR>, L<C<hex>|/hex EXPR>, L<C<int>|/int EXPR>,
319L<C<log>|/log EXPR>, L<C<oct>|/oct EXPR>, L<C<rand>|/rand EXPR>,
320L<C<sin>|/sin EXPR>, L<C<sqrt>|/sqrt EXPR>, L<C<srand>|/srand EXPR>
321
275322=item Functions for real @ARRAYs
276323X<array>
277324
278325(実配列のための関数)
279326
280C<each>, C<keys>, C<pop>, C<push>, C<shift>, C<splice>, C<unshift>, C<values>
327=for Pod::Functions =ARRAY
281328
329L<C<each>|/each HASH>, L<C<keys>|/keys HASH>, L<C<pop>|/pop ARRAY>,
330L<C<push>|/push ARRAY,LIST>, L<C<shift>|/shift ARRAY>,
331L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST>,
332L<C<unshift>|/unshift ARRAY,LIST>, L<C<values>|/values HASH>
333
282334=item Functions for list data
283335X<list>
284336
285337(リストデータのための関数)
286338
287C<grep>, C<join>, C<map>, C<qw//>, C<reverse>, C<sort>, C<unpack>
339=for Pod::Functions =LIST
288340
341L<C<grep>|/grep BLOCK LIST>, L<C<join>|/join EXPR,LIST>,
342L<C<map>|/map BLOCK LIST>, L<C<qwE<sol>E<sol>>|/qwE<sol>STRINGE<sol>>,
343L<C<reverse>|/reverse LIST>, L<C<sort>|/sort SUBNAME LIST>,
344L<C<unpack>|/unpack TEMPLATE,EXPR>
345
289346=item Functions for real %HASHes
290347X<hash>
291348
292349(実ハッシュのための関数)
293350
294C<delete>, C<each>, C<exists>, C<keys>, C<values>
351=for Pod::Functions =HASH
295352
353L<C<delete>|/delete EXPR>, L<C<each>|/each HASH>,
354L<C<exists>|/exists EXPR>, L<C<keys>|/keys HASH>,
355L<C<values>|/values HASH>
356
296357=item Input and output functions
297358X<I/O> X<input> X<output> X<dbm>
298359
299360(入出力関数)
300361
301C<binmode>, C<close>, C<closedir>, C<dbmclose>, C<dbmopen>, C<die>, C<eof>,
362=for Pod::Functions =I/O
302C<fileno>, C<flock>, C<format>, C<getc>, C<print>, C<printf>, C<read>,
303C<readdir>, C<rewinddir>, C<say>, C<seek>, C<seekdir>, C<select>, C<syscall>,
304C<sysread>, C<sysseek>, C<syswrite>, C<tell>, C<telldir>, C<truncate>,
305C<warn>, C<write>
306363
364L<C<binmode>|/binmode FILEHANDLE, LAYER>, L<C<close>|/close FILEHANDLE>,
365L<C<closedir>|/closedir DIRHANDLE>, L<C<dbmclose>|/dbmclose HASH>,
366L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, L<C<die>|/die LIST>,
367L<C<eof>|/eof FILEHANDLE>, L<C<fileno>|/fileno FILEHANDLE>,
368L<C<flock>|/flock FILEHANDLE,OPERATION>, L<C<format>|/format>,
369L<C<getc>|/getc FILEHANDLE>, L<C<print>|/print FILEHANDLE LIST>,
370L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
371L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>,
372L<C<readdir>|/readdir DIRHANDLE>, L<C<readline>|/readline EXPR>
373L<C<rewinddir>|/rewinddir DIRHANDLE>, L<C<say>|/say FILEHANDLE LIST>,
374L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
375L<C<seekdir>|/seekdir DIRHANDLE,POS>,
376L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>,
377L<C<syscall>|/syscall NUMBER, LIST>,
378L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
379L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>,
380L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
381L<C<tell>|/tell FILEHANDLE>, L<C<telldir>|/telldir DIRHANDLE>,
382L<C<truncate>|/truncate FILEHANDLE,LENGTH>, L<C<warn>|/warn LIST>,
383L<C<write>|/write FILEHANDLE>
384
385=begin original
386
387L<C<say>|/say FILEHANDLE LIST> is available only if the
388L<C<"say"> feature|feature/The 'say' feature> is enabled or if it is
389prefixed with C<CORE::>. The
390L<C<"say"> feature|feature/The 'say' feature> is enabled automatically
391with a C<use v5.10> (or higher) declaration in the current scope.
392
393=end original
394
395L<C<say>|/say FILEHANDLE LIST> は
396L<C<"say"> 機能|feature/The 'say' feature> が有効か C<CORE::> が
397前置されたときにのみ利用可能です。
398L<C<"say"> 機能|feature/The 'say' feature> は現在のスコープで
399C<use v5.10> (またはそれ以上) が宣言されると自動的に有効になります。
400
307401=item Functions for fixed-length data or records
308402
309403(固定長データやレコードのための関数)
310404
311C<pack>, C<read>, C<syscall>, C<sysread>, C<syswrite>, C<unpack>, C<vec>
405=for Pod::Functions =Binary
312406
407L<C<pack>|/pack TEMPLATE,LIST>,
408L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>,
409L<C<syscall>|/syscall NUMBER, LIST>,
410L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
411L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>,
412L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
413L<C<unpack>|/unpack TEMPLATE,EXPR>, L<C<vec>|/vec EXPR,OFFSET,BITS>
414
313415=item Functions for filehandles, files, or directories
314416X<file> X<filehandle> X<directory> X<pipe> X<link> X<symlink>
315417
316418(ファイルハンドル、ファイル、ディレクトリのための関数)
317419
318C<-I<X>>, C<chdir>, C<chmod>, C<chown>, C<chroot>, C<fcntl>, C<glob>,
420=for Pod::Functions =File
319C<ioctl>, C<link>, C<lstat>, C<mkdir>, C<open>, C<opendir>,
320C<readlink>, C<rename>, C<rmdir>, C<stat>, C<symlink>, C<sysopen>,
321C<umask>, C<unlink>, C<utime>
322421
422L<C<-I<X>>|/-X FILEHANDLE>, L<C<chdir>|/chdir EXPR>,
423L<C<chmod>|/chmod LIST>, L<C<chown>|/chown LIST>,
424L<C<chroot>|/chroot FILENAME>,
425L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>, L<C<glob>|/glob EXPR>,
426L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>,
427L<C<link>|/link OLDFILE,NEWFILE>, L<C<lstat>|/lstat FILEHANDLE>,
428L<C<mkdir>|/mkdir FILENAME,MASK>, L<C<open>|/open FILEHANDLE,EXPR>,
429L<C<opendir>|/opendir DIRHANDLE,EXPR>, L<C<readlink>|/readlink EXPR>,
430L<C<rename>|/rename OLDNAME,NEWNAME>, L<C<rmdir>|/rmdir FILENAME>,
431L<C<select>|/select FILEHANDLE>, L<C<stat>|/stat FILEHANDLE>,
432L<C<symlink>|/symlink OLDFILE,NEWFILE>,
433L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>,
434L<C<umask>|/umask EXPR>, L<C<unlink>|/unlink LIST>,
435L<C<utime>|/utime LIST>
436
323437=item Keywords related to the control flow of your Perl program
324438X<control flow>
325439
326440(プログラムの流れを制御することに関連するキーワード)
327441
328C<caller>, C<continue>, C<die>, C<do>, C<dump>, C<eval>, C<exit>,
442=for Pod::Functions =Flow
329C<goto>, C<last>, C<next>, C<redo>, C<return>, C<sub>, C<wantarray>
330443
331=item Keywords related to the switch feature
444L<C<break>|/break>, L<C<caller>|/caller EXPR>,
445L<C<continue>|/continue BLOCK>, L<C<die>|/die LIST>, L<C<do>|/do BLOCK>,
446L<C<dump>|/dump LABEL>, L<C<eval>|/eval EXPR>,
447L<C<evalbytes>|/evalbytes EXPR> L<C<exit>|/exit EXPR>,
448L<C<__FILE__>|/__FILE__>, L<C<goto>|/goto LABEL>,
449L<C<last>|/last LABEL>, L<C<__LINE__>|/__LINE__>,
450L<C<next>|/next LABEL>, L<C<__PACKAGE__>|/__PACKAGE__>,
451L<C<redo>|/redo LABEL>, L<C<return>|/return EXPR>,
452L<C<sub>|/sub NAME BLOCK>, L<C<__SUB__>|/__SUB__>,
453L<C<wantarray>|/wantarray>
332454
333(switch 機能に関連するキーワード)
455=begin original
334456
335C<break>, C<continue>, C<default, >C<given>, C<when>
457L<C<break>|/break> is available only if you enable the experimental
458L<C<"switch"> feature|feature/The 'switch' feature> or use the C<CORE::>
459prefix. The L<C<"switch"> feature|feature/The 'switch' feature> also
460enables the C<default>, C<given> and C<when> statements, which are
461documented in L<perlsyn/"Switch Statements">.
462The L<C<"switch"> feature|feature/The 'switch' feature> is enabled
463automatically with a C<use v5.10> (or higher) declaration in the current
464scope. In Perl v5.14 and earlier, L<C<continue>|/continue BLOCK>
465required the L<C<"switch"> feature|feature/The 'switch' feature>, like
466the other keywords.
336467
468=end original
469
470L<C<break>|/break> は、実験的な
471L<C<"switch"> 機能|feature/The 'switch' feature> が有効か C<CORE::> 接頭辞を
472使ったときにのみ利用可能です。
473L<C<"switch"> 機能|feature/The 'switch' feature> は、
474L<perlsyn/"Switch Statements"> で文書化されている
475C<default>, C<given>, C<when> 文も有効にします。
476L<C<"switch"> 機能|feature/The 'switch' feature> は、現在のスコープで
477C<use v5.10> (またはそれ以上) 宣言があると自動的に有効になります。
478Perl v5.14 以前では、L<C<continue>|/continue BLOCK> は他のキーワードと同様に
479L<C<"switch"> 機能|feature/The 'switch' feature> が必要です。
480
337481=begin original
338482
339These are available only if you enable the C<"switch"> feature.
483L<C<evalbytes>|/evalbytes EXPR> is only available with the
340See L<feature> and L<perlsyn/"Switch statements">.
484L<C<"evalbytes"> feature|feature/The 'unicode_eval' and 'evalbytes' features>
341Alternately, include a C<use v5.10> or later to the current scope.
485(see L<feature>) or if prefixed with C<CORE::>. L<C<__SUB__>|/__SUB__>
486is only available with the
487L<C<"current_sub"> feature|feature/The 'current_sub' feature> or if
488prefixed with C<CORE::>. Both the
489L<C<"evalbytes">|feature/The 'unicode_eval' and 'evalbytes' features>
490and L<C<"current_sub">|feature/The 'current_sub' feature> features are
491enabled automatically with a C<use v5.16> (or higher) declaration in the
492current scope.
342493
343494=end original
344495
345これらは C<"switch"> 機能が有効の場合にのみ利用可能です。
496L<C<evalbytes>|/evalbytes EXPR>
346L<feature> と L<perlsyn/"Switch statements"> を参照してください。
497L<C<"evalbytes"> 機能|feature/The 'unicode_eval' and 'evalbytes' features>
347あるいは、現在のスコープに C<use v5.10> 以降を含めてくだ
498(L<feature> 参照) が有効か C<CORE::> が前置れたときにのみ利用可能です
499L<C<__SUB__>|/__SUB__> は
500L<C<"current_sub"> 機能|feature/The 'current_sub' feature> が有効か
501C<CORE::> が前置されたときにのみ利用可能です。
502L<C<"evalbytes">|feature/The 'unicode_eval' and 'evalbytes' features> と
503L<C<"current_sub">|feature/The 'current_sub' feature> の両方の機能は
504現在のスコープで
505C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。
348506
349507=item Keywords related to scoping
350508
351509(スコープに関するキーワード)
352510
353C<caller>, C<import>, C<local>, C<my>, C<our>, C<package>, C<state>, C<use>
511=for Pod::Functions =Namespace
354512
513L<C<caller>|/caller EXPR>, L<C<import>|/import LIST>,
514L<C<local>|/local EXPR>, L<C<my>|/my VARLIST>, L<C<our>|/our VARLIST>,
515L<C<package>|/package NAMESPACE>, L<C<state>|/state VARLIST>,
516L<C<use>|/use Module VERSION LIST>
517
355518=begin original
356519
357C<state> is available only if the C<"state"> feature is enabled. See
520L<C<state>|/state VARLIST> is available only if the
358L<feature>. Alternately, include a C<use v5.10> or later to the current scope.
521L<C<"state"> feature|feature/The 'state' feature> is enabled or if it is
522prefixed with C<CORE::>. The
523L<C<"state"> feature|feature/The 'state' feature> is enabled
524automatically with a C<use v5.10> (or higher) declaration in the current
525scope.
359526
360527=end original
361528
362C<state> は C<"state"> 機能が有効の場合にのみ利用可能です。
529L<C<state>|/state VARLIST>
363L<feature> を参照してください。
530L<C<"state"> 機能|feature/The 'state' feature> が有効か C<CORE::>
364あるいは、現在のスコープ C<use v5.10> 以降を含めてください
531前置した場合のみ利用可能です
532L<C<"state"> 機能|feature/The 'state' feature> は現在のスコープで
533C<use v5.10> (またはそれ以上) を宣言した場合自動的に有効になります。
365534
366535=item Miscellaneous functions
367536
368537(さまざまな関数)
369538
370C<defined>, C<dump>, C<eval>, C<formline>, C<local>, C<my>, C<our>,
539=for Pod::Functions =Misc
371C<reset>, C<scalar>, C<state>, C<undef>, C<wantarray>
372540
541L<C<defined>|/defined EXPR>, L<C<formline>|/formline PICTURE,LIST>,
542L<C<lock>|/lock THING>, L<C<prototype>|/prototype FUNCTION>,
543L<C<reset>|/reset EXPR>, L<C<scalar>|/scalar EXPR>,
544L<C<undef>|/undef EXPR>
545
373546=item Functions for processes and process groups
374547X<process> X<pid> X<process id>
375548
376549(プロセスとプロセスグループのための関数)
377550
378C<alarm>, C<exec>, C<fork>, C<getpgrp>, C<getppid>, C<getpriority>, C<kill>,
551=for Pod::Functions =Process
379C<pipe>, C<qx//>, C<setpgrp>, C<setpriority>, C<sleep>, C<system>,
380C<times>, C<wait>, C<waitpid>
381552
553L<C<alarm>|/alarm SECONDS>, L<C<exec>|/exec LIST>, L<C<fork>|/fork>,
554L<C<getpgrp>|/getpgrp PID>, L<C<getppid>|/getppid>,
555L<C<getpriority>|/getpriority WHICH,WHO>, L<C<kill>|/kill SIGNAL, LIST>,
556L<C<pipe>|/pipe READHANDLE,WRITEHANDLE>,
557L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>>,
558L<C<readpipe>|/readpipe EXPR>, L<C<setpgrp>|/setpgrp PID,PGRP>,
559L<C<setpriority>|/setpriority WHICH,WHO,PRIORITY>,
560L<C<sleep>|/sleep EXPR>, L<C<system>|/system LIST>, L<C<times>|/times>,
561L<C<wait>|/wait>, L<C<waitpid>|/waitpid PID,FLAGS>
562
382563=item Keywords related to Perl modules
383564X<module>
384565
385566(Perl モジュールに関するキーワード)
386567
387C<do>, C<import>, C<no>, C<package>, C<require>, C<use>
568=for Pod::Functions =Modules
388569
570L<C<do>|/do EXPR>, L<C<import>|/import LIST>,
571L<C<no>|/no MODULE VERSION LIST>, L<C<package>|/package NAMESPACE>,
572L<C<require>|/require VERSION>, L<C<use>|/use Module VERSION LIST>
573
389574=item Keywords related to classes and object-orientation
390575X<object> X<class> X<package>
391576
392577(クラスとオブジェクト指向に関するキーワード)
393578
394C<bless>, C<dbmclose>, C<dbmopen>, C<package>, C<ref>, C<tie>, C<tied>,
579=for Pod::Functions =Objects
395C<untie>, C<use>
396580
581L<C<bless>|/bless REF,CLASSNAME>, L<C<dbmclose>|/dbmclose HASH>,
582L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>,
583L<C<package>|/package NAMESPACE>, L<C<ref>|/ref EXPR>,
584L<C<tie>|/tie VARIABLE,CLASSNAME,LIST>, L<C<tied>|/tied VARIABLE>,
585L<C<untie>|/untie VARIABLE>, L<C<use>|/use Module VERSION LIST>
586
397587=item Low-level socket functions
398588X<socket> X<sock>
399589
400590(低レベルソケット関数)
401591
402C<accept>, C<bind>, C<connect>, C<getpeername>, C<getsockname>,
592=for Pod::Functions =Socket
403C<getsockopt>, C<listen>, C<recv>, C<send>, C<setsockopt>, C<shutdown>,
404C<socket>, C<socketpair>
405593
594L<C<accept>|/accept NEWSOCKET,GENERICSOCKET>,
595L<C<bind>|/bind SOCKET,NAME>, L<C<connect>|/connect SOCKET,NAME>,
596L<C<getpeername>|/getpeername SOCKET>,
597L<C<getsockname>|/getsockname SOCKET>,
598L<C<getsockopt>|/getsockopt SOCKET,LEVEL,OPTNAME>,
599L<C<listen>|/listen SOCKET,QUEUESIZE>,
600L<C<recv>|/recv SOCKET,SCALAR,LENGTH,FLAGS>,
601L<C<send>|/send SOCKET,MSG,FLAGS,TO>,
602L<C<setsockopt>|/setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL>,
603L<C<shutdown>|/shutdown SOCKET,HOW>,
604L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL>,
605L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL>
606
406607=item System V interprocess communication functions
407608X<IPC> X<System V> X<semaphore> X<shared memory> X<memory> X<message>
408609
409610(System V プロセス間通信関数)
410611
411C<msgctl>, C<msgget>, C<msgrcv>, C<msgsnd>, C<semctl>, C<semget>, C<semop>,
612=for Pod::Functions =SysV
412C<shmctl>, C<shmget>, C<shmread>, C<shmwrite>
413613
614L<C<msgctl>|/msgctl ID,CMD,ARG>, L<C<msgget>|/msgget KEY,FLAGS>,
615L<C<msgrcv>|/msgrcv ID,VAR,SIZE,TYPE,FLAGS>,
616L<C<msgsnd>|/msgsnd ID,MSG,FLAGS>,
617L<C<semctl>|/semctl ID,SEMNUM,CMD,ARG>,
618L<C<semget>|/semget KEY,NSEMS,FLAGS>, L<C<semop>|/semop KEY,OPSTRING>,
619L<C<shmctl>|/shmctl ID,CMD,ARG>, L<C<shmget>|/shmget KEY,SIZE,FLAGS>,
620L<C<shmread>|/shmread ID,VAR,POS,SIZE>,
621L<C<shmwrite>|/shmwrite ID,STRING,POS,SIZE>
622
414623=item Fetching user and group info
415624X<user> X<group> X<password> X<uid> X<gid> X<passwd> X</etc/passwd>
416625
417626(ユーザーとグループの情報取得)
418627
419C<endgrent>, C<endhostent>, C<endnetent>, C<endpwent>, C<getgrent>,
628=for Pod::Functions =User
420C<getgrgid>, C<getgrnam>, C<getlogin>, C<getpwent>, C<getpwnam>,
421C<getpwuid>, C<setgrent>, C<setpwent>
422629
630L<C<endgrent>|/endgrent>, L<C<endhostent>|/endhostent>,
631L<C<endnetent>|/endnetent>, L<C<endpwent>|/endpwent>,
632L<C<getgrent>|/getgrent>, L<C<getgrgid>|/getgrgid GID>,
633L<C<getgrnam>|/getgrnam NAME>, L<C<getlogin>|/getlogin>,
634L<C<getpwent>|/getpwent>, L<C<getpwnam>|/getpwnam NAME>,
635L<C<getpwuid>|/getpwuid UID>, L<C<setgrent>|/setgrent>,
636L<C<setpwent>|/setpwent>
637
423638=item Fetching network info
424639X<network> X<protocol> X<host> X<hostname> X<IP> X<address> X<service>
425640
426641(ネットワーク情報取得)
427642
428C<endprotoent>, C<endservent>, C<gethostbyaddr>, C<gethostbyname>,
643=for Pod::Functions =Network
429C<gethostent>, C<getnetbyaddr>, C<getnetbyname>, C<getnetent>,
430C<getprotobyname>, C<getprotobynumber>, C<getprotoent>,
431C<getservbyname>, C<getservbyport>, C<getservent>, C<sethostent>,
432C<setnetent>, C<setprotoent>, C<setservent>
433644
645L<C<endprotoent>|/endprotoent>, L<C<endservent>|/endservent>,
646L<C<gethostbyaddr>|/gethostbyaddr ADDR,ADDRTYPE>,
647L<C<gethostbyname>|/gethostbyname NAME>, L<C<gethostent>|/gethostent>,
648L<C<getnetbyaddr>|/getnetbyaddr ADDR,ADDRTYPE>,
649L<C<getnetbyname>|/getnetbyname NAME>, L<C<getnetent>|/getnetent>,
650L<C<getprotobyname>|/getprotobyname NAME>,
651L<C<getprotobynumber>|/getprotobynumber NUMBER>,
652L<C<getprotoent>|/getprotoent>,
653L<C<getservbyname>|/getservbyname NAME,PROTO>,
654L<C<getservbyport>|/getservbyport PORT,PROTO>,
655L<C<getservent>|/getservent>, L<C<sethostent>|/sethostent STAYOPEN>,
656L<C<setnetent>|/setnetent STAYOPEN>,
657L<C<setprotoent>|/setprotoent STAYOPEN>,
658L<C<setservent>|/setservent STAYOPEN>
659
434660=item Time-related functions
435661X<time> X<date>
436662
437663(時刻に関する関数)
438664
439C<gmtime>, C<localtime>, C<time>, C<times>
665=for Pod::Functions =Time
440666
441=item Functions new in perl5
667L<C<gmtime>|/gmtime EXPR>, L<C<localtime>|/localtime EXPR>,
442X<perl5>
668L<C<time>|/time>, L<C<times>|/times>
443669
444(perl5 で新設された関数)
670=item Non-function keywords
445671
446C<abs>, C<bless>, C<break>, C<chomp>, C<chr>, C<continue>, C<default>,
672=for Pod::Functions =!Non-functions
447C<exists>, C<formline>, C<given>, C<glob>, C<import>, C<lc>, C<lcfirst>,
448C<lock>, C<map>, C<my>, C<no>, C<our>, C<prototype>, C<qr//>, C<qw//>, C<qx//>,
449C<readline>, C<readpipe>, C<ref>, C<sub>*, C<sysopen>, C<tie>, C<tied>, C<uc>,
450C<ucfirst>, C<untie>, C<use>, C<when>
451673
452=begin original
674C<and>, C<AUTOLOAD>, C<BEGIN>, C<CHECK>, C<cmp>, C<CORE>, C<__DATA__>,
675C<default>, C<DESTROY>, C<else>, C<elseif>, C<elsif>, C<END>, C<__END__>,
676C<eq>, C<for>, C<foreach>, C<ge>, C<given>, C<gt>, C<if>, C<INIT>, C<le>,
677C<lt>, C<ne>, C<not>, C<or>, C<UNITCHECK>, C<unless>, C<until>, C<when>,
678C<while>, C<x>, C<xor>
453679
454* C<sub> was a keyword in Perl 4, but in Perl 5 it is an
455operator, which can be used in expressions.
456
457=end original
458
459* - C<sub> は Perl4 ではキーワードですが、Perl5 では演算子なので、
460式で使えます。
461
462=item Functions obsoleted in perl5
463
464(perl5 では古いものとなった関数)
465
466C<dbmclose>, C<dbmopen>
467
468680=back
469681
470682=head2 Portability
471683X<portability> X<Unix> X<portable>
472684
473685(移植性)
474686
475687=begin original
476688
477689Perl was born in Unix and can therefore access all common Unix
478690system calls. In non-Unix environments, the functionality of some
479691Unix system calls may not be available or details of the available
480692functionality may differ slightly. The Perl functions affected
481693by this are:
482694
483695=end original
484696
485697Perl は Unix 環境で生まれたので、全ての共通する Unix システムコールに
486アクセスします。非 Unix 環境では、いくつかの Unix システムコールの
698アクセスします。
487機能が使えなかったり、使える機能の詳細が多少異なったりします。
699非 Unix 環境では、いくつかの Unix システムコールの機能が使えなかったり、
700使える機能の詳細が多少異なったりします。
488701これによる影響を受ける Perl 関数は以下のものです:
489702
490C<-X>, C<binmode>, C<chmod>, C<chown>, C<chroot>, C<crypt>,
703L<C<-I<X>>|/-X FILEHANDLE>, L<C<binmode>|/binmode FILEHANDLE, LAYER>,
491C<dbmclose>, C<dbmopen>, C<dump>, C<endgrent>, C<endhostent>,
704L<C<chmod>|/chmod LIST>, L<C<chown>|/chown LIST>,
492C<endnetent>, C<endprotoent>, C<endpwent>, C<endservent>, C<exec>,
705L<C<chroot>|/chroot FILENAME>, L<C<crypt>|/crypt PLAINTEXT,SALT>,
493C<fcntl>, C<flock>, C<fork>, C<getgrent>, C<getgrgid>, C<gethostbyname>,
706L<C<dbmclose>|/dbmclose HASH>, L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>,
494C<gethostent>, C<getlogin>, C<getnetbyaddr>, C<getnetbyname>, C<getnetent>,
707L<C<dump>|/dump LABEL>, L<C<endgrent>|/endgrent>,
495C<getppid>, C<getpgrp>, C<getpriority>, C<getprotobynumber>,
708L<C<endhostent>|/endhostent>, L<C<endnetent>|/endnetent>,
496C<getprotoent>, C<getpwent>, C<getpwnam>, C<getpwuid>,
709L<C<endprotoent>|/endprotoent>, L<C<endpwent>|/endpwent>,
497C<getservbyport>, C<getservent>, C<getsockopt>, C<glob>, C<ioctl>,
710L<C<endservent>|/endservent>, L<C<exec>|/exec LIST>,
498C<kill>, C<link>, C<lstat>, C<msgctl>, C<msgget>, C<msgrcv>,
711L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>,
499C<msgsnd>, C<open>, C<pipe>, C<readlink>, C<rename>, C<select>, C<semctl>,
712L<C<flock>|/flock FILEHANDLE,OPERATION>, L<C<fork>|/fork>,
500C<semget>, C<semop>, C<setgrent>, C<sethostent>, C<setnetent>,
713L<C<getgrent>|/getgrent>, L<C<getgrgid>|/getgrgid GID>,
501C<setpgrp>, C<setpriority>, C<setprotoent>, C<setpwent>,
714L<C<gethostbyname>|/gethostbyname NAME>, L<C<gethostent>|/gethostent>,
502C<setservent>, C<setsockopt>, C<shmctl>, C<shmget>, C<shmread>,
715L<C<getlogin>|/getlogin>,
503C<shmwrite>, C<socket>, C<socketpair>,
716L<C<getnetbyaddr>|/getnetbyaddr ADDR,ADDRTYPE>,
504C<stat>, C<symlink>, C<syscall>, C<sysopen>, C<system>,
717L<C<getnetbyname>|/getnetbyname NAME>, L<C<getnetent>|/getnetent>,
505C<times>, C<truncate>, C<umask>, C<unlink>,
718L<C<getppid>|/getppid>, L<C<getpgrp>|/getpgrp PID>,
506C<utime>, C<wait>, C<waitpid>
719L<C<getpriority>|/getpriority WHICH,WHO>,
720L<C<getprotobynumber>|/getprotobynumber NUMBER>,
721L<C<getprotoent>|/getprotoent>, L<C<getpwent>|/getpwent>,
722L<C<getpwnam>|/getpwnam NAME>, L<C<getpwuid>|/getpwuid UID>,
723L<C<getservbyport>|/getservbyport PORT,PROTO>,
724L<C<getservent>|/getservent>,
725L<C<getsockopt>|/getsockopt SOCKET,LEVEL,OPTNAME>,
726L<C<glob>|/glob EXPR>, L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>,
727L<C<kill>|/kill SIGNAL, LIST>, L<C<link>|/link OLDFILE,NEWFILE>,
728L<C<lstat>|/lstat FILEHANDLE>, L<C<msgctl>|/msgctl ID,CMD,ARG>,
729L<C<msgget>|/msgget KEY,FLAGS>,
730L<C<msgrcv>|/msgrcv ID,VAR,SIZE,TYPE,FLAGS>,
731L<C<msgsnd>|/msgsnd ID,MSG,FLAGS>, L<C<open>|/open FILEHANDLE,EXPR>,
732L<C<pipe>|/pipe READHANDLE,WRITEHANDLE>, L<C<readlink>|/readlink EXPR>,
733L<C<rename>|/rename OLDNAME,NEWNAME>,
734L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>,
735L<C<semctl>|/semctl ID,SEMNUM,CMD,ARG>,
736L<C<semget>|/semget KEY,NSEMS,FLAGS>, L<C<semop>|/semop KEY,OPSTRING>,
737L<C<setgrent>|/setgrent>, L<C<sethostent>|/sethostent STAYOPEN>,
738L<C<setnetent>|/setnetent STAYOPEN>, L<C<setpgrp>|/setpgrp PID,PGRP>,
739L<C<setpriority>|/setpriority WHICH,WHO,PRIORITY>,
740L<C<setprotoent>|/setprotoent STAYOPEN>, L<C<setpwent>|/setpwent>,
741L<C<setservent>|/setservent STAYOPEN>,
742L<C<setsockopt>|/setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL>,
743L<C<shmctl>|/shmctl ID,CMD,ARG>, L<C<shmget>|/shmget KEY,SIZE,FLAGS>,
744L<C<shmread>|/shmread ID,VAR,POS,SIZE>,
745L<C<shmwrite>|/shmwrite ID,STRING,POS,SIZE>,
746L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL>,
747L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL>,
748L<C<stat>|/stat FILEHANDLE>, L<C<symlink>|/symlink OLDFILE,NEWFILE>,
749L<C<syscall>|/syscall NUMBER, LIST>,
750L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>,
751L<C<system>|/system LIST>, L<C<times>|/times>,
752L<C<truncate>|/truncate FILEHANDLE,LENGTH>, L<C<umask>|/umask EXPR>,
753L<C<unlink>|/unlink LIST>, L<C<utime>|/utime LIST>, L<C<wait>|/wait>,
754L<C<waitpid>|/waitpid PID,FLAGS>
507755
508756=begin original
509757
510758For more information about the portability of these functions, see
511759L<perlport> and other available platform-specific documentation.
512760
513761=end original
514762
515763これらの関数の移植性に関するさらなる情報については、
516L<perlport> とその他のプラットホーム固有のドキュメントを参照してさい。
764L<perlport> とその他のプラットホーム固有のドキュメントを参照してください。
517765
518766=head2 Alphabetical Listing of Perl Functions
519767
520=over
768=over
521769
522770=item -X FILEHANDLE
523771X<-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>
524772X<-S>X<-b>X<-c>X<-t>X<-u>X<-g>X<-k>X<-T>X<-B>X<-M>X<-A>X<-C>
525773
526774=item -X EXPR
527775
528776=item -X DIRHANDLE
529777
530778=item -X
531779
780=for Pod::Functions a file test (-r, -x, etc)
781
532782=begin original
533783
534784A file test, where X is one of the letters listed below. This unary
535operator takes one argument, either a filename, a filehandle, or a dirhandle,
785operator takes one argument, either a filename, a filehandle, or a dirhandle,
536786and tests the associated file to see if something is true about it. If the
537argument is omitted, tests C<$_>, except for C<-t>, which tests STDIN.
787argument is omitted, tests L<C<$_>|perlvar/$_>, except for C<-t>, which
538Unless otherwise documented, it returns C<1> for true and C<''> for false, or
788tests STDIN. Unless otherwise documented, it returns C<1> for true and
539the undefined value if the file doesn't exist. Despite the funny
789C<''> for false. If the file doesn't exist or can't be examined, it
540names, precedence is the same as any other named unary operator. The
790returns L<C<undef>|/undef EXPR> and sets L<C<$!>|perlvar/$!> (errno).
541operator may be any of:
791Despite the funny names, precedence is the same as any other named unary
792operator. The operator may be any of:
542793
543794=end original
544795
545796X は以下にあげる文字で、ファイルテストを行ないます。
546この単項演算子は、ファイル名かファイルハンドルを唯一の
797この単項演算子は、ファイル名かファイルハンドルを唯一の引数として動作し、
547引数として動作し、「あること」について真であるか否かを
798「あること」について真であるか否かを判定した結果を返します。
548判定した結果返します
799引数が省略されると、C<-t> では STDIN 調べますが、その他は
549引数が省略されると、C<-t> では STDIN を調べますが、その他は C<$_> を調べます。
800L<C<$_>|perlvar/$_> を調べます。
550特に記述されていなければ、真として C<1> を返し、偽として
801特に記述されていなければ、真として C<1> を返し、偽として C<''> を返します。
551C<''> を返し、ファイルが存在しなければ、未定義値を返します。
802ファイルが存在しないか、テスト出来なければ、L<C<undef>|/undef EXPR> を返し
803L<C<$!>|perlvar/$!> (errno) を設定します。
552804みかけは変わっていますが、優先順位は名前付き単項演算子と同じで、
553805他の単項演算子と同じく、引数を括弧で括ることもできます。
554806演算子には以下のものがあります:
555807
556808=begin original
557809
558810 -r File is readable by effective uid/gid.
559811 -w File is writable by effective uid/gid.
560812 -x File is executable by effective uid/gid.
561813 -o File is owned by effective uid.
562814
563815=end original
564816
565 -r ファイルが実効 uid/gid で読み出し可
817 -r ファイルが実効 uid/gid で読み出し可
566 -w ファイルが実効 uid/gid で書き込み可
818 -w ファイルが実効 uid/gid で書き込み可
567 -x ファイルが実効 uid/gid で実行可
819 -x ファイルが実効 uid/gid で実行可
568 -o ファイルが実効 uid の所有物
820 -o ファイルが実効 uid の所有物
569821
570822=begin original
571823
572824 -R File is readable by real uid/gid.
573825 -W File is writable by real uid/gid.
574826 -X File is executable by real uid/gid.
575827 -O File is owned by real uid.
576828
577829=end original
578830
579 -R ファイルが実 uid/gid で読み出し可
831 -R ファイルが実 uid/gid で読み出し可
580 -W ファイルが実 uid/gid で書き込み可
832 -W ファイルが実 uid/gid で書き込み可
581 -X ファイルが実 uid/gid で実行可
833 -X ファイルが実 uid/gid で実行可
582 -O ファイルが実 uid の所有物
834 -O ファイルが実 uid の所有物
583835
584836=begin original
585837
586838 -e File exists.
587839 -z File has zero size (is empty).
588840 -s File has nonzero size (returns size in bytes).
589841
590842=end original
591843
592 -e ファイルが存在する
844 -e ファイルが存在する
593 -z ファイルの大きさがゼロ(空)
845 -z ファイルの大きさがゼロ(空)
594 -s ファイルの大きさがゼロ以外 (バイト単位での大きさを返す)
846 -s ファイルの大きさがゼロ以外 (バイト単位での大きさを返す)
595847
596848=begin original
597849
598850 -f File is a plain file.
599851 -d File is a directory.
600 -l File is a symbolic link.
852 -l File is a symbolic link (false if symlinks aren't
853 supported by the file system).
601854 -p File is a named pipe (FIFO), or Filehandle is a pipe.
602855 -S File is a socket.
603856 -b File is a block special file.
604857 -c File is a character special file.
605858 -t Filehandle is opened to a tty.
606859
607860=end original
608861
609 -f ファイルは通常ファイル
862 -f ファイルは通常ファイル
610 -d ファイルはディレクトリ
863 -d ファイルはディレクトリ
611 -l ファイルはシンボリックリンク
864 -l ファイルはシンボリックリンク(ファイルシステムが非対応なら偽)。
612 -p ファイルは名前付きパイプ (FIFO) またはファイルハンドルはパイプ
865 -p ファイルは名前付きパイプ (FIFO) またはファイルハンドルはパイプ
613 -S ファイルはソケット
866 -S ファイルはソケット
614 -b ファイルはブロック特殊ファイル
867 -b ファイルはブロック特殊ファイル
615 -c ファイルはキャラクタ特殊ファイル
868 -c ファイルはキャラクタ特殊ファイル
616 -t ファイルハンドルは tty にオープンされている
869 -t ファイルハンドルは tty にオープンされている
617870
618871=begin original
619872
620873 -u File has setuid bit set.
621874 -g File has setgid bit set.
622875 -k File has sticky bit set.
623876
624877=end original
625878
626 -u ファイルの setuid ビットがセットされている
879 -u ファイルの setuid ビットがセットされている
627 -g ファイルの setgid ビットがセットされている
880 -g ファイルの setgid ビットがセットされている
628 -k ファイルの sticky ビットがセットされている
881 -k ファイルの sticky ビットがセットされている
629882
630883=begin original
631884
632 -T File is an ASCII text file (heuristic guess).
885 -T File is an ASCII or UTF-8 text file (heuristic guess).
633886 -B File is a "binary" file (opposite of -T).
634887
635888=end original
636889
637 -T ファイルは ASCII テキストファイル (発見的に推測します)
890 -T ファイルは ASCII または UTF-8 テキストファイル (発見的に推測します)
638 -B ファイルは「バイナリ」ファイル (-T の反対)
891 -B ファイルは「バイナリ」ファイル (-T の反対)
639892
640893=begin original
641894
642895 -M Script start time minus file modification time, in days.
643896 -A Same for access time.
644 -C Same for inode change time (Unix, may differ for other platforms)
897 -C Same for inode change time (Unix, may differ for other
898 platforms)
645899
646900=end original
647901
648 -M スクリプト実行開始時刻からファイル修正時刻を引いたもの(日単位)
902 -M スクリプト実行開始時刻からファイル修正時刻を引いたもの(日単位)
649 -A 同様にアクセスがあってからの日数
903 -A 同様にアクセスがあってからの日数
650 -C 同様に(Unix では) inode が変更されてからの日数(それ以外のプラットフォームでは違うかもしれません)
904 -C 同様に(Unix では) inode が変更されてからの日数(それ以外の
905 プラットフォームでは違うかもしれません)。
651906
652907=begin original
653908
654909Example:
655910
656911=end original
657912
658913例:
659914
660915 while (<>) {
661916 chomp;
662917 next unless -f $_; # ignore specials
663918 #...
664919 }
665920
666921=begin original
667922
668923Note that C<-s/a/b/> does not do a negated substitution. Saying
669924C<-exp($foo)> still works as expected, however: only single letters
670925following a minus are interpreted as file tests.
671926
672927=end original
673928
674929C<-s/a/b> は、置換演算 (s///) の符号反転ではありません。
675しかし、C<-exp($foo)> は期待どおりに動作します
930しかし、C<-exp($foo)> は期待どおりに動作します; しかし、マイナス記号の後に
676マイナス記号の後に英字が 1 字続くときにのみ、ファイルテストと
931英字が 1 字続くときにのみ、ファイルテストと解釈されます。
677解釈されます。
678932
679933=begin original
680934
681935These operators are exempt from the "looks like a function rule" described
682above. That is, an opening parenthesis after the operator does not affect
936above. That is, an opening parenthesis after the operator does not affect
683how much of the following code constitutes the argument. Put the opening
937how much of the following code constitutes the argument. Put the opening
684938parentheses before the operator to separate it from code that follows (this
685939applies only to operators with higher precedence than unary operators, of
686940course):
687941
688942=end original
689943
690944これらの演算子は上述の「関数のように見えるルール」から免除されます。
691945つまり、演算子の後の開きかっこは、引き続くコードのどこまでが引数を
692946構成するかに影響を与えません。
693947演算子を引き続くコードから分離するには、演算子の前に開きかっこを
694948置いてください (これはもちろん、単項演算子より高い優先順位を持つ
695949演算子にのみ適用されます):
696950
697951 -s($file) + 1024 # probably wrong; same as -s($file + 1024)
698952 (-s $file) + 1024 # correct
699953
700954=begin original
701955
702956The interpretation of the file permission operators C<-r>, C<-R>,
703957C<-w>, C<-W>, C<-x>, and C<-X> is by default based solely on the mode
704958of the file and the uids and gids of the user. There may be other
705959reasons you can't actually read, write, or execute the file: for
706960example network filesystem access controls, ACLs (access control lists),
707961read-only filesystems, and unrecognized executable formats. Note
708962that the use of these six specific operators to verify if some operation
709963is possible is usually a mistake, because it may be open to race
710964conditions.
711965
712966=end original
713967
714968ファイルのパーミッション演算子 C<-r>, C<-R>, C<-w>, C<-W>, C<-x>,
715969C<-X> の解釈は、ファイルのモードとユーザの実効/実 uid と
716970実効/実 gid のみから判断されます。
717971実際にファイルが読めたり、書けたり、実行できたりするためには、
718972別の条件が必要かもしれません:
719973例えば、ネットワークファイルシステムアクセスコントロール、
720974ACL(アクセスコントロールリスト)、読み込み専用ファイルシステム、
721975認識できない実行ファイルフォーマット、などです。
722976これらの 6 つの演算子を、特定の操作が可能かどうかを確認するために使うのは
723977通常は誤りであることに注意してください; なぜなら、これらは競合条件を
724978招きやすいからです。
725979
726980=begin original
727981
728982Also note that, for the superuser on the local filesystems, the C<-r>,
729983C<-R>, C<-w>, and C<-W> tests always return 1, and C<-x> and C<-X> return 1
730984if any execute bit is set in the mode. Scripts run by the superuser
731may thus need to do a stat() to determine the actual mode of the file,
985may thus need to do a L<C<stat>|/stat FILEHANDLE> to determine the
732or temporarily set their effective uid to something else.
986actual mode of the file, or temporarily set their effective uid to
987something else.
733988
734989=end original
735990
736991ローカルファイルシステムのスーパーユーザには、
737992C<-r>, C<-R>, C<-w>, C<-W> に対して、常に 1 が返り、モード中の
738993いずれかの実行許可ビットが立っていれば、C<-x>, C<-X> にも 1 が
739994返ることにも注意してください。
740995スーパーユーザが実行するスクリプトでは、ファイルのモードを調べるためには、
741stat() を行なうか、実効 uid を一時的に別のものにする
996L<C<stat>|/stat FILEHANDLE> を行なうか、実効 uid を一時的に別のものにする
742997必要があるでしょう。
743998
744999=begin original
7451000
746If you are using ACLs, there is a pragma called C<filetest> that may
1001If you are using ACLs, there is a pragma called L<C<filetest>|filetest>
747produce more accurate results than the bare stat() mode bits.
1002that may produce more accurate results than the bare
748When under C<use filetest 'access'> the above-mentioned filetests
1003L<C<stat>|/stat FILEHANDLE> mode bits.
749test whether the permission can(not) be granted using the
1004When under C<use filetest 'access'>, the above-mentioned filetests
750access(2) family of system calls. Also note that the C<-x> and C<-X> may
1005test whether the permission can(not) be granted using the L<access(2)>
1006family of system calls. Also note that the C<-x> and C<-X> tests may
7511007under this pragma return true even if there are no execute permission
7521008bits set (nor any extra execute permission ACLs). This strangeness is
753due to the underlying system calls' definitions. Note also that, due to
1009due to the underlying system calls' definitions. Note also that, due to
7541010the implementation of C<use filetest 'access'>, the C<_> special
7551011filehandle won't cache the results of the file tests when this pragma is
756in effect. Read the documentation for the C<filetest> pragma for more
1012in effect. Read the documentation for the L<C<filetest>|filetest>
757information.
1013pragma for more information.
7581014
7591015=end original
7601016
761ACL を使っている場合は、生の stat() モードビットより
1017ACL を使っている場合は、生の L<C<stat>|/stat FILEHANDLE> モードビットより
762精度の高い結果を作成する C<filetest> プラグマがあります。
1018精度の高い結果を作成する L<C<filetest>|filetest> プラグマがあります。
7631019C<use filetest 'access'> とした場合、上述したファイルテストは
764システムコールの access(2) ファミリーを使って権限が与えられているか
1020システムコールの L<access(2)> ファミリーを使って権限が与えられているか
7651021どうかをテストします。
766また、このプラグマが指定されている場合、C<-x> と C<-X> は
1022また、このプラグマが指定されている場合、C<-x> と C<-X> テスト
7671023たとえ実行許可ビット(または追加の実行許可 ACL)がセットされていない
7681024場合でも真を返すことに注意してください。
7691025この挙動は使用するシステムコールの定義によるものです。
7701026C<use filetest 'access'> の実装により、このプラグマが有効の場合は
7711027C<_> 特殊ファイルハンドルはファイルテストの結果をキャッシュしないことに
7721028注意してください。
773さらなる情報については C<filetest> プラグマのドキュメントを
1029さらなる情報については L<C<filetest>|filetest> プラグマのドキュメントを
7741030参照してください。
7751031
7761032=begin original
7771033
778The C<-T> and C<-B> switches work as follows. The first block or so of the
1034The C<-T> and C<-B> tests work as follows. The first block or so of
779file is examined for odd characters such as strange control codes or
1035the file is examined to see if it is valid UTF-8 that includes non-ASCII
780characters with the high bit set. If too many strange characters (>30%)
1036characters. If so, it's a C<-T> file. Otherwise, that same portion of
781are found, it's a C<-B> file; otherwise it's a C<-T> file. Also, any file
1037the file is examined for odd characters such as strange control codes or
782containing a zero byte in the first block is considered a binary file. If C<-T>
1038characters with the high bit set. If more than a third of the
783or C<-B> is used on a filehandle, the current IO buffer is examined
1039characters are strange, it's a C<-B> file; otherwise it's a C<-T> file.
1040Also, any file containing a zero byte in the examined portion is
1041considered a binary file. (If executed within the scope of a L<S<use
1042locale>|perllocale> which includes C<LC_CTYPE>, odd characters are
1043anything that isn't a printable nor space in the current locale.) If
1044C<-T> or C<-B> is used on a filehandle, the current IO buffer is
1045examined
7841046rather than the first block. Both C<-T> and C<-B> return true on an empty
7851047file, or a file at EOF when testing a filehandle. Because you have to
7861048read a file to do the C<-T> test, on most occasions you want to use a C<-f>
7871049against the file first, as in C<next unless -f $file && -T $file>.
7881050
7891051=end original
7901052
7911053ファイルテスト C<-T> と C<-B> の動作原理は、次のようになっています。
792ファイルの最初の数ブロックを調べて、変わった制御コードや
1054ファイルの最初の数ブロックを調べて、非 ASCII 文字を含む妥当な UTF-8 かどうかを
1055調べます。
1056もしそうなら、それは C<-T> ファイルです。
1057さもなければ、ファイルの同じ位置から、変わった制御コードや
7931058上位ビットがセットされているような、通常のテキストには現れない文字を探します。
794ような文字たくさん (>30%) 見つかるようあれば、
1059三分一以上がおかしな文字ならそれは C<-B> ファイルです;
795そのファイルは C<-B> ファイルであると判断されま;
1060さもなければ C<-T> ファイルです
796さもなけば C<-T> ファイルとなります。
1061また、調べた位置にヌル文字が含まファイルも、バイナリファイル
797最初のブロックにヌル文字が含まるファイルも、
1062みなさます。
798バイナリファイルとみなされます。
1063(C<LC_CTYPE> を含む L<S<use locale>|perllocale> のスコープの中で実行されると、
1064おかしな文字というのは現在のロケールで表示可能でもスペースでもないものです。)
7991065C<-T> や C<-B> をファイルハンドルに対して用いると、
8001066最初のブロックを調べる代わりに、IO バッファを調べます。
8011067調べたファイルの中身が何もないときや、
8021068ファイルハンドルを調べたときに EOF に達して
8031069いたときには、C<-T> も C<-B> も「真」を返します。
8041070C<-T> テストをするためにはファイルを読み込まないといけないので、
8051071たいていは C<next unless -f $file && -T $file> というような形で
8061072まず調べたいファイルに対して C<-f> を使いたいはずです。
8071073
8081074=begin original
8091075
810If any of the file tests (or either the C<stat> or C<lstat> operator) is given
1076If any of the file tests (or either the L<C<stat>|/stat FILEHANDLE> or
811the special filehandle consisting of a solitary underline, then the stat
1077L<C<lstat>|/lstat FILEHANDLE> operator) is given the special filehandle
812structure of the previous file test (or stat operator) is used, saving
1078consisting of a solitary underline, then the stat structure of the
813a system call. (This doesn't work with C<-t>, and you need to remember
1079previous file test (or L<C<stat>|/stat FILEHANDLE> operator) is used,
814that lstat() and C<-l> leave values in the stat structure for the
1080saving a system call. (This doesn't work with C<-t>, and you need to
815symbolic link, not the real file.) (Also, if the stat buffer was filled by
1081remember that L<C<lstat>|/lstat FILEHANDLE> and C<-l> leave values in
816an C<lstat> call, C<-T> and C<-B> will reset it with the results of C<stat _>).
1082the stat structure for the symbolic link, not the real file.) (Also, if
1083the stat buffer was filled by an L<C<lstat>|/lstat FILEHANDLE> call,
1084C<-T> and C<-B> will reset it with the results of C<stat _>).
8171085Example:
8181086
8191087=end original
8201088
821どのファイルテスト (あるいは、C<stat> や C<lstat>) 演算子にも、
1089どのファイルテスト (あるいは、L<C<stat>|/stat FILEHANDLE>
1090L<C<lstat>|/lstat FILEHANDLE>) 演算子にも、
8221091下線だけから成る特別なファイルハンドルを与えると、
823前回のファイルテスト (や stat) の stat 構造体が使われ、
1092前回のファイルテスト (や L<C<stat>|/stat FILEHANDLE> 演算子) の
824システムコールを省きます。
1093stat 構造体が使われ、システムコールを省きます。
825(C<-t> には使えませんし、lstat() や C<-l> は実ファイルではなく、
1094(C<-t> には使えませんし、L<C<lstat>|/lstat FILEHANDLE> や C<-l> は
826シンボリックリンクの情報を stat 構造体に残すことを
1095実ファイルではなく、シンボリックリンクの情報を stat 構造体に残すことを
8271096覚えておく必要があります。)
828(また、stat バッファが C<lstat> 呼び出しで埋まった場合、
1097(また、stat バッファが L<C<lstat>|/lstat FILEHANDLE> 呼び出しで埋まった場合、
8291098C<-T> と C<-B> の結果は C<stat _> の結果でリセットされます。
8301099例:
8311100
8321101 print "Can do.\n" if -r $a || -w _ || -x _;
8331102
8341103 stat($filename);
8351104 print "Readable\n" if -r _;
8361105 print "Writable\n" if -w _;
8371106 print "Executable\n" if -x _;
8381107 print "Setuid\n" if -u _;
8391108 print "Setgid\n" if -g _;
8401109 print "Sticky\n" if -k _;
8411110 print "Text\n" if -T _;
8421111 print "Binary\n" if -B _;
8431112
8441113=begin original
8451114
846As of Perl 5.9.1, as a form of purely syntactic sugar, you can stack file
1115As of Perl 5.10.0, as a form of purely syntactic sugar, you can stack file
8471116test operators, in a way that C<-f -w -x $file> is equivalent to
848C<-x $file && -w _ && -f _>. (This is only fancy fancy: if you use
1117C<-x $file && -w _ && -f _>. (This is only fancy syntax: if you use
8491118the return value of C<-f $file> as an argument to another filetest
8501119operator, no special magic will happen.)
8511120
8521121=end original
8531122
854Perl 5.9.1 から、純粋にシンタックスシュガーとして、ファイルテスト演算子を
1123Perl 5.10.0 から、純粋にシンタックスシュガーとして、ファイルテスト演算子を
8551124スタックさせることができるので、C<-f -w -x $file> は
8561125C<-x $file && -w _ && -f _> と等価です。
8571126(これは文法上だけの話です; もし C<-f $file> の返り値を他のファイルテスト
8581127演算子の引数として使う場合は、何の特別なことも起きません。)
8591128
1129=begin original
1130
1131Portability issues: L<perlport/-X>.
1132
1133=end original
1134
1135移植性の問題: L<perlport/-X>。
1136
1137=begin original
1138
1139To avoid confusing would-be users of your code with mysterious
1140syntax errors, put something like this at the top of your script:
1141
1142=end original
1143
1144あなたのコードのユーザーが不思議な文法エラーで混乱することを
1145避けるために、スクリプトの先頭に以下のようなことを書いてください:
1146
1147 use 5.010; # so filetest ops can stack
1148
8601149=item abs VALUE
8611150X<abs> X<absolute>
8621151
8631152=item abs
8641153
1154=for Pod::Functions absolute value function
1155
8651156=begin original
8661157
8671158Returns the absolute value of its argument.
868If VALUE is omitted, uses C<$_>.
1159If VALUE is omitted, uses L<C<$_>|perlvar/$_>.
8691160
8701161=end original
8711162
8721163引数の絶対値を返します。
873VALUE が省略された場合は、C<$_> を使います。
1164VALUE が省略された場合は、L<C<$_>|perlvar/$_> を使います。
8741165
8751166=item accept NEWSOCKET,GENERICSOCKET
8761167X<accept>
8771168
1169=for Pod::Functions accept an incoming socket connect
1170
8781171=begin original
8791172
880Accepts an incoming socket connect, just as accept(2)
1173Accepts an incoming socket connect, just as L<accept(2)>
8811174does. Returns the packed address if it succeeded, false otherwise.
8821175See the example in L<perlipc/"Sockets: Client/Server Communication">.
8831176
8841177=end original
8851178
886accept(2) システムコールと同様に、着信するソケットの接続を受け付けます。
1179L<accept(2)> システムコールと同様に、着信するソケットの接続を受け付けます。
8871180成功時にはパックされたアドレスを返し、失敗すれば偽を返します。
888L<perlipc/"Sockets: Client/Server Communication"> の
1181L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
889例を参照してください。
8901182
8911183=begin original
8921184
8931185On systems that support a close-on-exec flag on files, the flag will
8941186be set for the newly opened file descriptor, as determined by the
895value of $^F. See L<perlvar/$^F>.
1187value of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>.
8961188
8971189=end original
8981190
8991191ファイルに対する close-on-exec フラグをサポートしているシステムでは、
900フラグは $^F の値で決定される、新しくオープンされたファイル記述子に対して
1192フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた
901セットされます。
1193ファイル記述子に対してセットされます。
9021194L<perlvar/$^F> を参照してください。
9031195
9041196=item alarm SECONDS
9051197X<alarm>
9061198X<SIGALRM>
9071199X<timer>
9081200
9091201=item alarm
9101202
1203=for Pod::Functions schedule a SIGALRM
1204
9111205=begin original
9121206
9131207Arranges to have a SIGALRM delivered to this process after the
9141208specified number of wallclock seconds has elapsed. If SECONDS is not
915specified, the value stored in C<$_> is used. (On some machines,
1209specified, the value stored in L<C<$_>|perlvar/$_> is used. (On some
916unfortunately, the elapsed time may be up to one second less or more
1210machines, unfortunately, the elapsed time may be up to one second less
917than you specified because of how seconds are counted, and process
1211or more than you specified because of how seconds are counted, and
918scheduling may delay the delivery of the signal even further.)
1212process scheduling may delay the delivery of the signal even further.)
9191213
9201214=end original
9211215
9221216指定した壁時計秒数が経過した後に、自プロセスに SIGALRM が
923送られてくるようにします。SECONDS が指定されていない場合は、
1217送られてくるようにします。
924C<$_>に格納されている値を使います。
1218SECONDS が指定されていない場合は、L<C<$_>|perlvar/$_> に格納されている値を
925(マシンによっては、秒の数え方が異なるため、指定した秒数よりも
1219使います。
926最大で 1 秒ずれます。)
1220(マシンによっては、秒の数え方が異なるため、指定した秒数よりも最大で
12211 秒ずれます。)
9271222
9281223=begin original
9291224
9301225Only one timer may be counting at once. Each call disables the
9311226previous timer, and an argument of C<0> may be supplied to cancel the
9321227previous timer without starting a new one. The returned value is the
9331228amount of time remaining on the previous timer.
9341229
9351230=end original
9361231
9371232一度には一つのタイマだけが設定可能です。
9381233呼び出しを行なう度に、以前のタイマを無効にしますし、
9391234新しくタイマを起動しないで以前のタイマをキャンセルするために
9401235引数に C<0> を指定して呼び出すことができます。
9411236以前のタイマの残り時間が、返り値となります。
9421237
9431238=begin original
9441239
945For delays of finer granularity than one second, the Time::HiRes module
1240For delays of finer granularity than one second, the L<Time::HiRes> module
9461241(from CPAN, and starting from Perl 5.8 part of the standard
947distribution) provides ualarm(). You may also use Perl's four-argument
1242distribution) provides
948version of select() leaving the first three arguments undefined, or you
1243L<C<ualarm>|Time::HiRes/ualarm ( $useconds [, $interval_useconds ] )>.
949might be able to use the C<syscall> interface to access setitimer(2) if
1244You may also use Perl's four-argument version of
950your system supports it. See L<perlfaq8> for details.
1245L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> leaving the first three
1246arguments undefined, or you might be able to use the
1247L<C<syscall>|/syscall NUMBER, LIST> interface to access L<setitimer(2)>
1248if your system supports it. See L<perlfaq8> for details.
9511249
9521250=end original
9531251
9541 秒より精度の高いスリープを行なうには、
12521 秒より精度の高いスリープを行なうには、L<Time::HiRes> モジュール(CPAN から、
955Time::HiRes モジュール(CPAN から、また Perl 5.8 からは
1253また Perl 5.8 からは標準配布されています) が
956標準配布されています) が ualarm() を提供します。
1254L<C<usleep>|Time::HiRes/usleep ( $useconds )> を提供します。
957Perl の 4 引数版 select() を最初の 3 引数を未定義にして使うか、
1255Perl の 4 引数版 L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を最初の
958setitimer(2) をサポートしているシステムでは、Perl の
12563 引数を未定義にして使うか、L<setitimer(2)> をサポートしているシステムでは、
959C<syscall> インタフェースを使ってアクセスすることもできます。
1257Perl の L<C<syscall>|/syscall NUMBER, LIST> インタフェースを使って
1258アクセスすることもできます。
9601259詳しくは L<perlfaq8> を参照してください。
9611260
9621261=begin original
9631262
964It is usually a mistake to intermix C<alarm> and C<sleep> calls, because
1263It is usually a mistake to intermix L<C<alarm>|/alarm SECONDS> and
965C<sleep> may be internally implemented on your system with C<alarm>.
1264L<C<sleep>|/sleep EXPR> calls, because L<C<sleep>|/sleep EXPR> may be
1265internally implemented on your system with L<C<alarm>|/alarm SECONDS>.
9661266
9671267=end original
9681268
969C<alarm> と C<sleep> を混ぜて使うのは普通は間違いです; なぜなら、
1269L<C<alarm>|/alarm SECONDS> L<C<sleep>|/sleep EXPR> を混ぜて使うのは
970C<sleep> は内部的に C<alarm> を使って内部的に実装されているかも
1270普通は間違いです; なぜなら、L<C<sleep>|/sleep EXPR> 内部的に
1271L<C<alarm>|/alarm SECONDS> を使って内部的に実装されているかも
9711272しれないからです。
9721273
9731274=begin original
9741275
975If you want to use C<alarm> to time out a system call you need to use an
1276If you want to use L<C<alarm>|/alarm SECONDS> to time out a system call
976C<eval>/C<die> pair. You can't rely on the alarm causing the system call to
1277you need to use an L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> pair. You
977fail with C<$!> set to C<EINTR> because Perl sets up signal handlers to
1278can't rely on the alarm causing the system call to fail with
978restart system calls on some systems. Using C<eval>/C<die> always works,
1279L<C<$!>|perlvar/$!> set to C<EINTR> because Perl sets up signal handlers
979modulo the caveats given in L<perlipc/"Signals">.
1280to restart system calls on some systems. Using
1281L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> always works, modulo the
1282caveats given in L<perlipc/"Signals">.
9801283
9811284=end original
9821285
983C<alarm> をシステムコールの時間切れのために使いたいなら、
1286L<C<alarm>|/alarm SECONDS> をシステムコールの時間切れのために使いたいなら、
984C<eval>/C<die> のペアで使う必要があります。
1287L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> のペアで使う必要があります。
985システムコールが失敗したときに C<$!> に C<EINTR> がセットされることに
1288システムコールが失敗したときに L<C<$!>|perlvar/$!> に C<EINTR> が
986頼ってはいけませんなぜならシステムによっては Perl は
1289セットされることに頼ってはいけません; なぜならシステムによっては Perl は
9871290システムコールを再開するためにシグナルハンドラを設定するからです。
988C<eval>/C<die> は常にうまく動きます
1291L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> は常にうまく動きます;
989注意点については L<perlipc/"Signals"> を参照してさい。
1292注意点については L<perlipc/"Signals"> を参照してください。
9901293
9911294 eval {
9921295 local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
9931296 alarm $timeout;
994 $nread = sysread SOCKET, $buffer, $size;
1297 my $nread = sysread $socket, $buffer, $size;
9951298 alarm 0;
9961299 };
9971300 if ($@) {
9981301 die unless $@ eq "alarm\n"; # propagate unexpected errors
9991302 # timed out
10001303 }
10011304 else {
10021305 # didn't
10031306 }
10041307
10051308=begin original
10061309
10071310For more information see L<perlipc>.
10081311
10091312=end original
10101313
10111314さらなる情報については L<perlipc> を参照してください。
10121315
1316=begin original
1317
1318Portability issues: L<perlport/alarm>.
1319
1320=end original
1321
1322移植性の問題: L<perlport/alarm>。
1323
10131324=item atan2 Y,X
10141325X<atan2> X<arctangent> X<tan> X<tangent>
10151326
1327=for Pod::Functions arctangent of Y/X in the range -PI to PI
1328
10161329=begin original
10171330
10181331Returns the arctangent of Y/X in the range -PI to PI.
10191332
10201333=end original
10211334
10221335-πからπの範囲で Y/X の逆正接を返します。
10231336
10241337=begin original
10251338
1026For the tangent operation, you may use the C<Math::Trig::tan>
1339For the tangent operation, you may use the
1027function, or use the familiar relation:
1340L<C<Math::Trig::tan>|Math::Trig/B<tan>> function, or use the familiar
1341relation:
10281342
10291343=end original
10301344
1031正接を求めたいときは、C<Math::Trig::tan> を使うか、
1345正接を求めたいときは、L<C<Math::Trig::tan>|Math::Trig/B<tan>> を使うか、
10321346以下のよく知られた関係を使ってください。
10331347
10341348 sub tan { sin($_[0]) / cos($_[0]) }
10351349
10361350=begin original
10371351
10381352The return value for C<atan2(0,0)> is implementation-defined; consult
1039your atan2(3) manpage for more information.
1353your L<atan2(3)> manpage for more information.
10401354
10411355=end original
10421356
10431357C<atan2(0,0)> の返り値は実装依存です; さらなる情報については
1044atan2(3) man ページを参照してください。
1358L<atan2(3)> man ページを参照してください。
10451359
1360=begin original
1361
1362Portability issues: L<perlport/atan2>.
1363
1364=end original
1365
1366移植性の問題: L<perlport/atan2>。
1367
10461368=item bind SOCKET,NAME
10471369X<bind>
10481370
1371=for Pod::Functions binds an address to a socket
1372
10491373=begin original
10501374
1051Binds a network address to a socket, just as bind(2)
1375Binds a network address to a socket, just as L<bind(2)>
10521376does. Returns true if it succeeded, false otherwise. NAME should be a
10531377packed address of the appropriate type for the socket. See the examples in
10541378L<perlipc/"Sockets: Client/Server Communication">.
10551379
10561380=end original
10571381
1058bind(2) システムコールと同様に、ネットワークアドレスをソケットに結び付けます。
1382L<bind(2)> システムコールと同様に、ネットワークアドレスをソケットに
1059成功時には真を返し、失敗時には偽を返します。
1383結び付けます。
1060NAME は、ソケットに対する、適切な型のパックれたアドレスでなければなりせん
1384成功時に真を、さなければ偽を返し
1385NAME は、ソケットに対する、適切な型のパックされた
1386アドレスでなければなりません。
10611387L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
10621388
10631389=item binmode FILEHANDLE, LAYER
10641390X<binmode> X<binary> X<text> X<DOS> X<Windows>
10651391
10661392=item binmode FILEHANDLE
10671393
1394=for Pod::Functions prepare binary files for I/O
1395
10681396=begin original
10691397
10701398Arranges for FILEHANDLE to be read or written in "binary" or "text"
10711399mode on systems where the run-time libraries distinguish between
10721400binary and text files. If FILEHANDLE is an expression, the value is
10731401taken as the name of the filehandle. Returns true on success,
1074otherwise it returns C<undef> and sets C<$!> (errno).
1402otherwise it returns L<C<undef>|/undef EXPR> and sets
1403L<C<$!>|perlvar/$!> (errno).
10751404
10761405=end original
10771406
10781407バイナリファイルとテキストファイルを区別する OS において、
10791408FILEHANDLE を「バイナリ」または「テキスト」で読み書きするように
10801409指定します。
10811410FILEHANDLE が式である場合には、その式の値がファイルハンドルの
10821411名前として使われます。
1083成功時には真を返し、失敗時には C<undef> を返して C<$!> (errno) 設定ます。
1412成功時には真を返し、失敗時には L<C<undef>|/undef EXPR> を
1413L<C<$!>|perlvar/$!> (errno) を設定します。
10841414
10851415=begin original
10861416
1087On some systems (in general, DOS- and Windows-based systems) binmode()
1417On some systems (in general, DOS- and Windows-based systems)
1088is necessary when you're not working with a text file. For the sake
1418L<C<binmode>|/binmode FILEHANDLE, LAYER> is necessary when you're not
1089of portability it is a good idea always to use it when appropriate,
1419working with a text file. For the sake of portability it is a good idea
1090and never to use it when it isn't appropriate. Also, people can
1420always to use it when appropriate, and never to use it when it isn't
1091set their I/O to be by default UTF8-encoded Unicode, not bytes.
1421appropriate. Also, people can set their I/O to be by default
1422UTF8-encoded Unicode, not bytes.
10921423
10931424=end original
10941425
1095テキストファイルでないものを扱う場合に binmode() が必要な
1426テキストファイルでないものを扱う場合に
1427L<C<binmode>|/binmode FILEHANDLE, LAYER> が必要な
10961428システムもあります(一般的には DOS と Windows ベースのシステムです)。
10971429移植性のために、適切なときには常にこれを使い、適切でないときには
10981430決して使わないというのは良い考えです。
10991431また、デフォルトとして I/O を bytes ではなく UTF-8 エンコードされた
11001432Unicode にセットすることも出来ます。
11011433
11021434=begin original
11031435
1104In other words: regardless of platform, use binmode() on binary data,
1436In other words: regardless of platform, use
1105like images, for example.
1437L<C<binmode>|/binmode FILEHANDLE, LAYER> on binary data, like images,
1438for example.
11061439
11071440=end original
11081441
11091442言い換えると: プラットフォームに関わらず、
1110例えばイメージのようなバイナリファイルに対しては binmode() を
1443例えばイメージのようなバイナリファイルに対しては
1111使ってください。
1444L<C<binmode>|/binmode FILEHANDLE, LAYER> を使ってください。
11121445
11131446=begin original
11141447
11151448If LAYER is present it is a single string, but may contain multiple
1116directives. The directives alter the behaviour of the filehandle.
1449directives. The directives alter the behaviour of the filehandle.
11171450When LAYER is present, using binmode on a text file makes sense.
11181451
11191452=end original
11201453
11211454LAYER が存在すると、それは単一の文字列ですが、複数の指示子を
11221455含むことができます。
11231456指示子はファイルハンドルの振る舞いを変更します。
11241457LAYER が存在すると、テキストファイルでの binmode が意味を持ちます。
11251458
11261459=begin original
11271460
11281461If LAYER is omitted or specified as C<:raw> the filehandle is made
1129suitable for passing binary data. This includes turning off possible CRLF
1462suitable for passing binary data. This includes turning off possible CRLF
11301463translation and marking it as bytes (as opposed to Unicode characters).
11311464Note that, despite what may be implied in I<"Programming Perl"> (the
11321465Camel, 3rd edition) or elsewhere, C<:raw> is I<not> simply the inverse of C<:crlf>.
11331466Other layers that would affect the binary nature of the stream are
1134I<also> disabled. See L<PerlIO>, L<perlrun>, and the discussion about the
1467I<also> disabled. See L<PerlIO>, L<perlrun>, and the discussion about the
11351468PERLIO environment variable.
11361469
11371470=end original
11381471
11391472LAYER が省略されたり、C<:raw> が指定されると、ファイルハンドルはバイナリ
11401473データの通過に適するように設定されます。
11411474これには CRLF 変換をオフにしたり、それぞれを(Unicode 文字ではなく)
11421475バイトであるとマークしたりすることを含みます。
11431476I<"プログラミング Perl">(ラクダ本第三版) やその他で暗示されているにも関わらず、
11441477C<:raw> は単なる C<:crlf> の I<逆ではありません>。
11451478ストリームのバイナリとしての性質に影響を与える
11461479I<その他の層も無効にされます>。
11471480L<PerlIO>, L<perlrun> およびPERLIO 環境変数に関する議論を参照してください。
11481481
11491482=begin original
11501483
11511484The C<:bytes>, C<:crlf>, C<:utf8>, and any other directives of the
1152form C<:...>, are called I/O I<layers>. The C<open> pragma can be used to
1485form C<:...>, are called I/O I<layers>. The L<open> pragma can be used to
1153establish default I/O layers. See L<open>.
1486establish default I/O layers.
11541487
11551488=end original
11561489
11571490C<:bytes>, C<:crlf>, and C<:utf8>, 及びその他の C<:...> 形式の指示子は
11581491I/O I<層> が呼び出されます。
1159C<open> プラグマはデフォルト I/O 層を指定するために使われます。
1492L<open> プラグマはデフォルト I/O 層を指定するために使われます。
1160L<open> を参照してください。
11611493
11621494=begin original
11631495
1164I<The LAYER parameter of the binmode() function is described as "DISCIPLINE"
1496I<The LAYER parameter of the L<C<binmode>|/binmode FILEHANDLE, LAYER>
1165in "Programming Perl, 3rd Edition". However, since the publishing of this
1497function is described as "DISCIPLINE" in "Programming Perl, 3rd
1166book, by many known as "Camel III", the consensus of the naming of this
1498Edition". However, since the publishing of this book, by many known as
1167functionality has moved from "discipline" to "layer". All documentation
1499"Camel III", the consensus of the naming of this functionality has moved
1168of this version of Perl therefore refers to "layers" rather than to
1500from "discipline" to "layer". All documentation of this version of Perl
1169"disciplines". Now back to the regularly scheduled documentation...>
1501therefore refers to "layers" rather than to "disciplines". Now back to
1502the regularly scheduled documentation...>
11701503
11711504=end original
11721505
1173I<binmode() 関数の LAYER パラメータは 「プログラミングPerl 第3版」で
1506I<L<C<binmode>|/binmode FILEHANDLE, LAYER> 関数の LAYER パラメータは
1507「プログラミングPerl 第 3 版」では
11741508「ディシプリン(DISCIPLINE)」と表現されていました。
1175しかし、「ラクダ本第3版」として知られているこの本の出版後、この機能の名前は
1509しかし、「ラクダ本第 3 版」として知られているこの本の出版後、この機能の名前は
11761510「ディシプリン」から「層」に変更することで合意されました。
11771511従って、このバージョンの Perl の全ての文書では「ディシプリン」ではなく
1178「層」と記述されています。では通常の解説に戻ります…>
1512「層」と記述されています。では通常の解説に戻ります…>
11791513
11801514=begin original
11811515
11821516To mark FILEHANDLE as UTF-8, use C<:utf8> or C<:encoding(UTF-8)>.
11831517C<:utf8> just marks the data as UTF-8 without further checking,
11841518while C<:encoding(UTF-8)> checks the data for actually being valid
1185UTF-8. More details can be found in L<PerlIO::encoding>.
1519UTF-8. More details can be found in L<PerlIO::encoding>.
11861520
11871521=end original
11881522
11891523FILEHANDLE が UTF-8 であるというマークをつけるには、C<:utf8> か
11901524C<:encoding(UTF-8)> を使ってください。
11911525C<:utf8> は、さらなるチェックなしにデータが UTF-8 としてマークしますが、
11921526C<:encoding(UTF-8)> はデータが実際に有効な UTF-8 かどうかをチェックします。
11931527さらなる詳細は L<PerlIO::encoding> にあります。
11941528
11951529=begin original
11961530
1197In general, binmode() should be called after open() but before any I/O
1531In general, L<C<binmode>|/binmode FILEHANDLE, LAYER> should be called
1198is done on the filehandle. Calling binmode() normally flushes any
1532after L<C<open>|/open FILEHANDLE,EXPR> but before any I/O is done on the
1199pending buffered output data (and perhaps pending input data) on the
1533filehandle. Calling L<C<binmode>|/binmode FILEHANDLE, LAYER> normally
1200handle. An exception to this is the C<:encoding> layer that
1534flushes any pending buffered output data (and perhaps pending input
1201changes the default character encoding of the handle; see L</open>.
1535data) on the handle. An exception to this is the C<:encoding> layer
1536that changes the default character encoding of the handle.
12021537The C<:encoding> layer sometimes needs to be called in
1203mid-stream, and it doesn't flush the stream. The C<:encoding>
1538mid-stream, and it doesn't flush the stream. C<:encoding>
12041539also implicitly pushes on top of itself the C<:utf8> layer because
12051540internally Perl operates on UTF8-encoded Unicode characters.
12061541
12071542=end original
12081543
1209一般的に binmode() は open() を呼び出した後、このファイルハンドルに対する
1544一般的に L<C<binmode>|/binmode FILEHANDLE, LAYER> は
1545L<C<open>|/open FILEHANDLE,EXPR> を呼び出した後、このファイルハンドルに対する
12101546I/O 操作をする前に呼び出すべきです。
1211binmode() を呼び出すと、普通はこのファイルハンドルに対して
1547L<C<binmode>|/binmode FILEHANDLE, LAYER> を呼び出すと、普通はこの
1212バッファリングされている全ての出力データ
1548ファイルハンドルに対してバッファリングされている全ての出力データ
12131549(およびおそらくは入力データ)をフラッシュします。
12141550例外は、このハンドルに対するデフォルト文字エンコーディングを変更する
1215C<:encoding> 層です; L</open> を参照してください
1551C<:encoding> 層です。
12161552C<:encoding> 層はストリームの途中で呼び出す必要があることがあり、
12171553それによってストリームはフラッシュされません。
12181554Perl は内部で UTF-8 エンコードされた Unicode 文字を操作しているので、
12191555C<:encoding> は暗黙のうちに自身を C<:utf8> 層の上に押し上げます。
12201556
12211557=begin original
12221558
12231559The operating system, device drivers, C libraries, and Perl run-time
12241560system all conspire to let the programmer treat a single
12251561character (C<\n>) as the line terminator, irrespective of external
12261562representation. On many operating systems, the native text file
12271563representation matches the internal representation, but on some
12281564platforms the external representation of C<\n> is made up of more than
12291565one character.
12301566
12311567=end original
12321568
12331569オペレーティングシステム、デバイスドライバ、C ライブラリ、
12341570Perl ランタイムシステムは全て、プログラマが外部表現に関わらず
123515711 文字 (C<\n>) を行終端として扱えるように協調作業します。
12361572多くのオペレーティングシステムでは、ネイティブテキストファイル表現は
12371573内部表現と同じですが、C<\n> の外部表現が複数文字になる
12381574プラットフォームもあります。
12391575
12401576=begin original
12411577
12421578All variants of Unix, Mac OS (old and new), and Stream_LF files on VMS use
12431579a single character to end each line in the external representation of text
12441580(even though that single character is CARRIAGE RETURN on old, pre-Darwin
1245flavors of Mac OS, and is LINE FEED on Unix and most VMS files). In other
1581flavors of Mac OS, and is LINE FEED on Unix and most VMS files). In other
12461582systems like OS/2, DOS, and the various flavors of MS-Windows, your program
12471583sees a C<\n> as a simple C<\cJ>, but what's stored in text files are the
1248two characters C<\cM\cJ>. That means that if you don't use binmode() on
1584two characters C<\cM\cJ>. That means that if you don't use
1249these systems, C<\cM\cJ> sequences on disk will be converted to C<\n> on
1585L<C<binmode>|/binmode FILEHANDLE, LAYER> on these systems, C<\cM\cJ>
1250input, and any C<\n> in your program will be converted back to C<\cM\cJ> on
1586sequences on disk will be converted to C<\n> on input, and any C<\n> in
1251output. This is what you want for text files, but it can be disastrous for
1587your program will be converted back to C<\cM\cJ> on output. This is
1252binary files.
1588what you want for text files, but it can be disastrous for binary files.
12531589
12541590=end original
12551591
12561592全ての Unix 系、(新旧の)Mac OS、VMS の Stream_LF ファイルは
12571593テキストの外部表現として各行の末尾に一つの文字を
12581594使っています(しかしその文字は古い Darwin 以前の Mac OS では復帰で、
12591595Unix とほとんどのVMS のファイルでは改行です)。
12601596VMS, MS-DOS, MS-Windows 系といったその他のシステムでは、
12611597プログラムからは C<\n> は単純に C<\cJ> に見えますが、
12621598テキストファイルとして保存される場合は C<\cM\cJ> の 2 文字になります。
1263つまり、もしこれらのシステムで binmode()使わないと、
1599つまり、もしこれらのシステムで L<C<binmode>|/binmode FILEHANDLE, LAYER>
1264ディスク上の C<\cM\cJ> という並びは入力時に C<\n> に変換され、
1600使わないと、ディスク上の C<\cM\cJ> という並びは入力時に C<\n> に変換され、
12651601プログラムが出力した全ての C<\n> は C<\cM\cJ> に逆変換されます。
12661602これはテキストファイルの場合は思い通りの結果でしょうが、
12671603バイナリファイルの場合は悲惨です。
12681604
12691605=begin original
12701606
1271Another consequence of using binmode() (on some systems) is that
1607Another consequence of using L<C<binmode>|/binmode FILEHANDLE, LAYER>
1272special end-of-file markers will be seen as part of the data stream.
1608(on some systems) is that special end-of-file markers will be seen as
1273For systems from the Microsoft family this means that, if your binary
1609part of the data stream. For systems from the Microsoft family this
1274data contain C<\cZ>, the I/O subsystem will regard it as the end of
1610means that, if your binary data contain C<\cZ>, the I/O subsystem will
1275the file, unless you use binmode().
1611regard it as the end of the file, unless you use
1612L<C<binmode>|/binmode FILEHANDLE, LAYER>.
12761613
12771614=end original
12781615
1279binmode() を(いくつかのシステムで)使うことによるその他の作用としては、
1616L<C<binmode>|/binmode FILEHANDLE, LAYER> を(いくつかのシステムで)
1280特別なファイル終端マーカーがデータストリームの一部として
1617使うことによるその他の作用としては、特別なファイル終端マーカーが
1281見られることです。
1618データストリームの一部として見られることです。
1282Microsoft ファミリーのシステムでは、binmode() を使っていないと
1619Microsoft ファミリーのシステムでは、
1283もしバイナリデータに C<\cZ> が含まれていきにI/O サブシステムが
1620L<C<binmode>|/binmode FILEHANDLE, LAYER> を使っていないと、
1284これをファイル終端とみなすことを意味します。
1621バイナリデータに C<\cZ> が含れていたときに、
1622I/O サブシステムがこれをファイル終端とみなすことを意味します。
12851623
12861624=begin original
12871625
1288binmode() is important not only for readline() and print() operations,
1626L<C<binmode>|/binmode FILEHANDLE, LAYER> is important not only for
1289but also when using read(), seek(), sysread(), syswrite() and tell()
1627L<C<readline>|/readline EXPR> and L<C<print>|/print FILEHANDLE LIST>
1290(see L<perlport> for more details). See the C<$/> and C<$\> variables
1628operations, but also when using
1291in L<perlvar> for how to manually set your input and output
1629L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1630L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1631L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1632L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> and
1633L<C<tell>|/tell FILEHANDLE> (see L<perlport> for more details). See the
1634L<C<$E<sol>>|perlvar/$E<sol>> and L<C<$\>|perlvar/$\> variables in
1635L<perlvar> for how to manually set your input and output
12921636line-termination sequences.
12931637
12941638=end original
12951639
1296binmode() は readline() と print() 操作にだけではなく、
1640L<C<binmode>|/binmode FILEHANDLE, LAYER> L<C<readline>|/readline EXPR> と
1297read(), seek(), sysread(), syswrite(), tell() を使うときも重要
1641L<C<print>|/print FILEHANDLE LIST> 操作だけはなく、
1642L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1643L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1644L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1645L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1646L<C<tell>|/tell FILEHANDLE> を使うときにも重要です
12981647(詳細は L<perlport> を参照してください)。
12991648入出力の行端末シーケンスを手動でセットする方法については
1300L<perlvar> の C<$/> 変数と C<$\> 変数を参照してください。
1649L<perlvar> の L<C<$E<sol>>|perlvar/$E<sol>> 変数
1650L<C<$\>|perlvar/$\> 変数を参照してください。
13011651
1652=begin original
1653
1654Portability issues: L<perlport/binmode>.
1655
1656=end original
1657
1658移植性の問題: L<perlport/binmode>。
1659
13021660=item bless REF,CLASSNAME
13031661X<bless>
13041662
13051663=item bless REF
13061664
1665=for Pod::Functions create an object
1666
13071667=begin original
13081668
13091669This function tells the thingy referenced by REF that it is now an object
13101670in the CLASSNAME package. If CLASSNAME is omitted, the current package
1311is used. Because a C<bless> is often the last thing in a constructor,
1671is used. Because a L<C<bless>|/bless REF,CLASSNAME> is often the last
1312it returns the reference for convenience. Always use the two-argument
1672thing in a constructor, it returns the reference for convenience.
1313version if a derived class might inherit the function doing the blessing.
1673Always use the two-argument version if a derived class might inherit the
1314See L<perltoot> and L<perlobj> for more about the blessing (and blessings)
1674method doing the blessing. See L<perlobj> for more about the blessing
1315of objects.
1675(and blessings) of objects.
13161676
13171677=end original
13181678
13191679この関数は、REF で渡された オブジェクトに対し、
13201680CLASSNAME 内のオブジェクトとなったことを伝えます。
13211681CLASSNAME が省略された場合には、その時点のパッケージとなります。
1322C<bless> は通常、コンストラクタの最後に置かれますので、
1682L<C<bless>|/bless REF,CLASSNAME> は通常、コンストラクタの最後に
1323簡便のためにそのリファレンスを返します。
1683置かれますので、簡便のためにそのリファレンスを返します。
1324派生クラスが bless される関数を継承する場合は、
1684派生クラスが bless されるメソッドを継承する場合は、
13251685常に 2 引数版を使ってください。
1326オブジェクトの bless (や再 bless) について、
1686オブジェクトの bless (や再 bless) について、詳しくは と L<perlobj> を
1327詳しくは L<perltoot> と L<perlobj> を参照してください。
1687参照してください。
13281688
13291689=begin original
13301690
13311691Consider always blessing objects in CLASSNAMEs that are mixed case.
13321692Namespaces with all lowercase names are considered reserved for
1333Perl pragmata. Builtin types have all uppercase names. To prevent
1693Perl pragmas. Builtin types have all uppercase names. To prevent
13341694confusion, you may wish to avoid such package names as well. Make sure
13351695that CLASSNAME is a true value.
13361696
13371697=end original
13381698
13391699大文字小文字が混じっている CLASSNAME のオブジェクトは常に bless することを
13401700考慮してください。
13411701全て小文字の名前を持つ名前空間は Perl プラグマのために予約されています。
13421702組み込みの型は全て大文字の名前を持ちます。
13431703混乱を避けるために、
13441704パッケージ名としてこのような名前は避けるべきです。
13451705CLASSNAME は真の値を持つようにしてください。
13461706
13471707=begin original
13481708
13491709See L<perlmod/"Perl Modules">.
13501710
13511711=end original
13521712
1353L<perlmod/"Perl Modules"> を参照してさい。
1713L<perlmod/"Perl Modules"> を参照してください。
13541714
13551715=item break
13561716
1717=for Pod::Functions +switch break out of a C<given> block
1718
13571719=begin original
13581720
1359Break out of a C<given()> block.
1721Break out of a C<given> block.
13601722
13611723=end original
13621724
1363C<given()> ブロックから脱出します。
1725C<given> ブロックから脱出します。
13641726
13651727=begin original
13661728
1367This keyword is enabled by the C<"switch"> feature: see
1729L<C<break>|/break> is available only if the
1368L<feature> for more information. Alternately, include a C<use
1730L<C<"switch"> feature|feature/The 'switch' feature> is enabled or if it
1369v5.10> or later to the current scope.
1731is prefixed with C<CORE::>. The
1732L<C<"switch"> feature|feature/The 'switch' feature> is enabled
1733automatically with a C<use v5.10> (or higher) declaration in the current
1734scope.
13701735
13711736=end original
13721737
1373このキーワードは C<"switch"> 機能によって有効になります:
1738L<C<break>|/break> は、L<C<"switch"> 機能|feature/The 'switch' feature> が
1374さらなる情報については L<feature> を参照してください
1739有効か、C<CORE::> 接頭辞使ったときにのみ利用可能です
1375あるいは、現在のスコープに C<use v5.10> 以降を含めてください。
1740L<C<"switch"> 機能|feature/The 'switch' feature> は、現在のスコープ
1741C<use v5.10> (またはそれ以上) 宣言があると自動的に有効になります。
13761742
13771743=item caller EXPR
13781744X<caller> X<call stack> X<stack> X<stack trace>
13791745
13801746=item caller
13811747
1748=for Pod::Functions get context of the current subroutine call
1749
13821750=begin original
13831751
1384Returns the context of the current subroutine call. In scalar context,
1752Returns the context of the current pure perl subroutine call. In scalar
1385returns the caller's package name if there I<is> a caller (that is, if
1753context, returns the caller's package name if there I<is> a caller (that is, if
1386we're in a subroutine or C<eval> or C<require>) and the undefined value
1754we're in a subroutine or L<C<eval>|/eval EXPR> or
1387otherwise. In list context, returns
1755L<C<require>|/require VERSION>) and the undefined value otherwise.
1756caller never returns XS subs and they are skipped. The next pure perl
1757sub will appear instead of the XS sub in caller's return values. In
1758list context, caller returns
13881759
13891760=end original
13901761
1391その時点のサブルーチン呼び出しのコンテキストを返します。
1762その時点のピュア perl サブルーチン呼び出しのコンテキストを返します。
13921763スカラコンテキストでは、呼び元が I<ある> 場合
1393(サブルーチン、C<eval>、C<require> の中にいるとき) には
1764(サブルーチン、L<C<eval>|/eval EXPR>L<C<require>|/require VERSION> の中に
1394呼び出し元のパッケージ名を返し、その他のときには未定義値を返します。
1765いるとき) には呼び出し元のパッケージ名を返し、
1395リストコンテキストで、以下を返します:
1766その他のときに未定義値を返します
1767caller は XS サブルーチンを返すことはなく、それらは飛ばされます。
1768XS サブルーチンの代わりに次のピュア perl サブルーチンが caller の返り値に
1769なります。
1770リストコンテキストでは、caller は以下を返します:
13961771
1397 # 0 1 2
1772 # 0 1 2
1398 ($package, $filename, $line) = caller;
1773 my ($package, $filename, $line) = caller;
13991774
14001775=begin original
14011776
14021777With EXPR, it returns some extra information that the debugger uses to
14031778print a stack trace. The value of EXPR indicates how many call frames
14041779to go back before the current one.
14051780
14061781=end original
14071782
14081783EXPR を付けると、デバッガがスタックトレースを表示するために使う情報を返します。
14091784EXPR の値は、現状から数えて、
14101785いくつ前のコールフレームまで戻るかを示します。
14111786
14121787 # 0 1 2 3 4
1413 ($package, $filename, $line, $subroutine, $hasargs,
1788 my ($package, $filename, $line, $subroutine, $hasargs,
14141789
14151790 # 5 6 7 8 9 10
14161791 $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash)
1417 = caller($i);
1792 = caller($i);
14181793
14191794=begin original
14201795
1421Here $subroutine may be C<(eval)> if the frame is not a subroutine
1796Here, $subroutine is the function that the caller called (rather than the
1422call, but an C<eval>. In such a case additional elements $evaltext and
1797function containing the caller). Note that $subroutine may be C<(eval)> if
1423C<$is_require> are set: C<$is_require> is true if the frame is created by a
1798the frame is not a subroutine call, but an L<C<eval>|/eval EXPR>. In
1424C<require> or C<use> statement, $evaltext contains the text of the
1799such a case additional elements $evaltext and C<$is_require> are set:
1425C<eval EXPR> statement. In particular, for an C<eval BLOCK> statement,
1800C<$is_require> is true if the frame is created by a
1426$subroutine is C<(eval)>, but $evaltext is undefined. (Note also that
1801L<C<require>|/require VERSION> or L<C<use>|/use Module VERSION LIST>
1427each C<use> statement creates a C<require> frame inside an C<eval EXPR>
1802statement, $evaltext contains the text of the C<eval EXPR> statement.
1428frame.) $subroutine may also be C<(unknown)> if this particular
1803In particular, for an C<eval BLOCK> statement, $subroutine is C<(eval)>,
1429subroutine happens to have been deleted from the symbol table.
1804but $evaltext is undefined. (Note also that each
1430C<$hasargs> is true if a new instance of C<@_> was set up for the frame.
1805L<C<use>|/use Module VERSION LIST> statement creates a
1806L<C<require>|/require VERSION> frame inside an C<eval EXPR> frame.)
1807$subroutine may also be C<(unknown)> if this particular subroutine
1808happens to have been deleted from the symbol table. C<$hasargs> is true
1809if a new instance of L<C<@_>|perlvar/@_> was set up for the frame.
14311810C<$hints> and C<$bitmask> contain pragmatic hints that the caller was
1432compiled with. The C<$hints> and C<$bitmask> values are subject to change
1811compiled with. C<$hints> corresponds to L<C<$^H>|perlvar/$^H>, and
1433between versions of Perl, and are not meant for external use.
1812C<$bitmask> corresponds to
1813L<C<${^WARNING_BITS}>|perlvar/${^WARNING_BITS}>. The C<$hints> and
1814C<$bitmask> values are subject to change between versions of Perl, and
1815are not meant for external use.
14341816
14351817=end original
14361818
1437もしフレームがサブルーチン呼び出しではなく C<eval> だっ場合、この
1819ここ、$subroutine 、(caller を含む関数ではなく) caller が呼び出し
1438$subroutine は C<(eval)> になります。
1820関数です。
1821フレームがサブルーチン呼び出しではなく L<C<eval>|/eval EXPR> だった場合、この
1822$subroutine は C<(eval)> になることに注意してください。
14391823この場合、追加の要素である $evaltext と C<$is_require> がセットされます:
1440C<$is_require> はフレームが C<require> または C<use> で作られ場合に
1824C<$is_require> はフレームが L<C<require>|/require VERSION>
1441真になり、$evaltext は C<eval EXPR> のテキストが入ます。
1825L<C<use>|/use Module VERSION LIST> で作られた場合に真にな
1826$evaltext は C<eval EXPR> のテキストが入ります。
14421827特に、C<eval BLOCK> の場合、$subroutine は C<(eval)> になりますが、
14431828$evaltext は未定義値になります。
1444(それぞれの C<use> は C<eval EXPR> の中で C<require> フレームを作ることに
1829(それぞれの L<C<use>|/use Module VERSION LIST> は C<eval EXPR> の中で
1445注意してください。)
1830L<C<require>|/require VERSION> フレームを作ることに注意してください。)
14461831$subroutine は、そのサブルーチンがシンボルテーブルから削除された場合は
14471832C<(unknown)> になります。
1448C<$hasargs> はこのフレーム用に C<@_> の新しい実体が設定された場合に真となります。
1833C<$hasargs> はこのフレーム用に L<C<@_>|perlvar/@_> の新しい実体が
1834設定された場合に真となります。
14491835C<$hints> と C<$bitmask> は caller がコンパイルされたときの
14501836実際的なヒントを含みます。
1837C<$hints> は L<C<$^H>|perlvar/$^H> に対応し、C<$bitmask> は
1838L<C<${^WARNING_BITS}>|perlvar/${^WARNING_BITS}> に
1839対応します。
14511840C<$hints> は C<$bitmask> は Perl のバージョンによって変更される
1452可能性があるので、外部での使用を想定していません。
1841可能性があるので、外部での使用を想定していません。
14531842
14541843=begin original
14551844
1456C<$hinthash> is a reference to a hash containing the value of C<%^H> when the
1845C<$hinthash> is a reference to a hash containing the value of
1457caller was compiled, or C<undef> if C<%^H> was empty. Do not modify the values
1846L<C<%^H>|perlvar/%^H> when the caller was compiled, or
1458of this hash, as they are the actual values stored in the optree.
1847L<C<undef>|/undef EXPR> if L<C<%^H>|perlvar/%^H> was empty. Do not
1848modify the values of this hash, as they are the actual values stored in
1849the optree.
14591850
14601851=end original
14611852
1462C<$hinthash> は、caller がコンパイルされた時の C<%^H> の値を含む
1853C<$hinthash> は、caller がコンパイルされた時の L<C<%^H>|perlvar/%^H> の値を
1463ハッシュへのリファレンスか、あるいは C<%^H> が空の場合は C<undef> です。
1854含むハッシュへのリファレンスか、あるいは L<C<%^H>|perlvar/%^H> が空の場合は
1855L<C<undef>|/undef EXPR> です。
14641856このハッシュの値は構文木に保管されている実際の値なので、変更しないで下さい。
14651857
14661858=begin original
14671859
1468Furthermore, when called from within the DB package, caller returns more
1860Furthermore, when called from within the DB package in
1861list context, and with an argument, caller returns more
14691862detailed information: it sets the list variable C<@DB::args> to be the
14701863arguments with which the subroutine was invoked.
14711864
14721865=end original
14731866
1474さらに、DB パッケージの中から呼ばれた場合は、caller は
1867さらに、DB パッケージの中からリストコンテキストで引数付きで呼ばれた場合は、
1475より詳細な情報を返します
1868caller はより詳細な情報を返します; サブルーチンが起動されたときの引数を
1476サブルーチンが起動されたときの引数を変数 C<@DB::args> に設定します。
1869変数 C<@DB::args> に設定します。
14771870
14781871=begin original
14791872
14801873Be aware that the optimizer might have optimized call frames away before
1481C<caller> had a chance to get the information. That means that C<caller(N)>
1874L<C<caller>|/caller EXPR> had a chance to get the information. That
1482might not return information about the call frame you expect it to, for
1875means that C<caller(N)> might not return information about the call
1483C<< N > 1 >>. In particular, C<@DB::args> might have information from the
1876frame you expect it to, for C<< N > 1 >>. In particular, C<@DB::args>
1484previous time C<caller> was called.
1877might have information from the previous time L<C<caller>|/caller EXPR>
1878was called.
14851879
14861880=end original
14871881
1488C<caller> が情報を得る前にオプティマイザが呼び出しフレームを最適化して
1882L<C<caller>|/caller EXPR> が情報を得る前にオプティマイザが呼び出しフレームを
1489しまうかもしれないことに注意してください。
1883最適化してしまうかもしれないことに注意してください。
14901884これは、C<caller(N)> が C<< N > 1 >> のとき、
14911885あなたが予測した呼び出しフレームの情報を返さないかもしれないことを意味します。
1492特に、C<@DB::args> は C<caller> が前回呼び出された時の情報を
1886特に、C<@DB::args> は L<C<caller>|/caller EXPR> が前回呼び出された時の情報を
14931887持っているかもしれません。
14941888
14951889=begin original
14961890
14971891Be aware that setting C<@DB::args> is I<best effort>, intended for
1498debugging or generating backtraces, and should not be relied upon. In
1892debugging or generating backtraces, and should not be relied upon. In
1499particular, as C<@_> contains aliases to the caller's arguments, Perl does
1893particular, as L<C<@_>|perlvar/@_> contains aliases to the caller's
1500not take a copy of C<@_>, so C<@DB::args> will contain modifications the
1894arguments, Perl does not take a copy of L<C<@_>|perlvar/@_>, so
1501subroutine makes to C<@_> or its contents, not the original values at call
1895C<@DB::args> will contain modifications the subroutine makes to
1502time. C<@DB::args>, like C<@_>, does not hold explicit references to its
1896L<C<@_>|perlvar/@_> or its contents, not the original values at call
1503elements, so under certain cases its elements may have become freed and
1897time. C<@DB::args>, like L<C<@_>|perlvar/@_>, does not hold explicit
1504reallocated for other variables or temporary values. Finally, a side effect
1898references to its elements, so under certain cases its elements may have
1505of the current implementation is that the effects of C<shift @_> can
1899become freed and reallocated for other variables or temporary values.
1506I<normally> be undone (but not C<pop @_> or other splicing, I<and> not if a
1900Finally, a side effect of the current implementation is that the effects
1507reference to C<@_> has been taken, I<and> subject to the caveat about reallocated
1901of C<shift @_> can I<normally> be undone (but not C<pop @_> or other
1508elements), so C<@DB::args> is actually a hybrid of the current state and
1902splicing, I<and> not if a reference to L<C<@_>|perlvar/@_> has been
1509initial state of C<@_>. Buyer beware.
1903taken, I<and> subject to the caveat about reallocated elements), so
1904C<@DB::args> is actually a hybrid of the current state and initial state
1905of L<C<@_>|perlvar/@_>. Buyer beware.
15101906
15111907=end original
15121908
15131909C<@DB::args> の設定は I<ベストエフォート> で、デバッグやバックトレースの
15141910生成を目的としていて、これに依存するべきではないということにも
15151911注意してください。
1516特に、C<@_> は呼び出し元の引数へのエイリアスを含んでいるので、Perl は
1912特に、L<C<@_>|perlvar/@_> は呼び出し元の引数へのエイリアスを含んでいるので、
1517C<@_> のコピーを取らず、従って C<@DB::args> はサブルーチンが
1913Perl は L<C<@_>|perlvar/@_> のコピーを取らず、従って C<@DB::args> は
1518C<@_> やその内容に行った変更を含んでいて、呼び出し時の元の値ではありません。
1914サブルーチンが L<C<@_>|perlvar/@_> やその内容に行った変更を含んでいて、
1519C<@DB::args> は、C<@_> と同様、そ要素へ明示的なリファレンスを
1915呼び出し時値ではありません。
1520保持しないので、ある種の状況では、解放されて他変数や一時的な値のために
1916C<@DB::args> は、L<C<@_>|perlvar/@_> と同様、そ要素への明示的な
1521再割り当てされているかもしません。
1917リファレンスを保持しなので、あ種の状況では、解放さて他の変数や
1918一時的な値のために再割り当てされているかもしれません。
15221919最後に、現在の実装の副作用は、C<shift @_> の効果は I<普通は> 行われない
15231920(しかし C<pop @_> やその他の splice は違い、I<そして> もし
1524C<@_> のリファレンスが取られると違い、I<そして> 再割り当てされた要素に関する
1921L<C<@_>|perlvar/@_> のリファレンスが取られると違い、I<そして> 再割り当てされた
1525問題になりやすいです)ことなので、C<@DB::args> は実際には現在の状態と
1922要素に関する問題になりやすいです)ことなので、C<@DB::args> は実際には現在の
1526C<@_> の初期状態との合成物となります。
1923状態と L<C<@_>|perlvar/@_> の初期状態との合成物となります。
15271924ご用心を。
15281925
15291926=item chdir EXPR
15301927X<chdir>
15311928X<cd>
15321929X<directory, change>
15331930
15341931=item chdir FILEHANDLE
15351932
15361933=item chdir DIRHANDLE
15371934
15381935=item chdir
15391936
1937=for Pod::Functions change your current working directory
1938
15401939=begin original
15411940
1542Changes the working directory to EXPR, if possible. If EXPR is omitted,
1941Changes the working directory to EXPR, if possible. If EXPR is omitted,
15431942changes to the directory specified by C<$ENV{HOME}>, if set; if not,
1544changes to the directory specified by C<$ENV{LOGDIR}>. (Under VMS, the
1943changes to the directory specified by C<$ENV{LOGDIR}>. (Under VMS, the
1545variable C<$ENV{SYS$LOGIN}> is also checked, and used if it is set.) If
1944variable C<$ENV{'SYS$LOGIN'}> is also checked, and used if it is set.) If
1546neither is set, C<chdir> does nothing. It returns true on success,
1945neither is set, L<C<chdir>|/chdir EXPR> does nothing and fails. It
1547false otherwise. See the example under C<die>.
1946returns true on success, false otherwise. See the example under
1947L<C<die>|/die LIST>.
15481948
15491949=end original
15501950
15511951(可能であれば、) カレントディレクトリを EXPR に移します。
1552EXPR を指定しないと、C<$ENV{HOME}> が設定されていれば、
1952EXPR を指定しないと、C<$ENV{HOME}> が設定されていれば、そのディレクトリに
1553そのディレクトリに移ります。
1953移ります; うでなく、C<$ENV{LOGDIR}>が設定されていれば、そのディレクトリに
1554そうでなく、C<$ENV{LOGDIR}>が設定されていれば、そのディレクトリに移ります。
1954移ります。
1555(VMS では C<$ENV{SYS$LOGIN}> もチェックされ、もしセットされていれば使われます。)
1955(VMS では C<$ENV{'SYS$LOGIN'}> もチェックされ、もしセットされていれば
1556どちらも設定さていなければ、C<chdir> は何もしせん
1956使われま)
1957どちらも設定されていなければ、L<C<chdir>|/chdir EXPR> は何もせずに失敗します。
15571958成功時には真を返し、そうでなければ偽を返します。
1558C<die> の項の例を参照してください。
1959L<C<die>|/die LIST> の項の例を参照してください。
15591960
15601961=begin original
15611962
1562On systems that support fchdir(2), you may pass a filehandle or
1963On systems that support L<fchdir(2)>, you may pass a filehandle or
1563directory handle as the argument. On systems that don't support fchdir(2),
1964directory handle as the argument. On systems that don't support L<fchdir(2)>,
15641965passing handles raises an exception.
15651966
15661967=end original
15671968
1568fchdir(2) に対応しているシステムでは、ファイルハンドルや
1969L<fchdir(2)> に対応しているシステムでは、ファイルハンドルや
15691970ディレクトリハンドルを引数として渡せます。
1570fchdir に対応していないシステムでは、ハンドルを渡すと例外が発生します。
1971L<fchdir(2)> に対応していないシステムでは、ハンドルを渡すと例外が発生します。
15711972
15721973=item chmod LIST
15731974X<chmod> X<permission> X<mode>
15741975
1976=for Pod::Functions changes the permissions on a list of files
1977
15751978=begin original
15761979
15771980Changes the permissions of a list of files. The first element of the
15781981list must be the numeric mode, which should probably be an octal
15791982number, and which definitely should I<not> be a string of octal digits:
15801983C<0644> is okay, but C<"0644"> is not. Returns the number of files
1581successfully changed. See also L</oct> if all you have is a string.
1984successfully changed. See also L<C<oct>|/oct EXPR> if all you have is a
1985string.
15821986
15831987=end original
15841988
15851989LIST に含まれるファイルの、パーミッションを変更します。
1586LIST の最初の要素は、数値表現のモードでなければなりません
1990LIST の最初の要素は、数値表現のモードでなければなりません;
1587恐らく 8 進表記の数であるべきでしょうしかし、8 進表記のC<文字列ではいけません>。
1991恐らく 8 進表記の数であるべきでしょう: しかし、8 進表記の
1588C<0644> は OK ですが、 C<'0644'> はだめ、ということです。
1992文字列では I<いけません>: C<0644> は OK ですが、 C<"0644"> は
1993だめ、ということです。
15891994変更に成功したファイルの数を返します。
1590文字列を使いたい場合は、L</oct> を参照してください。
1995文字列を使いたい場合は、L<C<oct>|/oct EXPR> を参照してください。
15911996
1592 $cnt = chmod 0755, "foo", "bar";
1997 my $cnt = chmod 0755, "foo", "bar";
15931998 chmod 0755, @executables;
1594 $mode = "0644"; chmod $mode, "foo"; # !!! sets mode to
1999 my $mode = "0644"; chmod $mode, "foo"; # !!! sets mode to
1595 # --w----r-T
2000 # --w----r-T
1596 $mode = "0644"; chmod oct($mode), "foo"; # this is better
2001 my $mode = "0644"; chmod oct($mode), "foo"; # this is better
1597 $mode = 0644; chmod $mode, "foo"; # this is best
2002 my $mode = 0644; chmod $mode, "foo"; # this is best
15982003
15992004=begin original
16002005
1601On systems that support fchmod(2), you may pass filehandles among the
2006On systems that support L<fchmod(2)>, you may pass filehandles among the
1602files. On systems that don't support fchmod(2), passing filehandles raises
2007files. On systems that don't support L<fchmod(2)>, passing filehandles raises
16032008an exception. Filehandles must be passed as globs or glob references to be
16042009recognized; barewords are considered filenames.
16052010
16062011=end original
16072012
1608fchmod(2) に対応しているシステムでは、ファイルハンドルを引数として渡せます。
2013L<fchmod(2)> に対応しているシステムでは、ファイルハンドルを引数として
1609fchmod(2) に対応していないシステムでは、ファイルハンドルを渡す
2014せま
2015L<fchmod(2)> に対応していないシステムでは、ファイルハンドルを渡すと
16102016例外が発生します。
16112017ファイルハンドルを認識させるためには、グロブまたはリファレンスとして
16122018渡されなければなりません;
16132019裸の単語はファイル名として扱われます。
16142020
16152021 open(my $fh, "<", "foo");
16162022 my $perm = (stat $fh)[2] & 07777;
16172023 chmod($perm | 0600, $fh);
16182024
16192025=begin original
16202026
1621You can also import the symbolic C<S_I*> constants from the C<Fcntl>
2027You can also import the symbolic C<S_I*> constants from the
2028L<C<Fcntl>|Fcntl> module:
16222029
1623module:
1624
16252030=end original
16262031
1627シンボリックな C<S_I*> 定数を C<Fcntl> モジュールから
2032L<C<Fcntl>|Fcntl> モジュールから C<S_I*> シンボル定数を
1628インポートすることもできます
2033インポートすることもできます:
16292034
16302035 use Fcntl qw( :mode );
16312036 chmod S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, @executables;
16322037 # Identical to the chmod 0755 of the example above.
16332038
2039=begin original
2040
2041Portability issues: L<perlport/chmod>.
2042
2043=end original
2044
2045移植性の問題: L<perlport/chmod>。
2046
16342047=item chomp VARIABLE
16352048X<chomp> X<INPUT_RECORD_SEPARATOR> X<$/> X<newline> X<eol>
16362049
16372050=item chomp( LIST )
16382051
16392052=item chomp
16402053
2054=for Pod::Functions remove a trailing record separator from a string
2055
16412056=begin original
16422057
1643This safer version of L</chop> removes any trailing string
2058This safer version of L<C<chop>|/chop VARIABLE> removes any trailing
1644that corresponds to the current value of C<$/> (also known as
2059string that corresponds to the current value of
1645$INPUT_RECORD_SEPARATOR in the C<English> module). It returns the total
2060L<C<$E<sol>>|perlvar/$E<sol>> (also known as C<$INPUT_RECORD_SEPARATOR>
2061in the L<C<English>|English> module). It returns the total
16462062number of characters removed from all its arguments. It's often used to
16472063remove the newline from the end of an input record when you're worried
16482064that the final record may be missing its newline. When in paragraph
1649mode (C<$/ = "">), it removes all trailing newlines from the string.
2065mode (C<$/ = ''>), it removes all trailing newlines from the string.
1650When in slurp mode (C<$/ = undef>) or fixed-length record mode (C<$/> is
2066When in slurp mode (C<$/ = undef>) or fixed-length record mode
1651a reference to an integer or the like; see L<perlvar>) chomp() won't
2067(L<C<$E<sol>>|perlvar/$E<sol>> is a reference to an integer or the like;
1652remove anything.
2068see L<perlvar>), L<C<chomp>|/chomp VARIABLE> won't remove anything.
1653If VARIABLE is omitted, it chomps C<$_>. Example:
2069If VARIABLE is omitted, it chomps L<C<$_>|perlvar/$_>. Example:
16542070
16552071=end original
16562072
1657より安全な C<chop> (以下を参照してください) です
2073より安全な L<C<chop>|/chop VARIABLE> (以下を参照してください) です;
1658C<$/> (C<English> モジュールでは、$INPUT_RECORD_SEPARATOR
2074L<C<$E<sol>>|perlvar/$E<sol>> (L<C<English>|English> モジュールでは、
1659とも言う) のその時点の値に対応する行末文字を削除します。
2075C<$INPUT_RECORD_SEPARATOR> とも言う) のその時点の
2076値に対応する行末文字を削除します。
16602077全ての引数から削除した文字数の合計を返します。
16612078入力レコードから、改行を削除したいのだけれど、最後のレコードには改行が
16622079入っているのかわからないような場合に、使用できます。
1663段落モード (C<$/ = "">) では、レコードの最後の改行をすべて取り除きます。
2080段落モード (C<$/ = ''>) では、レコードの最後の改行をすべて取り除きます。
16642081吸い込みモード (C<$/ = undef>) や 固定長レコードモード
1665(C<$/> が整数へのリファレンスや類似のものの場合; L<perlvar>を参照してください)
2082(L<C<$E<sol>>|perlvar/$E<sol>> が整数へのリファレンスや類似のものの場合;
1666では、chomp()何も取り除きません。
2083L<perlvar>を参照してください)では、L<C<chomp>|/chomp VARIABLE>
1667VARIABLE が省略されると、$_ を対象として chomp し
2084何も取り除きせん
2085VARIABLE が省略されると、L<C<$_>|perlvar/$_> を対象として chomp します。
16682086例:
16692087
16702088 while (<>) {
16712089 chomp; # avoid \n on last field
1672 @array = split(/:/);
2090 my @array = split(/:/);
16732091 # ...
16742092 }
16752093
16762094=begin original
16772095
1678If VARIABLE is a hash, it chomps the hash's values, but not its keys.
2096If VARIABLE is a hash, it chomps the hash's values, but not its keys,
2097resetting the L<C<each>|/each HASH> iterator in the process.
16792098
16802099=end original
16812100
1682VARIABLE がハッシュなら、ハッシュのキーではなく値について chomp します。
2101VARIABLE がハッシュなら、ハッシュのキーではなく値について chomp し
2102このプロセスの L<C<each>|/each HASH> 反復子をリセットします。
16832103
16842104=begin original
16852105
16862106You can actually chomp anything that's an lvalue, including an assignment:
16872107
16882108=end original
16892109
16902110左辺値であれば、代入を含めて、任意のものを chomp できます:
16912111
1692 chomp($cwd = `pwd`);
2112 chomp(my $cwd = `pwd`);
1693 chomp($answer = <STDIN>);
2113 chomp(my $answer = <STDIN>);
16942114
16952115=begin original
16962116
16972117If you chomp a list, each element is chomped, and the total number of
16982118characters removed is returned.
16992119
17002120=end original
17012121
17022122リストを chomp すると、個々の要素が chomp され、
17032123削除された文字数の合計が返されます。
17042124
17052125=begin original
17062126
17072127Note that parentheses are necessary when you're chomping anything
17082128that is not a simple variable. This is because C<chomp $cwd = `pwd`;>
17092129is interpreted as C<(chomp $cwd) = `pwd`;>, rather than as
17102130C<chomp( $cwd = `pwd` )> which you might expect. Similarly,
17112131C<chomp $a, $b> is interpreted as C<chomp($a), $b> rather than
17122132as C<chomp($a, $b)>.
17132133
17142134=end original
17152135
17162136単純な変数以外のものを chomp する場合はかっこが必要であることに
17172137注意してください。
17182138これは、C<chomp $cwd = `pwd`;> は、予測している
17192139C<chomp( $cwd = `pwd` )> ではなく、C<(chomp $cwd) = `pwd`;> と
17202140解釈されるからです。
17212141同様に、C<chomp $a, $b> は C<chomp($a, $b)> ではなく C<chomp($a), $b>
17222142と解釈されます。
17232143
17242144=item chop VARIABLE
17252145X<chop>
17262146
17272147=item chop( LIST )
17282148
17292149=item chop
17302150
2151=for Pod::Functions remove the last character from a string
2152
17312153=begin original
17322154
17332155Chops off the last character of a string and returns the character
17342156chopped. It is much more efficient than C<s/.$//s> because it neither
1735scans nor copies the string. If VARIABLE is omitted, chops C<$_>.
2157scans nor copies the string. If VARIABLE is omitted, chops
1736If VARIABLE is a hash, it chops the hash's values, but not its keys.
2158L<C<$_>|perlvar/$_>.
2159If VARIABLE is a hash, it chops the hash's values, but not its keys,
2160resetting the L<C<each>|/each HASH> iterator in the process.
17372161
17382162=end original
17392163
17402164文字列の最後の文字を切り捨てて、その切り取った文字を返します。
17412165文字列の検索もコピーも行ないませんので
17422166C<s/.$//s> よりも、ずっと効率的です。
1743VARIABLE が省略されると、C<$_> を対象として chop します。
2167VARIABLE が省略されると、L<C<$_>|perlvar/$_> を対象として chop します。
1744VARIABLE がハッシュの場合、ハッシュの value を chop しますが
2168VARIABLE がハッシュの場合、ハッシュのキーではなく値について chop し、
1745key chop しません
2169このプロセスの L<C<each>|/each HASH> 反復子をリセットしま
17462170
17472171=begin original
17482172
17492173You can actually chop anything that's an lvalue, including an assignment.
17502174
17512175=end original
17522176
17532177実際のところ、代入を含む左辺値となりうるなんでも chop できます。
17542178
17552179=begin original
17562180
17572181If you chop a list, each element is chopped. Only the value of the
1758last C<chop> is returned.
2182last L<C<chop>|/chop VARIABLE> is returned.
17592183
17602184=end original
17612185
17622186リストを chop すると、個々の要素が chop されます。
1763最後の C<chop> の値だけが返されます。
2187最後の L<C<chop>|/chop VARIABLE> の値だけが返されます。
17642188
17652189=begin original
17662190
1767Note that C<chop> returns the last character. To return all but the last
2191Note that L<C<chop>|/chop VARIABLE> returns the last character. To
1768character, use C<substr($string, 0, -1)>.
2192return all but the last character, use C<substr($string, 0, -1)>.
17692193
17702194=end original
17712195
1772C<chop> は最後の文字を返すことに注意してください。
2196L<C<chop>|/chop VARIABLE> は最後の文字を返すことに注意してください。
17732197最後以外の全ての文字を返すためには、C<substr($string, 0, -1)> を
17742198使ってください。
17752199
17762200=begin original
17772201
1778See also L</chomp>.
2202See also L<C<chomp>|/chomp VARIABLE>.
17792203
17802204=end original
17812205
1782L</chomp> も参照してください。
2206L<C<chomp>|/chomp VARIABLE> も参照してください。
17832207
17842208=item chown LIST
17852209X<chown> X<owner> X<user> X<group>
17862210
2211=for Pod::Functions change the ownership on a list of files
2212
17872213=begin original
17882214
17892215Changes the owner (and group) of a list of files. The first two
17902216elements of the list must be the I<numeric> uid and gid, in that
17912217order. A value of -1 in either position is interpreted by most
17922218systems to leave that value unchanged. Returns the number of files
17932219successfully changed.
17942220
17952221=end original
17962222
17972223LIST に含まれるファイルの所有者 (とグループ) を変更します。
17982224LIST の最初の二つの要素には、I<数値表現> の uid と gid を
17992225この順序で与えなければなりません。
18002226どちらかの値を -1 にすると、ほとんどのシステムではその値は
18012227変更しないと解釈します。
1802変更に成功したファイルの数されます。
2228変更に成功したファイルの数ます。
18032229
1804 $cnt = chown $uid, $gid, 'foo', 'bar';
2230 my $cnt = chown $uid, $gid, 'foo', 'bar';
18052231 chown $uid, $gid, @filenames;
18062232
18072233=begin original
18082234
1809On systems that support fchown(2), you may pass filehandles among the
2235On systems that support L<fchown(2)>, you may pass filehandles among the
1810files. On systems that don't support fchown(2), passing filehandles raises
2236files. On systems that don't support L<fchown(2)>, passing filehandles raises
18112237an exception. Filehandles must be passed as globs or glob references to be
18122238recognized; barewords are considered filenames.
18132239
18142240=end original
18152241
1816fchown(2) に対応しているシステムでは、ファイルハンドルを引数として渡せます。
2242L<fchown(2)> に対応しているシステムでは、ファイルハンドルを引数として渡せます。
1817fchown(2) に対応していないシステムでは、ファイルハンドルを渡すと
2243L<fchown(2)> に対応していないシステムでは、ファイルハンドルを渡すと
18182244例外が発生します。
18192245ファイルハンドルを認識させるためには、グロブまたはリファレンスとして
18202246渡されなければなりません; 裸の単語はファイル名として扱われます。
18212247
18222248=begin original
18232249
18242250Here's an example that looks up nonnumeric uids in the passwd file:
18252251
18262252=end original
18272253
18282254passwd ファイルから数値表現でない uid を検索する例を
18292255示します:
18302256
18312257 print "User: ";
1832 chomp($user = <STDIN>);
2258 chomp(my $user = <STDIN>);
18332259 print "Files: ";
1834 chomp($pattern = <STDIN>);
2260 chomp(my $pattern = <STDIN>);
18352261
1836 ($login,$pass,$uid,$gid) = getpwnam($user)
2262 my ($login,$pass,$uid,$gid) = getpwnam($user)
18372263 or die "$user not in passwd file";
18382264
1839 @ary = glob($pattern); # expand filenames
2265 my @ary = glob($pattern); # expand filenames
18402266 chown $uid, $gid, @ary;
18412267
18422268=begin original
18432269
18442270On most systems, you are not allowed to change the ownership of the
18452271file unless you're the superuser, although you should be able to change
18462272the group to any of your secondary groups. On insecure systems, these
18472273restrictions may be relaxed, but this is not a portable assumption.
18482274On POSIX systems, you can detect this condition this way:
18492275
18502276=end original
18512277
18522278ほとんどのシステムでは、スーパーユーザーだけがファイルの所有者を
18532279変更できますが、グループは実行者の副グループに変更できるべきです。
1854安全でないシステムでは、この制限はゆるめられています
2280安全でないシステムでは、この制限はゆるめられています; しかしこれは
1855しかしこれは移植性のある仮定ではありません。
2281移植性のある仮定ではありません。
18562282POSIX システムでは、以下のようにしてこの条件を検出できます:
18572283
18582284 use POSIX qw(sysconf _PC_CHOWN_RESTRICTED);
1859 $can_chown_giveaway = not sysconf(_PC_CHOWN_RESTRICTED);
2285 my $can_chown_giveaway = ! sysconf(_PC_CHOWN_RESTRICTED);
18602286
2287=begin original
2288
2289Portability issues: L<perlport/chown>.
2290
2291=end original
2292
2293移植性の問題: L<perlport/chown>。
2294
18612295=item chr NUMBER
18622296X<chr> X<character> X<ASCII> X<Unicode>
18632297
18642298=item chr
18652299
2300=for Pod::Functions get character this number represents
2301
18662302=begin original
18672303
18682304Returns the character represented by that NUMBER in the character set.
18692305For example, C<chr(65)> is C<"A"> in either ASCII or Unicode, and
1870chr(0x263a) is a Unicode smiley face.
2306chr(0x263a) is a Unicode smiley face.
18712307
18722308=end original
18732309
18742310特定の文字セットでの NUMBER で表わされる文字を返します。
1875たとえば、C<chr(65)> は ASCII と Unicode の両方で C<"A"> となります
2311たとえば、C<chr(65)> は ASCII と Unicode の両方で C<"A"> となります;
1876chr(0x263a) は Unicode のスマイリーフェイスです。
2312chr(0x263a) は Unicode のスマイリーフェイスです。
18772313
18782314=begin original
18792315
18802316Negative values give the Unicode replacement character (chr(0xfffd)),
18812317except under the L<bytes> pragma, where the low eight bits of the value
18822318(truncated to an integer) are used.
18832319
18842320=end original
18852321
18862322負の数は Unicode の置換文字 (chr(0xfffd)) を与えますが、
18872323L<bytes> プラグマの影響下では、(integer に切り詰められた)値の下位 8 ビットが
18882324使われます。
18892325
18902326=begin original
18912327
1892If NUMBER is omitted, uses C<$_>.
2328If NUMBER is omitted, uses L<C<$_>|perlvar/$_>.
18932329
18942330=end original
18952331
1896NUMBER が省略された場合、C<$_> を使います。
2332NUMBER が省略された場合、L<C<$_>|perlvar/$_> を使います。
18972333
18982334=begin original
18992335
1900For the reverse, use L</ord>.
2336For the reverse, use L<C<ord>|/ord EXPR>.
19012337
19022338=end original
19032339
1904逆を行うためには、L</ord> を参照してください。
2340逆を行うためには、L<C<ord>|/ord EXPR> を参照してください。
19052341
19062342=begin original
19072343
19082344Note that characters from 128 to 255 (inclusive) are by default
19092345internally not encoded as UTF-8 for backward compatibility reasons.
19102346
19112347=end original
19122348
19132349128 から 255 までの文字は過去との互換性のために
19142350デフォルトでは UTF-8 Unicode にエンコードされません。
19152351
19162352=begin original
19172353
19182354See L<perlunicode> for more about Unicode.
19192355
19202356=end original
19212357
1922Unicode についてもっと知りたいなら、L<perlunicode> を
2358Unicode についてL<perlunicode> を参照してください。
1923参照してください。
19242359
19252360=item chroot FILENAME
19262361X<chroot> X<root>
19272362
19282363=item chroot
19292364
2365=for Pod::Functions make directory new root for path lookups
2366
19302367=begin original
19312368
19322369This function works like the system call by the same name: it makes the
19332370named directory the new root directory for all further pathnames that
19342371begin with a C</> by your process and all its children. (It doesn't
19352372change your current working directory, which is unaffected.) For security
19362373reasons, this call is restricted to the superuser. If FILENAME is
1937omitted, does a C<chroot> to C<$_>.
2374omitted, does a L<C<chroot>|/chroot FILENAME> to L<C<$_>|perlvar/$_>.
19382375
19392376=end original
19402377
1941同じ名前のシステムコールと同じことをします
2378同じ名前のシステムコールと同じことをします: 現在のプロセス及び子プロセスに
1942現在のプロセス及び子プロセスに対して、C</>で始まるパス名に関して
2379対して、C</>で始まるパス名に関して指定されたディレクトリを新しい
1943指定されたディレクトリを新しいルートディレクトリとして扱います。
2380ルートディレクトリとして扱います。
1944(これはカレントディレクトリを変更しませんカレントディレクトリはそのままです)。
2381(これはカレントディレクトリを変更しません; カレントディレクトリは
2382そのままです。)
19452383セキュリティ上の理由により、この呼び出しはスーパーユーザーしか行えません。
1946FILENAME を省略すると、C<$_> へ C<chroot> します。
2384FILENAME を省略すると、L<C<$_>|perlvar/$_>
2385L<C<chroot>|/chroot FILENAME> します。
19472386
2387=begin original
2388
2389B<NOTE:> It is good security practice to do C<chdir("/")>
2390(L<C<chdir>|/chdir EXPR> to the root directory) immediately after a
2391L<C<chroot>|/chroot FILENAME>.
2392
2393=end original
2394
2395B<注意:> L<C<chroot>|/chroot FILENAME> の直後に (ルートディレクトリに
2396L<C<chdir>|/chdir EXPR> する)
2397C<chdir("/")> するのはセキュリティ上の良い習慣です。
2398
2399=begin original
2400
2401Portability issues: L<perlport/chroot>.
2402
2403=end original
2404
2405移植性の問題: L<perlport/chroot>。
2406
19482407=item close FILEHANDLE
19492408X<close>
19502409
19512410=item close
19522411
2412=for Pod::Functions close file (or pipe or socket) handle
2413
19532414=begin original
19542415
19552416Closes the file or pipe associated with the filehandle, flushes the IO
19562417buffers, and closes the system file descriptor. Returns true if those
19572418operations succeed and if no error was reported by any PerlIO
19582419layer. Closes the currently selected filehandle if the argument is
19592420omitted.
19602421
19612422=end original
19622423
19632424FILEHANDLE に対応したファイルまたはパイプをクローズして、
19642425IO バッファをフラッシュし、システムファイル記述子をクローズします。
19652426操作が成功し、PerlIO 層からエラーが報告されなかった場合に真を返します。
19662427引数が省略された場合、現在選択されているファイルハンドルをクローズします。
19672428
19682429=begin original
19692430
19702431You don't have to close FILEHANDLE if you are immediately going to do
1971another C<open> on it, because C<open> closes it for you. (See
2432another L<C<open>|/open FILEHANDLE,EXPR> on it, because
1972C<open>.) However, an explicit C<close> on an input file resets the line
2433L<C<open>|/open FILEHANDLE,EXPR> closes it for you. (See
1973counter (C<$.>), while the implicit close done by C<open> does not.
2434L<C<open>|/open FILEHANDLE,EXPR>.) However, an explicit
2435L<C<close>|/close FILEHANDLE> on an input file resets the line counter
2436(L<C<$.>|perlvar/$.>), while the implicit close done by
2437L<C<open>|/open FILEHANDLE,EXPR> does not.
19742438
19752439=end original
19762440
1977クローズしてすぐにまた、同じファイルハンドルに
2441クローズしてすぐにまた、同じファイルハンドルに対してオープンを行なう
1978対してオープンを行なう場合には、C<open> が自動的に C<close>
2442場合には、L<C<open>|/open FILEHANDLE,EXPR> が自動的に
1979を行ないますので、close FILEHANDLE する必要はありせん
2443L<C<close>|/close FILEHANDLE> を行ないすので、
1980(C<open> を参照してください)
2444close FILEHANDLE する必要はありません
2445(L<C<open>|/open FILEHANDLE,EXPR> を参照してください。)
19812446ただし、明示的にクローズを行なったときにのみ入力ファイルの
1982行番号 (C<$.>) のリセットが行なわれ、C<open> によって行なわれる
2447行番号 (L<C<$.>|perlvar/$.>) のリセットが行なわれ、
1983暗黙の C<close>では行なわれません。
2448L<C<open>|/open FILEHANDLE,EXPR> によって行なわれ
2449暗黙の L<C<close>|/close FILEHANDLE> では行なわれません。
19842450
19852451=begin original
19862452
1987If the filehandle came from a piped open, C<close> returns false if one of
2453If the filehandle came from a piped open, L<C<close>|/close FILEHANDLE>
1988the other syscalls involved fails or if its program exits with non-zero
2454returns false if one of the other syscalls involved fails or if its
1989status. If the only problem was that the program exited non-zero, C<$!>
2455program exits with non-zero status. If the only problem was that the
1990will be set to C<0>. Closing a pipe also waits for the process executing
2456program exited non-zero, L<C<$!>|perlvar/$!> will be set to C<0>.
1991on the pipe to exit--in case you wish to look at the output of the pipe
2457Closing a pipe also waits for the process executing on the pipe to
1992afterwards--and implicitly puts the exit status value of that command into
2458exit--in case you wish to look at the output of the pipe afterwards--and
1993C<$?> and C<${^CHILD_ERROR_NATIVE}>.
2459implicitly puts the exit status value of that command into
2460L<C<$?>|perlvar/$?> and
2461L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>.
19942462
19952463=end original
19962464
1997ファイルハンドルがパイプつきオープンなら、
2465ファイルハンドルがパイプつきオープンなら、L<C<close>|/close FILEHANDLE> は
1998C<close> はその他のシステムコールが失敗したり
2466その他のシステムコールが失敗したりプログラムが非ゼロのステータスで終了した
1999プログラムが非ゼロのステータスで終了した場合にも偽を返します
2467場合にも偽を返します
2000(プログラムが非ゼロで終了しただけの場合は、C<$!>がC<0>にセットされます)。
2468プログラムが非ゼロで終了しただけの場合は、L<C<$!>|perlvar/$!> C<0>
2001後でパイプの出力を見たい場合のために、パイプのクローズでは、
2469セットされます。
2002パイプ上で実行されてロセス終了を待ち
2470後でパイプの出力を見た場合のために、パイプのクローズではパイプ上で
2003また自動的にコマンドのステータス値を C<$?> と
2471実行されているプロセスの終了を待ち、また自動的にコマンドのステータス値を
2004C<${^CHILD_ERROR_NATIVE}> に設定します。
2472L<C<$?>|perlvar/$?>
2473L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に設定します。
20052474
20062475=begin original
20072476
2008If there are multiple threads running, C<close> on a filehandle from a
2477If there are multiple threads running, L<C<close>|/close FILEHANDLE> on
2009piped open returns true without waiting for the child process to terminate,
2478a filehandle from a piped open returns true without waiting for the
2010if the filehandle is still open in another thread.
2479child process to terminate, if the filehandle is still open in another
2480thread.
20112481
20122482=end original
20132483
20142484複数のスレッドがある場合、パイプで開かれたファイルハンドルに対する
2015C<close> は、そのファイルハンドルが他のスレッドでまだ開かれている場合、
2485L<C<close>|/close FILEHANDLE> は、そのファイルハンドルが他のスレッドで
2016子プロセスの終了を待たずに真を返します。
2486まだ開かれている場合、子プロセスの終了を待たずに真を返します。
20172487
20182488=begin original
20192489
20202490Closing the read end of a pipe before the process writing to it at the
20212491other end is done writing results in the writer receiving a SIGPIPE. If
20222492the other end can't handle that, be sure to read all the data before
20232493closing the pipe.
20242494
20252495=end original
20262496
20272497書き込み側が閉じる前に途中でパイプの読み込み側が閉じた場合、
20282498書き込み側に SIGPIPE が配送されます。
20292499書き込み側がこれを扱えない場合、パイプを閉じる前に
20302500確実に全てのデータが読み込まれるようにする必要があります。
20312501
20322502=begin original
20332503
20342504Example:
20352505
20362506=end original
20372507
20382508例:
20392509
20402510 open(OUTPUT, '|sort >foo') # pipe to sort
20412511 or die "Can't start sort: $!";
20422512 #... # print stuff to output
20432513 close OUTPUT # wait for sort to finish
20442514 or warn $! ? "Error closing sort pipe: $!"
20452515 : "Exit status $? from sort";
20462516 open(INPUT, 'foo') # get sort's results
20472517 or die "Can't open 'foo' for input: $!";
20482518
20492519=begin original
20502520
20512521FILEHANDLE may be an expression whose value can be used as an indirect
20522522filehandle, usually the real filehandle name or an autovivified handle.
20532523
20542524=end original
20552525
2056FILEHANDLE は式でもかまいませんこの場合、値は間接ファイルハンドルと
2526FILEHANDLE は式でもかまいません; この場合、値は間接ファイルハンドルと
20572527して扱われ、普通は実際のファイルハンドル名か自動有効化されたハンドルです。
20582528
20592529=item closedir DIRHANDLE
20602530X<closedir>
20612531
2532=for Pod::Functions close directory handle
2533
20622534=begin original
20632535
2064Closes a directory opened by C<opendir> and returns the success of that
2536Closes a directory opened by L<C<opendir>|/opendir DIRHANDLE,EXPR> and
2065system call.
2537returns the success of that system call.
20662538
20672539=end original
20682540
2069C<opendir> でオープンしたディレクトリをクローズし、
2541L<C<opendir>|/opendir DIRHANDLE,EXPR> でオープンしたディレクトリをクローズし、
20702542システムコールの返り値を返します。
20712543
20722544=item connect SOCKET,NAME
20732545X<connect>
20742546
2547=for Pod::Functions connect to a remote socket
2548
20752549=begin original
20762550
2077Attempts to connect to a remote socket, just like connect(2).
2551Attempts to connect to a remote socket, just like L<connect(2)>.
20782552Returns true if it succeeded, false otherwise. NAME should be a
20792553packed address of the appropriate type for the socket. See the examples in
20802554L<perlipc/"Sockets: Client/Server Communication">.
20812555
20822556=end original
20832557
2084connect(2) システムコールと同様に、リモートソケットへの接続を試みます。
2558L<connect(2)> システムコールと同様に、リモートソケットへの接続を試みます。
2085成功時には真を返し失敗時には偽を返します。
2559成功時には真を、さもなければ偽を返します。
20862560NAME は、ソケットに対する、適切な型のパックされた
20872561アドレスでなければなりません。
20882562L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
20892563
20902564=item continue BLOCK
20912565X<continue>
20922566
20932567=item continue
20942568
2569=for Pod::Functions optional trailing block in a while or foreach
2570
20952571=begin original
20962572
2097C<continue> is actually a flow control statement rather than a function. If
2573When followed by a BLOCK, L<C<continue>|/continue BLOCK> is actually a
2098there is a C<continue> BLOCK attached to a BLOCK (typically in a C<while> or
2574flow control statement rather than a function. If there is a
2099C<foreach>), it is always executed just before the conditional is about to
2575L<C<continue>|/continue BLOCK> BLOCK attached to a BLOCK (typically in a
2100be evaluated again, just like the third part of a C<for> loop in C. Thus
2576C<while> or C<foreach>), it is always executed just before the
2101it can be used to increment a loop variable, even when the loop has been
2577conditional is about to be evaluated again, just like the third part of
2102continued via the C<next> statement (which is similar to the C C<continue>
2578a C<for> loop in C. Thus it can be used to increment a loop variable,
2579even when the loop has been continued via the L<C<next>|/next LABEL>
2580statement (which is similar to the C L<C<continue>|/continue BLOCK>
21032581statement).
21042582
21052583=end original
21062584
2107C<continue> は実際には関数ではなく、実行制御文です。
2585BLOCK が引き続く場合、L<C<continue>|/continue BLOCK> は実際には関数ではなく、
2108C<continue> BLOCK が BLOCK (典型的には C<while> または C<foreach> の中)にあると、
2586実行制御文です。
2109これは条件文再評価される直前常に実行されす。
2587L<C<continue>|/continue BLOCK> BLOCK BLOCK (典型的は C<while> たは
2588C<foreach> の中)にあると、これは条件文が再評価される直前に常に実行されます;
21102589これは C における C<for> ループの 3 番目の部分と同様です。
2111従って、これは C<next> 文
2590従って、これは L<C<next>|/next LABEL> (これは C の
2112(これは C の C<continue> 文と似ています)を使ってループが繰り返されるときでも
2591L<C<continue>|/continue BLOCK> 文と似ています) を使って
2113ループ変数を増やしたいときに使えます。
2592ループが繰り返されるときでもループ変数を増やしたいときに使えます。
21142593
21152594=begin original
21162595
2117C<last>, C<next>, or C<redo> may appear within a C<continue>
2596L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, or
2118block; C<last> and C<redo> behave as if they had been executed within
2597L<C<redo>|/redo LABEL> may appear within a
2119the main block. So will C<next>, but since it will execute a C<continue>
2598L<C<continue>|/continue BLOCK> block; L<C<last>|/last LABEL> and
2120block, it may be more entertaining.
2599L<C<redo>|/redo LABEL> behave as if they had been executed within the
2600main block. So will L<C<next>|/next LABEL>, but since it will execute a
2601L<C<continue>|/continue BLOCK> block, it may be more entertaining.
21212602
21222603=end original
21232604
2124C<last>, C<next>, C<redo> が C<continue> ブロック内に現れる可能性あります;
2605L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL> が
2125C<last> C<redo> はメインブロックの中で実行されたのと同じよう振舞います
2606L<C<continue>|/continue BLOCK> ブロック現れる可能性があります;
2126C<next> の場合は、C<continue> ブロックを実行することになるので
2607L<C<last>|/last LABEL> と L<C<redo>|/redo LABEL> はメインブロックの
2127より面白いことになります。
2608実行されたの同じよう振舞います。
2609L<C<next>|/next LABEL> の場合は、L<C<continue>|/continue BLOCK> ブロックを
2610実行することになるので、より面白いことになります。
21282611
21292612 while (EXPR) {
21302613 ### redo always comes here
21312614 do_something;
21322615 } continue {
21332616 ### next always comes here
21342617 do_something_else;
21352618 # then back the top to re-check EXPR
21362619 }
21372620 ### last always comes here
21382621
21392622=begin original
21402623
2141Omitting the C<continue> section is equivalent to using an
2624Omitting the L<C<continue>|/continue BLOCK> section is equivalent to
2142empty one, logically enough, so C<next> goes directly back
2625using an empty one, logically enough, so L<C<next>|/next LABEL> goes
2143to check the condition at the top of the loop.
2626directly back to check the condition at the top of the loop.
21442627
21452628=end original
21462629
2147C<continue> 節を省略するのは、空の節を指定したのと同じで、
2630L<C<continue>|/continue BLOCK> 節を省略するのは、空の節を指定したのと同じで、
2148論理的には十分なので、この場合、C<next> は直接ループ先頭の
2631論理的には十分なので、この場合、L<C<next>|/next LABEL> は直接ループ先頭の
21492632条件チェックに戻ります。
21502633
21512634=begin original
21522635
2153If the C<"switch"> feature is enabled, C<continue> is also a function that
2636When there is no BLOCK, L<C<continue>|/continue BLOCK> is a function
2154falls through the current C<when> or C<default> block instead of iterating
2637that falls through the current C<when> or C<default> block instead of
2155a dynamically enclosing C<foreach> or exiting a lexically enclosing C<given>.
2638iterating a dynamically enclosing C<foreach> or exiting a lexically
2156See L<feature> and L<perlsyn/"Switch statements"> for more
2639enclosing C<given>. In Perl 5.14 and earlier, this form of
2157information.
2640L<C<continue>|/continue BLOCK> was only available when the
2641L<C<"switch"> feature|feature/The 'switch' feature> was enabled. See
2642L<feature> and L<perlsyn/"Switch Statements"> for more information.
21582643
21592644=end original
21602645
2161C<"switch"> 機能有効、C<continue> は動的に囲まれた C<foreach> や
2646BLOCK がなければL<C<continue>|/continue BLOCK> は動的に囲まれた C<foreach> や
21622647レキシカルに囲まれた C<given> で反復するのではなく、現在の C<when> または
2163C<default> のブロックを通り抜けるための文にもなります。
2648C<default> のブロックを通り抜けるための文す。
2164さらなる情報については L<feature> と L<perlsyn/"Switch statements">
2649Perl 5.14 以前で、この形式の L<C<continue>|/continue BLOCK>
2650L<C<"switch"> 機能|feature/The 'switch' feature> が有効の場合にのみ
2651利用可能です。
2652さらなる情報については L<feature> と L<perlsyn/"Switch Statements"> を
21652653参照してください。
21662654
21672655=item cos EXPR
21682656X<cos> X<cosine> X<acos> X<arccosine>
21692657
21702658=item cos
21712659
2660=for Pod::Functions cosine function
2661
21722662=begin original
21732663
21742664Returns the cosine of EXPR (expressed in radians). If EXPR is omitted,
2175takes the cosine of C<$_>.
2665takes the cosine of L<C<$_>|perlvar/$_>.
21762666
21772667=end original
21782668
21792669(ラジアンで示した) EXPR の余弦を返します。
2180EXPR が省略されたときには、C<$_> の余弦を取ります。
2670EXPR が省略されたときには、L<C<$_>|perlvar/$_> の余弦を取ります。
21812671
21822672=begin original
21832673
2184For the inverse cosine operation, you may use the C<Math::Trig::acos()>
2674For the inverse cosine operation, you may use the
2185function, or use this relation:
2675L<C<Math::Trig::acos>|Math::Trig> function, or use this relation:
21862676
21872677=end original
21882678
2189逆余弦を求めるためには、C<Math::Trig::acos()> 関数を使うか、
2679逆余弦を求めるためには、L<C<Math::Trig::acos>|Math::Trig> 関数を使うか、
21902680以下の関係を使ってください。
21912681
21922682 sub acos { atan2( sqrt(1 - $_[0] * $_[0]), $_[0] ) }
21932683
21942684=item crypt PLAINTEXT,SALT
21952685X<crypt> X<digest> X<hash> X<salt> X<plaintext> X<password>
21962686X<decrypt> X<cryptography> X<passwd> X<encrypt>
21972687
2688=for Pod::Functions one-way passwd-style encryption
2689
21982690=begin original
21992691
2200Creates a digest string exactly like the crypt(3) function in the C
2692Creates a digest string exactly like the L<crypt(3)> function in the C
22012693library (assuming that you actually have a version there that has not
22022694been extirpated as a potential munition).
22032695
22042696=end original
22052697
2206C ライブラリの crypt(3) 関数と全く同じように、ダイジェスト文字列を
2698C ライブラリの L<crypt(3)> 関数と全く同じように、ダイジェスト文字列を
22072699作成します(一時的な必需品として、まだ絶滅していないバージョンを
22082700持っていると仮定しています)。
22092701
22102702=begin original
22112703
2212crypt() is a one-way hash function. The PLAINTEXT and SALT are turned
2704L<C<crypt>|/crypt PLAINTEXT,SALT> is a one-way hash function. The
2705PLAINTEXT and SALT are turned
22132706into a short string, called a digest, which is returned. The same
22142707PLAINTEXT and SALT will always return the same string, but there is no
22152708(known) way to get the original PLAINTEXT from the hash. Small
22162709changes in the PLAINTEXT or SALT will result in large changes in the
22172710digest.
22182711
22192712=end original
22202713
2221crypt() は一方向ハッシュ関数です。
2714L<C<crypt>|/crypt PLAINTEXT,SALT> は一方向ハッシュ関数です。
22222715PLAINTEXT と SALT はダイジェストと呼ばれる短い文字列に変えられて、
22232716それが返されます。
22242717PLAINTEXT と SALT が同じ場合は常に同じ文字列を返しますが、ハッシュから
22252718元の PLAINTEXT を得る(既知の)方法はありません。
22262719PLAINTEXT や SALT を少し変更してもダイジェストは大きく変更されます。
22272720
22282721=begin original
22292722
22302723There is no decrypt function. This function isn't all that useful for
22312724cryptography (for that, look for F<Crypt> modules on your nearby CPAN
22322725mirror) and the name "crypt" is a bit of a misnomer. Instead it is
22332726primarily used to check if two pieces of text are the same without
22342727having to transmit or store the text itself. An example is checking
22352728if a correct password is given. The digest of the password is stored,
22362729not the password itself. The user types in a password that is
2237crypt()'d with the same salt as the stored digest. If the two digests
2730L<C<crypt>|/crypt PLAINTEXT,SALT>'d with the same salt as the stored
2238match, the password is correct.
2731digest. If the two digests match, the password is correct.
22392732
22402733=end original
22412734
22422735復号化関数はありません。
22432736この関数は暗号化のためにはまったく役に立ちません(このためには、
22442737お近くの CPAN ミラーで F<Crypt> モジュールを探してください)ので、
22452738"crypt" という名前は少し間違った名前です。
22462739その代わりに、一般的には二つのテキスト片が同じかどうかをテキストそのものを
22472740転送したり保管したりせずにチェックするために使います。
22482741例としては、正しいパスワードが与えられたかどうかをチェックがあります。
22492742パスワード自身ではなく、パスワードのダイジェストが保管されます。
22502743ユーザーがパスワードを入力すると、保管されているダイジェストと同じ
2251salt で crypt() します。
2744salt で L<C<crypt>|/crypt PLAINTEXT,SALT> します。
22522745二つのダイジェストが同じなら、パスワードは正しいです。
22532746
22542747=begin original
22552748
22562749When verifying an existing digest string you should use the digest as
22572750the salt (like C<crypt($plain, $digest) eq $digest>). The SALT used
22582751to create the digest is visible as part of the digest. This ensures
2259crypt() will hash the new string with the same salt as the digest.
2752L<C<crypt>|/crypt PLAINTEXT,SALT> will hash the new string with the same
2260This allows your code to work with the standard L<crypt|/crypt> and
2753salt as the digest. This allows your code to work with the standard
2261with more exotic implementations. In other words, assume
2754L<C<crypt>|/crypt PLAINTEXT,SALT> and with more exotic implementations.
2262nothing about the returned string itself nor about how many bytes
2755In other words, assume nothing about the returned string itself nor
2263of SALT may matter.
2756about how many bytes of SALT may matter.
22642757
22652758=end original
22662759
22672760すでにあるダイジェスト文字列を検証するには、ダイジェストを
22682761(C<crypt($plain, $digest) eq $digest> のようにして)salt として使います。
22692762ダイジェストを作るのに使われた SALT はダイジェストの一部として見えます。
2270これにより、crypt() は同じ salt で新しい文字列をダイジェストとして
2763これにより、L<C<crypt>|/crypt PLAINTEXT,SALT> は同じ salt で新しい文字列を
2271ハッシュ化できるようにします。
2764ダイジェストとしてハッシュ化できるようにします。
2272これによって標準的な C<crypt|/crypt> や、より風変わりな実装でも動作します。
2765これによって標準的な L<C<crypt>|/crypt PLAINTEXT,SALT> や、より風変わりな
2766実装でも動作します。
22732767言い換えると、返される文字列や、SALT が何バイトあるかといったことに対して、
22742768どのような仮定もしてはいけません。
22752769
22762770=begin original
22772771
22782772Traditionally the result is a string of 13 bytes: two first bytes of
22792773the salt, followed by 11 bytes from the set C<[./0-9A-Za-z]>, and only
2280the first eight bytes of PLAINTEXT mattered. But alternative
2774the first eight bytes of PLAINTEXT mattered. But alternative
22812775hashing schemes (like MD5), higher level security schemes (like C2),
22822776and implementations on non-Unix platforms may produce different
22832777strings.
22842778
22852779=end original
22862780
22872781伝統的には結果は 13 バイトの文字列です: 最初の 2 バイトは salt、引き続いて
22882782集合 C<[./0-9A-Za-z]> からの 11 バイトで、PLAINTEXT の最初の
228927838 バイトだけが意味があります。
22902784しかし、(MD5 のように) 異なったハッシュ手法、
22912785(C2 のような) 高レベルセキュリティ手法、非 Unix プラットフォームでの
22922786実装などでは異なった文字列が生成されることがあります。
22932787
22942788=begin original
22952789
22962790When choosing a new salt create a random two character string whose
22972791characters come from the set C<[./0-9A-Za-z]> (like C<join '', ('.',
22982792'/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]>). This set of
22992793characters is just a recommendation; the characters allowed in
23002794the salt depend solely on your system's crypt library, and Perl can't
2301restrict what salts C<crypt()> accepts.
2795restrict what salts L<C<crypt>|/crypt PLAINTEXT,SALT> accepts.
23022796
23032797=end original
23042798
23052799新しい salt を選択する場合は、集合 C<[./0-9A-Za-z]> から
2306(C<join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]> のようにして)
2800(C<join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]> の
2307ランダムに2 つの文字を選びます。
2801ようにして)ランダムに2 つの文字を選びます。
23082802この文字集合は単なる推薦です; salt として許される文字はシステムの暗号化
2309ライブラリだけに依存し、Perl は C<crypt()> がどのような salt を受け付けるかに
2803ライブラリだけに依存し、Perl は L<C<crypt>|/crypt PLAINTEXT,SALT> が
2310ついて制限しません。
2804どのような salt を受け付けるかについて制限しません。
23112805
23122806=begin original
23132807
23142808Here's an example that makes sure that whoever runs this program knows
23152809their password:
23162810
23172811=end original
23182812
23192813プログラムを実行する人が、
23202814自分のパスワードを知っていることを確認する例です:
23212815
2322 $pwd = (getpwuid($<))[1];
2816 my $pwd = (getpwuid($<))[1];
23232817
23242818 system "stty -echo";
23252819 print "Password: ";
2326 chomp($word = <STDIN>);
2820 chomp(my $word = <STDIN>);
23272821 print "\n";
23282822 system "stty echo";
23292823
23302824 if (crypt($word, $pwd) ne $pwd) {
23312825 die "Sorry...\n";
23322826 } else {
23332827 print "ok\n";
23342828 }
23352829
23362830=begin original
23372831
23382832Of course, typing in your own password to whoever asks you
23392833for it is unwise.
23402834
23412835=end original
23422836
23432837もちろん、自分自身のパスワードを誰にでも入力するのは賢明ではありません。
23442838
23452839=begin original
23462840
2347The L<crypt|/crypt> function is unsuitable for hashing large quantities
2841The L<C<crypt>|/crypt PLAINTEXT,SALT> function is unsuitable for hashing
2348of data, not least of all because you can't get the information
2842large quantities of data, not least of all because you can't get the
2349back. Look at the L<Digest> module for more robust algorithms.
2843information back. Look at the L<Digest> module for more robust
2844algorithms.
23502845
23512846=end original
23522847
2353L<crypt|/crypt> 関数は大量のデータのハッシュ化には向いていません。
2848L<C<crypt>|/crypt PLAINTEXT,SALT> 関数は大量のデータのハッシュ化には
2354これは情報を戻せないという理由だけではありません。
2849向いていません; これは情報を戻せないという理由だけではありません。
23552850より頑強なアルゴリズムについては L<Digest> モジュールを参照してください。
23562851
23572852=begin original
23582853
2359If using crypt() on a Unicode string (which I<potentially> has
2854If using L<C<crypt>|/crypt PLAINTEXT,SALT> on a Unicode string (which
2360characters with codepoints above 255), Perl tries to make sense
2855I<potentially> has characters with codepoints above 255), Perl tries to
2361of the situation by trying to downgrade (a copy of)
2856make sense of the situation by trying to downgrade (a copy of) the
2362the string back to an eight-bit byte string before calling crypt()
2857string back to an eight-bit byte string before calling
2363(on that copy). If that works, good. If not, crypt() dies with
2858L<C<crypt>|/crypt PLAINTEXT,SALT> (on that copy). If that works, good.
2364C<Wide character in crypt>.
2859If not, L<C<crypt>|/crypt PLAINTEXT,SALT> dies with
2860L<C<Wide character in crypt>|perldiag/Wide character in %s>.
23652861
23662862=end original
23672863
23682864Unicode 文字列(I<潜在的には> 255 を越えるコードポイントを持つ文字を
2369含みます)に crypt() を使った場合、Perl は crypt() を呼び出す前に与えられた
2865含みます)に L<C<crypt>|/crypt PLAINTEXT,SALT> を使った場合、Perl は
2866L<C<crypt>|/crypt PLAINTEXT,SALT> を呼び出す前に与えられた
23702867文字列を8 ビットバイト文字列にダウングレードする(文字列のコピーを作る)
23712868ことで状況のつじつまを合わせようとします。
2372うまく動けば、それでよし。動かなければ、crypt() は
2869うまく動けば、それでよし。
2373C<Wide character in crypt> というメッセージと共に die します。
2870動かなければ、L<C<crypt>|/crypt PLAINTEXT,SALT>
2871L<C<Wide character in crypt>|perldiag/Wide character in %s> という
2872メッセージと共に die します。
23742873
2874=begin original
2875
2876Portability issues: L<perlport/crypt>.
2877
2878=end original
2879
2880移植性の問題: L<perlport/crypt>。
2881
23752882=item dbmclose HASH
23762883X<dbmclose>
23772884
2885=for Pod::Functions breaks binding on a tied dbm file
2886
23782887=begin original
23792888
2380[This function has been largely superseded by the C<untie> function.]
2889[This function has been largely superseded by the
2890L<C<untie>|/untie VARIABLE> function.]
23812891
23822892=end original
23832893
2384[この関数は、C<untie> 関数に大きくとって代わられました。]
2894[この関数は、L<C<untie>|/untie VARIABLE> 関数に大きくとって代わられました。]
23852895
23862896=begin original
23872897
23882898Breaks the binding between a DBM file and a hash.
23892899
23902900=end original
23912901
23922902DBM ファイルとハッシュの連結をはずします。
23932903
2904=begin original
2905
2906Portability issues: L<perlport/dbmclose>.
2907
2908=end original
2909
2910移植性の問題: L<perlport/dbmclose>。
2911
23942912=item dbmopen HASH,DBNAME,MASK
23952913X<dbmopen> X<dbm> X<ndbm> X<sdbm> X<gdbm>
23962914
2915=for Pod::Functions create binding on a tied dbm file
2916
23972917=begin original
23982918
2399[This function has been largely superseded by the C<tie> function.]
2919[This function has been largely superseded by the
2920L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function.]
24002921
24012922=end original
24022923
2403[この関数は、C<tie> 関数に大きくとって代わられました。]
2924[この関数は、L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数に
2925大きくとって代わられました。]
24042926
24052927=begin original
24062928
2407This binds a dbm(3), ndbm(3), sdbm(3), gdbm(3), or Berkeley DB file to a
2929This binds a L<dbm(3)>, L<ndbm(3)>, L<sdbm(3)>, L<gdbm(3)>, or Berkeley
2408hash. HASH is the name of the hash. (Unlike normal C<open>, the first
2930DB file to a hash. HASH is the name of the hash. (Unlike normal
2409argument is I<not> a filehandle, even though it looks like one). DBNAME
2931L<C<open>|/open FILEHANDLE,EXPR>, the first argument is I<not> a
2410is the name of the database (without the F<.dir> or F<.pag> extension if
2932filehandle, even though it looks like one). DBNAME is the name of the
2411any). If the database does not exist, it is created with protection
2933database (without the F<.dir> or F<.pag> extension if any). If the
2412specified by MASK (as modified by the C<umask>). If your system supports
2934database does not exist, it is created with protection specified by MASK
2413only the older DBM functions, you may make only one C<dbmopen> call in your
2935(as modified by the L<C<umask>|/umask EXPR>). To prevent creation of
2936the database if it doesn't exist, you may specify a MODE of 0, and the
2937function will return a false value if it can't find an existing
2938database. If your system supports only the older DBM functions, you may
2939make only one L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> call in your
24142940program. In older versions of Perl, if your system had neither DBM nor
2415ndbm, calling C<dbmopen> produced a fatal error; it now falls back to
2941ndbm, calling L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> produced a fatal
2416sdbm(3).
2942error; it now falls back to L<sdbm(3)>.
24172943
24182944=end original
24192945
2420dbm(3), ndbm(3), sdbm(3), gdbm(3) ファイルまたは Berkeley DB
2946L<dbm(3)>, L<ndbm(3)>, L<sdbm(3)>, L<gdbm(3)> ファイルまたは
2421ファイルを連想配列に結び付けます。
2947Berkeley DB ファイルを連想配列に結び付けます。
24222948HASH は、その連想配列の名前です。
2423(普通の C<open> とは違って、最初の引数はファイルハンドル
2949(普通の L<C<open>|/open FILEHANDLE,EXPR> とは違って、最初の引数は
2424I<ではありません>まあ、似たようなものですが)
2950ファイルハンドル I<ではありません>; まあ、似たようなものですが)
2425DBNAME は、データベースの名前です (拡張子の .dir や
2951DBNAME は、データベースの名前です (拡張子の .dir や .pag はもしあっても
2426.pag はもしあってもつけません)。
2952つけません)。
2427データベースが存在しなければ、MODE MASK (を C<umask> で修正したもの)
2953データベースが存在しなければ、MODE MASK (を L<C<umask>|/umask EXPR>
2428指定されたモードで作られます。
2954修正したもの) で指定されたモードで作られます。
2955存在しないときにデータベースを作成しないようにするには、MODE に 0 を
2956設定でき、データベースを見つけられなかった場合は関数は偽を返します。
24292957古い DBM 関数のみをサポートしているシステムでは、プログラム中で 1 度だけ
2430dbmopen() を実行することができます。
2958L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を実行することができます。
24312959昔のバージョンの Perl では、DBM も ndbm も持っていないシステムでは、
2432dbmopen() を呼び出すと致命的エラーになります
2960L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を呼び出すと致命的エラーになります;
2433現在では sdbm(3) にフォールバックします。
2961現在では L<sdbm(3)> にフォールバックします。
24342962
24352963=begin original
24362964
24372965If you don't have write access to the DBM file, you can only read hash
24382966variables, not set them. If you want to test whether you can write,
2439either use file tests or try setting a dummy hash entry inside an C<eval>
2967either use file tests or try setting a dummy hash entry inside an
2440to trap the error.
2968L<C<eval>|/eval EXPR> to trap the error.
24412969
24422970=end original
24432971
24442972DBM ファイルに対して、書き込み権が無いときには、ハッシュ
24452973配列を読みだすことだけができ、設定することはできません。
24462974書けるか否かを調べたい場合には、ファイルテスト
2447演算子を使うか、エラーをトラップするための C<eval> の中で、
2975演算子を使うか、エラーをトラップするための L<C<eval>|/eval EXPR> の中で、
24482976ダミーのハッシュエントリを設定してみることになります。
24492977
24502978=begin original
24512979
2452Note that functions such as C<keys> and C<values> may return huge lists
2980Note that functions such as L<C<keys>|/keys HASH> and
2453when used on large DBM files. You may prefer to use the C<each>
2981L<C<values>|/values HASH> may return huge lists when used on large DBM
2454function to iterate over large DBM files. Example:
2982files. You may prefer to use the L<C<each>|/each HASH> function to
2983iterate over large DBM files. Example:
24552984
24562985=end original
24572986
2458大きな DBM ファイルを扱うときには、C<keys> や C<values> のような関数は、
2987大きな DBM ファイルを扱うときには、L<C<keys>|/keys HASH>
2459巨大なリストを返します。
2988L<C<values>|/values HASH> のような関数は、巨大なリストを返します。
2460大きな DBM ファイルでは、C<each> 関数を使って繰り返しを行なった方が
2989大きな DBM ファイルでは、L<C<each>|/each HASH> 関数を使って繰り返しを
2461良いかもしれません。
2990行なった方が良いかもしれません。
24622991例:
24632992
24642993 # print out history file offsets
24652994 dbmopen(%HIST,'/usr/lib/news/history',0666);
24662995 while (($key,$val) = each %HIST) {
24672996 print $key, ' = ', unpack('L',$val), "\n";
24682997 }
24692998 dbmclose(%HIST);
24702999
24713000=begin original
24723001
24733002See also L<AnyDBM_File> for a more general description of the pros and
24743003cons of the various dbm approaches, as well as L<DB_File> for a particularly
24753004rich implementation.
24763005
24773006=end original
24783007
24793008様々な dbm 手法に対する利点欠点に関するより一般的な記述および
24803009特にリッチな実装である L<DB_File> に関しては
24813010L<AnyDBM_File> も参照してください。
24823011
24833012=begin original
24843013
24853014You can control which DBM library you use by loading that library
2486before you call dbmopen():
3015before you call L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>:
24873016
24883017=end original
24893018
2490dbmopen() を呼び出す前にライブラリを読み込むことで、
3019L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を呼び出す前にライブラリを
2491どの DBM ライブラリを使うかを制御できます:
3020読み込むことで、どの DBM ライブラリを使うかを制御できます:
24923021
24933022 use DB_File;
24943023 dbmopen(%NS_Hist, "$ENV{HOME}/.netscape/history.db")
24953024 or die "Can't open netscape history file: $!";
24963025
2497=item default BLOCK
2498
24993026=begin original
25003027
2501Within a C<foreach> or a C<given>, a C<default> BLOCK acts like a C<when>
3028Portability issues: L<perlport/dbmopen>.
2502that's always true. Only available after Perl 5.10, and only if the
2503C<switch> feature has been requested. See L</when>.
25043029
25053030=end original
25063031
2507C<foreach> や C<given> の中では、C<default> BLOCK は常に真の C<when>
3032移植性の問題: L<perlport/dbmopen>
2508ように動作します。
2509Perl 5.10 以降でのみ、かつ C<switch> 機能が有効の場合にのみ利用可能です。
2510L</when> を参照してください。
25113033
25123034=item defined EXPR
25133035X<defined> X<undef> X<undefined>
25143036
25153037=item defined
25163038
3039=for Pod::Functions test whether a value, variable, or function is defined
3040
25173041=begin original
25183042
2519Returns a Boolean value telling whether EXPR has a value other than
3043Returns a Boolean value telling whether EXPR has a value other than the
2520the undefined value C<undef>. If EXPR is not present, C<$_> is
3044undefined value L<C<undef>|/undef EXPR>. If EXPR is not present,
2521checked.
3045L<C<$_>|perlvar/$_> is checked.
25223046
25233047=end original
25243048
2525左辺値 EXPR が未定義値 C<undef> 以外の値を持つか否かを示す、ブール値を
3049左辺値 EXPR が未定義値 L<C<undef>|/undef EXPR> 以外の値を持つか否かを示す、
2526返します。
3050ブール値を返します。
2527EXPR がない場合は、C<$_> がチェックされます。
3051EXPR がない場合は、L<C<$_>|perlvar/$_> がチェックされます。
25283052
25293053=begin original
25303054
2531Many operations return C<undef> to indicate failure, end of file,
3055Many operations return L<C<undef>|/undef EXPR> to indicate failure, end
2532system error, uninitialized variable, and other exceptional
3056of file, system error, uninitialized variable, and other exceptional
2533conditions. This function allows you to distinguish C<undef> from
3057conditions. This function allows you to distinguish
2534other values. (A simple Boolean test will not distinguish among
3058L<C<undef>|/undef EXPR> from other values. (A simple Boolean test will
2535C<undef>, zero, the empty string, and C<"0">, which are all equally
3059not distinguish among L<C<undef>|/undef EXPR>, zero, the empty string,
2536false.) Note that since C<undef> is a valid scalar, its presence
3060and C<"0">, which are all equally false.) Note that since
2537doesn't I<necessarily> indicate an exceptional condition: C<pop>
3061L<C<undef>|/undef EXPR> is a valid scalar, its presence doesn't
2538returns C<undef> when its argument is an empty array, I<or> when the
3062I<necessarily> indicate an exceptional condition: L<C<pop>|/pop ARRAY>
2539element to return happens to be C<undef>.
3063returns L<C<undef>|/undef EXPR> when its argument is an empty array,
3064I<or> when the element to return happens to be L<C<undef>|/undef EXPR>.
25403065
25413066=end original
25423067
25433068多くの演算子が、EOF や未初期化変数、システムエラーといった、
2544例外的な条件で C<undef> を返すようになっています。
3069例外的な条件で L<C<undef>|/undef EXPR> を返すようになっています。
2545この関数は、他の値と C<undef> とを区別するために使えます。
3070この関数は、他の値と L<C<undef>|/undef EXPR> とを区別するために使えます。
2546(単純な真偽値テストでは、C<undef>、0、C<"0"> のいずれも偽を返すので、
3071(単純な真偽値テストでは、L<C<undef>|/undef EXPR>、0、C<"0"> のいずれも偽を
2547区別することができません。)
3072返すので、区別することができません。)
2548C<undef> は有効なスカラ値なので、その存在が I<必ずしも>
3073L<C<undef>|/undef EXPR> は有効なスカラ値なので、その存在が I<必ずしも>
25493074例外的な状況を表すとは限らないということに注意してください:
2550C<pop> は引数が空の配列だったときに C<undef> を返しますが、
3075L<C<pop>|/pop ARRAY> は引数が空の配列だったときに L<C<undef>|/undef EXPR>
2551I<あるいは> 返すべき要素がたまたま C<undef> だったのかもしれません。
3076返しますが、I<あるいは> 返すべき要素がたまたま
3077L<C<undef>|/undef EXPR> だったのかもしれません。
25523078
25533079=begin original
25543080
2555You may also use C<defined(&func)> to check whether subroutine C<&func>
3081You may also use C<defined(&func)> to check whether subroutine C<func>
25563082has ever been defined. The return value is unaffected by any forward
2557declarations of C<&func>. A subroutine that is not defined
3083declarations of C<func>. A subroutine that is not defined
25583084may still be callable: its package may have an C<AUTOLOAD> method that
25593085makes it spring into existence the first time that it is called; see
25603086L<perlsub>.
25613087
25623088=end original
25633089
2564C<defined(&func)> とすることでサブルーチン C<&func> の存在を、
3090C<defined(&func)> とすることでサブルーチン C<func> の存在を、
25653091確かめることもできます。
2566返り値は C<&func> の前方定義には影響されません。
3092返り値は C<func> の前方定義には影響されません。
25673093定義されていないサブルーチンも呼び出し可能です:
25683094最初に呼び出されたときに存在するようにするための
25693095C<AUTOLOAD> メソッドを持ったパッケージかもしれません;
2570L<perlsub> を参照してさい。
3096L<perlsub> を参照してください。
25713097
25723098=begin original
25733099
2574Use of C<defined> on aggregates (hashes and arrays) is deprecated. It
3100Use of L<C<defined>|/defined EXPR> on aggregates (hashes and arrays) is
3101deprecated. It
25753102used to report whether memory for that aggregate had ever been
25763103allocated. This behavior may disappear in future versions of Perl.
25773104You should instead use a simple test for size:
25783105
25793106=end original
25803107
2581集合(ハッシュや配列)への C<defined> の使用は非推奨です。
3108集合(ハッシュや配列)への L<C<defined>|/defined EXPR> の使用は非推奨です。
25823109これはその集合にメモリが割り当てられたかを報告するのに
25833110用いられていました。
25843111この振る舞いは将来のバージョンの Perl では消滅するかもしれません。
25853112代わりにサイズに対する簡単なテストを使うべきです。
25863113
25873114 if (@an_array) { print "has array elements\n" }
25883115 if (%a_hash) { print "has hash members\n" }
25893116
25903117=begin original
25913118
25923119When used on a hash element, it tells you whether the value is defined,
2593not whether the key exists in the hash. Use L</exists> for the latter
3120not whether the key exists in the hash. Use L<C<exists>|/exists EXPR>
2594purpose.
3121for the latter purpose.
25953122
25963123=end original
25973124
25983125ハッシュの要素に対して用いると、value が定義されているか否かを
25993126返すものであって、ハッシュに key が存在するか否かを返すのではありません。
2600この用途には、L</exists> を使ってください。
3127この用途には、L<C<exists>|/exists EXPR> を使ってください。
26013128
26023129=begin original
26033130
26043131Examples:
26053132
26063133=end original
26073134
26083135例:
26093136
26103137 print if defined $switch{D};
26113138 print "$val\n" while defined($val = pop(@ary));
26123139 die "Can't readlink $sym: $!"
26133140 unless defined($value = readlink $sym);
2614 sub foo { defined &$bar ? &$bar(@_) : die "No bar"; }
3141 sub foo { defined &$bar ? $bar->(@_) : die "No bar"; }
26153142 $debugging = 0 unless defined $debugging;
26163143
26173144=begin original
26183145
2619Note: Many folks tend to overuse C<defined> and are then surprised to
3146Note: Many folks tend to overuse L<C<defined>|/defined EXPR> and are
2620discover that the number C<0> and C<""> (the zero-length string) are, in fact,
3147then surprised to discover that the number C<0> and C<""> (the
2621defined values. For example, if you say
3148zero-length string) are, in fact, defined values. For example, if you
3149say
26223150
26233151=end original
26243152
2625注意: 多くの人々が C<defined> を使いすぎて、C<0> と C<"">(空文字列) が
3153注意: 多くの人々が L<C<defined>|/defined EXPR> を使いすぎて、C<0> と
2626実際のところ定義された値であることに驚くようです。
3154C<"">(空文字列) が実際のところ定義された値であることに驚くようです。
26273155例えば、以下のように書くと:
26283156
26293157 "ab" =~ /a(.*)b/;
26303158
26313159=begin original
26323160
26333161The pattern match succeeds and C<$1> is defined, although it
26343162matched "nothing". It didn't really fail to match anything. Rather, it
26353163matched something that happened to be zero characters long. This is all
26363164very above-board and honest. When a function returns an undefined value,
26373165it's an admission that it couldn't give you an honest answer. So you
2638should use C<defined> only when questioning the integrity of what
3166should use L<C<defined>|/defined EXPR> only when questioning the
2639you're trying to do. At other times, a simple comparison to C<0> or C<""> is
3167integrity of what you're trying to do. At other times, a simple
2640what you want.
3168comparison to C<0> or C<""> is what you want.
26413169
26423170=end original
26433171
26443172パターンマッチングが成功し、C<$1> が定義されても、実際には
26453173「なし」にマッチしています。
26463174しかしこれは何にもマッチしていないわけではありません。
26473175何かにはマッチしているのですが、たまたまそれが長さ 0 だっただけです。
26483176これは非常に率直で正直なことです。
26493177関数が未定義値を返すとき、正直な答えを返すことができないことを
26503178告白しています。
26513179ですので、あなたが自分がしようとしていることの完全性を確認するときにだけ
2652C<defined> を使うべきです。
3180L<C<defined>|/defined EXPR> を使うべきです。
26533181その他の場合では、単に C<0> または C<""> と比較するというのがあなたの
26543182求めているものです。
26553183
26563184=begin original
26573185
2658See also L</undef>, L</exists>, L</ref>.
3186See also L<C<undef>|/undef EXPR>, L<C<exists>|/exists EXPR>,
3187L<C<ref>|/ref EXPR>.
26593188
26603189=end original
26613190
2662L</undef>, L</exists>, L</ref> も参照してください。
3191L<C<undef>|/undef EXPR>, L<C<exists>|/exists EXPR>, L<C<ref>|/ref EXPR> も
3192参照してください。
26633193
26643194=item delete EXPR
26653195X<delete>
26663196
3197=for Pod::Functions deletes a value from a hash
3198
26673199=begin original
26683200
2669Given an expression that specifies an element or slice of a hash, C<delete>
3201Given an expression that specifies an element or slice of a hash,
2670deletes the specified elements from that hash so that exists() on that element
3202L<C<delete>|/delete EXPR> deletes the specified elements from that hash
2671no longer returns true. Setting a hash element to the undefined value does
3203so that L<C<exists>|/exists EXPR> on that element no longer returns
2672not remove its key, but deleting it does; see L</exists>.
3204true. Setting a hash element to the undefined value does not remove its
3205key, but deleting it does; see L<C<exists>|/exists EXPR>.
26733206
26743207=end original
26753208
2676ハッシュの要素やスライスを指定する式を取り、C<delete> は
3209ハッシュの要素やスライスを指定する式を取り、L<C<delete>|/delete EXPR> は
26773210指定された要素をハッシュから削除するので、
2678その要素に対する exists() はもはや真を返さなくなります。
3211その要素に対する L<C<exists>|/exists EXPR> はもはや真を返さなくなります。
26793212ハッシュ要素に未定義値をセットしてもそのキーは削除されませんが、
2680delete では削除されます; L</exists> を参照してください。
3213delete では削除されます; L<C<exists>|/exists EXPR> を参照してください。
26813214
26823215=begin original
26833216
26843217In list context, returns the value or values deleted, or the last such
26853218element in scalar context. The return list's length always matches that of
26863219the argument list: deleting non-existent elements returns the undefined value
26873220in their corresponding positions.
26883221
26893222=end original
26903223
26913224リストコンテキストでは削除された要素を返し、スカラコンテキストでは
26923225削除された要素のうち最後のものを返します。
26933226返されたリストの長さは常に引数リストの長さと一致します:
26943227存在しない要素を削除すると、対応する位置に未定義値をセットして返します。
26953228
26963229=begin original
26973230
2698delete() may also be used on arrays and array slices, but its behavior is less
3231L<C<delete>|/delete EXPR> may also be used on arrays and array slices,
2699straightforward. Although exists() will return false for deleted entries,
3232but its behavior is less straightforward. Although
2700deleting array elements never changes indices of existing values; use shift()
3233L<C<exists>|/exists EXPR> will return false for deleted entries,
2701or splice() for that. However, if all deleted elements fall at the end of an
3234deleting array elements never changes indices of existing values; use
2702array, the array's size shrinks to the position of the highest element that
3235L<C<shift>|/shift ARRAY> or L<C<splice>|/splice
2703still tests true for exists(), or to 0 if none do.
3236ARRAY,OFFSET,LENGTH,LIST> for that. However, if any deleted elements
3237fall at the end of an array, the array's size shrinks to the position of
3238the highest element that still tests true for L<C<exists>|/exists EXPR>,
3239or to 0 if none do. In other words, an array won't have trailing
3240nonexistent elements after a delete.
27043241
27053242=end original
27063243
2707delete() は配列や配列のスライスに対しても使えますが、その振る舞いは
3244L<C<delete>|/delete EXPR> は配列や配列のスライスに対しても使えますが、その
2708あまり直感的ではありません。
3245振る舞いはあまり直感的ではありません。
2709削除されたエントリに対しては exists() は偽を返しますが、
3246削除されたエントリに対しては L<C<exists>|/exists EXPR> は偽を返しますが、
27103247配列要素を削除しても、存在する値の添え字は変わりません; このためには
2711shift() や splice()使ってください。
3248L<C<shift>|/shift ARRAY> L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST>
2712しかし、全の削除れた要素が配列の末尾であった場合、配列のサイズは
3249使っくだい。
2713exists() が真となる最大位置の要素(それない場合は 0)に切り詰められます。
3250しかし、削除された要素が配列の末尾であった場合、配列のサイズ
3251L<C<exists>|/exists EXPR> が真となる最大位置の要素(それがない場合は 0)に
3252切り詰められます。
3253言い換えると、delete の後には配列の末尾に値のない要素はありません。
27143254
27153255=begin original
27163256
2717B<WARNING:> Calling delete on array values is deprecated and likely to
3257B<WARNING:> Calling L<C<delete>|/delete EXPR> on array values is
2718be removed in a future version of Perl.
3258strongly discouraged. The
3259notion of deleting or checking the existence of Perl array elements is not
3260conceptually coherent, and can lead to surprising behavior.
27193261
27203262=end original
27213263
2722B<警告:> 配列の値に対して delete を呼び出すことは非推奨で、将来の
3264B<警告:> 配列の値に対して L<C<delete>|/delete EXPR> を呼び出すことは強く
2723バージョンの Perl では削除される予定です。
3265非推奨です。
3266Perl の配列要素を削除したり存在を調べたりする記法は概念的に一貫しておらず、
3267驚くべき振る舞いを引き起こすことがあります。
27243268
27253269=begin original
27263270
2727Deleting from C<%ENV> modifies the environment. Deleting from a hash tied to
3271Deleting from L<C<%ENV>|perlvar/%ENV> modifies the environment.
2728a DBM file deletes the entry from the DBM file. Deleting from a C<tied> hash
3272Deleting from a hash tied to a DBM file deletes the entry from the DBM
2729or array may not necessarily return anything; it depends on the implementation
3273file. Deleting from a L<C<tied>|/tied VARIABLE> hash or array may not
2730of the C<tied> package's DELETE method, which may do whatever it pleases.
3274necessarily return anything; it depends on the implementation of the
3275L<C<tied>|/tied VARIABLE> package's DELETE method, which may do whatever
3276it pleases.
27313277
27323278=end original
27333279
2734C<%ENV> から削除を行なうと、実際に環境変数を変更します。
3280L<C<%ENV>|perlvar/%ENV> から削除を行なうと、実際に環境変数を変更します。
27353281DBM ファイルに tie された配列からの削除は、その DBM ファイルからエントリを
27363282削除します。
2737しかし、C<tie> されたハッシュや配列からの削除は、
3283しかし、L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> されたハッシュや配列からの
2738値を返すとは限りません; これは C<tie> されたパッケージの DELETE
3284削除は、値を返すとは限りません; これは
3285L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> されたパッケージの DELETE
27393286メソッドの実装に依存するので、どんなことでも起こります。
27403287
27413288=begin original
27423289
27433290The C<delete local EXPR> construct localizes the deletion to the current
27443291block at run time. Until the block exits, elements locally deleted
27453292temporarily no longer exist. See L<perlsub/"Localized deletion of elements
27463293of composite types">.
27473294
27483295=end original
27493296
27503297C<delete local EXPR> 構文は、現在のブロックの削除を実行時にローカル化します。
27513298ブロックから出るまで、ローカルで削除された要素は存在しなくなります。
27523299L<perlsub/"Localized deletion of elements of composite types"> を
27533300参照してください。
27543301
2755 %hash = (foo => 11, bar => 22, baz => 33);
3302 my %hash = (foo => 11, bar => 22, baz => 33);
2756 $scalar = delete $hash{foo}; # $scalar is 11
3303 my $scalar = delete $hash{foo}; # $scalar is 11
2757 $scalar = delete @hash{qw(foo bar)}; # $scalar is 22
3304 $scalar = delete @hash{qw(foo bar)}; # $scalar is 22
2758 @array = delete @hash{qw(foo bar baz)}; # @array is (undef,undef,33)
3305 my @array = delete @hash{qw(foo baz)}; # @array is (undef,33)
27593306
27603307=begin original
27613308
27623309The following (inefficiently) deletes all the values of %HASH and @ARRAY:
27633310
27643311=end original
27653312
27663313以下は、%HASH と @ARRAY のすべての値を(非効率的に)削除します:
27673314
2768 foreach $key (keys %HASH) {
3315 foreach my $key (keys %HASH) {
27693316 delete $HASH{$key};
27703317 }
27713318
2772 foreach $index (0 .. $#ARRAY) {
3319 foreach my $index (0 .. $#ARRAY) {
27733320 delete $ARRAY[$index];
27743321 }
27753322
27763323=begin original
27773324
27783325And so do these:
27793326
27803327=end original
27813328
27823329そして以下のようにもできます:
27833330
27843331 delete @HASH{keys %HASH};
27853332
27863333 delete @ARRAY[0 .. $#ARRAY];
27873334
27883335=begin original
27893336
27903337But both are slower than assigning the empty list
2791or undefining %HASH or @ARRAY, which is the customary
3338or undefining %HASH or @ARRAY, which is the customary
27923339way to empty out an aggregate:
27933340
27943341=end original
27953342
27963343しかし、これら二つは両方とも、構造を空にするための慣習的な方法である、
27973344単に空リストを代入するか、%HASH や @ARRAY を
27983345undef するより遅いです:
27993346
28003347 %HASH = (); # completely empty %HASH
28013348 undef %HASH; # forget %HASH ever existed
28023349
28033350 @ARRAY = (); # completely empty @ARRAY
28043351 undef @ARRAY; # forget @ARRAY ever existed
28053352
28063353=begin original
28073354
28083355The EXPR can be arbitrarily complicated provided its
28093356final operation is an element or slice of an aggregate:
28103357
28113358=end original
28123359
28133360最終的な操作が集合の要素かスライスである限りは、
28143361いずれかである限りは、EXPR には任意の複雑な式を置くことができます:
28153362
28163363 delete $ref->[$x][$y]{$key};
28173364 delete @{$ref->[$x][$y]}{$key1, $key2, @morekeys};
28183365
28193366 delete $ref->[$x][$y][$index];
28203367 delete @{$ref->[$x][$y]}[$index1, $index2, @moreindices];
28213368
28223369=item die LIST
28233370X<die> X<throw> X<exception> X<raise> X<$@> X<abort>
28243371
3372=for Pod::Functions raise an exception or bail out
3373
28253374=begin original
28263375
2827C<die> raises an exception. Inside an C<eval> the error message is stuffed
3376L<C<die>|/die LIST> raises an exception. Inside an
2828into C<$@> and the C<eval> is terminated with the undefined value.
3377L<C<eval>|/eval EXPR> the error message is stuffed into
2829If the exception is outside of all enclosing C<eval>s, then the uncaught
3378L<C<$@>|perlvar/$@> and the L<C<eval>|/eval EXPR> is terminated with the
2830exception prints LIST to C<STDERR> and exits with a non-zero value. If you
3379undefined value. If the exception is outside of all enclosing
2831need to exit the process with a specific exit code, see L</exit>.
3380L<C<eval>|/eval EXPR>s, then the uncaught exception prints LIST to
3381C<STDERR> and exits with a non-zero value. If you need to exit the
3382process with a specific exit code, see L<C<exit>|/exit EXPR>.
28323383
28333384=end original
28343385
2835C<die> は例外を発生させます。
3386L<C<die>|/die LIST> は例外を発生させます。
2836C<eval> の中で使用すると、エラーメッセージが C<$@> に入り、C<eval> は
3387L<C<eval>|/eval EXPR> の中で使用すると、エラーメッセージが
3388L<C<$@>|perlvar/$@> に入り、L<C<eval>|/eval EXPR> は
28373389未定義値を返して終了します。
2838例外が全ての C<eval> の外側の場合は、捕捉されなかった例外は LIST を
3390例外が全ての L<C<eval>|/eval EXPR> の外側の場合は、捕捉されなかった例外は
2839C<STDERR> に表示して、非 0 の値で終了します。
3391LIST を C<STDERR> に表示して、非 0 の値で終了します。
2840特定の終了コードでプロセスを終了させる必要がある場合は、L</exit> を
3392特定の終了コードでプロセスを終了させる必要がある場合は、
2841参照してください。
3393L<C<exit>|/exit EXPR> を参照してください。
28423394
28433395=begin original
28443396
28453397Equivalent examples:
28463398
28473399=end original
28483400
28493401等価な例:
28503402
28513403 die "Can't cd to spool: $!\n" unless chdir '/usr/spool/news';
28523404 chdir '/usr/spool/news' or die "Can't cd to spool: $!\n"
28533405
28543406=begin original
28553407
28563408If the last element of LIST does not end in a newline, the current
28573409script line number and input line number (if any) are also printed,
28583410and a newline is supplied. Note that the "input line number" (also
28593411known as "chunk") is subject to whatever notion of "line" happens to
28603412be currently in effect, and is also available as the special variable
2861C<$.>. See L<perlvar/"$/"> and L<perlvar/"$.">.
3413L<C<$.>|perlvar/$.>. See L<perlvar/"$/"> and L<perlvar/"$.">.
28623414
28633415=end original
28643416
2865LIST の最後の要素が改行で終わっていなければ、その時点の
3417LIST の最後の要素が改行で終わっていなければ、その時点のスクリプト名と
2866スクリプト名とスクリプトの行番号、(もしあれば)
3418スクリプトの行番号、(もしあれば) 入力ファイルの行番号と改行文字が、続けて
2867入力ファイルの行番号と改行文字が、続けて表示されます。
3419表示されます。
2868「入力行番号」("chunk" とも呼ばれます)は
3420「入力行番号」("chunk" とも呼ばれます)は「行」という概念が現在有効であると
2869「行」という概念が現在有効であると仮定しています。
3421仮定しています; また特殊変数 L<C<$.>|perlvar/$.> でも利用可能です。
2870また特殊変数 C<$.> でも利用可能です。
28713422L<perlvar/"$/"> と L<perlvar/"$."> も参照してください。
28723423
28733424=begin original
28743425
28753426Hint: sometimes appending C<", stopped"> to your message will cause it
28763427to make better sense when the string C<"at foo line 123"> is appended.
28773428Suppose you are running script "canasta".
28783429
28793430=end original
28803431
28813432ヒント: メッセージの最後を C<", stopped"> のようなもので
28823433終わるようにしておけば、C<"at foo line 123"> のように
28833434追加されて、わかりやすくなります。
28843435"canasta" というスクリプトを実行しているとします。
28853436
28863437 die "/etc/games is no good";
28873438 die "/etc/games is no good, stopped";
28883439
28893440=begin original
28903441
28913442produce, respectively
28923443
28933444=end original
28943445
28953446これは、それぞれ以下のように表示します。
28963447
28973448 /etc/games is no good at canasta line 123.
28983449 /etc/games is no good, stopped at canasta line 123.
28993450
29003451=begin original
29013452
2902If the output is empty and C<$@> already contains a value (typically from a
3453If the output is empty and L<C<$@>|perlvar/$@> already contains a value
2903previous eval) that value is reused after appending C<"\t...propagated">.
3454(typically from a previous eval) that value is reused after appending
2904This is useful for propagating exceptions:
3455C<"\t...propagated">. This is useful for propagating exceptions:
29053456
29063457=end original
29073458
2908出力が空で C<$@> が(典型的には前回の eval で)既に値を持っている場合、
3459出力が空で L<C<$@>|perlvar/$@> が(典型的には前回の eval で)既に値を持っている
2909値は C<"\t...propagated"> を追加した後再利用されます。
3460場合、値は C<"\t...propagated"> を追加した後再利用されます。
29103461これは例外を伝播させる場合に有効です:
29113462
29123463 eval { ... };
29133464 die unless $@ =~ /Expected exception/;
29143465
29153466=begin original
29163467
2917If the output is empty and C<$@> contains an object reference that has a
3468If the output is empty and L<C<$@>|perlvar/$@> contains an object
2918C<PROPAGATE> method, that method will be called with additional file
3469reference that has a C<PROPAGATE> method, that method will be called
2919and line number parameters. The return value replaces the value in
3470with additional file and line number parameters. The return value
2920C<$@>; i.e., as if C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >>
3471replaces the value in L<C<$@>|perlvar/$@>; i.e., as if
2921were called.
3472C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >> were called.
29223473
29233474=end original
29243475
2925出力が空で、C<$@> が C<PROPAGATE> メソッドを含むオブジェクトへの
3476出力が空で、L<C<$@>|perlvar/$@> が C<PROPAGATE> メソッドを含むオブジェクトへの
29263477リファレンスを含む場合、このメソッドが追加ファイルと行番号を引数として
29273478呼び出されます。
2928返り値は C<$@> の値を置き換えます;
3479返り値は L<C<$@>|perlvar/$@> の値を置き換えます;
29293480つまり、C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >> が
29303481呼び出されたかのようになります。
29313482
29323483=begin original
29333484
2934If C<$@> is empty then the string C<"Died"> is used.
3485If L<C<$@>|perlvar/$@> is empty, then the string C<"Died"> is used.
29353486
29363487=end original
29373488
2938C<$@> が空の場合、C<"Died"> が使われます。
3489L<C<$@>|perlvar/$@> が空の場合、C<"Died"> が使われます。
29393490
29403491=begin original
29413492
29423493If an uncaught exception results in interpreter exit, the exit code is
2943determined from the values of C<$!> and C<$?> with this pseudocode:
3494determined from the values of L<C<$!>|perlvar/$!> and
3495L<C<$?>|perlvar/$?> with this pseudocode:
29443496
29453497=end original
29463498
29473499例外が捕捉されないとインタプリタは終了し、終了コードは以下の
2948擬似コードのように、C<$!> と C<$?> の値から決定されます:
3500擬似コードのように、L<C<$!>|perlvar/$!>L<C<$?>|perlvar/$?> の値から
3501決定されます:
29493502
29503503 exit $! if $!; # errno
29513504 exit $? >> 8 if $? >> 8; # child exit status
29523505 exit 255; # last resort
29533506
29543507=begin original
29553508
3509As with L<C<exit>|/exit EXPR>, L<C<$?>|perlvar/$?> is set prior to
3510unwinding the call stack; any C<DESTROY> or C<END> handlers can then
3511alter this value, and thus Perl's exit code.
3512
3513=end original
3514
3515L<C<exit>|/exit EXPR> と同様に、コールスタックを巻き戻す前に
3516L<C<$?>|perlvar/$?> が設定されます; C<DESTROY> と C<END> のハンドラが
3517それからこの値を変更して、これが Perl の終了コードになります。
3518
3519=begin original
3520
29563521The intent is to squeeze as much possible information about the likely cause
2957into the limited space of the system exit code. However, as C<$!> is the value
3522into the limited space of the system exit code. However, as
2958of C's C<errno>, which can be set by any system call, this means that the value
3523L<C<$!>|perlvar/$!> is the value of C's C<errno>, which can be set by
2959of the exit code used by C<die> can be non-predictable, so should not be relied
3524any system call, this means that the value of the exit code used by
3525L<C<die>|/die LIST> can be non-predictable, so should not be relied
29603526upon, other than to be non-zero.
29613527
29623528=end original
29633529
29643530この意図は、できるだけ多くの似たような原因に関する情報を、システム終了
29653531コードという限られた領域に圧縮することです。
2966しかし、C<$!> はシステムコールによって設定される可能性がある C の
3532しかし、L<C<$!>|perlvar/$!> はシステムコールによって設定される可能性がある C の
2967C<errno> の値であり、C<die> によって使われる終了コードの値は
3533C<errno> の値であり、L<C<die>|/die LIST> によって使われる終了コードの値は
29683534予測不能であることを意味するので、非 0 ということ以上にこの値に
29693535依存するべきではありません。
29703536
29713537=begin original
29723538
2973You can also call C<die> with a reference argument, and if this is trapped
3539You can also call L<C<die>|/die LIST> with a reference argument, and if
2974within an C<eval>, C<$@> contains that reference. This permits more
3540this is trapped within an L<C<eval>|/eval EXPR>, L<C<$@>|perlvar/$@>
2975elaborate exception handling using objects that maintain arbitrary state
3541contains that reference. This permits more elaborate exception handling
2976about the exception. Such a scheme is sometimes preferable to matching
3542using objects that maintain arbitrary state about the exception. Such a
2977particular string values of C<$@> with regular expressions. Because C<$@>
3543scheme is sometimes preferable to matching particular string values of
2978is a global variable and C<eval> may be used within object implementations,
3544L<C<$@>|perlvar/$@> with regular expressions. Because
2979be careful that analyzing the error object doesn't replace the reference in
3545L<C<$@>|perlvar/$@> is a global variable and L<C<eval>|/eval EXPR> may
2980the global variable. It's easiest to make a local copy of the reference
3546be used within object implementations, be careful that analyzing the
2981before any manipulations. Here's an example:
3547error object doesn't replace the reference in the global variable. It's
3548easiest to make a local copy of the reference before any manipulations.
3549Here's an example:
29823550
29833551=end original
29843552
2985die() はリファレンス引数と共に呼び出すこともでき、これが
3553L<C<die>|/die LIST> はリファレンス引数と共に呼び出すこともでき、これが
2986eval() 内部でトラップされた場合、C<$@> はそのリファレンスを持ちます。
3554L<C<eval>|/eval EXPR> 内部でトラップされた場合、L<C<$@>|perlvar/$@>
3555そのリファレンスを持ちます。
29873556これは、例外の性質について任意の状態を管理するオブジェクトを使った
29883557より複雑な例外処理の実装を可能にします。
2989このようなスキームは C<$@> の特定の文字列値を正規表現を使って
3558このようなスキームは L<C<$@>|perlvar/$@> の特定の文字列値を正規表現を使って
29903559マッチングするときに時々好まれます。
2991C<$@> はグローバル変数で、C<eval> はオブジェクト実装の内部で
3560L<C<$@>|perlvar/$@> はグローバル変数で、L<C<eval>|/eval EXPR> はオブジェクト
2992使われることがあるので、エラーオブジェクトの解析はグローバル変数の
3561実装の内部で使われることがあるので、エラーオブジェクトの解析はグローバル変数の
29933562リファレンスを置き換えないことに注意を払わなければなりません。
29943563他の操作をする前にリファレンスのローカルコピーを
29953564作るのが一番簡単です。
29963565以下に例を示します:
29973566
29983567 use Scalar::Util "blessed";
29993568
30003569 eval { ... ; die Some::Module::Exception->new( FOO => "bar" ) };
30013570 if (my $ev_err = $@) {
3002 if (blessed($ev_err) && $ev_err->isa("Some::Module::Exception")) {
3571 if (blessed($ev_err)
3572 && $ev_err->isa("Some::Module::Exception")) {
30033573 # handle Some::Module::Exception
30043574 }
30053575 else {
30063576 # handle all other possible exceptions
30073577 }
30083578 }
30093579
30103580=begin original
30113581
30123582Because Perl stringifies uncaught exception messages before display,
30133583you'll probably want to overload stringification operations on
30143584exception objects. See L<overload> for details about that.
30153585
30163586=end original
30173587
30183588perl は捕らえられなかった例外のメッセージを表示する前に文字列化するので、
30193589このようなカスタム例外オブジェクトの文字列化をオーバーロードしたいと
30203590思うかもしれません。
30213591これに関する詳細は L<overload> を参照してください。
30223592
30233593=begin original
30243594
3025You can arrange for a callback to be run just before the C<die>
3595You can arrange for a callback to be run just before the
3026does its deed, by setting the C<$SIG{__DIE__}> hook. The associated
3596L<C<die>|/die LIST> does its deed, by setting the
3027handler is called with the error text and can change the error
3597L<C<$SIG{__DIE__}>|perlvar/%SIG> hook. The associated handler is called
3028message, if it sees fit, by calling C<die> again. See
3598with the error text and can change the error message, if it sees fit, by
3029L<perlvar/%SIG> for details on setting C<%SIG> entries, and
3599calling L<C<die>|/die LIST> again. See L<perlvar/%SIG> for details on
3030L<"eval BLOCK"> for some examples. Although this feature was
3600setting L<C<%SIG>|perlvar/%SIG> entries, and L<C<eval>|/eval EXPR> for some
3031to be run only right before your program was to exit, this is not
3601examples. Although this feature was to be run only right before your
3032currently so: the C<$SIG{__DIE__}> hook is currently called
3602program was to exit, this is not currently so: the
3033even inside eval()ed blocks/strings! If one wants the hook to do
3603L<C<$SIG{__DIE__}>|perlvar/%SIG> hook is currently called even inside
3604L<C<eval>|/eval EXPR>ed blocks/strings! If one wants the hook to do
30343605nothing in such situations, put
30353606
30363607=end original
30373608
3038C<$SIG{__DIE__}> フックをセットすることで、C<die> がその行動を行う
3609L<C<$SIG{__DIE__}>|perlvar/%SIG> フックをセットすることで、
3610L<C<die>|/die LIST> がその行動を行う
30393611直前に実行されるコールバックを設定できます。
30403612結び付けられたハンドラはエラーテキストと共に呼び出され、
3041必要なら再び C<die> を呼び出すことでエラーテキストを変更できアス。
3613必要なら再び L<C<die>|/die LIST> を呼び出すことでエラーテキストを
3042C<%SIG> のエントリをセットる詳細については、L<perlvar/%SIG> を、
3614変更できま
3043例については L<"eval BLOCK"> を参照してくださ
3615L<C<%SIG>|perlvar/%SIG> のエントリセットする詳細につては、
3616L<perlvar/%SIG> を、例については L<C<eval>|/eval EXPR> を参照してください。
30443617この機能はプログラムが終了しようとする前に 1 回だけ実行していましたが、
30453618現在ではそうではありません:
3046C<$SIG{__DIE__}> フックは eval() されたブロック/文字列の中でも
3619L<C<$SIG{__DIE__}>|perlvar/%SIG> フックは L<C<eval>|/eval EXPR> された
3047呼ばれるのです!
3620ブロック/文字列の中でも呼ばれるのです!
30483621もしそのような状況で何もしなくない時は:
30493622
30503623 die @_ if $^S;
30513624
30523625=begin original
30533626
30543627as the first line of the handler (see L<perlvar/$^S>). Because
30553628this promotes strange action at a distance, this counterintuitive
30563629behavior may be fixed in a future release.
30573630
30583631=end original
30593632
30603633をハンドラの最初の行に置いてください(L<perlvar/$^S> を参照してください)。
30613634これは離れたところで不思議な行動を引き起こすので、
30623635この直感的でない振る舞いは将来のリリースで修正されるかもしれません。
30633636
30643637=begin original
30653638
3066See also exit(), warn(), and the Carp module.
3639See also L<C<exit>|/exit EXPR>, L<C<warn>|/warn LIST>, and the L<Carp>
3640module.
30673641
30683642=end original
30693643
3070exit() と warn() と Carp モジュールも参照してください。
3644L<C<exit>|/exit EXPR> L<C<warn>|/warn LIST> L<Carp> モジュールも
3645参照してください。
30713646
30723647=item do BLOCK
30733648X<do> X<block>
30743649
3650=for Pod::Functions turn a BLOCK into a TERM
3651
30753652=begin original
30763653
30773654Not really a function. Returns the value of the last command in the
30783655sequence of commands indicated by BLOCK. When modified by the C<while> or
30793656C<until> loop modifier, executes the BLOCK once before testing the loop
3080condition. (On other statements the loop modifiers test the conditional
3657condition. (On other statements the loop modifiers test the conditional
30813658first.)
30823659
30833660=end original
30843661
30853662実際は関数ではありません。
30863663BLOCK で示されるコマンド列の最後の値を返します。
30873664C<while> や C<until> ループ修飾子で修飾すると、
30883665ループ条件を調べる前に 1 度、BLOCK を実行します。
30893666(これ以外の実行文は、ループ修飾子により、条件が最初に
30903667調べられます。)
30913668
30923669=begin original
30933670
30943671C<do BLOCK> does I<not> count as a loop, so the loop control statements
3095C<next>, C<last>, or C<redo> cannot be used to leave or restart the block.
3672L<C<next>|/next LABEL>, L<C<last>|/last LABEL>, or
3673L<C<redo>|/redo LABEL> cannot be used to leave or restart the block.
30963674See L<perlsyn> for alternative strategies.
30973675
30983676=end original
30993677
3100C<do BLOCK> はループとしては I<扱われません>
3678C<do BLOCK> はループとしては I<扱われません>; 従って、L<C<next>|/next LABEL>,
3101従って、C<next>, C<last>, C<redo> といったループ制御文は
3679L<C<last>|/last LABEL>,L<C<redo>|/redo LABEL> といったループ制御文は
31023680ブロックから抜けたり再開することはできません。
3103その他の戦略については L<perlsyn> を参照してさい。
3681その他の戦略については L<perlsyn> を参照してください。
31043682
3105=item do SUBROUTINE(LIST)
3106X<do>
3107
3108=begin original
3109
3110This form of subroutine call is deprecated. SUBROUTINE can be a bareword,
3111a scalar variable or a subroutine beginning with C<&>.
3112
3113=end original
3114
3115この形のサブルーチン呼び出しは非推奨です。
3116SUBROUTINE には裸の単語、スカラ変数、C<&> で始まるサブルーチンが使えます。
3117
31183683=item do EXPR
31193684X<do>
31203685
31213686=begin original
31223687
31233688Uses the value of EXPR as a filename and executes the contents of the
31243689file as a Perl script.
31253690
31263691=end original
31273692
31283693EXPR の値をファイル名として用い、そのファイルの中身を
31293694Perl のスクリプトとして実行します。
31303695
31313696 do 'stat.pl';
31323697
31333698=begin original
31343699
3135is just like
3700is largely like
31363701
31373702=end original
31383703
3139は以下のものと同じようなものですが、
3704だいたい以下のものと同じようなものですが、
31403705
31413706 eval `cat stat.pl`;
31423707
31433708=begin original
31443709
3145except that it's more efficient and concise, keeps track of the current
3710except that it's more concise, runs no external processes, keeps track of
3146filename for error messages, searches the C<@INC> directories, and updates
3711the current filename for error messages, searches the
3147C<%INC> if the file is found. See L<perlvar/@INC> and L<perlvar/%INC> for
3712L<C<@INC>|perlvar/@INC> directories, and updates L<C<%INC>|perlvar/%INC>
3148these variables. It also differs in that code evaluated with C<do FILENAME>
3713if the file is found. See L<perlvar/@INC> and L<perlvar/%INC> for these
3149cannot see lexicals in the enclosing scope; C<eval STRING> does. It's the
3714variables. It also differs in that code evaluated with C<do FILE>
3150same, however, in that it does reparse the file every time you call it,
3715cannot see lexicals in the enclosing scope; C<eval STRING> does. It's
3151so you probably don't want to do this inside a loop.
3716the same, however, in that it does reparse the file every time you call
3717it, so you probably don't want to do this inside a loop.
31523718
31533719=end original
31543720
3155より効率的で、簡潔であり、エラーメッセージでファイル名がわかる、
3721より簡潔で、外部プログラムを起動せず、エラーメッセージでファイル名がわかる、
31563722カレントディレクトリでファイルが見つからなかったときに
3157C<@INC> ディレクトリを検索する、ファイルがあったときに C<%INC> を更新する、
3723L<C<@INC>|perlvar/@INC> ディレクトリを検索する、ファイルがあったときに
3158といったことがあります。
3724L<C<%INC>|perlvar/%INC> を更新する、といったことがあります。
31593725これらの変数については L<perlvar/@INC> と L<perlvar/%INC> を
31603726参照してください。
3161C<do FILENAME> で評価されたコードは、入れ子のスコープにある
3727C<do FILE> で評価されたコードは、入れ子のスコープにある
31623728レキシカル変数を見ることができないのに対し、C<eval STRING>ではできる、
31633729という違いがあります。
31643730しかし、呼び出すたびにファイルを解析し直すという点では同じですから、
31653731ループ内でこれを使おうなどとは、間違っても思ったりしないように。
31663732
31673733=begin original
31683734
3169If C<do> can read the file but cannot compile it, it returns C<undef> and sets
3735If L<C<do>|/do EXPR> can read the file but cannot compile it, it
3170an error message in C<$@>. If C<do> cannot read the file, it returns undef
3736returns L<C<undef>|/undef EXPR> and sets an error message in
3171and sets C<$!> to the error. Always check C<$@> first, as compilation
3737L<C<$@>|perlvar/$@>. If L<C<do>|/do EXPR> cannot read the file, it
3172could fail in a way that also sets C<$!>. If the file is successfully
3738returns undef and sets L<C<$!>|perlvar/$!> to the error. Always check
3173compiled, C<do> returns the value of the last expression evaluated.
3739L<C<$@>|perlvar/$@> first, as compilation could fail in a way that also
3740sets L<C<$!>|perlvar/$!>. If the file is successfully compiled,
3741L<C<do>|/do EXPR> returns the value of the last expression evaluated.
31743742
31753743=end original
31763744
3177C<do> がファイルを読み込めたがコンパイルできなかった場合、
3745L<C<do>|/do EXPR> がファイルを読み込めたがコンパイルできなかった場合、
3178C<undef> を返して C<$@> にエラーメッセージを設定します。
3746L<C<undef>|/undef EXPR> を返して L<C<$@>|perlvar/$@> にエラーメッセージを
3179C<do>がファイルを読み込めなかった場合、undef を返て C<$!> に
3747設定ます。
3180エラー設定ます。
3748L<C<do>|/do EXPR>がファイル読み込めなかった場合、undef を返
3181コンパイルに失敗したときにも C<$!> が設定されるので、常に C<$@> を
3749L<C<$!>|perlvar/$!> にエラー設定します。
3182チェックます。
3750コンパイル失敗たときにも L<C<$!>|perlvar/$!> が設定されるので、
3183ファイルのコンパイル成功した場合、C<do> は最後に評価した表現の値します。
3751 L<C<$@>|perlvar/$@>先にチェックします。
3752ファイルのコンパイルに成功した場合、L<C<do>|/do EXPR> は最後に評価した表現の
3753値を返します。
31843754
31853755=begin original
31863756
31873757Inclusion of library modules is better done with the
3188C<use> and C<require> operators, which also do automatic error checking
3758L<C<use>|/use Module VERSION LIST> and L<C<require>|/require VERSION>
3189and raise an exception if there's a problem.
3759operators, which also do automatic error checking and raise an exception
3760if there's a problem.
31903761
31913762=end original
31923763
3193ライブラリモジュールのインクルードには、C<use> 演算子や
3764ライブラリモジュールのインクルードには、
3194C<require> 演算子を使った方がよいです。
3765L<C<use>|/use Module VERSION LIST> 演算子
3766L<C<require>|/require VERSION> 演算子を使った方がよいです;
31953767これらは自動的にエラーをチェックして、問題があれば例外を発生させます。
31963768
31973769=begin original
31983770
3199You might like to use C<do> to read in a program configuration
3771You might like to use L<C<do>|/do EXPR> to read in a program
3200file. Manual error checking can be done this way:
3772configuration file. Manual error checking can be done this way:
32013773
32023774=end original
32033775
3204C<do> をプログラム設定ファイルを読み込むのに使いたいかもしれません。
3776L<C<do>|/do EXPR> をプログラム設定ファイルを読み込むのに
3777使いたいかもしれません。
32053778手動のエラーチェックは以下のようにして行えます:
32063779
32073780 # read in config files: system first, then user
32083781 for $file ("/share/prog/defaults.rc",
32093782 "$ENV{HOME}/.someprogrc")
32103783 {
32113784 unless ($return = do $file) {
32123785 warn "couldn't parse $file: $@" if $@;
32133786 warn "couldn't do $file: $!" unless defined $return;
32143787 warn "couldn't run $file" unless $return;
32153788 }
32163789 }
32173790
32183791=item dump LABEL
32193792X<dump> X<core> X<undump>
32203793
3794=item dump EXPR
3795
32213796=item dump
32223797
3798=for Pod::Functions create an immediate core dump
3799
32233800=begin original
32243801
32253802This function causes an immediate core dump. See also the B<-u>
32263803command-line switch in L<perlrun>, which does the same thing.
32273804Primarily this is so that you can use the B<undump> program (not
32283805supplied) to turn your core dump into an executable binary after
32293806having initialized all your variables at the beginning of the
32303807program. When the new binary is executed it will begin by executing
3231a C<goto LABEL> (with all the restrictions that C<goto> suffers).
3808a C<goto LABEL> (with all the restrictions that L<C<goto>|/goto LABEL>
3809suffers).
32323810Think of it as a goto with an intervening core dump and reincarnation.
3233If C<LABEL> is omitted, restarts the program from the top.
3811If C<LABEL> is omitted, restarts the program from the top. The
3812C<dump EXPR> form, available starting in Perl 5.18.0, allows a name to be
3813computed at run time, being otherwise identical to C<dump LABEL>.
32343814
32353815=end original
32363816
32373817この関数は即座にコアダンプを行ないます。
32383818同様のことを行う L<perlrun> の B<-u> オプションも参照してください。
32393819プログラムの先頭で、
32403820すべての変数を初期化したあとのコアダンプを B<undump>
32413821プログラム(提供していません)を使って実行ファイルに返ることができます。
32423822この新しいバイナリが実行されると、C<goto LABEL> から始めます
3243(C<goto> に関する制限はすべて適用されます)。
3823(L<C<goto>|/goto LABEL> に関する制限はすべて適用されます)。
32443824コアダンプをはさんで再生する goto と考えてください。
32453825C<LABEL> が省略されると、プログラムを先頭から再開します。
3826Perl 5.18.0 から利用可能な C<dump EXPR> 形式では、実行時に計算される
3827名前が使えます; その他は C<dump LABEL> と同一です。
32463828
32473829=begin original
32483830
32493831B<WARNING>: Any files opened at the time of the dump will I<not>
32503832be open any more when the program is reincarnated, with possible
32513833resulting confusion by Perl.
32523834
32533835=end original
32543836
3255B<警告>: dump 時点でオープンされていたファイルは、
3837B<警告>: dump 時点でオープンされていたファイルは、プログラムが
3256プログラムが再生されたときには、もはやオープンされていません
3838再生されたときには、もはやオープンされて I<いません>; Perl を
3257Perl を混乱させる可能性があります。
3839混乱させる可能性があります。
32583840
32593841=begin original
32603842
32613843This function is now largely obsolete, mostly because it's very hard to
3262convert a core file into an executable. That's why you should now invoke
3844convert a core file into an executable. That's why you should now invoke
3263it as C<CORE::dump()>, if you don't want to be warned against a possible
3845it as C<CORE::dump()> if you don't want to be warned against a possible
32643846typo.
32653847
32663848=end original
32673849
32683850この関数は大幅に時代遅れのものです; 主な理由としては、コアファイルを
32693851実行形式に変換するのが非常に困難であることです。
32703852これが、今ではタイプミスの可能性を警告されたくないなら
3271C<CORE::dump()> として起動するべき理由です。
3853C<CORE::dump> として起動するべき理由です。
32723854
3855=begin original
3856
3857Unlike most named operators, this has the same precedence as assignment.
3858It is also exempt from the looks-like-a-function rule, so
3859C<dump ("foo")."bar"> will cause "bar" to be part of the argument to
3860L<C<dump>|/dump LABEL>.
3861
3862=end original
3863
3864ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
3865また、関数のように見えるものの規則からも免れるので、C<dump ("foo")."bar"> と
3866すると "bar" は L<C<dump>|/dump LABEL> への引数の一部になります。
3867
3868=begin original
3869
3870Portability issues: L<perlport/dump>.
3871
3872=end original
3873
3874移植性の問題: L<perlport/dump>。
3875
32733876=item each HASH
32743877X<each> X<hash, iterator>
32753878
32763879=item each ARRAY
32773880X<array, iterator>
32783881
3279=item each EXPR
3882=for Pod::Functions retrieve the next key/value pair from a hash
32803883
32813884=begin original
32823885
3283When called in list context, returns a 2-element list consisting of the key
3886When called on a hash in list context, returns a 2-element list
3284and value for the next element of a hash, or the index and value for the
3887consisting of the key and value for the next element of a hash. In Perl
3285next element of an array, so that you can iterate over it. When called in
38885.12 and later only, it will also return the index and value for the next
3286scalar context, returns only the key (not the value) in a hash, or the index
3889element of an array so that you can iterate over it; older Perls consider
3287in an array.
3890this a syntax error. When called in scalar context, returns only the key
3891(not the value) in a hash, or the index in an array.
32883892
32893893=end original
32903894
3291リストコンテキストで呼び出した場合は、次の要素に対する、
3895ハッシュに対してリストコンテキストで呼び出した場合は、次の要素に対する、
3292ハッシュのキーと値か、配列のインデックスと値からなる
3896ハッシュのキーと値を返します。
32932 要素のリストを返すので、反復を行えます。
3897Perl 5.12 以降のみ配列のインデックスと値からなる
38982 要素のリストを返すので、反復を行えます; より古い Perl ではこれは
3899文法エラーと考えられます。
32943900スカラコンテキストで呼び出した場合は、
32953901ハッシュの場合は(値ではなく)キー、配列の場合はインデックスを返します。
32963902
32973903=begin original
32983904
32993905Hash entries are returned in an apparently random order. The actual random
3300order is subject to change in future versions of Perl, but it is
3906order is specific to a given hash; the exact same series of operations
3301guaranteed to be in the same order as either the C<keys> or C<values>
3907on two hashes may result in a different order for each hash. Any insertion
3302function would produce on the same (unmodified) hash. Since Perl
3908into the hash may change the order, as will any deletion, with the exception
33035.8.2 the ordering can be different even between different runs of Perl
3909that the most recent key returned by L<C<each>|/each HASH> or
3304for security reasons (see L<perlsec/"Algorithmic Complexity Attacks">).
3910L<C<keys>|/keys HASH> may be deleted without changing the order. So
3911long as a given hash is unmodified you may rely on
3912L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and
3913L<C<each>|/each HASH> to repeatedly return the same order
3914as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
3915details on why hash order is randomized. Aside from the guarantees
3916provided here the exact details of Perl's hash algorithm and the hash
3917traversal order are subject to change in any release of Perl.
33053918
33063919=end original
33073920
3308ハッシュエントリは見かけ上、ランダムな順序で返されます。
3921ハッシュ要素は見かけ上、ランダムな順序で返されます。
3309実際のランダムな順perl 将来バージョンでは変わるかもしれませんが、
3922実際のランダムな順ハッシュに固有です; 二つハッシュに全く同じ一連
3310C<keys> や C<values> 関数が同じ(変更されいない)ハッシュに対し
3923操作を行っも、ハッシュによっ異なった順序になります。
3311生成すると同じ番であることは保証されます
3924ハッシュへ挿入によって序が変わることがあります; 削除も同様ですが、
3312Perl 5.8.2 以降でセキュリティ上の理由により、
3925L<C<each>|/each HASH> また L<C<keys>|/keys HASH> によって返されたもっとも
3313実行される毎に順番は変かもしれせん
3926最近のキー順序をことなく削除できす。
3314(L<perlsec/"Algorithmic Complexity Attacks"> を参照してください)。
3927ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>,
3928L<C<each>|/each HASH> が繰り返し同じ順序で
3929返すことに依存してもかまいません。
3930なぜハッシュの順序がランダム化されているかの詳細については
3931L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。
3932ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の
3933正確な詳細は Perl のリリースによって変更される可能性があります。
33153934
33163935=begin original
33173936
3318After C<each> has returned all entries from the hash or array, the next
3937After L<C<each>|/each HASH> has returned all entries from the hash or
3319call to C<each> returns the empty list in list context and C<undef> in
3938array, the next call to L<C<each>|/each HASH> returns the empty list in
3320scalar context. The next call following that one restarts iteration. Each
3939list context and L<C<undef>|/undef EXPR> in scalar context; the next
3321hash or array has its own internal iterator, accessed by C<each>, C<keys>,
3940call following I<that> one restarts iteration. Each hash or array has
3322and C<values>. The iterator is implicitly reset when C<each> has reached
3941its own internal iterator, accessed by L<C<each>|/each HASH>,
3323the end as just described; it can be explicitly reset by calling C<keys> or
3942L<C<keys>|/keys HASH>, and L<C<values>|/values HASH>. The iterator is
3324C<values> on the hash or array. If you add or delete a hash's elements
3943implicitly reset when L<C<each>|/each HASH> has reached the end as just
3325while iterating over it, entries may be skipped or duplicated--so don't do
3944described; it can be explicitly reset by calling L<C<keys>|/keys HASH>
3326that. Exception: It is always safe to delete the item most recently
3945or L<C<values>|/values HASH> on the hash or array. If you add or delete
3327returned by C<each()>, so the following code works properly:
3946a hash's elements while iterating over it, the effect on the iterator is
3947unspecified; for example, entries may be skipped or duplicated--so don't
3948do that. Exception: It is always safe to delete the item most recently
3949returned by L<C<each>|/each HASH>, so the following code works properly:
33283950
33293951=end original
33303952
3331C<each> がハッシュをすべて読み込んでしまった後、リストコンテキストでは
3953L<C<each>|/each HASH> がハッシュをすべて読み込んでしまった後、
3332リストが返され、スカラコンテキストでは C<undef> 返されます。
3954次の L<C<each>|/each HASH> 呼び出しでは、リストコンテキストでは空リスト
3333そのあともう一度呼び出すと再び反復を始めます
3955返されスカラコンテキストでは L<C<undef>|/undef EXPR> が返されます;
3334ハッシュや配列毎にれぞれ反復子がり、C<each>、C<keys>、C<values>
3956I<> もう一度呼び出すと、再び反復を始めます。
3335アクセスさます。
3957ハッシュや配列毎にそぞれ反復子があり、L<C<each>|/each HASH>、
3336反復子は、前述したように C<each> が要素をべて読むことによって
3958L<C<keys>|/keys HASH>、L<C<values>|/values HASH> でアクセスされま
3337暗黙リセットされます; また、ハッシュや配列対し
3959反復子は、前述したようL<C<each>|/each HASH> が要素をすべて読むことよっ
3338C<keys HASH>, C<values HASH> を呼び出すことで明示的にリセットできます。
3960暗黙にリセットされます; また、ハッシュや配列に対して L<C<keys>|/keys HASH>,
3961L<C<values>|/values HASH> を呼び出すことで明示的にリセットできます。
33393962繰り返しを行なっている間に、ハッシュに要素を追加したり削除したりすると、
3340要素が飛ばされたり重複したりするので、てはいけせん。
3963反復子の動作は未定義です; 例えば、要素が飛ばされたり重複したりします--
3341例外: 一番最近に C<each()> から返されたものを削除するの常に安全です
3964従って、していけません
3342は以下ようなコードが正しく動くこと意味しま:
3965例外: 一番最近に L<C<each>|/each HASH> から返さたものを削除るのは常に
3966安全です; これは以下のようなコードが正しく動くことを意味します:
33433967
3344 while (($key, $value) = each %hash) {
3968 while (my ($key, $value) = each %hash) {
3345 print $key, "\n";
3969 print $key, "\n";
3346 delete $hash{$key}; # This is safe
3970 delete $hash{$key}; # This is safe
3347 }
3971 }
33483972
33493973=begin original
33503974
3351This prints out your environment like the printenv(1) program,
3975Tied hashes may have a different ordering behaviour to perl's hash
3976implementation.
3977
3978=end original
3979
3980tie されたハッシュは、順序に関して Perl のハッシュと異なった振る舞いをします。
3981
3982=begin original
3983
3984This prints out your environment like the L<printenv(1)> program,
33523985but in a different order:
33533986
33543987=end original
33553988
3356これは、printenv(1) プログラムのように環境変数を表示しますが、
3989これは、L<printenv(1)> プログラムのように環境変数を表示しますが、
33573990順序は異なっています:
33583991
3359 while (($key,$value) = each %ENV) {
3992 while (my ($key,$value) = each %ENV) {
33603993 print "$key=$value\n";
33613994 }
33623995
33633996=begin original
33643997
3365Starting with Perl 5.14, C<each> can take a scalar EXPR, which must hold
3998Starting with Perl 5.14, an experimental feature allowed
3366reference to an unblessed hash or array. The argument will be dereferenced
3999L<C<each>|/each HASH> to take a scalar expression. This experiment has
3367automatically. This aspect of C<each> is considered highly experimental.
4000been deemed unsuccessful, and was removed as of Perl 5.24.
3368The exact behaviour may change in a future version of Perl.
33694001
33704002=end original
33714003
3372Perl 5.14 から、C<each> スカラの EXPR を取ることができになりました;
4004Perl 5.14 から、L<C<each>|/each HASH> がスカラを取ることが出来とい
3373これは bless されていないハッシュや配列へのリファレンスでなければなりません
4005実験的機能がありました
3374引数自動的にデリファレンスされま
4006この実験失敗と見なされ、Perl 5.24 で削除されした
3375C<each> のこの動作は高度に実験的であると考えられています。
3376正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
33774007
3378 while (($key,$value) = each $hashref) { ... }
4008=begin original
33794009
4010As of Perl 5.18 you can use a bare L<C<each>|/each HASH> in a C<while>
4011loop, which will set L<C<$_>|perlvar/$_> on every iteration.
4012
4013=end original
4014
4015Perl 5.18 から C<while> ループの中に裸の L<C<each>|/each HASH> を書けます;
4016これは繰り返し毎に L<C<$_>|perlvar/$_> を設定します。
4017
4018 while (each %ENV) {
4019 print "$_=$ENV{$_}\n";
4020 }
4021
33804022=begin original
33814023
3382See also C<keys>, C<values>, and C<sort>.
4024To avoid confusing would-be users of your code who are running earlier
4025versions of Perl with mysterious syntax errors, put this sort of thing at
4026the top of your file to signal that your code will work I<only> on Perls of
4027a recent vintage:
33834028
33844029=end original
33854030
3386C<keys> や C<values> や C<sort> も参照てください。
4031あなたのコードを以前のバージョンの Perl で実行たユーザーが不思議な
4032文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
4033I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
4034書いてください:
33874035
4036 use 5.012; # so keys/values/each work on arrays
4037 use 5.018; # so each assigns to $_ in a lone while test
4038
4039=begin original
4040
4041See also L<C<keys>|/keys HASH>, L<C<values>|/values HASH>, and
4042L<C<sort>|/sort SUBNAME LIST>.
4043
4044=end original
4045
4046L<C<keys>|/keys HASH> や L<C<values>|/values HASH> や
4047L<C<sort>|/sort SUBNAME LIST> も参照してください。
4048
33884049=item eof FILEHANDLE
33894050X<eof>
33904051X<end of file>
33914052X<end-of-file>
33924053
33934054=item eof ()
33944055
33954056=item eof
33964057
4058=for Pod::Functions test a filehandle for its end
4059
33974060=begin original
33984061
33994062Returns 1 if the next read on FILEHANDLE will return end of file I<or> if
34004063FILEHANDLE is not open. FILEHANDLE may be an expression whose value
34014064gives the real filehandle. (Note that this function actually
34024065reads a character and then C<ungetc>s it, so isn't useful in an
34034066interactive context.) Do not read from a terminal file (or call
34044067C<eof(FILEHANDLE)> on it) after end-of-file is reached. File types such
34054068as terminals may lose the end-of-file condition if you do.
34064069
34074070=end original
34084071
34094072次に FILEHANDLE 上で読み込みを行なったときに、EOF が返されるときか、
34104073I<または> FILEHANDLE がオープンされていないと、1 を返します。
34114074FILEHANDLE は、値が実際のファイルハンドルを示す式であってもかまいません。
34124075(この関数は、実際に文字を読み、C<ungetc> を行ないますので、
34134076対話型の場合には有用ではありません。)
34144077端末ファイルは EOF に達した後にさらに読み込んだり C<eof(FILEHANDLE)> を
34154078呼び出したりしてはいけません。
34164079そのようなことをすると、端末のようなファイルタイプは
34174080EOF 状態を失ってしまうかもしれません。
34184081
34194082=begin original
34204083
3421An C<eof> without an argument uses the last file read. Using C<eof()>
4084An L<C<eof>|/eof FILEHANDLE> without an argument uses the last file
3422with empty parentheses is different. It refers to the pseudo file
4085read. Using L<C<eof()>|/eof FILEHANDLE> with empty parentheses is
3423formed from the files listed on the command line and accessed via the
4086different. It refers to the pseudo file formed from the files listed on
3424C<< <> >> operator. Since C<< <> >> isn't explicitly opened,
4087the command line and accessed via the C<< <> >> operator. Since
3425as a normal filehandle is, an C<eof()> before C<< <> >> has been
4088C<< <> >> isn't explicitly opened, as a normal filehandle is, an
3426used will cause C<@ARGV> to be examined to determine if input is
4089L<C<eof()>|/eof FILEHANDLE> before C<< <> >> has been used will cause
3427available. Similarly, an C<eof()> after C<< <> >> has returned
4090L<C<@ARGV>|perlvar/@ARGV> to be examined to determine if input is
3428end-of-file will assume you are processing another C<@ARGV> list,
4091available. Similarly, an L<C<eof()>|/eof FILEHANDLE> after C<< <> >>
3429and if you haven't set C<@ARGV>, will read input from C<STDIN>;
4092has returned end-of-file will assume you are processing another
3430see L<perlop/"I/O Operators">.
4093L<C<@ARGV>|perlvar/@ARGV> list, and if you haven't set
4094L<C<@ARGV>|perlvar/@ARGV>, will read input from C<STDIN>; see
4095L<perlop/"I/O Operators">.
34314096
34324097=end original
34334098
3434引数を省略した C<eof> は、最後に読み込みを行なったファイルを使います。
4099引数を省略した L<C<eof>|/eof FILEHANDLE> は、最後に読み込みを行なった
3435空の括弧つけた C<eof()> は異なります。
4100ファイル使います。
4101空の括弧をつけた L<C<eof()>|/eof FILEHANDLE> は異なります。
34364102これはコマンドラインのファイルリストで構成され、C<< <> >> 演算子経由で
34374103アクセスされる擬似ファイルを示すために用いられます。
34384104通常のファイルハンドルと違って C<< <> >> は明示的にオープンされないので、
3439C<< <> >> を使う前に C<eof()> を使うと、
4105C<< <> >> を使う前に L<C<eof()>|/eof FILEHANDLE> を使うと、
3440入力が正常か確認するために C<@ARGV> がテストされます。
4106入力が正常か確認するために L<C<@ARGV>|perlvar/@ARGV> がテストされます。
3441同様に、C<< <> >> が EOF を返した後の C<eof()> は、
4107同様に、C<< <> >> が EOF を返した後の L<C<eof()>|/eof FILEHANDLE> は、
3442他の C<@ARGV> リストを処理していると仮定し、もし C<@ARGV> を
4108他の L<C<@ARGV>|perlvar/@ARGV> リストを処理していると仮定し、もし
3443セットしていないときは C<STDIN> から読み込みます;
4109L<C<@ARGV>|perlvar/@ARGV> をセットしていないときは C<STDIN> から読み込みます;
34444110L<perlop/"I/O Operators"> を参照してください。
34454111
34464112=begin original
34474113
3448In a C<< while (<>) >> loop, C<eof> or C<eof(ARGV)> can be used to
4114In a C<< while (<>) >> loop, L<C<eof>|/eof FILEHANDLE> or C<eof(ARGV)>
3449detect the end of each file, whereas C<eof()> will detect the end
4115can be used to detect the end of each file, whereas
3450of the very last file only. Examples:
4116L<C<eof()>|/eof FILEHANDLE> will detect the end of the very last file
4117only. Examples:
34514118
34524119=end original
34534120
34544121C<< while (<>) >> ループの中では、個々のファイルの終わりを調べるには、
3455C<eof> か C<eof(ARGV)> を用いるのに対して
4122L<C<eof>|/eof FILEHANDLE> か C<eof(ARGV)> を用いるのに対して
3456C<eof()> は最後のファイルの終わりのみを調べます。
4123L<C<eof()>|/eof FILEHANDLE> は最後のファイルの終わりのみを調べます。
34574124例:
34584125
34594126 # reset line numbering on each input file
34604127 while (<>) {
34614128 next if /^\s*#/; # skip comments
34624129 print "$.\t$_";
34634130 } continue {
34644131 close ARGV if eof; # Not eof()!
34654132 }
34664133
34674134 # insert dashes just before last line of last file
34684135 while (<>) {
34694136 if (eof()) { # check for end of last file
34704137 print "--------------\n";
34714138 }
34724139 print;
3473 last if eof(); # needed if we're reading from a terminal
4140 last if eof(); # needed if we're reading from a terminal
34744141 }
34754142
34764143=begin original
34774144
3478Practical hint: you almost never need to use C<eof> in Perl, because the
4145Practical hint: you almost never need to use L<C<eof>|/eof FILEHANDLE>
3479input operators typically return C<undef> when they run out of data or
4146in Perl, because the input operators typically return L<C<undef>|/undef
3480encounter an error.
4147EXPR> when they run out of data or encounter an error.
34814148
34824149=end original
34834150
3484現実的なヒント: Perl で C<eof> が必要となることは、ほとんどありません;
4151現実的なヒント: Perl で L<C<eof>|/eof FILEHANDLE> が必要となることは、
4152ほとんどありません;
34854153基本的には、データがなくなったときやエラーがあったときに、入力演算子が
3486C<undef> を返してくれるからです。
4154L<C<undef>|/undef EXPR> を返してくれるからです。
34874155
34884156=item eval EXPR
34894157X<eval> X<try> X<catch> X<evaluate> X<parse> X<execute>
34904158X<error, handling> X<exception, handling>
34914159
34924160=item eval BLOCK
34934161
34944162=item eval
34954163
4164=for Pod::Functions catch exceptions or compile and run code
4165
34964166=begin original
34974167
3498In the first form, the return value of EXPR is parsed and executed as if it
4168In the first form, often referred to as a "string eval", the return
4169value of EXPR is parsed and executed as if it
34994170were a little Perl program. The value of the expression (which is itself
35004171determined within scalar context) is first parsed, and if there were no
3501errors, executed in the lexical context of the current Perl program, so
4172errors, executed as a block within the lexical context of the current Perl
3502that any variable settings or subroutine and format definitions remain
4173program. This means, that in particular, any outer lexical variables are
3503afterwards. Note that the value is parsed every time the C<eval> executes.
4174visible to it, and any package variable settings or subroutine and format
3504If EXPR is omitted, evaluates C<$_>. This form is typically used to
4175definitions remain afterwards.
3505delay parsing and subsequent execution of the text of EXPR until run time.
35064176
35074177=end original
35084178
3509第一の形式では、EXPR の返り値が Perl のプログラムであるかのように
4179第一の形式(しばしば「文字列 eval」として参照されます)では、EXPR の返り値が
3510解析され、実行されます。
4180Perl のプログラムであるかのように解析され、実行されます。
35114181式の値(それ自身スカラコンテキストの中で決定されます)はまずパースされ、
3512エラーがなければ
4182エラーがなければ Perl プログラムのレキシカルコンテキストの中のブロックとして
3513Perl プログラムのレキシカルコンテキストの中で実行されますので、変数の設定、
4183実行されます
3514サブルーチンやフォーマットの定義は、後も残っています。 
4184これは、特に、外側レキシカル変数は見えていて、パッケージ変数の設定や
3515返される値 C<eval> が実行されにパースされることに注意してください
4185サブルーチンやフォーマットの定義その後も残っているということです
3516EXPR を省略すると、C<$_> を評価します。
4187=begin original
4188
4189Note that the value is parsed every time the L<C<eval>|/eval EXPR>
4190executes. If EXPR is omitted, evaluates L<C<$_>|perlvar/$_>. This form
4191is typically used to delay parsing and subsequent execution of the text
4192of EXPR until run time.
4193
4194=end original
4195
4196返される値は L<C<eval>|/eval EXPR> が実行されるごとにパースされることに
4197注意してください。
4198EXPR が省略されると、L<C<$_>|perlvar/$_> を評価します。
35174199この形は主に EXPR のテキストのパースと実行を実行時にまで
35184200遅延させるのに用います。
35194201
35204202=begin original
35214203
4204If the
4205L<C<"unicode_eval"> feature|feature/The 'unicode_eval' and 'evalbytes' features>
4206is enabled (which is the default under a
4207C<use 5.16> or higher declaration), EXPR or L<C<$_>|perlvar/$_> is
4208treated as a string of characters, so L<C<use utf8>|utf8> declarations
4209have no effect, and source filters are forbidden. In the absence of the
4210L<C<"unicode_eval"> feature|feature/The 'unicode_eval' and 'evalbytes' features>,
4211will sometimes be treated as characters and sometimes as bytes,
4212depending on the internal encoding, and source filters activated within
4213the L<C<eval>|/eval EXPR> exhibit the erratic, but historical, behaviour
4214of affecting some outer file scope that is still compiling. See also
4215the L<C<evalbytes>|/evalbytes EXPR> operator, which always treats its
4216input as a byte stream and works properly with source filters, and the
4217L<feature> pragma.
4218
4219=end original
4220
4221L<C<"unicode_eval"> 機能|feature/The 'unicode_eval' and 'evalbytes' features>
4222が有効の場合(これは C<use 5.16> またはそれ以上が
4223宣言されている場合はデフォルトです)、EXPR や L<C<$_>|perlvar/$_> は文字単位の
4224文字列として扱われるので、L<C<use utf8>|utf8> 宣言は無効で、ソースフィルタは
4225禁止されます。
4226L<C<"unicode_eval"> 機能|feature/The 'unicode_eval' and 'evalbytes' features>
4227がなければ、内部エンコーディングに依存して
4228時々文字単位として扱われ、時々バイト単位で扱われます; そして
4229L<C<eval>|/eval EXPR> の中で有効になったソースフィルタは、まだ
4230コンパイル中である一部の外側のファイルスコープに影響を与えるという、
4231間違っているけれども歴史的な振る舞いを見せます。
4232入力を常にバイト列として扱い、ソースフィルタが適切に動作する
4233L<C<evalbytes>|/evalbytes EXPR> 演算子および L<feature> プラグマを
4234参照してください。
4235
4236=begin original
4237
4238Problems can arise if the string expands a scalar containing a floating
4239point number. That scalar can expand to letters, such as C<"NaN"> or
4240C<"Infinity">; or, within the scope of a L<C<use locale>|locale>, the
4241decimal point character may be something other than a dot (such as a
4242comma). None of these are likely to parse as you are likely expecting.
4243
4244=end original
4245
4246文字列をが小数点を含むスカラを展開するときに問題が起こることがあります。
4247そのようなスカラは C<"NaN"> や C<"Infinity"> のような文字に
4248展開されることがあります; または、L<C<use locale>|locale> のスコープの中では、
4249小数点文字は (カンマのような) ドット以外の文字かもしれません。
4250これらはどれもあなたがおそらく予測しているようにはパースされません。
4251
4252=begin original
4253
35224254In the second form, the code within the BLOCK is parsed only once--at the
3523same time the code surrounding the C<eval> itself was parsed--and executed
4255same time the code surrounding the L<C<eval>|/eval EXPR> itself was
4256parsed--and executed
35244257within the context of the current Perl program. This form is typically
35254258used to trap exceptions more efficiently than the first (see below), while
35264259also providing the benefit of checking the code within BLOCK at compile
35274260time.
35284261
35294262=end original
35304263
35314264第二の形式では、BLOCK 内部のコードは一度だけパースされ -- コードを
3532囲む C<eval> 自身がパースされるのと同じ時点です -- 現在の Perl プログラム
4265囲む L<C<eval>|/eval EXPR> 自身がパースされるのと同じ時点です -- 現在の
3533コンテキストで実行されます。
4266Perl プログラムのコンテキストで実行されます。
3534この形式は典型的には第一の形式より効率的に例外をトラップします(後述)
4267この形式は典型的には第一の形式より効率的に例外をトラップします(後述);
35354268また BLOCK 内部のコードはコンパイル時にチェックされるという利点を提供します。
35364269
35374270=begin original
35384271
35394272The final semicolon, if any, may be omitted from the value of EXPR or within
35404273the BLOCK.
35414274
35424275=end original
35434276
3544最後のセミコロンは、もしあれば、EXPR の値や BLOCK の中身から省くことができます。
4277最後のセミコロンは、もしあれば、EXPR の値や BLOCK の中身から
4278省くことができます。
35454279
35464280=begin original
35474281
35484282In both forms, the value returned is the value of the last expression
35494283evaluated inside the mini-program; a return statement may be also used, just
35504284as with subroutines. The expression providing the return value is evaluated
3551in void, scalar, or list context, depending on the context of the C<eval>
4285in void, scalar, or list context, depending on the context of the
3552itself. See L</wantarray> for more on how the evaluation context can be
4286L<C<eval>|/eval EXPR> itself. See L<C<wantarray>|/wantarray> for more
3553determined.
4287on how the evaluation context can be determined.
35544288
35554289=end original
35564290
35574291どちらの形式でも、返される値はミニプログラムの内部で最後に評価された
35584292表現の値です; サブルーチンと同様、return 文も使えます。
3559返り値として提供される表現は、C<eval> 自身のコンテキストに依存して
4293返り値として提供される表現は、L<C<eval>|/eval EXPR> 自身のコンテキストに
3560無効・スカラ・リストのいずれかのコンテキストで評価されます。
4294依存して無効・スカラ・リストのいずれかのコンテキストで評価されます。
3561評価コンテキストの決定方法についての詳細は L</wantarray> を参照してください。
4295評価コンテキストの決定方法についての詳細は L<C<wantarray>|/wantarray> を
4296参照してください。
35624297
35634298=begin original
35644299
3565If there is a syntax error or runtime error, or a C<die> statement is
4300If there is a syntax error or runtime error, or a L<C<die>|/die LIST>
3566executed, C<eval> returns C<undef> in scalar context
4301statement is executed, L<C<eval>|/eval EXPR> returns
3567or an empty list--or, for syntax errors, a list containing a single
4302L<C<undef>|/undef EXPR> in scalar context or an empty list in list
3568undefined value--in list context, and C<$@> is set to the error
4303context, and L<C<$@>|perlvar/$@> is set to the error message. (Prior to
3569message. The discrepancy in the return values in list context is
43045.16, a bug caused L<C<undef>|/undef EXPR> to be returned in list
3570considered a bug by some, and will probably be fixed in a future
4305context for syntax errors, but not for runtime errors.) If there was no
3571release. If there was no error, C<$@> is guaranteed to be the empty
4306error, L<C<$@>|perlvar/$@> is set to the empty string. A control flow
3572string. Beware that using C<eval> neither silences Perl from printing
4307operator like L<C<last>|/last LABEL> or L<C<goto>|/goto LABEL> can
3573warnings to STDERR, nor does it stuff the text of warning messages into C<$@>.
4308bypass the setting of L<C<$@>|perlvar/$@>. Beware that using
3574To do either of those, you have to use the C<$SIG{__WARN__}> facility, or
4309L<C<eval>|/eval EXPR> neither silences Perl from printing warnings to
3575turn off warnings inside the BLOCK or EXPR using S<C<no warnings 'all'>>.
4310STDERR, nor does it stuff the text of warning messages into
3576See L</warn>, L<perlvar>, L<warnings> and L<perllexwarn>.
4311L<C<$@>|perlvar/$@>. To do either of those, you have to use the
4312L<C<$SIG{__WARN__}>|perlvar/%SIG> facility, or turn off warnings inside
4313the BLOCK or EXPR using S<C<no warnings 'all'>>. See
4314L<C<warn>|/warn LIST>, L<perlvar>, and L<warnings>.
35774315
35784316=end original
35794317
3580構文エラーや実行エラーが発生するか、C<die> 文が実行されると、
4318構文エラーや実行エラーが発生するか、L<C<die>|/die LIST> 文が実行されると、
3581C<eval> はスカラコンテキストでは C<undef> が、リストコンテキストでは
4319L<C<eval>|/eval EXPR> はスカラコンテキストでは L<C<undef>|/undef EXPR> が、
3582リスト -- あるいは、文法エラーのときには、単一のエラーメッセージからなる
4320リストコンテキストで空リストが設定され
3583リストが設定されます。
4321L<C<$@>|perlvar/$@> にエラーメッセージが設定されます。
3584リストコンテキストでの返り値の違いある意味バグと考えられていて、
4322(5.16 以前では、バグによって、リストコンテキストで構文エラー時に
3585おそらく将来のリリースで修正されす。
4323L<C<undef>|/undef EXPR> を返していしたが、実行エラーの時には
3586エラーがなければ、C<$@> は空文字列であることが保証され 
4324返していせんでした)
3587C<eval> を、STDERR 警告メッセージを表示せない目的や、
4325エラーがなければ、L<C<$@>|perlvar/$@> は空文字列設定れます。
3588警告メッセージを C<$@> に格納する目的では使わいでください。
4326L<C<last>|/last LABEL> や L<C<goto>|/goto LABEL> のようフロー制御演算子は
3589そのような用途では、C<$SIG{__WARN__}> 機能使うか、
4327L<C<$@>|perlvar/$@> の設定回避できます。
4328L<C<eval>|/eval EXPR> を、STDERR に警告メッセージを表示させない目的や、
4329警告メッセージを L<C<$@>|perlvar/$@> に格納する目的では使わないでください。
4330そのような用途では、L<C<$SIG{__WARN__}>|perlvar/%SIG> 機能を使うか、
35904331S<C<no warnings 'all'>> を使って BLOCK か EXPR の内部での警告を
35914332オフにする必要があります。
3592L</warn>, L<perlvar>, L<warnings>, L<perllexwarn> を参照してください。
4333L<C<warn>|/warn LIST>, L<perlvar>, L<warnings> を参照してください。
35934334
35944335=begin original
35954336
3596Note that, because C<eval> traps otherwise-fatal errors, it is useful for
4337Note that, because L<C<eval>|/eval EXPR> traps otherwise-fatal errors,
3597determining whether a particular feature (such as C<socket> or C<symlink>)
4338it is useful for determining whether a particular feature (such as
3598is implemented. It is also Perl's exception-trapping mechanism, where
4339L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL> or
3599the die operator is used to raise exceptions.
4340L<C<symlink>|/symlink OLDFILE,NEWFILE>) is implemented. It is also
4341Perl's exception-trapping mechanism, where the L<C<die>|/die LIST>
4342operator is used to raise exceptions.
36004343
36014344=end original
36024345
3603C<eval> は、致命的エラーとなるようなものをトラップすることができるので、
4346L<C<eval>|/eval EXPR> は、致命的エラーとなるようなものを
3604(C<socket> や C<symlink> いった) 特定の機能実装されていかを
4347トラップすることができので
4348(L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL> や
4349L<C<symlink>|/symlink OLDFILE,NEWFILE> といった) 特定の機能が
4350実装されているかを、
36054351調べるために使うことができることに注意してください。
3606die 演算子が例外を発生させるものとすれば、これはまた、Perl の例外捕捉機能と
4352L<C<die>|/die LIST> 演算子が例外を発生させるものとすれば、これはまた、
3607捉えることもできます。
4353Perl の例外捕捉機能と捉えることもできます。
36084354
36094355=begin original
36104356
36114357If you want to trap errors when loading an XS module, some problems with
36124358the binary interface (such as Perl version skew) may be fatal even with
3613C<eval> unless C<$ENV{PERL_DL_NONLAZY}> is set. See L<perlrun>.
4359L<C<eval>|/eval EXPR> unless C<$ENV{PERL_DL_NONLAZY}> is set. See
4360L<perlrun>.
36144361
36154362=end original
36164363
36174364XS モジュールのロード中のエラーをトラップしたいなら、
36184365(Perl バージョンの違いのような) バイナリインターフェースに関する問題に
3619ついては C<$ENV{PERL_DL_NONLAZY}> がセットされていない C<eval> でも
4366ついては C<$ENV{PERL_DL_NONLAZY}> がセットされていない
3620致命的エラーになるかもしれません。
4367L<C<eval>|/eval EXPR> でも致命的エラーになるかもしれません。
36214368L<perlrun> を参照してください。
36224369
36234370=begin original
36244371
36254372If the code to be executed doesn't vary, you may use the eval-BLOCK
36264373form to trap run-time errors without incurring the penalty of
3627recompiling each time. The error, if any, is still returned in C<$@>.
4374recompiling each time. The error, if any, is still returned in
4375L<C<$@>|perlvar/$@>.
36284376Examples:
36294377
36304378=end original
36314379
36324380実行するコードが変わらないのであれば、毎回多量の再コンパイルすることなしに、
36334381実行時エラーのトラップを行なうために、
36344382eval-BLOCK 形式を使うことができます。
3635エラーがあれば、やはり $@ に返されます。
4383エラーがあれば、やはり L<C<$@>|perlvar/$@> に返されます。
36364384例:
36374385
36384386 # make divide-by-zero nonfatal
36394387 eval { $answer = $a / $b; }; warn $@ if $@;
36404388
36414389 # same thing, but less efficient
36424390 eval '$answer = $a / $b'; warn $@ if $@;
36434391
36444392 # a compile-time error
36454393 eval { $answer = }; # WRONG
36464394
36474395 # a run-time error
36484396 eval '$answer ='; # sets $@
36494397
36504398=begin original
36514399
3652Using the C<eval{}> form as an exception trap in libraries does have some
4400Using the C<eval {}> form as an exception trap in libraries does have some
36534401issues. Due to the current arguably broken state of C<__DIE__> hooks, you
36544402may wish not to trigger any C<__DIE__> hooks that user code may have installed.
36554403You can use the C<local $SIG{__DIE__}> construct for this purpose,
36564404as this example shows:
36574405
36584406=end original
36594407
36604408C<eval{}> 形式をライブラリの例外を捕捉するために使うときには
36614409問題があります。
36624410現在の C<__DIE__> フックの状態はほぼ確実に壊れているという理由で、
36634411ユーザーのコードが設定した C<__DIE__> フックを実行したくないかもしれません。
36644412この目的には以下の例のように、C<local $SIG{__DIE__}> 構造が使えます。
36654413
36664414 # a private exception trap for divide-by-zero
36674415 eval { local $SIG{'__DIE__'}; $answer = $a / $b; };
36684416 warn $@ if $@;
36694417
36704418=begin original
36714419
36724420This is especially significant, given that C<__DIE__> hooks can call
3673C<die> again, which has the effect of changing their error messages:
4421L<C<die>|/die LIST> again, which has the effect of changing their error
4422messages:
36744423
36754424=end original
36764425
3677これは特に顕著です与えられた C<__DIE__> フックは C<die> をもう一度
4426これは特に顕著です; 与えられた C<__DIE__> フックは L<C<die>|/die LIST>
3678呼び出すことができ、これによってエラーメッセージを変える効果があります:
4427もう一度呼び出すことができ、これによってエラーメッセージを変える
4428効果があります:
36794429
36804430 # __DIE__ hooks may modify error messages
36814431 {
36824432 local $SIG{'__DIE__'} =
36834433 sub { (my $x = $_[0]) =~ s/foo/bar/g; die $x };
36844434 eval { die "foo lives here" };
36854435 print $@ if $@; # prints "bar lives here"
36864436 }
36874437
36884438=begin original
36894439
36904440Because this promotes action at a distance, this counterintuitive behavior
36914441may be fixed in a future release.
36924442
36934443=end original
36944444
36954445これは距離の離れた行動であるため、この直感的でない振る舞いは
36964446将来のリリースでは修正されるかもしれません。
36974447
36984448=begin original
36994449
3700With an C<eval>, you should be especially careful to remember what's
4450With an L<C<eval>|/eval EXPR>, you should be especially careful to
3701being looked at when:
4451remember what's being looked at when:
37024452
37034453=end original
37044454
3705C<eval> では、以下のような場合に、
4455L<C<eval>|/eval EXPR> では、以下のような場合に、
37064456何が調べられるかに特に注意しておくことが必要です:
37074457
37084458 eval $x; # CASE 1
37094459 eval "$x"; # CASE 2
37104460
37114461 eval '$x'; # CASE 3
37124462 eval { $x }; # CASE 4
37134463
37144464 eval "\$$x++"; # CASE 5
37154465 $$x++; # CASE 6
37164466
37174467=begin original
37184468
37194469Cases 1 and 2 above behave identically: they run the code contained in
37204470the variable $x. (Although case 2 has misleading double quotes making
37214471the reader wonder what else might be happening (nothing is).) Cases 3
37224472and 4 likewise behave in the same way: they run the code C<'$x'>, which
37234473does nothing but return the value of $x. (Case 4 is preferred for
37244474purely visual reasons, but it also has the advantage of compiling at
37254475compile-time instead of at run-time.) Case 5 is a place where
37264476normally you I<would> like to use double quotes, except that in this
37274477particular situation, you can just use symbolic references instead, as
37284478in case 6.
37294479
37304480=end original
37314481
37324482上記の CASE 1 と CASE 2 の動作は同一で、変数 $x 内の
37334483コードを実行します。
37344484(ただし、CASE 2 では、必要のないダブルクォートによって、
37354485読む人が何が起こるか混乱することでしょう (何も起こりませんが)。)
37364486同様に CASE 3 と CASE 4 の動作も等しく、$x の値を返す以外に
37374487何もしない C<$x> というコードを実行します
37384488(純粋に見た目の問題で、CASE 4 が好まれますが、
37394489実行時でなくコンパイル時にコンパイルされるという利点もあります)。
3740CASE 5 の場合は、通常ダブルクォートを使用します
4490CASE 5 の場合は、通常ダブルクォートを使用 I<します>;
37414491この状況を除けば、CASE 6 のように、単に
37424492シンボリックリファレンスを使えば良いでしょう。
37434493
37444494=begin original
37454495
3746Before Perl 5.14, the assignment to C<$@> occurred before restoration
4496Before Perl 5.14, the assignment to L<C<$@>|perlvar/$@> occurred before
3747of localised variables, which means that for your code to run on older
4497restoration
4498of localized variables, which means that for your code to run on older
37484499versions, a temporary is required if you want to mask some but not all
37494500errors:
37504501
37514502=end original
37524503
3753Perl 5.14 より前では、C<$@> への代入はローカル化された変数の復帰の前に
4504Perl 5.14 より前では、L<C<$@>|perlvar/$@> への代入はローカル化された変数の
3754起きるので、古いバージョンで実行される場合は、全てではなく一部だけの
4505復帰の前に起きるので、古いバージョンで実行される場合は、全てではなく一部だけの
37554506エラーをマスクしたい場合には一時変数が必要です:
37564507
37574508 # alter $@ on nefarious repugnancy only
37584509 {
37594510 my $e;
37604511 {
3761 local $@; # protect existing $@
4512 local $@; # protect existing $@
3762 eval { test_repugnancy() };
4513 eval { test_repugnancy() };
3763 # $@ =~ /nefarious/ and die $@; # Perl 5.14 and higher only
4514 # $@ =~ /nefarious/ and die $@; # Perl 5.14 and higher only
3764 $@ =~ /nefarious/ and $e = $@;
4515 $@ =~ /nefarious/ and $e = $@;
37654516 }
37664517 die $e if defined $e
37674518 }
37684519
37694520=begin original
37704521
37714522C<eval BLOCK> does I<not> count as a loop, so the loop control statements
3772C<next>, C<last>, or C<redo> cannot be used to leave or restart the block.
4523L<C<next>|/next LABEL>, L<C<last>|/last LABEL>, or
4524L<C<redo>|/redo LABEL> cannot be used to leave or restart the block.
37734525
37744526=end original
37754527
3776C<eval BLOCK> はループとして I<扱われません>
4528C<eval BLOCK> はループとして I<扱われません>; 従って、L<C<next>|/next LABEL>,
3777従って、C<next>, C<last>, C<redo> といったループ制御文でブロックから離れたり
4529L<C<last>|/last LABEL>, L<C<redo>|/redo LABEL> といったループ制御文で
3778再実行したりはできません。
4530ブロックから離れたり再実行したりはできません。
37794531
37804532=begin original
37814533
3782An C<eval ''> executed within the C<DB> package doesn't see the usual
4534An C<eval ''> executed within a subroutine defined
4535in the C<DB> package doesn't see the usual
37834536surrounding lexical scope, but rather the scope of the first non-DB piece
3784of code that called it. You don't normally need to worry about this unless
4537of code that called it. You don't normally need to worry about this unless
37854538you are writing a Perl debugger.
37864539
37874540=end original
37884541
3789C<DB> パッケージ内で C<eval ''> を実行すると、通常の
4542C<DB> パッケージで定義されたサブルーチン内で C<eval ''> を実行すると、通常の
37904543レキシカルスコープではなく、これを呼び出した最初の非 DB コード片の
37914544スコープになります。
37924545Perl デバッガを書いているのでない限り、普通はこれについて心配する必要は
37934546ありません。
37944547
4548=item evalbytes EXPR
4549X<evalbytes>
4550
4551=item evalbytes
4552
4553=for Pod::Functions +evalbytes similar to string eval, but intend to parse a bytestream
4554
4555=begin original
4556
4557This function is like L<C<eval>|/eval EXPR> with a string argument,
4558except it always parses its argument, or L<C<$_>|perlvar/$_> if EXPR is
4559omitted, as a string of bytes. A string containing characters whose
4560ordinal value exceeds 255 results in an error. Source filters activated
4561within the evaluated code apply to the code itself.
4562
4563=end original
4564
4565この関数は文字列引数の L<C<eval>|/eval EXPR> と同様ですが、引数(EXPR が
4566省略された場合はL<C<$_>|perlvar/$_>) を常にバイト単位のの文字列として
4567扱います。
4568序数が 255 を超える文字を含む文字列はエラーになります。
4569eval されたコード内で有効になったソースフィルタはコード自体に適用されます。
4570
4571=begin original
4572
4573L<C<evalbytes>|/evalbytes EXPR> is available only if the
4574L<C<"evalbytes"> feature|feature/The 'unicode_eval' and 'evalbytes' features>
4575is enabled or if it is prefixed with C<CORE::>. The
4576L<C<"evalbytes"> feature|feature/The 'unicode_eval' and 'evalbytes' features>
4577is enabled automatically with a C<use v5.16> (or higher) declaration in
4578the current scope.
4579
4580=end original
4581
4582L<C<evalbytes>|/evalbytes EXPR> は、
4583L<C<"evalbytes"> 機能|feature/The 'unicode_eval' and 'evalbytes' features> が
4584有効か、C<CORE::> 接頭辞を使ったときにのみ利用可能です。
4585L<C<"evalbytes"> 機能|feature/The 'unicode_eval' and 'evalbytes' features> は、
4586現在のスコープで C<use v5.16> (またはそれ以上) 宣言があると自動的に
4587有効になります。
4588
37954589=item exec LIST
37964590X<exec> X<execute>
37974591
37984592=item exec PROGRAM LIST
37994593
4594=for Pod::Functions abandon this program to run another
4595
38004596=begin original
38014597
3802The C<exec> function executes a system command I<and never returns>;
4598The L<C<exec>|/exec LIST> function executes a system command I<and never
3803use C<system> instead of C<exec> if you want it to return. It fails and
4599returns>; use L<C<system>|/system LIST> instead of L<C<exec>|/exec LIST>
4600if you want it to return. It fails and
38044601returns false only if the command does not exist I<and> it is executed
38054602directly instead of via your system's command shell (see below).
38064603
38074604=end original
38084605
3809C<exec> 関数は、システムのコマンドを実行し、I<戻ってはきません>;
4606L<C<exec>|/exec LIST> 関数は、システムのコマンドを実行し、I<戻ってはきません>;
3810戻って欲しい場合には、C<exec>ではなく C<system> 関数を使ってください。
4607戻って欲しい場合には、L<C<exec>|/exec LIST>ではなく
4608L<C<system>|/system LIST> 関数を使ってください。
38114609コマンドが存在せず、I<しかも> システムのコマンドシェル経由でなく
38124610直接コマンドを実行しようとした場合にのみこの関数は失敗して偽を返します。
38134611
38144612=begin original
38154613
3816Since it's a common mistake to use C<exec> instead of C<system>, Perl
4614Since it's a common mistake to use L<C<exec>|/exec LIST> instead of
3817warns you if there is a following statement that isn't C<die>, C<warn>,
4615L<C<system>|/system LIST>, Perl warns you if L<C<exec>|/exec LIST> is
3818or C<exit> (if C<-w> is set--but you always do that, right?). If you
4616called in void context and if there is a following statement that isn't
3819I<really> want to follow an C<exec> with some other statement, you
4617L<C<die>|/die LIST>, L<C<warn>|/warn LIST>, or L<C<exit>|/exit EXPR> (if
3820can use one of these styles to avoid the warning:
4618L<warnings> are enabled--but you always do that, right?). If you
4619I<really> want to follow an L<C<exec>|/exec LIST> with some other
4620statement, you can use one of these styles to avoid the warning:
38214621
38224622=end original
38234623
3824C<system> の代わりに C<exec> を使うというよくある間違いを防ぐために、
4624L<C<system>|/system LIST> の代わりに L<C<exec>|/exec LIST> を使うという
3825引き続文が C<die>, C<warn>, C<exit>(C<-w>セッされている場合 --
4625ある間違いを防ぐために、L<C<exec>|/exec LIST> が無効コンテキス
3826でもいつもセットしますよね) 以外の場合Perl は警告を出します。
4626呼び出されて、引き続く文が L<C<die>|/die LIST>, L<C<warn>|/warn LIST>,
3827もし I<本当に> C<exec> の後に他の文を書きたい場合、
4627L<C<exit>|/exit EXPR> 以外の場合、Perl は警告を出します(L<warnings> が
3828以下どちらかのスタイルを使うこと警告を回避できます:
4628有効場合 -- もいつもセットしてますよね?)。
4629もし I<本当に> L<C<exec>|/exec LIST> の後に他の文を書きたい場合、以下の
4630どちらかのスタイルを使うことで警告を回避できます:
38294631
38304632 exec ('foo') or print STDERR "couldn't exec foo: $!";
38314633 { exec ('foo') }; print STDERR "couldn't exec foo: $!";
38324634
38334635=begin original
38344636
3835If there is more than one argument in LIST, or if LIST is an array
4637If there is more than one argument in LIST, this calls L<execvp(3)> with the
3836with more than one value, calls execvp(3) with the arguments in LIST.
4638arguments in LIST. If there is only one element in LIST, the argument is
3837If there is only one scalar argument or an array with one element in it,
4639checked for shell metacharacters, and if there are any, the entire
3838the argument is checked for shell metacharacters, and if there are any,
4640argument is passed to the system's command shell for parsing (this is
3839the entire argument is passed to the system's command shell for parsing
4641C</bin/sh -c> on Unix platforms, but varies on other platforms). If
3840(this is C</bin/sh -c> on Unix platforms, but varies on other platforms).
4642there are no shell metacharacters in the argument, it is split into words
3841If there are no shell metacharacters in the argument, it is split into
4643and passed directly to C<execvp>, which is more efficient. Examples:
3842words and passed directly to C<execvp>, which is more efficient.
3843Examples:
38444644
38454645=end original
38464646
3847LIST に複数の引数がある場合、LIST が複数持つ
4647LIST に複数の引数がある場合、LIST の引数使って L<execvp(3)> を
3848配列の場合には、LIST の引数を使って、execvp(3) を呼び出します。
4648呼び出します。
38491 つのスカラ引数のみまたは要素が一つの配列の場合には、その引数から
4649LIST 要素が一つのの場合には、その引数からシェルのメタ文字をチェックし、
3850シェルのメタ文字をチェックし、もしメタ文字があれば、
4650もしメタ文字があれば、引数全体をシステムのコマンドシェル(これはUnix では
3851引数全体をシステムのコマンドシェル(これはUnix では
38524651C</bin/sh -c> ですが、システムによって異なります)に渡して解析させます。
3853もし、メタキャラクタがなければその引数単語に分け、
4652シェルのメタ文字がなかった場合、引数単語に分解されて直接 C<execvp> に
3854より効率的な C<execvp> に直接渡します。
4653渡されます; この方がより効率的す。
38554654例:
38564655
38574656 exec '/bin/echo', 'Your arguments are: ', @ARGV;
38584657 exec "sort $outfile | uniq";
38594658
38604659=begin original
38614660
38624661If you don't really want to execute the first argument, but want to lie
38634662to the program you are executing about its own name, you can specify
38644663the program you actually want to run as an "indirect object" (without a
3865comma) in front of the LIST. (This always forces interpretation of the
4664comma) in front of the LIST, as in C<exec PROGRAM LIST>. (This always
3866LIST as a multivalued list, even if there is only a single scalar in
4665forces interpretation of the LIST as a multivalued list, even if there
3867the list.) Example:
4666is only a single scalar in the list.) Example:
38684667
38694668=end original
38704669
3871第一引数に指定するものを本当に実行したいが、実行する
4670第一引数に指定するものを本当に実行したいが、実行するプログラムに対して別の
3872プログラムに対して別の名前を教えたい場合には、LISTのに、
4671名前を教えたい場合には、C<exec PROGRAM LIST> ように、LIST の前に
3873「間接オブジェクト」(コンマなし) として実際に
4672「間接オブジェクト」(コンマなし) として実際に実行したいプログラムを
3874実行したいプログラムを指定することができます。
4673指定することができます。
3875(これによって、LIST に単一のスカラしかなくても、複数
4674(これによって、LIST に単一のスカラしかなくても、複数値のリストであるように、
3876値のリストであるように、LIST の解釈を行ないます。)
4675LIST の解釈を行ないます。)
38774676例:
38784677
3879 $shell = '/bin/csh';
4678 my $shell = '/bin/csh';
38804679 exec $shell '-sh'; # pretend it's a login shell
38814680
38824681=begin original
38834682
38844683or, more directly,
38854684
38864685=end original
38874686
38884687あるいは、より直接的に、
38894688
38904689 exec {'/bin/csh'} '-sh'; # pretend it's a login shell
38914690
38924691=begin original
38934692
38944693When the arguments get executed via the system shell, results are
38954694subject to its quirks and capabilities. See L<perlop/"`STRING`">
38964695for details.
38974696
38984697=end original
38994698
39004699引数がシステムシェルで実行されるとき、結果はシェルの奇癖と能力によって
39014700変わります。
39024701詳細については L<perlop/"`STRING`"> を参照してください。
39034702
39044703=begin original
39054704
3906Using an indirect object with C<exec> or C<system> is also more
4705Using an indirect object with L<C<exec>|/exec LIST> or
3907secure. This usage (which also works fine with system()) forces
4706L<C<system>|/system LIST> is also more secure. This usage (which also
4707works fine with L<C<system>|/system LIST>) forces
39084708interpretation of the arguments as a multivalued list, even if the
39094709list had just one argument. That way you're safe from the shell
39104710expanding wildcards or splitting up words with whitespace in them.
39114711
39124712=end original
39134713
3914C<exec> や C<system> で間接オブジェクトを使うのもより安全です。
4714L<C<exec>|/exec LIST> L<C<system>|/system LIST> で間接オブジェクトを
3915この使い方(system() でも同様にまく動きます)は、たとえ引数が一つだけ
4715使うのもより安全です。
3916場合も、複数の値を持つリストとして引数を解釈するとを強制します
4716の使い方(L<C<system>|/system LIST> でも同様にうく動きま)は、たとえ
4717引数が一つだけの場合も、複数の値を持つリストとして引数を解釈することを
4718強制します。
39174719この方法で、シェルによるワイルドカード展開や、空白による単語の分割から
39184720守られます。
39194721
3920 @args = ( "echo surprise" );
4722 my @args = ( "echo surprise" );
39214723
39224724 exec @args; # subject to shell escapes
39234725 # if @args == 1
39244726 exec { $args[0] } @args; # safe even with one-arg list
39254727
39264728=begin original
39274729
39284730The first version, the one without the indirect object, ran the I<echo>
39294731program, passing it C<"surprise"> an argument. The second version didn't;
39304732it tried to run a program named I<"echo surprise">, didn't find it, and set
3931C<$?> to a non-zero value indicating failure.
4733L<C<$?>|perlvar/$?> to a non-zero value indicating failure.
39324734
39334735=end original
39344736
39354737間接オブジェクトなしの一つ目のバージョンでは、I<echo> プログラムが実行され、
39364738C<"surprise"> が引数として渡されます。
39374739二つ目のバージョンでは違います; I<"echo surprise"> という名前の
39384740プログラムを実行しようとして、見つからないので、失敗したことを示すために
3939C<$?> に非 0 がセットされます。
4741L<C<$?>|perlvar/$?> に非 0 がセットされます。
39404742
39414743=begin original
39424744
3943Beginning with v5.6.0, Perl attempts to flush all files opened for
4745On Windows, only the C<exec PROGRAM LIST> indirect object syntax will
3944output before the exec, but this may not be supported on some platforms
4746reliably avoid using the shell; C<exec LIST>, even with more than one
3945(see L<perlport>). To be safe, you may need to set C<$|> ($AUTOFLUSH
4747element, will fall back to the shell if the first spawn fails.
3946in English) or call the C<autoflush()> method of C<IO::Handle> on any
3947open handles to avoid lost output.
39484748
39494749=end original
39504750
4751Windows では、C<exec PROGRAM LIST> 間接オブジェクト構文のみが、シェルを
4752使うのを回避するための信頼できる方法です; C<exec LIST> は、複数の要素が
4753あっても、最初の spawn が失敗したときにシェルに
4754フォールバックすることがあります。
4755
4756=begin original
4757
4758Perl attempts to flush all files opened for output before the exec,
4759but this may not be supported on some platforms (see L<perlport>).
4760To be safe, you may need to set L<C<$E<verbar>>|perlvar/$E<verbar>>
4761(C<$AUTOFLUSH> in L<English>) or call the C<autoflush> method of
4762L<C<IO::Handle>|IO::Handle/METHODS> on any open handles to avoid lost
4763output.
4764
4765=end original
4766
39514767v5.6.0 から、Perl は exec の前に出力用に開かれている全てのファイルを
39524768フラッシュしようとしますが、これに対応していないプラットフォームもあります
39534769(L<perlport> を参照してください)。
39544770安全のためには、出力が重複するのを避けるために、全てのオープンしている
3955ハンドルに対して C<$|> (English モジュールでは $AUTOFLUSH) を設定するか、
4771ハンドルに対して L<C<$E<verbar>>|perlvar/$E<verbar>>
3956C<IO::Handle> モジュール C<autoflush()> メソッドを呼ぶ必要が
4772(L<English> モジュールでは C<$AUTOFLUSH>)設定するか、
3957あるかもしれません。
4773L<C<IO::Handle>|IO::Handle/METHODS> モジュールの C<autoflush> メソッドを
4774呼ぶ必要があるかもしれません。
39584775
39594776=begin original
39604777
3961Note that C<exec> will not call your C<END> blocks, nor will it invoke
4778Note that L<C<exec>|/exec LIST> will not call your C<END> blocks, nor
3962C<DESTROY> methods on your objects.
4779will it invoke C<DESTROY> methods on your objects.
39634780
39644781=end original
39654782
3966C<exec> は C<END> ブロックや、オブジェクトの C<DESTROY> メソッドを
4783L<C<exec>|/exec LIST> は C<END> ブロックや、オブジェクトの
3967起動しないことに注意してください。
4784C<DESTROY> メソッドを起動しないことに注意してください。
39684785
4786=begin original
4787
4788Portability issues: L<perlport/exec>.
4789
4790=end original
4791
4792移植性の問題: L<perlport/exec>。
4793
39694794=item exists EXPR
39704795X<exists> X<autovivification>
39714796
4797=for Pod::Functions test whether a hash key is present
4798
39724799=begin original
39734800
39744801Given an expression that specifies an element of a hash, returns true if the
39754802specified element in the hash has ever been initialized, even if the
39764803corresponding value is undefined.
39774804
39784805=end original
39794806
39804807ハッシュ要素を示す表現が与えられ、指定された要素が、ハッシュに存在すれば、
39814808たとえ対応する値が未定義でも真を返します。
39824809
39834810 print "Exists\n" if exists $hash{$key};
39844811 print "Defined\n" if defined $hash{$key};
39854812 print "True\n" if $hash{$key};
39864813
39874814=begin original
39884815
39894816exists may also be called on array elements, but its behavior is much less
3990obvious and is strongly tied to the use of L</delete> on arrays. B<Be aware>
4817obvious and is strongly tied to the use of L<C<delete>|/delete EXPR> on
3991that calling exists on array values is deprecated and likely to be removed in
4818arrays.
3992a future version of Perl.
39934819
39944820=end original
39954821
39964822exists は配列の要素に対しても呼び出せますが、その振る舞いははるかに
3997不明確で、配列に対する L</delete> の使用と強く結びついています。
4823不明確で、配列に対する L<C<delete>|/delete EXPR> の使用と強く
3998配列の値に対して exists を呼のは非推奨であり、将来のバージョンの
4824ついていま
3999Perl では削除されるかもしれないことを B<注意してください> 。
40004825
4826=begin original
4827
4828B<WARNING:> Calling L<C<exists>|/exists EXPR> on array values is
4829strongly discouraged. The
4830notion of deleting or checking the existence of Perl array elements is not
4831conceptually coherent, and can lead to surprising behavior.
4832
4833=end original
4834
4835B<警告:> 配列の値に対して L<C<exists>|/exists EXPR> を呼び出すことは強く
4836非推奨です。
4837Perl の配列要素を削除したり存在を調べたりする記法は概念的に一貫しておらず、
4838驚くべき振る舞いを引き起こすことがあります。
4839
40014840 print "Exists\n" if exists $array[$index];
40024841 print "Defined\n" if defined $array[$index];
40034842 print "True\n" if $array[$index];
40044843
40054844=begin original
40064845
40074846A hash or array element can be true only if it's defined and defined only if
40084847it exists, but the reverse doesn't necessarily hold true.
40094848
40104849=end original
40114850
40124851ハッシュまたは配列要素は、定義されているときにのみ真となり、
40134852存在しているときにのみ定義されますが、逆は必ずしも真ではありません。
40144853
40154854=begin original
40164855
40174856Given an expression that specifies the name of a subroutine,
40184857returns true if the specified subroutine has ever been declared, even
40194858if it is undefined. Mentioning a subroutine name for exists or defined
40204859does not count as declaring it. Note that a subroutine that does not
40214860exist may still be callable: its package may have an C<AUTOLOAD>
40224861method that makes it spring into existence the first time that it is
40234862called; see L<perlsub>.
40244863
40254864=end original
40264865
40274866引数としてサブルーチンの名前が指定された場合、
40284867指定されたサブルーチンが宣言されていれば(たとえ未定義でも)
40294868真を返します。
40304869exists や defined のために言及されているサブルーチン名は
40314870宣言としてのカウントに入りません。
40324871存在しないサブルーチンでも呼び出し可能かもしれないことに注意してください:
40334872パッケージが C<AUTOLOAD> メソッドを持っていて、最初に呼び出された時に
40344873存在を作り出すかもしれません; L<perlsub> を参照してください。
40354874
40364875 print "Exists\n" if exists &subroutine;
40374876 print "Defined\n" if defined &subroutine;
40384877
40394878=begin original
40404879
40414880Note that the EXPR can be arbitrarily complicated as long as the final
40424881operation is a hash or array key lookup or subroutine name:
40434882
40444883=end original
40454884
4046最終的な操作がハッシュや配列の key による検索またはサブルーチン名である限りは、
4885最終的な操作がハッシュや配列の key による検索または
4047EXPR には任意の複雑な式を置くことができます:
4886サブルーチン名である限りは、EXPR には任意の複雑な式を置くことができます:
40484887
40494888 if (exists $ref->{A}->{B}->{$key}) { }
40504889 if (exists $hash{A}{B}{$key}) { }
40514890
40524891 if (exists $ref->{A}->{B}->[$ix]) { }
40534892 if (exists $hash{A}{B}[$ix]) { }
40544893
40554894 if (exists &{$ref->{A}{B}{$key}}) { }
40564895
40574896=begin original
40584897
4059Although the mostly deeply nested array or hash will not spring into
4898Although the most deeply nested array or hash element will not spring into
40604899existence just because its existence was tested, any intervening ones will.
40614900Thus C<< $ref->{"A"} >> and C<< $ref->{"A"}->{"B"} >> will spring
4062into existence due to the existence test for the $key element above.
4901into existence due to the existence test for the C<$key> element above.
40634902This happens anywhere the arrow operator is used, including even here:
40644903
40654904=end original
40664905
4067ネストした配列やハッシュの一番深い部分は、その存在をテストしただけでは
4906最も深くネストした配列やハッシュの要素は、その存在をテストしただけでは
40684907存在するようにはなりませんが、途中のものは存在するようになります。
4069従って C<< $ref->{"A"} >> と C<< $ref->{"A"}->{"B"} >> は上記の $key の
4908従って C<< $ref->{"A"} >> と C<< $ref->{"A"}->{"B"} >> は上記の C<$key>
40704909存在をテストしたことによって存在するようになります。
40714910これは、矢印演算子が使われるところでは、以下のようなものを含むどこででも
40724911起こります。
40734912
40744913 undef $ref;
40754914 if (exists $ref->{"Some key"}) { }
40764915 print $ref; # prints HASH(0x80d3d5c)
40774916
40784917=begin original
40794918
40804919This surprising autovivification in what does not at first--or even
40814920second--glance appear to be an lvalue context may be fixed in a future
40824921release.
40834922
40844923=end original
40854924
40864925一目見ただけでは -- あるいは二目見ても -- 驚かされる、左辺値コンテキストでの
40874926自動有効化は将来のリリースでは修正されるでしょう。
40884927
40894928=begin original
40904929
40914930Use of a subroutine call, rather than a subroutine name, as an argument
4092to exists() is an error.
4931to L<C<exists>|/exists EXPR> is an error.
40934932
40944933=end original
40954934
4096exists() の引数としてサブルーチン名でなくサブルーチン呼び出しを使うと、
4935L<C<exists>|/exists EXPR> の引数としてサブルーチン名でなくサブルーチン
4097エラーになります。
4936呼び出しを使うと、エラーになります。
40984937
40994938 exists &sub; # OK
41004939 exists &sub(); # Error
41014940
41024941=item exit EXPR
41034942X<exit> X<terminate> X<abort>
41044943
41054944=item exit
41064945
4946=for Pod::Functions terminate this program
4947
41074948=begin original
41084949
41094950Evaluates EXPR and exits immediately with that value. Example:
41104951
41114952=end original
41124953
41134954EXPR を評価し、即座にその値を持って終了します。
41144955例:
41154956
4116 $ans = <STDIN>;
4957 my $ans = <STDIN>;
41174958 exit 0 if $ans =~ /^[Xx]/;
41184959
41194960=begin original
41204961
4121See also C<die>. If EXPR is omitted, exits with C<0> status. The only
4962See also L<C<die>|/die LIST>. If EXPR is omitted, exits with C<0>
4963status. The only
41224964universally recognized values for EXPR are C<0> for success and C<1>
41234965for error; other values are subject to interpretation depending on the
41244966environment in which the Perl program is running. For example, exiting
4125496769 (EX_UNAVAILABLE) from a I<sendmail> incoming-mail filter will cause
41264968the mailer to return the item undelivered, but that's not true everywhere.
41274969
41284970=end original
41294971
4130C<die> も参照してください。
4972L<C<die>|/die LIST> も参照してください。
41314973EXPR が省略された場合には、ステータスを C<0> として終了します。
4132EXPR の値として広く利用可能なのは C<0> が成功で C<1> がエラーということだけです。
4974EXPR の値として広く利用可能なのは C<0> が成功で C<1> が
4133その他の値は、 Perl が実行される環境によって異なる解釈がされ
4975エラーということだけです; その他の値は、 Perl が実行される環境によって異なる
4134可能性があります。
4976解釈がされる可能性があります。
41354977例えば、I<sendmail> 到着メールフィルタから 69 (EX_UNAVAILABLE) で終了すると
41364978メーラーはアイテムを配達せずに差し戻しますが、
41374979これはいつでも真ではありません。
41384980
41394981=begin original
41404982
4141Don't use C<exit> to abort a subroutine if there's any chance that
4983Don't use L<C<exit>|/exit EXPR> to abort a subroutine if there's any
4142someone might want to trap whatever error happened. Use C<die> instead,
4984chance that someone might want to trap whatever error happened. Use
4143which can be trapped by an C<eval>.
4985L<C<die>|/die LIST> instead, which can be trapped by an
4986L<C<eval>|/eval EXPR>.
41444987
41454988=end original
41464989
41474990誰かが発生したエラーをトラップしようと考えている可能性がある場合は、
4148サブルーチンの中断に C<exit> を使わないでください。
4991サブルーチンの中断に L<C<exit>|/exit EXPR> を使わないでください。
4149代わりに C<eval> でトラップできる C<die> を使ってください。
4992代わりに L<C<eval>|/eval EXPR> でトラップできる L<C<die>|/die LIST>
4993使ってください。
41504994
41514995=begin original
41524996
4153The exit() function does not always exit immediately. It calls any
4997The L<C<exit>|/exit EXPR> function does not always exit immediately. It
4154defined C<END> routines first, but these C<END> routines may not
4998calls any defined C<END> routines first, but these C<END> routines may
4155themselves abort the exit. Likewise any object destructors that need to
4999not themselves abort the exit. Likewise any object destructors that
4156be called are called before the real exit. C<END> routines and destructors
5000need to be called are called before the real exit. C<END> routines and
4157can change the exit status by modifying C<$?>. If this is a problem, you
5001destructors can change the exit status by modifying L<C<$?>|perlvar/$?>.
4158can call C<POSIX:_exit($status)> to avoid END and destructor processing.
5002If this is a problem, you can call
4159See L<perlmod> for details.
5003L<C<POSIX::_exit($status)>|POSIX/C<_exit>> to avoid C<END> and destructor
5004processing. See L<perlmod> for details.
41605005
41615006=end original
41625007
4163exit() 関数は常に直ちに終了するわけではありません。
5008L<C<exit>|/exit EXPR> 関数は常に直ちに終了するわけではありません。
4164まず、定義されている END ルーチンを呼び出しますが、
5009まず、定義されている C<END> ルーチンを呼び出しますが、
41655010C<END> ルーチン自身は exit を止められません。
41665011同様に、呼び出す必要のあるオブジェクトデストラクタは
41675012すべて、実際の終了前に呼び出されます。
4168C<END> ルーチンとデストラクタは C<$?> を修正することで終了コードを
5013C<END> ルーチンとデストラクタは L<C<$?>|perlvar/$?> を修正することで
4169変更できます。
5014終了コードを変更できます。
4170これが問題になる場合は、END やデストラクタが実行されることを
5015これが問題になる場合は、C<END> やデストラクタが実行されることを
4171防ぐために C<POSIX:_exit($status)> を呼び出してください。
5016防ぐために L<C<POSIX::_exit($status)>|POSIX/C<_exit>> を呼び出してください。
41725017詳しくは L<perlmod> を参照してください。
41735018
5019=begin original
5020
5021Portability issues: L<perlport/exit>.
5022
5023=end original
5024
5025移植性の問題: L<perlport/exit>。
5026
41745027=item exp EXPR
41755028X<exp> X<exponential> X<antilog> X<antilogarithm> X<e>
41765029
41775030=item exp
41785031
5032=for Pod::Functions raise I<e> to a power
5033
41795034=begin original
41805035
41815036Returns I<e> (the natural logarithm base) to the power of EXPR.
41825037If EXPR is omitted, gives C<exp($_)>.
41835038
41845039=end original
41855040
4186I<e> (自然対数の底) の EXPR 乗を返します。 
5041I<e> (自然対数の底) の EXPR 乗を返します。
41875042EXPR を省略した場合には、C<exp($_)> を返します。
41885043
5044=item fc EXPR
5045X<fc> X<foldcase> X<casefold> X<fold-case> X<case-fold>
5046
5047=item fc
5048
5049=for Pod::Functions +fc return casefolded version of a string
5050
5051=begin original
5052
5053Returns the casefolded version of EXPR. This is the internal function
5054implementing the C<\F> escape in double-quoted strings.
5055
5056=end original
5057
5058EXPR の畳み込み版を返します。
5059これは、ダブルクォート文字列における、C<\F> エスケープを
5060実装する内部関数です。
5061
5062=begin original
5063
5064Casefolding is the process of mapping strings to a form where case
5065differences are erased; comparing two strings in their casefolded
5066form is effectively a way of asking if two strings are equal,
5067regardless of case.
5068
5069=end original
5070
5071畳み込みは大文字小文字の違いを消した形式に文字列をマッピングする処理です;
5072畳み込み形式で二つの文字列を比較するのは二つの文字列が大文字小文字に
5073関わらず等しいかどうかを比較する効率的な方法です。
5074
5075=begin original
5076
5077Roughly, if you ever found yourself writing this
5078
5079=end original
5080
5081おおよそ、自分自身で以下のように書いていたとしても
5082
5083 lc($this) eq lc($that) # Wrong!
5084 # or
5085 uc($this) eq uc($that) # Also wrong!
5086 # or
5087 $this =~ /^\Q$that\E\z/i # Right!
5088
5089=begin original
5090
5091Now you can write
5092
5093=end original
5094
5095今では以下のように書けます
5096
5097 fc($this) eq fc($that)
5098
5099=begin original
5100
5101And get the correct results.
5102
5103=end original
5104
5105そして正しい結果を得られます。
5106
5107=begin original
5108
5109Perl only implements the full form of casefolding, but you can access
5110the simple folds using L<Unicode::UCD/B<casefold()>> and
5111L<Unicode::UCD/B<prop_invmap()>>.
5112For further information on casefolding, refer to
5113the Unicode Standard, specifically sections 3.13 C<Default Case Operations>,
51144.2 C<Case-Normative>, and 5.18 C<Case Mappings>,
5115available at L<http://www.unicode.org/versions/latest/>, as well as the
5116Case Charts available at L<http://www.unicode.org/charts/case/>.
5117
5118=end original
5119
5120Perl は完全な形式の畳み込みのみを実装していますが、
5121L<Unicode::UCD/B<casefold()>> と L<Unicode::UCD/B<prop_invmap()>> を使って
5122単純なたたみ込みにアクセスできます。
5123畳み込みに関するさらなる情報については、
5124L<http://www.unicode.org/versions/latest/> で利用可能な Unicode 標準、特に
51253.13 C<Default Case Operations>, 4.2 C<Case-Normative>, 5.18
5126C<Case Mappings> および、L<http://www.unicode.org/charts/case/> で
5127利用可能なケース表を参照してください。
5128
5129=begin original
5130
5131If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
5132
5133=end original
5134
5135EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
5136
5137=begin original
5138
5139This function behaves the same way under various pragmas, such as within
5140L<S<C<"use feature 'unicode_strings">>|feature/The 'unicode_strings' feature>,
5141as L<C<lc>|/lc EXPR> does, with the single exception of
5142L<C<fc>|/fc EXPR> of I<LATIN CAPITAL LETTER SHARP S> (U+1E9E) within the
5143scope of L<S<C<use locale>>|locale>. The foldcase of this character
5144would normally be C<"ss">, but as explained in the L<C<lc>|/lc EXPR>
5145section, case
5146changes that cross the 255/256 boundary are problematic under locales,
5147and are hence prohibited. Therefore, this function under locale returns
5148instead the string C<"\x{17F}\x{17F}">, which is the I<LATIN SMALL LETTER
5149LONG S>. Since that character itself folds to C<"s">, the string of two
5150of them together should be equivalent to a single U+1E9E when foldcased.
5151
5152=end original
5153
5154この関数は、
5155L<S<C<"use feature 'unicode_strings">>|feature/The 'unicode_strings' feature>
5156のようなさまざまなプラグマの影響下では、L<C<lc>|/lc EXPR> と同様に
5157振る舞います;
5158但し、L<S<C<use locale>>|locale> のスコープ内での
5159I<LATIN CAPITAL LETTER SHARP S> (U+1E9E) の L<C<fc>|/fc EXPR> は例外です。
5160この文字の畳み込み文字は普通は C<"ss"> ですが、L<C<lc>|/lc EXPR> の節で
5161説明しているように、ロケールの基での255/256 境界をまたぐ大文字小文字の変更は
5162問題があるので、禁止されています。
5163従って、ロケールの基ではこの関数は代わりに I<LATIN SMALL LETTER LONG S> である
5164C<"\x{17F}\x{17F}"> を返します。
5165この文字自体は C<"s"> の畳み込みなので、これら二つを合わせた文字列は
5166畳み込まれた場合は単一の U+1E9E と等価になります。
5167
5168=begin original
5169
5170While the Unicode Standard defines two additional forms of casefolding,
5171one for Turkic languages and one that never maps one character into multiple
5172characters, these are not provided by the Perl core. However, the CPAN module
5173L<C<Unicode::Casing>|Unicode::Casing> may be used to provide an implementation.
5174
5175=end original
5176
5177Unicode 標準はさらに二つの畳み込み形式、一つはツルキ語、もう一つは決して
5178一つの文字が複数の文字にマッピングされないもの、を定義していますが、
5179これらは Perl コアでは提供されません。
5180しかし、CPAN モジュール L<C<Unicode::Casing>|Unicode::Casing> が実装を
5181提供しています。
5182
5183=begin original
5184
5185L<C<fc>|/fc EXPR> is available only if the
5186L<C<"fc"> feature|feature/The 'fc' feature> is enabled or if it is
5187prefixed with C<CORE::>. The
5188L<C<"fc"> feature|feature/The 'fc' feature> is enabled automatically
5189with a C<use v5.16> (or higher) declaration in the current scope.
5190
5191=end original
5192
5193L<C<fc>|/fc EXPR> は
5194L<C<"fc"> 機能|feature/The 'fc' feature> が有効か C<CORE::> が
5195前置されたときにのみ利用可能です。
5196L<C<"fc"> 機能|feature/The 'fc' feature> は現在のスコープで
5197C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。
5198
41895199=item fcntl FILEHANDLE,FUNCTION,SCALAR
41905200X<fcntl>
41915201
5202=for Pod::Functions file control system call
5203
41925204=begin original
41935205
4194Implements the fcntl(2) function. You'll probably have to say
5206Implements the L<fcntl(2)> function. You'll probably have to say
41955207
41965208=end original
41975209
4198fcntl(2) 関数を実装します。
5210L<fcntl(2)> 関数を実装します。
4199正しい定数定義を得るために、まず
5211正しい定数定義を得るために、まず
42005212
42015213 use Fcntl;
42025214
42035215=begin original
42045216
42055217first to get the correct constant definitions. Argument processing and
4206value returned work just like C<ioctl> below.
5218value returned work just like L<C<ioctl>|/ioctl
4207For example:
5219FILEHANDLE,FUNCTION,SCALAR> below. For example:
42085220
42095221=end original
42105222
42115223と書くことが必要でしょう。
4212引数の処理と返り値については、下記の C<ioctl> と同様に動作します。
5224引数の処理と返り値については、下記の
4213例:
5225L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同様に動作します。
5226例えば:
42145227
42155228 use Fcntl;
4216 fcntl($filehandle, F_GETFL, $packed_return_buffer)
5229 my $flags = fcntl($filehandle, F_GETFL, 0)
4217 or die "can't fcntl F_GETFL: $!";
5230 or die "Can't fcntl F_GETFL: $!";
42185231
42195232=begin original
42205233
4221You don't have to check for C<defined> on the return from C<fcntl>.
5234You don't have to check for L<C<defined>|/defined EXPR> on the return
4222Like C<ioctl>, it maps a C<0> return from the system call into
5235from L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>. Like
4223C<"0 but true"> in Perl. This string is true in boolean context and C<0>
5236L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>, it maps a C<0> return
4224in numeric context. It is also exempt from the normal B<-w> warnings
5237from the system call into C<"0 but true"> in Perl. This string is true
4225on improper numeric conversions.
5238in boolean context and C<0> in numeric context. It is also exempt from
5239the normal
5240L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s>
5241L<warnings> on improper numeric conversions.
42265242
42275243=end original
42285244
4229C<fcntl> からの返り値のチェックに C<defined> を使う必要はありません。
5245L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> からの返り値のチェックに
4230C<ioctl> と違って、C<fnctl> はシステムコールの結果が C<0> だった場合
5246L<C<defined>|/defined EXPR> を使う必要ありません。
4231C<"0 だが真">を返します。
5247L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と違って、これは
5248システムコールの結果が C<0> だった場合は C<"0 だが真"> を返します。
42325249この文字列は真偽値コンテキストでは真となり、
42335250数値コンテキストでは C<0> になります。
4234これはまた、不適切な数値変換に関する通常の B<-w> 警告を回避します。
5251これはまた、不適切な数値変換に関する通常の
5252L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s>
5253L<warnings> を回避します。
42355254
42365255=begin original
42375256
4238Note that C<fcntl> raises an exception if used on a machine that
5257Note that L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> raises an
4239doesn't implement fcntl(2). See the Fcntl module or your fcntl(2)
5258exception if used on a machine that doesn't implement L<fcntl(2)>. See
4240manpage to learn what functions are available on your system.
5259the L<Fcntl> module or your L<fcntl(2)> manpage to learn what functions
5260are available on your system.
42415261
42425262=end original
42435263
4244fcntl(2) が実装されていないマシンでは、C<fcntl>は例外を
5264L<fcntl(2)> が実装されていないマシンでは、
5265L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> は例外を
42455266引き起こすことに注意してください。
4246システムでどの関数が利用可能かについては Fcntl モジュールや
5267システムでどの関数が利用可能かについては L<Fcntl> モジュールや
4247fcntl(2) man ページを参照してください。
5268L<fcntl(2)> man ページを参照してください。
42485269
42495270=begin original
42505271
4251Here's an example of setting a filehandle named C<REMOTE> to be
5272Here's an example of setting a filehandle named C<$REMOTE> to be
4252non-blocking at the system level. You'll have to negotiate C<$|>
5273non-blocking at the system level. You'll have to negotiate
4253on your own, though.
5274L<C<$E<verbar>>|perlvar/$E<verbar>> on your own, though.
42545275
42555276=end original
42565277
4257これは C<REMOTE> というファイルハンドルをシステムレベルで
5278これは C<$REMOTE> というファイルハンドルをシステムレベルで
42585279非ブロックモードにセットする例です。
4259ただし、 C<$|> を自分で管理しなければなりません。
5280ただし、 L<C<$E<verbar>>|perlvar/$E<verbar>> を自分で管理しなければなりません。
42605281
42615282 use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
42625283
4263 $flags = fcntl(REMOTE, F_GETFL, 0)
5284 my $flags = fcntl($REMOTE, F_GETFL, 0)
4264 or die "Can't get flags for the socket: $!\n";
5285 or die "Can't get flags for the socket: $!\n";
42655286
4266 $flags = fcntl(REMOTE, F_SETFL, $flags | O_NONBLOCK)
5287 fcntl($REMOTE, F_SETFL, $flags | O_NONBLOCK)
4267 or die "Can't set flags for the socket: $!\n";
5288 or die "Can't set flags for the socket: $!\n";
42685289
5290=begin original
5291
5292Portability issues: L<perlport/fcntl>.
5293
5294=end original
5295
5296移植性の問題: L<perlport/fcntl>。
5297
5298=item __FILE__
5299X<__FILE__>
5300
5301=for Pod::Functions the name of the current source file
5302
5303=begin original
5304
5305A special token that returns the name of the file in which it occurs.
5306
5307=end original
5308
5309これが書いてあるファイルの名前を返す特殊トークン。
5310
42695311=item fileno FILEHANDLE
42705312X<fileno>
42715313
5314=for Pod::Functions return file descriptor from filehandle
5315
42725316=begin original
42735317
42745318Returns the file descriptor for a filehandle, or undefined if the
42755319filehandle is not open. If there is no real file descriptor at the OS
42765320level, as can happen with filehandles connected to memory objects via
4277C<open> with a reference for the third argument, -1 is returned.
5321L<C<open>|/open FILEHANDLE,EXPR> with a reference for the third
5322argument, -1 is returned.
42785323
42795324=end original
42805325
4281ファイルハンドルに対するファイル記述子を返します
5326ファイルハンドルに対するファイル記述子を返します; ファイルハンドルが
4282ファイルハンドルがオープンしていない場合は未定義値を返します。
5327オープンしていない場合は未定義値を返します。
4283OS レベルで実際のファイル記述子がない(C<open> の第 3 引数にリファレンスを
5328OS レベルで実際のファイル記述子がない(L<C<open>|/open FILEHANDLE,EXPR>
5329第 3 引数にリファレンスを
42845330指定してファイルハンドルがメモリオブジェクトと結びつけられたときに
42855331起こります)場合、-1 が返されます。
42865332
42875333=begin original
42885334
4289This is mainly useful for constructing
5335This is mainly useful for constructing bitmaps for
4290bitmaps for C<select> and low-level POSIX tty-handling operations.
5336L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> and low-level POSIX
5337tty-handling operations.
42915338If FILEHANDLE is an expression, the value is taken as an indirect
42925339filehandle, generally its name.
42935340
42945341=end original
42955342
4296これは主に C<select> や低レベル POSIX tty 操作に対する、ビットマップを
5343これは主に L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> や低レベル
4297構成するときに便利です。
5344POSIX tty 操作に対する、ビットマップを構成するときに便利です。
42985345FILEHANDLE が式であれば、
42995346その値が間接ファイルハンドル(普通は名前)として使われます。
43005347
43015348=begin original
43025349
43035350You can use this to find out whether two handles refer to the
43045351same underlying descriptor:
43055352
43065353=end original
43075354
43085355これを、二つのハンドルが同じ識別子を参照しているかどうかを見つけるのに
43095356使えます:
43105357
4311 if (fileno(THIS) == fileno(THAT)) {
5358 if (fileno($this) != -1 && fileno($this) == fileno($that)) {
4312 print "THIS and THAT are dups\n";
5359 print "\$this and \$that are dups\n";
5360 } elsif (fileno($this) != -1 && fileno($that) != -1) {
5361 print "\$this and \$that have different " .
5362 "underlying file descriptors\n";
5363 } else {
5364 print "At least one of \$this and \$that does " .
5365 "not have a real file descriptor\n";
43135366 }
43145367
5368=begin original
5369
5370The behavior of L<C<fileno>|/fileno FILEHANDLE> on a directory handle
5371depends on the operating system. On a system with L<dirfd(3)> or
5372similar, L<C<fileno>|/fileno FILEHANDLE> on a directory
5373handle returns the underlying file descriptor associated with the
5374handle; on systems with no such support, it returns the undefined value,
5375and sets L<C<$!>|perlvar/$!> (errno).
5376
5377=end original
5378
5379ディレクトリハンドルに対する L<C<fileno>|/fileno FILEHANDLE> の振る舞いは
5380オペレーティングシステムに依存します。
5381L<dirfd(3)> のようなものがあるシステムでは、ディレクトリハンドルに対する
5382L<C<fileno>|/fileno FILEHANDLE> はハンドルに関連付けられた基となる
5383ファイル記述子を返します;
5384そのような対応がないシステムでは、未定義値を返し、
5385L<C<$!>|perlvar/$!> (errno) を設定します。
5386
43155387=item flock FILEHANDLE,OPERATION
43165388X<flock> X<lock> X<locking>
43175389
5390=for Pod::Functions lock an entire file with an advisory lock
5391
43185392=begin original
43195393
4320Calls flock(2), or an emulation of it, on FILEHANDLE. Returns true
5394Calls L<flock(2)>, or an emulation of it, on FILEHANDLE. Returns true
43215395for success, false on failure. Produces a fatal error if used on a
4322machine that doesn't implement flock(2), fcntl(2) locking, or lockf(3).
5396machine that doesn't implement L<flock(2)>, L<fcntl(2)> locking, or
4323C<flock> is Perl's portable file-locking interface, although it locks
5397L<lockf(3)>. L<C<flock>|/flock FILEHANDLE,OPERATION> is Perl's portable
4324entire files only, not records.
5398file-locking interface, although it locks entire files only, not
5399records.
43255400
43265401=end original
43275402
4328FILEHANDLE に対して flock(2)、またはそのエミュレーションを呼び出します。
5403FILEHANDLE に対して L<flock(2)>、またはそのエミュレーションを呼び出します。
43295404成功時には真を、失敗時には偽を返します。
4330flock(2), fcntl(2) ロック, lockf(3) のいずれかを実装していない
5405L<flock(2)>, L<fcntl(2)> ロック, L<lockf(3)> のいずれかを実装していない
43315406マシンで使うと、致命的エラーが発生します。
4332C<flock> は Perl の移植性のあるファイルロックインターフェースです。
5407L<C<flock>|/flock FILEHANDLE,OPERATION> は Perl の移植性のある
5408ファイルロックインターフェースです;
43335409しかしレコードではなく、ファイル全体のみをロックします。
43345410
43355411=begin original
43365412
4337Two potentially non-obvious but traditional C<flock> semantics are
5413Two potentially non-obvious but traditional L<C<flock>|/flock
5414FILEHANDLE,OPERATION> semantics are
43385415that it waits indefinitely until the lock is granted, and that its locks
43395416are B<merely advisory>. Such discretionary locks are more flexible, but
43405417offer fewer guarantees. This means that programs that do not also use
4341C<flock> may modify files locked with C<flock>. See L<perlport>,
5418L<C<flock>|/flock FILEHANDLE,OPERATION> may modify files locked with
5419L<C<flock>|/flock FILEHANDLE,OPERATION>. See L<perlport>,
43425420your port's specific documentation, and your system-specific local manpages
43435421for details. It's best to assume traditional behavior if you're writing
43445422portable programs. (But if you're not, you should as always feel perfectly
43455423free to write for your own system's idiosyncrasies (sometimes called
43465424"features"). Slavish adherence to portability concerns shouldn't get
43475425in the way of your getting your job done.)
43485426
43495427=end original
43505428
4351明白ではないものの、伝統的な C<flock> の動作としては、ロックが得られるまで
5429明白ではないものの、伝統的な L<C<flock>|/flock FILEHANDLE,OPERATION>
5430動作としては、ロックが得られるまで
43525431無限に待ち続けるものと、B<単に勧告的に> ロックするものの二つがあります。
43535432このような自由裁量のロックはより柔軟ですが、保障されるものはより少ないです。
4354これは、C<flock> を使わないプログラムが C<flock> でロックされたファイルを
5433これは、L<C<flock>|/flock FILEHANDLE,OPERATION> を使わないプログラムが
5434L<C<flock>|/flock FILEHANDLE,OPERATION> でロックされたファイルを
43555435書き換えるかもしれないことを意味します。
43565436詳細については、L<perlport>、システム固有のドキュメント、システム固有の
43575437ローカルの man ページを参照してください。
43585438移植性のあるプログラムを書く場合は、伝統的な振る舞いを仮定するのが
43595439ベストです。
43605440(しかし移植性のないプログラムを書く場合は、自身のシステムの性癖(しばしば
43615441「仕様」と呼ばれます)に合わせて書くことも完全に自由です。
43625442盲目的に移植性に固執することで、あなたの作業を仕上げるのを邪魔するべきでは
43635443ありません。)
43645444
43655445=begin original
43665446
43675447OPERATION is one of LOCK_SH, LOCK_EX, or LOCK_UN, possibly combined with
43685448LOCK_NB. These constants are traditionally valued 1, 2, 8 and 4, but
43695449you can use the symbolic names if you import them from the L<Fcntl> module,
43705450either individually, or as a group using the C<:flock> tag. LOCK_SH
43715451requests a shared lock, LOCK_EX requests an exclusive lock, and LOCK_UN
43725452releases a previously requested lock. If LOCK_NB is bitwise-or'ed with
4373LOCK_SH or LOCK_EX, then C<flock> returns immediately rather than blocking
5453LOCK_SH or LOCK_EX, then L<C<flock>|/flock FILEHANDLE,OPERATION> returns
4374waiting for the lock; check the return status to see if you got it.
5454immediately rather than blocking waiting for the lock; check the return
5455status to see if you got it.
43755456
43765457=end original
43775458
43785459OPERATION は LOCK_SH, LOCK_EX, LOCK_UN のいずれかで、LOCK_NB と
43795460組み合わされることもあります。
43805461これらの定数は伝統的には 1, 2, 8, 4 の値を持ちますが、L<Fcntl> モジュールから
43815462シンボル名を独立してインポートするか、C<:flock> タグを使うグループとして、
43825463シンボル名をを使うことができます。
43835464LOCK_SH は共有ロックを要求し、LOCK_EX は排他ロックを要求し、LOCK_UN は
43845465前回要求したロックを開放します。
4385LOCK_NB と LOCK_SH か LOCK_EX がビット単位の論理和されると、C<flock> は
5466LOCK_NB と LOCK_SH か LOCK_EX がビット単位の論理和されると、
5467L<C<flock>|/flock FILEHANDLE,OPERATION> は
43865468ロックを取得するまで待つのではなく、すぐに返ります;
43875469ロックが取得できたかどうかは返り値を調べます。
43885470
43895471=begin original
43905472
43915473To avoid the possibility of miscoordination, Perl now flushes FILEHANDLE
43925474before locking or unlocking it.
43935475
43945476=end original
43955477
43965478不一致の可能性を避けるために、Perl はファイルをロック、アンロックする前に
43975479FILEHANDLE をフラッシュします。
43985480
43995481=begin original
44005482
4401Note that the emulation built with lockf(3) doesn't provide shared
5483Note that the emulation built with L<lockf(3)> doesn't provide shared
44025484locks, and it requires that FILEHANDLE be open with write intent. These
4403are the semantics that lockf(3) implements. Most if not all systems
5485are the semantics that L<lockf(3)> implements. Most if not all systems
4404implement lockf(3) in terms of fcntl(2) locking, though, so the
5486implement L<lockf(3)> in terms of L<fcntl(2)> locking, though, so the
44055487differing semantics shouldn't bite too many people.
44065488
44075489=end original
44085490
4409lockf(3) で作成されたエミュレーションは共有ロックを提供せず、
5491L<lockf(3)> で作成されたエミュレーションは共有ロックを提供せず、
44105492FILEHANDLE が書き込みモードで開いていることを必要とすることに
44115493注意してください。
4412これは lockf(3) が実装している動作です。
5494これは L<lockf(3)> が実装している動作です。
4413しかし、全てではないにしてもほとんどのシステムでは fcntl(2) を使って
5495しかし、全てではないにしてもほとんどのシステムでは L<fcntl(2)> を使って
4414lockf(3) を実装しているので、異なった動作で多くの人々を混乱させることは
5496L<lockf(3)> を実装しているので、異なった動作で多くの人々を混乱させることは
44155497ないはずです。
44165498
44175499=begin original
44185500
4419Note that the fcntl(2) emulation of flock(3) requires that FILEHANDLE
5501Note that the L<fcntl(2)> emulation of L<flock(3)> requires that FILEHANDLE
44205502be open with read intent to use LOCK_SH and requires that it be open
44215503with write intent to use LOCK_EX.
44225504
44235505=end original
44245506
4425flock(3) の fcntl(2) エミュレーションは、 LOCK_SH を使うためには
5507L<flock(3)>L<fcntl(2)> エミュレーションは、 LOCK_SH を使うためには
44265508FILEHANDLE を読み込みで開いている必要があり、LOCK_EX を使うためには
44275509書き込みで開いている必要があることに注意してください。
44285510
44295511=begin original
44305512
4431Note also that some versions of C<flock> cannot lock things over the
5513Note also that some versions of L<C<flock>|/flock FILEHANDLE,OPERATION>
4432network; you would need to use the more system-specific C<fcntl> for
5514cannot lock things over the network; you would need to use the more
4433that. If you like you can force Perl to ignore your system's flock(2)
5515system-specific L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> for
4434function, and so provide its own fcntl(2)-based emulation, by passing
5516that. If you like you can force Perl to ignore your system's L<flock(2)>
5517function, and so provide its own L<fcntl(2)>-based emulation, by passing
44355518the switch C<-Ud_flock> to the F<Configure> program when you configure
44365519and build a new Perl.
44375520
44385521=end original
44395522
4440ネットワーク越しにはロックできない C<flock> もあることに注意してください;
5523ネットワーク越しにはロックできない L<C<flock>|/flock FILEHANDLE,OPERATION>
4441のためは、よりシステム依存な C<fcntl> を使う必要があります。
5524ある注意してください;
4442Perl にシステムの flock(2) 関数を無視させ、自身の fcntl(2) ベースの
5525このためは、よりシステム依存な
5526L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> を使う必要があります。
5527Perl にシステムの L<flock(2)> 関数を無視させ、自身の L<fcntl(2)> ベースの
44435528エミュレーションを使う場合は、新しい Perl を設定およびビルドするときに
44445529F<Configure> プログラムに C<-Ud_flock> オプションを渡してください。
44455530
44465531=begin original
44475532
44485533Here's a mailbox appender for BSD systems.
44495534
44505535=end original
44515536
44525537BSD システムでのメールボックスへの追加処理の例を示します。
44535538
4454 use Fcntl qw(:flock SEEK_END); # import LOCK_* and SEEK_END constants
5539 # import LOCK_* and SEEK_END constants
5540 use Fcntl qw(:flock SEEK_END);
44555541
44565542 sub lock {
44575543 my ($fh) = @_;
44585544 flock($fh, LOCK_EX) or die "Cannot lock mailbox - $!\n";
44595545
44605546 # and, in case someone appended while we were waiting...
44615547 seek($fh, 0, SEEK_END) or die "Cannot seek - $!\n";
44625548 }
44635549
44645550 sub unlock {
44655551 my ($fh) = @_;
44665552 flock($fh, LOCK_UN) or die "Cannot unlock mailbox - $!\n";
44675553 }
44685554
44695555 open(my $mbox, ">>", "/usr/spool/mail/$ENV{'USER'}")
44705556 or die "Can't open mailbox: $!";
44715557
44725558 lock($mbox);
44735559 print $mbox $msg,"\n\n";
44745560 unlock($mbox);
44755561
44765562=begin original
44775563
4478On systems that support a real flock(2), locks are inherited across fork()
5564On systems that support a real L<flock(2)>, locks are inherited across
4479calls, whereas those that must resort to the more capricious fcntl(2)
5565L<C<fork>|/fork> calls, whereas those that must resort to the more
4480function lose their locks, making it seriously harder to write servers.
5566capricious L<fcntl(2)> function lose their locks, making it seriously
5567harder to write servers.
44815568
44825569=end original
44835570
4484真の flock(2) に対応しているシステムではロックは fork() を通して
5571真の L<flock(2)> に対応しているシステムではロックは L<C<fork>|/fork> を通して
4485継承されるのに対して、より不安定な fcntl(2) に頼らなければならない場合、
5572継承されるのに対して、より不安定な L<fcntl(2)> に頼らなければならない場合、
44865573サーバを書くのは本当により難しくなります。
44875574
44885575=begin original
44895576
4490See also L<DB_File> for other flock() examples.
5577See also L<DB_File> for other L<C<flock>|/flock FILEHANDLE,OPERATION>
5578examples.
44915579
44925580=end original
44935581
4494その他の flock() の例としては L<DB_File> も参照してください。
5582その他の L<C<flock>|/flock FILEHANDLE,OPERATION> の例としては L<DB_File> も
5583参照してください。
44955584
5585=begin original
5586
5587Portability issues: L<perlport/flock>.
5588
5589=end original
5590
5591移植性の問題: L<perlport/flock>。
5592
44965593=item fork
44975594X<fork> X<child> X<parent>
44985595
5596=for Pod::Functions create a new process just like this one
5597
44995598=begin original
45005599
4501Does a fork(2) system call to create a new process running the
5600Does a L<fork(2)> system call to create a new process running the
45025601same program at the same point. It returns the child pid to the
4503parent process, C<0> to the child process, or C<undef> if the fork is
5602parent process, C<0> to the child process, or L<C<undef>|/undef EXPR> if
5603the fork is
45045604unsuccessful. File descriptors (and sometimes locks on those descriptors)
45055605are shared, while everything else is copied. On most systems supporting
4506fork(), great care has gone into making it extremely efficient (for
5606L<fork(2)>, great care has gone into making it extremely efficient (for
45075607example, using copy-on-write technology on data pages), making it the
45085608dominant paradigm for multitasking over the last few decades.
45095609
45105610=end original
45115611
45125612同じプログラムの同じ地点から開始する新しいプロセスを作成するために
4513システムコール fork(2) を行ないます。
5613システムコール L<fork(2)> を行ないます。
45145614親プロセスには、チャイルドプロセスの pid を、
45155615チャイルドプロセスに C<0> を返しますが、
4516fork に失敗したときには、C<undef>を返します。
5616fork に失敗したときには、L<C<undef>|/undef EXPR>を返します。
45175617ファイル記述子(および記述子に関連するロック)は共有され、
45185618その他の全てはコピーされます。
4519fork() に対応するほとんどのシステムでは、
5619L<fork(2)> に対応するほとんどのシステムでは、
45205620これを極めて効率的にするために多大な努力が払われてきました
4521(例えば、データページへの copy-on-write テクノロジーなどです)
5621(例えば、データページへの copy-on-write テクノロジーなどです);
45225622これはここ 20 年にわたるマルチタスクに関する主要なパラダイムとなっています。
45235623
45245624=begin original
45255625
4526Beginning with v5.6.0, Perl attempts to flush all files opened for
5626Perl attempts to flush all files opened for output before forking the
4527output before forking the child process, but this may not be supported
5627child process, but this may not be supported on some platforms (see
4528on some platforms (see L<perlport>). To be safe, you may need to set
5628L<perlport>). To be safe, you may need to set
4529C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method of
5629L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>) or
4530C<IO::Handle> on any open handles to avoid duplicate output.
5630call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS> on
5631any open handles to avoid duplicate output.
45315632
45325633=end original
45335634
45345635v5.6.0 から、Perl は子プロセスを fork する前に出力用にオープンしている全ての
45355636ファイルをフラッシュしようとしますが、これに対応していないプラットフォームも
45365637あります(L<perlport> を参照してください)。
45375638安全のためには、出力が重複するのを避けるために、
4538全てのオープンしているハンドルに対して C<$|> (English モジュールでは
5639全てのオープンしているハンドルに対して L<C<$E<verbar>>|perlvar/$E<verbar>>
4539$AUTOFLUSH) を設定するか、
5640(L<English> モジュールでは C<$AUTOFLUSH>) を設定するか、
4540C<IO::Handle> モジュールの C<autoflush()>メソッドをを呼ぶ必要が
5641L<C<IO::Handle>|IO::Handle/METHODS> モジュールの C<autoflush> メソッドを
4541あるかもしれません。
5642呼ぶ必要があるかもしれません。
45425643
45435644=begin original
45445645
4545If you C<fork> without ever waiting on your children, you will
5646If you L<C<fork>|/fork> without ever waiting on your children, you will
45465647accumulate zombies. On some systems, you can avoid this by setting
4547C<$SIG{CHLD}> to C<"IGNORE">. See also L<perlipc> for more examples of
5648L<C<$SIG{CHLD}>|perlvar/%SIG> to C<"IGNORE">. See also L<perlipc> for
4548forking and reaping moribund children.
5649more examples of forking and reaping moribund children.
45495650
45505651=end original
45515652
4552チャイルドプロセスの終了を待たずに、C<fork> を繰り返せば、
5653チャイルドプロセスの終了を待たずに、L<C<fork>|/fork> を繰り返せば、
45535654ゾンビをためこむことになります。
4554C<$SIG{CHLD}> に C<"IGNORE"> を指定することでこれを回避できるシステムもあります。
5655L<C<$SIG{CHLD}>|perlvar/%SIG> に C<"IGNORE"> を指定することでこれを
5656回避できるシステムもあります。
45555657fork と消滅しかけている子プロセスを回収するための更なる例については
45565658L<perlipc> も参照してください。
45575659
45585660=begin original
45595661
45605662Note that if your forked child inherits system file descriptors like
45615663STDIN and STDOUT that are actually connected by a pipe or socket, even
45625664if you exit, then the remote server (such as, say, a CGI script or a
45635665backgrounded job launched from a remote shell) won't think you're done.
45645666You should reopen those to F</dev/null> if it's any issue.
45655667
45665668=end original
45675669
45685670fork した子プロセスが STDIN や STDOUT といったシステムファイル記述子を
45695671継承する場合、(CGI スクリプトやリモートシェルといった
45705672バックグラウンドジョブのような)リモートサーバは考え通りに
45715673動かないであろうことに注意してください。
45725674このような場合ではこれらを F</dev/null> として再オープンするべきです。
45735675
5676=begin original
5677
5678On some platforms such as Windows, where the L<fork(2)> system call is
5679not available, Perl can be built to emulate L<C<fork>|/fork> in the Perl
5680interpreter. The emulation is designed, at the level of the Perl
5681program, to be as compatible as possible with the "Unix" L<fork(2)>.
5682However it has limitations that have to be considered in code intended
5683to be portable. See L<perlfork> for more details.
5684
5685=end original
5686
5687Windows のような L<fork(2)> が利用不能なシステムでは、Perl は
5688L<C<fork>|/fork> を Perl インタプリタでエミュレートします。
5689エミュレーションは Perl プログラムのレベルではできるだけ "Unix" L<fork(2)> と
5690互換性があるように設計されています。
5691しかしコードが移植性があると考えられるように制限があります。
5692さらなる詳細については L<perlfork> を参照してください。
5693
5694=begin original
5695
5696Portability issues: L<perlport/fork>.
5697
5698=end original
5699
5700移植性の問題: L<perlport/fork>。
5701
45745702=item format
45755703X<format>
45765704
5705=for Pod::Functions declare a picture format with use by the write() function
5706
45775707=begin original
45785708
4579Declare a picture format for use by the C<write> function. For
5709Declare a picture format for use by the L<C<write>|/write FILEHANDLE>
4580example:
5710function. For example:
45815711
45825712=end original
45835713
4584C<write> 関数で使うピクチャーフォーマットを宣言します。
5714L<C<write>|/write FILEHANDLE> 関数で使うピクチャーフォーマットを宣言します。
4585例:
5715えば:
45865716
45875717 format Something =
45885718 Test: @<<<<<<<< @||||| @>>>>>
45895719 $str, $%, '$' . int($num)
45905720 .
45915721
45925722 $str = "widget";
45935723 $num = $cost/$quantity;
45945724 $~ = 'Something';
45955725 write;
45965726
45975727=begin original
45985728
45995729See L<perlform> for many details and examples.
46005730
46015731=end original
46025732
4603詳細と例については L<perlform> を参照してさい。
5733詳細と例については L<perlform> を参照してください。
46045734
46055735=item formline PICTURE,LIST
46065736X<formline>
46075737
5738=for Pod::Functions internal function used for formats
5739
46085740=begin original
46095741
4610This is an internal function used by C<format>s, though you may call it,
5742This is an internal function used by L<C<format>|/format>s, though you
4611too. It formats (see L<perlform>) a list of values according to the
5743may call it, too. It formats (see L<perlform>) a list of values
4612contents of PICTURE, placing the output into the format output
5744according to the contents of PICTURE, placing the output into the format
4613accumulator, C<$^A> (or C<$ACCUMULATOR> in English).
5745output accumulator, L<C<$^A>|perlvar/$^A> (or C<$ACCUMULATOR> in
4614Eventually, when a C<write> is done, the contents of
5746L<English>). Eventually, when a L<C<write>|/write FILEHANDLE> is done,
4615C<$^A> are written to some filehandle. You could also read C<$^A>
5747the contents of L<C<$^A>|perlvar/$^A> are written to some filehandle.
4616and then set C<$^A> back to C<"">. Note that a format typically
5748You could also read L<C<$^A>|perlvar/$^A> and then set
4617does one C<formline> per line of form, but the C<formline> function itself
5749L<C<$^A>|perlvar/$^A> back to C<"">. Note that a format typically does
4618doesn't care how many newlines are embedded in the PICTURE. This means
5750one L<C<formline>|/formline PICTURE,LIST> per line of form, but the
4619that the C<~> and C<~~> tokens treat the entire PICTURE as a single line.
5751L<C<formline>|/formline PICTURE,LIST> function itself doesn't care how
4620You may therefore need to use multiple formlines to implement a single
5752many newlines are embedded in the PICTURE. This means that the C<~> and
4621record format, just like the C<format> compiler.
5753C<~~> tokens treat the entire PICTURE as a single line. You may
5754therefore need to use multiple formlines to implement a single record
5755format, just like the L<C<format>|/format> compiler.
46225756
46235757=end original
46245758
4625これは、C<format> が使用する内部関数ですが、直接呼び出すこともできます。
5759これは、L<C<format>|/format> が使用する内部関数ですが、直接呼び出すことも
5760できます。
46265761これは、PICTURE の内容にしたがって、LIST の値を整形し (L<perlform> を
4627参照してください)、結果をフォーマット出力アキュムレータC<$^A>
5762参照してください)、結果をフォーマット出力アキュムレータL<C<$^A>|perlvar/$^A>
4628(English モジュールでは C<$ACCUMULATOR>) に納めます。
5763(L<English> モジュールでは C<$ACCUMULATOR>) に納めます。
4629最終的に、C<write> が実行されると、C<$^A> の中身が
5764最終的に、L<C<write>|/write FILEHANDLE> が実行されると、
4630何らかのファイルハンドルに書き出されます。
5765L<C<$^A>|perlvar/$^A> の中身が、何らかのファイルハンドルに書き出されます。
4631また、自分で C<$^A> を読んで、C<$^A> の内容を C<""> に戻してもかまいません。
5766また、自分で L<C<$^A>|perlvar/$^A> を読んで、L<C<$^A>|perlvar/$^A> の内容を
4632format は通常、1 行ごとに C<formline> を行ないますが、
5767C<""> に戻してもかまいません。
4633C<formline> 関数自身は、PICTURE の中にいくつの改行が入っているかは、
5768format は通常、1 行ごとに L<C<formline>|/formline PICTURE,LIST>
4634関係がありせん。
5769行ないすが、L<C<formline>|/formline PICTURE,LIST> 関数自身は、PICTURE の中に
5770いくつの改行が入っているかは、関係がありません。
46355771これは、C<~> と C<~~>トークンは PICTURE 全体を一行として扱うことを意味します。
46365772従って、1 レコードフォーマットを実装するためには
4637フォーマットコンパイラのような複数 formline を使う必要があります。
5773L<C<format>|/format> コンパイラのような複数 formline を使う必要があります。
46385774
46395775=begin original
46405776
46415777Be careful if you put double quotes around the picture, because an C<@>
46425778character may be taken to mean the beginning of an array name.
4643C<formline> always returns true. See L<perlform> for other examples.
5779L<C<formline>|/formline PICTURE,LIST> always returns true. See
5780L<perlform> for other examples.
46445781
46455782=end original
46465783
46475784ダブルクォートで PICTURE を囲む場合には、C<@> という文字が
46485785配列名の始まりと解釈されますので、注意してください。
4649C<formline> は常に真を返します。
5786L<C<formline>|/formline PICTURE,LIST> は常に真を返します。
46505787その他の例については L<perlform> を参照してください。
46515788
46525789=begin original
46535790
4654If you are trying to use this instead of C<write> to capture the output,
5791If you are trying to use this instead of L<C<write>|/write FILEHANDLE>
4655you may find it easier to open a filehandle to a scalar
5792to capture the output, you may find it easier to open a filehandle to a
4656(C<< open $fh, ">", \$output >>) and write to that instead.
5793scalar (C<< open my $fh, ">", \$output >>) and write to that instead.
46575794
46585795=end original
46595796
4660出力を捕捉するために C<write> の代わりにこれを使おうとした場合、
5797出力を捕捉するために L<C<write>|/write FILEHANDLE> の代わりにこれを
4661スカラにファイルハンドルを開いて (C<< open $fh, ">", \$output >>)、
5798使おうとした場合、スカラにファイルハンドルを開いて
5799(C<< open my $fh, ">", \$output >>)、
46625800代わりにここに出力する方が簡単であることに気付くでしょう。
46635801
46645802=item getc FILEHANDLE
46655803X<getc> X<getchar> X<character> X<file, read>
46665804
46675805=item getc
46685806
5807=for Pod::Functions get the next character from the filehandle
5808
46695809=begin original
46705810
46715811Returns the next character from the input file attached to FILEHANDLE,
46725812or the undefined value at end of file or if there was an error (in
4673the latter case C<$!> is set). If FILEHANDLE is omitted, reads from
5813the latter case L<C<$!>|perlvar/$!> is set). If FILEHANDLE is omitted,
5814reads from
46745815STDIN. This is not particularly efficient. However, it cannot be
46755816used by itself to fetch single characters without waiting for the user
46765817to hit enter. For that, try something more like:
46775818
46785819=end original
46795820
4680FILEHANDLE につながれている入力ファイルから、次の一文字を返します
5821FILEHANDLE につながれている入力ファイルから、次の一文字を返します;
46815822ファイルの最後、またはエラーが発生した場合は、未定義値を返します
4682(後者の場合は C<$!> がセットされます)。
5823(後者の場合は L<C<$!>|perlvar/$!> がセットされます)。
46835824FILEHANDLE が省略された場合には、STDIN から読み込みを行ないます。
46845825これは特に効率的ではありません。
46855826しかし、これはユーザーがリターンキーを押すのを待つことなく
46865827一文字を読み込む用途には使えません。
46875828そのような場合には、以下のようなものを試して見てください:
46885829
46895830 if ($BSD_STYLE) {
46905831 system "stty cbreak </dev/tty >/dev/tty 2>&1";
46915832 }
46925833 else {
46935834 system "stty", '-icanon', 'eol', "\001";
46945835 }
46955836
4696 $key = getc(STDIN);
5837 my $key = getc(STDIN);
46975838
46985839 if ($BSD_STYLE) {
46995840 system "stty -cbreak </dev/tty >/dev/tty 2>&1";
47005841 }
47015842 else {
47025843 system 'stty', 'icanon', 'eol', '^@'; # ASCII NUL
47035844 }
47045845 print "\n";
47055846
47065847=begin original
47075848
4708Determination of whether $BSD_STYLE should be set
5849Determination of whether C<$BSD_STYLE> should be set is left as an
4709is left as an exercise to the reader.
5850exercise to the reader.
47105851
47115852=end original
47125853
4713$BSD_STYLE をセットするべきかどうかを決定する方法については
5854C<$BSD_STYLE> をセットするべきかどうかを決定する方法については
47145855読者への宿題として残しておきます。
47155856
47165857=begin original
47175858
4718The C<POSIX::getattr> function can do this more portably on
5859The L<C<POSIX::getattr>|POSIX/C<getattr>> function can do this more
4719systems purporting POSIX compliance. See also the C<Term::ReadKey>
5860portably on systems purporting POSIX compliance. See also the
4720module from your nearest CPAN site; details on CPAN can be found under
5861L<C<Term::ReadKey>|Term::ReadKey> module on CPAN.
4721L<perlmodlib/CPAN>.
47225862
47235863=end original
47245864
4725C<POSIX::getattr> 関数は POSIX 準拠を主張するシステムでこれを
5865L<C<POSIX::getattr>|POSIX/C<getattr>> 関数は POSIX 準拠を主張するシステムで
4726より移植性のある形で行います。
5866これをより移植性のある形で行います。
4727お近くの CPAN サイトから C<Term::ReadKey> モジュールも参照して下さい;
5867CPAN にある L<C<Term::ReadKey>|Term::ReadKey> モジュールも
4728CPAN に関する詳細は L<perlmodlib/CPAN> にあります
5868参照してください
47295869
47305870=item getlogin
47315871X<getlogin> X<login>
47325872
5873=for Pod::Functions return who logged in at this tty
5874
47335875=begin original
47345876
47355877This implements the C library function of the same name, which on most
47365878systems returns the current login from F</etc/utmp>, if any. If it
4737returns the empty string, use C<getpwuid>.
5879returns the empty string, use L<C<getpwuid>|/getpwuid UID>.
47385880
47395881=end original
47405882
47415883これは同じ名前の C ライブラリ関数を実装していて、
4742多くのシステムでは、もしあれば、/etc/utmp から現在のログイン名を返します。
5884多くのシステムでは、もしあれば、F</etc/utmp> から現在のログイン名を返します。
4743もし空文字列が返ってきた場合は、getpwuid()使ってください。
5885もし空文字列が返ってきた場合は、L<C<getpwuid>|/getpwuid UID>
5886使ってください。
47445887
4745 $login = getlogin || getpwuid($<) || "Kilroy";
5888 my $login = getlogin || getpwuid($<) || "Kilroy";
47465889
47475890=begin original
47485891
4749Do not consider C<getlogin> for authentication: it is not as
5892Do not consider L<C<getlogin>|/getlogin> for authentication: it is not
4750secure as C<getpwuid>.
5893as secure as L<C<getpwuid>|/getpwuid UID>.
47515894
47525895=end original
47535896
4754C<getlogin> を認証に使ってはいけません
5897L<C<getlogin>|/getlogin> を認証に使ってはいけません: これは
4755これは C<getpwuid> のように安全ではありません。
5898L<C<getpwuid>|/getpwuid UID> のように安全ではありません。
47565899
5900=begin original
5901
5902Portability issues: L<perlport/getlogin>.
5903
5904=end original
5905
5906移植性の問題: L<perlport/getlogin>。
5907
47575908=item getpeername SOCKET
47585909X<getpeername> X<peer>
47595910
5911=for Pod::Functions find the other end of a socket connection
5912
47605913=begin original
47615914
47625915Returns the packed sockaddr address of the other end of the SOCKET
47635916connection.
47645917
47655918=end original
47665919
47675920SOCKET コネクションの向こう側のパックされた aockaddr アドレスを返します。
47685921
47695922 use Socket;
4770 $hersockaddr = getpeername(SOCK);
5923 my $hersockaddr = getpeername($sock);
4771 ($port, $iaddr) = sockaddr_in($hersockaddr);
5924 my ($port, $iaddr) = sockaddr_in($hersockaddr);
4772 $herhostname = gethostbyaddr($iaddr, AF_INET);
5925 my $herhostname = gethostbyaddr($iaddr, AF_INET);
4773 $herstraddr = inet_ntoa($iaddr);
5926 my $herstraddr = inet_ntoa($iaddr);
47745927
47755928=item getpgrp PID
47765929X<getpgrp> X<group>
47775930
5931=for Pod::Functions get process group
5932
47785933=begin original
47795934
47805935Returns the current process group for the specified PID. Use
47815936a PID of C<0> to get the current process group for the
47825937current process. Will raise an exception if used on a machine that
4783doesn't implement getpgrp(2). If PID is omitted, returns the process
5938doesn't implement L<getpgrp(2)>. If PID is omitted, returns the process
4784group of the current process. Note that the POSIX version of C<getpgrp>
5939group of the current process. Note that the POSIX version of
4785does not accept a PID argument, so only C<PID==0> is truly portable.
5940L<C<getpgrp>|/getpgrp PID> does not accept a PID argument, so only
5941C<PID==0> is truly portable.
47865942
47875943=end original
47885944
47895945指定された PID の現在のプロセスグループを返します。
47905946PID に C<0> を与えるとカレントプロセスの指定となります。
4791getpgrp(2) を実装していないマシンで実行した場合には、例外が発生します。
5947L<getpgrp(2)> を実装していないマシンで実行した場合には、例外が発生します。
47925948PID を省略するとカレントプロセスのプロセスグループを返します。
4793POSIX 版の C<getpgrp> は PID 引数を受け付けないので、
5949POSIX 版の L<C<getpgrp>|/getpgrp PID> は PID 引数を受け付けないので、
47945950C<PID==0> のみが完全に移植性があります。
47955951
5952=begin original
5953
5954Portability issues: L<perlport/getpgrp>.
5955
5956=end original
5957
5958移植性の問題: L<perlport/getpgrp>。
5959
47965960=item getppid
47975961X<getppid> X<parent> X<pid>
47985962
5963=for Pod::Functions get parent process ID
5964
47995965=begin original
48005966
48015967Returns the process id of the parent process.
48025968
48035969=end original
48045970
48055971親プロセスのプロセス id を返します。
48065972
48075973=begin original
48085974
4809Note for Linux users: on Linux, the C functions C<getpid()> and
5975Note for Linux users: Between v5.8.1 and v5.16.0 Perl would work
4810C<getppid()> return different values from different threads. In order to
5976around non-POSIX thread semantics the minority of Linux systems (and
4811be portable, this behavior is not reflected by the Perl-level function
5977Debian GNU/kFreeBSD systems) that used LinuxThreads, this emulation
4812C<getppid()>, that returns a consistent value across threads. If you want
5978has since been removed. See the documentation for L<$$|perlvar/$$> for
4813to call the underlying C<getppid()>, you may use the CPAN module
5979details.
4814C<Linux::Pid>.
48155980
48165981=end original
48175982
4818Linux ユーザーへの注意: Linux では C<getpid()> C<getppid()> の C 関数
5983Linux ユーザーへの注意: v5.8.1 から v5.16.0 の間 Perl
4819スレッドが異なと異った値を返します。
5984LinuxThreads という非 POSIX なスレッド文法を使っていマイナー
4820移植性のために、この振る舞いは Perl レベルの関数 C<getppid()>
5985Linux システム (および Debian GNU/kFreeBSD システム) に対応していました。
4821反映されず、スレッドをたいで一貫性のある値を返ます。
5986このエミュレーションは削除されました;
4822基礎となる C<getppid()> を呼び出場合は、CPAN モジュールである
5987詳しくは L<$$|perlvar/$$> の文書参照てくださ
4823C<Linux::Pid> を使ってください。
48245988
5989=begin original
5990
5991Portability issues: L<perlport/getppid>.
5992
5993=end original
5994
5995移植性の問題: L<perlport/getppid>。
5996
48255997=item getpriority WHICH,WHO
48265998X<getpriority> X<priority> X<nice>
48275999
6000=for Pod::Functions get current nice value
6001
48286002=begin original
48296003
48306004Returns the current priority for a process, a process group, or a user.
4831(See C<getpriority(2)>.) Will raise a fatal exception if used on a
6005(See L<getpriority(2)>.) Will raise a fatal exception if used on a
4832machine that doesn't implement getpriority(2).
6006machine that doesn't implement L<getpriority(2)>.
48336007
48346008=end original
48356009
48366010プロセス、プロセスグループ、ユーザに対する現在の優先度を返します。
4837(C<getpriority(2)> を参照してください。)
6011(L<getpriority(2)> を参照してください。)
4838getpriority(2) を実装していない
6012L<getpriority(2)> を実装していない
48396013マシンで実行した場合には、致命的例外が発生します。
48406014
6015=begin original
6016
6017Portability issues: L<perlport/getpriority>.
6018
6019=end original
6020
6021移植性の問題: L<perlport/getpriority>。
6022
48416023=item getpwnam NAME
48426024X<getpwnam> X<getgrnam> X<gethostbyname> X<getnetbyname> X<getprotobyname>
48436025X<getpwuid> X<getgrgid> X<getservbyname> X<gethostbyaddr> X<getnetbyaddr>
48446026X<getprotobynumber> X<getservbyport> X<getpwent> X<getgrent> X<gethostent>
48456027X<getnetent> X<getprotoent> X<getservent> X<setpwent> X<setgrent> X<sethostent>
48466028X<setnetent> X<setprotoent> X<setservent> X<endpwent> X<endgrent> X<endhostent>
4847X<endnetent> X<endprotoent> X<endservent>
6029X<endnetent> X<endprotoent> X<endservent>
48486030
6031=for Pod::Functions get passwd record given user login name
6032
48496033=item getgrnam NAME
48506034
6035=for Pod::Functions get group record given group name
6036
48516037=item gethostbyname NAME
48526038
6039=for Pod::Functions get host record given name
6040
48536041=item getnetbyname NAME
48546042
6043=for Pod::Functions get networks record given name
6044
48556045=item getprotobyname NAME
48566046
6047=for Pod::Functions get protocol record given name
6048
48576049=item getpwuid UID
48586050
6051=for Pod::Functions get passwd record given user ID
6052
48596053=item getgrgid GID
48606054
6055=for Pod::Functions get group record given group user ID
6056
48616057=item getservbyname NAME,PROTO
48626058
6059=for Pod::Functions get services record given its name
6060
48636061=item gethostbyaddr ADDR,ADDRTYPE
48646062
6063=for Pod::Functions get host record given its address
6064
48656065=item getnetbyaddr ADDR,ADDRTYPE
48666066
6067=for Pod::Functions get network record given its address
6068
48676069=item getprotobynumber NUMBER
48686070
6071=for Pod::Functions get protocol record numeric protocol
6072
48696073=item getservbyport PORT,PROTO
48706074
6075=for Pod::Functions get services record given numeric port
6076
48716077=item getpwent
48726078
6079=for Pod::Functions get next passwd record
6080
48736081=item getgrent
48746082
6083=for Pod::Functions get next group record
6084
48756085=item gethostent
48766086
6087=for Pod::Functions get next hosts record
6088
48776089=item getnetent
48786090
6091=for Pod::Functions get next networks record
6092
48796093=item getprotoent
48806094
6095=for Pod::Functions get next protocols record
6096
48816097=item getservent
48826098
6099=for Pod::Functions get next services record
6100
48836101=item setpwent
48846102
6103=for Pod::Functions prepare passwd file for use
6104
48856105=item setgrent
48866106
6107=for Pod::Functions prepare group file for use
6108
48876109=item sethostent STAYOPEN
48886110
6111=for Pod::Functions prepare hosts file for use
6112
48896113=item setnetent STAYOPEN
48906114
6115=for Pod::Functions prepare networks file for use
6116
48916117=item setprotoent STAYOPEN
48926118
6119=for Pod::Functions prepare protocols file for use
6120
48936121=item setservent STAYOPEN
48946122
6123=for Pod::Functions prepare services file for use
6124
48956125=item endpwent
48966126
6127=for Pod::Functions be done using passwd file
6128
48976129=item endgrent
48986130
6131=for Pod::Functions be done using group file
6132
48996133=item endhostent
49006134
6135=for Pod::Functions be done using hosts file
6136
49016137=item endnetent
49026138
6139=for Pod::Functions be done using networks file
6140
49036141=item endprotoent
49046142
6143=for Pod::Functions be done using protocols file
6144
49056145=item endservent
49066146
6147=for Pod::Functions be done using services file
6148
49076149=begin original
49086150
49096151These routines are the same as their counterparts in the
49106152system C library. In list context, the return values from the
49116153various get routines are as follows:
49126154
49136155=end original
49146156
49156157これらのルーチンは、システムの C ライブラリの同名の関数と同じです。
49166158リストコンテキストでは、さまざまな
49176159get ルーチンからの返り値は、次のようになります:
49186160
4919 ($name,$passwd,$uid,$gid,
6161 # 0 1 2 3 4
4920 $quota,$comment,$gcos,$dir,$shell,$expire) = getpw*
6162 my ( $name, $passwd, $gid, $members ) = getgr*
4921 ($name,$passwd,$gid,$members) = getgr*
6163 my ( $name, $aliases, $addrtype, $net ) = getnet*
4922 ($name,$aliases,$addrtype,$length,@addrs) = gethost*
6164 my ( $name, $aliases, $port, $proto ) = getserv*
4923 ($name,$aliases,$addrtype,$net) = getnet*
6165 my ( $name, $aliases, $proto ) = getproto*
4924 ($name,$aliases,$proto) = getproto*
6166 my ( $name, $aliases, $addrtype, $length, @addrs ) = gethost*
4925 ($name,$aliases,$port,$proto) = getserv*
6167 my ( $name, $passwd, $uid, $gid, $quota,
6168 $comment, $gcos, $dir, $shell, $expire ) = getpw*
6169 # 5 6 7 8 9
49266170
49276171=begin original
49286172
4929(If the entry doesn't exist you get an empty list.)
6173(If the entry doesn't exist, the return value is a single meaningless true
6174value.)
49306175
49316176=end original
49326177
4933(エントリが存在しなければ、空リストがされます。)
6178(エントリが存在しなければ、返り値は単一の意味のない真の値です。)
49346179
49356180=begin original
49366181
49376182The exact meaning of the $gcos field varies but it usually contains
49386183the real name of the user (as opposed to the login name) and other
49396184information pertaining to the user. Beware, however, that in many
49406185system users are able to change this information and therefore it
49416186cannot be trusted and therefore the $gcos is tainted (see
49426187L<perlsec>). The $passwd and $shell, user's encrypted password and
49436188login shell, are also tainted, for the same reason.
49446189
49456190=end original
49466191
49476192$gcos フィールドの正確な意味はさまざまですが、通常は(ログイン名ではなく)
49486193ユーザーの実際の名前とユーザーに付随する情報を含みます。
49496194但し、多くのシステムではユーザーがこの情報を変更できるので、この情報は
49506195信頼できず、従って $gcos は汚染されます(L<perlsec> を参照してください)。
49516196ユーザーの暗号化されたパスワードとログインシェルである $passwd と
49526197$shell も、同様の理由で汚染されます。
49536198
49546199=begin original
49556200
49566201In scalar context, you get the name, unless the function was a
49576202lookup by name, in which case you get the other thing, whatever it is.
49586203(If the entry doesn't exist you get the undefined value.) For example:
49596204
49606205=end original
49616206
49626207スカラコンテキストでは、*nam、*byname といった NAME で検索するもの以外は、
49636208name を返し、NAME で検索するものは、何か別のものを返します。
49646209(エントリが存在しなければ、未定義値が返ります。)
4965例:
6210えば:
49666211
4967 $uid = getpwnam($name);
6212 my $uid = getpwnam($name);
4968 $name = getpwuid($num);
6213 my $name = getpwuid($num);
4969 $name = getpwent();
6214 my $name = getpwent();
4970 $gid = getgrnam($name);
6215 my $gid = getgrnam($name);
4971 $name = getgrgid($num);
6216 my $name = getgrgid($num);
4972 $name = getgrent();
6217 my $name = getgrent();
4973 #etc.
6218 <#ins> etc.
49746219
49756220=begin original
49766221
49776222In I<getpw*()> the fields $quota, $comment, and $expire are special
49786223in that they are unsupported on many systems. If the
49796224$quota is unsupported, it is an empty scalar. If it is supported, it
49806225usually encodes the disk quota. If the $comment field is unsupported,
49816226it is an empty scalar. If it is supported it usually encodes some
49826227administrative comment about the user. In some systems the $quota
49836228field may be $change or $age, fields that have to do with password
49846229aging. In some systems the $comment field may be $class. The $expire
49856230field, if present, encodes the expiration period of the account or the
49866231password. For the availability and the exact meaning of these fields
4987in your system, please consult getpwnam(3) and your system's
6232in your system, please consult L<getpwnam(3)> and your system's
49886233F<pwd.h> file. You can also find out from within Perl what your
49896234$quota and $comment fields mean and whether you have the $expire field
4990by using the C<Config> module and the values C<d_pwquota>, C<d_pwage>,
6235by using the L<C<Config>|Config> module and the values C<d_pwquota>, C<d_pwage>,
49916236C<d_pwchange>, C<d_pwcomment>, and C<d_pwexpire>. Shadow password
49926237files are supported only if your vendor has implemented them in the
49936238intuitive fashion that calling the regular C library routines gets the
49946239shadow versions if you're running under privilege or if there exists
4995the shadow(3) functions as found in System V (this includes Solaris
6240the L<shadow(3)> functions as found in System V (this includes Solaris
49966241and Linux). Those systems that implement a proprietary shadow password
49976242facility are unlikely to be supported.
49986243
49996244=end original
50006245
50016246I<getpw*()> では、$quota, $comment, $expire フィールドは、
50026247多くのシステムでは対応していないので特別な処理がされます。
50036248$quota が非対応の場合、空のスカラになります。
50046249対応している場合、通常はディスククォータの値が入ります。
50056250$comment フィールドが非対応の場合、空のスカラになります。
50066251対応している場合、通常はユーザーに関する管理上のコメントが入ります。
50076252$quota フィールドはパスワードの寿命を示す $change や $age である
50086253システムもあります。
50096254$comment フィールドは $class であるシステムもあります。
50106255$expire フィールドがある場合は、アカウントやパスワードが時間切れになる
50116256期間が入ります。
50126257動作させるシステムでのこれらのフィールドの有効性と正確な意味については、
5013getpwnam(3) のドキュメントと F<pwd.h> ファイルを参照してください。
6258L<getpwnam(3)> のドキュメントと F<pwd.h> ファイルを参照してください。
50146259$quota と $comment フィールドが何を意味しているかと、$expire フィールドが
5015あるかどうかは、C<Config> モジュールを使って、C<d_pwquota>, C<d_pwage>,
6260あるかどうかは、L<C<Config>|Config> モジュールを使って、C<d_pwquota>,
5016C<d_pwchange>, C<d_pwcomment>, C<d_pwexpire> の値を調べることによって
6261C<d_pwage>, C<d_pwchange>, C<d_pwcomment>, C<d_pwexpire> の値を
5017Perl 自身で調べることも出来ます。
6262調べることによって Perl 自身で調べることも出来ます。
50186263シャドウパスワードは、通常の C ライブラリルーチンを権限がある状態で
50196264呼び出すことでシャドウ版が取得できるか、System V にあるような
5020(Solaris と Linux を含みます) shadow(3) 関数があるといった、
6265(Solaris と Linux を含みます) L<shadow(3)> 関数があるといった、
50216266直感的な方法で実装されている場合にのみ対応されます。
50226267独占的なシャドウパスワード機能を実装しているシステムでは、
50236268それに対応されることはないでしょう。
50246269
50256270=begin original
50266271
50276272The $members value returned by I<getgr*()> is a space-separated list of
50286273the login names of the members of the group.
50296274
50306275=end original
50316276
50326277I<getgr*()> によって返る値 $members は、グループのメンバの
50336278ログイン名をスペースで区切ったものです。
50346279
50356280=begin original
50366281
50376282For the I<gethost*()> functions, if the C<h_errno> variable is supported in
5038C, it will be returned to you via C<$?> if the function call fails. The
6283C, it will be returned to you via L<C<$?>|perlvar/$?> if the function
6284call fails. The
50396285C<@addrs> value returned by a successful call is a list of raw
50406286addresses returned by the corresponding library call. In the
50416287Internet domain, each address is four bytes long; you can unpack it
50426288by saying something like:
50436289
50446290=end original
50456291
50466292I<gethost*()> 関数では、C で C<h_errno> 変数がサポートされていれば、
5047関数呼出が失敗したときに、C<$?> を通して、その値が返されます。
6293関数呼出が失敗したときに、L<C<$?>|perlvar/$?> を通して、その値が返されます。
50486294成功時に返される C<@addrs> 値は、対応するシステムコールが返す、
50496295生のアドレスのリストです。
50506296インターネットドメインでは、個々のアドレスは、4 バイト長です;
50516297以下のようにして unpack することができます:
50526298
5053 ($a,$b,$c,$d) = unpack('W4',$addr[0]);
6299 my ($w,$x,$y,$z) = unpack('W4',$addr[0]);
50546300
50556301=begin original
50566302
50576303The Socket library makes this slightly easier:
50586304
50596305=end original
50606306
50616307Socket ライブラリを使うともう少し簡単になります。
50626308
50636309 use Socket;
5064 $iaddr = inet_aton("127.1"); # or whatever address
6310 my $iaddr = inet_aton("127.1"); # or whatever address
5065 $name = gethostbyaddr($iaddr, AF_INET);
6311 my $name = gethostbyaddr($iaddr, AF_INET);
50666312
50676313 # or going the other way
5068 $straddr = inet_ntoa($iaddr);
6314 my $straddr = inet_ntoa($iaddr);
50696315
50706316=begin original
50716317
50726318In the opposite way, to resolve a hostname to the IP address
50736319you can write this:
50746320
50756321=end original
50766322
50776323逆方向に、ホスト名から IP アドレスを解決するには以下のように書けます:
50786324
50796325 use Socket;
5080 $packed_ip = gethostbyname("www.perl.org");
6326 my $packed_ip = gethostbyname("www.perl.org");
6327 my $ip_address;
50816328 if (defined $packed_ip) {
50826329 $ip_address = inet_ntoa($packed_ip);
50836330 }
50846331
50856332=begin original
50866333
5087Make sure <gethostbyname()> is called in SCALAR context and that
6334Make sure L<C<gethostbyname>|/gethostbyname NAME> is called in SCALAR
5088its return value is checked for definedness.
6335context and that its return value is checked for definedness.
50896336
50906337=end original
50916338
5092C<gethostbyname()> はスカラコンテキストで呼び出すようにして、返り値が
6339L<C<gethostbyname>|/gethostbyname NAME> はスカラコンテキストで
5093定義されているかを必ずチェックしてください。
6340呼び出すようにして、返り値が定義されているかを必ずチェックしてください。
50946341
50956342=begin original
50966343
6344The L<C<getprotobynumber>|/getprotobynumber NUMBER> function, even
6345though it only takes one argument, has the precedence of a list
6346operator, so beware:
6347
6348=end original
6349
6350L<C<getprotobynumber>|/getprotobynumber NUMBER> 関数は、一つの引数しか
6351取らないにも関わらず、リスト演算子の優先順位を持ちます; 従って
6352注意してください:
6353
6354 getprotobynumber $number eq 'icmp' # WRONG
6355 getprotobynumber($number eq 'icmp') # actually means this
6356 getprotobynumber($number) eq 'icmp' # better this way
6357
6358=begin original
6359
50976360If you get tired of remembering which element of the return list
5098contains which return value, by-name interfaces are provided
6361contains which return value, by-name interfaces are provided in standard
5099in standard modules: C<File::stat>, C<Net::hostent>, C<Net::netent>,
6362modules: L<C<File::stat>|File::stat>, L<C<Net::hostent>|Net::hostent>,
5100C<Net::protoent>, C<Net::servent>, C<Time::gmtime>, C<Time::localtime>,
6363L<C<Net::netent>|Net::netent>, L<C<Net::protoent>|Net::protoent>,
5101and C<User::grent>. These override the normal built-ins, supplying
6364L<C<Net::servent>|Net::servent>, L<C<Time::gmtime>|Time::gmtime>,
5102versions that return objects with the appropriate names
6365L<C<Time::localtime>|Time::localtime>, and
5103for each field. For example:
6366L<C<User::grent>|User::grent>. These override the normal built-ins,
6367supplying versions that return objects with the appropriate names for
6368each field. For example:
51046369
51056370=end original
51066371
51076372返り値のリストの何番目がどの要素かを覚えるのに疲れたなら、
51086373名前ベースのインターフェースが標準モジュールで提供されています:
5109C<File::stat>, C<Net::hostent>, C<Net::netent>,
6374L<C<File::stat>|File::stat>, L<C<Net::hostent>|Net::hostent>,
5110C<Net::protoent>, C<Net::servent>, C<Time::gmtime>, C<Time::localtime>,
6375L<C<Net::netent>|Net::netent>, L<C<Net::protoent>|Net::protoent>,
5111C<User::grent> です。
6376L<C<Net::servent>|Net::servent>, L<C<Time::gmtime>|Time::gmtime>,
6377L<C<Time::localtime>|Time::localtime>,
6378L<C<User::grent>|User::grent> です。
51126379これらは通常の組み込みを上書きし、
51136380それぞれのフィールドに適切な名前をつけたオブジェクトを返します。
5114例:
6381えば:
51156382
51166383 use File::stat;
51176384 use User::pwent;
5118 $is_his = (stat($filename)->uid == pwent($whoever)->uid);
6385 my $is_his = (stat($filename)->uid == pwent($whoever)->uid);
51196386
51206387=begin original
51216388
51226389Even though it looks as though they're the same method calls (uid),
51236390they aren't, because a C<File::stat> object is different from
51246391a C<User::pwent> object.
51256392
51266393=end original
51276394
5128同じメソッド(uid)を呼び出しているように見えますが、違います
6395同じメソッド(uid)を呼び出しているように見えますが、違います;
51296396なぜなら C<File::stat> オブジェクトは C<User::pwent> オブジェクトとは
51306397異なるからです。
51316398
6399=begin original
6400
6401Portability issues: L<perlport/getpwnam> to L<perlport/endservent>.
6402
6403=end original
6404
6405移植性の問題: L<perlport/getpwnam> から L<perlport/endservent>。
6406
51326407=item getsockname SOCKET
51336408X<getsockname>
51346409
6410=for Pod::Functions retrieve the sockaddr for a given socket
6411
51356412=begin original
51366413
51376414Returns the packed sockaddr address of this end of the SOCKET connection,
51386415in case you don't know the address because you have several different
51396416IPs that the connection might have come in on.
51406417
51416418=end original
51426419
5143SOCKET 接続のこちら側の pack された sockaddr アドレスを返します
6420SOCKET 接続のこちら側の pack された sockaddr アドレスを返します;
51446421複数の異なる IP から接続されるためにアドレスがわからない場合に使います。
51456422
51466423 use Socket;
5147 $mysockaddr = getsockname(SOCK);
6424 my $mysockaddr = getsockname($sock);
5148 ($port, $myaddr) = sockaddr_in($mysockaddr);
6425 my ($port, $myaddr) = sockaddr_in($mysockaddr);
51496426 printf "Connect to %s [%s]\n",
51506427 scalar gethostbyaddr($myaddr, AF_INET),
51516428 inet_ntoa($myaddr);
51526429
51536430=item getsockopt SOCKET,LEVEL,OPTNAME
51546431X<getsockopt>
51556432
6433=for Pod::Functions get socket options on a given socket
6434
51566435=begin original
51576436
51586437Queries the option named OPTNAME associated with SOCKET at a given LEVEL.
51596438Options may exist at multiple protocol levels depending on the socket
51606439type, but at least the uppermost socket level SOL_SOCKET (defined in the
5161C<Socket> module) will exist. To query options at another level the
6440L<C<Socket>|Socket> module) will exist. To query options at another
5162protocol number of the appropriate protocol controlling the option
6441level the protocol number of the appropriate protocol controlling the
5163should be supplied. For example, to indicate that an option is to be
6442option should be supplied. For example, to indicate that an option is
5164interpreted by the TCP protocol, LEVEL should be set to the protocol
6443to be interpreted by the TCP protocol, LEVEL should be set to the
5165number of TCP, which you can get using C<getprotobyname>.
6444protocol number of TCP, which you can get using
6445L<C<getprotobyname>|/getprotobyname NAME>.
51666446
51676447=end original
51686448
51696449与えられた LEVEL で SOCKET に関連付けられた OPTNAME と言う名前のオプションを
51706450問い合わせます。
51716451オプションはソケットの種類に依存しした複数のプロトコルレベルに存在することも
5172ありますが、少なくとも最上位ソケットレベル SOL_SOCKET (C<Socket> モジュールで
6452ありますが、少なくとも最上位ソケットレベル SOL_SOCKET
5173定義されています)は存在します。
6453(L<C<Socket>|Socket> モジュールで定義されています)は存在します。
51746454その他のレベルのオプションを問い合わせるには、そのオプションを制御する
51756455適切なプロトコルのプロトコル番号を指定します。
51766456例えば、オプションが TCP プロトコルで解釈されるべきであることを示すためには、
5177LEVEL は C<getprotobyname> で得られる TCP のプロトコル番号を設定します。
6457LEVEL は L<C<getprotobyname>|/getprotobyname NAME> で得られる TCP の
6458プロトコル番号を設定します。
51786459
51796460=begin original
51806461
51816462The function returns a packed string representing the requested socket
5182option, or C<undef> on error, with the reason for the error placed in
6463option, or L<C<undef>|/undef EXPR> on error, with the reason for the
5183C<$!>. Just what is in the packed string depends on LEVEL and OPTNAME;
6464error placed in L<C<$!>|perlvar/$!>. Just what is in the packed string
5184consult getsockopt(2) for details. A common case is that the option is an
6465depends on LEVEL and OPTNAME; consult L<getsockopt(2)> for details. A
5185integer, in which case the result is a packed integer, which you can decode
6466common case is that the option is an integer, in which case the result
5186using C<unpack> with the C<i> (or C<I>) format.
6467is a packed integer, which you can decode using
6468L<C<unpack>|/unpack TEMPLATE,EXPR> with the C<i> (or C<I>) format.
51876469
51886470=end original
51896471
51906472この関数は、要求されたソケットオプションの pack された文字列表現か、
5191あるいはエラーの場合は C<undef> を返し、エラーの理由は C<$!> にあります。
6473あるいはエラーの場合は L<C<undef>|/undef EXPR> を返し、エラーの理由は
6474L<C<$!>|perlvar/$!> にあります。
51926475pack された文字列の中身は LEVEL と OPTNAME に依存します;
5193詳細については getsockopt(2) を確認してください。
6476詳細については L<getsockopt(2)> を確認してください。
5194一般的な場合はオプションが整数の場合で、この場合結果は C<unpack> の C<i>
6477一般的な場合はオプションが整数の場合で、この場合結果は
6478L<C<unpack>|/unpack TEMPLATE,EXPR> の C<i>
51956479(あるいは C<I>)フォーマットでデコードできる pack された整数です。
51966480
51976481=begin original
51986482
51996483Here's an example to test whether Nagle's algorithm is enabled on a socket:
52006484
52016485=end original
52026486
52036487あるソケットで Nagle のアルゴリズム有効かどうかを調べる例です:
52046488
52056489 use Socket qw(:all);
52066490
52076491 defined(my $tcp = getprotobyname("tcp"))
52086492 or die "Could not determine the protocol number for tcp";
52096493 # my $tcp = IPPROTO_TCP; # Alternative
52106494 my $packed = getsockopt($socket, $tcp, TCP_NODELAY)
52116495 or die "getsockopt TCP_NODELAY: $!";
52126496 my $nodelay = unpack("I", $packed);
5213 print "Nagle's algorithm is turned ", $nodelay ? "off\n" : "on\n";
6497 print "Nagle's algorithm is turned ",
6498 $nodelay ? "off\n" : "on\n";
52146499
5215
5216=item given EXPR BLOCK
5217X<given>
5218
5219=item given BLOCK
5220
52216500=begin original
52226501
5223C<given> is analogous to the C<switch> keyword in other languages. C<given>
6502Portability issues: L<perlport/getsockopt>.
5224and C<when> are used in Perl to implement C<switch>/C<case> like statements.
5225Only available after Perl 5.10. For example:
52266503
52276504=end original
52286505
5229C<given> は他言語での C<switch> キーワードと似ています
6506移植性問題: L<perlport/getsockopt>。
5230C<given> と C<when> は C<switch>/C<case> 風の構文を実装するために Perl で
5231使われます。
5232Perl 5.10 以降でのみ利用可能です。
5233例えば:
52346507
5235 use v5.10;
5236 given ($fruit) {
5237 when (/apples?/) {
5238 print "I like apples."
5239 }
5240 when (/oranges?/) {
5241 print "I don't like oranges."
5242 }
5243 default {
5244 print "I don't like anything"
5245 }
5246 }
5247
5248=begin original
5249
5250See L<perlsyn/"Switch statements"> for detailed information.
5251
5252=end original
5253
5254詳しい情報については L<perlsyn/"Switch statements"> を参照してください。
5255
52566508=item glob EXPR
52576509X<glob> X<wildcard> X<filename, expansion> X<expand>
52586510
52596511=item glob
52606512
6513=for Pod::Functions expand filenames using wildcards
6514
52616515=begin original
52626516
52636517In list context, returns a (possibly empty) list of filename expansions on
5264the value of EXPR such as the standard Unix shell F</bin/csh> would do. In
6518the value of EXPR such as the standard Unix shell F</bin/csh> would do. In
52656519scalar context, glob iterates through such filename expansions, returning
5266undef when the list is exhausted. This is the internal function
6520undef when the list is exhausted. This is the internal function
5267implementing the C<< <*.c> >> operator, but you can use it directly. If
6521implementing the C<< <*.c> >> operator, but you can use it directly. If
5268EXPR is omitted, C<$_> is used. The C<< <*.c> >> operator is discussed in
6522EXPR is omitted, L<C<$_>|perlvar/$_> is used. The C<< <*.c> >> operator
5269more detail in L<perlop/"I/O Operators">.
6523is discussed in more detail in L<perlop/"I/O Operators">.
52706524
52716525=end original
52726526
52736527リストコンテキストでは、
52746528EXPR の値を、標準 Unix シェル F</bin/csh> が行なうように
52756529ファイル名の展開を行なった結果のリスト(空かもしれません)を返します。
52766530スカラコンテキストでは、glob はこのようなファイル名展開を繰り返し、
52776531リストがなくなったら undef を返します。
52786532これは、C<< <*.c> >> 演算子を実装する内部関数ですが、
52796533直接使用することもできます。
5280EXPR 省略ると、C<$_>が使われます。
6534EXPR 省略されると、L<C<$_>|perlvar/$_> が使われます。
52816535C<< <*.c> >>演算子については
52826536L<perlop/"I/O Operators"> でより詳細に議論しています。
52836537
52846538=begin original
52856539
5286Note that C<glob> splits its arguments on whitespace and treats
6540Note that L<C<glob>|/glob EXPR> splits its arguments on whitespace and
5287each segment as separate pattern. As such, C<glob("*.c *.h")>
6541treats
6542each segment as separate pattern. As such, C<glob("*.c *.h")>
52886543matches all files with a F<.c> or F<.h> extension. The expression
52896544C<glob(".* *")> matches all files in the current working directory.
6545If you want to glob filenames that might contain whitespace, you'll
6546have to use extra quotes around the spacey filename to protect it.
6547For example, to glob filenames that have an C<e> followed by a space
6548followed by an C<f>, use one of:
52906549
52916550=end original
52926551
5293C<glob> は引数を空白で分割して、それぞれの部分別々のパターンとして
6552L<C<glob>|/glob EXPR> は引数を空白で分割して、それぞれを分割された
5294扱うこに注意してください。
6553パターンとしてます
5295それにより、C<glob("*.c *.h")> は F<.c> F<.h> 拡張子を持つ全ての
6554従って、C<glob("*.c *.h")> は F<.c> または F<.h> 拡張子を持つ全てのファイルに
5296ファイルにマッチングします。
6555マッチングします。
5297C<glob(".* *")> という式はカレントワーキングディレクトリの
6556C<glob(".* *")> はカレントワーキングディレクトリの全てのファイルに
5298全てのファイルにマッチングします。
6557マッチングします。
6558空白を含んでいるかも知れないファイル名をグロブしたい場合、それを守るために
6559空白入りファイル名の周りに追加のクォートを使う必要があります。
6560例えば、C<e> の後に空白、その後に C<f> というファイル名をグロブするには
6561以下の一つを使います:
52996562
6563 my @spacies = <"*e f*">;
6564 my @spacies = glob '"*e f*"';
6565 my @spacies = glob q("*e f*");
6566
53006567=begin original
53016568
6569If you had to get a variable through, you could do this:
6570
6571=end original
6572
6573変数を通す必要があった場合、以下のようにできました:
6574
6575 my @spacies = glob "'*${var}e f*'";
6576 my @spacies = glob qq("*${var}e f*");
6577
6578=begin original
6579
53026580If non-empty braces are the only wildcard characters used in the
5303C<glob>, no filenames are matched, but potentially many strings
6581L<C<glob>|/glob EXPR>, no filenames are matched, but potentially many
5304are returned. For example, this produces nine strings, one for
6582strings are returned. For example, this produces nine strings, one for
53056583each pairing of fruits and colors:
53066584
53076585=end original
53086586
5309空でない中かっこが C<glob> で使われている唯一のワイルドカード文字列
6587空でない中かっこが L<C<glob>|/glob EXPR> で使われている唯一の
5310場合、ファイル名とはマッチングせず、可能性のある文字列が返されます。
6588ワイルドカード文字列の場合、ファイル名とはマッチングせず、
6589可能性のある文字列が返されます。
53116590例えば、これは 9 個の文字列を生成し、それぞれは果物と色の組み合わせに
53126591なります:
53136592
5314 @many = glob "{apple,tomato,cherry}={green,yellow,red}";
6593 my @many = glob "{apple,tomato,cherry}={green,yellow,red}";
53156594
53166595=begin original
53176596
5318Beginning with v5.6.0, this operator is implemented using the standard
6597This operator is implemented using the standard C<File::Glob> extension.
5319C<File::Glob> extension. See L<File::Glob> for details, including
6598See L<File::Glob> for details, including
5320C<bsd_glob> which does not treat whitespace as a pattern separator.
6599L<C<bsd_glob>|File::Glob/C<bsd_glob>>, which does not treat whitespace
6600as a pattern separator.
53216601
53226602=end original
53236603
53246604v5.6.0 から、この演算子は標準の C<File::Glob> 拡張を使って
53256605実装されています。
5326空白をパターンのセパレータとして扱わない C<bsd_glob> を含めた
6606空白をパターンのセパレータとして扱わない
5327詳細は L<File::Glob> を参照して下さい。
6607L<C<bsd_glob>|File::Glob/C<bsd_glob>>含めた
6608詳細は L<File::Glob> を参照してください。
53286609
6610=begin original
6611
6612Portability issues: L<perlport/glob>.
6613
6614=end original
6615
6616移植性の問題: L<perlport/glob>。
6617
53296618=item gmtime EXPR
53306619X<gmtime> X<UTC> X<Greenwich>
53316620
53326621=item gmtime
53336622
6623=for Pod::Functions convert UNIX time into record or string using Greenwich time
6624
53346625=begin original
53356626
5336Works just like L<localtime> but the returned values are
6627Works just like L<C<localtime>|/localtime EXPR> but the returned values
5337localized for the standard Greenwich time zone.
6628are localized for the standard Greenwich time zone.
53386629
53396630=end original
53406631
5341L<localtime> と同様に働きますが、返り値はグリニッジ標準時に
6632L<C<localtime>|/localtime EXPR> と同様に働きますが、返り値はグリニッジ標準時に
53426633ローカライズされています。
53436634
53446635=begin original
53456636
53466637Note: When called in list context, $isdst, the last value
53476638returned by gmtime, is always C<0>. There is no
53486639Daylight Saving Time in GMT.
53496640
53506641=end original
53516642
53526643注意: リストコンテキストで呼び出した時、gmtime が返す末尾の値である
53536644$isdst は常に C<0> です。
53546645GMT には夏時間はありません。
53556646
53566647=begin original
53576648
5358See L<perlport/gmtime> for portability concerns.
6649Portability issues: L<perlport/gmtime>.
53596650
53606651=end original
53616652
5362移植性の問題については L<perlport/gmtime> を参照してください
6653移植性の問題: L<perlport/gmtime>。
53636654
53646655=item goto LABEL
53656656X<goto> X<jump> X<jmp>
53666657
53676658=item goto EXPR
53686659
53696660=item goto &NAME
53706661
6662=for Pod::Functions create spaghetti code
6663
53716664=begin original
53726665
5373The C<goto-LABEL> form finds the statement labeled with LABEL and
6666The C<goto LABEL> form finds the statement labeled with LABEL and
5374resumes execution there. It can't be used to get out of a block or
6667resumes execution there. It can't be used to get out of a block or
5375subroutine given to C<sort>. It can be used to go almost anywhere
6668subroutine given to L<C<sort>|/sort SUBNAME LIST>. It can be used to go
5376else within the dynamic scope, including out of subroutines, but it's
6669almost anywhere else within the dynamic scope, including out of
5377usually better to use some other construct such as C<last> or C<die>.
6670subroutines, but it's usually better to use some other construct such as
5378The author of Perl has never felt the need to use this form of C<goto>
6671L<C<last>|/last LABEL> or L<C<die>|/die LIST>. The author of Perl has
5379(in Perl, that is; C is another matter). (The difference is that C
6672never felt the need to use this form of L<C<goto>|/goto LABEL> (in Perl,
5380does not offer named loops combined with loop control. Perl does, and
6673that is; C is another matter). (The difference is that C does not offer
5381this replaces most structured uses of C<goto> in other languages.)
6674named loops combined with loop control. Perl does, and this replaces
6675most structured uses of L<C<goto>|/goto LABEL> in other languages.)
53826676
53836677=end original
53846678
5385C<goto-LABEL> の形式は、LABEL というラベルの付いた文を
6679C<goto LABEL> の形式は、LABEL というラベルの付いた文を
53866680探して、そこへ実行を移すものです。
5387C<sort> で与えられたブロックやサブルーチンから外へ出ることはできません。
6681L<C<sort>|/sort SUBNAME LIST> で与えられたブロックやサブルーチンから外へ
6682出ることはできません。
53886683これ以外は、サブルーチンの外を含む、動的スコープ内の
53896684ほとんどすべての場所へ行くために使用できますが、普通は、
5390C<last> や C<die> といった別の構造を使った方が良いでしょう。
6685L<C<last>|/last LABEL> L<C<die>|/die LIST> といった別の構造を使った方が
5391Perl の作者はこの形式の C<goto> を使必要を感じたことは、
6686良いでしょ
6687Perl の作者はこの形式の L<C<goto>|/goto LABEL> を使う必要を感じたことは、
539266881 度もありません (Perl では; C は別のお話です)。
53936689(違いは、C にはループ制御と結びついた名前つきのループがないことです。
5394Perl にはあり、これが他の言語でのほとんどの構造的な C<goto> の使用法を
6690Perl にはあり、これが他の言語でのほとんどの構造的な L<C<goto>|/goto LABEL>
5395置き換えます。)
6691使用法を置き換えます。)
53966692
53976693=begin original
53986694
5399The C<goto-EXPR> form expects a label name, whose scope will be resolved
6695The C<goto EXPR> form expects to evaluate C<EXPR> to a code reference or
5400dynamically. This allows for computed C<goto>s per FORTRAN, but isn't
6696a label name. If it evaluates to a code reference, it will be handled
5401necessarily recommended if you're optimizing for maintainability:
6697like C<goto &NAME>, below. This is especially useful for implementing
6698tail recursion via C<goto __SUB__>.
54026699
54036700=end original
54046701
5405C<goto-EXPR> の形式はラベル名を予測、このスコープは動的に解決されます。
6702C<goto EXPR> の形式は、C<EXPR> をコードリファレンスまたはラベル名
5406れにより FORTRAN のような算術 C<goto> が可能になりますが、
6703評価するとを想定します
6704コードリファレンスとして評価する場合、後述する C<goto &NAME> のように
6705扱います。
6706これは特に、C<goto __SUB__> による末尾再帰の実装に有用です。
6707
6708=begin original
6709
6710If the expression evaluates to a label name, its scope will be resolved
6711dynamically. This allows for computed L<C<goto>|/goto LABEL>s per
6712FORTRAN, but isn't necessarily recommended if you're optimizing for
6713maintainability:
6714
6715=end original
6716
6717式がラベル名に評価される場合、このスコープは動的に解決されます。
6718これにより FORTRAN のような算術 L<C<goto>|/goto LABEL> が可能になりますが、
54076719保守性を重視するならお勧めしません。
54086720
54096721 goto ("FOO", "BAR", "GLARCH")[$i];
54106722
54116723=begin original
54126724
5413As shown in this example, C<goto-EXPR> is exempt from the "looks like a
6725As shown in this example, C<goto EXPR> is exempt from the "looks like a
5414function" rule. A pair of parentheses following it does not (necessarily)
6726function" rule. A pair of parentheses following it does not (necessarily)
5415delimit its argument. C<goto("NE")."XT"> is equivalent to C<goto NEXT>.
6727delimit its argument. C<goto("NE")."XT"> is equivalent to C<goto NEXT>.
6728Also, unlike most named operators, this has the same precedence as
6729assignment.
54166730
54176731=end original
54186732
5419この例で示したように、C<goto-EXPR> は「関数のように見える」ルールから
6733この例で示したように、C<goto EXPR> は「関数のように見える」ルールから
54206734除外されます。
54216735これに引き続くかっこの組は引数の区切りとは(必ずしも)なりません。
54226736C<goto("NE")."XT"> は C<goto NEXT> と等価です。
6737また、ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
54236738
54246739=begin original
54256740
5426Use of C<goto-LABEL> or C<goto-EXPR> to jump into a construct is
6741Use of C<goto LABEL> or C<goto EXPR> to jump into a construct is
54276742deprecated and will issue a warning. Even then, it may not be used to
54286743go into any construct that requires initialization, such as a
54296744subroutine or a C<foreach> loop. It also can't be used to go into a
54306745construct that is optimized away.
54316746
54326747=end original
54336748
5434構造の中に飛び込むために C<goto-LABEL> や C<goto-EXPR> を使うことは
6749構造の中に飛び込むために C<goto LABEL> や C<goto EXPR> を使うことは
54356750非推奨で、警告が発生します。
54366751それでも、サブルーチンや C<foreach> ループのような、初期化が必要な
54376752構造の中に入るために使うことは出来ません。
54386753また、最適化してなくなってしまった構造の中へ入るために使うことも出来ません。
54396754
54406755=begin original
54416756
5442The C<goto-&NAME> form is quite different from the other forms of
6757The C<goto &NAME> form is quite different from the other forms of
5443C<goto>. In fact, it isn't a goto in the normal sense at all, and
6758L<C<goto>|/goto LABEL>. In fact, it isn't a goto in the normal sense at
5444doesn't have the stigma associated with other gotos. Instead, it
6759all, and doesn't have the stigma associated with other gotos. Instead,
5445exits the current subroutine (losing any changes set by local()) and
6760it exits the current subroutine (losing any changes set by
5446immediately calls in its place the named subroutine using the current
6761L<C<local>|/local EXPR>) and immediately calls in its place the named
5447value of @_. This is used by C<AUTOLOAD> subroutines that wish to
6762subroutine using the current value of L<C<@_>|perlvar/@_>. This is used
5448load another subroutine and then pretend that the other subroutine had
6763by C<AUTOLOAD> subroutines that wish to load another subroutine and then
5449been called in the first place (except that any modifications to C<@_>
6764pretend that the other subroutine had been called in the first place
5450in the current subroutine are propagated to the other subroutine.)
6765(except that any modifications to L<C<@_>|perlvar/@_> in the current
5451After the C<goto>, not even C<caller> will be able to tell that this
6766subroutine are propagated to the other subroutine.) After the
5452routine was called first.
6767L<C<goto>|/goto LABEL>, not even L<C<caller>|/caller EXPR> will be able
6768to tell that this routine was called first.
54536769
54546770=end original
54556771
5456C<goto-&NAME> の形式は、その他の C<goto> の形式とはかなり
6772C<goto &NAME> の形式は、その他の L<C<goto>|/goto LABEL> の形式とはかなり
54576773異なったものです。
54586774実際、これは普通の感覚でいうところのどこかへ行くものでは全くなく、
54596775他の goto が持つ不名誉を持っていません。
5460現在のサブルーチンを終了し (local() による変更は失われます)、
6776現在のサブルーチンを終了し (L<C<local>|/local EXPR> による変更は失われます)、
5461直ちに現在の @_ の値を使って指定された名前のサブルーチンを呼び出します。
6777直ちに現在の L<C<@_>|perlvar/@_> の値を使って指定された名前のサブルーチンを
6778呼び出します。
54626779これは、C<AUTOLOAD> サブルーチンが別のサブルーチンをロードして、
54636780その別のサブルーチンが最初に呼ばれたようにするために使われます
5464(ただし、現在のサブルーチンで C<@_> を修正した場合には、
6781(ただし、現在のサブルーチンで L<C<@_>|perlvar/@_> を修正した場合には、
54656782その別のサブルーチンに伝えられます)。
5466C<goto> のあとは、C<caller> でさえも、現在のサブルーチンが
6783L<C<goto>|/goto LABEL> のあとは、L<C<caller>|/caller EXPR> でさえも、現在の
5467最初に呼び出されたと言うことができません。
6784サブルーチンが最初に呼び出されたと言うことができません。
54686785
54696786=begin original
54706787
54716788NAME needn't be the name of a subroutine; it can be a scalar variable
54726789containing a code reference or a block that evaluates to a code
54736790reference.
54746791
54756792=end original
54766793
54776794NAME はサブルーチンの名前である必要はありません; コードリファレンスを
54786795含むスカラ値や、コードリファレンスと評価されるブロックでも構いません。
54796796
54806797=item grep BLOCK LIST
54816798X<grep>
54826799
54836800=item grep EXPR,LIST
54846801
6802=for Pod::Functions locate elements in a list test true against a given criterion
6803
54856804=begin original
54866805
5487This is similar in spirit to, but not the same as, grep(1) and its
6806This is similar in spirit to, but not the same as, L<grep(1)> and its
54886807relatives. In particular, it is not limited to using regular expressions.
54896808
54906809=end original
54916810
5492これは grep(1) とその親類と同じようなものですが、同じではありません。
6811これは L<grep(1)> とその親類と同じようなものですが、同じではありません。
54936812特に、正規表現の使用に制限されません。
54946813
54956814=begin original
54966815
54976816Evaluates the BLOCK or EXPR for each element of LIST (locally setting
5498C<$_> to each element) and returns the list value consisting of those
6817L<C<$_>|perlvar/$_> to each element) and returns the list value
6818consisting of those
54996819elements for which the expression evaluated to true. In scalar
55006820context, returns the number of times the expression was true.
55016821
55026822=end original
55036823
55046824LIST の個々の要素に対して、BLOCK か EXPR を評価し
5505(C<$_> は、ローカルに個々の要素が設定されます) 、
6825(L<C<$_>|perlvar/$_> は、ローカルに個々の要素が設定されます) 、
55066826その要素のうち、評価した式が真となったものからなるリスト値が返されます。
5507スカラコンテキストでは、式が真となった回数を返します。 例:
6827スカラコンテキストでは、式が真となった回数を返します。
55086828
5509 @foo = grep(!/^#/, @bar); # weed out comments
6829 my @foo = grep(!/^#/, @bar); # weed out comments
55106830
55116831=begin original
55126832
55136833or equivalently,
55146834
55156835=end original
55166836
55176837あるいは等価な例として:
55186838
5519 @foo = grep {!/^#/} @bar; # weed out comments
6839 my @foo = grep {!/^#/} @bar; # weed out comments
55206840
55216841=begin original
55226842
5523Note that C<$_> is an alias to the list value, so it can be used to
6843Note that L<C<$_>|perlvar/$_> is an alias to the list value, so it can
6844be used to
55246845modify the elements of the LIST. While this is useful and supported,
55256846it can cause bizarre results if the elements of LIST are not variables.
55266847Similarly, grep returns aliases into the original list, much as a for
55276848loop's index variable aliases the list elements. That is, modifying an
5528element of a list returned by grep (for example, in a C<foreach>, C<map>
6849element of a list returned by grep (for example, in a C<foreach>,
5529or another C<grep>) actually modifies the element in the original list.
6850L<C<map>|/map BLOCK LIST> or another L<C<grep>|/grep BLOCK LIST>)
6851actually modifies the element in the original list.
55306852This is usually something to be avoided when writing clear code.
55316853
55326854=end original
55336855
5534C<$_> は、LIST の値へのエイリアスですので、LIST の要素を
6856L<C<$_>|perlvar/$_> は、LIST の値へのエイリアスですので、LIST の要素を
55356857変更するために使うことができます。
55366858これは、便利でサポートされていますが、
55376859LIST の要素が変数でないと、おかしな結果になります。
5538同様に、grep は元のリストへのエイリアスを返します
6860同様に、grep は元のリストへのエイリアスを返します; for ループの
5539for ループのインデックス変数がリスト要素のエイリアスであるのと
6861インデックス変数がリスト要素のエイリアスであるのと同様です。
5540同様です。
55416862つまり、grep で返されたリストの要素を
5542(C<foreach>, C<map>, または他の C<grep> で)修正すると
6863(C<foreach>, L<C<map>|/map BLOCK LIST>, または他の
5543元のリストの要素が変更されます。
6864L<C<grep>|/grep BLOCK LIST> で)修正すると元のリストの要素が変更されます。
5544これはきれいなコードを書こうする邪魔なることが多いです。
6865これはきれいなコードを書は普通は回避されます。
55456866
55466867=begin original
55476868
5548If C<$_> is lexical in the scope where the C<grep> appears (because it has
6869See also L<C<map>|/map BLOCK LIST> for a list composed of the results of
5549been declared with C<my $_>) then, in addition to being locally aliased to
6870the BLOCK or EXPR.
5550the list elements, C<$_> keeps being lexical inside the block; i.e., it
5551can't be seen from the outside, avoiding any potential side-effects.
55526871
55536872=end original
55546873
5555(C<my $_> として宣言されることよって) C<$_> C<grep> が現れるスコープ内で
6874BLOCK EXPR の結果をリストの形したい場合は L<C<map>|/map BLOCK LIST>
5556レキシカルな場合は、ローカルではリスト要素へのエイリアスであることに加え
6875参照しください。
5557C<$_> はブロック内でレキシカルでありつづけます; つまり、外側からは見えず、
5558起こりうる副作用を回避します。
55596876
5560=begin original
5561
5562See also L</map> for a list composed of the results of the BLOCK or EXPR.
5563
5564=end original
5565
5566BLOCK や EXPR の結果をリストの形にしたい場合は L</map> を参照してください。
5567
55686877=item hex EXPR
55696878X<hex> X<hexadecimal>
55706879
55716880=item hex
55726881
6882=for Pod::Functions convert a hexadecimal string to a number
6883
55736884=begin original
55746885
5575Interprets EXPR as a hex string and returns the corresponding value.
6886Interprets EXPR as a hex string and returns the corresponding numeric value.
5576(To convert strings that might start with either C<0>, C<0x>, or C<0b>, see
6887If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
5577L</oct>.) If EXPR is omitted, uses C<$_>.
55786888
55796889=end original
55806890
5581EXPR を 16 進数の文字列と解釈して、対応する値を返します。
6891EXPR を 16 進数の文字列と解釈して、対応する値を返します。
5582(C<0>, C<0x>, C<0b> で始ま文字列の変換には、L</oct> を
6892EXPR が省略され、L<C<$_>|perlvar/$_> を使います。
5583参照してください。)
5584EXPR が省略されると、C<$_> を使用します。
55856893
55866894 print hex '0xAf'; # prints '175'
55876895 print hex 'aF'; # same
6896 $valid_input =~ /\A(?:0?[xX])?(?:_?[0-9a-fA-F])*\z/
55886897
55896898=begin original
55906899
5591Hex strings may only represent integers. Strings that would cause
6900A hex string consists of hex digits and an optional C<0x> or C<x> prefix.
5592integer overflow trigger a warning. Leading whitespace is not stripped,
6901Each hex digit may be preceded by a single underscore, which will be ignored.
5593unlike oct(). To present something as hex, look into L</printf>,
6902Any other character triggers a warning and causes the rest of the string
5594L</sprintf>, and L</unpack>.
6903to be ignored (even leading whitespace, unlike L<C<oct>|/oct EXPR>).
6904Only integers can be represented, and integer overflow triggers a warning.
55956905
55966906=end original
55976907
559816 進文字列は数のみを表現します。
690816 進文字列は 16 進と、オプション C<0x> または C<x> 接頭辞からなります。
5599オーバーフローを起こすような文字列警告ます。
6909それぞれの 16 進数は一つの下線前に置くことがでれは無視されます。
5600oct() と違って、先頭の空白は除去されません。
6910その他の文字警告を引き起こし(例え先頭の空白でも、L<C<oct>|/oct EXPR> と
5601何かを 16 進で表現したい場合、L</printf>, L</sprintf>, L</unpack> を
6911異なり)文字列の残りの部分無視されます。
6912整数のみを表現でき、整数オーバーフローは警告を引き起こします。
6913
6914=begin original
6915
6916To convert strings that might start with any of C<0>, C<0x>, or C<0b>,
6917see L<C<oct>|/oct EXPR>. To present something as hex, look into
6918L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
6919L<C<sprintf>|/sprintf FORMAT, LIST>, and
6920L<C<unpack>|/unpack TEMPLATE,EXPR>.
6921
6922=end original
6923
6924C<0>, C<0x>, C<0b> のいずれかで始まるかもしれない文字列を変換するには、
6925L<C<oct>|/oct EXPR> を参照してください。
6926何かを 16 進で表現したい場合は、L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
6927L<C<sprintf>|/sprintf FORMAT, LIST>, L<C<unpack>|/unpack TEMPLATE,EXPR> を
56026928参照してください。
56036929
56046930=item import LIST
56056931X<import>
56066932
6933=for Pod::Functions patch a module's namespace into your own
6934
56076935=begin original
56086936
5609There is no builtin C<import> function. It is just an ordinary
6937There is no builtin L<C<import>|/import LIST> function. It is just an
5610method (subroutine) defined (or inherited) by modules that wish to export
6938ordinary method (subroutine) defined (or inherited) by modules that wish
5611names to another module. The C<use> function calls the C<import> method
6939to export names to another module. The
5612for the package used. See also L</use>, L<perlmod>, and L<Exporter>.
6940L<C<use>|/use Module VERSION LIST> function calls the
6941L<C<import>|/import LIST> method for the package used. See also
6942L<C<use>|/use Module VERSION LIST>, L<perlmod>, and L<Exporter>.
56136943
56146944=end original
56156945
5616組み込みの C<import> 関数というものはありません。
6946組み込みの L<C<import>|/import LIST> 関数というものはありません。
56176947これは単に、別のモジュールに名前をエクスポートしたいモジュールが
56186948定義した(または継承した)、通常のメソッド(サブルーチン)です。
5619C<use> 関数はパッケージを使う時に C<import> メソッドを呼び出します。
6949L<C<use>|/use Module VERSION LIST> 関数はパッケージを使う時に
5620L</use>, L<perlmod>, L<Exporter> も参照てください
6950L<C<import>|/import LIST> メソッドを呼び出ます
6951L<C<use>|/use Module VERSION LIST>, L<perlmod>, L<Exporter> も
6952参照してください。
56216953
56226954=item index STR,SUBSTR,POSITION
56236955X<index> X<indexOf> X<InStr>
56246956
56256957=item index STR,SUBSTR
56266958
6959=for Pod::Functions find a substring within a string
6960
56276961=begin original
56286962
56296963The index function searches for one string within another, but without
56306964the wildcard-like behavior of a full regular-expression pattern match.
56316965It returns the position of the first occurrence of SUBSTR in STR at
56326966or after POSITION. If POSITION is omitted, starts searching from the
56336967beginning of the string. POSITION before the beginning of the string
56346968or after its end is treated as if it were the beginning or the end,
5635respectively. POSITION and the return value are based at C<0> (or whatever
6969respectively. POSITION and the return value are based at zero.
5636you've set the C<$[> variable to--but don't do that). If the substring
6970If the substring is not found, L<C<index>|/index STR,SUBSTR,POSITION>
5637is not found, C<index> returns one less than the base, ordinarily C<-1>.
6971returns -1.
56386972
56396973=end original
56406974
56416975index 関数は ある文字列をもうひとつの文字列から検索しますが、
56426976完全正規表現パターンマッチのワイルドカード的な振る舞いはしません。
56436977STR の中の POSITION の位置以降で、最初に SUBSTR が見つかった位置を返します。
56446978POSITION が省略された場合には、STR の最初から探し始めます。
56456979POSITION が文字列の先頭より前、あるいは末尾より後ろを指定した場合は、
56466980それぞれ先頭と末尾を指定されたものとして扱われます。
5647POSITION と返り値のベースは、C<0> (もしくは、変数 C<$[> に設定した値です --
6981POSITION と返り値のベースは、0 です
5648し、これは使いけません)。
6982SUBSTR が見つらなかた場合に、L<C<index>|/index STR,SUBSTR,POSITION> は
5649SUBSTR が見つからなかった場合には、C<index> はベースよりも 1 い値、
6983-1 が返れます。
5650通常は C<-1> が返されます。
56516984
56526985=item int EXPR
56536986X<int> X<integer> X<truncate> X<trunc> X<floor>
56546987
56556988=item int
56566989
6990=for Pod::Functions get the integer portion of a number
6991
56576992=begin original
56586993
5659Returns the integer portion of EXPR. If EXPR is omitted, uses C<$_>.
6994Returns the integer portion of EXPR. If EXPR is omitted, uses
6995L<C<$_>|perlvar/$_>.
56606996You should not use this function for rounding: one because it truncates
56616997towards C<0>, and two because machine representations of floating-point
56626998numbers can sometimes produce counterintuitive results. For example,
56636999C<int(-6.725/0.025)> produces -268 rather than the correct -269; that's
56647000because it's really more like -268.99999999999994315658 instead. Usually,
5665the C<sprintf>, C<printf>, or the C<POSIX::floor> and C<POSIX::ceil>
7001the L<C<sprintf>|/sprintf FORMAT, LIST>,
5666functions will serve you better than will int().
7002L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, or the
7003L<C<POSIX::floor>|POSIX/C<floor>> and L<C<POSIX::ceil>|POSIX/C<ceil>>
7004functions will serve you better than will L<C<int>|/int EXPR>.
56677005
56687006=end original
56697007
56707008EXPR の整数部を返します。
5671EXPR 省略ると、C<$_> を使います。
7009EXPR 省略されると、L<C<$_>|perlvar/$_> を使います。
5672この関数を丸めのために使うべきではありません
7010この関数を丸めのために使うべきではありません: 第一の理由として C<0> の
5673第一の理由として C<0> の方向への切捨てを行うから、第二の理由として
7011方向への切捨てを行うから、第二の理由として浮動小数点数の機械表現は時々直感に
5674浮動小数点数の機械表現は時々直感に反した結果を生み出すからです。
7012反した結果を生み出すからです。
5675たとえば、C<int(-6.725/0.025)> は正しい結果である -269 ではなく
7013たとえば、C<int(-6.725/0.025)> は正しい結果である -269 ではなく -268 を
5676-268 を返します。
7014返します: これは実際には -268.99999999999994315658 というような値に
5677これは実際には -268.99999999999994315658 というような値になっているからです。
7015なっているからです。
5678通常、C<sprintf>, C<printf>, C<POSIX::floor>, C<POSIX::ceil> の方が
7016通常、L<C<sprintf>|/sprintf FORMAT, LIST>,
5679int() より便利です。
7017L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
7018L<C<POSIX::floor>|POSIX/C<floor>>, L<C<POSIX::ceil>|POSIX/C<ceil>> の方が
7019L<C<int>|/int EXPR> より便利です。
56807020
56817021=item ioctl FILEHANDLE,FUNCTION,SCALAR
56827022X<ioctl>
56837023
7024=for Pod::Functions system-dependent device control system call
7025
56847026=begin original
56857027
5686Implements the ioctl(2) function. You'll probably first have to say
7028Implements the L<ioctl(2)> function. You'll probably first have to say
56877029
56887030=end original
56897031
5690ioctl(2) 関数を実装します。
7032L<ioctl(2)> 関数を実装します。
56917033正しい関数の定義を得るために、おそらく最初に
56927034
5693 require "sys/ioctl.ph"; # probably in $Config{archlib}/sys/ioctl.ph
7035 require "sys/ioctl.ph"; # probably in
7036 # $Config{archlib}/sys/ioctl.ph
56947037
56957038=begin original
56967039
56977040to get the correct function definitions. If F<sys/ioctl.ph> doesn't
56987041exist or doesn't have the correct definitions you'll have to roll your
56997042own, based on your C header files such as F<< <sys/ioctl.h> >>.
57007043(There is a Perl script called B<h2ph> that comes with the Perl kit that
57017044may help you in this, but it's nontrivial.) SCALAR will be read and/or
57027045written depending on the FUNCTION; a C pointer to the string value of SCALAR
5703will be passed as the third argument of the actual C<ioctl> call. (If SCALAR
7046will be passed as the third argument of the actual
7047L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> call. (If SCALAR
57047048has no string value but does have a numeric value, that value will be
57057049passed rather than a pointer to the string value. To guarantee this to be
5706true, add a C<0> to the scalar before using it.) The C<pack> and C<unpack>
7050true, add a C<0> to the scalar before using it.) The
7051L<C<pack>|/pack TEMPLATE,LIST> and L<C<unpack>|/unpack TEMPLATE,EXPR>
57077052functions may be needed to manipulate the values of structures used by
5708C<ioctl>.
7053L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>.
57097054
57107055=end original
57117056
57127057としなくてはならないでしょう。
57137058F<sys/ioctl.ph> がないか、間違った定義をしている場合には、
5714F<< <sys/ioctl.ph> >>のような C のヘッダファイルをもとに、
7059F<< <sys/ioctl.h> >>のような C のヘッダファイルをもとに、
57157060自分で作らなければなりません。
5716(Perl の配布キットに入っている B<h2ph> という
7061(Perl の配布キットに入っている B<h2ph> という Perl スクリプトが
5717Perl スクリプトがこれを手助けしてくれるでしょうが、これは重要。)
7062これを手助けしてくれるでしょうが、これは自明はありません。)
57187063FOUNCTION に応じて SCALAR が読み書きされます;
5719SCALAR の文字列値へのポインタが、実際の C<ioctl> コールの
7064SCALAR の文字列値へのポインタが、実際の
7065L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> コールの
572070663 番目の引数として渡されます。
57217067(SCALAR が文字列値を持っておらず、数値を持っている場合には、
57227068文字列値へのポインタの代わりに、その値が渡されます。
57237069このことを保証するためには、使用する前に SCALAR にC<0> を足してください。)
5724C<ioctl> で使われる構造体の値を操作するには、
7070L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> で使われる構造体の値を
5725C<pack> 関数と C<unpack> 関数が必要なるでしょう。
7071操作するには、L<C<pack>|/pack TEMPLATE,LIST> 関数と
7072L<C<unpack>|/unpack TEMPLATE,EXPR> 関数が必要となるでしょう。
57267073
57277074=begin original
57287075
5729The return value of C<ioctl> (and C<fcntl>) is as follows:
7076The return value of L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> (and
7077L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>) is as follows:
57307078
57317079=end original
57327080
5733C<ioctl> (と C<fcntl>) の返り値は、以下のようになります:
7081L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>
7082(と L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>) の返り値は、
7083以下のようになります:
57347084
57357085=begin original
57367086
57377087 if OS returns: then Perl returns:
57387088 -1 undefined value
57397089 0 string "0 but true"
57407090 anything else that number
57417091
57427092=end original
57437093
57447094 OS が返した値: Perl が返す値:
57457095 -1 未定義値
57467096 0 「0 だが真」の文字列
57477097 その他 その値そのもの
57487098
57497099=begin original
57507100
57517101Thus Perl returns true on success and false on failure, yet you can
57527102still easily determine the actual value returned by the operating
57537103system:
57547104
57557105=end original
57567106
57577107つまり Perl は、成功時に「真」、失敗時に「偽」を返す
57587108ことになり、OS が実際に返した値も、以下のように簡単に知ることができます。
57597109
5760 $retval = ioctl(...) || -1;
7110 my $retval = ioctl(...) || -1;
57617111 printf "System returned %d\n", $retval;
57627112
57637113=begin original
57647114
5765The special string C<"0 but true"> is exempt from B<-w> complaints
7115The special string C<"0 but true"> is exempt from
5766about improper numeric conversions.
7116L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s>
7117L<warnings> on improper numeric conversions.
57677118
57687119=end original
57697120
57707121特別な文字列 C<"0 だが真"> は、不適切な数値変換に関する
5771B<-w> 警告を回避します。
7122L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s>
7123L<warnings> 警告を回避します。
57727124
7125=begin original
7126
7127Portability issues: L<perlport/ioctl>.
7128
7129=end original
7130
7131移植性の問題: L<perlport/ioctl>。
7132
57737133=item join EXPR,LIST
57747134X<join>
57757135
7136=for Pod::Functions join a list into a string using a separator
7137
57767138=begin original
57777139
57787140Joins the separate strings of LIST into a single string with fields
57797141separated by the value of EXPR, and returns that new string. Example:
57807142
57817143=end original
57827144
57837145LIST の個別の文字列を、EXPR の値で区切って
578471461 つの文字列につなげ、その文字列を返します。
57857147例:
57867148
5787 $rec = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell);
7149 my $rec = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell);
57887150
57897151=begin original
57907152
5791Beware that unlike C<split>, C<join> doesn't take a pattern as its
7153Beware that unlike L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>,
5792first argument. Compare L</split>.
7154L<C<join>|/join EXPR,LIST> doesn't take a pattern as its first argument.
7155Compare L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>.
57937156
57947157=end original
57957158
5796C<split> と違って、C<join> は最初の引数にパターンは取れないこ
7159L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>違って、
7160L<C<join>|/join EXPR,LIST> は最初の引数にパターンは取れないことに
57977161注意してください。
5798L</split> と比較してください。
7162L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> と比較してください。
57997163
58007164=item keys HASH
58017165X<keys> X<key>
58027166
58037167=item keys ARRAY
58047168
5805=item keys EXPR
7169=for Pod::Functions retrieve list of indices from a hash
58067170
58077171=begin original
58087172
5809Returns a list consisting of all the keys of the named hash, or the indices
7173Called in list context, returns a list consisting of all the keys of the
5810of an array. (In scalar context, returns the number of keys or indices.)
7174named hash, or in Perl 5.12 or later only, the indices of an array. Perl
7175releases prior to 5.12 will produce a syntax error if you try to use an
7176array argument. In scalar context, returns the number of keys or indices.
58117177
58127178=end original
58137179
5814指定したハッシュのすべてのキー、あるいは配列のインデックスからなるリストを
7180リストコンテキストで呼び出されると、指定したハッシュのすべてのキー、あるいは
5815返します。
7181Perl 5.12 以降でのみ、配列のインデックスからなるリストを返します。
5816(スカラコンテキストでは、キーやインデックスの数をします。)
71825.12 より前 Perl は配列引数を使おうとすると文法エラーを出力します。
7183スカラコンテキストでは、キーやインデックスの数を返します。
58177184
58187185=begin original
58197186
5820The keys of a hash are returned in an apparently random order. The actual
7187Hash entries are returned in an apparently random order. The actual random
5821random order is subject to change in future versions of Perl, but it
7188order is specific to a given hash; the exact same series of operations
5822is guaranteed to be the same order as either the C<values> or C<each>
7189on two hashes may result in a different order for each hash. Any insertion
5823function produces (given that the hash has not been modified). Since
7190into the hash may change the order, as will any deletion, with the exception
5824Perl 5.8.1 the ordering can be different even between different runs of
7191that the most recent key returned by L<C<each>|/each HASH> or
5825Perl for security reasons (see L<perlsec/"Algorithmic Complexity
7192L<C<keys>|/keys HASH> may be deleted without changing the order. So
5826Attacks">).
7193long as a given hash is unmodified you may rely on
7194L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and L<C<each>|/each
7195HASH> to repeatedly return the same order
7196as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
7197details on why hash order is randomized. Aside from the guarantees
7198provided here the exact details of Perl's hash algorithm and the hash
7199traversal order are subject to change in any release of Perl. Tied hashes
7200may behave differently to Perl's hashes with respect to changes in order on
7201insertion and deletion of items.
58277202
58287203=end original
58297204
5830ハッシュのキーは見たところではランダムな順番に返されます。
7205ハッシュ要素は見かけ上、ランダムな順序で返されます。
5831実際のランダムな順Perl 将来バージョンでは変わるかもしれませんが、
7206実際のランダムな順ハッシュに固有です; 二つハッシュに全く同じ一連
5832C<values> や C<each> 関数が同じ(変更されいない)ハッシュに対し
7207操作を行っも、ハッシュによっ異なった順序になります。
5833生成すると同じ番であることは保証されます
7208ハッシュへ挿入によって序が変わることがあります; 削除も同様ですが、
5834Perl 5.8.1 以降でセキュリティ上の理由により、
7209L<C<each>|/each HASH> また L<C<keys>|/keys HASH> によって返されたもっとも
5835実行される毎に順番は変わります
7210最近のキー順序をえることなく削除できます
5836(L<perlsec/"Algorithmic Complexity Attacks"> を参照してください)。
7211ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>,
7212L<C<each>|/each HASH> が繰り返し同じ順序で
7213返すことに依存してもかまいません。
7214なぜハッシュの順序がランダム化されているかの詳細については
7215L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。
7216ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の
7217正確な詳細は Perl のリリースによって変更される可能性があります。
7218tie されたハッシュは、アイテムの挿入と削除の順序に関して Perl のハッシュと
7219異なった振る舞いをします。
58377220
58387221=begin original
58397222
5840As a side effect, calling keys() resets the internal interator of the HASH or ARRAY
7223As a side effect, calling L<C<keys>|/keys HASH> resets the internal
5841(see L</each>). In particular, calling keys() in void context resets
7224iterator of the HASH or ARRAY (see L<C<each>|/each HASH>). In
5842the iterator with no other overhead.
7225particular, calling L<C<keys>|/keys HASH> in void context resets the
7226iterator with no other overhead.
58437227
58447228=end original
58457229
5846副作用として、HASH や ARRAY の反復子を初期化します
7230副作用として、L<C<keys>|/keys HASH> の呼び出しは HASH や ARRAY の反復子を
5847(L</each> を参照してください)。
7231初期化します (L<C<each>|/each HASH> を参照してください)。
5848特に、無効コンテキストで keys() を呼び出すと
7232特に、無効コンテキストで L<C<keys>|/keys HASH> を呼び出すと
58497233オーバーヘッドなしで反復子を初期化します。
58507234
58517235=begin original
58527236
58537237Here is yet another way to print your environment:
58547238
58557239=end original
58567240
58577241環境変数を表示する別の例です:
58587242
5859 @keys = keys %ENV;
7243 my @keys = keys %ENV;
5860 @values = values %ENV;
7244 my @values = values %ENV;
58617245 while (@keys) {
58627246 print pop(@keys), '=', pop(@values), "\n";
58637247 }
58647248
58657249=begin original
58667250
58677251or how about sorted by key:
58687252
58697253=end original
58707254
58717255key でソートしてもいいでしょう:
58727256
5873 foreach $key (sort(keys %ENV)) {
7257 foreach my $key (sort(keys %ENV)) {
58747258 print $key, '=', $ENV{$key}, "\n";
58757259 }
58767260
58777261=begin original
58787262
58797263The returned values are copies of the original keys in the hash, so
5880modifying them will not affect the original hash. Compare L</values>.
7264modifying them will not affect the original hash. Compare
7265L<C<values>|/values HASH>.
58817266
58827267=end original
58837268
58847269返される値はハッシュにある元のキーのコピーなので、
58857270これを変更しても元のハッシュには影響を与えません。
5886L</values> と比較してください。
7271L<C<values>|/values HASH> と比較してください。
58877272
58887273=begin original
58897274
5890To sort a hash by value, you'll need to use a C<sort> function.
7275To sort a hash by value, you'll need to use a
5891Here's a descending numeric sort of a hash by its values:
7276L<C<sort>|/sort SUBNAME LIST> function. Here's a descending numeric
7277sort of a hash by its values:
58927278
58937279=end original
58947280
5895ハッシュを値でソートするためには、C<sort> 関数を使う必要があります。
7281ハッシュを値でソートするためには、L<C<sort>|/sort SUBNAME LIST> 関数を使う
7282必要があります。
58967283以下ではハッシュの値を数値の降順でソートしています:
58977284
5898 foreach $key (sort { $hash{$b} <=> $hash{$a} } keys %hash) {
7285 foreach my $key (sort { $hash{$b} <=> $hash{$a} } keys %hash) {
58997286 printf "%4d %s\n", $hash{$key}, $key;
59007287 }
59017288
59027289=begin original
59037290
5904Used as an lvalue, C<keys> allows you to increase the number of hash buckets
7291Used as an lvalue, L<C<keys>|/keys HASH> allows you to increase the
7292number of hash buckets
59057293allocated for the given hash. This can gain you a measure of efficiency if
59067294you know the hash is going to get big. (This is similar to pre-extending
59077295an array by assigning a larger number to $#array.) If you say
59087296
59097297=end original
59107298
5911左辺値として使うことで、C<keys> を使うことで与えられたハッシュに割り当てられた
7299左辺値として使うことで、L<C<keys>|/keys HASH> を使うことで与えられたハッシュに
5912ハッシュ表の大きさを増やすことができます。
7300割り当てられたハッシュ表の大きさを増やすことができます。
59137301これによって、ハッシュが大きくなっていくなっていくときの
59147302効率の測定ができます。
59157303(これは大きい値を $#array に代入することで配列を予め拡張することに
59167304似ています。)
59177305以下のようにすると:
59187306
59197307 keys %hash = 200;
59207308
59217309=begin original
59227310
59237311then C<%hash> will have at least 200 buckets allocated for it--256 of them,
59247312in fact, since it rounds up to the next power of two. These
59257313buckets will be retained even if you do C<%hash = ()>, use C<undef
59267314%hash> if you want to free the storage while C<%hash> is still in scope.
59277315You can't shrink the number of buckets allocated for the hash using
5928C<keys> in this way (but you needn't worry about doing this by accident,
7316L<C<keys>|/keys HASH> in this way (but you needn't worry about doing
5929as trying has no effect). C<keys @array> in an lvalue context is a syntax
7317this by accident, as trying has no effect). C<keys @array> in an lvalue
5930error.
7318context is a syntax error.
59317319
59327320=end original
59337321
5934C<%hash> は少なくとも 200 の大きさの表が割り当てられます --
7322C<%hash> は少なくとも 200 の大きさの表が割り当てられます --
59357323実際には 2 のべき乗に切り上げられるので、256 が割り当てられます。
59367324この表はたとえ C<%hash = ()> としても残るので、
59377325もし C<%hash> がスコープにいるうちにこの領域を開放したい場合は
59387326C<undef %hash> を使います。
5939この方法で C<keys> を使うことで、表の大きさを小さくすることはできません
7327この方法で L<C<keys>|/keys HASH> を使うことで、表の大きさを小さくすることは
7328できません
59407329(間違えてそのようなことをしても何も起きないので気にすることはありません)。
59417330左辺値コンテキストでの C<keys @array> は文法エラーとなります。
59427331
59437332=begin original
59447333
5945Starting with Perl 5.14, C<keys> can take a scalar EXPR, which must contain
7334Starting with Perl 5.14, an experimental feature allowed
5946a reference to an unblessed hash or array. The argument will be
7335L<C<keys>|/keys HASH> to take a scalar expression. This experiment has
5947dereferenced automatically. This aspect of C<keys> is considered highly
7336been deemed unsuccessful, and was removed as of Perl 5.24.
5948experimental. The exact behaviour may change in a future version of Perl.
59497337
59507338=end original
59517339
5952Perl 5.14 から、C<keys> スカラの EXPR を取ることができになりました;
7340Perl 5.14 から、L<C<keys>|/keys HASH> がスカラを取ることが出来とい
5953これは bless されていないハッシュや配列へのリファレンスでなければなりません
7341実験的機能がありました
5954引数自動的にデリファレンスされま
7342この実験失敗と見なされ、Perl 5.24 で削除されした
5955C<keys> のこの動作は高度に実験的であると考えられています。
5956正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
59577343
5958 for (keys $hashref) { ... }
7344=begin original
5959 for (keys $obj->get_arrayref) { ... }
59607345
7346To avoid confusing would-be users of your code who are running earlier
7347versions of Perl with mysterious syntax errors, put this sort of thing at
7348the top of your file to signal that your code will work I<only> on Perls of
7349a recent vintage:
7350
7351=end original
7352
7353あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
7354文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
7355I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
7356書いてください:
7357
7358 use 5.012; # so keys/values/each work on arrays
7359
59617360=begin original
59627361
5963See also C<each>, C<values>, and C<sort>.
7362See also L<C<each>|/each HASH>, L<C<values>|/values HASH>, and
7363L<C<sort>|/sort SUBNAME LIST>.
59647364
59657365=end original
59667366
5967C<each>, C<values>, C<sort> も参照してください。
7367L<C<each>|/each HASH>, L<C<values>|/values HASH>,
7368L<C<sort>|/sort SUBNAME LIST> も参照してください。
59687369
59697370=item kill SIGNAL, LIST
7371
7372=item kill SIGNAL
59707373X<kill> X<signal>
59717374
7375=for Pod::Functions send a signal to a process or process group
7376
59727377=begin original
59737378
5974Sends a signal to a list of processes. Returns the number of
7379Sends a signal to a list of processes. Returns the number of arguments
5975processes successfully signaled (which is not necessarily the
7380that were successfully used to signal (which is not necessarily the same
5976same as the number actually killed).
7381as the number of processes actually killed, e.g. where a process group is
7382killed).
59777383
59787384=end original
59797385
5980プロセスのリストにシグナルを送ります。シグナル送信に成功したプロセスの
7386プロセスのリストにシグナルを送ります。
5981数を返します
7387シグナル送信に使われた引数の数を返します
5982(実際に kill に成功しプロセスと同じとは限りません)。
7388(例えばプロセスグループが kill された場合のように、実際に kill され
7389プロセスの数と同じとは限りません)。
59837390
5984 $cnt = kill 1, $child1, $child2;
7391 my $cnt = kill 'HUP', $child1, $child2;
5985 kill 9, @goners;
7392 kill 'KILL', @goners;
59867393
59877394=begin original
59887395
5989If SIGNAL is zero, no signal is sent to the process, but C<kill>
7396SIGNAL may be either a signal name (a string) or a signal number. A signal
5990checks whether it's I<possible> to send a signal to it (that
7397name may start with a C<SIG> prefix, thus C<FOO> and C<SIGFOO> refer to the
5991means, to be brief, that the process is owned by the same user, or we are
7398same signal. The string form of SIGNAL is recommended for portability because
5992the super-user). This is useful to check that a child process is still
7399the same signal may have different numbers in different operating systems.
5993alive (even if only as a zombie) and hasn't changed its UID. See
5994L<perlport> for notes on the portability of this construct.
59957400
59967401=end original
59977402
5998SIGNAL がゼロの場合、プロセスにシグナルは送れませんが、
7403SIGNAL シグナル名(文字列)かシグナル番号のどちかです。
5999C<kill> は、シグナルを送ることが I<可能> かどうかを調べます
7404シグナル名は C<SIG> 接頭辞で始まることがあるので、C<FOO> と C<SIGFOO> は同じ
6000(これは、簡単に言うと、プロセスが同じユーザーに所有されているか、
7405シグナルを意味します。
6001自分スーパーユーザーであることを意味します)。
7406移植性から文字列形式の SIGNAL 推奨されます; 同じシグナルが異なった
6002これは子プロセスが(ゾビとしてだけも)まだ生きていて、 UID
7407オペレーティグシステムは異なった番号になることあるからです。
6003変わっていないことを調べる時に有用です。
6004この構成の移植性に関する注意については L<perlport> を参照して下さい。
60057408
60067409=begin original
60077410
6008Unlike in the shell, if SIGNAL is negative, it kills process groups instead
7411A list of signal names supported by the current platform can be found in
6009of processes. That means you usually want to use positive not negative signals.
7412C<$Config{sig_name}>, which is provided by the L<C<Config>|Config>
6010You may also use a signal name in quotes.
7413module. See L<Config> for more details.
60117414
60127415=end original
60137416
6014ェルとは異なり、シグナルに負数を与えると
7417現在のプラットフォームが対応しているシグナル一覧はL<C<Config>|Config>
7418モジュールによって提供される C<$Config{sig_name}> にあります。
7419さらなる詳細については L<Config> を参照してください。
7420
7421=begin original
7422
7423A negative signal name is the same as a negative signal number, killing process
7424groups instead of processes. For example, C<kill '-KILL', $pgrp> and
7425C<kill -9, $pgrp> will send C<SIGKILL> to
7426the entire process group specified. That
7427means you usually want to use positive not negative signals.
7428
7429=end original
7430
7431負のシグナル名は負のシグナル番号と同じで、
60157432プロセスではなくプロセスグループに対して kill を行ないます。
7433たとえば、C<kill '-KILL', $pgrp> と C<kill -9, $pgrp> は指定された
7434プロセスグループ全体に C<SIGKILL> を送ります。
60167435すなわち、通常は、負のシグナルは用いず、正のシグナルを使うことになります。
6017シグナル名をクォートして使うこともできます。
60187436
60197437=begin original
60207438
7439If SIGNAL is either the number 0 or the string C<ZERO> (or C<SIGZERO>),
7440no signal is sent to the process, but L<C<kill>|/kill SIGNAL, LIST>
7441checks whether it's I<possible> to send a signal to it
7442(that means, to be brief, that the process is owned by the same user, or we are
7443the super-user). This is useful to check that a child process is still
7444alive (even if only as a zombie) and hasn't changed its UID. See
7445L<perlport> for notes on the portability of this construct.
7446
7447=end original
7448
7449SIGNAL が数値 0 か文字列 C<ZERO> (または C<SIGZERO> の場合、プロセスに
7450シグナルは送られませんが、L<C<kill>|/kill SIGNAL, LIST> は、
7451シグナルを送ることが I<可能> かどうかを調べます (これは、簡単に言うと、
7452プロセスが同じユーザーに所有されているか、自分がスーパーユーザーであることを
7453意味します)。
7454これは子プロセスが(ゾンビとしてだけでも)まだ生きていて、 UID が
7455変わっていないことを調べる時に有用です。
7456この構成の移植性に関する注意については L<perlport> を参照してください。
7457
7458=begin original
7459
60217460The behavior of kill when a I<PROCESS> number is zero or negative depends on
60227461the operating system. For example, on POSIX-conforming systems, zero will
6023signal the current process group and -1 will signal all processes.
7462signal the current process group, -1 will signal all processes, and any
7463other negative PROCESS number will act as a negative signal number and
7464kill the entire process group specified.
60247465
60257466=end original
60267467
60277468I<PROCESS> 番号が 0 あるいは負数の場合の kill の振る舞いは
60287469オペレーティングシステムに依存します。
60297470例えば、POSIX 準拠のシステムでは、0 は現在のプロセスグループにシグナルを送り、
6030-1 は全てのプロセスにシグナルを送ります。
7471-1 は全てのプロセスにシグナルを送り、それ以外の負数の PROCESS 番号は
7472負数のシグナル番号として動作し、指定されたプロセスグループ全体を kill します。
60317473
60327474=begin original
60337475
7476If both the SIGNAL and the PROCESS are negative, the results are undefined.
7477A warning may be produced in a future version.
7478
7479=end original
7480
7481SIGNAL と PROCESS の両方が負数の場合、結果は未定義です。
7482将来のバージョンでは警告が出るかも知れません。
7483
7484=begin original
7485
60347486See L<perlipc/"Signals"> for more details.
60357487
60367488=end original
60377489
60387490詳細は L<perlipc/"Signals"> を参照してください。
60397491
7492=begin original
7493
7494On some platforms such as Windows where the L<fork(2)> system call is not
7495available, Perl can be built to emulate L<C<fork>|/fork> at the
7496interpreter level.
7497This emulation has limitations related to kill that have to be considered,
7498for code running on Windows and in code intended to be portable.
7499
7500=end original
7501
7502Windows のような L<fork(2)> が利用不能なシステムでは、Perl は
7503L<C<fork>|/fork> をインタプリタレベルでエミュレートします。
7504エミュレーションは kill に関連して、コードが Windows で実行されて
7505しかしコードが移植性があると考えられるように制限があります。
7506
7507=begin original
7508
7509See L<perlfork> for more details.
7510
7511=end original
7512
7513さらなる詳細については L<perlfork> を参照してください。
7514
7515=begin original
7516
7517If there is no I<LIST> of processes, no signal is sent, and the return
7518value is 0. This form is sometimes used, however, because it causes
7519tainting checks to be run. But see
7520L<perlsec/Laundering and Detecting Tainted Data>.
7521
7522=end original
7523
7524処理する I<LIST> がない場合、シグナルは送られず、返り値は 0 です。
7525しかし、この形式は時々使われます; 実行するために汚染チェックを
7526引き起こすからです。
7527しかし L<perlsec/Laundering and Detecting Tainted Data> を参照してください。
7528
7529=begin original
7530
7531Portability issues: L<perlport/kill>.
7532
7533=end original
7534
7535移植性の問題: L<perlport/kill>。
7536
60407537=item last LABEL
60417538X<last> X<break>
60427539
7540=item last EXPR
7541
60437542=item last
60447543
7544=for Pod::Functions exit a block prematurely
7545
60457546=begin original
60467547
6047The C<last> command is like the C<break> statement in C (as used in
7548The L<C<last>|/last LABEL> command is like the C<break> statement in C
7549(as used in
60487550loops); it immediately exits the loop in question. If the LABEL is
6049omitted, the command refers to the innermost enclosing loop. The
7551omitted, the command refers to the innermost enclosing
6050C<continue> block, if any, is not executed:
7552loop. The C<last EXPR> form, available starting in Perl
75535.18.0, allows a label name to be computed at run time,
7554and is otherwise identical to C<last LABEL>. The
7555L<C<continue>|/continue BLOCK> block, if any, is not executed:
60517556
60527557=end original
60537558
6054C<last> コマンドは、(ループ内で使った) C の C<break> 文と
7559L<C<last>|/last LABEL> コマンドは、(ループ内で使った) C の C<break> 文と
60557560同じようなもので、LABEL で指定されるループを即座に抜けます。
6056LABEL が省略されると、一番内側のループが対象となります。
7561LABEL が省略されると、コマンドは一番内側のループを参照します。
6057C<continue> ブロックがあっても実行されません:
7562Perl 5.18.0 から利用可能な C<last EXPR> 形式では、実行時に計算され
7563ラベル名を使えます; それ以外は C<last LABEL> と同一です。
7564L<C<continue>|/continue BLOCK> ブロックがあっても実行されません:
60587565
60597566 LINE: while (<STDIN>) {
60607567 last LINE if /^$/; # exit when done with header
60617568 #...
60627569 }
60637570
60647571=begin original
60657572
6066C<last> cannot be used to exit a block that returns a value such as
7573L<C<last>|/last LABEL> cannot be used to exit a block that returns a
6067C<eval {}>, C<sub {}>, or C<do {}>, and should not be used to exit
7574value such as C<eval {}>, C<sub {}>, or C<do {}>, and should not be used
6068a grep() or map() operation.
7575to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST>
7576operation.
60697577
60707578=end original
60717579
6072C<last> は C<eval {}>, C<sub {}>, C<do {}> といった
7580L<C<last>|/last LABEL> は C<eval {}>, C<sub {}>, C<do {}> といった
60737581値を返すブロックを終了するのには使えませんし、
6074grep() や map() 操作を終了するのに使うべきではありません。
7582L<C<grep>|/grep BLOCK LIST> L<C<map>|/map BLOCK LIST> 操作を終了するのに
7583使うべきではありません。
60757584
60767585=begin original
60777586
60787587Note that a block by itself is semantically identical to a loop
6079that executes once. Thus C<last> can be used to effect an early
7588that executes once. Thus L<C<last>|/last LABEL> can be used to effect
6080exit out of such a block.
7589an early exit out of such a block.
60817590
60827591=end original
60837592
6084ブロックはそれ体文法的には一だけ実行されるループと同であることに
7593ブロック自は一だけ実行されるループと文法的にであることに
6085注意してください。従って、C<last> でそのようなブロックを
7594注意してください。
6086途中で抜け出すことができます。
7595従って、L<C<last>|/last LABEL> でそのようなブロックを途中で
7596抜け出すことができます。
60877597
60887598=begin original
60897599
6090See also L</continue> for an illustration of how C<last>, C<next>, and
7600See also L<C<continue>|/continue BLOCK> for an illustration of how
6091C<redo> work.
7601L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and
7602L<C<redo>|/redo LABEL> work.
60927603
60937604=end original
60947605
6095C<last>, C<next>, C<redo> がどのように働くかについては
7606L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL>
6096L</continue> も参照してさい。
7607どのように働くかについては L<C<continue>|/continue BLOCK> も参照してください。
60977608
7609=begin original
7610
7611Unlike most named operators, this has the same precedence as assignment.
7612It is also exempt from the looks-like-a-function rule, so
7613C<last ("foo")."bar"> will cause "bar" to be part of the argument to
7614L<C<last>|/last LABEL>.
7615
7616=end original
7617
7618ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
7619また、関数のように見えるものの規則からも免れるので、C<last ("foo")."bar"> と
7620すると "bar" は L<C<last>|/last LABEL> への引数の一部となります。
7621
60987622=item lc EXPR
60997623X<lc> X<lowercase>
61007624
61017625=item lc
61027626
7627=for Pod::Functions return lower-case version of a string
7628
61037629=begin original
61047630
61057631Returns a lowercased version of EXPR. This is the internal function
61067632implementing the C<\L> escape in double-quoted strings.
61077633
61087634=end original
61097635
61107636EXPR を小文字に変換したものを返します。
61117637これは、ダブルクォート文字列における、
61127638C<\L> エスケープを実装する内部関数です。
61137639
61147640=begin original
61157641
6116If EXPR is omitted, uses C<$_>.
7642If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
61177643
61187644=end original
61197645
6120EXPR が省略されると、C<$_> を使います。
7646EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
61217647
61227648=begin original
61237649
61247650What gets returned depends on several factors:
61257651
61267652=end original
61277653
61287654返り値として得られるものは色々な要素に依存します:
61297655
61307656=over
61317657
61327658=item If C<use bytes> is in effect:
61337659
61347660(C<use bytes> が有効の場合)
61357661
6136=over
6137
6138=item On EBCDIC platforms
6139
61407662=begin original
61417663
6142The results are what the C language system call C<tolower()> returns.
7664The results follow ASCII rules. Only the characters C<A-Z> change,
7665to C<a-z> respectively.
61437666
61447667=end original
61457668
6146結果は、C 言語のシステムコール C<tolower()> が返すもす。
7669結果は ASCII規則に従います。
7670C<A-Z> のみが変換され、それぞれ C<a-z> になります。
61477671
6148=item On ASCII platforms
7672=item Otherwise, if C<use locale> for C<LC_CTYPE> is in effect:
61497673
7674(それ以外の場合で、C<LC_CTYPE> に対して C<use locale> が有効の場合)
7675
61507676=begin original
61517677
6152The results follow ASCII semantics. Only characters C<A-Z> change, to C<a-z>
7678Respects current C<LC_CTYPE> locale for code points < 256; and uses Unicode
6153respectively.
7679rules for the remaining code points (this last can only happen if
7680the UTF8 flag is also set). See L<perllocale>.
61547681
61557682=end original
61567683
6157結果ASCII の意味論に従います
7684符号位置 < 256 に対して現在の C<LC_CTYPE> ロケールに従います; そして
6158C<A-Z> みが変換され、それぞれ C<a-z> になります
7685残り符号位置に付いては Unicode の規則を使います (これは UTF8 フラグも
7686設定されている場合にのみ起こります)。
7687L<perllocale> を参照してください。
61597688
6160=back
6161
6162=item Otherwise, If EXPR has the UTF8 flag set
6163
6164(その他の場合で、EXPR に UTF8 フラグがセットされている場合)
6165
61667689=begin original
61677690
6168If the current package has a subroutine named C<ToLower>, it will be used to
7691Starting in v5.20, Perl uses full Unicode rules if the locale is
6169change the case
7692UTF-8. Otherwise, there is a deficiency in this scheme, which is that
6170(See L<perlunicode/"User-Defined Case Mappings (for serious hackers only)">.)
7693case changes that cross the 255/256
6171Otherwise Unicode semantics are used for the case change.
7694boundary are not well-defined. For example, the lower case of LATIN CAPITAL
7695LETTER SHARP S (U+1E9E) in Unicode rules is U+00DF (on ASCII
7696platforms). But under C<use locale> (prior to v5.20 or not a UTF-8
7697locale), the lower case of U+1E9E is
7698itself, because 0xDF may not be LATIN SMALL LETTER SHARP S in the
7699current locale, and Perl has no way of knowing if that character even
7700exists in the locale, much less what code point it is. Perl returns
7701a result that is above 255 (almost always the input character unchanged),
7702for all instances (and there aren't many) where the 255/256 boundary
7703would otherwise be crossed; and starting in v5.22, it raises a
7704L<locale|perldiag/Can't do %s("%s") on non-UTF-8 locale; resolved to "%s".> warning.
61727705
61737706=end original
61747707
6175現在のパッケージで C<ToLower> という名前サブルーチンがある場合
7708v5.20 から、ロケールが UTF-8 の場合は Perl は完全な Unicode の規則を使います。
6176大文字小文字変換するためにこれが使われます
7709さもなければ、この手法には、255/266 の境界をまたぐ大文字小文字変換
6177(L<perlunicode/"User-Defined Case Mappings (for serious hackers only)"> を
7710未定義であるという欠点があります。
6178参照してください)
7711例えば、Unicode での LATIN CAPITAL LETTER SHARP S (U+1E9E) の小文字は
6179さもなければ、大文字小文字変換には Unicode の意味論が使われます。
7712(ASCII プラットフォームで) U+00DF す。
7713しかし C<use locale> が有効(v5.20 より前か、UTF-8 ロケール以外)なら、U+1E9E の
7714小文字は自分自身です; なぜなら 0xDF は現在のロケールでは
7715LATIN SMALL LETTER SHARP S ではなく、Perl は例えこのロケールに文字が
7716存在するかどうかを知る方法がなく、ましてどの符号位置かを知る方法が
7717ないからです。
7718Perl は 255/256 境界をまたぐ全ての(多くはありません)実体については
7719(ほとんど常に入力文字を変更せずに)256 以上の値を返します;
7720そして v5.22 から
7721L<locale|perldiag/Can't do %s("%s") on non-UTF-8 locale; resolved to "%s".>
7722警告を出力します。
61807723
6181=item Otherwise, if C<use locale> is in effect
7724=item Otherwise, If EXPR has the UTF8 flag set:
61827725
6183(それ以外の場合で、C<use locale>有効の場合)
7726(その他の場合で、EXPR UTF8 フラグセットされている場合)
61847727
61857728=begin original
61867729
6187Respects current LC_CTYPE locale. See L<perllocale>.
7730Unicode rules are used for the case change.
61887731
61897732=end original
61907733
6191現在の LC_CTYPE ロケールに従います。
7734大文字小文字変換には Unicode の規則が使われます。
6192L<perllocale> を参照してください。
61937735
6194=item Otherwise, if C<use feature 'unicode_strings'> is in effect:
7736=item Otherwise, if C<use feature 'unicode_strings'> or C<use locale ':not_characters'> is in effect:
61957737
6196(それ以外の場合で、C<use feature 'unicode_strings'> が有効の場合)
7738(それ以外の場合で、C<use feature 'unicode_strings'> か C<use locale ':not_characters'> が有効の場合)
61977739
61987740=begin original
61997741
6200Unicode semantics are used for the case change. Any subroutine named
7742Unicode rules are used for the case change.
6201C<ToLower> will be ignored.
62027743
62037744=end original
62047745
6205大文字小文字変換には Unicode の意味論が使われます。
7746大文字小文字変換には Unicode の規則が使われます。
6206C<ToLower> という名前のサブルーチンは無視されます。
62077747
62087748=item Otherwise:
62097749
62107750(それ以外の場合)
62117751
6212=over
6213
6214=item On EBCDIC platforms
6215
62167752=begin original
62177753
6218The results are what the C language system call C<tolower()> returns.
7754ASCII rules are used for the case change. The lowercase of any character
6219
6220=end original
6221
6222結果は、C 言語のシステムコール C<tolower()> が返すものです。
6223
6224=item On ASCII platforms
6225
6226=begin original
6227
6228ASCII semantics are used for the case change. The lowercase of any character
62297755outside the ASCII range is the character itself.
62307756
62317757=end original
62327758
6233大文字小文字変換には ASCII の意味論が使われます。
7759大文字小文字変換には ASCII の規則が使われます。
62347760ASCII の範囲外の文字の「小文字」はその文字自身です。
62357761
62367762=back
62377763
6238=back
6239
62407764=item lcfirst EXPR
62417765X<lcfirst> X<lowercase>
62427766
62437767=item lcfirst
62447768
7769=for Pod::Functions return a string with just the next letter in lower case
7770
62457771=begin original
62467772
62477773Returns the value of EXPR with the first character lowercased. This
62487774is the internal function implementing the C<\l> escape in
62497775double-quoted strings.
62507776
62517777=end original
62527778
62537779最初の文字だけを小文字にした、EXPR を返します。
62547780これは、ダブルクォート文字列における、C<\l> エスケープを
62557781実装する内部関数です。
62567782
62577783=begin original
62587784
6259If EXPR is omitted, uses C<$_>.
7785If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
62607786
62617787=end original
62627788
6263EXPR が省略されると、C<$_> を使います。
7789EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
62647790
62657791=begin original
62667792
6267This function behaves the same way under various pragmata, such as in a locale,
7793This function behaves the same way under various pragmas, such as in a locale,
6268as L</lc> does.
7794as L<C<lc>|/lc EXPR> does.
62697795
62707796=end original
62717797
62727798この関数は、ロケールのようなさまざまなプラグマの影響下では、
6273L</lc> と同様に振る舞います。
7799L<C<lc>|/lc EXPR> と同様に振る舞います。
62747800
62757801=item length EXPR
62767802X<length> X<size>
62777803
62787804=item length
62797805
7806=for Pod::Functions return the number of characters in a string
7807
62807808=begin original
62817809
62827810Returns the length in I<characters> of the value of EXPR. If EXPR is
6283omitted, returns the length of C<$_>. If EXPR is undefined, returns
7811omitted, returns the length of L<C<$_>|perlvar/$_>. If EXPR is
6284C<undef>.
7812undefined, returns L<C<undef>|/undef EXPR>.
62857813
62867814=end original
62877815
62887816EXPR の値の I<文字> の長さを返します。
6289EXPR が省略されたときには、C<$_> の長さを返します。
7817EXPR が省略されたときには、L<C<$_>|perlvar/$_> の長さを返します。
6290EXPR が未定義値の場合、C<undef> を返します。
7818EXPR が未定義値の場合、L<C<undef>|/undef EXPR> を返します。
62917819
62927820=begin original
62937821
62947822This function cannot be used on an entire array or hash to find out how
62957823many elements these have. For that, use C<scalar @array> and C<scalar keys
62967824%hash>, respectively.
62977825
62987826=end original
62997827
63007828この関数は配列やハッシュ全体に対してどれだけの要素を含んでいるかを
63017829調べるためには使えません。
63027830そのような用途には、それぞれ C<scalar @array> と C<scalar keys %hash> を
63037831利用してください。
63047832
63057833=begin original
63067834
6307Like all Perl character operations, length() normally deals in logical
7835Like all Perl character operations, L<C<length>|/length EXPR> normally
7836deals in logical
63087837characters, not physical bytes. For how many bytes a string encoded as
63097838UTF-8 would take up, use C<length(Encode::encode_utf8(EXPR))> (you'll have
63107839to C<use Encode> first). See L<Encode> and L<perlunicode>.
63117840
63127841=end original
63137842
6314全ての Perl の文字操作と同様、length() は通常物理的なバイトではなく
7843全ての Perl の文字操作と同様、L<C<length>|/length EXPR> は通常物理的な
6315論理文字を扱います。
7844バイトではなく論理文字を扱います。
63167845UTF-8 でエンコードされた文字列が何バイトかを知るには、
63177846C<length(Encode::encode_utf8(EXPR))> を使ってください (先に
63187847C<use Encode> する必要があります)。
63197848L<Encode> と L<perlunicode> を参照してください。
63207849
7850=item __LINE__
7851X<__LINE__>
7852
7853=for Pod::Functions the current source line number
7854
7855=begin original
7856
7857A special token that compiles to the current line number.
7858
7859=end original
7860
7861現在の行番号にコンパイルされる特殊トークン。
7862
63217863=item link OLDFILE,NEWFILE
63227864X<link>
63237865
7866=for Pod::Functions create a hard link in the filesystem
7867
63247868=begin original
63257869
63267870Creates a new filename linked to the old filename. Returns true for
63277871success, false otherwise.
63287872
63297873=end original
63307874
63317875OLDFILE にリンクされた、新しいファイル NEWFILE を作ります。
6332成功時には true を、失敗時には false を返します。
7876成功時にはを、さもなければ偽を返します。
63337877
7878=begin original
7879
7880Portability issues: L<perlport/link>.
7881
7882=end original
7883
7884移植性の問題: L<perlport/link>。
7885
63347886=item listen SOCKET,QUEUESIZE
63357887X<listen>
63367888
7889=for Pod::Functions register your socket as a server
7890
63377891=begin original
63387892
6339Does the same thing that the listen(2) system call does. Returns true if
7893Does the same thing that the L<listen(2)> system call does. Returns true if
63407894it succeeded, false otherwise. See the example in
63417895L<perlipc/"Sockets: Client/Server Communication">.
63427896
63437897=end original
63447898
6345listen(2) システムコールと同じことをします。成功時には真を返し、
7899L<listen(2)> システムコールと同じことをします。
6346失敗時には偽を返します。
7900成功時には真を、さもなければ偽を返します。
6347L<perlipc/"Sockets: Client/Server Communication">の例を参照してください。
7901L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
63487902
63497903=item local EXPR
63507904X<local>
63517905
7906=for Pod::Functions create a temporary value for a global variable (dynamic scoping)
7907
63527908=begin original
63537909
6354You really probably want to be using C<my> instead, because C<local> isn't
7910You really probably want to be using L<C<my>|/my VARLIST> instead,
6355what most people think of as "local". See
7911because L<C<local>|/local EXPR> isn't what most people think of as
6356L<perlsub/"Private Variables via my()"> for details.
7912"local". See L<perlsub/"Private Variables via my()"> for details.
63577913
63587914=end original
63597915
6360あなたはが本当に望んでいるのは C<my> の方でしょう
7916あなたはが本当に望んでいるのは L<C<my>|/my VARLIST> の方でしょう;
6361C<local> はほとんどの人々が「ローカル」と考えるものと違うからです。
7917L<C<local>|/local EXPR> はほとんどの人々が「ローカル」と考えるものと
7918違うからです。
63627919詳細は L<perlsub/"Private Variables via my()"> を参照してください。
63637920
63647921=begin original
63657922
63667923A local modifies the listed variables to be local to the enclosing
63677924block, file, or eval. If more than one value is listed, the list must
63687925be placed in parentheses. See L<perlsub/"Temporary Values via local()">
63697926for details, including issues with tied arrays and hashes.
63707927
63717928=end original
63727929
63737930"local" はリストアップされた変数を、囲っているブロック、
63747931ファイル、eval の中で、ローカルなものにします。
6375複数の値を指定する場合は、リストは括弧でくくらなければなりません。
7932複数の値を指定する場合は、リストはかっこでくくらなければなりません。
63767933tie した配列とハッシュに関する事項を含む詳細については
63777934L<perlsub/"Temporary Values via local()"> を参照してください。
63787935
63797936=begin original
63807937
63817938The C<delete local EXPR> construct can also be used to localize the deletion
63827939of array/hash elements to the current block.
63837940See L<perlsub/"Localized deletion of elements of composite types">.
63847941
63857942=end original
63867943
63877944C<delete local EXPR> 構文は、配列/ハッシュの要素の削除を現在の
63887945ブロックにローカル化するためにも使われていました。
63897946L<perlsub/"Localized deletion of elements of composite types"> を
63907947参照してください。
63917948
63927949=item localtime EXPR
63937950X<localtime> X<ctime>
63947951
63957952=item localtime
63967953
7954=for Pod::Functions convert UNIX time into record or string using local time
7955
63977956=begin original
63987957
63997958Converts a time as returned by the time function to a 9-element list
64007959with the time analyzed for the local time zone. Typically used as
64017960follows:
64027961
64037962=end original
64047963
64057964time 関数が返す時刻を、ローカルなタイムゾーンで測った時刻として、
640679659 要素の配列に変換します。
6407は、以下のようにして使用します
7966通は、以下のようにして使ます:
64087967
6409 # 0 1 2 3 4 5 6 7 8
7968 # 0 1 2 3 4 5 6 7 8
6410 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
7969 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
64117970 localtime(time);
64127971
64137972=begin original
64147973
64157974All list elements are numeric and come straight out of the C `struct
64167975tm'. C<$sec>, C<$min>, and C<$hour> are the seconds, minutes, and hours
64177976of the specified time.
64187977
64197978=end original
64207979
64217980すべてのリスト要素は数値で、C の `struct tm' 構造体から
64227981直接持ってきます。
64237982C<$sec>, C<$min>, C<$hour> は指定された時刻の秒、分、時です。
64247983
64257984=begin original
64267985
64277986C<$mday> is the day of the month and C<$mon> the month in
64287987the range C<0..11>, with 0 indicating January and 11 indicating December.
64297988This makes it easy to get a month name from a list:
64307989
64317990=end original
64327991
6433C<$mday> は月の何日目か、C<$mon> は月の値です
7992C<$mday> は月の何日目か、C<$mon> は月の値です; 月の値は C<0..11> で、0 が
6434月の値は C<0..11> で、0 が 1 月、11 が 12 月です。
79931 月、11 が 12 月です。
64357994これにより、リストから月の名前を得るのが簡単になります:
64367995
6437 my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
7996 my @abbr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
64387997 print "$abbr[$mon] $mday";
64397998 # $mon=9, $mday=18 gives "Oct 18"
64407999
64418000=begin original
64428001
6443C<$year> is the number of years since 1900, B<not> just the last two digits
8002C<$year> contains the number of years since 1900. To get a 4-digit
6444of the year. That is, C<$year> is C<123> in year 2023. The proper way
8003year write:
6445to get a 4-digit year is simply:
64468004
64478005=end original
64488006
6449C<$year> は 1900 年からの年数であり、単に西暦の下 2 桁表しているのでは
8007C<$year> は 1900 年からの年数を持ちます。
6450B<ありせん>。
80084 桁の年を得るには以下のようにしす:
6451つまり、$year が C<123> なら 2023 年です。
64524 桁の西暦を得るには単に以下のようにしてください:
64538009
64548010 $year += 1900;
64558011
64568012=begin original
64578013
6458Otherwise you create non-Y2K-compliant programs--and you wouldn't want
6459to do that, would you?
6460
6461=end original
6462
6463さもなければ、Y2K 問題を含んだプログラムを作ることになります --
6464それはお望みじゃないでしょう?
6465
6466=begin original
6467
64688014To get the last two digits of the year (e.g., "01" in 2001) do:
64698015
64708016=end original
64718017
64728018西暦の下 2 桁(2001 年では "01")がほしい場合は以下のようにします:
64738019
64748020 $year = sprintf("%02d", $year % 100);
64758021
64768022=begin original
64778023
64788024C<$wday> is the day of the week, with 0 indicating Sunday and 3 indicating
64798025Wednesday. C<$yday> is the day of the year, in the range C<0..364>
64808026(or C<0..365> in leap years.)
64818027
64828028=end original
64838029
64848030C<$wday> は曜日で、0 が日曜日、3 が水曜日です。
64858031C<$yday> はその年の何日目かで、C<0..364> の値を取ります
6486(うるう年は C<0..365> です)
8032(うるう年は C<0..365> です。)
64878033
64888034=begin original
64898035
64908036C<$isdst> is true if the specified time occurs during Daylight Saving
64918037Time, false otherwise.
64928038
64938039=end original
64948040
64958041C<$isdst> は指定された時刻が夏時間の場合は真、そうでなければ偽です。
64968042
64978043=begin original
64988044
6499If EXPR is omitted, C<localtime()> uses the current time (as returned
8045If EXPR is omitted, L<C<localtime>|/localtime EXPR> uses the current
6500by time(3)).
8046time (as returned by L<C<time>|/time>).
65018047
65028048=end original
65038049
6504EXPR が省略されると、C<localtime()> は(time(3) によって返される)
8050EXPR が省略されると、L<C<localtime>|/localtime EXPR> は
6505現在時刻を使います。
8051(L<C<time>|/time> によって返される) 現在時刻を使います。
65068052
65078053=begin original
65088054
6509In scalar context, C<localtime()> returns the ctime(3) value:
8055In scalar context, L<C<localtime>|/localtime EXPR> returns the
8056L<ctime(3)> value:
65108057
65118058=end original
65128059
6513スカラコンテキストでは、C<localtime()> は ctime(3) の値を返します:
8060スカラコンテキストでは、L<C<localtime>|/localtime EXPR> L<ctime(3)> の値を
8061返します:
65148062
6515 $now_string = localtime; # e.g., "Thu Oct 13 04:54:34 1994"
8063 my $now_string = localtime; # e.g., "Thu Oct 13 04:54:34 1994"
65168064
65178065=begin original
65188066
6519This scalar value is B<not> locale-dependent but is a Perl builtin. For GMT
8067The format of this scalar value is B<not> locale-dependent but built
6520instead of local time use the L</gmtime> builtin. See also the
8068into Perl. For GMT instead of local time use the
6521C<Time::Local> module (for converting seconds, minutes, hours, and such back to
8069L<C<gmtime>|/gmtime EXPR> builtin. See also the
6522the integer value returned by time()), and the L<POSIX> module's strftime(3)
8070L<C<Time::Local>|Time::Local> module (for converting seconds, minutes,
6523and mktime(3) functions.
8071hours, and such back to the integer value returned by L<C<time>|/time>),
8072and the L<POSIX> module's L<C<strftime>|POSIX/C<strftime>> and
8073L<C<mktime>|POSIX/C<mktime>> functions.
65248074
65258075=end original
65268076
6527スカラ値はロケール依存 B<ではなく>、Perl の組み込みの値です。
8077このスカラ値の形式はロケール依存 B<ではなく>、Perl の組み込みの値です。
6528ローカル時刻ではなく GMT がほしい場合は L</gmtime> 組み込み関数を
8078ローカル時刻ではなく GMT がほしい場合は L<C<gmtime>|/gmtime EXPR> 組み込み
6529使ってください。
8079関数を使ってください。
6530また、(秒、分、時などの形から、time() が返す値である
8080また、(秒、分、時などの形から、L<C<time>|/time> が返す値である
65311970 年 1 月 1 日の真夜中からの秒数に変換する) C<Time::Local> モジュール
80811970 年 1 月 1 日の真夜中からの秒数に変換する)
6532及び POSIX モジュールで提供される strftime(3) と mktime(3) 関数も
8082L<C<Time::Local>|Time::Local> モジュール及び L<POSIX> モジュールで提供される
8083L<C<strftime>|POSIX/C<strftime>> と L<C<mktime>|POSIX/C<mktime>> 関数も
65338084参照してください。
65348085
65358086=begin original
65368087
65378088To get somewhat similar but locale-dependent date strings, set up your
65388089locale environment variables appropriately (please see L<perllocale>) and
65398090try for example:
65408091
65418092=end original
65428093
65438094似たような、しかしロケール依存の日付文字列がほしい場合は、
65448095ロケール環境変数を適切に設定して(L<perllocale> を参照してください)、
65458096以下の例を試してください:
65468097
65478098 use POSIX qw(strftime);
6548 $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;
8099 my $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;
65498100 # or for GMT formatted appropriately for your locale:
6550 $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime;
8101 my $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime;
65518102
65528103=begin original
65538104
6554Note that the C<%a> and C<%b>, the short forms of the day of the week
8105Note that C<%a> and C<%b>, the short forms of the day of the week
65558106and the month of the year, may not necessarily be three characters wide.
65568107
65578108=end original
65588109
65598110曜日と月の短い表現である C<%a> と C<%b> は、3 文字とは限らないことに
65608111注意してください。
65618112
65628113=begin original
65638114
6564See L<perlport/localtime> for portability concerns.
6565
6566=end original
6567
6568移植性については L<perlport/localtime> を参照してください。
6569
6570=begin original
6571
65728115The L<Time::gmtime> and L<Time::localtime> modules provide a convenient,
6573by-name access mechanism to the gmtime() and localtime() functions,
8116by-name access mechanism to the L<C<gmtime>|/gmtime EXPR> and
6574respectively.
8117L<C<localtime>|/localtime EXPR> functions, respectively.
65758118
65768119=end original
65778120
65788121L<Time::gmtime> モジュールと L<Time::localtime> モジュールは、それぞれ
6579gmtime() 関数と localtime() 関数に、名前でアクセスする機構を提供する
8122L<C<gmtime>|/gmtime EXPR> 関数と L<C<localtime>|/localtime EXPR> 関数に、
6580便利なモジュールです。
8123名前でアクセスする機構を提供する便利なモジュールです。
65818124
65828125=begin original
65838126
65848127For a comprehensive date and time representation look at the
65858128L<DateTime> module on CPAN.
65868129
65878130=end original
65888131
65898132包括的な日付と時刻の表現については、CPAN の L<DateTime> モジュールを
65908133参照してください。
65918134
8135=begin original
8136
8137Portability issues: L<perlport/localtime>.
8138
8139=end original
8140
8141移植性の問題: L<perlport/localtime>。
8142
65928143=item lock THING
65938144X<lock>
65948145
8146=for Pod::Functions +5.005 get a thread lock on a variable, subroutine, or method
8147
65958148=begin original
65968149
65978150This function places an advisory lock on a shared variable or referenced
65988151object contained in I<THING> until the lock goes out of scope.
65998152
66008153=end original
66018154
66028155この関数は I<THING> が含む共有変数またはリファレンスされたオブジェクトに、
66038156スコープから出るまでアドバイサリロックを掛けます.
66048157
66058158=begin original
66068159
6607lock() is a "weak keyword" : this means that if you've defined a function
8160The value returned is the scalar itself, if the argument is a scalar, or a
8161reference, if the argument is a hash, array or subroutine.
8162
8163=end original
8164
8165返される値は、引数がスカラならそのスカラ自身、引数がハッシュ、配列、
8166サブルーチンならリファレンスです。
8167
8168=begin original
8169
8170L<C<lock>|/lock THING> is a "weak keyword"; this means that if you've
8171defined a function
66088172by this name (before any calls to it), that function will be called
66098173instead. If you are not under C<use threads::shared> this does nothing.
66108174See L<threads::shared>.
66118175
66128176=end original
66138177
6614lock() は「弱いキーワード」です: もしユーザーが(呼び出し前に)
8178L<C<lock>|/lock THING> は「弱いキーワード」です; もしユーザーが(呼び出し前に)
66158179この名前で関数を定義すると、定義された関数の方が呼び出されます。
66168180C<use threads::shared> の影響下でない場合は、これは何もしません。
66178181L<threads::shared> を参照してください。
66188182
66198183=item log EXPR
66208184X<log> X<logarithm> X<e> X<ln> X<base>
66218185
66228186=item log
66238187
8188=for Pod::Functions retrieve the natural logarithm for a number
8189
66248190=begin original
66258191
66268192Returns the natural logarithm (base I<e>) of EXPR. If EXPR is omitted,
6627returns the log of C<$_>. To get the
8193returns the log of L<C<$_>|perlvar/$_>. To get the
66288194log of another base, use basic algebra:
66298195The base-N log of a number is equal to the natural log of that number
66308196divided by the natural log of N. For example:
66318197
66328198=end original
66338199
66348200EXPR の (I<e> を底とする) 自然対数を返します。
6635EXPR が省略されると、C<$_> の対数を返します。
8201EXPR が省略されると、L<C<$_>|perlvar/$_> の対数を返します。
66368202底の異なる対数を求めるためには、基礎代数を利用してください:
66378203ある数の N を底とする対数は、その数の自然対数を N の自然対数で割ったものです。
6638例:
8204えば:
66398205
66408206 sub log10 {
66418207 my $n = shift;
66428208 return log($n)/log(10);
66438209 }
66448210
66458211=begin original
66468212
6647See also L</exp> for the inverse operation.
8213See also L<C<exp>|/exp EXPR> for the inverse operation.
66488214
66498215=end original
66508216
6651逆操作については L</exp> を参照してさい。
8217逆操作については L<C<exp>|/exp EXPR> を参照してください。
66528218
6653=item lstat EXPR
8219=item lstat FILEHANDLE
66548220X<lstat>
66558221
8222=item lstat EXPR
8223
8224=item lstat DIRHANDLE
8225
66568226=item lstat
66578227
8228=for Pod::Functions stat a symbolic link
8229
66588230=begin original
66598231
6660Does the same thing as the C<stat> function (including setting the
8232Does the same thing as the L<C<stat>|/stat FILEHANDLE> function
6661special C<_> filehandle) but stats a symbolic link instead of the file
8233(including setting the special C<_> filehandle) but stats a symbolic
6662the symbolic link points to. If symbolic links are unimplemented on
8234link instead of the file the symbolic link points to. If symbolic links
6663your system, a normal C<stat> is done. For much more detailed
8235are unimplemented on your system, a normal L<C<stat>|/stat FILEHANDLE>
6664information, please see the documentation for C<stat>.
8236is done. For much more detailed information, please see the
8237documentation for L<C<stat>|/stat FILEHANDLE>.
66658238
66668239=end original
66678240
66688241(特別なファイルハンドルである C<_> の設定を含めて)
6669C<stat> 関数と同じことをしますが、シンボリックリンクが
8242L<C<stat>|/stat FILEHANDLE> 関数と同じことをしますが、シンボリックリンクが
66708243指しているファイルではなく、シンボリックリンク自体の stat をとります。
6671シンボリックリンクがシステムに実装されていないと、通常の C<stat> が行なわれます。
8244シンボリックリンクがシステムに実装されていないと、通常の
6672さらにより詳細な情報については、L<stat> の文書を参照してください
8245L<C<stat>|/stat FILEHANDLE> が行なわれます
8246さらにより詳細な情報については、L<C<stat>|/stat FILEHANDLE> の文書を
8247参照してください。
66738248
66748249=begin original
66758250
6676If EXPR is omitted, stats C<$_>.
8251If EXPR is omitted, stats L<C<$_>|perlvar/$_>.
66778252
66788253=end original
66798254
6680EXPR が省略されると、C<$_> の stat をとります。
8255EXPR が省略されると、L<C<$_>|perlvar/$_> の stat をとります。
66818256
8257=begin original
8258
8259Portability issues: L<perlport/lstat>.
8260
8261=end original
8262
8263移植性の問題: L<perlport/lstat>。
8264
66828265=item m//
66838266
8267=for Pod::Functions match a string with a regular expression pattern
8268
66848269=begin original
66858270
66868271The match operator. See L<perlop/"Regexp Quote-Like Operators">.
66878272
66888273=end original
66898274
66908275マッチ演算子です。
66918276L<perlop/"Regexp Quote-Like Operators"> を参照してください。
66928277
66938278=item map BLOCK LIST
66948279X<map>
66958280
66968281=item map EXPR,LIST
66978282
8283=for Pod::Functions apply a change to a list to get back a new list with the changes
8284
66988285=begin original
66998286
67008287Evaluates the BLOCK or EXPR for each element of LIST (locally setting
6701C<$_> to each element) and returns the list value composed of the
8288L<C<$_>|perlvar/$_> to each element) and returns the list value composed
8289of the
67028290results of each such evaluation. In scalar context, returns the
67038291total number of elements so generated. Evaluates BLOCK or EXPR in
67048292list context, so each element of LIST may produce zero, one, or
67058293more elements in the returned value.
67068294
67078295=end original
67088296
67098297LIST の個々の要素に対して、BLOCK か EXPR を評価し
6710(C<$_> は、ローカルに個々の要素が設定されます) 、
8298(L<C<$_>|perlvar/$_> は、ローカルに個々の要素が設定されます) 、
67118299それぞれの評価結果からなるリスト値が返されます。
67128300スカラコンテキストでは、生成された要素の数を返します。
67138301BLOCK や EXPR をリストコンテキストで評価しますので、LIST の
67148302個々の要素によって作られる、返り値であるリストの要素数は、
671583030 個の場合もあれば、複数の場合もあります。
67168304
6717 @chars = map(chr, @numbers);
8305 my @chars = map(chr, @numbers);
67188306
67198307=begin original
67208308
67218309translates a list of numbers to the corresponding characters.
67228310
67238311=end original
67248312
67258313は、数のリストを対応する文字に変換します。
67268314
67278315 my @squares = map { $_ * $_ } @numbers;
67288316
67298317=begin original
67308318
67318319translates a list of numbers to their squared values.
67328320
67338321=end original
67348322
67358323これは数値のリストを、その 2 乗に変換します。
67368324
67378325 my @squares = map { $_ > 5 ? ($_ * $_) : () } @numbers;
67388326
67398327=begin original
67408328
67418329shows that number of returned elements can differ from the number of
6742input elements. To omit an element, return an empty list ().
8330input elements. To omit an element, return an empty list ().
67438331This could also be achieved by writing
67448332
67458333=end original
67468334
67478335のように、返された要素の数が入力要素の数と異なる場合もあります。
67488336要素を省略するには、空リスト () を返します。
67498337これは以下のように書くことでも達成できて
67508338
67518339 my @squares = map { $_ * $_ } grep { $_ > 5 } @numbers;
67528340
67538341=begin original
67548342
67558343which makes the intention more clear.
67568344
67578345=end original
67588346
67598347この方が目的がよりはっきりします。
67608348
67618349=begin original
67628350
67638351Map always returns a list, which can be
67648352assigned to a hash such that the elements
6765become key/value pairs. See L<perldata> for more details.
8353become key/value pairs. See L<perldata> for more details.
67668354
67678355=end original
67688356
67698357map は常にリストを返し、要素がキー/値の組になるようなハッシュに
67708358代入できます。
67718359さらなる詳細については L<perldata> を参照してください。
67728360
6773 %hash = map { get_a_key_for($_) => $_ } @array;
8361 my %hash = map { get_a_key_for($_) => $_ } @array;
67748362
67758363=begin original
67768364
67778365is just a funny way to write
67788366
67798367=end original
67808368
67818369は以下のものをちょっと変わった書き方で書いたものです。
67828370
6783 %hash = ();
8371 my %hash;
67848372 foreach (@array) {
67858373 $hash{get_a_key_for($_)} = $_;
67868374 }
67878375
67888376=begin original
67898377
6790Note that C<$_> is an alias to the list value, so it can be used to
8378Note that L<C<$_>|perlvar/$_> is an alias to the list value, so it can
6791modify the elements of the LIST. While this is useful and supported,
8379be used to modify the elements of the LIST. While this is useful and
6792it can cause bizarre results if the elements of LIST are not variables.
8380supported, it can cause bizarre results if the elements of LIST are not
6793Using a regular C<foreach> loop for this purpose would be clearer in
8381variables. Using a regular C<foreach> loop for this purpose would be
6794most cases. See also L</grep> for an array composed of those items of
8382clearer in most cases. See also L<C<grep>|/grep BLOCK LIST> for an
6795the original list for which the BLOCK or EXPR evaluates to true.
8383array composed of those items of the original list for which the BLOCK
8384or EXPR evaluates to true.
67968385
67978386=end original
67988387
6799C<$_> は、LIST の値へのエイリアスですので、LIST の要素を
8388L<C<$_>|perlvar/$_> は、LIST の値へのエイリアスですので、LIST の要素を
68008389変更するために使うことができます。
68018390これは、便利でサポートされていますが、
68028391LIST の要素が変数でないと、おかしな結果になります。
68038392この目的には通常の C<foreach> ループを使うことで、ほとんどの場合は
68048393より明確になります。
68058394BLOCK や EXPR が真になる元のリストの要素からなる配列については、
6806L</grep> も参照してください。
8395L<C<grep>|/grep BLOCK LIST> も参照してください。
68078396
68088397=begin original
68098398
6810If C<$_> is lexical in the scope where the C<map> appears (because it has
6811been declared with C<my $_>), then, in addition to being locally aliased to
6812the list elements, C<$_> keeps being lexical inside the block; that is, it
6813can't be seen from the outside, avoiding any potential side-effects.
6814
6815=end original
6816
6817(C<my $_> として宣言されることによって) C<$_> が C<map> が現れるスコープ内で
6818レキシカルな場合は、ローカルではリスト要素へのエイリアスであることに加えて、
6819C<$_> はブロック内でレキシカルでありつづけます; つまり、外側からは見えず、
6820起こりうる副作用を回避します。
6821
6822=begin original
6823
68248399C<{> starts both hash references and blocks, so C<map { ...> could be either
6825the start of map BLOCK LIST or map EXPR, LIST. Because Perl doesn't look
8400the start of map BLOCK LIST or map EXPR, LIST. Because Perl doesn't look
68268401ahead for the closing C<}> it has to take a guess at which it's dealing with
6827based on what it finds just after the C<{>. Usually it gets it right, but if it
8402based on what it finds just after the
8403C<{>. Usually it gets it right, but if it
68288404doesn't it won't realize something is wrong until it gets to the C<}> and
6829encounters the missing (or unexpected) comma. The syntax error will be
8405encounters the missing (or unexpected) comma. The syntax error will be
68308406reported close to the C<}>, but you'll need to change something near the C<{>
6831such as using a unary C<+> to give Perl some help:
8407such as using a unary C<+> or semicolon to give Perl some help:
68328408
68338409=end original
68348410
68358411C<{> はハッシュリファレンスとブロックの両方の開始文字なので、
68368412C<map { ...> は map BLOCK LIST の場合と map EXPR, LIST の場合があります。
68378413Perl は終了文字の C<}> を先読みしないので、C<{> の直後の文字を見て
68388414どちらとして扱うかを推測します。
68398415通常この推測は正しいですが、もし間違った場合は、C<}> まで読み込んで
68408416カンマが足りない(または多い)ことがわかるまで、何かがおかしいことに
68418417気付きません。
6842C<}> の近くで文法エラーが出ますが、Perl を助けるために単項の C<+>
8418C<}> の近くで文法エラーが出ますが、Perl を助けるために単項の C<+>
6843使うというように、C<{> の近くの何かを変更する必要があります。
8419セミコロンを使うというように、C<{> の近くの何かを変更する必要があります。
68448420
6845 %hash = map { "\L$_" => 1 } @array # perl guesses EXPR. wrong
8421 my %hash = map { "\L$_" => 1 } @array # perl guesses EXPR. wrong
6846 %hash = map { +"\L$_" => 1 } @array # perl guesses BLOCK. right
8422 my %hash = map { +"\L$_" => 1 } @array # perl guesses BLOCK. right
6847 %hash = map { ("\L$_" => 1) } @array # this also works
8423 my %hash = map {; "\L$_" => 1 } @array # this also works
6848 %hash = map { lc($_) => 1 } @array # as does this.
8424 my %hash = map { ("\L$_" => 1) } @array # as does this
6849 %hash = map +( lc($_) => 1 ), @array # this is EXPR and works!
8425 my %hash = map { lc($_) => 1 } @array # and this.
8426 my %hash = map +( lc($_) => 1 ), @array # this is EXPR and works!
68508427
6851 %hash = map ( lc($_), 1 ), @array # evaluates to (1, @array)
8428 my %hash = map ( lc($_), 1 ), @array # evaluates to (1, @array)
68528429
68538430=begin original
68548431
68558432or to force an anon hash constructor use C<+{>:
68568433
68578434=end original
68588435
68598436または C<+{> を使って無名ハッシュコンストラクタを強制します:
68608437
6861 @hashes = map +{ lc($_) => 1 }, @array # EXPR, so needs comma at end
8438 my @hashes = map +{ lc($_) => 1 }, @array # EXPR, so needs
8439 # comma at end
68628440
68638441=begin original
68648442
68658443to get a list of anonymous hashes each with only one entry apiece.
68668444
68678445=end original
68688446
68698447こうするとそれぞれ 1 要素だけの無名ハッシュのリストを得られます。
68708448
68718449=item mkdir FILENAME,MASK
68728450X<mkdir> X<md> X<directory, create>
68738451
68748452=item mkdir FILENAME
68758453
68768454=item mkdir
68778455
8456=for Pod::Functions create a directory
8457
68788458=begin original
68798459
68808460Creates the directory specified by FILENAME, with permissions
6881specified by MASK (as modified by C<umask>). If it succeeds it
8461specified by MASK (as modified by L<C<umask>|/umask EXPR>). If it
6882returns true; otherwise it returns false and sets C<$!> (errno).
8462succeeds it returns true; otherwise it returns false and sets
8463L<C<$!>|perlvar/$!> (errno).
68838464MASK defaults to 0777 if omitted, and FILENAME defaults
6884to C<$_> if omitted.
8465to L<C<$_>|perlvar/$_> if omitted.
68858466
68868467=end original
68878468
68888469FILENAME で指定したディレクトリを、MASK で指定した許可モード(を
6889C<umask> で修正したもの) で作成します。
8470L<C<umask>|/umask EXPR> で修正したもの) で作成します。
6890成功時には真を返します; 失敗時には偽を返して C<$!> (errno) を設定します。
8471成功時には真を返します; さもなければ偽を返して
8472L<C<$!>|perlvar/$!> (errno) を設定します。
68918473MASK を省略すると、0777 とみなし、
6892FILENAME を省略すると、C<$_> を使います。
8474FILENAME を省略すると、L<C<$_>|perlvar/$_> を使います。
68938475
68948476=begin original
68958477
68968478In general, it is better to create directories with a permissive MASK
6897and let the user modify that with their C<umask> than it is to supply
8479and let the user modify that with their L<C<umask>|/umask EXPR> than it
8480is to supply
68988481a restrictive MASK and give the user no way to be more permissive.
68998482The exceptions to this rule are when the file or directory should be
6900kept private (mail files, for instance). The perlfunc(1) entry on
8483kept private (mail files, for instance). The documentation for
6901C<umask> discusses the choice of MASK in more detail.
8484L<C<umask>|/umask EXPR> discusses the choice of MASK in more detail.
69028485
69038486=end original
69048487
69058488一般的に、制限された MASK を使ってユーザーがより寛容にする方法を
6906与えないより、寛容な MASK でディレクトリを作り、ユーザーが自身の C<umask> で
8489与えないより、寛容な MASK でディレクトリを作り、ユーザーが自身の
6907修正するようにした方がよいです。
8490L<C<umask>|/umask EXPR> で修正するようにした方がよいです。
69088491例外は、(例えばメールファイルのような)プライベートに保つべきファイルや
69098492ディレクトリを書く場合です。
6910perlfunc(1) の C<umask> で、MASK の選択に関して詳細に議論しています。
8493L<C<umask>|/umask EXPR> の文書で、MASK の選択に関して詳細に議論しています。
69118494
69128495=begin original
69138496
69148497Note that according to the POSIX 1003.1-1996 the FILENAME may have any
69158498number of trailing slashes. Some operating and filesystems do not get
69168499this right, so Perl automatically removes all trailing slashes to keep
69178500everyone happy.
69188501
69198502=end original
69208503
69218504POSIX 1003.1-1996 によれば、FILENAME には末尾に任意の数のスラッシュを
69228505つけることができます。
69238506このようには動かない OS やファイルシステムもあるので、Perl はみんなが
69248507幸せになれるように、自動的に末尾のスラッシュを削除します。
69258508
69268509=begin original
69278510
69288511To recursively create a directory structure, look at
6929the C<mkpath> function of the L<File::Path> module.
8512the L<C<make_path>|File::Path/make_path( $dir1, $dir2, .... )> function
8513of the L<File::Path> module.
69308514
69318515=end original
69328516
69338517ディレクトリ構造を再帰的に作成するには、L<File::Path> モジュールの
6934C<makepath> 関数を参照してください。
8518L<C<make_path>|File::Path/make_path( $dir1, $dir2, .... )> 関数を
8519参照してください。
69358520
69368521=item msgctl ID,CMD,ARG
69378522X<msgctl>
69388523
8524=for Pod::Functions SysV IPC message control operations
8525
69398526=begin original
69408527
6941Calls the System V IPC function msgctl(2). You'll probably have to say
8528Calls the System V IPC function L<msgctl(2)>. You'll probably have to say
69428529
69438530=end original
69448531
6945System V IPC 関数 msgctl を呼び出します。正しい定数定義を得るために、まず
8532System V IPC 関数 L<msgctl(2)> を呼び出します。
8533正しい定数定義を得るために、まず
69468534
69478535 use IPC::SysV;
69488536
69498537=begin original
69508538
69518539first to get the correct constant definitions. If CMD is C<IPC_STAT>,
69528540then ARG must be a variable that will hold the returned C<msqid_ds>
6953structure. Returns like C<ioctl>: the undefined value for error,
8541structure. Returns like L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>:
6954C<"0 but true"> for zero, or the actual return value otherwise. See also
8542the undefined value for error, C<"0 but true"> for zero, or the actual
6955L<perlipc/"SysV IPC"> and the documentation for C<IPC::SysV> and
8543return value otherwise. See also L<perlipc/"SysV IPC"> and the
6956C<IPC::Semaphore>.
8544documentation for L<C<IPC::SysV>|IPC::SysV> and
8545L<C<IPC::Semaphore>|IPC::Semaphore>.
69578546
69588547=end original
69598548
6960宣言する必要があるでしょう。
8549書くことが必要でしょう。
69618550CMD が C<IPC_STAT> であれば、ARG は返される C<msqid_ds> 構造体を
69628551納める変数でなければなりません。
6963C<ioctl> と同じように、エラー時には未定義値、
8552L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同じように、エラー時には
6964ゼロのときは C<"0 but true">、それ以外なら、その値そのものを返します。
8553未定義値、ゼロのときは C<"0 but true">、それ以外なら、その値そのものを
6965L<perlipc/"SysV IPC"> および、C<IPC::SysV>, C<IPC::Semaphore> の文書も
8554返します。
6966参照してください。
8555L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>,
8556L<C<IPC::Semaphore>|IPC::Semaphore> の文書も参照してください。
69678557
8558=begin original
8559
8560Portability issues: L<perlport/msgctl>.
8561
8562=end original
8563
8564移植性の問題: L<perlport/msgctl>。
8565
69688566=item msgget KEY,FLAGS
69698567X<msgget>
69708568
8569=for Pod::Functions get SysV IPC message queue
8570
69718571=begin original
69728572
6973Calls the System V IPC function msgget(2). Returns the message queue
8573Calls the System V IPC function L<msgget(2)>. Returns the message queue
6974id, or C<undef> on error. See also
8574id, or L<C<undef>|/undef EXPR> on error. See also L<perlipc/"SysV IPC">
6975L<perlipc/"SysV IPC"> and the documentation for C<IPC::SysV> and
8575and the documentation for L<C<IPC::SysV>|IPC::SysV> and
6976C<IPC::Msg>.
8576L<C<IPC::Msg>|IPC::Msg>.
69778577
69788578=end original
69798579
6980System V IPC 関数 msgget を呼び出します。
8580System V IPC 関数 L<msgget(2)> を呼び出します。
6981メッセージキューの ID か、エラー時には C<undef> を返します。
8581メッセージキューの ID か、エラー時には L<C<undef>|/undef EXPR> を返します。
6982L<perlipc/"SysV IPC"> よび、C<IPC::SysV>, C<IPC::Msg> の文書も
8582L<perlipc/"SysV IPC"> よび、L<C<IPC::SysV>|IPC::SysV>,
6983参照してください。
8583L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。
69848584
8585=begin original
8586
8587Portability issues: L<perlport/msgget>.
8588
8589=end original
8590
8591移植性の問題: L<perlport/msgget>。
8592
69858593=item msgrcv ID,VAR,SIZE,TYPE,FLAGS
69868594X<msgrcv>
69878595
8596=for Pod::Functions receive a SysV IPC message from a message queue
8597
69888598=begin original
69898599
69908600Calls the System V IPC function msgrcv to receive a message from
69918601message queue ID into variable VAR with a maximum message size of
69928602SIZE. Note that when a message is received, the message type as a
69938603native long integer will be the first thing in VAR, followed by the
69948604actual message. This packing may be opened with C<unpack("l! a*")>.
6995Taints the variable. Returns true if successful, false
8605Taints the variable. Returns true if successful, false
69968606on error. See also L<perlipc/"SysV IPC"> and the documentation for
6997C<IPC::SysV> and C<IPC::SysV::Msg>.
8607L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Msg>|IPC::Msg>.
69988608
69998609=end original
70008610
70018611System V IPC 関数 msgrcv を呼び出し、メッセージキュー ID から、
70028612変数 VAR に最大メッセージ長 SIZE のメッセージを受信します。
70038613メッセージが受信された時、ネイティブな long 整数のメッセージタイプが
70048614VAR の先頭となり、実際のメッセージが続きます。
70058615このパッキングは C<unpack("l! a*")> で展開できます。
70068616変数は汚染されます。
7007成功時には真を返し、エラー時には偽を返します。
8617成功時には真を、エラー時には偽を返します。
7008L<perlipc/"SysV IPC"> および、C<IPC::SysV>, C<IPC::SysV::Msg> の文書も
8618L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>,
7009参照してください。
8619L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。
70108620
8621=begin original
8622
8623Portability issues: L<perlport/msgrcv>.
8624
8625=end original
8626
8627移植性の問題: L<perlport/msgrcv>。
8628
70118629=item msgsnd ID,MSG,FLAGS
70128630X<msgsnd>
70138631
8632=for Pod::Functions send a SysV IPC message to a message queue
8633
70148634=begin original
70158635
70168636Calls the System V IPC function msgsnd to send the message MSG to the
70178637message queue ID. MSG must begin with the native long integer message
70188638type, be followed by the length of the actual message, and then finally
70198639the message itself. This kind of packing can be achieved with
70208640C<pack("l! a*", $type, $message)>. Returns true if successful,
7021false on error. See also the C<IPC::SysV>
8641false on error. See also L<perlipc/"SysV IPC"> and the documentation
7022and C<IPC::SysV::Msg> documentation.
8642for L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Msg>|IPC::Msg>.
70238643
70248644=end original
70258645
70268646System V IPC 関数 msgsnd を呼び出し、メッセージキュー ID に
70278647メッセージ MSG を送信します。
7028MSG の先頭は、ネイティブなlong 整数のメッセージタイプでなければならず、
8648MSG の先頭は、ネイティブな long 整数のメッセージタイプでなければならず、
70298649メッセージの長さ、メッセージ本体と続きます。
70308650これは、C<pack("l! a*", $type, $message)> として生成できます。
70318651成功時には真を、エラー時には偽を返します。
7032C<IPC::SysV> C<IPC::SysV::Msg> の文書も参照してください。
8652L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>,
8653L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。
70338654
7034=item my EXPR
8655=begin original
8656
8657Portability issues: L<perlport/msgsnd>.
8658
8659=end original
8660
8661移植性の問題: L<perlport/msgsnd>。
8662
8663=item my VARLIST
70358664X<my>
70368665
7037=item my TYPE EXPR
8666=item my TYPE VARLIST
70388667
7039=item my EXPR : ATTRS
8668=item my VARLIST : ATTRS
70408669
7041=item my TYPE EXPR : ATTRS
8670=item my TYPE VARLIST : ATTRS
70428671
8672=for Pod::Functions declare and assign a local variable (lexical scoping)
8673
70438674=begin original
70448675
7045A C<my> declares the listed variables to be local (lexically) to the
8676A L<C<my>|/my VARLIST> declares the listed variables to be local
7046enclosing block, file, or C<eval>. If more than one value is listed,
8677(lexically) to the enclosing block, file, or L<C<eval>|/eval EXPR>. If
7047the list must be placed in parentheses.
8678more than one variable is listed, the list must be placed in
8679parentheses.
70488680
70498681=end original
70508682
7051C<my> はリストアップされた変数を、囲っているブロック、ファイル、
8683L<C<my>|/my VARLIST> はリストアップされた変数を、囲っているブロック、ファイル、
7052C<eval> の中でローカルな (レキシカルな) ものにします。
8684L<C<eval>|/eval EXPR> の中でローカルな (レキシカルな) ものにします。
7053複数の並べる場合は、括弧括る必要がありま
8685複数の変数指定する場合は、リストはかっこくくらなければなりません
70548686
70558687=begin original
70568688
70578689The exact semantics and interface of TYPE and ATTRS are still
7058evolving. TYPE is currently bound to the use of the C<fields> pragma,
8690evolving. TYPE may be a bareword, a constant declared
7059and attributes are handled using the C<attributes> pragma, or starting
8691with L<C<use constant>|constant>, or L<C<__PACKAGE__>|/__PACKAGE__>. It
7060from Perl 5.8.0 also via the C<Attribute::Handlers> module. See
8692is
7061L<perlsub/"Private Variables via my()"> for details, and L<fields>,
8693currently bound to the use of the L<fields> pragma,
7062L<attributes>, and L<Attribute::Handlers>.
8694and attributes are handled using the L<attributes> pragma, or starting
8695from Perl 5.8.0 also via the L<Attribute::Handlers> module. See
8696L<perlsub/"Private Variables via my()"> for details.
70638697
70648698=end original
70658699
70668700TYPE と ATTRS の正確な文法とインターフェースは今でも進化しています。
7067現在のところ、TYPE は C<fields> プラグマの使用と結び付けらていて
8701TYPE は、裸の単語、L<C<use constant>|constant> で宣言さた定数
7068属性は C<attributes> プラグマか、Perl 5.8.0 らは
8702L<C<__PACKAGE__>|/__PACKAGE__> のいずれです。
7069C<Attribute::Handlers> モジュールと結び付けられています。
8703現在のところ、TYPE は L<fields> プラグマの使用と結び付けられていて、
7070詳しくはL<perlsub/"Private Variables via my()">, L<fields>,
8704属性 L<attributes> プラグマか、Perl 5.8.0 からは
7071L<attributes>, L<Attribute::Handlers> を参照しください。
8705L<Attribute::Handlers> モジュールと結び付けられています
8706詳しくは L<perlsub/"Private Variables via my()"> を参照してください。
70728707
8708=begin original
8709
8710Note that with a parenthesised list, L<C<undef>|/undef EXPR> can be used
8711as a dummy placeholder, for example to skip assignment of initial
8712values:
8713
8714=end original
8715
8716かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> は、例えば初期値の代入を
8717飛ばすために、ダミーのプレースホルダとして使えることに注意してください:
8718
8719 my ( undef, $min, $hour ) = localtime;
8720
70738721=item next LABEL
70748722X<next> X<continue>
70758723
8724=item next EXPR
8725
70768726=item next
70778727
8728=for Pod::Functions iterate a block prematurely
8729
70788730=begin original
70798731
7080The C<next> command is like the C<continue> statement in C; it starts
8732The L<C<next>|/next LABEL> command is like the C<continue> statement in
7081the next iteration of the loop:
8733C; it starts the next iteration of the loop:
70828734
70838735=end original
70848736
7085C<next> コマンドは、C での C<continue> 文のようなもので、
8737L<C<next>|/next LABEL> コマンドは、C での C<continue> 文のようなもので、
70868738ループの次の繰り返しを開始します:
70878739
70888740 LINE: while (<STDIN>) {
70898741 next LINE if /^#/; # discard comments
70908742 #...
70918743 }
70928744
70938745=begin original
70948746
7095Note that if there were a C<continue> block on the above, it would get
8747Note that if there were a L<C<continue>|/continue BLOCK> block on the
8748above, it would get
70968749executed even on discarded lines. If LABEL is omitted, the command
7097refers to the innermost enclosing loop.
8750refers to the innermost enclosing loop. The C<next EXPR> form, available
8751as of Perl 5.18.0, allows a label name to be computed at run time, being
8752otherwise identical to C<next LABEL>.
70988753
70998754=end original
71008755
7101C<continue> ブロックが存在すれば、たとえ捨てられる行に
8756L<C<continue>|/continue BLOCK> ブロックが存在すれば、たとえ捨てられる行に
71028757あっても、それが実行されます。
7103LABEL が省略されると、このコマンドはもっとも内側のループを参照します。
8758LABEL が省略されると、コマンドは一番内側のループを参照します。
8759Perl 5.18.0 から利用可能な C<next EXPR> 形式では、実行時に計算される
8760ラベル名が使えます; それ以外は C<next LABEL> と同一です。
71048761
71058762=begin original
71068763
7107C<next> cannot be used to exit a block which returns a value such as
8764L<C<next>|/next LABEL> cannot be used to exit a block which returns a
7108C<eval {}>, C<sub {}>, or C<do {}>, and should not be used to exit
8765value such as C<eval {}>, C<sub {}>, or C<do {}>, and should not be used
7109a grep() or map() operation.
8766to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST>
8767operation.
71108768
71118769=end original
71128770
7113C<next> は C<eval {}>, C<sub {}>, C<do {}> のように値を返す
8771L<C<next>|/next LABEL> は C<eval {}>, C<sub {}>, C<do {}> のように値を返す
7114ブロックから抜けるのには使えません
8772ブロックから抜けるのには使えません; また、L<C<grep>|/grep BLOCK LIST> や
7115また、grep() や map() 操作から抜けるのに使うべきではありません。
8773L<C<map>|/map BLOCK LIST> 操作から抜けるのに使うべきではありません。
71168774
71178775=begin original
71188776
71198777Note that a block by itself is semantically identical to a loop
7120that executes once. Thus C<next> will exit such a block early.
8778that executes once. Thus L<C<next>|/next LABEL> will exit such a block
8779early.
71218780
71228781=end original
71238782
71248783ブロック自身は一回だけ実行されるループと文法的に同一であることに
71258784注意してください。
7126従って、C<next> はそのようなブロックから早く抜けるのに使えます。
8785従って、L<C<next>|/next LABEL> はそのようなブロックから早く抜けるのに使えます。
71278786
71288787=begin original
71298788
7130See also L</continue> for an illustration of how C<last>, C<next>, and
8789See also L<C<continue>|/continue BLOCK> for an illustration of how
7131C<redo> work.
8790L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and
8791L<C<redo>|/redo LABEL> work.
71328792
71338793=end original
71348794
7135C<last>, C<next>, C<redo> がどのように働くかについては
8795L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL>
7136L</continue> も参照してさい。
8796どのように働くかについては L<C<continue>|/continue BLOCK> も参照してください。
71378797
8798=begin original
8799
8800Unlike most named operators, this has the same precedence as assignment.
8801It is also exempt from the looks-like-a-function rule, so
8802C<next ("foo")."bar"> will cause "bar" to be part of the argument to
8803L<C<next>|/next LABEL>.
8804
8805=end original
8806
8807ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
8808また、関数のように見えるものの規則からも免れるので、C<next ("foo")."bar"> と
8809すると "bar" は L<C<next>|/next LABEL> への引数の一部となります。
8810
71388811=item no MODULE VERSION LIST
71398812X<no declarations>
71408813X<unimporting>
71418814
71428815=item no MODULE VERSION
71438816
71448817=item no MODULE LIST
71458818
71468819=item no MODULE
71478820
71488821=item no VERSION
71498822
8823=for Pod::Functions unimport some module symbols or semantics at compile time
8824
71508825=begin original
71518826
7152See the C<use> function, of which C<no> is the opposite.
8827See the L<C<use>|/use Module VERSION LIST> function, of which
8828L<C<no>|/no MODULE VERSION LIST> is the opposite.
71538829
71548830=end original
71558831
7156L<use> 関数を参照してください。C<no> は、その逆を行なうものです。
8832L<C<use>|/use Module VERSION LIST> 関数を参照してください;
8833L<C<no>|/no MODULE VERSION LIST> は、その逆を行なうものです。
71578834
71588835=item oct EXPR
71598836X<oct> X<octal> X<hex> X<hexadecimal> X<binary> X<bin>
71608837
71618838=item oct
71628839
8840=for Pod::Functions convert a string to an octal number
8841
71638842=begin original
71648843
71658844Interprets EXPR as an octal string and returns the corresponding
71668845value. (If EXPR happens to start off with C<0x>, interprets it as a
71678846hex string. If EXPR starts off with C<0b>, it is interpreted as a
71688847binary string. Leading whitespace is ignored in all three cases.)
71698848The following will handle decimal, binary, octal, and hex in standard
71708849Perl notation:
71718850
71728851=end original
71738852
71748853EXPR を 8 進数文字列と解釈して、対応する値を返します。
71758854(EXPR が C<0x> で始まるときには、16 進数文字列と解釈します。
71768855EXPR が C<0b>で始まるときは、2 進数文字列と解釈します。
71778856どの場合でも、先頭の空白は無視されます。)
71788857以下の例は、標準的な Perl の記法での
7179885810 進数、2 進数、8 進数、16 進数を扱います:
71808859
71818860 $val = oct($val) if $val =~ /^0/;
71828861
71838862=begin original
71848863
7185If EXPR is omitted, uses C<$_>. To go the other way (produce a number
8864If EXPR is omitted, uses L<C<$_>|perlvar/$_>. To go the other way
7186in octal), use sprintf() or printf():
8865(produce a number in octal), use L<C<sprintf>|/sprintf FORMAT, LIST> or
8866L<C<printf>|/printf FILEHANDLE FORMAT, LIST>:
71878867
71888868=end original
71898869
7190EXPR 省略ると、C<$_> を使用します。
8870EXPR 省略されると、L<C<$_>|perlvar/$_> を使ます。
7191(8 進数を扱う)その他の方法としては sprintf() または printf()があります。
8871(8 進数を扱う)その他の方法としては L<C<sprintf>|/sprintf FORMAT, LIST> や
8872L<C<printf>|/printf FILEHANDLE FORMAT, LIST> があります:
71928873
7193 $dec_perms = (stat("filename"))[2] & 07777;
8874 my $dec_perms = (stat("filename"))[2] & 07777;
7194 $oct_perm_str = sprintf "%o", $perms;
8875 my $oct_perm_str = sprintf "%o", $perms;
71958876
71968877=begin original
71978878
7198The oct() function is commonly used when a string such as C<644> needs
8879The L<C<oct>|/oct EXPR> function is commonly used when a string such as
7199to be converted into a file mode, for example. Although Perl
8880C<644> needs
8881to be converted into a file mode, for example. Although Perl
72008882automatically converts strings into numbers as needed, this automatic
72018883conversion assumes base 10.
72028884
72038885=end original
72048886
7205oct() 関数は例えば、 C<644> といった文字列をファイルモードに変換する時
8887L<C<oct>|/oct EXPR> 関数は例えば、 C<644> といった文字列をファイルモードに
7206よく使います。
8888変換する時によく使います。
72078889Perl は必要に応じて自動的に文字列を数値に変換しますが、
72088890この自動変換は十進数を仮定します。
72098891
72108892=begin original
72118893
7212Leading white space is ignored without warning, as too are any trailing
8894Leading white space is ignored without warning, as too are any trailing
7213non-digits, such as a decimal point (C<oct> only handles non-negative
8895non-digits, such as a decimal point (L<C<oct>|/oct EXPR> only handles
7214integers, not negative integers or floating point).
8896non-negative integers, not negative integers or floating point).
72158897
72168898=end original
72178899
72188900先頭の空白や、末尾の(小数点のような)非数字は警告なしに無視されます
7219(C<oct> は非負整数のみを扱えます; 負の整数や小数は扱えません)。
8901(L<C<oct>|/oct EXPR> は非負整数のみを扱えます; 負の整数や小数は扱えません)。
72208902
72218903=item open FILEHANDLE,EXPR
72228904X<open> X<pipe> X<file, open> X<fopen>
72238905
72248906=item open FILEHANDLE,MODE,EXPR
72258907
72268908=item open FILEHANDLE,MODE,EXPR,LIST
72278909
72288910=item open FILEHANDLE,MODE,REFERENCE
72298911
72308912=item open FILEHANDLE
72318913
8914=for Pod::Functions open a file, pipe, or descriptor
8915
72328916=begin original
72338917
72348918Opens the file whose filename is given by EXPR, and associates it with
72358919FILEHANDLE.
72368920
72378921=end original
72388922
72398923EXPR で与えられたファイル名のファイルを開き、FILEHANDLE と結び付けます。
72408924
72418925=begin original
72428926
72438927Simple examples to open a file for reading:
72448928
72458929=end original
72468930
72478931読み込みのためにファイルを開くための簡単な例は以下のもので:
72488932
7249 open(my $fh, "<", "input.txt")
8933 open(my $fh, "<", "input.txt")
7250 or die "cannot open < input.txt: $!";
8934 or die "Can't open < input.txt: $!";
72518935
72528936=begin original
72538937
72548938and for writing:
72558939
72568940=end original
72578941
72588942書き込み用は以下のものです:
72598943
7260 open(my $fh, ">", "output.txt")
8944 open(my $fh, ">", "output.txt")
7261 or die "cannot open > output.txt: $!";
8945 or die "Can't open > output.txt: $!";
72628946
72638947=begin original
72648948
7265(The following is a comprehensive reference to open(): for a gentler
8949(The following is a comprehensive reference to
7266introduction you may consider L<perlopentut>.)
8950L<C<open>|/open FILEHANDLE,EXPR>: for a gentler introduction you may
8951consider L<perlopentut>.)
72678952
72688953=end original
72698954
7270(以下は総合的な open() のリファレンスです: より親切な説明については
8955(以下は総合的な L<C<open>|/open FILEHANDLE,EXPR> のリファレンスです:
7271L<perlopentut> を参照してください。)
8956より親切な説明については L<perlopentut> を参照してください。)
72728957
72738958=begin original
72748959
72758960If FILEHANDLE is an undefined scalar variable (or array or hash element), a
72768961new filehandle is autovivified, meaning that the variable is assigned a
72778962reference to a newly allocated anonymous filehandle. Otherwise if
72788963FILEHANDLE is an expression, its value is the real filehandle. (This is
72798964considered a symbolic reference, so C<use strict "refs"> should I<not> be
72808965in effect.)
72818966
72828967=end original
72838968
72848969FILEHANDLE が未定義のスカラ変数(または配列かハッシュの要素)の場合、
72858970新しいファイルハンドルが自動有効化され、その変数は新しく割り当てられた
72868971無名ファイルハンドルへのリファレンスが代入されます。
72878972さもなければ、もし FILEHANDLE が式なら、その値を求めている実際の
72888973ファイルハンドルの名前として使います。
72898974(これはシンボリックリファレンスとして扱われるので、
72908975C<use strict "refs"> の影響を I<受けません>。)
72918976
72928977=begin original
72938978
7294If EXPR is omitted, the global (package) scalar variable of the same
7295name as the FILEHANDLE contains the filename. (Note that lexical
7296variables--those declared with C<my> or C<state>--will not work for this
7297purpose; so if you're using C<my> or C<state>, specify EXPR in your
7298call to open.)
7299
7300=end original
7301
7302EXPR が省略された場合、FILEHANDLE と同じ名前のグローバル(パッケージ)
7303スカラ変数にファイル名が入っています。
7304(レキシカル変数 -- C<my> や C<state> で宣言されたもの -- はこの用途には
7305使えないことに注意してください; 従って、C<my> や C<state> を使っている場合は、
7306open を呼び出すときに EXPR を指定してください。)
7307
7308=begin original
7309
73108979If three (or more) arguments are specified, the open mode (including
73118980optional encoding) in the second argument are distinct from the filename in
73128981the third. If MODE is C<< < >> or nothing, the file is opened for input.
73138982If MODE is C<< > >>, the file is opened for output, with existing files
73148983first being truncated ("clobbered") and nonexisting files newly created.
73158984If MODE is C<<< >> >>>, the file is opened for appending, again being
73168985created if necessary.
73178986
73188987=end original
73198988
732089893 (またはそれ以上)の引数が指定された場合、2 番目の引数の(オプションの
73218990エンコーディングを含む)開く時のモードは、3 番目のファイル名と分離されます。
73228991MODE が C<< < >> か空の場合、ファイルは入力用に開かれます。
73238992MODE が C<< > >> の場合、ファイルは出力用に開かれ、既にファイルが
73248993ある場合は切り詰められ(上書きされ)、ない場合は新しく作られます。
73258994MODE が C<<< >> >>> の場合、ファイルは追加用に開かれ、やはり必要なら
73268995作成されます。
73278996
73288997=begin original
73298998
73308999You can put a C<+> in front of the C<< > >> or C<< < >> to
73319000indicate that you want both read and write access to the file; thus
7332C<< +< >> is almost always preferred for read/write updates--the
9001C<< +< >> is almost always preferred for read/write updates--the
7333C<< +> >> mode would clobber the file first. You cant usually use
9002C<< +> >> mode would clobber the file first. You can't usually use
73349003either read-write mode for updating textfiles, since they have
73359004variable-length records. See the B<-i> switch in L<perlrun> for a
73369005better approach. The file is created with permissions of C<0666>
7337modified by the process's C<umask> value.
9006modified by the process's L<C<umask>|/umask EXPR> value.
73389007
73399008=end original
73409009
73419010ファイルに読み込みアクセスと書き込みアクセスの両方をしたいことを示すために、
73429011C<< > >> や C<< < >> の前に C<+> を付けることができます:
73439012従って、ほとんど常に C<< +< >> が読み書き更新のために使われます --
73449013C<< +> >> モードはまずファイルを上書きします。
73459014普通はこれらの読み書きモードをテキストファイルの更新のためには使えません;
73469015なぜなら可変長のレコードで構成されているからです。
73479016よりよい手法については L<perlrun> の B<-i> オプションを参照してください。
7348ファイルは C<0666> をプロセスの C<umask> 値で修正したパーミッションで
9017ファイルは C<0666> をプロセスの L<C<umask>|/umask EXPR> 値で修正した
7349作成されます。
9018パーミッションで作成されます。
73509019
73519020=begin original
73529021
7353These various prefixes correspond to the fopen(3) modes of C<r>,
9022These various prefixes correspond to the L<fopen(3)> modes of C<r>,
73549023C<r+>, C<w>, C<w+>, C<a>, and C<a+>.
73559024
73569025=end original
73579026
7358これらの様々な前置詞は fopen(3) の C<r>, C<r+>,
9027これらの様々な前置詞は L<fopen(3)> の C<r>, C<r+>,
73599028C<w>, C<w+>, C<a>, C<a+> のモードに対応します。
73609029
73619030=begin original
73629031
73639032In the one- and two-argument forms of the call, the mode and filename
73649033should be concatenated (in that order), preferably separated by white
73659034space. You can--but shouldn't--omit the mode in these forms when that mode
7366is C<< < >>. It is always safe to use the two-argument form of C<open> if
9035is C<< < >>. It is safe to use the two-argument form of
7367the filename argument is a known literal.
9036L<C<open>|/open FILEHANDLE,EXPR> if the filename argument is a known literal.
73689037
73699038=end original
73709039
737190401 引数 と 2 引数の形式ではモードとファイル名は(この順番で)
73729041結合されます(空白によって分割されているかもしれません)。
73739042この形式で、モードが C<< '<' >> の場合はモードを省略できます (が、
73749043するべきではありません)。
7375ファイル引数が既知のリテラルの場合、2 引数形式の C<open> は常に安全です。
9044ファイル引数が既知のリテラルの場合、2 引数形式の
9045L<C<open>|/open FILEHANDLE,EXPR> は安全です。
73769046
73779047=begin original
73789048
73799049For three or more arguments if MODE is C<|->, the filename is
73809050interpreted as a command to which output is to be piped, and if MODE
73819051is C<-|>, the filename is interpreted as a command that pipes
73829052output to us. In the two-argument (and one-argument) form, one should
73839053replace dash (C<->) with the command.
73849054See L<perlipc/"Using open() for IPC"> for more examples of this.
7385(You are not allowed to C<open> to a command that pipes both in I<and>
9055(You are not allowed to L<C<open>|/open FILEHANDLE,EXPR> to a command
7386out, but see L<IPC::Open2>, L<IPC::Open3>, and
9056that pipes both in I<and> out, but see L<IPC::Open2>, L<IPC::Open3>, and
73879057L<perlipc/"Bidirectional Communication with Another Process"> for
73889058alternatives.)
73899059
73909060=end original
73919061
739290623 引数以上の形式で
73939063MODE が C<|-> の場合、ファイル名は出力がパイプされるコマンドとして
73949064解釈され、MODE が C<-|> の場合、ファイル名は出力がこちらに
73959065パイプされるコマンドとして解釈されます。
73962 引数(と 1 引数) の形式ではハイフン(C<->)をコマンドの代わりに
90662 引数(と 1 引数) の形式ではハイフン(C<->)をコマンドの代わりに使えます。
7397使えます。
73989067これに関するさらなる例については L<perlipc/"Using open() for IPC"> を
73999068参照してください。
7400(C<open> を入出力 I<両用> にパイプすることは出来ませんが
9069(L<C<open>|/open FILEHANDLE,EXPR> を入出力 I<両用> にパイプすることは
7401代替案としては L<IPC::Open2>, L<IPC::Open3>,
9070出来ませんが、代替案としては L<IPC::Open2>, L<IPC::Open3>,
74029071L<perlipc/"Bidirectional Communication with Another Process"> を
74039072参照してください。)
74049073
74059074=begin original
74069075
74079076In the form of pipe opens taking three or more arguments, if LIST is specified
74089077(extra arguments after the command name) then LIST becomes arguments
74099078to the command invoked if the platform supports it. The meaning of
7410C<open> with more than three arguments for non-pipe modes is not yet
9079L<C<open>|/open FILEHANDLE,EXPR> with more than three arguments for
7411defined, but experimental "layers" may give extra LIST arguments
9080non-pipe modes is not yet defined, but experimental "layers" may give
7412meaning.
9081extra LIST arguments meaning.
74139082
74149083=end original
74159084
74169085パイプでの三つ以上の引数の形式では、LIST (コマンド名の後の追加の引数) が
74179086指定されると、プラットフォームが対応していれば、LIST は起動される
74189087コマンドへの引数となります。
7419パイプモードではない C<open> での三つ以上の引数の意味はまだ未定義ですが、
9088パイプモードではない L<C<open>|/open FILEHANDLE,EXPR> での三つ以上の引数の
7420実験的な「層」は追加の LIST 引数の意味を与えます。
9089意味はまだ未定義ですが、実験的な「層」は追加の LIST 引数の意味を与えます。
74219090
74229091=begin original
74239092
7424In the two-argument (and one-argument) form, opening C<< <- >>
9093In the two-argument (and one-argument) form, opening C<< <- >>
74259094or C<-> opens STDIN and opening C<< >- >> opens STDOUT.
74269095
74279096=end original
74289097
742990982 引数(と 1 引数)で C<< <- >> か C<-> を open すると STDIN が
74309099オープンされ、C<< >- >> を open すると STDOUT がオープンされます。
74319100
74329101=begin original
74339102
74349103You may (and usually should) use the three-argument form of open to specify
74359104I/O layers (sometimes referred to as "disciplines") to apply to the handle
74369105that affect how the input and output are processed (see L<open> and
7437L<PerlIO> for more details). For example:
9106L<PerlIO> for more details). For example:
74389107
74399108=end original
74409109
74419110open の 3 引数形式では、どのように入出力が処理されるかに影響を与える
74429111I/O 層(「ディシプリン」とも呼ばれます)を指定できます
74439112(そして普通はそうするべきです)
74449113(詳細については L<open> と L<PerlIO> を参照してください)。
74459114例えば:
74469115
7447 open(my $fh, "<:encoding(UTF-8)", "filename")
9116 open(my $fh, "<:encoding(UTF-8)", $filename)
7448 || die "can't open UTF-8 encoded filename: $!";
9117 || die "Can't open UTF-8 encoded $filename: $!";
74499118
74509119=begin original
74519120
74529121opens the UTF8-encoded file containing Unicode characters;
7453see L<perluniintro>. Note that if layers are specified in the
9122see L<perluniintro>. Note that if layers are specified in the
74549123three-argument form, then default layers stored in ${^OPEN} (see L<perlvar>;
7455usually set by the B<open> pragma or the switch B<-CioD>) are ignored.
9124usually set by the L<open> pragma or the switch C<-CioD>) are ignored.
9125Those layers will also be ignored if you specifying a colon with no name
9126following it. In that case the default layer for the operating system
9127(:raw on Unix, :crlf on Windows) is used.
74569128
74579129=end original
74589130
74599131は、Unicode 文字を含む UTF8 エンコードされたファイルを開きます;
74609132L<perluniintro> を参照してください。
746191333 引数形式で層を指定すると、${^OPEN} (L<perlvar> を参照してください;
7462通常はC<open> プラグマか B<-CioD> オプションでセットされます)
9134通常は L<open> プラグマか C<-CioD> オプションでセットされます) に保存された
7463に保存されたデフォルト層は無視されることに注意してください。
9135デフォルト層は無視されることに注意してください。
9136これらの層は、名前なしでコロンを指定した場合にも無視されます。
9137この場合 OS のデフォルトの層 (Unix では :raw、Windows では :crlf) が
9138使われます。
74649139
74659140=begin original
74669141
74679142Open returns nonzero on success, the undefined value otherwise. If
7468the C<open> involved a pipe, the return value happens to be the pid of
9143the L<C<open>|/open FILEHANDLE,EXPR> involved a pipe, the return value
7469the subprocess.
9144happens to be the pid of the subprocess.
74709145
74719146=end original
74729147
74739148open は、成功時にはゼロ以外を返し、失敗時には未定義値を返します。
7474パイプに関る C<open> のときには、返り値はサブプロセスの pid となります。
9149パイプに関る L<C<open>|/open FILEHANDLE,EXPR> のときには、返り値は
9150サブプロセスの pid となります。
74759151
74769152=begin original
74779153
7478If you're running Perl on a system that distinguishes between text
9154On some systems (in general, DOS- and Windows-based systems)
7479files and binary files, then you should check out L</binmode> for tips
9155L<C<binmode>|/binmode FILEHANDLE, LAYER> is necessary when you're not
7480for dealing with this. The key distinction between systems that need
9156working with a text file. For the sake of portability it is a good idea
7481C<binmode> and those that don't is their text file formats. Systems
9157always to use it when appropriate, and never to use it when it isn't
7482like Unix, Mac OS, and Plan 9, that end lines with a single
9158appropriate. Also, people can set their I/O to be by default
7483character and encode that character in C as C<"\n"> do not
9159UTF8-encoded Unicode, not bytes.
7484need C<binmode>. The rest need it.
74859160
74869161=end original
74879162
7488テキストファイルとバイナリファイルを区別するシステム Perl を実行して
9163テキストファイルでものを扱う場合に
7489場合、これを扱うための小技のために L</binmode> をチェックするべきです。
9164L<C<binmode>|/binmode FILEHANDLE, LAYER> が必要な
7490動作させているシステム C<binmode> が必要か不要化を区別する鍵は、テキ
9165システムもあります(一般的には DOS と Windows ベーのシステムです)。
7491ファイル形式す。
9166移植性ために、適切なときには常にこれを使い、適切ないときには
7492Unix, Mac OS, Plan 9 といった、行境界を 1 文字で表現し、それが C で
9167決して使わないといのは良い考えです。
7493C<"\n"> でエンコードされる場合、C<binmode> は不要です。
9168また、デフォルトとして I/O を bytes はなく UTF-8 エンコードされ
7494それ以外では必要です。
9169Unicode にセットすることも出来ます。
74959170
74969171=begin original
74979172
7498When opening a file, it's seldom a good idea to continue
9173When opening a file, it's seldom a good idea to continue
7499if the request failed, so C<open> is frequently used with
9174if the request failed, so L<C<open>|/open FILEHANDLE,EXPR> is frequently
7500C<die>. Even if C<die> won't do what you want (say, in a CGI script,
9175used with L<C<die>|/die LIST>. Even if L<C<die>|/die LIST> won't do
9176what you want (say, in a CGI script,
75019177where you want to format a suitable error message (but there are
75029178modules that can help with that problem)) always check
7503the return value from opening a file.
9179the return value from opening a file.
75049180
75059181=end original
75069182
7507ファイルを開く時、開くのに失敗した時に通常の処理を続けるのは
9183ファイルを開く時、開くのに失敗した時に通常の処理を続けるのは普通は悪い
7508普通は悪い考えですので、C<open> はしばしば C<die> と結び付けられて
9184考えので、L<C<open>|/open FILEHANDLE,EXPR> はしばしば
7509使われます。
9185L<C<die>|/die LIST> と結び付けられて使われます。
7510望むものが C<die> でない場合(例えば、CGI スクリプト のように
9186望むものが L<C<die>|/die LIST> でない場合(例えば、CGI スクリプトのように
75119187きれいにフォーマットされたエラーメッセージを作りたい場合
75129188(但しこの問題を助けるモジュールがあります))でも、
75139189ファイルを開いた時の返り値を常にチェックするべきです。
75149190
75159191=begin original
75169192
9193The filehandle will be closed when its reference count reaches zero.
9194If it is a lexically scoped variable declared with L<C<my>|/my VARLIST>,
9195that usually
9196means the end of the enclosing scope. However, this automatic close
9197does not check for errors, so it is better to explicitly close
9198filehandles, especially those used for writing:
9199
9200=end original
9201
9202ファイルハンドルは、参照カウントが 0 になったときに閉じられます。
9203これが L<C<my>|/my VARLIST> で宣言されたレキシカルスコープを持つ変数の場合、
9204普通は囲まれたスコープの終わりを意味します。
9205しかし、この自動閉じはエラーをチェックしないので、特に書き込み用の場合は、
9206明示的にファイルハンドルを閉じる方がよいです。
9207
9208 close($handle)
9209 || warn "close failed: $!";
9210
9211=begin original
9212
9213An older style is to use a bareword as the filehandle, as
9214
9215=end original
9216
9217より古いスタイルは、次のように、ファイルハンドルとして裸の単語を使います
9218
9219 open(FH, "<", "input.txt")
9220 or die "Can't open < input.txt: $!";
9221
9222=begin original
9223
9224Then you can use C<FH> as the filehandle, in C<< close FH >> and C<<
9225<FH> >> and so on. Note that it's a global variable, so this form is
9226not recommended in new code.
9227
9228=end original
9229
9230それから C<FH> を、C<< close FH >> や C<< <FH> >> などのように、
9231ファイルハンドルとして使えます。
9232これはグローバル変数なので、新しいコードでは非推奨であることに
9233注意してください。
9234
9235=begin original
9236
9237As a shortcut a one-argument call takes the filename from the global
9238scalar variable of the same name as the filehandle:
9239
9240=end original
9241
9242短縮版として、1 引数呼び出しでは、ファイル名を、ファイルハンドルと同じ名前の
9243グローバルなスカラ変数から取ります:
9244
9245 $ARTICLE = 100;
9246 open(ARTICLE) or die "Can't find article $ARTICLE: $!\n";
9247
9248=begin original
9249
9250Here C<$ARTICLE> must be a global (package) scalar variable - not one
9251declared with L<C<my>|/my VARLIST> or L<C<state>|/state VARLIST>.
9252
9253=end original
9254
9255ここで C<$ARTICLE> はグローバル(パッケージ)スカラ変数でなければなりません -
9256L<C<my>|/my VARLIST> や L<C<state>|/state VARLIST> で宣言された
9257変数ではありません。
9258
9259=begin original
9260
75179261As a special case the three-argument form with a read/write mode and the third
7518argument being C<undef>:
9262argument being L<C<undef>|/undef EXPR>:
75199263
75209264=end original
75219265
7522特別な場合として、3 引数の形で読み書きモードで 3 番目の引数が
9266特別な場合として、3 引数の形で読み書きモードで 3 番目の引数が L<C<undef>|/undef EXPR> の場合:
7523C<undef> の場合:
75249267
75259268 open(my $tmp, "+>", undef) or die ...
75269269
75279270=begin original
75289271
75299272opens a filehandle to an anonymous temporary file. Also using C<< +< >>
75309273works for symmetry, but you really should consider writing something
7531to the temporary file first. You will need to seek() to do the
9274to the temporary file first. You will need to
7532reading.
9275L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> to do the reading.
75339276
75349277=end original
75359278
75369279無名一時ファイルとしてファイルハンドルを開きます。
75379280また C<< +< >> も対称性のために動作しますが、
75389281一時ファイルにはまず何かを書き込みたいはずです。
7539読み込みを行うためには seek()必要です。
9282読み込みを行うためには L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>
9283必要です。
75409284
75419285=begin original
75429286
7543Since v5.8.0, Perl has built using PerlIO by default. Unless you've
9287Perl is built using PerlIO by default. Unless you've
75449288changed this (such as building Perl with C<Configure -Uuseperlio>), you can
75459289open filehandles directly to Perl scalars via:
75469290
75479291=end original
75489292
7549v5.8.0 から、Perl はデフォルトで PerlIO を使ってビルドされています。
9293Perl はデフォルトで PerlIO を使ってビルドされています。
75509294(C<Configure -Uuseperlio> して Perl をビルドするなどして)これを
75519295変更していない限り、以下のようにして、Perl スカラを直接ファイルハンドルで
75529296開くことができます:
75539297
7554 open($fh, ">", \$variable) || ..
9298 open(my $fh, ">", \$variable) || ..
75559299
75569300=begin original
75579301
75589302To (re)open C<STDOUT> or C<STDERR> as an in-memory file, close it first:
75599303
75609304=end original
75619305
75629306C<STDOUT> や C<STDERR> を「オンメモリの」ファイルとして
75639307再び開きたい場合は、先にそれを閉じます:
75649308
75659309 close STDOUT;
75669310 open(STDOUT, ">", \$variable)
75679311 or die "Can't open STDOUT: $!";
75689312
75699313=begin original
75709314
7571General examples:
9315See L<perliol> for detailed info on PerlIO.
75729316
75739317=end original
75749318
7575一般的な例:
9319PerlIO に関する詳しい情報については L<perliol> を参照してください。
75769320
7577 $ARTICLE = 100;
9321=begin original
7578 open(ARTICLE) or die "Can't find article $ARTICLE: $!\n";
7579 while (<ARTICLE>) {...
75809322
7581 open(LOG, ">>/usr/spool/news/twitlog"); # (log is reserved)
9323General examples:
7582 # if the open fails, output is discarded
75839324
7584 open(my $dbase, "+<", "dbase.mine") # open for update
9325=end original
7585 or die "Can't open 'dbase.mine' for update: $!";
75869326
7587 open(my $dbase, "+<dbase.mine") # ditto
9327一般的な例:
7588 or die "Can't open 'dbase.mine' for update: $!";
75899328
7590 open(ARTICLE, "-|", "caesar <$article") # decrypt article
9329 open(my $log, ">>", "/usr/spool/news/twitlog");
7591 or die "Can't start caesar: $!";
9330 # if the open fails, output is discarded
75929331
7593 open(ARTICLE, "caesar <$article |") # ditto
9332 open(my $dbase, "+<", "dbase.mine") # open for update
7594 or die "Can't start caesar: $!";
9333 or die "Can't open 'dbase.mine' for update: $!";
75959334
7596 open(EXTRACT, "|sort >Tmp$$") # $$ is our process id
9335 open(my $dbase, "+<dbase.mine") # ditto
7597 or die "Can't start sort: $!";
9336 or die "Can't open 'dbase.mine' for update: $!";
75989337
7599 # in-memory files
9338 open(my $article_fh, "-|", "caesar <$article") # decrypt
7600 open(MEMORY, ">", \$var)
9339 # article
7601 or die "Can't open memory file: $!";
9340 or die "Can't start caesar: $!";
7602 print MEMORY "foo!\n"; # output will appear in $var
76039341
7604 # process argument list of files along with any includes
9342 open(my $article_fh, "caesar <$article |") # ditto
9343 or die "Can't start caesar: $!";
76059344
7606 foreach $file (@ARGV) {
9345 open(my $out_fh, "|-", "sort >Tmp$$") # $$ is our process id
7607 process($file, "fh00");
9346 or die "Can't start sort: $!";
7608 }
76099347
7610 sub process {
9348 # in-memory files
7611 my($filename, $input) = @_;
9349 open(my $memory, ">", \$var)
7612 $input++; # this is a string increment
9350 or die "Can't open memory file: $!";
7613 unless (open($input, "<", $filename)) {
9351 print $memory "foo!\n"; # output will appear in $var
7614 print STDERR "Can't open $filename: $!\n";
7615 return;
7616 }
76179352
7618 local $_;
7619 while (<$input>) { # note use of indirection
7620 if (/^#include "(.*)"/) {
7621 process($1, $input);
7622 next;
7623 }
7624 #... # whatever
7625 }
7626 }
7627
76289353=begin original
76299354
7630See L<perliol> for detailed info on PerlIO.
7631
7632=end original
7633
7634PerlIO に関する詳しい情報については L<perliol> を参照してください。
7635
7636=begin original
7637
76389355You may also, in the Bourne shell tradition, specify an EXPR beginning
76399356with C<< >& >>, in which case the rest of the string is interpreted
76409357as the name of a filehandle (or file descriptor, if numeric) to be
7641duped (as C<dup(2)>) and opened. You may use C<&> after C<< > >>,
9358duped (as in L<dup(2)>) and opened. You may use C<&> after C<< > >>,
76429359C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>, and C<< +< >>.
76439360The mode you specify should match the mode of the original filehandle.
76449361(Duping a filehandle does not take into account any existing contents
7645of IO buffers.) If you use the three-argument form, then you can pass either a
9362of IO buffers.) If you use the three-argument
9363form, then you can pass either a
76469364number, the name of a filehandle, or the normal "reference to a glob".
76479365
76489366=end original
76499367
76509368Bourne シェルの慣例にしたがって、EXPR の先頭に C<< >& >>
76519369を付けると、EXPR の残りの文字列をファイルハンドル名
7652(数字であれば、ファイル記述子) と解釈して、それを (C<dup(2)> によって)
9370(数字であれば、ファイル記述子) と解釈して、それを (L<dup(2)> によって)
76539371複製してオープンします。
76549372C<&> は、C<< > >>, C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>,
76559373C<< +< >>というモード指定に付けることができます。
76569374指定するモード指定は、もとのファイルハンドルのモードと
76579375合っていないといけません。
76589376(ファイルハンドルの複製は既に存在する IO バッファの内容に含めません。)
765993773 引数形式を使う場合は、数値を渡すか、ファイルハンドルの名前を渡すか、
76609378通常の「グロブへのリファレンス」を渡します。
76619379
76629380=begin original
76639381
76649382Here is a script that saves, redirects, and restores C<STDOUT> and
76659383C<STDERR> using various methods:
76669384
76679385=end original
76689386
76699387C<STDOUT> と C<STDERR> 保存し、リダイレクトし、元に戻すスクリプトを示します:
76709388
76719389 #!/usr/bin/perl
76729390 open(my $oldout, ">&STDOUT") or die "Can't dup STDOUT: $!";
76739391 open(OLDERR, ">&", \*STDERR) or die "Can't dup STDERR: $!";
76749392
76759393 open(STDOUT, '>', "foo.out") or die "Can't redirect STDOUT: $!";
76769394 open(STDERR, ">&STDOUT") or die "Can't dup STDOUT: $!";
76779395
76789396 select STDERR; $| = 1; # make unbuffered
76799397 select STDOUT; $| = 1; # make unbuffered
76809398
76819399 print STDOUT "stdout 1\n"; # this works for
76829400 print STDERR "stderr 1\n"; # subprocesses too
76839401
76849402 open(STDOUT, ">&", $oldout) or die "Can't dup \$oldout: $!";
76859403 open(STDERR, ">&OLDERR") or die "Can't dup OLDERR: $!";
76869404
76879405 print STDOUT "stdout 2\n";
76889406 print STDERR "stderr 2\n";
76899407
76909408=begin original
76919409
76929410If you specify C<< '<&=X' >>, where C<X> is a file descriptor number
7693or a filehandle, then Perl will do an equivalent of C's C<fdopen> of
9411or a filehandle, then Perl will do an equivalent of C's L<fdopen(3)> of
7694that file descriptor (and not call C<dup(2)>); this is more
9412that file descriptor (and not call L<dup(2)>); this is more
76959413parsimonious of file descriptors. For example:
76969414
76979415=end original
76989416
76999417C<X> をファイル記述子の番号かファイルハンドルとして、
77009418C<< '<&=X' >> と指定すると、Perl はそのファイル記述子に対する
7701C の C<fdopen> と同じことを行ないます(そして C<dup(2)> は呼び出しません);
9419C の L<fdopen(3)> と同じことを行ないます(そして L<dup(2)> は呼び出しません);
77029420これはファイル記述子をより節約します。
7703例:
9421えば:
77049422
77059423 # open for input, reusing the fileno of $fd
7706 open(FILEHANDLE, "<&=$fd")
9424 open(my $fh, "<&=", $fd)
77079425
77089426=begin original
77099427
77109428or
77119429
77129430=end original
77139431
77149432または
77159433
7716 open(FILEHANDLE, "<&=", $fd)
9434 open(my $fh, "<&=$fd")
77179435
77189436=begin original
77199437
77209438or
77219439
77229440=end original
77239441
77249442または
77259443
7726 # open for append, using the fileno of OLDFH
9444 # open for append, using the fileno of $oldfh
7727 open(FH, ">>&=", OLDFH)
9445 open(my $fh, ">>&=", $oldfh)
77289446
77299447=begin original
77309448
7731or
7732
7733=end original
7734
7735または
7736
7737 open(FH, ">>&=OLDFH")
7738
7739=begin original
7740
77419449Being parsimonious on filehandles is also useful (besides being
77429450parsimonious) for example when something is dependent on file
7743descriptors, like for example locking using flock(). If you do just
9451descriptors, like for example locking using
7744C<< open(A, ">>&B") >>, the filehandle A will not have the same file
9452L<C<flock>|/flock FILEHANDLE,OPERATION>. If you do just
7745descriptor as B, and therefore flock(A) will not flock(B) nor vice
9453C<< open(my $A, ">>&", $B) >>, the filehandle C<$A> will not have the
7746versa. But with C<< open(A, ">>&=B") >>, the filehandles will share
9454same file descriptor as C<$B>, and therefore C<flock($A)> will not
7747the same underlying system file descriptor.
9455C<flock($B)> nor vice versa. But with C<< open(my $A, ">>&=", $B) >>,
9456the filehandles will share the same underlying system file descriptor.
77489457
77499458=end original
77509459
7751ファイルハンドルを倹約することは、何かがファイル記述子に依存している場合、
9460ファイルハンドルを倹約することは、(倹約できること以外に)何かが
7752例えば flock() を使ったファイルロックとった場合に有用です
9461ファイル記述子に依存して場合、例えば
7753(しかも倹約できます)。
9462L<C<flock>|/flock FILEHANDLE,OPERATION> を使った
7754C<< open(A, ">>&B") >> とすると、ファイルハンドル A は B 同じ
9463ファイルロックいった場合に有用です。
7755ファイル記述子にはならないので、flock(A) flock(B) は別々になりま
9464C<< open(my $A, ">>&", $B) >> とると、ファイルハンドル C<$A> は C<$B> と同じ
7756しかし C<< open(A, ">>&=B") >> ファイルハンドルは基礎とるシステムの
9465ファイル記述子にはならないので、C<flock($A)> と C<flock($B)> は別々にります。
9466しかし C<< open(my $A, ">>&=", $B) >> ではファイルハンドルは基礎となるシステムの
77579467同じファイル記述子を共有します。
77589468
77599469=begin original
77609470
77619471Note that under Perls older than 5.8.0, Perl uses the standard C library's'
7762fdopen() to implement the C<=> functionality. On many Unix systems,
9472L<fdopen(3)> to implement the C<=> functionality. On many Unix systems,
7763fdopen() fails when file descriptors exceed a certain value, typically 255.
9473L<fdopen(3)> fails when file descriptors exceed a certain value, typically 255.
77649474For Perls 5.8.0 and later, PerlIO is (most often) the default.
77659475
77669476=end original
77679477
776894785.8.0 より前の Perl の場合、C<=> 機能の実装は
7769標準 C ライブラリの fdopen() を使っています。
9479標準 C ライブラリの L<fdopen(3)> を使っています。
7770多くの Unix システムでは、fdopen() はファイル記述子がある値
9480多くの Unix システムでは、L<fdopen(3)> はファイル記述子がある値
77719481(典型的には 255)を超えた場合に失敗することが知られています。
777294825.8.0 以降の Perl では、(ほとんどの場合) PerlIO がデフォルトです。
77739483
77749484=begin original
77759485
7776You can see whether your Perl was built with PerlIO by running C<perl -V>
9486You can see whether your Perl was built with PerlIO by running
7777and looking for the C<useperlio=> line. If C<useperlio> is C<define>, you
9487C<perl -V:useperlio>. If it says C<'define'>, you have PerlIO;
7778have PerlIO; otherwise you don't.
9488otherwise you don't.
77799489
77809490=end original
77819491
77829492Perl が PerlIO つきでビルドされているかどうかを確認するには、
7783C<perl -V> として C<useperlio=> の行を見ます。
9493C<perl -V:useperlio> を見ます。
7784C<useperlio> が C<define> なら PerlIO を使っています;
9494これが C<'define'> なら PerlIO を使っています;
77859495そうでなければ使っていません。
77869496
77879497=begin original
77889498
77899499If you open a pipe on the command C<-> (that is, specify either C<|-> or C<-|>
7790with the one- or two-argument forms of C<open>),
9500with the one- or two-argument forms of
7791an implicit C<fork> is done, so C<open> returns twice: in the parent
9501L<C<open>|/open FILEHANDLE,EXPR>), an implicit L<C<fork>|/fork> is done,
7792process it returns the pid
9502so L<C<open>|/open FILEHANDLE,EXPR> returns twice: in the parent process
9503it returns the pid
77939504of the child process, and in the child process it returns (a defined) C<0>.
77949505Use C<defined($pid)> or C<//> to determine whether the open was successful.
77959506
77969507=end original
77979508
77981 引数 または 2 引数の形の C<open()> で (C<-|> や C<|-> というふうに)
95091 引数 または 2 引数の形の L<C<open>|/open FILEHANDLE,EXPR>)
7799C<-> というコマンドにパイプを開くと、暗黙の C<fork> が行なわれるので
9510(C<-|> や C<|-> というふうに) C<-> というコマンドにパイプを開くと、
7800C<open> は 2 回返ります;
9511暗黙の L<C<fork>|/fork> が行なわれるので、
9512L<C<open>|/open FILEHANDLE,EXPR> は 2 回返ります;
78019513親プロセスには子プロセスの pid が返され、子プロセスには (定義された) C<0> が
78029514返されます。
78039515open が成功したかどうかを調べるには、C<defined($pid)> または C<//> を
78049516使います。
78059517
78069518=begin original
78079519
78089520For example, use either
78099521
78109522=end original
78119523
78129524例えば、以下の二つ
78139525
7814 $child_pid = open(FROM_KID, "|-") // die "can't fork: $!";
9526 my $child_pid = open(my $from_kid, "-|") // die "Can't fork: $!";
78159527
78169528=begin original
78179529
78189530or
78199531
78209532=end original
78219533
78229534または
78239535
7824 $child_pid = open(TO_KID, "|-") // die "can't fork: $!";
9536 my $child_pid = open(my $to_kid, "|-") // die "Can't fork: $!";
78259537
78269538=begin original
78279539
7828followed by
9540followed by
78299541
78309542=end original
78319543
78329544を使って、後で以下のようにします。
78339545
78349546 if ($child_pid) {
78359547 # am the parent:
7836 # either write TO_KID or else read FROM_KID
9548 # either write $to_kid or else read $from_kid
78379549 ...
7838 wait $child_pid;
9550 waitpid $child_pid, 0;
78399551 } else {
78409552 # am the child; use STDIN/STDOUT normally
78419553 ...
78429554 exit;
7843 }
9555 }
78449556
78459557=begin original
78469558
78479559The filehandle behaves normally for the parent, but I/O to that
78489560filehandle is piped from/to the STDOUT/STDIN of the child process.
78499561In the child process, the filehandle isn't opened--I/O happens from/to
78509562the new STDOUT/STDIN. Typically this is used like the normal
78519563piped open when you want to exercise more control over just how the
78529564pipe command gets executed, such as when running setuid and
78539565you don't want to have to scan shell commands for metacharacters.
78549566
78559567=end original
78569568
7857親プロセスでは、このファイルハンドルは
9569親プロセスでは、このファイルハンドルは通常通りに動作しますが、行なわれる
7858通常通りに動作しますが、行なわれる入出力は、
9570入出力は、子プロセスの STDIN/STDOUT にパイプされます。
7859チャイルドプロセスの STDIN/STDOUT にパイプされます。
9571プロセス側では、そファイルハンドルは開かれず、入出力は新しい STDOUT
7860チャイルドプロセス側では、そのファイルハンドルは
9572STDIN に対して行なわれます。
7861オープンされず、入出力は新しい STDOUT か STDIN に対して行なわれます。
78629573これは、setuid で実行して、シェルコマンドのメタ文字を
78639574検索させたくないような場合に、パイプコマンドの起動の仕方を
78649575制御したいとき、普通のパイプの open と同じように使います。
78659576
78669577=begin original
78679578
78689579The following blocks are more or less equivalent:
78699580
78709581=end original
78719582
78729583以下の組み合わせは、だいたい同じものです:
78739584
7874 open(FOO, "|tr '[a-z]' '[A-Z]'");
9585 open(my $fh, "|tr '[a-z]' '[A-Z]'");
7875 open(FOO, "|-", "tr '[a-z]' '[A-Z]'");
9586 open(my $fh, "|-", "tr '[a-z]' '[A-Z]'");
7876 open(FOO, "|-") || exec 'tr', '[a-z]', '[A-Z]';
9587 open(my $fh, "|-") || exec 'tr', '[a-z]', '[A-Z]';
7877 open(FOO, "|-", "tr", '[a-z]', '[A-Z]');
9588 open(my $fh, "|-", "tr", '[a-z]', '[A-Z]');
78789589
7879 open(FOO, "cat -n '$file'|");
9590 open(my $fh, "cat -n '$file'|");
7880 open(FOO, "-|", "cat -n '$file'");
9591 open(my $fh, "-|", "cat -n '$file'");
7881 open(FOO, "-|") || exec "cat", "-n", $file;
9592 open(my $fh, "-|") || exec "cat", "-n", $file;
7882 open(FOO, "-|", "cat", "-n", $file);
9593 open(my $fh, "-|", "cat", "-n", $file);
78839594
78849595=begin original
78859596
78869597The last two examples in each block show the pipe as "list form", which is
78879598not yet supported on all platforms. A good rule of thumb is that if
7888your platform has a real C<fork()> (in other words, if your platform is
9599your platform has a real L<C<fork>|/fork> (in other words, if your platform is
7889Unix, including Linux and MacOS X), you can use the list form. You would
9600Unix, including Linux and MacOS X), you can use the list form. You would
78909601want to use the list form of the pipe so you can pass literal arguments
78919602to the command without risk of the shell interpreting any shell metacharacters
78929603in them. However, this also bars you from opening pipes to commands
78939604that intentionally contain shell metacharacters, such as:
78949605
78959606=end original
78969607
78979608それぞれのブロックの末尾二つの例ではパイプを「リスト形式」にしていますが、
78989609これはまだ全てのプラットフォームで対応しているわけではなりません。
7899よい経験則としては、もし実行しているプラットフォームで本当の C<fork()> が
9610よい経験則としては、もし実行しているプラットフォームで本当の
7900あれば(言い換えると、プラットフォームが Linux や MacOS X を含む Unix なら)
9611L<C<fork>|/fork> があれば(言い換えると、プラットフォームが Linux や
7901リスト形式が使えます。
9612MacOS X を含む Unix なら)リスト形式が使えます。
79029613パイプのリスト形式を使うことで、コマンドへのリテラルな引数を、
79039614シェルのメタ文字をシェルが解釈するリスクなしに渡すことができます。
79049615しかし、これは以下のように意図的にシェルメタ文字を含むコマンドをパイプとして
79059616開くことを妨げます:
79069617
7907 open(FOO, "|cat -n | expand -4 | lpr")
9618 open(my $fh, "|cat -n | expand -4 | lpr")
7908 // die "Can't open pipeline to lpr: $!";
9619 || die "Can't open pipeline to lpr: $!";
79099620
79109621=begin original
79119622
79129623See L<perlipc/"Safe Pipe Opens"> for more examples of this.
79139624
79149625=end original
79159626
7916これに関する更なる例については L<perlipc/"Safe Pipe Opens"> を参照して下さい。
9627これに関する更なる例については L<perlipc/"Safe Pipe Opens"> を
9628参照してください。
79179629
79189630=begin original
79199631
7920Beginning with v5.6.0, Perl will attempt to flush all files opened for
9632Perl will attempt to flush all files opened for
79219633output before any operation that may do a fork, but this may not be
79229634supported on some platforms (see L<perlport>). To be safe, you may need
7923to set C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method
9635to set L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>)
7924of C<IO::Handle> on any open handles.
9636or call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS>
9637on any open handles.
79259638
79269639=end original
79279640
79289641v5.6.0 から、Perl は書き込み用に開いている全てのファイルに対して
79299642fork を行う前にフラッシュしようとしますが、これに対応していない
79309643プラットフォームもあります(L<perlport> を参照してください)。
7931安全のために、C<$|> (English モジュールでは $AUTOFLUSH) をセットするか、
9644安全のために、L<C<$E<verbar>>|perlvar/$E<verbar>> (L<English> モジュールでは
7932全ての開いているハンドルに対して C<IO::Handle> の C<autoflush()> メソッドを
9645C<$AUTOFLUSH>) をセットするか、全ての開いているハンドルに対して
9646L<C<IO::Handle>|IO::Handle/METHODS> の C<autoflush> メソッドを
79339647呼び出す必要があるかもしれません。
79349648
79359649=begin original
79369650
79379651On systems that support a close-on-exec flag on files, the flag will
79389652be set for the newly opened file descriptor as determined by the value
7939of C<$^F>. See L<perlvar/$^F>.
9653of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>.
79409654
79419655=end original
79429656
79439657ファイルに対する close-on-exec フラグをサポートしているシステムでは、
7944フラグは C<$^F> の値で決定される、新しくオープンされたファイル記述子に対して
9658フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた
7945セットされます。
9659ファイル記述子に対してセットされます。
79469660L<perlvar/$^F> を参照してください。
79479661
79489662=begin original
79499663
79509664Closing any piped filehandle causes the parent process to wait for the
7951child to finish, then returns the status value in C<$?> and
9665child to finish, then returns the status value in L<C<$?>|perlvar/$?> and
7952C<${^CHILD_ERROR_NATIVE}>.
9666L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>.
79539667
79549668=end original
79559669
7956パイプのファイルハンドルを close することで、
9670パイプのファイルハンドルを close することで、親プロセスは、子プロセスの終了を
7957親プロセスは、チャイルドプロセスの終了を待ち、それから C<$?> と
9671待ち、それから L<C<$?>|perlvar/$?> と
7958C<${^CHILD_ERROR_NATIVE}> にステータス値を返します。
9672L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> にステータス値を
9673返します。
79599674
79609675=begin original
79619676
7962The filename passed to the one- and two-argument forms of open() will
9677The filename passed to the one- and two-argument forms of
9678L<C<open>|/open FILEHANDLE,EXPR> will
79639679have leading and trailing whitespace deleted and normal
79649680redirection characters honored. This property, known as "magic open",
79659681can often be used to good effect. A user could specify a filename of
79669682F<"rsh cat file |">, or you could change certain filenames as needed:
79679683
79689684=end original
79699685
79701 引数 と 2 引数の形の open() に渡されたファイル名は、
96861 引数 と 2 引数の形の L<C<open>|/open FILEHANDLE,EXPR> に渡された
7971はじめと終わりの空白が取り除かれ、
9687ファイル名、はじめと終わりの空白が取り除かれ、通常のリダイレクト文字列を
7972通常のリダイレクト文字列を受け付けます。
9688受け付けます。
7973この機能は "magic open" として知られていますが、
9689この機能は "magic open" として知られていますが、普通いい効果をもたらします。
7974普通いい効果をもたらします。
79759690ユーザーは F<"rsh cat file |"> といったファイル名を指定できますし、
79769691特定のファイル名を必要に応じて変更できます。
79779692
79789693 $filename =~ s/(.*\.gz)\s*$/gzip -dc < $1|/;
7979 open(FH, $filename) or die "Can't open $filename: $!";
9694 open(my $fh, $filename) or die "Can't open $filename: $!";
79809695
79819696=begin original
79829697
79839698Use the three-argument form to open a file with arbitrary weird characters in it,
79849699
79859700=end original
79869701
79879702妙な文字が含まれているようなファイル名をオープンするには、
798897033 引数の形を使います。
79899704
7990 open(FOO, "<", $file)
9705 open(my $fh, "<", $file)
7991 || die "can't open < $file: $!";
9706 || die "Can't open $file: $!";
79929707
79939708=begin original
79949709
79959710otherwise it's necessary to protect any leading and trailing whitespace:
79969711
79979712=end original
79989713
79999714あるいは、次のようにして、最初と最後の空白を保護します:
80009715
80019716 $file =~ s#^(\s)#./$1#;
8002 open(FOO, "< $file\0")
9717 open(my $fh, "< $file\0")
8003 || die "open failed: $!";
9718 || die "Can't open $file: $!";
80049719
80059720=begin original
80069721
80079722(this may not work on some bizarre filesystems). One should
80089723conscientiously choose between the I<magic> and I<three-argument> form
8009of open():
9724of L<C<open>|/open FILEHANDLE,EXPR>:
80109725
80119726=end original
80129727
80139728(これは奇妙なファイルシステムでは動作しないかもしれません)。
8014open() の I<magic> と I<3 引数> 形式を誠実に選択するべきです。
9729L<C<open>|/open FILEHANDLE,EXPR> の I<magic> と I<3 引数> 形式を誠実に
9730選択するべきです。
80159731
8016 open(IN, $ARGV[0]) || die "can't open $ARGV[0]: $!";
9732 open(my $in, $ARGV[0]) || die "Can't open $ARGV[0]: $!";
80179733
80189734=begin original
80199735
80209736will allow the user to specify an argument of the form C<"rsh cat file |">,
80219737but will not work on a filename that happens to have a trailing space, while
80229738
80239739=end original
80249740
80259741とするとユーザーは C<"rsh cat file |"> という形の引数を指定できますが、
8026末尾にスペースがついてしまったファイル名では動作しません一方:
9742末尾にスペースがついてしまったファイル名では動作しません; 一方:
80279743
8028 open(IN, "<", $ARGV[0])
9744 open(my $in, "<", $ARGV[0])
8029 || die "can't open < $ARGV[0]: $!";
9745 || die "Can't open $ARGV[0]: $!";
80309746
80319747=begin original
80329748
8033will have exactly the opposite restrictions.
9749will have exactly the opposite restrictions. (However, some shells
9750support the syntax C<< perl your_program.pl <( rsh cat file ) >>, which
9751produces a filename that can be opened normally.)
80349752
80359753=end original
80369754
80379755はまったく逆の制限があります。
9756(しかし、一部のシェルは C<< perl your_program.pl <( rsh cat file ) >> という
9757文法に対応していて、普通に開くことが出来るファイル名を出力します。)
80389758
80399759=begin original
80409760
8041If you want a "real" C C<open> (see C<open(2)> on your system), then you
9761If you want a "real" C L<open(2)>, then you should use the
8042should use the C<sysopen> function, which involves no such magic (but may
9762L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> function, which involves
8043use subtly different filemodes than Perl open(), which is mapped to C
9763no such magic (but uses different filemodes than Perl
8044fopen()). This is another way to protect your filenames from
9764L<C<open>|/open FILEHANDLE,EXPR>, which corresponds to C L<fopen(3)>).
8045interpretation. For example:
9765This is another way to protect your filenames from interpretation. For
9766example:
80469767
80479768=end original
80489769
8049もし「本当の」C 言語の C<open> (システムの C<open(2)> を参照してください)
9770もし「本当の」C 言語の L<open(2)> が必要なら、このような副作用のない
8050必要なら、このような副作用のない C<sysopen> 関数を使うべきです
9771L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> 関数を使うべきです
8051(ただし、C の fopen() に割り付けられる Perl の open() とは
9772(ただし、C の L<fopen(3)>対応する Perl の
8052かすかに違うファイルモードを持ちます)。
9773L<C<open>|/open FILEHANDLE,EXPR> とは違うファイルモードを持ちます)。
80539774これはファイル名を解釈から守るもう一つの方法です。
80549775例えば:
80559776
80569777 use IO::Handle;
8057 sysopen(HANDLE, $path, O_RDWR|O_CREAT|O_EXCL)
9778 sysopen(my $fh, $path, O_RDWR|O_CREAT|O_EXCL)
8058 or die "sysopen $path: $!";
9779 or die "Can't open $path: $!";
8059 $oldfh = select(HANDLE); $| = 1; select($oldfh);
9780 $fh->autoflush(1);
8060 print HANDLE "stuff $$\n";
9781 print $fh "stuff $$\n";
8061 seek(HANDLE, 0, 0);
9782 seek($fh, 0, 0);
8062 print "File contains: ", <HANDLE>;
9783 print "File contains: ", readline($fh);
80639784
80649785=begin original
80659786
8066Using the constructor from the C<IO::Handle> package (or one of its
9787See L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> for some details about
8067subclasses, such as C<IO::File> or C<IO::Socket>), you can generate anonymous
9788mixing reading and writing.
8068filehandles that have the scope of the variables used to hold them, then
8069automatically (but silently) close once their reference counts become
8070zero, typically at scope exit:
80719789
80729790=end original
80739791
8074C<IO::Handle> パッケージ(または C<IO::File> や C<IO::Socket> とった
9792読み書きを混ぜる場合の詳細につては
8075サブパッケージ)のコンストラクタ使うことで、
9793L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> 参照してください。
8076これらへのリファレンスを保持している変数のスコープを持ち、それから
8077参照カウントが 0 になると自動的に (しかし暗黙に) 閉じる
8078無名ファイルハンドルを作成できます:
80799794
8080 use IO::File;
8081 #...
8082 sub read_myfile_munged {
8083 my $ALL = shift;
8084 # or just leave it undef to autoviv
8085 my $handle = IO::File->new;
8086 open($handle, "<", "myfile") or die "myfile: $!";
8087 $first = <$handle>
8088 or return (); # Automatically closed here.
8089 mung($first) or die "mung failed"; # Or here.
8090 return (first, <$handle>) if $ALL; # Or here.
8091 return $first; # Or here.
8092 }
8093
80949795=begin original
80959796
8096B<WARNING:> The previous example has a bug because the automatic
9797Portability issues: L<perlport/open>.
8097close that happens when the refcount on C<handle> does not
8098properly detect and report failures. I<Always> close the handle
8099yourself and inspect the return value.
81009798
81019799=end original
81029800
8103B<警告:> 自動的に閉じると、C<handle> の参照カウントが適切に検出できない
9801移植性の問題: L<perlport/open>
8104ときに失敗が報告されるのでバグがあります。
8105I<常に> ハンドルを自分自身で閉じて、返り値を調べてください。
81069802
8107 close($handle)
8108 || warn "close failed: $!";
8109
8110=begin original
8111
8112See L</seek> for some details about mixing reading and writing.
8113
8114=end original
8115
8116読み書きを混ぜる場合の詳細については L</seek> を参照して下さい。
8117
81189803=item opendir DIRHANDLE,EXPR
81199804X<opendir>
81209805
9806=for Pod::Functions open a directory
9807
81219808=begin original
81229809
8123Opens a directory named EXPR for processing by C<readdir>, C<telldir>,
9810Opens a directory named EXPR for processing by
8124C<seekdir>, C<rewinddir>, and C<closedir>. Returns true if successful.
9811L<C<readdir>|/readdir DIRHANDLE>, L<C<telldir>|/telldir DIRHANDLE>,
9812L<C<seekdir>|/seekdir DIRHANDLE,POS>,
9813L<C<rewinddir>|/rewinddir DIRHANDLE>, and
9814L<C<closedir>|/closedir DIRHANDLE>. Returns true if successful.
81259815DIRHANDLE may be an expression whose value can be used as an indirect
81269816dirhandle, usually the real dirhandle name. If DIRHANDLE is an undefined
81279817scalar variable (or array or hash element), the variable is assigned a
81289818reference to a new anonymous dirhandle; that is, it's autovivified.
81299819DIRHANDLEs have their own namespace separate from FILEHANDLEs.
81309820
81319821=end original
81329822
8133C<readdir>、C<telldir>、C<seekdir>、C<rewinddir>、C<closedir>
9823L<C<readdir>|/readdir DIRHANDLE>、L<C<telldir>|/telldir DIRHANDLE>、
8134処理するために、EXPR で指定された名前のディレクトリをオープンします。
9824L<C<seekdir>|/seekdir DIRHANDLE,POS>、L<C<rewinddir>|/rewinddir DIRHANDLE>、
9825L<C<closedir>|/closedir DIRHANDLE> で処理するために、EXPR で指定された名前の
9826ディレクトリをオープンします。
81359827成功時には真を返します。
81369828DIRHANDLE は間接ディレクトリハンドルとして使える値(普通は実際のディレクトリ
81379829ハンドルの名前)となる式でも構いません。
81389830DIRHANDLE が未定義のスカラ値(または配列かハッシュの要素)の場合、その変数は
81399831新しい無名ディレクトリハンドルへのリファレンスが代入されます; つまり、
81409832自動有効化されます。
81419833DIRHANDLE は、FILEHANDLE とは別に名前空間を持っています。
81429834
81439835=begin original
81449836
8145See the example at C<readdir>.
9837See the example at L<C<readdir>|/readdir DIRHANDLE>.
81469838
81479839=end original
81489840
8149C<readdir> の例を参照してください。
9841L<C<readdir>|/readdir DIRHANDLE> の例を参照してください。
81509842
81519843=item ord EXPR
81529844X<ord> X<encoding>
81539845
81549846=item ord
81559847
9848=for Pod::Functions find a character's numeric representation
9849
81569850=begin original
81579851
8158Returns the numeric (the native 8-bit encoding, like ASCII or EBCDIC,
9852Returns the numeric value of the first character of EXPR.
8159or Unicode) value of the first character of EXPR.
9853If EXPR is an empty string, returns 0. If EXPR is omitted, uses
8160If EXPR is an empty string, returns 0. If EXPR is omitted, uses C<$_>.
9854L<C<$_>|perlvar/$_>.
81619855(Note I<character>, not byte.)
81629856
81639857=end original
81649858
8165EXPR の最初の文字の数値としての(ASCII, EBCDIC, Unicode のような 8-bit
9859EXPR の最初の文字の数値としての値を返します。
8166ネイティブエンコーディングの)値を返します。
81679860EXPR が空文字列の場合は、0 を返します。
8168EXPR 省略した場合は、C<$_> を使用します。
9861EXPR 省略されるとL<C<$_>|perlvar/$_> を使ます。
81699862(バイトではなく I<文字> であることに注意してください。)
81709863
81719864=begin original
81729865
8173For the reverse, see L</chr>.
9866For the reverse, see L<C<chr>|/chr NUMBER>.
81749867See L<perlunicode> for more about Unicode.
81759868
81769869=end original
81779870
8178逆のことをするには L</chr> を参照してください。
9871逆のことをするには L<C<chr>|/chr NUMBER> を参照してください。
81799872Unicode については L<perlunicode> を参照してください。
81809873
8181=item our EXPR
9874=item our VARLIST
81829875X<our> X<global>
81839876
8184=item our TYPE EXPR
9877=item our TYPE VARLIST
81859878
8186=item our EXPR : ATTRS
9879=item our VARLIST : ATTRS
81879880
8188=item our TYPE EXPR : ATTRS
9881=item our TYPE VARLIST : ATTRS
81899882
9883=for Pod::Functions +5.6.0 declare and assign a package variable (lexical scoping)
9884
81909885=begin original
81919886
8192C<our> associates a simple name with a package variable in the current
9887L<C<our>|/our VARLIST> makes a lexical alias to a package (i.e. global)
8193package for use within the current scope. When C<use strict 'vars'> is in
9888variable of the same name in the current package for use within the
8194effect, C<our> lets you use declared global variables without qualifying
9889current lexical scope.
8195them with package names, within the lexical scope of the C<our> declaration.
8196In this way C<our> differs from C<use vars>, which is package-scoped.
81979890
81989891=end original
81999892
8200C<our> は単純名を、現在のスコープ内で使うために、現在のパッケージの
9893L<C<our>|/our VARLIST> は単純名を、現在のレキシカルスコープ内で使うために、
8201パッケージ変数と結び付けます。
9894現在のパッケージの同じ名前のパッケージ(つまりグローバルな)変数への
8202C<use strict 'vars'> が有効の場合は、C<our> 使うことで、C<our> 宣言の
9895レキシカルな別名作ります。
8203レキシカルスコープ内で、宣言されたグローバル変数をパッケージ名で
8204修飾することなく使うことができます。
8205この意味では、C<use vars> はパッケージスコープなので、C<our> とは異なります。
82069896
82079897=begin original
82089898
8209Unlike C<my> or C<state>, which allocates storage for a variable and
9899L<C<our>|/our VARLIST> has the same scoping rules as
8210associates a simple name with that storage for use within the current
9900L<C<my>|/my VARLIST> or L<C<state>|/state VARLIST>, meaning that it is
8211scope, C<our> associates a simple name with a package (read: global)
9901only valid within a lexical scope. Unlike L<C<my>|/my VARLIST> and
8212variable in the current package, for use within the current lexical scope.
9902L<C<state>|/state VARLIST>, which both declare new (lexical) variables,
8213In other words, C<our> has the same scoping rules as C<my> or C<state>, but
9903L<C<our>|/our VARLIST> only creates an alias to an existing variable: a
8214does not necessarily create a variable.
9904package variable of the same name.
82159905
82169906=end original
82179907
8218記憶領域を変数に割り当て、単純名を現在のスコープ内で使うためにその記憶領域に
9908L<C<our>|/our VARLIST> は L<C<my>|/my VARLIST> や
8219割り当てる C<my> や C<state> と違って、C<our> は単純名を、現在のレキシカ
9909L<C<state>|/state VARLIST> と同じスコープールを持ちます; つまり
8220スコープ内で使うために、現在パッケージの(読み込み: グローバル) パッケージ
9910レキシカルスコープの中でだけ有効です。
8221変数と結び付けま
9911新しい(レキシカル)変数を宣言る L<C<my>|/my VARLIST> や
8222言い換えると、C<our> は C<my> や C<state> と同じスコープルールを持ちますが
9912L<C<state>|/state VARLIST> と異なりL<C<our>|/our VARLIST> は既に
8223変数を作る必要はありません
9913存在する変数への別名を作るだけです: 同じ名前のパッケージ変数です
82249914
82259915=begin original
82269916
8227If more than one value is listed, the list must be placed
9917This means that when C<use strict 'vars'> is in effect, L<C<our>|/our
9918VARLIST> lets you use a package variable without qualifying it with the
9919package name, but only within the lexical scope of the
9920L<C<our>|/our VARLIST> declaration. This applies immediately--even
9921within the same statement.
9922
9923=end original
9924
9925つまり、C<use strict 'vars'> が有効の場合は、L<C<our>|/our VARLIST> を
9926使うことで、
9927パッケージ変数をパッケージ名で修飾することなく使うことができますが、
9928L<C<our>|/our VARLIST> 宣言のレキシカルスコープ内だけということです。
9929これは(たとえ同じ文の中でも)直ちに適用されます。
9930
9931 package Foo;
9932 use strict;
9933
9934 $Foo::foo = 23;
9935
9936 {
9937 our $foo; # alias to $Foo::foo
9938 print $foo; # prints 23
9939 }
9940
9941 print $Foo::foo; # prints 23
9942
9943 print $foo; # ERROR: requires explicit package name
9944
9945=begin original
9946
9947This works even if the package variable has not been used before, as
9948package variables spring into existence when first used.
9949
9950=end original
9951
9952これはパッケージ変数がまだ使われていなくても動作します; パッケージ変数は、
9953最初に使われた時にひょっこり現れるからです。
9954
9955 package Foo;
9956 use strict;
9957
9958 our $foo = 23; # just like $Foo::foo = 23
9959
9960 print $Foo::foo; # prints 23
9961
9962=begin original
9963
9964Because the variable becomes legal immediately under C<use strict 'vars'>, so
9965long as there is no variable with that name is already in scope, you can then
9966reference the package variable again even within the same statement.
9967
9968=end original
9969
9970変数は C<use strict 'vars'> の基で直ちに正当になるので、
9971スコープ内に同じ名前の変数がない限り、
9972たとえ同じ文の中でもパッケージ変数を再び参照できます。
9973
9974 package Foo;
9975 use strict;
9976
9977 my $foo = $foo; # error, undeclared $foo on right-hand side
9978 our $foo = $foo; # no errors
9979
9980=begin original
9981
9982If more than one variable is listed, the list must be placed
82289983in parentheses.
82299984
82309985=end original
82319986
8232二つ以上リストする場合は、リストはかっこでくくる必要がありま
9987複数変数指定する場合は、リストはかっこでくくらなければなりません
82339988
8234 our $foo;
82359989 our($bar, $baz);
82369990
82379991=begin original
82389992
8239An C<our> declaration declares a global variable that will be visible
9993An L<C<our>|/our VARLIST> declaration declares an alias for a package
9994variable that will be visible
82409995across its entire lexical scope, even across package boundaries. The
82419996package in which the variable is entered is determined at the point
82429997of the declaration, not at the point of use. This means the following
82439998behavior holds:
82449999
824510000=end original
824610001
8247C<our> 宣言はレキシカルスコープ全体に対して(たとえパッケージ境界を
10002L<C<our>|/our VARLIST> 宣言はレキシカルスコープ全体に対して (たとえ
8248越えていても)見えるグロバル変数を宣言します。
10003パッケージ境界を越えていても)見える、パッケ変数への別名を宣言します。
824910004この変数が入るパッケージは宣言した時点で定義され、
825010005使用した時点ではありません。
825110006これにより、以下のような振る舞いになります:
825210007
825310008 package Foo;
825410009 our $bar; # declares $Foo::bar for rest of lexical scope
825510010 $bar = 20;
825610011
825710012 package Bar;
825810013 print $bar; # prints 20, as it refers to $Foo::bar
825910014
826010015=begin original
826110016
8262Multiple C<our> declarations with the same name in the same lexical
10017Multiple L<C<our>|/our VARLIST> declarations with the same name in the
10018same lexical
826310019scope are allowed if they are in different packages. If they happen
826410020to be in the same package, Perl will emit warnings if you have asked
8265for them, just like multiple C<my> declarations. Unlike a second
10021for them, just like multiple L<C<my>|/my VARLIST> declarations. Unlike
8266C<my> declaration, which will bind the name to a fresh variable, a
10022a second L<C<my>|/my VARLIST> declaration, which will bind the name to a
8267second C<our> declaration in the same package, in the same scope, is
10023fresh variable, a second L<C<our>|/our VARLIST> declaration in the same
8268merely redundant.
10024package, in the same scope, is merely redundant.
826910025
827010026=end original
827110027
827210028同じレキシカルスコープでも、パッケージが異なっていれば、同じ名前で複数の
8273C<our> 宣言ができます。
10029L<C<our>|/our VARLIST> 宣言ができます。
827410030同じパッケージになっていると、警告が出力されるようになっていれば
8275複数の C<my> 宣言がある場合と同じように警告が出力されます。
10031複数の L<C<my>|/my VARLIST> 宣言がある場合と同じように警告が出力されます。
8276新しい変数を名前に割り当てることになる 2 回目の C<my> 宣言と違って、
10032新しい変数を名前に割り当てることになる 2 回目の L<C<my>|/my VARLIST> 宣言と
8277同じパッケージの同じスコープで 2 回 C<our> 宣言するのは単に冗長です。
10033違って、同じパッケージの同じスコープで 2 回
10034L<C<our>|/our VARLIST> 宣言するのは単に冗長です。
827810035
827910036 use warnings;
828010037 package Foo;
828110038 our $bar; # declares $Foo::bar for rest of lexical scope
828210039 $bar = 20;
828310040
828410041 package Bar;
828510042 our $bar = 30; # declares $Bar::bar for rest of lexical scope
828610043 print $bar; # prints 30
828710044
828810045 our $bar; # emits warning but has no other effect
828910046 print $bar; # still prints 30
829010047
829110048=begin original
829210049
8293An C<our> declaration may also have a list of attributes associated
10050An L<C<our>|/our VARLIST> declaration may also have a list of attributes
8294with it.
10051associated with it.
829510052
829610053=end original
829710054
8298C<our> 宣言には、それと結び付けられる属性のリストを持つこともあります。
10055L<C<our>|/our VARLIST> 宣言には、それと結び付けられる属性のリストを
10056持つこともあります。
829910057
830010058=begin original
830110059
830210060The exact semantics and interface of TYPE and ATTRS are still
8303evolving. TYPE is currently bound to the use of C<fields> pragma,
10061evolving. TYPE is currently bound to the use of the L<fields> pragma,
8304and attributes are handled using the C<attributes> pragma, or starting
10062and attributes are handled using the L<attributes> pragma, or, starting
8305from Perl 5.8.0 also via the C<Attribute::Handlers> module. See
10063from Perl 5.8.0, also via the L<Attribute::Handlers> module. See
8306L<perlsub/"Private Variables via my()"> for details, and L<fields>,
10064L<perlsub/"Private Variables via my()"> for details.
8307L<attributes>, and L<Attribute::Handlers>.
830810065
830910066=end original
831010067
831110068TYPE と ATTRS の正確な文法とインターフェースは今でも進化しています。
8312現在のところ、TYPE は C<fields> プラグマの使用と結び付けられていて、
10069現在のところ、TYPE は L<fields> プラグマの使用と結び付けられていて、
8313属性は C<attributes> プラグマか、Perl 5.8.0 からは
10070属性は L<attributes> プラグマか、Perl 5.8.0 からは
8314C<Attribute::Handlers> モジュールと結び付けられています。
10071L<Attribute::Handlers> モジュールと結び付けられています。
8315詳しくはL<perlsub/"Private Variables via my()">, L<fields>,
10072詳しくは L<perlsub/"Private Variables via my()"> を参照してください。
8316L<attributes>, L<Attribute::Handlers> を参照してください。
831710073
10074=begin original
10075
10076Note that with a parenthesised list, L<C<undef>|/undef EXPR> can be used
10077as a dummy placeholder, for example to skip assignment of initial
10078values:
10079
10080=end original
10081
10082かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> は、例えば初期値の代入を
10083飛ばすために、ダミーのプレースホルダとして使えることに注意してください:
10084
10085 our ( undef, $min, $hour ) = localtime;
10086
10087=begin original
10088
10089L<C<our>|/our VARLIST> differs from L<C<use vars>|vars>, which allows
10090use of an unqualified name I<only> within the affected package, but
10091across scopes.
10092
10093=end original
10094
10095L<C<our>|/our VARLIST> は L<C<use vars>|vars> と異なります; スコープを
10096またぐのではなく、影響するパッケージの内側 I<のみ> で完全修飾されていない
10097名前を使えるようにします。
10098
831810099=item pack TEMPLATE,LIST
831910100X<pack>
832010101
10102=for Pod::Functions convert a list into a binary representation
10103
832110104=begin original
832210105
832310106Takes a LIST of values and converts it into a string using the rules
832410107given by the TEMPLATE. The resulting string is the concatenation of
832510108the converted values. Typically, each converted value looks
832610109like its machine-level representation. For example, on 32-bit machines
832710110an integer may be represented by a sequence of 4 bytes, which will in
8328Perl be presented as a string that's 4 characters long.
10111Perl be presented as a string that's 4 characters long.
832910112
833010113=end original
833110114
833210115LIST の値を TEMPLATE で与えられたルールを用いて文字列に変換します。
833310116結果の文字列は変換した値を連結したものです。
833410117典型的には、それぞれの変換された値はマシンレベルの表現のように見えます。
833510118例えば、32-bit マシンでは、整数は 4 バイトで表現されるので、
833610119Perl では 4 文字の文字列で表現されます。
833710120
833810121=begin original
833910122
834010123See L<perlpacktut> for an introduction to this function.
834110124
834210125=end original
834310126
834410127この関数の説明については L<perlpacktut> を参照してください。
834510128
834610129=begin original
834710130
834810131The TEMPLATE is a sequence of characters that give the order and type
834910132of values, as follows:
835010133
835110134=end original
835210135
835310136TEMPLATE は、以下のような値の型と順番を指定する文字を並べたものです:
835410137
835510138=begin original
835610139
835710140 a A string with arbitrary binary data, will be null padded.
835810141 A A text (ASCII) string, will be space padded.
835910142 Z A null-terminated (ASCIZ) string, will be null padded.
836010143
836110144=end original
836210145
8363 a 任意のバイナリデータを含む文字列、ヌル文字で埋める
10146 a 任意のバイナリデータを含む文字列、ヌル文字で埋める
8364 A テキスト (ASCII) 文字列、スペース文字で埋める
10147 A テキスト (ASCII) 文字列、スペース文字で埋める
8365 Z ヌル文字終端 (ASCIZ) 文字列、ヌル文字で埋める
10148 Z ヌル文字終端 (ASCIZ) 文字列、ヌル文字で埋める
836610149
836710150=begin original
836810151
8369 b A bit string (ascending bit order inside each byte, like vec()).
10152 b A bit string (ascending bit order inside each byte,
10153 like vec()).
837010154 B A bit string (descending bit order inside each byte).
837110155 h A hex string (low nybble first).
837210156 H A hex string (high nybble first).
837310157
837410158=end original
837510159
8376 b ビット列 (バイトごとに昇ビット順、vec() と同じ)
10160 b ビット列 (バイトごとに昇ビット順、vec() と同じ)
8377 B ビット列 (バイトごとに降ビット順)
10161 B ビット列 (バイトごとに降ビット順)
8378 h 16 進数文字列 (低位ニブルが先)
10162 h 16 進数文字列 (低位ニブルが先)
8379 H 16 進数文字列 (高位ニブルが先)
10163 H 16 進数文字列 (高位ニブルが先)
838010164
838110165=begin original
838210166
838310167 c A signed char (8-bit) value.
838410168 C An unsigned char (octet) value.
838510169 W An unsigned char value (can be greater than 255).
838610170
838710171=end original
838810172
8389 c signed char (8 ビット) 値
10173 c signed char (8 ビット) 値
8390 C unsigned char (オクテット) 値
10174 C unsigned char (オクテット) 値
8391 W unsigned char 値 (255 より大きいかもしれません)
10175 W unsigned char 値 (255 より大きいかもしれません)
839210176
839310177=begin original
839410178
839510179 s A signed short (16-bit) value.
839610180 S An unsigned short value.
839710181
839810182=end original
839910183
8400 s signed short (16 ビット) 値
10184 s signed short (16 ビット) 値
8401 S unsigned short 値
10185 S unsigned short 値
840210186
840310187=begin original
840410188
840510189 l A signed long (32-bit) value.
840610190 L An unsigned long value.
840710191
840810192=end original
840910193
8410 l signed long (32 ビット) 値
10194 l signed long (32 ビット) 値
8411 L unsigned long 値
10195 L unsigned long 値
841210196
841310197=begin original
841410198
841510199 q A signed quad (64-bit) value.
841610200 Q An unsigned quad value.
8417 (Quads are available only if your system supports 64-bit
10201 (Quads are available only if your system supports 64-bit
8418 integer values _and_ if Perl has been compiled to support those.
10202 integer values _and_ if Perl has been compiled to support
8419 Raises an exception otherwise.)
10203 those. Raises an exception otherwise.)
842010204
842110205=end original
842210206
8423 q 符号付き 64 ビット整数
10207 q 符号付き 64 ビット整数
8424 Q 符号なし 64 ビット整数
10208 Q 符号なし 64 ビット整数
842510209 (64 ビット整数は、システムが 64 ビット整数に対応していて、かつ Perl が
842610210 64 ビット整数対応としてコンパイルされている場合にのみ使用可能です。
842710211 それ以外の場合は例外が発生します。)
842810212
842910213=begin original
843010214
843110215 i A signed integer value.
843210216 I A unsigned integer value.
8433 (This 'integer' is _at_least_ 32 bits wide. Its exact
10217 (This 'integer' is _at_least_ 32 bits wide. Its exact
8434 size depends on what a local C compiler calls 'int'.)
10218 size depends on what a local C compiler calls 'int'.)
843510219
843610220=end original
843710221
8438 i signed int 値
10222 i signed int 値
8439 I unsigned int 値
10223 I unsigned int 値
8440 (ここでの 'integer' は 「最低」 32 bits 幅です。
10224 (ここでの 'integer' は 「最低」 32 ビット幅です。正確なサイズは
8441 正確なサイズはローカルの C コンパイラの
10225 ローカルの C コンパイラの 'int' のサイズに依存します。)
8442 'int'のサイズに依存します)
844310226
844410227=begin original
844510228
844610229 n An unsigned short (16-bit) in "network" (big-endian) order.
844710230 N An unsigned long (32-bit) in "network" (big-endian) order.
844810231 v An unsigned short (16-bit) in "VAX" (little-endian) order.
844910232 V An unsigned long (32-bit) in "VAX" (little-endian) order.
845010233
845110234=end original
845210235
8453 n "network" 順序 (ビッグエンディアン) の unsigned short (16 ビット)
10236 n "network" 順序 (ビッグエンディアン) の unsigned short (16 ビット)
8454 N "network" 順序 (ビッグエンディアン) の unsigned long (32 ビット)
10237 N "network" 順序 (ビッグエンディアン) の unsigned long (32 ビット)
8455 v "VAX" 順序 (リトルエンディアン) の unsigned short (16 ビット)
10238 v "VAX" 順序 (リトルエンディアン) の unsigned short (16 ビット)
8456 V "VAX" 順序 (リトルエンディアン) の unsigned long (32 ビット)
10239 V "VAX" 順序 (リトルエンディアン) の unsigned long (32 ビット)
845710240
845810241=begin original
845910242
8460 j A Perl internal signed integer value (IV).
10243 j A Perl internal signed integer value (IV).
8461 J A Perl internal unsigned integer value (UV).
10244 J A Perl internal unsigned integer value (UV).
846210245
846310246=end original
846410247
8465 j Perl 内部符号付き整数 (IV)
10248 j Perl 内部符号付き整数 (IV)
8466 J Perl 内部符号なし整数 (UV)
10249 J Perl 内部符号なし整数 (UV)
846710250
846810251=begin original
846910252
847010253 f A single-precision float in native format.
847110254 d A double-precision float in native format.
847210255
847310256=end original
847410257
8475 f 機種依存の単精度浮動小数点数
10258 f 機種依存の単精度浮動小数点数
8476 d 機種依存の倍精度浮動小数点数
10259 d 機種依存の倍精度浮動小数点数
847710260
847810261=begin original
847910262
848010263 F A Perl internal floating-point value (NV) in native format
848110264 D A float of long-double precision in native format.
8482 (Long doubles are available only if your system supports long
10265 (Long doubles are available only if your system supports
8483 double values _and_ if Perl has been compiled to support those.
10266 long double values _and_ if Perl has been compiled to
8484 Raises an exception otherwise.)
10267 support those. Raises an exception otherwise.
10268 Note that there are different long double formats.)
848510269
848610270=end original
848710271
848810272 F ネイティブフォーマットの Perl 内部浮動小数点数 (NV)
8489 D ネイティブフォーマットの長い倍精度浮動小数点数(long double)
10273 D ネイティブフォーマットの長い倍精度浮動小数点数(long double)
849010274 (long double は、システムが long double に対応していて、かつ Perl が
849110275 long double 対応としてコンパイルされている場合にのみ使用可能です。
8492 それ以外の場合は例外が発生します。)
10276 それ以外の場合は例外が発生します。
10277 long double 型式の場合は異なることに注意してください)
849310278
849410279=begin original
849510280
849610281 p A pointer to a null-terminated string.
849710282 P A pointer to a structure (fixed-length string).
849810283
849910284=end original
850010285
8501 p ヌル文字で終端する文字列へのポインタ
10286 p ヌル文字で終端する文字列へのポインタ
8502 P 構造体 (固定長文字列) へのポインタ
10287 P 構造体 (固定長文字列) へのポインタ
850310288
850410289=begin original
850510290
850610291 u A uuencoded string.
8507 U A Unicode character number. Encodes to a character in character mode
10292 U A Unicode character number. Encodes to a character in char-
8508 and UTF-8 (or UTF-EBCDIC in EBCDIC platforms) in byte mode.
10293 acter mode and UTF-8 (or UTF-EBCDIC in EBCDIC platforms) in
10294 byte mode.
850910295
851010296=end original
851110297
8512 u uuencode 文字列
10298 u uuencode 文字列
851310299 U Unicode 文字番号。文字モードでは文字に、バイトモードなら UTF-8 に
8514 (EBCDIC システムでは UTF-EBCDIC に)エンコードされます
10300 (EBCDIC システムでは UTF-EBCDIC に)エンコードされます
851510301
851610302=begin original
851710303
8518 w A BER compressed integer (not an ASN.1 BER, see perlpacktut for
10304 w A BER compressed integer (not an ASN.1 BER, see perlpacktut
8519 details). Its bytes represent an unsigned integer in base 128,
10305 for details). Its bytes represent an unsigned integer in
8520 most significant digit first, with as few digits as possible. Bit
10306 base 128, most significant digit first, with as few digits
8521 eight (the high bit) is set on each byte except the last.
10307 as possible. Bit eight (the high bit) is set on each byte
10308 except the last.
852210309
852310310=end original
852410311
8525 w A BER 圧縮変数(ASN.1 BER ではありません詳細については perlpacktut を
10312 w A BER 圧縮変数(ASN.1 BER ではありません; 詳細については perlpacktut を
852610313 参照してください)。このバイト列はできるだけ少ない桁数で表現された
852710314 128 を基とした符号なし整数で、最上位ビットから順に並びます。
852810315 最後のバイト以外の各バイトのビット 8 (上位ビット) がセットされます。
852910316
853010317=begin original
853110318
853210319 x A null byte (a.k.a ASCII NUL, "\000", chr(0))
853310320 X Back up a byte.
853410321 @ Null-fill or truncate to absolute position, counted from the
853510322 start of the innermost ()-group.
8536 . Null-fill or truncate to absolute position specified by the value.
10323 . Null-fill or truncate to absolute position specified by
10324 the value.
853710325 ( Start of a ()-group.
853810326
853910327=end original
854010328
854110329 x ヌル文字 (つまり ASCII NUL, "\000", chr(0))
8542 X 1 文字後退
10330 X 1 文字後退
854310331 @ 一番内側の () の組の開始位置から数えて、絶対位置までヌル文字で
8544 埋めるか切り詰める
10332 埋めるか切り詰める
8545 . 値で指定した絶対位置までヌル文字で埋めるか切り詰める
10333 . 値で指定した絶対位置までヌル文字で埋めるか切り詰める
8546 ( () の組の開始
10334 ( () の組の開始
854710335
854810336=begin original
854910337
855010338One or more modifiers below may optionally follow certain letters in the
855110339TEMPLATE (the second column lists letters for which the modifier is valid):
855210340
855310341=end original
855410342
855510343以下に示す一つまたは複数の修飾子を、TEMPLATE の文字のいくつかにオプションで
855610344付けることができます(表の 2 列目は、その修飾子が有効な文字です):
855710345
855810346=begin original
855910347
856010348 ! sSlLiI Forces native (short, long, int) sizes instead
856110349 of fixed (16-/32-bit) sizes.
856210350
856310351=end original
856410352
856510353 ! sSlLiI 固定の(16/32 ビット)サイズではなく、ネイティブな
856610354 (short, long, int)サイズを強制する。
856710355
856810356=begin original
856910357
8570 xX Make x and X act as alignment commands.
10358 ! xX Make x and X act as alignment commands.
857110359
857210360=end original
857310361
8574 xX x と X をアライメントコマンドとして振舞わせる。
10362 ! xX x と X をアライメントコマンドとして振舞わせる。
857510363
857610364=begin original
857710365
8578 nNvV Treat integers as signed instead of unsigned.
10366 ! nNvV Treat integers as signed instead of unsigned.
857910367
858010368=end original
858110369
8582 nNvV 整数を符号なしではなく符号付きとして扱わせる。
10370 ! nNvV 整数を符号なしではなく符号付きとして扱わせる。
858310371
858410372=begin original
858510373
8586 @. Specify position as byte offset in the internal
10374 ! @. Specify position as byte offset in the internal
8587 representation of the packed string. Efficient but
10375 representation of the packed string. Efficient
8588 dangerous.
10376 but dangerous.
858910377
859010378=end original
859110379
8592 @. pack された内部表現のバイトオフセットとして位置を指定する。
10380 ! @. pack された内部表現のバイトオフセットとして位置を指定する。
859310381 効率的ですが危険です。
859410382
859510383=begin original
859610384
859710385 > sSiIlLqQ Force big-endian byte-order on the type.
859810386 jJfFdDpP (The "big end" touches the construct.)
859910387
860010388=end original
860110389
8602 > sSiIlLqQ これらの型のバイト順をビッグエンディアンに強制します
10390 > sSiIlLqQ これらの型のバイト順をビッグエンディアンに強制します
8603 jJfFdDpP (「大きい端」が構造に触れています)
10391 jJfFdDpP (「大きい端」が構造に触れています)
860410392
860510393=begin original
860610394
860710395 < sSiIlLqQ Force little-endian byte-order on the type.
860810396 jJfFdDpP (The "little end" touches the construct.)
860910397
861010398=end original
861110399
8612 < sSiIlLqQ これらの型のバイト順をリトルエンディアンに強制します
10400 < sSiIlLqQ これらの型のバイト順をリトルエンディアンに強制します
8613 jJfFdDpP (「小さい端」が構造に触れています)
10401 jJfFdDpP (「小さい端」が構造に触れています)
861410402
861510403=begin original
861610404
8617The C<< > >> and C<< < >> modifiers can also be used on C<()> groups
10405The C<< > >> and C<< < >> modifiers can also be used on C<()> groups
8618to force a particular byte-order on all components in that group,
10406to force a particular byte-order on all components in that group,
861910407including all its subgroups.
862010408
862110409=end original
862210410
862310411C<< > >> と C<< < >> の修飾子は C<()>-グループでも使えます;
862410412この場合はそのグループと全ての副グループ内の全ての要素を特定のバイト順に
862510413強制します。
862610414
10415=begin comment
10416
10417Larry recalls that the hex and bit string formats (H, h, B, b) were added to
10418pack for processing data from NASA's Magellan probe. Magellan was in an
10419elliptical orbit, using the antenna for the radar mapping when close to
10420Venus and for communicating data back to Earth for the rest of the orbit.
10421There were two transmission units, but one of these failed, and then the
10422other developed a fault whereby it would randomly flip the sense of all the
10423bits. It was easy to automatically detect complete records with the correct
10424sense, and complete records with all the bits flipped. However, this didn't
10425recover the records where the sense flipped midway. A colleague of Larry's
10426was able to pretty much eyeball where the records flipped, so they wrote an
10427editor named kybble (a pun on the dog food Kibbles 'n Bits) to enable him to
10428manually correct the records and recover the data. For this purpose pack
10429gained the hex and bit string format specifiers.
10430
10431git shows that they were added to perl 3.0 in patch #44 (Jan 1991, commit
1043227e2fb84680b9cc1), but the patch description makes no mention of their
10433addition, let alone the story behind them.
10434
10435=end comment
10436
862710437=begin original
862810438
862910439The following rules apply:
863010440
863110441=end original
863210442
863310443以下の条件が適用されます:
863410444
8635=over
10445=over
863610446
863710447=item *
863810448
863910449=begin original
864010450
864110451Each letter may optionally be followed by a number indicating the repeat
864210452count. A numeric repeat count may optionally be enclosed in brackets, as
864310453in C<pack("C[80]", @arr)>. The repeat count gobbles that many values from
864410454the LIST when used with all format types other than C<a>, C<A>, C<Z>, C<b>,
864510455C<B>, C<h>, C<H>, C<@>, C<.>, C<x>, C<X>, and C<P>, where it means
8646something else, dscribed below. Supplying a C<*> for the repeat count
10456something else, described below. Supplying a C<*> for the repeat count
864710457instead of a number means to use however many items are left, except for:
864810458
864910459=end original
865010460
865110461これらの文字の後には、繰り返し数を示す数字を付けることができます。
865210462数値の繰り返し数は C<pack "C[80]", @arr> のように大かっこで
865310463囲むこともできます。
865410464C<a>, C<A>, C<Z>, C<b>, C<B>, C<h>, C<H>, C<@>, C<.>, C<x>, C<X>, C<P>
865510465以外の全ての型では、LIST から繰り返し数の値を取り出して使います。
865610466繰り返し数に C<*> を指定すると、以下の例外を除いて、
865710467その時点で残っているすべての要素を意味します。
865810468
10469=over
865910470
10471=item *
866010472
8661=over
8662
8663=item *
8664
866510473=begin original
866610474
866710475C<@>, C<x>, and C<X>, where it is equivalent to C<0>.
866810476
866910477=end original
867010478
867110479C<@>, C<x>, C<X> では C<0> と等価です。
867210480
8673=item *
10481=item *
867410482
867510483=begin original
867610484
867710485<.>, where it means relative to the start of the string.
867810486
867910487=end original
868010488
8681C<.> では文字列の先頭からの相対位置を意味します。
10489<.> では文字列の先頭からの相対位置を意味します。
868210490
8683=item *
10491=item *
868410492
868510493=begin original
868610494
868710495C<u>, where it is equivalent to 1 (or 45, which here is equivalent).
868810496
868910497=end original
869010498
869110499C<u> では 1 (あるいはここでは 45 でも等価です) と等価です。
869210500
8693=back
10501=back
869410502
869510503=begin original
869610504
869710505One can replace a numeric repeat count with a template letter enclosed in
869810506brackets to use the packed byte length of the bracketed template for the
869910507repeat count.
870010508
870110509=end original
870210510
870310511このテンプレートでパックされたバイト長を繰り返し数として使うために、
870410512大かっこで囲まれたテンプレートで数値の繰り返し数を置き換えることが
870510513できます。
870610514
870710515=begin original
870810516
870910517For example, the template C<x[L]> skips as many bytes as in a packed long,
871010518and the template C<"$t X[$t] $t"> unpacks twice whatever $t (when
871110519variable-expanded) unpacks. If the template in brackets contains alignment
871210520commands (such as C<x![d]>), its packed length is calculated as if the
871310521start of the template had the maximal possible alignment.
871410522
871510523=end original
871610524
871710525例えば、テンプレート C<x[L]> は long でパックされたバイト数分だけスキップし、
871810526テンプレート C<"$t X[$t] $t"> は $t (変数展開された場合)を
871910527unpack したものの 2 倍を unpack します。
872010528(C<x![d]> のように) 大かっこにアライメントコマンドが含まれている場合、
872110529パックされた長さは、テンプレートの先頭で最大限可能なアライメントを
872210530持っているものとして計算されます。
872310531
872410532=begin original
872510533
872610534When used with C<Z>, a C<*> as the repeat count is guaranteed to add a
872710535trailing null byte, so the resulting string is always one byte longer than
872810536the byte length of the item itself.
872910537
873010538=end original
873110539
873210540C<Z> で、繰り返し数として C<*> が使われた場合、末尾にヌルバイトが
8733保証されるので、パックされた結果は常に要素 C<length> の値より
10541保証されるので、結果の文字列は常にアイテム自身バイト長よりも 1 バイト
87341 大きくなります。
10542くなります。
873510543
873610544=begin original
873710545
873810546When used with C<@>, the repeat count represents an offset from the start
873910547of the innermost C<()> group.
874010548
874110549=end original
874210550
874310551C<@> で使うと、繰り返し数は一番内側の C<()> グループの先頭からのオフセットを
874410552表現します。
874510553
874610554=begin original
874710555
874810556When used with C<.>, the repeat count determines the starting position to
874910557calculate the value offset as follows:
875010558
875110559=end original
875210560
875310561C<.> で使われると、繰り返し数は以下のようにして、
875410562値のオフセットを計算するための開始位置を決定するために使われます。
875510563
8756=over
10564=over
875710565
875810566=item *
875910567
876010568=begin original
876110569
876210570If the repeat count is C<0>, it's relative to the current position.
876310571
876410572=end original
876510573
876610574繰り返し数が C<0> なら、現在位置からの相対位置となります。
876710575
876810576=item *
876910577
877010578=begin original
877110579
877210580If the repeat count is C<*>, the offset is relative to the start of the
877310581packed string.
877410582
877510583=end original
877610584
8777繰り返し数が C<*> なら、オフセットは pack された文字列の先頭からの相対位置です。
10585繰り返し数が C<*> なら、オフセットは pack された文字列の先頭からの
10586相対位置です。
877810587
877910588=item *
878010589
878110590=begin original
878210591
878310592And if it's an integer I<n>, the offset is relative to the start of the
878410593I<n>th innermost C<( )> group, or to the start of the string if I<n> is
878510594bigger then the group level.
878610595
878710596=end original
878810597
878910598そして整数 I<n> なら、オフセットは一番内側から I<n> 番目の C<( )> グループの
879010599先頭、あるいは I<n> がグループレベルより大きい場合は文字列の先頭からの
879110600相対位置です。
879210601
879310602=back
879410603
879510604=begin original
879610605
879710606The repeat count for C<u> is interpreted as the maximal number of bytes
8798to encode per line of output, with 0, 1 and 2 replaced by 45. The repeat
10607to encode per line of output, with 0, 1 and 2 replaced by 45. The repeat
879910608count should not be more than 65.
880010609
880110610=end original
880210611
880310612C<u> での繰り返し回数は、出力行毎に最大何バイトまでをエンコードするかを
8804示します0, 1, 2 は 45 として扱われます。
10613示します; 0, 1, 2 は 45 として扱われます。
880510614繰り返し数は 65 を超えてはなりません。
880610615
880710616=item *
880810617
880910618=begin original
881010619
881110620The C<a>, C<A>, and C<Z> types gobble just one value, but pack it as a
881210621string of length count, padding with nulls or spaces as needed. When
881310622unpacking, C<A> strips trailing whitespace and nulls, C<Z> strips everything
881410623after the first null, and C<a> returns data with no stripping at all.
881510624
881610625=end original
881710626
881810627C<a>, C<A>, C<Z> という型を使うと、値を一つだけ取り出して使いますが、
881910628繰り返し数で示す長さの文字列となるように、必要に応じてヌル文字か
882010629スペース文字を付け足します。
8821unpack するとき、C<A> は後続の空白やヌル文字を取り除きます
10630unpack するとき、C<A> は後続の空白やヌル文字を取り除きます; C<Z> は最初の
8822C<Z> は最初のヌル文字以降の全てを取り除きます
10631ヌル文字以降の全てを取り除きます; C<a> はデータを取り除くことなく
8823C<a> はデータを取り除くことなくそのまま返します。
10632そのまま返します。
882410633
882510634=begin original
882610635
882710636If the value to pack is too long, the result is truncated. If it's too
882810637long and an explicit count is provided, C<Z> packs only C<$count-1> bytes,
882910638followed by a null byte. Thus C<Z> always packs a trailing null, except
883010639when the count is 0.
883110640
883210641=end original
883310642
883410643pack する値が長すぎる場合、結果は切り詰められます。
883510644長すぎてかつ明示的に個数が指定されている場合、
883610645C<Z> は C<$count-1> バイトまで pack し、その後にヌルバイトがつきます。
883710646従って、C<Z> は、繰り返し数が 0 の場合を除いて、常に末尾にヌルバイトが
883810647つきます。
883910648
884010649=item *
884110650
884210651=begin original
884310652
884410653Likewise, the C<b> and C<B> formats pack a string that's that many bits long.
884510654Each such format generates 1 bit of the result. These are typically followed
884610655by a repeat count like C<B8> or C<B64>.
884710656
884810657=end original
884910658
885010659同様に、C<b> や C<B> は、繰り返し数で示すビット長のビット列に pack します。
885110660これらの各文字は結果の 1 ビットを生成します。
885210661これらは典型的には C<B8> や C<B64> のような繰り返しカウントが引き続きます。
885310662
885410663=begin original
885510664
885610665Each result bit is based on the least-significant bit of the corresponding
885710666input character, i.e., on C<ord($char)%2>. In particular, characters C<"0">
885810667and C<"1"> generate bits 0 and 1, as do characters C<"\000"> and C<"\001">.
885910668
886010669=end original
886110670
886210671結果ビットのそれぞれは対応する入力文字の最下位ビットを基にします
886310672(つまり C<ord($char)%2>)。
886410673特に、文字 C<"0"> と C<"1"> は文字 C<"\000"> と C<"\001"> と同様に、
886510674ビット 0 と 1 を生成します。
886610675
886710676=begin original
886810677
886910678Starting from the beginning of the input string, each 8-tuple
887010679of characters is converted to 1 character of output. With format C<b>,
887110680the first character of the 8-tuple determines the least-significant bit of a
887210681character; with format C<B>, it determines the most-significant bit of
887310682a character.
887410683
887510684=end original
887610685
8877pack() の入力文字列の先頭から始めて、8 タプル毎に 1 文字の出力に
10686pack() の入力文字列の先頭から始めて、8 タプル毎に 1 文字の出力に変換されます。
8878変換されます。
887910687C<b> フォーマットでは 8 タプルの最初の文字が出力の最下位ビットとなります;
888010688C<B> フォーマットでは出力の最上位ビットとなります。
888110689
888210690=begin original
888310691
888410692If the length of the input string is not evenly divisible by 8, the
888510693remainder is packed as if the input string were padded by null characters
888610694at the end. Similarly during unpacking, "extra" bits are ignored.
888710695
888810696=end original
888910697
889010698もし入力文字列の長さが 8 で割り切れない場合、余りの部分は入力文字列の
889110699最後にヌル文字がパッディングされているものとしてパックされます。
889210700同様に、unpack 中は「余分な」ビットは無視されます。
889310701
889410702=begin original
889510703
889610704If the input string is longer than needed, remaining characters are ignored.
889710705
889810706=end original
889910707
890010708入力文字列が必要な分よりも長い場合、余分な文字は無視されます。
890110709
890210710=begin original
890310711
8904A C<*> for the repeat count uses all characters of the input field.
10712A C<*> for the repeat count uses all characters of the input field.
890510713On unpacking, bits are converted to a string of C<0>s and C<1>s.
890610714
890710715=end original
890810716
8909繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が
10717繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が使われます。
8910使われます。
891110718unpack 時にはビット列は C<0> と C<1> の文字列に変換されます。
891210719
891310720=item *
891410721
891510722=begin original
891610723
891710724The C<h> and C<H> formats pack a string that many nybbles (4-bit groups,
891810725representable as hexadecimal digits, C<"0".."9"> C<"a".."f">) long.
891910726
892010727=end original
892110728
892210729C<h> や C<H> は、多ニブル長(16 進文字である C<"0".."9"> C<"a".."f"> で
892310730表現可能な 4 ビットグループ)のニブル列に pack します。
892410731
892510732=begin original
892610733
8927For each such format, pack() generates 4 bits of result.
10734For each such format, L<C<pack>|/pack TEMPLATE,LIST> generates 4 bits of result.
892810735With non-alphabetical characters, the result is based on the 4 least-significant
892910736bits of the input character, i.e., on C<ord($char)%16>. In particular,
893010737characters C<"0"> and C<"1"> generate nybbles 0 and 1, as do bytes
893110738C<"\000"> and C<"\001">. For characters C<"a".."f"> and C<"A".."F">, the result
893210739is compatible with the usual hexadecimal digits, so that C<"a"> and
8933C<"A"> both generate the nybble C<0xA==10>. Use only these specific hex
10740C<"A"> both generate the nybble C<0xA==10>. Use only these specific hex
893410741characters with this format.
893510742
893610743=end original
893710744
8938このようなフォーマット文字のそれぞれについて、pack()
10745このようなフォーマット文字のそれぞれについて、L<C<pack>|/pack TEMPLATE,LIST>
893910746結果の 4 ビットを生成します。
894010747英字でない文字の場合、結果は入力文字の下位 4 ビットを
894110748基にします(つまり C<ord($char)%16>)。
894210749特に、文字 C<"0"> と C<"1"> はバイト C<"\000"> と C<"\001"> と同様に
894310750ニブル 0 と 1 を生成します。
8944文字 C<"a".."f"> と C<"A".."F"> の場合は結果は通常の
10751文字 C<"a".."f"> と C<"A".."F"> の場合は結果は通常の 16 進数と同じ結果に
894516 進数と同じ結果にりますので、C<"a"> と C<"A"> はどちらも
10752ので、C<"a"> と C<"A"> はどちらも ニブル C<0xa==10> を生成します。
8946ニブル C<0xa==10> を生成します。
894710753これらの 16 進文字はこの特定のフォーマットでだけ使ってください。
894810754
894910755=begin original
895010756
8951Starting from the beginning of the template to pack(), each pair
10757Starting from the beginning of the template to
10758L<C<pack>|/pack TEMPLATE,LIST>, each pair
895210759of characters is converted to 1 character of output. With format C<h>, the
895310760first character of the pair determines the least-significant nybble of the
895410761output character; with format C<H>, it determines the most-significant
895510762nybble.
895610763
895710764=end original
895810765
8959pack() のテンプレートの先頭から始めて、2 文字毎に 1 文字の出力
10766L<C<pack>|/pack TEMPLATE,LIST> のテンプレートの先頭から始めて、2 文字毎に
8960変換されます。
107671 文字の出力に変換されます。
896110768C<h> フォーマットでは 1 文字目が出力の最下位ニブルとなり、
896210769C<H> フォーマットでは出力の最上位ニブルとなります。
896310770
896410771=begin original
896510772
896610773If the length of the input string is not even, it behaves as if padded by
896710774a null character at the end. Similarly, "extra" nybbles are ignored during
896810775unpacking.
896910776
897010777=end original
897110778
897210779入力文字列の長さが偶数でない場合、最後にヌル文字でパッディングされて
897310780いるかのように振る舞います。
897410781同様に、unpack 中は「余分な」ニブルは無視されます。
897510782
897610783=begin original
897710784
897810785If the input string is longer than needed, extra characters are ignored.
897910786
898010787=end original
898110788
898210789入力文字列が必要な分より長い場合、余分な部分は無視されます。
898310790
898410791=begin original
898510792
898610793A C<*> for the repeat count uses all characters of the input field. For
8987unpack(), nybbles are converted to a string of hexadecimal digits.
10794L<C<unpack>|/unpack TEMPLATE,EXPR>, nybbles are converted to a string of
10795hexadecimal digits.
898810796
898910797=end original
899010798
8991繰り返し数として C<*> が指定されると、入力フィールドの全ての
10799繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が使われます。
8992文字が使われます。
10800L<C<unpack>|/unpack TEMPLATE,EXPR> 時にはニブルは 16 進数の文字列に
8993unpack() 時にはニブルは 16 進数の文字列に変換されます。
10801変換されます。
899410802
899510803=item *
899610804
899710805=begin original
899810806
899910807The C<p> format packs a pointer to a null-terminated string. You are
900010808responsible for ensuring that the string is not a temporary value, as that
900110809could potentially get deallocated before you got around to using the packed
900210810result. The C<P> format packs a pointer to a structure of the size indicated
900310811by the length. A null pointer is created if the corresponding value for
9004C<p> or C<P> is C<undef>; similarly with unpack(), where a null pointer
10812C<p> or C<P> is L<C<undef>|/undef EXPR>; similarly with
9005unpacks into C<undef>.
10813L<C<unpack>|/unpack TEMPLATE,EXPR>, where a null pointer unpacks into
10814L<C<undef>|/undef EXPR>.
900610815
900710816=end original
900810817
900910818C<p> は、ヌル文字終端文字列へのポインタを pack します。
901010819文字列が一時的な値でない(つまり pack された結果を使う前に文字列が
9011解放されない) ことに責任を持つ必要があります
10820解放されない) ことに責任を持つ必要があります
901210821C<P> は、指定した長さの構造体へのポインタを pack します。
9013C<p> または C<P> に対応する値が C<undef> だった場合、
10822C<p> または C<P> に対応する値が L<C<undef>|/undef EXPR> だった場合、
9014ヌルポインタが作成されます; ヌルポインタが C<undef>unpack される
10823ヌルポインタが作成されます; ヌルポインタが L<C<undef>|/undef EXPR> に
9015unpack() と同様です。
10824unpack される L<C<unpack>|/unpack TEMPLATE,EXPR> と同様です。
901610825
901710826=begin original
901810827
901910828If your system has a strange pointer size--meaning a pointer is neither as
902010829big as an int nor as big as a long--it may not be possible to pack or
902110830unpack pointers in big- or little-endian byte order. Attempting to do
902210831so raises an exception.
902310832
902410833=end original
902510834
902610835システムのポインタが変わったサイズの場合--つまり、int の大きさでも
902710836long の大きさでもない場合--ポインタをビッグエンディアンやリトルエンディアンの
902810837バイト順で pack や unpack することはできません。
902910838そうしようとすると例外が発生します。
903010839
903110840=item *
903210841
903310842=begin original
903410843
903510844The C</> template character allows packing and unpacking of a sequence of
903610845items where the packed structure contains a packed item count followed by
903710846the packed items themselves. This is useful when the structure you're
903810847unpacking has encoded the sizes or repeat counts for some of its fields
903910848within the structure itself as separate fields.
904010849
904110850=end original
904210851
904310852C</> テンプレート文字は、アイテムの数の後にアイテムそのものが入っている形の
904410853アイテム列を pack 及び unpack します。
904510854これは、unpack したい構造体が、サイズや繰り返し数が構造体自身の中に
904610855独立したフィールドとしてエンコードされている場合に有効です。
904710856
904810857=begin original
904910858
9050For C<pack>, you write I<length-item>C</>I<sequence-item>, and the
10859For L<C<pack>|/pack TEMPLATE,LIST>, you write
9051I<length-item> describes how the length value is packed. Formats likely
10860I<length-item>C</>I<sequence-item>, and the
10861I<length-item> describes how the length value is packed. Formats likely
905210862to be of most use are integer-packing ones like C<n> for Java strings,
905310863C<w> for ASN.1 or SNMP, and C<N> for Sun XDR.
905410864
905510865=end original
905610866
9057C<pack> では I<length-item>C</>I<string-item> の形になり、
10867L<C<pack>|/pack TEMPLATE,LIST> では I<length-item>C</>I<string-item> の
10868形になり、
905810869I<length-item> は長さの値がどのように pack されているかを指定します。
905910870もっともよく使われるのは Java 文字列 のための C<n>、ASN.1 や SNMP のための
906010871C<w>、Sun XDR のための C<N> といった整数型です。
906110872
906210873=begin original
906310874
9064For C<pack>, I<sequence-item> may have a repeat count, in which case
10875For L<C<pack>|/pack TEMPLATE,LIST>, I<sequence-item> may have a repeat
10876count, in which case
906510877the minimum of that and the number of available items is used as the argument
9066for I<length-item>. If it has no repeat count or uses a '*', the number
10878for I<length-item>. If it has no repeat count or uses a '*', the number
906710879of available items is used.
906810880
906910881=end original
907010882
9071C<pack> では、I<sequence-item> は繰り返し数を持つことがあり、その場合は
10883L<C<pack>|/pack TEMPLATE,LIST> では、I<sequence-item> は繰り返し数を
9072その最小値と利用可能なアイテムの数は I<length-item> のための引数として
10884持つことがあり、その場合はその最小値と利用可能なアイテムの数は
9073使われます。
10885I<length-item> のための引数として使われます。
907410886繰り返し数がなかったり、'*' を使うと、利用可能なアイテムの数が使われます。
907510887
907610888=begin original
907710889
9078For C<unpack>, an internal stack of integer arguments unpacked so far is
10890For L<C<unpack>|/unpack TEMPLATE,EXPR>, an internal stack of integer
9079used. You write C</>I<sequence-item> and the repeat count is obtained by
10891arguments unpacked so far is
9080popping off the last element from the stack. The I<sequence-item> must not
10892used. You write C</>I<sequence-item> and the repeat count is obtained by
10893popping off the last element from the stack. The I<sequence-item> must not
908110894have a repeat count.
908210895
908310896=end original
908410897
9085C<unpack> では、今まで unpack した数値引数の内部スタックが使われます。
10898L<C<unpack>|/unpack TEMPLATE,EXPR> では、今まで unpack した数値引数の
10899内部スタックが使われます。
908610900C</>I<sequence-item> と書いて、繰り返し数はスタックから最後の要素を
908710901取り出すことで得ます。
908810902I<sequence-item> は繰り返し数を持っていてはいけません。
908910903
909010904=begin original
909110905
909210906If I<sequence-item> refers to a string type (C<"A">, C<"a">, or C<"Z">),
909310907the I<length-item> is the string length, not the number of strings. With
909410908an explicit repeat count for pack, the packed string is adjusted to that
909510909length. For example:
909610910
909710911=end original
909810912
909910913I<sequence-item> が文字列型 (C<"A">, C<"a">, C<"Z">) を参照している場合、
910010914I<length-item> は文字列の数ではなく、文字列の長さです。
910110915pack で明示的な繰り返し数があると、pack された文字列は与えられた
910210916長さに調整されます。
910310917例えば:
910410918
9105 unpack("W/a", "\004Gurusamy") gives ("Guru")
10919 This code: gives this result:
9106 unpack("a3/A A*", "007 Bond J ") gives (" Bond", "J")
9107 unpack("a3 x2 /A A*", "007: Bond, J.") gives ("Bond, J", ".")
910810920
9109 pack("n/a* w/a","hello,","world") gives "\000\006hello,\005world"
10921 unpack("W/a", "\004Gurusamy") ("Guru")
9110 pack("a/W2", ord("a") .. ord("z")) gives "2ab"
10922 unpack("a3/A A*", "007 Bond J ") (" Bond", "J")
10923 unpack("a3 x2 /A A*", "007: Bond, J.") ("Bond, J", ".")
911110924
10925 pack("n/a* w/a","hello,","world") "\000\006hello,\005world"
10926 pack("a/W2", ord("a") .. ord("z")) "2ab"
10927
911210928=begin original
911310929
9114The I<length-item> is not returned explicitly from C<unpack>.
10930The I<length-item> is not returned explicitly from
10931L<C<unpack>|/unpack TEMPLATE,EXPR>.
911510932
911610933=end original
911710934
9118I<length-item> は C<unpack> から明示的には返されません。
10935I<length-item> は L<C<unpack>|/unpack TEMPLATE,EXPR> から明示的には
10936返されません。
911910937
912010938=begin original
912110939
912210940Supplying a count to the I<length-item> format letter is only useful with
912310941C<A>, C<a>, or C<Z>. Packing with a I<length-item> of C<a> or C<Z> may
912410942introduce C<"\000"> characters, which Perl does not regard as legal in
912510943numeric strings.
912610944
912710945=end original
912810946
912910947I<length-item> 文字に繰り返し数をつけるのは、
913010948文字が C<A>, C<a>, C<Z> でない限りは有用ではありません。
913110949C<a> や C<Z> を I<length-item> として pack すると C<"\000"> 文字が
913210950出力されることがあり、Perl はこれを有効な数値文字列として認識しません。
913310951
913410952=item *
913510953
913610954=begin original
913710955
913810956The integer types C<s>, C<S>, C<l>, and C<L> may be
913910957followed by a C<!> modifier to specify native shorts or
914010958longs. As shown in the example above, a bare C<l> means
914110959exactly 32 bits, although the native C<long> as seen by the local C compiler
914210960may be larger. This is mainly an issue on 64-bit platforms. You can
914310961see whether using C<!> makes any difference this way:
914410962
914510963=end original
914610964
914710965C<s>, C<S>, C<l>, C<L> の整数タイプに引き続いて C<!> 修飾子を
914810966つけることで、ネイティブの short や long を指定できます。
914910967上述のように、C<l> は正確に 32 ビットですが、ネイティブな
915010968(ローカルな C コンパイラによる)C<long> はもっと大きいかもしれません。
915110969これは主に 64 ビットプラットフォームで意味があります。
915210970C<!> を使うことによって違いがあるかどうかは以下のようにして調べられます:
915310971
9154 printf "format s is %d, s! is %d\n",
10972 printf "format s is %d, s! is %d\n",
915510973 length pack("s"), length pack("s!");
915610974
9157 printf "format l is %d, l! is %d\n",
10975 printf "format l is %d, l! is %d\n",
915810976 length pack("l"), length pack("l!");
915910977
916010978=begin original
916110979
916210980C<i!> and C<I!> are also allowed, but only for completeness' sake:
916310981they are identical to C<i> and C<I>.
916410982
916510983=end original
916610984
916710985C<i!> と C<I!> も動作しますが、単に完全性のためだけです;
916810986これは C<i> 及び C<I> と同じです。
916910987
917010988=begin original
917110989
917210990The actual sizes (in bytes) of native shorts, ints, longs, and long
917310991longs on the platform where Perl was built are also available from
917410992the command line:
917510993
917610994=end original
917710995
917810996Perl がビルドされたプラットフォームでの short, int, long, long long の
917910997実際の(バイト数での)サイズはコマンドラインから:
918010998
918110999 $ perl -V:{short,int,long{,long}}size
918211000 shortsize='2';
918311001 intsize='4';
918411002 longsize='4';
918511003 longlongsize='8';
918611004
918711005=begin original
918811006
9189or programmatically via the C<Config> module:
11007or programmatically via the L<C<Config>|Config> module:
919011008
919111009=end original
919211010
9193あるいは C<Config> モジュールからプログラムで:
11011あるいは L<C<Config>|Config> モジュールからプログラムで:
919411012
919511013 use Config;
919611014 print $Config{shortsize}, "\n";
919711015 print $Config{intsize}, "\n";
919811016 print $Config{longsize}, "\n";
919911017 print $Config{longlongsize}, "\n";
920011018
920111019=begin original
920211020
9203C<$Config{longlongsize}> is undefined on systems without
11021C<$Config{longlongsize}> is undefined on systems without
920411022long long support.
920511023
920611024=end original
920711025
920811026システムが long long に対応していない場合は C<$Config{longlongsize}> は
920911027未定義値になります。
921011028
921111029=item *
921211030
921311031=begin original
921411032
921511033The integer formats C<s>, C<S>, C<i>, C<I>, C<l>, C<L>, C<j>, and C<J> are
921611034inherently non-portable between processors and operating systems because
921711035they obey native byteorder and endianness. For example, a 4-byte integer
9218110360x12345678 (305419896 decimal) would be ordered natively (arranged in and
921911037handled by the CPU registers) into bytes as
922011038
922111039=end original
922211040
922311041整数フォーマット C<s>, C<S>, C<i>, C<I>, C<l>, C<L>, C<j>, C<J> は
922411042ネイティブなバイト順序とエンディアンに従っているため、
922511043本質的にプロセッサ間や OS 間で移植性がありません。
922611044例えば 4 バイトの整数 0x12345678 (10 進数では 305419896) は
922711045内部では(CPU レジスタによって変換され扱われる形では)
922811046以下のようなバイト列に並べられます:
922911047
923011048 0x12 0x34 0x56 0x78 # big-endian
923111049 0x78 0x56 0x34 0x12 # little-endian
923211050
923311051=begin original
923411052
923511053Basically, Intel and VAX CPUs are little-endian, while everybody else,
923611054including Motorola m68k/88k, PPC, Sparc, HP PA, Power, and Cray, are
9237big-endian. Alpha and MIPS can be either: Digital/Compaq uses (well, used)
11055big-endian. Alpha and MIPS can be either: Digital/Compaq uses (well, used)
923811056them in little-endian mode, but SGI/Cray uses them in big-endian mode.
923911057
924011058=end original
924111059
9242基本的に、Intel と VAX の CPU はリトルエンディアンです
11060基本的に、Intel と VAX の CPU はリトルエンディアンです; 一方、
9243一方、Motorola m68k/88k, PPC, Sparc, HP PA, Power, Cray などを含む
11061Motorola m68k/88k, PPC, Sparc, HP PA, Power, Cray などを含むその他の全ては
9244その他の全てはビッグエンディアンです。
11062ビッグエンディアンです。
9245Alpha と MIPS は両方ともあります:
11063Alpha と MIPS は両方ともあります: Digital/Compaq はリトルエンディアンモードで
9246Digital/Compaq はリトルエンディアンモードで使っています (えーと、いました) が、
11064使っています (えーと、いました) が、SGI/Cray はビッグエンディアンモードで
9247SGI/Cray はビッグエンディアンモードで使っています。
11065使っています。
924811066
924911067=begin original
925011068
925111069The names I<big-endian> and I<little-endian> are comic references to the
925211070egg-eating habits of the little-endian Lilliputians and the big-endian
925311071Blefuscudians from the classic Jonathan Swift satire, I<Gulliver's Travels>.
925411072This entered computer lingo via the paper "On Holy Wars and a Plea for
925511073Peace" by Danny Cohen, USC/ISI IEN 137, April 1, 1980.
925611074
925711075=end original
925811076
9259I<ビッグエンディアン> と I<リトルエンディアン> の名前は
11077I<ビッグエンディアン> と I<リトルエンディアン> の名前は
9260古典である「ガリバー旅行記」とリリパット族の卵を食べる習慣から
11078ジョナサン=スウィフトによる風刺小説の古典 I<ガリバー旅行記> で卵を
11079小さい方からむくリリパット国と大きい方からむくブレフスキュ国から
926111080取られています。
926211081"On Holy Wars and a Plea for Peace" by Danny Cohen, USC/ISI IEN 137,
926311082April 1, 1980 の文書からコンピュータ用語として取り入れられました。
926411083
926511084=begin original
926611085
926711086Some systems may have even weirder byte orders such as
926811087
926911088=end original
927011089
927111090以下のような、さらに変わったバイト順序を持つシステムもあるかもしれません:
927211091
927311092 0x56 0x78 0x12 0x34
927411093 0x34 0x12 0x78 0x56
927511094
927611095=begin original
927711096
11097These are called mid-endian, middle-endian, mixed-endian, or just weird.
11098
11099=end original
11100
11101これらは mid-endian, middle-endian, mixed-endian あるいは単におかしなものと
11102呼ばれます。
11103
11104=begin original
11105
927811106You can determine your system endianness with this incantation:
927911107
928011108=end original
928111109
928211110システムの設定は以下のようにして調べられます:
928311111
9284 printf("%#02x ", $_) for unpack("W*", pack L=>0x12345678);
11112 printf("%#02x ", $_) for unpack("W*", pack L=>0x12345678);
928511113
928611114=begin original
928711115
928811116The byteorder on the platform where Perl was built is also available
928911117via L<Config>:
929011118
929111119=end original
929211120
929311121Perl がビルドされたプラットフォームでのバイト順序は
929411122L<Config> 経由か:
929511123
929611124 use Config;
929711125 print "$Config{byteorder}\n";
929811126
929911127=begin original
930011128
930111129or from the command line:
930211130
930311131=end original
930411132
930511133あるいはコマンドラインで:
930611134
930711135 $ perl -V:byteorder
930811136
930911137=begin original
931011138
931111139Byteorders C<"1234"> and C<"12345678"> are little-endian; C<"4321">
9312and C<"87654321"> are big-endian.
11140and C<"87654321"> are big-endian. Systems with multiarchitecture binaries
11141will have C<"ffff">, signifying that static information doesn't work,
11142one must use runtime probing.
931311143
931411144=end original
931511145
931611146C<"1234"> と C<"12345678"> はリトルエンディアンです;
931711147C<"4321"> と C<"87654321"> はビッグエンディアンです。
11148マルチアーキテクチャバイナリを持つシステムは
11149C<"ffff"> となります; これは静的な情報は動作せず、実行時調査を使う必要が
11150あることを示します。
931811151
931911152=begin original
932011153
9321For portably packed integers, either use the formats C<n>, C<N>, C<v>,
11154For portably packed integers, either use the formats C<n>, C<N>, C<v>,
932211155and C<V> or else use the C<< > >> and C<< < >> modifiers described
932311156immediately below. See also L<perlport>.
932411157
932511158=end original
932611159
932711160移植性のあるパック化された整数がほしい場合は、
932811161C<n>, C<N>, C<v>, C<V> フォーマットを使うか、
932911162直後で説明する C<< > >> と C<< < >> の修飾子が使えます。
9330L<perlport> も参照してさい。
11163L<perlport> も参照してください。
933111164
933211165=item *
933311166
933411167=begin original
933511168
9336Starting with Perl 5.9.2, integer and floating-point formats, along with
11169Also floating point numbers have endianness. Usually (but not always)
9337the C<p> and C<P> formats and C<()> groups, may all be followed by the
11170this agrees with the integer endianness. Even though most platforms
11171these days use the IEEE 754 binary format, there are differences,
11172especially if the long doubles are involved. You can see the
11173C<Config> variables C<doublekind> and C<longdblkind> (also C<doublesize>,
11174C<longdblsize>): the "kind" values are enums, unlike C<byteorder>.
11175
11176=end original
11177
11178また、浮動小数点数にもエンディアンがあります。
11179通常は(但し常にではありません)これは整数のエンディアンと同じです。
11180最近のほとんどのプラットフォームが IEEE 754 バイナリ形式を使っているにも
11181関わらず、(特に long double 関連で) 相違点があります。
11182C<Config> 変数 C<doublekind> と C<longdblkind> (および C<doublesize>,
11183C<longdblsize>) を参照できます: "kind" 値は C<byteorder> と異なり、
11184順序値です。
11185
11186=begin original
11187
11188Portability-wise the best option is probably to keep to the IEEE 754
1118964-bit doubles, and of agreed-upon endianness. Another possibility
11190is the C<"%a">) format of L<C<printf>|/printf FILEHANDLE FORMAT, LIST>.
11191
11192=end original
11193
11194移植性を考慮した最良の選択肢はおそらく、IEEE 754 64-bit double と同意した
11195エンディアンを維持することです。
11196もう一つの可能性は L<C<printf>|/printf FILEHANDLE FORMAT, LIST> の
11197C<"%a"> 型式です。
11198
11199=item *
11200
11201=begin original
11202
11203Starting with Perl 5.10.0, integer and floating-point formats, along with
11204the C<p> and C<P> formats and C<()> groups, may all be followed by the
933811205C<< > >> or C<< < >> endianness modifiers to respectively enforce big-
9339or little-endian byte-order. These modifiers are especially useful
11206or little-endian byte-order. These modifiers are especially useful
9340given how C<n>, C<N>, C<v>, and C<V> don't cover signed integers,
11207given how C<n>, C<N>, C<v>, and C<V> don't cover signed integers,
93411120864-bit integers, or floating-point values.
934211209
934311210=end original
934411211
9345Perl 5.9.2 から、C<p> と C<P> フォーマットや C<()> グループと同様、
11212Perl 5.10.0 から、C<p> と C<P> フォーマットや C<()> グループと同様、
934611213全ての整数と浮動小数点数のフォーマットは、C<< > >> や C<< < >> の
934711214エンディアン修飾子をつけることで、それぞれ
934811215ビッグエンディアンとリトルエンディアンに強制させることができます。
934911216C<n>, C<N>, C<v>, C<V> は符号付き整数、64 ビット整数、浮動小数点数に
935011217対応していないので、これは特に有用です。
935111218
935211219=begin original
935311220
935411221Here are some concerns to keep in mind when using an endianness modifier:
935511222
935611223=end original
935711224
935811225エンディアン修飾子を使うときに心に留めておくべきことを記します:
935911226
936011227=over
936111228
9362=item *
11229=item *
936311230
936411231=begin original
936511232
9366Exchanging signed integers between different platforms works only
11233Exchanging signed integers between different platforms works only
936711234when all platforms store them in the same format. Most platforms store
936811235signed integers in two's-complement notation, so usually this is not an issue.
936911236
937011237=end original
937111238
937211239異なったプラットフォームで符号付き整数を交換することは、全ての
937311240プラットフォームで同じフォーマットで保存されている場合にのみうまくいきます。
937411241ほとんどのプラットフォームでは符号付き整数は 2 の補数記法で保存するので、
937511242普通はこれは問題になりません。
937611243
9377=item *
11244=item *
937811245
937911246=begin original
938011247
938111248The C<< > >> or C<< < >> modifiers can only be used on floating-point
938211249formats on big- or little-endian machines. Otherwise, attempting to
938311250use them raises an exception.
938411251
938511252=end original
938611253
938711254C<< > >> や C<< < >> の修飾子はビッグエンディアンやリトルエンディアンの
938811255マシンでの浮動小数点フォーマットでのみ使えます。
938911256それ以外では、そのようなことをすると例外が発生します。
939011257
9391=item *
11258=item *
939211259
939311260=begin original
939411261
939511262Forcing big- or little-endian byte-order on floating-point values for
939611263data exchange can work only if all platforms use the same
939711264binary representation such as IEEE floating-point. Even if all
939811265platforms are using IEEE, there may still be subtle differences. Being able
939911266to use C<< > >> or C<< < >> on floating-point values can be useful,
940011267but also dangerous if you don't know exactly what you're doing.
940111268It is not a general way to portably store floating-point values.
940211269
940311270=end original
940411271
940511272データ交換のために浮動小数点数のバイト順をビッグエンディアンかリトル
940611273エンディアンに強制することは、全てのプラットフォームが
940711274IEEE 浮動小数点フォーマットのような同じバイナリ表現の場合にのみ
940811275うまくいきます。
940911276たとえ全てのプラットフォームが IEEE を使っていても、そこには微妙な違いが
941011277あるかもしれません。
9411浮動小数点数に C<< > >> や C<< < >> が使えることは便利な場合が
11278浮動小数点数に C<< > >> や C<< < >> が使えることは便利な場合がありますが、
9412ありますが、もし自分が何をしているかを正確に理解していなければ、
11279もし自分が何をしているかを正確に理解していなければ、危険です。
9413危険です。
941411280移植性のある浮動小数点数の保存のための一般的な方法はありません。
941511281
9416=item *
11282=item *
941711283
941811284=begin original
941911285
942011286When using C<< > >> or C<< < >> on a C<()> group, this affects
942111287all types inside the group that accept byte-order modifiers,
942211288including all subgroups. It is silently ignored for all other
942311289types. You are not allowed to override the byte-order within a group
942411290that already has a byte-order modifier suffix.
942511291
942611292=end original
942711293
942811294C<()> グループで C<< > >> や C<< < >> を使うと、これは、副グループを
942911295含む全ての型のうち、バイト順修飾子を受け入れる全てのものに影響与えます。
943011296その他の型については沈黙のうちに無視されます。
943111297既にバイト順接尾辞を持っているグループ内のバイト順を上書きすることは
943211298できません。
943311299
943411300=back
943511301
943611302=item *
943711303
943811304=begin original
943911305
944011306Real numbers (floats and doubles) are in native machine format only.
944111307Due to the multiplicity of floating-point formats and the lack of a
944211308standard "network" representation for them, no facility for interchange has been
944311309made. This means that packed floating-point data written on one machine
944411310may not be readable on another, even if both use IEEE floating-point
944511311arithmetic (because the endianness of the memory representation is not part
944611312of the IEEE spec). See also L<perlport>.
944711313
944811314=end original
944911315
945011316実数 (float と double) は、機種依存のフォーマットしかありません。
9451いろんな浮動小数点数のフォーマットが在り、標準的な
11317いろんな浮動小数点数のフォーマットが在り、標準的な "network" 表現といったものが
9452"network" 表現といったものがないため、データ交換のための機能は
11318ないため、データ交換のための機能は用意してありません。
9453用意してありません。
945411319つまり、あるマシンで pack した浮動小数点数は、別のマシンでは
9455読めないかもしれないということです
11320読めないかもしれないということです; たとえ双方で IEEE フォーマットの
9456たとえ双方で IEEE フォーマットの浮動小数点数演算を行なっていてもです
11321浮動小数点数演算を行なっていてもです (IEEE の仕様では、メモリ表現上の
9457(IEEE の仕様では、メモリ表現上のバイト順序までは、
11322バイト順序までは、規定されていないからです)。
9458規定されていないからです)。
945911323L<perlport> も参照してください。
946011324
946111325=begin original
946211326
946311327If you know I<exactly> what you're doing, you can use the C<< > >> or C<< < >>
946411328modifiers to force big- or little-endian byte-order on floating-point values.
946511329
946611330=end original
946711331
946811332もし何をしようとしているのかを I<正確に> 理解しているなら、浮動小数点数の
946911333バイト順をビッグエンディアンやリトルエンディアンに強制するために、
947011334C<< > >> と C<< < >> の修飾子が使えます。
947111335
947211336=begin original
947311337
947411338Because Perl uses doubles (or long doubles, if configured) internally for
9475all numeric calculation, converting from double into float and thence
11339all numeric calculation, converting from double into float and thence
947611340to double again loses precision, so C<unpack("f", pack("f", $foo)>)
947711341will not in general equal $foo.
947811342
947911343=end original
948011344
9481Perl では、すべての数値演算のために、内部的に double (または
11345Perl では、すべての数値演算のために、内部的に double (または設定によっては
9482設定によっては long double) を使用しているので、
11346long double) を使用しているので、double から float へ変換し、それから再び
9483double から float へ変換し、それから再び double に戻すと
11347double に戻すと精度が落ちることになり、C<unpack("f", pack("f", $foo)>) は、
9484精度が落ちることになり、C<unpack("f", pack("f", $foo)>) は、
948511348一般には $foo と同じではありません。
948611349
948711350=item *
948811351
948911352=begin original
949011353
949111354Pack and unpack can operate in two modes: character mode (C<C0> mode) where
9492the packed string is processed per character, and UTF-8 mode (C<U0> mode)
11355the packed string is processed per character, and UTF-8 byte mode (C<U0> mode)
949311356where the packed string is processed in its UTF-8-encoded Unicode form on
9494a byte-by-byte basis. Character mode is the default unless the format string
11357a byte-by-byte basis. Character mode is the default
9495starts with C<U>. You can always switch mode mid-format with an explicit
11358unless the format string starts with C<U>. You
9496C<C0> or C<U0> in the format. This mode remains in effect until the next
11359can always switch mode mid-format with an explicit
11360C<C0> or C<U0> in the format. This mode remains in effect until the next
949711361mode change, or until the end of the C<()> group it (directly) applies to.
949811362
949911363=end original
950011364
950111365pack と unpack は二つのモードで操作します: pack された文字列を文字単位で
950211366処理する文字モード (C<C0> モード) と、pack された文字列を、バイト毎に、
950311367その UTF-8 エンコードされた形式で処理するUTF-8 モード (C<U0> モード) です。
950411368文字モードはフォーマット文字列が C<U> で始まっていない限りはデフォルトです。
950511369モードはフォーマット中に明示的に C<C0> または C<U0> と書くことでいつでも
950611370切り替えられます。
9507モードは次のモードに切り替えられるか、(直接)適用された () グループが
11371モードは次のモードに切り替えられるか、(直接)適用された C<()> グループが
950811372終了するまで有効です。
950911373
951011374=begin original
951111375
9512Using C<C0> to get Unicode characters while using C<U0> to get I<non>-Unicode
11376Using C<C0> to get Unicode characters while using C<U0> to get I<non>-Unicode
951311377bytes is not necessarily obvious. Probably only the first of these
951411378is what you want:
951511379
951611380=end original
951711381
951811382Unicode 文字を取得するのに C<C0> を使い、I<非> Unicode バイトを取得するのに
951911383C<U0> を使うというのは必ずしも明白ではありません。
952011384おそらく、これらのうち最初のものだけが望みのものでしょう:
952111385
9522 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
11386 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
952311387 perl -CS -ne 'printf "%v04X\n", $_ for unpack("C0A*", $_)'
952411388 03B1.03C9
9525 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
11389 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
952611390 perl -CS -ne 'printf "%v02X\n", $_ for unpack("U0A*", $_)'
952711391 CE.B1.CF.89
9528 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
11392 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
952911393 perl -C0 -ne 'printf "%v02X\n", $_ for unpack("C0A*", $_)'
953011394 CE.B1.CF.89
9531 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
11395 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
953211396 perl -C0 -ne 'printf "%v02X\n", $_ for unpack("U0A*", $_)'
953311397 C3.8E.C2.B1.C3.8F.C2.89
953411398
953511399=begin original
953611400
953711401Those examples also illustrate that you should not try to use
9538C<pack>/C<unpack> as a substitute for the L<Encode> module.
11402L<C<pack>|/pack TEMPLATE,LIST>/L<C<unpack>|/unpack TEMPLATE,EXPR> as a
11403substitute for the L<Encode> module.
953911404
954011405=end original
954111406
9542これらの例は、C<pack>/C<unpack> L<Encode> モジュールの代わりとして
11407これらの例は、L<C<pack>|/pack TEMPLATE,LIST>/
11408L<C<unpack>|/unpack TEMPLATE,EXPR> を L<Encode> モジュールの代わりとして
954311409使おうとするべきではないということも示しています。
954411410
954511411=item *
954611412
954711413=begin original
954811414
954911415You must yourself do any alignment or padding by inserting, for example,
9550enough C<"x">es while packing. There is no way for pack() and unpack()
11416enough C<"x">es while packing. There is no way for
9551to know where characters are going to or coming from, so they
11417L<C<pack>|/pack TEMPLATE,LIST> and L<C<unpack>|/unpack TEMPLATE,EXPR>
11418to know where characters are going to or coming from, so they
955211419handle their output and input as flat sequences of characters.
955311420
955411421=end original
955511422
955611423pack するときに、例えば十分な数の C<"x"> を挿入することによって
955711424アライメントやパッディングを行うのは全て自分でしなければなりません。
9558文字列がどこへ行くかやどこから来たかを pack() や unpack()
11425L<C<pack>|/pack TEMPLATE,LIST> L<C<unpack>|/unpack TEMPLATE,EXPR> は、
9559知る方法はないので、C<pack> (と C<unpack>) は出力と入力フラットな
11426文字列がどこへ行くかやどこから来たか
9560文字列として扱います。
11427知る方法はないので、出力と入力をフラットな文字列として扱います。
956111428
956211429=item *
956311430
956411431=begin original
956511432
956611433A C<()> group is a sub-TEMPLATE enclosed in parentheses. A group may
9567take a repeat count either as postfix, or for unpack(), also via the C</>
11434take a repeat count either as postfix, or for
11435L<C<unpack>|/unpack TEMPLATE,EXPR>, also via the C</>
956811436template character. Within each repetition of a group, positioning with
9569C<@> starts over at 0. Therefore, the result of
11437C<@> starts over at 0. Therefore, the result of
957011438
957111439=end original
957211440
957311441C<()> のグループはかっこで囲われた副テンプレートです。
9574グループは繰り返し数を取ることができます; 接尾辞によるか、unpack() の場合は
11442グループは繰り返し数を取ることができます; 接尾辞によるか、
9575C</> テンプレート文字によります。
11443L<C<unpack>|/unpack TEMPLATE,EXPR> の場合は C</> テンプレート文字によります。
957611444グループの繰り返し毎に、C<@> の位置は 0 になります。
957711445従って、以下の結果は:
957811446
957911447 pack("@1A((@2A)@3A)", qw[X Y Z])
958011448
958111449=begin original
958211450
958311451is the string C<"\0X\0\0YZ">.
958411452
958511453=end original
958611454
958711455文字列 C<"\0X\0\0YZ"> です。
958811456
958911457=item *
959011458
959111459=begin original
959211460
959311461C<x> and C<X> accept the C<!> modifier to act as alignment commands: they
959411462jump forward or back to the closest position aligned at a multiple of C<count>
9595characters. For example, to pack() or unpack() a C structure like
11463characters. For example, to L<C<pack>|/pack TEMPLATE,LIST> or
11464L<C<unpack>|/unpack TEMPLATE,EXPR> a C structure like
959611465
959711466=end original
959811467
959911468C<x> と C<X> にはアライメントコマンドとして C<!> 修飾子を付けることができます:
960011469これは C<count> 文字の倍数のアライメントとなる、もっとも近い位置に移動します。
9601例えば、以下のような構造体を pack() または unpack() するめに
11470例えば、以下のような C 構造体を L<C<pack>|/pack TEMPLATE,LIST> または
11471L<C<unpack>|/unpack TEMPLATE,EXPR> するには
960211472
960311473 struct {
960411474 char c; /* one signed, 8-bit character */
9605 double d;
11475 double d;
960611476 char cc[2];
960711477 }
960811478
960911479=begin original
961011480
961111481one may need to use the template C<c x![d] d c[2]>. This assumes that
961211482doubles must be aligned to the size of double.
961311483
961411484=end original
961511485
961611486C<W x![d] d W[2]> というテンプレートを使う必要があるかもしれません。
961711487これは double が double のサイズでアライメントされていることを
961811488仮定しています。
961911489
962011490=begin original
962111491
962211492For alignment commands, a C<count> of 0 is equivalent to a C<count> of 1;
962311493both are no-ops.
962411494
962511495=end original
962611496
9627アライメントコマンドに対しては、C<count> に 0 を指定するのは 1 を
11497アライメントコマンドに対しては、C<count> に 0 を指定するのは
9628指定するのと等価です; どちらも何もしません。
11498C<count> に 1 を指定するのと等価です; どちらも何もしません。
962911499
963011500=item *
963111501
963211502=begin original
963311503
963411504C<n>, C<N>, C<v> and C<V> accept the C<!> modifier to
963511505represent signed 16-/32-bit integers in big-/little-endian order.
963611506This is portable only when all platforms sharing packed data use the
963711507same binary representation for signed integers; for example, when all
963811508platforms use two's-complement representation.
963911509
964011510=end original
964111511
9642C<n>, C<N>, C<v>, C<V> は
11512C<n>, C<N>, C<v>, C<V> はビッグ/リトルエンディアンの順序で符号付き 16 または
9643ビッグ/リトルエンディアンの順序で符号付き 16 または
96441151332 ビット整数で表現するための C<!> 修飾子を受け入れます。
964511514これは pack されたデータを共有する全てのプラットフォームが
964611515符号付き整数について同じバイナリ表現を使う場合にのみ移植性があります;
964711516例えば、全てのプラットフォームで 2 の補数表現を使う場合です。
964811517
964911518=item *
965011519
965111520=begin original
965211521
965311522Comments can be embedded in a TEMPLATE using C<#> through the end of line.
965411523White space can separate pack codes from each other, but modifiers and
965511524repeat counts must follow immediately. Breaking complex templates into
965611525individual line-by-line components, suitably annotated, can do as much to
965711526improve legibility and maintainability of pack/unpack formats as C</x> can
965811527for complicated pattern matches.
965911528
966011529=end original
966111530
966211531TEMPLATE の中の C<#> から行末まではコメントです。
966311532空白は pack コードをそれぞれ分けるために使えますが、修飾子と
966411533繰り返し数は直後に置かなければなりません。
966511534複雑なテンプレートを個々の行単位の要素に分解して適切に注釈をつけると、
966611535複雑なパターンマッチングに対する C</x> と同じぐらい、pack/unpack
966711536フォーマットの読みやすさと保守性が向上します。
966811537
966911538=item *
967011539
967111540=begin original
967211541
9673If TEMPLATE requires more arguments than pack() is given, pack()
11542If TEMPLATE requires more arguments than L<C<pack>|/pack TEMPLATE,LIST>
11543is given, L<C<pack>|/pack TEMPLATE,LIST>
967411544assumes additional C<""> arguments. If TEMPLATE requires fewer arguments
967511545than given, extra arguments are ignored.
967611546
967711547=end original
967811548
9679TEMPLATE が要求する引数の数が pack() が実際に与えている数より多い場合、
11549TEMPLATE が要求する引数の数が L<C<pack>|/pack TEMPLATE,LIST> が実際に
9680pack() は追加の C<""> 引数があものと仮定します。
11550与えてい数より多い場合、
11551L<C<pack>|/pack TEMPLATE,LIST> は追加の C<""> 引数があるものと仮定します。
968111552TEMPLATE が要求する引数の数の方が少ない場合、余分の引数は無視されます。
968211553
11554=item *
11555
11556=begin original
11557
11558Attempting to pack the special floating point values C<Inf> and C<NaN>
11559(infinity, also in negative, and not-a-number) into packed integer values
11560(like C<"L">) is a fatal error. The reason for this is that there simply
11561isn't any sensible mapping for these special values into integers.
11562
11563=end original
11564
11565特殊浮動小数点値 C<Inf> と C<NaN>
11566((負を含む)無限と非数) を (C<"L"> のような) 整数値に pack しようとすると
11567致命的エラーとなります。
11568この理由は、単に特殊値を整数に割り当てられないからです。
11569
968311570=back
968411571
968511572=begin original
968611573
968711574Examples:
968811575
968911576=end original
969011577
969111578例:
969211579
969311580 $foo = pack("WWWW",65,66,67,68);
969411581 # foo eq "ABCD"
969511582 $foo = pack("W4",65,66,67,68);
969611583 # same thing
969711584 $foo = pack("W4",0x24b6,0x24b7,0x24b8,0x24b9);
969811585 # same thing with Unicode circled letters.
969911586 $foo = pack("U4",0x24b6,0x24b7,0x24b8,0x24b9);
9700 # same thing with Unicode circled letters. You don't get the UTF-8
11587 # same thing with Unicode circled letters. You don't get the
9701 # bytes because the U at the start of the format caused a switch to
11588 # UTF-8 bytes because the U at the start of the format caused
9702 # U0-mode, so the UTF-8 bytes get joined into characters
11589 # a switch to U0-mode, so the UTF-8 bytes get joined into
11590 # characters
970311591 $foo = pack("C0U4",0x24b6,0x24b7,0x24b8,0x24b9);
970411592 # foo eq "\xe2\x92\xb6\xe2\x92\xb7\xe2\x92\xb8\xe2\x92\xb9"
9705 # This is the UTF-8 encoding of the string in the previous example
11593 # This is the UTF-8 encoding of the string in the
11594 # previous example
970611595
970711596 $foo = pack("ccxxcc",65,66,67,68);
970811597 # foo eq "AB\0\0CD"
970911598
971011599 # NOTE: The examples above featuring "W" and "c" are true
971111600 # only on ASCII and ASCII-derived systems such as ISO Latin 1
971211601 # and UTF-8. On EBCDIC systems, the first example would be
971311602 # $foo = pack("WWWW",193,194,195,196);
971411603
971511604 $foo = pack("s2",1,2);
971611605 # "\001\000\002\000" on little-endian
971711606 # "\000\001\000\002" on big-endian
971811607
971911608 $foo = pack("a4","abcd","x","y","z");
972011609 # "abcd"
972111610
972211611 $foo = pack("aaaa","abcd","x","y","z");
972311612 # "axyz"
972411613
972511614 $foo = pack("a14","abcdefg");
972611615 # "abcdefg\0\0\0\0\0\0\0"
972711616
972811617 $foo = pack("i9pl", gmtime);
972911618 # a real struct tm (on my system anyway)
973011619
973111620 $utmp_template = "Z8 Z8 Z16 L";
973211621 $utmp = pack($utmp_template, @utmp1);
973311622 # a struct utmp (BSDish)
973411623
973511624 @utmp2 = unpack($utmp_template, $utmp);
973611625 # "@utmp1" eq "@utmp2"
973711626
973811627 sub bintodec {
973911628 unpack("N", pack("B32", substr("0" x 32 . shift, -32)));
974011629 }
974111630
974211631 $foo = pack('sx2l', 12, 34);
974311632 # short 12, two zero bytes padding, long 34
974411633 $bar = pack('s@4l', 12, 34);
974511634 # short 12, zero fill to position 4, long 34
974611635 # $foo eq $bar
974711636 $baz = pack('s.l', 12, 4, 34);
974811637 # short 12, zero fill to position 4, long 34
974911638
975011639 $foo = pack('nN', 42, 4711);
975111640 # pack big-endian 16- and 32-bit unsigned integers
975211641 $foo = pack('S>L>', 42, 4711);
975311642 # exactly the same
975411643 $foo = pack('s<l<', -42, 4711);
975511644 # pack little-endian 16- and 32-bit signed integers
975611645 $foo = pack('(sl)<', -42, 4711);
975711646 # exactly the same
975811647
975911648=begin original
976011649
9761The same template may generally also be used in unpack().
11650The same template may generally also be used in
11651L<C<unpack>|/unpack TEMPLATE,EXPR>.
976211652
976311653=end original
976411654
9765一般には、pack で使用したものと同じテンプレートが
11655一般には、同じテンプレートが L<C<unpack>|/unpack TEMPLATE,EXPR> でも
9766unpack() 関数でも使用できます。
11656使用できます。
976711657
976811658=item package NAMESPACE
976911659
977011660=item package NAMESPACE VERSION
977111661X<package> X<module> X<namespace> X<version>
977211662
977311663=item package NAMESPACE BLOCK
977411664
977511665=item package NAMESPACE VERSION BLOCK
977611666X<package> X<module> X<namespace> X<version>
977711667
11668=for Pod::Functions declare a separate global namespace
11669
977811670=begin original
977911671
978011672Declares the BLOCK or the rest of the compilation unit as being in the
978111673given namespace. The scope of the package declaration is either the
978211674supplied code BLOCK or, in the absence of a BLOCK, from the declaration
978311675itself through the end of current scope (the enclosing block, file, or
9784C<eval>). That is, the forms without a BLOCK are operative through the end
11676L<C<eval>|/eval EXPR>). That is, the forms without a BLOCK are
9785of the current scope, just like the C<my>, C<state>, and C<our> operators.
11677operative through the end of the current scope, just like the
9786All unqualified dynamic identifiers in this scope will be in the given
11678L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>, and
9787namespace, except where overridden by another C<package> declaration or
11679L<C<our>|/our VARLIST> operators. All unqualified dynamic identifiers
11680in this scope will be in the given namespace, except where overridden by
11681another L<C<package>|/package NAMESPACE> declaration or
978811682when they're one of the special identifiers that qualify into C<main::>,
978911683like C<STDOUT>, C<ARGV>, C<ENV>, and the punctuation variables.
979011684
979111685=end original
979211686
979311687BLOCK や残りのコンパイル単位を与えられた名前空間として宣言します。
979411688パッケージ宣言のスコープは BLOCK か、BLOCK がないばあいは宣言自身から
9795現在のスコープの末尾 (閉じたブロック、ファイル、C<eval>) です。
11689現在のスコープの末尾 (閉じたブロック、ファイル、L<C<eval>|/eval EXPR>) です。
9796つまり、BLOCK なしの形式は、C<my>, C<state>, C<our> 演算子と同様に
11690つまり、BLOCK なしの形式は、L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>,
9797現在のスコープの末尾にまで作用します。
11691L<C<our>|/our VARLIST> 演算子と同様に現在のスコープの末尾にまで作用します。
979811692このスコープ内の、全ての完全修飾されていない動的識別子は、他の
9799C<package> 宣言によって上書きされるか、
11693L<C<package>|/package NAMESPACE> 宣言によって上書きされるか、
980011694C<STDOUT>, C<ARGV>, C<ENV> や句読点変数のように C<main::> に
980111695割り当てられる特殊変数でない限り、指定された
980211696名前空間になります。
980311697
980411698=begin original
980511699
980611700A package statement affects dynamic variables only, including those
9807you've used C<local> on, but I<not> lexical variables, which are created
11701you've used L<C<local>|/local EXPR> on, but I<not> lexically-scoped
9808with C<my>, C<state>, or C<our>. Typically it would be the first
11702variables, which are created with L<C<my>|/my VARLIST>,
9809declaration in a file included by C<require> or C<use>. You can switch into a
11703L<C<state>|/state VARLIST>, or L<C<our>|/our VARLIST>. Typically it
9810package in more than one place, since this only determines which default
11704would be the first declaration in a file included by
11705L<C<require>|/require VERSION> or L<C<use>|/use Module VERSION LIST>.
11706You can switch into a
11707package in more than one place, since this only determines which default
981111708symbol table the compiler uses for the rest of that block. You can refer to
981211709identifiers in other packages than the current one by prefixing the identifier
981311710with the package name and a double colon, as in C<$SomePack::var>
981411711or C<ThatPack::INPUT_HANDLE>. If package name is omitted, the C<main>
981511712package as assumed. That is, C<$::sail> is equivalent to
981611713C<$main::sail> (as well as to C<$main'sail>, still seen in ancient
981711714code, mostly from Perl 4).
981811715
981911716=end original
982011717
9821package 文は動的変数にのみ影響します(C<local> で使ったものも
11718package 文は動的変数にのみ影響します(L<C<local>|/local EXPR> で使ったものも
9822含みます)が、C<my>, C<state>, C<our> のいずれかで作成された
11719含みます)が、L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>,
9823レキシカル変数には I<影響しません>
11720L<C<our>|/our VARLIST> のいずれかで作成された
9824典型的にはこれは C<require> や C<use> 演算子でインクルードされるファイルの
11721レキシカルなスコープの変数には I<影響しません>
11722典型的にはこれは L<C<require>|/require VERSION> や
11723L<C<use>|/use Module VERSION LIST> 演算子でインクルードされるファイルの
982511724最初に宣言されます。
982611725パッケージを複数の場所で切り替えることができます;
982711726なぜならこれは単にコンパイラがこのブロックの残りに対してどの
982811727シンボルテーブルを使うかにのみ影響するからです。
982911728他のパッケージの識別子は、C<$SomePack::var> や
983011729C<ThatPack::INPUT_HANDLE> のように、識別子にパッケージ名と
983111730コロン二つをつけることで参照できます。
983211731パッケージ名が省略された場合、C<main> パッケージが仮定されます。
983311732つまり、C<$::sail> は C<$main::sail> と等価です(ほとんどは Perl 4 からの、
983411733古いコードでは C<$main'sail> もまだ見られます)。
983511734
983611735=begin original
983711736
9838If VERSION is provided, C<package> sets the C<$VERSION> variable in the given
11737If VERSION is provided, L<C<package>|/package NAMESPACE> sets the
11738C<$VERSION> variable in the given
983911739namespace to a L<version> object with the VERSION provided. VERSION must be a
984011740"strict" style version number as defined by the L<version> module: a positive
984111741decimal number (integer or decimal-fraction) without exponentiation or else a
984211742dotted-decimal v-string with a leading 'v' character and at least three
984311743components. You should set C<$VERSION> only once per package.
984411744
984511745=end original
984611746
9847VERSION が指定されると、C<package> は与えられた名前空間の C<$VERSION> 変数に、
11747VERSION が指定されると、L<C<package>|/package NAMESPACE> は与えられた
11748名前空間の C<$VERSION> 変数に、
984811749指定された VERSION の L<version> オブジェクトをセットします。
984911750VERSION は L<version> で定義されている「厳密な」形式のバージョン番号で
985011751なければなりません: 指数のない正の 10 進数 (整数か 10 進小数) か、
985111752さもなければ先頭に 'v' の文字が付いて、少なくとも三つの部分から
985211753構成されるドット付き 10 進v-文字列です。
985311754C<$VERSION> はパッケージ毎に 1 回だけセットするべきです。
985411755
985511756=begin original
985611757
985711758See L<perlmod/"Packages"> for more information about packages, modules,
985811759and classes. See L<perlsub> for other scoping issues.
985911760
986011761=end original
986111762
986211763パッケージ、モジュール、クラスに関するさらなる情報については
986311764L<perlmod/"Packages"> を参照してください。
986411765その他のスコープに関する話題については L<perlsub> を参照してください。
986511766
11767=item __PACKAGE__
11768X<__PACKAGE__>
11769
11770=for Pod::Functions +5.004 the current package
11771
11772=begin original
11773
11774A special token that returns the name of the package in which it occurs.
11775
11776=end original
11777
11778これが書いてあるパッケージの名前を返す特殊トークン。
11779
986611780=item pipe READHANDLE,WRITEHANDLE
986711781X<pipe>
986811782
11783=for Pod::Functions open a pair of connected filehandles
11784
986911785=begin original
987011786
987111787Opens a pair of connected pipes like the corresponding system call.
987211788Note that if you set up a loop of piped processes, deadlock can occur
987311789unless you are very careful. In addition, note that Perl's pipes use
9874IO buffering, so you may need to set C<$|> to flush your WRITEHANDLE
11790IO buffering, so you may need to set L<C<$E<verbar>>|perlvar/$E<verbar>>
9875after each command, depending on the application.
11791to flush your WRITEHANDLE after each command, depending on the
11792application.
987611793
987711794=end original
987811795
9879対応するシステムコールと同じように、
11796対応するシステムコールと同じように、接続されたパイプのペアを開きます。
9880接続されたパイプのペアをオープンします。
988111797パイプでプロセスをループにするときには、よほど気を付けないと、
988211798デッドロックが起こり得ます。
9883さらに、Perl のパイプでは、IO のバッファリングを使いますから
11799さらに、Perl のパイプでは、IO のバッファリングを使ので
988411800アプリケーションによっては、コマンドごとに WRITEHANDLE を
9885フラッシュするように、C<$|> を設定することが必要になるかもしれません。
11801フラッシュするように、L<C<$E<verbar>>|perlvar/$E<verbar>> を設定することが
11802必要になるかもしれません。
988611803
988711804=begin original
988811805
11806Returns true on success.
11807
11808=end original
11809
11810成功時には真を返します。
11811
11812=begin original
11813
988911814See L<IPC::Open2>, L<IPC::Open3>, and
989011815L<perlipc/"Bidirectional Communication with Another Process">
989111816for examples of such things.
989211817
989311818=end original
989411819
989511820これらに関する例については、L<IPC::Open2>, L<IPC::Open3>,
989611821L<perlipc/"Bidirectional Communication with Another Process"> を
9897参照してさい。
11822参照してください。
989811823
989911824=begin original
990011825
990111826On systems that support a close-on-exec flag on files, that flag is set
9902on all newly opened file descriptors whose C<fileno>s are I<higher> than
11827on all newly opened file descriptors whose
9903the current value of $^F (by default 2 for C<STDERR>). See L<perlvar/$^F>.
11828L<C<fileno>|/fileno FILEHANDLE>s are I<higher> than the current value of
11829L<C<$^F>|perlvar/$^F> (by default 2 for C<STDERR>). See L<perlvar/$^F>.
990411830
990511831=end original
990611832
990711833ファイルに対する close-on-exec フラグをサポートしているシステムでは、
990811834新しくオープンされたファイル記述子のうち、
9909C<fileno> が現在の $^F の値(デフォルトでは C<STDERR> の 2)
11835L<C<fileno>|/fileno FILEHANDLE> が現在の L<C<$^F>|perlvar/$^F>
11836(デフォルトでは C<STDERR> の 2)
991011837I<よりも大きい> ものに対してフラグがセットされます。
991111838L<perlvar/$^F> を参照してください。
991211839
991311840=item pop ARRAY
991411841X<pop> X<stack>
991511842
9916=item pop EXPR
9917
991811843=item pop
991911844
11845=for Pod::Functions remove the last element from an array and return it
11846
992011847=begin original
992111848
992211849Pops and returns the last value of the array, shortening the array by
992311850one element.
992411851
992511852=end original
992611853
992711854配列の最後の値をポップして返し、配列の大きさを 1 だけ小さくします。
992811855
992911856=begin original
993011857
9931Returns the undefined value if the array is empty, although this may also
11858Returns the undefined value if the array is empty, although this may
9932happen at other times. If ARRAY is omitted, pops the C<@ARGV> array in the
11859also happen at other times. If ARRAY is omitted, pops the
9933main program, but the C<@_> array in subroutines, just like C<shift>.
11860L<C<@ARGV>|perlvar/@ARGV> array in the main program, but the
11861L<C<@_>|perlvar/@_> array in subroutines, just like
11862L<C<shift>|/shift ARRAY>.
993411863
993511864=end original
993611865
993711866指定された配列に要素がなければ未定義値が返されますが、
993811867しかしこれは他の場合にも起こり得ます。
9939ARRAY が省略されると、C<shift> と同様に、メインプログラムでは C<@ARGV> が
11868ARRAY が省略されると、L<C<shift>|/shift ARRAY> と同様に、メインプログラムでは
9940使われますが、サブルーチンでは C<@_> が使われます
11869L<C<@ARGV>|perlvar/@ARGV> が使われますが、
11870サブルーチンでは L<C<@_>|perlvar/@_> が使われます。
994111871
994211872=begin original
994311873
9944Starting with Perl 5.14, C<pop> can take a scalar EXPR, which must hold a
11874Starting with Perl 5.14, an experimental feature allowed
9945reference to an unblessed array. The argument will be dereferenced
11875L<C<pop>|/pop ARRAY> to take a
9946automatically. This aspect of C<pop> is considered highly experimental.
11876scalar expression. This experiment has been deemed unsuccessful, and was
9947The exact behaviour may change in a future version of Perl.
11877removed as of Perl 5.24.
994811878
994911879=end original
995011880
9951Perl 5.14 から、C<pop> スカラの EXPR を取ることができになりました;
11881Perl 5.14 から、L<C<pop>|/pop ARRAY> がスカラを取ることが出来とい
9952これは bless されていない配列へのリファレンスでなければなりません
11882実験的機能がありました
9953引数自動的にデリファレンスされま
11883この実験失敗と見なされ、Perl 5.24 で削除されした
9954C<pop> のこの動作は高度に実験的であると考えられています。
9955正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
995611884
995711885=item pos SCALAR
995811886X<pos> X<match, position>
995911887
996011888=item pos
996111889
11890=for Pod::Functions find or set the offset for the last/next m//g search
11891
996211892=begin original
996311893
996411894Returns the offset of where the last C<m//g> search left off for the
9965variable in question (C<$_> is used when the variable is not
11895variable in question (L<C<$_>|perlvar/$_> is used when the variable is not
9966specified). Note that 0 is a valid match offset. C<undef> indicates
11896specified). Note that 0 is a valid match offset.
11897L<C<undef>|/undef EXPR> indicates
996711898that the search position is reset (usually due to match failure, but
996811899can also be because no match has yet been run on the scalar).
996911900
997011901=end original
997111902
997211903対象の変数に対して、前回の C<m//g> が終了した場所の
9973オフセットを返します(変数が指定されなかった場合は C<$_> が使われます)。
11904オフセットを返します(変数が指定されなかった場合は L<C<$_>|perlvar/$_>
11905使われます)。
9974119060 は有効なマッチオフセットであることに注意してください。
9975C<undef> は検索位置がリセットされることを意味します (通常はマッチ失敗が
11907L<C<undef>|/undef EXPR> は検索位置がリセットされることを意味します (通常は
9976原因ですが、このスカラ値にまだマッチングが行われていないためかもしれません)。
11908マッチ失敗が原因ですが、このスカラ値にまだマッチングが
11909行われていないためかもしれません)。
997711910
997811911=begin original
997911912
9980C<pos> directly accesses the location used by the regexp engine to
11913L<C<pos>|/pos SCALAR> directly accesses the location used by the regexp
9981store the offset, so assigning to C<pos> will change that offset, and
11914engine to store the offset, so assigning to L<C<pos>|/pos SCALAR> will
9982so will also influence the C<\G> zero-width assertion in regular
11915change that offset, and so will also influence the C<\G> zero-width
9983expressions. Both of these effects take place for the next match, so
11916assertion in regular expressions. Both of these effects take place for
9984you can't affect the position with C<pos> during the current match,
11917the next match, so you can't affect the position with
9985such as in C<(?{pos() = 5})> or C<s//pos() = 5/e>.
11918L<C<pos>|/pos SCALAR> during the current match, such as in
11919C<(?{pos() = 5})> or C<s//pos() = 5/e>.
998611920
998711921=end original
998811922
9989C<pos> は正規表現エンジンがオフセットを保存するために使う場所を直接
11923L<C<pos>|/pos SCALAR> は正規表現エンジンがオフセットを保存するために使う場所を
9990アクセスするので、C<pos> への代入はオフセットを変更し、そのような変更は
11924直接アクセスするので、L<C<pos>|/pos SCALAR> への代入はオフセットを変更し、
9991正規表現における C<\G> ゼロ幅アサートにも影響を与えます。
11925そのような変更は正規表現における C<\G> ゼロ幅アサートにも影響を与えます。
999211926これらの効果の両方は次のマッチングのために行われるので、
999311927C<(?{pos() = 5})> や C<s//pos() = 5/e> のように現在のマッチング中の
9994C<pos> の位置には影響を与えません。
11928L<C<pos>|/pos SCALAR> の位置には影響を与えません。
999511929
999611930=begin original
999711931
9998Setting C<pos> also resets the I<matched with zero-length> flag, described
11932Setting L<C<pos>|/pos SCALAR> also resets the I<matched with
11933zero-length> flag, described
999911934under L<perlre/"Repeated Patterns Matching a Zero-length Substring">.
1000011935
1000111936=end original
1000211937
10003C<pos> を設定すると、
11938L<C<pos>|/pos SCALAR> を設定すると、
1000411939L<perlre/"Repeated Patterns Matching a Zero-length Substring"> に
1000511940記述されている、I<長さ 0 でマッチング> フラグもリセットされます。
1000611941
1000711942=begin original
1000811943
1000911944Because a failed C<m//gc> match doesn't reset the offset, the return
10010from C<pos> won't change either in this case. See L<perlre> and
11945from L<C<pos>|/pos SCALAR> won't change either in this case. See
10011L<perlop>.
11946L<perlre> and L<perlop>.
1001211947
1001311948=end original
1001411949
1001511950C<m//gc> マッチに失敗してもオフセットはリセットしないので、
10016C<pos> からの返り値はどちらの場合も変更されません。
11951L<C<pos>|/pos SCALAR> からの返り値はどちらの場合も変更されません。
1001711952L<perlre> と L<perlop> を参照してください。
1001811953
1001911954=item print FILEHANDLE LIST
1002011955X<print>
1002111956
1002211957=item print FILEHANDLE
1002311958
1002411959=item print LIST
1002511960
1002611961=item print
1002711962
11963=for Pod::Functions output a list to a filehandle
11964
1002811965=begin original
1002911966
1003011967Prints a string or a list of strings. Returns true if successful.
1003111968FILEHANDLE may be a scalar variable containing the name of or a reference
1003211969to the filehandle, thus introducing one level of indirection. (NOTE: If
1003311970FILEHANDLE is a variable and the next token is a term, it may be
1003411971misinterpreted as an operator unless you interpose a C<+> or put
10035parentheses around the arguments.) If FILEHANDLE is omitted, prints to the
11972parentheses around the arguments.) If FILEHANDLE is omitted, prints to the
10036last selected (see L</select>) output handle. If LIST is omitted, prints
11973last selected (see L<C<select>|/select FILEHANDLE>) output handle. If
10037C<$_> to the currently selected output handle. To use FILEHANDLE alone to
11974LIST is omitted, prints L<C<$_>|perlvar/$_> to the currently selected
10038print the content of C<$_> to it, you must use a real filehandle like
11975output handle. To use FILEHANDLE alone to print the content of
11976L<C<$_>|perlvar/$_> to it, you must use a bareword filehandle like
1003911977C<FH>, not an indirect one like C<$fh>. To set the default output handle
1004011978to something other than STDOUT, use the select operation.
1004111979
1004211980=end original
1004311981
1004411982文字列か文字列のリストを出力します。
10045成功時には真を返します。FILEHANDLE は、
11983成功時には真を返します。
10046ファイルハンドル名またはそのリファレンスが
11984FILEHANDLE は、ファイルハンドル名またはそのリファレンスが
1004711985入っているスカラ変数名でもよいので、一段階の間接指定が行なえます。
1004811986(注: FILEHANDLE に変数を使い、次のトークンが「項」のときには、
1004911987間に C<+> を置くか、引数の前後を括弧で括らなければ、
1005011988誤って解釈されることがあります。)
10051FILEHANDLE を省略した場合には、最後に選択された (L</select> 参照) 出力
11989FILEHANDLE を省略した場合には、最後に選択された
10052チャネルに出力します。
11990(L<C<select>|/select FILEHANDLE> 参照) 出力チャネルに出力します。
10053LIST を省略すると、C<$_> が現在選択されている出力ハンドルに出力されます。
11991LIST を省略すると、L<C<$_>|perlvar/$_> が現在選択されている出力ハンドルに
10054C<$_> の内容を表示るために FILEHANDLE のみを使用するには、
11992出力されま
10055C<$fh> のような間接ファイルハンドルではなく、C<FH>ような実際の
11993L<C<$_>|perlvar/$_>内容を表示するために FILEHANDLEみを使用するには、
11994C<$fh> のような間接ファイルハンドルではなく、C<FH> のような裸の単語の
1005611995ファイルハンドルを使わなければなりません。
1005711996デフォルトの出力チャネルを STDOUT 以外にするには、select 演算子を
1005811997使ってください。
1005911998
1006011999=begin original
1006112000
10062The current value of C<$,> (if any) is printed between each LIST item. The
12001The current value of L<C<$,>|perlvar/$,> (if any) is printed between
10063current value of C<$\> (if any) is printed after the entire LIST has been
12002each LIST item. The current value of L<C<$\>|perlvar/$\> (if any) is
10064printed. Because print takes a LIST, anything in the LIST is evaluated in
12003printed after the entire LIST has been printed. Because print takes a
10065list context, including any subroutines whose return lists you pass to
12004LIST, anything in the LIST is evaluated in list context, including any
10066C<print>. Be careful not to follow the print keyword with a left
12005subroutines whose return lists you pass to
12006L<C<print>|/print FILEHANDLE LIST>. Be careful not to follow the print
12007keyword with a left
1006712008parenthesis unless you want the corresponding right parenthesis to
1006812009terminate the arguments to the print; put parentheses around all arguments
1006912010(or interpose a C<+>, but that doesn't look as good).
1007012011
1007112012=end original
1007212013
10073C<$,> の値が(もしあれば)各 LIST 要素の間に出力されます。
12014L<C<$,>|perlvar/$,> の値が(もしあれば)各 LIST 要素の間に出力されます。
10074LIST 全体が出力された後、(もしあれば) C<$\> の現在の値が出力されます。
12015LIST 全体が出力された後、(もしあれば) L<C<$\>|perlvar/$\> の現在の値が
12016出力されます。
1007512017print の引数は LIST なので、LIST の中のものは、すべてリストコンテキストで
10076評価されます; C<print> に渡した、リストを返すサブルーチンも含みます。。
12018評価されます; L<C<print>|/print FILEHANDLE LIST> に渡した、リストを返す
12019サブルーチンも含みます。
1007712020また、すべての引数を括弧で括るのでなければ、print というキーワードの
1007812021次に開き括弧を書いてはいけません; すべての引数を括弧で括ってください
1007912022(あるいは "print" と引数の間に C<+> を書きますが、これはあまり
1008012023よくありません)。
1008112024
1008212025=begin original
1008312026
1008412027If you're storing handles in an array or hash, or in general whenever
1008512028you're using any expression more complex than a bareword handle or a plain,
1008612029unsubscripted scalar variable to retrieve it, you will have to use a block
1008712030returning the filehandle value instead, in which case the LIST may not be
1008812031omitted:
1008912032
1009012033=end original
1009112034
1009212035もし FILESHANDLE を配列、ハッシュあるいは一般的には裸の単語のハンドルや
1009312036普通のスカラ変数よりも複雑な表現を使っている場合、代わりにその値を返す
1009412037ブロックを使う必要があります; この場合 LIST は省略できません:
1009512038
1009612039 print { $files[$i] } "stuff\n";
1009712040 print { $OK ? STDOUT : STDERR } "stuff\n";
1009812041
1009912042=begin original
1010012043
1010112044Printing to a closed pipe or socket will generate a SIGPIPE signal. See
1010212045L<perlipc> for more on signal handling.
1010312046
1010412047=end original
1010512048
1010612049閉じたパイプやソケットに print すると SIGPIPE シグナルが生成されます。
1010712050さらなるシグナル操作については L<perlipc> を参照してください。
1010812051
1010912052=item printf FILEHANDLE FORMAT, LIST
1011012053X<printf>
1011112054
1011212055=item printf FILEHANDLE
1011312056
1011412057=item printf FORMAT, LIST
1011512058
1011612059=item printf
1011712060
12061=for Pod::Functions output a formatted list to a filehandle
12062
1011812063=begin original
1011912064
10120Equivalent to C<print FILEHANDLE sprintf(FORMAT, LIST)>, except that C<$\>
12065Equivalent to C<print FILEHANDLE sprintf(FORMAT, LIST)>, except that
10121(the output record separator) is not appended. The first argument of the
12066L<C<$\>|perlvar/$\> (the output record separator) is not appended. The
10122list will be interpreted as the C<printf> format. See C<sprintf> for an
12067FORMAT and the LIST are actually parsed as a single list. The first
10123explanation of the format argument. If you omit the LIST, C<$_> is used;
12068argument of the list will be interpreted as the
10124to use FILEHANDLE without a LIST, you must use a real filehandle like
12069L<C<printf>|/printf FILEHANDLE FORMAT, LIST> format. This means that
10125C<FH>, not an indirect one like C<$fh>. If C<use locale> is in effect and
12070C<printf(@_)> will use C<$_[0]> as the format. See
10126POSIX::setlocale() has been called, the character used for the decimal
12071L<sprintf|/sprintf FORMAT, LIST> for an explanation of the format
10127separator in formatted floating-point numbers is affected by the LC_NUMERIC
12072argument. If C<use locale> (including C<use locale ':not_characters'>)
10128locale setting. See L<perllocale> and L<POSIX>.
12073is in effect and L<C<POSIX::setlocale>|POSIX/C<setlocale>> has been
12074called, the character used for the decimal separator in formatted
12075floating-point numbers is affected by the C<LC_NUMERIC> locale setting.
12076See L<perllocale> and L<POSIX>.
1012912077
1013012078=end original
1013112079
10132C<$\>(出力レコードセパレータ)を追加しないことを除けば、
12080L<C<$\>|perlvar/$\>(出力レコードセパレータ)を追加しないことを除けば、
1013312081C<print FILEHANDLE sprintf(FORMAT, LIST)> と等価です。
10134リストの最初の要素は、C<printf> フォーマット解釈されます。
12082FORMAT と LIST は実際には単一のリストとしてパースされます。
10135フォーマッ引数説明について C<sprintf> を参照してください。
12083リストの最初の要素、L<C<printf>|/printf FILEHANDLE FORMAT, LIST>
10136LIST を省略する、C<$_> が使われます;
12084フォーマット解釈されます
10137LIST FILEHANDLE を使るには、
12085これは、C<printf(@_)> はフォーマットと C<$_[0]> を使うということで
10138C<$fh> のような間接ァイルハンドルでなく、C<FH> のような実際の
12086ォーマット引数の説明について L<sprintf|/sprintf FORMAT, LIST>
10139ファイルハンドルを使わなければなりません
12087参照してください
10140C<use locale> が効力もっていて、POSIX::setlocale()呼び出されていれば
12088(C<use locale ':not_characters'> を含む) C<use locale>有効で
10141小数点に使われる文字は LC_NUMERIC ロケール設定の影響を受けます。
12089L<C<POSIX::setlocale>|POSIX/C<setlocale>> が呼び出されていれば、
12090小数点に使われる文字は C<LC_NUMERIC> ロケール設定の影響を受けます。
1014212091L<perllocale> と L<POSIX> を参照してください。
1014312092
1014412093=begin original
1014512094
10146Don't fall into the trap of using a C<printf> when a simple
12095For historical reasons, if you omit the list, L<C<$_>|perlvar/$_> is
10147C<print> would do. The C<print> is more efficient and less
12096used as the format;
10148error prone.
12097to use FILEHANDLE without a list, you must use a bareword filehandle like
12098C<FH>, not an indirect one like C<$fh>. However, this will rarely do what
12099you want; if L<C<$_>|perlvar/$_> contains formatting codes, they will be
12100replaced with the empty string and a warning will be emitted if
12101L<warnings> are enabled. Just use L<C<print>|/print FILEHANDLE LIST> if
12102you want to print the contents of L<C<$_>|perlvar/$_>.
1014912103
1015012104=end original
1015112105
10152単純 C<print> 使うべきころで C<printf> を使ってまう
12106歴史的理由により、リスト省略する、フォーマットと
12107L<C<$_>|perlvar/$_> が使われます;
12108リストなしで FILEHANDLE を使用するには、C<$fh> のような
12109間接ファイルハンドルではなく、C<FH> のような裸の単語の
12110ファイルハンドルを使わなければなりません。
12111しかし、これがあなたが求めていることをすることはまれです;
12112L<C<$_>|perlvar/$_> がフォーマッティングコードの場合、空文字列に置き換えられ、
12113L<warnings> が有効なら警告が出力されます。
12114L<C<$_>|perlvar/$_> の内容を表示したい場合は、単に
12115L<C<print>|/print FILEHANDLE LIST> を使ってください。
12116
12117=begin original
12118
12119Don't fall into the trap of using a
12120L<C<printf>|/printf FILEHANDLE FORMAT, LIST> when a simple
12121L<C<print>|/print FILEHANDLE LIST> would do. The
12122L<C<print>|/print FILEHANDLE LIST> is more efficient and less error
12123prone.
12124
12125=end original
12126
12127単純な L<C<print>|/print FILEHANDLE LIST> を使うべきところで
12128L<C<printf>|/printf FILEHANDLE FORMAT, LIST> を使ってしまう
1015312129罠にかからないようにしてください。
10154C<print> はより効率的で、間違いが起こりにくいです。
12130L<C<print>|/print FILEHANDLE LIST> はより効率的で、間違いが起こりにくいです。
1015512131
1015612132=item prototype FUNCTION
1015712133X<prototype>
1015812134
12135=item prototype
12136
12137=for Pod::Functions +5.002 get the prototype (if any) of a subroutine
12138
1015912139=begin original
1016012140
10161Returns the prototype of a function as a string (or C<undef> if the
12141Returns the prototype of a function as a string (or
12142L<C<undef>|/undef EXPR> if the
1016212143function has no prototype). FUNCTION is a reference to, or the name of,
10163the function whose prototype you want to retrieve.
12144the function whose prototype you want to retrieve. If FUNCTION is omitted,
12145L<C<$_>|perlvar/$_> is used.
1016412146
1016512147=end original
1016612148
1016712149関数のプロトタイプを文字列として返します(関数にプロトタイプがない場合は
10168C<undef> を返します)。
12150L<C<undef>|/undef EXPR> を返します)。
1016912151FUNCTION はプロトタイプを得たい関数の名前、またはリファレンスです。
12152FUNCTION が省略された場合、L<C<$_>|perlvar/$_> が使われます。
1017012153
1017112154=begin original
1017212155
1017312156If FUNCTION is a string starting with C<CORE::>, the rest is taken as a
10174name for a Perl builtin. If the builtin is not I<overridable> (such as
12157name for a Perl builtin. If the builtin's arguments
10175C<qw//>) or if its arguments cannot be adequately expressed by a prototype
12158cannot be adequately expressed by a prototype
10176(such as C<system>), prototype() returns C<undef>, because the builtin
12159(such as L<C<system>|/system LIST>), L<C<prototype>|/prototype FUNCTION>
12160returns L<C<undef>|/undef EXPR>, because the builtin
1017712161does not really behave like a Perl function. Otherwise, the string
1017812162describing the equivalent prototype is returned.
1017912163
1018012164=end original
1018112165
1018212166FUNCTION が C<CORE::> で始まっている場合、残りは Perl ビルドインの名前として
1018312167扱われます。
10184このビルドインが(C<qw//> のように) I<オーバーラド可能> でない、
12168このビルドインの引数が(L<C<system>|/system LIST> のように)プロトタプとして
10185またはこの引数が(C<system> のように)プロトタイプとして適切に記述できない場合、
12169適切に記述できない場合、L<C<prototype>|/prototype FUNCTION> は
10186prototype() は C<undef> を返します;
12170L<C<undef>|/undef EXPR> を返します;
1018712171なぜならビルドインは実際に Perl 関数のように振舞わないからです。
1018812172それ以外では、等価なプロトタイプを表現した文字列が返されます。
1018912173
1019012174=item push ARRAY,LIST
1019112175X<push> X<stack>
1019212176
10193=item push EXPR,LIST
12177=for Pod::Functions append one or more elements to an array
1019412178
1019512179=begin original
1019612180
1019712181Treats ARRAY as a stack by appending the values of LIST to the end of
1019812182ARRAY. The length of ARRAY increases by the length of LIST. Has the same
1019912183effect as
1020012184
1020112185=end original
1020212186
1020312187ARRAY をスタックとして扱い、LIST 内の値を ARRAY の終わりに追加します。
1020412188ARRAY の大きさは、LIST の長さ分だけ大きくなります。
1020512189これは、
1020612190
10207 for $value (LIST) {
12191 for my $value (LIST) {
1020812192 $ARRAY[++$#ARRAY] = $value;
1020912193 }
1021012194
1021112195=begin original
1021212196
1021312197but is more efficient. Returns the number of elements in the array following
10214the completed C<push>.
12198the completed L<C<push>|/push ARRAY,LIST>.
1021512199
1021612200=end original
1021712201
1021812202とするのと同じ効果がありますが、より効率的です。
10219C<push> の処理終了後の配列の要素数を返します。
12203L<C<push>|/push ARRAY,LIST> の処理終了後の配列の要素数を返します。
1022012204
1022112205=begin original
1022212206
10223Starting with Perl 5.14, C<push> can take a scalar EXPR, which must hold a
12207Starting with Perl 5.14, an experimental feature allowed
10224reference to an unblessed array. The argument will be dereferenced
12208L<C<push>|/push ARRAY,LIST> to take a
10225automatically. This aspect of C<push> is considered highly experimental.
12209scalar expression. This experiment has been deemed unsuccessful, and was
10226The exact behaviour may change in a future version of Perl.
12210removed as of Perl 5.24.
1022712211
1022812212=end original
1022912213
10230Perl 5.14 から、C<push> スカラの EXPR を取ることができになりました;
12214Perl 5.14 から、L<C<push>|/push ARRAY,LIST> がスカラを取ることが出来とい
10231これは bless されていない配列へのリファレンスでなければなりません
12215実験的機能がありました
10232引数自動的にデリファレンスされま
12216この実験失敗と見なされ、Perl 5.24 で削除されした
10233C<push> のこの動作は高度に実験的であると考えられています。
10234正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
1023512217
1023612218=item q/STRING/
1023712219
12220=for Pod::Functions singly quote a string
12221
1023812222=item qq/STRING/
1023912223
10240=item qx/STRING/
12224=for Pod::Functions doubly quote a string
1024112225
1024212226=item qw/STRING/
1024312227
12228=for Pod::Functions quote a list of words
12229
12230=item qx/STRING/
12231
12232=for Pod::Functions backquote quote a string
12233
1024412234=begin original
1024512235
1024612236Generalized quotes. See L<perlop/"Quote-Like Operators">.
1024712237
1024812238=end original
1024912239
1025012240汎用のクォートです。
1025112241L<perlop/"Quote-Like Operators"> を参照してください。
1025212242
1025312243=item qr/STRING/
1025412244
12245=for Pod::Functions +5.005 compile pattern
12246
1025512247=begin original
1025612248
1025712249Regexp-like quote. See L<perlop/"Regexp Quote-Like Operators">.
1025812250
1025912251=end original
1026012252
1026112253正規表現風のクォートです。
1026212254L<perlop/"Regexp Quote-Like Operators"> を参照してください。
1026312255
1026412256=item quotemeta EXPR
1026512257X<quotemeta> X<metacharacter>
1026612258
1026712259=item quotemeta
1026812260
12261=for Pod::Functions quote regular expression magic characters
12262
1026912263=begin original
1027012264
10271Returns the value of EXPR with all non-"word"
12265Returns the value of EXPR with all the ASCII non-"word"
10272characters backslashed. (That is, all characters not matching
12266characters backslashed. (That is, all ASCII characters not matching
1027312267C</[A-Za-z_0-9]/> will be preceded by a backslash in the
1027412268returned string, regardless of any locale settings.)
1027512269This is the internal function implementing
1027612270the C<\Q> escape in double-quoted strings.
12271(See below for the behavior on non-ASCII code points.)
1027712272
1027812273=end original
1027912274
10280EXPR の中のすべての非英数字キャラクタをバックスラッシュで
12275EXPR の中のすべての ASCII 非英数字キャラクタをバックスラッシュで
10281エスケープしたものを返します
12276エスケープしたものを返します
10282(つまり、C</[A-Za-z_0-9]/> にマッチしない全ての文字の前には
12277(つまり、C</[A-Za-z_0-9]/> にマッチしない全ての ASCII 文字の前には
10283ロケールに関わらずバックスラッシュが前置されます)
12278ロケールに関わらずバックスラッシュが前置されます。)
10284これは、ダブルクォート文字列での C<\Q> エスケープを
12279これは、ダブルクォート文字列での C<\Q> エスケープを実装するための
10285実装するための内部関数です。
12280内部関数です。
12281(非 ASCII 符号位置での振る舞いについては以下を参照してください。)
1028612282
1028712283=begin original
1028812284
10289If EXPR is omitted, uses C<$_>.
12285If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
1029012286
1029112287=end original
1029212288
10293EXPR が省略されると、C<$_> を使います。
12289EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
1029412290
1029512291=begin original
1029612292
1029712293quotemeta (and C<\Q> ... C<\E>) are useful when interpolating strings into
1029812294regular expressions, because by default an interpolated variable will be
10299considered a mini-regular expression. For example:
12295considered a mini-regular expression. For example:
1030012296
1030112297=end original
1030212298
1030312299クォートメタ (と C<\Q> ... C<\E>) は、文字列を正規表現に展開するのに
1030412300便利です; なぜなら、デフォルトでは展開された変数は小さな正規表現として
1030512301扱われるからです。
1030612302例えば:
1030712303
1030812304 my $sentence = 'The quick brown fox jumped over the lazy dog';
1030912305 my $substring = 'quick.*?fox';
1031012306 $sentence =~ s{$substring}{big bad wolf};
1031112307
1031212308=begin original
1031312309
1031412310Will cause C<$sentence> to become C<'The big bad wolf jumped over...'>.
1031512311
1031612312=end original
1031712313
1031812314とすると、C<$sentence> は C<'The big bad wolf jumped over...'> になります。
1031912315
1032012316=begin original
1032112317
1032212318On the other hand:
1032312319
1032412320=end original
1032512321
1032612322一方:
1032712323
1032812324 my $sentence = 'The quick brown fox jumped over the lazy dog';
1032912325 my $substring = 'quick.*?fox';
1033012326 $sentence =~ s{\Q$substring\E}{big bad wolf};
1033112327
1033212328=begin original
1033312329
1033412330Or:
1033512331
1033612332=end original
1033712333
1033812334あるいは:
1033912335
1034012336 my $sentence = 'The quick brown fox jumped over the lazy dog';
1034112337 my $substring = 'quick.*?fox';
1034212338 my $quoted_substring = quotemeta($substring);
1034312339 $sentence =~ s{$quoted_substring}{big bad wolf};
1034412340
1034512341=begin original
1034612342
10347Will both leave the sentence as is. Normally, when accepting literal string
12343Will both leave the sentence as is.
10348input from the user, quotemeta() or C<\Q> must be used.
12344Normally, when accepting literal string input from the user,
12345L<C<quotemeta>|/quotemeta EXPR> or C<\Q> must be used.
1034912346
1035012347=end original
1035112348
1035212349とすると、両方ともそのままです。
1035312350普通は、ユーザーからのリテラルな文字列入力を受け付ける場合は、
10354必ず quotemeta() か C<\Q> を使わなければなりません。
12351必ず L<C<quotemeta>|/quotemeta EXPR> か C<\Q> を使わなければなりません。
1035512352
1035612353=begin original
1035712354
10358In Perl 5.14, all characters whose code points are above 127 are not
12355In Perl v5.14, all non-ASCII characters are quoted in non-UTF-8-encoded
10359quoted in UTF8-encoded strings, but all are quoted in UTF-8 strings.
12356strings, but not quoted in UTF-8 strings.
10360It is planned to change this behavior in 5.16, but the exact rules
10361haven't been determined yet.
1036212357
1036312358=end original
1036412359
10365Perl 5.14 では、符号位置が 127 を超える全ての文字は UTF-8 エンコードされた
12360Perl v5.14 では、全ての非 ASCII 文字は UTF-8 エンコードされた
10366文字列ではクォートされませんが、UTF-8 文字列では全てクォートされます。
12361文字列ではクォートされませんが、UTF-8 文字列ではクォートされます。
10367この振る舞いは 5.16 で変更が計画されていますが、正確な規則はまだ
10368決定していません。
1036912362
12363=begin original
12364
12365Starting in Perl v5.16, Perl adopted a Unicode-defined strategy for
12366quoting non-ASCII characters; the quoting of ASCII characters is
12367unchanged.
12368
12369=end original
12370
12371Perl v5.16 から、Perl は非 ASCII 文字をクォートするのに Unicode で
12372定義された戦略を採用しました; ASCII 文字のクォートは変わりません。
12373
12374=begin original
12375
12376Also unchanged is the quoting of non-UTF-8 strings when outside the
12377scope of a
12378L<C<use feature 'unicode_strings'>|feature/The 'unicode_strings' feature>,
12379which is to quote all
12380characters in the upper Latin1 range. This provides complete backwards
12381compatibility for old programs which do not use Unicode. (Note that
12382C<unicode_strings> is automatically enabled within the scope of a
12383S<C<use v5.12>> or greater.)
12384
12385=end original
12386
12387また、
12388L<C<use feature 'unicode_strings'>|feature/The 'unicode_strings' feature> の
12389範囲外で非 UTF-8 文字列をクォートするのも変わりません; 上位の Latin1 の範囲の
12390全ての文字をクォートします。
12391これは Unicode を使わない古いプログラムに対して完全な後方互換性を提供します。
12392(C<unicode_strings> は S<C<use v5.12>> またはそれ以上のスコープでは
12393自動的に有効になることに注意してください。)
12394
12395=begin original
12396
12397Within the scope of L<C<use locale>|locale>, all non-ASCII Latin1 code
12398points
12399are quoted whether the string is encoded as UTF-8 or not. As mentioned
12400above, locale does not affect the quoting of ASCII-range characters.
12401This protects against those locales where characters such as C<"|"> are
12402considered to be word characters.
12403
12404=end original
12405
12406L<C<use locale>|locale> スコープの内側では、全ての非 ASCII Latin1 符号位置は
12407文字列が UTF-8 でエンコードされているかどうかに関わらずクォートされます。
12408上述のように、ロケールは ASCII の範囲の文字のクォートに影響を与えません。
12409これは C<"|"> のような文字が単語文字として考えられるロケールから守ります。
12410
12411=begin original
12412
12413Otherwise, Perl quotes non-ASCII characters using an adaptation from
12414Unicode (see L<http://www.unicode.org/reports/tr31/>).
12415The only code points that are quoted are those that have any of the
12416Unicode properties: Pattern_Syntax, Pattern_White_Space, White_Space,
12417Default_Ignorable_Code_Point, or General_Category=Control.
12418
12419=end original
12420
12421さもなければ、Perl は Unicode からの本版を使って非 ASCII 文字をクォートします
12422(L<http://www.unicode.org/reports/tr31/> 参照)。
12423クォートされる符号位置は以下のどれかの Unicode を特性を持つものだけです:
12424Pattern_Syntax, Pattern_White_Space, White_Space,
12425Default_Ignorable_Code_Point, or General_Category=Control。
12426
12427=begin original
12428
12429Of these properties, the two important ones are Pattern_Syntax and
12430Pattern_White_Space. They have been set up by Unicode for exactly this
12431purpose of deciding which characters in a regular expression pattern
12432should be quoted. No character that can be in an identifier has these
12433properties.
12434
12435=end original
12436
12437これらの特性の中で、重要な二つは Pattern_Syntax と Pattern_White_Space です。
12438これらはまさに正規表現中パターン中のどの文字をクォートするべきかを
12439決定するという目的のために Unicode によって設定されています。
12440識別子になる文字はこれらの特性はありません。
12441
12442=begin original
12443
12444Perl promises, that if we ever add regular expression pattern
12445metacharacters to the dozen already defined
12446(C<\ E<verbar> ( ) [ { ^ $ * + ? .>), that we will only use ones that have the
12447Pattern_Syntax property. Perl also promises, that if we ever add
12448characters that are considered to be white space in regular expressions
12449(currently mostly affected by C</x>), they will all have the
12450Pattern_White_Space property.
12451
12452=end original
12453
12454Perl は、正規表現メタ文字として既に定義されている
12455(C<\ E<verbar> ( ) [ { ^ $ * + ? .>) ものに追加するときは、
12456Pattern_Syntax 特性を持つものだけを使うことを約束します。
12457Perl はまた、(現在の所ほとんどは C</x> よって影響される)正規表現中で空白と
12458考えられる文字に追加するときは、Pattern_White_Space 特性を
12459持つものであることを約束します。
12460
12461=begin original
12462
12463Unicode promises that the set of code points that have these two
12464properties will never change, so something that is not quoted in v5.16
12465will never need to be quoted in any future Perl release. (Not all the
12466code points that match Pattern_Syntax have actually had characters
12467assigned to them; so there is room to grow, but they are quoted
12468whether assigned or not. Perl, of course, would never use an
12469unassigned code point as an actual metacharacter.)
12470
12471=end original
12472
12473Unicode はこれら二つの特性を持つ符号位置の集合が決して変わらないことを
12474約束しているので、v5.16 でクォートされないものは将来の Perl リリースでも
12475クォートする必要はありません。
12476(Pattern_Syntax にマッチングする全ての符号位置が実際に割り当てられている
12477文字を持っているわけではありません; したがって拡張する余地がありますが、
12478割り当てられているかどうかに関わらずクォートされます。
12479Perl はもちろん割り当てられていない符号位置を実際のメタ文字として使うことは
12480ありません。)
12481
12482=begin original
12483
12484Quoting characters that have the other 3 properties is done to enhance
12485the readability of the regular expression and not because they actually
12486need to be quoted for regular expression purposes (characters with the
12487White_Space property are likely to be indistinguishable on the page or
12488screen from those with the Pattern_White_Space property; and the other
12489two properties contain non-printing characters).
12490
12491=end original
12492
12493その他の 3 特性を持つ文字のクォートは正規表現の可読性を向上させるために
12494行われ、実際には正規表現の目的でクォートする必要があるからではありません
12495(White_Space 特性を持つ文字は表示上は Pattern_White_Space 特性を持つ文字と
12496おそらく区別が付かないでしょう; そして残りの
12497二つの特性は非表示文字を含んでいます).
12498
1037012499=item rand EXPR
1037112500X<rand> X<random>
1037212501
1037312502=item rand
1037412503
12504=for Pod::Functions retrieve the next pseudorandom number
12505
1037512506=begin original
1037612507
1037712508Returns a random fractional number greater than or equal to C<0> and less
1037812509than the value of EXPR. (EXPR should be positive.) If EXPR is
1037912510omitted, the value C<1> is used. Currently EXPR with the value C<0> is
1038012511also special-cased as C<1> (this was undocumented before Perl 5.8.0
1038112512and is subject to change in future versions of Perl). Automatically calls
10382C<srand> unless C<srand> has already been called. See also C<srand>.
12513L<C<srand>|/srand EXPR> unless L<C<srand>|/srand EXPR> has already been
12514called. See also L<C<srand>|/srand EXPR>.
1038312515
1038412516=end original
1038512517
1038612518C<0> 以上 EXPR の値未満の小数の乱数値を返します。
1038712519(EXPR は正の数である必要があります。)
10388EXPR 省略ると、C<1> とみなします。
12520EXPR 省略されると、C<1> が使われます。
1038912521現在のところ、EXPR に値 C<0> をセットすると C<1> として特別扱いされます
1039012522(これは Perl 5.8.0 以前には文書化されておらず、将来のバージョンの perl では
1039112523変更される可能性があります)。
10392C<srand> が既に呼ばれている場合以外は、自動的に C<srand> 関数を
12524L<C<srand>|/srand EXPR> が既に呼ばれている場合以外は、自動的に
10393呼び出します。
12525L<C<srand>|/srand EXPR> 関数を呼び出します。
10394C<srand> も参照してください。
12526L<C<srand>|/srand EXPR> も参照してください。
1039512527
1039612528=begin original
1039712529
10398Apply C<int()> to the value returned by C<rand()> if you want random
12530Apply L<C<int>|/int EXPR> to the value returned by L<C<rand>|/rand EXPR>
10399integers instead of random fractional numbers. For example,
12531if you want random integers instead of random fractional numbers. For
12532example,
1040012533
1040112534=end original
1040212535
10403ランダムな小数ではなく、ランダムな整数がほしい場合は、C<rand()> から
12536ランダムな小数ではなく、ランダムな整数がほしい場合は、
10404返された値に C<int()> を適用してください。
12537L<C<rand>|/rand EXPR> から返された値に L<C<int>|/int EXPR>
12538適用してください。
12539例えば:
1040512540
1040612541 int(rand(10))
1040712542
1040812543=begin original
1040912544
1041012545returns a random integer between C<0> and C<9>, inclusive.
1041112546
1041212547=end original
1041312548
1041412549これは C<0> から C<9> の値をランダムに返します。
1041512550
1041612551=begin original
1041712552
1041812553(Note: If your rand function consistently returns numbers that are too
1041912554large or too small, then your version of Perl was probably compiled
1042012555with the wrong number of RANDBITS.)
1042112556
1042212557=end original
1042312558
1042412559(注: もし、rand 関数が、常に大きい値ばかりや、小さい数ばかりを
1042512560返すようなら、お使いになっている Perl が、
1042612561良くない RANDBITS を使ってコンパイルされている可能性があります。)
1042712562
1042812563=begin original
1042912564
10430B<C<rand()> is not cryptographically secure. You should not rely
12565B<L<C<rand>|/rand EXPR> is not cryptographically secure. You should not rely
1043112566on it in security-sensitive situations.> As of this writing, a
1043212567number of third-party CPAN modules offer random number generators
1043312568intended by their authors to be cryptographically secure,
10434including: L<Math::Random::Secure>, L<Math::Random::MT::Perl>, and
12569including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
10435L<Math::TrulyRandom>.
12570and L<Math::TrulyRandom>.
1043612571
1043712572=end original
1043812573
10439B<C<rand()> は暗号学的に安全ではありません。
12574B<L<C<rand>|/rand EXPR> は暗号学的に安全ではありません。
1044012575セキュリティ的に重要な状況でこれに頼るべきではありません。>
1044112576これを書いている時点で、いくつかのサードパーティ CPAN モジュールが
1044212577作者によって暗号学的に安全であることを目的とした乱数生成器を
10443提供しています: L<Math::Random::Secure>, L<Math::Random::MT::Perl>,
12578提供しています: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
1044412579L<Math::TrulyRandom> などです。
1044512580
1044612581=item read FILEHANDLE,SCALAR,LENGTH,OFFSET
1044712582X<read> X<file, read>
1044812583
1044912584=item read FILEHANDLE,SCALAR,LENGTH
1045012585
12586=for Pod::Functions fixed-length buffered input from a filehandle
12587
1045112588=begin original
1045212589
1045312590Attempts to read LENGTH I<characters> of data into variable SCALAR
1045412591from the specified FILEHANDLE. Returns the number of characters
1045512592actually read, C<0> at end of file, or undef if there was an error (in
10456the latter case C<$!> is also set). SCALAR will be grown or shrunk
12593the latter case L<C<$!>|perlvar/$!> is also set). SCALAR will be grown
12594or shrunk
1045712595so that the last character actually read is the last character of the
1045812596scalar after the read.
1045912597
1046012598=end original
1046112599
10462指定した FILEHANDLE から、変数 SCALAR に LENGTH I<文字> の
12600指定した FILEHANDLE から、変数 SCALAR に LENGTH I<文字> のデータを
10463データを読み込みます。
12601読み込みます。
10464実際に読み込まれた文字数、
12602実際に読み込まれた文字数、ファイル終端の場合は C<0>、エラーの場合は undef の
10465ファイル終端の場合C<0>、エラーの場合は undef のいずかを返します
12603いずれかを返します (後者の場合、L<C<$!>|perlvar/$!> もセットされます)。
10466(後者の場合、C<$!> もセットされま)。
12604SCALAR は伸び縮みるので、読み込み後は、実際に読み込んだ最後の文字がスカラの
10467SCALAR は伸び縮みするで、
12605最後文字になります。
10468読み込み後は、実際に読み込んだ最後の文字がスカラの最後の文字になります。
1046912606
1047012607=begin original
1047112608
1047212609An OFFSET may be specified to place the read data at some place in the
1047312610string other than the beginning. A negative OFFSET specifies
1047412611placement at that many characters counting backwards from the end of
1047512612the string. A positive OFFSET greater than the length of SCALAR
1047612613results in the string being padded to the required size with C<"\0">
1047712614bytes before the result of the read is appended.
1047812615
1047912616=end original
1048012617
10481OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行なうことが
12618OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行なえます。
10482できます。
1048312619OFFSET に負の値を指定すると、文字列の最後から逆向きに何文字目かで
1048412620位置を指定します。
10485OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は
12621OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は読み込みの結果が
10486読み込みの結果が追加される前に、必要なサイズまで C<"\0"> のバイトで
12622追加される前に、必要なサイズまで C<"\0"> のバイトでパッディングされます。
10487パッディングされます。
1048812623
1048912624=begin original
1049012625
1049112626The call is implemented in terms of either Perl's or your system's native
10492fread(3) library function. To get a true read(2) system call, see C<sysread>.
12627L<fread(3)> library function. To get a true L<read(2)> system call, see
12628L<sysread|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>.
1049312629
1049412630=end original
1049512631
10496この関数は、Perl か システムの fread(3) ライブラリ関数を使って実装しています。
12632この関数は、Perl か システムの L<fread(3)> ライブラリ関数を使って
10497本当の read(2) システムコールを利用するには、C<sysread> を参照してください。
12633実装しています
12634本当の L<read(2)> システムコールを利用するには、
12635L<sysread|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を参照してください。
1049812636
1049912637=begin original
1050012638
1050112639Note the I<characters>: depending on the status of the filehandle,
1050212640either (8-bit) bytes or characters are read. By default, all
1050312641filehandles operate on bytes, but for example if the filehandle has
10504been opened with the C<:utf8> I/O layer (see L</open>, and the C<open>
12642been opened with the C<:utf8> I/O layer (see
10505pragma, L<open>), the I/O will operate on UTF8-encoded Unicode
12643L<C<open>|/open FILEHANDLE,EXPR>, and the L<open>
10506characters, not bytes. Similarly for the C<:encoding> pragma:
12644pragma), the I/O will operate on UTF8-encoded Unicode
12645characters, not bytes. Similarly for the C<:encoding> layer:
1050712646in that case pretty much any characters can be read.
1050812647
1050912648=end original
1051012649
1051112650I<文字> に関する注意: ファイルハンドルの状態によって、(8 ビットの) バイトか
1051212651文字が読み込まれます。
1051312652デフォルトでは全てのファイルハンドルはバイトを処理しますが、
10514例えばファイルハンドルが C<:utf8> I/O 層(L</open>, C<open> プラグマ、
12653例えばファイルハンドルが C<:utf8> I/O 層(L<C<open>|/open FILEHANDLE,EXPR>,
10515L<open> を参照してください) で開かれた場合、I/O はバイトではなく、
12654L<open> プラグマを参照してください) で開かれた場合、I/O はバイトではなく、
1051612655UTF8 エンコードされた Unicode 文字を操作します。
10517C<:encoding> プラグマも同様です:
12656C<:encoding> も同様です:
1051812657この場合、ほとんど大体全ての文字が読み込めます。
1051912658
1052012659=item readdir DIRHANDLE
1052112660X<readdir>
1052212661
12662=for Pod::Functions get a directory from a directory handle
12663
1052312664=begin original
1052412665
10525Returns the next directory entry for a directory opened by C<opendir>.
12666Returns the next directory entry for a directory opened by
12667L<C<opendir>|/opendir DIRHANDLE,EXPR>.
1052612668If used in list context, returns all the rest of the entries in the
1052712669directory. If there are no more entries, returns the undefined value in
1052812670scalar context and the empty list in list context.
1052912671
1053012672=end original
1053112673
10532C<opendir> でオープンしたディレクトリで、
12674L<C<opendir>|/opendir DIRHANDLE,EXPR> でオープンしたディレクトリで、次の
10533次のディレクトリエントリを返します。
12675ディレクトリエントリを返します。
10534リストコンテキストで用いると、
12676リストコンテキストで用いると、そのディレクトリの残りのエントリを、すべて
10535そのディレクトリの残りのエントリを、すべて返します。
12677返します。
1053612678エントリが残っていない場合には、スカラコンテキストでは未定義値を、
1053712679リストコンテキストでは空リストを返します。
1053812680
1053912681=begin original
1054012682
10541If you're planning to filetest the return values out of a C<readdir>, you'd
12683If you're planning to filetest the return values out of a
10542better prepend the directory in question. Otherwise, because we didn't
12684L<C<readdir>|/readdir DIRHANDLE>, you'd better prepend the directory in
10543C<chdir> there, it would have been testing the wrong file.
12685question. Otherwise, because we didn't L<C<chdir>|/chdir EXPR> there,
12686it would have been testing the wrong file.
1054412687
1054512688=end original
1054612689
10547C<readdir> の返り値をファイルテストに使おうと計画しているなら、
12690L<C<readdir>|/readdir DIRHANDLE> の返り値をファイルテストに使おうと
10548頭にディレクトリをつける必要があります。
12691計画しているなら、頭にディレクトリをつける必要があります。
10549さもなければ、ここでは C<chdir> はしないので、
12692さもなければ、ここでは L<C<chdir>|/chdir EXPR> はしないので、
1055012693間違ったファイルをテストしてしまうことになるでしょう。
1055112694
10552 opendir(my $dh, $some_dir) || die "can't opendir $some_dir: $!";
12695 opendir(my $dh, $some_dir) || die "Can't opendir $some_dir: $!";
10553 @dots = grep { /^\./ && -f "$some_dir/$_" } readdir($dh);
12696 my @dots = grep { /^\./ && -f "$some_dir/$_" } readdir($dh);
1055412697 closedir $dh;
1055512698
1055612699=begin original
1055712700
10558As of Perl 5.11.2 you can use a bare C<readdir> in a C<while> loop,
12701As of Perl 5.12 you can use a bare L<C<readdir>|/readdir DIRHANDLE> in a
10559which will set C<$_> on every iteration.
12702C<while> loop, which will set L<C<$_>|perlvar/$_> on every iteration.
1056012703
1056112704=end original
1056212705
10563Perl 5.11.2 から裸の C<readdir> を C<while> で使うことができ、
12706Perl 5.12 から裸の L<C<readdir>|/readdir DIRHANDLE> を C<while> で
10564この場合繰り返し毎に C<$_> にセットされます。
12707使うとができ、この場合繰り返し毎に L<C<$_>|perlvar/$_> にセットされます。
1056512708
10566 opendir(my $dh, $some_dir) || die;
12709 opendir(my $dh, $some_dir) || die "Can't open $some_dir: $!";
10567 while(readdir $dh) {
12710 while (readdir $dh) {
1056812711 print "$some_dir/$_\n";
1056912712 }
1057012713 closedir $dh;
1057112714
12715=begin original
12716
12717To avoid confusing would-be users of your code who are running earlier
12718versions of Perl with mysterious failures, put this sort of thing at the
12719top of your file to signal that your code will work I<only> on Perls of a
12720recent vintage:
12721
12722=end original
12723
12724あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
12725失敗で混乱することを避けるために、コードが最近のバージョンの Perl で
12726I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
12727書いてください:
12728
12729 use 5.012; # so readdir assigns to $_ in a lone while test
12730
1057212731=item readline EXPR
1057312732
1057412733=item readline
1057512734X<readline> X<gets> X<fgets>
1057612735
12736=for Pod::Functions fetch a record from a file
12737
1057712738=begin original
1057812739
1057912740Reads from the filehandle whose typeglob is contained in EXPR (or from
1058012741C<*ARGV> if EXPR is not provided). In scalar context, each call reads and
1058112742returns the next line until end-of-file is reached, whereupon the
10582subsequent call returns C<undef>. In list context, reads until end-of-file
12743subsequent call returns L<C<undef>|/undef EXPR>. In list context, reads
10583is reached and returns a list of lines. Note that the notion of "line"
12744until end-of-file is reached and returns a list of lines. Note that the
10584used here is whatever you may have defined with C<$/> or
12745notion of "line" used here is whatever you may have defined with
10585C<$INPUT_RECORD_SEPARATOR>). See L<perlvar/"$/">.
12746L<C<$E<sol>>|perlvar/$E<sol>> (or C<$INPUT_RECORD_SEPARATOR> in
12747L<English>). See L<perlvar/"$/">.
1058612748
1058712749=end original
1058812750
1058912751型グロブが EXPR (EXPR がない場合は C<*ARGV>) に含まれている
1059012752ファイルハンドルから読み込みます。
10591スカラコンテキストでは、呼び出し毎に一行読み込んで返します
12753スカラコンテキストでは、呼び出し毎に一行読み込んで返します; ファイルの
10592ファイルの最後まで読み込んだら、以後の呼び出しでは C<undef> を返します。
12754最後まで読み込んだら、以後の呼び出しでは L<C<undef>|/undef EXPR> を返します。
10593リストコンテキストでは、ファイルの最後まで読み込んで、
12755リストコンテキストでは、ファイルの最後まで読み込んで、行のリストを返します。
10594リストを返しす。
12756ここで「行」とは、L<C<$E<sol>>|perlvar/$E<sol>> (たは
10595ここでの「行」とは、C<$/> または C<$INPUT_RECORD_SEPARATOR> で
12757L<English> モジュールでは C<$INPUT_RECORD_SEPARATOR>)
1059612758定義されることに注意してください。
10597L<perlvar/"$/"> を参照してさい。
12759L<perlvar/"$/"> を参照してください。
1059812760
1059912761=begin original
1060012762
10601When C<$/> is set to C<undef>, when C<readline> is in scalar
12763When L<C<$E<sol>>|perlvar/$E<sol>> is set to L<C<undef>|/undef EXPR>,
10602context (i.e., file slurp mode), and when an empty file is read, it
12764when L<C<readline>|/readline EXPR> is in scalar context (i.e., file
10603returns C<''> the first time, followed by C<undef> subsequently.
12765slurp mode), and when an empty file is read, it returns C<''> the first
12766time, followed by L<C<undef>|/undef EXPR> subsequently.
1060412767
1060512768=end original
1060612769
10607C<$/> に C<undef> を設定した場合は、C<readline> はスカラコンテキスト
12770L<C<$E<sol>>|perlvar/$E<sol>>L<C<undef>|/undef EXPR> を設定した場合は、
10608(つまりファイル吸い込みモード)となり、
12771L<C<readline>|/readline EXPR> はスカラコンテキスト (つまりファイル吸い込み
10609空のファイルを読み込んだ場合は、最初は C<''> を返し、
12772モード)となり、空のファイルを読み込んだ場合は、最初は C<''> を返し、
10610それ以降は C<undef> を返します。
12773それ以降は L<C<undef>|/undef EXPR> を返します。
1061112774
1061212775=begin original
1061312776
1061412777This is the internal function implementing the C<< <EXPR> >>
1061512778operator, but you can use it directly. The C<< <EXPR> >>
1061612779operator is discussed in more detail in L<perlop/"I/O Operators">.
1061712780
1061812781=end original
1061912782
1062012783これは C<< <EXPR> >> 演算子を実装している内部関数ですが、
1062112784直接使うこともできます。
1062212785C<< <EXPR> >> 演算子についてのさらなる詳細については
1062312786L<perlop/"I/O Operators"> で議論されています。
1062412787
10625 $line = <STDIN>;
12788 my $line = <STDIN>;
10626 $line = readline(*STDIN); # same thing
12789 my $line = readline(STDIN); # same thing
1062712790
1062812791=begin original
1062912792
10630If C<readline> encounters an operating system error, C<$!> will be set
12793If L<C<readline>|/readline EXPR> encounters an operating system error,
10631with the corresponding error message. It can be helpful to check
12794L<C<$!>|perlvar/$!> will be set with the corresponding error message.
10632C<$!> when you are reading from filehandles you don't trust, such as a
12795It can be helpful to check L<C<$!>|perlvar/$!> when you are reading from
10633tty or a socket. The following example uses the operator form of
12796filehandles you don't trust, such as a tty or a socket. The following
10634C<readline> and dies if the result is not defined.
12797example uses the operator form of L<C<readline>|/readline EXPR> and dies
12798if the result is not defined.
1063512799
1063612800=end original
1063712801
10638C<readline> が OS のシステムエラーになると、C<$!> に対応するエラーメッセージが
12802L<C<readline>|/readline EXPR> が OS のシステムエラーになると、
10639セットされます。
12803L<C<$!>|perlvar/$!> に対応するエラーメッセージがセットされます。
1064012804tty やソケットといった、信頼できないファイルハンドルから読み込む時には
10641C<$!> をチェックするのが助けになります。
12805L<C<$!>|perlvar/$!> をチェックするのが助けになります。
10642以下の例は演算子の形の C<readline> を使っており、結果が
12806以下の例は演算子の形の L<C<readline>|/readline EXPR> を使っており、結果が
1064312807未定義の場合は die します。
1064412808
1064512809 while ( ! eof($fh) ) {
10646 defined( $_ = <$fh> ) or die "readline failed: $!";
12810 defined( $_ = readline $fh ) or die "readline failed: $!";
1064712811 ...
1064812812 }
1064912813
1065012814=begin original
1065112815
10652Note that you have can't handle C<readline> errors that way with the
12816Note that you have can't handle L<C<readline>|/readline EXPR> errors
10653C<ARGV> filehandle. In that case, you have to open each element of
12817that way with the C<ARGV> filehandle. In that case, you have to open
10654C<@ARGV> yourself since C<eof> handles C<ARGV> differently.
12818each element of L<C<@ARGV>|perlvar/@ARGV> yourself since
12819L<C<eof>|/eof FILEHANDLE> handles C<ARGV> differently.
1065512820
1065612821=end original
1065712822
10658C<readline> のエラーは C<ARGV> ファイルハンドルの方法では扱えないことに
12823L<C<readline>|/readline EXPR> のエラーは C<ARGV> ファイルハンドルの方法では
10659注意してください。
12824扱えないことに注意してください。
10660この場合、C<eof> は C<ARGV> を異なった方法で扱うので、
12825この場合、L<C<eof>|/eof FILEHANDLE> は C<ARGV> を異なった方法で扱うので、
10661C<@ARGV> のそれぞれの要素を自分でオープンする必要があります。
12826L<C<@ARGV>|perlvar/@ARGV> のそれぞれの要素を自分でオープンする必要があります。
1066212827
1066312828 foreach my $arg (@ARGV) {
1066412829 open(my $fh, $arg) or warn "Can't open $arg: $!";
1066512830
1066612831 while ( ! eof($fh) ) {
10667 defined( $_ = <$fh> )
12832 defined( $_ = readline $fh )
1066812833 or die "readline failed for $arg: $!";
1066912834 ...
1067012835 }
1067112836 }
1067212837
1067312838=item readlink EXPR
1067412839X<readlink>
1067512840
1067612841=item readlink
1067712842
12843=for Pod::Functions determine where a symbolic link is pointing
12844
1067812845=begin original
1067912846
1068012847Returns the value of a symbolic link, if symbolic links are
1068112848implemented. If not, raises an exception. If there is a system
10682error, returns the undefined value and sets C<$!> (errno). If EXPR is
12849error, returns the undefined value and sets L<C<$!>|perlvar/$!> (errno).
10683omitted, uses C<$_>.
12850If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
1068412851
1068512852=end original
1068612853
10687シンボリックリンクが実装されていれば、
12854シンボリックリンクが実装されていれば、シンボリックリンクの値を返します。
10688シンボリックリンクの値を返します。
1068912855実装されていないときには、例外が発生します。
1069012856何らかのシステムエラーが検出されると、未定義値を返し、
10691C<$!> (errno) を設定します。
12857L<C<$!>|perlvar/$!> (errno) を設定します。
10692EXPR が省略されると、C<$_> を使います。
12858EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
1069312859
12860=begin original
12861
12862Portability issues: L<perlport/readlink>.
12863
12864=end original
12865
12866移植性の問題: L<perlport/readlink>。
12867
1069412868=item readpipe EXPR
1069512869
1069612870=item readpipe
1069712871X<readpipe>
1069812872
12873=for Pod::Functions execute a system command and collect standard output
12874
1069912875=begin original
1070012876
1070112877EXPR is executed as a system command.
1070212878The collected standard output of the command is returned.
1070312879In scalar context, it comes back as a single (potentially
1070412880multi-line) string. In list context, returns a list of lines
10705(however you've defined lines with C<$/> or C<$INPUT_RECORD_SEPARATOR>).
12881(however you've defined lines with L<C<$E<sol>>|perlvar/$E<sol>> (or
12882C<$INPUT_RECORD_SEPARATOR> in L<English>)).
1070612883This is the internal function implementing the C<qx/EXPR/>
1070712884operator, but you can use it directly. The C<qx/EXPR/>
1070812885operator is discussed in more detail in L<perlop/"I/O Operators">.
10709If EXPR is omitted, uses C<$_>.
12886If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
1071012887
1071112888=end original
1071212889
1071312890EXPR がシステムコマンドとして実行されます。
1071412891コマンドの標準出力の内容が返されます。
1071512892スカラコンテキストでは、単一の(内部的に複数行の)文字列を返します。
1071612893リストコンテキストでは、行のリストを返します
10717(但し、行は C<$/> または C<$INPUT_RECORD_SEPARATOR> で定義されます)。
12894(但し、行は L<C<$E<sol>>|perlvar/$E<sol>> (または L<English> モジュール
10718これは C<qx/EXPR/> 演算子を実装する内部関数ですが、
12895C<$INPUT_RECORD_SEPARATOR> で定義されま)。
10719直接使うことも出来ます。
12896これは C<qx/EXPR/> 演算子を実装する内部関数ですが、直接使うことも出来ます。
10720C<qx/EXPR/> 演算子は L<perlop/"I/O Operators"> でより詳細に
12897C<qx/EXPR/> 演算子は L<perlop/"I/O Operators"> でより詳細に述べられています。
10721述べらいます。
12898EXPR が省略さると、L<C<$_>|perlvar/$_> を使います。
10722EXPR を省略すると、C<$_> を使用します。
1072312899
1072412900=item recv SOCKET,SCALAR,LENGTH,FLAGS
1072512901X<recv>
1072612902
12903=for Pod::Functions receive a message over a Socket
12904
1072712905=begin original
1072812906
1072912907Receives a message on a socket. Attempts to receive LENGTH characters
1073012908of data into variable SCALAR from the specified SOCKET filehandle.
1073112909SCALAR will be grown or shrunk to the length actually read. Takes the
1073212910same flags as the system call of the same name. Returns the address
1073312911of the sender if SOCKET's protocol supports this; returns an empty
1073412912string otherwise. If there's an error, returns the undefined value.
10735This call is actually implemented in terms of recvfrom(2) system call.
12913This call is actually implemented in terms of the L<recvfrom(2)> system call.
1073612914See L<perlipc/"UDP: Message Passing"> for examples.
1073712915
1073812916=end original
1073912917
1074012918ソケット上のメッセージを受信します。
1074112919指定されたファイルハンドル SOCKET から、変数 SCALAR に
1074212920LENGTH 文字のデータを読み込もうとします。
10743SCALAR は、実際に読まれた長さによって、大きくなったり、
12921SCALAR は、実際に読まれた長さによって、大きくなったり、小さくなったりします。
10744小さくなったりします。
12922同名のシステムコールと同じフラグが指定できます。
10745同名のシステムコールと同じ FLAGS を使います。
1074612923SOCKET のプロトコルが対応していれば、送信側のアドレスを返します。
1074712924エラー発生時には、未定義値を返します。
10748実際には、C のrecvfrom(2) を呼びます。
12925実際には、C の L<recvfrom(2)> を呼びます。
10749例についてはL<perlipc/"UDP: Message Passing">を参照してください。
12926例については L<perlipc/"UDP: Message Passing"> を参照してください。
1075012927
1075112928=begin original
1075212929
1075312930Note the I<characters>: depending on the status of the socket, either
1075412931(8-bit) bytes or characters are received. By default all sockets
1075512932operate on bytes, but for example if the socket has been changed using
10756binmode() to operate with the C<:encoding(utf8)> I/O layer (see the
12933L<C<binmode>|/binmode FILEHANDLE, LAYER> to operate with the
10757C<open> pragma, L<open>), the I/O will operate on UTF8-encoded Unicode
12934C<:encoding(utf8)> I/O layer (see the L<open> pragma), the I/O will
10758characters, not bytes. Similarly for the C<:encoding> pragma: in that
12935operate on UTF8-encoded Unicode
12936characters, not bytes. Similarly for the C<:encoding> layer: in that
1075912937case pretty much any characters can be read.
1076012938
1076112939=end original
1076212940
1076312941I<文字> に関する注意: ソケットの状態によって、(8 ビットの) バイトか
1076412942文字を受信します。
10765デフォルトでは全てのソケットはバイトを処理しますが、
12943デフォルトでは全てのソケットはバイトを処理しますが、例えばソケットが
10766例えばソケットが binmode() で C<:encoding(utf8)> I/O 層(C<open> プラグマ、
12944L<C<binmode>|/binmode FILEHANDLE, LAYER> で C<:encoding(utf8)> I/O 層
10767L<open> を参照してください) を使うように指定された場合、I/O はバイトではなく
12945(L<open> プラグマを参照してください) を使うように指定された場合、
10768UTF8 エンコードされた Unicode 文字を操作します。
12946I/O はバイトではなく、UTF8 エンコードされた Unicode 文字を操作します。
10769C<:encoding> プラグマも同様です:
12947C<:encoding> も同様です:
1077012948この場合、ほとんど大体全ての文字が読み込めます。
1077112949
1077212950=item redo LABEL
1077312951X<redo>
1077412952
12953=item redo EXPR
12954
1077512955=item redo
1077612956
12957=for Pod::Functions start this loop iteration over again
12958
1077712959=begin original
1077812960
10779The C<redo> command restarts the loop block without evaluating the
12961The L<C<redo>|/redo LABEL> command restarts the loop block without
10780conditional again. The C<continue> block, if any, is not executed. If
12962evaluating the conditional again. The L<C<continue>|/continue BLOCK>
12963block, if any, is not executed. If
1078112964the LABEL is omitted, the command refers to the innermost enclosing
10782loop. Programs that want to lie to themselves about what was just input
12965loop. The C<redo EXPR> form, available starting in Perl 5.18.0, allows a
12966label name to be computed at run time, and is otherwise identical to C<redo
12967LABEL>. Programs that want to lie to themselves about what was just input
1078312968normally use this command:
1078412969
1078512970=end original
1078612971
10787C<redo> コマンドは、条件を再評価しないで、ループブロックの始めからもう一度
12972L<C<redo>|/redo LABEL> コマンドは、条件を再評価しないで、ループブロックの
10788実行を開始します。
12973始めからもう一度実行を開始します。
10789C<continue> ブロックがあっても、実行されません。
12974L<C<continue>|/continue BLOCK> ブロックがあっても、実行されません。
10790LABEL が省略されると、このコマンドは、もっとも内側のループを参照します。
12975LABEL が省略されると、コマンドは一番内側のループを参照します。
12976Perl 5.18.0 から利用可能な C<redo EXPR> 形式では、実行時に計算されるラベル名が
12977使えます; それ以外は C<redo LABEL> と同一です。
1079112978このコマンドは通常、自分への入力を欺くために使用します:
1079212979
1079312980 # a simpleminded Pascal comment stripper
1079412981 # (warning: assumes no { or } in strings)
1079512982 LINE: while (<STDIN>) {
1079612983 while (s|({.*}.*){.*}|$1 |) {}
1079712984 s|{.*}| |;
1079812985 if (s|{.*| |) {
10799 $front = $_;
12986 my $front = $_;
1080012987 while (<STDIN>) {
1080112988 if (/}/) { # end of comment?
1080212989 s|^|$front\{|;
1080312990 redo LINE;
1080412991 }
1080512992 }
1080612993 }
1080712994 print;
1080812995 }
1080912996
1081012997=begin original
1081112998
10812C<redo> cannot be used to retry a block that returns a value such as
12999L<C<redo>|/redo LABEL> cannot be used to retry a block that returns a
10813C<eval {}>, C<sub {}>, or C<do {}>, and should not be used to exit
13000value such as C<eval {}>, C<sub {}>, or C<do {}>, and should not be used
10814a grep() or map() operation.
13001to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST>
13002operation.
1081513003
1081613004=end original
1081713005
10818C<redo> は C<eval {}>, C<sub {}>, C<do {}> のように値を返す
13006L<C<redo>|/redo LABEL> は C<eval {}>, C<sub {}>, C<do {}> のように値を返す
10819ブロックを繰り返すのには使えません
13007ブロックを繰り返すのには使えません; また、L<C<grep>|/grep BLOCK LIST> や
10820また、grep() や map() 操作から抜けるのに使うべきではありません。
13008L<C<map>|/map BLOCK LIST> 操作から抜けるのに使うべきではありません。
1082113009
1082213010=begin original
1082313011
1082413012Note that a block by itself is semantically identical to a loop
10825that executes once. Thus C<redo> inside such a block will effectively
13013that executes once. Thus L<C<redo>|/redo LABEL> inside such a block
10826turn it into a looping construct.
13014will effectively turn it into a looping construct.
1082713015
1082813016=end original
1082913017
1083013018ブロック自身は一回だけ実行されるループと文法的に同一であることに
1083113019注意してください。
10832従って、ブロックの中で C<redo> を使うことで効果的に
13020従って、ブロックの中で L<C<redo>|/redo LABEL> を使うことで効果的に
1083313021ループ構造に変換します。
1083413022
1083513023=begin original
1083613024
10837See also L</continue> for an illustration of how C<last>, C<next>, and
13025See also L<C<continue>|/continue BLOCK> for an illustration of how
10838C<redo> work.
13026L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and
13027L<C<redo>|/redo LABEL> work.
1083913028
1084013029=end original
1084113030
10842C<last>, C<next>, C<redo> がどのように働くかについては
13031L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL>
10843L</continue> も参照してさい。
13032どのように働くかについては L<C<continue>|/continue BLOCK> も参照してください。
1084413033
13034=begin original
13035
13036Unlike most named operators, this has the same precedence as assignment.
13037It is also exempt from the looks-like-a-function rule, so
13038C<redo ("foo")."bar"> will cause "bar" to be part of the argument to
13039L<C<redo>|/redo LABEL>.
13040
13041=end original
13042
13043ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
13044また、関数のように見えるものの規則からも免れるので、C<redo ("foo")."bar"> と
13045すると "bar" は L<C<redo>|/redo LABEL> への引数の一部となります。
13046
1084513047=item ref EXPR
1084613048X<ref> X<reference>
1084713049
1084813050=item ref
1084913051
13052=for Pod::Functions find out the type of thing being referenced
13053
1085013054=begin original
1085113055
1085213056Returns a non-empty string if EXPR is a reference, the empty
10853string otherwise. If EXPR
13057string otherwise. If EXPR is not specified, L<C<$_>|perlvar/$_> will be
10854is not specified, C<$_> will be used. The value returned depends on the
13058used. The value returned depends on the type of thing the reference is
10855type of thing the reference is a reference to.
13059a reference to.
10856Builtin types include:
1085713060
1085813061=end original
1085913062
1086013063EXPR がリファレンスであれば、空でない文字列を返し、さもなくば、
1086113064空文字列を返します。
10862EXPR が指定されなければ、C<$_> が使われます。
13065EXPR が指定されなければ、L<C<$_>|perlvar/$_> が使われます。
1086313066返される値は、リファレンスが参照するものの型に依存します。
13067
13068=begin original
13069
13070Builtin types include:
13071
13072=end original
13073
1086413074組み込みの型には、以下のものがあります。
1086513075
1086613076 SCALAR
1086713077 ARRAY
1086813078 HASH
1086913079 CODE
1087013080 REF
1087113081 GLOB
1087213082 LVALUE
1087313083 FORMAT
1087413084 IO
1087513085 VSTRING
1087613086 Regexp
1087713087
1087813088=begin original
1087913089
10880If the referenced object has been blessed into a package, then that package
13090You can think of L<C<ref>|/ref EXPR> as a C<typeof> operator.
10881name is returned instead. You can think of C<ref> as a C<typeof> operator.
1088213091
1088313092=end original
1088413093
10885参照されるオブジェクトが何らかパッケージ
13094L<C<ref>|/ref EXPR> はC<typeof> 演算子よう考えることができます。
10886bless されたものであれば、これらの代わりに、
10887そのパッケージ名が返されます。
10888C<ref> は、C<typeof> 演算子のように考えることができます。
1088913095
1089013096 if (ref($r) eq "HASH") {
1089113097 print "r is a reference to a hash.\n";
1089213098 }
1089313099 unless (ref($r)) {
1089413100 print "r is not a reference at all.\n";
1089513101 }
1089613102
1089713103=begin original
1089813104
1089913105The return value C<LVALUE> indicates a reference to an lvalue that is not
10900a variable. You get this from taking the reference of function calls like
13106a variable. You get this from taking the reference of function calls like
10901C<pos()> or C<substr()>. C<VSTRING> is returned if the reference points
13107L<C<pos>|/pos SCALAR> or
10902to a L<version string|perldata/"Version Strings">.
13108L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT>. C<VSTRING> is
13109returned if the reference points to a
13110L<version string|perldata/"Version Strings">.
1090313111
1090413112=end original
1090513113
1090613114返り値 C<LVALUE> は、変数ではない左辺値へのリファレンスを示します。
10907これは、C<pos()> C<substr()> のようの関数呼び出しのリファレンスから
13115これは、L<C<pos>|/pos SCALAR>
10908得られます。
13116L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> のような関数呼び出しの
13117リファレンスから得られます。
1090913118C<VSTRING> は、リファレンスが L<version string|perldata/"Version Strings"> を
1091013119指している場合に返されます。
1091113120
1091213121=begin original
1091313122
1091413123The result C<Regexp> indicates that the argument is a regular expression
10915resulting from C<qr//>.
13124resulting from L<C<qrE<sol>E<sol>>|/qrE<sol>STRINGE<sol>>.
1091613125
1091713126=end original
1091813127
10919C<Regexp> という結果は、引数が C<qr//> からの結果である
13128C<Regexp> という結果は、引数が
13129L<C<qrE<sol>E<sol>>|/qrE<sol>STRINGE<sol>> からの結果である
1092013130正規表現であることを意味します。
1092113131
1092213132=begin original
1092313133
13134If the referenced object has been blessed into a package, then that package
13135name is returned instead. But don't use that, as it's now considered
13136"bad practice". For one reason, an object could be using a class called
13137C<Regexp> or C<IO>, or even C<HASH>. Also, L<C<ref>|/ref EXPR> doesn't
13138take into account subclasses, like
13139L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>> does.
13140
13141=end original
13142
13143参照されるオブジェクトが、何らかのパッケージに bless されたものであれば、
13144これらの代わりに、そのパッケージ名が返されます。
13145しかし、これは今では「悪い習慣」と考えられているので、しないでください。
13146理由の一つは、オブジェクトは C<Regexp>, C<IO> や C<HASH> などと呼ばれる
13147クラスを使うかも知れないからです。
13148また、L<C<ref>|/ref EXPR> は
13149L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>> のようにサブクラスを
13150考慮したりはしません。
13151
13152=begin original
13153
13154Instead, use L<C<blessed>|Scalar::Util/blessed> (in the L<Scalar::Util>
13155module) for boolean checks, L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>>
13156for specific class checks and L<C<reftype>|Scalar::Util/reftype> (also
13157from L<Scalar::Util>) for type checks. (See L<perlobj> for details and
13158a L<C<blessed>|Scalar::Util/blessed>/L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>>
13159example.)
13160
13161=end original
13162
13163代わりに、真偽値チェックには (L<Scalar::Util> モジュールにある)
13164L<C<blessed>|Scalar::Util/blessed> を、特定のクラスのチェックには
13165L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>> を、型のチェックには
13166(これも L<Scalar::Util> にある) L<C<reftype>|Scalar::Util/reftype> を
13167使ってください。
13168(詳細と L<C<blessed>|Scalar::Util/blessed>/
13169L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>> の例については
13170L<perlobj> を参照してください。)
13171
13172=begin original
13173
1092413174See also L<perlref>.
1092513175
1092613176=end original
1092713177
1092813178L<perlref> も参照してください。
1092913179
1093013180=item rename OLDNAME,NEWNAME
1093113181X<rename> X<move> X<mv> X<ren>
1093213182
13183=for Pod::Functions change a filename
13184
1093313185=begin original
1093413186
1093513187Changes the name of a file; an existing file NEWNAME will be
1093613188clobbered. Returns true for success, false otherwise.
1093713189
1093813190=end original
1093913191
10940ファイルの名前を変更します
13192ファイルの名前を変更します; NEWNAME というファイルが既に存在した場合、
10941NEWNAME というファイルが既に存在した場合、上書きされるかもしれません。
13193上書きされるかもしれません。
10942成功時には真、失敗時には偽を返します。
13194成功時には真さもなければ偽を返します。
1094313195
1094413196=begin original
1094513197
1094613198Behavior of this function varies wildly depending on your system
1094713199implementation. For example, it will usually not work across file system
1094813200boundaries, even though the system I<mv> command sometimes compensates
1094913201for this. Other restrictions include whether it works on directories,
1095013202open files, or pre-existing files. Check L<perlport> and either the
10951rename(2) manpage or equivalent system documentation for details.
13203L<rename(2)> manpage or equivalent system documentation for details.
1095213204
1095313205=end original
1095413206
1095513207この関数の振る舞いはシステムの実装に大きく依存して異なります。
10956普通はファイルシステムにまたがってパス名を付け替えることはできません
13208例えば、普通はファイルシステムにまたがってパス名を付け替えることはできません;
1095713209システムの I<mv> がこれを補完している場合でもそうです。
1095813210その他の制限には、ディレクトリ、オープンしているファイル、既に存在している
1095913211ファイルに対して使えるか、といったことを含みます。
10960詳しくは、L<perlport> および rename(2) man ページあるいは同様の
13212詳しくは、L<perlport> および L<rename(2)> man ページあるいは同様の
1096113213システムドキュメントを参照してください。
1096213214
1096313215=begin original
1096413216
10965For a platform independent C<move> function look at the L<File::Copy>
13217For a platform independent L<C<move>|File::Copy/move> function look at
10966module.
13218the L<File::Copy> module.
1096713219
1096813220=end original
1096913221
10970プラットフォームに依存しない C<move> 関数については L<File::Copy> モジュールを
13222プラットフォームに依存しない L<C<move>|File::Copy/move> 関数については
10971参照してください。
13223L<File::Copy> モジュールを参照してください。
1097213224
13225=begin original
13226
13227Portability issues: L<perlport/rename>.
13228
13229=end original
13230
13231移植性の問題: L<perlport/rename>。
13232
1097313233=item require VERSION
1097413234X<require>
1097513235
1097613236=item require EXPR
1097713237
1097813238=item require
1097913239
13240=for Pod::Functions load in external functions from a library at runtime
13241
1098013242=begin original
1098113243
1098213244Demands a version of Perl specified by VERSION, or demands some semantics
10983specified by EXPR or by C<$_> if EXPR is not supplied.
13245specified by EXPR or by L<C<$_>|perlvar/$_> if EXPR is not supplied.
1098413246
1098513247=end original
1098613248
1098713249VERSION で指定される Perl のバージョンを要求するか、
10988EXPR (省略時には C<$_>) によって指定されるいくつかの動作を要求します。
13250EXPR (省略時には L<C<$_>|perlvar/$_>) によって指定されるいくつかの動作を
13251要求します。
1098913252
1099013253=begin original
1099113254
1099213255VERSION may be either a numeric argument such as 5.006, which will be
10993compared to C<$]>, or a literal of the form v5.6.1, which will be compared
13256compared to L<C<$]>|perlvar/$]>, or a literal of the form v5.6.1, which
10994to C<$^V> (aka $PERL_VERSION). An exception is raised if
13257will be compared to L<C<$^V>|perlvar/$^V> (or C<$PERL_VERSION> in
10995VERSION is greater than the version of the current Perl interpreter.
13258L<English>). An exception is raised if VERSION is greater than the
10996Compare with L</use>, which can do a similar check at compile time.
13259version of the current Perl interpreter. Compare with
13260L<C<use>|/use Module VERSION LIST>, which can do a similar check at
13261compile time.
1099713262
1099813263=end original
1099913264
11000VERSION は 5.006 のような数値(C<$]> と比較されます)か、v5.6.1 の形
13265VERSION は 5.006 のような数値(L<C<$]>|perlvar/$]> と比較されます)か、
11001(C<$^V> (またの名を $PERL_VERSION) と比較されます)指定します。
13266v5.6.1 の形 (L<C<$^V>|perlvar/$^V> (また L<English> モジュール
13267C<$PERL_VERSION>) と比較されます)で指定します。
1100213268VERSION が Perl の現在のバージョンより大きいと、例外が発生します。
11003L</use> と似ていますが、これはコンパイル時にチェックされます。
13269L<C<use>|/use Module VERSION LIST> と似ていますが、これはコンパイル時に
13270チェックされます。
1100413271
1100513272=begin original
1100613273
1100713274Specifying VERSION as a literal of the form v5.6.1 should generally be
1100813275avoided, because it leads to misleading error messages under earlier
1100913276versions of Perl that do not support this syntax. The equivalent numeric
1101013277version should be used instead.
1101113278
1101213279=end original
1101313280
1101413281VERSION に v5.6.1 の形のリテラルを指定することは一般的には避けるべきです;
1101513282なぜなら、この文法に対応していない Perl の初期のバージョンでは
1101613283誤解させるようなエラーメッセージが出るからです。
1101713284代わりに等価な数値表現を使うべきです。
1101813285
1101913286=begin original
1102013287
1102113288 require v5.6.1; # run time version check
1102213289 require 5.6.1; # ditto
11023 require 5.006_001; # ditto; preferred for backwards compatibility
13290 require 5.006_001; # ditto; preferred for backwards
13291 compatibility
1102413292
1102513293=end original
1102613294
1102713295 require v5.6.1; # 実行時バージョンチェック
1102813296 require 5.6.1; # 同様
1102913297 require 5.006_001; # 同様; 後方互換性のためには望ましい
1103013298
1103113299=begin original
1103213300
11033Otherwise, C<require> demands that a library file be included if it
13301Otherwise, L<C<require>|/require VERSION> demands that a library file be
11034hasn't already been included. The file is included via the do-FILE
13302included if it hasn't already been included. The file is included via
11035mechanism, which is essentially just a variety of C<eval> with the
13303the do-FILE mechanism, which is essentially just a variety of
13304L<C<eval>|/eval EXPR> with the
1103613305caveat that lexical variables in the invoking script will be invisible
11037to the included code. Has semantics similar to the following subroutine:
13306to the included code. If it were implemented in pure Perl, it
13307would have semantics similar to the following:
1103813308
1103913309=end original
1104013310
11041それ以外の場合には、C<require> は、既に読み込まれていないときに読み込む
13311それ以外の場合には、L<C<require>|/require VERSION> は、既に
11042ライブラリファイルを要求するものとなります。
13312読み込まれていないときに読み込むライブラリファイルを要求するものとなります。
11043そのファイルは、基本的には C<eval> の一種である、do-FILE によって
13313そのファイルは、基本的には L<C<eval>|/eval EXPR> の一種である、
11044読み込まれますが、起動したスクリプトのレキシカル変数は読み込まれたコードから
13314do-FILE によって読み込まれますが、起動したスクリプトのレキシカル変数は
11045見えないという欠点があります。
13315読み込まれたコードから見えないという欠点があります。
11046意味的には、次のようなサブルーチンと同じようなものです:
13316ピュア Perl で実装した場合、意味的には、次のようなサブルーチンと
13317同じようなものです:
1104713318
13319 use Carp 'croak';
13320 use version;
13321
1104813322 sub require {
11049 my ($filename) = @_;
13323 my ($filename) = @_;
11050 if (exists $INC{$filename}) {
13324 if ( my $version = eval { version->parse($filename) } ) {
11051 return 1 if $INC{$filename};
13325 if ( $version > $^V ) {
11052 die "Compilation failed in require";
13326 my $vn = $version->normal;
11053 }
13327 croak "Perl $vn required--this is only $^V, stopped";
11054 my ($realfilename,$result);
13328 }
11055 ITER: {
13329 return 1;
11056 foreach $prefix (@INC) {
13330 }
11057 $realfilename = "$prefix/$filename";
11058 if (-f $realfilename) {
13332 if (exists $INC{$filename}) {
11059 $INC{$filename} = $realfilename;
13333 return 1 if $INC{$filename};
11060 $result = do $realfilename;
13334 croak "Compilation failed in require";
11061 last ITER;
13335 }
11062 }
11063 }
13337 foreach $prefix (@INC) {
11064 die "Can't find $filename in \@INC";
13338 if (ref($prefix)) {
11065 }
13339 #... do other stuff - see text below ....
11066 if ($@) {
13340 }
11067 $INC{$filename} = undef;
13341 # (see text below about possible appending of .pmc
11068 die $@;
13342 # suffix to $filename)
11069 } elsif (!$result) {
13343 my $realfilename = "$prefix/$filename";
11070 delete $INC{$filename};
13344 next if ! -e $realfilename || -d _ || -b _;
11071 die "$filename did not return true value";
13345 $INC{$filename} = $realfilename;
11072 } else {
13346 my $result = do($realfilename);
11073 return $result;
13347 # but run in caller's namespace
11074 }
13349 if (!defined $result) {
13350 $INC{$filename} = undef;
13351 croak $@ ? "$@Compilation failed in require"
13352 : "Can't locate $filename: $!\n";
13353 }
13354 if (!$result) {
13355 delete $INC{$filename};
13356 croak "$filename did not return true value";
13357 }
13358 $! = 0;
13359 return $result;
13360 }
13361 croak "Can't locate $filename in \@INC ...";
1107513362 }
1107613363
1107713364=begin original
1107813365
1107913366Note that the file will not be included twice under the same specified
1108013367name.
1108113368
1108213369=end original
1108313370
1108413371ファイルは、同じ名前で 2 回読み込まれることはないことに注意してください。
1108513372
1108613373=begin original
1108713374
1108813375The file must return true as the last statement to indicate
1108913376successful execution of any initialization code, so it's customary to
1109013377end such a file with C<1;> unless you're sure it'll return true
1109113378otherwise. But it's better just to put the C<1;>, in case you add more
1109213379statements.
1109313380
1109413381=end original
1109513382
11096初期化コードの実行がうまくいったことを示すために、
13383初期化コードの実行がうまくいったことを示すために、ファイルは真を
11097ファイルは真を返さなければなりませんから、
13384返さなければならないので、真を返すようになっている自信がある場合を除いては
11098真を返すようになっている自信がある場合を除いては、
1109913385ファイルの最後に C<1;> と書くのが習慣です。
11100実行文を追加するような場合に備えて、C<1;> と書いておいた方が
13386しかし、実行文を追加するような場合に備えて、C<1;> と書いておいた方が良いです。
11101良いでしょう。
1110213387
1110313388=begin original
1110413389
11105If EXPR is a bareword, the require assumes a "F<.pm>" extension and
13390If EXPR is a bareword, L<C<require>|/require VERSION> assumes a F<.pm>
11106replaces "F<::>" with "F</>" in the filename for you,
13391extension and replaces C<::> with C</> in the filename for you,
1110713392to make it easy to load standard modules. This form of loading of
1110813393modules does not risk altering your namespace.
1110913394
1111013395=end original
1111113396
11112EXPR が裸の単語であるときには、標準モジュールのロードを
13397EXPR が裸の単語であるときには、標準モジュールのロードを簡単にするように、
11113簡単にするように、require は拡張子が "F<.pm>" であり、
13398L<C<require>|/require VERSION> は拡張子が F<.pm> であり、C<::> を C</> に
11114"F<::>" を "F</>" に変えたものがファイル名であると仮定します。
13399変えたものがファイル名であると仮定します。
11115この形式のモジュールロードは、
13400この形式のモジュールロードは、名前空間を変更してしまう危険はありません。
11116名前空間を変更してしまう危険はありません。
1111713401
1111813402=begin original
1111913403
1112013404In other words, if you try this:
1112113405
1112213406=end original
1112313407
1112413408言い換えると、以下のようにすると:
1112513409
1112613410 require Foo::Bar; # a splendid bareword
1112713411
1112813412=begin original
1112913413
11130The require function will actually look for the "F<Foo/Bar.pm>" file in the
13414The require function will actually look for the F<Foo/Bar.pm> file in the
11131directories specified in the C<@INC> array.
13415directories specified in the L<C<@INC>|perlvar/@INC> array.
1113213416
1113313417=end original
1113413418
11135require 関数は C<@INC> 配列で指定されたディレクトリにある
13419require 関数は L<C<@INC>|perlvar/@INC> 配列で指定されたディレクトリにある
11136"F<Foo/Bar.pm>" ファイルを探します。
13420F<Foo/Bar.pm> ファイルを探します。
1113713421
1113813422=begin original
1113913423
1114013424But if you try this:
1114113425
1114213426=end original
1114313427
1114413428しかし、以下のようにすると:
1114513429
11146 $class = 'Foo::Bar';
13430 my $class = 'Foo::Bar';
1114713431 require $class; # $class is not a bareword
1114813432 #or
1114913433 require "Foo::Bar"; # not a bareword because of the ""
1115013434
1115113435=begin original
1115213436
11153The require function will look for the "F<Foo::Bar>" file in the @INC array and
13437The require function will look for the F<Foo::Bar> file in the
11154will complain about not finding "F<Foo::Bar>" there. In this case you can do:
13438L<C<@INC>|perlvar/@INC> array and
13439will complain about not finding F<Foo::Bar> there. In this case you can do:
1115513440
1115613441=end original
1115713442
11158require 関数は @INC 配列の "F<Foo::Bar>" ファイルを探し、
13443require 関数は L<C<@INC>|perlvar/@INC> 配列の F<Foo::Bar> ファイルを探し、
11159おそらくそこに "F<Foo::Bar>" がないと文句をいうことになるでしょう。
13444おそらくそこに F<Foo::Bar> がないと文句をいうことになるでしょう。
1116013445このような場合には、以下のようにします:
1116113446
1116213447 eval "require $class";
1116313448
1116413449=begin original
1116513450
11166Now that you understand how C<require> looks for files with a
13451Now that you understand how L<C<require>|/require VERSION> looks for
11167bareword argument, there is a little extra functionality going on behind
13452files with a bareword argument, there is a little extra functionality
11168the scenes. Before C<require> looks for a "F<.pm>" extension, it will
13453going on behind the scenes. Before L<C<require>|/require VERSION> looks
11169first look for a similar filename with a "F<.pmc>" extension. If this file
13454for a F<.pm> extension, it will first look for a similar filename with a
11170is found, it will be loaded in place of any file ending in a "F<.pm>"
13455F<.pmc> extension. If this file is found, it will be loaded in place of
11171extension.
13456any file ending in a F<.pm> extension.
1117213457
1117313458=end original
1117413459
11175引数が裸の単語の場合、C<require> がどのようにファイルを探すか
13460引数が裸の単語の場合、L<C<require>|/require VERSION> がどのようにファイルを
11176理解してください; 水面下でちょっとした追加の機能があります。
13461探すかを理解してください; 水面下でちょっとした追加の機能があります。
11177C<require> が拡張子 "F<.pm>" のファイルを探す前に、まず拡張子 "F<.pmc>" を
13462L<C<require>|/require VERSION> が拡張子 F<.pm> のファイルを探す前に、まず
11178持つファイルを探します。
13463拡張子 F<.pmc> を持つファイルを探します。
11179このファイルが見つかると、このファイルが拡張子 "F<.pm>" の代わりに
13464このファイルが見つかると、このファイルが拡張子 F<.pm> の代わりに
1118013465読み込まれます。
1118113466
1118213467=begin original
1118313468
1118413469You can also insert hooks into the import facility by putting Perl code
11185directly into the @INC array. There are three forms of hooks: subroutine
13470directly into the L<C<@INC>|perlvar/@INC> array. There are three forms
11186references, array references, and blessed objects.
13471of hooks: subroutine references, array references, and blessed objects.
1118713472
1118813473=end original
1118913474
11190@INC 配列に直接 Perl コードを入れることで、インポート機能にフックを
13475L<C<@INC>|perlvar/@INC> 配列に直接 Perl コードを入れることで、インポート機能に
11191挿入できます。
13476フックを挿入できます。
11192134773 種類のフックがあります: サブルーチンリファレンス、配列リファレンス、
1119313478bless されたオブジェクトです。
1119413479
1119513480=begin original
1119613481
1119713482Subroutine references are the simplest case. When the inclusion system
11198walks through @INC and encounters a subroutine, this subroutine gets
13483walks through L<C<@INC>|perlvar/@INC> and encounters a subroutine, this
11199called with two parameters, the first a reference to itself, and the
13484subroutine gets called with two parameters, the first a reference to
11200second the name of the file to be included (e.g., "F<Foo/Bar.pm>"). The
13485itself, and the second the name of the file to be included (e.g.,
11201subroutine should return either nothing or else a list of up to three
13486F<Foo/Bar.pm>). The subroutine should return either nothing or else a
11202values in the following order:
13487list of up to four values in the following order:
1120313488
1120413489=end original
1120513490
1120613491サブルーチンへのリファレンスは一番単純な場合です。
11207インクルード機能が @INC を走査してサブルーチンに出会った場合、この
13492インクルード機能が L<C<@INC>|perlvar/@INC> を走査してサブルーチンに
11208サブルーチンは二つの引数と共に呼び出されます;
13493出会った場合、このサブルーチンは二つの引数と共に呼び出されます;
1120913494一つ目は自身へのリファレンス、二つ目はインクルードされるファイル名
11210("F<Foo/Bar.pm>" など)です。
13495(F<Foo/Bar.pm> など)です。
11211サブルーチンは何も返さないか、以下の順で最大つの値のリストを
13496サブルーチンは何も返さないか、以下の順で最大つの値のリストを返します。
11212返します。
1121313497
1121413498=over
1121513499
1121613500=item 1
1121713501
1121813502=begin original
1121913503
11220A filehandle, from which the file will be read.
13504A reference to a scalar, containing any initial source code to prepend to
13505the file or generator output.
1122113506
1122213507=end original
1122313508
11224ファイルが読み込まれるファイルハンル。
13509ファイルやジェネレータの出力の前に追加される初期化ソースコーを含む
13510スカラへのリファレンス。
1122513511
1122613512=item 2
1122713513
1122813514=begin original
1122913515
11230A reference to a subroutine. If there is no filehandle (previous item),
13516A filehandle, from which the file will be read.
13517
13518=end original
13519
13520ファイルが読み込まれるファイルハンドル。
13521
13522=item 3
13523
13524=begin original
13525
13526A reference to a subroutine. If there is no filehandle (previous item),
1123113527then this subroutine is expected to generate one line of source code per
11232call, writing the line into C<$_> and returning 1, then finally at end of
13528call, writing the line into L<C<$_>|perlvar/$_> and returning 1, then
11233file returning 0. If there is a filehandle, then the subroutine will be
13529finally at end of file returning 0. If there is a filehandle, then the
11234called to act as a simple source filter, with the line as read in C<$_>.
13530subroutine will be called to act as a simple source filter, with the
13531line as read in L<C<$_>|perlvar/$_>.
1123513532Again, return 1 for each valid line, and 0 after all lines have been
1123613533returned.
1123713534
1123813535=end original
1123913536
1124013537サブルーチンへのリファレンス。
11241(一つ前のアイテムである)ファイルハンドルがない場合、
13538(一つ前のアイテムである)ファイルハンドルがない場合、サブルーチンは呼び出し毎に
11242サブルーチンは呼び出し毎に一行のソースコードを生成し、その行を C<$_> に
13539一行のソースコードを生成し、その行を L<C<$_>|perlvar/$_>書き込んで 1 を
11243書き込んで 1 を返し、それから最終的にファイル終端で 0 を返すものと
13540返し、それから最終的にファイル終端で 0 を返すものと想定されます。
11244想定されます。
1124513541ファイルハンドルがある場合、サブルーチンは単純なソースフィルタとして
11246振舞うように呼び出され、行は C<$_> から読み込まれます。
13542振舞うように呼び出され、行は L<C<$_>|perlvar/$_> から読み込まれます。
1124713543再び、有効な行ごとに 1 を返し、全ての行を返した後では 0 を返します。
1124813544
11249=item 3
13545=item 4
1125013546
1125113547=begin original
1125213548
11253Optional state for the subroutine. The state is passed in as C<$_[1]>. A
13549Optional state for the subroutine. The state is passed in as C<$_[1]>. A
1125413550reference to the subroutine itself is passed in as C<$_[0]>.
1125513551
1125613552=end original
1125713553
1125813554サブルーチンのための状態(オプション)。
1125913555状態は C<$_[1]> として渡されます。
1126013556サブルーチンへのリファレンス自身は C<$_[0]> として渡されます。
1126113557
1126213558=back
1126313559
1126413560=begin original
1126513561
11266If an empty list, C<undef>, or nothing that matches the first 3 values above
13562If an empty list, L<C<undef>|/undef EXPR>, or nothing that matches the
11267is returned, then C<require> looks at the remaining elements of @INC.
13563first 3 values above is returned, then L<C<require>|/require VERSION>
13564looks at the remaining elements of L<C<@INC>|perlvar/@INC>.
1126813565Note that this filehandle must be a real filehandle (strictly a typeglob
11269or reference to a typeglob, whether blessed or unblessed); tied filehandles
13566or reference to a typeglob, whether blessed or unblessed); tied filehandles
1127013567will be ignored and processing will stop there.
1127113568
1127213569=end original
1127313570
11274空リスト、C<undef>、または上記の最初の三つの値のどれとも一致しないものが
13571空リスト、L<C<undef>|/undef EXPR>、または上記の最初の三つの値のどれとも
11275返されると、C<require> は @INC の残りの要素を見ます。
13572一致しないものが返されると、L<C<require>|/require VERSION>
13573L<C<@INC>|perlvar/@INC> の残りの要素を見ます。
1127613574このファイルハンドルは実際のファイルハンドル(厳密には型グロブ、型グロブへの
1127713575リファレンス、bless されているかに関わらず)でなければなりません;
1127813576tie されたファイルハンドルは無視され、返り値の処理はそこで停止します。
1127913577
1128013578=begin original
1128113579
1128213580If the hook is an array reference, its first element must be a subroutine
1128313581reference. This subroutine is called as above, but the first parameter is
1128413582the array reference. This lets you indirectly pass arguments to
1128513583the subroutine.
1128613584
1128713585=end original
1128813586
1128913587フックが配列のリファレンスの場合、その最初の要素はサブルーチンへの
1129013588リファレンスでなければなりません。
1129113589このサブルーチンは上述のように呼び出されますが、その最初の引数は
1129213590配列のリファレンスです。
1129313591これによって、間接的にサブルーチンに引数を渡すことが出来ます。
1129413592
1129513593=begin original
1129613594
1129713595In other words, you can write:
1129813596
1129913597=end original
1130013598
1130113599言い換えると、以下のように書いたり:
1130213600
1130313601 push @INC, \&my_sub;
1130413602 sub my_sub {
1130513603 my ($coderef, $filename) = @_; # $coderef is \&my_sub
1130613604 ...
1130713605 }
1130813606
1130913607=begin original
1131013608
1131113609or:
1131213610
1131313611=end original
1131413612
1131513613または以下のように書けます:
1131613614
1131713615 push @INC, [ \&my_sub, $x, $y, ... ];
1131813616 sub my_sub {
1131913617 my ($arrayref, $filename) = @_;
1132013618 # Retrieve $x, $y, ...
11321 my @parameters = @$arrayref[1..$#$arrayref];
13619 my (undef, @parameters) = @$arrayref;
1132213620 ...
1132313621 }
1132413622
1132513623=begin original
1132613624
11327If the hook is an object, it must provide an INC method that will be
13625If the hook is an object, it must provide an C<INC> method that will be
1132813626called as above, the first parameter being the object itself. (Note that
1132913627you must fully qualify the sub's name, as unqualified C<INC> is always forced
1133013628into package C<main>.) Here is a typical code layout:
1133113629
1133213630=end original
1133313631
11334フックがオブジェクトの場合、INC メソッドを提供している必要があります;
13632フックがオブジェクトの場合、C<INC> メソッドを提供している必要があります;
1133513633それが、最初の引数をオブジェクト自身として上述のように呼び出されます。
1133613634(修飾されていない C<INC> は常にパッケージ C<main> に強制されるため、
1133713635サブルーチン名は完全修飾する必要があることに注意してください。)
1133813636以下は典型的なコードレイアウトです:
1133913637
1134013638 # In Foo.pm
1134113639 package Foo;
1134213640 sub new { ... }
1134313641 sub Foo::INC {
1134413642 my ($self, $filename) = @_;
1134513643 ...
1134613644 }
1134713645
1134813646 # In the main program
1134913647 push @INC, Foo->new(...);
1135013648
1135113649=begin original
1135213650
11353These hooks are also permitted to set the %INC entry
13651These hooks are also permitted to set the L<C<%INC>|perlvar/%INC> entry
11354corresponding to the files they have loaded. See L<perlvar/%INC>.
13652corresponding to the files they have loaded. See L<perlvar/%INC>.
1135513653
1135613654=end original
1135713655
11358これらのフックは、読み込まれるファイルに対応する %INC エントリを
13656これらのフックは、読み込まれるファイルに対応する
11359セットすることも許可します。
13657L<C<%INC>|perlvar/%INC> エントリをセットすることも許可します。
1136013658L<perlvar/%INC> を参照してください。
1136113659
1136213660=begin original
1136313661
11364For a yet-more-powerful import facility, see L</use> and L<perlmod>.
13662For a yet-more-powerful import facility, see
13663L<C<use>|/use Module VERSION LIST> and L<perlmod>.
1136513664
1136613665=end original
1136713666
1136813667より強力な import 機能については、このドキュメントの
11369L</use> の項と、L<perlmod> を参照してください。
13668L<C<use>|/use Module VERSION LIST> の項と、L<perlmod> を参照してください。
1137013669
1137113670=item reset EXPR
1137213671X<reset>
1137313672
1137413673=item reset
1137513674
13675=for Pod::Functions clear all variables of a given name
13676
1137613677=begin original
1137713678
11378Generally used in a C<continue> block at the end of a loop to clear
13679Generally used in a L<C<continue>|/continue BLOCK> block at the end of a
11379variables and reset C<??> searches so that they work again. The
13680loop to clear variables and reset C<m?pattern?> searches so that they
13681work again. The
1138013682expression is interpreted as a list of single characters (hyphens
1138113683allowed for ranges). All variables and arrays beginning with one of
1138213684those letters are reset to their pristine state. If the expression is
11383omitted, one-match searches (C<?pattern?>) are reset to match again.
13685omitted, one-match searches (C<m?pattern?>) are reset to match again.
1138413686Only resets variables or searches in the current package. Always returns
11385136871. Examples:
1138613688
1138713689=end original
1138813690
11389通常、ループの最後に、変数をクリアし、C<??> 検索を再び
13691通常、ループの最後に、変数をクリアし、C<m?pattern?> 検索を再び動作するように
11390動作するようにリセットするため、C<continue> ブロックで使われます。
13692リセットするため、L<C<continue>|/continue BLOCK> ブロックで使われます。
1139113693EXPR は、文字を並べたもの (範囲を指定するのに、ハイフンが使えます) と
1139213694解釈されます。
1139313695名前がその文字のいずれかで始まる変数や配列は、
1139413696最初の状態にリセットされます。
11395EXPR を省略すると、1 回検索 (C<?PATTERN?>) を再びマッチするように
13697EXPR を省略すると、1 回検索 (C<m?pattern?>) を再びマッチするように
1139613698リセットできます。
1139713699カレントパッケージの変数もしくは検索だけがリセットされます。
1139813700常に 1 を返します。
1139913701例:
1140013702
1140113703 reset 'X'; # reset all X variables
1140213704 reset 'a-z'; # reset lower case variables
11403 reset; # just reset ?one-time? searches
13705 reset; # just reset m?one-time? searches
1140413706
1140513707=begin original
1140613708
1140713709Resetting C<"A-Z"> is not recommended because you'll wipe out your
11408C<@ARGV> and C<@INC> arrays and your C<%ENV> hash. Resets only package
13710L<C<@ARGV>|perlvar/@ARGV> and L<C<@INC>|perlvar/@INC> arrays and your
11409variables; lexical variables are unaffected, but they clean themselves
13711L<C<%ENV>|perlvar/%ENV> hash.
11410up on scope exit anyway, so you'll probably want to use them instead.
13712Resets only package variables; lexical variables are unaffected, but
11411See L</my>.
13713they clean themselves up on scope exit anyway, so you'll probably want
13714to use them instead. See L<C<my>|/my VARLIST>.
1141213715
1141313716=end original
1141413717
11415reset C<"A-Z"> とすると、C<@ARGV>, C<@INC> 配列や C<%ENV> ハッシュも
13718reset C<"A-Z"> とすると、L<C<@ARGV>|perlvar/@ARGV>,
11416なくなってしまいますから、止めた方が良いでしょう。
13719L<C<@INC>|perlvar/@INC> 配列や L<C<%ENV>|perlvar/%ENV> ハッシュも
11417パッケージ変数だけがリセットされす;
13720なくなってしうので、止めた方が良いでしょう。
11418レキシカル変数は影響を受けませんが、スコープから外れれば
13721パッケージ変数だけがリセットされます; レキシカル変数は影響を受けませんが、
11419自動的に綺麗になりますので、これからはこちらを使うようにした方が
13722スコープから外れれば自動的に綺麗になので、これからはこちらを
11420よいでしょう。
13723使うようにした方がよいでしょう。
11421L</my> を参照してください。
13724L<C<my>|/my VARLIST> を参照してください。
1142213725
1142313726=item return EXPR
1142413727X<return>
1142513728
1142613729=item return
1142713730
13731=for Pod::Functions get out of a function early
13732
1142813733=begin original
1142913734
11430Returns from a subroutine, C<eval>, or C<do FILE> with the value
13735Returns from a subroutine, L<C<eval>|/eval EXPR>,
13736L<C<do FILE>|/do EXPR>, L<C<sort>|/sort SUBNAME LIST> block or regex
13737eval block (but not a L<C<grep>|/grep BLOCK LIST> or
13738L<C<map>|/map BLOCK LIST> block) with the value
1143113739given in EXPR. Evaluation of EXPR may be in list, scalar, or void
1143213740context, depending on how the return value will be used, and the context
11433may vary from one execution to the next (see C<wantarray>). If no EXPR
13741may vary from one execution to the next (see
13742L<C<wantarray>|/wantarray>). If no EXPR
1143413743is given, returns an empty list in list context, the undefined value in
1143513744scalar context, and (of course) nothing at all in void context.
1143613745
1143713746=end original
1143813747
11439サブルーチン, C<eval>, C<do FILE> から EXPR で与えられた値をもって、
13748サブルーチン, L<C<eval>|/eval EXPR>, L<C<do FILE>|/do EXPR>,
11440リターンしす。
13749L<C<sort>|/sort SUBNAME LIST> ブロックたは正規表現 eval ブロック
11441EXPR の評価は、返り値がどのように使われるかによって
13750(但し L<C<grep>|/grep BLOCK LIST> や
11442リスト、スカラ、無効コンテキストにります。
13751L<C<map>|/map BLOCK LIST> ブロックではい) から
11443テキストは実行毎に変わります(C<wantarray> を参照してください)
13752EXPR で与えられ値をもって、リターます。
13753EXPR の評価は、返り値がどのように使われるかによってリスト、スカラ、
13754無効コンテキストになります; またコンテキストは実行毎に変わります
13755(L<C<wantarray>|/wantarray> を参照してください)。
1144413756EXPR が指定されなかった場合は、リストコンテキストでは空リストを、
11445スカラコンテキストでは未定義値を返します
13757スカラコンテキストでは未定義値を返します; そして(もちろん)
11446そして(もちろん)無効コンテキストでは何も返しません。
13758無効コンテキストでは何も返しません。
1144713759
1144813760=begin original
1144913761
11450(In the absence of an explicit C<return>, a subroutine, eval,
13762(In the absence of an explicit L<C<return>|/return EXPR>, a subroutine,
11451or do FILE automatically returns the value of the last expression
13763L<C<eval>|/eval EXPR>,
13764or L<C<do FILE>|/do EXPR> automatically returns the value of the last expression
1145213765evaluated.)
1145313766
1145413767=end original
1145513768
11456(サブルーチン, eval, do FILE に明示的に C<return> が
13769(サブルーチン, L<C<eval>|/eval EXPR>, L<C<do FILE>|/do EXPR> に明示的に
11457なければ、最後に評価された値で、自動的にリターンします。)
13770L<C<return>|/return EXPR> がなければ、最後に評価された値で、
13771自動的にリターンします。)
1145813772
13773=begin original
13774
13775Unlike most named operators, this is also exempt from the
13776looks-like-a-function rule, so C<return ("foo")."bar"> will
13777cause C<"bar"> to be part of the argument to L<C<return>|/return EXPR>.
13778
13779=end original
13780
13781ほとんどの名前付き演算子と異なり、関数のように見えるものの規則からも
13782免れるので、C<return ("foo")."bar"> とすると C<"bar"> は
13783L<C<return>|/return EXPR> への引数の一部となります。
13784
1145913785=item reverse LIST
1146013786X<reverse> X<rev> X<invert>
1146113787
13788=for Pod::Functions flip a string or a list
13789
1146213790=begin original
1146313791
1146413792In list context, returns a list value consisting of the elements
1146513793of LIST in the opposite order. In scalar context, concatenates the
1146613794elements of LIST and returns a string value with all characters
1146713795in the opposite order.
1146813796
1146913797=end original
1147013798
1147113799リストコンテキストでは、LIST を構成する要素を逆順に並べた
1147213800リスト値を返します。
1147313801スカラコンテキストでは、LIST の要素を連結して、
1147413802全ての文字を逆順にした文字列を返します。
1147513803
1147613804 print join(", ", reverse "world", "Hello"); # Hello, world
1147713805
1147813806 print scalar reverse "dlrow ,", "olleH"; # Hello, world
1147913807
1148013808=begin original
1148113809
11482Used without arguments in scalar context, reverse() reverses C<$_>.
13810Used without arguments in scalar context, L<C<reverse>|/reverse LIST>
13811reverses L<C<$_>|perlvar/$_>.
1148313812
1148413813=end original
1148513814
11486スカラコンテキストで引数なしで使うと、reverse() は C<$_> を逆順にします。
13815スカラコンテキストで引数なしで使うと、L<C<reverse>|/reverse LIST>
13816L<C<$_>|perlvar/$_> を逆順にします。
1148713817
1148813818 $_ = "dlrow ,olleH";
11489 print reverse; # No output, list context
13819 print reverse; # No output, list context
11490 print scalar reverse; # Hello, world
13820 print scalar reverse; # Hello, world
1149113821
1149213822=begin original
1149313823
1149413824Note that reversing an array to itself (as in C<@a = reverse @a>) will
11495preserve non-existent elements whenever possible, i.e., for non magical
13825preserve non-existent elements whenever possible; i.e., for non-magical
11496arrays or tied arrays with C<EXISTS> and C<DELETE> methods.
13826arrays or for tied arrays with C<EXISTS> and C<DELETE> methods.
1149713827
1149813828=end original
1149913829
1150013830(C<@a = reverse @a> のように) 反転した配列を自分自身に代入すると、
1150113831存在しない要素は可能なら(つまりマジカルでない配列や
1150213832C<EXISTS> と C<DELETE> メソッドがある tie された配列)
1150313833いつでも保存されることに注意してください。
1150413834
1150513835=begin original
1150613836
1150713837This operator is also handy for inverting a hash, although there are some
1150813838caveats. If a value is duplicated in the original hash, only one of those
1150913839can be represented as a key in the inverted hash. Also, this has to
1151013840unwind one hash and build a whole new one, which may take some time
1151113841on a large hash, such as from a DBM file.
1151213842
1151313843=end original
1151413844
1151513845この演算子はハッシュの逆順にするのにも便利ですが、いくつかの弱点があります。
1151613846元のハッシュで値が重複していると、それらのうち一つだけが
1151713847逆順になったハッシュのキーとして表現されます。
1151813848また、これは一つのハッシュをほどいて完全に新しいハッシュを作るので、
1151913849DBM ファイルからのような大きなハッシュでは少し時間がかかります。
1152013850
11521 %by_name = reverse %by_address; # Invert the hash
13851 my %by_name = reverse %by_address; # Invert the hash
1152213852
1152313853=item rewinddir DIRHANDLE
1152413854X<rewinddir>
1152513855
13856=for Pod::Functions reset directory handle
13857
1152613858=begin original
1152713859
1152813860Sets the current position to the beginning of the directory for the
11529C<readdir> routine on DIRHANDLE.
13861L<C<readdir>|/readdir DIRHANDLE> routine on DIRHANDLE.
1153013862
1153113863=end original
1153213864
11533DIRHANDLE に対する C<readdir> ルーチンの現在位置を
13865DIRHANDLE に対する L<C<readdir>|/readdir DIRHANDLE> ルーチンの現在位置を
1153413866ディレクトリの最初に設定します。
1153513867
13868=begin original
13869
13870Portability issues: L<perlport/rewinddir>.
13871
13872=end original
13873
13874移植性の問題: L<perlport/rewinddir>。
13875
1153613876=item rindex STR,SUBSTR,POSITION
1153713877X<rindex>
1153813878
1153913879=item rindex STR,SUBSTR
1154013880
13881=for Pod::Functions right-to-left substring search
13882
1154113883=begin original
1154213884
11543Works just like index() except that it returns the position of the I<last>
13885Works just like L<C<index>|/index STR,SUBSTR,POSITION> except that it
13886returns the position of the I<last>
1154413887occurrence of SUBSTR in STR. If POSITION is specified, returns the
1154513888last occurrence beginning at or before that position.
1154613889
1154713890=end original
1154813891
1154913892STR 中で I<最後に> 見つかった SUBSTR の位置を返すことを除いて、
11550index() と同じように動作します。
13893L<C<index>|/index STR,SUBSTR,POSITION> と同じように動作します。
1155113894POSITION を指定すると、その位置から始まるか、その位置より前の、
1155213895最後の位置を返します。
1155313896
1155413897=item rmdir FILENAME
1155513898X<rmdir> X<rd> X<directory, remove>
1155613899
1155713900=item rmdir
1155813901
13902=for Pod::Functions remove a directory
13903
1155913904=begin original
1156013905
1156113906Deletes the directory specified by FILENAME if that directory is
1156213907empty. If it succeeds it returns true; otherwise it returns false and
11563sets C<$!> (errno). If FILENAME is omitted, uses C<$_>.
13908sets L<C<$!>|perlvar/$!> (errno). If FILENAME is omitted, uses
13909L<C<$_>|perlvar/$_>.
1156413910
1156513911=end original
1156613912
1156713913FILENAME で指定したディレクトリが空であれば、
1156813914そのディレクトリを削除します。
11569成功時には真を返します; さもなければ偽を返しC<$!> (errno) を設定します。
13915成功時には真を返します; さもなければ偽を返して L<C<$!>|perlvar/$!> (errno) を
11570FILENAME を省略した場合には、C<$_> を使用します。
13916設定します。
13917FILENAME を省略した場合には、L<C<$_>|perlvar/$_> を使用します。
1157113918
1157213919=begin original
1157313920
1157413921To remove a directory tree recursively (C<rm -rf> on Unix) look at
11575the C<rmtree> function of the L<File::Path> module.
13922the L<C<rmtree>|File::Path/rmtree( $dir )> function of the L<File::Path>
13923module.
1157613924
1157713925=end original
1157813926
1157913927ディレクトリツリーを再帰的に削除したい (Unix での C<rm -rf>) 場合、
11580L<File::Path> モジュールの C<rmtree> 関数を参照してください。
13928L<File::Path> モジュールの L<C<rmtree>|File::Path/rmtree( $dir )> 関数を
13929参照してください。
1158113930
1158213931=item s///
1158313932
13933=for Pod::Functions replace a pattern with a string
13934
1158413935=begin original
1158513936
1158613937The substitution operator. See L<perlop/"Regexp Quote-Like Operators">.
1158713938
1158813939=end original
1158913940
1159013941置換演算子。
1159113942L<perlop/"Regexp Quote-Like Operators"> を参照してください。
1159213943
1159313944=item say FILEHANDLE LIST
1159413945X<say>
1159513946
1159613947=item say FILEHANDLE
1159713948
1159813949=item say LIST
1159913950
1160013951=item say
1160113952
13953=for Pod::Functions +say output a list to a filehandle, appending a newline
13954
1160213955=begin original
1160313956
11604Just like C<print>, but implicitly appends a newline. C<say LIST> is
13957Just like L<C<print>|/print FILEHANDLE LIST>, but implicitly appends a
11605simply an abbreviation for C<{ local $\ = "\n"; print LIST }>. To use
13958newline. C<say LIST> is simply an abbreviation for
11606FILEHANDLE without a LIST to print the contents of C<$_> to it, you must
13959C<{ local $\ = "\n"; print LIST }>. To use FILEHANDLE without a LIST to
11607use a real filehandle like C<FH>, not an indirect one like C<$fh>.
13960print the contents of L<C<$_>|perlvar/$_> to it, you must use a bareword
13961filehandle like C<FH>, not an indirect one like C<$fh>.
1160813962
1160913963=end original
1161013964
11611C<print> と同様ですが、暗黙に改行が追加されます。
13965L<C<print>|/print FILEHANDLE LIST> と同様ですが、暗黙に改行が追加されます。
1161213966C<say LIST> は単に C<{ local $\ = "\n"; print LIST }> の省略形です。
11613C<$_> の内容を表示するために LIST なしで FILEHANDLE を使用するには、
13967L<C<$_>|perlvar/$_> の内容を表示するために LIST なしで FILEHANDLE を
11614C<$fh> のような間接ファイルハンドルではなく、C<FH> のような実際の
13968使用するには、C<$fh> のような間接ファイルハンドルではなく、C<FH> のような
11615ファイルハンドルを使わなければなりません。
13969裸の単語のファイルハンドルを使わなければなりません。
1161613970
1161713971=begin original
1161813972
11619This keyword is available only when the C<"say"> feature is enabled; see
13973L<C<say>|/say FILEHANDLE LIST> is available only if the
11620L<feature>. Alternately, include a C<use v5.10> or later to the current
13974L<C<"say"> feature|feature/The 'say' feature> is enabled or if it is
11621scope.
13975prefixed with C<CORE::>. The
13976L<C<"say"> feature|feature/The 'say' feature> is enabled automatically
13977with a C<use v5.10> (or higher) declaration in the current scope.
1162213978
1162313979=end original
1162413980
11625このキーワードは、C<"say"> 機能が有効の場合にのみ利用可能です;
13981L<C<say>|/say FILEHANDLE LIST> は
11626L<feature> を参照してください。
13982L<C<"say"> 機能|feature/The 'say' feature> が有効か C<CORE::> が
11627あるいは、現在のスコープに C<use v5.10> 以降を含めてくだ
13983前置れたときにのみ利用可能です
13984L<C<"say"> 機能|feature/The 'say' feature> は現在のスコープで
13985C<use v5.10> (またはそれ以上) が宣言されると自動的に有効になります。
1162813986
1162913987=item scalar EXPR
1163013988X<scalar> X<context>
1163113989
13990=for Pod::Functions force a scalar context
13991
1163213992=begin original
1163313993
1163413994Forces EXPR to be interpreted in scalar context and returns the value
1163513995of EXPR.
1163613996
1163713997=end original
1163813998
1163913999EXPR を強制的にスカラコンテキストで解釈されるようにして、
1164014000EXPR の値を返します。
1164114001
11642 @counts = ( scalar @a, scalar @b, scalar @c );
14002 my @counts = ( scalar @a, scalar @b, scalar @c );
1164314003
1164414004=begin original
1164514005
1164614006There is no equivalent operator to force an expression to
1164714007be interpolated in list context because in practice, this is never
1164814008needed. If you really wanted to do so, however, you could use
1164914009the construction C<@{[ (some expression) ]}>, but usually a simple
1165014010C<(some expression)> suffices.
1165114011
1165214012=end original
1165314013
11654式を強制的にリストコンテキストで解釈させるようにする演算子はありません
14014式を強制的にリストコンテキストで解釈させるようにする演算子はありません;
1165514015理論的には不要だからです。
1165614016それでも、もしそうしたいのなら、C<@{[ (some expression) ]}> という構造を
11657使えます。
14017使えます; しかし、普通は単に C<(some expression)> とすれば十分です
11658しかし、普通は単に C<(some expression)> とすれば十分です。
1165914018
1166014019=begin original
1166114020
11662Because C<scalar> is a unary operator, if you accidentally use a
14021Because L<C<scalar>|/scalar EXPR> is a unary operator, if you
14022accidentally use a
1166314023parenthesized list for the EXPR, this behaves as a scalar comma expression,
1166414024evaluating all but the last element in void context and returning the final
1166514025element evaluated in scalar context. This is seldom what you want.
1166614026
1166714027=end original
1166814028
11669C<scalar> は単項演算子なので、EXPR として括弧でくくったリストを使った場合、
14029L<C<scalar>|/scalar EXPR> は単項演算子なので、EXPR として括弧でくくった
11670これはスカラカンマ表現として振舞い、最後以外の全ては無効コンテキストとして
14030リストを使った場合、これはスカラカンマ表現として振舞い、最後以外の全ては
11671扱われ、最後の要素をスカラコンテキストとして扱った結果が返されます。
14031無効コンテキストとして扱われ、最後の要素をスカラコンテキストとして扱った
14032結果が返されます。
1167214033これがあなたの望むものであることはめったにないでしょう。
1167314034
1167414035=begin original
1167514036
1167614037The following single statement:
1167714038
1167814039=end original
1167914040
1168014041以下の一つの文は:
1168114042
11682 print uc(scalar(&foo,$bar)),$baz;
14043 print uc(scalar(foo(), $bar)), $baz;
1168314044
1168414045=begin original
1168514046
1168614047is the moral equivalent of these two:
1168714048
1168814049=end original
1168914050
1169014051以下の二つの文と等価です。
1169114052
11692 &foo;
14053 foo();
11693 print(uc($bar),$baz);
14054 print(uc($bar), $baz);
1169414055
1169514056=begin original
1169614057
11697See L<perlop> for more details on unary operators and the comma operator.
14058See L<perlop> for more details on unary operators and the comma operator,
14059and L<perldata> for details on evaluating a hash in scalar contex.
1169814060
1169914061=end original
1170014062
11701単項演算子とカンマ演算子に関する詳細については L<perlop> を参照して下さい。
14063単項演算子とカンマ演算子に関する詳細については L<perlop> を
14064スカラコンテキストでのハッシュの評価に関する詳細については L<perldata> を
14065参照してください。
1170214066
1170314067=item seek FILEHANDLE,POSITION,WHENCE
1170414068X<seek> X<fseek> X<filehandle, position>
1170514069
14070=for Pod::Functions reposition file pointer for random-access I/O
14071
1170614072=begin original
1170714073
11708Sets FILEHANDLE's position, just like the C<fseek> call of C<stdio>.
14074Sets FILEHANDLE's position, just like the L<fseek(3)> call of C C<stdio>.
1170914075FILEHANDLE may be an expression whose value gives the name of the
1171014076filehandle. The values for WHENCE are C<0> to set the new position
1171114077I<in bytes> to POSITION; C<1> to set it to the current position plus
1171214078POSITION; and C<2> to set it to EOF plus POSITION, typically
1171314079negative. For WHENCE you may use the constants C<SEEK_SET>,
1171414080C<SEEK_CUR>, and C<SEEK_END> (start of the file, current position, end
1171514081of the file) from the L<Fcntl> module. Returns C<1> on success, false
1171614082otherwise.
1171714083
1171814084=end original
1171914085
11720C<stdio> ライブラリの C<fseek> 関数のように、FILEHANDLE の
14086C の C<stdio> ライブラリの L<fseek(3)> 関数のように、FILEHANDLE の
1172114087ファイルポインタを任意の位置に設定します。
1172214088FILEHANDLE は、実際のファイルハンドル名を与える式でもかまいません。
1172314089WHENCE の値が、C<0> ならば、新しい位置を I<バイト単位で> POSITION の位置へ
11724設定します; C<1> ならば、現在位置から I<バイト数で> POSITION 加えた位置へ
14090設定します; C<1> ならば、現在位置から POSITION 加えた位置へ
1172514091設定します; C<2> ならば、EOF からPOSITION だけ加えた位置へ、新しい位置を
1172614092設定します。
1172714093この値には、L<Fcntl> モジュールで使われている C<SEEK_SET>、C<SEEK_CUR>、
1172814094C<SEEK_END> (ファイルの先頭、現在位置、ファイルの最後)という定数を
1172914095使うこともできます。
11730成功時には、C<1> を、失敗時には C<0> を返します。
14096成功時には、C<1> を、失敗時にはそれ以外を返します。
1173114097
1173214098=begin original
1173314099
1173414100Note the I<in bytes>: even if the filehandle has been set to
1173514101operate on characters (for example by using the C<:encoding(utf8)> open
11736layer), tell() will return byte offsets, not character offsets
14102layer), L<C<tell>|/tell FILEHANDLE> will return byte offsets, not
11737(because implementing that would render seek() and tell() rather slow).
14103character offsets (because implementing that would render
14104L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> and
14105L<C<tell>|/tell FILEHANDLE> rather slow).
1173814106
1173914107=end original
1174014108
1174114109I<バイト単位> に関する注意: ファイルハンドルが (例えば C<:encoding(utf8)> 層を
11742使って)文字を操作するように設定されていたとしても、tell() は文字の
14110使って)文字を操作するように設定されていたとしても、
11743オフセットではなくバイトのオフセットを返すことに注意してください
14111L<C<tell>|/tell FILEHANDLE> は文字のオフセットではなくバイトのオフセットを
11744(なぜならこれを実装 seek() と tell() が遅くなってまうからです)。
14112に注意てください
14113(なぜならこれを実装すると L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> と
14114L<C<tell>|/tell FILEHANDLE> が遅くなってしまうからです)。
1174514115
1174614116=begin original
1174714117
11748If you want to position the file for C<sysread> or C<syswrite>, don't use
14118If you want to position the file for
11749C<seek>, because buffering makes its effect on the file's read-write position
14119L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> or
11750unpredictable and non-portable. Use C<sysseek> instead.
14120L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, don't use
14121L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, because buffering makes its
14122effect on the file's read-write position unpredictable and non-portable.
14123Use L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> instead.
1175114124
1175214125=end original
1175314126
11754C<sysread> や C<syswrite> のためにファイルの位置を指定したい場合は、
14127L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>
11755C<seek> は使えません; なぜならバッファリングのためにファイルの読み込み位置は
14128L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> のためにファイルの
14129位置を指定したい場合は、L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> は
14130使えません; なぜならバッファリングのためにファイルの読み込み位置は
1175614131動作は予測不能で移植性のないものになってしまいます。
11757代わりに C<sysseek> を使ってください。
14132代わりに L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> を使ってください。
1175814133
1175914134=begin original
1176014135
1176114136Due to the rules and rigors of ANSI C, on some systems you have to do a
1176214137seek whenever you switch between reading and writing. Amongst other
11763things, this may have the effect of calling stdio's clearerr(3).
14138things, this may have the effect of calling stdio's L<clearerr(3)>.
1176414139A WHENCE of C<1> (C<SEEK_CUR>) is useful for not moving the file position:
1176514140
1176614141=end original
1176714142
1176814143ANSI C の規則と困難により、システムによっては読み込みと書き込みを
1176914144切り替える度にシークしなければならない場合があります。
11770その他のことの中で、これは stdio の clearerr(3) を呼び出す効果があります。
14145その他のことの中で、これは stdio の L<clearerr(3)> を呼び出す効果があります。
1177114146WHENCE の C<1> (C<SEEK_CUR>) が、ファイル位置を変えないので有用です:
1177214147
11773 seek(TEST,0,1);
14148 seek($fh, 0, 1);
1177414149
1177514150=begin original
1177614151
1177714152This is also useful for applications emulating C<tail -f>. Once you hit
1177814153EOF on your read and then sleep for a while, you (probably) have to stick in a
11779dummy seek() to reset things. The C<seek> doesn't change the position,
14154dummy L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> to reset things. The
14155L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> doesn't change the position,
1178014156but it I<does> clear the end-of-file condition on the handle, so that the
11781next C<< <FILE> >> makes Perl try again to read something. (We hope.)
14157next C<readline FILE> makes Perl try again to read something. (We hope.)
1178214158
1178314159=end original
1178414160
1178514161これはアプリケーションで C<tail -f> をエミュレートするのにも有用です。
1178614162一度読み込み時に EOF に到達すると、しばらくスリープし、
11787(おそらく) ダミーの seek() をすることでリセットする必要があります。
14163(おそらく) ダミーの L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> をすることで
11788C<seek> は現在の位置を変更しません、ハンドルの EOF 状態を
14164リセットする必要あります。
11789I<クリアします> ので、次の C<< <FILE> >> で Perl 再び何か
14165L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> は現在の位置変更しませんが、
11790読み込もうとします。(そはずす。)
14166ハンドルの EOF 状態をI<クリアします> ので、次の C<readline FILE> で Perl は
14167再び何かを読み込もうとします。(そのはずです。)
1179114168
1179214169=begin original
1179314170
1179414171If that doesn't work (some I/O implementations are particularly
1179514172cantankerous), you might need something like this:
1179614173
1179714174=end original
1179814175
1179914176これが動かない場合(特に意地の悪い I/O 実装もあります)、
1180014177以下のようなことをする必要があります:
1180114178
1180214179 for (;;) {
11803 for ($curpos = tell(FILE); $_ = <FILE>;
14180 for ($curpos = tell($fh); $_ = readline($fh);
11804 $curpos = tell(FILE)) {
14181 $curpos = tell($fh)) {
1180514182 # search for some stuff and put it into files
1180614183 }
1180714184 sleep($for_a_while);
11808 seek(FILE, $curpos, 0);
14185 seek($fh, $curpos, 0);
1180914186 }
1181014187
1181114188=item seekdir DIRHANDLE,POS
1181214189X<seekdir>
1181314190
14191=for Pod::Functions reposition directory pointer
14192
1181414193=begin original
1181514194
11816Sets the current position for the C<readdir> routine on DIRHANDLE. POS
14195Sets the current position for the L<C<readdir>|/readdir DIRHANDLE>
11817must be a value returned by C<telldir>. C<seekdir> also has the same caveats
14196routine on DIRHANDLE. POS must be a value returned by
11818about possible directory compaction as the corresponding system library
14197L<C<telldir>|/telldir DIRHANDLE>. L<C<seekdir>|/seekdir DIRHANDLE,POS>
11819routine.
14198also has the same caveats about possible directory compaction as the
14199corresponding system library routine.
1182014200
1182114201=end original
1182214202
11823DIRHANDLE での C<readdir> ルーチンの現在位置を設定します。
14203DIRHANDLE での L<C<readdir>|/readdir DIRHANDLE> ルーチンの現在位置を
11824POS は、C<telldir> が返す値でなければなりせん
14204設定し
11825C<seekdir> は同名のシステムライブラリルーチンと同じく、
14205POS は、L<C<telldir>|/telldir DIRHANDLE> が返す値でなければなりません。
11826ディレクトリ縮小時問題が考えられます。
14206L<C<seekdir>|/seekdir DIRHANDLE,POS> は同名システムライブラリルーチンと
14207同じく、ディレクトリ縮小時の問題が考えられます。
1182714208
1182814209=item select FILEHANDLE
1182914210X<select> X<filehandle, default>
1183014211
1183114212=item select
1183214213
14214=for Pod::Functions reset default output or do I/O multiplexing
14215
1183314216=begin original
1183414217
1183514218Returns the currently selected filehandle. If FILEHANDLE is supplied,
1183614219sets the new current default filehandle for output. This has two
11837effects: first, a C<write> or a C<print> without a filehandle
14220effects: first, a L<C<write>|/write FILEHANDLE> or a L<C<print>|/print
14221FILEHANDLE LIST> without a filehandle
1183814222default to this FILEHANDLE. Second, references to variables related to
11839output will refer to this output channel.
14223output will refer to this output channel.
1184014224
1184114225=end original
1184214226
1184314227その時点で、選択されていたファイルハンドルを返します。
11844FILEHANDLE を指定した場合には、その値を出力のデフォルト
14228FILEHANDLE を指定した場合には、その値を出力のデフォルトファイルハンドルに
11845ファイルハンドルに設定します。
14229設定します。
11846これには、2 つの効果があります
14230これには、2 つの効果があります: まず、ファイルハンドルを指定しないで
11847まず、ファイルハンドル指定しないで
14231L<C<write>|/write FILEHANDLE> や L<C<print>|/print FILEHANDLE LIST>
11848C<write> や C<print> を行なった場合のデフォルトが、
14232行なった場合のデフォルトが、この FILEHANDLE になります。
11849この FILEHANDLE になります。
14233もう一つは、出力関連の変数への参照は、この出力チャネルを
11850もう一つは、出力関連の変数への参照は、
14234参照するようになります。
11851この出力チャネルを参照するようになります。
1185214235
1185314236=begin original
1185414237
1185514238For example, to set the top-of-form format for more than one
1185614239output channel, you might do the following:
1185714240
1185814241=end original
1185914242
1186014243例えば、複数の出力チャネルに対して、ページ先頭フォーマットを
1186114244設定するには:
1186214245
1186314246 select(REPORT1);
1186414247 $^ = 'report1_top';
1186514248 select(REPORT2);
1186614249 $^ = 'report2_top';
1186714250
1186814251=begin original
1186914252
1187014253FILEHANDLE may be an expression whose value gives the name of the
1187114254actual filehandle. Thus:
1187214255
1187314256=end original
1187414257
11875FILEHANDLE は、実際のファイルハンドルを示す式でもかまいません。
14258FILEHANDLE は、実際のファイルハンドル名を示す式でもかまいません。
1187614259つまり、以下のようなものです:
1187714260
11878 $oldfh = select(STDERR); $| = 1; select($oldfh);
14261 my $oldfh = select(STDERR); $| = 1; select($oldfh);
1187914262
1188014263=begin original
1188114264
1188214265Some programmers may prefer to think of filehandles as objects with
1188314266methods, preferring to write the last example as:
1188414267
1188514268=end original
1188614269
11887ファイルハンドルはメソッドを持ったオブジェクトであると
14270ファイルハンドルはメソッドを持ったオブジェクトであると考えることを好む
11888考えることを好むプログラマもいるかもしれません
14271プログラマもいるかもしれません; そのような場合のための最後の例は
11889そのような場合のための最後の例は以下のようなものです
14272以下のようなものです:
1189014273
11891 use IO::Handle;
1189214274 STDERR->autoflush(1);
1189314275
14276=begin original
14277
14278(Prior to Perl version 5.14, you have to C<use IO::Handle;> explicitly
14279first.)
14280
14281=end original
14282
14283(Perl バージョン 5.14 以前では、まず明示的に C<use IO::Handle;> とする
14284必要があります。)
14285
14286=begin original
14287
14288Portability issues: L<perlport/select>.
14289
14290=end original
14291
14292移植性の問題: L<perlport/select>。
14293
1189414294=item select RBITS,WBITS,EBITS,TIMEOUT
1189514295X<select>
1189614296
1189714297=begin original
1189814298
11899This calls the select(2) syscall with the bit masks specified, which
14299This calls the L<select(2)> syscall with the bit masks specified, which
11900can be constructed using C<fileno> and C<vec>, along these lines:
14300can be constructed using L<C<fileno>|/fileno FILEHANDLE> and
14301L<C<vec>|/vec EXPR,OFFSET,BITS>, along these lines:
1190114302
1190214303=end original
1190314304
11904これは、select(2) システムコールを、指定したビットマスクで呼び出します
14305これは、L<select(2)> システムコールを、指定したビットマスクで呼び出します;
11905ビットマスクは、C<fileno> と C<vec> を使って、以下のようにして
14306ビットマスクは、L<C<fileno>|/fileno FILEHANDLE>
11906作成できます:
14307L<C<vec>|/vec EXPR,OFFSET,BITS> を使って、以下のようにして作成できます:
1190714308
11908 $rin = $win = $ein = '';
14309 my $rin = my $win = my $ein = '';
11909 vec($rin,fileno(STDIN),1) = 1;
14310 vec($rin, fileno(STDIN), 1) = 1;
11910 vec($win,fileno(STDOUT),1) = 1;
14311 vec($win, fileno(STDOUT), 1) = 1;
1191114312 $ein = $rin | $win;
1191214313
1191314314=begin original
1191414315
1191514316If you want to select on many filehandles, you may wish to write a
1191614317subroutine like this:
1191714318
1191814319=end original
1191914320
1192014321複数のファイルハンドルに select を行ないたいのであれば、
1192114322以下のようにします:
1192214323
1192314324 sub fhbits {
11924 my(@fhlist) = split(' ',$_[0]);
14325 my @fhlist = @_;
11925 my($bits);
14326 my $bits = "";
11926 for (@fhlist) {
14327 for my $fh (@fhlist) {
11927 vec($bits,fileno($_),1) = 1;
14328 vec($bits, fileno($fh), 1) = 1;
1192814329 }
11929 $bits;
14330 return $bits;
1193014331 }
11931 $rin = fhbits('STDIN TTY SOCK');
14332 my $rin = fhbits(\*STDIN, $tty, $mysock);
1193214333
1193314334=begin original
1193414335
1193514336The usual idiom is:
1193614337
1193714338=end original
1193814339
1193914340通常は、
1194014341
11941 ($nfound,$timeleft) =
14342 my ($nfound, $timeleft) =
11942 select($rout=$rin, $wout=$win, $eout=$ein, $timeout);
14343 select(my $rout = $rin, my $wout = $win, my $eout = $ein,
14344 $timeout);
1194314345
1194414346=begin original
1194514347
1194614348or to block until something becomes ready just do this
1194714349
1194814350=end original
1194914351
1195014352のように使い、いずれかの準備が整うまでブロックするには、
1195114353以下のようにします。
1195214354
11953 $nfound = select($rout=$rin, $wout=$win, $eout=$ein, undef);
14355 my $nfound =
14356 select(my $rout = $rin, my $wout = $win, my $eout = $ein, undef);
1195414357
1195514358=begin original
1195614359
11957Most systems do not bother to return anything useful in $timeleft, so
14360Most systems do not bother to return anything useful in C<$timeleft>, so
11958calling select() in scalar context just returns $nfound.
14361calling L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> in scalar context
14362just returns C<$nfound>.
1195914363
1196014364=end original
1196114365
11962ほとんどのシステムではわざわざ意味のある値を $timeleft に返さないので、
14366ほとんどのシステムではわざわざ意味のある値を C<$timeleft> に返さないので、
11963select() をスカラコンテキストで呼び出すと、単に $nfound を返します。
14367L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> をスカラコンテキストで
14368呼び出すと、単に C<$nfound> を返します。
1196414369
1196514370=begin original
1196614371
11967Any of the bit masks can also be undef. The timeout, if specified, is
14372Any of the bit masks can also be L<C<undef>|/undef EXPR>. The timeout,
14373if specified, is
1196814374in seconds, which may be fractional. Note: not all implementations are
11969capable of returning the $timeleft. If not, they always return
14375capable of returning the C<$timeleft>. If not, they always return
11970$timeleft equal to the supplied $timeout.
14376C<$timeleft> equal to the supplied C<$timeout>.
1197114377
1197214378=end original
1197314379
11974どのビットマスクにも undef を設定することができます。
14380どのビットマスクにも L<C<undef>|/undef EXPR> を設定することができます。
1197514381TIMEOUT を指定するときは、秒数で指定し、小数でかまいません。
11976注: すべての実装で、$timeleft が返せるものではありません。
14382注: すべての実装で、C<$timeleft> が返せるものではありません。
11977その場合、$timeleft には、常に指定した TIMEOUT と同じ値が返されます。
14383その場合、C<$timeleft> には、常に指定した C<$timeout> と同じ値が返されます。
1197814384
1197914385=begin original
1198014386
1198114387You can effect a sleep of 250 milliseconds this way:
1198214388
1198314389=end original
1198414390
1198514391250 ミリ秒の sleep と同じ効果が、以下のようにして得られます。
1198614392
1198714393 select(undef, undef, undef, 0.25);
1198814394
1198914395=begin original
1199014396
11991Note that whether C<select> gets restarted after signals (say, SIGALRM)
14397Note that whether L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> gets
11992is implementation-dependent. See also L<perlport> for notes on the
14398restarted after signals (say, SIGALRM) is implementation-dependent. See
11993portability of C<select>.
14399also L<perlport> for notes on the portability of
14400L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>.
1199414401
1199514402=end original
1199614403
11997C<select> がシグナル (例えば、SIGALRM) の後に再起動するかどうかは
14404L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> がシグナル (例えば、SIGALRM) の
11998実装依存であることに注意してください。
14405後に再起動するかどうかは実装依存であることに注意してください。
11999C<select> の移植性に関する注意については L<perlport> も参照してください。
14406L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> の移植性に関する
14407注意については L<perlport> も参照してください。
1200014408
1200114409=begin original
1200214410
12003On error, C<select> behaves like select(2): it returns
14411On error, L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> behaves just
12004-1 and sets C<$!>.
14412like L<select(2)>: it returns C<-1> and sets L<C<$!>|perlvar/$!>.
1200514413
1200614414=end original
1200714415
12008エラー時は、C<select>select(2) のように振舞います:
14416エラー時は、L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> は
12009-1 を返し、C<$!> をセットします
14417L<select(2)> のように振舞います:
14418C<-1> を返し、L<C<$!>|perlvar/$!> をセットします。
1201014419
1201114420=begin original
1201214421
12013On some Unixes, select(2) may report a socket file descriptor as "ready for
14422On some Unixes, L<select(2)> may report a socket file descriptor as
12014reading" even when no data is available, and thus any subsequent C<read>
14423"ready for reading" even when no data is available, and thus any
12015would block. This can be avoided if you always use O_NONBLOCK on the
14424subsequent L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> would block.
12016socket. See select(2) and fcntl(2) for further details.
14425This can be avoided if you always use C<O_NONBLOCK> on the socket. See
14426L<select(2)> and L<fcntl(2)> for further details.
1201714427
1201814428=end original
1201914429
12020Unix の中には、実際に利用可能なデータがないために引き続く C<read> が
14430Unix の中には、実際に利用可能なデータがないために引き続く
12021ブロックされる場合でも、select(2) が、ソケットファイル記述子
14431L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>
14432ブロックされる場合でも、L<select(2)> が、ソケットファイル記述子が
1202214433「読み込み準備中」であると報告するものもあります。
12023これは、ソケットに対して常に O_NONBLOCK フラグを使うことで回避できます。
14434これは、ソケットに対して常に C<O_NONBLOCK> フラグを使うことで回避できます。
12024さらなる詳細については select(2) と fcntl(2) を参照してください。
14435さらなる詳細については L<select(2)>L<fcntl(2)> を参照してください。
1202514436
1202614437=begin original
1202714438
12028B<WARNING>: One should not attempt to mix buffered I/O (like C<read>
14439The standard L<C<IO::Select>|IO::Select> module provides a
12029or <FH>) with C<select>, except as permitted by POSIX, and even
14440user-friendlier interface to
12030then only on POSIX systems. You have to use C<sysread> instead.
14441L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, mostly because it does
14442all the bit-mask work for you.
1203114443
1203214444=end original
1203314445
12034B<警告>: バッファ付き I/O (C<read> や <FH>) と C<select>
14446標準の L<C<IO::Select>|IO::Select> モジュールは
14447L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> へのよりユーザーフレンドリーな
14448インターフェースを提供します; 主な理由はビットマスクの仕事を
14449してくれることです。
14450
14451=begin original
14452
14453B<WARNING>: One should not attempt to mix buffered I/O (like
14454L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> or
14455L<C<readline>|/readline EXPR>) with
14456L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, except as permitted by
14457POSIX, and even then only on POSIX systems. You have to use
14458L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> instead.
14459
14460=end original
14461
14462B<警告>: バッファ付き I/O (L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> や
14463L<C<readline>|/readline EXPR>) と
14464L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を
1203514465混ぜて使ってはいけません(例外: POSIX で認められている形で使い、
1203614466POSIX システムでだけ動かす場合を除きます)。
12037代わりに C<sysread> を使わなければなりません。
14467代わりに L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>
14468使わなければなりません。
1203814469
14470=begin original
14471
14472Portability issues: L<perlport/select>.
14473
14474=end original
14475
14476移植性の問題: L<perlport/select>。
14477
1203914478=item semctl ID,SEMNUM,CMD,ARG
1204014479X<semctl>
1204114480
14481=for Pod::Functions SysV semaphore control operations
14482
1204214483=begin original
1204314484
12044Calls the System V IPC function semctl(2). You'll probably have to say
14485Calls the System V IPC function L<semctl(2)>. You'll probably have to say
1204514486
1204614487=end original
1204714488
12048System V IPC 関数 semctl(2) を呼び出します。
14489System V IPC 関数 L<semctl(2)> を呼び出します。
1204914490正しい定数定義を得るために、まず
1205014491
1205114492 use IPC::SysV;
1205214493
1205314494=begin original
1205414495
1205514496first to get the correct constant definitions. If CMD is IPC_STAT or
1205614497GETALL, then ARG must be a variable that will hold the returned
12057semid_ds structure or semaphore value array. Returns like C<ioctl>:
14498semid_ds structure or semaphore value array. Returns like
14499L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>:
1205814500the undefined value for error, "C<0 but true>" for zero, or the actual
1205914501return value otherwise. The ARG must consist of a vector of native
1206014502short integers, which may be created with C<pack("s!",(0)x$nsem)>.
12061See also L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::Semaphore>
14503See also L<perlipc/"SysV IPC"> and the documentation for
12062documentation.
14504L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>.
1206314505
1206414506=end original
1206514507
12066宣言する必要があるでしょう。
14508書くことが必要でしょう。
1206714509CMD が、IPC_STAT か GETALL のときには、ARG は、返される
1206814510semid_ds 構造体か、セマフォ値の配列を納める変数でなければなりません。
12069C<ioctl> と同じように、エラー時には未定義値、
14511L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同じように、エラー時には
12070ゼロのときは C<"0 だが真">、それ以外なら、その値そのものを返します。
14512未定義値、ゼロのときは C<"0 だが真">、それ以外なら、その値そのものを返します。
12071ARG はネイティブな short int のベクターから成っていなければなりません
14513ARG はネイティブな short int のベクターから成っていなければなりません; これは
12072これは C<pack("s!",(0)x$nsem)> で作成できます。
14514C<pack("s!",(0)x$nsem)> で作成できます。
12073L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::Semaphore> も参照してください。
14515L<perlipc/"SysV IPC"> と、
14516L<C<IPC::SysV>|IPC::SysV>, L<C<IPC::Semaphore>|IPC::Semaphore> の文書も
14517参照してください。
1207414518
14519=begin original
14520
14521Portability issues: L<perlport/semctl>.
14522
14523=end original
14524
14525移植性の問題: L<perlport/semctl>。
14526
1207514527=item semget KEY,NSEMS,FLAGS
1207614528X<semget>
1207714529
14530=for Pod::Functions get set of SysV semaphores
14531
1207814532=begin original
1207914533
12080Calls the System V IPC function semget(2). Returns the semaphore id, or
14534Calls the System V IPC function L<semget(2)>. Returns the semaphore id, or
1208114535the undefined value on error. See also
12082L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Semaphore>
14536L<perlipc/"SysV IPC"> and the documentation for
12083documentation.
14537L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>.
1208414538
1208514539=end original
1208614540
12087System V IPC 関数 semget(2) を呼び出します。
14541System V IPC 関数 L<semget(2)> を呼び出します。
1208814542セマフォ ID か、エラー時には未定義値を返します。
12089L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Semaphore>
14543L<perlipc/"SysV IPC"> と、L<C<IPC::SysV>|IPC::SysV>,
12090参照してください。
14544L<C<IPC::Semaphore>|IPC::Semaphore> 文書も参照してください。
1209114545
14546=begin original
14547
14548Portability issues: L<perlport/semget>.
14549
14550=end original
14551
14552移植性の問題: L<perlport/semget>。
14553
1209214554=item semop KEY,OPSTRING
1209314555X<semop>
1209414556
14557=for Pod::Functions SysV semaphore operations
14558
1209514559=begin original
1209614560
12097Calls the System V IPC function semop(2) for semaphore operations
14561Calls the System V IPC function L<semop(2)> for semaphore operations
1209814562such as signalling and waiting. OPSTRING must be a packed array of
1209914563semop structures. Each semop structure can be generated with
12100C<pack("s!3", $semnum, $semop, $semflag)>. The length of OPSTRING
14564C<pack("s!3", $semnum, $semop, $semflag)>. The length of OPSTRING
1210114565implies the number of semaphore operations. Returns true if
1210214566successful, false on error. As an example, the
1210314567following code waits on semaphore $semnum of semaphore id $semid:
1210414568
1210514569=end original
1210614570
1210714571シグナルを送信や、待ち合わせなどのセマフォ操作を行なうために、
12108System V IPC 関数 semop(2) を呼び出します。
14572System V IPC 関数 L<semop(2)> を呼び出します。
1210914573OPSTRING は、semop 構造体の pack された配列でなければなりません。
12110semop 構造体は、それぞれ、
14574semop 構造体は、それぞれ、C<pack("s!3", $semnum, $semop, $semflag)> のように
12111C<pack("s!3", $semnum, $semop, $semflag)> のように作ることができます。
14575作ることができます。
1211214576セマフォ操作の数は、OPSTRING の長さからわかります。
1211314577成功時には真を、エラー時には偽を返します。
1211414578以下の例は、セマフォ ID $semid のセマフォ $semnum で
1211514579待ち合わせを行ないます。
1211614580
12117 $semop = pack("s!3", $semnum, -1, 0);
14581 my $semop = pack("s!3", $semnum, -1, 0);
1211814582 die "Semaphore trouble: $!\n" unless semop($semid, $semop);
1211914583
1212014584=begin original
1212114585
1212214586To signal the semaphore, replace C<-1> with C<1>. See also
12123L<perlipc/"SysV IPC">, C<IPC::SysV>, and C<IPC::SysV::Semaphore>
14587L<perlipc/"SysV IPC"> and the documentation for
12124documentation.
14588L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>.
1212514589
1212614590=end original
1212714591
1212814592セマフォにシグナルを送るには、C<-1> を C<1> に変更してください。
12129L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Semaphore>
14593L<perlipc/"SysV IPC"> と L<C<IPC::SysV>|IPC::SysV>,
12130参照してください。
14594L<C<IPC::Semaphore>|IPC::Semaphore> の文書も参照してください。
1213114595
14596=begin original
14597
14598Portability issues: L<perlport/semop>.
14599
14600=end original
14601
14602移植性の問題: L<perlport/semop>。
14603
1213214604=item send SOCKET,MSG,FLAGS,TO
1213314605X<send>
1213414606
1213514607=item send SOCKET,MSG,FLAGS
1213614608
14609=for Pod::Functions send a message over a socket
14610
1213714611=begin original
1213814612
1213914613Sends a message on a socket. Attempts to send the scalar MSG to the SOCKET
1214014614filehandle. Takes the same flags as the system call of the same name. On
1214114615unconnected sockets, you must specify a destination to I<send to>, in which
12142case it does a sendto(2) syscall. Returns the number of characters sent,
14616case it does a L<sendto(2)> syscall. Returns the number of characters sent,
12143or the undefined value on error. The sendmsg(2) syscall is currently
14617or the undefined value on error. The L<sendmsg(2)> syscall is currently
1214414618unimplemented. See L<perlipc/"UDP: Message Passing"> for examples.
1214514619
1214614620=end original
1214714621
1214814622ソケットにメッセージを送ります。
1214914623スカラ MSG を ファイルハンドル SOCKET に送ろうとします。
1215014624同名のシステムコールと同じフラグが指定できます。
1215114625接続していないソケットには、I<send to> に接続先を指定しなければならず、
12152この場合、sendto(2) を実行します。
14626この場合、L<sendto(2)> を実行します。
1215314627送信した文字数か、エラー時には、未定義値を返します。
12154システムコール sendmsg(2) は現在実装されていません。
14628システムコール L<sendmsg(2)> は現在実装されていません。
1215514629例については L<perlipc/"UDP: Message Passing"> を参照してください。
1215614630
1215714631=begin original
1215814632
1215914633Note the I<characters>: depending on the status of the socket, either
1216014634(8-bit) bytes or characters are sent. By default all sockets operate
1216114635on bytes, but for example if the socket has been changed using
12162binmode() to operate with the C<:encoding(utf8)> I/O layer (see
14636L<C<binmode>|/binmode FILEHANDLE, LAYER> to operate with the
12163L</open>, or the C<open> pragma, L<open>), the I/O will operate on UTF-8
14637C<:encoding(utf8)> I/O layer (see L<C<open>|/open FILEHANDLE,EXPR>, or
14638the L<open> pragma), the I/O will operate on UTF-8
1216414639encoded Unicode characters, not bytes. Similarly for the C<:encoding>
12165pragma: in that case pretty much any characters can be sent.
14640layer: in that case pretty much any characters can be sent.
1216614641
1216714642=end original
1216814643
1216914644I<文字> に関する注意: ソケットの状態によって、(8 ビットの) バイトか
1217014645文字を送信します。
1217114646デフォルトでは全てのソケットはバイトを処理しますが、
12172例えばソケットが binmode() で C<:encoding(utf8)> I/O 層(L</open>
14647例えばソケットが L<C<binmode>|/binmode FILEHANDLE, LAYER>
12173C<open> プラグマ、L<open> を参照してください) を使うように指定された場合
14648C<:encoding(utf8)> I/O 層(L<C<open>|/open FILEHANDLE,EXPR>
14649L<open> プラグマを参照してください) を使うように指定された場合、
1217414650I/O はバイトではなく、UTF-8 エンコードされた Unicode 文字を操作します。
12175C<:encoding> プラグマも同様です:
14651C<:encoding> も同様です:
1217614652この場合、ほとんど大体全ての文字が書き込めます。
1217714653
1217814654=item setpgrp PID,PGRP
1217914655X<setpgrp> X<group>
1218014656
14657=for Pod::Functions set the process group of a process
14658
1218114659=begin original
1218214660
1218314661Sets the current process group for the specified PID, C<0> for the current
1218414662process. Raises an exception when used on a machine that doesn't
12185implement POSIX setpgid(2) or BSD setpgrp(2). If the arguments are omitted,
14663implement POSIX L<setpgid(2)> or BSD L<setpgrp(2)>. If the arguments
12186it defaults to C<0,0>. Note that the BSD 4.2 version of C<setpgrp> does not
14664are omitted, it defaults to C<0,0>. Note that the BSD 4.2 version of
12187accept any arguments, so only C<setpgrp(0,0)> is portable. See also
14665L<C<setpgrp>|/setpgrp PID,PGRP> does not accept any arguments, so only
12188C<POSIX::setsid()>.
14666C<setpgrp(0,0)> is portable. See also
14667L<C<POSIX::setsid()>|POSIX/C<setsid>>.
1218914668
1219014669=end original
1219114670
1219214671指定した PID (C<0> を指定するとカレントプロセス) に
1219314672対するプロセスグループを設定します。
12194POSIX setpgrp(2) または BSD setpgrp(2) が実装されていないマシンでは、
14673POSIX L<setpgrp(2)> または BSD L<setpgrp(2)> が実装されていないマシンでは、
1219514674例外が発生します。
1219614675引数が省略された場合は、C<0,0>が使われます。
12197BSD 4.2 版の C<setpgrp> は引数を取ることができないので、
14676BSD 4.2 版の L<C<setpgrp>|/setpgrp PID,PGRP> は引数を取ることができないので、
1219814677C<setpgrp(0,0)> のみが移植性があることに注意してください。
12199C<POSIX::setsid()> も参照してください。
14678L<C<POSIX::setsid()>|POSIX/C<setsid>> も参照してください。
1220014679
14680=begin original
14681
14682Portability issues: L<perlport/setpgrp>.
14683
14684=end original
14685
14686移植性の問題: L<perlport/setpgrp>。
14687
1220114688=item setpriority WHICH,WHO,PRIORITY
1220214689X<setpriority> X<priority> X<nice> X<renice>
1220314690
14691=for Pod::Functions set a process's nice value
14692
1220414693=begin original
1220514694
1220614695Sets the current priority for a process, a process group, or a user.
12207(See setpriority(2).) Raises an exception when used on a machine
14696(See L<setpriority(2)>.) Raises an exception when used on a machine
12208that doesn't implement setpriority(2).
14697that doesn't implement L<setpriority(2)>.
1220914698
1221014699=end original
1221114700
1221214701プロセス、プロセスグループ、ユーザに対する優先順位を設定します。
12213(setpriority(2) を参照してください。)
14702(L<setpriority(2)> を参照してください。)
12214setpriority(2) が実装されていないマシンでは、
14703L<setpriority(2)> が実装されていないマシンでは、例外が発生します。
12215例外が発生します。
1221614704
14705=begin original
14706
14707Portability issues: L<perlport/setpriority>.
14708
14709=end original
14710
14711移植性の問題: L<perlport/setpriority>。
14712
1221714713=item setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL
1221814714X<setsockopt>
1221914715
14716=for Pod::Functions set some socket options
14717
1222014718=begin original
1222114719
12222Sets the socket option requested. Returns C<undef> on error.
14720Sets the socket option requested. Returns L<C<undef>|/undef EXPR> on
12223Use integer constants provided by the C<Socket> module for
14721error. Use integer constants provided by the L<C<Socket>|Socket> module
14722for
1222414723LEVEL and OPNAME. Values for LEVEL can also be obtained from
1222514724getprotobyname. OPTVAL might either be a packed string or an integer.
1222614725An integer OPTVAL is shorthand for pack("i", OPTVAL).
1222714726
1222814727=end original
1222914728
1223014729要求したソケットオプションを設定します。
12231エラー時には、C<undef> を返します。
14730エラー時には、L<C<undef>|/undef EXPR> を返します。
12232LEVEL と OPNAME には C<Socket> モジュールが提供する整数定数を使います。
14731LEVEL と OPNAME には L<C<Socket>|Socket> モジュールが提供する
14732整数定数を使います。
1223314733LEVEL の値は getprotobyname から得ることもできます。
1223414734OPTVAL は pack された文字列か整数です。
1223514735整数の OPTVAL は pack("i", OPTVAL) の省略表現です。
1223614736
1223714737=begin original
1223814738
1223914739An example disabling Nagle's algorithm on a socket:
1224014740
1224114741=end original
1224214742
1224314743ソケットに対する Nagle のアルゴリズムを無効にする例です:
1224414744
1224514745 use Socket qw(IPPROTO_TCP TCP_NODELAY);
1224614746 setsockopt($socket, IPPROTO_TCP, TCP_NODELAY, 1);
1224714747
14748=begin original
14749
14750Portability issues: L<perlport/setsockopt>.
14751
14752=end original
14753
14754移植性の問題: L<perlport/setsockopt>。
14755
1224814756=item shift ARRAY
1224914757X<shift>
1225014758
12251=item shift EXPR
12252
1225314759=item shift
1225414760
14761=for Pod::Functions remove the first element of an array, and return it
14762
1225514763=begin original
1225614764
1225714765Shifts the first value of the array off and returns it, shortening the
1225814766array by 1 and moving everything down. If there are no elements in the
1225914767array, returns the undefined value. If ARRAY is omitted, shifts the
12260C<@_> array within the lexical scope of subroutines and formats, and the
14768L<C<@_>|perlvar/@_> array within the lexical scope of subroutines and
12261C<@ARGV> array outside a subroutine and also within the lexical scopes
14769formats, and the L<C<@ARGV>|perlvar/@ARGV> array outside a subroutine
14770and also within the lexical scopes
1226214771established by the C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}>,
1226314772C<UNITCHECK {}>, and C<END {}> constructs.
1226414773
1226514774=end original
1226614775
12267配列の最初の値を取り出して、その値を返し、配列を一つ
14776配列の最初の値を取り出して、その値を返し、配列を一つ短くして、すべての要素を
12268短くして、すべての要素を前へずらします。
14777前へずらします。
1226914778配列に要素がなければ、未定義値を返します。
12270ARRAY を省略すると、
14779ARRAY を省略すると、サブルーチンやフォーマットのレキシカルスコープでは
12271サブルーチンやフォーマットレキシカルスコープC<@_> を、
14780L<C<@_>|perlvar/@_> を、サブルーチンの外側C<eval STRING>, C<BEGIN {}>,
12272サブルーチンの外側で、C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}>,
14781C<INIT {}>, C<CHECK {}>, C<UNITCHECK {}>, C<END {}> で作成された
12273C<UNITCHECK {}>, C<END {}> で作成されたレキシカルスコープでは
14782レキシカルスコープでは L<C<@ARGV>|perlvar/@ARGV> が用いられます。
12274C<@ARGV> が用いられます。
1227514783
1227614784=begin original
1227714785
12278Starting with Perl 5.14, C<shift> can take a scalar EXPR, which must hold a
14786Starting with Perl 5.14, an experimental feature allowed
12279reference to an unblessed array. The argument will be dereferenced
14787L<C<shift>|/shift ARRAY> to take a
12280automatically. This aspect of C<shift> is considered highly experimental.
14788scalar expression. This experiment has been deemed unsuccessful, and was
12281The exact behaviour may change in a future version of Perl.
14789removed as of Perl 5.24.
1228214790
1228314791=end original
1228414792
12285Perl 5.14 から、C<shift> スカラの EXPR を取ることができになりました;
14793Perl 5.14 から、L<C<shift>|/shift ARRAY> がスカラを取ることが出来とい
12286これは bless されていない配列へのリファレンスでなければなりません
14794実験的機能がありました
12287引数自動的にデリファレンスされま
14795この実験失敗と見なされ、Perl 5.24 で削除されした
12288C<shift> のこの動作は高度に実験的であると考えられています。
12289正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
1229014796
1229114797=begin original
1229214798
12293See also C<unshift>, C<push>, and C<pop>. C<shift> and C<unshift> do the
14799See also L<C<unshift>|/unshift ARRAY,LIST>, L<C<push>|/push ARRAY,LIST>,
12294same thing to the left end of an array that C<pop> and C<push> do to the
14800and L<C<pop>|/pop ARRAY>. L<C<shift>|/shift ARRAY> and
12295right end.
14801L<C<unshift>|/unshift ARRAY,LIST> do the same thing to the left end of
14802an array that L<C<pop>|/pop ARRAY> and L<C<push>|/push ARRAY,LIST> do to
14803the right end.
1229614804
1229714805=end original
1229814806
12299C<unshift>、C<push>、C<pop> も参照してください。
14807L<C<unshift>|/unshift ARRAY,LIST>、L<C<push>|/push ARRAY,LIST>、
12300C<shift> と C<unshift> は、C<pop>
14808L<C<pop>|/pop ARRAY> も参照してください。
12301C<push> が配列の右端で行なうこ左端で行ないます。
14809L<C<shift>|/shift ARRAY> L<C<unshift>|/unshift ARRAY,LIST> は
14810L<C<pop>|/pop ARRAY> と L<C<push>|/push ARRAY,LIST> が配列の右端で
14811行なうことを、左端で行ないます。
1230214812
1230314813=item shmctl ID,CMD,ARG
1230414814X<shmctl>
1230514815
14816=for Pod::Functions SysV shared memory operations
14817
1230614818=begin original
1230714819
1230814820Calls the System V IPC function shmctl. You'll probably have to say
1230914821
1231014822=end original
1231114823
12312System V IPC 関数 shmctl を呼び出します。正しい定数定義を得るために、まず
14824System V IPC 関数 shmctl を呼び出します。
14825正しい定数定義を得るために、まず
1231314826
1231414827 use IPC::SysV;
1231514828
1231614829=begin original
1231714830
1231814831first to get the correct constant definitions. If CMD is C<IPC_STAT>,
1231914832then ARG must be a variable that will hold the returned C<shmid_ds>
12320structure. Returns like ioctl: C<undef> for error; "C<0> but
14833structure. Returns like ioctl: L<C<undef>|/undef EXPR> for error; "C<0>
12321true" for zero; and the actual return value otherwise.
14834but true" for zero; and the actual return value otherwise.
12322See also L<perlipc/"SysV IPC"> and C<IPC::SysV> documentation.
14835See also L<perlipc/"SysV IPC"> and the documentation for
14836L<C<IPC::SysV>|IPC::SysV>.
1232314837
1232414838=end original
1232514839
12326宣言する必要があるでしょう。
14840書くことが必要でしょう。
1232714841CMD が、C<IPC_STAT> ならば、ARG は、返される C<shmid_ds> 構造体を
1232814842納める変数でなければなりません。
12329ioctl と同様です: エラー時には C<undef>; ゼロのときは "C<0> だが真";
14843ioctl と同様です: エラー時には L<C<undef>|/undef EXPR>; ゼロのときは
12330それ以外なら、その値そのものを返します。
14844"C<0> だが真"; それ以外なら、その値そのものを返します。
12331L<perlipc/"SysV IPC"> と C<IPC::SysV> も参照してください。
14845L<perlipc/"SysV IPC"> と L<C<IPC::SysV>|IPC::SysV> の文書も参照してください。
1233214846
14847=begin original
14848
14849Portability issues: L<perlport/shmctl>.
14850
14851=end original
14852
14853移植性の問題: L<perlport/shmctl>。
14854
1233314855=item shmget KEY,SIZE,FLAGS
1233414856X<shmget>
1233514857
14858=for Pod::Functions get SysV shared memory segment identifier
14859
1233614860=begin original
1233714861
1233814862Calls the System V IPC function shmget. Returns the shared memory
12339segment id, or C<undef> on error.
14863segment id, or L<C<undef>|/undef EXPR> on error.
12340See also L<perlipc/"SysV IPC"> and C<IPC::SysV> documentation.
14864See also L<perlipc/"SysV IPC"> and the documentation for
14865L<C<IPC::SysV>|IPC::SysV>.
1234114866
1234214867=end original
1234314868
1234414869System V IPC 関数 shmget を呼び出します。
12345共有メモリのセグメント ID か、エラー時には C<undef> を返します。
14870共有メモリのセグメント ID か、エラー時には L<C<undef>|/undef EXPR> を返します。
12346L<perlipc/"SysV IPC"> と C<IPC::SysV> も参照してください。
14871L<perlipc/"SysV IPC"> と L<C<IPC::SysV>|IPC::SysV> の文書も参照してください。
1234714872
14873=begin original
14874
14875Portability issues: L<perlport/shmget>.
14876
14877=end original
14878
14879移植性の問題: L<perlport/shmget>。
14880
1234814881=item shmread ID,VAR,POS,SIZE
1234914882X<shmread>
1235014883X<shmwrite>
1235114884
14885=for Pod::Functions read SysV shared memory
14886
1235214887=item shmwrite ID,STRING,POS,SIZE
1235314888
14889=for Pod::Functions write SysV shared memory
14890
1235414891=begin original
1235514892
1235614893Reads or writes the System V shared memory segment ID starting at
1235714894position POS for size SIZE by attaching to it, copying in/out, and
1235814895detaching from it. When reading, VAR must be a variable that will
1235914896hold the data read. When writing, if STRING is too long, only SIZE
1236014897bytes are used; if STRING is too short, nulls are written to fill out
1236114898SIZE bytes. Return true if successful, false on error.
12362shmread() taints the variable. See also L<perlipc/"SysV IPC">,
14899L<C<shmread>|/shmread ID,VAR,POS,SIZE> taints the variable. See also
12363C<IPC::SysV>, and the C<IPC::Shareable> module from CPAN.
14900L<perlipc/"SysV IPC"> and the documentation for
14901L<C<IPC::SysV>|IPC::SysV> and the L<C<IPC::Shareable>|IPC::Shareable>
14902module from CPAN.
1236414903
1236514904=end original
1236614905
12367System V 共有メモリセグメント ID に対し、アタッチして、
14906System V 共有メモリセグメント ID に対し、アタッチして、コピーを行ない、
12368コピーを行ない、デタッチするという形で、位置 POS から、
14907デタッチするという形で、位置 POS から、サイズ SIZE だけ、読み込みか書き込みを
12369サイズ SIZE だけ、読み込みか書き込みを行ないます。
14908行ないます。
12370読み込み時には、VAR は読み込んだデータを納める
14909読み込み時には、VAR は読み込んだデータを納める変数でなければなりません。
12371変数でなければなりせん。
14910書き込み時には、STRING が長すぎても、SIZE バイトだが使われます; STRING が
12372書き込み時には、STRING が長すぎても、SIZE バイトだけ使われます。
14911短すぎる場合には、SIZE バイトを埋めるために、ヌル文字書き込まれます。
12373STRING が短すぎる場合には、SIZE バイトを埋めるために、
12374ヌル文字が書き込まれます。
1237514912成功時には真を、エラー時には偽を返します。
12376shmread() は変数を汚染します。
14913L<C<shmread>|/shmread ID,VAR,POS,SIZE> は変数を汚染します。
12377L<perlipc/"SysV IPC"> および C<IPC::SysV> と
14914L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV> CPAN の
12378CPAN の C<IPC::Shareable> も参照してください。
14915L<C<IPC::Shareable>|IPC::Shareable> の文書も参照してください。
1237914916
14917=begin original
14918
14919Portability issues: L<perlport/shmread> and L<perlport/shmwrite>.
14920
14921=end original
14922
14923移植性の問題: L<perlport/shmread> と L<perlport/shmwrite>。
14924
1238014925=item shutdown SOCKET,HOW
1238114926X<shutdown>
1238214927
14928=for Pod::Functions close down just half of a socket connection
14929
1238314930=begin original
1238414931
1238514932Shuts down a socket connection in the manner indicated by HOW, which
1238614933has the same interpretation as in the syscall of the same name.
1238714934
1238814935=end original
1238914936
1239014937同名のシステムコールと同じように解釈される HOW によって、
1239114938指定された方法でソケット接続のシャットダウンを行ないます。
1239214939
12393 shutdown(SOCKET, 0); # I/we have stopped reading data
14940 shutdown($socket, 0); # I/we have stopped reading data
12394 shutdown(SOCKET, 1); # I/we have stopped writing data
14941 shutdown($socket, 1); # I/we have stopped writing data
12395 shutdown(SOCKET, 2); # I/we have stopped using this socket
14942 shutdown($socket, 2); # I/we have stopped using this socket
1239614943
1239714944=begin original
1239814945
1239914946This is useful with sockets when you want to tell the other
1240014947side you're done writing but not done reading, or vice versa.
1240114948It's also a more insistent form of close because it also
1240214949disables the file descriptor in any forked copies in other
1240314950processes.
1240414951
1240514952=end original
1240614953
1240714954これは、こちらがソケットを書き終わったが読み終わっていない、
1240814955またはその逆を相手側に伝えたいときに便利です。
1240914956これはその他のプロセスでフォークしたファイル記述子のコピーも
1241014957無効にするので、よりしつこい閉じ方です。
1241114958
1241214959=begin original
1241314960
12414Returns C<1> for success; on error, returns C<undef> if
14961Returns C<1> for success; on error, returns L<C<undef>|/undef EXPR> if
1241514962the first argument is not a valid filehandle, or returns C<0> and sets
12416C<$!> for any other failure.
14963L<C<$!>|perlvar/$!> for any other failure.
1241714964
1241814965=end original
1241914966
1242014967成功時には C<1> を返します;
12421エラーの場合、最初の引数が有効なファイルハンドルでない場合は C<undef> を
14968エラーの場合、最初の引数が有効なファイルハンドルでない場合は
12422返し、その他のエラーの場合は C<0> を返してC<$!> をセットします。
14969L<C<undef>|/undef EXPR> を返し、その他のエラーの場合は C<0> を返して
14970L<C<$!>|perlvar/$!> をセットします。
1242314971
1242414972=item sin EXPR
1242514973X<sin> X<sine> X<asin> X<arcsine>
1242614974
1242714975=item sin
1242814976
14977=for Pod::Functions return the sine of a number
14978
1242914979=begin original
1243014980
1243114981Returns the sine of EXPR (expressed in radians). If EXPR is omitted,
12432returns sine of C<$_>.
14982returns sine of L<C<$_>|perlvar/$_>.
1243314983
1243414984=end original
1243514985
1243614986(ラジアンで示した) EXPR の正弦を返します。
12437EXPR が省略されたときには、C<$_> の正弦を返します。
14987EXPR が省略されたときには、L<C<$_>|perlvar/$_> の正弦を返します。
1243814988
1243914989=begin original
1244014990
1244114991For the inverse sine operation, you may use the C<Math::Trig::asin>
1244214992function, or use this relation:
1244314993
1244414994=end original
1244514995
1244614996逆正弦を求めるためには、C<Math::Trig::asin> 関数を使うか、
1244714997以下の関係を使ってください:
1244814998
1244914999 sub asin { atan2($_[0], sqrt(1 - $_[0] * $_[0])) }
1245015000
1245115001=item sleep EXPR
1245215002X<sleep> X<pause>
1245315003
1245415004=item sleep
1245515005
15006=for Pod::Functions block for some number of seconds
15007
1245615008=begin original
1245715009
12458Causes the script to sleep for (integer) EXPR seconds, or forever if no
15010Causes the script to sleep for (integer) EXPR seconds, or forever if no
12459argument is given. Returns the integer number of seconds actually slept.
15011argument is given. Returns the integer number of seconds actually slept.
1246015012
1246115013=end original
1246215014
1246315015スクリプトを(整数の) EXPR で指定した秒数 (省略時には、永久に)
1246415016スリープさせます。
12465実際にスリープした秒数を返します。
15017実際にスリープした秒数を返します。
1246615018
1246715019=begin original
1246815020
1246915021May be interrupted if the process receives a signal such as C<SIGALRM>.
1247015022
1247115023=end original
1247215024
1247315025そのプロセスが C<SIGALRM>のようなシグナルを受信すると、
1247415026割り込みがかかります。
1247515027
1247615028 eval {
12477 local $SIG{ALARM} = sub { die "Alarm!\n" };
15029 local $SIG{ALRM} = sub { die "Alarm!\n" };
1247815030 sleep;
1247915031 };
1248015032 die $@ unless $@ eq "Alarm!\n";
1248115033
1248215034=begin original
1248315035
12484You probably cannot mix C<alarm> and C<sleep> calls, because C<sleep>
15036You probably cannot mix L<C<alarm>|/alarm SECONDS> and
12485is often implemented using C<alarm>.
15037L<C<sleep>|/sleep EXPR> calls, because L<C<sleep>|/sleep EXPR> is often
15038implemented using L<C<alarm>|/alarm SECONDS>.
1248615039
1248715040=end original
1248815041
12489C<sleep> は、C<alarm> を使って実装されることが多いので、C<alarm>
15042L<C<sleep>|/sleep EXPR> は、L<C<alarm>|/alarm SECONDS> を使って
12490C<sleep> は、混ぜて使用するこはおそらくできません。
15043実装されることが多いので、L<C<alarm>|/alarm SECONDS>
15044L<C<sleep>|/sleep EXPR> は、混ぜて使用することはおそらくできません。
1249115045
1249215046=begin original
1249315047
1249415048On some older systems, it may sleep up to a full second less than what
1249515049you requested, depending on how it counts seconds. Most modern systems
1249615050always sleep the full amount. They may appear to sleep longer than that,
1249715051however, because your process might not be scheduled right away in a
1249815052busy multitasking system.
1249915053
1250015054=end original
1250115055
1250215056古いシステムでは、どのように秒を数えるかによって、要求した秒数に完全に
1250315057満たないうちに、スリープから抜ける場合があります。
1250415058最近のシステムでは、常に完全にスリープします。
1250515059しかし、負荷の高いマルチタスクシステムでは
1250615060正しくスケジューリングされないがために
1250715061より長い時間スリープすることがあります。
1250815062
1250915063=begin original
1251015064
12511For delays of finer granularity than one second, the Time::HiRes module
15065For delays of finer granularity than one second, the L<Time::HiRes>
12512(from CPAN, and starting from Perl 5.8 part of the standard
15066module (from CPAN, and starting from Perl 5.8 part of the standard
12513distribution) provides usleep(). You may also use Perl's four-argument
15067distribution) provides L<C<usleep>|Time::HiRes/usleep ( $useconds )>.
12514version of select() leaving the first three arguments undefined, or you
15068You may also use Perl's four-argument
12515might be able to use the C<syscall> interface to access setitimer(2) if
15069version of L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> leaving the
12516your system supports it. See L<perlfaq8> for details.
15070first three arguments undefined, or you might be able to use the
15071L<C<syscall>|/syscall NUMBER, LIST> interface to access L<setitimer(2)>
15072if your system supports it. See L<perlfaq8> for details.
1251715073
1251815074=end original
1251915075
125201 秒より精度の高いスリープを行なうには、
150761 秒より精度の高いスリープを行なうには、L<Time::HiRes> モジュール(CPAN から、
12521Time::HiRes モジュール(CPAN から、また Perl 5.8 からは
15077また Perl 5.8 からは標準配布されています) が
12522標準配布されています) が usleep() を提供します。
15078L<C<usleep>|Time::HiRes/usleep ( $useconds )> を提供します。
12523Perl の 4 引数版 select() を最初の 3 引数を未定義にして使うか、
15079Perl の 4 引数版 L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を最初の
12524setitimer(2) をサポートしているシステムでは、Perl の
150803 引数を未定義にして使うか、L<setitimer(2)> をサポートしているシステムでは、
12525C<syscall> インタフェースを使ってアクセスすることもできます。
15081Perl の L<C<syscall>|/syscall NUMBER, LIST> インタフェースを使って
15082アクセスすることもできます。
1252615083詳しくは L<perlfaq8> を参照してください。
1252715084
1252815085=begin original
1252915086
12530See also the POSIX module's C<pause> function.
15087See also the L<POSIX> module's L<C<pause>|POSIX/C<pause>> function.
1253115088
1253215089=end original
1253315090
12534POSIX モジュールの C<pause> 関数も参照してさい。
15091L<POSIX> モジュールの L<C<pause>|POSIX/C<pause>> 関数も参照してください。
1253515092
1253615093=item socket SOCKET,DOMAIN,TYPE,PROTOCOL
1253715094X<socket>
1253815095
15096=for Pod::Functions create a socket
15097
1253915098=begin original
1254015099
1254115100Opens a socket of the specified kind and attaches it to filehandle
1254215101SOCKET. DOMAIN, TYPE, and PROTOCOL are specified the same as for
1254315102the syscall of the same name. You should C<use Socket> first
1254415103to get the proper definitions imported. See the examples in
1254515104L<perlipc/"Sockets: Client/Server Communication">.
1254615105
1254715106=end original
1254815107
12549指定した種類のソケットをオープンし、ファイルハンドル
15108指定した種類のソケットをオープンし、ファイルハンドル SOCKET にアタッチします。
12550SOCKET にアタッチします。
15109DOMAIN, TYPE, PROTOCOL は、同名のシステムコールと同じよう指定します。
12551DOMAINTYPEPROTOCOL は、
15110適切な定義を import するためにまず、C<use Socket> とするとよいでしょう。
12552同名システムコールと同じように指定ます
15111L<perlipc/"Sockets: Client/Server Communication"> 例を参照てください
12553適切な定義を import するために、まず、C<use Socket> と
12554するとよいでしょう。
12555例については L<perlipc/"Sockets: Client/Server Communication"> を
12556参照してください。
1255715112
1255815113=begin original
1255915114
1256015115On systems that support a close-on-exec flag on files, the flag will
1256115116be set for the newly opened file descriptor, as determined by the
12562value of $^F. See L<perlvar/$^F>.
15117value of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>.
1256315118
1256415119=end original
1256515120
1256615121ファイルに対する close-on-exec フラグをサポートしているシステムでは、
12567フラグは $^F の値で決定される、新しくオープンされたファイル記述子に対して
15122フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた
12568セットされます。
15123ファイル記述子に対してセットされます。
1256915124L<perlvar/$^F> を参照してください。
1257015125
1257115126=item socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL
1257215127X<socketpair>
1257315128
15129=for Pod::Functions create a pair of sockets
15130
1257415131=begin original
1257515132
1257615133Creates an unnamed pair of sockets in the specified domain, of the
1257715134specified type. DOMAIN, TYPE, and PROTOCOL are specified the same as
1257815135for the syscall of the same name. If unimplemented, raises an exception.
1257915136Returns true if successful.
1258015137
1258115138=end original
1258215139
1258315140指定した DOMAIN に、指定した TYPE で名前の無いソケットのペアを生成します。
12584DOMAINTYPEPROTOCOL は、同名のシステムコールと同じように指定します。
15141DOMAIN, TYPE, PROTOCOL は、同名のシステムコールと同じように指定します。
1258515142実装されていない場合には、例外が発生します。
1258615143成功時には真を返します。
1258715144
1258815145=begin original
1258915146
1259015147On systems that support a close-on-exec flag on files, the flag will
1259115148be set for the newly opened file descriptors, as determined by the value
12592of $^F. See L<perlvar/$^F>.
15149of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>.
1259315150
1259415151=end original
1259515152
1259615153ファイルに対する close-on-exec フラグをサポートしているシステムでは、
12597フラグは $^F の値で決定される、新しくオープンされたファイル記述子に対して
15154フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた
12598セットされます。
15155ファイル記述子に対してセットされます。
1259915156L<perlvar/$^F> を参照してください。
1260015157
1260115158=begin original
1260215159
12603Some systems defined C<pipe> in terms of C<socketpair>, in which a call
15160Some systems define L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> in terms of
12604to C<pipe(Rdr, Wtr)> is essentially:
15161L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL>, in
15162which a call to C<pipe($rdr, $wtr)> is essentially:
1260515163
1260615164=end original
1260715165
12608C<pipe> を C<socketpair> を使って定義しているシステムもあります;
15166L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> を
12609C<pipe(Rdr, Wtr)> は本質的には以下のようになります:
15167L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL> を使って
15168定義しているシステムもあります;
15169C<pipe($rdr, $wtr)> は本質的には以下のようになります:
1261015170
1261115171 use Socket;
12612 socketpair(Rdr, Wtr, AF_UNIX, SOCK_STREAM, PF_UNSPEC);
15172 socketpair(my $rdr, my $wtr, AF_UNIX, SOCK_STREAM, PF_UNSPEC);
12613 shutdown(Rdr, 1); # no more writing for reader
15173 shutdown($rdr, 1); # no more writing for reader
12614 shutdown(Wtr, 0); # no more reading for writer
15174 shutdown($wtr, 0); # no more reading for writer
1261515175
1261615176=begin original
1261715177
1261815178See L<perlipc> for an example of socketpair use. Perl 5.8 and later will
1261915179emulate socketpair using IP sockets to localhost if your system implements
1262015180sockets but not socketpair.
1262115181
1262215182=end original
1262315183
1262415184socketpair の使用例については L<perlipc> を参照してください。
1262515185Perl 5.8 以降では、システムがソケットを実装しているが socketpair を
1262615186実装していない場合、localhost に対して IP ソケットを使うことで
1262715187socketpair をエミュレートします。
1262815188
15189=begin original
15190
15191Portability issues: L<perlport/socketpair>.
15192
15193=end original
15194
15195移植性の問題: L<perlport/socketpair>。
15196
1262915197=item sort SUBNAME LIST
1263015198X<sort> X<qsort> X<quicksort> X<mergesort>
1263115199
1263215200=item sort BLOCK LIST
1263315201
1263415202=item sort LIST
1263515203
15204=for Pod::Functions sort a list of values
15205
1263615206=begin original
1263715207
1263815208In list context, this sorts the LIST and returns the sorted list value.
12639In scalar context, the behaviour of C<sort()> is undefined.
15209In scalar context, the behaviour of L<C<sort>|/sort SUBNAME LIST> is
15210undefined.
1264015211
1264115212=end original
1264215213
1264315214リストコンテキストでは、LIST をソートし、ソートされたリスト値を返します。
12644スカラコンテキストでは、C<sort()> の振る舞いは未定義です。
15215スカラコンテキストでは、L<C<sort>|/sort SUBNAME LIST> の振る舞いは未定義です。
1264515216
1264615217=begin original
1264715218
12648If SUBNAME or BLOCK is omitted, C<sort>s in standard string comparison
15219If SUBNAME or BLOCK is omitted, L<C<sort>|/sort SUBNAME LIST>s in
15220standard string comparison
1264915221order. If SUBNAME is specified, it gives the name of a subroutine
1265015222that returns an integer less than, equal to, or greater than C<0>,
12651depending on how the elements of the list are to be ordered. (The
15223depending on how the elements of the list are to be ordered. (The
1265215224C<< <=> >> and C<cmp> operators are extremely useful in such routines.)
1265315225SUBNAME may be a scalar variable name (unsubscripted), in which case
1265415226the value provides the name of (or a reference to) the actual
1265515227subroutine to use. In place of a SUBNAME, you can provide a BLOCK as
1265615228an anonymous, in-line sort subroutine.
1265715229
1265815230=end original
1265915231
12660SUBNAME や BLOCK を省略すると、標準の文字列比較の順番でソートが
15232SUBNAME や BLOCK を省略すると、L<C<sort>|/sort SUBNAME LIST> は標準の
12661行なわれます。
15233文字列比較の順番で行なわれます。
1266215234SUBNAME を指定すると、それは、リストの要素をどのような順番に並べるかに
12663応じて、負、ゼロ、正の整数を返すサブルーチンの名前であると解釈されます。
15235応じて、負の整数C<0>、正の整数を返すサブルーチンの名前であると解釈されます。
12664(このようなルーチンには、C<< <=> >> 演算子や cmp 演算子が、
15236(このようなルーチンには、C<< <=> >> 演算子や C<cmp> 演算子が、
1266515237たいへん便利です。)
12666SUBNAME は、スカラ変数名(添字なし)でもよく、
15238SUBNAME は、スカラ変数名(添字なし)でもよく、その場合には、その値が使用する
12667その場合には、その値が使用する実際のサブルーチンの
15239実際のサブルーチンの名前(またはそのリファレンス)と解釈されます。
12668前(またはそリファレス)解釈されます。
15240SUBNAME の代わりに、無名のラインソートルーチンして、BLOCK を
12669SUBNAME の代わりに、無名のインライン
15241書くことができます。
12670ソートルーチンとして、BLOCK を書くことができます。
1267115242
1267215243=begin original
1267315244
1267415245If the subroutine's prototype is C<($$)>, the elements to be compared are
12675passed by reference in C<@_>, as for a normal subroutine. This is slower
15246passed by reference in L<C<@_>|perlvar/@_>, as for a normal subroutine.
12676than unprototyped subroutines, where the elements to be compared are passed
15247This is slower than unprototyped subroutines, where the elements to be
12677into the subroutine as the package global variables $a and $b (see example
15248compared are passed into the subroutine as the package global variables
12678below). Note that in the latter case, it is usually highly counter-productive
15249C<$a> and C<$b> (see example below). Note that in the latter case, it
12679to declare $a and $b as lexicals.
15250is usually highly counter-productive to declare C<$a> and C<$b> as
15251lexicals.
1268015252
1268115253=end original
1268215254
12683サブルーチンのプロトタイプが C<($$)>の場合、
15255サブルーチンのプロトタイプが C<($$)>の場合、比較する要素は通常のサブルーチンと
12684比較する要素は通常のサブルーチンと同じように C<@_> の中に
15256同じように L<C<@_>|perlvar/@_> の中にリファレンスとして渡されます。
12685リファレンスとして渡さ
15257はプロトタイプなしのサブルーチンより遅いで; この場合は比較のため
12686これはプロトタイプなしのサブルーチンより遅いです。
15258サブルーチンに渡される二つの要素は、パッケージのグローバル変数 C<$a> と
12687この場合は比較のためサブルーチンに渡される二つ
15259C<$b> で渡されます(次例を参照してください)。
12688要素は、パッケージグローバ変数 $a と $b で渡されま
15260後者場合、レキシカ C<$a>C<$b> を宣言るのは普通とても
12689(次の例を参照してください)
15261逆効果になります
12690後者の場合、レキシカルに $a と $b を宣言するのは普通とても逆効果になります。
1269115262
1269215263=begin original
1269315264
15265If the subroutine is an XSUB, the elements to be compared are pushed on
15266to the stack, the way arguments are usually passed to XSUBs. C<$a> and
15267C<$b> are not set.
15268
15269=end original
15270
15271サブルーチンが XSUB の場合、比較される要素は、普通に引数を XSUB に渡す形で、
15272スタックにプッシュされます。
15273C<$a> と C<$b> は設定されません。
15274
15275=begin original
15276
1269415277The values to be compared are always passed by reference and should not
1269515278be modified.
1269615279
1269715280=end original
1269815281
12699$a や $b はリファレンスによって渡されるので、変更するべきではありません。
15282比較される値はリファレンスによって渡されるので、変更するべきではありません。
1270015283
1270115284=begin original
1270215285
1270315286You also cannot exit out of the sort block or subroutine using any of the
12704loop control operators described in L<perlsyn> or with C<goto>.
15287loop control operators described in L<perlsyn> or with
15288L<C<goto>|/goto LABEL>.
1270515289
1270615290=end original
1270715291
1270815292また、ソートブロックやサブルーチンから L<perlsyn> で説明されている
12709ループ制御子や C<goto> を使って抜けてはいけません。
15293ループ制御子や L<C<goto>|/goto LABEL> を使って抜けてはいけません。
1271015294
1271115295=begin original
1271215296
12713When C<use locale> is in effect, C<sort LIST> sorts LIST according to the
15297When L<C<use locale>|locale> (but not C<use locale ':not_characters'>)
15298is in effect, C<sort LIST> sorts LIST according to the
1271415299current collation locale. See L<perllocale>.
1271515300
1271615301=end original
1271715302
12718C<use locale> が有効の場合、C<sort LIST> は LIST を現在の比較ロケールに
15303L<C<use locale>|locale> が有効(そして C<use locale ':not_characters'>
12719従ってソートします。L<perllocale> を参照し下さい。
15304有効でない)の場合、C<sort LIST> は LIST 現在の比較ロケールに従っ
15305ソートします。
15306L<perllocale> を参照してください。
1272015307
1272115308=begin original
1272215309
12723sort() returns aliases into the original list, much as a for loop's index
15310L<C<sort>|/sort SUBNAME LIST> returns aliases into the original list,
12724variable aliases the list elements. That is, modifying an element of a
15311much as a for loop's index variable aliases the list elements. That is,
12725list returned by sort() (for example, in a C<foreach>, C<map> or C<grep>)
15312modifying an element of a list returned by L<C<sort>|/sort SUBNAME LIST>
15313(for example, in a C<foreach>, L<C<map>|/map BLOCK LIST> or
15314L<C<grep>|/grep BLOCK LIST>)
1272615315actually modifies the element in the original list. This is usually
1272715316something to be avoided when writing clear code.
1272815317
1272915318=end original
1273015319
12731sort() は元のリストへのエイリアスを返します; for ループのインデックス変数が
15320L<C<sort>|/sort SUBNAME LIST> は元のリストへのエイリアスを返します;
12732リスト要素へのエイリアスと同様です。
15321for ループのインデックス変数がリスト要素へのエイリアスと同様です。
12733つまり、sort() で返されるリストの要素を(例えば、C<foreach> や C<map> や
15322つまり、L<C<sort>|/sort SUBNAME LIST> で返されるリストの要素を(例えば、
12734C<grep> で)変更すると、実際に元のリストの要素が変更されます。
15323C<foreach> や L<C<map>|/map BLOCK LIST> や
12735これはきれいなコードを書くこと普通は回避できま
15324L<C<grep>|/grep BLOCK LIST> )変更ると、実際に元のリストの要素が
15325変更されます。
15326これはきれいなコードを書くときには普通は回避されます。
1273615327
1273715328=begin original
1273815329
1273915330Perl 5.6 and earlier used a quicksort algorithm to implement sort.
12740That algorithm was not stable, so I<could> go quadratic. (A I<stable> sort
15331That algorithm was not stable and I<could> go quadratic. (A I<stable> sort
1274115332preserves the input order of elements that compare equal. Although
1274215333quicksort's run time is O(NlogN) when averaged over all arrays of
1274315334length N, the time can be O(N**2), I<quadratic> behavior, for some
1274415335inputs.) In 5.7, the quicksort implementation was replaced with
1274515336a stable mergesort algorithm whose worst-case behavior is O(NlogN).
1274615337But benchmarks indicated that for some inputs, on some platforms,
12747the original quicksort was faster. 5.8 has a sort pragma for
15338the original quicksort was faster. 5.8 has a L<sort> pragma for
1274815339limited control of the sort. Its rather blunt control of the
1274915340underlying algorithm may not persist into future Perls, but the
1275015341ability to characterize the input or output in implementation
12751independent ways quite probably will. See L<the sort pragma|sort>.
15342independent ways quite probably will.
1275215343
1275315344=end original
1275415345
1275515346Perl 5.6 以前ではソートの実装にクイックソートアルゴリズムを使っていました。
12756このアルゴリズムは安定していないので、2 乗の時間が掛かる
15347このアルゴリズムは安定しておらず、2 乗の時間が掛かる I<可能性があります>。
12757I<可能性があります>。
1275815348(I<安定した> ソートは、比較した時に同じ要素の入力順が保存されます。
12759クイックソートの実行時間は、長さ N の全ての配列の平均では
15349クイックソートの実行時間は、長さ N の全ての配列の平均では O(NlogN) ですが、
12760O(NlogN) ですが、入力によっては O(N**2) という I<2 乗の> 振る舞いを
15350入力によっては O(N**2) という I<2 乗の> 振る舞いをすることがあります。)
12761ことがあります。)
153515.7 では、クイックソートによ実装は、最悪の場合の振る舞いも O(NlogN) である、
127625.7 では、クイックソートによる実装は、最悪の場合の振る舞いも
15352安定したマージソートアルゴリズム置き換えられました。
12763O(NlogN) である、安定マーソートアルゴリズムに置き換えられました。
15353かし、入力とプラットフォームによっては、ベンチマークはクイックソートの方が
12764しかし、入力とプラットフォームによっては、ベンチマークはクイックソートの
15354速くなります。
12765速くなります。
153555.8 ではソートを限定的に制御できる L<sort> プラグマります。
127665.8 ではソートを限定的に制御できる sort プラグマがあります。
1276715356この、アルゴリズムの直接的な制御方法は将来の perl では引き継がれないかも
1276815357しれませんが、実装に依存しない形で入力や出力を性格付ける機能は
1276915358おそらくあります。
12770L<the sort pragma|sort> を参照してください。
1277115359
1277215360=begin original
1277315361
1277415362Examples:
1277515363
1277615364=end original
1277715365
1277815366例:
1277915367
1278015368 # sort lexically
12781 @articles = sort @files;
15369 my @articles = sort @files;
12782
1278315371 # same thing, but with explicit sort routine
12784 @articles = sort {$a cmp $b} @files;
15372 my @articles = sort {$a cmp $b} @files;
12785
1278615374 # now case-insensitively
12787 @articles = sort {uc($a) cmp uc($b)} @files;
15375 my @articles = sort {fc($a) cmp fc($b)} @files;
12788
1278915377 # same thing in reversed order
12790 @articles = sort {$b cmp $a} @files;
15378 my @articles = sort {$b cmp $a} @files;
12791
1279215380 # sort numerically ascending
12793 @articles = sort {$a <=> $b} @files;
15381 my @articles = sort {$a <=> $b} @files;
12794
1279515383 # sort numerically descending
12796 @articles = sort {$b <=> $a} @files;
15384 my @articles = sort {$b <=> $a} @files;
12797
1279815386 # this sorts the %age hash by value instead of key
1279915387 # using an in-line function
12800 @eldest = sort { $age{$b} <=> $age{$a} } keys %age;
15388 my @eldest = sort { $age{$b} <=> $age{$a} } keys %age;
12801
1280215390 # sort using explicit subroutine name
1280315391 sub byage {
12804 $age{$a} <=> $age{$b}; # presuming numeric
15392 $age{$a} <=> $age{$b}; # presuming numeric
1280515393 }
12806 @sortedclass = sort byage @class;
15394 my @sortedclass = sort byage @class;
12807
1280815396 sub backwards { $b cmp $a }
12809 @harry = qw(dog cat x Cain Abel);
15397 my @harry = qw(dog cat x Cain Abel);
12810 @george = qw(gone chased yz Punished Axed);
15398 my @george = qw(gone chased yz Punished Axed);
1281115399 print sort @harry;
1281215400 # prints AbelCaincatdogx
1281315401 print sort backwards @harry;
1281415402 # prints xdogcatCainAbel
1281515403 print sort @george, 'to', @harry;
1281615404 # prints AbelAxedCainPunishedcatchaseddoggonetoxyz
1281715405
1281815406 # inefficiently sort by descending numeric compare using
1281915407 # the first integer after the first = sign, or the
1282015408 # whole record case-insensitively otherwise
1282115409
1282215410 my @new = sort {
1282315411 ($b =~ /=(\d+)/)[0] <=> ($a =~ /=(\d+)/)[0]
12824 ||
15412 ||
12825 uc($a) cmp uc($b)
15413 fc($a) cmp fc($b)
1282615414 } @old;
1282715415
1282815416 # same thing, but much more efficiently;
1282915417 # we'll build auxiliary indices instead
1283015418 # for speed
12831 my @nums = @caps = ();
15419 my (@nums, @caps);
1283215420 for (@old) {
1283315421 push @nums, ( /=(\d+)/ ? $1 : undef );
12834 push @caps, uc($_);
15422 push @caps, fc($_);
1283515423 }
1283615424
1283715425 my @new = @old[ sort {
12838 $nums[$b] <=> $nums[$a]
15426 $nums[$b] <=> $nums[$a]
12839 ||
15427 ||
12840 $caps[$a] cmp $caps[$b]
15428 $caps[$a] cmp $caps[$b]
12841 } 0..$#old
15429 } 0..$#old
12842 ];
15430 ];
1284315431
1284415432 # same thing, but without any temps
12845 @new = map { $_->[0] }
15433 my @new = map { $_->[0] }
1284615434 sort { $b->[1] <=> $a->[1]
12847 ||
15435 ||
12848 $a->[2] cmp $b->[2]
15436 $a->[2] cmp $b->[2]
12849 } map { [$_, /=(\d+)/, uc($_)] } @old;
15437 } map { [$_, /=(\d+)/, fc($_)] } @old;
1285015438
1285115439 # using a prototype allows you to use any comparison subroutine
1285215440 # as a sort subroutine (including other package's subroutines)
12853 package other;
15441 package Other;
12854 sub backwards ($$) { $_[1] cmp $_[0]; } # $a and $b are not set here
15442 sub backwards ($$) { $_[1] cmp $_[0]; } # $a and $b are
12855
15443 # not set here
1285615444 package main;
12857 @new = sort other::backwards @old;
15445 my @new = sort Other::backwards @old;
12858
1285915447 # guarantee stability, regardless of algorithm
1286015448 use sort 'stable';
12861 @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old;
15449 my @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old;
12862
1286315451 # force use of mergesort (not portable outside Perl 5.8)
1286415452 use sort '_mergesort'; # note discouraging _
12865 @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old;
15453 my @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old;
1286615454
1286715455=begin original
1286815456
1286915457Warning: syntactical care is required when sorting the list returned from
12870a function. If you want to sort the list returned by the function call
15458a function. If you want to sort the list returned by the function call
1287115459C<find_records(@key)>, you can use:
1287215460
1287315461=end original
1287415462
1287515463警告: 関数からかえされたリストをソートするときには文法上の注意が必要です。
1287615464関数呼び出し C<find_records(@key)> から返されたリストをソートしたい場合、
1287715465以下のように出来ます:
1287815466
12879 @contact = sort { $a cmp $b } find_records @key;
15467 my @contact = sort { $a cmp $b } find_records @key;
12880 @contact = sort +find_records(@key);
15468 my @contact = sort +find_records(@key);
12881 @contact = sort &find_records(@key);
15469 my @contact = sort &find_records(@key);
12882 @contact = sort(find_records(@key));
15470 my @contact = sort(find_records(@key));
1288315471
1288415472=begin original
1288515473
12886If instead you want to sort the array @key with the comparison routine
15474If instead you want to sort the array C<@key> with the comparison routine
1288715475C<find_records()> then you can use:
1288815476
1288915477=end original
1289015478
12891一方、配列 @key を比較ルーチン C<find_records()> でソートしたい場合は、
15479一方、配列 C<@key> を比較ルーチン C<find_records()> でソートしたい場合は、
1289215480以下のように出来ます:
1289315481
12894 @contact = sort { find_records() } @key;
15482 my @contact = sort { find_records() } @key;
12895 @contact = sort find_records(@key);
15483 my @contact = sort find_records(@key);
12896 @contact = sort(find_records @key);
15484 my @contact = sort(find_records @key);
12897 @contact = sort(find_records (@key));
15485 my @contact = sort(find_records (@key));
1289815486
1289915487=begin original
1290015488
12901If you're using strict, you I<must not> declare $a
15489You I<must not> declare C<$a>
12902and $b as lexicals. They are package globals. That means
15490and C<$b> as lexicals. They are package globals. That means
1290315491that if you're in the C<main> package and type
1290415492
1290515493=end original
1290615494
12907use strict している場合、$a と $b をレキシカルとして
15495C<$a>C<$b> をレキシカルとして宣言しては I<いけません>。
12908宣言しては I<いけません>。
1290915496これはパッケージグローバルです。
1291015497つまり、C<main> パッケージで以下のように書いた場合:
1291115498
12912 @articles = sort {$b <=> $a} @files;
15499 my @articles = sort {$b <=> $a} @files;
1291315500
1291415501=begin original
1291515502
1291615503then C<$a> and C<$b> are C<$main::a> and C<$main::b> (or C<$::a> and C<$::b>),
1291715504but if you're in the C<FooPack> package, it's the same as typing
1291815505
1291915506=end original
1292015507
1292115508C<$a> と C<$b> は C<$main::a> と C<$main::b> (または C<$::a> と C<$::b>) を
1292215509意味しますが、C<FooPack> パッケージ内の場合、これは以下と同じになります:
1292315510
12924 @articles = sort {$FooPack::b <=> $FooPack::a} @files;
15511 my @articles = sort {$FooPack::b <=> $FooPack::a} @files;
1292515512
1292615513=begin original
1292715514
1292815515The comparison function is required to behave. If it returns
1292915516inconsistent results (sometimes saying C<$x[1]> is less than C<$x[2]> and
1293015517sometimes saying the opposite, for example) the results are not
1293115518well-defined.
1293215519
1293315520=end original
1293415521
1293515522比較関数は一貫した振る舞いをすることが求められます。
1293615523一貫しない結果を返す(例えば、あるときは C<$x[1]> が C<$x[2]> より
1293715524小さいと返し、またあるときは逆を返す)場合、結果は未定義です。
1293815525
1293915526=begin original
1294015527
12941Because C<< <=> >> returns C<undef> when either operand is C<NaN>
15528Because C<< <=> >> returns L<C<undef>|/undef EXPR> when either operand
12942(not-a-number), and laso because C<sort> raises an exception unless the
15529is C<NaN> (not-a-number), be careful when sorting with a
12943result of a comparison is defined, be careful when sorting with a
1294415530comparison function like C<< $a <=> $b >> any lists that might contain a
1294515531C<NaN>. The following example takes advantage that C<NaN != NaN> to
1294615532eliminate any C<NaN>s from the input list.
1294715533
1294815534=end original
1294915535
1295015536C<< <=> >> はどちらかのオペランドが C<NaN> (not-a-number) のときに
12951C<undef> を返、C<sort> 比較の結果が未定義値だと例外が発生するの
15537L<C<undef>|/undef EXPR> を返すので、C<< $a <=> $b >> といった比較関数
12952C<< $a <=> $b >> といった比較関数でソートする場合はリストに C<NaN> が
15538ソートする場合はリストに C<NaN> が含まれないように注意してください。
12953含まれないように注意してください。
1295415539以下の例は 入力リストから C<NaN> を取り除くために C<NaN != NaN> という性質を
1295515540利用しています。
1295615541
12957 @result = sort { $a <=> $b } grep { $_ == $_ } @input;
15542 my @result = sort { $a <=> $b } grep { $_ == $_ } @input;
1295815543
12959=item splice ARRAY or EXPR,OFFSET,LENGTH,LIST
15544=item splice ARRAY,OFFSET,LENGTH,LIST
1296015545X<splice>
1296115546
12962=item splice ARRAY or EXPR,OFFSET,LENGTH
15547=item splice ARRAY,OFFSET,LENGTH
1296315548
12964=item splice ARRAY or EXPR,OFFSET
15549=item splice ARRAY,OFFSET
1296515550
12966=item splice ARRAY or EXPR
15551=item splice ARRAY
1296715552
15553=for Pod::Functions add or remove elements anywhere in an array
15554
1296815555=begin original
1296915556
1297015557Removes the elements designated by OFFSET and LENGTH from an array, and
1297115558replaces them with the elements of LIST, if any. In list context,
1297215559returns the elements removed from the array. In scalar context,
12973returns the last element removed, or C<undef> if no elements are
15560returns the last element removed, or L<C<undef>|/undef EXPR> if no
15561elements are
1297415562removed. The array grows or shrinks as necessary.
1297515563If OFFSET is negative then it starts that far from the end of the array.
1297615564If LENGTH is omitted, removes everything from OFFSET onward.
1297715565If LENGTH is negative, removes the elements from OFFSET onward
1297815566except for -LENGTH elements at the end of the array.
12979If both OFFSET and LENGTH are omitted, removes everything. If OFFSET is
15567If both OFFSET and LENGTH are omitted, removes everything. If OFFSET is
12980past the end of the array, Perl issues a warning, and splices at the
15568past the end of the array and a LENGTH was provided, Perl issues a warning,
12981end of the array.
15569and splices at the end of the array.
1298215570
1298315571=end original
1298415572
1298515573ARRAY から OFFSET、LENGTH で指定される要素を取り除き、
1298615574LIST があれば、それを代わりに挿入します。
1298715575リストコンテキストでは、配列から取り除かれた要素を返します。
12988スカラコンテキストでは、取り除かれた最後の要素を返します
15576スカラコンテキストでは、取り除かれた最後の要素を返します; 要素が
12989要素が取り除かれなかった場合は C<undef> を返します。
15577取り除かれなかった場合は L<C<undef>|/undef EXPR> を返します。
1299015578配列は、必要に応じて、大きくなったり、小さくなったりします。
1299115579OFFSET が負の数の場合は、配列の最後からの距離を示します。
1299215580LENGTH が省略されると、OFFSET 以降のすべての要素を取り除きます。
1299315581LENGTH が負の数の場合は、OFFSET から前方へ、配列の最後から -LENGTH 要素を
1299415582除いて取り除きます。
1299515583OFFSET と LENGTH の両方が省略されると、全ての要素を取り除きます。
12996OFFSET が配列の最後より後ろの場合、Perl は警告を出し、配列の最後に対して
15584OFFSET が配列の最後より後ろ LENGTH が指定されていると、Perl は警告を出し、
12997処理します。
15585配列の最後に対して処理します。
1299815586
1299915587=begin original
1300015588
13001The following equivalences hold (assuming C<< $[ == 0 and $#a >= $i >> )
15589The following equivalences hold (assuming C<< $#a >= $i >> )
1300215590
1300315591=end original
1300415592
13005以下は、(C<< $[ == 0 と $#a >= $i >> と仮定すると) それぞれ、等価です。
15593以下は、(C<< $#a >= $i >> と仮定すると) それぞれ、等価です。
1300615594
1300715595 push(@a,$x,$y) splice(@a,@a,0,$x,$y)
1300815596 pop(@a) splice(@a,-1)
1300915597 shift(@a) splice(@a,0,1)
1301015598 unshift(@a,$x,$y) splice(@a,0,0,$x,$y)
1301115599 $a[$i] = $y splice(@a,$i,1,$y)
1301215600
1301315601=begin original
1301415602
13015Example, assuming array lengths are passed before arrays:
15603L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> can be used, for example,
15604to implement n-ary queue processing:
1301615605
1301715606=end original
1301815607
13019次の例では、配列の前にそれぞれ配列の大きさが渡されるものとしています:
15608L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> は、例えばn-ary キュー処理
15609実装に使えます:
1302015610
13021 sub aeq { # compare two list values
15611 sub nary_print {
13022 my(@a) = splice(@_,0,shift);
15612 my $n = shift;
13023 my(@b) = splice(@_,0,shift);
15613 while (my @next_n = splice @_, 0, $n) {
13024 return 0 unless @a == @b; # same len?
15614 say join q{ -- }, @next_n;
13025 while (@a) {
15615 }
13026 return 0 if pop(@a) ne pop(@b);
13027 }
13028 return 1;
1302915616 }
13030 if (&aeq($len,@foo[1..$len],0+@bar,@bar)) { ... }
1303115617
15618 nary_print(3, qw(a b c d e f g h));
15619 # prints:
15620 # a -- b -- c
15621 # d -- e -- f
15622 # g -- h
15623
1303215624=begin original
1303315625
13034Starting with Perl 5.14, C<splice> can take scalar EXPR, which must hold a
15626Starting with Perl 5.14, an experimental feature allowed
13035reference to an unblessed array. The argument will be dereferenced
15627L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> to take a
13036automatically. This aspect of C<splice> is considered highly experimental.
15628scalar expression. This experiment has been deemed unsuccessful, and was
13037The exact behaviour may change in a future version of Perl.
15629removed as of Perl 5.24.
1303815630
1303915631=end original
1304015632
13041Perl 5.14 から、C<splice> スカラの EXPR 取ることができるようになりました;
15633Perl 5.14 から、L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> がスカラ
13042れは bless されてない配列へのリファレンスでなければなりません
15634取るとが出来るとう実験的機能がありました
13043引数自動的にデリファレンスされま
15635この実験失敗と見なされ、Perl 5.24 で削除されした
13044C<splice> のこの動作は高度に実験的であると考えられています。
13045正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
1304615636
1304715637=item split /PATTERN/,EXPR,LIMIT
1304815638X<split>
1304915639
1305015640=item split /PATTERN/,EXPR
1305115641
1305215642=item split /PATTERN/
1305315643
1305415644=item split
1305515645
15646=for Pod::Functions split up a string using a regexp delimiter
15647
1305615648=begin original
1305715649
13058Splits the string EXPR into a list of strings and returns that list. By
15650Splits the string EXPR into a list of strings and returns the
13059default, empty leading fields are preserved, and empty trailing ones are
15651list in list context, or the size of the list in scalar context.
13060deleted. (If all fields are empty, they are considered to be trailing.)
1306115652
1306215653=end original
1306315654
13064文字列 EXPR を文字列のリストに分割して、リストを返します。
15655文字列 EXPR を文字列のリストに分割して、リストコンテキストではそのリスト
13065デフォルトでは、行頭空白は保存れ、末尾の空白は削除されます。
15656返し、スカラコンテキストではリスト大きを返します。
13066(全てのフィールドが空の場合、これらは末尾であるとして扱われます。)
1306715657
1306815658=begin original
1306915659
13070In scalar context, returns the number of fields found.
15660If only PATTERN is given, EXPR defaults to L<C<$_>|perlvar/$_>.
1307115661
1307215662=end original
1307315663
13074スカラコンテキストでは、見つかったフィードの数を返します。
15664PATTERN のみが与えられ場合、EXPR のデトは L<C<$_>|perlvar/$_> です。
1307515665
1307615666=begin original
1307715667
13078If EXPR is omitted, splits the C<$_> string. If PATTERN is also omitted,
15668Anything in EXPR that matches PATTERN is taken to be a separator
13079splits on whitespace (after skipping any leading whitespace). Anything
15669that separates the EXPR into substrings (called "I<fields>") that
13080matching PATTERN is taken to be a delimiter separating the fields. (Note
15670do B<not> include the separator. Note that a separator may be
13081that the delimiter may be longer than one character.)
15671longer than one character or even have no characters at all (the
15672empty string, which is a zero-width match).
1308215673
1308315674=end original
1308415675
13085EXPR を省略すると、文字列 C<$_> split します。
15676EXPR の中で PATTERN にマッチングするものは何でも EXPR("I<fields>"
13086もし、PATTERN も省略すると、
15677呼ばれる)セパレータを B<含まない> 部分文字列に分割するための
13087(先頭の空白文字をスキップした後) 空白で split します。
15678セパレータとなります。
13088PATTERN にマッチするものは、フィルドを分割するデリミとし扱われます。
15679セパレータは一文字より長くもよく、全く文字がなくてもよい(空文字列は
13089(デリミタは、1 文字は限りません)
15680ゼロ幅マッチングです)いうことに注意してください
1309015681
1309115682=begin original
1309215683
13093If LIMIT is specified and positive, it represents the maximum number
15684The PATTERN need not be constant; an expression may be used
13094of fields the EXPR will be split into, though the actual number of
15685to specify a pattern that varies at runtime.
13095fields returned depends on the number of times PATTERN matches within
13096EXPR. If LIMIT is unspecified or zero, trailing null fields are
13097stripped (which potential users of C<pop> would do well to remember).
13098If LIMIT is negative, it is treated as if an arbitrarily large LIMIT
13099had been specified. Note that splitting an EXPR that evaluates to the
13100empty string always returns the empty list, regardless of the LIMIT
13101specified.
1310215686
1310315687=end original
1310415688
13105正の数の LIMIT を指した場合に、EXPR が分割されるフィルドの最大数
15689PATTERN 数である必要ありません; 実行時に変更されるパタ
13106表しまが、実際に返されフィールドの数は EXPR の中で何回 PATTERN が
15690指定するために式を使えます。
13107マッチするかに依存します。
13108LIMIT を指定しないかゼロなら、末尾の空フィールドを捨ててしまいます
13109(C<pop> を行なうときには気を付けないといけません)。
13110LIMIT が負ならば、LIMIT に任意の大きな数を指定したのと同じことになります。
13111空文字列に評価される EXPR を分割する場合、LIMIT での指定に関わらず
13112常に空のリストが返ることに注意してください。
1311315691
1311415692=begin original
1311515693
13116A pattern matching the empty string (not to be confused with
15694If PATTERN matches the empty string, the EXPR is split at the match
13117an empty pattern C<//>, which is just one member of the set of patterns
15695position (between characters). As an example, the following:
13118matching the epmty string), splits EXPR into individual
13119characters. For example:
1312015696
1312115697=end original
1312215698
13123空文字列にマッチするパターン (空パター C<//> と混同しないでください。
15699PATTERN が空文字列にマッチングする場合、EXPR はマッチグ位置
13124これは、空文字列にマッチするパターン一つしかありせん) は、
15700(文字の間)分割されす。
13125場所にマッチし、EXPR を 1 文字ずつに分割します。
15701例えば、以下のものは:
13126例えば:
1312715702
13128 print join(':', split(/ */, 'hi there')), "\n";
15703 print join(':', split(/b/, 'abc')), "\n";
1312915704
1313015705=begin original
1313115706
13132produces the output 'h:i:t:h:e:r:e'.
15707uses the C<b> in C<'abc'> as a separator to produce the output C<a:c>.
15708However, this:
1313315709
1313415710=end original
1313515711
13136は、'h:i:t:h:e:r:e' という出力になります。
15712C<'abc'> の C<b> をセパレータして使って出力 C<a:c> を生成します。
15713しかし、これは:
1313715714
15715 print join(':', split(//, 'abc')), "\n";
15716
1313815717=begin original
1313915718
13140As a special case for C<split>, the empty pattern C<//> specifically
15719uses empty string matches as separators to produce the output
13141matches the empty string; this is not be confused with the normal use
15720C<a:b:c>; thus, the empty string may be used to split EXPR into a
13142of an empty pattern to mean the last successful match. So to split
15721list of its component characters.
13143a string into individual characters, the following:
1314415722
1314515723=end original
1314615724
13147C<split> に関する特別な場合として、特に空パ C<//> は空文字列に
15725文字列マッチングをセタとして使って出力 C<a:b:c> を生成します; 従って、
13148マッチするので、最後成功したマッチングを意味する通常の C<//> の
15726空文字列は EXPR を構成する文字リスト分割するために使われます。
13149使用法と混乱しないようにしてください。
13150それで、文字列を個々の文字に分割する場合は、以下のようにすると:
1315115727
13152 print join(':', split(//, 'hi there')), "\n";
15728=begin original
1315315729
15730As a special case for L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>,
15731the empty pattern given in
15732L<match operator|perlop/"m/PATTERN/msixpodualngc"> syntax (C<//>)
15733specifically matches the empty string, which is contrary to its usual
15734interpretation as the last successful match.
15735
15736=end original
15737
15738L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> の特殊な場合として、
15739L<マッチング演算子|perlop/"m/PATTERN/msixpodualngc"> 文法で与えられた
15740空パターン (C<//>) は特に空文字列にマッチングし、最後に成功した
15741マッチングという普通の解釈と異なります。
15742
1315415743=begin original
1315515744
13156produces the output 'h:i: :t:h:e:r:e'.
15745If PATTERN is C</^/>, then it is treated as if it used the
15746L<multiline modifier|perlreref/OPERATORS> (C</^/m>), since it
15747isn't much use otherwise.
1315715748
1315815749=end original
1315915750
13160'h:i: :t:h:e:r:e' という出力になります。
15751PATTERN が C</^/> の場合、L<複数行修飾子|perlreref/OPERATORS>
15752(C</^/m>) が使われたかのように扱われます; そうでなければほとんど
15753使えないからです。
1316115754
1316215755=begin original
1316315756
13164Empty leading fields are produced when there are positive-width matches at
15757As another special case,
13165the beginning of the string; a zero-width match at the beginning of
15758L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> emulates the default
13166the string does not produce an empty field. For example:
15759behavior of the
15760command line tool B<awk> when the PATTERN is either omitted or a
15761string composed of a single space character (such as S<C<' '>> or
15762S<C<"\x20">>, but not e.g. S<C</ />>). In this case, any leading
15763whitespace in EXPR is removed before splitting occurs, and the PATTERN is
15764instead treated as if it were C</\s+/>; in particular, this means that
15765I<any> contiguous whitespace (not just a single space character) is used as
15766a separator. However, this special treatment can be avoided by specifying
15767the pattern S<C</ />> instead of the string S<C<" ">>, thereby allowing
15768only a single space character to be a separator. In earlier Perls this
15769special case was restricted to the use of a plain S<C<" ">> as the
15770pattern argument to split; in Perl 5.18.0 and later this special case is
15771triggered by any expression which evaluates to the simple string S<C<" ">>.
1316715772
1316815773=end original
1316915774
13170先頭空フィールドは、文字列の先頭で 0 でい幅でマッチした場合
15775もう一つ特別な場合として、
13171生成されます。
15776L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> は
13172 0 でマッチした場合は生成されません。
15777PATTERN が省略されるか単一のスペース文字からなる文字列 (つり例えば
13173例えば:
15778S<C</ />> ではなく S<C<' '>> や S<C<"\x20">>) の場合、コマンドラインツール
15779B<awk> のデフォルトの振る舞いをエミュレートします。
15780この場合、EXPR の先頭の空白は分割を行う前に削除され、PATTERN は
15781C</\s+/> であったかのように扱われます; 特に、これは (単に単一の
15782スペース文字ではなく) I<あらゆる> 連続した空白がセパレータとして
15783使われるということです。
15784しかし、この特別の扱いは文字列 S<C<" ">> の代わりにパターン S<C</ />> を
15785指定することで回避でき、それによってセパレータとして単一の
15786スペース文字のみが使われます。
15787以前の Perl ではこの特別な場合は split のパターン引数として単に S<C<" ">> を
15788使った場合に制限されていました; Perl 5.18.0 以降では、この特別な場合は
15789単純な文字列 S<C<" ">> と評価される任意の式によって引き起こされます。
1317415790
13175 print join(':', split(/(?=\w)/, 'hi there!'));
15791=begin original
1317615792
15793If omitted, PATTERN defaults to a single space, S<C<" ">>, triggering
15794the previously described I<awk> emulation.
15795
15796=end original
15797
15798省略されると、PATTERN のデフォルトは単一のスペース S<C<" ">> になり、
15799先に記述した I<awk> エミュレーションを起動します。
15800
1317715801=begin original
1317815802
13179produces the output 'h:i :t:h:e:r:e!'. Empty trailing fields, on the other
15803If LIMIT is specified and positive, it represents the maximum number
13180hand, are produced when there is a match at the end of the string (and
15804of fields into which the EXPR may be split; in other words, LIMIT is
13181when LIMIT is given and is not 0), regardless of the length of the match.
15805one greater than the maximum number of times EXPR may be split. Thus,
13182For example:
15806the LIMIT value C<1> means that EXPR may be split a maximum of zero
15807times, producing a maximum of one field (namely, the entire value of
15808EXPR). For instance:
1318315809
1318415810=end original
1318515811
13186れの出力は 'h:i :t:h:e:r:e!' となります。
15812LIMIT が指定さた正数場合、EXPR が分割されるフィールドの最大数を
13187一方末尾の空フィールド、マッチングの長に関わらず、文字列の最後に
15813表現します; 言い換えると LIMIT EXPR が分割れる数より一つ大きい数です。
13188マッチングした(そし LIMIT が与えられてそれが 0 でなかった)場合に
15814従っLIMIT の値 C<1> は EXPR 最大 0 回分割されるということ
13189生成されます。
15815最大で一つのフィールドを生成ます (言い換えると、EXPR 全体の値です)
1319015816例えば:
1319115817
13192 print join(':', split(//, 'hi there!', -1)), "\n";
15818 print join(':', split(//, 'abc', 1)), "\n";
13193 print join(':', split(/\W/, 'hi there!', -1)), "\n";
1319415819
1319515820=begin original
1319615821
13197produce the output 'h:i: :t:h:e:r:e:!:' and 'hi:there:', respectively,
15822produces the output C<abc>, and this:
13198both with an empty trailing field.
1319915823
1320015824=end original
1320115825
13202これの出力それぞれ 'h:i :t:h:e:r:e:!:' および 'hi:there:' となり
15826これは C<abc> を出力し次のものは:
13203両方とも末尾に空フィールドが付きます。
1320415827
15828 print join(':', split(//, 'abc', 2)), "\n";
15829
1320515830=begin original
1320615831
13207The LIMIT parameter can be used to split a line partially
15832produces the output C<a:bc>, and each of these:
1320815833
1320915834=end original
1321015835
13211LIMIT使うと行を部分的に split することができます。
15836C<a:bc>出力し以下のものそれぞれは:
1321215837
13213 ($login, $passwd, $remainder) = split(/:/, $_, 3);
15838 print join(':', split(//, 'abc', 3)), "\n";
15839 print join(':', split(//, 'abc', 4)), "\n";
1321415840
1321515841=begin original
1321615842
13217When assigning to a list, if LIMIT is omitted, or zero, Perl supplies
15843produces the output C<a:b:c>.
13218a LIMIT one larger than the number of variables in the list, to avoid
13219unnecessary work. For the list above LIMIT would have been 4 by
13220default. In time critical applications it behooves you not to split
13221into more fields than you really need.
1322215844
1322315845=end original
1322415846
13225リストへ代入するとき、LIMIT省略るか 0 の場合、Perl は、
15847C<a:b:c>出力しま
13226無駄な仕事を避けるため、そのリストの変数の数より、1 つだけ大きい
13227LIMIT が与えられたものとして処理を行ないます。
13228上のリストの場合には、LIMIT はデフォルトで 4 になります。
13229時間が問題となるアプリケーションでは、
13230必要以上のフィールドに分けないようにする必要があります。
1323115848
1323215849=begin original
1323315850
13234If the PATTERN contains parentheses, additional list elements are
15851If LIMIT is negative, it is treated as if it were instead arbitrarily
13235created from each matching substring in the delimiter.
15852large; as many fields as possible are produced.
1323615853
1323715854=end original
1323815855
13239PATTERN に括弧含まれていると、デリミタ内部分文字列マッチするも、
15856LIMIT が負数なら、非常に大き数であよう扱われま; できだけ多く
13240リスト要素に含まるようになります。
15857フィールドが生成されます。
1324115858
13242 split(/([,-])/, "1-10,20", 3);
15859=begin original
1324315860
15861If LIMIT is omitted (or, equivalently, zero), then it is usually
15862treated as if it were instead negative but with the exception that
15863trailing empty fields are stripped (empty leading fields are always
15864preserved); if all fields are empty, then all fields are considered to
15865be trailing (and are thus stripped in this case). Thus, the following:
15866
15867=end original
15868
15869LIMIT が省略されると(あるいは等価な 0 なら)、普通は負数が指定されたかのように
15870動作しますが、末尾の空フィールドは取り除かれるという例外があります
15871(先頭の空フィールドは常に保存されます); もし全てのフィールドが空なら、
15872全てのフィールドが末尾として扱われます(そしてこの場合取り除かれます)。
15873従って、以下のようにすると:
15874
15875 print join(':', split(/,/, 'a,b,c,,,')), "\n";
15876
1324415877=begin original
1324515878
13246produces the list value
15879produces the output C<a:b:c>, but the following:
1324715880
1324815881=end original
1324915882
13250は、以下のリスト値を生成します
15883出力 C<a:b:c> を生成しますが、以下のようにすると:
1325115884
13252 (1, '-', 10, ',', 20)
15885 print join(':', split(/,/, 'a,b,c,,,', -1)), "\n";
1325315886
1325415887=begin original
1325515888
13256If you had the entire header of a normal Unix email message in $header,
15889produces the output C<a:b:c:::>.
13257you could split it up into fields and their values this way:
1325815890
1325915891=end original
1326015892
13261$header に Unix E メールメッセージヘッダ全体が入っているとると、
15893出力 C<a:b:c:::> を生成しま
13262以下のようにしてフィールドとその値に分割できます:
1326315894
13264 $header =~ s/\n(?=\s)//g; # fix continuation lines
15895=begin original
13265 %hdrs = (UNIX_FROM => split /^(\S*?):\s*/m, $header);
1326615896
15897In time-critical applications, it is worthwhile to avoid splitting
15898into more fields than necessary. Thus, when assigning to a list,
15899if LIMIT is omitted (or zero), then LIMIT is treated as though it
15900were one larger than the number of variables in the list; for the
15901following, LIMIT is implicitly 3:
15902
15903=end original
15904
15905時間に厳しいアプリケーションでは、必要でないフィールドの分割を避けるのは
15906価値があります。
15907従って、リストに代入される場合に、LIMIT が省略される(または 0)と、
15908LIMIT は リストにある変数の数より一つ大きい数のように扱われます;
15909次の場合、LIMIT は暗黙に 3 になります:
15910
15911 my ($login, $passwd) = split(/:/);
15912
1326715913=begin original
1326815914
13269The pattern C</PATTERN/> may be replaced with an expression to specify
15915Note that splitting an EXPR that evaluates to the empty string always
13270patterns that vary at runtime. (To do runtime compilation only once,
15916produces zero fields, regardless of the LIMIT specified.
13271use C</$variable/o>.)
1327215917
1327315918=end original
1327415919
13275/PATTERN/ は、実行時わるパターン指定する式で置き換えるこができます。
15920LIMIT の指定らず、空文字列に評価され EXPR 分割すると常に 0 個の
13276(実行時のコンパイルを 1 度にするため、/$variable/o を使ってください。)
15921フィー生成すること注意してください。
1327715922
1327815923=begin original
1327915924
13280As a special case, specifying a PATTERN of space (S<C<' '>>) will split on
15925An empty leading field is produced when there is a positive-width
13281white space just as C<split> with no arguments does. Thus, S<C<split(' ')>> can
15926match at the beginning of EXPR. For instance:
13282be used to emulate B<awk>'s default behavior, whereas S<C<split(/ /)>>
13283will give you as many initial null fields (empty string) as there are leading spaces.
13284A C<split> on C</\s+/> is like a S<C<split(' ')>> except that any leading
13285whitespace produces a null first field. A C<split> with no arguments
13286really does a S<C<split(' ', $_)>> internally.
1328715927
1328815928=end original
1328915929
13290特別な場合として、PATTERNスペス (S<C<' '>>) を指定すると、
15930EXPR の先頭で正数幅でマッチングしたときは先頭に空のフィルドが
13291引数なしの C<split> のように空白で split を行ないます。
15931生成されます。
13292つまり、S<C<split(' ')>> は B<awk> のデフォルトの動作をエミュレートするために
15932例えば:
13293使うことができ、S<C<split(/ /)>> は行頭のスペースの数に応じた空フィールド
13294(空文字列)ができます。
13295C<split /\s+/> は S<C<split(' ')>> と同様ですが、
13296先頭の空白は先頭の空フィールドとなります。
13297引数なしの C<split> は内部的には S<C<split(' ', $_)>> を実行します。
1329815933
15934 print join(':', split(/ /, ' abc')), "\n";
15935
1329915936=begin original
1330015937
13301A PATTERN of C</^/> is treated as if it were C</^/m>, since it isn't
15938produces the output C<:abc>. However, a zero-width match at the
13302much use otherwise.
15939beginning of EXPR never produces an empty field, so that:
1330315940
1330415941=end original
1330515942
13306PATTERN C</^/> を指定すると C</^/m> とて扱われます。
15943これは出力 C<:abc> を生成します。
13307意味に使われることまずないからす。
15944しかし、EXPR 先頭でのゼロ幅マッチング決して空フィールドを生成しない:
1330815945
15946 print join(':', split(//, ' abc'));
15947
1330915948=begin original
1331015949
13311Example:
15950produces the output S<C< :a:b:c>> (rather than S<C<: :a:b:c>>).
1331215951
1331315952=end original
1331415953
13315:
15954これは(S<C<: :a:b:c>> ではなく)出力 S<C< :a:b:c>> を生成します。
1331615955
13317 open(PASSWD, '/etc/passwd');
15956=begin original
13318 while (<PASSWD>) {
13319 chomp;
13320 ($login, $passwd, $uid, $gid,
13321 $gcos, $home, $shell) = split(/:/);
13322 #...
13323 }
1332415957
15958An empty trailing field, on the other hand, is produced when there is a
15959match at the end of EXPR, regardless of the length of the match
15960(of course, unless a non-zero LIMIT is given explicitly, such fields are
15961removed, as in the last example). Thus:
15962
15963=end original
15964
15965一方、末尾の空のフィールドは、マッチングの長さに関わらず、EXPR の末尾で
15966マッチングしたときに生成されます(もちろん非 0 の LIMIT が明示的に
15967指定されていない場合です; このようなフィールドは前の例のように
15968取り除かれます)。
15969従って:
15970
15971 print join(':', split(//, ' abc', -1)), "\n";
15972
1332515973=begin original
1332615974
13327As with regular pattern matching, any capturing parentheses that are not
15975produces the output S<C< :a:b:c:>>.
13328matched in a C<split()> will be set to C<undef> when returned:
1332915976
1333015977=end original
1333115978
13332通常のパターンマッチングで、C<split()> でマッチない全てのかっこは
15979これは出力 S<C< :a:b:c:>> を生成ます。
13333返される時には C<undef> がセットされます。
1333415980
13335 @fields = split /(A)|B/, "1A2B3";
15981=begin original
13336 # @fields is (1, 'A', 2, undef, 3)
1333715982
15983If the PATTERN contains
15984L<capturing groups|perlretut/Grouping things and hierarchical matching>,
15985then for each separator, an additional field is produced for each substring
15986captured by a group (in the order in which the groups are specified,
15987as per L<backreferences|perlretut/Backreferences>); if any group does not
15988match, then it captures the L<C<undef>|/undef EXPR> value instead of a
15989substring. Also,
15990note that any such additional field is produced whenever there is a
15991separator (that is, whenever a split occurs), and such an additional field
15992does B<not> count towards the LIMIT. Consider the following expressions
15993evaluated in list context (each returned list is provided in the associated
15994comment):
15995
15996=end original
15997
15998PATTERN が
15999L<捕捉グループ|perlretut/Grouping things and hierarchical matching> を
16000含んでいる場合、それぞれのセパレータについて、
16001(L<後方参照|perlretut/Backreferences> のようにグループが指定された)
16002グループによって捕捉されたそれぞれの部分文字列について追加のフィールドが
16003生成されます; どのグループもマッチングしなかった場合、部分文字列の代わりに
16004L<C<undef>|/undef EXPR> 値を捕捉します。
16005また、このような追加のフィールドはセパレータがあるとき(つまり、分割が
16006行われるとき)はいつでも生成され、このような追加のフィールドは
16007LIMIT に関してはカウント B<されない> ことに注意してください。
16008リストコンテキストで評価される以下のような式を考えます
16009(それぞれの返されるリストは関連づけられたコメントで提供されます):
16010
16011 split(/-|,/, "1-10,20", 3)
16012 # ('1', '10', '20')
16013
16014 split(/(-|,)/, "1-10,20", 3)
16015 # ('1', '-', '10', ',', '20')
16016
16017 split(/-|(,)/, "1-10,20", 3)
16018 # ('1', undef, '10', ',', '20')
16019
16020 split(/(-)|,/, "1-10,20", 3)
16021 # ('1', '-', '10', undef, '20')
16022
16023 split(/(-)|(,)/, "1-10,20", 3)
16024 # ('1', '-', undef, '10', undef, ',', '20')
16025
1333816026=item sprintf FORMAT, LIST
1333916027X<sprintf>
1334016028
16029=for Pod::Functions formatted print into a string
16030
1334116031=begin original
1334216032
13343Returns a string formatted by the usual C<printf> conventions of the C
16033Returns a string formatted by the usual
13344library function C<sprintf>. See below for more details
16034L<C<printf>|/printf FILEHANDLE FORMAT, LIST> conventions of the C
13345and see C<sprintf(3)> or C<printf(3)> on your system for an explanation of
16035library function L<C<sprintf>|/sprintf FORMAT, LIST>. See below for
13346the general principles.
16036more details and see L<sprintf(3)> or L<printf(3)> on your system for an
16037explanation of the general principles.
1334716038
1334816039=end original
1334916040
13350普通の C 言語の C<printf> 記法フォーマットで、整形された文字列を返します。
16041C ライブラリ関数 L<C<sprintf>|/sprintf FORMAT, LIST>
16042普通の L<C<printf>|/printf FILEHANDLE FORMAT, LIST> 記法の
16043整形された文字列を返します。
1335116044一般的な原則の説明については以下の説明と、システムの
13352C<sprintf(3)> または C<printf(3)> の説明を参照してください。
16045L<sprintf(3)> または L<printf(3)> の説明を参照してください。
1335316046
1335416047=begin original
1335516048
1335616049For example:
1335716050
1335816051=end original
1335916052
13360例:
16053えば:
1336116054
1336216055 # Format number with up to 8 leading zeroes
13363 $result = sprintf("%08d", $number);
16056 my $result = sprintf("%08d", $number);
1336416057
1336516058 # Round number to 3 digits after decimal point
13366 $rounded = sprintf("%.3f", $number);
16059 my $rounded = sprintf("%.3f", $number);
1336716060
1336816061=begin original
1336916062
13370Perl does its own C<sprintf> formatting: it emulates the C
16063Perl does its own L<C<sprintf>|/sprintf FORMAT, LIST> formatting: it
13371function sprintf(3), but doesn't use it except for floating-point
16064emulates the C
13372numbers, and even then only standard modifiers are allowed.
16065function L<sprintf(3)>, but doesn't use it except for floating-point
13373Non-standard extensions in your local sprintf(3) are
16066numbers, and even then only standard modifiers are allowed.
16067Non-standard extensions in your local L<sprintf(3)> are
1337416068therefore unavailable from Perl.
1337516069
1337616070=end original
1337716071
13378Perl は C<sprintf> フォーマット処理を自力で行います:
16072Perl は L<C<sprintf>|/sprintf FORMAT, LIST> フォーマット処理を自力で行います:
13379これは C の sprintf(3) 関数をエミュレートしますが、
16073これは C の L<sprintf(3)> 関数をエミュレートしますが、C の関数は使いません
13380C の関数は使いません(浮動小数点を除きますが、それでも標準の
16074(浮動小数点を除きますが、それでも標準の記述子のみが利用できます)。
13381記述子みが利用す)
16075従って、ローカルな非標準 L<sprintf(3)> 拡張機能は Perl は使えせん
13382従って、ローカルな非標準の C<sprintf> 拡張機能は Perl では使えません。
1338316076
1338416077=begin original
1338516078
13386Unlike C<printf>, C<sprintf> does not do what you probably mean when you
16079Unlike L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
13387pass it an array as your first argument. The array is given scalar context,
16080L<C<sprintf>|/sprintf FORMAT, LIST> does not do what you probably mean
16081when you pass it an array as your first argument.
16082The array is given scalar context,
1338816083and instead of using the 0th element of the array as the format, Perl will
1338916084use the count of elements in the array as the format, which is almost never
1339016085useful.
1339116086
1339216087=end original
1339316088
13394C<printf> と違って、 C<sprintf> の最初の引数に配列を渡し
16089L<C<printf>|/printf FILEHANDLE FORMAT, LIST> と違っ
16090L<C<sprintf>|/sprintf FORMAT, LIST> の最初の引数に配列を渡しても
1339516091あなたが多分望むとおりには動作しません。
1339616092配列はスカラコンテキストで渡されるので、配列の 0 番目の要素ではなく、
13397配列の要素数をフォーマットとして扱います。
16093配列の要素数をフォーマットとして扱います; これはほとんど役に立ちません
13398これはほとんど役に立ちません。
1339916094
1340016095=begin original
1340116096
13402Perl's C<sprintf> permits the following universally-known conversions:
16097Perl's L<C<sprintf>|/sprintf FORMAT, LIST> permits the following
16098universally-known conversions:
1340316099
1340416100=end original
1340516101
13406Perl の C<sprintf> は以下の一般に知られている変換に対応しています:
16102Perl の L<C<sprintf>|/sprintf FORMAT, LIST> は以下の一般に知られている変換に
16103対応しています:
1340716104
1340816105=begin original
1340916106
1341016107 %% a percent sign
1341116108 %c a character with the given number
1341216109 %s a string
1341316110 %d a signed integer, in decimal
1341416111 %u an unsigned integer, in decimal
1341516112 %o an unsigned integer, in octal
1341616113 %x an unsigned integer, in hexadecimal
1341716114 %e a floating-point number, in scientific notation
1341816115 %f a floating-point number, in fixed decimal notation
1341916116 %g a floating-point number, in %e or %f notation
1342016117
1342116118=end original
1342216119
1342316120 %% パーセントマーク
1342416121 %c 与えられた番号の文字
1342516122 %s 文字列
1342616123 %d 符号付き 10 進数
1342716124 %u 符号なし 10 進数
1342816125 %o 符号なし 8 進数
1342916126 %x 符号なし 16 進数
1343016127 %e 科学的表記の浮動小数点数
1343116128 %f 固定 10 進数表記の浮動小数点数
1343216129 %g %e か %f の表記の浮動小数点数
1343316130
1343416131=begin original
1343516132
1343616133In addition, Perl permits the following widely-supported conversions:
1343716134
1343816135=end original
1343916136
1344016137さらに、Perl では以下のよく使われている変換に対応しています:
1344116138
1344216139=begin original
1344316140
1344416141 %X like %x, but using upper-case letters
1344516142 %E like %e, but using an upper-case "E"
1344616143 %G like %g, but with an upper-case "E" (if applicable)
1344716144 %b an unsigned integer, in binary
1344816145 %B like %b, but using an upper-case "B" with the # flag
1344916146 %p a pointer (outputs the Perl value's address in hexadecimal)
1345016147 %n special: *stores* the number of characters output so far
13451 into the next variable in the parameter list
16148 into the next argument in the parameter list
16149 %a hexadecimal floating point
16150 %A like %a, but using upper-case letters
1345216151
1345316152=end original
1345416153
1345516154 %X %x と同様だが大文字を使う
1345616155 %E %e と同様だが大文字の "E" を使う
1345716156 %G %g と同様だが(適切なら)大文字の "E" を使う
1345816157 %b 符号なし 2 進数
1345916158 %B %b と同様だが、# フラグで大文字の "B" を使う
1346016159 %p ポインタ (Perl の値のアドレスを 16 進数で出力する)
1346116160 %n 特殊: 出力文字数を引数リストの次の変数に「格納」する
16161 %a 16 進浮動小数点
16162 %A %a と同様だが、大文字を使う
1346216163
1346316164=begin original
1346416165
1346516166Finally, for backward (and we do mean "backward") compatibility, Perl
1346616167permits these unnecessary but widely-supported conversions:
1346716168
1346816169=end original
1346916170
1347016171最後に、過去との互換性(これは「過去」だと考えています)のために、
1347116172Perl は以下の不要ではあるけれども広く使われている変換に対応しています。
1347216173
1347316174=begin original
1347416175
1347516176 %i a synonym for %d
1347616177 %D a synonym for %ld
1347716178 %U a synonym for %lu
1347816179 %O a synonym for %lo
1347916180 %F a synonym for %f
1348016181
1348116182=end original
1348216183
1348316184 %i %d の同義語
1348416185 %D %ld の同義語
1348516186 %U %lu の同義語
1348616187 %O %lo の同義語
1348716188 %F %f の同義語
1348816189
1348916190=begin original
1349016191
1349116192Note that the number of exponent digits in the scientific notation produced
1349216193by C<%e>, C<%E>, C<%g> and C<%G> for numbers with the modulus of the
1349316194exponent less than 100 is system-dependent: it may be three or less
1349416195(zero-padded as necessary). In other words, 1.23 times ten to the
1349599th may be either "1.23e99" or "1.23e099".
1619699th may be either "1.23e99" or "1.23e099". Similarly for C<%a> and C<%A>:
16197the exponent or the hexadecimal digits may float: especially the
16198"long doubles" Perl configuration option may cause surprises.
1349616199
1349716200=end original
1349816201
1349916202C<%e>, C<%E>, C<%g>, C<%G> において、指数部が 100 未満の場合の
1350016203指数部の科学的な表記法はシステム依存であることに注意してください:
13501162043 桁かもしれませんし、それ以下かもしれません(必要に応じて 0 で
1350216205パッディングされます)。
1350316206言い換えると、 1.23 掛ける 10 の 99 乗は "1.23e99" かもしれませんし
1350416207"1.23e099" かもしれません。
16208同様に C<%a> と C<%A> の場合:
16209指数部と 16 進数が浮動小数点かもしれません:
16210特に "long doubles" Perl 設定オプションが驚きを引き起こすかもしれません。
1350516211
1350616212=begin original
1350716213
1350816214Between the C<%> and the format letter, you may specify several
1350916215additional attributes controlling the interpretation of the format.
1351016216In order, these are:
1351116217
1351216218=end original
1351316219
1351416220C<%> とフォーマット文字の間に、フォーマットの解釈を制御するための、
1351516221いくつかの追加の属性を指定できます。
1351616222順番に、以下のものがあります:
1351716223
1351816224=over 4
1351916225
1352016226=item format parameter index
1352116227
1352216228(フォーマットパラメータインデックス)
1352316229
1352416230=begin original
1352516231
13526An explicit format parameter index, such as C<2$>. By default sprintf
16232An explicit format parameter index, such as C<2$>. By default sprintf
1352716233will format the next unused argument in the list, but this allows you
1352816234to take the arguments out of order:
1352916235
1353016236=end original
1353116237
1353216238C<2$> のような明示的なフォーマットパラメータインデックス。
1353316239デフォルトでは sprintf はリストの次の使われていない引数を
1353416240フォーマットしますが、これによって異なった順番の引数を使えるようにします:
1353516241
1353616242 printf '%2$d %1$d', 12, 34; # prints "34 12"
1353716243 printf '%3$d %d %1$d', 1, 2, 3; # prints "3 1 1"
1353816244
1353916245=item flags
1354016246
1354116247(フラグ)
1354216248
1354316249=begin original
1354416250
1354516251one or more of:
1354616252
1354716253=end original
1354816254
1354916255以下のうちの一つまたは複数指定できます:
1355016256
1355116257=begin original
1355216258
1355316259 space prefix non-negative number with a space
1355416260 + prefix non-negative number with a plus sign
1355516261 - left-justify within the field
1355616262 0 use zeros, not spaces, to right-justify
1355716263 # ensure the leading "0" for any octal,
1355816264 prefix non-zero hexadecimal with "0x" or "0X",
1355916265 prefix non-zero binary with "0b" or "0B"
1356016266
1356116267=end original
1356216268
1356316269 space 非負数の前に空白をつける
1356416270 + 非負数の前にプラス記号をつける
1356516271 - フィールド内で左詰めする
1356616272 0 右詰めに空白ではなくゼロを使う
1356716273 # 8 進数では確実に先頭に "0" をつける;
1356816274 非 0 の 16 進数では "0x" か "0X" をつける;
1356916275 非 0 の 2 進数では "0b" か "0B" をつける
1357016276
1357116277=begin original
1357216278
1357316279For example:
1357416280
1357516281=end original
1357616282
13577例:
16283えば:
1357816284
1357916285 printf '<% d>', 12; # prints "< 12>"
16286 printf '<% d>', 0; # prints "< 0>"
16287 printf '<% d>', -12; # prints "<-12>"
1358016288 printf '<%+d>', 12; # prints "<+12>"
16289 printf '<%+d>', 0; # prints "<+0>"
16290 printf '<%+d>', -12; # prints "<-12>"
1358116291 printf '<%6s>', 12; # prints "< 12>"
1358216292 printf '<%-6s>', 12; # prints "<12 >"
1358316293 printf '<%06s>', 12; # prints "<000012>"
1358416294 printf '<%#o>', 12; # prints "<014>"
1358516295 printf '<%#x>', 12; # prints "<0xc>"
1358616296 printf '<%#X>', 12; # prints "<0XC>"
1358716297 printf '<%#b>', 12; # prints "<0b1100>"
1358816298 printf '<%#B>', 12; # prints "<0B1100>"
1358916299
1359016300=begin original
1359116301
1359216302When a space and a plus sign are given as the flags at once,
13593a plus sign is used to prefix a positive number.
16303the space is ignored.
1359416304
1359516305=end original
1359616306
13597空白とプラス記号がフラグとして同時に与えられると、プラス記号は正の数に
16307空白とプラス記号がフラグとして同時に与えられると、
13598前置するために使われます。
16308空白は無視されます。
1359916309
1360016310 printf '<%+ d>', 12; # prints "<+12>"
1360116311 printf '<% +d>', 12; # prints "<+12>"
1360216312
1360316313=begin original
1360416314
1360516315When the # flag and a precision are given in the %o conversion,
1360616316the precision is incremented if it's necessary for the leading "0".
1360716317
1360816318=end original
1360916319
1361016320%o 変換に # フラグと精度が与えられると、先頭の "0" が必要な場合は
1361116321精度に 1 が加えられます。
1361216322
1361316323 printf '<%#.5o>', 012; # prints "<00012>"
1361416324 printf '<%#.5o>', 012345; # prints "<012345>"
1361516325 printf '<%#.0o>', 0; # prints "<0>"
1361616326
1361716327=item vector flag
1361816328
1361916329(ベクタフラグ)
1362016330
1362116331=begin original
1362216332
1362316333This flag tells Perl to interpret the supplied string as a vector of
13624integers, one for each character in the string. Perl applies the format to
16334integers, one for each character in the string. Perl applies the format to
1362516335each integer in turn, then joins the resulting strings with a separator (a
13626dot C<.> by default). This can be useful for displaying ordinal values of
16336dot C<.> by default). This can be useful for displaying ordinal values of
1362716337characters in arbitrary strings:
1362816338
1362916339=end original
1363016340
1363116341このフラグは Perl に、与えられた文字列を、文字毎に一つの整数のベクタとして
1363216342解釈させます。
1363316343Perl は各数値をフォーマットし、それから結果の文字列をセパレータ
1363416344(デフォルトでは C<.>)で連結します。
1363516345これは任意の文字列の文字を順序付きの値として表示するのに便利です:
1363616346
1363716347 printf "%vd", "AB\x{100}"; # prints "65.66.256"
1363816348 printf "version is v%vd\n", $^V; # Perl's version
1363916349
1364016350=begin original
1364116351
1364216352Put an asterisk C<*> before the C<v> to override the string to
1364316353use to separate the numbers:
1364416354
1364516355=end original
1364616356
1364716357アスタリスク C<*> を C<v> の前に置くと、数値を分けるために使われる文字列を
1364816358上書きします:
1364916359
1365016360 printf "address is %*vX\n", ":", $addr; # IPv6 address
1365116361 printf "bits are %0*v8b\n", " ", $bits; # random bitstring
1365216362
1365316363=begin original
1365416364
1365516365You can also explicitly specify the argument number to use for
1365616366the join string using something like C<*2$v>; for example:
1365716367
1365816368=end original
1365916369
1366016370また、C<*2$v> のように、連結する文字列として使う引数の番号を明示的に
1366116371指定できます; 例えば:
1366216372
13663 printf '%*4$vX %*4$vX %*4$vX', @addr[1..3], ":"; # 3 IPv6 addresses
16373 printf '%*4$vX %*4$vX %*4$vX', # 3 IPv6 addresses
16374 @addr[1..3], ":";
1366416375
1366516376=item (minimum) width
1366616377
1366716378((最小)幅)
1366816379
1366916380=begin original
1367016381
1367116382Arguments are usually formatted to be only as wide as required to
13672display the given value. You can override the width by putting
16383display the given value. You can override the width by putting
1367316384a number here, or get the width from the next argument (with C<*>)
1367416385or from a specified argument (e.g., with C<*2$>):
1367516386
1367616387=end original
1367716388
1367816389引数は、普通は値を表示するのに必要なちょうどの幅でフォーマットされます。
1367916390ここに数値を置くか、(C<*> で)次の引数か(C<*2$> で)明示的に指定した引数で
1368016391幅を上書きできます。
1368116392
13682 printf "<%s>", "a"; # prints "<a>"
16393 printf "<%s>", "a"; # prints "<a>"
13683 printf "<%6s>", "a"; # prints "< a>"
16394 printf "<%6s>", "a"; # prints "< a>"
13684 printf "<%*s>", 6, "a"; # prints "< a>"
16395 printf "<%*s>", 6, "a"; # prints "< a>"
13685 printf "<%*2$s>", "a", 6; # prints "< a>"
16396 printf '<%*2$s>', "a", 6; # prints "< a>"
13686 printf "<%2s>", "long"; # prints "<long>" (does not truncate)
16397 printf "<%2s>", "long"; # prints "<long>" (does not truncate)
1368716398
1368816399=begin original
1368916400
1369016401If a field width obtained through C<*> is negative, it has the same
1369116402effect as the C<-> flag: left-justification.
1369216403
1369316404=end original
1369416405
1369516406C<*> を通して得られたフィールドの値が負数の場合、C<-> フラグと
1369616407同様の効果 (左詰め) があります。
1369716408
1369816409=item precision, or maximum width
1369916410X<precision>
1370016411
1370116412(精度あるいは最大幅)
1370216413
1370316414=begin original
1370416415
1370516416You can specify a precision (for numeric conversions) or a maximum
1370616417width (for string conversions) by specifying a C<.> followed by a number.
1370716418For floating-point formats except C<g> and C<G>, this specifies
1370816419how many places right of the decimal point to show (the default being 6).
1370916420For example:
1371016421
1371116422=end original
1371216423
1371316424C<.> の後に数値を指定することで、(数値変換の場合)精度や(文字列変換の場合)
1371416425最大幅を指定できます。
1371516426小数点数フォーマットの場合、C<g> と C<G> を除いて、表示する小数点以下の
1371616427桁数を指定します(デフォルトは 6 です)。
13717例:
16428えば:
1371816429
1371916430 # these examples are subject to system-specific variation
1372016431 printf '<%f>', 1; # prints "<1.000000>"
1372116432 printf '<%.1f>', 1; # prints "<1.0>"
1372216433 printf '<%.0f>', 1; # prints "<1>"
1372316434 printf '<%e>', 10; # prints "<1.000000e+01>"
1372416435 printf '<%.1e>', 10; # prints "<1.0e+01>"
1372516436
1372616437=begin original
1372716438
1372816439For "g" and "G", this specifies the maximum number of digits to show,
13729including thoe prior to the decimal point and those after it; for
16440including those prior to the decimal point and those after it; for
1373016441example:
1373116442
1373216443=end original
1373316444
1373416445"g" と "G" の場合、これは表示する数値の数を指定します;
1373516446これには小数点の前の数値と後の数値を含みます; 例えば:
1373616447
1373716448 # These examples are subject to system-specific variation.
1373816449 printf '<%g>', 1; # prints "<1>"
1373916450 printf '<%.10g>', 1; # prints "<1>"
1374016451 printf '<%g>', 100; # prints "<100>"
1374116452 printf '<%.1g>', 100; # prints "<1e+02>"
1374216453 printf '<%.2g>', 100.01; # prints "<1e+02>"
1374316454 printf '<%.5g>', 100.01; # prints "<100.01>"
1374416455 printf '<%.4g>', 100.01; # prints "<100>"
1374516456
1374616457=begin original
1374716458
1374816459For integer conversions, specifying a precision implies that the
1374916460output of the number itself should be zero-padded to this width,
1375016461where the 0 flag is ignored:
1375116462
1375216463=end original
1375316464
1375416465整数変換の場合、精度を指定すると、数値自体の出力はこの幅に 0 で
1375516466パッディングするべきであることを暗に示すことになり、0 フラグは
1375616467無視されます:
1375716468
1375816469 printf '<%.6d>', 1; # prints "<000001>"
1375916470 printf '<%+.6d>', 1; # prints "<+000001>"
1376016471 printf '<%-10.6d>', 1; # prints "<000001 >"
1376116472 printf '<%10.6d>', 1; # prints "< 000001>"
1376216473 printf '<%010.6d>', 1; # prints "< 000001>"
1376316474 printf '<%+10.6d>', 1; # prints "< +000001>"
1376416475
1376516476 printf '<%.6x>', 1; # prints "<000001>"
1376616477 printf '<%#.6x>', 1; # prints "<0x000001>"
1376716478 printf '<%-10.6x>', 1; # prints "<000001 >"
1376816479 printf '<%10.6x>', 1; # prints "< 000001>"
1376916480 printf '<%010.6x>', 1; # prints "< 000001>"
1377016481 printf '<%#10.6x>', 1; # prints "< 0x000001>"
1377116482
1377216483=begin original
1377316484
1377416485For string conversions, specifying a precision truncates the string
1377516486to fit the specified width:
1377616487
1377716488=end original
1377816489
1377916490文字列変換の場合、精度を指定すると、指定された幅に収まるように文字列を
1378016491切り詰めます:
1378116492
1378216493 printf '<%.5s>', "truncated"; # prints "<trunc>"
1378316494 printf '<%10.5s>', "truncated"; # prints "< trunc>"
1378416495
1378516496=begin original
1378616497
13787You can also get the precision from the next argument using C<.*>:
16498You can also get the precision from the next argument using C<.*>, or from a
16499specified argument (e.g., with C<.*2$>):
1378816500
1378916501=end original
1379016502
13791C<.*> を使って精度を次の引数から取ることも出来ます:
16503C<.*> を使って精度を次の引数から取ったり、
16504(C<.*2$> のように) 指定した引数から取ったりすることもできます:
1379216505
1379316506 printf '<%.6x>', 1; # prints "<000001>"
1379416507 printf '<%.*x>', 6, 1; # prints "<000001>"
1379516508
16509 printf '<%.*2$x>', 1, 6; # prints "<000001>"
16510
16511 printf '<%6.*2$x>', 1, 4; # prints "< 0001>"
16512
1379616513=begin original
1379716514
1379816515If a precision obtained through C<*> is negative, it counts
1379916516as having no precision at all.
1380016517
1380116518=end original
1380216519
1380316520C<*> によって得られた精度が負数の場合、精度が指定されなかった場合と
1380416521同じ効果となります。
1380516522
1380616523 printf '<%.*s>', 7, "string"; # prints "<string>"
1380716524 printf '<%.*s>', 3, "string"; # prints "<str>"
1380816525 printf '<%.*s>', 0, "string"; # prints "<>"
1380916526 printf '<%.*s>', -1, "string"; # prints "<string>"
1381016527
1381116528 printf '<%.*d>', 1, 0; # prints "<0>"
1381216529 printf '<%.*d>', 0, 0; # prints "<>"
1381316530 printf '<%.*d>', -1, 0; # prints "<0>"
1381416531
13815=begin original
13816
13817You cannot currently get the precision from a specified number,
13818but it is intended that this will be possible in the future, for
13819example using C<.*2$>:
13820
13821=end original
13822
13823現在のところ精度を指定した数値から得ることはできませんが、
13824将来は 例えば C<.*2$> のようにして可能にしようとしています:
13825
13826 printf "<%.*2$x>", 1, 6; # INVALID, but in future will print "<000001>"
13827
1382816532=item size
1382916533
1383016534(サイズ)
1383116535
1383216536=begin original
1383316537
1383416538For numeric conversions, you can specify the size to interpret the
13835number as using C<l>, C<h>, C<V>, C<q>, C<L>, or C<ll>. For integer
16539number as using C<l>, C<h>, C<V>, C<q>, C<L>, or C<ll>. For integer
1383616540conversions (C<d u o x X b i D U O>), numbers are usually assumed to be
1383716541whatever the default integer size is on your platform (usually 32 or 64
1383816542bits), but you can override this to use instead one of the standard C types,
1383916543as supported by the compiler used to build Perl:
1384016544
1384116545=end original
1384216546
1384316547数値変換では、C<l>, C<h>, C<V>, C<q>, C<L>, C<ll> を使って解釈する数値の
1384416548大きさを指定できます。
1384516549整数変換 (C<d u o x X b i D U O>) では、数値は通常プラットフォームの
1384616550デフォルトの整数のサイズ (通常は 32 ビットか 64 ビット) を仮定しますが、
1384716551これを Perl がビルドされたコンパイラが対応している標準 C の型の一つで
1384816552上書きできます:
1384916553
1385016554=begin original
1385116555
13852 hh interpret integer as C type "char" or "unsigned char"
16556 hh interpret integer as C type "char" or "unsigned
13853 on Perl 5.14 or later
16557 char" on Perl 5.14 or later
13854 h interpret integer as C type "short" or "unsigned short"
16558 h interpret integer as C type "short" or
13855 j intepret integer as C type "intmax_t" on Perl 5.14
16559 "unsigned short"
13856 or later, and only with a C99 compiler (unportable)
16560 j interpret integer as C type "intmax_t" on Perl
13857 l interpret integer as C type "long" or "unsigned long"
16561 5.14 or later, and only with a C99 compiler
13858 q, L, or ll interpret integer as C type "long long", "unsigned long long",
16562 (unportable)
13859 or "quad" (typically 64-bit integers)
16563 l interpret integer as C type "long" or
13860 t intepret integer as C type "ptrdiff_t" on Perl 5.14 or later
16564 "unsigned long"
13861 z intepret integer as C type "size_t" on Perl 5.14 or later
16565 q, L, or ll interpret integer as C type "long long",
16566 "unsigned long long", or "quad" (typically
16567 64-bit integers)
16568 t interpret integer as C type "ptrdiff_t" on Perl
16569 5.14 or later
16570 z interpret integer as C type "size_t" on Perl 5.14
16571 or later
1386216572
1386316573=end original
1386416574
1386516575 hh Perl 5.14 以降で整数を C の "char" または "unsigned char"
13866 型として解釈する
16576 型として解釈する
1386716577 h 整数を C の "char" または "unsigned char" 型として解釈する
13868 j Perl 5.14 以降 C99 コンパイラのみで整数を C の "intmax_t"
16578 j Perl 5.14 以降 C99 コンパイラのみで整数を C の "intmax_t"
13869 型として解釈する (移植性なし)
16579 型として解釈する (移植性なし)
1387016580 l 整数を C の "long" または "unsigned long" と解釈する
1387116581 h 整数を C の "short" または "unsigned short" と解釈する
1387216582 q, L or ll 整数を C の "long long", "unsigned long long",
1387316583 "quads"(典型的には 64 ビット整数) のどれかと解釈する
13874 t Perl 5.14 以降で整数を C の "ptrdiff_t" 型として解釈する
16584 t Perl 5.14 以降で整数を C の "ptrdiff_t" 型として解釈する
13875 z Perl 5.14 以降で整数を C の "size_t" 型として解釈する
16585 z Perl 5.14 以降で整数を C の "size_t" 型として解釈する
1387616586
1387716587=begin original
1387816588
1387916589As of 5.14, none of these raises an exception if they are not supported on
1388016590your platform. However, if warnings are enabled, a warning of the
13881C<printf> warning class is issued on an unsupported conversion flag.
16591L<C<printf>|warnings> warning class is issued on an unsupported
13882Should you instead prefer an exception, do this:
16592conversion flag. Should you instead prefer an exception, do this:
1388316593
1388416594=end original
1388516595
13886165965.14 から、プラットフォームがこれらに対応していないときでも例外が
1388716597発生しなくなりました。
1388816598しかし、もし警告が有効になっているなら、
13889非対応変換フラグに関して C<printf> 警告クラスの警告が発生します。
16599非対応変換フラグに関して L<C<printf>|warnings> 警告クラスの警告が発生します。
1389016600例外の方がお好みなら、以下のようにします:
1389116601
1389216602 use warnings FATAL => "printf";
1389316603
1389416604=begin original
1389516605
1389616606If you would like to know about a version dependency before you
1389716607start running the program, put something like this at its top:
1389816608
1389916609=end original
1390016610
1390116611プログラムの実行開始前にバージョン依存について知りたいなら、先頭に
1390216612以下のようなものを書きます:
1390316613
1390416614 use 5.014; # for hh/j/t/z/ printf modifiers
1390516615
1390616616=begin original
1390716617
1390816618You can find out whether your Perl supports quads via L<Config>:
1390916619
1391016620=end original
1391116621
1391216622Perl が 64 ビット整数に対応しているかどうかは L<Config> を使って
1391316623調べられます:
1391416624
1391516625 use Config;
13916 if ($Config{use64bitint} eq "define" || $Config{longsize} >= 8) {
16626 if ($Config{use64bitint} eq "define"
16627 || $Config{longsize} >= 8) {
1391716628 print "Nice quads!\n";
1391816629 }
1391916630
1392016631=begin original
1392116632
1392216633For floating-point conversions (C<e f g E F G>), numbers are usually assumed
1392316634to be the default floating-point size on your platform (double or long double),
1392416635but you can force "long double" with C<q>, C<L>, or C<ll> if your
13925platform supports them. You can find out whether your Perl supports long
16636platform supports them. You can find out whether your Perl supports long
1392616637doubles via L<Config>:
1392716638
1392816639=end original
1392916640
1393016641浮動小数点数変換 (C<e f g E F G>) では、普通はプラットフォームのデフォルトの
13931不動小数点数のサイズ (double か long double) を仮定します
16642不動小数点数のサイズ (double か long double) を仮定しますが、
16643プラットフォームが対応しているなら、C<q>, C<L>, C<ll> に対して
16644"long double" を強制できます。
1393216645Perl が long double に対応しているかどうかは L<Config> を使って
1393316646調べられます:
1393416647
1393516648 use Config;
1393616649 print "long doubles\n" if $Config{d_longdbl} eq "define";
1393716650
1393816651=begin original
1393916652
1394016653You can find out whether Perl considers "long double" to be the default
1394116654floating-point size to use on your platform via L<Config>:
1394216655
1394316656=end original
1394416657
1394516658Perl が "long double" をデフォルトの浮動小数点数として扱っているかどうかは
1394616659L<Config> を使って調べられます:
1394716660
1394816661 use Config;
1394916662 if ($Config{uselongdouble} eq "define") {
13950 print "long doubles by default\n";
16663 print "long doubles by default\n";
1395116664 }
1395216665
1395316666=begin original
1395416667
1395516668It can also be that long doubles and doubles are the same thing:
1395616669
1395716670=end original
1395816671
1395916672long double と double が同じ場合もあります:
1396016673
1396116674 use Config;
1396216675 ($Config{doublesize} == $Config{longdblsize}) &&
1396316676 print "doubles are long doubles\n";
1396416677
1396516678=begin original
1396616679
1396716680The size specifier C<V> has no effect for Perl code, but is supported for
1396816681compatibility with XS code. It means "use the standard size for a Perl
1396916682integer or floating-point number", which is the default.
1397016683
1397116684=end original
1397216685
1397316686サイズ指定子 C<V> は Perl のコードには何の影響もありませんが、これは
1397416687XS コードとの互換性のために対応しています。
1397516688これは「Perl 整数 (または浮動小数点数) として標準的なサイズを使う」ことを
1397616689意味し、これはデフォルトです。
1397716690
1397816691=item order of arguments
1397916692
1398016693(引数の順序)
1398116694
1398216695=begin original
1398316696
13984Normally, sprintf() takes the next unused argument as the value to
16697Normally, L<C<sprintf>|/sprintf FORMAT, LIST> takes the next unused
13985format for each format specification. If the format specification
16698argument as the value to
16699format for each format specification. If the format specification
1398616700uses C<*> to require additional arguments, these are consumed from
1398716701the argument list in the order they appear in the format
1398816702specification I<before> the value to format. Where an argument is
1398916703specified by an explicit index, this does not affect the normal
1399016704order for the arguments, even when the explicitly specified index
1399116705would have been the next argument.
1399216706
1399316707=end original
1399416708
13995通常、sprintf() は各フォーマット指定について、使われていない次の引数を
16709通常、L<C<sprintf>|/sprintf FORMAT, LIST> は各フォーマット指定について、
16710使われていない次の引数を
1399616711フォーマットする値として使います。
1399716712追加の引数を要求するためにフォーマット指定 C<*> を使うと、
1399816713これらはフォーマットする値の I<前> のフォーマット指定に現れる順番に
1399916714引数リストから消費されます。
1400016715引数の位置が明示的なインデックスを使って指定された場合、
1400116716(明示的に指定したインデックスが次の引数の場合でも)
1400216717これは通常の引数の順番に影響を与えません。
1400316718
1400416719=begin original
1400516720
1400616721So:
1400716722
1400816723=end original
1400916724
1401016725それで:
1401116726
1401216727 printf "<%*.*s>", $a, $b, $c;
1401316728
1401416729=begin original
1401516730
1401616731uses C<$a> for the width, C<$b> for the precision, and C<$c>
1401716732as the value to format; while:
1401816733
1401916734=end original
1402016735
1402116736とすると C<$a> を幅に、C<$b> を精度に、C<$c> をフォーマットの値に
1402216737使います; 一方:
1402316738
14024 printf "<%*1$.*s>", $a, $b;
16739 printf '<%*1$.*s>', $a, $b;
1402516740
1402616741=begin original
1402716742
1402816743would use C<$a> for the width and precision, and C<$b> as the
1402916744value to format.
1403016745
1403116746=end original
1403216747
1403316748とすると C<$a> を幅と精度に、C<$b> をフォーマットの値に使います。
1403416749
1403516750=begin original
1403616751
1403716752Here are some more examples; be aware that when using an explicit
1403816753index, the C<$> may need escaping:
1403916754
1404016755=end original
1404116756
1404216757以下にさらなる例を示します; 明示的にインデックスを使う場合、C<$> は
1404316758エスケープする必要があることに注意してください:
1404416759
14045 printf "%2\$d %d\n", 12, 34; # will print "34 12\n"
16760 printf "%2\$d %d\n", 12, 34; # will print "34 12\n"
14046 printf "%2\$d %d %d\n", 12, 34; # will print "34 12 34\n"
16761 printf "%2\$d %d %d\n", 12, 34; # will print "34 12 34\n"
14047 printf "%3\$d %d %d\n", 12, 34, 56; # will print "56 12 34\n"
16762 printf "%3\$d %d %d\n", 12, 34, 56; # will print "56 12 34\n"
14048 printf "%2\$*3\$d %d\n", 12, 34, 3; # will print " 34 12\n"
16763 printf "%2\$*3\$d %d\n", 12, 34, 3; # will print " 34 12\n"
16764 printf "%*1\$.*f\n", 4, 5, 10; # will print "5.0000\n"
1404916765
1405016766=back
1405116767
1405216768=begin original
1405316769
14054If C<use locale> is in effect and POSIX::setlocale() has been called,
16770If L<C<use locale>|locale> (including C<use locale ':not_characters'>)
16771is in effect and L<C<POSIX::setlocale>|POSIX/C<setlocale>> has been
16772called,
1405516773the character used for the decimal separator in formatted floating-point
14056numbers is affected by the LC_NUMERIC locale. See L<perllocale>
16774numbers is affected by the C<LC_NUMERIC> locale. See L<perllocale>
1405716775and L<POSIX>.
1405816776
1405916777=end original
1406016778
14061C<use locale> が有効で、POSIX::setlocale()呼び出されている場合
16779(C<use locale ':not_characters'> を含む)L<C<use locale>|locale>有効で
16780L<C<POSIX::setlocale>|POSIX/C<setlocale>> が呼び出されている場合、
1406216781フォーマットされた浮動小数点数の小数点として使われる文字は
14063LC_NUMERIC ロケールの影響を受けます。
16782C<LC_NUMERIC> ロケールの影響を受けます。
1406416783L<perllocale> と L<POSIX> を参照してください。
1406516784
1406616785=item sqrt EXPR
1406716786X<sqrt> X<root> X<square root>
1406816787
1406916788=item sqrt
1407016789
16790=for Pod::Functions square root function
16791
1407116792=begin original
1407216793
1407316794Return the positive square root of EXPR. If EXPR is omitted, uses
14074C<$_>. Works only for non-negative operands unless you've
16795L<C<$_>|perlvar/$_>. Works only for non-negative operands unless you've
14075loaded the C<Math::Complex> module.
16796loaded the L<C<Math::Complex>|Math::Complex> module.
1407616797
1407716798=end original
1407816799
1407916800EXPR の正の平方根を返します。
14080EXPR 省略ると、C<$_> を使います。
16801EXPR 省略されると、L<C<$_>|perlvar/$_> を使います。
14081C<Math::Complex> モジュールを使わない場合は、負の数の引数は扱えません。
16802L<C<Math::Complex>|Math::Complex> モジュールを使わない場合は、負の数の引数は
16803扱えません。
1408216804
1408316805 use Math::Complex;
1408416806 print sqrt(-4); # prints 2i
1408516807
1408616808=item srand EXPR
1408716809X<srand> X<seed> X<randseed>
1408816810
1408916811=item srand
1409016812
16813=for Pod::Functions seed the random number generator
16814
1409116815=begin original
1409216816
14093Sets and returns the random number seed for the C<rand> operator.
16817Sets and returns the random number seed for the L<C<rand>|/rand EXPR>
16818operator.
1409416819
1409516820=end original
1409616821
14097C<rand> 演算子のためのシード値を設定して返します。
16822L<C<rand>|/rand EXPR> 演算子のためのシード値を設定して返します。
1409816823
1409916824=begin original
1410016825
14101The point of the function is to "seed" the C<rand> function so that
16826The point of the function is to "seed" the L<C<rand>|/rand EXPR>
14102C<rand> can produce a different sequence each time you run your
16827function so that L<C<rand>|/rand EXPR> can produce a different sequence
14103program. When called with a parameter, C<srand> uses that for the seed;
16828each time you run your program. When called with a parameter,
14104otherwise it (semi-)randomly chooses a seed. In either case, starting with
16829L<C<srand>|/srand EXPR> uses that for the seed; otherwise it
14105Perl 5.14, it returns the seed.
16830(semi-)randomly chooses a seed. In either case, starting with Perl 5.14,
16831it returns the seed. To signal that your code will work I<only> on Perls
16832of a recent vintage:
1410616833
1410716834=end original
1410816835
14109この関数のポイントは、プログラムを実行するごとに C<rand> 関数が
16836この関数のポイントは、プログラムを実行するごとに L<C<rand>|/rand EXPR> 関数が
14110異なる乱数列を生成できるように C<rand> 関数の「種」を設定することです。
16837異なる乱数列を生成できるように L<C<rand>|/rand EXPR> 関数の「種」を
14111C<srand> を引数付きで呼び出と、れを種して使いま; さもなければ
16838設定こと
14112(だいたい)ランダムに種びます
16839L<C<srand>|/srand EXPR> 引数付きで呼出すと、これを種として使います;
16840さもなければ(だいたい)ランダムに種を選びます。
1411316841どちらの場合でも、Perl 5.14 からは種を返します。
16842特定の時期の Perl I<でのみ> 動作することを知らせるには以下のようにします:
1411416843
14115=begin original
16844 use 5.014; # so srand returns the seed
1411616845
14117If C<srand()> is not called explicitly, it is called implicitly without a
14118parameter at the first use of the C<rand> operator. However, this was not true
14119of versions of Perl before 5.004, so if your script will run under older
14120Perl versions, it should call C<srand>; otherwise most programs won't call
14121C<srand()> at all.
14122
14123=end original
14124
14125C<srand()> が明示的に呼び出されなかった場合、最初に C<rand> 演算子を使った
14126時点で暗黙に引数なしで呼び出されます。
14127しかし、これは Perl のバージョンが 5.004 より前では行われませんので、
14128プログラムが古い Perl で実行される場合は、C<srand> を呼ぶべきです;
14129さもなければ、ほとんどのプログラムは C<srand()> を一切呼び出す必要は
14130ありません。
14131
1413216846=begin original
1413316847
14134But there are a few situations in recent Perls where programs are likely to
16848If L<C<srand>|/srand EXPR> is not called explicitly, it is called
14135want to call C<srand>. One is for generating predictable results generally for
16849implicitly without a parameter at the first use of the
14136testing or debugging. There, you use C<srand($seed)>, with the same C<$seed>
16850L<C<rand>|/rand EXPR> operator. However, there are a few situations
14137each time. Another other case is where you need a cryptographically-strong
16851where programs are likely to want to call L<C<srand>|/srand EXPR>. One
14138starting point rather than the generally acceptable default, which is based on
16852is for generating predictable results, generally for testing or
14139time of day, process ID, and memory allocation, or the F</dev/urandom> device
16853debugging. There, you use C<srand($seed)>, with the same C<$seed> each
14140if available. And still another case is that you may want to call C<srand()>
16854time. Another case is that you may want to call L<C<srand>|/srand EXPR>
14141after a C<fork()> to avoid child processes sharing the same seed value as the
16855after a L<C<fork>|/fork> to avoid child processes sharing the same seed
14142parent (and consequently each other).
16856value as the parent (and consequently each other).
1414316857
1414416858=end original
1414516859
14146しかし、最近の Perl でプログラムが C<srand> 呼び出いであろう状況が
16860L<C<srand>|/srand EXPR> が明示的に呼び出されなかっ場合、最初に
14147いくつかあります。
16861L<C<rand>|/rand EXPR> 演算子を使った時点で暗黙に引数なしで呼び出されます。
16862しかし、最近の Perl でプログラムが L<C<srand>|/srand EXPR> を
16863呼び出したいであろう状況がいくつかあります。
1414816864一つはテストやデバッグのために予測可能な結果を生成するためです。
1414916865この場合、C<srand($seed)> (C<$seed> は毎回同じ値を使う) を使います。
14150もう一つの場合は、時刻、プロセス ID、メモリ配置、(利用可能なら) F</dev/urandom>
14151デバイスといった、一般的に受け入れられるデフォルトよりも暗号学的に
14152強力な開始点が必要な場合です。
1415316866もう一つの場合としては、子プロセスが親や他の子プロセスと同じ種の値を
14154共有することを避けるために、C<fork()> の後に C<srand()> を
16867共有することを避けるために、L<C<fork>|/fork> の後に L<C<srand>|/srand EXPR> を
1415516868呼び出したいかもしれません。
1415616869
1415716870=begin original
1415816871
1415916872Do B<not> call C<srand()> (i.e., without an argument) more than once per
1416016873process. The internal state of the random number generator should
1416116874contain more entropy than can be provided by any seed, so calling
14162C<srand()> again actually I<loses> randomness.
16875L<C<srand>|/srand EXPR> again actually I<loses> randomness.
1416316876
1416416877=end original
1416516878
14166C<srand()> (引数なし)をプロセス中で複数回呼び出しては B<いけません>。
16879L<C<srand>|/srand EXPR> (引数なし)をプロセス中で複数回
16880呼び出しては B<いけません>。
1416716881乱数生成器の内部状態はどのような種によって提供されるものよりも
1416816882高いエントロピーを持っているので、C<srand()> を再び呼び出すと
1416916883ランダム性が I<失われます>。
1417016884
1417116885=begin original
1417216886
14173Most implementations of C<srand> take an integer and will silently
16887Most implementations of L<C<srand>|/srand EXPR> take an integer and will
16888silently
1417416889truncate decimal numbers. This means C<srand(42)> will usually
1417516890produce the same results as C<srand(42.1)>. To be safe, always pass
14176C<srand> an integer.
16891L<C<srand>|/srand EXPR> an integer.
1417716892
1417816893=end original
1417916894
14180C<srand> のほとんどの実装では整数を取り、小数を暗黙に切り捨てます。
16895L<C<srand>|/srand EXPR> のほとんどの実装では整数を取り、小数を暗黙に
14181これは、C<srand(42)> は普通 C<srand(42.1)> と同じ結果になることを
16896切り捨てます。
14182意味します。
16897これは、C<srand(42)> は普通 C<srand(42.1)> と同じ結果になることを意味します。
14183安全のために、C<srand> には常に整数を渡しましょう。
16898安全のために、L<C<srand>|/srand EXPR> には常に整数を渡しましょう。
1418416899
1418516900=begin original
1418616901
14187In versions of Perl prior to 5.004 the default seed was just the
14188current C<time>. This isn't a particularly good seed, so many old
14189programs supply their own seed value (often C<time ^ $$> or C<time ^
14190($$ + ($$ << 15))>), but that isn't necessary any more.
14191
14192=end original
14193
141945.004 以前の Perl では、デフォルトのシード値は現在の C<time> でした。
14195これは特によいシード値ではありませんでしたので、
14196多くの古いプログラムは自力でシード値を指定しています
14197(C<time ^ $$> または C<time ^ ($$ + ($$ << 15))> がよく使われました)が、
14198もはやこれは必要ありません。
14199
14200=begin original
14201
14202For cryptographic purposes, however, you need something much more random
14203than the default seed. Checksumming the compressed output of one or more
14204rapidly changing operating system status programs is the usual method. For
14205example:
14206
14207=end original
14208
14209しかし、暗号処理にはもっとランダムな値を使う必要があります。
14210急激に変化する OS のステータス値プログラムの出力をひとつまたは複数用い、
14211圧縮してチェックサムをとる、というようなことが普通行なわれます。
14212例えば:
14213
14214 srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip -f`);
14215
14216=begin original
14217
14218If you're particularly concerned with this, search the CPAN for
14219random number generator modules instead of rolling out your own.
14220
14221=end original
14222
14223特にこのようなことに関心がある場合は、自分で処理せずに、
14224CPAN の乱数発生モジュールを探してください。
14225
14226=begin original
14227
14228Frequently called programs (like CGI scripts) that simply use
14229
14230=end original
14231
14232(CGI スクリプトのような)頻繁に呼び出されるプログラムで単純に
14233
14234 time ^ $$
14235
14236=begin original
14237
14238for a seed can fall prey to the mathematical property that
14239
14240=end original
14241
14242を種として使うと、3 回に 1 回は以下の数学特性
14243
14244 a^b == (a+1)^(b+1)
14245
14246=begin original
14247
14248one-third of the time. So don't do that.
14249
14250=end original
14251
14252の餌食になります。
14253従ってこのようなことはしてはいけません。
14254
14255=begin original
14256
1425716902A typical use of the returned seed is for a test program which has too many
1425816903combinations to test comprehensively in the time available to it each run. It
1425916904can test a random subset each time, and should there be a failure, log the seed
1426016905used for that run so that it can later be used to reproduce the same results.
1426116906
1426216907=end original
1426316908
1426416909返された種の典型的な利用法は、実行毎のテストを利用可能な時間内に完全に
1426516910行うには組み合わせが多すぎるテストプログラム用です。
1426616911毎回ランダムなサブセットをテストし、もし失敗したら、その実行で使った
1426716912種をログに出力することで、後で同じ結果を再現するために使えます。
1426816913
16914=begin original
16915
16916B<L<C<rand>|/rand EXPR> is not cryptographically secure. You should not rely
16917on it in security-sensitive situations.> As of this writing, a
16918number of third-party CPAN modules offer random number generators
16919intended by their authors to be cryptographically secure,
16920including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
16921and L<Math::TrulyRandom>.
16922
16923=end original
16924
16925B<L<C<rand>|/rand EXPR> は暗号学的に安全ではありません。
16926セキュリティ的に重要な状況でこれに頼るべきではありません。>
16927これを書いている時点で、いくつかのサードパーティ CPAN モジュールが
16928作者によって暗号学的に安全であることを目的とした乱数生成器を
16929提供しています: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
16930L<Math::TrulyRandom> などです。
16931
1426916932=item stat FILEHANDLE
1427016933X<stat> X<file, status> X<ctime>
1427116934
1427216935=item stat EXPR
1427316936
1427416937=item stat DIRHANDLE
1427516938
1427616939=item stat
1427716940
16941=for Pod::Functions get a file's status information
16942
1427816943=begin original
1427916944
1428016945Returns a 13-element list giving the status info for a file, either
14281the file opened via FILEHANDLE or DIRHANDLE, or named by EXPR. If EXPR is
16946the file opened via FILEHANDLE or DIRHANDLE, or named by EXPR. If EXPR is
14282omitted, it stats C<$_> (not C<_>!). Returns the empty list if C<stat> fails. Typically
16947omitted, it stats L<C<$_>|perlvar/$_> (not C<_>!). Returns the empty
16948list if L<C<stat>|/stat FILEHANDLE> fails. Typically
1428316949used as follows:
1428416950
1428516951=end original
1428616952
1428716953FILEHANDLE か DIRHANDLE を通じてオープンされているファイルか、
1428816954EXPR で指定されるファイルの情報を与える、13 要素のリストを返します。
14289EXPR が省略されると、 C<$_> が用いられます (C<_> ではありません!)。
16955EXPR が省略されると、 L<C<$_>|perlvar/$_> が用いられます
14290C<stat> に失敗した場合に、空リストを返し
16956(C<_> ありせん!)
16957L<C<stat>|/stat FILEHANDLE> に失敗した場合には、空リストを返します。
1429116958普通は、以下のようにして使います:
1429216959
14293 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
16960 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
14294 $atime,$mtime,$ctime,$blksize,$blocks)
16961 $atime,$mtime,$ctime,$blksize,$blocks)
1429516962 = stat($filename);
1429616963
1429716964=begin original
1429816965
1429916966Not all fields are supported on all filesystem types. Here are the
1430016967meanings of the fields:
1430116968
1430216969=end original
1430316970
1430416971全てのファイルシステムで全てのフィールドに対応しているわけではありません。
1430516972フィールドの意味は以下の通りです。
1430616973
1430716974=begin original
1430816975
1430916976 0 dev device number of filesystem
1431016977 1 ino inode number
1431116978 2 mode file mode (type and permissions)
1431216979 3 nlink number of (hard) links to the file
1431316980 4 uid numeric user ID of file's owner
1431416981 5 gid numeric group ID of file's owner
1431516982 6 rdev the device identifier (special files only)
1431616983 7 size total size of file, in bytes
1431716984 8 atime last access time in seconds since the epoch
1431816985 9 mtime last modify time in seconds since the epoch
1431916986 10 ctime inode change time in seconds since the epoch (*)
14320 11 blksize preferred block size for file system I/O
16987 11 blksize preferred I/O size in bytes for interacting with the
14321 12 blocks actual number of blocks allocated
16988 file (may vary from file to file)
16989 12 blocks actual number of system-specific blocks allocated
16990 on disk (often, but not always, 512 bytes each)
1432216991
1432316992=end original
1432416993
1432516994 0 dev ファイルシステムのデバイス番号
1432616995 1 ino inode 番号
1432716996 2 mode ファイルモード (タイプとパーミッション)
1432816997 3 nlink ファイルへの(ハード)リンクの数
1432916998 4 uid ファイル所有者のユーザー ID の数値
1433016999 5 gid ファイル所有者のグループ ID の数値
1433117000 6 rdev デバイス識別子(特殊ファイルのみ)
1433217001 7 size ファイルサイズ(バイト単位)
1433317002 8 atime 紀元から、最後にアクセスされた時刻までの秒数
1433417003 9 mtime 紀元から、最後に修正(modify)された時刻までの秒数
1433517004 10 ctime 紀元から、inode 変更(change)された時刻までの秒数 (*)
14336 11 blksize ファイルシステム I/O に適したブロックサ
17005 11 blksize ファイルとの相互作用のために適した I/O ト数
14337 12 blocks 実際割り当てらるブロックの数
17006 (ファイルごと異なるかもし)
17007 12 blocks ディスクに割り当てたシステム依存のブロック(常にでは
17008 ありませんがたいていはそれぞれ 512 バイト)の数
1433817009
1433917010=begin original
1434017011
1434117012(The epoch was at 00:00 January 1, 1970 GMT.)
1434217013
1434317014=end original
1434417015
14345(紀元は GMT で 1970/01/01 00:00:00)
17016(紀元は GMT で 1970/01/01 00:00:00)
1434617017
1434717018=begin original
1434817019
14349(*) Not all fields are supported on all filesystem types. Notably, the
17020(*) Not all fields are supported on all filesystem types. Notably, the
1435017021ctime field is non-portable. In particular, you cannot expect it to be a
1435117022"creation time"; see L<perlport/"Files and Filesystems"> for details.
1435217023
1435317024=end original
1435417025
1435517026(*) 全てのフィールドが全てのファイルシステムタイプで対応しているわけでは
1435617027ありません。
1435717028明らかに、ctime のフィールドは移植性がありません。
1435817029特に、これから「作成時刻」を想定することは出来ません;
1435917030詳細については L<perlport/"Files and Filesystems"> を参照してください。
1436017031
1436117032=begin original
1436217033
14363If C<stat> is passed the special filehandle consisting of an underline, no
17034If L<C<stat>|/stat FILEHANDLE> is passed the special filehandle
14364stat is done, but the current contents of the stat structure from the
17035consisting of an underline, no stat is done, but the current contents of
14365last C<stat>, C<lstat>, or filetest are returned. Example:
17036the stat structure from the last L<C<stat>|/stat FILEHANDLE>,
17037L<C<lstat>|/lstat FILEHANDLE>, or filetest are returned. Example:
1436617038
1436717039=end original
1436817040
14369下線だけの _ という特別なファイルハンドルを C<stat> に渡すと、
17041下線だけの _ という特別なファイルハンドルを L<C<stat>|/stat FILEHANDLE>
14370実際には stat を行なわず、stat 構造体に残っている
17042渡すと、実際には stat を行なわず、stat 構造体に残っている
14371前回の stat やファイルテストの情報が返されます。
17043前回の L<C<stat>|/stat FILEHANDLE>, L<C<lstat>|/lstat FILEHANDLE>
17044ファイルテストの情報が返されます。
1437217045例:
1437317046
1437417047 if (-x $file && (($d) = stat(_)) && $d < 0) {
1437517048 print "$file is executable NFS file\n";
1437617049 }
1437717050
1437817051=begin original
1437917052
1438017053(This works on machines only for which the device number is negative
1438117054under NFS.)
1438217055
1438317056=end original
1438417057
14385(これは、NFS のもとでデバイス番号が負になるマシンで
17058(これは、NFS のもとでデバイス番号が負になるマシンでのみ動作します。)
14386のみ動作します。)
1438717059
1438817060=begin original
1438917061
1439017062Because the mode contains both the file type and its permissions, you
1439117063should mask off the file type portion and (s)printf using a C<"%o">
1439217064if you want to see the real permissions.
1439317065
1439417066=end original
1439517067
1439617068モードにはファイルタイプとその権限の両方が含まれているので、
1439717069本当の権限を見たい場合は、(s)printf で C<"%"> を使うことで
1439817070ファイルタイプをマスクするべきです。
1439917071
14400 $mode = (stat($filename))[2];
17072 my $mode = (stat($filename))[2];
1440117073 printf "Permissions are %04o\n", $mode & 07777;
1440217074
1440317075=begin original
1440417076
14405In scalar context, C<stat> returns a boolean value indicating success
17077In scalar context, L<C<stat>|/stat FILEHANDLE> returns a boolean value
17078indicating success
1440617079or failure, and, if successful, sets the information associated with
1440717080the special filehandle C<_>.
1440817081
1440917082=end original
1441017083
14411スカラコンテキストでは、C<stat> は成功か失敗を表す真偽値を返し、
17084スカラコンテキストでは、L<C<stat>|/stat FILEHANDLE> は成功か失敗を表す真偽値を
14412成功した場合は、特別なファイルハンドル C<_> に結び付けられた
17085返し、成功した場合は、特別なファイルハンドル C<_> に結び付けられた
1441317086情報をセットします。
1441417087
1441517088=begin original
1441617089
1441717090The L<File::stat> module provides a convenient, by-name access mechanism:
1441817091
1441917092=end original
1442017093
1442117094L<File::stat> モジュールは、便利な名前によるアクセス機構を提供します。
1442217095
1442317096 use File::stat;
14424 $sb = stat($filename);
17097 my $sb = stat($filename);
1442517098 printf "File is %s, size is %s, perm %04o, mtime %s\n",
1442617099 $filename, $sb->size, $sb->mode & 07777,
1442717100 scalar localtime $sb->mtime;
1442817101
1442917102=begin original
1443017103
1443117104You can import symbolic mode constants (C<S_IF*>) and functions
14432(C<S_IS*>) from the Fcntl module:
17105(C<S_IS*>) from the L<Fcntl> module:
1443317106
1443417107=end original
1443517108
14436モード定数 (C<S_IF*>) と関数 (C<S_IS*>) を Fcntl モジュールから
17109モード定数 (C<S_IF*>) と関数 (C<S_IS*>) を L<Fcntl> モジュールから
1443717110インポートできます。
1443817111
1443917112 use Fcntl ':mode';
1444017113
14441 $mode = (stat($filename))[2];
17114 my $mode = (stat($filename))[2];
1444217115
14443 $user_rwx = ($mode & S_IRWXU) >> 6;
17116 my $user_rwx = ($mode & S_IRWXU) >> 6;
14444 $group_read = ($mode & S_IRGRP) >> 3;
17117 my $group_read = ($mode & S_IRGRP) >> 3;
14445 $other_execute = $mode & S_IXOTH;
17118 my $other_execute = $mode & S_IXOTH;
1444617119
1444717120 printf "Permissions are %04o\n", S_IMODE($mode), "\n";
1444817121
14449 $is_setuid = $mode & S_ISUID;
17122 my $is_setuid = $mode & S_ISUID;
14450 $is_directory = S_ISDIR($mode);
17123 my $is_directory = S_ISDIR($mode);
1445117124
1445217125=begin original
1445317126
1445417127You could write the last two using the C<-u> and C<-d> operators.
1445517128Commonly available C<S_IF*> constants are:
1445617129
1445717130=end original
1445817131
1445917132最後の二つは C<-u> と C<-d> 演算子を使っても書けます。
1446017133一般に利用可能な C<S_IF*> 定数は以下のものです。
1446117134
1446217135 # Permissions: read, write, execute, for user, group, others.
1446317136
1446417137 S_IRWXU S_IRUSR S_IWUSR S_IXUSR
1446517138 S_IRWXG S_IRGRP S_IWGRP S_IXGRP
1446617139 S_IRWXO S_IROTH S_IWOTH S_IXOTH
1446717140
1446817141 # Setuid/Setgid/Stickiness/SaveText.
14469 # Note that the exact meaning of these is system dependent.
17142 # Note that the exact meaning of these is system-dependent.
1447017143
1447117144 S_ISUID S_ISGID S_ISVTX S_ISTXT
1447217145
14473 # File types. Not necessarily all are available on your system.
17146 # File types. Not all are necessarily available on
17147 # your system.
1447417148
14475 S_IFREG S_IFDIR S_IFLNK S_IFBLK S_IFCHR S_IFIFO S_IFSOCK S_IFWHT S_ENFMT
17149 S_IFREG S_IFDIR S_IFLNK S_IFBLK S_IFCHR
17150 S_IFIFO S_IFSOCK S_IFWHT S_ENFMT
1447617151
14477 # The following are compatibility aliases for S_IRUSR, S_IWUSR, S_IXUSR.
17152 # The following are compatibility aliases for S_IRUSR,
17153 # S_IWUSR, and S_IXUSR.
1447817154
1447917155 S_IREAD S_IWRITE S_IEXEC
1448017156
1448117157=begin original
1448217158
1448317159and the C<S_IF*> functions are
1448417160
1448517161=end original
1448617162
1448717163一般に利用可能な C<S_IF*> 関数は以下のものです。
1448817164
14489 S_IMODE($mode) the part of $mode containing the permission bits
17165 S_IMODE($mode) the part of $mode containing the permission
14490 and the setuid/setgid/sticky bits
17166 bits and the setuid/setgid/sticky bits
1449117167
14492 S_IFMT($mode) the part of $mode containing the file type
17168 S_IFMT($mode) the part of $mode containing the file type
14493 which can be bit-anded with (for example) S_IFREG
17169 which can be bit-anded with (for example)
14494 or with the following functions
17170 S_IFREG or with the following functions
1449517171
1449617172 # The operators -f, -d, -l, -b, -c, -p, and -S.
1449717173
1449817174 S_ISREG($mode) S_ISDIR($mode) S_ISLNK($mode)
1449917175 S_ISBLK($mode) S_ISCHR($mode) S_ISFIFO($mode) S_ISSOCK($mode)
1450017176
1450117177 # No direct -X operator counterpart, but for the first one
1450217178 # the -g operator is often equivalent. The ENFMT stands for
1450317179 # record flocking enforcement, a platform-dependent feature.
1450417180
1450517181 S_ISENFMT($mode) S_ISWHT($mode)
1450617182
1450717183=begin original
1450817184
14509See your native chmod(2) and stat(2) documentation for more details
17185See your native L<chmod(2)> and L<stat(2)> documentation for more details
1451017186about the C<S_*> constants. To get status info for a symbolic link
14511instead of the target file behind the link, use the C<lstat> function.
17187instead of the target file behind the link, use the
17188L<C<lstat>|/lstat FILEHANDLE> function.
1451217189
1451317190=end original
1451417191
14515C<S_*> 定数に関する詳細についてはネイティブの chmod(2) と stat(2) の
17192C<S_*> 定数に関する詳細についてはネイティブの L<chmod(2)>L<stat(2)>
14516ドキュメントを参照してさい。
17193ドキュメントを参照してください。
1451717194リンクの先にあるファイルではなく、シンボリックリンクそのものの情報を
14518得たい場合は、C<lstat> 関数を使ってください。
17195得たい場合は、L<C<lstat>|/lstat FILEHANDLE> 関数を使ってください。
1451917196
14520=item state EXPR
17197=begin original
17198
17199Portability issues: L<perlport/stat>.
17200
17201=end original
17202
17203移植性の問題: L<perlport/stat>。
17204
17205=item state VARLIST
1452117206X<state>
1452217207
14523=item state TYPE EXPR
17208=item state TYPE VARLIST
1452417209
14525=item state EXPR : ATTRS
17210=item state VARLIST : ATTRS
1452617211
14527=item state TYPE EXPR : ATTRS
17212=item state TYPE VARLIST : ATTRS
1452817213
17214=for Pod::Functions +state declare and assign a persistent lexical variable
17215
1452917216=begin original
1453017217
14531C<state> declares a lexically scoped variable, just like C<my> does.
17218L<C<state>|/state VARLIST> declares a lexically scoped variable, just
17219like L<C<my>|/my VARLIST>.
1453217220However, those variables will never be reinitialized, contrary to
1453317221lexical variables that are reinitialized each time their enclosing block
1453417222is entered.
17223See L<perlsub/"Persistent Private Variables"> for details.
1453517224
1453617225=end original
1453717226
14538C<state> は C<my> と同様に、レキシカルスコープの変数を宣言します。
17227L<C<state>|/state VARLIST> ちょうど L<C<my>|/my VARLIST> と同様に、
14539しかし、ブロックに入る毎に再初期化されるレキシカル変数と違って、
17228レキシカルなスコープの変数を宣言します。
14540これらの変数は決して再初期化されません。
17229しかし、レキシカル変数がブロックに入る毎に再初期化されるのと異なり、
17230この変数は決して再初期化されません。
17231詳しくは L<perlsub/"Persistent Private Variables"> を参照してください。
1454117232
1454217233=begin original
1454317234
14544C<state> variables are enabled only when the C<use feature "state"> pragma
17235If more than one variable is listed, the list must be placed in
14545is in effect. See L<feature>.
17236parentheses. With a parenthesised list, L<C<undef>|/undef EXPR> can be
17237used as a
17238dummy placeholder. However, since initialization of state variables in
17239list context is currently not possible this would serve no purpose.
1454617240
1454717241=end original
1454817242
14549C<state> 変は C<feature 'state'> プラグマが有効の場合のみ有効
17243数の変数を指定する場合、かっこ囲まなければなりません
14550L<feature> を参照してください。
17244かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> はダミーの
17245プレースホルダとして使えます。
17246しかし、リストコンテキストでの state 変数の初期化は現在のところできないので、
17247これは無意味です。
1455117248
17249=begin original
17250
17251L<C<state>|/state VARLIST> is available only if the
17252L<C<"state"> feature|feature/The 'state' feature> is enabled or if it is
17253prefixed with C<CORE::>. The
17254L<C<"state"> feature|feature/The 'state' feature> is enabled
17255automatically with a C<use v5.10> (or higher) declaration in the current
17256scope.
17257
17258=end original
17259
17260L<C<state>|/state VARLIST> は
17261L<C<"state"> 機能|feature/The 'state' feature> が有効か C<CORE::> を
17262前置した場合にのみ利用可能です。
17263L<C<"state"> 機能|feature/The 'state' feature> は現在のスコープで
17264C<use v5.10> (またはそれ以上) を宣言した場合自動的に有効になります。
17265
1455217266=item study SCALAR
1455317267X<study>
1455417268
1455517269=item study
1455617270
17271=for Pod::Functions optimize input data for repeated searches
17272
1455717273=begin original
1455817274
14559Takes extra time to study SCALAR (C<$_> if unspecified) in anticipation of
17275B<Note that since Perl version 5.16 this function has been a no-op, but
14560doing many pattern matches on the string before it is next modified.
17276this might change in a future release.>
17277
17278=end original
17279
17280B<Perl バージョン 5.16 からこの関数は何もしませんが、これは将来のリリースで
17281変更されるかもしれないことに注意してください。>
17282
17283=begin original
17284
17285May take extra time to study SCALAR (L<C<$_>|perlvar/$_> if unspecified)
17286in anticipation
17287of doing many pattern matches on the string before it is next modified.
1456117288This may or may not save time, depending on the nature and number of
1456217289patterns you are searching and the distribution of character
1456317290frequencies in the string to be searched; you probably want to compare
1456417291run times with and without it to see which is faster. Those loops
1456517292that scan for many short constant strings (including the constant
14566parts of more complex patterns) will benefit most. You may have only
17293parts of more complex patterns) will benefit most.
14567one C<study> active at a time: if you study a different scalar the first
14568is "unstudied". (The way C<study> works is this: a linked list of every
17295=end original
17296
17297次に変更される前に、この文字列で多くのパターンマッチングを行うと予想して
17298SCALAR (未指定の場合は L<C<$_>|perlvar/$_>) を学習するために追加の時間を
17299使います。
17300これは、検索するパターンの数と性質、および検索される文字列の文字頻度の
17301分散によって、時間短縮になることもならないことにもなります;
17302おそらくどちらが速いかを調べるためにこれありとなしとで実行時間を
17303比較した方がよいでしょう。
17304多くの短い固定文字列(より複雑なパターンの固定部分を含む)をスキャンする
17305ループで最も効果があります。
17306
17307=begin original
17308
17309(The way L<C<study>|/study SCALAR> used to work is this: a linked list
17310of every
1456917311character in the string to be searched is made, so we know, for
1457017312example, where all the C<'k'> characters are. From each search string,
1457117313the rarest character is selected, based on some static frequency tables
1457217314constructed from some C programs and English text. Only those places
1457317315that contain this "rarest" character are examined.)
1457417316
1457517317=end original
1457617318
14577に変更される前に、何回も文字列に対するパターンマッチを
17319(L<C<study>|/study SCALAR> の動作方法はのものでした: 検索される文字列
14578行なうアプケーションで、
17320全ての文字のリンクリストが作られるので、例えば、全ての C<'k'> 文字が
14579そのような文字列 SCALAR(省略時は C<$_>) 予め学習しておきます。
17321どこあるか知ります。
14580これは、検索のためにようなパターンを何回使うによって、
17322検索文字列からいくつか C プログラムと英文ら構築された
14581また、検索される文字列内の文字頻度の分布よって、
17323静的頻度テーブルを基最も頻度の少ない文字が選ばれます。
14582時間を節約することになるかれませんし、逆に浪費
17324の「もっとも稀な」文字を含む場所のみが調べられます。)
14583ことになるかもしれません。
14584予習をした場合と、しない場合の実行時間を比較して、
14585どちらが速いか調べることが、必要でしょう。
14586短い固定文字列 (複雑なパターンの固定部分を含みます) をたくさん
14587検索するループで、もっとも効果があるでしょう。
14588同時には、一つの C<study>だけが有効です。
14589別のスカラを study した場合には、以前に学習した内容は
14590「忘却」されてしまいます。
14591(この C<study> の仕組みは、まず、検索される文字列内の
14592すべての文字のリンクされたリストが作られ、たとえば、
14593すべての C<'k'> がどこにあるかがわかるようになります。
14594各々の検索文字列から、C プログラムや英語のテキストから作られた
14595頻度の統計情報に基づいて、もっとも珍しい文字が選ばれます。
14596この「珍しい」文字を含む場所だけが調べられるのです。)
1459717325
1459817326=begin original
1459917327
1460017328For example, here is a loop that inserts index producing entries
1460117329before any line containing a certain pattern:
1460217330
1460317331=end original
1460417332
1460517333たとえば、特定のパターンを含む行の前にインデックスを
1460617334付けるエントリを入れる例を示します。
1460717335
1460817336 while (<>) {
1460917337 study;
1461017338 print ".IX foo\n" if /\bfoo\b/;
1461117339 print ".IX bar\n" if /\bbar\b/;
1461217340 print ".IX blurfl\n" if /\bblurfl\b/;
1461317341 # ...
1461417342 print;
1461517343 }
1461617344
1461717345=begin original
1461817346
14619In searching for C</\bfoo\b/>, only locations in C<$_> that contain C<f>
17347In searching for C</\bfoo\b/>, only locations in L<C<$_>|perlvar/$_>
17348that contain C<f>
1462017349will be looked at, because C<f> is rarer than C<o>. In general, this is
1462117350a big win except in pathological cases. The only question is whether
1462217351it saves you more time than it took to build the linked list in the
1462317352first place.
1462417353
1462517354=end original
1462617355
14627C<f> は C<o> よりも珍しいので、C</\bfoo\b/> を探すとき、C<$_> で C<f>
17356C<f> は C<o> よりも珍しいので、C</\bfoo\b/> を探すとき、L<C<$_>|perlvar/$_>
14628含む場所だけが探されます。
17357C<f> を含む場所だけが探されます。
1462917358一般に、病的な場合を除いて、かなりの結果が得られます。
1463017359唯一の問題は、節約できる時間が、最初にリンクリストを作る
1463117360時間よりも多いかどうかです、
1463217361
1463317362=begin original
1463417363
1463517364Note that if you have to look for strings that you don't know till
14636runtime, you can build an entire loop as a string and C<eval> that to
17365runtime, you can build an entire loop as a string and L<C<eval>|/eval
14637avoid recompiling all your patterns all the time. Together with
17366EXPR> that to avoid recompiling all your patterns all the time.
14638undefining C<$/> to input entire files as one record, this can be quite
17367Together with undefining L<C<$E<sol>>|perlvar/$E<sol>> to input entire
14639fast, often faster than specialized programs like fgrep(1). The following
17368files as one record, this can be quite
17369fast, often faster than specialized programs like L<fgrep(1)>. The following
1464017370scans a list of files (C<@files>) for a list of words (C<@words>), and prints
1464117371out the names of those files that contain a match:
1464217372
1464317373=end original
1464417374
1464517375実行時まで、探そうとする文字列がわからないときには、
14646ループ全体を文字列として組み立てて、C<eval> すれば、
17376ループ全体を文字列として組み立てて、L<C<eval>|/eval EXPR> すれば、
1464717377いつも、すべてのパターンを再コンパイルするという事態は避けられます。
1464817378ファイル全体を一つのレコードとして入力するために、
14649C<$/> を未定義にすれば、かなり速くなり、
17379L<C<$E<sol>>|perlvar/$E<sol>> を未定義にすれば、かなり速くなり、
14650多くの場合 fgrep(1) のような専用のプログラムより速くなります。
17380多くの場合 L<fgrep(1)> のような専用のプログラムより速くなります。
1465117381以下の例は、ファイルのリスト (C<@files>) から単語のリスト (C<@words>) を
1465217382探して、マッチするものがあったファイル名を出力します。
1465317383
14654 $search = 'while (<>) { study;';
17384 my $search = 'local $/; while (<>) { study;';
14655 foreach $word (@words) {
17385 foreach my $word (@words) {
1465617386 $search .= "++\$seen{\$ARGV} if /\\b$word\\b/;\n";
1465717387 }
1465817388 $search .= "}";
1465917389 @ARGV = @files;
14660 undef $/;
17390 my %seen;
1466117391 eval $search; # this screams
14662 $/ = "\n"; # put back to normal input delimiter
17392 foreach my $file (sort keys(%seen)) {
14663 foreach $file (sort keys(%seen)) {
1466417393 print $file, "\n";
1466517394 }
1466617395
1466717396=item sub NAME BLOCK
1466817397X<sub>
1466917398
1467017399=item sub NAME (PROTO) BLOCK
1467117400
1467217401=item sub NAME : ATTRS BLOCK
1467317402
1467417403=item sub NAME (PROTO) : ATTRS BLOCK
1467517404
17405=for Pod::Functions declare a subroutine, possibly anonymously
17406
1467617407=begin original
1467717408
1467817409This is subroutine definition, not a real function I<per se>. Without a
1467917410BLOCK it's just a forward declaration. Without a NAME, it's an anonymous
1468017411function declaration, so does return a value: the CODE ref of the closure
1468117412just created.
1468217413
1468317414=end original
1468417415
1468517416これはサブルーチン定義であり、I<本質的には> 実際の関数ではありません。
1468617417BLOCK なしの場合、これは単に前方宣言です。
1468717418NAME なしの場合は、無名関数定義であり、値(作成したブロックの
1468817419コードリファレンス)を返します: 単にクロージャの CODE リファレンスが
1468917420作成されます。
1469017421
1469117422=begin original
1469217423
1469317424See L<perlsub> and L<perlref> for details about subroutines and
1469417425references; see L<attributes> and L<Attribute::Handlers> for more
1469517426information about attributes.
1469617427
1469717428=end original
1469817429
1469917430サブルーチンとリファレンスに関する詳細については、L<perlsub> と
1470017431L<perlref> を参照してください; 属性に関する更なる情報については
1470117432L<attributes> と L<Attribute::Handlers> を参照してください。
1470217433
17434=item __SUB__
17435X<__SUB__>
17436
17437=for Pod::Functions +current_sub the current subroutine, or C<undef> if not in a subroutine
17438
17439=begin original
17440
17441A special token that returns a reference to the current subroutine, or
17442L<C<undef>|/undef EXPR> outside of a subroutine.
17443
17444=end original
17445
17446現在のサブルーチンのリファレンスを返す特殊トークン; サブルーチンの外側では
17447L<C<undef>|/undef EXPR>。
17448
17449=begin original
17450
17451The behaviour of L<C<__SUB__>|/__SUB__> within a regex code block (such
17452as C</(?{...})/>) is subject to change.
17453
17454=end original
17455
17456(C</(?{...})/> のような) 正規表現コードブロックの中の
17457L<C<__SUB__>|/__SUB__> の振る舞いは変更される予定です。
17458
17459=begin original
17460
17461This token is only available under C<use v5.16> or the
17462L<C<"current_sub"> feature|feature/The 'current_sub' feature>.
17463See L<feature>.
17464
17465=end original
17466
17467このトークンは C<use v5.16> または
17468L<C<"current_sub"> 機能|feature/The 'current_sub' feature> でのみ
17469利用可能です。
17470L<feature> を参照してください。
17471
1470317472=item substr EXPR,OFFSET,LENGTH,REPLACEMENT
1470417473X<substr> X<substring> X<mid> X<left> X<right>
1470517474
1470617475=item substr EXPR,OFFSET,LENGTH
1470717476
1470817477=item substr EXPR,OFFSET
1470917478
17479=for Pod::Functions get or alter a portion of a string
17480
1471017481=begin original
1471117482
1471217483Extracts a substring out of EXPR and returns it. First character is at
14713offset C<0> (or whatever you've set C<$[> to (but B<<don't do that>)).
17484offset zero. If OFFSET is negative, starts
14714If OFFSET is negative (or more precisely, less than C<$[>), starts
1471517485that far back from the end of the string. If LENGTH is omitted, returns
1471617486everything through the end of the string. If LENGTH is negative, leaves that
1471717487many characters off the end of the string.
1471817488
1471917489=end original
1472017490
1472117491EXPR から、部分文字列を取り出して返します。
14722最初の文字がオフセット C<0> (もしくは、C<$[> に設定した値
17492最初の文字がオフセット 0 となります。
14723(しかしこれ使ってはいけません))となります。
17493OFFSET に負の値設定すると、EXPR の終わりからのオフセットとなります。
14724OFFSET に負の値(より厳密には、C<$[>より小さい値)を設定すると、
14725EXPR の終わりからのオフセットとなります。
1472617494LENGTH を省略すると、EXPR の最後まですべてが返されます。
1472717495LENGTH が負の値だと、文字列の最後から指定された数だけ文字を取り除きます。
1472817496
1472917497 my $s = "The black cat climbed the green tree";
1473017498 my $color = substr $s, 4, 5; # black
1473117499 my $middle = substr $s, 4, -11; # black cat climbed the
1473217500 my $end = substr $s, 14; # climbed the green tree
1473317501 my $tail = substr $s, -4; # tree
1473417502 my $z = substr $s, -4, 2; # tr
1473517503
1473617504=begin original
1473717505
14738You can use the substr() function as an lvalue, in which case EXPR
17506You can use the L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT>
17507function as an lvalue, in which case EXPR
1473917508must itself be an lvalue. If you assign something shorter than LENGTH,
1474017509the string will shrink, and if you assign something longer than LENGTH,
1474117510the string will grow to accommodate it. To keep the string the same
14742length, you may need to pad or chop your value using C<sprintf>.
17511length, you may need to pad or chop your value using
17512L<C<sprintf>|/sprintf FORMAT, LIST>.
1474317513
1474417514=end original
1474517515
14746substr() を左辺値として使用することも可能で、その場合には、
17516L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> を左辺値として
14747EXPR が自身左辺値でなければなりません。
17517使用することも可能で、その場合には、EXPR が自身左辺値でなければなりません。
1474817518LENGTH より短いものを代入したときには、
1474917519EXPR は短くなり、LENGTH より長いものを代入したときには、
1475017520EXPR はそれに合わせて伸びることになります。
14751EXPR の長さを一定に保つためには、C<sprintf> を使って、
17521EXPR の長さを一定に保つためには、L<C<sprintf>|/sprintf FORMAT, LIST>
14752代入する値の長さを調整することが、必要になるかもしれません。
17522使って、代入する値の長さを調整することが、必要になるかもしれません。
1475317523
1475417524=begin original
1475517525
1475617526If OFFSET and LENGTH specify a substring that is partly outside the
1475717527string, only the part within the string is returned. If the substring
14758is beyond either end of the string, substr() returns the undefined
17528is beyond either end of the string,
17529L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> returns the undefined
1475917530value and produces a warning. When used as an lvalue, specifying a
1476017531substring that is entirely outside the string raises an exception.
1476117532Here's an example showing the behavior for boundary cases:
1476217533
1476317534=end original
1476417535
1476517536OFFSET と LENGTH として文字列の外側を含むような部分文字列が指定されると、
1476617537文字列の内側の部分だけが返されます。
14767部分文字列が文字列の両端の外側の場合、substr() は未定義値を返し、
17538部分文字列が文字列の両端の外側の場合、
17539L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> は未定義値を返し、
1476817540警告が出力されます。
1476917541左辺値として使った場合、文字列の完全に外側を部分文字列として指定すると
1477017542例外が発生します。
1477117543以下は境界条件の振る舞いを示す例です:
1477217544
1477317545 my $name = 'fred';
1477417546 substr($name, 4) = 'dy'; # $name is now 'freddy'
1477517547 my $null = substr $name, 6, 2; # returns "" (no warning)
1477617548 my $oops = substr $name, 7; # returns undef, with warning
1477717549 substr($name, 7) = 'gap'; # raises an exception
1477817550
1477917551=begin original
1478017552
14781An alternative to using substr() as an lvalue is to specify the
17553An alternative to using
17554L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> as an lvalue is to
17555specify the
1478217556replacement string as the 4th argument. This allows you to replace
1478317557parts of the EXPR and return what was there before in one operation,
14784just as you can with splice().
17558just as you can with
17559L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST>.
1478517560
1478617561=end original
1478717562
14788substr() を左辺値として使う代わりの方法は、置き換える文字列を 4 番目の
17563L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> を左辺値として使う
14789引数として指定することです。
17564代わりの方法は、置き換える文字列を 4 番目の引数として指定することです。
1479017565これにより、EXPR の一部を置き換え、置き換える前が何であったかを返す、
14791ということを(splice() と同様) 1 動作で行えます。
17566ということを(L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> と同様)
175671 動作で行えます。
1479217568
1479317569 my $s = "The black cat climbed the green tree";
1479417570 my $z = substr $s, 14, 7, "jumped from"; # climbed
1479517571 # $s is now "The black cat jumped from the green tree"
1479617572
1479717573=begin original
1479817574
14799Note that the lvalue returned by the three-argument version of substr() acts as
17575Note that the lvalue returned by the three-argument version of
17576L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> acts as
1480017577a 'magic bullet'; each time it is assigned to, it remembers which part
1480117578of the original string is being modified; for example:
1480217579
1480317580=end original
1480417581
148053 引数の substr() によって返された左辺値は「魔法の弾丸」のように振舞うことに
175823 引数の L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> によって返された
14806注意してください; これが代入される毎に、元の文字列のどの部分が変更されたかが
17583左辺値は「魔法の弾丸」のように振舞うことに注意してください;
14807思い出されます; 例えば:
17584これが代入される毎に、元の文字列のどの部分が変更されたかが思い出されます;
17585例えば:
1480817586
14809 $x = '1234';
17587 my $x = '1234';
1481017588 for (substr($x,1,2)) {
1481117589 $_ = 'a'; print $x,"\n"; # prints 1a4
1481217590 $_ = 'xyz'; print $x,"\n"; # prints 1xyz4
1481317591 $x = '56789';
1481417592 $_ = 'pq'; print $x,"\n"; # prints 5pq9
1481517593 }
1481617594
1481717595=begin original
1481817596
14819Prior to Perl version 5.9.1, the result of using an lvalue multiple times was
17597With negative offsets, it remembers its position from the end of the string
17598when the target string is modified:
17599
17600=end original
17601
17602負数のオフセットの場合、ターゲット文字列が修正されたときに文字列の末尾からの
17603位置を覚えます:
17604
17605 my $x = '1234';
17606 for (substr($x, -3, 2)) {
17607 $_ = 'a'; print $x,"\n"; # prints 1a4, as above
17608 $x = 'abcdefg';
17609 print $_,"\n"; # prints f
17610 }
17611
17612=begin original
17613
17614Prior to Perl version 5.10, the result of using an lvalue multiple times was
17615unspecified. Prior to 5.16, the result with negative offsets was
1482017616unspecified.
1482117617
1482217618=end original
1482317619
14824バージョン 5.9.1 前の Perl では、複数回左辺値を使った場合の結果は
17620バージョン 5.10 より前の Perl では、複数回左辺値を使った場合の結果は
1482517621未定義でした。
176225.16 より前では、負のオフセットの結果は未定義です。
1482617623
1482717624=item symlink OLDFILE,NEWFILE
1482817625X<symlink> X<link> X<symbolic link> X<link, symbolic>
1482917626
17627=for Pod::Functions create a symbolic link to a file
17628
1483017629=begin original
1483117630
1483217631Creates a new filename symbolically linked to the old filename.
1483317632Returns C<1> for success, C<0> otherwise. On systems that don't support
1483417633symbolic links, raises an exception. To check for that,
1483517634use eval:
1483617635
1483717636=end original
1483817637
1483917638NEWFILE として、OLDFILE へのシンボリックリンクを生成します。
1484017639成功時には C<1> を返し、失敗時には C<0> を返します。
1484117640シンボリックリンクをサポートしていないシステムでは、
1484217641例外が発生します。
1484317642これをチェックするには、eval を使用します:
1484417643
14845 $symlink_exists = eval { symlink("",""); 1 };
17644 my $symlink_exists = eval { symlink("",""); 1 };
1484617645
17646=begin original
17647
17648Portability issues: L<perlport/symlink>.
17649
17650=end original
17651
17652移植性の問題: L<perlport/symlink>。
17653
1484717654=item syscall NUMBER, LIST
1484817655X<syscall> X<system call>
1484917656
17657=for Pod::Functions execute an arbitrary system call
17658
1485017659=begin original
1485117660
1485217661Calls the system call specified as the first element of the list,
1485317662passing the remaining elements as arguments to the system call. If
1485417663unimplemented, raises an exception. The arguments are interpreted
1485517664as follows: if a given argument is numeric, the argument is passed as
1485617665an int. If not, the pointer to the string value is passed. You are
1485717666responsible to make sure a string is pre-extended long enough to
1485817667receive any result that might be written into a string. You can't use a
14859string literal (or other read-only string) as an argument to C<syscall>
17668string literal (or other read-only string) as an argument to
14860because Perl has to assume that any string pointer might be written
17669L<C<syscall>|/syscall NUMBER, LIST> because Perl has to assume that any
14861through. If your
17670string pointer might be written through. If your
1486217671integer arguments are not literals and have never been interpreted in a
1486317672numeric context, you may need to add C<0> to them to force them to look
14864like numbers. This emulates the C<syswrite> function (or vice versa):
17673like numbers. This emulates the
17674L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> function (or
17675vice versa):
1486517676
1486617677=end original
1486717678
1486817679LIST の最初の要素で指定するシステムコールを、残りの要素をその
1486917680システムコールの引数として呼び出します。
14870実装されていないときには、例外が発生します。
17681実装されていない場合には、例外が発生します。
1487117682引数は、以下のように解釈されます: 引数が数字であれば、int として
1487217683引数を渡します。
1487317684そうでなければ、文字列値へのポインタが渡されます。
1487417685文字列に結果を受け取るときには、その結果を受け取るのに十分なくらいに、
1487517686文字列を予め伸ばしておく必要があります。
14876文字列リテラル(あるいはその他の読み込み専用の文字列)を C<syscall> の
17687文字列リテラル(あるいはその他の読み込み専用の文字列)を
14877引数として使うことはできません
17688L<C<syscall>|/syscall NUMBER, LIST> の引数として使うことはできません;
1487817689Perl は全ての文字列ポインタは書き込まれると仮定しなければならないからです。
14879整数引数が、リテラルでなく、数値コンテキストで評価されたことの
17690整数引数が、リテラルでなく、数値コンテキストで評価されたことのない
14880ないものであれば、数値として解釈されるように、
17691ものであれば、数値として解釈されるように、
1488117692C<0> を足しておく必要があるかもしれません。
14882以下は C<syswrite> 関数(あるいはその逆)をエミュレートします。
17693以下は L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> 関数(あるいは
17694その逆)をエミュレートします。
1488317695
1488417696 require 'syscall.ph'; # may need to run h2ph
14885 $s = "hi there\n";
17697 my $s = "hi there\n";
14886 syscall(&SYS_write, fileno(STDOUT), $s, length $s);
17698 syscall(SYS_write(), fileno(STDOUT), $s, length $s);
1488717699
1488817700=begin original
1488917701
1489017702Note that Perl supports passing of up to only 14 arguments to your syscall,
1489117703which in practice should (usually) suffice.
1489217704
1489317705=end original
1489417706
1489517707Perl は、システムコールに最大 14 個の引数しか渡せませんが、
1489617708(普通は)実用上問題はないでしょう。
1489717709
1489817710=begin original
1489917711
1490017712Syscall returns whatever value returned by the system call it calls.
14901If the system call fails, C<syscall> returns C<-1> and sets C<$!> (errno).
17713If the system call fails, L<C<syscall>|/syscall NUMBER, LIST> returns
17714C<-1> and sets L<C<$!>|perlvar/$!> (errno).
1490217715Note that some system calls I<can> legitimately return C<-1>. The proper
14903way to handle such calls is to assign C<$!=0> before the call, then
17716way to handle such calls is to assign C<$! = 0> before the call, then
14904check the value of C<$!> if C<syscall> returns C<-1>.
17717check the value of L<C<$!>|perlvar/$!> if
17718L<C<syscall>|/syscall NUMBER, LIST> returns C<-1>.
1490517719
1490617720=end original
1490717721
1490817722syscall は、呼び出したシステムコールが返した値を返します。
14909システムコールが失敗すると、C<syscall> は C<-1> を返し、
17723システムコールが失敗すると、L<C<syscall>|/syscall NUMBER, LIST> は C<-1> を
14910C<$!>(errno) を設定します。
17724返し、L<C<$!>|perlvar/$!>(errno) を設定します。
1491117725システムコールが正常に C<-1> を返す I<場合がある> ことに注意してください。
1491217726このようなシステムコールを正しく扱うには、
14913C<$!=0> をシステムコールの前に実行し、それから
17727C<$! = 0> をシステムコールの前に実行し、それから
14914C<syscall> が C<-1> を返した時には C<$!> の値を調べてください。
17728L<C<syscall>|/syscall NUMBER, LIST> が C<-1> を返した時には
17729L<C<$!>|perlvar/$!> の値を調べてください。
1491517730
1491617731=begin original
1491717732
14918There's a problem with C<syscall(&SYS_pipe)>: it returns the file
17733There's a problem with C<syscall(SYS_pipe())>: it returns the file
1491917734number of the read end of the pipe it creates, but there is no way
1492017735to retrieve the file number of the other end. You can avoid this
14921problem by using C<pipe> instead.
17736problem by using L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> instead.
1492217737
1492317738=end original
1492417739
14925C<syscall(&SYS_pipe)> には問題があり、
17740C<syscall(&SYS_pipe)> には問題があり、作ったパイプの、読み出し側の
14926作ったパイプの、読み出し側のファイル番号を返しますが、
17741ファイル番号を返しますが、もう一方のファイル番号を得る方法がありません。
14927もう一方ファイル番号方法があません。
17742問題避けためには、代わに L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> を
14928この問題を避けるためには、代わりに C<pipe> を使ってください。
17743使ってください。
1492917744
17745=begin original
17746
17747Portability issues: L<perlport/syscall>.
17748
17749=end original
17750
17751移植性の問題: L<perlport/syscall>。
17752
1493017753=item sysopen FILEHANDLE,FILENAME,MODE
1493117754X<sysopen>
1493217755
1493317756=item sysopen FILEHANDLE,FILENAME,MODE,PERMS
1493417757
17758=for Pod::Functions +5.002 open a file, pipe, or descriptor
17759
1493517760=begin original
1493617761
1493717762Opens the file whose filename is given by FILENAME, and associates it with
1493817763FILEHANDLE. If FILEHANDLE is an expression, its value is used as the real
14939filehandle wanted; an undefined scalar will be suitably autovivified. This
17764filehandle wanted; an undefined scalar will be suitably autovivified. This
14940function calls the underlying operating system's I<open>(2) function with the
17765function calls the underlying operating system's L<open(2)> function with the
1494117766parameters FILENAME, MODE, and PERMS.
1494217767
1494317768=end original
1494417769
1494517770FILENAME で与えられたファイル名のファイルをオープンし、
1494617771FILEHANDLE と結び付けます。
1494717772FILEHANDLE が式の場合、その値は実際の求めているファイルハンドルの名前として
1494817773扱われます; 未定義のスカラは適切に自動有効化されます。
14949この関数呼び出しはシステムの I<open>(2) 関数を FILENAME, MODE, PERMS の
17774この関数呼び出しはシステムの L<open(2)> 関数を FILENAME, MODE, PERMS の
1495017775引数で呼び出すことを基礎としています。
1495117776
1495217777=begin original
1495317778
17779Returns true on success and L<C<undef>|/undef EXPR> otherwise.
17780
17781=end original
17782
17783成功時は真を、さもなければ L<C<undef>|/undef EXPR> を返します。
17784
17785=begin original
17786
1495417787The possible values and flag bits of the MODE parameter are
14955system-dependent; they are available via the standard module C<Fcntl>. See
17788system-dependent; they are available via the standard module
14956the documentation of your operating system's I<open>(2) syscall to see
17789L<C<Fcntl>|Fcntl>. See the documentation of your operating system's
17790L<open(2)> syscall to see
1495717791which values and flag bits are available. You may combine several flags
1495817792using the C<|>-operator.
1495917793
1496017794=end original
1496117795
1496217796MODE パラメータに指定できるフラグビットと値はシステム依存です;
14963これは標準モジュール C<Fcntl> 経由で利用可能です。
17797これは標準モジュール L<C<Fcntl>|Fcntl> 経由で利用可能です。
1496417798どのようなフラグビットと値が利用可能であるかについては、
14965OS の I<open>(2) システムコールに関する文書を参照してください。
17799OS の L<open(2)> システムコールに関する文書を参照してください。
1496617800C<|> 演算子を使って複数のフラグを結合することができます。
1496717801
1496817802=begin original
1496917803
1497017804Some of the most common values are C<O_RDONLY> for opening the file in
1497117805read-only mode, C<O_WRONLY> for opening the file in write-only mode,
1497217806and C<O_RDWR> for opening the file in read-write mode.
1497317807X<O_RDONLY> X<O_RDWR> X<O_WRONLY>
1497417808
1497517809=end original
1497617810
1497717811もっともよく使われる値は、ファイルを読み込み専用で開く C<O_RDONLY>、
1497817812ファイルを書き込み専用で開く C<O_WRONLY>、
1497917813ファイルを読み書き両用で開く C<O_RDWR> です。
1498017814X<O_RDONLY> X<O_RDWR> X<O_WRONLY>
1498117815
1498217816=begin original
1498317817
1498417818For historical reasons, some values work on almost every system
1498517819supported by Perl: 0 means read-only, 1 means write-only, and 2
1498617820means read/write. We know that these values do I<not> work under
14987OS/390 & VM/ESA Unix and on the Macintosh; you probably don't want to
17821OS/390 and on the Macintosh; you probably don't want to
1498817822use them in new code.
1498917823
1499017824=end original
1499117825
14992歴史的な理由により、Perl が対応しているほとんどのシステムで
17826歴史的な理由により、Perl が対応しているほとんどのシステムで使える値が
14993使える値があります。
17827あります:0 は読み込み専用、1 は書き込み専用、2 は読み書き両用を意味します。
149940 は読み込み専用、1 は書き込み専用、2読み書き両用を意味します
17828OS/390 Macintosh 動作 I<ない> ことが分かっています;
14995OS/390 & VM/ESA Unix と Macintosh では動作 I<しない> ことが分かっています;
1499617829新しく書くコードではこれらは使わないほうがよいでしょう。
1499717830
1499817831=begin original
1499917832
15000If the file named by FILENAME does not exist and the C<open> call creates
17833If the file named by FILENAME does not exist and the
17834L<C<open>|/open FILEHANDLE,EXPR> call creates
1500117835it (typically because MODE includes the C<O_CREAT> flag), then the value of
1500217836PERMS specifies the permissions of the newly created file. If you omit
15003the PERMS argument to C<sysopen>, Perl uses the octal value C<0666>.
17837the PERMS argument to L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>,
17838Perl uses the octal value C<0666>.
1500417839These permission values need to be in octal, and are modified by your
15005process's current C<umask>.
17840process's current L<C<umask>|/umask EXPR>.
1500617841X<O_CREAT>
1500717842
1500817843=end original
1500917844
1501017845FILENAME という名前のファイルが存在せず、(典型的には MODE が
15011C<O_CREAT> フラグを含んでいたために) C<open> 呼び出しがそれを作った場合、
17846C<O_CREAT> フラグを含んでいたために)
17847L<C<open>|/open FILEHANDLE,EXPR> 呼び出しがそれを作った場合、
1501217848PERMS の値は新しく作られたファイルの権限を指定します。
15013C<sysopen> の PERMS 引数を省略した場合、Perl は 8 進数 C<0666> を使います。
17849L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> の PERMS 引数を省略した場合、
15014これらの権限は 8 進数である必要があり、プロセスの現在の C<umask>
17850Perl は 8 進数 C<0666> を使います。
15015修正さます。
17851らの権限は 8 進数である必要があり、プロセスの現在の
17852L<C<umask>|/umask EXPR> で修正されます。
1501617853X<O_CREAT>
1501717854
1501817855=begin original
1501917856
1502017857In many systems the C<O_EXCL> flag is available for opening files in
1502117858exclusive mode. This is B<not> locking: exclusiveness means here that
15022if the file already exists, sysopen() fails. C<O_EXCL> may not work
17859if the file already exists,
17860L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> fails. C<O_EXCL> may
17861not work
1502317862on network filesystems, and has no effect unless the C<O_CREAT> flag
1502417863is set as well. Setting C<O_CREAT|O_EXCL> prevents the file from
1502517864being opened if it is a symbolic link. It does not protect against
1502617865symbolic links in the file's path.
1502717866X<O_EXCL>
1502817867
1502917868=end original
1503017869
1503117870多くのシステムではファイルを排他モードで開くために C<O_EXCL> が
1503217871利用可能です。
1503317872これはロック B<ではありません>: 排他性というのは既にファイルが
15034存在していた場合、sysopen()失敗することを意味します。
17873存在していた場合、L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>
17874失敗することを意味します。
1503517875C<O_EXCL> はネットワークファイルシステムでは動作せず、
1503617876またC<O_CREAT> フラグも有効でない限りは効果がありません。
1503717877C<O_CREAT|O_EXCL> をセットすると、これがシンボリックリンクだった場合は
1503817878ファイルを開くことを妨げます。
1503917879これはファイルパス中のシンボリックリンクは守りません。
1504017880X<O_EXCL>
1504117881
1504217882=begin original
1504317883
1504417884Sometimes you may want to truncate an already-existing file. This
1504517885can be done using the C<O_TRUNC> flag. The behavior of
1504617886C<O_TRUNC> with C<O_RDONLY> is undefined.
1504717887X<O_TRUNC>
1504817888
1504917889=end original
1505017890
1505117891既に存在しているファイルを切り詰めたい場合もあるかもしれません。
1505217892これは C<O_TRUNC> フラグを使うことで行えます。
1505317893C<O_RDONLY> と C<O_TRUNC> を同時に指定したときの振る舞いは未定義です。
1505417894X<O_TRUNC>
1505517895
1505617896=begin original
1505717897
15058You should seldom if ever use C<0644> as argument to C<sysopen>, because
17898You should seldom if ever use C<0644> as argument to
17899L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>, because
1505917900that takes away the user's option to have a more permissive umask.
15060Better to omit it. See the perlfunc(1) entry on C<umask> for more
17901Better to omit it. See L<C<umask>|/umask EXPR> for more on this.
15061on this.
1506217902
1506317903=end original
1506417904
15065めったなことでは C<sysopen> の引数に C<0644> を指定するべきではないでしょう:
17905めったなことでは L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> の引数に
17906C<0644> を指定するべきではないでしょう:
1506617907ユーザーがより寛大な umask を指定する選択肢を奪うからです。
1506717908省略した方がいいです。
15068これに関するさらなる情報については perlfunc(1) の C<umask> を
17909これに関するさらなる情報については L<C<umask>|/umask EXPR> を
1506917910参照してください。
1507017911
1507117912=begin original
1507217913
15073Note that C<sysopen> depends on the fdopen() C library function.
17914Note that under Perls older than 5.8.0,
15074On many Unix systems, fdopen() is known to fail when file descriptors
17915L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> depends on the
15075exceed a certain value, typically 255. If you need more file
17916L<fdopen(3)> C library function. On many Unix systems, L<fdopen(3)> is known
15076descriptors than that, consider rebuilding Perl to use the C<sfio>
17917to fail when file descriptors exceed a certain value, typically 255. If
15077library, or perhaps using the POSIX::open() function.
17918you need more file descriptors than that, consider using the
17919L<C<POSIX::open>|POSIX/C<open>> function. For Perls 5.8.0 and later,
17920PerlIO is (most often) the default.
1507817921
1507917922=end original
1508017923
15081C<sysopen> C の fdopen() ライブラリ関数に依存していることに注意してください。
179245.8.0 より古い Perl では、
15082多くの Unix システムでは、fdopen() はファイル記述子がある値(例えば 255)を超えると
17925L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>
15083失敗することが知られています
17926C の L<fdopen(3)> ライブラリ関数に依存していることに注意しください。
17927多くの Unix システムでは、L<fdopen(3)> はファイル記述子がある値(例えば 255)を
17928超えると失敗することが知られています。
1508417929これより多くのファイル記述子が必要な場合は、
15085Perl を C<sfio> ライブラリを使再ビルドするか、
17930L<C<POSIX::open>|POSIX/C<open>> 関数を使うことを検討しください。
15086POSIX::open() 関数を使うことを健闘してください
17931Perl 5.8.0 以降では、(ほぼ確実に) PerlIO がデフォルトです
1508717932
1508817933=begin original
1508917934
1509017935See L<perlopentut> for a kinder, gentler explanation of opening files.
1509117936
1509217937=end original
1509317938
15094ファイル操作に関するより親切な説明については L<perlopentut> を参照して下さい。
17939ファイルを開くことに関するより親切な説明については L<perlopentut> を
17940参照してください。
1509517941
17942=begin original
17943
17944Portability issues: L<perlport/sysopen>.
17945
17946=end original
17947
17948移植性の問題: L<perlport/sysopen>。
17949
1509617950=item sysread FILEHANDLE,SCALAR,LENGTH,OFFSET
1509717951X<sysread>
1509817952
1509917953=item sysread FILEHANDLE,SCALAR,LENGTH
1510017954
17955=for Pod::Functions fixed-length unbuffered input from a filehandle
17956
1510117957=begin original
1510217958
1510317959Attempts to read LENGTH bytes of data into variable SCALAR from the
15104specified FILEHANDLE, using the read(2). It bypasses
17960specified FILEHANDLE, using L<read(2)>. It bypasses
15105buffered IO, so mixing this with other kinds of reads, C<print>,
17961buffered IO, so mixing this with other kinds of reads,
15106C<write>, C<seek>, C<tell>, or C<eof> can cause confusion because the
17962L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
15107perlio or stdio layers usually buffers data. Returns the number of
17963L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
17964L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> can cause
17965confusion because the
17966perlio or stdio layers usually buffer data. Returns the number of
1510817967bytes actually read, C<0> at end of file, or undef if there was an
15109error (in the latter case C<$!> is also set). SCALAR will be grown or
17968error (in the latter case L<C<$!>|perlvar/$!> is also set). SCALAR will
17969be grown or
1511017970shrunk so that the last byte actually read is the last byte of the
1511117971scalar after the read.
1511217972
1511317973=end original
1511417974
15115read(2) を用いて、指定した FILEHANDLE から、変数 SCALAR へ、LENGTH バイトの
17975L<read(2)> を用いて、指定した FILEHANDLE から、変数 SCALAR へ、LENGTH バイトの
1511617976データの読み込みを試みます。
15117これは、バッファ付き IO ルーチンを通りませんから、
17977これは、バッファ付き IO ルーチンを通りませんから、他の入力関数,
15118他の入力関数, C<print>, C<write>,
17978L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
15119C<seek>, C<tell>, C<eof> と混ぜて使うと、入力がおかしくなるかも
17979L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>,
15120れません。
17980L<C<eof>|/eof FILEHANDLE> と混ぜて使うと、入力がおかくなるかも
15121perlio 層や stdio 層は普通データをバッファリングするからです。
17981しれません; perlio 層や stdio 層は普通データをバッファリングするからです。
15122ファイルの最後では C<0>が、エラー時には undef が、
17982ファイルの最後では C<0>が、エラー時には undef が、それ以外では実際に
15123それ以外では実際に読み込まれたデータの長さが返されます
17983読み込まれたデータの長さが返されます (後者の場合は L<C<$!>|perlvar/$!> も
15124(後者の場合は C<$!> もセットされます)。
17984セットされます)。
1512517985実際に読み込んだ最後のバイトが read した後の最後のバイトになるので、
1512617986SCALAR は伸び縮みします。
1512717987
1512817988=begin original
1512917989
1513017990An OFFSET may be specified to place the read data at some place in the
1513117991string other than the beginning. A negative OFFSET specifies
1513217992placement at that many characters counting backwards from the end of
1513317993the string. A positive OFFSET greater than the length of SCALAR
1513417994results in the string being padded to the required size with C<"\0">
1513517995bytes before the result of the read is appended.
1513617996
1513717997=end original
1513817998
15139OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行なうことが
17999OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行なえます。
15140できます。
1514118000OFFSET に負の値を指定すると、文字列の最後から逆向きに何文字目かで
1514218001位置を指定します。
15143OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は
18002OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は読み込みの結果が
15144読み込みの結果が追加される前に、必要なサイズまで C<"\0"> のバイトで
18003追加される前に、必要なサイズまで C<"\0"> のバイトでパッディングされます。
15145パッディングされます。
1514618004
1514718005=begin original
1514818006
15149There is no syseof() function, which is ok, since eof() doesn't work
18007There is no syseof() function, which is ok, since
15150well on device files (like ttys) anyway. Use sysread() and check
18008L<C<eof>|/eof FILEHANDLE> doesn't work well on device files (like ttys)
15151for a return value for 0 to decide whether you're done.
18009anyway. Use L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> and
18010check for a return value for 0 to decide whether you're done.
1515218011
1515318012=end original
1515418013
15155syseof() 関数はありませんが、問題ありません
18014syseof() 関数はありませんが、問題ありません; どちらにしろ
15156どちらにしろ eof() は(tty のような)デバイスファイルに対して
18015L<C<eof>|/eof FILEHANDLE>
15157うまく動作しないからです。
18016(tty のような)デバイスファイルに対してはうまく動作しないからです。
15158sysread() を使って、 返り値が 0 かどうかで最後まで読んだかを
18017L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を使って、
15159判断してください。
18018返り値が 0 かどうかで最後まで読んだかを判断してください。
1516018019
1516118020=begin original
1516218021
15163Note that if the filehandle has been marked as C<:utf8> Unicode
18022Note that if the filehandle has been marked as C<:utf8>, Unicode
1516418023characters are read instead of bytes (the LENGTH, OFFSET, and the
15165return value of sysread() are in Unicode characters).
18024return value of L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>
15166The C<:encoding(...)> layer implicitly introduces the C<:utf8> layer.
18025are in Unicode characters). The C<:encoding(...)> layer implicitly
15167See L</binmode>, L</open>, and the C<open> pragma, L<open>.
18026introduces the C<:utf8> layer. See
18027L<C<binmode>|/binmode FILEHANDLE, LAYER>,
18028L<C<open>|/open FILEHANDLE,EXPR>, and the L<open> pragma.
1516818029
1516918030=end original
1517018031
1517118032ファイルハンドルが C<:utf8> であるとマークが付けられると、バイトではなく
15172Unicode 文字が読み込まれます (sysread() の LENGTH, OFFSET および返り値は
18033Unicode 文字が読み込まれます
15173Unicode 文字になります)。
18034(L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> の LENGTH, OFFSET
18035および返り値は Unicode 文字になります)。
1517418036C<:encoding(...)> 層は暗黙のうちに C<:utf8> 層が導入されます。
15175L</binmode>, L</open>, C<open> プラグマ, L<open> を参照してください。
18037L<C<binmode>|/binmode FILEHANDLE, LAYER>, L<C<open>|/open FILEHANDLE,EXPR>,
18038L<open> プラグマを参照してください。
1517618039
1517718040=item sysseek FILEHANDLE,POSITION,WHENCE
1517818041X<sysseek> X<lseek>
1517918042
18043=for Pod::Functions +5.004 position I/O pointer on handle used with sysread and syswrite
18044
1518018045=begin original
1518118046
15182Sets FILEHANDLE's system position in bytes using lseek(2). FILEHANDLE may
18047Sets FILEHANDLE's system position in bytes using L<lseek(2)>. FILEHANDLE may
1518318048be an expression whose value gives the name of the filehandle. The values
1518418049for WHENCE are C<0> to set the new position to POSITION; C<1> to set the it
1518518050to the current position plus POSITION; and C<2> to set it to EOF plus
1518618051POSITION, typically negative.
1518718052
1518818053=end original
1518918054
15190FILEHANDLE のシステム位置をバイト単位で lseek(2) を使って設定します。
18055FILEHANDLE のシステム位置をバイト単位で L<lseek(2)> を使って設定します。
15191FILEHANDLE は式でもいません。
18056FILEHANDLE は、実際のファイルハンドル名を与える式でもかまいません。
15192その場合はその値がファイルハンドルの名前となります。
1519318057WHENCE の値が、C<0> ならば、新しい位置を POSITION の位置へ設定します;
1519418058C<1> ならば、現在位置から POSITION 加えた位置へ設定します; C<2> ならば、
1519518059EOF から POSITION だけ(普通は負の数です)加えた位置へ、新しい位置を
1519618060設定します。
1519718061
1519818062=begin original
1519918063
1520018064Note the I<in bytes>: even if the filehandle has been set to operate
1520118065on characters (for example by using the C<:encoding(utf8)> I/O layer),
15202tell() will return byte offsets, not character offsets (because
18066L<C<tell>|/tell FILEHANDLE> will return byte offsets, not character
15203implementing that would render sysseek() unacceptably slow).
18067offsets (because implementing that would render
18068L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> unacceptably slow).
1520418069
1520518070=end original
1520618071
1520718072I<バイト単位> に関する注意: 文字単位で扱うようにファイルハンドルが
1520818073設定されている場合(C<:encoding(utf8)> I/O 層を使っている場合など)でも、
15209tell() は文字のオフセットではなくバイトのオフセットを返します
18074L<C<tell>|/tell FILEHANDLE> は文字のオフセットではなくバイトのオフセットを
15210(なぜならこれを実装すると sysseek() が受け入れられないほど
18075返します (なぜならこれを実装すると
18076L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> が受け入れられないほど
1521118077遅くなるからです)。
1521218078
1521318079=begin original
1521418080
15215sysseek() bypasses normal buffered IO, so mixing it with reads other
18081L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> bypasses normal
15216than C<sysread> (for example C<< <> >> or read()) C<print>, C<write>,
18082buffered IO, so mixing it with reads other than
15217C<seek>, C<tell>, or C<eof> may cause confusion.
18083L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> (for example
18084L<C<readline>|/readline EXPR> or
18085L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>),
18086L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
18087L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
18088L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> may cause
18089confusion.
1521818090
1521918091=end original
1522018092
15221sysseek() は普通のバッファ付き IO をバイパスしますので、
18093L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> は普通のバッファ付き IO を
15222C<sysread> 以外 (例えば C<< <> >> や read() の)読み込み
18094バイパスします
15223C<print>, C<write>, C<seek>, C<tell>, C<eof> と混ぜて使うと
18095L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> 以外の (例えば
15224混乱を引き起こします。
18096L<C<readline>|/readline EXPR> や
18097L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> の)読み込み、
18098L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
18099L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>,
18100L<C<eof>|/eof FILEHANDLE> と混ぜて使うと混乱を引き起こします。
1522518101
1522618102=begin original
1522718103
1522818104For WHENCE, you may also use the constants C<SEEK_SET>, C<SEEK_CUR>,
1522918105and C<SEEK_END> (start of the file, current position, end of the file)
15230from the Fcntl module. Use of the constants is also more portable
18106from the L<Fcntl> module. Use of the constants is also more portable
1523118107than relying on 0, 1, and 2. For example to define a "systell" function:
1523218108
1523318109=end original
1523418110
15235WHENCE には、Fcntl モジュールで使われている C<SEEK_SET>, C<SEEK_CUR>,
18111WHENCE には、L<Fcntl> モジュールで使われている C<SEEK_SET>, C<SEEK_CUR>,
1523618112C<SEEK_END> (ファイルの先頭、現在位置、ファイルの最後)という定数を
1523718113使うこともできます。
1523818114定数の使用は 0, 1, 2 に依存するよりも移植性があります。
1523918115例えば "systell" 関数を定義するには:
1524018116
1524118117 use Fcntl 'SEEK_CUR';
1524218118 sub systell { sysseek($_[0], 0, SEEK_CUR) }
1524318119
1524418120=begin original
1524518121
1524618122Returns the new position, or the undefined value on failure. A position
15247of zero is returned as the string C<"0 but true">; thus C<sysseek> returns
18123of zero is returned as the string C<"0 but true">; thus
18124L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> returns
1524818125true on success and false on failure, yet you can still easily determine
1524918126the new position.
1525018127
1525118128=end original
1525218129
15253新しい位置を返します。
18130新しい位置を返します; 失敗したときは未定義値を返します
15254失敗したとき未定義値を返します
18131位置がゼロの場合、C<"0 but true"> の文字列とて返されます; 従って
15255位置がゼロの場合は、C<"0 but true"> の文字列としてされます。
18132L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> は成功時に真をし、
15256従って C<sysseek> は成功時に真を返し、失敗時に偽を返しますが、
18133失敗時に偽を返しますが、簡単に新しい位置を判定できます。
15257簡単に新しい位置を判定できます。
1525818134
1525918135=item system LIST
1526018136X<system> X<shell>
1526118137
1526218138=item system PROGRAM LIST
1526318139
18140=for Pod::Functions run a separate program
18141
1526418142=begin original
1526518143
15266Does exactly the same thing as C<exec LIST>, except that a fork is
18144Does exactly the same thing as L<C<exec>|/exec LIST>, except that a fork is
1526718145done first and the parent process waits for the child process to
1526818146exit. Note that argument processing varies depending on the
1526918147number of arguments. If there is more than one argument in LIST,
1527018148or if LIST is an array with more than one value, starts the program
1527118149given by the first element of the list with arguments given by the
1527218150rest of the list. If there is only one scalar argument, the argument
1527318151is checked for shell metacharacters, and if there are any, the
1527418152entire argument is passed to the system's command shell for parsing
1527518153(this is C</bin/sh -c> on Unix platforms, but varies on other
1527618154platforms). If there are no shell metacharacters in the argument,
1527718155it is split into words and passed directly to C<execvp>, which is
15278more efficient.
18156more efficient. On Windows, only the C<system PROGRAM LIST> syntax will
18157reliably avoid using the shell; C<system LIST>, even with more than one
18158element, will fall back to the shell if the first spawn fails.
1527918159
1528018160=end original
1528118161
15282C<exec LIST> とほとんど同じですが、まず fork を行ない、
18162L<C<exec>|/exec LIST> とほとんど同じですが、まず fork を行ない、
1528318163親プロセスではチャイルドプロセスが終了するのを wait します。
1528418164exec の項で述べたように、引数の処理は、引数の数によって異なることに
1528518165注意してください。
1528618166LIST に複数の引数がある場合、または LIST が複数の要素からなる配列の場合、
15287リストの最初の要素で与えられるプログラムを、リストの残りの要素を
18167リストの最初の要素で与えられるプログラムを、リストの残りの要素を引数として
15288引数として起動します。
18168起動します。
15289スカラの引数が一つだけの場合、
18169スカラの引数が一つだけの場合、引数はシェルのメタ文字をチェックされ、もし
15290引数シェルのメタ文字をチェックさ、もしあれば
18170あればパースのために引数全体がステムコマンドシェル (こ
15291ズのために引数全体システコマンドシェル
18171Unix プラットフォムでは C</bin/sh -c> です、他のプラットフォーでは
15292(こは Unix プラットフォームでは C</bin/sh -c> でが、
18172異なります)に渡さ
15293プラットフォームでは異ります)されます。
18173シェルメタ文字がかった場合、引数は単語分解されて直接 C<execvp> に
15294シェルメタ文字なかった場合、
18174渡されます; こより効率的です。
15295引数は単語に分解されて直接 C<execvp> に渡されます。
18175Windows では、C<system PROGRAM LIST> 構文のみが安定してシェルの使用を
15296より効率的で
18176回避します; C<system LIST> は、2 要素以上でも、最初 spawn 失敗ると
18177シェルにフォールバックします。
1529718178
1529818179=begin original
1529918180
15300Beginning with v5.6.0, Perl will attempt to flush all files opened for
18181Perl will attempt to flush all files opened for
1530118182output before any operation that may do a fork, but this may not be
1530218183supported on some platforms (see L<perlport>). To be safe, you may need
15303to set C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method
18184to set L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>)
15304of C<IO::Handle> on any open handles.
18185or call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS>
18186on any open handles.
1530518187
1530618188=end original
1530718189
1530818190v5.6.0 から、Perl は書き込み用に開いている全てのファイルに対して
1530918191fork を行う前にフラッシュしようとしますが、これに対応していない
1531018192プラットフォームもあります(L<perlport> を参照してください)。
15311安全のために、C<$|> (English モジュールでは $AUTOFLUSH) をセットするか、
18193安全のために、L<C<$E<verbar>>|perlvar/$E<verbar>> (L<English> モジュールでは
15312全ての開いているハンドルに対して C<IO::Handle> の C<autoflush()> メソッドを
18194C<$AUTOFLUSH>) をセットするか、全ての開いているハンドルに対して
18195L<C<IO::Handle>|IO::Handle/METHODS> の C<autoflush> メソッドを
1531318196呼び出す必要があるかもしれません。
1531418197
1531518198=begin original
1531618199
1531718200The return value is the exit status of the program as returned by the
15318C<wait> call. To get the actual exit value, shift right by eight (see
18201L<C<wait>|/wait> call. To get the actual exit value, shift right by
15319below). See also L</exec>. This is I<not> what you want to use to capture
18202eight (see below). See also L<C<exec>|/exec LIST>. This is I<not> what
15320the output from a command; for that you should use merely backticks or
18203you want to use to capture the output from a command; for that you
15321C<qx//>, as described in L<perlop/"`STRING`">. Return value of -1
18204should use merely backticks or
15322indicates a failure to start the program or an error of the wait(2) system
18205L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>>, as described in
15323call (inspect $! for the reason).
18206L<perlop/"`STRING`">. Return value of -1 indicates a failure to start
18207the program or an error of the L<wait(2)> system call (inspect
18208L<C<$!>|perlvar/$!> for the reason).
1532418209
1532518210=end original
1532618211
15327返り値は、C<wait> が返すプログラムの exit 状態です。
18212返り値は、L<C<wait>|/wait> が返すプログラムの exit 状態です。
1532818213実際の exit 値を得るには 右に 8 ビットシフトしてください(後述)。
15329L</exec> も参照してください。
18214L<C<exec>|/exec LIST> も参照してください。
1533018215これはコマンドからの出力を捕らえるために使うものI<ではありません>;
1533118216そのような用途には、L<perlop/"`STRING`"> に記述されている
15332逆クォートや C<qx//> を使用してください。
18217逆クォートや L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>> を使用してください。
15333-1 の返り値はプログラムを開始させることに失敗したか、wait(2)
18218-1 の返り値はプログラムを開始させることに失敗したか、L<wait(2)>
1533418219システムコールがエラーを出したことを示します
15335(理由は $! を調べてください)。
18220(理由は L<C<$!>|perlvar/$!> を調べてください)。
1533618221
1533718222=begin original
1533818223
15339If you'd like to make C<system> (and many other bits of Perl) die on error,
18224If you'd like to make L<C<system>|/system LIST> (and many other bits of
15340have a look at the L<autodie> pragma.
18225Perl) die on error, have a look at the L<autodie> pragma.
1534118226
1534218227=end original
1534318228
15344もし C<system> (及び Perl のその他の多くの部分) でエラー時に
18229もし L<C<system>|/system LIST> (及び Perl のその他の多くの部分) でエラー時に
1534518230die したいなら、L<autodie> プラグマを見てみてください。
1534618231
1534718232=begin original
1534818233
15349Like C<exec>, C<system> allows you to lie to a program about its name if
18234Like L<C<exec>|/exec LIST>, L<C<system>|/system LIST> allows you to lie
15350you use the C<system PROGRAM LIST> syntax. Again, see L</exec>.
18235to a program about its name if you use the C<system PROGRAM LIST>
18236syntax. Again, see L<C<exec>|/exec LIST>.
1535118237
1535218238=end original
1535318239
15354C<exec> と同様に、C<system> でも C<system PROGRAM LIST> の文法を
18240L<C<exec>|/exec LIST> と同様に、L<C<system>|/system LIST> でも
15355使うことで、プログラムに対してその名前を嘘をつくことができます。
18241C<system PROGRAM LIST> の文法を使うことで、プログラムに対してその名前を
15356再び、L</exec> 参照して下さい
18242つくことができます
18243再び、L<C<exec>|/exec LIST> を参照してください。
1535718244
1535818245=begin original
1535918246
1536018247Since C<SIGINT> and C<SIGQUIT> are ignored during the execution of
15361C<system>, if you expect your program to terminate on receipt of these
18248L<C<system>|/system LIST>, if you expect your program to terminate on
15362signals you will need to arrange to do so yourself based on the return
18249receipt of these signals you will need to arrange to do so yourself
15363value.
18250based on the return value.
1536418251
1536518252=end original
1536618253
15367C<SIGINT> と C<SIGQUIT> は C<system> の実行中は無視されるので、
18254C<SIGINT> と C<SIGQUIT> は L<C<system>|/system LIST> の実行中は無視されるので、
1536818255これらのシグナルを受信して終了させることを想定したプログラムの場合、
1536918256返り値を利用するように変更する必要があります。
1537018257
15371 @args = ("command", "arg1", "arg2");
18258 my @args = ("command", "arg1", "arg2");
1537218259 system(@args) == 0
15373 or die "system @args failed: $?"
18260 or die "system @args failed: $?";
1537418261
1537518262=begin original
1537618263
15377If you'd like to manually inspect C<system>'s failure, you can check all
18264If you'd like to manually inspect L<C<system>|/system LIST>'s failure,
15378possible failure modes by inspecting C<$?> like this:
18265you can check all possible failure modes by inspecting
18266L<C<$?>|perlvar/$?> like this:
1537918267
1538018268=end original
1538118269
15382C<system> の失敗を手動で検査したいなら、
18270L<C<system>|/system LIST> の失敗を手動で検査したいなら、以下のように
15383以下のように C<$?> を調べることで、全ての失敗の可能性を
18271L<C<$?>|perlvar/$?> を調べることで、全ての失敗の可能性をチェックできます:
15384チェックできます:
1538518272
1538618273 if ($? == -1) {
1538718274 print "failed to execute: $!\n";
1538818275 }
1538918276 elsif ($? & 127) {
1539018277 printf "child died with signal %d, %s coredump\n",
1539118278 ($? & 127), ($? & 128) ? 'with' : 'without';
1539218279 }
1539318280 else {
1539418281 printf "child exited with value %d\n", $? >> 8;
1539518282 }
1539618283
1539718284=begin original
1539818285
15399Alternatively, you may inspect the value of C<${^CHILD_ERROR_NATIVE}>
18286Alternatively, you may inspect the value of
15400with the C<W*()> calls from the POSIX module.
18287L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> with the
18288L<C<W*()>|POSIX/C<WIFEXITED>> calls from the L<POSIX> module.
1540118289
1540218290=end original
1540318291
15404または、POSIX モジュールの C<W*()> 呼び出しを使って
18292または、L<POSIX> モジュールの L<C<W*()>|POSIX/C<WIFEXITED>> 呼び出しを使って
15405C<${^CHILD_ERROR_NATIVE}> の値を調べることもできます。
18293L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> の値を
18294調べることもできます。
1540618295
1540718296=begin original
1540818297
15409When C<system>'s arguments are executed indirectly by the shell,
18298When L<C<system>|/system LIST>'s arguments are executed indirectly by
15410results and return codes are subject to its quirks.
18299the shell, results and return codes are subject to its quirks.
15411See L<perlop/"`STRING`"> and L</exec> for details.
18300See L<perlop/"`STRING`"> and L<C<exec>|/exec LIST> for details.
1541218301
1541318302=end original
1541418303
15415C<system> の引数がシェルによって間接的に実行された場合、
18304L<C<system>|/system LIST> の引数がシェルによって間接的に実行された場合、
1541618305結果と返り値はシェルの癖によって変更されることがあります。
15417詳細については L<perlop/"`STRING`"> と L</exec> を参照して下さい。
18306詳細については L<perlop/"`STRING`"> と L<C<exec>|/exec LIST> を
18307参照してください。
1541818308
1541918309=begin original
1542018310
15421Since C<system> does a C<fork> and C<wait> it may affect a C<SIGCHLD>
18311Since L<C<system>|/system LIST> does a L<C<fork>|/fork> and
15422handler. See L<perlipc> for details.
18312L<C<wait>|/wait> it may affect a C<SIGCHLD> handler. See L<perlipc> for
18313details.
1542318314
1542418315=end original
1542518316
15426C<system> は C<fork> と C<wait> を行うので、C<SIGCHLD> ハンドラの影響を
18317L<C<system>|/system LIST> L<C<fork>|/fork>L<C<wait>|/wait> を行うので、
15427受けます。
18318C<SIGCHLD> ハンドラの影響を受けます。
1542818319詳しくは L<perlipc> を参照してください。
1542918320
18321=begin original
18322
18323Portability issues: L<perlport/system>.
18324
18325=end original
18326
18327移植性の問題: L<perlport/system>。
18328
1543018329=item syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET
1543118330X<syswrite>
1543218331
1543318332=item syswrite FILEHANDLE,SCALAR,LENGTH
1543418333
1543518334=item syswrite FILEHANDLE,SCALAR
1543618335
18336=for Pod::Functions fixed-length unbuffered output to a filehandle
18337
1543718338=begin original
1543818339
1543918340Attempts to write LENGTH bytes of data from variable SCALAR to the
15440specified FILEHANDLE, using write(2). If LENGTH is
18341specified FILEHANDLE, using L<write(2)>. If LENGTH is
1544118342not specified, writes whole SCALAR. It bypasses buffered IO, so
15442mixing this with reads (other than C<sysread())>, C<print>, C<write>,
18343mixing this with reads (other than C<sysread)>),
15443C<seek>, C<tell>, or C<eof> may cause confusion because the perlio and
18344L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
15444stdio layers usually buffer data. Returns the number of bytes
18345L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
15445actually written, or C<undef> if there was an error (in this case the
18346L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> may cause
15446errno variable C<$!> is also set). If the LENGTH is greater than the
18347confusion because the perlio and stdio layers usually buffer data.
18348Returns the number of bytes actually written, or L<C<undef>|/undef EXPR>
18349if there was an error (in this case the errno variable
18350L<C<$!>|perlvar/$!> is also set). If the LENGTH is greater than the
1544718351data available in the SCALAR after the OFFSET, only as much data as is
1544818352available will be written.
1544918353
1545018354=end original
1545118355
15452write(2) を使って、指定した FILEHANDLEへ、
18356L<write(2)> を使って、指定した FILEHANDLEへ、変数 SCALAR から、LENGTH バイトの
15453変数 SCALAR から、LENGTH バイトのデータの書き込みを試みます。
18357データの書き込みを試みます。
1545418358LENGTH が指定されなかった場合、 SCALAR 全体を書き込みます。
15455これは、バッファ付き IO ルーチンを通りませんから、
18359これは、バッファ付き IO ルーチンを通りませんから、他の入力関数
15456他の入力関数(C<sysread()> 以外), C<print>, C<write>,
18360(C<sysread> 以外),
15457C<seek>, C<tell>, or C<eof>と混ぜて使うと、
18361L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
15458出力がおかしくなるかもしれません。
18362L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>,
18363L<C<eof>|/eof FILEHANDLE> と混ぜて使うと、出力がおかしくなるかもしれません;
1545918364perlio 層と stdio 層は普通データをバッファリングするからです。
15460実際に読み込まれたデータの長さか、エラー時には C<undef> が返されます
18365実際に読み込まれたデータの長さか、エラー時には L<C<undef>|/undef EXPR>
15461(この場合エラー変数 C<$!> もセットされます)。
18366返されます(この場合エラー変数 L<C<$!>|perlvar/$!> もセットされます)。
1546218367LENGTH が OFFSET 以降の SCALAR の利用可能なデータより大きかった場合、
1546318368利用可能なデータのみが書き込まれます。
1546418369
1546518370=begin original
1546618371
1546718372An OFFSET may be specified to write the data from some part of the
1546818373string other than the beginning. A negative OFFSET specifies writing
1546918374that many characters counting backwards from the end of the string.
1547018375If SCALAR is of length zero, you can only use an OFFSET of 0.
1547118376
1547218377=end original
1547318378
1547418379OFFSET を指定すると、SCALAR の先頭以外の場所から、
1547518380データを取り出して、書き込みを行なうことができます。
1547618381OFFSET に負の値を指定すると、文字列の最後から逆向きに数えて
1547718382何バイト目から書き込むかを示します。
1547818383SCALAR の長さが 0 の場合、OFFSET は 0 のみ使用できます。
1547918384
1548018385=begin original
1548118386
1548218387B<WARNING>: If the filehandle is marked C<:utf8>, Unicode characters
1548318388encoded in UTF-8 are written instead of bytes, and the LENGTH, OFFSET, and
15484return value of syswrite() are in (UTF8-encoded Unicode) characters.
18389return value of L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>
18390are in (UTF8-encoded Unicode) characters.
1548518391The C<:encoding(...)> layer implicitly introduces the C<:utf8> layer.
1548618392Alternately, if the handle is not marked with an encoding but you
1548718393attempt to write characters with code points over 255, raises an exception.
15488See L</binmode>, L</open>, and the C<open> pragma, L<open>.
18394See L<C<binmode>|/binmode FILEHANDLE, LAYER>,
18395L<C<open>|/open FILEHANDLE,EXPR>, and the L<open> pragma.
1548918396
1549018397=end original
1549118398
1549218399B<警告>: ファイルハンドルが C<:utf8> であるとマークが付けられると、
1549318400バイトではなく UTF-8 エンコードされた Unicode 文字が読み込まれ、
15494syswrite() LENGTH, OFFSET および返り値は (UTF8 エンコードされた
18401L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> LENGTH, OFFSET
15495Unicode) 文字単位になります。
18402および返り値は (UTF8 エンコードされた Unicode) 文字単位になります。
1549618403C<:encoding(...)> 層は暗黙のうちに C<:utf8> 層が導入されます。
1549718404または、もしハンドルにエンコーディングが記録されていない状態で
1549818405255 を超える符号位置の文字を書き込もうとすると、例外が発生します。
15499L</binmode>, L</open>, C<open> プラグマ, L<open> を参照してください。
18406L<C<binmode>|/binmode FILEHANDLE, LAYER>, L<C<open>|/open FILEHANDLE,EXPR>,
18407L<open> プラグマを参照してください。
1550018408
1550118409=item tell FILEHANDLE
1550218410X<tell>
1550318411
1550418412=item tell
1550518413
18414=for Pod::Functions get current seekpointer on a filehandle
18415
1550618416=begin original
1550718417
1550818418Returns the current position I<in bytes> for FILEHANDLE, or -1 on
1550918419error. FILEHANDLE may be an expression whose value gives the name of
1551018420the actual filehandle. If FILEHANDLE is omitted, assumes the file
1551118421last read.
1551218422
1551318423=end original
1551418424
15515FILEHANDLE の現在の位置を I<バイト数で> 返します
18425FILEHANDLE の現在の位置を I<バイト数で> 返します; エラーの場合は -1 を
15516エラーの場合は -1 を返します。
18426返します。
1551718427FILEHANDLE は、実際のファイルハンドル名を示す式でもかまいません。
15518FILEHANDLE が省略された場合には、
18428FILEHANDLE が省略された場合には、最後に読み込みを行なったファイルについて
15519最後に読み込みを行なったファイルについて調べます。
18429調べます。
1552018430
1552118431=begin original
1552218432
1552318433Note the I<in bytes>: even if the filehandle has been set to
1552418434operate on characters (for example by using the C<:encoding(utf8)> open
15525layer), tell() will return byte offsets, not character offsets (because
18435layer), L<C<tell>|/tell FILEHANDLE> will return byte offsets, not
15526that would render seek() and tell() rather slow).
18436character offsets (because that would render
18437L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> and
18438L<C<tell>|/tell FILEHANDLE> rather slow).
1552718439
1552818440=end original
1552918441
1553018442I<バイト単位> に関する注意: ファイルハンドルが (例えば
1553118443C<:encoding(utf8)> 層を使って)
15532文字を操作するように設定されていたとしても、tell()文字の
18444文字を操作するように設定されていたとしても、L<C<tell>|/tell FILEHANDLE>
15533オフセットではなくバイトのオフセットを返すことに注意してください
18445文字のオフセットではなくバイトのオフセットを返すことに注意してください
15534(なぜならこれは seek() と tell() が遅くなってしまうからです)。
18446(なぜならこれは L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> と
18447L<C<tell>|/tell FILEHANDLE> が遅くなってしまうからです)。
1553518448
1553618449=begin original
1553718450
15538The return value of tell() for the standard streams like the STDIN
18451The return value of L<C<tell>|/tell FILEHANDLE> for the standard streams
15539depends on the operating system: it may return -1 or something else.
18452like the STDIN depends on the operating system: it may return -1 or
15540tell() on pipes, fifos, and sockets usually returns -1.
18453something else. L<C<tell>|/tell FILEHANDLE> on pipes, fifos, and
18454sockets usually returns -1.
1554118455
1554218456=end original
1554318457
15544STDIN のような標準ストリームに対する tell() の返り値は OS に依存します。
18458STDIN のような標準ストリームに対する L<C<tell>|/tell FILEHANDLE> の返り値は
18459OS に依存します:
1554518460-1 やその他の値が返ってくるかもしれません。
15546パイプ、FIFO、ソケットに対して tell() を使うと、普通は -1 が返ります。
18461パイプ、FIFO、ソケットに対して L<C<tell>|/tell FILEHANDLE> を使うと、普通は
18462-1 が返ります。
1554718463
1554818464=begin original
1554918465
15550There is no C<systell> function. Use C<sysseek(FH, 0, 1)> for that.
18466There is no C<systell> function. Use C<sysseek($fh, 0, 1)> for that.
1555118467
1555218468=end original
1555318469
1555418470C<systell> 関数はありません。
15555代わりに C<sysseek(FH, 0, 1)> を使ってください。
18471代わりに C<sysseek($fh, 0, 1)> を使ってください。
1555618472
1555718473=begin original
1555818474
15559Do not use tell() (or other buffered I/O operations) on a filehandle
18475Do not use L<C<tell>|/tell FILEHANDLE> (or other buffered I/O
15560that has been manipulated by sysread(), syswrite(), or sysseek().
18476operations) on a filehandle that has been manipulated by
15561Those functions ignore the buffering, while tell() does not.
18477L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
18478L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, or
18479L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>. Those functions
18480ignore the buffering, while L<C<tell>|/tell FILEHANDLE> does not.
1556218481
1556318482=end original
1556418483
15565sysread(), syswrite(), sysseek() で操作されたファイルハンドルに tell()
18484L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
18485L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
18486L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> で操作された
18487ファイルハンドルに L<C<tell>|/tell FILEHANDLE>
1556618488(またはその他のバッファリング I/O 操作) を使わないでください。
15567これらの関数はバッファリングを無視しますが、tell()違います。
18489これらの関数はバッファリングを無視しますが、L<C<tell>|/tell FILEHANDLE>
18490違います。
1556818491
1556918492=item telldir DIRHANDLE
1557018493X<telldir>
1557118494
18495=for Pod::Functions get current seekpointer on a directory handle
18496
1557218497=begin original
1557318498
15574Returns the current position of the C<readdir> routines on DIRHANDLE.
18499Returns the current position of the L<C<readdir>|/readdir DIRHANDLE>
15575Value may be given to C<seekdir> to access a particular location in a
18500routines on DIRHANDLE. Value may be given to
15576directory. C<telldir> has the same caveats about possible directory
18501L<C<seekdir>|/seekdir DIRHANDLE,POS> to access a particular location in
15577compaction as the corresponding system library routine.
18502a directory. L<C<telldir>|/telldir DIRHANDLE> has the same caveats
18503about possible directory compaction as the corresponding system library
18504routine.
1557818505
1557918506=end original
1558018507
15581DIRHANDLE 上の C<readdir> ルーチンに対する現在位置を返します。
18508DIRHANDLE 上の L<C<readdir>|/readdir DIRHANDLE> ルーチンに対する現在位置を
18509返します。
1558218510値は、そのディレクトリで特定の位置をアクセスするため、
15583C<seekdir> に渡すことができます。
18511L<C<seekdir>|/seekdir DIRHANDLE,POS> に渡すことができます。
15584C<telldir> は同名のシステムライブラリルーチンと同じく、
18512L<C<telldir>|/telldir DIRHANDLE> は同名のシステムライブラリルーチンと同じく、
1558518513ディレクトリ縮小時の問題が考えられます。
1558618514
1558718515=item tie VARIABLE,CLASSNAME,LIST
1558818516X<tie>
1558918517
18518=for Pod::Functions +5.002 bind a variable to an object class
18519
1559018520=begin original
1559118521
1559218522This function binds a variable to a package class that will provide the
1559318523implementation for the variable. VARIABLE is the name of the variable
1559418524to be enchanted. CLASSNAME is the name of a class implementing objects
15595of correct type. Any additional arguments are passed to the C<new>
18525of correct type. Any additional arguments are passed to the
18526appropriate constructor
1559618527method of the class (meaning C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>,
1559718528or C<TIEHASH>). Typically these are arguments such as might be passed
15598to the C<dbm_open()> function of C. The object returned by the C<new>
18529to the L<dbm_open(3)> function of C. The object returned by the
15599method is also returned by the C<tie> function, which would be useful
18530constructor is also returned by the
18531L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function, which would be useful
1560018532if you want to access other methods in CLASSNAME.
1560118533
1560218534=end original
1560318535
1560418536この関数は、変数を、その変数の実装を行なうクラスと結び付けます。
1560518537VARIABLE は、魔法をかける変数の名前です。
1560618538CLASSNAME は、正しい型のオブジェクトを実装するクラスの名前です。
15607他に引数があれば、そのクラスの C<new> メソッドに渡されます
18539他に引数があれば、そのクラスの適切なコンストラクタメソッドに渡されます
1560818540(つまり C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>, C<TIEHASH>)。
15609通常、これらは、C の C<dbm_open> などの関数に渡す引数となります。
18541通常、これらは、C の L<dbm_open(3)> などの関数に渡す引数となります。
15610C<new> メソッドで返されるオブジェクトはまた C<tie> 関数でも返されます。
18542コンストラクタで返されるオブジェクトはまた
18543L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数でも返されます;
1561118544これは CLASSNAME の他のメソッドにアクセスしたいときに便利です。
1561218545
1561318546=begin original
1561418547
15615Note that functions such as C<keys> and C<values> may return huge lists
18548Note that functions such as L<C<keys>|/keys HASH> and
15616when used on large objects, like DBM files. You may prefer to use the
18549L<C<values>|/values HASH> may return huge lists when used on large
15617C<each> function to iterate over such. Example:
18550objects, like DBM files. You may prefer to use the L<C<each>|/each
18551HASH> function to iterate over such. Example:
1561818552
1561918553=end original
1562018554
15621DBM ファイルのような大きなオブジェクトでは、C<keys> や C<values> のような
18555DBM ファイルのような大きなオブジェクトでは、L<C<keys>|/keys HASH>
15622関数は、大きなリストを返す可能性があります。
18556L<C<values>|/values HASH> のような関数は、大きなリストを返す可能性があります。
15623そのような場合では、C<each> 関数を使って繰り返しを行なった方が
18557そのような場合では、L<C<each>|/each HASH> 関数を使って繰り返しを行なった方が
1562418558よいかもしれません。
1562518559例:
1562618560
1562718561 # print out history file offsets
1562818562 use NDBM_File;
15629 tie(%HIST, 'NDBM_File', '/usr/lib/news/history', 1, 0);
18563 tie(my %HIST, 'NDBM_File', '/usr/lib/news/history', 1, 0);
15630 while (($key,$val) = each %HIST) {
18564 while (my ($key,$val) = each %HIST) {
15631 print $key, ' = ', unpack('L',$val), "\n";
18565 print $key, ' = ', unpack('L', $val), "\n";
1563218566 }
15633 untie(%HIST);
1563418567
1563518568=begin original
1563618569
1563718570A class implementing a hash should have the following methods:
1563818571
1563918572=end original
1564018573
1564118574ハッシュを実装するクラスでは、次のようなメソッドを用意します:
1564218575
1564318576 TIEHASH classname, LIST
1564418577 FETCH this, key
1564518578 STORE this, key, value
1564618579 DELETE this, key
1564718580 CLEAR this
1564818581 EXISTS this, key
1564918582 FIRSTKEY this
1565018583 NEXTKEY this, lastkey
1565118584 SCALAR this
1565218585 DESTROY this
1565318586 UNTIE this
1565418587
1565518588=begin original
1565618589
1565718590A class implementing an ordinary array should have the following methods:
1565818591
1565918592=end original
1566018593
1566118594通常の配列を実装するクラスでは、次のようなメソッドを用意します:
1566218595
1566318596 TIEARRAY classname, LIST
1566418597 FETCH this, key
1566518598 STORE this, key, value
1566618599 FETCHSIZE this
1566718600 STORESIZE this, count
1566818601 CLEAR this
1566918602 PUSH this, LIST
1567018603 POP this
1567118604 SHIFT this
1567218605 UNSHIFT this, LIST
1567318606 SPLICE this, offset, length, LIST
1567418607 EXTEND this, count
18608 DELETE this, key
18609 EXISTS this, key
1567518610 DESTROY this
1567618611 UNTIE this
1567718612
1567818613=begin original
1567918614
1568018615A class implementing a filehandle should have the following methods:
1568118616
1568218617=end original
1568318618
1568418619ファイルハンドルを実装するクラスでは、次のようなメソッドを用意します:
1568518620
1568618621 TIEHANDLE classname, LIST
1568718622 READ this, scalar, length, offset
1568818623 READLINE this
1568918624 GETC this
1569018625 WRITE this, scalar, length, offset
1569118626 PRINT this, LIST
1569218627 PRINTF this, format, LIST
1569318628 BINMODE this
1569418629 EOF this
1569518630 FILENO this
1569618631 SEEK this, position, whence
1569718632 TELL this
1569818633 OPEN this, mode, LIST
1569918634 CLOSE this
1570018635 DESTROY this
1570118636 UNTIE this
1570218637
1570318638=begin original
1570418639
1570518640A class implementing a scalar should have the following methods:
1570618641
1570718642=end original
1570818643
1570918644スカラ変数を実装するクラスでは、次のようなメソッドを用意します:
1571018645
1571118646 TIESCALAR classname, LIST
1571218647 FETCH this,
1571318648 STORE this, value
1571418649 DESTROY this
1571518650 UNTIE this
1571618651
1571718652=begin original
1571818653
1571918654Not all methods indicated above need be implemented. See L<perltie>,
1572018655L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>, and L<Tie::Handle>.
1572118656
1572218657=end original
1572318658
1572418659上記の全てのメソッドを実装する必要はありません。
1572518660L<perltie>, L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>,
15726L<Tie::Handle> を参照してさい。
18661L<Tie::Handle> を参照してください。
1572718662
1572818663=begin original
1572918664
15730Unlike C<dbmopen>, the C<tie> function will not C<use> or C<require> a module
18665Unlike L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, the
15731for you; you need to do that explicitly yourself. See L<DB_File>
18666L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function will not
15732or the F<Config> module for interesting C<tie> implementations.
18667L<C<use>|/use Module VERSION LIST> or L<C<require>|/require VERSION> a
18668module for you; you need to do that explicitly yourself. See L<DB_File>
18669or the L<Config> module for interesting
18670L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> implementations.
1573318671
1573418672=end original
1573518673
15736C<dbmopen> と違い、C<tie> 関数はモジュールを C<use> したり
18674L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> と違い、
15737C<require> したりしません; 自分で明示的に行う必要があります。
18675L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数はモジュールを
15738C<tie> の興味深い実装については L<DB_File> F<Config> モジュールを
18676L<C<use>|/use Module VERSION LIST> したり
15739参照て下さい。
18677L<C<require>|/require VERSION> たりしません;
18678自分で明示的に行う必要があります。
18679L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> の興味深い実装については
18680L<DB_File> や L<Config> モジュールを参照してください。
1574018681
1574118682=begin original
1574218683
15743For further details see L<perltie>, L<"tied VARIABLE">.
18684For further details see L<perltie>, L<C<tied>|/tied VARIABLE>.
1574418685
1574518686=end original
1574618687
15747更なる詳細については L<perltie> や L<"tied VARIABLE"> を参照して下さい。
18688更なる詳細については L<perltie> や L<C<tied>|/tied VARIABLE> を
18689参照してください。
1574818690
1574918691=item tied VARIABLE
1575018692X<tied>
1575118693
18694=for Pod::Functions get a reference to the object underlying a tied variable
18695
1575218696=begin original
1575318697
1575418698Returns a reference to the object underlying VARIABLE (the same value
15755that was originally returned by the C<tie> call that bound the variable
18699that was originally returned by the
18700L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> call that bound the variable
1575618701to a package.) Returns the undefined value if VARIABLE isn't tied to a
1575718702package.
1575818703
1575918704=end original
1576018705
1576118706VARIABLE の基となるオブジェクトへのリファレンスを返します
15762(変数をパッケージに結びつけるために C<tie> 呼び出しをしたときの
18707(変数をパッケージに結びつけるために
18708L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 呼び出しをしたときの
1576318709返り値と同じものです)。
1576418710VARIABLE がパッケージと結び付けられていない場合は未定義値を返します。
1576518711
1576618712=item time
1576718713X<time> X<epoch>
1576818714
18715=for Pod::Functions return number of seconds since 1970
18716
1576918717=begin original
1577018718
1577118719Returns the number of non-leap seconds since whatever time the system
15772considers to be the epoch, suitable for feeding to C<gmtime> and
18720considers to be the epoch, suitable for feeding to
15773C<localtime>. On most systems the epoch is 00:00:00 UTC, January 1, 1970;
18721L<C<gmtime>|/gmtime EXPR> and L<C<localtime>|/localtime EXPR>. On most
18722systems the epoch is 00:00:00 UTC, January 1, 1970;
1577418723a prominent exception being Mac OS Classic which uses 00:00:00, January 1,
15775187241904 in the current local time zone for its epoch.
1577618725
1577718726=end original
1577818727
15779C<gmtime> や C<localtime> への入力形式に合っている、
18728L<C<gmtime>|/gmtime EXPR> L<C<localtime>|/localtime EXPR> への入力形式に
15780システムが紀元と考える時点からの連続秒数を返します。
18729合っている、システムが紀元と考える時点からの連続秒数を返します。
1578118730ほとんどのシステムでは紀元は UTC 1970 年 1 月 1 日 00:00:00 です;
1578218731特徴的な例外としては、古い Mac OS ではローカルタイムゾーンの
15783187321904 年 1 月 1 日 00:00:00 を紀元として使います。
1578418733
1578518734=begin original
1578618735
1578718736For measuring time in better granularity than one second, use the
1578818737L<Time::HiRes> module from Perl 5.8 onwards (or from CPAN before then), or,
15789if you have gettimeofday(2), you may be able to use the C<syscall>
18738if you have L<gettimeofday(2)>, you may be able to use the
15790interface of Perl. See L<perlfaq8> for details.
18739L<C<syscall>|/syscall NUMBER, LIST> interface of Perl. See L<perlfaq8>
18740for details.
1579118741
1579218742=end original
1579318743
15794187441 秒よりも細かい時間を計測するためには、Perl 5.8 以降(それ以前では
1579518745CPANから)の L<Time::HiRes> モジュールを使うか、
15796gettimeofday(2) があるなら、Perl の C<syscall> インターフェースを
18746L<gettimeofday(2)> があるなら、Perl の
15797使ってください。
18747L<C<syscall>|/syscall NUMBER, LIST> インターフェースを使ってください。
15798詳しくは L<perlfaq8> を参照してさい。
18748詳しくは L<perlfaq8> を参照してください。
1579918749
1580018750=begin original
1580118751
1580218752For date and time processing look at the many related modules on CPAN.
1580318753For a comprehensive date and time representation look at the
1580418754L<DateTime> module.
1580518755
1580618756=end original
1580718757
1580818758日付と時刻の処理は、多くの関連するモジュールが CPAN にあります。
1580918759包括的な日付と時刻の表現については、CPAN の L<DateTime> モジュールを
1581018760参照してください。
1581118761
1581218762=item times
1581318763X<times>
1581418764
18765=for Pod::Functions return elapsed time for self and child processes
18766
1581518767=begin original
1581618768
1581718769Returns a four-element list giving the user and system times in
1581818770seconds for this process and any exited children of this process.
1581918771
1582018772=end original
1582118773
1582218774現プロセス及び終了したその子プロセスに対する、ユーザ時間とシステム時間を
1582318775秒で示した、4 要素のリスト値を返します。
1582418776
15825 ($user,$system,$cuser,$csystem) = times;
18777 my ($user,$system,$cuser,$csystem) = times;
1582618778
1582718779=begin original
1582818780
15829In scalar context, C<times> returns C<$user>.
18781In scalar context, L<C<times>|/times> returns C<$user>.
1583018782
1583118783=end original
1583218784
15833スカラコンテキストでは、C<times> は C<$user> を返します。
18785スカラコンテキストでは、L<C<times>|/times> は C<$user> を返します。
1583418786
1583518787=begin original
1583618788
1583718789Children's times are only included for terminated children.
1583818790
1583918791=end original
1584018792
1584118793子プロセスに対する times は、終了した子プロセスのみ含められます。
1584218794
18795=begin original
18796
18797Portability issues: L<perlport/times>.
18798
18799=end original
18800
18801移植性の問題: L<perlport/times>。
18802
1584318803=item tr///
1584418804
18805=for Pod::Functions transliterate a string
18806
1584518807=begin original
1584618808
15847The transliteration operator. Same as C<y///>. See
18809The transliteration operator. Same as
15848L<perlop/"Quote and Quote-like Operators">.
18810L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>>. See
18811L<perlop/"Quote-Like Operators">.
1584918812
1585018813=end original
1585118814
15852変換演算子。
18815文字変換演算子です
15853C<y///> と同じです。
18816L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>> と同じです。
15854L<perlop/"Quote and Quote-like Operators"> を参照してください。
18817L<perlop/"Quote-Like Operators"> を参照してください。
1585518818
1585618819=item truncate FILEHANDLE,LENGTH
1585718820X<truncate>
1585818821
1585918822=item truncate EXPR,LENGTH
1586018823
18824=for Pod::Functions shorten a file
18825
1586118826=begin original
1586218827
1586318828Truncates the file opened on FILEHANDLE, or named by EXPR, to the
1586418829specified length. Raises an exception if truncate isn't implemented
15865on your system. Returns true if successful, C<undef> on error.
18830on your system. Returns true if successful, L<C<undef>|/undef EXPR> on
18831error.
1586618832
1586718833=end original
1586818834
1586918835FILEHANDLE 上にオープンされたファイルか、EXPR で名前を表わしたファイルを、
1587018836指定した長さに切り詰めます。
1587118837システム上に truncate が実装されていなければ、例外が発生します。
15872成功すれば真を、エラー時には C<undef> を返します。
18838成功すれば真を、エラー時には L<C<undef>|/undef EXPR> を返します。
1587318839
1587418840=begin original
1587518841
1587618842The behavior is undefined if LENGTH is greater than the length of the
1587718843file.
1587818844
1587918845=end original
1588018846
1588118847LENGTH がファイルの長さより大きい場合の振る舞いは未定義です。
1588218848
1588318849=begin original
1588418850
1588518851The position in the file of FILEHANDLE is left unchanged. You may want to
15886call L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> before writing to the file.
18852call L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> before writing to the
18853file.
1588718854
1588818855=end original
1588918856
1589018857FILEHANDLE のファイルの位置は変わりません。
1589118858ファイルに書き込む前に L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> を
1589218859呼び出したいかもしれません。
1589318860
18861=begin original
18862
18863Portability issues: L<perlport/truncate>.
18864
18865=end original
18866
18867移植性の問題: L<perlport/truncate>。
18868
1589418869=item uc EXPR
1589518870X<uc> X<uppercase> X<toupper>
1589618871
1589718872=item uc
1589818873
18874=for Pod::Functions return upper-case version of a string
18875
1589918876=begin original
1590018877
1590118878Returns an uppercased version of EXPR. This is the internal function
1590218879implementing the C<\U> escape in double-quoted strings.
1590318880It does not attempt to do titlecase mapping on initial letters. See
15904L</ucfirst> for that.
18881L<C<ucfirst>|/ucfirst EXPR> for that.
1590518882
1590618883=end original
1590718884
1590818885EXPR を大文字に変換したものを返します。
1590918886これは、ダブルクォート文字列における、C<\U> エスケープを
1591018887実装する内部関数です。
1591118888先頭文字の タイトル文字マッピングは試みません。
15912このためには L</ucfirst> を参照してください。
18889このためには L<C<ucfirst>|/ucfirst EXPR> を参照してください。
1591318890
1591418891=begin original
1591518892
15916If EXPR is omitted, uses C<$_>.
18893If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
1591718894
1591818895=end original
1591918896
15920EXPR が省略されると、C<$_> を使います。
18897EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
1592118898
1592218899=begin original
1592318900
15924This function behaves the same way under various pragma, such as in a locale,
18901This function behaves the same way under various pragmas, such as in a locale,
15925as L</lc> does.
18902as L<C<lc>|/lc EXPR> does.
1592618903
1592718904=end original
1592818905
1592918906この関数は、ロケールのようなさまざまなプラグマの影響下では、
15930L</lc> と同様に振る舞います。
18907L<C<lc>|/lc EXPR> と同様に振る舞います。
1593118908
1593218909=item ucfirst EXPR
1593318910X<ucfirst> X<uppercase>
1593418911
1593518912=item ucfirst
1593618913
18914=for Pod::Functions return a string with just the next letter in upper case
18915
1593718916=begin original
1593818917
1593918918Returns the value of EXPR with the first character in uppercase
1594018919(titlecase in Unicode). This is the internal function implementing
1594118920the C<\u> escape in double-quoted strings.
1594218921
1594318922=end original
1594418923
1594518924最初の文字だけを大文字にした、EXPR を返します
1594618925(Unicode では titlecase)。
1594718926これは、ダブルクォート文字列における、C<\u> エスケープを
1594818927実装する内部関数です。
1594918928
1595018929=begin original
1595118930
15952If EXPR is omitted, uses C<$_>.
18931If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
1595318932
1595418933=end original
1595518934
15956EXPR が省略されると、C<$_> を使います。
18935EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
1595718936
1595818937=begin original
1595918938
15960This function behaves the same way under various pragma, such as in a locale,
18939This function behaves the same way under various pragmas, such as in a locale,
15961as L</lc> does.
18940as L<C<lc>|/lc EXPR> does.
1596218941
1596318942=end original
1596418943
1596518944この関数は、ロケールのようなさまざまなプラグマの影響下では、
15966L</lc> と同様に振る舞います。
18945L<C<lc>|/lc EXPR> と同様に振る舞います。
1596718946
1596818947=item umask EXPR
1596918948X<umask>
1597018949
1597118950=item umask
1597218951
18952=for Pod::Functions set file creation mode mask
18953
1597318954=begin original
1597418955
1597518956Sets the umask for the process to EXPR and returns the previous value.
1597618957If EXPR is omitted, merely returns the current umask.
1597718958
1597818959=end original
1597918960
1598018961現在のプロセスの umask を EXPR に設定し、以前の値を返します。
1598118962EXPR が省略されると、単にその時点の umask の値を返します。
1598218963
1598318964=begin original
1598418965
1598518966The Unix permission C<rwxr-x---> is represented as three sets of three
1598618967bits, or three octal digits: C<0750> (the leading 0 indicates octal
15987and isn't one of the digits). The C<umask> value is such a number
18968and isn't one of the digits). The L<C<umask>|/umask EXPR> value is such
15988representing disabled permissions bits. The permission (or "mode")
18969a number representing disabled permissions bits. The permission (or
15989values you pass C<mkdir> or C<sysopen> are modified by your umask, so
18970"mode") values you pass L<C<mkdir>|/mkdir FILENAME,MASK> or
15990even if you tell C<sysopen> to create a file with permissions C<0777>,
18971L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> are modified by your
15991if your umask is C<0022>, then the file will actually be created with
18972umask, so even if you tell
15992permissions C<0755>. If your C<umask> were C<0027> (group can't
18973L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> to create a file with
15993write; others can't read, write, or execute), then passing
18974permissions C<0777>, if your umask is C<0022>, then the file will
15994C<sysopen> C<0666> would create a file with mode C<0640> (because
18975actually be created with permissions C<0755>. If your
15995C<0666 &~ 027> is C<0640>).
18976L<C<umask>|/umask EXPR> were C<0027> (group can't write; others can't
18977read, write, or execute), then passing
18978L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> C<0666> would create a
18979file with mode C<0640> (because C<0666 &~ 027> is C<0640>).
1599618980
1599718981=end original
1599818982
1599918983Unix パーミッション C<rwxr-x---> は 3 ビットの三つの組、
1600018984または 3 桁の 8 進数として表現されます:
1600118985C<0750> (先頭の 0 は 8 進数を意味し、実際の値ではありません)。
16002C<umask> の値は無効にするパーミッションビットのこのような数値表現です。
18986L<C<umask>|/umask EXPR> の値は無効にするパーミッションビットのこのような
16003C<mkdir> や C<sysopen> で渡されたパーミッション(または「モード」)の
18987表現です。
16004umask で修正され、たとえ C<sysopen> で C<0777> のパーミッションで
18988L<C<mkdir>|/mkdir FILENAME,MASK>
18989L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> で渡されたパーミッション
18990(または「モード」)の値は umask で修正され、たとえ
18991L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> で C<0777> のパーミッションで
1600518992ファイルを作るように指定しても、umask が C<0022> なら、
1600618993結果としてファイルは C<0755> のパーミッションで作成されます。
16007C<umask> が C<0027> (グループは書き込めない; その他は読み込み、書き込み、
18994L<C<umask>|/umask EXPR> が C<0027> (グループは書き込めない; その他は読み込み、
16008実行できない) のとき、C<sysopen> に C<0666> を渡すと、
18995書き込み、実行できない) のとき
18996L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> に C<0666> を渡すと、
1600918997ファイルはモード C<0640> (なぜなら C<0666 &~ 027> は C<0640>)で作成されます。
1601018998
1601118999=begin original
1601219000
1601319001Here's some advice: supply a creation mode of C<0666> for regular
16014files (in C<sysopen>) and one of C<0777> for directories (in
19002files (in L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>) and one of
16015C<mkdir>) and executable files. This gives users the freedom of
19003C<0777> for directories (in L<C<mkdir>|/mkdir FILENAME,MASK>) and
19004executable files. This gives users the freedom of
1601619005choice: if they want protected files, they might choose process umasks
1601719006of C<022>, C<027>, or even the particularly antisocial mask of C<077>.
1601819007Programs should rarely if ever make policy decisions better left to
1601919008the user. The exception to this is when writing files that should be
16020kept private: mail files, web browser cookies, I<.rhosts> files, and
19009kept private: mail files, web browser cookies, F<.rhosts> files, and
1602119010so on.
1602219011
1602319012=end original
1602419013
16025以下は助言です: 作成モードとして、(C<sysopen> による)通常ファイルでは
19014以下は助言です: 作成モードとして、
16026C<0666> を、(C<mkdir> による)ディレクトリでは C<0777> を指定しましょう。
19015(L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> による)通常ファイルでは
19016C<0666> を、(L<C<mkdir>|/mkdir FILENAME,MASK> による)ディレクトリでは
19017C<0777> を指定しましょう。
1602719018これにより、ユーザーに選択の自由を与えます: もしファイルを守りたいなら、
1602819019プロセスの umask として C<022>, C<027>, あるいは特に非社交的な
1602919020C<077> を選択できます。
1603019021プログラムがユーザーより適切なポリシー選択ができることは稀です。
1603119022例外は、プライベートに保つべきファイル(メール、ウェブブラウザのクッキー、
16032I<.rhosts> ファイルなど)を書く場合です。
19023F<.rhosts> ファイルなど)を書く場合です。
1603319024
1603419025=begin original
1603519026
16036If umask(2) is not implemented on your system and you are trying to
19027If L<umask(2)> is not implemented on your system and you are trying to
16037restrict access for I<yourself> (i.e., C<< (EXPR & 0700) > 0 >>),
19028restrict access for I<yourself> (i.e., C<< (EXPR & 0700) > 0 >>),
16038raises an exception. If umask(2) is not implemented and you are
19029raises an exception. If L<umask(2)> is not implemented and you are
16039not trying to restrict access for yourself, returns C<undef>.
19030not trying to restrict access for yourself, returns
19031L<C<undef>|/undef EXPR>.
1604019032
1604119033=end original
1604219034
16043umask(2) が実装されていないシステムで、I<自分自身> へのアクセスを
19035L<umask(2)> が実装されていないシステムで、I<自分自身> へのアクセスを
1604419036制限しようとした(つまり C<< (EXPR & 0700) > 0 >>)場合、例外が発生します。
16045umask(2) が実装されていないシステムで、自分自身へのアクセスは
19037L<umask(2)> が実装されていないシステムで、自分自身へのアクセスは
16046制限しようとしなかった場合、C<undef> を返します。
19038制限しようとしなかった場合、L<C<undef>|/undef EXPR> を返します。
1604719039
1604819040=begin original
1604919041
1605019042Remember that a umask is a number, usually given in octal; it is I<not> a
16051string of octal digits. See also L</oct>, if all you have is a string.
19043string of octal digits. See also L<C<oct>|/oct EXPR>, if all you have
19044is a string.
1605219045
1605319046=end original
1605419047
16055umask は通常 8 進数で与えられる数値であることを忘れないでください
19048umask は通常 8 進数で与えられる数値であることを忘れないでください; 8 進数の
160568 進数の文字列 I<ではありません>。
19049文字列 I<ではありません>。
16057文字列しかない場合、 L</oct> も参照してさい。
19050文字列しかない場合、 L<C<oct>|/oct EXPR> も参照してください。
1605819051
19052=begin original
19053
19054Portability issues: L<perlport/umask>.
19055
19056=end original
19057
19058移植性の問題: L<perlport/umask>。
19059
1605919060=item undef EXPR
1606019061X<undef> X<undefine>
1606119062
1606219063=item undef
1606319064
19065=for Pod::Functions remove a variable or function definition
19066
1606419067=begin original
1606519068
1606619069Undefines the value of EXPR, which must be an lvalue. Use only on a
1606719070scalar value, an array (using C<@>), a hash (using C<%>), a subroutine
1606819071(using C<&>), or a typeglob (using C<*>). Saying C<undef $hash{$key}>
1606919072will probably not do what you expect on most predefined variables or
16070DBM list values, so don't do that; see L<delete>. Always returns the
19073DBM list values, so don't do that; see L<C<delete>|/delete EXPR>.
16071undefined value. You can omit the EXPR, in which case nothing is
19074Always returns the undefined value.
19075You can omit the EXPR, in which case nothing is
1607219076undefined, but you still get an undefined value that you could, for
1607319077instance, return from a subroutine, assign to a variable, or pass as a
1607419078parameter. Examples:
1607519079
1607619080=end original
1607719081
1607819082左辺値である EXPR の値を未定義にします。
16079スカラ値、(C<@> を使った)配列、(C<%> を使った)ハッシュ、(C<&> を使った)
19083スカラ値、(C<@> を使った)配列、(C<%> を使った)ハッシュ、(C<&> を使った)
1608019084サブルーチン、(C<*> を使った)型グロブだけに使用します。
1608119085特殊変数や DBM リスト値に C<undef $hash{$key}> などとしても
1608219086おそらく期待通りの結果にはなりませんから、しないでください;
16083L</delete> を参照してください。
19087L<C<delete>|/delete EXPR> を参照してください。
1608419088常に未定義値を返します。
1608519089EXPR は省略することができ、その場合には何も未定義にされませんが
1608619090未定義値は返されますので、それをたとえば、
1608719091サブルーチンの返り値、変数への割り当て、引数などとして使うことができます。
1608819092例:
1608919093
1609019094 undef $foo;
1609119095 undef $bar{'blurfl'}; # Compare to: delete $bar{'blurfl'};
1609219096 undef @ary;
1609319097 undef %hash;
1609419098 undef &mysub;
1609519099 undef *xyz; # destroys $xyz, @xyz, %xyz, &xyz, etc.
1609619100 return (wantarray ? (undef, $errmsg) : undef) if $they_blew_it;
1609719101 select undef, undef, undef, 0.25;
16098 ($a, $b, undef, $c) = &foo; # Ignore third value returned
19102 my ($x, $y, undef, $z) = foo(); # Ignore third value returned
1609919103
1610019104=begin original
1610119105
1610219106Note that this is a unary operator, not a list operator.
1610319107
1610419108=end original
1610519109
1610619110これはリスト演算子ではなく、単項演算子であることに注意してください。
1610719111
1610819112=item unlink LIST
1610919113X<unlink> X<delete> X<remove> X<rm> X<del>
1611019114
1611119115=item unlink
1611219116
19117=for Pod::Functions remove one link to a file
19118
1611319119=begin original
1611419120
16115Deletes a list of files. On success, it returns the number of files
19121Deletes a list of files. On success, it returns the number of files
16116it successfully deleted. On failure, it returns false and sets C<$!>
19122it successfully deleted. On failure, it returns false and sets
16117(errno):
19123L<C<$!>|perlvar/$!> (errno):
1611819124
1611919125=end original
1612019126
1612119127LIST に含まれるファイルを削除します。
1612219128成功時は削除に成功したファイルの数を返します。
16123失敗時は偽を返しC<$!> (error) をセットします:
19129失敗時は偽を返して L<C<$!>|perlvar/$!> (error) をセットします:
1612419130
1612519131 my $unlinked = unlink 'a', 'b', 'c';
1612619132 unlink @goners;
1612719133 unlink glob "*.bak";
1612819134
1612919135=begin original
1613019136
16131On error, C<unlink> will not tell you which files it could not remove.
19137On error, L<C<unlink>|/unlink LIST> will not tell you which files it
19138could not remove.
1613219139If you want to know which files you could not remove, try them one
1613319140at a time:
1613419141
1613519142=end original
1613619143
16137エラーの場合、C<unlink> はどのファイルが削除できなかったかを知らせません。
19144エラーの場合、L<C<unlink>|/unlink LIST> はどのファイルが削除できなかったかを
19145知らせません。
1613819146どのファイルが削除できなかったかを知りたい場合は、一つずつ削除してください:
1613919147
1614019148 foreach my $file ( @goners ) {
1614119149 unlink $file or warn "Could not unlink $file: $!";
1614219150 }
1614319151
1614419152=begin original
1614519153
16146Note: C<unlink> will not attempt to delete directories unless you are
19154Note: L<C<unlink>|/unlink LIST> will not attempt to delete directories
16147superuser and the B<-U> flag is supplied to Perl. Even if these
19155unless you are
19156superuser and the B<-U> flag is supplied to Perl. Even if these
1614819157conditions are met, be warned that unlinking a directory can inflict
16149damage on your filesystem. Finally, using C<unlink> on directories is
19158damage on your filesystem. Finally, using L<C<unlink>|/unlink LIST> on
16150not supported on many operating systems. Use C<rmdir> instead.
19159directories is not supported on many operating systems. Use
19160L<C<rmdir>|/rmdir FILENAME> instead.
1615119161
1615219162=end original
1615319163
16154注: スーパーユーザ権限で、Perl に -U を付けて実行した場合でなければ、
19164注: スーパーユーザ権限で、Perl に B<-U> を付けて実行した場合でなければ、
16155C<unlink> はディレクトリを削除しようとすることはありません。
19165L<C<unlink>|/unlink LIST> はディレクトリを削除しようとすることはありません。
1615619166この条件にあう場合にも、ディレクトリの削除は、
1615719167ファイルシステムに多大な損害を与える可能性があります。
16158最後に、C<unlink> をディレクトリに使うのはほとんどの OS では
19168最後に、L<C<unlink>|/unlink LIST> をディレクトリに使うのはほとんどの OS では
1615919169対応していません。
16160代わりに C<rmdir> を使ってください。
19170代わりに L<C<rmdir>|/rmdir FILENAME> を使ってください。
1616119171
1616219172=begin original
1616319173
16164If LIST is omitted, C<unlink> uses C<$_>.
19174If LIST is omitted, L<C<unlink>|/unlink LIST> uses L<C<$_>|perlvar/$_>.
1616519175
1616619176=end original
1616719177
16168LIST が省略されると、C<unlink> は C<$_> を使います。
19178LIST が省略されると、L<C<unlink>|/unlink LIST> L<C<$_>|perlvar/$_>
19179使います。
1616919180
1617019181=item unpack TEMPLATE,EXPR
1617119182X<unpack>
1617219183
1617319184=item unpack TEMPLATE
1617419185
19186=for Pod::Functions convert binary structure into normal perl variables
19187
1617519188=begin original
1617619189
16177C<unpack> does the reverse of C<pack>: it takes a string
19190L<C<unpack>|/unpack TEMPLATE,EXPR> does the reverse of
19191L<C<pack>|/pack TEMPLATE,LIST>: it takes a string
1617819192and expands it out into a list of values.
1617919193(In scalar context, it returns merely the first value produced.)
1618019194
1618119195=end original
1618219196
16183C<unpack> は C<pack> の逆を行ないます: 構造体を表わす文字列をとり、
19197L<C<unpack>|/unpack TEMPLATE,EXPR> L<C<pack>|/pack TEMPLATE,LIST> の逆を
19198行ないます: 構造体を表わす文字列をとり、
1618419199リスト値に展開し、その配列値を返します。
1618519200(スカラコンテキストでは、単に最初の値を返します。)
1618619201
1618719202=begin original
1618819203
16189If EXPR is omitted, unpacks the C<$_> string.
19204If EXPR is omitted, unpacks the L<C<$_>|perlvar/$_> string.
1619019205See L<perlpacktut> for an introduction to this function.
1619119206
1619219207=end original
1619319208
16194EXPR が省略されると、C<$_> の文字列を unpack します。
19209EXPR が省略されると、L<C<$_>|perlvar/$_> の文字列を unpack します。
16195この関数についての説明については L<perlpacktut> を参照してください。
19210この関数の説明については L<perlpacktut> を参照してください。
1619619211
1619719212=begin original
1619819213
1619919214The string is broken into chunks described by the TEMPLATE. Each chunk
1620019215is converted separately to a value. Typically, either the string is a result
16201of C<pack>, or the characters of the string represent a C structure of some
19216of L<C<pack>|/pack TEMPLATE,LIST>, or the characters of the string
16202kind.
19217represent a C structure of some kind.
1620319218
1620419219=end original
1620519220
1620619221文字列は TEMPLATE で示された固まりに分割されます。
1620719222それぞれの固まりは別々に値に変換されます。
16208典型的には、文字列は C<pack> の結果あるいはある種の C の構造体
19223典型的には、文字列は L<C<pack>|/pack TEMPLATE,LIST> の結果あるいはある種の
16209文字列表現の文字列です。
19224C の構造体の文字列表現の文字列です。
1621019225
1621119226=begin original
1621219227
16213The TEMPLATE has the same format as in the C<pack> function.
19228The TEMPLATE has the same format as in the
19229L<C<pack>|/pack TEMPLATE,LIST> function.
1621419230Here's a subroutine that does substring:
1621519231
1621619232=end original
1621719233
16218TEMPLATE は、C<pack> 関数と同じフォーマットを使います。
19234TEMPLATE は、L<C<pack>|/pack TEMPLATE,LIST> 関数と同じフォーマットを使います。
1621919235部分文字列を取り出すうサブルーチンの例を示します:
1622019236
1622119237 sub substr {
16222 my($what,$where,$howmuch) = @_;
19238 my ($what, $where, $howmuch) = @_;
1622319239 unpack("x$where a$howmuch", $what);
1622419240 }
1622519241
1622619242=begin original
1622719243
1622819244and then there's
1622919245
1623019246=end original
1623119247
1623219248これもそうです。
1623319249
1623419250 sub ordinal { unpack("W",$_[0]); } # same as ord()
1623519251
1623619252=begin original
1623719253
16238In addition to fields allowed in pack(), you may prefix a field with
19254In addition to fields allowed in L<C<pack>|/pack TEMPLATE,LIST>, you may
16239a %<number> to indicate that
19255prefix a field with a %<number> to indicate that
1624019256you want a <number>-bit checksum of the items instead of the items
16241themselves. Default is a 16-bit checksum. Checksum is calculated by
19257themselves. Default is a 16-bit checksum. The checksum is calculated by
1624219258summing numeric values of expanded values (for string fields the sum of
1624319259C<ord($char)> is taken; for bit fields the sum of zeroes and ones).
1624419260
1624519261=end original
1624619262
16247pack() で利用可能なフィールドの他に、
19263L<C<pack>|/pack TEMPLATE,LIST> で利用可能なフィールドの他に、
1624819264フィールドの前に %<数値> というものを付けて、
1624919265項目自身の代わりに、その項目の <数値>-ビットのチェックサムを
1625019266計算させることができます。
1625119267デフォルトは、16-ビットチェックサムです。
1625219268チェックサムは展開された値の数値としての値の合計
1625319269(文字列フィールドの場合は C<ord($char)> の合計;
1625419270ビットフィールドの場合は 0 と 1 の合計) が用いられます。
1625519271
1625619272=begin original
1625719273
1625819274For example, the following
1625919275computes the same number as the System V sum program:
1626019276
1626119277=end original
1626219278
1626319279たとえば、以下のコードは
1626419280System V の sum プログラムと同じ値を計算します。
1626519281
16266 $checksum = do {
19282 my $checksum = do {
1626719283 local $/; # slurp!
16268 unpack("%32W*",<>) % 65535;
19284 unpack("%32W*", readline) % 65535;
1626919285 };
1627019286
1627119287=begin original
1627219288
1627319289The following efficiently counts the number of set bits in a bit vector:
1627419290
1627519291=end original
1627619292
1627719293以下は、効率的にビットベクターの設定されているビットを
1627819294数えるものです。
1627919295
16280 $setbits = unpack("%32b*", $selectmask);
19296 my $setbits = unpack("%32b*", $selectmask);
1628119297
1628219298=begin original
1628319299
1628419300The C<p> and C<P> formats should be used with care. Since Perl
16285has no way of checking whether the value passed to C<unpack()>
19301has no way of checking whether the value passed to
19302L<C<unpack>|/unpack TEMPLATE,EXPR>
1628619303corresponds to a valid memory location, passing a pointer value that's
1628719304not known to be valid is likely to have disastrous consequences.
1628819305
1628919306=end original
1629019307
1629119308C<p> と C<P> は注意深く使うべきです。
16292Perl は C<unpack()> に渡された値が有効なメモリ位置を指しているかどうか
19309Perl は L<C<unpack>|/unpack TEMPLATE,EXPR> に渡された値が有効なメモリ位置を
16293確認する方法がないので、有効かどうかわからないポインタ値を渡すと
19310指しているかどうかを確認する方法がないので、有効かどうかわからない
16294悲惨な結果を引き起こすかもしれません。
19311ポインタ値を渡すと悲惨な結果を引き起こすかもしれません。
1629519312
1629619313=begin original
1629719314
1629819315If there are more pack codes or if the repeat count of a field or a group
1629919316is larger than what the remainder of the input string allows, the result
1630019317is not well defined: the repeat count may be decreased, or
16301C<unpack()> may produce empty strings or zeros, or it may raise an exception.
19318L<C<unpack>|/unpack TEMPLATE,EXPR> may produce empty strings or zeros,
19319or it may raise an exception.
1630219320If the input string is longer than one described by the TEMPLATE,
1630319321the remainder of that input string is ignored.
1630419322
1630519323=end original
1630619324
1630719325多くの pack コードがある場合や、フィールドやグループの繰り返し回数が
1630819326入力文字列の残りより大きい場合、結果は未定義です:
16309繰り返し回数が減らされる場合もありますし、C<unpack()> が空文字列や 0 を
19327繰り返し回数が減らされる場合もありますし、
19328L<C<unpack>|/unpack TEMPLATE,EXPR> が空文字列や 0 を
1631019329返すこともありますし、例外が発生します。
1631119330もし入力文字列が TEMPLATE で表現されているものより大きい場合、
1631219331入力文字列の残りは無視されます。
1631319332
1631419333=begin original
1631519334
16316See L</pack> for more examples and notes.
19335See L<C<pack>|/pack TEMPLATE,LIST> for more examples and notes.
1631719336
1631819337=end original
1631919338
16320さらなる例と注意に関しては L</pack> を参照してください。
19339さらなる例と注意に関しては L<C<pack>|/pack TEMPLATE,LIST> を参照してください。
1632119340
16322=item untie VARIABLE
16323X<untie>
16324
16325=begin original
16326
16327Breaks the binding between a variable and a package. (See C<tie>.)
16328Has no effect if the variable is not tied.
16329
16330=end original
16331
16332変数とパッケージの間の結合を解きます。
16333(L<tie> を参照してください。)
16334結合されていない場合は何も起きません。
16335
1633619341=item unshift ARRAY,LIST
1633719342X<unshift>
1633819343
16339=item unshift EXPR,LIST
19344=for Pod::Functions prepend more elements to the beginning of a list
1634019345
1634119346=begin original
1634219347
16343Does the opposite of a C<shift>. Or the opposite of a C<push>,
19348Does the opposite of a L<C<shift>|/shift ARRAY>. Or the opposite of a
19349L<C<push>|/push ARRAY,LIST>,
1634419350depending on how you look at it. Prepends list to the front of the
1634519351array and returns the new number of elements in the array.
1634619352
1634719353=end original
1634819354
16349C<shift> の逆操作を行ないます。
19355L<C<shift>|/shift ARRAY> の逆操作を行ないます。
16350見方を変えれば、C<push> の逆操作とも考えられます。
19356見方を変えれば、L<C<push>|/push ARRAY,LIST> の逆操作とも考えられます。
1635119357LIST を ARRAY の先頭に入れて、新しくできた配列の要素の数を返します。
1635219358
1635319359 unshift(@ARGV, '-e') unless $ARGV[0] =~ /^-/;
1635419360
1635519361=begin original
1635619362
1635719363Note the LIST is prepended whole, not one element at a time, so the
16358prepended elements stay in the same order. Use C<reverse> to do the
19364prepended elements stay in the same order. Use
16359reverse.
19365L<C<reverse>|/reverse LIST> to do the reverse.
1636019366
1636119367=end original
1636219368
1636319369LIST は、はらばらにではなく、一度に登録されるので、順番はそのままです。
16364逆順に登録するには、C<reverse> を使ってください。
19370逆順に登録するには、L<C<reverse>|/reverse LIST> を使ってください。
1636519371
1636619372=begin original
1636719373
16368Starting with Perl 5.14, C<unshift> can take a scalar EXPR, which must hold
19374Starting with Perl 5.14, an experimental feature allowed
16369a reference to an unblessed array. The argument will be dereferenced
19375L<C<unshift>|/unshift ARRAY,LIST> to take
16370automatically. This aspect of C<unshift> is considered highly
19376a scalar expression. This experiment has been deemed unsuccessful, and was
16371experimental. The exact behaviour may change in a future version of Perl.
19377removed as of Perl 5.24.
1637219378
1637319379=end original
1637419380
16375Perl 5.14 から、C<unshift> スカラの EXPR 取ることができるようになりました;
19381Perl 5.14 から、L<C<unshift>|/unshift ARRAY,LIST> がスカラ
16376れは bless されてない配列へのリファレンスでなければなりません
19382取るとが出来るとう実験的機能がありました
16377引数自動的にデリファレンスされま
19383この実験失敗と見なされ、Perl 5.24 で削除されした
16378C<unshift> のこの動作は高度に実験的であると考えられています。
16379正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
1638019384
19385=item untie VARIABLE
19386X<untie>
19387
19388=for Pod::Functions break a tie binding to a variable
19389
19390=begin original
19391
19392Breaks the binding between a variable and a package.
19393(See L<tie|/tie VARIABLE,CLASSNAME,LIST>.)
19394Has no effect if the variable is not tied.
19395
19396=end original
19397
19398変数とパッケージの間の結合を解きます。
19399(L<tie|/tie VARIABLE,CLASSNAME,LIST> を参照してください。)
19400結合されていない場合は何も起きません。
19401
1638119402=item use Module VERSION LIST
1638219403X<use> X<module> X<import>
1638319404
1638419405=item use Module VERSION
1638519406
1638619407=item use Module LIST
1638719408
1638819409=item use Module
1638919410
1639019411=item use VERSION
1639119412
19413=for Pod::Functions load in a module at compile time and import its namespace
19414
1639219415=begin original
1639319416
1639419417Imports some semantics into the current package from the named module,
1639519418generally by aliasing certain subroutine or variable names into your
1639619419package. It is exactly equivalent to
1639719420
1639819421=end original
1639919422
16400指定したモジュールから、現在のパッケージにさまざまな内容を
19423指定したモジュールから、現在のパッケージにさまざまな内容をインポートします;
16401インポートします。
1640219424多くは、パッケージのサブルーチン名や、変数名に別名を付けることで、
16403実現されています。これは、
19425実現されています。
16404以下は等価ですが:
19426これは、以下は等価ですが:
1640519427
1640619428 BEGIN { require Module; Module->import( LIST ); }
1640719429
1640819430=begin original
1640919431
1641019432except that Module I<must> be a bareword.
16411The importation can be made conditional; see L<if>.
19433The importation can be made conditional by using the L<if> module.
1641219434
1641319435=end original
1641419436
1641519437Module が I<裸の単語でなければならない> ことを除けば、です。
16416インポートは条件付きで行うことができます; L<if> を参照してください
19438インポートは、L<if> を使って条件付きで行うことができます。
1641719439
1641819440=begin original
1641919441
1642019442In the peculiar C<use VERSION> form, VERSION may be either a positive
16421decimal fraction such as 5.006, which will be compared to C<$]>, or a v-string
19443decimal fraction such as 5.006, which will be compared to
16422of the form v5.6.1, which will be compared to C<$^V> (aka $PERL_VERSION). An
19444L<C<$]>|perlvar/$]>, or a v-string of the form v5.6.1, which will be
19445compared to L<C<$^V>|perlvar/$^V> (aka $PERL_VERSION). An
1642319446exception is raised if VERSION is greater than the version of the
1642419447current Perl interpreter; Perl will not attempt to parse the rest of the
16425file. Compare with L</require>, which can do a similar check at run time.
19448file. Compare with L<C<require>|/require VERSION>, which can do a
19449similar check at run time.
1642619450Symmetrically, C<no VERSION> allows you to specify that you want a version
1642719451of Perl older than the specified one.
1642819452
1642919453=end original
1643019454
16431特に C<use VERSION> の形式では、
19455特に C<use VERSION> の形式では、VERSION は 5.006 のような正の 10 進小数
16432VERSION は 5.006 のような正の 10 進小数 (C<$]> と比較されます)か、v5.6.1 の形
19456(L<C<$]>|perlvar/$]> と比較されます)か、v5.6.1 の形
16433(C<$^V> (またの名を $PERL_VERSION) と比較されます) のv-文字列で指定します。
19457(L<C<$^V>|perlvar/$^V> (またの名を $PERL_VERSION) と比較されます) の
19458v-文字列で指定します。
1643419459VERSION が Perl の現在のバージョンより大きいと、例外が発生します;
1643519460Perl はファイルの残りを読み込みません。
16436L</require> と似ていますが、これは実行時にチェックされます。
19461L<C<require>|/require VERSION> と似ていますが、これは実行時にチェックされます。
1643719462対称的に、C<no VERSION> は指定されたバージョンより古いバージョンの Perl で
1643819463動作させたいことを意味します。
1643919464
1644019465=begin original
1644119466
1644219467Specifying VERSION as a literal of the form v5.6.1 should generally be
1644319468avoided, because it leads to misleading error messages under earlier
1644419469versions of Perl (that is, prior to 5.6.0) that do not support this
1644519470syntax. The equivalent numeric version should be used instead.
1644619471
1644719472=end original
1644819473
1644919474VERSION に v5.6.1 の形のリテラルを指定することは一般的には避けるべきです;
1645019475なぜなら、この文法に対応していない Perl の初期のバージョン
1645119476(つまり、 5.6.0 以前) では誤解させるようなエラーメッセージが出るからです。
1645219477代わりに等価な数値表現を使うべきです。
1645319478
1645419479 use v5.6.1; # compile time version check
1645519480 use 5.6.1; # ditto
1645619481 use 5.006_001; # ditto; preferred for backwards compatibility
1645719482
1645819483=begin original
1645919484
1646019485This is often useful if you need to check the current Perl version before
16461C<use>ing library modules that won't work with older versions of Perl.
19486L<C<use>|/use Module VERSION LIST>ing library modules that won't work
19487with older versions of Perl.
1646219488(We try not to do this more than we have to.)
1646319489
1646419490=end original
1646519491
16466これは古いバージョンの Perl で動かなくなったライブラリ
19492これは古いバージョンの Perl で動かなくなったライブラリモジュールを
16467モジュール(我々は必要な場合以外ようなことがないように
19493L<C<use>|/use Module VERSION LIST> する前、現在 Perl のバージョンを
16468努力していますが)を C<use> する前に、現在の Perl のバージョンを
1646919494調べたい場合に有用です。
19495(我々は必要な場合以外にそのようなことがないように努力していますが。)
1647019496
1647119497=begin original
1647219498
16473Also, if the specified Perl version is greater than or equal to 5.9.5,
19499C<use VERSION> also lexically enables all features available in the requested
16474C<use VERSION> will also load the C<feature> pragma and enable all
19500version as defined by the L<feature> pragma, disabling any features
16475features available in the requested version. See L<feature>.
19501not in the requested version's feature bundle. See L<feature>.
1647619502Similarly, if the specified Perl version is greater than or equal to
164775.11.0, strictures are enabled lexically as with C<use strict> (except
195035.12.0, strictures are enabled lexically as
16478that the F<strict.pm> file is not actually loaded).
19504with L<C<use strict>|strict>. Any explicit use of
19505C<use strict> or C<no strict> overrides C<use VERSION>, even if it comes
19506before it. Later use of C<use VERSION>
19507will override all behavior of a previous
19508C<use VERSION>, possibly removing the C<strict> and C<feature> added by
19509C<use VERSION>. C<use VERSION> does not
19510load the F<feature.pm> or F<strict.pm>
19511files.
1647919512
1648019513=end original
1648119514
16482また、指定された Perl のバージョンが 5.9.5 以上の場合、C<use VERSION> は
19515C<use VERSION> は、L<feature> プラグマで定義されたように、指定された
16483C<feature> プラグマも読み込み、要求されたバージョンで利用可能な全ての機能を
19516バージョンで利用可能な全ての機能を有効にし、指定されたバージョンの機能の
16484効にします。
19517束にない機能をレキシカルに無効にします。
1648519518L<feature> を参照してください。
16486同様に、指定された Perl のバージョンが 5.11.0 以上の場合、
19519同様に、指定された Perl のバージョンが 5.12.0 以上の場合、
16487制限は C<use strict> と同様にレキシカルに有効になります
19520制限は L<C<use strict>|strict> と同様にレキシカルに有効になります
16488(但し F<strict.pm> ファイルは実際は読み込まれません)。
19521明示的に C<use strict> や C<no strict> を使うと、例え先
19522指定されていたとしても、C<use VERSION> を上書きします。
19523後から使った C<use VERSION> は先の
19524C<use VERSION> の全ての振る舞いを上書きするので、
19525C<use VERSION> によって追加された C<strict> と C<feature> を
19526削除することがあります。
19527C<use VERSION> は F<feature.pm> と F<strict.pm> ファイルは読み込みません。
1648919528
1649019529=begin original
1649119530
16492The C<BEGIN> forces the C<require> and C<import> to happen at compile time. The
19531The C<BEGIN> forces the L<C<require>|/require VERSION> and
16493C<require> makes sure the module is loaded into memory if it hasn't been
19532L<C<import>|/import LIST> to happen at compile time. The
16494yet. The C<import> is not a builtin; it's just an ordinary static method
19533L<C<require>|/require VERSION> makes sure the module is loaded into
19534memory if it hasn't been yet. The L<C<import>|/import LIST> is not a
19535builtin; it's just an ordinary static method
1649519536call into the C<Module> package to tell the module to import the list of
1649619537features back into the current package. The module can implement its
16497C<import> method any way it likes, though most modules just choose to
19538L<C<import>|/import LIST> method any way it likes, though most modules
16498derive their C<import> method via inheritance from the C<Exporter> class that
19539just choose to derive their L<C<import>|/import LIST> method via
16499is defined in the C<Exporter> module. See L<Exporter>. If no C<import>
19540inheritance from the C<Exporter> class that is defined in the
16500method can be found then the call is skipped, even if there is an AUTOLOAD
19541L<C<Exporter>|Exporter> module. See L<Exporter>. If no
16501method.
19542L<C<import>|/import LIST> method can be found, then the call is skipped,
19543even if there is an AUTOLOAD method.
1650219544
1650319545=end original
1650419546
16505C<BEGIN> によって、C<require> や C<import> は、コンパイル時に
19547C<BEGIN> によって、L<C<require>|/require VERSION>
19548L<C<import>|/import LIST> は、コンパイル時に
1650619549実行されることになります。
16507C<require> は、モジュールがまだメモリにロードされていなければ、ロードします。
19550L<C<require>|/require VERSION> は、モジュールがまだメモリに
16508C<import> は、組込みの関数ではありません; まざま機能を現在のパッケジに
19551ロードれていければ、ロドします。
16509インポートするように C<Module> パッケージに伝えるために呼ばれる
19552L<C<import>|/import LIST> は組込みの関数ではありません; さまざまな機能を
16510通常静的メソドで
19553現在ケージにインポートるように C<Module> パッケージに伝えるために
16511モジュール側ではC<import> メソッドをどのようにも実装ることが
19554呼ばれる通常の静的メソッドです
16512できますが、多くのモジュールでは、C<Exporter> モジュール定義された、
19555モジュールでは、L<C<import>|/import LIST> メソッドをどのように
16513C<Exporter> クラスから継承によってC<import> メソッドを行なうように
19556実装することができますが、多くモジュールでは
16514しています。
19557L<C<Exporter>|Exporter> モジュールで定義された、
19558C<Exporter> クラスからの継承によって、L<C<import>|/import LIST> メソッドを
19559行なうようにしています。
1651519560L<Exporter>モジュールを参照してください。
16516C<import>メソッドが見つからなかった場合、AUTOLOAD メソッドがあったとしても
19561L<C<import>|/import LIST>メソッドが見つからなかった場合、AUTOLOAD メソッドが
16517呼び出しはスキップされます。
19562あったとしても呼び出しはスキップされます。
1651819563
1651919564=begin original
1652019565
16521If you do not want to call the package's C<import> method (for instance,
19566If you do not want to call the package's L<C<import>|/import LIST>
19567method (for instance,
1652219568to stop your namespace from being altered), explicitly supply the empty list:
1652319569
1652419570=end original
1652519571
16526パッケージの C<import> メソッドを呼び出したくない場合(例えば、名前空間を
19572パッケージの L<C<import>|/import LIST> メソッドを呼び出したくない場合(例えば、
16527変更したくない場合など)は、明示的に空リストを指定してください:
19573名前空間を変更したくない場合など)は、明示的に空リストを指定してください:
1652819574
1652919575 use Module ();
1653019576
1653119577=begin original
1653219578
1653319579That is exactly equivalent to
1653419580
1653519581=end original
1653619582
1653719583これは以下と完全に等価です:
1653819584
1653919585 BEGIN { require Module }
1654019586
1654119587=begin original
1654219588
1654319589If the VERSION argument is present between Module and LIST, then the
16544C<use> will call the VERSION method in class Module with the given
19590L<C<use>|/use Module VERSION LIST> will call the C<VERSION> method in
16545version as an argument. The default VERSION method, inherited from
19591class Module with the given version as an argument:
16546the UNIVERSAL class, croaks if the given version is larger than the
16547value of the variable C<$Module::VERSION>.
1654819592
1654919593=end original
1655019594
16551Module と LIST の間に VERSION 引数がある場合、C<use> は Module クラスの
19595Module と LIST の間に VERSION 引数がある場合、
16552VERSION メソッドを、与えられたバージョンを引数として呼び出します。
19596L<C<use>|/use Module VERSION LIST> は Module クラスの
16553デフォルトの VERSION メソッド UNIVERSAL クラスか継承しもので、
19597C<VERSION> メソッド与えバージョンを引数として呼び出します:
19598
19599 use Module 12.34;
19600
19601=begin original
19602
19603is equivalent to:
19604
19605=end original
19606
19607は以下と等価です:
19608
19609 BEGIN { require Module; Module->VERSION(12.34) }
19610
19611=begin original
19612
19613The L<default C<VERSION> method|UNIVERSAL/C<VERSION ( [ REQUIRE ] )>>,
19614inherited from the L<C<UNIVERSAL>|UNIVERSAL> class, croaks if the given
19615version is larger than the value of the variable C<$Module::VERSION>.
19616
19617=end original
19618
19619デフォルトの
19620L<default C<VERSION> メソッド|UNIVERSAL/C<VERSION ( [ REQUIRE ] )>> は、
19621L<C<UNIVERSAL>|UNIVERSAL> クラスから継承したもので、
1655419622与えられたバージョンが 変数 C<$Module::VERSION> の値より大きい場合に
1655519623警告を出します。
1655619624
1655719625=begin original
1655819626
16559Again, there is a distinction between omitting LIST (C<import> called
19627Again, there is a distinction between omitting LIST (L<C<import>|/import
16560with no arguments) and an explicit empty LIST C<()> (C<import> not
19628LIST> called with no arguments) and an explicit empty LIST C<()>
16561called). Note that there is no comma after VERSION!
19629(L<C<import>|/import LIST> not called). Note that there is no comma
19630after VERSION!
1656219631
1656319632=end original
1656419633
16565繰り返すと、LIST を省略する(C<import> が引数なしで呼び出される)ことと
19634繰り返すと、LIST を省略する(L<C<import>|/import LIST> が引数なしで
16566明示的に空の LIST C<()> を指定する (C<import> は呼び出されない)ことは
19635呼び出される)ことと明示的に空の LIST C<()> を指定する
16567違います。
19636(L<C<import>|/import LIST> は呼び出されない)ことは違います。
1656819637VERSION の後ろにカンマが不要なことに注意してください!
1656919638
1657019639=begin original
1657119640
1657219641Because this is a wide-open interface, pragmas (compiler directives)
16573are also implemented this way. Currently implemented pragmas are:
19642are also implemented this way. Some of the currently implemented
19643pragmas are:
1657419644
1657519645=end original
1657619646
1657719647これは、広く公開されているインタフェースですので、
1657819648プラグマ (コンパイラディレクティブ) も、この方法で実装されています。
16579現在実装されているプラグマには、以下のものがあります:
19649現在実装されているプラグマには、以下のようなものがあります:
1658019650
1658119651 use constant;
1658219652 use diagnostics;
1658319653 use integer;
1658419654 use sigtrap qw(SEGV BUS);
1658519655 use strict qw(subs vars refs);
1658619656 use subs qw(afunc blurfl);
1658719657 use warnings qw(all);
1658819658 use sort qw(stable _quicksort _mergesort);
1658919659
1659019660=begin original
1659119661
1659219662Some of these pseudo-modules import semantics into the current
16593block scope (like C<strict> or C<integer>, unlike ordinary modules,
19663block scope (like L<C<strict>|strict> or L<C<integer>|integer>, unlike
16594which import symbols into the current package (which are effective
19664ordinary modules, which import symbols into the current package (which
16595through the end of the file).
19665are effective through the end of the file).
1659619666
1659719667=end original
1659819668
1659919669通常のモジュールが、現在のパッケージにシンボルをインポートする
16600(これは、ファイルの終わりまで有効です) のに対して、
19670(これは、ファイルの終わりまで有効です) のに対して、これらの擬似モジュールの
16601これらの擬似モジュールの一部(C<strict> や C<integer> など)は、
19671一部(L<C<strict>|strict>L<C<integer>|integer> など)は、現在の
16602現在のブロックスコープにインポートを行ないます。
19672ブロックスコープにインポートを行ないます。
1660319673
1660419674=begin original
1660519675
16606Because C<use> takes effect at compile time, it doesn't respect the
19676Because L<C<use>|/use Module VERSION LIST> takes effect at compile time,
16607ordinary flow control of the code being compiled. In particular, putting
19677it doesn't respect the ordinary flow control of the code being compiled.
16608a C<use> inside the false branch of a conditional doesn't prevent it
19678In particular, putting a L<C<use>|/use Module VERSION LIST> inside the
16609from being processed. If a module or pragma only needs to be loaded
19679false branch of a conditional doesn't prevent it
19680from being processed. If a module or pragma only needs to be loaded
1661019681conditionally, this can be done using the L<if> pragma:
1661119682
1661219683=end original
1661319684
16614C<use> はコンパイル時に有効なので、コードがコンパイルされる際の通常の
19685L<C<use>|/use Module VERSION LIST> はコンパイル時に有効なので、コードが
16615流れ制御には従いません。
19686コンパイルされる際の通常の流れ制御には従いません。
16616特に、条件文のうち成立しない側の中に C<use> を書いても、
19687特に、条件文のうち成立しない側の中に L<C<use>|/use Module VERSION LIST>
16617処理を妨げられません。
19688書いても、処理を妨げられません。
1661819689モジュールやプラグマを条件付きでのみ読み込みたい場合、
1661919690L<if> プラグマを使って実現できます:
1662019691
1662119692 use if $] < 5.008, "utf8";
1662219693 use if WANT_WARNINGS, warnings => qw(all);
1662319694
1662419695=begin original
1662519696
16626There's a corresponding C<no> declaration that unimports meanings imported
19697There's a corresponding L<C<no>|/no MODULE VERSION LIST> declaration
16627by C<use>, i.e., it calls C<unimport Module LIST> instead of C<import>.
19698that unimports meanings imported by L<C<use>|/use Module VERSION LIST>,
16628It behaves just as C<import> does with VERSION, an omitted or empty LIST,
19699i.e., it calls C<< Module->unimport(LIST) >> instead of
19700L<C<import>|/import LIST>. It behaves just as L<C<import>|/import LIST>
19701does with VERSION, an omitted or empty LIST,
1662919702or no unimport method being found.
1663019703
1663119704=end original
1663219705
16633これに対して、C<no> 宣言という、C<use> によってインポートされたものを
19706これに対して、L<C<no>|/no MODULE VERSION LIST> 宣言という、
16634インポートされていないことにするものがあります。
19707L<C<use>|/use Module VERSION LIST> によってインポートされものを、
16635つまり、C<import> 代わに C<unimport Module LIST> を呼び出します
19708インポートされていないことにするもがあります; つまり、
19709L<C<import>|/import LIST> の代わりに
19710C<< Module->unimport(LIST) >> を呼び出します。
1663619711これは VERSION、省略された LIST、空の LIST、unimport メソッドが見つからない
16637場合などの観点では、C<import> と同様に振る舞います。
19712場合などの観点では、L<C<import>|/import LIST> と同様に振る舞います。
1663819713
1663919714 no integer;
1664019715 no strict 'refs';
1664119716 no warnings;
1664219717
1664319718=begin original
1664419719
16645Care should be taken when using the C<no VERSION> form of C<no>. It is
19720Care should be taken when using the C<no VERSION> form of L<C<no>|/no
19721MODULE VERSION LIST>. It is
1664619722I<only> meant to be used to assert that the running Perl is of a earlier
1664719723version than its argument and I<not> to undo the feature-enabling side effects
1664819724of C<use VERSION>.
1664919725
1665019726=end original
1665119727
16652C<no> の C<no VERSION> 形式を使うときには注意を払うべきです。
19728L<C<no>|/no MODULE VERSION LIST> の C<no VERSION> 形式を使うときには
19729注意を払うべきです。
1665319730これは引数で指定されたバージョンよりも前の Perl で実行されたときに
1665419731アサートされることを意味する I<だけ> で、C<use VERSION> によって
1665519732有効にされた副作用をなかったことにするもの I<ではありません>。
1665619733
1665719734=begin original
1665819735
1665919736See L<perlmodlib> for a list of standard modules and pragmas. See L<perlrun>
16660for the C<-M> and C<-m> command-line options to Perl that give C<use>
19737for the C<-M> and C<-m> command-line options to Perl that give
16661functionality from the command-line.
19738L<C<use>|/use Module VERSION LIST> functionality from the command-line.
1666219739
1666319740=end original
1666419741
1666519742標準モジュールやプラグマの一覧は、L<perlmodlib> を参照してください。
16666コマンドラインから C<use> 機能を指定するための C<-M> C<-m>
19743コマンドラインから L<C<use>|/use Module VERSION LIST> 機能を
16667コマンドラインオプションについては L<perlrun> を参照して下さい。
19744指定するための C<-M> と C<-m> の
19745コマンドラインオプションについては L<perlrun> を参照してください。
1666819746
1666919747=item utime LIST
1667019748X<utime>
1667119749
19750=for Pod::Functions set a file's last access and modify times
19751
1667219752=begin original
1667319753
1667419754Changes the access and modification times on each file of a list of
1667519755files. The first two elements of the list must be the NUMERIC access
1667619756and modification times, in that order. Returns the number of files
1667719757successfully changed. The inode change time of each file is set
1667819758to the current time. For example, this code has the same effect as the
16679Unix touch(1) command when the files I<already exist> and belong to
19759Unix L<touch(1)> command when the files I<already exist> and belong to
1668019760the user running the program:
1668119761
1668219762=end original
1668319763
1668419764ファイルのアクセス時刻と修正(modification) 時刻を変更します。
1668519765LIST の最初の二つの要素に、数値で表わしたアクセス時刻と修正時刻を
1668619766順に指定します。
1668719767変更に成功したファイルの数を返します。
1668819768各ファイルの inode 変更(change)時刻には、その時点の時刻が設定されます。
1668919769例えば、このコードはファイルが I<既に存在して> いて、ユーザーが
1669019770実行しているプログラムに従っているなら、
16691Unix の touch(1) コマンドと同じ効果があります。
19771Unix の L<touch(1)> コマンドと同じ効果があります。
1669219772
1669319773 #!/usr/bin/perl
16694 $atime = $mtime = time;
19774 my $atime = my $mtime = time;
1669519775 utime $atime, $mtime, @ARGV;
1669619776
1669719777=begin original
1669819778
16699Since Perl 5.7.2, if the first two elements of the list are C<undef>,
19779Since Perl 5.8.0, if the first two elements of the list are
16700the utime(2) syscall from your C library is called with a null second
19780L<C<undef>|/undef EXPR>,
16701argument. On most systems, this will set the file's access and
19781the L<utime(2)> syscall from your C library is called with a null second
19782argument. On most systems, this will set the file's access and
1670219783modification times to the current time (i.e., equivalent to the example
1670319784above) and will work even on files you don't own provided you have write
1670419785permission:
1670519786
1670619787=end original
1670719788
16708Perl 5.7.2 から、リストの最初の二つの要素が C<undef> である場合、
19789Perl 5.8.0 から、リストの最初の二つの要素が L<C<undef>|/undef EXPR> である
16709C ライブラリの utime(2) システムコールを、秒の引数を null として
19790場合、C ライブラリの L<utime(2)> システムコールを、秒の引数を null として
1671019791呼び出します。
1671119792ほとんどのシステムでは、これによってファイルのアクセス時刻と修正時刻を
1671219793現在の時刻にセットし(つまり、上記の例と等価です)、
1671319794書き込み権限があれば他のユーザーのファイルに対しても動作します。
1671419795
16715 for $file (@ARGV) {
19796 for my $file (@ARGV) {
16716 utime(undef, undef, $file)
19797 utime(undef, undef, $file)
16717 || warn "couldn't touch $file: $!";
19798 || warn "Couldn't touch $file: $!";
16718 }
19799 }
1671919800
1672019801=begin original
1672119802
1672219803Under NFS this will use the time of the NFS server, not the time of
1672319804the local machine. If there is a time synchronization problem, the
1672419805NFS server and local machine will have different times. The Unix
16725touch(1) command will in fact normally use this form instead of the
19806L<touch(1)> command will in fact normally use this form instead of the
1672619807one shown in the first example.
1672719808
1672819809=end original
1672919810
1673019811NFS では、これはローカルマシンの時刻ではなく、NFS サーバーの時刻が
1673119812使われます。
1673219813時刻同期に問題がある場合、NFS サーバーとローカルマシンで違う時刻に
1673319814なっている場合があります。
16734実際のところ、Unix の touch(1) コマンドは普通、最初の例ではなく、
19815実際のところ、Unix の L<touch(1)> コマンドは普通、最初の例ではなく、
1673519816この形を使います。
1673619817
1673719818=begin original
1673819819
16739Passing only one of the first two elements as C<undef> is
19820Passing only one of the first two elements as L<C<undef>|/undef EXPR> is
16740equivalent to passing a 0 and will not have the effect
19821equivalent to passing a 0 and will not have the effect described when
16741described when both are C<undef>. This also triggers an
19822both are L<C<undef>|/undef EXPR>. This also triggers an
1674219823uninitialized warning.
1674319824
1674419825=end original
1674519826
16746最初の二つの要素のうち、一つだけに C<undef> を渡すと、その要素は 0 を
19827最初の二つの要素のうち、一つだけに L<C<undef>|/undef EXPR> を渡すと、その
16747渡すのと等価となり、上述の、両方に C<undef> を渡した時と同じ
19828要素は 0 を渡すのと等価となり、上述の、両方に L<C<undef>|/undef EXPR>
16748効果ではありません。
19829渡した時と同じ効果ではありません。
1674919830この場合は、未初期化の警告が出ます。
1675019831
1675119832=begin original
1675219833
16753On systems that support futimes(2), you may pass filehandles among the
19834On systems that support L<futimes(2)>, you may pass filehandles among the
16754files. On systems that don't support futimes(2), passing filehandles raises
19835files. On systems that don't support L<futimes(2)>, passing filehandles raises
1675519836an exception. Filehandles must be passed as globs or glob references to be
1675619837recognized; barewords are considered filenames.
1675719838
1675819839=end original
1675919840
16760futimes(2) に対応しているシステムでは、ファイルハンドルを引数として
19841L<futimes(2)> に対応しているシステムでは、ファイルハンドルを引数として
1676119842渡せます。
16762futimes(2) に対応していないシステムでは、ファイルハンドルを渡すと
19843L<futimes(2)> に対応していないシステムでは、ファイルハンドルを渡すと
1676319844例外が発生します。
1676419845ファイルハンドルを認識させるためには、グロブまたはリファレンスとして
1676519846渡されなければなりません; 裸の単語はファイル名として扱われます。
1676619847
19848=begin original
19849
19850Portability issues: L<perlport/utime>.
19851
19852=end original
19853
19854移植性の問題: L<perlport/utime>。
19855
1676719856=item values HASH
1676819857X<values>
1676919858
1677019859=item values ARRAY
1677119860
16772=item values EXPR
19861=for Pod::Functions return a list of the values in a hash
1677319862
1677419863=begin original
1677519864
16776Returns a list consisting of all the values of the named hash, or the values
19865In list context, returns a list consisting of all the values of the named
16777of an array. (In scalar context, returns the number of values.)
19866hash. In Perl 5.12 or later only, will also return a list of the values of
19867an array; prior to that release, attempting to use an array argument will
19868produce a syntax error. In scalar context, returns the number of values.
1677819869
1677919870=end original
1678019871
16781指定したハッシュのすべての値、あるいは配列の全ての値からなるリスト
19872リストコンテキストでは、指定したハッシュのすべての値を返します。
16782返します
19873Perl 5.12 以降でのみ、配列の全ての値からなるリストも返します;
16783(カラコンテキストでは、値の数を返します。)
19874このリリーの前では、配列要素に使おうとすると文法エラーが発生します。
19875スカラコンテキストでは、値の数を返します。
1678419876
1678519877=begin original
1678619878
16787The values are returned in an apparently random order. The actual
19879Hash entries are returned in an apparently random order. The actual random
16788random order is subject to change in future versions of Perl, but it
19880order is specific to a given hash; the exact same series of operations
16789is guaranteed to be the same order as either the C<keys> or C<each>
19881on two hashes may result in a different order for each hash. Any insertion
16790function would produce on the same (unmodified) hash. Since Perl
19882into the hash may change the order, as will any deletion, with the exception
167915.8.1 the ordering is different even between different runs of Perl
19883that the most recent key returned by L<C<each>|/each HASH> or
16792for security reasons (see L<perlsec/"Algorithmic Complexity Attacks">).
19884L<C<keys>|/keys HASH> may be deleted without changing the order. So
19885long as a given hash is unmodified you may rely on
19886L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and
19887L<C<each>|/each HASH> to repeatedly return the same order
19888as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
19889details on why hash order is randomized. Aside from the guarantees
19890provided here the exact details of Perl's hash algorithm and the hash
19891traversal order are subject to change in any release of Perl. Tied hashes
19892may behave differently to Perl's hashes with respect to changes in order on
19893insertion and deletion of items.
1679319894
1679419895=end original
1679519896
16796返される value の順序た目にばらばらものです。
19897ハッシュ要素は見かけ上、ランダム順序返されます。
16797実際のランダムな順序は将来バージョン Perl では変わる可能性が
19898実際のランダムな順序はハッシュに固有です; 二つハッシュに全く同じ一連
16798ありますが、同じ(変更されいない)ハッシュに対し
19899操作を行っも、ハッシュによっ異なった順序になります。
16799C<keys>関数や C<each>関数が返すもと同じ順序であることは保証されます
19900ハッシュへ挿入によって順序が変わることがあります; 削除も同様ですが、
16800Perl 5.8.1 以降でセキュリティ上の理由により、
19901L<C<each>|/each HASH> また L<C<keys>|/keys HASH> によって返されたもっとも
16801実行される毎に順番は変わります
19902最近のキー順序をえることなく削除できます
16802(L<perlsec/"Algorithmic Complexity Attacks"> を参照してください)。
19903ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>,
19904L<C<each>|/each HASH> が繰り返し同じ順序で返すことに依存してもかまいません。
19905なぜハッシュの順序がランダム化されているかの詳細については
19906L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。
19907ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の
19908正確な詳細は Perl のリリースによって変更される可能性があります。
19909tie されたハッシュは、アイテムの挿入と削除の順序に関して Perl のハッシュと
19910異なった振る舞いをします。
1680319911
1680419912=begin original
1680519913
16806As a side effect, calling values() resets the HASH or ARRAY's internal
19914As a side effect, calling L<C<values>|/values HASH> resets the HASH or
16807iterator;
19915ARRAY's internal iterator, see L<C<each>|/each HASH>. (In particular,
16808see L</each>. (In particular, calling values() in void context resets
19916calling L<C<values>|/values HASH> in void context resets the iterator
16809the iterator with no other overhead. Apart from resetting the iterator,
19917with no other overhead. Apart from resetting the iterator,
1681019918C<values @array> in list context is the same as plain C<@array>.
16811We recommend that you use void context C<keys @array> for this, but reasoned
19919(We recommend that you use void context C<keys @array> for this, but
16812that it taking C<values @array> out would require more documentation than
19920reasoned that taking C<values @array> out would require more
16813leaving it in.)
19921documentation than leaving it in.)
1681419922
1681519923=end original
1681619924
16817副作用として、values() を呼び出すと HASH や ARRAY の内部反復子を
19925副作用として、L<C<values>|/values HASH> を呼び出すと HASH や ARRAY の
16818リセットします;
19926内部反復子をリセットします; L<C<each>|/each HASH> を参照してください。
16819C</each> を参照してください。
19927(特に、L<C<values>|/values HASH> を無効コンテキストで呼び出すとその他の
16820(特に、values() を無効コンテキストで呼び出すとその他のオーバーヘッドなしで
19928オーバーヘッドなしで反復子をリセットします。
16821反復子をリセットします。
1682219929反復子をリセットするということを除けば、
1682319930リストコンテキストでの C<values @array> は単なる C<@array> と同じです。
1682419931この目的のためには無効コンテキストで C<keys @array> を使うことを
1682519932お勧めしますが、C<values @array> を取り出すにはそのままにするよりも
1682619933より多くの文書が必要だと判断しました。)
1682719934
1682819935=begin original
1682919936
1683019937Note that the values are not copied, which means modifying them will
1683119938modify the contents of the hash:
1683219939
1683319940=end original
1683419941
1683519942値はコピーされないので、返されたリストを変更すると
1683619943ハッシュの中身が変更されることに注意してください。
1683719944
16838 for (values %hash) { s/foo/bar/g } # modifies %hash values
19945 for (values %hash) { s/foo/bar/g } # modifies %hash values
16839 for (@hash{keys %hash}) { s/foo/bar/g } # same
19946 for (@hash{keys %hash}) { s/foo/bar/g } # same
1684019947
1684119948=begin original
1684219949
16843Starting with Perl 5.14, C<values> can take a scalar EXPR, which must hold
19950Starting with Perl 5.14, an experimental feature allowed
16844a reference to an unblessed hash or array. The argument will be
19951L<C<values>|/values HASH> to take a
16845dereferenced automatically. This aspect of C<values> is considered highly
19952scalar expression. This experiment has been deemed unsuccessful, and was
16846experimental. The exact behaviour may change in a future version of Perl.
19953removed as of Perl 5.24.
1684719954
1684819955=end original
1684919956
16850Perl 5.14 から、C<values> スカラの EXPR を取ることができになりました;
19957Perl 5.14 から、L<C<values>|/values HASH> がスカラを取ることが出来とい
16851これは bless されていないハッシュや配列へのリファレンスでなければなりません
19958実験的機能がありました
16852引数自動的にデリファレンスされま
19959この実験失敗と見なされ、Perl 5.24 で削除されした
16853C<values> のこの動作は高度に実験的であると考えられています。
16854正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
1685519960
16856 for (values $hashref) { ... }
19961=begin original
16857 for (values $obj->get_arrayref) { ... }
1685819962
19963To avoid confusing would-be users of your code who are running earlier
19964versions of Perl with mysterious syntax errors, put this sort of thing at
19965the top of your file to signal that your code will work I<only> on Perls of
19966a recent vintage:
19967
19968=end original
19969
19970あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
19971文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
19972I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
19973書いてください:
19974
19975 use 5.012; # so keys/values/each work on arrays
19976
1685919977=begin original
1686019978
16861See also C<keys>, C<each>, and C<sort>.
19979See also L<C<keys>|/keys HASH>, L<C<each>|/each HASH>, and
19980L<C<sort>|/sort SUBNAME LIST>.
1686219981
1686319982=end original
1686419983
16865C<keys>, C<each>, C<sort> も参照してください。
19984L<C<keys>|/keys HASH>, L<C<each>|/each HASH>, L<C<sort>|/sort SUBNAME LIST>
19985参照してください。
1686619986
1686719987=item vec EXPR,OFFSET,BITS
1686819988X<vec> X<bit> X<bit vector>
1686919989
19990=for Pod::Functions test or set particular bits in a string
19991
1687019992=begin original
1687119993
1687219994Treats the string in EXPR as a bit vector made up of elements of
1687319995width BITS and returns the value of the element specified by OFFSET
1687419996as an unsigned integer. BITS therefore specifies the number of bits
1687519997that are reserved for each element in the bit vector. This must
1687619998be a power of two from 1 to 32 (or 64, if your platform supports
1687719999that).
1687820000
1687920001=end original
1688020002
1688120003文字列 EXPR を BITS 幅の要素からなるビットベクターとして扱い、
1688220004OFFSET で指定された要素を符号なし整数として返します。
1688320005従って、 BITS はビットベクターの中の各要素について予約されるビット数です。
1688420006BIT は、1 から 32 まで(プラットホームが
1688520007対応していれば 64 まで) の 2 のべき乗でなければなりません。
1688620008
1688720009=begin original
1688820010
1688920011If BITS is 8, "elements" coincide with bytes of the input string.
1689020012
1689120013=end original
1689220014
1689320015BITS が 8 の場合、「要素」は入力文字列の各バイトと一致します。
1689420016
1689520017=begin original
1689620018
1689720019If BITS is 16 or more, bytes of the input string are grouped into chunks
1689820020of size BITS/8, and each group is converted to a number as with
16899pack()/unpack() with big-endian formats C<n>/C<N> (and analogously
20021L<C<pack>|/pack TEMPLATE,LIST>/L<C<unpack>|/unpack TEMPLATE,EXPR> with
16900for BITS==64). See L<"pack"> for details.
20022big-endian formats C<n>/C<N> (and analogously for BITS==64). See
20023L<C<pack>|/pack TEMPLATE,LIST> for details.
1690120024
1690220025=end original
1690320026
1690420027BITS が 16 以上の場合、入力のバイト列は BITS/8 のサイズの固まりに
16905グループ化され、各グループは pack()/unpack() のビッグエンディアン
20028グループ化され、各グループは L<C<pack>|/pack TEMPLATE,LIST>/
20029L<C<unpack>|/unpack TEMPLATE,EXPR> のビッグエンディアン
1690620030フォーマット C<n>/C<N> を用いて(BITS==64 の類似として)数値に変換されます。
16907詳細は L<"pack"> を参照してください。
20031詳細は L<C<pack>|/pack TEMPLATE,LIST> を参照してください。
1690820032
1690920033=begin original
1691020034
1691120035If bits is 4 or less, the string is broken into bytes, then the bits
1691220036of each byte are broken into 8/BITS groups. Bits of a byte are
1691320037numbered in a little-endian-ish way, as in C<0x01>, C<0x02>,
1691420038C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80>. For example,
1691520039breaking the single input byte C<chr(0x36)> into two groups gives a list
1691620040C<(0x6, 0x3)>; breaking it into 4 groups gives C<(0x2, 0x1, 0x3, 0x0)>.
1691720041
1691820042=end original
1691920043
1692020044BITS が 4 以下の場合、文字列はバイトに分解され、バイトの各ビットは
16921200458/BITS 個のグループに分割されます。
1692220046ビットはリトルエンディアン風に、C<0x01>, C<0x02>,
1692320047C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80> の順になります。
1692420048例えば、入力バイト C<chr(0x36)> を二つのグループに分割すると、
16925C<(0x6, 0x3)> になります
20049C<(0x6, 0x3)> になります; 4 つに分割すると C<(0x2, 0x1, 0x3, 0x0)> に
169264 つに分割すると C<(0x2, 0x1, 0x3, 0x0)> になります。
20050なります。
1692720051
1692820052=begin original
1692920053
16930C<vec> may also be assigned to, in which case parentheses are needed
20054L<C<vec>|/vec EXPR,OFFSET,BITS> may also be assigned to, in which case
20055parentheses are needed
1693120056to give the expression the correct precedence as in
1693220057
1693320058=end original
1693420059
16935左辺値として、代入の対象にすることもできます。
20060L<C<vec>|/vec EXPR,OFFSET,BITS> は左辺値として、代入の
16936この場合、式を正しく先行させるために以下のように括弧が必要です。
20061対象にするともできます; この場合、式を正しく
20062先行させるために以下のように括弧が必要です:
1693720063
1693820064 vec($image, $max_x * $x + $y, 8) = 3;
1693920065
1694020066=begin original
1694120067
1694220068If the selected element is outside the string, the value 0 is returned.
1694320069If an element off the end of the string is written to, Perl will first
1694420070extend the string with sufficiently many zero bytes. It is an error
1694520071to try to write off the beginning of the string (i.e., negative OFFSET).
1694620072
1694720073=end original
1694820074
1694920075選択された要素が文字列の外側だった場合、値 0 が返されます。
1695020076文字列の最後よりも後ろの要素に書き込もうとした場合、
1695120077Perl はまず文字列を必要な分だけ 0 のバイトで拡張します。
1695220078文字列の先頭より前に書き込もうとした(つまり OFFSET が負の数だった)
1695320079場合はエラーとなります。
1695420080
1695520081=begin original
1695620082
1695720083If the string happens to be encoded as UTF-8 internally (and thus has
16958the UTF8 flag set), this is ignored by C<vec>, and it operates on the
20084the UTF8 flag set), this is ignored by L<C<vec>|/vec EXPR,OFFSET,BITS>,
20085and it operates on the
1695920086internal byte string, not the conceptual character string, even if you
16960only have characters with values less than 256.
20087only have characters with values less than 256.
1696120088
1696220089=end original
1696320090
1696420091文字列がなぜか内部で UTF-8 でエンコードされている場合(したがって UTF8 フラグが
16965セットされている場合)、これは C<vec> では無視され、たとえ値が 256 未満の
20092セットされている場合)、これは L<C<vec>|/vec EXPR,OFFSET,BITS> では無視され、
16966文字だけであったとしても、概念的な
20093たとえ値が 256 未満の文字だけであったとしても、概念的な文字列ではなく
16967文字列ではなく内部バイト文字列で操作されます。
20094内部バイト文字列で操作されます。
1696820095
1696920096=begin original
1697020097
16971Strings created with C<vec> can also be manipulated with the logical
20098Strings created with L<C<vec>|/vec EXPR,OFFSET,BITS> can also be
20099manipulated with the logical
1697220100operators C<|>, C<&>, C<^>, and C<~>. These operators will assume a bit
1697320101vector operation is desired when both operands are strings.
1697420102See L<perlop/"Bitwise String Operators">.
1697520103
1697620104=end original
1697720105
16978C<vec> で作られた文字列は、論理演算子 C<|>、C<&>、C<^> で
20106L<C<vec>|/vec EXPR,OFFSET,BITS> で作られた文字列は、論理演算子 C<|>、C<&>、
16979扱うこともできます。
20107C<^>, C<~> で扱うこともできます。
1698020108これらの演算子は、両方の被演算子に文字列を使うと、
1698120109ビットベクター演算を行ないます。
1698220110L<perlop/"Bitwise String Operators"> を参照してください。
1698320111
1698420112=begin original
1698520113
1698620114The following code will build up an ASCII string saying C<'PerlPerlPerl'>.
1698720115The comments show the string after each step. Note that this code works
1698820116in the same way on big-endian or little-endian machines.
1698920117
1699020118=end original
1699120119
1699220120次のコードは C<'PerlPerlPerl'> という ASCII 文字列を作成します。
1699320121コメントは各行の実行後の文字列を示します。
1699420122このコードはビッグエンディアンでもリトルエンディアンでも同じように
1699520123動作することに注意してください。
1699620124
1699720125 my $foo = '';
1699820126 vec($foo, 0, 32) = 0x5065726C; # 'Perl'
1699920127
1700020128 # $foo eq "Perl" eq "\x50\x65\x72\x6C", 32 bits
1700120129 print vec($foo, 0, 8); # prints 80 == 0x50 == ord('P')
1700220130
1700320131 vec($foo, 2, 16) = 0x5065; # 'PerlPe'
1700420132 vec($foo, 3, 16) = 0x726C; # 'PerlPerl'
1700520133 vec($foo, 8, 8) = 0x50; # 'PerlPerlP'
1700620134 vec($foo, 9, 8) = 0x65; # 'PerlPerlPe'
1700720135 vec($foo, 20, 4) = 2; # 'PerlPerlPe' . "\x02"
1700820136 vec($foo, 21, 4) = 7; # 'PerlPerlPer'
1700920137 # 'r' is "\x72"
1701020138 vec($foo, 45, 2) = 3; # 'PerlPerlPer' . "\x0c"
1701120139 vec($foo, 93, 1) = 1; # 'PerlPerlPer' . "\x2c"
1701220140 vec($foo, 94, 1) = 1; # 'PerlPerlPerl'
1701320141 # 'l' is "\x6c"
1701420142
1701520143=begin original
1701620144
1701720145To transform a bit vector into a string or list of 0's and 1's, use these:
1701820146
1701920147=end original
1702020148
1702120149ビットベクターを、0 と 1 の文字列や配列に変換するには、
1702220150以下のようにします。
1702320151
17024 $bits = unpack("b*", $vector);
20152 my $bits = unpack("b*", $vector);
17025 @bits = split(//, unpack("b*", $vector));
20153 my @bits = split(//, unpack("b*", $vector));
1702620154
1702720155=begin original
1702820156
1702920157If you know the exact length in bits, it can be used in place of the C<*>.
1703020158
1703120159=end original
1703220160
17033ビット長が分かっていれば、* の代わりにその長さを使うことができます。
20161ビット長が分かっていれば、C<*> の代わりにその長さを使うことができます。
1703420162
1703520163=begin original
1703620164
1703720165Here is an example to illustrate how the bits actually fall in place:
1703820166
1703920167=end original
1704020168
1704120169これはビットが実際にどのような位置に入るかを図示する例です。
1704220170
17043 #!/usr/bin/perl -wl
20171 #!/usr/bin/perl -wl
1704420172
17045 print <<'EOT';
20173 print <<'EOT';
17046 0 1 2 3
20174 0 1 2 3
17047 unpack("V",$_) 01234567890123456789012345678901
20175 unpack("V",$_) 01234567890123456789012345678901
17048 ------------------------------------------------------------------
20176 ------------------------------------------------------------------
17049 EOT
20177 EOT
1705020178
17051 for $w (0..3) {
20179 for $w (0..3) {
17052 $width = 2**$w;
20180 $width = 2**$w;
17053 for ($shift=0; $shift < $width; ++$shift) {
20181 for ($shift=0; $shift < $width; ++$shift) {
17054 for ($off=0; $off < 32/$width; ++$off) {
20182 for ($off=0; $off < 32/$width; ++$off) {
17055 $str = pack("B*", "0"x32);
20183 $str = pack("B*", "0"x32);
17056 $bits = (1<<$shift);
20184 $bits = (1<<$shift);
17057 vec($str, $off, $width) = $bits;
20185 vec($str, $off, $width) = $bits;
17058 $res = unpack("b*",$str);
20186 $res = unpack("b*",$str);
17059 $val = unpack("V", $str);
20187 $val = unpack("V", $str);
17060 write;
20188 write;
17061 }
20189 }
17062 }
20190 }
17063 }
20191 }
1706420192
17065 format STDOUT =
20193 format STDOUT =
17066 vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
20194 vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
17067 $off, $width, $bits, $val, $res
20195 $off, $width, $bits, $val, $res
17068 .
20196 .
17069 __END__
20197 __END__
1707020198
1707120199=begin original
1707220200
17073Regardless of the machine architecture on which it runs, the
20201Regardless of the machine architecture on which it runs, the
1707420202example above should print the following table:
1707520203
1707620204=end original
1707720205
1707820206実行するマシンのアーキテクチャに関わらず、
1707920207上記の例は以下の表を出力します。
1708020208
17081 0 1 2 3
20209 0 1 2 3
17082 unpack("V",$_) 01234567890123456789012345678901
20210 unpack("V",$_) 01234567890123456789012345678901
17083 ------------------------------------------------------------------
20211 ------------------------------------------------------------------
17084 vec($_, 0, 1) = 1 == 1 10000000000000000000000000000000
20212 vec($_, 0, 1) = 1 == 1 10000000000000000000000000000000
17085 vec($_, 1, 1) = 1 == 2 01000000000000000000000000000000
20213 vec($_, 1, 1) = 1 == 2 01000000000000000000000000000000
17086 vec($_, 2, 1) = 1 == 4 00100000000000000000000000000000
20214 vec($_, 2, 1) = 1 == 4 00100000000000000000000000000000
17087 vec($_, 3, 1) = 1 == 8 00010000000000000000000000000000
20215 vec($_, 3, 1) = 1 == 8 00010000000000000000000000000000
17088 vec($_, 4, 1) = 1 == 16 00001000000000000000000000000000
20216 vec($_, 4, 1) = 1 == 16 00001000000000000000000000000000
17089 vec($_, 5, 1) = 1 == 32 00000100000000000000000000000000
20217 vec($_, 5, 1) = 1 == 32 00000100000000000000000000000000
17090 vec($_, 6, 1) = 1 == 64 00000010000000000000000000000000
20218 vec($_, 6, 1) = 1 == 64 00000010000000000000000000000000
17091 vec($_, 7, 1) = 1 == 128 00000001000000000000000000000000
20219 vec($_, 7, 1) = 1 == 128 00000001000000000000000000000000
17092 vec($_, 8, 1) = 1 == 256 00000000100000000000000000000000
20220 vec($_, 8, 1) = 1 == 256 00000000100000000000000000000000
17093 vec($_, 9, 1) = 1 == 512 00000000010000000000000000000000
20221 vec($_, 9, 1) = 1 == 512 00000000010000000000000000000000
17094 vec($_,10, 1) = 1 == 1024 00000000001000000000000000000000
20222 vec($_,10, 1) = 1 == 1024 00000000001000000000000000000000
17095 vec($_,11, 1) = 1 == 2048 00000000000100000000000000000000
20223 vec($_,11, 1) = 1 == 2048 00000000000100000000000000000000
17096 vec($_,12, 1) = 1 == 4096 00000000000010000000000000000000
20224 vec($_,12, 1) = 1 == 4096 00000000000010000000000000000000
17097 vec($_,13, 1) = 1 == 8192 00000000000001000000000000000000
20225 vec($_,13, 1) = 1 == 8192 00000000000001000000000000000000
17098 vec($_,14, 1) = 1 == 16384 00000000000000100000000000000000
20226 vec($_,14, 1) = 1 == 16384 00000000000000100000000000000000
17099 vec($_,15, 1) = 1 == 32768 00000000000000010000000000000000
20227 vec($_,15, 1) = 1 == 32768 00000000000000010000000000000000
17100 vec($_,16, 1) = 1 == 65536 00000000000000001000000000000000
20228 vec($_,16, 1) = 1 == 65536 00000000000000001000000000000000
17101 vec($_,17, 1) = 1 == 131072 00000000000000000100000000000000
20229 vec($_,17, 1) = 1 == 131072 00000000000000000100000000000000
17102 vec($_,18, 1) = 1 == 262144 00000000000000000010000000000000
20230 vec($_,18, 1) = 1 == 262144 00000000000000000010000000000000
17103 vec($_,19, 1) = 1 == 524288 00000000000000000001000000000000
20231 vec($_,19, 1) = 1 == 524288 00000000000000000001000000000000
17104 vec($_,20, 1) = 1 == 1048576 00000000000000000000100000000000
20232 vec($_,20, 1) = 1 == 1048576 00000000000000000000100000000000
17105 vec($_,21, 1) = 1 == 2097152 00000000000000000000010000000000
20233 vec($_,21, 1) = 1 == 2097152 00000000000000000000010000000000
17106 vec($_,22, 1) = 1 == 4194304 00000000000000000000001000000000
20234 vec($_,22, 1) = 1 == 4194304 00000000000000000000001000000000
17107 vec($_,23, 1) = 1 == 8388608 00000000000000000000000100000000
20235 vec($_,23, 1) = 1 == 8388608 00000000000000000000000100000000
17108 vec($_,24, 1) = 1 == 16777216 00000000000000000000000010000000
20236 vec($_,24, 1) = 1 == 16777216 00000000000000000000000010000000
17109 vec($_,25, 1) = 1 == 33554432 00000000000000000000000001000000
20237 vec($_,25, 1) = 1 == 33554432 00000000000000000000000001000000
17110 vec($_,26, 1) = 1 == 67108864 00000000000000000000000000100000
20238 vec($_,26, 1) = 1 == 67108864 00000000000000000000000000100000
17111 vec($_,27, 1) = 1 == 134217728 00000000000000000000000000010000
20239 vec($_,27, 1) = 1 == 134217728 00000000000000000000000000010000
17112 vec($_,28, 1) = 1 == 268435456 00000000000000000000000000001000
20240 vec($_,28, 1) = 1 == 268435456 00000000000000000000000000001000
17113 vec($_,29, 1) = 1 == 536870912 00000000000000000000000000000100
20241 vec($_,29, 1) = 1 == 536870912 00000000000000000000000000000100
17114 vec($_,30, 1) = 1 == 1073741824 00000000000000000000000000000010
20242 vec($_,30, 1) = 1 == 1073741824 00000000000000000000000000000010
17115 vec($_,31, 1) = 1 == 2147483648 00000000000000000000000000000001
20243 vec($_,31, 1) = 1 == 2147483648 00000000000000000000000000000001
17116 vec($_, 0, 2) = 1 == 1 10000000000000000000000000000000
20244 vec($_, 0, 2) = 1 == 1 10000000000000000000000000000000
17117 vec($_, 1, 2) = 1 == 4 00100000000000000000000000000000
20245 vec($_, 1, 2) = 1 == 4 00100000000000000000000000000000
17118 vec($_, 2, 2) = 1 == 16 00001000000000000000000000000000
20246 vec($_, 2, 2) = 1 == 16 00001000000000000000000000000000
17119 vec($_, 3, 2) = 1 == 64 00000010000000000000000000000000
20247 vec($_, 3, 2) = 1 == 64 00000010000000000000000000000000
17120 vec($_, 4, 2) = 1 == 256 00000000100000000000000000000000
20248 vec($_, 4, 2) = 1 == 256 00000000100000000000000000000000
17121 vec($_, 5, 2) = 1 == 1024 00000000001000000000000000000000
20249 vec($_, 5, 2) = 1 == 1024 00000000001000000000000000000000
17122 vec($_, 6, 2) = 1 == 4096 00000000000010000000000000000000
20250 vec($_, 6, 2) = 1 == 4096 00000000000010000000000000000000
17123 vec($_, 7, 2) = 1 == 16384 00000000000000100000000000000000
20251 vec($_, 7, 2) = 1 == 16384 00000000000000100000000000000000
17124 vec($_, 8, 2) = 1 == 65536 00000000000000001000000000000000
20252 vec($_, 8, 2) = 1 == 65536 00000000000000001000000000000000
17125 vec($_, 9, 2) = 1 == 262144 00000000000000000010000000000000
20253 vec($_, 9, 2) = 1 == 262144 00000000000000000010000000000000
17126 vec($_,10, 2) = 1 == 1048576 00000000000000000000100000000000
20254 vec($_,10, 2) = 1 == 1048576 00000000000000000000100000000000
17127 vec($_,11, 2) = 1 == 4194304 00000000000000000000001000000000
20255 vec($_,11, 2) = 1 == 4194304 00000000000000000000001000000000
17128 vec($_,12, 2) = 1 == 16777216 00000000000000000000000010000000
20256 vec($_,12, 2) = 1 == 16777216 00000000000000000000000010000000
17129 vec($_,13, 2) = 1 == 67108864 00000000000000000000000000100000
20257 vec($_,13, 2) = 1 == 67108864 00000000000000000000000000100000
17130 vec($_,14, 2) = 1 == 268435456 00000000000000000000000000001000
20258 vec($_,14, 2) = 1 == 268435456 00000000000000000000000000001000
17131 vec($_,15, 2) = 1 == 1073741824 00000000000000000000000000000010
20259 vec($_,15, 2) = 1 == 1073741824 00000000000000000000000000000010
17132 vec($_, 0, 2) = 2 == 2 01000000000000000000000000000000
20260 vec($_, 0, 2) = 2 == 2 01000000000000000000000000000000
17133 vec($_, 1, 2) = 2 == 8 00010000000000000000000000000000
20261 vec($_, 1, 2) = 2 == 8 00010000000000000000000000000000
17134 vec($_, 2, 2) = 2 == 32 00000100000000000000000000000000
20262 vec($_, 2, 2) = 2 == 32 00000100000000000000000000000000
17135 vec($_, 3, 2) = 2 == 128 00000001000000000000000000000000
20263 vec($_, 3, 2) = 2 == 128 00000001000000000000000000000000
17136 vec($_, 4, 2) = 2 == 512 00000000010000000000000000000000
20264 vec($_, 4, 2) = 2 == 512 00000000010000000000000000000000
17137 vec($_, 5, 2) = 2 == 2048 00000000000100000000000000000000
20265 vec($_, 5, 2) = 2 == 2048 00000000000100000000000000000000
17138 vec($_, 6, 2) = 2 == 8192 00000000000001000000000000000000
20266 vec($_, 6, 2) = 2 == 8192 00000000000001000000000000000000
17139 vec($_, 7, 2) = 2 == 32768 00000000000000010000000000000000
20267 vec($_, 7, 2) = 2 == 32768 00000000000000010000000000000000
17140 vec($_, 8, 2) = 2 == 131072 00000000000000000100000000000000
20268 vec($_, 8, 2) = 2 == 131072 00000000000000000100000000000000
17141 vec($_, 9, 2) = 2 == 524288 00000000000000000001000000000000
20269 vec($_, 9, 2) = 2 == 524288 00000000000000000001000000000000
17142 vec($_,10, 2) = 2 == 2097152 00000000000000000000010000000000
20270 vec($_,10, 2) = 2 == 2097152 00000000000000000000010000000000
17143 vec($_,11, 2) = 2 == 8388608 00000000000000000000000100000000
20271 vec($_,11, 2) = 2 == 8388608 00000000000000000000000100000000
17144 vec($_,12, 2) = 2 == 33554432 00000000000000000000000001000000
20272 vec($_,12, 2) = 2 == 33554432 00000000000000000000000001000000
17145 vec($_,13, 2) = 2 == 134217728 00000000000000000000000000010000
20273 vec($_,13, 2) = 2 == 134217728 00000000000000000000000000010000
17146 vec($_,14, 2) = 2 == 536870912 00000000000000000000000000000100
20274 vec($_,14, 2) = 2 == 536870912 00000000000000000000000000000100
17147 vec($_,15, 2) = 2 == 2147483648 00000000000000000000000000000001
20275 vec($_,15, 2) = 2 == 2147483648 00000000000000000000000000000001
17148 vec($_, 0, 4) = 1 == 1 10000000000000000000000000000000
20276 vec($_, 0, 4) = 1 == 1 10000000000000000000000000000000
17149 vec($_, 1, 4) = 1 == 16 00001000000000000000000000000000
20277 vec($_, 1, 4) = 1 == 16 00001000000000000000000000000000
17150 vec($_, 2, 4) = 1 == 256 00000000100000000000000000000000
20278 vec($_, 2, 4) = 1 == 256 00000000100000000000000000000000
17151 vec($_, 3, 4) = 1 == 4096 00000000000010000000000000000000
20279 vec($_, 3, 4) = 1 == 4096 00000000000010000000000000000000
17152 vec($_, 4, 4) = 1 == 65536 00000000000000001000000000000000
20280 vec($_, 4, 4) = 1 == 65536 00000000000000001000000000000000
17153 vec($_, 5, 4) = 1 == 1048576 00000000000000000000100000000000
20281 vec($_, 5, 4) = 1 == 1048576 00000000000000000000100000000000
17154 vec($_, 6, 4) = 1 == 16777216 00000000000000000000000010000000
20282 vec($_, 6, 4) = 1 == 16777216 00000000000000000000000010000000
17155 vec($_, 7, 4) = 1 == 268435456 00000000000000000000000000001000
20283 vec($_, 7, 4) = 1 == 268435456 00000000000000000000000000001000
17156 vec($_, 0, 4) = 2 == 2 01000000000000000000000000000000
20284 vec($_, 0, 4) = 2 == 2 01000000000000000000000000000000
17157 vec($_, 1, 4) = 2 == 32 00000100000000000000000000000000
20285 vec($_, 1, 4) = 2 == 32 00000100000000000000000000000000
17158 vec($_, 2, 4) = 2 == 512 00000000010000000000000000000000
20286 vec($_, 2, 4) = 2 == 512 00000000010000000000000000000000
17159 vec($_, 3, 4) = 2 == 8192 00000000000001000000000000000000
20287 vec($_, 3, 4) = 2 == 8192 00000000000001000000000000000000
17160 vec($_, 4, 4) = 2 == 131072 00000000000000000100000000000000
20288 vec($_, 4, 4) = 2 == 131072 00000000000000000100000000000000
17161 vec($_, 5, 4) = 2 == 2097152 00000000000000000000010000000000
20289 vec($_, 5, 4) = 2 == 2097152 00000000000000000000010000000000
17162 vec($_, 6, 4) = 2 == 33554432 00000000000000000000000001000000
20290 vec($_, 6, 4) = 2 == 33554432 00000000000000000000000001000000
17163 vec($_, 7, 4) = 2 == 536870912 00000000000000000000000000000100
20291 vec($_, 7, 4) = 2 == 536870912 00000000000000000000000000000100
17164 vec($_, 0, 4) = 4 == 4 00100000000000000000000000000000
20292 vec($_, 0, 4) = 4 == 4 00100000000000000000000000000000
17165 vec($_, 1, 4) = 4 == 64 00000010000000000000000000000000
20293 vec($_, 1, 4) = 4 == 64 00000010000000000000000000000000
17166 vec($_, 2, 4) = 4 == 1024 00000000001000000000000000000000
20294 vec($_, 2, 4) = 4 == 1024 00000000001000000000000000000000
17167 vec($_, 3, 4) = 4 == 16384 00000000000000100000000000000000
20295 vec($_, 3, 4) = 4 == 16384 00000000000000100000000000000000
17168 vec($_, 4, 4) = 4 == 262144 00000000000000000010000000000000
20296 vec($_, 4, 4) = 4 == 262144 00000000000000000010000000000000
17169 vec($_, 5, 4) = 4 == 4194304 00000000000000000000001000000000
20297 vec($_, 5, 4) = 4 == 4194304 00000000000000000000001000000000
17170 vec($_, 6, 4) = 4 == 67108864 00000000000000000000000000100000
20298 vec($_, 6, 4) = 4 == 67108864 00000000000000000000000000100000
17171 vec($_, 7, 4) = 4 == 1073741824 00000000000000000000000000000010
20299 vec($_, 7, 4) = 4 == 1073741824 00000000000000000000000000000010
17172 vec($_, 0, 4) = 8 == 8 00010000000000000000000000000000
20300 vec($_, 0, 4) = 8 == 8 00010000000000000000000000000000
17173 vec($_, 1, 4) = 8 == 128 00000001000000000000000000000000
20301 vec($_, 1, 4) = 8 == 128 00000001000000000000000000000000
17174 vec($_, 2, 4) = 8 == 2048 00000000000100000000000000000000
20302 vec($_, 2, 4) = 8 == 2048 00000000000100000000000000000000
17175 vec($_, 3, 4) = 8 == 32768 00000000000000010000000000000000
20303 vec($_, 3, 4) = 8 == 32768 00000000000000010000000000000000
17176 vec($_, 4, 4) = 8 == 524288 00000000000000000001000000000000
20304 vec($_, 4, 4) = 8 == 524288 00000000000000000001000000000000
17177 vec($_, 5, 4) = 8 == 8388608 00000000000000000000000100000000
20305 vec($_, 5, 4) = 8 == 8388608 00000000000000000000000100000000
17178 vec($_, 6, 4) = 8 == 134217728 00000000000000000000000000010000
20306 vec($_, 6, 4) = 8 == 134217728 00000000000000000000000000010000
17179 vec($_, 7, 4) = 8 == 2147483648 00000000000000000000000000000001
20307 vec($_, 7, 4) = 8 == 2147483648 00000000000000000000000000000001
17180 vec($_, 0, 8) = 1 == 1 10000000000000000000000000000000
20308 vec($_, 0, 8) = 1 == 1 10000000000000000000000000000000
17181 vec($_, 1, 8) = 1 == 256 00000000100000000000000000000000
20309 vec($_, 1, 8) = 1 == 256 00000000100000000000000000000000
17182 vec($_, 2, 8) = 1 == 65536 00000000000000001000000000000000
20310 vec($_, 2, 8) = 1 == 65536 00000000000000001000000000000000
17183 vec($_, 3, 8) = 1 == 16777216 00000000000000000000000010000000
20311 vec($_, 3, 8) = 1 == 16777216 00000000000000000000000010000000
17184 vec($_, 0, 8) = 2 == 2 01000000000000000000000000000000
20312 vec($_, 0, 8) = 2 == 2 01000000000000000000000000000000
17185 vec($_, 1, 8) = 2 == 512 00000000010000000000000000000000
20313 vec($_, 1, 8) = 2 == 512 00000000010000000000000000000000
17186 vec($_, 2, 8) = 2 == 131072 00000000000000000100000000000000
20314 vec($_, 2, 8) = 2 == 131072 00000000000000000100000000000000
17187 vec($_, 3, 8) = 2 == 33554432 00000000000000000000000001000000
20315 vec($_, 3, 8) = 2 == 33554432 00000000000000000000000001000000
17188 vec($_, 0, 8) = 4 == 4 00100000000000000000000000000000
20316 vec($_, 0, 8) = 4 == 4 00100000000000000000000000000000
17189 vec($_, 1, 8) = 4 == 1024 00000000001000000000000000000000
20317 vec($_, 1, 8) = 4 == 1024 00000000001000000000000000000000
17190 vec($_, 2, 8) = 4 == 262144 00000000000000000010000000000000
20318 vec($_, 2, 8) = 4 == 262144 00000000000000000010000000000000
17191 vec($_, 3, 8) = 4 == 67108864 00000000000000000000000000100000
20319 vec($_, 3, 8) = 4 == 67108864 00000000000000000000000000100000
17192 vec($_, 0, 8) = 8 == 8 00010000000000000000000000000000
20320 vec($_, 0, 8) = 8 == 8 00010000000000000000000000000000
17193 vec($_, 1, 8) = 8 == 2048 00000000000100000000000000000000
20321 vec($_, 1, 8) = 8 == 2048 00000000000100000000000000000000
17194 vec($_, 2, 8) = 8 == 524288 00000000000000000001000000000000
20322 vec($_, 2, 8) = 8 == 524288 00000000000000000001000000000000
17195 vec($_, 3, 8) = 8 == 134217728 00000000000000000000000000010000
20323 vec($_, 3, 8) = 8 == 134217728 00000000000000000000000000010000
17196 vec($_, 0, 8) = 16 == 16 00001000000000000000000000000000
20324 vec($_, 0, 8) = 16 == 16 00001000000000000000000000000000
17197 vec($_, 1, 8) = 16 == 4096 00000000000010000000000000000000
20325 vec($_, 1, 8) = 16 == 4096 00000000000010000000000000000000
17198 vec($_, 2, 8) = 16 == 1048576 00000000000000000000100000000000
20326 vec($_, 2, 8) = 16 == 1048576 00000000000000000000100000000000
17199 vec($_, 3, 8) = 16 == 268435456 00000000000000000000000000001000
20327 vec($_, 3, 8) = 16 == 268435456 00000000000000000000000000001000
17200 vec($_, 0, 8) = 32 == 32 00000100000000000000000000000000
20328 vec($_, 0, 8) = 32 == 32 00000100000000000000000000000000
17201 vec($_, 1, 8) = 32 == 8192 00000000000001000000000000000000
20329 vec($_, 1, 8) = 32 == 8192 00000000000001000000000000000000
17202 vec($_, 2, 8) = 32 == 2097152 00000000000000000000010000000000
20330 vec($_, 2, 8) = 32 == 2097152 00000000000000000000010000000000
17203 vec($_, 3, 8) = 32 == 536870912 00000000000000000000000000000100
20331 vec($_, 3, 8) = 32 == 536870912 00000000000000000000000000000100
17204 vec($_, 0, 8) = 64 == 64 00000010000000000000000000000000
20332 vec($_, 0, 8) = 64 == 64 00000010000000000000000000000000
17205 vec($_, 1, 8) = 64 == 16384 00000000000000100000000000000000
20333 vec($_, 1, 8) = 64 == 16384 00000000000000100000000000000000
17206 vec($_, 2, 8) = 64 == 4194304 00000000000000000000001000000000
20334 vec($_, 2, 8) = 64 == 4194304 00000000000000000000001000000000
17207 vec($_, 3, 8) = 64 == 1073741824 00000000000000000000000000000010
20335 vec($_, 3, 8) = 64 == 1073741824 00000000000000000000000000000010
17208 vec($_, 0, 8) = 128 == 128 00000001000000000000000000000000
20336 vec($_, 0, 8) = 128 == 128 00000001000000000000000000000000
17209 vec($_, 1, 8) = 128 == 32768 00000000000000010000000000000000
20337 vec($_, 1, 8) = 128 == 32768 00000000000000010000000000000000
17210 vec($_, 2, 8) = 128 == 8388608 00000000000000000000000100000000
20338 vec($_, 2, 8) = 128 == 8388608 00000000000000000000000100000000
17211 vec($_, 3, 8) = 128 == 2147483648 00000000000000000000000000000001
20339 vec($_, 3, 8) = 128 == 2147483648 00000000000000000000000000000001
1721220340
1721320341=item wait
1721420342X<wait>
1721520343
20344=for Pod::Functions wait for any child process to die
20345
1721620346=begin original
1721720347
17218Behaves like wait(2) on your system: it waits for a child
20348Behaves like L<wait(2)> on your system: it waits for a child
1721920349process to terminate and returns the pid of the deceased process, or
17220C<-1> if there are no child processes. The status is returned in C<$?>
20350C<-1> if there are no child processes. The status is returned in
17221and C<${^CHILD_ERROR_NATIVE}>.
20351L<C<$?>|perlvar/$?> and
20352L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>.
1722220353Note that a return value of C<-1> could mean that child processes are
1722320354being automatically reaped, as described in L<perlipc>.
1722420355
1722520356=end original
1722620357
17227wait(2) と同様に振る舞います
20358L<wait(2)> と同様に振る舞います: チャイルドプロセスが終了するのを待ち、
17228チャイルドプロセスが終了するのを待ち、消滅したプロセスの pid を返します
20359消滅したプロセスの pid を返します; チャイルドプロセスが存在しないときには、
17229チャイルドプロセスが存在しないときには、C<-1> を返します。
20360C<-1> を返します。
17230ステータスは C<$?> と C<${^CHILD_ERROR_NATIVE}> に返されます。
20361ステータスは L<C<$?>|perlvar/$?>
20362L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に返されます。
1723120363L<perlipc> に書いているように、返り値が C<-1> の場合は子プロセスが
1723220364自動的に刈り取られたことを意味するかもしれないことに注意してください。
1723320365
1723420366=begin original
1723520367
17236If you use wait in your handler for $SIG{CHLD} it may accidentally for the
20368If you use L<C<wait>|/wait> in your handler for
17237child created by qx() or system(). See L<perlipc> for details.
20369L<C<$SIG{CHLD}>|perlvar/%SIG>, it may accidentally wait for the child
20370created by L<C<qx>|/qxE<sol>STRINGE<sol>> or L<C<system>|/system LIST>.
20371See L<perlipc> for details.
1723820372
1723920373=end original
1724020374
17241wait を $SIG{CHLD} のハンドラで使うと、誤って qx() や system() に
20375L<C<wait>|/wait>L<C<$SIG{CHLD}>|perlvar/%SIG> のハンドラで使うと、誤って
17242適用されるかも知れません。
20376L<C<qx>|/qxE<sol>STRINGE<sol>> や L<C<system>|/system LIST> によって
20377作られた子を待つことになるかも知れません。
1724320378詳しくは L<perlipc> を参照してください。
1724420379
20380=begin original
20381
20382Portability issues: L<perlport/wait>.
20383
20384=end original
20385
20386移植性の問題: L<perlport/wait>。
20387
1724520388=item waitpid PID,FLAGS
1724620389X<waitpid>
1724720390
20391=for Pod::Functions wait for a particular child process to die
20392
1724820393=begin original
1724920394
1725020395Waits for a particular child process to terminate and returns the pid of
17251the deceased process, or C<-1> if there is no such child process. On some
20396the deceased process, or C<-1> if there is no such child process. A
17252systems, a value of 0 indicates that there are processes still running.
20397non-blocking wait (with L<WNOHANG|POSIX/C<WNOHANG>> in FLAGS) can return 0 if
17253The status is returned in C<$?> and C<${^CHILD_ERROR_NATIVE}>. If you say
20398there are child processes matching PID but none have terminated yet.
20399The status is returned in L<C<$?>|perlvar/$?> and
20400L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>.
1725420401
1725520402=end original
1725620403
17257特定のチャイルドプロセスが終了するのを待ち、消滅した
20404特定のプロセスが終了するのを待ち、消滅したプロセスの pid を
17258プロセスの pid を返します。
20405返します; 指定した子プロセスが存在しないときには、C<-1> を返します。
17259指定したチャイルドプロセスが存在しないときは、C<-1> をます。
20406(FLAGS L<WNOHANG|POSIX/C<WNOHANG>>指定た) 非ブロッキング wait は、
17260 0 がプロセスがまだ実行中であること示すシステムもあります。
20407PIDマッチングする子プロセスがいてもまだ終了していない場合に 0
17261ステータスは C<$?> と C<${^CHILD_ERROR_NATIVE}> にされます。
20408すことがあります。
20409ステータスは L<C<$?>|perlvar/$?> と
20410L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に返されます。
1726220411
20412=begin original
20413
20414A PID of C<0> indicates to wait for any child process whose process group ID is
20415equal to that of the current process. A PID of less than C<-1> indicates to
20416wait for any child process whose process group ID is equal to -PID. A PID of
20417C<-1> indicates to wait for any child process.
20418
20419=end original
20420
20421PID に C<0> を指定すると、プロセスグループ ID が現在のプロセスと同じである
20422任意の子プロセスを wait します。
20423PID に C<-1> 以下を指定すると、プロセスグループ ID が -PID に等しい
20424任意の子プロセスを wait します。
20425PID に C<-1> を指定すると任意の子プロセスを wait します。
20426
20427=begin original
20428
20429If you say
20430
20431=end original
20432
20433以下のようにするか
20434
1726320435 use POSIX ":sys_wait_h";
17264 #...
20437 my $kid;
1726520438 do {
1726620439 $kid = waitpid(-1, WNOHANG);
1726720440 } while $kid > 0;
1726820441
1726920442=begin original
1727020443
17271then you can do a non-blocking wait for all pending zombie processes.
20444or
20445
20446=end original
20447
20448または
20449
20450 1 while waitpid(-1, WNOHANG) > 0;
20451
20452=begin original
20453
20454then you can do a non-blocking wait for all pending zombie processes (see
20455L<POSIX/WAIT>).
1727220456Non-blocking wait is available on machines supporting either the
17273waitpid(2) or wait4(2) syscalls. However, waiting for a particular
20457L<waitpid(2)> or L<wait4(2)> syscalls. However, waiting for a particular
1727420458pid with FLAGS of C<0> is implemented everywhere. (Perl emulates the
1727520459system call by remembering the status values of processes that have
1727620460exited but have not been harvested by the Perl script yet.)
1727720461
1727820462=end original
1727920463
1728020464とすると、ブロックが起こらないようにして、全ての待機中ゾンビプロセスを
17281wait します。
20465wait します (L<POSIX/WAIT> を参照してください)
17282ブロックなしの wait は、システムコール wait_pid(2) か、
20466ブロックなしの wait は、システムコール L<wait_pid(2)> か、
17283システムコール wait4(2) をサポートしているマシンで利用可能です。
20467システムコール L<wait4(2)> をサポートしているマシンで利用可能です。
1728420468しかしながら、特定の pid を C<0> の FLAGS での wait はどこでも
1728520469実装されています。
1728620470(exit したプロセスのステータス値を覚えておいて、Perl がシステムコールを
1728720471エミュレートしますが、Perl スクリプトには取り入れられていません。)
1728820472
1728920473=begin original
1729020474
1729120475Note that on some systems, a return value of C<-1> could mean that child
1729220476processes are being automatically reaped. See L<perlipc> for details,
1729320477and for other examples.
1729420478
1729520479=end original
1729620480
1729720481システムによっては、返り値が C<-1> の場合は子プロセスが自動的に
1729820482刈り取られたことを意味するかもしれないことに注意してください。
1729920483詳細やその他の例については L<perlipc> を参照してください。
1730020484
20485=begin original
20486
20487Portability issues: L<perlport/waitpid>.
20488
20489=end original
20490
20491移植性の問題: L<perlport/waitpid>。
20492
1730120493=item wantarray
1730220494X<wantarray> X<context>
1730320495
20496=for Pod::Functions get void vs scalar vs list context of current subroutine call
20497
1730420498=begin original
1730520499
1730620500Returns true if the context of the currently executing subroutine or
17307C<eval> is looking for a list value. Returns false if the context is
20501L<C<eval>|/eval EXPR> is looking for a list value. Returns false if the
20502context is
1730820503looking for a scalar. Returns the undefined value if the context is
1730920504looking for no value (void context).
1731020505
1731120506=end original
1731220507
17313現在実行中のサブルーチンか eval() ブロックのコンテキストが、リスト値を
20508現在実行中のサブルーチンか L<C<eval>|/eval EXPR> ブロックのコンテキストが、
17314要求するものであれば、真を返します。
20509リスト値を要求するものであれば、真を返します。
1731520510スカラを要求するコンテキストであれば、偽を返します。
1731620511何も値を要求しない(無効コンテキスト)場合は未定義値を返します。
1731720512
1731820513 return unless defined wantarray; # don't bother doing more
1731920514 my @a = complex_calculation();
1732020515 return wantarray ? @a : "@a";
1732120516
1732220517=begin original
1732320518
17324C<wantarray()>'s result is unspecified in the top level of a file,
20519L<C<wantarray>|/wantarray>'s result is unspecified in the top level of a file,
1732520520in a C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT> or C<END> block, or
1732620521in a C<DESTROY> method.
1732720522
1732820523=end original
1732920524
1733020525ファイルのトップレベル、C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT>, C<END>
17331ブロック内、C<DESTROY> メソッド内では C<wantarray()> の結果は未定義です。
20526ブロック内、C<DESTROY> メソッド内では L<C<wantarray>|/wantarray> の結果は
20527未定義です。
1733220528
1733320529=begin original
1733420530
1733520531This function should have been named wantlist() instead.
1733620532
1733720533=end original
1733820534
1733920535この関数は wantlist() という名前にするべきでした。
1734020536
1734120537=item warn LIST
1734220538X<warn> X<warning> X<STDERR>
1734320539
20540=for Pod::Functions print debugging info
20541
1734420542=begin original
1734520543
1734620544Prints the value of LIST to STDERR. If the last element of LIST does
17347not end in a newline, it appends the same file/line number text as C<die>
20545not end in a newline, it appends the same file/line number text as
17348does.
20546L<C<die>|/die LIST> does.
1734920547
1735020548=end original
1735120549
1735220550LIST の値を STDERR に出力します。
17353LIST の最後の要素が改行で終わっていない場合、C<die> が行うのと同様の
20551LIST の最後の要素が改行で終わっていない場合、L<C<die>|/die LIST> が行うのと
17354ファイル/行番号のテキストが追加されます。
20552同様のファイル/行番号のテキストが追加されます。
1735520553
1735620554=begin original
1735720555
17358If the output is empty and C<$@> already contains a value (typically from a
20556If the output is empty and L<C<$@>|perlvar/$@> already contains a value
17359previous eval) that value is used after appending C<"\t...caught">
20557(typically from a previous eval) that value is used after appending
17360to C<$@>. This is useful for staying almost, but not entirely similar to
20558C<"\t...caught"> to L<C<$@>|perlvar/$@>. This is useful for staying
17361C<die>.
20559almost, but not entirely similar to L<C<die>|/die LIST>.
1736220560
1736320561=end original
1736420562
17365出力が空かつ、(典型的には以前の eval によって) C<$@> に既に値が入っている
20563出力が空かつ、(典型的には以前の eval によって) L<C<$@>|perlvar/$@> に既に値が
17366場合、C<$@> に C<"\t...caught"> を追加した値が用いられます。
20564入っている場合、L<C<$@>|perlvar/$@> に C<"\t...caught"> を追加した値が
20565用いられます。
1736720566これはほとんどそのままにするときに便利ですが、
17368C<die> と全体的に似ているわけではありません。
20567L<C<die>|/die LIST> と全体的に似ているわけではありません。
1736920568
1737020569=begin original
1737120570
17372If C<$@> is empty then the string C<"Warning: Something's wrong"> is used.
20571If L<C<$@>|perlvar/$@> is empty, then the string
20572C<"Warning: Something's wrong"> is used.
1737320573
1737420574=end original
1737520575
17376C<$@> が空の場合は、C<"Warning: Something's wrong"> という文字列が
20576L<C<$@>|perlvar/$@> が空の場合は、C<"Warning: Something's wrong"> という
17377使われます。
20577文字列が使われます。
1737820578
1737920579=begin original
1738020580
17381No message is printed if there is a C<$SIG{__WARN__}> handler
20581No message is printed if there is a L<C<$SIG{__WARN__}>|perlvar/%SIG>
20582handler
1738220583installed. It is the handler's responsibility to deal with the message
17383as it sees fit (like, for instance, converting it into a C<die>). Most
20584as it sees fit (like, for instance, converting it into a
20585L<C<die>|/die LIST>). Most
1738420586handlers must therefore arrange to actually display the
17385warnings that they are not prepared to deal with, by calling C<warn>
20587warnings that they are not prepared to deal with, by calling
20588L<C<warn>|/warn LIST>
1738620589again in the handler. Note that this is quite safe and will not
1738720590produce an endless loop, since C<__WARN__> hooks are not called from
1738820591inside one.
1738920592
1739020593=end original
1739120594
17392C<$SIG{__WARN__}> ハンドラが設定されている場合は何のメッセージも
20595L<C<$SIG{__WARN__}>|perlvar/%SIG> ハンドラが設定されている場合は何の
17393表示されません。
20596メッセージも表示されません。
17394メッセージをどう扱うか(例えば C<die> に変換するか)はハンドラの
20597メッセージをどう扱うか(例えば L<C<die>|/die LIST> に変換するか)はハンドラの
1739520598責任ということです。
1739620599従ってほとんどのハンドラは、扱おうと準備していない警告を表示するために、
17397ハンドラの中で C<warn> を再び呼び出します。
20600ハンドラの中で L<C<warn>|/warn LIST> を再び呼び出します。
1739820601C<__WARN__> フックはハンドラ内では呼び出されないので、これは十分安全で、
1739920602無限ループを引き起こすことはないということに注意してください。
1740020603
1740120604=begin original
1740220605
1740320606You will find this behavior is slightly different from that of
17404C<$SIG{__DIE__}> handlers (which don't suppress the error text, but can
20607L<C<$SIG{__DIE__}>|perlvar/%SIG> handlers (which don't suppress the
17405instead call C<die> again to change it).
20608error text, but can instead call L<C<die>|/die LIST> again to change
20609it).
1740620610
1740720611=end original
1740820612
17409この振る舞いは C<$SIG{__DIE__}> ハンドラ(エラーテキストは削除しませんが、
20613この振る舞いは L<C<$SIG{__DIE__}>|perlvar/%SIG> ハンドラ(エラーテキストは
17410代わりに C<die> をもう一度呼び出すことで変更できます)とは
20614削除しませんが、代わりに L<C<die>|/die LIST> をもう一度呼び出すことで
17411少し違うことに気付くことでしょう。
20615変更できます)とは少し違うことに気付くことでしょう。
1741220616
1741320617=begin original
1741420618
1741520619Using a C<__WARN__> handler provides a powerful way to silence all
1741620620warnings (even the so-called mandatory ones). An example:
1741720621
1741820622=end original
1741920623
1742020624C<__WARN__> ハンドラを使うと、(いわゆる必須のものを含む)全ての
1742120625警告を黙らせる強力な手段となります。
1742220626例:
1742320627
1742420628 # wipe out *all* compile-time warnings
1742520629 BEGIN { $SIG{'__WARN__'} = sub { warn $_[0] if $DOWARN } }
1742620630 my $foo = 10;
1742720631 my $foo = 20; # no warning about duplicate my $foo,
1742820632 # but hey, you asked for it!
1742920633 # no compile-time or run-time warnings before here
1743020634 $DOWARN = 1;
1743120635
1743220636 # run-time warnings enabled after here
1743320637 warn "\$foo is alive and $foo!"; # does show up
1743420638
1743520639=begin original
1743620640
17437See L<perlvar> for details on setting C<%SIG> entries and for more
20641See L<perlvar> for details on setting L<C<%SIG>|perlvar/%SIG> entries
17438examples. See the Carp module for other kinds of warnings using its
20642and for more
17439carp() and cluck() functions.
20643examples. See the L<Carp> module for other kinds of warnings using its
20644C<carp> and C<cluck> functions.
1744020645
1744120646=end original
1744220647
17443C<%SIG> エントリのセットに関する詳細とさらなる例に関しては
20648L<C<%SIG>|perlvar/%SIG> エントリのセットに関する詳細とさらなる例に関しては
17444L<perlvar> を参照してさい。
20649L<perlvar> を参照してください。
17445carp() 関数と cluck() 関数を用いた警告の方法に関しては
20650C<carp> 関数と C<cluck> 関数を用いた警告の方法に関しては
17446Carp モジュールを参照してさい。
20651L<Carp> モジュールを参照してください。
1744720652
17448=item when EXPR BLOCK
17449X<when>
17450
17451=item when BLOCK
17452
17453=begin original
17454
17455C<when> is analogous to the C<case> keyword in other languages. Used with a
17456C<foreach> loop or the experimental C<given> block, C<when> can be used in
17457Perl to implement C<switch>/C<case> like statements. Available as a
17458statement after Perl 5.10 and as a statement modifier after 5.14.
17459Here are three examples:
17460
17461=end original
17462
17463C<when> は他の言語での C<case> キーワードと似ています。
17464C<foreach> ループか実験的な C<given> で使って、C<when> は Perl で
17465C<switch>/C<case> 風の文を実装するのに使われます。
17466文としては Perl 5.10 から利用可能で、文修飾子としては 5.14 から
17467利用可能です。
17468以下に三つ例を示します:
17469
17470 use v5.10;
17471 foreach (@fruits) {
17472 when (/apples?/) {
17473 say "I like apples."
17474 }
17475 when (/oranges?/) {
17476 say "I don't like oranges."
17477 }
17478 default {
17479 say "I don't like anything"
17480 }
17481 }
17482
17483 # require 5.14 for when as statement modifier
17484 use v5.14;
17485 foreach (@fruits) {
17486 say "I like apples." when /apples?/;
17487 say "I don't like oranges." when /oranges?;
17488 default { say "I don't like anything" }
17489 }
17490
17491 use v5.10;
17492 given ($fruit) {
17493 when (/apples?/) {
17494 say "I like apples."
17495 }
17496 when (/oranges?/) {
17497 say "I don't like oranges."
17498 }
17499 default {
17500 say "I don't like anything"
17501 }
17502 }
17503
17504=begin original
17505
17506See L<perlsyn/"Switch statements"> for detailed information.
17507
17508=end original
17509
17510詳しい情報については L<perlsyn/"Switch statements"> を参照してください。
17511
1751220653=item write FILEHANDLE
1751320654X<write>
1751420655
1751520656=item write EXPR
1751620657
1751720658=item write
1751820659
20660=for Pod::Functions print a picture record
20661
1751920662=begin original
1752020663
1752120664Writes a formatted record (possibly multi-line) to the specified FILEHANDLE,
1752220665using the format associated with that file. By default the format for
1752320666a file is the one having the same name as the filehandle, but the
17524format for the current output channel (see the C<select> function) may be set
20667format for the current output channel (see the
17525explicitly by assigning the name of the format to the C<$~> variable.
20668L<C<select>|/select FILEHANDLE> function) may be set explicitly by
20669assigning the name of the format to the L<C<$~>|perlvar/$~> variable.
1752620670
1752720671=end original
1752820672
1752920673指定された FILEHANDLE に対して、そのファイルに対応させた
1753020674フォーマットを使って、(複数行の場合もある) 整形された
1753120675レコードを書き出します。
1753220676デフォルトでは、ファイルに対応するフォーマットは、ファイルハンドルと
17533同じ名前のものですが、その時点の出力チャネル (C<select> 関数の項を
20677同じ名前のものですが、その時点の出力チャネル
17534参照してください) のフォーマットは、その名前を明示的に変数 C<$~>
20678(L<C<select>|/select FILEHANDLE> 関数の項を
17535代入することで、変更が可能です。 
20679参照してください) のフォーマットはその名前を明示的に
20680L<C<$~>|perlvar/$~> に代入することで、変更が可能です。
1753620681
1753720682=begin original
1753820683
1753920684Top of form processing is handled automatically: if there is insufficient
1754020685room on the current page for the formatted record, the page is advanced by
17541writing a form feed, a special top-of-page format is used to format the new
20686writing a form feed and a special top-of-page
20687format is used to format the new
1754220688page header before the record is written. By default, the top-of-page
17543format is the name of the filehandle with "_TOP" appended. This would be a
20689format is the name of the filehandle with C<_TOP> appended, or C<top>
20690in the current package if the former does not exist. This would be a
1754420691problem with autovivified filehandles, but it may be dynamically set to the
17545format of your choice by assigning the name to the C<$^> variable while
20692format of your choice by assigning the name to the L<C<$^>|perlvar/$^>
17546that filehandle is selected. The number of lines remaining on the current
20693variable while that filehandle is selected. The number of lines
17547page is in variable C<$->, which can be set to C<0> to force a new page.
20694remaining on the current page is in variable L<C<$->|perlvar/$->, which
20695can be set to C<0> to force a new page.
1754820696
1754920697=end original
1755020698
17551ページの先頭の処理は、自動的に行なわれます
20699ページの先頭の処理は、自動的に行なわれます: 現在のページに整形された
17552現在のページに整形されたレコードを出力するだけのスペースがない場合には、
20700レコードを出力するだけのスペースがない場合には、改ページを行なってページを
17553改ページを行なってページを進め、新しいページヘッダを整形するため、
20701進め、新しいページヘッダを整形するため、ページ先頭フォーマットが使われ
17554ページ先頭フォーマットが使われ、その後でレコードが書かれます。
20702その後でレコードが書かれます。
1755520703デフォルトでは、ページ先頭フォーマットは、ファイルハンドルの名前に
17556"_TOP" をつなげたものです。
20704C<_TOP> をつなげたものか、前者が存在しないなら、現在のパッケージの
20705C<top> です。
1755720706これは自動有効化されたファイルハンドルで問題になる可能性がありますが、
1755820707ファイルハンドルが選択されている間に、
17559変数 C<$^> に名前を設定すれば、動的にフォーマットを
20708変数 L<C<$^>|perlvar/$^> に名前を設定すれば、動的にフォーマットを
1756020709変更することができます。
17561そのページの残り行数は、変数 C<$-> に入っており、この変数を 0 に
20710そのページの残り行数は、変数 L<C<$->|perlvar/$-> に入っており、この変数を
17562設定することで、強制的に改ページを行なうことができます。
20711C<0> に設定することで、強制的に改ページを行なうことができます。
1756320712
1756420713=begin original
1756520714
1756620715If FILEHANDLE is unspecified, output goes to the current default output
1756720716channel, which starts out as STDOUT but may be changed by the
17568C<select> operator. If the FILEHANDLE is an EXPR, then the expression
20717L<C<select>|/select FILEHANDLE> operator. If the FILEHANDLE is an EXPR,
20718then the expression
1756920719is evaluated and the resulting string is used to look up the name of
1757020720the FILEHANDLE at run time. For more on formats, see L<perlform>.
1757120721
1757220722=end original
1757320723
17574FILEHANDLE を指定しないと、出力はその時点のデフォルト
20724FILEHANDLE を指定しないと、出力はその時点のデフォルト出力チャネルに対して
17575出力チャネルに対して行なわれます
20725行なわれます; これは、スクリプトの開始時点では STDOUT ですが、
17576これは、スクリプトの開始時点では STDOUT ですが、select() 演算子で
20726L<C<select>|/select FILEHANDLE> 演算子で変更することができます。
17577変更することができます。
1757820727FILEHANDLE が EXPR ならば、式が評価され、その結果の文字列が
1757920728実行時に FILEHANDLE の名前として見られます。
1758020729フォーマットについて、さらには、L<perlform> を参照してください。
1758120730
1758220731=begin original
1758320732
17584Note that write is I<not> the opposite of C<read>. Unfortunately.
20733Note that write is I<not> the opposite of
20734L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>. Unfortunately.
1758520735
1758620736=end original
1758720737
17588残念ながら、write は C<read> の反対のことをするも
20738write は L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>
17589I<ではありません>。
20739反対のことをするもの I<ではありません>。
20740残念ながら。
1759020741
1759120742=item y///
1759220743
20744=for Pod::Functions transliterate a string
20745
1759320746=begin original
1759420747
17595The transliteration operator. Same as C<tr///>. See
20748The transliteration operator. Same as
17596L<perlop/"Quote and Quote-like Operators">.
20749L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>>. See
20750L<perlop/"Quote-Like Operators">.
1759720751
1759820752=end original
1759920753
1760020754文字変換演算子です。
17601C<tr///> と同じです。
20755L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>> と同じです。
17602L<perlop/"Quote and Quote-like Operators"> を参照してください。
20756L<perlop/"Quote-Like Operators"> を参照してください。
1760320757
1760420758=back
1760520759
20760=head2 Non-function Keywords by Cross-reference
20761
20762=head3 perldata
20763
20764=over
20765
20766=item __DATA__
20767
20768=item __END__
20769
20770=begin original
20771
20772These keywords are documented in L<perldata/"Special Literals">.
20773
20774=end original
20775
20776これらのキーワードは L<perldata/"Special Literals"> で文書化されています。
20777
20778=back
20779
20780=head3 perlmod
20781
20782=over
20783
20784=item BEGIN
20785
20786=item CHECK
20787
20788=item END
20789
20790=item INIT
20791
20792=item UNITCHECK
20793
20794=begin original
20795
20796These compile phase keywords are documented in L<perlmod/"BEGIN, UNITCHECK, CHECK, INIT and END">.
20797
20798=end original
20799
20800これらのコンパイルフェーズキーワードは
20801L<perlmod/"BEGIN, UNITCHECK, CHECK, INIT and END"> で文書化されています。
20802
20803=back
20804
20805=head3 perlobj
20806
20807=over
20808
20809=item DESTROY
20810
20811=begin original
20812
20813This method keyword is documented in L<perlobj/"Destructors">.
20814
20815=end original
20816
20817このメソッドキーワードは L<perlobj/"Destructors"> で文書化されています。
20818
20819=back
20820
20821=head3 perlop
20822
20823=over
20824
20825=item and
20826
20827=item cmp
20828
20829=item eq
20830
20831=item ge
20832
20833=item gt
20834
20835=item le
20836
20837=item lt
20838
20839=item ne
20840
20841=item not
20842
20843=item or
20844
20845=item x
20846
20847=item xor
20848
20849=begin original
20850
20851These operators are documented in L<perlop>.
20852
20853=end original
20854
20855これらの演算子は L<perlop> で文書化されています。
20856
20857=back
20858
20859=head3 perlsub
20860
20861=over
20862
20863=item AUTOLOAD
20864
20865=begin original
20866
20867This keyword is documented in L<perlsub/"Autoloading">.
20868
20869=end original
20870
20871このキーワードは L<perlsub/"Autoloading"> で文書化されています。
20872
20873=back
20874
20875=head3 perlsyn
20876
20877=over
20878
20879=item else
20880
20881=item elsif
20882
20883=item for
20884
20885=item foreach
20886
20887=item if
20888
20889=item unless
20890
20891=item until
20892
20893=item while
20894
20895=begin original
20896
20897These flow-control keywords are documented in L<perlsyn/"Compound Statements">.
20898
20899=end original
20900
20901これらのフロー制御キーワードは L<perlsyn/"Compound Statements"> で
20902文書化されています。
20903
20904=item elseif
20905
20906=begin original
20907
20908The "else if" keyword is spelled C<elsif> in Perl. There's no C<elif>
20909or C<else if> either. It does parse C<elseif>, but only to warn you
20910about not using it.
20911
20912=end original
20913
20914"else if" キーワードは Perl では C<elsif> と綴ります。
20915C<elif> や C<else if> はありません。
20916C<elseif> はパースされますが、使わないように警告するためだけです。
20917
20918=begin original
20919
20920See the documentation for flow-control keywords in L<perlsyn/"Compound
20921Statements">.
20922
20923=end original
20924
20925L<perlsyn/"Compound Statements"> のフロー制御キーワードに関する文章を
20926参照してください。
20927
20928=back
20929
20930=over
20931
20932=item default
20933
20934=item given
20935
20936=item when
20937
20938=begin original
20939
20940These flow-control keywords related to the experimental switch feature are
20941documented in L<perlsyn/"Switch Statements">.
20942
20943=end original
20944
20945これらの実験的な switch 機能に関連するフロー制御キーワードは
20946L<perlsyn/"Switch Statements"> で文書化されています。
20947
20948=back
20949
20950=cut
20951
1760620952=begin meta
1760720953
1760820954Translate: 吉村 寿人 <JAE00534@niftyserve.or.jp>
1760920955Update: SHIRAKATA Kentaro <argrath@ub32.org> (5.6.1-)
1761020956Status: completed
1761120957
1761220958=end meta
17613
17614=cut