perlfunc > 5.30.0 との差分

perlfunc 5.30.0 と 5.6.1 の差分

11
22=encoding euc-jp
33
44=head1 NAME
5X<function>
65
76=begin original
87
98perlfunc - Perl builtin functions
109
1110=end original
1211
1312perlfunc - Perl 組み込み関数
1413
1514=head1 DESCRIPTION
1615
1716=begin original
1817
1918The functions in this section can serve as terms in an expression.
2019They fall into two major categories: list operators and named unary
2120operators. These differ in their precedence relationship with a
2221following comma. (See the precedence table in L<perlop>.) List
2322operators take more than one argument, while unary operators can never
2423take more than one argument. Thus, a comma terminates the argument of
2524a unary operator, but merely separates the arguments of a list
26operator. A unary operator generally provides scalar context to its
25operator. A unary operator generally provides a scalar context to its
2726argument, while a list operator may provide either scalar or list
28contexts for its arguments. If it does both, scalar arguments
27contexts for its arguments. If it does both, the scalar arguments will
29come first and list argument follow, and there can only ever
28be first, and the list argument will follow. (Note that there can ever
30be one such list argument. For instance,
29be only one such list argument.) For instance, splice() has three scalar
31L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> has three scalar arguments
30arguments followed by a list, whereas gethostbyname() has four scalar
32followed by a list, whereas L<C<gethostbyname>|/gethostbyname NAME> has
31arguments.
33four scalar arguments.
3432
3533=end original
3634
3735この節の関数は、式の中で項として使うことができます。
38これらは、大きくつに分けられます:
36これらは、大きく 2 つに分けられます:
3937リスト演算子と名前付き単項演算子です。
40これらの違いは、その後に出て来るコンマとの優先順位の関係にあります。
38これらの違いは、その後に出て来るコンマとの優先順位の関係にあります。 
4139(L<perlop> の優先順位の表を参照してください。)
42リスト演算子は 2 個以上の引数をとるのに対して、単項演算子が複数の引数を
40リスト演算子は 2 個以上の引数をとるのに対して、
43とることはありません。
41単項演算子が複数の引数をとることはありません。
44つまり、コンマは単項演算子の引数の終わりとなりますが、リスト演算子の
42つまり、コンマは単項演算子の引数の終わりとなりますが、
45場合には、引数の区切りでしかありません。
43リスト演算子の場合には、引数の区切りでしかありません。
46単項演算子は一般に、引数に対してスカラコンテキストを与えるのに対して、
44単項演算子は一般に、
45引数に対してスカラコンテキストを与えるのに対して、
4746スカラ演算子の場合には、引数に対してスカラコンテキストを与える場合も、
4847リストコンテキストを与える場合もあります。
49つのリスト演算子が両方のコンテキストを与える場合には、スカラ引数
481 つのリスト演算子が
50いくつか並び、最後にリスト引数が一つ続きます;
49両方のコンテキストを与える場合には、スカラ引数がいくつか並び、
51そしてそのようなリスト引数は一だけしかありせん
50最後にリスト引数が 1 続き
52たとえば、L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> は三つのカラ引数
51(リ引数は 1 つだけです。)
53つのリスト引数が続きます;
52たとえば、splice() は 3 つのスカラ引数に 1 つのリスト引数が続きます
54一方 L<C<gethostbyname>|/gethostbyname NAME> つのスカラ引数を持ちます。
53一方 gethostbyname() 4 つのスカラ引数を持ちます。
5554
5655=begin original
5756
5857In the syntax descriptions that follow, list operators that expect a
59list (and provide list context for elements of the list) are shown
58list (and provide list context for the elements of the list) are shown
6059with LIST as an argument. Such a list may consist of any combination
6160of scalar arguments or list values; the list values will be included
6261in the list as if each individual element were interpolated at that
6362point in the list, forming a longer single-dimensional list value.
64Commas should separate literal elements of the LIST.
63Elements of the LIST should be separated by commas.
6564
6665=end original
6766
68後に載せる構文記述では、リストをとり (そのリストの要素にリストコンテキストを
67後に載せる構文記述では、リストをとり
69与える)リスト演算子は、引数として LIST ように書いています;
68(そのリストの要素にリストコンテキスト与え)
69リスト演算子は、引数として LIST をとるように書いています。
7070そのようなリストには、任意のスカラ引数の組み合わせやリスト値を
71含めることができ、リスト値はリストの中に、個々の要素が展開されたように
71含めることができ、リスト値はリストの中に、
72埋め込まれます。
72個々の要素が展開されたように埋め込まれます。
73731 次元の長いリスト値が形成されることになります。
74LIST のリテラルな要素は、コンマで区切られます。
74LIST の要素は、コンマで区切られている必要があります。
7575
7676=begin original
7777
7878Any function in the list below may be used either with or without
7979parentheses around its arguments. (The syntax descriptions omit the
80parentheses.) If you use parentheses, the simple but occasionally
80parentheses.) If you use the parentheses, the simple (but occasionally
81surprising rule is this: It I<looks> like a function, therefore it I<is> a
81surprising) rule is this: It I<looks> like a function, therefore it I<is> a
8282function, and precedence doesn't matter. Otherwise it's a list
83operator or unary operator, and precedence does matter. Whitespace
83operator or unary operator, and precedence does matter. And whitespace
84between the function and left parenthesis doesn't count, so sometimes
84between the function and left parenthesis doesn't count--so you need to
85you need to be careful:
85be careful sometimes:
8686
8787=end original
8888
89以下のリストの関数はすべて、引数の前後の括弧は省略可能となっています。
89以下のリストの関数はすべて、引数の前後の括弧は省略可能と
90なっています。
9091(構文記述では省略しています。)
91括弧を使うときには、単純な、(しかし、ときには驚く結果となる規則が
92括弧を使うときには、
92適用できます:
93単純な (しかし、ときには驚く結果となる) 規則が適用できます:
9394I<関数に見える>ならば、I<それは関数>で、優先順位は関係ありません。
94そう見えなければ、それはリスト演算子か単項演算子で、優先順位が関係します。
95そう見えなければ、それはリスト演算子か単項演算子で、優先順位が
95数と開き括弧の間の空白は関ありせんので、ときに
96関係す。
96気を付けなければなりません:
97また、関数と開き括弧の間の空白は関係ありませんので、
98ときに気を付けなければなりません:
9799
98 print 1+2+4; # Prints 7.
100 print 1+2+4; # Prints 7.
99 print(1+2) + 4; # Prints 3.
101 print(1+2) + 4; # Prints 3.
100 print (1+2)+4; # Also prints 3!
102 print (1+2)+4; # Also prints 3!
101 print +(1+2)+4; # Prints 7.
103 print +(1+2)+4; # Prints 7.
102 print ((1+2)+4); # Prints 7.
104 print ((1+2)+4); # Prints 7.
103105
104106=begin original
105107
106If you run Perl with the L<C<use warnings>|warnings> pragma, it can warn
108If you run Perl with the B<-w> switch it can warn you about this. For
107you about this. For example, the third line above produces:
109example, the third line above produces:
108110
111 print (...) interpreted as function at - line 1.
112 Useless use of integer addition in void context at - line 1.
113
109114=end original
110115
111Perl に L<C<use warnings>|warnings> プラグマを付けて実行すれば、
116Perl に B<-w> スイッチを付けて実行すれば、こういったものには
112こういったものには警告を出してくれます。
117警告を出してくれます。
113たとえば、上記のつめは、以下のような警告が出ます:
118たとえば、上記の 3 つめは、以下のような警告が出ます:
114119
115 print (...) interpreted as function at - line 1.
120 print (...) interpreted as function at - line 1.
116 Useless use of integer addition in void context at - line 1.
121 Useless use of integer addition in void context at - line 1.
117122
118123=begin original
119124
120125A few functions take no arguments at all, and therefore work as neither
121unary nor list operators. These include such functions as
126unary nor list operators. These include such functions as C<time>
122L<C<time>|/time> and L<C<endpwent>|/endpwent>. For example,
127and C<endpwent>. For example, C<time+86_400> always means
123C<time+86_400> always means C<time() + 86_400>.
128C<time() + 86_400>.
124129
125130=end original
126131
127132いくつかの関数は引数を全くとらないので、単項演算子としても
128133リスト演算子としても動作しません。
129このような関数としては L<C<time>|/time>L<C<endpwent>|/endpwent>
134このような関数としては C<time> や C<endpwent> があります。
130あります。
131135例えば、C<time+86_400> は常に C<time() + 86_400> として扱われます。
132136
133137=begin original
134138
135139For functions that can be used in either a scalar or list context,
136nonabortive failure is generally indicated in scalar context by
140nonabortive failure is generally indicated in a scalar context by
137returning the undefined value, and in list context by returning the
141returning the undefined value, and in a list context by returning the
138empty list.
142null list.
139143
140144=end original
141145
142スカラコンテキストでも、リストコンテキストでも使える関数は、致命的でない
146スカラコンテキストでも、リストコンテキストでも使える関数は、
143エラーを示すために、スカラコンテキストでは未定義値を返し、
147致命的でないエラーを示すために、スカラコンテキストでは
144リストコンテキストでは空リストを返します。
148未定義値を返し、リストコンテキストでは空リストを返します。
145149
146150=begin original
147151
148152Remember the following important rule: There is B<no rule> that relates
149153the behavior of an expression in list context to its behavior in scalar
150154context, or vice versa. It might do two totally different things.
151Each operator and function decides which sort of value would be most
155Each operator and function decides which sort of value it would be most
152156appropriate to return in scalar context. Some operators return the
153157length of the list that would have been returned in list context. Some
154158operators return the first value in the list. Some operators return the
155159last value in the list. Some operators return a count of successful
156160operations. In general, they do what you want, unless you want
157161consistency.
158X<context>
159162
160163=end original
161164
162165以下に述べる重要なルールを忘れないで下さい: リストコンテキストでの
163166振る舞いとスカラコンテキストでの振る舞いの関係、あるいはその逆に
164167B<ルールはありません>。
1651682 つの全く異なったことがあります。
166169それぞれの演算子と関数は、スカラコンテキストでは、もっとも適切と
167170思われる値を返します。
168171リストコンテキストで返す時のリストの長さを返す演算子もあります。
169172リストの最初の値を返す演算子もあります。
170173リストの最後の値を返す演算子もあります。
171174成功した操作の数を返す演算子もあります。
172175一般的には、一貫性を求めない限り、こちらが求めることをします。
173X<context>
174176
175177=begin original
176178
177A named array in scalar context is quite different from what would at
179An named array in scalar context is quite different from what would at
178180first glance appear to be a list in scalar context. You can't get a list
179181like C<(1,2,3)> into being in scalar context, because the compiler knows
180182the context at compile time. It would generate the scalar comma operator
181there, not the list concatenation version of the comma. That means it
183there, not the list construction version of the comma. That means it
182184was never a list to start with.
183185
184186=end original
185187
186188スカラコンテキストでの名前付き配列は、スカラコンテキストでのリストを
187189一目見たものとは全く違います。
188190コンパイラはコンパイル時にコンテキストを知っているので、
189191C<(1,2,3)> のようなリストをスカラコンテキストで得ることはできません。
190これはスカラコンマ演算子を生成し、コンマのリスト結合版ではありません。
192これはスカラコンマ演算子を生成し、コンマのリスト作成版ではありません。
191193これは初めからリストであることはないことを意味します。
192194
193195=begin original
194196
195197In general, functions in Perl that serve as wrappers for system calls
196("syscalls") of the same name (like L<chown(2)>, L<fork(2)>,
198of the same name (like chown(2), fork(2), closedir(2), etc.) all return
197L<closedir(2)>, etc.) return true when they succeed and
199true when they succeed and C<undef> otherwise, as is usually mentioned
198L<C<undef>|/undef EXPR> otherwise, as is usually mentioned in the
200in the descriptions below. This is different from the C interfaces,
199descriptions below. This is different from the C interfaces, which
201which return C<-1> on failure. Exceptions to this rule are C<wait>,
200return C<-1> on failure. Exceptions to this rule include
202C<waitpid>, and C<syscall>. System calls also set the special C<$!>
201L<C<wait>|/wait>, L<C<waitpid>|/waitpid PID,FLAGS>, and
203variable on failure. Other functions do not, except accidentally.
202L<C<syscall>|/syscall NUMBER, LIST>. System calls also set the special
203L<C<$!>|perlvar/$!> variable on failure. Other functions do not, except
204accidentally.
205204
206205=end original
207206
208207一般的に、同じ名前のシステムコールのラッパーとして動作する Perl の関数
209(L<chown(2)>, L<fork(2)>, L<closedir(2)> など)は、以下に述べるように、
208(chown(2), fork(2), closedir(2) など)は、以下に述べるように、
210成功時に真を返し、そうでなければ L<C<undef>|/undef EXPR> を返します。
209成功時に真を返し、そうでなければ C<undef> を返します。
211210これは失敗時に C<-1> を返す C のインターフェースとは違います。
212このルールの例外は L<C<wait>|/wait>, L<C<waitpid>|/waitpid PID,FLAGS>,
211このルールの例外は C<wait>, C<waitpid>, C<syscall> です。
213L<C<syscall>|/syscall NUMBER, LIST> です。
212システムコールは失敗時に特殊変数 C<$!> をセットします。
214システムコールは失敗時に特殊変数 L<C<$!>|perlvar/$!> をセットします。
215213その他の関数は、事故を除いて、セットしません。
216214
217=begin original
218
219Extension modules can also hook into the Perl parser to define new
220kinds of keyword-headed expression. These may look like functions, but
221may also look completely different. The syntax following the keyword
222is defined entirely by the extension. If you are an implementor, see
223L<perlapi/PL_keyword_plugin> for the mechanism. If you are using such
224a module, see the module's documentation for details of the syntax that
225it defines.
226
227=end original
228
229エクステンションモジュールは、新しい種類のキーワードが頭に付いた式を
230定義するために Perl パーサをフックできます。
231これらは関数のように見えるかもしれませんが、全く別物かもしれません。
232キーワード以降の文法は完全にエクステンションによって定義されます。
233もしあなたが実装者なら、この機構については L<perlapi/PL_keyword_plugin> を
234参照してください。
235もしあなたがそのようなモジュールを使っているなら、
236定義されている文法の詳細についてはモジュールの文書を参照してください。
237
238215=head2 Perl Functions by Category
239X<function>
240216
241217(カテゴリ別の Perl 関数)
242218
243219=begin original
244220
245221Here are Perl's functions (including things that look like
246222functions, like some keywords and named operators)
247223arranged by category. Some functions appear in more
248than one place. Any warnings, including those produced by
224than one place.
249keywords, are described in L<perldiag> and L<warnings>.
250225
251226=end original
252227
253228以下に、カテゴリ別の関数(キーワードや名前付き演算子のような、
254229関数のように見えるものも含みます)を示します。
255230複数の場所に現れる関数もあります。
256キーワードによって生成されるものを含む全ての警告は
257L<perldiag> と L<warnings> に記述されています。
258231
259232=over 4
260233
261234=item Functions for SCALARs or strings
262X<scalar> X<string> X<character>
263235
264236(スカラや文字列のための関数)
265237
266=for Pod::Functions =String
238C<chomp>, C<chop>, C<chr>, C<crypt>, C<hex>, C<index>, C<lc>, C<lcfirst>,
239C<length>, C<oct>, C<ord>, C<pack>, C<q/STRING/>, C<qq/STRING/>, C<reverse>,
240C<rindex>, C<sprintf>, C<substr>, C<tr///>, C<uc>, C<ucfirst>, C<y///>
267241
268L<C<chomp>|/chomp VARIABLE>, L<C<chop>|/chop VARIABLE>,
269L<C<chr>|/chr NUMBER>, L<C<crypt>|/crypt PLAINTEXT,SALT>,
270L<C<fc>|/fc EXPR>, L<C<hex>|/hex EXPR>,
271L<C<index>|/index STR,SUBSTR,POSITION>, L<C<lc>|/lc EXPR>,
272L<C<lcfirst>|/lcfirst EXPR>, L<C<length>|/length EXPR>,
273L<C<oct>|/oct EXPR>, L<C<ord>|/ord EXPR>,
274L<C<pack>|/pack TEMPLATE,LIST>,
275L<C<qE<sol>E<sol>>|/qE<sol>STRINGE<sol>>,
276L<C<qqE<sol>E<sol>>|/qqE<sol>STRINGE<sol>>, L<C<reverse>|/reverse LIST>,
277L<C<rindex>|/rindex STR,SUBSTR,POSITION>,
278L<C<sprintf>|/sprintf FORMAT, LIST>,
279L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT>,
280L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>>, L<C<uc>|/uc EXPR>,
281L<C<ucfirst>|/ucfirst EXPR>,
282L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>>
283
284=begin original
285
286L<C<fc>|/fc EXPR> is available only if the
287L<C<"fc"> feature|feature/The 'fc' feature> is enabled or if it is
288prefixed with C<CORE::>. The
289L<C<"fc"> feature|feature/The 'fc' feature> is enabled automatically
290with a C<use v5.16> (or higher) declaration in the current scope.
291
292=end original
293
294L<C<fc>|/fc EXPR> は L<C<"fc"> 機能|feature/The 'fc' feature> が有効か
295C<CORE::> が前置されたときにのみ利用可能です。
296L<C<"fc"> 機能|feature/The 'fc' feature> は現在のスコープで
297C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。
298
299242=item Regular expressions and pattern matching
300X<regular expression> X<regex> X<regexp>
301243
302244(正規表現とパターンマッチング)
303245
304=for Pod::Functions =Regexp
246C<m//>, C<pos>, C<quotemeta>, C<s///>, C<split>, C<study>, C<qr//>
305247
306L<C<mE<sol>E<sol>>|/mE<sol>E<sol>>, L<C<pos>|/pos SCALAR>,
307L<C<qrE<sol>E<sol>>|/qrE<sol>STRINGE<sol>>,
308L<C<quotemeta>|/quotemeta EXPR>,
309L<C<sE<sol>E<sol>E<sol>>|/sE<sol>E<sol>E<sol>>,
310L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>,
311L<C<study>|/study SCALAR>
312
313248=item Numeric functions
314X<numeric> X<number> X<trigonometric> X<trigonometry>
315249
316250(数値関数)
317251
318=for Pod::Functions =Math
252C<abs>, C<atan2>, C<cos>, C<exp>, C<hex>, C<int>, C<log>, C<oct>, C<rand>,
253C<sin>, C<sqrt>, C<srand>
319254
320L<C<abs>|/abs VALUE>, L<C<atan2>|/atan2 Y,X>, L<C<cos>|/cos EXPR>,
321L<C<exp>|/exp EXPR>, L<C<hex>|/hex EXPR>, L<C<int>|/int EXPR>,
322L<C<log>|/log EXPR>, L<C<oct>|/oct EXPR>, L<C<rand>|/rand EXPR>,
323L<C<sin>|/sin EXPR>, L<C<sqrt>|/sqrt EXPR>, L<C<srand>|/srand EXPR>
324
325255=item Functions for real @ARRAYs
326X<array>
327256
328257(実配列のための関数)
329258
330=for Pod::Functions =ARRAY
259C<pop>, C<push>, C<shift>, C<splice>, C<unshift>
331260
332L<C<each>|/each HASH>, L<C<keys>|/keys HASH>, L<C<pop>|/pop ARRAY>,
333L<C<push>|/push ARRAY,LIST>, L<C<shift>|/shift ARRAY>,
334L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST>,
335L<C<unshift>|/unshift ARRAY,LIST>, L<C<values>|/values HASH>
336
337261=item Functions for list data
338X<list>
339262
340263(リストデータのための関数)
341264
342=for Pod::Functions =LIST
265C<grep>, C<join>, C<map>, C<qw/STRING/>, C<reverse>, C<sort>, C<unpack>
343266
344L<C<grep>|/grep BLOCK LIST>, L<C<join>|/join EXPR,LIST>,
345L<C<map>|/map BLOCK LIST>, L<C<qwE<sol>E<sol>>|/qwE<sol>STRINGE<sol>>,
346L<C<reverse>|/reverse LIST>, L<C<sort>|/sort SUBNAME LIST>,
347L<C<unpack>|/unpack TEMPLATE,EXPR>
348
349267=item Functions for real %HASHes
350X<hash>
351268
352269(実ハッシュのための関数)
353270
354=for Pod::Functions =HASH
271C<delete>, C<each>, C<exists>, C<keys>, C<values>
355272
356L<C<delete>|/delete EXPR>, L<C<each>|/each HASH>,
357L<C<exists>|/exists EXPR>, L<C<keys>|/keys HASH>,
358L<C<values>|/values HASH>
359
360273=item Input and output functions
361X<I/O> X<input> X<output> X<dbm>
362274
363275(入出力関数)
364276
365=for Pod::Functions =I/O
277C<binmode>, C<close>, C<closedir>, C<dbmclose>, C<dbmopen>, C<die>, C<eof>,
278C<fileno>, C<flock>, C<format>, C<getc>, C<print>, C<printf>, C<read>,
279C<readdir>, C<rewinddir>, C<seek>, C<seekdir>, C<select>, C<syscall>,
280C<sysread>, C<sysseek>, C<syswrite>, C<tell>, C<telldir>, C<truncate>,
281C<warn>, C<write>
366282
367L<C<binmode>|/binmode FILEHANDLE, LAYER>, L<C<close>|/close FILEHANDLE>,
283=item Functions for fixed length data or records
368L<C<closedir>|/closedir DIRHANDLE>, L<C<dbmclose>|/dbmclose HASH>,
369L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, L<C<die>|/die LIST>,
370L<C<eof>|/eof FILEHANDLE>, L<C<fileno>|/fileno FILEHANDLE>,
371L<C<flock>|/flock FILEHANDLE,OPERATION>, L<C<format>|/format>,
372L<C<getc>|/getc FILEHANDLE>, L<C<print>|/print FILEHANDLE LIST>,
373L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
374L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>,
375L<C<readdir>|/readdir DIRHANDLE>, L<C<readline>|/readline EXPR>,
376L<C<rewinddir>|/rewinddir DIRHANDLE>, L<C<say>|/say FILEHANDLE LIST>,
377L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
378L<C<seekdir>|/seekdir DIRHANDLE,POS>,
379L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>,
380L<C<syscall>|/syscall NUMBER, LIST>,
381L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
382L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>,
383L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
384L<C<tell>|/tell FILEHANDLE>, L<C<telldir>|/telldir DIRHANDLE>,
385L<C<truncate>|/truncate FILEHANDLE,LENGTH>, L<C<warn>|/warn LIST>,
386L<C<write>|/write FILEHANDLE>
387284
388=begin original
389
390L<C<say>|/say FILEHANDLE LIST> is available only if the
391L<C<"say"> feature|feature/The 'say' feature> is enabled or if it is
392prefixed with C<CORE::>. The
393L<C<"say"> feature|feature/The 'say' feature> is enabled automatically
394with a C<use v5.10> (or higher) declaration in the current scope.
395
396=end original
397
398L<C<say>|/say FILEHANDLE LIST> は
399L<C<"say"> 機能|feature/The 'say' feature> が有効か C<CORE::> が
400前置されたときにのみ利用可能です。
401L<C<"say"> 機能|feature/The 'say' feature> は現在のスコープで
402C<use v5.10> (またはそれ以上) が宣言されると自動的に有効になります。
403
404=item Functions for fixed-length data or records
405
406285(固定長データやレコードのための関数)
407286
408=for Pod::Functions =Binary
287C<pack>, C<read>, C<syscall>, C<sysread>, C<syswrite>, C<unpack>, C<vec>
409288
410L<C<pack>|/pack TEMPLATE,LIST>,
411L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>,
412L<C<syscall>|/syscall NUMBER, LIST>,
413L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
414L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>,
415L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
416L<C<unpack>|/unpack TEMPLATE,EXPR>, L<C<vec>|/vec EXPR,OFFSET,BITS>
417
418289=item Functions for filehandles, files, or directories
419X<file> X<filehandle> X<directory> X<pipe> X<link> X<symlink>
420290
421291(ファイルハンドル、ファイル、ディレクトリのための関数)
422292
423=for Pod::Functions =File
293C<-I<X>>, C<chdir>, C<chmod>, C<chown>, C<chroot>, C<fcntl>, C<glob>,
294C<ioctl>, C<link>, C<lstat>, C<mkdir>, C<open>, C<opendir>,
295C<readlink>, C<rename>, C<rmdir>, C<stat>, C<symlink>, C<umask>,
296C<unlink>, C<utime>
424297
425L<C<-I<X>>|/-X FILEHANDLE>, L<C<chdir>|/chdir EXPR>,
298=item Keywords related to the control flow of your perl program
426L<C<chmod>|/chmod LIST>, L<C<chown>|/chown LIST>,
427L<C<chroot>|/chroot FILENAME>,
428L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>, L<C<glob>|/glob EXPR>,
429L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>,
430L<C<link>|/link OLDFILE,NEWFILE>, L<C<lstat>|/lstat FILEHANDLE>,
431L<C<mkdir>|/mkdir FILENAME,MODE>, L<C<open>|/open FILEHANDLE,EXPR>,
432L<C<opendir>|/opendir DIRHANDLE,EXPR>, L<C<readlink>|/readlink EXPR>,
433L<C<rename>|/rename OLDNAME,NEWNAME>, L<C<rmdir>|/rmdir FILENAME>,
434L<C<select>|/select FILEHANDLE>, L<C<stat>|/stat FILEHANDLE>,
435L<C<symlink>|/symlink OLDFILE,NEWFILE>,
436L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>,
437L<C<umask>|/umask EXPR>, L<C<unlink>|/unlink LIST>,
438L<C<utime>|/utime LIST>
439299
440=item Keywords related to the control flow of your Perl program
441X<control flow>
442
443300(プログラムの流れを制御することに関連するキーワード)
444301
445=for Pod::Functions =Flow
302C<caller>, C<continue>, C<die>, C<do>, C<dump>, C<eval>, C<exit>,
303C<goto>, C<last>, C<next>, C<redo>, C<return>, C<sub>, C<wantarray>
446304
447L<C<break>|/break>, L<C<caller>|/caller EXPR>,
448L<C<continue>|/continue BLOCK>, L<C<die>|/die LIST>, L<C<do>|/do BLOCK>,
449L<C<dump>|/dump LABEL>, L<C<eval>|/eval EXPR>,
450L<C<evalbytes>|/evalbytes EXPR>, L<C<exit>|/exit EXPR>,
451L<C<__FILE__>|/__FILE__>, L<C<goto>|/goto LABEL>,
452L<C<last>|/last LABEL>, L<C<__LINE__>|/__LINE__>,
453L<C<next>|/next LABEL>, L<C<__PACKAGE__>|/__PACKAGE__>,
454L<C<redo>|/redo LABEL>, L<C<return>|/return EXPR>,
455L<C<sub>|/sub NAME BLOCK>, L<C<__SUB__>|/__SUB__>,
456L<C<wantarray>|/wantarray>
457
458=begin original
459
460L<C<break>|/break> is available only if you enable the experimental
461L<C<"switch"> feature|feature/The 'switch' feature> or use the C<CORE::>
462prefix. The L<C<"switch"> feature|feature/The 'switch' feature> also
463enables the C<default>, C<given> and C<when> statements, which are
464documented in L<perlsyn/"Switch Statements">.
465The L<C<"switch"> feature|feature/The 'switch' feature> is enabled
466automatically with a C<use v5.10> (or higher) declaration in the current
467scope. In Perl v5.14 and earlier, L<C<continue>|/continue BLOCK>
468required the L<C<"switch"> feature|feature/The 'switch' feature>, like
469the other keywords.
470
471=end original
472
473L<C<break>|/break> は、実験的な
474L<C<"switch"> 機能|feature/The 'switch' feature> が有効か C<CORE::> 接頭辞を
475使ったときにのみ利用可能です。
476L<C<"switch"> 機能|feature/The 'switch' feature> は、
477L<perlsyn/"Switch Statements"> で文書化されている
478C<default>, C<given>, C<when> 文も有効にします。
479L<C<"switch"> 機能|feature/The 'switch' feature> は、現在のスコープで
480C<use v5.10> (またはそれ以上) 宣言があると自動的に有効になります。
481Perl v5.14 以前では、L<C<continue>|/continue BLOCK> は他のキーワードと同様に
482L<C<"switch"> 機能|feature/The 'switch' feature> が必要です。
483
484=begin original
485
486L<C<evalbytes>|/evalbytes EXPR> is only available with the
487L<C<"evalbytes"> feature|feature/The 'unicode_eval' and 'evalbytes' features>
488(see L<feature>) or if prefixed with C<CORE::>. L<C<__SUB__>|/__SUB__>
489is only available with the
490L<C<"current_sub"> feature|feature/The 'current_sub' feature> or if
491prefixed with C<CORE::>. Both the
492L<C<"evalbytes">|feature/The 'unicode_eval' and 'evalbytes' features>
493and L<C<"current_sub">|feature/The 'current_sub' feature> features are
494enabled automatically with a C<use v5.16> (or higher) declaration in the
495current scope.
496
497=end original
498
499L<C<evalbytes>|/evalbytes EXPR> は
500L<C<"evalbytes"> 機能|feature/The 'unicode_eval' and 'evalbytes' features>
501(L<feature> 参照) が有効か C<CORE::> が前置されたときにのみ利用可能です。
502L<C<__SUB__>|/__SUB__> は
503L<C<"current_sub"> 機能|feature/The 'current_sub' feature> が有効か
504C<CORE::> が前置されたときにのみ利用可能です。
505L<C<"evalbytes">|feature/The 'unicode_eval' and 'evalbytes' features> と
506L<C<"current_sub">|feature/The 'current_sub' feature> の両方の機能は
507現在のスコープで
508C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。
509
510305=item Keywords related to scoping
511306
512307(スコープに関するキーワード)
513308
514=for Pod::Functions =Namespace
309C<caller>, C<import>, C<local>, C<my>, C<our>, C<package>, C<use>
515310
516L<C<caller>|/caller EXPR>, L<C<import>|/import LIST>,
517L<C<local>|/local EXPR>, L<C<my>|/my VARLIST>, L<C<our>|/our VARLIST>,
518L<C<package>|/package NAMESPACE>, L<C<state>|/state VARLIST>,
519L<C<use>|/use Module VERSION LIST>
520
521=begin original
522
523L<C<state>|/state VARLIST> is available only if the
524L<C<"state"> feature|feature/The 'state' feature> is enabled or if it is
525prefixed with C<CORE::>. The
526L<C<"state"> feature|feature/The 'state' feature> is enabled
527automatically with a C<use v5.10> (or higher) declaration in the current
528scope.
529
530=end original
531
532L<C<state>|/state VARLIST> は
533L<C<"state"> 機能|feature/The 'state' feature> が有効か C<CORE::> を
534前置した場合にのみ利用可能です。
535L<C<"state"> 機能|feature/The 'state' feature> は現在のスコープで
536C<use v5.10> (またはそれ以上) を宣言した場合自動的に有効になります。
537
538311=item Miscellaneous functions
539312
540313(さまざまな関数)
541314
542=for Pod::Functions =Misc
315C<defined>, C<dump>, C<eval>, C<formline>, C<local>, C<my>, C<our>, C<reset>,
316C<scalar>, C<undef>, C<wantarray>
543317
544L<C<defined>|/defined EXPR>, L<C<formline>|/formline PICTURE,LIST>,
545L<C<lock>|/lock THING>, L<C<prototype>|/prototype FUNCTION>,
546L<C<reset>|/reset EXPR>, L<C<scalar>|/scalar EXPR>,
547L<C<undef>|/undef EXPR>
548
549318=item Functions for processes and process groups
550X<process> X<pid> X<process id>
551319
552320(プロセスとプロセスグループのための関数)
553321
554=for Pod::Functions =Process
322C<alarm>, C<exec>, C<fork>, C<getpgrp>, C<getppid>, C<getpriority>, C<kill>,
323C<pipe>, C<qx/STRING/>, C<setpgrp>, C<setpriority>, C<sleep>, C<system>,
324C<times>, C<wait>, C<waitpid>
555325
556L<C<alarm>|/alarm SECONDS>, L<C<exec>|/exec LIST>, L<C<fork>|/fork>,
326=item Keywords related to perl modules
557L<C<getpgrp>|/getpgrp PID>, L<C<getppid>|/getppid>,
558L<C<getpriority>|/getpriority WHICH,WHO>, L<C<kill>|/kill SIGNAL, LIST>,
559L<C<pipe>|/pipe READHANDLE,WRITEHANDLE>,
560L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>>,
561L<C<readpipe>|/readpipe EXPR>, L<C<setpgrp>|/setpgrp PID,PGRP>,
562L<C<setpriority>|/setpriority WHICH,WHO,PRIORITY>,
563L<C<sleep>|/sleep EXPR>, L<C<system>|/system LIST>, L<C<times>|/times>,
564L<C<wait>|/wait>, L<C<waitpid>|/waitpid PID,FLAGS>
565327
566=item Keywords related to Perl modules
328(perl モジュールに関するキーワード)
567X<module>
568329
569(Perl モジュールに関するキーワード)
330C<do>, C<import>, C<no>, C<package>, C<require>, C<use>
570331
571=for Pod::Functions =Modules
332=item Keywords related to classes and object-orientedness
572333
573L<C<do>|/do EXPR>, L<C<import>|/import LIST>,
574L<C<no>|/no MODULE VERSION LIST>, L<C<package>|/package NAMESPACE>,
575L<C<require>|/require VERSION>, L<C<use>|/use Module VERSION LIST>
576
577=item Keywords related to classes and object-orientation
578X<object> X<class> X<package>
579
580334(クラスとオブジェクト指向に関するキーワード)
581335
582=for Pod::Functions =Objects
336C<bless>, C<dbmclose>, C<dbmopen>, C<package>, C<ref>, C<tie>, C<tied>,
337C<untie>, C<use>
583338
584L<C<bless>|/bless REF,CLASSNAME>, L<C<dbmclose>|/dbmclose HASH>,
585L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>,
586L<C<package>|/package NAMESPACE>, L<C<ref>|/ref EXPR>,
587L<C<tie>|/tie VARIABLE,CLASSNAME,LIST>, L<C<tied>|/tied VARIABLE>,
588L<C<untie>|/untie VARIABLE>, L<C<use>|/use Module VERSION LIST>
589
590339=item Low-level socket functions
591X<socket> X<sock>
592340
593341(低レベルソケット関数)
594342
595=for Pod::Functions =Socket
343C<accept>, C<bind>, C<connect>, C<getpeername>, C<getsockname>,
344C<getsockopt>, C<listen>, C<recv>, C<send>, C<setsockopt>, C<shutdown>,
345C<socket>, C<socketpair>
596346
597L<C<accept>|/accept NEWSOCKET,GENERICSOCKET>,
598L<C<bind>|/bind SOCKET,NAME>, L<C<connect>|/connect SOCKET,NAME>,
599L<C<getpeername>|/getpeername SOCKET>,
600L<C<getsockname>|/getsockname SOCKET>,
601L<C<getsockopt>|/getsockopt SOCKET,LEVEL,OPTNAME>,
602L<C<listen>|/listen SOCKET,QUEUESIZE>,
603L<C<recv>|/recv SOCKET,SCALAR,LENGTH,FLAGS>,
604L<C<send>|/send SOCKET,MSG,FLAGS,TO>,
605L<C<setsockopt>|/setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL>,
606L<C<shutdown>|/shutdown SOCKET,HOW>,
607L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL>,
608L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL>
609
610347=item System V interprocess communication functions
611X<IPC> X<System V> X<semaphore> X<shared memory> X<memory> X<message>
612348
613349(System V プロセス間通信関数)
614350
615=for Pod::Functions =SysV
351C<msgctl>, C<msgget>, C<msgrcv>, C<msgsnd>, C<semctl>, C<semget>, C<semop>,
352C<shmctl>, C<shmget>, C<shmread>, C<shmwrite>
616353
617L<C<msgctl>|/msgctl ID,CMD,ARG>, L<C<msgget>|/msgget KEY,FLAGS>,
618L<C<msgrcv>|/msgrcv ID,VAR,SIZE,TYPE,FLAGS>,
619L<C<msgsnd>|/msgsnd ID,MSG,FLAGS>,
620L<C<semctl>|/semctl ID,SEMNUM,CMD,ARG>,
621L<C<semget>|/semget KEY,NSEMS,FLAGS>, L<C<semop>|/semop KEY,OPSTRING>,
622L<C<shmctl>|/shmctl ID,CMD,ARG>, L<C<shmget>|/shmget KEY,SIZE,FLAGS>,
623L<C<shmread>|/shmread ID,VAR,POS,SIZE>,
624L<C<shmwrite>|/shmwrite ID,STRING,POS,SIZE>
625
626354=item Fetching user and group info
627X<user> X<group> X<password> X<uid> X<gid> X<passwd> X</etc/passwd>
628355
629356(ユーザーとグループの情報取得)
630357
631=for Pod::Functions =User
358C<endgrent>, C<endhostent>, C<endnetent>, C<endpwent>, C<getgrent>,
359C<getgrgid>, C<getgrnam>, C<getlogin>, C<getpwent>, C<getpwnam>,
360C<getpwuid>, C<setgrent>, C<setpwent>
632361
633L<C<endgrent>|/endgrent>, L<C<endhostent>|/endhostent>,
634L<C<endnetent>|/endnetent>, L<C<endpwent>|/endpwent>,
635L<C<getgrent>|/getgrent>, L<C<getgrgid>|/getgrgid GID>,
636L<C<getgrnam>|/getgrnam NAME>, L<C<getlogin>|/getlogin>,
637L<C<getpwent>|/getpwent>, L<C<getpwnam>|/getpwnam NAME>,
638L<C<getpwuid>|/getpwuid UID>, L<C<setgrent>|/setgrent>,
639L<C<setpwent>|/setpwent>
640
641362=item Fetching network info
642X<network> X<protocol> X<host> X<hostname> X<IP> X<address> X<service>
643363
644364(ネットワーク情報取得)
645365
646=for Pod::Functions =Network
366C<endprotoent>, C<endservent>, C<gethostbyaddr>, C<gethostbyname>,
367C<gethostent>, C<getnetbyaddr>, C<getnetbyname>, C<getnetent>,
368C<getprotobyname>, C<getprotobynumber>, C<getprotoent>,
369C<getservbyname>, C<getservbyport>, C<getservent>, C<sethostent>,
370C<setnetent>, C<setprotoent>, C<setservent>
647371
648L<C<endprotoent>|/endprotoent>, L<C<endservent>|/endservent>,
649L<C<gethostbyaddr>|/gethostbyaddr ADDR,ADDRTYPE>,
650L<C<gethostbyname>|/gethostbyname NAME>, L<C<gethostent>|/gethostent>,
651L<C<getnetbyaddr>|/getnetbyaddr ADDR,ADDRTYPE>,
652L<C<getnetbyname>|/getnetbyname NAME>, L<C<getnetent>|/getnetent>,
653L<C<getprotobyname>|/getprotobyname NAME>,
654L<C<getprotobynumber>|/getprotobynumber NUMBER>,
655L<C<getprotoent>|/getprotoent>,
656L<C<getservbyname>|/getservbyname NAME,PROTO>,
657L<C<getservbyport>|/getservbyport PORT,PROTO>,
658L<C<getservent>|/getservent>, L<C<sethostent>|/sethostent STAYOPEN>,
659L<C<setnetent>|/setnetent STAYOPEN>,
660L<C<setprotoent>|/setprotoent STAYOPEN>,
661L<C<setservent>|/setservent STAYOPEN>
662
663372=item Time-related functions
664X<time> X<date>
665373
666374(時刻に関する関数)
667375
668=for Pod::Functions =Time
376C<gmtime>, C<localtime>, C<time>, C<times>
669377
670L<C<gmtime>|/gmtime EXPR>, L<C<localtime>|/localtime EXPR>,
378=item Functions new in perl5
671L<C<time>|/time>, L<C<times>|/times>
672379
673=item Non-function keywords
380(perl5 で新設された関数)
674381
675=for Pod::Functions =!Non-functions
382C<abs>, C<bless>, C<chomp>, C<chr>, C<exists>, C<formline>, C<glob>,
383C<import>, C<lc>, C<lcfirst>, C<map>, C<my>, C<no>, C<our>, C<prototype>,
384C<qx>, C<qw>, C<readline>, C<readpipe>, C<ref>, C<sub*>, C<sysopen>, C<tie>,
385C<tied>, C<uc>, C<ucfirst>, C<untie>, C<use>
676386
677C<and>, C<AUTOLOAD>, C<BEGIN>, C<CHECK>, C<cmp>, C<CORE>, C<__DATA__>,
387=begin original
678C<default>, C<DESTROY>, C<else>, C<elseif>, C<elsif>, C<END>, C<__END__>,
679C<eq>, C<for>, C<foreach>, C<ge>, C<given>, C<gt>, C<if>, C<INIT>, C<le>,
680C<lt>, C<ne>, C<not>, C<or>, C<UNITCHECK>, C<unless>, C<until>, C<when>,
681C<while>, C<x>, C<xor>
682388
389* - C<sub> was a keyword in perl4, but in perl5 it is an
390operator, which can be used in expressions.
391
392=end original
393
394* - C<sub> は perl4 ではキーワードですが、perl5 では演算子なので、
395式で使えます。
396
397=item Functions obsoleted in perl5
398
399(perl5 では古いものとなった関数)
400
401C<dbmclose>, C<dbmopen>
402
683403=back
684404
685405=head2 Portability
686X<portability> X<Unix> X<portable>
687406
688(移植性)
689
690407=begin original
691408
692409Perl was born in Unix and can therefore access all common Unix
693410system calls. In non-Unix environments, the functionality of some
694Unix system calls may not be available or details of the available
411Unix system calls may not be available, or details of the available
695412functionality may differ slightly. The Perl functions affected
696413by this are:
697414
698415=end original
699416
700417Perl は Unix 環境で生まれたので、全ての共通する Unix システムコールに
701アクセスします。
418アクセスします。非 Unix 環境では、いくつかの Unix システムコールの
702非 Unix 環境では、いくつかの Unix システムコールの機能が使えなかったり、
419機能が使えなかったり、使える機能の詳細が多少異なったりします。
703使える機能の詳細が多少異なったりします。
704420これによる影響を受ける Perl 関数は以下のものです:
705421
706L<C<-I<X>>|/-X FILEHANDLE>, L<C<binmode>|/binmode FILEHANDLE, LAYER>,
422C<-X>, C<binmode>, C<chmod>, C<chown>, C<chroot>, C<crypt>,
707L<C<chmod>|/chmod LIST>, L<C<chown>|/chown LIST>,
423C<dbmclose>, C<dbmopen>, C<dump>, C<endgrent>, C<endhostent>,
708L<C<chroot>|/chroot FILENAME>, L<C<crypt>|/crypt PLAINTEXT,SALT>,
424C<endnetent>, C<endprotoent>, C<endpwent>, C<endservent>, C<exec>,
709L<C<dbmclose>|/dbmclose HASH>, L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>,
425C<fcntl>, C<flock>, C<fork>, C<getgrent>, C<getgrgid>, C<gethostent>,
710L<C<dump>|/dump LABEL>, L<C<endgrent>|/endgrent>,
426C<getlogin>, C<getnetbyaddr>, C<getnetbyname>, C<getnetent>,
711L<C<endhostent>|/endhostent>, L<C<endnetent>|/endnetent>,
427C<getppid>, C<getprgp>, C<getpriority>, C<getprotobynumber>,
712L<C<endprotoent>|/endprotoent>, L<C<endpwent>|/endpwent>,
428C<getprotoent>, C<getpwent>, C<getpwnam>, C<getpwuid>,
713L<C<endservent>|/endservent>, L<C<exec>|/exec LIST>,
429C<getservbyport>, C<getservent>, C<getsockopt>, C<glob>, C<ioctl>,
714L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>,
430C<kill>, C<link>, C<lstat>, C<msgctl>, C<msgget>, C<msgrcv>,
715L<C<flock>|/flock FILEHANDLE,OPERATION>, L<C<fork>|/fork>,
431C<msgsnd>, C<open>, C<pipe>, C<readlink>, C<rename>, C<select>, C<semctl>,
716L<C<getgrent>|/getgrent>, L<C<getgrgid>|/getgrgid GID>,
432C<semget>, C<semop>, C<setgrent>, C<sethostent>, C<setnetent>,
717L<C<gethostbyname>|/gethostbyname NAME>, L<C<gethostent>|/gethostent>,
433C<setpgrp>, C<setpriority>, C<setprotoent>, C<setpwent>,
718L<C<getlogin>|/getlogin>,
434C<setservent>, C<setsockopt>, C<shmctl>, C<shmget>, C<shmread>,
719L<C<getnetbyaddr>|/getnetbyaddr ADDR,ADDRTYPE>,
435C<shmwrite>, C<socket>, C<socketpair>, C<stat>, C<symlink>, C<syscall>,
720L<C<getnetbyname>|/getnetbyname NAME>, L<C<getnetent>|/getnetent>,
436C<sysopen>, C<system>, C<times>, C<truncate>, C<umask>, C<unlink>,
721L<C<getppid>|/getppid>, L<C<getpgrp>|/getpgrp PID>,
437C<utime>, C<wait>, C<waitpid>
722L<C<getpriority>|/getpriority WHICH,WHO>,
723L<C<getprotobynumber>|/getprotobynumber NUMBER>,
724L<C<getprotoent>|/getprotoent>, L<C<getpwent>|/getpwent>,
725L<C<getpwnam>|/getpwnam NAME>, L<C<getpwuid>|/getpwuid UID>,
726L<C<getservbyport>|/getservbyport PORT,PROTO>,
727L<C<getservent>|/getservent>,
728L<C<getsockopt>|/getsockopt SOCKET,LEVEL,OPTNAME>,
729L<C<glob>|/glob EXPR>, L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>,
730L<C<kill>|/kill SIGNAL, LIST>, L<C<link>|/link OLDFILE,NEWFILE>,
731L<C<lstat>|/lstat FILEHANDLE>, L<C<msgctl>|/msgctl ID,CMD,ARG>,
732L<C<msgget>|/msgget KEY,FLAGS>,
733L<C<msgrcv>|/msgrcv ID,VAR,SIZE,TYPE,FLAGS>,
734L<C<msgsnd>|/msgsnd ID,MSG,FLAGS>, L<C<open>|/open FILEHANDLE,EXPR>,
735L<C<pipe>|/pipe READHANDLE,WRITEHANDLE>, L<C<readlink>|/readlink EXPR>,
736L<C<rename>|/rename OLDNAME,NEWNAME>,
737L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>,
738L<C<semctl>|/semctl ID,SEMNUM,CMD,ARG>,
739L<C<semget>|/semget KEY,NSEMS,FLAGS>, L<C<semop>|/semop KEY,OPSTRING>,
740L<C<setgrent>|/setgrent>, L<C<sethostent>|/sethostent STAYOPEN>,
741L<C<setnetent>|/setnetent STAYOPEN>, L<C<setpgrp>|/setpgrp PID,PGRP>,
742L<C<setpriority>|/setpriority WHICH,WHO,PRIORITY>,
743L<C<setprotoent>|/setprotoent STAYOPEN>, L<C<setpwent>|/setpwent>,
744L<C<setservent>|/setservent STAYOPEN>,
745L<C<setsockopt>|/setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL>,
746L<C<shmctl>|/shmctl ID,CMD,ARG>, L<C<shmget>|/shmget KEY,SIZE,FLAGS>,
747L<C<shmread>|/shmread ID,VAR,POS,SIZE>,
748L<C<shmwrite>|/shmwrite ID,STRING,POS,SIZE>,
749L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL>,
750L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL>,
751L<C<stat>|/stat FILEHANDLE>, L<C<symlink>|/symlink OLDFILE,NEWFILE>,
752L<C<syscall>|/syscall NUMBER, LIST>,
753L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>,
754L<C<system>|/system LIST>, L<C<times>|/times>,
755L<C<truncate>|/truncate FILEHANDLE,LENGTH>, L<C<umask>|/umask EXPR>,
756L<C<unlink>|/unlink LIST>, L<C<utime>|/utime LIST>, L<C<wait>|/wait>,
757L<C<waitpid>|/waitpid PID,FLAGS>
758438
759439=begin original
760440
761441For more information about the portability of these functions, see
762442L<perlport> and other available platform-specific documentation.
763443
764444=end original
765445
766446これらの関数の移植性に関するさらなる情報については、
767L<perlport> とその他のプラットホーム固有のドキュメントを参照してください。
447L<perlport> とその他のプラットホーム固有のドキュメントを参照してさい。
768448
769449=head2 Alphabetical Listing of Perl Functions
770450
771=over
451=over 8
772452
773=item -X FILEHANDLE
453=item I<-X> FILEHANDLE
774X<-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>
775X<-S>X<-b>X<-c>X<-t>X<-u>X<-g>X<-k>X<-T>X<-B>X<-M>X<-A>X<-C>
776454
777=item -X EXPR
455=item I<-X> EXPR
778456
779=item -X DIRHANDLE
457=item I<-X>
780458
781=item -X
782
783=for Pod::Functions a file test (-r, -x, etc)
784
785459=begin original
786460
787461A file test, where X is one of the letters listed below. This unary
788operator takes one argument, either a filename, a filehandle, or a dirhandle,
462operator takes one argument, either a filename or a filehandle, and
789and tests the associated file to see if something is true about it. If the
463tests the associated file to see if something is true about it. If the
790argument is omitted, tests L<C<$_>|perlvar/$_>, except for C<-t>, which
464argument is omitted, tests C<$_>, except for C<-t>, which tests STDIN.
791tests STDIN. Unless otherwise documented, it returns C<1> for true and
465Unless otherwise documented, it returns C<1> for true and C<''> for false, or
792C<''> for false. If the file doesn't exist or can't be examined, it
466the undefined value if the file doesn't exist. Despite the funny
793returns L<C<undef>|/undef EXPR> and sets L<C<$!>|perlvar/$!> (errno).
467names, precedence is the same as any other named unary operator, and
794With the exception of the C<-l> test they all follow symbolic links
468the argument may be parenthesized like any other unary operator. The
795because they use C<stat()> and not C<lstat()> (so dangling symlinks can't
469operator may be any of:
796be examined and will therefore report failure).
797470
798471=end original
799472
800473X は以下にあげる文字で、ファイルテストを行ないます。
801この単項演算子は、ファイル名かファイルハンドルを唯一の引数として動作し、
474この単項演算子は、ファイル名かファイルハンドルを唯一の
802「あること」について真であるか否かを判定した結果を返します。
475引数として動作し、「あること」について真であるか否かを
803引数が省略されると、C<-t> では STDIN 調べますが、その他は
476判定した結果返します
804L<C<$_>|perlvar/$_> を調べます。
477引数が省略されると、C<-t> では STDIN を調べますが、その他は C<$_> を調べます。
805特に記述されていなければ、真として C<1> を返し、偽として C<''> を返します。
478特に記述されていなければ、真として C<1> を返し、偽として
806ファイルが存在しないか、テスト出来なければ、L<C<undef>|/undef EXPR> を返し
479C<''> を返し、ファイルが存在しなければ、未定義値を返します。
807L<C<$!>|perlvar/$!> (errno) を設定します。
808C<-l> テストを例外として、これら全てはシンボリックリンクに従います;
809C<lstat()> ではなく C<stat()> を使っているからです
810(従って壊れたシンボリックリンクは検査されず、失敗が報告されます)。
811
812=begin original
813
814Despite the funny names, precedence is the same as any other named unary
815operator. The operator may be any of:
816
817=end original
818
819480みかけは変わっていますが、優先順位は名前付き単項演算子と同じで、
820481他の単項演算子と同じく、引数を括弧で括ることもできます。
821482演算子には以下のものがあります:
822483
484X<-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>
485X<-S>X<-b>X<-c>X<-t>X<-u>X<-g>X<-k>X<-T>X<-B>X<-M>X<-A>X<-C>
486
823487=begin original
824488
825 -r File is readable by effective uid/gid.
489 -r File is readable by effective uid/gid.
826 -w File is writable by effective uid/gid.
490 -w File is writable by effective uid/gid.
827 -x File is executable by effective uid/gid.
491 -x File is executable by effective uid/gid.
828 -o File is owned by effective uid.
492 -o File is owned by effective uid.
829493
830494=end original
831495
832 -r ファイルが実効 uid/gid で読み出し可
496 -r ファイルが実効 uid/gid で読み出し可
833 -w ファイルが実効 uid/gid で書き込み可
497 -w ファイルが実効 uid/gid で書き込み可
834 -x ファイルが実効 uid/gid で実行可
498 -x ファイルが実効 uid/gid で実行可
835 -o ファイルが実効 uid の所有物
499 -o ファイルが実効 uid の所有物
836500
837501=begin original
838502
839 -R File is readable by real uid/gid.
503 -R File is readable by real uid/gid.
840 -W File is writable by real uid/gid.
504 -W File is writable by real uid/gid.
841 -X File is executable by real uid/gid.
505 -X File is executable by real uid/gid.
842 -O File is owned by real uid.
506 -O File is owned by real uid.
843507
844508=end original
845509
846 -R ファイルが実 uid/gid で読み出し可
510 -R ファイルが実 uid/gid で読み出し可
847 -W ファイルが実 uid/gid で書き込み可
511 -W ファイルが実 uid/gid で書き込み可
848 -X ファイルが実 uid/gid で実行可
512 -X ファイルが実 uid/gid で実行可
849 -O ファイルが実 uid の所有物
513 -O ファイルが実 uid の所有物
850514
851515=begin original
852516
853 -e File exists.
517 -e File exists.
854 -z File has zero size (is empty).
518 -z File has zero size (is empty).
855 -s File has nonzero size (returns size in bytes).
519 -s File has nonzero size (returns size in bytes).
856520
857521=end original
858522
859 -e ファイルが存在する
523 -e ファイルが存在する
860 -z ファイルの大きさがゼロ(空)
524 -z ファイルの大きさがゼロ(空)
861 -s ファイルの大きさがゼロ以外 (バイト単位での大きさを返す)
525 -s ファイルの大きさがゼロ以外 (バイト単位での大きさを返す)
862526
863527=begin original
864528
865 -f File is a plain file.
529 -f File is a plain file.
866 -d File is a directory.
530 -d File is a directory.
867 -l File is a symbolic link (false if symlinks aren't
531 -l File is a symbolic link.
868 supported by the file system).
532 -p File is a named pipe (FIFO), or Filehandle is a pipe.
869 -p File is a named pipe (FIFO), or Filehandle is a pipe.
533 -S File is a socket.
870 -S File is a socket.
534 -b File is a block special file.
871 -b File is a block special file.
535 -c File is a character special file.
872 -c File is a character special file.
536 -t Filehandle is opened to a tty.
873 -t Filehandle is opened to a tty.
874537
875538=end original
876539
877 -f ファイルは通常ファイル
540 -f ファイルは通常ファイル
878 -d ファイルはディレクトリ
541 -d ファイルはディレクトリ
879 -l ファイルはシンボリックリンク(ファイルシステムが非対応なら偽)。
542 -l ファイルはシンボリックリンク
880 -p ファイルは名前付きパイプ (FIFO) またはファイルハンドルはパイプ
543 -p ファイルは名前付きパイプ (FIFO) またはファイルハンドルはパイプ
881 -S ファイルはソケット
544 -S ファイルはソケット
882 -b ファイルはブロック特殊ファイル
545 -b ファイルはブロック特殊ファイル
883 -c ファイルはキャラクタ特殊ファイル
546 -c ファイルはキャラクタ特殊ファイル
884 -t ファイルハンドルは tty にオープンされている
547 -t ファイルハンドルは tty にオープンされている
885548
886549=begin original
887550
888 -u File has setuid bit set.
551 -u File has setuid bit set.
889 -g File has setgid bit set.
552 -g File has setgid bit set.
890 -k File has sticky bit set.
553 -k File has sticky bit set.
891554
892555=end original
893556
894 -u ファイルの setuid ビットがセットされている
557 -u ファイルの setuid ビットがセットされている
895 -g ファイルの setgid ビットがセットされている
558 -g ファイルの setgid ビットがセットされている
896 -k ファイルの sticky ビットがセットされている
559 -k ファイルの sticky ビットがセットされている
897560
898561=begin original
562 -T File is an ASCII text file.
563 -B File is a "binary" file (opposite of -T).
899564
900 -T File is an ASCII or UTF-8 text file (heuristic guess).
901 -B File is a "binary" file (opposite of -T).
902
903565=end original
904566
905 -T ファイルは ASCII または UTF-8 テキストファイル (発見的に推測します)。
567 -T ファイルは ASCII テキストファイル
906 -B ファイルは「バイナリ」ファイル (-T の反対)
568 -B ファイルは「バイナリ」ファイル (-T の反対)
907569
908570=begin original
909571
910 -M Script start time minus file modification time, in days.
572 -M Age of file in days when script started.
911 -A Same for access time.
573 -A Same for access time.
912 -C Same for inode change time (Unix, may differ for other
574 -C Same for inode change time.
913 platforms)
914575
915576=end original
916577
917 -M スクリプト実行開始時刻からファイル修正時刻を引いたも(単位)。
578 -M スクリプト実行開始時ファイル修正からの日
918 -A 同様にアクセスがあってからの日数
579 -A 同様にアクセスがあってからの日数
919 -C 同様に(Unix では) inode が変更されてからの日数(それ以外の
580 -C 同様に inode が変更されてからの日数
920 プラットフォームでは違うかもしれません)。
921581
922582=begin original
923583
924584Example:
925585
926586=end original
927587
928588例:
929589
930590 while (<>) {
931 chomp;
591 chomp;
932 next unless -f $_; # ignore specials
592 next unless -f $_; # ignore specials
933 #...
593 #...
934594 }
935595
936596=begin original
937597
938Note that C<-s/a/b/> does not do a negated substitution. Saying
939C<-exp($foo)> still works as expected, however: only single letters
940following a minus are interpreted as file tests.
941
942=end original
943
944C<-s/a/b> は、置換演算 (s///) の符号反転ではありません。
945しかし、C<-exp($foo)> は期待どおりに動作します; しかし、マイナス記号の後に
946英字が 1 字続くときにのみ、ファイルテストと解釈されます。
947
948=begin original
949
950These operators are exempt from the "looks like a function rule" described
951above. That is, an opening parenthesis after the operator does not affect
952how much of the following code constitutes the argument. Put the opening
953parentheses before the operator to separate it from code that follows (this
954applies only to operators with higher precedence than unary operators, of
955course):
956
957=end original
958
959これらの演算子は上述の「関数のように見えるルール」から免除されます。
960つまり、演算子の後の開きかっこは、引き続くコードのどこまでが引数を
961構成するかに影響を与えません。
962演算子を引き続くコードから分離するには、演算子の前に開きかっこを
963置いてください (これはもちろん、単項演算子より高い優先順位を持つ
964演算子にのみ適用されます):
965
966 -s($file) + 1024 # probably wrong; same as -s($file + 1024)
967 (-s $file) + 1024 # correct
968
969=begin original
970
971598The interpretation of the file permission operators C<-r>, C<-R>,
972599C<-w>, C<-W>, C<-x>, and C<-X> is by default based solely on the mode
973600of the file and the uids and gids of the user. There may be other
974reasons you can't actually read, write, or execute the file: for
601reasons you can't actually read, write, or execute the file. Such
975example network filesystem access controls, ACLs (access control lists),
602reasons may be for example network filesystem access controls, ACLs
976read-only filesystems, and unrecognized executable formats. Note
603(access control lists), read-only filesystems, and unrecognized
977that the use of these six specific operators to verify if some operation
604executable formats.
978is possible is usually a mistake, because it may be open to race
979conditions.
980605
981606=end original
982607
983608ファイルのパーミッション演算子 C<-r>, C<-R>, C<-w>, C<-W>, C<-x>,
984609C<-X> の解釈は、ファイルのモードとユーザの実効/実 uid と
985610実効/実 gid のみから判断されます。
986611実際にファイルが読めたり、書けたり、実行できたりするためには、
987別の条件が必要かもしれません:
612別の条件が必要かもしれません
988例えば、ネットワークファイルシステムアクセスコントロール、
613条件としてはネットワークファイルシステムアクセスコントロール、
989614ACL(アクセスコントロールリスト)、読み込み専用ファイルシステム、
990認識できない実行ファイルフォーマット、などす。
615認識できない実行ファイルフォーマット、などがあります。
991これらの 6 つの演算子を、特定の操作が可能かどうかを確認するために使うのは
992通常は誤りであることに注意してください; なぜなら、これらは競合条件を
993招きやすいからです。
994616
995617=begin original
996618
997619Also note that, for the superuser on the local filesystems, the C<-r>,
998620C<-R>, C<-w>, and C<-W> tests always return 1, and C<-x> and C<-X> return 1
999621if any execute bit is set in the mode. Scripts run by the superuser
1000may thus need to do a L<C<stat>|/stat FILEHANDLE> to determine the
622may thus need to do a stat() to determine the actual mode of the file,
1001actual mode of the file, or temporarily set their effective uid to
623or temporarily set their effective uid to something else.
1002something else.
1003624
1004625=end original
1005626
1006627ローカルファイルシステムのスーパーユーザには、
1007628C<-r>, C<-R>, C<-w>, C<-W> に対して、常に 1 が返り、モード中の
1008629いずれかの実行許可ビットが立っていれば、C<-x>, C<-X> にも 1 が
1009630返ることにも注意してください。
1010631スーパーユーザが実行するスクリプトでは、ファイルのモードを調べるためには、
1011L<C<stat>|/stat FILEHANDLE> を行なうか、実効 uid を一時的に別のものにする
632stat() を行なうか、実効 uid を一時的に別のものにする
1012633必要があるでしょう。
1013634
1014635=begin original
1015636
1016If you are using ACLs, there is a pragma called L<C<filetest>|filetest>
637If you are using ACLs, there is a pragma called C<filetest> that may
1017that may produce more accurate results than the bare
638produce more accurate results than the bare stat() mode bits.
1018L<C<stat>|/stat FILEHANDLE> mode bits.
639When under the C<use filetest 'access'> the above-mentioned filetests
1019When under C<use filetest 'access'>, the above-mentioned filetests
640will test whether the permission can (not) be granted using the
1020test whether the permission can(not) be granted using the L<access(2)>
641access() family of system calls. Also note that the C<-x> and C<-X> may
1021family of system calls. Also note that the C<-x> and C<-X> tests may
1022642under this pragma return true even if there are no execute permission
1023643bits set (nor any extra execute permission ACLs). This strangeness is
1024due to the underlying system calls' definitions. Note also that, due to
644due to the underlying system calls' definitions. Read the
1025the implementation of C<use filetest 'access'>, the C<_> special
645documentation for the C<filetest> pragma for more information.
1026filehandle won't cache the results of the file tests when this pragma is
1027in effect. Read the documentation for the L<C<filetest>|filetest>
1028pragma for more information.
1029646
1030647=end original
1031648
1032ACL を使っている場合は、生の L<C<stat>|/stat FILEHANDLE> モードビットより
649ACL を使っている場合は、生の stat() モードビットより
1033精度の高い結果を作成する L<C<filetest>|filetest> プラグマがあります。
650精度の高い結果を作成する C<filetest> プラグマがあります。
1034651C<use filetest 'access'> とした場合、上述したファイルテストは
1035システムコールの L<access(2)> ファミリーを使って権限が与えられているか
652システムコールの access() ファミリーを使って権限が与えられているか
1036653どうかをテストします。
1037また、このプラグマが指定されている場合、C<-x> と C<-X> テスト
654また、このプラグマが指定されている場合、C<-x> と C<-X> は
1038655たとえ実行許可ビット(または追加の実行許可 ACL)がセットされていない
1039656場合でも真を返すことに注意してください。
1040657この挙動は使用するシステムコールの定義によるものです。
1041C<use filetest 'access'> の実装により、このプラグマが有効場合は
658さらなる情報については C<filetest> プラグマのドキュメントを
1042C<_> 特殊ファイルハンドルはファイルテストの結果をキャッシュしないことに
1043注意してください。
1044さらなる情報については L<C<filetest>|filetest> プラグマのドキュメントを
1045659参照してください。
1046660
1047661=begin original
1048662
1049The C<-T> and C<-B> tests work as follows. The first block or so of
663Note that C<-s/a/b/> does not do a negated substitution. Saying
1050the file is examined to see if it is valid UTF-8 that includes non-ASCII
664C<-exp($foo)> still works as expected, however--only single letters
1051characters. If so, it's a C<-T> file. Otherwise, that same portion of
665following a minus are interpreted as file tests.
1052the file is examined for odd characters such as strange control codes or
1053characters with the high bit set. If more than a third of the
667=end original
1054characters are strange, it's a C<-B> file; otherwise it's a C<-T> file.
1055Also, any file containing a zero byte in the examined portion is
669C<-s/a/b> は、置換演算 (s///) の符号反転ではありません。
1056considered a binary file. (If executed within the scope of a L<S<use
670しかし、C<-exp($foo)> は期待どおりに動作します。
1057locale>|perllocale> which includes C<LC_CTYPE>, odd characters are
671マイナス記号の後に英字が 1 字続くときにのみ、ファイルテストと
1058anything that isn't a printable nor space in the current locale.) If
672解釈されます。
1059C<-T> or C<-B> is used on a filehandle, the current IO buffer is
1060examined
674=begin original
1061rather than the first block. Both C<-T> and C<-B> return true on an empty
676The C<-T> and C<-B> switches work as follows. The first block or so of the
677file is examined for odd characters such as strange control codes or
678characters with the high bit set. If too many strange characters (>30%)
679are found, it's a C<-B> file, otherwise it's a C<-T> file. Also, any file
680containing null in the first block is considered a binary file. If C<-T>
681or C<-B> is used on a filehandle, the current stdio buffer is examined
682rather than the first block. Both C<-T> and C<-B> return true on a null
1062683file, or a file at EOF when testing a filehandle. Because you have to
1063684read a file to do the C<-T> test, on most occasions you want to use a C<-f>
1064685against the file first, as in C<next unless -f $file && -T $file>.
1065686
1066687=end original
1067688
1068689ファイルテスト C<-T> と C<-B> の動作原理は、次のようになっています。
1069ファイルの最初の数ブロックを調べて、非 ASCII 文字を含む妥当な UTF-8 かどうかを
690ファイルの最初の数ブロックを調べて、変わった制御コードや
1070調べます。
1071もしそうなら、それは C<-T> ファイルです。
1072さもなければ、ファイルの同じ位置から、変わった制御コードや
1073691上位ビットがセットされているような、通常のテキストには現れない文字を探します。
1074三分一以上がおかしな文字ならそれは C<-B> ファイルです;
692ような文字たくさん (>30%) 見つかるようあれば、
1075さもなければ C<-T> ファイルです。
693そのファイルは C<-B> ファイルであると判断され、
1076また、調べた位置にヌル文字が含まるファイルもバイナリファイルと
694ほど見つからなければC<-T> ファイルとなります。
1077みなされす。
695最初のブロックにヌル文字が含れるファイルも、
1078(C<LC_CTYPE> を含む L<S<use locale>|perllocale> のスコープの中で実行されると、
696バイナリファイルとみなされます。
1079おかしな文字というのは現在のロケールで表示可能でもスペースでもないものです。)
1080697C<-T> や C<-B> をファイルハンドルに対して用いると、
1081最初のブロックを調べる代わりに、IO バッファを調べます。
698最初のブロックを調べる代わりに、標準入出力バッファを調べます。
1082699調べたファイルの中身が何もないときや、
1083700ファイルハンドルを調べたときに EOF に達して
1084701いたときには、C<-T> も C<-B> も「真」を返します。
1085702C<-T> テストをするためにはファイルを読み込まないといけないので、
1086703たいていは C<next unless -f $file && -T $file> というような形で
1087704まず調べたいファイルに対して C<-f> を使いたいはずです。
1088705
1089706=begin original
1090707
1091If any of the file tests (or either the L<C<stat>|/stat FILEHANDLE> or
708If any of the file tests (or either the C<stat> or C<lstat> operators) are given
1092L<C<lstat>|/lstat FILEHANDLE> operator) is given the special filehandle
709the special filehandle consisting of a solitary underline, then the stat
1093consisting of a solitary underline, then the stat structure of the
710structure of the previous file test (or stat operator) is used, saving
1094previous file test (or L<C<stat>|/stat FILEHANDLE> operator) is used,
711a system call. (This doesn't work with C<-t>, and you need to remember
1095saving a system call. (This doesn't work with C<-t>, and you need to
712that lstat() and C<-l> will leave values in the stat structure for the
1096remember that L<C<lstat>|/lstat FILEHANDLE> and C<-l> leave values in
713symbolic link, not the real file.) Example:
1097the stat structure for the symbolic link, not the real file.) (Also, if
1098the stat buffer was filled by an L<C<lstat>|/lstat FILEHANDLE> call,
1099C<-T> and C<-B> will reset it with the results of C<stat _>).
1100Example:
1101714
1102715=end original
1103716
1104どのファイルテスト (あるいは、L<C<stat>|/stat FILEHANDLE>
717どのファイルテスト (あるいは、C<stat> や C<lstat>) 演算子にも、
1105L<C<lstat>|/lstat FILEHANDLE>) 演算子にも、
1106718下線だけから成る特別なファイルハンドルを与えると、
1107前回のファイルテスト (や L<C<stat>|/stat FILEHANDLE> 演算子) の
719前回のファイルテスト (や stat) の stat 構造体が使われ、
1108stat 構造体が使われ、システムコールを省きます。
720システムコールを省きます。
1109(C<-t> には使えませんし、L<C<lstat>|/lstat FILEHANDLE> や C<-l> は
721(C<-t> には使えませんし、lstat() や C<-l> は実ファイルではなく、
1110実ファイルではなく、シンボリックリンクの情報を stat 構造体に残すことを
722シンボリックリンクの情報を stat 構造体に残すことを
1111覚えておく必要があります。)
723覚えておく必要があります。)例:
1112(また、stat バッファが L<C<lstat>|/lstat FILEHANDLE> 呼び出しで埋まった場合、
1113C<-T> と C<-B> の結果は C<stat _> の結果でリセットされます。
1114例:
1115724
1116725 print "Can do.\n" if -r $a || -w _ || -x _;
1117726
1118727 stat($filename);
1119728 print "Readable\n" if -r _;
1120729 print "Writable\n" if -w _;
1121730 print "Executable\n" if -x _;
1122731 print "Setuid\n" if -u _;
1123732 print "Setgid\n" if -g _;
1124733 print "Sticky\n" if -k _;
1125734 print "Text\n" if -T _;
1126735 print "Binary\n" if -B _;
1127736
1128=begin original
1129
1130As of Perl 5.10.0, as a form of purely syntactic sugar, you can stack file
1131test operators, in a way that C<-f -w -x $file> is equivalent to
1132C<-x $file && -w _ && -f _>. (This is only fancy syntax: if you use
1133the return value of C<-f $file> as an argument to another filetest
1134operator, no special magic will happen.)
1135
1136=end original
1137
1138Perl 5.10.0 から、純粋にシンタックスシュガーとして、ファイルテスト演算子を
1139スタックさせることができるので、C<-f -w -x $file> は
1140C<-x $file && -w _ && -f _> と等価です。
1141(これは文法上だけの話です; もし C<-f $file> の返り値を他のファイルテスト
1142演算子の引数として使う場合は、何の特別なことも起きません。)
1143
1144=begin original
1145
1146Portability issues: L<perlport/-X>.
1147
1148=end original
1149
1150移植性の問題: L<perlport/-X>。
1151
1152=begin original
1153
1154To avoid confusing would-be users of your code with mysterious
1155syntax errors, put something like this at the top of your script:
1156
1157=end original
1158
1159あなたのコードのユーザーが不思議な文法エラーで混乱することを
1160避けるために、スクリプトの先頭に以下のようなことを書いてください:
1161
1162 use 5.010; # so filetest ops can stack
1163
1164737=item abs VALUE
1165X<abs> X<absolute>
1166738
1167739=item abs
1168740
1169=for Pod::Functions absolute value function
1170
1171741=begin original
1172742
1173743Returns the absolute value of its argument.
1174If VALUE is omitted, uses L<C<$_>|perlvar/$_>.
744If VALUE is omitted, uses C<$_>.
1175745
1176746=end original
1177747
1178748引数の絶対値を返します。
1179VALUE が省略された場合は、L<C<$_>|perlvar/$_> を使います。
749VALUE が省略された場合は、C<$_> を使います。
1180750
1181751=item accept NEWSOCKET,GENERICSOCKET
1182X<accept>
1183752
1184=for Pod::Functions accept an incoming socket connect
1185
1186753=begin original
1187754
1188Accepts an incoming socket connect, just as L<accept(2)>
755Accepts an incoming socket connect, just as the accept(2) system call
1189756does. Returns the packed address if it succeeded, false otherwise.
1190757See the example in L<perlipc/"Sockets: Client/Server Communication">.
1191758
1192759=end original
1193760
1194L<accept(2)> システムコールと同様に、着信するソケットの接続を受け付けます。
761accept(2) システムコールと同様に、着信するソケットの接続を受け付けます。
1195762成功時にはパックされたアドレスを返し、失敗すれば偽を返します。
1196L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
763L<perlipc/"Sockets: Client/Server Communication"> の
764例を参照してください。
1197765
1198766=begin original
1199767
1200768On systems that support a close-on-exec flag on files, the flag will
1201769be set for the newly opened file descriptor, as determined by the
1202value of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>.
770value of $^F. See L<perlvar/$^F>.
1203771
1204772=end original
1205773
1206774ファイルに対する close-on-exec フラグをサポートしているシステムでは、
1207フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた
775フラグは $^F の値で決定される、新しくオープンされたファイル記述子に対して
1208ファイル記述子に対してセットされます。
776セットされます。L<perlvar/$^F> を参照してください
1209L<perlvar/$^F> を参照してください。
1210777
1211778=item alarm SECONDS
1212X<alarm>
1213X<SIGALRM>
1214X<timer>
1215779
1216780=item alarm
1217781
1218=for Pod::Functions schedule a SIGALRM
1219
1220782=begin original
1221783
1222784Arranges to have a SIGALRM delivered to this process after the
1223specified number of wallclock seconds has elapsed. If SECONDS is not
785specified number of seconds have elapsed. If SECONDS is not specified,
1224specified, the value stored in L<C<$_>|perlvar/$_> is used. (On some
786the value stored in C<$_> is used. (On some machines,
1225machines, unfortunately, the elapsed time may be up to one second less
787unfortunately, the elapsed time may be up to one second less than you
1226or more than you specified because of how seconds are counted, and
788specified because of how seconds are counted.) Only one timer may be
1227process scheduling may delay the delivery of the signal even further.)
789counting at once. Each call disables the previous timer, and an
790argument of C<0> may be supplied to cancel the previous timer without
791starting a new one. The returned value is the amount of time remaining
792on the previous timer.
1228793
1229794=end original
1230795
1231指定した壁時計秒数が経過した後に、自プロセスに SIGALRM が
796指定した秒数が経過した後に、自プロセスに SIGALRM が
1232送られてくるようにします。
797送られてくるようにします。SECONDS が指定されていない場合は、
1233SECONDS が指定されていない場合は、L<C<$_>|perlvar/$_> に格納されている値を
798C<$_>に格納されている値を使います。
1234使います。
799(マシンによっては、秒の
1235(マシンによっては、秒の数え方が異なるため、指定した秒数よりも最大で
800数え方が異なるため、指定した秒数よりも最大で 1 秒少ない経過時間となります。)
12361 秒ずれます。)
801一度には 1 つのタイマだけが設定可能です。
1237
1238=begin original
1239
1240Only one timer may be counting at once. Each call disables the
1241previous timer, and an argument of C<0> may be supplied to cancel the
1242previous timer without starting a new one. The returned value is the
1243amount of time remaining on the previous timer.
1244
1245=end original
1246
1247一度には一つのタイマだけが設定可能です。
1248802呼び出しを行なう度に、以前のタイマを無効にしますし、
1249803新しくタイマを起動しないで以前のタイマをキャンセルするために
1250804引数に C<0> を指定して呼び出すことができます。
1251805以前のタイマの残り時間が、返り値となります。
1252806
1253807=begin original
1254808
1255For delays of finer granularity than one second, the L<Time::HiRes> module
809For delays of finer granularity than one second, you may use Perl's
1256(from CPAN, and starting from Perl 5.8 part of the standard
810four-argument version of select() leaving the first three arguments
1257distribution) provides
811undefined, or you might be able to use the C<syscall> interface to
1258L<C<ualarm>|Time::HiRes/ualarm ( $useconds [, $interval_useconds ] )>.
812access setitimer(2) if your system supports it. The Time::HiRes module
1259You may also use Perl's four-argument version of
813from CPAN may also prove useful.
1260L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> leaving the first three
1261arguments undefined, or you might be able to use the
1262L<C<syscall>|/syscall NUMBER, LIST> interface to access L<setitimer(2)>
1263if your system supports it. See L<perlfaq8> for details.
1264814
1265815=end original
1266816
12671 秒より精度の高いスリープを行なうには、L<Time::HiRes> モジュール(CPAN から、
8171 秒より精度の高いスリープを行なうには、
1268また Perl 5.8 からは標準配布されています)
818Perl 4 引数版 select() を最初の 3 引数を未定義にして使うか、
1269L<C<usleep>|Time::HiRes/usleep ( $useconds )>提供ます。
819setitimer(2) をサポートているシステムでは、Perl の
1270Perl の 4 引数版 L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を最初の
820C<syscall> インタフェース使ってアクセスすることができます。
12713 引数を未定義にして使うか、L<setitimer(2)> をサポトしているシステムは、
821CPAN の Time::HiRes モジュルも有用しょう。
1272Perl の L<C<syscall>|/syscall NUMBER, LIST> インタフェースを使って
1273アクセスすることもできます。
1274詳しくは L<perlfaq8> を参照してください。
1275822
1276823=begin original
1277824
1278It is usually a mistake to intermix L<C<alarm>|/alarm SECONDS> and
825It is usually a mistake to intermix C<alarm> and C<sleep> calls.
1279L<C<sleep>|/sleep EXPR> calls, because L<C<sleep>|/sleep EXPR> may be
826(C<sleep> may be internally implemented in your system with C<alarm>)
1280internally implemented on your system with L<C<alarm>|/alarm SECONDS>.
1281827
1282828=end original
1283829
1284L<C<alarm>|/alarm SECONDS> L<C<sleep>|/sleep EXPR> を混ぜて使うのは
830C<alarm> と C<sleep> を混ぜて使うのは普通は間違いです。
1285普通は間違いです; なぜなら、L<C<sleep>|/sleep EXPR> 内部的に
831(C<sleep> は内部的に C<alarm> を使って内部的に実装されているかもしれません)
1286L<C<alarm>|/alarm SECONDS> を使って内部的に実装されているかも
1287しれないからです。
1288832
1289833=begin original
1290834
1291If you want to use L<C<alarm>|/alarm SECONDS> to time out a system call
835If you want to use C<alarm> to time out a system call you need to use an
1292you need to use an L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> pair. You
836C<eval>/C<die> pair. You can't rely on the alarm causing the system call to
1293can't rely on the alarm causing the system call to fail with
837fail with C<$!> set to C<EINTR> because Perl sets up signal handlers to
1294L<C<$!>|perlvar/$!> set to C<EINTR> because Perl sets up signal handlers
838restart system calls on some systems. Using C<eval>/C<die> always works,
1295to restart system calls on some systems. Using
839modulo the caveats given in L<perlipc/"Signals">.
1296L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> always works, modulo the
1297caveats given in L<perlipc/"Signals">.
1298840
1299841=end original
1300842
1301L<C<alarm>|/alarm SECONDS> をシステムコールの時間切れのために使いたいなら、
843C<alarm> をシステムコールの時間切れのために使いたいなら、
1302L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> のペアで使う必要があります。
844C<eval>/C<die> のペアで使う必要があります。
1303システムコールが失敗したときに L<C<$!>|perlvar/$!> に C<EINTR> が
845システムコールが失敗したときに C<$!> に C<EINTR> がセットされることに
1304セットされることに頼ってはいけません; なぜならシステムによっては Perl は
846頼ってはいけませんなぜならシステムによっては Perl は
1305847システムコールを再開するためにシグナルハンドラを設定するからです。
1306L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> は常にうまく動きます;
848C<eval>/C<die> は常にうまく動きます
1307注意点については L<perlipc/"Signals"> を参照してください。
849注意点については L<perlipc/"Signals"> を参照してさい。
1308850
1309851 eval {
1310 local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
852 local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
1311 alarm $timeout;
853 alarm $timeout;
1312 my $nread = sysread $socket, $buffer, $size;
854 $nread = sysread SOCKET, $buffer, $size;
1313 alarm 0;
855 alarm 0;
1314856 };
1315857 if ($@) {
1316 die unless $@ eq "alarm\n"; # propagate unexpected errors
858 die unless $@ eq "alarm\n"; # propagate unexpected errors
1317 # timed out
859 # timed out
1318860 }
1319861 else {
1320 # didn't
862 # didn't
1321863 }
1322864
1323=begin original
1324
1325For more information see L<perlipc>.
1326
1327=end original
1328
1329さらなる情報については L<perlipc> を参照してください。
1330
1331=begin original
1332
1333Portability issues: L<perlport/alarm>.
1334
1335=end original
1336
1337移植性の問題: L<perlport/alarm>。
1338
1339865=item atan2 Y,X
1340X<atan2> X<arctangent> X<tan> X<tangent>
1341866
1342=for Pod::Functions arctangent of Y/X in the range -PI to PI
1343
1344867=begin original
1345868
1346869Returns the arctangent of Y/X in the range -PI to PI.
1347870
1348871=end original
1349872
1350873-πからπの範囲で Y/X の逆正接を返します。
1351874
1352875=begin original
1353876
1354For the tangent operation, you may use the
877For the tangent operation, you may use the C<Math::Trig::tan>
1355L<C<Math::Trig::tan>|Math::Trig/B<tan>> function, or use the familiar
878function, or use the familiar relation:
1356relation:
1357879
1358880=end original
1359881
1360正接を求めたいときは、L<C<Math::Trig::tan>|Math::Trig/B<tan>> を使うか、
882正接を求めたいときは、C<Math::Trig::tan> を使うか、
1361883以下のよく知られた関係を使ってください。
1362884
1363885 sub tan { sin($_[0]) / cos($_[0]) }
1364886
1365=begin original
1366
1367The return value for C<atan2(0,0)> is implementation-defined; consult
1368your L<atan2(3)> manpage for more information.
1369
1370=end original
1371
1372C<atan2(0,0)> の返り値は実装依存です; さらなる情報については
1373L<atan2(3)> man ページを参照してください。
1374
1375=begin original
1376
1377Portability issues: L<perlport/atan2>.
1378
1379=end original
1380
1381移植性の問題: L<perlport/atan2>。
1382
1383887=item bind SOCKET,NAME
1384X<bind>
1385888
1386=for Pod::Functions binds an address to a socket
1387
1388889=begin original
1389890
1390Binds a network address to a socket, just as L<bind(2)>
891Binds a network address to a socket, just as the bind system call
1391892does. Returns true if it succeeded, false otherwise. NAME should be a
1392893packed address of the appropriate type for the socket. See the examples in
1393894L<perlipc/"Sockets: Client/Server Communication">.
1394895
1395896=end original
1396897
1397L<bind(2)> システムコールと同様に、ネットワークアドレスをソケットに
898bind(2) システムコールと同様に、ネットワークアドレスをソケットに結び付けます。
1398結び付けます。
899成功時には真を返し、失敗時には偽を返します。
1399成功時に真を、さなければ偽を返し
900NAME は、ソケットに対する、適切な型のパックれたアドレスでなければなりせん
1400NAME は、ソケットに対する、適切な型のパックされた
1401アドレスでなければなりません。
1402901L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
1403902
1404=item binmode FILEHANDLE, LAYER
903=item binmode FILEHANDLE, DISCIPLINE
1405X<binmode> X<binary> X<text> X<DOS> X<Windows>
1406904
1407905=item binmode FILEHANDLE
1408906
1409=for Pod::Functions prepare binary files for I/O
1410
1411907=begin original
1412908
1413Arranges for FILEHANDLE to be read or written in "binary" or "text"
909Arranges for FILEHANDLE to be read or written in "binary" or "text" mode
1414mode on systems where the run-time libraries distinguish between
910on systems where the run-time libraries distinguish between binary and
1415binary and text files. If FILEHANDLE is an expression, the value is
911text files. If FILEHANDLE is an expression, the value is taken as the
1416taken as the name of the filehandle. Returns true on success,
912name of the filehandle. DISCIPLINE can be either of C<":raw"> for
1417otherwise it returns L<C<undef>|/undef EXPR> and sets
913binary mode or C<":crlf"> for "text" mode. If the DISCIPLINE is
1418L<C<$!>|perlvar/$!> (errno).
914omitted, it defaults to C<":raw">.
1419915
1420916=end original
1421917
1422918バイナリファイルとテキストファイルを区別する OS において、
1423919FILEHANDLE を「バイナリ」または「テキスト」で読み書きするように
1424920指定します。
1425921FILEHANDLE が式である場合には、その式の値がファイルハンドルの
1426922名前として使われます。
1427成功時に返し、失敗時には L<C<undef>|/undef EXPR> を返して
923DISCIPLINE バイナリモード示す C<":raw">
1428L<C<$!>|perlvar/$!> (errno) を設定します。
924テキストモードを示す C<":crlf"> のどちらかです。
925DISCIPLINE を省略すると、デフォルトとして C<":raw"> が使われます。
1429926
1430927=begin original
1431928
1432On some systems (in general, DOS- and Windows-based systems)
929binmode() should be called after open() but before any I/O is done on
1433L<C<binmode>|/binmode FILEHANDLE, LAYER> is necessary when you're not
930the filehandle.
1434working with a text file. For the sake of portability it is a good idea
1435always to use it when appropriate, and never to use it when it isn't
1436appropriate. Also, people can set their I/O to be by default
1437UTF8-encoded Unicode, not bytes.
1438931
1439932=end original
1440933
1441テキストファイルでないものを扱う場合
934binmode() は open() の後、ファイルハンドル対する入出力が
1442L<C<binmode>|/binmode FILEHANDLE, LAYER> が必要な
935行われる前に呼び出されるべきです。
1443システムもあります(一般的には DOS と Windows ベースのシステムです)。
1444移植性のために、適切なときには常にこれを使い、適切でないときには
1445決して使わないというのは良い考えです。
1446また、デフォルトとして I/O を bytes ではなく UTF-8 エンコードされた
1447Unicode にセットすることも出来ます。
1448936
1449937=begin original
1450938
1451In other words: regardless of platform, use
939On many systems binmode() currently has no effect, but in future, it
1452L<C<binmode>|/binmode FILEHANDLE, LAYER> on binary data, like images,
940will be extended to support user-defined input and output disciplines.
1453for example.
941On some systems binmode() is necessary when you're not working with a
942text file. For the sake of portability it is a good idea to always use
943it when appropriate, and to never use it when it isn't appropriate.
1454944
1455945=end original
1456946
1457言い換える: プラットフォームに関わらず
947多くのシステムでは現在のころ binmode() は何の効果もありませんが
1458例えばイメジのようなバイナリファイル対しては
948将来ユザーが定義した入出力機能に対応するように拡張される予定です。
1459L<C<binmode>|/binmode FILEHANDLE, LAYER> を使ってください。
949テキストファイルでないものを扱う場合に binmode() が必要な
950システムもあります。
951移植性のために、適切なときには常にこれを使い、適切でないときには
952決して使わないというのは良い考えです。
1460953
1461954=begin original
1462955
1463If LAYER is present it is a single string, but may contain multiple
956In other words: Regardless of platform, use binmode() on binary
1464directives. The directives alter the behaviour of the filehandle.
957files, and do not use binmode() on text files.
1465When LAYER is present, using binmode on a text file makes sense.
1466958
1467959=end original
1468960
1469LAYER が存在すると、それは単一の文字列ですが、複数の指示子を
961言い換えると: プラットフォームに関わらず
1470含むことができます
962バイナリファイルに対しては binmode() を使ってください
1471指示子はファイルハンドルの振る舞い変更します
963テキストファイルには binmode() 使わないでください
1472LAYER が存在すると、テキストファイルでの binmode が意味を持ちます。
1473964
1474965=begin original
1475966
1476If LAYER is omitted or specified as C<:raw> the filehandle is made
967The C<open> pragma can be used to establish default disciplines.
1477suitable for passing binary data. This includes turning off possible CRLF
968See L<open>.
1478translation and marking it as bytes (as opposed to Unicode characters).
1479Note that, despite what may be implied in I<"Programming Perl"> (the
1480Camel, 3rd edition) or elsewhere, C<:raw> is I<not> simply the inverse of C<:crlf>.
1481Other layers that would affect the binary nature of the stream are
1482I<also> disabled. See L<PerlIO>, L<perlrun>, and the discussion about the
1483PERLIO environment variable.
1484969
1485970=end original
1486971
1487LAYER が省略されたり、C<:raw> が指定されると、ファイハンドルはバイナリ
972C<open> プラグマを使ってトの動作を設定できます。
1488データの通過に適するように設定れます
973L<open> を参照して下
1489これには CRLF 変換をオフにしたり、それぞれを(Unicode 文字ではなく)
1490バイトであるとマークしたりすることを含みます。
1491I<"プログラミング Perl">(ラクダ本第三版) やその他で暗示されているにも関わらず、
1492C<:raw> は単なる C<:crlf> の I<逆ではありません>。
1493ストリームのバイナリとしての性質に影響を与える
1494I<その他の層も無効にされます>。
1495L<PerlIO>, L<perlrun> およびPERLIO 環境変数に関する議論を参照してください。
1496974
1497975=begin original
1498976
1499The C<:bytes>, C<:crlf>, C<:utf8>, and any other directives of the
1500form C<:...>, are called I/O I<layers>. The L<open> pragma can be used to
1501establish default I/O layers.
1502
1503=end original
1504
1505C<:bytes>, C<:crlf>, and C<:utf8>, 及びその他の C<:...> 形式の指示子は
1506I/O I<層> が呼び出されます。
1507L<open> プラグマはデフォルト I/O 層を指定するために使われます。
1508
1509=begin original
1510
1511I<The LAYER parameter of the L<C<binmode>|/binmode FILEHANDLE, LAYER>
1512function is described as "DISCIPLINE" in "Programming Perl, 3rd
1513Edition". However, since the publishing of this book, by many known as
1514"Camel III", the consensus of the naming of this functionality has moved
1515from "discipline" to "layer". All documentation of this version of Perl
1516therefore refers to "layers" rather than to "disciplines". Now back to
1517the regularly scheduled documentation...>
1518
1519=end original
1520
1521I<L<C<binmode>|/binmode FILEHANDLE, LAYER> 関数の LAYER パラメータは
1522「プログラミングPerl 第 3 版」では
1523「ディシプリン(DISCIPLINE)」と表現されていました。
1524しかし、「ラクダ本第 3 版」として知られているこの本の出版後、この機能の名前は
1525「ディシプリン」から「層」に変更することで合意されました。
1526従って、このバージョンの Perl の全ての文書では「ディシプリン」ではなく
1527「層」と記述されています。では通常の解説に戻ります…>
1528
1529=begin original
1530
1531To mark FILEHANDLE as UTF-8, use C<:utf8> or C<:encoding(UTF-8)>.
1532C<:utf8> just marks the data as UTF-8 without further checking,
1533while C<:encoding(UTF-8)> checks the data for actually being valid
1534UTF-8. More details can be found in L<PerlIO::encoding>.
1535
1536=end original
1537
1538FILEHANDLE が UTF-8 であるというマークをつけるには、C<:utf8> か
1539C<:encoding(UTF-8)> を使ってください。
1540C<:utf8> は、さらなるチェックなしにデータが UTF-8 としてマークしますが、
1541C<:encoding(UTF-8)> はデータが実際に有効な UTF-8 かどうかをチェックします。
1542さらなる詳細は L<PerlIO::encoding> にあります。
1543
1544=begin original
1545
1546In general, L<C<binmode>|/binmode FILEHANDLE, LAYER> should be called
1547after L<C<open>|/open FILEHANDLE,EXPR> but before any I/O is done on the
1548filehandle. Calling L<C<binmode>|/binmode FILEHANDLE, LAYER> normally
1549flushes any pending buffered output data (and perhaps pending input
1550data) on the handle. An exception to this is the C<:encoding> layer
1551that changes the default character encoding of the handle.
1552The C<:encoding> layer sometimes needs to be called in
1553mid-stream, and it doesn't flush the stream. C<:encoding>
1554also implicitly pushes on top of itself the C<:utf8> layer because
1555internally Perl operates on UTF8-encoded Unicode characters.
1556
1557=end original
1558
1559一般的に L<C<binmode>|/binmode FILEHANDLE, LAYER> は
1560L<C<open>|/open FILEHANDLE,EXPR> を呼び出した後、このファイルハンドルに対する
1561I/O 操作をする前に呼び出すべきです。
1562L<C<binmode>|/binmode FILEHANDLE, LAYER> を呼び出すと、普通はこの
1563ファイルハンドルに対してバッファリングされている全ての出力データ
1564(およびおそらくは入力データ)をフラッシュします。
1565例外は、このハンドルに対するデフォルト文字エンコーディングを変更する
1566C<:encoding> 層です。
1567C<:encoding> 層はストリームの途中で呼び出す必要があることがあり、
1568それによってストリームはフラッシュされません。
1569Perl は内部で UTF-8 エンコードされた Unicode 文字を操作しているので、
1570C<:encoding> は暗黙のうちに自身を C<:utf8> 層の上に押し上げます。
1571
1572=begin original
1573
1574977The operating system, device drivers, C libraries, and Perl run-time
1575system all conspire to let the programmer treat a single
978system all work together to let the programmer treat a single
1576character (C<\n>) as the line terminator, irrespective of external
979character (C<\n>) as the line terminator, irrespective of the external
1577980representation. On many operating systems, the native text file
1578981representation matches the internal representation, but on some
1579982platforms the external representation of C<\n> is made up of more than
1580983one character.
1581984
1582985=end original
1583986
1584987オペレーティングシステム、デバイスドライバ、C ライブラリ、
1585988Perl ランタイムシステムは全て、プログラマが外部表現に関わらず
15869891 文字 (C<\n>) を行終端として扱えるように協調作業します。
1587990多くのオペレーティングシステムでは、ネイティブテキストファイル表現は
1588991内部表現と同じですが、C<\n> の外部表現が複数文字になる
1589992プラットフォームもあります。
1590993
1591994=begin original
1592995
1593All variants of Unix, Mac OS (old and new), and Stream_LF files on VMS use
996Mac OS and all variants of Unix use a single character to end each line
1594a single character to end each line in the external representation of text
997in the external representation of text (even though that single
1595(even though that single character is CARRIAGE RETURN on old, pre-Darwin
998character is not necessarily the same across these platforms).
1596flavors of Mac OS, and is LINE FEED on Unix and most VMS files). In other
999Consequently binmode() has no effect on these operating systems. In
1597systems like OS/2, DOS, and the various flavors of MS-Windows, your program
1000other systems like VMS, MS-DOS and the various flavors of MS-Windows
1598sees a C<\n> as a simple C<\cJ>, but what's stored in text files are the
1001your program sees a C<\n> as a simple C<\cJ>, but what's stored in text
1599two characters C<\cM\cJ>. That means that if you don't use
1002files are the two characters C<\cM\cJ>. That means that, if you don't
1600L<C<binmode>|/binmode FILEHANDLE, LAYER> on these systems, C<\cM\cJ>
1003use binmode() on these systems, C<\cM\cJ> sequences on disk will be
1601sequences on disk will be converted to C<\n> on input, and any C<\n> in
1004converted to C<\n> on input, and any C<\n> in your program will be
1602your program will be converted back to C<\cM\cJ> on output. This is
1005converted back to C<\cM\cJ> on output. This is what you want for text
1603what you want for text files, but it can be disastrous for binary files.
1006files, but it can be disastrous for binary files.
16041007
16051008=end original
16061009
1607全ての Unix 系、(新旧)Mac OS、VMS Stream_LF ファイルは
1010Mac OS と全ての Unix 系はテキスト外部表現として各行末尾に 1 つの文字を
1608テキストの外部表現とし各行末尾に一つの文字
1011使っいます(その文字はプラットフォームによって異なる場合もあります)。
1609使っています(しかしその文字は古い Darwin 以前Mac OS では復帰で、
1012その結果、binmode() はこれらの OS では何の効果もありません。
1610Unix とほとんどのVMS のファイルでは改行です)。
16111013VMS, MS-DOS, MS-Windows 系といったその他のシステムでは、
16121014プログラムからは C<\n> は単純に C<\cJ> に見えますが、
16131015テキストファイルとして保存される場合は C<\cM\cJ> の 2 文字になります。
1614つまり、もしこれらのシステムで L<C<binmode>|/binmode FILEHANDLE, LAYER>
1016つまり、もしこれらのシステムで binmode()使わないと、
1615使わないと、ディスク上の C<\cM\cJ> という並びは入力時に C<\n> に変換され、
1017ディスク上の C<\cM\cJ> という並びは入力時に C<\n> に変換され、
16161018プログラムが出力した全ての C<\n> は C<\cM\cJ> に逆変換されます。
16171019これはテキストファイルの場合は思い通りの結果でしょうが、
16181020バイナリファイルの場合は悲惨です。
16191021
16201022=begin original
16211023
1622Another consequence of using L<C<binmode>|/binmode FILEHANDLE, LAYER>
1024Another consequence of using binmode() (on some systems) is that
1623(on some systems) is that special end-of-file markers will be seen as
1025special end-of-file markers will be seen as part of the data stream.
1624part of the data stream. For systems from the Microsoft family this
1026For systems from the Microsoft family this means that if your binary
1625means that, if your binary data contain C<\cZ>, the I/O subsystem will
1027data contains C<\cZ>, the I/O subsystem will regard it as the end of
1626regard it as the end of the file, unless you use
1028the file, unless you use binmode().
1627L<C<binmode>|/binmode FILEHANDLE, LAYER>.
16281029
16291030=end original
16301031
1631L<C<binmode>|/binmode FILEHANDLE, LAYER> を(いくつかのシステムで)
1032binmode() を(いくつかのシステムで)使うことによるその他の作用としては、
1632使うことによるその他の作用としては、特別なファイル終端マーカーが
1033特別なファイル終端マーカーがデータストリームの一部として
1633データストリームの一部として見られることです。
1034見られることです。
1634Microsoft ファミリーのシステムでは、
1035Microsoft ファミリーのシステムでは、binmode() を使っていないと
1635L<C<binmode>|/binmode FILEHANDLE, LAYER> を使っていないと、
1036もしバイナリデータに C<\cZ> が含まれていきにI/O サブシステムが
1636もしバイナリデータに C<\cZ> が含まていたきに、
1037をファイル終端みなすことを意味します。
1637I/O サブシステムがこれをファイル終端とみなすことを意味します。
16381038
16391039=begin original
16401040
1641L<C<binmode>|/binmode FILEHANDLE, LAYER> is important not only for
1041binmode() is not only important for readline() and print() operations,
1642L<C<readline>|/readline EXPR> and L<C<print>|/print FILEHANDLE LIST>
1042but also when using read(), seek(), sysread(), syswrite() and tell()
1643operations, but also when using
1043(see L<perlport> for more details). See the C<$/> and C<$\> variables
1644L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1044in L<perlvar> for how to manually set your input and output
1645L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1646L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1647L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> and
1648L<C<tell>|/tell FILEHANDLE> (see L<perlport> for more details). See the
1649L<C<$E<sol>>|perlvar/$E<sol>> and L<C<$\>|perlvar/$\> variables in
1650L<perlvar> for how to manually set your input and output
16511045line-termination sequences.
16521046
16531047=end original
16541048
1655L<C<binmode>|/binmode FILEHANDLE, LAYER> L<C<readline>|/readline EXPR> と
1049binmode() は readline() と print() 操作にだけではなく、
1656L<C<print>|/print FILEHANDLE LIST> 操作だけはなく、
1050read(), seek(), sysread(), syswrite(), tell() を使うときも重要
1657L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1658L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1659L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1660L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1661L<C<tell>|/tell FILEHANDLE> を使うときにも重要です
16621051(詳細は L<perlport> を参照してください)。
16631052入出力の行端末シーケンスを手動でセットする方法については
1664L<perlvar> の L<C<$E<sol>>|perlvar/$E<sol>> 変数と
1053L<perlvar> の C<$/> 変数と C<$\> 変数を参照してください。
1665L<C<$\>|perlvar/$\> 変数を参照してください。
16661054
1667=begin original
1668
1669Portability issues: L<perlport/binmode>.
1670
1671=end original
1672
1673移植性の問題: L<perlport/binmode>。
1674
16751055=item bless REF,CLASSNAME
1676X<bless>
16771056
16781057=item bless REF
16791058
1680=for Pod::Functions create an object
1681
16821059=begin original
16831060
16841061This function tells the thingy referenced by REF that it is now an object
1685in the CLASSNAME package. If CLASSNAME is an empty string, it is
1062in the CLASSNAME package. If CLASSNAME is omitted, the current package
1686interpreted as referring to the C<main> package.
1063is used. Because a C<bless> is often the last thing in a constructor,
1687If CLASSNAME is omitted, the current package
1064it returns the reference for convenience. Always use the two-argument
1688is used. Because a L<C<bless>|/bless REF,CLASSNAME> is often the last
1065version if the function doing the blessing might be inherited by a
1689thing in a constructor, it returns the reference for convenience.
1066derived class. See L<perltoot> and L<perlobj> for more about the blessing
1690Always use the two-argument version if a derived class might inherit the
1691method doing the blessing. See L<perlobj> for more about the blessing
16921067(and blessings) of objects.
16931068
16941069=end original
16951070
16961071この関数は、REF で渡された オブジェクトに対し、
16971072CLASSNAME 内のオブジェクトとなったことを伝えます。
1698CLASSNAME が空文字列の場合、C<main> パッケージを参照しているものと
1699解釈されます。
17001073CLASSNAME が省略された場合には、その時点のパッケージとなります。
1701L<C<bless>|/bless REF,CLASSNAME> は通常、コンストラクタの最後に
1074C<bless> は通常、コンストラクタの最後に置かれますので、
1702置かれますので、簡便のためにそのリファレンスを返します。
1075簡便のためにそのリファレンスを返します。
1703派生クラスが bless されるメソッドを継承る場合は、
1076bless される関数が派生クラスによって継承される場合は、
17041077常に 2 引数版を使ってください。
1705オブジェクトの bless (や再 bless) について、詳しくは と L<perlobj> を
1078オブジェクトの bless (や再 bless) について、
1706参照してください。
1079詳しくは L<perltoot> と L<perlobj> を参照してください。
17071080
17081081=begin original
17091082
17101083Consider always blessing objects in CLASSNAMEs that are mixed case.
17111084Namespaces with all lowercase names are considered reserved for
1712Perl pragmas. Builtin types have all uppercase names. To prevent
1085Perl pragmata. Builtin types have all uppercase names, so to prevent
1713confusion, you may wish to avoid such package names as well.
1086confusion, you may wish to avoid such package names as well. Make sure
1714It is advised to avoid the class name C<0>, because much code erroneously
1087that CLASSNAME is a true value.
1715uses the result of L<C<ref>|/ref EXPR> as a truth value.
17161088
17171089=end original
17181090
17191091大文字小文字が混じっている CLASSNAME のオブジェクトは常に bless することを
17201092考慮してください。
17211093全て小文字の名前を持つ名前空間は Perl プラグマのために予約されています。
1722組み込みの型は全て大文字の名前を持ちます
1094組み込みの型は全て大文字の名前を持ちますので、混乱を避けるために、
1723混乱を避けるために、
17241095パッケージ名としてこのような名前は避けるべきです。
17251096CLASSNAME は真の値を持つようにしてください。
1726クラス名として C<0> は避けてください; 多くのコードが誤って
1727L<C<ref>|/ref EXPR> の結果を真の値として使っているからです。
17281097
17291098=begin original
17301099
17311100See L<perlmod/"Perl Modules">.
17321101
17331102=end original
17341103
1735L<perlmod/"Perl Modules"> を参照してください。
1104L<perlmod/"Perl Modules"> を参照してさい。
17361105
1737=item break
1738
1739=for Pod::Functions +switch break out of a C<given> block
1740
1741=begin original
1742
1743Break out of a C<given> block.
1744
1745=end original
1746
1747C<given> ブロックから脱出します。
1748
1749=begin original
1750
1751L<C<break>|/break> is available only if the
1752L<C<"switch"> feature|feature/The 'switch' feature> is enabled or if it
1753is prefixed with C<CORE::>. The
1754L<C<"switch"> feature|feature/The 'switch' feature> is enabled
1755automatically with a C<use v5.10> (or higher) declaration in the current
1756scope.
1757
1758=end original
1759
1760L<C<break>|/break> は、L<C<"switch"> 機能|feature/The 'switch' feature> が
1761有効か、C<CORE::> 接頭辞を使ったときにのみ利用可能です。
1762L<C<"switch"> 機能|feature/The 'switch' feature> は、現在のスコープで
1763C<use v5.10> (またはそれ以上) 宣言があると自動的に有効になります。
1764
17651106=item caller EXPR
1766X<caller> X<call stack> X<stack> X<stack trace>
17671107
17681108=item caller
17691109
1770=for Pod::Functions get context of the current subroutine call
1771
17721110=begin original
17731111
1774Returns the context of the current pure perl subroutine call. In scalar
1112Returns the context of the current subroutine call. In scalar context,
1775context, returns the caller's package name if there I<is> a caller (that is, if
1113returns the caller's package name if there is a caller, that is, if
1776we're in a subroutine or L<C<eval>|/eval EXPR> or
1114we're in a subroutine or C<eval> or C<require>, and the undefined value
1777L<C<require>|/require VERSION>) and the undefined value otherwise.
1115otherwise. In list context, returns
1778caller never returns XS subs and they are skipped. The next pure perl
1779sub will appear instead of the XS sub in caller's return values. In
1780list context, caller returns
17811116
17821117=end original
17831118
1784その時点のピュア perl サブルーチン呼び出しのコンテキストを返します。
1119その時点のサブルーチン呼び出しのコンテキストを返します。
1785スカラコンテキストでは、呼び元が I<ある> 場合
1120スカラコンテキストでは、呼び元がある場合
1786(サブルーチン、L<C<eval>|/eval EXPR>L<C<require>|/require VERSION> の中に
1121(サブルーチン、C<eval>、C<require> の中にいるとき) には
1787いるとき) には呼び出し元のパッケージ名を返し、
1122呼び出し元のパッケージ名を返し、その他のときには未定義値を返します。
1788その他のときに未定義値を返します
1123リストコンテキストで、以下を返します:
1789caller は XS サブルーチンを返すことはなく、それらは飛ばされます。
1790XS サブルーチンの代わりに次のピュア perl サブルーチンが caller の返り値に
1791なります。
1792リストコンテキストでは、caller は以下を返します:
17931124
1794 # 0 1 2
1125 ($package, $filename, $line) = caller;
1795 my ($package, $filename, $line) = caller;
17961126
17971127=begin original
17981128
17991129With EXPR, it returns some extra information that the debugger uses to
18001130print a stack trace. The value of EXPR indicates how many call frames
18011131to go back before the current one.
18021132
18031133=end original
18041134
18051135EXPR を付けると、デバッガがスタックトレースを表示するために使う情報を返します。
18061136EXPR の値は、現状から数えて、
18071137いくつ前のコールフレームまで戻るかを示します。
18081138
1809 # 0 1 2 3 4
1139 ($package, $filename, $line, $subroutine, $hasargs,
1810 my ($package, $filename, $line, $subroutine, $hasargs,
1140 $wantarray, $evaltext, $is_require, $hints, $bitmask) = caller($i);
18111141
1812 # 5 6 7 8 9 10
1813 $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash)
1814 = caller($i);
1815
18161142=begin original
18171143
1818Here, $subroutine is the function that the caller called (rather than the
1144Here $subroutine may be C<(eval)> if the frame is not a subroutine
1819function containing the caller). Note that $subroutine may be C<(eval)> if
1145call, but an C<eval>. In such a case additional elements $evaltext and
1820the frame is not a subroutine call, but an L<C<eval>|/eval EXPR>. In
1146C<$is_require> are set: C<$is_require> is true if the frame is created by a
1821such a case additional elements $evaltext and C<$is_require> are set:
1147C<require> or C<use> statement, $evaltext contains the text of the
1822C<$is_require> is true if the frame is created by a
1148C<eval EXPR> statement. In particular, for an C<eval BLOCK> statement,
1823L<C<require>|/require VERSION> or L<C<use>|/use Module VERSION LIST>
1149$filename is C<(eval)>, but $evaltext is undefined. (Note also that
1824statement, $evaltext contains the text of the C<eval EXPR> statement.
1150each C<use> statement creates a C<require> frame inside an C<eval EXPR>)
1825In particular, for an C<eval BLOCK> statement, $subroutine is C<(eval)>,
1151frame. C<$hasargs> is true if a new instance of C<@_> was set up for the
1826but $evaltext is undefined. (Note also that each
1152frame. C<$hints> and C<$bitmask> contain pragmatic hints that the caller
1827L<C<use>|/use Module VERSION LIST> statement creates a
1153was compiled with. The C<$hints> and C<$bitmask> values are subject to
1828L<C<require>|/require VERSION> frame inside an C<eval EXPR> frame.)
1154change between versions of Perl, and are not meant for external use.
1829$subroutine may also be C<(unknown)> if this particular subroutine
1830happens to have been deleted from the symbol table. C<$hasargs> is true
1831if a new instance of L<C<@_>|perlvar/@_> was set up for the frame.
1832C<$hints> and C<$bitmask> contain pragmatic hints that the caller was
1833compiled with. C<$hints> corresponds to L<C<$^H>|perlvar/$^H>, and
1834C<$bitmask> corresponds to
1835L<C<${^WARNING_BITS}>|perlvar/${^WARNING_BITS}>. The C<$hints> and
1836C<$bitmask> values are subject to change between versions of Perl, and
1837are not meant for external use.
18381155
18391156=end original
18401157
1841ここ、$subroutine 、(caller を含む関数ではなく) caller が呼び出し
1158もしフレームがサブルーチン呼び出しではなく C<eval> だっ場合、この
1842関数です。
1159$subroutine は C<(eval)> になります。
1843フレームがサブルーチン呼び出しではなく L<C<eval>|/eval EXPR> だった場合、この
1844$subroutine は C<(eval)> になることに注意してください。
18451160この場合、追加の要素である $evaltext と C<$is_require> がセットされます:
1846C<$is_require> はフレームが L<C<require>|/require VERSION>
1161C<$is_require> はフレームが C<require> または C<use> で作られ場合に
1847L<C<use>|/use Module VERSION LIST> で作られた場合に真にな
1162真になり、$evaltext は C<eval EXPR> のテキストが入ます。
1848$evaltext は C<eval EXPR> のテキストが入ります
1163特に、C<eval BLOCK> の場合、$filename は C<(eval)> になりますが、
1849特に、C<eval BLOCK> の場合、$subroutine は C<(eval)> になりますが、
18501164$evaltext は未定義値になります。
1851(それぞれの L<C<use>|/use Module VERSION LIST> は C<eval EXPR> の中で
1165(それぞれの C<use> は C<eval EXPR> の中で C<require> フレームを作ることに
1852L<C<require>|/require VERSION> フレームを作ることに注意してください。)
1166注意してください。)
1853$subroutine、そサブルチンシンボルテーブルから削除された場合
1167C<$hasargs>フレム用に C<@_> の新しい実体設定された場合に真となります。
1854C<(unknown)> になります。
1855C<$hasargs> はこのフレーム用に L<C<@_>|perlvar/@_> の新しい実体が
1856設定された場合に真となります。
18571168C<$hints> と C<$bitmask> は caller がコンパイルされたときの
18581169実際的なヒントを含みます。
1859C<$hints> は L<C<$^H>|perlvar/$^H> に対応し、C<$bitmask> は
1860L<C<${^WARNING_BITS}>|perlvar/${^WARNING_BITS}> に
1861対応します。
18621170C<$hints> は C<$bitmask> は Perl のバージョンによって変更される
1863可能性があるので、外部での使用を想定していません。
1171可能性があるので、外部での使用を想定していません。
18641172
18651173=begin original
18661174
1867C<$hinthash> is a reference to a hash containing the value of
1175Furthermore, when called from within the DB package, caller returns more
1868L<C<%^H>|perlvar/%^H> when the caller was compiled, or
1869L<C<undef>|/undef EXPR> if L<C<%^H>|perlvar/%^H> was empty. Do not
1870modify the values of this hash, as they are the actual values stored in
1871the optree.
1872
1873=end original
1874
1875C<$hinthash> は、caller がコンパイルされた時の L<C<%^H>|perlvar/%^H> の値を
1876含むハッシュへのリファレンスか、あるいは L<C<%^H>|perlvar/%^H> が空の場合は
1877L<C<undef>|/undef EXPR> です。
1878このハッシュの値は構文木に保管されている実際の値なので、変更しないで下さい。
1879
1880=begin original
1881
1882Furthermore, when called from within the DB package in
1883list context, and with an argument, caller returns more
18841176detailed information: it sets the list variable C<@DB::args> to be the
18851177arguments with which the subroutine was invoked.
18861178
18871179=end original
18881180
1889さらに、DB パッケージの中からリストコンテキストで引数付きで呼ばれた場合は、
1181さらに、DB パッケージの中から呼ばれた場合は、caller は
1890caller はより詳細な情報を返します; サブルーチンが起動されたときの引数を
1182より詳細な情報を返します
1891変数 C<@DB::args> に設定します。
1183サブルーチンが起動されたときの引数を変数 C<@DB::args> に設定します。
18921184
18931185=begin original
18941186
18951187Be aware that the optimizer might have optimized call frames away before
1896L<C<caller>|/caller EXPR> had a chance to get the information. That
1188C<caller> had a chance to get the information. That means that C<caller(N)>
1897means that C<caller(N)> might not return information about the call
1189might not return information about the call frame you expect it do, for
1898frame you expect it to, for C<< N > 1 >>. In particular, C<@DB::args>
1190C<< N > 1 >>. In particular, C<@DB::args> might have information from the
1899might have information from the previous time L<C<caller>|/caller EXPR>
1191previous time C<caller> was called.
1900was called.
19011192
19021193=end original
19031194
1904L<C<caller>|/caller EXPR> が情報を得る前にオプティマイザが呼び出しフレームを
1195C<caller> が情報を得る前にオプティマイザが呼び出しフレームを最適化して
1905最適化してしまうかもしれないことに注意してください。
1196しまうかもしれないことに注意してください。
19061197これは、C<caller(N)> が C<< N > 1 >> のとき、
19071198あなたが予測した呼び出しフレームの情報を返さないかもしれないことを意味します。
1908特に、C<@DB::args> は L<C<caller>|/caller EXPR> が前回呼び出された時の情報を
1199特に、C<@DB::args> は C<caller> が前回呼び出された時の情報を
19091200持っているかもしれません。
19101201
1911=begin original
1912
1913Be aware that setting C<@DB::args> is I<best effort>, intended for
1914debugging or generating backtraces, and should not be relied upon. In
1915particular, as L<C<@_>|perlvar/@_> contains aliases to the caller's
1916arguments, Perl does not take a copy of L<C<@_>|perlvar/@_>, so
1917C<@DB::args> will contain modifications the subroutine makes to
1918L<C<@_>|perlvar/@_> or its contents, not the original values at call
1919time. C<@DB::args>, like L<C<@_>|perlvar/@_>, does not hold explicit
1920references to its elements, so under certain cases its elements may have
1921become freed and reallocated for other variables or temporary values.
1922Finally, a side effect of the current implementation is that the effects
1923of C<shift @_> can I<normally> be undone (but not C<pop @_> or other
1924splicing, I<and> not if a reference to L<C<@_>|perlvar/@_> has been
1925taken, I<and> subject to the caveat about reallocated elements), so
1926C<@DB::args> is actually a hybrid of the current state and initial state
1927of L<C<@_>|perlvar/@_>. Buyer beware.
1928
1929=end original
1930
1931C<@DB::args> の設定は I<ベストエフォート> で、デバッグやバックトレースの
1932生成を目的としていて、これに依存するべきではないということにも
1933注意してください。
1934特に、L<C<@_>|perlvar/@_> は呼び出し元の引数へのエイリアスを含んでいるので、
1935Perl は L<C<@_>|perlvar/@_> のコピーを取らず、従って C<@DB::args> は
1936サブルーチンが L<C<@_>|perlvar/@_> やその内容に行った変更を含んでいて、
1937呼び出し時の元の値ではありません。
1938C<@DB::args> は、L<C<@_>|perlvar/@_> と同様、その要素への明示的な
1939リファレンスを保持しないので、ある種の状況では、解放されて他の変数や
1940一時的な値のために再割り当てされているかもしれません。
1941最後に、現在の実装の副作用は、C<shift @_> の効果は I<普通は> 行われない
1942(しかし C<pop @_> やその他の splice は違い、I<そして> もし
1943L<C<@_>|perlvar/@_> のリファレンスが取られると違い、I<そして> 再割り当てされた
1944要素に関する問題になりやすいです)ことなので、C<@DB::args> は実際には現在の
1945状態と L<C<@_>|perlvar/@_> の初期状態との合成物となります。
1946ご用心を。
1947
19481202=item chdir EXPR
1949X<chdir>
1950X<cd>
1951X<directory, change>
19521203
1953=item chdir FILEHANDLE
1954
1955=item chdir DIRHANDLE
1956
1957=item chdir
1958
1959=for Pod::Functions change your current working directory
1960
19611204=begin original
19621205
19631206Changes the working directory to EXPR, if possible. If EXPR is omitted,
19641207changes to the directory specified by C<$ENV{HOME}>, if set; if not,
1965changes to the directory specified by C<$ENV{LOGDIR}>. (Under VMS, the
1208changes to the directory specified by C<$ENV{LOGDIR}>. If neither is
1966variable C<$ENV{'SYS$LOGIN'}> is also checked, and used if it is set.) If
1209set, C<chdir> does nothing. It returns true upon success, false
1967neither is set, L<C<chdir>|/chdir EXPR> does nothing and fails. It
1210otherwise. See the example under C<die>.
1968returns true on success, false otherwise. See the example under
1969L<C<die>|/die LIST>.
19701211
19711212=end original
19721213
19731214(可能であれば、) カレントディレクトリを EXPR に移します。
1974EXPR を指定しないと、C<$ENV{HOME}> が設定されていれば、そのディレクトリに
1215EXPR を指定しないと、C<$ENV{HOME}> が設定されていれば、
1975移ります; うでなく、C<$ENV{LOGDIR}>が設定されていれば、そのディレクトリに
1216そのディレクトリに移ります。
1976移ります。
1217そうでなく、C<$ENV{LOGDIR}>が設定されていれば、そのディレクトリに移ります。
1977(VMS では C<$ENV{'SYS$LOGIN'}> チェックされ、もしセットされていれば
1218どちら設定されていなければ、C<chdir> は何もしません。
1978使われます。)
1979どちらも設定されていなければ、L<C<chdir>|/chdir EXPR> は何もせずに失敗します。
19801219成功時には真を返し、そうでなければ偽を返します。
1981L<C<die>|/die LIST> の項の例を参照してください。
1220C<die> の項の例を参照してください。
19821221
1983=begin original
1984
1985On systems that support L<fchdir(2)>, you may pass a filehandle or
1986directory handle as the argument. On systems that don't support L<fchdir(2)>,
1987passing handles raises an exception.
1988
1989=end original
1990
1991L<fchdir(2)> に対応しているシステムでは、ファイルハンドルや
1992ディレクトリハンドルを引数として渡せます。
1993L<fchdir(2)> に対応していないシステムでは、ハンドルを渡すと例外が発生します。
1994
19951222=item chmod LIST
1996X<chmod> X<permission> X<mode>
19971223
1998=for Pod::Functions changes the permissions on a list of files
1999
20001224=begin original
20011225
20021226Changes the permissions of a list of files. The first element of the
2003list must be the numeric mode, which should probably be an octal
1227list must be the numerical mode, which should probably be an octal
2004number, and which definitely should I<not> be a string of octal digits:
1228number, and which definitely should I<not> a string of octal digits:
2005C<0644> is okay, but C<"0644"> is not. Returns the number of files
1229C<0644> is okay, C<'0644'> is not. Returns the number of files
2006successfully changed. See also L<C<oct>|/oct EXPR> if all you have is a
1230successfully changed. See also L</oct>, if all you have is a string.
2007string.
20081231
20091232=end original
20101233
20111234LIST に含まれるファイルの、パーミッションを変更します。
2012LIST の最初の要素は、数値表現のモードでなければなりません;
1235LIST の最初の要素は、数値表現のモードでなければなりません
2013恐らく 8 進表記の数であるべきでしょう: しかし、8 進表記の
1236恐らく 8 進表記の数であるべきでしょうしかし、8 進表記のC<文字列ではいけません>。
2014文字列では I<いけません>: C<0644> は OK ですが、 C<"0644"> は
1237C<0644> は OK ですが、 C<'0644'> はだめ、ということです。
2015だめ、ということです。
20161238変更に成功したファイルの数を返します。
2017文字列を使いたい場合は、L<C<oct>|/oct EXPR> を参照してください。
1239文字列を使いたい場合は、L</oct> を参照してください。
20181240
2019 my $cnt = chmod 0755, "foo", "bar";
1241 $cnt = chmod 0755, 'foo', 'bar';
20201242 chmod 0755, @executables;
2021 my $mode = "0644"; chmod $mode, "foo"; # !!! sets mode to
1243 $mode = '0644'; chmod $mode, 'foo'; # !!! sets mode to
2022 # --w----r-T
1244 # --w----r-T
2023 my $mode = "0644"; chmod oct($mode), "foo"; # this is better
1245 $mode = '0644'; chmod oct($mode), 'foo'; # this is better
2024 my $mode = 0644; chmod $mode, "foo"; # this is best
1246 $mode = 0644; chmod $mode, 'foo'; # this is best
20251247
20261248=begin original
20271249
2028On systems that support L<fchmod(2)>, you may pass filehandles among the
1250You can also import the symbolic C<S_I*> constants from the Fcntl
2029files. On systems that don't support L<fchmod(2)>, passing filehandles raises
1251module:
2030an exception. Filehandles must be passed as globs or glob references to be
2031recognized; barewords are considered filenames.
20321252
20331253=end original
20341254
2035L<fchmod(2)> に対応しているシステムでは、ファイドルを引数して
1255シンボリックな C<S_I*> 定数を Fcntl モジューからイポートするこもできます。
2036渡せます。
2037L<fchmod(2)> に対応していないシステムでは、ファイルハンドルを渡すと
2038例外が発生します。
2039ファイルハンドルを認識させるためには、グロブまたはリファレンスとして
2040渡されなければなりません;
2041裸の単語はファイル名として扱われます。
20421256
2043 open(my $fh, "<", "foo");
1257 use Fcntl ':mode';
2044 my $perm = (stat $fh)[2] & 07777;
2045 chmod($perm | 0600, $fh);
20461258
2047=begin original
2048
2049You can also import the symbolic C<S_I*> constants from the
2050L<C<Fcntl>|Fcntl> module:
2051
2052=end original
2053
2054L<C<Fcntl>|Fcntl> モジュールから C<S_I*> シンボル定数を
2055インポートすることもできます:
2056
2057 use Fcntl qw( :mode );
20581259 chmod S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, @executables;
2059 # Identical to the chmod 0755 of the example above.
1260 # This is identical to the chmod 0755 of the above example.
20601261
2061=begin original
2062
2063Portability issues: L<perlport/chmod>.
2064
2065=end original
2066
2067移植性の問題: L<perlport/chmod>。
2068
20691262=item chomp VARIABLE
2070X<chomp> X<INPUT_RECORD_SEPARATOR> X<$/> X<newline> X<eol>
20711263
2072=item chomp( LIST )
1264=item chomp LIST
20731265
20741266=item chomp
20751267
2076=for Pod::Functions remove a trailing record separator from a string
2077
20781268=begin original
20791269
2080This safer version of L<C<chop>|/chop VARIABLE> removes any trailing
1270This safer version of L</chop> removes any trailing string
2081string that corresponds to the current value of
1271that corresponds to the current value of C<$/> (also known as
2082L<C<$E<sol>>|perlvar/$E<sol>> (also known as C<$INPUT_RECORD_SEPARATOR>
1272$INPUT_RECORD_SEPARATOR in the C<English> module). It returns the total
2083in the L<C<English>|English> module). It returns the total
20841273number of characters removed from all its arguments. It's often used to
20851274remove the newline from the end of an input record when you're worried
20861275that the final record may be missing its newline. When in paragraph
2087mode (C<$/ = ''>), it removes all trailing newlines from the string.
1276mode (C<$/ = "">), it removes all trailing newlines from the string.
2088When in slurp mode (C<$/ = undef>) or fixed-length record mode
1277When in slurp mode (C<$/ = undef>) or fixed-length record mode (C<$/> is
2089(L<C<$E<sol>>|perlvar/$E<sol>> is a reference to an integer or the like;
1278a reference to an integer or the like, see L<perlvar>) chomp() won't
2090see L<perlvar>), L<C<chomp>|/chomp VARIABLE> won't remove anything.
1279remove anything.
2091If VARIABLE is omitted, it chomps L<C<$_>|perlvar/$_>. Example:
1280If VARIABLE is omitted, it chomps C<$_>. Example:
20921281
20931282=end original
20941283
2095より安全な L<C<chop>|/chop VARIABLE> (以下を参照してください) です;
1284より安全な C<chop> (以下を参照してください) です
2096L<C<$E<sol>>|perlvar/$E<sol>> (L<C<English>|English> モジュールでは、
1285C<$/> (C<English> モジュールでは、$INPUT_RECORD_SEPARATOR
2097C<$INPUT_RECORD_SEPARATOR> とも言う) のその時点の
1286とも言う) のその時点の値に対応する行末文字を削除します。
2098値に対応する行末文字を削除します。
20991287全ての引数から削除した文字数の合計を返します。
21001288入力レコードから、改行を削除したいのだけれど、最後のレコードには改行が
21011289入っているのかわからないような場合に、使用できます。
2102段落モード (C<$/ = ''>) では、レコードの最後の改行をすべて取り除きます。
1290段落モード (C<$/ = "">) では、レコードの最後の改行をすべて取り除きます。
21031291吸い込みモード (C<$/ = undef>) や 固定長レコードモード
2104(L<C<$E<sol>>|perlvar/$E<sol>> が整数へのリファレンスや類似のものの場合;
1292(C<$/> が整数へのリファレンスや類似のものの場合。L<perlvar>を参照してください)
2105L<perlvar>を参照してください)では、L<C<chomp>|/chomp VARIABLE>
1293では、chomp()何も取り除きません。
2106何も取り除きせん
1294VARIABLE が省略されると、$_ を対象として chomp し
2107VARIABLE が省略されると、L<C<$_>|perlvar/$_> を対象として chomp します。
21081295例:
21091296
1297=begin original
1298
21101299 while (<>) {
2111 chomp; # avoid \n on last field
1300 chomp; # avoid \n on last field
2112 my @array = split(/:/);
1301 @array = split(/:/);
2113 # ...
1302 # ...
21141303 }
21151304
1305=end original
1306
1307 while (<>) {
1308 chomp; # 最後のフィールドの \n を避ける
1309 @array = split(/:/);
1310 #...
1311 }
1312
21161313=begin original
21171314
2118If VARIABLE is a hash, it chomps the hash's values, but not its keys,
1315If VARIABLE is a hash, it chomps the hash's values, but not its keys.
2119resetting the L<C<each>|/each HASH> iterator in the process.
21201316
21211317=end original
21221318
2123VARIABLE がハッシュなら、ハッシュのキーではなく値について chomp し
1319VARIABLE がハッシュなら、ハッシュのキーではなく値について chomp します。
2124このプロセスの L<C<each>|/each HASH> 反復子をリセットします。
21251320
21261321=begin original
21271322
21281323You can actually chomp anything that's an lvalue, including an assignment:
21291324
21301325=end original
21311326
21321327左辺値であれば、代入を含めて、任意のものを chomp できます:
21331328
2134 chomp(my $cwd = `pwd`);
1329 chomp($cwd = `pwd`);
2135 chomp(my $answer = <STDIN>);
1330 chomp($answer = <STDIN>);
21361331
21371332=begin original
21381333
21391334If you chomp a list, each element is chomped, and the total number of
21401335characters removed is returned.
21411336
21421337=end original
21431338
21441339リストを chomp すると、個々の要素が chomp され、
21451340削除された文字数の合計が返されます。
21461341
2147=begin original
2148
2149Note that parentheses are necessary when you're chomping anything
2150that is not a simple variable. This is because C<chomp $cwd = `pwd`;>
2151is interpreted as C<(chomp $cwd) = `pwd`;>, rather than as
2152C<chomp( $cwd = `pwd` )> which you might expect. Similarly,
2153C<chomp $a, $b> is interpreted as C<chomp($a), $b> rather than
2154as C<chomp($a, $b)>.
2155
2156=end original
2157
2158単純な変数以外のものを chomp する場合はかっこが必要であることに
2159注意してください。
2160これは、C<chomp $cwd = `pwd`;> は、予測している
2161C<chomp( $cwd = `pwd` )> ではなく、C<(chomp $cwd) = `pwd`;> と
2162解釈されるからです。
2163同様に、C<chomp $a, $b> は C<chomp($a, $b)> ではなく C<chomp($a), $b>
2164と解釈されます。
2165
21661342=item chop VARIABLE
2167X<chop>
21681343
2169=item chop( LIST )
1344=item chop LIST
21701345
21711346=item chop
21721347
2173=for Pod::Functions remove the last character from a string
2174
21751348=begin original
21761349
21771350Chops off the last character of a string and returns the character
21781351chopped. It is much more efficient than C<s/.$//s> because it neither
2179scans nor copies the string. If VARIABLE is omitted, chops
1352scans nor copies the string. If VARIABLE is omitted, chops C<$_>.
2180L<C<$_>|perlvar/$_>.
1353If VARIABLE is a hash, it chops the hash's values, but not its keys.
2181If VARIABLE is a hash, it chops the hash's values, but not its keys,
2182resetting the L<C<each>|/each HASH> iterator in the process.
21831354
21841355=end original
21851356
21861357文字列の最後の文字を切り捨てて、その切り取った文字を返します。
21871358文字列の検索もコピーも行ないませんので
21881359C<s/.$//s> よりも、ずっと効率的です。
2189VARIABLE が省略されると、L<C<$_>|perlvar/$_> を対象として chop します。
1360VARIABLE が省略されると、C<$_> を対象として chop します。
2190VARIABLE がハッシュの場合、ハッシュのキーではなく値について chop し、
1361VARIABLE がハッシュの場合、ハッシュの value を chop しますが
2191このプロセスの L<C<each>|/each HASH> 反復子をリセットしま
1362key は chop しません
21921363
21931364=begin original
21941365
21951366You can actually chop anything that's an lvalue, including an assignment.
21961367
21971368=end original
21981369
21991370実際のところ、代入を含む左辺値となりうるなんでも chop できます。
22001371
22011372=begin original
22021373
22031374If you chop a list, each element is chopped. Only the value of the
2204last L<C<chop>|/chop VARIABLE> is returned.
1375last C<chop> is returned.
22051376
22061377=end original
22071378
22081379リストを chop すると、個々の要素が chop されます。
2209最後の L<C<chop>|/chop VARIABLE> の値だけが返されます。
1380最後の C<chop> の値だけが返されます。
22101381
22111382=begin original
22121383
2213Note that L<C<chop>|/chop VARIABLE> returns the last character. To
1384Note that C<chop> returns the last character. To return all but the last
2214return all but the last character, use C<substr($string, 0, -1)>.
1385character, use C<substr($string, 0, -1)>.
22151386
22161387=end original
22171388
2218L<C<chop>|/chop VARIABLE> は最後の文字を返すことに注意してください。
1389C<chop> は最後の文字を返すことに注意してください。
22191390最後以外の全ての文字を返すためには、C<substr($string, 0, -1)> を
22201391使ってください。
22211392
2222=begin original
2223
2224See also L<C<chomp>|/chomp VARIABLE>.
2225
2226=end original
2227
2228L<C<chomp>|/chomp VARIABLE> も参照してください。
2229
22301393=item chown LIST
2231X<chown> X<owner> X<user> X<group>
22321394
2233=for Pod::Functions change the ownership on a list of files
2234
22351395=begin original
22361396
22371397Changes the owner (and group) of a list of files. The first two
22381398elements of the list must be the I<numeric> uid and gid, in that
22391399order. A value of -1 in either position is interpreted by most
22401400systems to leave that value unchanged. Returns the number of files
22411401successfully changed.
22421402
22431403=end original
22441404
22451405LIST に含まれるファイルの所有者 (とグループ) を変更します。
2246LIST の最初のつの要素には、I<数値表現> の uid と gid を
1406LIST の最初の 2 つの要素には、I<数値表現> の uid と gid を
22471407この順序で与えなければなりません。
22481408どちらかの値を -1 にすると、ほとんどのシステムではその値は
22491409変更しないと解釈します。
2250変更に成功したファイルの数ます。
1410変更に成功したファイルの数されます。
22511411
2252 my $cnt = chown $uid, $gid, 'foo', 'bar';
1412 $cnt = chown $uid, $gid, 'foo', 'bar';
22531413 chown $uid, $gid, @filenames;
22541414
22551415=begin original
22561416
2257On systems that support L<fchown(2)>, you may pass filehandles among the
2258files. On systems that don't support L<fchown(2)>, passing filehandles raises
2259an exception. Filehandles must be passed as globs or glob references to be
2260recognized; barewords are considered filenames.
2261
2262=end original
2263
2264L<fchown(2)> に対応しているシステムでは、ファイルハンドルを引数として渡せます。
2265L<fchown(2)> に対応していないシステムでは、ファイルハンドルを渡すと
2266例外が発生します。
2267ファイルハンドルを認識させるためには、グロブまたはリファレンスとして
2268渡されなければなりません; 裸の単語はファイル名として扱われます。
2269
2270=begin original
2271
22721417Here's an example that looks up nonnumeric uids in the passwd file:
22731418
22741419=end original
22751420
22761421passwd ファイルから数値表現でない uid を検索する例を
22771422示します:
22781423
22791424 print "User: ";
2280 chomp(my $user = <STDIN>);
1425 chomp($user = <STDIN>);
22811426 print "Files: ";
2282 chomp(my $pattern = <STDIN>);
1427 chomp($pattern = <STDIN>);
22831428
2284 my ($login,$pass,$uid,$gid) = getpwnam($user)
1429 ($login,$pass,$uid,$gid) = getpwnam($user)
2285 or die "$user not in passwd file";
1430 or die "$user not in passwd file";
22861431
2287 my @ary = glob($pattern); # expand filenames
1432 @ary = glob($pattern); # expand filenames
22881433 chown $uid, $gid, @ary;
22891434
22901435=begin original
22911436
22921437On most systems, you are not allowed to change the ownership of the
22931438file unless you're the superuser, although you should be able to change
22941439the group to any of your secondary groups. On insecure systems, these
22951440restrictions may be relaxed, but this is not a portable assumption.
22961441On POSIX systems, you can detect this condition this way:
22971442
22981443=end original
22991444
23001445ほとんどのシステムでは、スーパーユーザーだけがファイルの所有者を
23011446変更できますが、グループは実行者の副グループに変更できるべきです。
2302安全でないシステムでは、この制限はゆるめられています; しかしこれは
1447安全でないシステムでは、この制限はゆるめられています
2303移植性のある仮定ではありません。
1448しかしこれは移植性のある仮定ではありません。
23041449POSIX システムでは、以下のようにしてこの条件を検出できます:
23051450
23061451 use POSIX qw(sysconf _PC_CHOWN_RESTRICTED);
2307 my $can_chown_giveaway = ! sysconf(_PC_CHOWN_RESTRICTED);
1452 $can_chown_giveaway = not sysconf(_PC_CHOWN_RESTRICTED);
23081453
2309=begin original
2310
2311Portability issues: L<perlport/chown>.
2312
2313=end original
2314
2315移植性の問題: L<perlport/chown>。
2316
23171454=item chr NUMBER
2318X<chr> X<character> X<ASCII> X<Unicode>
23191455
23201456=item chr
23211457
2322=for Pod::Functions get character this number represents
2323
23241458=begin original
23251459
23261460Returns the character represented by that NUMBER in the character set.
23271461For example, C<chr(65)> is C<"A"> in either ASCII or Unicode, and
2328chr(0x263a) is a Unicode smiley face.
1462chr(0x263a) is a Unicode smiley face (but only within the scope of
1463a C<use utf8>). For the reverse, use L</ord>.
1464See L<utf8> for more about Unicode.
23291465
23301466=end original
23311467
23321468特定の文字セットでの NUMBER で表わされる文字を返します。
2333たとえば、C<chr(65)> は ASCII と Unicode の両方で C<"A"> となります;
1469たとえば、C<chr(65)> は ASCII と Unicode の両方で C<"A"> となります
2334chr(0x263a) は Unicode のスマイリーフェイスです
1470chr(0x263a) は Unicode のスマイリーフェイスです
1471(ただし C<use utf8> のスコープ内のみです)。
1472逆を行うためには、L</ord> を参照してください。
1473Unicode についてもっと知りたいなら、L<utf8> を参照してください。
23351474
23361475=begin original
23371476
2338Negative values give the Unicode replacement character (chr(0xfffd)),
1477If NUMBER is omitted, uses C<$_>.
2339except under the L<bytes> pragma, where the low eight bits of the value
2340(truncated to an integer) are used.
23411478
23421479=end original
23431480
2344負の数は Unicode の置換文字 (chr(0xfffd)) 与えますが、
1481NUMBER が省略された場合、C<$_>使います
2345L<bytes> プラグマの影響下では、(integer に切り詰められた)値の下位 8 ビットが
2346使われます。
23471482
2348=begin original
2349
2350If NUMBER is omitted, uses L<C<$_>|perlvar/$_>.
2351
2352=end original
2353
2354NUMBER が省略された場合、L<C<$_>|perlvar/$_> を使います。
2355
2356=begin original
2357
2358For the reverse, use L<C<ord>|/ord EXPR>.
2359
2360=end original
2361
2362逆を行うためには、L<C<ord>|/ord EXPR> を参照してください。
2363
2364=begin original
2365
2366Note that characters from 128 to 255 (inclusive) are by default
2367internally not encoded as UTF-8 for backward compatibility reasons.
2368
2369=end original
2370
2371128 から 255 までの文字は過去との互換性のために
2372デフォルトでは UTF-8 Unicode にエンコードされません。
2373
2374=begin original
2375
2376See L<perlunicode> for more about Unicode.
2377
2378=end original
2379
2380Unicode については L<perlunicode> を参照してください。
2381
23821483=item chroot FILENAME
2383X<chroot> X<root>
23841484
23851485=item chroot
23861486
2387=for Pod::Functions make directory new root for path lookups
2388
23891487=begin original
23901488
23911489This function works like the system call by the same name: it makes the
23921490named directory the new root directory for all further pathnames that
23931491begin with a C</> by your process and all its children. (It doesn't
23941492change your current working directory, which is unaffected.) For security
23951493reasons, this call is restricted to the superuser. If FILENAME is
2396omitted, does a L<C<chroot>|/chroot FILENAME> to L<C<$_>|perlvar/$_>.
1494omitted, does a C<chroot> to C<$_>.
23971495
23981496=end original
23991497
2400同じ名前のシステムコールと同じことをします: 現在のプロセス及び子プロセスに
1498同じ名前のシステムコールと同じことをします
2401対して、C</>で始まるパス名に関して指定されたディレクトリを新しい
1499現在のプロセス及び子プロセスに対して、C</>で始まるパス名に関して
2402ルートディレクトリとして扱います。
1500指定されたディレクトリを新しいルートディレクトリとして扱います。
2403(これはカレントディレクトリを変更しません; カレントディレクトリは
1501(これはカレントディレクトリを変更しませんカレントディレクトリはそのままです)。
2404そのままです。)
24051502セキュリティ上の理由により、この呼び出しはスーパーユーザーしか行えません。
2406FILENAME を省略すると、L<C<$_>|perlvar/$_>
1503FILENAME を省略すると、C<$_> へ C<chroot> します。
2407L<C<chroot>|/chroot FILENAME> します。
24081504
2409=begin original
2410
2411B<NOTE:> It is good security practice to do C<chdir("/")>
2412(L<C<chdir>|/chdir EXPR> to the root directory) immediately after a
2413L<C<chroot>|/chroot FILENAME>.
2414
2415=end original
2416
2417B<注意:> L<C<chroot>|/chroot FILENAME> の直後に (ルートディレクトリに
2418L<C<chdir>|/chdir EXPR> する)
2419C<chdir("/")> するのはセキュリティ上の良い習慣です。
2420
2421=begin original
2422
2423Portability issues: L<perlport/chroot>.
2424
2425=end original
2426
2427移植性の問題: L<perlport/chroot>。
2428
24291505=item close FILEHANDLE
2430X<close>
24311506
24321507=item close
24331508
2434=for Pod::Functions close file (or pipe or socket) handle
2435
24361509=begin original
24371510
2438Closes the file or pipe associated with the filehandle, flushes the IO
1511Closes the file or pipe associated with the file handle, returning true
2439buffers, and closes the system file descriptor. Returns true if those
1512only if stdio successfully flushes buffers and closes the system file
2440operations succeed and if no error was reported by any PerlIO
1513descriptor. Closes the currently selected filehandle if the argument
2441layer. Closes the currently selected filehandle if the argument is
1514is omitted.
2442omitted.
24431515
24441516=end original
24451517
2446FILEHANDLE に対応したファイルまたはパイプをクローズして、
1518FILEHANDLE に対応したファイルまたはパイプをクローズします。
2447IO バッファフラッシュし、システムファイル記述子クローズします。
1519標準入出力が正常にバッファフラッシュを行なって、
2448操作が成功し、PerlIO 層からエラが報告されなかっ場合に真を返します。
1520ファイル記述子のクロズしときのみ「を返します。
24491521引数が省略された場合、現在選択されているファイルハンドルをクローズします。
24501522
24511523=begin original
24521524
24531525You don't have to close FILEHANDLE if you are immediately going to do
2454another L<C<open>|/open FILEHANDLE,EXPR> on it, because
1526another C<open> on it, because C<open> will close it for you. (See
2455L<C<open>|/open FILEHANDLE,EXPR> closes it for you. (See
1527C<open>.) However, an explicit C<close> on an input file resets the line
2456L<C<open>|/open FILEHANDLE,EXPR>.) However, an explicit
1528counter (C<$.>), while the implicit close done by C<open> does not.
2457L<C<close>|/close FILEHANDLE> on an input file resets the line counter
2458(L<C<$.>|perlvar/$.>), while the implicit close done by
2459L<C<open>|/open FILEHANDLE,EXPR> does not.
24601529
24611530=end original
24621531
2463クローズしてすぐにまた、同じファイルハンドルに対してオープンを行なう
1532クローズしてすぐにまた、同じファイルハンドルに
2464場合には、L<C<open>|/open FILEHANDLE,EXPR> が自動的に
1533対してオープンを行なう場合には、C<open> が自動的に C<close>
2465L<C<close>|/close FILEHANDLE> を行ないまので、
1534を行ないますので、close FILEHANDLE する必要はありません
2466close FILEHANDLE する必要はありません
1535(C<open> を参照してください)
2467(L<C<open>|/open FILEHANDLE,EXPR> を参照してください。)
24681536ただし、明示的にクローズを行なったときにのみ入力ファイルの
2469行番号 (L<C<$.>|perlvar/$.>) のリセットが行なわれ、
1537行番号 (C<$.>) のリセットが行なわれ、C<open> によって行なわれる
2470L<C<open>|/open FILEHANDLE,EXPR> によって行なわれ
1538暗黙の C<close>では行なわれません。
2471暗黙の L<C<close>|/close FILEHANDLE> では行なわれません。
24721539
24731540=begin original
24741541
2475If the filehandle came from a piped open, L<C<close>|/close FILEHANDLE>
1542If the file handle came from a piped open C<close> will additionally
2476returns false if one of the other syscalls involved fails or if its
1543return false if one of the other system calls involved fails or if the
2477program exits with non-zero status. If the only problem was that the
1544program exits with non-zero status. (If the only problem was that the
2478program exited non-zero, L<C<$!>|perlvar/$!> will be set to C<0>.
1545program exited non-zero C<$!> will be set to C<0>.) Closing a pipe
2479Closing a pipe also waits for the process executing on the pipe to
1546also waits for the process executing on the pipe to complete, in case you
2480exit--in case you wish to look at the output of the pipe afterwards--and
1547want to look at the output of the pipe afterwards, and
2481implicitly puts the exit status value of that command into
1548implicitly puts the exit status value of that command into C<$?>.
2482L<C<$?>|perlvar/$?> and
2483L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>.
24841549
24851550=end original
24861551
2487ファイルハンドルがパイプつきオープンなら、L<C<close>|/close FILEHANDLE> は
1552ファイルハンドルがパイプつきオープンなら、
2488その他のシステムコールが失敗したりプログラムが非ゼロのステータスで終了した
1553C<close> はその他のシステムコールが失敗したり
2489場合にも偽を返します
1554プログラムが非ゼロのステータスで終了した場合にも偽を返します
2490プログラムが非ゼロで終了しただけの場合は、L<C<$!>|perlvar/$!> C<0>
1555(プログラムが非ゼロで終了しただけの場合は、C<$!>がC<0>にセットされます)。
2491セットされます。
1556後でパイプの出力を見たい場合のために、
2492後でパイプの出力を見たい場合のために、パイプのクローズでは、パイプ上で
1557パイプのクローズでは、パイプ上で実行されている
2493実行されているプロセスの了を待ちた自動的にコマンドのステータス値を
1558プロセスの了を待ちます。
2494L<C<$?>|perlvar/$?>
1559また自動的にコマンドのステータス値を C<$?> に設定します。
2495L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に設定します。
24961560
24971561=begin original
24981562
2499If there are multiple threads running, L<C<close>|/close FILEHANDLE> on
1563Prematurely closing the read end of a pipe (i.e. before the process
2500a filehandle from a piped open returns true without waiting for the
1564writing to it at the other end has closed it) will result in a
2501child process to terminate, if the filehandle is still open in another
1565SIGPIPE being delivered to the writer. If the other end can't
2502thread.
1566handle that, be sure to read all the data before closing the pipe.
25031567
25041568=end original
25051569
2506複数のスレッド場合、パイプで開かれたファイルハンドル対する
1570途中で(つまり、書き込み側閉じ)
2507L<C<close>|/close FILEHANDLE> は、そのファルハンドルが他スレッドで
1571読み込み側が閉じた場合、
2508まだ開かれている場合、子プロセスの終了を待たずに真を返します。
2509
2510=begin original
2511
2512Closing the read end of a pipe before the process writing to it at the
2513other end is done writing results in the writer receiving a SIGPIPE. If
2514the other end can't handle that, be sure to read all the data before
2515closing the pipe.
2516
2517=end original
2518
2519書き込み側が閉じる前に途中でパイプの読み込み側が閉じた場合、
25201572書き込み側に SIGPIPE が配送されます。
25211573書き込み側がこれを扱えない場合、パイプを閉じる前に
25221574確実に全てのデータが読み込まれるようにする必要があります。
25231575
25241576=begin original
25251577
25261578Example:
25271579
25281580=end original
25291581
25301582例:
25311583
25321584 open(OUTPUT, '|sort >foo') # pipe to sort
25331585 or die "Can't start sort: $!";
2534 #... # print stuff to output
1586 #... # print stuff to output
2535 close OUTPUT # wait for sort to finish
1587 close OUTPUT # wait for sort to finish
25361588 or warn $! ? "Error closing sort pipe: $!"
25371589 : "Exit status $? from sort";
2538 open(INPUT, 'foo') # get sort's results
1590 open(INPUT, 'foo') # get sort's results
25391591 or die "Can't open 'foo' for input: $!";
25401592
25411593=begin original
25421594
25431595FILEHANDLE may be an expression whose value can be used as an indirect
2544filehandle, usually the real filehandle name or an autovivified handle.
1596filehandle, usually the real filehandle name.
25451597
25461598=end original
25471599
2548FILEHANDLE は式でもかまいません; この場合、値は間接ファイルハンドルと
1600FILEHANDLE は式でもかまいませんこの場合、値は間接ファイルハンドルと
2549して扱われ、普通は実際のファイルハンドル名か自動有効化されたハンドルです。
1601して扱われ、普通は実際のファイルハンドル名です。
25501602
25511603=item closedir DIRHANDLE
2552X<closedir>
25531604
2554=for Pod::Functions close directory handle
2555
25561605=begin original
25571606
2558Closes a directory opened by L<C<opendir>|/opendir DIRHANDLE,EXPR> and
1607Closes a directory opened by C<opendir> and returns the success of that
2559returns the success of that system call.
1608system call.
25601609
25611610=end original
25621611
2563L<C<opendir>|/opendir DIRHANDLE,EXPR> でオープンしたディレクトリをクローズし、
1612C<opendir> でオープンしたディレクトリをクローズし、
25641613システムコールの返り値を返します。
25651614
2566=item connect SOCKET,NAME
1615=begin original
2567X<connect>
25681616
2569=for Pod::Functions connect to a remote socket
1617DIRHANDLE may be an expression whose value can be used as an indirect
1618dirhandle, usually the real dirhandle name.
25701619
1620=end original
1621
1622DIRHANDLE は式でもかまいません。この場合、値は相対ディレクトリハンドルと
1623して扱われ、普通は実際のディレクトリハンドル名です。
1624
1625=item connect SOCKET,NAME
1626
25711627=begin original
25721628
2573Attempts to connect to a remote socket, just like L<connect(2)>.
1629Attempts to connect to a remote socket, just as the connect system call
2574Returns true if it succeeded, false otherwise. NAME should be a
1630does. Returns true if it succeeded, false otherwise. NAME should be a
25751631packed address of the appropriate type for the socket. See the examples in
25761632L<perlipc/"Sockets: Client/Server Communication">.
25771633
25781634=end original
25791635
2580L<connect(2)> システムコールと同様に、リモートソケットへの接続を試みます。
1636connect(2) システムコールと同様に、リモートソケットへの接続を試みます。
2581成功時には真を、さもなければ偽を返します。
1637成功時には真を返し失敗時には偽を返します。
25821638NAME は、ソケットに対する、適切な型のパックされた
25831639アドレスでなければなりません。
25841640L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
25851641
25861642=item continue BLOCK
2587X<continue>
25881643
2589=item continue
2590
2591=for Pod::Functions optional trailing block in a while or foreach
2592
25931644=begin original
25941645
2595When followed by a BLOCK, L<C<continue>|/continue BLOCK> is actually a
1646Actually a flow control statement rather than a function. If there is a
2596flow control statement rather than a function. If there is a
1647C<continue> BLOCK attached to a BLOCK (typically in a C<while> or
2597L<C<continue>|/continue BLOCK> BLOCK attached to a BLOCK (typically in a
1648C<foreach>), it is always executed just before the conditional is about to
2598C<while> or C<foreach>), it is always executed just before the
1649be evaluated again, just like the third part of a C<for> loop in C. Thus
2599conditional is about to be evaluated again, just like the third part of
1650it can be used to increment a loop variable, even when the loop has been
2600a C<for> loop in C. Thus it can be used to increment a loop variable,
1651continued via the C<next> statement (which is similar to the C C<continue>
2601even when the loop has been continued via the L<C<next>|/next LABEL>
2602statement (which is similar to the C L<C<continue>|/continue BLOCK>
26031652statement).
26041653
26051654=end original
26061655
2607BLOCK が引き続く場合、L<C<continue>|/continue BLOCK> は実際には関数ではなく、
1656実際には関数ではなく、実行制御文です。
2608実行制御文です。
1657C<continue> BLOCK が BLOCK (典型的には C<while> または C<foreach> の中)にあると、
2609L<C<continue>|/continue BLOCK> BLOCK BLOCK (典型的は C<while> たは
1658これは条件文再評価される直前常に実行されす。
2610C<foreach> の中)にあると、これは条件文が再評価される直前に常に実行されます;
26111659これは C における C<for> ループの 3 番目の部分と同様です。
2612従って、これは L<C<next>|/next LABEL> (これは C の
1660従って、これは C<next> 文
2613L<C<continue>|/continue BLOCK> 文と似ています) を使って
1661(これは C の C<continue> 文と似ています)を使ってループが繰り返されるときでも
2614ループが繰り返されるときでもループ変数を増やしたいときに使えます。
1662ループ変数を増やしたいときに使えます。
26151663
26161664=begin original
26171665
2618L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, or
1666C<last>, C<next>, or C<redo> may appear within a C<continue>
2619L<C<redo>|/redo LABEL> may appear within a
1667block. C<last> and C<redo> will behave as if they had been executed within
2620L<C<continue>|/continue BLOCK> block; L<C<last>|/last LABEL> and
1668the main block. So will C<next>, but since it will execute a C<continue>
2621L<C<redo>|/redo LABEL> behave as if they had been executed within the
1669block, it may be more entertaining.
2622main block. So will L<C<next>|/next LABEL>, but since it will execute a
2623L<C<continue>|/continue BLOCK> block, it may be more entertaining.
26241670
26251671=end original
26261672
2627L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL> が
1673C<last>, C<next>, C<redo> が C<continue> ブロック内に現れる可能性あります。
2628L<C<continue>|/continue BLOCK> ブロック内に現る可能性があります;
1674C<last> C<redo> はメインブロックの中で実行さたのと同じように振舞います
2629L<C<last>|/last LABEL> と L<C<redo>|/redo LABEL> はメインブロックの
1675C<next> の場合は、C<continue> ブロックを実行することになるので
2630実行されたのと同じうに振舞います。
1676り面白ことになります。
2631L<C<next>|/next LABEL> の場合は、L<C<continue>|/continue BLOCK> ブロックを
2632実行することになるので、より面白いことになります。
26331677
26341678 while (EXPR) {
2635 ### redo always comes here
1679 ### redo always comes here
2636 do_something;
1680 do_something;
26371681 } continue {
2638 ### next always comes here
1682 ### next always comes here
2639 do_something_else;
1683 do_something_else;
2640 # then back the top to re-check EXPR
1684 # then back the top to re-check EXPR
26411685 }
26421686 ### last always comes here
26431687
26441688=begin original
26451689
2646Omitting the L<C<continue>|/continue BLOCK> section is equivalent to
1690Omitting the C<continue> section is semantically equivalent to using an
2647using an empty one, logically enough, so L<C<next>|/next LABEL> goes
1691empty one, logically enough. In that case, C<next> goes directly back
2648directly back to check the condition at the top of the loop.
1692to check the condition at the top of the loop.
26491693
26501694=end original
26511695
2652L<C<continue>|/continue BLOCK> 節を省略するのは、空の節を指定したのと同じで、
1696C<continue> 節を省略するのは、文法的には空の節を指定したのと同じで、
2653論理的には十分なの、この場合、L<C<next>|/next LABEL> は直接ループ先頭の
1697論理的には十分です。
2654条件チェックに戻ります。
1698この場合、C<next> は直接ループ先頭の条件チェックに戻ります。
26551699
2656=begin original
2657
2658When there is no BLOCK, L<C<continue>|/continue BLOCK> is a function
2659that falls through the current C<when> or C<default> block instead of
2660iterating a dynamically enclosing C<foreach> or exiting a lexically
2661enclosing C<given>. In Perl 5.14 and earlier, this form of
2662L<C<continue>|/continue BLOCK> was only available when the
2663L<C<"switch"> feature|feature/The 'switch' feature> was enabled. See
2664L<feature> and L<perlsyn/"Switch Statements"> for more information.
2665
2666=end original
2667
2668BLOCK がなければ、L<C<continue>|/continue BLOCK> は動的に囲まれた C<foreach> や
2669レキシカルに囲まれた C<given> で反復するのではなく、現在の C<when> または
2670C<default> のブロックを通り抜けるための文です。
2671Perl 5.14 以前では、この形式の L<C<continue>|/continue BLOCK> は
2672L<C<"switch"> 機能|feature/The 'switch' feature> が有効の場合にのみ
2673利用可能です。
2674さらなる情報については L<feature> と L<perlsyn/"Switch Statements"> を
2675参照してください。
2676
26771700=item cos EXPR
2678X<cos> X<cosine> X<acos> X<arccosine>
26791701
26801702=item cos
26811703
2682=for Pod::Functions cosine function
2683
26841704=begin original
26851705
26861706Returns the cosine of EXPR (expressed in radians). If EXPR is omitted,
2687takes the cosine of L<C<$_>|perlvar/$_>.
1707takes cosine of C<$_>.
26881708
26891709=end original
26901710
26911711(ラジアンで示した) EXPR の余弦を返します。
2692EXPR が省略されたときには、L<C<$_>|perlvar/$_> の余弦を取ります。
1712EXPR が省略されたときには、C<$_> の余弦を取ります。
26931713
26941714=begin original
26951715
2696For the inverse cosine operation, you may use the
1716For the inverse cosine operation, you may use the C<Math::Trig::acos()>
2697L<C<Math::Trig::acos>|Math::Trig> function, or use this relation:
1717function, or use this relation:
26981718
26991719=end original
27001720
2701逆余弦を求めるためには、L<C<Math::Trig::acos>|Math::Trig> 関数を使うか、
1721逆余弦を求めるためには、C<Math::Trig::acos()> 関数を使うか、
27021722以下の関係を使ってください。
27031723
27041724 sub acos { atan2( sqrt(1 - $_[0] * $_[0]), $_[0] ) }
27051725
27061726=item crypt PLAINTEXT,SALT
2707X<crypt> X<digest> X<hash> X<salt> X<plaintext> X<password>
2708X<decrypt> X<cryptography> X<passwd> X<encrypt>
27091727
2710=for Pod::Functions one-way passwd-style encryption
2711
27121728=begin original
27131729
2714Creates a digest string exactly like the L<crypt(3)> function in the C
1730Encrypts a string exactly like the crypt(3) function in the C library
2715library (assuming that you actually have a version there that has not
1731(assuming that you actually have a version there that has not been
2716been extirpated as a potential munition).
1732extirpated as a potential munition). This can prove useful for checking
1733the password file for lousy passwords, amongst other things. Only the
1734guys wearing white hats should do this.
27171735
27181736=end original
27191737
2720C ライブラリの L<crypt(3)> 関数と全く同じように、ダイジェスト文字列を
1738C ライブラリの crypt(3) 関数と全く同じように、文字列を暗号化します
2721作成します(一時的な必需品として、まだ絶滅していないバージョンを
1739(一時的な必需品として、まだ絶滅していないバージョンを持っていると仮定しています)。
2722持っていると仮定しています)。
1740パスワードファイルの中で、
1741あまり良くないものをチェックするために使うことができます。
1742公正な人だけが、これを行なうべきです。
27231743
27241744=begin original
27251745
2726L<C<crypt>|/crypt PLAINTEXT,SALT> is a one-way hash function. The
1746Note that C<crypt> is intended to be a one-way function, much like breaking
2727PLAINTEXT and SALT are turned
1747eggs to make an omelette. There is no (known) corresponding decrypt
2728into a short string, called a digest, which is returned. The same
1748function. As a result, this function isn't all that useful for
2729PLAINTEXT and SALT will always return the same string, but there is no
1749cryptography. (For that, see your nearby CPAN mirror.)
2730(known) way to get the original PLAINTEXT from the hash. Small
2731changes in the PLAINTEXT or SALT will result in large changes in the
2732digest.
27331750
27341751=end original
27351752
2736L<C<crypt>|/crypt PLAINTEXT,SALT> は一方向ハッシュ関数です
1753C<crypt> は一方向関数を指向していることに注意してください
2737PLAINTEXT と SALT はダイジェストと呼ばれ短い文字列変えられて、
1754オムレツを作卵を割るようなものです。
2738が返されます。
1755(知らている限り)対応る復号化関数はありません
2739PLAINTEXT SALT が同じ場合同じ文字列を返しますが、ハッシュから
1756結果して、この関数あらゆる暗号て有効というわけではありせん
2740の PLAINTEXT得る(既知の)方法はありません
1757(こためには、お近くの CPAN を参照してください)。
2741PLAINTEXT や SALT を少し変更してもダイジェストは大きく変更されます。
27421758
27431759=begin original
27441760
2745There is no decrypt function. This function isn't all that useful for
1761When verifying an existing encrypted string you should use the encrypted
2746cryptography (for that, look for F<Crypt> modules on your nearby CPAN
1762text as the salt (like C<crypt($plain, $crypted) eq $crypted>). This
2747mirror) and the name "crypt" is a bit of a misnomer. Instead it is
1763allows your code to work with the standard C<crypt> and with more
2748primarily used to check if two pieces of text are the same without
1764exotic implementations. When choosing a new salt create a random two
2749having to transmit or store the text itself. An example is checking
1765character string whose characters come from the set C<[./0-9A-Za-z]>
2750if a correct password is given. The digest of the password is stored,
1766(like C<join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]>).
2751not the password itself. The user types in a password that is
2752L<C<crypt>|/crypt PLAINTEXT,SALT>'d with the same salt as the stored
2753digest. If the two digests match, the password is correct.
27541767
27551768=end original
27561769
2757号化関数ありません。
1770すでにある暗号化された文字列の検証するに、暗号化されたテキストを
2758この関数は暗号化のためにはまったく役に立ちません(ためは、
1771(C<crypt($plain, $crypted) eq $crypted> ようして)salt として使います。
2759お近くの CPAN ミラーで F<Crypt> モジュールを探してください)ので
1772これによって標準的な C<crypt> より風変わりな実装で動作します。
2760"crypt" という名前は少し間違った名前です。
2761その代わりに、一般的には二つのテキスト片が同じかどうかをテキストそのものを
2762転送したり保管したりせずにチェックするために使います。
2763例としては、正しいパスワードが与えられたかどうかをチェックがあります。
2764パスワード自身ではなく、パスワードのダイジェストが保管されます。
2765ユーザーがパスワードを入力すると、保管されているダイジェストと同じ
2766salt で L<C<crypt>|/crypt PLAINTEXT,SALT> します。
2767二つのダイジェストが同じなら、パスワードは正しいです。
2768
2769=begin original
2770
2771When verifying an existing digest string you should use the digest as
2772the salt (like C<crypt($plain, $digest) eq $digest>). The SALT used
2773to create the digest is visible as part of the digest. This ensures
2774L<C<crypt>|/crypt PLAINTEXT,SALT> will hash the new string with the same
2775salt as the digest. This allows your code to work with the standard
2776L<C<crypt>|/crypt PLAINTEXT,SALT> and with more exotic implementations.
2777In other words, assume nothing about the returned string itself nor
2778about how many bytes of SALT may matter.
2779
2780=end original
2781
2782すでにあるダイジェスト文字列を検証するには、ダイジェストを
2783(C<crypt($plain, $digest) eq $digest> のようにして)salt として使います。
2784ダイジェストを作るのに使われた SALT はダイジェストの一部として見えます。
2785これにより、L<C<crypt>|/crypt PLAINTEXT,SALT> は同じ salt で新しい文字列を
2786ダイジェストとしてハッシュ化できるようにします。
2787これによって標準的な L<C<crypt>|/crypt PLAINTEXT,SALT> や、より風変わりな
2788実装でも動作します。
2789言い換えると、返される文字列や、SALT が何バイトあるかといったことに対して、
2790どのような仮定もしてはいけません。
2791
2792=begin original
2793
2794Traditionally the result is a string of 13 bytes: two first bytes of
2795the salt, followed by 11 bytes from the set C<[./0-9A-Za-z]>, and only
2796the first eight bytes of PLAINTEXT mattered. But alternative
2797hashing schemes (like MD5), higher level security schemes (like C2),
2798and implementations on non-Unix platforms may produce different
2799strings.
2800
2801=end original
2802
2803伝統的には結果は 13 バイトの文字列です: 最初の 2 バイトは salt、引き続いて
2804集合 C<[./0-9A-Za-z]> からの 11 バイトで、PLAINTEXT の最初の
28058 バイトだけが意味があります。
2806しかし、(MD5 のように) 異なったハッシュ手法、
2807(C2 のような) 高レベルセキュリティ手法、非 Unix プラットフォームでの
2808実装などでは異なった文字列が生成されることがあります。
2809
2810=begin original
2811
2812When choosing a new salt create a random two character string whose
2813characters come from the set C<[./0-9A-Za-z]> (like C<join '', ('.',
2814'/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]>). This set of
2815characters is just a recommendation; the characters allowed in
2816the salt depend solely on your system's crypt library, and Perl can't
2817restrict what salts L<C<crypt>|/crypt PLAINTEXT,SALT> accepts.
2818
2819=end original
2820
28211773新しい salt を選択する場合は、集合 C<[./0-9A-Za-z]> から
2822(C<join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]> の
1774(C<join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]> のようにして)
2823ようにして)ランダムに2 つの文字を選びます。
1775ランダムに2 つの文字を選びます。
2824この文字集合は単なる推薦です; salt として許される文字はシステムの暗号化
2825ライブラリだけに依存し、Perl は L<C<crypt>|/crypt PLAINTEXT,SALT> が
2826どのような salt を受け付けるかについて制限しません。
28271776
28281777=begin original
28291778
28301779Here's an example that makes sure that whoever runs this program knows
2831their password:
1780their own password:
28321781
28331782=end original
28341783
28351784プログラムを実行する人が、
28361785自分のパスワードを知っていることを確認する例です:
28371786
2838 my $pwd = (getpwuid($<))[1];
1787 $pwd = (getpwuid($<))[1];
28391788
28401789 system "stty -echo";
28411790 print "Password: ";
2842 chomp(my $word = <STDIN>);
1791 chomp($word = <STDIN>);
28431792 print "\n";
28441793 system "stty echo";
28451794
28461795 if (crypt($word, $pwd) ne $pwd) {
2847 die "Sorry...\n";
1796 die "Sorry...\n";
28481797 } else {
2849 print "ok\n";
1798 print "ok\n";
28501799 }
28511800
28521801=begin original
28531802
28541803Of course, typing in your own password to whoever asks you
28551804for it is unwise.
28561805
28571806=end original
28581807
28591808もちろん、自分自身のパスワードを誰にでも入力するのは賢明ではありません。
28601809
28611810=begin original
28621811
2863The L<C<crypt>|/crypt PLAINTEXT,SALT> function is unsuitable for hashing
1812The L<crypt> function is unsuitable for encrypting large quantities
2864large quantities of data, not least of all because you can't get the
1813of data, not least of all because you can't get the information
2865information back. Look at the L<Digest> module for more robust
1814back. Look at the F<by-module/Crypt> and F<by-module/PGP> directories
2866algorithms.
1815on your favorite CPAN mirror for a slew of potentially useful
1816modules.
28671817
28681818=end original
28691819
2870L<C<crypt>|/crypt PLAINTEXT,SALT> 関数は大量のデータのハッシュ化には
1820L<crypt> 関数は大量のデータの暗号化には向いていません。
2871向いていません; これは情報を戻せないという理由だけではありません。
1821これは情報を戻せないという理由だけではありません。
2872より頑強アルゴリズムについては L<Digest> モジュールを参照してください。
1822たのお好みの CPAN ミラー の F<by-module/Crypt> と F<by-module/PGP>
1823ディレクトリを見れば、あなたの役に立ちそうなモジュールが大量にあります。
28731824
2874=begin original
2875
2876If using L<C<crypt>|/crypt PLAINTEXT,SALT> on a Unicode string (which
2877I<potentially> has characters with codepoints above 255), Perl tries to
2878make sense of the situation by trying to downgrade (a copy of) the
2879string back to an eight-bit byte string before calling
2880L<C<crypt>|/crypt PLAINTEXT,SALT> (on that copy). If that works, good.
2881If not, L<C<crypt>|/crypt PLAINTEXT,SALT> dies with
2882L<C<Wide character in crypt>|perldiag/Wide character in %s>.
2883
2884=end original
2885
2886Unicode 文字列(I<潜在的には> 255 を越えるコードポイントを持つ文字を
2887含みます)に L<C<crypt>|/crypt PLAINTEXT,SALT> を使った場合、Perl は
2888L<C<crypt>|/crypt PLAINTEXT,SALT> を呼び出す前に与えられた
2889文字列を8 ビットバイト文字列にダウングレードする(文字列のコピーを作る)
2890ことで状況のつじつまを合わせようとします。
2891うまく動けば、それでよし。
2892動かなければ、L<C<crypt>|/crypt PLAINTEXT,SALT> は
2893L<C<Wide character in crypt>|perldiag/Wide character in %s> という
2894メッセージと共に die します。
2895
2896=begin original
2897
2898Portability issues: L<perlport/crypt>.
2899
2900=end original
2901
2902移植性の問題: L<perlport/crypt>。
2903
29041825=item dbmclose HASH
2905X<dbmclose>
29061826
2907=for Pod::Functions breaks binding on a tied dbm file
2908
29091827=begin original
29101828
2911[This function has been largely superseded by the
1829[This function has been largely superseded by the C<untie> function.]
2912L<C<untie>|/untie VARIABLE> function.]
29131830
2914=end original
2915
2916[この関数は、L<C<untie>|/untie VARIABLE> 関数に大きくとって代わられました。]
2917
2918=begin original
2919
29201831Breaks the binding between a DBM file and a hash.
29211832
29221833=end original
29231834
1835[この関数は、C<untie> 関数に大きくとって代わられました。]
1836
29241837DBM ファイルとハッシュの連結をはずします。
29251838
2926=begin original
2927
2928Portability issues: L<perlport/dbmclose>.
2929
2930=end original
2931
2932移植性の問題: L<perlport/dbmclose>。
2933
29341839=item dbmopen HASH,DBNAME,MASK
2935X<dbmopen> X<dbm> X<ndbm> X<sdbm> X<gdbm>
29361840
2937=for Pod::Functions create binding on a tied dbm file
2938
29391841=begin original
29401842
2941[This function has been largely superseded by the
1843[This function has been largely superseded by the C<tie> function.]
2942L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function.]
29431844
2944=end original
1845This binds a dbm(3), ndbm(3), sdbm(3), gdbm(3), or Berkeley DB file to a
1846hash. HASH is the name of the hash. (Unlike normal C<open>, the first
2946[この関数は、L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数に
1847argument is I<not> a filehandle, even though it looks like one). DBNAME
2947大きくとって代わられました。]
1848is the name of the database (without the F<.dir> or F<.pag> extension if
1849any). If the database does not exist, it is created with protection
2949=begin original
1850specified by MASK (as modified by the C<umask>). If your system supports
1851only the older DBM functions, you may perform only one C<dbmopen> in your
2951This binds a L<dbm(3)>, L<ndbm(3)>, L<sdbm(3)>, L<gdbm(3)>, or Berkeley
2952DB file to a hash. HASH is the name of the hash. (Unlike normal
2953L<C<open>|/open FILEHANDLE,EXPR>, the first argument is I<not> a
2954filehandle, even though it looks like one). DBNAME is the name of the
2955database (without the F<.dir> or F<.pag> extension if any). If the
2956database does not exist, it is created with protection specified by MASK
2957(as modified by the L<C<umask>|/umask EXPR>). To prevent creation of
2958the database if it doesn't exist, you may specify a MODE of 0, and the
2959function will return a false value if it can't find an existing
2960database. If your system supports only the older DBM functions, you may
2961make only one L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> call in your
29621852program. In older versions of Perl, if your system had neither DBM nor
2963ndbm, calling L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> produced a fatal
1853ndbm, calling C<dbmopen> produced a fatal error; it now falls back to
2964error; it now falls back to L<sdbm(3)>.
1854sdbm(3).
29651855
29661856=end original
29671857
2968L<dbm(3)>, L<ndbm(3)>, L<sdbm(3)>, L<gdbm(3)> ファイルまた
1858[この関数は、C<tie> 関数に大きくとって代わられ。]
2969Berkeley DB ファイルを連想配列に結び付けます。
1860dbm(3), ndbm(3), sdbm(3), gdbm(3) ファイルまたは Berkeley DB
1861ファイルを連想配列に結び付けます。
29701862HASH は、その連想配列の名前です。
2971(普通の L<C<open>|/open FILEHANDLE,EXPR> とは違って、最初の引数は
1863(普通の C<open> とは違って、最初の引数はファイルハンドル
2972ファイルハンドル I<ではありません>; まあ、似たようなものですが)
1864I<ではありません>まあ、似たようなものですが。)
2973DBNAME は、データベースの名前です (拡張子の .dir や .pag はもしあっても
1865DBNAME は、データベースの名前です (拡張子の .dir や
2974つけません)。
1866.pag はもしあってもつけません)。
2975データベースが存在しなければ、MODE MASK (を L<C<umask>|/umask EXPR>
1867データベースが存在しなければ、MODE MASK (を C<umask> で修正したもの)
2976修正したもの) で指定されたモードで作られます。
1868指定されたモードで作られます。
2977存在しないときにデータベースを作成しないようにするには、MODE に 0 を
2978設定でき、データベースを見つけられなかった場合は関数は偽を返します。
29791869古い DBM 関数のみをサポートしているシステムでは、プログラム中で 1 度だけ
2980L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を実行することができます。
1870dbmopen() を実行することができます。
29811871昔のバージョンの Perl では、DBM も ndbm も持っていないシステムでは、
2982L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を呼び出すと致命的エラーになります;
1872dbmopen() を呼び出すと致命的エラーになります
2983現在では L<sdbm(3)> にフォールバックします。
1873現在では sdbm(3) にフォールバックします。
29841874
29851875=begin original
29861876
29871877If you don't have write access to the DBM file, you can only read hash
29881878variables, not set them. If you want to test whether you can write,
2989either use file tests or try setting a dummy hash entry inside an
1879either use file tests or try setting a dummy hash entry inside an C<eval>,
2990L<C<eval>|/eval EXPR> to trap the error.
1880which will trap the error.
29911881
29921882=end original
29931883
29941884DBM ファイルに対して、書き込み権が無いときには、ハッシュ
29951885配列を読みだすことだけができ、設定することはできません。
29961886書けるか否かを調べたい場合には、ファイルテスト
2997演算子を使うか、エラーをトラップための L<C<eval>|/eval EXPR> の中で、
1887演算子を使うか、エラーをトラップしてくれC<eval>
2998ダミーのハッシュエントリを設定してみることになります。
1888の中で、ダミーのハッシュエントリを設定してみることになります。
29991889
30001890=begin original
30011891
3002Note that functions such as L<C<keys>|/keys HASH> and
1892Note that functions such as C<keys> and C<values> may return huge lists
3003L<C<values>|/values HASH> may return huge lists when used on large DBM
1893when used on large DBM files. You may prefer to use the C<each>
3004files. You may prefer to use the L<C<each>|/each HASH> function to
1894function to iterate over large DBM files. Example:
3005iterate over large DBM files. Example:
30061895
30071896=end original
30081897
3009大きな DBM ファイルを扱うときには、L<C<keys>|/keys HASH>
1898大きな DBM ファイルを扱うときには、C<keys> や C<values> のような関数は、
3010L<C<values>|/values HASH> のような関数は、巨大なリストを返します。
1899巨大なリストを返します。
3011大きな DBM ファイルでは、L<C<each>|/each HASH> 関数を使って繰り返しを
1900大きな DBM ファイルでは、C<each> 関数を使って繰り返しを行なった方が
3012行なった方が良いかもしれません。
1901良いかもしれません。
30131902例:
30141903
30151904 # print out history file offsets
30161905 dbmopen(%HIST,'/usr/lib/news/history',0666);
30171906 while (($key,$val) = each %HIST) {
3018 print $key, ' = ', unpack('L',$val), "\n";
1907 print $key, ' = ', unpack('L',$val), "\n";
30191908 }
30201909 dbmclose(%HIST);
30211910
30221911=begin original
30231912
30241913See also L<AnyDBM_File> for a more general description of the pros and
30251914cons of the various dbm approaches, as well as L<DB_File> for a particularly
30261915rich implementation.
30271916
30281917=end original
30291918
30301919様々な dbm 手法に対する利点欠点に関するより一般的な記述および
30311920特にリッチな実装である L<DB_File> に関しては
30321921L<AnyDBM_File> も参照してください。
30331922
30341923=begin original
30351924
30361925You can control which DBM library you use by loading that library
3037before you call L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>:
1926before you call dbmopen():
30381927
30391928=end original
30401929
3041L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を呼び出す前にライブラリを
1930dbmopen() を呼び出す前にライブラリを読み込むことで、
3042読み込むことで、どの DBM ライブラリを使うかを制御できます:
1931どの DBM ライブラリを使うかを制御できます:
30431932
30441933 use DB_File;
30451934 dbmopen(%NS_Hist, "$ENV{HOME}/.netscape/history.db")
3046 or die "Can't open netscape history file: $!";
1935 or die "Can't open netscape history file: $!";
30471936
3048=begin original
3049
3050Portability issues: L<perlport/dbmopen>.
3051
3052=end original
3053
3054移植性の問題: L<perlport/dbmopen>。
3055
30561937=item defined EXPR
3057X<defined> X<undef> X<undefined>
30581938
30591939=item defined
30601940
3061=for Pod::Functions test whether a value, variable, or function is defined
3062
30631941=begin original
30641942
3065Returns a Boolean value telling whether EXPR has a value other than the
1943Returns a Boolean value telling whether EXPR has a value other than
3066undefined value L<C<undef>|/undef EXPR>. If EXPR is not present,
1944the undefined value C<undef>. If EXPR is not present, C<$_> will be
3067L<C<$_>|perlvar/$_> is checked.
1945checked.
30681946
30691947=end original
30701948
3071左辺値 EXPR が未定義値 L<C<undef>|/undef EXPR> 以外の値を持つか否かを示す、
1949左辺値 EXPR が未定義値 C<undef> 以外の値を持つか否かを示す、ブール値を
3072ブール値を返します。
1950返します。
3073EXPR がない場合は、L<C<$_>|perlvar/$_> がチェックされます。
1951EXPR がない場合は、C<$_> がチェックされます。
30741952
30751953=begin original
30761954
3077Many operations return L<C<undef>|/undef EXPR> to indicate failure, end
1955Many operations return C<undef> to indicate failure, end of file,
3078of file, system error, uninitialized variable, and other exceptional
1956system error, uninitialized variable, and other exceptional
3079conditions. This function allows you to distinguish
1957conditions. This function allows you to distinguish C<undef> from
3080L<C<undef>|/undef EXPR> from other values. (A simple Boolean test will
1958other values. (A simple Boolean test will not distinguish among
3081not distinguish among L<C<undef>|/undef EXPR>, zero, the empty string,
1959C<undef>, zero, the empty string, and C<"0">, which are all equally
3082and C<"0">, which are all equally false.) Note that since
1960false.) Note that since C<undef> is a valid scalar, its presence
3083L<C<undef>|/undef EXPR> is a valid scalar, its presence doesn't
1961doesn't I<necessarily> indicate an exceptional condition: C<pop>
3084I<necessarily> indicate an exceptional condition: L<C<pop>|/pop ARRAY>
1962returns C<undef> when its argument is an empty array, I<or> when the
3085returns L<C<undef>|/undef EXPR> when its argument is an empty array,
1963element to return happens to be C<undef>.
3086I<or> when the element to return happens to be L<C<undef>|/undef EXPR>.
30871964
30881965=end original
30891966
30901967多くの演算子が、EOF や未初期化変数、システムエラーといった、
3091例外的な条件で L<C<undef>|/undef EXPR> を返すようになっています。
1968例外的な条件で C<undef> を返すようになっています。
3092この関数は、他の値と L<C<undef>|/undef EXPR> とを区別するために使えます。
1969この関数は、他の値と C<undef> とを区別するために使えます。
3093(単純な真偽値テストでは、L<C<undef>|/undef EXPR>、0、C<"0"> のいずれも偽を
1970(単純な真偽値テストでは、C<undef>、0、空文字、C<"0"> のいずれも偽を返すので、
3094返すので、区別することができません。)
1971区別することができません。)
3095L<C<undef>|/undef EXPR> は有効なスカラ値なので、その存在が I<必ずしも>
1972C<undef> は有効なスカラ値なので、その存在が I<必ずしも>
30961973例外的な状況を表すとは限らないということに注意してください:
3097L<C<pop>|/pop ARRAY> は引数が空の配列だったときに L<C<undef>|/undef EXPR>
1974C<pop> は引数が空の配列だったときに C<undef> を返しますが、
3098返しますが、I<あるいは> 返すべき要素がたまたま
1975I<あるいは> 返すべき要素がたまたま C<undef> だったのかもしれません。
3099L<C<undef>|/undef EXPR> だったのかもしれません。
31001976
31011977=begin original
31021978
3103You may also use C<defined(&func)> to check whether subroutine C<func>
1979You may also use C<defined(&func)> to check whether subroutine C<&func>
31041980has ever been defined. The return value is unaffected by any forward
3105declarations of C<func>. A subroutine that is not defined
1981declarations of C<&foo>. Note that a subroutine which is not defined
31061982may still be callable: its package may have an C<AUTOLOAD> method that
3107makes it spring into existence the first time that it is called; see
1983makes it spring into existence the first time that it is called -- see
31081984L<perlsub>.
31091985
31101986=end original
31111987
3112C<defined(&func)> とすることでサブルーチン C<func> の存在を、
1988C<defined(&func)> とすることでサブルーチン C<&func> の存在を、
31131989確かめることもできます。
3114返り値は C<func> の前方定義には影響されません。
1990返り値は C<&foo> の前方定義には影響されません。
3115定義されていないサブルーチンも呼び出し可能です:
1991定義されていないサブルーチンも呼び出し可能であることに注意してください。
31161992最初に呼び出されたときに存在するようにするための
3117C<AUTOLOAD> メソッドを持ったパッケージかもしれません;
1993C<AUTOLOAD> メソッドを持ったパッケージかもしれません--
3118L<perlsub> を参照してください。
1994L<perlsub> を参照してさい。
31191995
31201996=begin original
31211997
3122Use of L<C<defined>|/defined EXPR> on aggregates (hashes and arrays) is
1998Use of C<defined> on aggregates (hashes and arrays) is deprecated. It
3123no longer supported. It used to report whether memory for that
1999used to report whether memory for that aggregate has ever been
3124aggregate had ever been allocated. You should instead use a simple
2000allocated. This behavior may disappear in future versions of Perl.
3125test for size:
2001You should instead use a simple test for size:
31262002
31272003=end original
31282004
3129集合(ハッシュや配列)への L<C<defined>|/defined EXPR> の使用は
2005集合(ハッシュや配列)への C<defined> の使用は非推奨です。
3130や対応しいません。
2006これその集合にメモリが割り当られたかを報告するのに
3131これはその集合にメモリが割り当てられたかを報告するのに用いられていました。
2007用いられていました。
2008この振る舞いは将来のバージョンの Perl では消滅するかもしれません。
31322009代わりにサイズに対する簡単なテストを使うべきです。
31332010
31342011 if (@an_array) { print "has array elements\n" }
31352012 if (%a_hash) { print "has hash members\n" }
31362013
31372014=begin original
31382015
31392016When used on a hash element, it tells you whether the value is defined,
3140not whether the key exists in the hash. Use L<C<exists>|/exists EXPR>
2017not whether the key exists in the hash. Use L</exists> for the latter
3141for the latter purpose.
2018purpose.
31422019
2020Examples:
2021
31432022=end original
31442023
31452024ハッシュの要素に対して用いると、value が定義されているか否かを
31462025返すものであって、ハッシュに key が存在するか否かを返すのではありません。
3147この用途には、L<C<exists>|/exists EXPR> を使ってください。
2026この用途には、L</exists> を使ってください。
31482027
3149=begin original
3150
3151Examples:
3152
3153=end original
3154
31552028例:
31562029
3157 print if defined $switch{D};
2030 print if defined $switch{'D'};
31582031 print "$val\n" while defined($val = pop(@ary));
31592032 die "Can't readlink $sym: $!"
3160 unless defined($value = readlink $sym);
2033 unless defined($value = readlink $sym);
3161 sub foo { defined &$bar ? $bar->(@_) : die "No bar"; }
2034 sub foo { defined &$bar ? &$bar(@_) : die "No bar"; }
31622035 $debugging = 0 unless defined $debugging;
31632036
31642037=begin original
31652038
3166Note: Many folks tend to overuse L<C<defined>|/defined EXPR> and are
2039Note: Many folks tend to overuse C<defined>, and then are surprised to
3167then surprised to discover that the number C<0> and C<""> (the
2040discover that the number C<0> and C<""> (the zero-length string) are, in fact,
3168zero-length string) are, in fact, defined values. For example, if you
2041defined values. For example, if you say
3169say
31702042
31712043=end original
31722044
3173注意: 多くの人々が L<C<defined>|/defined EXPR> を使いすぎて、C<0> と
2045注意: 多くの人々が C<defined> を使いすぎて、C<0> と C<"">(空文字列) が
3174C<"">(空文字列) が実際のところ定義された値であることに驚くようです。
2046実際のところ定義された値であることに驚くようです。
31752047例えば、以下のように書くと:
31762048
31772049 "ab" =~ /a(.*)b/;
31782050
31792051=begin original
31802052
3181The pattern match succeeds and C<$1> is defined, although it
2053The pattern match succeeds, and C<$1> is defined, despite the fact that it
3182matched "nothing". It didn't really fail to match anything. Rather, it
2054matched "nothing". But it didn't really match nothing--rather, it
31832055matched something that happened to be zero characters long. This is all
31842056very above-board and honest. When a function returns an undefined value,
31852057it's an admission that it couldn't give you an honest answer. So you
3186should use L<C<defined>|/defined EXPR> only when questioning the
2058should use C<defined> only when you're questioning the integrity of what
3187integrity of what you're trying to do. At other times, a simple
2059you're trying to do. At other times, a simple comparison to C<0> or C<""> is
3188comparison to C<0> or C<""> is what you want.
2060what you want.
31892061
31902062=end original
31912063
31922064パターンマッチングが成功し、C<$1> が定義されても、実際には
31932065「なし」にマッチしています。
3194しかしこれは何にもマッチしていないわけではありません
2066しかしこれは何にもマッチしていないわけではありません--
31952067何かにはマッチしているのですが、たまたまそれが長さ 0 だっただけです。
31962068これは非常に率直で正直なことです。
31972069関数が未定義値を返すとき、正直な答えを返すことができないことを
31982070告白しています。
31992071ですので、あなたが自分がしようとしていることの完全性を確認するときにだけ
3200L<C<defined>|/defined EXPR> を使うべきです。
2072C<defined> を使うべきです。
32012073その他の場合では、単に C<0> または C<""> と比較するというのがあなたの
32022074求めているものです。
32032075
32042076=begin original
32052077
3206See also L<C<undef>|/undef EXPR>, L<C<exists>|/exists EXPR>,
2078See also L</undef>, L</exists>, L</ref>.
3207L<C<ref>|/ref EXPR>.
32082079
32092080=end original
32102081
3211L<C<undef>|/undef EXPR>, L<C<exists>|/exists EXPR>, L<C<ref>|/ref EXPR> も
2082L</undef>, L</exists>, L</ref> も参照してください。
3212参照してください。
32132083
32142084=item delete EXPR
3215X<delete>
32162085
3217=for Pod::Functions deletes a value from a hash
3218
32192086=begin original
32202087
3221Given an expression that specifies an element or slice of a hash,
2088Given an expression that specifies a hash element, array element, hash slice,
3222L<C<delete>|/delete EXPR> deletes the specified elements from that hash
2089or array slice, deletes the specified element(s) from the hash or array.
3223so that L<C<exists>|/exists EXPR> on that element no longer returns
2090In the case of an array, if the array elements happen to be at the end,
3224true. Setting a hash element to the undefined value does not remove its
2091the size of the array will shrink to the highest element that tests
3225key, but deleting it does; see L<C<exists>|/exists EXPR>.
2092true for exists() (or 0 if no such element exists).
32262093
32272094=end original
32282095
3229ハッシュ要素スライスを指定する式を取り、L<C<delete>|/delete EXPR> は
2096ハッシュ要素、配列要素、ハッシュスライス、配列スライスを指定する式を取り、
3230指定された要素をハッシュから削除するので、
2097指定された要素をハッシュや配列から削除しま
3231の要素に対する L<C<exists>|/exists EXPR> もはや真を返さなくなります。
2098配列場合、配列要素が最後あった場合
3232ハッシュ要素に未定義値をセットしてもそのキーは削除されせんが、
2099配列の大きさは exists() が真を返す最後尾の要素に縮み
3233delete で削除されます; L<C<exists>|/exists EXPR> を参照してください
2100(そのような要素がない場合0 になります)
32342101
32352102=begin original
32362103
3237In list context, usually returns the value or values deleted, or the last such
2104Returns each element so deleted or the undefined value if there was no such
3238element in scalar context. The return list's length corresponds to that of
2105element. Deleting from C<$ENV{}> modifies the environment. Deleting from
3239the argument list: deleting non-existent elements returns the undefined value
2106a hash tied to a DBM file deletes the entry from the DBM file. Deleting
3240in their corresponding positions. When a
2107from a C<tie>d hash or array may not necessarily return anything.
3241L<keyE<sol>value hash slice|perldata/KeyE<sol>Value Hash Slices> is passed to
3242C<delete>, the return value is a list of key/value pairs (two elements for each
3243item deleted from the hash).
32442108
32452109=end original
32462110
3247リストコンテキストでは通常は削除された要素を返しスカラコンテキストで
2111削除された値か(何も削除されなかった場合に) 未定義値が返されます。
3248削除された要素のち最後のものします。
2112C<$ENV{}> から削除を行なと、実際に環境変数変更します。
3249返されたリストの長さは常に引数リストの長さに対応します:
3250存在しない要素を削除すると、対応する位置に未定義値をセットして返します。
3251L<キーE<sol>値ハッシュスライス|perldata/KeyE<sol>Value Hash Slices> が
3252C<delete> に渡されると、返り値はキー/値の組(それぞれのアイテムについて
3253二つの要素が元のハッシュから削除されたもの)です。
3254
3255=begin original
3256
3257L<C<delete>|/delete EXPR> may also be used on arrays and array slices,
3258but its behavior is less straightforward. Although
3259L<C<exists>|/exists EXPR> will return false for deleted entries,
3260deleting array elements never changes indices of existing values; use
3261L<C<shift>|/shift ARRAY> or L<C<splice>|/splice
3262ARRAY,OFFSET,LENGTH,LIST> for that. However, if any deleted elements
3263fall at the end of an array, the array's size shrinks to the position of
3264the highest element that still tests true for L<C<exists>|/exists EXPR>,
3265or to 0 if none do. In other words, an array won't have trailing
3266nonexistent elements after a delete.
3267
3268=end original
3269
3270L<C<delete>|/delete EXPR> は配列や配列のスライスに対しても使えますが、その
3271振る舞いはあまり直感的ではありません。
3272削除されたエントリに対しては L<C<exists>|/exists EXPR> は偽を返しますが、
3273配列要素を削除しても、存在する値の添え字は変わりません; このためには
3274L<C<shift>|/shift ARRAY> や L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> を
3275使ってください。
3276しかし、削除された要素が配列の末尾であった場合、配列のサイズは
3277L<C<exists>|/exists EXPR> が真となる最大位置の要素(それがない場合は 0)に
3278切り詰められます。
3279言い換えると、delete の後には配列の末尾に値のない要素はありません。
3280
3281=begin original
3282
3283B<WARNING:> Calling L<C<delete>|/delete EXPR> on array values is
3284strongly discouraged. The
3285notion of deleting or checking the existence of Perl array elements is not
3286conceptually coherent, and can lead to surprising behavior.
3287
3288=end original
3289
3290B<警告:> 配列の値に対して L<C<delete>|/delete EXPR> を呼び出すことは強く
3291非推奨です。
3292Perl の配列要素を削除したり存在を調べたりする記法は概念的に一貫しておらず、
3293驚くべき振る舞いを引き起こすことがあります。
3294
3295=begin original
3296
3297Deleting from L<C<%ENV>|perlvar/%ENV> modifies the environment.
3298Deleting from a hash tied to a DBM file deletes the entry from the DBM
3299file. Deleting from a L<C<tied>|/tied VARIABLE> hash or array may not
3300necessarily return anything; it depends on the implementation of the
3301L<C<tied>|/tied VARIABLE> package's DELETE method, which may do whatever
3302it pleases.
3303
3304=end original
3305
3306L<C<%ENV>|perlvar/%ENV> から削除を行なうと、実際に環境変数を変更します。
33072113DBM ファイルに tie された配列からの削除は、その DBM ファイルからエントリを
33082114削除します。
3309しかし、L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> されたハッシュや配列からの
2115しかし、C<tie> されたハッシュや配列からの削除は、
3310削除は、値を返すとは限りません; これは
2116値を返すとは限りません
3311L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> されたパッケージの DELETE
3312メソッドの実装に依存するので、どんなことでも起こります。
33132117
33142118=begin original
33152119
3316The C<delete local EXPR> construct localizes the deletion to the current
2120Deleting an array element effectively returns that position of the array
3317block at run time. Until the block exits, elements locally deleted
2121to its initial, uninitialized state. Subsequently testing for the same
3318temporarily no longer exist. See L<perlsub/"Localized deletion of elements
2122element with exists() will return false. Note that deleting array
3319of composite types">.
2123elements in the middle of an array will not shift the index of the ones
2124after them down--use splice() for that. See L</exists>.
33202125
33212126=end original
33222127
3323C<delete local EXPR> 構文は現在ブロック削除を実行時にローカルます。
2128配列要素を削除した場合配列位置は初期、初期されていない状態になります。
3324ブロックから出るまで、ローカルで削除された要素は存在なくなります。
2129引き続いて同じ要素に対て exists() でテストすると偽を返します。
3325L<perlsub/"Localized deletion of elements of composite types">
2130配列の途中の配列要素削除してもインデックスはシフトしないことに
3326参照してください。
2131注意てください -- このためには splice() を使ってください。
2132L</exists> を参照してください。
33272133
3328 my %hash = (foo => 11, bar => 22, baz => 33);
3329 my $scalar = delete $hash{foo}; # $scalar is 11
3330 $scalar = delete @hash{qw(foo bar)}; # $scalar is 22
3331 my @array = delete @hash{qw(foo baz)}; # @array is (undef,33)
3332
33332134=begin original
33342135
33352136The following (inefficiently) deletes all the values of %HASH and @ARRAY:
33362137
33372138=end original
33382139
33392140以下は、%HASH と @ARRAY のすべての値を(非効率的に)削除します:
33402141
3341 foreach my $key (keys %HASH) {
2142 foreach $key (keys %HASH) {
3342 delete $HASH{$key};
2143 delete $HASH{$key};
33432144 }
33442145
3345 foreach my $index (0 .. $#ARRAY) {
2146 foreach $index (0 .. $#ARRAY) {
3346 delete $ARRAY[$index];
2147 delete $ARRAY[$index];
33472148 }
33482149
33492150=begin original
33502151
33512152And so do these:
33522153
33532154=end original
33542155
33552156そして以下のようにもできます:
33562157
33572158 delete @HASH{keys %HASH};
33582159
33592160 delete @ARRAY[0 .. $#ARRAY];
33602161
33612162=begin original
33622163
3363But both are slower than assigning the empty list
2164But both of these are slower than just assigning the empty list
3364or undefining %HASH or @ARRAY, which is the customary
2165or undefining %HASH or @ARRAY:
3365way to empty out an aggregate:
33662166
33672167=end original
33682168
3369しかし、これら二つは両方とも、構造を空にするための慣習的な方法である
2169しかし、これら二つは空リストを代入する%HASH や @ARRAY を
3370単に空リストを代入するか、%HASH や @ARRAY を
33712170undef するより遅いです:
33722171
3373 %HASH = (); # completely empty %HASH
2172 %HASH = (); # completely empty %HASH
3374 undef %HASH; # forget %HASH ever existed
2173 undef %HASH; # forget %HASH ever existed
33752174
3376 @ARRAY = (); # completely empty @ARRAY
2175 @ARRAY = (); # completely empty @ARRAY
3377 undef @ARRAY; # forget @ARRAY ever existed
2176 undef @ARRAY; # forget @ARRAY ever existed
33782177
33792178=begin original
33802179
3381The EXPR can be arbitrarily complicated provided its
2180Note that the EXPR can be arbitrarily complicated as long as the final
3382final operation is an element or slice of an aggregate:
2181operation is a hash element, array element, hash slice, or array slice
2182lookup:
33832183
33842184=end original
33852185
3386最終的な操作が集合の要素スライスである限りは
2186最終的な操作がハッシュ要素、配列要素、ハッシュスライス、配列スライスの
3387いずれかである限りは、EXPR には任意の複雑な式を置くことができます:
2187いずれかである限りは、EXPR には任意の複雑な式を置くことができることに
2188注意してください:
33882189
33892190 delete $ref->[$x][$y]{$key};
33902191 delete @{$ref->[$x][$y]}{$key1, $key2, @morekeys};
33912192
33922193 delete $ref->[$x][$y][$index];
33932194 delete @{$ref->[$x][$y]}[$index1, $index2, @moreindices];
33942195
33952196=item die LIST
3396X<die> X<throw> X<exception> X<raise> X<$@> X<abort>
33972197
3398=for Pod::Functions raise an exception or bail out
3399
34002198=begin original
34012199
3402L<C<die>|/die LIST> raises an exception. Inside an L<C<eval>|/eval EXPR>
2200Outside an C<eval>, prints the value of LIST to C<STDERR> and
3403the exception is stuffed into L<C<$@>|perlvar/$@> and the L<C<eval>|/eval
2201exits with the current value of C<$!> (errno). If C<$!> is C<0>,
3404EXPR> is terminated with the undefined value. If the exception is
2202exits with the value of C<<< ($? >> 8) >>> (backtick `command`
3405outside of all enclosing L<C<eval>|/eval EXPR>s, then the uncaught
2203status). If C<<< ($? >> 8) >>> is C<0>, exits with C<255>. Inside
3406exception is printed to C<STDERR> and perl exits with an exit code
2204an C<eval(),> the error message is stuffed into C<$@> and the
3407indicating failure. If you need to exit the process with a specific
2205C<eval> is terminated with the undefined value. This makes
3408exit code, see L<C<exit>|/exit EXPR>.
2206C<die> the way to raise an exception.
34092207
34102208=end original
34112209
3412L<C<die>|/die LIST> は例外発生させます。
2210C<eval> の外では、LIST の値 C<STDERR> に出力し、その時点の
3413L<C<eval>|/eval EXPR> 使用ると、例外が
2211C<$!> (errno) exit しま
3414L<C<$@>|perlvar/$@> に入り、L<C<eval>|/eval EXPR> は
2212C<$!> の値が C<0> ならば、
3415未定義を返して終了します。
2213C<<< ($? >> 8) >>> (backtick `command` のステータス) ので exitします。
3416例外が全ての L<C<eval>|/eval EXPR> の外側の場合は、捕捉されなかった例外は
2214C<<< ($? >> 8) >>> も C<0> であば、C<255> で exit することにります。
3417C<STDERR> に表示され、perl は失敗を示す終了コード終了しま
2215C<eval> の中使用ると、エラーメッセージが、
3418特定の終了コードでプロセスを終了させる必要がある場合は、
2216C<$@> に入れられます。
3419L<C<exit>|/exit EXPR> 参照てください
2217C<eval> は中断され、未定義値ます
2218これが C<die> が例外を発生させる方法です。
34202219
34212220=begin original
34222221
34232222Equivalent examples:
34242223
34252224=end original
34262225
34272226等価な例:
34282227
34292228 die "Can't cd to spool: $!\n" unless chdir '/usr/spool/news';
34302229 chdir '/usr/spool/news' or die "Can't cd to spool: $!\n"
34312230
34322231=begin original
34332232
3434Most of the time, C<die> is called with a string to use as the exception.
2233If the value of EXPR does not end in a newline, the current script line
3435You may either give a single non-reference operand to serve as the
2234number and input line number (if any) are also printed, and a newline
3436exception, or a list of two or more items, which will be stringified
2235is supplied. Note that the "input line number" (also known as "chunk")
3437and concatenated to make the exception.
2236is subject to whatever notion of "line" happens to be currently in
2237effect, and is also available as the special variable C<$.>.
2238See L<perlvar/"$/"> and L<perlvar/"$.">.
34382239
34392240=end original
34402241
3441ほとんどの場合、C<die> は例外として使うため文字列と共に呼び出さます。
2242EXPR評価結果が改行で終わっていなけば、その時点の
3442例外として圧から割れる単一の非ファレンオペランドか
2243スクプト名とクリプトの行番号(もしあれば)
3443例外を作るために文字列化され連結される、二つ以上のアイテムのリストを
2244入力ファイルの行番号と改行文字が、続け表示されます。
3444指定するこができます
2245「入力行番号」("chunk" も呼ばれます)は
2246「行」という概念が現在有効であると仮定しています。
3446=begin original
2247また特殊変数 C<$.> でも利用可能です。
3447
3448If the string exception does not end in a newline, the current
3449script line number and input line number (if any) and a newline
3450are appended to it. Note that the "input line number" (also
3451known as "chunk") is subject to whatever notion of "line" happens to
3452be currently in effect, and is also available as the special variable
3453L<C<$.>|perlvar/$.>. See L<perlvar/"$/"> and L<perlvar/"$.">.
3454
3455=end original
3456
3457文字列例外が改行で終わっていなければ、その時点のスクリプト名と
3458スクリプトの行番号、(もしあれば) 入力ファイルの行番号と改行文字が
3459それに追加されます。
3460「入力行番号」("chunk" とも呼ばれます)は「行」という概念が現在有効であると
3461仮定しています; また特殊変数 L<C<$.>|perlvar/$.> でも利用可能です。
34622248L<perlvar/"$/"> と L<perlvar/"$."> も参照してください。
34632249
34642250=begin original
34652251
3466Hint: sometimes appending C<", stopped"> to your message will cause it
2252Hint: sometimes appending C<", stopped"> to your message
3467to make better sense when the string C<"at foo line 123"> is appended.
2253will cause it to make better sense when the string C<"at foo line 123"> is
3468Suppose you are running script "canasta".
2254appended. Suppose you are running script "canasta".
34692255
34702256=end original
34712257
34722258ヒント: メッセージの最後を C<", stopped"> のようなもので
34732259終わるようにしておけば、C<"at foo line 123"> のように
34742260追加されて、わかりやすくなります。
34752261"canasta" というスクリプトを実行しているとします。
34762262
34772263 die "/etc/games is no good";
34782264 die "/etc/games is no good, stopped";
34792265
34802266=begin original
34812267
34822268produce, respectively
34832269
34842270=end original
34852271
34862272これは、それぞれ以下のように表示します。
34872273
34882274 /etc/games is no good at canasta line 123.
34892275 /etc/games is no good, stopped at canasta line 123.
34902276
34912277=begin original
34922278
3493If LIST was empty or made an empty string, and L<C<$@>|perlvar/$@>
2279See also exit(), warn(), and the Carp module.
3494already contains an exception value (typically from a previous
3495L<C<eval>|/eval EXPR>), then that value is reused after
3496appending C<"\t...propagated">. This is useful for propagating exceptions:
34972280
34982281=end original
34992282
3500出力が空か空文字列を作り、L<C<$@>|perlvar/$@>
2283exit() と warn() と Carp モジュールも参照してください。
3501(典型的には前回の L<C<eval>|/eval EXPR> で)
3502既に例外値を持っている場合、
3503値は C<"\t...propagated"> を追加した後再利用されます。
3504これは例外を伝播させる場合に有効です:
35052284
3506 eval { ... };
3507 die unless $@ =~ /Expected exception/;
3508
35092285=begin original
35102286
3511If LIST was empty or made an empty string,
2287If LIST is empty and C<$@> already contains a value (typically from a
3512and L<C<$@>|perlvar/$@> contains an object
2288previous eval) that value is reused after appending C<"\t...propagated">.
3513reference that has a C<PROPAGATE> method, that method will be called
2289This is useful for propagating exceptions:
3514with additional file and line number parameters. The return value
3515replaces the value in L<C<$@>|perlvar/$@>; i.e., as if
3516C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >> were called.
35172290
35182291=end original
35192292
3520出力が空か空文字列を作り、L<C<$@>|perlvar/$@> が C<PROPAGATE> メソッド
2293LIST が空C<$@> が(典型的には前回の eval で)既に値持っている場合、
3521含むオブジェクトへのリファレンス含む場合、
2294値は C<"\t...propagated"> 追加した後再利用されます。
3522のメソッドが追加ファイルと行番号引数として呼び出れま
2295れは例外伝播せる場合に有効で:
3523返り値は L<C<$@>|perlvar/$@> の値を置き換えます;
3524つまり、C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >> が
3525呼び出されたかのようになります。
35262296
3527=begin original
2297 eval { ... };
2298 die unless $@ =~ /Expected exception/;
35282299
3529If LIST was empty or made an empty string, and L<C<$@>|perlvar/$@>
3530is also empty, then the string C<"Died"> is used.
3531
3532=end original
3533
3534LIST が空か空文字列を作り、L<C<$@>|perlvar/$@> も空の場合、
3535C<"Died"> が使われます。
3536
35372300=begin original
35382301
3539You can also call L<C<die>|/die LIST> with a reference argument, and if
2302If C<$@> is empty then the string C<"Died"> is used.
3540this is trapped within an L<C<eval>|/eval EXPR>, L<C<$@>|perlvar/$@>
3541contains that reference. This permits more elaborate exception handling
3542using objects that maintain arbitrary state about the exception. Such a
3543scheme is sometimes preferable to matching particular string values of
3544L<C<$@>|perlvar/$@> with regular expressions.
35452303
35462304=end original
35472305
3548L<C<die>|/die LIST> はリファレンス引数と共に呼び出すこともでき、これ
2306C<$@> が空の場合、C<"Died"> が使われます。
3549L<C<eval>|/eval EXPR> 内部でトラップされた場合、L<C<$@>|perlvar/$@> は
3550そのリファレンスを持ちます。
3551これは、例外の性質について任意の状態を管理するオブジェクトを使った
3552より複雑な例外処理の実装を可能にします。
3553このようなスキームは L<C<$@>|perlvar/$@> の特定の文字列値を正規表現を使って
3554マッチングするときに時々好まれます。
35552307
35562308=begin original
35572309
3558Because Perl stringifies uncaught exception messages before display,
2310die() can also be called with a reference argument. If this happens to be
3559you'll probably want to overload stringification operations on
2311trapped within an eval(), $@ contains the reference. This behavior permits
3560exception objects. See L<overload> for details about that.
2312a more elaborate exception handling implementation using objects that
3561The stringified message should be non-empty, and should end in a newline,
2313maintain arbitrary state about the nature of the exception. Such a scheme
3562in order to fit in with the treatment of string exceptions.
2314is sometimes preferable to matching particular string values of $@ using
3563Also, because an exception object reference cannot be stringified
2315regular expressions. Here's an example:
3564without destroying it, Perl doesn't attempt to append location or other
3565information to a reference exception. If you want location information
3566with a complex exception object, you'll have to arrange to put the
3567location information into the object yourself.
35682316
35692317=end original
35702318
3571perl捕らえられなかった例外のメッセージを表示する前文字列化るの
2319die()リファレンス引数と共呼び出こともきます。
3572このようなカタム例外オブジェクトの文字列化オーバーロードしたいと
2320eval() 内部でこのように呼び出された場合、$@ はリファレンスを持ちます。
3573思うかもしれません。
2321この振る舞いは、例外の性質にすいて任意の状態を管理するオブジェクトを使った
3574これに関する詳細は L<overload> 参照てください
2322より複雑な例外ハンドリングの実装可能にます
3575文字列化されたメッセ文字列例外の扱いに合わせるために、
2323このようなスキ $@ の特定の文字列値を正規表現を使って
3576空ではなく、末尾は改行であす。
2324マッチングすに時々好まれます。以下に例を示します:
3577また、例外オブジェクトリファレンスはそれを破壊することなく
3578文字列化することができないので、Perl はリファレンス例外に位置や
3579その他の情報を追加しようとしません。
3580複雑な例外オブジェクトに位置情報が欲しい場合、
3581オブジェクト自身に位置情報を設定するように用意する必要があります。
35822325
3583=begin original
3584
3585Because L<C<$@>|perlvar/$@> is a global variable, be careful that
3586analyzing an exception caught by C<eval> doesn't replace the reference
3587in the global variable. It's
3588easiest to make a local copy of the reference before any manipulations.
3589Here's an example:
3590
3591=end original
3592
3593L<C<$@>|perlvar/$@> はグローバル変数なので、
3594C<eval> により補足された例外の解析はグローバル変数の
3595リファレンスを置き換えないことに注意を払わなければなりません。
3596他の操作をする前にリファレンスのローカルコピーを
3597作るのが一番簡単です。
3598以下に例を示します:
3599
3600 use Scalar::Util "blessed";
3601
36022326 eval { ... ; die Some::Module::Exception->new( FOO => "bar" ) };
3603 if (my $ev_err = $@) {
2327 if ($@) {
3604 if (blessed($ev_err)
2328 if (ref($@) && UNIVERSAL::isa($@,"Some::Module::Exception")) {
3605 && $ev_err->isa("Some::Module::Exception")) {
36062329 # handle Some::Module::Exception
36072330 }
36082331 else {
36092332 # handle all other possible exceptions
36102333 }
36112334 }
36122335
36132336=begin original
36142337
3615If an uncaught exception results in interpreter exit, the exit code is
2338Because perl will stringify uncaught exception messages before displaying
3616determined from the values of L<C<$!>|perlvar/$!> and
2339them, you may want to overload stringification operations on such custom
3617L<C<$?>|perlvar/$?> with this pseudocode:
2340exception objects. See L<overload> for details about that.
36182341
36192342=end original
36202343
3621例外が捉されないとインタプリタは終了し、終了コドは以下
2344perl はらえられなかった例外のメッセジを表示する前に文字列化するで、
3622擬似コードのように、L<C<$!>|perlvar/$!> と L<C<$?>|perlvar/$?> 値から
2345のようなカスタム例外オブジェクト文字列化をオーバーロードしたいと
3623決定されます:
2346思うかもしれません。
2347これに関する詳細は L<overload> を参照してください。
36242348
3625 exit $! if $!; # errno
3626 exit $? >> 8 if $? >> 8; # child exit status
3627 exit 255; # last resort
3628
36292349=begin original
36302350
3631As with L<C<exit>|/exit EXPR>, L<C<$?>|perlvar/$?> is set prior to
2351You can arrange for a callback to be run just before the C<die>
3632unwinding the call stack; any C<DESTROY> or C<END> handlers can then
2352does its deed, by setting the C<$SIG{__DIE__}> hook. The associated
3633alter this value, and thus Perl's exit code.
2353handler will be called with the error text and can change the error
2354message, if it sees fit, by calling C<die> again. See
3635=end original
2355L<perlvar/$SIG{expr}> for details on setting C<%SIG> entries, and
2356L<"eval BLOCK"> for some examples. Although this feature was meant
3637L<C<exit>|/exit EXPR> と同様に、コールスタックを巻き戻す前に
2357to be run only right before your program was to exit, this is not
3638L<C<$?>|perlvar/$?> が設定されます; C<DESTROY> C<END> のハンドラが
2358currently the case--the C<$SIG{__DIE__}> hook is currently called
3639それからこの値を変更して、これが Perl の終了コードになります。
2359even inside eval()ed blocks/strings! If one wants the hook to do
3640
3641=begin original
3642
3643The intent is to squeeze as much possible information about the likely cause
3644into the limited space of the system exit code. However, as
3645L<C<$!>|perlvar/$!> is the value of C's C<errno>, which can be set by
3646any system call, this means that the value of the exit code used by
3647L<C<die>|/die LIST> can be non-predictable, so should not be relied
3648upon, other than to be non-zero.
3649
3650=end original
3651
3652この意図は、できるだけ多くの似たような原因に関する情報を、システム終了
3653コードという限られた領域に圧縮することです。
3654しかし、L<C<$!>|perlvar/$!> はシステムコールによって設定される可能性がある C の
3655C<errno> の値であり、L<C<die>|/die LIST> によって使われる終了コードの値は
3656予測不能であることを意味するので、非 0 ということ以上にこの値に
3657依存するべきではありません。
3658
3659=begin original
3660
3661You can arrange for a callback to be run just before the
3662L<C<die>|/die LIST> does its deed, by setting the
3663L<C<$SIG{__DIE__}>|perlvar/%SIG> hook. The associated handler is called
3664with the exception as an argument, and can change the exception,
3665if it sees fit, by
3666calling L<C<die>|/die LIST> again. See L<perlvar/%SIG> for details on
3667setting L<C<%SIG>|perlvar/%SIG> entries, and L<C<eval>|/eval EXPR> for some
3668examples. Although this feature was to be run only right before your
3669program was to exit, this is not currently so: the
3670L<C<$SIG{__DIE__}>|perlvar/%SIG> hook is currently called even inside
3671L<C<eval>|/eval EXPR>ed blocks/strings! If one wants the hook to do
36722360nothing in such situations, put
36732361
36742362=end original
36752363
3676L<C<$SIG{__DIE__}>|perlvar/%SIG> フックをセットすることで、
2364C<$SIG{__DIE__}> フックをセットすることで、C<die> がその行動を行う
3677L<C<die>|/die LIST> がその行動を行う
36782365直前に実行されるコールバックを設定できます。
3679結び付けられたハンドラは例外を引数して呼び出され、
2366結び付けられたハンドラはエラーテキスト共に呼び出され、
3680必要なら再び L<C<die>|/die LIST> を呼び出すことで例外を変更できます
2367必要なら再び C<die> を呼び出すことでエラーテキストを変更できアス
3681L<C<%SIG>|perlvar/%SIG> のエントリをセットする詳細については、
2368C<%SIG> のエントリをセットする詳細については、L<perlvar/$SIG{expr}> を
3682L<perlvar/%SIG> を、例については L<C<eval>|/eval EXPR> を参照してください。
2369例については L<"eval BLOCK"> を参照してください。
3683この機能はプログラムが終了しようとする前に 1 回だけ実行していましたが、
2370この機能はプログラムが終了しようとする前に 1 回だけ実行されることを
3684現在ではそうではありません:
2371意味していましたが、現在ではそうではありません --
3685L<C<$SIG{__DIE__}>|perlvar/%SIG> フックは L<C<eval>|/eval EXPR> された
2372C<$SIG{__DIE__}> フックは eval() されたブロック/文字列の中でも
3686ブロック/文字列の中でも呼ばれるのです!
2373呼ばれるのです!
36872374もしそのような状況で何もしなくない時は:
36882375
3689 die @_ if $^S;
2376 die @_ if $^S;
36902377
36912378=begin original
36922379
36932380as the first line of the handler (see L<perlvar/$^S>). Because
36942381this promotes strange action at a distance, this counterintuitive
3695behavior may be fixed in a future release.
2382behavior may be fixed in a future release.
36962383
36972384=end original
36982385
36992386をハンドラの最初の行に置いてください(L<perlvar/$^S> を参照してください)。
37002387これは離れたところで不思議な行動を引き起こすので、
37012388この直感的でない振る舞いは将来のリリースで修正されるかもしれません。
37022389
3703=begin original
3704
3705See also L<C<exit>|/exit EXPR>, L<C<warn>|/warn LIST>, and the L<Carp>
3706module.
3707
3708=end original
3709
3710L<C<exit>|/exit EXPR> と L<C<warn>|/warn LIST> と L<Carp> モジュールも
3711参照してください。
3712
37132390=item do BLOCK
3714X<do> X<block>
37152391
3716=for Pod::Functions turn a BLOCK into a TERM
3717
37182392=begin original
37192393
37202394Not really a function. Returns the value of the last command in the
3721sequence of commands indicated by BLOCK. When modified by the C<while> or
2395sequence of commands indicated by BLOCK. When modified by a loop
3722C<until> loop modifier, executes the BLOCK once before testing the loop
2396modifier, executes the BLOCK once before testing the loop condition.
3723condition. (On other statements the loop modifiers test the conditional
2397(On other statements the loop modifiers test the conditional first.)
3724first.)
37252398
37262399=end original
37272400
37282401実際は関数ではありません。
37292402BLOCK で示されるコマンド列の最後の値を返します。
3730C<while> や C<until> ループ修飾子で修飾すると、
2403ループ修飾子で修飾すると、
37312404ループ条件を調べる前に 1 度、BLOCK を実行します。
37322405(これ以外の実行文は、ループ修飾子により、条件が最初に
37332406調べられます。)
37342407
37352408=begin original
37362409
37372410C<do BLOCK> does I<not> count as a loop, so the loop control statements
3738L<C<next>|/next LABEL>, L<C<last>|/last LABEL>, or
2411C<next>, C<last>, or C<redo> cannot be used to leave or restart the block.
3739L<C<redo>|/redo LABEL> cannot be used to leave or restart the block.
37402412See L<perlsyn> for alternative strategies.
37412413
37422414=end original
37432415
3744C<do BLOCK> はループとしては I<扱われません>; 従って、L<C<next>|/next LABEL>,
2416C<do BLOCK> はループとしては I<扱われません>
3745L<C<last>|/last LABEL>,L<C<redo>|/redo LABEL> といったループ制御文は
2417従って、C<next>, C<last>, C<redo> といったループ制御文は
37462418ブロックから抜けたり再開することはできません。
3747その他の戦略については L<perlsyn> を参照してください。
2419その他の戦略については L<perlsyn> を参照してさい。
37482420
2421=item do SUBROUTINE(LIST)
2422
2423=begin original
2424
2425A deprecated form of subroutine call. See L<perlsub>.
2426
2427=end original
2428
2429推奨されない形のサブルーチン呼び出しです。
2430L<perlsub> を参照してください。
2431
37492432=item do EXPR
3750X<do>
37512433
37522434=begin original
37532435
37542436Uses the value of EXPR as a filename and executes the contents of the
3755file as a Perl script:
2437file as a Perl script. Its primary use is to include subroutines
2438from a Perl subroutine library.
37562439
37572440=end original
37582441
37592442EXPR の値をファイル名として用い、そのファイルの中身を
3760Perl のスクリプトとして実行します:
2443Perl のスクリプトとして実行します
2444主に、Perl のサブルーチンライブラリからサブルーチンを
2445インクルードするために用います。
37612446
3762 # load the exact specified file (./ and ../ special-cased)
3763 do '/foo/stat.pl';
3764 do './stat.pl';
3765 do '../foo/stat.pl';
3766
3767 # search for the named file within @INC
37682447 do 'stat.pl';
3769 do 'foo/stat.pl';
37702448
37712449=begin original
37722450
3773C<do './stat.pl'> is largely like
2451is just like
37742452
37752453=end original
37762454
3777C<do './stat.pl'> だいたい以下のものと同じようなものですが、
2455は以下のものと同じようなものですが、
37782456
3779 eval `cat stat.pl`;
2457 scalar eval `cat stat.pl`;
37802458
37812459=begin original
37822460
3783except that it's more concise, runs no external processes, and keeps
2461except that it's more efficient and concise, keeps track of the current
3784track of the current filename for error messages. It also differs in that
2462filename for error messages, searches the @INC libraries, and updates
3785code evaluated with C<do FILE> cannot see lexicals in the enclosing
2463C<%INC> if the file is found. See L<perlvar/Predefined Names> for these
3786scope; C<eval STRING> does. It's the same, however, in that it does
2464variables. It also differs in that code evaluated with C<do FILENAME>
3787reparse the file every time you call it, so you probably don't want
2465cannot see lexicals in the enclosing scope; C<eval STRING> does. It's the
3788to do this inside a loop.
2466same, however, in that it does reparse the file every time you call it,
2467so you probably don't want to do this inside a loop.
37892468
37902469=end original
37912470
3792より簡潔で、外部プログラムを起動せず、エラーメッセージでファイル名がわかる、
2471より効率的で、簡潔であり、エラーメッセージでファイル名がわかる、
2472カレントディレクトリでファイルが見つからなかったときに
2473@INC ライブラリを検索する、ファイルがあったときに C<%INC> を更新する、
37932474といったことがあります。
3794C<do FILE> で評価れたコードは、入れ子のスコープにある
2475L<perlvar/Predefined Names> も参照してくだい。
2476C<do FILENAME> で評価されたコードは、入れ子のスコープにある
37952477レキシカル変数を見ることができないのに対し、C<eval STRING>ではできる、
37962478という違いがあります。
37972479しかし、呼び出すたびにファイルを解析し直すという点では同じですから、
37982480ループ内でこれを使おうなどとは、間違っても思ったりしないように。
37992481
38002482=begin original
38012483
3802Using C<do> with a relative path (except for F<./> and F<../>), like
2484If C<do> cannot read the file, it returns undef and sets C<$!> to the
2485error. If C<do> can read the file but cannot compile it, it
2486returns undef and sets an error message in C<$@>. If the file is
2487successfully compiled, C<do> returns the value of the last expression
2488evaluated.
38032489
38042490=end original
38052491
3806次のように、C<do> (F<./> と F<../> 以外の) 相対パスを使うと:
2492C<do>がファイルを読み込めなかった場合、undef を返して C<$!>
2493エラーを設定します。
2494C<do> がファイルを読み込めたがコンパイルできなかった場合、
2495undef を返して C<$@> にエラーメッセージを設定します。
2496ファイルのコンパイルに成功した場合、C<do> は最後に評価した表現の値を返します。
38072497
3808 do 'foo/stat.pl';
3809
38102498=begin original
38112499
3812will search the L<C<@INC>|perlvar/@INC> directories, and update
2500Note that inclusion of library modules is better done with the
3813L<C<%INC>|perlvar/%INC> if the file is found. See L<perlvar/@INC>
2501C<use> and C<require> operators, which also do automatic error checking
3814and L<perlvar/%INC> for these variables. In particular, note that
2502and raise an exception if there's a problem.
3815whilst historically L<C<@INC>|perlvar/@INC> contained '.' (the
3816current directory) making these two cases equivalent, that is no
3817longer necessarily the case, as '.' is not included in C<@INC> by default
3818in perl versions 5.26.0 onwards. Instead, perl will now warn:
38192503
38202504=end original
38212505
3822L<C<@INC>|perlvar/@INC> ディレクトリを検索し、ファイルが見つかれば
2506ライブラリモジュールのインクルードには、C<use> 演算子や
3823L<C<%INC>|perlvar/%INC> を更新ます
2507C<require> 演算子使った方がよいことに注意てください
3824これらの変数については L<perlvar/@INC> と L<perlvar/%INC> を参照してください。
3825特に、歴史的には L<C<@INC>|perlvar/@INC> に '.' (カレントディレクトリ) を
3826含んでいたのでこの二つの場合は等価でしたが、
3827perl バージョン 5.26.0 以降ではデフォルトでは C<@INC> に '.' を
3828含んでいないので、もはやそうではないことに注意してください。
3829代わりに、perl は次のような警告を出します:
3830
3831 do "stat.pl" failed, '.' is no longer in @INC;
3832 did you mean do "./stat.pl"?
3833
3834=begin original
3835
3836If L<C<do>|/do EXPR> can read the file but cannot compile it, it
3837returns L<C<undef>|/undef EXPR> and sets an error message in
3838L<C<$@>|perlvar/$@>. If L<C<do>|/do EXPR> cannot read the file, it
3839returns undef and sets L<C<$!>|perlvar/$!> to the error. Always check
3840L<C<$@>|perlvar/$@> first, as compilation could fail in a way that also
3841sets L<C<$!>|perlvar/$!>. If the file is successfully compiled,
3842L<C<do>|/do EXPR> returns the value of the last expression evaluated.
3843
3844=end original
3845
3846L<C<do>|/do EXPR> がファイルを読み込めたがコンパイルできなかった場合、
3847L<C<undef>|/undef EXPR> を返して L<C<$@>|perlvar/$@> にエラーメッセージを
3848設定します。
3849L<C<do>|/do EXPR>がファイルを読み込めなかった場合、undef を返して
3850L<C<$!>|perlvar/$!> にエラーを設定します。
3851コンパイルに失敗したときにも L<C<$!>|perlvar/$!> が設定されるので、
3852常に L<C<$@>|perlvar/$@> を先にチェックします。
3853ファイルのコンパイルに成功した場合、L<C<do>|/do EXPR> は最後に評価した表現の
3854値を返します。
3855
3856=begin original
3857
3858Inclusion of library modules is better done with the
3859L<C<use>|/use Module VERSION LIST> and L<C<require>|/require VERSION>
3860operators, which also do automatic error checking and raise an exception
3861if there's a problem.
3862
3863=end original
3864
3865ライブラリモジュールのインクルードには、
3866L<C<use>|/use Module VERSION LIST> 演算子や
3867L<C<require>|/require VERSION> 演算子を使った方がよいです;
38682508これらは自動的にエラーをチェックして、問題があれば例外を発生させます。
38692509
38702510=begin original
38712511
3872You might like to use L<C<do>|/do EXPR> to read in a program
2512You might like to use C<do> to read in a program configuration
3873configuration file. Manual error checking can be done this way:
2513file. Manual error checking can be done this way:
38742514
38752515=end original
38762516
3877L<C<do>|/do EXPR> をプログラム設定ファイルを読み込むのに
2517C<do> をプログラム設定ファイルを読み込むのに使いたいかもしれません。
3878使いたいかもしれません。
38792518手動のエラーチェックは以下のようにして行えます:
38802519
3881 # Read in config files: system first, then user.
2520 # read in config files: system first, then user
3882 # Beware of using relative pathnames here.
38832521 for $file ("/share/prog/defaults.rc",
3884 "$ENV{HOME}/.someprogrc")
2522 "$ENV{HOME}/.someprogrc")
3885 {
2523 {
3886 unless ($return = do $file) {
2524 unless ($return = do $file) {
3887 warn "couldn't parse $file: $@" if $@;
2525 warn "couldn't parse $file: $@" if $@;
3888 warn "couldn't do $file: $!" unless defined $return;
2526 warn "couldn't do $file: $!" unless defined $return;
3889 warn "couldn't run $file" unless $return;
2527 warn "couldn't run $file" unless $return;
3890 }
2528 }
38912529 }
38922530
38932531=item dump LABEL
3894X<dump> X<core> X<undump>
38952532
3896=item dump EXPR
3897
38982533=item dump
38992534
3900=for Pod::Functions create an immediate core dump
3901
39022535=begin original
39032536
39042537This function causes an immediate core dump. See also the B<-u>
39052538command-line switch in L<perlrun>, which does the same thing.
39062539Primarily this is so that you can use the B<undump> program (not
39072540supplied) to turn your core dump into an executable binary after
39082541having initialized all your variables at the beginning of the
39092542program. When the new binary is executed it will begin by executing
3910a C<goto LABEL> (with all the restrictions that L<C<goto>|/goto LABEL>
2543a C<goto LABEL> (with all the restrictions that C<goto> suffers).
3911suffers).
39122544Think of it as a goto with an intervening core dump and reincarnation.
3913If C<LABEL> is omitted, restarts the program from the top. The
2545If C<LABEL> is omitted, restarts the program from the top.
3914C<dump EXPR> form, available starting in Perl 5.18.0, allows a name to be
3915computed at run time, being otherwise identical to C<dump LABEL>.
39162546
39172547=end original
39182548
39192549この関数は即座にコアダンプを行ないます。
39202550同様のことを行う L<perlrun> の B<-u> オプションも参照してください。
39212551プログラムの先頭で、
39222552すべての変数を初期化したあとのコアダンプを B<undump>
39232553プログラム(提供していません)を使って実行ファイルに返ることができます。
39242554この新しいバイナリが実行されると、C<goto LABEL> から始めます
3925(L<C<goto>|/goto LABEL> に関する制限はすべて適用されます)。
2555(C<goto> に関する制限はすべて適用されます)。
39262556コアダンプをはさんで再生する goto と考えてください。
39272557C<LABEL> が省略されると、プログラムを先頭から再開します。
3928Perl 5.18.0 から利用可能な C<dump EXPR> 形式では、実行時に計算される
3929名前が使えます; その他は C<dump LABEL> と同一です。
39302558
39312559=begin original
39322560
39332561B<WARNING>: Any files opened at the time of the dump will I<not>
39342562be open any more when the program is reincarnated, with possible
3935resulting confusion by Perl.
2563resulting confusion on the part of Perl.
39362564
39372565=end original
39382566
3939B<警告>: dump 時点でオープンされていたファイルは、プログラムが
2567B<警告>: dump 時点でオープンされていたファイルは、
3940再生されたときには、もはやオープンされて I<いません>; Perl を
2568プログラムが再生されたときには、もはやオープンされていません
3941混乱させる可能性があります。
2569Perl を部分的に混乱させる可能性があります。
39422570
39432571=begin original
39442572
3945This function is now largely obsolete, mostly because it's very hard to
2573This function is now largely obsolete, partly because it's very
3946convert a core file into an executable. As of Perl 5.30, it must be invoked
2574hard to convert a core file into an executable, and because the
3947as C<CORE::dump()>.
2575real compiler backends for generating portable bytecode and compilable
2576C code have superseded it.
39482577
39492578=end original
39502579
3951この関数は大幅に時代遅れのものです; 主な理由としては、コアファイルを
2580この関数は大幅に時代遅れのものです; 理由としては、コアファイルを
3952実行形式に変換するのが非常に困難であることです。
2581実行形式に変換するのが非常に困難であること、また移植性のある
3953Perl 5.30 から、これは C<CORE::dump()> として起動しなけばなりません。
2582バイトコードとコンパイル可能な C コードが生成さ
2583実際のコンパイラバックエンドがこれを置き換えたことがあります。
39542584
39552585=begin original
39562586
3957Unlike most named operators, this has the same precedence as assignment.
2587If you're looking to use L<dump> to speed up your program, consider
3958It is also exempt from the looks-like-a-function rule, so
2588generating bytecode or native C code as described in L<perlcc>. If
3959C<dump ("foo")."bar"> will cause "bar" to be part of the argument to
2589you're just trying to accelerate a CGI script, consider using the
3960L<C<dump>|/dump LABEL>.
2590C<mod_perl> extension to B<Apache>, or the CPAN module, Fast::CGI.
2591You might also consider autoloading or selfloading, which at least
2592make your program I<appear> to run faster.
39612593
39622594=end original
39632595
3964ほとんど名前付き演算子と異なり、れは代入同じ優先順位持ちます。
2596プログラム速度を上げるために L<dump> を使うことを考えているなら、
3965また、関数のように見えるものの規則からも免れるので、C<dump ("foo")."bar">
2597L<perlcc> で記述されているような、バイトコードかネイティブな C コードを
3966すると "bar" は L<C<dump>|/dump LABEL> への引数の一部になります
2598生成するを検討してみてください
2599もし単に CGI スクリプトを高速化したいなら、B<Apache> の拡張である
2600C<mod_perl> や、CPAN モジュールである Fast::CGI を検討してみてください。
2601少なくともプログラムが速く動作する I<ようにみえる>、オートロードや
2602自力ロードも検討してみてください。
39672603
3968=begin original
3969
3970Portability issues: L<perlport/dump>.
3971
3972=end original
3973
3974移植性の問題: L<perlport/dump>。
3975
39762604=item each HASH
3977X<each> X<hash, iterator>
39782605
3979=item each ARRAY
3980X<array, iterator>
3981
3982=for Pod::Functions retrieve the next key/value pair from a hash
3983
39842606=begin original
39852607
3986When called on a hash in list context, returns a 2-element list
2608When called in list context, returns a 2-element list consisting of the
3987consisting of the key and value for the next element of a hash. In Perl
2609key and value for the next element of a hash, so that you can iterate over
39885.12 and later only, it will also return the index and value for the next
2610it. When called in scalar context, returns only the key for the next
3989element of an array so that you can iterate over it; older Perls consider
2611element in the hash.
3990this a syntax error. When called in scalar context, returns only the key
3991(not the value) in a hash, or the index in an array.
39922612
39932613=end original
39942614
3995ハッシュに対してリストコンテキストで呼び出した場合は、次の要素に対する
2615リストコンテキストで呼び出した場合は、
3996ハッシュのキーと値を返しま
2616ハッシュの次の 要素 に対る、key と 要素 からなる
3997Perl 5.12 以降でみ、配列インデクスと値からなる
26172 要素リストを返しますで、ハシュ上での繰り返しを
39982 要素のリストを返すので、反復をます; より古い Perl ではこれは
2618なうことができます
3999文法エラーと考えられます。
40002619スカラコンテキストで呼び出した場合は、
4001ハッシュの場合は(値ではなく)キー、配列場合はインデックスを返します。
2620ハッシュの要素のための key を返します。
40022621
40032622=begin original
40042623
4005Hash entries are returned in an apparently random order. The actual random
2624Entries are returned in an apparently random order. The actual random
4006order is specific to a given hash; the exact same series of operations
2625order is subject to change in future versions of perl, but it is guaranteed
4007on two hashes may result in a different order for each hash. Any insertion
2626to be in the same order as either the C<keys> or C<values> function
4008into the hash may change the order, as will any deletion, with the exception
2627would produce on the same (unmodified) hash.
4009that the most recent key returned by L<C<each>|/each HASH> or
4010L<C<keys>|/keys HASH> may be deleted without changing the order. So
4011long as a given hash is unmodified you may rely on
4012L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and
4013L<C<each>|/each HASH> to repeatedly return the same order
4014as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
4015details on why hash order is randomized. Aside from the guarantees
4016provided here the exact details of Perl's hash algorithm and the hash
4017traversal order are subject to change in any release of Perl.
40182628
40192629=end original
40202630
4021ハッシュ要素は見かけ上、ランダムな順序で返されます。
2631エントリは見かけ上、ランダムな順序で返されます。
4022実際のランダムな順ハッシュに固有です; 二つハッシュに全く同じ一連
2632実際のランダムな順perl 将来バージョンでは変わるかもしれませんが、
4023操作を行っも、ハッシュによっ異なった順序になります。
2633C<keys> や C<values> 関数が同じ(変更されいない)ハッシュに対し
4024ハッシュへ挿入によって序が変わることがあります; 削除も同様ですが、
2634生成すると同じ番であることは保証されます
4025L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも
4026最近のキーは順序を変えることなく削除できます。
4027ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>,
4028L<C<each>|/each HASH> が繰り返し同じ順序で
4029返すことに依存してもかまいません。
4030なぜハッシュの順序がランダム化されているかの詳細については
4031L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。
4032ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の
4033正確な詳細は Perl のリリースによって変更される可能性があります。
40342635
40352636=begin original
40362637
4037After L<C<each>|/each HASH> has returned all entries from the hash or
2638When the hash is entirely read, a null array is returned in list context
4038array, the next call to L<C<each>|/each HASH> returns the empty list in
2639(which when assigned produces a false (C<0>) value), and C<undef> in
4039list context and L<C<undef>|/undef EXPR> in scalar context; the next
2640scalar context. The next call to C<each> after that will start iterating
4040call following I<that> one restarts iteration. Each hash or array has
2641again. There is a single iterator for each hash, shared by all C<each>,
4041its own internal iterator, accessed by L<C<each>|/each HASH>,
2642C<keys>, and C<values> function calls in the program; it can be reset by
4042L<C<keys>|/keys HASH>, and L<C<values>|/values HASH>. The iterator is
2643reading all the elements from the hash, or by evaluating C<keys HASH> or
4043implicitly reset when L<C<each>|/each HASH> has reached the end as just
2644C<values HASH>. If you add or delete elements of a hash while you're
4044described; it can be explicitly reset by calling L<C<keys>|/keys HASH>
2645iterating over it, you may get entries skipped or duplicated, so
4045or L<C<values>|/values HASH> on the hash or array, or by referencing
2646don't. Exception: It is always safe to delete the item most recently
4046the hash (but not array) in list context. If you add or delete
2647returned by C<each()>, which means that the following code will work:
4047a hash's elements while iterating over it, the effect on the iterator is
4048unspecified; for example, entries may be skipped or duplicated--so don't
4049do that. Exception: It is always safe to delete the item most recently
4050returned by L<C<each>|/each HASH>, so the following code works properly:
40512648
40522649=end original
40532650
4054L<C<each>|/each HASH> がハッシュをすべて読み込んでしまった後
2651ハッシュをすべて読み込んでしまうとリストコンテキストでは空配列が
4055次の L<C<each>|/each HASH> 呼び出しでは、リストコンテキストでは空リストが
2652返されます(これは代入されると、偽 (C<0>) となります)。
4056返され、スカラコンテキストでは L<C<undef>|/undef EXPR> が返されます;
2653スカラコンテキストでは C<undef> が返されます
4057I<そのあと> もう一度呼び出すと、再び反復を始めます。
2654そのあともう一度 C<each> を呼び出すと、
4058ハッシュや配列毎にそれぞれ反復子があ、L<C<each>|/each HASH>、
2655再び繰返しを始めます。
4059L<C<keys>|/keys HASH>、L<C<values>|/values HASH> でアクセスされま
2656ハッシュごとに反復子が 1 つあり、プログラム中のべての
4060反復子は、前述したように L<C<each>|/each HASH> が要素をべて読むことによって
2657C<each> 関数、C<keys> 関数、C<values> 関数で共用されま
4061暗黙にリセットされます; またハッシュや配列に対し L<C<keys>|/keys HASH>,
2658反復子は、配列の要素をすべて読むことよっ、またはC<keys HASH>,
4062L<C<values>|/values HASH> 呼び出か、コンテキスト
2659C<values HASH>を評価ることでセッすることがきます。
4063(配列ではなく)ハッシュを参照ことで明示的にリセットできます。
40642660繰り返しを行なっている間に、ハッシュに要素を追加したり削除したりすると、
4065反復子の動作は未定義です; 例えば、要素が飛ばされたり重複したりします--
2661要素が飛ばされたり重複したりするので、てはいけせん。
4066従って、していけません
2662例外: 一番最近に C<each()> から返されたものを削除するの常に安全です
4067例外: 一番最近に L<C<each>|/each HASH> から返さたものを削除るのは常に
2663は以下ようなコードが正しく動くこと意味しま:
4068安全です; これは以下のようなコードが正しく動くことを意味します:
40692664
4070 while (my ($key, $value) = each %hash) {
2665 while (($key, $value) = each %hash) {
4071 print $key, "\n";
2666 print $key, "\n";
4072 delete $hash{$key}; # This is safe
2667 delete $hash{$key}; # This is safe
4073 }
2668 }
40742669
40752670=begin original
40762671
4077Tied hashes may have a different ordering behaviour to perl's hash
2672The following prints out your environment like the printenv(1) program,
4078implementation.
2673only in a different order:
40792674
40802675=end original
40812676
4082tie されたハッシュは、順序に関して Perl のハッシュと異なった振舞いをします。
2677以下のプログラムは、順番が異なるものの、
2678printenv(1) プログラムのように環境変数を表示します:
40832679
4084=begin original
2680 while (($key,$value) = each %ENV) {
2681 print "$key=$value\n";
4086The iterator used by C<each> is attached to the hash or array, and is
4087shared between all iteration operations applied to the same hash or array.
4088Thus all uses of C<each> on a single hash or array advance the same
4089iterator location. All uses of C<each> are also subject to having the
4090iterator reset by any use of C<keys> or C<values> on the same hash or
4091array, or by the hash (but not array) being referenced in list context.
4092This makes C<each>-based loops quite fragile: it is easy to arrive at
4093such a loop with the iterator already part way through the object, or to
4094accidentally clobber the iterator state during execution of the loop body.
4095It's easy enough to explicitly reset the iterator before starting a loop,
4096but there is no way to insulate the iterator state used by a loop from
4097the iterator state used by anything else that might execute during the
4098loop body. To avoid these problems, use a C<foreach> loop rather than
4099C<while>-C<each>.
4100
4101=end original
4102
4103C<each> で使われる反復子はハッシュや配列に付随し、
4104同じハッシュや配列に適用される全ての反復操作の間で共有されます。
4105従って、一つのハッシュや配列での C<each> の全ての使用は同じ反復位置を
4106進めます。
4107また、全ての C<each> は、同じハッシュまたはキーに対する
4108C<keys> や C<values> の使用によって、または
4109(リストではなく)ハッシュがリストコンテキストで参照されることによって、
4110反復子がリセットされることになります。
4111これは、C<each> を基にしたループをかなり不安定にします:
4112そのようなループが既にオブジェクトを部分的に通りぬけた反復子で行われたり、
4113ループ本体の実行中に誤って反復子の状態を壊すことは容易です。
4114ループを始める前に反復子を明示的にリセットするのは十分容易ですが、
4115ループ本体の間に実行しているかもしれない他の何かによって使われている
4116反復子の状態から、
4117ループによって使われている反復子の状態を分離する方法はありません。
4118これらの問題を避けるには、C<while>-C<each> ではなく
4119C<foreach> ループを使ってください。
4120
4121=begin original
4122
4123This prints out your environment like the L<printenv(1)> program,
4124but in a different order:
4125
4126=end original
4127
4128これは、L<printenv(1)> プログラムのように環境変数を表示しますが、
4129順序は異なっています:
4130
4131 while (my ($key,$value) = each %ENV) {
4132 print "$key=$value\n";
41332682 }
41342683
41352684=begin original
41362685
4137Starting with Perl 5.14, an experimental feature allowed
2686See also C<keys>, C<values> and C<sort>.
4138L<C<each>|/each HASH> to take a scalar expression. This experiment has
4139been deemed unsuccessful, and was removed as of Perl 5.24.
41402687
41412688=end original
41422689
4143Perl 5.14 から、L<C<each>|/each HASH> がスカラ式を取ることが出来ると
2690C<keys> C<values> や C<sort> も参照してくださ
4144実験的機能がありました。
4145この実験は失敗と見なされ、Perl 5.24 で削除されました。
41462691
4147=begin original
4148
4149As of Perl 5.18 you can use a bare L<C<each>|/each HASH> in a C<while>
4150loop, which will set L<C<$_>|perlvar/$_> on every iteration.
4151If either an C<each> expression or an explicit assignment of an C<each>
4152expression to a scalar is used as a C<while>/C<for> condition, then
4153the condition actually tests for definedness of the expression's value,
4154not for its regular truth value.
4155
4156=end original
4157
4158Perl 5.18 から C<while> ループの中に裸の L<C<each>|/each HASH> を書けます;
4159これは繰り返し毎に L<C<$_>|perlvar/$_> を設定します。
4160C<each> 式または C<each> 式からスカラへの明示的な代入が
4161C<while>/C<for> の条件部として使われた場合、
4162条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを
4163テストします。
4164
4165 while (each %ENV) {
4166 print "$_=$ENV{$_}\n";
4167 }
4168
4169=begin original
4170
4171To avoid confusing would-be users of your code who are running earlier
4172versions of Perl with mysterious syntax errors, put this sort of thing at
4173the top of your file to signal that your code will work I<only> on Perls of
4174a recent vintage:
4175
4176=end original
4177
4178あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
4179文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
4180I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
4181書いてください:
4182
4183 use 5.012; # so keys/values/each work on arrays
4184 use 5.018; # so each assigns to $_ in a lone while test
4185
4186=begin original
4187
4188See also L<C<keys>|/keys HASH>, L<C<values>|/values HASH>, and
4189L<C<sort>|/sort SUBNAME LIST>.
4190
4191=end original
4192
4193L<C<keys>|/keys HASH> や L<C<values>|/values HASH> や
4194L<C<sort>|/sort SUBNAME LIST> も参照してください。
4195
41962692=item eof FILEHANDLE
4197X<eof>
4198X<end of file>
4199X<end-of-file>
42002693
42012694=item eof ()
42022695
42032696=item eof
42042697
4205=for Pod::Functions test a filehandle for its end
4206
42072698=begin original
42082699
4209Returns 1 if the next read on FILEHANDLE will return end of file I<or> if
2700Returns 1 if the next read on FILEHANDLE will return end of file, or if
42102701FILEHANDLE is not open. FILEHANDLE may be an expression whose value
42112702gives the real filehandle. (Note that this function actually
4212reads a character and then C<ungetc>s it, so isn't useful in an
2703reads a character and then C<ungetc>s it, so isn't very useful in an
42132704interactive context.) Do not read from a terminal file (or call
42142705C<eof(FILEHANDLE)> on it) after end-of-file is reached. File types such
42152706as terminals may lose the end-of-file condition if you do.
42162707
42172708=end original
42182709
4219次に FILEHANDLE 上で読み込みを行なったときに、EOF が返されるときか、
2710次に FILEHANDLE 上で読み込みを行なったときに、 EOF が返されるときか、
4220I<または> FILEHANDLE がオープンされていないと、1 を返します。
2711FILEHANDLE がオープンされていないと、1 を返します。
42212712FILEHANDLE は、値が実際のファイルハンドルを示す式であってもかまいません。
42222713(この関数は、実際に文字を読み、C<ungetc> を行ないますので、
4223対話型の場合には有用ではありません。)
2714対話型の場合には、それ程有用ではありません。)
42242715端末ファイルは EOF に達した後にさらに読み込んだり C<eof(FILEHANDLE)> を
42252716呼び出したりしてはいけません。
42262717そのようなことをすると、端末のようなファイルタイプは
42272718EOF 状態を失ってしまうかもしれません。
42282719
42292720=begin original
42302721
4231An L<C<eof>|/eof FILEHANDLE> without an argument uses the last file
2722An C<eof> without an argument uses the last file read. Using C<eof()>
4232read. Using L<C<eof()>|/eof FILEHANDLE> with empty parentheses is
2723with empty parentheses is very different. It refers to the pseudo file
4233different. It refers to the pseudo file formed from the files listed on
2724formed from the files listed on the command line and accessed via the
4234the command line and accessed via the C<< <> >> operator. Since
2725C<< <> >> operator. Since C<< <> >> isn't explicitly opened,
4235C<< <> >> isn't explicitly opened, as a normal filehandle is, an
2726as a normal filehandle is, an C<eof()> before C<< <> >> has been
4236L<C<eof()>|/eof FILEHANDLE> before C<< <> >> has been used will cause
2727used will cause C<@ARGV> to be examined to determine if input is
4237L<C<@ARGV>|perlvar/@ARGV> to be examined to determine if input is
2728available.
4238available. Similarly, an L<C<eof()>|/eof FILEHANDLE> after C<< <> >>
4239has returned end-of-file will assume you are processing another
4240L<C<@ARGV>|perlvar/@ARGV> list, and if you haven't set
4241L<C<@ARGV>|perlvar/@ARGV>, will read input from C<STDIN>; see
4242L<perlop/"I/O Operators">.
42432729
42442730=end original
42452731
4246引数を省略した L<C<eof>|/eof FILEHANDLE> は、最後に読み込みを行なった
2732引数を省略した C<eof> は、最後に読み込みを行なったファイルを使います。
4247ファイル使います。
2733空の括弧つけた C<eof()> は大きく異なります。
4248空の括弧をつけた L<C<eof()>|/eof FILEHANDLE> は異なります。
42492734これはコマンドラインのファイルリストで構成され、C<< <> >> 演算子経由で
42502735アクセスされる擬似ファイルを示すために用いられます。
42512736通常のファイルハンドルと違って C<< <> >> は明示的にオープンされないので、
4252C<< <> >> を使う前に L<C<eof()>|/eof FILEHANDLE> を使うと、
2737C<< <> >> を使う前に C<eof()> を使うと、
4253入力が正常か確認するために L<C<@ARGV>|perlvar/@ARGV> がテストされます。
2738入力が正常か確認するために C<@ARGV> がテストされます。
4254同様に、C<< <> >> が EOF を返した後の L<C<eof()>|/eof FILEHANDLE> は、
4255他の L<C<@ARGV>|perlvar/@ARGV> リストを処理していると仮定し、もし
4256L<C<@ARGV>|perlvar/@ARGV> をセットしていないときは C<STDIN> から読み込みます;
4257L<perlop/"I/O Operators"> を参照してください。
42582739
42592740=begin original
42602741
4261In a C<< while (<>) >> loop, L<C<eof>|/eof FILEHANDLE> or C<eof(ARGV)>
2742In a C<< while (<>) >> loop, C<eof> or C<eof(ARGV)> can be used to
4262can be used to detect the end of each file, whereas
2743detect the end of each file, C<eof()> will only detect the end of the
4263L<C<eof()>|/eof FILEHANDLE> will detect the end of the very last file
2744last file. Examples:
4264only. Examples:
42652745
42662746=end original
42672747
42682748C<< while (<>) >> ループの中では、個々のファイルの終わりを調べるには、
4269L<C<eof>|/eof FILEHANDLE> か C<eof(ARGV)> を用いるのに対して
2749C<eof> か C<eof(ARGV)> を用います。
4270L<C<eof()>|/eof FILEHANDLE> は最後のファイルの終わりのみを調べます。
2750C<eof()> は最後のファイルの終わりのみを調べます。
42712751例:
42722752
42732753 # reset line numbering on each input file
42742754 while (<>) {
4275 next if /^\s*#/; # skip comments
2755 next if /^\s*#/; # skip comments
4276 print "$.\t$_";
2756 print "$.\t$_";
42772757 } continue {
4278 close ARGV if eof; # Not eof()!
2758 close ARGV if eof; # Not eof()!
42792759 }
42802760
42812761 # insert dashes just before last line of last file
42822762 while (<>) {
4283 if (eof()) { # check for end of last file
2763 if (eof()) { # check for end of current file
4284 print "--------------\n";
2764 print "--------------\n";
4285 }
2765 close(ARGV); # close or last; is needed if we
4286 print;
2766 # are reading from the terminal
4287 last if eof(); # needed if we're reading from a terminal
2767 }
2768 print;
42882769 }
42892770
42902771=begin original
42912772
4292Practical hint: you almost never need to use L<C<eof>|/eof FILEHANDLE>
2773Practical hint: you almost never need to use C<eof> in Perl, because the
4293in Perl, because the input operators typically return L<C<undef>|/undef
2774input operators typically return C<undef> when they run out of data, or if
4294EXPR> when they run out of data or encounter an error.
2775there was an error.
42952776
42962777=end original
42972778
4298現実的なヒント: Perl で L<C<eof>|/eof FILEHANDLE> が必要となることは、
2779現実的なヒント: Perl で C<eof> が必要となることは、ほとんどありません。
4299ほとんどありません;
2780基本的には、
4300基本的には、データがなくなったときやエラーがあったときに、入力演算子が
2781データがなくなったときやエラーがあったときに、入力演算子が
4301L<C<undef>|/undef EXPR> を返してくれるからです。
2782C<undef> を返してくれるからです。
43022783
43032784=item eval EXPR
4304X<eval> X<try> X<catch> X<evaluate> X<parse> X<execute>
4305X<error, handling> X<exception, handling>
43062785
43072786=item eval BLOCK
43082787
4309=item eval
4310
4311=for Pod::Functions catch exceptions or compile and run code
4312
43132788=begin original
43142789
4315C<eval> in all its forms is used to execute a little Perl program,
2790In the first form, the return value of EXPR is parsed and executed as if it
4316trapping any errors encountered so they don't crash the calling program.
2791were a little Perl program. The value of the expression (which is itself
2792determined within scalar context) is first parsed, and if there weren't any
2793errors, executed in the lexical context of the current Perl program, so
2794that any variable settings or subroutine and format definitions remain
2795afterwards. Note that the value is parsed every time the eval executes.
2796If EXPR is omitted, evaluates C<$_>. This form is typically used to
2797delay parsing and subsequent execution of the text of EXPR until run time.
43172798
43182799=end original
43192800
4320の C<eval> も小さな Perl のプログラムであるかのように実行され、
2801第一ではEXPR の返り値が Perl のプログラムであるかのように
4321遭遇した全てのエラーをトラップするので呼び出したプログラムが
2802解析され実行されます。
4322ッシュすことありせん。
2803式の値(それ自身スカコンテキストの中で決定され)はまずパースされ、
2804エラーがなければ
2805Perl プログラムのレキシカルコンテキストの中で実行されますので、変数の設定、
2806サブルーチンやフォーマットの定義は、その後も残っています。 
2807返される値は eval が実行されるごとにパースされます。
2808サブルーチン同様に、最後に評価した式の値か、return 文の値です。
2809EXPR を省略すると、C<$_> を評価します。
2810この形は主に EXPR のテキストのパースと実行を実行時にまで
2811遅延させるのに用います。
43232812
43242813=begin original
43252814
4326Plain C<eval> with no argument is just C<eval EXPR>, where the
2815In the second form, the code within the BLOCK is parsed only once--at the
4327expression is understood to be contained in L<C<$_>|perlvar/$_>. Thus
2816same time the code surrounding the eval itself was parsed--and executed
4328there are only two real C<eval> forms; the one with an EXPR is often
2817within the context of the current Perl program. This form is typically
4329called "string eval". In a string eval, the value of the expression
2818used to trap exceptions more efficiently than the first (see below), while
4330(which is itself determined within scalar context) is first parsed, and
2819also providing the benefit of checking the code within BLOCK at compile
4331if there were no errors, executed as a block within the lexical context
2820time.
4332of the current Perl program. This form is typically used to delay
4333parsing and subsequent execution of the text of EXPR until run time.
4334Note that the value is parsed every time the C<eval> executes.
43352821
43362822=end original
43372823
4338引数なし C<eval> は単に C<eval EXPR> で、式は L<C<$_>|perlvar/$_>
2824第二、BLOCK 内部のコードは一度だけパースされ--コードを
4339含まていのとして考えられま
2825囲む eval 自身がパースされるのと同じ時点で--現在の Perl プログラムの
4340従って際には二つだけの C<eval> 形式があります:
2826コンテキストで行されます
4341EXPR ものはしばしば「文字列 eval」(string eval) と呼ばれます。
2827形式典型的には第一の形式より効率的に例外をトラップします(後述)
4342「文字列 eval」で
2828また BLOCK 内部のコードコンパイル時にチェックされるという利点を提供します。
4343式の値(それ自身スカラコンテキストの中で決定されます)はまずパースされ、
4344エラーがなければ Perl プログラムのレキシカルコンテキストの中のブロックとして
4345実行されます。
4346この形は主に EXPR のテキストのパースと実行を実行時にまで
4347遅延させるのに用います。
4348返される値は C<eval> が実行されるごとにパースされることに注意してください。
43492829
43502830=begin original
43512831
4352The other form is called "block eval". It is less general than string
2832The final semicolon, if any, may be omitted from the value of EXPR or within
4353eval, but the code within the BLOCK is parsed only once (at the same
2833the BLOCK.
4354time the code surrounding the C<eval> itself was parsed) and executed
4355within the context of the current Perl program. This form is typically
4356used to trap exceptions more efficiently than the first, while also
4357providing the benefit of checking the code within BLOCK at compile time.
4358BLOCK is parsed and compiled just once. Since errors are trapped, it
4359often is used to check if a given feature is available.
43602834
43612835=end original
43622836
4363もう一つ型式は「ブック eval」呼ばれます。
2837最後セミコンは、もしあれば、EXPR の値や BLOCK の中身から省くこができます。
4364これは文字列 eval ほど一般的ではありませんが、
4365BLOCK 内部のコードは一度だけパースされ (コードを
4366囲む C<eval> 自身がパースされるのと同じ時点です) 現在の
4367Perl プログラムのコンテキストで実行されます。
4368この形式は典型的には第一の形式より効率的に例外をトラップします;
4369また BLOCK 内部のコードはコンパイル時にチェックされるという利点を提供します。
4370BLOCK は一度だけパース及びコンパイルされます。
4371エラーはトラップされてるので、しばしば与えられた機能が利用可能かを
4372チェックするために使われます。
43732838
43742839=begin original
43752840
43762841In both forms, the value returned is the value of the last expression
4377evaluated inside the mini-program; a return statement may also be used, just
2842evaluated inside the mini-program; a return statement may be also used, just
43782843as with subroutines. The expression providing the return value is evaluated
4379in void, scalar, or list context, depending on the context of the
2844in void, scalar, or list context, depending on the context of the eval itself.
4380C<eval> itself. See L<C<wantarray>|/wantarray> for more
2845See L</wantarray> for more on how the evaluation context can be determined.
4381on how the evaluation context can be determined.
43822846
43832847=end original
43842848
43852849どちらの形式でも、返される値はミニプログラムの内部で最後に評価された
4386表現の値です; サブルーチンと同様、return も使えます。
2850表現の値です; サブルーチンと同様、return ステートメントも使えます。
4387返り値として提供される表現は、C<eval> 自身のコンテキストに
2851返り値として提供される表現は、eval 自身のコンテキストに依存して
4388依存して無効・スカラ・リストのいずれかのコンテキストで評価されます。
2852無効・スカラ・リストのいずれかのコンテキストで評価されます。
4389評価コンテキストの決定方法についての詳細は L<C<wantarray>|/wantarray> を
2853評価コンテキストの決定方法についての詳細は L</wantarray> を参照してください。
4390参照してください。
43912854
43922855=begin original
43932856
4394If there is a syntax error or runtime error, or a L<C<die>|/die LIST>
2857If there is a syntax error or runtime error, or a C<die> statement is
4395statement is executed, C<eval> returns
2858executed, an undefined value is returned by C<eval>, and C<$@> is set to the
4396L<C<undef>|/undef EXPR> in scalar context, or an empty list in list
2859error message. If there was no error, C<$@> is guaranteed to be a null
4397context, and L<C<$@>|perlvar/$@> is set to the error message. (Prior to
2860string. Beware that using C<eval> neither silences perl from printing
43985.16, a bug caused L<C<undef>|/undef EXPR> to be returned in list
2861warnings to STDERR, nor does it stuff the text of warning messages into C<$@>.
4399context for syntax errors, but not for runtime errors.) If there was no
2862To do either of those, you have to use the C<$SIG{__WARN__}> facility. See
4400error, L<C<$@>|perlvar/$@> is set to the empty string. A control flow
2863L</warn> and L<perlvar>.
4401operator like L<C<last>|/last LABEL> or L<C<goto>|/goto LABEL> can
4402bypass the setting of L<C<$@>|perlvar/$@>. Beware that using
4403C<eval> neither silences Perl from printing warnings to
4404STDERR, nor does it stuff the text of warning messages into
4405L<C<$@>|perlvar/$@>. To do either of those, you have to use the
4406L<C<$SIG{__WARN__}>|perlvar/%SIG> facility, or turn off warnings inside
4407the BLOCK or EXPR using S<C<no warnings 'all'>>. See
4408L<C<warn>|/warn LIST>, L<perlvar>, and L<warnings>.
44092864
44102865=end original
44112866
4412構文エラーや実行エラーが発生するか、L<C<die>|/die LIST> 文が実行されると、
2867構文エラーや実行エラーが発生するか、C<die> 文が実行されると、
4413C<eval> はスカラコンテキストでは L<C<undef>|/undef EXPR>
2868C<eval> の値として未定義値が返され、C<$@> にエラーメッセージ設定されます。
4414リストコンテキストでは空リスト設定され
2869エラーがなければ、C<$@> 文字列であること保証されます。 
4415L<C<$@>|perlvar/$@> にエラーメッセージが設定されます。
4416(5.16 以前では、バグによって、リストコンテキストで構文エラーの時には
4417L<C<undef>|/undef EXPR> を返していましたが、実行エラーの時には
4418返していませんでした。)
4419エラーがなければ、L<C<$@>|perlvar/$@> は空文字列に設定されます。
4420L<C<last>|/last LABEL> や L<C<goto>|/goto LABEL> のようなフロー制御演算子は
4421L<C<$@>|perlvar/$@> の設定を回避できます。
44222870C<eval> を、STDERR に警告メッセージを表示させない目的や、
4423警告メッセージを L<C<$@>|perlvar/$@> に格納する目的では使わないでください。
2871警告メッセージを C<$@> に格納する目的では使わないでください。
4424そのような用途では、L<C<$SIG{__WARN__}>|perlvar/%SIG> 機能を使うか、
2872そのような用途では、C<$SIG{__WARN__}> 機能を使わなければなりません。
4425S<C<no warnings 'all'>> を使って BLOCK か EXPR の内部での警告
2873L</warn> L<perlvar>参照してください。
4426オフにする必要があります。
4427L<C<warn>|/warn LIST>, L<perlvar>, L<warnings> を参照してください。
44282874
44292875=begin original
44302876
4431Note that, because C<eval> traps otherwise-fatal errors,
2877Note that, because C<eval> traps otherwise-fatal errors, it is useful for
4432it is useful for determining whether a particular feature (such as
2878determining whether a particular feature (such as C<socket> or C<symlink>)
4433L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL> or
2879is implemented. It is also Perl's exception trapping mechanism, where
4434L<C<symlink>|/symlink OLDFILE,NEWFILE>) is implemented. It is also
2880the die operator is used to raise exceptions.
4435Perl's exception-trapping mechanism, where the L<C<die>|/die LIST>
4436operator is used to raise exceptions.
44372881
44382882=end original
44392883
4440C<eval> は、致命的エラーとなるようなものを
2884C<eval> は、致命的エラーとなるようなものをトラップすることができますから、
4441トラップすることができので
2885(C<socket> や C<symlink> いった) 特定の機能実装されていかを
4442(L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL> や
4443L<C<symlink>|/symlink OLDFILE,NEWFILE> といった) 特定の機能が
4444実装されているかを、
44452886調べるために使うことができることに注意してください。
4446L<C<die>|/die LIST> 演算子が例外を発生させるものとすれば、これはまた
2887die 演算子が例外を発生させるものとすれば、
4447Perl の例外捕捉機能と捉えることもできます。
2888これはまた、Perl の例外捕捉機能と捉えることもできます。
44482889
44492890=begin original
44502891
4451Before Perl 5.14, the assignment to L<C<$@>|perlvar/$@> occurred before
4452restoration
4453of localized variables, which means that for your code to run on older
4454versions, a temporary is required if you want to mask some, but not all
4455errors:
4456
4457=end original
4458
4459Perl 5.14 より前では、L<C<$@>|perlvar/$@> への代入はローカル化された変数の
4460復帰の前に起きるので、古いバージョンで実行される場合は、全てではなく一部だけの
4461エラーをマスクしたい場合には一時変数が必要です:
4462
4463 # alter $@ on nefarious repugnancy only
4464 {
4465 my $e;
4466 {
4467 local $@; # protect existing $@
4468 eval { test_repugnancy() };
4469 # $@ =~ /nefarious/ and die $@; # Perl 5.14 and higher only
4470 $@ =~ /nefarious/ and $e = $@;
4471 }
4472 die $e if defined $e
4473 }
4474
4475=begin original
4476
4477There are some different considerations for each form:
4478
4479=end original
4480
4481それぞれの型式について、異なった考慮事項があります:
4482
4483=over 4
4484
4485=item String eval
4486
4487(文字列 eval)
4488
4489=begin original
4490
4491Since the return value of EXPR is executed as a block within the lexical
4492context of the current Perl program, any outer lexical variables are
4493visible to it, and any package variable settings or subroutine and
4494format definitions remain afterwards.
4495
4496=end original
4497
4498EXPR の返り値は現在の Perl プログラムのレキシカルコンテキストの中で
4499実行されるので、外側のレキシカルスコープはそこから見え、
4500パッケージ変数設定やサブルーチンとフォーマット設定は後に残ります。
4501
4502=over 4
4503
4504=item Under the L<C<"unicode_eval"> feature|feature/The 'unicode_eval' and 'evalbytes' features>
4505
4506=begin original
4507
4508If this feature is enabled (which is the default under a C<use 5.16> or
4509higher declaration), EXPR is considered to be
4510in the same encoding as the surrounding program. Thus if
4511S<L<C<use utf8>|utf8>> is in effect, the string will be treated as being
4512UTF-8 encoded. Otherwise, the string is considered to be a sequence of
4513independent bytes. Bytes that correspond to ASCII-range code points
4514will have their normal meanings for operators in the string. The
4515treatment of the other bytes depends on if the
4516L<C<'unicode_strings"> feature|feature/The 'unicode_strings' feature> is
4517in effect.
4518
4519=end original
4520
4521この機能が有効の場合(これは C<use 5.16> またはそれ以上が
4522宣言されている場合はデフォルトです)、
4523EXPR は周りのプログラムと同じエンコーディングであるとして扱われます。
4524従って、S<L<C<use utf8>|utf8>> が有効の場合、
4525文字列は UTF-8 エンコードされているものとして扱われます。
4526さもなければ、この文字列は個々のバイト列として扱われます。
4527ASCII の範囲の符号位置に対応するバイトは、
4528文字列の操作に関して通常の意味を持ちます。
4529その他のバイトの扱いは、
4530<C<'unicode_strings"> feature|feature/'unicode_strings' 機能> が有効の場合か
4531どうかに依存します。
4532
4533=begin original
4534
4535In a plain C<eval> without an EXPR argument, being in S<C<use utf8>> or
4536not is irrelevant; the UTF-8ness of C<$_> itself determines the
4537behavior.
4538
4539=end original
4540
4541EXPR 引数のない単なる C<eval> の場合、S<C<use utf8>> の有無は無関係です;
4542C<$_> 自身の UTF-8 性が振る舞いを決定します。
4543
4544=begin original
4545
4546Any S<C<use utf8>> or S<C<no utf8>> declarations within the string have
4547no effect, and source filters are forbidden. (C<unicode_strings>,
4548however, can appear within the string.) See also the
4549L<C<evalbytes>|/evalbytes EXPR> operator, which works properly with
4550source filters.
4551
4552=end original
4553
4554文字列中の S<C<use utf8>> や S<C<no utf8>> 宣言は無効で、ソースフィルタは
4555禁止されます。
4556(しかし、C<unicode_strings> は文字列の中に現れます。)
4557ソースフィルタが適切に動作する
4558L<C<evalbytes>|/evalbytes EXPR> 演算子も参照してください。
4559
4560=begin original
4561
4562Variables defined outside the C<eval> and used inside it retain their
4563original UTF-8ness. Everything inside the string follows the normal
4564rules for a Perl program with the given state of S<C<use utf8>>.
4565
4566=end original
4567
4568Variables defined outside the
4569C<eval> の外側で定義され、内側で使われた変数は、
4570元の UTF-8 性を維持します。
4571内側の文字列は、S<C<use utf8>> の状態によって Perl プログラムに適用される
4572通常の規則に従います。
4573
4574=item Outside the C<"unicode_eval"> feature
4575
4576=begin original
4577
4578In this case, the behavior is problematic and is not so easily
4579described. Here are two bugs that cannot easily be fixed without
4580breaking existing programs:
4581
4582=end original
4583
4584この場合、振る舞いには問題があり、それほど簡単には説明できません。
4585既存のプログラムを壊さずに簡単に修正することが出来ない二つのバグがあります:
4586
4587=over 4
4588
4589=item *
4590
4591=begin original
4592
4593It can lose track of whether something should be encoded as UTF-8 or
4594not.
4595
4596=end original
4597
4598あるものが UTF-8 でエンコードされているかどうかを見失うことがあります。
4599
4600=item *
4601
4602=begin original
4603
4604Source filters activated within C<eval> leak out into whichever file
4605scope is currently being compiled. To give an example with the CPAN module
4606L<Semi::Semicolons>:
4607
4608=end original
4609
4610C<eval> の中で有効にされたソースフィルタは、現在どちらのファイルスコープで
4611コンパイルされているかをリークさせます。
4612CPAN モジュール L<Semi::Semicolons> を使った例は:
4613
4614 BEGIN { eval "use Semi::Semicolons; # not filtered" }
4615 # filtered here!
4616
4617=begin original
4618
4619L<C<evalbytes>|/evalbytes EXPR> fixes that to work the way one would
4620expect:
4621
4622=end original
4623
4624L<C<evalbytes>|/evalbytes EXPR> は、人が想定するだろう手法で動作するように
4625これを修正します:
4626
4627 use feature "evalbytes";
4628 BEGIN { evalbytes "use Semi::Semicolons; # filtered" }
4629 # not filtered
4630
4631=back
4632
4633=back
4634
4635=begin original
4636
4637Problems can arise if the string expands a scalar containing a floating
4638point number. That scalar can expand to letters, such as C<"NaN"> or
4639C<"Infinity">; or, within the scope of a L<C<use locale>|locale>, the
4640decimal point character may be something other than a dot (such as a
4641comma). None of these are likely to parse as you are likely expecting.
4642
4643=end original
4644
4645文字列をが小数点を含むスカラを展開するときに問題が起こることがあります。
4646そのようなスカラは C<"NaN"> や C<"Infinity"> のような文字に
4647展開されることがあります; または、L<C<use locale>|locale> のスコープの中では、
4648小数点文字は (カンマのような) ドット以外の文字かもしれません。
4649これらはどれもあなたがおそらく予測しているようにはパースされません。
4650
4651=begin original
4652
4653You should be especially careful to remember what's being looked at
4654when:
4655
4656=end original
4657
4658以下のような場合に、何が調べられるかに特に注意しておくことが必要です:
4659
4660 eval $x; # CASE 1
4661 eval "$x"; # CASE 2
4662
4663 eval '$x'; # CASE 3
4664 eval { $x }; # CASE 4
4665
4666 eval "\$$x++"; # CASE 5
4667 $$x++; # CASE 6
4668
4669=begin original
4670
4671Cases 1 and 2 above behave identically: they run the code contained in
4672the variable $x. (Although case 2 has misleading double quotes making
4673the reader wonder what else might be happening (nothing is).) Cases 3
4674and 4 likewise behave in the same way: they run the code C<'$x'>, which
4675does nothing but return the value of $x. (Case 4 is preferred for
4676purely visual reasons, but it also has the advantage of compiling at
4677compile-time instead of at run-time.) Case 5 is a place where
4678normally you I<would> like to use double quotes, except that in this
4679particular situation, you can just use symbolic references instead, as
4680in case 6.
4681
4682=end original
4683
4684上記の CASE 1 と CASE 2 の動作は同一で、変数 $x 内の
4685コードを実行します。
4686(ただし、CASE 2 では、必要のないダブルクォートによって、
4687読む人が何が起こるか混乱することでしょう (何も起こりませんが)。)
4688同様に CASE 3 と CASE 4 の動作も等しく、$x の値を返す以外に
4689何もしない C<$x> というコードを実行します
4690(純粋に見た目の問題で、CASE 4 が好まれますが、
4691実行時でなくコンパイル時にコンパイルされるという利点もあります)。
4692CASE 5 の場合は、通常ダブルクォートを使用 I<します>;
4693この状況を除けば、CASE 6 のように、単に
4694シンボリックリファレンスを使えば良いでしょう。
4695
4696=begin original
4697
4698An C<eval ''> executed within a subroutine defined
4699in the C<DB> package doesn't see the usual
4700surrounding lexical scope, but rather the scope of the first non-DB piece
4701of code that called it. You don't normally need to worry about this unless
4702you are writing a Perl debugger.
4703
4704=end original
4705
4706C<DB> パッケージで定義されたサブルーチン内で C<eval ''> を実行すると、通常の
4707レキシカルスコープではなく、これを呼び出した最初の非 DB コード片の
4708スコープになります。
4709Perl デバッガを書いているのでない限り、普通はこれについて心配する必要は
4710ありません。
4711
4712=begin original
4713
4714The final semicolon, if any, may be omitted from the value of EXPR.
4715
4716=end original
4717
4718最後のセミコロンは、もしあれば、EXPR の値から省くことができます。
4719
4720=item Block eval
4721
4722=begin original
4723
47242892If the code to be executed doesn't vary, you may use the eval-BLOCK
47252893form to trap run-time errors without incurring the penalty of
4726recompiling each time. The error, if any, is still returned in
2894recompiling each time. The error, if any, is still returned in C<$@>.
4727L<C<$@>|perlvar/$@>.
47282895Examples:
47292896
47302897=end original
47312898
47322899実行するコードが変わらないのであれば、毎回多量の再コンパイルすることなしに、
47332900実行時エラーのトラップを行なうために、
47342901eval-BLOCK 形式を使うことができます。
4735エラーがあれば、やはり L<C<$@>|perlvar/$@> に返されます。
2902エラーがあれば、やはり $@ に返されます。
47362903例:
47372904
47382905 # make divide-by-zero nonfatal
47392906 eval { $answer = $a / $b; }; warn $@ if $@;
47402907
47412908 # same thing, but less efficient
47422909 eval '$answer = $a / $b'; warn $@ if $@;
47432910
47442911 # a compile-time error
4745 eval { $answer = }; # WRONG
2912 eval { $answer = }; # WRONG
47462913
47472914 # a run-time error
4748 eval '$answer ='; # sets $@
2915 eval '$answer ='; # sets $@
47492916
47502917=begin original
47512918
4752If you want to trap errors when loading an XS module, some problems with
2919Due to the current arguably broken state of C<__DIE__> hooks, when using
4753the binary interface (such as Perl version skew) may be fatal even with
2920the C<eval{}> form as an exception trap in libraries, you may wish not
4754C<eval> unless C<$ENV{PERL_DL_NONLAZY}> is set. See
2921to trigger any C<__DIE__> hooks that user code may have installed.
4755L<perlrun>.
4756
4757=end original
4758
4759XS モジュールのロード中のエラーをトラップしたいなら、
4760(Perl バージョンの違いのような) バイナリインターフェースに関する問題に
4761ついては C<$ENV{PERL_DL_NONLAZY}> がセットされていない
4762C<eval> でも致命的エラーになるかもしれません。
4763L<perlrun> を参照してください。
4764
4765=begin original
4766
4767Using the C<eval {}> form as an exception trap in libraries does have some
4768issues. Due to the current arguably broken state of C<__DIE__> hooks, you
4769may wish not to trigger any C<__DIE__> hooks that user code may have installed.
47702922You can use the C<local $SIG{__DIE__}> construct for this purpose,
4771as this example shows:
2923as shown in this example:
47722924
47732925=end original
47742926
4775C<eval{}> 形式をライブラリの例外を捕捉するために使うときには
2927C<eval{}> 形式をライブラリの例外を補足するために使うとき
4776問題があります。
47772928現在の C<__DIE__> フックの状態はほぼ確実に壊れているという理由で、
47782929ユーザーのコードが設定した C<__DIE__> フックを実行したくないかもしれません。
47792930この目的には以下の例のように、C<local $SIG{__DIE__}> 構造が使えます。
47802931
4781 # a private exception trap for divide-by-zero
2932 # a very private exception trap for divide-by-zero
47822933 eval { local $SIG{'__DIE__'}; $answer = $a / $b; };
47832934 warn $@ if $@;
47842935
47852936=begin original
47862937
47872938This is especially significant, given that C<__DIE__> hooks can call
4788L<C<die>|/die LIST> again, which has the effect of changing their error
2939C<die> again, which has the effect of changing their error messages:
4789messages:
47902940
47912941=end original
47922942
4793これは特に顕著です; 与えられた C<__DIE__> フックは L<C<die>|/die LIST>
2943これは特に顕著です与えられた C<__DIE__> フックは C<die> をもう一度
4794もう一度呼び出すことができ、これによってエラーメッセージを変える
2944呼び出すことができ、これによってエラーメッセージを変える効果があります:
4795効果があります:
47962945
47972946 # __DIE__ hooks may modify error messages
47982947 {
47992948 local $SIG{'__DIE__'} =
48002949 sub { (my $x = $_[0]) =~ s/foo/bar/g; die $x };
48012950 eval { die "foo lives here" };
48022951 print $@ if $@; # prints "bar lives here"
48032952 }
48042953
48052954=begin original
48062955
48072956Because this promotes action at a distance, this counterintuitive behavior
48082957may be fixed in a future release.
48092958
48102959=end original
48112960
48122961これは距離の離れた行動であるため、この直感的でない振る舞いは
48132962将来のリリースでは修正されるかもしれません。
48142963
48152964=begin original
48162965
4817C<eval BLOCK> does I<not> count as a loop, so the loop control statements
2966With an C<eval>, you should be especially careful to remember what's
4818L<C<next>|/next LABEL>, L<C<last>|/last LABEL>, or
2967being looked at when:
4819L<C<redo>|/redo LABEL> cannot be used to leave or restart the block.
48202968
48212969=end original
48222970
4823C<eval BLOCK> はループとして I<扱われません>; 従ってL<C<next>|/next LABEL>,
2971C<eval> は、以下のような場合に、
4824L<C<last>|/last LABEL>, L<C<redo>|/redo LABEL> いったループ制御文
2972何が調べられるかに特に注意しておくこが必要す:
4825ブロックから離れたり再実行したりはできません。
48262973
4827=begin original
2974 eval $x; # CASE 1
2975 eval "$x"; # CASE 2
48282976
4829The final semicolon, if any, may be omitted from within the BLOCK.
2977 eval '$x'; # CASE 3
2978 eval { $x }; # CASE 4
48302979
4831=end original
2980 eval "\$$x++"; # CASE 5
2981 $$x++; # CASE 6
48322982
4833最後のセミコロンは、もしあれば、BLOCK の中から削除されます。
4834
4835=back
4836
4837=item evalbytes EXPR
4838X<evalbytes>
4839
4840=item evalbytes
4841
4842=for Pod::Functions +evalbytes similar to string eval, but intend to parse a bytestream
4843
48442983=begin original
48452984
4846This function is similar to a L<string eval|/eval EXPR>, except it
2985Cases 1 and 2 above behave identically: they run the code contained in
4847always parses its argument (or L<C<$_>|perlvar/$_> if EXPR is omitted)
2986the variable $x. (Although case 2 has misleading double quotes making
4848as a string of independent bytes.
2987the reader wonder what else might be happening (nothing is).) Cases 3
2988and 4 likewise behave in the same way: they run the code C<'$x'>, which
2989does nothing but return the value of $x. (Case 4 is preferred for
2990purely visual reasons, but it also has the advantage of compiling at
2991compile-time instead of at run-time.) Case 5 is a place where
2992normally you I<would> like to use double quotes, except that in this
2993particular situation, you can just use symbolic references instead, as
2994in case 6.
48492995
48502996=end original
48512997
4852関数は L<文字列 eval|/eval EXPR> に似ていますが(EXPR
2998上記CASE 1 と CASE 2 の動作は同一で$x 内の
4853省略された場合はL<C<$_>|perlvar/$_>) 常にバイト単位のの文字列と
2999コード実行ます。
4854ます。
3000(ただし、CASE 2 では、必要のなダブルクォートによって、
3001読む人が何が起こるか混乱することでしょう (何も起こりませんが)。)
3002同様に CASE 3 と CASE 4 の動作も等しく、$x の値を返す以外に
3003何もしない C<$x> というコードを実行します
3004(純粋に見た目の問題で、CASE 4 が好まれますが、
3005実行時でなくコンパイル時にコンパイルされるという利点もあります)。
3006CASE 5 の場合は、通常ダブルクォートを使用します。
3007この状況を除けば、CASE 6 のように、単に
3008シンボリックリファレンスを使えば良いでしょう。
48553009
48563010=begin original
48573011
4858If called when S<C<use utf8>> is in effect, the string will be assumed
3012C<eval BLOCK> does I<not> count as a loop, so the loop control statements
4859to be encoded in UTF-8, and C<evalbytes> will make a temporary copy to
3013C<next>, C<last>, or C<redo> cannot be used to leave or restart the block.
4860work from, downgraded to non-UTF-8. If this is not possible
4861(because one or more characters in it require UTF-8), the C<evalbytes>
4862will fail with the error stored in C<$@>.
48633014
48643015=end original
48653016
4866S<C<use utf8>> が有効のきに呼び出さると、
3017C<eval BLOCK> はループして I<扱わません>。
4867文字列は UTF-8 でエンコドさていると仮定され、
3018従って、C<next>, C<last>, C<redo> といったルプ制御文でブロックから離たり
4868C<evalbytes> は、非 UTF-8 にダウングレードした一時的なコピーを作りま
3019再実行したりはできせん
4869(UTF-8 が必要な文字があるために) これが不可能な場合、
4870C<evalbytes> は失敗し、エラーは C<$@> に保管されます。
48713020
4872=begin original
4873
4874Bytes that correspond to ASCII-range code points will have their normal
4875meanings for operators in the string. The treatment of the other bytes
4876depends on if the L<C<'unicode_strings"> feature|feature/The
4877'unicode_strings' feature> is in effect.
4878
4879=end original
4880
4881ASCII の範囲の符号位置に対応するバイトは、
4882文字列の操作に関して通常の意味を持ちます。
4883その他のバイトの扱いは、
4884<C<'unicode_strings"> feature|feature/'unicode_strings' 機能> が有効の場合か
4885どうかに依存します。
4886
4887=begin original
4888
4889Of course, variables that are UTF-8 and are referred to in the string
4890retain that:
4891
4892=end original
4893
4894もちろん、UTF-8 で文字列の中で参照されている変数はそのままです:
4895
4896 my $a = "\x{100}";
4897 evalbytes 'print ord $a, "\n"';
4898
4899=begin original
4900
4901prints
4902
4903=end original
4904
4905というのは、次を表示し、
4906
4907 256
4908
4909=begin original
4910
4911and C<$@> is empty.
4912
4913=end original
4914
4915C<$@> は空になります。
4916
4917=begin original
4918
4919Source filters activated within the evaluated code apply to the code
4920itself.
4921
4922=end original
4923
4924eval されたコード内で有効になったソースフィルタはコード自体に適用されます。
4925
4926=begin original
4927
4928L<C<evalbytes>|/evalbytes EXPR> is available starting in Perl v5.16. To
4929access it, you must say C<CORE::evalbytes>, but you can omit the
4930C<CORE::> if the
4931L<C<"evalbytes"> feature|feature/The 'unicode_eval' and 'evalbytes' features>
4932is enabled. This is enabled automatically with a C<use v5.16> (or
4933higher) declaration in the current scope.
4934
4935=end original
4936
4937L<C<evalbytes>|/evalbytes EXPR> は Perl v5.16 から利用可能です。
4938これにアクセスするには C<CORE::evalbytes> とする必要がありますが、
4939L<C<"evalbytes"> 機能|feature/The 'unicode_eval' and 'evalbytes' features> が
4940有効なら C<CORE::> を省略できます。
4941これは現在のスコープで C<use v5.16> (またはそれ以上) 宣言があると
4942自動的に有効になります。
4943
49443021=item exec LIST
4945X<exec> X<execute>
49463022
49473023=item exec PROGRAM LIST
49483024
4949=for Pod::Functions abandon this program to run another
4950
49513025=begin original
49523026
4953The L<C<exec>|/exec LIST> function executes a system command I<and never
3027The C<exec> function executes a system command I<and never returns>--
4954returns>; use L<C<system>|/system LIST> instead of L<C<exec>|/exec LIST>
3028use C<system> instead of C<exec> if you want it to return. It fails and
4955if you want it to return. It fails and
49563029returns false only if the command does not exist I<and> it is executed
49573030directly instead of via your system's command shell (see below).
49583031
49593032=end original
49603033
4961L<C<exec>|/exec LIST> 関数は、システムのコマンドを実行し、I<戻ってはきません>;
3034C<exec> 関数は、システムのコマンドを実行し、I<戻ってはきません>
4962戻って欲しい場合には、L<C<exec>|/exec LIST>ではなく
3035戻って欲しい場合には、C<exec>ではなく C<system> 関数を使ってください。
4963L<C<system>|/system LIST> 関数を使ってください。
49643036コマンドが存在せず、I<しかも> システムのコマンドシェル経由でなく
49653037直接コマンドを実行しようとした場合にのみこの関数は失敗して偽を返します。
49663038
49673039=begin original
49683040
4969Since it's a common mistake to use L<C<exec>|/exec LIST> instead of
3041Since it's a common mistake to use C<exec> instead of C<system>, Perl
4970L<C<system>|/system LIST>, Perl warns you if L<C<exec>|/exec LIST> is
3042warns you if there is a following statement which isn't C<die>, C<warn>,
4971called in void context and if there is a following statement that isn't
3043or C<exit> (if C<-w> is set - but you always do that). If you
4972L<C<die>|/die LIST>, L<C<warn>|/warn LIST>, or L<C<exit>|/exit EXPR> (if
3044I<really> want to follow an C<exec> with some other statement, you
4973L<warnings> are enabled--but you always do that, right?). If you
3045can use one of these styles to avoid the warning:
4974I<really> want to follow an L<C<exec>|/exec LIST> with some other
4975statement, you can use one of these styles to avoid the warning:
49763046
49773047=end original
49783048
4979L<C<system>|/system LIST> の代わりに L<C<exec>|/exec LIST> を使うという
3049C<system> の代わりに C<exec> を使うというよくある間違いを防ぐために、
4980ある間違いを防ぐために、L<C<exec>|/exec LIST> が無効コンテキス
3050引き続文が C<die>, C<warn>, C<exit>(C<-w>セッされている場合 -
4981呼び出され、引き続く文が L<C<die>|/die LIST>, L<C<warn>|/warn LIST>,
3051でもいつもセットしますよね) 以外の場合、Perl は警告を出します。
4982L<C<exit>|/exit EXPR> 以外の場合、Perl は警告を出します(L<warnings> が
3052もし I<本当に> C<exec> の後に他の文を書きたい場合、
4983有効場合 -- もいつもセットしてますよね?)。
3053以下どちらかのスタイルを使うこと警告を回避できます:
4984もし I<本当に> L<C<exec>|/exec LIST> の後に他の文を書きたい場合、以下の
4985どちらかのスタイルを使うことで警告を回避できます:
49863054
49873055 exec ('foo') or print STDERR "couldn't exec foo: $!";
49883056 { exec ('foo') }; print STDERR "couldn't exec foo: $!";
49893057
49903058=begin original
49913059
4992If there is more than one argument in LIST, this calls L<execvp(3)> with the
3060If there is more than one argument in LIST, or if LIST is an array
4993arguments in LIST. If there is only one element in LIST, the argument is
3061with more than one value, calls execvp(3) with the arguments in LIST.
4994checked for shell metacharacters, and if there are any, the entire
3062If there is only one scalar argument or an array with one element in it,
4995argument is passed to the system's command shell for parsing (this is
3063the argument is checked for shell metacharacters, and if there are any,
4996C</bin/sh -c> on Unix platforms, but varies on other platforms). If
3064the entire argument is passed to the system's command shell for parsing
4997there are no shell metacharacters in the argument, it is split into words
3065(this is C</bin/sh -c> on Unix platforms, but varies on other platforms).
4998and passed directly to C<execvp>, which is more efficient. Examples:
3066If there are no shell metacharacters in the argument, it is split into
3067words and passed directly to C<execvp>, which is more efficient.
3068Examples:
49993069
50003070=end original
50013071
5002LIST に複数の引数がある場合、LIST の引数を使って L<execvp(3)> を
3072LIST に複数の引数がある場合、LIST が複の値持つ
5003呼び出します。
3073配列の場合には、LIST の引数を使って、execvp(3) を呼び出します。
5004LIST 要素がつのの場合には、その引数からシェルのメタ文字をチェックし、
30741 つのスカラ引数のみまたは要素が 1 つの配列の場合には、その引数から
5005もしメタ文字があれば、引数全体をシステムのコマンドシェル(これはUnix では
3075シェルのメタ文字をチェックし、もしメタ文字があれば、
3076引数全体をシステムのコマンドシェル(これはUnix では
50063077C</bin/sh -c> ですが、システムによって異なります)に渡して解析させます。
5007シェルのメタ文字がなかった場合、引数単語に分解されて直接 C<execvp> に
3078もし、メタキャラクタがなければその引数単語に分け、
5008渡されます; この方がより効率的す。
3079より効率的な C<execvp> に直接渡します。
50093080例:
50103081
50113082 exec '/bin/echo', 'Your arguments are: ', @ARGV;
50123083 exec "sort $outfile | uniq";
50133084
50143085=begin original
50153086
50163087If you don't really want to execute the first argument, but want to lie
50173088to the program you are executing about its own name, you can specify
50183089the program you actually want to run as an "indirect object" (without a
5019comma) in front of the LIST, as in C<exec PROGRAM LIST>. (This always
3090comma) in front of the LIST. (This always forces interpretation of the
5020forces interpretation of the LIST as a multivalued list, even if there
3091LIST as a multivalued list, even if there is only a single scalar in
5021is only a single scalar in the list.) Example:
3092the list.) Example:
50223093
50233094=end original
50243095
5025第一引数に指定するものを本当に実行したいが、実行するプログラムに対して別の
3096第一引数に指定するものを本当に実行したいが、実行する
5026名前を教えたい場合には、C<exec PROGRAM LIST> ように、LIST の前に
3097プログラムに対して別の名前を教えたい場合には、LISTの前に
5027「間接オブジェクト」(コンマなし) として実際に実行したいプログラムを
3098「間接オブジェクト」(コンマなし) として実際に
5028指定することができます。
3099実行したいプログラムを指定することができます。
5029(これによって、LIST に単一のスカラしかなくても、複数値のリストであるように、
3100(これによって、LIST に単一のスカラしかなくても、複数
5030LIST の解釈を行ないます。)
3101値のリストであるように、LIST の解釈を行ないます。)
50313102例:
50323103
5033 my $shell = '/bin/csh';
3104 $shell = '/bin/csh';
5034 exec $shell '-sh'; # pretend it's a login shell
3105 exec $shell '-sh'; # pretend it's a login shell
50353106
50363107=begin original
50373108
50383109or, more directly,
50393110
50403111=end original
50413112
50423113あるいは、より直接的に、
50433114
5044 exec {'/bin/csh'} '-sh'; # pretend it's a login shell
3115 exec {'/bin/csh'} '-sh'; # pretend it's a login shell
50453116
50463117=begin original
50473118
5048When the arguments get executed via the system shell, results are
3119When the arguments get executed via the system shell, results will
5049subject to its quirks and capabilities. See L<perlop/"`STRING`">
3120be subject to its quirks and capabilities. See L<perlop/"`STRING`">
50503121for details.
50513122
50523123=end original
50533124
50543125引数がシステムシェルで実行されるとき、結果はシェルの奇癖と能力によって
50553126変わります。
50563127詳細については L<perlop/"`STRING`"> を参照してください。
50573128
50583129=begin original
50593130
5060Using an indirect object with L<C<exec>|/exec LIST> or
3131Using an indirect object with C<exec> or C<system> is also more
5061L<C<system>|/system LIST> is also more secure. This usage (which also
3132secure. This usage (which also works fine with system()) forces
5062works fine with L<C<system>|/system LIST>) forces
50633133interpretation of the arguments as a multivalued list, even if the
50643134list had just one argument. That way you're safe from the shell
50653135expanding wildcards or splitting up words with whitespace in them.
50663136
50673137=end original
50683138
5069L<C<exec>|/exec LIST> L<C<system>|/system LIST> で間接オブジェクトを
3139C<exec> や C<system> で間接オブジェクトを使うのもより安全です。
5070使うもより安全です
3140使い方(system() も同様にうまく動きま)は、たとえ引数が一つだけの
5071この使い方(L<C<system>|/system LIST> で同様にうまく動きます)は
3141場合も、複数の値を持つリストして引数を解釈することを強制します。
5072引数が一つだけの場合も、複数の値を持つリストとして引数を解釈することを
5073強制します。
50743142この方法で、シェルによるワイルドカード展開や、空白による単語の分割から
50753143守られます。
50763144
5077 my @args = ( "echo surprise" );
3145 @args = ( "echo surprise" );
50783146
50793147 exec @args; # subject to shell escapes
50803148 # if @args == 1
50813149 exec { $args[0] } @args; # safe even with one-arg list
50823150
50833151=begin original
50843152
50853153The first version, the one without the indirect object, ran the I<echo>
5086program, passing it C<"surprise"> an argument. The second version didn't;
3154program, passing it C<"surprise"> an argument. The second version
5087it tried to run a program named I<"echo surprise">, didn't find it, and set
3155didn't--it tried to run a program literally called I<"echo surprise">,
5088L<C<$?>|perlvar/$?> to a non-zero value indicating failure.
3156didn't find it, and set C<$?> to a non-zero value indicating failure.
50893157
50903158=end original
50913159
50923160間接オブジェクトなしの一つ目のバージョンでは、I<echo> プログラムが実行され、
50933161C<"surprise"> が引数として渡されます。
5094二つ目のバージョンでは違います; I<"echo surprise"> という名前の
3162二つ目のバージョンでは違います -- 文字通り I<"echo surprise"> という名前の
50953163プログラムを実行しようとして、見つからないので、失敗したことを示すために
5096L<C<$?>|perlvar/$?> に非 0 がセットされます。
3164C<$?> に非 0 がセットされます。
50973165
50983166=begin original
50993167
5100On Windows, only the C<exec PROGRAM LIST> indirect object syntax will
3168Beginning with v5.6.0, Perl will attempt to flush all files opened for
5101reliably avoid using the shell; C<exec LIST>, even with more than one
3169output before the exec, but this may not be supported on some platforms
5102element, will fall back to the shell if the first spawn fails.
3170(see L<perlport>). To be safe, you may need to set C<$|> ($AUTOFLUSH
3171in English) or call the C<autoflush()> method of C<IO::Handle> on any
3172open handles in order to avoid lost output.
51033173
51043174=end original
51053175
5106Windows では、C<exec PROGRAM LIST> 間接オブジェクト構文のみが、シェルを
5107使うのを回避するための信頼できる方法です; C<exec LIST> は、複数の要素が
5108あっても、最初の spawn が失敗したときにシェルに
5109フォールバックすることがあります。
5110
5111=begin original
5112
5113Perl attempts to flush all files opened for output before the exec,
5114but this may not be supported on some platforms (see L<perlport>).
5115To be safe, you may need to set L<C<$E<verbar>>|perlvar/$E<verbar>>
5116(C<$AUTOFLUSH> in L<English>) or call the C<autoflush> method of
5117L<C<IO::Handle>|IO::Handle/METHODS> on any open handles to avoid lost
5118output.
5119
5120=end original
5121
51223176v5.6.0 から、Perl は exec の前に出力用に開かれている全てのファイルを
51233177フラッシュしようとしますが、これに対応していないプラットフォームもあります
51243178(L<perlport> を参照してください)。
51253179安全のためには、出力が重複するのを避けるために、全てのオープンしている
5126ハンドルに対して L<C<$E<verbar>>|perlvar/$E<verbar>>
3180ハンドルに対して C<$|> (English モジュールでは $AUTOFLUSH) を設定するか、
5127(L<English> モジュールでは C<$AUTOFLUSH>) を設定するか、
3181C<IO::Handle> モジュール C<autoflush()> メソッドを呼ぶ必要が
5128L<C<IO::Handle>|IO::Handle/METHODS> モジュールの C<autoflush> メソッドを
3182あるかもしれません。
5129呼ぶ必要があるかもしれません。
51303183
51313184=begin original
51323185
5133Note that L<C<exec>|/exec LIST> will not call your C<END> blocks, nor
3186Note that C<exec> will not call your C<END> blocks, nor will it call
5134will it invoke C<DESTROY> methods on your objects.
3187any C<DESTROY> methods in your objects.
51353188
51363189=end original
51373190
5138L<C<exec>|/exec LIST> は C<END> ブロックや、オブジェクトの
3191C<exec> は C<END> ブロックや、オブジェクトの C<DESTROY> メソッドを
5139C<DESTROY> メソッドを起動しないことに注意してください。
3192呼び出さないことに注意してください。
51403193
5141=begin original
5142
5143Portability issues: L<perlport/exec>.
5144
5145=end original
5146
5147移植性の問題: L<perlport/exec>。
5148
51493194=item exists EXPR
5150X<exists> X<autovivification>
51513195
5152=for Pod::Functions test whether a hash key is present
5153
51543196=begin original
51553197
5156Given an expression that specifies an element of a hash, returns true if the
3198Given an expression that specifies a hash element or array element,
5157specified element in the hash has ever been initialized, even if the
3199returns true if the specified element in the hash or array has ever
5158corresponding value is undefined.
3200been initialized, even if the corresponding value is undefined. The
3201element is not autovivified if it doesn't exist.
51593202
51603203=end original
51613204
5162ハッシュ要素を示す表現が与えられ、指定された要素が、ハッシュに存在すれば
3205ハッシュ要素か配列要素を示す表現が与えられ、
5163とえ対応する値未定義でも真を返しま
3206指定され要素、ハッシュか配列に存在れば、
3207たとえ対応する value が未定義でも真を返します。
3208要素が存在しなかった場合は自動活性化されません。
51643209
5165 print "Exists\n" if exists $hash{$key};
3210 print "Exists\n" if exists $hash{$key};
5166 print "Defined\n" if defined $hash{$key};
3211 print "Defined\n" if defined $hash{$key};
51673212 print "True\n" if $hash{$key};
51683213
5169=begin original
3214 print "Exists\n" if exists $array[$index];
3215 print "Defined\n" if defined $array[$index];
5171exists may also be called on array elements, but its behavior is much less
5172obvious and is strongly tied to the use of L<C<delete>|/delete EXPR> on
5173arrays.
5174
5175=end original
5176
5177exists は配列の要素に対しても呼び出せますが、その振る舞いははるかに
5178不明確で、配列に対する L<C<delete>|/delete EXPR> の使用と強く
5179結びついています。
5180
5181=begin original
5182
5183B<WARNING:> Calling L<C<exists>|/exists EXPR> on array values is
5184strongly discouraged. The
5185notion of deleting or checking the existence of Perl array elements is not
5186conceptually coherent, and can lead to surprising behavior.
5187
5188=end original
5189
5190B<警告:> 配列の値に対して L<C<exists>|/exists EXPR> を呼び出すことは強く
5191非推奨です。
5192Perl の配列要素を削除したり存在を調べたりする記法は概念的に一貫しておらず、
5193驚くべき振る舞いを引き起こすことがあります。
5194
5195 print "Exists\n" if exists $array[$index];
5196 print "Defined\n" if defined $array[$index];
51973216 print "True\n" if $array[$index];
51983217
51993218=begin original
52003219
5201A hash or array element can be true only if it's defined and defined only if
3220A hash or array element can be true only if it's defined, and defined if
52023221it exists, but the reverse doesn't necessarily hold true.
52033222
52043223=end original
52053224
52063225ハッシュまたは配列要素は、定義されているときにのみ真となり、
52073226存在しているときにのみ定義されますが、逆は必ずしも真ではありません。
52083227
52093228=begin original
52103229
52113230Given an expression that specifies the name of a subroutine,
52123231returns true if the specified subroutine has ever been declared, even
52133232if it is undefined. Mentioning a subroutine name for exists or defined
5214does not count as declaring it. Note that a subroutine that does not
3233does not count as declaring it. Note that a subroutine which does not
52153234exist may still be callable: its package may have an C<AUTOLOAD>
52163235method that makes it spring into existence the first time that it is
5217called; see L<perlsub>.
3236called -- see L<perlsub>.
52183237
52193238=end original
52203239
52213240引数としてサブルーチンの名前が指定された場合、
52223241指定されたサブルーチンが宣言されていれば(たとえ未定義でも)
52233242真を返します。
52243243exists や defined のために言及されているサブルーチン名は
52253244宣言としてのカウントに入りません。
52263245存在しないサブルーチンでも呼び出し可能かもしれないことに注意してください:
52273246パッケージが C<AUTOLOAD> メソッドを持っていて、最初に呼び出された時に
5228存在を作り出すかもしれません; L<perlsub> を参照してください。
3247存在を作り出すかもしれません -- L<perlsub> を参照してください。
52293248
5230 print "Exists\n" if exists &subroutine;
3249 print "Exists\n" if exists &subroutine;
5231 print "Defined\n" if defined &subroutine;
3250 print "Defined\n" if defined &subroutine;
52323251
52333252=begin original
52343253
52353254Note that the EXPR can be arbitrarily complicated as long as the final
52363255operation is a hash or array key lookup or subroutine name:
52373256
52383257=end original
52393258
5240最終的な操作がハッシュや配列の key による検索または
3259最終的な操作がハッシュや配列の key による検索またはサブルーチン名である限りは、
5241サブルーチン名である限りは、EXPR には任意の複雑な式を置くことができます:
3260EXPR には任意の複雑な式を置くことができます:
52423261
5243 if (exists $ref->{A}->{B}->{$key}) { }
3262 if (exists $ref->{A}->{B}->{$key}) { }
5244 if (exists $hash{A}{B}{$key}) { }
3263 if (exists $hash{A}{B}{$key}) { }
52453264
5246 if (exists $ref->{A}->{B}->[$ix]) { }
3265 if (exists $ref->{A}->{B}->[$ix]) { }
5247 if (exists $hash{A}{B}[$ix]) { }
3266 if (exists $hash{A}{B}[$ix]) { }
52483267
52493268 if (exists &{$ref->{A}{B}{$key}}) { }
52503269
52513270=begin original
52523271
5253Although the most deeply nested array or hash element will not spring into
3272Although the deepest nested array or hash will not spring into existence
5254existence just because its existence was tested, any intervening ones will.
3273just because its existence was tested, any intervening ones will.
52553274Thus C<< $ref->{"A"} >> and C<< $ref->{"A"}->{"B"} >> will spring
5256into existence due to the existence test for the C<$key> element above.
3275into existence due to the existence test for the $key element above.
5257This happens anywhere the arrow operator is used, including even here:
3276This happens anywhere the arrow operator is used, including even:
52583277
52593278=end original
52603279
5261最も深くネストした配列やハッシュの要素は、その存在をテストしただけでは
3280ネストした配列やハッシュの一番深い部分は、その存在をテストしただけでは
52623281存在するようにはなりませんが、途中のものは存在するようになります。
5263従って C<< $ref->{"A"} >> と C<< $ref->{"A"}->{"B"} >> は上記の C<$key>
3282従って C<< $ref->{"A"} >> と C<< $ref->{"A"}->{"B"} >> は上記の $key の
52643283存在をテストしたことによって存在するようになります。
52653284これは、矢印演算子が使われるところでは、以下のようなものを含むどこででも
52663285起こります。
52673286
52683287 undef $ref;
5269 if (exists $ref->{"Some key"}) { }
3288 if (exists $ref->{"Some key"}) { }
5270 print $ref; # prints HASH(0x80d3d5c)
3289 print $ref; # prints HASH(0x80d3d5c)
52713290
52723291=begin original
52733292
5274Use of a subroutine call, rather than a subroutine name, as an argument
3293This surprising autovivification in what does not at first--or even
5275to L<C<exists>|/exists EXPR> is an error.
3294second--glance appear to be an lvalue context may be fixed in a future
3295release.
52763296
52773297=end original
52783298
5279L<C<exists>|/exists EXPR> の引数としサブルーチなくサブルーチン
3299一目見ただけでは -- あるいは二目見も -- 驚かされる、左辺値コテキスト
5280呼び出を使と、エラーになります
3300自動有効化は将来のリリースでは修正されるでう。
52813301
5282 exists &sub; # OK
3302=begin original
5283 exists &sub(); # Error
52843303
5285=item exit EXPR
3304See L<perlref/"Pseudo-hashes: Using an array as a hash"> for specifics
5286X<exit> X<terminate> X<abort>
3305on how exists() acts when used on a pseudo-hash.
52873306
5288=item exit
3307=end original
52893308
5290=for Pod::Functions terminate this program
3309擬似ハッシュに用いた場合に exists() がどのように振舞うかの仕様については
3310L<perlref/"Pseudo-hashes: Using an array as a hash"> を参照してください。
52913311
52923312=begin original
52933313
3314Use of a subroutine call, rather than a subroutine name, as an argument
3315to exists() is an error.
3316
3317=end original
3318
3319exists() の引数としてサブルーチン名でなくサブルーチン呼び出しを使うと、
3320エラーになります。
3321
3322 exists &sub; # OK
3323 exists &sub(); # Error
3324
3325=item exit EXPR
3326
3327=begin original
3328
52943329Evaluates EXPR and exits immediately with that value. Example:
52953330
52963331=end original
52973332
52983333EXPR を評価し、即座にその値を持って終了します。
52993334例:
53003335
5301 my $ans = <STDIN>;
3336 $ans = <STDIN>;
53023337 exit 0 if $ans =~ /^[Xx]/;
53033338
53043339=begin original
53053340
5306See also L<C<die>|/die LIST>. If EXPR is omitted, exits with C<0>
3341See also C<die>. If EXPR is omitted, exits with C<0> status. The only
5307status. The only
53083342universally recognized values for EXPR are C<0> for success and C<1>
53093343for error; other values are subject to interpretation depending on the
53103344environment in which the Perl program is running. For example, exiting
5311334569 (EX_UNAVAILABLE) from a I<sendmail> incoming-mail filter will cause
53123346the mailer to return the item undelivered, but that's not true everywhere.
53133347
53143348=end original
53153349
5316L<C<die>|/die LIST> も参照してください。
3350C<die> も参照してください。
53173351EXPR が省略された場合には、ステータスを C<0> として終了します。
5318EXPR の値として広く利用可能なのは C<0> が成功で C<1> が
3352EXPR の値として広く利用可能なのは C<0> が成功で C<1> がエラーということだけです。
5319エラーということだけです; その他の値は、 Perl が実行される環境によって異なる
3353その他の値は、 Perl が実行される環境によって異なる解釈がされ
5320解釈がされる可能性があります。
3354可能性があります。
53213355例えば、I<sendmail> 到着メールフィルタから 69 (EX_UNAVAILABLE) で終了すると
53223356メーラーはアイテムを配達せずに差し戻しますが、
53233357これはいつでも真ではありません。
53243358
53253359=begin original
53263360
5327Don't use L<C<exit>|/exit EXPR> to abort a subroutine if there's any
3361Don't use C<exit> to abort a subroutine if there's any chance that
5328chance that someone might want to trap whatever error happened. Use
3362someone might want to trap whatever error happened. Use C<die> instead,
5329L<C<die>|/die LIST> instead, which can be trapped by an
3363which can be trapped by an C<eval>.
5330L<C<eval>|/eval EXPR>.
53313364
53323365=end original
53333366
53343367誰かが発生したエラーをトラップしようと考えている可能性がある場合は、
5335サブルーチンの中断に L<C<exit>|/exit EXPR> を使わないでください。
3368サブルーチンの中断に C<exit> を使わないでください。
5336代わりに L<C<eval>|/eval EXPR> でトラップできる L<C<die>|/die LIST>
3369代わりに C<eval> でトラップできる C<die> を使ってください。
5337使ってください。
53383370
53393371=begin original
53403372
5341The L<C<exit>|/exit EXPR> function does not always exit immediately. It
3373The exit() function does not always exit immediately. It calls any
5342calls any defined C<END> routines first, but these C<END> routines may
3374defined C<END> routines first, but these C<END> routines may not
5343not themselves abort the exit. Likewise any object destructors that
3375themselves abort the exit. Likewise any object destructors that need to
5344need to be called are called before the real exit. C<END> routines and
3376be called are called before the real exit. If this is a problem, you
5345destructors can change the exit status by modifying L<C<$?>|perlvar/$?>.
3377can call C<POSIX:_exit($status)> to avoid END and destructor processing.
5346If this is a problem, you can call
3378See L<perlmod> for details.
5347L<C<POSIX::_exit($status)>|POSIX/C<_exit>> to avoid C<END> and destructor
5348processing. See L<perlmod> for details.
53493379
53503380=end original
53513381
5352L<C<exit>|/exit EXPR> 関数は常に直ちに終了するわけではありません。
3382exit() 関数は常に直ちに終了するわけではありません。
5353まず、定義されている C<END> ルーチンを呼び出しますが、
3383まず、定義されている END ルーチンを呼び出しますが、
53543384C<END> ルーチン自身は exit を止められません。
53553385同様に、呼び出す必要のあるオブジェクトデストラクタは
53563386すべて、実際の終了前に呼び出されます。
5357C<END> ルーチンとデストラクタは L<C<$?>|perlvar/$?> を修正すること
3387これが問題になる場合は、END デストラクタが実行されること
5358終了コード変更できます
3388防ぐために C<POSIX:_exit($status)> 呼び出してください
5359これが問題になる場合は、C<END> やデストラクタが実行されることを
5360防ぐために L<C<POSIX::_exit($status)>|POSIX/C<_exit>> を呼び出してください。
53613389詳しくは L<perlmod> を参照してください。
53623390
5363=begin original
5364
5365Portability issues: L<perlport/exit>.
5366
5367=end original
5368
5369移植性の問題: L<perlport/exit>。
5370
53713391=item exp EXPR
5372X<exp> X<exponential> X<antilog> X<antilogarithm> X<e>
53733392
53743393=item exp
53753394
5376=for Pod::Functions raise I<e> to a power
5377
53783395=begin original
53793396
5380Returns I<e> (the natural logarithm base) to the power of EXPR.
3397Returns I<e> (the natural logarithm base) to the power of EXPR.
53813398If EXPR is omitted, gives C<exp($_)>.
53823399
53833400=end original
53843401
5385I<e> (自然対数の底) の EXPR 乗を返します。
3402I<e> (自然対数の底) の EXPR 乗を返します。 
53863403EXPR を省略した場合には、C<exp($_)> を返します。
53873404
5388=item fc EXPR
5389X<fc> X<foldcase> X<casefold> X<fold-case> X<case-fold>
5390
5391=item fc
5392
5393=for Pod::Functions +fc return casefolded version of a string
5394
5395=begin original
5396
5397Returns the casefolded version of EXPR. This is the internal function
5398implementing the C<\F> escape in double-quoted strings.
5399
5400=end original
5401
5402EXPR の畳み込み版を返します。
5403これは、ダブルクォート文字列における、C<\F> エスケープを
5404実装する内部関数です。
5405
5406=begin original
5407
5408Casefolding is the process of mapping strings to a form where case
5409differences are erased; comparing two strings in their casefolded
5410form is effectively a way of asking if two strings are equal,
5411regardless of case.
5412
5413=end original
5414
5415畳み込みは大文字小文字の違いを消した形式に文字列をマッピングする処理です;
5416畳み込み形式で二つの文字列を比較するのは二つの文字列が大文字小文字に
5417関わらず等しいかどうかを比較する効率的な方法です。
5418
5419=begin original
5420
5421Roughly, if you ever found yourself writing this
5422
5423=end original
5424
5425おおよそ、自分自身で以下のように書いていたとしても
5426
5427 lc($this) eq lc($that) # Wrong!
5428 # or
5429 uc($this) eq uc($that) # Also wrong!
5430 # or
5431 $this =~ /^\Q$that\E\z/i # Right!
5432
5433=begin original
5434
5435Now you can write
5436
5437=end original
5438
5439今では以下のように書けます
5440
5441 fc($this) eq fc($that)
5442
5443=begin original
5444
5445And get the correct results.
5446
5447=end original
5448
5449そして正しい結果を得られます。
5450
5451=begin original
5452
5453Perl only implements the full form of casefolding, but you can access
5454the simple folds using L<Unicode::UCD/B<casefold()>> and
5455L<Unicode::UCD/B<prop_invmap()>>.
5456For further information on casefolding, refer to
5457the Unicode Standard, specifically sections 3.13 C<Default Case Operations>,
54584.2 C<Case-Normative>, and 5.18 C<Case Mappings>,
5459available at L<http://www.unicode.org/versions/latest/>, as well as the
5460Case Charts available at L<http://www.unicode.org/charts/case/>.
5461
5462=end original
5463
5464Perl は完全な形式の畳み込みのみを実装していますが、
5465L<Unicode::UCD/B<casefold()>> と L<Unicode::UCD/B<prop_invmap()>> を使って
5466単純なたたみ込みにアクセスできます。
5467畳み込みに関するさらなる情報については、
5468L<http://www.unicode.org/versions/latest/> で利用可能な Unicode 標準、特に
54693.13 C<Default Case Operations>, 4.2 C<Case-Normative>, 5.18
5470C<Case Mappings> および、L<http://www.unicode.org/charts/case/> で
5471利用可能なケース表を参照してください。
5472
5473=begin original
5474
5475If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
5476
5477=end original
5478
5479EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
5480
5481=begin original
5482
5483This function behaves the same way under various pragmas, such as within
5484L<S<C<"use feature 'unicode_strings">>|feature/The 'unicode_strings' feature>,
5485as L<C<lc>|/lc EXPR> does, with the single exception of
5486L<C<fc>|/fc EXPR> of I<LATIN CAPITAL LETTER SHARP S> (U+1E9E) within the
5487scope of L<S<C<use locale>>|locale>. The foldcase of this character
5488would normally be C<"ss">, but as explained in the L<C<lc>|/lc EXPR>
5489section, case
5490changes that cross the 255/256 boundary are problematic under locales,
5491and are hence prohibited. Therefore, this function under locale returns
5492instead the string C<"\x{17F}\x{17F}">, which is the I<LATIN SMALL LETTER
5493LONG S>. Since that character itself folds to C<"s">, the string of two
5494of them together should be equivalent to a single U+1E9E when foldcased.
5495
5496=end original
5497
5498この関数は、
5499L<S<C<"use feature 'unicode_strings">>|feature/The 'unicode_strings' feature>
5500のようなさまざまなプラグマの影響下では、L<C<lc>|/lc EXPR> と同様に
5501振る舞います;
5502但し、L<S<C<use locale>>|locale> のスコープ内での
5503I<LATIN CAPITAL LETTER SHARP S> (U+1E9E) の L<C<fc>|/fc EXPR> は例外です。
5504この文字の畳み込み文字は普通は C<"ss"> ですが、L<C<lc>|/lc EXPR> の節で
5505説明しているように、ロケールの基での255/256 境界をまたぐ大文字小文字の変更は
5506問題があるので、禁止されています。
5507従って、ロケールの基ではこの関数は代わりに I<LATIN SMALL LETTER LONG S> である
5508C<"\x{17F}\x{17F}"> を返します。
5509この文字自体は C<"s"> の畳み込みなので、これら二つを合わせた文字列は
5510畳み込まれた場合は単一の U+1E9E と等価になります。
5511
5512=begin original
5513
5514While the Unicode Standard defines two additional forms of casefolding,
5515one for Turkic languages and one that never maps one character into multiple
5516characters, these are not provided by the Perl core. However, the CPAN module
5517L<C<Unicode::Casing>|Unicode::Casing> may be used to provide an implementation.
5518
5519=end original
5520
5521Unicode 標準はさらに二つの畳み込み形式、一つはツルキ語、もう一つは決して
5522一つの文字が複数の文字にマッピングされないもの、を定義していますが、
5523これらは Perl コアでは提供されません。
5524しかし、CPAN モジュール L<C<Unicode::Casing>|Unicode::Casing> が実装を
5525提供しています。
5526
5527=begin original
5528
5529L<C<fc>|/fc EXPR> is available only if the
5530L<C<"fc"> feature|feature/The 'fc' feature> is enabled or if it is
5531prefixed with C<CORE::>. The
5532L<C<"fc"> feature|feature/The 'fc' feature> is enabled automatically
5533with a C<use v5.16> (or higher) declaration in the current scope.
5534
5535=end original
5536
5537L<C<fc>|/fc EXPR> は L<C<"fc"> 機能|feature/The 'fc' feature> が有効か
5538C<CORE::> が前置されたときにのみ利用可能です。
5539L<C<"fc"> 機能|feature/The 'fc' feature> は現在のスコープで
5540C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。
5541
55423405=item fcntl FILEHANDLE,FUNCTION,SCALAR
5543X<fcntl>
55443406
5545=for Pod::Functions file control system call
5546
55473407=begin original
55483408
5549Implements the L<fcntl(2)> function. You'll probably have to say
3409Implements the fcntl(2) function. You'll probably have to say
55503410
5551=end original
5552
5553L<fcntl(2)> 関数を実装します。
5554正しい定数定義を得るために、まず
5555
55563411 use Fcntl;
55573412
5558=begin original
5559
55603413first to get the correct constant definitions. Argument processing and
5561value returned work just like L<C<ioctl>|/ioctl
3414value return works just like C<ioctl> below.
5562FILEHANDLE,FUNCTION,SCALAR> below. For example:
3415For example:
55633416
55643417=end original
55653418
3419fcntl(2) 関数を実装します。
3420正しい定数定義を得るために、まず、
3421
3422 use Fcntl;
3423
55663424と書くことが必要でしょう。
5567引数の処理と返り値については、下記の
3425引数の処理と返り値については、下記の C<ioctl> と同様に動作します。
5568L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同様に動作します。
3426例:
5569例えば:
55703427
55713428 use Fcntl;
5572 my $flags = fcntl($filehandle, F_GETFL, 0)
3429 fcntl($filehandle, F_GETFL, $packed_return_buffer)
5573 or die "Can't fcntl F_GETFL: $!";
3430 or die "can't fcntl F_GETFL: $!";
55743431
55753432=begin original
55763433
5577You don't have to check for L<C<defined>|/defined EXPR> on the return
3434You don't have to check for C<defined> on the return from C<fnctl>.
5578from L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>. Like
3435Like C<ioctl>, it maps a C<0> return from the system call into
5579L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>, it maps a C<0> return
3436C<"0 but true"> in Perl. This string is true in boolean context and C<0>
5580from the system call into C<"0 but true"> in Perl. This string is true
3437in numeric context. It is also exempt from the normal B<-w> warnings
5581in boolean context and C<0> in numeric context. It is also exempt from
3438on improper numeric conversions.
5582the normal
5583L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s>
5584L<warnings> on improper numeric conversions.
55853439
55863440=end original
55873441
5588L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> からの返り値のチェックに
3442C<fcntl> からの返り値のチェックに C<defined> を使う必要はありません。
5589L<C<defined>|/defined EXPR> を使う必要ありません。
3443C<ioctl> と違って、C<fnctl> はシステムコールの結果が C<0> だった場合
5590L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と違って、これは
3444C<"0 だが真"> を返します。
5591システムコールの結果が C<0> だった場合は C<"0 だが真"> を返します。
55923445この文字列は真偽値コンテキストでは真となり、
55933446数値コンテキストでは C<0> になります。
5594これはまた、不適切な数値変換に関する通常の
3447これはまた、不適切な数値変換に関する通常の B<-w> 警告を回避します。
5595L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s>
5596L<warnings> を回避します。
55973448
55983449=begin original
55993450
5600Note that L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> raises an
3451Note that C<fcntl> will produce a fatal error if used on a machine that
5601exception if used on a machine that doesn't implement L<fcntl(2)>. See
3452doesn't implement fcntl(2). See the Fcntl module or your fcntl(2)
5602the L<Fcntl> module or your L<fcntl(2)> manpage to learn what functions
3453manpage to learn what functions are available on your system.
5603are available on your system.
56043454
56053455=end original
56063456
5607L<fcntl(2)> が実装されていないマシンでは、
3457fcntl(2) が実装されていないマシンでは、C<fcntl>は致命的エラーを
5608L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> は例外を
56093458引き起こすことに注意してください。
5610システムでどの関数が利用可能かについては L<Fcntl> モジュールや
3459システムでどの関数が利用可能かについては Fcntl モジュールや
5611L<fcntl(2)> man ページを参照してください。
3460fcntl(2) man ページを参照してください。
56123461
5613=begin original
5614
5615Here's an example of setting a filehandle named C<$REMOTE> to be
5616non-blocking at the system level. You'll have to negotiate
5617L<C<$E<verbar>>|perlvar/$E<verbar>> on your own, though.
5618
5619=end original
5620
5621これは C<$REMOTE> というファイルハンドルをシステムレベルで
5622非ブロックモードにセットする例です。
5623ただし、 L<C<$E<verbar>>|perlvar/$E<verbar>> を自分で管理しなければなりません。
5624
5625 use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
5626
5627 my $flags = fcntl($REMOTE, F_GETFL, 0)
5628 or die "Can't get flags for the socket: $!\n";
5629
5630 fcntl($REMOTE, F_SETFL, $flags | O_NONBLOCK)
5631 or die "Can't set flags for the socket: $!\n";
5632
5633=begin original
5634
5635Portability issues: L<perlport/fcntl>.
5636
5637=end original
5638
5639移植性の問題: L<perlport/fcntl>。
5640
5641=item __FILE__
5642X<__FILE__>
5643
5644=for Pod::Functions the name of the current source file
5645
5646=begin original
5647
5648A special token that returns the name of the file in which it occurs.
5649
5650=end original
5651
5652これが書いてあるファイルの名前を返す特殊トークン。
5653
56543462=item fileno FILEHANDLE
5655X<fileno>
56563463
5657=item fileno DIRHANDLE
5658
5659=for Pod::Functions return file descriptor from filehandle
5660
56613464=begin original
56623465
5663Returns the file descriptor for a filehandle or directory handle,
3466Returns the file descriptor for a filehandle, or undefined if the
5664or undefined if the
3467filehandle is not open. This is mainly useful for constructing
5665filehandle is not open. If there is no real file descriptor at the OS
3468bitmaps for C<select> and low-level POSIX tty-handling operations.
5666level, as can happen with filehandles connected to memory objects via
5667L<C<open>|/open FILEHANDLE,EXPR> with a reference for the third
5668argument, -1 is returned.
5669
5670=end original
5671
5672ファイルハンドルやディレクトリハンドルに対するファイル記述子を返します;
5673ファイルハンドルがオープンしていない場合は未定義値を返します。
5674OS レベルで実際のファイル記述子がない(L<C<open>|/open FILEHANDLE,EXPR> の
5675第 3 引数にリファレンスを
5676指定してファイルハンドルがメモリオブジェクトと結びつけられたときに
5677起こります)場合、-1 が返されます。
5678
5679=begin original
5680
5681This is mainly useful for constructing bitmaps for
5682L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> and low-level POSIX
5683tty-handling operations.
56843469If FILEHANDLE is an expression, the value is taken as an indirect
56853470filehandle, generally its name.
56863471
56873472=end original
56883473
5689これは主 L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> や低レベ
3474ファイルハンドル対するファイ記述子を返します。
5690POSIX tty 操作に対する、ビットマップを構成するときに便利です。
3475ファイルハンドルがオーンしていない場合は未定義値返します。
3476これは主に C<select> や低レベル POSIX tty 操作に対する、ビットマップを
3477構成するときに便利です。
56913478FILEHANDLE が式であれば、
56923479その値が間接ファイルハンドル(普通は名前)として使われます。
56933480
56943481=begin original
56953482
5696You can use this to find out whether two handles refer to the
3483You can use this to find out whether two handles refer to the
56973484same underlying descriptor:
56983485
56993486=end original
57003487
5701これを、二つのハンドルが同じ識別子を参照しているかどうかを見つけるのに
3488これを、二つのハンドルが同じ記述子を参照しているかどうかを
5702使えます:
3489調べるのに使えます:
57033490
5704 if (fileno($this) != -1 && fileno($this) == fileno($that)) {
3491 if (fileno(THIS) == fileno(THAT)) {
5705 print "\$this and \$that are dups\n";
3492 print "THIS and THAT are dups\n";
5706 } elsif (fileno($this) != -1 && fileno($that) != -1) {
3493 }
5707 print "\$this and \$that have different " .
5708 "underlying file descriptors\n";
5709 } else {
5710 print "At least one of \$this and \$that does " .
5711 "not have a real file descriptor\n";
5712 }
57133494
5714=begin original
5715
5716The behavior of L<C<fileno>|/fileno FILEHANDLE> on a directory handle
5717depends on the operating system. On a system with L<dirfd(3)> or
5718similar, L<C<fileno>|/fileno FILEHANDLE> on a directory
5719handle returns the underlying file descriptor associated with the
5720handle; on systems with no such support, it returns the undefined value,
5721and sets L<C<$!>|perlvar/$!> (errno).
5722
5723=end original
5724
5725ディレクトリハンドルに対する L<C<fileno>|/fileno FILEHANDLE> の振る舞いは
5726オペレーティングシステムに依存します。
5727L<dirfd(3)> のようなものがあるシステムでは、ディレクトリハンドルに対する
5728L<C<fileno>|/fileno FILEHANDLE> はハンドルに関連付けられた基となる
5729ファイル記述子を返します;
5730そのような対応がないシステムでは、未定義値を返し、
5731L<C<$!>|perlvar/$!> (errno) を設定します。
5732
57333495=item flock FILEHANDLE,OPERATION
5734X<flock> X<lock> X<locking>
57353496
5736=for Pod::Functions lock an entire file with an advisory lock
5737
57383497=begin original
57393498
5740Calls L<flock(2)>, or an emulation of it, on FILEHANDLE. Returns true
3499Calls flock(2), or an emulation of it, on FILEHANDLE. Returns true
57413500for success, false on failure. Produces a fatal error if used on a
5742machine that doesn't implement L<flock(2)>, L<fcntl(2)> locking, or
3501machine that doesn't implement flock(2), fcntl(2) locking, or lockf(3).
5743L<lockf(3)>. L<C<flock>|/flock FILEHANDLE,OPERATION> is Perl's portable
3502C<flock> is Perl's portable file locking interface, although it locks
5744file-locking interface, although it locks entire files only, not
3503only entire files, not records.
5745records.
57463504
57473505=end original
57483506
5749FILEHANDLE に対して L<flock(2)>、またはそのエミュレーションを呼び出します。
3507FILEHANDLE に対して flock(2)、またはそのエミュレーションを呼び出します。
57503508成功時には真を、失敗時には偽を返します。
5751L<flock(2)>, L<fcntl(2)> ロック, L<lockf(3)> のいずれかを実装していない
3509flock(2), fcntl(2) ロック, lockf(3) のいずれかを実装していない
57523510マシンで使うと、致命的エラーが発生します。
5753L<C<flock>|/flock FILEHANDLE,OPERATION> は Perl の移植性のある
3511C<flock> は Perl の移植性のあるファイルロックインターフェースです。
5754ファイルロックインターフェースです;
57553512しかしレコードではなく、ファイル全体のみをロックします。
57563513
57573514=begin original
57583515
5759Two potentially non-obvious but traditional L<C<flock>|/flock
3516Two potentially non-obvious but traditional C<flock> semantics are
5760FILEHANDLE,OPERATION> semantics are
57613517that it waits indefinitely until the lock is granted, and that its locks
5762are B<merely advisory>. Such discretionary locks are more flexible, but
3518B<merely advisory>. Such discretionary locks are more flexible, but offer
5763offer fewer guarantees. This means that programs that do not also use
3519fewer guarantees. This means that files locked with C<flock> may be
5764L<C<flock>|/flock FILEHANDLE,OPERATION> may modify files locked with
3520modified by programs that do not also use C<flock>. See L<perlport>,
5765L<C<flock>|/flock FILEHANDLE,OPERATION>. See L<perlport>,
3521your port's specific documentation, or your system-specific local manpages
5766your port's specific documentation, and your system-specific local manpages
57673522for details. It's best to assume traditional behavior if you're writing
57683523portable programs. (But if you're not, you should as always feel perfectly
57693524free to write for your own system's idiosyncrasies (sometimes called
57703525"features"). Slavish adherence to portability concerns shouldn't get
57713526in the way of your getting your job done.)
57723527
57733528=end original
57743529
5775明白ではないものの、伝統的な L<C<flock>|/flock FILEHANDLE,OPERATION>
3530明白ではないものの、伝統的な C<flock> の動作としては、ロックが得られるまで
5776動作としては、ロックが得られるまで
57773531無限に待ち続けるものと、B<単に勧告的に> ロックするものの二つがあります。
57783532このような自由裁量のロックはより柔軟ですが、保障されるものはより少ないです。
5779これは、L<C<flock>|/flock FILEHANDLE,OPERATION> を使わないプログラムが
3533これは、C<flock> でロックされたファイルは C<flock> を使わない
5780L<C<flock>|/flock FILEHANDLE,OPERATION> でックさたファイル
3534グラムによって書き換えらるかもしれないこと意味します。
5781書き換えるかもしれないことを意味します。
57823535詳細については、L<perlport>、システム固有のドキュメント、システム固有の
57833536ローカルの man ページを参照してください。
57843537移植性のあるプログラムを書く場合は、伝統的な振る舞いを仮定するのが
57853538ベストです。
57863539(しかし移植性のないプログラムを書く場合は、自身のシステムの性癖(しばしば
57873540「仕様」と呼ばれます)に合わせて書くことも完全に自由です。
57883541盲目的に移植性に固執することで、あなたの作業を仕上げるのを邪魔するべきでは
57893542ありません。)
57903543
57913544=begin original
57923545
57933546OPERATION is one of LOCK_SH, LOCK_EX, or LOCK_UN, possibly combined with
57943547LOCK_NB. These constants are traditionally valued 1, 2, 8 and 4, but
5795you can use the symbolic names if you import them from the L<Fcntl> module,
3548you can use the symbolic names if you import them from the Fcntl module,
5796either individually, or as a group using the C<:flock> tag. LOCK_SH
3549either individually, or as a group using the ':flock' tag. LOCK_SH
57973550requests a shared lock, LOCK_EX requests an exclusive lock, and LOCK_UN
57983551releases a previously requested lock. If LOCK_NB is bitwise-or'ed with
5799LOCK_SH or LOCK_EX, then L<C<flock>|/flock FILEHANDLE,OPERATION> returns
3552LOCK_SH or LOCK_EX then C<flock> will return immediately rather than blocking
5800immediately rather than blocking waiting for the lock; check the return
3553waiting for the lock (check the return status to see if you got it).
5801status to see if you got it.
58023554
58033555=end original
58043556
58053557OPERATION は LOCK_SH, LOCK_EX, LOCK_UN のいずれかで、LOCK_NB と
58063558組み合わされることもあります。
5807これらの定数は伝統的には 1, 2, 8, 4 の値を持ちますが、L<Fcntl> モジュールから
3559これらの定数は伝統的には 1, 2, 8, 4 の値を持ちますが、Fcntl モジュールから
5808シンボル名を独立してインポートするか、C<:flock> タグを使うグループとして、
3560シンボル名を独立してインポートするか、 ':flock' タグを使うグループとして、
58093561シンボル名をを使うことができます。
58103562LOCK_SH は共有ロックを要求し、LOCK_EX は排他ロックを要求し、LOCK_UN は
58113563前回要求したロックを開放します。
5812LOCK_NB と LOCK_SH か LOCK_EX がビット単位の論理和されると、
3564LOCK_NB と LOCK_SH か LOCK_EX がビット単位の論理和されると、C<flock> は
5813L<C<flock>|/flock FILEHANDLE,OPERATION>
3565ロックを取得するまで待つのでなく、すぐに返ります(ロックが取得できたか
5814ロックを取得するまで待つのでなく、すぐに返ります;
3566どうかは返り値を調べます)。
5815ロックが取得できたかどうかは返り値を調べます。
58163567
58173568=begin original
58183569
58193570To avoid the possibility of miscoordination, Perl now flushes FILEHANDLE
58203571before locking or unlocking it.
58213572
58223573=end original
58233574
58243575不一致の可能性を避けるために、Perl はファイルをロック、アンロックする前に
58253576FILEHANDLE をフラッシュします。
58263577
58273578=begin original
58283579
5829Note that the emulation built with L<lockf(3)> doesn't provide shared
3580Note that the emulation built with lockf(3) doesn't provide shared
58303581locks, and it requires that FILEHANDLE be open with write intent. These
5831are the semantics that L<lockf(3)> implements. Most if not all systems
3582are the semantics that lockf(3) implements. Most if not all systems
5832implement L<lockf(3)> in terms of L<fcntl(2)> locking, though, so the
3583implement lockf(3) in terms of fcntl(2) locking, though, so the
58333584differing semantics shouldn't bite too many people.
58343585
58353586=end original
58363587
5837L<lockf(3)> で作成されたエミュレーションは共有ロックを提供せず、
3588lockf(3) で作成されたエミュレーションは共有ロックを提供せず、
58383589FILEHANDLE が書き込みモードで開いていることを必要とすることに
58393590注意してください。
5840これは L<lockf(3)> が実装している動作です。
3591これは lockf(3) が実装している動作です。
5841しかし、全てではないにしてもほとんどのシステムでは L<fcntl(2)> を使って
3592しかし、全てではないにしてもほとんどのシステムでは fcntl(2) を使って
5842L<lockf(3)> を実装しているので、異なった動作で多くの人々を混乱させることは
3593lockf(3) を実装しているので、異なった動作で多くの人々を混乱させることは
58433594ないはずです。
58443595
58453596=begin original
58463597
5847Note that the L<fcntl(2)> emulation of L<flock(3)> requires that FILEHANDLE
3598Note also that some versions of C<flock> cannot lock things over the
5848be open with read intent to use LOCK_SH and requires that it be open
3599network; you would need to use the more system-specific C<fcntl> for
5849with write intent to use LOCK_EX.
3600that. If you like you can force Perl to ignore your system's flock(2)
3601function, and so provide its own fcntl(2)-based emulation, by passing
5851=end original
5852
5853L<flock(3)> の L<fcntl(2)> エミュレーションは、 LOCK_SH を使うためには
5854FILEHANDLE を読み込みで開いている必要があり、LOCK_EX を使うためには
5855書き込みで開いている必要があることに注意してください。
5856
5857=begin original
5858
5859Note also that some versions of L<C<flock>|/flock FILEHANDLE,OPERATION>
5860cannot lock things over the network; you would need to use the more
5861system-specific L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> for
5862that. If you like you can force Perl to ignore your system's L<flock(2)>
5863function, and so provide its own L<fcntl(2)>-based emulation, by passing
58643602the switch C<-Ud_flock> to the F<Configure> program when you configure
5865and build a new Perl.
3603perl.
58663604
58673605=end original
58683606
5869ネットワーク越しにはロックできない L<C<flock>|/flock FILEHANDLE,OPERATION>
3607ネットワーク越しにはロックできない C<flock> もあることに注意してください;
5870ある注意してください;
3608のためは、よりシステム依存な C<fcntl> を使う必要があります。
5871このためは、よりシステム依存な
3609Perl にシステムの flock(2) 関数を無視させ、自身の fcntl(2) ベースの
5872L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> を使う必要があります。
3610エミュレーションを使う場合は、perl を設定するときに F<Configure>
5873Perl にシステ L<flock(2)> 関数無視せ、自身の L<fcntl(2)> ベースの
3611プログラ C<-Ud_flock> オプション渡してくだい。
5874エミュレーションを使う場合は、新しい Perl を設定およびビルドするときに
5875F<Configure> プログラムに C<-Ud_flock> オプションを渡してください。
58763612
58773613=begin original
58783614
58793615Here's a mailbox appender for BSD systems.
58803616
58813617=end original
58823618
58833619BSD システムでのメールボックスへの追加処理の例を示します。
58843620
5885 # import LOCK_* and SEEK_END constants
3621 use Fcntl ':flock'; # import LOCK_* constants
5886 use Fcntl qw(:flock SEEK_END);
58873622
58883623 sub lock {
5889 my ($fh) = @_;
3624 flock(MBOX,LOCK_EX);
5890 flock($fh, LOCK_EX) or die "Cannot lock mailbox - $!\n";
3625 # and, in case someone appended
5891 # and, in case we're running on a very old UNIX
3626 # while we were waiting...
5892 # variant without the modern O_APPEND semantics...
3627 seek(MBOX, 0, 2);
5893 seek($fh, 0, SEEK_END) or die "Cannot seek - $!\n";
58943628 }
58953629
58963630 sub unlock {
5897 my ($fh) = @_;
3631 flock(MBOX,LOCK_UN);
5898 flock($fh, LOCK_UN) or die "Cannot unlock mailbox - $!\n";
58993632 }
59003633
5901 open(my $mbox, ">>", "/usr/spool/mail/$ENV{'USER'}")
3634 open(MBOX, ">>/usr/spool/mail/$ENV{'USER'}")
5902 or die "Can't open mailbox: $!";
3635 or die "Can't open mailbox: $!";
59033636
5904 lock($mbox);
3637 lock();
5905 print $mbox $msg,"\n\n";
3638 print MBOX $msg,"\n\n";
5906 unlock($mbox);
3639 unlock();
59073640
59083641=begin original
59093642
5910On systems that support a real L<flock(2)>, locks are inherited across
3643On systems that support a real flock(), locks are inherited across fork()
5911L<C<fork>|/fork> calls, whereas those that must resort to the more
3644calls, whereas those that must resort to the more capricious fcntl()
5912capricious L<fcntl(2)> function lose their locks, making it seriously
3645function lose the locks, making it harder to write servers.
5913harder to write servers.
59143646
59153647=end original
59163648
5917真の L<flock(2)> に対応しているシステムではロックは L<C<fork>|/fork> を通して
3649真の flock() に対応しているシステムではロックは fork() を通して
5918継承されるのに対して、より不安定な L<fcntl(2)> に頼らなければならない場合、
3650継承されるのに対して、より不安定な fcntl() に頼らなければならない場合、
5919サーバを書くのは本当により難しくなります。
3651サーバを書くのはより難しくなります。
59203652
59213653=begin original
59223654
5923See also L<DB_File> for other L<C<flock>|/flock FILEHANDLE,OPERATION>
3655See also L<DB_File> for other flock() examples.
5924examples.
59253656
59263657=end original
59273658
5928その他の L<C<flock>|/flock FILEHANDLE,OPERATION> の例としては L<DB_File> も
3659その他の flock() の例としては L<DB_File> も参照してください。
5929参照してください。
59303660
5931=begin original
5932
5933Portability issues: L<perlport/flock>.
5934
5935=end original
5936
5937移植性の問題: L<perlport/flock>。
5938
59393661=item fork
5940X<fork> X<child> X<parent>
59413662
5942=for Pod::Functions create a new process just like this one
5943
59443663=begin original
59453664
5946Does a L<fork(2)> system call to create a new process running the
3665Does a fork(2) system call to create a new process running the
59473666same program at the same point. It returns the child pid to the
5948parent process, C<0> to the child process, or L<C<undef>|/undef EXPR> if
3667parent process, C<0> to the child process, or C<undef> if the fork is
5949the fork is
59503668unsuccessful. File descriptors (and sometimes locks on those descriptors)
59513669are shared, while everything else is copied. On most systems supporting
5952L<fork(2)>, great care has gone into making it extremely efficient (for
3670fork(), great care has gone into making it extremely efficient (for
59533671example, using copy-on-write technology on data pages), making it the
59543672dominant paradigm for multitasking over the last few decades.
59553673
59563674=end original
59573675
59583676同じプログラムの同じ地点から開始する新しいプロセスを作成するために
5959システムコール L<fork(2)> を行ないます。
3677システムコール fork(2) を行ないます。
59603678親プロセスには、チャイルドプロセスの pid を、
59613679チャイルドプロセスに C<0> を返しますが、
5962fork に失敗したときには、L<C<undef>|/undef EXPR>を返します。
3680fork に失敗したときには、C<undef>を返します。
59633681ファイル記述子(および記述子に関連するロック)は共有され、
59643682その他の全てはコピーされます。
5965L<fork(2)> に対応するほとんどのシステムでは、
3683fork() に対応するほとんどのシステムでは、
59663684これを極めて効率的にするために多大な努力が払われてきました
5967(例えば、データページへの copy-on-write テクノロジーなどです);
3685(例えば、データページへの copy-on-write テクノロジーなどです)
59683686これはここ 20 年にわたるマルチタスクに関する主要なパラダイムとなっています。
59693687
59703688=begin original
59713689
5972Perl attempts to flush all files opened for output before forking the
3690Beginning with v5.6.0, Perl will attempt to flush all files opened for
5973child process, but this may not be supported on some platforms (see
3691output before forking the child process, but this may not be supported
5974L<perlport>). To be safe, you may need to set
3692on some platforms (see L<perlport>). To be safe, you may need to set
5975L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>) or
3693C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method of
5976call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS> on
3694C<IO::Handle> on any open handles in order to avoid duplicate output.
5977any open handles to avoid duplicate output.
59783695
59793696=end original
59803697
59813698v5.6.0 から、Perl は子プロセスを fork する前に出力用にオープンしている全ての
59823699ファイルをフラッシュしようとしますが、これに対応していないプラットフォームも
59833700あります(L<perlport> を参照してください)。
59843701安全のためには、出力が重複するのを避けるために、
5985全てのオープンしているハンドルに対して L<C<$E<verbar>>|perlvar/$E<verbar>>
3702全てのオープンしているハンドルに対して C<$|> (English モジュールでは
5986(L<English> モジュールでは C<$AUTOFLUSH>) を設定するか、
3703$AUTOFLUSH) を設定するか、
5987L<C<IO::Handle>|IO::Handle/METHODS> モジュールの C<autoflush> メソッドを
3704C<IO::Handle> モジュールの C<autoflush()>メソッドをを呼ぶ必要が
5988呼ぶ必要があるかもしれません。
3705あるかもしれません。
59893706
59903707=begin original
59913708
5992If you L<C<fork>|/fork> without ever waiting on your children, you will
3709If you C<fork> without ever waiting on your children, you will
59933710accumulate zombies. On some systems, you can avoid this by setting
5994L<C<$SIG{CHLD}>|perlvar/%SIG> to C<"IGNORE">. See also L<perlipc> for
3711C<$SIG{CHLD}> to C<"IGNORE">. See also L<perlipc> for more examples of
5995more examples of forking and reaping moribund children.
3712forking and reaping moribund children.
59963713
59973714=end original
59983715
5999チャイルドプロセスの終了を待たずに、L<C<fork>|/fork> を繰り返せば、
3716チャイルドプロセスの終了を待たずに、C<fork> を繰り返せば、
60003717ゾンビをためこむことになります。
6001L<C<$SIG{CHLD}>|perlvar/%SIG> に C<"IGNORE"> を指定することでこれを
3718C<$SIG{CHLD}> に C<"IGNORE"> を指定することでこれを回避できるシステムもあります。
6002回避できるシステムもあります。
60033719fork と消滅しかけている子プロセスを回収するための更なる例については
60043720L<perlipc> も参照してください。
60053721
60063722=begin original
60073723
60083724Note that if your forked child inherits system file descriptors like
60093725STDIN and STDOUT that are actually connected by a pipe or socket, even
60103726if you exit, then the remote server (such as, say, a CGI script or a
60113727backgrounded job launched from a remote shell) won't think you're done.
60123728You should reopen those to F</dev/null> if it's any issue.
60133729
60143730=end original
60153731
60163732fork した子プロセスが STDIN や STDOUT といったシステムファイル記述子を
60173733継承する場合、(CGI スクリプトやリモートシェルといった
60183734バックグラウンドジョブのような)リモートサーバは考え通りに
60193735動かないであろうことに注意してください。
60203736このような場合ではこれらを F</dev/null> として再オープンするべきです。
60213737
6022=begin original
6023
6024On some platforms such as Windows, where the L<fork(2)> system call is
6025not available, Perl can be built to emulate L<C<fork>|/fork> in the Perl
6026interpreter. The emulation is designed, at the level of the Perl
6027program, to be as compatible as possible with the "Unix" L<fork(2)>.
6028However it has limitations that have to be considered in code intended
6029to be portable. See L<perlfork> for more details.
6030
6031=end original
6032
6033Windows のような L<fork(2)> が利用不能なシステムでは、Perl は
6034L<C<fork>|/fork> を Perl インタプリタでエミュレートします。
6035エミュレーションは Perl プログラムのレベルではできるだけ "Unix" L<fork(2)> と
6036互換性があるように設計されています。
6037しかしコードが移植性があると考えられるように制限があります。
6038さらなる詳細については L<perlfork> を参照してください。
6039
6040=begin original
6041
6042Portability issues: L<perlport/fork>.
6043
6044=end original
6045
6046移植性の問題: L<perlport/fork>。
6047
60483738=item format
6049X<format>
60503739
6051=for Pod::Functions declare a picture format with use by the write() function
6052
60533740=begin original
60543741
6055Declare a picture format for use by the L<C<write>|/write FILEHANDLE>
3742Declare a picture format for use by the C<write> function. For
6056function. For example:
3743example:
60573744
60583745=end original
60593746
6060L<C<write>|/write FILEHANDLE> 関数で使うピクチャーフォーマットを宣言します。
3747C<write> 関数で使うピクチャーフォーマットを宣言します。
6061えば:
3748例:
60623749
60633750 format Something =
6064 Test: @<<<<<<<< @||||| @>>>>>
3751 Test: @<<<<<<<< @||||| @>>>>>
6065 $str, $%, '$' . int($num)
3752 $str, $%, '$' . int($num)
60663753 .
60673754
60683755 $str = "widget";
60693756 $num = $cost/$quantity;
60703757 $~ = 'Something';
60713758 write;
60723759
60733760=begin original
60743761
60753762See L<perlform> for many details and examples.
60763763
60773764=end original
60783765
6079詳細と例については L<perlform> を参照してください。
3766詳細と例については L<perlform> を参照してさい。
60803767
60813768=item formline PICTURE,LIST
6082X<formline>
60833769
6084=for Pod::Functions internal function used for formats
6085
60863770=begin original
60873771
6088This is an internal function used by L<C<format>|/format>s, though you
3772This is an internal function used by C<format>s, though you may call it,
6089may call it, too. It formats (see L<perlform>) a list of values
3773too. It formats (see L<perlform>) a list of values according to the
6090according to the contents of PICTURE, placing the output into the format
3774contents of PICTURE, placing the output into the format output
6091output accumulator, L<C<$^A>|perlvar/$^A> (or C<$ACCUMULATOR> in
3775accumulator, C<$^A> (or C<$ACCUMULATOR> in English).
6092L<English>). Eventually, when a L<C<write>|/write FILEHANDLE> is done,
3776Eventually, when a C<write> is done, the contents of
6093the contents of L<C<$^A>|perlvar/$^A> are written to some filehandle.
3777C<$^A> are written to some filehandle, but you could also read C<$^A>
6094You could also read L<C<$^A>|perlvar/$^A> and then set
3778yourself and then set C<$^A> back to C<"">. Note that a format typically
6095L<C<$^A>|perlvar/$^A> back to C<"">. Note that a format typically does
3779does one C<formline> per line of form, but the C<formline> function itself
6096one L<C<formline>|/formline PICTURE,LIST> per line of form, but the
3780doesn't care how many newlines are embedded in the PICTURE. This means
6097L<C<formline>|/formline PICTURE,LIST> function itself doesn't care how
3781that the C<~> and C<~~> tokens will treat the entire PICTURE as a single line.
6098many newlines are embedded in the PICTURE. This means that the C<~> and
3782You may therefore need to use multiple formlines to implement a single
6099C<~~> tokens treat the entire PICTURE as a single line. You may
3783record format, just like the format compiler.
6100therefore need to use multiple formlines to implement a single record
6101format, just like the L<C<format>|/format> compiler.
61023784
61033785=end original
61043786
6105これは、L<C<format>|/format> が使用する内部関数ですが、直接呼び出すことも
3787これは、C<format> が使用する内部関数ですが、直接呼び出すこともできます。
6106できます。
3788これは、PICTURE の内容にしたがって、
6107これは、PICTURE の内容にしたがって、LIST の値を整形し (L<perlform>
3789LIST の値を整形し (perlform manpage 参照してください)、
6108参照してください)、結果をフォーマット出力アキュムレータL<C<$^A>|perlvar/$^A>
3790結果をフォーマット出力アキュムレータ
6109(L<English> モジュールでは C<$ACCUMULATOR>) に納めます。
3791C<$^A>(English モジュールでは C<$ACCUMULATOR>) に納めます。
6110最終的に、L<C<write>|/write FILEHANDLE> が実行されると、
3792最終的に、C<write> が実行されると、C<$^A> の中身が
6111L<C<$^A>|perlvar/$^A> の中身が、何らかのファイルハンドルに書き出されます
3793何らかのファイルハンドルに書き出されますが、自分で C<$^A> を読んで、
6112また、自分で L<C<$^A>|perlvar/$^A>読んで、L<C<$^A>|perlvar/$^A> の内容を
3794C<$^A> の内容 C<""> に戻してもかまいません。
6113C<""> に戻してもかまいません。
3795format は通常、1 行ごとに C<formline> を行ないますが、
6114format は通常、1 行ごとに L<C<formline>|/formline PICTURE,LIST>
3796C<formline> 関数自身は、PICTURE の中にいくつの改行が入っているかは、
6115行ないますが、L<C<formline>|/formline PICTURE,LIST> 数自身は、PICTURE の中に
3797係がありません。
6116いくつの改行が入っているかは、関係がありません。
61173798これは、C<~> と C<~~>トークンは PICTURE 全体を一行として扱うことを意味します。
61183799従って、1 レコードフォーマットを実装するためには
6119L<C<format>|/format> コンパイラのような複数 formline を使う必要があります。
3800フォーマットコンパイラのような複数 formline を使う必要があります。
61203801
61213802=begin original
61223803
61233804Be careful if you put double quotes around the picture, because an C<@>
61243805character may be taken to mean the beginning of an array name.
6125L<C<formline>|/formline PICTURE,LIST> always returns true. See
3806C<formline> always returns true. See L<perlform> for other examples.
6126L<perlform> for other examples.
61273807
61283808=end original
61293809
61303810ダブルクォートで PICTURE を囲む場合には、C<@> という文字が
61313811配列名の始まりと解釈されますので、注意してください。
6132L<C<formline>|/formline PICTURE,LIST> は常に真を返します。
3812C<formline> は常に真を返します。
61333813その他の例については L<perlform> を参照してください。
61343814
6135=begin original
6136
6137If you are trying to use this instead of L<C<write>|/write FILEHANDLE>
6138to capture the output, you may find it easier to open a filehandle to a
6139scalar (C<< open my $fh, ">", \$output >>) and write to that instead.
6140
6141=end original
6142
6143出力を捕捉するために L<C<write>|/write FILEHANDLE> の代わりにこれを
6144使おうとした場合、スカラにファイルハンドルを開いて
6145(C<< open my $fh, ">", \$output >>)、
6146代わりにここに出力する方が簡単であることに気付くでしょう。
6147
61483815=item getc FILEHANDLE
6149X<getc> X<getchar> X<character> X<file, read>
61503816
61513817=item getc
61523818
6153=for Pod::Functions get the next character from the filehandle
6154
61553819=begin original
61563820
61573821Returns the next character from the input file attached to FILEHANDLE,
6158or the undefined value at end of file or if there was an error (in
3822or the undefined value at end of file, or if there was an error.
6159the latter case L<C<$!>|perlvar/$!> is set). If FILEHANDLE is omitted,
3823If FILEHANDLE is omitted, reads from STDIN. This is not particularly
6160reads from
3824efficient. However, it cannot be used by itself to fetch single
6161STDIN. This is not particularly efficient. However, it cannot be
3825characters without waiting for the user to hit enter. For that, try
6162used by itself to fetch single characters without waiting for the user
3826something more like:
6163to hit enter. For that, try something more like:
61643827
61653828=end original
61663829
6167FILEHANDLE につながれている入力ファイルから、次の一文字を返します;
3830FILEHANDLE につながれている入力ファイルから、次の一文字を返します
6168ファイルの最後、またはエラーが発生した場合は、未定義値を返します
3831ファイルの最後、またはエラーが発生した場合は、未定義値を返します
6169(後者の場合は L<C<$!>|perlvar/$!> がセットされます)。
61703832FILEHANDLE が省略された場合には、STDIN から読み込みを行ないます。
61713833これは特に効率的ではありません。
61723834しかし、これはユーザーがリターンキーを押すのを待つことなく
61733835一文字を読み込む用途には使えません。
61743836そのような場合には、以下のようなものを試して見てください:
61753837
61763838 if ($BSD_STYLE) {
6177 system "stty cbreak </dev/tty >/dev/tty 2>&1";
3839 system "stty cbreak </dev/tty >/dev/tty 2>&1";
61783840 }
61793841 else {
6180 system "stty", '-icanon', 'eol', "\001";
3842 system "stty", '-icanon', 'eol', "\001";
61813843 }
61823844
6183 my $key = getc(STDIN);
3845 $key = getc(STDIN);
61843846
61853847 if ($BSD_STYLE) {
6186 system "stty -cbreak </dev/tty >/dev/tty 2>&1";
3848 system "stty -cbreak </dev/tty >/dev/tty 2>&1";
61873849 }
61883850 else {
6189 system 'stty', 'icanon', 'eol', '^@'; # ASCII NUL
3851 system "stty", 'icanon', 'eol', '^@'; # ASCII null
61903852 }
61913853 print "\n";
61923854
61933855=begin original
61943856
6195Determination of whether C<$BSD_STYLE> should be set is left as an
3857Determination of whether $BSD_STYLE should be set
6196exercise to the reader.
3858is left as an exercise to the reader.
61973859
61983860=end original
61993861
6200C<$BSD_STYLE> をセットするべきかどうかを決定する方法については
3862$BSD_STYLE をセットするべきかどうかを決定する方法については
62013863読者への宿題として残しておきます。
62023864
62033865=begin original
62043866
6205The L<C<POSIX::getattr>|POSIX/C<getattr>> function can do this more
3867The C<POSIX::getattr> function can do this more portably on
6206portably on systems purporting POSIX compliance. See also the
3868systems purporting POSIX compliance. See also the C<Term::ReadKey>
6207L<C<Term::ReadKey>|Term::ReadKey> module on CPAN.
3869module from your nearest CPAN site; details on CPAN can be found on
3870L<perlmodlib/CPAN>.
62083871
62093872=end original
62103873
6211L<C<POSIX::getattr>|POSIX/C<getattr>> 関数は POSIX 準拠を主張するシステムで
3874C<POSIX::getattr> 関数は POSIX 準拠を主張するシステムで
6212これをより移植性のある形で行います。
3875これをより移植性のある形で行います。お近くの CPAN サイトから
6213CPAN にある L<C<Term::ReadKey>|Term::ReadKey> モジュールも
3876C<Term::ReadKey> モジュールも参照して下さい; CPAN に関する詳細は
6214参照してください
3877L<perlmodlib/CPAN> にあります
62153878
62163879=item getlogin
6217X<getlogin> X<login>
62183880
6219=for Pod::Functions return who logged in at this tty
6220
62213881=begin original
62223882
6223This implements the C library function of the same name, which on most
3883Implements the C library function of the same name, which on most
6224systems returns the current login from F</etc/utmp>, if any. If it
3884systems returns the current login from F</etc/utmp>, if any. If null,
6225returns the empty string, use L<C<getpwuid>|/getpwuid UID>.
3885use C<getpwuid>.
62263886
62273887=end original
62283888
6229これは同じ名前の C ライブラリ関数実装していて、
3889同じ名前の C ライブラリ関数実装です。
6230多くのシステムでは、もしあれば、F</etc/utmp> から現在のログイン名を返します。
3890多くのシステムでは、もしあれば、/etc/utmp から現在のログイン名を返します。
6231もし空文字列が返ってきた場合はL<C<getpwuid>|/getpwuid UID>
3891ヌルであれば、getpwuid()使ってください。
6232使ってください。
62333892
6234 my $login = getlogin || getpwuid($<) || "Kilroy";
3893 $login = getlogin || getpwuid($<) || "Kilroy";
62353894
62363895=begin original
62373896
6238Do not consider L<C<getlogin>|/getlogin> for authentication: it is not
3897Do not consider C<getlogin> for authentication: it is not as
6239as secure as L<C<getpwuid>|/getpwuid UID>.
3898secure as C<getpwuid>.
62403899
62413900=end original
62423901
6243L<C<getlogin>|/getlogin> を認証に使ってはいけません: これは
3902C<getlogin> を認証に使ってはいけません
6244L<C<getpwuid>|/getpwuid UID> のように安全ではありません。
3903これは C<getpwuid> のように安全ではありません。
62453904
6246=begin original
6247
6248Portability issues: L<perlport/getlogin>.
6249
6250=end original
6251
6252移植性の問題: L<perlport/getlogin>。
6253
62543905=item getpeername SOCKET
6255X<getpeername> X<peer>
62563906
6257=for Pod::Functions find the other end of a socket connection
6258
62593907=begin original
62603908
6261Returns the packed sockaddr address of the other end of the SOCKET
3909Returns the packed sockaddr address of other end of the SOCKET connection.
6262connection.
62633910
62643911=end original
62653912
62663913SOCKET コネクションの向こう側のパックされた aockaddr アドレスを返します。
62673914
62683915 use Socket;
6269 my $hersockaddr = getpeername($sock);
3916 $hersockaddr = getpeername(SOCK);
6270 my ($port, $iaddr) = sockaddr_in($hersockaddr);
3917 ($port, $iaddr) = sockaddr_in($hersockaddr);
6271 my $herhostname = gethostbyaddr($iaddr, AF_INET);
3918 $herhostname = gethostbyaddr($iaddr, AF_INET);
6272 my $herstraddr = inet_ntoa($iaddr);
3919 $herstraddr = inet_ntoa($iaddr);
62733920
62743921=item getpgrp PID
6275X<getpgrp> X<group>
62763922
6277=for Pod::Functions get process group
6278
62793923=begin original
62803924
62813925Returns the current process group for the specified PID. Use
62823926a PID of C<0> to get the current process group for the
62833927current process. Will raise an exception if used on a machine that
6284doesn't implement L<getpgrp(2)>. If PID is omitted, returns the process
3928doesn't implement getpgrp(2). If PID is omitted, returns process
6285group of the current process. Note that the POSIX version of
3929group of current process. Note that the POSIX version of C<getpgrp>
6286L<C<getpgrp>|/getpgrp PID> does not accept a PID argument, so only
3930does not accept a PID argument, so only C<PID==0> is truly portable.
6287C<PID==0> is truly portable.
62883931
62893932=end original
62903933
62913934指定された PID の現在のプロセスグループを返します。
62923935PID に C<0> を与えるとカレントプロセスの指定となります。
6293L<getpgrp(2)> を実装していないマシンで実行した場合には、例外が発生します。
3936getpgrp(2) を実装していないマシンで実行した場合には、例外が発生します。
62943937PID を省略するとカレントプロセスのプロセスグループを返します。
6295POSIX 版の L<C<getpgrp>|/getpgrp PID> は PID 引数を受け付けないので、
3938POSIX 版の C<getpgrp> は PID 引数を受け付けないので、
62963939C<PID==0> のみが完全に移植性があります。
62973940
6298=begin original
6299
6300Portability issues: L<perlport/getpgrp>.
6301
6302=end original
6303
6304移植性の問題: L<perlport/getpgrp>。
6305
63063941=item getppid
6307X<getppid> X<parent> X<pid>
63083942
6309=for Pod::Functions get parent process ID
6310
63113943=begin original
63123944
63133945Returns the process id of the parent process.
63143946
63153947=end original
63163948
63173949親プロセスのプロセス id を返します。
63183950
6319=begin original
6320
6321Note for Linux users: Between v5.8.1 and v5.16.0 Perl would work
6322around non-POSIX thread semantics the minority of Linux systems (and
6323Debian GNU/kFreeBSD systems) that used LinuxThreads, this emulation
6324has since been removed. See the documentation for L<$$|perlvar/$$> for
6325details.
6326
6327=end original
6328
6329Linux ユーザーへの注意: v5.8.1 から v5.16.0 の間 Perl は
6330LinuxThreads という非 POSIX なスレッド文法を使っているマイナーな
6331Linux システム (および Debian GNU/kFreeBSD システム) に対応していました。
6332このエミュレーションは削除されました;
6333詳しくは L<$$|perlvar/$$> の文書を参照してください。
6334
6335=begin original
6336
6337Portability issues: L<perlport/getppid>.
6338
6339=end original
6340
6341移植性の問題: L<perlport/getppid>。
6342
63433951=item getpriority WHICH,WHO
6344X<getpriority> X<priority> X<nice>
63453952
6346=for Pod::Functions get current nice value
6347
63483953=begin original
63493954
63503955Returns the current priority for a process, a process group, or a user.
63513956(See L<getpriority(2)>.) Will raise a fatal exception if used on a
6352machine that doesn't implement L<getpriority(2)>.
3957machine that doesn't implement getpriority(2).
63533958
63543959=end original
63553960
63563961プロセス、プロセスグループ、ユーザに対する現在の優先度を返します。
63573962(L<getpriority(2)> を参照してください。)
6358L<getpriority(2)> を実装していない
3963getpriority(2) を実装していない
6359マシンで実行した場合には、致命的例外が発生します。
3964マシンで実行した場合には、例外が発生します。
63603965
6361=begin original
6362
6363C<WHICH> can be any of C<PRIO_PROCESS>, C<PRIO_PGRP> or C<PRIO_USER>
6364imported from L<POSIX/RESOURCE CONSTANTS>.
6365
6366=end original
6367
6368C<WHICH> は L<POSIX/RESOURCE CONSTANTS> からインポートされた
6369C<PRIO_PROCESS>, C<PRIO_PGRP>, C<PRIO_USER> のいずれかです。
6370
6371=begin original
6372
6373Portability issues: L<perlport/getpriority>.
6374
6375=end original
6376
6377移植性の問題: L<perlport/getpriority>。
6378
63793966=item getpwnam NAME
6380X<getpwnam> X<getgrnam> X<gethostbyname> X<getnetbyname> X<getprotobyname>
6381X<getpwuid> X<getgrgid> X<getservbyname> X<gethostbyaddr> X<getnetbyaddr>
6382X<getprotobynumber> X<getservbyport> X<getpwent> X<getgrent> X<gethostent>
6383X<getnetent> X<getprotoent> X<getservent> X<setpwent> X<setgrent> X<sethostent>
6384X<setnetent> X<setprotoent> X<setservent> X<endpwent> X<endgrent> X<endhostent>
6385X<endnetent> X<endprotoent> X<endservent>
63863967
6387=for Pod::Functions get passwd record given user login name
6388
63893968=item getgrnam NAME
63903969
6391=for Pod::Functions get group record given group name
6392
63933970=item gethostbyname NAME
63943971
6395=for Pod::Functions get host record given name
6396
63973972=item getnetbyname NAME
63983973
6399=for Pod::Functions get networks record given name
6400
64013974=item getprotobyname NAME
64023975
6403=for Pod::Functions get protocol record given name
6404
64053976=item getpwuid UID
64063977
6407=for Pod::Functions get passwd record given user ID
6408
64093978=item getgrgid GID
64103979
6411=for Pod::Functions get group record given group user ID
6412
64133980=item getservbyname NAME,PROTO
64143981
6415=for Pod::Functions get services record given its name
6416
64173982=item gethostbyaddr ADDR,ADDRTYPE
64183983
6419=for Pod::Functions get host record given its address
6420
64213984=item getnetbyaddr ADDR,ADDRTYPE
64223985
6423=for Pod::Functions get network record given its address
6424
64253986=item getprotobynumber NUMBER
64263987
6427=for Pod::Functions get protocol record numeric protocol
6428
64293988=item getservbyport PORT,PROTO
64303989
6431=for Pod::Functions get services record given numeric port
6432
64333990=item getpwent
64343991
6435=for Pod::Functions get next passwd record
6436
64373992=item getgrent
64383993
6439=for Pod::Functions get next group record
6440
64413994=item gethostent
64423995
6443=for Pod::Functions get next hosts record
6444
64453996=item getnetent
64463997
6447=for Pod::Functions get next networks record
6448
64493998=item getprotoent
64503999
6451=for Pod::Functions get next protocols record
6452
64534000=item getservent
64544001
6455=for Pod::Functions get next services record
6456
64574002=item setpwent
64584003
6459=for Pod::Functions prepare passwd file for use
6460
64614004=item setgrent
64624005
6463=for Pod::Functions prepare group file for use
6464
64654006=item sethostent STAYOPEN
64664007
6467=for Pod::Functions prepare hosts file for use
6468
64694008=item setnetent STAYOPEN
64704009
6471=for Pod::Functions prepare networks file for use
6472
64734010=item setprotoent STAYOPEN
64744011
6475=for Pod::Functions prepare protocols file for use
6476
64774012=item setservent STAYOPEN
64784013
6479=for Pod::Functions prepare services file for use
6480
64814014=item endpwent
64824015
6483=for Pod::Functions be done using passwd file
6484
64854016=item endgrent
64864017
6487=for Pod::Functions be done using group file
6488
64894018=item endhostent
64904019
6491=for Pod::Functions be done using hosts file
6492
64934020=item endnetent
64944021
6495=for Pod::Functions be done using networks file
6496
64974022=item endprotoent
64984023
6499=for Pod::Functions be done using protocols file
6500
65014024=item endservent
65024025
6503=for Pod::Functions be done using services file
6504
65054026=begin original
65064027
6507These routines are the same as their counterparts in the
4028These routines perform the same functions as their counterparts in the
6508system C library. In list context, the return values from the
4029system library. In list context, the return values from the
65094030various get routines are as follows:
65104031
65114032=end original
65124033
6513これらのルーチンは、システムの C ライブラリの同名の関数と同じです。
4034これらのルーチンは、システムライブラリの同名の関数を実行します。
65144035リストコンテキストでは、さまざまな
65154036get ルーチンからの返り値は、次のようになります:
65164037
6517 # 0 1 2 3 4
4038 ($name,$passwd,$uid,$gid,
6518 my ( $name, $passwd, $gid, $members ) = getgr*
4039 $quota,$comment,$gcos,$dir,$shell,$expire) = getpw*
6519 my ( $name, $aliases, $addrtype, $net ) = getnet*
4040 ($name,$passwd,$gid,$members) = getgr*
6520 my ( $name, $aliases, $port, $proto ) = getserv*
4041 ($name,$aliases,$addrtype,$length,@addrs) = gethost*
6521 my ( $name, $aliases, $proto ) = getproto*
4042 ($name,$aliases,$addrtype,$net) = getnet*
6522 my ( $name, $aliases, $addrtype, $length, @addrs ) = gethost*
4043 ($name,$aliases,$proto) = getproto*
6523 my ( $name, $passwd, $uid, $gid, $quota,
4044 ($name,$aliases,$port,$proto) = getserv*
6524 $comment, $gcos, $dir, $shell, $expire ) = getpw*
6525 # 5 6 7 8 9
65264045
65274046=begin original
65284047
6529(If the entry doesn't exist, the return value is a single meaningless true
4048(If the entry doesn't exist you get a null list.)
6530value.)
65314049
65324050=end original
65334051
6534(エントリが存在しなければ、返り値は単一の意味のない真の値です。)
4052(エントリが存在しなければ、空リストがされます。)
65354053
65364054=begin original
65374055
65384056The exact meaning of the $gcos field varies but it usually contains
65394057the real name of the user (as opposed to the login name) and other
65404058information pertaining to the user. Beware, however, that in many
65414059system users are able to change this information and therefore it
65424060cannot be trusted and therefore the $gcos is tainted (see
65434061L<perlsec>). The $passwd and $shell, user's encrypted password and
6544login shell, are also tainted, for the same reason.
4062login shell, are also tainted, because of the same reason.
65454063
65464064=end original
65474065
65484066$gcos フィールドの正確な意味はさまざまですが、通常は(ログイン名ではなく)
65494067ユーザーの実際の名前とユーザーに付随する情報を含みます。
65504068但し、多くのシステムではユーザーがこの情報を変更できるので、この情報は
65514069信頼できず、従って $gcos は汚染されます(L<perlsec> を参照してください)。
65524070ユーザーの暗号化されたパスワードとログインシェルである $passwd と
65534071$shell も、同様の理由で汚染されます。
65544072
65554073=begin original
65564074
65574075In scalar context, you get the name, unless the function was a
65584076lookup by name, in which case you get the other thing, whatever it is.
65594077(If the entry doesn't exist you get the undefined value.) For example:
65604078
65614079=end original
65624080
65634081スカラコンテキストでは、*nam、*byname といった NAME で検索するもの以外は、
65644082name を返し、NAME で検索するものは、何か別のものを返します。
65654083(エントリが存在しなければ、未定義値が返ります。)
6566えば:
4084例:
65674085
6568 my $uid = getpwnam($name);
4086 $uid = getpwnam($name);
6569 my $name = getpwuid($num);
4087 $name = getpwuid($num);
6570 my $name = getpwent();
4088 $name = getpwent();
6571 my $gid = getgrnam($name);
4089 $gid = getgrnam($name);
6572 my $name = getgrgid($num);
4090 $name = getgrgid($num;
6573 my $name = getgrent();
4091 $name = getgrent();
6574 <#del> etc.
4092 #etc.
65754093
65764094=begin original
65774095
65784096In I<getpw*()> the fields $quota, $comment, and $expire are special
6579in that they are unsupported on many systems. If the
4097cases in the sense that in many systems they are unsupported. If the
65804098$quota is unsupported, it is an empty scalar. If it is supported, it
65814099usually encodes the disk quota. If the $comment field is unsupported,
65824100it is an empty scalar. If it is supported it usually encodes some
65834101administrative comment about the user. In some systems the $quota
65844102field may be $change or $age, fields that have to do with password
65854103aging. In some systems the $comment field may be $class. The $expire
65864104field, if present, encodes the expiration period of the account or the
65874105password. For the availability and the exact meaning of these fields
6588in your system, please consult L<getpwnam(3)> and your system's
4106in your system, please consult your getpwnam(3) documentation and your
65894107F<pwd.h> file. You can also find out from within Perl what your
65904108$quota and $comment fields mean and whether you have the $expire field
6591by using the L<C<Config>|Config> module and the values C<d_pwquota>, C<d_pwage>,
4109by using the C<Config> module and the values C<d_pwquota>, C<d_pwage>,
65924110C<d_pwchange>, C<d_pwcomment>, and C<d_pwexpire>. Shadow password
6593files are supported only if your vendor has implemented them in the
4111files are only supported if your vendor has implemented them in the
65944112intuitive fashion that calling the regular C library routines gets the
65954113shadow versions if you're running under privilege or if there exists
6596the L<shadow(3)> functions as found in System V (this includes Solaris
4114the shadow(3) functions as found in System V ( this includes Solaris
6597and Linux). Those systems that implement a proprietary shadow password
4115and Linux.) Those systems which implement a proprietary shadow password
65984116facility are unlikely to be supported.
65994117
66004118=end original
66014119
66024120I<getpw*()> では、$quota, $comment, $expire フィールドは、
66034121多くのシステムでは対応していないので特別な処理がされます。
66044122$quota が非対応の場合、空のスカラになります。
66054123対応している場合、通常はディスククォータの値が入ります。
66064124$comment フィールドが非対応の場合、空のスカラになります。
66074125対応している場合、通常はユーザーに関する管理上のコメントが入ります。
66084126$quota フィールドはパスワードの寿命を示す $change や $age である
66094127システムもあります。
66104128$comment フィールドは $class であるシステムもあります。
66114129$expire フィールドがある場合は、アカウントやパスワードが時間切れになる
66124130期間が入ります。
66134131動作させるシステムでのこれらのフィールドの有効性と正確な意味については、
6614L<getpwnam(3)> のドキュメントと F<pwd.h> ファイルを参照してください。
4132getpwnam(3) のドキュメントと F<pwd.h> ファイルを参照してください。
66154133$quota と $comment フィールドが何を意味しているかと、$expire フィールドが
6616あるかどうかは、L<C<Config>|Config> モジュールを使って、C<d_pwquota>,
4134あるかどうかは、C<Config> モジュールを使って、C<d_pwquota>, C<d_pwage>,
6617C<d_pwage>, C<d_pwchange>, C<d_pwcomment>, C<d_pwexpire> の値を
4135C<d_pwchange>, C<d_pwcomment>, C<d_pwexpire> の値を調べることによって
6618調べることによって Perl 自身で調べることも出来ます。
4136Perl 自身で調べることも出来ます。
66194137シャドウパスワードは、通常の C ライブラリルーチンを権限がある状態で
66204138呼び出すことでシャドウ版が取得できるか、System V にあるような
6621(Solaris と Linux を含みます) L<shadow(3)> 関数があるといった、
4139(Solaris と Linux を含みます) shadow(3) 関数があるといった、
66224140直感的な方法で実装されている場合にのみ対応されます。
66234141独占的なシャドウパスワード機能を実装しているシステムでは、
66244142それに対応されることはないでしょう。
66254143
66264144=begin original
66274145
6628The $members value returned by I<getgr*()> is a space-separated list of
4146The $members value returned by I<getgr*()> is a space separated list of
66294147the login names of the members of the group.
66304148
66314149=end original
66324150
66334151I<getgr*()> によって返る値 $members は、グループのメンバの
66344152ログイン名をスペースで区切ったものです。
66354153
66364154=begin original
66374155
66384156For the I<gethost*()> functions, if the C<h_errno> variable is supported in
6639C, it will be returned to you via L<C<$?>|perlvar/$?> if the function
4157C, it will be returned to you via C<$?> if the function call fails. The
6640call fails. The
4158C<@addrs> value returned by a successful call is a list of the raw
6641C<@addrs> value returned by a successful call is a list of raw
4159addresses returned by the corresponding system library call. In the
6642addresses returned by the corresponding library call. In the
4160Internet domain, each address is four bytes long and you can unpack it
6643Internet domain, each address is four bytes long; you can unpack it
66444161by saying something like:
66454162
4163 ($a,$b,$c,$d) = unpack('C4',$addr[0]);
4164
66464165=end original
66474166
66484167I<gethost*()> 関数では、C で C<h_errno> 変数がサポートされていれば、
6649関数呼出が失敗したときに、L<C<$?>|perlvar/$?> を通して、その値が返されます。
4168関数呼出が失敗したときに、C<$?> を通して、その値が返されます。
66504169成功時に返される C<@addrs> 値は、対応するシステムコールが返す、
66514170生のアドレスのリストです。
6652インターネットドメインでは、個々のアドレスは、4 バイト長です;
4171インターネットドメインでは、個々のアドレスは、4 バイト長で
6653以下のようにして unpack することができます:
4172以下のようにして unpack することができます
66544173
6655 my ($w,$x,$y,$z) = unpack('W4',$addr[0]);
4174 ($a,$b,$c,$d) = unpack('C4',$addr[0]);
66564175
66574176=begin original
66584177
66594178The Socket library makes this slightly easier:
66604179
66614180=end original
66624181
66634182Socket ライブラリを使うともう少し簡単になります。
66644183
66654184 use Socket;
6666 my $iaddr = inet_aton("127.1"); # or whatever address
4185 $iaddr = inet_aton("127.1"); # or whatever address
6667 my $name = gethostbyaddr($iaddr, AF_INET);
4186 $name = gethostbyaddr($iaddr, AF_INET);
66684187
66694188 # or going the other way
6670 my $straddr = inet_ntoa($iaddr);
4189 $straddr = inet_ntoa($iaddr);
66714190
66724191=begin original
66734192
6674In the opposite way, to resolve a hostname to the IP address
6675you can write this:
6676
6677=end original
6678
6679逆方向に、ホスト名から IP アドレスを解決するには以下のように書けます:
6680
6681 use Socket;
6682 my $packed_ip = gethostbyname("www.perl.org");
6683 my $ip_address;
6684 if (defined $packed_ip) {
6685 $ip_address = inet_ntoa($packed_ip);
6686 }
6687
6688=begin original
6689
6690Make sure L<C<gethostbyname>|/gethostbyname NAME> is called in SCALAR
6691context and that its return value is checked for definedness.
6692
6693=end original
6694
6695L<C<gethostbyname>|/gethostbyname NAME> はスカラコンテキストで
6696呼び出すようにして、返り値が定義されているかを必ずチェックしてください。
6697
6698=begin original
6699
6700The L<C<getprotobynumber>|/getprotobynumber NUMBER> function, even
6701though it only takes one argument, has the precedence of a list
6702operator, so beware:
6703
6704=end original
6705
6706L<C<getprotobynumber>|/getprotobynumber NUMBER> 関数は、一つの引数しか
6707取らないにも関わらず、リスト演算子の優先順位を持ちます; 従って
6708注意してください:
6709
6710 getprotobynumber $number eq 'icmp' # WRONG
6711 getprotobynumber($number eq 'icmp') # actually means this
6712 getprotobynumber($number) eq 'icmp' # better this way
6713
6714=begin original
6715
67164193If you get tired of remembering which element of the return list
6717contains which return value, by-name interfaces are provided in standard
4194contains which return value, by-name interfaces are provided
6718modules: L<C<File::stat>|File::stat>, L<C<Net::hostent>|Net::hostent>,
4195in standard modules: C<File::stat>, C<Net::hostent>, C<Net::netent>,
6719L<C<Net::netent>|Net::netent>, L<C<Net::protoent>|Net::protoent>,
4196C<Net::protoent>, C<Net::servent>, C<Time::gmtime>, C<Time::localtime>,
6720L<C<Net::servent>|Net::servent>, L<C<Time::gmtime>|Time::gmtime>,
4197and C<User::grent>. These override the normal built-ins, supplying
6721L<C<Time::localtime>|Time::localtime>, and
4198versions that return objects with the appropriate names
6722L<C<User::grent>|User::grent>. These override the normal built-ins,
4199for each field. For example:
6723supplying versions that return objects with the appropriate names for
6724each field. For example:
67254200
67264201=end original
67274202
67284203返り値のリストの何番目がどの要素かを覚えるのに疲れたなら、
67294204名前ベースのインターフェースが標準モジュールで提供されています:
6730L<C<File::stat>|File::stat>, L<C<Net::hostent>|Net::hostent>,
4205C<File::stat>, C<Net::hostent>, C<Net::netent>,
6731L<C<Net::netent>|Net::netent>, L<C<Net::protoent>|Net::protoent>,
4206C<Net::protoent>, C<Net::servent>, C<Time::gmtime>, C<Time::localtime>,
6732L<C<Net::servent>|Net::servent>, L<C<Time::gmtime>|Time::gmtime>,
4207C<User::grent> です。
6733L<C<Time::localtime>|Time::localtime>,
6734L<C<User::grent>|User::grent> です。
67354208これらは通常の組み込みを上書きし、
67364209それぞれのフィールドに適切な名前をつけたオブジェクトを返します。
6737えば:
4210例:
67384211
67394212 use File::stat;
67404213 use User::pwent;
6741 my $is_his = (stat($filename)->uid == pwent($whoever)->uid);
4214 $is_his = (stat($filename)->uid == pwent($whoever)->uid);
67424215
67434216=begin original
67444217
6745Even though it looks as though they're the same method calls (uid),
4218Even though it looks like they're the same method calls (uid),
6746they aren't, because a C<File::stat> object is different from
4219they aren't, because a C<File::stat> object is different from
67474220a C<User::pwent> object.
67484221
67494222=end original
67504223
6751同じメソッド(uid)を呼び出しているように見えますが、違います;
4224同じメソッド(uid)を呼び出しているように見えますが、違います
67524225なぜなら C<File::stat> オブジェクトは C<User::pwent> オブジェクトとは
67534226異なるからです。
67544227
6755=begin original
6756
6757Many of these functions are not safe in a multi-threaded environment
6758where more than one thread can be using them. In particular, functions
6759like C<getpwent()> iterate per-process and not per-thread, so if two
6760threads are simultaneously iterating, neither will get all the records.
6761
6762=end original
6763
6764これらの関数の多くは、複数のスレッドがこれらを使うような
6765マルチスレッド環境では安全ではありません。
6766特に、
6767C<getpwent()> のような関数はスレッド単位ではなくプロセス単位で
6768反復するので、二つのスレッドが同時に反復すると、
6769どちらも全てのレコードを得られません。
6770
6771=begin original
6772
6773Some systems have thread-safe versions of some of the functions, such as
6774C<getpwnam_r()> instead of C<getpwnam()>. There, Perl automatically and
6775invisibly substitutes the thread-safe version, without notice. This
6776means that code that safely runs on some systems can fail on others that
6777lack the thread-safe versions.
6778
6779=end original
6780
6781一部のシステムは、
6782C<getpwnam()> の代わりの C<getpwnam_r()> のように、一部の関数について
6783スレッドセーフ版を持っています。
6784その場合、Perl は自動的かつ目に見えないように、通知なしで
6785スレッドセーフ版に置き換えます。
6786つまり、一部のシステムで安全に実行できるコードが
6787スレッドセーフ版のないその他のシステムでは失敗することがあるということです。
6788
6789=begin original
6790
6791Portability issues: L<perlport/getpwnam> to L<perlport/endservent>.
6792
6793=end original
6794
6795移植性の問題: L<perlport/getpwnam> から L<perlport/endservent>。
6796
67974228=item getsockname SOCKET
6798X<getsockname>
67994229
6800=for Pod::Functions retrieve the sockaddr for a given socket
6801
68024230=begin original
68034231
68044232Returns the packed sockaddr address of this end of the SOCKET connection,
68054233in case you don't know the address because you have several different
68064234IPs that the connection might have come in on.
68074235
68084236=end original
68094237
6810SOCKET 接続のこちら側の pack された sockaddr アドレスを返します;
4238SOCKET 接続のこちら側の pack された sockaddr アドレスを返します
68114239複数の異なる IP から接続されるためにアドレスがわからない場合に使います。
68124240
68134241 use Socket;
6814 my $mysockaddr = getsockname($sock);
4242 $mysockaddr = getsockname(SOCK);
6815 my ($port, $myaddr) = sockaddr_in($mysockaddr);
4243 ($port, $myaddr) = sockaddr_in($mysockaddr);
6816 printf "Connect to %s [%s]\n",
4244 printf "Connect to %s [%s]\n",
68174245 scalar gethostbyaddr($myaddr, AF_INET),
68184246 inet_ntoa($myaddr);
68194247
68204248=item getsockopt SOCKET,LEVEL,OPTNAME
6821X<getsockopt>
68224249
6823=for Pod::Functions get socket options on a given socket
6824
68254250=begin original
68264251
6827Queries the option named OPTNAME associated with SOCKET at a given LEVEL.
4252Returns the socket option requested, or undef if there is an error.
6828Options may exist at multiple protocol levels depending on the socket
6829type, but at least the uppermost socket level SOL_SOCKET (defined in the
6830L<C<Socket>|Socket> module) will exist. To query options at another
6831level the protocol number of the appropriate protocol controlling the
6832option should be supplied. For example, to indicate that an option is
6833to be interpreted by the TCP protocol, LEVEL should be set to the
6834protocol number of TCP, which you can get using
6835L<C<getprotobyname>|/getprotobyname NAME>.
68364253
68374254=end original
68384255
6839与えられた LEVEL で SOCKET に関連付けられた OPTNAME と言う名前のオプションを
4256要求されたソケットオプションを返し、
6840問いわせます。
4257エラーの場には undef を返します。
6841オプションはソケットの種類に依存しした複数のプロトコルレベルに存在することも
6842ありますが、少なくとも最上位ソケットレベル SOL_SOCKET
6843(L<C<Socket>|Socket> モジュールで定義されています)は存在します。
6844その他のレベルのオプションを問い合わせるには、そのオプションを制御する
6845適切なプロトコルのプロトコル番号を指定します。
6846例えば、オプションが TCP プロトコルで解釈されるべきであることを示すためには、
6847LEVEL は L<C<getprotobyname>|/getprotobyname NAME> で得られる TCP の
6848プロトコル番号を設定します。
68494258
4259=item glob EXPR
4260
4261=item glob
4262
68504263=begin original
68514264
6852The function returns a packed string representing the requested socket
4265Returns the value of EXPR with filename expansions such as the
6853option, or L<C<undef>|/undef EXPR> on error, with the reason for the
4266standard Unix shell F</bin/csh> would do. This is the internal function
6854error placed in L<C<$!>|perlvar/$!>. Just what is in the packed string
4267implementing the C<< <*.c> >> operator, but you can use it directly.
6855depends on LEVEL and OPTNAME; consult L<getsockopt(2)> for details. A
4268If EXPR is omitted, C<$_> is used. The C<< <*.c> >> operator is
6856common case is that the option is an integer, in which case the result
4269discussed in more detail in L<perlop/"I/O Operators">.
6857is a packed integer, which you can decode using
6858L<C<unpack>|/unpack TEMPLATE,EXPR> with the C<i> (or C<I>) format.
68594270
68604271=end original
68614272
6862関数は要求されたソケットオプョンの pack された文字列表現か
4273EXPR 値を標準 Unix ェル F</bin/csh> が行なうように
6863あるいはエラー場合は L<C<undef>|/undef EXPR> を返し、エラーの理由は
4274ファイル名展開行なって返します。
6864L<C<$!>|perlvar/$!> にありま
4275これは、C<< <*.c> >> 演算子を実装る内部関数ですが、
6865pack された文字列の中身は LEVEL OPTNAME に依存します;
4276直接使用するこもできます
6866詳細については L<getsockopt(2)> を確認してください
4277EXPR を省略すると、C<$_>が使われます
6867一般的な場合はオプションが整数の場合で、この場合結果
4278C<< <*.c> >>演算子について
6868L<C<unpack>|/unpack TEMPLATE,EXPR> の C<i>
4279L<perlop/"I/O Operators"> でより詳細に議論しています。
6869(あるいは C<I>)フォーマットでデコードできる pack された整数です。
68704280
68714281=begin original
68724282
6873Here's an example to test whether Nagle's algorithm is enabled on a socket:
4283Beginning with v5.6.0, this operator is implemented using the standard
4284C<File::Glob> extension. See L<File::Glob> for details.
68744285
68754286=end original
68764287
6877あるソケットで Nagle のアルゴリズム有効かどうか調べる例です:
4288v5.6.0 から、この演算子は標準の C<File::Glob> 拡張使って
4289実装されています。
4290詳細は L<File::Glob> を参照して下さい。
68784291
6879 use Socket qw(:all);
4292=item gmtime EXPR
68804293
6881 defined(my $tcp = getprotobyname("tcp"))
6882 or die "Could not determine the protocol number for tcp";
6883 # my $tcp = IPPROTO_TCP; # Alternative
6884 my $packed = getsockopt($socket, $tcp, TCP_NODELAY)
6885 or die "getsockopt TCP_NODELAY: $!";
6886 my $nodelay = unpack("I", $packed);
6887 print "Nagle's algorithm is turned ",
6888 $nodelay ? "off\n" : "on\n";
6889
68904294=begin original
68914295
6892Portability issues: L<perlport/getsockopt>.
4296Converts a time as returned by the time function to a 8-element list
4297with the time localized for the standard Greenwich time zone.
4298Typically used as follows:
68934299
68944300=end original
68954301
6896移植性の問題: L<perlport/getsockopt>。
4302time 関数が返す時刻を、グリニッジタイムゾーンで測った時刻として、
43038 要素のリストに変換します。
4304通常は、以下のようにして使用します:
68974305
6898=item glob EXPR
4306 # 0 1 2 3 4 5 6 7
6899X<glob> X<wildcard> X<filename, expansion> X<expand>
4307 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =
4308 gmtime(time);
69004309
6901=item glob
6902
6903=for Pod::Functions expand filenames using wildcards
6904
69054310=begin original
69064311
6907In list context, returns a (possibly empty) list of filename expansions on
4312All list elements are numeric, and come straight out of the C `struct
6908the value of EXPR such as the standard Unix shell F</bin/csh> would do. In
4313tm'. $sec, $min, and $hour are the seconds, minutes, and hours of the
6909scalar context, glob iterates through such filename expansions, returning
4314specified time. $mday is the day of the month, and $mon is the month
6910undef when the list is exhausted. This is the internal function
4315itself, in the range C<0..11> with 0 indicating January and 11
6911implementing the C<< <*.c> >> operator, but you can use it directly. If
4316indicating December. $year is the number of years since 1900. That
6912EXPR is omitted, L<C<$_>|perlvar/$_> is used. The C<< <*.c> >> operator
4317is, $year is C<123> in year 2023. $wday is the day of the week, with
6913is discussed in more detail in L<perlop/"I/O Operators">.
43180 indicating Sunday and 3 indicating Wednesday. $yday is the day of
4319the year, in the range C<0..364> (or C<0..365> in leap years.)
69144320
69154321=end original
69164322
6917リストコンテキストでは、
4323すべてのリスト要素数値でC の `struct tm' 構造体から
6918EXPR の値を、標準 Unix シェル F</bin/csh> が行なうように
4324直接持ってきます。
6919ファイル名の展開を行なっ結果リスト(空かもしれません)を返します。
4325$sec, $min, $hour は指定され時刻秒、分、時です。
6920スカラコンテキストでは、globようなファイル名展開を繰り返し、
4326$mday 月の何日目か$mon値です。
6921リストなくなったら undef を返します。
4327月の値は C<0..11> で、0 1 月、11 が 12 月です。
6922これ、C<< <*.c> >> 演算子を実装する内部関数ですが、
4328$year 1900 年からの年数です
6923直接使用することもできます。
4329り、$year が C<123> なら 2023 年です。
6924EXPR省略されるとL<C<$_>|perlvar/$_>使われます。
4330$wday は曜日で、0 日曜日3水曜日です。
6925C<< <*.c> >>演算子については
4331$yday はその年の何日目かで、C<0..364> の値を取ります
6926L<perlop/"I/O Operators"> でより詳細に議論しています。
4332(うるう年は C<0..365> です)
69274333
69284334=begin original
69294335
6930Note that L<C<glob>|/glob EXPR> splits its arguments on whitespace and
4336Note that the $year element is I<not> simply the last two digits of
6931treats
4337the year. If you assume it is, then you create non-Y2K-compliant
6932each segment as separate pattern. As such, C<glob("*.c *.h")>
4338programs--and you wouldn't want to do that, would you?
6933matches all files with a F<.c> or F<.h> extension. The expression
6934C<glob(".* *")> matches all files in the current working directory.
6935If you want to glob filenames that might contain whitespace, you'll
6936have to use extra quotes around the spacey filename to protect it.
6937For example, to glob filenames that have an C<e> followed by a space
6938followed by an C<f>, use one of:
69394339
69404340=end original
69414341
6942L<C<glob>|/glob EXPR> 引数空白分割して、それぞれを分割れた
4342$year 要素単純に年の下 2 桁返す I<のはない> ことに注意してくだい。
6943パターンとしています
4343そう仮定ししまうと、Y2K 準拠でなプログラムを作ってしいま--
6944従って、C<glob("*.c *.h")> F<.c> まは F<.h> 拡張子を持つ全てのファイルに
4344そうくないでしょう?
6945マッチングします。
6946式 C<glob(".* *")> はカレントワーキングディレクトリの全てのファイルに
6947マッチングします。
6948空白を含んでいるかも知れないファイル名をグロブしたい場合、それを守るために
6949空白入りファイル名の周りに追加のクォートを使う必要があります。
6950例えば、C<e> の後に空白、その後に C<f> というファイル名をグロブするには
6951以下の一つを使います:
69524345
6953 my @spacies = <"*e f*">;
6954 my @spacies = glob '"*e f*"';
6955 my @spacies = glob q("*e f*");
6956
69574346=begin original
69584347
6959If you had to get a variable through, you could do this:
4348The proper way to get a complete 4-digit year is simply:
69604349
69614350=end original
69624351
6963変数を通す必要があった場合、以下ようにできま:
4352完全な 4 桁年を得る正い方法は単純です:
69644353
6965 my @spacies = glob "'*${var}e f*'";
4354 $year += 1900;
6966 my @spacies = glob qq("*${var}e f*");
69674355
69684356=begin original
69694357
6970If non-empty braces are the only wildcard characters used in the
4358And to get the last two digits of the year (e.g., '01' in 2001) do:
6971L<C<glob>|/glob EXPR>, no filenames are matched, but potentially many
6972strings are returned. For example, this produces nine strings, one for
6973each pairing of fruits and colors:
69744359
69754360=end original
69764361
6977空でない中かっこが L<C<glob>|/glob EXPR> で使われてい唯一
4362そして年の下 2 桁(2001 年なら '01')を得には次ようにします:
6978ワイルドカード文字列の場合、ファイル名とはマッチングせず、
6979可能性のある文字列が返されます。
6980例えば、これは 9 個の文字列を生成し、それぞれは果物と色の組み合わせに
6981なります:
69824363
6983 my @many = glob "{apple,tomato,cherry}={green,yellow,red}";
4364 $year = sprintf("%02d", $year % 100);
69844365
69854366=begin original
69864367
6987This operator is implemented using the standard C<File::Glob> extension.
4368If EXPR is omitted, C<gmtime()> uses the current time (C<gmtime(time)>).
6988See L<File::Glob> for details, including
6989L<C<bsd_glob>|File::Glob/C<bsd_glob>>, which does not treat whitespace
6990as a pattern separator.
69914369
69924370=end original
69934371
6994v5.6.0 からこの演算子は標準の C<File::Glob> 拡張を使って
4372EXPR が省略されると、C<gmtime()> は現在の時刻を使います (C<gmtime(time)>)。
6995実装されています。
6996空白をパターンのセパレータとして扱わない
6997L<C<bsd_glob>|File::Glob/C<bsd_glob>> を含めた
6998詳細は L<File::Glob> を参照してください。
69994373
70004374=begin original
70014375
7002If a C<glob> expression is used as the condition of a C<while> or C<for>
4376In scalar context, C<gmtime()> returns the ctime(3) value:
7003loop, then it will be implicitly assigned to C<$_>. If either a C<glob>
7004expression or an explicit assignment of a C<glob> expression to a scalar
7005is used as a C<while>/C<for> condition, then the condition actually
7006tests for definedness of the expression's value, not for its regular
7007truth value.
70084377
70094378=end original
70104379
7011C<glob> 式が C<while> や C<for> ループ条件とて使われた場合、
4380スカラコンテキストでは、C<gmtime()> ctime(3)値を返ます:
7012これは暗黙に C<$_> に代入されます。
7013C<glob> 式または C<glob> 式からスカラへの明示的な代入が
7014C<while>/C<for> の条件部として使われた場合、
7015条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを
7016テストします。
70174381
7018=begin original
4382 $now_string = gmtime; # e.g., "Thu Oct 13 04:54:34 1994"
70194383
7020Portability issues: L<perlport/glob>.
7021
7022=end original
7023
7024移植性の問題: L<perlport/glob>。
7025
7026=item gmtime EXPR
7027X<gmtime> X<UTC> X<Greenwich>
7028
7029=item gmtime
7030
7031=for Pod::Functions convert UNIX time into record or string using Greenwich time
7032
70334384=begin original
70344385
7035Works just like L<C<localtime>|/localtime EXPR> but the returned values
4386Also see the C<timegm> function provided by the C<Time::Local> module,
7036are localized for the standard Greenwich time zone.
4387and the strftime(3) function available via the POSIX module.
70374388
70384389=end original
70394390
7040L<C<localtime>|/localtime EXPR> と同様に働きますが、返り値はグリニッジ標準時に
4391C<Time::Local> で提供されている C<timegm> 関数も参照して下さい。
7041ローカライズされています。
4392た、POSIX モジュールで strftime(3) 関数が利用可能です。
70424393
70434394=begin original
70444395
7045Note: When called in list context, $isdst, the last value
4396This scalar value is B<not> locale dependent (see L<perllocale>), but
7046returned by gmtime, is always C<0>. There is no
4397is instead a Perl builtin. Also see the C<Time::Local> module, and the
7047Daylight Saving Time in GMT.
4398strftime(3) and mktime(3) functions available via the POSIX module. To
4399get somewhat similar but locale dependent date strings, set up your
4400locale environment variables appropriately (please see L<perllocale>)
4401and try for example:
70484402
70494403=end original
70504404
7051注意: リトコンテキスト呼び出した時、gmtime が返す末尾の値である
4405このカラ値はロケール依存 B<はなく> (L<perllocale> を参照してください)、
7052$isdst は常に C<0> です。
4406Perl 組み込み機能です。
7053GMT には夏時間はありません。
4407ロケール依存で似たような日付文字列を得るには、ロケール環境変数を
4408適切に設定(L<perllocale> を参照してください)した上で、
4409以下の例を試してください:
70544410
4411 use POSIX qw(strftime);
4412 $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime;
4413
70554414=begin original
70564415
7057Portability issues: L<perlport/gmtime>.
4416Note that the C<%a> and C<%b> escapes, which represent the short forms
4417of the day of the week and the month of the year, may not necessarily
4418be three characters wide in all locales.
70584419
70594420=end original
70604421
7061移植性の問題: L<perlport/gmtime>
4422C<%a> と C<%b>、つまり曜日と月の短い表現は全てのロケールで 3 文字であるとは
4423限らないことに注意してください。
70624424
70634425=item goto LABEL
7064X<goto> X<jump> X<jmp>
70654426
70664427=item goto EXPR
70674428
70684429=item goto &NAME
70694430
7070=for Pod::Functions create spaghetti code
7071
70724431=begin original
70734432
7074The C<goto LABEL> form finds the statement labeled with LABEL and
4433The C<goto-LABEL> form finds the statement labeled with LABEL and resumes
7075resumes execution there. It can't be used to get out of a block or
4434execution there. It may not be used to go into any construct that
7076subroutine given to L<C<sort>|/sort SUBNAME LIST>. It can be used to go
4435requires initialization, such as a subroutine or a C<foreach> loop. It
7077almost anywhere else within the dynamic scope, including out of
4436also can't be used to go into a construct that is optimized away,
7078subroutines, but it's usually better to use some other construct such as
4437or to get out of a block or subroutine given to C<sort>.
7079L<C<last>|/last LABEL> or L<C<die>|/die LIST>. The author of Perl has
4438It can be used to go almost anywhere else within the dynamic scope,
7080never felt the need to use this form of L<C<goto>|/goto LABEL> (in Perl,
4439including out of subroutines, but it's usually better to use some other
7081that is; C is another matter). (The difference is that C does not offer
4440construct such as C<last> or C<die>. The author of Perl has never felt the
7082named loops combined with loop control. Perl does, and this replaces
4441need to use this form of C<goto> (in Perl, that is--C is another matter).
7083most structured uses of L<C<goto>|/goto LABEL> in other languages.)
70844442
70854443=end original
70864444
7087C<goto LABEL> の形式は、LABEL というラベルの付いた文を
4445C<goto-LABEL> の形式は、LABEL というラベルの付いた文を
7088探して、そこへ実行を移すものです。
4446探して、そこへ実行を移すものです。 サブルーチンや
7089L<C<sort>|/sort SUBNAME LIST> で与えられたブロックやサブルーチンか外へ
4447C<foreach> ループなど、何かの初期化が必要な構造の中に
7090出ることはできません。
4448入り込むことは許されません。 最適化によってなくなってしまう構造の中にも
4449goto することはできません。
4450また、C<sort>で与えられたブロックやサブルーチンから外へ出ることもできません。
70914451これ以外は、サブルーチンの外を含む、動的スコープ内の
70924452ほとんどすべての場所へ行くために使用できますが、普通は、
7093L<C<last>|/last LABEL> L<C<die>|/die LIST> といった別の構造を使った方が
4453C<last> や C<die> といった別の構造を使った方が良いでしょう。
7094良いでしょ
4454Perl の作者はこの形式の C<goto> を使必要を感じたことは、
7095Perl の作者この形式の L<C<goto>|/goto LABEL> を使う必要を感じたこと
44551 度もありません (Perl C は別のお話です)。
70961 度もありません (Perl では; C は別のお話です)。
7097(違いは、C にはループ制御と結びついた名前つきのループがないことです。
7098Perl にはあり、これが他の言語でのほとんどの構造的な L<C<goto>|/goto LABEL> の
7099使用法を置き換えます。)
71004456
71014457=begin original
71024458
7103The C<goto EXPR> form expects to evaluate C<EXPR> to a code reference or
4459The C<goto-EXPR> form expects a label name, whose scope will be resolved
7104a label name. If it evaluates to a code reference, it will be handled
4460dynamically. This allows for computed C<goto>s per FORTRAN, but isn't
7105like C<goto &NAME>, below. This is especially useful for implementing
4461necessarily recommended if you're optimizing for maintainability:
7106tail recursion via C<goto __SUB__>.
71074462
71084463=end original
71094464
7110C<goto EXPR> の形式は、C<EXPR> をコードリファレンスまたはラベル名
4465C<goto-EXPR> の形式はラベル名を予測、このスコープは動的に解決されます。
7111評価するとを想定します
4466れにより FORTRAN のような算術 C<goto> が可能になりますが、
7112コードリファレンスとして評価する場合、後述する C<goto &NAME> のように
7113扱います。
7114これは特に、C<goto __SUB__> による末尾再帰の実装に有用です。
7115
7116=begin original
7117
7118If the expression evaluates to a label name, its scope will be resolved
7119dynamically. This allows for computed L<C<goto>|/goto LABEL>s per
7120FORTRAN, but isn't necessarily recommended if you're optimizing for
7121maintainability:
7122
7123=end original
7124
7125式がラベル名に評価される場合、このスコープは動的に解決されます。
7126これにより FORTRAN のような算術 L<C<goto>|/goto LABEL> が可能になりますが、
71274467保守性を重視するならお勧めしません。
71284468
71294469 goto ("FOO", "BAR", "GLARCH")[$i];
71304470
71314471=begin original
71324472
7133As shown in this example, C<goto EXPR> is exempt from the "looks like a
4473The C<goto-&NAME> form is quite different from the other forms of C<goto>.
7134function" rule. A pair of parentheses following it does not (necessarily)
4474In fact, it isn't a goto in the normal sense at all, and doesn't have
7135delimit its argument. C<goto("NE")."XT"> is equivalent to C<goto NEXT>.
4475the stigma associated with other gotos. Instead, it
7136Also, unlike most named operators, this has the same precedence as
4476substitutes a call to the named subroutine for the currently running
7137assignment.
4477subroutine. This is used by C<AUTOLOAD> subroutines that wish to load
4478another subroutine and then pretend that the other subroutine had been
4479called in the first place (except that any modifications to C<@_>
4480in the current subroutine are propagated to the other subroutine.)
4481After the C<goto>, not even C<caller> will be able to tell that this
4482routine was called first.
71384483
71394484=end original
71404485
7141この例で示したように、C<goto EXPR> は「関数ように見える」ルール
4486C<goto-&NAME> の形式、そ他の C<goto> の形式とはなり
7142除外されます。
7143これに引き続くかっこの組は引数の区切りとは(必ずしも)なりません。
7144C<goto("NE")."XT"> は C<goto NEXT> と等価です。
7145また、ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
7146
7147=begin original
7148
7149Use of C<goto LABEL> or C<goto EXPR> to jump into a construct is
7150deprecated and will issue a warning. Even then, it may not be used to
7151go into any construct that requires initialization, such as a
7152subroutine, a C<foreach> loop, or a C<given>
7153block. In general, it may not be used to jump into the parameter
7154of a binary or list operator, but it may be used to jump into the
7155I<first> parameter of a binary operator. (The C<=>
7156assignment operator's "first" operand is its right-hand
7157operand.) It also can't be used to go into a
7158construct that is optimized away.
7159
7160=end original
7161
7162構造の中に飛び込むために C<goto LABEL> や C<goto EXPR> を使うことは
7163非推奨で、警告が発生します。
7164それでも、サブルーチンや C<foreach> ループや C<given> ブロックのような、
7165初期化が必要な
7166構造の中に入るために使うことは出来ません。
7167一般的に、2 項演算子やリスト演算子の引数に飛び込むことはできませんが、
71682 項演算子の I<最初の> 引数に飛び込むために使われていました。
7169(C<=> 代入演算子の「最初の」オペランドはその右オペランドです。)
7170また、最適化してなくなってしまった構造の中へ入るために使うことも出来ません。
7171
7172=begin original
7173
7174The C<goto &NAME> form is quite different from the other forms of
7175L<C<goto>|/goto LABEL>. In fact, it isn't a goto in the normal sense at
7176all, and doesn't have the stigma associated with other gotos. Instead,
7177it exits the current subroutine (losing any changes set by
7178L<C<local>|/local EXPR>) and immediately calls in its place the named
7179subroutine using the current value of L<C<@_>|perlvar/@_>. This is used
7180by C<AUTOLOAD> subroutines that wish to load another subroutine and then
7181pretend that the other subroutine had been called in the first place
7182(except that any modifications to L<C<@_>|perlvar/@_> in the current
7183subroutine are propagated to the other subroutine.) After the
7184L<C<goto>|/goto LABEL>, not even L<C<caller>|/caller EXPR> will be able
7185to tell that this routine was called first.
7186
7187=end original
7188
7189C<goto &NAME> の形式は、その他の L<C<goto>|/goto LABEL> の形式とはかなり
71904487異なったものです。
71914488実際、これは普通の感覚でいうところのどこかへ行くものでは全くなく、
71924489他の goto が持つ不名誉を持っていません。
7193現在のサブルーチンを終了し (L<C<local>|/local EXPR> による変更は失わます)、
4490これは、実行中のサブルーチンを、NAME で指定さたサブルーチンの
7194直ちに現在の L<C<@_>|perlvar/@_> の値を使って指定された名前のサブルーチンを
4491呼び出しで置き換えます。
7195呼び出します。
71964492これは、C<AUTOLOAD> サブルーチンが別のサブルーチンをロードして、
71974493その別のサブルーチンが最初に呼ばれたようにするために使われます
7198(ただし、現在のサブルーチンで L<C<@_>|perlvar/@_> を修正した場合には、
4494(ただし、現在のサブルーチンで C<@_> を修正した場合には、
71994495その別のサブルーチンに伝えられます)。
7200L<C<goto>|/goto LABEL> のあとは、L<C<caller>|/caller EXPR> でさえも、現在の
4496C<goto> のあとは、C<caller> でさえも、現在のサブルーチンが
7201サブルーチンが最初に呼び出されたと言うことができません。
4497最初に呼び出されたと言うことができません。
72024498
72034499=begin original
72044500
72054501NAME needn't be the name of a subroutine; it can be a scalar variable
7206containing a code reference or a block that evaluates to a code
4502containing a code reference, or a block which evaluates to a code
72074503reference.
72084504
72094505=end original
72104506
72114507NAME はサブルーチンの名前である必要はありません; コードリファレンスを
72124508含むスカラ値や、コードリファレンスと評価されるブロックでも構いません。
72134509
72144510=item grep BLOCK LIST
7215X<grep>
72164511
72174512=item grep EXPR,LIST
72184513
7219=for Pod::Functions locate elements in a list test true against a given criterion
7220
72214514=begin original
72224515
7223This is similar in spirit to, but not the same as, L<grep(1)> and its
4516This is similar in spirit to, but not the same as, grep(1) and its
72244517relatives. In particular, it is not limited to using regular expressions.
72254518
72264519=end original
72274520
7228これは L<grep(1)> とその親類と同じようなものですが、同じではありません。
4521これは grep(1) とその親類と同じようなものですが、同じではありません。
72294522特に、正規表現の使用に制限されません。
72304523
72314524=begin original
72324525
72334526Evaluates the BLOCK or EXPR for each element of LIST (locally setting
7234L<C<$_>|perlvar/$_> to each element) and returns the list value
4527C<$_> to each element) and returns the list value consisting of those
7235consisting of those
72364528elements for which the expression evaluated to true. In scalar
72374529context, returns the number of times the expression was true.
72384530
72394531=end original
72404532
72414533LIST の個々の要素に対して、BLOCK か EXPR を評価し
7242(L<C<$_>|perlvar/$_> は、ローカルに個々の要素が設定されます) 、
4534(C<$_> は、ローカルに個々の要素が設定されます) 、
72434535その要素のうち、評価した式が真となったものからなるリスト値が返されます。
7244スカラコンテキストでは、式が真となった回数を返します。
4536スカラコンテキストでは、式が真となった回数を返します。 例:
72454537
7246 my @foo = grep(!/^#/, @bar); # weed out comments
4538 @foo = grep(!/^#/, @bar); # weed out comments
72474539
72484540=begin original
72494541
72504542or equivalently,
72514543
72524544=end original
72534545
72544546あるいは等価な例として:
72554547
7256 my @foo = grep {!/^#/} @bar; # weed out comments
4548 @foo = grep {!/^#/} @bar; # weed out comments
72574549
72584550=begin original
72594551
7260Note that L<C<$_>|perlvar/$_> is an alias to the list value, so it can
4552Note that C<$_> is an alias to the list value, so it can be used to
7261be used to
72624553modify the elements of the LIST. While this is useful and supported,
72634554it can cause bizarre results if the elements of LIST are not variables.
72644555Similarly, grep returns aliases into the original list, much as a for
72654556loop's index variable aliases the list elements. That is, modifying an
7266element of a list returned by grep (for example, in a C<foreach>,
4557element of a list returned by grep (for example, in a C<foreach>, C<map>
7267L<C<map>|/map BLOCK LIST> or another L<C<grep>|/grep BLOCK LIST>)
4558or another C<grep>) actually modifies the element in the original list.
7268actually modifies the element in the original list.
72694559This is usually something to be avoided when writing clear code.
72704560
72714561=end original
72724562
7273L<C<$_>|perlvar/$_> は、LIST の値へのエイリアスですので、LIST の要素を
4563C<$_> は、LIST の値へのエイリアスですので、LIST の要素を
72744564変更するために使うことができます。
72754565これは、便利でサポートされていますが、
72764566LIST の要素が変数でないと、おかしな結果になります。
7277同様に、grep は元のリストへのエイリアスを返します; for ループの
4567同様に、grep は元のリストへのエイリアスを返します
7278インデックス変数がリスト要素のエイリアスであるのと同様です。
4568for ループのインデックス変数がリスト要素のエイリアスであるのと
4569同様です。
72794570つまり、grep で返されたリストの要素を
7280(C<foreach>, L<C<map>|/map BLOCK LIST>, または他の
4571(C<foreach>, C<map>, または他の C<grep> で)修正すると
7281L<C<grep>|/grep BLOCK LIST> で)修正すると元のリストの要素が変更されます。
4572元のリストの要素が変更されます。
7282これはきれいなコードを書は普通は回避されます。
4573これはきれいなコードを書こうする邪魔なることが多いです。
72834574
72844575=begin original
72854576
7286See also L<C<map>|/map BLOCK LIST> for a list composed of the results of
4577See also L</map> for a list composed of the results of the BLOCK or EXPR.
7287the BLOCK or EXPR.
72884578
72894579=end original
72904580
7291BLOCK や EXPR の結果をリストの形にしたい場合は L<C<map>|/map BLOCK LIST> を
4581BLOCK や EXPR の結果をリストの形にしたい場合は L</map> を参照してください。
7292参照してください。
72934582
72944583=item hex EXPR
7295X<hex> X<hexadecimal>
72964584
72974585=item hex
72984586
7299=for Pod::Functions convert a hexadecimal string to a number
7300
73014587=begin original
73024588
7303Interprets EXPR as a hex string and returns the corresponding numeric value.
4589Interprets EXPR as a hex string and returns the corresponding value.
7304If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
4590(To convert strings that might start with either 0, 0x, or 0b, see
4591L</oct>.) If EXPR is omitted, uses C<$_>.
73054592
73064593=end original
73074594
7308EXPR を 16 進数の文字列と解釈して、対応する値を返します。
4595EXPR を 16 進数の文字列と解釈して、対応する値を返します。
7309EXPR が省略され、L<C<$_>|perlvar/$_> を使います。
4596(0, 0x, 0b で始ま文字列の変換には、L</oct> を
4597参照してください。)
4598EXPR が省略されると、C<$_> を使用します。
73104599
73114600 print hex '0xAf'; # prints '175'
73124601 print hex 'aF'; # same
7313 $valid_input =~ /\A(?:0?[xX])?(?:_?[0-9a-fA-F])*\z/
73144602
73154603=begin original
73164604
7317A hex string consists of hex digits and an optional C<0x> or C<x> prefix.
4605Hex strings may only represent integers. Strings that would cause
7318Each hex digit may be preceded by a single underscore, which will be ignored.
4606integer overflow trigger a warning.
7319Any other character triggers a warning and causes the rest of the string
7320to be ignored (even leading whitespace, unlike L<C<oct>|/oct EXPR>).
7321Only integers can be represented, and integer overflow triggers a warning.
73224607
73234608=end original
73244609
732516 進文字列は 16 進と、オプション C<0x> または C<x> 接頭辞からなります。
461016 進文字列は数のみを表現します。
7326それぞれの 16 進は一つの下線前に置くとがでれは無視されます。
4611オーバーフローすような文字列は警告を引ます。
7327その他の文字は警告を引き起こし、(例え先頭の空白でも、L<C<oct>|/oct EXPR> と
7328異なり)文字列の残りの部分は無視されます。
7329整数のみを表現でき、整数オーバーフローは警告を引き起こします。
73304612
7331=begin original
4613=item import
73324614
7333To convert strings that might start with any of C<0>, C<0x>, or C<0b>,
7334see L<C<oct>|/oct EXPR>. To present something as hex, look into
7335L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
7336L<C<sprintf>|/sprintf FORMAT, LIST>, and
7337L<C<unpack>|/unpack TEMPLATE,EXPR>.
7338
7339=end original
7340
7341C<0>, C<0x>, C<0b> のいずれかで始まるかもしれない文字列を変換するには、
7342L<C<oct>|/oct EXPR> を参照してください。
7343何かを 16 進で表現したい場合は、L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
7344L<C<sprintf>|/sprintf FORMAT, LIST>, L<C<unpack>|/unpack TEMPLATE,EXPR> を
7345参照してください。
7346
7347=item import LIST
7348X<import>
7349
7350=for Pod::Functions patch a module's namespace into your own
7351
73524615=begin original
73534616
7354There is no builtin L<C<import>|/import LIST> function. It is just an
4617There is no builtin C<import> function. It is just an ordinary
7355ordinary method (subroutine) defined (or inherited) by modules that wish
4618method (subroutine) defined (or inherited) by modules that wish to export
7356to export names to another module. The
4619names to another module. The C<use> function calls the C<import> method
7357L<C<use>|/use Module VERSION LIST> function calls the
4620for the package used. See also L</use>, L<perlmod>, and L<Exporter>.
7358L<C<import>|/import LIST> method for the package used. See also
7359L<C<use>|/use Module VERSION LIST>, L<perlmod>, and L<Exporter>.
73604621
73614622=end original
73624623
7363組み込みの L<C<import>|/import LIST> 関数というものはありません。
4625組み込みの C<import> 関数というものはありません。
73644626これは単に、別のモジュールに名前をエクスポートしたいモジュールが
73654627定義した(または継承した)、通常のメソッド(サブルーチン)です。
7366L<C<use>|/use Module VERSION LIST> 関数はパッケージを使う時に
4628C<use> 関数はパッケージを使う時に C<import> メソッドを呼び出します。
7367L<C<import>|/import LIST> メソッドを呼び出ます
4629L</use>, L<perlmod>, L<Exporter> も参照てください
7368L<C<use>|/use Module VERSION LIST>, L<perlmod>, L<Exporter> も
7369参照してください。
73704630
73714631=item index STR,SUBSTR,POSITION
7372X<index> X<indexOf> X<InStr>
73734632
73744633=item index STR,SUBSTR
73754634
7376=for Pod::Functions find a substring within a string
7377
73784635=begin original
73794636
73804637The index function searches for one string within another, but without
73814638the wildcard-like behavior of a full regular-expression pattern match.
73824639It returns the position of the first occurrence of SUBSTR in STR at
73834640or after POSITION. If POSITION is omitted, starts searching from the
7384beginning of the string. POSITION before the beginning of the string
4641beginning of the string. The return value is based at C<0> (or whatever
7385or after its end is treated as if it were the beginning or the end,
4642you've set the C<$[> variable to--but don't do that). If the substring
7386respectively. POSITION and the return value are based at zero.
4643is not found, returns one less than the base, ordinarily C<-1>.
7387If the substring is not found, L<C<index>|/index STR,SUBSTR,POSITION>
7388returns -1.
73894644
73904645=end original
73914646
73924647index 関数は ある文字列をもうひとつの文字列から検索しますが、
73934648完全正規表現パターンマッチのワイルドカード的な振る舞いはしません。
73944649STR の中の POSITION の位置以降で、最初に SUBSTR が見つかった位置を返します。
73954650POSITION が省略された場合には、STR の最初から探し始めます。
7396POSITION が文字列の先頭よあるい末尾より後ろを指定した場合は
4651値のベースはC<0> (もしく、変数 C<$[> に設定した値です -- しかし
7397ぞれ先頭と末尾を指定されたものとし扱われ
4652は使っはいけせん)
7398POSITION と返り値のベースは、0 です。
4653SUBSTR が見つからなかった場合には、ベースよりも 1 小さい値、
7399SUBSTR が見つからなかった場合に、L<C<index>|/index STR,SUBSTR,POSITION> は
4654通常 C<-1> が返されます。
7400-1 が返されます。
74014655
74024656=item int EXPR
7403X<int> X<integer> X<truncate> X<trunc> X<floor>
74044657
74054658=item int
74064659
7407=for Pod::Functions get the integer portion of a number
7408
74094660=begin original
74104661
7411Returns the integer portion of EXPR. If EXPR is omitted, uses
4662Returns the integer portion of EXPR. If EXPR is omitted, uses C<$_>.
7412L<C<$_>|perlvar/$_>.
74134663You should not use this function for rounding: one because it truncates
7414towards C<0>, and two because machine representations of floating-point
4664towards C<0>, and two because machine representations of floating point
74154665numbers can sometimes produce counterintuitive results. For example,
74164666C<int(-6.725/0.025)> produces -268 rather than the correct -269; that's
74174667because it's really more like -268.99999999999994315658 instead. Usually,
7418the L<C<sprintf>|/sprintf FORMAT, LIST>,
4668the C<sprintf>, C<printf>, or the C<POSIX::floor> and C<POSIX::ceil>
7419L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, or the
4669functions will serve you better than will int().
7420L<C<POSIX::floor>|POSIX/C<floor>> and L<C<POSIX::ceil>|POSIX/C<ceil>>
7421functions will serve you better than will L<C<int>|/int EXPR>.
74224670
74234671=end original
74244672
74254673EXPR の整数部を返します。
7426EXPR 省略されると、L<C<$_>|perlvar/$_> を使います。
4674EXPR 省略ると、C<$_> を使います。
7427この関数を丸めのために使うべきではありません: 第一の理由として C<0> の
4675この関数を丸めのために使うべきではありません
7428方向への切捨てを行うから、第二の理由として浮動小数点数の機械表現は時々直感に
4676第一の理由として C<0> の方向への切捨てを行うから、第二の理由として
7429反した結果を生み出すからです。
4677浮動小数点数の機械表現は時々直感に反した結果を生み出すからです。
7430たとえば、C<int(-6.725/0.025)> は正しい結果である -269 ではなく -268 を
4678たとえば、C<int(-6.725/0.025)> は正しい結果である -269 ではなく
7431返します: これは実際には -268.99999999999994315658 というような値に
4679-268 を返します。
7432なっているからです。
4680これは実際には -268.99999999999994315658 というような値になっているからです。
7433通常、L<C<sprintf>|/sprintf FORMAT, LIST>,
4681通常、C<sprintf>, C<printf>, C<POSIX::floor>, C<POSIX::ceil> の方が
7434L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
4682int() より便利です。
7435L<C<POSIX::floor>|POSIX/C<floor>>, L<C<POSIX::ceil>|POSIX/C<ceil>> の方が
7436L<C<int>|/int EXPR> より便利です。
74374683
74384684=item ioctl FILEHANDLE,FUNCTION,SCALAR
7439X<ioctl>
74404685
7441=for Pod::Functions system-dependent device control system call
7442
74434686=begin original
74444687
7445Implements the L<ioctl(2)> function. You'll probably first have to say
4688Implements the ioctl(2) function. You'll probably first have to say
74464689
74474690=end original
74484691
7449L<ioctl(2)> 関数を実装します。
4692ioctl(2) 関数を実装します。
74504693正しい関数の定義を得るために、おそらく最初に
74514694
7452 require "sys/ioctl.ph"; # probably in
4695 require "ioctl.ph"; # probably in /usr/local/lib/perl/ioctl.ph
7453 # $Config{archlib}/sys/ioctl.ph
74544696
74554697=begin original
74564698
7457to get the correct function definitions. If F<sys/ioctl.ph> doesn't
4699to get the correct function definitions. If F<ioctl.ph> doesn't
74584700exist or doesn't have the correct definitions you'll have to roll your
74594701own, based on your C header files such as F<< <sys/ioctl.h> >>.
74604702(There is a Perl script called B<h2ph> that comes with the Perl kit that
74614703may help you in this, but it's nontrivial.) SCALAR will be read and/or
7462written depending on the FUNCTION; a C pointer to the string value of SCALAR
4704written depending on the FUNCTION--a pointer to the string value of SCALAR
7463will be passed as the third argument of the actual
4705will be passed as the third argument of the actual C<ioctl> call. (If SCALAR
7464L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> call. (If SCALAR
74654706has no string value but does have a numeric value, that value will be
74664707passed rather than a pointer to the string value. To guarantee this to be
7467true, add a C<0> to the scalar before using it.) The
4708true, add a C<0> to the scalar before using it.) The C<pack> and C<unpack>
7468L<C<pack>|/pack TEMPLATE,LIST> and L<C<unpack>|/unpack TEMPLATE,EXPR>
74694709functions may be needed to manipulate the values of structures used by
7470L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>.
4710C<ioctl>.
74714711
74724712=end original
74734713
74744714としなくてはならないでしょう。
7475F<sys/ioctl.ph> がないか、間違った定義をしている場合には、
4715ioctl.h がないか、間違った定義をしている場合には、
7476F<< <sys/ioctl.h> >>のような C のヘッダファイルをもとに、
4716F<< <sys/ioctl.ph> >>のような C のヘッダファイルをもとに、
74774717自分で作らなければなりません。
7478(Perl の配布キットに入っている B<h2ph> という Perl スクリプトが
4718(Perl の配布キットに入っている B<h2ph> という
7479これを手助けしてくれるでしょうが、これは自明はありません。)
4719Perl スクリプトがこれを手助けしてくれるでしょうが、これは重要。)
7480FOUNCTION に応じて SCALAR が読み書きされます;
4720FOUNCTION に応じて SCALAR が読み書きされます
7481SCALAR の文字列値へのポインタが、実際の
4721SCALAR の文字列値へのポインタが、実際の C<ioctl> コールの
7482L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> コールの
748347223 番目の引数として渡されます。
74844723(SCALAR が文字列値を持っておらず、数値を持っている場合には、
74854724文字列値へのポインタの代わりに、その値が渡されます。
74864725このことを保証するためには、使用する前に SCALAR にC<0> を足してください。)
7487L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> で使われる構造体の値を
4726C<ioctl> で使われる構造体の値を操作するには、
7488操作するには、L<C<pack>|/pack TEMPLATE,LIST> 関数と
4727C<pack> 関数と C<unpack> 関数が必要なるでしょう。
7489L<C<unpack>|/unpack TEMPLATE,EXPR> 関数が必要となるでしょう。
74904728
74914729=begin original
74924730
7493The return value of L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> (and
4731The return value of C<ioctl> (and C<fcntl>) is as follows:
7494L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>) is as follows:
74954732
74964733=end original
74974734
7498L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>
4735C<ioctl> (と C<fcntl>) の返り値は、以下のようになります:
7499(と L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>) の返り値は、
7500以下のようになります:
75014736
75024737=begin original
75034738
7504 if OS returns: then Perl returns:
4739 if OS returns: then Perl returns:
7505 -1 undefined value
4740 -1 undefined value
7506 0 string "0 but true"
4741 0 string "0 but true"
7507 anything else that number
4742 anything else that number
75084743
75094744=end original
75104745
7511 OS が返した値: Perl が返す値:
4746 OS が返した値: Perl が返す値:
7512 -1 未定義値
4747 -1 未定義値
7513 0 「0 だが真」の文字列
4748 0 「0 だが真」の文字列
7514 その他 その値そのもの
4749 その他 その値そのもの
75154750
75164751=begin original
75174752
75184753Thus Perl returns true on success and false on failure, yet you can
75194754still easily determine the actual value returned by the operating
75204755system:
75214756
75224757=end original
75234758
75244759つまり Perl は、成功時に「真」、失敗時に「偽」を返す
75254760ことになり、OS が実際に返した値も、以下のように簡単に知ることができます。
75264761
7527 my $retval = ioctl(...) || -1;
4762 $retval = ioctl(...) || -1;
75284763 printf "System returned %d\n", $retval;
75294764
75304765=begin original
75314766
7532The special string C<"0 but true"> is exempt from
4767The special string "C<0> but true" is exempt from B<-w> complaints
7533L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s>
4768about improper numeric conversions.
7534L<warnings> on improper numeric conversions.
75354769
75364770=end original
75374771
75384772特別な文字列 C<"0 だが真"> は、不適切な数値変換に関する
7539L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s>
4773B<-w> 警告を回避します。
7540L<warnings> 警告を回避します。
75414774
75424775=begin original
75434776
7544Portability issues: L<perlport/ioctl>.
4777Here's an example of setting a filehandle named C<REMOTE> to be
4778non-blocking at the system level. You'll have to negotiate C<$|>
4779on your own, though.
75454780
75464781=end original
75474782
7548移植性の問題: L<perlport/ioctl>
4783これは C<REMOTE> というファイルハンドルをシステムレベルで
4784非ブロックモードにセットする例です。
4785ただし、 C<$|> を自分で管理しなければなりません。
75494786
7550=item join EXPR,LIST
4787 use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
7551X<join>
75524788
7553=for Pod::Functions join a list into a string using a separator
4789 $flags = fcntl(REMOTE, F_GETFL, 0)
4790 or die "Can't get flags for the socket: $!\n";
75544791
4792 $flags = fcntl(REMOTE, F_SETFL, $flags | O_NONBLOCK)
4793 or die "Can't set flags for the socket: $!\n";
4794
4795=item join EXPR,LIST
4796
75554797=begin original
75564798
75574799Joins the separate strings of LIST into a single string with fields
75584800separated by the value of EXPR, and returns that new string. Example:
75594801
75604802=end original
75614803
75624804LIST の個別の文字列を、EXPR の値で区切って
756348051 つの文字列につなげ、その文字列を返します。
75644806例:
75654807
7566 my $rec = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell);
4808 $rec = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell);
75674809
75684810=begin original
75694811
7570Beware that unlike L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>,
4812Beware that unlike C<split>, C<join> doesn't take a pattern as its
7571L<C<join>|/join EXPR,LIST> doesn't take a pattern as its first argument.
4813first argument. Compare L</split>.
7572Compare L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>.
75734814
75744815=end original
75754816
7576L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> と違って、
4817C<split> と違って、C<join> は最初の引数にパターンは取れないことに
7577L<C<join>|/join EXPR,LIST> は最初の引数にパターンは取れないことに
75784818注意してください。
7579L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> と比較してください。
4819L</split> と比較してください。
75804820
75814821=item keys HASH
7582X<keys> X<key>
75834822
7584=item keys ARRAY
7585
7586=for Pod::Functions retrieve list of indices from a hash
7587
75884823=begin original
75894824
7590Called in list context, returns a list consisting of all the keys of the
4825Returns a list consisting of all the keys of the named hash. (In
7591named hash, or in Perl 5.12 or later only, the indices of an array. Perl
4826scalar context, returns the number of keys.) The keys are returned in
7592releases prior to 5.12 will produce a syntax error if you try to use an
4827an apparently random order. The actual random order is subject to
7593array argument. In scalar context, returns the number of keys or indices.
4828change in future versions of perl, but it is guaranteed to be the same
4829order as either the C<values> or C<each> function produces (given
4830that the hash has not been modified). As a side effect, it resets
4831HASH's iterator.
75944832
75954833=end original
75964834
7597リストコンテキストで呼び出されると、指定したハッシュのすべてのキー、あいは
4835指定したハッシュのすべての key からな、リストを返します。
7598Perl 5.12 以降でのみ、配列のイデックからなるリストを返します。
4836(スカラコテキストでは、key の数を返します。)
75995.12 より前の Perl 配列引数を使おうすると文法エーを出力します。
4837キー見たころではンダムな順番に返されます。
7600スカテキストで、キやイデックスの数を返します。
4838実際のランダムな順番 perl の将来のバジョでは変わるかもせんが、
4839C<values> や C<each> 関数が同じ(変更されていない)ハッシュに対して
4840生成するのと同じ順番であることは保証されます。
4841副作用として、HASH の反復子を初期化します。
76014842
76024843=begin original
76034844
7604Hash entries are returned in an apparently random order. The actual random
7605order is specific to a given hash; the exact same series of operations
7606on two hashes may result in a different order for each hash. Any insertion
7607into the hash may change the order, as will any deletion, with the exception
7608that the most recent key returned by L<C<each>|/each HASH> or
7609L<C<keys>|/keys HASH> may be deleted without changing the order. So
7610long as a given hash is unmodified you may rely on
7611L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and L<C<each>|/each
7612HASH> to repeatedly return the same order
7613as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
7614details on why hash order is randomized. Aside from the guarantees
7615provided here the exact details of Perl's hash algorithm and the hash
7616traversal order are subject to change in any release of Perl. Tied hashes
7617may behave differently to Perl's hashes with respect to changes in order on
7618insertion and deletion of items.
7619
7620=end original
7621
7622ハッシュ要素は見かけ上、ランダムな順序で返されます。
7623実際のランダムな順序はハッシュに固有です; 二つのハッシュに全く同じ一連の
7624操作を行っても、ハッシュによって異なった順序になります。
7625ハッシュへの挿入によって順序が変わることがあります; 削除も同様ですが、
7626L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも
7627最近のキーは順序を変えることなく削除できます。
7628ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>,
7629L<C<each>|/each HASH> が繰り返し同じ順序で
7630返すことに依存してもかまいません。
7631なぜハッシュの順序がランダム化されているかの詳細については
7632L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。
7633ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の
7634正確な詳細は Perl のリリースによって変更される可能性があります。
7635tie されたハッシュは、アイテムの挿入と削除の順序に関して Perl のハッシュと
7636異なった振る舞いをします。
7637
7638=begin original
7639
7640As a side effect, calling L<C<keys>|/keys HASH> resets the internal
7641iterator of the HASH or ARRAY (see L<C<each>|/each HASH>) before
7642yielding the keys. In
7643particular, calling L<C<keys>|/keys HASH> in void context resets the
7644iterator with no other overhead.
7645
7646=end original
7647
7648副作用として、L<C<keys>|/keys HASH> の呼び出しは、
7649キーを取り出す前に HASH や ARRAY の反復子を
7650初期化します (L<C<each>|/each HASH> を参照してください)。
7651特に、無効コンテキストで L<C<keys>|/keys HASH> を呼び出すと
7652オーバーヘッドなしで反復子を初期化します。
7653
7654=begin original
7655
76564845Here is yet another way to print your environment:
76574846
76584847=end original
76594848
76604849環境変数を表示する別の例です:
76614850
7662 my @keys = keys %ENV;
4851 @keys = keys %ENV;
7663 my @values = values %ENV;
4852 @values = values %ENV;
7664 while (@keys) {
4853 while (@keys) {
7665 print pop(@keys), '=', pop(@values), "\n";
4854 print pop(@keys), '=', pop(@values), "\n";
76664855 }
76674856
76684857=begin original
76694858
76704859or how about sorted by key:
76714860
76724861=end original
76734862
76744863key でソートしてもいいでしょう:
76754864
7676 foreach my $key (sort(keys %ENV)) {
4865 foreach $key (sort(keys %ENV)) {
7677 print $key, '=', $ENV{$key}, "\n";
4866 print $key, '=', $ENV{$key}, "\n";
76784867 }
76794868
76804869=begin original
76814870
76824871The returned values are copies of the original keys in the hash, so
7683modifying them will not affect the original hash. Compare
4872modifying them will not affect the original hash. Compare L</values>.
7684L<C<values>|/values HASH>.
76854873
76864874=end original
76874875
76884876返される値はハッシュにある元のキーのコピーなので、
76894877これを変更しても元のハッシュには影響を与えません。
7690L<C<values>|/values HASH> と比較してください。
4878L</values> と比較してください。
76914879
76924880=begin original
76934881
7694To sort a hash by value, you'll need to use a
4882To sort a hash by value, you'll need to use a C<sort> function.
7695L<C<sort>|/sort SUBNAME LIST> function. Here's a descending numeric
4883Here's a descending numeric sort of a hash by its values:
7696sort of a hash by its values:
76974884
76984885=end original
76994886
7700ハッシュを値でソートするためには、L<C<sort>|/sort SUBNAME LIST> 関数を使う
4887ハッシュを値でソートするためには、C<sort> 関数を使う必要があります。
7701必要があります。
77024888以下ではハッシュの値を数値の降順でソートしています:
77034889
7704 foreach my $key (sort { $hash{$b} <=> $hash{$a} } keys %hash) {
4890 foreach $key (sort { $hash{$b} <=> $hash{$a} } keys %hash) {
7705 printf "%4d %s\n", $hash{$key}, $key;
4891 printf "%4d %s\n", $hash{$key}, $key;
77064892 }
77074893
77084894=begin original
77094895
7710Used as an lvalue, L<C<keys>|/keys HASH> allows you to increase the
4896As an lvalue C<keys> allows you to increase the number of hash buckets
7711number of hash buckets
77124897allocated for the given hash. This can gain you a measure of efficiency if
77134898you know the hash is going to get big. (This is similar to pre-extending
77144899an array by assigning a larger number to $#array.) If you say
77154900
77164901=end original
77174902
7718左辺値として使うことでL<C<keys>|/keys HASH> を使うことで与えられたハッシュに
4903左辺値として、C<keys> を使うことで与えられたハッシュに割り当てられた
7719割り当てられたハッシュ表の大きさを増やすことができます。
4904ハッシュ表の大きさを増やすことができます。
77204905これによって、ハッシュが大きくなっていくなっていくときの
7721効率の測定ができます。
4906効率の測定ができます。以下のようにすると:
7722(これは大きい値を $#array に代入することで配列を予め拡張することに
7723似ています。)
7724以下のようにすると:
77254907
77264908 keys %hash = 200;
77274909
77284910=begin original
77294911
77304912then C<%hash> will have at least 200 buckets allocated for it--256 of them,
77314913in fact, since it rounds up to the next power of two. These
77324914buckets will be retained even if you do C<%hash = ()>, use C<undef
77334915%hash> if you want to free the storage while C<%hash> is still in scope.
77344916You can't shrink the number of buckets allocated for the hash using
7735L<C<keys>|/keys HASH> in this way (but you needn't worry about doing
4917C<keys> in this way (but you needn't worry about doing this by accident,
7736this by accident, as trying has no effect). C<keys @array> in an lvalue
4918as trying has no effect).
7737context is a syntax error.
77384919
77394920=end original
77404921
7741C<%hash> は少なくとも 200 の大きさの表が割り当てられます --
4922C<%hash> は少なくとも 200 の大きさの表が割り当てられます --
77424923実際には 2 のべき乗に切り上げられるので、256 が割り当てられます。
77434924この表はたとえ C<%hash = ()> としても残るので、
77444925もし C<%hash> がスコープにいるうちにこの領域を開放したい場合は
77454926C<undef %hash> を使います。
7746この方法で L<C<keys>|/keys HASH> を使うことで、表の大きさを小さくすることは
4927この方法で C<keys> を使うことで、表の大きさを小さくすることはできません
7747できません
77484928(間違えてそのようなことをしても何も起きないので気にすることはありません)。
7749左辺値コンテキストでの C<keys @array> は文法エラーとなります。
77504929
77514930=begin original
77524931
7753Starting with Perl 5.14, an experimental feature allowed
4932See also C<each>, C<values> and C<sort>.
7754L<C<keys>|/keys HASH> to take a scalar expression. This experiment has
7755been deemed unsuccessful, and was removed as of Perl 5.24.
77564933
77574934=end original
77584935
7759Perl 5.14 から、L<C<keys>|/keys HASH> がスカラ式を取ることが出来ると
4936C<each>, C<values>, C<sort> も参照してくださ
7760実験的機能がありました。
7761この実験は失敗と見なされ、Perl 5.24 で削除されました。
77624937
7763=begin original
7764
7765To avoid confusing would-be users of your code who are running earlier
7766versions of Perl with mysterious syntax errors, put this sort of thing at
7767the top of your file to signal that your code will work I<only> on Perls of
7768a recent vintage:
7769
7770=end original
7771
7772あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
7773文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
7774I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
7775書いてください:
7776
7777 use 5.012; # so keys/values/each work on arrays
7778
7779=begin original
7780
7781See also L<C<each>|/each HASH>, L<C<values>|/values HASH>, and
7782L<C<sort>|/sort SUBNAME LIST>.
7783
7784=end original
7785
7786L<C<each>|/each HASH>, L<C<values>|/values HASH>,
7787L<C<sort>|/sort SUBNAME LIST> も参照してください。
7788
77894938=item kill SIGNAL, LIST
77904939
7791=item kill SIGNAL
7792X<kill> X<signal>
7793
7794=for Pod::Functions send a signal to a process or process group
7795
77964940=begin original
77974941
7798Sends a signal to a list of processes. Returns the number of arguments
4942Sends a signal to a list of processes. Returns the number of
7799that were successfully used to signal (which is not necessarily the same
4943processes successfully signaled (which is not necessarily the
7800as the number of processes actually killed, e.g. where a process group is
4944same as the number actually killed).
7801killed).
78024945
78034946=end original
78044947
7805プロセスのリストにシグナルを送ります。
4948プロセスのリストにシグナルを送ります。シグナル送信に成功したプロセスの
7806シグナル送信に使われた引数の数を返します
4949数を返します
7807(例えばプロセスグループが kill された場合のように、実際に kill され
4950(実際に kill に成功しプロセスと同じとは限りません)。
7808プロセスの数と同じとは限りません)。
78094951
7810 my $cnt = kill 'HUP', $child1, $child2;
4952 $cnt = kill 1, $child1, $child2;
7811 kill 'KILL', @goners;
4953 kill 9, @goners;
78124954
78134955=begin original
78144956
7815SIGNAL may be either a signal name (a string) or a signal number. A signal
4957If SIGNAL is zero, no signal is sent to the process. This is a
7816name may start with a C<SIG> prefix, thus C<FOO> and C<SIGFOO> refer to the
4958useful way to check that the process is alive and hasn't changed
7817same signal. The string form of SIGNAL is recommended for portability because
4959its UID. See L<perlport> for notes on the portability of this
7818the same signal may have different numbers in different operating systems.
4960construct.
78194961
78204962=end original
78214963
7822SIGNAL シグナル名(文字列)かシグナル番号のどちかです
4964SIGNAL がゼロの場合、プロセスにシグナルは送れません
7823シグナル名C<SIG> 接頭辞で始まることがあので、C<FOO> と C<SIGFOO> は同じ
4965これプロセスが生きていて、 UID が変わっていないことを調べ時に
7824シグナルを意味します。
4966有用です。
7825移植性から文字列形式の SIGNAL が推奨れます; 同じシグナルが異なった
4967この構成の移植性に関する注意については L<perlport> を参照して下い。
7826オペレーティングシステムでは異なった番号になることがあるからです。
78274968
78284969=begin original
78294970
7830A list of signal names supported by the current platform can be found in
4971Unlike in the shell, if SIGNAL is negative, it kills
7831C<$Config{sig_name}>, which is provided by the L<C<Config>|Config>
4972process groups instead of processes. (On System V, a negative I<PROCESS>
7832module. See L<Config> for more details.
4973number will also kill process groups, but that's not portable.) That
4974means you usually want to use positive not negative signals. You may also
4975use a signal name in quotes. See L<perlipc/"Signals"> for details.
78334976
78344977=end original
78354978
7836現在のプラットフォームが対応しているシグナル一覧はL<C<Config>|Config>
4979ェルとは異なり、シグナルに負数を与えると
7837モジュールによって提供される C<$Config{sig_name}> にあります。
7838さらなる詳細については L<Config> を参照してください。
7839
7840=begin original
7841
7842A negative signal name is the same as a negative signal number, killing process
7843groups instead of processes. For example, C<kill '-KILL', $pgrp> and
7844C<kill -9, $pgrp> will send C<SIGKILL> to
7845the entire process group specified. That
7846means you usually want to use positive not negative signals.
7847
7848=end original
7849
7850負のシグナル名は負のシグナル番号と同じで、
78514980プロセスではなくプロセスグループに対して kill を行ないます。
7852たとえば、C<kill '-KILL', $pgrp> と C<kill -9, $pgrp> 指定された
4981(Syetem V 、プロセス番号として負の値を与えても、
7853プロセスグループ全体に C<SIGKILL>送ります
4982プロセスグループ kill行ないますが、
4983移植性がありません。)
78544984すなわち、通常は、負のシグナルは用いず、正のシグナルを使うことになります。
4985シグナル名をクォートして使うこともできます。
4986詳細はL<perlipc/"Signals">を参照してください。
78554987
7856=begin original
7857
7858If SIGNAL is either the number 0 or the string C<ZERO> (or C<SIGZERO>),
7859no signal is sent to the process, but L<C<kill>|/kill SIGNAL, LIST>
7860checks whether it's I<possible> to send a signal to it
7861(that means, to be brief, that the process is owned by the same user, or we are
7862the super-user). This is useful to check that a child process is still
7863alive (even if only as a zombie) and hasn't changed its UID. See
7864L<perlport> for notes on the portability of this construct.
7865
7866=end original
7867
7868SIGNAL が数値 0 か文字列 C<ZERO> (または C<SIGZERO> の場合、プロセスに
7869シグナルは送られませんが、L<C<kill>|/kill SIGNAL, LIST> は、
7870シグナルを送ることが I<可能> かどうかを調べます (これは、簡単に言うと、
7871プロセスが同じユーザーに所有されているか、自分がスーパーユーザーであることを
7872意味します)。
7873これは子プロセスが(ゾンビとしてだけでも)まだ生きていて、 UID が
7874変わっていないことを調べる時に有用です。
7875この構成の移植性に関する注意については L<perlport> を参照してください。
7876
7877=begin original
7878
7879The behavior of kill when a I<PROCESS> number is zero or negative depends on
7880the operating system. For example, on POSIX-conforming systems, zero will
7881signal the current process group, -1 will signal all processes, and any
7882other negative PROCESS number will act as a negative signal number and
7883kill the entire process group specified.
7884
7885=end original
7886
7887I<PROCESS> 番号が 0 あるいは負数の場合の kill の振る舞いは
7888オペレーティングシステムに依存します。
7889例えば、POSIX 準拠のシステムでは、0 は現在のプロセスグループにシグナルを送り、
7890-1 は全てのプロセスにシグナルを送り、それ以外の負数の PROCESS 番号は
7891負数のシグナル番号として動作し、指定されたプロセスグループ全体を kill します。
7892
7893=begin original
7894
7895If both the SIGNAL and the PROCESS are negative, the results are undefined.
7896A warning may be produced in a future version.
7897
7898=end original
7899
7900SIGNAL と PROCESS の両方が負数の場合、結果は未定義です。
7901将来のバージョンでは警告が出るかも知れません。
7902
7903=begin original
7904
7905See L<perlipc/"Signals"> for more details.
7906
7907=end original
7908
7909詳細は L<perlipc/"Signals"> を参照してください。
7910
7911=begin original
7912
7913On some platforms such as Windows where the L<fork(2)> system call is not
7914available, Perl can be built to emulate L<C<fork>|/fork> at the
7915interpreter level.
7916This emulation has limitations related to kill that have to be considered,
7917for code running on Windows and in code intended to be portable.
7918
7919=end original
7920
7921Windows のような L<fork(2)> が利用不能なシステムでは、Perl は
7922L<C<fork>|/fork> をインタプリタレベルでエミュレートします。
7923エミュレーションは kill に関連して、コードが Windows で実行されて
7924しかしコードが移植性があると考えられるように制限があります。
7925
7926=begin original
7927
7928See L<perlfork> for more details.
7929
7930=end original
7931
7932さらなる詳細については L<perlfork> を参照してください。
7933
7934=begin original
7935
7936If there is no I<LIST> of processes, no signal is sent, and the return
7937value is 0. This form is sometimes used, however, because it causes
7938tainting checks to be run. But see
7939L<perlsec/Laundering and Detecting Tainted Data>.
7940
7941=end original
7942
7943処理する I<LIST> がない場合、シグナルは送られず、返り値は 0 です。
7944しかし、この形式は時々使われます; 実行するために汚染チェックを
7945引き起こすからです。
7946しかし L<perlsec/Laundering and Detecting Tainted Data> を参照してください。
7947
7948=begin original
7949
7950Portability issues: L<perlport/kill>.
7951
7952=end original
7953
7954移植性の問題: L<perlport/kill>。
7955
79564988=item last LABEL
7957X<last> X<break>
79584989
7959=item last EXPR
7960
79614990=item last
79624991
7963=for Pod::Functions exit a block prematurely
7964
79654992=begin original
79664993
7967The L<C<last>|/last LABEL> command is like the C<break> statement in C
4994The C<last> command is like the C<break> statement in C (as used in
7968(as used in
79694995loops); it immediately exits the loop in question. If the LABEL is
7970omitted, the command refers to the innermost enclosing
4996omitted, the command refers to the innermost enclosing loop. The
7971loop. The C<last EXPR> form, available starting in Perl
4997C<continue> block, if any, is not executed:
79725.18.0, allows a label name to be computed at run time,
7973and is otherwise identical to C<last LABEL>. The
7974L<C<continue>|/continue BLOCK> block, if any, is not executed:
79754998
79764999=end original
79775000
7978L<C<last>|/last LABEL> コマンドは、(ループ内で使った) C の C<break> 文と
5001C<last> コマンドは、(ループ内で使った) C の C<break> 文と
79795002同じようなもので、LABEL で指定されるループを即座に抜けます。
7980LABEL が省略されると、コマンドは一番内側のループを参照します。
5003LABEL が省略されると、一番内側のループが対象となります。
7981Perl 5.18.0 から利用可能な C<last EXPR> 形式では、実行時に計算され
5004C<continue> ブロックがあっても実行されません:
7982ラベル名を使えます; それ以外は C<last LABEL> と同一です。
7983L<C<continue>|/continue BLOCK> ブロックがあっても実行されません:
79845005
79855006 LINE: while (<STDIN>) {
7986 last LINE if /^$/; # exit when done with header
5007 last LINE if /^$/; # exit when done with header
7987 #...
5008 #...
79885009 }
79895010
79905011=begin original
79915012
7992L<C<last>|/last LABEL> cannot return a value from a block that typically
5013C<last> cannot be used to exit a block which returns a value such as
7993returns a value, such as C<eval {}>, C<sub {}>, or C<do {}>. It will perform
5014C<eval {}>, C<sub {}> or C<do {}>, and should not be used to exit
7994its flow control behavior, which precludes any return value. It should not be
5015a grep() or map() operation.
7995used to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST>
7996operation.
79975016
79985017=end original
79995018
8000L<C<last>|/last LABEL> は C<eval {}>, C<sub {}>, C<do {}> といった
5019C<last> は C<eval {}>, C<sub {}>, C<do {}> といった
8001典型的には値を返すブロックから値返せません
5020値を返すブロックを終了するのには使えませんし、
8002これは、返り値不可能にするフロー制御振る舞いを実行し
5021grep() や map() 操作終了するのに使うべきではありせん
8003L<C<grep>|/grep BLOCK LIST> や L<C<map>|/map BLOCK LIST> 操作を終了するのに
8004使うべきではありません。
80055022
80065023=begin original
80075024
80085025Note that a block by itself is semantically identical to a loop
8009that executes once. Thus L<C<last>|/last LABEL> can be used to effect
5026that executes once. Thus C<last> can be used to effect an early
8010an early exit out of such a block.
5027exit out of such a block.
80115028
80125029=end original
80135030
8014ブロック自は一だけ実行されるループと文法的にであることに
5031ブロックはそれ体文法的には一だけ実行されるループと同であることに
8015注意してください。
5032注意してください。従って、C<last> でそのようなブロックを
8016従って、L<C<last>|/last LABEL> でそのようなブロックを途中で
5033途中で抜け出すことができます。
8017抜け出すことができます。
80185034
80195035=begin original
80205036
8021See also L<C<continue>|/continue BLOCK> for an illustration of how
5037See also L</continue> for an illustration of how C<last>, C<next>, and
8022L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and
5038C<redo> work.
8023L<C<redo>|/redo LABEL> work.
80245039
80255040=end original
80265041
8027L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL>
5042C<last>, C<next>, C<redo> がどのように働くかについては
8028どのように働くかについては L<C<continue>|/continue BLOCK> 参照してください。
5043L</continue> 参照してさい。
80295044
8030=begin original
8031
8032Unlike most named operators, this has the same precedence as assignment.
8033It is also exempt from the looks-like-a-function rule, so
8034C<last ("foo")."bar"> will cause "bar" to be part of the argument to
8035L<C<last>|/last LABEL>.
8036
8037=end original
8038
8039ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
8040また、関数のように見えるものの規則からも免れるので、C<last ("foo")."bar"> と
8041すると "bar" は L<C<last>|/last LABEL> への引数の一部となります。
8042
80435045=item lc EXPR
8044X<lc> X<lowercase>
80455046
80465047=item lc
80475048
8048=for Pod::Functions return lower-case version of a string
8049
80505049=begin original
80515050
8052Returns a lowercased version of EXPR. This is the internal function
5051Returns an lowercased version of EXPR. This is the internal function
80535052implementing the C<\L> escape in double-quoted strings.
5053Respects current LC_CTYPE locale if C<use locale> in force. See L<perllocale>
5054and L<utf8>.
80545055
80555056=end original
80565057
80575058EXPR を小文字に変換したものを返します。
80585059これは、ダブルクォート文字列における、
80595060C<\L> エスケープを実装する内部関数です。
5061C<use locale> が有効な場合は、現在の LC_CTYPE ロケールを参照します。
5062L<perllocale> と L<utf8> を参照してください。
80605063
80615064=begin original
80625065
8063If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
5066If EXPR is omitted, uses C<$_>.
80645067
80655068=end original
80665069
8067EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
5070EXPR が省略されると、C<$_>を使います。
80685071
8069=begin original
8070
8071What gets returned depends on several factors:
8072
8073=end original
8074
8075返り値として得られるものは色々な要素に依存します:
8076
8077=over
8078
8079=item If C<use bytes> is in effect:
8080
8081(C<use bytes> が有効の場合)
8082
8083=begin original
8084
8085The results follow ASCII rules. Only the characters C<A-Z> change,
8086to C<a-z> respectively.
8087
8088=end original
8089
8090結果は ASCII の規則に従います。
8091C<A-Z> のみが変換され、それぞれ C<a-z> になります。
8092
8093=item Otherwise, if C<use locale> for C<LC_CTYPE> is in effect:
8094
8095(それ以外の場合で、C<LC_CTYPE> に対して C<use locale> が有効の場合)
8096
8097=begin original
8098
8099Respects current C<LC_CTYPE> locale for code points < 256; and uses Unicode
8100rules for the remaining code points (this last can only happen if
8101the UTF8 flag is also set). See L<perllocale>.
8102
8103=end original
8104
8105符号位置 < 256 に対しては現在の C<LC_CTYPE> ロケールに従います; そして
8106残りの符号位置に付いては Unicode の規則を使います (これは UTF8 フラグも
8107設定されている場合にのみ起こります)。
8108L<perllocale> を参照してください。
8109
8110=begin original
8111
8112Starting in v5.20, Perl uses full Unicode rules if the locale is
8113UTF-8. Otherwise, there is a deficiency in this scheme, which is that
8114case changes that cross the 255/256
8115boundary are not well-defined. For example, the lower case of LATIN CAPITAL
8116LETTER SHARP S (U+1E9E) in Unicode rules is U+00DF (on ASCII
8117platforms). But under C<use locale> (prior to v5.20 or not a UTF-8
8118locale), the lower case of U+1E9E is
8119itself, because 0xDF may not be LATIN SMALL LETTER SHARP S in the
8120current locale, and Perl has no way of knowing if that character even
8121exists in the locale, much less what code point it is. Perl returns
8122a result that is above 255 (almost always the input character unchanged),
8123for all instances (and there aren't many) where the 255/256 boundary
8124would otherwise be crossed; and starting in v5.22, it raises a
8125L<locale|perldiag/Can't do %s("%s") on non-UTF-8 locale; resolved to "%s".> warning.
8126
8127=end original
8128
8129v5.20 から、ロケールが UTF-8 の場合は Perl は完全な Unicode の規則を使います。
8130さもなければ、この手法には、255/266 の境界をまたぐ大文字小文字の変換は
8131未定義であるという欠点があります。
8132例えば、Unicode での LATIN CAPITAL LETTER SHARP S (U+1E9E) の小文字は
8133(ASCII プラットフォームでは) U+00DF です。
8134しかし C<use locale> が有効(v5.20 より前か、UTF-8 ロケール以外)なら、U+1E9E の
8135小文字は自分自身です; なぜなら 0xDF は現在のロケールでは
8136LATIN SMALL LETTER SHARP S ではなく、Perl は例えこのロケールに文字が
8137存在するかどうかを知る方法がなく、ましてどの符号位置かを知る方法が
8138ないからです。
8139Perl は 255/256 境界をまたぐ全ての(多くはありません)実体については
8140(ほとんど常に入力文字を変更せずに)256 以上の値を返します;
8141そして v5.22 から
8142L<locale|perldiag/Can't do %s("%s") on non-UTF-8 locale; resolved to "%s".>
8143警告を出力します。
8144
8145=item Otherwise, If EXPR has the UTF8 flag set:
8146
8147(その他の場合で、EXPR に UTF8 フラグがセットされている場合)
8148
8149=begin original
8150
8151Unicode rules are used for the case change.
8152
8153=end original
8154
8155大文字小文字変換には Unicode の規則が使われます。
8156
8157=item Otherwise, if C<use feature 'unicode_strings'> or C<use locale ':not_characters'> is in effect:
8158
8159(それ以外の場合で、C<use feature 'unicode_strings'> か C<use locale ':not_characters'> が有効の場合)
8160
8161=begin original
8162
8163Unicode rules are used for the case change.
8164
8165=end original
8166
8167大文字小文字変換には Unicode の規則が使われます。
8168
8169=item Otherwise:
8170
8171(それ以外の場合)
8172
8173=begin original
8174
8175ASCII rules are used for the case change. The lowercase of any character
8176outside the ASCII range is the character itself.
8177
8178=end original
8179
8180大文字小文字変換には ASCII の規則が使われます。
8181ASCII の範囲外の文字の「小文字」はその文字自身です。
8182
8183=back
8184
81855072=item lcfirst EXPR
8186X<lcfirst> X<lowercase>
81875073
81885074=item lcfirst
81895075
8190=for Pod::Functions return a string with just the next letter in lower case
8191
81925076=begin original
81935077
8194Returns the value of EXPR with the first character lowercased. This
5078Returns the value of EXPR with the first character lowercased. This is
8195is the internal function implementing the C<\l> escape in
5079the internal function implementing the C<\l> escape in double-quoted strings.
8196double-quoted strings.
5080Respects current LC_CTYPE locale if C<use locale> in force. See L<perllocale>.
81975081
81985082=end original
81995083
82005084最初の文字だけを小文字にした、EXPR を返します。
82015085これは、ダブルクォート文字列における、C<\l> エスケープを
82025086実装する内部関数です。
5087C<use locale> が有効な場合は、現在の LC_CTYPE ロケールを参照します。
5088L<perllocale> を参照してください。
82035089
82045090=begin original
82055091
8206If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
5092If EXPR is omitted, uses C<$_>.
82075093
82085094=end original
82095095
8210EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
5096EXPR が省略されると、C<$_>を使います。
82115097
8212=begin original
8213
8214This function behaves the same way under various pragmas, such as in a locale,
8215as L<C<lc>|/lc EXPR> does.
8216
8217=end original
8218
8219この関数は、ロケールのようなさまざまなプラグマの影響下では、
8220L<C<lc>|/lc EXPR> と同様に振る舞います。
8221
82225098=item length EXPR
8223X<length> X<size>
82245099
82255100=item length
82265101
8227=for Pod::Functions return the number of characters in a string
8228
82295102=begin original
82305103
8231Returns the length in I<characters> of the value of EXPR. If EXPR is
5104Returns the length in characters of the value of EXPR. If EXPR is
8232omitted, returns the length of L<C<$_>|perlvar/$_>. If EXPR is
5105omitted, returns length of C<$_>. Note that this cannot be used on
8233undefined, returns L<C<undef>|/undef EXPR>.
5106an entire array or hash to find out how many elements these have.
5107For that, use C<scalar @array> and C<scalar keys %hash> respectively.
82345108
82355109=end original
82365110
8237EXPR の値の I<文字> の長さを返します。
5111EXPR の値の文字の長さを返します。
8238EXPR が省略されたときには、L<C<$_>|perlvar/$_> の長さを返します。
5112EXPR が省略されたときには、C<$_> の長さを返します。
8239EXPR が未定義値場合、L<C<undef>|/undef EXPR> 返します。
5113これは配列やハッシュ全体に対してどれだけ要素含んでいるかを
8240
8241=begin original
8242
8243This function cannot be used on an entire array or hash to find out how
8244many elements these have. For that, use C<scalar @array> and C<scalar keys
8245%hash>, respectively.
8246
8247=end original
8248
8249この関数は配列やハッシュ全体に対してどれだけの要素を含んでいるかを
82505114調べるためには使えません。
82515115そのような用途には、それぞれ C<scalar @array> と C<scalar keys %hash> を
82525116利用してください。
82535117
8254=begin original
8255
8256Like all Perl character operations, L<C<length>|/length EXPR> normally
8257deals in logical
8258characters, not physical bytes. For how many bytes a string encoded as
8259UTF-8 would take up, use C<length(Encode::encode('UTF-8', EXPR))>
8260(you'll have to C<use Encode> first). See L<Encode> and L<perlunicode>.
8261
8262=end original
8263
8264全ての Perl の文字操作と同様、L<C<length>|/length EXPR> は通常物理的な
8265バイトではなく論理文字を扱います。
8266UTF-8 でエンコードされた文字列が何バイトかを知るには、
8267C<length(Encode::encode('UTF-8', EXPR))> を使ってください (先に
8268C<use Encode> する必要があります)。
8269L<Encode> と L<perlunicode> を参照してください。
8270
8271=item __LINE__
8272X<__LINE__>
8273
8274=for Pod::Functions the current source line number
8275
8276=begin original
8277
8278A special token that compiles to the current line number.
8279
8280=end original
8281
8282現在の行番号にコンパイルされる特殊トークン。
8283
82845118=item link OLDFILE,NEWFILE
8285X<link>
82865119
8287=for Pod::Functions create a hard link in the filesystem
8288
82895120=begin original
82905121
82915122Creates a new filename linked to the old filename. Returns true for
8292success, false otherwise.
5123success, false otherwise.
82935124
82945125=end original
82955126
8296OLDFILE にリンクされた、新しいファイル NEWFILE を作ります。
5127OLDFILE にリンクされた、新しいファイル NEWFILE を作
8297成功時にはを、さもなければ偽を返します。
5128ります。 成功時には true を、失敗時には false を返します。
82985129
8299=begin original
8300
8301Portability issues: L<perlport/link>.
8302
8303=end original
8304
8305移植性の問題: L<perlport/link>。
8306
83075130=item listen SOCKET,QUEUESIZE
8308X<listen>
83095131
8310=for Pod::Functions register your socket as a server
8311
83125132=begin original
83135133
8314Does the same thing that the L<listen(2)> system call does. Returns true if
5134Does the same thing that the listen system call does. Returns true if
8315it succeeded, false otherwise. See the example in
5135it succeeded, false otherwise. See the example in
83165136L<perlipc/"Sockets: Client/Server Communication">.
83175137
83185138=end original
83195139
8320L<listen(2)> システムコールと同じことをします。
5140listen システムコールと同じことをします。成功時には真を返し、
8321成功時には真を、さもなければ偽を返します。
5141失敗時には偽を返します。
8322L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
5142L<perlipc/"Sockets: Client/Server Communication">の例を参照してください。
83235143
83245144=item local EXPR
8325X<local>
83265145
8327=for Pod::Functions create a temporary value for a global variable (dynamic scoping)
8328
83295146=begin original
83305147
8331You really probably want to be using L<C<my>|/my VARLIST> instead,
5148You really probably want to be using C<my> instead, because C<local> isn't
8332because L<C<local>|/local EXPR> isn't what most people think of as
5149what most people think of as "local". See
8333"local". See L<perlsub/"Private Variables via my()"> for details.
5150L<perlsub/"Private Variables via my()"> for details.
83345151
83355152=end original
83365153
8337あなたはが本当に望んでいるのは L<C<my>|/my VARLIST> の方でしょう;
5154あなたはが本当に望んでいるのは C<my> の方でしょう
8338L<C<local>|/local EXPR> はほとんどの人々が「ローカル」と考えるものと
5155C<local> はほとんどの人々が「ローカル」と考えるものと違うからです。
8339違うからです。
5156詳細はL<perlsub/"Private Variables
8340詳細は L<perlsub/"Private Variables via my()"> を参照してください。
5157via my()">を参照してください。
83415158
83425159=begin original
83435160
83445161A local modifies the listed variables to be local to the enclosing
83455162block, file, or eval. If more than one value is listed, the list must
83465163be placed in parentheses. See L<perlsub/"Temporary Values via local()">
83475164for details, including issues with tied arrays and hashes.
83485165
83495166=end original
83505167
83515168"local" はリストアップされた変数を、囲っているブロック、
83525169ファイル、eval の中で、ローカルなものにします。
8353複数の値を指定する場合は、リストはかっこでくくらなければなりません。
5170複数の値を指定する場合は、リストは括弧でくくらなければなりません。
83545171tie した配列とハッシュに関する事項を含む詳細については
83555172L<perlsub/"Temporary Values via local()"> を参照してください。
83565173
8357=begin original
8358
8359The C<delete local EXPR> construct can also be used to localize the deletion
8360of array/hash elements to the current block.
8361See L<perlsub/"Localized deletion of elements of composite types">.
8362
8363=end original
8364
8365C<delete local EXPR> 構文は、配列/ハッシュの要素の削除を現在の
8366ブロックにローカル化するためにも使われていました。
8367L<perlsub/"Localized deletion of elements of composite types"> を
8368参照してください。
8369
83705174=item localtime EXPR
8371X<localtime> X<ctime>
83725175
8373=item localtime
8374
8375=for Pod::Functions convert UNIX time into record or string using local time
8376
83775176=begin original
83785177
83795178Converts a time as returned by the time function to a 9-element list
83805179with the time analyzed for the local time zone. Typically used as
83815180follows:
83825181
83835182=end original
83845183
83855184time 関数が返す時刻を、ローカルなタイムゾーンで測った時刻として、
838651859 要素の配列に変換します。
8387通は、以下のようにして使ます:
5186は、以下のようにして使用します
83885187
8389 # 0 1 2 3 4 5 6 7 8
5188 # 0 1 2 3 4 5 6 7 8
8390 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
5189 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
8391 localtime(time);
5190 localtime(time);
83925191
83935192=begin original
83945193
8395All list elements are numeric and come straight out of the C `struct
5194All list elements are numeric, and come straight out of the C `struct
8396tm'. C<$sec>, C<$min>, and C<$hour> are the seconds, minutes, and hours
5195tm'. $sec, $min, and $hour are the seconds, minutes, and hours of the
8397of the specified time.
5196specified time. $mday is the day of the month, and $mon is the month
5197itself, in the range C<0..11> with 0 indicating January and 11
5198indicating December. $year is the number of years since 1900. That
5199is, $year is C<123> in year 2023. $wday is the day of the week, with
52000 indicating Sunday and 3 indicating Wednesday. $yday is the day of
5201the year, in the range C<0..364> (or C<0..365> in leap years.) $isdst
5202is true if the specified time occurs during daylight savings time,
5203false otherwise.
83985204
83995205=end original
84005206
8401すべてのリスト要素は数値で、C の `struct tm' 構造体から
5207すべてのリスト要素は数値で、C の `struct tm' 構造体から
84025208直接持ってきます。
8403C<$sec>, C<$min>, C<$hour> は指定された時刻の秒、分、時です。
5209$sec, $min, $hour は指定された時刻の秒、分、時です。
5210$mday は月の何日目か、$mon は月の値です。
5211月の値は C<0..11> で、0 が 1 月、11 が 12 月です。
5212$year は 1900 年からの年数です。
5213つまり、$year が C<123> なら 2023 年です。
5214$wday は曜日で、0 が日曜日、3 が水曜日です。
5215$yday はその年の何日目かで、C<0..364> の値を取ります
5216(うるう年は C<0..365> です)。
5217$isdst は指定された時刻が夏時間の場合は真、そうでなければ偽です。
84045218
84055219=begin original
84065220
8407C<$mday> is the day of the month and C<$mon> the month in
5221Note that the $year element is I<not> simply the last two digits of
8408the range C<0..11>, with 0 indicating January and 11 indicating December.
5222the year. If you assume it is, then you create non-Y2K-compliant
8409This makes it easy to get a month name from a list:
5223programs--and you wouldn't want to do that, would you?
84105224
84115225=end original
84125226
8413C<$mday> は月何日目か、C<$mon> は月の値です; 月の値は C<0..11> で、0 が
5227$year 要素が単に西暦 2 桁を表している I<のではない> ことに
84141 月11 が 12 月です。
5228注意してください。これを仮定するとY2K 問題を含んだプログラムを
8415より、リストから月の名前を得るのが簡単になります:
5229作るになります。それはお望みじゃないでしょう?
84165230
8417 my @abbr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
8418 print "$abbr[$mon] $mday";
8419 # $mon=9, $mday=18 gives "Oct 18"
8420
84215231=begin original
84225232
8423C<$year> contains the number of years since 1900. To get a 4-digit
5233The proper way to get a complete 4-digit year is simply:
8424year write:
84255234
84265235=end original
84275236
8428C<$year> 1900 年から年数持ちます。
5237完全な 4 西暦得るには単に以下のようにしてください:
84294 桁の年を得るには以下のようにします:
84305238
8431 $year += 1900;
5239 $year += 1900;
84325240
84335241=begin original
84345242
8435To get the last two digits of the year (e.g., "01" in 2001) do:
5243And to get the last two digits of the year (e.g., '01' in 2001) do:
84365244
84375245=end original
84385246
8439西暦の下 2 桁(2001 年では "01")がほしい場合は以下のようにします:
5247そして西暦の下 2 桁(2001 年では '01')がほしい場合は以下のようにします:
84405248
8441 $year = sprintf("%02d", $year % 100);
5249 $year = sprintf("%02d", $year % 100);
84425250
84435251=begin original
84445252
8445C<$wday> is the day of the week, with 0 indicating Sunday and 3 indicating
5253If EXPR is omitted, C<localtime()> uses the current time (C<localtime(time)>).
8446Wednesday. C<$yday> is the day of the year, in the range C<0..364>
8447(or C<0..365> in leap years.)
84485254
84495255=end original
84505256
8451C<$wday> は曜日で、0 日曜日3 が水曜日です。
5257EXPR省略されるとlocaltime(time()) を行ないます。
8452C<$yday> はその年の何日目かで、C<0..364> の値を取ります
8453(うるう年は C<0..365> です。)
84545258
84555259=begin original
84565260
8457C<$isdst> is true if the specified time occurs during Daylight Saving
5261In scalar context, C<localtime()> returns the ctime(3) value:
8458Time, false otherwise.
84595262
84605263=end original
84615264
8462C<$isdst> は指定された時刻が夏時間場合は真、そうでなければ偽で
5265スカラコンテキストでは、ctime(3)値を返しま:
84635266
8464=begin original
5267 $now_string = localtime; # e.g., "Thu Oct 13 04:54:34 1994"
84655268
8466If EXPR is omitted, L<C<localtime>|/localtime EXPR> uses the current
8467time (as returned by L<C<time>|/time>).
8468
8469=end original
8470
8471EXPR が省略されると、L<C<localtime>|/localtime EXPR> は
8472(L<C<time>|/time> によって返される) 現在時刻を使います。
8473
84745269=begin original
84755270
8476In scalar context, L<C<localtime>|/localtime EXPR> returns the
5271This scalar value is B<not> locale dependent, see L<perllocale>, but
8477L<ctime(3)> value:
5272instead a Perl builtin. Also see the C<Time::Local> module
5273(to convert the second, minutes, hours, ... back to seconds since the
5274stroke of midnight the 1st of January 1970, the value returned by
5275time()), and the strftime(3) and mktime(3) functions available via the
5276POSIX module. To get somewhat similar but locale dependent date
5277strings, set up your locale environment variables appropriately
5278(please see L<perllocale>) and try for example:
84785279
84795280=end original
84805281
8481スカラコンテキストでは、L<C<localtime>|/localtime EXPR> は L<ctime(3)> の値
5282スカラ値はロケール依存 B<ではなく>Perl の組み込みのです
8482ます:
5283(L<perllocale> を参照てください)。
5284また、(秒、分、時…の形から、time() が返す値である
8484 my $now_string = localtime; # e.g., "Thu Oct 13 04:54:34 1994"
52851970 1 1 日の真夜中からの秒数に変換する) C<Time::Local> モジュール
5286及び POSIX モジュールで提供される strftime(3) と mktime(3) 関数も
8486=begin original
8487
8488The format of this scalar value is B<not> locale-dependent but built
8489into Perl. For GMT instead of local time use the
8490L<C<gmtime>|/gmtime EXPR> builtin. See also the
8491L<C<Time::Local>|Time::Local> module (for converting seconds, minutes,
8492hours, and such back to the integer value returned by L<C<time>|/time>),
8493and the L<POSIX> module's L<C<strftime>|POSIX/C<strftime>> and
8494L<C<mktime>|POSIX/C<mktime>> functions.
8495
8496=end original
8497
8498このスカラ値の形式はロケール依存 B<ではなく>、Perl の組み込みの値です。
8499ローカル時刻ではなく GMT がほしい場合は L<C<gmtime>|/gmtime EXPR> 組み込み
8500関数を使ってください。
8501また、(秒、分、時などの形から、L<C<time>|/time> が返す値である
85021970 年 1 月 1 日の真夜中からの秒数に変換する)
8503L<C<Time::Local>|Time::Local> モジュール及び L<POSIX> モジュールで提供される
8504L<C<strftime>|POSIX/C<strftime>> と L<C<mktime>|POSIX/C<mktime>> 関数も
85055287参照してください。
8506
8507=begin original
8508
8509To get somewhat similar but locale-dependent date strings, set up your
8510locale environment variables appropriately (please see L<perllocale>) and
8511try for example:
8512
8513=end original
8514
85155288似たような、しかしロケール依存の日付文字列がほしい場合は、
85165289ロケール環境変数を適切に設定して(L<perllocale> を参照してください)、
85175290以下の例を試してください:
85185291
85195292 use POSIX qw(strftime);
8520 my $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;
5293 $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;
8521 # or for GMT formatted appropriately for your locale:
8522 my $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime;
85235294
85245295=begin original
85255296
8526Note that C<%a> and C<%b>, the short forms of the day of the week
5297Note that the C<%a> and C<%b>, the short forms of the day of the week
85275298and the month of the year, may not necessarily be three characters wide.
85285299
85295300=end original
85305301
85315302曜日と月の短い表現である C<%a> と C<%b> は、3 文字とは限らないことに
85325303注意してください。
85335304
8534=begin original
5305=item lock
85355306
8536The L<Time::gmtime> and L<Time::localtime> modules provide a convenient,
5307 lock I<THING>
8537by-name access mechanism to the L<C<gmtime>|/gmtime EXPR> and
8538L<C<localtime>|/localtime EXPR> functions, respectively.
85395308
8540=end original
8541
8542L<Time::gmtime> モジュールと L<Time::localtime> モジュールは、それぞれ
8543L<C<gmtime>|/gmtime EXPR> 関数と L<C<localtime>|/localtime EXPR> 関数に、
8544名前でアクセスする機構を提供する便利なモジュールです。
8545
85465309=begin original
85475310
8548For a comprehensive date and time representation look at the
5311This function places an advisory lock on a variable, subroutine,
8549L<DateTime> module on CPAN.
5312or referenced object contained in I<THING> until the lock goes out
5313of scope. This is a built-in function only if your version of Perl
5314was built with threading enabled, and if you've said C<use Threads>.
5315Otherwise a user-defined function by this name will be called. See
5316L<Thread>.
85505317
85515318=end original
85525319
8553包括的な日付と時刻表現について、CPAN の L<DateTime> モジュー
5320関数I<THING> が含む変数、サブーチン、リファレンスされた
8554参照してください。
5321オブジェクトに、スコープから出るまでアドバイサリロックを掛けます.
5322これはスレッドを有効にしてビルドされた Perl で、かつ C<use Threads> した
5323場合にのみ組み込み関数となります。
5324それ以外の場合はこの名前をもつユーザーが定義した関数が呼び出されます。
5325L<Thread> を参照してください。
85555326
8556=begin original
8557
8558Portability issues: L<perlport/localtime>.
8559
8560=end original
8561
8562移植性の問題: L<perlport/localtime>。
8563
8564=item lock THING
8565X<lock>
8566
8567=for Pod::Functions +5.005 get a thread lock on a variable, subroutine, or method
8568
8569=begin original
8570
8571This function places an advisory lock on a shared variable or referenced
8572object contained in I<THING> until the lock goes out of scope.
8573
8574=end original
8575
8576この関数は I<THING> が含む共有変数またはリファレンスされたオブジェクトに、
8577スコープから出るまでアドバイサリロックを掛けます.
8578
8579=begin original
8580
8581The value returned is the scalar itself, if the argument is a scalar, or a
8582reference, if the argument is a hash, array or subroutine.
8583
8584=end original
8585
8586返される値は、引数がスカラならそのスカラ自身、引数がハッシュ、配列、
8587サブルーチンならリファレンスです。
8588
8589=begin original
8590
8591L<C<lock>|/lock THING> is a "weak keyword"; this means that if you've
8592defined a function
8593by this name (before any calls to it), that function will be called
8594instead. If you are not under C<use threads::shared> this does nothing.
8595See L<threads::shared>.
8596
8597=end original
8598
8599L<C<lock>|/lock THING> は「弱いキーワード」です; もしユーザーが(呼び出し前に)
8600この名前で関数を定義すると、定義された関数の方が呼び出されます。
8601C<use threads::shared> の影響下でない場合は、これは何もしません。
8602L<threads::shared> を参照してください。
8603
86045327=item log EXPR
8605X<log> X<logarithm> X<e> X<ln> X<base>
86065328
86075329=item log
86085330
8609=for Pod::Functions retrieve the natural logarithm for a number
8610
86115331=begin original
86125332
86135333Returns the natural logarithm (base I<e>) of EXPR. If EXPR is omitted,
8614returns the log of L<C<$_>|perlvar/$_>. To get the
5334returns log of C<$_>. To get the log of another base, use basic algebra:
8615log of another base, use basic algebra:
86165335The base-N log of a number is equal to the natural log of that number
86175336divided by the natural log of N. For example:
86185337
86195338=end original
86205339
86215340EXPR の (I<e> を底とする) 自然対数を返します。
8622EXPR が省略されると、L<C<$_>|perlvar/$_> の対数を返します。
5341EXPR が省略されると、C<$_> の対数を返します。
86235342底の異なる対数を求めるためには、基礎代数を利用してください:
86245343ある数の N を底とする対数は、その数の自然対数を N の自然対数で割ったものです。
8625えば:
5344例:
86265345
86275346 sub log10 {
8628 my $n = shift;
5347 my $n = shift;
8629 return log($n)/log(10);
5348 return log($n)/log(10);
8630 }
5349 }
86315350
86325351=begin original
86335352
8634See also L<C<exp>|/exp EXPR> for the inverse operation.
5353See also L</exp> for the inverse operation.
86355354
86365355=end original
86375356
8638逆操作については L<C<exp>|/exp EXPR> を参照してください。
5357逆操作については L</exp> を参照してさい。
86395358
86405359=item lstat FILEHANDLE
8641X<lstat>
86425360
86435361=item lstat EXPR
86445362
8645=item lstat DIRHANDLE
8646
86475363=item lstat
86485364
8649=for Pod::Functions stat a symbolic link
8650
86515365=begin original
86525366
8653Does the same thing as the L<C<stat>|/stat FILEHANDLE> function
5367Does the same thing as the C<stat> function (including setting the
8654(including setting the special C<_> filehandle) but stats a symbolic
5368special C<_> filehandle) but stats a symbolic link instead of the file
8655link instead of the file the symbolic link points to. If symbolic links
5369the symbolic link points to. If symbolic links are unimplemented on
8656are unimplemented on your system, a normal L<C<stat>|/stat FILEHANDLE>
5370your system, a normal C<stat> is done.
8657is done. For much more detailed information, please see the
8658documentation for L<C<stat>|/stat FILEHANDLE>.
86595371
86605372=end original
86615373
86625374(特別なファイルハンドルである C<_> の設定を含めて)
8663L<C<stat>|/stat FILEHANDLE> 関数と同じことをしますが、シンボリックリンクが
5375C<stat> 関数と同じことをしますが、シンボリックリンクが
86645376指しているファイルではなく、シンボリックリンク自体の stat をとります。
8665シンボリックリンクがシステムに実装されていないと、通常の
5377シンボリックリンクがシステムに実装されていないと、通常の C<stat> が行なわれます。
8666L<C<stat>|/stat FILEHANDLE> が行なわれます。
8667さらにより詳細な情報については、L<C<stat>|/stat FILEHANDLE> の文書を
8668参照してください。
86695378
86705379=begin original
86715380
8672If EXPR is omitted, stats L<C<$_>|perlvar/$_>.
5381If EXPR is omitted, stats C<$_>.
86735382
86745383=end original
86755384
8676EXPR が省略されると、L<C<$_>|perlvar/$_> の stat をとります。
5385EXPR が省略されると、C<$_> の stat をとります。
86775386
8678=begin original
8679
8680Portability issues: L<perlport/lstat>.
8681
8682=end original
8683
8684移植性の問題: L<perlport/lstat>。
8685
86865387=item m//
86875388
8688=for Pod::Functions match a string with a regular expression pattern
8689
86905389=begin original
86915390
8692The match operator. See L<perlop/"Regexp Quote-Like Operators">.
5391The match operator. See L<perlop>.
86935392
86945393=end original
86955394
86965395マッチ演算子です。
8697L<perlop/"Regexp Quote-Like Operators"> を参照してください。
5396L<perlop> を参照してください。
86985397
86995398=item map BLOCK LIST
8700X<map>
87015399
87025400=item map EXPR,LIST
87035401
8704=for Pod::Functions apply a change to a list to get back a new list with the changes
8705
87065402=begin original
87075403
87085404Evaluates the BLOCK or EXPR for each element of LIST (locally setting
8709L<C<$_>|perlvar/$_> to each element) and composes a list of the results of
5405C<$_> to each element) and returns the list value composed of the
8710each such evaluation. Each element of LIST may produce zero, one, or more
5406results of each such evaluation. In scalar context, returns the
8711elements in the generated list, so the number of elements in the generated
5407total number of elements so generated. Evaluates BLOCK or EXPR in
8712list may differ from that in LIST. In scalar context, returns the total
5408list context, so each element of LIST may produce zero, one, or
8713number of elements so generated. In list context, returns the generated list.
5409more elements in the returned value.
87145410
87155411=end original
87165412
87175413LIST の個々の要素に対して、BLOCK か EXPR を評価し
8718(L<C<$_>|perlvar/$_> は、ローカルに個々の要素が設定されます) 、
5414(C<$_> は、ローカルに個々の要素が設定されます) 、
8719それぞれの評価結果からなるリストを作ります。
5415それぞれの評価結果からなるリスト値が返されます。
8720LIST の個々の要素によって作られる、生成されたリストの要素数は、
87210 個の場合もあれば、複数の場合もあるので、
8722生成されたリストの要素数は LIST の要素数と異なるかも知れません。
87235416スカラコンテキストでは、生成された要素の数を返します。
8724リストコンテキストでは、生成されたリストを返します
5417BLOCK や EXPR をリストコンテキストで評価しますので、LIST の
5418個々の要素によって作られる、返り値であるリストの要素数は、
54190 個の場合もあれば、複数の場合もあります。
87255420
8726 my @chars = map(chr, @numbers);
5421 @chars = map(chr, @nums);
87275422
87285423=begin original
87295424
8730translates a list of numbers to the corresponding characters.
5425translates a list of numbers to the corresponding characters. And
87315426
87325427=end original
87335428
8734は、数のリストを対応する文字に変換します。
5429は、数のリストを対応する文字に変換します。また、
87355430
8736 my @squares = map { $_ * $_ } @numbers;
5431 %hash = map { getkey($_) => $_ } @array;
87375432
87385433=begin original
87395434
8740translates a list of numbers to their squared values.
8741
8742=end original
8743
8744これは数値のリストを、その 2 乗に変換します。
8745
8746 my @squares = map { $_ > 5 ? ($_ * $_) : () } @numbers;
8747
8748=begin original
8749
8750shows that number of returned elements can differ from the number of
8751input elements. To omit an element, return an empty list ().
8752This could also be achieved by writing
8753
8754=end original
8755
8756のように、返された要素の数が入力要素の数と異なる場合もあります。
8757要素を省略するには、空リスト () を返します。
8758これは以下のように書くことでも達成できて
8759
8760 my @squares = map { $_ * $_ } grep { $_ > 5 } @numbers;
8761
8762=begin original
8763
8764which makes the intention more clear.
8765
8766=end original
8767
8768この方が目的がよりはっきりします。
8769
8770=begin original
8771
8772Map always returns a list, which can be
8773assigned to a hash such that the elements
8774become key/value pairs. See L<perldata> for more details.
8775
8776=end original
8777
8778map は常にリストを返し、要素がキー/値の組になるようなハッシュに
8779代入できます。
8780さらなる詳細については L<perldata> を参照してください。
8781
8782 my %hash = map { get_a_key_for($_) => $_ } @array;
8783
8784=begin original
8785
87865435is just a funny way to write
87875436
87885437=end original
87895438
87905439は以下のものをちょっと変わった書き方で書いたものです。
87915440
8792 my %hash;
5441 %hash = ();
8793 foreach (@array) {
5442 foreach $_ (@array) {
8794 $hash{get_a_key_for($_)} = $_;
5443 $hash{getkey($_)} = $_;
87955444 }
87965445
87975446=begin original
87985447
8799Note that L<C<$_>|perlvar/$_> is an alias to the list value, so it can
5448Note that C<$_> is an alias to the list value, so it can be used to
8800be used to modify the elements of the LIST. While this is useful and
5449modify the elements of the LIST. While this is useful and supported,
8801supported, it can cause bizarre results if the elements of LIST are not
5450it can cause bizarre results if the elements of LIST are not variables.
8802variables. Using a regular C<foreach> loop for this purpose would be
5451Using a regular C<foreach> loop for this purpose would be clearer in
8803clearer in most cases. See also L<C<grep>|/grep BLOCK LIST> for a
5452most cases. See also L</grep> for an array composed of those items of
8804list composed of those items of the original list for which the BLOCK
5453the original list for which the BLOCK or EXPR evaluates to true.
8805or EXPR evaluates to true.
88065454
88075455=end original
88085456
8809L<C<$_>|perlvar/$_> は、LIST の値へのエイリアスですので、LIST の要素を
5457C<$_> は、LIST の値へのエイリアスですので、LIST の要素を
88105458変更するために使うことができます。
88115459これは、便利でサポートされていますが、
88125460LIST の要素が変数でないと、おかしな結果になります。
88135461この目的には通常の C<foreach> ループを使うことで、ほとんどの場合は
88145462より明確になります。
8815BLOCK や EXPR が真になる元のリストの要素からなるリストについては、
5463BLOCK や EXPR が真になる元のリストの要素からなる配列については、
8816L<C<grep>|/grep BLOCK LIST> も参照してください。
5464L</grep> も参照してください。
88175465
88185466=begin original
88195467
88205468C<{> starts both hash references and blocks, so C<map { ...> could be either
8821the start of map BLOCK LIST or map EXPR, LIST. Because Perl doesn't look
5469the start of map BLOCK LIST or map EXPR, LIST. Because perl doesn't look
8822ahead for the closing C<}> it has to take a guess at which it's dealing with
5470ahead for the closing C<}> it has to take a guess at which its dealing with
8823based on what it finds just after the
5471based what it finds just after the C<{>. Usually it gets it right, but if it
8824C<{>. Usually it gets it right, but if it
88255472doesn't it won't realize something is wrong until it gets to the C<}> and
8826encounters the missing (or unexpected) comma. The syntax error will be
5473encounters the missing (or unexpected) comma. The syntax error will be
8827reported close to the C<}>, but you'll need to change something near the C<{>
5474reported close to the C<}> but you'll need to change something near the C<{>
8828such as using a unary C<+> or semicolon to give Perl some help:
5475such as using a unary C<+> to give perl some help:
88295476
88305477=end original
88315478
88325479C<{> はハッシュリファレンスとブロックの両方の開始文字なので、
88335480C<map { ...> は map BLOCK LIST の場合と map EXPR, LIST の場合があります。
8834Perl は終了文字の C<}> を先読みしないので、C<{> の直後の文字を見て
5481perl は終了文字の C<}> を先読みしないので、C<{> の直後の文字を見て
88355482どちらとして扱うかを推測します。
88365483通常この推測は正しいですが、もし間違った場合は、C<}> まで読み込んで
88375484カンマが足りない(または多い)ことがわかるまで、何かがおかしいことに
88385485気付きません。
8839C<}> の近くで文法エラーが出ますが、Perl を助けるために単項の C<+>
5486C<}> の近くで文法エラーが出ますが、perl を助けるために単項の C<+>
8840セミコロンを使うというように、C<{> の近くの何かを変更する必要があります。
5487使うというように、C<{> の近くの何かを変更する必要があります。
88415488
8842 my %hash = map { "\L$_" => 1 } @array # perl guesses EXPR. wrong
5489 %hash = map { "\L$_", 1 } @array # perl guesses EXPR. wrong
8843 my %hash = map { +"\L$_" => 1 } @array # perl guesses BLOCK. right
5490 %hash = map { +"\L$_", 1 } @array # perl guesses BLOCK. right
8844 my %hash = map {; "\L$_" => 1 } @array # this also works
5491 %hash = map { ("\L$_", 1) } @array # this also works
8845 my %hash = map { ("\L$_" => 1) } @array # as does this
5492 %hash = map { lc($_), 1 } @array # as does this.
8846 my %hash = map { lc($_) => 1 } @array # and this.
5493 %hash = map +( lc($_), 1 ), @array # this is EXPR and works!
8847 my %hash = map +( lc($_) => 1 ), @array # this is EXPR and works!
88485494
8849 my %hash = map ( lc($_), 1 ), @array # evaluates to (1, @array)
5495 %hash = map ( lc($_), 1 ), @array # evaluates to (1, @array)
88505496
88515497=begin original
88525498
8853or to force an anon hash constructor use C<+{>:
5499or to force an anon hash constructor use C<+{>
88545500
88555501=end original
88565502
88575503または C<+{> を使って無名ハッシュコンストラクタを強制します:
88585504
8859 my @hashes = map +{ lc($_) => 1 }, @array # EXPR, so needs
5505 @hashes = map +{ lc($_), 1 }, @array # EXPR, so needs , at end
8860 # comma at end
88615506
88625507=begin original
88635508
8864to get a list of anonymous hashes each with only one entry apiece.
5509and you get list of anonymous hashes each with only 1 entry.
88655510
88665511=end original
88675512
88685513こうするとそれぞれ 1 要素だけの無名ハッシュのリストを得られます。
88695514
8870=item mkdir FILENAME,MODE
5515=item mkdir FILENAME,MASK
8871X<mkdir> X<md> X<directory, create>
88725516
88735517=item mkdir FILENAME
88745518
8875=item mkdir
8876
8877=for Pod::Functions create a directory
8878
88795519=begin original
88805520
88815521Creates the directory specified by FILENAME, with permissions
8882specified by MODE (as modified by L<C<umask>|/umask EXPR>). If it
5522specified by MASK (as modified by C<umask>). If it succeeds it
8883succeeds it returns true; otherwise it returns false and sets
5523returns true, otherwise it returns false and sets C<$!> (errno).
8884L<C<$!>|perlvar/$!> (errno).
5524If omitted, MASK defaults to 0777.
8885MODE defaults to 0777 if omitted, and FILENAME defaults
8886to L<C<$_>|perlvar/$_> if omitted.
88875525
88885526=end original
88895527
8890FILENAME で指定したディレクトリを、MODE で指定した許可モード(を
5528FILENAME で指定したディレクトリを、MASK で指定した許可モード(を
8891L<C<umask>|/umask EXPR> で修正したもの) で作成します。
5529C<umask> で修正したもの) で作成します。
8892成功時には真を返します; さもなければ偽を返して
5530成功時には真を返し、失敗時には偽を返して C<$!> (errno) を設定します。
8893L<C<$!>|perlvar/$!> (errno) 設定します。
5531MASK省略すると、0777 とみなします。
8894MODE を省略すると、0777 とみなし、
8895FILENAME を省略すると、L<C<$_>|perlvar/$_> を使います。
88965532
88975533=begin original
88985534
8899In general, it is better to create directories with a permissive MODE
5535In general, it is better to create directories with permissive MASK,
8900and let the user modify that with their L<C<umask>|/umask EXPR> than it
5536and let the user modify that with their C<umask>, than it is to supply
8901is to supply
5537a restrictive MASK and give the user no way to be more permissive.
8902a restrictive MODE and give the user no way to be more permissive.
89035538The exceptions to this rule are when the file or directory should be
8904kept private (mail files, for instance). The documentation for
5539kept private (mail files, for instance). The perlfunc(1) entry on
8905L<C<umask>|/umask EXPR> discusses the choice of MODE in more detail.
5540C<umask> discusses the choice of MASK in more detail.
89065541
89075542=end original
89085543
8909一般的に、制限された MODE を使ってユーザーがより寛容にする方法を
5544一般的に、制限された MASK を使ってユーザーがより寛容にする方法を
8910与えないより、寛容な MODE でディレクトリを作り、ユーザーが自身の
5545与えないより、寛容な MASK でディレクトリを作り、ユーザーが自身の C<umask> で
8911L<C<umask>|/umask EXPR> で修正するようにした方がよいです。
5546修正するようにした方がよいです。
89125547例外は、(例えばメールファイルのような)プライベートに保つべきファイルや
89135548ディレクトリを書く場合です。
8914L<C<umask>|/umask EXPR> の文書で、MODE の選択に関して詳細に議論しています。
5549perlfunc(1) の C<umask> で、MASK の選択に関して詳細に議論しています。
89155550
8916=begin original
8917
8918Note that according to the POSIX 1003.1-1996 the FILENAME may have any
8919number of trailing slashes. Some operating and filesystems do not get
8920this right, so Perl automatically removes all trailing slashes to keep
8921everyone happy.
8922
8923=end original
8924
8925POSIX 1003.1-1996 によれば、FILENAME には末尾に任意の数のスラッシュを
8926つけることができます。
8927このようには動かない OS やファイルシステムもあるので、Perl はみんなが
8928幸せになれるように、自動的に末尾のスラッシュを削除します。
8929
8930=begin original
8931
8932To recursively create a directory structure, look at
8933the L<C<make_path>|File::Path/make_path( $dir1, $dir2, .... )> function
8934of the L<File::Path> module.
8935
8936=end original
8937
8938ディレクトリ構造を再帰的に作成するには、L<File::Path> モジュールの
8939L<C<make_path>|File::Path/make_path( $dir1, $dir2, .... )> 関数を
8940参照してください。
8941
89425551=item msgctl ID,CMD,ARG
8943X<msgctl>
89445552
8945=for Pod::Functions SysV IPC message control operations
8946
89475553=begin original
89485554
8949Calls the System V IPC function L<msgctl(2)>. You'll probably have to say
5555Calls the System V IPC function msgctl(2). You'll probably have to say
89505556
8951=end original
8952
8953System V IPC 関数 L<msgctl(2)> を呼び出します。
8954正しい定数定義を得るために、まず
8955
89565557 use IPC::SysV;
89575558
8958=begin original
8959
89605559first to get the correct constant definitions. If CMD is C<IPC_STAT>,
8961then ARG must be a variable that will hold the returned C<msqid_ds>
5560then ARG must be a variable which will hold the returned C<msqid_ds>
8962structure. Returns like L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>:
5561structure. Returns like C<ioctl>: the undefined value for error,
8963the undefined value for error, C<"0 but true"> for zero, or the actual
5562C<"0 but true"> for zero, or the actual return value otherwise. See also
8964return value otherwise. See also L<perlipc/"SysV IPC"> and the
5563L<perlipc/"SysV IPC">, C<IPC::SysV>, and C<IPC::Semaphore> documentation.
8965documentation for L<C<IPC::SysV>|IPC::SysV> and
8966L<C<IPC::Semaphore>|IPC::Semaphore>.
89675564
89685565=end original
89695566
8970と書くことが必要でょう
5567System V IPC 関数 msgctl を呼び出ます正しい定数定義を得るために、まず
5568
5569 use IPC::SysV;
5570
5571と宣言する必要があるでしょう。
89715572CMD が C<IPC_STAT> であれば、ARG は返される C<msqid_ds> 構造体を
89725573納める変数でなければなりません。
8973L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同じように、エラー時には
5574C<ioctl> と同じように、エラー時には未定義値、
8974未定義値、ゼロのときは C<"0 but true">、それ以外なら、その値そのものを
5575ゼロのときは C<"0 but true">、それ以外なら、その値そのものを返します。
8975ます
5576L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::Semaphore> も参照てください
8976L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>,
8977L<C<IPC::Semaphore>|IPC::Semaphore> の文書も参照してください。
89785577
8979=begin original
8980
8981Portability issues: L<perlport/msgctl>.
8982
8983=end original
8984
8985移植性の問題: L<perlport/msgctl>。
8986
89875578=item msgget KEY,FLAGS
8988X<msgget>
89895579
8990=for Pod::Functions get SysV IPC message queue
8991
89925580=begin original
89935581
8994Calls the System V IPC function L<msgget(2)>. Returns the message queue
5582Calls the System V IPC function msgget(2). Returns the message queue
8995id, or L<C<undef>|/undef EXPR> on error. See also L<perlipc/"SysV IPC">
5583id, or the undefined value if there is an error. See also
8996and the documentation for L<C<IPC::SysV>|IPC::SysV> and
5584L<perlipc/"SysV IPC"> and C<IPC::SysV> and C<IPC::Msg> documentation.
8997L<C<IPC::Msg>|IPC::Msg>.
89985585
89995586=end original
90005587
9001System V IPC 関数 L<msgget(2)> を呼び出します。
5588System V IPC 関数 msgget を呼び出します。
9002メッセージキューの ID か、エラー時には L<C<undef>|/undef EXPR> を返します。
5589メッセージキューの ID か、エラー時には未定義値を返します。
9003L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>,
5590L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::Msg> も参照してください。
9004L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。
90055591
9006=begin original
9007
9008Portability issues: L<perlport/msgget>.
9009
9010=end original
9011
9012移植性の問題: L<perlport/msgget>。
9013
90145592=item msgrcv ID,VAR,SIZE,TYPE,FLAGS
9015X<msgrcv>
90165593
9017=for Pod::Functions receive a SysV IPC message from a message queue
9018
90195594=begin original
90205595
90215596Calls the System V IPC function msgrcv to receive a message from
90225597message queue ID into variable VAR with a maximum message size of
90235598SIZE. Note that when a message is received, the message type as a
90245599native long integer will be the first thing in VAR, followed by the
90255600actual message. This packing may be opened with C<unpack("l! a*")>.
9026Taints the variable. Returns true if successful, false
5601Taints the variable. Returns true if successful, or false if there is
9027on error. See also L<perlipc/"SysV IPC"> and the documentation for
5602an error. See also L<perlipc/"SysV IPC">, C<IPC::SysV>, and
9028L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Msg>|IPC::Msg>.
5603C<IPC::SysV::Msg> documentation.
90295604
90305605=end original
90315606
90325607System V IPC 関数 msgrcv を呼び出し、メッセージキュー ID から、
90335608変数 VAR に最大メッセージ長 SIZE のメッセージを受信します。
90345609メッセージが受信された時、ネイティブな long 整数のメッセージタイプが
90355610VAR の先頭となり、実際のメッセージが続きます。
90365611このパッキングは C<unpack("l! a*")> で展開できます。
90375612変数は汚染されます。
9038成功時には真を、エラー時には偽を返します。
5613成功時には真を返し、エラー時には偽を返します。
9039L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>,
5614L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Msg> も参照してください。
9040L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。
90415615
9042=begin original
9043
9044Portability issues: L<perlport/msgrcv>.
9045
9046=end original
9047
9048移植性の問題: L<perlport/msgrcv>。
9049
90505616=item msgsnd ID,MSG,FLAGS
9051X<msgsnd>
90525617
9053=for Pod::Functions send a SysV IPC message to a message queue
9054
90555618=begin original
90565619
90575620Calls the System V IPC function msgsnd to send the message MSG to the
90585621message queue ID. MSG must begin with the native long integer message
9059type, be followed by the length of the actual message, and then finally
5622type, and be followed by the length of the actual message, and finally
90605623the message itself. This kind of packing can be achieved with
90615624C<pack("l! a*", $type, $message)>. Returns true if successful,
9062false on error. See also L<perlipc/"SysV IPC"> and the documentation
5625or false if there is an error. See also C<IPC::SysV>
9063for L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Msg>|IPC::Msg>.
5626and C<IPC::SysV::Msg> documentation.
90645627
90655628=end original
90665629
90675630System V IPC 関数 msgsnd を呼び出し、メッセージキュー ID に
90685631メッセージ MSG を送信します。
9069MSG の先頭は、ネイティブな long 整数のメッセージタイプでなければならず、
5632MSG の先頭は、ネイティブなlong 整数のメッセージタイプでなければならず、
90705633メッセージの長さ、メッセージ本体と続きます。
90715634これは、C<pack("l! a*", $type, $message)> として生成できます。
90725635成功時には真を、エラー時には偽を返します。
9073L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>,
5636C<IPC::SysV> と C<IPC::SysV::Msg> も参照してください。
9074L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。
90755637
9076=begin original
5638=item my EXPR
90775639
9078Portability issues: L<perlport/msgsnd>.
5640=item my EXPR : ATTRIBUTES
90795641
9080=end original
9081
9082移植性の問題: L<perlport/msgsnd>。
9083
9084=item my VARLIST
9085X<my>
9086
9087=item my TYPE VARLIST
9088
9089=item my VARLIST : ATTRS
9090
9091=item my TYPE VARLIST : ATTRS
9092
9093=for Pod::Functions declare and assign a local variable (lexical scoping)
9094
90955642=begin original
90965643
9097A L<C<my>|/my VARLIST> declares the listed variables to be local
5644A C<my> declares the listed variables to be local (lexically) to the
9098(lexically) to the enclosing block, file, or L<C<eval>|/eval EXPR>. If
5645enclosing block, file, or C<eval>. If
9099more than one variable is listed, the list must be placed in
5646more than one value is listed, the list must be placed in parentheses. See
9100parentheses.
9101
9102=end original
9103
9104L<C<my>|/my VARLIST> はリストアップされた変数を、囲っているブロック、ファイル、
9105L<C<eval>|/eval EXPR> の中でローカルな (レキシカルな) ものにします。
9106複数の変数を指定する場合は、リストはかっこでくくらなければなりません。
9107
9108=begin original
9109
9110The exact semantics and interface of TYPE and ATTRS are still
9111evolving. TYPE may be a bareword, a constant declared
9112with L<C<use constant>|constant>, or L<C<__PACKAGE__>|/__PACKAGE__>. It
9113is
9114currently bound to the use of the L<fields> pragma,
9115and attributes are handled using the L<attributes> pragma, or starting
9116from Perl 5.8.0 also via the L<Attribute::Handlers> module. See
91175647L<perlsub/"Private Variables via my()"> for details.
91185648
91195649=end original
91205650
9121TYPE と ATTRS の正確な文法とインターフェース今でも進化しています。
5651C<my>リストアップされた変数を、囲っているブロック、ファイル、
9122TYPE は、裸の単語、L<C<use constant>|constant>宣言された定数、
5652C<eval> の中ローカルな (レキシカルな) ものにします。
9123L<C<__PACKAGE__>|/__PACKAGE__> いずれかです。
5653複数値を並べる場合には、括弧括る必要があります。
9124現在のところ、TYPE L<fields> プラグマの使用と結び付けられていて、
5654詳しくはL<perlsub/"Private Variables via my()">を参照しくださ
9125属性は L<attributes> プラグマか、Perl 5.8.0 からは
9126L<Attribute::Handlers> モジュールと結び付けられています。
9127詳しくは L<perlsub/"Private Variables via my()"> を参照してください。
91285655
9129=begin original
9130
9131Note that with a parenthesised list, L<C<undef>|/undef EXPR> can be used
9132as a dummy placeholder, for example to skip assignment of initial
9133values:
9134
9135=end original
9136
9137かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> は、例えば初期値の代入を
9138飛ばすために、ダミーのプレースホルダとして使えることに注意してください:
9139
9140 my ( undef, $min, $hour ) = localtime;
9141
91425656=item next LABEL
9143X<next> X<continue>
91445657
9145=item next EXPR
9146
91475658=item next
91485659
9149=for Pod::Functions iterate a block prematurely
9150
91515660=begin original
91525661
9153The L<C<next>|/next LABEL> command is like the C<continue> statement in
5662The C<next> command is like the C<continue> statement in C; it starts
9154C; it starts the next iteration of the loop:
5663the next iteration of the loop:
91555664
91565665=end original
91575666
9158L<C<next>|/next LABEL> コマンドは、C での C<continue> 文のようなもので、
5667C<next> コマンドは、C での C<continue> 文のようなもので、
91595668ループの次の繰り返しを開始します:
91605669
91615670 LINE: while (<STDIN>) {
9162 next LINE if /^#/; # discard comments
5671 next LINE if /^#/; # discard comments
9163 #...
5672 #...
91645673 }
91655674
91665675=begin original
91675676
9168Note that if there were a L<C<continue>|/continue BLOCK> block on the
5677Note that if there were a C<continue> block on the above, it would get
9169above, it would get
5678executed even on discarded lines. If the LABEL is omitted, the command
9170executed even on discarded lines. If LABEL is omitted, the command
5679refers to the innermost enclosing loop.
9171refers to the innermost enclosing loop. The C<next EXPR> form, available
9172as of Perl 5.18.0, allows a label name to be computed at run time, being
9173otherwise identical to C<next LABEL>.
91745680
91755681=end original
91765682
9177L<C<continue>|/continue BLOCK> ブロックが存在すれば、たとえ捨てられる行に
5683C<continue> ブロックが存在すれば、たとえ捨てられる行に
91785684あっても、それが実行されます。
9179LABEL が省略されると、コマンドは一番内側のループを参照します。
5685LABEL が省略されると、このコマンドはもっとも内側のループを参照します。
9180Perl 5.18.0 から利用可能な C<next EXPR> 形式では、実行時に計算される
9181ラベル名が使えます; それ以外は C<next LABEL> と同一です。
91825686
91835687=begin original
91845688
9185L<C<next>|/next LABEL> cannot return a value from a block that typically
5689C<next> cannot be used to exit a block which returns a value such as
9186returns a value, such as C<eval {}>, C<sub {}>, or C<do {}>. It will perform
5690C<eval {}>, C<sub {}> or C<do {}>, and should not be used to exit
9187its flow control behavior, which precludes any return value. It should not be
5691a grep() or map() operation.
9188used to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST>
9189operation.
91905692
91915693=end original
91925694
9193L<C<next>|/next LABEL> は C<eval {}>, C<sub {}>, C<do {}> といった
5695C<next> は C<eval {}>, C<sub {}>, C<do {}> のように値を返す
9194典型的には値を返すブロックから値を返せません。
5696ブロックから抜けるのには使えません。
9195これは返り値を不可能にすフロー制御振る舞いを実行し
5697またgrep() や map() 操作から抜けるのに使うべきではありせん
9196L<C<grep>|/grep BLOCK LIST> や L<C<map>|/map BLOCK LIST> 操作を終了するのに
9197使うべきではありません。
91985698
91995699=begin original
92005700
92015701Note that a block by itself is semantically identical to a loop
9202that executes once. Thus L<C<next>|/next LABEL> will exit such a block
5702that executes once. Thus C<next> will exit such a block early.
9203early.
92045703
92055704=end original
92065705
92075706ブロック自身は一回だけ実行されるループと文法的に同一であることに
92085707注意してください。
9209従って、L<C<next>|/next LABEL> はそのようなブロックから早く抜けるのに使えます。
5708従って、C<next> はそのようなブロックから早く抜けるのに使えます。
92105709
92115710=begin original
92125711
9213See also L<C<continue>|/continue BLOCK> for an illustration of how
5712See also L</continue> for an illustration of how C<last>, C<next>, and
9214L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and
5713C<redo> work.
9215L<C<redo>|/redo LABEL> work.
92165714
92175715=end original
92185716
9219L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL>
5717C<last>, C<next>, C<redo> がどのように働くかについては
9220どのように働くかについては L<C<continue>|/continue BLOCK> も参照してください。
5718L</continue> も参照してさい。
92215719
9222=begin original
5720=item no Module LIST
92235721
9224Unlike most named operators, this has the same precedence as assignment.
9225It is also exempt from the looks-like-a-function rule, so
9226C<next ("foo")."bar"> will cause "bar" to be part of the argument to
9227L<C<next>|/next LABEL>.
9228
9229=end original
9230
9231ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
9232また、関数のように見えるものの規則からも免れるので、C<next ("foo")."bar"> と
9233すると "bar" は L<C<next>|/next LABEL> への引数の一部となります。
9234
9235=item no MODULE VERSION LIST
9236X<no declarations>
9237X<unimporting>
9238
9239=item no MODULE VERSION
9240
9241=item no MODULE LIST
9242
9243=item no MODULE
9244
9245=item no VERSION
9246
9247=for Pod::Functions unimport some module symbols or semantics at compile time
9248
92495722=begin original
92505723
9251See the L<C<use>|/use Module VERSION LIST> function, of which
5724See the L</use> function, which C<no> is the opposite of.
9252L<C<no>|/no MODULE VERSION LIST> is the opposite.
92535725
92545726=end original
92555727
9256L<C<use>|/use Module VERSION LIST> 関数を参照してください;
5728L</use> 関数を参照してください。C<no> は、その逆を行なうものです。
9257L<C<no>|/no MODULE VERSION LIST> は、その逆を行なうものです。
92585729
92595730=item oct EXPR
9260X<oct> X<octal> X<hex> X<hexadecimal> X<binary> X<bin>
92615731
92625732=item oct
92635733
9264=for Pod::Functions convert a string to an octal number
9265
92665734=begin original
92675735
92685736Interprets EXPR as an octal string and returns the corresponding
92695737value. (If EXPR happens to start off with C<0x>, interprets it as a
92705738hex string. If EXPR starts off with C<0b>, it is interpreted as a
9271binary string. Leading whitespace is ignored in all three cases.)
5739binary string.) The following will handle decimal, binary, octal, and
9272The following will handle decimal, binary, octal, and hex in standard
5740hex in the standard Perl or C notation:
9273Perl notation:
92745741
92755742=end original
92765743
92775744EXPR を 8 進数文字列と解釈して、対応する値を返します。
92785745(EXPR が C<0x> で始まるときには、16 進数文字列と解釈します。
9279EXPR が C<0b>で始まるときは、2 進数文字列と解釈します。
5746EXPR が C<0b>で始まるときは、2 進数文字列と解釈します。)
9280場合でも先頭空白は無視されます。)
5747以下例は標準的な Perl や C 記法での
9281以下の例は、標準的な Perl の記法での
9282574810 進数、2 進数、8 進数、16 進数を扱います:
92835749
92845750 $val = oct($val) if $val =~ /^0/;
92855751
92865752=begin original
92875753
9288If EXPR is omitted, uses L<C<$_>|perlvar/$_>. To go the other way
5754If EXPR is omitted, uses C<$_>. To go the other way (produce a number
9289(produce a number in octal), use L<C<sprintf>|/sprintf FORMAT, LIST> or
5755in octal), use sprintf() or printf():
9290L<C<printf>|/printf FILEHANDLE FORMAT, LIST>:
92915756
92925757=end original
92935758
9294EXPR 省略されると、L<C<$_>|perlvar/$_> を使ます。
5759EXPR 省略ると、C<$_> を使用します。
9295(8 進数を扱う)その他の方法としては L<C<sprintf>|/sprintf FORMAT, LIST> や
5760(8 進数を扱う)その他の方法としては sprintf() または printf()があります。
9296L<C<printf>|/printf FILEHANDLE FORMAT, LIST> があります:
92975761
9298 my $dec_perms = (stat("filename"))[2] & 07777;
5762 $perms = (stat("filename"))[2] & 07777;
9299 my $oct_perm_str = sprintf "%o", $perms;
5763 $oct_perms = sprintf "%lo", $perms;
93005764
93015765=begin original
93025766
9303The L<C<oct>|/oct EXPR> function is commonly used when a string such as
5767The oct() function is commonly used when a string such as C<644> needs
9304C<644> needs
5768to be converted into a file mode, for example. (Although perl will
9305to be converted into a file mode, for example. Although Perl
5769automatically convert strings into numbers as needed, this automatic
9306automatically converts strings into numbers as needed, this automatic
5770conversion assumes base 10.)
9307conversion assumes base 10.
93085771
93095772=end original
93105773
9311L<C<oct>|/oct EXPR> 関数は例えば、 C<644> といった文字列をファイルモードに
5774oct() 関数は例えば、 C<644> といった文字列をファイルモードに変換する時
9312変換する時によく使います。
5775よく使います。
9313Perl は必要に応じて自動的に文字列を数値に変換しますが、
5776(Perl は必要に応じて自動的に文字列を数値に変換しますが、
9314この自動変換は十進数を仮定します。
5777この自動変換は十進数を仮定します。)
93155778
9316=begin original
5779=item open FILEHANDLE,MODE,LIST
93175780
9318Leading white space is ignored without warning, as too are any trailing
9319non-digits, such as a decimal point (L<C<oct>|/oct EXPR> only handles
9320non-negative integers, not negative integers or floating point).
9321
9322=end original
9323
9324先頭の空白や、末尾の(小数点のような)非数字は警告なしに無視されます
9325(L<C<oct>|/oct EXPR> は非負整数のみを扱えます; 負の整数や小数は扱えません)。
9326
93275781=item open FILEHANDLE,EXPR
9328X<open> X<pipe> X<file, open> X<fopen>
93295782
9330=item open FILEHANDLE,MODE,EXPR
9331
9332=item open FILEHANDLE,MODE,EXPR,LIST
9333
9334=item open FILEHANDLE,MODE,REFERENCE
9335
93365783=item open FILEHANDLE
93375784
9338=for Pod::Functions open a file, pipe, or descriptor
9339
93405785=begin original
93415786
93425787Opens the file whose filename is given by EXPR, and associates it with
9343FILEHANDLE.
5788FILEHANDLE. If FILEHANDLE is an expression, its value is used as the
5789name of the real filehandle wanted. (This is considered a symbolic
5790reference, so C<use strict 'refs'> should I<not> be in effect.)
93445791
93455792=end original
93465793
9347EXPR で与えられたファイル名ファイルを開きFILEHANDLE と結び付けます。
5794EXPR でファイル名を指定するファイルをオープンして
5795FILEHANDLE に対応させます。
5796FILEHANDLE が式のときには、その値が実際に使用するファイルハンドルの
5797名前として使われます。
5798(これはシンボリックリファレンスと考えられますので、
5799C<use strict 'refs'> はI<効果がありません>。)
93485800
93495801=begin original
93505802
9351Simple examples to open a file for reading:
5803If EXPR is omitted, the scalar
5804variable of the same name as the FILEHANDLE contains the filename.
5805(Note that lexical variables--those declared with C<my>--will not work
5806for this purpose; so if you're using C<my>, specify EXPR in your call
5807to open.) See L<perlopentut> for a kinder, gentler explanation of opening
5808files.
93525809
93535810=end original
93545811
9355読み込みのためにファイル開くため簡単な例は以下のもので:
5812EXPR 省略すると、FILEHANDLE と同じ名前スカラ変数に、
5813ファイル名が入れられているものとして処理されます。
5814(C<my> で宣言されたレキシカル変数はこの目的には使えません。
5815従って、C<my>を使った場合は、open を呼び出すときに EXPR を指定してください。)
5816ファイルのオープンに関するより親切な説明については
5817L<perlopentut> を参照して下さい。
93565818
9357 open(my $fh, "<", "input.txt")
9358 or die "Can't open < input.txt: $!";
9359
93605819=begin original
93615820
9362and for writing:
5821If MODE is C<< '<' >> or nothing, the file is opened for input.
5822If MODE is C<< '>' >>, the file is truncated and opened for
5823output, being created if necessary. If MODE is C<<< '>>' >>>,
5824the file is opened for appending, again being created if necessary.
5825You can put a C<'+'> in front of the C<< '>' >> or C<< '<' >> to indicate that
5826you want both read and write access to the file; thus C<< '+<' >> is almost
5827always preferred for read/write updates--the C<< '+>' >> mode would clobber the
5828file first. You can't usually use either read-write mode for updating
5829textfiles, since they have variable length records. See the B<-i>
5830switch in L<perlrun> for a better approach. The file is created with
5831permissions of C<0666> modified by the process' C<umask> value.
93635832
93645833=end original
93655834
9366書き込み用は以下ののです:
5835MODE が C<< '<' >> か、何付けなかった場合には、
5836入力用としてオープンされることになります。
5837MODE が C<< '>' >> の場合には、ファイルは空にされたあと出力用に
5838オープンされ、必要ならファイルが作成されます。
5839MODE が C<<< '>>' >>> の場合には、追記用にオープンされ、
5840必要ならファイルが作成されます。
5841C<< '>' >> や C<< '<' >> の前に C<'+'> を置くことで、
5842ファイルを読み書き両用にすることもできます。
5843従って、C<< '+<' >> はほとんどの場合読み書き更新をするために適したものです。
5844C<< '+>' >> は最初にファイルを上書きします。
5845テキストファイルを更新する場合には普通はどちらの読み書きモードも使えません。
5846可変長のレコードを持つからです。
5847よりよい手法については L<perlrun> の B<-i> オプションを参照して下さい。
5848作成されるファイルのパーミッションは C<0666> を
5849プロセスの C<umask> の値で修正したものになります。
93675850
9368 open(my $fh, ">", "output.txt")
9369 or die "Can't open > output.txt: $!";
9370
93715851=begin original
93725852
9373(The following is a comprehensive reference to
5853These various prefixes correspond to the fopen(3) modes of C<'r'>, C<'r+'>,
9374L<C<open>|/open FILEHANDLE,EXPR>: for a gentler introduction you may
5854C<'w'>, C<'w+'>, C<'a'>, and C<'a+'>.
9375consider L<perlopentut>.)
93765855
93775856=end original
93785857
9379(以下は総合的L<C<open>|/open FILEHANDLE,EXPR> のリファレンスです:
5858これらの様々前置詞は fopen(3) の C<'r'>, C<'r+'>,
9380より親切な説明については L<perlopentut> を参照てください)
5859C<'w'>, C<'w+'>, C<'a'>, C<'a+'> のモードに対応ます
93815860
93825861=begin original
93835862
9384If FILEHANDLE is an undefined scalar variable (or array or hash element), a
5863In the 2-arguments (and 1-argument) form of the call the mode and
9385new filehandle is autovivified, meaning that the variable is assigned a
5864filename should be concatenated (in this order), possibly separated by
9386reference to a newly allocated anonymous filehandle. Otherwise if
5865spaces. It is possible to omit the mode if the mode is C<< '<' >>.
9387FILEHANDLE is an expression, its value is the real filehandle. (This is
9388considered a symbolic reference, so C<use strict "refs"> should I<not> be
9389in effect.)
93905866
93915867=end original
93925868
9393FILEHANDLE が未定義のスカラ変数(また配列かハッシュ要素)の場合、
58692 数(と 1 引数) の形式でモードとファイル名は(こ順番で)
9394新しいファイルハンドルが自動有効化され、その変数は新しくり当
5870結合されます(空白によって分されいるかもしません)。
9395無名ファイルハンルへのリファレンス代入されます。
5871モードが C<< '<' >> の場合はモードを省略できます。
9396さもなければ、もし FILEHANDLE が式なら、その値を求めている実際の
9397ファイルハンドルの名前として使います。
9398(これはシンボリックリファレンスとして扱われるので、
9399C<use strict "refs"> の影響を I<受けません>。)
94005872
94015873=begin original
94025874
9403If three (or more) arguments are specified, the open mode (including
5875If the filename begins with C<'|'>, the filename is interpreted as a
9404optional encoding) in the second argument are distinct from the filename in
5876command to which output is to be piped, and if the filename ends with a
9405the third. If MODE is C<< < >> or nothing, the file is opened for input.
5877C<'|'>, the filename is interpreted as a command which pipes output to
9406If MODE is C<< > >>, the file is opened for output, with existing files
5878us. See L<perlipc/"Using open() for IPC">
9407first being truncated ("clobbered") and nonexisting files newly created.
5879for more examples of this. (You are not allowed to C<open> to a command
9408If MODE is C<<< >> >>>, the file is opened for appending, again being
5880that pipes both in I<and> out, but see L<IPC::Open2>, L<IPC::Open3>,
9409created if necessary.
5881and L<perlipc/"Bidirectional Communication with Another Process">
5882for alternatives.)
94105883
94115884=end original
94125885
94133 (またはそれ以上)引数が指定された場合、2 番目の引数の(オプションの
5886ファイル名先頭に C<'|'> を付けると、
9414エンーディグを含む)開く時のモー3 番目のファイル名と分離されます。
5887そのファイル名をンドとして解釈し、ファイルハンドルへの
9415MODE C<< < >> か空の場合、ファルは入力用に開かれます。
5888出力プを通じて、そのコマンドへ入力れます。
9416MODE C<< > >> の場合、ファイルは出力用開かれ既にファイルが
5889逆にファイル名の最後に C<'|'> を付けた場合に
9417ある場合は切り詰められ(上書きされ)、ない場合は新く作られます。
5890同様にファイル名をコマンドと解釈、そのコマンドの出力がパイプを通じて、
9418MODE が C<<< >> >>> の場合、ファイルは追加用に開れ、やはり必要な
5891ファイルハンドルから入力として読み込むことができるようになります。
9419作成さ
5892に関るさらなる例については L<perlipc/"Using open() for IPC"> を
5893参照してください。
5894(C<open> を入出力 I<両用> にパイプすることは出来ませんが
5895代替案としては L<IPC::Open2>, L<IPC::Open3>,
5896L<perlipc/"Bidirectional Communication with Another Process">
5897を参照してください。)
94205898
94215899=begin original
94225900
9423You can put a C<+> in front of the C<< > >> or C<< < >> to
5901If MODE is C<'|-'>, the filename is interpreted as a
9424indicate that you want both read and write access to the file; thus
5902command to which output is to be piped, and if MODE is
9425C<< +< >> is almost always preferred for read/write updates--the
5903C<'-|'>, the filename is interpreted as a command which pipes output to
9426C<< +> >> mode would clobber the file first. You can't usually use
5904us. In the 2-arguments (and 1-argument) form one should replace dash
9427either read-write mode for updating textfiles, since they have
5905(C<'-'>) with the command. See L<perlipc/"Using open() for IPC">
9428variable-length records. See the B<-i> switch in L<perlrun> for a
5906for more examples of this. (You are not allowed to C<open> to a command
9429better approach. The file is created with permissions of C<0666>
5907that pipes both in I<and> out, but see L<IPC::Open2>, L<IPC::Open3>,
9430modified by the process's L<C<umask>|/umask EXPR> value.
5908and L<perlipc/"Bidirectional Communication"> for alternatives.)
94315909
94325910=end original
94335911
9434ファイルに読み込みアクセス書き込みアクセスの両方をたいことを示すために、
5912MODE が C<'|-'> の場合、ファイル名は出力がパイプされるコマンドとし
9435C<< > >> や C<< < >>前に C<+> を付けることできます:
5913解釈され、MODE C<'-|'> の場合、ファイル名は出力こちらに
9436従って、ほとんど常に C<< +< >> が読み書き更新のために使われます --
9437C<< +> >> モードはまずファイルを上書きします。
9438普通はこれらの読み書きモードをテキストファイルの更新のためには使えません;
9439なぜなら可変長のレコードで構成されているからです。
9440よりよい手法については L<perlrun> の B<-i> オプションを参照してください。
9441ファイルは C<0666> をプロセスの L<C<umask>|/umask EXPR> 値で修正した
9442パーミッションで作成されます。
9443
9444=begin original
9445
9446These various prefixes correspond to the L<fopen(3)> modes of C<r>,
9447C<r+>, C<w>, C<w+>, C<a>, and C<a+>.
9448
9449=end original
9450
9451これらの様々な前置詞は L<fopen(3)> の C<r>, C<r+>,
9452C<w>, C<w+>, C<a>, C<a+> のモードに対応します。
9453
9454=begin original
9455
9456In the one- and two-argument forms of the call, the mode and filename
9457should be concatenated (in that order), preferably separated by white
9458space. You can--but shouldn't--omit the mode in these forms when that mode
9459is C<< < >>. It is safe to use the two-argument form of
9460L<C<open>|/open FILEHANDLE,EXPR> if the filename argument is a known literal.
9461
9462=end original
9463
94641 引数 と 2 引数の形式ではモードとファイル名は(この順番で)
9465結合されます(空白によって分割されているかもしれません)。
9466この形式で、モードが C<< '<' >> の場合はモードを省略できます (が、
9467するべきではありません)。
9468ファイル引数が既知のリテラルの場合、2 引数形式の
9469L<C<open>|/open FILEHANDLE,EXPR> は安全です。
9470
9471=begin original
9472
9473For three or more arguments if MODE is C<|->, the filename is
9474interpreted as a command to which output is to be piped, and if MODE
9475is C<-|>, the filename is interpreted as a command that pipes
9476output to us. In the two-argument (and one-argument) form, one should
9477replace dash (C<->) with the command.
9478See L<perlipc/"Using open() for IPC"> for more examples of this.
9479(You are not allowed to L<C<open>|/open FILEHANDLE,EXPR> to a command
9480that pipes both in I<and> out, but see L<IPC::Open2>, L<IPC::Open3>, and
9481L<perlipc/"Bidirectional Communication with Another Process"> for
9482alternatives.)
9483
9484=end original
9485
94863 引数以上の形式で
9487MODE が C<|-> の場合、ファイル名は出力がパイプされるコマンドとして
9488解釈され、MODE が C<-|> の場合、ファイル名は出力がこちらに
94895914パイプされるコマンドとして解釈されます。
94902 引数(と 1 引数) の形式ではハイフン(C<->)をコマンドの代わりに使えます。
59152 引数(と 1 引数) の形式ではハイフン(C<'-'>)をコマンドの代わりに
5916使えます。
94915917これに関するさらなる例については L<perlipc/"Using open() for IPC"> を
94925918参照してください。
9493(L<C<open>|/open FILEHANDLE,EXPR> を入出力 I<両用> にパイプすることは
5919(C<open> を入出力 I<両用> にパイプすることは出来ませんが
9494出来ませんが、代替案としては L<IPC::Open2>, L<IPC::Open3>,
5920代替案としては L<IPC::Open2>, L<IPC::Open3>,
9495L<perlipc/"Bidirectional Communication with Another Process"> を
5921L<perlipc/"Bidirectional Communication"> を参照してください。)
9496参照してください。)
94975922
94985923=begin original
94995924
9500In the form of pipe opens taking three or more arguments, if LIST is specified
5925In the 2-arguments (and 1-argument) form opening C<'-'> opens STDIN
9501(extra arguments after the command name) then LIST becomes arguments
5926and opening C<< '>-' >> opens STDOUT.
9502to the command invoked if the platform supports it. The meaning of
9503L<C<open>|/open FILEHANDLE,EXPR> with more than three arguments for
9504non-pipe modes is not yet defined, but experimental "layers" may give
9505extra LIST arguments meaning.
95065927
95075928=end original
95085929
9509パイプでの三つ以上の引数の形式では、LIST (コマンド名の後の追加の引数) が
59302 引数(と 1 引数) C<'-'> を open すると STDIN オープンされ、
9510指定されると、プラットフォームが対応していれば、LIST は起動され
5931C<< '>-' >> を open すると STDOUT がオープンされます。
9511コマンドへの引数となります。
9512パイプモードではない L<C<open>|/open FILEHANDLE,EXPR> での三つ以上の引数の
9513意味はまだ未定義ですが、実験的な「層」は追加の LIST 引数の意味を与えます。
95145932
95155933=begin original
95165934
9517In the two-argument (and one-argument) form, opening C<< <- >>
5935Open returns
9518or C<-> opens STDIN and opening C<< >- >> opens STDOUT.
5936nonzero upon success, the undefined value otherwise. If the C<open>
5937involved a pipe, the return value happens to be the pid of the
5938subprocess.
95195939
95205940=end original
95215941
95222 引数(と 1 引数)で C<< <- >> か C<-> を open すると STDIN が
9523オープンされ、C<< >- >> を open すると STDOUT がオープンされます。
9524
9525=begin original
9526
9527You may (and usually should) use the three-argument form of open to specify
9528I/O layers (sometimes referred to as "disciplines") to apply to the handle
9529that affect how the input and output are processed (see L<open> and
9530L<PerlIO> for more details). For example:
9531
9532=end original
9533
9534open の 3 引数形式では、どのように入出力が処理されるかに影響を与える
9535I/O 層(「ディシプリン」とも呼ばれます)を指定できます
9536(そして普通はそうするべきです)
9537(詳細については L<open> と L<PerlIO> を参照してください)。
9538例えば:
9539
9540 open(my $fh, "<:encoding(UTF-8)", $filename)
9541 || die "Can't open UTF-8 encoded $filename: $!";
9542
9543=begin original
9544
9545opens the UTF8-encoded file containing Unicode characters;
9546see L<perluniintro>. Note that if layers are specified in the
9547three-argument form, then default layers stored in ${^OPEN} (see L<perlvar>;
9548usually set by the L<open> pragma or the switch C<-CioD>) are ignored.
9549Those layers will also be ignored if you specify a colon with no name
9550following it. In that case the default layer for the operating system
9551(:raw on Unix, :crlf on Windows) is used.
9552
9553=end original
9554
9555は、Unicode 文字を含む UTF8 エンコードされたファイルを開きます;
9556L<perluniintro> を参照してください。
95573 引数形式で層を指定すると、${^OPEN} (L<perlvar> を参照してください;
9558通常は L<open> プラグマか C<-CioD> オプションでセットされます) に保存された
9559デフォルト層は無視されることに注意してください。
9560これらの層は、名前なしでコロンを指定した場合にも無視されます。
9561この場合 OS のデフォルトの層 (Unix では :raw、Windows では :crlf) が
9562使われます。
9563
9564=begin original
9565
9566Open returns nonzero on success, the undefined value otherwise. If
9567the L<C<open>|/open FILEHANDLE,EXPR> involved a pipe, the return value
9568happens to be the pid of the subprocess.
9569
9570=end original
9571
95725942open は、成功時にはゼロ以外を返し、失敗時には未定義値を返します。
9573パイプに関る L<C<open>|/open FILEHANDLE,EXPR> のときには、返り値は
5943パイプに関る C<open> のときには、返り値はサブプロセスの pid となります。
9574サブプロセスの pid となります。
95755944
95765945=begin original
95775946
9578On some systems (in general, DOS- and Windows-based systems)
5947If you're unfortunate enough to be running Perl on a system that
9579L<C<binmode>|/binmode FILEHANDLE, LAYER> is necessary when you're not
5948distinguishes between text files and binary files (modern operating
9580working with a text file. For the sake of portability it is a good idea
5949systems don't care), then you should check out L</binmode> for tips for
9581always to use it when appropriate, and never to use it when it isn't
5950dealing with this. The key distinction between systems that need C<binmode>
9582appropriate. Also, people can set their I/O to be by default
5951and those that don't is their text file formats. Systems like Unix, MacOS, and
9583UTF8-encoded Unicode, not bytes.
5952Plan9, which delimit lines with a single character, and which encode that
5953character in C as C<"\n">, do not need C<binmode>. The rest need it.
95845954
95855955=end original
95865956
9587テキストファイルでないもの扱う場合に
5957不幸にしてテキストファイルとバイナリファイル区別するシステムで
9588L<C<binmode>|/binmode FILEHANDLE, LAYER> が必要な
5958Perl を動かす場合(最近の OS は区別しません)、これを扱うための
9589システムもあります(一般的には DOS Windows ベースのシステムです)
5959TIPS について L</binmode> をチェックするべきです。
9590移植性のために、適切なときには常にこれを使い、適切でいときに
5960C<binmode> が必要システム不要システムを区別する鍵
9591決して使わないというは良い考えです。
5961テキストファイル形式です。
9592また、デフォルトとして I/O bytes では UTF-8 エンコードされ
5962Unix, MacOS, Plan9 のよう、行が 1 文字で分割され、その文字が
9593Unicode にセットすることも出来ます。
5963C では C<"\n"> でエンコードされる場合、C<binmode> は不要です。
5964そうでない場合は必要です。
95945965
95955966=begin original
95965967
9597When opening a file, it's seldom a good idea to continue
5968When opening a file, it's usually a bad idea to continue normal execution
9598if the request failed, so L<C<open>|/open FILEHANDLE,EXPR> is frequently
5969if the request failed, so C<open> is frequently used in connection with
9599used with L<C<die>|/die LIST>. Even if L<C<die>|/die LIST> won't do
5970C<die>. Even if C<die> won't do what you want (say, in a CGI script,
9600what you want (say, in a CGI script,
5971where you want to make a nicely formatted error message (but there are
9601where you want to format a suitable error message (but there are
5972modules that can help with that problem)) you should always check
9602modules that can help with that problem)) always check
5973the return value from opening a file. The infrequent exception is when
9603the return value from opening a file.
5974working with an unopened filehandle is actually what you want to do.
96045975
96055976=end original
96065977
9607ファイルを開く時、開くのに失敗した時に通常の処理を続けるのは普通は悪い
5978ファイルを開く時、開くのに失敗した時に通常の処理を続けるのは
9608考えので、L<C<open>|/open FILEHANDLE,EXPR> はしばしば
5979普通は悪い考えですので、C<open> はしばしば C<die> と結び付けられて
9609L<C<die>|/die LIST> と結び付けられて使われます。
5980使われます。
9610望むものが L<C<die>|/die LIST> でない場合(例えば、CGI スクリプトのように
5981望むものが C<die> ない場合(例えば、CGI スクリプト のように
96115982きれいにフォーマットされたエラーメッセージを作りたい場合
96125983(但しこの問題を助けるモジュールがあります))でも、
9613ファイルを開いた時のり値を常にチェックするべきです。
5984ファイルを開いた時のり値を常にチェックするべきです。
5985めったにない例外は、開いていないファイルハンドルを使うのが
5986本当にやりたいことの場合です。
96145987
96155988=begin original
96165989
9617The filehandle will be closed when its reference count reaches zero.
5990Examples:
9618If it is a lexically scoped variable declared with L<C<my>|/my VARLIST>,
9619that usually
9620means the end of the enclosing scope. However, this automatic close
9621does not check for errors, so it is better to explicitly close
9622filehandles, especially those used for writing:
96235991
96245992=end original
96255993
9626ファイルハンドルは、参照カウントが 0 になったときに閉じられます。
5994例:
9627これが L<C<my>|/my VARLIST> で宣言されたレキシカルスコープを持つ変数の場合、
9628普通は囲まれたスコープの終わりを意味します。
9629しかし、この自動閉じはエラーをチェックしないので、特に書き込み用の場合は、
9630明示的にファイルハンドルを閉じる方がよいです。
96315995
9632 close($handle)
9633 || warn "close failed: $!";
9634
9635=begin original
9636
9637An older style is to use a bareword as the filehandle, as
9638
9639=end original
9640
9641より古いスタイルは、次のように、ファイルハンドルとして裸の単語を使います
9642
9643 open(FH, "<", "input.txt")
9644 or die "Can't open < input.txt: $!";
9645
9646=begin original
9647
9648Then you can use C<FH> as the filehandle, in C<< close FH >> and C<<
9649<FH> >> and so on. Note that it's a global variable, so this form is
9650not recommended in new code.
9651
9652=end original
9653
9654それから C<FH> を、C<< close FH >> や C<< <FH> >> などのように、
9655ファイルハンドルとして使えます。
9656これはグローバル変数なので、新しいコードでは非推奨であることに
9657注意してください。
9658
9659=begin original
9660
9661As a shortcut a one-argument call takes the filename from the global
9662scalar variable of the same name as the filehandle:
9663
9664=end original
9665
9666短縮版として、1 引数呼び出しでは、ファイル名を、ファイルハンドルと同じ名前の
9667グローバルなスカラ変数から取ります:
9668
96695996 $ARTICLE = 100;
9670 open(ARTICLE) or die "Can't find article $ARTICLE: $!\n";
5997 open ARTICLE or die "Can't find article $ARTICLE: $!\n";
5998 while (<ARTICLE>) {...
96715999
9672=begin original
6000 open(LOG, '>>/usr/spool/news/twitlog'); # (log is reserved)
6001 # if the open fails, output is discarded
96736002
9674Here C<$ARTICLE> must be a global (package) scalar variable - not one
6003 open(DBASE, '+<', 'dbase.mine') # open for update
9675declared with L<C<my>|/my VARLIST> or L<C<state>|/state VARLIST>.
6004 or die "Can't open 'dbase.mine' for update: $!";
96766005
9677=end original
6006 open(DBASE, '+<dbase.mine') # ditto
6007 or die "Can't open 'dbase.mine' for update: $!";
96786008
9679ここで C<$ARTICLE> はグローバル(パッケージ)スカラ変数でなければなりません -
6009 open(ARTICLE, '-|', "caesar <$article") # decrypt article
9680L<C<my>|/my VARLIST> や L<C<state>|/state VARLIST> で宣言された
6010 or die "Can't start caesar: $!";
9681変数ではありません。
96826011
9683=begin original
6012 open(ARTICLE, "caesar <$article |") # ditto
6013 or die "Can't start caesar: $!";
96846014
9685As a special case the three-argument form with a read/write mode and the third
6015 open(EXTRACT, "|sort >/tmp/Tmp$$") # $$ is our process id
9686argument being L<C<undef>|/undef EXPR>:
6016 or die "Can't start sort: $!";
96876017
9688=end original
6018 # process argument list of files along with any includes
96896019
9690特別な場合として、3 引数の形で読み書きモードで 3 番目の引数が
6020 foreach $file (@ARGV) {
9691L<C<undef>|/undef EXPR> の場合:
6021 process($file, 'fh00');
6022 }
96926023
9693 open(my $tmp, "+>", undef) or die ...
6024 sub process {
6025 my($filename, $input) = @_;
6026 $input++; # this is a string increment
6027 unless (open($input, $filename)) {
6028 print STDERR "Can't open $filename: $!\n";
6029 return;
6030 }
96946031
9695=begin original
6032 local $_;
6033 while (<$input>) { # note use of indirection
6034 if (/^#include "(.*)"/) {
6035 process($1, $input);
6036 next;
6037 }
6038 #... # whatever
6039 }
6040 }
96966041
9697opens a filehandle to a newly created empty anonymous temporary file.
9698(This happens under any mode, which makes C<< +> >> the only useful and
9699sensible mode to use.) You will need to
9700L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> to do the reading.
9701
9702=end original
9703
9704新しく作成した空の無名一時ファイルとしてファイルハンドルを開きます。
9705(これはどのモードでも起こりますが、C<< +> >> のみが有用で意味があります)
9706読み込みを行うためには L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> が
9707必要です。
9708
97096042=begin original
97106043
9711Perl is built using PerlIO by default. Unless you've
9712changed this (such as building Perl with C<Configure -Uuseperlio>), you can
9713open filehandles directly to Perl scalars via:
9714
9715=end original
9716
9717Perl はデフォルトで PerlIO を使ってビルドされています。
9718(C<Configure -Uuseperlio> して Perl をビルドするなどして)これを
9719変更していない限り、以下のようにして、Perl スカラを直接ファイルハンドルで
9720開くことができます:
9721
9722 open(my $fh, ">", \$variable) || ..
9723
9724=begin original
9725
9726To (re)open C<STDOUT> or C<STDERR> as an in-memory file, close it first:
9727
9728=end original
9729
9730C<STDOUT> や C<STDERR> を「オンメモリの」ファイルとして
9731再び開きたい場合は、先にそれを閉じます:
9732
9733 close STDOUT;
9734 open(STDOUT, ">", \$variable)
9735 or die "Can't open STDOUT: $!";
9736
9737=begin original
9738
9739The scalars for in-memory files are treated as octet strings: unless
9740the file is being opened with truncation the scalar may not contain
9741any code points over 0xFF.
9742
9743=end original
9744
9745オンメモリファイルのためのスカラはオクテット文字列として扱われます:
9746ファイルが切り詰められて開かれない限り、
9747スカラは 0xFF を超える符号位置を含みません。
9748
9749=begin original
9750
9751Opening in-memory files I<can> fail for a variety of reasons. As with
9752any other C<open>, check the return value for success.
9753
9754=end original
9755
9756オンメモリファイルを開くのは様々な理由で失敗する I<ことがあります>。
9757その他の C<open> と同様、成功したかを返り値でチェックしてください。
9758
9759=begin original
9760
9761See L<perliol> for detailed info on PerlIO.
9762
9763=end original
9764
9765PerlIO に関する詳しい情報については L<perliol> を参照してください。
9766
9767=begin original
9768
9769General examples:
9770
9771=end original
9772
9773一般的な例:
9774
9775 open(my $log, ">>", "/usr/spool/news/twitlog");
9776 # if the open fails, output is discarded
9777
9778 open(my $dbase, "+<", "dbase.mine") # open for update
9779 or die "Can't open 'dbase.mine' for update: $!";
9780
9781 open(my $dbase, "+<dbase.mine") # ditto
9782 or die "Can't open 'dbase.mine' for update: $!";
9783
9784 open(my $article_fh, "-|", "caesar <$article") # decrypt
9785 # article
9786 or die "Can't start caesar: $!";
9787
9788 open(my $article_fh, "caesar <$article |") # ditto
9789 or die "Can't start caesar: $!";
9790
9791 open(my $out_fh, "|-", "sort >Tmp$$") # $$ is our process id
9792 or die "Can't start sort: $!";
9793
9794 # in-memory files
9795 open(my $memory, ">", \$var)
9796 or die "Can't open memory file: $!";
9797 print $memory "foo!\n"; # output will appear in $var
9798
9799=begin original
9800
98016044You may also, in the Bourne shell tradition, specify an EXPR beginning
9802with C<< >& >>, in which case the rest of the string is interpreted
6045with C<< '>&' >>, in which case the rest of the string is interpreted as the
9803as the name of a filehandle (or file descriptor, if numeric) to be
6046name of a filehandle (or file descriptor, if numeric) to be
9804duped (as in L<dup(2)>) and opened. You may use C<&> after C<< > >>,
6047duped and opened. You may use C<&> after C<< > >>, C<<< >> >>>,
9805C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>, and C<< +< >>.
6048C<< < >>, C<< +> >>, C<<< +>> >>>, and C<< +< >>. The
9806The mode you specify should match the mode of the original filehandle.
6049mode you specify should match the mode of the original filehandle.
9807(Duping a filehandle does not take into account any existing contents
6050(Duping a filehandle does not take into account any existing contents of
9808of IO buffers.) If you use the three-argument
6051stdio buffers.) Duping file handles is not yet supported for 3-argument
9809form, then you can pass either a
6052open().
9810number, the name of a filehandle, or the normal "reference to a glob".
98116053
98126054=end original
98136055
9814Bourne シェルの慣例にしたがって、EXPR の先頭に C<< >& >>
6056Bourne シェルの慣例にしたがって、EXPR の先頭に C<< '>&' >>
98156057を付けると、EXPR の残りの文字列をファイルハンドル名
9816(数字であれば、ファイル記述子) と解釈して、それを (L<dup(2)> によっ)
6058(数字であれば、ファイル記述子) と解釈して、それを複製しオープンします。
9817複製してオープンします。
98186059C<&> は、C<< > >>, C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>,
98196060C<< +< >>というモード指定に付けることができます。
98206061指定するモード指定は、もとのファイルハンドルのモードと
98216062合っていないといけません。
9822(ファイルハンドルの複製は既に存在する IO バッファの内容に含めません。)
6063(ファイルハンドルの複製は既に存在する stdio バッファの内容に含めません。)
98233 引数形式を使う場合は、数値を渡すか、ファイルハンドルの名前を渡すか、
6064ファイルハンドルの複製は 3 引数 open() ではまだ対応していません。
9824通常の「グロブへのリファレンス」を渡します。
98256065
98266066=begin original
98276067
9828Here is a script that saves, redirects, and restores C<STDOUT> and
6068Here is a script that saves, redirects, and restores STDOUT and
9829C<STDERR> using various methods:
6069STDERR:
98306070
98316071=end original
98326072
9833C<STDOUT>C<STDERR> 保存し、リダイレクトし、元に戻すスクリプトを示します:
6073STDOUT と STDERR 保存し、リダイレクトし、元に戻すスクリプトを示します
98346074
98356075 #!/usr/bin/perl
9836 open(my $oldout, ">&STDOUT") or die "Can't dup STDOUT: $!";
6076 open(OLDOUT, ">&STDOUT");
9837 open(OLDERR, ">&", \*STDERR) or die "Can't dup STDERR: $!";
6077 open(OLDERR, ">&STDERR");
98386078
9839 open(STDOUT, '>', "foo.out") or die "Can't redirect STDOUT: $!";
6079 open(STDOUT, '>', "foo.out") || die "Can't redirect stdout";
9840 open(STDERR, ">&STDOUT") or die "Can't dup STDOUT: $!";
6080 open(STDERR, ">&STDOUT") || die "Can't dup stdout";
98416081
9842 select STDERR; $| = 1; # make unbuffered
6082 select(STDERR); $| = 1; # make unbuffered
9843 select STDOUT; $| = 1; # make unbuffered
6083 select(STDOUT); $| = 1; # make unbuffered
98446084
9845 print STDOUT "stdout 1\n"; # this works for
6085 print STDOUT "stdout 1\n"; # this works for
9846 print STDERR "stderr 1\n"; # subprocesses too
6086 print STDERR "stderr 1\n"; # subprocesses too
98476087
9848 open(STDOUT, ">&", $oldout) or die "Can't dup \$oldout: $!";
6088 close(STDOUT);
9849 open(STDERR, ">&OLDERR") or die "Can't dup OLDERR: $!";
6089 close(STDERR);
98506090
6091 open(STDOUT, ">&OLDOUT");
6092 open(STDERR, ">&OLDERR");
6093
98516094 print STDOUT "stdout 2\n";
98526095 print STDERR "stderr 2\n";
98536096
98546097=begin original
98556098
9856If you specify C<< '<&=X' >>, where C<X> is a file descriptor number
6099If you specify C<< '<&=N' >>, where C<N> is a number, then Perl will do an
9857or a filehandle, then Perl will do an equivalent of C's L<fdopen(3)> of
6100equivalent of C's C<fdopen> of that file descriptor; this is more
9858that file descriptor (and not call L<dup(2)>); this is more
98596101parsimonious of file descriptors. For example:
98606102
98616103=end original
98626104
9863C<X> をファイル記述子の番号かファイルハンドルとして、
6105C<N> を数値として、C<< '<&=N' >> と指定すると、Perl は
9864C<< '<&=X' >> と指定すると、Perl はそのファイル記述子に対する
6106そのファイル記述子に対する C の C<fdopen> と同じことを行ないます。
9865C の L<fdopen(3)> と同じ行ないます(そて L<dup(2)> は呼び出しせん);
6107れはファイル記述子より節約します。たとえば:
9866これはファイル記述子をより節約します。
9867例えば:
98686108
9869 # open for input, reusing the fileno of $fd
6109 open(FILEHANDLE, "<&=$fd")
9870 open(my $fh, "<&=", $fd)
98716110
98726111=begin original
98736112
9874or
6113Note that this feature depends on the fdopen() C library function.
6114On many UNIX systems, fdopen() is known to fail when file descriptors
6115exceed a certain value, typically 255. If you need more file
6116descriptors than that, consider rebuilding Perl to use the C<sfio>
6117library.
98756118
98766119=end original
98776120
9878また
6121この機能 fdopen() C ライブラリ関数に依存します。
6122多くの UNIX システムでは、fdopen() はファイル記述子がある値
9880 open(my $fh, "<&=$fd")
9881
9882=begin original
9883
9884or
9885
9886=end original
9887
9888または
9889
9890 # open for append, using the fileno of $oldfh
9891 open(my $fh, ">>&=", $oldfh)
9892
9893=begin original
9894
9895Being parsimonious on filehandles is also useful (besides being
9896parsimonious) for example when something is dependent on file
9897descriptors, like for example locking using
9898L<C<flock>|/flock FILEHANDLE,OPERATION>. If you do just
9899C<< open(my $A, ">>&", $B) >>, the filehandle C<$A> will not have the
9900same file descriptor as C<$B>, and therefore C<flock($A)> will not
9901C<flock($B)> nor vice versa. But with C<< open(my $A, ">>&=", $B) >>,
9902the filehandles will share the same underlying system file descriptor.
9903
9904=end original
9905
9906ファイルハンドルを倹約することは、(倹約できること以外に)何かが
9907ファイル記述子に依存している場合、例えば
9908L<C<flock>|/flock FILEHANDLE,OPERATION> を使った
9909ファイルロックといった場合に有用です。
9910C<< open(my $A, ">>&", $B) >> とすると、ファイルハンドル C<$A> は C<$B> と同じ
9911ファイル記述子にはならないので、C<flock($A)> と C<flock($B)> は別々になります。
9912しかし C<< open(my $A, ">>&=", $B) >> ではファイルハンドルは基礎となるシステムの
9913同じファイル記述子を共有します。
9914
9915=begin original
9916
9917Note that under Perls older than 5.8.0, Perl uses the standard C library's'
9918L<fdopen(3)> to implement the C<=> functionality. On many Unix systems,
9919L<fdopen(3)> fails when file descriptors exceed a certain value, typically 255.
9920For Perls 5.8.0 and later, PerlIO is (most often) the default.
9921
9922=end original
9923
99245.8.0 より前の Perl の場合、C<=> 機能の実装は
9925標準 C ライブラリの L<fdopen(3)> を使っています。
9926多くの Unix システムでは、L<fdopen(3)> はファイル記述子がある値
99276123(典型的には 255)を超えた場合に失敗することが知られています。
99285.8.0 以降 Perl では、(ほとんどの場合) PerlIO がデトです。
6124これより多くのファイ記述子が必要な場合は、
6125C<sfio> ライブラリを使って Perl を再ビルドすることを検討して下さい。
99296126
99306127=begin original
99316128
9932You can see whether your Perl was built with PerlIO by running
6129If you open a pipe on the command C<'-'>, i.e., either C<'|-'> or C<'-|'>
9933C<perl -V:useperlio>. If it says C<'define'>, you have PerlIO;
6130with 2-arguments (or 1-argument) form of open(), then
9934otherwise you don't.
6131there is an implicit fork done, and the return value of open is the pid
6132of the child within the parent process, and C<0> within the child
9936=end original
6133process. (Use C<defined($pid)> to determine whether the open was successful.)
6134The filehandle behaves normally for the parent, but i/o to that
9938Perl が PerlIO つきでビルドされているかどうかを確認するには、
9939C<perl -V:useperlio> を見ます。
9940これが C<'define'> なら PerlIO を使っています;
9941そうでなければ使っていません。
9942
9943=begin original
9944
9945If you open a pipe on the command C<-> (that is, specify either C<|-> or C<-|>
9946with the one- or two-argument forms of
9947L<C<open>|/open FILEHANDLE,EXPR>), an implicit L<C<fork>|/fork> is done,
9948so L<C<open>|/open FILEHANDLE,EXPR> returns twice: in the parent process
9949it returns the pid
9950of the child process, and in the child process it returns (a defined) C<0>.
9951Use C<defined($pid)> or C<//> to determine whether the open was successful.
9952
9953=end original
9954
99551 引数 または 2 引数の形の L<C<open>|/open FILEHANDLE,EXPR>) で
9956(C<-|> や C<|-> というふうに) C<-> というコマンドにパイプを開くと、
9957暗黙の L<C<fork>|/fork> が行なわれるので、
9958L<C<open>|/open FILEHANDLE,EXPR> は 2 回返ります;
9959親プロセスには子プロセスの pid が返され、子プロセスには (定義された) C<0> が
9960返されます。
9961open が成功したかどうかを調べるには、C<defined($pid)> または C<//> を
9962使います。
9963
9964=begin original
9965
9966For example, use either
9967
9968=end original
9969
9970例えば、以下の二つ
9971
9972 my $child_pid = open(my $from_kid, "-|") // die "Can't fork: $!";
9973
9974=begin original
9975
9976or
9977
9978=end original
9979
9980または
9981
9982 my $child_pid = open(my $to_kid, "|-") // die "Can't fork: $!";
9983
9984=begin original
9985
9986followed by
9987
9988=end original
9989
9990を使って、後で以下のようにします。
9991
9992 if ($child_pid) {
9993 # am the parent:
9994 # either write $to_kid or else read $from_kid
9995 ...
9996 waitpid $child_pid, 0;
9997 } else {
9998 # am the child; use STDIN/STDOUT normally
9999 ...
10000 exit;
10001 }
10002
10003=begin original
10004
10005The filehandle behaves normally for the parent, but I/O to that
100066135filehandle is piped from/to the STDOUT/STDIN of the child process.
10007In the child process, the filehandle isn't opened--I/O happens from/to
6136In the child process the filehandle isn't opened--i/o happens from/to
10008the new STDOUT/STDIN. Typically this is used like the normal
6137the new STDOUT or STDIN. Typically this is used like the normal
100096138piped open when you want to exercise more control over just how the
10010pipe command gets executed, such as when running setuid and
6139pipe command gets executed, such as when you are running setuid, and
10011you don't want to have to scan shell commands for metacharacters.
6140don't want to have to scan shell commands for metacharacters.
6141The following triples are more or less equivalent:
100126142
100136143=end original
100146144
10015親プロセスで、こファイルハンドルは通常通りに動作しますが、行なわれる
61452 引数(また 1 引数)形の open() で
10016入出力は、子プロセスの STDIN/STDOUTパイプされます。
6146C<'-|'> C<'|-'> というふう、C<'-'> というコマンドに
10017子プロセス側では、そのファルハドルは開か入出力は新しい STDOUT か
6147プをオープすると、fork が行なわれ、open の返り値として、
10018STDIN対して行なわれます。
6148親プロセスにはチャイルドプロセスの pid が、チャイルドプロセス
6149C<0> が返されます。
6150(open が成功したかどうかは、
6151C<defined($pid)> のようにして調べることができます。)
6152親プロセスでは、このファイルハンドルは
6153通常通りに動作しますが、行なわれる入出力は、
6154チャイルドプロセスの STDIN/STDOUT にパイプされます。
6155チャイルドプロセス側では、そのファイルハンドルは
6156オープンされず、入出力は新しい STDOUT か STDIN に対して行なわれます。
100196157これは、setuid で実行して、シェルコマンドのメタ文字を
100206158検索させたくないような場合に、パイプコマンドの起動の仕方を
10021制御したいとき、普通のパイプの open と同じように使います。
6159制御したいとき、普通のパイプのopen と同じように使います。
10022
10023=begin original
10024
10025The following blocks are more or less equivalent:
10026
10027=end original
10028
100296160以下の組み合わせは、だいたい同じものです:
100306161
10031 open(my $fh, "|tr '[a-z]' '[A-Z]'");
6162 open(FOO, "|tr '[a-z]' '[A-Z]'");
10032 open(my $fh, "|-", "tr '[a-z]' '[A-Z]'");
6163 open(FOO, '|-', "tr '[a-z]' '[A-Z]'");
10033 open(my $fh, "|-") || exec 'tr', '[a-z]', '[A-Z]';
6164 open(FOO, '|-') || exec 'tr', '[a-z]', '[A-Z]';
10034 open(my $fh, "|-", "tr", '[a-z]', '[A-Z]');
100356165
10036 open(my $fh, "cat -n '$file'|");
6166 open(FOO, "cat -n '$file'|");
10037 open(my $fh, "-|", "cat -n '$file'");
6167 open(FOO, '-|', "cat -n '$file'");
10038 open(my $fh, "-|") || exec "cat", "-n", $file;
6168 open(FOO, '-|') || exec 'cat', '-n', $file;
10039 open(my $fh, "-|", "cat", "-n", $file);
100406169
100416170=begin original
100426171
10043The last two examples in each block show the pipe as "list form", which is
10044not yet supported on all platforms. A good rule of thumb is that if
10045your platform has a real L<C<fork>|/fork> (in other words, if your platform is
10046Unix, including Linux and MacOS X), you can use the list form. You would
10047want to use the list form of the pipe so you can pass literal arguments
10048to the command without risk of the shell interpreting any shell metacharacters
10049in them. However, this also bars you from opening pipes to commands
10050that intentionally contain shell metacharacters, such as:
10051
10052=end original
10053
10054それぞれのブロックの末尾二つの例ではパイプを「リスト形式」にしていますが、
10055これはまだ全てのプラットフォームで対応しているわけではなりません。
10056よい経験則としては、もし実行しているプラットフォームで本当の
10057L<C<fork>|/fork> があれば(言い換えると、プラットフォームが Linux や
10058MacOS X を含む Unix なら)リスト形式が使えます。
10059パイプのリスト形式を使うことで、コマンドへのリテラルな引数を、
10060シェルのメタ文字をシェルが解釈するリスクなしに渡すことができます。
10061しかし、これは以下のように意図的にシェルメタ文字を含むコマンドをパイプとして
10062開くことを妨げます:
10063
10064 open(my $fh, "|cat -n | expand -4 | lpr")
10065 || die "Can't open pipeline to lpr: $!";
10066
10067=begin original
10068
100696172See L<perlipc/"Safe Pipe Opens"> for more examples of this.
100706173
100716174=end original
100726175
10073これに関する更なる例については L<perlipc/"Safe Pipe Opens"> を
6176これに関する更なる例については L<perlipc/"Safe Pipe Opens"> を参照して下さい。
10074参照してください。
100756177
100766178=begin original
100776179
10078Perl will attempt to flush all files opened for
6180Beginning with v5.6.0, Perl will attempt to flush all files opened for
100796181output before any operation that may do a fork, but this may not be
100806182supported on some platforms (see L<perlport>). To be safe, you may need
10081to set L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>)
6183to set C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method
10082or call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS>
6184of C<IO::Handle> on any open handles.
10083on any open handles.
100846185
100856186=end original
100866187
100876188v5.6.0 から、Perl は書き込み用に開いている全てのファイルに対して
100886189fork を行う前にフラッシュしようとしますが、これに対応していない
100896190プラットフォームもあります(L<perlport> を参照してください)。
10090安全のために、L<C<$E<verbar>>|perlvar/$E<verbar>> (L<English> モジュールでは
6191安全のために、C<$|> (English モジュールでは $AUTOFLUSH) をセットするか、
10091C<$AUTOFLUSH>) をセットするか、全ての開いているハンドルに対して
6192全ての開いているハンドルに対して C<IO::Handle> の C<autoflush()> メソッドを
10092L<C<IO::Handle>|IO::Handle/METHODS> の C<autoflush> メソッドを
6193呼び出すようにしてください。
10093呼び出す必要があるかもしれません。
100946194
100956195=begin original
100966196
10097On systems that support a close-on-exec flag on files, the flag will
6197On systems that support a
10098be set for the newly opened file descriptor as determined by the value
6198close-on-exec flag on files, the flag will be set for the newly opened
10099of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>.
6199file descriptor as determined by the value of $^F. See L<perlvar/$^F>.
101006200
101016201=end original
101026202
101036203ファイルに対する close-on-exec フラグをサポートしているシステムでは、
10104フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた
6204フラグは$^F の値で決定される、新しくオープンされたファイル記述子に対して
10105ファイル記述子に対してセットされます。
6205セットされます。
10106L<perlvar/$^F> を参照してください。
6206L<perlvar/$^F>を参照してください。
101076207
101086208=begin original
101096209
101106210Closing any piped filehandle causes the parent process to wait for the
10111child to finish, then returns the status value in L<C<$?>|perlvar/$?> and
6211child to finish, and returns the status value in C<$?>.
10112L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>.
101136212
101146213=end original
101156214
10116パイプのファイルハンドルを close することで、親プロセスは、子プロセスの終了を
6215パイプのファイルハンドルを close することで、
10117待ち、それから L<C<$?>|perlvar/$?>
6216親プロセスは、チャイルドプロセスの終了を待ち、C<$?>
10118L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> にステータス値を
6217ステータス値を返します。
10119返します。
101206218
101216219=begin original
101226220
10123The filename passed to the one- and two-argument forms of
6221The filename passed to 2-argument (or 1-argument) form of open()
10124L<C<open>|/open FILEHANDLE,EXPR> will
6222will have leading and trailing
10125have leading and trailing whitespace deleted and normal
6223whitespace deleted, and the normal redirection characters
10126redirection characters honored. This property, known as "magic open",
6224honored. This property, known as "magic open",
101276225can often be used to good effect. A user could specify a filename of
101286226F<"rsh cat file |">, or you could change certain filenames as needed:
101296227
101306228=end original
101316229
101321 引数 2 引数の形の L<C<open>|/open FILEHANDLE,EXPR> に渡された
62302 引数(1 引数)の形の open() に渡されたファイル名は、
10133ファイル名、はじめと終わりの空白が取り除かれ、通常のリダイレクト文字列を
6231はじめと終わりの空白が取り除かれ、
10134受け付けます。
6232通常のリダイレクト文字列を受け付けます。
10135この機能は "magic open" として知られていますが、普通いい効果をもたらします。
6233この機能は "magic open" として知られていますが、
6234普通いい効果をもたらします。
101366235ユーザーは F<"rsh cat file |"> といったファイル名を指定できますし、
101376236特定のファイル名を必要に応じて変更できます。
101386237
101396238 $filename =~ s/(.*\.gz)\s*$/gzip -dc < $1|/;
10140 open(my $fh, $filename) or die "Can't open $filename: $!";
6239 open(FH, $filename) or die "Can't open $filename: $!";
101416240
101426241=begin original
101436242
10144Use the three-argument form to open a file with arbitrary weird characters in it,
6243Use 3-argument form to open a file with arbitrary weird characters in it,
101456244
101466245=end original
101476246
101486247妙な文字が含まれているようなファイル名をオープンするには、
1014962483 引数の形を使います。
101506249
10151 open(my $fh, "<", $file)
6250 open(FOO, '<', $file);
10152 || die "Can't open $file: $!";
101536251
101546252=begin original
101556253
101566254otherwise it's necessary to protect any leading and trailing whitespace:
101576255
101586256=end original
101596257
101606258あるいは、次のようにして、最初と最後の空白を保護します:
101616259
101626260 $file =~ s#^(\s)#./$1#;
10163 open(my $fh, "< $file\0")
6261 open(FOO, "< $file\0");
10164 || die "Can't open $file: $!";
101656262
101666263=begin original
101676264
101686265(this may not work on some bizarre filesystems). One should
10169conscientiously choose between the I<magic> and I<three-argument> form
6266conscientiously choose between the I<magic> and 3-arguments form
10170of L<C<open>|/open FILEHANDLE,EXPR>:
6267of open():
101716268
101726269=end original
101736270
101746271(これは奇妙なファイルシステムでは動作しないかもしれません)。
10175L<C<open>|/open FILEHANDLE,EXPR> の I<magic> と I<3 引数> 形式を誠実に
6272open() の I<magic> と 3 引数形式を誠実に選択するべきです。
10176選択するべきです。
101776273
10178 open(my $in, $ARGV[0]) || die "Can't open $ARGV[0]: $!";
6274 open IN, $ARGV[0];
101796275
101806276=begin original
101816277
101826278will allow the user to specify an argument of the form C<"rsh cat file |">,
10183but will not work on a filename that happens to have a trailing space, while
6279but will not work on a filename which happens to have a trailing space, while
101846280
101856281=end original
101866282
101876283とするとユーザーは C<"rsh cat file |"> という形の引数を指定できますが、
10188末尾にスペースがついてしまったファイル名では動作しません; 一方:
6284末尾にスペースがついてしまったファイル名では動作しません一方:
101896285
10190 open(my $in, "<", $ARGV[0])
6286 open IN, '<', $ARGV[0];
10191 || die "Can't open $ARGV[0]: $!";
101926287
101936288=begin original
101946289
10195will have exactly the opposite restrictions. (However, some shells
6290will have exactly the opposite restrictions.
10196support the syntax C<< perl your_program.pl <( rsh cat file ) >>, which
10197produces a filename that can be opened normally.)
101986291
101996292=end original
102006293
102016294はまったく逆の制限があります。
10202(しかし、一部のシェルは C<< perl your_program.pl <( rsh cat file ) >> という
10203文法に対応していて、普通に開くことが出来るファイル名を出力します。)
102046295
102056296=begin original
102066297
10207If you want a "real" C L<open(2)>, then you should use the
6298If you want a "real" C C<open> (see L<open(2)> on your system), then you
10208L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> function, which involves
6299should use the C<sysopen> function, which involves no such magic (but
10209no such magic (but uses different filemodes than Perl
6300may use subtly different filemodes than Perl open(), which is mapped
10210L<C<open>|/open FILEHANDLE,EXPR>, which corresponds to C L<fopen(3)>).
6301to C fopen()). This is
10211This is another way to protect your filenames from interpretation. For
6302another way to protect your filenames from interpretation. For example:
10212example:
102136303
102146304=end original
102156305
10216もし「本当の」C 言語の L<open(2)> が必要なら、このような副作用のな
6306もし「本当の」C 言語の C<open> (システムの L<open(2)> を参照してくださ)が
10217L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> 関数を使うべきです
6307必要なら、このような副作用のない C<sysopen> 関数を使うべきです
10218(ただし、C の L<fopen(3)>対応する Perl の
6308(ただし、C の fopen() に割り付けられる Perl の open() とは
10219L<C<open>|/open FILEHANDLE,EXPR> とは違うファイルモードを持ちます)。
6309かすかに違うファイルモードを持ちます)。
102206310これはファイル名を解釈から守るもう一つの方法です。
102216311例えば:
102226312
102236313 use IO::Handle;
10224 sysopen(my $fh, $path, O_RDWR|O_CREAT|O_EXCL)
6314 sysopen(HANDLE, $path, O_RDWR|O_CREAT|O_EXCL)
10225 or die "Can't open $path: $!";
6315 or die "sysopen $path: $!";
10226 $fh->autoflush(1);
6316 $oldfh = select(HANDLE); $| = 1; select($oldfh);
10227 print $fh "stuff $$\n";
6317 print HANDLE "stuff $$\n";
10228 seek($fh, 0, 0);
6318 seek(HANDLE, 0, 0);
10229 print "File contains: ", readline($fh);
6319 print "File contains: ", <HANDLE>;
102306320
102316321=begin original
102326322
10233See L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> for some details about
6323Using the constructor from the C<IO::Handle> package (or one of its
10234mixing reading and writing.
6324subclasses, such as C<IO::File> or C<IO::Socket>), you can generate anonymous
6325filehandles that have the scope of whatever variables hold references to
6326them, and automatically close whenever and however you leave that scope:
102356327
102366328=end original
102376329
10238読み書きを混ぜる場合の詳細について
6330C<IO::Handle> パッケージ(また C<IO::File> や C<IO::Socket> といった
10239L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> 参照してください。
6331サブパッケージ)のコンストラクタ使うことで、
6332これらへのリファレンスを保持している変数のスコープを持ち、
6333スコープから離れると自動的に閉じる無名ファイルハンドルを作成できます:
102406334
6335 use IO::File;
6336 #...
6337 sub read_myfile_munged {
6338 my $ALL = shift;
6339 my $handle = new IO::File;
6340 open($handle, "myfile") or die "myfile: $!";
6341 $first = <$handle>
6342 or return (); # Automatically closed here.
6343 mung $first or die "mung failed"; # Or here.
6344 return $first, <$handle> if $ALL; # Or here.
6345 $first; # Or here.
6346 }
6347
102416348=begin original
102426349
10243Portability issues: L<perlport/open>.
6350See L</seek> for some details about mixing reading and writing.
102446351
102456352=end original
102466353
10247移植性問題: L<perlport/open>。
6354読み書きを混ぜる場合詳細については L</seek> を参照して下さい
102486355
102496356=item opendir DIRHANDLE,EXPR
10250X<opendir>
102516357
10252=for Pod::Functions open a directory
10253
102546358=begin original
102556359
10256Opens a directory named EXPR for processing by
6360Opens a directory named EXPR for processing by C<readdir>, C<telldir>,
10257L<C<readdir>|/readdir DIRHANDLE>, L<C<telldir>|/telldir DIRHANDLE>,
6361C<seekdir>, C<rewinddir>, and C<closedir>. Returns true if successful.
10258L<C<seekdir>|/seekdir DIRHANDLE,POS>,
6362DIRHANDLEs have their own namespace separate from FILEHANDLEs.
10259L<C<rewinddir>|/rewinddir DIRHANDLE>, and
10260L<C<closedir>|/closedir DIRHANDLE>. Returns true if successful.
10261DIRHANDLE may be an expression whose value can be used as an indirect
10262dirhandle, usually the real dirhandle name. If DIRHANDLE is an undefined
10263scalar variable (or array or hash element), the variable is assigned a
10264reference to a new anonymous dirhandle; that is, it's autovivified.
10265Dirhandles are the same objects as filehandles; an I/O object can only
10266be open as one of these handle types at once.
102676363
102686364=end original
102696365
10270L<C<readdir>|/readdir DIRHANDLE>、L<C<telldir>|/telldir DIRHANDLE>、
6366C<readdir>、C<telldir>、C<seekdir>、C<rewinddir>、
10271L<C<seekdir>|/seekdir DIRHANDLE,POS>、L<C<rewinddir>|/rewinddir DIRHANDLE>、
6367C<closedir> で処理するために、EXPR で指定された名前の
10272L<C<closedir>|/closedir DIRHANDLE> で処理るため、EXPR で指定された名前の
6368ディレクトリをオープンしま。成功時は真を返します。
10273ディレクトリオープンします。
6369DIRHANDLE は、FILEHANDLE とは別に名前空間持っています。
10274成功時には真を返します。
10275DIRHANDLE は間接ディレクトリハンドルとして使える値(普通は実際のディレクトリ
10276ハンドルの名前)となる式でも構いません。
10277DIRHANDLE が未定義のスカラ値(または配列かハッシュの要素)の場合、その変数は
10278新しい無名ディレクトリハンドルへのリファレンスが代入されます; つまり、
10279自動有効化されます。
10280ディレクトリハンドルはファイルハンドルと同じオブジェクトです;
10281一つの I/O オブジェクトは同時にこれらのハンドル型のどちらかとしてのみ
10282開くことができます。
102836370
10284=begin original
10285
10286See the example at L<C<readdir>|/readdir DIRHANDLE>.
10287
10288=end original
10289
10290L<C<readdir>|/readdir DIRHANDLE> の例を参照してください。
10291
102926371=item ord EXPR
10293X<ord> X<encoding>
102946372
102956373=item ord
102966374
10297=for Pod::Functions find a character's numeric representation
10298
102996375=begin original
103006376
10301Returns the numeric value of the first character of EXPR.
6377Returns the numeric (ASCII or Unicode) value of the first character of EXPR. If
10302If EXPR is an empty string, returns 0. If EXPR is omitted, uses
6378EXPR is omitted, uses C<$_>. For the reverse, see L</chr>.
10303L<C<$_>|perlvar/$_>.
6379See L<utf8> for more about Unicode.
10304(Note I<character>, not byte.)
103056380
103066381=end original
103076382
10308EXPR の最初の文字の数値としての値を返します。
6383EXPR の最初の文字の数値としての(ASCII または Unicode) 値を返します。
10309EXPR が空文字列の場合は、0します。
6384EXPR を省略した場合は、C<$_>使用します。
10310EXPR が省略されるL<C<$_>|perlvar/$_> を使ます
6385逆のこをするには L</chr> を参照してください。
10311(バイトでなく I<文字> であることに注意してください。)
6386Unicode についてL<utf8> を参照してください。
103126387
10313=begin original
6388=item our EXPR
103146389
10315For the reverse, see L<C<chr>|/chr NUMBER>.
10316See L<perlunicode> for more about Unicode.
10317
10318=end original
10319
10320逆のことをするには L<C<chr>|/chr NUMBER> を参照してください。
10321Unicode については L<perlunicode> を参照してください。
10322
10323=item our VARLIST
10324X<our> X<global>
10325
10326=item our TYPE VARLIST
10327
10328=item our VARLIST : ATTRS
10329
10330=item our TYPE VARLIST : ATTRS
10331
10332=for Pod::Functions +5.6.0 declare and assign a package variable (lexical scoping)
10333
103346390=begin original
103356391
10336L<C<our>|/our VARLIST> makes a lexical alias to a package (i.e. global)
6392An C<our> declares the listed variables to be valid globals within
10337variable of the same name in the current package for use within the
6393the enclosing block, file, or C<eval>. That is, it has the same
10338current lexical scope.
6394scoping rules as a "my" declaration, but does not create a local
6395variable. If more than one value is listed, the list must be placed
6396in parentheses. The C<our> declaration has no semantic effect unless
6397"use strict vars" is in effect, in which case it lets you use the
6398declared global variable without qualifying it with a package name.
6399(But only within the lexical scope of the C<our> declaration. In this
6400it differs from "use vars", which is package scoped.)
103396401
103406402=end original
103416403
10342L<C<our>|/our VARLIST> 単純名を、現在のレキシカスコープ内で使うために、
6404C<our> は挙げられた変数ブロックファイ、C<eval> 内で
10343現在のパッケージの同じ名前のパッケージ(つまりグローバルな)変数への
6405グローバルとして宣言します。
10344レキシカな別名作ります
6406これは "my" 宣言と同じスコープールもちますが、
6407ローカル変数を作りません。
6408複数の変数を指定する場合は、変数は括弧で囲わなければなりません。
6409C<our> 宣言は "use strict vars" が有効でなければ
6410意味論的な効果はもちません。
6411この場合、宣言したグローバル変数をパッケージ名で修飾せずに使えます。
6412(しかし C<our> 宣言のレキシカルスコープの内側だけです。
6413これは "use vars" と異なります。こちらはパッケージスコープです。)
103456414
103466415=begin original
103476416
10348L<C<our>|/our VARLIST> has the same scoping rules as
6417An C<our> declaration declares a global variable that will be visible
10349L<C<my>|/my VARLIST> or L<C<state>|/state VARLIST>, meaning that it is
10350only valid within a lexical scope. Unlike L<C<my>|/my VARLIST> and
10351L<C<state>|/state VARLIST>, which both declare new (lexical) variables,
10352L<C<our>|/our VARLIST> only creates an alias to an existing variable: a
10353package variable of the same name.
10354
10355=end original
10356
10357L<C<our>|/our VARLIST> は L<C<my>|/my VARLIST> や
10358L<C<state>|/state VARLIST> と同じスコープルールを持ちます; つまり
10359レキシカルスコープの中でだけ有効です。
10360新しい(レキシカル)変数を宣言する L<C<my>|/my VARLIST> や
10361L<C<state>|/state VARLIST> と異なり、L<C<our>|/our VARLIST> は既に
10362存在する変数への別名を作るだけです: 同じ名前のパッケージ変数です。
10363
10364=begin original
10365
10366This means that when C<use strict 'vars'> is in effect, L<C<our>|/our
10367VARLIST> lets you use a package variable without qualifying it with the
10368package name, but only within the lexical scope of the
10369L<C<our>|/our VARLIST> declaration. This applies immediately--even
10370within the same statement.
10371
10372=end original
10373
10374つまり、C<use strict 'vars'> が有効の場合は、L<C<our>|/our VARLIST> を
10375使うことで、
10376パッケージ変数をパッケージ名で修飾することなく使うことができますが、
10377L<C<our>|/our VARLIST> 宣言のレキシカルスコープ内だけということです。
10378これは(たとえ同じ文の中でも)直ちに適用されます。
10379
10380 package Foo;
10381 use strict;
10382
10383 $Foo::foo = 23;
10384
10385 {
10386 our $foo; # alias to $Foo::foo
10387 print $foo; # prints 23
10388 }
10389
10390 print $Foo::foo; # prints 23
10391
10392 print $foo; # ERROR: requires explicit package name
10393
10394=begin original
10395
10396This works even if the package variable has not been used before, as
10397package variables spring into existence when first used.
10398
10399=end original
10400
10401これはパッケージ変数がまだ使われていなくても動作します; パッケージ変数は、
10402最初に使われた時にひょっこり現れるからです。
10403
10404 package Foo;
10405 use strict;
10406
10407 our $foo = 23; # just like $Foo::foo = 23
10408
10409 print $Foo::foo; # prints 23
10410
10411=begin original
10412
10413Because the variable becomes legal immediately under C<use strict 'vars'>, so
10414long as there is no variable with that name is already in scope, you can then
10415reference the package variable again even within the same statement.
10416
10417=end original
10418
10419変数は C<use strict 'vars'> の基で直ちに正当になるので、
10420スコープ内に同じ名前の変数がない限り、
10421たとえ同じ文の中でもパッケージ変数を再び参照できます。
10422
10423 package Foo;
10424 use strict;
10425
10426 my $foo = $foo; # error, undeclared $foo on right-hand side
10427 our $foo = $foo; # no errors
10428
10429=begin original
10430
10431If more than one variable is listed, the list must be placed
10432in parentheses.
10433
10434=end original
10435
10436複数の変数を指定する場合は、リストはかっこでくくらなければなりません。
10437
10438 our($bar, $baz);
10439
10440=begin original
10441
10442An L<C<our>|/our VARLIST> declaration declares an alias for a package
10443variable that will be visible
104446418across its entire lexical scope, even across package boundaries. The
104456419package in which the variable is entered is determined at the point
104466420of the declaration, not at the point of use. This means the following
104476421behavior holds:
104486422
104496423=end original
104506424
10451L<C<our>|/our VARLIST> 宣言はレキシカルスコープ全体に対して (たとえ
6425C<our> 宣言はレキシカルスコープ全体に対して(たとえパッケージ境界を
10452パッケージ境界を越えていても)見える、パッケ変数への別名を宣言します。
6426越えていても)見えるグロバル変数を宣言します。
104536427この変数が入るパッケージは宣言した時点で定義され、
104546428使用した時点ではありません。
104556429これにより、以下のような振る舞いになります:
104566430
104576431 package Foo;
10458 our $bar; # declares $Foo::bar for rest of lexical scope
6432 our $bar; # declares $Foo::bar for rest of lexical scope
104596433 $bar = 20;
104606434
104616435 package Bar;
10462 print $bar; # prints 20, as it refers to $Foo::bar
6436 print $bar; # prints 20
104636437
104646438=begin original
104656439
10466Multiple L<C<our>|/our VARLIST> declarations with the same name in the
6440Multiple C<our> declarations in the same lexical scope are allowed
10467same lexical
6441if they are in different packages. If they happened to be in the same
10468scope are allowed if they are in different packages. If they happen
6442package, Perl will emit warnings if you have asked for them.
10469to be in the same package, Perl will emit warnings if you have asked
10470for them, just like multiple L<C<my>|/my VARLIST> declarations. Unlike
10471a second L<C<my>|/my VARLIST> declaration, which will bind the name to a
10472fresh variable, a second L<C<our>|/our VARLIST> declaration in the same
10473package, in the same scope, is merely redundant.
104746443
104756444=end original
104766445
10477同じレキシカルスコープでも、パッケージが異なっていれば、同じ名前で複数の
6446同じレキシカルスコープでも、パッケージが異なっていれば、複数の
10478L<C<our>|/our VARLIST> 宣言ができます。
6447C<our> 宣言ができます。
104796448同じパッケージになっていると、警告が出力されるようになっていれば
10480複数の L<C<my>|/my VARLIST> 宣言がある場合と同じように警告が出力されます。
6449警告が出力されます。
10481新しい変数を名前に割り当てることになる 2 回目の L<C<my>|/my VARLIST> 宣言と
10482違って、同じパッケージの同じスコープで 2 回
10483L<C<our>|/our VARLIST> 宣言するのは単に冗長です。
104846450
104856451 use warnings;
104866452 package Foo;
10487 our $bar; # declares $Foo::bar for rest of lexical scope
6453 our $bar; # declares $Foo::bar for rest of lexical scope
104886454 $bar = 20;
104896455
104906456 package Bar;
10491 our $bar = 30; # declares $Bar::bar for rest of lexical scope
6457 our $bar = 30; # declares $Bar::bar for rest of lexical scope
10492 print $bar; # prints 30
6458 print $bar; # prints 30
104936459
10494 our $bar; # emits warning but has no other effect
6460 our $bar; # emits warning
10495 print $bar; # still prints 30
104966461
10497=begin original
10498
10499An L<C<our>|/our VARLIST> declaration may also have a list of attributes
10500associated with it.
10501
10502=end original
10503
10504L<C<our>|/our VARLIST> 宣言には、それと結び付けられる属性のリストを
10505持つこともあります。
10506
10507=begin original
10508
10509The exact semantics and interface of TYPE and ATTRS are still
10510evolving. TYPE is currently bound to the use of the L<fields> pragma,
10511and attributes are handled using the L<attributes> pragma, or, starting
10512from Perl 5.8.0, also via the L<Attribute::Handlers> module. See
10513L<perlsub/"Private Variables via my()"> for details.
10514
10515=end original
10516
10517TYPE と ATTRS の正確な文法とインターフェースは今でも進化しています。
10518現在のところ、TYPE は L<fields> プラグマの使用と結び付けられていて、
10519属性は L<attributes> プラグマか、Perl 5.8.0 からは
10520L<Attribute::Handlers> モジュールと結び付けられています。
10521詳しくは L<perlsub/"Private Variables via my()"> を参照してください。
10522
10523=begin original
10524
10525Note that with a parenthesised list, L<C<undef>|/undef EXPR> can be used
10526as a dummy placeholder, for example to skip assignment of initial
10527values:
10528
10529=end original
10530
10531かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> は、例えば初期値の代入を
10532飛ばすために、ダミーのプレースホルダとして使えることに注意してください:
10533
10534 our ( undef, $min, $hour ) = localtime;
10535
10536=begin original
10537
10538L<C<our>|/our VARLIST> differs from L<C<use vars>|vars>, which allows
10539use of an unqualified name I<only> within the affected package, but
10540across scopes.
10541
10542=end original
10543
10544L<C<our>|/our VARLIST> は L<C<use vars>|vars> と異なります; スコープを
10545またぐのではなく、影響するパッケージの内側 I<のみ> で完全修飾されていない
10546名前を使えるようにします。
10547
105486462=item pack TEMPLATE,LIST
10549X<pack>
105506463
10551=for Pod::Functions convert a list into a binary representation
10552
105536464=begin original
105546465
105556466Takes a LIST of values and converts it into a string using the rules
105566467given by the TEMPLATE. The resulting string is the concatenation of
105576468the converted values. Typically, each converted value looks
105586469like its machine-level representation. For example, on 32-bit machines
10559an integer may be represented by a sequence of 4 bytes, which will in
6470a converted integer may be represented by a sequence of 4 bytes.
10560Perl be presented as a string that's 4 characters long.
105616471
105626472=end original
105636473
10564LIST の値を TEMPLATE で与えられたルールを用いて文字列に変換します。
6474LIST の値を TEMPLATE で与えられたルールを用いて
6475文字列に変換します。
105656476結果の文字列は変換した値を連結したものです。
105666477典型的には、それぞれの変換された値はマシンレベルの表現のように見えます。
10567例えば、32-bit マシンでは、整数 4 バイトで表現されるで、
6478例えば、32-bit マシンでは、整数を変換すると 4 バイトのデータとして
10568Perl では 4 文字の文字列で表現されます。
6479表現されます。
105696480
105706481=begin original
105716482
10572See L<perlpacktut> for an introduction to this function.
6483The TEMPLATE is a
6484sequence of characters that give the order and type of values, as
6485follows:
105736486
105746487=end original
105756488
10576この関数の説明については L<perlpacktut> を参照してください。
6489TEMPLATE は、以下の
6490ような値の型と順番を指定する文字を並べたものです:
105776491
105786492=begin original
105796493
10580The TEMPLATE is a sequence of characters that give the order and type
6494 a A string with arbitrary binary data, will be null padded.
10581of values, as follows:
6495 A An ASCII string, will be space padded.
6496 Z A null terminated (asciz) string, will be null padded.
105826497
10583=end original
6498 b A bit string (ascending bit order inside each byte, like vec()).
6499 B A bit string (descending bit order inside each byte).
6500 h A hex string (low nybble first).
6501 H A hex string (high nybble first).
105846502
10585TEMPLATE は、以下のような値の型と順番を指定する文字を並べたものです:
6503 c A signed char value.
6504 C An unsigned char value. Only does bytes. See U for Unicode.
105866505
10587=begin original
6506 s A signed short value.
6507 S An unsigned short value.
6508 (This 'short' is _exactly_ 16 bits, which may differ from
6509 what a local C compiler calls 'short'. If you want
6510 native-length shorts, use the '!' suffix.)
105886511
10589 a A string with arbitrary binary data, will be null padded.
6512 i A signed integer value.
10590 A A text (ASCII) string, will be space padded.
6513 I An unsigned integer value.
10591 Z A null-terminated (ASCIZ) string, will be null padded.
6514 (This 'integer' is _at_least_ 32 bits wide. Its exact
6515 size depends on what a local C compiler calls 'int',
6516 and may even be larger than the 'long' described in
6517 the next item.)
105926518
10593=end original
6519 l A signed long value.
6520 L An unsigned long value.
6521 (This 'long' is _exactly_ 32 bits, which may differ from
6522 what a local C compiler calls 'long'. If you want
6523 native-length longs, use the '!' suffix.)
105946524
10595 a 任意のバイナリデータを含む文字列、ヌル文字で埋める。
6525 n An unsigned short in "network" (big-endian) order.
10596 A テキスト (ASCII) 文字列、スペース文字で埋める。
6526 N An unsigned long in "network" (big-endian) order.
10597 Z ヌル文字終端 (ASCIZ) 文字列、ヌル文字で埋める。
6527 v An unsigned short in "VAX" (little-endian) order.
6528 V An unsigned long in "VAX" (little-endian) order.
6529 (These 'shorts' and 'longs' are _exactly_ 16 bits and
6530 _exactly_ 32 bits, respectively.)
105986531
10599=begin original
6532 q A signed quad (64-bit) value.
6533 Q An unsigned quad value.
6534 (Quads are available only if your system supports 64-bit
6535 integer values _and_ if Perl has been compiled to support those.
6536 Causes a fatal error otherwise.)
106006537
10601 b A bit string (ascending bit order inside each byte,
6538 f A single-precision float in the native format.
10602 like vec()).
6539 d A double-precision float in the native format.
10603 B A bit string (descending bit order inside each byte).
10604 h A hex string (low nybble first).
10605 H A hex string (high nybble first).
106066540
10607=end original
6541 p A pointer to a null-terminated string.
6542 P A pointer to a structure (fixed-length string).
106086543
10609 b ビット列 (バイトごとに昇ビット順、vec() と同じ)。
6544 u A uuencoded string.
10610 B ビット列 (バイトごとに降ビット順)。
6545 U A Unicode character number. Encodes to UTF-8 internally.
10611 h 16 進数文字列 (低位ニブルが先)。
6546 Works even if C<use utf8> is not in effect.
10612 H 16 進数文字列 (高位ニブルが先)。
106136547
10614=begin original
6548 w A BER compressed integer. Its bytes represent an unsigned
6549 integer in base 128, most significant digit first, with as
6550 few digits as possible. Bit eight (the high bit) is set
6551 on each byte except the last.
106156552
10616 c A signed char (8-bit) value.
6553 x A null byte.
10617 C An unsigned char (octet) value.
6554 X Back up a byte.
10618 W An unsigned char value (can be greater than 255).
6555 @ Null fill to absolute position.
106196556
106206557=end original
106216558
10622 c signed char (8 ビット) 値。
6559 a 任意のバイナリデータを含む文字列、ヌル文字で埋める
10623 C unsigned char (オクテット) 値。
6560 A ASCII 文字列、スペース文字で埋める
10624 W unsigned char 値 (255 より大きいかもしれません)
6561 Z ヌル文字終端(asciz)文字列、ヌル文字で埋める
106256562
10626=begin original
6563 b ビット列 (バイトごとに昇ビット順、vec() と同じ)
6564 B ビット列 (バイトごとに降ビット順)
6565 h 16 進数文字列 (低位ニブルが先)
6566 H 16 進数文字列 (高位ニブルが先)
106276567
10628 s A signed short (16-bit) value.
6568 c signed char
10629 S An unsigned short value.
6569 C unsigned char 値。バイトのみ。Unicode 用は U。
106306570
10631=end original
6571 s signed short 値
6572 S unsigned short 値
6573 (ここでの 'short' は「正確に」 16 bit です。
6574 ローカルの C コンパイラの 'short' のサイズとは違うかもしれません。
6575 ネイティブな長さの short を使いたい場合は、
6576 '!' 前置詞を使ってください。)
106326577
10633 s signed short (16 ビット)
6578 i signed int 値
10634 S unsigned short 値
6579 I unsigned int 値
6580 (ここでの 'integer' は 「最低」 32 bits 幅です。
6581 正確なサイズはローカルの C コンパイラの
6582 'int'のサイズに依存します。
6583 また、下記の 'long' より大きい可能性もあります)
106356584
10636=begin original
6585 l signed long 値
6586 L unsigned long 値
6587 (ここでの 'long' は「正確に」32 ビットです。これは
6588 ローカルの C コンパイラの 'long' のサイズとは違うかもしれません。
6589 ネイティブな長さの 'long' が必要な場合は、'!' 前置詞を使ってください)
106376590
10638 l A signed long (32-bit) value.
6591 n "network" 順序 (ビッグエンディアン) unsigned short
10639 L An unsigned long value.
6592 N "network" 順序 (ビッグエンディアン) の unsigned long
6593 v "VAX" 順序 (リトルエンディアン) の unsigned short
6594 V "VAX" 順序 (リトルエンディアン) の unsigned long
6595 (これらの 'short' と 'long' は「正確に」それぞれ 16 ビットと
6596 32 ビットす)
106406597
10641=end original
6598 q 符号付き 64 ビット整数
6599 Q 符号なし 64 ビット整数
6600 (64 ビット整数は、システムが 64 ビット整数に対応していて、かつ Perl が
6601 64 ビット整数対応としてコンパイルされている場合にのみ使用可能です。
6602 それ以外の場合は致命的エラーが発生します。)
106426603
10643 l signed long (32 ビット) 値。
6604 f 機種依存の単精度浮動小数点数
10644 L unsigned long 値。
6605 d 機種依存の倍精度浮動小数点数
106456606
10646=begin original
6607 p ヌル文字で終端する文字列へのポインタ
6608 P 構造体 (固定長文字列) へのポインタ
106476609
10648 q A signed quad (64-bit) value.
6610 u uuencode 文字列
10649 Q An unsigned quad value.
6611 U Unicode 文字番号。内部的に UTF-8 にエンコードされます。
10650 (Quads are available only if your system supports 64-bit
6612 C<use utf8> が有効でなくても動作します。
10651 integer values _and_ if Perl has been compiled to support
10652 those. Raises an exception otherwise.)
106536613
10654=end original
6614 w A BER 圧縮変数。このバイト列はできるだけ少ない桁数で表現された
6615 128 を基とした符号なし整数で、最上位ビットから順に並びます。
6616 最後のバイト以外の各バイトのビット 8 (上位ビット) がセットされます。
106556617
10656 q 符号付き 64 ビット整数。
6618 x ヌル文字
10657 Q 符号なし 64 ビット整数。
6619 X 1 文字後退
10658 (64 ビット整数は、システムが 64 ビット整数に応していて、かつ Perl が
6620 @ 位置までヌル文字で埋める
10659 64 ビット整数対応としてコンパイルされている場合にのみ使用可能です。
10660 それ以外の場合は例外が発生します。)
106616621
106626622=begin original
106636623
10664 i A signed integer value.
10665 I An unsigned integer value.
10666 (This 'integer' is _at_least_ 32 bits wide. Its exact
10667 size depends on what a local C compiler calls 'int'.)
10668
10669=end original
10670
10671 i signed int 値。
10672 I unsigned int 値。
10673 (ここでの 'integer' は 「最低」 32 ビット幅です。正確なサイズは
10674 ローカルの C コンパイラの 'int' のサイズに依存します。)
10675
10676=begin original
10677
10678 n An unsigned short (16-bit) in "network" (big-endian) order.
10679 N An unsigned long (32-bit) in "network" (big-endian) order.
10680 v An unsigned short (16-bit) in "VAX" (little-endian) order.
10681 V An unsigned long (32-bit) in "VAX" (little-endian) order.
10682
10683=end original
10684
10685 n "network" 順序 (ビッグエンディアン) の unsigned short (16 ビット)。
10686 N "network" 順序 (ビッグエンディアン) の unsigned long (32 ビット)。
10687 v "VAX" 順序 (リトルエンディアン) の unsigned short (16 ビット)。
10688 V "VAX" 順序 (リトルエンディアン) の unsigned long (32 ビット)。
10689
10690=begin original
10691
10692 j A Perl internal signed integer value (IV).
10693 J A Perl internal unsigned integer value (UV).
10694
10695=end original
10696
10697 j Perl 内部符号付き整数 (IV)。
10698 J Perl 内部符号なし整数 (UV)。
10699
10700=begin original
10701
10702 f A single-precision float in native format.
10703 d A double-precision float in native format.
10704
10705=end original
10706
10707 f 機種依存の単精度浮動小数点数。
10708 d 機種依存の倍精度浮動小数点数。
10709
10710=begin original
10711
10712 F A Perl internal floating-point value (NV) in native format
10713 D A float of long-double precision in native format.
10714 (Long doubles are available only if your system supports
10715 long double values _and_ if Perl has been compiled to
10716 support those. Raises an exception otherwise.
10717 Note that there are different long double formats.)
10718
10719=end original
10720
10721 F ネイティブフォーマットの Perl 内部浮動小数点数 (NV)
10722 D ネイティブフォーマットの長い倍精度浮動小数点数(long double)。
10723 (long double は、システムが long double に対応していて、かつ Perl が
10724 long double 対応としてコンパイルされている場合にのみ使用可能です。
10725 それ以外の場合は例外が発生します。
10726 long double 型式の場合は異なることに注意してください)
10727
10728=begin original
10729
10730 p A pointer to a null-terminated string.
10731 P A pointer to a structure (fixed-length string).
10732
10733=end original
10734
10735 p ヌル文字で終端する文字列へのポインタ。
10736 P 構造体 (固定長文字列) へのポインタ。
10737
10738=begin original
10739
10740 u A uuencoded string.
10741 U A Unicode character number. Encodes to a character in char-
10742 acter mode and UTF-8 (or UTF-EBCDIC in EBCDIC platforms) in
10743 byte mode.
10744
10745=end original
10746
10747 u uuencode 文字列。
10748 U Unicode 文字番号。文字モードでは文字に、バイトモードなら UTF-8 に
10749 (EBCDIC システムでは UTF-EBCDIC に)エンコードされます。
10750
10751=begin original
10752
10753 w A BER compressed integer (not an ASN.1 BER, see perlpacktut
10754 for details). Its bytes represent an unsigned integer in
10755 base 128, most significant digit first, with as few digits
10756 as possible. Bit eight (the high bit) is set on each byte
10757 except the last.
10758
10759=end original
10760
10761 w A BER 圧縮変数(ASN.1 BER ではありません; 詳細については perlpacktut を
10762 参照してください)。このバイト列はできるだけ少ない桁数で表現された
10763 128 を基とした符号なし整数で、最上位ビットから順に並びます。
10764 最後のバイト以外の各バイトのビット 8 (上位ビット) がセットされます。
10765
10766=begin original
10767
10768 x A null byte (a.k.a ASCII NUL, "\000", chr(0))
10769 X Back up a byte.
10770 @ Null-fill or truncate to absolute position, counted from the
10771 start of the innermost ()-group.
10772 . Null-fill or truncate to absolute position specified by
10773 the value.
10774 ( Start of a ()-group.
10775
10776=end original
10777
10778 x ヌル文字 (つまり ASCII NUL, "\000", chr(0))
10779 X 1 文字後退。
10780 @ 一番内側の () の組の開始位置から数えて、絶対位置までヌル文字で
10781 埋めるか切り詰める。
10782 . 値で指定した絶対位置までヌル文字で埋めるか切り詰める。
10783 ( () の組の開始。
10784
10785=begin original
10786
10787One or more modifiers below may optionally follow certain letters in the
10788TEMPLATE (the second column lists letters for which the modifier is valid):
10789
10790=end original
10791
10792以下に示す一つまたは複数の修飾子を、TEMPLATE の文字のいくつかにオプションで
10793付けることができます(表の 2 列目は、その修飾子が有効な文字です):
10794
10795=begin original
10796
10797 ! sSlLiI Forces native (short, long, int) sizes instead
10798 of fixed (16-/32-bit) sizes.
10799
10800=end original
10801
10802 ! sSlLiI 固定の(16/32 ビット)サイズではなく、ネイティブな
10803 (short, long, int)サイズを強制する。
10804
10805=begin original
10806
10807 ! xX Make x and X act as alignment commands.
10808
10809=end original
10810
10811 ! xX x と X をアライメントコマンドとして振舞わせる。
10812
10813=begin original
10814
10815 ! nNvV Treat integers as signed instead of unsigned.
10816
10817=end original
10818
10819 ! nNvV 整数を符号なしではなく符号付きとして扱わせる。
10820
10821=begin original
10822
10823 ! @. Specify position as byte offset in the internal
10824 representation of the packed string. Efficient
10825 but dangerous.
10826
10827=end original
10828
10829 ! @. pack された内部表現のバイトオフセットとして位置を指定する。
10830 効率的ですが危険です。
10831
10832=begin original
10833
10834 > sSiIlLqQ Force big-endian byte-order on the type.
10835 jJfFdDpP (The "big end" touches the construct.)
10836
10837=end original
10838
10839 > sSiIlLqQ これらの型のバイト順をビッグエンディアンに強制します。
10840 jJfFdDpP (「大きい端」が構造に触れています。)
10841
10842=begin original
10843
10844 < sSiIlLqQ Force little-endian byte-order on the type.
10845 jJfFdDpP (The "little end" touches the construct.)
10846
10847=end original
10848
10849 < sSiIlLqQ これらの型のバイト順をリトルエンディアンに強制します。
10850 jJfFdDpP (「小さい端」が構造に触れています。)
10851
10852=begin original
10853
10854The C<< > >> and C<< < >> modifiers can also be used on C<()> groups
10855to force a particular byte-order on all components in that group,
10856including all its subgroups.
10857
10858=end original
10859
10860C<< > >> と C<< < >> の修飾子は C<()>-グループでも使えます;
10861この場合はそのグループと全ての副グループ内の全ての要素を特定のバイト順に
10862強制します。
10863
10864=begin comment
10865
10866Larry recalls that the hex and bit string formats (H, h, B, b) were added to
10867pack for processing data from NASA's Magellan probe. Magellan was in an
10868elliptical orbit, using the antenna for the radar mapping when close to
10869Venus and for communicating data back to Earth for the rest of the orbit.
10870There were two transmission units, but one of these failed, and then the
10871other developed a fault whereby it would randomly flip the sense of all the
10872bits. It was easy to automatically detect complete records with the correct
10873sense, and complete records with all the bits flipped. However, this didn't
10874recover the records where the sense flipped midway. A colleague of Larry's
10875was able to pretty much eyeball where the records flipped, so they wrote an
10876editor named kybble (a pun on the dog food Kibbles 'n Bits) to enable him to
10877manually correct the records and recover the data. For this purpose pack
10878gained the hex and bit string format specifiers.
10879
10880git shows that they were added to perl 3.0 in patch #44 (Jan 1991, commit
1088127e2fb84680b9cc1), but the patch description makes no mention of their
10882addition, let alone the story behind them.
10883
10884=end comment
10885
10886=begin original
10887
108886624The following rules apply:
108896625
108906626=end original
108916627
108926628以下の条件が適用されます:
108936629
10894=over
6630=over 8
108956631
108966632=item *
108976633
108986634=begin original
108996635
10900Each letter may optionally be followed by a number indicating the repeat
6636Each letter may optionally be followed by a number giving a repeat
10901count. A numeric repeat count may optionally be enclosed in brackets, as
6637count. With all types except C<a>, C<A>, C<Z>, C<b>, C<B>, C<h>,
10902in C<pack("C[80]", @arr)>. The repeat count gobbles that many values from
6638C<H>, and C<P> the pack function will gobble up that many values from
10903the LIST when used with all format types other than C<a>, C<A>, C<Z>, C<b>,
6639the LIST. A C<*> for the repeat count means to use however many items are
10904C<B>, C<h>, C<H>, C<@>, C<.>, C<x>, C<X>, and C<P>, where it means
6640left, except for C<@>, C<x>, C<X>, where it is equivalent
10905something else, described below. Supplying a C<*> for the repeat count
6641to C<0>, and C<u>, where it is equivalent to 1 (or 45, what is the
10906instead of a number means to use however many items are left, except for:
6642same).
109076643
109086644=end original
109096645
109106646これらの文字の後には、繰り返し数を示す数字を付けることができます。
10911数値の繰り返し数は C<pack "C[80]", @arr> のように大かっこ
6647C<a>, C<A>, C<Z>, C<b>, C<B>, C<h>, C<H>, C<P> 以外全ての型は、
10912囲むこともできます。
6648LIST からその数の値を取り出して使います。
10913C<a>, C<A>, C<Z>, C<b>, C<B>, C<h>, C<H>, C<@>, C<.>, C<x>, C<X>, C<P>
6649くり返し数に C<*> を指定すると、その時点で残っているすべての要素を意味します。
10914以外の全ての型では、LIST から繰り返し数の値を取り出して使います。
6650ただし、C<@>, C<x>, C<X>では C<0> と C<u> と等価で、
10915繰り返し数に C<*> を指定すと、以下の例外を除て、
66511 (あるいは 45 でも同じ) と等価です。
10916その時点で残っているすべての要素を意味します。
109176652
10918=over
10919
10920=item *
10921
109226653=begin original
109236654
10924C<@>, C<x>, and C<X>, where it is equivalent to C<0>.
6655When used with C<Z>, C<*> results in the addition of a trailing null
6656byte (so the packed result will be one longer than the byte C<length>
6657of the item).
109256658
109266659=end original
109276660
10928C<@>, C<x>, C<X> では C<0> 等価で
6661C<*> C<Z> と共に使われた場合、末尾にヌルバイトをつけま
6662(従ってパックされた結果は要素の C<length> の値より 1 大きくなります)。
109296663
10930=item *
10931
109326664=begin original
109336665
10934<.>, where it means relative to the start of the string.
10935
10936=end original
10937
10938<.> では文字列の先頭からの相対位置を意味します。
10939
10940=item *
10941
10942=begin original
10943
10944C<u>, where it is equivalent to 1 (or 45, which here is equivalent).
10945
10946=end original
10947
10948C<u> では 1 (あるいはここでは 45 でも等価です) と等価です。
10949
10950=back
10951
10952=begin original
10953
10954One can replace a numeric repeat count with a template letter enclosed in
10955brackets to use the packed byte length of the bracketed template for the
10956repeat count.
10957
10958=end original
10959
10960このテンプレートでパックされたバイト長を繰り返し数として使うために、
10961大かっこで囲まれたテンプレートで数値の繰り返し数を置き換えることが
10962できます。
10963
10964=begin original
10965
10966For example, the template C<x[L]> skips as many bytes as in a packed long,
10967and the template C<"$t X[$t] $t"> unpacks twice whatever $t (when
10968variable-expanded) unpacks. If the template in brackets contains alignment
10969commands (such as C<x![d]>), its packed length is calculated as if the
10970start of the template had the maximal possible alignment.
10971
10972=end original
10973
10974例えば、テンプレート C<x[L]> は long でパックされたバイト数分だけスキップし、
10975テンプレート C<"$t X[$t] $t"> は $t (変数展開された場合)を
10976unpack したものの 2 倍を unpack します。
10977(C<x![d]> のように) 大かっこにアライメントコマンドが含まれている場合、
10978パックされた長さは、テンプレートの先頭で最大限可能なアライメントを
10979持っているものとして計算されます。
10980
10981=begin original
10982
10983When used with C<Z>, a C<*> as the repeat count is guaranteed to add a
10984trailing null byte, so the resulting string is always one byte longer than
10985the byte length of the item itself.
10986
10987=end original
10988
10989C<Z> で、繰り返し数として C<*> が使われた場合、末尾にヌルバイトが
10990保証されるので、結果の文字列は常にアイテム自身のバイト長よりも 1 バイト
10991長くなります。
10992
10993=begin original
10994
10995When used with C<@>, the repeat count represents an offset from the start
10996of the innermost C<()> group.
10997
10998=end original
10999
11000C<@> で使うと、繰り返し数は一番内側の C<()> グループの先頭からのオフセットを
11001表現します。
11002
11003=begin original
11004
11005When used with C<.>, the repeat count determines the starting position to
11006calculate the value offset as follows:
11007
11008=end original
11009
11010C<.> で使われると、繰り返し数は以下のようにして、
11011値のオフセットを計算するための開始位置を決定するために使われます。
11012
11013=over
11014
11015=item *
11016
11017=begin original
11018
11019If the repeat count is C<0>, it's relative to the current position.
11020
11021=end original
11022
11023繰り返し数が C<0> なら、現在位置からの相対位置となります。
11024
11025=item *
11026
11027=begin original
11028
11029If the repeat count is C<*>, the offset is relative to the start of the
11030packed string.
11031
11032=end original
11033
11034繰り返し数が C<*> なら、オフセットは pack された文字列の先頭からの
11035相対位置です。
11036
11037=item *
11038
11039=begin original
11040
11041And if it's an integer I<n>, the offset is relative to the start of the
11042I<n>th innermost C<( )> group, or to the start of the string if I<n> is
11043bigger then the group level.
11044
11045=end original
11046
11047そして整数 I<n> なら、オフセットは一番内側から I<n> 番目の C<( )> グループの
11048先頭、あるいは I<n> がグループレベルより大きい場合は文字列の先頭からの
11049相対位置です。
11050
11051=back
11052
11053=begin original
11054
110556666The repeat count for C<u> is interpreted as the maximal number of bytes
11056to encode per line of output, with 0, 1 and 2 replaced by 45. The repeat
6667to encode per line of output, with 0 and 1 replaced by 45.
11057count should not be more than 65.
110586668
110596669=end original
110606670
110616671C<u> での繰り返し回数は、出力行毎に最大何バイトまでをエンコードするかを
11062示します; 0, 1, 2 は 45 として扱われます。
6672示します0 1 は 45 として扱われます。
11063繰り返し数は 65 を超えてはなりません。
110646673
110656674=item *
110666675
110676676=begin original
110686677
110696678The C<a>, C<A>, and C<Z> types gobble just one value, but pack it as a
11070string of length count, padding with nulls or spaces as needed. When
6679string of length count, padding with nulls or spaces as necessary. When
11071unpacking, C<A> strips trailing whitespace and nulls, C<Z> strips everything
6680unpacking, C<A> strips trailing spaces and nulls, C<Z> strips everything
11072after the first null, and C<a> returns data with no stripping at all.
6681after the first null, and C<a> returns data verbatim. When packing,
6682C<a>, and C<Z> are equivalent.
110736683
110746684=end original
110756685
110766686C<a>, C<A>, C<Z> という型を使うと、値を一つだけ取り出して使いますが、
110776687繰り返し数で示す長さの文字列となるように、必要に応じてヌル文字か
110786688スペース文字を付け足します。
11079unpack するとき、C<A> は後続の空白やヌル文字を取り除きます; C<Z> は最初の
6689unpack するとき、C<A> は後続のスペース文字やヌル文字を取り除きます
11080ヌル文字以降の全てを取り除きます; C<a> はデータを取り除くことなく
6690C<Z>は最初のヌル文字以降の全てを取り除きます
11081そのまま返します。
6691C<a>はデータをそのまま返します。
6692pack するときは、 C<a> と C<Z> は等価です。
110826693
110836694=begin original
110846695
11085If the value to pack is too long, the result is truncated. If it's too
6696If the value-to-pack is too long, it is truncated. If too long and an
11086long and an explicit count is provided, C<Z> packs only C<$count-1> bytes,
6697explicit count is provided, C<Z> packs only C<$count-1> bytes, followed
11087followed by a null byte. Thus C<Z> always packs a trailing null, except
6698by a null byte. Thus C<Z> always packs a trailing null byte under
11088when the count is 0.
6699all circumstances.
110896700
110906701=end original
110916702
11092pack する値が長すぎる場合、結果は切り詰められます。
6703pack する値が長すぎる場合、切り詰められます。
110936704長すぎてかつ明示的に個数が指定されている場合、
110946705C<Z> は C<$count-1> バイトまで pack し、その後にヌルバイトがつきます。
11095従って、C<Z> は、繰り返し数が 0 場合を除いて、常に末尾にヌルバイトが
6706従って、C<Z> はような状態でも常に末尾にヌルバイトがつきます。
11096つきます。
110976707
110986708=item *
110996709
111006710=begin original
111016711
11102Likewise, the C<b> and C<B> formats pack a string that's that many bits long.
6712Likewise, the C<b> and C<B> fields pack a string that many bits long.
11103Each such format generates 1 bit of the result. These are typically followed
6713Each byte of the input field of pack() generates 1 bit of the result.
11104by a repeat count like C<B8> or C<B64>.
6714Each result bit is based on the least-significant bit of the corresponding
6715input byte, i.e., on C<ord($byte)%2>. In particular, bytes C<"0"> and
6716C<"1"> generate bits 0 and 1, as do bytes C<"\0"> and C<"\1">.
111056717
111066718=end original
111076719
111086720同様に、C<b> や C<B> は、繰り返し数で示すビット長のビット列に pack します。
11109これらの各文字は結果の 1 ビットを生成します。
6721pack() 入力フィールドのバイトは結果の 1 ビットを生成します。
11110典型的には C<B8> や C<B64> ような繰り返しカウンが引き続きます
6722結果ビットのそぞれ対応する入力バイト最下位ビッを基にします
6723(つまり C<ord($byte)%2>)。
6724特に、バイト C<"0"> と C<"1"> は
6725バイト C<"\0"> と C<"\1"> と同様に、ビット 0 と 1 を生成します。
111116726
111126727=begin original
111136728
11114Each result bit is based on the least-significant bit of the corresponding
6729Starting from the beginning of the input string of pack(), each 8-tuple
11115input character, i.e., on C<ord($char)%2>. In particular, characters C<"0">
6730of bytes is converted to 1 byte of output. With format C<b>
11116and C<"1"> generate bits 0 and 1, as do characters C<"\000"> and C<"\001">.
6731the first byte of the 8-tuple determines the least-significant bit of a
6732byte, and with format C<B> it determines the most-significant bit of
6733a byte.
111176734
111186735=end original
111196736
11120結果ビットそれぞれは対応する入力文字の最下位ビッを基します
6737pack() の入力文字先頭から始めて、8 タプル毎に 1 バイの出力
11121(つり C<ord($char)%2>)
6738変換され
11122特に、文字 C<"0"> と C<"1"> 文字 C<"\000"> C<"\001"> と同様に
6739C<b> フォーマットで8 タプルの最初のバイトが出力の最下位ビットなり
11123ビット 0 と 1 を生成します。
11124
11125=begin original
11126
11127Starting from the beginning of the input string, each 8-tuple
11128of characters is converted to 1 character of output. With format C<b>,
11129the first character of the 8-tuple determines the least-significant bit of a
11130character; with format C<B>, it determines the most-significant bit of
11131a character.
11132
11133=end original
11134
11135pack() の入力文字列の先頭から始めて、8 タプル毎に 1 文字の出力に変換されます。
11136C<b> フォーマットでは 8 タプルの最初の文字が出力の最下位ビットとなります;
111376740C<B> フォーマットでは出力の最上位ビットとなります。
111386741
111396742=begin original
111406743
11141If the length of the input string is not evenly divisible by 8, the
6744If the length of the input string is not exactly divisible by 8, the
11142remainder is packed as if the input string were padded by null characters
6745remainder is packed as if the input string were padded by null bytes
11143at the end. Similarly during unpacking, "extra" bits are ignored.
6746at the end. Similarly, during unpack()ing the "extra" bits are ignored.
111446747
111456748=end original
111466749
111476750もし入力文字列の長さが 8 で割り切れない場合、余りの部分は入力文字列の
11148最後にヌル文字がパッディングされているものとしてパックされます。
6751最後にヌルバイトがパッディングされているものとしてパックされます。
11149同様に、unpack 中は「余分な」ビットは無視されます。
6752同様に、unpack() 中は「余分な」ビットは無視されます。
111506753
111516754=begin original
111526755
11153If the input string is longer than needed, remaining characters are ignored.
6756If the input string of pack() is longer than needed, extra bytes are ignored.
6757A C<*> for the repeat count of pack() means to use all the bytes of
6758the input field. On unpack()ing the bits are converted to a string
6759of C<"0">s and C<"1">s.
111546760
111556761=end original
111566762
11157入力文字列が必要な分よりも長い場合、余分な文字は無視されます。
6763pack() の入力文字列が必要な分よりも長い場合、余分な部分は無視されます。
6764pack() の繰り返し数として C<*> が指定されると、入力フィールドの全ての
6765バイト列がが使われます。
6766unpack() 時にはビット列は C<"0"> と C<"1"> の文字列に変換されます。
111586767
11159=begin original
11160
11161A C<*> for the repeat count uses all characters of the input field.
11162On unpacking, bits are converted to a string of C<0>s and C<1>s.
11163
11164=end original
11165
11166繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が使われます。
11167unpack 時にはビット列は C<0> と C<1> の文字列に変換されます。
11168
111696768=item *
111706769
111716770=begin original
111726771
11173The C<h> and C<H> formats pack a string that many nybbles (4-bit groups,
6772The C<h> and C<H> fields pack a string that many nybbles (4-bit groups,
11174representable as hexadecimal digits, C<"0".."9"> C<"a".."f">) long.
6773representable as hexadecimal digits, 0-9a-f) long.
111756774
111766775=end original
111776776
11178C<h> や C<H> は、多ニブル長(16 進文字である C<"0".."9"> C<"a".."f">
6777C<h> や C<H> は、多ニブル長(16 進文字である 0-9a-f で表現可能な
11179表現可能な 4 ビットグループ)のニブル列に pack します。
67784 ビットグループ)のニブル列に pack します。
111806779
111816780=begin original
111826781
11183For each such format, L<C<pack>|/pack TEMPLATE,LIST> generates 4 bits of result.
6782Each byte of the input field of pack() generates 4 bits of the result.
11184With non-alphabetical characters, the result is based on the 4 least-significant
6783For non-alphabetical bytes the result is based on the 4 least-significant
11185bits of the input character, i.e., on C<ord($char)%16>. In particular,
6784bits of the input byte, i.e., on C<ord($byte)%16>. In particular,
11186characters C<"0"> and C<"1"> generate nybbles 0 and 1, as do bytes
6785bytes C<"0"> and C<"1"> generate nybbles 0 and 1, as do bytes
11187C<"\000"> and C<"\001">. For characters C<"a".."f"> and C<"A".."F">, the result
6786C<"\0"> and C<"\1">. For bytes C<"a".."f"> and C<"A".."F"> the result
111886787is compatible with the usual hexadecimal digits, so that C<"a"> and
11189C<"A"> both generate the nybble C<0xA==10>. Use only these specific hex
6788C<"A"> both generate the nybble C<0xa==10>. The result for bytes
11190characters with this format.
6789C<"g".."z"> and C<"G".."Z"> is not well-defined.
111916790
111926791=end original
111936792
11194ようなマッ文字それぞれについて、L<C<pack>|/pack TEMPLATE,LIST>
6793pack() 入力ルドの各バイは結果4 ビットを生成します。
11195結果の 4 ビットを生成します。
6794英字でないバイトの場合、結果は入力バイト下位 4 ビットを
11196英字でない文字の場合、結果は入力文字の下位 4 ビットを
6795基にします(つまり C<ord($byte)%16>)。
11197します(つまり C<ord($char)%16>)。
6796、バイト C<"0"> C<"1"> はバイト C<"\0"> と C<"\1"> と同様に
11198特に、文字 C<"0"> と C<"1"> はバイト C<"\000"> と C<"\001"> と同様に
111996797ニブル 0 と 1 を生成します。
11200文字 C<"a".."f"> と C<"A".."F"> の場合は結果は通常の 16 進数と同じ結果に
6798バイト C<"a".."f"> と C<"A".."F"> の場合は結果は通常の
11201ので、C<"a"> と C<"A"> はどちらも ニブル C<0xa==10> を生成します。
679916 進数と同じ結果にりますので、C<"a"> と C<"A"> はどちらも
11202これらの 16 進文字はこの特定のフォーマットでだけ使ってください
6800ニブル C<0xa==10> を生成します
6801バイト C<"g".."z"> と C<"G".."Z"> に対する結果は未定義です。
112036802
112046803=begin original
112056804
11206Starting from the beginning of the template to
6805Starting from the beginning of the input string of pack(), each pair
11207L<C<pack>|/pack TEMPLATE,LIST>, each pair
6806of bytes is converted to 1 byte of output. With format C<h> the
11208of characters is converted to 1 character of output. With format C<h>, the
6807first byte of the pair determines the least-significant nybble of the
11209first character of the pair determines the least-significant nybble of the
6808output byte, and with format C<H> it determines the most-significant
11210output character; with format C<H>, it determines the most-significant
112116809nybble.
112126810
112136811=end original
112146812
11215L<C<pack>|/pack TEMPLATE,LIST> テンプレートの先頭から始めて、2 文字毎に
6813pack()入力文字列の先頭から始めて、2 バイトに 1 バイトの出力
112161 文字の出力に変換されます。
6814変換されます。
11217C<h> フォーマットでは 1 文字目が出力の最下位ニブルとなり、
6815C<h> フォーマットでは 1 バイト目が出力の最下位ニブルとなり、
112186816C<H> フォーマットでは出力の最上位ニブルとなります。
112196817
112206818=begin original
112216819
11222If the length of the input string is not even, it behaves as if padded by
6820If the length of the input string is not even, it behaves as if padded
11223a null character at the end. Similarly, "extra" nybbles are ignored during
6821by a null byte at the end. Similarly, during unpack()ing the "extra"
11224unpacking.
6822nybbles are ignored.
112256823
112266824=end original
112276825
11228入力文字列の長さが偶数でない場合、最後にヌル文字でパッディングされて
6826入力文字列の長さが偶数でない場合、最後にヌルバイトでパッディングされて
112296827いるかのように振る舞います。
11230同様に、unpack 中は「余分な」ニブルは無視されます。
6828同様に、unpack() 中は「余分な」ニブルは無視されます。
112316829
112326830=begin original
112336831
11234If the input string is longer than needed, extra characters are ignored.
6832If the input string of pack() is longer than needed, extra bytes are ignored.
6833A C<*> for the repeat count of pack() means to use all the bytes of
6834the input field. On unpack()ing the bits are converted to a string
6835of hexadecimal digits.
112356836
112366837=end original
112376838
11238入力文字列が必要な分より長い場合、余分な部分は無視されます。
6839pack() の入力文字列が必要な分より長い場合、余分な部分は無視されます。
6840pack() の繰り返し数として C<*> が指定されると、入力フィールドの全ての
6841バイト列がが使われます。
6842unpack() 時にはビット列は 16 進数の文字列に変換されます。
112396843
11240=begin original
11241
11242A C<*> for the repeat count uses all characters of the input field. For
11243L<C<unpack>|/unpack TEMPLATE,EXPR>, nybbles are converted to a string of
11244hexadecimal digits.
11245
11246=end original
11247
11248繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が使われます。
11249L<C<unpack>|/unpack TEMPLATE,EXPR> 時にはニブルは 16 進数の文字列に
11250変換されます。
11251
112526844=item *
112536845
112546846=begin original
112556847
11256The C<p> format packs a pointer to a null-terminated string. You are
6848The C<p> type packs a pointer to a null-terminated string. You are
11257responsible for ensuring that the string is not a temporary value, as that
6849responsible for ensuring the string is not a temporary value (which can
11258could potentially get deallocated before you got around to using the packed
6850potentially get deallocated before you get around to using the packed result).
11259result. The C<P> format packs a pointer to a structure of the size indicated
6851The C<P> type packs a pointer to a structure of the size indicated by the
11260by the length. A null pointer is created if the corresponding value for
6852length. A NULL pointer is created if the corresponding value for C<p> or
11261C<p> or C<P> is L<C<undef>|/undef EXPR>; similarly with
6853C<P> is C<undef>, similarly for unpack().
11262L<C<unpack>|/unpack TEMPLATE,EXPR>, where a null pointer unpacks into
11263L<C<undef>|/undef EXPR>.
112646854
112656855=end original
112666856
11267C<p> は、ヌル文字終端文字列へのポインタを pack します。
6857C<p>は、ヌル文字終端文字列へのポインタを pack します。
112686858文字列が一時的な値でない(つまり pack された結果を使う前に文字列が
11269解放されない) ことに責任を持つ必要があります
6859解放されない) ことに責任を持つ必要があります
112706860C<P> は、指定した長さの構造体へのポインタを pack します。
11271C<p> または C<P> に対応する値が L<C<undef>|/undef EXPR> だった場合、
6861C<p>またはC<P>に対応する値が C<undef> だった場合、
11272ヌルポインタが作成されます; ヌルポインタが L<C<undef>|/undef EXPR> に
6862unpack() と同様にヌルポインタが作成されます
11273unpack される L<C<unpack>|/unpack TEMPLATE,EXPR> と同様です。
112746863
11275=begin original
11276
11277If your system has a strange pointer size--meaning a pointer is neither as
11278big as an int nor as big as a long--it may not be possible to pack or
11279unpack pointers in big- or little-endian byte order. Attempting to do
11280so raises an exception.
11281
11282=end original
11283
11284システムのポインタが変わったサイズの場合--つまり、int の大きさでも
11285long の大きさでもない場合--ポインタをビッグエンディアンやリトルエンディアンの
11286バイト順で pack や unpack することはできません。
11287そうしようとすると例外が発生します。
11288
112896864=item *
112906865
112916866=begin original
112926867
11293The C</> template character allows packing and unpacking of a sequence of
6868The C</> template character allows packing and unpacking of strings where
11294items where the packed structure contains a packed item count followed by
6869the packed structure contains a byte count followed by the string itself.
11295the packed items themselves. This is useful when the structure you're
6870You write I<length-item>C</>I<string-item>.
11296unpacking has encoded the sizes or repeat counts for some of its fields
11297within the structure itself as separate fields.
112986871
112996872=end original
113006873
11301C</> テンプレート文字は、テム数の後にアイテムそのものが入っている形の
6874C</> テンプレート文字は、文字列の長さを示すバト列の後に
11302アイテム列を pack 及び unpack します。
6875文字列そのものが入っている形の文字列を pack 及び unpack します。
11303これは、unpack したい構造体が、サイズや繰り返し数が構造体自身
6876I<length-item>C</>I<string-item>なります。
11304独立したフィールドとしてエンコードされている場合に有効です。
113056877
113066878=begin original
113076879
11308For L<C<pack>|/pack TEMPLATE,LIST>, you write
6880The I<length-item> can be any C<pack> template letter,
11309I<length-item>C</>I<sequence-item>, and the
6881and describes how the length value is packed.
11310I<length-item> describes how the length value is packed. Formats likely
6882The ones likely to be of most use are integer-packing ones like
11311to be of most use are integer-packing ones like C<n> for Java strings,
6883C<n> (for Java strings), C<w> (for ASN.1 or SNMP)
11312C<w> for ASN.1 or SNMP, and C<N> for Sun XDR.
6884and C<N> (for Sun XDR).
113136885
113146886=end original
113156887
11316L<C<pack>|/pack TEMPLATE,LIST> では I<length-item>C</>I<string-item>
6888I<length-item> には任意の C<pack> テンプレート文字が利用でき、
11317なり、
6889長さの値がどのようパックされているかを指定します。
11318I<length-item> は長さの値がどのように pack されているかを指定します。
6890もっともよく使われるのは C<n>(Java 文字列), C<w>(SNMP), C<N>(Sun XDR) と
11319ともよく使われるのは Java 文字列 のめの C<n>、ASN.1 や SNMP のための
6891った整数型です。
11320C<w>、Sun XDR のための C<N> といった整数型です。
113216892
113226893=begin original
113236894
11324For L<C<pack>|/pack TEMPLATE,LIST>, I<sequence-item> may have a repeat
6895The I<string-item> must, at present, be C<"A*">, C<"a*"> or C<"Z*">.
11325count, in which case
6896For C<unpack> the length of the string is obtained from the I<length-item>,
11326the minimum of that and the number of available items is used as the argument
6897but if you put in the '*' it will be ignored.
11327for I<length-item>. If it has no repeat count or uses a '*', the number
11328of available items is used.
113296898
113306899=end original
113316900
11332L<C<pack>|/pack TEMPLATE,LIST> では、I<sequence-item> は繰り返し数を
6901I<string-item> は現在のところ C<"A*">, C<"a*">, C<"Z*"> のいずれかで
11333持つことがあり、その場合はその最小値と利用可能アイテムの数は
6902ければなりません。
11334I<length-item> のための引数として使われます
6903C<unpack> の場合は文字列の長さは I<length-item> から得られますが、
11335繰り返し数がなかったり、'*' を使う、利用可能なアイテムの数が使われます。
6904'*' を置く無視されます。
113366905
11337=begin original
6906 unpack 'C/a', "\04Gurusamy"; gives 'Guru'
6907 unpack 'a3/A* A*', '007 Bond J '; gives (' Bond','J')
6908 pack 'n/a* w/a*','hello,','world'; gives "\000\006hello,\005world"
113386909
11339For L<C<unpack>|/unpack TEMPLATE,EXPR>, an internal stack of integer
11340arguments unpacked so far is
11341used. You write C</>I<sequence-item> and the repeat count is obtained by
11342popping off the last element from the stack. The I<sequence-item> must not
11343have a repeat count.
11344
11345=end original
11346
11347L<C<unpack>|/unpack TEMPLATE,EXPR> では、今まで unpack した数値引数の
11348内部スタックが使われます。
11349C</>I<sequence-item> と書いて、繰り返し数はスタックから最後の要素を
11350取り出すことで得ます。
11351I<sequence-item> は繰り返し数を持っていてはいけません。
11352
113536910=begin original
113546911
11355If I<sequence-item> refers to a string type (C<"A">, C<"a">, or C<"Z">),
6912The I<length-item> is not returned explicitly from C<unpack>.
11356the I<length-item> is the string length, not the number of strings. With
11357an explicit repeat count for pack, the packed string is adjusted to that
11358length. For example:
113596913
113606914=end original
113616915
11362I<sequence-item> が文字列型 (C<"A">, C<"a">, C<"Z">) を参照している場合、
6916I<length-item> C<unpack> から明示的には返されません。
11363I<length-item> は文字列の数ではなく、文字列の長さです。
11364pack で明示的な繰り返し数があると、pack された文字列は与えられた
11365長さに調整されます。
11366例えば:
113676917
11368 This code: gives this result:
11369
11370 unpack("W/a", "\004Gurusamy") ("Guru")
11371 unpack("a3/A A*", "007 Bond J ") (" Bond", "J")
11372 unpack("a3 x2 /A A*", "007: Bond, J.") ("Bond, J", ".")
11373
11374 pack("n/a* w/a","hello,","world") "\000\006hello,\005world"
11375 pack("a/W2", ord("a") .. ord("z")) "2ab"
11376
113776918=begin original
113786919
11379The I<length-item> is not returned explicitly from
6920Adding a count to the I<length-item> letter is unlikely to do anything
11380L<C<unpack>|/unpack TEMPLATE,EXPR>.
6921useful, unless that letter is C<A>, C<a> or C<Z>. Packing with a
6922I<length-item> of C<a> or C<Z> may introduce C<"\000"> characters,
6923which Perl does not regard as legal in numeric strings.
113816924
113826925=end original
113836926
11384I<length-item> は L<C<unpack>|/unpack TEMPLATE,EXPR> から明示的には
6927I<length-item> 文字繰り返し数をつけるの
11385返されません。
11386
11387=begin original
11388
11389Supplying a count to the I<length-item> format letter is only useful with
11390C<A>, C<a>, or C<Z>. Packing with a I<length-item> of C<a> or C<Z> may
11391introduce C<"\000"> characters, which Perl does not regard as legal in
11392numeric strings.
11393
11394=end original
11395
11396I<length-item> 文字に繰り返し数をつけるのは、
113976928文字が C<A>, C<a>, C<Z> でない限りは有用ではありません。
11398C<a> や C<Z> を I<length-item> として pack すると C<"\000"> 文字が
6929C<a> や C<Z> を I<length-item> としてパックすると C<"\000"> 文字が
113996930出力されることがあり、Perl はこれを有効な数値文字列として認識しません。
114006931
114016932=item *
114026933
114036934=begin original
114046935
114056936The integer types C<s>, C<S>, C<l>, and C<L> may be
11406followed by a C<!> modifier to specify native shorts or
6937immediately followed by a C<!> suffix to signify native shorts or
11407longs. As shown in the example above, a bare C<l> means
6938longs--as you can see from above for example a bare C<l> does mean
11408exactly 32 bits, although the native C<long> as seen by the local C compiler
6939exactly 32 bits, the native C<long> (as seen by the local C compiler)
11409may be larger. This is mainly an issue on 64-bit platforms. You can
6940may be larger. This is an issue mainly in 64-bit platforms. You can
11410see whether using C<!> makes any difference this way:
6941see whether using C<!> makes any difference by
114116942
114126943=end original
114136944
11414C<s>, C<S>, C<l>, C<L> の整数タイプに引き続いて C<!> 修飾子
6945C<s>, C<S>, C<l>, C<L> の整数タイプの直後接尾辞として C<!> を
11415つけることで、ネイティブの short や long を指定できます
6946つけることで、ネイティブの short や long を指定できます --
11416上述のように、C<l> は正確に 32 ビットですが、ネイティブな
6947上述のように、例えば C<l> は正確に 32 ビットであり、ネイティブな
114176948(ローカルな C コンパイラによる)C<long> はもっと大きいかもしれません。
114186949これは主に 64 ビットプラットフォームで意味があります。
114196950C<!> を使うことによって違いがあるかどうかは以下のようにして調べられます:
114206951
11421 printf "format s is %d, s! is %d\n",
6952 print length(pack("s")), " ", length(pack("s!")), "\n";
11422 length pack("s"), length pack("s!");
6953 print length(pack("l")), " ", length(pack("l!")), "\n";
114236954
11424 printf "format l is %d, l! is %d\n",
11425 length pack("l"), length pack("l!");
11426
114276955=begin original
114286956
11429C<i!> and C<I!> are also allowed, but only for completeness' sake:
6957C<i!> and C<I!> also work but only because of completeness;
114306958they are identical to C<i> and C<I>.
114316959
114326960=end original
114336961
114346962C<i!> と C<I!> も動作しますが、単に完全性のためだけです;
114356963これは C<i> 及び C<I> と同じです。
114366964
114376965=begin original
114386966
114396967The actual sizes (in bytes) of native shorts, ints, longs, and long
11440longs on the platform where Perl was built are also available from
6968longs on the platform where Perl was built are also available via
11441the command line:
6969L<Config>:
114426970
114436971=end original
114446972
114456973Perl がビルドされたプラットフォームでの short, int, long, long long の
11446実際の(バイト数での)サイズはコマンドラインか:
6974実際の(バイト数での)サイズは L<Config> でも得れます。
114476975
11448 $ perl -V:{short,int,long{,long}}size
11449 shortsize='2';
11450 intsize='4';
11451 longsize='4';
11452 longlongsize='8';
11453
11454=begin original
11455
11456or programmatically via the L<C<Config>|Config> module:
11457
11458=end original
11459
11460あるいは L<C<Config>|Config> モジュールからプログラムで:
11461
114626976 use Config;
114636977 print $Config{shortsize}, "\n";
114646978 print $Config{intsize}, "\n";
114656979 print $Config{longsize}, "\n";
114666980 print $Config{longlongsize}, "\n";
114676981
114686982=begin original
114696983
11470C<$Config{longlongsize}> is undefined on systems without
6984(The C<$Config{longlongsize}> will be undefine if your system does
11471long long support.
6985not support long longs.)
114726986
114736987=end original
114746988
11475システムが long long に対応していない場合は C<$Config{longlongsize}> は
6989(システムが long long に対応していない場合は C<$Config{longlongsize}> は
11476未定義値になります。
6990未定義値になります。)
114776991
114786992=item *
114796993
114806994=begin original
114816995
11482The integer formats C<s>, C<S>, C<i>, C<I>, C<l>, C<L>, C<j>, and C<J> are
6996The integer formats C<s>, C<S>, C<i>, C<I>, C<l>, and C<L>
11483inherently non-portable between processors and operating systems because
6997are inherently non-portable between processors and operating systems
11484they obey native byteorder and endianness. For example, a 4-byte integer
6998because they obey the native byteorder and endianness. For example a
114850x12345678 (305419896 decimal) would be ordered natively (arranged in and
69994-byte integer 0x12345678 (305419896 decimal) be ordered natively
11486handled by the CPU registers) into bytes as
7000(arranged in and handled by the CPU registers) into bytes as
114877001
114887002=end original
114897003
11490整数フォーマット C<s>, C<S>, C<i>, C<I>, C<l>, C<L>, C<j>, C<J>
7004整数フォーマット C<s>, C<S>, C<i>, C<I>, C<l>, C<L> は
114917005ネイティブなバイト順序とエンディアンに従っているため、
114927006本質的にプロセッサ間や OS 間で移植性がありません。
114937007例えば 4 バイトの整数 0x12345678 (10 進数では 305419896) は
114947008内部では(CPU レジスタによって変換され扱われる形では)
114957009以下のようなバイト列に並べられます:
114967010
11497 0x12 0x34 0x56 0x78 # big-endian
7011 0x12 0x34 0x56 0x78 # big-endian
11498 0x78 0x56 0x34 0x12 # little-endian
7012 0x78 0x56 0x34 0x12 # little-endian
114997013
115007014=begin original
115017015
11502Basically, Intel and VAX CPUs are little-endian, while everybody else,
7016Basically, the Intel and VAX CPUs are little-endian, while everybody
11503including Motorola m68k/88k, PPC, Sparc, HP PA, Power, and Cray, are
7017else, for example Motorola m68k/88k, PPC, Sparc, HP PA, Power, and
11504big-endian. Alpha and MIPS can be either: Digital/Compaq uses (well, used)
7018Cray are big-endian. Alpha and MIPS can be either: Digital/Compaq
11505them in little-endian mode, but SGI/Cray uses them in big-endian mode.
7019used/uses them in little-endian mode; SGI/Cray uses them in big-endian mode.
115067020
115077021=end original
115087022
11509基本的に、Intel と VAX の CPU はリトルエンディアンです; 一方、
7023基本的に、Intel と VAX の CPU はリトルエンディアンです
11510Motorola m68k/88k, PPC, Sparc, HP PA, Power, Cray などを含むその他の全ては
7024一方それ以外、例えば Motorola m68k/88k, PPC, Sparc, HP PA, Power,
11511ビッグエンディアンです。
7025Cray などはビッグエンディアンです。
11512Alpha と MIPS は両方ともあります: Digital/Compaq はリトルエンディアンモードで
7026Alpha と MIPS は両方ともあります:
11513使っています (えーと、いました) が、SGI/Crayビッグエンディアンモードで
7027Digital/Compaqリトルエンディアンモードで使っています(いました);
11514使っています。
7028SGI/Cray はビッグエンディアンモードで使っています。
115157029
115167030=begin original
115177031
11518The names I<big-endian> and I<little-endian> are comic references to the
7032The names `big-endian' and `little-endian' are comic references to
11519egg-eating habits of the little-endian Lilliputians and the big-endian
7033the classic "Gulliver's Travels" (via the paper "On Holy Wars and a
11520Blefuscudians from the classic Jonathan Swift satire, I<Gulliver's Travels>.
7034Plea for Peace" by Danny Cohen, USC/ISI IEN 137, April 1, 1980) and
11521This entered computer lingo via the paper "On Holy Wars and a Plea for
7035the egg-eating habits of the Lilliputians.
11522Peace" by Danny Cohen, USC/ISI IEN 137, April 1, 1980.
115237036
115247037=end original
115257038
11526I<ビッグエンディアン> I<リトルエンディアン> の名前は
7039ビッグエンディアンリトルエンディアンの名前は
11527ジョナサン=スウィフトによる風刺小説の古典 I<ガリバー旅行記> で卵を
7040古典である「ガリバー旅行記」とリリパット族の卵を食べる習慣から
11528小さい方からむくリリパット国と大きい方からむくブレフスキュ国から
115297041取られています。
11530"On Holy Wars and a Plea for Peace" by Danny Cohen, USC/ISI IEN 137,
11531April 1, 1980 の文書からコンピュータ用語として取り入れられました。
115327042
115337043=begin original
115347044
115357045Some systems may have even weirder byte orders such as
115367046
115377047=end original
115387048
115397049以下のような、さらに変わったバイト順序を持つシステムもあるかもしれません:
115407050
11541 0x56 0x78 0x12 0x34
7051 0x56 0x78 0x12 0x34
11542 0x34 0x12 0x78 0x56
7052 0x34 0x12 0x78 0x56
115437053
115447054=begin original
115457055
11546These are called mid-endian, middle-endian, mixed-endian, or just weird.
7056You can see your system's preference with
115477057
115487058=end original
115497059
11550これら mid-endian, middle-endian, mixed-endian あるいは単おかなもの
7060システムの設定以下のようにして見るこができます:
11551呼ばれます。
115527061
11553=begin original
7062 print join(" ", map { sprintf "%#02x", $_ }
7063 unpack("C*",pack("L",0x12345678))), "\n";
115547064
11555You can determine your system endianness with this incantation:
11556
11557=end original
11558
11559システムの設定は以下のようにして調べられます:
11560
11561 printf("%#02x ", $_) for unpack("W*", pack L=>0x12345678);
11562
115637065=begin original
115647066
115657067The byteorder on the platform where Perl was built is also available
115667068via L<Config>:
115677069
115687070=end original
115697071
115707072Perl がビルドされたプラットフォームでのバイト順序は
11571L<Config> 経由か:
7073L<Config> でも知ることができます:
115727074
11573 use Config;
7075 use Config;
11574 print "$Config{byteorder}\n";
7076 print $Config{byteorder}, "\n";
115757077
115767078=begin original
115777079
11578or from the command line:
7080Byteorders C<'1234'> and C<'12345678'> are little-endian, C<'4321'>
7081and C<'87654321'> are big-endian.
115797082
115807083=end original
115817084
11582あるいコマドライで:
7085C<'1234'> と C<'12345678'> リトルエディア
7086C<'4321'> と C<'87654321'> はビッグエンディアンです。
115837087
11584 $ perl -V:byteorder
11585
115867088=begin original
115877089
11588Byteorders C<"1234"> and C<"12345678"> are little-endian; C<"4321">
7090If you want portable packed integers use the formats C<n>, C<N>,
11589and C<"87654321"> are big-endian. Systems with multiarchitecture binaries
7091C<v>, and C<V>, their byte endianness and size is known.
11590will have C<"ffff">, signifying that static information doesn't work,
7092See also L<perlport>.
11591one must use runtime probing.
115927093
115937094=end original
115947095
11595C<"1234"> と C<"12345678"> はリトルエンディアンです;
11596C<"4321"> と C<"87654321"> はビッグエンディアンです。
11597マルチアーキテクチャバイナリを持つシステムは
11598C<"ffff"> となります; これは静的な情報は動作せず、実行時調査を使う必要が
11599あることを示します。
11600
11601=begin original
11602
11603For portably packed integers, either use the formats C<n>, C<N>, C<v>,
11604and C<V> or else use the C<< > >> and C<< < >> modifiers described
11605immediately below. See also L<perlport>.
11606
11607=end original
11608
116097096移植性のあるパック化された整数がほしい場合は、
11610C<n>, C<N>, C<v>, C<V> フォーマットを使うか、
7097C<n>, C<N>, C<v>, C<V> を使ってください。
11611直後で説明する C<< > >> C<< < >> の修飾子使えます。
7098これらはバイトエンディアンサイズ固定されています。
11612L<perlport> も参照してください。
7099L<perlport> も参照してさい。
116137100
116147101=item *
116157102
116167103=begin original
116177104
11618Also floating point numbers have endianness. Usually (but not always)
7105Real numbers (floats and doubles) are in the native machine format only;
11619this agrees with the integer endianness. Even though most platforms
7106due to the multiplicity of floating formats around, and the lack of a
11620these days use the IEEE 754 binary format, there are differences,
7107standard "network" representation, no facility for interchange has been
11621especially if the long doubles are involved. You can see the
7108made. This means that packed floating point data written on one machine
11622C<Config> variables C<doublekind> and C<longdblkind> (also C<doublesize>,
7109may not be readable on another - even if both use IEEE floating point
11623C<longdblsize>): the "kind" values are enums, unlike C<byteorder>.
7110arithmetic (as the endian-ness of the memory representation is not part
11624
11625=end original
11626
11627また、浮動小数点数にもエンディアンがあります。
11628通常は(但し常にではありません)これは整数のエンディアンと同じです。
11629最近のほとんどのプラットフォームが IEEE 754 バイナリ形式を使っているにも
11630関わらず、(特に long double 関連で) 相違点があります。
11631C<Config> 変数 C<doublekind> と C<longdblkind> (および C<doublesize>,
11632C<longdblsize>) を参照できます: "kind" 値は C<byteorder> と異なり、
11633順序値です。
11634
11635=begin original
11636
11637Portability-wise the best option is probably to keep to the IEEE 754
1163864-bit doubles, and of agreed-upon endianness. Another possibility
11639is the C<"%a">) format of L<C<printf>|/printf FILEHANDLE FORMAT, LIST>.
11640
11641=end original
11642
11643移植性を考慮した最良の選択肢はおそらく、IEEE 754 64-bit double と同意した
11644エンディアンを維持することです。
11645もう一つの可能性は L<C<printf>|/printf FILEHANDLE FORMAT, LIST> の
11646C<"%a"> 型式です。
11647
11648=item *
11649
11650=begin original
11651
11652Starting with Perl 5.10.0, integer and floating-point formats, along with
11653the C<p> and C<P> formats and C<()> groups, may all be followed by the
11654C<< > >> or C<< < >> endianness modifiers to respectively enforce big-
11655or little-endian byte-order. These modifiers are especially useful
11656given how C<n>, C<N>, C<v>, and C<V> don't cover signed integers,
1165764-bit integers, or floating-point values.
11658
11659=end original
11660
11661Perl 5.10.0 から、C<p> と C<P> フォーマットや C<()> グループと同様、
11662全ての整数と浮動小数点数のフォーマットは、C<< > >> や C<< < >> の
11663エンディアン修飾子をつけることで、それぞれ
11664ビッグエンディアンとリトルエンディアンに強制させることができます。
11665C<n>, C<N>, C<v>, C<V> は符号付き整数、64 ビット整数、浮動小数点数に
11666対応していないので、これは特に有用です。
11667
11668=begin original
11669
11670Here are some concerns to keep in mind when using an endianness modifier:
11671
11672=end original
11673
11674エンディアン修飾子を使うときに心に留めておくべきことを記します:
11675
11676=over
11677
11678=item *
11679
11680=begin original
11681
11682Exchanging signed integers between different platforms works only
11683when all platforms store them in the same format. Most platforms store
11684signed integers in two's-complement notation, so usually this is not an issue.
11685
11686=end original
11687
11688異なったプラットフォームで符号付き整数を交換することは、全ての
11689プラットフォームで同じフォーマットで保存されている場合にのみうまくいきます。
11690ほとんどのプラットフォームでは符号付き整数は 2 の補数記法で保存するので、
11691普通はこれは問題になりません。
11692
11693=item *
11694
11695=begin original
11696
11697The C<< > >> or C<< < >> modifiers can only be used on floating-point
11698formats on big- or little-endian machines. Otherwise, attempting to
11699use them raises an exception.
11700
11701=end original
11702
11703C<< > >> や C<< < >> の修飾子はビッグエンディアンやリトルエンディアンの
11704マシンでの浮動小数点フォーマットでのみ使えます。
11705それ以外では、そのようなことをすると例外が発生します。
11706
11707=item *
11708
11709=begin original
11710
11711Forcing big- or little-endian byte-order on floating-point values for
11712data exchange can work only if all platforms use the same
11713binary representation such as IEEE floating-point. Even if all
11714platforms are using IEEE, there may still be subtle differences. Being able
11715to use C<< > >> or C<< < >> on floating-point values can be useful,
11716but also dangerous if you don't know exactly what you're doing.
11717It is not a general way to portably store floating-point values.
11718
11719=end original
11720
11721データ交換のために浮動小数点数のバイト順をビッグエンディアンかリトル
11722エンディアンに強制することは、全てのプラットフォームが
11723IEEE 浮動小数点フォーマットのような同じバイナリ表現の場合にのみ
11724うまくいきます。
11725たとえ全てのプラットフォームが IEEE を使っていても、そこには微妙な違いが
11726あるかもしれません。
11727浮動小数点数に C<< > >> や C<< < >> が使えることは便利な場合がありますが、
11728もし自分が何をしているかを正確に理解していなければ、危険です。
11729移植性のある浮動小数点数の保存のための一般的な方法はありません。
11730
11731=item *
11732
11733=begin original
11734
11735When using C<< > >> or C<< < >> on a C<()> group, this affects
11736all types inside the group that accept byte-order modifiers,
11737including all subgroups. It is silently ignored for all other
11738types. You are not allowed to override the byte-order within a group
11739that already has a byte-order modifier suffix.
11740
11741=end original
11742
11743C<()> グループで C<< > >> や C<< < >> を使うと、これは、副グループを
11744含む全ての型のうち、バイト順修飾子を受け入れる全てのものに影響与えます。
11745その他の型については沈黙のうちに無視されます。
11746既にバイト順接尾辞を持っているグループ内のバイト順を上書きすることは
11747できません。
11748
11749=back
11750
11751=item *
11752
11753=begin original
11754
11755Real numbers (floats and doubles) are in native machine format only.
11756Due to the multiplicity of floating-point formats and the lack of a
11757standard "network" representation for them, no facility for interchange has been
11758made. This means that packed floating-point data written on one machine
11759may not be readable on another, even if both use IEEE floating-point
11760arithmetic (because the endianness of the memory representation is not part
117617111of the IEEE spec). See also L<perlport>.
117627112
117637113=end original
117647114
117657115実数 (float と double) は、機種依存のフォーマットしかありません。
11766いろんな浮動小数点数のフォーマットが在り、標準的な "network" 表現といったものが
7116いろんな浮動小数点数のフォーマットが在り、標準的な
11767ないため、データ交換のための機能は用意してありません。
7117"network" 表現といったものがないため、データ交換のための機能は
7118用意してありません。
117687119つまり、あるマシンで pack した浮動小数点数は、別のマシンでは
11769読めないかもしれないということです; たとえ双方で IEEE フォーマットの
7120読めないかもしれないということです
11770浮動小数点数演算を行なっていてもです (IEEE の仕様では、メモリ表現上の
7121たとえ双方で IEEE フォーマットの浮動小数点数演算を行なっていてもです
11771バイト順序までは、規定されていないからです)。
7122(IEEE の仕様では、メモリ表現上のバイト順序までは、
7123規定されていないからです)。
117727124L<perlport> も参照してください。
117737125
117747126=begin original
117757127
11776If you know I<exactly> what you're doing, you can use the C<< > >> or C<< < >>
7128Note that Perl uses doubles internally for all numeric calculation, and
11777modifiers to force big- or little-endian byte-order on floating-point values.
7129converting from double into float and thence back to double again will
7130lose precision (i.e., C<unpack("f", pack("f", $foo)>) will not in general
7131equal $foo).
117787132
117797133=end original
117807134
11781もし何をしようとしいるかを I<正確> 理解しているなら、浮動小数点数の
7135Perl では、すべての数値演算のため、内部的に double を使用しています。
11782バイト順をビッグエンディアンやリトルエンディアン強制るために、
7136double から float へ変換し、それから再び double
11783C<< > >> と C<< < >> の修飾子が使えます。
7137精度が落ちるこになります (つまり、C<unpack("f", pack("f", $foo)>) は、
7138一般には $foo と同じではないということです)。
117847139
11785=begin original
11786
11787Because Perl uses doubles (or long doubles, if configured) internally for
11788all numeric calculation, converting from double into float and thence
11789to double again loses precision, so C<unpack("f", pack("f", $foo)>)
11790will not in general equal $foo.
11791
11792=end original
11793
11794Perl では、すべての数値演算のために、内部的に double (または設定によっては
11795long double) を使用しているので、double から float へ変換し、それから再び
11796double に戻すと精度が落ちることになり、C<unpack("f", pack("f", $foo)>) は、
11797一般には $foo と同じではありません。
11798
117997140=item *
118007141
118017142=begin original
118027143
11803Pack and unpack can operate in two modes: character mode (C<C0> mode) where
7144If the pattern begins with a C<U>, the resulting string will be treated
11804the packed string is processed per character, and UTF-8 byte mode (C<U0> mode)
7145as Unicode-encoded. You can force UTF8 encoding on in a string with an
11805where the packed string is processed in its UTF-8-encoded Unicode form on
7146initial C<U0>, and the bytes that follow will be interpreted as Unicode
11806a byte-by-byte basis. Character mode is the default
7147characters. If you don't want this to happen, you can begin your pattern
11807unless the format string starts with C<U>. You
7148with C<C0> (or anything else) to force Perl not to UTF8 encode your
11808can always switch mode mid-format with an explicit
7149string, and then follow this with a C<U*> somewhere in your pattern.
11809C<C0> or C<U0> in the format. This mode remains in effect until the next
11810mode change, or until the end of the C<()> group it (directly) applies to.
118117150
118127151=end original
118137152
11814pack unpack は二つのモード操作しす: pack された文字列を文字単位
7153パターンが C<U>っている場合、結果の文字列は Unicode
11815処理する文字モード (C<C0> モード) と、pack された文字列を、バイト毎に、
7154エンコードされているものとして扱われます。
11816その UTF-8 エンコードされた形式処理するUTF-8 モード (C<U0> モード) です。
7155先頭に C<U0> を持つ文字列で UTF8 エンコーディングを強制き、
11817文字モードはフォーマッ文字 C<U> で始まっいない限りはデフォルトです。
7156引き続くバイト列 Unicode 文字列とし解釈されます。
11818モードはフォーマット中に明示的に C<C0> または C<U0> と書くことつでも
7157のようなこが起きてほしくな場合は、
11819切り替えられます。
7158パターンを C<C0> (か他のもの)で始めることによって、
11820モードは次のモード切り替えられるか、(直接)適用された C<()> グルプが
7159Perl 文字列を UTF8 エンコドさせないように強制でき、
11821終了するで有効です。
7160その後にパターンのどこかに C<U*> を置きます。
118227161
11823=begin original
11824
11825Using C<C0> to get Unicode characters while using C<U0> to get I<non>-Unicode
11826bytes is not necessarily obvious. Probably only the first of these
11827is what you want:
11828
11829=end original
11830
11831Unicode 文字を取得するのに C<C0> を使い、I<非> Unicode バイトを取得するのに
11832C<U0> を使うというのは必ずしも明白ではありません。
11833おそらく、これらのうち最初のものだけが望みのものでしょう:
11834
11835 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
11836 perl -CS -ne 'printf "%v04X\n", $_ for unpack("C0A*", $_)'
11837 03B1.03C9
11838 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
11839 perl -CS -ne 'printf "%v02X\n", $_ for unpack("U0A*", $_)'
11840 CE.B1.CF.89
11841 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
11842 perl -C0 -ne 'printf "%v02X\n", $_ for unpack("C0A*", $_)'
11843 CE.B1.CF.89
11844 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
11845 perl -C0 -ne 'printf "%v02X\n", $_ for unpack("U0A*", $_)'
11846 C3.8E.C2.B1.C3.8F.C2.89
11847
11848=begin original
11849
11850Those examples also illustrate that you should not try to use
11851L<C<pack>|/pack TEMPLATE,LIST>/L<C<unpack>|/unpack TEMPLATE,EXPR> as a
11852substitute for the L<Encode> module.
11853
11854=end original
11855
11856これらの例は、L<C<pack>|/pack TEMPLATE,LIST>/
11857L<C<unpack>|/unpack TEMPLATE,EXPR> を L<Encode> モジュールの代わりとして
11858使おうとするべきではないということも示しています。
11859
118607162=item *
118617163
118627164=begin original
118637165
11864You must yourself do any alignment or padding by inserting, for example,
7166You must yourself do any alignment or padding by inserting for example
11865enough C<"x">es while packing. There is no way for
7167enough C<'x'>es while packing. There is no way to pack() and unpack()
11866L<C<pack>|/pack TEMPLATE,LIST> and L<C<unpack>|/unpack TEMPLATE,EXPR>
7168could know where the bytes are going to or coming from. Therefore
11867to know where characters are going to or coming from, so they
7169C<pack> (and C<unpack>) handle their output and input as flat
11868handle their output and input as flat sequences of characters.
7170sequences of bytes.
118697171
118707172=end original
118717173
11872pack するときに、例えば十分な数の C<"x"> を挿入することによって
7174パックするときに、例えば十分な数の C<'x'> を挿入することによって
118737175アライメントやパッディングを行うのは全て自分でしなければなりません。
11874L<C<pack>|/pack TEMPLATE,LIST> L<C<unpack>|/unpack TEMPLATE,EXPR> は、
7176バイト列がどこへ行くか・どこから来たかを pack() や unpack()
11875文字列がどこへ行くかやどこから来たかを
7177知る方法はありません。
11876知る方法ないので、出力と入力をフラットな文字列として扱います。
7178従って C<pack> (と C<unpack>) は出力と入力をフラットなバイト列として
7179扱います。
118777180
118787181=item *
118797182
118807183=begin original
118817184
11882A C<()> group is a sub-TEMPLATE enclosed in parentheses. A group may
7185A comment in a TEMPLATE starts with C<#> and goes to the end of line.
11883take a repeat count either as postfix, or for
11884L<C<unpack>|/unpack TEMPLATE,EXPR>, also via the C</>
11885template character. Within each repetition of a group, positioning with
11886C<@> starts over at 0. Therefore, the result of
118877186
118887187=end original
118897188
11890C<()> のグループはかっこで囲われた副テンプレートです。
11891グループは繰り返し数を取ることができます; 接尾辞によるか、
11892L<C<unpack>|/unpack TEMPLATE,EXPR> の場合は C</> テンプレート文字によります。
11893グループの繰り返し毎に、C<@> の位置は 0 になります。
11894従って、以下の結果は:
11895
11896 pack("@1A((@2A)@3A)", qw[X Y Z])
11897
11898=begin original
11899
11900is the string C<"\0X\0\0YZ">.
11901
11902=end original
11903
11904文字列 C<"\0X\0\0YZ"> です。
11905
11906=item *
11907
11908=begin original
11909
11910C<x> and C<X> accept the C<!> modifier to act as alignment commands: they
11911jump forward or back to the closest position aligned at a multiple of C<count>
11912characters. For example, to L<C<pack>|/pack TEMPLATE,LIST> or
11913L<C<unpack>|/unpack TEMPLATE,EXPR> a C structure like
11914
11915=end original
11916
11917C<x> と C<X> にはアライメントコマンドとして C<!> 修飾子を付けることができます:
11918これは C<count> 文字の倍数のアライメントとなる、もっとも近い位置に移動します。
11919例えば、以下のような C 構造体を L<C<pack>|/pack TEMPLATE,LIST> または
11920L<C<unpack>|/unpack TEMPLATE,EXPR> するには
11921
11922 struct {
11923 char c; /* one signed, 8-bit character */
11924 double d;
11925 char cc[2];
11926 }
11927
11928=begin original
11929
11930one may need to use the template C<c x![d] d c[2]>. This assumes that
11931doubles must be aligned to the size of double.
11932
11933=end original
11934
11935C<W x![d] d W[2]> というテンプレートを使う必要があるかもしれません。
11936これは double が double のサイズでアライメントされていることを
11937仮定しています。
11938
11939=begin original
11940
11941For alignment commands, a C<count> of 0 is equivalent to a C<count> of 1;
11942both are no-ops.
11943
11944=end original
11945
11946アライメントコマンドに対しては、C<count> に 0 を指定するのは
11947C<count> に 1 を指定するのと等価です; どちらも何もしません。
11948
11949=item *
11950
11951=begin original
11952
11953C<n>, C<N>, C<v> and C<V> accept the C<!> modifier to
11954represent signed 16-/32-bit integers in big-/little-endian order.
11955This is portable only when all platforms sharing packed data use the
11956same binary representation for signed integers; for example, when all
11957platforms use two's-complement representation.
11958
11959=end original
11960
11961C<n>, C<N>, C<v>, C<V> はビッグ/リトルエンディアンの順序で符号付き 16 または
1196232 ビット整数で表現するための C<!> 修飾子を受け入れます。
11963これは pack されたデータを共有する全てのプラットフォームが
11964符号付き整数について同じバイナリ表現を使う場合にのみ移植性があります;
11965例えば、全てのプラットフォームで 2 の補数表現を使う場合です。
11966
11967=item *
11968
11969=begin original
11970
11971Comments can be embedded in a TEMPLATE using C<#> through the end of line.
11972White space can separate pack codes from each other, but modifiers and
11973repeat counts must follow immediately. Breaking complex templates into
11974individual line-by-line components, suitably annotated, can do as much to
11975improve legibility and maintainability of pack/unpack formats as C</x> can
11976for complicated pattern matches.
11977
11978=end original
11979
119807189TEMPLATE の中の C<#> から行末まではコメントです。
11981空白は pack コードをそれぞれ分けるために使えますが、修飾子と
11982繰り返し数は直後に置かなければなりません。
11983複雑なテンプレートを個々の行単位の要素に分解して適切に注釈をつけると、
11984複雑なパターンマッチングに対する C</x> と同じぐらい、pack/unpack
11985フォーマットの読みやすさと保守性が向上します。
119867190
119877191=item *
119887192
119897193=begin original
119907194
11991If TEMPLATE requires more arguments than L<C<pack>|/pack TEMPLATE,LIST>
7195If TEMPLATE requires more arguments to pack() than actually given, pack()
11992is given, L<C<pack>|/pack TEMPLATE,LIST>
7196assumes additional C<""> arguments. If TEMPLATE requires less arguments
11993assumes additional C<""> arguments. If TEMPLATE requires fewer arguments
7197to pack() than actually given, extra arguments are ignored.
11994than given, extra arguments are ignored.
119957198
119967199=end original
119977200
11998TEMPLATE が要求する引数の数が L<C<pack>|/pack TEMPLATE,LIST> が実際に
7201TEMPLATE が要求する引数の数が pack() が実際に与えている数より多い場合、
11999与えているより多い場合、
7202追加の C<""> 引があるものと仮定します。
12000L<C<pack>|/pack TEMPLATE,LIST> は追加の C<""> 引数があるものと仮定します。
120017203TEMPLATE が要求する引数の数の方が少ない場合、余分の引数は無視されます。
120027204
12003=item *
12004
12005=begin original
12006
12007Attempting to pack the special floating point values C<Inf> and C<NaN>
12008(infinity, also in negative, and not-a-number) into packed integer values
12009(like C<"L">) is a fatal error. The reason for this is that there simply
12010isn't any sensible mapping for these special values into integers.
12011
12012=end original
12013
12014特殊浮動小数点値 C<Inf> と C<NaN>
12015((負を含む)無限と非数) を (C<"L"> のような) 整数値に pack しようとすると
12016致命的エラーとなります。
12017この理由は、単に特殊値を整数に割り当てられないからです。
12018
120197205=back
120207206
120217207=begin original
120227208
120237209Examples:
120247210
120257211=end original
120267212
120277213例:
120287214
12029 $foo = pack("WWWW",65,66,67,68);
7215 $foo = pack("CCCC",65,66,67,68);
120307216 # foo eq "ABCD"
12031 $foo = pack("W4",65,66,67,68);
7217 $foo = pack("C4",65,66,67,68);
120327218 # same thing
12033 $foo = pack("W4",0x24b6,0x24b7,0x24b8,0x24b9);
12034 # same thing with Unicode circled letters.
120357219 $foo = pack("U4",0x24b6,0x24b7,0x24b8,0x24b9);
12036 # same thing with Unicode circled letters. You don't get the
7220 # same thing with Unicode circled letters
12037 # UTF-8 bytes because the U at the start of the format caused
12038 # a switch to U0-mode, so the UTF-8 bytes get joined into
12039 # characters
12040 $foo = pack("C0U4",0x24b6,0x24b7,0x24b8,0x24b9);
12041 # foo eq "\xe2\x92\xb6\xe2\x92\xb7\xe2\x92\xb8\xe2\x92\xb9"
12042 # This is the UTF-8 encoding of the string in the
12043 # previous example
120447221
120457222 $foo = pack("ccxxcc",65,66,67,68);
120467223 # foo eq "AB\0\0CD"
120477224
12048 # NOTE: The examples above featuring "W" and "c" are true
7225 # note: the above examples featuring "C" and "c" are true
120497226 # only on ASCII and ASCII-derived systems such as ISO Latin 1
12050 # and UTF-8. On EBCDIC systems, the first example would be
7227 # and UTF-8. In EBCDIC the first example would be
12051 # $foo = pack("WWWW",193,194,195,196);
7228 # $foo = pack("CCCC",193,194,195,196);
120527229
120537230 $foo = pack("s2",1,2);
12054 # "\001\000\002\000" on little-endian
7231 # "\1\0\2\0" on little-endian
12055 # "\000\001\000\002" on big-endian
7232 # "\0\1\0\2" on big-endian
120567233
120577234 $foo = pack("a4","abcd","x","y","z");
120587235 # "abcd"
120597236
120607237 $foo = pack("aaaa","abcd","x","y","z");
120617238 # "axyz"
120627239
120637240 $foo = pack("a14","abcdefg");
120647241 # "abcdefg\0\0\0\0\0\0\0"
120657242
120667243 $foo = pack("i9pl", gmtime);
120677244 # a real struct tm (on my system anyway)
120687245
120697246 $utmp_template = "Z8 Z8 Z16 L";
120707247 $utmp = pack($utmp_template, @utmp1);
120717248 # a struct utmp (BSDish)
120727249
120737250 @utmp2 = unpack($utmp_template, $utmp);
120747251 # "@utmp1" eq "@utmp2"
120757252
120767253 sub bintodec {
12077 unpack("N", pack("B32", substr("0" x 32 . shift, -32)));
7254 unpack("N", pack("B32", substr("0" x 32 . shift, -32)));
120787255 }
120797256
120807257 $foo = pack('sx2l', 12, 34);
120817258 # short 12, two zero bytes padding, long 34
120827259 $bar = pack('s@4l', 12, 34);
120837260 # short 12, zero fill to position 4, long 34
120847261 # $foo eq $bar
12085 $baz = pack('s.l', 12, 4, 34);
12086 # short 12, zero fill to position 4, long 34
120877262
12088 $foo = pack('nN', 42, 4711);
12089 # pack big-endian 16- and 32-bit unsigned integers
12090 $foo = pack('S>L>', 42, 4711);
12091 # exactly the same
12092 $foo = pack('s<l<', -42, 4711);
12093 # pack little-endian 16- and 32-bit signed integers
12094 $foo = pack('(sl)<', -42, 4711);
12095 # exactly the same
12096
120977263=begin original
120987264
12099The same template may generally also be used in
7265The same template may generally also be used in unpack().
12100L<C<unpack>|/unpack TEMPLATE,EXPR>.
121017266
121027267=end original
121037268
12104一般には、同じテンプレートが L<C<unpack>|/unpack TEMPLATE,EXPR> でも
7269一般には、pack で使用したものと同じテンプレートが
12105使用できます。
7270unpack 関数でも使用できます。
121067271
121077272=item package NAMESPACE
121087273
12109=item package NAMESPACE VERSION
7274=item package
12110X<package> X<module> X<namespace> X<version>
121117275
12112=item package NAMESPACE BLOCK
12113
12114=item package NAMESPACE VERSION BLOCK
12115X<package> X<module> X<namespace> X<version>
12116
12117=for Pod::Functions declare a separate global namespace
12118
121197276=begin original
121207277
12121Declares the BLOCK or the rest of the compilation unit as being in the
7278Declares the compilation unit as being in the given namespace. The scope
12122given namespace. The scope of the package declaration is either the
7279of the package declaration is from the declaration itself through the end
12123supplied code BLOCK or, in the absence of a BLOCK, from the declaration
7280of the enclosing block, file, or eval (the same as the C<my> operator).
12124itself through the end of current scope (the enclosing block, file, or
7281All further unqualified dynamic identifiers will be in this namespace.
12125L<C<eval>|/eval EXPR>). That is, the forms without a BLOCK are
7282A package statement affects only dynamic variables--including those
12126operative through the end of the current scope, just like the
7283you've used C<local> on--but I<not> lexical variables, which are created
12127L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>, and
7284with C<my>. Typically it would be the first declaration in a file to
12128L<C<our>|/our VARLIST> operators. All unqualified dynamic identifiers
7285be included by the C<require> or C<use> operator. You can switch into a
12129in this scope will be in the given namespace, except where overridden by
7286package in more than one place; it merely influences which symbol table
12130another L<C<package>|/package NAMESPACE> declaration or
7287is used by the compiler for the rest of that block. You can refer to
12131when they're one of the special identifiers that qualify into C<main::>,
7288variables and filehandles in other packages by prefixing the identifier
12132like C<STDOUT>, C<ARGV>, C<ENV>, and the punctuation variables.
7289with the package name and a double colon: C<$Package::Variable>.
7290If the package name is null, the C<main> package as assumed. That is,
7291C<$::sail> is equivalent to C<$main::sail> (as well as to C<$main'sail>,
7292still seen in older code).
121337293
121347294=end original
121357295
12136BLOCK や残りのコンパイル単位を与えられた名前空間として宣言します。
7296与えられた名前空間でのコンパイル単位を宣言します。
12137パッケージ宣言のスコープは BLOCK かBLOCK がないばあいは宣言自から
7297パッケージ宣言のスコープは、宣言自から、閉じたブロック、ファイル、
12138現在のスコープの末尾 (閉じたブロック、ファイル、L<C<eval>|/eval EXPR>) です。
7298eval の終わりまでです(C<my> 演算子と同じです)
12139つまり、BLOCK なし形式、L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>,
7299全てさらなる修飾されてない動的識別子この名前空間になります。
12140L<C<our>|/our VARLIST> 演算子と同様現在スコープの末尾にまで作用します
7300package 文は動的変数にのみ影響します -- C<local> で使ったものも
12141このスコープ内の全ての完全修飾されていない動的識別子、他の
7301含みます -- がC<my> で作成されたレキシカル変数に I<影響しません>。
12142L<C<package>|/package NAMESPACE> 宣言によって上書きされるか、
7302典型的にはこれは C<require> C<use> 演算子でインクルードされるファイルの
12143C<STDOUT>, C<ARGV>, C<ENV> や句読点変数のように C<main::> に
12144割り当てられる特殊変数でない限り、指定された
12145名前空間になります。
12146
12147=begin original
12148
12149A package statement affects dynamic variables only, including those
12150you've used L<C<local>|/local EXPR> on, but I<not> lexically-scoped
12151variables, which are created with L<C<my>|/my VARLIST>,
12152L<C<state>|/state VARLIST>, or L<C<our>|/our VARLIST>. Typically it
12153would be the first declaration in a file included by
12154L<C<require>|/require VERSION> or L<C<use>|/use Module VERSION LIST>.
12155You can switch into a
12156package in more than one place, since this only determines which default
12157symbol table the compiler uses for the rest of that block. You can refer to
12158identifiers in other packages than the current one by prefixing the identifier
12159with the package name and a double colon, as in C<$SomePack::var>
12160or C<ThatPack::INPUT_HANDLE>. If package name is omitted, the C<main>
12161package as assumed. That is, C<$::sail> is equivalent to
12162C<$main::sail> (as well as to C<$main'sail>, still seen in ancient
12163code, mostly from Perl 4).
12164
12165=end original
12166
12167package 文は動的変数にのみ影響します(L<C<local>|/local EXPR> で使ったものも
12168含みます)が、L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>,
12169L<C<our>|/our VARLIST> のいずれかで作成された
12170レキシカルなスコープの変数には I<影響しません>。
12171典型的にはこれは L<C<require>|/require VERSION> や
12172L<C<use>|/use Module VERSION LIST> 演算子でインクルードされるファイルの
121737303最初に宣言されます。
121747304パッケージを複数の場所で切り替えることができます;
12175なぜならこれは単にコンパイラがこのブロックの残りに対してどの
7305これは単にコンパイラがこのブロックの残りに対してどのシンボルテーブルを
12176シンボルテーブルを使うかにのみ影響するからです。
7306使うかにのみ影響します。
12177他のパッケージの識別子は、C<$SomePack::var> や
7307他のパッケージの変数やファイルハンドルは、識別子にパッケージ名と
12178C<ThatPack::INPUT_HANDLE> のように、識別子にパッケージ名と
7308コロン 2 つをつけることで参照できます(C<$Package::Variable>)。
12179コロン二つをつけることで参照できます。
7309パッケージ名が空文字列の場合、C<main> パッケージが仮定されます。
12180パッケージ名が省略された場合、C<main> パッケージが仮定されま
7310つまり、C<$::sail> は C<$main::sail> と等価で(C<$main'sail> も
12181つまり、C<$::sail> は C<$main::sail> と等価す(ほとんど Perl 4 かの、
7311古いコードではまだ見れます)。
12182古いコードでは C<$main'sail> もまだ見られます)。
121837312
121847313=begin original
121857314
12186If VERSION is provided, L<C<package>|/package NAMESPACE> sets the
7315If NAMESPACE is omitted, then there is no current package, and all
12187C<$VERSION> variable in the given
7316identifiers must be fully qualified or lexicals. This is stricter
12188namespace to a L<version> object with the VERSION provided. VERSION must be a
7317than C<use strict>, since it also extends to function names.
12189"strict" style version number as defined by the L<version> module: a positive
12190decimal number (integer or decimal-fraction) without exponentiation or else a
12191dotted-decimal v-string with a leading 'v' character and at least three
12192components. You should set C<$VERSION> only once per package.
121937318
121947319=end original
121957320
12196VERSION が指定されると、L<C<package>|/package NAMESPACE> は与えら
7321NAMESPACE が省略さると、カレントパッケージはなくなるので、
12197名前空間 C<$VERSION> 変数に、
7322全て識別子は完全修飾されるかレキシカルでなければなりません。
12198指定された VERSION L<version> オブジェクトをセットす。
7323これは関数名にも適用されで、C<use strict> より厳いです。
12199VERSION は L<version> で定義されている「厳密な」形式のバージョン番号で
12200なければなりません: 指数のない正の 10 進数 (整数か 10 進小数) か、
12201さもなければ先頭に 'v' の文字が付いて、少なくとも三つの部分から
12202構成されるドット付き 10 進v-文字列です。
12203C<$VERSION> はパッケージ毎に 1 回だけセットするべきです。
122047324
122057325=begin original
122067326
122077327See L<perlmod/"Packages"> for more information about packages, modules,
122087328and classes. See L<perlsub> for other scoping issues.
122097329
122107330=end original
122117331
122127332パッケージ、モジュール、クラスに関するさらなる情報については
122137333L<perlmod/"Packages"> を参照してください。
122147334その他のスコープに関する話題については L<perlsub> を参照してください。
122157335
12216=item __PACKAGE__
12217X<__PACKAGE__>
12218
12219=for Pod::Functions +5.004 the current package
12220
12221=begin original
12222
12223A special token that returns the name of the package in which it occurs.
12224
12225=end original
12226
12227これが書いてあるパッケージの名前を返す特殊トークン。
12228
122297336=item pipe READHANDLE,WRITEHANDLE
12230X<pipe>
122317337
12232=for Pod::Functions open a pair of connected filehandles
12233
122347338=begin original
122357339
122367340Opens a pair of connected pipes like the corresponding system call.
122377341Note that if you set up a loop of piped processes, deadlock can occur
122387342unless you are very careful. In addition, note that Perl's pipes use
12239IO buffering, so you may need to set L<C<$E<verbar>>|perlvar/$E<verbar>>
7343stdio buffering, so you may need to set C<$|> to flush your WRITEHANDLE
12240to flush your WRITEHANDLE after each command, depending on the
7344after each command, depending on the application.
12241application.
122427345
122437346=end original
122447347
12245対応するシステムコールと同じように、接続されたパイプのペアを開きます。
7348対応するシステムコールと同じように、
7349接続されたパイプのペアをオープンします。
122467350パイプでプロセスをループにするときには、よほど気を付けないと、
122477351デッドロックが起こり得ます。
12248さらに、Perl のパイプでは、IO のバッファリングを使ので
7352さらに、Perl のパイプでは、stdio のバッファリングを使いますから
122497353アプリケーションによっては、コマンドごとに WRITEHANDLE を
12250フラッシュするように、L<C<$E<verbar>>|perlvar/$E<verbar>> を設定することが
7354フラッシュするように、C<$|> を設定することが必要になるかもしれません。
12251必要になるかもしれません。
122527355
122537356=begin original
122547357
12255Returns true on success.
7358See L<IPC::Open2>, L<IPC::Open3>, and L<perlipc/"Bidirectional Communication">
12256
12257=end original
12258
12259成功時には真を返します。
12260
12261=begin original
12262
12263See L<IPC::Open2>, L<IPC::Open3>, and
12264L<perlipc/"Bidirectional Communication with Another Process">
122657359for examples of such things.
122667360
122677361=end original
122687362
122697363これらに関する例については、L<IPC::Open2>, L<IPC::Open3>,
12270L<perlipc/"Bidirectional Communication with Another Process"> を
7364L<perlipc/"Bidirectional Communication"> を参照して下さい。
12271参照してください。
122727365
122737366=begin original
122747367
12275On systems that support a close-on-exec flag on files, that flag is set
7368On systems that support a close-on-exec flag on files, the flag will be set
12276on all newly opened file descriptors whose
7369for the newly opened file descriptors as determined by the value of $^F.
12277L<C<fileno>|/fileno FILEHANDLE>s are I<higher> than the current value of
7370See L<perlvar/$^F>.
12278L<C<$^F>|perlvar/$^F> (by default 2 for C<STDERR>). See L<perlvar/$^F>.
122797371
122807372=end original
122817373
122827374ファイルに対する close-on-exec フラグをサポートしているシステムでは、
12283新しくオープンされたファイル記述子のうち、
7375フラグは $^F の値で決定される、新しくオープンされたファイル記述子に対して
12284L<C<fileno>|/fileno FILEHANDLE> が現在の L<C<$^F>|perlvar/$^F> の値
7376セットされます。
12285(デフォルトでは C<STDERR> の 2)
12286I<よりも大きい> ものに対してフラグがセットされます。
122877377L<perlvar/$^F> を参照してください。
122887378
122897379=item pop ARRAY
12290X<pop> X<stack>
122917380
122927381=item pop
122937382
12294=for Pod::Functions remove the last element from an array and return it
12295
122967383=begin original
122977384
122987385Pops and returns the last value of the array, shortening the array by
12299one element.
7386one element. Has an effect similar to
123007387
123017388=end original
123027389
123037390配列の最後の値をポップして返し、配列の大きさを 1 だけ小さくします。
7391これは、以下と同じ効果があります。
123047392
12305=begin original
7393 $ARRAY[$#ARRAY--]
123067394
12307Returns the undefined value if the array is empty, although this may
12308also happen at other times. If ARRAY is omitted, pops the
12309L<C<@ARGV>|perlvar/@ARGV> array in the main program, but the
12310L<C<@_>|perlvar/@_> array in subroutines, just like
12311L<C<shift>|/shift ARRAY>.
12312
12313=end original
12314
12315指定された配列に要素がなければ未定義値が返されますが、
12316しかしこれは他の場合にも起こり得ます。
12317ARRAY が省略されると、L<C<shift>|/shift ARRAY> と同様に、メインプログラムでは
12318L<C<@ARGV>|perlvar/@ARGV> が使われますが、
12319サブルーチンでは L<C<@_>|perlvar/@_> が使われます。
12320
123217395=begin original
123227396
12323Starting with Perl 5.14, an experimental feature allowed
7397If there are no elements in the array, returns the undefined value
12324L<C<pop>|/pop ARRAY> to take a
7398(although this may happen at other times as well). If ARRAY is
12325scalar expression. This experiment has been deemed unsuccessful, and was
7399omitted, pops the C<@ARGV> array in the main program, and the C<@_>
12326removed as of Perl 5.24.
7400array in subroutines, just like C<shift>.
123277401
123287402=end original
123297403
12330Perl 5.14 からL<C<pop>|/pop ARRAY> スカラ式を取ることが出来るという
7404指定された配列に要素がなければ未定義値返されます
12331実験的機能がありました
7405(しかしこれは他の場合にも起こす)
12332この実験は失敗と見なされ、Perl 5.24 削除されました。
7406ARRAY が省略されるとC<shift> と同様に、メインプログラムは C<@ARGV>が、
7407サブルーチンでは C<@_> が使われます。
123337408
123347409=item pos SCALAR
12335X<pos> X<match, position>
123367410
123377411=item pos
123387412
12339=for Pod::Functions find or set the offset for the last/next m//g search
12340
123417413=begin original
123427414
12343Returns the offset of where the last C<m//g> search left off for the
7415Returns the offset of where the last C<m//g> search left off for the variable
12344variable in question (L<C<$_>|perlvar/$_> is used when the variable is not
7416in question (C<$_> is used when the variable is not specified). May be
12345specified). This offset is in characters unless the
7417modified to change that offset. Such modification will also influence
12346(no-longer-recommended) L<C<use bytes>|bytes> pragma is in effect, in
7418the C<\G> zero-width assertion in regular expressions. See L<perlre> and
12347which case the offset is in bytes. Note that 0 is a valid match offset.
7419L<perlop>.
12348L<C<undef>|/undef EXPR> indicates
12349that the search position is reset (usually due to match failure, but
12350can also be because no match has yet been run on the scalar).
123517420
123527421=end original
123537422
123547423対象の変数に対して、前回の C<m//g> が終了した場所の
12355オフセットを返します(変数が指定されなかった場合は L<C<$_>|perlvar/$_>
7424オフセットを返します(変数が指定されなかった場合は C<$_> が使われます)。
12356使われます)
7425そのオフセットを変えるために、変更することができます。
12357オフセットは、(もはや勧められい) L<C<use bytes>|bytes> プラグマが有効の
7426そのよう変更は正規表現における C<\G> ゼロ幅アサートにも
12358場合(この場合はバイト単位です)除いて、文字単位です。
7427影響与えます。
123590 は有効なマッチオフセットであることに注意してください。
12360L<C<undef>|/undef EXPR> は検索位置がリセットされることを意味します (通常は
12361マッチ失敗が原因ですが、このスカラ値にまだマッチングが
12362行われていないためかもしれません)。
12363
12364=begin original
12365
12366L<C<pos>|/pos SCALAR> directly accesses the location used by the regexp
12367engine to store the offset, so assigning to L<C<pos>|/pos SCALAR> will
12368change that offset, and so will also influence the C<\G> zero-width
12369assertion in regular expressions. Both of these effects take place for
12370the next match, so you can't affect the position with
12371L<C<pos>|/pos SCALAR> during the current match, such as in
12372C<(?{pos() = 5})> or C<s//pos() = 5/e>.
12373
12374=end original
12375
12376L<C<pos>|/pos SCALAR> は正規表現エンジンがオフセットを保存するために使う場所を
12377直接アクセスするので、L<C<pos>|/pos SCALAR> への代入はオフセットを変更し、
12378そのような変更は正規表現における C<\G> ゼロ幅アサートにも影響を与えます。
12379これらの効果の両方は次のマッチングのために行われるので、
12380C<(?{pos() = 5})> や C<s//pos() = 5/e> のように現在のマッチング中の
12381L<C<pos>|/pos SCALAR> の位置には影響を与えません。
12382
12383=begin original
12384
12385Setting L<C<pos>|/pos SCALAR> also resets the I<matched with
12386zero-length> flag, described
12387under L<perlre/"Repeated Patterns Matching a Zero-length Substring">.
12388
12389=end original
12390
12391L<C<pos>|/pos SCALAR> を設定すると、
12392L<perlre/"Repeated Patterns Matching a Zero-length Substring"> に
12393記述されている、I<長さ 0 でマッチング> フラグもリセットされます。
12394
12395=begin original
12396
12397Because a failed C<m//gc> match doesn't reset the offset, the return
12398from L<C<pos>|/pos SCALAR> won't change either in this case. See
12399L<perlre> and L<perlop>.
12400
12401=end original
12402
12403C<m//gc> マッチに失敗してもオフセットはリセットしないので、
12404L<C<pos>|/pos SCALAR> からの返り値はどちらの場合も変更されません。
124057428L<perlre> と L<perlop> を参照してください。
124067429
124077430=item print FILEHANDLE LIST
12408X<print>
124097431
12410=item print FILEHANDLE
12411
124127432=item print LIST
124137433
124147434=item print
124157435
12416=for Pod::Functions output a list to a filehandle
12417
124187436=begin original
124197437
124207438Prints a string or a list of strings. Returns true if successful.
12421FILEHANDLE may be a scalar variable containing the name of or a reference
7439FILEHANDLE may be a scalar variable name, in which case the variable
12422to the filehandle, thus introducing one level of indirection. (NOTE: If
7440contains the name of or a reference to the filehandle, thus introducing
12423FILEHANDLE is a variable and the next token is a term, it may be
7441one level of indirection. (NOTE: If FILEHANDLE is a variable and
12424misinterpreted as an operator unless you interpose a C<+> or put
7442the next token is a term, it may be misinterpreted as an operator
12425parentheses around the arguments.) If FILEHANDLE is omitted, prints to the
7443unless you interpose a C<+> or put parentheses around the arguments.)
12426last selected (see L<C<select>|/select FILEHANDLE>) output handle. If
7444If FILEHANDLE is omitted, prints by default to standard output (or
12427LIST is omitted, prints L<C<$_>|perlvar/$_> to the currently selected
7445to the last selected output channel--see L</select>). If LIST is
12428output handle. To use FILEHANDLE alone to print the content of
7446also omitted, prints C<$_> to the currently selected output channel.
12429L<C<$_>|perlvar/$_> to it, you must use a bareword filehandle like
7447To set the default output channel to something other than STDOUT
12430C<FH>, not an indirect one like C<$fh>. To set the default output handle
7448use the select operation. The current value of C<$,> (if any) is
12431to something other than STDOUT, use the select operation.
7449printed between each LIST item. The current value of C<$\> (if
7450any) is printed after the entire LIST has been printed. Because
7451print takes a LIST, anything in the LIST is evaluated in list
7452context, and any subroutine that you call will have one or more of
7453its expressions evaluated in list context. Also be careful not to
7454follow the print keyword with a left parenthesis unless you want
7455the corresponding right parenthesis to terminate the arguments to
7456the print--interpose a C<+> or put parentheses around all the
7457arguments.
124327458
124337459=end original
124347460
124357461文字列か文字列のリストを出力します。
12436成功時には真を返します。
7462成功時には真を返します。FILEHANDLE は、
12437FILEHANDLE は、ファイルハンドルまたはそのファレンスが
7463スカラ変数でもよく、その場合にその変数にファイル
12438入っているスカラ変数でもよいで、一段階の間接指定行なえます。
7464ハンドルまたはそリファレンス
7465入っているものとして扱われますから、一段階の間接指定が行なえます。
124397466(注: FILEHANDLE に変数を使い、次のトークンが「項」のときには、
124407467間に C<+> を置くか、引数の前後を括弧で括らなければ、
124417468誤って解釈されることがあります。)
12442FILEHANDLE を省略した場合には、最後に選択された
7469FILEHANDLE を省略した場合には、標準出力 (か、
12443(L<C<select>|/select FILEHANDLE> 参照) 出力チャネルに出力します。
7470最後に選択された出力チャネル --- L</select>参照) に出力します。
12444LIST 省略すると、L<C<$_>|perlvar/$_> 現在選択されている出力ハンドルに
7471LIST 省略すると、C<$_> 現在選択されている出力チャネルに
12445出力されます。
7472出力することになります。
12446L<C<$_>|perlvar/$_> 内容表示するために FILEHANDLE のみを使用する
7473デフォルト出力チャネルSTDOUT 以外したければselect 演算子を
12447C<$fh> のような間接ファイルハンドルではなく、C<FH> のような裸の単語の
12448ファイルハンドルを使わなければなりません。
12449デフォルトの出力チャネルを STDOUT 以外にするには、select 演算子を
124507474使ってください。
7475C<$,> の値が(もしあれば)各 LIST 要素の間に出力されます。
7476print の引数は LIST なので、LISTの中のものは、
7477すべてリストコンテキストで評価されます。
7478サブルーチンの呼び出しがあれば、リストコンテキストでは、
7479複数の値を返すかもしれません。また、すべての
7480引数を括弧で括るのでなければ、print というキーワードの
7481次に開き括弧を書いてはいけません。
7482"print" と引数の間に C<+> を書くか、
7483すべての引数を括弧で括ってください。
124517484
124527485=begin original
124537486
12454The current value of L<C<$,>|perlvar/$,> (if any) is printed between
7487Note that if you're storing FILEHANDLES in an array or other expression,
12455each LIST item. The current value of L<C<$\>|perlvar/$\> (if any) is
7488you will have to use a block returning its value instead:
12456printed after the entire LIST has been printed. Because print takes a
12457LIST, anything in the LIST is evaluated in list context, including any
12458subroutines whose return lists you pass to
12459L<C<print>|/print FILEHANDLE LIST>. Be careful not to follow the print
12460keyword with a left
12461parenthesis unless you want the corresponding right parenthesis to
12462terminate the arguments to the print; put parentheses around all arguments
12463(or interpose a C<+>, but that doesn't look as good).
124647489
124657490=end original
124667491
12467L<C<$,>|perlvar/$,> の値が(もしあれば)各 LIST 要素出力されます。
7492もし FILESHANDLES を配列やそ他の表現保存している場合は、
12468LIST 全体が出力された後、(もしあれば) L<C<$\>|perlvar/$\> 現在の値が
7493代わりにその値を返すブロックを使う必要あります:
12469出力されます。
12470print の引数は LIST なので、LIST の中のものは、すべてリストコンテキストで
12471評価されます; L<C<print>|/print FILEHANDLE LIST> に渡した、リストを返す
12472サブルーチンも含みます。
12473また、すべての引数を括弧で括るのでなければ、print というキーワードの
12474次に開き括弧を書いてはいけません; すべての引数を括弧で括ってください
12475(あるいは "print" と引数の間に C<+> を書きますが、これはあまり
12476よくありません)。
124777494
12478=begin original
12479
12480If you're storing handles in an array or hash, or in general whenever
12481you're using any expression more complex than a bareword handle or a plain,
12482unsubscripted scalar variable to retrieve it, you will have to use a block
12483returning the filehandle value instead, in which case the LIST may not be
12484omitted:
12485
12486=end original
12487
12488もし FILESHANDLE を配列、ハッシュあるいは一般的には裸の単語のハンドルや
12489普通のスカラ変数よりも複雑な表現を使っている場合、代わりにその値を返す
12490ブロックを使う必要があります; この場合 LIST は省略できません:
12491
124927495 print { $files[$i] } "stuff\n";
12493 print { $OK ? *STDOUT : *STDERR } "stuff\n";
7496 print { $OK ? STDOUT : STDERR } "stuff\n";
124947497
12495=begin original
12496
12497Printing to a closed pipe or socket will generate a SIGPIPE signal. See
12498L<perlipc> for more on signal handling.
12499
12500=end original
12501
12502閉じたパイプやソケットに print すると SIGPIPE シグナルが生成されます。
12503さらなるシグナル操作については L<perlipc> を参照してください。
12504
125057498=item printf FILEHANDLE FORMAT, LIST
12506X<printf>
125077499
12508=item printf FILEHANDLE
12509
125107500=item printf FORMAT, LIST
125117501
12512=item printf
12513
12514=for Pod::Functions output a formatted list to a filehandle
12515
125167502=begin original
125177503
12518Equivalent to C<print FILEHANDLE sprintf(FORMAT, LIST)>, except that
7504Equivalent to C<print FILEHANDLE sprintf(FORMAT, LIST)>, except that C<$\>
12519L<C<$\>|perlvar/$\> (the output record separator) is not appended. The
7505(the output record separator) is not appended. The first argument
12520FORMAT and the LIST are actually parsed as a single list. The first
7506of the list will be interpreted as the C<printf> format. If C<use locale> is
12521argument of the list will be interpreted as the
7507in effect, the character used for the decimal point in formatted real numbers
12522L<C<printf>|/printf FILEHANDLE FORMAT, LIST> format. This means that
7508is affected by the LC_NUMERIC locale. See L<perllocale>.
12523C<printf(@_)> will use C<$_[0]> as the format. See
12524L<sprintf|/sprintf FORMAT, LIST> for an explanation of the format
12525argument. If C<use locale> (including C<use locale ':not_characters'>)
12526is in effect and L<C<POSIX::setlocale>|POSIX/C<setlocale>> has been
12527called, the character used for the decimal separator in formatted
12528floating-point numbers is affected by the C<LC_NUMERIC> locale setting.
12529See L<perllocale> and L<POSIX>.
125307509
125317510=end original
125327511
12533L<C<$\>|perlvar/$\>(出力レコードセパレータ)を追加しないことを除けば、
7512C<$\>(出力レコードセパレータ)を追加しないことを除けば、
125347513C<print FILEHANDLE sprintf(FORMAT, LIST)> と等価です。
12535FORMAT と LIST は実際には単一のリストとしてパされます。
7514リストの最初の要素は、C<printf> フォマットと解釈されます。
12536リストの最初の要素は、L<C<printf>|/printf FILEHANDLE FORMAT, LIST>
7515C<use locale>が効力をもっていれば、小数点に使われる文字は
12537フォマットと解釈されます。
7516LC_NUMERIC ロケルの影響を受けます。
12538これは、C<printf(@_)> はフォーマットとして C<$_[0]> を使うとうことです
7517L<perllocale> を参照してください。
12539フォーマット引数の説明については L<sprintf|/sprintf FORMAT, LIST> を
12540参照してください。
12541(C<use locale ':not_characters'> を含む) C<use locale> が有効で、
12542L<C<POSIX::setlocale>|POSIX/C<setlocale>> が呼び出されていれば、
12543小数点に使われる文字は C<LC_NUMERIC> ロケール設定の影響を受けます。
12544L<perllocale> と L<POSIX> を参照してください。
125457518
125467519=begin original
125477520
12548For historical reasons, if you omit the list, L<C<$_>|perlvar/$_> is
7521Don't fall into the trap of using a C<printf> when a simple
12549used as the format;
7522C<print> would do. The C<print> is more efficient and less
12550to use FILEHANDLE without a list, you must use a bareword filehandle like
7523error prone.
12551C<FH>, not an indirect one like C<$fh>. However, this will rarely do what
12552you want; if L<C<$_>|perlvar/$_> contains formatting codes, they will be
12553replaced with the empty string and a warning will be emitted if
12554L<warnings> are enabled. Just use L<C<print>|/print FILEHANDLE LIST> if
12555you want to print the contents of L<C<$_>|perlvar/$_>.
125567524
125577525=end original
125587526
12559歴史的理由により、リスト省略する、フォーマットとし
7527単純 C<print> 使うべきころで C<printf> を使っしまう
12560L<C<$_>|perlvar/$_> が使われます;
12561リストなしで FILEHANDLE を使用するには、C<$fh> のような
12562間接ファイルハンドルではなく、C<FH> のような裸の単語の
12563ファイルハンドルを使わなければなりません。
12564しかし、これがあなたが求めていることをすることはまれです;
12565L<C<$_>|perlvar/$_> がフォーマッティングコードの場合、空文字列に置き換えられ、
12566L<warnings> が有効なら警告が出力されます。
12567L<C<$_>|perlvar/$_> の内容を表示したい場合は、単に
12568L<C<print>|/print FILEHANDLE LIST> を使ってください。
12569
12570=begin original
12571
12572Don't fall into the trap of using a
12573L<C<printf>|/printf FILEHANDLE FORMAT, LIST> when a simple
12574L<C<print>|/print FILEHANDLE LIST> would do. The
12575L<C<print>|/print FILEHANDLE LIST> is more efficient and less error
12576prone.
12577
12578=end original
12579
12580単純な L<C<print>|/print FILEHANDLE LIST> を使うべきところで
12581L<C<printf>|/printf FILEHANDLE FORMAT, LIST> を使ってしまう
125827528罠にかからないようにしてください。
12583L<C<print>|/print FILEHANDLE LIST> はより効率的で、間違いが起こりにくいです。
7529C<print> はより効率的で、間違いが起こりにくいです。
125847530
125857531=item prototype FUNCTION
12586X<prototype>
125877532
12588=item prototype
12589
12590=for Pod::Functions +5.002 get the prototype (if any) of a subroutine
12591
125927533=begin original
125937534
12594Returns the prototype of a function as a string (or
7535Returns the prototype of a function as a string (or C<undef> if the
12595L<C<undef>|/undef EXPR> if the
125967536function has no prototype). FUNCTION is a reference to, or the name of,
12597the function whose prototype you want to retrieve. If FUNCTION is omitted,
7537the function whose prototype you want to retrieve.
12598L<C<$_>|perlvar/$_> is used.
125997538
126007539=end original
126017540
126027541関数のプロトタイプを文字列として返します(関数にプロトタイプがない場合は
12603L<C<undef>|/undef EXPR> を返します)。
7542C<undef> を返します)。
126047543FUNCTION はプロトタイプを得たい関数の名前、またはリファレンスです。
12605FUNCTION が省略された場合、L<C<$_>|perlvar/$_> が使われます。
126067544
126077545=begin original
126087546
126097547If FUNCTION is a string starting with C<CORE::>, the rest is taken as a
12610name for a Perl builtin. If the builtin's arguments
7548name for Perl builtin. If the builtin is not I<overridable> (such as
12611cannot be adequately expressed by a prototype
7549C<qw//>) or its arguments cannot be expressed by a prototype (such as
12612(such as L<C<system>|/system LIST>), L<C<prototype>|/prototype FUNCTION>
7550C<system>) returns C<undef> because the builtin does not really behave
12613returns L<C<undef>|/undef EXPR>, because the builtin
7551like a Perl function. Otherwise, the string describing the equivalent
12614does not really behave like a Perl function. Otherwise, the string
7552prototype is returned.
12615describing the equivalent prototype is returned.
126167553
126177554=end original
126187555
126197556FUNCTION が C<CORE::> で始まっている場合、残りは Perl ビルドインの名前として
126207557扱われます。
12621このビルドインの引数が(L<C<system>|/system LIST> のように)プロトタプとして
7558このビルドインが(C<qw//> のように) I<オーバーラド可能> でない、
12622適切に記述できない場合、L<C<prototype>|/prototype FUNCTION> は
7559またはこの引数が(C<system> のよう)プロトタイプとして記述できない場合、
12623L<C<undef>|/undef EXPR> を返します;
7560C<undef> を返します
126247561なぜならビルドインは実際に Perl 関数のように振舞わないからです。
126257562それ以外では、等価なプロトタイプを表現した文字列が返されます。
126267563
126277564=item push ARRAY,LIST
12628X<push> X<stack>
126297565
12630=for Pod::Functions append one or more elements to an array
12631
126327566=begin original
126337567
12634Treats ARRAY as a stack by appending the values of LIST to the end of
7568Treats ARRAY as a stack, and pushes the values of LIST
12635ARRAY. The length of ARRAY increases by the length of LIST. Has the same
7569onto the end of ARRAY. The length of ARRAY increases by the length of
12636effect as
7570LIST. Has the same effect as
126377571
12638=end original
7572 for $value (LIST) {
7573 $ARRAY[++$#ARRAY] = $value;
12640ARRAY をスタックとして扱い、LIST 内の値を ARRAY の終わりに追加します。
12641ARRAY の大きさは、LIST の長さ分だけ大きくなります。
12642これは、
12643
12644 for my $value (LIST) {
12645 $ARRAY[++$#ARRAY] = $value;
126467574 }
126477575
12648=begin original
7576but is more efficient. Returns the new number of elements in the array.
126497577
12650but is more efficient. Returns the number of elements in the array following
12651the completed L<C<push>|/push ARRAY,LIST>.
12652
126537578=end original
126547579
12655すると同じ効果がありますが、より効率的です。
7580ARRAY をスタックして扱い、LIST 内値を ARRAY の終わにプッシュします。
12656L<C<push>|/push ARRAY,LIST>処理終了後の配列の要素数を返します。
7581ARRAY の大きさは、LIST の長さ分だけ大きくなります。これは、
126577582
12658=begin original
7583 for $value (LIST) {
7584 $ARRAY[++$#ARRAY] = $value;
7585 }
126597586
12660Starting with Perl 5.14, an experimental feature allowed
7587とするのと同じ効果がありますが、より効率的です。
12661L<C<push>|/push ARRAY,LIST> to take a
7588変更後の配列の要素数を返します。
12662scalar expression. This experiment has been deemed unsuccessful, and was
12663removed as of Perl 5.24.
126647589
12665=end original
12666
12667Perl 5.14 から、L<C<push>|/push ARRAY,LIST> がスカラ式を取ることが出来るという
12668実験的機能がありました。
12669この実験は失敗と見なされ、Perl 5.24 で削除されました。
12670
126717590=item q/STRING/
126727591
12673=for Pod::Functions singly quote a string
12674
126757592=item qq/STRING/
126767593
12677=for Pod::Functions doubly quote a string
7594=item qr/STRING/
126787595
12679=item qw/STRING/
12680
12681=for Pod::Functions quote a list of words
12682
126837596=item qx/STRING/
126847597
12685=for Pod::Functions backquote quote a string
7598=item qw/STRING/
126867599
126877600=begin original
126887601
12689Generalized quotes. See L<perlop/"Quote-Like Operators">.
7602Generalized quotes. See L<perlop/"Regexp Quote-Like Operators">.
126907603
126917604=end original
126927605
126937606汎用のクォートです。
12694L<perlop/"Quote-Like Operators"> を参照してください。
7607L<perlop/"Regexp Quote-Like Operators">を参照してください。
126957608
12696=item qr/STRING/
12697
12698=for Pod::Functions +5.005 compile pattern
12699
12700=begin original
12701
12702Regexp-like quote. See L<perlop/"Regexp Quote-Like Operators">.
12703
12704=end original
12705
12706正規表現風のクォートです。
12707L<perlop/"Regexp Quote-Like Operators"> を参照してください。
12708
127097609=item quotemeta EXPR
12710X<quotemeta> X<metacharacter>
127117610
127127611=item quotemeta
127137612
12714=for Pod::Functions quote regular expression magic characters
12715
127167613=begin original
127177614
12718Returns the value of EXPR with all the ASCII non-"word"
7615Returns the value of EXPR with all non-"word"
12719characters backslashed. (That is, all ASCII characters not matching
7616characters backslashed. (That is, all characters not matching
127207617C</[A-Za-z_0-9]/> will be preceded by a backslash in the
127217618returned string, regardless of any locale settings.)
127227619This is the internal function implementing
127237620the C<\Q> escape in double-quoted strings.
12724(See below for the behavior on non-ASCII code points.)
127257621
127267622=end original
127277623
12728EXPR の中のすべての ASCII 非英数字キャラクタをバックスラッシュで
7624EXPR の中のすべての非英数字キャラクタをバックスラッシュで
12729エスケープしたものを返します
7625エスケープしたものを返します
12730(つまり、C</[A-Za-z_0-9]/> にマッチしない全ての ASCII 文字の前には
7626(つまり、C</[A-Za-z_0-9]/> にマッチしない全ての文字の前には
12731ロケールに関わらずバックスラッシュが前置されます)
7627ロケールに関わらずバックスラッシュが前置されます)
12732これは、ダブルクォート文字列での C<\Q> エスケープを実装するための
7628これは、ダブルクォート文字列での C<\Q> エスケープを
12733内部関数です。
7629実装するための内部関数です。
12734(非 ASCII 符号位置での振る舞いについては以下を参照してください。)
127357630
127367631=begin original
127377632
12738If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
7633If EXPR is omitted, uses C<$_>.
127397634
127407635=end original
127417636
12742EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
7637EXPR が省略されると、C<$_> を使います。
127437638
12744=begin original
12745
12746quotemeta (and C<\Q> ... C<\E>) are useful when interpolating strings into
12747regular expressions, because by default an interpolated variable will be
12748considered a mini-regular expression. For example:
12749
12750=end original
12751
12752クォートメタ (と C<\Q> ... C<\E>) は、文字列を正規表現に展開するのに
12753便利です; なぜなら、デフォルトでは展開された変数は小さな正規表現として
12754扱われるからです。
12755例えば:
12756
12757 my $sentence = 'The quick brown fox jumped over the lazy dog';
12758 my $substring = 'quick.*?fox';
12759 $sentence =~ s{$substring}{big bad wolf};
12760
12761=begin original
12762
12763Will cause C<$sentence> to become C<'The big bad wolf jumped over...'>.
12764
12765=end original
12766
12767とすると、C<$sentence> は C<'The big bad wolf jumped over...'> になります。
12768
12769=begin original
12770
12771On the other hand:
12772
12773=end original
12774
12775一方:
12776
12777 my $sentence = 'The quick brown fox jumped over the lazy dog';
12778 my $substring = 'quick.*?fox';
12779 $sentence =~ s{\Q$substring\E}{big bad wolf};
12780
12781=begin original
12782
12783Or:
12784
12785=end original
12786
12787あるいは:
12788
12789 my $sentence = 'The quick brown fox jumped over the lazy dog';
12790 my $substring = 'quick.*?fox';
12791 my $quoted_substring = quotemeta($substring);
12792 $sentence =~ s{$quoted_substring}{big bad wolf};
12793
12794=begin original
12795
12796Will both leave the sentence as is.
12797Normally, when accepting literal string input from the user,
12798L<C<quotemeta>|/quotemeta EXPR> or C<\Q> must be used.
12799
12800=end original
12801
12802とすると、両方ともそのままです。
12803普通は、ユーザーからのリテラルな文字列入力を受け付ける場合は、
12804必ず L<C<quotemeta>|/quotemeta EXPR> か C<\Q> を使わなければなりません。
12805
12806=begin original
12807
12808In Perl v5.14, all non-ASCII characters are quoted in non-UTF-8-encoded
12809strings, but not quoted in UTF-8 strings.
12810
12811=end original
12812
12813Perl v5.14 では、全ての非 ASCII 文字は非 UTF-8 エンコードされた
12814文字列ではクォートされませんが、UTF-8 文字列ではクォートされます。
12815
12816=begin original
12817
12818Starting in Perl v5.16, Perl adopted a Unicode-defined strategy for
12819quoting non-ASCII characters; the quoting of ASCII characters is
12820unchanged.
12821
12822=end original
12823
12824Perl v5.16 から、Perl は非 ASCII 文字をクォートするのに Unicode で
12825定義された戦略を採用しました; ASCII 文字のクォートは変わりません。
12826
12827=begin original
12828
12829Also unchanged is the quoting of non-UTF-8 strings when outside the
12830scope of a
12831L<C<use feature 'unicode_strings'>|feature/The 'unicode_strings' feature>,
12832which is to quote all
12833characters in the upper Latin1 range. This provides complete backwards
12834compatibility for old programs which do not use Unicode. (Note that
12835C<unicode_strings> is automatically enabled within the scope of a
12836S<C<use v5.12>> or greater.)
12837
12838=end original
12839
12840また、
12841L<C<use feature 'unicode_strings'>|feature/The 'unicode_strings' feature> の
12842範囲外で非 UTF-8 文字列をクォートするのも変わりません; 上位の Latin1 の範囲の
12843全ての文字をクォートします。
12844これは Unicode を使わない古いプログラムに対して完全な後方互換性を提供します。
12845(C<unicode_strings> は S<C<use v5.12>> またはそれ以上のスコープでは
12846自動的に有効になることに注意してください。)
12847
12848=begin original
12849
12850Within the scope of L<C<use locale>|locale>, all non-ASCII Latin1 code
12851points
12852are quoted whether the string is encoded as UTF-8 or not. As mentioned
12853above, locale does not affect the quoting of ASCII-range characters.
12854This protects against those locales where characters such as C<"|"> are
12855considered to be word characters.
12856
12857=end original
12858
12859L<C<use locale>|locale> スコープの内側では、全ての非 ASCII Latin1 符号位置は
12860文字列が UTF-8 でエンコードされているかどうかに関わらずクォートされます。
12861上述のように、ロケールは ASCII の範囲の文字のクォートに影響を与えません。
12862これは C<"|"> のような文字が単語文字として考えられるロケールから守ります。
12863
12864=begin original
12865
12866Otherwise, Perl quotes non-ASCII characters using an adaptation from
12867Unicode (see L<http://www.unicode.org/reports/tr31/>).
12868The only code points that are quoted are those that have any of the
12869Unicode properties: Pattern_Syntax, Pattern_White_Space, White_Space,
12870Default_Ignorable_Code_Point, or General_Category=Control.
12871
12872=end original
12873
12874さもなければ、Perl は Unicode からの本版を使って非 ASCII 文字をクォートします
12875(L<http://www.unicode.org/reports/tr31/> 参照)。
12876クォートされる符号位置は以下のどれかの Unicode を特性を持つものだけです:
12877Pattern_Syntax, Pattern_White_Space, White_Space,
12878Default_Ignorable_Code_Point, or General_Category=Control。
12879
12880=begin original
12881
12882Of these properties, the two important ones are Pattern_Syntax and
12883Pattern_White_Space. They have been set up by Unicode for exactly this
12884purpose of deciding which characters in a regular expression pattern
12885should be quoted. No character that can be in an identifier has these
12886properties.
12887
12888=end original
12889
12890これらの特性の中で、重要な二つは Pattern_Syntax と Pattern_White_Space です。
12891これらはまさに正規表現中パターン中のどの文字をクォートするべきかを
12892決定するという目的のために Unicode によって設定されています。
12893識別子になる文字はこれらの特性はありません。
12894
12895=begin original
12896
12897Perl promises, that if we ever add regular expression pattern
12898metacharacters to the dozen already defined
12899(C<\ E<verbar> ( ) [ { ^ $ * + ? .>), that we will only use ones that have the
12900Pattern_Syntax property. Perl also promises, that if we ever add
12901characters that are considered to be white space in regular expressions
12902(currently mostly affected by C</x>), they will all have the
12903Pattern_White_Space property.
12904
12905=end original
12906
12907Perl は、正規表現メタ文字として既に定義されている
12908(C<\ E<verbar> ( ) [ { ^ $ * + ? .>) ものに追加するときは、
12909Pattern_Syntax 特性を持つものだけを使うことを約束します。
12910Perl はまた、(現在の所ほとんどは C</x> よって影響される)正規表現中で空白と
12911考えられる文字に追加するときは、Pattern_White_Space 特性を
12912持つものであることを約束します。
12913
12914=begin original
12915
12916Unicode promises that the set of code points that have these two
12917properties will never change, so something that is not quoted in v5.16
12918will never need to be quoted in any future Perl release. (Not all the
12919code points that match Pattern_Syntax have actually had characters
12920assigned to them; so there is room to grow, but they are quoted
12921whether assigned or not. Perl, of course, would never use an
12922unassigned code point as an actual metacharacter.)
12923
12924=end original
12925
12926Unicode はこれら二つの特性を持つ符号位置の集合が決して変わらないことを
12927約束しているので、v5.16 でクォートされないものは将来の Perl リリースでも
12928クォートする必要はありません。
12929(Pattern_Syntax にマッチングする全ての符号位置が実際に割り当てられている
12930文字を持っているわけではありません; したがって拡張する余地がありますが、
12931割り当てられているかどうかに関わらずクォートされます。
12932Perl はもちろん割り当てられていない符号位置を実際のメタ文字として使うことは
12933ありません。)
12934
12935=begin original
12936
12937Quoting characters that have the other 3 properties is done to enhance
12938the readability of the regular expression and not because they actually
12939need to be quoted for regular expression purposes (characters with the
12940White_Space property are likely to be indistinguishable on the page or
12941screen from those with the Pattern_White_Space property; and the other
12942two properties contain non-printing characters).
12943
12944=end original
12945
12946その他の 3 特性を持つ文字のクォートは正規表現の可読性を向上させるために
12947行われ、実際には正規表現の目的でクォートする必要があるからではありません
12948(White_Space 特性を持つ文字は表示上は Pattern_White_Space 特性を持つ文字と
12949おそらく区別が付かないでしょう; そして残りの
12950二つの特性は非表示文字を含んでいます).
12951
129527639=item rand EXPR
12953X<rand> X<random>
129547640
129557641=item rand
129567642
12957=for Pod::Functions retrieve the next pseudorandom number
12958
129597643=begin original
129607644
129617645Returns a random fractional number greater than or equal to C<0> and less
129627646than the value of EXPR. (EXPR should be positive.) If EXPR is
12963omitted, the value C<1> is used. Currently EXPR with the value C<0> is
7647omitted, the value C<1> is used. Automatically calls C<srand> unless
12964also special-cased as C<1> (this was undocumented before Perl 5.8.0
7648C<srand> has already been called. See also C<srand>.
12965and is subject to change in future versions of Perl). Automatically calls
12966L<C<srand>|/srand EXPR> unless L<C<srand>|/srand EXPR> has already been
12967called. See also L<C<srand>|/srand EXPR>.
129687649
129697650=end original
129707651
129717652C<0> 以上 EXPR の値未満の小数の乱数値を返します。
12972(EXPR は正の数である必要があります。)
7653(EXPRは正の数である必要があります。)
12973EXPR 省略されると、C<1> が使われます。
7654EXPR 省略ると、C<1> とみなします。
12974現在のところ、EXPR に値 C<0> をセットす C<1> として特別扱いされます
7655C<srand> が既に呼ばれてい場合以外は、自動的に C<srand> 関数を
12975(これは Perl 5.8.0 以前には文書化されておらず、将来のバージョンの perl では
7656呼び出します。
12976変更れる可能性があります)
7657C<srand> も参照してくだ
12977L<C<srand>|/srand EXPR> が既に呼ばれている場合以外は、自動的に
12978L<C<srand>|/srand EXPR> 関数を呼び出します。
12979L<C<srand>|/srand EXPR> も参照してください。
129807658
129817659=begin original
129827660
12983Apply L<C<int>|/int EXPR> to the value returned by L<C<rand>|/rand EXPR>
12984if you want random integers instead of random fractional numbers. For
12985example,
12986
12987=end original
12988
12989ランダムな小数ではなく、ランダムな整数がほしい場合は、
12990L<C<rand>|/rand EXPR> から返された値に L<C<int>|/int EXPR> を
12991適用してください。
12992例えば:
12993
12994 int(rand(10))
12995
12996=begin original
12997
12998returns a random integer between C<0> and C<9>, inclusive.
12999
13000=end original
13001
13002これは C<0> から C<9> の値をランダムに返します。
13003
13004=begin original
13005
130067661(Note: If your rand function consistently returns numbers that are too
130077662large or too small, then your version of Perl was probably compiled
130087663with the wrong number of RANDBITS.)
130097664
130107665=end original
130117666
130127667(注: もし、rand 関数が、常に大きい値ばかりや、小さい数ばかりを
130137668返すようなら、お使いになっている Perl が、
130147669良くない RANDBITS を使ってコンパイルされている可能性があります。)
130157670
13016=begin original
13017
13018B<L<C<rand>|/rand EXPR> is not cryptographically secure. You should not rely
13019on it in security-sensitive situations.> As of this writing, a
13020number of third-party CPAN modules offer random number generators
13021intended by their authors to be cryptographically secure,
13022including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
13023and L<Math::TrulyRandom>.
13024
13025=end original
13026
13027B<L<C<rand>|/rand EXPR> は暗号学的に安全ではありません。
13028セキュリティ的に重要な状況でこれに頼るべきではありません。>
13029これを書いている時点で、いくつかのサードパーティ CPAN モジュールが
13030作者によって暗号学的に安全であることを目的とした乱数生成器を
13031提供しています: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
13032L<Math::TrulyRandom> などです。
13033
130347671=item read FILEHANDLE,SCALAR,LENGTH,OFFSET
13035X<read> X<file, read>
130367672
130377673=item read FILEHANDLE,SCALAR,LENGTH
130387674
13039=for Pod::Functions fixed-length buffered input from a filehandle
13040
130417675=begin original
130427676
13043Attempts to read LENGTH I<characters> of data into variable SCALAR
7677Attempts to read LENGTH bytes of data into variable SCALAR from the
13044from the specified FILEHANDLE. Returns the number of characters
7678specified FILEHANDLE. Returns the number of bytes actually read, C<0>
13045actually read, C<0> at end of file, or undef if there was an error (in
7679at end of file, or undef if there was an error. SCALAR will be grown
13046the latter case L<C<$!>|perlvar/$!> is also set). SCALAR will be grown
7680or shrunk to the length actually read. If SCALAR needs growing, the
13047or shrunk
7681new bytes will be zero bytes. An OFFSET may be specified to place
13048so that the last character actually read is the last character of the
7682the read data into some other place in SCALAR than the beginning.
13049scalar after the read.
7683The call is actually implemented in terms of stdio's fread(3) call.
7684To get a true read(2) system call, see C<sysread>.
130507685
130517686=end original
130527687
13053指定した FILEHANDLE から、変数 SCALAR に LENGTH I<文字> データを
7688指定した FILEHANDLE から、変数 SCALAR に LENGTH バイト
13054読み込みます。
7689データを読み込みます。
13055実際に読み込まれた文字数、ファイル終端の場合は C<0>、エラーの場合は undef の
7690実際に読み込まれたバイト数、
13056いずれかを返します (後者の場合、L<C<$!>|perlvar/$!> もセットされます)
7691ファイル終端の場合C<0>、エラーの場合は undef のいずかを返します。
13057SCALAR は伸び縮みするので読み込み後は、実際に読み込んだ最後の文字がスカラの
7692SCALAR は、実際に読み込んだ長さに応じて、伸び縮みします。
13058最後の文字になります。
7693SCALAR が伸びた場合、伸びた部分はバイト 0 になります。
7694OFFSET を指定すると、SCALAR の先頭以外の場所から、
7695読み込みを行なうことができます。
7696この関数は、stdio ライブラリの fread(3) 関数を使って実装しています。
7697本当の read(2) システムコールを利用するには、C<sysread> を参照してください。
130597698
13060=begin original
13061
13062An OFFSET may be specified to place the read data at some place in the
13063string other than the beginning. A negative OFFSET specifies
13064placement at that many characters counting backwards from the end of
13065the string. A positive OFFSET greater than the length of SCALAR
13066results in the string being padded to the required size with C<"\0">
13067bytes before the result of the read is appended.
13068
13069=end original
13070
13071OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行なえます。
13072OFFSET に負の値を指定すると、文字列の最後から逆向きに何文字目かで
13073位置を指定します。
13074OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は読み込みの結果が
13075追加される前に、必要なサイズまで C<"\0"> のバイトでパッディングされます。
13076
13077=begin original
13078
13079The call is implemented in terms of either Perl's or your system's native
13080L<fread(3)> library function. To get a true L<read(2)> system call, see
13081L<sysread|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>.
13082
13083=end original
13084
13085この関数は、Perl か システムの L<fread(3)> ライブラリ関数を使って
13086実装しています。
13087本当の L<read(2)> システムコールを利用するには、
13088L<sysread|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を参照してください。
13089
13090=begin original
13091
13092Note the I<characters>: depending on the status of the filehandle,
13093either (8-bit) bytes or characters are read. By default, all
13094filehandles operate on bytes, but for example if the filehandle has
13095been opened with the C<:utf8> I/O layer (see
13096L<C<open>|/open FILEHANDLE,EXPR>, and the L<open>
13097pragma), the I/O will operate on UTF8-encoded Unicode
13098characters, not bytes. Similarly for the C<:encoding> layer:
13099in that case pretty much any characters can be read.
13100
13101=end original
13102
13103I<文字> に関する注意: ファイルハンドルの状態によって、(8 ビットの) バイトか
13104文字が読み込まれます。
13105デフォルトでは全てのファイルハンドルはバイトを処理しますが、
13106例えばファイルハンドルが C<:utf8> I/O 層(L<C<open>|/open FILEHANDLE,EXPR>,
13107L<open> プラグマを参照してください) で開かれた場合、I/O はバイトではなく、
13108UTF8 エンコードされた Unicode 文字を操作します。
13109C<:encoding> 層も同様です:
13110この場合、ほとんど大体全ての文字が読み込めます。
13111
131127699=item readdir DIRHANDLE
13113X<readdir>
131147700
13115=for Pod::Functions get a directory from a directory handle
13116
131177701=begin original
131187702
13119Returns the next directory entry for a directory opened by
7703Returns the next directory entry for a directory opened by C<opendir>.
13120L<C<opendir>|/opendir DIRHANDLE,EXPR>.
131217704If used in list context, returns all the rest of the entries in the
13122directory. If there are no more entries, returns the undefined value in
7705directory. If there are no more entries, returns an undefined value in
13123scalar context and the empty list in list context.
7706scalar context or a null list in list context.
131247707
131257708=end original
131267709
13127L<C<opendir>|/opendir DIRHANDLE,EXPR> でオープンしたディレクトリで、次の
7710C<opendir> でオープンしたディレクトリで、
13128ディレクトリエントリを返します。
7711次のディレクトリエントリを返します。
13129リストコンテキストで用いると、そのディレクトリの残りのエントリを、すべて
7712リストコンテキストで用いると、
13130返します。
7713そのディレクトリの残りのエントリを、すべて返します。
131317714エントリが残っていない場合には、スカラコンテキストでは未定義値を、
131327715リストコンテキストでは空リストを返します。
131337716
131347717=begin original
131357718
13136If you're planning to filetest the return values out of a
7719If you're planning to filetest the return values out of a C<readdir>, you'd
13137L<C<readdir>|/readdir DIRHANDLE>, you'd better prepend the directory in
7720better prepend the directory in question. Otherwise, because we didn't
13138question. Otherwise, because we didn't L<C<chdir>|/chdir EXPR> there,
7721C<chdir> there, it would have been testing the wrong file.
13139it would have been testing the wrong file.
131407722
131417723=end original
131427724
13143L<C<readdir>|/readdir DIRHANDLE> の返り値をファイルテストに使おうと
7725C<readdir> の返り値をファイルテストに使おうと計画しているなら、
13144計画しているなら、頭にディレクトリをつける必要があります。
7726頭にディレクトリをつける必要があります。
13145さもなければ、ここでは L<C<chdir>|/chdir EXPR> はしないので、
7727さもなければ、ここでは C<chdir> はしないので、
131467728間違ったファイルをテストしてしまうことになるでしょう。
131477729
13148 opendir(my $dh, $some_dir) || die "Can't opendir $some_dir: $!";
7730 opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!";
13149 my @dots = grep { /^\./ && -f "$some_dir/$_" } readdir($dh);
7731 @dots = grep { /^\./ && -f "$some_dir/$_" } readdir(DIR);
13150 closedir $dh;
7732 closedir DIR;
131517733
13152=begin original
13153
13154As of Perl 5.12 you can use a bare L<C<readdir>|/readdir DIRHANDLE> in a
13155C<while> loop, which will set L<C<$_>|perlvar/$_> on every iteration.
13156If either a C<readdir> expression or an explicit assignment of a
13157C<readdir> expression to a scalar is used as a C<while>/C<for> condition,
13158then the condition actually tests for definedness of the expression's
13159value, not for its regular truth value.
13160
13161=end original
13162
13163Perl 5.12 から裸の L<C<readdir>|/readdir DIRHANDLE> を C<while> で
13164使うことができ、この場合繰り返し毎に L<C<$_>|perlvar/$_> にセットされます。
13165C<readdir> 式または C<readdir> 式からスカラへの明示的な代入が
13166C<while>/C<for> の条件部として使われた場合、
13167条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを
13168テストします。
13169
13170 opendir(my $dh, $some_dir) || die "Can't open $some_dir: $!";
13171 while (readdir $dh) {
13172 print "$some_dir/$_\n";
13173 }
13174 closedir $dh;
13175
13176=begin original
13177
13178To avoid confusing would-be users of your code who are running earlier
13179versions of Perl with mysterious failures, put this sort of thing at the
13180top of your file to signal that your code will work I<only> on Perls of a
13181recent vintage:
13182
13183=end original
13184
13185あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
13186失敗で混乱することを避けるために、コードが最近のバージョンの Perl で
13187I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
13188書いてください:
13189
13190 use 5.012; # so readdir assigns to $_ in a lone while test
13191
131927734=item readline EXPR
131937735
13194=item readline
13195X<readline> X<gets> X<fgets>
13196
13197=for Pod::Functions fetch a record from a file
13198
131997736=begin original
132007737
13201Reads from the filehandle whose typeglob is contained in EXPR (or from
7738Reads from the filehandle whose typeglob is contained in EXPR. In scalar
13202C<*ARGV> if EXPR is not provided). In scalar context, each call reads and
7739context, each call reads and returns the next line, until end-of-file is
13203returns the next line until end-of-file is reached, whereupon the
7740reached, whereupon the subsequent call returns undef. In list context,
13204subsequent call returns L<C<undef>|/undef EXPR>. In list context, reads
7741reads until end-of-file is reached and returns a list of lines. Note that
13205until end-of-file is reached and returns a list of lines. Note that the
7742the notion of "line" used here is however you may have defined it
13206notion of "line" used here is whatever you may have defined with
7743with C<$/> or C<$INPUT_RECORD_SEPARATOR>). See L<perlvar/"$/">.
13207L<C<$E<sol>>|perlvar/$E<sol>> (or C<$INPUT_RECORD_SEPARATOR> in
13208L<English>). See L<perlvar/"$/">.
132097744
132107745=end original
132117746
13212型グロブが EXPR (EXPR がない場合は C<*ARGV>) に含まれている
7747typeglob が EXPR に含まれているファイルハンドルから読み込みます。
13213ファイルハドルから読み込ます。
7748スカラコテキストでは、呼び出し毎に一行読み込んで返します。
13214スカラコンテキスト、呼び出し毎に一行読み込んで返します; ファイルの
7749ファイルの最後ま読み込んだら以後の呼び出しでは undef を返します
13215最後まで読み込んだら、以後の呼び出しは L<C<undef>|/undef EXPR> を返します。
7750リストコンテキストでは、ファイルの最後まで読み込んで
13216リストコンテキストでは、ファイルの最後まで読み込んで、行のリストを返します。
7751行のリストを返します。
13217ここでの「行」とは、L<C<$E<sol>>|perlvar/$E<sol>> (または
7752ここでの「行」とは、C<$/> または C<$INPUT_RECORD_SEPARATOR> で
13218L<English> モジュールでは C<$INPUT_RECORD_SEPARATOR>)
7753定義されることに注意してください。L<perlvar/"$/"> も参照して下さい。
13219定義されることに注意してください。
13220L<perlvar/"$/"> を参照してください。
132217754
132227755=begin original
132237756
13224When L<C<$E<sol>>|perlvar/$E<sol>> is set to L<C<undef>|/undef EXPR>,
7757When C<$/> is set to C<undef>, when readline() is in scalar
13225when L<C<readline>|/readline EXPR> is in scalar context (i.e., file
7758context (i.e. file slurp mode), and when an empty file is read, it
13226slurp mode), and when an empty file is read, it returns C<''> the first
7759returns C<''> the first time, followed by C<undef> subsequently.
13227time, followed by L<C<undef>|/undef EXPR> subsequently.
132287760
132297761=end original
132307762
13231L<C<$E<sol>>|perlvar/$E<sol>>L<C<undef>|/undef EXPR> を設定した場合は、
7763C<$/> に C<undef> を設定した場合は、readline() はスカラコンテキスト
13232L<C<readline>|/readline EXPR> はスカラコンテキスト (つまりファイル吸い込み
7764(つまりファイル吸い込みモード)となり、
13233モード)となり、空のファイルを読み込んだ場合は、最初は C<''> を返し、
7765空のファイルを読み込んだ場合は、最初は C<''> を返し、
13234それ以降は L<C<undef>|/undef EXPR> を返します。
7766それ以降は C<undef> を返します。
132357767
132367768=begin original
132377769
132387770This is the internal function implementing the C<< <EXPR> >>
132397771operator, but you can use it directly. The C<< <EXPR> >>
132407772operator is discussed in more detail in L<perlop/"I/O Operators">.
132417773
132427774=end original
132437775
132447776これは C<< <EXPR> >> 演算子を実装している内部関数ですが、
132457777直接使うこともできます。
132467778C<< <EXPR> >> 演算子についてのさらなる詳細については
132477779L<perlop/"I/O Operators"> で議論されています。
132487780
13249 my $line = <STDIN>;
7781 $line = <STDIN>;
13250 my $line = readline(STDIN); # same thing
7782 $line = readline(*STDIN); # same thing
132517783
13252=begin original
13253
13254If L<C<readline>|/readline EXPR> encounters an operating system error,
13255L<C<$!>|perlvar/$!> will be set with the corresponding error message.
13256It can be helpful to check L<C<$!>|perlvar/$!> when you are reading from
13257filehandles you don't trust, such as a tty or a socket. The following
13258example uses the operator form of L<C<readline>|/readline EXPR> and dies
13259if the result is not defined.
13260
13261=end original
13262
13263L<C<readline>|/readline EXPR> が OS のシステムエラーになると、
13264L<C<$!>|perlvar/$!> に対応するエラーメッセージがセットされます。
13265tty やソケットといった、信頼できないファイルハンドルから読み込む時には
13266L<C<$!>|perlvar/$!> をチェックするのが助けになります。
13267以下の例は演算子の形の L<C<readline>|/readline EXPR> を使っており、結果が
13268未定義の場合は die します。
13269
13270 while ( ! eof($fh) ) {
13271 defined( $_ = readline $fh ) or die "readline failed: $!";
13272 ...
13273 }
13274
13275=begin original
13276
13277Note that you have can't handle L<C<readline>|/readline EXPR> errors
13278that way with the C<ARGV> filehandle. In that case, you have to open
13279each element of L<C<@ARGV>|perlvar/@ARGV> yourself since
13280L<C<eof>|/eof FILEHANDLE> handles C<ARGV> differently.
13281
13282=end original
13283
13284L<C<readline>|/readline EXPR> のエラーは C<ARGV> ファイルハンドルの方法では
13285扱えないことに注意してください。
13286この場合、L<C<eof>|/eof FILEHANDLE> は C<ARGV> を異なった方法で扱うので、
13287L<C<@ARGV>|perlvar/@ARGV> のそれぞれの要素を自分でオープンする必要があります。
13288
13289 foreach my $arg (@ARGV) {
13290 open(my $fh, $arg) or warn "Can't open $arg: $!";
13291
13292 while ( ! eof($fh) ) {
13293 defined( $_ = readline $fh )
13294 or die "readline failed for $arg: $!";
13295 ...
13296 }
13297 }
13298
13299=begin original
13300
13301Like the C<< <EXPR> >> operator, if a C<readline> expression is
13302used as the condition of a C<while> or C<for> loop, then it will be
13303implicitly assigned to C<$_>. If either a C<readline> expression or
13304an explicit assignment of a C<readline> expression to a scalar is used
13305as a C<while>/C<for> condition, then the condition actually tests for
13306definedness of the expression's value, not for its regular truth value.
13307
13308=end original
13309
13310C<< <EXPR> >> 演算子と同様、
13311C<readline> 式が C<while> や C<for> ループの条件として使われた場合、
13312これは暗黙に C<$_> に代入されます。
13313C<readline> 式または C<readline> 式からスカラへの明示的な代入が
13314C<while>/C<for> の条件部として使われた場合、
13315条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを
13316テストします。
13317
133187784=item readlink EXPR
13319X<readlink>
133207785
133217786=item readlink
133227787
13323=for Pod::Functions determine where a symbolic link is pointing
13324
133257788=begin original
133267789
133277790Returns the value of a symbolic link, if symbolic links are
13328implemented. If not, raises an exception. If there is a system
7791implemented. If not, gives a fatal error. If there is some system
13329error, returns the undefined value and sets L<C<$!>|perlvar/$!> (errno).
7792error, returns the undefined value and sets C<$!> (errno). If EXPR is
13330If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
7793omitted, uses C<$_>.
133317794
133327795=end original
133337796
13334シンボリックリンクが実装されていれば、シンボリックリンクの値を返します。
7797シンボリックリンクが実装されていれば、
13335実装されていないときには、例外が発生します。
7798シンボリックリンクの値を返します。
13336何らかのシステムエラーが検出されと、未定義値を返し、
7799実装されていないきには致命的エラーとなります。
13337L<C<$!>|perlvar/$!> (errno) を設定します。
7800何らかのシステムエラーが検出されると、
13338EXPR が省略されるとL<C<$_>|perlvar/$_> 使います。
7801未定義値を返し、C<$!> (errno)設定します。
7802EXPR を省略すると、C<$_> を使用します。
133397803
13340=begin original
13341
13342Portability issues: L<perlport/readlink>.
13343
13344=end original
13345
13346移植性の問題: L<perlport/readlink>。
13347
133487804=item readpipe EXPR
133497805
13350=item readpipe
13351X<readpipe>
13352
13353=for Pod::Functions execute a system command and collect standard output
13354
133557806=begin original
133567807
133577808EXPR is executed as a system command.
133587809The collected standard output of the command is returned.
133597810In scalar context, it comes back as a single (potentially
133607811multi-line) string. In list context, returns a list of lines
13361(however you've defined lines with L<C<$E<sol>>|perlvar/$E<sol>> (or
7812(however you've defined lines with C<$/> or C<$INPUT_RECORD_SEPARATOR>).
13362C<$INPUT_RECORD_SEPARATOR> in L<English>)).
133637813This is the internal function implementing the C<qx/EXPR/>
133647814operator, but you can use it directly. The C<qx/EXPR/>
133657815operator is discussed in more detail in L<perlop/"I/O Operators">.
13366If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
133677816
133687817=end original
133697818
133707819EXPR がシステムコマンドとして実行されます。
133717820コマンドの標準出力の内容が返されます。
133727821スカラコンテキストでは、単一の(内部的に複数行の)文字列を返します。
133737822リストコンテキストでは、行のリストを返します
13374(但し、行は L<C<$E<sol>>|perlvar/$E<sol>> (または L<English> モジュール
7823(但し、行は C<$/> または C<$INPUT_RECORD_SEPARATOR> で定義されます)。
13375C<$INPUT_RECORD_SEPARATOR> で定義されま)。
7824これは C<qx/EXPR/> 演算子を実装する内部関数ですが、
13376これは C<qx/EXPR/> 演算子を実装する内部関数ですが、直接使うことも出来ます。
7825直接使うことも出来ます。
13377C<qx/EXPR/> 演算子は L<perlop/"I/O Operators"> でより詳細に述べられています。
7826C<qx/EXPR/> 演算子は L<perlop/"I/O Operators"> でより詳細に
13378EXPR が省略さると、L<C<$_>|perlvar/$_> を使います。
7827述べらいます。
133797828
133807829=item recv SOCKET,SCALAR,LENGTH,FLAGS
13381X<recv>
133827830
13383=for Pod::Functions receive a message over a Socket
13384
133857831=begin original
133867832
13387Receives a message on a socket. Attempts to receive LENGTH characters
7833Receives a message on a socket. Attempts to receive LENGTH bytes of
13388of data into variable SCALAR from the specified SOCKET filehandle.
7834data into variable SCALAR from the specified SOCKET filehandle. SCALAR
13389SCALAR will be grown or shrunk to the length actually read. Takes the
7835will be grown or shrunk to the length actually read. Takes the same
13390same flags as the system call of the same name. Returns the address
7836flags as the system call of the same name. Returns the address of the
13391of the sender if SOCKET's protocol supports this; returns an empty
7837sender if SOCKET's protocol supports this; returns an empty string
13392string otherwise. If there's an error, returns the undefined value.
7838otherwise. If there's an error, returns the undefined value. This call
13393This call is actually implemented in terms of the L<recvfrom(2)> system call.
7839is actually implemented in terms of recvfrom(2) system call. See
13394See L<perlipc/"UDP: Message Passing"> for examples.
7840L<perlipc/"UDP: Message Passing"> for examples.
133957841
133967842=end original
133977843
133987844ソケット上のメッセージを受信します。
133997845指定されたファイルハンドル SOCKET から、変数 SCALAR に
13400LENGTH 文字のデータを読み込もうとします。
7846LENGTH バイトのデータを読み込もうとします。
13401SCALAR は、実際に読まれた長さによって、大きくなったり、小さくなったりします。
7847SCALAR は、実際に読まれた長さによって、大きくなったり、
13402同名のシステムコールと同じフラグが指定できます。
7848小さくなったりします。
7849同名のシステムコールと同じ FLAGS を使います。
134037850SOCKET のプロトコルが対応していれば、送信側のアドレスを返します。
134047851エラー発生時には、未定義値を返します。
13405実際には、C の L<recvfrom(2)> を呼びます。
7852実際には、C のrecvfrom(2) を呼びます。
13406例については L<perlipc/"UDP: Message Passing"> を参照してください。
7853例についてはL<perlipc/"UDP: Message Passing">を参照してください。
134077854
13408=begin original
13409
13410Note that if the socket has been marked as C<:utf8>, C<recv> will
13411throw an exception. The C<:encoding(...)> layer implicitly introduces
13412the C<:utf8> layer. See L<C<binmode>|/binmode FILEHANDLE, LAYER>.
13413
13414=end original
13415
13416ソケットが C<:utf8> としてマークされている場合、
13417C<recv> は例外を投げることに注意してください。
13418C<:encoding(...)> 層は暗黙に C<:utf8> 層を導入します。
13419L<C<binmode>|/binmode FILEHANDLE, LAYER> を参照してください。
13420
134217855=item redo LABEL
13422X<redo>
134237856
13424=item redo EXPR
13425
134267857=item redo
134277858
13428=for Pod::Functions start this loop iteration over again
13429
134307859=begin original
134317860
13432The L<C<redo>|/redo LABEL> command restarts the loop block without
7861The C<redo> command restarts the loop block without evaluating the
13433evaluating the conditional again. The L<C<continue>|/continue BLOCK>
7862conditional again. The C<continue> block, if any, is not executed. If
13434block, if any, is not executed. If
134357863the LABEL is omitted, the command refers to the innermost enclosing
13436loop. The C<redo EXPR> form, available starting in Perl 5.18.0, allows a
7864loop. This command is normally used by programs that want to lie to
13437label name to be computed at run time, and is otherwise identical to C<redo
7865themselves about what was just input:
13438LABEL>. Programs that want to lie to themselves about what was just input
13439normally use this command:
134407866
134417867=end original
134427868
13443L<C<redo>|/redo LABEL> コマンドは、条件を再評価しないで、ループブロックの
7869redo コマンドは、条件を再評価しないで、ループブロックの始めからもう一度
13444始めからもう一度実行を開始します。
7870実行を開始します。
13445L<C<continue>|/continue BLOCK> ブロックがあっても、実行されません。
7871C<continue> ブロックがあっても、実行されません。
13446LABEL が省略されると、コマンドは一番内側のループを参照します。
7872LABEL が省略されると、このコマンドは、もっとも内側のループを参照します。
13447Perl 5.18.0 から利用可能な C<redo EXPR> 形式では、実行時に計算されるラベル名が
13448使えます; それ以外は C<redo LABEL> と同一です。
134497873このコマンドは通常、自分への入力を欺くために使用します:
134507874
134517875 # a simpleminded Pascal comment stripper
134527876 # (warning: assumes no { or } in strings)
134537877 LINE: while (<STDIN>) {
13454 while (s|({.*}.*){.*}|$1 |) {}
7878 while (s|({.*}.*){.*}|$1 |) {}
13455 s|{.*}| |;
7879 s|{.*}| |;
13456 if (s|{.*| |) {
7880 if (s|{.*| |) {
13457 my $front = $_;
7881 $front = $_;
13458 while (<STDIN>) {
7882 while (<STDIN>) {
13459 if (/}/) { # end of comment?
7883 if (/}/) { # end of comment?
13460 s|^|$front\{|;
7884 s|^|$front\{|;
13461 redo LINE;
7885 redo LINE;
13462 }
7886 }
13463 }
7887 }
13464 }
7888 }
13465 print;
7889 print;
134667890 }
134677891
134687892=begin original
134697893
13470L<C<redo>|/redo LABEL> cannot return a value from a block that typically
7894C<redo> cannot be used to retry a block which returns a value such as
13471returns a value, such as C<eval {}>, C<sub {}>, or C<do {}>. It will perform
7895C<eval {}>, C<sub {}> or C<do {}>, and should not be used to exit
13472its flow control behavior, which precludes any return value. It should not be
7896a grep() or map() operation.
13473used to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST>
13474operation.
134757897
134767898=end original
134777899
13478L<C<redo>|/redo LABEL> は C<eval {}>, C<sub {}>, C<do {}> といった
7900C<redo> は C<eval {}>, C<sub {}>, C<do {}> のように値を返す
13479典型的には値を返すブロックから値を返ません。
7901ブロックを繰りすのには使えません。
13480これは返り値を不可能にすフロー制御振る舞いを実行し
7902またgrep() や map() 操作から抜けるのに使うべきではありせん
13481L<C<grep>|/grep BLOCK LIST> や L<C<map>|/map BLOCK LIST> 操作を終了するのに
13482使うべきではありません。
134837903
134847904=begin original
134857905
134867906Note that a block by itself is semantically identical to a loop
13487that executes once. Thus L<C<redo>|/redo LABEL> inside such a block
7907that executes once. Thus C<redo> inside such a block will effectively
13488will effectively turn it into a looping construct.
7908turn it into a looping construct.
134897909
134907910=end original
134917911
134927912ブロック自身は一回だけ実行されるループと文法的に同一であることに
134937913注意してください。
13494従って、ブロックの中で L<C<redo>|/redo LABEL> を使うことで効果的に
7914従って、ブロックの中で C<redo> を使うことで効果的に
134957915ループ構造に変換します。
134967916
134977917=begin original
134987918
13499See also L<C<continue>|/continue BLOCK> for an illustration of how
7919See also L</continue> for an illustration of how C<last>, C<next>, and
13500L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and
7920C<redo> work.
13501L<C<redo>|/redo LABEL> work.
135027921
135037922=end original
135047923
13505L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL>
7924C<last>, C<next>, C<redo> がどのように働くかについては
13506どのように働くかについては L<C<continue>|/continue BLOCK> 参照してください。
7925L</continue> 参照してさい。
135077926
13508=begin original
13509
13510Unlike most named operators, this has the same precedence as assignment.
13511It is also exempt from the looks-like-a-function rule, so
13512C<redo ("foo")."bar"> will cause "bar" to be part of the argument to
13513L<C<redo>|/redo LABEL>.
13514
13515=end original
13516
13517ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
13518また、関数のように見えるものの規則からも免れるので、C<redo ("foo")."bar"> と
13519すると "bar" は L<C<redo>|/redo LABEL> への引数の一部となります。
13520
135217927=item ref EXPR
13522X<ref> X<reference>
135237928
135247929=item ref
135257930
13526=for Pod::Functions find out the type of thing being referenced
13527
135287931=begin original
135297932
13530Examines the value of EXPR, expecting it to be a reference, and returns
7933Returns a true value if EXPR is a reference, false otherwise. If EXPR
13531a string giving information about the reference and the type of referent.
7934is not specified, C<$_> will be used. The value returned depends on the
13532If EXPR is not specified, L<C<$_>|perlvar/$_> will be used.
7935type of thing the reference is a reference to.
7936Builtin types include:
135337937
135347938=end original
135357939
13536Examines the value of
7940EXPR がリファレンスであれば、真を返し、さもなくば、偽を返します。
13537リファレンスと想定される EXPR の値を調べて
7941EXPR が指定されなければC<$_> が使われます。
13538そのリファレンスとリファレンス先の型にる情報を表す
7942返される値は、リファレンスが参照するも型に依存しま
13539文字列を返します。
7943組み込みの型には、以下のものがあります。
13540EXPR が指定されていない場合、L<C<$_>|perlvar/$_> が使われます。
135417944
13542=begin original
7945 SCALAR
7946 ARRAY
7947 HASH
7948 CODE
7949 REF
7950 GLOB
7951 LVALUE
135437952
13544If the operand is not a reference, then the empty string will be returned.
13545An empty string will only be returned in this situation. C<ref> is often
13546useful to just test whether a value is a reference, which can be done
13547by comparing the result to the empty string. It is a common mistake
13548to use the result of C<ref> directly as a truth value: this goes wrong
13549because C<0> (which is false) can be returned for a reference.
13550
13551=end original
13552
13553オペランドがリファレンスでない場合、空文字列が返されます。
13554空文字列はこの場合にのみ返されます。
13555結果を空文字列を比較することでできるので、
13556C<ref> は単にある値がリファレンスかどうかを調べるのにしばしば有用です。
13557C<ref> の結果を直接真の値として使うのは良くある誤りです:
13558リファレンスの場合に (偽である) C<0> が返されることがあるので、
13559これは誤りです。
13560
135617953=begin original
135627954
13563If the operand is a reference to a blessed object, then the name of
7955If the referenced object has been blessed into a package, then that package
13564the class into which the referent is blessed will be returned. C<ref>
7956name is returned instead. You can think of C<ref> as a C<typeof> operator.
13565doesn't care what the physical type of the referent is; blessing takes
13566precedence over such concerns. Beware that exact comparison of C<ref>
13567results against a class name doesn't perform a class membership test:
13568a class's members also include objects blessed into subclasses, for
13569which C<ref> will return the name of the subclass. Also beware that
13570class names can clash with the built-in type names (described below).
135717957
135727958=end original
135737959
13574オペランドが bless されオブジェクトへのリファレンスの場合
7960参照されオブジェクト何らかのパッケージに
13575リファレンス先が bless されているクラス名が返さます。
7961bless されたものであば、これらの代わりに、
13576C<ref> はリファレンス先物理的な種類については気にしせん;
7962パッケージ名が返されす。
13577bless されているかがそのような関心より優先されます。
7963C<ref> は、C<typeof> 演算子のように考えることができます。
13578C<ref> の結果とクラス名の正確な比較は、クラスの所属のテストを
13579実行しないことに注意してください:
13580C<ref> がサブクラスの名前を返す場合、
13581あるクラスのメンバはサブクラスに bless されているオブジェクトを
13582含んでいます。
13583クラス名は(後述する)組み込みの型名と衝突することにも注意してください。
135847964
13585=begin original
7965 if (ref($r) eq "HASH") {
7966 print "r is a reference to a hash.\n";
7967 }
7968 unless (ref($r)) {
7969 print "r is not a reference at all.\n";
7970 }
7971 if (UNIVERSAL::isa($r, "HASH")) { # for subclassing
7972 print "r is a reference to something that isa hash.\n";
7973 }
135867974
13587If the operand is a reference to an unblessed object, then the return
13588value indicates the type of object. If the unblessed referent is not
13589a scalar, then the return value will be one of the strings C<ARRAY>,
13590C<HASH>, C<CODE>, C<FORMAT>, or C<IO>, indicating only which kind of
13591object it is. If the unblessed referent is a scalar, then the return
13592value will be one of the strings C<SCALAR>, C<VSTRING>, C<REF>, C<GLOB>,
13593C<LVALUE>, or C<REGEXP>, depending on the kind of value the scalar
13594currently has. But note that C<qr//> scalars are created already
13595blessed, so C<ref qr/.../> will likely return C<Regexp>. Beware that
13596these built-in type names can also be used as
13597class names, so C<ref> returning one of these names doesn't unambiguously
13598indicate that the referent is of the kind to which the name refers.
13599
13600=end original
13601
13602オペランドが bless されていないオブジェクトへのリファレンスの場合、
13603返り値はオブジェクトの型を示します。
13604bless されていないリファレンス先がスカラではない場合、
13605返り値はオブジェクトの種類を示す、
13606C<ARRAY>, C<HASH>, C<CODE>, C<FORMAT>, C<IO> のいずれかの文字列です。
13607bless されていないリファレンス先がスカラの場合、
13608返り値はそのスカラが現在保持している種類に依存して、
13609C<SCALAR>, C<VSTRING>, C<REF>, C<GLOB>, C<LVALUE>, C<REGEXP> の
13610いずれかの文字列です。
13611しかし、C<qr//> は既に bless されて作成されるので、
13612C<ref qr/.../> はおそらく C<Regexp> を返すことに注意してください。
13613これらの組み込み型名はまたクラス名として使われることができるので、
13614C<ref> がこれらの名前の一つを返すことは、
13615明らかにリファレンス先がその名前が示している種類のものであることを
13616示しているわけではないことに注意してください。
13617
136187975=begin original
136197976
13620The ambiguity between built-in type names and class names significantly
7977See also L<perlref>.
13621limits the utility of C<ref>. For unambiguous information, use
13622L<C<Scalar::Util::blessed()>|Scalar::Util/blessed> for information about
13623blessing, and L<C<Scalar::Util::reftype()>|Scalar::Util/reftype> for
13624information about physical types. Use L<the C<isa> method|UNIVERSAL/C<<
13625$obj->isa( TYPE ) >>> for class membership tests, though one must be
13626sure of blessedness before attempting a method call.
136277978
136287979=end original
136297980
13630組み込み型とクラス名の間の曖昧さは C<ref> の有用性を大きく制限しています
7981L<perlref> も参照してください。
13631曖昧でない情報のためには、bless に関する情報については
13632L<C<Scalar::Util::blessed()>|Scalar::Util/blessed> を、
13633物理的な型の情報については
13634L<C<Scalar::Util::reftype()>|Scalar::Util/reftype> を使ってください。
13635クラスの所属メンバテストには
13636L<the C<isa> method|UNIVERSAL/C<<
13637$obj->isa( TYPE ) >>> を使ってください;
13638但し、メソッド呼び出しを試みる前に bless されていることを
13639確認しなければなりません。
136407982
13641=begin original
13642
13643See also L<perlref> and L<perlobj>.
13644
13645=end original
13646
13647L<perlref> と L<perlobj> も参照してください。
13648
136497983=item rename OLDNAME,NEWNAME
13650X<rename> X<move> X<mv> X<ren>
136517984
13652=for Pod::Functions change a filename
13653
136547985=begin original
136557986
136567987Changes the name of a file; an existing file NEWNAME will be
136577988clobbered. Returns true for success, false otherwise.
136587989
136597990=end original
136607991
13661ファイルの名前を変更します; NEWNAME というファイルが既に存在した場合、
7992ファイルの名前を変更します
13662上書きされるかもしれません。
7993NEWNAME というファイルが既に存在した場合、上書きされるかもしれません。
13663成功時には真さもなければ偽を返します。
7994成功時には真、失敗時には偽を返します。
136647995
136657996=begin original
136667997
136677998Behavior of this function varies wildly depending on your system
136687999implementation. For example, it will usually not work across file system
136698000boundaries, even though the system I<mv> command sometimes compensates
136708001for this. Other restrictions include whether it works on directories,
136718002open files, or pre-existing files. Check L<perlport> and either the
13672L<rename(2)> manpage or equivalent system documentation for details.
8003rename(2) manpage or equivalent system documentation for details.
136738004
136748005=end original
136758006
136768007この関数の振る舞いはシステムの実装に大きく依存して異なります。
13677例えば、普通はファイルシステムにまたがってパス名を付け替えることはできません;
8008普通はファイルシステムにまたがってパス名を付け替えることはできません
136788009システムの I<mv> がこれを補完している場合でもそうです。
136798010その他の制限には、ディレクトリ、オープンしているファイル、既に存在している
136808011ファイルに対して使えるか、といったことを含みます。
13681詳しくは、L<perlport> および L<rename(2)> man ページあるいは同様の
8012詳しくは、L<perlport> および rename(2) man ページあるいは同様の
136828013システムドキュメントを参照してください。
136838014
13684=begin original
13685
13686For a platform independent L<C<move>|File::Copy/move> function look at
13687the L<File::Copy> module.
13688
13689=end original
13690
13691プラットフォームに依存しない L<C<move>|File::Copy/move> 関数については
13692L<File::Copy> モジュールを参照してください。
13693
13694=begin original
13695
13696Portability issues: L<perlport/rename>.
13697
13698=end original
13699
13700移植性の問題: L<perlport/rename>。
13701
137028015=item require VERSION
13703X<require>
137048016
137058017=item require EXPR
137068018
137078019=item require
137088020
13709=for Pod::Functions load in external functions from a library at runtime
13710
137118021=begin original
137128022
13713Demands a version of Perl specified by VERSION, or demands some semantics
8023Demands some semantics specified by EXPR, or by C<$_> if EXPR is not
13714specified by EXPR or by L<C<$_>|perlvar/$_> if EXPR is not supplied.
8024supplied.
137158025
137168026=end original
137178027
13718VERSION 指定される Perl バージョンを要求するか、
8028EXPR (省略時には C<$_>) によって指定されるいくつか動作を要求しま
13719EXPR (省略時には L<C<$_>|perlvar/$_>) によって指定されるいくつかの動作を
13720要求します。
137218029
137228030=begin original
137238031
13724VERSION may be either a literal such as v5.24.1, which will be
8032If a VERSION is specified as a literal of the form v5.6.1,
13725compared to L<C<$^V>|perlvar/$^V> (or C<$PERL_VERSION> in L<English>),
8033demands that the current version of Perl (C<$^V> or $PERL_VERSION) be
13726or a numeric argument of the form 5.024001, which will be compared to
8034at least as recent as that version, at run time. (For compatibility
13727L<C<$]>|perlvar/$]>. An exception is raised if VERSION is greater than
8035with older versions of Perl, a numeric argument will also be interpreted
13728the version of the current Perl interpreter. Compare with
8036as VERSION.) Compare with L</use>, which can do a similar check at
13729L<C<use>|/use Module VERSION LIST>, which can do a similar check at
137308037compile time.
137318038
137328039=end original
137338040
13734VERSION は、v5.24.1 のようなリテラル
8041VERSION v5.6.1 の形で指定されると、実行時の
13735(L<C<$^V>|perlvar/$^V> (または L<English> モジュールでは
8042Perl の現在のバージョン(C<$^V> または $PERL_VERSION)が
13736C<$PERL_VERSION>) 比較されます) か、
8043そのバージョン以降であるこを要求します
137375.024001 の数値形式(L<C<$]>|perlvar/$]>比較されます)で指定します。
8044(古いバージョンの Perl との互換性のために、数値の引数も
13738VERSION が Perl の現在のバージョンより大きい、例外が発生します
8045VERSION として解釈されます)
13739L<C<use>|/use Module VERSION LIST> と似ていますが、これはコンパイル時に
8046L</use> と似ていますが、これはコンパイル時にチェックされます。
13740チェックされます。
137418047
13742=begin original
8048 require v5.6.1; # run time version check
8049 require 5.6.1; # ditto
8050 require 5.005_03; # float version allowed for compatibility
137438051
13744Specifying VERSION as a numeric argument of the form 5.024001 should
13745generally be avoided as older less readable syntax compared to
13746v5.24.1. Before perl 5.8.0 (released in 2002), the more verbose numeric
13747form was the only supported syntax, which is why you might see it in
13748older code.
13749
13750=end original
13751
13752VERSION に 5.024001 の形の数値引数を指定することは一般的には避けるべきです;
13753v5.24.1 に比べてより古く読みにくい文法だからです。
13754(2002 年にリリースされた) perl 5.8.0 より前では、より冗長な
13755数値形式が唯一対応している文法でした; これが古いコードでこれを
13756見るかも知れない理由です。
13757
137588052=begin original
137598053
13760 require v5.24.1; # run time version check
8054Otherwise, demands that a library file be included if it hasn't already
13761 require 5.24.1; # ditto
8055been included. The file is included via the do-FILE mechanism, which is
13762 require 5.024_001; # ditto; older syntax compatible
8056essentially just a variety of C<eval>. Has semantics similar to the following
13763 with perl 5.6
8057subroutine:
137648058
137658059=end original
137668060
13767 require v5.24.1; # 実行時バージョンチェック
8061それ以外の場合には、既に読み込まれていないときに、
13768 require 5.24.1; # 同様
8062読み込むライブラリファイルを要求するものとなります。
13769 require 5.024_001; # 同様; perl 5.6 と互換性のある古い文法
8063そのファイルは、基本的には C<eval>一種である
8064do-FILE によって読み込まれます。
8065意味的には、次のようなサブルーチンと同じようなものです:
137708066
13771=begin original
13772
13773Otherwise, L<C<require>|/require VERSION> demands that a library file be
13774included if it hasn't already been included. The file is included via
13775the do-FILE mechanism, which is essentially just a variety of
13776L<C<eval>|/eval EXPR> with the
13777caveat that lexical variables in the invoking script will be invisible
13778to the included code. If it were implemented in pure Perl, it
13779would have semantics similar to the following:
13780
13781=end original
13782
13783それ以外の場合には、L<C<require>|/require VERSION> は、既に
13784読み込まれていないときに読み込むライブラリファイルを要求するものとなります。
13785そのファイルは、基本的には L<C<eval>|/eval EXPR> の一種である、
13786do-FILE によって読み込まれますが、起動したスクリプトのレキシカル変数は
13787読み込まれたコードから見えないという欠点があります。
13788ピュア Perl で実装した場合、意味的には、次のようなサブルーチンと
13789同じようなものです:
13790
13791 use Carp 'croak';
13792 use version;
13793
137948067 sub require {
13795 my ($filename) = @_;
8068 my($filename) = @_;
13796 if ( my $version = eval { version->parse($filename) } ) {
8069 return 1 if $INC{$filename};
13797 if ( $version > $^V ) {
8070 my($realfilename,$result);
13798 my $vn = $version->normal;
8071 ITER: {
13799 croak "Perl $vn required--this is only $^V, stopped";
8072 foreach $prefix (@INC) {
13800 }
8073 $realfilename = "$prefix/$filename";
13801 return 1;
8074 if (-f $realfilename) {
13802 }
8075 $INC{$filename} = $realfilename;
8076 $result = do $realfilename;
13804 if (exists $INC{$filename}) {
8077 last ITER;
13805 return 1 if $INC{$filename};
8078 }
13806 croak "Compilation failed in require";
8079 }
13807 }
8080 die "Can't find $filename in \@INC";
8081 }
13809 foreach $prefix (@INC) {
8082 delete $INC{$filename} if $@ || !$result;
13810 if (ref($prefix)) {
8083 die $@ if $@;
13811 #... do other stuff - see text below ....
8084 die "$filename did not return true value" unless $result;
13812 }
8085 return $result;
13813 # (see text below about possible appending of .pmc
13814 # suffix to $filename)
13815 my $realfilename = "$prefix/$filename";
13816 next if ! -e $realfilename || -d _ || -b _;
13817 $INC{$filename} = $realfilename;
13818 my $result = do($realfilename);
13819 # but run in caller's namespace
13820
13821 if (!defined $result) {
13822 $INC{$filename} = undef;
13823 croak $@ ? "$@Compilation failed in require"
13824 : "Can't locate $filename: $!\n";
13825 }
13826 if (!$result) {
13827 delete $INC{$filename};
13828 croak "$filename did not return true value";
13829 }
13830 $! = 0;
13831 return $result;
13832 }
13833 croak "Can't locate $filename in \@INC ...";
138348086 }
138358087
138368088=begin original
138378089
138388090Note that the file will not be included twice under the same specified
13839name.
8091name. The file must return true as the last statement to indicate
13840
13841=end original
13842
13843ファイルは、同じ名前で 2 回読み込まれることはないことに注意してください。
13844
13845=begin original
13846
13847The file must return true as the last statement to indicate
138488092successful execution of any initialization code, so it's customary to
138498093end such a file with C<1;> unless you're sure it'll return true
138508094otherwise. But it's better just to put the C<1;>, in case you add more
138518095statements.
138528096
138538097=end original
138548098
13855初期化コードの実行がうまくいったことを示すために、ファイルは真を
8099ファイルは、同じ名前で 2 回読み込まれることはありません。
13856返さなければならないで、真を返すよになってる自信がある場合除いては
8100初期化コード実行がまくったこと示すために
8101ファイルは真を返さなければなりませんから、
8102真を返すようになっている自信がある場合を除いては、
138578103ファイルの最後に C<1;> と書くのが習慣です。
13858しかし、実行文を追加するような場合に備えて、C<1;> と書いておいた方が良いです。
8104実行文を追加するような場合に備えて、C<1;> と書いておいた方が
8105良いでしょう。
138598106
138608107=begin original
138618108
13862If EXPR is a bareword, L<C<require>|/require VERSION> assumes a F<.pm>
8109If EXPR is a bareword, the require assumes a "F<.pm>" extension and
13863extension and replaces C<::> with C</> in the filename for you,
8110replaces "F<::>" with "F</>" in the filename for you,
138648111to make it easy to load standard modules. This form of loading of
13865modules does not risk altering your namespace, however it will autovivify
8112modules does not risk altering your namespace.
13866the stash for the required module.
138678113
138688114=end original
138698115
13870EXPR が裸の単語であるときには、標準モジュールのロードを簡単にするように、
8116EXPR が裸の単語であるときには、標準モジュールのロードを
13871L<C<require>|/require VERSION> は拡張子が F<.pm> であり、C<::> を C</> に
8117簡単にするように、require は拡張子が "F<.pm>" であり、
13872変えたものがファイル名であると仮定します。
8118"F<::>" を "F</>" に変えたものがファイル名であると仮定します。
13873この形式のモジュールロードは、名前空間を変更してしまう危険はありませんが、
8119この形式のモジュールロードは、
13874要求されたモジュールのためのスタッシュが自動有効化され
8120名前空間を変更してしう危険はありません
138758121
138768122=begin original
138778123
138788124In other words, if you try this:
138798125
138808126=end original
138818127
138828128言い換えると、以下のようにすると:
138838129
13884 require Foo::Bar; # a splendid bareword
8130 require Foo::Bar; # a splendid bareword
138858131
138868132=begin original
138878133
13888The require function will actually look for the F<Foo/Bar.pm> file in the
8134The require function will actually look for the "F<Foo/Bar.pm>" file in the
13889directories specified in the L<C<@INC>|perlvar/@INC> array, and it will
8135directories specified in the C<@INC> array.
13890autovivify the C<Foo::Bar::> stash at compile time.
138918136
13892=end original
13893
13894require 関数は L<C<@INC>|perlvar/@INC> 配列で指定されたディレクトリにある
13895F<Foo/Bar.pm> ファイルを探し、コンパイル時に
13896C<Foo::Bar::> のスタッシュを自動有効化します。
13897
13898=begin original
13899
139008137But if you try this:
139018138
139028139=end original
139038140
8141require 関数は C<@INC> 配列で指定されたディレクトリにある
8142"F<Foo/Bar.pm>" ファイルを探します。
8143
139048144しかし、以下のようにすると:
139058145
13906 my $class = 'Foo::Bar';
8146 $class = 'Foo::Bar';
13907 require $class; # $class is not a bareword
8147 require $class; # $class is not a bareword
139088148 #or
13909 require "Foo::Bar"; # not a bareword because of the ""
8149 require "Foo::Bar"; # not a bareword because of the ""
139108150
139118151=begin original
139128152
13913The require function will look for the F<Foo::Bar> file in the
8153The require function will look for the "F<Foo::Bar>" file in the @INC array and
13914L<C<@INC>|perlvar/@INC> array and
8154will complain about not finding "F<Foo::Bar>" there. In this case you can do:
13915will complain about not finding F<Foo::Bar> there. In this case you can do:
139168155
139178156=end original
139188157
13919require 関数は L<C<@INC>|perlvar/@INC> 配列の F<Foo::Bar> ファイルを探し、
8158require 関数は @INC 配列の "F<Foo::Bar>" ファイルを探し、
13920おそらくそこに F<Foo::Bar> がないと文句をいうことになるでしょう。
8159おそらくそこに "F<Foo::Bar>" がないと文句をいうことになるでしょう。
13921このような場合には、以下のように:
8160このような場合には、以下のようにします:
139228161
139238162 eval "require $class";
139248163
139258164=begin original
139268165
13927or you could do
8166For a yet-more-powerful import facility, see L</use> and L<perlmod>.
139288167
139298168=end original
139308169
13931あるいは次のようにも出来ます
13932
13933 require "Foo/Bar.pm";
13934
13935=begin original
13936
13937Neither of these forms will autovivify any stashes at compile time and
13938only have run time effects.
13939
13940=end original
13941
13942これらのどちらもコンパイル時にスタッシュを自動有効化せず、
13943実行時の効果のみを持ちます。
13944
13945=begin original
13946
13947Now that you understand how L<C<require>|/require VERSION> looks for
13948files with a bareword argument, there is a little extra functionality
13949going on behind the scenes. Before L<C<require>|/require VERSION> looks
13950for a F<.pm> extension, it will first look for a similar filename with a
13951F<.pmc> extension. If this file is found, it will be loaded in place of
13952any file ending in a F<.pm> extension. This applies to both the explicit
13953C<require "Foo/Bar.pm";> form and the C<require Foo::Bar;> form.
13954
13955=end original
13956
13957引数が裸の単語の場合、L<C<require>|/require VERSION> がどのようにファイルを
13958探すかを理解してください; 水面下でちょっとした追加の機能があります。
13959L<C<require>|/require VERSION> が拡張子 F<.pm> のファイルを探す前に、まず
13960拡張子 F<.pmc> を持つファイルを探します。
13961このファイルが見つかると、このファイルが拡張子 F<.pm> の代わりに
13962読み込まれます。
13963これは明示的な C<require "Foo/Bar.pm";> 形式と C<require Foo::Bar;> 形式の
13964両方に適用されます。
13965
13966=begin original
13967
13968You can also insert hooks into the import facility by putting Perl code
13969directly into the L<C<@INC>|perlvar/@INC> array. There are three forms
13970of hooks: subroutine references, array references, and blessed objects.
13971
13972=end original
13973
13974L<C<@INC>|perlvar/@INC> 配列に直接 Perl コードを入れることで、インポート機能に
13975フックを挿入できます。
139763 種類のフックがあります: サブルーチンリファレンス、配列リファレンス、
13977bless されたオブジェクトです。
13978
13979=begin original
13980
13981Subroutine references are the simplest case. When the inclusion system
13982walks through L<C<@INC>|perlvar/@INC> and encounters a subroutine, this
13983subroutine gets called with two parameters, the first a reference to
13984itself, and the second the name of the file to be included (e.g.,
13985F<Foo/Bar.pm>). The subroutine should return either nothing or else a
13986list of up to four values in the following order:
13987
13988=end original
13989
13990サブルーチンへのリファレンスは一番単純な場合です。
13991インクルード機能が L<C<@INC>|perlvar/@INC> を走査してサブルーチンに
13992出会った場合、このサブルーチンは二つの引数と共に呼び出されます;
13993一つ目は自身へのリファレンス、二つ目はインクルードされるファイル名
13994(F<Foo/Bar.pm> など)です。
13995サブルーチンは何も返さないか、以下の順で最大四つの値のリストを返します。
13996
13997=over
13998
13999=item 1
14000
14001=begin original
14002
14003A reference to a scalar, containing any initial source code to prepend to
14004the file or generator output.
14005
14006=end original
14007
14008ファイルやジェネレータの出力の前に追加される初期化ソースコードを含む
14009スカラへのリファレンス。
14010
14011=item 2
14012
14013=begin original
14014
14015A filehandle, from which the file will be read.
14016
14017=end original
14018
14019ファイルが読み込まれるファイルハンドル。
14020
14021=item 3
14022
14023=begin original
14024
14025A reference to a subroutine. If there is no filehandle (previous item),
14026then this subroutine is expected to generate one line of source code per
14027call, writing the line into L<C<$_>|perlvar/$_> and returning 1, then
14028finally at end of file returning 0. If there is a filehandle, then the
14029subroutine will be called to act as a simple source filter, with the
14030line as read in L<C<$_>|perlvar/$_>.
14031Again, return 1 for each valid line, and 0 after all lines have been
14032returned.
14033For historical reasons the subroutine will receive a meaningless argument
14034(in fact always the numeric value zero) as C<$_[0]>.
14035
14036=end original
14037
14038サブルーチンへのリファレンス。
14039(一つ前のアイテムである)ファイルハンドルがない場合、サブルーチンは呼び出し毎に
14040一行のソースコードを生成し、その行を L<C<$_>|perlvar/$_> に書き込んで 1 を
14041返し、それから最終的にファイル終端で 0 を返すものと想定されます。
14042ファイルハンドルがある場合、サブルーチンは単純なソースフィルタとして
14043振舞うように呼び出され、行は L<C<$_>|perlvar/$_> から読み込まれます。
14044再び、有効な行ごとに 1 を返し、全ての行を返した後では 0 を返します。
14045歴史的な理由により、サブルーチンは C<$_[0]> として意味のない引数
14046(実際には常に数値 0) を受け取ります。
14047
14048=item 4
14049
14050=begin original
14051
14052Optional state for the subroutine. The state is passed in as C<$_[1]>.
14053
14054=end original
14055
14056サブルーチンのための状態(オプション)。
14057状態は C<$_[1]> として渡されます。
14058
14059=back
14060
14061=begin original
14062
14063If an empty list, L<C<undef>|/undef EXPR>, or nothing that matches the
14064first 3 values above is returned, then L<C<require>|/require VERSION>
14065looks at the remaining elements of L<C<@INC>|perlvar/@INC>.
14066Note that this filehandle must be a real filehandle (strictly a typeglob
14067or reference to a typeglob, whether blessed or unblessed); tied filehandles
14068will be ignored and processing will stop there.
14069
14070=end original
14071
14072空リスト、L<C<undef>|/undef EXPR>、または上記の最初の三つの値のどれとも
14073一致しないものが返されると、L<C<require>|/require VERSION> は
14074L<C<@INC>|perlvar/@INC> の残りの要素を見ます。
14075このファイルハンドルは実際のファイルハンドル(厳密には型グロブ、型グロブへの
14076リファレンス、bless されているかに関わらず)でなければなりません;
14077tie されたファイルハンドルは無視され、返り値の処理はそこで停止します。
14078
14079=begin original
14080
14081If the hook is an array reference, its first element must be a subroutine
14082reference. This subroutine is called as above, but the first parameter is
14083the array reference. This lets you indirectly pass arguments to
14084the subroutine.
14085
14086=end original
14087
14088フックが配列のリファレンスの場合、その最初の要素はサブルーチンへの
14089リファレンスでなければなりません。
14090このサブルーチンは上述のように呼び出されますが、その最初の引数は
14091配列のリファレンスです。
14092これによって、間接的にサブルーチンに引数を渡すことが出来ます。
14093
14094=begin original
14095
14096In other words, you can write:
14097
14098=end original
14099
14100言い換えると、以下のように書いたり:
14101
14102 push @INC, \&my_sub;
14103 sub my_sub {
14104 my ($coderef, $filename) = @_; # $coderef is \&my_sub
14105 ...
14106 }
14107
14108=begin original
14109
14110or:
14111
14112=end original
14113
14114または以下のように書けます:
14115
14116 push @INC, [ \&my_sub, $x, $y, ... ];
14117 sub my_sub {
14118 my ($arrayref, $filename) = @_;
14119 # Retrieve $x, $y, ...
14120 my (undef, @parameters) = @$arrayref;
14121 ...
14122 }
14123
14124=begin original
14125
14126If the hook is an object, it must provide an C<INC> method that will be
14127called as above, the first parameter being the object itself. (Note that
14128you must fully qualify the sub's name, as unqualified C<INC> is always forced
14129into package C<main>.) Here is a typical code layout:
14130
14131=end original
14132
14133フックがオブジェクトの場合、C<INC> メソッドを提供している必要があります;
14134それが、最初の引数をオブジェクト自身として上述のように呼び出されます。
14135(修飾されていない C<INC> は常にパッケージ C<main> に強制されるため、
14136サブルーチン名は完全修飾する必要があることに注意してください。)
14137以下は典型的なコードレイアウトです:
14138
14139 # In Foo.pm
14140 package Foo;
14141 sub new { ... }
14142 sub Foo::INC {
14143 my ($self, $filename) = @_;
14144 ...
14145 }
14146
14147 # In the main program
14148 push @INC, Foo->new(...);
14149
14150=begin original
14151
14152These hooks are also permitted to set the L<C<%INC>|perlvar/%INC> entry
14153corresponding to the files they have loaded. See L<perlvar/%INC>.
14154
14155=end original
14156
14157これらのフックは、読み込まれるファイルに対応する
14158L<C<%INC>|perlvar/%INC> エントリをセットすることも許可します。
14159L<perlvar/%INC> を参照してください。
14160
14161=begin original
14162
14163For a yet-more-powerful import facility, see
14164L<C<use>|/use Module VERSION LIST> and L<perlmod>.
14165
14166=end original
14167
141688170より強力な import 機能については、このドキュメントの
14169L<C<use>|/use Module VERSION LIST> の項と、L<perlmod> を参照してください。
8171L</use> の項と、L<perlmod> を参照してください。
141708172
141718173=item reset EXPR
14172X<reset>
141738174
141748175=item reset
141758176
14176=for Pod::Functions clear all variables of a given name
14177
141788177=begin original
141798178
14180Generally used in a L<C<continue>|/continue BLOCK> block at the end of a
8179Generally used in a C<continue> block at the end of a loop to clear
14181loop to clear variables and reset C<m?pattern?> searches so that they
8180variables and reset C<??> searches so that they work again. The
14182work again. The
141838181expression is interpreted as a list of single characters (hyphens
14184allowed for ranges). All variables (scalars, arrays, and hashes)
8182allowed for ranges). All variables and arrays beginning with one of
14185in the current package beginning with one of
141868183those letters are reset to their pristine state. If the expression is
14187omitted, one-match searches (C<m?pattern?>) are reset to match again.
8184omitted, one-match searches (C<?pattern?>) are reset to match again. Resets
14188Only resets variables or searches in the current package. Always returns
8185only variables or searches in the current package. Always returns
1418981861. Examples:
141908187
141918188=end original
141928189
14193通常、ループの最後に、変数をクリアし、C<m?pattern?> 検索を再び動作するように
8190通常、ループの最後に、変数をクリアし、C<??> 検索を再び
14194リセットするため、L<C<continue>|/continue BLOCK> ブロックで使われます。
8191動作するようにリセットするため、C<continue> ブロックで使われます。
141958192EXPR は、文字を並べたもの (範囲を指定するのに、ハイフンが使えます) と
141968193解釈されます。
14197名前がその文字のいずれかで始まる、現在のパッケージの全ての変数
8194名前がその文字のいずれかで始まる変数や配列は、
14198(スカラ、配列、ハッシュ)は、
141998195最初の状態にリセットされます。
14200EXPR を省略すると、1 回検索 (C<m?pattern?>) を再びマッチするように
8196EXPR を省略すると、1 回検索 (C<?PATTERN?>) を再びマッチするように
142018197リセットできます。
142028198カレントパッケージの変数もしくは検索だけがリセットされます。
142038199常に 1 を返します。
142048200例:
142058201
14206 reset 'X'; # reset all X variables
8202 reset 'X'; # reset all X variables
14207 reset 'a-z'; # reset lower case variables
8203 reset 'a-z'; # reset lower case variables
14208 reset; # just reset m?one-time? searches
8204 reset; # just reset ?one-time? searches
142098205
142108206=begin original
142118207
142128208Resetting C<"A-Z"> is not recommended because you'll wipe out your
14213L<C<@ARGV>|perlvar/@ARGV> and L<C<@INC>|perlvar/@INC> arrays and your
8209C<@ARGV> and C<@INC> arrays and your C<%ENV> hash. Resets only package
14214L<C<%ENV>|perlvar/%ENV> hash.
8210variables--lexical variables are unaffected, but they clean themselves
8211up on scope exit anyway, so you'll probably want to use them instead.
8212See L</my>.
142158213
142168214=end original
142178215
14218reset C<"A-Z"> とすると、L<C<@ARGV>|perlvar/@ARGV>,
8216reset C<"A-Z"> とすると、C<@ARGV>, C<@INC> 配列や C<%ENV> ハッシュも
14219L<C<@INC>|perlvar/@INC> 配列や L<C<%ENV>|perlvar/%ENV> ハッシュも
8217なくなってしまいますから、止めた方が良いでしょう。
14220なくなってしまうので、止めた方良いでしょう
8218パッケージ変数だけリセットされます
8219レキシカル変数は、影響を受けませんが、スコープから外れれば、
8220自動的に綺麗になりますので、これからは、こちらを使うようにした方が
8221よいでしょう。
8222L</my> を参照してください。
142218223
14222=begin original
14223
14224Resets only package variables; lexical variables are unaffected, but
14225they clean themselves up on scope exit anyway, so you'll probably want
14226to use them instead. See L<C<my>|/my VARLIST>.
14227
14228=end original
14229
14230パッケージ変数だけがリセットされます; レキシカル変数は影響を受けませんが、
14231スコープから外れれば自動的に綺麗になるので、これからはこちらを
14232使うようにした方がよいでしょう。
14233L<C<my>|/my VARLIST> を参照してください。
14234
142358224=item return EXPR
14236X<return>
142378225
142388226=item return
142398227
14240=for Pod::Functions get out of a function early
14241
142428228=begin original
142438229
14244Returns from a subroutine, L<C<eval>|/eval EXPR>,
8230Returns from a subroutine, C<eval>, or C<do FILE> with the value
14245L<C<do FILE>|/do EXPR>, L<C<sort>|/sort SUBNAME LIST> block or regex
14246eval block (but not a L<C<grep>|/grep BLOCK LIST> or
14247L<C<map>|/map BLOCK LIST> block) with the value
142488231given in EXPR. Evaluation of EXPR may be in list, scalar, or void
142498232context, depending on how the return value will be used, and the context
14250may vary from one execution to the next (see
8233may vary from one execution to the next (see C<wantarray>). If no EXPR
14251L<C<wantarray>|/wantarray>). If no EXPR
142528234is given, returns an empty list in list context, the undefined value in
14253scalar context, and (of course) nothing at all in void context.
8235scalar context, and (of course) nothing at all in a void context.
142548236
142558237=end original
142568238
14257サブルーチン, L<C<eval>|/eval EXPR>, L<C<do FILE>|/do EXPR>,
8239サブルーチン, C<eval>, C<do FILE> から EXPR で与えられた値をもって、
14258L<C<sort>|/sort SUBNAME LIST> ブロックたは正規表現 eval ブロック
8240リターンしす。
14259(但し L<C<grep>|/grep BLOCK LIST> や
8241EXPR の評価は、返り値がどのように使われるかによって
14260L<C<map>|/map BLOCK LIST> ブロックではい) から
8242リスト、スカラ、無効コンテキストにります。
14261EXPR で与えられ値をもって、リターます。
8243テキストは実行毎に変わります(C<wantarray> を参照してください)
14262EXPR の評価は、返り値がどのように使われるかによってリスト、スカラ、
14263無効コンテキストになります; またコンテキストは実行毎に変わります
14264(L<C<wantarray>|/wantarray> を参照してください)。
142658244EXPR が指定されなかった場合は、リストコンテキストでは空リストを、
14266スカラコンテキストでは未定義値を返します; そして(もちろん)
8245スカラコンテキストでは未定義値を返します
14267無効コンテキストでは何も返しません。
8246そして(もちろん)無効コンテキストでは何も返しません。
142688247
142698248=begin original
142708249
14271(In the absence of an explicit L<C<return>|/return EXPR>, a subroutine,
8250(Note that in the absence of a explicit C<return>, a subroutine, eval,
14272L<C<eval>|/eval EXPR>,
8251or do FILE will automatically return the value of the last expression
14273or L<C<do FILE>|/do EXPR> automatically returns the value of the last expression
142748252evaluated.)
142758253
142768254=end original
142778255
14278(サブルーチン, L<C<eval>|/eval EXPR>, L<C<do FILE>|/do EXPR> に明示的に
8256(サブルーチン, eval, do FILE に明示的に C<return> が
14279L<C<return>|/return EXPR> がなければ、最後に評価された値で、
8257なければ、最後に評価された値で、自動的にリターンします。)
14280自動的にリターンします。)
142818258
14282=begin original
14283
14284Unlike most named operators, this is also exempt from the
14285looks-like-a-function rule, so C<return ("foo")."bar"> will
14286cause C<"bar"> to be part of the argument to L<C<return>|/return EXPR>.
14287
14288=end original
14289
14290ほとんどの名前付き演算子と異なり、関数のように見えるものの規則からも
14291免れるので、C<return ("foo")."bar"> とすると C<"bar"> は
14292L<C<return>|/return EXPR> への引数の一部となります。
14293
142948259=item reverse LIST
14295X<reverse> X<rev> X<invert>
142968260
14297=for Pod::Functions flip a string or a list
14298
142998261=begin original
143008262
143018263In list context, returns a list value consisting of the elements
143028264of LIST in the opposite order. In scalar context, concatenates the
143038265elements of LIST and returns a string value with all characters
143048266in the opposite order.
143058267
143068268=end original
143078269
143088270リストコンテキストでは、LIST を構成する要素を逆順に並べた
143098271リスト値を返します。
143108272スカラコンテキストでは、LIST の要素を連結して、
143118273全ての文字を逆順にした文字列を返します。
143128274
14313 print join(", ", reverse "world", "Hello"); # Hello, world
8275 print reverse <>; # line tac, last line first
143148276
14315 print scalar reverse "dlrow ,", "olleH"; # Hello, world
8277 undef $/; # for efficiency of <>
8278 print scalar reverse <>; # character tac, last line tsrif
143168279
143178280=begin original
143188281
14319Used without arguments in scalar context, L<C<reverse>|/reverse LIST>
14320reverses L<C<$_>|perlvar/$_>.
14321
14322=end original
14323
14324スカラコンテキストで引数なしで使うと、L<C<reverse>|/reverse LIST> は
14325L<C<$_>|perlvar/$_> を逆順にします。
14326
14327 $_ = "dlrow ,olleH";
14328 print reverse; # No output, list context
14329 print scalar reverse; # Hello, world
14330
14331=begin original
14332
14333Note that reversing an array to itself (as in C<@a = reverse @a>) will
14334preserve non-existent elements whenever possible; i.e., for non-magical
14335arrays or for tied arrays with C<EXISTS> and C<DELETE> methods.
14336
14337=end original
14338
14339(C<@a = reverse @a> のように) 反転した配列を自分自身に代入すると、
14340存在しない要素は可能なら(つまりマジカルでない配列や
14341C<EXISTS> と C<DELETE> メソッドがある tie された配列)
14342いつでも保存されることに注意してください。
14343
14344=begin original
14345
143468282This operator is also handy for inverting a hash, although there are some
143478283caveats. If a value is duplicated in the original hash, only one of those
143488284can be represented as a key in the inverted hash. Also, this has to
143498285unwind one hash and build a whole new one, which may take some time
143508286on a large hash, such as from a DBM file.
143518287
143528288=end original
143538289
143548290この演算子はハッシュの逆順にするのにも便利ですが、いくつかの弱点があります。
143558291元のハッシュで値が重複していると、それらのうち一つだけが
143568292逆順になったハッシュのキーとして表現されます。
143578293また、これは一つのハッシュをほどいて完全に新しいハッシュを作るので、
143588294DBM ファイルからのような大きなハッシュでは少し時間がかかります。
143598295
14360 my %by_name = reverse %by_address; # Invert the hash
8296 %by_name = reverse %by_address; # Invert the hash
143618297
143628298=item rewinddir DIRHANDLE
14363X<rewinddir>
143648299
14365=for Pod::Functions reset directory handle
14366
143678300=begin original
143688301
143698302Sets the current position to the beginning of the directory for the
14370L<C<readdir>|/readdir DIRHANDLE> routine on DIRHANDLE.
8303C<readdir> routine on DIRHANDLE.
143718304
143728305=end original
143738306
14374DIRHANDLE に対する L<C<readdir>|/readdir DIRHANDLE> ルーチンの現在位置を
8307DIRHANDLE に対する C<readdir> ルーチンの現在位置を
143758308ディレクトリの最初に設定します。
143768309
14377=begin original
14378
14379Portability issues: L<perlport/rewinddir>.
14380
14381=end original
14382
14383移植性の問題: L<perlport/rewinddir>。
14384
143858310=item rindex STR,SUBSTR,POSITION
14386X<rindex>
143878311
143888312=item rindex STR,SUBSTR
143898313
14390=for Pod::Functions right-to-left substring search
14391
143928314=begin original
143938315
14394Works just like L<C<index>|/index STR,SUBSTR,POSITION> except that it
8316Works just like index() except that it returns the position of the LAST
14395returns the position of the I<last>
143968317occurrence of SUBSTR in STR. If POSITION is specified, returns the
14397last occurrence beginning at or before that position.
8318last occurrence at or before that position.
143988319
143998320=end original
144008321
14401STR 中で I<最後に> 見つかった SUBSTR の位置を返すことを除いて、
8322STR 中で最後に見つかった SUBSTR の位置を返すことを除いて、
14402L<C<index>|/index STR,SUBSTR,POSITION> と同じように動作します。
8323index() と同じように動作します。
14403POSITION を指定すると、その位置から始まるか、その位置より前の、
8324POSITION を指定すると、その位置より前の、最後の位置を返します。
14404最後の位置を返します。
144058325
144068326=item rmdir FILENAME
14407X<rmdir> X<rd> X<directory, remove>
144088327
144098328=item rmdir
144108329
14411=for Pod::Functions remove a directory
14412
144138330=begin original
144148331
14415Deletes the directory specified by FILENAME if that directory is
8332Deletes the directory specified by FILENAME if that directory is empty. If it
14416empty. If it succeeds it returns true; otherwise it returns false and
8333succeeds it returns true, otherwise it returns false and sets C<$!> (errno). If
14417sets L<C<$!>|perlvar/$!> (errno). If FILENAME is omitted, uses
8334FILENAME is omitted, uses C<$_>.
14418L<C<$_>|perlvar/$_>.
144198335
144208336=end original
144218337
144228338FILENAME で指定したディレクトリが空であれば、
144238339そのディレクトリを削除します。
14424成功時には真を返します; さもなければ偽を返して L<C<$!>|perlvar/$!> (errno) を
8340成功時には真を返し、失敗時には偽を返しC<$!> (errno) を設定します。
14425設定します。
8341FILENAMEを省略した場合には、C<$_> を使用します。
14426FILENAME を省略した場合には、L<C<$_>|perlvar/$_> を使用します。
144278342
14428=begin original
14429
14430To remove a directory tree recursively (C<rm -rf> on Unix) look at
14431the L<C<rmtree>|File::Path/rmtree( $dir )> function of the L<File::Path>
14432module.
14433
14434=end original
14435
14436ディレクトリツリーを再帰的に削除したい (Unix での C<rm -rf>) 場合、
14437L<File::Path> モジュールの L<C<rmtree>|File::Path/rmtree( $dir )> 関数を
14438参照してください。
14439
144408343=item s///
144418344
14442=for Pod::Functions replace a pattern with a string
14443
144448345=begin original
144458346
14446The substitution operator. See L<perlop/"Regexp Quote-Like Operators">.
8347The substitution operator. See L<perlop>.
144478348
144488349=end original
144498350
144508351置換演算子。
14451L<perlop/"Regexp Quote-Like Operators"> を参照してください。
8352L<perlop> を参照してください。
144528353
14453=item say FILEHANDLE LIST
14454X<say>
14455
14456=item say FILEHANDLE
14457
14458=item say LIST
14459
14460=item say
14461
14462=for Pod::Functions +say output a list to a filehandle, appending a newline
14463
14464=begin original
14465
14466Just like L<C<print>|/print FILEHANDLE LIST>, but implicitly appends a
14467newline. C<say LIST> is simply an abbreviation for
14468C<{ local $\ = "\n"; print LIST }>. To use FILEHANDLE without a LIST to
14469print the contents of L<C<$_>|perlvar/$_> to it, you must use a bareword
14470filehandle like C<FH>, not an indirect one like C<$fh>.
14471
14472=end original
14473
14474L<C<print>|/print FILEHANDLE LIST> と同様ですが、暗黙に改行が追加されます。
14475C<say LIST> は単に C<{ local $\ = "\n"; print LIST }> の省略形です。
14476L<C<$_>|perlvar/$_> の内容を表示するために LIST なしで FILEHANDLE を
14477使用するには、C<$fh> のような間接ファイルハンドルではなく、C<FH> のような
14478裸の単語のファイルハンドルを使わなければなりません。
14479
14480=begin original
14481
14482L<C<say>|/say FILEHANDLE LIST> is available only if the
14483L<C<"say"> feature|feature/The 'say' feature> is enabled or if it is
14484prefixed with C<CORE::>. The
14485L<C<"say"> feature|feature/The 'say' feature> is enabled automatically
14486with a C<use v5.10> (or higher) declaration in the current scope.
14487
14488=end original
14489
14490L<C<say>|/say FILEHANDLE LIST> は
14491L<C<"say"> 機能|feature/The 'say' feature> が有効か C<CORE::> が
14492前置されたときにのみ利用可能です。
14493L<C<"say"> 機能|feature/The 'say' feature> は現在のスコープで
14494C<use v5.10> (またはそれ以上) が宣言されると自動的に有効になります。
14495
144968354=item scalar EXPR
14497X<scalar> X<context>
144988355
14499=for Pod::Functions force a scalar context
14500
145018356=begin original
145028357
145038358Forces EXPR to be interpreted in scalar context and returns the value
145048359of EXPR.
145058360
145068361=end original
145078362
145088363EXPR を強制的にスカラコンテキストで解釈されるようにして、
145098364EXPR の値を返します。
145108365
14511 my @counts = ( scalar @a, scalar @b, scalar @c );
8366 @counts = ( scalar @a, scalar @b, scalar @c );
145128367
145138368=begin original
145148369
145158370There is no equivalent operator to force an expression to
145168371be interpolated in list context because in practice, this is never
145178372needed. If you really wanted to do so, however, you could use
145188373the construction C<@{[ (some expression) ]}>, but usually a simple
145198374C<(some expression)> suffices.
145208375
145218376=end original
145228377
14523式を強制的にリストコンテキストで解釈させるようにする演算子はありません;
8378式を強制的にリストコンテキストで解釈させるようにする演算子はありません
145248379理論的には不要だからです。
145258380それでも、もしそうしたいのなら、C<@{[ (some expression) ]}> という構造を
14526使えます; しかし、普通は単に C<(some expression)> とすれば十分です
8381使えます。
8382しかし、普通は単に C<(some expression)> とすれば十分です。
145278383
145288384=begin original
145298385
14530Because L<C<scalar>|/scalar EXPR> is a unary operator, if you
8386Because C<scalar> is unary operator, if you accidentally use for EXPR a
14531accidentally use a
8387parenthesized list, this behaves as a scalar comma expression, evaluating
14532parenthesized list for the EXPR, this behaves as a scalar comma expression,
8388all but the last element in void context and returning the final element
14533evaluating all but the last element in void context and returning the final
8389evaluated in scalar context. This is seldom what you want.
14534element evaluated in scalar context. This is seldom what you want.
145358390
145368391=end original
145378392
14538L<C<scalar>|/scalar EXPR> は単項演算子なので、EXPR として括弧でくくった
8393C<scalar> は単項演算子なので、EXPR として括弧でくくったリストを使った場合、
14539リストを使った場合、これはスカラカンマ表現として振舞い、最後以外の全ては
8394これはスカラカンマ表現として振舞い、最後以外の全ては無効コンテキストとして
14540無効コンテキストとして扱われ、最後の要素をスカラコンテキストとして扱った
8395扱われ、最後の要素をスカラコンテキストとして扱った結果が返されます。
14541結果が返されます。
145428396これがあなたの望むものであることはめったにないでしょう。
145438397
145448398=begin original
145458399
145468400The following single statement:
145478401
145488402=end original
145498403
14550以下のつの文は:
8404以下の 1 つの文は:
145518405
14552 print uc(scalar(foo(), $bar)), $baz;
8406 print uc(scalar(&foo,$bar)),$baz;
145538407
145548408=begin original
145558409
145568410is the moral equivalent of these two:
145578411
145588412=end original
145598413
14560以下のつの文と等価です。
8414以下の 2 つの文と等価です。
145618415
14562 foo();
8416 &foo;
14563 print(uc($bar), $baz);
8417 print(uc($bar),$baz);
145648418
145658419=begin original
145668420
14567See L<perlop> for more details on unary operators and the comma operator,
8421See L<perlop> for more details on unary operators and the comma operator.
14568and L<perldata> for details on evaluating a hash in scalar contex.
145698422
145708423=end original
145718424
14572単項演算子とカンマ演算子に関する詳細については L<perlop> を
8425単項演算子とカンマ演算子に関する詳細については L<perlop> を参照して下さい。
14573スカラコンテキストでのハッシュの評価に関する詳細については L<perldata> を
14574参照してください。
145758426
145768427=item seek FILEHANDLE,POSITION,WHENCE
14577X<seek> X<fseek> X<filehandle, position>
145788428
14579=for Pod::Functions reposition file pointer for random-access I/O
14580
145818429=begin original
145828430
14583Sets FILEHANDLE's position, just like the L<fseek(3)> call of C C<stdio>.
8431Sets FILEHANDLE's position, just like the C<fseek> call of C<stdio>.
145848432FILEHANDLE may be an expression whose value gives the name of the
14585filehandle. The values for WHENCE are C<0> to set the new position
8433filehandle. The values for WHENCE are C<0> to set the new position to
14586I<in bytes> to POSITION; C<1> to set it to the current position plus
8434POSITION, C<1> to set it to the current position plus POSITION, and
14587POSITION; and C<2> to set it to EOF plus POSITION, typically
8435C<2> to set it to EOF plus POSITION (typically negative). For WHENCE
14588negative. For WHENCE you may use the constants C<SEEK_SET>,
8436you may use the constants C<SEEK_SET>, C<SEEK_CUR>, and C<SEEK_END>
14589C<SEEK_CUR>, and C<SEEK_END> (start of the file, current position, end
8437(start of the file, current position, end of the file) from the Fcntl
14590of the file) from the L<Fcntl> module. Returns C<1> on success, false
8438module. Returns C<1> upon success, C<0> otherwise.
14591otherwise.
145928439
145938440=end original
145948441
14595C の C<stdio> ライブラリの L<fseek(3)> 関数のように、FILEHANDLE の
8442C<stdio> ライブラリの C<fseek> 関数のように、FILEHANDLE の
145968443ファイルポインタを任意の位置に設定します。
145978444FILEHANDLE は、実際のファイルハンドル名を与える式でもかまいません。
14598WHENCE の値が、C<0> ならば、新しい位置を I<バイト単位で> POSITION の位置へ
8445WHENCE の値が、C<0> ならば、
14599設定ます; C<1> ならば、現在位置から POSITION 加えた位置へ
8446い位置を POSITION の位置へ、C<1> ならば、現在位置から
14600設定します; C<2> ならば、EOF からPOSITION だけ加えた位置へ、新しい位置を
8447POSITION 加えた位置へ、C<2> ならば、EOF から POSITION
14601設定します。
8448だけ加えた位置へ、新しい位置を設定します。
14602この値には、L<Fcntl> モジュールで使われている C<SEEK_SET>、C<SEEK_CUR>、
8449この値には、Fcntl モジュールで使われている C<SEEK_SET>、
14603C<SEEK_END> (ファイルの先頭、現在位置、ファイルの最後)という定数を
8450C<SEEK_CUR>、C<SEEK_END>
14604使うこともできます。
8451(ファイルの先頭、現在位置、ファイルの最後)という定数を使うこともできます。
14605成功時には、C<1> を、失敗時にはそれ以外を返します。
8452成功時には、C<1> を、失敗時には C<0> を返します。
146068453
146078454=begin original
146088455
14609Note the emphasis on bytes: even if the filehandle has been set to operate
8456If you want to position file for C<sysread> or C<syswrite>, don't use
14610on characters (for example using the C<:encoding(UTF-8)> I/O layer), the
8457C<seek>--buffering makes its effect on the file's system position
14611L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
8458unpredictable and non-portable. Use C<sysseek> instead.
14612L<C<tell>|/tell FILEHANDLE>, and
14613L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>
14614family of functions use byte offsets, not character offsets,
14615because seeking to a character offset would be very slow in a UTF-8 file.
146168459
146178460=end original
146188461
14619バイト単位に対する注意: 例え(例えば C<:encoding(UTF-8)> I/O 使うなどて)
8462C<sysread> C<syswrite> のためにファイルの位置指定たい場合は、
14620ファイルハドルが文字単位で処理するように設定されていとしても、
8463C<seek> は使えません -- バッファグのめに動作は予測不能で
14621L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
8464移植性のないものになってしまいます。
14622L<C<tell>|/tell FILEHANDLE>,
8465代わりに C<sysseek> を使ってください。
14623L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> シリーズの関数は
14624文字オフセットではなくバイトオフセットを使います;
14625文字オフセットでシークするのは UTF-8 ファイルではとても遅いからです。
146268466
146278467=begin original
146288468
14629If you want to position the file for
14630L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> or
14631L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, don't use
14632L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, because buffering makes its
14633effect on the file's read-write position unpredictable and non-portable.
14634Use L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> instead.
14635
14636=end original
14637
14638L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> や
14639L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> のためにファイルの
14640位置を指定したい場合は、L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> は
14641使えません; なぜならバッファリングのためにファイルの読み込み位置は
14642動作は予測不能で移植性のないものになってしまいます。
14643代わりに L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> を使ってください。
14644
14645=begin original
14646
146478469Due to the rules and rigors of ANSI C, on some systems you have to do a
146488470seek whenever you switch between reading and writing. Amongst other
14649things, this may have the effect of calling stdio's L<clearerr(3)>.
8471things, this may have the effect of calling stdio's clearerr(3).
146508472A WHENCE of C<1> (C<SEEK_CUR>) is useful for not moving the file position:
146518473
146528474=end original
146538475
146548476ANSI C の規則と困難により、システムによっては読み込みと書き込みを
146558477切り替える度にシークしなければならない場合があります。
14656その他のことの中で、これは stdio の L<clearerr(3)> を呼び出す効果があります。
8478その他のことの中で、これは stdio の clearerr(3) を呼び出す効果があります。
146578479WHENCE の C<1> (C<SEEK_CUR>) が、ファイル位置を変えないので有用です:
146588480
14659 seek($fh, 0, 1);
8481 seek(TEST,0,1);
146608482
146618483=begin original
146628484
146638485This is also useful for applications emulating C<tail -f>. Once you hit
14664EOF on your read and then sleep for a while, you (probably) have to stick in a
8486EOF on your read, and then sleep for a while, you might have to stick in a
14665dummy L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> to reset things. The
8487seek() to reset things. The C<seek> doesn't change the current position,
14666L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> doesn't change the position,
146678488but it I<does> clear the end-of-file condition on the handle, so that the
14668next C<readline FILE> makes Perl try again to read something. (We hope.)
8489next C<< <FILE> >> makes Perl try again to read something. We hope.
146698490
146708491=end original
146718492
146728493これはアプリケーションで C<tail -f> をエミュレートするのにも有用です。
146738494一度読み込み時に EOF に到達すると、しばらくスリープし、
14674(おそらく) ダミーの L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> をすることで
8495seek() することでリセットする必要があります。
14675リセットする必要がありす。
8496C<seek> は現在の位置を変更しせんが、ハンドルの EOF 状態を
14676L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> は現在の位置変更しませんが、
8497I<クリアします> ので、次の C<< <FILE> >> で Perl 再び何か
14677ハンドルの EOF 状態をI<クリアします> ので、次の C<readline FILE> で Perl は
8498読み込もうとします
14678再び何かを読み込もうとします。(そのはずです。)
8499そのはずです。
146798500
146808501=begin original
146818502
14682If that doesn't work (some I/O implementations are particularly
8503If that doesn't work (some stdios are particularly cantankerous), then
14683cantankerous), you might need something like this:
8504you may need something more like this:
146848505
146858506=end original
146868507
14687これが動かない場合(特に意地の悪い I/O 実装もあります)、
8508これが動かない場合(特に意地の悪い stdio もあります)、
146888509以下のようなことをする必要があります:
146898510
146908511 for (;;) {
14691 for ($curpos = tell($fh); $_ = readline($fh);
8512 for ($curpos = tell(FILE); $_ = <FILE>;
14692 $curpos = tell($fh)) {
8513 $curpos = tell(FILE)) {
14693 # search for some stuff and put it into files
8514 # search for some stuff and put it into files
14694 }
8515 }
14695 sleep($for_a_while);
8516 sleep($for_a_while);
14696 seek($fh, $curpos, 0);
8517 seek(FILE, $curpos, 0);
146978518 }
146988519
146998520=item seekdir DIRHANDLE,POS
14700X<seekdir>
147018521
14702=for Pod::Functions reposition directory pointer
14703
147048522=begin original
147058523
14706Sets the current position for the L<C<readdir>|/readdir DIRHANDLE>
8524Sets the current position for the C<readdir> routine on DIRHANDLE. POS
14707routine on DIRHANDLE. POS must be a value returned by
8525must be a value returned by C<telldir>. Has the same caveats about
14708L<C<telldir>|/telldir DIRHANDLE>. L<C<seekdir>|/seekdir DIRHANDLE,POS>
8526possible directory compaction as the corresponding system library
14709also has the same caveats about possible directory compaction as the
8527routine.
14710corresponding system library routine.
147118528
147128529=end original
147138530
14714DIRHANDLE での L<C<readdir>|/readdir DIRHANDLE> ルーチンの現在位置を
8531DIRHANDLE での C<readdir> ルーチンの現在位置を設定します。
14715設定します。
8532POS は、C<telldir> が返値でなければなりません
14716POS はL<C<telldir>|/telldir DIRHANDLE> が返す値でなければなりません。
8533同名のシステムライブラリルーチンと同じく
14717L<C<seekdir>|/seekdir DIRHANDLE,POS> は同名のシステムライブラルーチンと
8534ディレクト縮小時の問題が考えられます。
14718同じく、ディレクトリ縮小時の問題が考えられます。
147198535
147208536=item select FILEHANDLE
14721X<select> X<filehandle, default>
147228537
147238538=item select
147248539
14725=for Pod::Functions reset default output or do I/O multiplexing
14726
147278540=begin original
147288541
14729Returns the currently selected filehandle. If FILEHANDLE is supplied,
8542Returns the currently selected filehandle. Sets the current default
14730sets the new current default filehandle for output. This has two
8543filehandle for output, if FILEHANDLE is supplied. This has two
14731effects: first, a L<C<write>|/write FILEHANDLE> or a L<C<print>|/print
8544effects: first, a C<write> or a C<print> without a filehandle will
14732FILEHANDLE LIST> without a filehandle
147338545default to this FILEHANDLE. Second, references to variables related to
14734output will refer to this output channel.
8546output will refer to this output channel. For example, if you have to
8547set the top of form format for more than one output channel, you might
8548do the following:
147358549
147368550=end original
147378551
147388552その時点で、選択されていたファイルハンドルを返します。
14739FILEHANDLE を指定した場合には、その値を出力のデフォルトファイルハンドルに
8553FILEHANDLE を指定した場合には、その値を出力のデフォルト
14740設定します。
8554ファイルハンドルに設定します。
14741これには、2 つの効果があります: まず、ファイルハンドルを指定しないで
8555これには、2 つの効果があります
14742L<C<write>|/write FILEHANDLE> や L<C<print>|/print FILEHANDLE LIST>
8556まず、ファイルハンドル指定しないで
14743行なった場合のデフォルトが、この FILEHANDLE になります。
8557C<write> や C<print> を行なった場合のデフォルトが、
14744もう一つは、出力関連の変数への参照は、この出力チャネルを
8558この FILEHANDLE になります。
14745参照するようになります。
8559もう一つは、出力関連の変数への参照は、
8560この出力チャネルを参照するようになります。
8561たとえば、複数の出力チャネルに対して、ページ先頭フォーマットを
8562設定しなければならないのであれば、
8563以下のようにしなければならないでしょう。
147468564
14747=begin original
14748
14749For example, to set the top-of-form format for more than one
14750output channel, you might do the following:
14751
14752=end original
14753
14754例えば、複数の出力チャネルに対して、ページ先頭フォーマットを
14755設定するには:
14756
147578565 select(REPORT1);
147588566 $^ = 'report1_top';
147598567 select(REPORT2);
147608568 $^ = 'report2_top';
147618569
147628570=begin original
147638571
147648572FILEHANDLE may be an expression whose value gives the name of the
147658573actual filehandle. Thus:
147668574
147678575=end original
147688576
14769FILEHANDLE は、実際のファイルハンドル名を示す式でもかまいません。
8577FILEHANDLE は、実際のファイルハンドルを示す式でもかまいません。
147708578つまり、以下のようなものです:
147718579
14772 my $oldfh = select(STDERR); $| = 1; select($oldfh);
8580 $oldfh = select(STDERR); $| = 1; select($oldfh);
147738581
147748582=begin original
147758583
147768584Some programmers may prefer to think of filehandles as objects with
147778585methods, preferring to write the last example as:
147788586
147798587=end original
147808588
14781ファイルハンドルはメソッドを持ったオブジェクトであると考えることを好む
8589ファイルハンドルはメソッドを持ったオブジェクトであると
14782プログラマもいるかもしれません; そのような場合のための最後の例は
8590考えることを好むプログラマもいるかもしれません
14783以下のようなものです:
8591そのような場合のための最後の例は以下のようなものです
147848592
8593 use IO::Handle;
147858594 STDERR->autoflush(1);
147868595
14787=begin original
14788
14789(Prior to Perl version 5.14, you have to C<use IO::Handle;> explicitly
14790first.)
14791
14792=end original
14793
14794(Perl バージョン 5.14 以前では、まず明示的に C<use IO::Handle;> とする
14795必要があります。)
14796
14797=begin original
14798
14799Portability issues: L<perlport/select>.
14800
14801=end original
14802
14803移植性の問題: L<perlport/select>。
14804
148058596=item select RBITS,WBITS,EBITS,TIMEOUT
14806X<select>
148078597
148088598=begin original
148098599
14810This calls the L<select(2)> syscall with the bit masks specified, which
8600This calls the select(2) system call with the bit masks specified, which
14811can be constructed using L<C<fileno>|/fileno FILEHANDLE> and
8601can be constructed using C<fileno> and C<vec>, along these lines:
14812L<C<vec>|/vec EXPR,OFFSET,BITS>, along these lines:
148138602
148148603=end original
148158604
14816これは、L<select(2)> システムコールを、指定したビットマスクで呼び出します;
8605これは、select(2) システムコールを、指定したビットマスクで呼び出します
14817ビットマスクは、L<C<fileno>|/fileno FILEHANDLE> と
8606ビットマスクは、C<fileno> と
14818L<C<vec>|/vec EXPR,OFFSET,BITS> を使って、以下のようにして作成できます:
8607C<vec> を使って、以下のようにして作成できます
148198608
14820 my $rin = my $win = my $ein = '';
8609 $rin = $win = $ein = '';
14821 vec($rin, fileno(STDIN), 1) = 1;
8610 vec($rin,fileno(STDIN),1) = 1;
14822 vec($win, fileno(STDOUT), 1) = 1;
8611 vec($win,fileno(STDOUT),1) = 1;
148238612 $ein = $rin | $win;
148248613
148258614=begin original
148268615
14827If you want to select on many filehandles, you may wish to write a
8616If you want to select on many filehandles you might wish to write a
14828subroutine like this:
8617subroutine:
148298618
148308619=end original
148318620
148328621複数のファイルハンドルに select を行ないたいのであれば、
14833以下のようにします:
8622以下のようにします
148348623
148358624 sub fhbits {
14836 my @fhlist = @_;
8625 my(@fhlist) = split(' ',$_[0]);
14837 my $bits = "";
8626 my($bits);
14838 for my $fh (@fhlist) {
8627 for (@fhlist) {
14839 vec($bits, fileno($fh), 1) = 1;
8628 vec($bits,fileno($_),1) = 1;
14840 }
8629 }
14841 return $bits;
8630 $bits;
148428631 }
14843 my $rin = fhbits(\*STDIN, $tty, $mysock);
8632 $rin = fhbits('STDIN TTY SOCK');
148448633
148458634=begin original
148468635
148478636The usual idiom is:
148488637
148498638=end original
148508639
148518640通常は、
148528641
14853 my ($nfound, $timeleft) =
8642 ($nfound,$timeleft) =
14854 select(my $rout = $rin, my $wout = $win, my $eout = $ein,
8643 select($rout=$rin, $wout=$win, $eout=$ein, $timeout);
14855 $timeout);
148568644
148578645=begin original
148588646
148598647or to block until something becomes ready just do this
148608648
148618649=end original
148628650
148638651のように使い、いずれかの準備が整うまでブロックするには、
148648652以下のようにします。
148658653
14866 my $nfound =
8654 $nfound = select($rout=$rin, $wout=$win, $eout=$ein, undef);
14867 select(my $rout = $rin, my $wout = $win, my $eout = $ein, undef);
148688655
148698656=begin original
148708657
14871Most systems do not bother to return anything useful in C<$timeleft>, so
8658Most systems do not bother to return anything useful in $timeleft, so
14872calling L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> in scalar context
8659calling select() in scalar context just returns $nfound.
14873just returns C<$nfound>.
148748660
148758661=end original
148768662
14877ほとんどのシステムではわざわざ意味のある値を C<$timeleft> に返さないので、
8663ほとんどのシステムではわざわざ意味のある値を $timeleft に返さないので、
14878L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> をスカラコンテキストで
8664select() をスカラコンテキストで呼び出すと、単に $nfound を返します。
14879呼び出すと、単に C<$nfound> を返します。
148808665
148818666=begin original
148828667
14883Any of the bit masks can also be L<C<undef>|/undef EXPR>. The timeout,
8668Any of the bit masks can also be undef. The timeout, if specified, is
14884if specified, is
148858669in seconds, which may be fractional. Note: not all implementations are
14886capable of returning the C<$timeleft>. If not, they always return
8670capable of returning the$timeleft. If not, they always return
14887C<$timeleft> equal to the supplied C<$timeout>.
8671$timeleft equal to the supplied $timeout.
148888672
148898673=end original
148908674
14891どのビットマスクにも L<C<undef>|/undef EXPR> を設定することができます。
8675どのビットマスクにも undef を設定することができます。
148928676TIMEOUT を指定するときは、秒数で指定し、小数でかまいません。
14893注: すべての実装で、C<$timeleft> が返せるものではありません。
8677注: すべての実装で、$timeleft が返せるものではありません。
14894その場合、C<$timeleft> には、常に指定した C<$timeout> と同じ値が返されます。
8678その場合、$timeleft には、常に指定した TIMEOUT と同じ値が返されます。
148958679
148968680=begin original
148978681
148988682You can effect a sleep of 250 milliseconds this way:
148998683
149008684=end original
149018685
149028686250 ミリ秒の sleep と同じ効果が、以下のようにして得られます。
149038687
149048688 select(undef, undef, undef, 0.25);
149058689
149068690=begin original
149078691
14908Note that whether L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> gets
8692B<WARNING>: One should not attempt to mix buffered I/O (like C<read>
14909restarted after signals (say, SIGALRM) is implementation-dependent. See
8693or <FH>) with C<select>, except as permitted by POSIX, and even
14910also L<perlport> for notes on the portability of
8694then only on POSIX systems. You have to use C<sysread> instead.
14911L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>.
149128695
149138696=end original
149148697
14915L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> がシグナル (例えば、SIGALRM) の
8698B<警告>: バッファ付き I/O (C<read> や <FH>) と C<select>
14916後に再起動するかどうかは実装依存であることに注意してください。
14917L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> の移植性に関する
14918注意については L<perlport> も参照してください。
14919
14920=begin original
14921
14922On error, L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> behaves just
14923like L<select(2)>: it returns C<-1> and sets L<C<$!>|perlvar/$!>.
14924
14925=end original
14926
14927エラー時は、L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> は
14928L<select(2)> のように振舞います:
14929C<-1> を返し、L<C<$!>|perlvar/$!> をセットします。
14930
14931=begin original
14932
14933On some Unixes, L<select(2)> may report a socket file descriptor as
14934"ready for reading" even when no data is available, and thus any
14935subsequent L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> would block.
14936This can be avoided if you always use C<O_NONBLOCK> on the socket. See
14937L<select(2)> and L<fcntl(2)> for further details.
14938
14939=end original
14940
14941Unix の中には、実際に利用可能なデータがないために引き続く
14942L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> が
14943ブロックされる場合でも、L<select(2)> が、ソケットファイル記述子が
14944「読み込み準備中」であると報告するものもあります。
14945これは、ソケットに対して常に C<O_NONBLOCK> フラグを使うことで回避できます。
14946さらなる詳細については L<select(2)> と L<fcntl(2)> を参照してください。
14947
14948=begin original
14949
14950The standard L<C<IO::Select>|IO::Select> module provides a
14951user-friendlier interface to
14952L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, mostly because it does
14953all the bit-mask work for you.
14954
14955=end original
14956
14957標準の L<C<IO::Select>|IO::Select> モジュールは
14958L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> へのよりユーザーフレンドリーな
14959インターフェースを提供します; 主な理由はビットマスクの仕事を
14960してくれることです。
14961
14962=begin original
14963
14964B<WARNING>: One should not attempt to mix buffered I/O (like
14965L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> or
14966L<C<readline>|/readline EXPR>) with
14967L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, except as permitted by
14968POSIX, and even then only on POSIX systems. You have to use
14969L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> instead.
14970
14971=end original
14972
14973B<警告>: バッファ付き I/O (L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> や
14974L<C<readline>|/readline EXPR>) と
14975L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を
149768699混ぜて使ってはいけません(例外: POSIX で認められている形で使い、
149778700POSIX システムでだけ動かす場合を除きます)。
14978代わりに L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>
8701代わりに C<sysread> を使わなければなりません。
14979使わなければなりません。
149808702
14981=begin original
14982
14983Portability issues: L<perlport/select>.
14984
14985=end original
14986
14987移植性の問題: L<perlport/select>。
14988
149898703=item semctl ID,SEMNUM,CMD,ARG
14990X<semctl>
149918704
14992=for Pod::Functions SysV semaphore control operations
14993
149948705=begin original
149958706
14996Calls the System V IPC function L<semctl(2)>. You'll probably have to say
8707Calls the System V IPC function C<semctl>. You'll probably have to say
149978708
14998=end original
14999
15000System V IPC 関数 L<semctl(2)> を呼び出します。
15001正しい定数定義を得るために、まず
15002
150038709 use IPC::SysV;
150048710
15005=begin original
15006
150078711first to get the correct constant definitions. If CMD is IPC_STAT or
15008GETALL, then ARG must be a variable that will hold the returned
8712GETALL, then ARG must be a variable which will hold the returned
15009semid_ds structure or semaphore value array. Returns like
8713semid_ds structure or semaphore value array. Returns like C<ioctl>:
15010L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>:
150118714the undefined value for error, "C<0 but true>" for zero, or the actual
150128715return value otherwise. The ARG must consist of a vector of native
150138716short integers, which may be created with C<pack("s!",(0)x$nsem)>.
15014See also L<perlipc/"SysV IPC"> and the documentation for
8717See also L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::Semaphore>
15015L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>.
8718documentation.
150168719
150178720=end original
150188721
15019と書くことが必要でょう
8722System V IPC 関数 C<semctl> を呼び出ます正しい定数定義を得るために、まず
8723
8724 use IPC::SysV;
8725
8726と宣言する必要があるでしょう。
150208727CMD が、IPC_STAT か GETALL のときには、ARG は、返される
150218728semid_ds 構造体か、セマフォ値の配列を納める変数でなければなりません。
15022L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同じように、エラー時には
8729C<ioctl> と同じように、エラー時には未定義値、
15023未定義値、ゼロのときは C<"0 だが真">、それ以外なら、その値そのものを返します。
8730ゼロのときは C<"0 だが真">、それ以外なら、その値そのものを返します。
15024ARG はネイティブな short int のベクターから成っていなければなりません; これは
8731ARG はネイティブな short int のベクターから成っていなければなりません
15025C<pack("s!",(0)x$nsem)> で作成できます。
8732これは C<pack("s!",(0)x$nsem)> で作成できます。
15026L<perlipc/"SysV IPC"> と、
8733L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::Semaphore> も参照してください。
15027L<C<IPC::SysV>|IPC::SysV>, L<C<IPC::Semaphore>|IPC::Semaphore> の文書も
15028参照してください。
150298734
15030=begin original
15031
15032Portability issues: L<perlport/semctl>.
15033
15034=end original
15035
15036移植性の問題: L<perlport/semctl>。
15037
150388735=item semget KEY,NSEMS,FLAGS
15039X<semget>
150408736
15041=for Pod::Functions get set of SysV semaphores
15042
150438737=begin original
150448738
15045Calls the System V IPC function L<semget(2)>. Returns the semaphore id, or
8739Calls the System V IPC function semget. Returns the semaphore id, or
15046the undefined value on error. See also
8740the undefined value if there is an error. See also
15047L<perlipc/"SysV IPC"> and the documentation for
8741L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Semaphore>
15048L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>.
8742documentation.
150498743
150508744=end original
150518745
15052System V IPC 関数 L<semget(2)> を呼び出します。
8746System V IPC 関数 semget を呼び出します。
150538747セマフォ ID か、エラー時には未定義値を返します。
15054L<perlipc/"SysV IPC"> と、L<C<IPC::SysV>|IPC::SysV>,
8748L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Semaphore>
15055L<C<IPC::Semaphore>|IPC::Semaphore> 文書も参照してください。
8749参照してください。
150568750
15057=begin original
15058
15059Portability issues: L<perlport/semget>.
15060
15061=end original
15062
15063移植性の問題: L<perlport/semget>。
15064
150658751=item semop KEY,OPSTRING
15066X<semop>
150678752
15068=for Pod::Functions SysV semaphore operations
15069
150708753=begin original
150718754
15072Calls the System V IPC function L<semop(2)> for semaphore operations
8755Calls the System V IPC function semop to perform semaphore operations
15073such as signalling and waiting. OPSTRING must be a packed array of
8756such as signaling and waiting. OPSTRING must be a packed array of
150748757semop structures. Each semop structure can be generated with
15075C<pack("s!3", $semnum, $semop, $semflag)>. The length of OPSTRING
8758C<pack("sss", $semnum, $semop, $semflag)>. The number of semaphore
15076implies the number of semaphore operations. Returns true if
8759operations is implied by the length of OPSTRING. Returns true if
15077successful, false on error. As an example, the
8760successful, or false if there is an error. As an example, the
150788761following code waits on semaphore $semnum of semaphore id $semid:
150798762
150808763=end original
150818764
150828765シグナルを送信や、待ち合わせなどのセマフォ操作を行なうために、
15083System V IPC 関数 L<semop(2)> を呼び出します。
8766System V IPC 関数 semop を呼び出します。
150848767OPSTRING は、semop 構造体の pack された配列でなければなりません。
15085semop 構造体は、それぞれ、C<pack("s!3", $semnum, $semop, $semflag)> のように
8768semop 構造体は、それぞれ、
15086作ることができます。
8769C<pack("sss", $semnum, $semop, $semflag)> のように作ることができます。
150878770セマフォ操作の数は、OPSTRING の長さからわかります。
150888771成功時には真を、エラー時には偽を返します。
150898772以下の例は、セマフォ ID $semid のセマフォ $semnum で
150908773待ち合わせを行ないます。
150918774
15092 my $semop = pack("s!3", $semnum, -1, 0);
8775 $semop = pack("sss", $semnum, -1, 0);
150938776 die "Semaphore trouble: $!\n" unless semop($semid, $semop);
150948777
150958778=begin original
150968779
150978780To signal the semaphore, replace C<-1> with C<1>. See also
15098L<perlipc/"SysV IPC"> and the documentation for
8781L<perlipc/"SysV IPC">, C<IPC::SysV>, and C<IPC::SysV::Semaphore>
15099L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>.
8782documentation.
151008783
151018784=end original
151028785
151038786セマフォにシグナルを送るには、C<-1> を C<1> に変更してください。
15104L<perlipc/"SysV IPC"> と L<C<IPC::SysV>|IPC::SysV>,
8787L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Semaphore>
15105L<C<IPC::Semaphore>|IPC::Semaphore> の文書も参照してください。
8788参照してください。
151068789
15107=begin original
15108
15109Portability issues: L<perlport/semop>.
15110
15111=end original
15112
15113移植性の問題: L<perlport/semop>。
15114
151158790=item send SOCKET,MSG,FLAGS,TO
15116X<send>
151178791
151188792=item send SOCKET,MSG,FLAGS
151198793
15120=for Pod::Functions send a message over a socket
15121
151228794=begin original
151238795
15124Sends a message on a socket. Attempts to send the scalar MSG to the SOCKET
8796Sends a message on a socket. Takes the same flags as the system call
15125filehandle. Takes the same flags as the system call of the same name. On
8797of the same name. On unconnected sockets you must specify a
15126unconnected sockets, you must specify a destination to I<send to>, in which
8798destination to send TO, in which case it does a C C<sendto>. Returns
15127case it does a L<sendto(2)> syscall. Returns the number of characters sent,
8799the number of characters sent, or the undefined value if there is an
15128or the undefined value on error. The L<sendmsg(2)> syscall is currently
8800error. The C system call sendmsg(2) is currently unimplemented.
15129unimplemented. See L<perlipc/"UDP: Message Passing"> for examples.
8801See L<perlipc/"UDP: Message Passing"> for examples.
151308802
151318803=end original
151328804
15133ソケットメッセージを送ります。
8805SOCKET MSG を送ります。
15134スカラ MSG を ファイルハンドル SOCKET送ろうとします。
8806FLAGS には、同名のシステムコール同じフラグを指定します。
15135同名のシステムコールと同じフラグが指定できます。
8807接続していないソケットには、送信先 TO を指定しなければならず、
15136接続していないソケットにはI<send to> に接続先指定なければならず、
8808この場合C の C<sendto> を実行ます。
15137この場合、L<sendto(2)> を実行します。
151388809送信した文字数か、エラー時には、未定義値を返します。
15139システムコール L<sendmsg(2)> は現在実装されていません。
8810C の システムコール sendmsg(2) は現在実装されていません。
151408811例については L<perlipc/"UDP: Message Passing"> を参照してください。
151418812
15142=begin original
15143
15144Note that if the socket has been marked as C<:utf8>, C<send> will
15145throw an exception. The C<:encoding(...)> layer implicitly introduces
15146the C<:utf8> layer. See L<C<binmode>|/binmode FILEHANDLE, LAYER>.
15147
15148=end original
15149
15150ソケットが C<:utf8> とマークされている場合、
15151C<send> は例外を投げることに注意してください。
15152C<:encoding(...)> 層は暗黙に C<:utf8> 層を導入します。
15153L<C<binmode>|/binmode FILEHANDLE, LAYER> を参照してください。
15154
151558813=item setpgrp PID,PGRP
15156X<setpgrp> X<group>
151578814
15158=for Pod::Functions set the process group of a process
15159
151608815=begin original
151618816
151628817Sets the current process group for the specified PID, C<0> for the current
15163process. Raises an exception when used on a machine that doesn't
8818process. Will produce a fatal error if used on a machine that doesn't
15164implement POSIX L<setpgid(2)> or BSD L<setpgrp(2)>. If the arguments
8819implement POSIX setpgid(2) or BSD setpgrp(2). If the arguments are omitted,
15165are omitted, it defaults to C<0,0>. Note that the BSD 4.2 version of
8820it defaults to C<0,0>. Note that the BSD 4.2 version of C<setpgrp> does not
15166L<C<setpgrp>|/setpgrp PID,PGRP> does not accept any arguments, so only
8821accept any arguments, so only C<setpgrp(0,0)> is portable. See also
15167C<setpgrp(0,0)> is portable. See also
8822C<POSIX::setsid()>.
15168L<C<POSIX::setsid()>|POSIX/C<setsid>>.
151698823
151708824=end original
151718825
151728826指定した PID (C<0> を指定するとカレントプロセス) に
151738827対するプロセスグループを設定します。
15174POSIX L<setpgrp(2)> または BSD L<setpgrp(2)> が実装されていないマシンでは、
8828POSIX setpgrp(2) または BSD setpgrp(2) が実装されていないマシンでは、
15175例外が発生します。
8829致命的エラーが発生します。
151768830引数が省略された場合は、C<0,0>が使われます。
15177BSD 4.2 版の L<C<setpgrp>|/setpgrp PID,PGRP> は引数を取ることができないので、
8831BSD 4.2 版の C<setpgrp> は引数を取ることができないので、
151788832C<setpgrp(0,0)> のみが移植性があることに注意してください。
15179L<C<POSIX::setsid()>|POSIX/C<setsid>> も参照してください。
8833C<POSIX::setsid()> も参照してください。
151808834
15181=begin original
15182
15183Portability issues: L<perlport/setpgrp>.
15184
15185=end original
15186
15187移植性の問題: L<perlport/setpgrp>。
15188
151898835=item setpriority WHICH,WHO,PRIORITY
15190X<setpriority> X<priority> X<nice> X<renice>
151918836
15192=for Pod::Functions set a process's nice value
15193
151948837=begin original
151958838
151968839Sets the current priority for a process, a process group, or a user.
15197(See L<setpriority(2)>.) Raises an exception when used on a machine
8840(See setpriority(2).) Will produce a fatal error if used on a machine
15198that doesn't implement L<setpriority(2)>.
8841that doesn't implement setpriority(2).
151998842
152008843=end original
152018844
152028845プロセス、プロセスグループ、ユーザに対する優先順位を設定します。
15203(L<setpriority(2)> を参照してください。)
8846(setpriority(2) を参照してください。)
15204L<setpriority(2)> が実装されていないマシンでは、例外が発生します。
8847setpriority(2) が実装されていないマシンでは、
8848致命的エラーが発生します。
152058849
15206=begin original
15207
15208C<WHICH> can be any of C<PRIO_PROCESS>, C<PRIO_PGRP> or C<PRIO_USER>
15209imported from L<POSIX/RESOURCE CONSTANTS>.
15210
15211=end original
15212
15213C<WHICH> は、L<POSIX/RESOURCE CONSTANTS> からインポートされた
15214C<PRIO_PROCESS>, C<PRIO_PGRP>, C<PRIO_USER> のいずれかです。
15215
15216=begin original
15217
15218Portability issues: L<perlport/setpriority>.
15219
15220=end original
15221
15222移植性の問題: L<perlport/setpriority>。
15223
152248850=item setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL
15225X<setsockopt>
152268851
15227=for Pod::Functions set some socket options
15228
152298852=begin original
152308853
15231Sets the socket option requested. Returns L<C<undef>|/undef EXPR> on
8854Sets the socket option requested. Returns undefined if there is an
15232error. Use integer constants provided by the L<C<Socket>|Socket> module
8855error. OPTVAL may be specified as C<undef> if you don't want to pass an
15233for
8856argument.
15234LEVEL and OPNAME. Values for LEVEL can also be obtained from
15235getprotobyname. OPTVAL might either be a packed string or an integer.
15236An integer OPTVAL is shorthand for pack("i", OPTVAL).
152378857
152388858=end original
152398859
152408860要求したソケットオプションを設定します。
15241エラー時には、L<C<undef>|/undef EXPR> をます。
8861エラー時には、未定義値がされます。
15242LEVEL と OPNAME L<C<Socket>|Socket> モジュールが提供
8862引数を渡したくない場合には、OPTVAL に C<undef> を指定しま
15243整数定数を使います。
15244LEVEL の値は getprotobyname から得ることもできます。
15245OPTVAL は pack された文字列か整数です。
15246整数の OPTVAL は pack("i", OPTVAL) の省略表現です。
152478863
15248=begin original
15249
15250An example disabling Nagle's algorithm on a socket:
15251
15252=end original
15253
15254ソケットに対する Nagle のアルゴリズムを無効にする例です:
15255
15256 use Socket qw(IPPROTO_TCP TCP_NODELAY);
15257 setsockopt($socket, IPPROTO_TCP, TCP_NODELAY, 1);
15258
15259=begin original
15260
15261Portability issues: L<perlport/setsockopt>.
15262
15263=end original
15264
15265移植性の問題: L<perlport/setsockopt>。
15266
152678864=item shift ARRAY
15268X<shift>
152698865
152708866=item shift
152718867
15272=for Pod::Functions remove the first element of an array, and return it
15273
152748868=begin original
152758869
152768870Shifts the first value of the array off and returns it, shortening the
152778871array by 1 and moving everything down. If there are no elements in the
152788872array, returns the undefined value. If ARRAY is omitted, shifts the
15279L<C<@_>|perlvar/@_> array within the lexical scope of subroutines and
8873C<@_> array within the lexical scope of subroutines and formats, and the
15280formats, and the L<C<@ARGV>|perlvar/@ARGV> array outside a subroutine
8874C<@ARGV> array at file scopes or within the lexical scopes established by
15281and also within the lexical scopes
8875the C<eval ''>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}>, and C<END {}>
15282established by the C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}>,
8876constructs.
15283C<UNITCHECK {}>, and C<END {}> constructs.
152848877
152858878=end original
152868879
15287配列の最初の値を取り出して、その値を返し、配列を一つ短くして、すべての要素を
8880配列の最初の値を取り出して、その値を返し、配列を一つ
15288前へずらします。
8881短くして、すべての要素を前へずらします。
152898882配列に要素がなければ、未定義値を返します。
15290ARRAY を省略すると、サブルーチンやフォーマットのレキシカルスコープでは
8883ARRAY を省略すると、
15291L<C<@_>|perlvar/@_> を、サブルーチンの外側、C<eval STRING>, C<BEGIN {}>,
8884サブルーチンやフォーマットレキシカルスコープ C<@_> を、
15292C<INIT {}>, C<CHECK {}>, C<UNITCHECK {}>, C<END {}> で作成され
8885ファイルスコープま
15293レキシカルスコープでは L<C<@ARGV>|perlvar/@ARGV> が用いられます。
8886C<eval ''>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}>, C<END {}>
8887で作成されたレキシカルスコープでは C<@ARGV> が用いられます。
152948888
152958889=begin original
152968890
15297Starting with Perl 5.14, an experimental feature allowed
8891See also C<unshift>, C<push>, and C<pop>. C<shift> and C<unshift> do the
15298L<C<shift>|/shift ARRAY> to take a
8892same thing to the left end of an array that C<pop> and C<push> do to the
15299scalar expression. This experiment has been deemed unsuccessful, and was
8893right end.
15300removed as of Perl 5.24.
153018894
153028895=end original
153038896
15304Perl 5.14 から、L<C<shift>|/shift ARRAY> がスカラ式を取ることが出来ると
8897C<unshift>、C<push>、C<pop> も参照してくださ
15305実験的機能がありました。
8898C<shift> と C<unshift> は、C<pop> と
15306実験は失敗と見されPerl 5.24 削除されした
8899C<push> が配列右端で行うことを左端行ない
153078900
15308=begin original
15309
15310See also L<C<unshift>|/unshift ARRAY,LIST>, L<C<push>|/push ARRAY,LIST>,
15311and L<C<pop>|/pop ARRAY>. L<C<shift>|/shift ARRAY> and
15312L<C<unshift>|/unshift ARRAY,LIST> do the same thing to the left end of
15313an array that L<C<pop>|/pop ARRAY> and L<C<push>|/push ARRAY,LIST> do to
15314the right end.
15315
15316=end original
15317
15318L<C<unshift>|/unshift ARRAY,LIST>、L<C<push>|/push ARRAY,LIST>、
15319L<C<pop>|/pop ARRAY> も参照してください。
15320L<C<shift>|/shift ARRAY> と L<C<unshift>|/unshift ARRAY,LIST> は、
15321L<C<pop>|/pop ARRAY> と L<C<push>|/push ARRAY,LIST> が配列の右端で
15322行なうことを、左端で行ないます。
15323
153248901=item shmctl ID,CMD,ARG
15325X<shmctl>
153268902
15327=for Pod::Functions SysV shared memory operations
15328
153298903=begin original
153308904
153318905Calls the System V IPC function shmctl. You'll probably have to say
153328906
15333=end original
15334
15335System V IPC 関数 shmctl を呼び出します。
15336正しい定数定義を得るために、まず
15337
153388907 use IPC::SysV;
153398908
15340=begin original
15341
153428909first to get the correct constant definitions. If CMD is C<IPC_STAT>,
15343then ARG must be a variable that will hold the returned C<shmid_ds>
8910then ARG must be a variable which will hold the returned C<shmid_ds>
15344structure. Returns like ioctl: L<C<undef>|/undef EXPR> for error; "C<0>
8911structure. Returns like ioctl: the undefined value for error, "C<0> but
15345but true" for zero; and the actual return value otherwise.
8912true" for zero, or the actual return value otherwise.
15346See also L<perlipc/"SysV IPC"> and the documentation for
8913See also L<perlipc/"SysV IPC"> and C<IPC::SysV> documentation.
15347L<C<IPC::SysV>|IPC::SysV>.
153488914
153498915=end original
153508916
15351と書くことが必要でょう
8917System V IPC 関数 shmctl を呼び出ます正しい定数定義を得るために、まず
8918
8919 use IPC::SysV;
8920
8921と宣言する必要があるでしょう。
153528922CMD が、C<IPC_STAT> ならば、ARG は、返される C<shmid_ds> 構造体を
153538923納める変数でなければなりません。
15354ioctl と同様です: エラー時には L<C<undef>|/undef EXPR>; ゼロのときは
8924ioctl と同じように、エラー時には未定義値、ゼロのときは "C<0> だが真"、
15355"C<0> だが真"; それ以外なら、その値そのものを返します。
8925それ以外なら、その値そのものを返します。
15356L<perlipc/"SysV IPC"> と L<C<IPC::SysV>|IPC::SysV> の文書も参照してください。
8926L<perlipc/"SysV IPC"> と C<IPC::SysV> も参照してください。
153578927
15358=begin original
15359
15360Portability issues: L<perlport/shmctl>.
15361
15362=end original
15363
15364移植性の問題: L<perlport/shmctl>。
15365
153668928=item shmget KEY,SIZE,FLAGS
15367X<shmget>
153688929
15369=for Pod::Functions get SysV shared memory segment identifier
15370
153718930=begin original
153728931
153738932Calls the System V IPC function shmget. Returns the shared memory
15374segment id, or L<C<undef>|/undef EXPR> on error.
8933segment id, or the undefined value if there is an error.
15375See also L<perlipc/"SysV IPC"> and the documentation for
8934See also L<perlipc/"SysV IPC"> and C<IPC::SysV> documentation.
15376L<C<IPC::SysV>|IPC::SysV>.
153778935
153788936=end original
153798937
153808938System V IPC 関数 shmget を呼び出します。
15381共有メモリのセグメント ID か、エラー時には L<C<undef>|/undef EXPR> を返します。
8939共有メモリのセグメント ID か、エラー時には未定義値を返します。
15382L<perlipc/"SysV IPC"> と L<C<IPC::SysV>|IPC::SysV> の文書も参照してください。
8940L<perlipc/"SysV IPC"> と C<IPC::SysV> も参照してください。
153838941
15384=begin original
15385
15386Portability issues: L<perlport/shmget>.
15387
15388=end original
15389
15390移植性の問題: L<perlport/shmget>。
15391
153928942=item shmread ID,VAR,POS,SIZE
15393X<shmread>
15394X<shmwrite>
153958943
15396=for Pod::Functions read SysV shared memory
15397
153988944=item shmwrite ID,STRING,POS,SIZE
153998945
15400=for Pod::Functions write SysV shared memory
15401
154028946=begin original
154038947
154048948Reads or writes the System V shared memory segment ID starting at
154058949position POS for size SIZE by attaching to it, copying in/out, and
154068950detaching from it. When reading, VAR must be a variable that will
154078951hold the data read. When writing, if STRING is too long, only SIZE
154088952bytes are used; if STRING is too short, nulls are written to fill out
15409SIZE bytes. Return true if successful, false on error.
8953SIZE bytes. Return true if successful, or false if there is an error.
15410L<C<shmread>|/shmread ID,VAR,POS,SIZE> taints the variable. See also
8954shmread() taints the variable. See also L<perlipc/"SysV IPC">,
15411L<perlipc/"SysV IPC"> and the documentation for
8955C<IPC::SysV> documentation, and the C<IPC::Shareable> module from CPAN.
15412L<C<IPC::SysV>|IPC::SysV> and the L<C<IPC::Shareable>|IPC::Shareable>
15413module from CPAN.
154148956
154158957=end original
154168958
15417System V 共有メモリセグメント ID に対し、アタッチして、コピーを行ない、
8959System V 共有メモリセグメント ID に対し、アタッチして、
15418デタッチするという形で、位置 POS から、サイズ SIZE だけ、読み込みか書き込みを
8960コピーを行ない、デタッチするという形で、位置 POS から、
15419行ないます。
8961サイズ SIZE だけ、読み込みか書き込みを行ないます。
15420読み込み時には、VAR は読み込んだデータを納める変数でなければなりません。
8962読み込み時には、VAR は読み込んだデータを納める
15421書き込み時には、STRING が長すぎても、SIZE バイトだが使われます; STRING が
8963変数でなければなりせん。
15422短すぎる場合には、SIZE バイトを埋めるために、ヌル文字書き込まれます。
8964書き込み時には、STRING が長すぎても、SIZE バイトだけ使われます。
8965STRING が短すぎる場合には、SIZE バイトを埋めるために、
8966ヌル文字が書き込まれます。
154238967成功時には真を、エラー時には偽を返します。
15424L<C<shmread>|/shmread ID,VAR,POS,SIZE> は変数を汚染します。
8968shmread() は変数を汚染します。
15425L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV> と CPAN
8969L<perlipc/"SysV IPC"> C<IPC::SysV> の文章と、
15426L<C<IPC::Shareable>|IPC::Shareable> の文書も参照してください。
8970CPAN の C<IPC::Shareable> も参照してください。
154278971
15428=begin original
15429
15430Portability issues: L<perlport/shmread> and L<perlport/shmwrite>.
15431
15432=end original
15433
15434移植性の問題: L<perlport/shmread> と L<perlport/shmwrite>。
15435
154368972=item shutdown SOCKET,HOW
15437X<shutdown>
154388973
15439=for Pod::Functions close down just half of a socket connection
15440
154418974=begin original
154428975
154438976Shuts down a socket connection in the manner indicated by HOW, which
15444has the same interpretation as in the syscall of the same name.
8977has the same interpretation as in the system call of the same name.
154458978
154468979=end original
154478980
154488981同名のシステムコールと同じように解釈される HOW によって、
154498982指定された方法でソケット接続のシャットダウンを行ないます。
154508983
15451 shutdown($socket, 0); # I/we have stopped reading data
8984 shutdown(SOCKET, 0); # I/we have stopped reading data
15452 shutdown($socket, 1); # I/we have stopped writing data
8985 shutdown(SOCKET, 1); # I/we have stopped writing data
15453 shutdown($socket, 2); # I/we have stopped using this socket
8986 shutdown(SOCKET, 2); # I/we have stopped using this socket
154548987
154558988=begin original
154568989
154578990This is useful with sockets when you want to tell the other
154588991side you're done writing but not done reading, or vice versa.
15459It's also a more insistent form of close because it also
8992It's also a more insistent form of close because it also
154608993disables the file descriptor in any forked copies in other
154618994processes.
154628995
154638996=end original
154648997
154658998これは、こちらがソケットを書き終わったが読み終わっていない、
154668999またはその逆を相手側に伝えたいときに便利です。
154679000これはその他のプロセスでフォークしたファイル記述子のコピーも
154689001無効にするので、よりしつこい閉じ方です。
154699002
15470=begin original
15471
15472Returns C<1> for success; on error, returns L<C<undef>|/undef EXPR> if
15473the first argument is not a valid filehandle, or returns C<0> and sets
15474L<C<$!>|perlvar/$!> for any other failure.
15475
15476=end original
15477
15478成功時には C<1> を返します;
15479エラーの場合、最初の引数が有効なファイルハンドルでない場合は
15480L<C<undef>|/undef EXPR> を返し、その他のエラーの場合は C<0> を返して
15481L<C<$!>|perlvar/$!> をセットします。
15482
154839003=item sin EXPR
15484X<sin> X<sine> X<asin> X<arcsine>
154859004
154869005=item sin
154879006
15488=for Pod::Functions return the sine of a number
15489
154909007=begin original
154919008
154929009Returns the sine of EXPR (expressed in radians). If EXPR is omitted,
15493returns sine of L<C<$_>|perlvar/$_>.
9010returns sine of C<$_>.
154949011
154959012=end original
154969013
154979014(ラジアンで示した) EXPR の正弦を返します。
15498EXPR が省略されたときには、L<C<$_>|perlvar/$_> の正弦を返します。
9015EXPR が省略されたときには、C<$_> の正弦を返します。
154999016
155009017=begin original
155019018
155029019For the inverse sine operation, you may use the C<Math::Trig::asin>
155039020function, or use this relation:
155049021
155059022=end original
155069023
155079024逆正弦を求めるためには、C<Math::Trig::asin> 関数を使うか、
155089025以下の関係を使ってください:
155099026
155109027 sub asin { atan2($_[0], sqrt(1 - $_[0] * $_[0])) }
155119028
155129029=item sleep EXPR
15513X<sleep> X<pause>
155149030
155159031=item sleep
155169032
15517=for Pod::Functions block for some number of seconds
15518
155199033=begin original
155209034
15521Causes the script to sleep for (integer) EXPR seconds, or forever if no
9035Causes the script to sleep for EXPR seconds, or forever if no EXPR.
15522argument is given. Returns the integer number of seconds actually slept.
9036May be interrupted if the process receives a signal such as C<SIGALRM>.
9037Returns the number of seconds actually slept. You probably cannot
9038mix C<alarm> and C<sleep> calls, because C<sleep> is often implemented
9039using C<alarm>.
155239040
155249041=end original
155259042
15526スクリプトを(整数の) EXPR で指定した秒数 (省略時には、永久に)
9043スクリプトを EXPR で指定した秒数 (省略時には、永久に)
155279044スリープさせます。
15528実際にスリーした秒数返します。
9045そのロセスには、C<SIGALRM>のようなシグナル
9046受信すると、割り込みがかかります。
9047実際にスリープした秒数を返します。C<sleep> は、C<alarm> を
9048使って実装されることが多いので、C<alarm> と
9049C<sleep> は、おそらく混ぜて使用することはできません。
155299050
155309051=begin original
155319052
15532May be interrupted if the process receives a signal such as C<SIGALRM>.
15533
15534=end original
15535
15536そのプロセスが C<SIGALRM>のようなシグナルを受信すると、
15537割り込みがかかります。
15538
15539 eval {
15540 local $SIG{ALRM} = sub { die "Alarm!\n" };
15541 sleep;
15542 };
15543 die $@ unless $@ eq "Alarm!\n";
15544
15545=begin original
15546
15547You probably cannot mix L<C<alarm>|/alarm SECONDS> and
15548L<C<sleep>|/sleep EXPR> calls, because L<C<sleep>|/sleep EXPR> is often
15549implemented using L<C<alarm>|/alarm SECONDS>.
15550
15551=end original
15552
15553L<C<sleep>|/sleep EXPR> は、L<C<alarm>|/alarm SECONDS> を使って
15554実装されることが多いので、L<C<alarm>|/alarm SECONDS> と
15555L<C<sleep>|/sleep EXPR> は、混ぜて使用することはおそらくできません。
15556
15557=begin original
15558
155599053On some older systems, it may sleep up to a full second less than what
155609054you requested, depending on how it counts seconds. Most modern systems
155619055always sleep the full amount. They may appear to sleep longer than that,
155629056however, because your process might not be scheduled right away in a
155639057busy multitasking system.
155649058
155659059=end original
155669060
155679061古いシステムでは、どのように秒を数えるかによって、要求した秒数に完全に
155689062満たないうちに、スリープから抜ける場合があります。
155699063最近のシステムでは、常に完全にスリープします。
155709064しかし、負荷の高いマルチタスクシステムでは
155719065正しくスケジューリングされないがために
155729066より長い時間スリープすることがあります。
155739067
155749068=begin original
155759069
15576For delays of finer granularity than one second, the L<Time::HiRes>
9070For delays of finer granularity than one second, you may use Perl's
15577module (from CPAN, and starting from Perl 5.8 part of the standard
9071C<syscall> interface to access setitimer(2) if your system supports
15578distribution) provides L<C<usleep>|Time::HiRes/usleep ( $useconds )>.
9072it, or else see L</select> above. The Time::HiRes module from CPAN
15579You may also use Perl's four-argument
9073may also help.
15580version of L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> leaving the
15581first three arguments undefined, or you might be able to use the
15582L<C<syscall>|/syscall NUMBER, LIST> interface to access L<setitimer(2)>
15583if your system supports it. See L<perlfaq8> for details.
155849074
155859075=end original
155869076
155871 秒より精度の高いスリープを行なうには、L<Time::HiRes> モジュール(CPAN から、
90771 秒より精度の高いスリープを行なうには、
15588また Perl 5.8 からは標準配布されています) が
9078setitimer(2) をサポートしているシステムでは、Perl
15589L<C<usleep>|Time::HiRes/usleep ( $useconds )> を提供しま
9079C<syscall> インタフェース使ってアクセスるか、
15590Perl 4 引数版 L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を最初の
9080さもなければ上述の L</select> を参照してください。
155913 引数を未定義にして使うか、L<setitimer(2)> をサポトしているシステムは、
9081CPAN の Time::HiRes モジュルも有用しょう。
15592Perl の L<C<syscall>|/syscall NUMBER, LIST> インタフェースを使って
15593アクセスすることもできます。
15594詳しくは L<perlfaq8> を参照してください。
155959082
155969083=begin original
155979084
15598See also the L<POSIX> module's L<C<pause>|POSIX/C<pause>> function.
9085See also the POSIX module's C<pause> function.
155999086
156009087=end original
156019088
15602L<POSIX> モジュールの L<C<pause>|POSIX/C<pause>> 関数も参照してください。
9089POSIX モジュールの C<pause> 関数も参照してさい。
156039090
156049091=item socket SOCKET,DOMAIN,TYPE,PROTOCOL
15605X<socket>
156069092
15607=for Pod::Functions create a socket
15608
156099093=begin original
156109094
156119095Opens a socket of the specified kind and attaches it to filehandle
156129096SOCKET. DOMAIN, TYPE, and PROTOCOL are specified the same as for
15613the syscall of the same name. You should C<use Socket> first
9097the system call of the same name. You should C<use Socket> first
156149098to get the proper definitions imported. See the examples in
156159099L<perlipc/"Sockets: Client/Server Communication">.
156169100
156179101=end original
156189102
15619指定した種類のソケットをオープンし、ファイルハンドル SOCKET にアタッチします。
9103指定した種類のソケットをオープンし、ファイルハンドル
15620DOMAIN, TYPE, PROTOCOL は、同名のシステムコールと同じよう指定します。
9104SOCKET にアタッチします。
15621適切な定義を import するためにまず、C<use Socket> とするとよいでしょう。
9105DOMAINTYPEPROTOCOL は、
15622L<perlipc/"Sockets: Client/Server Communication"> 例を参照てください
9106同名システムコールと同じように指定ます
9107適切な定義を import するために、まず、C<use Socket> と
9108するとよいでしょう。
9109例については L<perlipc/"Sockets: Client/Server Communication"> を
9110参照してください。
156239111
156249112=begin original
156259113
156269114On systems that support a close-on-exec flag on files, the flag will
156279115be set for the newly opened file descriptor, as determined by the
15628value of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>.
9116value of $^F. See L<perlvar/$^F>.
156299117
156309118=end original
156319119
156329120ファイルに対する close-on-exec フラグをサポートしているシステムでは、
15633フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた
9121フラグは$^F の値で決定される、新しくオープンされたファイル記述子に対して
15634ファイル記述子に対してセットされます。
9122セットされます。
15635L<perlvar/$^F> を参照してください。
9123L<perlvar/$^F>を参照してください。
156369124
156379125=item socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL
15638X<socketpair>
156399126
15640=for Pod::Functions create a pair of sockets
15641
156429127=begin original
156439128
156449129Creates an unnamed pair of sockets in the specified domain, of the
156459130specified type. DOMAIN, TYPE, and PROTOCOL are specified the same as
15646for the syscall of the same name. If unimplemented, raises an exception.
9131for the system call of the same name. If unimplemented, yields a fatal
15647Returns true if successful.
9132error. Returns true if successful.
156489133
156499134=end original
156509135
156519136指定した DOMAIN に、指定した TYPE で名前の無いソケットのペアを生成します。
15652DOMAIN, TYPE, PROTOCOL は、同名のシステムコールと同じように指定します。
9137DOMAINTYPEPROTOCOL は、同名のシステムコールと同じように指定します。
15653実装されていない場合には、例外が発生します。
9138実装されていない場合には、致命的エラーとなります。
156549139成功時には真を返します。
156559140
156569141=begin original
156579142
156589143On systems that support a close-on-exec flag on files, the flag will
156599144be set for the newly opened file descriptors, as determined by the value
15660of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>.
9145of $^F. See L<perlvar/$^F>.
156619146
156629147=end original
156639148
156649149ファイルに対する close-on-exec フラグをサポートしているシステムでは、
15665フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた
9150フラグは$^F の値で決定される、新しくオープンされたファイル記述子に対して
15666ファイル記述子に対してセットされます。
9151セットされます。
156679152L<perlvar/$^F> を参照してください。
156689153
156699154=begin original
156709155
15671Some systems define L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> in terms of
9156Some systems defined C<pipe> in terms of C<socketpair>, in which a call
15672L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL>, in
9157to C<pipe(Rdr, Wtr)> is essentially:
15673which a call to C<pipe($rdr, $wtr)> is essentially:
156749158
156759159=end original
156769160
15677L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> を
9161C<pipe> を C<socketpair> を使って定義しているシステムもあります;
15678L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL> を使って
9162C<pipe(Rdr, Wtr)> は本質的には以下のようになります:
15679定義しているシステムもあります;
15680C<pipe($rdr, $wtr)> は本質的には以下のようになります:
156819163
156829164 use Socket;
15683 socketpair(my $rdr, my $wtr, AF_UNIX, SOCK_STREAM, PF_UNSPEC);
9165 socketpair(Rdr, Wtr, AF_UNIX, SOCK_STREAM, PF_UNSPEC);
15684 shutdown($rdr, 1); # no more writing for reader
9166 shutdown(Rdr, 1); # no more writing for reader
15685 shutdown($wtr, 0); # no more reading for writer
9167 shutdown(Wtr, 0); # no more reading for writer
156869168
156879169=begin original
156889170
15689See L<perlipc> for an example of socketpair use. Perl 5.8 and later will
9171See L<perlipc> for an example of socketpair use.
15690emulate socketpair using IP sockets to localhost if your system implements
15691sockets but not socketpair.
156929172
156939173=end original
156949174
156959175socketpair の使用例については L<perlipc> を参照してください。
15696Perl 5.8 以降では、システムがソケットを実装しているが socketpair を
15697実装していない場合、localhost に対して IP ソケットを使うことで
15698socketpair をエミュレートします。
156999176
15700=begin original
15701
15702Portability issues: L<perlport/socketpair>.
15703
15704=end original
15705
15706移植性の問題: L<perlport/socketpair>。
15707
157089177=item sort SUBNAME LIST
15709X<sort>
157109178
157119179=item sort BLOCK LIST
157129180
157139181=item sort LIST
157149182
15715=for Pod::Functions sort a list of values
15716
157179183=begin original
157189184
15719In list context, this sorts the LIST and returns the sorted list value.
9185Sorts the LIST and returns the sorted list value. If SUBNAME or BLOCK
15720In scalar context, the behaviour of L<C<sort>|/sort SUBNAME LIST> is
9186is omitted, C<sort>s in standard string comparison order. If SUBNAME is
15721undefined.
9187specified, it gives the name of a subroutine that returns an integer
9188less than, equal to, or greater than C<0>, depending on how the elements
9189of the list are to be ordered. (The C<< <=> >> and C<cmp>
9190operators are extremely useful in such routines.) SUBNAME may be a
9191scalar variable name (unsubscripted), in which case the value provides
9192the name of (or a reference to) the actual subroutine to use. In place
9193of a SUBNAME, you can provide a BLOCK as an anonymous, in-line sort
9194subroutine.
157229195
157239196=end original
157249197
15725リストコンテキストでは、LIST をソートし、ソートされたリスト値を返します。
9198LIST をソートし、ソートされたリスト値を返します。
15726スカラコンテキストでは、L<C<sort>|/sort SUBNAME LIST> の振舞いは未定義す。
9199SUBNAME や BLOCK を省略すと、標準の文字列比較の順番ソートが
9200行なわれます。
15728=begin original
9201SUBNAME を指定すると、それは、リストの
9202要素をどのような順番に並べるかに応じて、負、ゼロ、正の整数を返す
15730If SUBNAME or BLOCK is omitted, L<C<sort>|/sort SUBNAME LIST>s in
9203サブルーチンの名前であると解釈されます。
15731standard string comparison
9204(このようなルーチンには、C<< <=> >> 演算子や cmp 演算子が、
15732order. If SUBNAME is specified, it gives the name of a subroutine
15733that returns an integer less than, equal to, or greater than C<0>,
15734depending on how the elements of the list are to be ordered. (The
15735C<< <=> >> and C<cmp> operators are extremely useful in such routines.)
15736SUBNAME may be a scalar variable name (unsubscripted), in which case
15737the value provides the name of (or a reference to) the actual
15738subroutine to use. In place of a SUBNAME, you can provide a BLOCK as
15739an anonymous, in-line sort subroutine.
15740
15741=end original
15742
15743SUBNAME や BLOCK を省略すると、L<C<sort>|/sort SUBNAME LIST> は標準の
15744文字列比較の順番で行なわれます。
15745SUBNAME を指定すると、それは、リストの要素をどのような順番に並べるかに
15746応じて、負の整数、C<0>、正の整数を返すサブルーチンの名前であると解釈されます。
15747(このようなルーチンには、C<< <=> >> 演算子や C<cmp> 演算子が、
157489205たいへん便利です。)
15749SUBNAME は、スカラ変数名(添字なし)でもよく、その場合には、その値が使用する
9206SUBNAME は、スカラ変数名(添字なし)でもよく、
15750実際のサブルーチンの名前(またはそのリファレンス)と解釈されます。
9207その場合には、その値が使用する実際のサブルーチンの
15751SUBNAME の代わりに、無名のラインソートルーチンして、BLOCK を
9208前(またはそリファレス)解釈されます。
15752書くことができます。
9209SUBNAME の代わりに、無名のインライン
9210ソートルーチンとして、BLOCK を書くことができます。
157539211
157549212=begin original
157559213
15756If the subroutine's prototype is C<($$)>, the elements to be compared are
9214If the subroutine's prototype is C<($$)>, the elements to be compared
15757passed by reference in L<C<@_>|perlvar/@_>, as for a normal subroutine.
9215are passed by reference in C<@_>, as for a normal subroutine. This is
15758This is slower than unprototyped subroutines, where the elements to be
9216slower than unprototyped subroutines, where the elements to be
15759compared are passed into the subroutine as the package global variables
9217compared are passed into the subroutine
15760C<$a> and C<$b> (see example below).
9218as the package global variables $a and $b (see example below). Note that
9219in the latter case, it is usually counter-productive to declare $a and
9220$b as lexicals.
157619221
157629222=end original
157639223
15764サブルーチンのプロトタイプが C<($$)>の場合、比較する要素は通常のサブルーチンと
9224サブルーチンのプロトタイプが C<($$)>の場合、
15765同じように L<C<@_>|perlvar/@_> の中にリファレンスとして渡されます。
9225比較する要素は通常のサブルーチンと同じように C<@_> の中に
15766これはプロトタイプなしのサブルーチより遅いで; この場合は比較のため
9226リファレスとして渡されま
15767サブルーチンに渡される二つの要素は、パッケージのグローバル変数 C<$a> と
9227これはプロトタイプなしのサブルーチンより遅いです。
15768C<$b> で渡されます(次例を参照してください)。
9228この場合は比較のためサブルーチンに渡される 2 つ
9229要素は、パッケージのグローバル変数 $a と $b で渡されます
9230(次の例を参照してください)。
9231後者の場合、レキシカルに $a と $b を宣言するのは普通逆効果になります。
157699232
157709233=begin original
157719234
15772If the subroutine is an XSUB, the elements to be compared are pushed on
9235In either case, the subroutine may not be recursive. The values to be
15773to the stack, the way arguments are usually passed to XSUBs. C<$a> and
9236compared are always passed by reference, so don't modify them.
15774C<$b> are not set.
157759237
157769238=end original
157779239
15778サブルーチンが XSUB の場合、比較される要素、普通に引数を XSUB に渡す形
9240どちらの場合でも、サブルーチンは再帰的あってはなりません。
15779タックプッシュされます
9241$a や $b はリファレンスによって渡されるので、変更しないでください
15780C<$a> と C<$b> は設定されません。
157819242
157829243=begin original
157839244
15784The values to be compared are always passed by reference and should not
15785be modified.
15786
15787=end original
15788
15789比較される値はリファレンスによって渡されるので、変更するべきではありません。
15790
15791=begin original
15792
157939245You also cannot exit out of the sort block or subroutine using any of the
15794loop control operators described in L<perlsyn> or with
9246loop control operators described in L<perlsyn> or with C<goto>.
15795L<C<goto>|/goto LABEL>.
157969247
157979248=end original
157989249
157999250また、ソートブロックやサブルーチンから L<perlsyn> で説明されている
15800ループ制御子や L<C<goto>|/goto LABEL> を使って抜けてはいけません。
9251ループ制御子や C<goto> を使って抜けてはいけません。
158019252
158029253=begin original
158039254
15804When L<C<use locale>|locale> (but not C<use locale ':not_characters'>)
9255When C<use locale> is in effect, C<sort LIST> sorts LIST according to the
15805is in effect, C<sort LIST> sorts LIST according to the
158069256current collation locale. See L<perllocale>.
158079257
158089258=end original
158099259
15810L<C<use locale>|locale> が有効(そして C<use locale ':not_characters'>
9260C<use locale> が有効の場合、C<sort LIST> は LIST を現在の比較ロケールに
15811有効でない)の場合、C<sort LIST> は LIST 現在の比較ロケールに従っ
9261従ってソートします。L<perllocale> を参照し下さい。
15812ソートします。
15813L<perllocale> を参照してください。
158149262
158159263=begin original
158169264
15817L<C<sort>|/sort SUBNAME LIST> returns aliases into the original list,
15818much as a for loop's index variable aliases the list elements. That is,
15819modifying an element of a list returned by L<C<sort>|/sort SUBNAME LIST>
15820(for example, in a C<foreach>, L<C<map>|/map BLOCK LIST> or
15821L<C<grep>|/grep BLOCK LIST>)
15822actually modifies the element in the original list. This is usually
15823something to be avoided when writing clear code.
15824
15825=end original
15826
15827L<C<sort>|/sort SUBNAME LIST> は元のリストへのエイリアスを返します;
15828for ループのインデックス変数がリスト要素へのエイリアスと同様です。
15829つまり、L<C<sort>|/sort SUBNAME LIST> で返されるリストの要素を(例えば、
15830C<foreach> や L<C<map>|/map BLOCK LIST> や
15831L<C<grep>|/grep BLOCK LIST> で)変更すると、実際に元のリストの要素が
15832変更されます。
15833これはきれいなコードを書くときには普通は回避されます。
15834
15835=begin original
15836
15837Historically Perl has varied in whether sorting is stable by default.
15838If stability matters, it can be controlled explicitly by using the
15839L<sort> pragma.
15840
15841=end original
15842
15843歴史的には、ソートがデフォルトで安定かどうかは様々です。
15844安定性が問題になる場合は、L<sort> プラグマを使うことで明示的に制御できます。
15845
15846=begin original
15847
158489265Examples:
158499266
158509267=end original
158519268
158529269例:
158539270
158549271 # sort lexically
15855 my @articles = sort @files;
9272 @articles = sort @files;
158569273
158579274 # same thing, but with explicit sort routine
15858 my @articles = sort {$a cmp $b} @files;
9275 @articles = sort {$a cmp $b} @files;
158599276
158609277 # now case-insensitively
15861 my @articles = sort {fc($a) cmp fc($b)} @files;
9278 @articles = sort {uc($a) cmp uc($b)} @files;
158629279
158639280 # same thing in reversed order
15864 my @articles = sort {$b cmp $a} @files;
9281 @articles = sort {$b cmp $a} @files;
158659282
158669283 # sort numerically ascending
15867 my @articles = sort {$a <=> $b} @files;
9284 @articles = sort {$a <=> $b} @files;
158689285
158699286 # sort numerically descending
15870 my @articles = sort {$b <=> $a} @files;
9287 @articles = sort {$b <=> $a} @files;
158719288
158729289 # this sorts the %age hash by value instead of key
158739290 # using an in-line function
15874 my @eldest = sort { $age{$b} <=> $age{$a} } keys %age;
9291 @eldest = sort { $age{$b} <=> $age{$a} } keys %age;
158759292
158769293 # sort using explicit subroutine name
158779294 sub byage {
15878 $age{$a} <=> $age{$b}; # presuming numeric
9295 $age{$a} <=> $age{$b}; # presuming numeric
158799296 }
15880 my @sortedclass = sort byage @class;
9297 @sortedclass = sort byage @class;
158819298
158829299 sub backwards { $b cmp $a }
15883 my @harry = qw(dog cat x Cain Abel);
9300 @harry = qw(dog cat x Cain Abel);
15884 my @george = qw(gone chased yz Punished Axed);
9301 @george = qw(gone chased yz Punished Axed);
158859302 print sort @harry;
15886 # prints AbelCaincatdogx
9303 # prints AbelCaincatdogx
158879304 print sort backwards @harry;
15888 # prints xdogcatCainAbel
9305 # prints xdogcatCainAbel
158899306 print sort @george, 'to', @harry;
15890 # prints AbelAxedCainPunishedcatchaseddoggonetoxyz
9307 # prints AbelAxedCainPunishedcatchaseddoggonetoxyz
158919308
158929309 # inefficiently sort by descending numeric compare using
158939310 # the first integer after the first = sign, or the
158949311 # whole record case-insensitively otherwise
158959312
15896 my @new = sort {
9313 @new = sort {
15897 ($b =~ /=(\d+)/)[0] <=> ($a =~ /=(\d+)/)[0]
9314 ($b =~ /=(\d+)/)[0] <=> ($a =~ /=(\d+)/)[0]
15898 ||
9315 ||
15899 fc($a) cmp fc($b)
9316 uc($a) cmp uc($b)
159009317 } @old;
159019318
159029319 # same thing, but much more efficiently;
159039320 # we'll build auxiliary indices instead
159049321 # for speed
15905 my (@nums, @caps);
9322 @nums = @caps = ();
159069323 for (@old) {
15907 push @nums, ( /=(\d+)/ ? $1 : undef );
9324 push @nums, /=(\d+)/;
15908 push @caps, fc($_);
9325 push @caps, uc($_);
159099326 }
159109327
15911 my @new = @old[ sort {
9328 @new = @old[ sort {
15912 $nums[$b] <=> $nums[$a]
9329 $nums[$b] <=> $nums[$a]
15913 ||
9330 ||
15914 $caps[$a] cmp $caps[$b]
9331 $caps[$a] cmp $caps[$b]
15915 } 0..$#old
9332 } 0..$#old
15916 ];
9333 ];
159179334
159189335 # same thing, but without any temps
15919 my @new = map { $_->[0] }
9336 @new = map { $_->[0] }
159209337 sort { $b->[1] <=> $a->[1]
159219338 ||
159229339 $a->[2] cmp $b->[2]
15923 } map { [$_, /=(\d+)/, fc($_)] } @old;
9340 } map { [$_, /=(\d+)/, uc($_)] } @old;
159249341
159259342 # using a prototype allows you to use any comparison subroutine
159269343 # as a sort subroutine (including other package's subroutines)
15927 package Other;
9344 package other;
15928 sub backwards ($$) { $_[1] cmp $_[0]; } # $a and $b are
9345 sub backwards ($$) { $_[1] cmp $_[0]; } # $a and $b are not set here
15929 # not set here
159309347 package main;
15931 my @new = sort Other::backwards @old;
9348 @new = sort other::backwards @old;
159329349
15933 # guarantee stability
15934 use sort 'stable';
15935 my @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old;
15936
159379350=begin original
159389351
15939Warning: syntactical care is required when sorting the list returned from
9352If you're using strict, you I<must not> declare $a
15940a function. If you want to sort the list returned by the function call
9353and $b as lexicals. They are package globals. That means
15941C<find_records(@key)>, you can use:
9354if you're in the C<main> package and type
159429355
159439356=end original
159449357
15945警告: 関数から返されたリストをソートするときには文法上の注意が必要です。
9358use strict してい場合、$a $b をレキシカルとして
15946関数呼び出C<find_records(@key)> から返されたリストをソートした場合、
9359宣言ては I<いけません>。
15947以下のように出来ま:
9360これはパッケージグローバルで
9361つまり、C<main> パッケージで以下のように書いた場合:
159489362
15949 my @contact = sort { $a cmp $b } find_records @key;
9363 @articles = sort {$b <=> $a} @files;
15950 my @contact = sort +find_records(@key);
15951 my @contact = sort &find_records(@key);
15952 my @contact = sort(find_records(@key));
159539364
159549365=begin original
159559366
15956If instead you want to sort the array C<@key> with the comparison routine
9367then C<$a> and C<$b> are C<$main::a> and C<$main::b> (or C<$::a> and C<$::b>),
15957C<find_records()> then you can use:
9368but if you're in the C<FooPack> package, it's the same as typing
159589369
159599370=end original
159609371
15961一方、配列 C<@key> を比較ルーチン C<find_records()> でソートしい場合
9372C<$a> C<$b> C<$main::a> と C<$main::b> (または C<$::a> と C<$::b>) を
15962以下のよう出来ます:
9373意味しますが、C<FooPack> パッケージ内の場合、これは以下と同じなります:
159639374
15964 my @contact = sort { find_records() } @key;
9375 @articles = sort {$FooPack::b <=> $FooPack::a} @files;
15965 my @contact = sort find_records(@key);
15966 my @contact = sort(find_records @key);
15967 my @contact = sort(find_records (@key));
159689376
159699377=begin original
159709378
15971C<$a> and C<$b> are set as package globals in the package the sort() is
15972called from. That means C<$main::a> and C<$main::b> (or C<$::a> and
15973C<$::b>) in the C<main> package, C<$FooPack::a> and C<$FooPack::b> in the
15974C<FooPack> package, etc. If the sort block is in scope of a C<my> or
15975C<state> declaration of C<$a> and/or C<$b>, you I<must> spell out the full
15976name of the variables in the sort block :
15977
15978=end original
15979
15980C<$a> と C<$b> は、sort() を呼び出したパッケージのパッケージグローバルとして
15981設定されます。
15982つまり、C<main> パッケージの C<$main::a> と C<$main::b>
15983(あるいは C<$::a> と C<$::b>) 、
15984C<FooPack> パッケージの C<$FooPack::a> と C<$FooPack::b>、などです。
15985ソートブロックが C<$a> や C<$b> の C<my> または C<state> のスコープ内の場合、
15986ソートブロックの変数の完全名を I<指定しなければなりません>:
15987
15988 package main;
15989 my $a = "C"; # DANGER, Will Robinson, DANGER !!!
15990
15991 print sort { $a cmp $b } qw(A C E G B D F H);
15992 # WRONG
15993 sub badlexi { $a cmp $b }
15994 print sort badlexi qw(A C E G B D F H);
15995 # WRONG
15996 # the above prints BACFEDGH or some other incorrect ordering
15997
15998 print sort { $::a cmp $::b } qw(A C E G B D F H);
15999 # OK
16000 print sort { our $a cmp our $b } qw(A C E G B D F H);
16001 # also OK
16002 print sort { our ($a, $b); $a cmp $b } qw(A C E G B D F H);
16003 # also OK
16004 sub lexi { our $a cmp our $b }
16005 print sort lexi qw(A C E G B D F H);
16006 # also OK
16007 # the above print ABCDEFGH
16008
16009=begin original
16010
16011With proper care you may mix package and my (or state) C<$a> and/or C<$b>:
16012
16013=end original
16014
16015適切に注意すれば、パッケージと my (あるいは state) C<$a> や C<$b> を
16016混ぜることができます:
16017
16018 my $a = {
16019 tiny => -2,
16020 small => -1,
16021 normal => 0,
16022 big => 1,
16023 huge => 2
16024 };
16025
16026 say sort { $a->{our $a} <=> $a->{our $b} }
16027 qw{ huge normal tiny small big};
16028
16029 # prints tinysmallnormalbighuge
16030
16031=begin original
16032
16033C<$a> and C<$b> are implicitly local to the sort() execution and regain their
16034former values upon completing the sort.
16035
16036=end original
16037
16038C<$a> と C<$b> は sort() の実行中は暗黙にローカル化され、ソート終了時に
16039元の値に戻ります。
16040
16041=begin original
16042
16043Sort subroutines written using C<$a> and C<$b> are bound to their calling
16044package. It is possible, but of limited interest, to define them in a
16045different package, since the subroutine must still refer to the calling
16046package's C<$a> and C<$b> :
16047
16048=end original
16049
16050C<$a> と C<$b> を使って書かれたソートサブルーチンはその呼び出しパッケージに
16051しなければなりません。
16052異なるパッケージに定義することは可能ですが、
16053これは可能ですが、限られた関心しかありません;
16054サブルーチンは呼び出しパッケージの C<$a> と C<$b> を
16055参照しなければならないからです:
16056
16057 package Foo;
16058 sub lexi { $Bar::a cmp $Bar::b }
16059 package Bar;
16060 ... sort Foo::lexi ...
16061
16062=begin original
16063
16064Use the prototyped versions (see above) for a more generic alternative.
16065
16066=end original
16067
16068より一般的な代替案としては(前述の)プロトタイプ版を使ってください。
16069
16070=begin original
16071
160729379The comparison function is required to behave. If it returns
160739380inconsistent results (sometimes saying C<$x[1]> is less than C<$x[2]> and
160749381sometimes saying the opposite, for example) the results are not
160759382well-defined.
160769383
160779384=end original
160789385
160799386比較関数は一貫した振る舞いをすることが求められます。
160809387一貫しない結果を返す(例えば、あるときは C<$x[1]> が C<$x[2]> より
160819388小さいと返し、またあるときは逆を返す)場合、結果は未定義です。
160829389
16083=begin original
16084
16085Because C<< <=> >> returns L<C<undef>|/undef EXPR> when either operand
16086is C<NaN> (not-a-number), be careful when sorting with a
16087comparison function like C<< $a <=> $b >> any lists that might contain a
16088C<NaN>. The following example takes advantage that C<NaN != NaN> to
16089eliminate any C<NaN>s from the input list.
16090
16091=end original
16092
16093C<< <=> >> はどちらかのオペランドが C<NaN> (not-a-number) のときに
16094L<C<undef>|/undef EXPR> を返すので、C<< $a <=> $b >> といった比較関数で
16095ソートする場合はリストに C<NaN> が含まれないように注意してください。
16096以下の例は 入力リストから C<NaN> を取り除くために C<NaN != NaN> という性質を
16097利用しています。
16098
16099 my @result = sort { $a <=> $b } grep { $_ == $_ } @input;
16100
161019390=item splice ARRAY,OFFSET,LENGTH,LIST
16102X<splice>
161039391
161049392=item splice ARRAY,OFFSET,LENGTH
161059393
161069394=item splice ARRAY,OFFSET
161079395
161089396=item splice ARRAY
161099397
16110=for Pod::Functions add or remove elements anywhere in an array
16111
161129398=begin original
161139399
161149400Removes the elements designated by OFFSET and LENGTH from an array, and
161159401replaces them with the elements of LIST, if any. In list context,
161169402returns the elements removed from the array. In scalar context,
16117returns the last element removed, or L<C<undef>|/undef EXPR> if no
9403returns the last element removed, or C<undef> if no elements are
16118elements are
161199404removed. The array grows or shrinks as necessary.
161209405If OFFSET is negative then it starts that far from the end of the array.
161219406If LENGTH is omitted, removes everything from OFFSET onward.
16122If LENGTH is negative, removes the elements from OFFSET onward
9407If LENGTH is negative, leaves that many elements off the end of the array.
16123except for -LENGTH elements at the end of the array.
9408If both OFFSET and LENGTH are omitted, removes everything.
16124If both OFFSET and LENGTH are omitted, removes everything. If OFFSET is
16125past the end of the array and a LENGTH was provided, Perl issues a warning,
16126and splices at the end of the array.
161279409
9410The following equivalences hold (assuming C<$[ == 0>):
9411
161289412=end original
161299413
161309414ARRAY から OFFSET、LENGTH で指定される要素を取り除き、
161319415LIST があれば、それを代わりに挿入します。
161329416リストコンテキストでは、配列から取り除かれた要素を返します。
16133スカラコンテキストでは、取り除かれた最後の要素を返します; 要素が
9417スカラコンテキストでは、取り除かれた最後の要素を返します
16134取り除かれなかった場合は L<C<undef>|/undef EXPR> を返します。
9418要素が取り除かれなかった場合は C<undef> を返します。
161359419配列は、必要に応じて、大きくなったり、小さくなったりします。
161369420OFFSET が負の数の場合は、配列の最後からの距離を示します。
161379421LENGTH が省略されると、OFFSET 以降のすべての要素を取り除きます。
16138LENGTH が負の数の場合は、OFFSET から前方へ、配列の最後から -LENGTH 要素を
9422LENGTH が負の数の場合は、指定された数だけ配列の最後から要素を取り除きます。
16139除いて取り除きます。
161409423OFFSET と LENGTH の両方が省略されると、全ての要素を取り除きます。
16141OFFSET が配列の最後より後ろで、 LENGTH が指定されていると、Perl は警告を出し、
16142配列の最後に対して処理します。
161439424
16144=begin original
9425以下は、(C<$[ == 0> と仮定すると) それぞれ、等価です。
161459426
16146The following equivalences hold (assuming C<< $#a >= $i >> )
9427 push(@a,$x,$y) splice(@a,@a,0,$x,$y)
9428 pop(@a) splice(@a,-1)
9429 shift(@a) splice(@a,0,1)
9430 unshift(@a,$x,$y) splice(@a,0,0,$x,$y)
9431 $a[$x] = $y splice(@a,$x,1,$y)
161479432
16148=end original
16149
16150以下は、(C<< $#a >= $i >> と仮定すると) それぞれ、等価です。
16151
16152 push(@a,$x,$y) splice(@a,@a,0,$x,$y)
16153 pop(@a) splice(@a,-1)
16154 shift(@a) splice(@a,0,1)
16155 unshift(@a,$x,$y) splice(@a,0,0,$x,$y)
16156 $a[$i] = $y splice(@a,$i,1,$y)
16157
161589433=begin original
161599434
16160L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> can be used, for example,
9435Example, assuming array lengths are passed before arrays:
16161to implement n-ary queue processing:
161629436
161639437=end original
161649438
16165L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> は、例えばn-ary キュー処理
9439次の例では、配列の前にそれぞれ配列の大きさが渡されるものとしています:
16166実装に使えます:
161679440
16168 sub nary_print {
9441 sub aeq { # compare two list values
16169 my $n = shift;
9442 my(@a) = splice(@_,0,shift);
16170 while (my @next_n = splice @_, 0, $n) {
9443 my(@b) = splice(@_,0,shift);
16171 say join q{ -- }, @next_n;
9444 return 0 unless @a == @b; # same len?
16172 }
9445 while (@a) {
9446 return 0 if pop(@a) ne pop(@b);
9447 }
9448 return 1;
161739449 }
9450 if (&aeq($len,@foo[1..$len],0+@bar,@bar)) { ... }
161749451
16175 nary_print(3, qw(a b c d e f g h));
16176 # prints:
16177 # a -- b -- c
16178 # d -- e -- f
16179 # g -- h
16180
16181=begin original
16182
16183Starting with Perl 5.14, an experimental feature allowed
16184L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> to take a
16185scalar expression. This experiment has been deemed unsuccessful, and was
16186removed as of Perl 5.24.
16187
16188=end original
16189
16190Perl 5.14 から、L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> がスカラ式を
16191取ることが出来るという実験的機能がありました。
16192この実験は失敗と見なされ、Perl 5.24 で削除されました。
16193
161949452=item split /PATTERN/,EXPR,LIMIT
16195X<split>
161969453
161979454=item split /PATTERN/,EXPR
161989455
161999456=item split /PATTERN/
162009457
162019458=item split
162029459
16203=for Pod::Functions split up a string using a regexp delimiter
16204
162059460=begin original
162069461
16207Splits the string EXPR into a list of strings and returns the
9462Splits a string into a list of strings and returns that list. By default,
16208list in list context, or the size of the list in scalar context.
9463empty leading fields are preserved, and empty trailing ones are deleted.
16209(Prior to Perl 5.11, it also overwrote C<@_> with the list in
16210void and scalar context. If you target old perls, beware.)
162119464
162129465=end original
162139466
16214文字列 EXPR を文字列のリストに分割して、リストコンテキストではそのリスト
9467文字列を文字列のリストに分割して、リストを返します。
16215返し、スカラコンテキストではリスト大きを返します。
9468デフォルトでは、行頭空白は保存れ、末尾の空白は削除されます。
16216(Perl 5.11 以前では、無効コンテキストやスカラコンテキストの場合は
16217C<@_> をリストで上書きします。
16218もし古い perl を対象にするなら、注意してください。)
162199469
162209470=begin original
162219471
16222If only PATTERN is given, EXPR defaults to L<C<$_>|perlvar/$_>.
9472In scalar context, returns the number of fields found and splits into
9473the C<@_> array. Use of split in scalar context is deprecated, however,
9474because it clobbers your subroutine arguments.
162239475
162249476=end original
162259477
16226PATTERN みが与えられた場合、EXPR のデトは L<C<$_>|perlvar/$_> です。
9478スカラコンテキストの場合には見つかったィードの数を返し、
9479配列 C<@_> に分割結果を設定します。
9480しかし、スカラコンテキストでの split の使用は推奨されません。
9481サブルーチンの引数を上書きしてしまうからです。
162279482
162289483=begin original
162299484
16230Anything in EXPR that matches PATTERN is taken to be a separator
9485If EXPR is omitted, splits the C<$_> string. If PATTERN is also omitted,
16231that separates the EXPR into substrings (called "I<fields>") that
9486splits on whitespace (after skipping any leading whitespace). Anything
16232do B<not> include the separator. Note that a separator may be
9487matching PATTERN is taken to be a delimiter separating the fields. (Note
16233longer than one character or even have no characters at all (the
9488that the delimiter may be longer than one character.)
16234empty string, which is a zero-width match).
162359489
162369490=end original
162379491
16238EXPR の中で PATTERN にマッチングするものは何でも EXPR("I<fields>"
9492EXPR を省略すると、文字列 C<$_> split します。
16239呼ばれる)セパレータを B<含まない> 部分文字列に分割するための
9493もし、PATTERN も省略すると、
16240セパレータとなります。
9494(先頭の空白文字をスキップした後) 空白で split します。
16241セパレータは一文字より長くもよく、全く文字がなくてもよい(空文字列は
9495PATTERN にマッチするものは、フィルドを分割するデリミとし扱われます。
16242ゼロ幅マッチングです)いうことに注意してください
9496(デリミタは、1 文字は限りません)
162439497
162449498=begin original
162459499
16246The PATTERN need not be constant; an expression may be used
9500If LIMIT is specified and positive, splits into no more than that
16247to specify a pattern that varies at runtime.
9501many fields (though it may split into fewer). If LIMIT is unspecified
9502or zero, trailing null fields are stripped (which potential users
9503of C<pop> would do well to remember). If LIMIT is negative, it is
9504treated as if an arbitrarily large LIMIT had been specified.
162489505
162499506=end original
162509507
16251PATTERN 数である必要ありせん; 実行時に変更されるパタンを
9508正の数の LIMIT を指した場合に、最大その数でのフィルドに
16252指定るために式を使えます。
9509split しま (しかし、それより少ないことはあります)
9510LIMIT を指定しないかゼロなら、末尾の空フィールドを捨ててしまいます
9511(C<pop> を行なうときには気を付けないといけません)。
9512LIMIT が負ならば、LIMIT に任意の大きな数を指定したのと同じことになります。
162539513
162549514=begin original
162559515
16256If PATTERN matches the empty string, the EXPR is split at the match
9516A pattern matching the null string (not to be confused with
16257position (between characters). As an example, the following:
9517a null pattern C<//>, which is just one member of the set of patterns
9518matching a null string) will split the value of EXPR into separate
9519characters at each point it matches that way. For example:
162589520
16259=end original
9521 print join(':', split(/ */, 'hi there'));
162609522
16261PATTERN が空文字列にマッチングする場合、EXPR はマッチング位置
9523produces the output 'h:i:t:h:e:r:e'.
16262(文字の間)で分割されます。
16263例えば、以下のものは:
162649524
16265 print join(':', split(/b/, 'abc')), "\n";
16266
16267=begin original
16268
16269uses the C<b> in C<'abc'> as a separator to produce the output C<a:c>.
16270However, this:
16271
162729525=end original
162739526
16274C<'abc'> の C<b> をセータとして使って出力 C<a:c> を生成ます
9527空文字列にマッチするン (ヌルパーン C<//> と混同ないでください
16275しかし、これは:
9528これは、空文字列にマッチするパターンの一つでしかありません) は、
9529どの場所にもマッチし、EXPR の値を1 文字ずつに分割します。
9530たとえば、
162769531
16277 print join(':', split(//, 'abc')), "\n";
9532 print join(':', split(/ */, 'hi there'));
162789533
16279=begin original
9534は、'h:i:t:h:e:r:e' という出力になります。
162809535
16281uses empty string matches as separators to produce the output
16282C<a:b:c>; thus, the empty string may be used to split EXPR into a
16283list of its component characters.
16284
16285=end original
16286
16287空文字列マッチングをセパレータとして使って出力 C<a:b:c> を生成します; 従って、
16288空文字列は EXPR を構成する文字のリストに分割するために使われます。
16289
162909536=begin original
162919537
16292As a special case for L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>,
9538Empty leading (or trailing) fields are produced when there are positive width
16293the empty pattern given in
9539matches at the beginning (or end) of the string; a zero-width match at the
16294L<match operator|perlop/"m/PATTERN/msixpodualngc"> syntax (C<//>)
9540beginning (or end) of the string does not produce an empty field. For
16295specifically matches the empty string, which is contrary to its usual
9541example:
16296interpretation as the last successful match.
162979542
162989543=end original
162999544
16300L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> の特殊場合として、
9545先頭と末尾の空フィールドは、文字列の先頭または末尾で 0 い幅で
16301L<マッチング演算子|perlop/"m/PATTERN/msixpodualngc"> 文法で与えられ
9546マッチ場合は生成されます。
16302空パターン (C<//>) は特に空文字列にマッチング、最後に成功し
9547 0 マッチした場合は生成されません。
16303マッチングという普通の解釈と異なります。
16304
16305=begin original
16306
16307If PATTERN is C</^/>, then it is treated as if it used the
16308L<multiline modifier|perlreref/OPERATORS> (C</^/m>), since it
16309isn't much use otherwise.
16310
16311=end original
16312
16313PATTERN が C</^/> の場合、L<複数行修飾子|perlreref/OPERATORS>
16314(C</^/m>) が使われたかのように扱われます; そうでなければほとんど
16315使えないからです。
16316
16317=begin original
16318
16319C<E<sol>m> and any of the other pattern modifiers valid for C<qr>
16320(summarized in L<perlop/qrE<sol>STRINGE<sol>msixpodualn>) may be
16321specified explicitly.
16322
16323=end original
16324
16325C<qr> で有効な C<E<sol>m> 及びその他のパターン修飾子
16326(L<perlop/qrE<sol>STRINGE<sol>msixpodualn> にまとめられています) は
16327明示的に定義されます。
16328
16329=begin original
16330
16331As another special case,
16332L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> emulates the default
16333behavior of the
16334command line tool B<awk> when the PATTERN is either omitted or a
16335string composed of a single space character (such as S<C<' '>> or
16336S<C<"\x20">>, but not e.g. S<C</ />>). In this case, any leading
16337whitespace in EXPR is removed before splitting occurs, and the PATTERN is
16338instead treated as if it were C</\s+/>; in particular, this means that
16339I<any> contiguous whitespace (not just a single space character) is used as
16340a separator. However, this special treatment can be avoided by specifying
16341the pattern S<C</ />> instead of the string S<C<" ">>, thereby allowing
16342only a single space character to be a separator. In earlier Perls this
16343special case was restricted to the use of a plain S<C<" ">> as the
16344pattern argument to split; in Perl 5.18.0 and later this special case is
16345triggered by any expression which evaluates to the simple string S<C<" ">>.
16346
16347=end original
16348
16349もう一つの特別な場合として、
16350L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> は
16351PATTERN が省略されるか単一のスペース文字からなる文字列 (つまり例えば
16352S<C</ />> ではなく S<C<' '>> や S<C<"\x20">>) の場合、コマンドラインツール
16353B<awk> のデフォルトの振る舞いをエミュレートします。
16354この場合、EXPR の先頭の空白は分割を行う前に削除され、PATTERN は
16355C</\s+/> であったかのように扱われます; 特に、これは (単に単一の
16356スペース文字ではなく) I<あらゆる> 連続した空白がセパレータとして
16357使われるということです。
16358しかし、この特別の扱いは文字列 S<C<" ">> の代わりにパターン S<C</ />> を
16359指定することで回避でき、それによってセパレータとして単一の
16360スペース文字のみが使われます。
16361以前の Perl ではこの特別な場合は split のパターン引数として単に S<C<" ">> を
16362使った場合に制限されていました; Perl 5.18.0 以降では、この特別な場合は
16363単純な文字列 S<C<" ">> と評価される任意の式によって引き起こされます。
16364
16365=begin original
16366
16367As of Perl 5.28, this special-cased whitespace splitting works as expected in
16368the scope of L<< S<C<"use feature 'unicode_strings">>|feature/The
16369'unicode_strings' feature >>. In previous versions, and outside the scope of
16370that feature, it exhibits L<perlunicode/The "Unicode Bug">: characters that are
16371whitespace according to Unicode rules but not according to ASCII rules can be
16372treated as part of fields rather than as field separators, depending on the
16373string's internal encoding.
16374
16375=end original
16376
16377Perl 5.28 から、この特別な場合の空白分割は
16378L<< S<C<"use feature 'unicode_strings">>|feature/The
16379'unicode_strings' feature >> のスコープの中では想定通りに動作します。
16380以前のバージョンでは、そしてこの機能のスコープの外側では、
16381これは L<perlunicode/The "Unicode Bug"> を引き起こします:
16382Unicode によれば空白だけれども ASCII の規則ではそうではない文字は、
16383文字列の内部エンコーディングに依存して、
16384フィールドの区切りではなくフィールドの一部として扱われることがあります。
16385
16386=begin original
16387
16388If omitted, PATTERN defaults to a single space, S<C<" ">>, triggering
16389the previously described I<awk> emulation.
16390
16391=end original
16392
16393省略されると、PATTERN のデフォルトは単一のスペース S<C<" ">> になり、
16394先に記述した I<awk> エミュレーションを起動します。
16395
16396=begin original
16397
16398If LIMIT is specified and positive, it represents the maximum number
16399of fields into which the EXPR may be split; in other words, LIMIT is
16400one greater than the maximum number of times EXPR may be split. Thus,
16401the LIMIT value C<1> means that EXPR may be split a maximum of zero
16402times, producing a maximum of one field (namely, the entire value of
16403EXPR). For instance:
16404
16405=end original
16406
16407LIMIT が指定された正数の場合、EXPR が分割されるフィールドの最大数を
16408表現します; 言い換えると、 LIMIT は EXPR が分割される数より一つ大きい数です。
16409従って、LIMIT の値 C<1> は EXPR が最大 0 回分割されるということで、
16410最大で一つのフィールドを生成します (言い換えると、EXPR 全体の値です)。
164119548例えば:
164129549
16413 print join(':', split(//, 'abc', 1)), "\n";
9550 print join(':', split(/(?=\w)/, 'hi there!'));
164149551
164159552=begin original
164169553
16417produces the output C<abc>, and this:
9554produces the output 'h:i :t:h:e:r:e!'.
164189555
164199556=end original
164209557
16421これは C<abc> を出力し、次のものは:
9558これ出力は 'h:i :t:h:e:r:e!' となります。
164229559
16423 print join(':', split(//, 'abc', 2)), "\n";
16424
164259560=begin original
164269561
16427produces the output C<a:bc>, and each of these:
9562The LIMIT parameter can be used to split a line partially
164289563
164299564=end original
164309565
16431C<a:bc>出力し以下のものそれぞれは:
9566LIMIT使うと行を部分的に split することができます。
164329567
16433 print join(':', split(//, 'abc', 3)), "\n";
9568 ($login, $passwd, $remainder) = split(/:/, $_, 3);
16434 print join(':', split(//, 'abc', 4)), "\n";
164359569
164369570=begin original
164379571
16438produces the output C<a:b:c>.
9572When assigning to a list, if LIMIT is omitted, Perl supplies a LIMIT
9573one larger than the number of variables in the list, to avoid
9574unnecessary work. For the list above LIMIT would have been 4 by
9575default. In time critical applications it behooves you not to split
9576into more fields than you really need.
164399577
164409578=end original
164419579
16442C<a:b:c>出力しま
9580リストへ代入するとき、LIMIT省略ると、Perl は、
9581無駄な仕事を避けるため、そのリストの変数の数より、1 つだけ大きい
9582LIMIT が与えられたものとして処理を行ないます。
9583上のリストの場合には、LIMIT はデフォルトで 4 になります。
9584時間が問題となるアプリケーションでは、
9585必要以上のフィールドに分けないようにする必要があります。
164439586
164449587=begin original
164459588
16446If LIMIT is negative, it is treated as if it were instead arbitrarily
9589If the PATTERN contains parentheses, additional list elements are
16447large; as many fields as possible are produced.
9590created from each matching substring in the delimiter.
164489591
164499592=end original
164509593
16451LIMIT が負数なら、非常大き数であよう扱われま; できだけ多く
9594PATTERN括弧が含まれていると、デリミタ内部分文字列マッチするも、
16452フィールドが生成されます。
9595リスト要素に含まるようになります。
164539596
16454=begin original
9597 split(/([,-])/, "1-10,20", 3);
164559598
16456If LIMIT is omitted (or, equivalently, zero), then it is usually
16457treated as if it were instead negative but with the exception that
16458trailing empty fields are stripped (empty leading fields are always
16459preserved); if all fields are empty, then all fields are considered to
16460be trailing (and are thus stripped in this case). Thus, the following:
16461
16462=end original
16463
16464LIMIT が省略されると(あるいは等価な 0 なら)、普通は負数が指定されたかのように
16465動作しますが、末尾の空フィールドは取り除かれるという例外があります
16466(先頭の空フィールドは常に保存されます); もし全てのフィールドが空なら、
16467全てのフィールドが末尾として扱われます(そしてこの場合取り除かれます)。
16468従って、以下のようにすると:
16469
16470 print join(':', split(/,/, 'a,b,c,,,')), "\n";
16471
164729599=begin original
164739600
16474produces the output C<a:b:c>, but the following:
9601produces the list value
164759602
164769603=end original
164779604
16478出力 C<a:b:c> を生成しますが、以下のようにすると:
9605は、以下のリスト値を生成します
164799606
16480 print join(':', split(/,/, 'a,b,c,,,', -1)), "\n";
9607 (1, '-', 10, ',', 20)
164819608
164829609=begin original
164839610
16484produces the output C<a:b:c:::>.
9611If you had the entire header of a normal Unix email message in $header,
9612you could split it up into fields and their values this way:
164859613
164869614=end original
164879615
16488出力 C<a:b:c:::> を生成しま
9616$header に Unix E メールメッセージヘッダ全体が入っているとると、
9617以下のようにしてフィールドとその値に分割できます:
164899618
16490=begin original
9619 $header =~ s/\n\s+/ /g; # fix continuation lines
9620 %hdrs = (UNIX_FROM => split /^(\S*?):\s*/m, $header);
164919621
16492In time-critical applications, it is worthwhile to avoid splitting
16493into more fields than necessary. Thus, when assigning to a list,
16494if LIMIT is omitted (or zero), then LIMIT is treated as though it
16495were one larger than the number of variables in the list; for the
16496following, LIMIT is implicitly 3:
16497
16498=end original
16499
16500時間に厳しいアプリケーションでは、必要でないフィールドの分割を避けるのは
16501価値があります。
16502従って、リストに代入される場合に、LIMIT が省略される(または 0)と、
16503LIMIT は リストにある変数の数より一つ大きい数のように扱われます;
16504次の場合、LIMIT は暗黙に 3 になります:
16505
16506 my ($login, $passwd) = split(/:/);
16507
165089622=begin original
165099623
16510Note that splitting an EXPR that evaluates to the empty string always
9624The pattern C</PATTERN/> may be replaced with an expression to specify
16511produces zero fields, regardless of the LIMIT specified.
9625patterns that vary at runtime. (To do runtime compilation only once,
9626use C</$variable/o>.)
165129627
165139628=end original
165149629
16515LIMIT の指定に関わらず空文字列評価され EXPR 分割すると常に 0 個の
9630/PATTERN/ 実行時変わパターン指定する式で置き換えるこができます。
16516フィー生成すること注意してください。
9631(実行時のコンパイルを 1 度にするため、/$variable/o を使ってください。)
165179632
165189633=begin original
165199634
16520An empty leading field is produced when there is a positive-width
9635As a special case, specifying a PATTERN of space (C<' '>) will split on
16521match at the beginning of EXPR. For instance:
9636white space just as C<split> with no arguments does. Thus, C<split(' ')> can
9637be used to emulate B<awk>'s default behavior, whereas C<split(/ /)>
9638will give you as many null initial fields as there are leading spaces.
9639A C<split> on C</\s+/> is like a C<split(' ')> except that any leading
9640whitespace produces a null first field. A C<split> with no arguments
9641really does a C<split(' ', $_)> internally.
165229642
165239643=end original
165249644
16525EXPR の先頭で正数幅でマッチングしたときは先頭に空のフィルドが
9645特別な場合として、PATTERNスペス (C<' '>) を指定すると、
16526生成されます。
9646引数なしの C<split> のように空白で split を行ないます。
16527例えば:
9647つまり、C<split(' ')> は B<awk> のデフォルトの動作をエミュレートするために
9648使うことができ、C<split(/ /)> は行頭のスペースの数に応じた空フィールドが
9649できます。
9650C<split /\s+/> は C<split(' ')> と同様ですが、
9651先頭の空白は先頭の空フィールドとなります。
9652引数なしの C<split> は内部的には C<split(' ', $_)> を実行します。
165289653
16529 print join(':', split(/ /, ' abc')), "\n";
16530
165319654=begin original
165329655
16533produces the output C<:abc>. However, a zero-width match at the
9656A PATTERN of C</^/> is treated as if it were C</^/m>, since it isn't
16534beginning of EXPR never produces an empty field, so that:
9657much use otherwise.
165359658
16536=end original
9659Example:
165379660
16538これは出力 C<:abc> を生成します。
16539しかし、EXPR の先頭でのゼロ幅マッチングは決して空フィールドを生成しないので:
16540
16541 print join(':', split(//, ' abc'));
16542
16543=begin original
16544
16545produces the output S<C< :a:b:c>> (rather than S<C<: :a:b:c>>).
16546
165479661=end original
165489662
16549これは(S<C<: :a:b:c>> ではなく)出力 S<C< :a:b:c>> を生成します。
9663PATTERN に C</^/> を指定すると C</^/m> て扱われます。
9664他の意味に使われることはまずないからです。
165509665
16551=begin original
9666例:
165529667
16553An empty trailing field, on the other hand, is produced when there is a
9668 open(PASSWD, '/etc/passwd');
16554match at the end of EXPR, regardless of the length of the match
9669 while (<PASSWD>) {
16555(of course, unless a non-zero LIMIT is given explicitly, such fields are
9670 chomp;
16556removed, as in the last example). Thus:
9671 ($login, $passwd, $uid, $gid,
9672 $gcos, $home, $shell) = split(/:/);
9673 #...
9674 }
165579675
16558=end original
165599676
16560一方、末尾の空のフィールドは、マッチングの長さに関わらず、EXPR の末尾で
9677=item sprintf FORMAT, LIST
16561マッチングしたときに生成されます(もちろん非 0 の LIMIT が明示的に
16562指定されていない場合です; このようなフィールドは前の例のように
16563取り除かれます)。
16564従って:
165659678
16566 print join(':', split(//, ' abc', -1)), "\n";
16567
165689679=begin original
165699680
16570produces the output S<C< :a:b:c:>>.
9681Returns a string formatted by the usual C<printf> conventions of the C
9682library function C<sprintf>. See below for more details
9683and see L<sprintf(3)> or L<printf(3)> on your system for an explanation of
9684the general principles.
165719685
16572=end original
9686For example:
165739687
16574これは出力 S<C< :a:b:c:>> を生成します。
16575
16576=begin original
16577
16578If the PATTERN contains
16579L<capturing groups|perlretut/Grouping things and hierarchical matching>,
16580then for each separator, an additional field is produced for each substring
16581captured by a group (in the order in which the groups are specified,
16582as per L<backreferences|perlretut/Backreferences>); if any group does not
16583match, then it captures the L<C<undef>|/undef EXPR> value instead of a
16584substring. Also,
16585note that any such additional field is produced whenever there is a
16586separator (that is, whenever a split occurs), and such an additional field
16587does B<not> count towards the LIMIT. Consider the following expressions
16588evaluated in list context (each returned list is provided in the associated
16589comment):
16590
165919688=end original
165929689
16593PATTERN
9690普通の C 言語の C<printf> 記法のフォーマットで、整形された文字列を返します。
16594L<捕捉グループ|perlretut/Grouping things and hierarchical matching> を
16595含んでいる場合、それぞれのセパレータについて、
16596(L<後方参照|perlretut/Backreferences> のようにグループが指定された)
16597グループによって捕捉されたそれぞれの部分文字列について追加のフィールドが
16598生成されます; どのグループもマッチングしなかった場合、部分文字列の代わりに
16599L<C<undef>|/undef EXPR> 値を捕捉します。
16600また、このような追加のフィールドはセパレータがあるとき(つまり、分割が
16601行われるとき)はいつでも生成され、このような追加のフィールドは
16602LIMIT に関してはカウント B<されない> ことに注意してください。
16603リストコンテキストで評価される以下のような式を考えます
16604(それぞれの返されるリストは関連づけられたコメントで提供されます):
16605
16606 split(/-|,/, "1-10,20", 3)
16607 # ('1', '10', '20')
16608
16609 split(/(-|,)/, "1-10,20", 3)
16610 # ('1', '-', '10', ',', '20')
16611
16612 split(/-|(,)/, "1-10,20", 3)
16613 # ('1', undef, '10', ',', '20')
16614
16615 split(/(-)|,/, "1-10,20", 3)
16616 # ('1', '-', '10', undef, '20')
16617
16618 split(/(-)|(,)/, "1-10,20", 3)
16619 # ('1', '-', undef, '10', undef, ',', '20')
16620
16621=item sprintf FORMAT, LIST
16622X<sprintf>
16623
16624=for Pod::Functions formatted print into a string
16625
16626=begin original
16627
16628Returns a string formatted by the usual
16629L<C<printf>|/printf FILEHANDLE FORMAT, LIST> conventions of the C
16630library function L<C<sprintf>|/sprintf FORMAT, LIST>. See below for
16631more details and see L<sprintf(3)> or L<printf(3)> on your system for an
16632explanation of the general principles.
16633
16634=end original
16635
16636C ライブラリ関数 L<C<sprintf>|/sprintf FORMAT, LIST> の
16637普通の L<C<printf>|/printf FILEHANDLE FORMAT, LIST> 記法の
16638整形された文字列を返します。
166399691一般的な原則の説明については以下の説明と、システムの
166409692L<sprintf(3)> または L<printf(3)> の説明を参照してください。
166419693
16642=begin original
9694例:
166439695
16644For example:
16645
16646=end original
16647
16648例えば:
16649
166509696 # Format number with up to 8 leading zeroes
16651 my $result = sprintf("%08d", $number);
9697 $result = sprintf("%08d", $number);
166529698
166539699 # Round number to 3 digits after decimal point
16654 my $rounded = sprintf("%.3f", $number);
9700 $rounded = sprintf("%.3f", $number);
166559701
166569702=begin original
166579703
16658Perl does its own L<C<sprintf>|/sprintf FORMAT, LIST> formatting: it
9704Perl does its own C<sprintf> formatting--it emulates the C
16659emulates the C
9705function C<sprintf>, but it doesn't use it (except for floating-point
16660function L<sprintf(3)>, but doesn't use it except for floating-point
9706numbers, and even then only the standard modifiers are allowed). As a
16661numbers, and even then only standard modifiers are allowed.
9707result, any non-standard extensions in your local C<sprintf> are not
16662Non-standard extensions in your local L<sprintf(3)> are
9708available from Perl.
16663therefore unavailable from Perl.
166649709
166659710=end original
166669711
16667Perl は L<C<sprintf>|/sprintf FORMAT, LIST> フォーマット処理を自力で行います:
9712Perl は C<sprintf> フォーマット処理を自力で行います
16668これは C の L<sprintf(3)> 関数をエミュレートしますが、C の関数は使いません
9713これは C の C<sprintf> 関数をエミュレートしますが、
16669(浮動小数点を除きますが、それでも標準の記述子のみが利用できます)。
9714C の関数は使いません(浮動小数点を除きますが、それでも標準の
16670従って、ローカルな非標準 L<sprintf(3)> 拡張機能は Perl は使えせん
9715記述子みが利用す)
9716従って、ローカルな非標準の C<sprintf> 拡張機能は Perl では使えません。
166719717
166729718=begin original
166739719
16674Unlike L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
9720Unlike C<printf>, C<sprintf> does not do what you probably mean when you
16675L<C<sprintf>|/sprintf FORMAT, LIST> does not do what you probably mean
9721pass it an array as your first argument. The array is given scalar context,
16676when you pass it an array as your first argument.
16677The array is given scalar context,
166789722and instead of using the 0th element of the array as the format, Perl will
166799723use the count of elements in the array as the format, which is almost never
166809724useful.
166819725
166829726=end original
166839727
16684L<C<printf>|/printf FILEHANDLE FORMAT, LIST> と違っ
9728C<printf> と違って、 C<sprintf> の最初の引数に配列を渡し
16685L<C<sprintf>|/sprintf FORMAT, LIST> の最初の引数に配列を渡しても
166869729あなたが多分望むとおりには動作しません。
166879730配列はスカラコンテキストで渡されるので、配列の 0 番目の要素ではなく、
16688配列の要素数をフォーマットとして扱います; これはほとんど役に立ちません
9731配列の要素数をフォーマットとして扱います。
9732これはほとんど役に立ちません。
166899733
166909734=begin original
166919735
16692Perl's L<C<sprintf>|/sprintf FORMAT, LIST> permits the following
9736Perl's C<sprintf> permits the following universally-known conversions:
16693universally-known conversions:
166949737
166959738=end original
166969739
16697Perl の L<C<sprintf>|/sprintf FORMAT, LIST> は以下の一般に知られている変換に
9740Perl の C<sprintf> は以下の一般に知られている変換に対応しています:
16698対応しています:
166999741
16700=begin original
9742 %% a percent sign
9743 %c a character with the given number
9744 %s a string
9745 %d a signed integer, in decimal
9746 %u an unsigned integer, in decimal
9747 %o an unsigned integer, in octal
9748 %x an unsigned integer, in hexadecimal
9749 %e a floating-point number, in scientific notation
9750 %f a floating-point number, in fixed decimal notation
9751 %g a floating-point number, in %e or %f notation
167019752
16702 %% a percent sign
16703 %c a character with the given number
16704 %s a string
16705 %d a signed integer, in decimal
16706 %u an unsigned integer, in decimal
16707 %o an unsigned integer, in octal
16708 %x an unsigned integer, in hexadecimal
16709 %e a floating-point number, in scientific notation
16710 %f a floating-point number, in fixed decimal notation
16711 %g a floating-point number, in %e or %f notation
16712
16713=end original
16714
16715 %% パーセントマーク
16716 %c 与えられた番号の文字
16717 %s 文字列
16718 %d 符号付き 10 進数
16719 %u 符号なし 10 進数
16720 %o 符号なし 8 進数
16721 %x 符号なし 16 進数
16722 %e 科学的表記の浮動小数点数
16723 %f 固定 10 進数表記の浮動小数点数
16724 %g %e か %f の表記の浮動小数点数
16725
167269753=begin original
167279754
167289755In addition, Perl permits the following widely-supported conversions:
167299756
167309757=end original
167319758
167329759さらに、Perl では以下のよく使われている変換に対応しています:
167339760
16734=begin original
9761 %X like %x, but using upper-case letters
9762 %E like %e, but using an upper-case "E"
9763 %G like %g, but with an upper-case "E" (if applicable)
9764 %b an unsigned integer, in binary
9765 %p a pointer (outputs the Perl value's address in hexadecimal)
9766 %n special: *stores* the number of characters output so far
9767 into the next variable in the parameter list
167359768
16736 %X like %x, but using upper-case letters
16737 %E like %e, but using an upper-case "E"
16738 %G like %g, but with an upper-case "E" (if applicable)
16739 %b an unsigned integer, in binary
16740 %B like %b, but using an upper-case "B" with the # flag
16741 %p a pointer (outputs the Perl value's address in hexadecimal)
16742 %n special: *stores* the number of characters output so far
16743 into the next argument in the parameter list
16744 %a hexadecimal floating point
16745 %A like %a, but using upper-case letters
16746
16747=end original
16748
16749 %X %x と同様だが大文字を使う
16750 %E %e と同様だが大文字の "E" を使う
16751 %G %g と同様だが(適切なら)大文字の "E" を使う
16752 %b 符号なし 2 進数
16753 %B %b と同様だが、# フラグで大文字の "B" を使う
16754 %p ポインタ (Perl の値のアドレスを 16 進数で出力する)
16755 %n 特殊: 出力文字数を引数リストの次の変数に「格納」する
16756 %a 16 進浮動小数点
16757 %A %a と同様だが、大文字を使う
16758
167599769=begin original
167609770
167619771Finally, for backward (and we do mean "backward") compatibility, Perl
167629772permits these unnecessary but widely-supported conversions:
167639773
167649774=end original
167659775
167669776最後に、過去との互換性(これは「過去」だと考えています)のために、
167679777Perl は以下の不要ではあるけれども広く使われている変換に対応しています。
167689778
16769=begin original
9779 %i a synonym for %d
9780 %D a synonym for %ld
9781 %U a synonym for %lu
9782 %O a synonym for %lo
9783 %F a synonym for %f
167709784
16771 %i a synonym for %d
16772 %D a synonym for %ld
16773 %U a synonym for %lu
16774 %O a synonym for %lo
16775 %F a synonym for %f
16776
16777=end original
16778
16779 %i %d の同義語
16780 %D %ld の同義語
16781 %U %lu の同義語
16782 %O %lo の同義語
16783 %F %f の同義語
16784
167859785=begin original
167869786
16787Note that the number of exponent digits in the scientific notation produced
9787Note that the number of exponent digits in the scientific notation by
16788by C<%e>, C<%E>, C<%g> and C<%G> for numbers with the modulus of the
9788C<%e>, C<%E>, C<%g> and C<%G> for numbers with the modulus of the
167899789exponent less than 100 is system-dependent: it may be three or less
167909790(zero-padded as necessary). In other words, 1.23 times ten to the
1679199th may be either "1.23e99" or "1.23e099". Similarly for C<%a> and C<%A>:
979199th may be either "1.23e99" or "1.23e099".
16792the exponent or the hexadecimal digits may float: especially the
16793"long doubles" Perl configuration option may cause surprises.
167949792
167959793=end original
167969794
167979795C<%e>, C<%E>, C<%g>, C<%G> において、指数部が 100 未満の場合の
167989796指数部の科学的な表記法はシステム依存であることに注意してください:
1679997973 桁かもしれませんし、それ以下かもしれません(必要に応じて 0 で
168009798パッディングされます)。
168019799言い換えると、 1.23 掛ける 10 の 99 乗は "1.23e99" かもしれませんし
168029800"1.23e099" かもしれません。
16803同様に C<%a> と C<%A> の場合:
16804指数部と 16 進数が浮動小数点かもしれません:
16805特に "long doubles" Perl 設定オプションが驚きを引き起こすかもしれません。
168069801
168079802=begin original
168089803
16809Between the C<%> and the format letter, you may specify several
9804Perl permits the following universally-known flags between the C<%>
16810additional attributes controlling the interpretation of the format.
9805and the conversion letter:
16811In order, these are:
168129806
168139807=end original
168149808
16815C<%> とフォーマット文字の間に、ォーマット解釈を制御すための、
9809Perl は C<%> と変換文字の間ラグとして以下一般に知られてい
16816いくつか追加の属性を指定できます
9810に対応しています:
16817順番に、以下のものがあります:
168189811
16819=over 4
9812 space prefix positive number with a space
9813 + prefix positive number with a plus sign
16821=item format parameter index
16822
16823(フォーマットパラメータインデックス)
16824
16825=begin original
16826
16827An explicit format parameter index, such as C<2$>. By default sprintf
16828will format the next unused argument in the list, but this allows you
16829to take the arguments out of order:
16830
16831=end original
16832
16833C<2$> のような明示的なフォーマットパラメータインデックス。
16834デフォルトでは sprintf はリストの次の使われていない引数を
16835フォーマットしますが、これによって異なった順番の引数を使えるようにします:
16836
16837 printf '%2$d %1$d', 12, 34; # prints "34 12"
16838 printf '%3$d %d %1$d', 1, 2, 3; # prints "3 1 1"
16839
16840=item flags
16841
16842(フラグ)
16843
16844=begin original
16845
16846one or more of:
16847
16848=end original
16849
16850以下のうちの一つまたは複数指定できます:
16851
16852=begin original
16853
16854 space prefix non-negative number with a space
16855 + prefix non-negative number with a plus sign
168569814 - left-justify within the field
168579815 0 use zeros, not spaces, to right-justify
16858 # ensure the leading "0" for any octal,
9816 # prefix non-zero octal with "0", non-zero hex with "0x"
16859 prefix non-zero hexadecimal with "0x" or "0X",
9817 number minimum field width
16860 prefix non-zero binary with "0b" or "0B"
9818 .number "precision": digits after decimal point for
9819 floating-point, max length for string, minimum length
9820 for integer
9821 l interpret integer as C type "long" or "unsigned long"
9822 h interpret integer as C type "short" or "unsigned short"
9823 If no flags, interpret integer as C type "int" or "unsigned"
168619824
16862=end original
16863
16864 space 非負数の前に空白をつける
16865 + 非負数の前にプラス記号をつける
16866 - フィールド内で左詰めする
16867 0 右詰めに空白ではなくゼロを使う
16868 # 8 進数では確実に先頭に "0" をつける;
16869 非 0 の 16 進数では "0x" か "0X" をつける;
16870 非 0 の 2 進数では "0b" か "0B" をつける
16871
168729825=begin original
168739826
16874For example:
9827There are also two Perl-specific flags:
168759828
168769829=end original
168779830
16878例えば:
9831さらに Perl 独自の 2 つのフラグがあります:
168799832
16880 printf '<% d>', 12; # prints "< 12>"
9833 V interpret integer as Perl's standard integer type
16881 printf '<% d>', 0; # prints "< 0>"
9834 v interpret string as a vector of integers, output as
16882 printf '<% d>', -12; # prints "<-12>"
9835 numbers separated either by dots, or by an arbitrary
16883 printf '<%+d>', 12; # prints "<+12>"
9836 string received from the argument list when the flag
16884 printf '<%+d>', 0; # prints "<+0>"
9837 is preceded by C<*>
16885 printf '<%+d>', -12; # prints "<-12>"
16886 printf '<%6s>', 12; # prints "< 12>"
16887 printf '<%-6s>', 12; # prints "<12 >"
16888 printf '<%06s>', 12; # prints "<000012>"
16889 printf '<%#o>', 12; # prints "<014>"
16890 printf '<%#x>', 12; # prints "<0xc>"
16891 printf '<%#X>', 12; # prints "<0XC>"
16892 printf '<%#b>', 12; # prints "<0b1100>"
16893 printf '<%#B>', 12; # prints "<0B1100>"
168949838
168959839=begin original
168969840
16897When a space and a plus sign are given as the flags at once,
9841Where a number would appear in the flags, an asterisk (C<*>) may be
16898the space is ignored.
9842used instead, in which case Perl uses the next item in the parameter
9843list as the given number (that is, as the field width or precision).
16900=end original
16901
16902空白とプラス記号がフラグとして同時に与えられると、
16903空白は無視されます。
16904
16905 printf '<%+ d>', 12; # prints "<+12>"
16906 printf '<% +d>', 12; # prints "<+12>"
16907
16908=begin original
16909
16910When the # flag and a precision are given in the %o conversion,
16911the precision is incremented if it's necessary for the leading "0".
16912
16913=end original
16914
16915%o 変換に # フラグと精度が与えられると、先頭の "0" が必要な場合は
16916精度に 1 が加えられます。
16917
16918 printf '<%#.5o>', 012; # prints "<00012>"
16919 printf '<%#.5o>', 012345; # prints "<012345>"
16920 printf '<%#.0o>', 0; # prints "<0>"
16921
16922=item vector flag
16923
16924(ベクタフラグ)
16925
16926=begin original
16927
16928This flag tells Perl to interpret the supplied string as a vector of
16929integers, one for each character in the string. Perl applies the format to
16930each integer in turn, then joins the resulting strings with a separator (a
16931dot C<.> by default). This can be useful for displaying ordinal values of
16932characters in arbitrary strings:
16933
16934=end original
16935
16936このフラグは Perl に、与えられた文字列を、文字毎に一つの整数のベクタとして
16937解釈させます。
16938Perl は各数値をフォーマットし、それから結果の文字列をセパレータ
16939(デフォルトでは C<.>)で連結します。
16940これは任意の文字列の文字を順序付きの値として表示するのに便利です:
16941
16942 printf "%vd", "AB\x{100}"; # prints "65.66.256"
16943 printf "version is v%vd\n", $^V; # Perl's version
16944
16945=begin original
16946
16947Put an asterisk C<*> before the C<v> to override the string to
16948use to separate the numbers:
16949
16950=end original
16951
16952アスタリスク C<*> を C<v> の前に置くと、数値を分けるために使われる文字列を
16953上書きします:
16954
16955 printf "address is %*vX\n", ":", $addr; # IPv6 address
16956 printf "bits are %0*v8b\n", " ", $bits; # random bitstring
16957
16958=begin original
16959
16960You can also explicitly specify the argument number to use for
16961the join string using something like C<*2$v>; for example:
16962
16963=end original
16964
16965また、C<*2$v> のように、連結する文字列として使う引数の番号を明示的に
16966指定できます; 例えば:
16967
16968 printf '%*4$vX %*4$vX %*4$vX', # 3 IPv6 addresses
16969 @addr[1..3], ":";
16970
16971=item (minimum) width
16972
16973((最小)幅)
16974
16975=begin original
16976
16977Arguments are usually formatted to be only as wide as required to
16978display the given value. You can override the width by putting
16979a number here, or get the width from the next argument (with C<*>)
16980or from a specified argument (e.g., with C<*2$>):
16981
16982=end original
16983
16984引数は、普通は値を表示するのに必要なちょうどの幅でフォーマットされます。
16985ここに数値を置くか、(C<*> で)次の引数か(C<*2$> で)明示的に指定した引数で
16986幅を上書きできます。
16987
16988 printf "<%s>", "a"; # prints "<a>"
16989 printf "<%6s>", "a"; # prints "< a>"
16990 printf "<%*s>", 6, "a"; # prints "< a>"
16991 printf '<%*2$s>', "a", 6; # prints "< a>"
16992 printf "<%2s>", "long"; # prints "<long>" (does not truncate)
16993
16994=begin original
16995
169969844If a field width obtained through C<*> is negative, it has the same
169979845effect as the C<-> flag: left-justification.
169989846
169999847=end original
170009848
9849フラグとして数値を使えるところでは、代わりにアスタリスク (C<*>) を
9850使うことができます: その場合、Perl はパラメータリストの次の要素を
9851与えられた数値(フィールド幅か精度)として使います。
170019852C<*> を通して得られたフィールドの値が負数の場合、C<-> フラグと
170029853同様の効果 (左詰め) があります。
170039854
17004=item precision, or maximum width
17005X<precision>
17006
17007(精度あるいは最大幅)
17008
170099855=begin original
170109856
17011You can specify a precision (for numeric conversions) or a maximum
9857The C<v> flag is useful for displaying ordinal values of characters
17012width (for string conversions) by specifying a C<.> followed by a number.
9858in arbitrary strings:
17013For floating-point formats except C<g> and C<G>, this specifies
17014how many places right of the decimal point to show (the default being 6).
17015For example:
170169859
170179860=end original
170189861
17019C<.> の後に数値を指定することで、(数値変換の場合)精度や(文字列変換場合)
9862C<v> フラグは任意の文字列の文字を順序付きの値として表示するのに
17020最大幅を指定きま
9863便利です:
17021小数点数フォーマットの場合、C<g> と C<G> を除いて、表示する小数点以下の
17022桁数を指定します(デフォルトは 6 です)。
17023例えば:
170249864
17025 # these examples are subject to system-specific variation
9865 printf "version is v%vd\n", $^V; # Perl's version
17026 printf '<%f>', 1; # prints "<1.000000>"
9866 printf "address is %*vX\n", ":", $addr; # IPv6 address
17027 printf '<%.1f>', 1; # prints "<1.0>"
9867 printf "bits are %*vb\n", " ", $bits; # random bitstring
17028 printf '<%.0f>', 1; # prints "<1>"
17029 printf '<%e>', 10; # prints "<1.000000e+01>"
17030 printf '<%.1e>', 10; # prints "<1.0e+01>"
170319868
170329869=begin original
170339870
17034For "g" and "G", this specifies the maximum number of significant digits to
9871If C<use locale> is in effect, the character used for the decimal
17035show; for example:
9872point in formatted real numbers is affected by the LC_NUMERIC locale.
9873See L<perllocale>.
170369874
170379875=end original
170389876
17039"g" "G" の場合、は最大有効字を指定ます; 例えば:
9877C<use locale> が有効の場合、フォーマットさた実の小数点と
9878使われる文字は LC_NUMERIC ロケールの影響を受けます。
9879L<perllocale> を参照してください。
170409880
17041 # These examples are subject to system-specific variation.
17042 printf '<%g>', 1; # prints "<1>"
17043 printf '<%.10g>', 1; # prints "<1>"
17044 printf '<%g>', 100; # prints "<100>"
17045 printf '<%.1g>', 100; # prints "<1e+02>"
17046 printf '<%.2g>', 100.01; # prints "<1e+02>"
17047 printf '<%.5g>', 100.01; # prints "<100.01>"
17048 printf '<%.4g>', 100.01; # prints "<100>"
17049 printf '<%.1g>', 0.0111; # prints "<0.01>"
17050 printf '<%.2g>', 0.0111; # prints "<0.011>"
17051 printf '<%.3g>', 0.0111; # prints "<0.0111>"
17052
170539881=begin original
170549882
17055For integer conversions, specifying a precision implies that the
9883If Perl understands "quads" (64-bit integers) (this requires
17056output of the number itself should be zero-padded to this width,
9884either that the platform natively support quads or that Perl
17057where the 0 flag is ignored:
9885be specifically compiled to support quads), the characters
170589886
170599887=end original
170609888
17061整数変換の場合、精度指定すると、数値自体の出力はの幅 0
9889Perl が 64 ビット整数を理解する場合(はプラットフォームが内部
17062ディングすべきであることを暗ことなり、0 フラグは
989064 ビト整数に対応していか、Perl が特別 64ビット整数に対応るよう
17063無視されます:
9891コンパイルされている必要があります)、以下の文字には:
170649892
17065 printf '<%.6d>', 1; # prints "<000001>"
9893 d u o x X b i D U O
17066 printf '<%+.6d>', 1; # prints "<+000001>"
17067 printf '<%-10.6d>', 1; # prints "<000001 >"
17068 printf '<%10.6d>', 1; # prints "< 000001>"
17069 printf '<%010.6d>', 1; # prints "< 000001>"
17070 printf '<%+10.6d>', 1; # prints "< +000001>"
170719894
17072 printf '<%.6x>', 1; # prints "<000001>"
17073 printf '<%#.6x>', 1; # prints "<0x000001>"
17074 printf '<%-10.6x>', 1; # prints "<000001 >"
17075 printf '<%10.6x>', 1; # prints "< 000001>"
17076 printf '<%010.6x>', 1; # prints "< 000001>"
17077 printf '<%#10.6x>', 1; # prints "< 0x000001>"
17078
170799895=begin original
170809896
17081For string conversions, specifying a precision truncates the string
9897print quads, and they may optionally be preceded by
17082to fit the specified width:
170839898
170849899=end original
170859900
17086文字列変換の場合、精度指定すると指定され収まように文字列を
990164 ビット整数表示し以下のフラグを前つけことができます:
17087切り詰めます:
170889902
17089 printf '<%.5s>', "truncated"; # prints "<trunc>"
9903 ll L q
17090 printf '<%10.5s>', "truncated"; # prints "< trunc>"
170919904
170929905=begin original
170939906
17094You can also get the precision from the next argument using C<.*>, or from a
9907For example
17095specified argument (e.g., with C<.*2$>):
170969908
170979909=end original
170989910
17099C<.*> を使って精度を次引数から取ったり、
9911例えば以下ようにします:
17100(C<.*2$> のように) 指定した引数から取ったりすることもできます:
171019912
17102 printf '<%.6x>', 1; # prints "<000001>"
9913 %lld %16LX %qo
17103 printf '<%.*x>', 6, 1; # prints "<000001>"
171049914
17105 printf '<%.*2$x>', 1, 6; # prints "<000001>"
17106
17107 printf '<%6.*2$x>', 1, 4; # prints "< 0001>"
17108
171099915=begin original
171109916
17111If a precision obtained through C<*> is negative, it counts
17112as having no precision at all.
17113
17114=end original
17115
17116C<*> によって得られた精度が負数の場合、精度が指定されなかった場合と
17117同じ効果となります。
17118
17119 printf '<%.*s>', 7, "string"; # prints "<string>"
17120 printf '<%.*s>', 3, "string"; # prints "<str>"
17121 printf '<%.*s>', 0, "string"; # prints "<>"
17122 printf '<%.*s>', -1, "string"; # prints "<string>"
17123
17124 printf '<%.*d>', 1, 0; # prints "<0>"
17125 printf '<%.*d>', 0, 0; # prints "<>"
17126 printf '<%.*d>', -1, 0; # prints "<0>"
17127
17128=item size
17129
17130(サイズ)
17131
17132=begin original
17133
17134For numeric conversions, you can specify the size to interpret the
17135number as using C<l>, C<h>, C<V>, C<q>, C<L>, or C<ll>. For integer
17136conversions (C<d u o x X b i D U O>), numbers are usually assumed to be
17137whatever the default integer size is on your platform (usually 32 or 64
17138bits), but you can override this to use instead one of the standard C types,
17139as supported by the compiler used to build Perl:
17140
17141=end original
17142
17143数値変換では、C<l>, C<h>, C<V>, C<q>, C<L>, C<ll> を使って解釈する数値の
17144大きさを指定できます。
17145整数変換 (C<d u o x X b i D U O>) では、数値は通常プラットフォームの
17146デフォルトの整数のサイズ (通常は 32 ビットか 64 ビット) を仮定しますが、
17147これを Perl がビルドされたコンパイラが対応している標準 C の型の一つで
17148上書きできます:
17149
17150=begin original
17151
17152 hh interpret integer as C type "char" or "unsigned
17153 char" on Perl 5.14 or later
17154 h interpret integer as C type "short" or
17155 "unsigned short"
17156 j interpret integer as C type "intmax_t" on Perl
17157 5.14 or later; and prior to Perl 5.30, only with
17158 a C99 compiler (unportable)
17159 l interpret integer as C type "long" or
17160 "unsigned long"
17161 q, L, or ll interpret integer as C type "long long",
17162 "unsigned long long", or "quad" (typically
17163 64-bit integers)
17164 t interpret integer as C type "ptrdiff_t" on Perl
17165 5.14 or later
17166 z interpret integer as C type "size_t" on Perl 5.14
17167 or later
17168
17169=end original
17170
17171 hh Perl 5.14 以降で整数を C の "char" または "unsigned char"
17172 型として解釈する
17173 h 整数を C の "char" または "unsigned char" 型として解釈する
17174 j Perl 5.14 以降 Perl 5.30 以前の C99 コンパイラのみで整数を
17175 C の "intmax_t" 型として解釈する (移植性なし)
17176 l 整数を C の "long" または "unsigned long" と解釈する
17177 h 整数を C の "short" または "unsigned short" と解釈する
17178 q, L or ll 整数を C の "long long", "unsigned long long",
17179 "quads"(典型的には 64 ビット整数) のどれかと解釈する
17180 t Perl 5.14 以降で整数を C の "ptrdiff_t" 型として解釈する
17181 z Perl 5.14 以降で整数を C の "size_t" 型として解釈する
17182
17183=begin original
17184
17185As of 5.14, none of these raises an exception if they are not supported on
17186your platform. However, if warnings are enabled, a warning of the
17187L<C<printf>|warnings> warning class is issued on an unsupported
17188conversion flag. Should you instead prefer an exception, do this:
17189
17190=end original
17191
171925.14 から、プラットフォームがこれらに対応していないときでも例外が
17193発生しなくなりました。
17194しかし、もし警告が有効になっているなら、
17195非対応変換フラグに関して L<C<printf>|warnings> 警告クラスの警告が発生します。
17196例外の方がお好みなら、以下のようにします:
17197
17198 use warnings FATAL => "printf";
17199
17200=begin original
17201
17202If you would like to know about a version dependency before you
17203start running the program, put something like this at its top:
17204
17205=end original
17206
17207プログラムの実行開始前にバージョン依存について知りたいなら、先頭に
17208以下のようなものを書きます:
17209
17210 use 5.014; # for hh/j/t/z/ printf modifiers
17211
17212=begin original
17213
172149917You can find out whether your Perl supports quads via L<Config>:
172159918
172169919=end original
172179920
172189921Perl が 64 ビット整数に対応しているかどうかは L<Config> を使って
172199922調べられます:
172209923
17221 use Config;
9924 use Config;
17222 if ($Config{use64bitint} eq "define"
9925 ($Config{use64bitint} eq 'define' || $Config{longsize} == 8) &&
17223 || $Config{longsize} >= 8) {
9926 print "quads\n";
17224 print "Nice quads!\n";
17225 }
172269927
172279928=begin original
172289929
17229For floating-point conversions (C<e f g E F G>), numbers are usually assumed
9930If Perl understands "long doubles" (this requires that the platform
17230to be the default floating-point size on your platform (double or long double),
9931support long doubles), the flags
17231but you can force "long double" with C<q>, C<L>, or C<ll> if your
17232platform supports them. You can find out whether your Perl supports long
17233doubles via L<Config>:
172349932
172359933=end original
172369934
17237浮動小数点数変換 (C<e f g E F G>) で、普通はプラットフォームのデフォルトの
9935Perl "long double" を理解する場合(これにはプラットフォーム
17238不動小数点数のサイズ (double か long double) を仮定します
9936long double に対応ている必要があります)以下の文字には:
17239プラットフォームが対応しているなら、C<q>, C<L>, C<ll> に対して
17240"long double" を強制できます。
17241Perl が long double に対応しているかどうかは L<Config> を使って
17242調べられます:
172439937
17244 use Config;
9938 e f g E F G
17245 print "long doubles\n" if $Config{d_longdbl} eq "define";
172469939
172479940=begin original
172489941
17249You can find out whether Perl considers "long double" to be the default
9942may optionally be preceded by
17250floating-point size to use on your platform via L<Config>:
172519943
172529944=end original
172539945
17254Perl が "long double" をデフォルト浮動小数点数として扱っていかどうかは
9946以下フラグを前につけことができます:
17255L<Config> を使って調べられます:
172569947
17257 use Config;
9948 ll L
17258 if ($Config{uselongdouble} eq "define") {
17259 print "long doubles by default\n";
17260 }
172619949
172629950=begin original
172639951
17264It can also be that long doubles and doubles are the same thing:
9952For example
172659953
172669954=end original
172679955
17268long double と double が同じ場合もあります:
9956例えば以下のようにします:
172699957
17270 use Config;
9958 %llf %Lg
17271 ($Config{doublesize} == $Config{longdblsize}) &&
17272 print "doubles are long doubles\n";
172739959
172749960=begin original
172759961
17276The size specifier C<V> has no effect for Perl code, but is supported for
9962You can find out whether your Perl supports long doubles via L<Config>:
17277compatibility with XS code. It means "use the standard size for a Perl
17278integer or floating-point number", which is the default.
172799963
172809964=end original
172819965
17282サイズ指定子 C<V> は Perl のコードには何の影響もありませんが、これは
9966Perl が long double 対応しているかどうか L<Config> を使って
17283XS コードとの互換性のために対応しています
9967調べられます:
17284これは「Perl 整数 (または浮動小数点数) として標準的なサイズを使う」ことを
17285意味し、これはデフォルトです。
172869968
17287=item order of arguments
9969 use Config;
9970 $Config{d_longdbl} eq 'define' && print "long doubles\n";
172889971
17289(引数の順序)
9972=item sqrt EXPR
172909973
17291=begin original
9974=item sqrt
172929975
17293Normally, L<C<sprintf>|/sprintf FORMAT, LIST> takes the next unused
17294argument as the value to
17295format for each format specification. If the format specification
17296uses C<*> to require additional arguments, these are consumed from
17297the argument list in the order they appear in the format
17298specification I<before> the value to format. Where an argument is
17299specified by an explicit index, this does not affect the normal
17300order for the arguments, even when the explicitly specified index
17301would have been the next argument.
17302
17303=end original
17304
17305通常、L<C<sprintf>|/sprintf FORMAT, LIST> は各フォーマット指定について、
17306使われていない次の引数を
17307フォーマットする値として使います。
17308追加の引数を要求するためにフォーマット指定 C<*> を使うと、
17309これらはフォーマットする値の I<前> のフォーマット指定に現れる順番に
17310引数リストから消費されます。
17311引数の位置が明示的なインデックスを使って指定された場合、
17312(明示的に指定したインデックスが次の引数の場合でも)
17313これは通常の引数の順番に影響を与えません。
17314
173159976=begin original
173169977
17317So:
9978Return the square root of EXPR. If EXPR is omitted, returns square
9979root of C<$_>. Only works on non-negative operands, unless you've
9980loaded the standard Math::Complex module.
173189981
173199982=end original
173209983
17321それで:
9984EXPR の平方根を返します。
9985EXPR を省略すると、C<$_> の平方根を返します。
9986標準の Math::Complex モジュールを使わない場合は、
9987負の数の引数は扱えません。
173229988
17323 printf "<%*.*s>", $a, $b, $c;
9989 use Math::Complex;
9990 print sqrt(-2); # prints 1.4142135623731i
173249991
17325=begin original
9992=item srand EXPR
173269993
17327uses C<$a> for the width, C<$b> for the precision, and C<$c>
9994=item srand
17328as the value to format; while:
173299995
17330=end original
17331
17332とすると C<$a> を幅に、C<$b> を精度に、C<$c> をフォーマットの値に
17333使います; 一方:
17334
17335 printf '<%*1$.*s>', $a, $b;
17336
173379996=begin original
173389997
17339would use C<$a> for the width and precision, and C<$b> as the
9998Sets the random number seed for the C<rand> operator. If EXPR is
17340value to format.
9999omitted, uses a semi-random value supplied by the kernel (if it supports
10000the F</dev/urandom> device) or based on the current time and process
10001ID, among other things. In versions of Perl prior to 5.004 the default
10002seed was just the current C<time>. This isn't a particularly good seed,
10003so many old programs supply their own seed value (often C<time ^ $$> or
10004C<time ^ ($$ + ($$ << 15))>), but that isn't necessary any more.
1734110005
1734210006=end original
1734310007
17344とすると C<$a> を幅と精度に、C<$b> をフォーマットの値に使います。
10008rand 演算子ためのシードを設定します。
10009EXPR を省略すると、カーネルで提供されるもの
10010(F</dev/urandom> デバイスに対応している場合)または
10011現在時刻やプロセス ID やその他のものを基礎にした
10012擬似乱数を使います。
100135.004 以前の Perl では、デフォルトのシード値は現在の C<time> でした。
10014これは特によいシード値ではありませんでしたので、
10015多くの古いプログラムは自力でシード値を指定しています
10016(C<time ^ $$> または C<time ^ ($$ + ($$ << 15))> がよく使われました)が、
10017もはやこれは必要ありません。
1734510018
1734610019=begin original
1734710020
17348Here are some more examples; be aware that when using an explicit
10021In fact, it's usually not necessary to call C<srand> at all, because if
17349index, the C<$> may need escaping:
10022it is not called explicitly, it is called implicitly at the first use of
10023the C<rand> operator. However, this was not the case in version of Perl
10024before 5.004, so if your script will run under older Perl versions, it
10025should call C<srand>.
1735010026
1735110027=end original
1735210028
17353以下にさらなる例を示します; 明示的にインデックスを使う場合、C<$> は
10029実際普通は C<srand> を呼び出す必要全くありません。
17354エスケープする必要があること注意してください:
10030明示的呼び出れな場合、C<rand> 演算子を最初に使ったときに
10031自動的に呼び出されるからです。
10032しかし、5.004 以前のバージョンの Perl ではこれは行われないので、
10033古い Perl で動作させる可能性がある場合は、C<srand> を呼び出すべきです。
1735510034
17356 printf "%2\$d %d\n", 12, 34; # will print "34 12\n"
17357 printf "%2\$d %d %d\n", 12, 34; # will print "34 12 34\n"
17358 printf "%3\$d %d %d\n", 12, 34, 56; # will print "56 12 34\n"
17359 printf "%2\$*3\$d %d\n", 12, 34, 3; # will print " 34 12\n"
17360 printf "%*1\$.*f\n", 4, 5, 10; # will print "5.0000\n"
17361
17362=back
17363
1736410035=begin original
1736510036
17366If L<C<use locale>|locale> (including C<use locale ':not_characters'>)
10037Note that you need something much more random than the default seed for
17367is in effect and L<C<POSIX::setlocale>|POSIX/C<setlocale>> has been
10038cryptographic purposes. Checksumming the compressed output of one or more
17368called,
10039rapidly changing operating system status programs is the usual method. For
17369the character used for the decimal separator in formatted floating-point
10040example:
17370numbers is affected by the C<LC_NUMERIC> locale. See L<perllocale>
17371and L<POSIX>.
1737210041
1737310042=end original
1737410043
17375(C<use locale ':not_characters'> を含む)L<C<use locale>|locale> が有効で
10044暗号処理には
17376L<C<POSIX::setlocale>|POSIX/C<setlocale>> 呼び出されてい場合、
10045もっとランダムな値を使う必要あります。急激に変化す
17377フォマットされた浮動小数点数小数点して使われる文字は
10046OS のステタス値プログラム出力をひ
17378C<LC_NUMERIC> ロケールの影響を受けす。
10047たは複数用い、圧縮してチェックサムをとる、
17379L<perllocale> L<POSIX> を参照してください。
10048というようなことが普通、行なわれます
10049例えば:
1738010050
17381=item sqrt EXPR
10051 srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
17382X<sqrt> X<root> X<square root>
1738310052
17384=item sqrt
17385
17386=for Pod::Functions square root function
17387
1738810053=begin original
1738910054
17390Return the positive square root of EXPR. If EXPR is omitted, uses
10055If you're particularly concerned with this, see the C<Math::TrulyRandom>
17391L<C<$_>|perlvar/$_>. Works only for non-negative operands unless you've
10056module in CPAN.
17392loaded the L<C<Math::Complex>|Math::Complex> module.
1739310057
1739410058=end original
1739510059
17396EXPR 正の平方根を返します。
10060特にこようなことに関心がある場合は、
17397EXPR が省略されると、L<C<$_>|perlvar/$_> を使ます
10061CPAN C<Math::TrulyRandom> モジュール参照して下さい。
17398L<C<Math::Complex>|Math::Complex> モジュールを使わない場合は、負の数の引数は
17399扱えません。
1740010062
17401 use Math::Complex;
17402 print sqrt(-4); # prints 2i
17403
17404=item srand EXPR
17405X<srand> X<seed> X<randseed>
17406
17407=item srand
17408
17409=for Pod::Functions seed the random number generator
17410
1741110063=begin original
1741210064
17413Sets and returns the random number seed for the L<C<rand>|/rand EXPR>
10065Do I<not> call C<srand> multiple times in your program unless you know
17414operator.
10066exactly what you're doing and why you're doing it. The point of the
10067function is to "seed" the C<rand> function so that C<rand> can produce
10068a different sequence each time you run your program. Just do it once at the
10069top of your program, or you I<won't> get random numbers out of C<rand>!
1741510070
1741610071=end original
1741710072
17418L<C<rand>|/rand EXPR> 演算子のためのシード値設定して
10073をしようとしいるか、そてなぜそうるのかを正確に把握していない限り、
10074C<srand> をプログラム中でI<複数回呼び出してはいけません>。
10075この関数のポイントは、プログラムを実行するごとに C<rand> 関数が
10076異なる乱数列を生成できるように C<rand> 関数の「種」を設定することです。
10077単にプログラムの先頭で一回だけ呼び出してください。
10078さもなければ C<rand> で乱数を I<得られません>!
1741910079
1742010080=begin original
1742110081
17422The point of the function is to "seed" the L<C<rand>|/rand EXPR>
10082Frequently called programs (like CGI scripts) that simply use
17423function so that L<C<rand>|/rand EXPR> can produce a different sequence
17424each time you run your program. When called with a parameter,
17425L<C<srand>|/srand EXPR> uses that for the seed; otherwise it
17426(semi-)randomly chooses a seed. In either case, starting with Perl 5.14,
17427it returns the seed. To signal that your code will work I<only> on Perls
17428of a recent vintage:
1742910083
1743010084=end original
1743110085
17432この関数のポインは、プログラムを実行するごと L<C<rand>|/rand EXPR> 関数が
10086(CGI スクリプのような)頻繁に呼び出されるプログラムで単純
17433異なる乱数列を生成できるように L<C<rand>|/rand EXPR> 関数の「種」を
17434設定することです。
17435L<C<srand>|/srand EXPR> を引数付きで呼び出すと、これを種として使います;
17436さもなければ(だいたい)ランダムに種を選びます。
17437どちらの場合でも、Perl 5.14 からは種を返します。
17438特定の時期の Perl I<でのみ> 動作することを知らせるには以下のようにします:
1743910087
17440 use 5.014; # so srand returns the seed
10088 time ^ $$
1744110089
1744210090=begin original
1744310091
17444If L<C<srand>|/srand EXPR> is not called explicitly, it is called
10092for a seed can fall prey to the mathematical property that
17445implicitly without a parameter at the first use of the
17446L<C<rand>|/rand EXPR> operator. However, there are a few situations
17447where programs are likely to want to call L<C<srand>|/srand EXPR>. One
17448is for generating predictable results, generally for testing or
17449debugging. There, you use C<srand($seed)>, with the same C<$seed> each
17450time. Another case is that you may want to call L<C<srand>|/srand EXPR>
17451after a L<C<fork>|/fork> to avoid child processes sharing the same seed
17452value as the parent (and consequently each other).
1745310093
1745410094=end original
1745510095
17456L<C<srand>|/srand EXPR> が明示的呼び出されなかった場合、最初に
10096を種として使うと、3 1 回は以下の数学特性
17457L<C<rand>|/rand EXPR> 演算子を使った時点で暗黙に引数なしで呼び出されます。
17458しかし、最近の Perl でプログラムが L<C<srand>|/srand EXPR> を
17459呼び出したいであろう状況がいくつかあります。
17460一つはテストやデバッグのために予測可能な結果を生成するためです。
17461この場合、C<srand($seed)> (C<$seed> は毎回同じ値を使う) を使います。
17462もう一つの場合としては、子プロセスが親や他の子プロセスと同じ種の値を
17463共有することを避けるために、L<C<fork>|/fork> の後に L<C<srand>|/srand EXPR> を
17464呼び出したいかもしれません。
1746510097
17466=begin original
10098 a^b == (a+1)^(b+1)
1746710099
17468Do B<not> call C<srand()> (i.e., without an argument) more than once per
17469process. The internal state of the random number generator should
17470contain more entropy than can be provided by any seed, so calling
17471L<C<srand>|/srand EXPR> again actually I<loses> randomness.
17472
17473=end original
17474
17475L<C<srand>|/srand EXPR> (引数なし)をプロセス中で複数回
17476呼び出しては B<いけません>。
17477乱数生成器の内部状態はどのような種によって提供されるものよりも
17478高いエントロピーを持っているので、C<srand()> を再び呼び出すと
17479ランダム性が I<失われます>。
17480
1748110100=begin original
1748210101
17483Most implementations of L<C<srand>|/srand EXPR> take an integer and will
10102one-third of the time. So don't do that.
17484silently
17485truncate decimal numbers. This means C<srand(42)> will usually
17486produce the same results as C<srand(42.1)>. To be safe, always pass
17487L<C<srand>|/srand EXPR> an integer.
1748810103
1748910104=end original
1749010105
17491L<C<srand>|/srand EXPR> ほとんどの実装では整数を取り、小数を暗黙
10106餌食なります。
17492切り捨てま
10107従っこのようなことはしてはいけせん
17493これは、C<srand(42)> は普通 C<srand(42.1)> と同じ結果になることを意味します。
17494安全のために、L<C<srand>|/srand EXPR> には常に整数を渡しましょう。
1749510108
17496=begin original
17497
17498A typical use of the returned seed is for a test program which has too many
17499combinations to test comprehensively in the time available to it each run. It
17500can test a random subset each time, and should there be a failure, log the seed
17501used for that run so that it can later be used to reproduce the same results.
17502
17503=end original
17504
17505返された種の典型的な利用法は、実行毎のテストを利用可能な時間内に完全に
17506行うには組み合わせが多すぎるテストプログラム用です。
17507毎回ランダムなサブセットをテストし、もし失敗したら、その実行で使った
17508種をログに出力することで、後で同じ結果を再現するために使えます。
17509
17510=begin original
17511
17512B<L<C<rand>|/rand EXPR> is not cryptographically secure. You should not rely
17513on it in security-sensitive situations.> As of this writing, a
17514number of third-party CPAN modules offer random number generators
17515intended by their authors to be cryptographically secure,
17516including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
17517and L<Math::TrulyRandom>.
17518
17519=end original
17520
17521B<L<C<rand>|/rand EXPR> は暗号学的に安全ではありません。
17522セキュリティ的に重要な状況でこれに頼るべきではありません。>
17523これを書いている時点で、いくつかのサードパーティ CPAN モジュールが
17524作者によって暗号学的に安全であることを目的とした乱数生成器を
17525提供しています: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
17526L<Math::TrulyRandom> などです。
17527
1752810109=item stat FILEHANDLE
17529X<stat> X<file, status> X<ctime>
1753010110
1753110111=item stat EXPR
1753210112
17533=item stat DIRHANDLE
17534
1753510113=item stat
1753610114
17537=for Pod::Functions get a file's status information
17538
1753910115=begin original
1754010116
1754110117Returns a 13-element list giving the status info for a file, either
17542the file opened via FILEHANDLE or DIRHANDLE, or named by EXPR. If EXPR is
10118the file opened via FILEHANDLE, or named by EXPR. If EXPR is omitted,
17543omitted, it stats L<C<$_>|perlvar/$_> (not C<_>!). Returns the empty
10119it stats C<$_>. Returns a null list if the stat fails. Typically used
17544list if L<C<stat>|/stat FILEHANDLE> fails. Typically
10120as follows:
17545used as follows:
1754610121
1754710122=end original
1754810123
17549FILEHANDLE か DIRHANDLE を通じてオープンされているファイルか、
10124FILEHANDLE を通じてオープンされているファイルか、
1755010125EXPR で指定されるファイルの情報を与える、13 要素のリストを返します。
17551EXPR が省略されると、 L<C<$_>|perlvar/$_> が用いられます
10126EXPR が省略されると、 C<$_> が用いられます
17552(C<_> ありせん!)
10127stat に失敗した場合に、空リストを返し
17553L<C<stat>|/stat FILEHANDLE> に失敗した場合には、空リストを返します。
1755410128普通は、以下のようにして使います:
1755510129
17556 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
10130 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
17557 $atime,$mtime,$ctime,$blksize,$blocks)
10131 $atime,$mtime,$ctime,$blksize,$blocks)
1755810132 = stat($filename);
1755910133
1756010134=begin original
1756110135
1756210136Not all fields are supported on all filesystem types. Here are the
17563meanings of the fields:
10137meaning of the fields:
1756410138
1756510139=end original
1756610140
1756710141全てのファイルシステムで全てのフィールドに対応しているわけではありません。
1756810142フィールドの意味は以下の通りです。
1756910143
1757010144=begin original
1757110145
1757210146 0 dev device number of filesystem
1757310147 1 ino inode number
1757410148 2 mode file mode (type and permissions)
1757510149 3 nlink number of (hard) links to the file
1757610150 4 uid numeric user ID of file's owner
1757710151 5 gid numeric group ID of file's owner
1757810152 6 rdev the device identifier (special files only)
1757910153 7 size total size of file, in bytes
1758010154 8 atime last access time in seconds since the epoch
1758110155 9 mtime last modify time in seconds since the epoch
17582 10 ctime inode change time in seconds since the epoch (*)
10156 10 ctime inode change time (NOT creation time!) in seconds since the epoch
17583 11 blksize preferred I/O size in bytes for interacting with the
10157 11 blksize preferred block size for file system I/O
17584 file (may vary from file to file)
10158 12 blocks actual number of blocks allocated
17585 12 blocks actual number of system-specific blocks allocated
17586 on disk (often, but not always, 512 bytes each)
1758710159
10160(The epoch was at 00:00 January 1, 1970 GMT.)
10161
1758810162=end original
1758910163
1759010164 0 dev ファイルシステムのデバイス番号
1759110165 1 ino inode 番号
1759210166 2 mode ファイルモード (タイプとパーミッション)
1759310167 3 nlink ファイルへの(ハード)リンクの数
1759410168 4 uid ファイル所有者のユーザー ID の数値
1759510169 5 gid ファイル所有者のグループ ID の数値
1759610170 6 rdev デバイス識別子(特殊ファイルのみ)
1759710171 7 size ファイルサイズ(バイト単位)
1759810172 8 atime 紀元から、最後にアクセスされた時刻までの秒数
1759910173 9 mtime 紀元から、最後に修正(modify)された時刻までの秒数
17600 10 ctime 紀元から、inode 変更(change)された時刻までの秒数 (*)
10174 10 ctime 紀元から、inode 変更(change)された時刻(作成された時刻ではない!)までの秒数
17601 11 blksize ファイルとの相互作用のために適した I/O ト数
10175 11 blksize ファイルシステム I/O に適したブロックサ
17602 (ファイルごと異なるかもし)
10176 12 blocks 実際割り当てらるブロックの数
17603 12 blocks ディスクに割り当てたシステム依存のブロック(常にでは
17604 ありませんがたいていはそれぞれ 512 バイト)の数
1760510177
17606=begin original
10178(紀元は GMT で 1970/01/01 00:00:00)
1760710179
17608(The epoch was at 00:00 January 1, 1970 GMT.)
17609
17610=end original
17611
17612(紀元は GMT で 1970/01/01 00:00:00。)
17613
1761410180=begin original
1761510181
17616(*) Not all fields are supported on all filesystem types. Notably, the
10182If stat is passed the special filehandle consisting of an underline, no
17617ctime field is non-portable. In particular, you cannot expect it to be a
10183stat is done, but the current contents of the stat structure from the
17618"creation time"; see L<perlport/"Files and Filesystems"> for details.
10184last stat or filetest are returned. Example:
1761910185
1762010186=end original
1762110187
17622(*) 全てのフィールドが全てのファイルシステムタイプで対応しているわけでは
10188下線だけ _ という特別なファイルハンドルを stat に渡すと、
17623ありません。
10189実際には stat を行なわず、stat 構造体に残っている
17624明らかに、ctime ィードは移植性ありせん
10190前回の stat ァイテストの情報返され
17625特に、これから「作成時刻」を想定することは出来ません;
17626詳細については L<perlport/"Files and Filesystems"> を参照してください。
17627
17628=begin original
17629
17630If L<C<stat>|/stat FILEHANDLE> is passed the special filehandle
17631consisting of an underline, no stat is done, but the current contents of
17632the stat structure from the last L<C<stat>|/stat FILEHANDLE>,
17633L<C<lstat>|/lstat FILEHANDLE>, or filetest are returned. Example:
17634
17635=end original
17636
17637下線だけの _ という特別なファイルハンドルを L<C<stat>|/stat FILEHANDLE> に
17638渡すと、実際には stat を行なわず、stat 構造体に残っている
17639前回の L<C<stat>|/stat FILEHANDLE>, L<C<lstat>|/lstat FILEHANDLE> や
17640ファイルテストの情報が返されます。
1764110191例:
1764210192
1764310193 if (-x $file && (($d) = stat(_)) && $d < 0) {
17644 print "$file is executable NFS file\n";
10194 print "$file is executable NFS file\n";
1764510195 }
1764610196
1764710197=begin original
1764810198
1764910199(This works on machines only for which the device number is negative
1765010200under NFS.)
1765110201
1765210202=end original
1765310203
17654(これは、NFS のもとでデバイス番号が負になるマシンでのみ動作します。)
10204(これは、NFS のもとでデバイス番号が負になるマシンで
10205のみ動作します。)
1765510206
1765610207=begin original
1765710208
17658On some platforms inode numbers are of a type larger than perl knows how
17659to handle as integer numerical values. If necessary, an inode number will
17660be returned as a decimal string in order to preserve the entire value.
17661If used in a numeric context, this will be converted to a floating-point
17662numerical value, with rounding, a fate that is best avoided. Therefore,
17663you should prefer to compare inode numbers using C<eq> rather than C<==>.
17664C<eq> will work fine on inode numbers that are represented numerically,
17665as well as those represented as strings.
17666
17667=end original
17668
17669一部のプラットフォームでは、inode 番号は perl が整数値として
17670扱い方を知っているものよりも大きい型になっています。
17671もし必要なら、inode 番号は、値全体を保存するために 10 進文字列として
17672返されます。
17673数値コンテキストで使うと、これは丸めを伴う浮動小数点数に変換され、
17674できるだけ避けるべき結果になります。
17675従って、inode 番号の比較には C<==> ではなく C<eq> を使うべきです。
17676C<eq> は、inode 番号が数値で表現されていても、文字列で表現されていても
17677うまく動作します。
17678
17679=begin original
17680
1768110209Because the mode contains both the file type and its permissions, you
17682should mask off the file type portion and (s)printf using a C<"%o">
10210should mask off the file type portion and (s)printf using a C<"%o">
1768310211if you want to see the real permissions.
1768410212
1768510213=end original
1768610214
1768710215モードにはファイルタイプとその権限の両方が含まれているので、
1768810216本当の権限を見たい場合は、(s)printf で C<"%"> を使うことで
1768910217ファイルタイプをマスクするべきです。
1769010218
17691 my $mode = (stat($filename))[2];
10219 $mode = (stat($filename))[2];
1769210220 printf "Permissions are %04o\n", $mode & 07777;
1769310221
1769410222=begin original
1769510223
17696In scalar context, L<C<stat>|/stat FILEHANDLE> returns a boolean value
10224In scalar context, C<stat> returns a boolean value indicating success
17697indicating success
1769810225or failure, and, if successful, sets the information associated with
1769910226the special filehandle C<_>.
1770010227
1770110228=end original
1770210229
17703スカラコンテキストでは、L<C<stat>|/stat FILEHANDLE> は成功か失敗を表す真偽値を
10230スカラコンテキストでは、C<stat> は成功か失敗を表す真偽値を返し、
17704返し、成功した場合は、特別なファイルハンドル C<_> に結び付けられた
10231成功した場合は、特別なファイルハンドル C<_> に結び付けられた
1770510232情報をセットします。
1770610233
1770710234=begin original
1770810235
17709The L<File::stat> module provides a convenient, by-name access mechanism:
10236The File::stat module provides a convenient, by-name access mechanism:
1771010237
1771110238=end original
1771210239
17713L<File::stat> モジュールは、便利な名前によるアクセス機構を提供します。
10240File::stat モジュールは、便利な名前によるアクセス機構を提供します。
1771410241
1771510242 use File::stat;
17716 my $sb = stat($filename);
10243 $sb = stat($filename);
17717 printf "File is %s, size is %s, perm %04o, mtime %s\n",
10244 printf "File is %s, size is %s, perm %04o, mtime %s\n",
17718 $filename, $sb->size, $sb->mode & 07777,
10245 $filename, $sb->size, $sb->mode & 07777,
17719 scalar localtime $sb->mtime;
10246 scalar localtime $sb->mtime;
1772010247
1772110248=begin original
1772210249
1772310250You can import symbolic mode constants (C<S_IF*>) and functions
17724(C<S_IS*>) from the L<Fcntl> module:
10251(C<S_IS*>) from the Fcntl module:
1772510252
1772610253=end original
1772710254
17728モード定数 (C<S_IF*>) と関数 (C<S_IS*>) を L<Fcntl> モジュールから
10255モード定数 (C<S_IF*>) と関数 (C<S_IS*>) を Fcntl モジュールから
1772910256インポートできます。
1773010257
1773110258 use Fcntl ':mode';
1773210259
17733 my $mode = (stat($filename))[2];
10260 $mode = (stat($filename))[2];
1773410261
17735 my $user_rwx = ($mode & S_IRWXU) >> 6;
10262 $user_rwx = ($mode & S_IRWXU) >> 6;
17736 my $group_read = ($mode & S_IRGRP) >> 3;
10263 $group_read = ($mode & S_IRGRP) >> 3;
17737 my $other_execute = $mode & S_IXOTH;
10264 $other_execute = $mode & S_IXOTH;
1773810265
17739 printf "Permissions are %04o\n", S_IMODE($mode), "\n";
10266 printf "Permissions are %04o\n", S_ISMODE($mode), "\n";
1774010267
17741 my $is_setuid = $mode & S_ISUID;
10268 $is_setuid = $mode & S_ISUID;
17742 my $is_directory = S_ISDIR($mode);
10269 $is_setgid = S_ISDIR($mode);
1774310270
1774410271=begin original
1774510272
1774610273You could write the last two using the C<-u> and C<-d> operators.
17747Commonly available C<S_IF*> constants are:
10274The commonly available S_IF* constants are
1774810275
1774910276=end original
1775010277
1775110278最後の二つは C<-u> と C<-d> 演算子を使っても書けます。
17752一般に利用可能な C<S_IF*> 定数は以下のものです。
10279一般に利用可能な S_IF* 定数は以下のものです。
1775310280
1775410281 # Permissions: read, write, execute, for user, group, others.
1775510282
1775610283 S_IRWXU S_IRUSR S_IWUSR S_IXUSR
1775710284 S_IRWXG S_IRGRP S_IWGRP S_IXGRP
1775810285 S_IRWXO S_IROTH S_IWOTH S_IXOTH
1775910286
17760 # Setuid/Setgid/Stickiness/SaveText.
10287 # Setuid/Setgid/Stickiness.
17761 # Note that the exact meaning of these is system-dependent.
1776210288
1776310289 S_ISUID S_ISGID S_ISVTX S_ISTXT
1776410290
17765 # File types. Not all are necessarily available on
10291 # File types. Not necessarily all are available on your system.
17766 # your system.
1776710292
17768 S_IFREG S_IFDIR S_IFLNK S_IFBLK S_IFCHR
10293 S_IFREG S_IFDIR S_IFLNK S_IFBLK S_ISCHR S_IFIFO S_IFSOCK S_IFWHT S_ENFMT
17769 S_IFIFO S_IFSOCK S_IFWHT S_ENFMT
1777010294
17771 # The following are compatibility aliases for S_IRUSR,
10295 # The following are compatibility aliases for S_IRUSR, S_IWUSR, S_IXUSR.
17772 # S_IWUSR, and S_IXUSR.
1777310296
1777410297 S_IREAD S_IWRITE S_IEXEC
1777510298
1777610299=begin original
1777710300
17778and the C<S_IF*> functions are
10301and the S_IF* functions are
1777910302
1778010303=end original
1778110304
17782一般に利用可能な C<S_IF*> 関数は以下のものです。
10305一般に利用可能な S_IF* 関数は以下のものです。
1778310306
17784 S_IMODE($mode) the part of $mode containing the permission
10307 S_IFMODE($mode) the part of $mode containing the permission bits
17785 bits and the setuid/setgid/sticky bits
10308 and the setuid/setgid/sticky bits
1778610309
17787 S_IFMT($mode) the part of $mode containing the file type
10310 S_IFMT($mode) the part of $mode containing the file type
17788 which can be bit-anded with (for example)
10311 which can be bit-anded with e.g. S_IFREG
17789 S_IFREG or with the following functions
10312 or with the following functions
1779010313
17791 # The operators -f, -d, -l, -b, -c, -p, and -S.
10314 # The operators -f, -d, -l, -b, -c, -p, and -s.
1779210315
1779310316 S_ISREG($mode) S_ISDIR($mode) S_ISLNK($mode)
1779410317 S_ISBLK($mode) S_ISCHR($mode) S_ISFIFO($mode) S_ISSOCK($mode)
1779510318
1779610319 # No direct -X operator counterpart, but for the first one
1779710320 # the -g operator is often equivalent. The ENFMT stands for
1779810321 # record flocking enforcement, a platform-dependent feature.
1779910322
1780010323 S_ISENFMT($mode) S_ISWHT($mode)
1780110324
1780210325=begin original
1780310326
17804See your native L<chmod(2)> and L<stat(2)> documentation for more details
10327See your native chmod(2) and stat(2) documentation for more details
17805about the C<S_*> constants. To get status info for a symbolic link
10328about the S_* constants.
17806instead of the target file behind the link, use the
17807L<C<lstat>|/lstat FILEHANDLE> function.
1780810329
1780910330=end original
1781010331
17811C<S_*> 定数に関する詳細についてはネイティブの L<chmod(2)>L<stat(2)>
10332S_* 定数に関する詳細についてはネイティブの chmod(2) と stat(2) の
17812ドキュメントを参照してください。
10333ドキュメントを参照してさい。
17813リンクの先にあるファイルではなく、シンボリックリンクそのものの情報を
17814得たい場合は、L<C<lstat>|/lstat FILEHANDLE> 関数を使ってください。
1781510334
17816=begin original
17817
17818Portability issues: L<perlport/stat>.
17819
17820=end original
17821
17822移植性の問題: L<perlport/stat>。
17823
17824=item state VARLIST
17825X<state>
17826
17827=item state TYPE VARLIST
17828
17829=item state VARLIST : ATTRS
17830
17831=item state TYPE VARLIST : ATTRS
17832
17833=for Pod::Functions +state declare and assign a persistent lexical variable
17834
17835=begin original
17836
17837L<C<state>|/state VARLIST> declares a lexically scoped variable, just
17838like L<C<my>|/my VARLIST>.
17839However, those variables will never be reinitialized, contrary to
17840lexical variables that are reinitialized each time their enclosing block
17841is entered.
17842See L<perlsub/"Persistent Private Variables"> for details.
17843
17844=end original
17845
17846L<C<state>|/state VARLIST> はちょうど L<C<my>|/my VARLIST> と同様に、
17847レキシカルなスコープの変数を宣言します。
17848しかし、レキシカル変数がブロックに入る毎に再初期化されるのと異なり、
17849この変数は決して再初期化されません。
17850詳しくは L<perlsub/"Persistent Private Variables"> を参照してください。
17851
17852=begin original
17853
17854If more than one variable is listed, the list must be placed in
17855parentheses. With a parenthesised list, L<C<undef>|/undef EXPR> can be
17856used as a
17857dummy placeholder. However, since initialization of state variables in
17858such lists is currently not possible this would serve no purpose.
17859
17860=end original
17861
17862複数の変数を指定する場合、かっこで囲まなければなりません。
17863かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> はダミーの
17864プレースホルダとして使えます。
17865しかし、そのようなリストでの state 変数の初期化は現在のところできないので、
17866これは無意味です。
17867
17868=begin original
17869
17870L<C<state>|/state VARLIST> is available only if the
17871L<C<"state"> feature|feature/The 'state' feature> is enabled or if it is
17872prefixed with C<CORE::>. The
17873L<C<"state"> feature|feature/The 'state' feature> is enabled
17874automatically with a C<use v5.10> (or higher) declaration in the current
17875scope.
17876
17877=end original
17878
17879L<C<state>|/state VARLIST> は
17880L<C<"state"> 機能|feature/The 'state' feature> が有効か C<CORE::> を
17881前置した場合にのみ利用可能です。
17882L<C<"state"> 機能|feature/The 'state' feature> は現在のスコープで
17883C<use v5.10> (またはそれ以上) を宣言した場合自動的に有効になります。
17884
1788510335=item study SCALAR
17886X<study>
1788710336
1788810337=item study
1788910338
17890=for Pod::Functions no-op, formerly optimized input data for repeated searches
17891
1789210339=begin original
1789310340
17894At this time, C<study> does nothing. This may change in the future.
10341Takes extra time to study SCALAR (C<$_> if unspecified) in anticipation of
10342doing many pattern matches on the string before it is next modified.
10343This may or may not save time, depending on the nature and number of
10344patterns you are searching on, and on the distribution of character
10345frequencies in the string to be searched--you probably want to compare
10346run times with and without it to see which runs faster. Those loops
10347which scan for many short constant strings (including the constant
10348parts of more complex patterns) will benefit most. You may have only
10349one C<study> active at a time--if you study a different scalar the first
10350is "unstudied". (The way C<study> works is this: a linked list of every
10351character in the string to be searched is made, so we know, for
10352example, where all the C<'k'> characters are. From each search string,
10353the rarest character is selected, based on some static frequency tables
10354constructed from some C programs and English text. Only those places
10355that contain this "rarest" character are examined.)
1789510356
1789610357=end original
1789710358
17898現時点ではC<study> は何もしません。
10359次に変更される前に、何文字列に対するパターンマッチを
17899これは将来変更されるかもしれません。
10360行なうアプリケーションで、
10361そのような文字列 SCALAR(省略時には C<$_>) を予め学習しておきます。
10362これは、検索のために、どのようなパターンを何回使うかによって、
10363また、検索される文字列内の文字頻度の分布によって、
10364時間を節約することになるかもしれませんし、逆に浪費する
10365ことになるかもしれません。
10366予習をした場合と、しない場合の実行時間を比較して、
10367どちらが速いか調べることが、必要でしょう。
10368短い固定文字列 (複雑なパターンの固定部分を含みます) をたくさん
10369検索するループで、もっとも効果があるでしょう。
10370同時には、一つの C<study>だけが有効です。
10371別のスカラを study した場合には、以前に学習した内容は
10372「忘却」されてしまいます。
10373(この C<study> の仕組みは、まず、検索される文字列内の
10374すべての文字のリンクされたリストが作られ、たとえば、
10375すべての C<'k'> がどこにあるかがわかるようになります。
10376各々の検索文字列から、C プログラムや英語のテキストから作られた
10377頻度の統計情報に基づいて、もっとも珍しい文字が選ばれます。
10378この「珍しい」文字を含む場所だけが調べられるのです。)
1790010379
1790110380=begin original
1790210381
17903Prior to Perl version 5.16, it would create an inverted index of all characters
10382For example, here is a loop that inserts index producing entries
17904that occurred in the given SCALAR (or L<C<$_>|perlvar/$_> if unspecified). When
10383before any line containing a certain pattern:
17905matching a pattern, the rarest character from the pattern would be looked up in
17906this index. Rarity was based on some static frequency tables constructed from
17907some C programs and English text.
1790810384
1790910385=end original
1791010386
17911Perl バジョ 5.16 よりでは、
10387たとえば、特定のパターンを含む行のにインデックスを
17912与えらた SCALAR (たは指定されていなかった場合は L<C<$_>|perlvar/$_>)に
10388付けるエントリを入る例を示しす。
17913現れた全ての文字の転置インデックスを作ります。
17914パターンにマッチングしたとき、
17915パターン中の最も頻度の少ない文字がこのインデックスから探されます。
17916頻度は、C プログラムと英語の文章から構築された静的頻度テーブルを
17917基にしています。
1791810389
17919=item sub NAME BLOCK
10390 while (<>) {
17920X<sub>
10391 study;
10392 print ".IX foo\n" if /\bfoo\b/;
10393 print ".IX bar\n" if /\bbar\b/;
10394 print ".IX blurfl\n" if /\bblurfl\b/;
10395 # ...
10396 print;
10397 }
1792110398
17922=item sub NAME (PROTO) BLOCK
17923
17924=item sub NAME : ATTRS BLOCK
17925
17926=item sub NAME (PROTO) : ATTRS BLOCK
17927
17928=for Pod::Functions declare a subroutine, possibly anonymously
17929
1793010399=begin original
1793110400
17932This is subroutine definition, not a real function I<per se>. Without a
10401In searching for C</\bfoo\b/>, only those locations in C<$_> that contain C<f>
17933BLOCK it's just a forward declaration. Without a NAME, it's an anonymous
10402will be looked at, because C<f> is rarer than C<o>. In general, this is
17934function declaration, so does return a value: the CODE ref of the closure
10403a big win except in pathological cases. The only question is whether
17935just created.
10404it saves you more time than it took to build the linked list in the
10405first place.
1793610406
1793710407=end original
1793810408
17939これサブルーチン定義であり、I<本質的には> 実際の関数はありません。
10409C<f> C<o> よも珍しいのでC</\bfoo\b/> を探すとき、C<$_> C<f> を
17940BLOCK なしの合、こは単に前方宣言です。
10410含む所だけが探さす。
17941NAME しの場合無名関数定義であ、値(作成したブロック
10411一般に、病的な場合を除いてかなりの結果が得られます。
17942コードファレス)を返します: 単にロージャの CODE ファレン
10412唯一の問題は、節約できる時間が、最初にリンクリストを作る
17943作成されま
10413時間よりも多いかどうかで
1794410414
1794510415=begin original
1794610416
17947See L<perlsub> and L<perlref> for details about subroutines and
10417Note that if you have to look for strings that you don't know till
17948references; see L<attributes> and L<Attribute::Handlers> for more
10418runtime, you can build an entire loop as a string and C<eval> that to
17949information about attributes.
10419avoid recompiling all your patterns all the time. Together with
10420undefining C<$/> to input entire files as one record, this can be very
10421fast, often faster than specialized programs like fgrep(1). The following
10422scans a list of files (C<@files>) for a list of words (C<@words>), and prints
10423out the names of those files that contain a match:
1795010424
1795110425=end original
1795210426
17953サブルーチンリファレンスに関する詳細につは、L<perlsub> と
10427実行時まで、探そうとする文字列がわからなときには、
17954L<perlref> を参照してください; 属性に関る更なる情報については
10428ループ全体を文字列として組み立てて、C<eval> すれば、
17955L<attributes> と L<Attribute::Handlers> を参照しくださ
10429いつも、すべのパターンを再コンパイルするとう事態は
10430避けられます。
10431ファイル全体を一つのレコードとして入力するために、
10432C<$/> を未定義にすれば、かなり速くなり、
10433多くの場合 fgrep(1) のような専用のプログラムより速くなります。
10434以下の例は、ファイルのリスト (C<@files>) から単語のリスト (C<@words>) を
10435探して、マッチするものがあったファイル名を出力します。
1795610436
17957=item __SUB__
10437 $search = 'while (<>) { study;';
17958X<__SUB__>
10438 foreach $word (@words) {
10439 $search .= "++\$seen{\$ARGV} if /\\b$word\\b/;\n";
10440 }
10441 $search .= "}";
10442 @ARGV = @files;
10443 undef $/;
10444 eval $search; # this screams
10445 $/ = "\n"; # put back to normal input delimiter
10446 foreach $file (sort keys(%seen)) {
10447 print $file, "\n";
10448 }
1795910449
17960=for Pod::Functions +current_sub the current subroutine, or C<undef> if not in a subroutine
10450=item sub BLOCK
1796110451
17962=begin original
10452=item sub NAME
1796310453
17964A special token that returns a reference to the current subroutine, or
10454=item sub NAME BLOCK
17965L<C<undef>|/undef EXPR> outside of a subroutine.
1796610455
17967=end original
17968
17969現在のサブルーチンのリファレンスを返す特殊トークン; サブルーチンの外側では
17970L<C<undef>|/undef EXPR>。
17971
1797210456=begin original
1797310457
17974The behaviour of L<C<__SUB__>|/__SUB__> within a regex code block (such
10458This is subroutine definition, not a real function I<per se>. With just a
17975as C</(?{...})/>) is subject to change.
10459NAME (and possibly prototypes or attributes), it's just a forward declaration.
10460Without a NAME, it's an anonymous function declaration, and does actually
10461return a value: the CODE ref of the closure you just created. See L<perlsub>
10462and L<perlref> for details.
1797610463
1797710464=end original
1797810465
17979(C</(?{...})/> のような) 正規表現コードブロックの中の
10466これはサブルーチン定義であり、I<本質的には> 実際関数ではありません。
17980L<C<__SUB__>|/__SUB__>振る舞い変更され定です。
10467NAME (とプロトタイプや属性) みの場合、単な前方です。
10468NAME なしの場合は、無名関数定義であり、実際には値(作成したブロックの
10469コードリファレンス)を返します。
10470詳しくは L<perlsub> と L<perlref> を参照して下さい。
1798110471
17982=begin original
17983
17984This token is only available under C<use v5.16> or the
17985L<C<"current_sub"> feature|feature/The 'current_sub' feature>.
17986See L<feature>.
17987
17988=end original
17989
17990このトークンは C<use v5.16> または
17991L<C<"current_sub"> 機能|feature/The 'current_sub' feature> でのみ
17992利用可能です。
17993L<feature> を参照してください。
17994
1799510472=item substr EXPR,OFFSET,LENGTH,REPLACEMENT
17996X<substr> X<substring> X<mid> X<left> X<right>
1799710473
1799810474=item substr EXPR,OFFSET,LENGTH
1799910475
1800010476=item substr EXPR,OFFSET
1800110477
18002=for Pod::Functions get or alter a portion of a string
18003
1800410478=begin original
1800510479
1800610480Extracts a substring out of EXPR and returns it. First character is at
18007offset zero. If OFFSET is negative, starts
10481offset C<0>, or whatever you've set C<$[> to (but don't do that).
18008that far back from the end of the string. If LENGTH is omitted, returns
10482If OFFSET is negative (or more precisely, less than C<$[>), starts
18009everything through the end of the string. If LENGTH is negative, leaves that
10483that far from the end of the string. If LENGTH is omitted, returns
10484everything to the end of the string. If LENGTH is negative, leaves that
1801010485many characters off the end of the string.
1801110486
1801210487=end original
1801310488
1801410489EXPR から、部分文字列を取り出して返します。
18015最初の文字がオフセット 0 となります。
10490最初の文字がオフセット C<0> もしくは、C<$[> に設定した値
18016OFFSET に負の値を設定すると、EXPR の終わりらのオフセットとなります。
10491(ししこれを使ってはいけません)となります。
10492OFFSET に負の値(より厳密には、C<$[>より小さい値)を設定すると、
10493EXPR の終わりからのオフセットとなります。
1801710494LENGTH を省略すると、EXPR の最後まですべてが返されます。
1801810495LENGTH が負の値だと、文字列の最後から指定された数だけ文字を取り除きます。
1801910496
18020 my $s = "The black cat climbed the green tree";
18021 my $color = substr $s, 4, 5; # black
18022 my $middle = substr $s, 4, -11; # black cat climbed the
18023 my $end = substr $s, 14; # climbed the green tree
18024 my $tail = substr $s, -4; # tree
18025 my $z = substr $s, -4, 2; # tr
18026
1802710497=begin original
1802810498
18029You can use the L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT>
10499You can use the substr() function as an lvalue, in which case EXPR
18030function as an lvalue, in which case EXPR
1803110500must itself be an lvalue. If you assign something shorter than LENGTH,
1803210501the string will shrink, and if you assign something longer than LENGTH,
1803310502the string will grow to accommodate it. To keep the string the same
18034length, you may need to pad or chop your value using
10503length you may need to pad or chop your value using C<sprintf>.
18035L<C<sprintf>|/sprintf FORMAT, LIST>.
1803610504
1803710505=end original
1803810506
18039L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> を左辺値として
10507substr() を左辺値として使用することも可能で、その場合には、
18040使用することも可能で、その場合には、EXPR が自身左辺値でなければなりません。
10508EXPR が自身左辺値でなければなりません。
1804110509LENGTH より短いものを代入したときには、
1804210510EXPR は短くなり、LENGTH より長いものを代入したときには、
1804310511EXPR はそれに合わせて伸びることになります。
18044EXPR の長さを一定に保つためには、L<C<sprintf>|/sprintf FORMAT, LIST>
10512EXPR の長さを一定に保つためには、C<sprintf> を使って、
18045使って、代入する値の長さを調整することが、必要になるかもしれません。
10513代入する値の長さを調整することが、必要になるかもしれません。
1804610514
1804710515=begin original
1804810516
1804910517If OFFSET and LENGTH specify a substring that is partly outside the
1805010518string, only the part within the string is returned. If the substring
18051is beyond either end of the string,
10519is beyond either end of the string, substr() returns the undefined
18052L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> returns the undefined
1805310520value and produces a warning. When used as an lvalue, specifying a
18054substring that is entirely outside the string raises an exception.
10521substring that is entirely outside the string is a fatal error.
1805510522Here's an example showing the behavior for boundary cases:
1805610523
1805710524=end original
1805810525
1805910526OFFSET と LENGTH として文字列の外側を含むような部分文字列が指定されると、
1806010527文字列の内側の部分だけが返されます。
18061部分文字列が文字列の両端の外側の場合、
10528部分文字列が文字列の両端の外側の場合、substr() は未定義値を返し、
18062L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> は未定義値を返し、
1806310529警告が出力されます。
1806410530左辺値として使った場合、文字列の完全に外側を部分文字列として指定すると
18065例外が発生します。
10531致命的エラーになります。
1806610532以下は境界条件の振る舞いを示す例です:
1806710533
1806810534 my $name = 'fred';
18069 substr($name, 4) = 'dy'; # $name is now 'freddy'
10535 substr($name, 4) = 'dy'; # $name is now 'freddy'
18070 my $null = substr $name, 6, 2; # returns "" (no warning)
10536 my $null = substr $name, 6, 2; # returns '' (no warning)
18071 my $oops = substr $name, 7; # returns undef, with warning
10537 my $oops = substr $name, 7; # returns undef, with warning
18072 substr($name, 7) = 'gap'; # raises an exception
10538 substr($name, 7) = 'gap'; # fatal error
1807310539
1807410540=begin original
1807510541
18076An alternative to using
10542An alternative to using substr() as an lvalue is to specify the
18077L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> as an lvalue is to
18078specify the
1807910543replacement string as the 4th argument. This allows you to replace
1808010544parts of the EXPR and return what was there before in one operation,
18081just as you can with
10545just as you can with splice().
18082L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST>.
1808310546
1808410547=end original
1808510548
18086L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> を左辺値として使う
10549substr() を左辺値として使う代わりの方法は、置き換える文字列を 4 番目の
18087代わりの方法は、置き換える文字列を 4 番目の引数として指定することです。
10550引数として指定することです。
1808810551これにより、EXPR の一部を置き換え、置き換える前が何であったかを返す、
18089ということを(L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> と同様)
10552ということを(splice() と同様) 1 動作で行えます。
180901 動作で行えます。
1809110553
18092 my $s = "The black cat climbed the green tree";
18093 my $z = substr $s, 14, 7, "jumped from"; # climbed
18094 # $s is now "The black cat jumped from the green tree"
18095
18096=begin original
18097
18098Note that the lvalue returned by the three-argument version of
18099L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> acts as
18100a 'magic bullet'; each time it is assigned to, it remembers which part
18101of the original string is being modified; for example:
18102
18103=end original
18104
181053 引数の L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> によって返された
18106左辺値は「魔法の弾丸」のように振舞うことに注意してください;
18107これが代入される毎に、元の文字列のどの部分が変更されたかが思い出されます;
18108例えば:
18109
18110 my $x = '1234';
18111 for (substr($x,1,2)) {
18112 $_ = 'a'; print $x,"\n"; # prints 1a4
18113 $_ = 'xyz'; print $x,"\n"; # prints 1xyz4
18114 $x = '56789';
18115 $_ = 'pq'; print $x,"\n"; # prints 5pq9
18116 }
18117
18118=begin original
18119
18120With negative offsets, it remembers its position from the end of the string
18121when the target string is modified:
18122
18123=end original
18124
18125負数のオフセットの場合、ターゲット文字列が修正されたときに文字列の末尾からの
18126位置を覚えます:
18127
18128 my $x = '1234';
18129 for (substr($x, -3, 2)) {
18130 $_ = 'a'; print $x,"\n"; # prints 1a4, as above
18131 $x = 'abcdefg';
18132 print $_,"\n"; # prints f
18133 }
18134
18135=begin original
18136
18137Prior to Perl version 5.10, the result of using an lvalue multiple times was
18138unspecified. Prior to 5.16, the result with negative offsets was
18139unspecified.
18140
18141=end original
18142
18143バージョン 5.10 より前の Perl では、複数回左辺値を使った場合の結果は
18144未定義でした。
181455.16 より前では、負のオフセットの結果は未定義です。
18146
1814710554=item symlink OLDFILE,NEWFILE
18148X<symlink> X<link> X<symbolic link> X<link, symbolic>
1814910555
18150=for Pod::Functions create a symbolic link to a file
18151
1815210556=begin original
1815310557
1815410558Creates a new filename symbolically linked to the old filename.
1815510559Returns C<1> for success, C<0> otherwise. On systems that don't support
18156symbolic links, raises an exception. To check for that,
10560symbolic links, produces a fatal error at run time. To check for that,
1815710561use eval:
1815810562
1815910563=end original
1816010564
1816110565NEWFILE として、OLDFILE へのシンボリックリンクを生成します。
1816210566成功時には C<1> を返し、失敗時には C<0> を返します。
1816310567シンボリックリンクをサポートしていないシステムでは、
18164例外が発生します。
10568実行時に致命的エラーが発生します。
1816510569これをチェックするには、eval を使用します:
1816610570
18167 my $symlink_exists = eval { symlink("",""); 1 };
10571 $symlink_exists = eval { symlink("",""); 1 };
1816810572
18169=begin original
10573=item syscall LIST
1817010574
18171Portability issues: L<perlport/symlink>.
18172
18173=end original
18174
18175移植性の問題: L<perlport/symlink>。
18176
18177=item syscall NUMBER, LIST
18178X<syscall> X<system call>
18179
18180=for Pod::Functions execute an arbitrary system call
18181
1818210575=begin original
1818310576
1818410577Calls the system call specified as the first element of the list,
1818510578passing the remaining elements as arguments to the system call. If
18186unimplemented, raises an exception. The arguments are interpreted
10579unimplemented, produces a fatal error. The arguments are interpreted
1818710580as follows: if a given argument is numeric, the argument is passed as
1818810581an int. If not, the pointer to the string value is passed. You are
1818910582responsible to make sure a string is pre-extended long enough to
1819010583receive any result that might be written into a string. You can't use a
18191string literal (or other read-only string) as an argument to
10584string literal (or other read-only string) as an argument to C<syscall>
18192L<C<syscall>|/syscall NUMBER, LIST> because Perl has to assume that any
10585because Perl has to assume that any string pointer might be written
18193string pointer might be written through. If your
10586through. If your
1819410587integer arguments are not literals and have never been interpreted in a
1819510588numeric context, you may need to add C<0> to them to force them to look
18196like numbers. This emulates the
10589like numbers. This emulates the C<syswrite> function (or vice versa):
18197L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> function (or
18198vice versa):
1819910590
1820010591=end original
1820110592
1820210593LIST の最初の要素で指定するシステムコールを、残りの要素をその
1820310594システムコールの引数として呼び出します。
18204実装されていない場合には、例外が発生します。
10595実装されていないときには、致命的エラーとなります。
1820510596引数は、以下のように解釈されます: 引数が数字であれば、int として
1820610597引数を渡します。
1820710598そうでなければ、文字列値へのポインタが渡されます。
1820810599文字列に結果を受け取るときには、その結果を受け取るのに十分なくらいに、
1820910600文字列を予め伸ばしておく必要があります。
18210文字列リテラル(あるいはその他の読み込み専用の文字列)を
10601文字列リテラル(あるいはその他の読み込み専用の文字列)を C<syscall> の
18211L<C<syscall>|/syscall NUMBER, LIST> の引数として使うことはできません;
10602引数として使うことはできません
1821210603Perl は全ての文字列ポインタは書き込まれると仮定しなければならないからです。
18213整数引数が、リテラルでなく、数値コンテキストで評価されたことのない
10604整数引数が、リテラルでなく、数値コンテキストで評価されたことの
18214ものであれば、数値として解釈されるように、
10605ないものであれば、数値として解釈されるように、
1821510606C<0> を足しておく必要があるかもしれません。
18216以下は L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> 関数(あるいは
10607以下は C<syswrite> 関数(あるいはその逆)をエミュレートします。
18217その逆)をエミュレートします。
1821810608
18219 require 'syscall.ph'; # may need to run h2ph
10609 require 'syscall.ph'; # may need to run h2ph
18220 my $s = "hi there\n";
10610 $s = "hi there\n";
18221 syscall(SYS_write(), fileno(STDOUT), $s, length $s);
10611 syscall(&SYS_write, fileno(STDOUT), $s, length $s);
1822210612
1822310613=begin original
1822410614
18225Note that Perl supports passing of up to only 14 arguments to your syscall,
10615Note that Perl supports passing of up to only 14 arguments to your system call,
18226which in practice should (usually) suffice.
10616which in practice should usually suffice.
1822710617
1822810618=end original
1822910619
1823010620Perl は、システムコールに最大 14 個の引数しか渡せませんが、
18231(普通は)実用上問題はないでしょう。
10621実用上問題はないでしょう。
1823210622
1823310623=begin original
1823410624
1823510625Syscall returns whatever value returned by the system call it calls.
18236If the system call fails, L<C<syscall>|/syscall NUMBER, LIST> returns
10626If the system call fails, C<syscall> returns C<-1> and sets C<$!> (errno).
18237C<-1> and sets L<C<$!>|perlvar/$!> (errno).
10627Note that some system calls can legitimately return C<-1>. The proper
18238Note that some system calls I<can> legitimately return C<-1>. The proper
10628way to handle such calls is to assign C<$!=0;> before the call and
18239way to handle such calls is to assign C<$! = 0> before the call, then
10629check the value of C<$!> if syscall returns C<-1>.
18240check the value of L<C<$!>|perlvar/$!> if
18241L<C<syscall>|/syscall NUMBER, LIST> returns C<-1>.
1824210630
1824310631=end original
1824410632
1824510633syscall は、呼び出したシステムコールが返した値を返します。
18246システムコールが失敗すると、L<C<syscall>|/syscall NUMBER, LIST> は C<-1> を
10634システムコールが失敗すると、C<syscall> は C<-1> を返し、
18247返し、L<C<$!>|perlvar/$!>(errno) を設定します。
10635C<$!>(errno) を設定します。
18248システムコールが正常に C<-1> を返す I<場合がある> ことに注意してください。
10636システムコールが正常に C<-1> を返す場合があることに注意してください。
1824910637このようなシステムコールを正しく扱うには、
18250C<$! = 0> をシステムコールの前に実行し、それから
10638C<$!=0;> をシステムコールの前に実行し、
18251L<C<syscall>|/syscall NUMBER, LIST> が C<-1> を返した時には
10639syscall が C<-1> を返した時には C<$!> の値を調べてください。
18252L<C<$!>|perlvar/$!> の値を調べてください。
1825310640
1825410641=begin original
1825510642
18256There's a problem with C<syscall(SYS_pipe())>: it returns the file
10643There's a problem with C<syscall(&SYS_pipe)>: it returns the file
18257number of the read end of the pipe it creates, but there is no way
10644number of the read end of the pipe it creates. There is no way
18258to retrieve the file number of the other end. You can avoid this
10645to retrieve the file number of the other end. You can avoid this
18259problem by using L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> instead.
10646problem by using C<pipe> instead.
1826010647
1826110648=end original
1826210649
18263C<syscall(&SYS_pipe)> には問題があり、作ったパイプの、読み出し側の
10650C<syscall(&SYS_pipe)> には問題があり、
18264ファイル番号を返しますが、もう一方のファイル番号を得る方法がありません。
10651作ったパイプの、読み出し側のファイル番号を返しますが、
18265問題避けためには、代わに L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> を
10652もう一方ファイル番号方法があません。
18266使ってください。
10653この問題を避けるためには、代わりに C<pipe> を使ってください。
1826710654
18268=begin original
18269
18270Portability issues: L<perlport/syscall>.
18271
18272=end original
18273
18274移植性の問題: L<perlport/syscall>。
18275
1827610655=item sysopen FILEHANDLE,FILENAME,MODE
18277X<sysopen>
1827810656
1827910657=item sysopen FILEHANDLE,FILENAME,MODE,PERMS
1828010658
18281=for Pod::Functions +5.002 open a file, pipe, or descriptor
18282
1828310659=begin original
1828410660
18285Opens the file whose filename is given by FILENAME, and associates it with
10661Opens the file whose filename is given by FILENAME, and associates it
18286FILEHANDLE. If FILEHANDLE is an expression, its value is used as the real
10662with FILEHANDLE. If FILEHANDLE is an expression, its value is used as
18287filehandle wanted; an undefined scalar will be suitably autovivified. This
10663the name of the real filehandle wanted. This function calls the
18288function calls the underlying operating system's L<open(2)> function with the
10664underlying operating system's C<open> function with the parameters
18289parameters FILENAME, MODE, and PERMS.
10665FILENAME, MODE, PERMS.
1829010666
1829110667=end original
1829210668
1829310669FILENAME で与えられたファイル名のファイルをオープンし、
1829410670FILEHANDLE と結び付けます。
18295FILEHANDLE が式の場合、その値は実際求めているファイルハンドルの名前として
10671FILEHANDLE が式の場合、その値は実際求めているファイルハンドルの名前として
18296扱われます; 未定義のスカラは適切に自動有効化されます
10672扱われます。
18297この関数呼び出しはシステムの L<open(2)> 関数を FILENAME, MODE, PERMS の
10673この関数呼び出しはシステムの C<open> 関数を FILENAME, MODE, PERMS の
1829810674引数で呼び出すことを基礎としています。
1829910675
1830010676=begin original
1830110677
18302Returns true on success and L<C<undef>|/undef EXPR> otherwise.
18303
18304=end original
18305
18306成功時は真を、さもなければ L<C<undef>|/undef EXPR> を返します。
18307
18308=begin original
18309
1831010678The possible values and flag bits of the MODE parameter are
18311system-dependent; they are available via the standard module
10679system-dependent; they are available via the standard module C<Fcntl>.
18312L<C<Fcntl>|Fcntl>. See the documentation of your operating system's
10680See the documentation of your operating system's C<open> to see which
18313L<open(2)> syscall to see
10681values and flag bits are available. You may combine several flags
18314which values and flag bits are available. You may combine several flags
1831510682using the C<|>-operator.
1831610683
1831710684=end original
1831810685
1831910686MODE パラメータに指定できるフラグビットと値はシステム依存です;
18320これは標準モジュール L<C<Fcntl>|Fcntl> 経由で利用可能です。
10687これは標準モジュール C<Fcntl> 経由で利用可能です。
1832110688どのようなフラグビットと値が利用可能であるかについては、
18322OS の L<open(2)> システムコールに関する文書を参照してください。
10689OS の C<open> に関する文書を参照してください。
1832310690C<|> 演算子を使って複数のフラグを結合することができます。
1832410691
1832510692=begin original
1832610693
1832710694Some of the most common values are C<O_RDONLY> for opening the file in
1832810695read-only mode, C<O_WRONLY> for opening the file in write-only mode,
18329and C<O_RDWR> for opening the file in read-write mode.
10696and C<O_RDWR> for opening the file in read-write mode, and.
18330X<O_RDONLY> X<O_RDWR> X<O_WRONLY>
1833110697
1833210698=end original
1833310699
1833410700もっともよく使われる値は、ファイルを読み込み専用で開く C<O_RDONLY>、
1833510701ファイルを書き込み専用で開く C<O_WRONLY>、
1833610702ファイルを読み書き両用で開く C<O_RDWR> です。
18337X<O_RDONLY> X<O_RDWR> X<O_WRONLY>
1833810703
1833910704=begin original
1834010705
1834110706For historical reasons, some values work on almost every system
18342supported by Perl: 0 means read-only, 1 means write-only, and 2
10707supported by perl: zero means read-only, one means write-only, and two
1834310708means read/write. We know that these values do I<not> work under
18344OS/390 and on the Macintosh; you probably don't want to
10709OS/390 & VM/ESA Unix and on the Macintosh; you probably don't want to
1834510710use them in new code.
1834610711
1834710712=end original
1834810713
18349歴史的な理由により、Perl が対応しているほとんどのシステムで使える値が
10714歴史的な理由により、perl が対応しているほとんどのシステムで
18350あります:0 は読み込み専用、1 は書き込み専用、2 は読み書き両用を意味します。
10715使える値があります。
18351OS/390 Macintosh で動作 I<ない> ことが分かっています;
107160 は読み込み専用、1書き込み専用、2 は読み書き両用を意味します
10717OS/390 & VM/ESA Unix と Macintosh では動作 I<しない> ことが分かっています;
1835210718新しく書くコードではこれらは使わないほうがよいでしょう。
1835310719
1835410720=begin original
1835510721
18356If the file named by FILENAME does not exist and the
10722If the file named by FILENAME does not exist and the C<open> call creates
18357L<C<open>|/open FILEHANDLE,EXPR> call creates
1835810723it (typically because MODE includes the C<O_CREAT> flag), then the value of
1835910724PERMS specifies the permissions of the newly created file. If you omit
18360the PERMS argument to L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>,
10725the PERMS argument to C<sysopen>, Perl uses the octal value C<0666>.
18361Perl uses the octal value C<0666>.
1836210726These permission values need to be in octal, and are modified by your
18363process's current L<C<umask>|/umask EXPR>.
10727process's current C<umask>.
18364X<O_CREAT>
1836510728
1836610729=end original
1836710730
1836810731FILENAME という名前のファイルが存在せず、(典型的には MODE が
18369C<O_CREAT> フラグを含んでいたために)
10732C<O_CREAT> フラグを含んでいたために) C<open> 呼び出しがそれを作った場合、
18370L<C<open>|/open FILEHANDLE,EXPR> 呼び出しがそれを作った場合、
1837110733PERMS の値は新しく作られたファイルの権限を指定します。
18372L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> の PERMS 引数を省略した場合、
10734C<sysopen> の PERMS 引数を省略した場合、Perl は 8 進数 C<0666> を使います。
18373Perl は 8 進数 C<0666> を使います。
10735これらの権限は 8 進数である必要があり、プロセスの現在の C<umask>
18374らの権限は 8 進数である必要があり、プロセスの現在の
10736修正さます。
18375L<C<umask>|/umask EXPR> で修正されます。
18376X<O_CREAT>
1837710737
1837810738=begin original
1837910739
1838010740In many systems the C<O_EXCL> flag is available for opening files in
1838110741exclusive mode. This is B<not> locking: exclusiveness means here that
18382if the file already exists,
10742if the file already exists, sysopen() fails. The C<O_EXCL> wins
18383L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> fails. C<O_EXCL> may
10743C<O_TRUNC>.
18384not work
18385on network filesystems, and has no effect unless the C<O_CREAT> flag
18386is set as well. Setting C<O_CREAT|O_EXCL> prevents the file from
18387being opened if it is a symbolic link. It does not protect against
18388symbolic links in the file's path.
18389X<O_EXCL>
1839010744
1839110745=end original
1839210746
1839310747多くのシステムではファイルを排他モードで開くために C<O_EXCL> が
1839410748利用可能です。
1839510749これはロック B<ではありません>: 排他性というのは既にファイルが
18396存在していた場合、L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>
10750存在していた場合、sysopen()失敗することを意味します。
18397失敗することを意味します。
10751C<O_EXCL> は C<O_TRUNC> より優先します。
18398C<O_EXCL> はネットワークファイルシステムでは動作せず、
18399またC<O_CREAT> フラグも有効でない限りは効果がありません。
18400C<O_CREAT|O_EXCL> をセットすると、これがシンボリックリンクだった場合は
18401ファイルを開くことを妨げます。
18402これはファイルパス中のシンボリックリンクは守りません。
18403X<O_EXCL>
1840410752
1840510753=begin original
1840610754
18407Sometimes you may want to truncate an already-existing file. This
10755Sometimes you may want to truncate an already-existing file: C<O_TRUNC>.
18408can be done using the C<O_TRUNC> flag. The behavior of
18409C<O_TRUNC> with C<O_RDONLY> is undefined.
18410X<O_TRUNC>
1841110756
1841210757=end original
1841310758
18414既に存在しているファイルを切り詰めたい場合もあるかもしれません
10759既に存在しているファイルを切り詰めたい場合もあるかもしれません: C<O_TRUNC>
18415これは C<O_TRUNC> フラグを使うことで行えます。
18416C<O_RDONLY> と C<O_TRUNC> を同時に指定したときの振る舞いは未定義です。
18417X<O_TRUNC>
1841810760
1841910761=begin original
1842010762
18421You should seldom if ever use C<0644> as argument to
10763You should seldom if ever use C<0644> as argument to C<sysopen>, because
18422L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>, because
1842310764that takes away the user's option to have a more permissive umask.
18424Better to omit it. See L<C<umask>|/umask EXPR> for more on this.
10765Better to omit it. See the perlfunc(1) entry on C<umask> for more
10766on this.
1842510767
1842610768=end original
1842710769
18428めったなことでは L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> の引数に
10770めったなことでは C<sysopen> の引数に C<0644> を指定するべきではないでしょう:
18429C<0644> を指定するべきではないでしょう:
1843010771ユーザーがより寛大な umask を指定する選択肢を奪うからです。
1843110772省略した方がいいです。
18432これに関するさらなる情報については L<C<umask>|/umask EXPR> を
10773これに関するさらなる情報については perlfunc(1) の C<umask> を
1843310774参照してください。
1843410775
1843510776=begin original
1843610777
18437Note that under Perls older than 5.8.0,
10778Note that C<sysopen> depends on the fdopen() C library function.
18438L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> depends on the
10779On many UNIX systems, fdopen() is known to fail when file descriptors
18439L<fdopen(3)> C library function. On many Unix systems, L<fdopen(3)> is known
10780exceed a certain value, typically 255. If you need more file
18440to fail when file descriptors exceed a certain value, typically 255. If
10781descriptors than that, consider rebuilding Perl to use the C<sfio>
18441you need more file descriptors than that, consider using the
10782library, or perhaps using the POSIX::open() function.
18442L<C<POSIX::open>|POSIX/C<open>> function. For Perls 5.8.0 and later,
18443PerlIO is (most often) the default.
1844410783
1844510784=end original
1844610785
184475.8.0 より古い Perl では、
10786C<sysopen> C の fdopen() ライブラリ関数に依存していることに注意してください。
18448L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>
10787多くの UNIX システムでは、fdopen()ファイル記述子がある値(例えば 255)を超えると
18449C の L<fdopen(3)> ライブラリ関数に依存していることに注意しください。
10788失敗することが知られています
18450多くの Unix システムでは、L<fdopen(3)> はファイル記述子がある値(例えば 255)を
18451超えると失敗することが知られています。
1845210789これより多くのファイル記述子が必要な場合は、
18453L<C<POSIX::open>|POSIX/C<open>> 関数を使うことを検討しください。
10790Perl を C<sfio> ライブラリを使再ビルドするか、
18454Perl 5.8.0 以降では、(ほぼ確実に) PerlIO がデフォルトです
10791POSIX::open() 関数を使うことを健闘してください
1845510792
1845610793=begin original
1845710794
1845810795See L<perlopentut> for a kinder, gentler explanation of opening files.
1845910796
1846010797=end original
1846110798
18462ファイルを開くことに関するより親切な説明については L<perlopentut> を
10799ファイル操作に関するより親切な説明については L<perlopentut> を参照して下さい。
18463参照してください。
1846410800
18465=begin original
18466
18467Portability issues: L<perlport/sysopen>.
18468
18469=end original
18470
18471移植性の問題: L<perlport/sysopen>。
18472
1847310801=item sysread FILEHANDLE,SCALAR,LENGTH,OFFSET
18474X<sysread>
1847510802
1847610803=item sysread FILEHANDLE,SCALAR,LENGTH
1847710804
18478=for Pod::Functions fixed-length unbuffered input from a filehandle
18479
1848010805=begin original
1848110806
1848210807Attempts to read LENGTH bytes of data into variable SCALAR from the
18483specified FILEHANDLE, using L<read(2)>. It bypasses
10808specified FILEHANDLE, using the system call read(2). It bypasses stdio,
18484buffered IO, so mixing this with other kinds of reads,
10809so mixing this with other kinds of reads, C<print>, C<write>,
18485L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
10810C<seek>, C<tell>, or C<eof> can cause confusion because stdio
18486L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
10811usually buffers data. Returns the number of bytes actually read, C<0>
18487L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> can cause
10812at end of file, or undef if there was an error. SCALAR will be grown or
18488confusion because the
18489perlio or stdio layers usually buffer data. Returns the number of
18490bytes actually read, C<0> at end of file, or undef if there was an
18491error (in the latter case L<C<$!>|perlvar/$!> is also set). SCALAR will
18492be grown or
1849310813shrunk so that the last byte actually read is the last byte of the
1849410814scalar after the read.
1849510815
1849610816=end original
1849710817
18498L<read(2)> を用いて、指定した FILEHANDLE から、変数 SCALAR へ、LENGTH バイトの
10818システムコール read(2) を用いて、指定した FILEHANDLE
18499データの読み込みを試みます。
10819から、変数 SCALAR へ、LENGTH バイトのデータの読み込みを試みます。
18500これは、バッファ付き IO ルーチンを通りませんから、他の入力関数,
10820これは、stdio ルーチンを通りませんから、
18501L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
10821他の入力関数, C<print>, C<write>,
18502L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>,
10822C<seek>, C<tell>, C<eof> と混ぜて使うと、入力がおかしくなる
18503L<C<eof>|/eof FILEHANDLE> と混ぜて使うと、入力がおかしくなるか
10823れません。stdio は普通データをバッファリングするからです。
18504しれません; perlio 層や stdio 層は普通データをバッファリングするからす。
10824ファイルの最後は C<0>が、
18505ファイルの最後では C<0>が、エラー時には undef が、それ以外では実際に
10825エラー時には undef が、
18506読み込まれたデータの長さが返されます (後者の場合は L<C<$!>|perlvar/$!> も
10826それ以外では実際に読み込まれたデータの長さが返されます
18507セットされます)。
1850810827実際に読み込んだ最後のバイトが read した後の最後のバイトになるので、
1850910828SCALAR は伸び縮みします。
1851010829
1851110830=begin original
1851210831
1851310832An OFFSET may be specified to place the read data at some place in the
1851410833string other than the beginning. A negative OFFSET specifies
18515placement at that many characters counting backwards from the end of
10834placement at that many bytes counting backwards from the end of the
18516the string. A positive OFFSET greater than the length of SCALAR
10835string. A positive OFFSET greater than the length of SCALAR results
18517results in the string being padded to the required size with C<"\0">
10836in the string being padded to the required size with C<"\0"> bytes before
18518bytes before the result of the read is appended.
10837the result of the read is appended.
1851910838
1852010839=end original
1852110840
18522OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行なえます。
10841OFFSET を指定すると、
18523OFFSET に負値を指定すると、文字列最後から逆向きに何文字目か
10842SCALAR先頭以外場所から、読み込みを行なうことがきます。
10843OFFSET に負の値を指定すると、文字列の最後から逆向きに何バイト目かで
1852410844位置を指定します。
18525OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は読み込みの結果が
10845OFFSET が正の値で、SCALAR の長さよりも大きかった場合、
18526追加される前に、必要なサイズまで C<"\0"> のバイトでパッディングされます。
10846必要なサイズになるまで C<"\0"> でパッディングされ、その後に
10847読み込み結果が追加されます。
1852710848
1852810849=begin original
1852910850
18530There is no syseof() function, which is ok, since
10851There is no syseof() function, which is ok, since eof() doesn't work
18531L<C<eof>|/eof FILEHANDLE> doesn't work well on device files (like ttys)
10852very well on device files (like ttys) anyway. Use sysread() and check
18532anyway. Use L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> and
10853for a return value for 0 to decide whether you're done.
18533check for a return value of 0 to decide whether you're done.
1853410854
1853510855=end original
1853610856
18537syseof() 関数はありませんが、問題ありません; どちらにしろ
10857syseof() 関数はありませんが、問題ありません
18538L<C<eof>|/eof FILEHANDLE>
10858どちらにしろ eof() は(tty のような)デバイスファイルに対して
18539(tty のような)デバイスファイルに対してはうまく動作しないからです。
10859うまく動作しないからです。
18540L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を使って、
10860sysread() を使って、 返り値が 0 かどうかで最後まで読んだかを
18541返り値が 0 かどうかで最後まで読んだかを判断してください。
10861判断してください。
1854210862
18543=begin original
18544
18545Note that if the filehandle has been marked as C<:utf8>, C<sysread> will
18546throw an exception. The C<:encoding(...)> layer implicitly
18547introduces the C<:utf8> layer. See
18548L<C<binmode>|/binmode FILEHANDLE, LAYER>,
18549L<C<open>|/open FILEHANDLE,EXPR>, and the L<open> pragma.
18550
18551=end original
18552
18553ファイルハンドルが C<:utf8> であるとマークが付けられていると、
18554C<sysread> は例外を投げます。
18555C<:encoding(...)> 層は暗黙のうちに C<:utf8> 層が導入されます。
18556L<C<binmode>|/binmode FILEHANDLE, LAYER>, L<C<open>|/open FILEHANDLE,EXPR>,
18557L<open> プラグマを参照してください。
18558
1855910863=item sysseek FILEHANDLE,POSITION,WHENCE
18560X<sysseek> X<lseek>
1856110864
18562=for Pod::Functions +5.004 position I/O pointer on handle used with sysread and syswrite
18563
1856410865=begin original
1856510866
18566Sets FILEHANDLE's system position I<in bytes> using L<lseek(2)>. FILEHANDLE may
10867Sets FILEHANDLE's system position using the system call lseek(2). It
18567be an expression whose value gives the name of the filehandle. The values
10868bypasses stdio, so mixing this with reads (other than C<sysread>),
18568for WHENCE are C<0> to set the new position to POSITION; C<1> to set it
10869C<print>, C<write>, C<seek>, C<tell>, or C<eof> may cause confusion.
18569to the current position plus POSITION; and C<2> to set it to EOF plus
10870FILEHANDLE may be an expression whose value gives the name of the
18570POSITION, typically negative.
10871filehandle. The values for WHENCE are C<0> to set the new position to
10872POSITION, C<1> to set the it to the current position plus POSITION,
10873and C<2> to set it to EOF plus POSITION (typically negative). For
10874WHENCE, you may also use the constants C<SEEK_SET>, C<SEEK_CUR>, and
10875C<SEEK_END> (start of the file, current position, end of the file)
10876from the Fcntl module.
1857110877
1857210878=end original
1857310879
18574FILEHANDLE のシステム位置を I<バイト単位> で L<lseek(2)> を使って設定します。
10880FILEHANDLE のシステム位置を lseek(2) システムコールを使って設定します。
18575FILEHANDLE 、実際のファイルハンドル名与える式でもかいません。
10881これ stdio バイパスしすので、
18576WHENCE の値が、C<0> ならば、新しい位置を POSITION 位置へ設定します;
10882(C<sysread>以外)読み込み、
18577C<1> ならば、現在位置から POSITION 加えた位置へ設定します; C<2> ならば、
10883C<print>, C<write>, C<seek>, C<tell>, C<eof> と混ぜて使うと
18578EOF から POSITION だけ(普通は負の数です)加えた位置へ、新しい位置
10884混乱引き起こします。
18579設定し
10885FILEHANDLE は式でも構いせんその場合はその値がファイルハンドルの
10886名前となります。
10887WHENCE の値が、C<0> ならば、
10888新しい位置を POSITION の位置へ、C<1> ならば、現在位置から
10889POSITION 加えた位置へ、C<2> ならば、EOF から POSITION
10890だけ加えた位置へ、新しい位置を設定します。
10891この値には、Fcntl モジュールで使われている C<SEEK_SET>、
10892C<SEEK_CUR>、C<SEEK_END>
10893(ファイルの先頭、現在位置、ファイルの最後)という定数を使うこともできます。
1858010894
1858110895=begin original
1858210896
18583Note the emphasis on bytes: even if the filehandle has been set to operate
18584on characters (for example using the C<:encoding(UTF-8)> I/O layer), the
18585L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
18586L<C<tell>|/tell FILEHANDLE>, and
18587L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>
18588family of functions use byte offsets, not character offsets,
18589because seeking to a character offset would be very slow in a UTF-8 file.
18590
18591=end original
18592
18593バイト単位に対する注意: 例え(例えば C<:encoding(UTF-8)> I/O 層を使うなどして)
18594ファイルハンドルが文字単位で処理するように設定されていたとしても、
18595L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
18596L<C<tell>|/tell FILEHANDLE>,
18597L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> シリーズの関数は
18598文字オフセットではなくバイトオフセットを使います;
18599文字オフセットでシークするのは UTF-8 ファイルではとても遅いからです。
18600
18601=begin original
18602
18603L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> bypasses normal
18604buffered IO, so mixing it with reads other than
18605L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> (for example
18606L<C<readline>|/readline EXPR> or
18607L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>),
18608L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
18609L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
18610L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> may cause
18611confusion.
18612
18613=end original
18614
18615L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> は普通のバッファ付き IO を
18616バイパスしますので、
18617L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> 以外の (例えば
18618L<C<readline>|/readline EXPR> や
18619L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> の)読み込み、
18620L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
18621L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>,
18622L<C<eof>|/eof FILEHANDLE> と混ぜて使うと混乱を引き起こします。
18623
18624=begin original
18625
18626For WHENCE, you may also use the constants C<SEEK_SET>, C<SEEK_CUR>,
18627and C<SEEK_END> (start of the file, current position, end of the file)
18628from the L<Fcntl> module. Use of the constants is also more portable
18629than relying on 0, 1, and 2. For example to define a "systell" function:
18630
18631=end original
18632
18633WHENCE には、L<Fcntl> モジュールで使われている C<SEEK_SET>, C<SEEK_CUR>,
18634C<SEEK_END> (ファイルの先頭、現在位置、ファイルの最後)という定数を
18635使うこともできます。
18636定数の使用は 0, 1, 2 に依存するよりも移植性があります。
18637例えば "systell" 関数を定義するには:
18638
18639 use Fcntl 'SEEK_CUR';
18640 sub systell { sysseek($_[0], 0, SEEK_CUR) }
18641
18642=begin original
18643
1864410897Returns the new position, or the undefined value on failure. A position
18645of zero is returned as the string C<"0 but true">; thus
10898of zero is returned as the string C<"0 but true">; thus C<sysseek> returns
18646L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> returns
1864710899true on success and false on failure, yet you can still easily determine
1864810900the new position.
1864910901
1865010902=end original
1865110903
18652新しい位置を返します; 失敗したときは未定義値を返します。
10904新しい位置を返します失敗したときは未定義値を返します。
18653位置がゼロの場合は、C<"0 but true"> の文字列として返されます; 従って
10905位置がゼロの場合は、C<"0 but true"> の文字列として返されます
18654L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> は成功時に真を返し、
10906従って C<sysseek> は成功時に真を返し、失敗時に偽を返しますが
18655失敗時に偽を返しますが、簡単に新しい位置を判定できます。
10907簡単に新しい位置を判定できます。
1865610908
1865710909=item system LIST
18658X<system> X<shell>
1865910910
1866010911=item system PROGRAM LIST
1866110912
18662=for Pod::Functions run a separate program
18663
1866410913=begin original
1866510914
18666Does exactly the same thing as L<C<exec>|/exec LIST>, except that a fork is
10915Does exactly the same thing as C<exec LIST>, except that a fork is
18667done first and the parent process waits for the child process to
10916done first, and the parent process waits for the child process to
18668exit. Note that argument processing varies depending on the
10917complete. Note that argument processing varies depending on the
1866910918number of arguments. If there is more than one argument in LIST,
1867010919or if LIST is an array with more than one value, starts the program
1867110920given by the first element of the list with arguments given by the
1867210921rest of the list. If there is only one scalar argument, the argument
1867310922is checked for shell metacharacters, and if there are any, the
1867410923entire argument is passed to the system's command shell for parsing
1867510924(this is C</bin/sh -c> on Unix platforms, but varies on other
1867610925platforms). If there are no shell metacharacters in the argument,
1867710926it is split into words and passed directly to C<execvp>, which is
18678more efficient. On Windows, only the C<system PROGRAM LIST> syntax will
10927more efficient.
18679reliably avoid using the shell; C<system LIST>, even with more than one
18680element, will fall back to the shell if the first spawn fails.
1868110928
1868210929=end original
1868310930
18684L<C<exec>|/exec LIST> とほとんど同じですが、まず fork を行ない、
10931C<exec LIST> とほとんど同じですが、まず fork を行ない、
1868510932親プロセスではチャイルドプロセスが終了するのを wait します。
1868610933exec の項で述べたように、引数の処理は、引数の数によって異なることに
1868710934注意してください。
1868810935LIST に複数の引数がある場合、または LIST が複数の要素からなる配列の場合、
18689リストの最初の要素で与えられるプログラムを、リストの残りの要素を引数として
10936リストの最初の要素で与えられるプログラムを、リストの残りの要素を
18690起動します。
10937引数として起動します。
18691スカラの引数が一つだけの場合、引数はシェルのメタ文字をチェックされ、もし
10938スカラの引数が一つだけの場合、
18692あればパースのために引数全体がステムコマンドシェル (こ
10939引数シェルのメタキャラクタをチェックさ、もしあれば
18693Unix プラットフォムでは C</bin/sh -c> ですが、他プラットフォーでは
10940ために引数全体がシステコマンドシェル
18694異なります)に渡さ
10941(こは Unix プラットフォームでは C</bin/sh -c> でが、
18695シェルメタ文字がなかった場合、引数単語分解されて直接 C<execvp> に
10942プラットフォームで異なります)されます。
18696渡されます; この方より効率的です。
10943シェルメタキャラクタなかった場合、
18697Windows でC<system PROGRAM LIST> 構文のみが安定してシェルの使用を
10944引数単語に分解されて直接 C<execvp> に渡されます。
18698回避します; C<system LIST> は、2 要素以上でも、最初 spawn 失敗ると
10945より効率的で
18699シェルにフォールバックします。
1870010946
1870110947=begin original
1870210948
18703Perl will attempt to flush all files opened for
10949Beginning with v5.6.0, Perl will attempt to flush all files opened for
1870410950output before any operation that may do a fork, but this may not be
1870510951supported on some platforms (see L<perlport>). To be safe, you may need
18706to set L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>)
10952to set C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method
18707or call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS>
10953of C<IO::Handle> on any open handles.
18708on any open handles.
1870910954
1871010955=end original
1871110956
18712v5.6.0 から、Perl は書き込み用に開いてい全てファイル対して
10957v5.6.0から、Perl は fork を行うようなあらゆ動作
18713fork を行う前にフラッシュしようとしますが、これに対応していない
10958出力用オープンしていた全てのァイルをフラッシュしようとします
18714プラットフォームもあります(L<perlport> 参照してください)。
10959しかしこれをサポートしていないプラットフォームもあります(L<perlport> 参照)。
18715安全のために、L<C<$E<verbar>>|perlvar/$E<verbar>> (L<English> モジュールでは
10960安全のために、C<$l>(English モジュールを使っているなら $AUTOFLUSH)を
18716C<$AUTOFLUSH>) をセットするか、全ての開いているハンドルに対し
10961設定するか、あらゆオープン済みハンドルにおい C<IO::Handle> の C<autoflush()>
18717L<C<IO::Handle>|IO::Handle/METHODS> の C<autoflush> メソッド
10962メソッドが必要となるかもしれません。
18718呼び出す必要があるかもしれません。
1871910963
1872010964=begin original
1872110965
18722The return value is the exit status of the program as returned by the
10966The return value is the exit status of the program as
18723L<C<wait>|/wait> call. To get the actual exit value, shift right by
10967returned by the C<wait> call. To get the actual exit value divide by
18724eight (see below). See also L<C<exec>|/exec LIST>. This is I<not> what
10968256. See also L</exec>. This is I<not> what you want to use to capture
18725you want to use to capture the output from a command; for that you
10969the output from a command, for that you should use merely backticks or
18726should use merely backticks or
10970C<qx//>, as described in L<perlop/"`STRING`">. Return value of -1
18727L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>>, as described in
10971indicates a failure to start the program (inspect $! for the reason).
18728L<perlop/"`STRING`">. Return value of -1 indicates a failure to start
18729the program or an error of the L<wait(2)> system call (inspect
18730L<C<$!>|perlvar/$!> for the reason).
1873110972
1873210973=end original
1873310974
18734返り値は、L<C<wait>|/wait> が返すプログラムの exit 状態です。
10975返り値は、C<wait> が返すプログラムの exit 状態です。
18735実際の exit 値を得るには 右に 8 ビットシフトしてください(後述)
10976実際の exit 値を得るには 256 で割ってください。
18736L<C<exec>|/exec LIST> も参照してください。
10977L</exec> も参照してください。
18737これはコマンドからの出力を捕らえるために使うものI<ではありません>;
10978これはコマンドからの出力を捕らえるために使うものI<ではありません>
1873810979そのような用途には、L<perlop/"`STRING`"> に記述されている
18739逆クォートや L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>> を使用してください。
10980逆クォートや C<qx//> を使用してください。
18740-1 の返り値はプログラムを開始させることに失敗したか、L<wait(2)>
10981-1 の返り値はプログラムを開始させることに失敗したことを示します
18741システムコールがエラー出したことを示します
10982(理由は $! 調べてください)。
18742(理由は L<C<$!>|perlvar/$!> を調べてください)。
1874310983
1874410984=begin original
1874510985
18746If you'd like to make L<C<system>|/system LIST> (and many other bits of
10986Like C<exec>, C<system> allows you to lie to a program about its name if
18747Perl) die on error, have a look at the L<autodie> pragma.
10987you use the C<system PROGRAM LIST> syntax. Again, see L</exec>.
1874810988
1874910989=end original
1875010990
18751もし L<C<system>|/system LIST> (及び Perl その他の多くの部分) でエラー時に
10991C<exec> と同様に、C<system> でも C<system PROGRAM LIST> の文法を
18752die したいならL<autodie> マを見みてださい
10992使うことで、プラムに対しその名前を嘘をつことができます
10993再び、L</exec> を参照して下さい。
1875310994
1875410995=begin original
1875510996
18756Like L<C<exec>|/exec LIST>, L<C<system>|/system LIST> allows you to lie
10997Because C<system> and backticks block C<SIGINT> and C<SIGQUIT>, killing the
18757to a program about its name if you use the C<system PROGRAM LIST>
10998program they're running doesn't actually interrupt your program.
18758syntax. Again, see L<C<exec>|/exec LIST>.
1875910999
1876011000=end original
1876111001
18762L<C<exec>|/exec LIST> と同様に、L<C<system>|/system LIST> で
11002C<system> とバッククォートは C<SIGINT> と C<SIGQUIT> をブロックするの
18763C<system PROGRAM LIST> の文法を使うとで、プログラムに対して名前
11003れらが実行したプログラムを kill しても実際に元プログラム
18764嘘をつくことができ
11004中断させることはありせん
18765再び、L<C<exec>|/exec LIST> を参照してください。
1876611005
18767=begin original
11006 @args = ("command", "arg1", "arg2");
18768
18769Since C<SIGINT> and C<SIGQUIT> are ignored during the execution of
18770L<C<system>|/system LIST>, if you expect your program to terminate on
18771receipt of these signals you will need to arrange to do so yourself
18772based on the return value.
18773
18774=end original
18775
18776C<SIGINT> と C<SIGQUIT> は L<C<system>|/system LIST> の実行中は無視されるので、
18777これらのシグナルを受信して終了させることを想定したプログラムの場合、
18778返り値を利用するように変更する必要があります。
18779
18780 my @args = ("command", "arg1", "arg2");
1878111007 system(@args) == 0
18782 or die "system @args failed: $?";
11008 or die "system @args failed: $?"
1878311009
1878411010=begin original
1878511011
18786If you'd like to manually inspect L<C<system>|/system LIST>'s failure,
11012You can check all the failure possibilities by inspecting
18787you can check all possible failure modes by inspecting
11013C<$?> like this:
18788L<C<$?>|perlvar/$?> like this:
1878911014
1879011015=end original
1879111016
18792L<C<system>|/system LIST> の失敗手動検査したいなら以下ように
11017以下のように C<$?> を調べることで、全て失敗の可能性を
18793L<C<$?>|perlvar/$?> を調べることで、全ての失敗の可能性をチェックできます:
11018チェックすることができます:
1879411019
18795 if ($? == -1) {
11020 $exit_value = $? >> 8;
18796 print "failed to execute: $!\n";
11021 $signal_num = $? & 127;
18797 }
11022 $dumped_core = $? & 128;
18798 elsif ($? & 127) {
18799 printf "child died with signal %d, %s coredump\n",
18800 ($? & 127), ($? & 128) ? 'with' : 'without';
18801 }
18802 else {
18803 printf "child exited with value %d\n", $? >> 8;
18804 }
1880511023
1880611024=begin original
1880711025
18808Alternatively, you may inspect the value of
11026When the arguments get executed via the system shell, results
18809L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> with the
11027and return codes will be subject to its quirks and capabilities.
18810L<C<W*()>|POSIX/C<WIFEXITED>> calls from the L<POSIX> module.
11028See L<perlop/"`STRING`"> and L</exec> for details.
1881111029
1881211030=end original
1881311031
18814L<POSIX> モジュールの L<C<W*()>|POSIX/C<WIFEXITED>> 呼び出しを使って
11032引数がシステムシェル経由で実行され場合
18815L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> の
11033結果と返りはシェルの癖と能力によって変更されることがあります。
18816調べるこもできます
11034詳細については L<perlop/"`STRING`"> L</exec> を参照して下さい
1881711035
18818=begin original
18819
18820When L<C<system>|/system LIST>'s arguments are executed indirectly by
18821the shell, results and return codes are subject to its quirks.
18822See L<perlop/"`STRING`"> and L<C<exec>|/exec LIST> for details.
18823
18824=end original
18825
18826L<C<system>|/system LIST> の引数がシェルによって間接的に実行された場合、
18827結果と返り値はシェルの癖によって変更されることがあります。
18828詳細については L<perlop/"`STRING`"> と L<C<exec>|/exec LIST> を
18829参照してください。
18830
18831=begin original
18832
18833Since L<C<system>|/system LIST> does a L<C<fork>|/fork> and
18834L<C<wait>|/wait> it may affect a C<SIGCHLD> handler. See L<perlipc> for
18835details.
18836
18837=end original
18838
18839L<C<system>|/system LIST> は L<C<fork>|/fork> と L<C<wait>|/wait> を行うので、
18840C<SIGCHLD> ハンドラの影響を受けます。
18841詳しくは L<perlipc> を参照してください。
18842
18843=begin original
18844
18845Portability issues: L<perlport/system>.
18846
18847=end original
18848
18849移植性の問題: L<perlport/system>。
18850
1885111036=item syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET
18852X<syswrite>
1885311037
1885411038=item syswrite FILEHANDLE,SCALAR,LENGTH
1885511039
1885611040=item syswrite FILEHANDLE,SCALAR
1885711041
18858=for Pod::Functions fixed-length unbuffered output to a filehandle
18859
1886011042=begin original
1886111043
1886211044Attempts to write LENGTH bytes of data from variable SCALAR to the
18863specified FILEHANDLE, using L<write(2)>. If LENGTH is
11045specified FILEHANDLE, using the system call write(2). If LENGTH
18864not specified, writes whole SCALAR. It bypasses buffered IO, so
11046is not specified, writes whole SCALAR. It bypasses stdio, so mixing
18865mixing this with reads (other than C<sysread)>),
11047this with reads (other than C<sysread())>, C<print>, C<write>,
18866L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
11048C<seek>, C<tell>, or C<eof> may cause confusion because stdio
18867L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
11049usually buffers data. Returns the number of bytes actually written,
18868L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> may cause
11050or C<undef> if there was an error. If the LENGTH is greater than
18869confusion because the perlio and stdio layers usually buffer data.
11051the available data in the SCALAR after the OFFSET, only as much
18870Returns the number of bytes actually written, or L<C<undef>|/undef EXPR>
11052data as is available will be written.
18871if there was an error (in this case the errno variable
18872L<C<$!>|perlvar/$!> is also set). If the LENGTH is greater than the
18873data available in the SCALAR after the OFFSET, only as much data as is
18874available will be written.
1887511053
1887611054=end original
1887711055
18878L<write(2)> を使って、指定した FILEHANDLEへ、変数 SCALAR から、LENGTH バイトの
11056write(2) システムコールを使って、指定した FILEHANDLEへ、
18879データの書き込みを試みます。
11057変数 SCALAR から、LENGTH バイトのデータの書き込みを試みます。
1888011058LENGTH が指定されなかった場合、 SCALAR 全体を書き込みます。
18881これは、バッファ付き IO ルーチンを通りませんから、他の入力関数
11059これは、stdio ルーチンを通りませんから、
18882(C<sysread> 以外),
11060他の入力関数(C<sysread()>以外), C<print>, C<write>,
18883L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
11061C<seek>, C<tell>, or C<eof>と混ぜて使うと、
18884L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>,
11062出力がおかしくなるかもしれません。
18885L<C<eof>|/eof FILEHANDLE> と混ぜて使うと、出力がおかしくなるかもしれません;
11063stdio は普通データをバッファリングするからです。
18886perlio 層と stdio 層は普通データをバッファリングするらです。
11064実際に読み込まれたデータの長さ、エラー時には C<undef> が返されます。
18887実際に読み込まれたデータの長さか、エラー時には L<C<undef>|/undef EXPR> が
18888返されます(この場合エラー変数 L<C<$!>|perlvar/$!> もセットされます)。
1888911065LENGTH が OFFSET 以降の SCALAR の利用可能なデータより大きかった場合、
1889011066利用可能なデータのみが書き込まれます。
1889111067
1889211068=begin original
1889311069
1889411070An OFFSET may be specified to write the data from some part of the
1889511071string other than the beginning. A negative OFFSET specifies writing
18896that many characters counting backwards from the end of the string.
11072that many bytes counting backwards from the end of the string. In the
18897If SCALAR is of length zero, you can only use an OFFSET of 0.
11073case the SCALAR is empty you can use OFFSET but only zero offset.
1889811074
1889911075=end original
1890011076
1890111077OFFSET を指定すると、SCALAR の先頭以外の場所から、
1890211078データを取り出して、書き込みを行なうことができます。
1890311079OFFSET に負の値を指定すると、文字列の最後から逆向きに数えて
1890411080何バイト目から書き込むかを示します。
18905SCALAR の長さ 0 の場合、OFFSET は 0 のみ使用できます。
11081SCALAR がの場合、OFFSET はゼロのみ使用できます。
1890611082
18907=begin original
18908
18909B<WARNING>: If the filehandle is marked C<:utf8>, C<syswrite> will raise an exception.
18910The C<:encoding(...)> layer implicitly introduces the C<:utf8> layer.
18911Alternately, if the handle is not marked with an encoding but you
18912attempt to write characters with code points over 255, raises an exception.
18913See L<C<binmode>|/binmode FILEHANDLE, LAYER>,
18914L<C<open>|/open FILEHANDLE,EXPR>, and the L<open> pragma.
18915
18916=end original
18917
18918B<警告>: ファイルハンドルが C<:utf8> であるとマークが付けられていると、
18919C<syswrite> は例外を投げます。
18920C<:encoding(...)> 層は暗黙のうちに C<:utf8> 層が導入されます。
18921または、もしハンドルにエンコーディングが記録されていない状態で
18922255 を超える符号位置の文字を書き込もうとすると、例外が発生します。
18923L<C<binmode>|/binmode FILEHANDLE, LAYER>, L<C<open>|/open FILEHANDLE,EXPR>,
18924L<open> プラグマを参照してください。
18925
1892611083=item tell FILEHANDLE
18927X<tell>
1892811084
1892911085=item tell
1893011086
18931=for Pod::Functions get current seekpointer on a filehandle
18932
1893311087=begin original
1893411088
18935Returns the current position I<in bytes> for FILEHANDLE, or -1 on
11089Returns the current position for FILEHANDLE, or -1 on error. FILEHANDLE
18936error. FILEHANDLE may be an expression whose value gives the name of
11090may be an expression whose value gives the name of the actual filehandle.
18937the actual filehandle. If FILEHANDLE is omitted, assumes the file
11091If FILEHANDLE is omitted, assumes the file last read.
18938last read.
1893911092
1894011093=end original
1894111094
18942FILEHANDLE の現在の位置を I<バイト数で> 返します; エラーの場合は -1 を
11095FILEHANDLE の現在の位置を返しますエラーの場合は -1 を返します。
18943返します。
1894411096FILEHANDLE は、実際のファイルハンドル名を示す式でもかまいません。
18945FILEHANDLE が省略された場合には、最後に読み込みを行なったファイルについて
11097FILEHANDLE が省略された場合には、
18946調べます。
11098最後に読み込みを行なったファイルについて調べます。
1894711099
1894811100=begin original
1894911101
18950Note the emphasis on bytes: even if the filehandle has been set to operate
11102The return value of tell() for the standard streams like the STDIN
18951on characters (for example using the C<:encoding(UTF-8)> I/O layer), the
11103depends on the operating system: it may return -1 or something else.
18952L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
11104tell() on pipes, fifos, and sockets usually returns -1.
18953L<C<tell>|/tell FILEHANDLE>, and
18954L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>
18955family of functions use byte offsets, not character offsets,
18956because seeking to a character offset would be very slow in a UTF-8 file.
1895711105
1895811106=end original
1895911107
18960バイ単位に対する注意: 例え(例えば C<:encoding(UTF-8)> I/O 層を使うなどて)
11108STDIN のような標準スリームに対する tell() の返り値は OS に依存ます。
18961ファイルハンドルが文字単位で処理するように設定されていたとしても、
18962L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
18963L<C<tell>|/tell FILEHANDLE>,
18964L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> シリーズの関数は
18965文字オフセットではなくバイトオフセットを使います;
18966文字オフセットでシークするのは UTF-8 ファイルではとても遅いからです。
18967
18968=begin original
18969
18970The return value of L<C<tell>|/tell FILEHANDLE> for the standard streams
18971like the STDIN depends on the operating system: it may return -1 or
18972something else. L<C<tell>|/tell FILEHANDLE> on pipes, fifos, and
18973sockets usually returns -1.
18974
18975=end original
18976
18977STDIN のような標準ストリームに対する L<C<tell>|/tell FILEHANDLE> の返り値は
18978OS に依存します:
1897911109-1 やその他の値が返ってくるかもしれません。
18980パイプ、FIFO、ソケットに対して L<C<tell>|/tell FILEHANDLE> を使うと、普通は
11110パイプ、FIFO、ソケットに対して tell() を使うと、普通は -1 が返ります。
18981-1 が返ります。
1898211111
1898311112=begin original
1898411113
18985There is no C<systell> function. Use
11114There is no C<systell> function. Use C<sysseek(FH, 0, 1)> for that.
18986L<C<sysseek($fh, 0, 1)>|/sysseek FILEHANDLE,POSITION,WHENCE> for that.
1898711115
1898811116=end original
1898911117
1899011118C<systell> 関数はありません。
18991代わりに L<C<sysseek($fh, 0, 1)>|/sysseek FILEHANDLE,POSITION,WHENCE>
11119代わりに C<sysseek(FH, 0, 1)> を使ってください。
18992使ってください。
1899311120
18994=begin original
18995
18996Do not use L<C<tell>|/tell FILEHANDLE> (or other buffered I/O
18997operations) on a filehandle that has been manipulated by
18998L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
18999L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, or
19000L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>. Those functions
19001ignore the buffering, while L<C<tell>|/tell FILEHANDLE> does not.
19002
19003=end original
19004
19005L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
19006L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
19007L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> で操作された
19008ファイルハンドルに L<C<tell>|/tell FILEHANDLE>
19009(またはその他のバッファリング I/O 操作) を使わないでください。
19010これらの関数はバッファリングを無視しますが、L<C<tell>|/tell FILEHANDLE> は
19011違います。
19012
1901311121=item telldir DIRHANDLE
19014X<telldir>
1901511122
19016=for Pod::Functions get current seekpointer on a directory handle
19017
1901811123=begin original
1901911124
19020Returns the current position of the L<C<readdir>|/readdir DIRHANDLE>
11125Returns the current position of the C<readdir> routines on DIRHANDLE.
19021routines on DIRHANDLE. Value may be given to
11126Value may be given to C<seekdir> to access a particular location in a
19022L<C<seekdir>|/seekdir DIRHANDLE,POS> to access a particular location in
11127directory. Has the same caveats about possible directory compaction as
19023a directory. L<C<telldir>|/telldir DIRHANDLE> has the same caveats
11128the corresponding system library routine.
19024about possible directory compaction as the corresponding system library
19025routine.
1902611129
1902711130=end original
1902811131
19029DIRHANDLE 上の L<C<readdir>|/readdir DIRHANDLE> ルーチンに対する現在位置を
11132DIRHANDLE 上の C<readdir> ルーチンに対する現在位置を返します。
19030返します。
1903111133値は、そのディレクトリで特定の位置をアクセスするため、
19032L<C<seekdir>|/seekdir DIRHANDLE,POS> に渡すことができます。
11134C<seekdir> に渡すことができます。
19033L<C<telldir>|/telldir DIRHANDLE> は同名のシステムライブラリルーチンと同じく、
11135同名のシステムライブラリルーチンと同じく、
1903411136ディレクトリ縮小時の問題が考えられます。
1903511137
1903611138=item tie VARIABLE,CLASSNAME,LIST
19037X<tie>
1903811139
19039=for Pod::Functions +5.002 bind a variable to an object class
19040
1904111140=begin original
1904211141
1904311142This function binds a variable to a package class that will provide the
1904411143implementation for the variable. VARIABLE is the name of the variable
1904511144to be enchanted. CLASSNAME is the name of a class implementing objects
19046of correct type. Any additional arguments are passed to the
11145of correct type. Any additional arguments are passed to the C<new>
19047appropriate constructor
1904811146method of the class (meaning C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>,
1904911147or C<TIEHASH>). Typically these are arguments such as might be passed
19050to the L<dbm_open(3)> function of C. The object returned by the
11148to the C<dbm_open()> function of C. The object returned by the C<new>
19051constructor is also returned by the
11149method is also returned by the C<tie> function, which would be useful
19052L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function, which would be useful
1905311150if you want to access other methods in CLASSNAME.
1905411151
1905511152=end original
1905611153
1905711154この関数は、変数を、その変数の実装を行なうクラスと結び付けます。
1905811155VARIABLE は、魔法をかける変数の名前です。
1905911156CLASSNAME は、正しい型のオブジェクトを実装するクラスの名前です。
19060他に引数があれば、そのクラスの適切なコンストラクタメソッドに渡されます
11157他に引数があれば、そのクラスの C<new> メソッドに渡されます
1906111158(つまり C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>, C<TIEHASH>)。
19062通常、これらは、C の L<dbm_open(3)> などの関数に渡す引数となります。
11159通常、これらは、C の C<dbm_open> などの関数に渡す引数となります。
19063コンストラクタで返されるオブジェクトはまた
11160C<new> メソッドで返されるオブジェクトはまた C<tie> 関数でも返されます。
19064L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数でも返されます;
1906511161これは CLASSNAME の他のメソッドにアクセスしたいときに便利です。
1906611162
1906711163=begin original
1906811164
19069Note that functions such as L<C<keys>|/keys HASH> and
11165Note that functions such as C<keys> and C<values> may return huge lists
19070L<C<values>|/values HASH> may return huge lists when used on large
11166when used on large objects, like DBM files. You may prefer to use the
19071objects, like DBM files. You may prefer to use the L<C<each>|/each
11167C<each> function to iterate over such. Example:
19072HASH> function to iterate over such. Example:
1907311168
1907411169=end original
1907511170
19076DBM ファイルのような大きなオブジェクトでは、L<C<keys>|/keys HASH>
11171DBM ファイルのような大きなオブジェクトでは、C<keys> や C<values> のような
19077L<C<values>|/values HASH> のような関数は、大きなリストを返す可能性があります。
11172関数は、大きなリストを返す可能性があります。
19078そのような場合では、L<C<each>|/each HASH> 関数を使って繰り返しを行なった方が
11173そのような場合では、C<each> 関数を使って繰り返しを行なった方が
1907911174よいかもしれません。
1908011175例:
1908111176
1908211177 # print out history file offsets
1908311178 use NDBM_File;
19084 tie(my %HIST, 'NDBM_File', '/usr/lib/news/history', 1, 0);
11179 tie(%HIST, 'NDBM_File', '/usr/lib/news/history', 1, 0);
19085 while (my ($key,$val) = each %HIST) {
11180 while (($key,$val) = each %HIST) {
19086 print $key, ' = ', unpack('L', $val), "\n";
11181 print $key, ' = ', unpack('L',$val), "\n";
1908711182 }
11183 untie(%HIST);
1908811184
1908911185=begin original
1909011186
1909111187A class implementing a hash should have the following methods:
1909211188
1909311189=end original
1909411190
1909511191ハッシュを実装するクラスでは、次のようなメソッドを用意します:
1909611192
1909711193 TIEHASH classname, LIST
1909811194 FETCH this, key
1909911195 STORE this, key, value
1910011196 DELETE this, key
1910111197 CLEAR this
1910211198 EXISTS this, key
1910311199 FIRSTKEY this
1910411200 NEXTKEY this, lastkey
19105 SCALAR this
1910611201 DESTROY this
1910711202 UNTIE this
1910811203
1910911204=begin original
1911011205
1911111206A class implementing an ordinary array should have the following methods:
1911211207
1911311208=end original
1911411209
1911511210通常の配列を実装するクラスでは、次のようなメソッドを用意します:
1911611211
1911711212 TIEARRAY classname, LIST
1911811213 FETCH this, key
1911911214 STORE this, key, value
1912011215 FETCHSIZE this
1912111216 STORESIZE this, count
1912211217 CLEAR this
1912311218 PUSH this, LIST
1912411219 POP this
1912511220 SHIFT this
1912611221 UNSHIFT this, LIST
1912711222 SPLICE this, offset, length, LIST
1912811223 EXTEND this, count
19129 DELETE this, key
19130 EXISTS this, key
1913111224 DESTROY this
1913211225 UNTIE this
1913311226
1913411227=begin original
1913511228
19136A class implementing a filehandle should have the following methods:
11229A class implementing a file handle should have the following methods:
1913711230
1913811231=end original
1913911232
1914011233ファイルハンドルを実装するクラスでは、次のようなメソッドを用意します:
1914111234
1914211235 TIEHANDLE classname, LIST
1914311236 READ this, scalar, length, offset
1914411237 READLINE this
1914511238 GETC this
1914611239 WRITE this, scalar, length, offset
1914711240 PRINT this, LIST
1914811241 PRINTF this, format, LIST
1914911242 BINMODE this
1915011243 EOF this
1915111244 FILENO this
1915211245 SEEK this, position, whence
1915311246 TELL this
1915411247 OPEN this, mode, LIST
1915511248 CLOSE this
1915611249 DESTROY this
1915711250 UNTIE this
1915811251
1915911252=begin original
1916011253
1916111254A class implementing a scalar should have the following methods:
1916211255
1916311256=end original
1916411257
1916511258スカラ変数を実装するクラスでは、次のようなメソッドを用意します:
1916611259
1916711260 TIESCALAR classname, LIST
1916811261 FETCH this,
1916911262 STORE this, value
1917011263 DESTROY this
1917111264 UNTIE this
1917211265
1917311266=begin original
1917411267
1917511268Not all methods indicated above need be implemented. See L<perltie>,
1917611269L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>, and L<Tie::Handle>.
1917711270
1917811271=end original
1917911272
1918011273上記の全てのメソッドを実装する必要はありません。
1918111274L<perltie>, L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>,
19182L<Tie::Handle> を参照してください。
11275L<Tie::Handle> を参照してさい。
1918311276
1918411277=begin original
1918511278
19186Unlike L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, the
11279Unlike C<dbmopen>, the C<tie> function will not use or require a module
19187L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function will not
11280for you--you need to do that explicitly yourself. See L<DB_File>
19188L<C<use>|/use Module VERSION LIST> or L<C<require>|/require VERSION> a
11281or the F<Config> module for interesting C<tie> implementations.
19189module for you; you need to do that explicitly yourself. See L<DB_File>
19190or the L<Config> module for interesting
19191L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> implementations.
1919211282
1919311283=end original
1919411284
19195L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> と違い、
11285C<dbmopen> と違い、C<tie> 関数はモジュールを use したり
19196L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数はモジュールを
11286require したりしません -- 自分で明示的に行う必要があります。
19197L<C<use>|/use Module VERSION LIST> したり
11287C<tie> の興味深い実装については L<DB_File> F<Config> モジュールを
19198L<C<require>|/require VERSION> たりしません;
11288参照て下さい。
19199自分で明示的に行う必要があります。
19200L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> の興味深い実装については
19201L<DB_File> や L<Config> モジュールを参照してください。
1920211289
1920311290=begin original
1920411291
19205For further details see L<perltie>, L<C<tied>|/tied VARIABLE>.
11292For further details see L<perltie>, L<"tied VARIABLE">.
1920611293
1920711294=end original
1920811295
19209更なる詳細については L<perltie> や L<C<tied>|/tied VARIABLE> を
11296更なる詳細については L<perltie> や L<"tied VARIABLE"> を参照して下さい。
19210参照してください。
1921111297
1921211298=item tied VARIABLE
19213X<tied>
1921411299
19215=for Pod::Functions get a reference to the object underlying a tied variable
19216
1921711300=begin original
1921811301
1921911302Returns a reference to the object underlying VARIABLE (the same value
19220that was originally returned by the
11303that was originally returned by the C<tie> call that bound the variable
19221L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> call that bound the variable
1922211304to a package.) Returns the undefined value if VARIABLE isn't tied to a
1922311305package.
1922411306
1922511307=end original
1922611308
1922711309VARIABLE の基となるオブジェクトへのリファレンスを返します
19228(変数をパッケージに結びつけるために
11310(変数をパッケージに結びつけるために C<tie> 呼び出しをしたときの
19229L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 呼び出しをしたときの
1923011311返り値と同じものです)。
1923111312VARIABLE がパッケージと結び付けられていない場合は未定義値を返します。
1923211313
1923311314=item time
19234X<time> X<epoch>
1923511315
19236=for Pod::Functions return number of seconds since 1970
19237
1923811316=begin original
1923911317
1924011318Returns the number of non-leap seconds since whatever time the system
19241considers to be the epoch, suitable for feeding to
11319considers to be the epoch (that's 00:00:00, January 1, 1904 for MacOS,
19242L<C<gmtime>|/gmtime EXPR> and L<C<localtime>|/localtime EXPR>. On most
11320and 00:00:00 UTC, January 1, 1970 for most other systems).
19243systems the epoch is 00:00:00 UTC, January 1, 1970;
11321Suitable for feeding to C<gmtime> and C<localtime>.
19244a prominent exception being Mac OS Classic which uses 00:00:00, January 1,
192451904 in the current local time zone for its epoch.
1924611322
1924711323=end original
1924811324
19249L<C<gmtime>|/gmtime EXPR> や L<C<localtime>|/localtime EXPR> への入力形式に
11325システムが紀元と考える時点 (MacOS では 1904 年 1 月 1 日 00:00:00、
19250合っている、システムが紀元と考える時点からの連続秒数を返します。
11326その他のほとんどのシステムでは UTC 1970 年 1 月 1 日 00:00:00) からの
19251ほとんどのシステムでは紀元は UTC 1970 年 1 月 1 日 00:00:00 で;
11327連続秒数を返しま
19252特徴的な例外としては、古い Mac OS ではローカルタイムゾーン
11328C<gmtime> や C<localtime> 入力形式にあっています。
192531904 年 1 月 1 日 00:00:00 を紀元として使います。
1925411329
1925511330=begin original
1925611331
19257For measuring time in better granularity than one second, use the
11332For measuring time in better granularity than one second,
19258L<Time::HiRes> module from Perl 5.8 onwards (or from CPAN before then), or,
11333you may use either the Time::HiRes module from CPAN, or
19259if you have L<gettimeofday(2)>, you may be able to use the
11334if you have gettimeofday(2), you may be able to use the
19260L<C<syscall>|/syscall NUMBER, LIST> interface of Perl. See L<perlfaq8>
11335C<syscall> interface of Perl, see L<perlfaq8> for details.
19261for details.
1926211336
1926311337=end original
1926411338
192651 秒よりも細かい時間を計測するためには、Perl 5.8 以降(それ以前では
113391 秒よりも細かい時間を計測するためには、
19266CPANから)L<Time::HiRes> モジュールを使うか、
11340CPAN の Time::HiRes モジュールを使うか、
19267L<gettimeofday(2)> があるなら、Perl の
11341gettimeofday(2) があるなら、Perl の C<syscall> インターフェースを
19268L<C<syscall>|/syscall NUMBER, LIST> インターフェースを使ってください。
11342使った方がよでしょう
19269詳しくは L<perlfaq8> を参照してください。
11343詳しくは L<perlfaq8> を参照してさい。
1927011344
19271=begin original
19272
19273For date and time processing look at the many related modules on CPAN.
19274For a comprehensive date and time representation look at the
19275L<DateTime> module.
19276
19277=end original
19278
19279日付と時刻の処理は、多くの関連するモジュールが CPAN にあります。
19280包括的な日付と時刻の表現については、CPAN の L<DateTime> モジュールを
19281参照してください。
19282
1928311345=item times
19284X<times>
1928511346
19286=for Pod::Functions return elapsed time for self and child processes
19287
1928811347=begin original
1928911348
19290Returns a four-element list giving the user and system times in
11349Returns a four-element list giving the user and system times, in
19291seconds for this process and any exited children of this process.
11350seconds, for this process and the children of this process.
1929211351
1929311352=end original
1929411353
19295現プロセス及び終了したその子プロセスに対する、ユーザ時間とシステム時間を
11354現プロセス及びその子プロセスに対する、ユーザ時間とシステム時間を
1929611355秒で示した、4 要素のリスト値を返します。
1929711356
19298 my ($user,$system,$cuser,$csystem) = times;
11357 ($user,$system,$cuser,$csystem) = times;
1929911358
19300=begin original
19301
19302In scalar context, L<C<times>|/times> returns C<$user>.
19303
19304=end original
19305
19306スカラコンテキストでは、L<C<times>|/times> は C<$user> を返します。
19307
19308=begin original
19309
19310Children's times are only included for terminated children.
19311
19312=end original
19313
19314子プロセスに対する times は、終了した子プロセスのみ含められます。
19315
19316=begin original
19317
19318Portability issues: L<perlport/times>.
19319
19320=end original
19321
19322移植性の問題: L<perlport/times>。
19323
1932411359=item tr///
1932511360
19326=for Pod::Functions transliterate a string
19327
1932811361=begin original
1932911362
19330The transliteration operator. Same as
11363The transliteration operator. Same as C<y///>. See L<perlop>.
19331L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>>. See
19332L<perlop/"Quote-Like Operators">.
1933311364
1933411365=end original
1933511366
19336文字変換演算子です。
11367変換演算子。C<y///>と同じです。
19337L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>> と同じです
11368L<perlop> を参照してください
19338L<perlop/"Quote-Like Operators"> を参照してください。
1933911369
1934011370=item truncate FILEHANDLE,LENGTH
19341X<truncate>
1934211371
1934311372=item truncate EXPR,LENGTH
1934411373
19345=for Pod::Functions shorten a file
19346
1934711374=begin original
1934811375
1934911376Truncates the file opened on FILEHANDLE, or named by EXPR, to the
19350specified length. Raises an exception if truncate isn't implemented
11377specified length. Produces a fatal error if truncate isn't implemented
19351on your system. Returns true if successful, L<C<undef>|/undef EXPR> on
11378on your system. Returns true if successful, the undefined value
19352error.
11379otherwise.
1935311380
1935411381=end original
1935511382
1935611383FILEHANDLE 上にオープンされたファイルか、EXPR で名前を表わしたファイルを、
1935711384指定した長さに切り詰めます。
19358システム上に truncate が実装されていなければ、例外が発生します。
11385システム上に truncate が実装されていなければ、致命的エラーとなります。
19359成功すれば真を、エラー時には L<C<undef>|/undef EXPR> を返します。
11386成功すれば真を、さもなければ未定義値を返します。
1936011387
19361=begin original
19362
19363The behavior is undefined if LENGTH is greater than the length of the
19364file.
19365
19366=end original
19367
19368LENGTH がファイルの長さより大きい場合の振る舞いは未定義です。
19369
19370=begin original
19371
19372The position in the file of FILEHANDLE is left unchanged. You may want to
19373call L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> before writing to the
19374file.
19375
19376=end original
19377
19378FILEHANDLE のファイルの位置は変わりません。
19379ファイルに書き込む前に L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> を
19380呼び出したいかもしれません。
19381
19382=begin original
19383
19384Portability issues: L<perlport/truncate>.
19385
19386=end original
19387
19388移植性の問題: L<perlport/truncate>。
19389
1939011388=item uc EXPR
19391X<uc> X<uppercase> X<toupper>
1939211389
1939311390=item uc
1939411391
19395=for Pod::Functions return upper-case version of a string
19396
1939711392=begin original
1939811393
1939911394Returns an uppercased version of EXPR. This is the internal function
1940011395implementing the C<\U> escape in double-quoted strings.
19401It does not attempt to do titlecase mapping on initial letters. See
11396Respects current LC_CTYPE locale if C<use locale> in force. See L<perllocale>.
19402L<C<ucfirst>|/ucfirst EXPR> for that.
11397Under Unicode (C<use utf8>) it uses the standard Unicode uppercase mappings. (It
11398does not attempt to do titlecase mapping on initial letters. See C<ucfirst> for that.)
1940311399
11400If EXPR is omitted, uses C<$_>.
11401
1940411402=end original
1940511403
1940611404EXPR を大文字に変換したものを返します。
1940711405これは、ダブルクォート文字列における、C<\U> エスケープを
1940811406実装する内部関数です。
19409先頭文字タイト文字マッピングは試みせん
11407C<use locale> が有効な場合は、現在LC_CTYPE ロケーを参照し
19410このためには L<C<ucfirst>|/ucfirst EXPR> を参照してください。
11408L<perllocale> を参照してください。
11409(C<use utf8> を使った) Unicode では、標準 Unicode 大文字マッピングを
11410使います。
11411(元の文字の titlecase マッピングは試みません。
11412このためには C<ucfirst> を参照してください。)
1941111413
19412=begin original
11414EXPR が省略されると、C<$_> を使います。
1941311415
19414If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
19415
19416=end original
19417
19418EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
19419
19420=begin original
19421
19422This function behaves the same way under various pragmas, such as in a locale,
19423as L<C<lc>|/lc EXPR> does.
19424
19425=end original
19426
19427この関数は、ロケールのようなさまざまなプラグマの影響下では、
19428L<C<lc>|/lc EXPR> と同様に振る舞います。
19429
1943011416=item ucfirst EXPR
19431X<ucfirst> X<uppercase>
1943211417
1943311418=item ucfirst
1943411419
19435=for Pod::Functions return a string with just the next letter in upper case
19436
1943711420=begin original
1943811421
19439Returns the value of EXPR with the first character in uppercase
11422Returns the value of EXPR with the first character
19440(titlecase in Unicode). This is the internal function implementing
11423in uppercase (titlecase in Unicode). This is
19441the C<\u> escape in double-quoted strings.
11424the internal function implementing the C<\u> escape in double-quoted strings.
11425Respects current LC_CTYPE locale if C<use locale> in force. See L<perllocale>
11426and L<utf8>.
1944211427
11428If EXPR is omitted, uses C<$_>.
11429
1944311430=end original
1944411431
1944511432最初の文字だけを大文字にした、EXPR を返します
1944611433(Unicode では titlecase)。
1944711434これは、ダブルクォート文字列における、C<\u> エスケープを
1944811435実装する内部関数です。
11436C<use locale> が有効な場合は、現在の LC_CTYPE ロケールを参照します。
11437L<perllocale> と L<utf8> を参照してください。
1944911438
19450=begin original
11439EXPR が省略されると、C<$_> を使います。
1945111440
19452If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
19453
19454=end original
19455
19456EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
19457
19458=begin original
19459
19460This function behaves the same way under various pragmas, such as in a locale,
19461as L<C<lc>|/lc EXPR> does.
19462
19463=end original
19464
19465この関数は、ロケールのようなさまざまなプラグマの影響下では、
19466L<C<lc>|/lc EXPR> と同様に振る舞います。
19467
1946811441=item umask EXPR
19469X<umask>
1947011442
1947111443=item umask
1947211444
19473=for Pod::Functions set file creation mode mask
19474
1947511445=begin original
1947611446
1947711447Sets the umask for the process to EXPR and returns the previous value.
1947811448If EXPR is omitted, merely returns the current umask.
1947911449
1948011450=end original
1948111451
1948211452現在のプロセスの umask を EXPR に設定し、以前の値を返します。
1948311453EXPR が省略されると、単にその時点の umask の値を返します。
1948411454
1948511455=begin original
1948611456
1948711457The Unix permission C<rwxr-x---> is represented as three sets of three
1948811458bits, or three octal digits: C<0750> (the leading 0 indicates octal
19489and isn't one of the digits). The L<C<umask>|/umask EXPR> value is such
11459and isn't one of the digits). The C<umask> value is such a number
19490a number representing disabled permissions bits. The permission (or
11460representing disabled permissions bits. The permission (or "mode")
19491"mode") values you pass L<C<mkdir>|/mkdir FILENAME,MODE> or
11461values you pass C<mkdir> or C<sysopen> are modified by your umask, so
19492L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> are modified by your
11462even if you tell C<sysopen> to create a file with permissions C<0777>,
19493umask, so even if you tell
11463if your umask is C<0022> then the file will actually be created with
19494L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> to create a file with
11464permissions C<0755>. If your C<umask> were C<0027> (group can't
19495permissions C<0777>, if your umask is C<0022>, then the file will
11465write; others can't read, write, or execute), then passing
19496actually be created with permissions C<0755>. If your
11466C<sysopen> C<0666> would create a file with mode C<0640> (C<0666 &~
19497L<C<umask>|/umask EXPR> were C<0027> (group can't write; others can't
11467027> is C<0640>).
19498read, write, or execute), then passing
19499L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> C<0666> would create a
19500file with mode C<0640> (because C<0666 &~ 027> is C<0640>).
1950111468
1950211469=end original
1950311470
19504Unix パーミッション C<rwxr-x---> は 3 ビットのつの組、
11471Unix パーミッション C<rwxr-x---> は 3 ビットの 3 つの組、
1950511472または 3 桁の 8 進数として表現されます:
1950611473C<0750> (先頭の 0 は 8 進数を意味し、実際の値ではありません)。
19507L<C<umask>|/umask EXPR> の値は無効にするパーミッションビットのこのような
11474C<umask> の値は無効にするパーミッションビットのこのような数値表現です。
19508数値表現す。
11475C<mkdir> や C<sysopen> 渡されたパーミッション(または「モード」)の値は
19509L<C<mkdir>|/mkdir FILENAME,MODE>
11476umask で修正され、たとえ C<sysopen> で C<0777> のパーミッションで
19510L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> で渡されたパーミッション
19511(または「モード」)の値は umask で修正され、たとえ
19512L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> で C<0777> のパーミッションで
1951311477ファイルを作るように指定しても、umask が C<0022> なら、
1951411478結果としてファイルは C<0755> のパーミッションで作成されます。
19515L<C<umask>|/umask EXPR> が C<0027> (グループは書き込めない; その他は読み込み、
11479C<umask> が C<0027> (グループは書き込めない; その他は読み込み、書き込み、
19516書き込み、実行できない) のとき
11480実行できない) のとき、C<sysopen> に C<0666> を渡すと、
19517L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> に C<0666> を渡と、
11481ファイルはモード C<0640> (C<0666 &~ 027> は C<0640>)で作成されま
19518ファイルはモード C<0640> (なぜなら C<0666 &~ 027> は C<0640>)で作成されます。
1951911482
1952011483=begin original
1952111484
1952211485Here's some advice: supply a creation mode of C<0666> for regular
19523files (in L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>) and one of
11486files (in C<sysopen>) and one of C<0777> for directories (in
19524C<0777> for directories (in L<C<mkdir>|/mkdir FILENAME,MODE>) and
11487C<mkdir>) and executable files. This gives users the freedom of
19525executable files. This gives users the freedom of
1952611488choice: if they want protected files, they might choose process umasks
1952711489of C<022>, C<027>, or even the particularly antisocial mask of C<077>.
1952811490Programs should rarely if ever make policy decisions better left to
1952911491the user. The exception to this is when writing files that should be
19530kept private: mail files, web browser cookies, F<.rhosts> files, and
11492kept private: mail files, web browser cookies, I<.rhosts> files, and
1953111493so on.
1953211494
1953311495=end original
1953411496
19535以下は助言です: 作成モードとして、
11497以下は助言です: 作成モードとして、(C<sysopen> による)通常ファイルでは
19536(L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> による)通常ファイルでは
11498C<0666> を、(C<mkdir> による)ディレクトリでは C<0777> を指定しましょう。
19537C<0666> を、(L<C<mkdir>|/mkdir FILENAME,MODE> による)ディレクトリでは
19538C<0777> を指定しましょう。
1953911499これにより、ユーザーに選択の自由を与えます: もしファイルを守りたいなら、
1954011500プロセスの umask として C<022>, C<027>, あるいは特に非社交的な
1954111501C<077> を選択できます。
1954211502プログラムがユーザーより適切なポリシー選択ができることは稀です。
1954311503例外は、プライベートに保つべきファイル(メール、ウェブブラウザのクッキー、
19544F<.rhosts> ファイルなど)を書く場合です。
11504I<.rhosts> ファイルなど)を書く場合です。
1954511505
1954611506=begin original
1954711507
19548If L<umask(2)> is not implemented on your system and you are trying to
11508If umask(2) is not implemented on your system and you are trying to
19549restrict access for I<yourself> (i.e., C<< (EXPR & 0700) > 0 >>),
11509restrict access for I<yourself> (i.e., (EXPR & 0700) > 0), produces a
19550raises an exception. If L<umask(2)> is not implemented and you are
11510fatal error at run time. If umask(2) is not implemented and you are
19551not trying to restrict access for yourself, returns
11511not trying to restrict access for yourself, returns C<undef>.
19552L<C<undef>|/undef EXPR>.
1955311512
1955411513=end original
1955511514
19556L<umask(2)> が実装されていないシステムで、I<自分自身> へのアクセスを
11515umask(2) が実装されていないシステムで、I<自分自身> へのアクセスを
19557制限しようとした(つまり C<< (EXPR & 0700) > 0 >>)場合、例外発生します。
11516制限しようとした(つまり (EXPR & 0700) > 0)場合、実行時に致命的エラー
19558L<umask(2)> が実装されていないシステムで、自分自身へのアクセスは
11517発生します。
19559制限しようとしなかった場合、L<C<undef>|/undef EXPR> を返します。
11518umask(2) が実装されていないシステムで、自分自身へのアクセスは
11519制限しようとしなかった場合、C<undef> を返します。
1956011520
1956111521=begin original
1956211522
1956311523Remember that a umask is a number, usually given in octal; it is I<not> a
19564string of octal digits. See also L<C<oct>|/oct EXPR>, if all you have
11524string of octal digits. See also L</oct>, if all you have is a string.
19565is a string.
1956611525
1956711526=end original
1956811527
19569umask は通常 8 進数で与えられる数値であることを忘れないでください; 8 進数の
11528umask は通常 8 進数で与えられる数値であることを忘れないでください
19570文字列 I<ではありません>。
115298 進数の文字列 I<ではありません>。
19571文字列しかない場合、 L<C<oct>|/oct EXPR> も参照してください。
11530文字列しかない場合、 L</oct> も参照してさい。
1957211531
19573=begin original
19574
19575Portability issues: L<perlport/umask>.
19576
19577=end original
19578
19579移植性の問題: L<perlport/umask>。
19580
1958111532=item undef EXPR
19582X<undef> X<undefine>
1958311533
1958411534=item undef
1958511535
19586=for Pod::Functions remove a variable or function definition
19587
1958811536=begin original
1958911537
1959011538Undefines the value of EXPR, which must be an lvalue. Use only on a
1959111539scalar value, an array (using C<@>), a hash (using C<%>), a subroutine
19592(using C<&>), or a typeglob (using C<*>). Saying C<undef $hash{$key}>
11540(using C<&>), or a typeglob (using <*>). (Saying C<undef $hash{$key}>
1959311541will probably not do what you expect on most predefined variables or
19594DBM list values, so don't do that; see L<C<delete>|/delete EXPR>.
11542DBM list values, so don't do that; see L<delete>.) Always returns the
19595Always returns the undefined value.
11543undefined value. You can omit the EXPR, in which case nothing is
19596You can omit the EXPR, in which case nothing is
1959711544undefined, but you still get an undefined value that you could, for
19598instance, return from a subroutine, assign to a variable, or pass as a
11545instance, return from a subroutine, assign to a variable or pass as a
1959911546parameter. Examples:
1960011547
1960111548=end original
1960211549
1960311550左辺値である EXPR の値を未定義にします。
19604スカラ値、(C<@> を使った)配列、(C<%> を使った)ハッシュ、(C<&> を使った)
11551スカラ値、(C<@>を使った)配列、(C<%>を使った)ハッシュ、(C<&> を使った)
19605サブルーチン、(C<*> を使った)グロブだけに使用します。
11552サブルーチン、(C<*>を使った)タイプグロブだけに使用します。
19606特殊変数や DBM リスト値に C<undef $hash{$key}> などとしても
11553(特殊変数や DBM リスト値に C<undef $hash{$key}>などとしても
19607おそらく期待通りの結果にはなりませんから、しないでください;
11554おそらく期待通りの結果にはなりませんから、
19608L<C<delete>|/delete EXPR> を参照してください。
11555しないでください。L<delete>を参照してください。)
1960911556常に未定義値を返します。
1961011557EXPR は省略することができ、その場合には何も未定義にされませんが
1961111558未定義値は返されますので、それをたとえば、
1961211559サブルーチンの返り値、変数への割り当て、引数などとして使うことができます。
1961311560例:
1961411561
1961511562 undef $foo;
1961611563 undef $bar{'blurfl'}; # Compare to: delete $bar{'blurfl'};
1961711564 undef @ary;
1961811565 undef %hash;
1961911566 undef &mysub;
1962011567 undef *xyz; # destroys $xyz, @xyz, %xyz, &xyz, etc.
1962111568 return (wantarray ? (undef, $errmsg) : undef) if $they_blew_it;
1962211569 select undef, undef, undef, 0.25;
19623 my ($x, $y, undef, $z) = foo(); # Ignore third value returned
11570 ($a, $b, undef, $c) = &foo; # Ignore third value returned
1962411571
1962511572=begin original
1962611573
1962711574Note that this is a unary operator, not a list operator.
1962811575
1962911576=end original
1963011577
1963111578これはリスト演算子ではなく、単項演算子であることに注意してください。
1963211579
1963311580=item unlink LIST
19634X<unlink> X<delete> X<remove> X<rm> X<del>
1963511581
1963611582=item unlink
1963711583
19638=for Pod::Functions remove one link to a file
19639
1964011584=begin original
1964111585
19642Deletes a list of files. On success, it returns the number of files
11586Deletes a list of files. Returns the number of files successfully
19643it successfully deleted. On failure, it returns false and sets
11587deleted.
19644L<C<$!>|perlvar/$!> (errno):
1964511588
1964611589=end original
1964711590
1964811591LIST に含まれるファイルを削除します。
19649成功時は削除に成功したファイルの数を返します。
11592削除に成功したファイルの数を返します。
19650失敗時は偽を返して L<C<$!>|perlvar/$!> (error) をセットします:
1965111593
19652 my $unlinked = unlink 'a', 'b', 'c';
11594 $cnt = unlink 'a', 'b', 'c';
1965311595 unlink @goners;
19654 unlink glob "*.bak";
11596 unlink <*.bak>;
1965511597
1965611598=begin original
1965711599
19658On error, L<C<unlink>|/unlink LIST> will not tell you which files it
11600Note: C<unlink> will not delete directories unless you are superuser and
19659could not remove.
11601the B<-U> flag is supplied to Perl. Even if these conditions are
19660If you want to know which files you could not remove, try them one
11602met, be warned that unlinking a directory can inflict damage on your
19661at a time:
11603filesystem. Use C<rmdir> instead.
1966211604
19663=end original
11605If LIST is omitted, uses C<$_>.
1966411606
19665エラーの場合、L<C<unlink>|/unlink LIST> はどのファイルが削除できなかったかを
19666知らせません。
19667どのファイルが削除できなかったかを知りたい場合は、一つずつ削除してください:
19668
19669 foreach my $file ( @goners ) {
19670 unlink $file or warn "Could not unlink $file: $!";
19671 }
19672
19673=begin original
19674
19675Note: L<C<unlink>|/unlink LIST> will not attempt to delete directories
19676unless you are
19677superuser and the B<-U> flag is supplied to Perl. Even if these
19678conditions are met, be warned that unlinking a directory can inflict
19679damage on your filesystem. Finally, using L<C<unlink>|/unlink LIST> on
19680directories is not supported on many operating systems. Use
19681L<C<rmdir>|/rmdir FILENAME> instead.
19682
1968311607=end original
1968411608
19685注: スーパーユーザ権限で、Perl に B<-U> を付けて実行した場合でなければ、
11609注: スーパーユーザ権限で、Perl に -U を付けて実行した
19686L<C<unlink>|/unlink LIST> はディレクトリを削除しようとすることはありません。
11610場合でなければ、C<unlink> ディレクトリを削除することはありません。
1968711611この条件にあう場合にも、ディレクトリの削除は、
19688ファイルシステムに多大な損害を与える可能性があります
11612ファイルシステムに多大な損害を与える可能性がありますので、
19689最後、L<C<unlink>|/unlink LIST> ディレクトリに使うのはほとんどの OS では
11613注意が必要です。C<rmdir> を代わりに使ってください。
19690対応していません。
19691代わりに L<C<rmdir>|/rmdir FILENAME> を使ってください。
1969211614
19693=begin original
11615LIST が省略されると、C<$_> を使います。
1969411616
19695If LIST is omitted, L<C<unlink>|/unlink LIST> uses L<C<$_>|perlvar/$_>.
19696
19697=end original
19698
19699LIST が省略されると、L<C<unlink>|/unlink LIST> は L<C<$_>|perlvar/$_> を
19700使います。
19701
1970211617=item unpack TEMPLATE,EXPR
19703X<unpack>
1970411618
19705=item unpack TEMPLATE
19706
19707=for Pod::Functions convert binary structure into normal perl variables
19708
1970911619=begin original
1971011620
19711L<C<unpack>|/unpack TEMPLATE,EXPR> does the reverse of
11621C<unpack> does the reverse of C<pack>: it takes a string
19712L<C<pack>|/pack TEMPLATE,LIST>: it takes a string
1971311622and expands it out into a list of values.
1971411623(In scalar context, it returns merely the first value produced.)
1971511624
1971611625=end original
1971711626
19718L<C<unpack>|/unpack TEMPLATE,EXPR> L<C<pack>|/pack TEMPLATE,LIST> の逆を
11627C<unpack> は C<pack> の逆を行ないます: 構造体を表わす文字列をとり、
19719行ないます: 構造体を表わす文字列をとり、
1972011628リスト値に展開し、その配列値を返します。
1972111629(スカラコンテキストでは、単に最初の値を返します。)
1972211630
1972311631=begin original
1972411632
19725If EXPR is omitted, unpacks the L<C<$_>|perlvar/$_> string.
19726See L<perlpacktut> for an introduction to this function.
19727
19728=end original
19729
19730EXPR が省略されると、L<C<$_>|perlvar/$_> の文字列を unpack します。
19731この関数の説明については L<perlpacktut> を参照してください。
19732
19733=begin original
19734
1973511633The string is broken into chunks described by the TEMPLATE. Each chunk
1973611634is converted separately to a value. Typically, either the string is a result
19737of L<C<pack>|/pack TEMPLATE,LIST>, or the characters of the string
11635of C<pack>, or the bytes of the string represent a C structure of some
19738represent a C structure of some kind.
11636kind.
1973911637
1974011638=end original
1974111639
1974211640文字列は TEMPLATE で示された固まりに分割されます。
1974311641それぞれの固まりは別々に値に変換されます。
19744典型的には、文字列は L<C<pack>|/pack TEMPLATE,LIST> の結果あるいはある種の
11642典型的には、文字列は C<pack> の結果あるいはある種の C の構造体
19745C の構造体の文字列表現の文字列です。
11643文字列表現のバイト列です。
1974611644
1974711645=begin original
1974811646
19749The TEMPLATE has the same format as in the
11647The TEMPLATE has the same format as in the C<pack> function.
19750L<C<pack>|/pack TEMPLATE,LIST> function.
1975111648Here's a subroutine that does substring:
1975211649
1975311650=end original
1975411651
19755TEMPLATE は、L<C<pack>|/pack TEMPLATE,LIST> 関数と同じフォーマットを使います。
11652TEMPLATE は、C<pack> 関数と同じフォーマットを使います。
1975611653部分文字列を取り出すうサブルーチンの例を示します:
1975711654
1975811655 sub substr {
19759 my ($what, $where, $howmuch) = @_;
11656 my($what,$where,$howmuch) = @_;
19760 unpack("x$where a$howmuch", $what);
11657 unpack("x$where a$howmuch", $what);
1976111658 }
1976211659
1976311660=begin original
1976411661
1976511662and then there's
1976611663
1976711664=end original
1976811665
1976911666これもそうです。
1977011667
19771 sub ordinal { unpack("W",$_[0]); } # same as ord()
11668 sub ordinal { unpack("c",$_[0]); } # same as ord()
1977211669
1977311670=begin original
1977411671
19775In addition to fields allowed in L<C<pack>|/pack TEMPLATE,LIST>, you may
11672In addition to fields allowed in pack(), you may prefix a field with
19776prefix a field with a %<number> to indicate that
11673a %<number> to indicate that
1977711674you want a <number>-bit checksum of the items instead of the items
19778themselves. Default is a 16-bit checksum. The checksum is calculated by
11675themselves. Default is a 16-bit checksum. Checksum is calculated by
1977911676summing numeric values of expanded values (for string fields the sum of
19780C<ord($char)> is taken; for bit fields the sum of zeroes and ones).
11677C<ord($char)> is taken, for bit fields the sum of zeroes and ones).
1978111678
1978211679=end original
1978311680
19784L<C<pack>|/pack TEMPLATE,LIST> で利用可能なフィールドの他に、
11681pack() で利用可能なフィールドの他に、
1978511682フィールドの前に %<数値> というものを付けて、
1978611683項目自身の代わりに、その項目の <数値>-ビットのチェックサムを
1978711684計算させることができます。
1978811685デフォルトは、16-ビットチェックサムです。
1978911686チェックサムは展開された値の数値としての値の合計
19790(文字列フィールドの場合は C<ord($char)> の合計;
11687(文字列フィールドの場合は C<ord($char)> の合計
1979111688ビットフィールドの場合は 0 と 1 の合計) が用いられます。
1979211689
1979311690=begin original
1979411691
1979511692For example, the following
1979611693computes the same number as the System V sum program:
1979711694
1979811695=end original
1979911696
1980011697たとえば、以下のコードは
1980111698System V の sum プログラムと同じ値を計算します。
1980211699
19803 my $checksum = do {
11700 $checksum = do {
19804 local $/; # slurp!
11701 local $/; # slurp!
19805 unpack("%32W*", readline) % 65535;
11702 unpack("%32C*",<>) % 65535;
1980611703 };
1980711704
1980811705=begin original
1980911706
1981011707The following efficiently counts the number of set bits in a bit vector:
1981111708
1981211709=end original
1981311710
1981411711以下は、効率的にビットベクターの設定されているビットを
1981511712数えるものです。
1981611713
19817 my $setbits = unpack("%32b*", $selectmask);
11714 $setbits = unpack("%32b*", $selectmask);
1981811715
1981911716=begin original
1982011717
1982111718The C<p> and C<P> formats should be used with care. Since Perl
19822has no way of checking whether the value passed to
11719has no way of checking whether the value passed to C<unpack()>
19823L<C<unpack>|/unpack TEMPLATE,EXPR>
1982411720corresponds to a valid memory location, passing a pointer value that's
1982511721not known to be valid is likely to have disastrous consequences.
1982611722
1982711723=end original
1982811724
1982911725C<p> と C<P> は注意深く使うべきです。
19830Perl は L<C<unpack>|/unpack TEMPLATE,EXPR> に渡された値が有効なメモリ位置を
11726Perl は C<unpack()> に渡された値が有効なメモリ位置を指しているかどうか
19831指しているかどうかを確認する方法がないので、有効かどうかわからない
11727確認する方法がないので、有効かどうかわからないポインタ値を渡すと
19832ポインタ値を渡すと悲惨な結果を引き起こすかもしれません。
11728悲惨な結果を引き起こすかもしれません。
1983311729
1983411730=begin original
1983511731
19836If there are more pack codes or if the repeat count of a field or a group
11732If the repeat count of a field is larger than what the remainder of
19837is larger than what the remainder of the input string allows, the result
11733the input string allows, repeat count is decreased. If the input string
19838is not well defined: the repeat count may be decreased, or
11734is longer than one described by the TEMPLATE, the rest is ignored.
19839L<C<unpack>|/unpack TEMPLATE,EXPR> may produce empty strings or zeros,
19840or it may raise an exception.
19841If the input string is longer than one described by the TEMPLATE,
19842the remainder of that input string is ignored.
1984311735
1984411736=end original
1984511737
19846多くの pack コードがある場合や、フィールドやグループの繰り返し回数が
11738フィールドの繰り返し回数が入力文字列の残りより大きい場合、繰り返し回数は
19847入力文字列の残りより大きい場合、結果は未定義です:
11739減らされます。もし入力文字列が TEMPLATE で表現されているものより
19848繰り返し回数が減らされる場合もありますし、
11740大きい場合、残は無視されます
19849L<C<unpack>|/unpack TEMPLATE,EXPR> が空文字列や 0 を
19850返すこともありますし、例外が発生します。
19851もし入力文字列が TEMPLATE で表現されているものより大きい場合、
19852入力文字列の残りは無視されます。
1985311741
1985411742=begin original
1985511743
19856See L<C<pack>|/pack TEMPLATE,LIST> for more examples and notes.
11744See L</pack> for more examples and notes.
1985711745
1985811746=end original
1985911747
19860さらなる例と注意に関しては L<C<pack>|/pack TEMPLATE,LIST> を参照してください。
11748さらなる例と注意に関しては L</pack> を参照してください。
1986111749
19862=item unshift ARRAY,LIST
11750=item untie VARIABLE
19863X<unshift>
1986411751
19865=for Pod::Functions prepend more elements to the beginning of a list
19866
1986711752=begin original
1986811753
19869Does the opposite of a L<C<shift>|/shift ARRAY>. Or the opposite of a
11754Breaks the binding between a variable and a package. (See C<tie>.)
19870L<C<push>|/push ARRAY,LIST>,
19871depending on how you look at it. Prepends list to the front of the
19872array and returns the new number of elements in the array.
1987311755
1987411756=end original
1987511757
19876L<C<shift>|/shift ARRAY> 逆操作行ないます。
11758変数とパッケージ間の結合解きます。
19877見方を変えれば、L<C<push>|/push ARRAY,LIST> の逆操作とも考えられます
11759(L<tie> を参照してください)
19878LIST を ARRAY の先頭に入れて、新しくできた配列の要素の数を返します。
1987911760
19880 unshift(@ARGV, '-e') unless $ARGV[0] =~ /^-/;
11761=item unshift ARRAY,LIST
1988111762
1988211763=begin original
1988311764
19884Note the LIST is prepended whole, not one element at a time, so the
11765Does the opposite of a C<shift>. Or the opposite of a C<push>,
19885prepended elements stay in the same order. Use
11766depending on how you look at it. Prepends list to the front of the
19886L<C<reverse>|/reverse LIST> to do the reverse.
11767array, and returns the new number of elements in the array.
1988711768
1988811769=end original
1988911770
19890LIST は、はらばらにではなく、一度に登録されるで、順番はそのまです。
11771C<shift>逆操作を行ないます。
19891逆順に登録するにはL<C<reverse>|/reverse LIST> を使ってください
11772見方を変えれば、C<push>の逆操作とも考えられます
11773LIST を ARRAY の先頭に入れて、新しくできた配列の要素の数を返します。
1989211774
19893=begin original
11775 unshift(ARGV, '-e') unless $ARGV[0] =~ /^-/;
1989411776
19895Starting with Perl 5.14, an experimental feature allowed
19896L<C<unshift>|/unshift ARRAY,LIST> to take
19897a scalar expression. This experiment has been deemed unsuccessful, and was
19898removed as of Perl 5.24.
19899
19900=end original
19901
19902Perl 5.14 から、L<C<unshift>|/unshift ARRAY,LIST> がスカラ式を
19903取ることが出来るという実験的機能がありました。
19904この実験は失敗と見なされ、Perl 5.24 で削除されました。
19905
19906=item untie VARIABLE
19907X<untie>
19908
19909=for Pod::Functions break a tie binding to a variable
19910
1991111777=begin original
1991211778
19913Breaks the binding between a variable and a package.
11779Note the LIST is prepended whole, not one element at a time, so the
19914(See L<tie|/tie VARIABLE,CLASSNAME,LIST>.)
11780prepended elements stay in the same order. Use C<reverse> to do the
19915Has no effect if the variable is not tied.
11781reverse.
1991611782
1991711783=end original
1991811784
19919変数とパッケージ結合を解きます。
11785LIST は、はらばらにではなく、一度に登録されるで、順番はそのままです。
19920(L<tie|/tie VARIABLE,CLASSNAME,LIST> を参照してください。)
11786逆順に登録するには、C<reverse> を使ってください。
19921結合されていない場合は何も起きません。
1992211787
1992311788=item use Module VERSION LIST
19924X<use> X<module> X<import>
1992511789
1992611790=item use Module VERSION
1992711791
1992811792=item use Module LIST
1992911793
1993011794=item use Module
1993111795
1993211796=item use VERSION
1993311797
19934=for Pod::Functions load in a module at compile time and import its namespace
19935
1993611798=begin original
1993711799
1993811800Imports some semantics into the current package from the named module,
1993911801generally by aliasing certain subroutine or variable names into your
1994011802package. It is exactly equivalent to
1994111803
19942=end original
11804 BEGIN { require Module; import Module LIST; }
1994311805
19944指定したモジュールから、現在のパッケージにさまざまな内容をインポートします;
19945多くは、パッケージのサブルーチン名や、変数名に別名を付けることで、
19946実現されています。
19947これは、以下は等価ですが:
19948
19949 BEGIN { require Module; Module->import( LIST ); }
19950
19951=begin original
19952
1995311806except that Module I<must> be a bareword.
19954The importation can be made conditional by using the L<if> module.
1995511807
1995611808=end original
1995711809
19958Module が I<裸単語でければならない> こと除けば、です。
11810指定したモジュールから、現在パッケージにさまざま内容
19959インポートは、L<if> を使って条件付きで行うことができます。
11811インポートます。
11812多くは、パッケージのサブルーチン名や、変数名に別名を付けることで、
11813実現されています。これは、
11814Module が I<単なる単語でなければならない> ことを除けば、
1996011815
19961=begin original
11816 BEGIN { require Module; import Module LIST; }
1996211817
19963In the C<use VERSION> form, VERSION may be either a v-string such as
11818と等価です。
19964v5.24.1, which will be compared to L<C<$^V>|perlvar/$^V> (aka
19965$PERL_VERSION), or a numeric argument of the form 5.024001, which will
19966be compared to L<C<$]>|perlvar/$]>. An exception is raised if VERSION
19967is greater than the version of the current Perl interpreter; Perl will
19968not attempt to parse the rest of the file. Compare with
19969L<C<require>|/require VERSION>, which can do a similar check at run
19970time. Symmetrically, C<no VERSION> allows you to specify that you
19971want a version of Perl older than the specified one.
1997211819
19973=end original
19974
19975C<use VERSION> の形式では、VERSION は v5.24.1 のような v-文字列
19976(L<C<$^V>|perlvar/$^V> (またの名を $PERL_VERSION) と比較されます)
19977か、5.024001 の形の数値形式 (L<C<$]>|perlvar/$]> と比較されます) で
19978指定します。
19979VERSION が Perl の現在のバージョンより大きいと、例外が発生します;
19980Perl はファイルの残りを読み込みません。
19981L<C<require>|/require VERSION> と似ていますが、これは実行時に
19982チェックされます。
19983対称的に、C<no VERSION> は指定されたバージョンより古いバージョンの Perl で
19984動作させたいことを意味します。
19985
1998611820=begin original
1998711821
19988Specifying VERSION as a numeric argument of the form 5.024001 should
11822VERSION, which can be specified as a literal of the form v5.6.1, demands
19989generally be avoided as older less readable syntax compared to
11823that the current version of Perl (C<$^V> or $PERL_VERSION) be at least
19990v5.24.1. Before perl 5.8.0 released in 2002 the more verbose numeric
11824as recent as that version. (For compatibility with older versions of Perl,
19991form was the only supported syntax, which is why you might see it in
11825a numeric literal will also be interpreted as VERSION.) If the version
11826of the running Perl interpreter is less than VERSION, then an error
11827message is printed and Perl exits immediately without attempting to
11828parse the rest of the file. Compare with L</require>, which can do a
11829similar check at run time.
1999211830
1999311831=end original
1999411832
19995VERSION 5.024001 の形の数値引数を指定するは一般的には避けるべきです;
11833VERSION (v5.6.1 の形のリテラルとしても指定できます)を指定すると
19996v5.24.1 に比べてより古読みにくい文法だからです。
11834現在の Perl のバージョン (C<$^V> or $PERL_VERSION) が少なとも
19997(2002 年にリリースされた) perl 5.8.0 よりは、より冗長な
11835指定されたものよりも最近あることを要求します。
19998数値形式が唯一対応している文法でした; これが古いドでこれを
11836(古いジョンの Perl との互換性のために、数値リテラルも
19999見るかも知ない理由です。
11837VERSIONとして解釈さす。)
11838もし動作している Perl インタプリタのバージョンが VERSION より低い場合、
11839エラーメッセージが表示され、Perl はファイルの残りをパースせずに
11840直ちに終了します。
11841似たようなチェックを実行時に行える L</require> と比較してください。
2000011842
20001=begin original
11843 use v5.6.1; # compile time version check
11844 use 5.6.1; # ditto
11845 use 5.005_03; # float version allowed for compatibility
2000211846
20003 use v5.24.1; # compile time version check
20004 use 5.24.1; # ditto
20005 use 5.024_001; # ditto; older syntax compatible with perl 5.6
20006
20007=end original
20008
20009 use v5.24.1; # 実行時バージョンチェック
20010 use 5.24.1; # 同様
20011 use 5.024_001; # 同様; perl 5.6 と互換性のある古い文法
20012
2001311847=begin original
2001411848
2001511849This is often useful if you need to check the current Perl version before
20016L<C<use>|/use Module VERSION LIST>ing library modules that won't work
11850C<use>ing library modules that have changed in incompatible ways from
20017with older versions of Perl.
11851older versions of Perl. (We try not to do this more than we have to.)
20018(We try not to do this more than we have to.)
2001911852
2002011853=end original
2002111854
20022これは古いバージョンの Perl で動かなくなったライブラリモジュールを
11855これは古いバージョンの Perl から互換性のい形で変更されたライブラリ
20023L<C<use>|/use Module VERSION LIST> する前、現在 Perl のバージョンを
11856モジュール(我々は必要な場合以外ようなことがないように
11857努力していますが)を C<use> する前に、現在の Perl のバージョンを
2002411858調べたい場合に有用です。
20025(我々は必要な場合以外にそのようなことがないように努力していますが。)
2002611859
2002711860=begin original
2002811861
20029C<use VERSION> also lexically enables all features available in the requested
11862The C<BEGIN> forces the C<require> and C<import> to happen at compile time. The
20030version as defined by the L<feature> pragma, disabling any features
11863C<require> makes sure the module is loaded into memory if it hasn't been
20031not in the requested version's feature bundle. See L<feature>.
11864yet. The C<import> is not a builtin--it's just an ordinary static method
20032Similarly, if the specified Perl version is greater than or equal to
200335.12.0, strictures are enabled lexically as
20034with L<C<use strict>|strict>. Any explicit use of
20035C<use strict> or C<no strict> overrides C<use VERSION>, even if it comes
20036before it. Later use of C<use VERSION>
20037will override all behavior of a previous
20038C<use VERSION>, possibly removing the C<strict> and C<feature> added by
20039C<use VERSION>. C<use VERSION> does not
20040load the F<feature.pm> or F<strict.pm>
20041files.
20042
20043=end original
20044
20045C<use VERSION> は、L<feature> プラグマで定義されたように、指定された
20046バージョンで利用可能な全ての機能を有効にし、指定されたバージョンの機能の
20047束にない機能をレキシカルに無効にします。
20048L<feature> を参照してください。
20049同様に、指定された Perl のバージョンが 5.12.0 以上の場合、
20050制限は L<C<use strict>|strict> と同様にレキシカルに有効になります。
20051明示的に C<use strict> や C<no strict> を使うと、例え先に
20052指定されていたとしても、C<use VERSION> を上書きします。
20053後から使った C<use VERSION> は先の
20054C<use VERSION> の全ての振る舞いを上書きするので、
20055C<use VERSION> によって追加された C<strict> と C<feature> を
20056削除することがあります。
20057C<use VERSION> は F<feature.pm> と F<strict.pm> ファイルは読み込みません。
20058
20059=begin original
20060
20061The C<BEGIN> forces the L<C<require>|/require VERSION> and
20062L<C<import>|/import LIST> to happen at compile time. The
20063L<C<require>|/require VERSION> makes sure the module is loaded into
20064memory if it hasn't been yet. The L<C<import>|/import LIST> is not a
20065builtin; it's just an ordinary static method
2006611865call into the C<Module> package to tell the module to import the list of
2006711866features back into the current package. The module can implement its
20068L<C<import>|/import LIST> method any way it likes, though most modules
11867C<import> method any way it likes, though most modules just choose to
20069just choose to derive their L<C<import>|/import LIST> method via
11868derive their C<import> method via inheritance from the C<Exporter> class that
20070inheritance from the C<Exporter> class that is defined in the
11869is defined in the C<Exporter> module. See L<Exporter>. If no C<import>
20071L<C<Exporter>|Exporter> module. See L<Exporter>. If no
11870method can be found then the call is skipped.
20072L<C<import>|/import LIST> method can be found, then the call is skipped,
20073even if there is an AUTOLOAD method.
2007411871
2007511872=end original
2007611873
20077C<BEGIN> によって、L<C<require>|/require VERSION>
11874C<BEGIN> によって、C<require> や C<import> は、コンパイル時に
20078L<C<import>|/import LIST> は、コンパイル時に
2007911875実行されることになります。
20080L<C<require>|/require VERSION> は、モジュールがまだメモリに
11876C<require> は、モジュールがまだメモリにロードされていなければ、ロードします。
20081ロードされていければロードしす。
11877C<import> は、組込みの関数ではざまな機能を現在のパッケージに
20082L<C<import>|/import LIST> は組込みの関数ではありません; さまざまな機能を
11878インポートするように C<Module> パッケージに伝えるために呼ばれる
20083現在ケージにインポートるように C<Module> パッケージに伝えるために
11879通常静的メソドで
20084呼ばれる通常の静的メソッドです
11880モジュール側ではC<import> メソッドをどのようにも実装ることが
20085モジュールでは、L<C<import>|/import LIST> メソッドをどのように
11881できますが、多くのモジュールでは、C<Exporter> モジュール定義された、
20086実装することができますが、多くモジュールでは
11882C<Exporter> クラスから継承によってC<import> メソッドを行なうように
20087L<C<Exporter>|Exporter> モジュールで定義された、
11883しています。
20088C<Exporter> クラスからの継承によって、L<C<import>|/import LIST> メソッドを
20089行なうようにしています。
2009011884L<Exporter>モジュールを参照してください。
20091L<C<import>|/import LIST>メソッドが見つからなかった場合、AUTOLOAD メソドが
11885C<import>メソッドが見つからなかった場合、呼び出しはスキプされます。
20092あったとしても呼び出しはスキップされます。
2009311886
2009411887=begin original
2009511888
20096If you do not want to call the package's L<C<import>|/import LIST>
11889If you do not want to call the package's C<import> method (for instance,
20097method (for instance,
2009811890to stop your namespace from being altered), explicitly supply the empty list:
2009911891
2010011892=end original
2010111893
20102パッケージの L<C<import>|/import LIST> メソッドを呼び出したくない場合(例えば、
11894パッケージの C<import> メソッドを呼び出したくない場合(例えば、名前空間を
20103名前空間を変更したくない場合など)は、明示的に空リストを指定してください:
11895変更したくない場合など)は、明示的に空リストを指定してください:
2010411896
2010511897 use Module ();
2010611898
2010711899=begin original
2010811900
2010911901That is exactly equivalent to
2011011902
2011111903=end original
2011211904
2011311905これは以下と完全に等価です:
2011411906
2011511907 BEGIN { require Module }
2011611908
2011711909=begin original
2011811910
2011911911If the VERSION argument is present between Module and LIST, then the
20120L<C<use>|/use Module VERSION LIST> will call the C<VERSION> method in
11912C<use> will call the VERSION method in class Module with the given
20121class Module with the given version as an argument:
11913version as an argument. The default VERSION method, inherited from
11914the UNIVERSAL class, croaks if the given version is larger than the
11915value of the variable C<$Module::VERSION>.
2012211916
2012311917=end original
2012411918
20125Module と LIST の間に VERSION 引数がある場合、
11919Module と LIST の間に VERSION 引数がある場合、C<use> は Module クラスの
20126L<C<use>|/use Module VERSION LIST> は Module クラスの
11920VERSION メソッドを、与えられたバージョンを引数として呼び出します。
20127C<VERSION> メソッド与えれたバージョンを引数とて呼び出します:
11921デフォルトの VERSION メソッド UNIVERSAL クラスか継承たもので、
20128
20129 use Module 12.34;
20130
20131=begin original
20132
20133is equivalent to:
20134
20135=end original
20136
20137は以下と等価です:
20138
20139 BEGIN { require Module; Module->VERSION(12.34) }
20140
20141=begin original
20142
20143The L<default C<VERSION> method|UNIVERSAL/C<VERSION ( [ REQUIRE ] )>>,
20144inherited from the L<C<UNIVERSAL>|UNIVERSAL> class, croaks if the given
20145version is larger than the value of the variable C<$Module::VERSION>.
20146
20147=end original
20148
20149デフォルトの
20150L<default C<VERSION> メソッド|UNIVERSAL/C<VERSION ( [ REQUIRE ] )>> は、
20151L<C<UNIVERSAL>|UNIVERSAL> クラスから継承したもので、
2015211922与えられたバージョンが 変数 C<$Module::VERSION> の値より大きい場合に
2015311923警告を出します。
2015411924
2015511925=begin original
2015611926
20157The VERSION argument cannot be an arbitrary expression. It only counts
11927Again, there is a distinction between omitting LIST (C<import> called
20158as a VERSION argument if it is a version number literal, starting with
11928with no arguments) and an explicit empty LIST C<()> (C<import> not
20159either a digit or C<v> followed by a digit. Anything that doesn't
11929called). Note that there is no comma after VERSION!
20160look like a version literal will be parsed as the start of the LIST.
20161Nevertheless, many attempts to use an arbitrary expression as a VERSION
20162argument will appear to work, because L<Exporter>'s C<import> method
20163handles numeric arguments specially, performing version checks rather
20164than treating them as things to export.
2016511930
2016611931=end original
2016711932
20168VERSION 引数は任意の式はありません。
11933繰り返すと、LIST を省略する(C<import> が引数なし呼び出される)ことと
20169VERSION 引数が数値または C<v> に引き続て数値であるバージョン番号リテラルの
11934明示的に空の LIST C<()> を指定する (C<import> は呼び出されな)ことは
20170場合にのみ扱われます。
11935違います。
20171バージョンリテラルのように見えないものは LIST の開始としてパースされます。
20172それにも関わらず、VERSION 引数として任意の式を使おうとする
20173多くの試みは動作しているように見えます; なぜなら
20174L<Exporter> の C<import> メソッドは数値引数を特別に扱い、
20175それらをエクスポートするべきものと扱わずにバージョンチェックを
20176実行するからです。
20177
20178=begin original
20179
20180Again, there is a distinction between omitting LIST (L<C<import>|/import
20181LIST> called with no arguments) and an explicit empty LIST C<()>
20182(L<C<import>|/import LIST> not called). Note that there is no comma
20183after VERSION!
20184
20185=end original
20186
20187繰り返すと、LIST を省略する(L<C<import>|/import LIST> が引数なしで
20188呼び出される)ことと明示的に空の LIST C<()> を指定する
20189(L<C<import>|/import LIST> は呼び出されない)ことは違います。
2019011936VERSION の後ろにカンマが不要なことに注意してください!
2019111937
2019211938=begin original
2019311939
2019411940Because this is a wide-open interface, pragmas (compiler directives)
20195are also implemented this way. Some of the currently implemented
11941are also implemented this way. Currently implemented pragmas are:
20196pragmas are:
2019711942
2019811943=end original
2019911944
2020011945これは、広く公開されているインタフェースですので、
2020111946プラグマ (コンパイラディレクティブ) も、この方法で実装されています。
20202現在実装されているプラグマには、以下のようなものがあります:
11947現在実装されているプラグマには、以下のものがあります:
2020311948
2020411949 use constant;
2020511950 use diagnostics;
2020611951 use integer;
2020711952 use sigtrap qw(SEGV BUS);
2020811953 use strict qw(subs vars refs);
2020911954 use subs qw(afunc blurfl);
2021011955 use warnings qw(all);
20211 use sort qw(stable);
2021211956
2021311957=begin original
2021411958
2021511959Some of these pseudo-modules import semantics into the current
20216block scope (like L<C<strict>|strict> or L<C<integer>|integer>, unlike
11960block scope (like C<strict> or C<integer>, unlike ordinary modules,
20217ordinary modules, which import symbols into the current package (which
11961which import symbols into the current package (which are effective
20218are effective through the end of the file).
11962through the end of the file).
2021911963
2022011964=end original
2022111965
2022211966通常のモジュールが、現在のパッケージにシンボルをインポートする
20223(これは、ファイルの終わりまで有効です) のに対して、これらの擬似モジュールの
11967(これは、ファイルの終わりまで有効です) のに対して、
20224一部(L<C<strict>|strict>L<C<integer>|integer> など)は、現在の
11968これらの擬似モジュールの一部(C<strict> や C<integer> など)は、
20225ブロックスコープにインポートを行ないます。
11969現在のブロックスコープにインポートを行ないます。
2022611970
2022711971=begin original
2022811972
20229Because L<C<use>|/use Module VERSION LIST> takes effect at compile time,
11973There's a corresponding C<no> command that unimports meanings imported
20230it doesn't respect the ordinary flow control of the code being compiled.
11974by C<use>, i.e., it calls C<unimport Module LIST> instead of C<import>.
20231In particular, putting a L<C<use>|/use Module VERSION LIST> inside the
20232false branch of a conditional doesn't prevent it
20233from being processed. If a module or pragma only needs to be loaded
20234conditionally, this can be done using the L<if> pragma:
2023511975
2023611976=end original
2023711977
20238L<C<use>|/use Module VERSION LIST> はコンパイル時有効なコードが
11978これに対して、C<no> コマンドという、C<use> によってインポートされたも
20239コンパされる通常の流れ制御には従いせん
11979ンポートされていないことにすがあり
20240特に条件文うち成立しない側の中L<C<use>|/use Module VERSION LIST> を
11980つまりC<import> 代わりに C<unimport Module LIST> を呼び出します。
20241書いても、処理を妨げられません。
20242モジュールやプラグマを条件付きでのみ読み込みたい場合、
20243L<if> プラグマを使って実現できます:
2024411981
20245 use if $] < 5.008, "utf8";
20246 use if WANT_WARNINGS, warnings => qw(all);
20247
20248=begin original
20249
20250There's a corresponding L<C<no>|/no MODULE VERSION LIST> declaration
20251that unimports meanings imported by L<C<use>|/use Module VERSION LIST>,
20252i.e., it calls C<< Module->unimport(LIST) >> instead of
20253L<C<import>|/import LIST>. It behaves just as L<C<import>|/import LIST>
20254does with VERSION, an omitted or empty LIST,
20255or no unimport method being found.
20256
20257=end original
20258
20259これに対して、L<C<no>|/no MODULE VERSION LIST> 宣言という、
20260L<C<use>|/use Module VERSION LIST> によってインポートされたものを、
20261インポートされていないことにするものがあります; つまり、
20262L<C<import>|/import LIST> の代わりに
20263C<< Module->unimport(LIST) >> を呼び出します。
20264これは VERSION、省略された LIST、空の LIST、unimport メソッドが見つからない
20265場合などの観点では、L<C<import>|/import LIST> と同様に振る舞います。
20266
2026711982 no integer;
2026811983 no strict 'refs';
2026911984 no warnings;
2027011985
2027111986=begin original
2027211987
20273Care should be taken when using the C<no VERSION> form of L<C<no>|/no
11988If no C<unimport> method can be found the call fails with a fatal error.
20274MODULE VERSION LIST>. It is
20275I<only> meant to be used to assert that the running Perl is of a earlier
20276version than its argument and I<not> to undo the feature-enabling side effects
20277of C<use VERSION>.
2027811989
2027911990=end original
2028011991
20281L<C<no>|/no MODULE VERSION LIST> の C<no VERSION> 形式を使うときに
11992C<unimport> メソッドが見つからなかった場合、呼び出し致命的エラーで
20282注意を払うべきです。
11993失敗します。
20283これは引数で指定されたバージョンよりも前の Perl で実行されたときに
20284アサートされることを意味する I<だけ> で、C<use VERSION> によって
20285有効にされた副作用をなかったことにするもの I<ではありません>。
2028611994
2028711995=begin original
2028811996
2028911997See L<perlmodlib> for a list of standard modules and pragmas. See L<perlrun>
20290for the C<-M> and C<-m> command-line options to Perl that give
11998for the C<-M> and C<-m> command-line options to perl that give C<use>
20291L<C<use>|/use Module VERSION LIST> functionality from the command-line.
11999functionality from the command-line.
2029212000
2029312001=end original
2029412002
2029512003標準モジュールやプラグマの一覧は、L<perlmodlib> を参照してください。
20296コマンドラインから L<C<use>|/use Module VERSION LIST> 機能を
12004コマンドラインから C<use> 機能を指定するための C<-M> C<-m>
20297指定するための C<-M> と C<-m> の
12005コマンドラインオプションについては L<perlrun> を参照して下さい。
20298コマンドラインオプションについては L<perlrun> を参照してください。
2029912006
2030012007=item utime LIST
20301X<utime>
2030212008
20303=for Pod::Functions set a file's last access and modify times
20304
2030512009=begin original
2030612010
2030712011Changes the access and modification times on each file of a list of
20308files. The first two elements of the list must be the NUMERIC access
12012files. The first two elements of the list must be the NUMERICAL access
2030912013and modification times, in that order. Returns the number of files
2031012014successfully changed. The inode change time of each file is set
20311to the current time. For example, this code has the same effect as the
12015to the current time. This code has the same effect as the C<touch>
20312Unix L<touch(1)> command when the files I<already exist> and belong to
12016command if the files already exist:
20313the user running the program:
2031412017
2031512018=end original
2031612019
2031712020ファイルのアクセス時刻と修正(modification) 時刻を変更します。
20318LIST の最初のつの要素に、数値で表わしたアクセス時刻と修正時刻を
12021LIST の最初の 2 つの要素に、数値で表わしたアクセス時刻と修正時刻を
2031912022順に指定します。
12023LIST の残りの要素が、変更の対象となるファイルです。
2032012024変更に成功したファイルの数を返します。
2032112025各ファイルの inode 変更(change)時刻には、その時点の時刻が設定されます。
20322例えば、このコードはファイルが I<既に存在して> いて、ユーザーが
12026C<touch> コマンドの例です:
20323実行しているプログラムに従っているなら、
20324Unix の L<touch(1)> コマンドと同じ効果があります。
2032512027
2032612028 #!/usr/bin/perl
20327 my $atime = my $mtime = time;
12029 $now = time;
20328 utime $atime, $mtime, @ARGV;
12030 utime $now, $now, @ARGV;
2032912031
20330=begin original
20331
20332Since Perl 5.8.0, if the first two elements of the list are
20333L<C<undef>|/undef EXPR>,
20334the L<utime(2)> syscall from your C library is called with a null second
20335argument. On most systems, this will set the file's access and
20336modification times to the current time (i.e., equivalent to the example
20337above) and will work even on files you don't own provided you have write
20338permission:
20339
20340=end original
20341
20342Perl 5.8.0 から、リストの最初の二つの要素が L<C<undef>|/undef EXPR> である
20343場合、C ライブラリの L<utime(2)> システムコールを、秒の引数を null として
20344呼び出します。
20345ほとんどのシステムでは、これによってファイルのアクセス時刻と修正時刻を
20346現在の時刻にセットし(つまり、上記の例と等価です)、
20347書き込み権限があれば他のユーザーのファイルに対しても動作します。
20348
20349 for my $file (@ARGV) {
20350 utime(undef, undef, $file)
20351 || warn "Couldn't touch $file: $!";
20352 }
20353
20354=begin original
20355
20356Under NFS this will use the time of the NFS server, not the time of
20357the local machine. If there is a time synchronization problem, the
20358NFS server and local machine will have different times. The Unix
20359L<touch(1)> command will in fact normally use this form instead of the
20360one shown in the first example.
20361
20362=end original
20363
20364NFS では、これはローカルマシンの時刻ではなく、NFS サーバーの時刻が
20365使われます。
20366時刻同期に問題がある場合、NFS サーバーとローカルマシンで違う時刻に
20367なっている場合があります。
20368実際のところ、Unix の L<touch(1)> コマンドは普通、最初の例ではなく、
20369この形を使います。
20370
20371=begin original
20372
20373Passing only one of the first two elements as L<C<undef>|/undef EXPR> is
20374equivalent to passing a 0 and will not have the effect described when
20375both are L<C<undef>|/undef EXPR>. This also triggers an
20376uninitialized warning.
20377
20378=end original
20379
20380最初の二つの要素のうち、一つだけに L<C<undef>|/undef EXPR> を渡すと、その
20381要素は 0 を渡すのと等価となり、上述の、両方に L<C<undef>|/undef EXPR> を
20382渡した時と同じ効果ではありません。
20383この場合は、未初期化の警告が出ます。
20384
20385=begin original
20386
20387On systems that support L<futimes(2)>, you may pass filehandles among the
20388files. On systems that don't support L<futimes(2)>, passing filehandles raises
20389an exception. Filehandles must be passed as globs or glob references to be
20390recognized; barewords are considered filenames.
20391
20392=end original
20393
20394L<futimes(2)> に対応しているシステムでは、ファイルハンドルを引数として
20395渡せます。
20396L<futimes(2)> に対応していないシステムでは、ファイルハンドルを渡すと
20397例外が発生します。
20398ファイルハンドルを認識させるためには、グロブまたはリファレンスとして
20399渡されなければなりません; 裸の単語はファイル名として扱われます。
20400
20401=begin original
20402
20403Portability issues: L<perlport/utime>.
20404
20405=end original
20406
20407移植性の問題: L<perlport/utime>。
20408
2040912032=item values HASH
20410X<values>
2041112033
20412=item values ARRAY
20413
20414=for Pod::Functions return a list of the values in a hash
20415
2041612034=begin original
2041712035
20418In list context, returns a list consisting of all the values of the named
12036Returns a list consisting of all the values of the named hash. (In a
20419hash. In Perl 5.12 or later only, will also return a list of the values of
12037scalar context, returns the number of values.) The values are
20420an array; prior to that release, attempting to use an array argument will
12038returned in an apparently random order. The actual random order is
20421produce a syntax error. In scalar context, returns the number of values.
12039subject to change in future versions of perl, but it is guaranteed to
12040be the same order as either the C<keys> or C<each> function would
12041produce on the same (unmodified) hash.
2042212042
2042312043=end original
2042412044
20425リストコンテキストでは、指定したハッシュのすべてのを返します。
12045指定したハッシュのすべての value からなるリストを返します。
20426Perl 5.12 以降でみ、配列の全ての値からなるリストも返します;
12046(スカラコンテキストでは、value数を返します。)
20427リリースの前では、配列要素使おうとすると文法エラーが発生します。
12047返される value 順序は、見た目ばらばらなものです。
20428スカテキストで、値数を返します。
12048実際のランダムな順序将来バージョンの perl では変わる可能性が
12049ありますが、同じ(変更されていない)ハッシュに対して、
12050C<keys>関数や C<each>関数が返すものと同じ順序であることは保証されます。
2042912051
2043012052=begin original
2043112053
20432Hash entries are returned in an apparently random order. The actual random
20433order is specific to a given hash; the exact same series of operations
20434on two hashes may result in a different order for each hash. Any insertion
20435into the hash may change the order, as will any deletion, with the exception
20436that the most recent key returned by L<C<each>|/each HASH> or
20437L<C<keys>|/keys HASH> may be deleted without changing the order. So
20438long as a given hash is unmodified you may rely on
20439L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and
20440L<C<each>|/each HASH> to repeatedly return the same order
20441as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
20442details on why hash order is randomized. Aside from the guarantees
20443provided here the exact details of Perl's hash algorithm and the hash
20444traversal order are subject to change in any release of Perl. Tied hashes
20445may behave differently to Perl's hashes with respect to changes in order on
20446insertion and deletion of items.
20447
20448=end original
20449
20450ハッシュ要素は見かけ上、ランダムな順序で返されます。
20451実際のランダムな順序はハッシュに固有です; 二つのハッシュに全く同じ一連の
20452操作を行っても、ハッシュによって異なった順序になります。
20453ハッシュへの挿入によって順序が変わることがあります; 削除も同様ですが、
20454L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも
20455最近のキーは順序を変えることなく削除できます。
20456ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>,
20457L<C<each>|/each HASH> が繰り返し同じ順序で返すことに依存してもかまいません。
20458なぜハッシュの順序がランダム化されているかの詳細については
20459L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。
20460ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の
20461正確な詳細は Perl のリリースによって変更される可能性があります。
20462tie されたハッシュは、アイテムの挿入と削除の順序に関して Perl のハッシュと
20463異なった振る舞いをします。
20464
20465=begin original
20466
20467As a side effect, calling L<C<values>|/values HASH> resets the HASH or
20468ARRAY's internal iterator (see L<C<each>|/each HASH>) before yielding the
20469values. In particular,
20470calling L<C<values>|/values HASH> in void context resets the iterator
20471with no other overhead.
20472
20473=end original
20474
20475副作用として、L<C<values>|/values HASH> を呼び出すと、
20476値を取り出す前に HASH や ARRAY の
20477内部反復子(L<C<each>|/each HASH> 参照)をリセットします。
20478特に、L<C<values>|/values HASH> を無効コンテキストで呼び出すとその他の
20479オーバーヘッドなしで反復子をリセットします。
20480
20481=begin original
20482
20483Apart from resetting the iterator,
20484C<values @array> in list context is the same as plain C<@array>.
20485(We recommend that you use void context C<keys @array> for this, but
20486reasoned that taking C<values @array> out would require more
20487documentation than leaving it in.)
20488
20489=end original
20490
20491反復子をリセットするということを除けば、
20492リストコンテキストでの C<values @array> は単なる C<@array> と同じです。
20493この目的のためには無効コンテキストで C<keys @array> を使うことを
20494お勧めしますが、C<values @array> を取り出すにはそのままにするよりも
20495より多くの文書が必要だと判断しました。)
20496
20497=begin original
20498
2049912054Note that the values are not copied, which means modifying them will
2050012055modify the contents of the hash:
2050112056
2050212057=end original
2050312058
2050412059値はコピーされないので、返されたリストを変更すると
2050512060ハッシュの中身が変更されることに注意してください。
2050612061
20507 for (values %hash) { s/foo/bar/g } # modifies %hash values
12062 for (values %hash) { s/foo/bar/g } # modifies %hash values
20508 for (@hash{keys %hash}) { s/foo/bar/g } # same
12063 for (@hash{keys %hash}) { s/foo/bar/g } # same
2050912064
2051012065=begin original
2051112066
20512Starting with Perl 5.14, an experimental feature allowed
12067As a side effect, calling values() resets the HASH's internal iterator.
20513L<C<values>|/values HASH> to take a
12068See also C<keys>, C<each>, and C<sort>.
20514scalar expression. This experiment has been deemed unsuccessful, and was
20515removed as of Perl 5.24.
2051612069
2051712070=end original
2051812071
20519Perl 5.14 からL<C<values>|/values HASH> がスカラ式取ることが出来るという
12072副作用として、values() を呼び出すと HASH の内部イテレータリセットします。
20520実験的機能がありま
12073C<keys>, C<each>, C<sort> も参照てください
20521この実験は失敗と見なされ、Perl 5.24 で削除されました。
2052212074
20523=begin original
20524
20525To avoid confusing would-be users of your code who are running earlier
20526versions of Perl with mysterious syntax errors, put this sort of thing at
20527the top of your file to signal that your code will work I<only> on Perls of
20528a recent vintage:
20529
20530=end original
20531
20532あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
20533文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
20534I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
20535書いてください:
20536
20537 use 5.012; # so keys/values/each work on arrays
20538
20539=begin original
20540
20541See also L<C<keys>|/keys HASH>, L<C<each>|/each HASH>, and
20542L<C<sort>|/sort SUBNAME LIST>.
20543
20544=end original
20545
20546L<C<keys>|/keys HASH>, L<C<each>|/each HASH>, L<C<sort>|/sort SUBNAME LIST> も
20547参照してください。
20548
2054912075=item vec EXPR,OFFSET,BITS
20550X<vec> X<bit> X<bit vector>
2055112076
20552=for Pod::Functions test or set particular bits in a string
20553
2055412077=begin original
2055512078
2055612079Treats the string in EXPR as a bit vector made up of elements of
20557width BITS and returns the value of the element specified by OFFSET
12080width BITS, and returns the value of the element specified by OFFSET
2055812081as an unsigned integer. BITS therefore specifies the number of bits
2055912082that are reserved for each element in the bit vector. This must
2056012083be a power of two from 1 to 32 (or 64, if your platform supports
2056112084that).
2056212085
2056312086=end original
2056412087
2056512088文字列 EXPR を BITS 幅の要素からなるビットベクターとして扱い、
12089OFFSET で指定される要素の値を返します。
2056612090OFFSET で指定された要素を符号なし整数として返します。
2056712091従って、 BITS はビットベクターの中の各要素について予約されるビット数です。
2056812092BIT は、1 から 32 まで(プラットホームが
2056912093対応していれば 64 まで) の 2 のべき乗でなければなりません。
2057012094
2057112095=begin original
2057212096
20573If BITS is 8, "elements" coincide with bytes of the input string.
12097If BITS is 8, "elements" coincide with bytes of the input string.
2057412098
2057512099=end original
2057612100
2057712101BITS が 8 の場合、「要素」は入力文字列の各バイトと一致します。
2057812102
2057912103=begin original
2058012104
2058112105If BITS is 16 or more, bytes of the input string are grouped into chunks
2058212106of size BITS/8, and each group is converted to a number as with
20583L<C<pack>|/pack TEMPLATE,LIST>/L<C<unpack>|/unpack TEMPLATE,EXPR> with
12107pack()/unpack() with big-endian formats C<n>/C<N> (and analogously
20584big-endian formats C<n>/C<N> (and analogously for BITS==64). See
12108for BITS==64). See L<"pack"> for details.
20585L<C<pack>|/pack TEMPLATE,LIST> for details.
2058612109
2058712110=end original
2058812111
2058912112BITS が 16 以上の場合、入力のバイト列は BITS/8 のサイズの固まりに
20590グループ化され、各グループは L<C<pack>|/pack TEMPLATE,LIST>/
12113グループ化され、各グループは pack()/unpack() のビッグエンディアン
20591L<C<unpack>|/unpack TEMPLATE,EXPR> のビッグエンディアン
2059212114フォーマット C<n>/C<N> を用いて(BITS==64 の類似として)数値に変換されます。
20593詳細は L<C<pack>|/pack TEMPLATE,LIST> を参照してください。
12115詳細は L<"pack"> を参照してください。
2059412116
2059512117=begin original
2059612118
2059712119If bits is 4 or less, the string is broken into bytes, then the bits
2059812120of each byte are broken into 8/BITS groups. Bits of a byte are
2059912121numbered in a little-endian-ish way, as in C<0x01>, C<0x02>,
2060012122C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80>. For example,
2060112123breaking the single input byte C<chr(0x36)> into two groups gives a list
2060212124C<(0x6, 0x3)>; breaking it into 4 groups gives C<(0x2, 0x1, 0x3, 0x0)>.
2060312125
2060412126=end original
2060512127
2060612128BITS が 4 以下の場合、文字列はバイトに分解され、バイトの各ビットは
20607121298/BITS 個のグループに分割されます。
2060812130ビットはリトルエンディアン風に、C<0x01>, C<0x02>,
2060912131C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80> の順になります。
20610例えば、入力バイト C<chr(0x36)> をつのグループに分割すると、
12132例えば、入力バイト C<chr(0x36)> を 2 つのグループに分割すると、
20611C<(0x6, 0x3)> になります; 4 つに分割すると C<(0x2, 0x1, 0x3, 0x0)> に
12133C<(0x6, 0x3)> になります
20612なります。
121344 つに分割すると C<(0x2, 0x1, 0x3, 0x0)> になります。
2061312135
2061412136=begin original
2061512137
20616L<C<vec>|/vec EXPR,OFFSET,BITS> may also be assigned to, in which case
12138C<vec> may also be assigned to, in which case parentheses are needed
20617parentheses are needed
2061812139to give the expression the correct precedence as in
2061912140
2062012141=end original
2062112142
20622L<C<vec>|/vec EXPR,OFFSET,BITS> は左辺値として、代入の
12143左辺値として、代入の対象にすることもできます。
20623対象にするともできます; この場合、式を正しく
12144この場合、式を正しく先行させるために以下のように括弧が必要です。
20624先行させるために以下のように括弧が必要です:
2062512145
2062612146 vec($image, $max_x * $x + $y, 8) = 3;
2062712147
2062812148=begin original
2062912149
2063012150If the selected element is outside the string, the value 0 is returned.
2063112151If an element off the end of the string is written to, Perl will first
2063212152extend the string with sufficiently many zero bytes. It is an error
20633to try to write off the beginning of the string (i.e., negative OFFSET).
12153to try to write off the beginning of the string (i.e. negative OFFSET).
2063412154
2063512155=end original
2063612156
2063712157選択された要素が文字列の外側だった場合、値 0 が返されます。
2063812158文字列の最後よりも後ろの要素に書き込もうとした場合、
2063912159Perl はまず文字列を必要な分だけ 0 のバイトで拡張します。
2064012160文字列の先頭より前に書き込もうとした(つまり OFFSET が負の数だった)
2064112161場合はエラーとなります。
2064212162
2064312163=begin original
2064412164
20645If the string happens to be encoded as UTF-8 internally (and thus has
12165The string should not contain any character with the value > 255 (which
20646the UTF8 flag set), L<C<vec>|/vec EXPR,OFFSET,BITS> tries to convert it
12166can only happen if you're using UTF8 encoding). If it does, it will be
20647to use a one-byte-per-character internal representation. However, if the
12167treated as something which is not UTF8 encoded. When the C<vec> was
20648string contains characters with values of 256 or higher, that conversion
12168assigned to, other parts of your program will also no longer consider the
20649will fail, and a deprecation message will be raised. In that situation,
12169string to be UTF8 encoded. In other words, if you do have such characters
20650C<vec> will operate on the underlying buffer regardless, in its internal
12170in your string, vec() will operate on the actual byte string, and not the
20651UTF-8 representation. In Perl 5.32, this will be a fatal error.
12171conceptual character string.
2065212172
2065312173=end original
2065412174
20655文字列がたまたま内部で UTF-8 でエンコードされてい場合(したがって
12175文字列は値255 を越え文字を含むべきではありません
20656UTF8 フラがセットされている場合)
12176(これは UTF8 エンコーディンを使っているときにだけ起こりえます)
20657L<C<vec>|/vec EXPR,OFFSET,BITS> はこを単一バイト文字内部表現に
12177もし含んでいると、UTF8 エンコードさていないものとして扱われます。
20658変換しようします。
12178C<vec> が割り当てられたき、プログラムのその他の部分では
20659しかし、この文字列に値256 以上の文字が含まている場合、
12179もはやこの文字列が UTF8 エンコードさたと扱われなくなります。
20660は失敗し廃止予定メッセージが発生ます。
12180言いえるとこのような文字を文字列に含んでいると、
20661この場合、C<vec>内部 UTF-8 表現を気にせず
12181vec()実際バイト文字列として扱い概念的な文字の文字列としては
20662基となってるバッファに対して操作し
12182いません
20663Perl 5.32 で、これは致命的エラーになります。
2066412183
2066512184=begin original
2066612185
20667Strings created with L<C<vec>|/vec EXPR,OFFSET,BITS> can also be
12186Strings created with C<vec> can also be manipulated with the logical
20668manipulated with the logical
2066912187operators C<|>, C<&>, C<^>, and C<~>. These operators will assume a bit
2067012188vector operation is desired when both operands are strings.
2067112189See L<perlop/"Bitwise String Operators">.
2067212190
2067312191=end original
2067412192
20675L<C<vec>|/vec EXPR,OFFSET,BITS> で作られた文字列は、論理演算子 C<|>、C<&>、
12193vec() で作られた文字列は、論理演算子 C<|>、C<&>、C<^> で扱うこともできます。
20676C<^>, C<~> で扱うこともできます。
2067712194これらの演算子は、両方の被演算子に文字列を使うと、
2067812195ビットベクター演算を行ないます。
20679L<perlop/"Bitwise String Operators"> を参照してください。
2068012196
2068112197=begin original
2068212198
2068312199The following code will build up an ASCII string saying C<'PerlPerlPerl'>.
2068412200The comments show the string after each step. Note that this code works
2068512201in the same way on big-endian or little-endian machines.
2068612202
2068712203=end original
2068812204
2068912205次のコードは C<'PerlPerlPerl'> という ASCII 文字列を作成します。
2069012206コメントは各行の実行後の文字列を示します。
2069112207このコードはビッグエンディアンでもリトルエンディアンでも同じように
2069212208動作することに注意してください。
2069312209
2069412210 my $foo = '';
20695 vec($foo, 0, 32) = 0x5065726C; # 'Perl'
12211 vec($foo, 0, 32) = 0x5065726C; # 'Perl'
2069612212
2069712213 # $foo eq "Perl" eq "\x50\x65\x72\x6C", 32 bits
20698 print vec($foo, 0, 8); # prints 80 == 0x50 == ord('P')
12214 print vec($foo, 0, 8); # prints 80 == 0x50 == ord('P')
2069912215
20700 vec($foo, 2, 16) = 0x5065; # 'PerlPe'
12216 vec($foo, 2, 16) = 0x5065; # 'PerlPe'
20701 vec($foo, 3, 16) = 0x726C; # 'PerlPerl'
12217 vec($foo, 3, 16) = 0x726C; # 'PerlPerl'
20702 vec($foo, 8, 8) = 0x50; # 'PerlPerlP'
12218 vec($foo, 8, 8) = 0x50; # 'PerlPerlP'
20703 vec($foo, 9, 8) = 0x65; # 'PerlPerlPe'
12219 vec($foo, 9, 8) = 0x65; # 'PerlPerlPe'
20704 vec($foo, 20, 4) = 2; # 'PerlPerlPe' . "\x02"
12220 vec($foo, 20, 4) = 2; # 'PerlPerlPe' . "\x02"
20705 vec($foo, 21, 4) = 7; # 'PerlPerlPer'
12221 vec($foo, 21, 4) = 7; # 'PerlPerlPer'
20706 # 'r' is "\x72"
12222 # 'r' is "\x72"
20707 vec($foo, 45, 2) = 3; # 'PerlPerlPer' . "\x0c"
12223 vec($foo, 45, 2) = 3; # 'PerlPerlPer' . "\x0c"
20708 vec($foo, 93, 1) = 1; # 'PerlPerlPer' . "\x2c"
12224 vec($foo, 93, 1) = 1; # 'PerlPerlPer' . "\x2c"
20709 vec($foo, 94, 1) = 1; # 'PerlPerlPerl'
12225 vec($foo, 94, 1) = 1; # 'PerlPerlPerl'
20710 # 'l' is "\x6c"
12226 # 'l' is "\x6c"
2071112227
2071212228=begin original
2071312229
2071412230To transform a bit vector into a string or list of 0's and 1's, use these:
2071512231
2071612232=end original
2071712233
2071812234ビットベクターを、0 と 1 の文字列や配列に変換するには、
2071912235以下のようにします。
2072012236
20721 my $bits = unpack("b*", $vector);
12237 $bits = unpack("b*", $vector);
20722 my @bits = split(//, unpack("b*", $vector));
12238 @bits = split(//, unpack("b*", $vector));
2072312239
2072412240=begin original
2072512241
2072612242If you know the exact length in bits, it can be used in place of the C<*>.
2072712243
2072812244=end original
2072912245
20730ビット長が分かっていれば、C<*> の代わりにその長さを使うことができます。
12246ビット長が分かっていれば、* の代わりにその長さを使うことができます。
2073112247
2073212248=begin original
2073312249
2073412250Here is an example to illustrate how the bits actually fall in place:
2073512251
2073612252=end original
2073712253
2073812254これはビットが実際にどのような位置に入るかを図示する例です。
2073912255
20740 #!/usr/bin/perl -wl
12256 #!/usr/bin/perl -wl
2074112257
20742 print <<'EOT';
12258 print <<'EOT';
20743 0 1 2 3
12259 0 1 2 3
20744 unpack("V",$_) 01234567890123456789012345678901
12260 unpack("V",$_) 01234567890123456789012345678901
20745 ------------------------------------------------------------------
12261 ------------------------------------------------------------------
20746 EOT
12262 EOT
2074712263
20748 for $w (0..3) {
12264 for $w (0..3) {
20749 $width = 2**$w;
12265 $width = 2**$w;
20750 for ($shift=0; $shift < $width; ++$shift) {
12266 for ($shift=0; $shift < $width; ++$shift) {
20751 for ($off=0; $off < 32/$width; ++$off) {
12267 for ($off=0; $off < 32/$width; ++$off) {
20752 $str = pack("B*", "0"x32);
12268 $str = pack("B*", "0"x32);
20753 $bits = (1<<$shift);
12269 $bits = (1<<$shift);
20754 vec($str, $off, $width) = $bits;
12270 vec($str, $off, $width) = $bits;
20755 $res = unpack("b*",$str);
12271 $res = unpack("b*",$str);
20756 $val = unpack("V", $str);
12272 $val = unpack("V", $str);
20757 write;
12273 write;
20758 }
12274 }
20759 }
12275 }
20760 }
12276 }
2076112277
20762 format STDOUT =
12278 format STDOUT =
20763 vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
12279 vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
20764 $off, $width, $bits, $val, $res
12280 $off, $width, $bits, $val, $res
20765 .
12281 .
20766 __END__
12282 __END__
2076712283
2076812284=begin original
2076912285
20770Regardless of the machine architecture on which it runs, the
12286Regardless of the machine architecture on which it is run, the above
20771example above should print the following table:
12287example should print the following table:
2077212288
2077312289=end original
2077412290
2077512291実行するマシンのアーキテクチャに関わらず、
2077612292上記の例は以下の表を出力します。
2077712293
20778 0 1 2 3
12294 0 1 2 3
20779 unpack("V",$_) 01234567890123456789012345678901
12295 unpack("V",$_) 01234567890123456789012345678901
20780 ------------------------------------------------------------------
12296 ------------------------------------------------------------------
20781 vec($_, 0, 1) = 1 == 1 10000000000000000000000000000000
12297 vec($_, 0, 1) = 1 == 1 10000000000000000000000000000000
20782 vec($_, 1, 1) = 1 == 2 01000000000000000000000000000000
12298 vec($_, 1, 1) = 1 == 2 01000000000000000000000000000000
20783 vec($_, 2, 1) = 1 == 4 00100000000000000000000000000000
12299 vec($_, 2, 1) = 1 == 4 00100000000000000000000000000000
20784 vec($_, 3, 1) = 1 == 8 00010000000000000000000000000000
12300 vec($_, 3, 1) = 1 == 8 00010000000000000000000000000000
20785 vec($_, 4, 1) = 1 == 16 00001000000000000000000000000000
12301 vec($_, 4, 1) = 1 == 16 00001000000000000000000000000000
20786 vec($_, 5, 1) = 1 == 32 00000100000000000000000000000000
12302 vec($_, 5, 1) = 1 == 32 00000100000000000000000000000000
20787 vec($_, 6, 1) = 1 == 64 00000010000000000000000000000000
12303 vec($_, 6, 1) = 1 == 64 00000010000000000000000000000000
20788 vec($_, 7, 1) = 1 == 128 00000001000000000000000000000000
12304 vec($_, 7, 1) = 1 == 128 00000001000000000000000000000000
20789 vec($_, 8, 1) = 1 == 256 00000000100000000000000000000000
12305 vec($_, 8, 1) = 1 == 256 00000000100000000000000000000000
20790 vec($_, 9, 1) = 1 == 512 00000000010000000000000000000000
12306 vec($_, 9, 1) = 1 == 512 00000000010000000000000000000000
20791 vec($_,10, 1) = 1 == 1024 00000000001000000000000000000000
12307 vec($_,10, 1) = 1 == 1024 00000000001000000000000000000000
20792 vec($_,11, 1) = 1 == 2048 00000000000100000000000000000000
12308 vec($_,11, 1) = 1 == 2048 00000000000100000000000000000000
20793 vec($_,12, 1) = 1 == 4096 00000000000010000000000000000000
12309 vec($_,12, 1) = 1 == 4096 00000000000010000000000000000000
20794 vec($_,13, 1) = 1 == 8192 00000000000001000000000000000000
12310 vec($_,13, 1) = 1 == 8192 00000000000001000000000000000000
20795 vec($_,14, 1) = 1 == 16384 00000000000000100000000000000000
12311 vec($_,14, 1) = 1 == 16384 00000000000000100000000000000000
20796 vec($_,15, 1) = 1 == 32768 00000000000000010000000000000000
12312 vec($_,15, 1) = 1 == 32768 00000000000000010000000000000000
20797 vec($_,16, 1) = 1 == 65536 00000000000000001000000000000000
12313 vec($_,16, 1) = 1 == 65536 00000000000000001000000000000000
20798 vec($_,17, 1) = 1 == 131072 00000000000000000100000000000000
12314 vec($_,17, 1) = 1 == 131072 00000000000000000100000000000000
20799 vec($_,18, 1) = 1 == 262144 00000000000000000010000000000000
12315 vec($_,18, 1) = 1 == 262144 00000000000000000010000000000000
20800 vec($_,19, 1) = 1 == 524288 00000000000000000001000000000000
12316 vec($_,19, 1) = 1 == 524288 00000000000000000001000000000000
20801 vec($_,20, 1) = 1 == 1048576 00000000000000000000100000000000
12317 vec($_,20, 1) = 1 == 1048576 00000000000000000000100000000000
20802 vec($_,21, 1) = 1 == 2097152 00000000000000000000010000000000
12318 vec($_,21, 1) = 1 == 2097152 00000000000000000000010000000000
20803 vec($_,22, 1) = 1 == 4194304 00000000000000000000001000000000
12319 vec($_,22, 1) = 1 == 4194304 00000000000000000000001000000000
20804 vec($_,23, 1) = 1 == 8388608 00000000000000000000000100000000
12320 vec($_,23, 1) = 1 == 8388608 00000000000000000000000100000000
20805 vec($_,24, 1) = 1 == 16777216 00000000000000000000000010000000
12321 vec($_,24, 1) = 1 == 16777216 00000000000000000000000010000000
20806 vec($_,25, 1) = 1 == 33554432 00000000000000000000000001000000
12322 vec($_,25, 1) = 1 == 33554432 00000000000000000000000001000000
20807 vec($_,26, 1) = 1 == 67108864 00000000000000000000000000100000
12323 vec($_,26, 1) = 1 == 67108864 00000000000000000000000000100000
20808 vec($_,27, 1) = 1 == 134217728 00000000000000000000000000010000
12324 vec($_,27, 1) = 1 == 134217728 00000000000000000000000000010000
20809 vec($_,28, 1) = 1 == 268435456 00000000000000000000000000001000
12325 vec($_,28, 1) = 1 == 268435456 00000000000000000000000000001000
20810 vec($_,29, 1) = 1 == 536870912 00000000000000000000000000000100
12326 vec($_,29, 1) = 1 == 536870912 00000000000000000000000000000100
20811 vec($_,30, 1) = 1 == 1073741824 00000000000000000000000000000010
12327 vec($_,30, 1) = 1 == 1073741824 00000000000000000000000000000010
20812 vec($_,31, 1) = 1 == 2147483648 00000000000000000000000000000001
12328 vec($_,31, 1) = 1 == 2147483648 00000000000000000000000000000001
20813 vec($_, 0, 2) = 1 == 1 10000000000000000000000000000000
12329 vec($_, 0, 2) = 1 == 1 10000000000000000000000000000000
20814 vec($_, 1, 2) = 1 == 4 00100000000000000000000000000000
12330 vec($_, 1, 2) = 1 == 4 00100000000000000000000000000000
20815 vec($_, 2, 2) = 1 == 16 00001000000000000000000000000000
12331 vec($_, 2, 2) = 1 == 16 00001000000000000000000000000000
20816 vec($_, 3, 2) = 1 == 64 00000010000000000000000000000000
12332 vec($_, 3, 2) = 1 == 64 00000010000000000000000000000000
20817 vec($_, 4, 2) = 1 == 256 00000000100000000000000000000000
12333 vec($_, 4, 2) = 1 == 256 00000000100000000000000000000000
20818 vec($_, 5, 2) = 1 == 1024 00000000001000000000000000000000
12334 vec($_, 5, 2) = 1 == 1024 00000000001000000000000000000000
20819 vec($_, 6, 2) = 1 == 4096 00000000000010000000000000000000
12335 vec($_, 6, 2) = 1 == 4096 00000000000010000000000000000000
20820 vec($_, 7, 2) = 1 == 16384 00000000000000100000000000000000
12336 vec($_, 7, 2) = 1 == 16384 00000000000000100000000000000000
20821 vec($_, 8, 2) = 1 == 65536 00000000000000001000000000000000
12337 vec($_, 8, 2) = 1 == 65536 00000000000000001000000000000000
20822 vec($_, 9, 2) = 1 == 262144 00000000000000000010000000000000
12338 vec($_, 9, 2) = 1 == 262144 00000000000000000010000000000000
20823 vec($_,10, 2) = 1 == 1048576 00000000000000000000100000000000
12339 vec($_,10, 2) = 1 == 1048576 00000000000000000000100000000000
20824 vec($_,11, 2) = 1 == 4194304 00000000000000000000001000000000
12340 vec($_,11, 2) = 1 == 4194304 00000000000000000000001000000000
20825 vec($_,12, 2) = 1 == 16777216 00000000000000000000000010000000
12341 vec($_,12, 2) = 1 == 16777216 00000000000000000000000010000000
20826 vec($_,13, 2) = 1 == 67108864 00000000000000000000000000100000
12342 vec($_,13, 2) = 1 == 67108864 00000000000000000000000000100000
20827 vec($_,14, 2) = 1 == 268435456 00000000000000000000000000001000
12343 vec($_,14, 2) = 1 == 268435456 00000000000000000000000000001000
20828 vec($_,15, 2) = 1 == 1073741824 00000000000000000000000000000010
12344 vec($_,15, 2) = 1 == 1073741824 00000000000000000000000000000010
20829 vec($_, 0, 2) = 2 == 2 01000000000000000000000000000000
12345 vec($_, 0, 2) = 2 == 2 01000000000000000000000000000000
20830 vec($_, 1, 2) = 2 == 8 00010000000000000000000000000000
12346 vec($_, 1, 2) = 2 == 8 00010000000000000000000000000000
20831 vec($_, 2, 2) = 2 == 32 00000100000000000000000000000000
12347 vec($_, 2, 2) = 2 == 32 00000100000000000000000000000000
20832 vec($_, 3, 2) = 2 == 128 00000001000000000000000000000000
12348 vec($_, 3, 2) = 2 == 128 00000001000000000000000000000000
20833 vec($_, 4, 2) = 2 == 512 00000000010000000000000000000000
12349 vec($_, 4, 2) = 2 == 512 00000000010000000000000000000000
20834 vec($_, 5, 2) = 2 == 2048 00000000000100000000000000000000
12350 vec($_, 5, 2) = 2 == 2048 00000000000100000000000000000000
20835 vec($_, 6, 2) = 2 == 8192 00000000000001000000000000000000
12351 vec($_, 6, 2) = 2 == 8192 00000000000001000000000000000000
20836 vec($_, 7, 2) = 2 == 32768 00000000000000010000000000000000
12352 vec($_, 7, 2) = 2 == 32768 00000000000000010000000000000000
20837 vec($_, 8, 2) = 2 == 131072 00000000000000000100000000000000
12353 vec($_, 8, 2) = 2 == 131072 00000000000000000100000000000000
20838 vec($_, 9, 2) = 2 == 524288 00000000000000000001000000000000
12354 vec($_, 9, 2) = 2 == 524288 00000000000000000001000000000000
20839 vec($_,10, 2) = 2 == 2097152 00000000000000000000010000000000
12355 vec($_,10, 2) = 2 == 2097152 00000000000000000000010000000000
20840 vec($_,11, 2) = 2 == 8388608 00000000000000000000000100000000
12356 vec($_,11, 2) = 2 == 8388608 00000000000000000000000100000000
20841 vec($_,12, 2) = 2 == 33554432 00000000000000000000000001000000
12357 vec($_,12, 2) = 2 == 33554432 00000000000000000000000001000000
20842 vec($_,13, 2) = 2 == 134217728 00000000000000000000000000010000
12358 vec($_,13, 2) = 2 == 134217728 00000000000000000000000000010000
20843 vec($_,14, 2) = 2 == 536870912 00000000000000000000000000000100
12359 vec($_,14, 2) = 2 == 536870912 00000000000000000000000000000100
20844 vec($_,15, 2) = 2 == 2147483648 00000000000000000000000000000001
12360 vec($_,15, 2) = 2 == 2147483648 00000000000000000000000000000001
20845 vec($_, 0, 4) = 1 == 1 10000000000000000000000000000000
12361 vec($_, 0, 4) = 1 == 1 10000000000000000000000000000000
20846 vec($_, 1, 4) = 1 == 16 00001000000000000000000000000000
12362 vec($_, 1, 4) = 1 == 16 00001000000000000000000000000000
20847 vec($_, 2, 4) = 1 == 256 00000000100000000000000000000000
12363 vec($_, 2, 4) = 1 == 256 00000000100000000000000000000000
20848 vec($_, 3, 4) = 1 == 4096 00000000000010000000000000000000
12364 vec($_, 3, 4) = 1 == 4096 00000000000010000000000000000000
20849 vec($_, 4, 4) = 1 == 65536 00000000000000001000000000000000
12365 vec($_, 4, 4) = 1 == 65536 00000000000000001000000000000000
20850 vec($_, 5, 4) = 1 == 1048576 00000000000000000000100000000000
12366 vec($_, 5, 4) = 1 == 1048576 00000000000000000000100000000000
20851 vec($_, 6, 4) = 1 == 16777216 00000000000000000000000010000000
12367 vec($_, 6, 4) = 1 == 16777216 00000000000000000000000010000000
20852 vec($_, 7, 4) = 1 == 268435456 00000000000000000000000000001000
12368 vec($_, 7, 4) = 1 == 268435456 00000000000000000000000000001000
20853 vec($_, 0, 4) = 2 == 2 01000000000000000000000000000000
12369 vec($_, 0, 4) = 2 == 2 01000000000000000000000000000000
20854 vec($_, 1, 4) = 2 == 32 00000100000000000000000000000000
12370 vec($_, 1, 4) = 2 == 32 00000100000000000000000000000000
20855 vec($_, 2, 4) = 2 == 512 00000000010000000000000000000000
12371 vec($_, 2, 4) = 2 == 512 00000000010000000000000000000000
20856 vec($_, 3, 4) = 2 == 8192 00000000000001000000000000000000
12372 vec($_, 3, 4) = 2 == 8192 00000000000001000000000000000000
20857 vec($_, 4, 4) = 2 == 131072 00000000000000000100000000000000
12373 vec($_, 4, 4) = 2 == 131072 00000000000000000100000000000000
20858 vec($_, 5, 4) = 2 == 2097152 00000000000000000000010000000000
12374 vec($_, 5, 4) = 2 == 2097152 00000000000000000000010000000000
20859 vec($_, 6, 4) = 2 == 33554432 00000000000000000000000001000000
12375 vec($_, 6, 4) = 2 == 33554432 00000000000000000000000001000000
20860 vec($_, 7, 4) = 2 == 536870912 00000000000000000000000000000100
12376 vec($_, 7, 4) = 2 == 536870912 00000000000000000000000000000100
20861 vec($_, 0, 4) = 4 == 4 00100000000000000000000000000000
12377 vec($_, 0, 4) = 4 == 4 00100000000000000000000000000000
20862 vec($_, 1, 4) = 4 == 64 00000010000000000000000000000000
12378 vec($_, 1, 4) = 4 == 64 00000010000000000000000000000000
20863 vec($_, 2, 4) = 4 == 1024 00000000001000000000000000000000
12379 vec($_, 2, 4) = 4 == 1024 00000000001000000000000000000000
20864 vec($_, 3, 4) = 4 == 16384 00000000000000100000000000000000
12380 vec($_, 3, 4) = 4 == 16384 00000000000000100000000000000000
20865 vec($_, 4, 4) = 4 == 262144 00000000000000000010000000000000
12381 vec($_, 4, 4) = 4 == 262144 00000000000000000010000000000000
20866 vec($_, 5, 4) = 4 == 4194304 00000000000000000000001000000000
12382 vec($_, 5, 4) = 4 == 4194304 00000000000000000000001000000000
20867 vec($_, 6, 4) = 4 == 67108864 00000000000000000000000000100000
12383 vec($_, 6, 4) = 4 == 67108864 00000000000000000000000000100000
20868 vec($_, 7, 4) = 4 == 1073741824 00000000000000000000000000000010
12384 vec($_, 7, 4) = 4 == 1073741824 00000000000000000000000000000010
20869 vec($_, 0, 4) = 8 == 8 00010000000000000000000000000000
12385 vec($_, 0, 4) = 8 == 8 00010000000000000000000000000000
20870 vec($_, 1, 4) = 8 == 128 00000001000000000000000000000000
12386 vec($_, 1, 4) = 8 == 128 00000001000000000000000000000000
20871 vec($_, 2, 4) = 8 == 2048 00000000000100000000000000000000
12387 vec($_, 2, 4) = 8 == 2048 00000000000100000000000000000000
20872 vec($_, 3, 4) = 8 == 32768 00000000000000010000000000000000
12388 vec($_, 3, 4) = 8 == 32768 00000000000000010000000000000000
20873 vec($_, 4, 4) = 8 == 524288 00000000000000000001000000000000
12389 vec($_, 4, 4) = 8 == 524288 00000000000000000001000000000000
20874 vec($_, 5, 4) = 8 == 8388608 00000000000000000000000100000000
12390 vec($_, 5, 4) = 8 == 8388608 00000000000000000000000100000000
20875 vec($_, 6, 4) = 8 == 134217728 00000000000000000000000000010000
12391 vec($_, 6, 4) = 8 == 134217728 00000000000000000000000000010000
20876 vec($_, 7, 4) = 8 == 2147483648 00000000000000000000000000000001
12392 vec($_, 7, 4) = 8 == 2147483648 00000000000000000000000000000001
20877 vec($_, 0, 8) = 1 == 1 10000000000000000000000000000000
12393 vec($_, 0, 8) = 1 == 1 10000000000000000000000000000000
20878 vec($_, 1, 8) = 1 == 256 00000000100000000000000000000000
12394 vec($_, 1, 8) = 1 == 256 00000000100000000000000000000000
20879 vec($_, 2, 8) = 1 == 65536 00000000000000001000000000000000
12395 vec($_, 2, 8) = 1 == 65536 00000000000000001000000000000000
20880 vec($_, 3, 8) = 1 == 16777216 00000000000000000000000010000000
12396 vec($_, 3, 8) = 1 == 16777216 00000000000000000000000010000000
20881 vec($_, 0, 8) = 2 == 2 01000000000000000000000000000000
12397 vec($_, 0, 8) = 2 == 2 01000000000000000000000000000000
20882 vec($_, 1, 8) = 2 == 512 00000000010000000000000000000000
12398 vec($_, 1, 8) = 2 == 512 00000000010000000000000000000000
20883 vec($_, 2, 8) = 2 == 131072 00000000000000000100000000000000
12399 vec($_, 2, 8) = 2 == 131072 00000000000000000100000000000000
20884 vec($_, 3, 8) = 2 == 33554432 00000000000000000000000001000000
12400 vec($_, 3, 8) = 2 == 33554432 00000000000000000000000001000000
20885 vec($_, 0, 8) = 4 == 4 00100000000000000000000000000000
12401 vec($_, 0, 8) = 4 == 4 00100000000000000000000000000000
20886 vec($_, 1, 8) = 4 == 1024 00000000001000000000000000000000
12402 vec($_, 1, 8) = 4 == 1024 00000000001000000000000000000000
20887 vec($_, 2, 8) = 4 == 262144 00000000000000000010000000000000
12403 vec($_, 2, 8) = 4 == 262144 00000000000000000010000000000000
20888 vec($_, 3, 8) = 4 == 67108864 00000000000000000000000000100000
12404 vec($_, 3, 8) = 4 == 67108864 00000000000000000000000000100000
20889 vec($_, 0, 8) = 8 == 8 00010000000000000000000000000000
12405 vec($_, 0, 8) = 8 == 8 00010000000000000000000000000000
20890 vec($_, 1, 8) = 8 == 2048 00000000000100000000000000000000
12406 vec($_, 1, 8) = 8 == 2048 00000000000100000000000000000000
20891 vec($_, 2, 8) = 8 == 524288 00000000000000000001000000000000
12407 vec($_, 2, 8) = 8 == 524288 00000000000000000001000000000000
20892 vec($_, 3, 8) = 8 == 134217728 00000000000000000000000000010000
12408 vec($_, 3, 8) = 8 == 134217728 00000000000000000000000000010000
20893 vec($_, 0, 8) = 16 == 16 00001000000000000000000000000000
12409 vec($_, 0, 8) = 16 == 16 00001000000000000000000000000000
20894 vec($_, 1, 8) = 16 == 4096 00000000000010000000000000000000
12410 vec($_, 1, 8) = 16 == 4096 00000000000010000000000000000000
20895 vec($_, 2, 8) = 16 == 1048576 00000000000000000000100000000000
12411 vec($_, 2, 8) = 16 == 1048576 00000000000000000000100000000000
20896 vec($_, 3, 8) = 16 == 268435456 00000000000000000000000000001000
12412 vec($_, 3, 8) = 16 == 268435456 00000000000000000000000000001000
20897 vec($_, 0, 8) = 32 == 32 00000100000000000000000000000000
12413 vec($_, 0, 8) = 32 == 32 00000100000000000000000000000000
20898 vec($_, 1, 8) = 32 == 8192 00000000000001000000000000000000
12414 vec($_, 1, 8) = 32 == 8192 00000000000001000000000000000000
20899 vec($_, 2, 8) = 32 == 2097152 00000000000000000000010000000000
12415 vec($_, 2, 8) = 32 == 2097152 00000000000000000000010000000000
20900 vec($_, 3, 8) = 32 == 536870912 00000000000000000000000000000100
12416 vec($_, 3, 8) = 32 == 536870912 00000000000000000000000000000100
20901 vec($_, 0, 8) = 64 == 64 00000010000000000000000000000000
12417 vec($_, 0, 8) = 64 == 64 00000010000000000000000000000000
20902 vec($_, 1, 8) = 64 == 16384 00000000000000100000000000000000
12418 vec($_, 1, 8) = 64 == 16384 00000000000000100000000000000000
20903 vec($_, 2, 8) = 64 == 4194304 00000000000000000000001000000000
12419 vec($_, 2, 8) = 64 == 4194304 00000000000000000000001000000000
20904 vec($_, 3, 8) = 64 == 1073741824 00000000000000000000000000000010
12420 vec($_, 3, 8) = 64 == 1073741824 00000000000000000000000000000010
20905 vec($_, 0, 8) = 128 == 128 00000001000000000000000000000000
12421 vec($_, 0, 8) = 128 == 128 00000001000000000000000000000000
20906 vec($_, 1, 8) = 128 == 32768 00000000000000010000000000000000
12422 vec($_, 1, 8) = 128 == 32768 00000000000000010000000000000000
20907 vec($_, 2, 8) = 128 == 8388608 00000000000000000000000100000000
12423 vec($_, 2, 8) = 128 == 8388608 00000000000000000000000100000000
20908 vec($_, 3, 8) = 128 == 2147483648 00000000000000000000000000000001
12424 vec($_, 3, 8) = 128 == 2147483648 00000000000000000000000000000001
2090912425
2091012426=item wait
20911X<wait>
2091212427
20913=for Pod::Functions wait for any child process to die
20914
2091512428=begin original
2091612429
20917Behaves like L<wait(2)> on your system: it waits for a child
12430Behaves like the wait(2) system call on your system: it waits for a child
2091812431process to terminate and returns the pid of the deceased process, or
20919C<-1> if there are no child processes. The status is returned in
12432C<-1> if there are no child processes. The status is returned in C<$?>.
20920L<C<$?>|perlvar/$?> and
20921L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>.
2092212433Note that a return value of C<-1> could mean that child processes are
2092312434being automatically reaped, as described in L<perlipc>.
2092412435
2092512436=end original
2092612437
20927L<wait(2)> と同様に振る舞います: チャイルドプロセスが終了するのを待ち、
12438wait(2) システムコールと同様に振る舞います
20928消滅したプロセスの pid を返します; チャイルドプロセスが存在しないときには、
12439チャイルドプロセスが終了するのを待ち、消滅したプロセスの pid を返します
20929C<-1> を返します。
12440チャイルドプロセスが存在しないときには、C<-1> を返します。
20930ステータスは L<C<$?>|perlvar/$?>
12441ステータスは C<$?> に返されます。
20931L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に返されます。
2093212442L<perlipc> に書いているように、返り値が C<-1> の場合は子プロセスが
2093312443自動的に刈り取られたことを意味するかもしれないことに注意してください。
2093412444
20935=begin original
20936
20937If you use L<C<wait>|/wait> in your handler for
20938L<C<$SIG{CHLD}>|perlvar/%SIG>, it may accidentally wait for the child
20939created by L<C<qx>|/qxE<sol>STRINGE<sol>> or L<C<system>|/system LIST>.
20940See L<perlipc> for details.
20941
20942=end original
20943
20944L<C<wait>|/wait> を L<C<$SIG{CHLD}>|perlvar/%SIG> のハンドラで使うと、誤って
20945L<C<qx>|/qxE<sol>STRINGE<sol>> や L<C<system>|/system LIST> によって
20946作られた子を待つことになるかも知れません。
20947詳しくは L<perlipc> を参照してください。
20948
20949=begin original
20950
20951Portability issues: L<perlport/wait>.
20952
20953=end original
20954
20955移植性の問題: L<perlport/wait>。
20956
2095712445=item waitpid PID,FLAGS
20958X<waitpid>
2095912446
20960=for Pod::Functions wait for a particular child process to die
20961
2096212447=begin original
2096312448
2096412449Waits for a particular child process to terminate and returns the pid of
20965the deceased process, or C<-1> if there is no such child process. A
12450the deceased process, or C<-1> if there is no such child process. On some
20966non-blocking wait (with L<WNOHANG|POSIX/C<WNOHANG>> in FLAGS) can return 0 if
12451systems, a value of 0 indicates that there are processes still running.
20967there are child processes matching PID but none have terminated yet.
12452The status is returned in C<$?>. If you say
20968The status is returned in L<C<$?>|perlvar/$?> and
20969L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>.
2097012453
2097112454=end original
2097212455
20973特定のプロセスが終了するのを待ち、消滅したプロセスの pid を
12456特定のチャイルドプロセスが終了するのを待ち、消滅した
20974返します; 指定した子プロセスが存在しないときには、C<-1> を返します。
12457プロセスの pid を返します。
20975(FLAGS に L<WNOHANG|POSIX/C<WNOHANG>> を指定した) 非ブッキング wait は、
12458指定したチャイルドプセスが存在しないときには、C<-1> を返します。
20976PIDマッチングする子プロセスがいてもまだ終了していない場合に 0
12459 0 がプロセスがまだ実行中であること示すシステムもあります。
20977すことがあります。
12460ステータスは C<$?> にされます。
20978ステータスは L<C<$?>|perlvar/$?> と
20979L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に返されます。
2098012461
20981=begin original
20982
20983A PID of C<0> indicates to wait for any child process whose process group ID is
20984equal to that of the current process. A PID of less than C<-1> indicates to
20985wait for any child process whose process group ID is equal to -PID. A PID of
20986C<-1> indicates to wait for any child process.
20987
20988=end original
20989
20990PID に C<0> を指定すると、プロセスグループ ID が現在のプロセスと同じである
20991任意の子プロセスを wait します。
20992PID に C<-1> 以下を指定すると、プロセスグループ ID が -PID に等しい
20993任意の子プロセスを wait します。
20994PID に C<-1> を指定すると任意の子プロセスを wait します。
20995
20996=begin original
20997
20998If you say
20999
21000=end original
21001
21002以下のようにするか
21003
2100412462 use POSIX ":sys_wait_h";
12463 #...
12464 do {
12465 $kid = waitpid(-1,WNOHANG);
12466 } until $kid == -1;
2100512467
21006 my $kid;
21007 do {
21008 $kid = waitpid(-1, WNOHANG);
21009 } while $kid > 0;
21010
2101112468=begin original
2101212469
21013or
12470then you can do a non-blocking wait for all pending zombie processes.
21014
21015=end original
21016
21017または
21018
21019 1 while waitpid(-1, WNOHANG) > 0;
21020
21021=begin original
21022
21023then you can do a non-blocking wait for all pending zombie processes (see
21024L<POSIX/WAIT>).
2102512471Non-blocking wait is available on machines supporting either the
21026L<waitpid(2)> or L<wait4(2)> syscalls. However, waiting for a particular
12472waitpid(2) or wait4(2) system calls. However, waiting for a particular
2102712473pid with FLAGS of C<0> is implemented everywhere. (Perl emulates the
2102812474system call by remembering the status values of processes that have
2102912475exited but have not been harvested by the Perl script yet.)
2103012476
2103112477=end original
2103212478
2103312479とすると、ブロックが起こらないようにして、全ての待機中ゾンビプロセスを
21034wait します (L<POSIX/WAIT> を参照してください)
12480wait します。
21035ブロックなしの wait は、システムコール L<wait_pid(2)> か、
12481ブロックなしの wait は、システムコール wait_pid(2) か、
21036システムコール L<wait4(2)> をサポートしているマシンで利用可能です。
12482システムコール wait4(2) をサポートしているマシンで利用可能です。
2103712483しかしながら、特定の pid を C<0> の FLAGS での wait はどこでも
2103812484実装されています。
2103912485(exit したプロセスのステータス値を覚えておいて、Perl がシステムコールを
2104012486エミュレートしますが、Perl スクリプトには取り入れられていません。)
2104112487
2104212488=begin original
2104312489
2104412490Note that on some systems, a return value of C<-1> could mean that child
2104512491processes are being automatically reaped. See L<perlipc> for details,
2104612492and for other examples.
2104712493
2104812494=end original
2104912495
2105012496システムによっては、返り値が C<-1> の場合は子プロセスが自動的に
2105112497刈り取られたことを意味するかもしれないことに注意してください。
2105212498詳細やその他の例については L<perlipc> を参照してください。
2105312499
21054=begin original
21055
21056Portability issues: L<perlport/waitpid>.
21057
21058=end original
21059
21060移植性の問題: L<perlport/waitpid>。
21061
2106212500=item wantarray
21063X<wantarray> X<context>
2106412501
21065=for Pod::Functions get void vs scalar vs list context of current subroutine call
21066
2106712502=begin original
2106812503
21069Returns true if the context of the currently executing subroutine or
12504Returns true if the context of the currently executing subroutine is
21070L<C<eval>|/eval EXPR> is looking for a list value. Returns false if the
12505looking for a list value. Returns false if the context is looking
21071context is
12506for a scalar. Returns the undefined value if the context is looking
21072looking for a scalar. Returns the undefined value if the context is
12507for no value (void context).
21073looking for no value (void context).
2107412508
2107512509=end original
2107612510
21077現在実行中のサブルーチンか L<C<eval>|/eval EXPR> ブロックのコンテキストが、
12511現在実行中のサブルーチンのコンテキストが、リスト値を
21078リスト値を要求するものであれば、真を返します。
12512要求するものであれば、真を返します。
2107912513スカラを要求するコンテキストであれば、偽を返します。
2108012514何も値を要求しない(無効コンテキスト)場合は未定義値を返します。
2108112515
21082 return unless defined wantarray; # don't bother doing more
12516 return unless defined wantarray; # don't bother doing more
2108312517 my @a = complex_calculation();
2108412518 return wantarray ? @a : "@a";
2108512519
2108612520=begin original
2108712521
21088L<C<wantarray>|/wantarray>'s result is unspecified in the top level of a file,
12522This function should have been named wantlist() instead.
21089in a C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT> or C<END> block, or
21090in a C<DESTROY> method.
2109112523
2109212524=end original
2109312525
21094ファイルトップレベル、C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT>, C<END>
12526関数は wantlist() という名前にするべきでした。
21095ブロック内、C<DESTROY> メソッド内では L<C<wantarray>|/wantarray> の結果は
21096未定義です。
2109712527
12528=item warn LIST
12529
2109812530=begin original
2109912531
21100This function should have been named wantlist() instead.
12532Produces a message on STDERR just like C<die>, but doesn't exit or throw
12533an exception.
2110112534
2110212535=end original
2110312536
21104この関数は wantlist()名前するべきでた。
12537C<die>同じように STDERR にメッセージを出力ますが、
12538exit したり、例外を発生させたりしません。
2110512539
21106=item warn LIST
12540=begin original
21107X<warn> X<warning> X<STDERR>
2110812541
21109=for Pod::Functions print debugging info
12542If LIST is empty and C<$@> already contains a value (typically from a
12543previous eval) that value is used after appending C<"\t...caught">
12544to C<$@>. This is useful for staying almost, but not entirely similar to
12545C<die>.
2111012546
12547=end original
12548
12549LIST が空かつ、(典型的には以前の eval によって) C<$@> に既に値が入っている
12550場合、C<$@> に C<"\t...caught"> を追加した値が用いられます。
12551これはほとんどそのままにするときに便利ですが、
12552C<die> と全体的に似ているわけではありません。
12553
2111112554=begin original
2111212555
21113Emits a warning, usually by printing it to C<STDERR>. C<warn> interprets
12556If C<$@> is empty then the string C<"Warning: Something's wrong"> is used.
21114its operand LIST in the same way as C<die>, but is slightly different
21115in what it defaults to when LIST is empty or makes an empty string.
21116If it is empty and L<C<$@>|perlvar/$@> already contains an exception
21117value then that value is used after appending C<"\t...caught">. If it
21118is empty and C<$@> is also empty then the string C<"Warning: Something's
21119wrong"> is used.
2112012557
2112112558=end original
2112212559
21123(通常は C<STDERR> に表示するこで) 警告を出力します。
12560C<$@> が空の場合は、C<"Warning: Something's wrong"> という文字列が
21124C<warn> はそのオペランド LIST を C<die> と同様に解釈しますが、
12561使われます
21125LIST が空や空文字列を作る時に何をデフォルトとするかが少し異なります。
21126それが空かつ、L<C<$@>|perlvar/$@> に既に
21127例外値が入っている場合、C<"\t...caught"> を追加した値が
21128用いられます。
21129もしこれが空で C<$@> も空の場合は、C<"Warning: Something's wrong"> という
21130文字列が使われます。
2113112562
2113212563=begin original
2113312564
21134By default, the exception derived from the operand LIST is stringified
12565No message is printed if there is a C<$SIG{__WARN__}> handler
21135and printed to C<STDERR>. This behaviour can be altered by installing
12566installed. It is the handler's responsibility to deal with the message
21136a L<C<$SIG{__WARN__}>|perlvar/%SIG> handler. If there is such a
12567as it sees fit (like, for instance, converting it into a C<die>). Most
21137handler then no message is automatically printed; it is the handler's
12568handlers must therefore make arrangements to actually display the
21138responsibility to deal with the exception
12569warnings that they are not prepared to deal with, by calling C<warn>
21139as it sees fit (like, for instance, converting it into a
21140L<C<die>|/die LIST>). Most
21141handlers must therefore arrange to actually display the
21142warnings that they are not prepared to deal with, by calling
21143L<C<warn>|/warn LIST>
2114412570again in the handler. Note that this is quite safe and will not
2114512571produce an endless loop, since C<__WARN__> hooks are not called from
2114612572inside one.
2114712573
2114812574=end original
2114912575
21150デフォルトでは、LIST オペランドから生成された例外
12576C<$SIG{__WARN__}> ンドラが設定されている場合何のメッセージも
21151文字列化されて C<STDERR> に表示されま
12577表示されません
21152この振る舞いは、L<C<$SIG{__WARN__}>|perlvar/%SIG> ハンドラを設定することで
12578メッセージをどう扱うか(例えば C<die> に変換するか)はハンドラ
21153置き換えられます。
21154このようなハンドラが設定されている場合は何の
21155メッセージも自動的には表示されません;
21156例外をどう扱うか(例えば L<C<die>|/die LIST> に変換するか)はハンドラの
2115712579責任ということです。
2115812580従ってほとんどのハンドラは、扱おうと準備していない警告を表示するために、
21159ハンドラの中で L<C<warn>|/warn LIST> を再び呼び出します。
12581ハンドラの中で C<warn> を再び呼び出します。
2116012582C<__WARN__> フックはハンドラ内では呼び出されないので、これは十分安全で、
2116112583無限ループを引き起こすことはないということに注意してください。
2116212584
2116312585=begin original
2116412586
2116512587You will find this behavior is slightly different from that of
21166L<C<$SIG{__DIE__}>|perlvar/%SIG> handlers (which don't suppress the
12588C<$SIG{__DIE__}> handlers (which don't suppress the error text, but can
21167error text, but can instead call L<C<die>|/die LIST> again to change
12589instead call C<die> again to change it).
21168it).
2116912590
2117012591=end original
2117112592
21172この振る舞いは L<C<$SIG{__DIE__}>|perlvar/%SIG> ハンドラ(エラーテキストは
12593この振る舞いは C<$SIG{__DIE__}> ハンドラ(エラーテキストは削除しませんが、
21173削除しませんが、代わりに L<C<die>|/die LIST> をもう一度呼び出すことで
12594代わりに C<die> をもう一度呼び出すことで変更できます)とは
21174変更できます)とは少し違うことに気付くことでしょう。
12595少し違うことに気付くことでしょう。
2117512596
2117612597=begin original
2117712598
2117812599Using a C<__WARN__> handler provides a powerful way to silence all
2117912600warnings (even the so-called mandatory ones). An example:
2118012601
2118112602=end original
2118212603
2118312604C<__WARN__> ハンドラを使うと、(いわゆる必須のものを含む)全ての
2118412605警告を黙らせる強力な手段となります。
2118512606例:
2118612607
2118712608 # wipe out *all* compile-time warnings
2118812609 BEGIN { $SIG{'__WARN__'} = sub { warn $_[0] if $DOWARN } }
2118912610 my $foo = 10;
2119012611 my $foo = 20; # no warning about duplicate my $foo,
2119112612 # but hey, you asked for it!
2119212613 # no compile-time or run-time warnings before here
2119312614 $DOWARN = 1;
2119412615
2119512616 # run-time warnings enabled after here
2119612617 warn "\$foo is alive and $foo!"; # does show up
2119712618
2119812619=begin original
2119912620
21200See L<perlvar> for details on setting L<C<%SIG>|perlvar/%SIG> entries
12621See L<perlvar> for details on setting C<%SIG> entries, and for more
21201and for more
12622examples. See the Carp module for other kinds of warnings using its
21202examples. See the L<Carp> module for other kinds of warnings using its
12623carp() and cluck() functions.
21203C<carp> and C<cluck> functions.
2120412624
2120512625=end original
2120612626
21207L<C<%SIG>|perlvar/%SIG> エントリのセットに関する詳細とさらなる例に関しては
12627C<%SIG> エントリのセットに関する詳細とさらなる例に関しては
21208L<perlvar> を参照してください。
12628L<perlvar> を参照してさい。
21209C<carp> 関数と C<cluck> 関数を用いた警告の方法に関しては
12629carp() 関数と cluck() 関数を用いた警告の方法に関しては
21210L<Carp> モジュールを参照してください。
12630Carp モジュールを参照してさい。
2121112631
2121212632=item write FILEHANDLE
21213X<write>
2121412633
2121512634=item write EXPR
2121612635
2121712636=item write
2121812637
21219=for Pod::Functions print a picture record
21220
2122112638=begin original
2122212639
2122312640Writes a formatted record (possibly multi-line) to the specified FILEHANDLE,
2122412641using the format associated with that file. By default the format for
2122512642a file is the one having the same name as the filehandle, but the
21226format for the current output channel (see the
12643format for the current output channel (see the C<select> function) may be set
21227L<C<select>|/select FILEHANDLE> function) may be set explicitly by
12644explicitly by assigning the name of the format to the C<$~> variable.
21228assigning the name of the format to the L<C<$~>|perlvar/$~> variable.
2122912645
2123012646=end original
2123112647
2123212648指定された FILEHANDLE に対して、そのファイルに対応させた
2123312649フォーマットを使って、(複数行の場合もある) 整形された
2123412650レコードを書き出します。
2123512651デフォルトでは、ファイルに対応するフォーマットは、ファイルハンドルと
21236同じ名前のものですが、その時点の出力チャネル
12652同じ名前のものですが、その時点の出力チャネル (C<select> 関数の項を
21237(L<C<select>|/select FILEHANDLE> 関数の項を
12653参照してください) のフォーマットは、その名前を明示的に変数 C<$~>
21238参照してください) のフォーマットはその名前を明示的に
12654代入することで、変更が可能です。 
21239L<C<$~>|perlvar/$~> に代入することで、変更が可能です。
2124012655
2124112656=begin original
2124212657
21243Top of form processing is handled automatically: if there is insufficient
12658Top of form processing is handled automatically: if there is
21244room on the current page for the formatted record, the page is advanced by
12659insufficient room on the current page for the formatted record, the
21245writing a form feed and a special top-of-page
12660page is advanced by writing a form feed, a special top-of-page format
21246format is used to format the new
12661is used to format the new page header, and then the record is written.
21247page header before the record is written. By default, the top-of-page
12662By default the top-of-page format is the name of the filehandle with
21248format is the name of the filehandle with C<_TOP> appended, or C<top>
12663"_TOP" appended, but it may be dynamically set to the format of your
21249in the current package if the former does not exist. This would be a
12664choice by assigning the name to the C<$^> variable while the filehandle is
21250problem with autovivified filehandles, but it may be dynamically set to the
12665selected. The number of lines remaining on the current page is in
21251format of your choice by assigning the name to the L<C<$^>|perlvar/$^>
12666variable C<$->, which can be set to C<0> to force a new page.
21252variable while that filehandle is selected. The number of lines
21253remaining on the current page is in variable L<C<$->|perlvar/$->, which
21254can be set to C<0> to force a new page.
2125512667
2125612668=end original
2125712669
21258ページの先頭の処理は、自動的に行なわれます: 現在のページに整形された
12670ページの先頭の処理は、自動的に行なわれます
21259レコードを出力するだけのスペースがない場合には、改ページを行なってページを
12671現在のページに整形されたレコードを出力するだけのスペースがない場合には、
21260進め、新しいページヘッダを整形するため、ページ先頭フォーマットが使われ
12672改ページを行なってページを進め、新しいページヘッダを整形するため、
21261その後でレコードが書かれます。
12673ページ先頭フォーマットが使われ、その後でレコードが書かれます。
2126212674デフォルトでは、ページ先頭フォーマットは、ファイルハンドルの名前に
21263C<_TOP> をつなげたもの前者存在しななら現在のパッケージの
12675"_TOP" をつなげたものですがファイルハンドル選択されてる間に
21264C<top>
12676変数 C<$^> に名前を設定れば、動的にフォーマットを
21265これは自動有効化されたファイルハンドルで問題になる可能性がありますが、
21266ファイルハンドルが選択されている間に、
21267変数 L<C<$^>|perlvar/$^> に名前を設定すれば、動的にフォーマットを
2126812677変更することができます。
21269そのページの残り行数は、変数 L<C<$->|perlvar/$-> に入っており、この変数を
12678そのページの残り行数は、変数 C<$-> に入っており、この変数を 0 に
21270C<0> に設定することで、強制的に改ページを行なうことができます。
12679設定することで、強制的に改ページを行なうことができます。
2127112680
2127212681=begin original
2127312682
2127412683If FILEHANDLE is unspecified, output goes to the current default output
2127512684channel, which starts out as STDOUT but may be changed by the
21276L<C<select>|/select FILEHANDLE> operator. If the FILEHANDLE is an EXPR,
12685C<select> operator. If the FILEHANDLE is an EXPR, then the expression
21277then the expression
2127812686is evaluated and the resulting string is used to look up the name of
2127912687the FILEHANDLE at run time. For more on formats, see L<perlform>.
2128012688
2128112689=end original
2128212690
21283FILEHANDLE を指定しないと、出力はその時点のデフォルト出力チャネルに対して
12691FILEHANDLE を指定しないと、出力はその時点のデフォルト
21284行なわれます; これは、スクリプトの開始時点では STDOUT ですが、
12692出力チャネルに対して行なわれます
21285L<C<select>|/select FILEHANDLE> 演算子で変更することができます。
12693これは、スクリプトの開始時点では STDOUT ですが、select() 演算子で
12694変更することができます。
2128612695FILEHANDLE が EXPR ならば、式が評価され、その結果の文字列が
2128712696実行時に FILEHANDLE の名前として見られます。
2128812697フォーマットについて、さらには、L<perlform> を参照してください。
2128912698
2129012699=begin original
2129112700
21292Note that write is I<not> the opposite of
12701Note that write is I<not> the opposite of C<read>. Unfortunately.
21293L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>. Unfortunately.
2129412702
2129512703=end original
2129612704
21297write は L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>
12705残念ながら、write は C<read> の反対のことをするも
21298反対のことをするもの I<ではありません>。
12706I<ではありません>。
21299残念ながら。
2130012707
2130112708=item y///
2130212709
21303=for Pod::Functions transliterate a string
21304
2130512710=begin original
2130612711
21307The transliteration operator. Same as
12712The transliteration operator. Same as C<tr///>. See L<perlop>.
21308L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>>. See
21309L<perlop/"Quote-Like Operators">.
2131012713
2131112714=end original
2131212715
21313文字変換演算子です。
12716文字変換演算子です。C<tr///>と同じです。L<perlop>を参照して
21314L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>> と同じです
12717ください
21315L<perlop/"Quote-Like Operators"> を参照してください。
2131612718
2131712719=back
2131812720
21319=head2 Non-function Keywords by Cross-reference
21320
21321=head3 perldata
21322
21323=over
21324
21325=item __DATA__
21326
21327=item __END__
21328
21329=begin original
21330
21331These keywords are documented in L<perldata/"Special Literals">.
21332
21333=end original
21334
21335これらのキーワードは L<perldata/"Special Literals"> で文書化されています。
21336
21337=back
21338
21339=head3 perlmod
21340
21341=over
21342
21343=item BEGIN
21344
21345=item CHECK
21346
21347=item END
21348
21349=item INIT
21350
21351=item UNITCHECK
21352
21353=begin original
21354
21355These compile phase keywords are documented in L<perlmod/"BEGIN, UNITCHECK, CHECK, INIT and END">.
21356
21357=end original
21358
21359これらのコンパイルフェーズキーワードは
21360L<perlmod/"BEGIN, UNITCHECK, CHECK, INIT and END"> で文書化されています。
21361
21362=back
21363
21364=head3 perlobj
21365
21366=over
21367
21368=item DESTROY
21369
21370=begin original
21371
21372This method keyword is documented in L<perlobj/"Destructors">.
21373
21374=end original
21375
21376このメソッドキーワードは L<perlobj/"Destructors"> で文書化されています。
21377
21378=back
21379
21380=head3 perlop
21381
21382=over
21383
21384=item and
21385
21386=item cmp
21387
21388=item eq
21389
21390=item ge
21391
21392=item gt
21393
21394=item le
21395
21396=item lt
21397
21398=item ne
21399
21400=item not
21401
21402=item or
21403
21404=item x
21405
21406=item xor
21407
21408=begin original
21409
21410These operators are documented in L<perlop>.
21411
21412=end original
21413
21414これらの演算子は L<perlop> で文書化されています。
21415
21416=back
21417
21418=head3 perlsub
21419
21420=over
21421
21422=item AUTOLOAD
21423
21424=begin original
21425
21426This keyword is documented in L<perlsub/"Autoloading">.
21427
21428=end original
21429
21430このキーワードは L<perlsub/"Autoloading"> で文書化されています。
21431
21432=back
21433
21434=head3 perlsyn
21435
21436=over
21437
21438=item else
21439
21440=item elsif
21441
21442=item for
21443
21444=item foreach
21445
21446=item if
21447
21448=item unless
21449
21450=item until
21451
21452=item while
21453
21454=begin original
21455
21456These flow-control keywords are documented in L<perlsyn/"Compound Statements">.
21457
21458=end original
21459
21460これらのフロー制御キーワードは L<perlsyn/"Compound Statements"> で
21461文書化されています。
21462
21463=item elseif
21464
21465=begin original
21466
21467The "else if" keyword is spelled C<elsif> in Perl. There's no C<elif>
21468or C<else if> either. It does parse C<elseif>, but only to warn you
21469about not using it.
21470
21471=end original
21472
21473"else if" キーワードは Perl では C<elsif> と綴ります。
21474C<elif> や C<else if> はありません。
21475C<elseif> はパースされますが、使わないように警告するためだけです。
21476
21477=begin original
21478
21479See the documentation for flow-control keywords in L<perlsyn/"Compound
21480Statements">.
21481
21482=end original
21483
21484L<perlsyn/"Compound Statements"> のフロー制御キーワードに関する文章を
21485参照してください。
21486
21487=back
21488
21489=over
21490
21491=item default
21492
21493=item given
21494
21495=item when
21496
21497=begin original
21498
21499These flow-control keywords related to the experimental switch feature are
21500documented in L<perlsyn/"Switch Statements">.
21501
21502=end original
21503
21504これらの実験的な switch 機能に関連するフロー制御キーワードは
21505L<perlsyn/"Switch Statements"> で文書化されています。
21506
21507=back
21508
21509=cut
21510
2151112721=begin meta
2151212722
2151312723Translate: 吉村 寿人 <JAE00534@niftyserve.or.jp>
21514Update: SHIRAKATA Kentaro <argrath@ub32.org> (5.6.1-)
12724Update: Kentaro Shirakata <argrath@ub32.org>
21515Status: completed
12725License: GPL or Artistic
2151612726
2151712727=end meta