perlfunc > 5.18.1 との差分

perlfunc 5.18.1 と 5.38.0 の差分

11
2=encoding euc-jp
2=encoding utf8
33
44=head1 NAME
55X<function>
66
77=begin original
88
99perlfunc - Perl builtin functions
1010
1111=end original
1212
1313perlfunc - Perl 組み込み関数
1414
1515=head1 DESCRIPTION
1616
1717=begin original
1818
1919The functions in this section can serve as terms in an expression.
2020They fall into two major categories: list operators and named unary
2121operators. These differ in their precedence relationship with a
2222following comma. (See the precedence table in L<perlop>.) List
2323operators take more than one argument, while unary operators can never
2424take more than one argument. Thus, a comma terminates the argument of
2525a unary operator, but merely separates the arguments of a list
2626operator. A unary operator generally provides scalar context to its
2727argument, while a list operator may provide either scalar or list
28contexts for its arguments. If it does both, scalar arguments
28contexts for its arguments. If it does both, scalar arguments
2929come first and list argument follow, and there can only ever
30be one such list argument. For instance, splice() has three scalar
30be one such list argument. For instance,
31arguments followed by a list, whereas gethostbyname() has four scalar
31L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> has three scalar arguments
32arguments.
32followed by a list, whereas L<C<gethostbyname>|/gethostbyname NAME> has
33four scalar arguments.
3334
3435=end original
3536
3637この節の関数は、式の中で項として使うことができます。
3738これらは、大きく二つに分けられます:
3839リスト演算子と名前付き単項演算子です。
3940これらの違いは、その後に出て来るコンマとの優先順位の関係にあります。
4041(L<perlop> の優先順位の表を参照してください。)
4142リスト演算子は 2 個以上の引数をとるのに対して、単項演算子が複数の引数を
4243とることはありません。
4344つまり、コンマは単項演算子の引数の終わりとなりますが、リスト演算子の
4445場合には、引数の区切りでしかありません。
4546単項演算子は一般に、引数に対してスカラコンテキストを与えるのに対して、
4647スカラ演算子の場合には、引数に対してスカラコンテキストを与える場合も、
4748リストコンテキストを与える場合もあります。
4849一つのリスト演算子が両方のコンテキストを与える場合には、スカラ引数が
4950いくつか並び、最後にリスト引数が一つ続きます;
5051そしてそのようなリスト引数は一つだけしかありません。
51たとえば、splice() は三つのスカラ引数に一つのリスト引数が続きます;
52たとえば、L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> は三つのスカラ引数に
52方 gethostbyname() は四つのスカラ引数を持ちます
53一つの引数が続きます;
54一方 L<C<gethostbyname>|/gethostbyname NAME> は四つのスカラ引数を持ちます。
5355
5456=begin original
5557
5658In the syntax descriptions that follow, list operators that expect a
5759list (and provide list context for elements of the list) are shown
5860with LIST as an argument. Such a list may consist of any combination
5961of scalar arguments or list values; the list values will be included
6062in the list as if each individual element were interpolated at that
6163point in the list, forming a longer single-dimensional list value.
6264Commas should separate literal elements of the LIST.
6365
6466=end original
6567
6668後に載せる構文記述では、リストをとり (そのリストの要素にリストコンテキストを
6769与える)リスト演算子は、引数として LIST をとるように書いています;
6870そのようなリストには、任意のスカラ引数の組み合わせやリスト値を
6971含めることができ、リスト値はリストの中に、個々の要素が展開されたように
7072埋め込まれます。
71731 次元の長いリスト値が形成されることになります。
7274LIST のリテラルな要素は、コンマで区切られます。
7375
7476=begin original
7577
7678Any function in the list below may be used either with or without
7779parentheses around its arguments. (The syntax descriptions omit the
78parentheses.) If you use parentheses, the simple but occasionally
80parentheses.) If you use parentheses, the simple but occasionally
7981surprising rule is this: It I<looks> like a function, therefore it I<is> a
8082function, and precedence doesn't matter. Otherwise it's a list
8183operator or unary operator, and precedence does matter. Whitespace
8284between the function and left parenthesis doesn't count, so sometimes
8385you need to be careful:
8486
8587=end original
8688
8789以下のリストの関数はすべて、引数の前後の括弧は省略可能となっています。
8890(構文記述では省略しています。)
8991括弧を使うときには、単純な、(しかし、ときには驚く結果となる規則が
9092適用できます:
9193I<関数に見える>ならば、I<それは関数>で、優先順位は関係ありません。
9294そう見えなければ、それはリスト演算子か単項演算子で、優先順位が関係します。
9395関数と開き括弧の間の空白は関係ありませんので、ときに
9496気を付けなければなりません:
9597
9698 print 1+2+4; # Prints 7.
9799 print(1+2) + 4; # Prints 3.
98100 print (1+2)+4; # Also prints 3!
99101 print +(1+2)+4; # Prints 7.
100102 print ((1+2)+4); # Prints 7.
101103
102104=begin original
103105
104If you run Perl with the B<-w> switch it can warn you about this. For
106If you run Perl with the L<C<use warnings>|warnings> pragma, it can warn
105example, the third line above produces:
107you about this. For example, the third line above produces:
106108
107109=end original
108110
109Perl に B<-w> スイッチを付けて実行すれば、こういったものには警告を
111Perl に L<C<use warnings>|warnings> プラグマを付けて実行すれば、
110出してくれます。
112こういったものには警告を出してくれます。
111113たとえば、上記の三つめは、以下のような警告が出ます:
112114
113115 print (...) interpreted as function at - line 1.
114116 Useless use of integer addition in void context at - line 1.
115117
116118=begin original
117119
118120A few functions take no arguments at all, and therefore work as neither
119unary nor list operators. These include such functions as C<time>
121unary nor list operators. These include such functions as
120and C<endpwent>. For example, C<time+86_400> always means
122L<C<time>|/time> and L<C<endpwent>|/endpwent>. For example,
121C<time() + 86_400>.
123C<time+86_400> always means C<time() + 86_400>.
122124
123125=end original
124126
125127いくつかの関数は引数を全くとらないので、単項演算子としても
126128リスト演算子としても動作しません。
127このような関数としては C<time> や C<endpwent> があります。
129このような関数としては L<C<time>|/time>L<C<endpwent>|/endpwent>
130あります。
128131例えば、C<time+86_400> は常に C<time() + 86_400> として扱われます。
129132
130133=begin original
131134
132135For functions that can be used in either a scalar or list context,
133136nonabortive failure is generally indicated in scalar context by
134137returning the undefined value, and in list context by returning the
135138empty list.
136139
137140=end original
138141
139142スカラコンテキストでも、リストコンテキストでも使える関数は、致命的でない
140143エラーを示すために、スカラコンテキストでは未定義値を返し、
141144リストコンテキストでは空リストを返します。
142145
143146=begin original
144147
145148Remember the following important rule: There is B<no rule> that relates
146149the behavior of an expression in list context to its behavior in scalar
147150context, or vice versa. It might do two totally different things.
148151Each operator and function decides which sort of value would be most
149152appropriate to return in scalar context. Some operators return the
150153length of the list that would have been returned in list context. Some
151154operators return the first value in the list. Some operators return the
152155last value in the list. Some operators return a count of successful
153156operations. In general, they do what you want, unless you want
154157consistency.
155158X<context>
156159
157160=end original
158161
159162以下に述べる重要なルールを忘れないで下さい: リストコンテキストでの
160163振る舞いとスカラコンテキストでの振る舞いの関係、あるいはその逆に
161164B<ルールはありません>。
1621652 つの全く異なったことがあります。
163166それぞれの演算子と関数は、スカラコンテキストでは、もっとも適切と
164167思われる値を返します。
165168リストコンテキストで返す時のリストの長さを返す演算子もあります。
166169リストの最初の値を返す演算子もあります。
167170リストの最後の値を返す演算子もあります。
168171成功した操作の数を返す演算子もあります。
169172一般的には、一貫性を求めない限り、こちらが求めることをします。
170173X<context>
171174
172175=begin original
173176
174177A named array in scalar context is quite different from what would at
175178first glance appear to be a list in scalar context. You can't get a list
176179like C<(1,2,3)> into being in scalar context, because the compiler knows
177180the context at compile time. It would generate the scalar comma operator
178there, not the list construction version of the comma. That means it
181there, not the list concatenation version of the comma. That means it
179182was never a list to start with.
180183
181184=end original
182185
183186スカラコンテキストでの名前付き配列は、スカラコンテキストでのリストを
184187一目見たものとは全く違います。
185188コンパイラはコンパイル時にコンテキストを知っているので、
186189C<(1,2,3)> のようなリストをスカラコンテキストで得ることはできません。
187これはスカラコンマ演算子を生成し、コンマのリスト作成版ではありません。
190これはスカラコンマ演算子を生成し、コンマのリスト結合版ではありません。
188191これは初めからリストであることはないことを意味します。
189192
190193=begin original
191194
192In general, functions in Perl that serve as wrappers for system calls ("syscalls")
195In general, functions in Perl that serve as wrappers for system calls
193of the same name (like chown(2), fork(2), closedir(2), etc.) return
196("syscalls") of the same name (like L<chown(2)>, L<fork(2)>,
194true when they succeed and C<undef> otherwise, as is usually mentioned
197L<closedir(2)>, etc.) return true when they succeed and
195in the descriptions below. This is different from the C interfaces,
198L<C<undef>|/undef EXPR> otherwise, as is usually mentioned in the
196which return C<-1> on failure. Exceptions to this rule include C<wait>,
199descriptions below. This is different from the C interfaces, which
197C<waitpid>, and C<syscall>. System calls also set the special C<$!>
200return C<-1> on failure. Exceptions to this rule include
198variable on failure. Other functions do not, except accidentally.
201L<C<wait>|/wait>, L<C<waitpid>|/waitpid PID,FLAGS>, and
202L<C<syscall>|/syscall NUMBER, LIST>. System calls also set the special
203L<C<$!>|perlvar/$!> variable on failure. Other functions do not, except
204accidentally.
199205
200206=end original
201207
202208一般的に、同じ名前のシステムコールのラッパーとして動作する Perl の関数
203(chown(2), fork(2), closedir(2) など)は、以下に述べるように、
209(L<chown(2)>, L<fork(2)>, L<closedir(2)> など)は、以下に述べるように、
204成功時に真を返し、そうでなければ C<undef> を返します。
210成功時に真を返し、そうでなければ L<C<undef>|/undef EXPR> を返します。
205211これは失敗時に C<-1> を返す C のインターフェースとは違います。
206このルールの例外は C<wait>, C<waitpid>, C<syscall> です。
212このルールの例外は L<C<wait>|/wait>, L<C<waitpid>|/waitpid PID,FLAGS>,
207システムコールは失敗時に特殊変数 C<$!> をセットします。
213L<C<syscall>|/syscall NUMBER, LIST> です。
214システムコールは失敗時に特殊変数 L<C<$!>|perlvar/$!> をセットします。
208215その他の関数は、事故を除いて、セットしません。
209216
210217=begin original
211218
212219Extension modules can also hook into the Perl parser to define new
213220kinds of keyword-headed expression. These may look like functions, but
214221may also look completely different. The syntax following the keyword
215222is defined entirely by the extension. If you are an implementor, see
216223L<perlapi/PL_keyword_plugin> for the mechanism. If you are using such
217224a module, see the module's documentation for details of the syntax that
218225it defines.
219226
220227=end original
221228
222229エクステンションモジュールは、新しい種類のキーワードが頭に付いた式を
223230定義するために Perl パーサをフックできます。
224231これらは関数のように見えるかもしれませんが、全く別物かもしれません。
225232キーワード以降の文法は完全にエクステンションによって定義されます。
226233もしあなたが実装者なら、この機構については L<perlapi/PL_keyword_plugin> を
227234参照してください。
228235もしあなたがそのようなモジュールを使っているなら、
229236定義されている文法の詳細についてはモジュールの文書を参照してください。
230237
231238=head2 Perl Functions by Category
232239X<function>
233240
234241(カテゴリ別の Perl 関数)
235242
236243=begin original
237244
238245Here are Perl's functions (including things that look like
239246functions, like some keywords and named operators)
240247arranged by category. Some functions appear in more
241than one place.
248than one place. Any warnings, including those produced by
249keywords, are described in L<perldiag> and L<warnings>.
242250
243251=end original
244252
245253以下に、カテゴリ別の関数(キーワードや名前付き演算子のような、
246254関数のように見えるものも含みます)を示します。
247255複数の場所に現れる関数もあります。
256キーワードによって生成されるものを含む全ての警告は
257L<perldiag> と L<warnings> に記述されています。
248258
249259=over 4
250260
251261=item Functions for SCALARs or strings
252262X<scalar> X<string> X<character>
253263
254264(スカラや文字列のための関数)
255265
256266=for Pod::Functions =String
257267
258C<chomp>, C<chop>, C<chr>, C<crypt>, C<fc>, C<hex>, C<index>, C<lc>,
268L<C<chomp>|/chomp VARIABLE>, L<C<chop>|/chop VARIABLE>,
259C<lcfirst>, C<length>, C<oct>, C<ord>, C<pack>, C<q//>, C<qq//>, C<reverse>,
269L<C<chr>|/chr NUMBER>, L<C<crypt>|/crypt PLAINTEXT,SALT>,
260C<rindex>, C<sprintf>, C<substr>, C<tr///>, C<uc>, C<ucfirst>, C<y///>
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>>
261283
262284=begin original
263285
264C<fc> is available only if the C<"fc"> feature is enabled or if it is
286L<C<fc>|/fc EXPR> is available only if the
265prefixed with C<CORE::>. The C<"fc"> feature is enabled automatically
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
266290with a C<use v5.16> (or higher) declaration in the current scope.
267291
268292=end original
269293
270C<fc> は C<"fc"> 機能が有効か C<CORE::> が前置されたときにのみ利用可能です。
294L<C<fc>|/fc EXPR> L<C<"fc"> 機能|feature/The 'fc' feature> が有効か
271C<"fc"> 機能は現在のスコープで C<use v5.16> (またはそれ以上) 宣言され
295C<CORE::> が前置されきにのみ利用可能です。
272自動的に有効になります。
296L<C<"fc"> 機能|feature/The 'fc' feature> は現在のスコープで
297C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。
273298
274299=item Regular expressions and pattern matching
275300X<regular expression> X<regex> X<regexp>
276301
277302(正規表現とパターンマッチング)
278303
279304=for Pod::Functions =Regexp
280305
281C<m//>, C<pos>, C<qr//>, C<quotemeta>, C<s///>, C<split>, C<study>
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>
282312
283313=item Numeric functions
284314X<numeric> X<number> X<trigonometric> X<trigonometry>
285315
286316(数値関数)
287317
288318=for Pod::Functions =Math
289319
290C<abs>, C<atan2>, C<cos>, C<exp>, C<hex>, C<int>, C<log>, C<oct>, C<rand>,
320L<C<abs>|/abs VALUE>, L<C<atan2>|/atan2 Y,X>, L<C<cos>|/cos EXPR>,
291C<sin>, C<sqrt>, C<srand>
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>
292324
293325=item Functions for real @ARRAYs
294326X<array>
295327
296328(実配列のための関数)
297329
298330=for Pod::Functions =ARRAY
299331
300C<each>, C<keys>, C<pop>, C<push>, C<shift>, C<splice>, C<unshift>, C<values>
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>
301336
302337=item Functions for list data
303338X<list>
304339
305340(リストデータのための関数)
306341
307342=for Pod::Functions =LIST
308343
309C<grep>, C<join>, C<map>, C<qw//>, C<reverse>, C<sort>, C<unpack>
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>
310348
311349=item Functions for real %HASHes
312350X<hash>
313351
314352(実ハッシュのための関数)
315353
316354=for Pod::Functions =HASH
317355
318C<delete>, C<each>, C<exists>, C<keys>, C<values>
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>
319359
320360=item Input and output functions
321361X<I/O> X<input> X<output> X<dbm>
322362
323363(入出力関数)
324364
325365=for Pod::Functions =I/O
326366
327C<binmode>, C<close>, C<closedir>, C<dbmclose>, C<dbmopen>, C<die>, C<eof>,
367L<C<binmode>|/binmode FILEHANDLE, LAYER>, L<C<close>|/close FILEHANDLE>,
328C<fileno>, C<flock>, C<format>, C<getc>, C<print>, C<printf>, C<read>,
368L<C<closedir>|/closedir DIRHANDLE>, L<C<dbmclose>|/dbmclose HASH>,
329C<readdir>, C<readline> C<rewinddir>, C<say>, C<seek>, C<seekdir>, C<select>,
369L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, L<C<die>|/die LIST>,
330C<syscall>, C<sysread>, C<sysseek>, C<syswrite>, C<tell>, C<telldir>,
370L<C<eof>|/eof FILEHANDLE>, L<C<fileno>|/fileno FILEHANDLE>,
331C<truncate>, C<warn>, C<write>
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>
332387
333388=begin original
334389
335C<say> is available only if the C<"say"> feature is enabled or if it is
390L<C<say>|/say FILEHANDLE LIST> is available only if the
336prefixed with C<CORE::>. The C<"say"> feature is enabled automatically
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
337394with a C<use v5.10> (or higher) declaration in the current scope.
338395
339396=end original
340397
341C<say> は C<"say"> 機能が有効か C<CORE::> が前置されたときにのみ利用可能です。
398L<C<say>|/say FILEHANDLE LIST>
342C<"say"> 機能は現在のスコープで C<use v5.10> (またはそれ以上)宣言されると
399L<C<"say"> 機能|feature/The 'say' feature> が有効か C<CORE::>
343自動的有効になります。
400前置されたときのみ利用可能です。
401L<C<"say"> 機能|feature/The 'say' feature> は現在のスコープで
402C<use v5.10> (またはそれ以上) が宣言されると自動的に有効になります。
344403
345404=item Functions for fixed-length data or records
346405
347406(固定長データやレコードのための関数)
348407
349408=for Pod::Functions =Binary
350409
351C<pack>, C<read>, C<syscall>, C<sysread>, C<sysseek>, C<syswrite>, C<unpack>,
410L<C<pack>|/pack TEMPLATE,LIST>,
352C<vec>
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>
353417
354418=item Functions for filehandles, files, or directories
355419X<file> X<filehandle> X<directory> X<pipe> X<link> X<symlink>
356420
357421(ファイルハンドル、ファイル、ディレクトリのための関数)
358422
359423=for Pod::Functions =File
360424
361C<-I<X>>, C<chdir>, C<chmod>, C<chown>, C<chroot>, C<fcntl>, C<glob>,
425L<C<-I<X>>|/-X FILEHANDLE>, L<C<chdir>|/chdir EXPR>,
362C<ioctl>, C<link>, C<lstat>, C<mkdir>, C<open>, C<opendir>,
426L<C<chmod>|/chmod LIST>, L<C<chown>|/chown LIST>,
363C<readlink>, C<rename>, C<rmdir>, C<stat>, C<symlink>, C<sysopen>,
427L<C<chroot>|/chroot FILENAME>,
364C<umask>, C<unlink>, C<utime>
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,MODE,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>
365439
366440=item Keywords related to the control flow of your Perl program
367441X<control flow>
368442
369443(プログラムの流れを制御することに関連するキーワード)
370444
371445=for Pod::Functions =Flow
372446
373C<break>, C<caller>, C<continue>, C<die>, C<do>,
447L<C<break>|/break>, L<C<caller>|/caller EXPR>,
374C<dump>, C<eval>, C<evalbytes> C<exit>,
448L<C<continue>|/continue BLOCK>, L<C<die>|/die LIST>, L<C<do>|/do BLOCK>,
375C<__FILE__>, C<goto>, C<last>, C<__LINE__>, C<next>, C<__PACKAGE__>,
449L<C<dump>|/dump LABEL>, L<C<eval>|/eval EXPR>,
376C<redo>, C<return>, C<sub>, C<__SUB__>, C<wantarray>
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<method>|/method NAME BLOCK>,
454L<C<next>|/next LABEL>, L<C<__PACKAGE__>|/__PACKAGE__>,
455L<C<redo>|/redo LABEL>, L<C<return>|/return EXPR>,
456L<C<sub>|/sub NAME BLOCK>, L<C<__SUB__>|/__SUB__>,
457L<C<wantarray>|/wantarray>
377458
378459=begin original
379460
380C<break> is available only if you enable the experimental C<"switch">
461L<C<break>|/break> is available only if you enable the experimental
381feature or use the C<CORE::> prefix. The C<"switch"> feature also enables
462L<C<"switch"> feature|feature/The 'switch' feature> or use the C<CORE::>
382the C<default>, C<given> and C<when> statements, which are documented in
463prefix. The L<C<"switch"> feature|feature/The 'switch' feature> also
383L<perlsyn/"Switch Statements">. The C<"switch"> feature is enabled
464enables the C<default>, C<given> and C<when> statements, which are
465documented in L<perlsyn/"Switch Statements">.
466The L<C<"switch"> feature|feature/The 'switch' feature> is enabled
384467automatically with a C<use v5.10> (or higher) declaration in the current
385scope. In Perl v5.14 and earlier, C<continue> required the C<"switch">
468scope. In Perl v5.14 and earlier, L<C<continue>|/continue BLOCK>
386feature, like the other keywords.
469required the L<C<"switch"> feature|feature/The 'switch' feature>, like
470the other keywords.
387471
388472=end original
389473
390C<break> は C<"switch"> 機能が有効か C<CORE::> 接頭辞を使ったときにのみ
474L<C<break>|/break> は、実験的な
391利用可です。
475L<C<"switch"> 機|feature/The 'switch' feature> が有効か C<CORE::> 接頭辞を
392C<"switch"> 機は L<perlsyn/"Switch Statements"> 文書化されている
476使ったときにのみ利用可能です。
477L<C<"switch"> 機能|feature/The 'switch' feature> は、
478L<perlsyn/"Switch Statements"> で文書化されている
393479C<default>, C<given>, C<when> 文も有効にします。
394C<"switch"> 機能は現在のスコープで C<use v5.10> (またはそれ以上) が
480L<C<"switch"> 機能|feature/The 'switch' feature> 現在のスコープで
395宣言されると自動的に有効になります。
481C<use v5.10> (またはそれ以上) 宣言があると自動的に有効になります。
396Perl v5.14 以前では、C<continue> は他のキーワードと同様に C<"switch"> 機能が
482Perl v5.14 以前では、L<C<continue>|/continue BLOCK> は他のキーワードと同様に
397必要です。
483L<C<"switch"> 機能|feature/The 'switch' feature> が必要です。
398484
399485=begin original
400486
401C<evalbytes> is only available with the C<"evalbytes"> feature (see
487L<C<evalbytes>|/evalbytes EXPR> is only available with the
402L<feature>) or if prefixed with C<CORE::>. C<__SUB__> is only available
488L<C<"evalbytes"> feature|feature/The 'unicode_eval' and 'evalbytes' features>
403with the C<"current_sub"> feature or if prefixed with C<CORE::>. Both
489(see L<feature>) or if prefixed with C<CORE::>. L<C<__SUB__>|/__SUB__>
404the C<"evalbytes"> and C<"current_sub"> features are enabled automatically
490is only available with the
405with a C<use v5.16> (or higher) declaration in the current scope.
491L<C<"current_sub"> feature|feature/The 'current_sub' feature> or if
492prefixed with C<CORE::>. Both the
493L<C<"evalbytes">|feature/The 'unicode_eval' and 'evalbytes' features>
494and L<C<"current_sub">|feature/The 'current_sub' feature> features are
495enabled automatically with a C<use v5.16> (or higher) declaration in the
496current scope.
406497
407498=end original
408499
409C<evalbytes> は C<"evalbytes"> 機能 (L<feature> 参照) が有効か C<CORE::>
500L<C<evalbytes>|/evalbytes EXPR>
410前置されたときにのみ利用可です。
501L<C<"evalbytes"> 機|feature/The 'unicode_eval' and 'evalbytes' features>
411C<__SUB__> は C<"current_sub"> 機能が有効か C<CORE::> が前置されたときにのみ
502(L<feature> 参照) が有効か C<CORE::> が前置されたときにのみ利用可能です。
412利用可能です。
503L<C<__SUB__>|/__SUB__> は
413C<"evalbytes"> C<"current_sub"> の両方の機能は現在のスコープで
504L<C<"current_sub"> 機能|feature/The 'current_sub' feature> が有効か
505C<CORE::> が前置されたときにのみ利用可能です。
506L<C<"evalbytes">|feature/The 'unicode_eval' and 'evalbytes' features> と
507L<C<"current_sub">|feature/The 'current_sub' feature> の両方の機能は
508現在のスコープで
414509C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。
415510
416511=item Keywords related to scoping
417512
418513(スコープに関するキーワード)
419514
420515=for Pod::Functions =Namespace
421516
422C<caller>, C<import>, C<local>, C<my>, C<our>, C<package>, C<state>, C<use>
517L<C<caller>|/caller EXPR>,
518L<C<class>|/class NAMESPACE>,
519L<C<field>|/field VARNAME>,
520L<C<import>|/import LIST>,
521L<C<local>|/local EXPR>,
522L<C<my>|/my VARLIST>,
523L<C<our>|/our VARLIST>,
524L<C<package>|/package NAMESPACE>,
525L<C<state>|/state VARLIST>,
526L<C<use>|/use Module VERSION LIST>
423527
424528=begin original
425529
426C<state> is available only if the C<"state"> feature is enabled or if it is
530L<C<state>|/state VARLIST> is available only if the
427prefixed with C<CORE::>. The C<"state"> feature is enabled automatically
531L<C<"state"> feature|feature/The 'state' feature> is enabled or if it is
428with a C<use v5.10> (or higher) declaration in the current scope.
532prefixed with C<CORE::>. The
533L<C<"state"> feature|feature/The 'state' feature> is enabled
534automatically with a C<use v5.10> (or higher) declaration in the current
535scope.
429536
430537=end original
431538
432C<state> は C<"state"> 機能が有効か C<CORE::> を前置した場合にのみ
539L<C<state>|/state VARLIST>
433利用可です。
540L<C<"state"> 機|feature/The 'state' feature> が有効か C<CORE::> を
434C<"state"> 機能は現在のスコープで C<use v5.10> (またはそれ以上) を宣言した
541前置した場合にのみ利用可能です。
435場合自動的に有効になります。
542L<C<"state"> 機能|feature/The 'state' feature> は現在のスコープで
543C<use v5.10> (またはそれ以上) を宣言した場合自動的に有効になります。
436544
437545=item Miscellaneous functions
438546
439547(さまざまな関数)
440548
441549=for Pod::Functions =Misc
442550
443C<defined>, C<formline>, C<lock>, C<prototype>, C<reset>, C<scalar>, C<undef>
551L<C<defined>|/defined EXPR>, L<C<formline>|/formline PICTURE,LIST>,
552L<C<lock>|/lock THING>, L<C<prototype>|/prototype FUNCTION>,
553L<C<reset>|/reset EXPR>, L<C<scalar>|/scalar EXPR>,
554L<C<undef>|/undef EXPR>
444555
445556=item Functions for processes and process groups
446557X<process> X<pid> X<process id>
447558
448559(プロセスとプロセスグループのための関数)
449560
450561=for Pod::Functions =Process
451562
452C<alarm>, C<exec>, C<fork>, C<getpgrp>, C<getppid>, C<getpriority>, C<kill>,
563L<C<alarm>|/alarm SECONDS>, L<C<exec>|/exec LIST>, L<C<fork>|/fork>,
453C<pipe>, C<qx//>, C<readpipe>, C<setpgrp>,
564L<C<getpgrp>|/getpgrp PID>, L<C<getppid>|/getppid>,
454C<setpriority>, C<sleep>, C<system>,
565L<C<getpriority>|/getpriority WHICH,WHO>, L<C<kill>|/kill SIGNAL, LIST>,
455C<times>, C<wait>, C<waitpid>
566L<C<pipe>|/pipe READHANDLE,WRITEHANDLE>,
567L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>>,
568L<C<readpipe>|/readpipe EXPR>, L<C<setpgrp>|/setpgrp PID,PGRP>,
569L<C<setpriority>|/setpriority WHICH,WHO,PRIORITY>,
570L<C<sleep>|/sleep EXPR>, L<C<system>|/system LIST>, L<C<times>|/times>,
571L<C<wait>|/wait>, L<C<waitpid>|/waitpid PID,FLAGS>
456572
457573=item Keywords related to Perl modules
458574X<module>
459575
460576(Perl モジュールに関するキーワード)
461577
462578=for Pod::Functions =Modules
463579
464C<do>, C<import>, C<no>, C<package>, C<require>, C<use>
580L<C<do>|/do EXPR>, L<C<import>|/import LIST>,
581L<C<no>|/no MODULE VERSION LIST>, L<C<package>|/package NAMESPACE>,
582L<C<require>|/require VERSION>, L<C<use>|/use Module VERSION LIST>
465583
466584=item Keywords related to classes and object-orientation
467585X<object> X<class> X<package>
468586
469587(クラスとオブジェクト指向に関するキーワード)
470588
471589=for Pod::Functions =Objects
472590
473C<bless>, C<dbmclose>, C<dbmopen>, C<package>, C<ref>, C<tie>, C<tied>,
591L<C<bless>|/bless REF,CLASSNAME>,
474C<untie>, C<use>
592L<C<class>|/class NAMESPACE>,
593L<C<dbmclose>|/dbmclose HASH>,
594L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>,
595L<C<field>|/field VARNAME>,
596L<C<method>|/method NAME BLOCK>,
597L<C<package>|/package NAMESPACE>,
598L<C<ref>|/ref EXPR>,
599L<C<tie>|/tie VARIABLE,CLASSNAME,LIST>,
600L<C<tied>|/tied VARIABLE>,
601L<C<untie>|/untie VARIABLE>,
602L<C<use>|/use Module VERSION LIST>
475603
476604=item Low-level socket functions
477605X<socket> X<sock>
478606
479607(低レベルソケット関数)
480608
481609=for Pod::Functions =Socket
482610
483C<accept>, C<bind>, C<connect>, C<getpeername>, C<getsockname>,
611L<C<accept>|/accept NEWSOCKET,GENERICSOCKET>,
484C<getsockopt>, C<listen>, C<recv>, C<send>, C<setsockopt>, C<shutdown>,
612L<C<bind>|/bind SOCKET,NAME>, L<C<connect>|/connect SOCKET,NAME>,
485C<socket>, C<socketpair>
613L<C<getpeername>|/getpeername SOCKET>,
614L<C<getsockname>|/getsockname SOCKET>,
615L<C<getsockopt>|/getsockopt SOCKET,LEVEL,OPTNAME>,
616L<C<listen>|/listen SOCKET,QUEUESIZE>,
617L<C<recv>|/recv SOCKET,SCALAR,LENGTH,FLAGS>,
618L<C<send>|/send SOCKET,MSG,FLAGS,TO>,
619L<C<setsockopt>|/setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL>,
620L<C<shutdown>|/shutdown SOCKET,HOW>,
621L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL>,
622L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL>
486623
487624=item System V interprocess communication functions
488625X<IPC> X<System V> X<semaphore> X<shared memory> X<memory> X<message>
489626
490627(System V プロセス間通信関数)
491628
492629=for Pod::Functions =SysV
493630
494C<msgctl>, C<msgget>, C<msgrcv>, C<msgsnd>, C<semctl>, C<semget>, C<semop>,
631L<C<msgctl>|/msgctl ID,CMD,ARG>, L<C<msgget>|/msgget KEY,FLAGS>,
495C<shmctl>, C<shmget>, C<shmread>, C<shmwrite>
632L<C<msgrcv>|/msgrcv ID,VAR,SIZE,TYPE,FLAGS>,
633L<C<msgsnd>|/msgsnd ID,MSG,FLAGS>,
634L<C<semctl>|/semctl ID,SEMNUM,CMD,ARG>,
635L<C<semget>|/semget KEY,NSEMS,FLAGS>, L<C<semop>|/semop KEY,OPSTRING>,
636L<C<shmctl>|/shmctl ID,CMD,ARG>, L<C<shmget>|/shmget KEY,SIZE,FLAGS>,
637L<C<shmread>|/shmread ID,VAR,POS,SIZE>,
638L<C<shmwrite>|/shmwrite ID,STRING,POS,SIZE>
496639
497640=item Fetching user and group info
498641X<user> X<group> X<password> X<uid> X<gid> X<passwd> X</etc/passwd>
499642
500643(ユーザーとグループの情報取得)
501644
502645=for Pod::Functions =User
503646
504C<endgrent>, C<endhostent>, C<endnetent>, C<endpwent>, C<getgrent>,
647L<C<endgrent>|/endgrent>, L<C<endhostent>|/endhostent>,
505C<getgrgid>, C<getgrnam>, C<getlogin>, C<getpwent>, C<getpwnam>,
648L<C<endnetent>|/endnetent>, L<C<endpwent>|/endpwent>,
506C<getpwuid>, C<setgrent>, C<setpwent>
649L<C<getgrent>|/getgrent>, L<C<getgrgid>|/getgrgid GID>,
650L<C<getgrnam>|/getgrnam NAME>, L<C<getlogin>|/getlogin>,
651L<C<getpwent>|/getpwent>, L<C<getpwnam>|/getpwnam NAME>,
652L<C<getpwuid>|/getpwuid UID>, L<C<setgrent>|/setgrent>,
653L<C<setpwent>|/setpwent>
507654
508655=item Fetching network info
509656X<network> X<protocol> X<host> X<hostname> X<IP> X<address> X<service>
510657
511658(ネットワーク情報取得)
512659
513660=for Pod::Functions =Network
514661
515C<endprotoent>, C<endservent>, C<gethostbyaddr>, C<gethostbyname>,
662L<C<endprotoent>|/endprotoent>, L<C<endservent>|/endservent>,
516C<gethostent>, C<getnetbyaddr>, C<getnetbyname>, C<getnetent>,
663L<C<gethostbyaddr>|/gethostbyaddr ADDR,ADDRTYPE>,
517C<getprotobyname>, C<getprotobynumber>, C<getprotoent>,
664L<C<gethostbyname>|/gethostbyname NAME>, L<C<gethostent>|/gethostent>,
518C<getservbyname>, C<getservbyport>, C<getservent>, C<sethostent>,
665L<C<getnetbyaddr>|/getnetbyaddr ADDR,ADDRTYPE>,
519C<setnetent>, C<setprotoent>, C<setservent>
666L<C<getnetbyname>|/getnetbyname NAME>, L<C<getnetent>|/getnetent>,
667L<C<getprotobyname>|/getprotobyname NAME>,
668L<C<getprotobynumber>|/getprotobynumber NUMBER>,
669L<C<getprotoent>|/getprotoent>,
670L<C<getservbyname>|/getservbyname NAME,PROTO>,
671L<C<getservbyport>|/getservbyport PORT,PROTO>,
672L<C<getservent>|/getservent>, L<C<sethostent>|/sethostent STAYOPEN>,
673L<C<setnetent>|/setnetent STAYOPEN>,
674L<C<setprotoent>|/setprotoent STAYOPEN>,
675L<C<setservent>|/setservent STAYOPEN>
520676
521677=item Time-related functions
522678X<time> X<date>
523679
524680(時刻に関する関数)
525681
526682=for Pod::Functions =Time
527683
528C<gmtime>, C<localtime>, C<time>, C<times>
684L<C<gmtime>|/gmtime EXPR>, L<C<localtime>|/localtime EXPR>,
685L<C<time>|/time>, L<C<times>|/times>
529686
530687=item Non-function keywords
531688
532689=for Pod::Functions =!Non-functions
533690
534C<and>, C<AUTOLOAD>, C<BEGIN>, C<CHECK>, C<cmp>, C<CORE>, C<__DATA__>,
691C<ADJUST>,
535C<default>, C<DESTROY>, C<else>, C<elseif>, C<elsif>, C<END>, C<__END__>,
692C<and>,
536C<eq>, C<for>, C<foreach>, C<ge>, C<given>, C<gt>, C<if>, C<INIT>, C<le>,
693C<AUTOLOAD>,
537C<lt>, C<ne>, C<not>, C<or>, C<UNITCHECK>, C<unless>, C<until>, C<when>,
694C<BEGIN>,
538C<while>, C<x>, C<xor>
695C<catch>,
696C<CHECK>,
697C<cmp>,
698C<CORE>,
699C<__DATA__>,
700C<default>,
701C<defer>,
702C<DESTROY>,
703C<else>,
704C<elseif>,
705C<elsif>,
706C<END>,
707C<__END__>,
708C<eq>,
709C<finally>,
710C<for>,
711C<foreach>,
712C<ge>,
713C<given>,
714C<gt>,
715C<if>,
716C<INIT>,
717C<isa>,
718C<le>,
719C<lt>,
720C<ne>,
721C<not>,
722C<or>,
723C<try>,
724C<UNITCHECK>,
725C<unless>,
726C<until>,
727C<when>,
728C<while>,
729C<x>,
730C<xor>
539731
540732=back
541733
542734=head2 Portability
543735X<portability> X<Unix> X<portable>
544736
545737(移植性)
546738
547739=begin original
548740
549741Perl was born in Unix and can therefore access all common Unix
550742system calls. In non-Unix environments, the functionality of some
551743Unix system calls may not be available or details of the available
552744functionality may differ slightly. The Perl functions affected
553745by this are:
554746
555747=end original
556748
557749Perl は Unix 環境で生まれたので、全ての共通する Unix システムコールに
558750アクセスします。
559751非 Unix 環境では、いくつかの Unix システムコールの機能が使えなかったり、
560752使える機能の詳細が多少異なったりします。
561753これによる影響を受ける Perl 関数は以下のものです:
562754
563C<-X>, C<binmode>, C<chmod>, C<chown>, C<chroot>, C<crypt>,
755L<C<-I<X>>|/-X FILEHANDLE>, L<C<binmode>|/binmode FILEHANDLE, LAYER>,
564C<dbmclose>, C<dbmopen>, C<dump>, C<endgrent>, C<endhostent>,
756L<C<chmod>|/chmod LIST>, L<C<chown>|/chown LIST>,
565C<endnetent>, C<endprotoent>, C<endpwent>, C<endservent>, C<exec>,
757L<C<chroot>|/chroot FILENAME>, L<C<crypt>|/crypt PLAINTEXT,SALT>,
566C<fcntl>, C<flock>, C<fork>, C<getgrent>, C<getgrgid>, C<gethostbyname>,
758L<C<dbmclose>|/dbmclose HASH>, L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>,
567C<gethostent>, C<getlogin>, C<getnetbyaddr>, C<getnetbyname>, C<getnetent>,
759L<C<dump>|/dump LABEL>, L<C<endgrent>|/endgrent>,
568C<getppid>, C<getpgrp>, C<getpriority>, C<getprotobynumber>,
760L<C<endhostent>|/endhostent>, L<C<endnetent>|/endnetent>,
569C<getprotoent>, C<getpwent>, C<getpwnam>, C<getpwuid>,
761L<C<endprotoent>|/endprotoent>, L<C<endpwent>|/endpwent>,
570C<getservbyport>, C<getservent>, C<getsockopt>, C<glob>, C<ioctl>,
762L<C<endservent>|/endservent>, L<C<exec>|/exec LIST>,
571C<kill>, C<link>, C<lstat>, C<msgctl>, C<msgget>, C<msgrcv>,
763L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>,
572C<msgsnd>, C<open>, C<pipe>, C<readlink>, C<rename>, C<select>, C<semctl>,
764L<C<flock>|/flock FILEHANDLE,OPERATION>, L<C<fork>|/fork>,
573C<semget>, C<semop>, C<setgrent>, C<sethostent>, C<setnetent>,
765L<C<getgrent>|/getgrent>, L<C<getgrgid>|/getgrgid GID>,
574C<setpgrp>, C<setpriority>, C<setprotoent>, C<setpwent>,
766L<C<gethostbyname>|/gethostbyname NAME>, L<C<gethostent>|/gethostent>,
575C<setservent>, C<setsockopt>, C<shmctl>, C<shmget>, C<shmread>,
767L<C<getlogin>|/getlogin>,
576C<shmwrite>, C<socket>, C<socketpair>,
768L<C<getnetbyaddr>|/getnetbyaddr ADDR,ADDRTYPE>,
577C<stat>, C<symlink>, C<syscall>, C<sysopen>, C<system>,
769L<C<getnetbyname>|/getnetbyname NAME>, L<C<getnetent>|/getnetent>,
578C<times>, C<truncate>, C<umask>, C<unlink>,
770L<C<getppid>|/getppid>, L<C<getpgrp>|/getpgrp PID>,
579C<utime>, C<wait>, C<waitpid>
771L<C<getpriority>|/getpriority WHICH,WHO>,
772L<C<getprotobynumber>|/getprotobynumber NUMBER>,
773L<C<getprotoent>|/getprotoent>, L<C<getpwent>|/getpwent>,
774L<C<getpwnam>|/getpwnam NAME>, L<C<getpwuid>|/getpwuid UID>,
775L<C<getservbyport>|/getservbyport PORT,PROTO>,
776L<C<getservent>|/getservent>,
777L<C<getsockopt>|/getsockopt SOCKET,LEVEL,OPTNAME>,
778L<C<glob>|/glob EXPR>, L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>,
779L<C<kill>|/kill SIGNAL, LIST>, L<C<link>|/link OLDFILE,NEWFILE>,
780L<C<lstat>|/lstat FILEHANDLE>, L<C<msgctl>|/msgctl ID,CMD,ARG>,
781L<C<msgget>|/msgget KEY,FLAGS>,
782L<C<msgrcv>|/msgrcv ID,VAR,SIZE,TYPE,FLAGS>,
783L<C<msgsnd>|/msgsnd ID,MSG,FLAGS>, L<C<open>|/open FILEHANDLE,MODE,EXPR>,
784L<C<pipe>|/pipe READHANDLE,WRITEHANDLE>, L<C<readlink>|/readlink EXPR>,
785L<C<rename>|/rename OLDNAME,NEWNAME>,
786L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>,
787L<C<semctl>|/semctl ID,SEMNUM,CMD,ARG>,
788L<C<semget>|/semget KEY,NSEMS,FLAGS>, L<C<semop>|/semop KEY,OPSTRING>,
789L<C<setgrent>|/setgrent>, L<C<sethostent>|/sethostent STAYOPEN>,
790L<C<setnetent>|/setnetent STAYOPEN>, L<C<setpgrp>|/setpgrp PID,PGRP>,
791L<C<setpriority>|/setpriority WHICH,WHO,PRIORITY>,
792L<C<setprotoent>|/setprotoent STAYOPEN>, L<C<setpwent>|/setpwent>,
793L<C<setservent>|/setservent STAYOPEN>,
794L<C<setsockopt>|/setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL>,
795L<C<shmctl>|/shmctl ID,CMD,ARG>, L<C<shmget>|/shmget KEY,SIZE,FLAGS>,
796L<C<shmread>|/shmread ID,VAR,POS,SIZE>,
797L<C<shmwrite>|/shmwrite ID,STRING,POS,SIZE>,
798L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL>,
799L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL>,
800L<C<stat>|/stat FILEHANDLE>, L<C<symlink>|/symlink OLDFILE,NEWFILE>,
801L<C<syscall>|/syscall NUMBER, LIST>,
802L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>,
803L<C<system>|/system LIST>, L<C<times>|/times>,
804L<C<truncate>|/truncate FILEHANDLE,LENGTH>, L<C<umask>|/umask EXPR>,
805L<C<unlink>|/unlink LIST>, L<C<utime>|/utime LIST>, L<C<wait>|/wait>,
806L<C<waitpid>|/waitpid PID,FLAGS>
580807
581808=begin original
582809
583810For more information about the portability of these functions, see
584811L<perlport> and other available platform-specific documentation.
585812
586813=end original
587814
588815これらの関数の移植性に関するさらなる情報については、
589816L<perlport> とその他のプラットホーム固有のドキュメントを参照してください。
590817
591818=head2 Alphabetical Listing of Perl Functions
592819
593=over
820=over
594821
595822=item -X FILEHANDLE
596823X<-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>
597824X<-S>X<-b>X<-c>X<-t>X<-u>X<-g>X<-k>X<-T>X<-B>X<-M>X<-A>X<-C>
598825
599826=item -X EXPR
600827
601828=item -X DIRHANDLE
602829
603830=item -X
604831
605832=for Pod::Functions a file test (-r, -x, etc)
606833
607834=begin original
608835
609836A file test, where X is one of the letters listed below. This unary
610operator takes one argument, either a filename, a filehandle, or a dirhandle,
837operator takes one argument, either a filename, a filehandle, or a dirhandle,
611838and tests the associated file to see if something is true about it. If the
612argument is omitted, tests C<$_>, except for C<-t>, which tests STDIN.
839argument is omitted, tests L<C<$_>|perlvar/$_>, except for C<-t>, which
613Unless otherwise documented, it returns C<1> for true and C<''> for false, or
840tests STDIN. Unless otherwise documented, it returns C<1> for true and
614the undefined value if the file doesn't exist. Despite the funny
841C<''> for false. If the file doesn't exist or can't be examined, it
615names, precedence is the same as any other named unary operator. The
842returns L<C<undef>|/undef EXPR> and sets L<C<$!>|perlvar/$!> (errno).
616operator may be any of:
843With the exception of the C<-l> test they all follow symbolic links
844because they use C<stat()> and not C<lstat()> (so dangling symlinks can't
845be examined and will therefore report failure).
617846
618847=end original
619848
620849X は以下にあげる文字で、ファイルテストを行ないます。
621この単項演算子は、ファイル名かファイルハンドルを唯一の
850この単項演算子は、ファイル名かファイルハンドルを唯一の引数として動作し、
622引数として動作し、「あること」について真であるか否かを
851「あること」について真であるか否かを判定した結果を返します。
623判定した結果返します
852引数が省略されると、C<-t> では STDIN 調べますが、その他は
624引数が省略されると、C<-t> では STDIN を調べますが、その他は C<$_> を調べます。
853L<C<$_>|perlvar/$_> を調べます。
625特に記述されていなければ、真として C<1> を返し、偽として
854特に記述されていなければ、真として C<1> を返し、偽として C<''> を返します。
626C<''> を返し、ファイルが存在しなければ、未定義値を返します。
855ファイルが存在しないか、テスト出来なければ、L<C<undef>|/undef EXPR> を返し
856L<C<$!>|perlvar/$!> (errno) を設定します。
857C<-l> テストを例外として、これら全てはシンボリックリンクに従います;
858C<lstat()> ではなく C<stat()> を使っているからです
859(従って壊れたシンボリックリンクは検査されず、失敗が報告されます)。
860
861=begin original
862
863Despite the funny names, precedence is the same as any other named unary
864operator. The operator may be any of:
865
866=end original
867
627868みかけは変わっていますが、優先順位は名前付き単項演算子と同じで、
628869他の単項演算子と同じく、引数を括弧で括ることもできます。
629870演算子には以下のものがあります:
630871
631872=begin original
632873
633874 -r File is readable by effective uid/gid.
634875 -w File is writable by effective uid/gid.
635876 -x File is executable by effective uid/gid.
636877 -o File is owned by effective uid.
637878
638879=end original
639880
640881 -r ファイルが実効 uid/gid で読み出し可。
641882 -w ファイルが実効 uid/gid で書き込み可。
642883 -x ファイルが実効 uid/gid で実行可。
643884 -o ファイルが実効 uid の所有物。
644885
645886=begin original
646887
647888 -R File is readable by real uid/gid.
648889 -W File is writable by real uid/gid.
649890 -X File is executable by real uid/gid.
650891 -O File is owned by real uid.
651892
652893=end original
653894
654895 -R ファイルが実 uid/gid で読み出し可。
655896 -W ファイルが実 uid/gid で書き込み可。
656897 -X ファイルが実 uid/gid で実行可。
657898 -O ファイルが実 uid の所有物。
658899
659900=begin original
660901
661902 -e File exists.
662903 -z File has zero size (is empty).
663904 -s File has nonzero size (returns size in bytes).
664905
665906=end original
666907
667908 -e ファイルが存在する。
668909 -z ファイルの大きさがゼロ(空)。
669910 -s ファイルの大きさがゼロ以外 (バイト単位での大きさを返す)。
670911
671912=begin original
672913
673914 -f File is a plain file.
674915 -d File is a directory.
675 -l File is a symbolic link.
916 -l File is a symbolic link (false if symlinks aren't
917 supported by the file system).
676918 -p File is a named pipe (FIFO), or Filehandle is a pipe.
677919 -S File is a socket.
678920 -b File is a block special file.
679921 -c File is a character special file.
680922 -t Filehandle is opened to a tty.
681923
682924=end original
683925
684926 -f ファイルは通常ファイル。
685927 -d ファイルはディレクトリ。
686 -l ファイルはシンボリックリンク。
928 -l ファイルはシンボリックリンク(ファイルシステムが非対応なら偽)
687929 -p ファイルは名前付きパイプ (FIFO) またはファイルハンドルはパイプ。
688930 -S ファイルはソケット。
689931 -b ファイルはブロック特殊ファイル。
690932 -c ファイルはキャラクタ特殊ファイル。
691933 -t ファイルハンドルは tty にオープンされている。
692934
693935=begin original
694936
695937 -u File has setuid bit set.
696938 -g File has setgid bit set.
697939 -k File has sticky bit set.
698940
699941=end original
700942
701943 -u ファイルの setuid ビットがセットされている。
702944 -g ファイルの setgid ビットがセットされている。
703945 -k ファイルの sticky ビットがセットされている。
704946
705947=begin original
706948
707 -T File is an ASCII text file (heuristic guess).
949 -T File is an ASCII or UTF-8 text file (heuristic guess).
708950 -B File is a "binary" file (opposite of -T).
709951
710952=end original
711953
712 -T ファイルは ASCII テキストファイル (発見的に推測します)。
954 -T ファイルは ASCII または UTF-8 テキストファイル (発見的に推測します)。
713955 -B ファイルは「バイナリ」ファイル (-T の反対)。
714956
715957=begin original
716958
717959 -M Script start time minus file modification time, in days.
718960 -A Same for access time.
719961 -C Same for inode change time (Unix, may differ for other
720962 platforms)
721963
722964=end original
723965
724966 -M スクリプト実行開始時刻からファイル修正時刻を引いたもの(日単位)。
725967 -A 同様にアクセスがあってからの日数。
726968 -C 同様に(Unix では) inode が変更されてからの日数(それ以外の
727969 プラットフォームでは違うかもしれません)。
728970
729971=begin original
730972
731973Example:
732974
733975=end original
734976
735977例:
736978
737979 while (<>) {
738980 chomp;
739981 next unless -f $_; # ignore specials
740982 #...
741983 }
742984
743985=begin original
744986
745987Note that C<-s/a/b/> does not do a negated substitution. Saying
746988C<-exp($foo)> still works as expected, however: only single letters
747989following a minus are interpreted as file tests.
748990
749991=end original
750992
751993C<-s/a/b> は、置換演算 (s///) の符号反転ではありません。
752994しかし、C<-exp($foo)> は期待どおりに動作します; しかし、マイナス記号の後に
753995英字が 1 字続くときにのみ、ファイルテストと解釈されます。
754996
755997=begin original
756998
757999These operators are exempt from the "looks like a function rule" described
7581000above. That is, an opening parenthesis after the operator does not affect
7591001how much of the following code constitutes the argument. Put the opening
7601002parentheses before the operator to separate it from code that follows (this
7611003applies only to operators with higher precedence than unary operators, of
7621004course):
7631005
7641006=end original
7651007
7661008これらの演算子は上述の「関数のように見えるルール」から免除されます。
7671009つまり、演算子の後の開きかっこは、引き続くコードのどこまでが引数を
7681010構成するかに影響を与えません。
7691011演算子を引き続くコードから分離するには、演算子の前に開きかっこを
7701012置いてください (これはもちろん、単項演算子より高い優先順位を持つ
7711013演算子にのみ適用されます):
7721014
7731015 -s($file) + 1024 # probably wrong; same as -s($file + 1024)
7741016 (-s $file) + 1024 # correct
7751017
7761018=begin original
7771019
7781020The interpretation of the file permission operators C<-r>, C<-R>,
7791021C<-w>, C<-W>, C<-x>, and C<-X> is by default based solely on the mode
7801022of the file and the uids and gids of the user. There may be other
7811023reasons you can't actually read, write, or execute the file: for
7821024example network filesystem access controls, ACLs (access control lists),
7831025read-only filesystems, and unrecognized executable formats. Note
7841026that the use of these six specific operators to verify if some operation
7851027is possible is usually a mistake, because it may be open to race
7861028conditions.
7871029
7881030=end original
7891031
7901032ファイルのパーミッション演算子 C<-r>, C<-R>, C<-w>, C<-W>, C<-x>,
7911033C<-X> の解釈は、ファイルのモードとユーザの実効/実 uid と
7921034実効/実 gid のみから判断されます。
7931035実際にファイルが読めたり、書けたり、実行できたりするためには、
7941036別の条件が必要かもしれません:
7951037例えば、ネットワークファイルシステムアクセスコントロール、
7961038ACL(アクセスコントロールリスト)、読み込み専用ファイルシステム、
7971039認識できない実行ファイルフォーマット、などです。
7981040これらの 6 つの演算子を、特定の操作が可能かどうかを確認するために使うのは
7991041通常は誤りであることに注意してください; なぜなら、これらは競合条件を
8001042招きやすいからです。
8011043
8021044=begin original
8031045
8041046Also note that, for the superuser on the local filesystems, the C<-r>,
8051047C<-R>, C<-w>, and C<-W> tests always return 1, and C<-x> and C<-X> return 1
8061048if any execute bit is set in the mode. Scripts run by the superuser
807may thus need to do a stat() to determine the actual mode of the file,
1049may thus need to do a L<C<stat>|/stat FILEHANDLE> to determine the
808or temporarily set their effective uid to something else.
1050actual mode of the file, or temporarily set their effective uid to
1051something else.
8091052
8101053=end original
8111054
8121055ローカルファイルシステムのスーパーユーザには、
8131056C<-r>, C<-R>, C<-w>, C<-W> に対して、常に 1 が返り、モード中の
8141057いずれかの実行許可ビットが立っていれば、C<-x>, C<-X> にも 1 が
8151058返ることにも注意してください。
8161059スーパーユーザが実行するスクリプトでは、ファイルのモードを調べるためには、
817stat() を行なうか、実効 uid を一時的に別のものにする
1060L<C<stat>|/stat FILEHANDLE> を行なうか、実効 uid を一時的に別のものにする
8181061必要があるでしょう。
8191062
8201063=begin original
8211064
822If you are using ACLs, there is a pragma called C<filetest> that may
1065If you are using ACLs, there is a pragma called L<C<filetest>|filetest>
823produce more accurate results than the bare stat() mode bits.
1066that may produce more accurate results than the bare
824When under C<use filetest 'access'> the above-mentioned filetests
1067L<C<stat>|/stat FILEHANDLE> mode bits.
825test whether the permission can(not) be granted using the
1068When under C<use filetest 'access'>, the above-mentioned filetests
826access(2) family of system calls. Also note that the C<-x> and C<-X> may
1069test whether the permission can(not) be granted using the L<access(2)>
1070family of system calls. Also note that the C<-x> and C<-X> tests may
8271071under this pragma return true even if there are no execute permission
8281072bits set (nor any extra execute permission ACLs). This strangeness is
8291073due to the underlying system calls' definitions. Note also that, due to
8301074the implementation of C<use filetest 'access'>, the C<_> special
8311075filehandle won't cache the results of the file tests when this pragma is
832in effect. Read the documentation for the C<filetest> pragma for more
1076in effect. Read the documentation for the L<C<filetest>|filetest>
833information.
1077pragma for more information.
8341078
8351079=end original
8361080
837ACL を使っている場合は、生の stat() モードビットより
1081ACL を使っている場合は、生の L<C<stat>|/stat FILEHANDLE> モードビットより
838精度の高い結果を作成する C<filetest> プラグマがあります。
1082精度の高い結果を作成する L<C<filetest>|filetest> プラグマがあります。
8391083C<use filetest 'access'> とした場合、上述したファイルテストは
840システムコールの access(2) ファミリーを使って権限が与えられているか
1084システムコールの L<access(2)> ファミリーを使って権限が与えられているか
8411085どうかをテストします。
842また、このプラグマが指定されている場合、C<-x> と C<-X> は
1086また、このプラグマが指定されている場合、C<-x> と C<-X> テスト
8431087たとえ実行許可ビット(または追加の実行許可 ACL)がセットされていない
8441088場合でも真を返すことに注意してください。
8451089この挙動は使用するシステムコールの定義によるものです。
8461090C<use filetest 'access'> の実装により、このプラグマが有効の場合は
8471091C<_> 特殊ファイルハンドルはファイルテストの結果をキャッシュしないことに
8481092注意してください。
849さらなる情報については C<filetest> プラグマのドキュメントを
1093さらなる情報については L<C<filetest>|filetest> プラグマのドキュメントを
8501094参照してください。
8511095
8521096=begin original
8531097
854The C<-T> and C<-B> switches work as follows. The first block or so of the
1098The C<-T> and C<-B> tests work as follows. The first block or so of
855file is examined for odd characters such as strange control codes or
1099the file is examined to see if it is valid UTF-8 that includes non-ASCII
856characters with the high bit set. If too many strange characters (>30%)
1100characters. If so, it's a C<-T> file. Otherwise, that same portion of
857are found, it's a C<-B> file; otherwise it's a C<-T> file. Also, any file
1101the file is examined for odd characters such as strange control codes or
858containing a zero byte in the first block is considered a binary file. If C<-T>
1102characters with the high bit set. If more than a third of the
859or C<-B> is used on a filehandle, the current IO buffer is examined
1103characters are strange, it's a C<-B> file; otherwise it's a C<-T> file.
1104Also, any file containing a zero byte in the examined portion is
1105considered a binary file. (If executed within the scope of a L<S<use
1106locale>|perllocale> which includes C<LC_CTYPE>, odd characters are
1107anything that isn't a printable nor space in the current locale.) If
1108C<-T> or C<-B> is used on a filehandle, the current IO buffer is
1109examined
8601110rather than the first block. Both C<-T> and C<-B> return true on an empty
8611111file, or a file at EOF when testing a filehandle. Because you have to
8621112read a file to do the C<-T> test, on most occasions you want to use a C<-f>
8631113against the file first, as in C<next unless -f $file && -T $file>.
8641114
8651115=end original
8661116
8671117ファイルテスト C<-T> と C<-B> の動作原理は、次のようになっています。
868ファイルの最初の数ブロックを調べて、変わった制御コードや
1118ファイルの最初の数ブロックを調べて、非 ASCII 文字を含む妥当な UTF-8 かどうかを
1119調べます。
1120もしそうなら、それは C<-T> ファイルです。
1121さもなければ、ファイルの同じ位置から、変わった制御コードや
8691122上位ビットがセットされているような、通常のテキストには現れない文字を探します。
870ような文字たくさん (>30%) 見つかるようあれば、
1123三分一以上がおかしな文字ならそれは C<-B> ファイルです;
871そのファイルは C<-B> ファイルであると判断されま;
1124さもなければ C<-T> ファイルです
872さもなけば C<-T> ファイルとなります。
1125また、調べた位置にヌル文字が含まファイルも、バイナリファイル
873最初のブロックにヌル文字が含まるファイルも、
1126みなさます。
874バイナリファイルとみなされます。
1127(C<LC_CTYPE> を含む L<S<use locale>|perllocale> のスコープの中で実行されると、
1128おかしな文字というのは現在のロケールで表示可能でもスペースでもないものです。)
8751129C<-T> や C<-B> をファイルハンドルに対して用いると、
8761130最初のブロックを調べる代わりに、IO バッファを調べます。
8771131調べたファイルの中身が何もないときや、
8781132ファイルハンドルを調べたときに EOF に達して
8791133いたときには、C<-T> も C<-B> も「真」を返します。
8801134C<-T> テストをするためにはファイルを読み込まないといけないので、
8811135たいていは C<next unless -f $file && -T $file> というような形で
8821136まず調べたいファイルに対して C<-f> を使いたいはずです。
8831137
8841138=begin original
8851139
886If any of the file tests (or either the C<stat> or C<lstat> operator) is given
1140If any of the file tests (or either the L<C<stat>|/stat FILEHANDLE> or
887the special filehandle consisting of a solitary underline, then the stat
1141L<C<lstat>|/lstat FILEHANDLE> operator) is given the special filehandle
888structure of the previous file test (or stat operator) is used, saving
1142consisting of a solitary underline, then the stat structure of the
889a system call. (This doesn't work with C<-t>, and you need to remember
1143previous file test (or L<C<stat>|/stat FILEHANDLE> operator) is used,
890that lstat() and C<-l> leave values in the stat structure for the
1144saving a system call. (This doesn't work with C<-t>, and you need to
891symbolic link, not the real file.) (Also, if the stat buffer was filled by
1145remember that L<C<lstat>|/lstat FILEHANDLE> and C<-l> leave values in
892an C<lstat> call, C<-T> and C<-B> will reset it with the results of C<stat _>).
1146the stat structure for the symbolic link, not the real file.) (Also, if
1147the stat buffer was filled by an L<C<lstat>|/lstat FILEHANDLE> call,
1148C<-T> and C<-B> will reset it with the results of C<stat _>).
8931149Example:
8941150
8951151=end original
8961152
897どのファイルテスト (あるいは、C<stat> や C<lstat>) 演算子にも、
1153どのファイルテスト (あるいは、L<C<stat>|/stat FILEHANDLE>
1154L<C<lstat>|/lstat FILEHANDLE>) 演算子にも、
8981155下線だけから成る特別なファイルハンドルを与えると、
899前回のファイルテスト (や stat) の stat 構造体が使われ、
1156前回のファイルテスト (や L<C<stat>|/stat FILEHANDLE> 演算子) の
900システムコールを省きます。
1157stat 構造体が使われ、システムコールを省きます。
901(C<-t> には使えませんし、lstat() や C<-l> は実ファイルではなく、
1158(C<-t> には使えませんし、L<C<lstat>|/lstat FILEHANDLE> や C<-l> は
902シンボリックリンクの情報を stat 構造体に残すことを
1159実ファイルではなく、シンボリックリンクの情報を stat 構造体に残すことを
9031160覚えておく必要があります。)
904(また、stat バッファが C<lstat> 呼び出しで埋まった場合、
1161(また、stat バッファが L<C<lstat>|/lstat FILEHANDLE> 呼び出しで埋まった場合、
9051162C<-T> と C<-B> の結果は C<stat _> の結果でリセットされます。
9061163例:
9071164
9081165 print "Can do.\n" if -r $a || -w _ || -x _;
9091166
9101167 stat($filename);
9111168 print "Readable\n" if -r _;
9121169 print "Writable\n" if -w _;
9131170 print "Executable\n" if -x _;
9141171 print "Setuid\n" if -u _;
9151172 print "Setgid\n" if -g _;
9161173 print "Sticky\n" if -k _;
9171174 print "Text\n" if -T _;
9181175 print "Binary\n" if -B _;
9191176
9201177=begin original
9211178
9221179As of Perl 5.10.0, as a form of purely syntactic sugar, you can stack file
9231180test operators, in a way that C<-f -w -x $file> is equivalent to
924C<-x $file && -w _ && -f _>. (This is only fancy fancy: if you use
1181C<-x $file && -w _ && -f _>. (This is only fancy syntax: if you use
9251182the return value of C<-f $file> as an argument to another filetest
9261183operator, no special magic will happen.)
9271184
9281185=end original
9291186
9301187Perl 5.10.0 から、純粋にシンタックスシュガーとして、ファイルテスト演算子を
9311188スタックさせることができるので、C<-f -w -x $file> は
9321189C<-x $file && -w _ && -f _> と等価です。
9331190(これは文法上だけの話です; もし C<-f $file> の返り値を他のファイルテスト
9341191演算子の引数として使う場合は、何の特別なことも起きません。)
9351192
9361193=begin original
9371194
9381195Portability issues: L<perlport/-X>.
9391196
9401197=end original
9411198
9421199移植性の問題: L<perlport/-X>。
9431200
9441201=begin original
9451202
9461203To avoid confusing would-be users of your code with mysterious
9471204syntax errors, put something like this at the top of your script:
9481205
9491206=end original
9501207
9511208あなたのコードのユーザーが不思議な文法エラーで混乱することを
9521209避けるために、スクリプトの先頭に以下のようなことを書いてください:
9531210
954 use 5.010; # so filetest ops can stack
1211 use v5.10; # so filetest ops can stack
9551212
9561213=item abs VALUE
9571214X<abs> X<absolute>
9581215
9591216=item abs
9601217
9611218=for Pod::Functions absolute value function
9621219
9631220=begin original
9641221
9651222Returns the absolute value of its argument.
966If VALUE is omitted, uses C<$_>.
1223If VALUE is omitted, uses L<C<$_>|perlvar/$_>.
9671224
9681225=end original
9691226
9701227引数の絶対値を返します。
971VALUE が省略された場合は、C<$_> を使います。
1228VALUE が省略された場合は、L<C<$_>|perlvar/$_> を使います。
9721229
9731230=item accept NEWSOCKET,GENERICSOCKET
9741231X<accept>
9751232
9761233=for Pod::Functions accept an incoming socket connect
9771234
9781235=begin original
9791236
980Accepts an incoming socket connect, just as accept(2)
1237Accepts an incoming socket connect, just as L<accept(2)>
9811238does. Returns the packed address if it succeeded, false otherwise.
9821239See the example in L<perlipc/"Sockets: Client/Server Communication">.
9831240
9841241=end original
9851242
986accept(2) システムコールと同様に、着信するソケットの接続を受け付けます。
1243L<accept(2)> システムコールと同様に、着信するソケットの接続を受け付けます。
9871244成功時にはパックされたアドレスを返し、失敗すれば偽を返します。
9881245L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
9891246
9901247=begin original
9911248
9921249On systems that support a close-on-exec flag on files, the flag will
9931250be set for the newly opened file descriptor, as determined by the
994value of $^F. See L<perlvar/$^F>.
1251value of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>.
9951252
9961253=end original
9971254
9981255ファイルに対する close-on-exec フラグをサポートしているシステムでは、
999フラグは $^F の値で決定される、新しくオープンされたファイル記述子に対して
1256フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた
1000セットされます。
1257ファイル記述子に対してセットされます。
10011258L<perlvar/$^F> を参照してください。
10021259
10031260=item alarm SECONDS
10041261X<alarm>
10051262X<SIGALRM>
10061263X<timer>
10071264
10081265=item alarm
10091266
10101267=for Pod::Functions schedule a SIGALRM
10111268
10121269=begin original
10131270
10141271Arranges to have a SIGALRM delivered to this process after the
10151272specified number of wallclock seconds has elapsed. If SECONDS is not
1016specified, the value stored in C<$_> is used. (On some machines,
1273specified, the value stored in L<C<$_>|perlvar/$_> is used. (On some
1017unfortunately, the elapsed time may be up to one second less or more
1274machines, unfortunately, the elapsed time may be up to one second less
1018than you specified because of how seconds are counted, and process
1275or more than you specified because of how seconds are counted, and
1019scheduling may delay the delivery of the signal even further.)
1276process scheduling may delay the delivery of the signal even further.)
10201277
10211278=end original
10221279
10231280指定した壁時計秒数が経過した後に、自プロセスに SIGALRM が
10241281送られてくるようにします。
1025SECONDS が指定されていない場合は、C<$_> に格納されている値を使います。
1282SECONDS が指定されていない場合は、L<C<$_>|perlvar/$_> に格納されている値を
1283使います。
10261284(マシンによっては、秒の数え方が異なるため、指定した秒数よりも最大で
102712851 秒ずれます。)
10281286
10291287=begin original
10301288
10311289Only one timer may be counting at once. Each call disables the
10321290previous timer, and an argument of C<0> may be supplied to cancel the
10331291previous timer without starting a new one. The returned value is the
10341292amount of time remaining on the previous timer.
10351293
10361294=end original
10371295
10381296一度には一つのタイマだけが設定可能です。
10391297呼び出しを行なう度に、以前のタイマを無効にしますし、
10401298新しくタイマを起動しないで以前のタイマをキャンセルするために
10411299引数に C<0> を指定して呼び出すことができます。
10421300以前のタイマの残り時間が、返り値となります。
10431301
10441302=begin original
10451303
1046For delays of finer granularity than one second, the Time::HiRes module
1304For delays of finer granularity than one second, the L<Time::HiRes> module
10471305(from CPAN, and starting from Perl 5.8 part of the standard
1048distribution) provides ualarm(). You may also use Perl's four-argument
1306distribution) provides
1049version of select() leaving the first three arguments undefined, or you
1307L<C<ualarm>|Time::HiRes/ualarm ( $useconds [, $interval_useconds ] )>.
1050might be able to use the C<syscall> interface to access setitimer(2) if
1308You may also use Perl's four-argument version of
1051your system supports it. See L<perlfaq8> for details.
1309L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> leaving the first three
1310arguments undefined, or you might be able to use the
1311L<C<syscall>|/syscall NUMBER, LIST> interface to access L<setitimer(2)>
1312if your system supports it. See L<perlfaq8> for details.
10521313
10531314=end original
10541315
10551 秒より精度の高いスリープを行なうには、
13161 秒より精度の高いスリープを行なうには、L<Time::HiRes> モジュール(CPAN から、
1056Time::HiRes モジュール(CPAN から、また Perl 5.8 からは
1317また Perl 5.8 からは標準配布されています) が
1057標準配布されています) が ualarm() を提供します。
1318L<C<usleep>|Time::HiRes/usleep ( $useconds )> を提供します。
1058Perl の 4 引数版 select() を最初の 3 引数を未定義にして使うか、
1319Perl の 4 引数版 L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を最初の
1059setitimer(2) をサポートしているシステムでは、Perl の
13203 引数を未定義にして使うか、L<setitimer(2)> をサポートしているシステムでは、
1060C<syscall> インタフェースを使ってアクセスすることもできます。
1321Perl の L<C<syscall>|/syscall NUMBER, LIST> インタフェースを使って
1322アクセスすることもできます。
10611323詳しくは L<perlfaq8> を参照してください。
10621324
10631325=begin original
10641326
1065It is usually a mistake to intermix C<alarm> and C<sleep> calls, because
1327It is usually a mistake to intermix L<C<alarm>|/alarm SECONDS> and
1066C<sleep> may be internally implemented on your system with C<alarm>.
1328L<C<sleep>|/sleep EXPR> calls, because L<C<sleep>|/sleep EXPR> may be
1329internally implemented on your system with L<C<alarm>|/alarm SECONDS>.
10671330
10681331=end original
10691332
1070C<alarm> と C<sleep> を混ぜて使うのは普通は間違いです; なぜなら、
1333L<C<alarm>|/alarm SECONDS> L<C<sleep>|/sleep EXPR> を混ぜて使うのは
1071C<sleep> は内部的に C<alarm> を使って内部的に実装されているかも
1334普通は間違いです; なぜなら、L<C<sleep>|/sleep EXPR> 内部的に
1335L<C<alarm>|/alarm SECONDS> を使って内部的に実装されているかも
10721336しれないからです。
10731337
10741338=begin original
10751339
1076If you want to use C<alarm> to time out a system call you need to use an
1340If you want to use L<C<alarm>|/alarm SECONDS> to time out a system call
1077C<eval>/C<die> pair. You can't rely on the alarm causing the system call to
1341you need to use an L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> pair. You
1078fail with C<$!> set to C<EINTR> because Perl sets up signal handlers to
1342can't rely on the alarm causing the system call to fail with
1079restart system calls on some systems. Using C<eval>/C<die> always works,
1343L<C<$!>|perlvar/$!> set to C<EINTR> because Perl sets up signal handlers
1080modulo the caveats given in L<perlipc/"Signals">.
1344to restart system calls on some systems. Using
1345L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> always works, modulo the
1346caveats given in L<perlipc/"Signals">.
10811347
10821348=end original
10831349
1084C<alarm> をシステムコールの時間切れのために使いたいなら、
1350L<C<alarm>|/alarm SECONDS> をシステムコールの時間切れのために使いたいなら、
1085C<eval>/C<die> のペアで使う必要があります。
1351L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> のペアで使う必要があります。
1086システムコールが失敗したときに C<$!> に C<EINTR> がセットされることに
1352システムコールが失敗したときに L<C<$!>|perlvar/$!> に C<EINTR> が
1087頼ってはいけません; なぜならシステムによっては Perl は
1353セットされることに頼ってはいけません; なぜならシステムによっては Perl は
10881354システムコールを再開するためにシグナルハンドラを設定するからです。
1089C<eval>/C<die> は常にうまく動きます; 注意点については
1355L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> は常にうまく動きます;
1090L<perlipc/"Signals"> を参照してください。
1356注意点については L<perlipc/"Signals"> を参照してください。
10911357
10921358 eval {
10931359 local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
10941360 alarm $timeout;
1095 $nread = sysread SOCKET, $buffer, $size;
1361 my $nread = sysread $socket, $buffer, $size;
10961362 alarm 0;
10971363 };
10981364 if ($@) {
10991365 die unless $@ eq "alarm\n"; # propagate unexpected errors
11001366 # timed out
11011367 }
11021368 else {
11031369 # didn't
11041370 }
11051371
11061372=begin original
11071373
11081374For more information see L<perlipc>.
11091375
11101376=end original
11111377
11121378さらなる情報については L<perlipc> を参照してください。
11131379
11141380=begin original
11151381
11161382Portability issues: L<perlport/alarm>.
11171383
11181384=end original
11191385
11201386移植性の問題: L<perlport/alarm>。
11211387
11221388=item atan2 Y,X
11231389X<atan2> X<arctangent> X<tan> X<tangent>
11241390
11251391=for Pod::Functions arctangent of Y/X in the range -PI to PI
11261392
11271393=begin original
11281394
11291395Returns the arctangent of Y/X in the range -PI to PI.
11301396
11311397=end original
11321398
11331399-πからπの範囲で Y/X の逆正接を返します。
11341400
11351401=begin original
11361402
1137For the tangent operation, you may use the C<Math::Trig::tan>
1403For the tangent operation, you may use the
1138function, or use the familiar relation:
1404L<C<Math::Trig::tan>|Math::Trig/B<tan>> function, or use the familiar
1405relation:
11391406
11401407=end original
11411408
1142正接を求めたいときは、C<Math::Trig::tan> を使うか、
1409正接を求めたいときは、L<C<Math::Trig::tan>|Math::Trig/B<tan>> を使うか、
11431410以下のよく知られた関係を使ってください。
11441411
11451412 sub tan { sin($_[0]) / cos($_[0]) }
11461413
11471414=begin original
11481415
11491416The return value for C<atan2(0,0)> is implementation-defined; consult
1150your atan2(3) manpage for more information.
1417your L<atan2(3)> manpage for more information.
11511418
11521419=end original
11531420
11541421C<atan2(0,0)> の返り値は実装依存です; さらなる情報については
1155atan2(3) man ページを参照してください。
1422L<atan2(3)> man ページを参照してください。
11561423
11571424=begin original
11581425
11591426Portability issues: L<perlport/atan2>.
11601427
11611428=end original
11621429
11631430移植性の問題: L<perlport/atan2>。
11641431
11651432=item bind SOCKET,NAME
11661433X<bind>
11671434
11681435=for Pod::Functions binds an address to a socket
11691436
11701437=begin original
11711438
1172Binds a network address to a socket, just as bind(2)
1439Binds a network address to a socket, just as L<bind(2)>
11731440does. Returns true if it succeeded, false otherwise. NAME should be a
11741441packed address of the appropriate type for the socket. See the examples in
11751442L<perlipc/"Sockets: Client/Server Communication">.
11761443
11771444=end original
11781445
1179bind(2) システムコールと同様に、ネットワークアドレスをソケットに結び付けます。
1446L<bind(2)> システムコールと同様に、ネットワークアドレスをソケットに
1447結び付けます。
11801448成功時には真を、さもなければ偽を返します。
11811449NAME は、ソケットに対する、適切な型のパックされた
11821450アドレスでなければなりません。
11831451L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
11841452
11851453=item binmode FILEHANDLE, LAYER
11861454X<binmode> X<binary> X<text> X<DOS> X<Windows>
11871455
11881456=item binmode FILEHANDLE
11891457
11901458=for Pod::Functions prepare binary files for I/O
11911459
11921460=begin original
11931461
11941462Arranges for FILEHANDLE to be read or written in "binary" or "text"
11951463mode on systems where the run-time libraries distinguish between
11961464binary and text files. If FILEHANDLE is an expression, the value is
11971465taken as the name of the filehandle. Returns true on success,
1198otherwise it returns C<undef> and sets C<$!> (errno).
1466otherwise it returns L<C<undef>|/undef EXPR> and sets
1467L<C<$!>|perlvar/$!> (errno).
11991468
12001469=end original
12011470
12021471バイナリファイルとテキストファイルを区別する OS において、
12031472FILEHANDLE を「バイナリ」または「テキスト」で読み書きするように
12041473指定します。
12051474FILEHANDLE が式である場合には、その式の値がファイルハンドルの
12061475名前として使われます。
1207成功時には真を返し、失敗時には C<undef> を返して C<$!> (errno) 設定ます。
1476成功時には真を返し、失敗時には L<C<undef>|/undef EXPR> を
1477L<C<$!>|perlvar/$!> (errno) を設定します。
12081478
12091479=begin original
12101480
1211On some systems (in general, DOS- and Windows-based systems) binmode()
1481On some systems (in general, DOS- and Windows-based systems)
1212is necessary when you're not working with a text file. For the sake
1482L<C<binmode>|/binmode FILEHANDLE, LAYER> is necessary when you're not
1213of portability it is a good idea always to use it when appropriate,
1483working with a text file. For the sake of portability it is a good idea
1214and never to use it when it isn't appropriate. Also, people can
1484always to use it when appropriate, and never to use it when it isn't
1215set their I/O to be by default UTF8-encoded Unicode, not bytes.
1485appropriate. Also, people can set their I/O to be by default
1486UTF8-encoded Unicode, not bytes.
12161487
12171488=end original
12181489
1219テキストファイルでないものを扱う場合に binmode() が必要な
1490テキストファイルでないものを扱う場合に
1491L<C<binmode>|/binmode FILEHANDLE, LAYER> が必要な
12201492システムもあります(一般的には DOS と Windows ベースのシステムです)。
12211493移植性のために、適切なときには常にこれを使い、適切でないときには
12221494決して使わないというのは良い考えです。
12231495また、デフォルトとして I/O を bytes ではなく UTF-8 エンコードされた
12241496Unicode にセットすることも出来ます。
12251497
12261498=begin original
12271499
1228In other words: regardless of platform, use binmode() on binary data,
1500In other words: regardless of platform, use
1229like images, for example.
1501L<C<binmode>|/binmode FILEHANDLE, LAYER> on binary data, like images,
1502for example.
12301503
12311504=end original
12321505
12331506言い換えると: プラットフォームに関わらず、
1234例えばイメージのようなバイナリファイルに対しては binmode() を
1507例えばイメージのようなバイナリファイルに対しては
1235使ってください。
1508L<C<binmode>|/binmode FILEHANDLE, LAYER> を使ってください。
12361509
12371510=begin original
12381511
12391512If LAYER is present it is a single string, but may contain multiple
12401513directives. The directives alter the behaviour of the filehandle.
12411514When LAYER is present, using binmode on a text file makes sense.
12421515
12431516=end original
12441517
12451518LAYER が存在すると、それは単一の文字列ですが、複数の指示子を
12461519含むことができます。
12471520指示子はファイルハンドルの振る舞いを変更します。
12481521LAYER が存在すると、テキストファイルでの binmode が意味を持ちます。
12491522
12501523=begin original
12511524
12521525If LAYER is omitted or specified as C<:raw> the filehandle is made
12531526suitable for passing binary data. This includes turning off possible CRLF
12541527translation and marking it as bytes (as opposed to Unicode characters).
12551528Note that, despite what may be implied in I<"Programming Perl"> (the
12561529Camel, 3rd edition) or elsewhere, C<:raw> is I<not> simply the inverse of C<:crlf>.
12571530Other layers that would affect the binary nature of the stream are
1258I<also> disabled. See L<PerlIO>, L<perlrun>, and the discussion about the
1531I<also> disabled. See L<PerlIO>, and the discussion about the PERLIO
1259PERLIO environment variable.
1532environment variable in L<perlrun|perlrun/PERLIO>.
12601533
12611534=end original
12621535
12631536LAYER が省略されたり、C<:raw> が指定されると、ファイルハンドルはバイナリ
12641537データの通過に適するように設定されます。
12651538これには CRLF 変換をオフにしたり、それぞれを(Unicode 文字ではなく)
12661539バイトであるとマークしたりすることを含みます。
12671540I<"プログラミング Perl">(ラクダ本第三版) やその他で暗示されているにも関わらず、
12681541C<:raw> は単なる C<:crlf> の I<逆ではありません>。
12691542ストリームのバイナリとしての性質に影響を与える
12701543I<その他の層も無効にされます>。
1271L<PerlIO>, L<perlrun> およびPERLIO 環境変数に関する議論を参照してください。
1544L<PerlIO>, および L<perlrun|perlrun/PERLIO> PERLIO 環境変数に関する議論を
1545参照してください。
12721546
12731547=begin original
12741548
12751549The C<:bytes>, C<:crlf>, C<:utf8>, and any other directives of the
1276form C<:...>, are called I/O I<layers>. The C<open> pragma can be used to
1550form C<:...>, are called I/O I<layers>. The L<open> pragma can be used to
1277establish default I/O layers. See L<open>.
1551establish default I/O layers.
12781552
12791553=end original
12801554
12811555C<:bytes>, C<:crlf>, and C<:utf8>, 及びその他の C<:...> 形式の指示子は
12821556I/O I<層> が呼び出されます。
1283C<open> プラグマはデフォルト I/O 層を指定するために使われます。
1557L<open> プラグマはデフォルト I/O 層を指定するために使われます。
1284L<open> を参照してください。
12851558
12861559=begin original
12871560
1288I<The LAYER parameter of the binmode() function is described as "DISCIPLINE"
1561I<The LAYER parameter of the L<C<binmode>|/binmode FILEHANDLE, LAYER>
1289in "Programming Perl, 3rd Edition". However, since the publishing of this
1562function is described as "DISCIPLINE" in "Programming Perl, 3rd
1290book, by many known as "Camel III", the consensus of the naming of this
1563Edition". However, since the publishing of this book, by many known as
1291functionality has moved from "discipline" to "layer". All documentation
1564"Camel III", the consensus of the naming of this functionality has moved
1292of this version of Perl therefore refers to "layers" rather than to
1565from "discipline" to "layer". All documentation of this version of Perl
1293"disciplines". Now back to the regularly scheduled documentation...>
1566therefore refers to "layers" rather than to "disciplines". Now back to
1567the regularly scheduled documentation...>
12941568
12951569=end original
12961570
1297I<binmode() 関数の LAYER パラメータは 「プログラミングPerl 第3版」で
1571I<L<C<binmode>|/binmode FILEHANDLE, LAYER> 関数の LAYER パラメータは
1572「プログラミングPerl 第 3 版」では
12981573「ディシプリン(DISCIPLINE)」と表現されていました。
1299しかし、「ラクダ本第3版」として知られているこの本の出版後、この機能の名前は
1574しかし、「ラクダ本第 3 版」として知られているこの本の出版後、この機能の名前は
13001575「ディシプリン」から「層」に変更することで合意されました。
13011576従って、このバージョンの Perl の全ての文書では「ディシプリン」ではなく
13021577「層」と記述されています。では通常の解説に戻ります…>
13031578
13041579=begin original
13051580
13061581To mark FILEHANDLE as UTF-8, use C<:utf8> or C<:encoding(UTF-8)>.
13071582C<:utf8> just marks the data as UTF-8 without further checking,
13081583while C<:encoding(UTF-8)> checks the data for actually being valid
13091584UTF-8. More details can be found in L<PerlIO::encoding>.
13101585
13111586=end original
13121587
13131588FILEHANDLE が UTF-8 であるというマークをつけるには、C<:utf8> か
13141589C<:encoding(UTF-8)> を使ってください。
13151590C<:utf8> は、さらなるチェックなしにデータが UTF-8 としてマークしますが、
13161591C<:encoding(UTF-8)> はデータが実際に有効な UTF-8 かどうかをチェックします。
13171592さらなる詳細は L<PerlIO::encoding> にあります。
13181593
13191594=begin original
13201595
1321In general, binmode() should be called after open() but before any I/O
1596In general, L<C<binmode>|/binmode FILEHANDLE, LAYER> should be called
1322is done on the filehandle. Calling binmode() normally flushes any
1597after L<C<open>|/open FILEHANDLE,MODE,EXPR> but before any I/O is done on the
1323pending buffered output data (and perhaps pending input data) on the
1598filehandle. Calling L<C<binmode>|/binmode FILEHANDLE, LAYER> normally
1324handle. An exception to this is the C<:encoding> layer that
1599flushes any pending buffered output data (and perhaps pending input
1325changes the default character encoding of the handle; see L</open>.
1600data) on the handle. An exception to this is the C<:encoding> layer
1601that changes the default character encoding of the handle.
13261602The C<:encoding> layer sometimes needs to be called in
1327mid-stream, and it doesn't flush the stream. The C<:encoding>
1603mid-stream, and it doesn't flush the stream. C<:encoding>
13281604also implicitly pushes on top of itself the C<:utf8> layer because
13291605internally Perl operates on UTF8-encoded Unicode characters.
13301606
13311607=end original
13321608
1333一般的に binmode() は open() を呼び出した後、このファイルハンドルに対する
1609一般的に L<C<binmode>|/binmode FILEHANDLE, LAYER> は
1334I/O 操作する前に呼び出すべきです。
1610L<C<open>|/open FILEHANDLE,MODE,EXPR> を呼び出した後、このファイルハンドルに
1335binmode() を呼び出すと、普通はこのファイルハンドルに対して
1611対するI/O 操作する前に呼び出すべきです。
1336バッファリングされている全ての力データ
1612L<C<binmode>|/binmode FILEHANDLE, LAYER> を呼びすと、普通はこの
1613ファイルハンドルに対してバッファリングされている全ての出力データ
13371614(およびおそらくは入力データ)をフラッシュします。
13381615例外は、このハンドルに対するデフォルト文字エンコーディングを変更する
1339C<:encoding> 層です; L</open> を参照してください
1616C<:encoding> 層です。
13401617C<:encoding> 層はストリームの途中で呼び出す必要があることがあり、
13411618それによってストリームはフラッシュされません。
13421619Perl は内部で UTF-8 エンコードされた Unicode 文字を操作しているので、
13431620C<:encoding> は暗黙のうちに自身を C<:utf8> 層の上に押し上げます。
13441621
13451622=begin original
13461623
13471624The operating system, device drivers, C libraries, and Perl run-time
13481625system all conspire to let the programmer treat a single
13491626character (C<\n>) as the line terminator, irrespective of external
13501627representation. On many operating systems, the native text file
13511628representation matches the internal representation, but on some
13521629platforms the external representation of C<\n> is made up of more than
13531630one character.
13541631
13551632=end original
13561633
13571634オペレーティングシステム、デバイスドライバ、C ライブラリ、
13581635Perl ランタイムシステムは全て、プログラマが外部表現に関わらず
135916361 文字 (C<\n>) を行終端として扱えるように協調作業します。
13601637多くのオペレーティングシステムでは、ネイティブテキストファイル表現は
13611638内部表現と同じですが、C<\n> の外部表現が複数文字になる
13621639プラットフォームもあります。
13631640
13641641=begin original
13651642
13661643All variants of Unix, Mac OS (old and new), and Stream_LF files on VMS use
13671644a single character to end each line in the external representation of text
13681645(even though that single character is CARRIAGE RETURN on old, pre-Darwin
13691646flavors of Mac OS, and is LINE FEED on Unix and most VMS files). In other
13701647systems like OS/2, DOS, and the various flavors of MS-Windows, your program
13711648sees a C<\n> as a simple C<\cJ>, but what's stored in text files are the
1372two characters C<\cM\cJ>. That means that if you don't use binmode() on
1649two characters C<\cM\cJ>. That means that if you don't use
1373these systems, C<\cM\cJ> sequences on disk will be converted to C<\n> on
1650L<C<binmode>|/binmode FILEHANDLE, LAYER> on these systems, C<\cM\cJ>
1374input, and any C<\n> in your program will be converted back to C<\cM\cJ> on
1651sequences on disk will be converted to C<\n> on input, and any C<\n> in
1375output. This is what you want for text files, but it can be disastrous for
1652your program will be converted back to C<\cM\cJ> on output. This is
1376binary files.
1653what you want for text files, but it can be disastrous for binary files.
13771654
13781655=end original
13791656
13801657全ての Unix 系、(新旧の)Mac OS、VMS の Stream_LF ファイルは
13811658テキストの外部表現として各行の末尾に一つの文字を
13821659使っています(しかしその文字は古い Darwin 以前の Mac OS では復帰で、
13831660Unix とほとんどのVMS のファイルでは改行です)。
13841661VMS, MS-DOS, MS-Windows 系といったその他のシステムでは、
13851662プログラムからは C<\n> は単純に C<\cJ> に見えますが、
13861663テキストファイルとして保存される場合は C<\cM\cJ> の 2 文字になります。
1387つまり、もしこれらのシステムで binmode()使わないと、
1664つまり、もしこれらのシステムで L<C<binmode>|/binmode FILEHANDLE, LAYER>
1388ディスク上の C<\cM\cJ> という並びは入力時に C<\n> に変換され、
1665使わないと、ディスク上の C<\cM\cJ> という並びは入力時に C<\n> に変換され、
13891666プログラムが出力した全ての C<\n> は C<\cM\cJ> に逆変換されます。
13901667これはテキストファイルの場合は思い通りの結果でしょうが、
13911668バイナリファイルの場合は悲惨です。
13921669
13931670=begin original
13941671
1395Another consequence of using binmode() (on some systems) is that
1672Another consequence of using L<C<binmode>|/binmode FILEHANDLE, LAYER>
1396special end-of-file markers will be seen as part of the data stream.
1673(on some systems) is that special end-of-file markers will be seen as
1397For systems from the Microsoft family this means that, if your binary
1674part of the data stream. For systems from the Microsoft family this
1398data contain C<\cZ>, the I/O subsystem will regard it as the end of
1675means that, if your binary data contain C<\cZ>, the I/O subsystem will
1399the file, unless you use binmode().
1676regard it as the end of the file, unless you use
1677L<C<binmode>|/binmode FILEHANDLE, LAYER>.
14001678
14011679=end original
14021680
1403binmode() を(いくつかのシステムで)使うことによるその他の作用としては、
1681L<C<binmode>|/binmode FILEHANDLE, LAYER> を(いくつかのシステムで)
1404特別なファイル終端マーカーがデータストリームの一部として
1682使うことによるその他の作用としては、特別なファイル終端マーカーが
1405見られることです。
1683データストリームの一部として見られることです。
1406Microsoft ファミリーのシステムでは、binmode() を使っていないと
1684Microsoft ファミリーのシステムでは、
1407もしバイナリデータに C<\cZ> が含まれていきにI/O サブシステムが
1685L<C<binmode>|/binmode FILEHANDLE, LAYER> を使っていないと、
1408これをファイル終端とみなすことを意味します。
1686バイナリデータに C<\cZ> が含れていたときに、
1687I/O サブシステムがこれをファイル終端とみなすことを意味します。
14091688
14101689=begin original
14111690
1412binmode() is important not only for readline() and print() operations,
1691L<C<binmode>|/binmode FILEHANDLE, LAYER> is important not only for
1413but also when using read(), seek(), sysread(), syswrite() and tell()
1692L<C<readline>|/readline EXPR> and L<C<print>|/print FILEHANDLE LIST>
1414(see L<perlport> for more details). See the C<$/> and C<$\> variables
1693operations, but also when using
1415in L<perlvar> for how to manually set your input and output
1694L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1695L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1696L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1697L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> and
1698L<C<tell>|/tell FILEHANDLE> (see L<perlport> for more details). See the
1699L<C<$E<sol>>|perlvar/$E<sol>> and L<C<$\>|perlvar/$\> variables in
1700L<perlvar> for how to manually set your input and output
14161701line-termination sequences.
14171702
14181703=end original
14191704
1420binmode() は readline() と print() 操作にだけではなく、
1705L<C<binmode>|/binmode FILEHANDLE, LAYER> L<C<readline>|/readline EXPR> と
1421read(), seek(), sysread(), syswrite(), tell() を使うときも重要
1706L<C<print>|/print FILEHANDLE LIST> 操作だけはなく、
1707L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1708L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1709L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1710L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1711L<C<tell>|/tell FILEHANDLE> を使うときにも重要です
14221712(詳細は L<perlport> を参照してください)。
14231713入出力の行端末シーケンスを手動でセットする方法については
1424L<perlvar> の C<$/> 変数と C<$\> 変数を参照してください。
1714L<perlvar> の L<C<$E<sol>>|perlvar/$E<sol>> 変数
1715L<C<$\>|perlvar/$\> 変数を参照してください。
14251716
14261717=begin original
14271718
14281719Portability issues: L<perlport/binmode>.
14291720
14301721=end original
14311722
14321723移植性の問題: L<perlport/binmode>。
14331724
14341725=item bless REF,CLASSNAME
14351726X<bless>
14361727
14371728=item bless REF
14381729
14391730=for Pod::Functions create an object
14401731
14411732=begin original
14421733
1443This function tells the thingy referenced by REF that it is now an object
1734C<bless> tells Perl to mark the item referred to by C<REF> as an
1444in the CLASSNAME package. If CLASSNAME is omitted, the current package
1735object in a package. The two-argument version of C<bless> is
1445is used. Because a C<bless> is often the last thing in a constructor,
1736always preferable unless there is a specific reason to I<not>
1446it returns the reference for convenience. Always use the two-argument
1737use it.
1447version if a derived class might inherit the function doing the blessing.
1448See L<perlobj> for more about the blessing (and blessings) of objects.
14491738
14501739=end original
14511740
1452この関数は、REF で渡された オブジェクトに対し、
1741C<bless> tells Perl to mark the item referred to by C<REF> as an
1453CLASSNAME 内のオブジェクトとなったことを伝えます。
1742object in a package. The two-argument version of C<bless> is
1454CLASSNAME が省略された場合には、その時点のパッケージとなります。
1743always preferable unless there is a specific reason to I<not>
1455C<bless> は通常、コンストラクタの最後に置かれますので、
1744use it.
1456簡便のためにそのリファレンスを返します。
1745(TBT)
1457派生クラスが bless される関数を継承する場合は、
1458常に 2 引数版を使ってください。
1459オブジェクトの bless (や再 bless) について、詳しくは と L<perlobj> を
1460参照してください。
14611746
1747=over
1748
1749=item * Bless the referred-to item into a specific package
1750(recommended form):
1751
1752 bless $ref, $package;
1753
14621754=begin original
14631755
1464Consider always blessing objects in CLASSNAMEs that are mixed case.
1756The two-argument form adds the object to the package specified
1465Namespaces with all lowercase names are considered reserved for
1757as the second argument.
1466Perl pragmata. Builtin types have all uppercase names. To prevent
1467confusion, you may wish to avoid such package names as well. Make sure
1468that CLASSNAME is a true value.
14691758
14701759=end original
14711760
1472大文字小文字が混じっている CLASSNAME のオブジェクトは常に bless することを
1761The two-argument form adds the object to the package specified
1473考慮してください。
1762as the second argument.
1474全て小文字の名前を持つ名前空間は Perl プラグマのために予約されています。
1763(TBT)
1475組み込みの型は全て大文字の名前を持ちます。
1476混乱を避けるために、
1477パッケージ名としてこのような名前は避けるべきです。
1478CLASSNAME は真の値を持つようにしてください。
14791764
1765=item * Bless the referred-to item into package C<main>:
1766
1767 bless $ref, "";
1768
14801769=begin original
14811770
1482See L<perlmod/"Perl Modules">.
1771If the second argument is an empty string, C<bless> adds the
1772object to package C<main>.
14831773
14841774=end original
14851775
1486L<perlmod/"Perl Modules"> を参照してください。
1776If the second argument is an empty string, C<bless> adds the
1777object to package C<main>.
1778(TBT)
14871779
1780=item * Bless the referred-to item into the current package (not
1781inheritable):
1782
1783 bless $ref;
1784
1785=begin original
1786
1787If C<bless> is used without its second argument, the object is
1788created in the current package. The second argument should
1789always be supplied if a derived class might inherit a method
1790executing C<bless>. Because it is a potential source of bugs,
1791one-argument C<bless> is discouraged.
1792
1793=end original
1794
1795If C<bless> is used without its second argument, the object is
1796created in the current package. The second argument should
1797always be supplied if a derived class might inherit a method
1798executing C<bless>. Because it is a potential source of bugs,
1799one-argument C<bless> is discouraged.
1800(TBT)
1801
1802=back
1803
1804=begin original
1805
1806See L<perlobj> for more about the blessing (and blessings) of
1807objects.
1808
1809=end original
1810
1811See L<perlobj> for more about the blessing (and blessings) of
1812objects.
1813(TBT)
1814
1815=begin original
1816
1817L<C<bless>|/bless REF,CLASSNAME> returns its first argument, the
1818supplied reference, as the value of the function; since C<bless>
1819is commonly the last thing executed in constructors, this means
1820that the reference to the object is returned as the
1821constructor's value and allows the caller to immediately use
1822this returned object in method calls.
1823
1824=end original
1825
1826L<C<bless>|/bless REF,CLASSNAME> returns its first argument, the
1827supplied reference, as the value of the function; since C<bless>
1828is commonly the last thing executed in constructors, this means
1829that the reference to the object is returned as the
1830constructor's value and allows the caller to immediately use
1831this returned object in method calls.
1832(TBT)
1833
1834=begin original
1835
1836C<CLASSNAME> should always be a mixed-case name, as
1837all-uppercase and all-lowercase names are meant to be used only
1838for Perl builtin types and pragmas, respectively. Avoid creating
1839all-uppercase or all-lowercase package names to prevent
1840confusion.
1841
1842=end original
1843
1844C<CLASSNAME> should always be a mixed-case name, as
1845all-uppercase and all-lowercase names are meant to be used only
1846for Perl builtin types and pragmas, respectively. Avoid creating
1847all-uppercase or all-lowercase package names to prevent
1848confusion.
1849(TBT)
1850
1851=begin original
1852
1853Also avoid <Cbless>ing things into the class name C<0>; this
1854will cause code which (erroneously) checks the result of
1855L<C<ref>|/ref EXPR> to see if a reference is C<bless>ed to fail,
1856as "0", a falsy value, is returned.
1857
1858=end original
1859
1860Also avoid <Cbless>ing things into the class name C<0>; this
1861will cause code which (erroneously) checks the result of
1862L<C<ref>|/ref EXPR> to see if a reference is C<bless>ed to fail,
1863as "0", a falsy value, is returned.
1864(TBT)
1865
1866=begin original
1867
1868See L<perlmod/"Perl Modules"> for more details.
1869
1870=end original
1871
1872さらなる詳細については L<perlmod/"Perl Modules"> を参照してください。
1873
14881874=item break
14891875
14901876=for Pod::Functions +switch break out of a C<given> block
14911877
14921878=begin original
14931879
1494Break out of a C<given()> block.
1880Break out of a C<given> block.
14951881
14961882=end original
14971883
1498C<given()> ブロックから脱出します。
1884C<given> ブロックから脱出します。
14991885
15001886=begin original
15011887
1502This keyword is enabled by the C<"switch"> feature; see L<feature> for
1888L<C<break>|/break> is available only if the
1503more information on C<"switch">. You can also access it by prefixing it
1889L<C<"switch"> feature|feature/The 'switch' feature> is enabled or if it
1504with C<CORE::>. Alternatively, include a C<use v5.10> or later to the
1890is prefixed with C<CORE::>. The
1505current scope.
1891L<C<"switch"> feature|feature/The 'switch' feature> is enabled
1892automatically with a C<use v5.10> (or higher) declaration in the current
1893scope.
15061894
15071895=end original
15081896
1509このキーワードは C<"switch"> 機能によって有効になります; C<"switch"> に関する
1897L<C<break>|/break> は、L<C<"switch"> 機能|feature/The 'switch' feature>
1510さらなる情報については L<feature> を参照してください
1898有効か、C<CORE::> 接頭辞使ったときにのみ利用可能です
1511C<CORE::> を前置することによってもアクセスできます。
1899L<C<"switch"> 機能|feature/The 'switch' feature> は、現在のコープ
1512または、現在のスコープに C<use v5.10> 以降を含めてください
1900C<use v5.10> (またはそれ上) 宣言があると自動的に有効になります
15131901
15141902=item caller EXPR
15151903X<caller> X<call stack> X<stack> X<stack trace>
15161904
15171905=item caller
15181906
15191907=for Pod::Functions get context of the current subroutine call
15201908
15211909=begin original
15221910
1523Returns the context of the current subroutine call. In scalar context,
1911Returns the context of the current pure perl subroutine call. In scalar
1524returns the caller's package name if there I<is> a caller (that is, if
1912context, returns the caller's package name if there I<is> a caller (that is, if
1525we're in a subroutine or C<eval> or C<require>) and the undefined value
1913we're in a subroutine or L<C<eval>|/eval EXPR> or
1526otherwise. In list context, returns
1914L<C<require>|/require VERSION>) and the undefined value otherwise.
1915caller never returns XS subs and they are skipped. The next pure perl
1916sub will appear instead of the XS sub in caller's return values. In
1917list context, caller returns
15271918
15281919=end original
15291920
1530その時点のサブルーチン呼び出しのコンテキストを返します。
1921その時点のピュア perl サブルーチン呼び出しのコンテキストを返します。
15311922スカラコンテキストでは、呼び元が I<ある> 場合
1532(サブルーチン、C<eval>、C<require> の中にいるとき) には
1923(サブルーチン、L<C<eval>|/eval EXPR>L<C<require>|/require VERSION> の中に
1533呼び出し元のパッケージ名を返し、その他のときには未定義値を返します。
1924いるとき) には呼び出し元のパッケージ名を返し、
1534リストコンテキストで、以下を返します:
1925その他のときに未定義値を返します
1926caller は XS サブルーチンを返すことはなく、それらは飛ばされます。
1927XS サブルーチンの代わりに次のピュア perl サブルーチンが caller の返り値に
1928なります。
1929リストコンテキストでは、caller は以下を返します:
15351930
1536 # 0 1 2
1931 # 0 1 2
1537 ($package, $filename, $line) = caller;
1932 my ($package, $filename, $line) = caller;
15381933
15391934=begin original
15401935
1936Like L<C<__FILE__>|/__FILE__> and L<C<__LINE__>|/__LINE__>, the filename and
1937line number returned here may be altered by the mechanism described at
1938L<perlsyn/"Plain Old Comments (Not!)">.
1939
1940=end original
1941
1942L<C<__FILE__>|/__FILE__> と L<C<__LINE__>|/__LINE__> 同様、
1943ここで返されるファイル名と行番号は
1944L<perlsyn/"Plain Old Comments (Not!)"> で記述されている機構によって
1945置き換えられます。
1946
1947=begin original
1948
15411949With EXPR, it returns some extra information that the debugger uses to
15421950print a stack trace. The value of EXPR indicates how many call frames
15431951to go back before the current one.
15441952
15451953=end original
15461954
15471955EXPR を付けると、デバッガがスタックトレースを表示するために使う情報を返します。
15481956EXPR の値は、現状から数えて、
15491957いくつ前のコールフレームまで戻るかを示します。
15501958
15511959 # 0 1 2 3 4
1552 ($package, $filename, $line, $subroutine, $hasargs,
1960 my ($package, $filename, $line, $subroutine, $hasargs,
15531961
15541962 # 5 6 7 8 9 10
15551963 $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash)
1556 = caller($i);
1964 = caller($i);
15571965
15581966=begin original
15591967
1560Here $subroutine may be C<(eval)> if the frame is not a subroutine
1968Here, $subroutine is the function that the caller called (rather than the
1561call, but an C<eval>. In such a case additional elements $evaltext and
1969function containing the caller). Note that $subroutine may be C<(eval)> if
1562C<$is_require> are set: C<$is_require> is true if the frame is created by a
1970the frame is not a subroutine call, but an L<C<eval>|/eval EXPR>. In
1563C<require> or C<use> statement, $evaltext contains the text of the
1971such a case additional elements $evaltext and C<$is_require> are set:
1564C<eval EXPR> statement. In particular, for an C<eval BLOCK> statement,
1972C<$is_require> is true if the frame is created by a
1565$subroutine is C<(eval)>, but $evaltext is undefined. (Note also that
1973L<C<require>|/require VERSION> or L<C<use>|/use Module VERSION LIST>
1566each C<use> statement creates a C<require> frame inside an C<eval EXPR>
1974statement, $evaltext contains the text of the C<eval EXPR> statement.
1567frame.) $subroutine may also be C<(unknown)> if this particular
1975In particular, for an C<eval BLOCK> statement, $subroutine is C<(eval)>,
1568subroutine happens to have been deleted from the symbol table.
1976but $evaltext is undefined. (Note also that each
1569C<$hasargs> is true if a new instance of C<@_> was set up for the frame.
1977L<C<use>|/use Module VERSION LIST> statement creates a
1978L<C<require>|/require VERSION> frame inside an C<eval EXPR> frame.)
1979$subroutine may also be C<(unknown)> if this particular subroutine
1980happens to have been deleted from the symbol table. C<$hasargs> is true
1981if a new instance of L<C<@_>|perlvar/@_> was set up for the frame.
15701982C<$hints> and C<$bitmask> contain pragmatic hints that the caller was
1571compiled with. C<$hints> corresponds to C<$^H>, and C<$bitmask>
1983compiled with. C<$hints> corresponds to L<C<$^H>|perlvar/$^H>, and
1572corresponds to C<${^WARNING_BITS}>. The
1984C<$bitmask> corresponds to
1573C<$hints> and C<$bitmask> values are subject
1985L<C<${^WARNING_BITS}>|perlvar/${^WARNING_BITS}>. The C<$hints> and
1574to change between versions of Perl, and are not meant for external use.
1986C<$bitmask> values are subject to change between versions of Perl, and
1987are not meant for external use.
15751988
15761989=end original
15771990
1578もしフレームがサブルーチン呼び出しではなく C<eval> だっ場合、この
1991ここ、$subroutine 、(caller を含む関数ではなく) caller が呼び出し
1579$subroutine は C<(eval)> になります。
1992関数です。
1993フレームがサブルーチン呼び出しではなく L<C<eval>|/eval EXPR> だった場合、この
1994$subroutine は C<(eval)> になることに注意してください。
15801995この場合、追加の要素である $evaltext と C<$is_require> がセットされます:
1581C<$is_require> はフレームが C<require> または C<use> で作られ場合に
1996C<$is_require> はフレームが L<C<require>|/require VERSION>
1582真になり、$evaltext は C<eval EXPR> のテキストが入ます。
1997L<C<use>|/use Module VERSION LIST> で作られた場合に真にな
1998$evaltext は C<eval EXPR> のテキストが入ります。
15831999特に、C<eval BLOCK> の場合、$subroutine は C<(eval)> になりますが、
15842000$evaltext は未定義値になります。
1585(それぞれの C<use> は C<eval EXPR> の中で C<require> フレームを作ることに
2001(それぞれの L<C<use>|/use Module VERSION LIST> は C<eval EXPR> の中で
1586注意してください。)
2002L<C<require>|/require VERSION> フレームを作ることに注意してください。)
15872003$subroutine は、そのサブルーチンがシンボルテーブルから削除された場合は
15882004C<(unknown)> になります。
1589C<$hasargs> はこのフレーム用に C<@_> の新しい実体が設定された場合に
2005C<$hasargs> はこのフレーム用に L<C<@_>|perlvar/@_> の新しい実体が
1590真となります。
2006設定された場合に真となります。
15912007C<$hints> と C<$bitmask> は caller がコンパイルされたときの
15922008実際的なヒントを含みます。
1593C<$hints> は C<$^H> に対応し、C<$bitmask> は C<${^WARNING_BITS}> に
2009C<$hints> は L<C<$^H>|perlvar/$^H> に対応し、C<$bitmask> は
2010L<C<${^WARNING_BITS}>|perlvar/${^WARNING_BITS}> に
15942011対応します。
15952012C<$hints> は C<$bitmask> は Perl のバージョンによって変更される
15962013可能性があるので、外部での使用を想定していません。
15972014
15982015=begin original
15992016
1600C<$hinthash> is a reference to a hash containing the value of C<%^H> when the
2017C<$hinthash> is a reference to a hash containing the value of
1601caller was compiled, or C<undef> if C<%^H> was empty. Do not modify the values
2018L<C<%^H>|perlvar/%^H> when the caller was compiled, or
1602of this hash, as they are the actual values stored in the optree.
2019L<C<undef>|/undef EXPR> if L<C<%^H>|perlvar/%^H> was empty. Do not
2020modify the values of this hash, as they are the actual values stored in
2021the optree.
16032022
16042023=end original
16052024
1606C<$hinthash> は、caller がコンパイルされた時の C<%^H> の値を含む
2025C<$hinthash> は、caller がコンパイルされた時の L<C<%^H>|perlvar/%^H> の値を
1607ハッシュへのリファレンスか、あるいは C<%^H> が空の場合は C<undef> です。
2026含むハッシュへのリファレンスか、あるいは L<C<%^H>|perlvar/%^H> が空の場合は
2027L<C<undef>|/undef EXPR> です。
16082028このハッシュの値は構文木に保管されている実際の値なので、変更しないで下さい。
16092029
16102030=begin original
16112031
2032Note that the only types of call frames that are visible are subroutine
2033calls and C<eval>. Other forms of context, such as C<while> or C<foreach>
2034loops or C<try> blocks are not considered interesting to C<caller>, as they
2035do not alter the behaviour of the C<return> expression.
2036
2037=end original
2038
2039見ることができる呼び出しフレームの種類はサブルーチン呼び出しと
2040C<eval> だけであることに注意してください。
2041C<while> や C<foreach> のループや C<try> ブロックのようなその他の構造は、
2042C<caller> の関心外です; これらは C<return> 式の振る舞いを変えないからです。
2043
2044=begin original
2045
16122046Furthermore, when called from within the DB package in
16132047list context, and with an argument, caller returns more
16142048detailed information: it sets the list variable C<@DB::args> to be the
16152049arguments with which the subroutine was invoked.
16162050
16172051=end original
16182052
16192053さらに、DB パッケージの中からリストコンテキストで引数付きで呼ばれた場合は、
16202054caller はより詳細な情報を返します; サブルーチンが起動されたときの引数を
16212055変数 C<@DB::args> に設定します。
16222056
16232057=begin original
16242058
16252059Be aware that the optimizer might have optimized call frames away before
1626C<caller> had a chance to get the information. That means that C<caller(N)>
2060L<C<caller>|/caller EXPR> had a chance to get the information. That
1627might not return information about the call frame you expect it to, for
2061means that C<caller(N)> might not return information about the call
1628C<< N > 1 >>. In particular, C<@DB::args> might have information from the
2062frame you expect it to, for C<< N > 1 >>. In particular, C<@DB::args>
1629previous time C<caller> was called.
2063might have information from the previous time L<C<caller>|/caller EXPR>
2064was called.
16302065
16312066=end original
16322067
1633C<caller> が情報を得る前にオプティマイザが呼び出しフレームを最適化して
2068L<C<caller>|/caller EXPR> が情報を得る前にオプティマイザが呼び出しフレームを
1634しまうかもしれないことに注意してください。
2069最適化してしまうかもしれないことに注意してください。
16352070これは、C<caller(N)> が C<< N > 1 >> のとき、
16362071あなたが予測した呼び出しフレームの情報を返さないかもしれないことを意味します。
1637特に、C<@DB::args> は C<caller> が前回呼び出された時の情報を
2072特に、C<@DB::args> は L<C<caller>|/caller EXPR> が前回呼び出された時の情報を
16382073持っているかもしれません。
16392074
16402075=begin original
16412076
16422077Be aware that setting C<@DB::args> is I<best effort>, intended for
16432078debugging or generating backtraces, and should not be relied upon. In
1644particular, as C<@_> contains aliases to the caller's arguments, Perl does
2079particular, as L<C<@_>|perlvar/@_> contains aliases to the caller's
1645not take a copy of C<@_>, so C<@DB::args> will contain modifications the
2080arguments, Perl does not take a copy of L<C<@_>|perlvar/@_>, so
1646subroutine makes to C<@_> or its contents, not the original values at call
2081C<@DB::args> will contain modifications the subroutine makes to
1647time. C<@DB::args>, like C<@_>, does not hold explicit references to its
2082L<C<@_>|perlvar/@_> or its contents, not the original values at call
1648elements, so under certain cases its elements may have become freed and
2083time. C<@DB::args>, like L<C<@_>|perlvar/@_>, does not hold explicit
1649reallocated for other variables or temporary values. Finally, a side effect
2084references to its elements, so under certain cases its elements may have
1650of the current implementation is that the effects of C<shift @_> can
2085become freed and reallocated for other variables or temporary values.
1651I<normally> be undone (but not C<pop @_> or other splicing, I<and> not if a
2086Finally, a side effect of the current implementation is that the effects
1652reference to C<@_> has been taken, I<and> subject to the caveat about reallocated
2087of C<shift @_> can I<normally> be undone (but not C<pop @_> or other
1653elements), so C<@DB::args> is actually a hybrid of the current state and
2088splicing, I<and> not if a reference to L<C<@_>|perlvar/@_> has been
1654initial state of C<@_>. Buyer beware.
2089taken, I<and> subject to the caveat about reallocated elements), so
2090C<@DB::args> is actually a hybrid of the current state and initial state
2091of L<C<@_>|perlvar/@_>. Buyer beware.
16552092
16562093=end original
16572094
16582095C<@DB::args> の設定は I<ベストエフォート> で、デバッグやバックトレースの
16592096生成を目的としていて、これに依存するべきではないということにも
16602097注意してください。
1661特に、C<@_> は呼び出し元の引数へのエイリアスを含んでいるので、Perl は
2098特に、L<C<@_>|perlvar/@_> は呼び出し元の引数へのエイリアスを含んでいるので、
1662C<@_> のコピーを取らず、従って C<@DB::args> はサブルーチンが
2099Perl は L<C<@_>|perlvar/@_> のコピーを取らず、従って C<@DB::args> は
1663C<@_> やその内容に行った変更を含んでいて、呼び出し時の元の値ではありません。
2100サブルーチンが L<C<@_>|perlvar/@_> やその内容に行った変更を含んでいて、
1664C<@DB::args> は、C<@_> と同様、そ要素へ明示的なリファレンスを
2101呼び出し時値ではありません。
1665保持しないので、ある種の状況では、解放されて他変数や一時的な値のために
2102C<@DB::args> は、L<C<@_>|perlvar/@_> と同様、そ要素への明示的な
1666再割り当てされているかもしません。
2103リファレンスを保持しなので、あ種の状況では、解放さて他の変数や
2104一時的な値のために再割り当てされているかもしれません。
16672105最後に、現在の実装の副作用は、C<shift @_> の効果は I<普通は> 行われない
16682106(しかし C<pop @_> やその他の splice は違い、I<そして> もし
1669C<@_> のリファレンスが取られると違い、I<そして> 再割り当てされた要素に関する
2107L<C<@_>|perlvar/@_> のリファレンスが取られると違い、I<そして> 再割り当てされた
1670問題になりやすいです)ことなので、C<@DB::args> は実際には現在の状態と
2108要素に関する問題になりやすいです)ことなので、C<@DB::args> は実際には現在の
1671C<@_> の初期状態との合成物となります。
2109状態と L<C<@_>|perlvar/@_> の初期状態との合成物となります。
16722110ご用心を。
16732111
16742112=item chdir EXPR
16752113X<chdir>
16762114X<cd>
16772115X<directory, change>
16782116
16792117=item chdir FILEHANDLE
16802118
16812119=item chdir DIRHANDLE
16822120
16832121=item chdir
16842122
16852123=for Pod::Functions change your current working directory
16862124
16872125=begin original
16882126
16892127Changes the working directory to EXPR, if possible. If EXPR is omitted,
16902128changes to the directory specified by C<$ENV{HOME}>, if set; if not,
16912129changes to the directory specified by C<$ENV{LOGDIR}>. (Under VMS, the
1692variable C<$ENV{SYS$LOGIN}> is also checked, and used if it is set.) If
2130variable C<$ENV{'SYS$LOGIN'}> is also checked, and used if it is set.) If
1693neither is set, C<chdir> does nothing. It returns true on success,
2131neither is set, L<C<chdir>|/chdir EXPR> does nothing and fails. It
1694false otherwise. See the example under C<die>.
2132returns true on success, false otherwise. See the example under
2133L<C<die>|/die LIST>.
16952134
16962135=end original
16972136
16982137(可能であれば、) カレントディレクトリを EXPR に移します。
16992138EXPR を指定しないと、C<$ENV{HOME}> が設定されていれば、そのディレクトリに
17002139移ります; そうでなく、C<$ENV{LOGDIR}>が設定されていれば、そのディレクトリに
17012140移ります。
1702(VMS では C<$ENV{SYS$LOGIN}> もチェックされ、もしセットされていれば
2141(VMS では C<$ENV{'SYS$LOGIN'}> もチェックされ、もしセットされていれば
17032142使われます。)
1704どちらも設定されていなければ、C<chdir> は何もしません
2143どちらも設定されていなければ、L<C<chdir>|/chdir EXPR> は何もせずに失敗しま
17052144成功時には真を返し、そうでなければ偽を返します。
1706C<die> の項の例を参照してください。
2145L<C<die>|/die LIST> の項の例を参照してください。
17072146
17082147=begin original
17092148
1710On systems that support fchdir(2), you may pass a filehandle or
2149On systems that support L<fchdir(2)>, you may pass a filehandle or
1711directory handle as the argument. On systems that don't support fchdir(2),
2150directory handle as the argument. On systems that don't support L<fchdir(2)>,
17122151passing handles raises an exception.
17132152
17142153=end original
17152154
1716fchdir(2) に対応しているシステムでは、ファイルハンドルや
2155L<fchdir(2)> に対応しているシステムでは、ファイルハンドルや
17172156ディレクトリハンドルを引数として渡せます。
1718fchdir に対応していないシステムでは、ハンドルを渡すと例外が発生します。
2157L<fchdir(2)> に対応していないシステムでは、ハンドルを渡すと例外が発生します。
17192158
17202159=item chmod LIST
17212160X<chmod> X<permission> X<mode>
17222161
17232162=for Pod::Functions changes the permissions on a list of files
17242163
17252164=begin original
17262165
17272166Changes the permissions of a list of files. The first element of the
17282167list must be the numeric mode, which should probably be an octal
17292168number, and which definitely should I<not> be a string of octal digits:
17302169C<0644> is okay, but C<"0644"> is not. Returns the number of files
1731successfully changed. See also L</oct> if all you have is a string.
2170successfully changed. See also L<C<oct>|/oct EXPR> if all you have is a
2171string.
17322172
17332173=end original
17342174
17352175LIST に含まれるファイルの、パーミッションを変更します。
17362176LIST の最初の要素は、数値表現のモードでなければなりません;
17372177恐らく 8 進表記の数であるべきでしょう: しかし、8 進表記の
1738C<文字列ではいけません>: C<0644> は OK ですが、 C<'0644'> は
2178文字列では I<いけません>: C<0644> は OK ですが、 C<"0644"> は
17392179だめ、ということです。
17402180変更に成功したファイルの数を返します。
1741文字列を使いたい場合は、L</oct> を参照してください。
2181文字列を使いたい場合は、L<C<oct>|/oct EXPR> を参照してください。
17422182
1743 $cnt = chmod 0755, "foo", "bar";
2183 my $cnt = chmod 0755, "foo", "bar";
17442184 chmod 0755, @executables;
1745 $mode = "0644"; chmod $mode, "foo"; # !!! sets mode to
2185 my $mode = "0644"; chmod $mode, "foo"; # !!! sets mode to
1746 # --w----r-T
2186 # --w----r-T
1747 $mode = "0644"; chmod oct($mode), "foo"; # this is better
2187 my $mode = "0644"; chmod oct($mode), "foo"; # this is better
1748 $mode = 0644; chmod $mode, "foo"; # this is best
2188 my $mode = 0644; chmod $mode, "foo"; # this is best
17492189
17502190=begin original
17512191
1752On systems that support fchmod(2), you may pass filehandles among the
2192On systems that support L<fchmod(2)>, you may pass filehandles among the
1753files. On systems that don't support fchmod(2), passing filehandles raises
2193files. On systems that don't support L<fchmod(2)>, passing filehandles raises
17542194an exception. Filehandles must be passed as globs or glob references to be
17552195recognized; barewords are considered filenames.
17562196
17572197=end original
17582198
1759fchmod(2) に対応しているシステムでは、ファイルハンドルを引数として渡せます。
2199L<fchmod(2)> に対応しているシステムでは、ファイルハンドルを引数として
1760fchmod(2) に対応していないシステムでは、ファイルハンドルを渡す
2200せま
2201L<fchmod(2)> に対応していないシステムでは、ファイルハンドルを渡すと
17612202例外が発生します。
17622203ファイルハンドルを認識させるためには、グロブまたはリファレンスとして
17632204渡されなければなりません;
17642205裸の単語はファイル名として扱われます。
17652206
17662207 open(my $fh, "<", "foo");
17672208 my $perm = (stat $fh)[2] & 07777;
17682209 chmod($perm | 0600, $fh);
17692210
17702211=begin original
17712212
1772You can also import the symbolic C<S_I*> constants from the C<Fcntl>
2213You can also import the symbolic C<S_I*> constants from the
1773module:
2214L<C<Fcntl>|Fcntl> module:
17742215
17752216=end original
17762217
1777C<Fcntl> モジュールから C<S_I*> シンボル定数をインポートすることもできます:
2218L<C<Fcntl>|Fcntl> モジュールから C<S_I*> シンボル定数を
2219インポートすることもできます:
17782220
17792221 use Fcntl qw( :mode );
17802222 chmod S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, @executables;
17812223 # Identical to the chmod 0755 of the example above.
17822224
17832225=begin original
17842226
17852227Portability issues: L<perlport/chmod>.
17862228
17872229=end original
17882230
17892231移植性の問題: L<perlport/chmod>。
17902232
17912233=item chomp VARIABLE
17922234X<chomp> X<INPUT_RECORD_SEPARATOR> X<$/> X<newline> X<eol>
17932235
17942236=item chomp( LIST )
17952237
17962238=item chomp
17972239
17982240=for Pod::Functions remove a trailing record separator from a string
17992241
18002242=begin original
18012243
1802This safer version of L</chop> removes any trailing string
2244This safer version of L<C<chop>|/chop VARIABLE> removes any trailing
1803that corresponds to the current value of C<$/> (also known as
2245string that corresponds to the current value of
1804$INPUT_RECORD_SEPARATOR in the C<English> module). It returns the total
2246L<C<$E<sol>>|perlvar/$E<sol>> (also known as C<$INPUT_RECORD_SEPARATOR>
2247in the L<C<English>|English> module). It returns the total
18052248number of characters removed from all its arguments. It's often used to
18062249remove the newline from the end of an input record when you're worried
18072250that the final record may be missing its newline. When in paragraph
1808mode (C<$/ = "">), it removes all trailing newlines from the string.
2251mode (C<$/ = ''>), it removes all trailing newlines from the string.
1809When in slurp mode (C<$/ = undef>) or fixed-length record mode (C<$/> is
2252When in slurp mode (C<$/ = undef>) or fixed-length record mode
1810a reference to an integer or the like; see L<perlvar>) chomp() won't
2253(L<C<$E<sol>>|perlvar/$E<sol>> is a reference to an integer or the like;
1811remove anything.
2254see L<perlvar>), L<C<chomp>|/chomp VARIABLE> won't remove anything.
1812If VARIABLE is omitted, it chomps C<$_>. Example:
2255If VARIABLE is omitted, it chomps L<C<$_>|perlvar/$_>. Example:
18132256
18142257=end original
18152258
1816より安全な C<chop> (以下を参照してください) です; C<$/>
2259より安全な L<C<chop>|/chop VARIABLE> (以下を参照してください) です;
1817(C<English> モジュールでは、$INPUT_RECORD_SEPARATOR とも言う) のその時点の
2260L<C<$E<sol>>|perlvar/$E<sol>> (L<C<English>|English> モジュールでは、
2261C<$INPUT_RECORD_SEPARATOR> とも言う) のその時点の
18182262値に対応する行末文字を削除します。
18192263全ての引数から削除した文字数の合計を返します。
18202264入力レコードから、改行を削除したいのだけれど、最後のレコードには改行が
18212265入っているのかわからないような場合に、使用できます。
1822段落モード (C<$/ = "">) では、レコードの最後の改行をすべて取り除きます。
2266段落モード (C<$/ = ''>) では、レコードの最後の改行をすべて取り除きます。
18232267吸い込みモード (C<$/ = undef>) や 固定長レコードモード
1824(C<$/> が整数へのリファレンスや類似のものの場合; L<perlvar>を参照してください)
2268(L<C<$E<sol>>|perlvar/$E<sol>> が整数へのリファレンスや類似のものの場合;
1825では、chomp()何も取り除きません。
2269L<perlvar>を参照してください)では、L<C<chomp>|/chomp VARIABLE>
1826VARIABLE が省略されると、$_ を対象として chomp し
2270何も取り除きせん
2271VARIABLE が省略されると、L<C<$_>|perlvar/$_> を対象として chomp します。
18272272例:
18282273
18292274 while (<>) {
18302275 chomp; # avoid \n on last field
1831 @array = split(/:/);
2276 my @array = split(/:/);
18322277 # ...
18332278 }
18342279
18352280=begin original
18362281
1837If VARIABLE is a hash, it chomps the hash's values, but not its keys.
2282If VARIABLE is a hash, it chomps the hash's values, but not its keys,
2283resetting the L<C<each>|/each HASH> iterator in the process.
18382284
18392285=end original
18402286
1841VARIABLE がハッシュなら、ハッシュのキーではなく値について chomp します。
2287VARIABLE がハッシュなら、ハッシュのキーではなく値について chomp し
2288このプロセスの L<C<each>|/each HASH> 反復子をリセットします。
18422289
18432290=begin original
18442291
18452292You can actually chomp anything that's an lvalue, including an assignment:
18462293
18472294=end original
18482295
18492296左辺値であれば、代入を含めて、任意のものを chomp できます:
18502297
1851 chomp($cwd = `pwd`);
2298 chomp(my $cwd = `pwd`);
1852 chomp($answer = <STDIN>);
2299 chomp(my $answer = <STDIN>);
18532300
18542301=begin original
18552302
18562303If you chomp a list, each element is chomped, and the total number of
18572304characters removed is returned.
18582305
18592306=end original
18602307
18612308リストを chomp すると、個々の要素が chomp され、
18622309削除された文字数の合計が返されます。
18632310
18642311=begin original
18652312
18662313Note that parentheses are necessary when you're chomping anything
18672314that is not a simple variable. This is because C<chomp $cwd = `pwd`;>
18682315is interpreted as C<(chomp $cwd) = `pwd`;>, rather than as
18692316C<chomp( $cwd = `pwd` )> which you might expect. Similarly,
18702317C<chomp $a, $b> is interpreted as C<chomp($a), $b> rather than
18712318as C<chomp($a, $b)>.
18722319
18732320=end original
18742321
18752322単純な変数以外のものを chomp する場合はかっこが必要であることに
18762323注意してください。
18772324これは、C<chomp $cwd = `pwd`;> は、予測している
18782325C<chomp( $cwd = `pwd` )> ではなく、C<(chomp $cwd) = `pwd`;> と
18792326解釈されるからです。
18802327同様に、C<chomp $a, $b> は C<chomp($a, $b)> ではなく C<chomp($a), $b>
18812328と解釈されます。
18822329
18832330=item chop VARIABLE
18842331X<chop>
18852332
18862333=item chop( LIST )
18872334
18882335=item chop
18892336
18902337=for Pod::Functions remove the last character from a string
18912338
18922339=begin original
18932340
18942341Chops off the last character of a string and returns the character
18952342chopped. It is much more efficient than C<s/.$//s> because it neither
1896scans nor copies the string. If VARIABLE is omitted, chops C<$_>.
2343scans nor copies the string. If VARIABLE is omitted, chops
1897If VARIABLE is a hash, it chops the hash's values, but not its keys.
2344L<C<$_>|perlvar/$_>.
2345If VARIABLE is a hash, it chops the hash's values, but not its keys,
2346resetting the L<C<each>|/each HASH> iterator in the process.
18982347
18992348=end original
19002349
19012350文字列の最後の文字を切り捨てて、その切り取った文字を返します。
19022351文字列の検索もコピーも行ないませんので
19032352C<s/.$//s> よりも、ずっと効率的です。
1904VARIABLE が省略されると、C<$_> を対象として chop します。
2353VARIABLE が省略されると、L<C<$_>|perlvar/$_> を対象として chop します。
1905VARIABLE がハッシュの場合、ハッシュの value を chop しますが
2354VARIABLE がハッシュの場合、ハッシュのキーではなく値について chop し、
1906key chop しません
2355このプロセスの L<C<each>|/each HASH> 反復子をリセットしま
19072356
19082357=begin original
19092358
19102359You can actually chop anything that's an lvalue, including an assignment.
19112360
19122361=end original
19132362
19142363実際のところ、代入を含む左辺値となりうるなんでも chop できます。
19152364
19162365=begin original
19172366
19182367If you chop a list, each element is chopped. Only the value of the
1919last C<chop> is returned.
2368last L<C<chop>|/chop VARIABLE> is returned.
19202369
19212370=end original
19222371
19232372リストを chop すると、個々の要素が chop されます。
1924最後の C<chop> の値だけが返されます。
2373最後の L<C<chop>|/chop VARIABLE> の値だけが返されます。
19252374
19262375=begin original
19272376
1928Note that C<chop> returns the last character. To return all but the last
2377Note that L<C<chop>|/chop VARIABLE> returns the last character. To
1929character, use C<substr($string, 0, -1)>.
2378return all but the last character, use C<substr($string, 0, -1)>.
19302379
19312380=end original
19322381
1933C<chop> は最後の文字を返すことに注意してください。
2382L<C<chop>|/chop VARIABLE> は最後の文字を返すことに注意してください。
19342383最後以外の全ての文字を返すためには、C<substr($string, 0, -1)> を
19352384使ってください。
19362385
19372386=begin original
19382387
1939See also L</chomp>.
2388See also L<C<chomp>|/chomp VARIABLE>.
19402389
19412390=end original
19422391
1943L</chomp> も参照してください。
2392L<C<chomp>|/chomp VARIABLE> も参照してください。
19442393
19452394=item chown LIST
19462395X<chown> X<owner> X<user> X<group>
19472396
19482397=for Pod::Functions change the ownership on a list of files
19492398
19502399=begin original
19512400
19522401Changes the owner (and group) of a list of files. The first two
19532402elements of the list must be the I<numeric> uid and gid, in that
19542403order. A value of -1 in either position is interpreted by most
19552404systems to leave that value unchanged. Returns the number of files
19562405successfully changed.
19572406
19582407=end original
19592408
19602409LIST に含まれるファイルの所有者 (とグループ) を変更します。
19612410LIST の最初の二つの要素には、I<数値表現> の uid と gid を
19622411この順序で与えなければなりません。
19632412どちらかの値を -1 にすると、ほとんどのシステムではその値は
19642413変更しないと解釈します。
19652414変更に成功したファイルの数を返します。
19662415
1967 $cnt = chown $uid, $gid, 'foo', 'bar';
2416 my $cnt = chown $uid, $gid, 'foo', 'bar';
19682417 chown $uid, $gid, @filenames;
19692418
19702419=begin original
19712420
1972On systems that support fchown(2), you may pass filehandles among the
2421On systems that support L<fchown(2)>, you may pass filehandles among the
1973files. On systems that don't support fchown(2), passing filehandles raises
2422files. On systems that don't support L<fchown(2)>, passing filehandles raises
19742423an exception. Filehandles must be passed as globs or glob references to be
19752424recognized; barewords are considered filenames.
19762425
19772426=end original
19782427
1979fchown(2) に対応しているシステムでは、ファイルハンドルを引数として渡せます。
2428L<fchown(2)> に対応しているシステムでは、ファイルハンドルを引数として渡せます。
1980fchown(2) に対応していないシステムでは、ファイルハンドルを渡すと
2429L<fchown(2)> に対応していないシステムでは、ファイルハンドルを渡すと
19812430例外が発生します。
19822431ファイルハンドルを認識させるためには、グロブまたはリファレンスとして
19832432渡されなければなりません; 裸の単語はファイル名として扱われます。
19842433
19852434=begin original
19862435
19872436Here's an example that looks up nonnumeric uids in the passwd file:
19882437
19892438=end original
19902439
19912440passwd ファイルから数値表現でない uid を検索する例を
19922441示します:
19932442
19942443 print "User: ";
1995 chomp($user = <STDIN>);
2444 chomp(my $user = <STDIN>);
19962445 print "Files: ";
1997 chomp($pattern = <STDIN>);
2446 chomp(my $pattern = <STDIN>);
19982447
1999 ($login,$pass,$uid,$gid) = getpwnam($user)
2448 my ($login,$pass,$uid,$gid) = getpwnam($user)
20002449 or die "$user not in passwd file";
20012450
2002 @ary = glob($pattern); # expand filenames
2451 my @ary = glob($pattern); # expand filenames
20032452 chown $uid, $gid, @ary;
20042453
20052454=begin original
20062455
20072456On most systems, you are not allowed to change the ownership of the
20082457file unless you're the superuser, although you should be able to change
20092458the group to any of your secondary groups. On insecure systems, these
20102459restrictions may be relaxed, but this is not a portable assumption.
20112460On POSIX systems, you can detect this condition this way:
20122461
20132462=end original
20142463
20152464ほとんどのシステムでは、スーパーユーザーだけがファイルの所有者を
20162465変更できますが、グループは実行者の副グループに変更できるべきです。
20172466安全でないシステムでは、この制限はゆるめられています; しかしこれは
20182467移植性のある仮定ではありません。
20192468POSIX システムでは、以下のようにしてこの条件を検出できます:
20202469
20212470 use POSIX qw(sysconf _PC_CHOWN_RESTRICTED);
2022 $can_chown_giveaway = not sysconf(_PC_CHOWN_RESTRICTED);
2471 my $can_chown_giveaway = ! sysconf(_PC_CHOWN_RESTRICTED);
20232472
20242473=begin original
20252474
2026Portability issues: L<perlport/chmod>.
2475Portability issues: L<perlport/chown>.
20272476
20282477=end original
20292478
2030移植性の問題: L<perlport/chmod>。
2479移植性の問題: L<perlport/chown>。
20312480
20322481=item chr NUMBER
20332482X<chr> X<character> X<ASCII> X<Unicode>
20342483
20352484=item chr
20362485
20372486=for Pod::Functions get character this number represents
20382487
20392488=begin original
20402489
20412490Returns the character represented by that NUMBER in the character set.
20422491For example, C<chr(65)> is C<"A"> in either ASCII or Unicode, and
2043chr(0x263a) is a Unicode smiley face.
2492chr(0x263a) is a Unicode smiley face.
20442493
20452494=end original
20462495
20472496特定の文字セットでの NUMBER で表わされる文字を返します。
20482497たとえば、C<chr(65)> は ASCII と Unicode の両方で C<"A"> となります;
2049chr(0x263a) は Unicode のスマイリーフェイスです。
2498chr(0x263a) は Unicode のスマイリーフェイスです。
20502499
20512500=begin original
20522501
20532502Negative values give the Unicode replacement character (chr(0xfffd)),
20542503except under the L<bytes> pragma, where the low eight bits of the value
20552504(truncated to an integer) are used.
20562505
20572506=end original
20582507
20592508負の数は Unicode の置換文字 (chr(0xfffd)) を与えますが、
20602509L<bytes> プラグマの影響下では、(integer に切り詰められた)値の下位 8 ビットが
20612510使われます。
20622511
20632512=begin original
20642513
2065If NUMBER is omitted, uses C<$_>.
2514If NUMBER is omitted, uses L<C<$_>|perlvar/$_>.
20662515
20672516=end original
20682517
2069NUMBER が省略された場合、C<$_> を使います。
2518NUMBER が省略された場合、L<C<$_>|perlvar/$_> を使います。
20702519
20712520=begin original
20722521
2073For the reverse, use L</ord>.
2522For the reverse, use L<C<ord>|/ord EXPR>.
20742523
20752524=end original
20762525
2077逆を行うためには、L</ord> を参照してください。
2526逆を行うためには、L<C<ord>|/ord EXPR> を参照してください。
20782527
20792528=begin original
20802529
20812530Note that characters from 128 to 255 (inclusive) are by default
20822531internally not encoded as UTF-8 for backward compatibility reasons.
20832532
20842533=end original
20852534
20862535128 から 255 までの文字は過去との互換性のために
20872536デフォルトでは UTF-8 Unicode にエンコードされません。
20882537
20892538=begin original
20902539
20912540See L<perlunicode> for more about Unicode.
20922541
20932542=end original
20942543
20952544Unicode については L<perlunicode> を参照してください。
20962545
20972546=item chroot FILENAME
20982547X<chroot> X<root>
20992548
21002549=item chroot
21012550
21022551=for Pod::Functions make directory new root for path lookups
21032552
21042553=begin original
21052554
21062555This function works like the system call by the same name: it makes the
21072556named directory the new root directory for all further pathnames that
21082557begin with a C</> by your process and all its children. (It doesn't
21092558change your current working directory, which is unaffected.) For security
21102559reasons, this call is restricted to the superuser. If FILENAME is
2111omitted, does a C<chroot> to C<$_>.
2560omitted, does a L<C<chroot>|/chroot FILENAME> to L<C<$_>|perlvar/$_>.
21122561
21132562=end original
21142563
21152564同じ名前のシステムコールと同じことをします: 現在のプロセス及び子プロセスに
21162565対して、C</>で始まるパス名に関して指定されたディレクトリを新しい
21172566ルートディレクトリとして扱います。
21182567(これはカレントディレクトリを変更しません; カレントディレクトリは
21192568そのままです。)
21202569セキュリティ上の理由により、この呼び出しはスーパーユーザーしか行えません。
2121FILENAME を省略すると、C<$_> へ C<chroot> します。
2570FILENAME を省略すると、L<C<$_>|perlvar/$_>
2571L<C<chroot>|/chroot FILENAME> します。
21222572
21232573=begin original
21242574
2575B<NOTE:> It is mandatory for security to C<chdir("/")>
2576(L<C<chdir>|/chdir EXPR> to the root directory) immediately after a
2577L<C<chroot>|/chroot FILENAME>, otherwise the current working directory
2578may be outside of the new root.
2579
2580=end original
2581
2582B<注意:> L<C<chroot>|/chroot FILENAME> の直後に (ルートディレクトリに
2583L<C<chdir>|/chdir EXPR> する)
2584C<chdir("/")> するのはセキュリティ上必須です;
2585さもなければ現在の作業ディレクトリは新しいルートの外側かもしれません。
2586
2587=begin original
2588
21252589Portability issues: L<perlport/chroot>.
21262590
21272591=end original
21282592
21292593移植性の問題: L<perlport/chroot>。
21302594
2595=item class NAMESPACE
2596
2597=item class NAMESPACE VERSION
2598
2599=item class NAMESPACE BLOCK
2600
2601=item class NAMESPACE VERSION BLOCK
2602
2603=for Pod::Functions declare a separate global namespace that is an object class
2604
2605=begin original
2606
2607Declares the BLOCK or the rest of the compilation unit as being in the given
2608namespace, which implements an object class. This behaves similarly to
2609L<C<package>|/package NAMESPACE>, except that the newly-created package behaves
2610as a class.
2611
2612=end original
2613
2614Declares the BLOCK or the rest of the compilation unit as being in the given
2615namespace, which implements an object class. This behaves similarly to
2616L<C<package>|/package NAMESPACE>, except that the newly-created package behaves
2617as a class.
2618(TBT)
2619
21312620=item close FILEHANDLE
21322621X<close>
21332622
21342623=item close
21352624
21362625=for Pod::Functions close file (or pipe or socket) handle
21372626
21382627=begin original
21392628
21402629Closes the file or pipe associated with the filehandle, flushes the IO
21412630buffers, and closes the system file descriptor. Returns true if those
21422631operations succeed and if no error was reported by any PerlIO
21432632layer. Closes the currently selected filehandle if the argument is
21442633omitted.
21452634
21462635=end original
21472636
21482637FILEHANDLE に対応したファイルまたはパイプをクローズして、
21492638IO バッファをフラッシュし、システムファイル記述子をクローズします。
21502639操作が成功し、PerlIO 層からエラーが報告されなかった場合に真を返します。
21512640引数が省略された場合、現在選択されているファイルハンドルをクローズします。
21522641
21532642=begin original
21542643
21552644You don't have to close FILEHANDLE if you are immediately going to do
2156another C<open> on it, because C<open> closes it for you. (See
2645another L<C<open>|/open FILEHANDLE,MODE,EXPR> on it, because
2157L<open|/open FILEHANDLE>.) However, an explicit C<close> on an input file resets the line
2646L<C<open>|/open FILEHANDLE,MODE,EXPR> closes it for you. (See
2158counter (C<$.>), while the implicit close done by C<open> does not.
2647L<C<open>|/open FILEHANDLE,MODE,EXPR>.) However, an explicit
2648L<C<close>|/close FILEHANDLE> on an input file resets the line counter
2649(L<C<$.>|perlvar/$.>), while the implicit close done by
2650L<C<open>|/open FILEHANDLE,MODE,EXPR> does not.
21592651
21602652=end original
21612653
21622654クローズしてすぐにまた、同じファイルハンドルに対してオープンを行なう
2163場合には、C<open> が自動的に C<close> を行ないますので、
2655場合には、L<C<open>|/open FILEHANDLE,MODE,EXPR> が自動的に
2656L<C<close>|/close FILEHANDLE> を行ないますので、
21642657close FILEHANDLE する必要はありません。
2165(L<open|/open FILEHANDLE> を参照してください。)
2658(L<C<open>|/open FILEHANDLE,MODE,EXPR> を参照してください。)
21662659ただし、明示的にクローズを行なったときにのみ入力ファイルの
2167行番号 (C<$.>) のリセットが行なわれ、C<open> によって行なわれる
2660行番号 (L<C<$.>|perlvar/$.>) のリセットが行なわれ、
2168暗黙の C<close> では行なわれません。
2661L<C<open>|/open FILEHANDLE,MODE,EXPR> によって行なわれ
2662暗黙の L<C<close>|/close FILEHANDLE> では行なわれません。
21692663
21702664=begin original
21712665
2172If the filehandle came from a piped open, C<close> returns false if one of
2666If the filehandle came from a piped open, L<C<close>|/close FILEHANDLE>
2173the other syscalls involved fails or if its program exits with non-zero
2667returns false if one of the other syscalls involved fails or if its
2174status. If the only problem was that the program exited non-zero, C<$!>
2668program exits with non-zero status. If the only problem was that the
2175will be set to C<0>. Closing a pipe also waits for the process executing
2669program exited non-zero, L<C<$!>|perlvar/$!> will be set to C<0>.
2176on the pipe to exit--in case you wish to look at the output of the pipe
2670Closing a pipe also waits for the process executing on the pipe to
2177afterwards--and implicitly puts the exit status value of that command into
2671exit--in case you wish to look at the output of the pipe afterwards--and
2178C<$?> and C<${^CHILD_ERROR_NATIVE}>.
2672implicitly puts the exit status value of that command into
2673L<C<$?>|perlvar/$?> and
2674L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>.
21792675
21802676=end original
21812677
2182ファイルハンドルがパイプつきオープンなら、C<close> はその他の
2678ファイルハンドルがパイプつきオープンなら、L<C<close>|/close FILEHANDLE>
2183システムコールが失敗したりプログラムが非ゼロのステータスで終了した場合にも
2679その他のシステムコールが失敗したりプログラムが非ゼロのステータスで終了した
2184偽を返します。
2680場合にも偽を返します。
2185プログラムが非ゼロで終了しただけの場合は、C<$!>がC<0>にセットされます。
2681プログラムが非ゼロで終了しただけの場合は、L<C<$!>|perlvar/$!> C<0>
2682セットされます。
21862683後でパイプの出力を見たい場合のために、パイプのクローズでは、パイプ上で
21872684実行されているプロセスの終了を待ち、また自動的にコマンドのステータス値を
2188C<$?> と C<${^CHILD_ERROR_NATIVE}> に設定します。
2685L<C<$?>|perlvar/$?>
2686L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に設定します。
21892687
21902688=begin original
21912689
2192If there are multiple threads running, C<close> on a filehandle from a
2690If there are multiple threads running, L<C<close>|/close FILEHANDLE> on
2193piped open returns true without waiting for the child process to terminate,
2691a filehandle from a piped open returns true without waiting for the
2194if the filehandle is still open in another thread.
2692child process to terminate, if the filehandle is still open in another
2693thread.
21952694
21962695=end original
21972696
21982697複数のスレッドがある場合、パイプで開かれたファイルハンドルに対する
2199C<close> は、そのファイルハンドルが他のスレッドでまだ開かれている場合、
2698L<C<close>|/close FILEHANDLE> は、そのファイルハンドルが他のスレッドで
2200子プロセスの終了を待たずに真を返します。
2699まだ開かれている場合、子プロセスの終了を待たずに真を返します。
22012700
22022701=begin original
22032702
22042703Closing the read end of a pipe before the process writing to it at the
22052704other end is done writing results in the writer receiving a SIGPIPE. If
22062705the other end can't handle that, be sure to read all the data before
22072706closing the pipe.
22082707
22092708=end original
22102709
22112710書き込み側が閉じる前に途中でパイプの読み込み側が閉じた場合、
22122711書き込み側に SIGPIPE が配送されます。
22132712書き込み側がこれを扱えない場合、パイプを閉じる前に
22142713確実に全てのデータが読み込まれるようにする必要があります。
22152714
22162715=begin original
22172716
22182717Example:
22192718
22202719=end original
22212720
22222721例:
22232722
22242723 open(OUTPUT, '|sort >foo') # pipe to sort
22252724 or die "Can't start sort: $!";
22262725 #... # print stuff to output
22272726 close OUTPUT # wait for sort to finish
22282727 or warn $! ? "Error closing sort pipe: $!"
22292728 : "Exit status $? from sort";
22302729 open(INPUT, 'foo') # get sort's results
22312730 or die "Can't open 'foo' for input: $!";
22322731
22332732=begin original
22342733
22352734FILEHANDLE may be an expression whose value can be used as an indirect
22362735filehandle, usually the real filehandle name or an autovivified handle.
22372736
22382737=end original
22392738
22402739FILEHANDLE は式でもかまいません; この場合、値は間接ファイルハンドルと
22412740して扱われ、普通は実際のファイルハンドル名か自動有効化されたハンドルです。
22422741
22432742=item closedir DIRHANDLE
22442743X<closedir>
22452744
22462745=for Pod::Functions close directory handle
22472746
22482747=begin original
22492748
2250Closes a directory opened by C<opendir> and returns the success of that
2749Closes a directory opened by L<C<opendir>|/opendir DIRHANDLE,EXPR> and
2251system call.
2750returns the success of that system call.
22522751
22532752=end original
22542753
2255C<opendir> でオープンしたディレクトリをクローズし、
2754L<C<opendir>|/opendir DIRHANDLE,EXPR> でオープンしたディレクトリをクローズし、
22562755システムコールの返り値を返します。
22572756
22582757=item connect SOCKET,NAME
22592758X<connect>
22602759
22612760=for Pod::Functions connect to a remote socket
22622761
22632762=begin original
22642763
2265Attempts to connect to a remote socket, just like connect(2).
2764Attempts to connect to a remote socket, just like L<connect(2)>.
22662765Returns true if it succeeded, false otherwise. NAME should be a
22672766packed address of the appropriate type for the socket. See the examples in
22682767L<perlipc/"Sockets: Client/Server Communication">.
22692768
22702769=end original
22712770
2272connect(2) システムコールと同様に、リモートソケットへの接続を試みます。
2771L<connect(2)> システムコールと同様に、リモートソケットへの接続を試みます。
22732772成功時には真を、さもなければ偽を返します。
22742773NAME は、ソケットに対する、適切な型のパックされた
22752774アドレスでなければなりません。
22762775L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
22772776
22782777=item continue BLOCK
22792778X<continue>
22802779
22812780=item continue
22822781
22832782=for Pod::Functions optional trailing block in a while or foreach
22842783
22852784=begin original
22862785
2287When followed by a BLOCK, C<continue> is actually a
2786When followed by a BLOCK, L<C<continue>|/continue BLOCK> is actually a
2288flow control statement rather than a function. If
2787flow control statement rather than a function. If there is a
2289there is a C<continue> BLOCK attached to a BLOCK (typically in a C<while> or
2788L<C<continue>|/continue BLOCK> BLOCK attached to a BLOCK (typically in a
2290C<foreach>), it is always executed just before the conditional is about to
2789C<while> or C<foreach>), it is always executed just before the
2291be evaluated again, just like the third part of a C<for> loop in C. Thus
2790conditional is about to be evaluated again, just like the third part of
2292it can be used to increment a loop variable, even when the loop has been
2791a C<for> loop in C. Thus it can be used to increment a loop variable,
2293continued via the C<next> statement (which is similar to the C C<continue>
2792even when the loop has been continued via the L<C<next>|/next LABEL>
2793statement (which is similar to the C L<C<continue>|/continue BLOCK>
22942794statement).
22952795
22962796=end original
22972797
2298BLOCK が引き続く場合、C<continue> は実際には関数ではなく、実行制御文です。
2798BLOCK が引き続く場合、L<C<continue>|/continue BLOCK> は実際には関数ではなく、
2299C<continue> BLOCK が BLOCK (典型的には C<while> または C<foreach> の中)にあると、
2799実行制御文です。
2300これは条件文再評価される直前に常に実行されます; これは C における
2800L<C<continue>|/continue BLOCK> BLOCK BLOCK (典型的には C<while> または
2301C<for> ループ 3 番目の部分同様で
2801C<foreach> の中)にある、これは条件文が再評価される直前に常に実行されま;
2302従って、これは C<next> (これは C の C<continue> 似ていま) を使って
2802これは C における C<for> ループの 3 番目の部分同様で
2803従って、これは L<C<next>|/next LABEL> 文 (これは C の
2804L<C<continue>|/continue BLOCK> 文と似ています) を使って
23032805ループが繰り返されるときでもループ変数を増やしたいときに使えます。
23042806
23052807=begin original
23062808
2307C<last>, C<next>, or C<redo> may appear within a C<continue>
2809L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, or
2308block; C<last> and C<redo> behave as if they had been executed within
2810L<C<redo>|/redo LABEL> may appear within a
2309the main block. So will C<next>, but since it will execute a C<continue>
2811L<C<continue>|/continue BLOCK> block; L<C<last>|/last LABEL> and
2310block, it may be more entertaining.
2812L<C<redo>|/redo LABEL> behave as if they had been executed within the
2813main block. So will L<C<next>|/next LABEL>, but since it will execute a
2814L<C<continue>|/continue BLOCK> block, it may be more entertaining.
23112815
23122816=end original
23132817
2314C<last>, C<next>, C<redo> が C<continue> ブロック内に現れる可能性あります;
2818L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL> が
2315C<last> C<redo> はメインブロックの中で実行されたのと同じよう振舞います
2819L<C<continue>|/continue BLOCK> ブロック現れる可能性があります;
2316C<next> の場合は、C<continue> ブロックを実行することになるので
2820L<C<last>|/last LABEL> と L<C<redo>|/redo LABEL> はメインブロックの
2317より面白いことになります。
2821実行されたの同じよう振舞います。
2822L<C<next>|/next LABEL> の場合は、L<C<continue>|/continue BLOCK> ブロックを
2823実行することになるので、より面白いことになります。
23182824
23192825 while (EXPR) {
23202826 ### redo always comes here
23212827 do_something;
23222828 } continue {
23232829 ### next always comes here
23242830 do_something_else;
23252831 # then back the top to re-check EXPR
23262832 }
23272833 ### last always comes here
23282834
23292835=begin original
23302836
2331Omitting the C<continue> section is equivalent to using an
2837Omitting the L<C<continue>|/continue BLOCK> section is equivalent to
2332empty one, logically enough, so C<next> goes directly back
2838using an empty one, logically enough, so L<C<next>|/next LABEL> goes
2333to check the condition at the top of the loop.
2839directly back to check the condition at the top of the loop.
23342840
23352841=end original
23362842
2337C<continue> 節を省略するのは、空の節を指定したのと同じで、
2843L<C<continue>|/continue BLOCK> 節を省略するのは、空の節を指定したのと同じで、
2338論理的には十分なので、この場合、C<next> は直接ループ先頭の
2844論理的には十分なので、この場合、L<C<next>|/next LABEL> は直接ループ先頭の
23392845条件チェックに戻ります。
23402846
23412847=begin original
23422848
2343When there is no BLOCK, C<continue> is a function that
2849When there is no BLOCK, L<C<continue>|/continue BLOCK> is a function
2344falls through the current C<when> or C<default> block instead of iterating
2850that falls through the current C<when> or C<default> block instead of
2345a dynamically enclosing C<foreach> or exiting a lexically enclosing C<given>.
2851iterating a dynamically enclosing C<foreach> or exiting a lexically
2346In Perl 5.14 and earlier, this form of C<continue> was
2852enclosing C<given>. In Perl 5.14 and earlier, this form of
2347only available when the C<"switch"> feature was enabled.
2853L<C<continue>|/continue BLOCK> was only available when the
2348See L<feature> and L<perlsyn/"Switch Statements"> for more
2854L<C<"switch"> feature|feature/The 'switch' feature> was enabled. See
2349information.
2855L<feature> and L<perlsyn/"Switch Statements"> for more information.
23502856
23512857=end original
23522858
2353BLOCK がなければ、C<continue> は動的に囲まれた C<foreach> や
2859BLOCK がなければ、L<C<continue>|/continue BLOCK> は動的に囲まれた C<foreach> や
23542860レキシカルに囲まれた C<given> で反復するのではなく、現在の C<when> または
23552861C<default> のブロックを通り抜けるための文です。
2356Perl 5.14 以前では、この形式の C<continue> C<"switch"> 機能が有効の
2862Perl 5.14 以前では、この形式の L<C<continue>|/continue BLOCK>
2357場合にのみ利用可能です。
2863L<C<"switch"> 機能|feature/The 'switch' feature> が有効の場合にのみ
2864利用可能です。
23582865さらなる情報については L<feature> と L<perlsyn/"Switch Statements"> を
23592866参照してください。
23602867
23612868=item cos EXPR
23622869X<cos> X<cosine> X<acos> X<arccosine>
23632870
23642871=item cos
23652872
23662873=for Pod::Functions cosine function
23672874
23682875=begin original
23692876
23702877Returns the cosine of EXPR (expressed in radians). If EXPR is omitted,
2371takes the cosine of C<$_>.
2878takes the cosine of L<C<$_>|perlvar/$_>.
23722879
23732880=end original
23742881
23752882(ラジアンで示した) EXPR の余弦を返します。
2376EXPR が省略されたときには、C<$_> の余弦を取ります。
2883EXPR が省略されたときには、L<C<$_>|perlvar/$_> の余弦を取ります。
23772884
23782885=begin original
23792886
2380For the inverse cosine operation, you may use the C<Math::Trig::acos()>
2887For the inverse cosine operation, you may use the
2381function, or use this relation:
2888L<C<Math::Trig::acos>|Math::Trig> function, or use this relation:
23822889
23832890=end original
23842891
2385逆余弦を求めるためには、C<Math::Trig::acos()> 関数を使うか、
2892逆余弦を求めるためには、L<C<Math::Trig::acos>|Math::Trig> 関数を使うか、
23862893以下の関係を使ってください。
23872894
23882895 sub acos { atan2( sqrt(1 - $_[0] * $_[0]), $_[0] ) }
23892896
23902897=item crypt PLAINTEXT,SALT
23912898X<crypt> X<digest> X<hash> X<salt> X<plaintext> X<password>
23922899X<decrypt> X<cryptography> X<passwd> X<encrypt>
23932900
23942901=for Pod::Functions one-way passwd-style encryption
23952902
23962903=begin original
23972904
2398Creates a digest string exactly like the crypt(3) function in the C
2905Creates a digest string exactly like the L<crypt(3)> function in the C
23992906library (assuming that you actually have a version there that has not
24002907been extirpated as a potential munition).
24012908
24022909=end original
24032910
2404C ライブラリの crypt(3) 関数と全く同じように、ダイジェスト文字列を
2911C ライブラリの L<crypt(3)> 関数と全く同じように、ダイジェスト文字列を
24052912作成します(一時的な必需品として、まだ絶滅していないバージョンを
24062913持っていると仮定しています)。
24072914
24082915=begin original
24092916
2410crypt() is a one-way hash function. The PLAINTEXT and SALT are turned
2917L<C<crypt>|/crypt PLAINTEXT,SALT> is a one-way hash function. The
2918PLAINTEXT and SALT are turned
24112919into a short string, called a digest, which is returned. The same
24122920PLAINTEXT and SALT will always return the same string, but there is no
24132921(known) way to get the original PLAINTEXT from the hash. Small
24142922changes in the PLAINTEXT or SALT will result in large changes in the
24152923digest.
24162924
24172925=end original
24182926
2419crypt() は一方向ハッシュ関数です。
2927L<C<crypt>|/crypt PLAINTEXT,SALT> は一方向ハッシュ関数です。
24202928PLAINTEXT と SALT はダイジェストと呼ばれる短い文字列に変えられて、
24212929それが返されます。
24222930PLAINTEXT と SALT が同じ場合は常に同じ文字列を返しますが、ハッシュから
24232931元の PLAINTEXT を得る(既知の)方法はありません。
24242932PLAINTEXT や SALT を少し変更してもダイジェストは大きく変更されます。
24252933
24262934=begin original
24272935
24282936There is no decrypt function. This function isn't all that useful for
24292937cryptography (for that, look for F<Crypt> modules on your nearby CPAN
24302938mirror) and the name "crypt" is a bit of a misnomer. Instead it is
24312939primarily used to check if two pieces of text are the same without
24322940having to transmit or store the text itself. An example is checking
24332941if a correct password is given. The digest of the password is stored,
24342942not the password itself. The user types in a password that is
2435crypt()'d with the same salt as the stored digest. If the two digests
2943L<C<crypt>|/crypt PLAINTEXT,SALT>'d with the same salt as the stored
2436match, the password is correct.
2944digest. If the two digests match, the password is correct.
24372945
24382946=end original
24392947
24402948復号化関数はありません。
24412949この関数は暗号化のためにはまったく役に立ちません(このためには、
24422950お近くの CPAN ミラーで F<Crypt> モジュールを探してください)ので、
24432951"crypt" という名前は少し間違った名前です。
24442952その代わりに、一般的には二つのテキスト片が同じかどうかをテキストそのものを
24452953転送したり保管したりせずにチェックするために使います。
24462954例としては、正しいパスワードが与えられたかどうかをチェックがあります。
24472955パスワード自身ではなく、パスワードのダイジェストが保管されます。
24482956ユーザーがパスワードを入力すると、保管されているダイジェストと同じ
2449salt で crypt() します。
2957salt で L<C<crypt>|/crypt PLAINTEXT,SALT> します。
24502958二つのダイジェストが同じなら、パスワードは正しいです。
24512959
24522960=begin original
24532961
24542962When verifying an existing digest string you should use the digest as
24552963the salt (like C<crypt($plain, $digest) eq $digest>). The SALT used
24562964to create the digest is visible as part of the digest. This ensures
2457crypt() will hash the new string with the same salt as the digest.
2965L<C<crypt>|/crypt PLAINTEXT,SALT> will hash the new string with the same
2458This allows your code to work with the standard L<crypt|/crypt> and
2966salt as the digest. This allows your code to work with the standard
2459with more exotic implementations. In other words, assume
2967L<C<crypt>|/crypt PLAINTEXT,SALT> and with more exotic implementations.
2460nothing about the returned string itself nor about how many bytes
2968In other words, assume nothing about the returned string itself nor
2461of SALT may matter.
2969about how many bytes of SALT may matter.
24622970
24632971=end original
24642972
24652973すでにあるダイジェスト文字列を検証するには、ダイジェストを
24662974(C<crypt($plain, $digest) eq $digest> のようにして)salt として使います。
24672975ダイジェストを作るのに使われた SALT はダイジェストの一部として見えます。
2468これにより、crypt() は同じ salt で新しい文字列をダイジェストとして
2976これにより、L<C<crypt>|/crypt PLAINTEXT,SALT> は同じ salt で新しい文字列を
2469ハッシュ化できるようにします。
2977ダイジェストとしてハッシュ化できるようにします。
2470これによって標準的な C<crypt|/crypt> や、より風変わりな実装でも動作します。
2978これによって標準的な L<C<crypt>|/crypt PLAINTEXT,SALT> や、より風変わりな
2979実装でも動作します。
24712980言い換えると、返される文字列や、SALT が何バイトあるかといったことに対して、
24722981どのような仮定もしてはいけません。
24732982
24742983=begin original
24752984
24762985Traditionally the result is a string of 13 bytes: two first bytes of
24772986the salt, followed by 11 bytes from the set C<[./0-9A-Za-z]>, and only
24782987the first eight bytes of PLAINTEXT mattered. But alternative
24792988hashing schemes (like MD5), higher level security schemes (like C2),
24802989and implementations on non-Unix platforms may produce different
24812990strings.
24822991
24832992=end original
24842993
24852994伝統的には結果は 13 バイトの文字列です: 最初の 2 バイトは salt、引き続いて
24862995集合 C<[./0-9A-Za-z]> からの 11 バイトで、PLAINTEXT の最初の
248729968 バイトだけが意味があります。
24882997しかし、(MD5 のように) 異なったハッシュ手法、
24892998(C2 のような) 高レベルセキュリティ手法、非 Unix プラットフォームでの
24902999実装などでは異なった文字列が生成されることがあります。
24913000
24923001=begin original
24933002
24943003When choosing a new salt create a random two character string whose
24953004characters come from the set C<[./0-9A-Za-z]> (like C<join '', ('.',
24963005'/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]>). This set of
24973006characters is just a recommendation; the characters allowed in
24983007the salt depend solely on your system's crypt library, and Perl can't
2499restrict what salts C<crypt()> accepts.
3008restrict what salts L<C<crypt>|/crypt PLAINTEXT,SALT> accepts.
25003009
25013010=end original
25023011
25033012新しい salt を選択する場合は、集合 C<[./0-9A-Za-z]> から
2504(C<join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]> のようにして)
3013(C<join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]> の
2505ランダムに2 つの文字を選びます。
3014ようにして)ランダムに2 つの文字を選びます。
25063015この文字集合は単なる推薦です; salt として許される文字はシステムの暗号化
2507ライブラリだけに依存し、Perl は C<crypt()> がどのような salt を受け付けるかに
3016ライブラリだけに依存し、Perl は L<C<crypt>|/crypt PLAINTEXT,SALT> が
2508ついて制限しません。
3017どのような salt を受け付けるかについて制限しません。
25093018
25103019=begin original
25113020
25123021Here's an example that makes sure that whoever runs this program knows
25133022their password:
25143023
25153024=end original
25163025
25173026プログラムを実行する人が、
25183027自分のパスワードを知っていることを確認する例です:
25193028
2520 $pwd = (getpwuid($<))[1];
3029 my $pwd = (getpwuid($<))[1];
25213030
25223031 system "stty -echo";
25233032 print "Password: ";
2524 chomp($word = <STDIN>);
3033 chomp(my $word = <STDIN>);
25253034 print "\n";
25263035 system "stty echo";
25273036
25283037 if (crypt($word, $pwd) ne $pwd) {
25293038 die "Sorry...\n";
25303039 } else {
25313040 print "ok\n";
25323041 }
25333042
25343043=begin original
25353044
25363045Of course, typing in your own password to whoever asks you
25373046for it is unwise.
25383047
25393048=end original
25403049
25413050もちろん、自分自身のパスワードを誰にでも入力するのは賢明ではありません。
25423051
25433052=begin original
25443053
2545The L<crypt|/crypt> function is unsuitable for hashing large quantities
3054The L<C<crypt>|/crypt PLAINTEXT,SALT> function is unsuitable for hashing
2546of data, not least of all because you can't get the information
3055large quantities of data, not least of all because you can't get the
2547back. Look at the L<Digest> module for more robust algorithms.
3056information back. Look at the L<Digest> module for more robust
3057algorithms.
25483058
25493059=end original
25503060
2551L<crypt|/crypt> 関数は大量のデータのハッシュ化には向いていません; これ
3061L<C<crypt>|/crypt PLAINTEXT,SALT> 関数は大量のデータのハッシュ化には
2552情報を戻せないという理由だけではありません。
3062向いていません; これは情報を戻せないという理由だけではありません。
25533063より頑強なアルゴリズムについては L<Digest> モジュールを参照してください。
25543064
25553065=begin original
25563066
2557If using crypt() on a Unicode string (which I<potentially> has
3067If using L<C<crypt>|/crypt PLAINTEXT,SALT> on a Unicode string (which
2558characters with codepoints above 255), Perl tries to make sense
3068I<potentially> has characters with codepoints above 255), Perl tries to
2559of the situation by trying to downgrade (a copy of)
3069make sense of the situation by trying to downgrade (a copy of) the
2560the string back to an eight-bit byte string before calling crypt()
3070string back to an eight-bit byte string before calling
2561(on that copy). If that works, good. If not, crypt() dies with
3071L<C<crypt>|/crypt PLAINTEXT,SALT> (on that copy). If that works, good.
2562C<Wide character in crypt>.
3072If not, L<C<crypt>|/crypt PLAINTEXT,SALT> dies with
3073L<C<Wide character in crypt>|perldiag/Wide character in %s>.
25633074
25643075=end original
25653076
25663077Unicode 文字列(I<潜在的には> 255 を越えるコードポイントを持つ文字を
2567含みます)に crypt() を使った場合、Perl は crypt() を呼び出す前に与えられた
3078含みます)に L<C<crypt>|/crypt PLAINTEXT,SALT> を使った場合、Perl は
3079L<C<crypt>|/crypt PLAINTEXT,SALT> を呼び出す前に与えられた
25683080文字列を8 ビットバイト文字列にダウングレードする(文字列のコピーを作る)
25693081ことで状況のつじつまを合わせようとします。
25703082うまく動けば、それでよし。
2571動かなければ、crypt() は C<Wide character in crypt> というメッセージと共に
3083動かなければ、L<C<crypt>|/crypt PLAINTEXT,SALT>
2572die します。
3084L<C<Wide character in crypt>|perldiag/Wide character in %s> という
3085メッセージと共に die します。
25733086
25743087=begin original
25753088
25763089Portability issues: L<perlport/crypt>.
25773090
25783091=end original
25793092
25803093移植性の問題: L<perlport/crypt>。
25813094
25823095=item dbmclose HASH
25833096X<dbmclose>
25843097
25853098=for Pod::Functions breaks binding on a tied dbm file
25863099
25873100=begin original
25883101
2589[This function has been largely superseded by the C<untie> function.]
3102[This function has been largely superseded by the
3103L<C<untie>|/untie VARIABLE> function.]
25903104
25913105=end original
25923106
2593[この関数は、C<untie> 関数に大きくとって代わられました。]
3107[この関数は、L<C<untie>|/untie VARIABLE> 関数に大きくとって代わられました。]
25943108
25953109=begin original
25963110
25973111Breaks the binding between a DBM file and a hash.
25983112
25993113=end original
26003114
26013115DBM ファイルとハッシュの連結をはずします。
26023116
26033117=begin original
26043118
26053119Portability issues: L<perlport/dbmclose>.
26063120
26073121=end original
26083122
26093123移植性の問題: L<perlport/dbmclose>。
26103124
26113125=item dbmopen HASH,DBNAME,MASK
26123126X<dbmopen> X<dbm> X<ndbm> X<sdbm> X<gdbm>
26133127
26143128=for Pod::Functions create binding on a tied dbm file
26153129
26163130=begin original
26173131
26183132[This function has been largely superseded by the
2619L<tie|/tie VARIABLE,CLASSNAME,LIST> function.]
3133L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function.]
26203134
26213135=end original
26223136
2623[この関数は、L<tie|/tie VARIABLE,CLASSNAME,LIST> 関数に
3137[この関数は、L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数に
26243138大きくとって代わられました。]
26253139
26263140=begin original
26273141
2628This binds a dbm(3), ndbm(3), sdbm(3), gdbm(3), or Berkeley DB file to a
3142This binds a L<dbm(3)>, L<ndbm(3)>, L<sdbm(3)>, L<gdbm(3)>, or Berkeley
2629hash. HASH is the name of the hash. (Unlike normal C<open>, the first
3143DB file to a hash. HASH is the name of the hash. (Unlike normal
2630argument is I<not> a filehandle, even though it looks like one). DBNAME
3144L<C<open>|/open FILEHANDLE,MODE,EXPR>, the first argument is I<not> a
2631is the name of the database (without the F<.dir> or F<.pag> extension if
3145filehandle, even though it looks like one). DBNAME is the name of the
2632any). If the database does not exist, it is created with protection
3146database (without the F<.dir> or F<.pag> extension if any). If the
2633specified by MASK (as modified by the C<umask>). To prevent creation of
3147database does not exist, it is created with protection specified by MASK
2634the database if it doesn't exist, you may specify a MODE
3148(as modified by the L<C<umask>|/umask EXPR>). To prevent creation of
2635of 0, and the function will return a false value if it
3149the database if it doesn't exist, you may specify a MASK of 0, and the
2636can't find an existing database. If your system supports
3150function will return a false value if it can't find an existing
2637only the older DBM functions, you may make only one C<dbmopen> call in your
3151database. If your system supports only the older DBM functions, you may
3152make only one L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> call in your
26383153program. In older versions of Perl, if your system had neither DBM nor
2639ndbm, calling C<dbmopen> produced a fatal error; it now falls back to
3154ndbm, calling L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> produced a fatal
2640sdbm(3).
3155error; it now falls back to L<sdbm(3)>.
26413156
26423157=end original
26433158
2644dbm(3), ndbm(3), sdbm(3), gdbm(3) ファイルまたは Berkeley DB ファイルを
3159L<dbm(3)>, L<ndbm(3)>, L<sdbm(3)>, L<gdbm(3)> ファイルまたは
2645連想配列に結び付けます。
3160Berkeley DB ファイルを連想配列に結び付けます。
26463161HASH は、その連想配列の名前です。
2647(普通の C<open> とは違って、最初の引数はファイルハンドル I<ではありません>;
3162(普通の L<C<open>|/open FILEHANDLE,MODE,EXPR> とは違って、最初の引数は
2648まあ、似たようなものですが)。
3163ファイルハンドル I<ではありません>; まあ、似たようなものですが)。
26493164DBNAME は、データベースの名前です (拡張子の .dir や .pag はもしあっても
26503165つけません)。
2651データベースが存在しなければ、MODE MASK (を C<umask> で修正したもの)
3166データベースが存在しなければ、MASK (を L<C<umask>|/umask EXPR>
2652指定されたモードで作られます。
3167修正したもの) で指定されたモードで作られます。
2653存在しないときにデータベースを作成しないようにするには、MODE に 0 を
3168存在しないときにデータベースを作成しないようにするには、MASK に 0 を
26543169設定でき、データベースを見つけられなかった場合は関数は偽を返します。
26553170古い DBM 関数のみをサポートしているシステムでは、プログラム中で 1 度だけ
2656dbmopen() を実行することができます。
3171L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を実行することができます。
26573172昔のバージョンの Perl では、DBM も ndbm も持っていないシステムでは、
2658dbmopen() を呼び出すと致命的エラーになります; 現在では sdbm(3) に
3173L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を呼び出すと致命的エラーになります;
2659フォールバックします。
3174現在では L<sdbm(3)> にフォールバックします。
26603175
26613176=begin original
26623177
26633178If you don't have write access to the DBM file, you can only read hash
26643179variables, not set them. If you want to test whether you can write,
2665either use file tests or try setting a dummy hash entry inside an C<eval>
3180either use file tests or try setting a dummy hash entry inside an
2666to trap the error.
3181L<C<eval>|/eval EXPR> to trap the error.
26673182
26683183=end original
26693184
26703185DBM ファイルに対して、書き込み権が無いときには、ハッシュ
26713186配列を読みだすことだけができ、設定することはできません。
26723187書けるか否かを調べたい場合には、ファイルテスト
2673演算子を使うか、エラーをトラップするための C<eval> の中で、
3188演算子を使うか、エラーをトラップするための L<C<eval>|/eval EXPR> の中で、
26743189ダミーのハッシュエントリを設定してみることになります。
26753190
26763191=begin original
26773192
2678Note that functions such as C<keys> and C<values> may return huge lists
3193Note that functions such as L<C<keys>|/keys HASH> and
2679when used on large DBM files. You may prefer to use the C<each>
3194L<C<values>|/values HASH> may return huge lists when used on large DBM
2680function to iterate over large DBM files. Example:
3195files. You may prefer to use the L<C<each>|/each HASH> function to
3196iterate over large DBM files. Example:
26813197
26823198=end original
26833199
2684大きな DBM ファイルを扱うときには、C<keys> や C<values> のような関数は、
3200大きな DBM ファイルを扱うときには、L<C<keys>|/keys HASH>
2685巨大なリストを返します。
3201L<C<values>|/values HASH> のような関数は、巨大なリストを返します。
2686大きな DBM ファイルでは、C<each> 関数を使って繰り返しを行なった方が
3202大きな DBM ファイルでは、L<C<each>|/each HASH> 関数を使って繰り返しを
2687良いかもしれません。
3203行なった方が良いかもしれません。
26883204例:
26893205
26903206 # print out history file offsets
26913207 dbmopen(%HIST,'/usr/lib/news/history',0666);
26923208 while (($key,$val) = each %HIST) {
26933209 print $key, ' = ', unpack('L',$val), "\n";
26943210 }
26953211 dbmclose(%HIST);
26963212
26973213=begin original
26983214
26993215See also L<AnyDBM_File> for a more general description of the pros and
27003216cons of the various dbm approaches, as well as L<DB_File> for a particularly
27013217rich implementation.
27023218
27033219=end original
27043220
27053221様々な dbm 手法に対する利点欠点に関するより一般的な記述および
27063222特にリッチな実装である L<DB_File> に関しては
27073223L<AnyDBM_File> も参照してください。
27083224
27093225=begin original
27103226
27113227You can control which DBM library you use by loading that library
2712before you call dbmopen():
3228before you call L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>:
27133229
27143230=end original
27153231
2716dbmopen() を呼び出す前にライブラリを読み込むことで、
3232L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を呼び出す前にライブラリを
2717どの DBM ライブラリを使うかを制御できます:
3233読み込むことで、どの DBM ライブラリを使うかを制御できます:
27183234
27193235 use DB_File;
27203236 dbmopen(%NS_Hist, "$ENV{HOME}/.netscape/history.db")
27213237 or die "Can't open netscape history file: $!";
27223238
27233239=begin original
27243240
27253241Portability issues: L<perlport/dbmopen>.
27263242
27273243=end original
27283244
27293245移植性の問題: L<perlport/dbmopen>。
27303246
27313247=item defined EXPR
27323248X<defined> X<undef> X<undefined>
27333249
27343250=item defined
27353251
27363252=for Pod::Functions test whether a value, variable, or function is defined
27373253
27383254=begin original
27393255
2740Returns a Boolean value telling whether EXPR has a value other than
3256Returns a Boolean value telling whether EXPR has a value other than the
2741the undefined value C<undef>. If EXPR is not present, C<$_> is
3257undefined value L<C<undef>|/undef EXPR>. If EXPR is not present,
2742checked.
3258L<C<$_>|perlvar/$_> is checked.
27433259
27443260=end original
27453261
2746左辺値 EXPR が未定義値 C<undef> 以外の値を持つか否かを示す、ブール値を
3262左辺値 EXPR が未定義値 L<C<undef>|/undef EXPR> 以外の値を持つか否かを示す、
2747返します。
3263ブール値を返します。
2748EXPR がない場合は、C<$_> がチェックされます。
3264EXPR がない場合は、L<C<$_>|perlvar/$_> がチェックされます。
27493265
27503266=begin original
27513267
2752Many operations return C<undef> to indicate failure, end of file,
3268Many operations return L<C<undef>|/undef EXPR> to indicate failure, end
2753system error, uninitialized variable, and other exceptional
3269of file, system error, uninitialized variable, and other exceptional
2754conditions. This function allows you to distinguish C<undef> from
3270conditions. This function allows you to distinguish
2755other values. (A simple Boolean test will not distinguish among
3271L<C<undef>|/undef EXPR> from other values. (A simple Boolean test will
2756C<undef>, zero, the empty string, and C<"0">, which are all equally
3272not distinguish among L<C<undef>|/undef EXPR>, zero, the empty string,
2757false.) Note that since C<undef> is a valid scalar, its presence
3273and C<"0">, which are all equally false.) Note that since
2758doesn't I<necessarily> indicate an exceptional condition: C<pop>
3274L<C<undef>|/undef EXPR> is a valid scalar, its presence doesn't
2759returns C<undef> when its argument is an empty array, I<or> when the
3275I<necessarily> indicate an exceptional condition: L<C<pop>|/pop ARRAY>
2760element to return happens to be C<undef>.
3276returns L<C<undef>|/undef EXPR> when its argument is an empty array,
3277I<or> when the element to return happens to be L<C<undef>|/undef EXPR>.
27613278
27623279=end original
27633280
27643281多くの演算子が、EOF や未初期化変数、システムエラーといった、
2765例外的な条件で C<undef> を返すようになっています。
3282例外的な条件で L<C<undef>|/undef EXPR> を返すようになっています。
2766この関数は、他の値と C<undef> とを区別するために使えます。
3283この関数は、他の値と L<C<undef>|/undef EXPR> とを区別するために使えます。
2767(単純な真偽値テストでは、C<undef>、0、C<"0"> のいずれも偽を返すので、
3284(単純な真偽値テストでは、L<C<undef>|/undef EXPR>、0、C<"0"> のいずれも偽を
2768区別することができません。)
3285返すので、区別することができません。)
2769C<undef> は有効なスカラ値なので、その存在が I<必ずしも>
3286L<C<undef>|/undef EXPR> は有効なスカラ値なので、その存在が I<必ずしも>
27703287例外的な状況を表すとは限らないということに注意してください:
2771C<pop> は引数が空の配列だったときに C<undef> を返しますが、
3288L<C<pop>|/pop ARRAY> は引数が空の配列だったときに L<C<undef>|/undef EXPR>
2772I<あるいは> 返すべき要素がたまたま C<undef> だったのかもしれません。
3289返しますが、I<あるいは> 返すべき要素がたまたま
3290L<C<undef>|/undef EXPR> だったのかもしれません。
27733291
27743292=begin original
27753293
2776You may also use C<defined(&func)> to check whether subroutine C<&func>
3294You may also use C<defined(&func)> to check whether subroutine C<func>
27773295has ever been defined. The return value is unaffected by any forward
2778declarations of C<&func>. A subroutine that is not defined
3296declarations of C<func>. A subroutine that is not defined
27793297may still be callable: its package may have an C<AUTOLOAD> method that
27803298makes it spring into existence the first time that it is called; see
27813299L<perlsub>.
27823300
27833301=end original
27843302
2785C<defined(&func)> とすることでサブルーチン C<&func> の存在を、
3303C<defined(&func)> とすることでサブルーチン C<func> の存在を、
27863304確かめることもできます。
2787返り値は C<&func> の前方定義には影響されません。
3305返り値は C<func> の前方定義には影響されません。
27883306定義されていないサブルーチンも呼び出し可能です:
27893307最初に呼び出されたときに存在するようにするための
27903308C<AUTOLOAD> メソッドを持ったパッケージかもしれません;
27913309L<perlsub> を参照してください。
27923310
27933311=begin original
27943312
2795Use of C<defined> on aggregates (hashes and arrays) is deprecated. It
3313Use of L<C<defined>|/defined EXPR> on aggregates (hashes and arrays) is
2796used to report whether memory for that aggregate had ever been
3314no longer supported. It used to report whether memory for that
2797allocated. This behavior may disappear in future versions of Perl.
3315aggregate had ever been allocated. You should instead use a simple
2798You should instead use a simple test for size:
3316test for size:
27993317
28003318=end original
28013319
2802集合(ハッシュや配列)への C<defined> の使用は非推奨です。
3320集合(ハッシュや配列)への L<C<defined>|/defined EXPR> の使用は
2803これその集合にメモリが割り当られたかを報告するのに
3321や対応しいません。
2804用いられていました。
3322これはその集合にメモリが割り当てられたかを報告するのに用いられていました。
2805この振る舞いは将来のバージョンの Perl では消滅するかもしれません。
28063323代わりにサイズに対する簡単なテストを使うべきです。
28073324
28083325 if (@an_array) { print "has array elements\n" }
28093326 if (%a_hash) { print "has hash members\n" }
28103327
28113328=begin original
28123329
28133330When used on a hash element, it tells you whether the value is defined,
2814not whether the key exists in the hash. Use L</exists> for the latter
3331not whether the key exists in the hash. Use L<C<exists>|/exists EXPR>
2815purpose.
3332for the latter purpose.
28163333
28173334=end original
28183335
28193336ハッシュの要素に対して用いると、value が定義されているか否かを
28203337返すものであって、ハッシュに key が存在するか否かを返すのではありません。
2821この用途には、L</exists> を使ってください。
3338この用途には、L<C<exists>|/exists EXPR> を使ってください。
28223339
28233340=begin original
28243341
28253342Examples:
28263343
28273344=end original
28283345
28293346例:
28303347
28313348 print if defined $switch{D};
28323349 print "$val\n" while defined($val = pop(@ary));
28333350 die "Can't readlink $sym: $!"
28343351 unless defined($value = readlink $sym);
2835 sub foo { defined &$bar ? &$bar(@_) : die "No bar"; }
3352 sub foo { defined &$bar ? $bar->(@_) : die "No bar"; }
28363353 $debugging = 0 unless defined $debugging;
28373354
28383355=begin original
28393356
2840Note: Many folks tend to overuse C<defined> and are then surprised to
3357Note: Many folks tend to overuse L<C<defined>|/defined EXPR> and are
2841discover that the number C<0> and C<""> (the zero-length string) are, in fact,
3358then surprised to discover that the number C<0> and C<""> (the
2842defined values. For example, if you say
3359zero-length string) are, in fact, defined values. For example, if you
3360say
28433361
28443362=end original
28453363
2846注意: 多くの人々が C<defined> を使いすぎて、C<0> と C<"">(空文字列) が
3364注意: 多くの人々が L<C<defined>|/defined EXPR> を使いすぎて、C<0> と
2847実際のところ定義された値であることに驚くようです。
3365C<"">(空文字列) が実際のところ定義された値であることに驚くようです。
28483366例えば、以下のように書くと:
28493367
28503368 "ab" =~ /a(.*)b/;
28513369
28523370=begin original
28533371
28543372The pattern match succeeds and C<$1> is defined, although it
28553373matched "nothing". It didn't really fail to match anything. Rather, it
28563374matched something that happened to be zero characters long. This is all
28573375very above-board and honest. When a function returns an undefined value,
28583376it's an admission that it couldn't give you an honest answer. So you
2859should use C<defined> only when questioning the integrity of what
3377should use L<C<defined>|/defined EXPR> only when questioning the
2860you're trying to do. At other times, a simple comparison to C<0> or C<""> is
3378integrity of what you're trying to do. At other times, a simple
2861what you want.
3379comparison to C<0> or C<""> is what you want.
28623380
28633381=end original
28643382
28653383パターンマッチングが成功し、C<$1> が定義されても、実際には
28663384「なし」にマッチしています。
28673385しかしこれは何にもマッチしていないわけではありません。
28683386何かにはマッチしているのですが、たまたまそれが長さ 0 だっただけです。
28693387これは非常に率直で正直なことです。
28703388関数が未定義値を返すとき、正直な答えを返すことができないことを
28713389告白しています。
28723390ですので、あなたが自分がしようとしていることの完全性を確認するときにだけ
2873C<defined> を使うべきです。
3391L<C<defined>|/defined EXPR> を使うべきです。
28743392その他の場合では、単に C<0> または C<""> と比較するというのがあなたの
28753393求めているものです。
28763394
28773395=begin original
28783396
2879See also L</undef>, L</exists>, L</ref>.
3397See also L<C<undef>|/undef EXPR>, L<C<exists>|/exists EXPR>,
3398L<C<ref>|/ref EXPR>.
28803399
28813400=end original
28823401
2883L</undef>, L</exists>, L</ref> も参照してください。
3402L<C<undef>|/undef EXPR>, L<C<exists>|/exists EXPR>, L<C<ref>|/ref EXPR> も
3403参照してください。
28843404
28853405=item delete EXPR
28863406X<delete>
28873407
28883408=for Pod::Functions deletes a value from a hash
28893409
28903410=begin original
28913411
2892Given an expression that specifies an element or slice of a hash, C<delete>
3412Given an expression that specifies an element or slice of a hash,
2893deletes the specified elements from that hash so that exists() on that element
3413L<C<delete>|/delete EXPR> deletes the specified elements from that hash
2894no longer returns true. Setting a hash element to the undefined value does
3414so that L<C<exists>|/exists EXPR> on that element no longer returns
2895not remove its key, but deleting it does; see L</exists>.
3415true. Setting a hash element to the undefined value does not remove its
3416key, but deleting it does; see L<C<exists>|/exists EXPR>.
28963417
28973418=end original
28983419
2899ハッシュの要素やスライスを指定する式を取り、C<delete> は
3420ハッシュの要素やスライスを指定する式を取り、L<C<delete>|/delete EXPR> は
29003421指定された要素をハッシュから削除するので、
2901その要素に対する exists() はもはや真を返さなくなります。
3422その要素に対する L<C<exists>|/exists EXPR> はもはや真を返さなくなります。
29023423ハッシュ要素に未定義値をセットしてもそのキーは削除されませんが、
2903delete では削除されます; L</exists> を参照してください。
3424delete では削除されます; L<C<exists>|/exists EXPR> を参照してください。
29043425
29053426=begin original
29063427
2907In list context, returns the value or values deleted, or the last such
3428In list context, usually returns the value or values deleted, or the last such
2908element in scalar context. The return list's length always matches that of
3429element in scalar context. The return list's length corresponds to that of
29093430the argument list: deleting non-existent elements returns the undefined value
2910in their corresponding positions.
3431in their corresponding positions. Since Perl 5.28, a
3432L<keyE<sol>value hash slice|perldata/KeyE<sol>Value Hash Slices> can be passed
3433to C<delete>, and the return value is a list of key/value pairs (two elements
3434for each item deleted from the hash).
29113435
29123436=end original
29133437
2914リストコンテキストでは削除された要素を返し、スカラコンテキストでは
3438リストコンテキストでは通常は削除された要素を返し、スカラコンテキストでは
29153439削除された要素のうち最後のものを返します。
2916返されたリストの長さは常に引数リストの長さと一致します:
3440返されたリストの長さは常に引数リストの長さに対応します:
29173441存在しない要素を削除すると、対応する位置に未定義値をセットして返します。
3442Perl 5.28 から、
3443L<キーE<sol>値ハッシュスライス|perldata/KeyE<sol>Value Hash Slices> を
3444C<delete> に渡すことができ、
3445そして返り値はキー/値の組(それぞれのアイテムについて
3446二つの要素が元のハッシュから削除されたもの)です。
29183447
29193448=begin original
29203449
2921delete() may also be used on arrays and array slices, but its behavior is less
3450L<C<delete>|/delete EXPR> may also be used on arrays and array slices,
2922straightforward. Although exists() will return false for deleted entries,
3451but its behavior is less straightforward. Although
2923deleting array elements never changes indices of existing values; use shift()
3452L<C<exists>|/exists EXPR> will return false for deleted entries,
2924or splice() for that. However, if all deleted elements fall at the end of an
3453deleting array elements never changes indices of existing values; use
2925array, the array's size shrinks to the position of the highest element that
3454L<C<shift>|/shift ARRAY> or L<C<splice>|/splice
2926still tests true for exists(), or to 0 if none do.
3455ARRAY,OFFSET,LENGTH,LIST> for that. However, if any deleted elements
3456fall at the end of an array, the array's size shrinks to the position of
3457the highest element that still tests true for L<C<exists>|/exists EXPR>,
3458or to 0 if none do. In other words, an array won't have trailing
3459nonexistent elements after a delete.
29273460
29283461=end original
29293462
2930delete() は配列や配列のスライスに対しても使えますが、その振る舞いは
3463L<C<delete>|/delete EXPR> は配列や配列のスライスに対しても使えますが、その
2931あまり直感的ではありません。
3464振る舞いはあまり直感的ではありません。
2932削除されたエントリに対しては exists() は偽を返しますが、
3465削除されたエントリに対しては L<C<exists>|/exists EXPR> は偽を返しますが、
29333466配列要素を削除しても、存在する値の添え字は変わりません; このためには
2934shift() や splice()使ってください。
3467L<C<shift>|/shift ARRAY> L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST>
2935しかし、全の削除れた要素が配列の末尾であった場合、配列のサイズは
3468使っくだい。
2936exists() が真となる最大位置の要素(それない場合は 0)に切り詰められます。
3469しかし、削除された要素が配列の末尾であった場合、配列のサイズ
3470L<C<exists>|/exists EXPR> が真となる最大位置の要素(それがない場合は 0)に
3471切り詰められます。
3472言い換えると、delete の後には配列の末尾に値のない要素はありません。
29373473
29383474=begin original
29393475
2940B<WARNING:> Calling delete on array values is deprecated and likely to
3476B<WARNING:> Calling L<C<delete>|/delete EXPR> on array values is
2941be removed in a future version of Perl.
3477strongly discouraged. The
3478notion of deleting or checking the existence of Perl array elements is not
3479conceptually coherent, and can lead to surprising behavior.
29423480
29433481=end original
29443482
2945B<警告:> 配列の値に対して delete を呼び出すことは非推奨で、将来の
3483B<警告:> 配列の値に対して L<C<delete>|/delete EXPR> を呼び出すことは強く
2946バージョンの Perl では削除される予定です。
3484非推奨です。
3485Perl の配列要素を削除したり存在を調べたりする記法は概念的に一貫しておらず、
3486驚くべき振る舞いを引き起こすことがあります。
29473487
29483488=begin original
29493489
2950Deleting from C<%ENV> modifies the environment. Deleting from a hash tied to
3490Deleting from L<C<%ENV>|perlvar/%ENV> modifies the environment.
2951a DBM file deletes the entry from the DBM file. Deleting from a C<tied> hash
3491Deleting from a hash tied to a DBM file deletes the entry from the DBM
2952or array may not necessarily return anything; it depends on the implementation
3492file. Deleting from a L<C<tied>|/tied VARIABLE> hash or array may not
2953of the C<tied> package's DELETE method, which may do whatever it pleases.
3493necessarily return anything; it depends on the implementation of the
3494L<C<tied>|/tied VARIABLE> package's DELETE method, which may do whatever
3495it pleases.
29543496
29553497=end original
29563498
2957C<%ENV> から削除を行なうと、実際に環境変数を変更します。
3499L<C<%ENV>|perlvar/%ENV> から削除を行なうと、実際に環境変数を変更します。
29583500DBM ファイルに tie された配列からの削除は、その DBM ファイルからエントリを
29593501削除します。
2960しかし、C<tie> されたハッシュや配列からの削除は、
3502しかし、L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> されたハッシュや配列からの
2961値を返すとは限りません; これは C<tie> されたパッケージの DELETE
3503削除は、値を返すとは限りません; これは
3504L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> されたパッケージの DELETE
29623505メソッドの実装に依存するので、どんなことでも起こります。
29633506
29643507=begin original
29653508
29663509The C<delete local EXPR> construct localizes the deletion to the current
29673510block at run time. Until the block exits, elements locally deleted
29683511temporarily no longer exist. See L<perlsub/"Localized deletion of elements
29693512of composite types">.
29703513
29713514=end original
29723515
29733516C<delete local EXPR> 構文は、現在のブロックの削除を実行時にローカル化します。
29743517ブロックから出るまで、ローカルで削除された要素は存在しなくなります。
29753518L<perlsub/"Localized deletion of elements of composite types"> を
29763519参照してください。
29773520
2978 %hash = (foo => 11, bar => 22, baz => 33);
3521 my %hash = (foo => 11, bar => 22, baz => 33);
2979 $scalar = delete $hash{foo}; # $scalar is 11
3522 my $scalar = delete $hash{foo}; # $scalar is 11
29803523 $scalar = delete @hash{qw(foo bar)}; # $scalar is 22
2981 @array = delete @hash{qw(foo baz)}; # @array is (undef,33)
3524 my @array = delete @hash{qw(foo baz)}; # @array is (undef,33)
29823525
29833526=begin original
29843527
29853528The following (inefficiently) deletes all the values of %HASH and @ARRAY:
29863529
29873530=end original
29883531
29893532以下は、%HASH と @ARRAY のすべての値を(非効率的に)削除します:
29903533
2991 foreach $key (keys %HASH) {
3534 foreach my $key (keys %HASH) {
29923535 delete $HASH{$key};
29933536 }
29943537
2995 foreach $index (0 .. $#ARRAY) {
3538 foreach my $index (0 .. $#ARRAY) {
29963539 delete $ARRAY[$index];
29973540 }
29983541
29993542=begin original
30003543
30013544And so do these:
30023545
30033546=end original
30043547
30053548そして以下のようにもできます:
30063549
30073550 delete @HASH{keys %HASH};
30083551
30093552 delete @ARRAY[0 .. $#ARRAY];
30103553
30113554=begin original
30123555
30133556But both are slower than assigning the empty list
3014or undefining %HASH or @ARRAY, which is the customary
3557or undefining %HASH or @ARRAY, which is the customary
30153558way to empty out an aggregate:
30163559
30173560=end original
30183561
30193562しかし、これら二つは両方とも、構造を空にするための慣習的な方法である、
30203563単に空リストを代入するか、%HASH や @ARRAY を
30213564undef するより遅いです:
30223565
30233566 %HASH = (); # completely empty %HASH
30243567 undef %HASH; # forget %HASH ever existed
30253568
30263569 @ARRAY = (); # completely empty @ARRAY
30273570 undef @ARRAY; # forget @ARRAY ever existed
30283571
30293572=begin original
30303573
30313574The EXPR can be arbitrarily complicated provided its
30323575final operation is an element or slice of an aggregate:
30333576
30343577=end original
30353578
30363579最終的な操作が集合の要素かスライスである限りは、
30373580いずれかである限りは、EXPR には任意の複雑な式を置くことができます:
30383581
30393582 delete $ref->[$x][$y]{$key};
3040 delete @{$ref->[$x][$y]}{$key1, $key2, @morekeys};
3583 delete $ref->[$x][$y]->@{$key1, $key2, @morekeys};
30413584
30423585 delete $ref->[$x][$y][$index];
3043 delete @{$ref->[$x][$y]}[$index1, $index2, @moreindices];
3586 delete $ref->[$x][$y]->@[$index1, $index2, @moreindices];
30443587
30453588=item die LIST
30463589X<die> X<throw> X<exception> X<raise> X<$@> X<abort>
30473590
30483591=for Pod::Functions raise an exception or bail out
30493592
30503593=begin original
30513594
3052C<die> raises an exception. Inside an C<eval> the error message is stuffed
3595L<C<die>|/die LIST> raises an exception. Inside an L<C<eval>|/eval EXPR>
3053into C<$@> and the C<eval> is terminated with the undefined value.
3596the exception is stuffed into L<C<$@>|perlvar/$@> and the L<C<eval>|/eval
3054If the exception is outside of all enclosing C<eval>s, then the uncaught
3597EXPR> is terminated with the undefined value. If the exception is
3055exception prints LIST to C<STDERR> and exits with a non-zero value. If you
3598outside of all enclosing L<C<eval>|/eval EXPR>s, then the uncaught
3056need to exit the process with a specific exit code, see L</exit>.
3599exception is printed to C<STDERR> and perl exits with an exit code
3600indicating failure. If you need to exit the process with a specific
3601exit code, see L<C<exit>|/exit EXPR>.
30573602
30583603=end original
30593604
3060C<die> は例外を発生させます。
3605L<C<die>|/die LIST> は例外を発生させます。
3061C<eval> の中で使用すると、エラーメッセージ C<$@> に入り、C<eval> は
3606L<C<eval>|/eval EXPR> の中で使用すると、例外
3607L<C<$@>|perlvar/$@> に入り、L<C<eval>|/eval EXPR> は
30623608未定義値を返して終了します。
3063例外が全ての C<eval> の外側の場合は、捕捉されなかった例外は LIST を
3609例外が全ての L<C<eval>|/eval EXPR> の外側の場合は、捕捉されなかった例外は
3064C<STDERR> に表示して 0 の値で終了します。
3610C<STDERR> に表示されperl は失敗を示す終了コードで終了します。
3065特定の終了コードでプロセスを終了させる必要がある場合は、L</exit> を
3611特定の終了コードでプロセスを終了させる必要がある場合は、
3066参照してください。
3612L<C<exit>|/exit EXPR> を参照してください。
30673613
30683614=begin original
30693615
30703616Equivalent examples:
30713617
30723618=end original
30733619
30743620等価な例:
30753621
30763622 die "Can't cd to spool: $!\n" unless chdir '/usr/spool/news';
30773623 chdir '/usr/spool/news' or die "Can't cd to spool: $!\n"
30783624
30793625=begin original
30803626
3081If the last element of LIST does not end in a newline, the current
3627Most of the time, C<die> is called with a string to use as the exception.
3082script line number and input line number (if any) are also printed,
3628You may either give a single non-reference operand to serve as the
3083and a newline is supplied. Note that the "input line number" (also
3629exception, or a list of two or more items, which will be stringified
3630and concatenated to make the exception.
3631
3632=end original
3633
3634ほとんどの場合、C<die> は例外として使うための文字列と共に呼び出されます。
3635例外として圧から割れる単一の非リファレンスオペランドか、
3636例外を作るために文字列化されて連結される、二つ以上のアイテムのリストを
3637指定することができます。
3638
3639=begin original
3640
3641If the string exception does not end in a newline, the current
3642script line number and input line number (if any) and a newline
3643are appended to it. Note that the "input line number" (also
30843644known as "chunk") is subject to whatever notion of "line" happens to
30853645be currently in effect, and is also available as the special variable
3086C<$.>. See L<perlvar/"$/"> and L<perlvar/"$.">.
3646L<C<$.>|perlvar/$.>. See L<perlvar/"$/"> and L<perlvar/"$.">.
30873647
30883648=end original
30893649
3090LIST の最後の要素が改行で終わっていなければ、その時点のスクリプト名と
3650文字列例外が改行で終わっていなければ、その時点のスクリプト名と
3091スクリプトの行番号、(もしあれば) 入力ファイルの行番号と改行文字が、続けて
3651スクリプトの行番号、(もしあれば) 入力ファイルの行番号と改行文字が
3092表示されます。
3652それに追加されます。
30933653「入力行番号」("chunk" とも呼ばれます)は「行」という概念が現在有効であると
3094仮定しています; また特殊変数 C<$.> でも利用可能です。
3654仮定しています; また特殊変数 L<C<$.>|perlvar/$.> でも利用可能です。
30953655L<perlvar/"$/"> と L<perlvar/"$."> も参照してください。
30963656
30973657=begin original
30983658
30993659Hint: sometimes appending C<", stopped"> to your message will cause it
31003660to make better sense when the string C<"at foo line 123"> is appended.
31013661Suppose you are running script "canasta".
31023662
31033663=end original
31043664
31053665ヒント: メッセージの最後を C<", stopped"> のようなもので
31063666終わるようにしておけば、C<"at foo line 123"> のように
31073667追加されて、わかりやすくなります。
31083668"canasta" というスクリプトを実行しているとします。
31093669
31103670 die "/etc/games is no good";
31113671 die "/etc/games is no good, stopped";
31123672
31133673=begin original
31143674
31153675produce, respectively
31163676
31173677=end original
31183678
31193679これは、それぞれ以下のように表示します。
31203680
31213681 /etc/games is no good at canasta line 123.
31223682 /etc/games is no good, stopped at canasta line 123.
31233683
31243684=begin original
31253685
3126If the output is empty and C<$@> already contains a value (typically from a
3686If LIST was empty or made an empty string, and L<C<$@>|perlvar/$@>
3127previous eval) that value is reused after appending C<"\t...propagated">.
3687already contains an exception value (typically from a previous
3128This is useful for propagating exceptions:
3688L<C<eval>|/eval EXPR>), then that value is reused after
3689appending C<"\t...propagated">. This is useful for propagating exceptions:
31293690
31303691=end original
31313692
3132出力が空C<$@> が(典型的には前回の eval で)既に値を持っている場合、
3693出力が空か空文字列を作り、L<C<$@>|perlvar/$@>
3694(典型的には前回の L<C<eval>|/eval EXPR> で)
3695既に例外値を持っている場合、
31333696値は C<"\t...propagated"> を追加した後再利用されます。
31343697これは例外を伝播させる場合に有効です:
31353698
31363699 eval { ... };
31373700 die unless $@ =~ /Expected exception/;
31383701
31393702=begin original
31403703
3141If the output is empty and C<$@> contains an object reference that has a
3704If LIST was empty or made an empty string,
3142C<PROPAGATE> method, that method will be called with additional file
3705and L<C<$@>|perlvar/$@> contains an object
3143and line number parameters. The return value replaces the value in
3706reference that has a C<PROPAGATE> method, that method will be called
3144C<$@>; i.e., as if C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >>
3707with additional file and line number parameters. The return value
3145were called.
3708replaces the value in L<C<$@>|perlvar/$@>; i.e., as if
3709C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >> were called.
31463710
31473711=end original
31483712
3149出力が空、C<$@> が C<PROPAGATE> メソッドを含むオブジェクトへの
3713出力が空か空文字列を作りL<C<$@>|perlvar/$@> が C<PROPAGATE> メソッドを
3150リファレンスを含む場合、このメソッドが追加ファイルと行番号を引数として
3714含むオブジェクトへのリファレンスを含む場合、
3151呼び出されます。
3715このメソッドが追加ファイルと行番号を引数として呼び出されます。
3152返り値は C<$@> の値を置き換えます;
3716返り値は L<C<$@>|perlvar/$@> の値を置き換えます;
31533717つまり、C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >> が
31543718呼び出されたかのようになります。
31553719
31563720=begin original
31573721
3158If C<$@> is empty then the string C<"Died"> is used.
3722If LIST was empty or made an empty string, and L<C<$@>|perlvar/$@>
3723is also empty, then the string C<"Died"> is used.
31593724
31603725=end original
31613726
3162C<$@> 空の場合、C<"Died"> が使われます。
3727LIST が空か空文字列を作り、L<C<$@>|perlvar/$@> 空の場合、
3728C<"Died"> が使われます。
31633729
31643730=begin original
31653731
3166If an uncaught exception results in interpreter exit, the exit code is
3732You can also call L<C<die>|/die LIST> with a reference argument, and if
3167determined from the values of C<$!> and C<$?> with this pseudocode:
3733this is trapped within an L<C<eval>|/eval EXPR>, L<C<$@>|perlvar/$@>
3734contains that reference. This permits more elaborate exception handling
3735using objects that maintain arbitrary state about the exception. Such a
3736scheme is sometimes preferable to matching particular string values of
3737L<C<$@>|perlvar/$@> with regular expressions.
31683738
31693739=end original
31703740
3171例外が捕捉されないとインタプリタ終了し終了コードは以下の
3741L<C<die>|/die LIST> リファレンス引数と共に呼び出すこともできこれが
3172擬似コードのように、C<$!> C<$?> の値から決定されます:
3742L<C<eval>|/eval EXPR> 内部でトラップされた場合、L<C<$@>|perlvar/$@>
3743そのリファレンスを持ちます。
3744これは、例外の性質について任意の状態を管理するオブジェクトを使った
3745より複雑な例外処理の実装を可能にします。
3746このようなスキームは L<C<$@>|perlvar/$@> の特定の文字列値を正規表現を使って
3747マッチングするときに時々好まれます。
31733748
3174 exit $! if $!; # errno
3175 exit $? >> 8 if $? >> 8; # child exit status
3176 exit 255; # last resort
3177
31783749=begin original
31793750
3180The intent is to squeeze as much possible information about the likely cause
3751Because Perl stringifies uncaught exception messages before display,
3181into the limited space of the system exit
3752you'll probably want to overload stringification operations on
3182code. However, as C<$!> is the value
3753exception objects. See L<overload> for details about that.
3183of C's C<errno>, which can be set by any system call, this means that the value
3754The stringified message should be non-empty, and should end in a newline,
3184of the exit code used by C<die> can be non-predictable, so should not be relied
3755in order to fit in with the treatment of string exceptions.
3185upon, other than to be non-zero.
3756Also, because an exception object reference cannot be stringified
3757without destroying it, Perl doesn't attempt to append location or other
3758information to a reference exception. If you want location information
3759with a complex exception object, you'll have to arrange to put the
3760location information into the object yourself.
31863761
31873762=end original
31883763
3189この意図、できるだけ多くの似たよう原因する情報をシステム終了
3764perl 捕らえられかった例外のメッセージを表示する前文字列化するので
3190ードという限られ領域に圧縮するこです。
3765このようなカスタム例外オブジェクトの文字列化をオバーロー
3191かし、C<$!> はシステムコールによって設定さる可能性がある C の
3766思うしれません。
3192C<errno> の値であり、C<die> によっ使われる終了コードの値は
3767これに関する詳細は L<overload> を参照しください。
3193予測不能であることを意味するので非 0 とうこと以上この値
3768文字列化されたメッセージは文字列例外の扱いに合わせるため
3194依存するべきではありません
3769空ではなく、末尾は改行であるべきで
3770また、例外オブジェクトリファレンスはそれを破壊することなく
3771文字列化することができないので、Perl はリファレンス例外に位置や
3772その他の情報を追加しようとしません。
3773複雑な例外オブジェクトに位置情報が欲しい場合、
3774オブジェクト自身に位置情報を設定するように用意する必要があります。
31953775
31963776=begin original
31973777
3198You can also call C<die> with a reference argument, and if this is trapped
3778Because L<C<$@>|perlvar/$@> is a global variable, be careful that
3199within an C<eval>, C<$@> contains that reference. This permits more
3779analyzing an exception caught by C<eval> doesn't replace the reference
3200elaborate exception handling using objects that maintain arbitrary state
3780in the global variable. It's
3201about the exception. Such a scheme is sometimes preferable to matching
3781easiest to make a local copy of the reference before any manipulations.
3202particular string values of C<$@> with regular expressions. Because C<$@>
3782Here's an example:
3203is a global variable and C<eval> may be used within object implementations,
3204be careful that analyzing the error object doesn't replace the reference in
3205the global variable. It's easiest to make a local copy of the reference
3206before any manipulations. Here's an example:
32073783
32083784=end original
32093785
3210die()リファレンス引と共に呼び出すこともこれが
3786L<C<$@>|perlvar/$@>グローバル変なので、
3211eval() 内部でトラップされた場合、C<$@> リファレンスを持ちます。
3787C<eval> により補足された例外の解析グローバル変数
3212これは、例外の性質について任意の状態を管理するオブジェクトを使った
3213より複雑な例外処理の実装を可能にします。
3214このようなスキームは C<$@> の特定の文字列値を正規表現を使って
3215マッチングするときに時々好まれます。
3216C<$@> はグローバル変数で、C<eval> はオブジェクト実装の内部で
3217使われることがあるので、エラーオブジェクトの解析はグローバル変数の
32183788リファレンスを置き換えないことに注意を払わなければなりません。
32193789他の操作をする前にリファレンスのローカルコピーを
32203790作るのが一番簡単です。
32213791以下に例を示します:
32223792
32233793 use Scalar::Util "blessed";
32243794
32253795 eval { ... ; die Some::Module::Exception->new( FOO => "bar" ) };
32263796 if (my $ev_err = $@) {
32273797 if (blessed($ev_err)
32283798 && $ev_err->isa("Some::Module::Exception")) {
32293799 # handle Some::Module::Exception
32303800 }
32313801 else {
32323802 # handle all other possible exceptions
32333803 }
32343804 }
32353805
32363806=begin original
32373807
3238Because Perl stringifies uncaught exception messages before display,
3808If an uncaught exception results in interpreter exit, the exit code is
3239you'll probably want to overload stringification operations on
3809determined from the values of L<C<$!>|perlvar/$!> and
3240exception objects. See L<overload> for details about that.
3810L<C<$?>|perlvar/$?> with this pseudocode:
32413811
32423812=end original
32433813
3244perl はらえられなかった例外のメッセジを表示する前に文字列化するで、
3814例外が捉されないとインタプリタは終了し、終了コドは以下
3245のようなカスタム例外オブジェクトの文字列化をオーバーロードしたい
3815擬似コードのように、L<C<$!>|perlvar/$!> L<C<$?>|perlvar/$?> の値から
3246思うかもしれません。
3816決定されます:
3247これに関する詳細は L<overload> を参照してください。
32483817
3818 exit $! if $!; # errno
3819 exit $? >> 8 if $? >> 8; # child exit status
3820 exit 255; # last resort
3821
32493822=begin original
32503823
3251You can arrange for a callback to be run just before the C<die>
3824As with L<C<exit>|/exit EXPR>, L<C<$?>|perlvar/$?> is set prior to
3252does its deed, by setting the C<$SIG{__DIE__}> hook. The associated
3825unwinding the call stack; any C<DESTROY> or C<END> handlers can then
3253handler is called with the error text and can change the error
3826alter this value, and thus Perl's exit code.
3254message, if it sees fit, by calling C<die> again. See
3255L<perlvar/%SIG> for details on setting C<%SIG> entries, and
3828=end original
3256L<"eval BLOCK"> for some examples. Although this feature was
3257to be run only right before your program was to exit, this is not
3830L<C<exit>|/exit EXPR> と同様に、コールスタックを巻き戻す前に
3258currently so: the C<$SIG{__DIE__}> hook is currently called
3831L<C<$?>|perlvar/$?> が設定されます; C<DESTROY> C<END> のハンドラが
3259even inside eval()ed blocks/strings! If one wants the hook to do
3832それからこの値を変更して、これが Perl の終了コードになります。
3833
3834=begin original
3835
3836The intent is to squeeze as much possible information about the likely cause
3837into the limited space of the system exit code. However, as
3838L<C<$!>|perlvar/$!> is the value of C's C<errno>, which can be set by
3839any system call, this means that the value of the exit code used by
3840L<C<die>|/die LIST> can be non-predictable, so should not be relied
3841upon, other than to be non-zero.
3842
3843=end original
3844
3845この意図は、できるだけ多くの似たような原因に関する情報を、システム終了
3846コードという限られた領域に圧縮することです。
3847しかし、L<C<$!>|perlvar/$!> はシステムコールによって設定される可能性がある C の
3848C<errno> の値であり、L<C<die>|/die LIST> によって使われる終了コードの値は
3849予測不能であることを意味するので、非 0 ということ以上にこの値に
3850依存するべきではありません。
3851
3852=begin original
3853
3854You can arrange for a callback to be run just before the
3855L<C<die>|/die LIST> does its deed, by setting the
3856L<C<$SIG{__DIE__}>|perlvar/%SIG> hook. The associated handler is called
3857with the exception as an argument, and can change the exception,
3858if it sees fit, by
3859calling L<C<die>|/die LIST> again. See L<perlvar/%SIG> for details on
3860setting L<C<%SIG>|perlvar/%SIG> entries, and L<C<eval>|/eval EXPR> for some
3861examples. Although this feature was to be run only right before your
3862program was to exit, this is not currently so: the
3863L<C<$SIG{__DIE__}>|perlvar/%SIG> hook is currently called even inside
3864L<C<eval>|/eval EXPR>ed blocks/strings! If one wants the hook to do
32603865nothing in such situations, put
32613866
32623867=end original
32633868
3264C<$SIG{__DIE__}> フックをセットすることで、C<die> がその行動を行う
3869L<C<$SIG{__DIE__}>|perlvar/%SIG> フックをセットすることで、
3870L<C<die>|/die LIST> がその行動を行う
32653871直前に実行されるコールバックを設定できます。
3266結び付けられたハンドラはエラーテキスト共に呼び出され、
3872結び付けられたハンドラは例外を引数して呼び出され、
3267必要なら再び C<die> を呼び出すことでエラーテキストを変更できアス
3873必要なら再び L<C<die>|/die LIST> を呼び出すことで例外を変更できます
3268C<%SIG> のエントリをセットする詳細については、L<perlvar/%SIG> を
3874L<C<%SIG>|perlvar/%SIG> のエントリをセットする詳細については、
3269例については L<"eval BLOCK"> を参照してください。
3875L<perlvar/%SIG> を、例については L<C<eval>|/eval EXPR> を参照してください。
32703876この機能はプログラムが終了しようとする前に 1 回だけ実行していましたが、
32713877現在ではそうではありません:
3272C<$SIG{__DIE__}> フックは eval() されたブロック/文字列の中でも
3878L<C<$SIG{__DIE__}>|perlvar/%SIG> フックは L<C<eval>|/eval EXPR> された
3273呼ばれるのです!
3879ブロック/文字列の中でも呼ばれるのです!
32743880もしそのような状況で何もしなくない時は:
32753881
32763882 die @_ if $^S;
32773883
32783884=begin original
32793885
32803886as the first line of the handler (see L<perlvar/$^S>). Because
32813887this promotes strange action at a distance, this counterintuitive
32823888behavior may be fixed in a future release.
32833889
32843890=end original
32853891
32863892をハンドラの最初の行に置いてください(L<perlvar/$^S> を参照してください)。
32873893これは離れたところで不思議な行動を引き起こすので、
32883894この直感的でない振る舞いは将来のリリースで修正されるかもしれません。
32893895
32903896=begin original
32913897
3292See also exit(), warn(), and the Carp module.
3898See also L<C<exit>|/exit EXPR>, L<C<warn>|/warn LIST>, and the L<Carp>
3899module.
32933900
32943901=end original
32953902
3296exit() と warn() と Carp モジュールも参照してください。
3903L<C<exit>|/exit EXPR> L<C<warn>|/warn LIST> L<Carp> モジュールも
3904参照してください。
32973905
32983906=item do BLOCK
32993907X<do> X<block>
33003908
33013909=for Pod::Functions turn a BLOCK into a TERM
33023910
33033911=begin original
33043912
33053913Not really a function. Returns the value of the last command in the
33063914sequence of commands indicated by BLOCK. When modified by the C<while> or
33073915C<until> loop modifier, executes the BLOCK once before testing the loop
33083916condition. (On other statements the loop modifiers test the conditional
33093917first.)
33103918
33113919=end original
33123920
33133921実際は関数ではありません。
33143922BLOCK で示されるコマンド列の最後の値を返します。
33153923C<while> や C<until> ループ修飾子で修飾すると、
33163924ループ条件を調べる前に 1 度、BLOCK を実行します。
33173925(これ以外の実行文は、ループ修飾子により、条件が最初に
33183926調べられます。)
33193927
33203928=begin original
33213929
33223930C<do BLOCK> does I<not> count as a loop, so the loop control statements
3323C<next>, C<last>, or C<redo> cannot be used to leave or restart the block.
3931L<C<next>|/next LABEL>, L<C<last>|/last LABEL>, or
3932L<C<redo>|/redo LABEL> cannot be used to leave or restart the block.
33243933See L<perlsyn> for alternative strategies.
33253934
33263935=end original
33273936
3328C<do BLOCK> はループとしては I<扱われません>; 従って、C<next>, C<last>,
3937C<do BLOCK> はループとしては I<扱われません>; 従って、L<C<next>|/next LABEL>,
3329C<redo> といったループ制御文はブロックから抜けたり
3938L<C<last>|/last LABEL>,L<C<redo>|/redo LABEL> といったループ制御文は
3330再開することはできません。
3939ブロックから抜けたり再開することはできません。
33313940その他の戦略については L<perlsyn> を参照してください。
33323941
3333=item do SUBROUTINE(LIST)
3334X<do>
3335
3336=begin original
3337
3338This form of subroutine call is deprecated. SUBROUTINE can be a bareword
3339or scalar variable.
3340
3341=end original
3342
3343この形のサブルーチン呼び出しは非推奨です。
3344SUBROUTINE には裸の単語またはスカラ変数が使えます。
3345
33463942=item do EXPR
33473943X<do>
33483944
33493945=begin original
33503946
33513947Uses the value of EXPR as a filename and executes the contents of the
3352file as a Perl script.
3948file as a Perl script:
33533949
33543950=end original
33553951
33563952EXPR の値をファイル名として用い、そのファイルの中身を
3357Perl のスクリプトとして実行します
3953Perl のスクリプトとして実行します:
33583954
3955 # load the exact specified file (./ and ../ special-cased)
3956 do '/foo/stat.pl';
3957 do './stat.pl';
3958 do '../foo/stat.pl';
3959
3960 # search for the named file within @INC
33593961 do 'stat.pl';
3962 do 'foo/stat.pl';
33603963
33613964=begin original
33623965
3363is largely like
3966C<do './stat.pl'> is largely like
33643967
33653968=end original
33663969
3367はだいたい以下のものと同じようなものですが、
3970C<do './stat.pl'> はだいたい以下のものと同じようなものですが、
33683971
33693972 eval `cat stat.pl`;
33703973
33713974=begin original
33723975
3373except that it's more concise, runs no external processes, keeps track of
3976except that it's more concise, runs no external processes, and keeps
3374the current
3977track of the current filename for error messages. It also differs in that
3375filename for error messages, searches the C<@INC> directories, and updates
3978code evaluated with C<do FILE> cannot see lexicals in the enclosing
3376C<%INC> if the file is found. See L<perlvar/@INC> and L<perlvar/%INC> for
3979scope; C<eval STRING> does. It's the same, however, in that it does
3377these variables. It also differs in that code evaluated with C<do FILENAME>
3980reparse the file every time you call it, so you probably don't want
3378cannot see lexicals in the enclosing scope; C<eval STRING> does. It's the
3981to do this inside a loop.
3379same, however, in that it does reparse the file every time you call it,
3380so you probably don't want to do this inside a loop.
33813982
33823983=end original
33833984
33843985より簡潔で、外部プログラムを起動せず、エラーメッセージでファイル名がわかる、
3385カレントディレクトリでファイルが見つからなかったときに
3386C<@INC> ディレクトリを検索する、ファイルがあったときに C<%INC> を更新する、
33873986といったことがあります。
3388これらの変数については L<perlvar/@INC> と L<perlvar/%INC>
3987C<do FILE> で評価されたコードは、入れ子のスコープにある
3389参照してください。
3390C<do FILENAME> で評価されたコードは、入れ子のスコープにある
33913988レキシカル変数を見ることができないのに対し、C<eval STRING>ではできる、
33923989という違いがあります。
33933990しかし、呼び出すたびにファイルを解析し直すという点では同じですから、
33943991ループ内でこれを使おうなどとは、間違っても思ったりしないように。
33953992
33963993=begin original
33973994
3398If C<do> can read the file but cannot compile it, it returns C<undef> and sets
3995Using C<do> with a relative path (except for F<./> and F<../>), like
3399an error message in C<$@>. If C<do> cannot read the file, it returns undef
3400and sets C<$!> to the error. Always check C<$@> first, as compilation
3401could fail in a way that also sets C<$!>. If the file is successfully
3402compiled, C<do> returns the value of the last expression evaluated.
34033996
34043997=end original
34053998
3406C<do> がファイルを読み込めたがコンイルできなかった場合、
3999次のように、C<do> に (F<./> と F<../> 以外の) 相対スを使うと:
3407C<undef> を返して C<$@> にエラーメッセージを設定します。
3408C<do>がファイルを読み込めなかった場合、undef を返して C<$!> に
3409エラーを設定します。
3410コンパイルに失敗したときにも C<$!> が設定されるので、常に C<$@> を
3411先にチェックします。
3412ファイルのコンパイルに成功した場合、C<do> は最後に評価した表現の値を返します。
34134000
4001 do 'foo/stat.pl';
4002
34144003=begin original
34154004
4005will search the L<C<@INC>|perlvar/@INC> directories, and update
4006L<C<%INC>|perlvar/%INC> if the file is found. See L<perlvar/@INC>
4007and L<perlvar/%INC> for these variables. In particular, note that
4008whilst historically L<C<@INC>|perlvar/@INC> contained '.' (the
4009current directory) making these two cases equivalent, that is no
4010longer necessarily the case, as '.' is not included in C<@INC> by default
4011in perl versions 5.26.0 onwards. Instead, perl will now warn:
4012
4013=end original
4014
4015L<C<@INC>|perlvar/@INC> ディレクトリを検索し、ファイルが見つかれば
4016L<C<%INC>|perlvar/%INC> を更新します。
4017これらの変数については L<perlvar/@INC> と L<perlvar/%INC> を参照してください。
4018特に、歴史的には L<C<@INC>|perlvar/@INC> に '.' (カレントディレクトリ) を
4019含んでいたのでこの二つの場合は等価でしたが、
4020perl バージョン 5.26.0 以降ではデフォルトでは C<@INC> に '.' を
4021含んでいないので、もはやそうではないことに注意してください。
4022代わりに、perl は次のような警告を出します:
4023
4024 do "stat.pl" failed, '.' is no longer in @INC;
4025 did you mean do "./stat.pl"?
4026
4027=begin original
4028
4029If L<C<do>|/do EXPR> can read the file but cannot compile it, it
4030returns L<C<undef>|/undef EXPR> and sets an error message in
4031L<C<$@>|perlvar/$@>. If L<C<do>|/do EXPR> cannot read the file, it
4032returns undef and sets L<C<$!>|perlvar/$!> to the error. Always check
4033L<C<$@>|perlvar/$@> first, as compilation could fail in a way that also
4034sets L<C<$!>|perlvar/$!>. If the file is successfully compiled,
4035L<C<do>|/do EXPR> returns the value of the last expression evaluated.
4036
4037=end original
4038
4039L<C<do>|/do EXPR> がファイルを読み込めたがコンパイルできなかった場合、
4040L<C<undef>|/undef EXPR> を返して L<C<$@>|perlvar/$@> にエラーメッセージを
4041設定します。
4042L<C<do>|/do EXPR>がファイルを読み込めなかった場合、undef を返して
4043L<C<$!>|perlvar/$!> にエラーを設定します。
4044コンパイルに失敗したときにも L<C<$!>|perlvar/$!> が設定されるので、
4045常に L<C<$@>|perlvar/$@> を先にチェックします。
4046ファイルのコンパイルに成功した場合、L<C<do>|/do EXPR> は最後に評価した表現の
4047値を返します。
4048
4049=begin original
4050
34164051Inclusion of library modules is better done with the
3417C<use> and C<require> operators, which also do automatic error checking
4052L<C<use>|/use Module VERSION LIST> and L<C<require>|/require VERSION>
3418and raise an exception if there's a problem.
4053operators, which also do automatic error checking and raise an exception
4054if there's a problem.
34194055
34204056=end original
34214057
3422ライブラリモジュールのインクルードには、C<use> 演算子や C<require> 演算子を
4058ライブラリモジュールのインクルードには、
3423使った方がよいです; これらは自動的にエラーをチェックして、問題があれば例外を
4059L<C<use>|/use Module VERSION LIST> 演算子や
3424発生させま
4060L<C<require>|/require VERSION> 演算子を使った方がよいで;
4061これらは自動的にエラーをチェックして、問題があれば例外を発生させます。
34254062
34264063=begin original
34274064
3428You might like to use C<do> to read in a program configuration
4065You might like to use L<C<do>|/do EXPR> to read in a program
3429file. Manual error checking can be done this way:
4066configuration file. Manual error checking can be done this way:
34304067
34314068=end original
34324069
3433C<do> をプログラム設定ファイルを読み込むのに使いたいかもしれません。
4070L<C<do>|/do EXPR> をプログラム設定ファイルを読み込むのに
4071使いたいかもしれません。
34344072手動のエラーチェックは以下のようにして行えます:
34354073
3436 # read in config files: system first, then user
4074 # Read in config files: system first, then user.
4075 # Beware of using relative pathnames here.
34374076 for $file ("/share/prog/defaults.rc",
34384077 "$ENV{HOME}/.someprogrc")
34394078 {
34404079 unless ($return = do $file) {
34414080 warn "couldn't parse $file: $@" if $@;
34424081 warn "couldn't do $file: $!" unless defined $return;
34434082 warn "couldn't run $file" unless $return;
34444083 }
34454084 }
34464085
34474086=item dump LABEL
34484087X<dump> X<core> X<undump>
34494088
34504089=item dump EXPR
34514090
34524091=item dump
34534092
34544093=for Pod::Functions create an immediate core dump
34554094
34564095=begin original
34574096
34584097This function causes an immediate core dump. See also the B<-u>
3459command-line switch in L<perlrun>, which does the same thing.
4098command-line switch in L<perlrun|perlrun/-u>, which does the same thing.
34604099Primarily this is so that you can use the B<undump> program (not
34614100supplied) to turn your core dump into an executable binary after
34624101having initialized all your variables at the beginning of the
34634102program. When the new binary is executed it will begin by executing
3464a C<goto LABEL> (with all the restrictions that C<goto> suffers).
4103a C<goto LABEL> (with all the restrictions that L<C<goto>|/goto LABEL>
4104suffers).
34654105Think of it as a goto with an intervening core dump and reincarnation.
34664106If C<LABEL> is omitted, restarts the program from the top. The
34674107C<dump EXPR> form, available starting in Perl 5.18.0, allows a name to be
34684108computed at run time, being otherwise identical to C<dump LABEL>.
34694109
34704110=end original
34714111
34724112この関数は即座にコアダンプを行ないます。
3473同様のことを行う L<perlrun> の B<-u> オプションも参照してください。
4113同様のことを行う <perlrun|perlrun/-u> の B<-u> オプションも参照してください。
34744114プログラムの先頭で、
34754115すべての変数を初期化したあとのコアダンプを B<undump>
34764116プログラム(提供していません)を使って実行ファイルに返ることができます。
34774117この新しいバイナリが実行されると、C<goto LABEL> から始めます
3478(C<goto> に関する制限はすべて適用されます)。
4118(L<C<goto>|/goto LABEL> に関する制限はすべて適用されます)。
34794119コアダンプをはさんで再生する goto と考えてください。
34804120C<LABEL> が省略されると、プログラムを先頭から再開します。
34814121Perl 5.18.0 から利用可能な C<dump EXPR> 形式では、実行時に計算される
34824122名前が使えます; その他は C<dump LABEL> と同一です。
34834123
34844124=begin original
34854125
34864126B<WARNING>: Any files opened at the time of the dump will I<not>
34874127be open any more when the program is reincarnated, with possible
34884128resulting confusion by Perl.
34894129
34904130=end original
34914131
34924132B<警告>: dump 時点でオープンされていたファイルは、プログラムが
3493再生されたときには、もはやオープンされていません; Perl を混乱させる可能性が
4133再生されたときには、もはやオープンされて I<いません>; Perl を
3494あります。
4134混乱させる可能性があります。
34954135
34964136=begin original
34974137
34984138This function is now largely obsolete, mostly because it's very hard to
3499convert a core file into an executable. That's why you should now invoke
4139convert a core file into an executable. As of Perl 5.30, it must be invoked
3500it as C<CORE::dump()>, if you don't want to be warned against a possible
4140as C<CORE::dump()>.
3501typo.
35024141
35034142=end original
35044143
35054144この関数は大幅に時代遅れのものです; 主な理由としては、コアファイルを
35064145実行形式に変換するのが非常に困難であることです。
3507これが、今でタイプミスの可能性を警告さたくいなら
4146Perl 5.30 から、これは C<CORE::dump()> として起動しなけりません。
3508C<CORE::dump()> として起動するべき理由です。
35094147
35104148=begin original
35114149
35124150Unlike most named operators, this has the same precedence as assignment.
35134151It is also exempt from the looks-like-a-function rule, so
35144152C<dump ("foo")."bar"> will cause "bar" to be part of the argument to
3515C<dump>.
4153L<C<dump>|/dump LABEL>.
35164154
35174155=end original
35184156
35194157ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
35204158また、関数のように見えるものの規則からも免れるので、C<dump ("foo")."bar"> と
3521すると "bar" は C<dump> への引数の一部になります。
4159すると "bar" は L<C<dump>|/dump LABEL> への引数の一部になります。
35224160
35234161=begin original
35244162
35254163Portability issues: L<perlport/dump>.
35264164
35274165=end original
35284166
35294167移植性の問題: L<perlport/dump>。
35304168
35314169=item each HASH
35324170X<each> X<hash, iterator>
35334171
35344172=item each ARRAY
35354173X<array, iterator>
35364174
3537=item each EXPR
3538
35394175=for Pod::Functions retrieve the next key/value pair from a hash
35404176
35414177=begin original
35424178
35434179When called on a hash in list context, returns a 2-element list
35444180consisting of the key and value for the next element of a hash. In Perl
354541815.12 and later only, it will also return the index and value for the next
35464182element of an array so that you can iterate over it; older Perls consider
35474183this a syntax error. When called in scalar context, returns only the key
35484184(not the value) in a hash, or the index in an array.
35494185
35504186=end original
35514187
35524188ハッシュに対してリストコンテキストで呼び出した場合は、次の要素に対する、
35534189ハッシュのキーと値を返します。
35544190Perl 5.12 以降でのみ、配列のインデックスと値からなる
355541912 要素のリストを返すので、反復を行えます; より古い Perl ではこれは
35564192文法エラーと考えられます。
35574193スカラコンテキストで呼び出した場合は、
35584194ハッシュの場合は(値ではなく)キー、配列の場合はインデックスを返します。
35594195
35604196=begin original
35614197
35624198Hash entries are returned in an apparently random order. The actual random
35634199order is specific to a given hash; the exact same series of operations
3564on two hashes may result in a different order for each hash. Any insertion
4200on two hashes may result in a different order for each hash. Any insertion
35654201into the hash may change the order, as will any deletion, with the exception
3566that the most recent key returned by C<each> or C<keys> may be deleted
4202that the most recent key returned by L<C<each>|/each HASH> or
3567without changing the order. So long as a given hash is unmodified you may
4203L<C<keys>|/keys HASH> may be deleted without changing the order. So
3568rely on C<keys>, C<values> and C<each> to repeatedly return the same order
4204long as a given hash is unmodified you may rely on
3569as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
4205L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and
3570details on why hash order is randomized. Aside from the guarantees
4206L<C<each>|/each HASH> to repeatedly return the same order
4207as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
4208details on why hash order is randomized. Aside from the guarantees
35714209provided here the exact details of Perl's hash algorithm and the hash
35724210traversal order are subject to change in any release of Perl.
35734211
35744212=end original
35754213
35764214ハッシュ要素は見かけ上、ランダムな順序で返されます。
35774215実際のランダムな順序はハッシュに固有です; 二つのハッシュに全く同じ一連の
35784216操作を行っても、ハッシュによって異なった順序になります。
35794217ハッシュへの挿入によって順序が変わることがあります; 削除も同様ですが、
3580C<each> または C<keys> によって返されたもっとも最近のキーは順序を
4218L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも
3581変えることなく削除できます。
4219最近のキーは順序を変えることなく削除できます。
3582ハッシュが変更されない限り、C<keys>, C<values>, C<each> が繰り返し同じ順序で
4220ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>,
3583返すことに依存してもかまいません。
4221L<C<each>|/each HASH> が繰り返し同じ順序で返すことに依存してもかまいません。
35844222なぜハッシュの順序がランダム化されているかの詳細については
35854223L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。
35864224ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の
35874225正確な詳細は Perl のリリースによって変更される可能性があります。
35884226
35894227=begin original
35904228
3591After C<each> has returned all entries from the hash or array, the next
4229After L<C<each>|/each HASH> has returned all entries from the hash or
3592call to C<each> returns the empty list in list context and C<undef> in
4230array, the next call to L<C<each>|/each HASH> returns the empty list in
3593scalar context; the next call following I<that> one restarts iteration.
4231list context and L<C<undef>|/undef EXPR> in scalar context; the next
3594Each hash or array has its own internal iterator, accessed by C<each>,
4232call following I<that> one restarts iteration. Each hash or array has
3595C<keys>, and C<values>. The iterator is implicitly reset when C<each> has
4233its own internal iterator, accessed by L<C<each>|/each HASH>,
3596reached the end as just described; it can be explicitly reset by calling
4234L<C<keys>|/keys HASH>, and L<C<values>|/values HASH>. The iterator is
3597C<keys> or C<values> on the hash or array. If you add or delete a hash's
4235implicitly reset when L<C<each>|/each HASH> has reached the end as just
3598elements while iterating over it, entries may be skipped or duplicated--so
4236described; it can be explicitly reset by calling L<C<keys>|/keys HASH>
3599don't do that. Exception: In the current implementation, it is always safe
4237or L<C<values>|/values HASH> on the hash or array, or by referencing
3600to delete the item most recently returned by C<each()>, so the following
4238the hash (but not array) in list context. If you add or delete
3601code works properly:
4239a hash's elements while iterating over it, the effect on the iterator is
4240unspecified; for example, entries may be skipped or duplicated--so don't
4241do that. Exception: It is always safe to delete the item most recently
4242returned by L<C<each>|/each HASH>, so the following code works properly:
36024243
36034244=end original
36044245
3605C<each> がハッシュをすべて読み込んでしまった後、リストコンテキストでは
4246L<C<each>|/each HASH> がハッシュをすべて読み込んでしまった後、
3606リストが返され、スカラコンテキストでは C<undef> 返されます;
4247次の L<C<each>|/each HASH> 呼び出しでは、リストコンテキストでは空リスト
4248返され、スカラコンテキストでは L<C<undef>|/undef EXPR> が返されます;
36074249I<そのあと> もう一度呼び出すと、再び反復を始めます。
3608ハッシュや配列毎にそれぞれ反復子があり、C<each>、C<keys>、C<values>
4250ハッシュや配列毎にそれぞれ反復子があり、L<C<each>|/each HASH>、
3609アクセスされます。
4251L<C<keys>|/keys HASH>、L<C<values>|/values HASH> でアクセスされます。
3610反復子は、前述したように C<each> が要素をすべて読むことによって
4252反復子は、前述したように L<C<each>|/each HASH> が要素をすべて読むことによって
3611暗黙にリセットされます; また、ハッシュや配列に対して
4253暗黙にリセットされます; また、ハッシュや配列に対して L<C<keys>|/keys HASH>,
3612C<keys HASH>, C<values HASH> を呼び出すことで明示的にセットできます。
4254L<C<values>|/values HASH> を呼び出すか、コンテキスト
4255(配列ではなく)ハッシュを参照ことで明示的にリセットできます。
36134256繰り返しを行なっている間に、ハッシュに要素を追加したり削除したりすると、
3614要素が飛ばされたり重複したりするので、てはいけせん。
4257反復子の動作は未定義です; 例えば、要素が飛ばされたり重複したりします--
3615例外: 現在の実装で一番最近に C<each()> から返されたものを削除するのは常に
4258従って、していけません。
4259例外: 一番最近に L<C<each>|/each HASH> から返されたものを削除するのは常に
36164260安全です; これは以下のようなコードが正しく動くことを意味します:
36174261
3618 while (($key, $value) = each %hash) {
4262 while (my ($key, $value) = each %hash) {
3619 print $key, "\n";
4263 print $key, "\n";
3620 delete $hash{$key}; # This is safe
4264 delete $hash{$key}; # This is safe
3621 }
4265 }
36224266
36234267=begin original
36244268
3625This prints out your environment like the printenv(1) program,
4269Tied hashes may have a different ordering behaviour to perl's hash
4270implementation.
4271
4272=end original
4273
4274tie されたハッシュは、順序に関して Perl のハッシュと異なった振る舞いをします。
4275
4276=begin original
4277
4278The iterator used by C<each> is attached to the hash or array, and is
4279shared between all iteration operations applied to the same hash or array.
4280Thus all uses of C<each> on a single hash or array advance the same
4281iterator location. All uses of C<each> are also subject to having the
4282iterator reset by any use of C<keys> or C<values> on the same hash or
4283array, or by the hash (but not array) being referenced in list context.
4284This makes C<each>-based loops quite fragile: it is easy to arrive at
4285such a loop with the iterator already part way through the object, or to
4286accidentally clobber the iterator state during execution of the loop body.
4287It's easy enough to explicitly reset the iterator before starting a loop,
4288but there is no way to insulate the iterator state used by a loop from
4289the iterator state used by anything else that might execute during the
4290loop body. To avoid these problems, use a C<foreach> loop rather than
4291C<while>-C<each>.
4292
4293=end original
4294
4295C<each> で使われる反復子はハッシュや配列に付随し、
4296同じハッシュや配列に適用される全ての反復操作の間で共有されます。
4297従って、一つのハッシュや配列での C<each> の全ての使用は同じ反復位置を
4298進めます。
4299また、全ての C<each> は、同じハッシュまたはキーに対する
4300C<keys> や C<values> の使用によって、または
4301(リストではなく)ハッシュがリストコンテキストで参照されることによって、
4302反復子がリセットされることになります。
4303これは、C<each> を基にしたループをかなり不安定にします:
4304そのようなループが既にオブジェクトを部分的に通りぬけた反復子で行われたり、
4305ループ本体の実行中に誤って反復子の状態を壊すことは容易です。
4306ループを始める前に反復子を明示的にリセットするのは十分容易ですが、
4307ループ本体の間に実行しているかもしれない他の何かによって使われている
4308反復子の状態から、
4309ループによって使われている反復子の状態を分離する方法はありません。
4310これらの問題を避けるには、C<while>-C<each> ではなく
4311C<foreach> ループを使ってください。
4312
4313=begin original
4314
4315This extends to using C<each> on the result of an anonymous hash or
4316array constructor. A new underlying array or hash is created each
4317time so each will always start iterating from scratch, eg:
4318
4319=end original
4320
4321これは、無名ハッシュや配列のコンストラクタの結果に
4322C<each> を使うように拡張します。
4323新しい基となる配列やハッシュは毎回作られるので、
4324それぞれは常に最初から反復します; 例:
4325
4326 # loops forever
4327 while (my ($key, $value) = each @{ +{ a => 1 } }) {
4328 print "$key=$value\n";
4329 }
4330
4331=begin original
4332
4333This prints out your environment like the L<printenv(1)> program,
36264334but in a different order:
36274335
36284336=end original
36294337
3630これは、printenv(1) プログラムのように環境変数を表示しますが、
4338これは、L<printenv(1)> プログラムのように環境変数を表示しますが、
36314339順序は異なっています:
36324340
3633 while (($key,$value) = each %ENV) {
4341 while (my ($key,$value) = each %ENV) {
36344342 print "$key=$value\n";
36354343 }
36364344
36374345=begin original
36384346
3639Starting with Perl 5.14, C<each> can take a scalar EXPR, which must hold
4347Starting with Perl 5.14, an experimental feature allowed
3640reference to an unblessed hash or array. The argument will be dereferenced
4348L<C<each>|/each HASH> to take a scalar expression. This experiment has
3641automatically. This aspect of C<each> is considered highly experimental.
4349been deemed unsuccessful, and was removed as of Perl 5.24.
3642The exact behaviour may change in a future version of Perl.
36434350
36444351=end original
36454352
3646Perl 5.14 から、C<each> スカラの EXPR を取ることができになりました;
4353Perl 5.14 から、L<C<each>|/each HASH> がスカラを取ることが出来とい
3647これは bless されていないハッシュや配列へのリファレンスでなければなりません
4354実験的機能がありました
3648引数自動的にデリファレンスされま
4355この実験失敗と見なされ、Perl 5.24 で削除されした
3649C<each> のこの動作は高度に実験的であると考えられています。
3650正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
36514356
3652 while (($key,$value) = each $hashref) { ... }
3653
36544357=begin original
36554358
3656As of Perl 5.18 you can use a bare C<each> in a C<while> loop,
4359As of Perl 5.18 you can use a bare L<C<each>|/each HASH> in a C<while>
3657which will set C<$_> on every iteration.
4360loop, which will set L<C<$_>|perlvar/$_> on every iteration.
4361If either an C<each> expression or an explicit assignment of an C<each>
4362expression to a scalar is used as a C<while>/C<for> condition, then
4363the condition actually tests for definedness of the expression's value,
4364not for its regular truth value.
36584365
36594366=end original
36604367
3661Perl 5.18 から C<while> ループの中に裸の C<each> を書けます; これは
4368Perl 5.18 から C<while> ループの中に裸の L<C<each>|/each HASH> を書けます;
3662繰り返し毎に C<$_> を設定します。
4369これは繰り返し毎に L<C<$_>|perlvar/$_> を設定します。
4370C<each> 式または C<each> 式からスカラへの明示的な代入が
4371C<while>/C<for> の条件部として使われた場合、
4372条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを
4373テストします。
36634374
3664 while(each %ENV) {
4375 while (each %ENV) {
36654376 print "$_=$ENV{$_}\n";
36664377 }
36674378
36684379=begin original
36694380
36704381To avoid confusing would-be users of your code who are running earlier
36714382versions of Perl with mysterious syntax errors, put this sort of thing at
36724383the top of your file to signal that your code will work I<only> on Perls of
36734384a recent vintage:
36744385
36754386=end original
36764387
36774388あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
36784389文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
36794390I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
36804391書いてください:
36814392
3682 use 5.012; # so keys/values/each work on arrays
4393 use v5.12; # so keys/values/each work on arrays
3683 use 5.014; # so keys/values/each work on scalars (experimental)
4394 use v5.18; # so each assigns to $_ in a lone while test
3684 use 5.018; # so each assigns to $_ in a lone while test
36854395
36864396=begin original
36874397
3688See also C<keys>, C<values>, and C<sort>.
4398See also L<C<keys>|/keys HASH>, L<C<values>|/values HASH>, and
4399L<C<sort>|/sort SUBNAME LIST>.
36894400
36904401=end original
36914402
3692C<keys> や C<values> や C<sort> も参照してください。
4403L<C<keys>|/keys HASH> L<C<values>|/values HASH>
4404L<C<sort>|/sort SUBNAME LIST> も参照してください。
36934405
36944406=item eof FILEHANDLE
36954407X<eof>
36964408X<end of file>
36974409X<end-of-file>
36984410
36994411=item eof ()
37004412
37014413=item eof
37024414
37034415=for Pod::Functions test a filehandle for its end
37044416
37054417=begin original
37064418
37074419Returns 1 if the next read on FILEHANDLE will return end of file I<or> if
37084420FILEHANDLE is not open. FILEHANDLE may be an expression whose value
37094421gives the real filehandle. (Note that this function actually
37104422reads a character and then C<ungetc>s it, so isn't useful in an
37114423interactive context.) Do not read from a terminal file (or call
37124424C<eof(FILEHANDLE)> on it) after end-of-file is reached. File types such
37134425as terminals may lose the end-of-file condition if you do.
37144426
37154427=end original
37164428
37174429次に FILEHANDLE 上で読み込みを行なったときに、EOF が返されるときか、
37184430I<または> FILEHANDLE がオープンされていないと、1 を返します。
37194431FILEHANDLE は、値が実際のファイルハンドルを示す式であってもかまいません。
37204432(この関数は、実際に文字を読み、C<ungetc> を行ないますので、
37214433対話型の場合には有用ではありません。)
37224434端末ファイルは EOF に達した後にさらに読み込んだり C<eof(FILEHANDLE)> を
37234435呼び出したりしてはいけません。
37244436そのようなことをすると、端末のようなファイルタイプは
37254437EOF 状態を失ってしまうかもしれません。
37264438
37274439=begin original
37284440
3729An C<eof> without an argument uses the last file read. Using C<eof()>
4441An L<C<eof>|/eof FILEHANDLE> without an argument uses the last file
3730with empty parentheses is different. It refers to the pseudo file
4442read. Using L<C<eof()>|/eof FILEHANDLE> with empty parentheses is
3731formed from the files listed on the command line and accessed via the
4443different. It refers to the pseudo file formed from the files listed on
3732C<< <> >> operator. Since C<< <> >> isn't explicitly opened,
4444the command line and accessed via the C<< <> >> operator. Since
3733as a normal filehandle is, an C<eof()> before C<< <> >> has been
4445C<< <> >> isn't explicitly opened, as a normal filehandle is, an
3734used will cause C<@ARGV> to be examined to determine if input is
4446L<C<eof()>|/eof FILEHANDLE> before C<< <> >> has been used will cause
3735available. Similarly, an C<eof()> after C<< <> >> has returned
4447L<C<@ARGV>|perlvar/@ARGV> to be examined to determine if input is
3736end-of-file will assume you are processing another C<@ARGV> list,
4448available. Similarly, an L<C<eof()>|/eof FILEHANDLE> after C<< <> >>
3737and if you haven't set C<@ARGV>, will read input from C<STDIN>;
4449has returned end-of-file will assume you are processing another
3738see L<perlop/"I/O Operators">.
4450L<C<@ARGV>|perlvar/@ARGV> list, and if you haven't set
4451L<C<@ARGV>|perlvar/@ARGV>, will read input from C<STDIN>; see
4452L<perlop/"I/O Operators">.
37394453
37404454=end original
37414455
3742引数を省略した C<eof> は、最後に読み込みを行なったファイルを使います。
4456引数を省略した L<C<eof>|/eof FILEHANDLE> は、最後に読み込みを行なった
3743空の括弧つけた C<eof()> は異なります。
4457ファイル使います。
4458空の括弧をつけた L<C<eof()>|/eof FILEHANDLE> は異なります。
37444459これはコマンドラインのファイルリストで構成され、C<< <> >> 演算子経由で
37454460アクセスされる擬似ファイルを示すために用いられます。
37464461通常のファイルハンドルと違って C<< <> >> は明示的にオープンされないので、
3747C<< <> >> を使う前に C<eof()> を使うと、
4462C<< <> >> を使う前に L<C<eof()>|/eof FILEHANDLE> を使うと、
3748入力が正常か確認するために C<@ARGV> がテストされます。
4463入力が正常か確認するために L<C<@ARGV>|perlvar/@ARGV> がテストされます。
3749同様に、C<< <> >> が EOF を返した後の C<eof()> は、
4464同様に、C<< <> >> が EOF を返した後の L<C<eof()>|/eof FILEHANDLE> は、
3750他の C<@ARGV> リストを処理していると仮定し、もし C<@ARGV> を
4465他の L<C<@ARGV>|perlvar/@ARGV> リストを処理していると仮定し、もし
3751セットしていないときは C<STDIN> から読み込みます;
4466L<C<@ARGV>|perlvar/@ARGV> をセットしていないときは C<STDIN> から読み込みます;
37524467L<perlop/"I/O Operators"> を参照してください。
37534468
37544469=begin original
37554470
3756In a C<< while (<>) >> loop, C<eof> or C<eof(ARGV)> can be used to
4471In a C<< while (<>) >> loop, L<C<eof>|/eof FILEHANDLE> or C<eof(ARGV)>
3757detect the end of each file, whereas C<eof()> will detect the end
4472can be used to detect the end of each file, whereas
3758of the very last file only. Examples:
4473L<C<eof()>|/eof FILEHANDLE> will detect the end of the very last file
4474only. Examples:
37594475
37604476=end original
37614477
37624478C<< while (<>) >> ループの中では、個々のファイルの終わりを調べるには、
3763C<eof> か C<eof(ARGV)> を用いるのに対して
4479L<C<eof>|/eof FILEHANDLE> か C<eof(ARGV)> を用いるのに対して
3764C<eof()> は最後のファイルの終わりのみを調べます。
4480L<C<eof()>|/eof FILEHANDLE> は最後のファイルの終わりのみを調べます。
37654481例:
37664482
37674483 # reset line numbering on each input file
37684484 while (<>) {
37694485 next if /^\s*#/; # skip comments
37704486 print "$.\t$_";
37714487 } continue {
37724488 close ARGV if eof; # Not eof()!
37734489 }
37744490
37754491 # insert dashes just before last line of last file
37764492 while (<>) {
37774493 if (eof()) { # check for end of last file
37784494 print "--------------\n";
37794495 }
37804496 print;
37814497 last if eof(); # needed if we're reading from a terminal
37824498 }
37834499
37844500=begin original
37854501
3786Practical hint: you almost never need to use C<eof> in Perl, because the
4502Practical hint: you almost never need to use L<C<eof>|/eof FILEHANDLE>
3787input operators typically return C<undef> when they run out of data or
4503in Perl, because the input operators typically return L<C<undef>|/undef
3788encounter an error.
4504EXPR> when they run out of data or encounter an error.
37894505
37904506=end original
37914507
3792現実的なヒント: Perl で C<eof> が必要となることは、ほとんどありません;
4508現実的なヒント: Perl で L<C<eof>|/eof FILEHANDLE> が必要となることは、
4509ほとんどありません;
37934510基本的には、データがなくなったときやエラーがあったときに、入力演算子が
3794C<undef> を返してくれるからです。
4511L<C<undef>|/undef EXPR> を返してくれるからです。
37954512
37964513=item eval EXPR
37974514X<eval> X<try> X<catch> X<evaluate> X<parse> X<execute>
37984515X<error, handling> X<exception, handling>
37994516
38004517=item eval BLOCK
38014518
38024519=item eval
38034520
38044521=for Pod::Functions catch exceptions or compile and run code
38054522
38064523=begin original
38074524
3808In the first form, the return value of EXPR is parsed and executed as if it
4525C<eval> in all its forms is used to execute a little Perl program,
3809were a little Perl program. The value of the expression (which is itself
4526trapping any errors encountered so they don't crash the calling program.
3810determined within scalar context) is first parsed, and if there were no
3811errors, executed as a block within the lexical context of the current Perl
3812program. This means, that in particular, any outer lexical variables are
3813visible to it, and any package variable settings or subroutine and format
3814definitions remain afterwards.
38154527
38164528=end original
38174529
3818第一では、EXPR 返り値が Perl のプログラムであるかのように
4530式の C<eval> も、小さな Perl のプログラムであるかのように実行され、
3819解析され、実行されま
4531遭遇した全てのエラーをトラップるので、呼び出したプログラムが
3820式の値(それ自身スカコンテキストの中で決定されま)はまずパースされ、
4532ッシュることありせん。
3821エラーがなければ
3822Perl プログラムのレキシカルコンテキストの中のブロックとして実行されます。
3823これは、特に、外側のレキシカル変数は見えていて、パッケージ変数の設定や
3824サブルーチンやフォーマットの定義はその後も残っているということです。
38254533
38264534=begin original
38274535
4536Plain C<eval> with no argument is just C<eval EXPR>, where the
4537expression is understood to be contained in L<C<$_>|perlvar/$_>. Thus
4538there are only two real C<eval> forms; the one with an EXPR is often
4539called "string eval". In a string eval, the value of the expression
4540(which is itself determined within scalar context) is first parsed, and
4541if there were no errors, executed as a block within the lexical context
4542of the current Perl program. This form is typically used to delay
4543parsing and subsequent execution of the text of EXPR until run time.
38284544Note that the value is parsed every time the C<eval> executes.
3829If EXPR is omitted, evaluates C<$_>. This form is typically used to
3830delay parsing and subsequent execution of the text of EXPR until run time.
38314545
38324546=end original
38334547
3834返される値は C<eval> が実行されるごとパースされることに注意してください。
4548引数なしの C<eval> 単に C<eval EXPR> で、式は L<C<$_>|perlvar/$_>
3835EXPR が省略されると、C<$_> を評価します。
4549含まていものとして考えられます。
4550従って実際には二つだけの C<eval> 形式があります:
4551EXPR のものはしばしば「文字列 eval」(string eval) と呼ばれます。
4552「文字列 eval」では、
4553式の値(それ自身スカラコンテキストの中で決定されます)はまずパースされ、
4554エラーがなければ Perl プログラムのレキシカルコンテキストの中のブロックとして
4555実行されます。
38364556この形は主に EXPR のテキストのパースと実行を実行時にまで
38374557遅延させるのに用います。
4558返される値は C<eval> が実行されるごとにパースされることに注意してください。
38384559
38394560=begin original
38404561
3841If the C<unicode_eval> feature is enabled (which is the default under a
4562The other form is called "block eval". It is less general than string
3842C<use 5.16> or higher declaration), EXPR or C<$_> is treated as a string of
4563eval, but the code within the BLOCK is parsed only once (at the same
3843characters, so C<use utf8> declarations have no effect, and source filters
4564time the code surrounding the C<eval> itself was parsed) and executed
3844are forbidden. In the absence of the C<unicode_eval> feature, the string
4565within the context of the current Perl program. This form is typically
3845will sometimes be treated as characters and sometimes as bytes, depending
4566used to trap exceptions more efficiently than the first, while also
3846on the internal encoding, and source filters activated within the C<eval>
4567providing the benefit of checking the code within BLOCK at compile time.
3847exhibit the erratic, but historical, behaviour of affecting some outer file
4568BLOCK is parsed and compiled just once. Since errors are trapped, it
3848scope that is still compiling. See also the L</evalbytes> keyword, which
4569often is used to check if a given feature is available.
3849always treats its input as a byte stream and works properly with source
3850filters, and the L<feature> pragma.
38514570
38524571=end original
38534572
3854C<unicode_eval> 機能が有効の場合(こは C<use 5.16> たはそれ以上が
4573もう一つの型式は「ブロック eval」と呼ばれます。
3855宣言さている場合デフォルトです)、EXPR や C<$_> は文字単位の文字として
4574れは文字列 eval ほど一般的ではありませんが、
3856扱われるので、C<use utf8> 宣言無効で、ソースフィルタは禁止されます。
4575BLOCK 内部のコード一度だけパースされ (コードを
3857C<unicode_eval> 機能なければ、文字列は内部エンコディングに依存して
4576囲む C<eval> 自身スされるのと同じ時点です) 現在の
3858時々文字単位として扱われ、時々バイ単位扱われます; そして C<eval> の
4577Perl プログラムのコンテキストで実行されます
3859中で有効なったソースフィルタ、まだコンパイル中であるの外側のファイル
4578この形式は典型的には一の形式より効率的に例をトラップします;
3860コー影響を与えるという、間違っているけれども歴史的な振る舞い
4579また BLOCK 内部のコードはコンパイル時チェックされるという利点提供します。
3861見せます。
4580BLOCK は一度だけパース及びコンパイルされます。
3862入力を常にバイ列とし扱いソースフィルタ適切に動作する
4581エラーはラップされるのでしばしば与えられた機能利用可能かを
3863L</evalbytes> キーワードおよび L<feature> プラグマを参照してください
4582チェックするために使われます
38644583
38654584=begin original
38664585
3867In the second form, the code within the BLOCK is parsed only once--at the
4586In both forms, the value returned is the value of the last expression
3868same time the code surrounding the C<eval> itself was parsed--and executed
4587evaluated inside the mini-program; a return statement may also be used, just
3869within the context of the current Perl program. This form is typically
4588as with subroutines. The expression providing the return value is evaluated
3870used to trap exceptions more efficiently than the first (see below), while
4589in void, scalar, or list context, depending on the context of the
3871also providing the benefit of checking the code within BLOCK at compile
4590C<eval> itself. See L<C<wantarray>|/wantarray> for more
3872time.
4591on how the evaluation context can be determined.
38734592
38744593=end original
38754594
3876第二の形式でBLOCK 内部のコードは一度だけパースされ -- コードを
4595どちらの形式で返される値はミニプログラムの内部で最後に評価され
3877囲む C<eval> 自身がパースされると同じ時点です -- 現在の Perl プログラムの
4596表現です; サブルーチンと同様、return 文も使えます。
3878コンテキストで実行されます。
4597返り値として提供される表現は、C<eval> 自身のコンテキスト
3879形式は典型的には第一形式より効率的に例外をラップします(後述);
4598依存して無効・スカラ・リストいずれかコンテキスで評価されます
3880また BLOCK 内部のードはコパイル時チェックされるとう利点提供します。
4599評価コンテキストの決定方法ての詳細は L<C<wantarray>|/wantarray>
4600参照してください。
38814601
38824602=begin original
38834603
3884The final semicolon, if any, may be omitted from the value of EXPR or within
4604If there is a syntax error or runtime error, or a L<C<die>|/die LIST>
3885the BLOCK.
4605statement is executed, C<eval> returns
4606L<C<undef>|/undef EXPR> in scalar context, or an empty list in list
4607context, and L<C<$@>|perlvar/$@> is set to the error message. (Prior to
46085.16, a bug caused L<C<undef>|/undef EXPR> to be returned in list
4609context for syntax errors, but not for runtime errors.) If there was no
4610error, L<C<$@>|perlvar/$@> is set to the empty string. A control flow
4611operator like L<C<last>|/last LABEL> or L<C<goto>|/goto LABEL> can
4612bypass the setting of L<C<$@>|perlvar/$@>. Beware that using
4613C<eval> neither silences Perl from printing warnings to
4614STDERR, nor does it stuff the text of warning messages into
4615L<C<$@>|perlvar/$@>. To do either of those, you have to use the
4616L<C<$SIG{__WARN__}>|perlvar/%SIG> facility, or turn off warnings inside
4617the BLOCK or EXPR using S<C<no warnings 'all'>>. See
4618L<C<warn>|/warn LIST>, L<perlvar>, and L<warnings>.
38864619
38874620=end original
38884621
3889最後のセミコロンは、もしあれば、EXPR の値 BLOCK の中身から省くことできます。
4622構文エラー実行エラーが発生するか、L<C<die>|/die LIST> 文実行されると、
4623C<eval> はスカラコンテキストでは L<C<undef>|/undef EXPR> が、
4624リストコンテキストでは空リストが設定され、
4625L<C<$@>|perlvar/$@> にエラーメッセージが設定されます。
4626(5.16 以前では、バグによって、リストコンテキストで構文エラーの時には
4627L<C<undef>|/undef EXPR> を返していましたが、実行エラーの時には
4628返していませんでした。)
4629エラーがなければ、L<C<$@>|perlvar/$@> は空文字列に設定されます。
4630L<C<last>|/last LABEL> や L<C<goto>|/goto LABEL> のようなフロー制御演算子は
4631L<C<$@>|perlvar/$@> の設定を回避できます。
4632C<eval> を、STDERR に警告メッセージを表示させない目的や、
4633警告メッセージを L<C<$@>|perlvar/$@> に格納する目的では使わないでください。
4634そのような用途では、L<C<$SIG{__WARN__}>|perlvar/%SIG> 機能を使うか、
4635S<C<no warnings 'all'>> を使って BLOCK か EXPR の内部での警告を
4636オフにする必要があります。
4637L<C<warn>|/warn LIST>, L<perlvar>, L<warnings> を参照してください。
38904638
38914639=begin original
38924640
3893In both forms, the value returned is the value of the last expression
4641Note that, because C<eval> traps otherwise-fatal errors,
3894evaluated inside the mini-program; a return statement may be also used, just
4642it is useful for determining whether a particular feature (such as
3895as with subroutines. The expression providing the return value is evaluated
4643L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL> or
3896in void, scalar, or list context, depending on the context of the C<eval>
4644L<C<symlink>|/symlink OLDFILE,NEWFILE>) is implemented. It is also
3897itself. See L</wantarray> for more on how the evaluation context can be
4645Perl's exception-trapping mechanism, where the L<C<die>|/die LIST>
3898determined.
4646operator is used to raise exceptions.
38994647
39004648=end original
39014649
3902どちらの形式でも、返される値ミニプログ内部で最後に評価された
4650C<eval> 、致命的エーとなるようなも
3903表現の値で; サブルーチン同様return 文も使えます。
4651トラップるこができるので
3904返り値として提供される表現は、C<eval> 自身のコンテキストに依存して
4652(L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL> や
3905無効・スカラ・リストのずれかコンテキストで評価されます。
4653L<C<symlink>|/symlink OLDFILE,NEWFILE> とった) 特定機能が
3906評価コンテキストの決定方法についての詳細は L</wantarray> を参照してください
4654実装れてるかを、
4655調べるために使うことができることに注意してください。
4656L<C<die>|/die LIST> 演算子が例外を発生させるものとすれば、これはまた、
4657Perl の例外捕捉機能と捉えることもできます。
39074658
39084659=begin original
39094660
3910If there is a syntax error or runtime error, or a C<die> statement is
4661Before Perl 5.14, the assignment to L<C<$@>|perlvar/$@> occurred before
3911executed, C<eval> returns C<undef> in scalar context
4662restoration
3912or an empty list in list context, and C<$@> is set to the error
4663of localized variables, which means that for your code to run on older
3913message. (Prior to 5.16, a bug caused C<undef> to be returned
4664versions, a temporary is required if you want to mask some, but not all
3914in list context for syntax errors, but not for runtime errors.)
4665errors:
3915If there was no error, C<$@> is set to the empty string. A
3916control flow operator like C<last> or C<goto> can bypass the setting of
3917C<$@>. Beware that using C<eval> neither silences Perl from printing
3918warnings to STDERR, nor does it stuff the text of warning messages into C<$@>.
3919To do either of those, you have to use the C<$SIG{__WARN__}> facility, or
3920turn off warnings inside the BLOCK or EXPR using S<C<no warnings 'all'>>.
3921See L</warn>, L<perlvar>, L<warnings> and L<perllexwarn>.
39224666
39234667=end original
39244668
3925構文エラーや実行エラーが発生するか、C<die> 文が実行されると、
4669Perl 5.14 より前ではL<C<$@>|perlvar/$@> への代入はローカル化された変数の
3926C<eval> はスカラコテキストでは C<undef> がリストコンテキストでは
4670復帰の前に起きるので、古いバージョンで実行される場合は、全てではなく一部だけの
3927空リ設定されま
4671エラーをマクしたい場合には一時変数必要で:
3928(5.16 以前では、バグによって、リストコンテキストで構文エラーの時には
3929C<undef> を返していましたが、実行エラーの時には返していませんでした。)
3930エラーがなければ、C<$@> は空文字列に設定されます。
3931C<last> や C<goto> のようなフロー制御演算子は C<$@> の設定を回避できます。
3932C<eval> を、STDERR に警告メッセージを表示させない目的や、
3933警告メッセージを C<$@> に格納する目的では使わないでください。
3934そのような用途では、C<$SIG{__WARN__}> 機能を使うか、
3935S<C<no warnings 'all'>> を使って BLOCK か EXPR の内部での警告を
3936オフにする必要があります。
3937L</warn>, L<perlvar>, L<warnings>, L<perllexwarn> を参照してください。
39384672
4673 # alter $@ on nefarious repugnancy only
4674 {
4675 my $e;
4676 {
4677 local $@; # protect existing $@
4678 eval { test_repugnancy() };
4679 # $@ =~ /nefarious/ and die $@; # Perl 5.14 and higher only
4680 $@ =~ /nefarious/ and $e = $@;
4681 }
4682 die $e if defined $e
4683 }
4684
39394685=begin original
39404686
3941Note that, because C<eval> traps otherwise-fatal errors, it is useful for
4687There are some different considerations for each form:
3942determining whether a particular feature (such as C<socket> or C<symlink>)
3943is implemented. It is also Perl's exception-trapping mechanism, where
3944the die operator is used to raise exceptions.
39454688
39464689=end original
39474690
3948C<eval> は致命的エラーとるようなものをトラップすることできるので、
4691それぞれの型式についてった考慮事項あります:
3949(C<socket> や C<symlink> といった) 特定の機能が実装されているかを、
3950調べるために使うことができることに注意してください。
3951die 演算子が例外を発生させるものとすれば、これはまた、Perl の例外捕捉機能と
3952捉えることもできます。
39534692
4693=over 4
4694
4695=item String eval
4696
4697(文字列 eval)
4698
39544699=begin original
39554700
3956If you want to trap errors when loading an XS module, some problems with
4701Since the return value of EXPR is executed as a block within the lexical
3957the binary interface (such as Perl version skew) may be fatal even with
4702context of the current Perl program, any outer lexical variables are
3958C<eval> unless C<$ENV{PERL_DL_NONLAZY}> is set. See L<perlrun>.
4703visible to it, and any package variable settings or subroutine and
4704format definitions remain afterwards.
39594705
39604706=end original
39614707
3962XS モジュールロード中ーをラップしたいなら、
4708EXPR返り値は現在 Perl プログムのレキシカルコンテキスの中で
3963(Perl バージョン違いような) バイナリインターフェーに関する問題に
4709実行されるで、外側レキシカルコープはそこから見え、
3964ついては C<$ENV{PERL_DL_NONLAZY}> がセットされていない C<eval> でも
4710ケージ変数設定やサブルーチンとフォーマッ設定は後に残ります。
3965致命的エラーになるかもしれません。
3966L<perlrun> を参照してください。
39674711
39684712=begin original
39694713
3970If the code to be executed doesn't vary, you may use the eval-BLOCK
4714Note that when C<BEGIN {}> blocks are embedded inside of an eval block
3971form to trap run-time errors without incurring the penalty of
4715the contents of the block will be executed immediately and before the rest
3972recompiling each time. The error, if any, is still returned in C<$@>.
4716of the eval code is executed. You can disable this entirely by
3973Examples:
39744717
39754718=end original
39764719
3977実行するコードが変わらないのであれば、毎回多量の再コンパイルすることなしに、
4720Note that when C<BEGIN {}> blocks are embedded inside of an eval block
3978実行時エラーのトラップを行なうために、
4721the contents of the block will be executed immediately and before the rest
3979eval-BLOCK 形式を使うことができます。
4722of the eval code is executed. You can disable this entirely by
3980エラーがあれば、やはり $@ に返されます。
4723(TBT)
3981例:
39824724
3983 # make divide-by-zero nonfatal
4725 local ${^MAX_NESTED_EVAL_BEGIN_BLOCKS} = 0;
3984 eval { $answer = $a / $b; }; warn $@ if $@;
4726 eval $string;
39854727
3986 # same thing, but less efficient
4728=begin original
3987 eval '$answer = $a / $b'; warn $@ if $@;
39884729
3989 # a compile-time error
4730which will cause any embedded C<BEGIN> blocks in C<$string> to throw an
3990 eval { $answer = }; # WRONG
4731exception.
39914732
3992 # a run-time error
4733=end original
3993 eval '$answer ='; # sets $@
39944734
4735which will cause any embedded C<BEGIN> blocks in C<$string> to throw an
4736exception.
4737(TBT)
4738
4739=over 4
4740
4741=item Under the L<C<"unicode_eval"> feature|feature/The 'unicode_eval' and 'evalbytes' features>
4742
39954743=begin original
39964744
3997Using the C<eval{}> form as an exception trap in libraries does have some
4745If this feature is enabled (which is the default under a C<use 5.16> or
3998issues. Due to the current arguably broken state of C<__DIE__> hooks, you
4746higher declaration), Perl assumes that EXPR is a character string.
3999may wish not to trigger any C<__DIE__> hooks that user code may have installed.
4747Any S<C<use utf8>> or S<C<no utf8>> declarations within
4000You can use the C<local $SIG{__DIE__}> construct for this purpose,
4748the string thus have no effect. Source filters are forbidden as well.
4001as this example shows:
4749(C<unicode_strings>, however, can appear within the string.)
40024750
40034751=end original
40044752
4005C<eval{}> 形式をライブラリの例外を捕捉するめに使うときに
4753この機能が有効の場合(これは C<use 5.16> たはそれ以上が
4006問題がありま
4754宣言されている場合はデフォルトで)、
4007現在の C<__DIE__> フック状態はほぼ確実に壊れているという理由で、
4755Perl EXPR が文字文字列であると仮定します。
4008ユーザーコードが設定した C<__DIE__> フックを実行したくないかもしれません
4756従って文字列中S<C<use utf8>> や S<C<no utf8>> 宣言は無効です
4009この目的には以下の例のように、C<local $SIG{__DIE__}> 構造が使えます。
4757ソースフィルタも禁止されます。
4758(しかし、C<unicode_strings> は文字列の中に現れます。)
40104759
4011 # a private exception trap for divide-by-zero
4760=begin original
4012 eval { local $SIG{'__DIE__'}; $answer = $a / $b; };
4013 warn $@ if $@;
40144761
4762See also the L<C<evalbytes>|/evalbytes EXPR> operator, which works properly
4763with source filters.
4764
4765=end original
4766
4767ソースフィルタが適切に動作する
4768L<C<evalbytes>|/evalbytes EXPR> 演算子も参照してください。
4769
4770=item Outside the C<"unicode_eval"> feature
4771
40154772=begin original
40164773
4017This is especially significant, given that C<__DIE__> hooks can call
4774In this case, the behavior is problematic and is not so easily
4018C<die> again, which has the effect of changing their error messages:
4775described. Here are two bugs that cannot easily be fixed without
4776breaking existing programs:
40194777
40204778=end original
40214779
4022れは特顕著です; 与えらた C<__DIE__> フック C<die> をもう一度
4780の場合、振る舞いは問題があり、そほど簡単に説明できません。
4023呼び出すことができ、これによってエラーメッセージを変える効果があります:
4781既存のプログラムを壊さずに簡単に修正ことが出来ない二つのバグがあります:
40244782
4025 # __DIE__ hooks may modify error messages
4783=over 4
4026 {
4027 local $SIG{'__DIE__'} =
4028 sub { (my $x = $_[0]) =~ s/foo/bar/g; die $x };
4029 eval { die "foo lives here" };
4030 print $@ if $@; # prints "bar lives here"
4031 }
40324784
4785=item *
4786
40334787=begin original
40344788
4035Because this promotes action at a distance, this counterintuitive behavior
4789Perl's internal storage of EXPR affects the behavior of the executed code.
4036may be fixed in a future release.
4790For example:
40374791
40384792=end original
40394793
4040これは距離の離れた行動であるため、この直感的でない振る舞いは
4794Perl's internal storage of
4041将来リリー修正されるかもしれせん
4795EXPR Perl の内部トーレージ実行されるコードの振る舞いに影響を与え
4796例えば:
40424797
4798 my $v = eval "use utf8; '$expr'";
4799
40434800=begin original
40444801
4045With an C<eval>, you should be especially careful to remember what's
4802If $expr is C<"\xc4\x80"> (U+0100 in UTF-8), then the value stored in C<$v>
4046being looked at when:
4803will depend on whether Perl stores $expr "upgraded" (cf. L<utf8>) or
4804not:
40474805
40484806=end original
40494807
4050C<eval> では、以下ような場合に、
4808$expr が C<"\xc4\x80"> (U+0100 in UTF-8) の場合、C<$v> 保管される値は
4051調べられるかに特に注意しておくことが必要です:
4809Perl $expr を「昇格」(L<utf8> 参照)して保管するかどうかよります:
40524810
4811=over
4812
4813=item * If upgraded, C<$v> will be C<"\xc4\x80"> (i.e., the
4814C<use utf8> has no effect.)
4815
4816(昇格されると、C<$v> will be C<"\xc4\x80"> になります (つまり、C<use utf8> は無効です。))
4817
4818=item * If non-upgraded, C<$v> will be C<"\x{100}">.
4819
4820(昇格されないと、C<$v> は C<"\x{100}">です。)
4821
4822=back
4823
4824This is undesirable since being
4825upgraded or not should not affect a string's behavior.
4826
4827=item *
4828
4829=begin original
4830
4831Source filters activated within C<eval> leak out into whichever file
4832scope is currently being compiled. To give an example with the CPAN module
4833L<Semi::Semicolons>:
4834
4835=end original
4836
4837C<eval> の中で有効にされたソースフィルタは、現在どちらのファイルスコープで
4838コンパイルされているかをリークさせます。
4839CPAN モジュール L<Semi::Semicolons> を使った例は:
4840
4841 BEGIN { eval "use Semi::Semicolons; # not filtered" }
4842 # filtered here!
4843
4844=begin original
4845
4846L<C<evalbytes>|/evalbytes EXPR> fixes that to work the way one would
4847expect:
4848
4849=end original
4850
4851L<C<evalbytes>|/evalbytes EXPR> は、人が想定するだろう手法で動作するように
4852これを修正します:
4853
4854 use feature "evalbytes";
4855 BEGIN { evalbytes "use Semi::Semicolons; # filtered" }
4856 # not filtered
4857
4858=back
4859
4860=back
4861
4862=begin original
4863
4864Problems can arise if the string expands a scalar containing a floating
4865point number. That scalar can expand to letters, such as C<"NaN"> or
4866C<"Infinity">; or, within the scope of a L<C<use locale>|locale>, the
4867decimal point character may be something other than a dot (such as a
4868comma). None of these are likely to parse as you are likely expecting.
4869
4870=end original
4871
4872文字列をが小数点を含むスカラを展開するときに問題が起こることがあります。
4873そのようなスカラは C<"NaN"> や C<"Infinity"> のような文字に
4874展開されることがあります; または、L<C<use locale>|locale> のスコープの中では、
4875小数点文字は (カンマのような) ドット以外の文字かもしれません。
4876これらはどれもあなたがおそらく予測しているようにはパースされません。
4877
4878=begin original
4879
4880You should be especially careful to remember what's being looked at
4881when:
4882
4883=end original
4884
4885以下のような場合に、何が調べられるかに特に注意しておくことが必要です:
4886
40534887 eval $x; # CASE 1
40544888 eval "$x"; # CASE 2
40554889
40564890 eval '$x'; # CASE 3
40574891 eval { $x }; # CASE 4
40584892
40594893 eval "\$$x++"; # CASE 5
40604894 $$x++; # CASE 6
40614895
40624896=begin original
40634897
40644898Cases 1 and 2 above behave identically: they run the code contained in
40654899the variable $x. (Although case 2 has misleading double quotes making
40664900the reader wonder what else might be happening (nothing is).) Cases 3
40674901and 4 likewise behave in the same way: they run the code C<'$x'>, which
40684902does nothing but return the value of $x. (Case 4 is preferred for
40694903purely visual reasons, but it also has the advantage of compiling at
40704904compile-time instead of at run-time.) Case 5 is a place where
40714905normally you I<would> like to use double quotes, except that in this
40724906particular situation, you can just use symbolic references instead, as
40734907in case 6.
40744908
40754909=end original
40764910
40774911上記の CASE 1 と CASE 2 の動作は同一で、変数 $x 内の
40784912コードを実行します。
40794913(ただし、CASE 2 では、必要のないダブルクォートによって、
40804914読む人が何が起こるか混乱することでしょう (何も起こりませんが)。)
40814915同様に CASE 3 と CASE 4 の動作も等しく、$x の値を返す以外に
4082何もしない C<$x> というコードを実行します
4916何もしない C<$x> というコードを実行します
40834917(純粋に見た目の問題で、CASE 4 が好まれますが、
40844918実行時でなくコンパイル時にコンパイルされるという利点もあります)。
4085CASE 5 の場合は、通常ダブルクォートを使用します
4919CASE 5 の場合は、通常ダブルクォートを使用 I<します>;
40864920この状況を除けば、CASE 6 のように、単に
40874921シンボリックリファレンスを使えば良いでしょう。
40884922
40894923=begin original
40904924
4091Before Perl 5.14, the assignment to C<$@> occurred before restoration
4925An C<eval ''> executed within a subroutine defined
4092of localized variables, which means that for your code to run on older
4926in the C<DB> package doesn't see the usual
4093versions, a temporary is required if you want to mask some but not all
4927surrounding lexical scope, but rather the scope of the first non-DB piece
4094errors:
4928of code that called it. You don't normally need to worry about this unless
4929you are writing a Perl debugger.
40954930
40964931=end original
40974932
4098Perl 5.14 より前では、C<$@> への代入はロカル化された変数復帰の前に
4933C<DB> パッケジで定義されたサブルーチン内で C<eval ''> を実行すると、通常
4099起きるので、古いバジョン実行される場合、全てではなく一部だけ
4934レキシカルスコではなく、これを呼び出した最初の非 DB コード片
4100エラーをマクしたい場合は一時変数が必要で:
4935コープなりま
4936Perl デバッガを書いているのでない限り、普通はこれについて心配する必要は
4937ありません。
41014938
4102 # alter $@ on nefarious repugnancy only
4939=begin original
4940
4941The final semicolon, if any, may be omitted from the value of EXPR.
4942
4943=end original
4944
4945最後のセミコロンは、もしあれば、EXPR の値から省くことができます。
4946
4947=item Block eval
4948
4949=begin original
4950
4951If the code to be executed doesn't vary, you may use the eval-BLOCK
4952form to trap run-time errors without incurring the penalty of
4953recompiling each time. The error, if any, is still returned in
4954L<C<$@>|perlvar/$@>.
4955Examples:
4956
4957=end original
4958
4959実行するコードが変わらないのであれば、毎回多量の再コンパイルすることなしに、
4960実行時エラーのトラップを行なうために、
4961eval-BLOCK 形式を使うことができます。
4962エラーがあれば、やはり L<C<$@>|perlvar/$@> に返されます。
4963例:
4964
4965 # make divide-by-zero nonfatal
4966 eval { $answer = $a / $b; }; warn $@ if $@;
4967
4968 # same thing, but less efficient
4969 eval '$answer = $a / $b'; warn $@ if $@;
4970
4971 # a compile-time error
4972 eval { $answer = }; # WRONG
4973
4974 # a run-time error
4975 eval '$answer ='; # sets $@
4976
4977=begin original
4978
4979If you want to trap errors when loading an XS module, some problems with
4980the binary interface (such as Perl version skew) may be fatal even with
4981C<eval> unless C<$ENV{PERL_DL_NONLAZY}> is set. See
4982L<perlrun|perlrun/PERL_DL_NONLAZY>.
4983
4984=end original
4985
4986XS モジュールのロード中のエラーをトラップしたいなら、
4987(Perl バージョンの違いのような) バイナリインターフェースに関する問題に
4988ついては C<$ENV{PERL_DL_NONLAZY}> がセットされていない
4989C<eval> でも致命的エラーになるかもしれません。
4990L<perlrun|perlrun/PERL_DL_NONLAZY> を参照してください。
4991
4992=begin original
4993
4994Using the C<eval {}> form as an exception trap in libraries does have some
4995issues. Due to the current arguably broken state of C<__DIE__> hooks, you
4996may wish not to trigger any C<__DIE__> hooks that user code may have installed.
4997You can use the C<local $SIG{__DIE__}> construct for this purpose,
4998as this example shows:
4999
5000=end original
5001
5002C<eval{}> 形式をライブラリの例外を捕捉するために使うときには
5003問題があります。
5004現在の C<__DIE__> フックの状態はほぼ確実に壊れているという理由で、
5005ユーザーのコードが設定した C<__DIE__> フックを実行したくないかもしれません。
5006この目的には以下の例のように、C<local $SIG{__DIE__}> 構造が使えます。
5007
5008 # a private exception trap for divide-by-zero
5009 eval { local $SIG{'__DIE__'}; $answer = $a / $b; };
5010 warn $@ if $@;
5011
5012=begin original
5013
5014This is especially significant, given that C<__DIE__> hooks can call
5015L<C<die>|/die LIST> again, which has the effect of changing their error
5016messages:
5017
5018=end original
5019
5020これは特に顕著です; 与えられた C<__DIE__> フックは L<C<die>|/die LIST> を
5021もう一度呼び出すことができ、これによってエラーメッセージを変える
5022効果があります:
5023
5024 # __DIE__ hooks may modify error messages
41035025 {
4104 my $e;
5026 local $SIG{'__DIE__'} =
4105 {
5027 sub { (my $x = $_[0]) =~ s/foo/bar/g; die $x };
4106 local $@; # protect existing $@
5028 eval { die "foo lives here" };
4107 eval { test_repugnancy() };
5029 print $@ if $@; # prints "bar lives here"
4108 # $@ =~ /nefarious/ and die $@; # Perl 5.14 and higher only
4109 $@ =~ /nefarious/ and $e = $@;
4110 }
4111 die $e if defined $e
41125030 }
41135031
41145032=begin original
41155033
5034Because this promotes action at a distance, this counterintuitive behavior
5035may be fixed in a future release.
5036
5037=end original
5038
5039これは距離の離れた行動であるため、この直感的でない振る舞いは
5040将来のリリースでは修正されるかもしれません。
5041
5042=begin original
5043
41165044C<eval BLOCK> does I<not> count as a loop, so the loop control statements
4117C<next>, C<last>, or C<redo> cannot be used to leave or restart the block.
5045L<C<next>|/next LABEL>, L<C<last>|/last LABEL>, or
5046L<C<redo>|/redo LABEL> cannot be used to leave or restart the block.
41185047
41195048=end original
41205049
4121C<eval BLOCK> はループとして I<扱われません>; 従って、C<next>, C<last>,
5050C<eval BLOCK> はループとして I<扱われません>; 従って、L<C<next>|/next LABEL>,
4122C<redo> といったループ制御文でブロックから離れたり再実行したりはできません。
5051L<C<last>|/last LABEL>, L<C<redo>|/redo LABEL> といったループ制御文で
5052ブロックから離れたり再実行したりはできません。
41235053
41245054=begin original
41255055
4126An C<eval ''> executed within a subroutine defined
5056The final semicolon, if any, may be omitted from within the BLOCK.
4127in the C<DB> package doesn't see the usual
4128surrounding lexical scope, but rather the scope of the first non-DB piece
4129of code that called it. You don't normally need to worry about this unless
4130you are writing a Perl debugger.
41315057
41325058=end original
41335059
4134C<DB> パッケージで定義されたサブルーチン内で C<eval ''> を実行ると、通常の
5060最後のセミコロンは、もしあれば、BLOCK の中から削除され
4135レキシカルスコープではなく、これを呼び出した最初の非 DB コード片の
4136スコープになります。
4137Perl デバッガを書いているのでない限り、普通はこれについて心配する必要は
4138ありません。
41395061
5062=back
5063
41405064=item evalbytes EXPR
41415065X<evalbytes>
41425066
41435067=item evalbytes
41445068
41455069=for Pod::Functions +evalbytes similar to string eval, but intend to parse a bytestream
41465070
41475071=begin original
41485072
4149This function is like L</eval> with a string argument, except it always
5073This function is similar to a L<string eval|/eval EXPR>, except it
4150parses its argument, or C<$_> if EXPR is omitted, as a string of bytes. A
5074always parses its argument (or L<C<$_>|perlvar/$_> if EXPR is omitted)
4151string containing characters whose ordinal value exceeds 255 results in an
5075as a byte string. If the string contains any code points above 255, then
4152error. Source filters activated within the evaluated code apply to the
5076it cannot be a byte string, and the C<evalbytes> will fail with the error
4153code itself.
5077stored in C<$@>.
41545078
41555079=end original
41565080
4157この関数は文字列引数の L</eval> と同様ですが、引数(EXPR が省略された場合は
5081この関数は L<文字列 eval|/eval EXPR> に似ていますが、引数(EXPR が
4158C<$_>) を常にバイト単位のの文字列として扱います。
5082省略された場合はL<C<$_>|perlvar/$_>) を常にバイト単位のの文字列として
4159序数が 255 を超える文字を含む文字列はエラーになります。
5083扱います。
5084文字列に 255 を超える符号位置が含まれている場合、バイト単位文字列に
5085することができないので、
5086C<evalbytes> は失敗し、エラーは C<$@> に保管されます。
5087
5088=begin original
5089
5090C<use utf8> and C<no utf8> within the string have their usual effect.
5091
5092=end original
5093
5094文字列中の C<use utf8> と C<no utf8> は通常の効果を持ちます。
5095
5096=begin original
5097
5098Source filters activated within the evaluated code apply to the code
5099itself.
5100
5101=end original
5102
41605103eval されたコード内で有効になったソースフィルタはコード自体に適用されます。
41615104
41625105=begin original
41635106
4164This function is only available under the C<evalbytes> feature, a
5107L<C<evalbytes>|/evalbytes EXPR> is available starting in Perl v5.16. To
4165C<use v5.16> (or higher) declaration, or with a C<CORE::> prefix. See
5108access it, you must say C<CORE::evalbytes>, but you can omit the
4166L<feature> for more information.
5109C<CORE::> if the
5110L<C<"evalbytes"> feature|feature/The 'unicode_eval' and 'evalbytes' features>
5111is enabled. This is enabled automatically with a C<use v5.16> (or
5112higher) declaration in the current scope.
41675113
41685114=end original
41695115
4170この関数は C<evalbytes> 機能が有効か、C<use v5.16> (またはそれ以上) が
5116L<C<evalbytes>|/evalbytes EXPR> は Perl v5.16 から利用可能です。
4171宣言されるか、C<CORE::> 接頭辞付きの場合にのみ有効で
5117にアクセスすには C<CORE::evalbytes> る必要がありますが、
4172さらなる情報については L<feature> を参照してください。
5118L<C<"evalbytes"> 機能|feature/The 'unicode_eval' and 'evalbytes' features>
5119有効なら C<CORE::> を省略できます。
5120これは現在のスコープで C<use v5.16> (またはそれ以上) 宣言があると
5121自動的に有効になります。
41735122
41745123=item exec LIST
41755124X<exec> X<execute>
41765125
41775126=item exec PROGRAM LIST
41785127
41795128=for Pod::Functions abandon this program to run another
41805129
41815130=begin original
41825131
4183The C<exec> function executes a system command I<and never returns>;
5132The L<C<exec>|/exec LIST> function executes a system command I<and never
4184use C<system> instead of C<exec> if you want it to return. It fails and
5133returns>; use L<C<system>|/system LIST> instead of L<C<exec>|/exec LIST>
5134if you want it to return. It fails and
41855135returns false only if the command does not exist I<and> it is executed
41865136directly instead of via your system's command shell (see below).
41875137
41885138=end original
41895139
4190C<exec> 関数は、システムのコマンドを実行し、I<戻ってはきません>;
5140L<C<exec>|/exec LIST> 関数は、システムのコマンドを実行し、I<戻ってはきません>;
4191戻って欲しい場合には、C<exec>ではなく C<system> 関数を使ってください。
5141戻って欲しい場合には、L<C<exec>|/exec LIST>ではなく
5142L<C<system>|/system LIST> 関数を使ってください。
41925143コマンドが存在せず、I<しかも> システムのコマンドシェル経由でなく
41935144直接コマンドを実行しようとした場合にのみこの関数は失敗して偽を返します。
41945145
41955146=begin original
41965147
4197Since it's a common mistake to use C<exec> instead of C<system>, Perl
5148Since it's a common mistake to use L<C<exec>|/exec LIST> instead of
4198warns you if C<exec> is called in void context and if there is a following
5149L<C<system>|/system LIST>, Perl warns you if L<C<exec>|/exec LIST> is
4199statement that isn't C<die>, C<warn>, or C<exit> (if C<-w> is set--but
5150called in void context and if there is a following statement that isn't
4200you always do that, right?). If you I<really> want to follow an C<exec>
5151L<C<die>|/die LIST>, L<C<warn>|/warn LIST>, or L<C<exit>|/exit EXPR> (if
4201with some other statement, you can use one of these styles to avoid the warning:
5152L<warnings> are enabled--but you always do that, right?). If you
5153I<really> want to follow an L<C<exec>|/exec LIST> with some other
5154statement, you can use one of these styles to avoid the warning:
42025155
42035156=end original
42045157
4205C<system> の代わりに C<exec> を使うというよくある間違いを防ぐために、
5158L<C<system>|/system LIST> の代わりに L<C<exec>|/exec LIST> を使うという
4206C<exec> が無効コンテキストで呼び出されて、引き続く文が C<die>, C<warn>,
5159よくある間違いを防ぐために、L<C<exec>|/exec LIST> が無効コンテキストで
4207C<exit> 以外の場合、Perl は警告を出します(C<-w> がセットされている場合 --
5160呼び出されて、引き続く文が L<C<die>|/die LIST>, L<C<warn>|/warn LIST>,
4208でもいつもセットますよね?)。
5161L<C<exit>|/exit EXPR> 以外の場合、Perl は警告を出します(L<warnings> が
4209もし I<本当に> C<exec> 後に他の文を書きたい場合、以下のどちらかの
5162有効の場合 -- でもいつもセットしてますよね?)。
4210スタイル使うことで警告を回避でます:
5163もし I<本当に> L<C<exec>|/exec LIST> の後に他の文たい場合、以下の
5164どちらかのスタイルを使うことで警告を回避できます:
42115165
42125166 exec ('foo') or print STDERR "couldn't exec foo: $!";
42135167 { exec ('foo') }; print STDERR "couldn't exec foo: $!";
42145168
42155169=begin original
42165170
4217If there is more than one argument in LIST, or if LIST is an array
5171If there is more than one argument in LIST, this calls L<execvp(3)> with the
4218with more than one value, calls execvp(3) with the arguments in LIST.
5172arguments in LIST. If there is only one element in LIST, the argument is
4219If there is only one scalar argument or an array with one element in it,
5173checked for shell metacharacters, and if there are any, the entire
4220the argument is checked for shell metacharacters, and if there are any,
5174argument is passed to the system's command shell for parsing (this is
4221the entire argument is passed to the system's command shell for parsing
5175C</bin/sh -c> on Unix platforms, but varies on other platforms). If
4222(this is C</bin/sh -c> on Unix platforms, but varies on other platforms).
5176there are no shell metacharacters in the argument, it is split into words
4223If there are no shell metacharacters in the argument, it is split into
5177and passed directly to C<execvp>, which is more efficient. Examples:
4224words and passed directly to C<execvp>, which is more efficient.
4225Examples:
42265178
42275179=end original
42285180
4229LIST に複数の引数がある場合、LIST が複数持つ
5181LIST に複数の引数がある場合、LIST の引数使って L<execvp(3)> を
4230配列の場合には、LIST の引数を使って、execvp(3) を呼び出します。
5182呼び出します。
42311 つのスカラ引数のみまたは要素が一つの配列の場合には、その引数から
5183LIST 要素が一つのの場合には、その引数からシェルのメタ文字をチェックし、
4232シェルのメタ文字をチェックし、もしメタ文字があれば、
5184もしメタ文字があれば、引数全体をシステムのコマンドシェル(これはUnix では
4233引数全体をシステムのコマンドシェル(これはUnix では
42345185C</bin/sh -c> ですが、システムによって異なります)に渡して解析させます。
42355186シェルのメタ文字がなかった場合、引数は単語に分解されて直接 C<execvp> に
42365187渡されます; この方がより効率的です。
42375188例:
42385189
42395190 exec '/bin/echo', 'Your arguments are: ', @ARGV;
42405191 exec "sort $outfile | uniq";
42415192
42425193=begin original
42435194
42445195If you don't really want to execute the first argument, but want to lie
42455196to the program you are executing about its own name, you can specify
42465197the program you actually want to run as an "indirect object" (without a
4247comma) in front of the LIST. (This always forces interpretation of the
5198comma) in front of the LIST, as in C<exec PROGRAM LIST>. (This always
4248LIST as a multivalued list, even if there is only a single scalar in
5199forces interpretation of the LIST as a multivalued list, even if there
4249the list.) Example:
5200is only a single scalar in the list.) Example:
42505201
42515202=end original
42525203
4253第一引数に指定するものを本当に実行したいが、実行する
5204第一引数に指定するものを本当に実行したいが、実行するプログラムに対して別の
4254プログラムに対して別の名前を教えたい場合には、LISTのに、
5205名前を教えたい場合には、C<exec PROGRAM LIST> ように、LIST の前に
4255「間接オブジェクト」(コンマなし) として実際に
5206「間接オブジェクト」(コンマなし) として実際に実行したいプログラムを
4256実行したいプログラムを指定することができます。
5207指定することができます。
4257(これによって、LIST に単一のスカラしかなくても、複数
5208(これによって、LIST に単一のスカラしかなくても、複数値のリストであるように、
4258値のリストであるように、LIST の解釈を行ないます。)
5209LIST の解釈を行ないます。)
42595210例:
42605211
4261 $shell = '/bin/csh';
5212 my $shell = '/bin/csh';
42625213 exec $shell '-sh'; # pretend it's a login shell
42635214
42645215=begin original
42655216
42665217or, more directly,
42675218
42685219=end original
42695220
42705221あるいは、より直接的に、
42715222
42725223 exec {'/bin/csh'} '-sh'; # pretend it's a login shell
42735224
42745225=begin original
42755226
42765227When the arguments get executed via the system shell, results are
42775228subject to its quirks and capabilities. See L<perlop/"`STRING`">
42785229for details.
42795230
42805231=end original
42815232
42825233引数がシステムシェルで実行されるとき、結果はシェルの奇癖と能力によって
42835234変わります。
42845235詳細については L<perlop/"`STRING`"> を参照してください。
42855236
42865237=begin original
42875238
4288Using an indirect object with C<exec> or C<system> is also more
5239Using an indirect object with L<C<exec>|/exec LIST> or
4289secure. This usage (which also works fine with system()) forces
5240L<C<system>|/system LIST> is also more secure. This usage (which also
5241works fine with L<C<system>|/system LIST>) forces
42905242interpretation of the arguments as a multivalued list, even if the
42915243list had just one argument. That way you're safe from the shell
42925244expanding wildcards or splitting up words with whitespace in them.
42935245
42945246=end original
42955247
4296C<exec> や C<system> で間接オブジェクトを使うのもより安全です。
5248L<C<exec>|/exec LIST> L<C<system>|/system LIST> で間接オブジェクトを
4297この使い方(system() でも同様にまく動きます)は、たとえ引数が一つだけ
5249使うのもより安全です。
4298場合も、複数の値を持つリストとして引数を解釈するとを強制します
5250の使い方(L<C<system>|/system LIST> でも同様にうく動きま)は、たとえ
5251引数が一つだけの場合も、複数の値を持つリストとして引数を解釈することを
5252強制します。
42995253この方法で、シェルによるワイルドカード展開や、空白による単語の分割から
43005254守られます。
43015255
4302 @args = ( "echo surprise" );
5256 my @args = ( "echo surprise" );
43035257
43045258 exec @args; # subject to shell escapes
43055259 # if @args == 1
43065260 exec { $args[0] } @args; # safe even with one-arg list
43075261
43085262=begin original
43095263
43105264The first version, the one without the indirect object, ran the I<echo>
43115265program, passing it C<"surprise"> an argument. The second version didn't;
43125266it tried to run a program named I<"echo surprise">, didn't find it, and set
4313C<$?> to a non-zero value indicating failure.
5267L<C<$?>|perlvar/$?> to a non-zero value indicating failure.
43145268
43155269=end original
43165270
43175271間接オブジェクトなしの一つ目のバージョンでは、I<echo> プログラムが実行され、
43185272C<"surprise"> が引数として渡されます。
43195273二つ目のバージョンでは違います; I<"echo surprise"> という名前の
43205274プログラムを実行しようとして、見つからないので、失敗したことを示すために
4321C<$?> に非 0 がセットされます。
5275L<C<$?>|perlvar/$?> に非 0 がセットされます。
43225276
43235277=begin original
43245278
5279On Windows, only the C<exec PROGRAM LIST> indirect object syntax will
5280reliably avoid using the shell; C<exec LIST>, even with more than one
5281element, will fall back to the shell if the first spawn fails.
5282
5283=end original
5284
5285Windows では、C<exec PROGRAM LIST> 間接オブジェクト構文のみが、シェルを
5286使うのを回避するための信頼できる方法です; C<exec LIST> は、複数の要素が
5287あっても、最初の spawn が失敗したときにシェルに
5288フォールバックすることがあります。
5289
5290=begin original
5291
43255292Perl attempts to flush all files opened for output before the exec,
43265293but this may not be supported on some platforms (see L<perlport>).
4327To be safe, you may need to set C<$|> ($AUTOFLUSH in English) or
5294To be safe, you may need to set L<C<$E<verbar>>|perlvar/$E<verbar>>
4328call the C<autoflush()> method of C<IO::Handle> on any open handles
5295(C<$AUTOFLUSH> in L<English>) or call the C<autoflush> method of
4329to avoid lost output.
5296L<C<IO::Handle>|IO::Handle/METHODS> on any open handles to avoid lost
5297output.
43305298
43315299=end original
43325300
4333v5.6.0 から、Perl は exec の前に出力用に開かれている全てのファイルを
5301Perl は exec の前に出力用に開かれている全てのファイルを
43345302フラッシュしようとしますが、これに対応していないプラットフォームもあります
43355303(L<perlport> を参照してください)。
43365304安全のためには、出力が重複するのを避けるために、全てのオープンしている
4337ハンドルに対して C<$|> (English モジュールでは $AUTOFLUSH) を設定するか、
5305ハンドルに対して L<C<$E<verbar>>|perlvar/$E<verbar>>
4338C<IO::Handle> モジュール C<autoflush()> メソッドを呼ぶ必要が
5306(L<English> モジュールでは C<$AUTOFLUSH>)設定するか、
4339あるかもしれません。
5307L<C<IO::Handle>|IO::Handle/METHODS> モジュールの C<autoflush> メソッドを
5308呼ぶ必要があるかもしれません。
43405309
43415310=begin original
43425311
4343Note that C<exec> will not call your C<END> blocks, nor will it invoke
5312Note that L<C<exec>|/exec LIST> will not call your C<END> blocks, nor
4344C<DESTROY> methods on your objects.
5313will it invoke C<DESTROY> methods on your objects.
43455314
43465315=end original
43475316
4348C<exec> は C<END> ブロックや、オブジェクトの C<DESTROY> メソッドを
5317L<C<exec>|/exec LIST> は C<END> ブロックや、オブジェクトの
4349起動しないことに注意してください。
5318C<DESTROY> メソッドを起動しないことに注意してください。
43505319
43515320=begin original
43525321
43535322Portability issues: L<perlport/exec>.
43545323
43555324=end original
43565325
43575326移植性の問題: L<perlport/exec>。
43585327
43595328=item exists EXPR
43605329X<exists> X<autovivification>
43615330
43625331=for Pod::Functions test whether a hash key is present
43635332
43645333=begin original
43655334
43665335Given an expression that specifies an element of a hash, returns true if the
43675336specified element in the hash has ever been initialized, even if the
43685337corresponding value is undefined.
43695338
43705339=end original
43715340
43725341ハッシュ要素を示す表現が与えられ、指定された要素が、ハッシュに存在すれば、
43735342たとえ対応する値が未定義でも真を返します。
43745343
43755344 print "Exists\n" if exists $hash{$key};
43765345 print "Defined\n" if defined $hash{$key};
43775346 print "True\n" if $hash{$key};
43785347
43795348=begin original
43805349
43815350exists may also be called on array elements, but its behavior is much less
4382obvious and is strongly tied to the use of L</delete> on arrays. B<Be aware>
5351obvious and is strongly tied to the use of L<C<delete>|/delete EXPR> on
4383that calling exists on array values is deprecated and likely to be removed in
5352arrays.
4384a future version of Perl.
43855353
43865354=end original
43875355
43885356exists は配列の要素に対しても呼び出せますが、その振る舞いははるかに
4389不明確で、配列に対する L</delete> の使用と強く結びついています。
5357不明確で、配列に対する L<C<delete>|/delete EXPR> の使用と強く
4390配列の値に対して exists を呼のは非推奨であり、将来のバージョンの
5358ついていま
4391Perl では削除されるかもしれないことを B<注意してください> 。
43925359
5360=begin original
5361
5362B<WARNING:> Calling L<C<exists>|/exists EXPR> on array values is
5363strongly discouraged. The
5364notion of deleting or checking the existence of Perl array elements is not
5365conceptually coherent, and can lead to surprising behavior.
5366
5367=end original
5368
5369B<警告:> 配列の値に対して L<C<exists>|/exists EXPR> を呼び出すことは強く
5370非推奨です。
5371Perl の配列要素を削除したり存在を調べたりする記法は概念的に一貫しておらず、
5372驚くべき振る舞いを引き起こすことがあります。
5373
43935374 print "Exists\n" if exists $array[$index];
43945375 print "Defined\n" if defined $array[$index];
43955376 print "True\n" if $array[$index];
43965377
43975378=begin original
43985379
43995380A hash or array element can be true only if it's defined and defined only if
44005381it exists, but the reverse doesn't necessarily hold true.
44015382
44025383=end original
44035384
44045385ハッシュまたは配列要素は、定義されているときにのみ真となり、
44055386存在しているときにのみ定義されますが、逆は必ずしも真ではありません。
44065387
44075388=begin original
44085389
44095390Given an expression that specifies the name of a subroutine,
44105391returns true if the specified subroutine has ever been declared, even
44115392if it is undefined. Mentioning a subroutine name for exists or defined
44125393does not count as declaring it. Note that a subroutine that does not
44135394exist may still be callable: its package may have an C<AUTOLOAD>
44145395method that makes it spring into existence the first time that it is
44155396called; see L<perlsub>.
44165397
44175398=end original
44185399
44195400引数としてサブルーチンの名前が指定された場合、
44205401指定されたサブルーチンが宣言されていれば(たとえ未定義でも)
44215402真を返します。
44225403exists や defined のために言及されているサブルーチン名は
44235404宣言としてのカウントに入りません。
44245405存在しないサブルーチンでも呼び出し可能かもしれないことに注意してください:
44255406パッケージが C<AUTOLOAD> メソッドを持っていて、最初に呼び出された時に
44265407存在を作り出すかもしれません; L<perlsub> を参照してください。
44275408
44285409 print "Exists\n" if exists &subroutine;
44295410 print "Defined\n" if defined &subroutine;
44305411
44315412=begin original
44325413
44335414Note that the EXPR can be arbitrarily complicated as long as the final
44345415operation is a hash or array key lookup or subroutine name:
44355416
44365417=end original
44375418
4438最終的な操作がハッシュや配列の key による検索またはサブルーチン名である限りは、
5419最終的な操作がハッシュや配列の key による検索または
4439EXPR には任意の複雑な式を置くことができます:
5420サブルーチン名である限りは、EXPR には任意の複雑な式を置くことができます:
44405421
44415422 if (exists $ref->{A}->{B}->{$key}) { }
44425423 if (exists $hash{A}{B}{$key}) { }
44435424
44445425 if (exists $ref->{A}->{B}->[$ix]) { }
44455426 if (exists $hash{A}{B}[$ix]) { }
44465427
44475428 if (exists &{$ref->{A}{B}{$key}}) { }
44485429
44495430=begin original
44505431
44515432Although the most deeply nested array or hash element will not spring into
44525433existence just because its existence was tested, any intervening ones will.
44535434Thus C<< $ref->{"A"} >> and C<< $ref->{"A"}->{"B"} >> will spring
4454into existence due to the existence test for the $key element above.
5435into existence due to the existence test for the C<$key> element above.
44555436This happens anywhere the arrow operator is used, including even here:
44565437
44575438=end original
44585439
44595440最も深くネストした配列やハッシュの要素は、その存在をテストしただけでは
44605441存在するようにはなりませんが、途中のものは存在するようになります。
4461従って C<< $ref->{"A"} >> と C<< $ref->{"A"}->{"B"} >> は上記の $key の
5442従って C<< $ref->{"A"} >> と C<< $ref->{"A"}->{"B"} >> は上記の C<$key>
44625443存在をテストしたことによって存在するようになります。
44635444これは、矢印演算子が使われるところでは、以下のようなものを含むどこででも
44645445起こります。
44655446
44665447 undef $ref;
44675448 if (exists $ref->{"Some key"}) { }
44685449 print $ref; # prints HASH(0x80d3d5c)
44695450
44705451=begin original
44715452
4472This surprising autovivification in what does not at first--or even
4473second--glance appear to be an lvalue context may be fixed in a future
4474release.
4475
4476=end original
4477
4478一目見ただけでは -- あるいは二目見ても -- 驚かされる、左辺値コンテキストでの
4479自動有効化は将来のリリースでは修正されるでしょう。
4480
4481=begin original
4482
44835453Use of a subroutine call, rather than a subroutine name, as an argument
4484to exists() is an error.
5454to L<C<exists>|/exists EXPR> is an error.
44855455
44865456=end original
44875457
4488exists() の引数としてサブルーチン名でなくサブルーチン呼び出しを使うと、
5458L<C<exists>|/exists EXPR> の引数としてサブルーチン名でなくサブルーチン
4489エラーになります。
5459呼び出しを使うと、エラーになります。
44905460
44915461 exists &sub; # OK
44925462 exists &sub(); # Error
44935463
44945464=item exit EXPR
44955465X<exit> X<terminate> X<abort>
44965466
44975467=item exit
44985468
44995469=for Pod::Functions terminate this program
45005470
45015471=begin original
45025472
45035473Evaluates EXPR and exits immediately with that value. Example:
45045474
45055475=end original
45065476
45075477EXPR を評価し、即座にその値を持って終了します。
45085478例:
45095479
4510 $ans = <STDIN>;
5480 my $ans = <STDIN>;
45115481 exit 0 if $ans =~ /^[Xx]/;
45125482
45135483=begin original
45145484
4515See also C<die>. If EXPR is omitted, exits with C<0> status. The only
5485See also L<C<die>|/die LIST>. If EXPR is omitted, exits with C<0>
5486status. The only
45165487universally recognized values for EXPR are C<0> for success and C<1>
45175488for error; other values are subject to interpretation depending on the
45185489environment in which the Perl program is running. For example, exiting
4519549069 (EX_UNAVAILABLE) from a I<sendmail> incoming-mail filter will cause
45205491the mailer to return the item undelivered, but that's not true everywhere.
45215492
45225493=end original
45235494
4524C<die> も参照してください。
5495L<C<die>|/die LIST> も参照してください。
45255496EXPR が省略された場合には、ステータスを C<0> として終了します。
45265497EXPR の値として広く利用可能なのは C<0> が成功で C<1> が
45275498エラーということだけです; その他の値は、 Perl が実行される環境によって異なる
45285499解釈がされる可能性があります。
45295500例えば、I<sendmail> 到着メールフィルタから 69 (EX_UNAVAILABLE) で終了すると
45305501メーラーはアイテムを配達せずに差し戻しますが、
45315502これはいつでも真ではありません。
45325503
45335504=begin original
45345505
4535Don't use C<exit> to abort a subroutine if there's any chance that
5506Don't use L<C<exit>|/exit EXPR> to abort a subroutine if there's any
4536someone might want to trap whatever error happened. Use C<die> instead,
5507chance that someone might want to trap whatever error happened. Use
4537which can be trapped by an C<eval>.
5508L<C<die>|/die LIST> instead, which can be trapped by an
5509L<C<eval>|/eval EXPR>.
45385510
45395511=end original
45405512
45415513誰かが発生したエラーをトラップしようと考えている可能性がある場合は、
4542サブルーチンの中断に C<exit> を使わないでください。
5514サブルーチンの中断に L<C<exit>|/exit EXPR> を使わないでください。
4543代わりに C<eval> でトラップできる C<die> を使ってください。
5515代わりに L<C<eval>|/eval EXPR> でトラップできる L<C<die>|/die LIST>
5516使ってください。
45445517
45455518=begin original
45465519
4547The exit() function does not always exit immediately. It calls any
5520The L<C<exit>|/exit EXPR> function does not always exit immediately. It
4548defined C<END> routines first, but these C<END> routines may not
5521calls any defined C<END> routines first, but these C<END> routines may
4549themselves abort the exit. Likewise any object destructors that need to
5522not themselves abort the exit. Likewise any object destructors that
4550be called are called before the real exit. C<END> routines and destructors
5523need to be called are called before the real exit. C<END> routines and
4551can change the exit status by modifying C<$?>. If this is a problem, you
5524destructors can change the exit status by modifying L<C<$?>|perlvar/$?>.
4552can call C<POSIX::_exit($status)> to avoid END and destructor processing.
5525If this is a problem, you can call
4553See L<perlmod> for details.
5526L<C<POSIX::_exit($status)>|POSIX/C<_exit>> to avoid C<END> and destructor
5527processing. See L<perlmod> for details.
45545528
45555529=end original
45565530
4557exit() 関数は常に直ちに終了するわけではありません。
5531L<C<exit>|/exit EXPR> 関数は常に直ちに終了するわけではありません。
4558まず、定義されている END ルーチンを呼び出しますが、
5532まず、定義されている C<END> ルーチンを呼び出しますが、
45595533C<END> ルーチン自身は exit を止められません。
45605534同様に、呼び出す必要のあるオブジェクトデストラクタは
45615535すべて、実際の終了前に呼び出されます。
4562C<END> ルーチンとデストラクタは C<$?> を修正することで終了コードを
5536C<END> ルーチンとデストラクタは L<C<$?>|perlvar/$?> を修正することで
4563変更できます。
5537終了コードを変更できます。
4564これが問題になる場合は、END やデストラクタが実行されることを
5538これが問題になる場合は、C<END> やデストラクタが実行されることを
4565防ぐために C<POSIX::_exit($status)> を呼び出してください。
5539防ぐために L<C<POSIX::_exit($status)>|POSIX/C<_exit>> を呼び出してください。
45665540詳しくは L<perlmod> を参照してください。
45675541
45685542=begin original
45695543
45705544Portability issues: L<perlport/exit>.
45715545
45725546=end original
45735547
45745548移植性の問題: L<perlport/exit>。
45755549
45765550=item exp EXPR
45775551X<exp> X<exponential> X<antilog> X<antilogarithm> X<e>
45785552
45795553=item exp
45805554
45815555=for Pod::Functions raise I<e> to a power
45825556
45835557=begin original
45845558
45855559Returns I<e> (the natural logarithm base) to the power of EXPR.
45865560If EXPR is omitted, gives C<exp($_)>.
45875561
45885562=end original
45895563
45905564I<e> (自然対数の底) の EXPR 乗を返します。
45915565EXPR を省略した場合には、C<exp($_)> を返します。
45925566
45935567=item fc EXPR
45945568X<fc> X<foldcase> X<casefold> X<fold-case> X<case-fold>
45955569
45965570=item fc
45975571
45985572=for Pod::Functions +fc return casefolded version of a string
45995573
46005574=begin original
46015575
46025576Returns the casefolded version of EXPR. This is the internal function
46035577implementing the C<\F> escape in double-quoted strings.
46045578
46055579=end original
46065580
46075581EXPR の畳み込み版を返します。
46085582これは、ダブルクォート文字列における、C<\F> エスケープを
46095583実装する内部関数です。
46105584
46115585=begin original
46125586
46135587Casefolding is the process of mapping strings to a form where case
46145588differences are erased; comparing two strings in their casefolded
46155589form is effectively a way of asking if two strings are equal,
46165590regardless of case.
46175591
46185592=end original
46195593
46205594畳み込みは大文字小文字の違いを消した形式に文字列をマッピングする処理です;
46215595畳み込み形式で二つの文字列を比較するのは二つの文字列が大文字小文字に
46225596関わらず等しいかどうかを比較する効率的な方法です。
46235597
46245598=begin original
46255599
46265600Roughly, if you ever found yourself writing this
46275601
46285602=end original
46295603
46305604おおよそ、自分自身で以下のように書いていたとしても
46315605
46325606 lc($this) eq lc($that) # Wrong!
46335607 # or
46345608 uc($this) eq uc($that) # Also wrong!
46355609 # or
46365610 $this =~ /^\Q$that\E\z/i # Right!
46375611
46385612=begin original
46395613
46405614Now you can write
46415615
46425616=end original
46435617
46445618今では以下のように書けます
46455619
46465620 fc($this) eq fc($that)
46475621
46485622=begin original
46495623
46505624And get the correct results.
46515625
46525626=end original
46535627
46545628そして正しい結果を得られます。
46555629
46565630=begin original
46575631
4658Perl only implements the full form of casefolding,
5632Perl only implements the full form of casefolding, but you can access
4659but you can access the simple folds using L<Unicode::UCD/casefold()> and
5633the simple folds using L<Unicode::UCD/B<casefold()>> and
4660L<Unicode::UCD/prop_invmap()>.
5634L<Unicode::UCD/B<prop_invmap()>>.
46615635For further information on casefolding, refer to
46625636the Unicode Standard, specifically sections 3.13 C<Default Case Operations>,
466356374.2 C<Case-Normative>, and 5.18 C<Case Mappings>,
4664available at L<http://www.unicode.org/versions/latest/>, as well as the
5638available at L<https://www.unicode.org/versions/latest/>, as well as the
4665Case Charts available at L<http://www.unicode.org/charts/case/>.
5639Case Charts available at L<https://www.unicode.org/charts/case/>.
46665640
46675641=end original
46685642
46695643Perl は完全な形式の畳み込みのみを実装していますが、
4670L<Unicode::UCD/casefold()> と L<Unicode::UCD/prop_invmap()> を使って
5644L<Unicode::UCD/B<casefold()>> と L<Unicode::UCD/B<prop_invmap()>> を使って
46715645単純なたたみ込みにアクセスできます。
46725646畳み込みに関するさらなる情報については、
4673L<http://www.unicode.org/versions/latest/> で利用可能な Unicode 標準、特に
5647L<https://www.unicode.org/versions/latest/> で利用可能な Unicode 標準、特に
467456483.13 C<Default Case Operations>, 4.2 C<Case-Normative>, 5.18
4675C<Case Mappings> および、L<http://www.unicode.org/charts/case/> で
5649C<Case Mappings> および、L<https://www.unicode.org/charts/case/> で
46765650利用可能なケース表を参照してください。
46775651
46785652=begin original
46795653
4680If EXPR is omitted, uses C<$_>.
5654If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
46815655
46825656=end original
46835657
4684EXPR が省略されると、C<$_> を使います。
5658EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
46855659
46865660=begin original
46875661
4688This function behaves the same way under various pragma, such as in a locale,
5662This function behaves the same way under various pragmas, such as within
4689as L</lc> does.
5663L<S<C<"use feature 'unicode_strings">>|feature/The 'unicode_strings' feature>,
5664as L<C<lc>|/lc EXPR> does, with the single exception of
5665L<C<fc>|/fc EXPR> of I<LATIN CAPITAL LETTER SHARP S> (U+1E9E) within the
5666scope of L<S<C<use locale>>|locale>. The foldcase of this character
5667would normally be C<"ss">, but as explained in the L<C<lc>|/lc EXPR>
5668section, case
5669changes that cross the 255/256 boundary are problematic under locales,
5670and are hence prohibited. Therefore, this function under locale returns
5671instead the string C<"\x{17F}\x{17F}">, which is the I<LATIN SMALL LETTER
5672LONG S>. Since that character itself folds to C<"s">, the string of two
5673of them together should be equivalent to a single U+1E9E when foldcased.
46905674
46915675=end original
46925676
4693この関数は、ロケールのようなさまざまなプラグマの影響下では、
5677この関数は、
4694L</lc> と同様に振る舞います。
5678L<S<C<"use feature 'unicode_strings">>|feature/The 'unicode_strings' feature>
5679のようなさまざまなプラグマの影響下では、L<C<lc>|/lc EXPR> と同様に
5680振る舞います;
5681但し、L<S<C<use locale>>|locale> のスコープ内での
5682I<LATIN CAPITAL LETTER SHARP S> (U+1E9E) の L<C<fc>|/fc EXPR> は例外です。
5683この文字の畳み込み文字は普通は C<"ss"> ですが、L<C<lc>|/lc EXPR> の節で
5684説明しているように、ロケールの基での255/256 境界をまたぐ大文字小文字の変更は
5685問題があるので、禁止されています。
5686従って、ロケールの基ではこの関数は代わりに I<LATIN SMALL LETTER LONG S> である
5687C<"\x{17F}\x{17F}"> を返します。
5688この文字自体は C<"s"> の畳み込みなので、これら二つを合わせた文字列は
5689畳み込まれた場合は単一の U+1E9E と等価になります。
46955690
46965691=begin original
46975692
46985693While the Unicode Standard defines two additional forms of casefolding,
46995694one for Turkic languages and one that never maps one character into multiple
4700characters, these are not provided by the Perl core; However, the CPAN module
5695characters, these are not provided by the Perl core. However, the CPAN module
4701C<Unicode::Casing> may be used to provide an implementation.
5696L<C<Unicode::Casing>|Unicode::Casing> may be used to provide an implementation.
47025697
47035698=end original
47045699
47055700Unicode 標準はさらに二つの畳み込み形式、一つはツルキ語、もう一つは決して
47065701一つの文字が複数の文字にマッピングされないもの、を定義していますが、
4707これらは Perl コアでは提供されません; しかし、CPAN モジュール
5702これらは Perl コアでは提供されません
4708C<Unicode::Casing> が実装を提供しています。
5703しかし、CPAN モジュール L<C<Unicode::Casing>|Unicode::Casing> が実装を
5704提供しています。
47095705
47105706=begin original
47115707
4712This keyword is available only when the C<"fc"> feature is enabled,
5708L<C<fc>|/fc EXPR> is available only if the
4713or when prefixed with C<CORE::>; See L<feature>. Alternately,
5709L<C<"fc"> feature|feature/The 'fc' feature> is enabled or if it is
4714include a C<use v5.16> or later to the current scope.
5710prefixed with C<CORE::>. The
5711L<C<"fc"> feature|feature/The 'fc' feature> is enabled automatically
5712with a C<use v5.16> (or higher) declaration in the current scope.
47155713
47165714=end original
47175715
4718このキーワードは C<"fc"> 機能が有効のとき、C<CORE::> が
5716L<C<fc>|/fc EXPR> L<C<"fc"> 機能|feature/The 'fc' feature> が有効か
4719前置されたときにのみ利用可能です; L<feature> を参照してください
5717C<CORE::> が前置されたときにのみ利用可能です。
4720または、現在のスコープに C<use v5.16> またそれ以上を含めてください。
5718L<C<"fc"> 機能|feature/The 'fc' feature> は現在のスコープで
5719C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。
47215720
47225721=item fcntl FILEHANDLE,FUNCTION,SCALAR
47235722X<fcntl>
47245723
47255724=for Pod::Functions file control system call
47265725
47275726=begin original
47285727
4729Implements the fcntl(2) function. You'll probably have to say
5728Implements the L<fcntl(2)> function. You'll probably have to say
47305729
47315730=end original
47325731
4733fcntl(2) 関数を実装します。
5732L<fcntl(2)> 関数を実装します。
47345733正しい定数定義を得るために、まず
47355734
47365735 use Fcntl;
47375736
47385737=begin original
47395738
47405739first to get the correct constant definitions. Argument processing and
4741value returned work just like C<ioctl> below.
5740value returned work just like L<C<ioctl>|/ioctl
4742For example:
5741FILEHANDLE,FUNCTION,SCALAR> below. For example:
47435742
47445743=end original
47455744
47465745と書くことが必要でしょう。
4747引数の処理と返り値については、下記の C<ioctl> と同様に動作します。
5746引数の処理と返り値については、下記の
5747L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同様に動作します。
47485748例えば:
47495749
47505750 use Fcntl;
4751 fcntl($filehandle, F_GETFL, $packed_return_buffer)
5751 my $flags = fcntl($filehandle, F_GETFL, 0)
4752 or die "can't fcntl F_GETFL: $!";
5752 or die "Can't fcntl F_GETFL: $!";
47535753
47545754=begin original
47555755
4756You don't have to check for C<defined> on the return from C<fcntl>.
5756You don't have to check for L<C<defined>|/defined EXPR> on the return
4757Like C<ioctl>, it maps a C<0> return from the system call into
5757from L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>. Like
4758C<"0 but true"> in Perl. This string is true in boolean context and C<0>
5758L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>, it maps a C<0> return
4759in numeric context. It is also exempt from the normal B<-w> warnings
5759from the system call into C<"0 but true"> in Perl. This string is true
4760on improper numeric conversions.
5760in boolean context and C<0> in numeric context. It is also exempt from
5761the normal
5762L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s>
5763L<warnings> on improper numeric conversions.
47615764
47625765=end original
47635766
4764C<fcntl> からの返り値のチェックに C<defined> を使う必要はありません。
5767L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> からの返り値のチェックに
4765C<ioctl> と違って、C<fnctl> はシステムコールの結果が C<0> だった場合
5768L<C<defined>|/defined EXPR> を使う必要ありません。
4766C<"0 だが真">を返します。
5769L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と違って、これは
5770システムコールの結果が C<0> だった場合は C<"0 だが真"> を返します。
47675771この文字列は真偽値コンテキストでは真となり、
47685772数値コンテキストでは C<0> になります。
4769これはまた、不適切な数値変換に関する通常の B<-w> 警告を回避します。
5773これはまた、不適切な数値変換に関する通常の
5774L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s>
5775L<warnings> を回避します。
47705776
47715777=begin original
47725778
4773Note that C<fcntl> raises an exception if used on a machine that
5779Note that L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> raises an
4774doesn't implement fcntl(2). See the Fcntl module or your fcntl(2)
5780exception if used on a machine that doesn't implement L<fcntl(2)>. See
4775manpage to learn what functions are available on your system.
5781the L<Fcntl> module or your L<fcntl(2)> manpage to learn what functions
5782are available on your system.
47765783
47775784=end original
47785785
4779fcntl(2) が実装されていないマシンでは、C<fcntl>は例外を
5786L<fcntl(2)> が実装されていないマシンでは、
5787L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> は例外を
47805788引き起こすことに注意してください。
4781システムでどの関数が利用可能かについては Fcntl モジュールや
5789システムでどの関数が利用可能かについては L<Fcntl> モジュールや
4782fcntl(2) man ページを参照してください。
5790L<fcntl(2)> man ページを参照してください。
47835791
47845792=begin original
47855793
4786Here's an example of setting a filehandle named C<REMOTE> to be
5794Here's an example of setting a filehandle named C<$REMOTE> to be
4787non-blocking at the system level. You'll have to negotiate C<$|>
5795non-blocking at the system level. You'll have to negotiate
4788on your own, though.
5796L<C<$E<verbar>>|perlvar/$E<verbar>> on your own, though.
47895797
47905798=end original
47915799
4792これは C<REMOTE> というファイルハンドルをシステムレベルで
5800これは C<$REMOTE> というファイルハンドルをシステムレベルで
47935801非ブロックモードにセットする例です。
4794ただし、 C<$|> を自分で管理しなければなりません。
5802ただし、 L<C<$E<verbar>>|perlvar/$E<verbar>> を自分で管理しなければなりません。
47955803
47965804 use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
47975805
4798 $flags = fcntl(REMOTE, F_GETFL, 0)
5806 my $flags = fcntl($REMOTE, F_GETFL, 0)
4799 or die "Can't get flags for the socket: $!\n";
5807 or die "Can't get flags for the socket: $!\n";
48005808
4801 $flags = fcntl(REMOTE, F_SETFL, $flags | O_NONBLOCK)
5809 fcntl($REMOTE, F_SETFL, $flags | O_NONBLOCK)
4802 or die "Can't set flags for the socket: $!\n";
5810 or die "Can't set flags for the socket: $!\n";
48035811
48045812=begin original
48055813
48065814Portability issues: L<perlport/fcntl>.
48075815
48085816=end original
48095817
48105818移植性の問題: L<perlport/fcntl>。
48115819
48125820=item __FILE__
48135821X<__FILE__>
48145822
48155823=for Pod::Functions the name of the current source file
48165824
48175825=begin original
48185826
48195827A special token that returns the name of the file in which it occurs.
5828It can be altered by the mechanism described at
5829L<perlsyn/"Plain Old Comments (Not!)">.
48205830
48215831=end original
48225832
48235833これが書いてあるファイルの名前を返す特殊トークン。
5834L<perlsyn/"Plain Old Comments (Not!)"> で記述されている機構を使って
5835置き換えられます。
48245836
5837=item field VARNAME
5838X<field>
5839
5840=for Pod::Functions declare a field variable of the current class
5841
5842=begin original
5843
5844Declares a new field variable within the current class. Methods and
5845C<ADJUST> blocks of the class will have access to this variable as if it
5846was a lexical in scope at that point.
5847
5848=end original
5849
5850Declares a new field variable within the current class. Methods and
5851C<ADJUST> blocks of the class will have access to this variable as if it
5852was a lexical in scope at that point.
5853(TBT)
5854
48255855=item fileno FILEHANDLE
48265856X<fileno>
48275857
5858=item fileno DIRHANDLE
5859
48285860=for Pod::Functions return file descriptor from filehandle
48295861
48305862=begin original
48315863
4832Returns the file descriptor for a filehandle, or undefined if the
5864Returns the file descriptor for a filehandle or directory handle,
5865or undefined if the
48335866filehandle is not open. If there is no real file descriptor at the OS
48345867level, as can happen with filehandles connected to memory objects via
4835C<open> with a reference for the third argument, -1 is returned.
5868L<C<open>|/open FILEHANDLE,MODE,EXPR> with a reference for the third
5869argument, -1 is returned.
48365870
48375871=end original
48385872
4839ファイルハンドルに対するファイル記述子を返します; ファイルハンドルが
5873ファイルハンドルやディレクトリハンドルに対するファイル記述子を返します;
4840オープンしていない場合は未定義値を返します。
5874ファイルハンドルがオープンしていない場合は未定義値を返します。
4841OS レベルで実際のファイル記述子がない(C<open> の第 3 引数にリファレンスを
5875OS レベルで実際のファイル記述子がない(
5876L<C<open>|/open FILEHANDLE,MODE,EXPR> の第 3 引数にリファレンスを
48425877指定してファイルハンドルがメモリオブジェクトと結びつけられたときに
48435878起こります)場合、-1 が返されます。
48445879
48455880=begin original
48465881
4847This is mainly useful for constructing
5882This is mainly useful for constructing bitmaps for
4848bitmaps for C<select> and low-level POSIX tty-handling operations.
5883L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> and low-level POSIX
5884tty-handling operations.
48495885If FILEHANDLE is an expression, the value is taken as an indirect
48505886filehandle, generally its name.
48515887
48525888=end original
48535889
4854これは主に C<select> や低レベル POSIX tty 操作に対する、ビットマップを
5890これは主に L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> や低レベル
4855構成するときに便利です。
5891POSIX tty 操作に対する、ビットマップを構成するときに便利です。
48565892FILEHANDLE が式であれば、
48575893その値が間接ファイルハンドル(普通は名前)として使われます。
48585894
48595895=begin original
48605896
48615897You can use this to find out whether two handles refer to the
48625898same underlying descriptor:
48635899
48645900=end original
48655901
48665902これを、二つのハンドルが同じ識別子を参照しているかどうかを見つけるのに
48675903使えます:
48685904
4869 if (fileno(THIS) == fileno(THAT)) {
5905 if (fileno($this) != -1 && fileno($this) == fileno($that)) {
4870 print "THIS and THAT are dups\n";
5906 print "\$this and \$that are dups\n";
5907 } elsif (fileno($this) != -1 && fileno($that) != -1) {
5908 print "\$this and \$that have different " .
5909 "underlying file descriptors\n";
5910 } else {
5911 print "At least one of \$this and \$that does " .
5912 "not have a real file descriptor\n";
48715913 }
48725914
5915=begin original
5916
5917The behavior of L<C<fileno>|/fileno FILEHANDLE> on a directory handle
5918depends on the operating system. On a system with L<dirfd(3)> or
5919similar, L<C<fileno>|/fileno FILEHANDLE> on a directory
5920handle returns the underlying file descriptor associated with the
5921handle; on systems with no such support, it returns the undefined value,
5922and sets L<C<$!>|perlvar/$!> (errno).
5923
5924=end original
5925
5926ディレクトリハンドルに対する L<C<fileno>|/fileno FILEHANDLE> の振る舞いは
5927オペレーティングシステムに依存します。
5928L<dirfd(3)> のようなものがあるシステムでは、ディレクトリハンドルに対する
5929L<C<fileno>|/fileno FILEHANDLE> はハンドルに関連付けられた基となる
5930ファイル記述子を返します;
5931そのような対応がないシステムでは、未定義値を返し、
5932L<C<$!>|perlvar/$!> (errno) を設定します。
5933
48735934=item flock FILEHANDLE,OPERATION
48745935X<flock> X<lock> X<locking>
48755936
48765937=for Pod::Functions lock an entire file with an advisory lock
48775938
48785939=begin original
48795940
4880Calls flock(2), or an emulation of it, on FILEHANDLE. Returns true
5941Calls L<flock(2)>, or an emulation of it, on FILEHANDLE. Returns true
48815942for success, false on failure. Produces a fatal error if used on a
4882machine that doesn't implement flock(2), fcntl(2) locking, or lockf(3).
5943machine that doesn't implement L<flock(2)>, L<fcntl(2)> locking, or
4883C<flock> is Perl's portable file-locking interface, although it locks
5944L<lockf(3)>. L<C<flock>|/flock FILEHANDLE,OPERATION> is Perl's portable
4884entire files only, not records.
5945file-locking interface, although it locks entire files only, not
5946records.
48855947
48865948=end original
48875949
4888FILEHANDLE に対して flock(2)、またはそのエミュレーションを呼び出します。
5950FILEHANDLE に対して L<flock(2)>、またはそのエミュレーションを呼び出します。
48895951成功時には真を、失敗時には偽を返します。
4890flock(2), fcntl(2) ロック, lockf(3) のいずれかを実装していない
5952L<flock(2)>, L<fcntl(2)> ロック, L<lockf(3)> のいずれかを実装していない
48915953マシンで使うと、致命的エラーが発生します。
4892C<flock> は Perl の移植性のあるファイルロックインターフェースです;
5954L<C<flock>|/flock FILEHANDLE,OPERATION> は Perl の移植性のある
5955ファイルロックインターフェースです;
48935956しかしレコードではなく、ファイル全体のみをロックします。
48945957
48955958=begin original
48965959
4897Two potentially non-obvious but traditional C<flock> semantics are
5960Two potentially non-obvious but traditional L<C<flock>|/flock
5961FILEHANDLE,OPERATION> semantics are
48985962that it waits indefinitely until the lock is granted, and that its locks
48995963are B<merely advisory>. Such discretionary locks are more flexible, but
49005964offer fewer guarantees. This means that programs that do not also use
4901C<flock> may modify files locked with C<flock>. See L<perlport>,
5965L<C<flock>|/flock FILEHANDLE,OPERATION> may modify files locked with
5966L<C<flock>|/flock FILEHANDLE,OPERATION>. See L<perlport>,
49025967your port's specific documentation, and your system-specific local manpages
49035968for details. It's best to assume traditional behavior if you're writing
49045969portable programs. (But if you're not, you should as always feel perfectly
49055970free to write for your own system's idiosyncrasies (sometimes called
49065971"features"). Slavish adherence to portability concerns shouldn't get
49075972in the way of your getting your job done.)
49085973
49095974=end original
49105975
4911明白ではないものの、伝統的な C<flock> の動作としては、ロックが得られるまで
5976明白ではないものの、伝統的な L<C<flock>|/flock FILEHANDLE,OPERATION>
5977動作としては、ロックが得られるまで
49125978無限に待ち続けるものと、B<単に勧告的に> ロックするものの二つがあります。
49135979このような自由裁量のロックはより柔軟ですが、保障されるものはより少ないです。
4914これは、C<flock> を使わないプログラムが C<flock> でロックされたファイルを
5980これは、L<C<flock>|/flock FILEHANDLE,OPERATION> を使わないプログラムが
5981L<C<flock>|/flock FILEHANDLE,OPERATION> でロックされたファイルを
49155982書き換えるかもしれないことを意味します。
49165983詳細については、L<perlport>、システム固有のドキュメント、システム固有の
49175984ローカルの man ページを参照してください。
49185985移植性のあるプログラムを書く場合は、伝統的な振る舞いを仮定するのが
49195986ベストです。
49205987(しかし移植性のないプログラムを書く場合は、自身のシステムの性癖(しばしば
49215988「仕様」と呼ばれます)に合わせて書くことも完全に自由です。
49225989盲目的に移植性に固執することで、あなたの作業を仕上げるのを邪魔するべきでは
49235990ありません。)
49245991
49255992=begin original
49265993
49275994OPERATION is one of LOCK_SH, LOCK_EX, or LOCK_UN, possibly combined with
49285995LOCK_NB. These constants are traditionally valued 1, 2, 8 and 4, but
49295996you can use the symbolic names if you import them from the L<Fcntl> module,
49305997either individually, or as a group using the C<:flock> tag. LOCK_SH
49315998requests a shared lock, LOCK_EX requests an exclusive lock, and LOCK_UN
49325999releases a previously requested lock. If LOCK_NB is bitwise-or'ed with
4933LOCK_SH or LOCK_EX, then C<flock> returns immediately rather than blocking
6000LOCK_SH or LOCK_EX, then L<C<flock>|/flock FILEHANDLE,OPERATION> returns
4934waiting for the lock; check the return status to see if you got it.
6001immediately rather than blocking waiting for the lock; check the return
6002status to see if you got it.
49356003
49366004=end original
49376005
49386006OPERATION は LOCK_SH, LOCK_EX, LOCK_UN のいずれかで、LOCK_NB と
49396007組み合わされることもあります。
49406008これらの定数は伝統的には 1, 2, 8, 4 の値を持ちますが、L<Fcntl> モジュールから
49416009シンボル名を独立してインポートするか、C<:flock> タグを使うグループとして、
49426010シンボル名をを使うことができます。
49436011LOCK_SH は共有ロックを要求し、LOCK_EX は排他ロックを要求し、LOCK_UN は
49446012前回要求したロックを開放します。
4945LOCK_NB と LOCK_SH か LOCK_EX がビット単位の論理和されると、C<flock> は
6013LOCK_NB と LOCK_SH か LOCK_EX がビット単位の論理和されると、
6014L<C<flock>|/flock FILEHANDLE,OPERATION> は
49466015ロックを取得するまで待つのではなく、すぐに返ります;
49476016ロックが取得できたかどうかは返り値を調べます。
49486017
49496018=begin original
49506019
49516020To avoid the possibility of miscoordination, Perl now flushes FILEHANDLE
49526021before locking or unlocking it.
49536022
49546023=end original
49556024
49566025不一致の可能性を避けるために、Perl はファイルをロック、アンロックする前に
49576026FILEHANDLE をフラッシュします。
49586027
49596028=begin original
49606029
4961Note that the emulation built with lockf(3) doesn't provide shared
6030Note that the emulation built with L<lockf(3)> doesn't provide shared
49626031locks, and it requires that FILEHANDLE be open with write intent. These
4963are the semantics that lockf(3) implements. Most if not all systems
6032are the semantics that L<lockf(3)> implements. Most if not all systems
4964implement lockf(3) in terms of fcntl(2) locking, though, so the
6033implement L<lockf(3)> in terms of L<fcntl(2)> locking, though, so the
49656034differing semantics shouldn't bite too many people.
49666035
49676036=end original
49686037
4969lockf(3) で作成されたエミュレーションは共有ロックを提供せず、
6038L<lockf(3)> で作成されたエミュレーションは共有ロックを提供せず、
49706039FILEHANDLE が書き込みモードで開いていることを必要とすることに
49716040注意してください。
4972これは lockf(3) が実装している動作です。
6041これは L<lockf(3)> が実装している動作です。
4973しかし、全てではないにしてもほとんどのシステムでは fcntl(2) を使って
6042しかし、全てではないにしてもほとんどのシステムでは L<fcntl(2)> を使って
4974lockf(3) を実装しているので、異なった動作で多くの人々を混乱させることは
6043L<lockf(3)> を実装しているので、異なった動作で多くの人々を混乱させることは
49756044ないはずです。
49766045
49776046=begin original
49786047
4979Note that the fcntl(2) emulation of flock(3) requires that FILEHANDLE
6048Note that the L<fcntl(2)> emulation of L<flock(3)> requires that FILEHANDLE
49806049be open with read intent to use LOCK_SH and requires that it be open
49816050with write intent to use LOCK_EX.
49826051
49836052=end original
49846053
4985flock(3) の fcntl(2) エミュレーションは、 LOCK_SH を使うためには
6054L<flock(3)>L<fcntl(2)> エミュレーションは、 LOCK_SH を使うためには
49866055FILEHANDLE を読み込みで開いている必要があり、LOCK_EX を使うためには
49876056書き込みで開いている必要があることに注意してください。
49886057
49896058=begin original
49906059
4991Note also that some versions of C<flock> cannot lock things over the
6060Note also that some versions of L<C<flock>|/flock FILEHANDLE,OPERATION>
4992network; you would need to use the more system-specific C<fcntl> for
6061cannot lock things over the network; you would need to use the more
4993that. If you like you can force Perl to ignore your system's flock(2)
6062system-specific L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> for
4994function, and so provide its own fcntl(2)-based emulation, by passing
6063that. If you like you can force Perl to ignore your system's L<flock(2)>
6064function, and so provide its own L<fcntl(2)>-based emulation, by passing
49956065the switch C<-Ud_flock> to the F<Configure> program when you configure
49966066and build a new Perl.
49976067
49986068=end original
49996069
5000ネットワーク越しにはロックできない C<flock> もあることに注意してください;
6070ネットワーク越しにはロックできない L<C<flock>|/flock FILEHANDLE,OPERATION>
5001のためは、よりシステム依存な C<fcntl> を使う必要があります。
6071ある注意してください;
5002Perl にシステムの flock(2) 関数を無視させ、自身の fcntl(2) ベースの
6072このためは、よりシステム依存な
6073L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> を使う必要があります。
6074Perl にシステムの L<flock(2)> 関数を無視させ、自身の L<fcntl(2)> ベースの
50036075エミュレーションを使う場合は、新しい Perl を設定およびビルドするときに
50046076F<Configure> プログラムに C<-Ud_flock> オプションを渡してください。
50056077
50066078=begin original
50076079
50086080Here's a mailbox appender for BSD systems.
50096081
50106082=end original
50116083
50126084BSD システムでのメールボックスへの追加処理の例を示します。
50136085
50146086 # import LOCK_* and SEEK_END constants
50156087 use Fcntl qw(:flock SEEK_END);
50166088
50176089 sub lock {
50186090 my ($fh) = @_;
50196091 flock($fh, LOCK_EX) or die "Cannot lock mailbox - $!\n";
6092 # and, in case we're running on a very old UNIX
5021 # and, in case someone appended while we were waiting...
6093 # variant without the modern O_APPEND semantics...
50226094 seek($fh, 0, SEEK_END) or die "Cannot seek - $!\n";
50236095 }
50246096
50256097 sub unlock {
50266098 my ($fh) = @_;
50276099 flock($fh, LOCK_UN) or die "Cannot unlock mailbox - $!\n";
50286100 }
50296101
50306102 open(my $mbox, ">>", "/usr/spool/mail/$ENV{'USER'}")
50316103 or die "Can't open mailbox: $!";
50326104
50336105 lock($mbox);
50346106 print $mbox $msg,"\n\n";
50356107 unlock($mbox);
50366108
50376109=begin original
50386110
5039On systems that support a real flock(2), locks are inherited across fork()
6111On systems that support a real L<flock(2)>, locks are inherited across
5040calls, whereas those that must resort to the more capricious fcntl(2)
6112L<C<fork>|/fork> calls, whereas those that must resort to the more
5041function lose their locks, making it seriously harder to write servers.
6113capricious L<fcntl(2)> function lose their locks, making it seriously
6114harder to write servers.
50426115
50436116=end original
50446117
5045真の flock(2) に対応しているシステムではロックは fork() を通して
6118真の L<flock(2)> に対応しているシステムではロックは L<C<fork>|/fork> を通して
5046継承されるのに対して、より不安定な fcntl(2) に頼らなければならない場合、
6119継承されるのに対して、より不安定な L<fcntl(2)> に頼らなければならない場合、
50476120サーバを書くのは本当により難しくなります。
50486121
50496122=begin original
50506123
5051See also L<DB_File> for other flock() examples.
6124See also L<DB_File> for other L<C<flock>|/flock FILEHANDLE,OPERATION>
6125examples.
50526126
50536127=end original
50546128
5055その他の flock() の例としては L<DB_File> も参照してください。
6129その他の L<C<flock>|/flock FILEHANDLE,OPERATION> の例としては L<DB_File> も
6130参照してください。
50566131
50576132=begin original
50586133
50596134Portability issues: L<perlport/flock>.
50606135
50616136=end original
50626137
50636138移植性の問題: L<perlport/flock>。
50646139
50656140=item fork
50666141X<fork> X<child> X<parent>
50676142
50686143=for Pod::Functions create a new process just like this one
50696144
50706145=begin original
50716146
5072Does a fork(2) system call to create a new process running the
6147Does a L<fork(2)> system call to create a new process running the
50736148same program at the same point. It returns the child pid to the
5074parent process, C<0> to the child process, or C<undef> if the fork is
6149parent process, C<0> to the child process, or L<C<undef>|/undef EXPR> if
6150the fork is
50756151unsuccessful. File descriptors (and sometimes locks on those descriptors)
50766152are shared, while everything else is copied. On most systems supporting
5077fork(), great care has gone into making it extremely efficient (for
6153L<fork(2)>, great care has gone into making it extremely efficient (for
50786154example, using copy-on-write technology on data pages), making it the
50796155dominant paradigm for multitasking over the last few decades.
50806156
50816157=end original
50826158
50836159同じプログラムの同じ地点から開始する新しいプロセスを作成するために
5084システムコール fork(2) を行ないます。
6160システムコール L<fork(2)> を行ないます。
50856161親プロセスには、チャイルドプロセスの pid を、
50866162チャイルドプロセスに C<0> を返しますが、
5087fork に失敗したときには、C<undef>を返します。
6163fork に失敗したときには、L<C<undef>|/undef EXPR>を返します。
50886164ファイル記述子(および記述子に関連するロック)は共有され、
50896165その他の全てはコピーされます。
5090fork() に対応するほとんどのシステムでは、
6166L<fork(2)> に対応するほとんどのシステムでは、
50916167これを極めて効率的にするために多大な努力が払われてきました
50926168(例えば、データページへの copy-on-write テクノロジーなどです);
50936169これはここ 20 年にわたるマルチタスクに関する主要なパラダイムとなっています。
50946170
50956171=begin original
50966172
5097Perl attempts to flush all files opened for
6173Perl attempts to flush all files opened for output before forking the
5098output before forking the child process, but this may not be supported
6174child process, but this may not be supported on some platforms (see
5099on some platforms (see L<perlport>). To be safe, you may need to set
6175L<perlport>). To be safe, you may need to set
5100C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method of
6176L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>) or
5101C<IO::Handle> on any open handles to avoid duplicate output.
6177call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS> on
6178any open handles to avoid duplicate output.
51026179
51036180=end original
51046181
5105v5.6.0 から、Perl は子プロセスを fork する前に出力用にオープンしている全ての
6182Perl は子プロセスを fork する前に出力用にオープンしている全ての
51066183ファイルをフラッシュしようとしますが、これに対応していないプラットフォームも
51076184あります(L<perlport> を参照してください)。
51086185安全のためには、出力が重複するのを避けるために、
5109全てのオープンしているハンドルに対して C<$|> (English モジュールでは
6186全てのオープンしているハンドルに対して L<C<$E<verbar>>|perlvar/$E<verbar>>
5110$AUTOFLUSH) を設定するか、
6187(L<English> モジュールでは C<$AUTOFLUSH>) を設定するか、
5111C<IO::Handle> モジュールの C<autoflush()>メソッドをを呼ぶ必要が
6188L<C<IO::Handle>|IO::Handle/METHODS> モジュールの C<autoflush> メソッドを
5112あるかもしれません。
6189呼ぶ必要があるかもしれません。
51136190
51146191=begin original
51156192
5116If you C<fork> without ever waiting on your children, you will
6193If you L<C<fork>|/fork> without ever waiting on your children, you will
51176194accumulate zombies. On some systems, you can avoid this by setting
5118C<$SIG{CHLD}> to C<"IGNORE">. See also L<perlipc> for more examples of
6195L<C<$SIG{CHLD}>|perlvar/%SIG> to C<"IGNORE">. See also L<perlipc> for
5119forking and reaping moribund children.
6196more examples of forking and reaping moribund children.
51206197
51216198=end original
51226199
5123チャイルドプロセスの終了を待たずに、C<fork> を繰り返せば、
6200チャイルドプロセスの終了を待たずに、L<C<fork>|/fork> を繰り返せば、
51246201ゾンビをためこむことになります。
5125C<$SIG{CHLD}> に C<"IGNORE"> を指定することでこれを回避できるシステムもあります。
6202L<C<$SIG{CHLD}>|perlvar/%SIG> に C<"IGNORE"> を指定することでこれを
6203回避できるシステムもあります。
51266204fork と消滅しかけている子プロセスを回収するための更なる例については
51276205L<perlipc> も参照してください。
51286206
51296207=begin original
51306208
51316209Note that if your forked child inherits system file descriptors like
51326210STDIN and STDOUT that are actually connected by a pipe or socket, even
51336211if you exit, then the remote server (such as, say, a CGI script or a
51346212backgrounded job launched from a remote shell) won't think you're done.
51356213You should reopen those to F</dev/null> if it's any issue.
51366214
51376215=end original
51386216
51396217fork した子プロセスが STDIN や STDOUT といったシステムファイル記述子を
51406218継承する場合、(CGI スクリプトやリモートシェルといった
51416219バックグラウンドジョブのような)リモートサーバは考え通りに
51426220動かないであろうことに注意してください。
51436221このような場合ではこれらを F</dev/null> として再オープンするべきです。
51446222
51456223=begin original
51466224
5147On some platforms such as Windows, where the fork() system call is not available,
6225On some platforms such as Windows, where the L<fork(2)> system call is
5148Perl can be built to emulate fork() in the Perl interpreter.
6226not available, Perl can be built to emulate L<C<fork>|/fork> in the Perl
5149The emulation is designed, at the level of the Perl program,
6227interpreter. The emulation is designed, at the level of the Perl
5150to be as compatible as possible with the "Unix" fork().
6228program, to be as compatible as possible with the "Unix" L<fork(2)>.
5151However it has limitations that have to be considered in code intended to be portable.
6229However it has limitations that have to be considered in code intended
5152See L<perlfork> for more details.
6230to be portable. See L<perlfork> for more details.
51536231
51546232=end original
51556233
5156Windows のような fork() が利用不能なシステムでは、Perl は fork() を Perl
6234Windows のような L<fork(2)> が利用不能なシステムでは、Perl は
5157インタプリタでエミュレートします。
6235L<C<fork>|/fork> を Perl インタプリタでエミュレートします。
5158エミュレーションは Perl プログラムのレベルではできるだけ "Unix" fork() と
6236エミュレーションは Perl プログラムのレベルではできるだけ "Unix" L<fork(2)>
51596237互換性があるように設計されています。
51606238しかしコードが移植性があると考えられるように制限があります。
51616239さらなる詳細については L<perlfork> を参照してください。
51626240
51636241=begin original
51646242
51656243Portability issues: L<perlport/fork>.
51666244
51676245=end original
51686246
51696247移植性の問題: L<perlport/fork>。
51706248
51716249=item format
51726250X<format>
51736251
51746252=for Pod::Functions declare a picture format with use by the write() function
51756253
51766254=begin original
51776255
5178Declare a picture format for use by the C<write> function. For
6256Declare a picture format for use by the L<C<write>|/write FILEHANDLE>
5179example:
6257function. For example:
51806258
51816259=end original
51826260
5183C<write> 関数で使うピクチャーフォーマットを宣言します。
6261L<C<write>|/write FILEHANDLE> 関数で使うピクチャーフォーマットを宣言します。
51846262例えば:
51856263
51866264 format Something =
51876265 Test: @<<<<<<<< @||||| @>>>>>
51886266 $str, $%, '$' . int($num)
51896267 .
51906268
51916269 $str = "widget";
51926270 $num = $cost/$quantity;
51936271 $~ = 'Something';
51946272 write;
51956273
51966274=begin original
51976275
51986276See L<perlform> for many details and examples.
51996277
52006278=end original
52016279
52026280詳細と例については L<perlform> を参照してください。
52036281
52046282=item formline PICTURE,LIST
52056283X<formline>
52066284
52076285=for Pod::Functions internal function used for formats
52086286
52096287=begin original
52106288
5211This is an internal function used by C<format>s, though you may call it,
6289This is an internal function used by L<C<format>|/format>s, though you
5212too. It formats (see L<perlform>) a list of values according to the
6290may call it, too. It formats (see L<perlform>) a list of values
5213contents of PICTURE, placing the output into the format output
6291according to the contents of PICTURE, placing the output into the format
5214accumulator, C<$^A> (or C<$ACCUMULATOR> in English).
6292output accumulator, L<C<$^A>|perlvar/$^A> (or C<$ACCUMULATOR> in
5215Eventually, when a C<write> is done, the contents of
6293L<English>). Eventually, when a L<C<write>|/write FILEHANDLE> is done,
5216C<$^A> are written to some filehandle. You could also read C<$^A>
6294the contents of L<C<$^A>|perlvar/$^A> are written to some filehandle.
5217and then set C<$^A> back to C<"">. Note that a format typically
6295You could also read L<C<$^A>|perlvar/$^A> and then set
5218does one C<formline> per line of form, but the C<formline> function itself
6296L<C<$^A>|perlvar/$^A> back to C<"">. Note that a format typically does
5219doesn't care how many newlines are embedded in the PICTURE. This means
6297one L<C<formline>|/formline PICTURE,LIST> per line of form, but the
5220that the C<~> and C<~~> tokens treat the entire PICTURE as a single line.
6298L<C<formline>|/formline PICTURE,LIST> function itself doesn't care how
5221You may therefore need to use multiple formlines to implement a single
6299many newlines are embedded in the PICTURE. This means that the C<~> and
5222record format, just like the C<format> compiler.
6300C<~~> tokens treat the entire PICTURE as a single line. You may
6301therefore need to use multiple formlines to implement a single record
6302format, just like the L<C<format>|/format> compiler.
52236303
52246304=end original
52256305
5226これは、C<format> が使用する内部関数ですが、直接呼び出すこともできます。
6306これは、L<C<format>|/format> が使用する内部関数ですが、直接呼び出すことも
6307できます。
52276308これは、PICTURE の内容にしたがって、LIST の値を整形し (L<perlform> を
5228参照してください)、結果をフォーマット出力アキュムレータC<$^A>
6309参照してください)、結果をフォーマット出力アキュムレータL<C<$^A>|perlvar/$^A>
5229(English モジュールでは C<$ACCUMULATOR>) に納めます。
6310(L<English> モジュールでは C<$ACCUMULATOR>) に納めます。
5230最終的に、C<write> が実行されると、C<$^A> の中身が
6311最終的に、L<C<write>|/write FILEHANDLE> が実行されると、
5231何らかのファイルハンドルに書き出されます。
6312L<C<$^A>|perlvar/$^A> の中身が、何らかのファイルハンドルに書き出されます。
5232また、自分で C<$^A> を読んで、C<$^A> の内容を C<""> に戻してもかまいません。
6313また、自分で L<C<$^A>|perlvar/$^A> を読んで、L<C<$^A>|perlvar/$^A> の内容を
5233format は通常、1 行ごとに C<formline> を行ないますが、
6314C<""> に戻してもかまいません。
5234C<formline> 関数自身は、PICTURE の中にいくつの改行が入っているかは、
6315format は通常、1 行ごとに L<C<formline>|/formline PICTURE,LIST>
5235関係がありせん。
6316行ないすが、L<C<formline>|/formline PICTURE,LIST> 関数自身は、PICTURE の中に
6317いくつの改行が入っているかは、関係がありません。
52366318これは、C<~> と C<~~>トークンは PICTURE 全体を一行として扱うことを意味します。
52376319従って、1 レコードフォーマットを実装するためには
5238フォーマットコンパイラのような複数 formline を使う必要があります。
6320L<C<format>|/format> コンパイラのような複数 formline を使う必要があります。
52396321
52406322=begin original
52416323
52426324Be careful if you put double quotes around the picture, because an C<@>
52436325character may be taken to mean the beginning of an array name.
5244C<formline> always returns true. See L<perlform> for other examples.
6326L<C<formline>|/formline PICTURE,LIST> always returns true. See
6327L<perlform> for other examples.
52456328
52466329=end original
52476330
52486331ダブルクォートで PICTURE を囲む場合には、C<@> という文字が
52496332配列名の始まりと解釈されますので、注意してください。
5250C<formline> は常に真を返します。
6333L<C<formline>|/formline PICTURE,LIST> は常に真を返します。
52516334その他の例については L<perlform> を参照してください。
52526335
52536336=begin original
52546337
5255If you are trying to use this instead of C<write> to capture the output,
6338If you are trying to use this instead of L<C<write>|/write FILEHANDLE>
5256you may find it easier to open a filehandle to a scalar
6339to capture the output, you may find it easier to open a filehandle to a
5257(C<< open $fh, ">", \$output >>) and write to that instead.
6340scalar (C<< open my $fh, ">", \$output >>) and write to that instead.
52586341
52596342=end original
52606343
5261出力を捕捉するために C<write> の代わりにこれを使おうとした場合、
6344出力を捕捉するために L<C<write>|/write FILEHANDLE> の代わりにこれを
5262スカラにファイルハンドルを開いて (C<< open $fh, ">", \$output >>)、
6345使おうとした場合、スカラにファイルハンドルを開いて
6346(C<< open my $fh, ">", \$output >>)、
52636347代わりにここに出力する方が簡単であることに気付くでしょう。
52646348
52656349=item getc FILEHANDLE
52666350X<getc> X<getchar> X<character> X<file, read>
52676351
52686352=item getc
52696353
52706354=for Pod::Functions get the next character from the filehandle
52716355
52726356=begin original
52736357
52746358Returns the next character from the input file attached to FILEHANDLE,
52756359or the undefined value at end of file or if there was an error (in
5276the latter case C<$!> is set). If FILEHANDLE is omitted, reads from
6360the latter case L<C<$!>|perlvar/$!> is set). If FILEHANDLE is omitted,
6361reads from
52776362STDIN. This is not particularly efficient. However, it cannot be
52786363used by itself to fetch single characters without waiting for the user
52796364to hit enter. For that, try something more like:
52806365
52816366=end original
52826367
52836368FILEHANDLE につながれている入力ファイルから、次の一文字を返します;
52846369ファイルの最後、またはエラーが発生した場合は、未定義値を返します
5285(後者の場合は C<$!> がセットされます)。
6370(後者の場合は L<C<$!>|perlvar/$!> がセットされます)。
52866371FILEHANDLE が省略された場合には、STDIN から読み込みを行ないます。
52876372これは特に効率的ではありません。
52886373しかし、これはユーザーがリターンキーを押すのを待つことなく
52896374一文字を読み込む用途には使えません。
52906375そのような場合には、以下のようなものを試して見てください:
52916376
52926377 if ($BSD_STYLE) {
52936378 system "stty cbreak </dev/tty >/dev/tty 2>&1";
52946379 }
52956380 else {
52966381 system "stty", '-icanon', 'eol', "\001";
52976382 }
52986383
5299 $key = getc(STDIN);
6384 my $key = getc(STDIN);
53006385
53016386 if ($BSD_STYLE) {
53026387 system "stty -cbreak </dev/tty >/dev/tty 2>&1";
53036388 }
53046389 else {
53056390 system 'stty', 'icanon', 'eol', '^@'; # ASCII NUL
53066391 }
53076392 print "\n";
53086393
53096394=begin original
53106395
5311Determination of whether $BSD_STYLE should be set
6396Determination of whether C<$BSD_STYLE> should be set is left as an
5312is left as an exercise to the reader.
6397exercise to the reader.
53136398
53146399=end original
53156400
5316$BSD_STYLE をセットするべきかどうかを決定する方法については
6401C<$BSD_STYLE> をセットするべきかどうかを決定する方法については
53176402読者への宿題として残しておきます。
53186403
53196404=begin original
53206405
5321The C<POSIX::getattr> function can do this more portably on
6406The L<C<POSIX::getattr>|POSIX/C<getattr>> function can do this more
5322systems purporting POSIX compliance. See also the C<Term::ReadKey>
6407portably on systems purporting POSIX compliance. See also the
5323module from your nearest CPAN site; details on CPAN can be found under
6408L<C<Term::ReadKey>|Term::ReadKey> module on CPAN.
5324L<perlmodlib/CPAN>.
53256409
53266410=end original
53276411
5328C<POSIX::getattr> 関数は POSIX 準拠を主張するシステムでこれを
6412L<C<POSIX::getattr>|POSIX/C<getattr>> 関数は POSIX 準拠を主張するシステムで
5329より移植性のある形で行います。
6413これをより移植性のある形で行います。
5330お近くの CPAN サイトから C<Term::ReadKey> モジュールも参照してください;
6414CPAN にある L<C<Term::ReadKey>|Term::ReadKey> モジュールも
5331CPAN に関する詳細は L<perlmodlib/CPAN> にあります
6415参照してください
53326416
53336417=item getlogin
53346418X<getlogin> X<login>
53356419
53366420=for Pod::Functions return who logged in at this tty
53376421
53386422=begin original
53396423
53406424This implements the C library function of the same name, which on most
53416425systems returns the current login from F</etc/utmp>, if any. If it
5342returns the empty string, use C<getpwuid>.
6426returns the empty string, use L<C<getpwuid>|/getpwuid UID>.
53436427
53446428=end original
53456429
53466430これは同じ名前の C ライブラリ関数を実装していて、
5347多くのシステムでは、もしあれば、/etc/utmp から現在のログイン名を返します。
6431多くのシステムでは、もしあれば、F</etc/utmp> から現在のログイン名を返します。
5348もし空文字列が返ってきた場合は、getpwuid()使ってください。
6432もし空文字列が返ってきた場合は、L<C<getpwuid>|/getpwuid UID>
6433使ってください。
53496434
5350 $login = getlogin || getpwuid($<) || "Kilroy";
6435 my $login = getlogin || getpwuid($<) || "Kilroy";
53516436
53526437=begin original
53536438
5354Do not consider C<getlogin> for authentication: it is not as
6439Do not consider L<C<getlogin>|/getlogin> for authentication: it is not
5355secure as C<getpwuid>.
6440as secure as L<C<getpwuid>|/getpwuid UID>.
53566441
53576442=end original
53586443
5359C<getlogin> を認証に使ってはいけません: これは C<getpwuid> のように
6444L<C<getlogin>|/getlogin> を認証に使ってはいけません: これは
5360安全ではありません。
6445L<C<getpwuid>|/getpwuid UID> のように安全ではありません。
53616446
53626447=begin original
53636448
53646449Portability issues: L<perlport/getlogin>.
53656450
53666451=end original
53676452
53686453移植性の問題: L<perlport/getlogin>。
53696454
53706455=item getpeername SOCKET
53716456X<getpeername> X<peer>
53726457
53736458=for Pod::Functions find the other end of a socket connection
53746459
53756460=begin original
53766461
53776462Returns the packed sockaddr address of the other end of the SOCKET
53786463connection.
53796464
53806465=end original
53816466
53826467SOCKET コネクションの向こう側のパックされた aockaddr アドレスを返します。
53836468
53846469 use Socket;
5385 $hersockaddr = getpeername(SOCK);
6470 my $hersockaddr = getpeername($sock);
5386 ($port, $iaddr) = sockaddr_in($hersockaddr);
6471 my ($port, $iaddr) = sockaddr_in($hersockaddr);
5387 $herhostname = gethostbyaddr($iaddr, AF_INET);
6472 my $herhostname = gethostbyaddr($iaddr, AF_INET);
5388 $herstraddr = inet_ntoa($iaddr);
6473 my $herstraddr = inet_ntoa($iaddr);
53896474
53906475=item getpgrp PID
53916476X<getpgrp> X<group>
53926477
53936478=for Pod::Functions get process group
53946479
53956480=begin original
53966481
53976482Returns the current process group for the specified PID. Use
53986483a PID of C<0> to get the current process group for the
53996484current process. Will raise an exception if used on a machine that
5400doesn't implement getpgrp(2). If PID is omitted, returns the process
6485doesn't implement L<getpgrp(2)>. If PID is omitted, returns the process
5401group of the current process. Note that the POSIX version of C<getpgrp>
6486group of the current process. Note that the POSIX version of
5402does not accept a PID argument, so only C<PID==0> is truly portable.
6487L<C<getpgrp>|/getpgrp PID> does not accept a PID argument, so only
6488C<PID==0> is truly portable.
54036489
54046490=end original
54056491
54066492指定された PID の現在のプロセスグループを返します。
54076493PID に C<0> を与えるとカレントプロセスの指定となります。
5408getpgrp(2) を実装していないマシンで実行した場合には、例外が発生します。
6494L<getpgrp(2)> を実装していないマシンで実行した場合には、例外が発生します。
54096495PID を省略するとカレントプロセスのプロセスグループを返します。
5410POSIX 版の C<getpgrp> は PID 引数を受け付けないので、
6496POSIX 版の L<C<getpgrp>|/getpgrp PID> は PID 引数を受け付けないので、
54116497C<PID==0> のみが完全に移植性があります。
54126498
54136499=begin original
54146500
54156501Portability issues: L<perlport/getpgrp>.
54166502
54176503=end original
54186504
54196505移植性の問題: L<perlport/getpgrp>。
54206506
54216507=item getppid
54226508X<getppid> X<parent> X<pid>
54236509
54246510=for Pod::Functions get parent process ID
54256511
54266512=begin original
54276513
54286514Returns the process id of the parent process.
54296515
54306516=end original
54316517
54326518親プロセスのプロセス id を返します。
54336519
54346520=begin original
54356521
54366522Note for Linux users: Between v5.8.1 and v5.16.0 Perl would work
54376523around non-POSIX thread semantics the minority of Linux systems (and
54386524Debian GNU/kFreeBSD systems) that used LinuxThreads, this emulation
5439has since been removed. See the documentation for L<$$|perlvar/$$> for
6525has since been removed. See the documentation for L<$$|perlvar/$$> for
54406526details.
54416527
54426528=end original
54436529
54446530Linux ユーザーへの注意: v5.8.1 から v5.16.0 の間 Perl は
54456531LinuxThreads という非 POSIX なスレッド文法を使っているマイナーな
54466532Linux システム (および Debian GNU/kFreeBSD システム) に対応していました。
54476533このエミュレーションは削除されました;
54486534詳しくは L<$$|perlvar/$$> の文書を参照してください。
54496535
54506536=begin original
54516537
54526538Portability issues: L<perlport/getppid>.
54536539
54546540=end original
54556541
54566542移植性の問題: L<perlport/getppid>。
54576543
54586544=item getpriority WHICH,WHO
54596545X<getpriority> X<priority> X<nice>
54606546
54616547=for Pod::Functions get current nice value
54626548
54636549=begin original
54646550
54656551Returns the current priority for a process, a process group, or a user.
54666552(See L<getpriority(2)>.) Will raise a fatal exception if used on a
5467machine that doesn't implement getpriority(2).
6553machine that doesn't implement L<getpriority(2)>.
54686554
54696555=end original
54706556
54716557プロセス、プロセスグループ、ユーザに対する現在の優先度を返します。
54726558(L<getpriority(2)> を参照してください。)
5473getpriority(2) を実装していない
6559L<getpriority(2)> を実装していない
54746560マシンで実行した場合には、致命的例外が発生します。
54756561
54766562=begin original
54776563
6564C<WHICH> can be any of C<PRIO_PROCESS>, C<PRIO_PGRP> or C<PRIO_USER>
6565imported from L<POSIX/RESOURCE CONSTANTS>.
6566
6567=end original
6568
6569C<WHICH> は、L<POSIX/RESOURCE CONSTANTS> からインポートされた
6570C<PRIO_PROCESS>, C<PRIO_PGRP>, C<PRIO_USER> のいずれかです。
6571
6572=begin original
6573
54786574Portability issues: L<perlport/getpriority>.
54796575
54806576=end original
54816577
54826578移植性の問題: L<perlport/getpriority>。
54836579
54846580=item getpwnam NAME
54856581X<getpwnam> X<getgrnam> X<gethostbyname> X<getnetbyname> X<getprotobyname>
54866582X<getpwuid> X<getgrgid> X<getservbyname> X<gethostbyaddr> X<getnetbyaddr>
54876583X<getprotobynumber> X<getservbyport> X<getpwent> X<getgrent> X<gethostent>
54886584X<getnetent> X<getprotoent> X<getservent> X<setpwent> X<setgrent> X<sethostent>
54896585X<setnetent> X<setprotoent> X<setservent> X<endpwent> X<endgrent> X<endhostent>
5490X<endnetent> X<endprotoent> X<endservent>
6586X<endnetent> X<endprotoent> X<endservent>
54916587
54926588=for Pod::Functions get passwd record given user login name
54936589
54946590=item getgrnam NAME
54956591
54966592=for Pod::Functions get group record given group name
54976593
54986594=item gethostbyname NAME
54996595
55006596=for Pod::Functions get host record given name
55016597
55026598=item getnetbyname NAME
55036599
55046600=for Pod::Functions get networks record given name
55056601
55066602=item getprotobyname NAME
55076603
55086604=for Pod::Functions get protocol record given name
55096605
55106606=item getpwuid UID
55116607
55126608=for Pod::Functions get passwd record given user ID
55136609
55146610=item getgrgid GID
55156611
55166612=for Pod::Functions get group record given group user ID
55176613
55186614=item getservbyname NAME,PROTO
55196615
55206616=for Pod::Functions get services record given its name
55216617
55226618=item gethostbyaddr ADDR,ADDRTYPE
55236619
55246620=for Pod::Functions get host record given its address
55256621
55266622=item getnetbyaddr ADDR,ADDRTYPE
55276623
55286624=for Pod::Functions get network record given its address
55296625
55306626=item getprotobynumber NUMBER
55316627
55326628=for Pod::Functions get protocol record numeric protocol
55336629
55346630=item getservbyport PORT,PROTO
55356631
55366632=for Pod::Functions get services record given numeric port
55376633
55386634=item getpwent
55396635
55406636=for Pod::Functions get next passwd record
55416637
55426638=item getgrent
55436639
55446640=for Pod::Functions get next group record
55456641
55466642=item gethostent
55476643
55486644=for Pod::Functions get next hosts record
55496645
55506646=item getnetent
55516647
55526648=for Pod::Functions get next networks record
55536649
55546650=item getprotoent
55556651
55566652=for Pod::Functions get next protocols record
55576653
55586654=item getservent
55596655
55606656=for Pod::Functions get next services record
55616657
55626658=item setpwent
55636659
55646660=for Pod::Functions prepare passwd file for use
55656661
55666662=item setgrent
55676663
55686664=for Pod::Functions prepare group file for use
55696665
55706666=item sethostent STAYOPEN
55716667
55726668=for Pod::Functions prepare hosts file for use
55736669
55746670=item setnetent STAYOPEN
55756671
55766672=for Pod::Functions prepare networks file for use
55776673
55786674=item setprotoent STAYOPEN
55796675
55806676=for Pod::Functions prepare protocols file for use
55816677
55826678=item setservent STAYOPEN
55836679
55846680=for Pod::Functions prepare services file for use
55856681
55866682=item endpwent
55876683
55886684=for Pod::Functions be done using passwd file
55896685
55906686=item endgrent
55916687
55926688=for Pod::Functions be done using group file
55936689
55946690=item endhostent
55956691
55966692=for Pod::Functions be done using hosts file
55976693
55986694=item endnetent
55996695
56006696=for Pod::Functions be done using networks file
56016697
56026698=item endprotoent
56036699
56046700=for Pod::Functions be done using protocols file
56056701
56066702=item endservent
56076703
56086704=for Pod::Functions be done using services file
56096705
56106706=begin original
56116707
56126708These routines are the same as their counterparts in the
56136709system C library. In list context, the return values from the
56146710various get routines are as follows:
56156711
56166712=end original
56176713
56186714これらのルーチンは、システムの C ライブラリの同名の関数と同じです。
56196715リストコンテキストでは、さまざまな
56206716get ルーチンからの返り値は、次のようになります:
56216717
5622 ($name,$passwd,$uid,$gid,
6718 # 0 1 2 3 4
5623 $quota,$comment,$gcos,$dir,$shell,$expire) = getpw*
6719 my ( $name, $passwd, $gid, $members ) = getgr*
5624 ($name,$passwd,$gid,$members) = getgr*
6720 my ( $name, $aliases, $addrtype, $net ) = getnet*
5625 ($name,$aliases,$addrtype,$length,@addrs) = gethost*
6721 my ( $name, $aliases, $port, $proto ) = getserv*
5626 ($name,$aliases,$addrtype,$net) = getnet*
6722 my ( $name, $aliases, $proto ) = getproto*
5627 ($name,$aliases,$proto) = getproto*
6723 my ( $name, $aliases, $addrtype, $length, @addrs ) = gethost*
5628 ($name,$aliases,$port,$proto) = getserv*
6724 my ( $name, $passwd, $uid, $gid, $quota,
6725 $comment, $gcos, $dir, $shell, $expire ) = getpw*
6726 # 5 6 7 8 9
56296727
56306728=begin original
56316729
5632(If the entry doesn't exist you get an empty list.)
6730(If the entry doesn't exist, the return value is a single meaningless true
6731value.)
56336732
56346733=end original
56356734
5636(エントリが存在しなければ、空リストがされます。)
6735(エントリが存在しなければ、返り値は単一の意味のない真の値です。)
56376736
56386737=begin original
56396738
56406739The exact meaning of the $gcos field varies but it usually contains
56416740the real name of the user (as opposed to the login name) and other
56426741information pertaining to the user. Beware, however, that in many
56436742system users are able to change this information and therefore it
56446743cannot be trusted and therefore the $gcos is tainted (see
56456744L<perlsec>). The $passwd and $shell, user's encrypted password and
56466745login shell, are also tainted, for the same reason.
56476746
56486747=end original
56496748
56506749$gcos フィールドの正確な意味はさまざまですが、通常は(ログイン名ではなく)
56516750ユーザーの実際の名前とユーザーに付随する情報を含みます。
56526751但し、多くのシステムではユーザーがこの情報を変更できるので、この情報は
56536752信頼できず、従って $gcos は汚染されます(L<perlsec> を参照してください)。
56546753ユーザーの暗号化されたパスワードとログインシェルである $passwd と
56556754$shell も、同様の理由で汚染されます。
56566755
56576756=begin original
56586757
56596758In scalar context, you get the name, unless the function was a
56606759lookup by name, in which case you get the other thing, whatever it is.
56616760(If the entry doesn't exist you get the undefined value.) For example:
56626761
56636762=end original
56646763
56656764スカラコンテキストでは、*nam、*byname といった NAME で検索するもの以外は、
56666765name を返し、NAME で検索するものは、何か別のものを返します。
56676766(エントリが存在しなければ、未定義値が返ります。)
56686767例えば:
56696768
5670 $uid = getpwnam($name);
6769 my $uid = getpwnam($name);
5671 $name = getpwuid($num);
6770 my $name = getpwuid($num);
5672 $name = getpwent();
6771 my $name = getpwent();
5673 $gid = getgrnam($name);
6772 my $gid = getgrnam($name);
5674 $name = getgrgid($num);
6773 my $name = getgrgid($num);
5675 $name = getgrent();
6774 my $name = getgrent();
5676 #etc.
6775 <#ins> etc.
56776776
56786777=begin original
56796778
56806779In I<getpw*()> the fields $quota, $comment, and $expire are special
56816780in that they are unsupported on many systems. If the
56826781$quota is unsupported, it is an empty scalar. If it is supported, it
56836782usually encodes the disk quota. If the $comment field is unsupported,
56846783it is an empty scalar. If it is supported it usually encodes some
56856784administrative comment about the user. In some systems the $quota
56866785field may be $change or $age, fields that have to do with password
56876786aging. In some systems the $comment field may be $class. The $expire
56886787field, if present, encodes the expiration period of the account or the
56896788password. For the availability and the exact meaning of these fields
5690in your system, please consult getpwnam(3) and your system's
6789in your system, please consult L<getpwnam(3)> and your system's
56916790F<pwd.h> file. You can also find out from within Perl what your
56926791$quota and $comment fields mean and whether you have the $expire field
5693by using the C<Config> module and the values C<d_pwquota>, C<d_pwage>,
6792by using the L<C<Config>|Config> module and the values C<d_pwquota>, C<d_pwage>,
56946793C<d_pwchange>, C<d_pwcomment>, and C<d_pwexpire>. Shadow password
56956794files are supported only if your vendor has implemented them in the
56966795intuitive fashion that calling the regular C library routines gets the
56976796shadow versions if you're running under privilege or if there exists
5698the shadow(3) functions as found in System V (this includes Solaris
6797the L<shadow(3)> functions as found in System V (this includes Solaris
56996798and Linux). Those systems that implement a proprietary shadow password
57006799facility are unlikely to be supported.
57016800
57026801=end original
57036802
57046803I<getpw*()> では、$quota, $comment, $expire フィールドは、
57056804多くのシステムでは対応していないので特別な処理がされます。
57066805$quota が非対応の場合、空のスカラになります。
57076806対応している場合、通常はディスククォータの値が入ります。
57086807$comment フィールドが非対応の場合、空のスカラになります。
57096808対応している場合、通常はユーザーに関する管理上のコメントが入ります。
57106809$quota フィールドはパスワードの寿命を示す $change や $age である
57116810システムもあります。
57126811$comment フィールドは $class であるシステムもあります。
57136812$expire フィールドがある場合は、アカウントやパスワードが時間切れになる
57146813期間が入ります。
57156814動作させるシステムでのこれらのフィールドの有効性と正確な意味については、
5716getpwnam(3) のドキュメントと F<pwd.h> ファイルを参照してください。
6815L<getpwnam(3)> のドキュメントと F<pwd.h> ファイルを参照してください。
57176816$quota と $comment フィールドが何を意味しているかと、$expire フィールドが
5718あるかどうかは、C<Config> モジュールを使って、C<d_pwquota>, C<d_pwage>,
6817あるかどうかは、L<C<Config>|Config> モジュールを使って、C<d_pwquota>,
5719C<d_pwchange>, C<d_pwcomment>, C<d_pwexpire> の値を調べることによって
6818C<d_pwage>, C<d_pwchange>, C<d_pwcomment>, C<d_pwexpire> の値を
5720Perl 自身で調べることも出来ます。
6819調べることによって Perl 自身で調べることも出来ます。
57216820シャドウパスワードは、通常の C ライブラリルーチンを権限がある状態で
57226821呼び出すことでシャドウ版が取得できるか、System V にあるような
5723(Solaris と Linux を含みます) shadow(3) 関数があるといった、
6822(Solaris と Linux を含みます) L<shadow(3)> 関数があるといった、
57246823直感的な方法で実装されている場合にのみ対応されます。
57256824独占的なシャドウパスワード機能を実装しているシステムでは、
57266825それに対応されることはないでしょう。
57276826
57286827=begin original
57296828
57306829The $members value returned by I<getgr*()> is a space-separated list of
57316830the login names of the members of the group.
57326831
57336832=end original
57346833
57356834I<getgr*()> によって返る値 $members は、グループのメンバの
57366835ログイン名をスペースで区切ったものです。
57376836
57386837=begin original
57396838
57406839For the I<gethost*()> functions, if the C<h_errno> variable is supported in
5741C, it will be returned to you via C<$?> if the function call fails. The
6840C, it will be returned to you via L<C<$?>|perlvar/$?> if the function
6841call fails. The
57426842C<@addrs> value returned by a successful call is a list of raw
57436843addresses returned by the corresponding library call. In the
57446844Internet domain, each address is four bytes long; you can unpack it
57456845by saying something like:
57466846
57476847=end original
57486848
57496849I<gethost*()> 関数では、C で C<h_errno> 変数がサポートされていれば、
5750関数呼出が失敗したときに、C<$?> を通して、その値が返されます。
6850関数呼出が失敗したときに、L<C<$?>|perlvar/$?> を通して、その値が返されます。
57516851成功時に返される C<@addrs> 値は、対応するシステムコールが返す、
57526852生のアドレスのリストです。
57536853インターネットドメインでは、個々のアドレスは、4 バイト長です;
57546854以下のようにして unpack することができます:
57556855
5756 ($a,$b,$c,$d) = unpack('W4',$addr[0]);
6856 my ($w,$x,$y,$z) = unpack('W4',$addr[0]);
57576857
57586858=begin original
57596859
57606860The Socket library makes this slightly easier:
57616861
57626862=end original
57636863
57646864Socket ライブラリを使うともう少し簡単になります。
57656865
57666866 use Socket;
5767 $iaddr = inet_aton("127.1"); # or whatever address
6867 my $iaddr = inet_aton("127.1"); # or whatever address
5768 $name = gethostbyaddr($iaddr, AF_INET);
6868 my $name = gethostbyaddr($iaddr, AF_INET);
57696869
57706870 # or going the other way
5771 $straddr = inet_ntoa($iaddr);
6871 my $straddr = inet_ntoa($iaddr);
57726872
57736873=begin original
57746874
57756875In the opposite way, to resolve a hostname to the IP address
57766876you can write this:
57776877
57786878=end original
57796879
57806880逆方向に、ホスト名から IP アドレスを解決するには以下のように書けます:
57816881
57826882 use Socket;
5783 $packed_ip = gethostbyname("www.perl.org");
6883 my $packed_ip = gethostbyname("www.perl.org");
6884 my $ip_address;
57846885 if (defined $packed_ip) {
57856886 $ip_address = inet_ntoa($packed_ip);
57866887 }
57876888
57886889=begin original
57896890
5790Make sure C<gethostbyname()> is called in SCALAR context and that
6891Make sure L<C<gethostbyname>|/gethostbyname NAME> is called in SCALAR
5791its return value is checked for definedness.
6892context and that its return value is checked for definedness.
57926893
57936894=end original
57946895
5795C<gethostbyname()> はスカラコンテキストで呼び出すようにして、返り値が
6896L<C<gethostbyname>|/gethostbyname NAME> はスカラコンテキストで
5796定義されているかを必ずチェックしてください。
6897呼び出すようにして、返り値が定義されているかを必ずチェックしてください。
57976898
57986899=begin original
57996900
5800The C<getprotobynumber> function, even though it only takes one argument,
6901The L<C<getprotobynumber>|/getprotobynumber NUMBER> function, even
5801has the precedence of a list operator, so beware:
6902though it only takes one argument, has the precedence of a list
6903operator, so beware:
58026904
58036905=end original
58046906
5805C<getprotobynumber> 関数は、一つの引数しか取らないにも関わらず、リスト
6907L<C<getprotobynumber>|/getprotobynumber NUMBER> 関数は、一つの引数しか
5806演算子の優先順位を持ちます; 従って注意してください:
6908取らないにも関わらず、リスト演算子の優先順位を持ちます; 従って
6909注意してください:
58076910
58086911 getprotobynumber $number eq 'icmp' # WRONG
58096912 getprotobynumber($number eq 'icmp') # actually means this
58106913 getprotobynumber($number) eq 'icmp' # better this way
58116914
58126915=begin original
58136916
58146917If you get tired of remembering which element of the return list
5815contains which return value, by-name interfaces are provided
6918contains which return value, by-name interfaces are provided in standard
5816in standard modules: C<File::stat>, C<Net::hostent>, C<Net::netent>,
6919modules: L<C<File::stat>|File::stat>, L<C<Net::hostent>|Net::hostent>,
5817C<Net::protoent>, C<Net::servent>, C<Time::gmtime>, C<Time::localtime>,
6920L<C<Net::netent>|Net::netent>, L<C<Net::protoent>|Net::protoent>,
5818and C<User::grent>. These override the normal built-ins, supplying
6921L<C<Net::servent>|Net::servent>, L<C<Time::gmtime>|Time::gmtime>,
5819versions that return objects with the appropriate names
6922L<C<Time::localtime>|Time::localtime>, and
5820for each field. For example:
6923L<C<User::grent>|User::grent>. These override the normal built-ins,
6924supplying versions that return objects with the appropriate names for
6925each field. For example:
58216926
58226927=end original
58236928
58246929返り値のリストの何番目がどの要素かを覚えるのに疲れたなら、
58256930名前ベースのインターフェースが標準モジュールで提供されています:
5826C<File::stat>, C<Net::hostent>, C<Net::netent>,
6931L<C<File::stat>|File::stat>, L<C<Net::hostent>|Net::hostent>,
5827C<Net::protoent>, C<Net::servent>, C<Time::gmtime>, C<Time::localtime>,
6932L<C<Net::netent>|Net::netent>, L<C<Net::protoent>|Net::protoent>,
5828C<User::grent> です。
6933L<C<Net::servent>|Net::servent>, L<C<Time::gmtime>|Time::gmtime>,
6934L<C<Time::localtime>|Time::localtime>,
6935L<C<User::grent>|User::grent> です。
58296936これらは通常の組み込みを上書きし、
58306937それぞれのフィールドに適切な名前をつけたオブジェクトを返します。
58316938例えば:
58326939
58336940 use File::stat;
58346941 use User::pwent;
5835 $is_his = (stat($filename)->uid == pwent($whoever)->uid);
6942 my $is_his = (stat($filename)->uid == pwent($whoever)->uid);
58366943
58376944=begin original
58386945
58396946Even though it looks as though they're the same method calls (uid),
58406947they aren't, because a C<File::stat> object is different from
58416948a C<User::pwent> object.
58426949
58436950=end original
58446951
58456952同じメソッド(uid)を呼び出しているように見えますが、違います;
58466953なぜなら C<File::stat> オブジェクトは C<User::pwent> オブジェクトとは
58476954異なるからです。
58486955
58496956=begin original
58506957
6958Many of these functions are not safe in a multi-threaded environment
6959where more than one thread can be using them. In particular, functions
6960like C<getpwent()> iterate per-process and not per-thread, so if two
6961threads are simultaneously iterating, neither will get all the records.
6962
6963=end original
6964
6965これらの関数の多くは、複数のスレッドがこれらを使うような
6966マルチスレッド環境では安全ではありません。
6967特に、
6968C<getpwent()> のような関数はスレッド単位ではなくプロセス単位で
6969反復するので、二つのスレッドが同時に反復すると、
6970どちらも全てのレコードを得られません。
6971
6972=begin original
6973
6974Some systems have thread-safe versions of some of the functions, such as
6975C<getpwnam_r()> instead of C<getpwnam()>. There, Perl automatically and
6976invisibly substitutes the thread-safe version, without notice. This
6977means that code that safely runs on some systems can fail on others that
6978lack the thread-safe versions.
6979
6980=end original
6981
6982一部のシステムは、
6983C<getpwnam()> の代わりの C<getpwnam_r()> のように、一部の関数について
6984スレッドセーフ版を持っています。
6985その場合、Perl は自動的かつ目に見えないように、通知なしで
6986スレッドセーフ版に置き換えます。
6987つまり、一部のシステムで安全に実行できるコードが
6988スレッドセーフ版のないその他のシステムでは失敗することがあるということです。
6989
6990=begin original
6991
58516992Portability issues: L<perlport/getpwnam> to L<perlport/endservent>.
58526993
58536994=end original
58546995
58556996移植性の問題: L<perlport/getpwnam> から L<perlport/endservent>。
58566997
58576998=item getsockname SOCKET
58586999X<getsockname>
58597000
58607001=for Pod::Functions retrieve the sockaddr for a given socket
58617002
58627003=begin original
58637004
58647005Returns the packed sockaddr address of this end of the SOCKET connection,
58657006in case you don't know the address because you have several different
58667007IPs that the connection might have come in on.
58677008
58687009=end original
58697010
58707011SOCKET 接続のこちら側の pack された sockaddr アドレスを返します;
58717012複数の異なる IP から接続されるためにアドレスがわからない場合に使います。
58727013
58737014 use Socket;
5874 $mysockaddr = getsockname(SOCK);
7015 my $mysockaddr = getsockname($sock);
5875 ($port, $myaddr) = sockaddr_in($mysockaddr);
7016 my ($port, $myaddr) = sockaddr_in($mysockaddr);
58767017 printf "Connect to %s [%s]\n",
58777018 scalar gethostbyaddr($myaddr, AF_INET),
58787019 inet_ntoa($myaddr);
58797020
58807021=item getsockopt SOCKET,LEVEL,OPTNAME
58817022X<getsockopt>
58827023
58837024=for Pod::Functions get socket options on a given socket
58847025
58857026=begin original
58867027
58877028Queries the option named OPTNAME associated with SOCKET at a given LEVEL.
58887029Options may exist at multiple protocol levels depending on the socket
58897030type, but at least the uppermost socket level SOL_SOCKET (defined in the
5890C<Socket> module) will exist. To query options at another level the
7031L<C<Socket>|Socket> module) will exist. To query options at another
5891protocol number of the appropriate protocol controlling the option
7032level the protocol number of the appropriate protocol controlling the
5892should be supplied. For example, to indicate that an option is to be
7033option should be supplied. For example, to indicate that an option is
5893interpreted by the TCP protocol, LEVEL should be set to the protocol
7034to be interpreted by the TCP protocol, LEVEL should be set to the
5894number of TCP, which you can get using C<getprotobyname>.
7035protocol number of TCP, which you can get using
7036L<C<getprotobyname>|/getprotobyname NAME>.
58957037
58967038=end original
58977039
58987040与えられた LEVEL で SOCKET に関連付けられた OPTNAME と言う名前のオプションを
58997041問い合わせます。
59007042オプションはソケットの種類に依存しした複数のプロトコルレベルに存在することも
5901ありますが、少なくとも最上位ソケットレベル SOL_SOCKET (C<Socket> モジュールで
7043ありますが、少なくとも最上位ソケットレベル SOL_SOCKET
5902定義されています)は存在します。
7044(L<C<Socket>|Socket> モジュールで定義されています)は存在します。
59037045その他のレベルのオプションを問い合わせるには、そのオプションを制御する
59047046適切なプロトコルのプロトコル番号を指定します。
59057047例えば、オプションが TCP プロトコルで解釈されるべきであることを示すためには、
5906LEVEL は C<getprotobyname> で得られる TCP のプロトコル番号を設定します。
7048LEVEL は L<C<getprotobyname>|/getprotobyname NAME> で得られる TCP の
7049プロトコル番号を設定します。
59077050
59087051=begin original
59097052
59107053The function returns a packed string representing the requested socket
5911option, or C<undef> on error, with the reason for the error placed in
7054option, or L<C<undef>|/undef EXPR> on error, with the reason for the
5912C<$!>. Just what is in the packed string depends on LEVEL and OPTNAME;
7055error placed in L<C<$!>|perlvar/$!>. Just what is in the packed string
5913consult getsockopt(2) for details. A common case is that the option is an
7056depends on LEVEL and OPTNAME; consult L<getsockopt(2)> for details. A
5914integer, in which case the result is a packed integer, which you can decode
7057common case is that the option is an integer, in which case the result
5915using C<unpack> with the C<i> (or C<I>) format.
7058is a packed integer, which you can decode using
7059L<C<unpack>|/unpack TEMPLATE,EXPR> with the C<i> (or C<I>) format.
59167060
59177061=end original
59187062
59197063この関数は、要求されたソケットオプションの pack された文字列表現か、
5920あるいはエラーの場合は C<undef> を返し、エラーの理由は C<$!> にあります。
7064あるいはエラーの場合は L<C<undef>|/undef EXPR> を返し、エラーの理由は
7065L<C<$!>|perlvar/$!> にあります。
59217066pack された文字列の中身は LEVEL と OPTNAME に依存します;
5922詳細については getsockopt(2) を確認してください。
7067詳細については L<getsockopt(2)> を確認してください。
5923一般的な場合はオプションが整数の場合で、この場合結果は C<unpack> の C<i>
7068一般的な場合はオプションが整数の場合で、この場合結果は
7069L<C<unpack>|/unpack TEMPLATE,EXPR> の C<i>
59247070(あるいは C<I>)フォーマットでデコードできる pack された整数です。
59257071
59267072=begin original
59277073
59287074Here's an example to test whether Nagle's algorithm is enabled on a socket:
59297075
59307076=end original
59317077
59327078あるソケットで Nagle のアルゴリズム有効かどうかを調べる例です:
59337079
59347080 use Socket qw(:all);
59357081
59367082 defined(my $tcp = getprotobyname("tcp"))
59377083 or die "Could not determine the protocol number for tcp";
59387084 # my $tcp = IPPROTO_TCP; # Alternative
59397085 my $packed = getsockopt($socket, $tcp, TCP_NODELAY)
59407086 or die "getsockopt TCP_NODELAY: $!";
59417087 my $nodelay = unpack("I", $packed);
59427088 print "Nagle's algorithm is turned ",
59437089 $nodelay ? "off\n" : "on\n";
59447090
59457091=begin original
59467092
59477093Portability issues: L<perlport/getsockopt>.
59487094
59497095=end original
59507096
59517097移植性の問題: L<perlport/getsockopt>。
59527098
59537099=item glob EXPR
59547100X<glob> X<wildcard> X<filename, expansion> X<expand>
59557101
59567102=item glob
59577103
59587104=for Pod::Functions expand filenames using wildcards
59597105
59607106=begin original
59617107
59627108In list context, returns a (possibly empty) list of filename expansions on
5963the value of EXPR such as the standard Unix shell F</bin/csh> would do. In
7109the value of EXPR such as the Unix shell Bash would do. In
59647110scalar context, glob iterates through such filename expansions, returning
5965undef when the list is exhausted. This is the internal function
7111L<C<undef>|/undef EXPR> when the list is exhausted. If EXPR is omitted,
5966implementing the C<< <*.c> >> operator, but you can use it directly. If
7112L<C<$_>|perlvar/$_> is used.
5967EXPR is omitted, C<$_> is used. The C<< <*.c> >> operator is discussed in
5968more detail in L<perlop/"I/O Operators">.
59697113
59707114=end original
59717115
59727116リストコンテキストでは、
5973EXPR の値を、標準 Unix シェル F</bin/csh> が行なうように
7117EXPR の値を、Unix シェル Bash が行なうように
59747118ファイル名の展開を行なった結果のリスト(空かもしれません)を返します。
59757119スカラコンテキストでは、glob はこのようなファイル名展開を繰り返し、
5976リストがなくなったら undef を返します。
7120リストがなくなったら L<C<undef>|/undef EXPR> を返します。
5977、C<< <*.c> >> 演算子を実装する内部関数です
7121EXPR が省略さるとL<C<$_>|perlvar/$_> が使われます。
5978直接使用することもできます。
5979EXPR が省略されると、C<$_> が使われます。
5980C<< <*.c> >>演算子については
5981L<perlop/"I/O Operators"> でより詳細に議論しています。
59827122
7123 # List context
7124 my @txt_files = glob("*.txt");
7125 my @perl_files = glob("*.pl *.pm");
7126
7127 # Scalar context
7128 while (my $file = glob("*.mp3")) {
7129 # Do stuff
7130 }
7131
59837132=begin original
59847133
5985Note that C<glob> splits its arguments on whitespace and treats
7134Glob also supports an alternate syntax using C<< < >> C<< > >> as
5986each segment as separate pattern. As such, C<glob("*.c *.h")>
7135delimiters. While this syntax is supported, it is recommended that you
7136use C<glob> instead as it is more readable and searchable.
7137
7138=end original
7139
7140glob はまた区切り文字として C<< < >> C<< > >> を使うもう一つの文法に
7141対応しています。
7142この文法は対応していますが、可読性と検索性がより高いので、代わりに
7143C<glob> を使うことを勧めます。
7144
7145 my @txt_files = <"*.txt">;
7146
7147=begin original
7148
7149If you need case insensitive file globbing that can be achieved using the
7150C<:nocase> parameter of the L<C<bsd_glob>|File::Glob/C<bsd_glob>> module.
7151
7152=end original
7153
7154大文字小文字を区別するファイルグロブが必要な場合、
7155L<C<bsd_glob>|File::Glob/C<bsd_glob>> モジュールの C<:nocase> 引数を
7156使うことで達成できます:
7157
7158 use File::Glob qw(:globally :nocase);
7159
7160 my @txt = glob("readme*"); # README readme.txt Readme.md
7161
7162=begin original
7163
7164Note that L<C<glob>|/glob EXPR> splits its arguments on whitespace and
7165treats
7166each segment as separate pattern. As such, C<glob("*.c *.h")>
59877167matches all files with a F<.c> or F<.h> extension. The expression
59887168C<glob(".* *")> matches all files in the current working directory.
59897169If you want to glob filenames that might contain whitespace, you'll
59907170have to use extra quotes around the spacey filename to protect it.
59917171For example, to glob filenames that have an C<e> followed by a space
5992followed by an C<f>, use either of:
7172followed by an C<f>, use one of:
59937173
59947174=end original
59957175
5996C<glob> は引数を空白で分割して、それぞれを分割されたパターンとして扱います。
7176L<C<glob>|/glob EXPR> は引数を空白で分割して、それぞれを分割された
7177パターンとして扱います。
59977178従って、C<glob("*.c *.h")> は F<.c> または F<.h> 拡張子を持つ全てのファイルに
59987179マッチングします。
59997180式 C<glob(".* *")> はカレントワーキングディレクトリの全てのファイルに
60007181マッチングします。
60017182空白を含んでいるかも知れないファイル名をグロブしたい場合、それを守るために
60027183空白入りファイル名の周りに追加のクォートを使う必要があります。
60037184例えば、C<e> の後に空白、その後に C<f> というファイル名をグロブするには
6004以下のどちらかを使います:
7185以下の一つを使います:
60057186
6006 @spacies = <"*e f*">;
7187 my @spacies = <"*e f*">;
6007 @spacies = glob '"*e f*"';
7188 my @spacies = glob('"*e f*"');
6008 @spacies = glob q("*e f*");
7189 my @spacies = glob(q("*e f*"));
60097190
60107191=begin original
60117192
60127193If you had to get a variable through, you could do this:
60137194
60147195=end original
60157196
60167197変数を通す必要があった場合、以下のようにできました:
60177198
6018 @spacies = glob "'*${var}e f*'";
7199 my @spacies = glob("'*${var}e f*'");
6019 @spacies = glob qq("*${var}e f*");
7200 my @spacies = glob(qq("*${var}e f*"));
60207201
60217202=begin original
60227203
60237204If non-empty braces are the only wildcard characters used in the
6024C<glob>, no filenames are matched, but potentially many strings
7205L<C<glob>|/glob EXPR>, no filenames are matched, but potentially many
6025are returned. For example, this produces nine strings, one for
7206strings are returned. For example, this produces nine strings, one for
60267207each pairing of fruits and colors:
60277208
60287209=end original
60297210
6030空でない中かっこが C<glob> で使われている唯一のワイルドカード文字列
7211空でない中かっこが L<C<glob>|/glob EXPR> で使われている唯一の
6031場合、ファイル名とはマッチングせず、可能性のある文字列が返されます。
7212ワイルドカード文字列の場合、ファイル名とはマッチングせず、
7213可能性のある文字列が返されます。
60327214例えば、これは 9 個の文字列を生成し、それぞれは果物と色の組み合わせに
60337215なります:
60347216
6035 @many = glob "{apple,tomato,cherry}={green,yellow,red}";
7217 my @many = glob("{apple,tomato,cherry}={green,yellow,red}");
60367218
60377219=begin original
60387220
6039This operator is implemented using the standard
7221This operator is implemented using the standard C<File::Glob> extension.
6040C<File::Glob> extension. See L<File::Glob> for details, including
7222See L<C<bsd_glob>|File::Glob/C<bsd_glob>> for details, including
6041C<bsd_glob> which does not treat whitespace as a pattern separator.
7223L<C<bsd_glob>|File::Glob/C<bsd_glob>>, which does not treat whitespace
7224as a pattern separator.
60427225
60437226=end original
60447227
6045v5.6.0 から、この演算子は標準の C<File::Glob> 拡張を使って
7228この演算子は標準の C<File::Glob> 拡張を使って
60467229実装されています。
6047空白をパターンのセパレータとして扱わない C<bsd_glob> を含めた
7230空白をパターンのセパレータとして扱わない
6048詳細は L<File::Glob> を参照してください。
7231L<C<bsd_glob>|File::Glob/C<bsd_glob>>含めた
7232詳細は L<C<bsd_glob>|File::Glob/C<bsd_glob>> を参照してください。
60497233
60507234=begin original
60517235
7236If a C<glob> expression is used as the condition of a C<while> or C<for>
7237loop, then it will be implicitly assigned to C<$_>. If either a C<glob>
7238expression or an explicit assignment of a C<glob> expression to a scalar
7239is used as a C<while>/C<for> condition, then the condition actually
7240tests for definedness of the expression's value, not for its regular
7241truth value.
7242
7243=end original
7244
7245C<glob> 式が C<while> や C<for> ループの条件として使われた場合、
7246これは暗黙に C<$_> に代入されます。
7247C<glob> 式または C<glob> 式からスカラへの明示的な代入が
7248C<while>/C<for> の条件部として使われた場合、
7249条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを
7250テストします。
7251
7252=begin original
7253
7254Internal implemenation details:
7255
7256=end original
7257
7258内部実装の詳細:
7259
7260=begin original
7261
7262This is the internal function implementing the C<< <*.c> >> operator,
7263but you can use it directly. The C<< <*.c> >> operator is discussed in
7264more detail in L<perlop/"I/O Operators">.
7265
7266=end original
7267
7268これは、C<< <*.c> >> 演算子を実装する内部関数ですが、
7269直接使用することもできます。
7270C<< <*.c> >>演算子については
7271L<perlop/"I/O Operators"> でより詳細に議論しています。
7272
7273=begin original
7274
60527275Portability issues: L<perlport/glob>.
60537276
60547277=end original
60557278
60567279移植性の問題: L<perlport/glob>。
60577280
60587281=item gmtime EXPR
60597282X<gmtime> X<UTC> X<Greenwich>
60607283
60617284=item gmtime
60627285
60637286=for Pod::Functions convert UNIX time into record or string using Greenwich time
60647287
60657288=begin original
60667289
6067Works just like L</localtime> but the returned values are
7290Works just like L<C<localtime>|/localtime EXPR>, but the returned values
6068localized for the standard Greenwich time zone.
7291are localized for the standard Greenwich time zone.
60697292
60707293=end original
60717294
6072L</localtime> と同様に働きますが、返り値はグリニッジ標準時に
7295L<C<localtime>|/localtime EXPR> と同様に働きますが、返り値はグリニッジ標準時に
60737296ローカライズされています。
60747297
60757298=begin original
60767299
60777300Note: When called in list context, $isdst, the last value
60787301returned by gmtime, is always C<0>. There is no
60797302Daylight Saving Time in GMT.
60807303
60817304=end original
60827305
60837306注意: リストコンテキストで呼び出した時、gmtime が返す末尾の値である
60847307$isdst は常に C<0> です。
60857308GMT には夏時間はありません。
60867309
60877310=begin original
60887311
60897312Portability issues: L<perlport/gmtime>.
60907313
60917314=end original
60927315
60937316移植性の問題: L<perlport/gmtime>。
60947317
60957318=item goto LABEL
60967319X<goto> X<jump> X<jmp>
60977320
60987321=item goto EXPR
60997322
61007323=item goto &NAME
61017324
61027325=for Pod::Functions create spaghetti code
61037326
61047327=begin original
61057328
6106The C<goto-LABEL> form finds the statement labeled with LABEL and
7329The C<goto LABEL> form finds the statement labeled with LABEL and
61077330resumes execution there. It can't be used to get out of a block or
6108subroutine given to C<sort>. It can be used to go almost anywhere
7331subroutine given to L<C<sort>|/sort SUBNAME LIST>. It can be used to go
6109else within the dynamic scope, including out of subroutines, but it's
7332almost anywhere else within the dynamic scope, including out of
6110usually better to use some other construct such as C<last> or C<die>.
7333subroutines, but it's usually better to use some other construct such as
6111The author of Perl has never felt the need to use this form of C<goto>
7334L<C<last>|/last LABEL> or L<C<die>|/die LIST>. The author of Perl has
6112(in Perl, that is; C is another matter). (The difference is that C
7335never felt the need to use this form of L<C<goto>|/goto LABEL> (in Perl,
6113does not offer named loops combined with loop control. Perl does, and
7336that is; C is another matter). (The difference is that C does not offer
6114this replaces most structured uses of C<goto> in other languages.)
7337named loops combined with loop control. Perl does, and this replaces
7338most structured uses of L<C<goto>|/goto LABEL> in other languages.)
61157339
61167340=end original
61177341
6118C<goto-LABEL> の形式は、LABEL というラベルの付いた文を
7342C<goto LABEL> の形式は、LABEL というラベルの付いた文を
61197343探して、そこへ実行を移すものです。
6120C<sort> で与えられたブロックやサブルーチンから外へ出ることはできません。
7344L<C<sort>|/sort SUBNAME LIST> で与えられたブロックやサブルーチンから外へ
7345出ることはできません。
61217346これ以外は、サブルーチンの外を含む、動的スコープ内の
61227347ほとんどすべての場所へ行くために使用できますが、普通は、
6123C<last> や C<die> といった別の構造を使った方が良いでしょう。
7348L<C<last>|/last LABEL> L<C<die>|/die LIST> といった別の構造を使った方が
6124Perl の作者はこの形式の C<goto> を使必要を感じたことは、
7349良いでしょ
7350Perl の作者はこの形式の L<C<goto>|/goto LABEL> を使う必要を感じたことは、
612573511 度もありません (Perl では; C は別のお話です)。
61267352(違いは、C にはループ制御と結びついた名前つきのループがないことです。
6127Perl にはあり、これが他の言語でのほとんどの構造的な C<goto> の使用法を
7353Perl にはあり、これが他の言語でのほとんどの構造的な L<C<goto>|/goto LABEL>
6128置き換えます。)
7354使用法を置き換えます。)
61297355
61307356=begin original
61317357
6132The C<goto-EXPR> form expects a label name, whose scope will be resolved
7358The C<goto EXPR> form expects to evaluate C<EXPR> to a code reference or
6133dynamically. This allows for computed C<goto>s per FORTRAN, but isn't
7359a label name. If it evaluates to a code reference, it will be handled
6134necessarily recommended if you're optimizing for maintainability:
7360like C<goto &NAME>, below. This is especially useful for implementing
7361tail recursion via C<goto __SUB__>.
61357362
61367363=end original
61377364
6138C<goto-EXPR> の形式はラベル名を予測、このスコープは動的に解決されます。
7365C<goto EXPR> の形式は、C<EXPR> をコードリファレンスまたはラベル名
6139れにより FORTRAN のような算術 C<goto> が可能になりますが、
7366評価するとを想定します
7367コードリファレンスとして評価する場合、後述する C<goto &NAME> のように
7368扱います。
7369これは特に、C<goto __SUB__> による末尾再帰の実装に有用です。
7370
7371=begin original
7372
7373If the expression evaluates to a label name, its scope will be resolved
7374dynamically. This allows for computed L<C<goto>|/goto LABEL>s per
7375FORTRAN, but isn't necessarily recommended if you're optimizing for
7376maintainability:
7377
7378=end original
7379
7380式がラベル名に評価される場合、このスコープは動的に解決されます。
7381これにより FORTRAN のような算術 L<C<goto>|/goto LABEL> が可能になりますが、
61407382保守性を重視するならお勧めしません。
61417383
61427384 goto ("FOO", "BAR", "GLARCH")[$i];
61437385
61447386=begin original
61457387
6146As shown in this example, C<goto-EXPR> is exempt from the "looks like a
7388As shown in this example, C<goto EXPR> is exempt from the "looks like a
61477389function" rule. A pair of parentheses following it does not (necessarily)
61487390delimit its argument. C<goto("NE")."XT"> is equivalent to C<goto NEXT>.
61497391Also, unlike most named operators, this has the same precedence as
61507392assignment.
61517393
61527394=end original
61537395
6154この例で示したように、C<goto-EXPR> は「関数のように見える」ルールから
7396この例で示したように、C<goto EXPR> は「関数のように見える」ルールから
61557397除外されます。
61567398これに引き続くかっこの組は引数の区切りとは(必ずしも)なりません。
61577399C<goto("NE")."XT"> は C<goto NEXT> と等価です。
61587400また、ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
61597401
61607402=begin original
61617403
6162Use of C<goto-LABEL> or C<goto-EXPR> to jump into a construct is
7404Use of C<goto LABEL> or C<goto EXPR> to jump into a construct is
61637405deprecated and will issue a warning. Even then, it may not be used to
61647406go into any construct that requires initialization, such as a
6165subroutine or a C<foreach> loop. It also can't be used to go into a
7407subroutine, a C<foreach> loop, or a C<given>
7408block. In general, it may not be used to jump into the parameter
7409of a binary or list operator, but it may be used to jump into the
7410I<first> parameter of a binary operator. (The C<=>
7411assignment operator's "first" operand is its right-hand
7412operand.) It also can't be used to go into a
61667413construct that is optimized away.
61677414
61687415=end original
61697416
6170構造の中に飛び込むために C<goto-LABEL> や C<goto-EXPR> を使うことは
7417構造の中に飛び込むために C<goto LABEL> や C<goto EXPR> を使うことは
61717418非推奨で、警告が発生します。
6172それでも、サブルーチンや C<foreach> ループのような、初期化が必要な
7419それでも、サブルーチンや C<foreach> ループや C<given> ブロックのような、
7420初期化が必要な
61737421構造の中に入るために使うことは出来ません。
7422一般的に、2 項演算子やリスト演算子の引数に飛び込むことはできませんが、
74232 項演算子の I<最初の> 引数に飛び込むために使われていました。
7424(C<=> 代入演算子の「最初の」オペランドはその右オペランドです。)
61747425また、最適化してなくなってしまった構造の中へ入るために使うことも出来ません。
61757426
61767427=begin original
61777428
6178The C<goto-&NAME> form is quite different from the other forms of
7429The C<goto &NAME> form is quite different from the other forms of
6179C<goto>. In fact, it isn't a goto in the normal sense at all, and
7430L<C<goto>|/goto LABEL>. In fact, it isn't a goto in the normal sense at
6180doesn't have the stigma associated with other gotos. Instead, it
7431all, and doesn't have the stigma associated with other gotos. Instead,
6181exits the current subroutine (losing any changes set by local()) and
7432it exits the current subroutine (losing any changes set by
6182immediately calls in its place the named subroutine using the current
7433L<C<local>|/local EXPR>) and immediately calls in its place the named
6183value of @_. This is used by C<AUTOLOAD> subroutines that wish to
7434subroutine using the current value of L<C<@_>|perlvar/@_>. This is used
6184load another subroutine and then pretend that the other subroutine had
7435by C<AUTOLOAD> subroutines that wish to load another subroutine and then
6185been called in the first place (except that any modifications to C<@_>
7436pretend that the other subroutine had been called in the first place
6186in the current subroutine are propagated to the other subroutine.)
7437(except that any modifications to L<C<@_>|perlvar/@_> in the current
6187After the C<goto>, not even C<caller> will be able to tell that this
7438subroutine are propagated to the other subroutine.) After the
6188routine was called first.
7439L<C<goto>|/goto LABEL>, not even L<C<caller>|/caller EXPR> will be able
7440to tell that this routine was called first.
61897441
61907442=end original
61917443
6192C<goto-&NAME> の形式は、その他の C<goto> の形式とはかなり
7444C<goto &NAME> の形式は、その他の L<C<goto>|/goto LABEL> の形式とはかなり
61937445異なったものです。
61947446実際、これは普通の感覚でいうところのどこかへ行くものでは全くなく、
61957447他の goto が持つ不名誉を持っていません。
6196現在のサブルーチンを終了し (local() による変更は失われます)、
7448現在のサブルーチンを終了し (L<C<local>|/local EXPR> による変更は失われます)、
6197直ちに現在の @_ の値を使って指定された名前のサブルーチンを呼び出します。
7449直ちに現在の L<C<@_>|perlvar/@_> の値を使って指定された名前のサブルーチンを
7450呼び出します。
61987451これは、C<AUTOLOAD> サブルーチンが別のサブルーチンをロードして、
61997452その別のサブルーチンが最初に呼ばれたようにするために使われます
6200(ただし、現在のサブルーチンで C<@_> を修正した場合には、
7453(ただし、現在のサブルーチンで L<C<@_>|perlvar/@_> を修正した場合には、
62017454その別のサブルーチンに伝えられます)。
6202C<goto> のあとは、C<caller> でさえも、現在のサブルーチンが
7455L<C<goto>|/goto LABEL> のあとは、L<C<caller>|/caller EXPR> でさえも、現在の
6203最初に呼び出されたと言うことができません。
7456サブルーチンが最初に呼び出されたと言うことができません。
62047457
62057458=begin original
62067459
62077460NAME needn't be the name of a subroutine; it can be a scalar variable
62087461containing a code reference or a block that evaluates to a code
62097462reference.
62107463
62117464=end original
62127465
62137466NAME はサブルーチンの名前である必要はありません; コードリファレンスを
62147467含むスカラ値や、コードリファレンスと評価されるブロックでも構いません。
62157468
62167469=item grep BLOCK LIST
62177470X<grep>
62187471
62197472=item grep EXPR,LIST
62207473
62217474=for Pod::Functions locate elements in a list test true against a given criterion
62227475
62237476=begin original
62247477
6225This is similar in spirit to, but not the same as, grep(1) and its
7478This is similar in spirit to, but not the same as, L<grep(1)> and its
62267479relatives. In particular, it is not limited to using regular expressions.
62277480
62287481=end original
62297482
6230これは grep(1) とその親類と同じようなものですが、同じではありません。
7483これは L<grep(1)> とその親類と同じようなものですが、同じではありません。
62317484特に、正規表現の使用に制限されません。
62327485
62337486=begin original
62347487
62357488Evaluates the BLOCK or EXPR for each element of LIST (locally setting
6236C<$_> to each element) and returns the list value consisting of those
7489L<C<$_>|perlvar/$_> to each element) and returns the list value
7490consisting of those
62377491elements for which the expression evaluated to true. In scalar
62387492context, returns the number of times the expression was true.
62397493
62407494=end original
62417495
62427496LIST の個々の要素に対して、BLOCK か EXPR を評価し
6243(C<$_> は、ローカルに個々の要素が設定されます) 、
7497(L<C<$_>|perlvar/$_> は、ローカルに個々の要素が設定されます) 、
62447498その要素のうち、評価した式が真となったものからなるリスト値が返されます。
62457499スカラコンテキストでは、式が真となった回数を返します。
62467500
6247 @foo = grep(!/^#/, @bar); # weed out comments
7501 my @foo = grep(!/^#/, @bar); # weed out comments
62487502
62497503=begin original
62507504
62517505or equivalently,
62527506
62537507=end original
62547508
62557509あるいは等価な例として:
62567510
6257 @foo = grep {!/^#/} @bar; # weed out comments
7511 my @foo = grep {!/^#/} @bar; # weed out comments
62587512
62597513=begin original
62607514
6261Note that C<$_> is an alias to the list value, so it can be used to
7515Note that L<C<$_>|perlvar/$_> is an alias to the list value, so it can
7516be used to
62627517modify the elements of the LIST. While this is useful and supported,
62637518it can cause bizarre results if the elements of LIST are not variables.
62647519Similarly, grep returns aliases into the original list, much as a for
62657520loop's index variable aliases the list elements. That is, modifying an
6266element of a list returned by grep (for example, in a C<foreach>, C<map>
7521element of a list returned by grep (for example, in a C<foreach>,
6267or another C<grep>) actually modifies the element in the original list.
7522L<C<map>|/map BLOCK LIST> or another L<C<grep>|/grep BLOCK LIST>)
7523actually modifies the element in the original list.
62687524This is usually something to be avoided when writing clear code.
62697525
62707526=end original
62717527
6272C<$_> は、LIST の値へのエイリアスですので、LIST の要素を
7528L<C<$_>|perlvar/$_> は、LIST の値へのエイリアスですので、LIST の要素を
62737529変更するために使うことができます。
62747530これは、便利でサポートされていますが、
62757531LIST の要素が変数でないと、おかしな結果になります。
62767532同様に、grep は元のリストへのエイリアスを返します; for ループの
62777533インデックス変数がリスト要素のエイリアスであるのと同様です。
62787534つまり、grep で返されたリストの要素を
6279(C<foreach>, C<map>, または他の C<grep> で)修正すると
7535(C<foreach>, L<C<map>|/map BLOCK LIST>, または他の
6280元のリストの要素が変更されます。
7536L<C<grep>|/grep BLOCK LIST> で)修正すると元のリストの要素が変更されます。
62817537これはきれいなコードを書くときには普通は回避されます。
62827538
62837539=begin original
62847540
6285If C<$_> is lexical in the scope where the C<grep> appears (because it has
7541See also L<C<map>|/map BLOCK LIST> for a list composed of the results of
6286been declared with the deprecated C<my $_> construct)
7542the BLOCK or EXPR.
6287then, in addition to being locally aliased to
6288the list elements, C<$_> keeps being lexical inside the block; i.e., it
6289can't be seen from the outside, avoiding any potential side-effects.
62907543
62917544=end original
62927545
6293(廃止予定の C<my $_> 構文で宣言されることよって) C<$_> C<grep> が現れる
7546BLOCK EXPR の結果をリストの形したい場合は L<C<map>|/map BLOCK LIST>
6294スコープ内でレキシカルな場合は、ローカルではリスト要素への
7547参照してください。
6295エイリアスであることに加えて、C<$_> はブロック内でレキシカルで
6296ありつづけます; つまり、外側からは見えず、起こりうる副作用を回避します。
62977548
6298=begin original
6299
6300See also L</map> for a list composed of the results of the BLOCK or EXPR.
6301
6302=end original
6303
6304BLOCK や EXPR の結果をリストの形にしたい場合は L</map> を参照してください。
6305
63067549=item hex EXPR
63077550X<hex> X<hexadecimal>
63087551
63097552=item hex
63107553
6311=for Pod::Functions convert a string to a hexadecimal number
7554=for Pod::Functions convert a hexadecimal string to a number
63127555
63137556=begin original
63147557
6315Interprets EXPR as a hex string and returns the corresponding value.
7558Interprets EXPR as a hex string and returns the corresponding numeric value.
6316(To convert strings that might start with either C<0>, C<0x>, or C<0b>, see
7559If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
6317L</oct>.) If EXPR is omitted, uses C<$_>.
63187560
63197561=end original
63207562
6321EXPR を 16 進数の文字列と解釈して、対応する値を返します。
7563EXPR を 16 進数の文字列と解釈して、対応する値を返します。
6322(C<0>, C<0x>, C<0b> で始ま文字列の変換には、L</oct> を
7564EXPR が省略され、L<C<$_>|perlvar/$_> を使います。
6323参照してください。)
6324EXPR が省略されると、C<$_> を使います。
63257565
63267566 print hex '0xAf'; # prints '175'
63277567 print hex 'aF'; # same
7568 $valid_input =~ /\A(?:0?[xX])?(?:_?[0-9a-fA-F])*\z/
63287569
63297570=begin original
63307571
6331Hex strings may only represent integers. Strings that would cause
7572A hex string consists of hex digits and an optional C<0x> or C<x> prefix.
6332integer overflow trigger a warning. Leading whitespace is not stripped,
7573Each hex digit may be preceded by a single underscore, which will be ignored.
6333unlike oct(). To present something as hex, look into L</printf>,
7574Any other character triggers a warning and causes the rest of the string
6334L</sprintf>, and L</unpack>.
7575to be ignored (even leading whitespace, unlike L<C<oct>|/oct EXPR>).
7576Only integers can be represented, and integer overflow triggers a warning.
63357577
63367578=end original
63377579
633816 進文字列は数のみを表現します。
758016 進文字列は 16 進と、オプション C<0x> または C<x> 接頭辞からなります。
6339オーバーフローを起こすような文字列警告ます。
7581それぞれの 16 進数は一つの下線前に置くことがでれは無視されます。
6340oct() と違って、先頭の空白は除去されません。
7582その他の文字警告を引き起こし(例え先頭の空白でも、L<C<oct>|/oct EXPR> と
6341何かを 16 進で表現したい場合、L</printf>, L</sprintf>, L</unpack> を
7583異なり)文字列の残りの部分無視されます。
7584整数のみを表現でき、整数オーバーフローは警告を引き起こします。
7585
7586=begin original
7587
7588To convert strings that might start with any of C<0>, C<0x>, or C<0b>,
7589see L<C<oct>|/oct EXPR>. To present something as hex, look into
7590L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
7591L<C<sprintf>|/sprintf FORMAT, LIST>, and
7592L<C<unpack>|/unpack TEMPLATE,EXPR>.
7593
7594=end original
7595
7596C<0>, C<0x>, C<0b> のいずれかで始まるかもしれない文字列を変換するには、
7597L<C<oct>|/oct EXPR> を参照してください。
7598何かを 16 進で表現したい場合は、L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
7599L<C<sprintf>|/sprintf FORMAT, LIST>, L<C<unpack>|/unpack TEMPLATE,EXPR> を
63427600参照してください。
63437601
63447602=item import LIST
63457603X<import>
63467604
63477605=for Pod::Functions patch a module's namespace into your own
63487606
63497607=begin original
63507608
6351There is no builtin C<import> function. It is just an ordinary
7609There is no builtin L<C<import>|/import LIST> function. It is just an
6352method (subroutine) defined (or inherited) by modules that wish to export
7610ordinary method (subroutine) defined (or inherited) by modules that wish
6353names to another module. The C<use> function calls the C<import> method
7611to export names to another module. The
6354for the package used. See also L</use>, L<perlmod>, and L<Exporter>.
7612L<C<use>|/use Module VERSION LIST> function calls the
7613L<C<import>|/import LIST> method for the package used. See also
7614L<C<use>|/use Module VERSION LIST>, L<perlmod>, and L<Exporter>.
63557615
63567616=end original
63577617
6358組み込みの C<import> 関数というものはありません。
7618組み込みの L<C<import>|/import LIST> 関数というものはありません。
63597619これは単に、別のモジュールに名前をエクスポートしたいモジュールが
63607620定義した(または継承した)、通常のメソッド(サブルーチン)です。
6361C<use> 関数はパッケージを使う時に C<import> メソッドを呼び出します。
7621L<C<use>|/use Module VERSION LIST> 関数はパッケージを使う時に
6362L</use>, L<perlmod>, L<Exporter> も参照てください
7622L<C<import>|/import LIST> メソッドを呼び出ます
7623L<C<use>|/use Module VERSION LIST>, L<perlmod>, L<Exporter> も
7624参照してください。
63637625
63647626=item index STR,SUBSTR,POSITION
63657627X<index> X<indexOf> X<InStr>
63667628
63677629=item index STR,SUBSTR
63687630
63697631=for Pod::Functions find a substring within a string
63707632
63717633=begin original
63727634
63737635The index function searches for one string within another, but without
63747636the wildcard-like behavior of a full regular-expression pattern match.
63757637It returns the position of the first occurrence of SUBSTR in STR at
63767638or after POSITION. If POSITION is omitted, starts searching from the
63777639beginning of the string. POSITION before the beginning of the string
63787640or after its end is treated as if it were the beginning or the end,
63797641respectively. POSITION and the return value are based at zero.
6380If the substring is not found, C<index> returns -1.
7642If the substring is not found, L<C<index>|/index STR,SUBSTR,POSITION>
7643returns -1.
63817644
63827645=end original
63837646
63847647index 関数は ある文字列をもうひとつの文字列から検索しますが、
63857648完全正規表現パターンマッチのワイルドカード的な振る舞いはしません。
63867649STR の中の POSITION の位置以降で、最初に SUBSTR が見つかった位置を返します。
63877650POSITION が省略された場合には、STR の最初から探し始めます。
63887651POSITION が文字列の先頭より前、あるいは末尾より後ろを指定した場合は、
63897652それぞれ先頭と末尾を指定されたものとして扱われます。
63907653POSITION と返り値のベースは、0 です。
6391SUBSTR が見つからなかった場合には、C<index> -1 が返されます。
7654SUBSTR が見つからなかった場合には、L<C<index>|/index STR,SUBSTR,POSITION>
7655-1 が返されます。
63927656
7657=begin original
7658
7659Find characters or strings:
7660
7661=end original
7662
7663文字や文字列を探すには:
7664
7665 index("Perl is great", "P"); # Returns 0
7666 index("Perl is great", "g"); # Returns 8
7667 index("Perl is great", "great"); # Also returns 8
7668
7669=begin original
7670
7671Attempting to find something not there:
7672
7673=end original
7674
7675ないものを探そうとすると:
7676
7677 index("Perl is great", "Z"); # Returns -1 (not found)
7678
7679=begin original
7680
7681Using an offset to find the I<second> occurrence:
7682
7683=end original
7684
7685I<2 番目> の出現位置を探すためにオフセットを使うと:
7686
7687 index("Perl is great", "e", 5); # Returns 10
7688
63937689=item int EXPR
63947690X<int> X<integer> X<truncate> X<trunc> X<floor>
63957691
63967692=item int
63977693
63987694=for Pod::Functions get the integer portion of a number
63997695
64007696=begin original
64017697
6402Returns the integer portion of EXPR. If EXPR is omitted, uses C<$_>.
7698Returns the integer portion of EXPR. If EXPR is omitted, uses
7699L<C<$_>|perlvar/$_>.
64037700You should not use this function for rounding: one because it truncates
64047701towards C<0>, and two because machine representations of floating-point
64057702numbers can sometimes produce counterintuitive results. For example,
64067703C<int(-6.725/0.025)> produces -268 rather than the correct -269; that's
64077704because it's really more like -268.99999999999994315658 instead. Usually,
6408the C<sprintf>, C<printf>, or the C<POSIX::floor> and C<POSIX::ceil>
7705the L<C<sprintf>|/sprintf FORMAT, LIST>,
6409functions will serve you better than will int().
7706L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, or the
7707L<C<POSIX::floor>|POSIX/C<floor>> and L<C<POSIX::ceil>|POSIX/C<ceil>>
7708functions will serve you better than will L<C<int>|/int EXPR>.
64107709
64117710=end original
64127711
64137712EXPR の整数部を返します。
6414EXPR が省略されると、C<$_> を使います。
7713EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
64157714この関数を丸めのために使うべきではありません: 第一の理由として C<0> の
64167715方向への切捨てを行うから、第二の理由として浮動小数点数の機械表現は時々直感に
64177716反した結果を生み出すからです。
64187717たとえば、C<int(-6.725/0.025)> は正しい結果である -269 ではなく -268 を
64197718返します: これは実際には -268.99999999999994315658 というような値に
64207719なっているからです。
6421通常、C<sprintf>, C<printf>, C<POSIX::floor>, C<POSIX::ceil> の方が
7720通常、L<C<sprintf>|/sprintf FORMAT, LIST>,
6422int() より便利です。
7721L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
7722L<C<POSIX::floor>|POSIX/C<floor>>, L<C<POSIX::ceil>|POSIX/C<ceil>> の方が
7723L<C<int>|/int EXPR> より便利です。
64237724
64247725=item ioctl FILEHANDLE,FUNCTION,SCALAR
64257726X<ioctl>
64267727
64277728=for Pod::Functions system-dependent device control system call
64287729
64297730=begin original
64307731
6431Implements the ioctl(2) function. You'll probably first have to say
7732Implements the L<ioctl(2)> function. You'll probably first have to say
64327733
64337734=end original
64347735
6435ioctl(2) 関数を実装します。
7736L<ioctl(2)> 関数を実装します。
64367737正しい関数の定義を得るために、おそらく最初に
64377738
64387739 require "sys/ioctl.ph"; # probably in
64397740 # $Config{archlib}/sys/ioctl.ph
64407741
64417742=begin original
64427743
64437744to get the correct function definitions. If F<sys/ioctl.ph> doesn't
64447745exist or doesn't have the correct definitions you'll have to roll your
64457746own, based on your C header files such as F<< <sys/ioctl.h> >>.
64467747(There is a Perl script called B<h2ph> that comes with the Perl kit that
64477748may help you in this, but it's nontrivial.) SCALAR will be read and/or
64487749written depending on the FUNCTION; a C pointer to the string value of SCALAR
6449will be passed as the third argument of the actual C<ioctl> call. (If SCALAR
7750will be passed as the third argument of the actual
7751L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> call. (If SCALAR
64507752has no string value but does have a numeric value, that value will be
64517753passed rather than a pointer to the string value. To guarantee this to be
6452true, add a C<0> to the scalar before using it.) The C<pack> and C<unpack>
7754true, add a C<0> to the scalar before using it.) The
7755L<C<pack>|/pack TEMPLATE,LIST> and L<C<unpack>|/unpack TEMPLATE,EXPR>
64537756functions may be needed to manipulate the values of structures used by
6454C<ioctl>.
7757L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>.
64557758
64567759=end original
64577760
64587761としなくてはならないでしょう。
64597762F<sys/ioctl.ph> がないか、間違った定義をしている場合には、
64607763F<< <sys/ioctl.h> >>のような C のヘッダファイルをもとに、
64617764自分で作らなければなりません。
64627765(Perl の配布キットに入っている B<h2ph> という Perl スクリプトが
64637766これを手助けしてくれるでしょうが、これは自明ではありません。)
64647767FOUNCTION に応じて SCALAR が読み書きされます;
6465SCALAR の文字列値へのポインタが、実際の C<ioctl> コールの
7768SCALAR の文字列値へのポインタが、実際の
7769L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> コールの
646677703 番目の引数として渡されます。
64677771(SCALAR が文字列値を持っておらず、数値を持っている場合には、
64687772文字列値へのポインタの代わりに、その値が渡されます。
64697773このことを保証するためには、使用する前に SCALAR にC<0> を足してください。)
6470C<ioctl> で使われる構造体の値を操作するには、
7774L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> で使われる構造体の値を
6471C<pack> 関数と C<unpack> 関数が必要なるでしょう。
7775操作するには、L<C<pack>|/pack TEMPLATE,LIST> 関数と
7776L<C<unpack>|/unpack TEMPLATE,EXPR> 関数が必要となるでしょう。
64727777
64737778=begin original
64747779
6475The return value of C<ioctl> (and C<fcntl>) is as follows:
7780The return value of L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> (and
7781L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>) is as follows:
64767782
64777783=end original
64787784
6479C<ioctl> (と C<fcntl>) の返り値は、以下のようになります:
7785L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>
7786(と L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>) の返り値は、
7787以下のようになります:
64807788
64817789=begin original
64827790
64837791 if OS returns: then Perl returns:
64847792 -1 undefined value
64857793 0 string "0 but true"
64867794 anything else that number
64877795
64887796=end original
64897797
64907798 OS が返した値: Perl が返す値:
64917799 -1 未定義値
64927800 0 「0 だが真」の文字列
64937801 その他 その値そのもの
64947802
64957803=begin original
64967804
64977805Thus Perl returns true on success and false on failure, yet you can
64987806still easily determine the actual value returned by the operating
64997807system:
65007808
65017809=end original
65027810
65037811つまり Perl は、成功時に「真」、失敗時に「偽」を返す
65047812ことになり、OS が実際に返した値も、以下のように簡単に知ることができます。
65057813
6506 $retval = ioctl(...) || -1;
7814 my $retval = ioctl(...) || -1;
65077815 printf "System returned %d\n", $retval;
65087816
65097817=begin original
65107818
6511The special string C<"0 but true"> is exempt from B<-w> complaints
7819The special string C<"0 but true"> is exempt from
6512about improper numeric conversions.
7820L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s>
7821L<warnings> on improper numeric conversions.
65137822
65147823=end original
65157824
65167825特別な文字列 C<"0 だが真"> は、不適切な数値変換に関する
6517B<-w> 警告を回避します。
7826L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s>
7827L<warnings> 警告を回避します。
65187828
65197829=begin original
65207830
65217831Portability issues: L<perlport/ioctl>.
65227832
65237833=end original
65247834
65257835移植性の問題: L<perlport/ioctl>。
65267836
65277837=item join EXPR,LIST
65287838X<join>
65297839
65307840=for Pod::Functions join a list into a string using a separator
65317841
65327842=begin original
65337843
65347844Joins the separate strings of LIST into a single string with fields
65357845separated by the value of EXPR, and returns that new string. Example:
65367846
65377847=end original
65387848
65397849LIST の個別の文字列を、EXPR の値で区切って
654078501 つの文字列につなげ、その文字列を返します。
65417851例:
65427852
6543 $rec = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell);
7853 my $rec = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell);
65447854
65457855=begin original
65467856
6547Beware that unlike C<split>, C<join> doesn't take a pattern as its
7857Beware that unlike L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>,
6548first argument. Compare L</split>.
7858L<C<join>|/join EXPR,LIST> doesn't take a pattern as its first argument.
7859Compare L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>.
65497860
65507861=end original
65517862
6552C<split> と違って、C<join> は最初の引数にパターンは取れないこ
7863L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>違って、
7864L<C<join>|/join EXPR,LIST> は最初の引数にパターンは取れないことに
65537865注意してください。
6554L</split> と比較してください。
7866L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> と比較してください。
65557867
65567868=item keys HASH
65577869X<keys> X<key>
65587870
65597871=item keys ARRAY
65607872
6561=item keys EXPR
6562
65637873=for Pod::Functions retrieve list of indices from a hash
65647874
65657875=begin original
65667876
65677877Called in list context, returns a list consisting of all the keys of the
65687878named hash, or in Perl 5.12 or later only, the indices of an array. Perl
65697879releases prior to 5.12 will produce a syntax error if you try to use an
65707880array argument. In scalar context, returns the number of keys or indices.
65717881
65727882=end original
65737883
65747884リストコンテキストで呼び出されると、指定したハッシュのすべてのキー、あるいは
6575Perl 5.12 以降でのみ、配列のインデックスからなるリストを
7885Perl 5.12 以降でのみ、配列のインデックスからなるリストを返します。
6576返します。
657778865.12 より前の Perl は配列引数を使おうとすると文法エラーを出力します。
65787887スカラコンテキストでは、キーやインデックスの数を返します。
65797888
65807889=begin original
65817890
65827891Hash entries are returned in an apparently random order. The actual random
65837892order is specific to a given hash; the exact same series of operations
6584on two hashes may result in a different order for each hash. Any insertion
7893on two hashes may result in a different order for each hash. Any insertion
65857894into the hash may change the order, as will any deletion, with the exception
6586that the most recent key returned by C<each> or C<keys> may be deleted
7895that the most recent key returned by L<C<each>|/each HASH> or
6587without changing the order. So long as a given hash is unmodified you may
7896L<C<keys>|/keys HASH> may be deleted without changing the order. So
6588rely on C<keys>, C<values> and C<each> to repeatedly return the same order
7897long as a given hash is unmodified you may rely on
6589as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
7898L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and L<C<each>|/each
6590details on why hash order is randomized. Aside from the guarantees
7899HASH> to repeatedly return the same order
7900as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
7901details on why hash order is randomized. Aside from the guarantees
65917902provided here the exact details of Perl's hash algorithm and the hash
6592traversal order are subject to change in any release of Perl.
7903traversal order are subject to change in any release of Perl. Tied hashes
7904may behave differently to Perl's hashes with respect to changes in order on
7905insertion and deletion of items.
65937906
65947907=end original
65957908
65967909ハッシュ要素は見かけ上、ランダムな順序で返されます。
65977910実際のランダムな順序はハッシュに固有です; 二つのハッシュに全く同じ一連の
65987911操作を行っても、ハッシュによって異なった順序になります。
65997912ハッシュへの挿入によって順序が変わることがあります; 削除も同様ですが、
6600C<each> または C<keys> によって返されたもっとも最近のキーは順序を
7913L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも
6601変えることなく削除できます。
7914最近のキーは順序を変えることなく削除できます。
6602ハッシュが変更されない限り、C<keys>, C<values>, C<each> が繰り返し同じ順序で
7915ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>,
6603返すことに依存してもかまいません。
7916L<C<each>|/each HASH> が繰り返し同じ順序で返すことに依存してもかまいません。
66047917なぜハッシュの順序がランダム化されているかの詳細については
66057918L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。
66067919ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の
66077920正確な詳細は Perl のリリースによって変更される可能性があります。
7921tie されたハッシュは、アイテムの挿入と削除の順序に関して Perl のハッシュと
7922異なった振る舞いをします。
66087923
66097924=begin original
66107925
6611As a side effect, calling keys() resets the internal iterator of the HASH or
7926As a side effect, calling L<C<keys>|/keys HASH> resets the internal
6612ARRAY (see L</each>). In particular, calling keys() in void context resets
7927iterator of the HASH or ARRAY (see L<C<each>|/each HASH>) before
6613the iterator with no other overhead.
7928yielding the keys. In
7929particular, calling L<C<keys>|/keys HASH> in void context resets the
7930iterator with no other overhead.
66147931
66157932=end original
66167933
6617副作用として、HASH や ARRAY 反復子を初期化ます
7934副作用として、L<C<keys>|/keys HASH>呼び出は、
6618(L</each>参照してください)。
7935キーを取り出す前に HASH や ARRAY の反復子
6619特に、無効コンテキストで keys()呼び出すと
7936初期化します (L<C<each>|/each HASH> 参照してください)。
7937特に、無効コンテキストで L<C<keys>|/keys HASH> を呼び出すと
66207938オーバーヘッドなしで反復子を初期化します。
66217939
66227940=begin original
66237941
66247942Here is yet another way to print your environment:
66257943
66267944=end original
66277945
66287946環境変数を表示する別の例です:
66297947
6630 @keys = keys %ENV;
7948 my @keys = keys %ENV;
6631 @values = values %ENV;
7949 my @values = values %ENV;
66327950 while (@keys) {
66337951 print pop(@keys), '=', pop(@values), "\n";
66347952 }
66357953
66367954=begin original
66377955
66387956or how about sorted by key:
66397957
66407958=end original
66417959
66427960key でソートしてもいいでしょう:
66437961
6644 foreach $key (sort(keys %ENV)) {
7962 foreach my $key (sort(keys %ENV)) {
66457963 print $key, '=', $ENV{$key}, "\n";
66467964 }
66477965
66487966=begin original
66497967
66507968The returned values are copies of the original keys in the hash, so
6651modifying them will not affect the original hash. Compare L</values>.
7969modifying them will not affect the original hash. Compare
7970L<C<values>|/values HASH>.
66527971
66537972=end original
66547973
66557974返される値はハッシュにある元のキーのコピーなので、
66567975これを変更しても元のハッシュには影響を与えません。
6657L</values> と比較してください。
7976L<C<values>|/values HASH> と比較してください。
66587977
66597978=begin original
66607979
6661To sort a hash by value, you'll need to use a C<sort> function.
7980To sort a hash by value, you'll need to use a
6662Here's a descending numeric sort of a hash by its values:
7981L<C<sort>|/sort SUBNAME LIST> function. Here's a descending numeric
7982sort of a hash by its values:
66637983
66647984=end original
66657985
6666ハッシュを値でソートするためには、C<sort> 関数を使う必要があります。
7986ハッシュを値でソートするためには、L<C<sort>|/sort SUBNAME LIST> 関数を使う
7987必要があります。
66677988以下ではハッシュの値を数値の降順でソートしています:
66687989
6669 foreach $key (sort { $hash{$b} <=> $hash{$a} } keys %hash) {
7990 foreach my $key (sort { $hash{$b} <=> $hash{$a} } keys %hash) {
66707991 printf "%4d %s\n", $hash{$key}, $key;
66717992 }
66727993
66737994=begin original
66747995
6675Used as an lvalue, C<keys> allows you to increase the number of hash buckets
7996Used as an lvalue, L<C<keys>|/keys HASH> allows you to increase the
7997number of hash buckets
66767998allocated for the given hash. This can gain you a measure of efficiency if
66777999you know the hash is going to get big. (This is similar to pre-extending
66788000an array by assigning a larger number to $#array.) If you say
66798001
66808002=end original
66818003
6682左辺値として使うことで、C<keys> を使うことで与えられたハッシュに割り当てられた
8004左辺値として使うことで、L<C<keys>|/keys HASH> を使うことで与えられたハッシュに
6683ハッシュ表の大きさを増やすことができます。
8005割り当てられたハッシュ表の大きさを増やすことができます。
66848006これによって、ハッシュが大きくなっていくなっていくときの
66858007効率の測定ができます。
66868008(これは大きい値を $#array に代入することで配列を予め拡張することに
66878009似ています。)
66888010以下のようにすると:
66898011
66908012 keys %hash = 200;
66918013
66928014=begin original
66938015
66948016then C<%hash> will have at least 200 buckets allocated for it--256 of them,
66958017in fact, since it rounds up to the next power of two. These
66968018buckets will be retained even if you do C<%hash = ()>, use C<undef
66978019%hash> if you want to free the storage while C<%hash> is still in scope.
66988020You can't shrink the number of buckets allocated for the hash using
6699C<keys> in this way (but you needn't worry about doing this by accident,
8021L<C<keys>|/keys HASH> in this way (but you needn't worry about doing
6700as trying has no effect). C<keys @array> in an lvalue context is a syntax
8022this by accident, as trying has no effect). C<keys @array> in an lvalue
6701error.
8023context is a syntax error.
67028024
67038025=end original
67048026
6705C<%hash> は少なくとも 200 の大きさの表が割り当てられます --
8027C<%hash> は少なくとも 200 の大きさの表が割り当てられます --
67068028実際には 2 のべき乗に切り上げられるので、256 が割り当てられます。
67078029この表はたとえ C<%hash = ()> としても残るので、
67088030もし C<%hash> がスコープにいるうちにこの領域を開放したい場合は
67098031C<undef %hash> を使います。
6710この方法で C<keys> を使うことで、表の大きさを小さくすることはできません
8032この方法で L<C<keys>|/keys HASH> を使うことで、表の大きさを小さくすることは
8033できません
67118034(間違えてそのようなことをしても何も起きないので気にすることはありません)。
67128035左辺値コンテキストでの C<keys @array> は文法エラーとなります。
67138036
67148037=begin original
67158038
6716Starting with Perl 5.14, C<keys> can take a scalar EXPR, which must contain
8039Starting with Perl 5.14, an experimental feature allowed
6717a reference to an unblessed hash or array. The argument will be
8040L<C<keys>|/keys HASH> to take a scalar expression. This experiment has
6718dereferenced automatically. This aspect of C<keys> is considered highly
8041been deemed unsuccessful, and was removed as of Perl 5.24.
6719experimental. The exact behaviour may change in a future version of Perl.
67208042
67218043=end original
67228044
6723Perl 5.14 から、C<keys> スカラの EXPR を取ることができになりました;
8045Perl 5.14 から、L<C<keys>|/keys HASH> がスカラを取ることが出来とい
6724これは bless されていないハッシュや配列へのリファレンスでなければなりません
8046実験的機能がありました
6725引数自動的にデリファレンスされま
8047この実験失敗と見なされ、Perl 5.24 で削除されした
6726C<keys> のこの動作は高度に実験的であると考えられています。
6727正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
67288048
6729 for (keys $hashref) { ... }
6730 for (keys $obj->get_arrayref) { ... }
6731
67328049=begin original
67338050
67348051To avoid confusing would-be users of your code who are running earlier
67358052versions of Perl with mysterious syntax errors, put this sort of thing at
67368053the top of your file to signal that your code will work I<only> on Perls of
67378054a recent vintage:
67388055
67398056=end original
67408057
67418058あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
67428059文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
67438060I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
67448061書いてください:
67458062
6746 use 5.012; # so keys/values/each work on arrays
8063 use v5.12; # so keys/values/each work on arrays
6747 use 5.014; # so keys/values/each work on scalars (experimental)
67488064
67498065=begin original
67508066
6751See also C<each>, C<values>, and C<sort>.
8067See also L<C<each>|/each HASH>, L<C<values>|/values HASH>, and
8068L<C<sort>|/sort SUBNAME LIST>.
67528069
67538070=end original
67548071
6755C<each>, C<values>, C<sort> も参照してください。
8072L<C<each>|/each HASH>, L<C<values>|/values HASH>,
8073L<C<sort>|/sort SUBNAME LIST> も参照してください。
67568074
67578075=item kill SIGNAL, LIST
67588076
67598077=item kill SIGNAL
67608078X<kill> X<signal>
67618079
67628080=for Pod::Functions send a signal to a process or process group
67638081
67648082=begin original
67658083
6766Sends a signal to a list of processes. Returns the number of
8084Sends a signal to a list of processes. Returns the number of arguments
6767processes successfully signaled (which is not necessarily the
8085that were successfully used to signal (which is not necessarily the same
6768same as the number actually killed).
8086as the number of processes actually killed, e.g. where a process group is
8087killed).
67698088
67708089=end original
67718090
67728091プロセスのリストにシグナルを送ります。
6773シグナル送信に成功しプロセスの数を返します
8092シグナル送信に使われ引数の数を返します
6774(実際に kill に成功しプロセスと同じとは限りません)。
8093(例えばプロセスグループが kill された場合のように、実際に kill され
8094プロセスの数と同じとは限りません)。
67758095
6776 $cnt = kill 'HUP', $child1, $child2;
8096 my $cnt = kill 'HUP', $child1, $child2;
67778097 kill 'KILL', @goners;
67788098
67798099=begin original
67808100
67818101SIGNAL may be either a signal name (a string) or a signal number. A signal
67828102name may start with a C<SIG> prefix, thus C<FOO> and C<SIGFOO> refer to the
67838103same signal. The string form of SIGNAL is recommended for portability because
67848104the same signal may have different numbers in different operating systems.
67858105
67868106=end original
67878107
67888108SIGNAL はシグナル名(文字列)かシグナル番号のどちらかです。
67898109シグナル名は C<SIG> 接頭辞で始まることがあるので、C<FOO> と C<SIGFOO> は同じ
67908110シグナルを意味します。
67918111移植性から文字列形式の SIGNAL が推奨されます; 同じシグナルが異なった
67928112オペレーティングシステムでは異なった番号になることがあるからです。
67938113
67948114=begin original
67958115
67968116A list of signal names supported by the current platform can be found in
6797C<$Config{sig_name}>, which is provided by the C<Config> module. See L<Config>
8117C<$Config{sig_name}>, which is provided by the L<C<Config>|Config>
6798for more details.
8118module. See L<Config> for more details.
67998119
68008120=end original
68018121
6802現在のプラットフォームが対応しているシグナル名の一覧は、C<Config>
8122現在のプラットフォームが対応しているシグナル名の一覧は、L<C<Config>|Config>
68038123モジュールによって提供される C<$Config{sig_name}> にあります。
68048124さらなる詳細については L<Config> を参照してください。
68058125
68068126=begin original
68078127
68088128A negative signal name is the same as a negative signal number, killing process
68098129groups instead of processes. For example, C<kill '-KILL', $pgrp> and
6810C<kill -9, $pgrp> will send C<SIGKILL> to the entire process group specified. That
8130C<kill -9, $pgrp> will send C<SIGKILL> to
8131the entire process group specified. That
68118132means you usually want to use positive not negative signals.
68128133
68138134=end original
68148135
68158136負のシグナル名は負のシグナル番号と同じで、
68168137プロセスではなくプロセスグループに対して kill を行ないます。
68178138たとえば、C<kill '-KILL', $pgrp> と C<kill -9, $pgrp> は指定された
68188139プロセスグループ全体に C<SIGKILL> を送ります。
68198140すなわち、通常は、負のシグナルは用いず、正のシグナルを使うことになります。
68208141
68218142=begin original
68228143
6823If SIGNAL is either the number 0 or the string C<ZERO> (or C<SIGZZERO>),
8144If SIGNAL is either the number 0 or the string C<ZERO> (or C<SIGZERO>),
6824no signal is sent to
8145no signal is sent to the process, but L<C<kill>|/kill SIGNAL, LIST>
6825the process, but C<kill> checks whether it's I<possible> to send a signal to it
8146checks whether it's I<possible> to send a signal to it
68268147(that means, to be brief, that the process is owned by the same user, or we are
68278148the super-user). This is useful to check that a child process is still
68288149alive (even if only as a zombie) and hasn't changed its UID. See
68298150L<perlport> for notes on the portability of this construct.
68308151
68318152=end original
68328153
6833SIGNAL が数値 0 か文字列 C<ZERO> (または C<SIGZZERO> の場合、プロセスに
8154SIGNAL が数値 0 か文字列 C<ZERO> (または C<SIGZERO> の場合、プロセスに
6834シグナルは送られませんが、C<kill> は、シグナルを送ることが I<可能> かどうかを
8155シグナルは送られませんが、L<C<kill>|/kill SIGNAL, LIST> は、
6835調べます (これは、簡単に言うと、プロセスが同じユーザーに所有されているか
8156シグナルを送ることが I<可能> かどうかを調べます (これは、簡単に言うと、
6836自分がスーパーユーザーであることを意味します)。
8157プロセスが同じユーザーに所有されているか、自分がスーパーユーザーであることを
8158意味します)。
68378159これは子プロセスが(ゾンビとしてだけでも)まだ生きていて、 UID が
68388160変わっていないことを調べる時に有用です。
68398161この構成の移植性に関する注意については L<perlport> を参照してください。
68408162
68418163=begin original
68428164
68438165The behavior of kill when a I<PROCESS> number is zero or negative depends on
68448166the operating system. For example, on POSIX-conforming systems, zero will
68458167signal the current process group, -1 will signal all processes, and any
68468168other negative PROCESS number will act as a negative signal number and
68478169kill the entire process group specified.
68488170
68498171=end original
68508172
68518173I<PROCESS> 番号が 0 あるいは負数の場合の kill の振る舞いは
68528174オペレーティングシステムに依存します。
68538175例えば、POSIX 準拠のシステムでは、0 は現在のプロセスグループにシグナルを送り、
68548176-1 は全てのプロセスにシグナルを送り、それ以外の負数の PROCESS 番号は
68558177負数のシグナル番号として動作し、指定されたプロセスグループ全体を kill します。
68568178
68578179=begin original
68588180
68598181If both the SIGNAL and the PROCESS are negative, the results are undefined.
68608182A warning may be produced in a future version.
68618183
68628184=end original
68638185
68648186SIGNAL と PROCESS の両方が負数の場合、結果は未定義です。
68658187将来のバージョンでは警告が出るかも知れません。
68668188
68678189=begin original
68688190
68698191See L<perlipc/"Signals"> for more details.
68708192
68718193=end original
68728194
68738195詳細は L<perlipc/"Signals"> を参照してください。
68748196
68758197=begin original
68768198
6877On some platforms such as Windows where the fork() system call is not available.
8199On some platforms such as Windows where the L<fork(2)> system call is not
6878Perl can be built to emulate fork() at the interpreter level.
8200available, Perl can be built to emulate L<C<fork>|/fork> at the
8201interpreter level.
68798202This emulation has limitations related to kill that have to be considered,
68808203for code running on Windows and in code intended to be portable.
68818204
68828205=end original
68838206
6884Windows のような fork() が利用不能なシステムでは、Perl は fork() を
8207Windows のような L<fork(2)> が利用不能なシステムでは、Perl は
6885インタプリタレベルでエミュレートします。
8208L<C<fork>|/fork> をインタプリタレベルでエミュレートします。
68868209エミュレーションは kill に関連して、コードが Windows で実行されて
68878210しかしコードが移植性があると考えられるように制限があります。
68888211
68898212=begin original
68908213
68918214See L<perlfork> for more details.
68928215
68938216=end original
68948217
68958218さらなる詳細については L<perlfork> を参照してください。
68968219
68978220=begin original
68988221
68998222If there is no I<LIST> of processes, no signal is sent, and the return
69008223value is 0. This form is sometimes used, however, because it causes
6901tainting checks to be run. But see
8224tainting checks to be run, if your perl support taint checks. But see
69028225L<perlsec/Laundering and Detecting Tainted Data>.
69038226
69048227=end original
69058228
69068229処理する I<LIST> がない場合、シグナルは送られず、返り値は 0 です。
6907しかし、この形式は時々使われます; 実行するために汚染チェック
8230しかし、この形式は時々使われます; perl が汚染チェックに対応している場合、
6908引き起こすからです。
8231実行するために汚染チェックを引き起こすからです。
69098232しかし L<perlsec/Laundering and Detecting Tainted Data> を参照してください。
69108233
69118234=begin original
69128235
69138236Portability issues: L<perlport/kill>.
69148237
69158238=end original
69168239
69178240移植性の問題: L<perlport/kill>。
69188241
69198242=item last LABEL
69208243X<last> X<break>
69218244
69228245=item last EXPR
69238246
69248247=item last
69258248
69268249=for Pod::Functions exit a block prematurely
69278250
69288251=begin original
69298252
6930The C<last> command is like the C<break> statement in C (as used in
8253The L<C<last>|/last LABEL> command is like the C<break> statement in C
8254(as used in
69318255loops); it immediately exits the loop in question. If the LABEL is
69328256omitted, the command refers to the innermost enclosing
69338257loop. The C<last EXPR> form, available starting in Perl
693482585.18.0, allows a label name to be computed at run time,
69358259and is otherwise identical to C<last LABEL>. The
6936C<continue> block, if any, is not executed:
8260L<C<continue>|/continue BLOCK> block, if any, is not executed:
69378261
69388262=end original
69398263
6940C<last> コマンドは、(ループ内で使った) C の C<break> 文と
8264L<C<last>|/last LABEL> コマンドは、(ループ内で使った) C の C<break> 文と
69418265同じようなもので、LABEL で指定されるループを即座に抜けます。
69428266LABEL が省略されると、コマンドは一番内側のループを参照します。
69438267Perl 5.18.0 から利用可能な C<last EXPR> 形式では、実行時に計算される
69448268ラベル名を使えます; それ以外は C<last LABEL> と同一です。
6945C<continue> ブロックがあっても実行されません:
8269L<C<continue>|/continue BLOCK> ブロックがあっても実行されません:
69468270
69478271 LINE: while (<STDIN>) {
69488272 last LINE if /^$/; # exit when done with header
69498273 #...
69508274 }
69518275
69528276=begin original
69538277
6954C<last> cannot be used to exit a block that returns a value such as
8278L<C<last>|/last LABEL> cannot return a value from a block that typically
6955C<eval {}>, C<sub {}>, or C<do {}>, and should not be used to exit
8279returns a value, such as C<eval {}>, C<sub {}>, or C<do {}>. It will perform
6956a grep() or map() operation.
8280its flow control behavior, which precludes any return value. It should not be
8281used to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST>
8282operation.
69578283
69588284=end original
69598285
6960C<last> は C<eval {}>, C<sub {}>, C<do {}> といった
8286L<C<last>|/last LABEL> は C<eval {}>, C<sub {}>, C<do {}> といった
6961値を返すブロックを終了するのには使えませんし、
8287典型的には値を返すブロックから値返せません
6962grep() や map() 操作終了するのに使うべきではありせん
8288これは、返り値不可能にするフロー制御振る舞いを実行し
8289L<C<grep>|/grep BLOCK LIST> や L<C<map>|/map BLOCK LIST> 操作を終了するのに
8290使うべきではありません。
69638291
69648292=begin original
69658293
69668294Note that a block by itself is semantically identical to a loop
6967that executes once. Thus C<last> can be used to effect an early
8295that executes once. Thus L<C<last>|/last LABEL> can be used to effect
6968exit out of such a block.
8296an early exit out of such a block.
69698297
69708298=end original
69718299
69728300ブロック自身は一回だけ実行されるループと文法的に同一であることに
69738301注意してください。
6974従って、C<last> でそのようなブロックを途中で抜け出すことができます。
8302従って、L<C<last>|/last LABEL> でそのようなブロックを途中で
8303抜け出すことができます。
69758304
69768305=begin original
69778306
6978See also L</continue> for an illustration of how C<last>, C<next>, and
8307See also L<C<continue>|/continue BLOCK> for an illustration of how
6979C<redo> work.
8308L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and
8309L<C<redo>|/redo LABEL> work.
69808310
69818311=end original
69828312
6983C<last>, C<next>, C<redo> がどのように働くかについては
8313L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL>
6984L</continue> も参照してください。
8314どのように働くかについては L<C<continue>|/continue BLOCK> も参照してください。
69858315
69868316=begin original
69878317
69888318Unlike most named operators, this has the same precedence as assignment.
69898319It is also exempt from the looks-like-a-function rule, so
69908320C<last ("foo")."bar"> will cause "bar" to be part of the argument to
6991C<last>.
8321L<C<last>|/last LABEL>.
69928322
69938323=end original
69948324
69958325ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
69968326また、関数のように見えるものの規則からも免れるので、C<last ("foo")."bar"> と
6997すると "bar" は C<last> への引数の一部となります。
8327すると "bar" は L<C<last>|/last LABEL> への引数の一部となります。
69988328
69998329=item lc EXPR
70008330X<lc> X<lowercase>
70018331
70028332=item lc
70038333
70048334=for Pod::Functions return lower-case version of a string
70058335
70068336=begin original
70078337
7008Returns a lowercased version of EXPR. This is the internal function
8338Returns a lowercased version of EXPR. If EXPR is omitted, uses
7009implementing the C<\L> escape in double-quoted strings.
8339L<C<$_>|perlvar/$_>.
70108340
70118341=end original
70128342
70138343EXPR を小文字に変換したものを返します。
7014は、ダブルクォート文字列における、
8344EXPR が省略されるL<C<$_>|perlvar/$_> を使います。
7015C<\L> エスケープを実装する内部関数です。
70168345
7017=begin original
8346 my $str = lc("Perl is GREAT"); # "perl is great"
70188347
7019If EXPR is omitted, uses C<$_>.
7020
7021=end original
7022
7023EXPR が省略されると、C<$_> を使います。
7024
70258348=begin original
70268349
70278350What gets returned depends on several factors:
70288351
70298352=end original
70308353
70318354返り値として得られるものは色々な要素に依存します:
70328355
70338356=over
70348357
70358358=item If C<use bytes> is in effect:
70368359
70378360(C<use bytes> が有効の場合)
70388361
70398362=begin original
70408363
7041The results follow ASCII semantics. Only characters C<A-Z> change, to C<a-z>
8364The results follow ASCII rules. Only the characters C<A-Z> change,
7042respectively.
8365to C<a-z> respectively.
70438366
70448367=end original
70458368
7046結果は ASCII の意味論に従います。
8369結果は ASCII の規則に従います。
70478370C<A-Z> のみが変換され、それぞれ C<a-z> になります。
70488371
7049=item Otherwise, if C<use locale> (but not C<use locale ':not_characters'>) is in effect:
8372=item Otherwise, if C<use locale> for C<LC_CTYPE> is in effect:
70508373
7051(それ以外の場合で、C<use locale> が有効の(そして C<use locale 'not_characters'> が有効でない)場合)
8374(それ以外の場合で、C<LC_CTYPE> に対して C<use locale> が有効場合)
70528375
70538376=begin original
70548377
7055Respects current LC_CTYPE locale for code points < 256; and uses Unicode
8378Respects current C<LC_CTYPE> locale for code points < 256; and uses Unicode
7056semantics for the remaining code points (this last can only happen if
8379rules for the remaining code points (this last can only happen if
70578380the UTF8 flag is also set). See L<perllocale>.
70588381
70598382=end original
70608383
7061符号位置 < 256 に対しては現在の LC_CTYPE ロケールに従います; そして
8384符号位置 < 256 に対しては現在の C<LC_CTYPE> ロケールに従います; そして
7062残りの符号位置に付いては Unicode の意味論を使います (これは UTF8 フラグも
8385残りの符号位置に付いては Unicode の規則を使います (これは UTF8 フラグも
70638386設定されている場合にのみ起こります)。
70648387L<perllocale> を参照してください。
70658388
70668389=begin original
70678390
7068A deficiency in this is that case changes that cross the 255/256
8391Starting in v5.20, Perl uses full Unicode rules if the locale is
8392UTF-8. Otherwise, there is a deficiency in this scheme, which is that
8393case changes that cross the 255/256
70698394boundary are not well-defined. For example, the lower case of LATIN CAPITAL
7070LETTER SHARP S (U+1E9E) in Unicode semantics is U+00DF (on ASCII
8395LETTER SHARP S (U+1E9E) in Unicode rules is U+00DF (on ASCII
7071platforms). But under C<use locale>, the lower case of U+1E9E is
8396platforms). But under C<use locale> (prior to v5.20 or not a UTF-8
8397locale), the lower case of U+1E9E is
70728398itself, because 0xDF may not be LATIN SMALL LETTER SHARP S in the
70738399current locale, and Perl has no way of knowing if that character even
70748400exists in the locale, much less what code point it is. Perl returns
7075the input character unchanged, for all instances (and there aren't
8401a result that is above 255 (almost always the input character unchanged),
7076many) where the 255/256 boundary would otherwise be crossed.
8402for all instances (and there aren't many) where the 255/256 boundary
8403would otherwise be crossed; and starting in v5.22, it raises a
8404L<locale|perldiag/Can't do %s("%s") on non-UTF-8 locale; resolved to "%s".> warning.
70778405
70788406=end original
70798407
7080これの欠点は、255/266境界をまたぐ大文字小文字の変換は
8408v5.20 から、ロケールが UTF-8 場合は Perl は完全な Unicode の規則使いす。
7081未定義であるとです。
8409さもなければ、の手法には、255/266 の境界をまたぐ大文字小文字の変換は
8410未定義であるという欠点があります。
70828411例えば、Unicode での LATIN CAPITAL LETTER SHARP S (U+1E9E) の小文字は
70838412(ASCII プラットフォームでは) U+00DF です。
7084しかし C<use locale> が有効なら、U+1E9E の小文字は自分自身です; なぜなら
8413しかし C<use locale> が有効(v5.20 より前か、UTF-8 ロケール以外)なら、U+1E9E の
70850xDF は現在のロケールでは LATIN SMALL LETTER SHARP S ではなく、Perl
8414小文字は自分自身です; なぜなら 0xDF は現在のロケールでは
7086例えこのロケールに文字が存在するかどうかを知る方法がなく、まして
8415LATIN SMALL LETTER SHARP S ではなく、Perl は例えこのロケールに文字が
7087どの符号位置かを知る方法がないからです。
8416存在するかうかを知る方法がなく、ましてどの符号位置かを知る方法が
8417ないからです。
70888418Perl は 255/256 境界をまたぐ全ての(多くはありません)実体については
7089入力文字を変更せずに返します
8419(ほとんど常に入力文字を変更せずに)256 以上の値を返します;
8420そして v5.22 から
8421L<locale|perldiag/Can't do %s("%s") on non-UTF-8 locale; resolved to "%s".>
8422警告を出力します。
70908423
70918424=item Otherwise, If EXPR has the UTF8 flag set:
70928425
70938426(その他の場合で、EXPR に UTF8 フラグがセットされている場合)
70948427
70958428=begin original
70968429
7097Unicode semantics are used for the case change.
8430Unicode rules are used for the case change.
70988431
70998432=end original
71008433
7101大文字小文字変換には Unicode の意味論が使われます。
8434大文字小文字変換には Unicode の規則が使われます。
71028435
71038436=item Otherwise, if C<use feature 'unicode_strings'> or C<use locale ':not_characters'> is in effect:
71048437
71058438(それ以外の場合で、C<use feature 'unicode_strings'> か C<use locale ':not_characters'> が有効の場合)
71068439
71078440=begin original
71088441
7109Unicode semantics are used for the case change.
8442Unicode rules are used for the case change.
71108443
71118444=end original
71128445
7113大文字小文字変換には Unicode の意味論が使われます。
8446大文字小文字変換には Unicode の規則が使われます。
71148447
71158448=item Otherwise:
71168449
71178450(それ以外の場合)
71188451
71198452=begin original
71208453
7121ASCII semantics are used for the case change. The lowercase of any character
8454ASCII rules are used for the case change. The lowercase of any character
71228455outside the ASCII range is the character itself.
71238456
71248457=end original
71258458
7126大文字小文字変換には ASCII の意味論が使われます。
8459大文字小文字変換には ASCII の規則が使われます。
71278460ASCII の範囲外の文字の「小文字」はその文字自身です。
71288461
71298462=back
71308463
8464=begin original
8465
8466B<Note:> This is the internal function implementing the
8467L<C<\L>|perlop/"Quote and Quote-like Operators"> escape in double-quoted
8468strings.
8469
8470=end original
8471
8472B<注意:> これは、ダブルクォート文字列における、
8473L<C<\L>|perlop/"Quote and Quote-like Operators"> エスケープを実装する
8474内部関数です。
8475
8476 my $str = "Perl is \LGREAT\E"; # "Perl is great"
8477
71318478=item lcfirst EXPR
71328479X<lcfirst> X<lowercase>
71338480
71348481=item lcfirst
71358482
71368483=for Pod::Functions return a string with just the next letter in lower case
71378484
71388485=begin original
71398486
71408487Returns the value of EXPR with the first character lowercased. This
71418488is the internal function implementing the C<\l> escape in
71428489double-quoted strings.
71438490
71448491=end original
71458492
71468493最初の文字だけを小文字にした、EXPR を返します。
71478494これは、ダブルクォート文字列における、C<\l> エスケープを
71488495実装する内部関数です。
71498496
71508497=begin original
71518498
7152If EXPR is omitted, uses C<$_>.
8499If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
71538500
71548501=end original
71558502
7156EXPR が省略されると、C<$_> を使います。
8503EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
71578504
71588505=begin original
71598506
7160This function behaves the same way under various pragmata, such as in a locale,
8507This function behaves the same way under various pragmas, such as in a locale,
7161as L</lc> does.
8508as L<C<lc>|/lc EXPR> does.
71628509
71638510=end original
71648511
71658512この関数は、ロケールのようなさまざまなプラグマの影響下では、
7166L</lc> と同様に振る舞います。
8513L<C<lc>|/lc EXPR> と同様に振る舞います。
71678514
71688515=item length EXPR
71698516X<length> X<size>
71708517
71718518=item length
71728519
71738520=for Pod::Functions return the number of characters in a string
71748521
71758522=begin original
71768523
71778524Returns the length in I<characters> of the value of EXPR. If EXPR is
7178omitted, returns the length of C<$_>. If EXPR is undefined, returns
8525omitted, returns the length of L<C<$_>|perlvar/$_>. If EXPR is
7179C<undef>.
8526undefined, returns L<C<undef>|/undef EXPR>.
71808527
71818528=end original
71828529
71838530EXPR の値の I<文字> の長さを返します。
7184EXPR が省略されたときには、C<$_> の長さを返します。
8531EXPR が省略されたときには、L<C<$_>|perlvar/$_> の長さを返します。
7185EXPR が未定義値の場合、C<undef> を返します。
8532EXPR が未定義値の場合、L<C<undef>|/undef EXPR> を返します。
71868533
71878534=begin original
71888535
71898536This function cannot be used on an entire array or hash to find out how
71908537many elements these have. For that, use C<scalar @array> and C<scalar keys
71918538%hash>, respectively.
71928539
71938540=end original
71948541
71958542この関数は配列やハッシュ全体に対してどれだけの要素を含んでいるかを
71968543調べるためには使えません。
71978544そのような用途には、それぞれ C<scalar @array> と C<scalar keys %hash> を
71988545利用してください。
71998546
72008547=begin original
72018548
7202Like all Perl character operations, length() normally deals in logical
8549Like all Perl character operations, L<C<length>|/length EXPR> normally
8550deals in logical
72038551characters, not physical bytes. For how many bytes a string encoded as
7204UTF-8 would take up, use C<length(Encode::encode_utf8(EXPR))> (you'll have
8552UTF-8 would take up, use C<length(Encode::encode('UTF-8', EXPR))>
7205to C<use Encode> first). See L<Encode> and L<perlunicode>.
8553(you'll have to C<use Encode> first). See L<Encode> and L<perlunicode>.
72068554
72078555=end original
72088556
7209全ての Perl の文字操作と同様、length() は通常物理的なバイトではなく
8557全ての Perl の文字操作と同様、L<C<length>|/length EXPR> は通常物理的な
7210論理文字を扱います。
8558バイトではなく論理文字を扱います。
72118559UTF-8 でエンコードされた文字列が何バイトかを知るには、
7212C<length(Encode::encode_utf8(EXPR))> を使ってください (先に
8560C<length(Encode::encode('UTF-8', EXPR))> を使ってください (先に
72138561C<use Encode> する必要があります)。
72148562L<Encode> と L<perlunicode> を参照してください。
72158563
72168564=item __LINE__
72178565X<__LINE__>
72188566
72198567=for Pod::Functions the current source line number
72208568
72218569=begin original
72228570
72238571A special token that compiles to the current line number.
8572It can be altered by the mechanism described at
8573L<perlsyn/"Plain Old Comments (Not!)">.
72248574
72258575=end original
72268576
72278577現在の行番号にコンパイルされる特殊トークン。
8578L<perlsyn/"Plain Old Comments (Not!)"> で記述されている機構を使って
8579置き換えられます。
72288580
72298581=item link OLDFILE,NEWFILE
72308582X<link>
72318583
72328584=for Pod::Functions create a hard link in the filesystem
72338585
72348586=begin original
72358587
72368588Creates a new filename linked to the old filename. Returns true for
72378589success, false otherwise.
72388590
72398591=end original
72408592
72418593OLDFILE にリンクされた、新しいファイル NEWFILE を作ります。
72428594成功時には真を、さもなければ偽を返します。
72438595
72448596=begin original
72458597
72468598Portability issues: L<perlport/link>.
72478599
72488600=end original
72498601
72508602移植性の問題: L<perlport/link>。
72518603
72528604=item listen SOCKET,QUEUESIZE
72538605X<listen>
72548606
72558607=for Pod::Functions register your socket as a server
72568608
72578609=begin original
72588610
7259Does the same thing that the listen(2) system call does. Returns true if
8611Does the same thing that the L<listen(2)> system call does. Returns true if
72608612it succeeded, false otherwise. See the example in
72618613L<perlipc/"Sockets: Client/Server Communication">.
72628614
72638615=end original
72648616
7265listen(2) システムコールと同じことをします。
8617L<listen(2)> システムコールと同じことをします。
72668618成功時には真を、さもなければ偽を返します。
72678619L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
72688620
72698621=item local EXPR
72708622X<local>
72718623
72728624=for Pod::Functions create a temporary value for a global variable (dynamic scoping)
72738625
72748626=begin original
72758627
7276You really probably want to be using C<my> instead, because C<local> isn't
8628You really probably want to be using L<C<my>|/my VARLIST> instead,
7277what most people think of as "local". See
8629because L<C<local>|/local EXPR> isn't what most people think of as
7278L<perlsub/"Private Variables via my()"> for details.
8630"local". See L<perlsub/"Private Variables via my()"> for details.
72798631
72808632=end original
72818633
7282あなたはが本当に望んでいるのは C<my> の方でしょう; C<local> はほとんどの
8634あなたはが本当に望んでいるのは L<C<my>|/my VARLIST> の方でしょう;
7283人々が「ローカル」と考えるものと違うからです。
8635L<C<local>|/local EXPR> はほとんどの人々が「ローカル」と考えるものと
7284詳細は L<perlsub/"Private Variables via my()"> を参照してください
8636違うからです
8637詳しくは L<perlsub/"Private Variables via my()"> を参照してください。
72858638
72868639=begin original
72878640
72888641A local modifies the listed variables to be local to the enclosing
72898642block, file, or eval. If more than one value is listed, the list must
72908643be placed in parentheses. See L<perlsub/"Temporary Values via local()">
72918644for details, including issues with tied arrays and hashes.
72928645
72938646=end original
72948647
72958648"local" はリストアップされた変数を、囲っているブロック、
72968649ファイル、eval の中で、ローカルなものにします。
7297複数の値を指定する場合は、リストはかっこでくくらなければなりません。
8650複数の値を指定する場合は、リストはかっこで囲まなければなりません。
72988651tie した配列とハッシュに関する事項を含む詳細については
72998652L<perlsub/"Temporary Values via local()"> を参照してください。
73008653
73018654=begin original
73028655
73038656The C<delete local EXPR> construct can also be used to localize the deletion
73048657of array/hash elements to the current block.
73058658See L<perlsub/"Localized deletion of elements of composite types">.
73068659
73078660=end original
73088661
73098662C<delete local EXPR> 構文は、配列/ハッシュの要素の削除を現在の
73108663ブロックにローカル化するためにも使われていました。
73118664L<perlsub/"Localized deletion of elements of composite types"> を
73128665参照してください。
73138666
73148667=item localtime EXPR
73158668X<localtime> X<ctime>
73168669
73178670=item localtime
73188671
73198672=for Pod::Functions convert UNIX time into record or string using local time
73208673
73218674=begin original
73228675
73238676Converts a time as returned by the time function to a 9-element list
73248677with the time analyzed for the local time zone. Typically used as
73258678follows:
73268679
73278680=end original
73288681
73298682time 関数が返す時刻を、ローカルなタイムゾーンで測った時刻として、
733086839 要素の配列に変換します。
73318684普通は、以下のようにして使います:
73328685
7333 # 0 1 2 3 4 5 6 7 8
8686 # 0 1 2 3 4 5 6 7 8
7334 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
8687 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
73358688 localtime(time);
73368689
73378690=begin original
73388691
73398692All list elements are numeric and come straight out of the C `struct
73408693tm'. C<$sec>, C<$min>, and C<$hour> are the seconds, minutes, and hours
73418694of the specified time.
73428695
73438696=end original
73448697
73458698すべてのリスト要素は数値で、C の `struct tm' 構造体から
73468699直接持ってきます。
73478700C<$sec>, C<$min>, C<$hour> は指定された時刻の秒、分、時です。
73488701
73498702=begin original
73508703
73518704C<$mday> is the day of the month and C<$mon> the month in
73528705the range C<0..11>, with 0 indicating January and 11 indicating December.
73538706This makes it easy to get a month name from a list:
73548707
73558708=end original
73568709
73578710C<$mday> は月の何日目か、C<$mon> は月の値です; 月の値は C<0..11> で、0 が
735887111 月、11 が 12 月です。
73598712これにより、リストから月の名前を得るのが簡単になります:
73608713
73618714 my @abbr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
73628715 print "$abbr[$mon] $mday";
73638716 # $mon=9, $mday=18 gives "Oct 18"
73648717
73658718=begin original
73668719
7367C<$year> contains the number of years since 1900. To get a 4-digit
8720C<$year> contains the number of years since 1900. To get the full
73688721year write:
73698722
73708723=end original
73718724
73728725C<$year> は 1900 年からの年数を持ちます。
73734 桁の年を得るには以下のようにします:
8726完全な年を得るには以下のようにします:
73748727
73758728 $year += 1900;
73768729
73778730=begin original
73788731
73798732To get the last two digits of the year (e.g., "01" in 2001) do:
73808733
73818734=end original
73828735
73838736西暦の下 2 桁(2001 年では "01")がほしい場合は以下のようにします:
73848737
73858738 $year = sprintf("%02d", $year % 100);
73868739
73878740=begin original
73888741
73898742C<$wday> is the day of the week, with 0 indicating Sunday and 3 indicating
73908743Wednesday. C<$yday> is the day of the year, in the range C<0..364>
73918744(or C<0..365> in leap years.)
73928745
73938746=end original
73948747
73958748C<$wday> は曜日で、0 が日曜日、3 が水曜日です。
73968749C<$yday> はその年の何日目かで、C<0..364> の値を取ります
73978750(うるう年は C<0..365> です。)
73988751
73998752=begin original
74008753
7401C<$isdst> is true if the specified time occurs during Daylight Saving
8754C<$isdst> is true if the specified time occurs when Daylight Saving
7402Time, false otherwise.
8755Time is in effect, false otherwise.
74038756
74048757=end original
74058758
7406C<$isdst> は指定された時刻夏時間の場合は真、そうでなければ偽です。
8759C<$isdst> は指定された時刻夏時間が有効の場合は真、そうでなければ偽です。
74078760
74088761=begin original
74098762
7410If EXPR is omitted, C<localtime()> uses the current time (as returned
8763If EXPR is omitted, L<C<localtime>|/localtime EXPR> uses the current
7411by time(3)).
8764time (as returned by L<C<time>|/time>).
74128765
74138766=end original
74148767
7415EXPR が省略されると、C<localtime()> は(time(3) によって返される)
8768EXPR が省略されると、L<C<localtime>|/localtime EXPR> は
7416現在時刻を使います。
8769(L<C<time>|/time> によって返される) 現在時刻を使います。
74178770
74188771=begin original
74198772
7420In scalar context, C<localtime()> returns the ctime(3) value:
8773In scalar context, L<C<localtime>|/localtime EXPR> returns the
8774L<ctime(3)> value:
74218775
74228776=end original
74238777
7424スカラコンテキストでは、C<localtime()> は ctime(3) の値を返します:
8778スカラコンテキストでは、L<C<localtime>|/localtime EXPR> L<ctime(3)> の値を
8779返します:
74258780
7426 $now_string = localtime; # e.g., "Thu Oct 13 04:54:34 1994"
8781 my $now_string = localtime; # e.g., "Thu Oct 13 04:54:34 1994"
74278782
74288783=begin original
74298784
7430The format of this scalar value is B<not> locale-dependent
8785This scalar value is always in English, and is B<not> locale-dependent.
7431but built into Perl. For GMT instead of local
8786To get similar but locale-dependent date strings, try for example:
7432time use the L</gmtime> builtin. See also the
7433C<Time::Local> module (for converting seconds, minutes, hours, and such back to
7434the integer value returned by time()), and the L<POSIX> module's strftime(3)
7435and mktime(3) functions.
74368787
74378788=end original
74388789
7439このスカラ値の形式はロケール依存 B<ではなく>、Perl の組み込みの値です
8790このスカラ値は常に英語で、ロケール依存では B<ありません>。
7440ローカル時刻ではなく GMT がほしい場合は L</gmtime> 組み込み関数を
7441使ってください。
7442また、(秒、分、時などの形から、time() が返す値である
74431970 年 1 月 1 日の真夜中からの秒数に変換する) C<Time::Local> モジュール
7444及び POSIX モジュールで提供される strftime(3) と mktime(3) 関数も
7445参照してください。
7446
7447=begin original
7448
7449To get somewhat similar but locale-dependent date strings, set up your
7450locale environment variables appropriately (please see L<perllocale>) and
7451try for example:
7452
7453=end original
7454
74558791似たような、しかしロケール依存の日付文字列がほしい場合は、
7456ロケール環境変数を適切に設定して(L<perllocale> を参照してください)、
74578792以下の例を試してください:
74588793
7459 use POSIX qw(strftime);
8794 use POSIX qw(strftime);
7460 $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;
8795 my $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;
7461 # or for GMT formatted appropriately for your locale:
8796 # or for GMT formatted appropriately for your locale:
7462 $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime;
8797 my $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime;
74638798
74648799=begin original
74658800
7466Note that the C<%a> and C<%b>, the short forms of the day of the week
8801C$now_string> will be formatted according to the current LC_TIME locale
7467and the month of the year, may not necessarily be three characters wide.
8802the program or thread is running in. See L<perllocale> for how to set
8803up and change that locale. Note that C<%a> and C<%b>, the short forms
8804of the day of the week and the month of the year, may not necessarily be
8805three characters wide.
74688806
74698807=end original
74708808
8809C$now_string> はプログラムやスレッドが実行されている現在の LC_TIME ロケールに
8810従ってフォーマットされます。
8811このロケールの設定と変更の方法については L<perllocale> を参照してください。
74718812曜日と月の短い表現である C<%a> と C<%b> は、3 文字とは限らないことに
74728813注意してください。
74738814
74748815=begin original
74758816
74768817The L<Time::gmtime> and L<Time::localtime> modules provide a convenient,
7477by-name access mechanism to the gmtime() and localtime() functions,
8818by-name access mechanism to the L<C<gmtime>|/gmtime EXPR> and
7478respectively.
8819L<C<localtime>|/localtime EXPR> functions, respectively.
74798820
74808821=end original
74818822
74828823L<Time::gmtime> モジュールと L<Time::localtime> モジュールは、それぞれ
7483gmtime() 関数と localtime() 関数に、名前でアクセスする機構を提供する
8824L<C<gmtime>|/gmtime EXPR> 関数と L<C<localtime>|/localtime EXPR> 関数に、
7484便利なモジュールです。
8825名前でアクセスする機構を提供する便利なモジュールです。
74858826
74868827=begin original
74878828
74888829For a comprehensive date and time representation look at the
74898830L<DateTime> module on CPAN.
74908831
74918832=end original
74928833
74938834包括的な日付と時刻の表現については、CPAN の L<DateTime> モジュールを
74948835参照してください。
74958836
74968837=begin original
74978838
8839For GMT instead of local time use the L<C<gmtime>|/gmtime EXPR> builtin.
8840
8841=end original
8842
8843ローカル時刻ではなく GMT がほしい場合は L<C<gmtime>|/gmtime EXPR> 組み込み
8844関数を使ってください。
8845
8846=begin original
8847
8848See also the L<C<Time::Local>|Time::Local> module (for converting
8849seconds, minutes, hours, and such back to the integer value returned by
8850L<C<time>|/time>), and the L<POSIX> module's
8851L<C<mktime>|POSIX/C<mktime>> function.
8852
8853=end original
8854
8855また、(秒、分、時などの形から、L<C<time>|/time> が返す値である
88561970 年 1 月 1 日の真夜中からの秒数に変換する)
8857L<C<Time::Local>|Time::Local> モジュール及び L<POSIX> モジュールで提供される
8858L<C<mktime>|POSIX/C<mktime>> 関数も参照してください。
8859
8860=begin original
8861
74988862Portability issues: L<perlport/localtime>.
74998863
75008864=end original
75018865
75028866移植性の問題: L<perlport/localtime>。
75038867
75048868=item lock THING
75058869X<lock>
75068870
75078871=for Pod::Functions +5.005 get a thread lock on a variable, subroutine, or method
75088872
75098873=begin original
75108874
75118875This function places an advisory lock on a shared variable or referenced
75128876object contained in I<THING> until the lock goes out of scope.
75138877
75148878=end original
75158879
75168880この関数は I<THING> が含む共有変数またはリファレンスされたオブジェクトに、
75178881スコープから出るまでアドバイサリロックを掛けます.
75188882
75198883=begin original
75208884
75218885The value returned is the scalar itself, if the argument is a scalar, or a
75228886reference, if the argument is a hash, array or subroutine.
75238887
75248888=end original
75258889
75268890返される値は、引数がスカラならそのスカラ自身、引数がハッシュ、配列、
75278891サブルーチンならリファレンスです。
75288892
75298893=begin original
75308894
7531lock() is a "weak keyword" : this means that if you've defined a function
8895L<C<lock>|/lock THING> is a "weak keyword"; this means that if you've
8896defined a function
75328897by this name (before any calls to it), that function will be called
75338898instead. If you are not under C<use threads::shared> this does nothing.
75348899See L<threads::shared>.
75358900
75368901=end original
75378902
7538lock() は「弱いキーワード」です: もしユーザーが(呼び出し前に)
8903L<C<lock>|/lock THING> は「弱いキーワード」です; もしユーザーが(呼び出し前に)
75398904この名前で関数を定義すると、定義された関数の方が呼び出されます。
75408905C<use threads::shared> の影響下でない場合は、これは何もしません。
75418906L<threads::shared> を参照してください。
75428907
75438908=item log EXPR
75448909X<log> X<logarithm> X<e> X<ln> X<base>
75458910
75468911=item log
75478912
75488913=for Pod::Functions retrieve the natural logarithm for a number
75498914
75508915=begin original
75518916
75528917Returns the natural logarithm (base I<e>) of EXPR. If EXPR is omitted,
7553returns the log of C<$_>. To get the
8918returns the log of L<C<$_>|perlvar/$_>. To get the
75548919log of another base, use basic algebra:
75558920The base-N log of a number is equal to the natural log of that number
75568921divided by the natural log of N. For example:
75578922
75588923=end original
75598924
75608925EXPR の (I<e> を底とする) 自然対数を返します。
7561EXPR が省略されると、C<$_> の対数を返します。
8926EXPR が省略されると、L<C<$_>|perlvar/$_> の対数を返します。
75628927底の異なる対数を求めるためには、基礎代数を利用してください:
75638928ある数の N を底とする対数は、その数の自然対数を N の自然対数で割ったものです。
75648929例えば:
75658930
75668931 sub log10 {
75678932 my $n = shift;
75688933 return log($n)/log(10);
75698934 }
75708935
75718936=begin original
75728937
7573See also L</exp> for the inverse operation.
8938See also L<C<exp>|/exp EXPR> for the inverse operation.
75748939
75758940=end original
75768941
7577逆操作については L</exp> を参照してください。
8942逆操作については L<C<exp>|/exp EXPR> を参照してください。
75788943
75798944=item lstat FILEHANDLE
75808945X<lstat>
75818946
75828947=item lstat EXPR
75838948
75848949=item lstat DIRHANDLE
75858950
75868951=item lstat
75878952
75888953=for Pod::Functions stat a symbolic link
75898954
75908955=begin original
75918956
7592Does the same thing as the C<stat> function (including setting the
8957Does the same thing as the L<C<stat>|/stat FILEHANDLE> function
7593special C<_> filehandle) but stats a symbolic link instead of the file
8958(including setting the special C<_> filehandle) but stats a symbolic
7594the symbolic link points to. If symbolic links are unimplemented on
8959link instead of the file the symbolic link points to. If symbolic links
7595your system, a normal C<stat> is done. For much more detailed
8960are unimplemented on your system, a normal L<C<stat>|/stat FILEHANDLE>
7596information, please see the documentation for C<stat>.
8961is done. For much more detailed information, please see the
8962documentation for L<C<stat>|/stat FILEHANDLE>.
75978963
75988964=end original
75998965
76008966(特別なファイルハンドルである C<_> の設定を含めて)
7601C<stat> 関数と同じことをしますが、シンボリックリンクが
8967L<C<stat>|/stat FILEHANDLE> 関数と同じことをしますが、シンボリックリンクが
76028968指しているファイルではなく、シンボリックリンク自体の stat をとります。
7603シンボリックリンクがシステムに実装されていないと、通常の C<stat> が行なわれます。
8969シンボリックリンクがシステムに実装されていないと、通常の
7604さらにより詳細な情報については、L<stat> の文書を参照してください
8970L<C<stat>|/stat FILEHANDLE> が行なわれます
8971さらにより詳細な情報については、L<C<stat>|/stat FILEHANDLE> の文書を
8972参照してください。
76058973
76068974=begin original
76078975
7608If EXPR is omitted, stats C<$_>.
8976If EXPR is omitted, stats L<C<$_>|perlvar/$_>.
76098977
76108978=end original
76118979
7612EXPR が省略されると、C<$_> の stat をとります。
8980EXPR が省略されると、L<C<$_>|perlvar/$_> の stat をとります。
76138981
76148982=begin original
76158983
76168984Portability issues: L<perlport/lstat>.
76178985
76188986=end original
76198987
76208988移植性の問題: L<perlport/lstat>。
76218989
76228990=item m//
76238991
76248992=for Pod::Functions match a string with a regular expression pattern
76258993
76268994=begin original
76278995
76288996The match operator. See L<perlop/"Regexp Quote-Like Operators">.
76298997
76308998=end original
76318999
76329000マッチ演算子です。
76339001L<perlop/"Regexp Quote-Like Operators"> を参照してください。
76349002
76359003=item map BLOCK LIST
76369004X<map>
76379005
76389006=item map EXPR,LIST
76399007
76409008=for Pod::Functions apply a change to a list to get back a new list with the changes
76419009
76429010=begin original
76439011
76449012Evaluates the BLOCK or EXPR for each element of LIST (locally setting
7645C<$_> to each element) and returns the list value composed of the
9013L<C<$_>|perlvar/$_> to each element) and composes a list of the results of
7646results of each such evaluation. In scalar context, returns the
9014each such evaluation. Each element of LIST may produce zero, one, or more
7647total number of elements so generated. Evaluates BLOCK or EXPR in
9015elements in the generated list, so the number of elements in the generated
7648list context, so each element of LIST may produce zero, one, or
9016list may differ from that in LIST. In scalar context, returns the total
7649more elements in the returned value.
9017number of elements so generated. In list context, returns the generated list.
76509018
76519019=end original
76529020
76539021LIST の個々の要素に対して、BLOCK か EXPR を評価し
7654(C<$_> は、ローカルに個々の要素が設定されます) 、
9022(L<C<$_>|perlvar/$_> は、ローカルに個々の要素が設定されます) 、
7655それぞれの評価結果からなるリスト値が返されます。
9023それぞれの評価結果からなるリストを作ります。
9024LIST の個々の要素によって作られる、生成されたリストの要素数は、
90250 個の場合もあれば、複数の場合もあるので、
9026生成されたリストの要素数は LIST の要素数と異なるかも知れません。
76569027スカラコンテキストでは、生成された要素の数を返します。
7657BLOCK や EXPR をリストコンテキストで評価しますので、LIST の
9028リストコンテキストでは、生成されたリストを返します
7658個々の要素によって作られる、返り値であるリストの要素数は、
76590 個の場合もあれば、複数の場合もあります。
76609029
7661 @chars = map(chr, @numbers);
9030 my @chars = map(chr, @numbers);
76629031
76639032=begin original
76649033
76659034translates a list of numbers to the corresponding characters.
76669035
76679036=end original
76689037
76699038は、数のリストを対応する文字に変換します。
76709039
76719040 my @squares = map { $_ * $_ } @numbers;
76729041
76739042=begin original
76749043
76759044translates a list of numbers to their squared values.
76769045
76779046=end original
76789047
76799048これは数値のリストを、その 2 乗に変換します。
76809049
76819050 my @squares = map { $_ > 5 ? ($_ * $_) : () } @numbers;
76829051
76839052=begin original
76849053
76859054shows that number of returned elements can differ from the number of
76869055input elements. To omit an element, return an empty list ().
76879056This could also be achieved by writing
76889057
76899058=end original
76909059
76919060のように、返された要素の数が入力要素の数と異なる場合もあります。
76929061要素を省略するには、空リスト () を返します。
76939062これは以下のように書くことでも達成できて
76949063
76959064 my @squares = map { $_ * $_ } grep { $_ > 5 } @numbers;
76969065
76979066=begin original
76989067
76999068which makes the intention more clear.
77009069
77019070=end original
77029071
77039072この方が目的がよりはっきりします。
77049073
77059074=begin original
77069075
77079076Map always returns a list, which can be
77089077assigned to a hash such that the elements
77099078become key/value pairs. See L<perldata> for more details.
77109079
77119080=end original
77129081
77139082map は常にリストを返し、要素がキー/値の組になるようなハッシュに
77149083代入できます。
77159084さらなる詳細については L<perldata> を参照してください。
77169085
7717 %hash = map { get_a_key_for($_) => $_ } @array;
9086 my %hash = map { get_a_key_for($_) => $_ } @array;
77189087
77199088=begin original
77209089
77219090is just a funny way to write
77229091
77239092=end original
77249093
77259094は以下のものをちょっと変わった書き方で書いたものです。
77269095
7727 %hash = ();
9096 my %hash;
77289097 foreach (@array) {
77299098 $hash{get_a_key_for($_)} = $_;
77309099 }
77319100
77329101=begin original
77339102
7734Note that C<$_> is an alias to the list value, so it can be used to
9103Note that L<C<$_>|perlvar/$_> is an alias to the list value, so it can
7735modify the elements of the LIST. While this is useful and supported,
9104be used to modify the elements of the LIST. While this is useful and
7736it can cause bizarre results if the elements of LIST are not variables.
9105supported, it can cause bizarre results if the elements of LIST are not
7737Using a regular C<foreach> loop for this purpose would be clearer in
9106variables. Using a regular C<foreach> loop for this purpose would be
7738most cases. See also L</grep> for an array composed of those items of
9107clearer in most cases. See also L<C<grep>|/grep BLOCK LIST> for a
7739the original list for which the BLOCK or EXPR evaluates to true.
9108list composed of those items of the original list for which the BLOCK
9109or EXPR evaluates to true.
77409110
77419111=end original
77429112
7743C<$_> は、LIST の値へのエイリアスですので、LIST の要素を
9113L<C<$_>|perlvar/$_> は、LIST の値へのエイリアスですので、LIST の要素を
77449114変更するために使うことができます。
77459115これは、便利でサポートされていますが、
77469116LIST の要素が変数でないと、おかしな結果になります。
77479117この目的には通常の C<foreach> ループを使うことで、ほとんどの場合は
77489118より明確になります。
7749BLOCK や EXPR が真になる元のリストの要素からなる配列については、
9119BLOCK や EXPR が真になる元のリストの要素からなるリストについては、
7750L</grep> も参照してください。
9120L<C<grep>|/grep BLOCK LIST> も参照してください。
77519121
77529122=begin original
77539123
7754If C<$_> is lexical in the scope where the C<map> appears (because it has
7755been declared with the deprecated C<my $_> construct),
7756then, in addition to being locally aliased to
7757the list elements, C<$_> keeps being lexical inside the block; that is, it
7758can't be seen from the outside, avoiding any potential side-effects.
7759
7760=end original
7761
7762(廃止予定の C<my $_> 構文で宣言されることによって) C<$_> が C<map> が現れる
7763スコープ内でレキシカルな場合は、ローカルではリスト要素への
7764エイリアスであることに加えて、C<$_> はブロック内でレキシカルでありつづけます;
7765つまり、外側からは見えず、起こりうる副作用を回避します。
7766
7767=begin original
7768
77699124C<{> starts both hash references and blocks, so C<map { ...> could be either
77709125the start of map BLOCK LIST or map EXPR, LIST. Because Perl doesn't look
77719126ahead for the closing C<}> it has to take a guess at which it's dealing with
77729127based on what it finds just after the
77739128C<{>. Usually it gets it right, but if it
77749129doesn't it won't realize something is wrong until it gets to the C<}> and
77759130encounters the missing (or unexpected) comma. The syntax error will be
77769131reported close to the C<}>, but you'll need to change something near the C<{>
7777such as using a unary C<+> to give Perl some help:
9132such as using a unary C<+> or semicolon to give Perl some help:
77789133
77799134=end original
77809135
77819136C<{> はハッシュリファレンスとブロックの両方の開始文字なので、
77829137C<map { ...> は map BLOCK LIST の場合と map EXPR, LIST の場合があります。
77839138Perl は終了文字の C<}> を先読みしないので、C<{> の直後の文字を見て
77849139どちらとして扱うかを推測します。
77859140通常この推測は正しいですが、もし間違った場合は、C<}> まで読み込んで
77869141カンマが足りない(または多い)ことがわかるまで、何かがおかしいことに
77879142気付きません。
7788C<}> の近くで文法エラーが出ますが、Perl を助けるために単項の C<+>
9143C<}> の近くで文法エラーが出ますが、Perl を助けるために単項の C<+>
7789使うというように、C<{> の近くの何かを変更する必要があります。
9144セミコロンを使うというように、C<{> の近くの何かを変更する必要があります。
77909145
7791 %hash = map { "\L$_" => 1 } @array # perl guesses EXPR. wrong
9146 my %hash = map { "\L$_" => 1 } @array # perl guesses EXPR. wrong
7792 %hash = map { +"\L$_" => 1 } @array # perl guesses BLOCK. right
9147 my %hash = map { +"\L$_" => 1 } @array # perl guesses BLOCK. right
7793 %hash = map { ("\L$_" => 1) } @array # this also works
9148 my %hash = map {; "\L$_" => 1 } @array # this also works
7794 %hash = map { lc($_) => 1 } @array # as does this.
9149 my %hash = map { ("\L$_" => 1) } @array # as does this
7795 %hash = map +( lc($_) => 1 ), @array # this is EXPR and works!
9150 my %hash = map { lc($_) => 1 } @array # and this.
9151 my %hash = map +( lc($_) => 1 ), @array # this is EXPR and works!
77969152
7797 %hash = map ( lc($_), 1 ), @array # evaluates to (1, @array)
9153 my %hash = map ( lc($_), 1 ), @array # evaluates to (1, @array)
77989154
77999155=begin original
78009156
78019157or to force an anon hash constructor use C<+{>:
78029158
78039159=end original
78049160
78059161または C<+{> を使って無名ハッシュコンストラクタを強制します:
78069162
7807 @hashes = map +{ lc($_) => 1 }, @array # EXPR, so needs
9163 my @hashes = map +{ lc($_) => 1 }, @array # EXPR, so needs
7808 # comma at end
9164 # comma at end
78099165
78109166=begin original
78119167
78129168to get a list of anonymous hashes each with only one entry apiece.
78139169
78149170=end original
78159171
78169172こうするとそれぞれ 1 要素だけの無名ハッシュのリストを得られます。
78179173
7818=item mkdir FILENAME,MASK
9174=item method NAME BLOCK
9175X<method>
9176
9177=item method NAME : ATTRS BLOCK
9178
9179=for Pod::Functions declare a method of a class
9180
9181=begin original
9182
9183Creates a new named method in the scope of the class that it appears within.
9184This is only valid inside a L<C<class>|/class NAMESPACE> declaration.
9185
9186=end original
9187
9188Creates a new named method in the scope of the class that it appears within.
9189This is only valid inside a L<C<class>|/class NAMESPACE> declaration.
9190(TBT)
9191
9192=item mkdir FILENAME,MODE
78199193X<mkdir> X<md> X<directory, create>
78209194
78219195=item mkdir FILENAME
78229196
78239197=item mkdir
78249198
78259199=for Pod::Functions create a directory
78269200
78279201=begin original
78289202
78299203Creates the directory specified by FILENAME, with permissions
7830specified by MASK (as modified by C<umask>). If it succeeds it
9204specified by MODE (as modified by L<C<umask>|/umask EXPR>). If it
7831returns true; otherwise it returns false and sets C<$!> (errno).
9205succeeds it returns true; otherwise it returns false and sets
7832MASK defaults to 0777 if omitted, and FILENAME defaults
9206L<C<$!>|perlvar/$!> (errno).
7833to C<$_> if omitted.
9207MODE defaults to 0777 if omitted, and FILENAME defaults
9208to L<C<$_>|perlvar/$_> if omitted.
78349209
78359210=end original
78369211
7837FILENAME で指定したディレクトリを、MASK で指定した許可モード(を
9212FILENAME で指定したディレクトリを、MODE で指定した許可モード(を
7838C<umask> で修正したもの) で作成します。
9213L<C<umask>|/umask EXPR> で修正したもの) で作成します。
7839成功時には真を返します; さもなければ偽を返して C<$!> (errno) を設定します。
9214成功時には真を返します; さもなければ偽を返して
7840MASK を省略すると、0777 とみな
9215L<C<$!>|perlvar/$!> (errno) を設定ます。
7841FILENAME を省略すると、C<$_> を使います。
9216MODE を省略すると、0777 とみなし、
9217FILENAME を省略すると、L<C<$_>|perlvar/$_> を使います。
78429218
78439219=begin original
78449220
7845In general, it is better to create directories with a permissive MASK
9221In general, it is better to create directories with a permissive MODE
7846and let the user modify that with their C<umask> than it is to supply
9222and let the user modify that with their L<C<umask>|/umask EXPR> than it
7847a restrictive MASK and give the user no way to be more permissive.
9223is to supply
9224a restrictive MODE and give the user no way to be more permissive.
78489225The exceptions to this rule are when the file or directory should be
7849kept private (mail files, for instance). The perlfunc(1) entry on
9226kept private (mail files, for instance). The documentation for
7850C<umask> discusses the choice of MASK in more detail.
9227L<C<umask>|/umask EXPR> discusses the choice of MODE in more detail.
9228If bits in MODE other than the permission bits are set, the result may
9229be implementation defined, per POSIX 1003.1-2008.
78519230
78529231=end original
78539232
7854一般的に、制限された MASK を使ってユーザーがより寛容にする方法を
9233一般的に、制限された MODE を使ってユーザーがより寛容にする方法を
7855与えないより、寛容な MASK でディレクトリを作り、ユーザーが自身の C<umask> で
9234与えないより、寛容な MODE でディレクトリを作り、ユーザーが自身の
7856修正するようにした方がよいです。
9235L<C<umask>|/umask EXPR> で修正するようにした方がよいです。
78579236例外は、(例えばメールファイルのような)プライベートに保つべきファイルや
78589237ディレクトリを書く場合です。
7859perlfunc(1) の C<umask> で、MASK の選択に関して詳細に議論しています。
9238L<C<umask>|/umask EXPR> の文書で、MODE の選択に関して詳細に議論しています。
9239If bits in MODE other than the permission bits are set, the result may
9240be implementation defined, per POSIX 1003.1-2008.
9241(TBT)
78609242
78619243=begin original
78629244
78639245Note that according to the POSIX 1003.1-1996 the FILENAME may have any
78649246number of trailing slashes. Some operating and filesystems do not get
78659247this right, so Perl automatically removes all trailing slashes to keep
78669248everyone happy.
78679249
78689250=end original
78699251
78709252POSIX 1003.1-1996 によれば、FILENAME には末尾に任意の数のスラッシュを
78719253つけることができます。
78729254このようには動かない OS やファイルシステムもあるので、Perl はみんなが
78739255幸せになれるように、自動的に末尾のスラッシュを削除します。
78749256
78759257=begin original
78769258
78779259To recursively create a directory structure, look at
7878the C<mkpath> function of the L<File::Path> module.
9260the L<C<make_path>|File::Path/make_path( $dir1, $dir2, .... )> function
9261of the L<File::Path> module.
78799262
78809263=end original
78819264
78829265ディレクトリ構造を再帰的に作成するには、L<File::Path> モジュールの
7883C<makepath> 関数を参照してください。
9266L<C<make_path>|File::Path/make_path( $dir1, $dir2, .... )> 関数を
9267参照してください。
78849268
78859269=item msgctl ID,CMD,ARG
78869270X<msgctl>
78879271
78889272=for Pod::Functions SysV IPC message control operations
78899273
78909274=begin original
78919275
7892Calls the System V IPC function msgctl(2). You'll probably have to say
9276Calls the System V IPC function L<msgctl(2)>. You'll probably have to say
78939277
78949278=end original
78959279
7896System V IPC 関数 msgctl を呼び出します。
9280System V IPC 関数 L<msgctl(2)> を呼び出します。
78979281正しい定数定義を得るために、まず
78989282
78999283 use IPC::SysV;
79009284
79019285=begin original
79029286
79039287first to get the correct constant definitions. If CMD is C<IPC_STAT>,
79049288then ARG must be a variable that will hold the returned C<msqid_ds>
7905structure. Returns like C<ioctl>: the undefined value for error,
9289structure. Returns like L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>:
7906C<"0 but true"> for zero, or the actual return value otherwise. See also
9290the undefined value for error, C<"0 but true"> for zero, or the actual
7907L<perlipc/"SysV IPC"> and the documentation for C<IPC::SysV> and
9291return value otherwise. See also L<perlipc/"SysV IPC"> and the
7908C<IPC::Semaphore>.
9292documentation for L<C<IPC::SysV>|IPC::SysV> and
9293L<C<IPC::Semaphore>|IPC::Semaphore>.
79099294
79109295=end original
79119296
79129297と書くことが必要でしょう。
79139298CMD が C<IPC_STAT> であれば、ARG は返される C<msqid_ds> 構造体を
79149299納める変数でなければなりません。
7915C<ioctl> と同じように、エラー時には未定義値、
9300L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同じように、エラー時には
7916ゼロのときは C<"0 but true">、それ以外なら、その値そのものを返します。
9301未定義値、ゼロのときは C<"0 but true">、それ以外なら、その値そのものを
7917L<perlipc/"SysV IPC"> および、C<IPC::SysV>, C<IPC::Semaphore> の文書も
9302返します。
7918参照してください。
9303L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV> と
9304L<C<IPC::Semaphore>|IPC::Semaphore> の文書も参照してください。
79199305
79209306=begin original
79219307
79229308Portability issues: L<perlport/msgctl>.
79239309
79249310=end original
79259311
79269312移植性の問題: L<perlport/msgctl>。
79279313
79289314=item msgget KEY,FLAGS
79299315X<msgget>
79309316
79319317=for Pod::Functions get SysV IPC message queue
79329318
79339319=begin original
79349320
7935Calls the System V IPC function msgget(2). Returns the message queue
9321Calls the System V IPC function L<msgget(2)>. Returns the message queue
7936id, or C<undef> on error. See also
9322id, or L<C<undef>|/undef EXPR> on error. See also L<perlipc/"SysV IPC">
7937L<perlipc/"SysV IPC"> and the documentation for C<IPC::SysV> and
9323and the documentation for L<C<IPC::SysV>|IPC::SysV> and
7938C<IPC::Msg>.
9324L<C<IPC::Msg>|IPC::Msg>.
79399325
79409326=end original
79419327
7942System V IPC 関数 msgget を呼び出します。
9328System V IPC 関数 L<msgget(2)> を呼び出します。
7943メッセージキューの ID か、エラー時には C<undef> を返します。
9329メッセージキューの ID か、エラー時には L<C<undef>|/undef EXPR> を返します。
7944L<perlipc/"SysV IPC"> よび、C<IPC::SysV>, C<IPC::Msg> の文書も
9330L<perlipc/"SysV IPC"> よび、L<C<IPC::SysV>|IPC::SysV>
7945参照してください。
9331L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。
79469332
79479333=begin original
79489334
79499335Portability issues: L<perlport/msgget>.
79509336
79519337=end original
79529338
79539339移植性の問題: L<perlport/msgget>。
79549340
79559341=item msgrcv ID,VAR,SIZE,TYPE,FLAGS
79569342X<msgrcv>
79579343
79589344=for Pod::Functions receive a SysV IPC message from a message queue
79599345
79609346=begin original
79619347
79629348Calls the System V IPC function msgrcv to receive a message from
79639349message queue ID into variable VAR with a maximum message size of
79649350SIZE. Note that when a message is received, the message type as a
79659351native long integer will be the first thing in VAR, followed by the
79669352actual message. This packing may be opened with C<unpack("l! a*")>.
7967Taints the variable. Returns true if successful, false
9353Taints the variable. Returns true if successful, false
79689354on error. See also L<perlipc/"SysV IPC"> and the documentation for
7969C<IPC::SysV> and C<IPC::SysV::Msg>.
9355L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Msg>|IPC::Msg>.
79709356
79719357=end original
79729358
79739359System V IPC 関数 msgrcv を呼び出し、メッセージキュー ID から、
79749360変数 VAR に最大メッセージ長 SIZE のメッセージを受信します。
79759361メッセージが受信された時、ネイティブな long 整数のメッセージタイプが
79769362VAR の先頭となり、実際のメッセージが続きます。
79779363このパッキングは C<unpack("l! a*")> で展開できます。
79789364変数は汚染されます。
79799365成功時には真を、エラー時には偽を返します。
7980L<perlipc/"SysV IPC"> および、C<IPC::SysV>, C<IPC::SysV::Msg> の文書も
9366L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>
7981参照してください。
9367L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。
79829368
79839369=begin original
79849370
79859371Portability issues: L<perlport/msgrcv>.
79869372
79879373=end original
79889374
79899375移植性の問題: L<perlport/msgrcv>。
79909376
79919377=item msgsnd ID,MSG,FLAGS
79929378X<msgsnd>
79939379
79949380=for Pod::Functions send a SysV IPC message to a message queue
79959381
79969382=begin original
79979383
79989384Calls the System V IPC function msgsnd to send the message MSG to the
79999385message queue ID. MSG must begin with the native long integer message
8000type, be followed by the length of the actual message, and then finally
9386type, followed by the message itself. This kind of packing can be achieved
8001the message itself. This kind of packing can be achieved with
9387with C<pack("l! a*", $type, $message)>. Returns true if successful,
8002C<pack("l! a*", $type, $message)>. Returns true if successful,
9388false on error. See also L<perlipc/"SysV IPC"> and the documentation
8003false on error. See also the C<IPC::SysV>
9389for L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Msg>|IPC::Msg>.
8004and C<IPC::SysV::Msg> documentation.
80059390
80069391=end original
80079392
80089393System V IPC 関数 msgsnd を呼び出し、メッセージキュー ID に
80099394メッセージ MSG を送信します。
8010MSG の先頭は、ネイティブなlong 整数のメッセージタイプでなければならず、
9395MSG の先頭は、ネイティブな long 整数のメッセージタイプでなければならず、
8011メッセージの長さ、メッセージ本体続きます。
9396メッセージ本体続きます。
80129397これは、C<pack("l! a*", $type, $message)> として生成できます。
80139398成功時には真を、エラー時には偽を返します。
8014C<IPC::SysV> C<IPC::SysV::Msg> の文書も参照してください。
9399L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>
9400L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。
80159401
80169402=begin original
80179403
80189404Portability issues: L<perlport/msgsnd>.
80199405
80209406=end original
80219407
80229408移植性の問題: L<perlport/msgsnd>。
80239409
8024=item my EXPR
9410=item my VARLIST
80259411X<my>
80269412
8027=item my TYPE EXPR
9413=item my TYPE VARLIST
80289414
8029=item my EXPR : ATTRS
9415=item my VARLIST : ATTRS
80309416
8031=item my TYPE EXPR : ATTRS
9417=item my TYPE VARLIST : ATTRS
80329418
80339419=for Pod::Functions declare and assign a local variable (lexical scoping)
80349420
80359421=begin original
80369422
8037A C<my> declares the listed variables to be local (lexically) to the
9423A L<C<my>|/my VARLIST> declares the listed variables to be local
8038enclosing block, file, or C<eval>. If more than one value is listed,
9424(lexically) to the enclosing block, file, or L<C<eval>|/eval EXPR>. If
8039the list must be placed in parentheses.
9425more than one variable is listed, the list must be placed in
9426parentheses.
80409427
80419428=end original
80429429
8043C<my> はリストアップされた変数を、囲っているブロック、ファイル、
9430L<C<my>|/my VARLIST> はリストアップされた変数を、囲っているブロック、ファイル、
8044C<eval> の中でローカルな (レキシカルな) ものにします。
9431L<C<eval>|/eval EXPR> の中でローカルな (レキシカルな) ものにします。
8045複数のを指定する場合は、リストはかっこでくくらなければなりません。
9432複数の変数を指定する場合は、リストはかっこで囲まなければなりません。
80469433
80479434=begin original
80489435
9436Note that with a parenthesised list, L<C<undef>|/undef EXPR> can be used
9437as a dummy placeholder, for example to skip assignment of initial
9438values:
9439
9440=end original
9441
9442かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> は、例えば初期値の代入を
9443飛ばすために、ダミーのプレースホルダとして使えることに注意してください:
9444
9445 my ( undef, $min, $hour ) = localtime;
9446
9447=begin original
9448
9449Redeclaring a variable in the same scope or statement will "shadow" the
9450previous declaration, creating a new instance and preventing access to
9451the previous one. This is usually undesired and, if warnings are enabled,
9452will result in a warning in the C<shadow> category.
9453
9454=end original
9455
9456同じスコープや文で変数を再宣言すると、以前の宣言を「隠し」、
9457新しい実体を作って、以前の実体にアクセスできなくなります。
9458これは普通は望まれているものではなく、警告が有効なら、
9459C<shadow> カテゴリの警告が出ます。
9460
9461=begin original
9462
80499463The exact semantics and interface of TYPE and ATTRS are still
8050evolving. TYPE is currently bound to the use of the C<fields> pragma,
9464evolving. TYPE may be a bareword, a constant declared
8051and attributes are handled using the C<attributes> pragma, or starting
9465with L<C<use constant>|constant>, or L<C<__PACKAGE__>|/__PACKAGE__>. It
8052from Perl 5.8.0 also via the C<Attribute::Handlers> module. See
9466is
8053L<perlsub/"Private Variables via my()"> for details, and L<fields>,
9467currently bound to the use of the L<fields> pragma,
8054L<attributes>, and L<Attribute::Handlers>.
9468and attributes are handled using the L<attributes> pragma, or starting
9469from Perl 5.8.0 also via the L<Attribute::Handlers> module. See
9470L<perlsub/"Private Variables via my()"> for details.
80559471
80569472=end original
80579473
80589474TYPE と ATTRS の正確な文法とインターフェースは今でも進化しています。
8059現在のところ、TYPE は C<fields> プラグマの使用と結び付けらていて
9475TYPE は、裸の単語、L<C<use constant>|constant> で宣言さた定数
8060属性は C<attributes> プラグマか、Perl 5.8.0 らは
9476L<C<__PACKAGE__>|/__PACKAGE__> のいずれです。
8061C<Attribute::Handlers> モジュールと結び付けられています。
9477現在のところ、TYPE は L<fields> プラグマの使用と結び付けられていて、
8062詳しくはL<perlsub/"Private Variables via my()">, L<fields>,
9478属性 L<attributes> プラグマか、Perl 5.8.0 からは
8063L<attributes>, L<Attribute::Handlers> を参照しください。
9479L<Attribute::Handlers> モジュールと結び付けられています
9480詳しくは L<perlsub/"Private Variables via my()"> を参照してください。
80649481
80659482=item next LABEL
80669483X<next> X<continue>
80679484
80689485=item next EXPR
80699486
80709487=item next
80719488
80729489=for Pod::Functions iterate a block prematurely
80739490
80749491=begin original
80759492
8076The C<next> command is like the C<continue> statement in C; it starts
9493The L<C<next>|/next LABEL> command is like the C<continue> statement in
8077the next iteration of the loop:
9494C; it starts the next iteration of the loop:
80789495
80799496=end original
80809497
8081C<next> コマンドは、C での C<continue> 文のようなもので、
9498L<C<next>|/next LABEL> コマンドは、C での C<continue> 文のようなもので、
80829499ループの次の繰り返しを開始します:
80839500
80849501 LINE: while (<STDIN>) {
80859502 next LINE if /^#/; # discard comments
80869503 #...
80879504 }
80889505
80899506=begin original
80909507
8091Note that if there were a C<continue> block on the above, it would get
9508Note that if there were a L<C<continue>|/continue BLOCK> block on the
9509above, it would get
80929510executed even on discarded lines. If LABEL is omitted, the command
80939511refers to the innermost enclosing loop. The C<next EXPR> form, available
80949512as of Perl 5.18.0, allows a label name to be computed at run time, being
80959513otherwise identical to C<next LABEL>.
80969514
80979515=end original
80989516
8099C<continue> ブロックが存在すれば、たとえ捨てられる行に
9517L<C<continue>|/continue BLOCK> ブロックが存在すれば、たとえ捨てられる行に
81009518あっても、それが実行されます。
81019519LABEL が省略されると、コマンドは一番内側のループを参照します。
81029520Perl 5.18.0 から利用可能な C<next EXPR> 形式では、実行時に計算される
81039521ラベル名が使えます; それ以外は C<next LABEL> と同一です。
81049522
81059523=begin original
81069524
8107C<next> cannot be used to exit a block which returns a value such as
9525L<C<next>|/next LABEL> cannot return a value from a block that typically
8108C<eval {}>, C<sub {}>, or C<do {}>, and should not be used to exit
9526returns a value, such as C<eval {}>, C<sub {}>, or C<do {}>. It will perform
8109a grep() or map() operation.
9527its flow control behavior, which precludes any return value. It should not be
9528used to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST>
9529operation.
81109530
81119531=end original
81129532
8113C<next> は C<eval {}>, C<sub {}>, C<do {}> のように値を返すブロックから
9533L<C<next>|/next LABEL> は C<eval {}>, C<sub {}>, C<do {}> といった
8114抜けるのには使えません; また、grep() や map() 操作から抜けるのに
9534典型的には値を返すブロックから値を返せません
9535これは、返り値を不可能にするフロー制御の振る舞いを実行します。
9536L<C<grep>|/grep BLOCK LIST> や L<C<map>|/map BLOCK LIST> 操作を終了するのに
81159537使うべきではありません。
81169538
81179539=begin original
81189540
81199541Note that a block by itself is semantically identical to a loop
8120that executes once. Thus C<next> will exit such a block early.
9542that executes once. Thus L<C<next>|/next LABEL> will exit such a block
9543early.
81219544
81229545=end original
81239546
81249547ブロック自身は一回だけ実行されるループと文法的に同一であることに
81259548注意してください。
8126従って、C<next> はそのようなブロックから早く抜けるのに使えます。
9549従って、L<C<next>|/next LABEL> はそのようなブロックから早く抜けるのに使えます。
81279550
81289551=begin original
81299552
8130See also L</continue> for an illustration of how C<last>, C<next>, and
9553See also L<C<continue>|/continue BLOCK> for an illustration of how
8131C<redo> work.
9554L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and
9555L<C<redo>|/redo LABEL> work.
81329556
81339557=end original
81349558
8135C<last>, C<next>, C<redo> がどのように働くかについては
9559L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL>
8136L</continue> も参照してください。
9560どのように働くかについては L<C<continue>|/continue BLOCK> も参照してください。
81379561
81389562=begin original
81399563
81409564Unlike most named operators, this has the same precedence as assignment.
81419565It is also exempt from the looks-like-a-function rule, so
81429566C<next ("foo")."bar"> will cause "bar" to be part of the argument to
8143C<next>.
9567L<C<next>|/next LABEL>.
81449568
81459569=end original
81469570
81479571ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
81489572また、関数のように見えるものの規則からも免れるので、C<next ("foo")."bar"> と
8149すると "bar" は C<next> への引数の一部となります。
9573すると "bar" は L<C<next>|/next LABEL> への引数の一部となります。
81509574
81519575=item no MODULE VERSION LIST
81529576X<no declarations>
81539577X<unimporting>
81549578
81559579=item no MODULE VERSION
81569580
81579581=item no MODULE LIST
81589582
81599583=item no MODULE
81609584
81619585=item no VERSION
81629586
81639587=for Pod::Functions unimport some module symbols or semantics at compile time
81649588
81659589=begin original
81669590
8167See the C<use> function, of which C<no> is the opposite.
9591See the L<C<use>|/use Module VERSION LIST> function, of which
9592L<C<no>|/no MODULE VERSION LIST> is the opposite.
81689593
81699594=end original
81709595
8171L<use> 関数を参照してください; C<no> は、その逆を行なうものです。
9596L<C<use>|/use Module VERSION LIST> 関数を参照してください;
9597L<C<no>|/no MODULE VERSION LIST> は、その逆を行なうものです。
81729598
81739599=item oct EXPR
81749600X<oct> X<octal> X<hex> X<hexadecimal> X<binary> X<bin>
81759601
81769602=item oct
81779603
81789604=for Pod::Functions convert a string to an octal number
81799605
81809606=begin original
81819607
81829608Interprets EXPR as an octal string and returns the corresponding
8183value. (If EXPR happens to start off with C<0x>, interprets it as a
9609value. An octal string consists of octal digits and, as of Perl 5.33.5,
8184hex string. If EXPR starts off with C<0b>, it is interpreted as a
9610an optional C<0o> or C<o> prefix. Each octal digit may be preceded by
9611a single underscore, which will be ignored.
9612(If EXPR happens to start off with C<0x> or C<x>, interprets it as a
9613hex string. If EXPR starts off with C<0b> or C<b>, it is interpreted as a
81859614binary string. Leading whitespace is ignored in all three cases.)
81869615The following will handle decimal, binary, octal, and hex in standard
81879616Perl notation:
81889617
81899618=end original
81909619
81919620EXPR を 8 進数文字列と解釈して、対応する値を返します。
8192(EXPR が C<0x> で始まるときには、16文字解釈します。
96218 進数文字列は、8 進文字と、Perl 5.33.5 からはオプションの
8193EXPR が C<0b>で始るとき、2 進数文字列と解釈します。
9622C<0o> C<o> 接頭辞からなります。
9623各 8 進文字の前には一つの下線を置くことができ、これは無視されます。
9624(EXPR が C<0x> か C<x> で始まるときには、16 進数文字列と解釈します。
9625EXPR が C<0b> か C<b> で始まるときは、2 進数文字列と解釈します。
81949626どの場合でも、先頭の空白は無視されます。)
81959627以下の例は、標準的な Perl の記法での
8196962810 進数、2 進数、8 進数、16 進数を扱います:
81979629
81989630 $val = oct($val) if $val =~ /^0/;
81999631
82009632=begin original
82019633
8202If EXPR is omitted, uses C<$_>. To go the other way (produce a number
9634If EXPR is omitted, uses L<C<$_>|perlvar/$_>. To go the other way
8203in octal), use sprintf() or printf():
9635(produce a number in octal), use L<C<sprintf>|/sprintf FORMAT, LIST> or
9636L<C<printf>|/printf FILEHANDLE FORMAT, LIST>:
82049637
82059638=end original
82069639
8207EXPR が省略されると、C<$_> を使います。
9640EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
8208(8 進数を扱う)その他の方法としては sprintf() または printf()があります。
9641(8 進数を扱う)その他の方法としては L<C<sprintf>|/sprintf FORMAT, LIST> や
9642L<C<printf>|/printf FILEHANDLE FORMAT, LIST> があります:
82099643
8210 $dec_perms = (stat("filename"))[2] & 07777;
9644 my $dec_perms = (stat("filename"))[2] & 07777;
8211 $oct_perm_str = sprintf "%o", $perms;
9645 my $oct_perm_str = sprintf "%o", $perms;
82129646
82139647=begin original
82149648
8215The oct() function is commonly used when a string such as C<644> needs
9649The L<C<oct>|/oct EXPR> function is commonly used when a string such as
8216to be converted into a file mode, for example. Although Perl
9650C<644> needs
9651to be converted into a file mode, for example. Although Perl
82179652automatically converts strings into numbers as needed, this automatic
82189653conversion assumes base 10.
82199654
82209655=end original
82219656
8222oct() 関数は例えば、 C<644> といった文字列をファイルモードに変換する時
9657L<C<oct>|/oct EXPR> 関数は例えば、 C<644> といった文字列をファイルモードに
8223よく使います。
9658変換する時によく使います。
82249659Perl は必要に応じて自動的に文字列を数値に変換しますが、
82259660この自動変換は十進数を仮定します。
82269661
82279662=begin original
82289663
8229Leading white space is ignored without warning, as too are any trailing
9664Leading white space is ignored without warning, as too are any trailing
8230non-digits, such as a decimal point (C<oct> only handles non-negative
9665non-digits, such as a decimal point (L<C<oct>|/oct EXPR> only handles
8231integers, not negative integers or floating point).
9666non-negative integers, not negative integers or floating point).
82329667
82339668=end original
82349669
82359670先頭の空白や、末尾の(小数点のような)非数字は警告なしに無視されます
8236(C<oct> は非負整数のみを扱えます; 負の整数や小数は扱えません)。
9671(L<C<oct>|/oct EXPR> は非負整数のみを扱えます; 負の整数や小数は扱えません)。
82379672
8238=item open FILEHANDLE,EXPR
8239X<open> X<pipe> X<file, open> X<fopen>
82409673
82419674=item open FILEHANDLE,MODE,EXPR
9675X<open> X<pipe> X<file, open> X<fopen>
82429676
82439677=item open FILEHANDLE,MODE,EXPR,LIST
82449678
82459679=item open FILEHANDLE,MODE,REFERENCE
82469680
9681=item open FILEHANDLE,EXPR
9682
82479683=item open FILEHANDLE
82489684
82499685=for Pod::Functions open a file, pipe, or descriptor
82509686
82519687=begin original
82529688
8253Opens the file whose filename is given by EXPR, and associates it with
9689Associates an internal FILEHANDLE with the external file specified by
8254FILEHANDLE.
9690EXPR. That filehandle will subsequently allow you to perform
9691I/O operations on that file, such as reading from it or writing to it.
82559692
82569693=end original
82579694
8258EXPR で与えられたファイル名ファイルを開き、FILEHANDLE と結び付けます。
9695内部 FILEHANDLE を、EXPR で指定された外部ファイルに関連付けます。
9696このファイルハンドルはその後、読んだり書いたりといったそのファイルへの
9697I/O 操作をできるようにします。
82599698
82609699=begin original
82619700
8262Simple examples to open a file for reading:
9701Instead of a filename, you may specify an external command
9702(plus an optional argument list) or a scalar reference, in order to open
9703filehandles on commands or in-memory scalars, respectively.
82639704
82649705=end original
82659706
8266読み込みためにファイルを開くための簡単な例は以下のもので:
9707ファイル名代わり、コマンドやメモリ内スカラへのファイルハンドル
9708開くために、外部コマンド (とオプションの引数リスト) やスカラリファレンスを
9709指定できます。
82679710
8268 open(my $fh, "<", "input.txt")
9711=begin original
8269 or die "cannot open < input.txt: $!";
82709712
9713A thorough reference to C<open> follows. For a gentler introduction to
9714the basics of C<open>, see also the L<perlopentut> manual page.
9715
9716=end original
9717
9718C<open> の完全なリファレンスは後述します。
9719C<open> の基本に関するより親切な導入に関しては、
9720L<perlopentut> man ページも参照してください。
9721
9722=over
9723
9724=item Working with files
9725
82719726=begin original
82729727
8273and for writing:
9728Most often, C<open> gets invoked with three arguments: the required
9729FILEHANDLE (usually an empty scalar variable), followed by MODE (usually
9730a literal describing the I/O mode the filehandle will use), and then the
9731filename that the new filehandle will refer to.
82749732
82759733=end original
82769734
8277書き込み用は以下ものです:
9735ほとんど場合、C<open> は 3 引数起動されます:
9736必須の FILEHANDLE (通常は空のスカラ変数), 引き続いて MODE (通常は
9737ファイルハンドルを使う I/O モードを記述するリテラル)、
9738それから新しいファイルハンドルが参照するファイル名です。
82789739
8279 open(my $fh, ">", "output.txt")
9740=over
8280 or die "cannot open > output.txt: $!";
82819741
9742=item Simple examples
9743
9744(単純な例)
9745
82829746=begin original
82839747
8284(The following is a comprehensive reference to open(): for a gentler
9748Reading from a file:
8285introduction you may consider L<perlopentut>.)
82869749
82879750=end original
82889751
8289(以下は総合的な open() のリファレンスです: より親切な説明については
9752ファイルからの読み込み:
8290L<perlopentut> を参照してください。)
82919753
9754 open(my $fh, "<", "input.txt")
9755 or die "Can't open < input.txt: $!";
9756
9757 # Process every line in input.txt
9758 while (my $line = readline($fh)) {
9759 #
9760 # ... do something interesting with $line here ...
9761 #
9762 }
9763
82929764=begin original
82939765
8294If FILEHANDLE is an undefined scalar variable (or array or hash element), a
9766or writing to one:
8295new filehandle is autovivified, meaning that the variable is assigned a
8296reference to a newly allocated anonymous filehandle. Otherwise if
8297FILEHANDLE is an expression, its value is the real filehandle. (This is
8298considered a symbolic reference, so C<use strict "refs"> should I<not> be
8299in effect.)
83009767
83019768=end original
83029769
8303FILEHANDLE が未定義のスカラ変数(または配列かハッシュの要素)の場合、
9770そして書き込み:
8304新しいファイルハンドルが自動有効化され、その変数は新しく割り当てられた
8305無名ファイルハンドルへのリファレンスが代入されます。
8306さもなければ、もし FILEHANDLE が式なら、その値を求めている実際の
8307ファイルハンドルの名前として使います。
8308(これはシンボリックリファレンスとして扱われるので、
8309C<use strict "refs"> の影響を I<受けません>。)
83109771
9772 open(my $fh, ">", "output.txt")
9773 or die "Can't open > output.txt: $!";
9774
9775 print $fh "This line gets printed into output.txt.\n";
9776
83119777=begin original
83129778
8313If EXPR is omitted, the global (package) scalar variable of the same
9779For a summary of common filehandle operations such as these, see
8314name as the FILEHANDLE contains the filename. (Note that lexical
9780L<perlintro/Files and I/O>.
8315variables--those declared with C<my> or C<state>--will not work for this
8316purpose; so if you're using C<my> or C<state>, specify EXPR in your
8317call to open.)
83189781
83199782=end original
83209783
8321EXPR が省略された場合、FILEHANDLE と同じ名前グローバ(パッケージ)
9784ような基本的なファイハンドル操作の要約については、
8322スカラ変数にファイル名が入っています
9785L<perlintro/Files and I/O> を参照しください。
8323(レキシカル変数 -- C<my> や C<state> で宣言されたもの -- はこの用途には
8324使えないことに注意してください; 従って、C<my> や C<state> を使っている場合は、
8325open を呼び出すときに EXPR を指定してください。)
83269786
9787=item About filehandles
9788
9789(ファイルハンドルについて)
9790
83279791=begin original
83289792
8329If three (or more) arguments are specified, the open mode (including
9793The first argument to C<open>, labeled FILEHANDLE in this reference, is
8330optional encoding) in the second argument are distinct from the filename in
9794usually a scalar variable. (Exceptions exist, described in "Other
8331the third. If MODE is C<< < >> or nothing, the file is opened for input.
9795considerations", below.) If the call to C<open> succeeds, then the
9796expression provided as FILEHANDLE will get assigned an open
9797I<filehandle>. That filehandle provides an internal reference to the
9798specified external file, conveniently stored in a Perl variable, and
9799ready for I/O operations such as reading and writing.
9800
9801=end original
9802
9803このリファレンスでは FILEHANDLE というラベルが付いている、
9804C<open> の最初の引数は、通常はスカラ変数です。
9805(例外があります; 後述する "Other considerations" で記述されます。)
9806C<open> の呼び出しが成功すると、
9807FILEHANDLE として提供された式には、
9808開いた I<ファイルハンドル> が代入されます。
9809このファイルハンドルは指定された外部ファイルへの内部参照を提供し、
9810好都合なように Perl 変数に保管し、読み書きのような I/O 操作の準備をします。
9811
9812=item About modes
9813
9814(モードについて)
9815
9816=begin original
9817
9818When calling C<open> with three or more arguments, the second argument
9819-- labeled MODE here -- defines the I<open mode>. MODE is usually a
9820literal string comprising special characters that define the intended
9821I/O role of the filehandle being created: whether it's read-only, or
9822read-and-write, and so on.
9823
9824=end original
9825
98263 引数以上で C<open> を呼び出すとき、
98272 番目の引数 -- ここでは MODE -- は I<開くモード> を定義します。
9828MODE は普通、作られるファイルハンドルが意図している I/O の役割 (読み込み専用、
9829読み書き、など)を定義する特別な文字で構成されるリテラルな文字列です。
9830
9831=begin original
9832
9833If MODE is C<< < >>, the file is opened for input (read-only).
83329834If MODE is C<< > >>, the file is opened for output, with existing files
83339835first being truncated ("clobbered") and nonexisting files newly created.
83349836If MODE is C<<< >> >>>, the file is opened for appending, again being
83359837created if necessary.
83369838
83379839=end original
83389840
83393 (またはそれ以上)の引数指定された場合、2 番目の引数の(オプションの
9841MODE C<< < >> の場合、ファイルは入力用(読み込み専用)に開かれます。
8340エンコーディングを含む)開く時のモードは、3 番目のファイル名と分離されます。
8341MODE が C<< < >> か空の場合、ファイルは入力用に開かれます。
83429842MODE が C<< > >> の場合、ファイルは出力用に開かれ、既にファイルが
83439843ある場合は切り詰められ(上書きされ)、ない場合は新しく作られます。
83449844MODE が C<<< >> >>> の場合、ファイルは追加用に開かれ、やはり必要なら
83459845作成されます。
83469846
83479847=begin original
83489848
83499849You can put a C<+> in front of the C<< > >> or C<< < >> to
83509850indicate that you want both read and write access to the file; thus
8351C<< +< >> is almost always preferred for read/write updates--the
9851C<< +< >> is almost always preferred for read/write updates--the
83529852C<< +> >> mode would clobber the file first. You can't usually use
83539853either read-write mode for updating textfiles, since they have
8354variable-length records. See the B<-i> switch in L<perlrun> for a
9854variable-length records. See the B<-i> switch in
8355better approach. The file is created with permissions of C<0666>
9855L<perlrun|perlrun/-i[extension]> for a better approach. The file is
8356modified by the process's C<umask> value.
9856created with permissions of C<0666> modified by the process's
9857L<C<umask>|/umask EXPR> value.
83579858
83589859=end original
83599860
83609861ファイルに読み込みアクセスと書き込みアクセスの両方をしたいことを示すために、
83619862C<< > >> や C<< < >> の前に C<+> を付けることができます:
83629863従って、ほとんど常に C<< +< >> が読み書き更新のために使われます --
83639864C<< +> >> モードはまずファイルを上書きします。
83649865普通はこれらの読み書きモードをテキストファイルの更新のためには使えません;
83659866なぜなら可変長のレコードで構成されているからです。
8366よりよい手法については L<perlrun> の B<-i> オプションを参照してください。
9867よりよい手法については L<perlrun|perlrun/-i[extension]>
8367ファイルは C<0666> ロセスの C<umask> 値で修正したパーミッション
9868B<-i> プションを参照してください。
8368作成されます。
9869ファイルは C<0666> をプロセスの L<C<umask>|/umask EXPR> 値で修正した
9870パーミッションで作成されます。
83699871
83709872=begin original
83719873
8372These various prefixes correspond to the fopen(3) modes of C<r>,
9874These various prefixes correspond to the L<fopen(3)> modes of C<r>,
83739875C<r+>, C<w>, C<w+>, C<a>, and C<a+>.
83749876
83759877=end original
83769878
8377これらの様々な前置詞は fopen(3) の C<r>, C<r+>,
9879これらの様々な前置詞は L<fopen(3)> の C<r>, C<r+>,
83789880C<w>, C<w+>, C<a>, C<a+> のモードに対応します。
83799881
83809882=begin original
83819883
8382In the one- and two-argument forms of the call, the mode and filename
9884More examples of different modes in action:
8383should be concatenated (in that order), preferably separated by white
8384space. You can--but shouldn't--omit the mode in these forms when that mode
8385is C<< < >>. It is always safe to use the two-argument form of C<open> if
8386the filename argument is a known literal.
83879885
83889886=end original
83899887
83901 引数 と 2 引数の形式ではモードとファイル名は(この順番で)
9888実用的な異なったモードに関する更なる例:
8391結合されます(空白によって分割されているかもしれません)。
8392この形式で、モードが C<< '<' >> の場合はモードを省略できます (が、
8393するべきではありません)。
8394ファイル引数が既知のリテラルの場合、2 引数形式の C<open> は常に安全です。
83959889
8396=begin original
9890 # Open a file for concatenation
9891 open(my $log, ">>", "/usr/spool/news/twitlog")
9892 or warn "Couldn't open log file; discarding input";
83979893
8398For three or more arguments if MODE is C<|->, the filename is
9894 # Open a file for reading and writing
8399interpreted as a command to which output is to be piped, and if MODE
9895 open(my $dbase, "+<", "dbase.mine")
8400is C<-|>, the filename is interpreted as a command that pipes
9896 or die "Can't open 'dbase.mine' for update: $!";
8401output to us. In the two-argument (and one-argument) form, one should
8402replace dash (C<->) with the command.
8403See L<perlipc/"Using open() for IPC"> for more examples of this.
8404(You are not allowed to C<open> to a command that pipes both in I<and>
8405out, but see L<IPC::Open2>, L<IPC::Open3>, and
8406L<perlipc/"Bidirectional Communication with Another Process"> for
8407alternatives.)
84089897
8409=end original
9898=item Checking the return value
84109899
84113 引数以上の形式で
9900(返り値をチェックする)
8412MODE が C<|-> の場合、ファイル名は出力がパイプされるコマンドとして
8413解釈され、MODE が C<-|> の場合、ファイル名は出力がこちらに
8414パイプされるコマンドとして解釈されます。
84152 引数(と 1 引数) の形式ではハイフン(C<->)をコマンドの代わりに
8416使えます。
8417これに関するさらなる例については L<perlipc/"Using open() for IPC"> を
8418参照してください。
8419(C<open> を入出力 I<両用> にパイプすることは出来ませんが
8420代替案としては L<IPC::Open2>, L<IPC::Open3>,
8421L<perlipc/"Bidirectional Communication with Another Process"> を
8422参照してください。)
84239901
84249902=begin original
84259903
8426In the form of pipe opens taking three or more arguments, if LIST is specified
9904Open returns nonzero on success, the undefined value otherwise. If the
8427(extra arguments after the command name) then LIST becomes arguments
9905C<open> involved a pipe, the return value happens to be the pid of the
8428to the command invoked if the platform supports it. The meaning of
9906subprocess.
8429C<open> with more than three arguments for non-pipe modes is not yet
8430defined, but experimental "layers" may give extra LIST arguments
8431meaning.
84329907
84339908=end original
84349909
8435パイプでの三つ以上の引数の形式では、LIST (コマンド名の後の追加の引数) が
9910open は、成功時にはゼロ以外を返し、失敗時には未定義値を返します。
8436指定されると、プラットフォームが対応していれば、LIST 起動される
9911パイプに関 C<open> のきには返り値
8437コマンドへ引数となります。
9912サブプロセス pid となります。
8438パイプモードではない C<open> での三つ以上の引数の意味はまだ未定義ですが、
8439実験的な「層」は追加の LIST 引数の意味を与えます。
84409913
84419914=begin original
84429915
8443In the two-argument (and one-argument) form, opening C<< <- >>
9916When opening a file, it's seldom a good idea to continue if the request
8444or C<-> opens STDIN and opening C<< >- >> opens STDOUT.
9917failed, so C<open> is frequently used with L<C<die>|/die LIST>. Even if
9918you want your code to do something other than C<die> on a failed open,
9919you should still always check the return value from opening a file.
84459920
84469921=end original
84479922
84482 引数(と 1 引数)で C<< <- >> か C<-> open すと STDIN が
9923ファイル開く時、開くのに失敗した時に通常の処理を続けのは普通は悪い
8449オープンされ、C<< >- >> を open すると STDOUT がオープンされます。
9924考えなので、C<open> はしばしば
9925L<C<die>|/die LIST> と結び付けられて使われます。
9926開くときに失敗したときに L<C<die>|/die LIST> 意外の何かを
9927したい場合でも、ファイルを開いた時の返り値を常にチェックするべきです。
84509928
9929=back
9930
9931=item Specifying I/O layers in MODE
9932
9933(MODE で I/O 層を指定する)
9934
84519935=begin original
84529936
8453You may (and usually should) use the three-argument form of open to specify
9937You can use the three-argument form of open to specify
8454I/O layers (sometimes referred to as "disciplines") to apply to the handle
9938I/O layers (sometimes referred to as "disciplines") to apply to the new
8455that affect how the input and output are processed (see L<open> and
9939filehandle. These affect how the input and output are processed (see
9940L<open> and
84569941L<PerlIO> for more details). For example:
84579942
84589943=end original
84599944
8460open の 3 引数形式では、どのよう入出力が処理されるかに影響を与え
9945新しいファイルハンドル適用す
8461I/O 層(「ディシプリン」とも呼ばれます)を指定できま
9946I/O 層(「ディシプリン」とも呼ばれます)を指定するために
8462(そして普通はそうるべきです)
9947open の 3 引数形式を使えま
9948これらはどのように入出力が処理されるかに影響を与えます
84639949(詳細については L<open> と L<PerlIO> を参照してください)。
84649950例えば:
84659951
8466 open(my $fh, "<:encoding(UTF-8)", "filename")
9952 # loads PerlIO::encoding automatically
8467 || die "can't open UTF-8 encoded filename: $!";
9953 open(my $fh, "<:encoding(UTF-8)", $filename)
9954 || die "Can't open UTF-8 encoded $filename: $!";
84689955
84699956=begin original
84709957
8471opens the UTF8-encoded file containing Unicode characters;
9958This opens the UTF8-encoded file containing Unicode characters;
84729959see L<perluniintro>. Note that if layers are specified in the
8473three-argument form, then default layers stored in ${^OPEN} (see L<perlvar>;
9960three-argument form, then default layers stored in
8474usually set by the B<open> pragma or the switch B<-CioD>) are ignored.
9961L<C<${^OPEN}>|perlvar/${^OPEN}>
8475Those layers will also be ignored if you specifying a colon with no name
9962(usually set by the L<open> pragma or the switch C<-CioD>) are ignored.
9963Those layers will also be ignored if you specify a colon with no name
84769964following it. In that case the default layer for the operating system
84779965(:raw on Unix, :crlf on Windows) is used.
84789966
84799967=end original
84809968
8481は、Unicode 文字を含む UTF8 エンコードされたファイルを開きます;
9969これは、Unicode 文字を含む UTF8 エンコードされたファイルを開きます;
84829970L<perluniintro> を参照してください。
84833 引数形式で層を指定すると、${^OPEN} (L<perlvar> を参照してください;
99713 引数形式で層を指定すると、L<C<${^OPEN}>|perlvar/${^OPEN}>
8484通常はC<open> プラグマか B<-CioD> オプションでセットされます)
9972(通常は L<open> プラグマか C<-CioD> オプションでセットされます)
8485保存されたデフォルト層は無視されることに注意してください。
9973保存されたデフォルト層は無視されることに注意してください。
84869974これらの層は、名前なしでコロンを指定した場合にも無視されます。
84879975この場合 OS のデフォルトの層 (Unix では :raw、Windows では :crlf) が
84889976使われます。
84899977
84909978=begin original
84919979
8492Open returns nonzero on success, the undefined value otherwise. If
9980On some systems (in general, DOS- and Windows-based systems)
8493the C<open> involved a pipe, the return value happens to be the pid of
9981L<C<binmode>|/binmode FILEHANDLE, LAYER> is necessary when you're not
8494the subprocess.
9982working with a text file. For the sake of portability it is a good idea
9983always to use it when appropriate, and never to use it when it isn't
9984appropriate. Also, people can set their I/O to be by default
9985UTF8-encoded Unicode, not bytes.
84959986
84969987=end original
84979988
8498open は、成功時にはゼロ以外返し、失敗時は未定義値を返します。
9989テキストファイルでないもの扱う場合
8499パイプに関る C<open> のときには、返り値はサブプロセスの pid ります。
9990L<C<binmode>|/binmode FILEHANDLE, LAYER> が必要
9991システムもあります(一般的には DOS と Windows ベースのシステムです)。
9992移植性のために、適切なときには常にこれを使い、適切でないときには
9993決して使わないというのは良い考えです。
9994また、デフォルトとして I/O を bytes ではなく UTF-8 エンコードされた
9995Unicode にセットすることも出来ます。
85009996
9997=item Using C<undef> for temporary files
9998
9999(一時ファイルとして C<undef> を使う)
10000
850110001=begin original
850210002
8503If you're running Perl on a system that distinguishes between text
10003As a special case the three-argument form with a read/write mode and the third
8504files and binary files, then you should check out L</binmode> for tips
10004argument being L<C<undef>|/undef EXPR>:
8505for dealing with this. The key distinction between systems that need
8506C<binmode> and those that don't is their text file formats. Systems
8507like Unix, Mac OS, and Plan 9, that end lines with a single
8508character and encode that character in C as C<"\n"> do not
8509need C<binmode>. The rest need it.
851010005
851110006=end original
851210007
8513テキストファイルとバイナリファイルを区するシステムPerl を実行している
10008な場合として、3 引数の形読み書きモードで 3 番目の引数が
8514場合、これを扱うための小技のために L</binmode> をチェックするべきです。
10009L<C<undef>|/undef EXPR> の場合:
8515動作させているシステムで C<binmode> が必要か不要化を区別する鍵は、テキスト
8516ファイルの形式です。
8517Unix, Mac OS, Plan 9 といった、行の境界を 1 文字で表現し、それが C では
8518C<"\n"> でエンコードされる場合、C<binmode> は不要です。
8519それ以外では必要です。
852010010
10011 open(my $tmp, "+>", undef) or die ...
10012
852110013=begin original
852210014
8523When opening a file, it's seldom a good idea to continue
10015opens a filehandle to a newly created empty anonymous temporary file.
8524if the request failed, so C<open> is frequently used with
10016(This happens under any mode, which makes C<< +> >> the only useful and
8525C<die>. Even if C<die> won't do what you want (say, in a CGI script,
10017sensible mode to use.) You will need to
8526where you want to format a suitable error message (but there are
10018L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> to do the reading.
8527modules that can help with that problem)) always check
8528the return value from opening a file.
852910019
853010020=end original
853110021
8532ファイルを開く時、開くのに失敗た時に通常の処理続けるのは
10022新しく作成した空の無名一時ファイルてファイルハンドル開きます。
8533普通悪い考えですので、C<open> はしばしば C<die> と結び付けられて
10023(これモードも起こりますが、C<< +> >> のみが有用で意味があります。)
8534使われます。
10024読み込みを行うためには L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> が
8535望むものが C<die> ない場合(例えば、CGI スクリプト のように
10025必要す。
8536きれいにフォーマットされたエラーメッセージを作りたい場合
8537(但しこの問題を助けるモジュールがあります))でも、
8538ファイルを開いた時の返り値を常にチェックするべきです。
853910026
10027=item Opening a filehandle into an in-memory scalar
10028
10029(ファイルハンドルをメモリ内スカラに開く)
10030
854010031=begin original
854110032
8542As a special case the three-argument form with a read/write mode and the third
10033You can open filehandles directly to Perl scalars instead of a file or
8543argument being C<undef>:
10034other resource external to the program. To do so, provide a reference to
10035that scalar as the third argument to C<open>, like so:
854410036
854510037=end original
854610038
8547特別な場合とし、3 引数形で読み書きモ 3 番目の引数が
10039ファイルやその他のプログラムから見ての外部リソはなく、
8548C<undef> の場合:
10040Perl スカラに対して直接ファイルハンドルを開くことができます。
10041そうするためには、次のように、C<open> の 3 番目の引数としてその
10042スカラへのリファレンスを提供します:
854910043
8550 open(my $tmp, "+>", undef) or die ...
10044 open(my $memory, ">", \$var)
10045 or die "Can't open memory file: $!";
10046 print $memory "foo!\n"; # output will appear in $var
855110047
855210048=begin original
855310049
8554opens a filehandle to an anonymous temporary file. Also using C<< +< >>
10050To (re)open C<STDOUT> or C<STDERR> as an in-memory file, close it first:
8555works for symmetry, but you really should consider writing something
8556to the temporary file first. You will need to seek() to do the
8557reading.
855810051
855910052=end original
856010053
8561無名一時ファイルとしてファイルハンドルを開きます。
10054C<STDOUT> や C<STDERR> を「オンメモリの」ファイルとして
8562 C<< +< >> も対称性のため動作しますが、
10055再び開きい場合は、先それを閉じます:
8563一時ファイルにはまず何かを書き込みたいはずです。
8564読み込みを行うためには seek() が必要です。
856510056
10057 close STDOUT;
10058 open(STDOUT, ">", \$variable)
10059 or die "Can't open STDOUT: $!";
10060
856610061=begin original
856710062
8568Perl is built using PerlIO by default; Unless you've
10063The scalars for in-memory files are treated as octet strings: unless
8569changed this (such as building Perl with C<Configure -Uuseperlio>), you can
10064the file is being opened with truncation the scalar may not contain
8570open filehandles directly to Perl scalars via:
10065any code points over 0xFF.
857110066
857210067=end original
857310068
8574Perl はデルトで PerlIO を使っビルドさています;
10069オンメモリァイのためのスカラはオクテッ文字列とし扱われます:
8575(C<Configure -Uuseperlio> して Perl をビドするなどし)こ
10070ファイが切り詰められ開かない限り、
8576変更していない限り、以下のようにして、Perl スカラを直接ファイルハンドルで
10071スカラは 0xFF 超える符号位置を含みません。
8577開くことができます:
857810072
8579 open($fh, ">", \$variable) || ..
10073=begin original
858010074
10075Opening in-memory files I<can> fail for a variety of reasons. As with
10076any other C<open>, check the return value for success.
10077
10078=end original
10079
10080オンメモリファイルを開くのは様々な理由で失敗する I<ことがあります>。
10081その他の C<open> と同様、成功したかを返り値でチェックしてください。
10082
858110083=begin original
858210084
8583To (re)open C<STDOUT> or C<STDERR> as an in-memory file, close it first:
10085I<Technical note>: This feature works only when Perl is built with
10086PerlIO -- the default, except with older (pre-5.16) Perl installations
10087that were configured to not include it (e.g. via C<Configure
10088-Uuseperlio>). You can see whether your Perl was built with PerlIO by
10089running C<perl -V:useperlio>. If it says C<'define'>, you have PerlIO;
10090otherwise you don't.
858410091
858510092=end original
858610093
8587C<STDOUT> C<STDERR>「オンメモリの」ファイとし
10094I<技術ノート>: この機能は Perl が PerlIO 使ってビドされいる
8588再び開きたい場合は、先それを閉じます:
10095場合にのみ動作します; これは (C<Configure -Uuseperlio> によって)
10096これを含まないように設定されていた古い (5.16 より前の) Perl でない限り、
10097デフォルトです。
10098Perl が PerlIO つきでビルドされているかどうかを確認するには、
10099C<perl -V:useperlio> を見ます。
10100これが C<'define'> なら PerlIO を使っています;
10101そうでなければ使っていません。
858910102
8590 close STDOUT;
10103=begin original
8591 open(STDOUT, ">", \$variable)
8592 or die "Can't open STDOUT: $!";
859310104
10105See L<perliol> for detailed info on PerlIO.
10106
10107=end original
10108
10109PerlIO に関する詳しい情報については L<perliol> を参照してください。
10110
10111=item Opening a filehandle into a command
10112
10113(ファイルハンドルをコマンドに開く)
10114
859410115=begin original
859510116
8596General examples:
10117If MODE is C<|->, then the filename is
10118interpreted as a command to which output is to be piped, and if MODE
10119is C<-|>, the filename is interpreted as a command that pipes
10120output to us. In the two-argument (and one-argument) form, one should
10121replace dash (C<->) with the command.
10122See L<perlipc/"Using open() for IPC"> for more examples of this.
10123(You are not allowed to L<C<open>|/open FILEHANDLE,MODE,EXPR> to a command
10124that pipes both in I<and> out, but see L<IPC::Open2>, L<IPC::Open3>, and
10125L<perlipc/"Bidirectional Communication with Another Process"> for
10126alternatives.)
859710127
859810128=end original
859910129
8600一般的な例:
10130MODE が C<|-> の場合、ファイル名は出力がパイプされるコマンドとして
10131解釈され、MODE が C<-|> の場合、ファイル名は出力がこちらに
10132パイプされるコマンドとして解釈されます。
101332 引数(と 1 引数) の形式ではハイフン(C<->)をコマンドの代わりに使えます。
10134これに関するさらなる例については L<perlipc/"Using open() for IPC"> を
10135参照してください。
10136(L<C<open>|/open FILEHANDLE,MODE,EXPR> を入出力 I<両用> にパイプすることは
10137出来ませんが、代替案としては L<IPC::Open2>, L<IPC::Open3>,
10138L<perlipc/"Bidirectional Communication with Another Process"> を
10139参照してください。)
860110140
8602 $ARTICLE = 100;
10141 open(my $article_fh, "-|", "caesar <$article") # decrypt
8603 open(ARTICLE) or die "Can't find article $ARTICLE: $!\n";
10142 # article
8604 while (<ARTICLE>) {...
10143 or die "Can't start caesar: $!";
860510144
8606 open(LOG, ">>/usr/spool/news/twitlog"); # (log is reserved)
10145 open(my $article_fh, "caesar <$article |") # ditto
8607 # if the open fails, output is discarded
10146 or die "Can't start caesar: $!";
860810147
8609 open(my $dbase, "+<", "dbase.mine") # open for update
10148 open(my $out_fh, "|-", "sort >Tmp$$") # $$ is our process id
8610 or die "Can't open 'dbase.mine' for update: $!";
10149 or die "Can't start sort: $!";
861110150
8612 open(my $dbase, "+<dbase.mine") # ditto
10151=begin original
8613 or die "Can't open 'dbase.mine' for update: $!";
861410152
8615 open(ARTICLE, "-|", "caesar <$article") # decrypt article
10153In the form of pipe opens taking three or more arguments, if LIST is specified
8616 or die "Can't start caesar: $!";
10154(extra arguments after the command name) then LIST becomes arguments
10155to the command invoked if the platform supports it. The meaning of
10156L<C<open>|/open FILEHANDLE,MODE,EXPR> with more than three arguments for
10157non-pipe modes is not yet defined, but experimental "layers" may give
10158extra LIST arguments meaning.
861710159
8618 open(ARTICLE, "caesar <$article |") # ditto
10160=end original
8619 or die "Can't start caesar: $!";
862010161
8621 open(EXTRACT, "|sort >Tmp$$") # $$ is our process id
10162パイプでの三つ以上の引数の形式では、LIST (コマンド名の後の追加の引数)
8622 or die "Can't start sort: $!";
10163指定されると、プラットフォームが対応していれば、LIST は起動される
10164コマンドへの引数となります。
10165パイプモードではない L<C<open>|/open FILEHANDLE,MODE,EXPR> での
10166三つ以上の引数の意味はまだ未定義ですが、実験的な「層」は
10167追加の LIST 引数の意味を与えます。
862310168
8624 # in-memory files
10169=begin original
8625 open(MEMORY, ">", \$var)
8626 or die "Can't open memory file: $!";
8627 print MEMORY "foo!\n"; # output will appear in $var
862810170
8629 # process argument list of files along with any includes
10171If you open a pipe on the command C<-> (that is, specify either C<|-> or C<-|>
10172with the one- or two-argument forms of
10173L<C<open>|/open FILEHANDLE,MODE,EXPR>), an implicit L<C<fork>|/fork> is done,
10174so L<C<open>|/open FILEHANDLE,MODE,EXPR> returns twice: in the parent process
10175it returns the pid
10176of the child process, and in the child process it returns (a defined) C<0>.
10177Use C<defined($pid)> or C<//> to determine whether the open was successful.
863010178
8631 foreach $file (@ARGV) {
10179=end original
8632 process($file, "fh00");
8633 }
863410180
8635 sub process {
101811 引数 または 2 引数の形の L<C<open>|/open FILEHANDLE,MODE,EXPR>) で
8636 my($filename, $input) = @_;
10182(C<-|> C<|-> というふうに) C<-> というコマンドにパイプを開くと、
8637 $input++; # this is a string increment
10183暗黙の L<C<fork>|/fork> が行なわれるので、
8638 unless (open($input, "<", $filename)) {
10184L<C<open>|/open FILEHANDLE,MODE,EXPR> 2 回返ります;
8639 print STDERR "Can't open $filename: $!\n";
10185親プロセスには子プロセスの pid が返され、子プロセスには (定義された) C<0>
8640 return;
10186返されます。
8641 }
10187open が成功したかどうかを調べるには、C<defined($pid)> または C<//>
10188使います。
864210189
8643 local $_;
10190=begin original
8644 while (<$input>) { # note use of indirection
8645 if (/^#include "(.*)"/) {
10192For example, use either
8646 process($1, $input);
8647 next;
10194=end original
8648 }
8649 #... # whatever
10196例えば、以下の二つ
8650 }
10198 my $child_pid = open(my $from_kid, "-|")
10199 // die "Can't fork: $!";
10200
10201=begin original
10202
10203or
10204
10205=end original
10206
10207または
10208
10209 my $child_pid = open(my $to_kid, "|-")
10210 // die "Can't fork: $!";
10211
10212=begin original
10213
10214followed by
10215
10216=end original
10217
10218を使って、後で以下のようにします。
10219
10220 if ($child_pid) {
10221 # am the parent:
10222 # either write $to_kid or else read $from_kid
10223 ...
10224 waitpid $child_pid, 0;
10225 } else {
10226 # am the child; use STDIN/STDOUT normally
10227 ...
10228 exit;
865110229 }
865210230
865310231=begin original
865410232
8655See L<perliol> for detailed info on PerlIO.
10233The filehandle behaves normally for the parent, but I/O to that
10234filehandle is piped from/to the STDOUT/STDIN of the child process.
10235In the child process, the filehandle isn't opened--I/O happens from/to
10236the new STDOUT/STDIN. Typically this is used like the normal
10237piped open when you want to exercise more control over just how the
10238pipe command gets executed, such as when running setuid and
10239you don't want to have to scan shell commands for metacharacters.
865610240
865710241=end original
865810242
8659PerlIO する詳しい情報については L<perliol> を参照してください。
10243親プロセスでは、このファイルハンドルは通常通り動作しまが、行なわれ
10244入出力は、子プロセスの STDIN/STDOUT にパイプされます。
10245子プロセス側では、そのファイルハンドルは開かれず、入出力は新しい STDOUT か
10246STDIN に対して行なわれます。
10247これは、setuid で実行して、シェルコマンドのメタ文字を
10248検索させたくないような場合に、パイプコマンドの起動の仕方を
10249制御したいとき、普通のパイプの open と同じように使います。
866010250
866110251=begin original
866210252
10253The following blocks are more or less equivalent:
10254
10255=end original
10256
10257以下の組み合わせは、だいたい同じものです:
10258
10259 open(my $fh, "|tr '[a-z]' '[A-Z]'");
10260 open(my $fh, "|-", "tr '[a-z]' '[A-Z]'");
10261 open(my $fh, "|-") || exec 'tr', '[a-z]', '[A-Z]';
10262 open(my $fh, "|-", "tr", '[a-z]', '[A-Z]');
10263
10264 open(my $fh, "cat -n '$file'|");
10265 open(my $fh, "-|", "cat -n '$file'");
10266 open(my $fh, "-|") || exec "cat", "-n", $file;
10267 open(my $fh, "-|", "cat", "-n", $file);
10268
10269=begin original
10270
10271The last two examples in each block show the pipe as "list form", which
10272is not yet supported on all platforms. (If your platform has a real
10273L<C<fork>|/fork>, such as Linux and macOS, you can use the list form; it
10274also works on Windows with Perl 5.22 or later.) You would want to use
10275the list form of the pipe so you can pass literal arguments to the
10276command without risk of the shell interpreting any shell metacharacters
10277in them. However, this also bars you from opening pipes to commands that
10278intentionally contain shell metacharacters, such as:
10279
10280=end original
10281
10282それぞれのブロックの末尾二つの例ではパイプを「リスト形式」にしていますが、
10283これはまだ全てのプラットフォームで対応しているわけではなりません。
10284(もし実行しているプラットフォームで本当の
10285L<C<fork>|/fork> があれば(Linux や
10286MacOS X なら)リスト形式が使えます; Perl 5.22 以降では Windows でも
10287動作します。)
10288パイプのリスト形式を使うことで、コマンドへのリテラルな引数を、
10289シェルのメタ文字をシェルが解釈するリスクなしに渡すことができます。
10290しかし、これは以下のように意図的にシェルメタ文字を含むコマンドをパイプとして
10291開くことを妨げます:
10292
10293 open(my $fh, "|cat -n | expand -4 | lpr")
10294 || die "Can't open pipeline to lpr: $!";
10295
10296=begin original
10297
10298See L<perlipc/"Safe Pipe Opens"> for more examples of this.
10299
10300=end original
10301
10302これに関する更なる例については L<perlipc/"Safe Pipe Opens"> を
10303参照してください。
10304
10305=item Duping filehandles
10306
10307(ハンドルの複製)
10308
10309=begin original
10310
866310311You may also, in the Bourne shell tradition, specify an EXPR beginning
866410312with C<< >& >>, in which case the rest of the string is interpreted
866510313as the name of a filehandle (or file descriptor, if numeric) to be
8666duped (as C<dup(2)>) and opened. You may use C<&> after C<< > >>,
10314duped (as in L<dup(2)>) and opened. You may use C<&> after C<< > >>,
866710315C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>, and C<< +< >>.
866810316The mode you specify should match the mode of the original filehandle.
866910317(Duping a filehandle does not take into account any existing contents
867010318of IO buffers.) If you use the three-argument
867110319form, then you can pass either a
867210320number, the name of a filehandle, or the normal "reference to a glob".
867310321
867410322=end original
867510323
867610324Bourne シェルの慣例にしたがって、EXPR の先頭に C<< >& >>
867710325を付けると、EXPR の残りの文字列をファイルハンドル名
8678(数字であれば、ファイル記述子) と解釈して、それを (C<dup(2)> によって)
10326(数字であれば、ファイル記述子) と解釈して、それを (L<dup(2)> によって)
867910327複製してオープンします。
868010328C<&> は、C<< > >>, C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>,
868110329C<< +< >>というモード指定に付けることができます。
868210330指定するモード指定は、もとのファイルハンドルのモードと
868310331合っていないといけません。
868410332(ファイルハンドルの複製は既に存在する IO バッファの内容に含めません。)
8685103333 引数形式を使う場合は、数値を渡すか、ファイルハンドルの名前を渡すか、
868610334通常の「グロブへのリファレンス」を渡します。
868710335
868810336=begin original
868910337
869010338Here is a script that saves, redirects, and restores C<STDOUT> and
869110339C<STDERR> using various methods:
869210340
869310341=end original
869410342
869510343C<STDOUT> と C<STDERR> 保存し、リダイレクトし、元に戻すスクリプトを示します:
869610344
869710345 #!/usr/bin/perl
8698 open(my $oldout, ">&STDOUT") or die "Can't dup STDOUT: $!";
10346 open(my $oldout, ">&STDOUT")
8699 open(OLDERR, ">&", \*STDERR) or die "Can't dup STDERR: $!";
10347 or die "Can't dup STDOUT: $!";
10348 open(OLDERR, ">&", \*STDERR)
10349 or die "Can't dup STDERR: $!";
870010350
8701 open(STDOUT, '>', "foo.out") or die "Can't redirect STDOUT: $!";
10351 open(STDOUT, '>', "foo.out")
8702 open(STDERR, ">&STDOUT") or die "Can't dup STDOUT: $!";
10352 or die "Can't redirect STDOUT: $!";
10353 open(STDERR, ">&STDOUT")
10354 or die "Can't dup STDOUT: $!";
870310355
870410356 select STDERR; $| = 1; # make unbuffered
870510357 select STDOUT; $| = 1; # make unbuffered
870610358
870710359 print STDOUT "stdout 1\n"; # this works for
870810360 print STDERR "stderr 1\n"; # subprocesses too
870910361
8710 open(STDOUT, ">&", $oldout) or die "Can't dup \$oldout: $!";
10362 open(STDOUT, ">&", $oldout)
8711 open(STDERR, ">&OLDERR") or die "Can't dup OLDERR: $!";
10363 or die "Can't dup \$oldout: $!";
10364 open(STDERR, ">&OLDERR")
10365 or die "Can't dup OLDERR: $!";
871210366
871310367 print STDOUT "stdout 2\n";
871410368 print STDERR "stderr 2\n";
871510369
871610370=begin original
871710371
871810372If you specify C<< '<&=X' >>, where C<X> is a file descriptor number
8719or a filehandle, then Perl will do an equivalent of C's C<fdopen> of
10373or a filehandle, then Perl will do an equivalent of C's L<fdopen(3)> of
8720that file descriptor (and not call C<dup(2)>); this is more
10374that file descriptor (and not call L<dup(2)>); this is more
872110375parsimonious of file descriptors. For example:
872210376
872310377=end original
872410378
872510379C<X> をファイル記述子の番号かファイルハンドルとして、
872610380C<< '<&=X' >> と指定すると、Perl はそのファイル記述子に対する
8727C の C<fdopen> と同じことを行ないます(そして C<dup(2)> は呼び出しません);
10381C の L<fdopen(3)> と同じことを行ないます(そして L<dup(2)> は呼び出しません);
872810382これはファイル記述子をより節約します。
872910383例えば:
873010384
873110385 # open for input, reusing the fileno of $fd
8732 open(FILEHANDLE, "<&=$fd")
10386 open(my $fh, "<&=", $fd)
873310387
873410388=begin original
873510389
873610390or
873710391
873810392=end original
873910393
874010394または
874110395
8742 open(FILEHANDLE, "<&=", $fd)
10396 open(my $fh, "<&=$fd")
874310397
874410398=begin original
874510399
874610400or
874710401
874810402=end original
874910403
875010404または
875110405
8752 # open for append, using the fileno of OLDFH
10406 # open for append, using the fileno of $oldfh
8753 open(FH, ">>&=", OLDFH)
10407 open(my $fh, ">>&=", $oldfh)
875410408
875510409=begin original
875610410
8757or
8758
8759=end original
8760
8761または
8762
8763 open(FH, ">>&=OLDFH")
8764
8765=begin original
8766
876710411Being parsimonious on filehandles is also useful (besides being
876810412parsimonious) for example when something is dependent on file
8769descriptors, like for example locking using flock(). If you do just
10413descriptors, like for example locking using
8770C<< open(A, ">>&B") >>, the filehandle A will not have the same file
10414L<C<flock>|/flock FILEHANDLE,OPERATION>. If you do just
8771descriptor as B, and therefore flock(A) will not flock(B) nor vice
10415C<< open(my $A, ">>&", $B) >>, the filehandle C<$A> will not have the
8772versa. But with C<< open(A, ">>&=B") >>, the filehandles will share
10416same file descriptor as C<$B>, and therefore C<flock($A)> will not
8773the same underlying system file descriptor.
10417C<flock($B)> nor vice versa. But with C<< open(my $A, ">>&=", $B) >>,
10418the filehandles will share the same underlying system file descriptor.
877410419
877510420=end original
877610421
877710422ファイルハンドルを倹約することは、(倹約できること以外に)何かが
8778ファイル記述子に依存している場合、例えば flock() を使った
10423ファイル記述子に依存している場合、例えば
10424L<C<flock>|/flock FILEHANDLE,OPERATION> を使った
877910425ファイルロックといった場合に有用です。
8780C<< open(A, ">>&B") >> とすると、ファイルハンドル A は B と同じ
10426C<< open(my $A, ">>&", $B) >> とすると、ファイルハンドル C<$A>C<$B> と同じ
8781ファイル記述子にはならないので、flock(A) と flock(B) は別々になります。
10427ファイル記述子にはならないので、C<flock($A)>C<flock($B)> は別々になります。
8782しかし C<< open(A, ">>&=B") >> ではファイルハンドルは基礎となるシステムの
10428しかし C<< open(my $A, ">>&=", $B) >> ではファイルハンドルは基礎となるシステムの
878310429同じファイル記述子を共有します。
878410430
878510431=begin original
878610432
878710433Note that under Perls older than 5.8.0, Perl uses the standard C library's'
8788fdopen() to implement the C<=> functionality. On many Unix systems,
10434L<fdopen(3)> to implement the C<=> functionality. On many Unix systems,
8789fdopen() fails when file descriptors exceed a certain value, typically 255.
10435L<fdopen(3)> fails when file descriptors exceed a certain value, typically 255.
879010436For Perls 5.8.0 and later, PerlIO is (most often) the default.
879110437
879210438=end original
879310439
8794104405.8.0 より前の Perl の場合、C<=> 機能の実装は
8795標準 C ライブラリの fdopen() を使っています。
10441標準 C ライブラリの L<fdopen(3)> を使っています。
8796多くの Unix システムでは、fdopen() はファイル記述子がある値
10442多くの Unix システムでは、L<fdopen(3)> はファイル記述子がある値
879710443(典型的には 255)を超えた場合に失敗することが知られています。
87985.8.0 以降の Perl では、(ほとんどの場合) PerlIO がデフォルトです。
104445.8.0 以降の Perl では、(ほぼ確実に) PerlIO がデフォルトです。
879910445
10446=item Legacy usage
10447
10448(古い使い方)
10449
880010450=begin original
880110451
8802You can see whether your Perl was built with PerlIO by running C<perl -V>
10452This section describes ways to call C<open> outside of best practices;
8803and looking for the C<useperlio=> line. If C<useperlio> is C<define>, you
10453you may encounter these uses in older code. Perl does not consider their
8804have PerlIO; otherwise you don't.
10454use deprecated, exactly, but neither is it recommended in new code, for
10455the sake of clarity and readability.
880510456
880610457=end original
880710458
8808Perl が PerlIOきでビルドされてるかどうかを確認するには、
10459この節では、ベストプラクティスではない C<open> の呼び出し方につい
8809C<perl -V> と C<useperlio=> 行を見ます。
10460記述ます; より古いコードでこれらが使われているに遭遇るかもしれません
8810C<useperlio> が C<define> なら PerlIO使っています;
10461厳密には、Perl はこれらの仕様廃止予定にはしていませんが、
8811そうでなければ使っていません。
10462明瞭性と可読性のために、新しコードには薦めません。
881210463
10464=over
10465
10466=item Specifying mode and filename as a single argument
10467
10468(モードとファイル名を一つの引数で指定する)
10469
881310470=begin original
881410471
8815If you open a pipe on the command C<-> (that is, specify either C<|-> or C<-|>
10472In the one- and two-argument forms of the call, the mode and filename
8816with the one- or two-argument forms of C<open>),
10473should be concatenated (in that order), preferably separated by white
8817an implicit C<fork> is done, so C<open> returns twice: in the parent
10474space. You can--but shouldn't--omit the mode in these forms when that mode
8818process it returns the pid
10475is C<< < >>. It is safe to use the two-argument form of
8819of the child process, and in the child process it returns (a defined) C<0>.
10476L<C<open>|/open FILEHANDLE,MODE,EXPR> if the filename argument is a known literal.
8820Use C<defined($pid)> or C<//> to determine whether the open was successful.
882110477
882210478=end original
882310479
88241 引数 または 2 引数の形の C<open()> (C<-|> や C<|-> いうふうに)
104801 引数 2 引数の形はモードファイル名は(この順番で)
8825C<-> というコマンドパイプを開くと、暗黙の C<fork> が行なわれるので、
10481結合されます(空白よって分割さていかもしれません)。
8826C<open> 2 回返ります;
10482この形式で、モードが C<< '<' >> の場合はモードを省略できます (が、
8827親プロセスに子プロセスの pid が返され、子プロセスには (定義された) C<0> が
10483するべきでありません)
8828返されます。
10484ファイル引数が既知のリテラルの場合、2 引数形式の
8829open が成功したかどうかを調べるには、C<defined($pid)> または C<//>
10485L<C<open>|/open FILEHANDLE,MODE,EXPR> は安全です。
8830使います。
883110486
10487 open(my $dbase, "+<dbase.mine") # ditto
10488 or die "Can't open 'dbase.mine' for update: $!";
10489
883210490=begin original
883310491
8834For example, use either
10492In the two-argument (and one-argument) form, opening C<< <- >>
10493or C<-> opens STDIN and opening C<< >- >> opens STDOUT.
883510494
883610495=end original
883710496
8838例えば、以下の二つ
104972 引数(と 1 引数)で C<< <- >> か C<-> を open すると STDIN が
10498オープンされ、C<< >- >> を open すると STDOUT がオープンされます。
883910499
8840 $child_pid = open(FROM_KID, "-|") // die "can't fork: $!";
8841
884210500=begin original
884310501
8844or
10502New code should favor the three-argument form of C<open> over this older
10503form. Declaring the mode and the filename as two distinct arguments
10504avoids any confusion between the two.
884510505
884610506=end original
884710507
8848また
10508新しいコードで、このより古い形式ではなく、3 引数形式の C<open> を
10509使うべきです。
10510モードとファイル名を異なった二つの引数として指定することで、
10511二つの間の混乱を避けられます。
884910512
8850 $child_pid = open(TO_KID, "|-") // die "can't fork: $!";
10513=item Calling C<open> with one argument via global variables
885110514
10515(グローバル変数を使って C<open> を 1 引数で呼び出す)
10516
885210517=begin original
885310518
8854followed by
10519As a shortcut, a one-argument call takes the filename from the global
10520scalar variable of the same name as the filehandle:
885510521
885610522=end original
885710523
8858を使って、以下ようにします。
10524短縮版として、1 引数呼び出しは、ファイル名を、ファイルハンドルと同じ名前
10525グローバルなスカラ変数から取ります:
885910526
8860 if ($child_pid) {
10527 $ARTICLE = 100;
8861 # am the parent:
10528 open(ARTICLE)
8862 # either write TO_KID or else read FROM_KID
10529 or die "Can't find article $ARTICLE: $!\n";
8863 ...
8864 waitpid $child_pid, 0;
8865 } else {
8866 # am the child; use STDIN/STDOUT normally
8867 ...
8868 exit;
8869 }
887010530
887110531=begin original
887210532
8873The filehandle behaves normally for the parent, but I/O to that
10533Here C<$ARTICLE> must be a global (package) scalar variable - not one
8874filehandle is piped from/to the STDOUT/STDIN of the child process.
10534declared with L<C<my>|/my VARLIST> or L<C<state>|/state VARLIST>.
8875In the child process, the filehandle isn't opened--I/O happens from/to
8876the new STDOUT/STDIN. Typically this is used like the normal
8877piped open when you want to exercise more control over just how the
8878pipe command gets executed, such as when running setuid and
8879you don't want to have to scan shell commands for metacharacters.
888010535
888110536=end original
888210537
8883親プロセスでは、このファイハンドルは
10538ここ C<$ARTICLE> グローバ(パッケージ)スカラ変数でなければなりません -
8884通常通りに動作しますが、行なわる入出力は、
10539L<C<my>|/my VARLIST> や L<C<state>|/state VARLIST> で宣言さ
8885チャイルドプロセスの STDIN/STDOUT にパイプされ
10540変数ではありせん
8886チャイルドプロセス側では、そのファイルハンドルは
8887オープンされず、入出力は新しい STDOUT か STDIN に対して行なわれます。
8888これは、setuid で実行して、シェルコマンドのメタ文字を
8889検索させたくないような場合に、パイプコマンドの起動の仕方を
8890制御したいとき、普通のパイプの open と同じように使います。
889110541
10542=item Assigning a filehandle to a bareword
10543
10544(ファイルハンドルを裸の単語に代入する)
10545
889210546=begin original
889310547
8894The following blocks are more or less equivalent:
10548An older style is to use a bareword as the filehandle, as
889510549
889610550=end original
889710551
8898以下の組み合わせは、だいたい同じも:
10552より古いスタイルは、ように、ファイルハンドルとして裸の単語を使いま
889910553
8900 open(FOO, "|tr '[a-z]' '[A-Z]'");
10554 open(FH, "<", "input.txt")
8901 open(FOO, "|-", "tr '[a-z]' '[A-Z]'");
10555 or die "Can't open < input.txt: $!";
8902 open(FOO, "|-") || exec 'tr', '[a-z]', '[A-Z]';
8903 open(FOO, "|-", "tr", '[a-z]', '[A-Z]');
890410556
8905 open(FOO, "cat -n '$file'|");
8906 open(FOO, "-|", "cat -n '$file'");
8907 open(FOO, "-|") || exec "cat", "-n", $file;
8908 open(FOO, "-|", "cat", "-n", $file);
8909
891010557=begin original
891110558
8912The last two examples in each block show the pipe as "list form", which is
10559Then you can use C<FH> as the filehandle, in C<< close FH >> and C<<
8913not yet supported on all platforms. A good rule of thumb is that if
10560<FH> >> and so on. Note that it's a global variable, so this form is
8914your platform has a real C<fork()> (in other words, if your platform is
10561not recommended when dealing with filehandles other than Perl's built-in ones
8915Unix, including Linux and MacOS X), you can use the list form. You would
10562(e.g. STDOUT and STDIN). In fact, using a bareword for the filehandle is
8916want to use the list form of the pipe so you can pass literal arguments
10563an error when the C<bareword_filehandles> feature has been disabled. This
8917to the command without risk of the shell interpreting any shell metacharacters
10564feature is disabled by default when in the scope of C<use v5.36.0> or later.
8918in them. However, this also bars you from opening pipes to commands
8919that intentionally contain shell metacharacters, such as:
892010565
892110566=end original
892210567
8923それぞれのブロックの末尾二つの例ではパイプ「リスト形式」していますが
10568それから C<FH> 、C<< close FH >> や C<< <FH> >> などのように、
8924これはまだ全てのプラットォームで対応しているわけではなりせん
10569ァイルハンドルとして使え
8925よい経験則として、もし実行しているプラットフォ本当C<fork()>
10570これグロバル変数なの、Perl 組み込みのもの (例えば STDOUT と STDIN)
8926れば(言い換えると、プラットフォームが Linux や MacOS X を含む Unix なら)
10571以外では非推奨であるに注意してください。
8927リスト形式使えます。
10572実際、C<bareword_filehandles> 機能無効になっている場合は
8928リスト形式を使うことで、コマンドへのリテルな引数を、
10573ファルハンドルに裸単語を使うことはエーです。
8929シェルメタ文字をシェルが解釈するリクなしに渡すことがきます。
10574機能は、C<use v5.36.0> 以降のコープ内はデフォルトでは
8930しかし、これは以下のよう意図的にシェルメタ文字を含むコマンドをパイプとし
10575無効なっいます。
8931開くことを妨げます:
893210576
8933 open(FOO, "|cat -n | expand -4 | lpr")
10577=back
8934 // die "Can't open pipeline to lpr: $!";
893510578
10579=item Other considerations
10580
10581(その他の考慮点)
10582
10583=over
10584
10585=item Automatic filehandle closure
10586
10587(自動的にファイルハンドルを閉じる)
10588
893610589=begin original
893710590
8938See L<perlipc/"Safe Pipe Opens"> for more examples of this.
10591The filehandle will be closed when its reference count reaches zero. If
10592it is a lexically scoped variable declared with L<C<my>|/my VARLIST>,
10593that usually means the end of the enclosing scope. However, this
10594automatic close does not check for errors, so it is better to explicitly
10595close filehandles, especially those used for writing:
893910596
894010597=end original
894110598
8942これに関する更なる例についてL<perlipc/"Safe Pipe Opens"> を
10599ファイルハンドル、参照カウントが 0 になったときに閉じられます。
8943参照してくだい。
10600これが L<C<my>|/my VARLIST> で宣言れたレキシカルスコープを持つ変数の場合、
10601普通は囲まれたスコープの終わりを意味します。
10602しかし、この自動閉じはエラーをチェックしないので、特に書き込み用の場合は、
10603明示的にファイルハンドルを閉じる方がよいです。
894410604
10605 close($handle)
10606 || warn "close failed: $!";
10607
10608=item Automatic pipe flushing
10609
10610(パイプの自動フラッシュ)
10611
894510612=begin original
894610613
894710614Perl will attempt to flush all files opened for
894810615output before any operation that may do a fork, but this may not be
894910616supported on some platforms (see L<perlport>). To be safe, you may need
8950to set C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method
10617to set L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>)
8951of C<IO::Handle> on any open handles.
10618or call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS>
10619on any open handles.
895210620
895310621=end original
895410622
8955v5.6.0 から、Perl は書き込み用に開いている全てのファイルに対して
10623Perl は書き込み用に開いている全てのファイルに対して
895610624fork を行う前にフラッシュしようとしますが、これに対応していない
895710625プラットフォームもあります(L<perlport> を参照してください)。
8958安全のために、C<$|> (English モジュールでは $AUTOFLUSH) をセットするか、
10626安全のために、L<C<$E<verbar>>|perlvar/$E<verbar>> (L<English> モジュールでは
8959全ての開いているハンドルに対して C<IO::Handle> の C<autoflush()> メソッドを
10627C<$AUTOFLUSH>) をセットするか、全ての開いているハンドルに対して
10628L<C<IO::Handle>|IO::Handle/METHODS> の C<autoflush> メソッドを
896010629呼び出す必要があるかもしれません。
896110630
896210631=begin original
896310632
896410633On systems that support a close-on-exec flag on files, the flag will
896510634be set for the newly opened file descriptor as determined by the value
8966of C<$^F>. See L<perlvar/$^F>.
10635of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>.
896710636
896810637=end original
896910638
897010639ファイルに対する close-on-exec フラグをサポートしているシステムでは、
8971フラグは C<$^F> の値で決定される、新しくオープンされたファイル記述子に対して
10640フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた
8972セットされます。
10641ファイル記述子に対してセットされます。
897310642L<perlvar/$^F> を参照してください。
897410643
897510644=begin original
897610645
897710646Closing any piped filehandle causes the parent process to wait for the
8978child to finish, then returns the status value in C<$?> and
10647child to finish, then returns the status value in L<C<$?>|perlvar/$?> and
8979C<${^CHILD_ERROR_NATIVE}>.
10648L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>.
898010649
898110650=end original
898210651
8983パイプのファイルハンドルを close することで、
10652パイプのファイルハンドルを close することで、親プロセスは、子プロセスの終了を
8984親プロセスは、チャイルドプロセスの終了を待ち、それから C<$?> と
10653待ち、それから L<C<$?>|perlvar/$?> と
8985C<${^CHILD_ERROR_NATIVE}> にステータス値を返します。
10654L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> にステータス値を
10655返します。
898610656
10657=item Direct versus by-reference assignment of filehandles
10658
10659(ファイルハンドルの直接代入とリファレンスによる代入)
10660
898710661=begin original
898810662
8989The filename passed to the one- and two-argument forms of open() will
10663If FILEHANDLE -- the first argument in a call to C<open> -- is an
10664undefined scalar variable (or array or hash element), a new filehandle
10665is autovivified, meaning that the variable is assigned a reference to a
10666newly allocated anonymous filehandle. Otherwise if FILEHANDLE is an
10667expression, its value is the real filehandle. (This is considered a
10668symbolic reference, so C<use strict "refs"> should I<not> be in effect.)
10669
10670=end original
10671
10672FILEHANDLE (C<open> を呼び出すときの最初の引数) が未定義のスカラ変数
10673(または配列かハッシュの要素)の場合、
10674新しいファイルハンドルが自動有効化され、その変数は新しく割り当てられた
10675無名ファイルハンドルへのリファレンスが代入されます。
10676さもなければ、もし FILEHANDLE が式なら、その値を求めている実際の
10677ファイルハンドルの名前として使います。
10678(これはシンボリックリファレンスとして扱われるので、
10679C<use strict "refs"> の影響を I<受けません>。)
10680
10681=item Whitespace and special characters in the filename argument
10682
10683(ファイル名引数の空白と特殊文字)
10684
10685=begin original
10686
10687The filename passed to the one- and two-argument forms of
10688L<C<open>|/open FILEHANDLE,MODE,EXPR> will
899010689have leading and trailing whitespace deleted and normal
899110690redirection characters honored. This property, known as "magic open",
899210691can often be used to good effect. A user could specify a filename of
899310692F<"rsh cat file |">, or you could change certain filenames as needed:
899410693
899510694=end original
899610695
89971 引数 と 2 引数の形の open() に渡されたファイル名は、
106961 引数 と 2 引数の形の L<C<open>|/open FILEHANDLE,MODE,EXPR> に渡された
8998はじめと終わりの空白が取り除かれ、
10697ファイル名、はじめと終わりの空白が取り除かれ、通常のリダイレクト文字列を
8999通常のリダイレクト文字列を受け付けます。
10698受け付けます。
9000この機能は "magic open" として知られていますが、
10699この機能は "magic open" として知られていますが、普通いい効果をもたらします。
9001普通いい効果をもたらします。
900210700ユーザーは F<"rsh cat file |"> といったファイル名を指定できますし、
900310701特定のファイル名を必要に応じて変更できます。
900410702
900510703 $filename =~ s/(.*\.gz)\s*$/gzip -dc < $1|/;
9006 open(FH, $filename) or die "Can't open $filename: $!";
10704 open(my $fh, $filename)
10705 or die "Can't open $filename: $!";
900710706
900810707=begin original
900910708
901010709Use the three-argument form to open a file with arbitrary weird characters in it,
901110710
901210711=end original
901310712
901410713妙な文字が含まれているようなファイル名をオープンするには、
9015107143 引数の形を使います。
901610715
9017 open(FOO, "<", $file)
10716 open(my $fh, "<", $file)
9018 || die "can't open < $file: $!";
10717 || die "Can't open $file: $!";
901910718
902010719=begin original
902110720
902210721otherwise it's necessary to protect any leading and trailing whitespace:
902310722
902410723=end original
902510724
902610725あるいは、次のようにして、最初と最後の空白を保護します:
902710726
902810727 $file =~ s#^(\s)#./$1#;
9029 open(FOO, "< $file\0")
10728 open(my $fh, "< $file\0")
9030 || die "open failed: $!";
10729 || die "Can't open $file: $!";
903110730
903210731=begin original
903310732
903410733(this may not work on some bizarre filesystems). One should
903510734conscientiously choose between the I<magic> and I<three-argument> form
9036of open():
10735of L<C<open>|/open FILEHANDLE,MODE,EXPR>:
903710736
903810737=end original
903910738
904010739(これは奇妙なファイルシステムでは動作しないかもしれません)。
9041open() の I<magic> と I<3 引数> 形式を誠実に選択するべきです。
10740L<C<open>|/open FILEHANDLE,MODE,EXPR> の I<magic> と I<3 引数> 形式を誠実に
10741選択するべきです。
904210742
9043 open(IN, $ARGV[0]) || die "can't open $ARGV[0]: $!";
10743 open(my $in, $ARGV[0]) || die "Can't open $ARGV[0]: $!";
904410744
904510745=begin original
904610746
904710747will allow the user to specify an argument of the form C<"rsh cat file |">,
904810748but will not work on a filename that happens to have a trailing space, while
904910749
905010750=end original
905110751
905210752とするとユーザーは C<"rsh cat file |"> という形の引数を指定できますが、
905310753末尾にスペースがついてしまったファイル名では動作しません; 一方:
905410754
9055 open(IN, "<", $ARGV[0])
10755 open(my $in, "<", $ARGV[0])
9056 || die "can't open < $ARGV[0]: $!";
10756 || die "Can't open $ARGV[0]: $!";
905710757
905810758=begin original
905910759
9060will have exactly the opposite restrictions.
10760will have exactly the opposite restrictions. (However, some shells
10761support the syntax C<< perl your_program.pl <( rsh cat file ) >>, which
10762produces a filename that can be opened normally.)
906110763
906210764=end original
906310765
906410766はまったく逆の制限があります。
10767(しかし、一部のシェルは C<< perl your_program.pl <( rsh cat file ) >> という
10768文法に対応していて、普通に開くことが出来るファイル名を出力します。)
906510769
10770=item Invoking C-style C<open>
10771
10772(C 形式の C<open> の起動)
10773
906610774=begin original
906710775
9068If you want a "real" C C<open> (see L<open(2)> on your system), then you
10776If you want a "real" C L<open(2)>, then you should use the
9069should use the C<sysopen> function, which involves no such magic (but may
10777L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> function, which involves
9070use subtly different filemodes than Perl open(), which is mapped to C
10778no such magic (but uses different filemodes than Perl
9071fopen()). This is another way to protect your filenames from
10779L<C<open>|/open FILEHANDLE,MODE,EXPR>, which corresponds to C L<fopen(3)>).
9072interpretation. For example:
10780This is another way to protect your filenames from interpretation. For
10781example:
907310782
907410783=end original
907510784
9076もし「本当の」C 言語の C<open> (システムの C<open(2)> を参照してください)
10785もし「本当の」C 言語の L<open(2)> が必要なら、このような副作用のない
9077必要なら、このような副作用のない C<sysopen> 関数を使うべきです
10786L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> 関数を使うべきです
9078(ただし、C の fopen() に割り付けられる Perl の open() とは
10787(ただし、C の L<fopen(3)>対応する Perl の
9079かすかに違うファイルモードを持ちます)。
10788L<C<open>|/open FILEHANDLE,MODE,EXPR> とは違うファイルモードを持ちます)。
908010789これはファイル名を解釈から守るもう一つの方法です。
908110790例えば:
908210791
908310792 use IO::Handle;
9084 sysopen(HANDLE, $path, O_RDWR|O_CREAT|O_EXCL)
10793 sysopen(my $fh, $path, O_RDWR|O_CREAT|O_EXCL)
9085 or die "sysopen $path: $!";
10794 or die "Can't open $path: $!";
9086 $oldfh = select(HANDLE); $| = 1; select($oldfh);
10795 $fh->autoflush(1);
9087 print HANDLE "stuff $$\n";
10796 print $fh "stuff $$\n";
9088 seek(HANDLE, 0, 0);
10797 seek($fh, 0, 0);
9089 print "File contains: ", <HANDLE>;
10798 print "File contains: ", readline($fh);
909010799
909110800=begin original
909210801
9093Using the constructor from the C<IO::Handle> package (or one of its
10802See L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> for some details about
9094subclasses, such as C<IO::File> or C<IO::Socket>), you can generate anonymous
10803mixing reading and writing.
9095filehandles that have the scope of the variables used to hold them, then
9096automatically (but silently) close once their reference counts become
9097zero, typically at scope exit:
909810804
909910805=end original
910010806
9101C<IO::Handle> パッケージ(または C<IO::File> や C<IO::Socket> とった
10807読み書きを混ぜる場合の詳細につては
9102サブパッケージ)のコンストラクタ使うことで、
10808L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> 参照してください。
9103これらへのリファレンスを保持している変数のスコープを持ち、それから
9104参照カウントが 0 になると自動的に (しかし暗黙に) 閉じる
9105無名ファイルハンドルを作成できます:
910610809
9107 use IO::File;
10810=item Portability issues
9108 #...
9109 sub read_myfile_munged {
9110 my $ALL = shift;
9111 # or just leave it undef to autoviv
9112 my $handle = IO::File->new;
9113 open($handle, "<", "myfile") or die "myfile: $!";
9114 $first = <$handle>
9115 or return (); # Automatically closed here.
9116 mung($first) or die "mung failed"; # Or here.
9117 return (first, <$handle>) if $ALL; # Or here.
9118 return $first; # Or here.
9119 }
912010811
9121=begin original
10812(移植性の問題)
912210813
9123B<WARNING:> The previous example has a bug because the automatic
9124close that happens when the refcount on C<handle> reaches zero does not
9125properly detect and report failures. I<Always> close the handle
9126yourself and inspect the return value.
9127
9128=end original
9129
9130B<警告:> 先の例には、自動的に閉じると、C<handle> の参照カウントが
91310 になったことが適切に検出できなくて失敗が報告されるというバグがあります。
9132I<常に> ハンドルを自分自身で閉じて、返り値を調べてください。
9133
9134 close($handle)
9135 || warn "close failed: $!";
9136
913710814=begin original
913810815
9139See L</seek> for some details about mixing reading and writing.
10816See L<perlport/open>.
914010817
914110818=end original
914210819
9143読み書きを混ぜる場合の詳細については L</seek> を参照してください。
10820L<perlport/open> を参照してください。
914410821
9145=begin original
10822=back
914610823
9147Portability issues: L<perlport/open>.
10824=back
914810825
9149=end original
9150
9151移植性の問題: L<perlport/open>。
9152
915310826=item opendir DIRHANDLE,EXPR
915410827X<opendir>
915510828
915610829=for Pod::Functions open a directory
915710830
915810831=begin original
915910832
9160Opens a directory named EXPR for processing by C<readdir>, C<telldir>,
10833Opens a directory named EXPR for processing by
9161C<seekdir>, C<rewinddir>, and C<closedir>. Returns true if successful.
10834L<C<readdir>|/readdir DIRHANDLE>, L<C<telldir>|/telldir DIRHANDLE>,
10835L<C<seekdir>|/seekdir DIRHANDLE,POS>,
10836L<C<rewinddir>|/rewinddir DIRHANDLE>, and
10837L<C<closedir>|/closedir DIRHANDLE>. Returns true if successful.
916210838DIRHANDLE may be an expression whose value can be used as an indirect
916310839dirhandle, usually the real dirhandle name. If DIRHANDLE is an undefined
916410840scalar variable (or array or hash element), the variable is assigned a
916510841reference to a new anonymous dirhandle; that is, it's autovivified.
9166DIRHANDLEs have their own namespace separate from FILEHANDLEs.
10842Dirhandles are the same objects as filehandles; an I/O object can only
10843be open as one of these handle types at once.
916710844
916810845=end original
916910846
9170C<readdir>、C<telldir>、C<seekdir>、C<rewinddir>、C<closedir>
10847L<C<readdir>|/readdir DIRHANDLE>、L<C<telldir>|/telldir DIRHANDLE>、
9171処理するために、EXPR で指定された名前のディレクトリをオープンします。
10848L<C<seekdir>|/seekdir DIRHANDLE,POS>、L<C<rewinddir>|/rewinddir DIRHANDLE>、
10849L<C<closedir>|/closedir DIRHANDLE> で処理するために、EXPR で指定された名前の
10850ディレクトリをオープンします。
917210851成功時には真を返します。
917310852DIRHANDLE は間接ディレクトリハンドルとして使える値(普通は実際のディレクトリ
917410853ハンドルの名前)となる式でも構いません。
917510854DIRHANDLE が未定義のスカラ値(または配列かハッシュの要素)の場合、その変数は
917610855新しい無名ディレクトリハンドルへのリファレンスが代入されます; つまり、
917710856自動有効化されます。
9178DIRHANDLE 、FILEHANDLE は別に名前空間を持っていま
10857ディレクトリハンドルファイルハンドル同じオブジェクトで;
10858一つの I/O オブジェクトは同時にこれらのハンドル型のどちらかとしてのみ
10859開くことができます。
917910860
918010861=begin original
918110862
9182See the example at C<readdir>.
10863See the example at L<C<readdir>|/readdir DIRHANDLE>.
918310864
918410865=end original
918510866
9186C<readdir> の例を参照してください。
10867L<C<readdir>|/readdir DIRHANDLE> の例を参照してください。
918710868
918810869=item ord EXPR
918910870X<ord> X<encoding>
919010871
919110872=item ord
919210873
919310874=for Pod::Functions find a character's numeric representation
919410875
919510876=begin original
919610877
919710878Returns the numeric value of the first character of EXPR.
9198If EXPR is an empty string, returns 0. If EXPR is omitted, uses C<$_>.
10879If EXPR is an empty string, returns 0. If EXPR is omitted, uses
10880L<C<$_>|perlvar/$_>.
919910881(Note I<character>, not byte.)
920010882
920110883=end original
920210884
920310885EXPR の最初の文字の数値としての値を返します。
920410886EXPR が空文字列の場合は、0 を返します。
9205EXPR が省略されると、C<$_> を使います。
10887EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
920610888(バイトではなく I<文字> であることに注意してください。)
920710889
920810890=begin original
920910891
9210For the reverse, see L</chr>.
10892For the reverse, see L<C<chr>|/chr NUMBER>.
921110893See L<perlunicode> for more about Unicode.
921210894
921310895=end original
921410896
9215逆のことをするには L</chr> を参照してください。
10897逆のことをするには L<C<chr>|/chr NUMBER> を参照してください。
921610898Unicode については L<perlunicode> を参照してください。
921710899
9218=item our EXPR
10900=item our VARLIST
921910901X<our> X<global>
922010902
9221=item our TYPE EXPR
10903=item our TYPE VARLIST
922210904
9223=item our EXPR : ATTRS
10905=item our VARLIST : ATTRS
922410906
9225=item our TYPE EXPR : ATTRS
10907=item our TYPE VARLIST : ATTRS
922610908
922710909=for Pod::Functions +5.6.0 declare and assign a package variable (lexical scoping)
922810910
922910911=begin original
923010912
9231C<our> makes a lexical alias to a package variable of the same name in the current
10913L<C<our>|/our VARLIST> makes a lexical alias to a package (i.e. global)
9232package for use within the current lexical scope.
10914variable of the same name in the current package for use within the
10915current lexical scope.
923310916
923410917=end original
923510918
9236C<our> は単純名を、現在のレキシカルスコープ内で使うために、現在のパッケージの
10919L<C<our>|/our VARLIST> は単純名を、現在のレキシカルスコープ内で使うために、
9237同じ名前のパッケージ変数へのレキシカルな別名を作ります。
10920現在のパッケージの同じ名前のパッケージ(つまりグローバルな)変数への
10921レキシカルな別名を作ります。
923810922
923910923=begin original
924010924
9241C<our> has the same scoping rules as C<my> or C<state>, but C<our> only
10925L<C<our>|/our VARLIST> has the same scoping rules as
9242declares an alias, whereas C<my> or C<state> both declare a variable name and
10926L<C<my>|/my VARLIST> or L<C<state>|/state VARLIST>, meaning that it is
9243allocate storage for that name within the current scope.
10927only valid within a lexical scope. Unlike L<C<my>|/my VARLIST> and
10928L<C<state>|/state VARLIST>, which both declare new (lexical) variables,
10929L<C<our>|/our VARLIST> only creates an alias to an existing variable: a
10930package variable of the same name.
924410931
924510932=end original
924610933
9247C<our> は C<my> や C<state> と同じスコープルールを持ちますが、
10934L<C<our>|/our VARLIST> L<C<my>|/my VARLIST>
9248C<our> は別名を宣言するだけである一方、C<my> や C<state> は変数名
10935L<C<state>|/state VARLIST> と同じスコープルール持ちます; つまり
9249宣言し、現在のスコープ内にそ名前のための領域を割り当てます。
10936レキシカルスコープの中でだけ有効です。
10937新しい(レキシカル)変数を宣言する L<C<my>|/my VARLIST> や
10938L<C<state>|/state VARLIST> と異なり、L<C<our>|/our VARLIST> は既に
10939存在する変数への別名を作るだけです: 同じ名前のパッケージ変数です。
925010940
925110941=begin original
925210942
9253This means that when C<use strict 'vars'> is in effect, C<our> lets you use
10943This means that when C<use strict 'vars'> is in effect, L<C<our>|/our
9254a package variable without qualifying it with the package name, but only within
10944VARLIST> lets you use a package variable without qualifying it with the
9255the lexical scope of the C<our> declaration. In this way, C<our> differs from
10945package name, but only within the lexical scope of the
9256C<use vars>, which allows use of an unqualified name I<only> within the
10946L<C<our>|/our VARLIST> declaration. This applies immediately--even
9257affected package, but across scopes.
10947within the same statement.
925810948
925910949=end original
926010950
9261つまり、C<use strict 'vars'> が有効の場合は、C<our> を使うことで、
10951つまり、C<use strict 'vars'> が有効の場合は、L<C<our>|/our VARLIST>
10952使うことで、
926210953パッケージ変数をパッケージ名で修飾することなく使うことができますが、
9263C<our> 宣言のレキシカルスコープ内だけということです。
10954L<C<our>|/our VARLIST> 宣言のレキシカルスコープ内だけということです。
9264の意味で、C<our> は C<use vars> は異なります;
10955(たえ同じ文の中でも)直ちに適用されます
9265これは影響するパッケージの中で I<のみ> 非修飾名を使え、スコープを超えることは
9266できません。
926710956
10957 package Foo;
10958 use v5.36; # which implies "use strict;"
10959
10960 $Foo::foo = 23;
10961
10962 {
10963 our $foo; # alias to $Foo::foo
10964 print $foo; # prints 23
10965 }
10966
10967 print $Foo::foo; # prints 23
10968
10969 print $foo; # ERROR: requires explicit package name
10970
926810971=begin original
926910972
9270If more than one value is listed, the list must be placed
10973This works even if the package variable has not been used before, as
10974package variables spring into existence when first used.
10975
10976=end original
10977
10978これはパッケージ変数がまだ使われていなくても動作します; パッケージ変数は、
10979最初に使われた時にひょっこり現れるからです。
10980
10981 package Foo;
10982 use v5.36;
10983
10984 our $foo = 23; # just like $Foo::foo = 23
10985
10986 print $Foo::foo; # prints 23
10987
10988=begin original
10989
10990Because the variable becomes legal immediately under C<use strict 'vars'>, so
10991long as there is no variable with that name is already in scope, you can then
10992reference the package variable again even within the same statement.
10993
10994=end original
10995
10996変数は C<use strict 'vars'> の基で直ちに正当になるので、
10997スコープ内に同じ名前の変数がない限り、
10998たとえ同じ文の中でもパッケージ変数を再び参照できます。
10999
11000 package Foo;
11001 use v5.36;
11002
11003 my $foo = $foo; # error, undeclared $foo on right-hand side
11004 our $foo = $foo; # no errors
11005
11006=begin original
11007
11008If more than one variable is listed, the list must be placed
927111009in parentheses.
927211010
927311011=end original
927411012
9275複数のを指定する場合は、リストはかっこでくくらなければなりません。
11013複数の変数を指定する場合は、リストはかっこで囲まなければなりません。
927611014
9277 our $foo;
927811015 our($bar, $baz);
927911016
928011017=begin original
928111018
9282An C<our> declaration declares an alias for a package variable that will be visible
11019An L<C<our>|/our VARLIST> declaration declares an alias for a package
11020variable that will be visible
928311021across its entire lexical scope, even across package boundaries. The
928411022package in which the variable is entered is determined at the point
928511023of the declaration, not at the point of use. This means the following
928611024behavior holds:
928711025
928811026=end original
928911027
9290C<our> 宣言はレキシカルスコープ全体に対して(たとえパッケージ境界を
11028L<C<our>|/our VARLIST> 宣言はレキシカルスコープ全体に対して (たとえ
9291越えていても)見える、パッケージ変数への別名を宣言します。
11029パッケージ境界を越えていても)見える、パッケージ変数への別名を宣言します。
929211030この変数が入るパッケージは宣言した時点で定義され、
929311031使用した時点ではありません。
929411032これにより、以下のような振る舞いになります:
929511033
929611034 package Foo;
929711035 our $bar; # declares $Foo::bar for rest of lexical scope
929811036 $bar = 20;
929911037
930011038 package Bar;
930111039 print $bar; # prints 20, as it refers to $Foo::bar
930211040
930311041=begin original
930411042
9305Multiple C<our> declarations with the same name in the same lexical
11043Multiple L<C<our>|/our VARLIST> declarations with the same name in the
11044same lexical
930611045scope are allowed if they are in different packages. If they happen
930711046to be in the same package, Perl will emit warnings if you have asked
9308for them, just like multiple C<my> declarations. Unlike a second
11047for them, just like multiple L<C<my>|/my VARLIST> declarations. Unlike
9309C<my> declaration, which will bind the name to a fresh variable, a
11048a second L<C<my>|/my VARLIST> declaration, which will bind the name to a
9310second C<our> declaration in the same package, in the same scope, is
11049fresh variable, a second L<C<our>|/our VARLIST> declaration in the same
9311merely redundant.
11050package, in the same scope, is merely redundant.
931211051
931311052=end original
931411053
931511054同じレキシカルスコープでも、パッケージが異なっていれば、同じ名前で複数の
9316C<our> 宣言ができます。
11055L<C<our>|/our VARLIST> 宣言ができます。
931711056同じパッケージになっていると、警告が出力されるようになっていれば
9318複数の C<my> 宣言がある場合と同じように警告が出力されます。
11057複数の L<C<my>|/my VARLIST> 宣言がある場合と同じように警告が出力されます。
9319新しい変数を名前に割り当てることになる 2 回目の C<my> 宣言と違って、
11058新しい変数を名前に割り当てることになる 2 回目の L<C<my>|/my VARLIST> 宣言と
9320同じパッケージの同じスコープで 2 回 C<our> 宣言するのは単に冗長です。
11059違って、同じパッケージの同じスコープで 2 回
11060L<C<our>|/our VARLIST> 宣言するのは単に冗長です。
932111061
932211062 use warnings;
932311063 package Foo;
932411064 our $bar; # declares $Foo::bar for rest of lexical scope
932511065 $bar = 20;
932611066
932711067 package Bar;
932811068 our $bar = 30; # declares $Bar::bar for rest of lexical scope
932911069 print $bar; # prints 30
933011070
933111071 our $bar; # emits warning but has no other effect
933211072 print $bar; # still prints 30
933311073
933411074=begin original
933511075
9336An C<our> declaration may also have a list of attributes associated
11076An L<C<our>|/our VARLIST> declaration may also have a list of attributes
9337with it.
11077associated with it.
933811078
933911079=end original
934011080
9341C<our> 宣言には、それと結び付けられる属性のリストを持つこともあります。
11081L<C<our>|/our VARLIST> 宣言には、それと結び付けられる属性のリストを
11082持つこともあります。
934211083
934311084=begin original
934411085
934511086The exact semantics and interface of TYPE and ATTRS are still
9346evolving. TYPE is currently bound to the use of the C<fields> pragma,
11087evolving. TYPE is currently bound to the use of the L<fields> pragma,
9347and attributes are handled using the C<attributes> pragma, or, starting
11088and attributes are handled using the L<attributes> pragma, or, starting
9348from Perl 5.8.0, also via the C<Attribute::Handlers> module. See
11089from Perl 5.8.0, also via the L<Attribute::Handlers> module. See
9349L<perlsub/"Private Variables via my()"> for details, and L<fields>,
11090L<perlsub/"Private Variables via my()"> for details.
9350L<attributes>, and L<Attribute::Handlers>.
935111091
935211092=end original
935311093
935411094TYPE と ATTRS の正確な文法とインターフェースは今でも進化しています。
9355現在のところ、TYPE は C<fields> プラグマの使用と結び付けられていて、
11095現在のところ、TYPE は L<fields> プラグマの使用と結び付けられていて、
9356属性は C<attributes> プラグマか、Perl 5.8.0 からは
11096属性は L<attributes> プラグマか、Perl 5.8.0 からは
9357C<Attribute::Handlers> モジュールと結び付けられています。
11097L<Attribute::Handlers> モジュールと結び付けられています。
9358詳しくはL<perlsub/"Private Variables via my()">, L<fields>,
11098詳しくは L<perlsub/"Private Variables via my()"> を参照してください。
9359L<attributes>, L<Attribute::Handlers> を参照してください。
936011099
11100=begin original
11101
11102Note that with a parenthesised list, L<C<undef>|/undef EXPR> can be used
11103as a dummy placeholder, for example to skip assignment of initial
11104values:
11105
11106=end original
11107
11108かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> は、例えば初期値の代入を
11109飛ばすために、ダミーのプレースホルダとして使えることに注意してください:
11110
11111 our ( undef, $min, $hour ) = localtime;
11112
11113=begin original
11114
11115L<C<our>|/our VARLIST> differs from L<C<use vars>|vars>, which allows
11116use of an unqualified name I<only> within the affected package, but
11117across scopes.
11118
11119=end original
11120
11121L<C<our>|/our VARLIST> は L<C<use vars>|vars> と異なります; スコープを
11122またぐのではなく、影響するパッケージの内側 I<のみ> で完全修飾されていない
11123名前を使えるようにします。
11124
936111125=item pack TEMPLATE,LIST
936211126X<pack>
936311127
936411128=for Pod::Functions convert a list into a binary representation
936511129
936611130=begin original
936711131
936811132Takes a LIST of values and converts it into a string using the rules
936911133given by the TEMPLATE. The resulting string is the concatenation of
937011134the converted values. Typically, each converted value looks
937111135like its machine-level representation. For example, on 32-bit machines
937211136an integer may be represented by a sequence of 4 bytes, which will in
9373Perl be presented as a string that's 4 characters long.
11137Perl be presented as a string that's 4 characters long.
937411138
937511139=end original
937611140
937711141LIST の値を TEMPLATE で与えられたルールを用いて文字列に変換します。
937811142結果の文字列は変換した値を連結したものです。
937911143典型的には、それぞれの変換された値はマシンレベルの表現のように見えます。
938011144例えば、32-bit マシンでは、整数は 4 バイトで表現されるので、
9381Perl では 4 文字の文字列で表現されます。
11145Perl では 4 文字の文字列で表現されます。
938211146
938311147=begin original
938411148
938511149See L<perlpacktut> for an introduction to this function.
938611150
938711151=end original
938811152
938911153この関数の説明については L<perlpacktut> を参照してください。
939011154
939111155=begin original
939211156
939311157The TEMPLATE is a sequence of characters that give the order and type
939411158of values, as follows:
939511159
939611160=end original
939711161
939811162TEMPLATE は、以下のような値の型と順番を指定する文字を並べたものです:
939911163
940011164=begin original
940111165
940211166 a A string with arbitrary binary data, will be null padded.
940311167 A A text (ASCII) string, will be space padded.
940411168 Z A null-terminated (ASCIZ) string, will be null padded.
940511169
940611170=end original
940711171
940811172 a 任意のバイナリデータを含む文字列、ヌル文字で埋める。
940911173 A テキスト (ASCII) 文字列、スペース文字で埋める。
941011174 Z ヌル文字終端 (ASCIZ) 文字列、ヌル文字で埋める。
941111175
941211176=begin original
941311177
941411178 b A bit string (ascending bit order inside each byte,
941511179 like vec()).
941611180 B A bit string (descending bit order inside each byte).
941711181 h A hex string (low nybble first).
941811182 H A hex string (high nybble first).
941911183
942011184=end original
942111185
942211186 b ビット列 (バイトごとに昇ビット順、vec() と同じ)。
942311187 B ビット列 (バイトごとに降ビット順)。
942411188 h 16 進数文字列 (低位ニブルが先)。
942511189 H 16 進数文字列 (高位ニブルが先)。
942611190
942711191=begin original
942811192
942911193 c A signed char (8-bit) value.
943011194 C An unsigned char (octet) value.
943111195 W An unsigned char value (can be greater than 255).
943211196
943311197=end original
943411198
943511199 c signed char (8 ビット) 値。
943611200 C unsigned char (オクテット) 値。
943711201 W unsigned char 値 (255 より大きいかもしれません)。
943811202
943911203=begin original
944011204
944111205 s A signed short (16-bit) value.
944211206 S An unsigned short value.
944311207
944411208=end original
944511209
944611210 s signed short (16 ビット) 値。
944711211 S unsigned short 値。
944811212
944911213=begin original
945011214
945111215 l A signed long (32-bit) value.
945211216 L An unsigned long value.
945311217
945411218=end original
945511219
945611220 l signed long (32 ビット) 値。
945711221 L unsigned long 値。
945811222
945911223=begin original
946011224
946111225 q A signed quad (64-bit) value.
946211226 Q An unsigned quad value.
946311227 (Quads are available only if your system supports 64-bit
946411228 integer values _and_ if Perl has been compiled to support
946511229 those. Raises an exception otherwise.)
946611230
946711231=end original
946811232
946911233 q 符号付き 64 ビット整数。
947011234 Q 符号なし 64 ビット整数。
947111235 (64 ビット整数は、システムが 64 ビット整数に対応していて、かつ Perl が
947211236 64 ビット整数対応としてコンパイルされている場合にのみ使用可能です。
947311237 それ以外の場合は例外が発生します。)
947411238
947511239=begin original
947611240
947711241 i A signed integer value.
9478 I A unsigned integer value.
11242 I An unsigned integer value.
947911243 (This 'integer' is _at_least_ 32 bits wide. Its exact
948011244 size depends on what a local C compiler calls 'int'.)
948111245
948211246=end original
948311247
948411248 i signed int 値。
948511249 I unsigned int 値。
9486 (ここでの 'integer' は 「最低」 32 bits 幅です。正確なサイズは
11250 (ここでの 'integer' は 「最低」 32 ビット幅です。正確なサイズは
9487 ローカルの C コンパイラの'int'のサイズに依存します。)
11251 ローカルの C コンパイラの 'int' のサイズに依存します。)
948811252
948911253=begin original
949011254
949111255 n An unsigned short (16-bit) in "network" (big-endian) order.
949211256 N An unsigned long (32-bit) in "network" (big-endian) order.
949311257 v An unsigned short (16-bit) in "VAX" (little-endian) order.
949411258 V An unsigned long (32-bit) in "VAX" (little-endian) order.
949511259
949611260=end original
949711261
949811262 n "network" 順序 (ビッグエンディアン) の unsigned short (16 ビット)。
949911263 N "network" 順序 (ビッグエンディアン) の unsigned long (32 ビット)。
950011264 v "VAX" 順序 (リトルエンディアン) の unsigned short (16 ビット)。
950111265 V "VAX" 順序 (リトルエンディアン) の unsigned long (32 ビット)。
950211266
950311267=begin original
950411268
950511269 j A Perl internal signed integer value (IV).
950611270 J A Perl internal unsigned integer value (UV).
950711271
950811272=end original
950911273
951011274 j Perl 内部符号付き整数 (IV)。
951111275 J Perl 内部符号なし整数 (UV)。
951211276
951311277=begin original
951411278
951511279 f A single-precision float in native format.
951611280 d A double-precision float in native format.
951711281
951811282=end original
951911283
952011284 f 機種依存の単精度浮動小数点数。
952111285 d 機種依存の倍精度浮動小数点数。
952211286
952311287=begin original
952411288
952511289 F A Perl internal floating-point value (NV) in native format
952611290 D A float of long-double precision in native format.
952711291 (Long doubles are available only if your system supports
9528 long double values _and_ if Perl has been compiled to
11292 long double values. Raises an exception otherwise.
9529 support those. Raises an exception otherwise.)
11293 Note that there are different long double formats.)
953011294
953111295=end original
953211296
953311297 F ネイティブフォーマットの Perl 内部浮動小数点数 (NV)
953411298 D ネイティブフォーマットの長い倍精度浮動小数点数(long double)。
9535 (long double は、システムが long double に対応していて、かつ Perl が
11299 (long double は、システムが long double に対応している場合にのみ
9536 long double 対応としてコンパイルされている場合にのみ使用可能です。
11300 使用可能です。それ以外の場合は例外が発生します。
9537 それ以外の場合は例外が発生ます。)
11301 long double 型式の場合は異なることに注意てください。)
953811302
953911303=begin original
954011304
954111305 p A pointer to a null-terminated string.
954211306 P A pointer to a structure (fixed-length string).
954311307
954411308=end original
954511309
954611310 p ヌル文字で終端する文字列へのポインタ。
954711311 P 構造体 (固定長文字列) へのポインタ。
954811312
954911313=begin original
955011314
955111315 u A uuencoded string.
955211316 U A Unicode character number. Encodes to a character in char-
955311317 acter mode and UTF-8 (or UTF-EBCDIC in EBCDIC platforms) in
9554 byte mode.
11318 byte mode. Also on EBCDIC platforms, the character number will
11319 be the native EBCDIC value for character numbers below 256.
11320 This allows most programs using this feature to not have to
11321 care which type of platform they are running on.
955511322
11323
955611324=end original
955711325
955811326 u uuencode 文字列。
955911327 U Unicode 文字番号。文字モードでは文字に、バイトモードなら UTF-8 に
956011328 (EBCDIC システムでは UTF-EBCDIC に)エンコードされます。
11329 また EBCDIC プラットフォームでは、文字番号が 256 より下の場合は
11330 EBCDIC にネイティブな値です。
11331 これにより、この機能を使うほとんどのプログラムで、どの種類の
11332 プラットフォームで実行されるかを気にする必要がなくなります。
956111333
956211334=begin original
956311335
956411336 w A BER compressed integer (not an ASN.1 BER, see perlpacktut
956511337 for details). Its bytes represent an unsigned integer in
956611338 base 128, most significant digit first, with as few digits
956711339 as possible. Bit eight (the high bit) is set on each byte
956811340 except the last.
956911341
957011342=end original
957111343
957211344 w A BER 圧縮変数(ASN.1 BER ではありません; 詳細については perlpacktut を
957311345 参照してください)。このバイト列はできるだけ少ない桁数で表現された
957411346 128 を基とした符号なし整数で、最上位ビットから順に並びます。
957511347 最後のバイト以外の各バイトのビット 8 (上位ビット) がセットされます。
957611348
957711349=begin original
957811350
957911351 x A null byte (a.k.a ASCII NUL, "\000", chr(0))
958011352 X Back up a byte.
958111353 @ Null-fill or truncate to absolute position, counted from the
958211354 start of the innermost ()-group.
958311355 . Null-fill or truncate to absolute position specified by
958411356 the value.
958511357 ( Start of a ()-group.
958611358
958711359=end original
958811360
958911361 x ヌル文字 (つまり ASCII NUL, "\000", chr(0))
959011362 X 1 文字後退。
959111363 @ 一番内側の () の組の開始位置から数えて、絶対位置までヌル文字で
959211364 埋めるか切り詰める。
959311365 . 値で指定した絶対位置までヌル文字で埋めるか切り詰める。
959411366 ( () の組の開始。
959511367
959611368=begin original
959711369
959811370One or more modifiers below may optionally follow certain letters in the
959911371TEMPLATE (the second column lists letters for which the modifier is valid):
960011372
960111373=end original
960211374
960311375以下に示す一つまたは複数の修飾子を、TEMPLATE の文字のいくつかにオプションで
960411376付けることができます(表の 2 列目は、その修飾子が有効な文字です):
960511377
960611378=begin original
960711379
960811380 ! sSlLiI Forces native (short, long, int) sizes instead
960911381 of fixed (16-/32-bit) sizes.
961011382
961111383=end original
961211384
961311385 ! sSlLiI 固定の(16/32 ビット)サイズではなく、ネイティブな
961411386 (short, long, int)サイズを強制する。
961511387
961611388=begin original
961711389
9618 xX Make x and X act as alignment commands.
11390 ! xX Make x and X act as alignment commands.
961911391
962011392=end original
962111393
9622 xX x と X をアライメントコマンドとして振舞わせる。
11394 ! xX x と X をアライメントコマンドとして振舞わせる。
962311395
962411396=begin original
962511397
9626 nNvV Treat integers as signed instead of unsigned.
11398 ! nNvV Treat integers as signed instead of unsigned.
962711399
962811400=end original
962911401
9630 nNvV 整数を符号なしではなく符号付きとして扱わせる。
11402 ! nNvV 整数を符号なしではなく符号付きとして扱わせる。
963111403
963211404=begin original
963311405
9634 @. Specify position as byte offset in the internal
11406 ! @. Specify position as byte offset in the internal
963511407 representation of the packed string. Efficient
963611408 but dangerous.
963711409
963811410=end original
963911411
9640 @. pack された内部表現のバイトオフセットとして位置を指定する。
11412 ! @. pack された内部表現のバイトオフセットとして位置を指定する。
964111413 効率的ですが危険です。
964211414
964311415=begin original
964411416
964511417 > sSiIlLqQ Force big-endian byte-order on the type.
964611418 jJfFdDpP (The "big end" touches the construct.)
964711419
964811420=end original
964911421
965011422 > sSiIlLqQ これらの型のバイト順をビッグエンディアンに強制します。
965111423 jJfFdDpP (「大きい端」が構造に触れています。)
965211424
965311425=begin original
965411426
965511427 < sSiIlLqQ Force little-endian byte-order on the type.
965611428 jJfFdDpP (The "little end" touches the construct.)
965711429
965811430=end original
965911431
966011432 < sSiIlLqQ これらの型のバイト順をリトルエンディアンに強制します。
966111433 jJfFdDpP (「小さい端」が構造に触れています。)
966211434
966311435=begin original
966411436
9665The C<< > >> and C<< < >> modifiers can also be used on C<()> groups
11437The C<< > >> and C<< < >> modifiers can also be used on C<()> groups
9666to force a particular byte-order on all components in that group,
11438to force a particular byte-order on all components in that group,
966711439including all its subgroups.
966811440
966911441=end original
967011442
967111443C<< > >> と C<< < >> の修飾子は C<()>-グループでも使えます;
967211444この場合はそのグループと全ての副グループ内の全ての要素を特定のバイト順に
967311445強制します。
967411446
967511447=begin comment
967611448
967711449Larry recalls that the hex and bit string formats (H, h, B, b) were added to
9678pack for processing data from NASA's Magellan probe. Magellan was in an
11450pack for processing data from NASA's Magellan probe. Magellan was in an
967911451elliptical orbit, using the antenna for the radar mapping when close to
968011452Venus and for communicating data back to Earth for the rest of the orbit.
968111453There were two transmission units, but one of these failed, and then the
968211454other developed a fault whereby it would randomly flip the sense of all the
968311455bits. It was easy to automatically detect complete records with the correct
968411456sense, and complete records with all the bits flipped. However, this didn't
968511457recover the records where the sense flipped midway. A colleague of Larry's
968611458was able to pretty much eyeball where the records flipped, so they wrote an
968711459editor named kybble (a pun on the dog food Kibbles 'n Bits) to enable him to
968811460manually correct the records and recover the data. For this purpose pack
968911461gained the hex and bit string format specifiers.
969011462
969111463git shows that they were added to perl 3.0 in patch #44 (Jan 1991, commit
96921146427e2fb84680b9cc1), but the patch description makes no mention of their
969311465addition, let alone the story behind them.
969411466
969511467=end comment
969611468
969711469=begin original
969811470
969911471The following rules apply:
970011472
970111473=end original
970211474
970311475以下の条件が適用されます:
970411476
9705=over
11477=over
970611478
970711479=item *
970811480
970911481=begin original
971011482
971111483Each letter may optionally be followed by a number indicating the repeat
971211484count. A numeric repeat count may optionally be enclosed in brackets, as
971311485in C<pack("C[80]", @arr)>. The repeat count gobbles that many values from
971411486the LIST when used with all format types other than C<a>, C<A>, C<Z>, C<b>,
971511487C<B>, C<h>, C<H>, C<@>, C<.>, C<x>, C<X>, and C<P>, where it means
971611488something else, described below. Supplying a C<*> for the repeat count
971711489instead of a number means to use however many items are left, except for:
971811490
971911491=end original
972011492
972111493これらの文字の後には、繰り返し数を示す数字を付けることができます。
972211494数値の繰り返し数は C<pack "C[80]", @arr> のように大かっこで
972311495囲むこともできます。
972411496C<a>, C<A>, C<Z>, C<b>, C<B>, C<h>, C<H>, C<@>, C<.>, C<x>, C<X>, C<P>
972511497以外の全ての型では、LIST から繰り返し数の値を取り出して使います。
972611498繰り返し数に C<*> を指定すると、以下の例外を除いて、
972711499その時点で残っているすべての要素を意味します。
972811500
9729=over
11501=over
973011502
9731=item *
11503=item *
973211504
973311505=begin original
973411506
973511507C<@>, C<x>, and C<X>, where it is equivalent to C<0>.
973611508
973711509=end original
973811510
973911511C<@>, C<x>, C<X> では C<0> と等価です。
974011512
9741=item *
11513=item *
974211514
974311515=begin original
974411516
974511517<.>, where it means relative to the start of the string.
974611518
974711519=end original
974811520
9749C<.> では文字列の先頭からの相対位置を意味します。
11521<.> では文字列の先頭からの相対位置を意味します。
975011522
9751=item *
11523=item *
975211524
975311525=begin original
975411526
975511527C<u>, where it is equivalent to 1 (or 45, which here is equivalent).
975611528
975711529=end original
975811530
975911531C<u> では 1 (あるいはここでは 45 でも等価です) と等価です。
976011532
9761=back
11533=back
976211534
976311535=begin original
976411536
976511537One can replace a numeric repeat count with a template letter enclosed in
976611538brackets to use the packed byte length of the bracketed template for the
976711539repeat count.
976811540
976911541=end original
977011542
977111543このテンプレートでパックされたバイト長を繰り返し数として使うために、
977211544大かっこで囲まれたテンプレートで数値の繰り返し数を置き換えることが
977311545できます。
977411546
977511547=begin original
977611548
977711549For example, the template C<x[L]> skips as many bytes as in a packed long,
977811550and the template C<"$t X[$t] $t"> unpacks twice whatever $t (when
977911551variable-expanded) unpacks. If the template in brackets contains alignment
978011552commands (such as C<x![d]>), its packed length is calculated as if the
978111553start of the template had the maximal possible alignment.
978211554
978311555=end original
978411556
978511557例えば、テンプレート C<x[L]> は long でパックされたバイト数分だけスキップし、
978611558テンプレート C<"$t X[$t] $t"> は $t (変数展開された場合)を
978711559unpack したものの 2 倍を unpack します。
978811560(C<x![d]> のように) 大かっこにアライメントコマンドが含まれている場合、
978911561パックされた長さは、テンプレートの先頭で最大限可能なアライメントを
979011562持っているものとして計算されます。
979111563
979211564=begin original
979311565
979411566When used with C<Z>, a C<*> as the repeat count is guaranteed to add a
979511567trailing null byte, so the resulting string is always one byte longer than
979611568the byte length of the item itself.
979711569
979811570=end original
979911571
980011572C<Z> で、繰り返し数として C<*> が使われた場合、末尾にヌルバイトが
9801保証されるので、パックされた結果は常に要素 C<length> の値より
11573保証されるので、結果の文字列は常にアイテム自身バイト長よりも 1 バイト
98021 大きくなります。
11574くなります。
980311575
980411576=begin original
980511577
980611578When used with C<@>, the repeat count represents an offset from the start
980711579of the innermost C<()> group.
980811580
980911581=end original
981011582
981111583C<@> で使うと、繰り返し数は一番内側の C<()> グループの先頭からのオフセットを
981211584表現します。
981311585
981411586=begin original
981511587
981611588When used with C<.>, the repeat count determines the starting position to
981711589calculate the value offset as follows:
981811590
981911591=end original
982011592
982111593C<.> で使われると、繰り返し数は以下のようにして、
982211594値のオフセットを計算するための開始位置を決定するために使われます。
982311595
9824=over
11596=over
982511597
982611598=item *
982711599
982811600=begin original
982911601
983011602If the repeat count is C<0>, it's relative to the current position.
983111603
983211604=end original
983311605
983411606繰り返し数が C<0> なら、現在位置からの相対位置となります。
983511607
983611608=item *
983711609
983811610=begin original
983911611
984011612If the repeat count is C<*>, the offset is relative to the start of the
984111613packed string.
984211614
984311615=end original
984411616
9845繰り返し数が C<*> なら、オフセットは pack された文字列の先頭からの相対位置です。
11617繰り返し数が C<*> なら、オフセットは pack された文字列の先頭からの
11618相対位置です。
984611619
984711620=item *
984811621
984911622=begin original
985011623
985111624And if it's an integer I<n>, the offset is relative to the start of the
985211625I<n>th innermost C<( )> group, or to the start of the string if I<n> is
985311626bigger then the group level.
985411627
985511628=end original
985611629
985711630そして整数 I<n> なら、オフセットは一番内側から I<n> 番目の C<( )> グループの
985811631先頭、あるいは I<n> がグループレベルより大きい場合は文字列の先頭からの
985911632相対位置です。
986011633
986111634=back
986211635
986311636=begin original
986411637
986511638The repeat count for C<u> is interpreted as the maximal number of bytes
9866to encode per line of output, with 0, 1 and 2 replaced by 45. The repeat
11639to encode per line of output, with 0, 1 and 2 replaced by 45. The repeat
986711640count should not be more than 65.
986811641
986911642=end original
987011643
987111644C<u> での繰り返し回数は、出力行毎に最大何バイトまでをエンコードするかを
987211645示します; 0, 1, 2 は 45 として扱われます。
987311646繰り返し数は 65 を超えてはなりません。
987411647
987511648=item *
987611649
987711650=begin original
987811651
987911652The C<a>, C<A>, and C<Z> types gobble just one value, but pack it as a
988011653string of length count, padding with nulls or spaces as needed. When
988111654unpacking, C<A> strips trailing whitespace and nulls, C<Z> strips everything
988211655after the first null, and C<a> returns data with no stripping at all.
988311656
988411657=end original
988511658
988611659C<a>, C<A>, C<Z> という型を使うと、値を一つだけ取り出して使いますが、
988711660繰り返し数で示す長さの文字列となるように、必要に応じてヌル文字か
988811661スペース文字を付け足します。
988911662unpack するとき、C<A> は後続の空白やヌル文字を取り除きます; C<Z> は最初の
989011663ヌル文字以降の全てを取り除きます; C<a> はデータを取り除くことなく
989111664そのまま返します。
989211665
989311666=begin original
989411667
989511668If the value to pack is too long, the result is truncated. If it's too
989611669long and an explicit count is provided, C<Z> packs only C<$count-1> bytes,
989711670followed by a null byte. Thus C<Z> always packs a trailing null, except
989811671when the count is 0.
989911672
990011673=end original
990111674
990211675pack する値が長すぎる場合、結果は切り詰められます。
990311676長すぎてかつ明示的に個数が指定されている場合、
990411677C<Z> は C<$count-1> バイトまで pack し、その後にヌルバイトがつきます。
990511678従って、C<Z> は、繰り返し数が 0 の場合を除いて、常に末尾にヌルバイトが
990611679つきます。
990711680
990811681=item *
990911682
991011683=begin original
991111684
991211685Likewise, the C<b> and C<B> formats pack a string that's that many bits long.
991311686Each such format generates 1 bit of the result. These are typically followed
991411687by a repeat count like C<B8> or C<B64>.
991511688
991611689=end original
991711690
991811691同様に、C<b> や C<B> は、繰り返し数で示すビット長のビット列に pack します。
991911692これらの各文字は結果の 1 ビットを生成します。
992011693これらは典型的には C<B8> や C<B64> のような繰り返しカウントが引き続きます。
992111694
992211695=begin original
992311696
992411697Each result bit is based on the least-significant bit of the corresponding
992511698input character, i.e., on C<ord($char)%2>. In particular, characters C<"0">
992611699and C<"1"> generate bits 0 and 1, as do characters C<"\000"> and C<"\001">.
992711700
992811701=end original
992911702
993011703結果ビットのそれぞれは対応する入力文字の最下位ビットを基にします
993111704(つまり C<ord($char)%2>)。
993211705特に、文字 C<"0"> と C<"1"> は文字 C<"\000"> と C<"\001"> と同様に、
993311706ビット 0 と 1 を生成します。
993411707
993511708=begin original
993611709
993711710Starting from the beginning of the input string, each 8-tuple
993811711of characters is converted to 1 character of output. With format C<b>,
993911712the first character of the 8-tuple determines the least-significant bit of a
994011713character; with format C<B>, it determines the most-significant bit of
994111714a character.
994211715
994311716=end original
994411717
9945pack() の入力文字列の先頭から始めて、8 タプル毎に 1 文字の出力に
11718pack() の入力文字列の先頭から始めて、8 タプル毎に 1 文字の出力に変換されます。
9946変換されます。
994711719C<b> フォーマットでは 8 タプルの最初の文字が出力の最下位ビットとなります;
994811720C<B> フォーマットでは出力の最上位ビットとなります。
994911721
995011722=begin original
995111723
995211724If the length of the input string is not evenly divisible by 8, the
995311725remainder is packed as if the input string were padded by null characters
995411726at the end. Similarly during unpacking, "extra" bits are ignored.
995511727
995611728=end original
995711729
995811730もし入力文字列の長さが 8 で割り切れない場合、余りの部分は入力文字列の
995911731最後にヌル文字がパッディングされているものとしてパックされます。
996011732同様に、unpack 中は「余分な」ビットは無視されます。
996111733
996211734=begin original
996311735
996411736If the input string is longer than needed, remaining characters are ignored.
996511737
996611738=end original
996711739
996811740入力文字列が必要な分よりも長い場合、余分な文字は無視されます。
996911741
997011742=begin original
997111743
9972A C<*> for the repeat count uses all characters of the input field.
11744A C<*> for the repeat count uses all characters of the input field.
997311745On unpacking, bits are converted to a string of C<0>s and C<1>s.
997411746
997511747=end original
997611748
9977繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が
11749繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が使われます。
9978使われます。
997911750unpack 時にはビット列は C<0> と C<1> の文字列に変換されます。
998011751
998111752=item *
998211753
998311754=begin original
998411755
998511756The C<h> and C<H> formats pack a string that many nybbles (4-bit groups,
998611757representable as hexadecimal digits, C<"0".."9"> C<"a".."f">) long.
998711758
998811759=end original
998911760
999011761C<h> や C<H> は、多ニブル長(16 進文字である C<"0".."9"> C<"a".."f"> で
999111762表現可能な 4 ビットグループ)のニブル列に pack します。
999211763
999311764=begin original
999411765
9995For each such format, pack() generates 4 bits of result.
11766For each such format, L<C<pack>|/pack TEMPLATE,LIST> generates 4 bits of result.
999611767With non-alphabetical characters, the result is based on the 4 least-significant
999711768bits of the input character, i.e., on C<ord($char)%16>. In particular,
999811769characters C<"0"> and C<"1"> generate nybbles 0 and 1, as do bytes
999911770C<"\000"> and C<"\001">. For characters C<"a".."f"> and C<"A".."F">, the result
1000011771is compatible with the usual hexadecimal digits, so that C<"a"> and
10001C<"A"> both generate the nybble C<0xA==10>. Use only these specific hex
11772C<"A"> both generate the nybble C<0xA==10>. Use only these specific hex
1000211773characters with this format.
1000311774
1000411775=end original
1000511776
10006このようなフォーマット文字のそれぞれについて、pack()
11777このようなフォーマット文字のそれぞれについて、L<C<pack>|/pack TEMPLATE,LIST>
1000711778結果の 4 ビットを生成します。
1000811779英字でない文字の場合、結果は入力文字の下位 4 ビットを
1000911780基にします(つまり C<ord($char)%16>)。
1001011781特に、文字 C<"0"> と C<"1"> はバイト C<"\000"> と C<"\001"> と同様に
1001111782ニブル 0 と 1 を生成します。
10012文字 C<"a".."f"> と C<"A".."F"> の場合は結果は通常の
11783文字 C<"a".."f"> と C<"A".."F"> の場合は結果は通常の 16 進数と同じ結果に
1001316 進数と同じ結果にりますので、C<"a"> と C<"A"> はどちらも
11784ので、C<"a"> と C<"A"> はどちらも ニブル C<0xa==10> を生成します。
10014ニブル C<0xa==10> を生成します。
1001511785これらの 16 進文字はこの特定のフォーマットでだけ使ってください。
1001611786
1001711787=begin original
1001811788
10019Starting from the beginning of the template to pack(), each pair
11789Starting from the beginning of the template to
11790L<C<pack>|/pack TEMPLATE,LIST>, each pair
1002011791of characters is converted to 1 character of output. With format C<h>, the
1002111792first character of the pair determines the least-significant nybble of the
1002211793output character; with format C<H>, it determines the most-significant
1002311794nybble.
1002411795
1002511796=end original
1002611797
10027pack() のテンプレートの先頭から始めて、2 文字毎に 1 文字の出力
11798L<C<pack>|/pack TEMPLATE,LIST> のテンプレートの先頭から始めて、2 文字毎に
10028変換されます。
117991 文字の出力に変換されます。
1002911800C<h> フォーマットでは 1 文字目が出力の最下位ニブルとなり、
1003011801C<H> フォーマットでは出力の最上位ニブルとなります。
1003111802
1003211803=begin original
1003311804
1003411805If the length of the input string is not even, it behaves as if padded by
1003511806a null character at the end. Similarly, "extra" nybbles are ignored during
1003611807unpacking.
1003711808
1003811809=end original
1003911810
1004011811入力文字列の長さが偶数でない場合、最後にヌル文字でパッディングされて
1004111812いるかのように振る舞います。
1004211813同様に、unpack 中は「余分な」ニブルは無視されます。
1004311814
1004411815=begin original
1004511816
1004611817If the input string is longer than needed, extra characters are ignored.
1004711818
1004811819=end original
1004911820
1005011821入力文字列が必要な分より長い場合、余分な部分は無視されます。
1005111822
1005211823=begin original
1005311824
1005411825A C<*> for the repeat count uses all characters of the input field. For
10055unpack(), nybbles are converted to a string of hexadecimal digits.
11826L<C<unpack>|/unpack TEMPLATE,EXPR>, nybbles are converted to a string of
11827hexadecimal digits.
1005611828
1005711829=end original
1005811830
10059繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が
11831繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が使われます。
10060使われます。
11832L<C<unpack>|/unpack TEMPLATE,EXPR> 時にはニブルは 16 進数の文字列に
10061unpack() 時にはニブルは 16 進数の文字列に変換されます。
11833変換されます。
1006211834
1006311835=item *
1006411836
1006511837=begin original
1006611838
1006711839The C<p> format packs a pointer to a null-terminated string. You are
1006811840responsible for ensuring that the string is not a temporary value, as that
1006911841could potentially get deallocated before you got around to using the packed
1007011842result. The C<P> format packs a pointer to a structure of the size indicated
1007111843by the length. A null pointer is created if the corresponding value for
10072C<p> or C<P> is C<undef>; similarly with unpack(), where a null pointer
11844C<p> or C<P> is L<C<undef>|/undef EXPR>; similarly with
10073unpacks into C<undef>.
11845L<C<unpack>|/unpack TEMPLATE,EXPR>, where a null pointer unpacks into
11846L<C<undef>|/undef EXPR>.
1007411847
1007511848=end original
1007611849
1007711850C<p> は、ヌル文字終端文字列へのポインタを pack します。
1007811851文字列が一時的な値でない(つまり pack された結果を使う前に文字列が
1007911852解放されない) ことに責任を持つ必要があります。
1008011853C<P> は、指定した長さの構造体へのポインタを pack します。
10081C<p> または C<P> に対応する値が C<undef> だった場合、
11854C<p> または C<P> に対応する値が L<C<undef>|/undef EXPR> だった場合、
10082ヌルポインタが作成されます; ヌルポインタが C<undef>unpack される
11855ヌルポインタが作成されます; ヌルポインタが L<C<undef>|/undef EXPR> に
10083unpack() と同様です。
11856unpack される L<C<unpack>|/unpack TEMPLATE,EXPR> と同様です。
1008411857
1008511858=begin original
1008611859
1008711860If your system has a strange pointer size--meaning a pointer is neither as
1008811861big as an int nor as big as a long--it may not be possible to pack or
1008911862unpack pointers in big- or little-endian byte order. Attempting to do
1009011863so raises an exception.
1009111864
1009211865=end original
1009311866
1009411867システムのポインタが変わったサイズの場合--つまり、int の大きさでも
1009511868long の大きさでもない場合--ポインタをビッグエンディアンやリトルエンディアンの
1009611869バイト順で pack や unpack することはできません。
1009711870そうしようとすると例外が発生します。
1009811871
1009911872=item *
1010011873
1010111874=begin original
1010211875
1010311876The C</> template character allows packing and unpacking of a sequence of
1010411877items where the packed structure contains a packed item count followed by
1010511878the packed items themselves. This is useful when the structure you're
1010611879unpacking has encoded the sizes or repeat counts for some of its fields
1010711880within the structure itself as separate fields.
1010811881
1010911882=end original
1011011883
1011111884C</> テンプレート文字は、アイテムの数の後にアイテムそのものが入っている形の
1011211885アイテム列を pack 及び unpack します。
1011311886これは、unpack したい構造体が、サイズや繰り返し数が構造体自身の中に
1011411887独立したフィールドとしてエンコードされている場合に有効です。
1011511888
1011611889=begin original
1011711890
10118For C<pack>, you write I<length-item>C</>I<sequence-item>, and the
11891For L<C<pack>|/pack TEMPLATE,LIST>, you write
11892I<length-item>C</>I<sequence-item>, and the
1011911893I<length-item> describes how the length value is packed. Formats likely
1012011894to be of most use are integer-packing ones like C<n> for Java strings,
1012111895C<w> for ASN.1 or SNMP, and C<N> for Sun XDR.
1012211896
1012311897=end original
1012411898
10125C<pack> では I<length-item>C</>I<string-item> の形になり、
11899L<C<pack>|/pack TEMPLATE,LIST> では I<length-item>C</>I<string-item> の
11900形になり、
1012611901I<length-item> は長さの値がどのように pack されているかを指定します。
1012711902もっともよく使われるのは Java 文字列 のための C<n>、ASN.1 や SNMP のための
1012811903C<w>、Sun XDR のための C<N> といった整数型です。
1012911904
1013011905=begin original
1013111906
10132For C<pack>, I<sequence-item> may have a repeat count, in which case
11907For L<C<pack>|/pack TEMPLATE,LIST>, I<sequence-item> may have a repeat
11908count, in which case
1013311909the minimum of that and the number of available items is used as the argument
1013411910for I<length-item>. If it has no repeat count or uses a '*', the number
1013511911of available items is used.
1013611912
1013711913=end original
1013811914
10139C<pack> では、I<sequence-item> は繰り返し数を持つことがあり、その場合は
11915L<C<pack>|/pack TEMPLATE,LIST> では、I<sequence-item> は繰り返し数を
10140その最小値と利用可能なアイテムの数は I<length-item> のための引数として
11916持つことがあり、その場合はその最小値と利用可能なアイテムの数は
10141使われます。
11917I<length-item> のための引数として使われます。
1014211918繰り返し数がなかったり、'*' を使うと、利用可能なアイテムの数が使われます。
1014311919
1014411920=begin original
1014511921
10146For C<unpack>, an internal stack of integer arguments unpacked so far is
11922For L<C<unpack>|/unpack TEMPLATE,EXPR>, an internal stack of integer
11923arguments unpacked so far is
1014711924used. You write C</>I<sequence-item> and the repeat count is obtained by
1014811925popping off the last element from the stack. The I<sequence-item> must not
1014911926have a repeat count.
1015011927
1015111928=end original
1015211929
10153C<unpack> では、今まで unpack した数値引数の内部スタックが使われます。
11930L<C<unpack>|/unpack TEMPLATE,EXPR> では、今まで unpack した数値引数の
11931内部スタックが使われます。
1015411932C</>I<sequence-item> と書いて、繰り返し数はスタックから最後の要素を
1015511933取り出すことで得ます。
1015611934I<sequence-item> は繰り返し数を持っていてはいけません。
1015711935
1015811936=begin original
1015911937
1016011938If I<sequence-item> refers to a string type (C<"A">, C<"a">, or C<"Z">),
1016111939the I<length-item> is the string length, not the number of strings. With
1016211940an explicit repeat count for pack, the packed string is adjusted to that
1016311941length. For example:
1016411942
1016511943=end original
1016611944
1016711945I<sequence-item> が文字列型 (C<"A">, C<"a">, C<"Z">) を参照している場合、
1016811946I<length-item> は文字列の数ではなく、文字列の長さです。
1016911947pack で明示的な繰り返し数があると、pack された文字列は与えられた
1017011948長さに調整されます。
1017111949例えば:
1017211950
1017311951 This code: gives this result:
1017411952
1017511953 unpack("W/a", "\004Gurusamy") ("Guru")
1017611954 unpack("a3/A A*", "007 Bond J ") (" Bond", "J")
1017711955 unpack("a3 x2 /A A*", "007: Bond, J.") ("Bond, J", ".")
1017811956
1017911957 pack("n/a* w/a","hello,","world") "\000\006hello,\005world"
1018011958 pack("a/W2", ord("a") .. ord("z")) "2ab"
1018111959
1018211960=begin original
1018311961
10184The I<length-item> is not returned explicitly from C<unpack>.
11962The I<length-item> is not returned explicitly from
11963L<C<unpack>|/unpack TEMPLATE,EXPR>.
1018511964
1018611965=end original
1018711966
10188I<length-item> は C<unpack> から明示的には返されません。
11967I<length-item> は L<C<unpack>|/unpack TEMPLATE,EXPR> から明示的には
11968返されません。
1018911969
1019011970=begin original
1019111971
1019211972Supplying a count to the I<length-item> format letter is only useful with
1019311973C<A>, C<a>, or C<Z>. Packing with a I<length-item> of C<a> or C<Z> may
1019411974introduce C<"\000"> characters, which Perl does not regard as legal in
1019511975numeric strings.
1019611976
1019711977=end original
1019811978
1019911979I<length-item> 文字に繰り返し数をつけるのは、
1020011980文字が C<A>, C<a>, C<Z> でない限りは有用ではありません。
1020111981C<a> や C<Z> を I<length-item> として pack すると C<"\000"> 文字が
1020211982出力されることがあり、Perl はこれを有効な数値文字列として認識しません。
1020311983
1020411984=item *
1020511985
1020611986=begin original
1020711987
1020811988The integer types C<s>, C<S>, C<l>, and C<L> may be
1020911989followed by a C<!> modifier to specify native shorts or
1021011990longs. As shown in the example above, a bare C<l> means
1021111991exactly 32 bits, although the native C<long> as seen by the local C compiler
1021211992may be larger. This is mainly an issue on 64-bit platforms. You can
1021311993see whether using C<!> makes any difference this way:
1021411994
1021511995=end original
1021611996
1021711997C<s>, C<S>, C<l>, C<L> の整数タイプに引き続いて C<!> 修飾子を
1021811998つけることで、ネイティブの short や long を指定できます。
1021911999上述のように、C<l> は正確に 32 ビットですが、ネイティブな
1022012000(ローカルな C コンパイラによる)C<long> はもっと大きいかもしれません。
1022112001これは主に 64 ビットプラットフォームで意味があります。
1022212002C<!> を使うことによって違いがあるかどうかは以下のようにして調べられます:
1022312003
10224 printf "format s is %d, s! is %d\n",
12004 printf "format s is %d, s! is %d\n",
1022512005 length pack("s"), length pack("s!");
1022612006
10227 printf "format l is %d, l! is %d\n",
12007 printf "format l is %d, l! is %d\n",
1022812008 length pack("l"), length pack("l!");
1022912009
1023012010=begin original
1023112011
1023212012C<i!> and C<I!> are also allowed, but only for completeness' sake:
1023312013they are identical to C<i> and C<I>.
1023412014
1023512015=end original
1023612016
1023712017C<i!> と C<I!> も動作しますが、単に完全性のためだけです;
1023812018これは C<i> 及び C<I> と同じです。
1023912019
1024012020=begin original
1024112021
1024212022The actual sizes (in bytes) of native shorts, ints, longs, and long
1024312023longs on the platform where Perl was built are also available from
1024412024the command line:
1024512025
1024612026=end original
1024712027
1024812028Perl がビルドされたプラットフォームでの short, int, long, long long の
1024912029実際の(バイト数での)サイズはコマンドラインから:
1025012030
1025112031 $ perl -V:{short,int,long{,long}}size
1025212032 shortsize='2';
1025312033 intsize='4';
1025412034 longsize='4';
1025512035 longlongsize='8';
1025612036
1025712037=begin original
1025812038
10259or programmatically via the C<Config> module:
12039or programmatically via the L<C<Config>|Config> module:
1026012040
1026112041=end original
1026212042
10263あるいは C<Config> モジュールからプログラムで:
12043あるいは L<C<Config>|Config> モジュールからプログラムで:
1026412044
1026512045 use Config;
1026612046 print $Config{shortsize}, "\n";
1026712047 print $Config{intsize}, "\n";
1026812048 print $Config{longsize}, "\n";
1026912049 print $Config{longlongsize}, "\n";
1027012050
1027112051=begin original
1027212052
10273C<$Config{longlongsize}> is undefined on systems without
12053C<$Config{longlongsize}> is undefined on systems without
1027412054long long support.
1027512055
1027612056=end original
1027712057
1027812058システムが long long に対応していない場合は C<$Config{longlongsize}> は
1027912059未定義値になります。
1028012060
1028112061=item *
1028212062
1028312063=begin original
1028412064
1028512065The integer formats C<s>, C<S>, C<i>, C<I>, C<l>, C<L>, C<j>, and C<J> are
1028612066inherently non-portable between processors and operating systems because
1028712067they obey native byteorder and endianness. For example, a 4-byte integer
10288120680x12345678 (305419896 decimal) would be ordered natively (arranged in and
1028912069handled by the CPU registers) into bytes as
1029012070
1029112071=end original
1029212072
1029312073整数フォーマット C<s>, C<S>, C<i>, C<I>, C<l>, C<L>, C<j>, C<J> は
1029412074ネイティブなバイト順序とエンディアンに従っているため、
1029512075本質的にプロセッサ間や OS 間で移植性がありません。
1029612076例えば 4 バイトの整数 0x12345678 (10 進数では 305419896) は
1029712077内部では(CPU レジスタによって変換され扱われる形では)
1029812078以下のようなバイト列に並べられます:
1029912079
1030012080 0x12 0x34 0x56 0x78 # big-endian
1030112081 0x78 0x56 0x34 0x12 # little-endian
1030212082
1030312083=begin original
1030412084
1030512085Basically, Intel and VAX CPUs are little-endian, while everybody else,
1030612086including Motorola m68k/88k, PPC, Sparc, HP PA, Power, and Cray, are
10307big-endian. Alpha and MIPS can be either: Digital/Compaq uses (well, used)
12087big-endian. Alpha and MIPS can be either: Digital/Compaq uses (well, used)
1030812088them in little-endian mode, but SGI/Cray uses them in big-endian mode.
1030912089
1031012090=end original
1031112091
1031212092基本的に、Intel と VAX の CPU はリトルエンディアンです; 一方、
1031312093Motorola m68k/88k, PPC, Sparc, HP PA, Power, Cray などを含むその他の全ては
1031412094ビッグエンディアンです。
1031512095Alpha と MIPS は両方ともあります: Digital/Compaq はリトルエンディアンモードで
1031612096使っています (えーと、いました) が、SGI/Cray はビッグエンディアンモードで
1031712097使っています。
1031812098
1031912099=begin original
1032012100
1032112101The names I<big-endian> and I<little-endian> are comic references to the
1032212102egg-eating habits of the little-endian Lilliputians and the big-endian
1032312103Blefuscudians from the classic Jonathan Swift satire, I<Gulliver's Travels>.
1032412104This entered computer lingo via the paper "On Holy Wars and a Plea for
1032512105Peace" by Danny Cohen, USC/ISI IEN 137, April 1, 1980.
1032612106
1032712107=end original
1032812108
10329I<ビッグエンディアン> と I<リトルエンディアン> の名前は
12109I<ビッグエンディアン> と I<リトルエンディアン> の名前は
10330古典である「ガリバー旅行記」とリリパット族の卵を食べる習慣から
12110ジョナサン=スウィフトによる風刺小説の古典 I<ガリバー旅行記> で卵を
12111小さい方からむくリリパット国と大きい方からむくブレフスキュ国から
1033112112取られています。
1033212113"On Holy Wars and a Plea for Peace" by Danny Cohen, USC/ISI IEN 137,
1033312114April 1, 1980 の文書からコンピュータ用語として取り入れられました。
1033412115
1033512116=begin original
1033612117
1033712118Some systems may have even weirder byte orders such as
1033812119
1033912120=end original
1034012121
1034112122以下のような、さらに変わったバイト順序を持つシステムもあるかもしれません:
1034212123
1034312124 0x56 0x78 0x12 0x34
1034412125 0x34 0x12 0x78 0x56
1034512126
1034612127=begin original
1034712128
12129These are called mid-endian, middle-endian, mixed-endian, or just weird.
12130
12131=end original
12132
12133これらは mid-endian, middle-endian, mixed-endian あるいは単におかしなものと
12134呼ばれます。
12135
12136=begin original
12137
1034812138You can determine your system endianness with this incantation:
1034912139
1035012140=end original
1035112141
1035212142システムの設定は以下のようにして調べられます:
1035312143
10354 printf("%#02x ", $_) for unpack("W*", pack L=>0x12345678);
12144 printf("%#02x ", $_) for unpack("W*", pack L=>0x12345678);
1035512145
1035612146=begin original
1035712147
1035812148The byteorder on the platform where Perl was built is also available
1035912149via L<Config>:
1036012150
1036112151=end original
1036212152
1036312153Perl がビルドされたプラットフォームでのバイト順序は
1036412154L<Config> 経由か:
1036512155
1036612156 use Config;
1036712157 print "$Config{byteorder}\n";
1036812158
1036912159=begin original
1037012160
1037112161or from the command line:
1037212162
1037312163=end original
1037412164
1037512165あるいはコマンドラインで:
1037612166
1037712167 $ perl -V:byteorder
1037812168
1037912169=begin original
1038012170
1038112171Byteorders C<"1234"> and C<"12345678"> are little-endian; C<"4321">
10382and C<"87654321"> are big-endian.
12172and C<"87654321"> are big-endian. Systems with multiarchitecture binaries
12173will have C<"ffff">, signifying that static information doesn't work,
12174one must use runtime probing.
1038312175
1038412176=end original
1038512177
1038612178C<"1234"> と C<"12345678"> はリトルエンディアンです;
1038712179C<"4321"> と C<"87654321"> はビッグエンディアンです。
12180マルチアーキテクチャバイナリを持つシステムは
12181C<"ffff"> となります; これは静的な情報は動作せず、実行時調査を使う必要が
12182あることを示します。
1038812183
1038912184=begin original
1039012185
10391For portably packed integers, either use the formats C<n>, C<N>, C<v>,
12186For portably packed integers, either use the formats C<n>, C<N>, C<v>,
1039212187and C<V> or else use the C<< > >> and C<< < >> modifiers described
1039312188immediately below. See also L<perlport>.
1039412189
1039512190=end original
1039612191
1039712192移植性のあるパック化された整数がほしい場合は、
1039812193C<n>, C<N>, C<v>, C<V> フォーマットを使うか、
1039912194直後で説明する C<< > >> と C<< < >> の修飾子が使えます。
1040012195L<perlport> も参照してください。
1040112196
1040212197=item *
1040312198
1040412199=begin original
1040512200
12201Also floating point numbers have endianness. Usually (but not always)
12202this agrees with the integer endianness. Even though most platforms
12203these days use the IEEE 754 binary format, there are differences,
12204especially if the long doubles are involved. You can see the
12205C<Config> variables C<doublekind> and C<longdblkind> (also C<doublesize>,
12206C<longdblsize>): the "kind" values are enums, unlike C<byteorder>.
12207
12208=end original
12209
12210また、浮動小数点数にもエンディアンがあります。
12211通常は(但し常にではありません)これは整数のエンディアンと同じです。
12212最近のほとんどのプラットフォームが IEEE 754 バイナリ形式を使っているにも
12213関わらず、(特に long double 関連で) 相違点があります。
12214C<Config> 変数 C<doublekind> と C<longdblkind> (および C<doublesize>,
12215C<longdblsize>) を参照できます: "kind" 値は C<byteorder> と異なり、
12216順序値です。
12217
12218=begin original
12219
12220Portability-wise the best option is probably to keep to the IEEE 754
1222164-bit doubles, and of agreed-upon endianness. Another possibility
12222is the C<"%a">) format of L<C<printf>|/printf FILEHANDLE FORMAT, LIST>.
12223
12224=end original
12225
12226移植性を考慮した最良の選択肢はおそらく、IEEE 754 64-bit double と同意した
12227エンディアンを維持することです。
12228もう一つの可能性は L<C<printf>|/printf FILEHANDLE FORMAT, LIST> の
12229C<"%a"> 型式です。
12230
12231=item *
12232
12233=begin original
12234
1040612235Starting with Perl 5.10.0, integer and floating-point formats, along with
10407the C<p> and C<P> formats and C<()> groups, may all be followed by the
12236the C<p> and C<P> formats and C<()> groups, may all be followed by the
1040812237C<< > >> or C<< < >> endianness modifiers to respectively enforce big-
10409or little-endian byte-order. These modifiers are especially useful
12238or little-endian byte-order. These modifiers are especially useful
10410given how C<n>, C<N>, C<v>, and C<V> don't cover signed integers,
12239given how C<n>, C<N>, C<v>, and C<V> don't cover signed integers,
104111224064-bit integers, or floating-point values.
1041212241
1041312242=end original
1041412243
1041512244Perl 5.10.0 から、C<p> と C<P> フォーマットや C<()> グループと同様、
1041612245全ての整数と浮動小数点数のフォーマットは、C<< > >> や C<< < >> の
1041712246エンディアン修飾子をつけることで、それぞれ
1041812247ビッグエンディアンとリトルエンディアンに強制させることができます。
1041912248C<n>, C<N>, C<v>, C<V> は符号付き整数、64 ビット整数、浮動小数点数に
1042012249対応していないので、これは特に有用です。
1042112250
1042212251=begin original
1042312252
1042412253Here are some concerns to keep in mind when using an endianness modifier:
1042512254
1042612255=end original
1042712256
1042812257エンディアン修飾子を使うときに心に留めておくべきことを記します:
1042912258
1043012259=over
1043112260
10432=item *
12261=item *
1043312262
1043412263=begin original
1043512264
10436Exchanging signed integers between different platforms works only
12265Exchanging signed integers between different platforms works only
1043712266when all platforms store them in the same format. Most platforms store
1043812267signed integers in two's-complement notation, so usually this is not an issue.
1043912268
1044012269=end original
1044112270
1044212271異なったプラットフォームで符号付き整数を交換することは、全ての
1044312272プラットフォームで同じフォーマットで保存されている場合にのみうまくいきます。
1044412273ほとんどのプラットフォームでは符号付き整数は 2 の補数記法で保存するので、
1044512274普通はこれは問題になりません。
1044612275
10447=item *
12276=item *
1044812277
1044912278=begin original
1045012279
1045112280The C<< > >> or C<< < >> modifiers can only be used on floating-point
1045212281formats on big- or little-endian machines. Otherwise, attempting to
1045312282use them raises an exception.
1045412283
1045512284=end original
1045612285
1045712286C<< > >> や C<< < >> の修飾子はビッグエンディアンやリトルエンディアンの
1045812287マシンでの浮動小数点フォーマットでのみ使えます。
1045912288それ以外では、そのようなことをすると例外が発生します。
1046012289
10461=item *
12290=item *
1046212291
1046312292=begin original
1046412293
1046512294Forcing big- or little-endian byte-order on floating-point values for
1046612295data exchange can work only if all platforms use the same
1046712296binary representation such as IEEE floating-point. Even if all
1046812297platforms are using IEEE, there may still be subtle differences. Being able
1046912298to use C<< > >> or C<< < >> on floating-point values can be useful,
1047012299but also dangerous if you don't know exactly what you're doing.
1047112300It is not a general way to portably store floating-point values.
1047212301
1047312302=end original
1047412303
1047512304データ交換のために浮動小数点数のバイト順をビッグエンディアンかリトル
1047612305エンディアンに強制することは、全てのプラットフォームが
1047712306IEEE 浮動小数点フォーマットのような同じバイナリ表現の場合にのみ
1047812307うまくいきます。
1047912308たとえ全てのプラットフォームが IEEE を使っていても、そこには微妙な違いが
1048012309あるかもしれません。
10481浮動小数点数に C<< > >> や C<< < >> が使えることは便利な場合が
12310浮動小数点数に C<< > >> や C<< < >> が使えることは便利な場合がありますが、
10482ありますが、もし自分が何をしているかを正確に理解していなければ、
12311もし自分が何をしているかを正確に理解していなければ、危険です。
10483危険です。
1048412312移植性のある浮動小数点数の保存のための一般的な方法はありません。
1048512313
10486=item *
12314=item *
1048712315
1048812316=begin original
1048912317
1049012318When using C<< > >> or C<< < >> on a C<()> group, this affects
1049112319all types inside the group that accept byte-order modifiers,
1049212320including all subgroups. It is silently ignored for all other
1049312321types. You are not allowed to override the byte-order within a group
1049412322that already has a byte-order modifier suffix.
1049512323
1049612324=end original
1049712325
1049812326C<()> グループで C<< > >> や C<< < >> を使うと、これは、副グループを
1049912327含む全ての型のうち、バイト順修飾子を受け入れる全てのものに影響与えます。
1050012328その他の型については沈黙のうちに無視されます。
1050112329既にバイト順接尾辞を持っているグループ内のバイト順を上書きすることは
1050212330できません。
1050312331
1050412332=back
1050512333
1050612334=item *
1050712335
1050812336=begin original
1050912337
1051012338Real numbers (floats and doubles) are in native machine format only.
1051112339Due to the multiplicity of floating-point formats and the lack of a
1051212340standard "network" representation for them, no facility for interchange has been
1051312341made. This means that packed floating-point data written on one machine
1051412342may not be readable on another, even if both use IEEE floating-point
1051512343arithmetic (because the endianness of the memory representation is not part
1051612344of the IEEE spec). See also L<perlport>.
1051712345
1051812346=end original
1051912347
1052012348実数 (float と double) は、機種依存のフォーマットしかありません。
10521いろんな浮動小数点数のフォーマットが在り、標準的な
12349いろんな浮動小数点数のフォーマットが在り、標準的な "network" 表現といったものが
10522"network" 表現といったものがないため、データ交換のための機能は
12350ないため、データ交換のための機能は用意してありません。
10523用意してありません。
1052412351つまり、あるマシンで pack した浮動小数点数は、別のマシンでは
1052512352読めないかもしれないということです; たとえ双方で IEEE フォーマットの
1052612353浮動小数点数演算を行なっていてもです (IEEE の仕様では、メモリ表現上の
1052712354バイト順序までは、規定されていないからです)。
1052812355L<perlport> も参照してください。
1052912356
1053012357=begin original
1053112358
1053212359If you know I<exactly> what you're doing, you can use the C<< > >> or C<< < >>
1053312360modifiers to force big- or little-endian byte-order on floating-point values.
1053412361
1053512362=end original
1053612363
1053712364もし何をしようとしているのかを I<正確に> 理解しているなら、浮動小数点数の
1053812365バイト順をビッグエンディアンやリトルエンディアンに強制するために、
1053912366C<< > >> と C<< < >> の修飾子が使えます。
1054012367
1054112368=begin original
1054212369
1054312370Because Perl uses doubles (or long doubles, if configured) internally for
10544all numeric calculation, converting from double into float and thence
12371all numeric calculation, converting from double into float and thence
1054512372to double again loses precision, so C<unpack("f", pack("f", $foo)>)
1054612373will not in general equal $foo.
1054712374
1054812375=end original
1054912376
10550Perl では、すべての数値演算のために、内部的に double (または
12377Perl では、すべての数値演算のために、内部的に double (または設定によっては
10551設定によっては long double) を使用しているので、
12378long double) を使用しているので、double から float へ変換し、それから再び
10552double から float へ変換し、それから再び double に戻すと
12379double に戻すと精度が落ちることになり、C<unpack("f", pack("f", $foo)>) は、
10553精度が落ちることになり、C<unpack("f", pack("f", $foo)>) は、
1055412380一般には $foo と同じではありません。
1055512381
1055612382=item *
1055712383
1055812384=begin original
1055912385
1056012386Pack and unpack can operate in two modes: character mode (C<C0> mode) where
10561the packed string is processed per character, and UTF-8 mode (C<U0> mode)
12387the packed string is processed per character, and UTF-8 byte mode (C<U0> mode)
1056212388where the packed string is processed in its UTF-8-encoded Unicode form on
1056312389a byte-by-byte basis. Character mode is the default
1056412390unless the format string starts with C<U>. You
10565can always switch mode mid-format with an explicit
12391can always switch mode mid-format with an explicit
10566C<C0> or C<U0> in the format. This mode remains in effect until the next
12392C<C0> or C<U0> in the format. This mode remains in effect until the next
1056712393mode change, or until the end of the C<()> group it (directly) applies to.
1056812394
1056912395=end original
1057012396
1057112397pack と unpack は二つのモードで操作します: pack された文字列を文字単位で
1057212398処理する文字モード (C<C0> モード) と、pack された文字列を、バイト毎に、
1057312399その UTF-8 エンコードされた形式で処理するUTF-8 モード (C<U0> モード) です。
1057412400文字モードはフォーマット文字列が C<U> で始まっていない限りはデフォルトです。
1057512401モードはフォーマット中に明示的に C<C0> または C<U0> と書くことでいつでも
1057612402切り替えられます。
10577モードは次のモードに切り替えられるか、(直接)適用された () グループが
12403モードは次のモードに切り替えられるか、(直接)適用された C<()> グループが
1057812404終了するまで有効です。
1057912405
1058012406=begin original
1058112407
10582Using C<C0> to get Unicode characters while using C<U0> to get I<non>-Unicode
12408Using C<C0> to get Unicode characters while using C<U0> to get I<non>-Unicode
1058312409bytes is not necessarily obvious. Probably only the first of these
1058412410is what you want:
1058512411
1058612412=end original
1058712413
1058812414Unicode 文字を取得するのに C<C0> を使い、I<非> Unicode バイトを取得するのに
1058912415C<U0> を使うというのは必ずしも明白ではありません。
1059012416おそらく、これらのうち最初のものだけが望みのものでしょう:
1059112417
10592 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
12418 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
1059312419 perl -CS -ne 'printf "%v04X\n", $_ for unpack("C0A*", $_)'
1059412420 03B1.03C9
10595 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
12421 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
1059612422 perl -CS -ne 'printf "%v02X\n", $_ for unpack("U0A*", $_)'
1059712423 CE.B1.CF.89
10598 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
12424 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
1059912425 perl -C0 -ne 'printf "%v02X\n", $_ for unpack("C0A*", $_)'
1060012426 CE.B1.CF.89
10601 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
12427 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
1060212428 perl -C0 -ne 'printf "%v02X\n", $_ for unpack("U0A*", $_)'
1060312429 C3.8E.C2.B1.C3.8F.C2.89
1060412430
1060512431=begin original
1060612432
1060712433Those examples also illustrate that you should not try to use
10608C<pack>/C<unpack> as a substitute for the L<Encode> module.
12434L<C<pack>|/pack TEMPLATE,LIST>/L<C<unpack>|/unpack TEMPLATE,EXPR> as a
12435substitute for the L<Encode> module.
1060912436
1061012437=end original
1061112438
10612これらの例は、C<pack>/C<unpack> L<Encode> モジュールの代わりとして
12439これらの例は、L<C<pack>|/pack TEMPLATE,LIST>/
12440L<C<unpack>|/unpack TEMPLATE,EXPR> を L<Encode> モジュールの代わりとして
1061312441使おうとするべきではないということも示しています。
1061412442
1061512443=item *
1061612444
1061712445=begin original
1061812446
1061912447You must yourself do any alignment or padding by inserting, for example,
10620enough C<"x">es while packing. There is no way for pack() and unpack()
12448enough C<"x">es while packing. There is no way for
10621to know where characters are going to or coming from, so they
12449L<C<pack>|/pack TEMPLATE,LIST> and L<C<unpack>|/unpack TEMPLATE,EXPR>
12450to know where characters are going to or coming from, so they
1062212451handle their output and input as flat sequences of characters.
1062312452
1062412453=end original
1062512454
1062612455pack するときに、例えば十分な数の C<"x"> を挿入することによって
1062712456アライメントやパッディングを行うのは全て自分でしなければなりません。
10628文字列がどこへ行くかやどこから来たかを pack() や unpack()
12457L<C<pack>|/pack TEMPLATE,LIST> L<C<unpack>|/unpack TEMPLATE,EXPR> は、
10629知る方法はないので、C<pack> (と C<unpack>) は出力と入力フラットな
12458文字列がどこへ行くかやどこから来たか
10630文字列として扱います。
12459知る方法はないので、出力と入力をフラットな文字列として扱います。
1063112460
1063212461=item *
1063312462
1063412463=begin original
1063512464
1063612465A C<()> group is a sub-TEMPLATE enclosed in parentheses. A group may
10637take a repeat count either as postfix, or for unpack(), also via the C</>
12466take a repeat count either as postfix, or for
12467L<C<unpack>|/unpack TEMPLATE,EXPR>, also via the C</>
1063812468template character. Within each repetition of a group, positioning with
1063912469C<@> starts over at 0. Therefore, the result of
1064012470
1064112471=end original
1064212472
1064312473C<()> のグループはかっこで囲われた副テンプレートです。
10644グループは繰り返し数を取ることができます; 接尾辞によるか、unpack() の場合は
12474グループは繰り返し数を取ることができます; 接尾辞によるか、
10645C</> テンプレート文字によります。
12475L<C<unpack>|/unpack TEMPLATE,EXPR> の場合は C</> テンプレート文字によります。
1064612476グループの繰り返し毎に、C<@> の位置は 0 になります。
1064712477従って、以下の結果は:
1064812478
1064912479 pack("@1A((@2A)@3A)", qw[X Y Z])
1065012480
1065112481=begin original
1065212482
1065312483is the string C<"\0X\0\0YZ">.
1065412484
1065512485=end original
1065612486
1065712487文字列 C<"\0X\0\0YZ"> です。
1065812488
1065912489=item *
1066012490
1066112491=begin original
1066212492
1066312493C<x> and C<X> accept the C<!> modifier to act as alignment commands: they
1066412494jump forward or back to the closest position aligned at a multiple of C<count>
10665characters. For example, to pack() or unpack() a C structure like
12495characters. For example, to L<C<pack>|/pack TEMPLATE,LIST> or
12496L<C<unpack>|/unpack TEMPLATE,EXPR> a C structure like
1066612497
1066712498=end original
1066812499
1066912500C<x> と C<X> にはアライメントコマンドとして C<!> 修飾子を付けることができます:
1067012501これは C<count> 文字の倍数のアライメントとなる、もっとも近い位置に移動します。
10671例えば、以下のような構造体を pack() または unpack() するめに
12502例えば、以下のような C 構造体を L<C<pack>|/pack TEMPLATE,LIST> または
12503L<C<unpack>|/unpack TEMPLATE,EXPR> するには
1067212504
1067312505 struct {
1067412506 char c; /* one signed, 8-bit character */
10675 double d;
12507 double d;
1067612508 char cc[2];
1067712509 }
1067812510
1067912511=begin original
1068012512
1068112513one may need to use the template C<c x![d] d c[2]>. This assumes that
1068212514doubles must be aligned to the size of double.
1068312515
1068412516=end original
1068512517
1068612518C<W x![d] d W[2]> というテンプレートを使う必要があるかもしれません。
1068712519これは double が double のサイズでアライメントされていることを
1068812520仮定しています。
1068912521
1069012522=begin original
1069112523
1069212524For alignment commands, a C<count> of 0 is equivalent to a C<count> of 1;
1069312525both are no-ops.
1069412526
1069512527=end original
1069612528
10697アライメントコマンドに対しては、C<count> に 0 を指定するのは 1 を
12529アライメントコマンドに対しては、C<count> に 0 を指定するのは
10698指定するのと等価です; どちらも何もしません。
12530C<count> に 1 を指定するのと等価です; どちらも何もしません。
1069912531
1070012532=item *
1070112533
1070212534=begin original
1070312535
1070412536C<n>, C<N>, C<v> and C<V> accept the C<!> modifier to
1070512537represent signed 16-/32-bit integers in big-/little-endian order.
1070612538This is portable only when all platforms sharing packed data use the
1070712539same binary representation for signed integers; for example, when all
1070812540platforms use two's-complement representation.
1070912541
1071012542=end original
1071112543
10712C<n>, C<N>, C<v>, C<V> は
12544C<n>, C<N>, C<v>, C<V> はビッグ/リトルエンディアンの順序で符号付き 16 または
10713ビッグ/リトルエンディアンの順序で符号付き 16 または
107141254532 ビット整数で表現するための C<!> 修飾子を受け入れます。
1071512546これは pack されたデータを共有する全てのプラットフォームが
1071612547符号付き整数について同じバイナリ表現を使う場合にのみ移植性があります;
1071712548例えば、全てのプラットフォームで 2 の補数表現を使う場合です。
1071812549
1071912550=item *
1072012551
1072112552=begin original
1072212553
1072312554Comments can be embedded in a TEMPLATE using C<#> through the end of line.
1072412555White space can separate pack codes from each other, but modifiers and
1072512556repeat counts must follow immediately. Breaking complex templates into
1072612557individual line-by-line components, suitably annotated, can do as much to
1072712558improve legibility and maintainability of pack/unpack formats as C</x> can
1072812559for complicated pattern matches.
1072912560
1073012561=end original
1073112562
1073212563TEMPLATE の中の C<#> から行末まではコメントです。
1073312564空白は pack コードをそれぞれ分けるために使えますが、修飾子と
1073412565繰り返し数は直後に置かなければなりません。
1073512566複雑なテンプレートを個々の行単位の要素に分解して適切に注釈をつけると、
1073612567複雑なパターンマッチングに対する C</x> と同じぐらい、pack/unpack
1073712568フォーマットの読みやすさと保守性が向上します。
1073812569
1073912570=item *
1074012571
1074112572=begin original
1074212573
10743If TEMPLATE requires more arguments than pack() is given, pack()
12574If TEMPLATE requires more arguments than L<C<pack>|/pack TEMPLATE,LIST>
12575is given, L<C<pack>|/pack TEMPLATE,LIST>
1074412576assumes additional C<""> arguments. If TEMPLATE requires fewer arguments
1074512577than given, extra arguments are ignored.
1074612578
1074712579=end original
1074812580
10749TEMPLATE が要求する引数の数が pack() が実際に与えている数より多い場合、
12581TEMPLATE が要求する引数の数が L<C<pack>|/pack TEMPLATE,LIST> が実際に
10750pack() は追加の C<""> 引数があものと仮定します。
12582与えてい数より多い場合、
12583L<C<pack>|/pack TEMPLATE,LIST> は追加の C<""> 引数があるものと仮定します。
1075112584TEMPLATE が要求する引数の数の方が少ない場合、余分の引数は無視されます。
1075212585
12586=item *
12587
12588=begin original
12589
12590Attempting to pack the special floating point values C<Inf> and C<NaN>
12591(infinity, also in negative, and not-a-number) into packed integer values
12592(like C<"L">) is a fatal error. The reason for this is that there simply
12593isn't any sensible mapping for these special values into integers.
12594
12595=end original
12596
12597特殊浮動小数点値 C<Inf> と C<NaN>
12598((負を含む)無限と非数) を (C<"L"> のような) 整数値に pack しようとすると
12599致命的エラーとなります。
12600この理由は、単に特殊値を整数に割り当てられないからです。
12601
1075312602=back
1075412603
1075512604=begin original
1075612605
1075712606Examples:
1075812607
1075912608=end original
1076012609
1076112610例:
1076212611
1076312612 $foo = pack("WWWW",65,66,67,68);
1076412613 # foo eq "ABCD"
1076512614 $foo = pack("W4",65,66,67,68);
1076612615 # same thing
1076712616 $foo = pack("W4",0x24b6,0x24b7,0x24b8,0x24b9);
1076812617 # same thing with Unicode circled letters.
1076912618 $foo = pack("U4",0x24b6,0x24b7,0x24b8,0x24b9);
1077012619 # same thing with Unicode circled letters. You don't get the
1077112620 # UTF-8 bytes because the U at the start of the format caused
1077212621 # a switch to U0-mode, so the UTF-8 bytes get joined into
1077312622 # characters
1077412623 $foo = pack("C0U4",0x24b6,0x24b7,0x24b8,0x24b9);
1077512624 # foo eq "\xe2\x92\xb6\xe2\x92\xb7\xe2\x92\xb8\xe2\x92\xb9"
1077612625 # This is the UTF-8 encoding of the string in the
1077712626 # previous example
1077812627
1077912628 $foo = pack("ccxxcc",65,66,67,68);
1078012629 # foo eq "AB\0\0CD"
1078112630
1078212631 # NOTE: The examples above featuring "W" and "c" are true
1078312632 # only on ASCII and ASCII-derived systems such as ISO Latin 1
1078412633 # and UTF-8. On EBCDIC systems, the first example would be
1078512634 # $foo = pack("WWWW",193,194,195,196);
1078612635
1078712636 $foo = pack("s2",1,2);
1078812637 # "\001\000\002\000" on little-endian
1078912638 # "\000\001\000\002" on big-endian
1079012639
1079112640 $foo = pack("a4","abcd","x","y","z");
1079212641 # "abcd"
1079312642
1079412643 $foo = pack("aaaa","abcd","x","y","z");
1079512644 # "axyz"
1079612645
1079712646 $foo = pack("a14","abcdefg");
1079812647 # "abcdefg\0\0\0\0\0\0\0"
1079912648
1080012649 $foo = pack("i9pl", gmtime);
1080112650 # a real struct tm (on my system anyway)
1080212651
1080312652 $utmp_template = "Z8 Z8 Z16 L";
1080412653 $utmp = pack($utmp_template, @utmp1);
1080512654 # a struct utmp (BSDish)
1080612655
1080712656 @utmp2 = unpack($utmp_template, $utmp);
1080812657 # "@utmp1" eq "@utmp2"
1080912658
1081012659 sub bintodec {
1081112660 unpack("N", pack("B32", substr("0" x 32 . shift, -32)));
1081212661 }
1081312662
1081412663 $foo = pack('sx2l', 12, 34);
1081512664 # short 12, two zero bytes padding, long 34
1081612665 $bar = pack('s@4l', 12, 34);
1081712666 # short 12, zero fill to position 4, long 34
1081812667 # $foo eq $bar
1081912668 $baz = pack('s.l', 12, 4, 34);
1082012669 # short 12, zero fill to position 4, long 34
1082112670
1082212671 $foo = pack('nN', 42, 4711);
1082312672 # pack big-endian 16- and 32-bit unsigned integers
1082412673 $foo = pack('S>L>', 42, 4711);
1082512674 # exactly the same
1082612675 $foo = pack('s<l<', -42, 4711);
1082712676 # pack little-endian 16- and 32-bit signed integers
1082812677 $foo = pack('(sl)<', -42, 4711);
1082912678 # exactly the same
1083012679
1083112680=begin original
1083212681
10833The same template may generally also be used in unpack().
12682The same template may generally also be used in
12683L<C<unpack>|/unpack TEMPLATE,EXPR>.
1083412684
1083512685=end original
1083612686
10837一般には、pack で使用したものと同じテンプレートが
12687一般には、同じテンプレートが L<C<unpack>|/unpack TEMPLATE,EXPR> でも
10838unpack() 関数でも使用できます。
12688使用できます。
1083912689
1084012690=item package NAMESPACE
1084112691
1084212692=item package NAMESPACE VERSION
1084312693X<package> X<module> X<namespace> X<version>
1084412694
1084512695=item package NAMESPACE BLOCK
1084612696
1084712697=item package NAMESPACE VERSION BLOCK
1084812698X<package> X<module> X<namespace> X<version>
1084912699
1085012700=for Pod::Functions declare a separate global namespace
1085112701
1085212702=begin original
1085312703
1085412704Declares the BLOCK or the rest of the compilation unit as being in the
1085512705given namespace. The scope of the package declaration is either the
1085612706supplied code BLOCK or, in the absence of a BLOCK, from the declaration
1085712707itself through the end of current scope (the enclosing block, file, or
10858C<eval>). That is, the forms without a BLOCK are operative through the end
12708L<C<eval>|/eval EXPR>). That is, the forms without a BLOCK are
10859of the current scope, just like the C<my>, C<state>, and C<our> operators.
12709operative through the end of the current scope, just like the
10860All unqualified dynamic identifiers in this scope will be in the given
12710L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>, and
10861namespace, except where overridden by another C<package> declaration or
12711L<C<our>|/our VARLIST> operators. All unqualified dynamic identifiers
12712in this scope will be in the given namespace, except where overridden by
12713another L<C<package>|/package NAMESPACE> declaration or
1086212714when they're one of the special identifiers that qualify into C<main::>,
1086312715like C<STDOUT>, C<ARGV>, C<ENV>, and the punctuation variables.
1086412716
1086512717=end original
1086612718
1086712719BLOCK や残りのコンパイル単位を与えられた名前空間として宣言します。
1086812720パッケージ宣言のスコープは BLOCK か、BLOCK がないばあいは宣言自身から
10869現在のスコープの末尾 (閉じたブロック、ファイル、C<eval>) です。
12721現在のスコープの末尾 (閉じたブロック、ファイル、L<C<eval>|/eval EXPR>) です。
10870つまり、BLOCK なしの形式は、C<my>, C<state>, C<our> 演算子と同様に
12722つまり、BLOCK なしの形式は、L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>,
10871現在のスコープの末尾にまで作用します。
12723L<C<our>|/our VARLIST> 演算子と同様に現在のスコープの末尾にまで作用します。
1087212724このスコープ内の、全ての完全修飾されていない動的識別子は、他の
10873C<package> 宣言によって上書きされるか、
12725L<C<package>|/package NAMESPACE> 宣言によって上書きされるか、
1087412726C<STDOUT>, C<ARGV>, C<ENV> や句読点変数のように C<main::> に
1087512727割り当てられる特殊変数でない限り、指定された
1087612728名前空間になります。
1087712729
1087812730=begin original
1087912731
1088012732A package statement affects dynamic variables only, including those
10881you've used C<local> on, but I<not> lexically-scoped variables, which are created
12733you've used L<C<local>|/local EXPR> on, but I<not> lexically-scoped
10882with C<my>, C<state>, or C<our>. Typically it would be the first
12734variables, which are created with L<C<my>|/my VARLIST>,
10883declaration in a file included by C<require> or C<use>. You can switch into a
12735L<C<state>|/state VARLIST>, or L<C<our>|/our VARLIST>. Typically it
10884package in more than one place, since this only determines which default
12736would be the first declaration in a file included by
12737L<C<require>|/require VERSION> or L<C<use>|/use Module VERSION LIST>.
12738You can switch into a
12739package in more than one place, since this only determines which default
1088512740symbol table the compiler uses for the rest of that block. You can refer to
1088612741identifiers in other packages than the current one by prefixing the identifier
1088712742with the package name and a double colon, as in C<$SomePack::var>
1088812743or C<ThatPack::INPUT_HANDLE>. If package name is omitted, the C<main>
10889package as assumed. That is, C<$::sail> is equivalent to
12744package is assumed. That is, C<$::sail> is equivalent to
1089012745C<$main::sail> (as well as to C<$main'sail>, still seen in ancient
1089112746code, mostly from Perl 4).
1089212747
1089312748=end original
1089412749
10895package 文は動的変数にのみ影響します(C<local> で使ったものも
12750package 文は動的変数にのみ影響します(L<C<local>|/local EXPR> で使ったものも
10896含みます)が、C<my>, C<state>, C<our> のいずれかで作成された
12751含みます)が、L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>,
12752L<C<our>|/our VARLIST> のいずれかで作成された
1089712753レキシカルなスコープの変数には I<影響しません>。
10898典型的にはこれは C<require> や C<use> 演算子でインクルードされるファイルの
12754典型的にはこれは L<C<require>|/require VERSION>
12755L<C<use>|/use Module VERSION LIST> 演算子でインクルードされるファイルの
1089912756最初に宣言されます。
1090012757パッケージを複数の場所で切り替えることができます;
1090112758なぜならこれは単にコンパイラがこのブロックの残りに対してどの
1090212759シンボルテーブルを使うかにのみ影響するからです。
1090312760他のパッケージの識別子は、C<$SomePack::var> や
1090412761C<ThatPack::INPUT_HANDLE> のように、識別子にパッケージ名と
1090512762コロン二つをつけることで参照できます。
1090612763パッケージ名が省略された場合、C<main> パッケージが仮定されます。
1090712764つまり、C<$::sail> は C<$main::sail> と等価です(ほとんどは Perl 4 からの、
1090812765古いコードでは C<$main'sail> もまだ見られます)。
1090912766
1091012767=begin original
1091112768
10912If VERSION is provided, C<package> sets the C<$VERSION> variable in the given
12769If VERSION is provided, L<C<package>|/package NAMESPACE> sets the
12770C<$VERSION> variable in the given
1091312771namespace to a L<version> object with the VERSION provided. VERSION must be a
1091412772"strict" style version number as defined by the L<version> module: a positive
1091512773decimal number (integer or decimal-fraction) without exponentiation or else a
1091612774dotted-decimal v-string with a leading 'v' character and at least three
1091712775components. You should set C<$VERSION> only once per package.
1091812776
1091912777=end original
1092012778
10921VERSION が指定されると、C<package> は与えられた名前空間の C<$VERSION> 変数に、
12779VERSION が指定されると、L<C<package>|/package NAMESPACE> は与えられた
12780名前空間の C<$VERSION> 変数に、
1092212781指定された VERSION の L<version> オブジェクトをセットします。
1092312782VERSION は L<version> で定義されている「厳密な」形式のバージョン番号で
1092412783なければなりません: 指数のない正の 10 進数 (整数か 10 進小数) か、
1092512784さもなければ先頭に 'v' の文字が付いて、少なくとも三つの部分から
1092612785構成されるドット付き 10 進v-文字列です。
1092712786C<$VERSION> はパッケージ毎に 1 回だけセットするべきです。
1092812787
1092912788=begin original
1093012789
1093112790See L<perlmod/"Packages"> for more information about packages, modules,
1093212791and classes. See L<perlsub> for other scoping issues.
1093312792
1093412793=end original
1093512794
1093612795パッケージ、モジュール、クラスに関するさらなる情報については
1093712796L<perlmod/"Packages"> を参照してください。
1093812797その他のスコープに関する話題については L<perlsub> を参照してください。
1093912798
1094012799=item __PACKAGE__
1094112800X<__PACKAGE__>
1094212801
1094312802=for Pod::Functions +5.004 the current package
1094412803
1094512804=begin original
1094612805
1094712806A special token that returns the name of the package in which it occurs.
1094812807
1094912808=end original
1095012809
1095112810これが書いてあるパッケージの名前を返す特殊トークン。
1095212811
1095312812=item pipe READHANDLE,WRITEHANDLE
1095412813X<pipe>
1095512814
1095612815=for Pod::Functions open a pair of connected filehandles
1095712816
1095812817=begin original
1095912818
1096012819Opens a pair of connected pipes like the corresponding system call.
1096112820Note that if you set up a loop of piped processes, deadlock can occur
1096212821unless you are very careful. In addition, note that Perl's pipes use
10963IO buffering, so you may need to set C<$|> to flush your WRITEHANDLE
12822IO buffering, so you may need to set L<C<$E<verbar>>|perlvar/$E<verbar>>
10964after each command, depending on the application.
12823to flush your WRITEHANDLE after each command, depending on the
12824application.
1096512825
1096612826=end original
1096712827
10968対応するシステムコールと同じように、
12828対応するシステムコールと同じように、接続されたパイプのペアを開きます。
10969接続されたパイプのペアをオープンします。
1097012829パイプでプロセスをループにするときには、よほど気を付けないと、
1097112830デッドロックが起こり得ます。
10972さらに、Perl のパイプでは、IO のバッファリングを使いますから
12831さらに、Perl のパイプでは、IO のバッファリングを使ので
1097312832アプリケーションによっては、コマンドごとに WRITEHANDLE を
10974フラッシュするように、C<$|> を設定することが必要になるかもしれません。
12833フラッシュするように、L<C<$E<verbar>>|perlvar/$E<verbar>> を設定することが
12834必要になるかもしれません。
1097512835
1097612836=begin original
1097712837
1097812838Returns true on success.
1097912839
1098012840=end original
1098112841
1098212842成功時には真を返します。
1098312843
1098412844=begin original
1098512845
1098612846See L<IPC::Open2>, L<IPC::Open3>, and
1098712847L<perlipc/"Bidirectional Communication with Another Process">
1098812848for examples of such things.
1098912849
1099012850=end original
1099112851
1099212852これらに関する例については、L<IPC::Open2>, L<IPC::Open3>,
1099312853L<perlipc/"Bidirectional Communication with Another Process"> を
1099412854参照してください。
1099512855
1099612856=begin original
1099712857
1099812858On systems that support a close-on-exec flag on files, that flag is set
10999on all newly opened file descriptors whose C<fileno>s are I<higher> than
12859on all newly opened file descriptors whose
11000the current value of $^F (by default 2 for C<STDERR>). See L<perlvar/$^F>.
12860L<C<fileno>|/fileno FILEHANDLE>s are I<higher> than the current value of
12861L<C<$^F>|perlvar/$^F> (by default 2 for C<STDERR>). See L<perlvar/$^F>.
1100112862
1100212863=end original
1100312864
1100412865ファイルに対する close-on-exec フラグをサポートしているシステムでは、
1100512866新しくオープンされたファイル記述子のうち、
11006C<fileno> が現在の $^F の値(デフォルトでは C<STDERR> の 2)
12867L<C<fileno>|/fileno FILEHANDLE> が現在の L<C<$^F>|perlvar/$^F>
12868(デフォルトでは C<STDERR> の 2)
1100712869I<よりも大きい> ものに対してフラグがセットされます。
1100812870L<perlvar/$^F> を参照してください。
1100912871
1101012872=item pop ARRAY
1101112873X<pop> X<stack>
1101212874
11013=item pop EXPR
11014
1101512875=item pop
1101612876
1101712877=for Pod::Functions remove the last element from an array and return it
1101812878
1101912879=begin original
1102012880
11021Pops and returns the last value of the array, shortening the array by
12881Removes and returns the B<last> element of the array, shortening the array by
1102212882one element.
1102312883
1102412884=end original
1102512885
11026配列の最後の値をポップして返し、配列の大きさを 1 だけ小さくします。
12886配列の B<最後の> 値を削除して返し、配列の大きさを 1 だけ小さくします。
1102712887
12888 my @arr = ('cat', 'dog', 'mouse');
12889 my $item = pop(@arr); # 'mouse'
12890
12891 # @arr is now ('cat', 'dog')
12892
1102812893=begin original
1102912894
11030Returns the undefined value if the array is empty, although this may also
12895Returns C<undef> if the array is empty.
11031happen at other times. If ARRAY is omitted, pops the C<@ARGV> array in the
11032main program, but the C<@_> array in subroutines, just like C<shift>.
1103312896
1103412897=end original
1103512898
11036指定された配列に要素がなければ未定義値がされますが、
12899配列がら C<undef> をます
11037しかしこれは他の場合にも起こり得ます。
11038ARRAY が省略されると、C<shift> と同様に、メインプログラムでは C<@ARGV> が
11039使われますが、サブルーチンでは C<@_> が使われます。
1104012900
1104112901=begin original
1104212902
11043Starting with Perl 5.14, C<pop> can take a scalar EXPR, which must hold a
12903B<Note:> C<pop> may also return C<undef> if the last element in the array
11044reference to an unblessed array. The argument will be dereferenced
12904is C<undef>.
11045automatically. This aspect of C<pop> is considered highly experimental.
11046The exact behaviour may change in a future version of Perl.
1104712905
1104812906=end original
1104912907
11050Perl 5.14 から、C<pop> はスカラの EXPR を取ることができるようになりました;
12908B<Note:> C<pop> may also return C<undef> if the last element in the array
11051これは bless されていない配列へのリファレンスでなければなりません。
12909is C<undef>.
11052引数は自動的にデリファレンスされます。
12910(TBT)
11053C<pop> のこの動作は高度に実験的であると考えられています。
11054正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
1105512911
12912 my @arr = ('one', 'two', undef);
12913 my $item = pop(@arr); # undef
12914
1105612915=begin original
1105712916
11058To avoid confusing would-be users of your code who are running earlier
12917If ARRAY is omitted, C<pop> operates on the L<C<@ARGV>|perlvar/@ARGV> array
11059versions of Perl with mysterious syntax errors, put this sort of thing at
12918in the main program, but the L<C<@_>|perlvar/@_> array in subroutines. C<pop>
11060the top of your file to signal that your code will work I<only> on Perls of
12919will operate on the C<@ARGV> array in C<eval STRING>, C<BEGIN {}>, C<INIT {}>,
11061a recent vintage:
12920C<CHECK {}> blocks.
1106212921
1106312922=end original
1106412923
11065あなたのコードを以前のバージョンの Perl実行したユーザーが不思議な
12924ARRAY が省略されると、C<pop> は、メインプログラム
11066文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl
12925L<C<@ARGV>|perlvar/@ARGV> が使われますが、
11067I<のみ> 動作ることを示すためにファイルの先頭に以下のようなことを
12926サブルーチンでは L<C<@_>|perlvar/@_> が使われま
11068書いてください:
12927C<pop>
12928will operate on the C<@ARGV> array in C<eval STRING>, C<BEGIN {}>, C<INIT {}>,
12929C<CHECK {}> blocks.
12930(TBT)
1106912931
11070 use 5.014; # so push/pop/etc work on scalars (experimental)
12932=begin original
1107112933
12934Starting with Perl 5.14, an experimental feature allowed
12935L<C<pop>|/pop ARRAY> to take a
12936scalar expression. This experiment has been deemed unsuccessful, and was
12937removed as of Perl 5.24.
12938
12939=end original
12940
12941Perl 5.14 から、L<C<pop>|/pop ARRAY> がスカラ式を取ることが出来るという
12942実験的機能がありました。
12943この実験は失敗と見なされ、Perl 5.24 で削除されました。
12944
1107212945=item pos SCALAR
1107312946X<pos> X<match, position>
1107412947
1107512948=item pos
1107612949
1107712950=for Pod::Functions find or set the offset for the last/next m//g search
1107812951
1107912952=begin original
1108012953
1108112954Returns the offset of where the last C<m//g> search left off for the
11082variable in question (C<$_> is used when the variable is not
12955variable in question (L<C<$_>|perlvar/$_> is used when the variable is not
11083specified). Note that 0 is a valid match offset. C<undef> indicates
12956specified). This offset is in characters unless the
12957(no-longer-recommended) L<C<use bytes>|bytes> pragma is in effect, in
12958which case the offset is in bytes. Note that 0 is a valid match offset.
12959L<C<undef>|/undef EXPR> indicates
1108412960that the search position is reset (usually due to match failure, but
1108512961can also be because no match has yet been run on the scalar).
1108612962
1108712963=end original
1108812964
1108912965対象の変数に対して、前回の C<m//g> が終了した場所の
11090オフセットを返します(変数が指定されなかった場合は C<$_> が使われます)。
12966オフセットを返します(変数が指定されなかった場合は L<C<$_>|perlvar/$_>
12967使われます)。
12968オフセットは、(もはや勧められない) L<C<use bytes>|bytes> プラグマが有効の
12969場合(この場合はバイト単位です)を除いて、文字単位です。
11091129700 は有効なマッチオフセットであることに注意してください。
11092C<undef> は検索位置がリセットされることを意味します (通常はマッチ失敗が
12971L<C<undef>|/undef EXPR> は検索位置がリセットされることを意味します (通常は
11093原因ですが、このスカラ値にまだマッチングが行われていないためかもしれません)。
12972マッチ失敗が原因ですが、このスカラ値にまだマッチングが
12973行われていないためかもしれません)。
1109412974
1109512975=begin original
1109612976
11097C<pos> directly accesses the location used by the regexp engine to
12977L<C<pos>|/pos SCALAR> directly accesses the location used by the regexp
11098store the offset, so assigning to C<pos> will change that offset, and
12978engine to store the offset, so assigning to L<C<pos>|/pos SCALAR> will
11099so will also influence the C<\G> zero-width assertion in regular
12979change that offset, and so will also influence the C<\G> zero-width
11100expressions. Both of these effects take place for the next match, so
12980assertion in regular expressions. Both of these effects take place for
11101you can't affect the position with C<pos> during the current match,
12981the next match, so you can't affect the position with
11102such as in C<(?{pos() = 5})> or C<s//pos() = 5/e>.
12982L<C<pos>|/pos SCALAR> during the current match, such as in
12983C<(?{pos() = 5})> or C<s//pos() = 5/e>.
1110312984
1110412985=end original
1110512986
11106C<pos> は正規表現エンジンがオフセットを保存するために使う場所を直接
12987L<C<pos>|/pos SCALAR> は正規表現エンジンがオフセットを保存するために使う場所を
11107アクセスするので、C<pos> への代入はオフセットを変更し、そのような変更は
12988直接アクセスするので、L<C<pos>|/pos SCALAR> への代入はオフセットを変更し、
11108正規表現における C<\G> ゼロ幅アサートにも影響を与えます。
12989そのような変更は正規表現における C<\G> ゼロ幅アサートにも影響を与えます。
1110912990これらの効果の両方は次のマッチングのために行われるので、
1111012991C<(?{pos() = 5})> や C<s//pos() = 5/e> のように現在のマッチング中の
11111C<pos> の位置には影響を与えません。
12992L<C<pos>|/pos SCALAR> の位置には影響を与えません。
1111212993
1111312994=begin original
1111412995
11115Setting C<pos> also resets the I<matched with zero-length> flag, described
12996Setting L<C<pos>|/pos SCALAR> also resets the I<matched with
12997zero-length> flag, described
1111612998under L<perlre/"Repeated Patterns Matching a Zero-length Substring">.
1111712999
1111813000=end original
1111913001
11120C<pos> を設定すると、
13002L<C<pos>|/pos SCALAR> を設定すると、
1112113003L<perlre/"Repeated Patterns Matching a Zero-length Substring"> に
1112213004記述されている、I<長さ 0 でマッチング> フラグもリセットされます。
1112313005
1112413006=begin original
1112513007
1112613008Because a failed C<m//gc> match doesn't reset the offset, the return
11127from C<pos> won't change either in this case. See L<perlre> and
13009from L<C<pos>|/pos SCALAR> won't change either in this case. See
11128L<perlop>.
13010L<perlre> and L<perlop>.
1112913011
1113013012=end original
1113113013
1113213014C<m//gc> マッチに失敗してもオフセットはリセットしないので、
11133C<pos> からの返り値はどちらの場合も変更されません。
13015L<C<pos>|/pos SCALAR> からの返り値はどちらの場合も変更されません。
1113413016L<perlre> と L<perlop> を参照してください。
1113513017
1113613018=item print FILEHANDLE LIST
1113713019X<print>
1113813020
1113913021=item print FILEHANDLE
1114013022
1114113023=item print LIST
1114213024
1114313025=item print
1114413026
1114513027=for Pod::Functions output a list to a filehandle
1114613028
1114713029=begin original
1114813030
1114913031Prints a string or a list of strings. Returns true if successful.
1115013032FILEHANDLE may be a scalar variable containing the name of or a reference
1115113033to the filehandle, thus introducing one level of indirection. (NOTE: If
1115213034FILEHANDLE is a variable and the next token is a term, it may be
1115313035misinterpreted as an operator unless you interpose a C<+> or put
1115413036parentheses around the arguments.) If FILEHANDLE is omitted, prints to the
11155last selected (see L</select>) output handle. If LIST is omitted, prints
13037last selected (see L<C<select>|/select FILEHANDLE>) output handle. If
11156C<$_> to the currently selected output handle. To use FILEHANDLE alone to
13038LIST is omitted, prints L<C<$_>|perlvar/$_> to the currently selected
11157print the content of C<$_> to it, you must use a real filehandle like
13039output handle. To use FILEHANDLE alone to print the content of
13040L<C<$_>|perlvar/$_> to it, you must use a bareword filehandle like
1115813041C<FH>, not an indirect one like C<$fh>. To set the default output handle
1115913042to something other than STDOUT, use the select operation.
1116013043
1116113044=end original
1116213045
1116313046文字列か文字列のリストを出力します。
1116413047成功時には真を返します。
1116513048FILEHANDLE は、ファイルハンドル名またはそのリファレンスが
1116613049入っているスカラ変数名でもよいので、一段階の間接指定が行なえます。
1116713050(注: FILEHANDLE に変数を使い、次のトークンが「項」のときには、
1116813051間に C<+> を置くか、引数の前後を括弧で括らなければ、
1116913052誤って解釈されることがあります。)
11170FILEHANDLE を省略した場合には、最後に選択された (L</select> 参照) 出力
13053FILEHANDLE を省略した場合には、最後に選択された
11171チャネルに出力します。
13054(L<C<select>|/select FILEHANDLE> 参照) 出力チャネルに出力します。
11172LIST を省略すると、C<$_> が現在選択されている出力ハンドルに出力されます。
13055LIST を省略すると、L<C<$_>|perlvar/$_> が現在選択されている出力ハンドルに
11173C<$_> の内容を表示るために FILEHANDLE のみを使用するには、
13056出力されま
11174C<$fh> のような間接ファイルハンドルではなく、C<FH>ような実際の
13057L<C<$_>|perlvar/$_>内容を表示するために FILEHANDLEみを使用するには、
13058C<$fh> のような間接ファイルハンドルではなく、C<FH> のような裸の単語の
1117513059ファイルハンドルを使わなければなりません。
1117613060デフォルトの出力チャネルを STDOUT 以外にするには、select 演算子を
1117713061使ってください。
1117813062
1117913063=begin original
1118013064
11181The current value of C<$,> (if any) is printed between each LIST item. The
13065The current value of L<C<$,>|perlvar/$,> (if any) is printed between
11182current value of C<$\> (if any) is printed after the entire LIST has been
13066each LIST item. The current value of L<C<$\>|perlvar/$\> (if any) is
11183printed. Because print takes a LIST, anything in the LIST is evaluated in
13067printed after the entire LIST has been printed. Because print takes a
11184list context, including any subroutines whose return lists you pass to
13068LIST, anything in the LIST is evaluated in list context, including any
11185C<print>. Be careful not to follow the print keyword with a left
13069subroutines whose return lists you pass to
13070L<C<print>|/print FILEHANDLE LIST>. Be careful not to follow the print
13071keyword with a left
1118613072parenthesis unless you want the corresponding right parenthesis to
1118713073terminate the arguments to the print; put parentheses around all arguments
1118813074(or interpose a C<+>, but that doesn't look as good).
1118913075
1119013076=end original
1119113077
11192C<$,> の値が(もしあれば)各 LIST 要素の間に出力されます。
13078L<C<$,>|perlvar/$,> の値が(もしあれば)各 LIST 要素の間に出力されます。
11193LIST 全体が出力された後、(もしあれば) C<$\> の現在の値が出力されます。
13079LIST 全体が出力された後、(もしあれば) L<C<$\>|perlvar/$\> の現在の値が
13080出力されます。
1119413081print の引数は LIST なので、LIST の中のものは、すべてリストコンテキストで
11195評価されます; C<print> に渡した、リストを返すサブルーチンも含みます。
13082評価されます; L<C<print>|/print FILEHANDLE LIST> に渡した、リストを返す
13083サブルーチンも含みます。
1119613084また、すべての引数を括弧で括るのでなければ、print というキーワードの
1119713085次に開き括弧を書いてはいけません; すべての引数を括弧で括ってください
1119813086(あるいは "print" と引数の間に C<+> を書きますが、これはあまり
1119913087よくありません)。
1120013088
1120113089=begin original
1120213090
1120313091If you're storing handles in an array or hash, or in general whenever
1120413092you're using any expression more complex than a bareword handle or a plain,
1120513093unsubscripted scalar variable to retrieve it, you will have to use a block
1120613094returning the filehandle value instead, in which case the LIST may not be
1120713095omitted:
1120813096
1120913097=end original
1121013098
1121113099もし FILESHANDLE を配列、ハッシュあるいは一般的には裸の単語のハンドルや
1121213100普通のスカラ変数よりも複雑な表現を使っている場合、代わりにその値を返す
1121313101ブロックを使う必要があります; この場合 LIST は省略できません:
1121413102
1121513103 print { $files[$i] } "stuff\n";
11216 print { $OK ? STDOUT : STDERR } "stuff\n";
13104 print { $OK ? *STDOUT : *STDERR } "stuff\n";
1121713105
1121813106=begin original
1121913107
1122013108Printing to a closed pipe or socket will generate a SIGPIPE signal. See
1122113109L<perlipc> for more on signal handling.
1122213110
1122313111=end original
1122413112
1122513113閉じたパイプやソケットに print すると SIGPIPE シグナルが生成されます。
1122613114さらなるシグナル操作については L<perlipc> を参照してください。
1122713115
1122813116=item printf FILEHANDLE FORMAT, LIST
1122913117X<printf>
1123013118
1123113119=item printf FILEHANDLE
1123213120
1123313121=item printf FORMAT, LIST
1123413122
1123513123=item printf
1123613124
1123713125=for Pod::Functions output a formatted list to a filehandle
1123813126
1123913127=begin original
1124013128
11241Equivalent to C<print FILEHANDLE sprintf(FORMAT, LIST)>, except that C<$\>
13129Equivalent to C<print FILEHANDLE sprintf(FORMAT, LIST)>, except that
11242(the output record separator) is not appended. The FORMAT and the
13130L<C<$\>|perlvar/$\> (the output record separator) is not appended. The
11243LIST are actually parsed as a single list. The first argument
13131FORMAT and the LIST are actually parsed as a single list. The first
11244of the list will be interpreted as the C<printf> format. This
13132argument of the list will be interpreted as the
11245means that C<printf(@_)> will use C<$_[0]> as the format. See
13133L<C<printf>|/printf FILEHANDLE FORMAT, LIST> format. This means that
11246L<sprintf|/sprintf FORMAT, LIST> for an
13134C<printf(@_)> will use C<$_[0]> as the format. See
11247explanation of the format argument. If C<use locale> (including
13135L<sprintf|/sprintf FORMAT, LIST> for an explanation of the format
11248C<use locale ':not_characters'>) is in effect and
13136argument. If C<use locale> (including C<use locale ':not_characters'>)
11249POSIX::setlocale() has been called, the character used for the decimal
13137is in effect and L<C<POSIX::setlocale>|POSIX/C<setlocale>> has been
11250separator in formatted floating-point numbers is affected by the LC_NUMERIC
13138called, the character used for the decimal separator in formatted
11251locale setting. See L<perllocale> and L<POSIX>.
13139floating-point numbers is affected by the C<LC_NUMERIC> locale setting.
13140See L<perllocale> and L<POSIX>.
1125213141
1125313142=end original
1125413143
11255C<$\>(出力レコードセパレータ)を追加しないことを除けば、
13144L<C<$\>|perlvar/$\>(出力レコードセパレータ)を追加しないことを除けば、
1125613145C<print FILEHANDLE sprintf(FORMAT, LIST)> と等価です。
1125713146FORMAT と LIST は実際には単一のリストとしてパースされます。
11258リストの最初の要素は、C<printf> フォーマットと解釈されます。
13147リストの最初の要素は、L<C<printf>|/printf FILEHANDLE FORMAT, LIST>
13148フォーマットと解釈されます。
1125913149これは、C<printf(@_)> はフォーマットとして C<$_[0]> を使うということです。
1126013150フォーマット引数の説明については L<sprintf|/sprintf FORMAT, LIST> を
1126113151参照してください。
11262(C<use locale ':not_characters'> を含む) C<use locale> が効力をもっていて
13152(C<use locale ':not_characters'> を含む) C<use locale> が
11263POSIX::setlocale() が呼び出されていれば、
13153L<C<POSIX::setlocale>|POSIX/C<setlocale>> が呼び出されていれば、
11264小数点に使われる文字は LC_NUMERIC ロケール設定の影響を受けます。
13154小数点に使われる文字は C<LC_NUMERIC> ロケール設定の影響を受けます。
1126513155L<perllocale> と L<POSIX> を参照してください。
1126613156
1126713157=begin original
1126813158
11269For historical reasons, if you omit the list, C<$_> is used as the format;
13159For historical reasons, if you omit the list, L<C<$_>|perlvar/$_> is
11270to use FILEHANDLE without a list, you must use a real filehandle like
13160used as the format;
13161to use FILEHANDLE without a list, you must use a bareword filehandle like
1127113162C<FH>, not an indirect one like C<$fh>. However, this will rarely do what
11272you want; if $_ contains formatting codes, they will be replaced with the
13163you want; if L<C<$_>|perlvar/$_> contains formatting codes, they will be
11273empty string and a warning will be emitted if warnings are enabled. Just
13164replaced with the empty string and a warning will be emitted if
11274use C<print> if you want to print the contents of $_.
13165L<warnings> are enabled. Just use L<C<print>|/print FILEHANDLE LIST> if
13166you want to print the contents of L<C<$_>|perlvar/$_>.
1127513167
1127613168=end original
1127713169
11278歴史的な理由により、リストを省略すると、フォーマットとして C<$_> が使われます;
13170歴史的な理由により、リストを省略すると、フォーマットとして
11279リストなしで FILEHANDLE 使るには、
13171L<C<$_>|perlvar/$_> 使われま;
11280C<$fh> のよう間接ファイルハンドルではなく、C<FH> のような実際の
13172リスト FILEHANDLE を使用するには、C<$fh> のような
13173間接ファイルハンドルではなく、C<FH> のような裸の単語の
1128113174ファイルハンドルを使わなければなりません。
1128213175しかし、これがあなたが求めていることをすることはまれです;
11283$_ がフォーマッティングコードの場合、空文字列に置き換えられ、警告が有効なら
13176L<C<$_>|perlvar/$_> がフォーマッティングコードの場合、空文字列に置き換えられ、
11284警告が出力されます。
13177L<warnings> が有効なら警告が出力されます。
11285$_ の内容を表示したい場合は、単に C<print> を使ってください。
13178L<C<$_>|perlvar/$_> の内容を表示したい場合は、単に
13179L<C<print>|/print FILEHANDLE LIST> を使ってください。
1128613180
1128713181=begin original
1128813182
11289Don't fall into the trap of using a C<printf> when a simple
13183Don't fall into the trap of using a
11290C<print> would do. The C<print> is more efficient and less
13184L<C<printf>|/printf FILEHANDLE FORMAT, LIST> when a simple
11291error prone.
13185L<C<print>|/print FILEHANDLE LIST> would do. The
13186L<C<print>|/print FILEHANDLE LIST> is more efficient and less error
13187prone.
1129213188
1129313189=end original
1129413190
11295単純な C<print> を使うべきところで C<printf> を使ってしま
13191単純な L<C<print>|/print FILEHANDLE LIST> を使うべきところで
13192L<C<printf>|/printf FILEHANDLE FORMAT, LIST> を使ってしまう
1129613193罠にかからないようにしてください。
11297C<print> はより効率的で、間違いが起こりにくいです。
13194L<C<print>|/print FILEHANDLE LIST> はより効率的で、間違いが起こりにくいです。
1129813195
1129913196=item prototype FUNCTION
1130013197X<prototype>
1130113198
13199=item prototype
13200
1130213201=for Pod::Functions +5.002 get the prototype (if any) of a subroutine
1130313202
1130413203=begin original
1130513204
11306Returns the prototype of a function as a string (or C<undef> if the
13205Returns the prototype of a function as a string (or
13206L<C<undef>|/undef EXPR> if the
1130713207function has no prototype). FUNCTION is a reference to, or the name of,
11308the function whose prototype you want to retrieve.
13208the function whose prototype you want to retrieve. If FUNCTION is omitted,
13209L<C<$_>|perlvar/$_> is used.
1130913210
1131013211=end original
1131113212
1131213213関数のプロトタイプを文字列として返します(関数にプロトタイプがない場合は
11313C<undef> を返します)。
13214L<C<undef>|/undef EXPR> を返します)。
1131413215FUNCTION はプロトタイプを得たい関数の名前、またはリファレンスです。
13216FUNCTION が省略された場合、L<C<$_>|perlvar/$_> が使われます。
1131513217
1131613218=begin original
1131713219
1131813220If FUNCTION is a string starting with C<CORE::>, the rest is taken as a
1131913221name for a Perl builtin. If the builtin's arguments
1132013222cannot be adequately expressed by a prototype
11321(such as C<system>), prototype() returns C<undef>, because the builtin
13223(such as L<C<system>|/system LIST>), L<C<prototype>|/prototype FUNCTION>
13224returns L<C<undef>|/undef EXPR>, because the builtin
1132213225does not really behave like a Perl function. Otherwise, the string
1132313226describing the equivalent prototype is returned.
1132413227
1132513228=end original
1132613229
1132713230FUNCTION が C<CORE::> で始まっている場合、残りは Perl ビルドインの名前として
1132813231扱われます。
11329このビルドインの引数が(C<system> のように)プロトタイプとして適切に
13232このビルドインの引数が(L<C<system>|/system LIST> のように)プロトタイプとして
11330記述できない場合、prototype() C<undef> を返します;
13233適切に記述できない場合、L<C<prototype>|/prototype FUNCTION>
13234L<C<undef>|/undef EXPR> を返します;
1133113235なぜならビルドインは実際に Perl 関数のように振舞わないからです。
1133213236それ以外では、等価なプロトタイプを表現した文字列が返されます。
1133313237
1133413238=item push ARRAY,LIST
1133513239X<push> X<stack>
1133613240
11337=item push EXPR,LIST
11338
1133913241=for Pod::Functions append one or more elements to an array
1134013242
1134113243=begin original
1134213244
11343Treats ARRAY as a stack by appending the values of LIST to the end of
13245Adds one or more items to the B<end> of an array.
11344ARRAY. The length of ARRAY increases by the length of LIST. Has the same
11345effect as
1134613246
1134713247=end original
1134813248
11349ARRAY をスタックとして扱い、LIST 内 ARRAY 終わりに追加します。
13249一つまたは複数要素配列 B<末尾> 追加します。
11350ARRAY の大きさは、LIST の長さ分だけ大きくなります。
11351これは、
1135213250
11353 for $value (LIST) {
13251 my @animals = ("cat");
11354 $ARRAY[++$<#del>ARRAY] = $value;
13252 push(@animals, "mouse"); # ("cat", "mouse")
11355 }
1135613253
13254 my @colors = ("red");
13255 push(@colors, ("blue", "green")); # ("red", "blue", "green")
13256
1135713257=begin original
1135813258
11359but is more efficient. Returns the number of elements in the array following
13259Returns the number of elements in the array following the completed
11360the completed C<push>.
13260L<C<push>|/push ARRAY,LIST>.
1136113261
1136213262=end original
1136313263
11364とすると同じ効果がありすが、より効率的です。
13264L<C<push>|/push ARRAY,LIST> 処理終了後の配列の要素数を返します。
11365C<push> の処理終了後の配列の要素数を返します。
1136613265
11367=begin original
13266 my $color_count = push(@colors, ("yellow", "purple"));
1136813267
11369Starting with Perl 5.14, C<push> can take a scalar EXPR, which must hold a
13268 say "There are $color_count colors in the updated array";
11370reference to an unblessed array. The argument will be dereferenced
11371automatically. This aspect of C<push> is considered highly experimental.
11372The exact behaviour may change in a future version of Perl.
1137313269
11374=end original
11375
11376Perl 5.14 から、C<push> はスカラの EXPR を取ることができるようになりました;
11377これは bless されていない配列へのリファレンスでなければなりません。
11378引数は自動的にデリファレンスされます。
11379C<push> のこの動作は高度に実験的であると考えられています。
11380正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
11381
1138213270=begin original
1138313271
11384To avoid confusing would-be users of your code who are running earlier
13272Starting with Perl 5.14, an experimental feature allowed
11385versions of Perl with mysterious syntax errors, put this sort of thing at
13273L<C<push>|/push ARRAY,LIST> to take a
11386the top of your file to signal that your code will work I<only> on Perls of
13274scalar expression. This experiment has been deemed unsuccessful, and was
11387a recent vintage:
13275removed as of Perl 5.24.
1138813276
1138913277=end original
1139013278
11391あなたのコードを以前のバージョンの Perl で実行したユーザー不思議な
13279Perl 5.14 から、L<C<push>|/push ARRAY,LIST> スカラ式を取ることが出来るという
11392文法エラーで混乱することを避けるために、コード最近のバージョンの Perl で
13280実験的機能ありました。
11393I<のみ> 動作するとを示すためにファイル先頭に以下のようなこ
13281この実験は失敗見なされ、Perl 5.24 で削除されました。
11394書いてください:
1139513282
11396 use 5.014; # so push/pop/etc work on scalars (experimental)
11397
1139813283=item q/STRING/
1139913284
1140013285=for Pod::Functions singly quote a string
1140113286
1140213287=item qq/STRING/
1140313288
1140413289=for Pod::Functions doubly quote a string
1140513290
1140613291=item qw/STRING/
1140713292
1140813293=for Pod::Functions quote a list of words
1140913294
1141013295=item qx/STRING/
1141113296
1141213297=for Pod::Functions backquote quote a string
1141313298
1141413299=begin original
1141513300
1141613301Generalized quotes. See L<perlop/"Quote-Like Operators">.
1141713302
1141813303=end original
1141913304
1142013305汎用のクォートです。
1142113306L<perlop/"Quote-Like Operators"> を参照してください。
1142213307
1142313308=item qr/STRING/
1142413309
1142513310=for Pod::Functions +5.005 compile pattern
1142613311
1142713312=begin original
1142813313
1142913314Regexp-like quote. See L<perlop/"Regexp Quote-Like Operators">.
1143013315
1143113316=end original
1143213317
1143313318正規表現風のクォートです。
1143413319L<perlop/"Regexp Quote-Like Operators"> を参照してください。
1143513320
1143613321=item quotemeta EXPR
1143713322X<quotemeta> X<metacharacter>
1143813323
1143913324=item quotemeta
1144013325
1144113326=for Pod::Functions quote regular expression magic characters
1144213327
1144313328=begin original
1144413329
1144513330Returns the value of EXPR with all the ASCII non-"word"
1144613331characters backslashed. (That is, all ASCII characters not matching
1144713332C</[A-Za-z_0-9]/> will be preceded by a backslash in the
1144813333returned string, regardless of any locale settings.)
1144913334This is the internal function implementing
1145013335the C<\Q> escape in double-quoted strings.
1145113336(See below for the behavior on non-ASCII code points.)
1145213337
1145313338=end original
1145413339
1145513340EXPR の中のすべての ASCII 非英数字キャラクタをバックスラッシュで
1145613341エスケープしたものを返します。
1145713342(つまり、C</[A-Za-z_0-9]/> にマッチしない全ての ASCII 文字の前には
1145813343ロケールに関わらずバックスラッシュが前置されます。)
1145913344これは、ダブルクォート文字列での C<\Q> エスケープを実装するための
1146013345内部関数です。
1146113346(非 ASCII 符号位置での振る舞いについては以下を参照してください。)
1146213347
1146313348=begin original
1146413349
11465If EXPR is omitted, uses C<$_>.
13350If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
1146613351
1146713352=end original
1146813353
11469EXPR が省略されると、C<$_> を使います。
13354EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
1147013355
1147113356=begin original
1147213357
1147313358quotemeta (and C<\Q> ... C<\E>) are useful when interpolating strings into
1147413359regular expressions, because by default an interpolated variable will be
1147513360considered a mini-regular expression. For example:
1147613361
1147713362=end original
1147813363
1147913364クォートメタ (と C<\Q> ... C<\E>) は、文字列を正規表現に展開するのに
1148013365便利です; なぜなら、デフォルトでは展開された変数は小さな正規表現として
1148113366扱われるからです。
1148213367例えば:
1148313368
1148413369 my $sentence = 'The quick brown fox jumped over the lazy dog';
1148513370 my $substring = 'quick.*?fox';
1148613371 $sentence =~ s{$substring}{big bad wolf};
1148713372
1148813373=begin original
1148913374
1149013375Will cause C<$sentence> to become C<'The big bad wolf jumped over...'>.
1149113376
1149213377=end original
1149313378
1149413379とすると、C<$sentence> は C<'The big bad wolf jumped over...'> になります。
1149513380
1149613381=begin original
1149713382
1149813383On the other hand:
1149913384
1150013385=end original
1150113386
1150213387一方:
1150313388
1150413389 my $sentence = 'The quick brown fox jumped over the lazy dog';
1150513390 my $substring = 'quick.*?fox';
1150613391 $sentence =~ s{\Q$substring\E}{big bad wolf};
1150713392
1150813393=begin original
1150913394
1151013395Or:
1151113396
1151213397=end original
1151313398
1151413399あるいは:
1151513400
1151613401 my $sentence = 'The quick brown fox jumped over the lazy dog';
1151713402 my $substring = 'quick.*?fox';
1151813403 my $quoted_substring = quotemeta($substring);
1151913404 $sentence =~ s{$quoted_substring}{big bad wolf};
1152013405
1152113406=begin original
1152213407
1152313408Will both leave the sentence as is.
11524Normally, when accepting literal string
13409Normally, when accepting literal string input from the user,
11525input from the user, quotemeta() or C<\Q> must be used.
13410L<C<quotemeta>|/quotemeta EXPR> or C<\Q> must be used.
1152613411
1152713412=end original
1152813413
1152913414とすると、両方ともそのままです。
1153013415普通は、ユーザーからのリテラルな文字列入力を受け付ける場合は、
11531必ず quotemeta() か C<\Q> を使わなければなりません。
13416必ず L<C<quotemeta>|/quotemeta EXPR> か C<\Q> を使わなければなりません。
1153213417
1153313418=begin original
1153413419
13420Beware that if you put literal backslashes (those not inside
13421interpolated variables) between C<\Q> and C<\E>, double-quotish
13422backslash interpolation may lead to confusing results. If you
13423I<need> to use literal backslashes within C<\Q...\E>,
13424consult L<perlop/"Gory details of parsing quoted constructs">.
13425
13426=end original
13427
13428リテラルな逆スラッシュ (変数置換の中でないもの) を C<\Q> と C<\E> の間に
13429置くと、ダブルクォート風逆スラッシュ変数置換は混乱した結果を
13430引き起こすことがあることに注意してください。
13431C<\Q...\E> の中でリテラルな逆スラッシュを使うことが I<必要> なら、
13432L<perlop/"Gory details of parsing quoted constructs"> を参照してください。
13433
13434=begin original
13435
13436Because the result of S<C<"\Q I<STRING> \E">> has all metacharacters
13437quoted, there is no way to insert a literal C<$> or C<@> inside a
13438C<\Q\E> pair. If protected by C<\>, C<$> will be quoted to become
13439C<"\\\$">; if not, it is interpreted as the start of an interpolated
13440scalar.
13441
13442=end original
13443
13444S<C<"\Q I<STRING> \E">> の結果では全てのメタ文字がクォートされているので、
13445C<\Q\E> の組の中にリテラルな C<$> や C<@> を挿入する方法はありません。
13446C<\> で保護すると、C<$> は C<"\\\$"> になってクォートされます;
13447保護しないと、変数展開されるスカラの開始として解釈されます。
13448
13449=begin original
13450
1153513451In Perl v5.14, all non-ASCII characters are quoted in non-UTF-8-encoded
1153613452strings, but not quoted in UTF-8 strings.
1153713453
1153813454=end original
1153913455
1154013456Perl v5.14 では、全ての非 ASCII 文字は非 UTF-8 エンコードされた
1154113457文字列ではクォートされませんが、UTF-8 文字列ではクォートされます。
1154213458
1154313459=begin original
1154413460
1154513461Starting in Perl v5.16, Perl adopted a Unicode-defined strategy for
1154613462quoting non-ASCII characters; the quoting of ASCII characters is
1154713463unchanged.
1154813464
1154913465=end original
1155013466
1155113467Perl v5.16 から、Perl は非 ASCII 文字をクォートするのに Unicode で
1155213468定義された戦略を採用しました; ASCII 文字のクォートは変わりません。
1155313469
1155413470=begin original
1155513471
1155613472Also unchanged is the quoting of non-UTF-8 strings when outside the
11557scope of a C<use feature 'unicode_strings'>, which is to quote all
13473scope of a
13474L<C<use feature 'unicode_strings'>|feature/The 'unicode_strings' feature>,
13475which is to quote all
1155813476characters in the upper Latin1 range. This provides complete backwards
1155913477compatibility for old programs which do not use Unicode. (Note that
1156013478C<unicode_strings> is automatically enabled within the scope of a
1156113479S<C<use v5.12>> or greater.)
1156213480
1156313481=end original
1156413482
11565また、C<use feature 'unicode_strings'> の範囲外で非 UTF-8 文字列を
13483また、
11566クォートするのも変わりません; 上位の Latin1範囲の全ての文字を
13484L<C<use feature 'unicode_strings'>|feature/The 'unicode_strings' feature>
11567クォートしま
13485範囲外で非 UTF-8 文字列をクォートするのも変わりません; 上位の Latin1 の範囲の
11568これは Unicode を使わない古いプログラムに対して完な後方互換性
13486ての文字クォートします。
11569提供します。
13487これは Unicode を使わない古いプログラムに対して完全な後方互換性を提供します。
1157013488(C<unicode_strings> は S<C<use v5.12>> またはそれ以上のスコープでは
1157113489自動的に有効になることに注意してください。)
1157213490
1157313491=begin original
1157413492
11575Within the scope of C<use locale>, all non-ASCII Latin1 code points
13493Within the scope of L<C<use locale>|locale>, all non-ASCII Latin1 code
13494points
1157613495are quoted whether the string is encoded as UTF-8 or not. As mentioned
1157713496above, locale does not affect the quoting of ASCII-range characters.
1157813497This protects against those locales where characters such as C<"|"> are
1157913498considered to be word characters.
1158013499
1158113500=end original
1158213501
11583C<use locale> スコープの内側では、全ての非 ASCII Latin1 符号位置は
13502L<C<use locale>|locale> スコープの内側では、全ての非 ASCII Latin1 符号位置は
1158413503文字列が UTF-8 でエンコードされているかどうかに関わらずクォートされます。
1158513504上述のように、ロケールは ASCII の範囲の文字のクォートに影響を与えません。
1158613505これは C<"|"> のような文字が単語文字として考えられるロケールから守ります。
1158713506
1158813507=begin original
1158913508
1159013509Otherwise, Perl quotes non-ASCII characters using an adaptation from
11591Unicode (see L<http://www.unicode.org/reports/tr31/>).
13510Unicode (see L<https://www.unicode.org/reports/tr31/>).
1159213511The only code points that are quoted are those that have any of the
1159313512Unicode properties: Pattern_Syntax, Pattern_White_Space, White_Space,
1159413513Default_Ignorable_Code_Point, or General_Category=Control.
1159513514
1159613515=end original
1159713516
1159813517さもなければ、Perl は Unicode からの本版を使って非 ASCII 文字をクォートします
11599(L<http://www.unicode.org/reports/tr31/> 参照)。
13518(L<https://www.unicode.org/reports/tr31/> 参照)。
1160013519クォートされる符号位置は以下のどれかの Unicode を特性を持つものだけです:
1160113520Pattern_Syntax, Pattern_White_Space, White_Space,
1160213521Default_Ignorable_Code_Point, or General_Category=Control。
1160313522
1160413523=begin original
1160513524
1160613525Of these properties, the two important ones are Pattern_Syntax and
1160713526Pattern_White_Space. They have been set up by Unicode for exactly this
1160813527purpose of deciding which characters in a regular expression pattern
1160913528should be quoted. No character that can be in an identifier has these
1161013529properties.
1161113530
1161213531=end original
1161313532
1161413533これらの特性の中で、重要な二つは Pattern_Syntax と Pattern_White_Space です。
1161513534これらはまさに正規表現中パターン中のどの文字をクォートするべきかを
1161613535決定するという目的のために Unicode によって設定されています。
1161713536識別子になる文字はこれらの特性はありません。
1161813537
1161913538=begin original
1162013539
1162113540Perl promises, that if we ever add regular expression pattern
1162213541metacharacters to the dozen already defined
1162313542(C<\ E<verbar> ( ) [ { ^ $ * + ? .>), that we will only use ones that have the
1162413543Pattern_Syntax property. Perl also promises, that if we ever add
1162513544characters that are considered to be white space in regular expressions
1162613545(currently mostly affected by C</x>), they will all have the
1162713546Pattern_White_Space property.
1162813547
1162913548=end original
1163013549
1163113550Perl は、正規表現メタ文字として既に定義されている
1163213551(C<\ E<verbar> ( ) [ { ^ $ * + ? .>) ものに追加するときは、
1163313552Pattern_Syntax 特性を持つものだけを使うことを約束します。
1163413553Perl はまた、(現在の所ほとんどは C</x> よって影響される)正規表現中で空白と
1163513554考えられる文字に追加するときは、Pattern_White_Space 特性を
1163613555持つものであることを約束します。
1163713556
1163813557=begin original
1163913558
1164013559Unicode promises that the set of code points that have these two
1164113560properties will never change, so something that is not quoted in v5.16
1164213561will never need to be quoted in any future Perl release. (Not all the
1164313562code points that match Pattern_Syntax have actually had characters
1164413563assigned to them; so there is room to grow, but they are quoted
1164513564whether assigned or not. Perl, of course, would never use an
1164613565unassigned code point as an actual metacharacter.)
1164713566
1164813567=end original
1164913568
1165013569Unicode はこれら二つの特性を持つ符号位置の集合が決して変わらないことを
1165113570約束しているので、v5.16 でクォートされないものは将来の Perl リリースでも
1165213571クォートする必要はありません。
1165313572(Pattern_Syntax にマッチングする全ての符号位置が実際に割り当てられている
1165413573文字を持っているわけではありません; したがって拡張する余地がありますが、
1165513574割り当てられているかどうかに関わらずクォートされます。
1165613575Perl はもちろん割り当てられていない符号位置を実際のメタ文字として使うことは
1165713576ありません。)
1165813577
1165913578=begin original
1166013579
1166113580Quoting characters that have the other 3 properties is done to enhance
1166213581the readability of the regular expression and not because they actually
1166313582need to be quoted for regular expression purposes (characters with the
1166413583White_Space property are likely to be indistinguishable on the page or
1166513584screen from those with the Pattern_White_Space property; and the other
1166613585two properties contain non-printing characters).
1166713586
1166813587=end original
1166913588
1167013589その他の 3 特性を持つ文字のクォートは正規表現の可読性を向上させるために
1167113590行われ、実際には正規表現の目的でクォートする必要があるからではありません
1167213591(White_Space 特性を持つ文字は表示上は Pattern_White_Space 特性を持つ文字と
1167313592おそらく区別が付かないでしょう; そして残りの
1167413593二つの特性は非表示文字を含んでいます).
1167513594
1167613595=item rand EXPR
1167713596X<rand> X<random>
1167813597
1167913598=item rand
1168013599
1168113600=for Pod::Functions retrieve the next pseudorandom number
1168213601
1168313602=begin original
1168413603
1168513604Returns a random fractional number greater than or equal to C<0> and less
1168613605than the value of EXPR. (EXPR should be positive.) If EXPR is
1168713606omitted, the value C<1> is used. Currently EXPR with the value C<0> is
1168813607also special-cased as C<1> (this was undocumented before Perl 5.8.0
1168913608and is subject to change in future versions of Perl). Automatically calls
11690C<srand> unless C<srand> has already been called. See also C<srand>.
13609L<C<srand>|/srand EXPR> unless L<C<srand>|/srand EXPR> has already been
13610called. See also L<C<srand>|/srand EXPR>.
1169113611
1169213612=end original
1169313613
1169413614C<0> 以上 EXPR の値未満の小数の乱数値を返します。
1169513615(EXPR は正の数である必要があります。)
1169613616EXPR が省略されると、C<1> が使われます。
1169713617現在のところ、EXPR に値 C<0> をセットすると C<1> として特別扱いされます
1169813618(これは Perl 5.8.0 以前には文書化されておらず、将来のバージョンの perl では
1169913619変更される可能性があります)。
11700C<srand> が既に呼ばれている場合以外は、自動的に C<srand> 関数を
13620L<C<srand>|/srand EXPR> が既に呼ばれている場合以外は、自動的に
11701呼び出します。
13621L<C<srand>|/srand EXPR> 関数を呼び出します。
11702C<srand> も参照してください。
13622L<C<srand>|/srand EXPR> も参照してください。
1170313623
1170413624=begin original
1170513625
11706Apply C<int()> to the value returned by C<rand()> if you want random
13626Apply L<C<int>|/int EXPR> to the value returned by L<C<rand>|/rand EXPR>
11707integers instead of random fractional numbers. For example,
13627if you want random integers instead of random fractional numbers. For
13628example,
1170813629
1170913630=end original
1171013631
11711ランダムな小数ではなく、ランダムな整数がほしい場合は、C<rand()> から
13632ランダムな小数ではなく、ランダムな整数がほしい場合は、
11712返された値に C<int()> を適用してください。
13633L<C<rand>|/rand EXPR> から返された値に L<C<int>|/int EXPR>
13634適用してください。
1171313635例えば:
1171413636
1171513637 int(rand(10))
1171613638
1171713639=begin original
1171813640
1171913641returns a random integer between C<0> and C<9>, inclusive.
1172013642
1172113643=end original
1172213644
1172313645これは C<0> から C<9> の値をランダムに返します。
1172413646
1172513647=begin original
1172613648
1172713649(Note: If your rand function consistently returns numbers that are too
1172813650large or too small, then your version of Perl was probably compiled
1172913651with the wrong number of RANDBITS.)
1173013652
1173113653=end original
1173213654
1173313655(注: もし、rand 関数が、常に大きい値ばかりや、小さい数ばかりを
1173413656返すようなら、お使いになっている Perl が、
1173513657良くない RANDBITS を使ってコンパイルされている可能性があります。)
1173613658
1173713659=begin original
1173813660
11739B<C<rand()> is not cryptographically secure. You should not rely
13661B<L<C<rand>|/rand EXPR> is not cryptographically secure. You should not rely
1174013662on it in security-sensitive situations.> As of this writing, a
1174113663number of third-party CPAN modules offer random number generators
1174213664intended by their authors to be cryptographically secure,
1174313665including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
1174413666and L<Math::TrulyRandom>.
1174513667
1174613668=end original
1174713669
11748B<C<rand()> は暗号学的に安全ではありません。
13670B<L<C<rand>|/rand EXPR> は暗号学的に安全ではありません。
1174913671セキュリティ的に重要な状況でこれに頼るべきではありません。>
1175013672これを書いている時点で、いくつかのサードパーティ CPAN モジュールが
1175113673作者によって暗号学的に安全であることを目的とした乱数生成器を
1175213674提供しています: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
1175313675L<Math::TrulyRandom> などです。
1175413676
1175513677=item read FILEHANDLE,SCALAR,LENGTH,OFFSET
1175613678X<read> X<file, read>
1175713679
1175813680=item read FILEHANDLE,SCALAR,LENGTH
1175913681
1176013682=for Pod::Functions fixed-length buffered input from a filehandle
1176113683
1176213684=begin original
1176313685
1176413686Attempts to read LENGTH I<characters> of data into variable SCALAR
1176513687from the specified FILEHANDLE. Returns the number of characters
1176613688actually read, C<0> at end of file, or undef if there was an error (in
11767the latter case C<$!> is also set). SCALAR will be grown or shrunk
13689the latter case L<C<$!>|perlvar/$!> is also set). SCALAR will be grown
13690or shrunk
1176813691so that the last character actually read is the last character of the
1176913692scalar after the read.
1177013693
1177113694=end original
1177213695
11773指定した FILEHANDLE から、変数 SCALAR に LENGTH I<文字> の
13696指定した FILEHANDLE から、変数 SCALAR に LENGTH I<文字> のデータを
11774データを読み込みます。
13697読み込みます。
11775実際に読み込まれた文字数、
13698実際に読み込まれた文字数、ファイル終端の場合は C<0>、エラーの場合は undef の
11776ファイル終端の場合C<0>、エラーの場合は undef のいずかを返します
13699いずれかを返します (後者の場合、L<C<$!>|perlvar/$!> もセットされます)。
11777(後者の場合、C<$!> もセットされま)。
13700SCALAR は伸び縮みるので、読み込み後は、実際に読み込んだ最後の文字がスカラの
11778SCALAR は伸び縮みするで、
13701最後文字になります。
11779読み込み後は、実際に読み込んだ最後の文字がスカラの最後の文字になります。
1178013702
1178113703=begin original
1178213704
1178313705An OFFSET may be specified to place the read data at some place in the
1178413706string other than the beginning. A negative OFFSET specifies
1178513707placement at that many characters counting backwards from the end of
1178613708the string. A positive OFFSET greater than the length of SCALAR
1178713709results in the string being padded to the required size with C<"\0">
1178813710bytes before the result of the read is appended.
1178913711
1179013712=end original
1179113713
11792OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行なうことが
13714OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行なえます。
11793できます。
1179413715OFFSET に負の値を指定すると、文字列の最後から逆向きに何文字目かで
1179513716位置を指定します。
11796OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は
13717OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は読み込みの結果が
11797読み込みの結果が追加される前に、必要なサイズまで C<"\0"> のバイトで
13718追加される前に、必要なサイズまで C<"\0"> のバイトでパッディングされます。
11798パッディングされます。
1179913719
1180013720=begin original
1180113721
1180213722The call is implemented in terms of either Perl's or your system's native
11803fread(3) library function. To get a true read(2) system call, see
13723L<fread(3)> library function, via the L<PerlIO> layers applied to the
13724handle. To get a true L<read(2)> system call, see
1180413725L<sysread|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>.
1180513726
1180613727=end original
1180713728
11808この関数は、Perl か システムの fread(3) ライブラリ関数を使って実装しています。
13729この関数は、Perl か システムの L<fread(3)> ライブラリ関数を使って
11809本当の read(2) システムコールを利用るには、
13730ハンドルに適用されている L<PerlIO> 層経由で実装されていま
13731本当の L<read(2)> システムコールを利用するには、
1181013732L<sysread|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を参照してください。
1181113733
1181213734=begin original
1181313735
1181413736Note the I<characters>: depending on the status of the filehandle,
1181513737either (8-bit) bytes or characters are read. By default, all
1181613738filehandles operate on bytes, but for example if the filehandle has
11817been opened with the C<:utf8> I/O layer (see L</open>, and the C<open>
13739been opened with the C<:utf8> I/O layer (see
11818pragma, L<open>), the I/O will operate on UTF8-encoded Unicode
13740L<C<open>|/open FILEHANDLE,MODE,EXPR>, and the L<open>
11819characters, not bytes. Similarly for the C<:encoding> pragma:
13741pragma), the I/O will operate on UTF8-encoded Unicode
13742characters, not bytes. Similarly for the C<:encoding> layer:
1182013743in that case pretty much any characters can be read.
1182113744
1182213745=end original
1182313746
1182413747I<文字> に関する注意: ファイルハンドルの状態によって、(8 ビットの) バイトか
1182513748文字が読み込まれます。
1182613749デフォルトでは全てのファイルハンドルはバイトを処理しますが、
11827例えばファイルハンドルが C<:utf8> I/O 層(L</open>, C<open> プラグマ、
13750例えばファイルハンドルが C<:utf8> I/O 層
11828L<open> を参照してください) で開かれた場合、I/O はバイトではなく、
13751(L<C<open>|/open FILEHANDLE,MODE,EXPR>, L<open> プラグマを参照してください) で
13752開かれた場合、I/O はバイトではなく、
1182913753UTF8 エンコードされた Unicode 文字を操作します。
11830C<:encoding> プラグマも同様です:
13754C<:encoding> も同様です:
1183113755この場合、ほとんど大体全ての文字が読み込めます。
1183213756
1183313757=item readdir DIRHANDLE
1183413758X<readdir>
1183513759
1183613760=for Pod::Functions get a directory from a directory handle
1183713761
1183813762=begin original
1183913763
11840Returns the next directory entry for a directory opened by C<opendir>.
13764Returns the next directory entry for a directory opened by
13765L<C<opendir>|/opendir DIRHANDLE,EXPR>.
1184113766If used in list context, returns all the rest of the entries in the
1184213767directory. If there are no more entries, returns the undefined value in
1184313768scalar context and the empty list in list context.
1184413769
1184513770=end original
1184613771
11847C<opendir> でオープンしたディレクトリで、
13772L<C<opendir>|/opendir DIRHANDLE,EXPR> でオープンしたディレクトリで、次の
11848次のディレクトリエントリを返します。
13773ディレクトリエントリを返します。
11849リストコンテキストで用いると、
13774リストコンテキストで用いると、そのディレクトリの残りのエントリを、すべて
11850そのディレクトリの残りのエントリを、すべて返します。
13775返します。
1185113776エントリが残っていない場合には、スカラコンテキストでは未定義値を、
1185213777リストコンテキストでは空リストを返します。
1185313778
1185413779=begin original
1185513780
11856If you're planning to filetest the return values out of a C<readdir>, you'd
13781If you're planning to filetest the return values out of a
11857better prepend the directory in question. Otherwise, because we didn't
13782L<C<readdir>|/readdir DIRHANDLE>, you'd better prepend the directory in
11858C<chdir> there, it would have been testing the wrong file.
13783question. Otherwise, because we didn't L<C<chdir>|/chdir EXPR> there,
13784it would have been testing the wrong file.
1185913785
1186013786=end original
1186113787
11862C<readdir> の返り値をファイルテストに使おうと計画しているなら、
13788L<C<readdir>|/readdir DIRHANDLE> の返り値をファイルテストに使おうと
11863頭にディレクトリをつける必要があります。
13789計画しているなら、頭にディレクトリをつける必要があります。
11864さもなければ、ここでは C<chdir> はしないので、
13790さもなければ、ここでは L<C<chdir>|/chdir EXPR> はしないので、
1186513791間違ったファイルをテストしてしまうことになるでしょう。
1186613792
11867 opendir(my $dh, $some_dir) || die "can't opendir $some_dir: $!";
13793 opendir(my $dh, $some_dir) || die "Can't opendir $some_dir: $!";
11868 @dots = grep { /^\./ && -f "$some_dir/$_" } readdir($dh);
13794 my @dots = grep { /^\./ && -f "$some_dir/$_" } readdir($dh);
1186913795 closedir $dh;
1187013796
1187113797=begin original
1187213798
11873As of Perl 5.12 you can use a bare C<readdir> in a C<while> loop,
13799As of Perl 5.12 you can use a bare L<C<readdir>|/readdir DIRHANDLE> in a
11874which will set C<$_> on every iteration.
13800C<while> loop, which will set L<C<$_>|perlvar/$_> on every iteration.
13801If either a C<readdir> expression or an explicit assignment of a
13802C<readdir> expression to a scalar is used as a C<while>/C<for> condition,
13803then the condition actually tests for definedness of the expression's
13804value, not for its regular truth value.
1187513805
1187613806=end original
1187713807
11878Perl 5.12 から裸の C<readdir> を C<while> で使うことができ、
13808Perl 5.12 から裸の L<C<readdir>|/readdir DIRHANDLE> を C<while> で
11879この場合繰り返し毎に C<$_> にセットされます。
13809使うとができ、この場合繰り返し毎に L<C<$_>|perlvar/$_> にセットされます。
13810C<readdir> 式または C<readdir> 式からスカラへの明示的な代入が
13811C<while>/C<for> の条件部として使われた場合、
13812条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを
13813テストします。
1188013814
11881 opendir(my $dh, $some_dir) || die;
13815 opendir(my $dh, $some_dir) || die "Can't open $some_dir: $!";
11882 while(readdir $dh) {
13816 while (readdir $dh) {
1188313817 print "$some_dir/$_\n";
1188413818 }
1188513819 closedir $dh;
1188613820
1188713821=begin original
1188813822
1188913823To avoid confusing would-be users of your code who are running earlier
1189013824versions of Perl with mysterious failures, put this sort of thing at the
1189113825top of your file to signal that your code will work I<only> on Perls of a
1189213826recent vintage:
1189313827
1189413828=end original
1189513829
1189613830あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
1189713831失敗で混乱することを避けるために、コードが最近のバージョンの Perl で
1189813832I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
1189913833書いてください:
1190013834
11901 use 5.012; # so readdir assigns to $_ in a lone while test
13835 use v5.12; # so readdir assigns to $_ in a lone while test
1190213836
1190313837=item readline EXPR
1190413838
1190513839=item readline
1190613840X<readline> X<gets> X<fgets>
1190713841
1190813842=for Pod::Functions fetch a record from a file
1190913843
1191013844=begin original
1191113845
1191213846Reads from the filehandle whose typeglob is contained in EXPR (or from
1191313847C<*ARGV> if EXPR is not provided). In scalar context, each call reads and
1191413848returns the next line until end-of-file is reached, whereupon the
11915subsequent call returns C<undef>. In list context, reads until end-of-file
13849subsequent call returns L<C<undef>|/undef EXPR>. In list context, reads
11916is reached and returns a list of lines. Note that the notion of "line"
13850until end-of-file is reached and returns a list of lines. Note that the
11917used here is whatever you may have defined with C<$/> or
13851notion of "line" used here is whatever you may have defined with
11918C<$INPUT_RECORD_SEPARATOR>). See L<perlvar/"$/">.
13852L<C<$E<sol>>|perlvar/$E<sol>> (or C<$INPUT_RECORD_SEPARATOR> in
13853L<English>). See L<perlvar/"$/">.
1191913854
1192013855=end original
1192113856
1192213857型グロブが EXPR (EXPR がない場合は C<*ARGV>) に含まれている
1192313858ファイルハンドルから読み込みます。
1192413859スカラコンテキストでは、呼び出し毎に一行読み込んで返します; ファイルの
11925最後まで読み込んだら、以後の呼び出しでは C<undef> を返します。
13860最後まで読み込んだら、以後の呼び出しでは L<C<undef>|/undef EXPR> を返します。
1192613861リストコンテキストでは、ファイルの最後まで読み込んで、行のリストを返します。
11927ここでの「行」とは、C<$/> または C<$INPUT_RECORD_SEPARATOR> で
13862ここでの「行」とは、L<C<$E<sol>>|perlvar/$E<sol>> (または
13863L<English> モジュールでは C<$INPUT_RECORD_SEPARATOR>) で
1192813864定義されることに注意してください。
1192913865L<perlvar/"$/"> を参照してください。
1193013866
1193113867=begin original
1193213868
11933When C<$/> is set to C<undef>, when C<readline> is in scalar
13869When L<C<$E<sol>>|perlvar/$E<sol>> is set to L<C<undef>|/undef EXPR>,
11934context (i.e., file slurp mode), and when an empty file is read, it
13870when L<C<readline>|/readline EXPR> is in scalar context (i.e., file
11935returns C<''> the first time, followed by C<undef> subsequently.
13871slurp mode), and when an empty file is read, it returns C<''> the first
13872time, followed by L<C<undef>|/undef EXPR> subsequently.
1193613873
1193713874=end original
1193813875
11939C<$/> に C<undef> を設定した場合は、C<readline> はスカラコンテキスト
13876L<C<$E<sol>>|perlvar/$E<sol>>L<C<undef>|/undef EXPR> を設定した場合は、
11940(つまりファイル吸い込みモード)となり、
13877L<C<readline>|/readline EXPR> はスカラコンテキスト (つまりファイル吸い込み
11941空のファイルを読み込んだ場合は、最初は C<''> を返し、
13878モード)となり、空のファイルを読み込んだ場合は、最初は C<''> を返し、
11942それ以降は C<undef> を返します。
13879それ以降は L<C<undef>|/undef EXPR> を返します。
1194313880
1194413881=begin original
1194513882
1194613883This is the internal function implementing the C<< <EXPR> >>
1194713884operator, but you can use it directly. The C<< <EXPR> >>
1194813885operator is discussed in more detail in L<perlop/"I/O Operators">.
1194913886
1195013887=end original
1195113888
1195213889これは C<< <EXPR> >> 演算子を実装している内部関数ですが、
1195313890直接使うこともできます。
1195413891C<< <EXPR> >> 演算子についてのさらなる詳細については
1195513892L<perlop/"I/O Operators"> で議論されています。
1195613893
11957 $line = <STDIN>;
13894 my $line = <STDIN>;
11958 $line = readline(*STDIN); # same thing
13895 my $line = readline(STDIN); # same thing
1195913896
1196013897=begin original
1196113898
11962If C<readline> encounters an operating system error, C<$!> will be set
13899If L<C<readline>|/readline EXPR> encounters an operating system error,
11963with the corresponding error message. It can be helpful to check
13900L<C<$!>|perlvar/$!> will be set with the corresponding error message.
11964C<$!> when you are reading from filehandles you don't trust, such as a
13901It can be helpful to check L<C<$!>|perlvar/$!> when you are reading from
11965tty or a socket. The following example uses the operator form of
13902filehandles you don't trust, such as a tty or a socket. The following
11966C<readline> and dies if the result is not defined.
13903example uses the operator form of L<C<readline>|/readline EXPR> and dies
13904if the result is not defined.
1196713905
1196813906=end original
1196913907
11970C<readline> が OS のシステムエラーになると、C<$!> に対応するエラーメッセージが
13908L<C<readline>|/readline EXPR> が OS のシステムエラーになると、
11971セットされます。
13909L<C<$!>|perlvar/$!> に対応するエラーメッセージがセットされます。
1197213910tty やソケットといった、信頼できないファイルハンドルから読み込む時には
11973C<$!> をチェックするのが助けになります。
13911L<C<$!>|perlvar/$!> をチェックするのが助けになります。
11974以下の例は演算子の形の C<readline> を使っており、結果が
13912以下の例は演算子の形の L<C<readline>|/readline EXPR> を使っており、結果が
1197513913未定義の場合は die します。
1197613914
1197713915 while ( ! eof($fh) ) {
11978 defined( $_ = <$fh> ) or die "readline failed: $!";
13916 defined( $_ = readline $fh ) or die "readline failed: $!";
1197913917 ...
1198013918 }
1198113919
1198213920=begin original
1198313921
11984Note that you have can't handle C<readline> errors that way with the
13922Note that you can't handle L<C<readline>|/readline EXPR> errors
11985C<ARGV> filehandle. In that case, you have to open each element of
13923that way with the C<ARGV> filehandle. In that case, you have to open
11986C<@ARGV> yourself since C<eof> handles C<ARGV> differently.
13924each element of L<C<@ARGV>|perlvar/@ARGV> yourself since
13925L<C<eof>|/eof FILEHANDLE> handles C<ARGV> differently.
1198713926
1198813927=end original
1198913928
11990C<readline> のエラーは C<ARGV> ファイルハンドルの方法では扱えないことに
13929L<C<readline>|/readline EXPR> のエラーは C<ARGV> ファイルハンドルの方法では
11991注意してください。
13930扱えないことに注意してください。
11992この場合、C<eof> は C<ARGV> を異なった方法で扱うので、
13931この場合、L<C<eof>|/eof FILEHANDLE> は C<ARGV> を異なった方法で扱うので、
11993C<@ARGV> のそれぞれの要素を自分でオープンする必要があります。
13932L<C<@ARGV>|perlvar/@ARGV> のそれぞれの要素を自分でオープンする必要があります。
1199413933
1199513934 foreach my $arg (@ARGV) {
1199613935 open(my $fh, $arg) or warn "Can't open $arg: $!";
1199713936
1199813937 while ( ! eof($fh) ) {
11999 defined( $_ = <$fh> )
13938 defined( $_ = readline $fh )
1200013939 or die "readline failed for $arg: $!";
1200113940 ...
1200213941 }
1200313942 }
1200413943
13944=begin original
13945
13946Like the C<< <EXPR> >> operator, if a C<readline> expression is
13947used as the condition of a C<while> or C<for> loop, then it will be
13948implicitly assigned to C<$_>. If either a C<readline> expression or
13949an explicit assignment of a C<readline> expression to a scalar is used
13950as a C<while>/C<for> condition, then the condition actually tests for
13951definedness of the expression's value, not for its regular truth value.
13952
13953=end original
13954
13955C<< <EXPR> >> 演算子と同様、
13956C<readline> 式が C<while> や C<for> ループの条件として使われた場合、
13957これは暗黙に C<$_> に代入されます。
13958C<readline> 式または C<readline> 式からスカラへの明示的な代入が
13959C<while>/C<for> の条件部として使われた場合、
13960条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを
13961テストします。
13962
1200513963=item readlink EXPR
1200613964X<readlink>
1200713965
1200813966=item readlink
1200913967
1201013968=for Pod::Functions determine where a symbolic link is pointing
1201113969
1201213970=begin original
1201313971
1201413972Returns the value of a symbolic link, if symbolic links are
1201513973implemented. If not, raises an exception. If there is a system
12016error, returns the undefined value and sets C<$!> (errno). If EXPR is
13974error, returns the undefined value and sets L<C<$!>|perlvar/$!> (errno).
12017omitted, uses C<$_>.
13975If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
1201813976
1201913977=end original
1202013978
12021シンボリックリンクが実装されていれば、
13979シンボリックリンクが実装されていれば、シンボリックリンクの値を返します。
12022シンボリックリンクの値を返します。
1202313980実装されていないときには、例外が発生します。
1202413981何らかのシステムエラーが検出されると、未定義値を返し、
12025C<$!> (errno) を設定します。
13982L<C<$!>|perlvar/$!> (errno) を設定します。
12026EXPR が省略されると、C<$_> を使います。
13983EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
1202713984
1202813985=begin original
1202913986
1203013987Portability issues: L<perlport/readlink>.
1203113988
1203213989=end original
1203313990
1203413991移植性の問題: L<perlport/readlink>。
1203513992
1203613993=item readpipe EXPR
1203713994
1203813995=item readpipe
1203913996X<readpipe>
1204013997
1204113998=for Pod::Functions execute a system command and collect standard output
1204213999
1204314000=begin original
1204414001
1204514002EXPR is executed as a system command.
1204614003The collected standard output of the command is returned.
1204714004In scalar context, it comes back as a single (potentially
1204814005multi-line) string. In list context, returns a list of lines
12049(however you've defined lines with C<$/> or C<$INPUT_RECORD_SEPARATOR>).
14006(however you've defined lines with L<C<$E<sol>>|perlvar/$E<sol>> (or
14007C<$INPUT_RECORD_SEPARATOR> in L<English>)).
1205014008This is the internal function implementing the C<qx/EXPR/>
1205114009operator, but you can use it directly. The C<qx/EXPR/>
12052operator is discussed in more detail in L<perlop/"I/O Operators">.
14010operator is discussed in more detail in L<perlop/"C<qx/I<STRING>/>">.
12053If EXPR is omitted, uses C<$_>.
14011If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
1205414012
1205514013=end original
1205614014
1205714015EXPR がシステムコマンドとして実行されます。
1205814016コマンドの標準出力の内容が返されます。
1205914017スカラコンテキストでは、単一の(内部的に複数行の)文字列を返します。
1206014018リストコンテキストでは、行のリストを返します
12061(但し、行は C<$/> または C<$INPUT_RECORD_SEPARATOR> で定義されます)。
14019(但し、行は L<C<$E<sol>>|perlvar/$E<sol>> (または L<English> モジュール
12062これは C<qx/EXPR/> 演算子を実装する内部関数ですが、
14020C<$INPUT_RECORD_SEPARATOR> で定義されま)。
12063直接使うことも出来ます。
14021これは C<qx/EXPR/> 演算子を実装する内部関数ですが、直接使うことも出来ます。
12064C<qx/EXPR/> 演算子は L<perlop/"I/O Operators"> でより詳細に
14022C<qx/EXPR/> 演算子は L<perlop/"C<qx/I<STRING>/>"> でより詳細に
1206514023述べられています。
12066EXPR が省略されると、C<$_> を使います。
14024EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
1206714025
1206814026=item recv SOCKET,SCALAR,LENGTH,FLAGS
1206914027X<recv>
1207014028
1207114029=for Pod::Functions receive a message over a Socket
1207214030
1207314031=begin original
1207414032
1207514033Receives a message on a socket. Attempts to receive LENGTH characters
1207614034of data into variable SCALAR from the specified SOCKET filehandle.
1207714035SCALAR will be grown or shrunk to the length actually read. Takes the
1207814036same flags as the system call of the same name. Returns the address
1207914037of the sender if SOCKET's protocol supports this; returns an empty
1208014038string otherwise. If there's an error, returns the undefined value.
12081This call is actually implemented in terms of recvfrom(2) system call.
14039This call is actually implemented in terms of the L<recvfrom(2)> system call.
1208214040See L<perlipc/"UDP: Message Passing"> for examples.
1208314041
1208414042=end original
1208514043
1208614044ソケット上のメッセージを受信します。
1208714045指定されたファイルハンドル SOCKET から、変数 SCALAR に
1208814046LENGTH 文字のデータを読み込もうとします。
12089SCALAR は、実際に読まれた長さによって、大きくなったり、
14047SCALAR は、実際に読まれた長さによって、大きくなったり、小さくなったりします。
12090小さくなったりします。
1209114048同名のシステムコールと同じフラグが指定できます。
1209214049SOCKET のプロトコルが対応していれば、送信側のアドレスを返します。
1209314050エラー発生時には、未定義値を返します。
12094実際には、C のrecvfrom(2) を呼びます。
14051実際には、C の L<recvfrom(2)> を呼びます。
1209514052例については L<perlipc/"UDP: Message Passing"> を参照してください。
1209614053
1209714054=begin original
1209814055
12099Note the I<characters>: depending on the status of the socket, either
14056Note that if the socket has been marked as C<:utf8>, C<recv> will
12100(8-bit) bytes or characters are received. By default all sockets
14057throw an exception. The C<:encoding(...)> layer implicitly introduces
12101operate on bytes, but for example if the socket has been changed using
14058the C<:utf8> layer. See L<C<binmode>|/binmode FILEHANDLE, LAYER>.
12102binmode() to operate with the C<:encoding(utf8)> I/O layer (see the
12103C<open> pragma, L<open>), the I/O will operate on UTF8-encoded Unicode
12104characters, not bytes. Similarly for the C<:encoding> pragma: in that
12105case pretty much any characters can be read.
1210614059
1210714060=end original
1210814061
12109I<文字> に関する注意: ソケットの状態によって、(8 ビットの) バイトか
14062ソケットが C<:utf8> としてマークされている場合、
12110文字受信ます
14063C<recv> は例外投げることに注意てください
12111デフォルトで全てのソケットはバイト処理しますが、
14064C<:encoding(...)> 層暗黙に C<:utf8> 層導入します
12112例えばソケットが binmode() で C<:encoding(utf8)> I/O 層(C<open> プラグマ、
14065L<C<binmode>|/binmode FILEHANDLE, LAYER> を参照してください。
12113L<open> を参照してください) を使うように指定された場合、I/O はバイトではなく、
12114UTF8 エンコードされた Unicode 文字を操作します。
12115C<:encoding> プラグマも同様です:
12116この場合、ほとんど大体全ての文字が読み込めます。
1211714066
1211814067=item redo LABEL
1211914068X<redo>
1212014069
1212114070=item redo EXPR
1212214071
1212314072=item redo
1212414073
1212514074=for Pod::Functions start this loop iteration over again
1212614075
1212714076=begin original
1212814077
12129The C<redo> command restarts the loop block without evaluating the
14078The L<C<redo>|/redo LABEL> command restarts the loop block without
12130conditional again. The C<continue> block, if any, is not executed. If
14079evaluating the conditional again. The L<C<continue>|/continue BLOCK>
14080block, if any, is not executed. If
1213114081the LABEL is omitted, the command refers to the innermost enclosing
1213214082loop. The C<redo EXPR> form, available starting in Perl 5.18.0, allows a
1213314083label name to be computed at run time, and is otherwise identical to C<redo
12134LABEL>. Programs that want to lie to themselves about what was just input
14084LABEL>. Programs that want to lie to themselves about what was just input
1213514085normally use this command:
1213614086
1213714087=end original
1213814088
12139C<redo> コマンドは、条件を再評価しないで、ループブロックの始めからもう一度
14089L<C<redo>|/redo LABEL> コマンドは、条件を再評価しないで、ループブロックの
12140実行を開始します。
14090始めからもう一度実行を開始します。
12141C<continue> ブロックがあっても、実行されません。
14091L<C<continue>|/continue BLOCK> ブロックがあっても、実行されません。
1214214092LABEL が省略されると、コマンドは一番内側のループを参照します。
1214314093Perl 5.18.0 から利用可能な C<redo EXPR> 形式では、実行時に計算されるラベル名が
1214414094使えます; それ以外は C<redo LABEL> と同一です。
1214514095このコマンドは通常、自分への入力を欺くために使用します:
1214614096
1214714097 # a simpleminded Pascal comment stripper
1214814098 # (warning: assumes no { or } in strings)
1214914099 LINE: while (<STDIN>) {
1215014100 while (s|({.*}.*){.*}|$1 |) {}
1215114101 s|{.*}| |;
1215214102 if (s|{.*| |) {
12153 $front = $_;
14103 my $front = $_;
1215414104 while (<STDIN>) {
1215514105 if (/}/) { # end of comment?
1215614106 s|^|$front\{|;
1215714107 redo LINE;
1215814108 }
1215914109 }
1216014110 }
1216114111 print;
1216214112 }
1216314113
1216414114=begin original
1216514115
12166C<redo> cannot be used to retry a block that returns a value such as
14116L<C<redo>|/redo LABEL> cannot return a value from a block that typically
12167C<eval {}>, C<sub {}>, or C<do {}>, and should not be used to exit
14117returns a value, such as C<eval {}>, C<sub {}>, or C<do {}>. It will perform
12168a grep() or map() operation.
14118its flow control behavior, which precludes any return value. It should not be
14119used to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST>
14120operation.
1216914121
1217014122=end original
1217114123
12172C<redo> は C<eval {}>, C<sub {}>, C<do {}> のように値を返す
14124L<C<redo>|/redo LABEL> は C<eval {}>, C<sub {}>, C<do {}> といった
12173ブロックを繰りすのには使えません; また、grep() や map() 操作から抜けるのに
14125典型的には値を返すブロックから値を返ません
14126これは、返り値を不可能にするフロー制御の振る舞いを実行します。
14127L<C<grep>|/grep BLOCK LIST> や L<C<map>|/map BLOCK LIST> 操作を終了するのに
1217414128使うべきではありません。
1217514129
1217614130=begin original
1217714131
1217814132Note that a block by itself is semantically identical to a loop
12179that executes once. Thus C<redo> inside such a block will effectively
14133that executes once. Thus L<C<redo>|/redo LABEL> inside such a block
12180turn it into a looping construct.
14134will effectively turn it into a looping construct.
1218114135
1218214136=end original
1218314137
1218414138ブロック自身は一回だけ実行されるループと文法的に同一であることに
1218514139注意してください。
12186従って、ブロックの中で C<redo> を使うことで効果的に
14140従って、ブロックの中で L<C<redo>|/redo LABEL> を使うことで効果的に
1218714141ループ構造に変換します。
1218814142
1218914143=begin original
1219014144
12191See also L</continue> for an illustration of how C<last>, C<next>, and
14145See also L<C<continue>|/continue BLOCK> for an illustration of how
12192C<redo> work.
14146L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and
14147L<C<redo>|/redo LABEL> work.
1219314148
1219414149=end original
1219514150
12196C<last>, C<next>, C<redo> がどのように働くかについては
14151L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL>
12197L</continue> も参照してください。
14152どのように働くかについては L<C<continue>|/continue BLOCK> も参照してください。
1219814153
1219914154=begin original
1220014155
1220114156Unlike most named operators, this has the same precedence as assignment.
1220214157It is also exempt from the looks-like-a-function rule, so
1220314158C<redo ("foo")."bar"> will cause "bar" to be part of the argument to
12204C<redo>.
14159L<C<redo>|/redo LABEL>.
1220514160
1220614161=end original
1220714162
1220814163ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
1220914164また、関数のように見えるものの規則からも免れるので、C<redo ("foo")."bar"> と
12210すると "bar" は C<redo> への引数の一部となります。
14165すると "bar" は L<C<redo>|/redo LABEL> への引数の一部となります。
1221114166
1221214167=item ref EXPR
1221314168X<ref> X<reference>
1221414169
1221514170=item ref
1221614171
1221714172=for Pod::Functions find out the type of thing being referenced
1221814173
1221914174=begin original
1222014175
12221Returns a non-empty string if EXPR is a reference, the empty
14176Examines the value of EXPR, expecting it to be a reference, and returns
12222string otherwise. If EXPR
14177a string giving information about the reference and the type of referent.
12223is not specified, C<$_> will be used. The value returned depends on the
14178If EXPR is not specified, L<C<$_>|perlvar/$_> will be used.
12224type of thing the reference is a reference to.
12225Builtin types include:
1222614179
1222714180=end original
1222814181
12229EXPR がリファレンスであれば、空でない文字列を返し、さもなくば、
14182Examines the value of
12230空文字列返します。
14183リファレンスと想定される EXPR の値調べて、
12231EXPR が指定されなければ、C<$_> が使われま
14184そのリファレンスとリファレンス先の型に関る情報を表す
12232される値は、リファレンスが参照するものの型に依存します。
14185文字列を返します。
12233組み込みの型には以下のものあります。
14186EXPR が指定されていない場合L<C<$_>|perlvar/$_> 使われます。
1223414187
12235 SCALAR
12236 ARRAY
12237 HASH
12238 CODE
12239 REF
12240 GLOB
12241 LVALUE
12242 FORMAT
12243 IO
12244 VSTRING
12245 Regexp
12246
1224714188=begin original
1224814189
12249If the referenced object has been blessed into a package, then that package
14190If the operand is not a reference, then the empty string will be returned.
12250name is returned instead. You can think of C<ref> as a C<typeof> operator.
14191An empty string will only be returned in this situation. C<ref> is often
14192useful to just test whether a value is a reference, which can be done
14193by comparing the result to the empty string. It is a common mistake
14194to use the result of C<ref> directly as a truth value: this goes wrong
14195because C<0> (which is false) can be returned for a reference.
1225114196
1225214197=end original
1225314198
12254参照されるブジェクトが、何らかのパッケージに
14199ペランドリファレンスでない場合空文字列が返されます。
12255bless されたものであれば、れら代わり
14200空文字列はこの場合のみ返されます。
12256そのパッケージ名が返されま
14201結果を空文字列を比較ることでできるので、
12257C<ref> は、C<typeof> 演算子のよう考えことができます。
14202C<ref> はリファレンスかどうかを調べるのにしばしば有用です。
14203C<ref> の結果を直接真の値として使うのは良くある誤りです:
14204リファレンスの場合に (偽である) C<0> が返されることがあるので、
14205これは誤りです。
1225814206
12259 if (ref($r) eq "HASH") {
14207=begin original
12260 print "r is a reference to a hash.\n";
12261 }
12262 unless (ref($r)) {
12263 print "r is not a reference at all.\n";
12264 }
1226514208
14209If the operand is a reference to a blessed object, then the name of
14210the class into which the referent is blessed will be returned. C<ref>
14211doesn't care what the physical type of the referent is; blessing takes
14212precedence over such concerns. Beware that exact comparison of C<ref>
14213results against a class name doesn't perform a class membership test:
14214a class's members also include objects blessed into subclasses, for
14215which C<ref> will return the name of the subclass. Also beware that
14216class names can clash with the built-in type names (described below).
14217
14218=end original
14219
14220オペランドが bless されたオブジェクトへのリファレンスの場合、
14221リファレンス先が bless されているクラス名が返されます。
14222C<ref> はリファレンス先の物理的な種類については気にしません;
14223bless されているかがそのような関心より優先されます。
14224C<ref> の結果とクラス名の正確な比較は、クラスの所属のテストを
14225実行しないことに注意してください:
14226C<ref> がサブクラスの名前を返す場合、
14227あるクラスのメンバはサブクラスに bless されているオブジェクトを
14228含んでいます。
14229クラス名は(後述する)組み込みの型名と衝突することにも注意してください。
14230
1226614231=begin original
1226714232
12268The return value C<LVALUE> indicates a reference to an lvalue that is not
14233If the operand is a reference to an unblessed object, then the return
12269a variable. You get this from taking the reference of function calls like
14234value indicates the type of object. If the unblessed referent is not
12270C<pos()> or C<substr()>. C<VSTRING> is returned if the reference points
14235a scalar, then the return value will be one of the strings C<ARRAY>,
12271to a L<version string|perldata/"Version Strings">.
14236C<HASH>, C<CODE>, C<FORMAT>, or C<IO>, indicating only which kind of
14237object it is. If the unblessed referent is a scalar, then the return
14238value will be one of the strings C<SCALAR>, C<VSTRING>, C<REF>, C<GLOB>,
14239C<LVALUE>, or C<REGEXP>, depending on the kind of value the scalar
14240currently has. But note that C<qr//> scalars are created already
14241blessed, so C<ref qr/.../> will likely return C<Regexp>. Beware that
14242these built-in type names can also be used as
14243class names, so C<ref> returning one of these names doesn't unambiguously
14244indicate that the referent is of the kind to which the name refers.
1227214245
1227314246=end original
1227414247
12275返り値 C<LVALUE> は、変数ではない左辺値へのリファレンスを示します。
14248オペランドが bless されていないオブジェクトへのリファレンスの場合、
12276これ、C<pos()> や C<substr()> ようの関数呼び出のリファレンスから
14249返り値オブジェクト型を示ます。
12277得らます。
14250bless さていないリファレンス先がスカラではない場合、
12278C<VSTRING> 、リファレンスが L<version string|perldata/"Version Strings">
14251返り値オブジェクトの種類示す、
12279指してる場合に返さす。
14252C<ARRAY>, C<HASH>, C<CODE>, C<FORMAT>, C<IO> のかの文字列です。
14253bless されていないリファレンス先がスカラの場合、
14254返り値はそのスカラが現在保持している種類に依存して、
14255C<SCALAR>, C<VSTRING>, C<REF>, C<GLOB>, C<LVALUE>, C<REGEXP> の
14256いずれかの文字列です。
14257しかし、C<qr//> は既に bless されて作成されるので、
14258C<ref qr/.../> はおそらく C<Regexp> を返すことに注意してください。
14259これらの組み込み型名はまたクラス名として使われることができるので、
14260C<ref> がこれらの名前の一つを返すことは、
14261明らかにリファレンス先がその名前が示している種類のものであることを
14262示しているわけではないことに注意してください。
1228014263
1228114264=begin original
1228214265
12283The result C<Regexp> indicates that the argument is a regular expression
14266The ambiguity between built-in type names and class names significantly
12284resulting from C<qr//>.
14267limits the utility of C<ref>. For unambiguous information, use
14268L<C<Scalar::Util::blessed()>|Scalar::Util/blessed> for information about
14269blessing, and L<C<Scalar::Util::reftype()>|Scalar::Util/reftype> for
14270information about physical types. Use L<the C<isa> method|UNIVERSAL/C<<
14271$obj->isa( TYPE ) >>> for class membership tests, though one must be
14272sure of blessedness before attempting a method call. Alternatively, the
14273L<C<isa> operator|perlop/"Class Instance Operator"> can test class
14274membership without checking blessedness first.
1228514275
1228614276=end original
1228714277
12288C<Regexp> いう結果、引数が C<qr//> から結果である
14278組み込み型クラス名の間の曖昧さは C<ref> の有用性を大きく制限しています。
12289正規表現あることを意味しま
14279曖昧ない情報のためには、bless に関る情報については
14280L<C<Scalar::Util::blessed()>|Scalar::Util/blessed> を、
14281物理的な型の情報については
14282L<C<Scalar::Util::reftype()>|Scalar::Util/reftype> を使ってください。
14283クラスの所属メンバテストには
14284L<the C<isa> method|UNIVERSAL/C<<
14285$obj->isa( TYPE ) >>> を使ってください;
14286但し、メソッド呼び出しを試みる前に bless されていることを
14287確認しなければなりません。
14288あるいは、
14289L<C<isa> operator|perlop/"Class Instance Operator"> は、
14290最初に bless されているかを確認することなくクラスメンバをテストできます。
1229014291
1229114292=begin original
1229214293
12293See also L<perlref>.
14294See also L<perlref> and L<perlobj>.
1229414295
1229514296=end original
1229614297
12297L<perlref> も参照してください。
14298L<perlref> と L<perlobj> も参照してください。
1229814299
1229914300=item rename OLDNAME,NEWNAME
1230014301X<rename> X<move> X<mv> X<ren>
1230114302
1230214303=for Pod::Functions change a filename
1230314304
1230414305=begin original
1230514306
1230614307Changes the name of a file; an existing file NEWNAME will be
12307clobbered. Returns true for success, false otherwise.
14308clobbered. Returns true for success; on failure returns false and sets
14309L<C<$!>|perlvar/$!>.
1230814310
1230914311=end original
1231014312
1231114313ファイルの名前を変更します; NEWNAME というファイルが既に存在した場合、
1231214314上書きされるかもしれません。
12313成功時には真を、さもなければ偽を返します
14315成功時には真を返します; 失敗時には偽を返し、
14316L<C<$!>|perlvar/$!> を設定します。
1231414317
1231514318=begin original
1231614319
1231714320Behavior of this function varies wildly depending on your system
1231814321implementation. For example, it will usually not work across file system
1231914322boundaries, even though the system I<mv> command sometimes compensates
1232014323for this. Other restrictions include whether it works on directories,
1232114324open files, or pre-existing files. Check L<perlport> and either the
12322rename(2) manpage or equivalent system documentation for details.
14325L<rename(2)> manpage or equivalent system documentation for details.
1232314326
1232414327=end original
1232514328
1232614329この関数の振る舞いはシステムの実装に大きく依存して異なります。
1232714330例えば、普通はファイルシステムにまたがってパス名を付け替えることはできません;
1232814331システムの I<mv> がこれを補完している場合でもそうです。
1232914332その他の制限には、ディレクトリ、オープンしているファイル、既に存在している
1233014333ファイルに対して使えるか、といったことを含みます。
12331詳しくは、L<perlport> および rename(2) man ページあるいは同様の
14334詳しくは、L<perlport> および L<rename(2)> man ページあるいは同様の
1233214335システムドキュメントを参照してください。
1233314336
1233414337=begin original
1233514338
12336For a platform independent C<move> function look at the L<File::Copy>
14339For a platform independent L<C<move>|File::Copy/move> function look at
12337module.
14340the L<File::Copy> module.
1233814341
1233914342=end original
1234014343
12341プラットフォームに依存しない C<move> 関数については L<File::Copy> モジュールを
14344プラットフォームに依存しない L<C<move>|File::Copy/move> 関数については
12342参照してください。
14345L<File::Copy> モジュールを参照してください。
1234314346
1234414347=begin original
1234514348
1234614349Portability issues: L<perlport/rename>.
1234714350
1234814351=end original
1234914352
1235014353移植性の問題: L<perlport/rename>。
1235114354
1235214355=item require VERSION
1235314356X<require>
1235414357
1235514358=item require EXPR
1235614359
1235714360=item require
1235814361
1235914362=for Pod::Functions load in external functions from a library at runtime
1236014363
1236114364=begin original
1236214365
1236314366Demands a version of Perl specified by VERSION, or demands some semantics
12364specified by EXPR or by C<$_> if EXPR is not supplied.
14367specified by EXPR or by L<C<$_>|perlvar/$_> if EXPR is not supplied.
1236514368
1236614369=end original
1236714370
1236814371VERSION で指定される Perl のバージョンを要求するか、
12369EXPR (省略時には C<$_>) によって指定されるいくつかの動作を要求します。
14372EXPR (省略時には L<C<$_>|perlvar/$_>) によって指定されるいくつかの動作を
14373要求します。
1237014374
1237114375=begin original
1237214376
12373VERSION may be either a numeric argument such as 5.006, which will be
14377VERSION may be either a literal such as v5.24.1, which will be
12374compared to C<$]>, or a literal of the form v5.6.1, which will be compared
14378compared to L<C<$^V>|perlvar/$^V> (or C<$PERL_VERSION> in L<English>),
12375to C<$^V> (aka $PERL_VERSION). An exception is raised if
14379or a numeric argument of the form 5.024001, which will be compared to
12376VERSION is greater than the version of the current Perl interpreter.
14380L<C<$]>|perlvar/$]>. An exception is raised if VERSION is greater than
12377Compare with L</use>, which can do a similar check at compile time.
14381the version of the current Perl interpreter. Compare with
14382L<C<use>|/use Module VERSION LIST>, which can do a similar check at
14383compile time.
1237814384
1237914385=end original
1238014386
12381VERSION は 5.006 のような数値(C<$]> と比較されます)か、v5.6.1 の
14387VERSION は、v5.24.1 のようなリテラル
12382(C<$^V> (またの名を $PERL_VERSION) と比較されます)指定します。
14388(L<C<$^V>|perlvar/$^V> (また L<English> モジュール
14389C<$PERL_VERSION>) と比較されます) か、
143905.024001 の数値形式(L<C<$]>|perlvar/$]> と比較されます)で指定します。
1238314391VERSION が Perl の現在のバージョンより大きいと、例外が発生します。
12384L</use> と似ていますが、これはコンパイル時にチェックされます。
14392L<C<use>|/use Module VERSION LIST> と似ていますが、これはコンパイル時に
14393チェックされます。
1238514394
1238614395=begin original
1238714396
12388Specifying VERSION as a literal of the form v5.6.1 should generally be
14397Specifying VERSION as a numeric argument of the form 5.024001 should
12389avoided, because it leads to misleading error messages under earlier
14398generally be avoided as older less readable syntax compared to
12390versions of Perl that do not support this syntax. The equivalent numeric
14399v5.24.1. Before perl 5.8.0 (released in 2002), the more verbose numeric
12391version should be used instead.
14400form was the only supported syntax, which is why you might see it in
14401older code.
1239214402
1239314403=end original
1239414404
12395VERSION に v5.6.1 の形のリテラルを指定することは一般的には避けるべきです;
14405VERSION に 5.024001 の形の数値引数を指定することは一般的には避けるべきです;
12396なぜなら、この文法対応していない Perl の初期のバージョン
14406v5.24.1 比べより古く読みにく文法だからす。
12397誤解せるうなエラーメッセージが出るからす。
14407(2002 年にリリースれた) perl 5.8.0 り前は、より冗長な
12398代わりに等価な数値表現を使うべきす。
14408数値形式が唯一対応している文法した; これが古いコードでこれを
14409見るかも知れない理由です。
1239914410
1240014411=begin original
1240114412
12402 require v5.6.1; # run time version check
14413 require v5.24.1; # run time version check
12403 require 5.6.1; # ditto
14414 require 5.24.1; # ditto
12404 require 5.006_001; # ditto; preferred for backwards
14415 require 5.024_001; # ditto; older syntax compatible
12405 compatibility
14416 with perl 5.6
1240614417
1240714418=end original
1240814419
12409 require v5.6.1; # 実行時バージョンチェック
14420 require v5.24.1; # 実行時バージョンチェック
12410 require 5.6.1; # 同様
14421 require 5.24.1; # 同様
12411 require 5.006_001; # 同様; 後方互換性のためには望まし
14422 require 5.024_001; # 同様; perl 5.6 と互換性のある古文法
1241214423
1241314424=begin original
1241414425
12415Otherwise, C<require> demands that a library file be included if it
14426Otherwise, L<C<require>|/require VERSION> demands that a library file be
12416hasn't already been included. The file is included via the do-FILE
14427included if it hasn't already been included. The file is included via
12417mechanism, which is essentially just a variety of C<eval> with the
14428the do-FILE mechanism, which is essentially just a variety of
14429L<C<eval>|/eval EXPR> with the
1241814430caveat that lexical variables in the invoking script will be invisible
12419to the included code. Has semantics similar to the following subroutine:
14431to the included code. If it were implemented in pure Perl, it
14432would have semantics similar to the following:
1242014433
1242114434=end original
1242214435
12423それ以外の場合には、C<require> は、既に読み込まれていないときに読み込む
14436それ以外の場合には、L<C<require>|/require VERSION> は、既に
12424ライブラリファイルを要求するものとなります。
14437読み込まれていないときに読み込むライブラリファイルを要求するものとなります。
12425そのファイルは、基本的には C<eval> の一種である、do-FILE によって
14438そのファイルは、基本的には L<C<eval>|/eval EXPR> の一種である、
12426読み込まれますが、起動したスクリプトのレキシカル変数は読み込まれたコードから
14439do-FILE によって読み込まれますが、起動したスクリプトのレキシカル変数は
12427見えないという欠点があります。
14440読み込まれたコードから見えないという欠点があります。
12428意味的には、次のようなサブルーチンと同じようなものです:
14441ピュア Perl で実装した場合、意味的には、次のようなサブルーチンと
14442同じようなものです:
1242914443
14444 use Carp 'croak';
14445 use version;
14446
1243014447 sub require {
12431 my ($filename) = @_;
14448 my ($filename) = @_;
12432 if (exists $INC{$filename}) {
14449 if ( my $version = eval { version->parse($filename) } ) {
12433 return 1 if $INC{$filename};
14450 if ( $version > $^V ) {
12434 die "Compilation failed in require";
14451 my $vn = $version->normal;
12435 }
14452 croak "Perl $vn required--this is only $^V, stopped";
12436 my ($realfilename,$result);
14453 }
12437 ITER: {
14454 return 1;
12438 foreach $prefix (@INC) {
14455 }
12439 $realfilename = "$prefix/$filename";
12440 if (-f $realfilename) {
14457 if (exists $INC{$filename}) {
12441 $INC{$filename} = $realfilename;
14458 return 1 if $INC{$filename};
12442 $result = do $realfilename;
14459 croak "Compilation failed in require";
12443 last ITER;
14460 }
12444 }
12445 }
14462 local $INC;
12446 die "Can't find $filename in \@INC";
14463 # this type of loop lets a hook overwrite $INC if they wish
12447 }
14464 for($INC = 0; $INC < @INC; $INC++) {
12448 if ($@) {
14465 my $prefix = $INC[$INC];
12449 $INC{$filename} = undef;
14466 if (!defined $prefix) {
12450 die $@;
14467 next;
12451 } elsif (!$result) {
14468 }
12452 delete $INC{$filename};
14469 if (ref $prefix) {
12453 die "$filename did not return true value";
14470 #... do other stuff - see text below ....
12454 } else {
14471 }
12455 return $result;
14472 # (see text below about possible appending of .pmc
12456 }
14473 # suffix to $filename)
14474 my $realfilename = "$prefix/$filename";
14475 next if ! -e $realfilename || -d _ || -b _;
14476 $INC{$filename} = $realfilename;
14477 my $result = do($realfilename);
14478 # but run in caller's namespace
14479
14480 if (!defined $result) {
14481 $INC{$filename} = undef;
14482 croak $@ ? "$@Compilation failed in require"
14483 : "Can't locate $filename: $!\n";
14484 }
14485 if (!$result) {
14486 delete $INC{$filename};
14487 croak "$filename did not return true value";
14488 }
14489 $! = 0;
14490 return $result;
14491 }
14492 croak "Can't locate $filename in \@INC ...";
1245714493 }
1245814494
1245914495=begin original
1246014496
1246114497Note that the file will not be included twice under the same specified
1246214498name.
1246314499
1246414500=end original
1246514501
1246614502ファイルは、同じ名前で 2 回読み込まれることはないことに注意してください。
1246714503
1246814504=begin original
1246914505
12470The file must return true as the last statement to indicate
14506Historically the file must return true as the last statement to indicate
1247114507successful execution of any initialization code, so it's customary to
1247214508end such a file with C<1;> unless you're sure it'll return true
1247314509otherwise. But it's better just to put the C<1;>, in case you add more
12474statements.
14510statements. As of 5.37.6 this requirement may be avoided by enabling
14511the 'module_true' feature, which is enabled by default in modern
14512version bundles. Thus code with C<use v5.37;> no longer needs to concern
14513itself with this issue. See L<feature> for more details. Note that this
14514affects the compilation unit within which the feature is used, and using
14515it before requiring a module will not change the behavior of existing
14516modules that do not themselves also use it.
1247514517
1247614518=end original
1247714519
12478初期化コードの実行がうまくいったことを示すために、
14520歴史的に、初期化コードの実行がうまくいったことを示すために、ファイルは真を
12479ファイルは真を返さなければなりませんから、
14521返さなければならないので、真を返すようになっている自信がある場合を除いては
12480真を返すようになっている自信がある場合を除いては、
1248114522ファイルの最後に C<1;> と書くのが習慣です。
12482実行文を追加するような場合に備えて、C<1;> と書いておいた方が
14523しかし、実行文を追加するような場合に備えて、C<1;> と書いておいた方が良いです。
12483良いでしょう。
14524As of 5.37.6 this requirement may be avoided by enabling
14525the 'module_true' feature, which is enabled by default in modern
14526version bundles. Thus code with C<use v5.37;> no longer needs to concern
14527itself with this issue. See L<feature> for more details. Note that this
14528affects the compilation unit within which the feature is used, and using
14529it before requiring a module will not change the behavior of existing
14530modules that do not themselves also use it.
14531(TBT)
1248414532
1248514533=begin original
1248614534
12487If EXPR is a bareword, the require assumes a "F<.pm>" extension and
14535If EXPR is a bareword, L<C<require>|/require VERSION> assumes a F<.pm>
12488replaces "F<::>" with "F</>" in the filename for you,
14536extension and replaces C<::> with C</> in the filename for you,
1248914537to make it easy to load standard modules. This form of loading of
12490modules does not risk altering your namespace.
14538modules does not risk altering your namespace, however it will autovivify
14539the stash for the required module.
1249114540
1249214541=end original
1249314542
12494EXPR が裸の単語であるときには、標準モジュールのロードを
14543EXPR が裸の単語であるときには、標準モジュールのロードを簡単にするように、
12495簡単にするように、require は拡張子が "F<.pm>" であり、
14544L<C<require>|/require VERSION> は拡張子が F<.pm> であり、C<::> を C</> に
12496"F<::>" を "F</>" に変えたものがファイル名であると仮定します。
14545変えたものがファイル名であると仮定します。
12497この形式のモジュールロードは、
14546この形式のモジュールロードは、名前空間を変更してしまう危険はありませんが、
12498名前空間を変更してしう危険はありません
14547要求されたモジュールのためのスタッシュが自動有効化され
1249914548
1250014549=begin original
1250114550
1250214551In other words, if you try this:
1250314552
1250414553=end original
1250514554
1250614555言い換えると、以下のようにすると:
1250714556
1250814557 require Foo::Bar; # a splendid bareword
1250914558
1251014559=begin original
1251114560
12512The require function will actually look for the "F<Foo/Bar.pm>" file in the
14561The require function will actually look for the F<Foo/Bar.pm> file in the
12513directories specified in the C<@INC> array.
14562directories specified in the L<C<@INC>|perlvar/@INC> array, and it will
14563autovivify the C<Foo::Bar::> stash at compile time.
1251414564
1251514565=end original
1251614566
12517require 関数は C<@INC> 配列で指定されたディレクトリにある
14567require 関数は L<C<@INC>|perlvar/@INC> 配列で指定されたディレクトリにある
12518"F<Foo/Bar.pm>" ファイルを探します。
14568F<Foo/Bar.pm> ファイルを探し、コンパイル時に
14569C<Foo::Bar::> のスタッシュを自動有効化します。
1251914570
1252014571=begin original
1252114572
1252214573But if you try this:
1252314574
1252414575=end original
1252514576
1252614577しかし、以下のようにすると:
1252714578
12528 $class = 'Foo::Bar';
14579 my $class = 'Foo::Bar';
1252914580 require $class; # $class is not a bareword
1253014581 #or
1253114582 require "Foo::Bar"; # not a bareword because of the ""
1253214583
1253314584=begin original
1253414585
12535The require function will look for the "F<Foo::Bar>" file in the @INC array and
14586The require function will look for the F<Foo::Bar> file in the
12536will complain about not finding "F<Foo::Bar>" there. In this case you can do:
14587L<C<@INC>|perlvar/@INC> array and
14588will complain about not finding F<Foo::Bar> there. In this case you can do:
1253714589
1253814590=end original
1253914591
12540require 関数は @INC 配列の "F<Foo::Bar>" ファイルを探し、
14592require 関数は L<C<@INC>|perlvar/@INC> 配列の F<Foo::Bar> ファイルを探し、
12541おそらくそこに "F<Foo::Bar>" がないと文句をいうことになるでしょう。
14593おそらくそこに F<Foo::Bar> がないと文句をいうことになるでしょう。
12542このような場合には、以下のようにします:
14594このような場合には、以下のように:
1254314595
1254414596 eval "require $class";
1254514597
1254614598=begin original
1254714599
12548Now that you understand how C<require> looks for files with a
14600or you could do
12549bareword argument, there is a little extra functionality going on behind
12550the scenes. Before C<require> looks for a "F<.pm>" extension, it will
12551first look for a similar filename with a "F<.pmc>" extension. If this file
12552is found, it will be loaded in place of any file ending in a "F<.pm>"
12553extension.
1255414601
1255514602=end original
1255614603
12557引数が裸単語の場合、C<require> がどのようにファイルを探かを
14604あるいは次のようにも出来ま
12558理解してください; 水面下でちょっとした追加の機能があります。
12559C<require> が拡張子 "F<.pm>" のファイルを探す前に、まず拡張子 "F<.pmc>" を
14606 require "Foo/Bar.pm";
12560持つファイルを探します。
12561このファイルが見つかると、このファイルが拡張子 "F<.pm>" の代わりに
14608=begin original
14609
14610Neither of these forms will autovivify any stashes at compile time and
14611only have run time effects.
14612
14613=end original
14614
14615これらのどちらもコンパイル時にスタッシュを自動有効化せず、
14616実行時の効果のみを持ちます。
14617
14618=begin original
14619
14620Now that you understand how L<C<require>|/require VERSION> looks for
14621files with a bareword argument, there is a little extra functionality
14622going on behind the scenes. Before L<C<require>|/require VERSION> looks
14623for a F<.pm> extension, it will first look for a similar filename with a
14624F<.pmc> extension. If this file is found, it will be loaded in place of
14625any file ending in a F<.pm> extension. This applies to both the explicit
14626C<require "Foo/Bar.pm";> form and the C<require Foo::Bar;> form.
14627
14628=end original
14629
14630引数が裸の単語の場合、L<C<require>|/require VERSION> がどのようにファイルを
14631探すかを理解してください; 水面下でちょっとした追加の機能があります。
14632L<C<require>|/require VERSION> が拡張子 F<.pm> のファイルを探す前に、まず
14633拡張子 F<.pmc> を持つファイルを探します。
14634このファイルが見つかると、このファイルが拡張子 F<.pm> の代わりに
1256214635読み込まれます。
14636これは明示的な C<require "Foo/Bar.pm";> 形式と C<require Foo::Bar;> 形式の
14637両方に適用されます。
1256314638
1256414639=begin original
1256514640
12566You can also insert hooks into the import facility by putting Perl code
14641You can also insert hooks into the import facility by putting Perl
12567directly into the @INC array. There are three forms of hooks: subroutine
14642coderefs or objects directly into the L<C<@INC>|perlvar/@INC> array.
12568references, array references, and blessed objects.
14643There are two types of hooks, INC filters, and INCDIR hooks, and there
14644are three forms of representing a hook: subroutine references, array
14645references, and blessed objects.
1256914646
1257014647=end original
1257114648
12572@INC 配列に直接 Perl コードを入れることで、インポート機能にクを
14649L<C<@INC>|perlvar/@INC> 配列に直接コードァレンスやオブジェ
12573挿入できます。
14650入れることで、インポート機能にフックを挿入できます。
125743 種類のフックがあります: サブルーチンリファレンス、配列リファレンス、
14651There are two types of hooks, INC filters, and INCDIR hooks, and there
12575bless されたオブジェトで
14652フッの表現方法は 3 種類ありま: サブルーチンリファレンス、
14653配列リファレンス、bless されたオブジェクトです。
14654(TBT)
1257614655
1257714656=begin original
1257814657
1257914658Subroutine references are the simplest case. When the inclusion system
12580walks through @INC and encounters a subroutine, this subroutine gets
14659walks through L<C<@INC>|perlvar/@INC> and encounters a subroutine, unless
12581called with two parameters, the first a reference to itself, and the
14660this subroutine is blessed and supports an INCDIR hook this
12582second the name of the file to be included (e.g., "F<Foo/Bar.pm>"). The
14661subroutine will be assumed to be an INC hook will be called with two
12583subroutine should return either nothing or else a list of up to three
14662parameters, the first a reference to itself, and the second the name of
12584values in the following order:
14663the file to be included (e.g., F<Foo/Bar.pm>). The subroutine should
14664return either nothing or else a list of up to four values in the
14665following order:
1258514666
1258614667=end original
1258714668
1258814669サブルーチンへのリファレンスは一番単純な場合です。
12589インクルード機能が @INC を走査してサブルーチンに出会った場合、この
14670インクルード機能が L<C<@INC>|perlvar/@INC> を走査してサブルーチンに
12590サブルーチンは二つの引数と共に呼びされます;
14671会った場合、
14672このサブルーチンが bless されていて INCDIR フックに対応していない限り、
14673このサブルーチンは二つの引数と共に呼び出される INC フックであると
14674仮定されます;
1259114675一つ目は自身へのリファレンス、二つ目はインクルードされるファイル名
12592("F<Foo/Bar.pm>" など)です。
14676(F<Foo/Bar.pm> など)です。
12593サブルーチンは何も返さないか、以下の順で最大つの値のリストを
14677サブルーチンは何も返さないか、以下の順で最大つの値のリストを返します。
12594返します。
1259514678
1259614679=over
1259714680
1259814681=item 1
1259914682
1260014683=begin original
1260114684
12602A filehandle, from which the file will be read.
14685A reference to a scalar, containing any initial source code to prepend to
14686the file or generator output.
1260314687
1260414688=end original
1260514689
12606ファイルが読み込まれるファイルハンル。
14690ファイルやジェネレータの出力の前に追加される初期化ソースコーを含む
14691スカラへのリファレンス。
1260714692
1260814693=item 2
1260914694
1261014695=begin original
1261114696
14697A filehandle, from which the file will be read.
14698
14699=end original
14700
14701ファイルが読み込まれるファイルハンドル。
14702
14703=item 3
14704
14705=begin original
14706
1261214707A reference to a subroutine. If there is no filehandle (previous item),
1261314708then this subroutine is expected to generate one line of source code per
12614call, writing the line into C<$_> and returning 1, then finally at end of
14709call, writing the line into L<C<$_>|perlvar/$_> and returning 1, then
12615file returning 0. If there is a filehandle, then the subroutine will be
14710finally at end of file returning 0. If there is a filehandle, then the
12616called to act as a simple source filter, with the line as read in C<$_>.
14711subroutine will be called to act as a simple source filter, with the
14712line as read in L<C<$_>|perlvar/$_>.
1261714713Again, return 1 for each valid line, and 0 after all lines have been
1261814714returned.
14715For historical reasons the subroutine will receive a meaningless argument
14716(in fact always the numeric value zero) as C<$_[0]>.
1261914717
1262014718=end original
1262114719
1262214720サブルーチンへのリファレンス。
12623(一つ前のアイテムである)ファイルハンドルがない場合、
14721(一つ前のアイテムである)ファイルハンドルがない場合、サブルーチンは呼び出し毎に
12624サブルーチンは呼び出し毎に一行のソースコードを生成し、その行を C<$_> に
14722一行のソースコードを生成し、その行を L<C<$_>|perlvar/$_>書き込んで 1 を
12625書き込んで 1 を返し、それから最終的にファイル終端で 0 を返すものと
14723返し、それから最終的にファイル終端で 0 を返すものと想定されます。
12626想定されます。
1262714724ファイルハンドルがある場合、サブルーチンは単純なソースフィルタとして
12628振舞うように呼び出され、行は C<$_> から読み込まれます。
14725振舞うように呼び出され、行は L<C<$_>|perlvar/$_> から読み込まれます。
1262914726再び、有効な行ごとに 1 を返し、全ての行を返した後では 0 を返します。
14727歴史的な理由により、サブルーチンは C<$_[0]> として意味のない引数
14728(実際には常に数値 0) を受け取ります。
1263014729
12631=item 3
14730=item 4
1263214731
1263314732=begin original
1263414733
12635Optional state for the subroutine. The state is passed in as C<$_[1]>. A
14734Optional state for the subroutine. The state is passed in as C<$_[1]>.
12636reference to the subroutine itself is passed in as C<$_[0]>.
1263714735
1263814736=end original
1263914737
1264014738サブルーチンのための状態(オプション)。
1264114739状態は C<$_[1]> として渡されます。
12642サブルーチンへのリファレンス自身は C<$_[0]> として渡されます。
1264314740
1264414741=back
1264514742
1264614743=begin original
1264714744
12648If an empty list, C<undef>, or nothing that matches the first 3 values above
14745C<AUTOLOAD> cannot be used to resolve the C<INCDIR> method, C<INC> is
12649is returned, then C<require> looks at the remaining elements of @INC.
14746checked first, and C<AUTOLOAD> would resolve that.
14747
14748=end original
14749
14750C<AUTOLOAD> cannot be used to resolve the C<INCDIR> method, C<INC> is
14751checked first, and C<AUTOLOAD> would resolve that.
14752(TBT)
14753
14754=begin original
14755
14756If an empty list, L<C<undef>|/undef EXPR>, or nothing that matches the
14757first 3 values above is returned, then L<C<require>|/require VERSION>
14758looks at the remaining elements of L<C<@INC>|perlvar/@INC>.
1265014759Note that this filehandle must be a real filehandle (strictly a typeglob
12651or reference to a typeglob, whether blessed or unblessed); tied filehandles
14760or reference to a typeglob, whether blessed or unblessed); tied filehandles
1265214761will be ignored and processing will stop there.
1265314762
1265414763=end original
1265514764
12656空リスト、C<undef>、または上記の最初の三つの値のどれとも一致しないものが
14765空リスト、L<C<undef>|/undef EXPR>、または上記の最初の三つの値のどれとも
12657返されると、C<require> は @INC の残りの要素を見ます。
14766一致しないものが返されると、L<C<require>|/require VERSION>
14767L<C<@INC>|perlvar/@INC> の残りの要素を見ます。
1265814768このファイルハンドルは実際のファイルハンドル(厳密には型グロブ、型グロブへの
1265914769リファレンス、bless されているかに関わらず)でなければなりません;
1266014770tie されたファイルハンドルは無視され、返り値の処理はそこで停止します。
1266114771
1266214772=begin original
1266314773
12664If the hook is an array reference, its first element must be a subroutine
14774If the hook is an object, it should provide an C<INC> or C<INCDIR>
12665reference. This subroutine is called as above, but the first parameter is
14775method that will be called as above, the first parameter being the
12666the array reference. This lets you indirectly pass arguments to
14776object itself. If it does not provide either method, and the object is
12667the subroutine.
14777not CODE ref then an exception will be thrown, otherwise it will simply
14778be executed like an unblessed CODE ref would. Note that you must fully
14779qualify the method name when you declare an C<INC> sub (unlike the
14780C<INCDIR> sub), as the unqualified symbol C<INC> is always forced into
14781package C<main>. Here is a typical code layout for an C<INC> hook:
1266814782
1266914783=end original
1267014784
12671フックが配列リファレンスの場合、その最初の要素はサブルーチンへの
14785フックがオブジェクトの場合、C<INC> か C<INCDIR> メソッドを提供している
12672リファレンスでなければなりません。
14786必要があります;
12673ルーチンは上述のように呼び出されますが、その最初の引数は
14787それが、最初引数をオジェクト自身として上述のように呼び出されます
12674配列のリファレンスです。
14788If it does not provide either method, and the object is
12675これによって、間接的にサブルーチンに引数を渡すことが出来ます。
14789not CODE ref then an exception will be thrown, otherwise it will simply
14790be executed like an unblessed CODE ref would.
14791修飾されていない C<INC> シンボルは常にパッケージ C<main> に強制されるため、
14792C<INC> サブルーチンを宣言する場合は、
14793(C<INCDIR> サブルーチンと異なり)
14794完全修飾しなければならないことに注意してください。
14795以下は C<INC> フックの典型的なコードレイアウトです:
14796(TBT)
1267614797
14798 # In Foo.pm
14799 package Foo;
14800 sub new { ... }
14801 sub Foo::INC {
14802 my ($self, $filename) = @_;
14803 ...
14804 }
14805
14806 # In the main program
14807 push @INC, Foo->new(...);
14808
1267714809=begin original
1267814810
14811If the hook is an array reference, its first element must be a
14812subroutine reference or an object as described above. When the first
14813element is an object that supports an C<INC> or C<INCDIR> method then
14814the method will be called with the object as the first argument, the
14815filename requested as the second, and the hook array reference as the
14816the third. When the first element is a subroutine then it will be
14817called with the array as the first argument, and the filename as the
14818second, no third parameter will be passed in. In both forms you can
14819modify the contents of the array to provide state between calls, or
14820whatever you like.
14821
14822=end original
14823
14824フックが配列のリファレンスの場合、その最初の要素は前述の通り、
14825サブルーチンリファレンスかオブジェクトでなければなりません。
14826When the first
14827element is an object that supports an C<INC> or C<INCDIR> method then
14828the method will be called with the object as the first argument, the
14829filename requested as the second, and the hook array reference as the
14830the third. When the first element is a subroutine then it will be
14831called with the array as the first argument, and the filename as the
14832second, no third parameter will be passed in. In both forms you can
14833modify the contents of the array to provide state between calls, or
14834whatever you like.
14835(TBT)
14836
14837=begin original
14838
1267914839In other words, you can write:
1268014840
1268114841=end original
1268214842
1268314843言い換えると、以下のように書いたり:
1268414844
1268514845 push @INC, \&my_sub;
1268614846 sub my_sub {
1268714847 my ($coderef, $filename) = @_; # $coderef is \&my_sub
1268814848 ...
1268914849 }
1269014850
1269114851=begin original
1269214852
1269314853or:
1269414854
1269514855=end original
1269614856
12697または以下のように書けます:
14857または:
1269814858
1269914859 push @INC, [ \&my_sub, $x, $y, ... ];
1270014860 sub my_sub {
1270114861 my ($arrayref, $filename) = @_;
1270214862 # Retrieve $x, $y, ...
12703 my @parameters = @$arrayref[1..$#$arrayref];
14863 my (undef, @parameters) = @$arrayref;
1270414864 ...
1270514865 }
1270614866
1270714867=begin original
1270814868
12709If the hook is an object, it must provide an INC method that will be
14869or:
12710called as above, the first parameter being the object itself. (Note that
12711you must fully qualify the sub's name, as unqualified C<INC> is always forced
12712into package C<main>.) Here is a typical code layout:
1271314870
1271414871=end original
1271514872
12716フックがオブジェクトの場合、INC メソッドを提供している必要がありす;
14873たは:
12717それが、最初の引数をオブジェクト自身として上述のように呼び出されます。
12718(修飾されていない C<INC> は常にパッケージ C<main> に強制されるため、
12719サブルーチン名は完全修飾する必要があることに注意してください。)
12720以下は典型的なコードレイアウトです:
1272114874
12722 # In Foo.pm
14875 push @INC, [ HookObj->new(), $x, $y, ... ];
12723 package Foo;
14876 sub HookObj::INC {
12724 sub new { ... }
14877 my ($self, $filename, $arrayref)= @_;
12725 sub Foo::INC {
14878 my (undef, @parameters) = @$arrayref;
12726 my ($self, $filename) = @_;
1272714879 ...
1272814880 }
1272914881
12730 # In the main program
12731 push @INC, Foo->new(...);
12732
1273314882=begin original
1273414883
12735These hooks are also permitted to set the %INC entry
14884These hooks are also permitted to set the L<C<%INC>|perlvar/%INC> entry
1273614885corresponding to the files they have loaded. See L<perlvar/%INC>.
14886Should an C<INC> hook not do this then perl will set the C<%INC> entry
14887to be the hook reference itself.
1273714888
1273814889=end original
1273914890
12740これらのフックは、読み込まれるファイルに対応する %INC エントリを
14891これらのフックは、読み込まれるファイルに対応する
12741セットすることも許可します。
14892L<C<%INC>|perlvar/%INC> エントリをセットすることも許可します。
1274214893L<perlvar/%INC> を参照してください。
14894Should an C<INC> hook not do this then perl will set the C<%INC> entry
14895to be the hook reference itself.
14896(TBT)
1274314897
1274414898=begin original
1274514899
12746For a yet-more-powerful import facility, see L</use> and L<perlmod>.
14900A hook may also be used to rewrite the C<@INC> array. While this might
14901sound strange, there are situations where it can be very useful to do
14902this. Such hooks usually just return undef and do not mix filtering and
14903C<@INC> modifications. While in older versions of perl having a hook
14904modify C<@INC> was fraught with issues and could even result in
14905segfaults or assert failures, as of 5.37.7 the logic has been made much
14906more robust and the hook now has control over the loop iteration if it
14907wishes to do so.
1274714908
1274814909=end original
1274914910
12750より強力な import 機能については、このドキュメントの
14911A hook may also be used to rewrite the C<@INC> array. While this might
12751L</use> の項と、L<perlmod> を参照してください。
14912sound strange, there are situations where it can be very useful to do
14913this. Such hooks usually just return undef and do not mix filtering and
14914C<@INC> modifications. While in older versions of perl having a hook
14915modify C<@INC> was fraught with issues and could even result in
14916segfaults or assert failures, as of 5.37.7 the logic has been made much
14917more robust and the hook now has control over the loop iteration if it
14918wishes to do so.
14919(TBT)
1275214920
14921=begin original
14922
14923There is a now a facility to control the iterator for the C<@INC> array
14924traversal that is performed during require. The C<$INC> variable will be
14925initialized with the index of the currently executing hook. Once the
14926hook returns the next slot in C<@INC> that will be checked will be the
14927integer successor of value in C<$INC> (or -1 if it is undef). For example
14928the following code
14929
14930=end original
14931
14932There is a now a facility to control the iterator for the C<@INC> array
14933traversal that is performed during require. The C<$INC> variable will be
14934initialized with the index of the currently executing hook. Once the
14935hook returns the next slot in C<@INC> that will be checked will be the
14936integer successor of value in C<$INC> (or -1 if it is undef). For example
14937the following code
14938(TBT)
14939
14940 push @INC, sub {
14941 splice @INC, $INC, 1; # remove this hook from @INC
14942 unshift @INC, sub { warn "A" };
14943 undef $INC; # reset the $INC iterator so we
14944 # execute the newly installed sub
14945 # immediately.
14946 };
14947
14948=begin original
14949
14950would install a sub into C<@INC> that when executed as a hook (by for
14951instance a require of a file that does not exist), the hook will splice
14952itself out of C<@INC>, and add a new sub to the front that will warn
14953whenever someone does a require operation that requires an C<@INC>
14954search, and then immediately execute that hook.
14955
14956=end original
14957
14958would install a sub into C<@INC> that when executed as a hook (by for
14959instance a require of a file that does not exist), the hook will splice
14960itself out of C<@INC>, and add a new sub to the front that will warn
14961whenever someone does a require operation that requires an C<@INC>
14962search, and then immediately execute that hook.
14963(TBT)
14964
14965=begin original
14966
14967Prior to 5.37.7, there was no way to cause perl to use the newly
14968installed hook immediately, or to inspect any changed items in C<@INC> to
14969the left of the iterator, and so the warning would only be generated on
14970the second call to require. In more recent perl the presence of the last
14971statement which undefines C<$INC> will cause perl to restart the
14972traversal of the C<@INC> array at the beginning and execute the newly
14973installed sub immediately.
14974
14975=end original
14976
14977Prior to 5.37.7, there was no way to cause perl to use the newly
14978installed hook immediately, or to inspect any changed items in C<@INC> to
14979the left of the iterator, and so the warning would only be generated on
14980the second call to require. In more recent perl the presence of the last
14981statement which undefines C<$INC> will cause perl to restart the
14982traversal of the C<@INC> array at the beginning and execute the newly
14983installed sub immediately.
14984(TBT)
14985
14986=begin original
14987
14988Whatever value C<$INC> held, if any, will be restored at the end of the
14989require. Any changes made to C<$INC> during the lifetime of the hook
14990will be unrolled after the hook exits, and its value only has meaning
14991immediately after execution of the hook, thus setting C<$INC> to some
14992value prior to executing a C<require> will have no effect on how the
14993require executes at all.
14994
14995=end original
14996
14997Whatever value C<$INC> held, if any, will be restored at the end of the
14998require. Any changes made to C<$INC> during the lifetime of the hook
14999will be unrolled after the hook exits, and its value only has meaning
15000immediately after execution of the hook, thus setting C<$INC> to some
15001value prior to executing a C<require> will have no effect on how the
15002require executes at all.
15003(TBT)
15004
15005=begin original
15006
15007As of 5.37.7 C<@INC> values of undef will be silently ignored.
15008
15009=end original
15010
15011As of 5.37.7 C<@INC> values of undef will be silently ignored.
15012(TBT)
15013
15014=begin original
15015
15016The function C<require()> is difficult to wrap properly. Many modules
15017consult the stack to find information about their caller, and injecting
15018a new stack frame by wrapping C<require()> often breaks things.
15019Nevertheless it can be very helpful to have the ability to perform
15020actions before and after a C<require>, for instance for trace utilities
15021like C<Devel::TraceUse> or to measure time to load and the memory
15022consumption of the require graph. Because of the difficulties in safely
15023creating a C<require()> wrapper in 5.37.10 we introduced a new mechanism.
15024
15025=end original
15026
15027The function C<require()> is difficult to wrap properly. Many modules
15028consult the stack to find information about their caller, and injecting
15029a new stack frame by wrapping C<require()> often breaks things.
15030Nevertheless it can be very helpful to have the ability to perform
15031actions before and after a C<require>, for instance for trace utilities
15032like C<Devel::TraceUse> or to measure time to load and the memory
15033consumption of the require graph. Because of the difficulties in safely
15034creating a C<require()> wrapper in 5.37.10 we introduced a new mechanism.
15035(TBT)
15036
15037=begin original
15038
15039As of 5.37.10, prior to any other actions it performs, C<require> will
15040check if C<${^HOOK}{require__before}> contains a coderef, and if it does
15041it will be called with the filename form of the item being loaded. The hook
15042may modify C<$_[0]> to load a different filename, or it may throw a fatal
15043exception to cause the require to fail, which will be treated as though the
15044required code itself had thrown an exception.
15045
15046=end original
15047
15048As of 5.37.10, prior to any other actions it performs, C<require> will
15049check if C<${^HOOK}{require__before}> contains a coderef, and if it does
15050it will be called with the filename form of the item being loaded. The hook
15051may modify C<$_[0]> to load a different filename, or it may throw a fatal
15052exception to cause the require to fail, which will be treated as though the
15053required code itself had thrown an exception.
15054(TBT)
15055
15056=begin original
15057
15058The C<${^HOOK}{require__before}> hook may return a code reference, in
15059which case the code reference will be executed (in an eval with the
15060filname as a parameter) after the require completes. It will be executed
15061regardless of how the compilation completed, and even if the require
15062throws a fatal exception. The function may consult C<%INC> to determine
15063if the require failed or not. For instance the following code will print
15064some diagnostics before and after every C<require> statement. The
15065example also includes logic to chain the signal, so that multiple
15066signals can cooperate. Well behaved C<${^HOOK}{require__before}>
15067handlers should always take this into account.
15068
15069=end original
15070
15071The C<${^HOOK}{require__before}> hook may return a code reference, in
15072which case the code reference will be executed (in an eval with the
15073filname as a parameter) after the require completes. It will be executed
15074regardless of how the compilation completed, and even if the require
15075throws a fatal exception. The function may consult C<%INC> to determine
15076if the require failed or not. For instance the following code will print
15077some diagnostics before and after every C<require> statement. The
15078example also includes logic to chain the signal, so that multiple
15079signals can cooperate. Well behaved C<${^HOOK}{require__before}>
15080handlers should always take this into account.
15081(TBT)
15082
15083 {
15084 use Scalar::Util qw(reftype);
15085 my $old_hook = ${^HOOK}{require__before};
15086 local ${^HOOK}{require__before} = sub {
15087 my ($name) = @_;
15088 my $old_hook_ret;
15089 $old_hook_ret = $old_hook->($name) if $old_hook;
15090 warn "Requiring: $name\n";
15091 return sub {
15092 $old_hook_ret->() if ref($old_hook_ret)
15093 && reftype($old_hook_ret) eq "CODE";
15094 warn sprintf "Finished requiring %s: %s\n",
15095 $name, $INC{$name} ? "loaded" :"failed";
15096 };
15097 };
15098 require Whatever;
15099 }
15100
15101=begin original
15102
15103This hook executes for ALL C<require> statements, unlike C<INC> and
15104C<INCDIR> hooks, which are only executed for relative file names, and it
15105executes first before any other special behaviour inside of require.
15106Note that the initial hook in C<${^HOOK}{require__before}> is *not*
15107executed inside of an eval, and throwing an exception will stop further
15108processing, but the after hook it may return is executed inside of an
15109eval, and any exceptions it throws will be silently ignored. This is
15110because it executes inside of the scope cleanup logic that is triggered
15111after the require completes, and an exception at this time would not
15112stop the module from being loaded, etc.
15113
15114=end original
15115
15116This hook executes for ALL C<require> statements, unlike C<INC> and
15117C<INCDIR> hooks, which are only executed for relative file names, and it
15118executes first before any other special behaviour inside of require.
15119Note that the initial hook in C<${^HOOK}{require__before}> is *not*
15120executed inside of an eval, and throwing an exception will stop further
15121processing, but the after hook it may return is executed inside of an
15122eval, and any exceptions it throws will be silently ignored. This is
15123because it executes inside of the scope cleanup logic that is triggered
15124after the require completes, and an exception at this time would not
15125stop the module from being loaded, etc.
15126(TBT)
15127
15128=begin original
15129
15130There is a similar hook that fires after require completes,
15131C<${^HOOK}{require__after}>, which will be called after each require statement
15132completes, either via an exception or successfully. It will be called with
15133the filename of the most recently executed require statement. It is executed
15134in an eval, and will not in any way affect execution.
15135
15136=end original
15137
15138There is a similar hook that fires after require completes,
15139C<${^HOOK}{require__after}>, which will be called after each require statement
15140completes, either via an exception or successfully. It will be called with
15141the filename of the most recently executed require statement. It is executed
15142in an eval, and will not in any way affect execution.
15143(TBT)
15144
15145=begin original
15146
15147For a yet-more-powerful import facility built around C<require>, see
15148L<C<use>|/use Module VERSION LIST> and L<perlmod>.
15149
15150=end original
15151
15152C<require> 関連で構築されている、より強力な import 機能については、
15153この文書の L<C<use>|/use Module VERSION LIST> の項と、
15154L<perlmod> を参照してください。
15155
1275315156=item reset EXPR
1275415157X<reset>
1275515158
1275615159=item reset
1275715160
1275815161=for Pod::Functions clear all variables of a given name
1275915162
1276015163=begin original
1276115164
12762Generally used in a C<continue> block at the end of a loop to clear
15165Generally used in a L<C<continue>|/continue BLOCK> block at the end of a
12763variables and reset C<??> searches so that they work again. The
15166loop to clear variables and reset C<m?pattern?> searches so that they
15167work again. The
1276415168expression is interpreted as a list of single characters (hyphens
12765allowed for ranges). All variables and arrays beginning with one of
15169allowed for ranges). All variables (scalars, arrays, and hashes)
15170in the current package beginning with one of
1276615171those letters are reset to their pristine state. If the expression is
12767omitted, one-match searches (C<?pattern?>) are reset to match again.
15172omitted, one-match searches (C<m?pattern?>) are reset to match again.
1276815173Only resets variables or searches in the current package. Always returns
12769151741. Examples:
1277015175
1277115176=end original
1277215177
12773通常、ループの最後に、変数をクリアし、C<??> 検索を再び
15178通常、ループの最後に、変数をクリアし、C<m?pattern?> 検索を再び動作するように
12774動作するようにリセットするため、C<continue> ブロックで使われます。
15179リセットするため、L<C<continue>|/continue BLOCK> ブロックで使われます。
1277515180EXPR は、文字を並べたもの (範囲を指定するのに、ハイフンが使えます) と
1277615181解釈されます。
12777名前がその文字のいずれかで始まる変数や配列は、
15182名前がその文字のいずれかで始まる、現在のパッケージの全ての変数
15183(スカラ、配列、ハッシュ)は、
1277815184最初の状態にリセットされます。
12779EXPR を省略すると、1 回検索 (C<?PATTERN?>) を再びマッチするように
15185EXPR を省略すると、1 回検索 (C<m?pattern?>) を再びマッチするように
1278015186リセットできます。
1278115187カレントパッケージの変数もしくは検索だけがリセットされます。
1278215188常に 1 を返します。
1278315189例:
1278415190
1278515191 reset 'X'; # reset all X variables
1278615192 reset 'a-z'; # reset lower case variables
12787 reset; # just reset ?one-time? searches
15193 reset; # just reset m?one-time? searches
1278815194
1278915195=begin original
1279015196
1279115197Resetting C<"A-Z"> is not recommended because you'll wipe out your
12792C<@ARGV> and C<@INC> arrays and your C<%ENV> hash. Resets only package
15198L<C<@ARGV>|perlvar/@ARGV> and L<C<@INC>|perlvar/@INC> arrays and your
12793variables; lexical variables are unaffected, but they clean themselves
15199L<C<%ENV>|perlvar/%ENV> hash.
12794up on scope exit anyway, so you'll probably want to use them instead.
12795See L</my>.
1279615200
1279715201=end original
1279815202
12799reset C<"A-Z"> とすると、C<@ARGV>, C<@INC> 配列や C<%ENV> ハッシュも
15203reset C<"A-Z"> とすると、L<C<@ARGV>|perlvar/@ARGV>,
12800なくなってしまいますから、止めた方が良いでしょう。
15204L<C<@INC>|perlvar/@INC> 配列や L<C<%ENV>|perlvar/%ENV> ハッシュも
12801パッケージ変数だけがリセットされす;
15205なくなってしうので、止めた方が良いでしょう。
12802レキシカル変数は、影響を受けませんが、スコープから外れれば、
12803自動的に綺麗になりますので、これからは、こちらを使うようにした方が
12804よいでしょう。
12805L</my> を参照してください。
1280615206
15207=begin original
15208
15209Resets only package variables; lexical variables are unaffected, but
15210they clean themselves up on scope exit anyway, so you'll probably want
15211to use them instead. See L<C<my>|/my VARLIST>.
15212
15213=end original
15214
15215パッケージ変数だけがリセットされます; レキシカル変数は影響を受けませんが、
15216スコープから外れれば自動的に綺麗になるので、これからはこちらを
15217使うようにした方がよいでしょう。
15218L<C<my>|/my VARLIST> を参照してください。
15219
1280715220=item return EXPR
1280815221X<return>
1280915222
1281015223=item return
1281115224
1281215225=for Pod::Functions get out of a function early
1281315226
1281415227=begin original
1281515228
12816Returns from a subroutine, C<eval>, or C<do FILE> with the value
15229Returns from a subroutine, L<C<eval>|/eval EXPR>,
15230L<C<do FILE>|/do EXPR>, L<C<sort>|/sort SUBNAME LIST> block or regex
15231eval block (but not a L<C<grep>|/grep BLOCK LIST>,
15232L<C<map>|/map BLOCK LIST>, or L<C<do BLOCK>|/do BLOCK> block) with the value
1281715233given in EXPR. Evaluation of EXPR may be in list, scalar, or void
1281815234context, depending on how the return value will be used, and the context
12819may vary from one execution to the next (see L</wantarray>). If no EXPR
15235may vary from one execution to the next (see
15236L<C<wantarray>|/wantarray>). If no EXPR
1282015237is given, returns an empty list in list context, the undefined value in
1282115238scalar context, and (of course) nothing at all in void context.
1282215239
1282315240=end original
1282415241
12825サブルーチン, C<eval>, C<do FILE> から EXPR で与えられた値をもって、
15242サブルーチン, L<C<eval>|/eval EXPR>, L<C<do FILE>|/do EXPR>,
12826リターンしす。
15243L<C<sort>|/sort SUBNAME LIST> ブロックたは正規表現 eval ブロック
15244(但し L<C<grep>|/grep BLOCK LIST>,
15245L<C<map>|/map BLOCK LIST>, L<C<do BLOCK>|/do BLOCK> ブロックではない) から
15246EXPR で与えられた値をもって、リターンします。
1282715247EXPR の評価は、返り値がどのように使われるかによってリスト、スカラ、
1282815248無効コンテキストになります; またコンテキストは実行毎に変わります
12829(C<wantarray> を参照してください)。
15249(L<C<wantarray>|/wantarray> を参照してください)。
1283015250EXPR が指定されなかった場合は、リストコンテキストでは空リストを、
1283115251スカラコンテキストでは未定義値を返します; そして(もちろん)
1283215252無効コンテキストでは何も返しません。
1283315253
1283415254=begin original
1283515255
12836(In the absence of an explicit C<return>, a subroutine, eval,
15256(In the absence of an explicit L<C<return>|/return EXPR>, a subroutine,
12837or do FILE automatically returns the value of the last expression
15257L<C<eval>|/eval EXPR>,
15258or L<C<do FILE>|/do EXPR> automatically returns the value of the last expression
1283815259evaluated.)
1283915260
1284015261=end original
1284115262
12842(サブルーチン, eval, do FILE に明示的に C<return> が
15263(サブルーチン, L<C<eval>|/eval EXPR>, L<C<do FILE>|/do EXPR> に明示的に
12843なければ、最後に評価された値で、自動的にリターンします。)
15264L<C<return>|/return EXPR> がなければ、最後に評価された値で、
15265自動的にリターンします。)
1284415266
1284515267=begin original
1284615268
1284715269Unlike most named operators, this is also exempt from the
1284815270looks-like-a-function rule, so C<return ("foo")."bar"> will
12849cause "bar" to be part of the argument to C<return>.
15271cause C<"bar"> to be part of the argument to L<C<return>|/return EXPR>.
1285015272
1285115273=end original
1285215274
1285315275ほとんどの名前付き演算子と異なり、関数のように見えるものの規則からも
12854免れるので、C<return ("foo")."bar"> とすると "bar" は C<return> への引数の
15276免れるので、C<return ("foo")."bar"> とすると C<"bar">
12855一部となります。
15277L<C<return>|/return EXPR> への引数の一部となります。
1285615278
1285715279=item reverse LIST
1285815280X<reverse> X<rev> X<invert>
1285915281
1286015282=for Pod::Functions flip a string or a list
1286115283
1286215284=begin original
1286315285
1286415286In list context, returns a list value consisting of the elements
1286515287of LIST in the opposite order. In scalar context, concatenates the
1286615288elements of LIST and returns a string value with all characters
1286715289in the opposite order.
1286815290
1286915291=end original
1287015292
1287115293リストコンテキストでは、LIST を構成する要素を逆順に並べた
1287215294リスト値を返します。
1287315295スカラコンテキストでは、LIST の要素を連結して、
1287415296全ての文字を逆順にした文字列を返します。
1287515297
1287615298 print join(", ", reverse "world", "Hello"); # Hello, world
1287715299
1287815300 print scalar reverse "dlrow ,", "olleH"; # Hello, world
1287915301
1288015302=begin original
1288115303
12882Used without arguments in scalar context, reverse() reverses C<$_>.
15304Used without arguments in scalar context, L<C<reverse>|/reverse LIST>
15305reverses L<C<$_>|perlvar/$_>.
1288315306
1288415307=end original
1288515308
12886スカラコンテキストで引数なしで使うと、reverse() は C<$_> を逆順にします。
15309スカラコンテキストで引数なしで使うと、L<C<reverse>|/reverse LIST>
15310L<C<$_>|perlvar/$_> を逆順にします。
1288715311
1288815312 $_ = "dlrow ,olleH";
1288915313 print reverse; # No output, list context
1289015314 print scalar reverse; # Hello, world
1289115315
1289215316=begin original
1289315317
1289415318Note that reversing an array to itself (as in C<@a = reverse @a>) will
1289515319preserve non-existent elements whenever possible; i.e., for non-magical
1289615320arrays or for tied arrays with C<EXISTS> and C<DELETE> methods.
1289715321
1289815322=end original
1289915323
1290015324(C<@a = reverse @a> のように) 反転した配列を自分自身に代入すると、
1290115325存在しない要素は可能なら(つまりマジカルでない配列や
1290215326C<EXISTS> と C<DELETE> メソッドがある tie された配列)
1290315327いつでも保存されることに注意してください。
1290415328
1290515329=begin original
1290615330
1290715331This operator is also handy for inverting a hash, although there are some
1290815332caveats. If a value is duplicated in the original hash, only one of those
1290915333can be represented as a key in the inverted hash. Also, this has to
1291015334unwind one hash and build a whole new one, which may take some time
1291115335on a large hash, such as from a DBM file.
1291215336
1291315337=end original
1291415338
1291515339この演算子はハッシュの逆順にするのにも便利ですが、いくつかの弱点があります。
1291615340元のハッシュで値が重複していると、それらのうち一つだけが
1291715341逆順になったハッシュのキーとして表現されます。
1291815342また、これは一つのハッシュをほどいて完全に新しいハッシュを作るので、
1291915343DBM ファイルからのような大きなハッシュでは少し時間がかかります。
1292015344
12921 %by_name = reverse %by_address; # Invert the hash
15345 my %by_name = reverse %by_address; # Invert the hash
1292215346
1292315347=item rewinddir DIRHANDLE
1292415348X<rewinddir>
1292515349
1292615350=for Pod::Functions reset directory handle
1292715351
1292815352=begin original
1292915353
1293015354Sets the current position to the beginning of the directory for the
12931C<readdir> routine on DIRHANDLE.
15355L<C<readdir>|/readdir DIRHANDLE> routine on DIRHANDLE.
1293215356
1293315357=end original
1293415358
12935DIRHANDLE に対する C<readdir> ルーチンの現在位置を
15359DIRHANDLE に対する L<C<readdir>|/readdir DIRHANDLE> ルーチンの現在位置を
1293615360ディレクトリの最初に設定します。
1293715361
1293815362=begin original
1293915363
1294015364Portability issues: L<perlport/rewinddir>.
1294115365
1294215366=end original
1294315367
1294415368移植性の問題: L<perlport/rewinddir>。
1294515369
1294615370=item rindex STR,SUBSTR,POSITION
1294715371X<rindex>
1294815372
1294915373=item rindex STR,SUBSTR
1295015374
1295115375=for Pod::Functions right-to-left substring search
1295215376
1295315377=begin original
1295415378
12955Works just like index() except that it returns the position of the I<last>
15379Works just like L<C<index>|/index STR,SUBSTR,POSITION> except that it
15380returns the position of the I<last>
1295615381occurrence of SUBSTR in STR. If POSITION is specified, returns the
1295715382last occurrence beginning at or before that position.
1295815383
1295915384=end original
1296015385
1296115386STR 中で I<最後に> 見つかった SUBSTR の位置を返すことを除いて、
12962index() と同じように動作します。
15387L<C<index>|/index STR,SUBSTR,POSITION> と同じように動作します。
1296315388POSITION を指定すると、その位置から始まるか、その位置より前の、
1296415389最後の位置を返します。
1296515390
1296615391=item rmdir FILENAME
1296715392X<rmdir> X<rd> X<directory, remove>
1296815393
1296915394=item rmdir
1297015395
1297115396=for Pod::Functions remove a directory
1297215397
1297315398=begin original
1297415399
1297515400Deletes the directory specified by FILENAME if that directory is
1297615401empty. If it succeeds it returns true; otherwise it returns false and
12977sets C<$!> (errno). If FILENAME is omitted, uses C<$_>.
15402sets L<C<$!>|perlvar/$!> (errno). If FILENAME is omitted, uses
15403L<C<$_>|perlvar/$_>.
1297815404
1297915405=end original
1298015406
1298115407FILENAME で指定したディレクトリが空であれば、
1298215408そのディレクトリを削除します。
12983成功時には真を返します; さもなければ偽を返して C<$!> (errno) を設定します。
15409成功時には真を返します; さもなければ偽を返して L<C<$!>|perlvar/$!>
12984FILENAME省略した場合には、C<$_> を使用します。
15410(errno)設定します。
15411FILENAME を省略した場合には、L<C<$_>|perlvar/$_> を使用します。
1298515412
1298615413=begin original
1298715414
1298815415To remove a directory tree recursively (C<rm -rf> on Unix) look at
12989the C<rmtree> function of the L<File::Path> module.
15416the L<C<rmtree>|File::Path/rmtree( $dir )> function of the L<File::Path>
15417module.
1299015418
1299115419=end original
1299215420
1299315421ディレクトリツリーを再帰的に削除したい (Unix での C<rm -rf>) 場合、
12994L<File::Path> モジュールの C<rmtree> 関数を参照してください。
15422L<File::Path> モジュールの L<C<rmtree>|File::Path/rmtree( $dir )> 関数を
15423参照してください。
1299515424
1299615425=item s///
1299715426
1299815427=for Pod::Functions replace a pattern with a string
1299915428
1300015429=begin original
1300115430
1300215431The substitution operator. See L<perlop/"Regexp Quote-Like Operators">.
1300315432
1300415433=end original
1300515434
1300615435置換演算子。
1300715436L<perlop/"Regexp Quote-Like Operators"> を参照してください。
1300815437
1300915438=item say FILEHANDLE LIST
1301015439X<say>
1301115440
1301215441=item say FILEHANDLE
1301315442
1301415443=item say LIST
1301515444
1301615445=item say
1301715446
1301815447=for Pod::Functions +say output a list to a filehandle, appending a newline
1301915448
1302015449=begin original
1302115450
13022Just like C<print>, but implicitly appends a newline. C<say LIST> is
15451Just like L<C<print>|/print FILEHANDLE LIST>, but implicitly appends a
13023simply an abbreviation for C<{ local $\ = "\n"; print LIST }>. To use
15452newline at the end of the LIST instead of any value L<C<$\>|perlvar/$\>
13024FILEHANDLE without a LIST to print the contents of C<$_> to it, you must
15453might have. To use FILEHANDLE without a LIST to
13025use a real filehandle like C<FH>, not an indirect one like C<$fh>.
15454print the contents of L<C<$_>|perlvar/$_> to it, you must use a bareword
15455filehandle like C<FH>, not an indirect one like C<$fh>.
1302615456
1302715457=end original
1302815458
13029C<print> と同様ですが、暗黙に改行が追加されます。
15459L<C<print>|/print FILEHANDLE LIST> と同様ですが、
13030C<say LIST> は単に C<{ local $\ = "\n"; print LIST }> 省略形です。
15460L<C<$\>|perlvar/$\> の値の代わりに LIST の末尾に
13031C<$_> の内容を表示するため LIST なしで FILEHANDLE を使用るには、
15461改行が暗黙追加されま
13032C<$fh> のよう間接ファイルハンドルはなく、C<FH> のような実際の
15462L<C<$_>|perlvar/$_>内容を表示するために LIST FILEHANDLE
13033ファイルハンドルを使わければりません。
15463使用するには、C<$fh> のような間接ファイルハンドルではく、C<FH> のよう
15464裸の単語のファイルハンドルを使わなければなりません。
1303415465
1303515466=begin original
1303615467
13037This keyword is available only when the C<"say"> feature
15468L<C<say>|/say FILEHANDLE LIST> is available only if the
13038is enabled, or when prefixed with C<CORE::>; see
15469L<C<"say"> feature|feature/The 'say' feature> is enabled or if it is
13039L<feature>. Alternately, include a C<use v5.10> or later to the current
15470prefixed with C<CORE::>. The
13040scope.
15471L<C<"say"> feature|feature/The 'say' feature> is enabled automatically
15472with a C<use v5.10> (or higher) declaration in the current scope.
1304115473
1304215474=end original
1304315475
13044このキーワードは、C<"say"> 機能が有効か、C<CORE::> が前置された場合にのみ
15476L<C<say>|/say FILEHANDLE LIST>
13045利用可能です; L<feature> を参照してください。
15477L<C<"say"> 機能|feature/The 'say' feature> が有効か C<CORE::> が
13046は、現在のスコープ C<use v5.10> 以降を含めてください
15478前置されときのみ利用可能です
15479L<C<"say"> 機能|feature/The 'say' feature> は現在のスコープで
15480C<use v5.10> (またはそれ以上) が宣言されると自動的に有効になります。
1304715481
1304815482=item scalar EXPR
1304915483X<scalar> X<context>
1305015484
1305115485=for Pod::Functions force a scalar context
1305215486
1305315487=begin original
1305415488
1305515489Forces EXPR to be interpreted in scalar context and returns the value
1305615490of EXPR.
1305715491
1305815492=end original
1305915493
1306015494EXPR を強制的にスカラコンテキストで解釈されるようにして、
1306115495EXPR の値を返します。
1306215496
13063 @counts = ( scalar @a, scalar @b, scalar @c );
15497 my @counts = ( scalar @a, scalar @b, scalar @c );
1306415498
1306515499=begin original
1306615500
1306715501There is no equivalent operator to force an expression to
1306815502be interpolated in list context because in practice, this is never
1306915503needed. If you really wanted to do so, however, you could use
1307015504the construction C<@{[ (some expression) ]}>, but usually a simple
1307115505C<(some expression)> suffices.
1307215506
1307315507=end original
1307415508
1307515509式を強制的にリストコンテキストで解釈させるようにする演算子はありません;
1307615510理論的には不要だからです。
1307715511それでも、もしそうしたいのなら、C<@{[ (some expression) ]}> という構造を
1307815512使えます; しかし、普通は単に C<(some expression)> とすれば十分です。
1307915513
1308015514=begin original
1308115515
13082Because C<scalar> is a unary operator, if you accidentally use a
15516Because L<C<scalar>|/scalar EXPR> is a unary operator, if you
15517accidentally use a
1308315518parenthesized list for the EXPR, this behaves as a scalar comma expression,
1308415519evaluating all but the last element in void context and returning the final
1308515520element evaluated in scalar context. This is seldom what you want.
1308615521
1308715522=end original
1308815523
13089C<scalar> は単項演算子なので、EXPR として括弧でくくったリストを使った場合、
15524L<C<scalar>|/scalar EXPR> は単項演算子なので、EXPR として括弧でくくった
13090これはスカラカンマ表現として振舞い、最後以外の全ては無効コンテキストとして
15525リストを使った場合、これはスカラカンマ表現として振舞い、最後以外の全ては
13091扱われ、最後の要素をスカラコンテキストとして扱った結果が返されます。
15526無効コンテキストとして扱われ、最後の要素をスカラコンテキストとして扱った
15527結果が返されます。
1309215528これがあなたの望むものであることはめったにないでしょう。
1309315529
1309415530=begin original
1309515531
1309615532The following single statement:
1309715533
1309815534=end original
1309915535
1310015536以下の一つの文は:
1310115537
13102 print uc(scalar(&foo,$bar)),$baz;
15538 print uc(scalar(foo(), $bar)), $baz;
1310315539
1310415540=begin original
1310515541
1310615542is the moral equivalent of these two:
1310715543
1310815544=end original
1310915545
1311015546以下の二つの文と等価です。
1311115547
13112 &foo;
15548 foo();
13113 print(uc($bar),$baz);
15549 print(uc($bar), $baz);
1311415550
1311515551=begin original
1311615552
13117See L<perlop> for more details on unary operators and the comma operator.
15553See L<perlop> for more details on unary operators and the comma operator,
15554and L<perldata> for details on evaluating a hash in scalar context.
1311815555
1311915556=end original
1312015557
13121単項演算子とカンマ演算子に関する詳細については L<perlop> を参照してください。
15558単項演算子とカンマ演算子に関する詳細については L<perlop> を
15559スカラコンテキストでのハッシュの評価に関する詳細については L<perldata> を
15560参照してください。
1312215561
1312315562=item seek FILEHANDLE,POSITION,WHENCE
1312415563X<seek> X<fseek> X<filehandle, position>
1312515564
1312615565=for Pod::Functions reposition file pointer for random-access I/O
1312715566
1312815567=begin original
1312915568
13130Sets FILEHANDLE's position, just like the C<fseek> call of C<stdio>.
15569Sets FILEHANDLE's position, just like the L<fseek(3)> call of C C<stdio>.
1313115570FILEHANDLE may be an expression whose value gives the name of the
1313215571filehandle. The values for WHENCE are C<0> to set the new position
1313315572I<in bytes> to POSITION; C<1> to set it to the current position plus
1313415573POSITION; and C<2> to set it to EOF plus POSITION, typically
1313515574negative. For WHENCE you may use the constants C<SEEK_SET>,
1313615575C<SEEK_CUR>, and C<SEEK_END> (start of the file, current position, end
1313715576of the file) from the L<Fcntl> module. Returns C<1> on success, false
1313815577otherwise.
1313915578
1314015579=end original
1314115580
13142C<stdio> ライブラリの C<fseek> 関数のように、FILEHANDLE の
15581C の C<stdio> ライブラリの L<fseek(3)> 関数のように、FILEHANDLE の
1314315582ファイルポインタを任意の位置に設定します。
1314415583FILEHANDLE は、実際のファイルハンドル名を与える式でもかまいません。
1314515584WHENCE の値が、C<0> ならば、新しい位置を I<バイト単位で> POSITION の位置へ
13146設定します; C<1> ならば、現在位置から I<バイト数で> POSITION 加えた位置へ
15585設定します; C<1> ならば、現在位置から POSITION 加えた位置へ
1314715586設定します; C<2> ならば、EOF からPOSITION だけ加えた位置へ、新しい位置を
1314815587設定します。
1314915588この値には、L<Fcntl> モジュールで使われている C<SEEK_SET>、C<SEEK_CUR>、
1315015589C<SEEK_END> (ファイルの先頭、現在位置、ファイルの最後)という定数を
1315115590使うこともできます。
13152成功時には、C<1> を、失敗時には C<0> を返します。
15591成功時には、C<1> を、失敗時にはそれ以外を返します。
1315315592
1315415593=begin original
1315515594
13156Note the I<in bytes>: even if the filehandle has been set to
15595Note the emphasis on bytes: even if the filehandle has been set to operate
13157operate on characters (for example by using the C<:encoding(utf8)> open
15596on characters (for example using the C<:encoding(UTF-8)> I/O layer), the
13158layer), tell() will return byte offsets, not character offsets
15597L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
13159(because implementing that would render seek() and tell() rather slow).
15598L<C<tell>|/tell FILEHANDLE>, and
15599L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>
15600family of functions use byte offsets, not character offsets,
15601because seeking to a character offset would be very slow in a UTF-8 file.
1316015602
1316115603=end original
1316215604
13163I<バイト単位> する注意: ファイルハンドルが (例えば C<:encoding(utf8)> 層を
15605バイト単位にする注意: 例え(例えば C<:encoding(UTF-8)> I/O 層を使うなどして)
13164使って)文字を操作するように設定されていたとしても、tell() は文字の
15606ファイルハンドルが文字単位で処理するように設定されていたとしても、
13165オフセットではなくバイトのオフセットを返すことに注意してください
15607L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
13166(なぜならこれを実装すると seek() と tell() が遅くなってしまうからです)。
15608L<C<tell>|/tell FILEHANDLE>,
15609L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> シリーズの関数は
15610文字オフセットではなくバイトオフセットを使います;
15611文字オフセットでシークするのは UTF-8 ファイルではとても遅いからです。
1316715612
1316815613=begin original
1316915614
13170If you want to position the file for C<sysread> or C<syswrite>, don't use
15615If you want to position the file for
13171C<seek>, because buffering makes its effect on the file's read-write position
15616L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> or
13172unpredictable and non-portable. Use C<sysseek> instead.
15617L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, don't use
15618L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, because buffering makes its
15619effect on the file's read-write position unpredictable and non-portable.
15620Use L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> instead.
1317315621
1317415622=end original
1317515623
13176C<sysread> や C<syswrite> のためにファイルの位置を指定したい場合は、
15624L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>
13177C<seek> は使えません; なぜならバッファリングのためにファイルの読み込み位置は
15625L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> のためにファイルの
15626位置を指定したい場合は、L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> は
15627使えません; なぜならバッファリングのためにファイルの読み込み位置は
1317815628動作は予測不能で移植性のないものになってしまいます。
13179代わりに C<sysseek> を使ってください。
15629代わりに L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> を使ってください。
1318015630
1318115631=begin original
1318215632
1318315633Due to the rules and rigors of ANSI C, on some systems you have to do a
1318415634seek whenever you switch between reading and writing. Amongst other
13185things, this may have the effect of calling stdio's clearerr(3).
15635things, this may have the effect of calling stdio's L<clearerr(3)>.
1318615636A WHENCE of C<1> (C<SEEK_CUR>) is useful for not moving the file position:
1318715637
1318815638=end original
1318915639
1319015640ANSI C の規則と困難により、システムによっては読み込みと書き込みを
1319115641切り替える度にシークしなければならない場合があります。
13192その他のことの中で、これは stdio の clearerr(3) を呼び出す効果があります。
15642その他のことの中で、これは stdio の L<clearerr(3)> を呼び出す効果があります。
1319315643WHENCE の C<1> (C<SEEK_CUR>) が、ファイル位置を変えないので有用です:
1319415644
13195 seek(TEST,0,1);
15645 seek($fh, 0, 1);
1319615646
1319715647=begin original
1319815648
1319915649This is also useful for applications emulating C<tail -f>. Once you hit
1320015650EOF on your read and then sleep for a while, you (probably) have to stick in a
13201dummy seek() to reset things. The C<seek> doesn't change the position,
15651dummy L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> to reset things. The
15652L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> doesn't change the position,
1320215653but it I<does> clear the end-of-file condition on the handle, so that the
13203next C<< <FILE> >> makes Perl try again to read something. (We hope.)
15654next C<readline FILE> makes Perl try again to read something. (We hope.)
1320415655
1320515656=end original
1320615657
1320715658これはアプリケーションで C<tail -f> をエミュレートするのにも有用です。
1320815659一度読み込み時に EOF に到達すると、しばらくスリープし、
13209(おそらく) ダミーの seek() をすることでリセットする必要があります。
15660(おそらく) ダミーの L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> をすることで
13210C<seek> は現在の位置を変更しません、ハンドルの EOF 状態を
15661リセットする必要あります。
13211I<クリアします> ので、次の C<< <FILE> >> で Perl 再び何か
15662L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> は現在の位置変更しませんが、
13212読み込もうとします。(そはずす。)
15663ハンドルの EOF 状態をI<クリアします> ので、次の C<readline FILE> で Perl は
15664再び何かを読み込もうとします。(そのはずです。)
1321315665
1321415666=begin original
1321515667
1321615668If that doesn't work (some I/O implementations are particularly
1321715669cantankerous), you might need something like this:
1321815670
1321915671=end original
1322015672
1322115673これが動かない場合(特に意地の悪い I/O 実装もあります)、
1322215674以下のようなことをする必要があります:
1322315675
1322415676 for (;;) {
13225 for ($curpos = tell(FILE); $_ = <FILE>;
15677 for ($curpos = tell($fh); $_ = readline($fh);
13226 $curpos = tell(FILE)) {
15678 $curpos = tell($fh)) {
1322715679 # search for some stuff and put it into files
1322815680 }
1322915681 sleep($for_a_while);
13230 seek(FILE, $curpos, 0);
15682 seek($fh, $curpos, 0);
1323115683 }
1323215684
1323315685=item seekdir DIRHANDLE,POS
1323415686X<seekdir>
1323515687
1323615688=for Pod::Functions reposition directory pointer
1323715689
1323815690=begin original
1323915691
13240Sets the current position for the C<readdir> routine on DIRHANDLE. POS
15692Sets the current position for the L<C<readdir>|/readdir DIRHANDLE>
13241must be a value returned by C<telldir>. C<seekdir> also has the same caveats
15693routine on DIRHANDLE. POS must be a value returned by
13242about possible directory compaction as the corresponding system library
15694L<C<telldir>|/telldir DIRHANDLE>. L<C<seekdir>|/seekdir DIRHANDLE,POS>
13243routine.
15695also has the same caveats about possible directory compaction as the
15696corresponding system library routine.
1324415697
1324515698=end original
1324615699
13247DIRHANDLE での C<readdir> ルーチンの現在位置を設定します。
15700DIRHANDLE での L<C<readdir>|/readdir DIRHANDLE> ルーチンの現在位置を
13248POS は、C<telldir> が返す値でなければなりせん
15701設定し
13249C<seekdir> は同名のシステムライブラリルーチンと同じく、
15702POS は、L<C<telldir>|/telldir DIRHANDLE> が返す値でなければなりません。
13250ディレクトリ縮小時問題が考えられます。
15703L<C<seekdir>|/seekdir DIRHANDLE,POS> は同名システムライブラリルーチンと
15704同じく、ディレクトリ縮小時の問題が考えられます。
1325115705
1325215706=item select FILEHANDLE
1325315707X<select> X<filehandle, default>
1325415708
1325515709=item select
1325615710
1325715711=for Pod::Functions reset default output or do I/O multiplexing
1325815712
1325915713=begin original
1326015714
1326115715Returns the currently selected filehandle. If FILEHANDLE is supplied,
1326215716sets the new current default filehandle for output. This has two
13263effects: first, a C<write> or a C<print> without a filehandle
15717effects: first, a L<C<write>|/write FILEHANDLE>, L<C<print>|/print
13264default to this FILEHANDLE. Second, references to variables related to
15718FILEHANDLE LIST>, or L<C<say>|/say FILEHANDLE LIST> without a
13265output will refer to this output channel.
15719filehandle default to this FILEHANDLE. Second, references to variables
15720related to output will refer to this output channel.
1326615721
1326715722=end original
1326815723
1326915724その時点で、選択されていたファイルハンドルを返します。
1327015725FILEHANDLE を指定した場合には、その値を出力のデフォルトファイルハンドルに
1327115726設定します。
1327215727これには、2 つの効果があります: まず、ファイルハンドルを指定しないで
13273C<write> C<print> を行なった場合のデフォルトが、この FILEHANDLE
15728L<C<write>|/write FILEHANDLE>, L<C<print>|/print FILEHANDLE LIST>,
13274なります。
15729L<C<say>|/say FILEHANDLE LIST> を
15730行なった場合のデフォルトが、この FILEHANDLE になります。
1327515731もう一つは、出力関連の変数への参照は、この出力チャネルを
13276参照するようになります。
15732参照するようになります。
1327715733
1327815734=begin original
1327915735
1328015736For example, to set the top-of-form format for more than one
1328115737output channel, you might do the following:
1328215738
1328315739=end original
1328415740
1328515741例えば、複数の出力チャネルに対して、ページ先頭フォーマットを
1328615742設定するには:
1328715743
1328815744 select(REPORT1);
1328915745 $^ = 'report1_top';
1329015746 select(REPORT2);
1329115747 $^ = 'report2_top';
1329215748
1329315749=begin original
1329415750
1329515751FILEHANDLE may be an expression whose value gives the name of the
1329615752actual filehandle. Thus:
1329715753
1329815754=end original
1329915755
1330015756FILEHANDLE は、実際のファイルハンドル名を示す式でもかまいません。
1330115757つまり、以下のようなものです:
1330215758
13303 $oldfh = select(STDERR); $| = 1; select($oldfh);
15759 my $oldfh = select(STDERR); $| = 1; select($oldfh);
1330415760
1330515761=begin original
1330615762
1330715763Some programmers may prefer to think of filehandles as objects with
1330815764methods, preferring to write the last example as:
1330915765
1331015766=end original
1331115767
1331215768ファイルハンドルはメソッドを持ったオブジェクトであると考えることを好む
1331315769プログラマもいるかもしれません; そのような場合のための最後の例は
1331415770以下のようなものです:
1331515771
13316 use IO::Handle;
1331715772 STDERR->autoflush(1);
1331815773
1331915774=begin original
1332015775
15776(Prior to Perl version 5.14, you have to C<use IO::Handle;> explicitly
15777first.)
15778
15779=end original
15780
15781(Perl バージョン 5.14 以前では、まず明示的に C<use IO::Handle;> とする
15782必要があります。)
15783
15784=begin original
15785
15786Whilst you can use C<select> to temporarily "capture" the output of
15787C<print> like this:
15788
15789=end original
15790
15791Whilst you can use C<select> to temporarily "capture" the output of
15792C<print> like this:
15793(TBT)
15794
15795 {
15796 my $old_handle = select $new_handle;
15797
15798 # This goes to $new_handle:
15799 print "ok 1\n";
15800 ...
15801
15802 select $old_handle;
15803 }
15804
15805=begin original
15806
15807you might find it easier to localize the typeglob instead:
15808
15809=end original
15810
15811you might find it easier to localize the typeglob instead:
15812(TBT)
15813
15814 {
15815 local *STDOUT = $new_handle;
15816
15817 print "ok 1\n";
15818 ...
15819 }
15820
15821=begin original
15822
15823The two are not exactly equivalent, but the latter might be clearer and will
15824restore STDOUT if the wrapped code dies. The difference is that in the
15825former, the original STDOUT can still be accessed by explicitly using it in a
15826C<print> statement (as C<print STDOUT ...>), whereas in the latter the meaning
15827of the STDOUT handle itself has temporarily been changed.
15828
15829=end original
15830
15831The two are not exactly equivalent, but the latter might be clearer and will
15832restore STDOUT if the wrapped code dies. The difference is that in the
15833former, the original STDOUT can still be accessed by explicitly using it in a
15834C<print> statement (as C<print STDOUT ...>), whereas in the latter the meaning
15835of the STDOUT handle itself has temporarily been changed.
15836(TBT)
15837
15838=begin original
15839
1332115840Portability issues: L<perlport/select>.
1332215841
1332315842=end original
1332415843
1332515844移植性の問題: L<perlport/select>。
1332615845
1332715846=item select RBITS,WBITS,EBITS,TIMEOUT
1332815847X<select>
1332915848
1333015849=begin original
1333115850
13332This calls the select(2) syscall with the bit masks specified, which
15851This calls the L<select(2)> syscall with the bit masks specified, which
13333can be constructed using C<fileno> and C<vec>, along these lines:
15852can be constructed using L<C<fileno>|/fileno FILEHANDLE> and
15853L<C<vec>|/vec EXPR,OFFSET,BITS>, along these lines:
1333415854
1333515855=end original
1333615856
13337これは、select(2) システムコールを、指定したビットマスクで呼び出します;
15857これは、L<select(2)> システムコールを、指定したビットマスクで呼び出します;
13338ビットマスクは、C<fileno> と C<vec> を使って、以下のようにして
15858ビットマスクは、L<C<fileno>|/fileno FILEHANDLE>
13339作成できます:
15859L<C<vec>|/vec EXPR,OFFSET,BITS> を使って、以下のようにして作成できます:
1334015860
13341 $rin = $win = $ein = '';
15861 my $rin = my $win = my $ein = '';
1334215862 vec($rin, fileno(STDIN), 1) = 1;
1334315863 vec($win, fileno(STDOUT), 1) = 1;
1334415864 $ein = $rin | $win;
1334515865
1334615866=begin original
1334715867
1334815868If you want to select on many filehandles, you may wish to write a
1334915869subroutine like this:
1335015870
1335115871=end original
1335215872
1335315873複数のファイルハンドルに select を行ないたいのであれば、
1335415874以下のようにします:
1335515875
1335615876 sub fhbits {
1335715877 my @fhlist = @_;
1335815878 my $bits = "";
1335915879 for my $fh (@fhlist) {
1336015880 vec($bits, fileno($fh), 1) = 1;
1336115881 }
1336215882 return $bits;
1336315883 }
13364 $rin = fhbits(*STDIN, *TTY, *MYSOCK);
15884 my $rin = fhbits(\*STDIN, $tty, $mysock);
1336515885
1336615886=begin original
1336715887
1336815888The usual idiom is:
1336915889
1337015890=end original
1337115891
1337215892通常は、
1337315893
13374 ($nfound,$timeleft) =
15894 my ($nfound, $timeleft) =
13375 select($rout=$rin, $wout=$win, $eout=$ein, $timeout);
15895 select(my $rout = $rin, my $wout = $win, my $eout = $ein,
15896 $timeout);
1337615897
1337715898=begin original
1337815899
1337915900or to block until something becomes ready just do this
1338015901
1338115902=end original
1338215903
1338315904のように使い、いずれかの準備が整うまでブロックするには、
1338415905以下のようにします。
1338515906
13386 $nfound = select($rout=$rin, $wout=$win, $eout=$ein, undef);
15907 my $nfound =
15908 select(my $rout = $rin, my $wout = $win, my $eout = $ein, undef);
1338715909
1338815910=begin original
1338915911
13390Most systems do not bother to return anything useful in $timeleft, so
15912Most systems do not bother to return anything useful in C<$timeleft>, so
13391calling select() in scalar context just returns $nfound.
15913calling L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> in scalar context
15914just returns C<$nfound>.
1339215915
1339315916=end original
1339415917
13395ほとんどのシステムではわざわざ意味のある値を $timeleft に返さないので、
15918ほとんどのシステムではわざわざ意味のある値を C<$timeleft> に返さないので、
13396select() をスカラコンテキストで呼び出すと、単に $nfound を返します。
15919L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> をスカラコンテキストで
15920呼び出すと、単に C<$nfound> を返します。
1339715921
1339815922=begin original
1339915923
13400Any of the bit masks can also be undef. The timeout, if specified, is
15924Any of the bit masks can also be L<C<undef>|/undef EXPR>. The timeout,
15925if specified, is
1340115926in seconds, which may be fractional. Note: not all implementations are
13402capable of returning the $timeleft. If not, they always return
15927capable of returning the C<$timeleft>. If not, they always return
13403$timeleft equal to the supplied $timeout.
15928C<$timeleft> equal to the supplied C<$timeout>.
1340415929
1340515930=end original
1340615931
13407どのビットマスクにも undef を設定することができます。
15932どのビットマスクにも L<C<undef>|/undef EXPR> を設定することができます。
1340815933TIMEOUT を指定するときは、秒数で指定し、小数でかまいません。
13409注: すべての実装で、$timeleft が返せるものではありません。
15934注: すべての実装で、C<$timeleft> が返せるものではありません。
13410その場合、$timeleft には、常に指定した TIMEOUT と同じ値が返されます。
15935その場合、C<$timeleft> には、常に指定した C<$timeout> と同じ値が返されます。
1341115936
1341215937=begin original
1341315938
1341415939You can effect a sleep of 250 milliseconds this way:
1341515940
1341615941=end original
1341715942
1341815943250 ミリ秒の sleep と同じ効果が、以下のようにして得られます。
1341915944
1342015945 select(undef, undef, undef, 0.25);
1342115946
1342215947=begin original
1342315948
13424Note that whether C<select> gets restarted after signals (say, SIGALRM)
15949Note that whether L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> gets
13425is implementation-dependent. See also L<perlport> for notes on the
15950restarted after signals (say, SIGALRM) is implementation-dependent. See
13426portability of C<select>.
15951also L<perlport> for notes on the portability of
15952L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>.
1342715953
1342815954=end original
1342915955
13430C<select> がシグナル (例えば、SIGALRM) の後に再起動するかどうかは
15956L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> がシグナル (例えば、SIGALRM) の
13431実装依存であることに注意してください。
15957後に再起動するかどうかは実装依存であることに注意してください。
13432C<select> の移植性に関する注意については L<perlport> も参照してください。
15958L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> の移植性に関する
15959注意については L<perlport> も参照してください。
1343315960
1343415961=begin original
1343515962
13436On error, C<select> behaves just like select(2): it returns
15963On error, L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> behaves just
13437-1 and sets C<$!>.
15964like L<select(2)>: it returns C<-1> and sets L<C<$!>|perlvar/$!>.
1343815965
1343915966=end original
1344015967
13441エラー時は、C<select>select(2) のように振舞います:
15968エラー時は、L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> は
13442-1 を返し、C<$!> をセットします
15969L<select(2)> のように振舞います:
15970C<-1> を返し、L<C<$!>|perlvar/$!> をセットします。
1344315971
1344415972=begin original
1344515973
13446On some Unixes, select(2) may report a socket file descriptor as "ready for
15974On some Unixes, L<select(2)> may report a socket file descriptor as
13447reading" even when no data is available, and thus any subsequent C<read>
15975"ready for reading" even when no data is available, and thus any
13448would block. This can be avoided if you always use O_NONBLOCK on the
15976subsequent L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> would block.
13449socket. See select(2) and fcntl(2) for further details.
15977This can be avoided if you always use C<O_NONBLOCK> on the socket. See
15978L<select(2)> and L<fcntl(2)> for further details.
1345015979
1345115980=end original
1345215981
13453Unix の中には、実際に利用可能なデータがないために引き続く C<read> が
15982Unix の中には、実際に利用可能なデータがないために引き続く
13454ブロックされる場合でも、select(2) が、ソケットファイル記述子
15983L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>
15984ブロックされる場合でも、L<select(2)> が、ソケットファイル記述子が
1345515985「読み込み準備中」であると報告するものもあります。
13456これは、ソケットに対して常に O_NONBLOCK フラグを使うことで回避できます。
15986これは、ソケットに対して常に C<O_NONBLOCK> フラグを使うことで回避できます。
13457さらなる詳細については select(2) と fcntl(2) を参照してください。
15987さらなる詳細については L<select(2)>L<fcntl(2)> を参照してください。
1345815988
1345915989=begin original
1346015990
13461The standard C<IO::Select> module provides a user-friendlier interface
15991The standard L<C<IO::Select>|IO::Select> module provides a
13462to C<select>, mostly because it does all the bit-mask work for you.
15992user-friendlier interface to
15993L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, mostly because it does
15994all the bit-mask work for you.
1346315995
1346415996=end original
1346515997
13466標準の C<IO::Select> モジュールは C<select> へのよりユザーフレンドリーな
15998標準の L<C<IO::Select>|IO::Select> モジュルは
15999L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> へのよりユーザーフレンドリーな
1346716000インターフェースを提供します; 主な理由はビットマスクの仕事を
1346816001してくれることです。
1346916002
1347016003=begin original
1347116004
13472B<WARNING>: One should not attempt to mix buffered I/O (like C<read>
16005B<WARNING>: One should not attempt to mix buffered I/O (like
13473or <FH>) with C<select>, except as permitted by POSIX, and even
16006L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> or
13474then only on POSIX systems. You have to use C<sysread> instead.
16007L<C<readline>|/readline EXPR>) with
16008L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, except as permitted by
16009POSIX, and even then only on POSIX systems. You have to use
16010L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> instead.
1347516011
1347616012=end original
1347716013
13478B<警告>: バッファ付き I/O (C<read> や <FH>) と C<select>
16014B<警告>: バッファ付き I/O (L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>
16015L<C<readline>|/readline EXPR>) と
16016L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を
1347916017混ぜて使ってはいけません(例外: POSIX で認められている形で使い、
1348016018POSIX システムでだけ動かす場合を除きます)。
13481代わりに C<sysread> を使わなければなりません。
16019代わりに L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>
16020使わなければなりません。
1348216021
1348316022=begin original
1348416023
1348516024Portability issues: L<perlport/select>.
1348616025
1348716026=end original
1348816027
1348916028移植性の問題: L<perlport/select>。
1349016029
1349116030=item semctl ID,SEMNUM,CMD,ARG
1349216031X<semctl>
1349316032
1349416033=for Pod::Functions SysV semaphore control operations
1349516034
1349616035=begin original
1349716036
13498Calls the System V IPC function semctl(2). You'll probably have to say
16037Calls the System V IPC function L<semctl(2)>. You'll probably have to say
1349916038
1350016039=end original
1350116040
13502System V IPC 関数 semctl(2) を呼び出します。
16041System V IPC 関数 L<semctl(2)> を呼び出します。
1350316042正しい定数定義を得るために、まず
1350416043
1350516044 use IPC::SysV;
1350616045
1350716046=begin original
1350816047
1350916048first to get the correct constant definitions. If CMD is IPC_STAT or
1351016049GETALL, then ARG must be a variable that will hold the returned
13511semid_ds structure or semaphore value array. Returns like C<ioctl>:
16050semid_ds structure or semaphore value array. Returns like
16051L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>:
1351216052the undefined value for error, "C<0 but true>" for zero, or the actual
1351316053return value otherwise. The ARG must consist of a vector of native
1351416054short integers, which may be created with C<pack("s!",(0)x$nsem)>.
13515See also L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::Semaphore>
16055See also L<perlipc/"SysV IPC"> and the documentation for
13516documentation.
16056L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>.
1351716057
1351816058=end original
1351916059
1352016060と書くことが必要でしょう。
1352116061CMD が、IPC_STAT か GETALL のときには、ARG は、返される
1352216062semid_ds 構造体か、セマフォ値の配列を納める変数でなければなりません。
13523C<ioctl> と同じように、エラー時には未定義値、
16063L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同じように、エラー時には
13524ゼロのときは C<"0 だが真">、それ以外なら、その値そのものを返します。
16064未定義値、ゼロのときは C<"0 だが真">、それ以外なら、その値そのものを返します。
1352516065ARG はネイティブな short int のベクターから成っていなければなりません; これは
1352616066C<pack("s!",(0)x$nsem)> で作成できます。
13527L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::Semaphore> も参照してください。
16067L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>
16068L<C<IPC::Semaphore>|IPC::Semaphore> の文書も参照してください。
1352816069
1352916070=begin original
1353016071
1353116072Portability issues: L<perlport/semctl>.
1353216073
1353316074=end original
1353416075
1353516076移植性の問題: L<perlport/semctl>。
1353616077
1353716078=item semget KEY,NSEMS,FLAGS
1353816079X<semget>
1353916080
1354016081=for Pod::Functions get set of SysV semaphores
1354116082
1354216083=begin original
1354316084
13544Calls the System V IPC function semget(2). Returns the semaphore id, or
16085Calls the System V IPC function L<semget(2)>. Returns the semaphore id, or
1354516086the undefined value on error. See also
13546L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Semaphore>
16087L<perlipc/"SysV IPC"> and the documentation for
13547documentation.
16088L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>.
1354816089
1354916090=end original
1355016091
13551System V IPC 関数 semget(2) を呼び出します。
16092System V IPC 関数 L<semget(2)> を呼び出します。
1355216093セマフォ ID か、エラー時には未定義値を返します。
13553L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Semaphore>
16094L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>
13554参照してください。
16095L<C<IPC::Semaphore>|IPC::Semaphore> の文書も参照してください。
1355516096
1355616097=begin original
1355716098
1355816099Portability issues: L<perlport/semget>.
1355916100
1356016101=end original
1356116102
1356216103移植性の問題: L<perlport/semget>。
1356316104
1356416105=item semop KEY,OPSTRING
1356516106X<semop>
1356616107
1356716108=for Pod::Functions SysV semaphore operations
1356816109
1356916110=begin original
1357016111
13571Calls the System V IPC function semop(2) for semaphore operations
16112Calls the System V IPC function L<semop(2)> for semaphore operations
1357216113such as signalling and waiting. OPSTRING must be a packed array of
1357316114semop structures. Each semop structure can be generated with
13574C<pack("s!3", $semnum, $semop, $semflag)>. The length of OPSTRING
16115C<pack("s!3", $semnum, $semop, $semflag)>. The length of OPSTRING
1357516116implies the number of semaphore operations. Returns true if
1357616117successful, false on error. As an example, the
1357716118following code waits on semaphore $semnum of semaphore id $semid:
1357816119
1357916120=end original
1358016121
1358116122シグナルを送信や、待ち合わせなどのセマフォ操作を行なうために、
13582System V IPC 関数 semop(2) を呼び出します。
16123System V IPC 関数 L<semop(2)> を呼び出します。
1358316124OPSTRING は、semop 構造体の pack された配列でなければなりません。
13584semop 構造体は、それぞれ、
16125semop 構造体は、それぞれ、C<pack("s!3", $semnum, $semop, $semflag)> のように
13585C<pack("s!3", $semnum, $semop, $semflag)> のように作ることができます。
16126作ることができます。
1358616127セマフォ操作の数は、OPSTRING の長さからわかります。
1358716128成功時には真を、エラー時には偽を返します。
1358816129以下の例は、セマフォ ID $semid のセマフォ $semnum で
1358916130待ち合わせを行ないます。
1359016131
13591 $semop = pack("s!3", $semnum, -1, 0);
16132 my $semop = pack("s!3", $semnum, -1, 0);
1359216133 die "Semaphore trouble: $!\n" unless semop($semid, $semop);
1359316134
1359416135=begin original
1359516136
1359616137To signal the semaphore, replace C<-1> with C<1>. See also
13597L<perlipc/"SysV IPC">, C<IPC::SysV>, and C<IPC::SysV::Semaphore>
16138L<perlipc/"SysV IPC"> and the documentation for
13598documentation.
16139L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>.
1359916140
1360016141=end original
1360116142
1360216143セマフォにシグナルを送るには、C<-1> を C<1> に変更してください。
13603L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Semaphore>
16144L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>
13604参照してください。
16145L<C<IPC::Semaphore>|IPC::Semaphore> の文書も参照してください。
1360516146
1360616147=begin original
1360716148
1360816149Portability issues: L<perlport/semop>.
1360916150
1361016151=end original
1361116152
1361216153移植性の問題: L<perlport/semop>。
1361316154
1361416155=item send SOCKET,MSG,FLAGS,TO
1361516156X<send>
1361616157
1361716158=item send SOCKET,MSG,FLAGS
1361816159
1361916160=for Pod::Functions send a message over a socket
1362016161
1362116162=begin original
1362216163
1362316164Sends a message on a socket. Attempts to send the scalar MSG to the SOCKET
1362416165filehandle. Takes the same flags as the system call of the same name. On
1362516166unconnected sockets, you must specify a destination to I<send to>, in which
13626case it does a sendto(2) syscall. Returns the number of characters sent,
16167case it does a L<sendto(2)> syscall. Returns the number of characters sent,
13627or the undefined value on error. The sendmsg(2) syscall is currently
16168or the undefined value on error. The L<sendmsg(2)> syscall is currently
1362816169unimplemented. See L<perlipc/"UDP: Message Passing"> for examples.
1362916170
1363016171=end original
1363116172
1363216173ソケットにメッセージを送ります。
1363316174スカラ MSG を ファイルハンドル SOCKET に送ろうとします。
1363416175同名のシステムコールと同じフラグが指定できます。
1363516176接続していないソケットには、I<send to> に接続先を指定しなければならず、
13636この場合、sendto(2) を実行します。
16177この場合、L<sendto(2)> を実行します。
1363716178送信した文字数か、エラー時には、未定義値を返します。
13638システムコール sendmsg(2) は現在実装されていません。
16179システムコール L<sendmsg(2)> は現在実装されていません。
1363916180例については L<perlipc/"UDP: Message Passing"> を参照してください。
1364016181
1364116182=begin original
1364216183
13643Note the I<characters>: depending on the status of the socket, either
16184Note that if the socket has been marked as C<:utf8>, C<send> will
13644(8-bit) bytes or characters are sent. By default all sockets operate
16185throw an exception. The C<:encoding(...)> layer implicitly introduces
13645on bytes, but for example if the socket has been changed using
16186the C<:utf8> layer. See L<C<binmode>|/binmode FILEHANDLE, LAYER>.
13646binmode() to operate with the C<:encoding(utf8)> I/O layer (see
13647L</open>, or the C<open> pragma, L<open>), the I/O will operate on UTF-8
13648encoded Unicode characters, not bytes. Similarly for the C<:encoding>
13649pragma: in that case pretty much any characters can be sent.
1365016187
1365116188=end original
1365216189
13653I<文字> に関する注意: ソケットの状態によって、(8 ビットの) バイトか
16190ソケットが C<:utf8> とマークされている場合、
13654文字送信ます
16191C<send> は例外投げることに注意てください
13655デフォルトで全てのソケットはバイト処理しますが、
16192C<:encoding(...)> 層暗黙に C<:utf8> 層導入します
13656例えばソケットが binmode() で C<:encoding(utf8)> I/O 層(L</open>
16193L<C<binmode>|/binmode FILEHANDLE, LAYER> を参照してください。
13657C<open> プラグマ、L<open> を参照してください) を使うように指定された場合、
13658I/O はバイトではなく、UTF-8 エンコードされた Unicode 文字を操作します。
13659C<:encoding> プラグマも同様です:
13660この場合、ほとんど大体全ての文字が書き込めます。
1366116194
1366216195=item setpgrp PID,PGRP
1366316196X<setpgrp> X<group>
1366416197
1366516198=for Pod::Functions set the process group of a process
1366616199
1366716200=begin original
1366816201
1366916202Sets the current process group for the specified PID, C<0> for the current
1367016203process. Raises an exception when used on a machine that doesn't
13671implement POSIX setpgid(2) or BSD setpgrp(2). If the arguments are omitted,
16204implement POSIX L<setpgid(2)> or BSD L<setpgrp(2)>. If the arguments
13672it defaults to C<0,0>. Note that the BSD 4.2 version of C<setpgrp> does not
16205are omitted, it defaults to C<0,0>. Note that the BSD 4.2 version of
13673accept any arguments, so only C<setpgrp(0,0)> is portable. See also
16206L<C<setpgrp>|/setpgrp PID,PGRP> does not accept any arguments, so only
13674C<POSIX::setsid()>.
16207C<setpgrp(0,0)> is portable. See also
16208L<C<POSIX::setsid()>|POSIX/C<setsid>>.
1367516209
1367616210=end original
1367716211
1367816212指定した PID (C<0> を指定するとカレントプロセス) に
1367916213対するプロセスグループを設定します。
13680POSIX setpgrp(2) または BSD setpgrp(2) が実装されていないマシンでは、
16214POSIX L<setpgrp(2)> または BSD L<setpgrp(2)> が実装されていないマシンでは、
1368116215例外が発生します。
1368216216引数が省略された場合は、C<0,0>が使われます。
13683BSD 4.2 版の C<setpgrp> は引数を取ることができないので、
16217BSD 4.2 版の L<C<setpgrp>|/setpgrp PID,PGRP> は引数を取ることができないので、
1368416218C<setpgrp(0,0)> のみが移植性があることに注意してください。
13685C<POSIX::setsid()> も参照してください。
16219L<C<POSIX::setsid()>|POSIX/C<setsid>> も参照してください。
1368616220
1368716221=begin original
1368816222
1368916223Portability issues: L<perlport/setpgrp>.
1369016224
1369116225=end original
1369216226
1369316227移植性の問題: L<perlport/setpgrp>。
1369416228
1369516229=item setpriority WHICH,WHO,PRIORITY
1369616230X<setpriority> X<priority> X<nice> X<renice>
1369716231
1369816232=for Pod::Functions set a process's nice value
1369916233
1370016234=begin original
1370116235
1370216236Sets the current priority for a process, a process group, or a user.
13703(See setpriority(2).) Raises an exception when used on a machine
16237(See L<setpriority(2)>.) Raises an exception when used on a machine
13704that doesn't implement setpriority(2).
16238that doesn't implement L<setpriority(2)>.
1370516239
1370616240=end original
1370716241
1370816242プロセス、プロセスグループ、ユーザに対する優先順位を設定します。
13709(setpriority(2) を参照してください。)
16243(L<setpriority(2)> を参照してください。)
13710setpriority(2) が実装されていないマシンでは、
16244L<setpriority(2)> が実装されていないマシンでは、例外が発生します。
13711例外が発生します。
1371216245
1371316246=begin original
1371416247
16248C<WHICH> can be any of C<PRIO_PROCESS>, C<PRIO_PGRP> or C<PRIO_USER>
16249imported from L<POSIX/RESOURCE CONSTANTS>.
16250
16251=end original
16252
16253C<WHICH> は、L<POSIX/RESOURCE CONSTANTS> からインポートされた
16254C<PRIO_PROCESS>, C<PRIO_PGRP>, C<PRIO_USER> のいずれかです。
16255
16256=begin original
16257
1371516258Portability issues: L<perlport/setpriority>.
1371616259
1371716260=end original
1371816261
1371916262移植性の問題: L<perlport/setpriority>。
1372016263
1372116264=item setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL
1372216265X<setsockopt>
1372316266
1372416267=for Pod::Functions set some socket options
1372516268
1372616269=begin original
1372716270
13728Sets the socket option requested. Returns C<undef> on error.
16271Sets the socket option requested. Returns L<C<undef>|/undef EXPR> on
13729Use integer constants provided by the C<Socket> module for
16272error. Use integer constants provided by the L<C<Socket>|Socket> module
16273for
1373016274LEVEL and OPNAME. Values for LEVEL can also be obtained from
1373116275getprotobyname. OPTVAL might either be a packed string or an integer.
1373216276An integer OPTVAL is shorthand for pack("i", OPTVAL).
1373316277
1373416278=end original
1373516279
1373616280要求したソケットオプションを設定します。
13737エラー時には、C<undef> を返します。
16281エラー時には、L<C<undef>|/undef EXPR> を返します。
13738LEVEL と OPNAME には C<Socket> モジュールが提供する整数定数を使います。
16282LEVEL と OPNAME には L<C<Socket>|Socket> モジュールが提供する
16283整数定数を使います。
1373916284LEVEL の値は getprotobyname から得ることもできます。
1374016285OPTVAL は pack された文字列か整数です。
1374116286整数の OPTVAL は pack("i", OPTVAL) の省略表現です。
1374216287
1374316288=begin original
1374416289
1374516290An example disabling Nagle's algorithm on a socket:
1374616291
1374716292=end original
1374816293
1374916294ソケットに対する Nagle のアルゴリズムを無効にする例です:
1375016295
1375116296 use Socket qw(IPPROTO_TCP TCP_NODELAY);
1375216297 setsockopt($socket, IPPROTO_TCP, TCP_NODELAY, 1);
1375316298
1375416299=begin original
1375516300
1375616301Portability issues: L<perlport/setsockopt>.
1375716302
1375816303=end original
1375916304
1376016305移植性の問題: L<perlport/setsockopt>。
1376116306
1376216307=item shift ARRAY
1376316308X<shift>
1376416309
13765=item shift EXPR
13766
1376716310=item shift
1376816311
1376916312=for Pod::Functions remove the first element of an array, and return it
1377016313
1377116314=begin original
1377216315
13773Shifts the first value of the array off and returns it, shortening the
16316Removes and returns the B<first> element of an array. This shortens the
13774array by 1 and moving everything down. If there are no elements in the
16317array by one and moves everything down.
13775array, returns the undefined value. If ARRAY is omitted, shifts the
13776C<@_> array within the lexical scope of subroutines and formats, and the
13777C<@ARGV> array outside a subroutine and also within the lexical scopes
13778established by the C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}>,
13779C<UNITCHECK {}>, and C<END {}> constructs.
1378016318
1378116319=end original
1378216320
13783配列の最初の値を取り出して、その値を返し、配列を一つ
16321配列の B<最初の> 値を削除して返します。
13784短くして、すべての要素を前へずらします。
16322配列を一つ短くして、すべての要素を前へずらします。
13785配列に要素がなければ、未定義値を返します。
13786ARRAY を省略すると、
13787サブルーチンやフォーマットのレキシカルスコープでは C<@_> を、
13788サブルーチンの外側で、C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}>,
13789C<UNITCHECK {}>, C<END {}> で作成されたレキシカルスコープでは
13790C<@ARGV> が用いられます。
1379116323
16324 my @arr = ('cat', 'dog');
16325 my $item = shift(@arr); # 'cat'
16326
16327 # @arr is now ('dog');
16328
1379216329=begin original
1379316330
13794Starting with Perl 5.14, C<shift> can take a scalar EXPR, which must hold a
16331Returns C<undef> if the array is empty.
13795reference to an unblessed array. The argument will be dereferenced
13796automatically. This aspect of C<shift> is considered highly experimental.
13797The exact behaviour may change in a future version of Perl.
1379816332
1379916333=end original
1380016334
13801Perl 5.14 かC<shift> はスカラの EXPR 取ることができるようになりまた;
16335配列が空な C<undef> をます。
13802これは bless されていない配列へのリファレンスでなければなりません。
13803引数は自動的にデリファレンスされます。
13804C<shift> のこの動作は高度に実験的であると考えられています。
13805正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
1380616336
1380716337=begin original
1380816338
13809To avoid confusing would-be users of your code who are running earlier
16339B<Note:> C<shift> may also return C<undef> if the first element in the array
13810versions of Perl with mysterious syntax errors, put this sort of thing at
16340is C<undef>.
13811the top of your file to signal that your code will work I<only> on Perls of
13812a recent vintage:
1381316341
1381416342=end original
1381516343
13816あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
16344B<Note:> C<shift> may also return C<undef> if the first element in the array
13817文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
16345is C<undef>.
13818I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
16346(TBT)
13819書いてください:
1382016347
13821 use 5.014; # so push/pop/etc work on scalars (experimental)
16348 my @arr = (undef, 'two', 'three');
16349 my $item = shift(@arr); # undef
1382216350
1382316351=begin original
1382416352
13825See also C<unshift>, C<push>, and C<pop>. C<shift> and C<unshift> do the
16353If ARRAY is omitted, C<shift> operates on the C<@ARGV> array in the main
13826same thing to the left end of an array that C<pop> and C<push> do to the
16354program, and the C<@_> array in subroutines. C<shift> will operate on the
13827right end.
16355C<@ARGV> array in C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}> blocks.
1382816356
1382916357=end original
1383016358
13831C<unshift>、C<push>、C<pop> も参照してください。
16359If ARRAY is omitted, C<shift> operates on the C<@ARGV> array in the main
13832C<shift> C<unshift> は、C<pop>
16360program, and the C<@_> array in subroutines. C<shift> will operate on the
13833C<push> が配列の右端で行なうことを、左端で行ないます。
16361C<@ARGV> array in C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}> blocks.
16362(TBT)
1383416363
16364=begin original
16365
16366Starting with Perl 5.14, an experimental feature allowed
16367L<C<shift>|/shift ARRAY> to take a
16368scalar expression. This experiment has been deemed unsuccessful, and was
16369removed as of Perl 5.24.
16370
16371=end original
16372
16373Perl 5.14 から、L<C<shift>|/shift ARRAY> がスカラ式を取ることが出来るという
16374実験的機能がありました。
16375この実験は失敗と見なされ、Perl 5.24 で削除されました。
16376
16377=begin original
16378
16379See also L<C<unshift>|/unshift ARRAY,LIST>, L<C<push>|/push ARRAY,LIST>,
16380and L<C<pop>|/pop ARRAY>. L<C<shift>|/shift ARRAY> and
16381L<C<unshift>|/unshift ARRAY,LIST> do the same thing to the left end of
16382an array that L<C<pop>|/pop ARRAY> and L<C<push>|/push ARRAY,LIST> do to
16383the right end.
16384
16385=end original
16386
16387L<C<unshift>|/unshift ARRAY,LIST>、L<C<push>|/push ARRAY,LIST>、
16388L<C<pop>|/pop ARRAY> も参照してください。
16389L<C<shift>|/shift ARRAY> と L<C<unshift>|/unshift ARRAY,LIST> は、
16390L<C<pop>|/pop ARRAY> と L<C<push>|/push ARRAY,LIST> が配列の右端で
16391行なうことを、左端で行ないます。
16392
1383516393=item shmctl ID,CMD,ARG
1383616394X<shmctl>
1383716395
1383816396=for Pod::Functions SysV shared memory operations
1383916397
1384016398=begin original
1384116399
1384216400Calls the System V IPC function shmctl. You'll probably have to say
1384316401
1384416402=end original
1384516403
1384616404System V IPC 関数 shmctl を呼び出します。
1384716405正しい定数定義を得るために、まず
1384816406
1384916407 use IPC::SysV;
1385016408
1385116409=begin original
1385216410
1385316411first to get the correct constant definitions. If CMD is C<IPC_STAT>,
1385416412then ARG must be a variable that will hold the returned C<shmid_ds>
13855structure. Returns like ioctl: C<undef> for error; "C<0> but
16413structure. Returns like ioctl: L<C<undef>|/undef EXPR> for error; "C<0>
13856true" for zero; and the actual return value otherwise.
16414but true" for zero; and the actual return value otherwise.
13857See also L<perlipc/"SysV IPC"> and C<IPC::SysV> documentation.
16415See also L<perlipc/"SysV IPC"> and the documentation for
16416L<C<IPC::SysV>|IPC::SysV>.
1385816417
1385916418=end original
1386016419
1386116420と書くことが必要でしょう。
1386216421CMD が、C<IPC_STAT> ならば、ARG は、返される C<shmid_ds> 構造体を
1386316422納める変数でなければなりません。
13864ioctl と同様です: エラー時には C<undef>; ゼロのときは "C<0> だが真";
16423ioctl と同様です: エラー時には L<C<undef>|/undef EXPR>; ゼロのときは
13865それ以外なら、その値そのものを返します。
16424"C<0> だが真"; それ以外なら、その値そのものを返します。
13866L<perlipc/"SysV IPC"> C<IPC::SysV> も参照してください。
16425L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV> の文書
16426参照してください。
1386716427
1386816428=begin original
1386916429
1387016430Portability issues: L<perlport/shmctl>.
1387116431
1387216432=end original
1387316433
1387416434移植性の問題: L<perlport/shmctl>。
1387516435
1387616436=item shmget KEY,SIZE,FLAGS
1387716437X<shmget>
1387816438
1387916439=for Pod::Functions get SysV shared memory segment identifier
1388016440
1388116441=begin original
1388216442
1388316443Calls the System V IPC function shmget. Returns the shared memory
13884segment id, or C<undef> on error.
16444segment id, or L<C<undef>|/undef EXPR> on error.
13885See also L<perlipc/"SysV IPC"> and C<IPC::SysV> documentation.
16445See also L<perlipc/"SysV IPC"> and the documentation for
16446L<C<IPC::SysV>|IPC::SysV>.
1388616447
1388716448=end original
1388816449
1388916450System V IPC 関数 shmget を呼び出します。
13890共有メモリのセグメント ID か、エラー時には C<undef> を返します。
16451共有メモリのセグメント ID か、エラー時には L<C<undef>|/undef EXPR> を返します。
13891L<perlipc/"SysV IPC"> C<IPC::SysV> も参照してください。
16452L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV> の文書
16453参照してください。
1389216454
1389316455=begin original
1389416456
1389516457Portability issues: L<perlport/shmget>.
1389616458
1389716459=end original
1389816460
1389916461移植性の問題: L<perlport/shmget>。
1390016462
1390116463=item shmread ID,VAR,POS,SIZE
1390216464X<shmread>
1390316465X<shmwrite>
1390416466
1390516467=for Pod::Functions read SysV shared memory
1390616468
1390716469=item shmwrite ID,STRING,POS,SIZE
1390816470
1390916471=for Pod::Functions write SysV shared memory
1391016472
1391116473=begin original
1391216474
1391316475Reads or writes the System V shared memory segment ID starting at
1391416476position POS for size SIZE by attaching to it, copying in/out, and
1391516477detaching from it. When reading, VAR must be a variable that will
1391616478hold the data read. When writing, if STRING is too long, only SIZE
1391716479bytes are used; if STRING is too short, nulls are written to fill out
1391816480SIZE bytes. Return true if successful, false on error.
13919shmread() taints the variable. See also L<perlipc/"SysV IPC">,
16481L<C<shmread>|/shmread ID,VAR,POS,SIZE> taints the variable. See also
13920C<IPC::SysV>, and the C<IPC::Shareable> module from CPAN.
16482L<perlipc/"SysV IPC"> and the documentation for
16483L<C<IPC::SysV>|IPC::SysV> and the L<C<IPC::Shareable>|IPC::Shareable>
16484module from CPAN.
1392116485
1392216486=end original
1392316487
13924System V 共有メモリセグメント ID に対し、アタッチして、
16488System V 共有メモリセグメント ID に対し、アタッチして、コピーを行ない、
13925コピーを行ない、デタッチするという形で、位置 POS から、
16489デタッチするという形で、位置 POS から、サイズ SIZE だけ、読み込みか書き込みを
13926サイズ SIZE だけ、読み込みか書き込みを行ないます。
16490行ないます。
13927読み込み時には、VAR は読み込んだデータを納める
16491読み込み時には、VAR は読み込んだデータを納める変数でなければなりません。
13928変数でなければなりません。
1392916492書き込み時には、STRING が長すぎても、SIZE バイトだけが使われます; STRING が
1393016493短すぎる場合には、SIZE バイトを埋めるために、ヌル文字が書き込まれます。
1393116494成功時には真を、エラー時には偽を返します。
13932shmread() は変数を汚染します。
16495L<C<shmread>|/shmread ID,VAR,POS,SIZE> は変数を汚染します。
13933L<perlipc/"SysV IPC"> および C<IPC::SysV> と
16496L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV> CPAN の
13934CPAN の C<IPC::Shareable> も参照してください。
16497L<C<IPC::Shareable>|IPC::Shareable> の文書も参照してください。
1393516498
1393616499=begin original
1393716500
1393816501Portability issues: L<perlport/shmread> and L<perlport/shmwrite>.
1393916502
1394016503=end original
1394116504
1394216505移植性の問題: L<perlport/shmread> と L<perlport/shmwrite>。
1394316506
1394416507=item shutdown SOCKET,HOW
1394516508X<shutdown>
1394616509
1394716510=for Pod::Functions close down just half of a socket connection
1394816511
1394916512=begin original
1395016513
1395116514Shuts down a socket connection in the manner indicated by HOW, which
1395216515has the same interpretation as in the syscall of the same name.
1395316516
1395416517=end original
1395516518
1395616519同名のシステムコールと同じように解釈される HOW によって、
1395716520指定された方法でソケット接続のシャットダウンを行ないます。
1395816521
13959 shutdown(SOCKET, 0); # I/we have stopped reading data
16522 shutdown($socket, 0); # I/we have stopped reading data
13960 shutdown(SOCKET, 1); # I/we have stopped writing data
16523 shutdown($socket, 1); # I/we have stopped writing data
13961 shutdown(SOCKET, 2); # I/we have stopped using this socket
16524 shutdown($socket, 2); # I/we have stopped using this socket
1396216525
1396316526=begin original
1396416527
1396516528This is useful with sockets when you want to tell the other
1396616529side you're done writing but not done reading, or vice versa.
1396716530It's also a more insistent form of close because it also
1396816531disables the file descriptor in any forked copies in other
1396916532processes.
1397016533
1397116534=end original
1397216535
1397316536これは、こちらがソケットを書き終わったが読み終わっていない、
1397416537またはその逆を相手側に伝えたいときに便利です。
1397516538これはその他のプロセスでフォークしたファイル記述子のコピーも
1397616539無効にするので、よりしつこい閉じ方です。
1397716540
1397816541=begin original
1397916542
13980Returns C<1> for success; on error, returns C<undef> if
16543Returns C<1> for success; on error, returns L<C<undef>|/undef EXPR> if
1398116544the first argument is not a valid filehandle, or returns C<0> and sets
13982C<$!> for any other failure.
16545L<C<$!>|perlvar/$!> for any other failure.
1398316546
1398416547=end original
1398516548
1398616549成功時には C<1> を返します;
13987エラーの場合、最初の引数が有効なファイルハンドルでない場合は C<undef> を
16550エラーの場合、最初の引数が有効なファイルハンドルでない場合は
13988返し、その他のエラーの場合は C<0> を返してC<$!> をセットします。
16551L<C<undef>|/undef EXPR> を返し、その他のエラーの場合は C<0> を返して
16552L<C<$!>|perlvar/$!> をセットします。
1398916553
1399016554=item sin EXPR
1399116555X<sin> X<sine> X<asin> X<arcsine>
1399216556
1399316557=item sin
1399416558
1399516559=for Pod::Functions return the sine of a number
1399616560
1399716561=begin original
1399816562
1399916563Returns the sine of EXPR (expressed in radians). If EXPR is omitted,
14000returns sine of C<$_>.
16564returns sine of L<C<$_>|perlvar/$_>.
1400116565
1400216566=end original
1400316567
1400416568(ラジアンで示した) EXPR の正弦を返します。
14005EXPR が省略されたときには、C<$_> の正弦を返します。
16569EXPR が省略されたときには、L<C<$_>|perlvar/$_> の正弦を返します。
1400616570
1400716571=begin original
1400816572
1400916573For the inverse sine operation, you may use the C<Math::Trig::asin>
1401016574function, or use this relation:
1401116575
1401216576=end original
1401316577
1401416578逆正弦を求めるためには、C<Math::Trig::asin> 関数を使うか、
1401516579以下の関係を使ってください:
1401616580
1401716581 sub asin { atan2($_[0], sqrt(1 - $_[0] * $_[0])) }
1401816582
1401916583=item sleep EXPR
1402016584X<sleep> X<pause>
1402116585
1402216586=item sleep
1402316587
1402416588=for Pod::Functions block for some number of seconds
1402516589
1402616590=begin original
1402716591
14028Causes the script to sleep for (integer) EXPR seconds, or forever if no
16592Causes the script to sleep for (integer) EXPR seconds, or forever if no
14029argument is given. Returns the integer number of seconds actually slept.
16593argument is given. Returns the integer number of seconds actually slept.
1403016594
1403116595=end original
1403216596
1403316597スクリプトを(整数の) EXPR で指定した秒数 (省略時には、永久に)
1403416598スリープさせます。
14035実際にスリープした秒数を返します。
16599実際にスリープした秒数を返します。
1403616600
1403716601=begin original
1403816602
16603EXPR should be a positive integer. If called with a negative integer,
16604L<C<sleep>|/sleep EXPR> does not sleep but instead emits a warning, sets
16605C<$!> (C<errno>), and returns zero.
16606
16607=end original
16608
16609EXPR は正の整数である必要があります。
16610負の整数で呼び出すと、 L<C<sleep>|/sleep EXPR> はスリープせず、
16611警告を出力して、C<$!> (C<errno>) を設定し、ゼロを返します。
16612
16613=begin original
16614
16615If called with a non-integer, the fractional part is ignored.
16616
16617=end original
16618
16619If called with a non-integer, the fractional part is ignored.
16620(TBT)
16621
16622=begin original
16623
16624C<sleep 0> is permitted, but a function call to the underlying platform
16625implementation still occurs, with any side effects that may have.
16626C<sleep 0> is therefore not exactly identical to not sleeping at all.
16627
16628=end original
16629
16630C<sleep 0> は許されていますが、基となるプラットフォーム実装への
16631関数呼び出しはやはり行われ、どのような副作用も起こり得ます。
16632従って、C<sleep 0> は全くスリープしないのと正確に同じではありません。
16633
16634=begin original
16635
1403916636May be interrupted if the process receives a signal such as C<SIGALRM>.
1404016637
1404116638=end original
1404216639
1404316640そのプロセスが C<SIGALRM>のようなシグナルを受信すると、
1404416641割り込みがかかります。
1404516642
1404616643 eval {
14047 local $SIG{ALARM} = sub { die "Alarm!\n" };
16644 local $SIG{ALRM} = sub { die "Alarm!\n" };
1404816645 sleep;
1404916646 };
1405016647 die $@ unless $@ eq "Alarm!\n";
1405116648
1405216649=begin original
1405316650
14054You probably cannot mix C<alarm> and C<sleep> calls, because C<sleep>
16651You probably cannot mix L<C<alarm>|/alarm SECONDS> and
14055is often implemented using C<alarm>.
16652L<C<sleep>|/sleep EXPR> calls, because L<C<sleep>|/sleep EXPR> is often
16653implemented using L<C<alarm>|/alarm SECONDS>.
1405616654
1405716655=end original
1405816656
14059C<sleep> は、C<alarm> を使って実装されることが多いので、C<alarm>
16657L<C<sleep>|/sleep EXPR> は、L<C<alarm>|/alarm SECONDS> を使って
14060C<sleep> は、混ぜて使用するこはおそらくできません。
16658実装されることが多いので、L<C<alarm>|/alarm SECONDS>
16659L<C<sleep>|/sleep EXPR> は、混ぜて使用することはおそらくできません。
1406116660
1406216661=begin original
1406316662
1406416663On some older systems, it may sleep up to a full second less than what
1406516664you requested, depending on how it counts seconds. Most modern systems
1406616665always sleep the full amount. They may appear to sleep longer than that,
1406716666however, because your process might not be scheduled right away in a
1406816667busy multitasking system.
1406916668
1407016669=end original
1407116670
1407216671古いシステムでは、どのように秒を数えるかによって、要求した秒数に完全に
1407316672満たないうちに、スリープから抜ける場合があります。
1407416673最近のシステムでは、常に完全にスリープします。
1407516674しかし、負荷の高いマルチタスクシステムでは
1407616675正しくスケジューリングされないがために
1407716676より長い時間スリープすることがあります。
1407816677
1407916678=begin original
1408016679
14081For delays of finer granularity than one second, the Time::HiRes module
16680For delays of finer granularity than one second, the L<Time::HiRes>
14082(from CPAN, and starting from Perl 5.8 part of the standard
16681module (from CPAN, and starting from Perl 5.8 part of the standard
14083distribution) provides usleep(). You may also use Perl's four-argument
16682distribution) provides L<C<usleep>|Time::HiRes/usleep ( $useconds )>.
14084version of select() leaving the first three arguments undefined, or you
16683You may also use Perl's four-argument
14085might be able to use the C<syscall> interface to access setitimer(2) if
16684version of L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> leaving the
14086your system supports it. See L<perlfaq8> for details.
16685first three arguments undefined, or you might be able to use the
16686L<C<syscall>|/syscall NUMBER, LIST> interface to access L<setitimer(2)>
16687if your system supports it. See L<perlfaq8> for details.
1408716688
1408816689=end original
1408916690
140901 秒より精度の高いスリープを行なうには、
166911 秒より精度の高いスリープを行なうには、L<Time::HiRes> モジュール(CPAN から、
14091Time::HiRes モジュール(CPAN から、また Perl 5.8 からは
16692また Perl 5.8 からは標準配布されています) が
14092標準配布されています) が usleep() を提供します。
16693L<C<usleep>|Time::HiRes/usleep ( $useconds )> を提供します。
14093Perl の 4 引数版 select() を最初の 3 引数を未定義にして使うか、
16694Perl の 4 引数版 L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を最初の
14094setitimer(2) をサポートしているシステムでは、Perl の
166953 引数を未定義にして使うか、L<setitimer(2)> をサポートしているシステムでは、
14095C<syscall> インタフェースを使ってアクセスすることもできます。
16696Perl の L<C<syscall>|/syscall NUMBER, LIST> インタフェースを使って
16697アクセスすることもできます。
1409616698詳しくは L<perlfaq8> を参照してください。
1409716699
1409816700=begin original
1409916701
14100See also the POSIX module's C<pause> function.
16702See also the L<POSIX> module's L<C<pause>|POSIX/C<pause>> function.
1410116703
1410216704=end original
1410316705
14104POSIX モジュールの C<pause> 関数も参照してください。
16706L<POSIX> モジュールの L<C<pause>|POSIX/C<pause>> 関数も参照してください。
1410516707
1410616708=item socket SOCKET,DOMAIN,TYPE,PROTOCOL
1410716709X<socket>
1410816710
1410916711=for Pod::Functions create a socket
1411016712
1411116713=begin original
1411216714
1411316715Opens a socket of the specified kind and attaches it to filehandle
1411416716SOCKET. DOMAIN, TYPE, and PROTOCOL are specified the same as for
1411516717the syscall of the same name. You should C<use Socket> first
1411616718to get the proper definitions imported. See the examples in
1411716719L<perlipc/"Sockets: Client/Server Communication">.
1411816720
1411916721=end original
1412016722
14121指定した種類のソケットをオープンし、ファイルハンドル
16723指定した種類のソケットをオープンし、ファイルハンドル SOCKET にアタッチします。
14122SOCKET にアタッチします。
1412316724DOMAIN, TYPE, PROTOCOL は、同名のシステムコールと同じように指定します。
14124適切な定義を import するために、まず、C<use Socket> と
16725適切な定義を import するために、まず、C<use Socket> とするとよいでしょう。
14125するとよいでしょう。
1412616726L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
1412716727
1412816728=begin original
1412916729
1413016730On systems that support a close-on-exec flag on files, the flag will
1413116731be set for the newly opened file descriptor, as determined by the
14132value of $^F. See L<perlvar/$^F>.
16732value of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>.
1413316733
1413416734=end original
1413516735
1413616736ファイルに対する close-on-exec フラグをサポートしているシステムでは、
14137フラグは $^F の値で決定される、新しくオープンされたファイル記述子に対して
16737フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた
14138セットされます。
16738ファイル記述子に対してセットされます。
1413916739L<perlvar/$^F> を参照してください。
1414016740
1414116741=item socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL
1414216742X<socketpair>
1414316743
1414416744=for Pod::Functions create a pair of sockets
1414516745
1414616746=begin original
1414716747
1414816748Creates an unnamed pair of sockets in the specified domain, of the
1414916749specified type. DOMAIN, TYPE, and PROTOCOL are specified the same as
1415016750for the syscall of the same name. If unimplemented, raises an exception.
1415116751Returns true if successful.
1415216752
1415316753=end original
1415416754
1415516755指定した DOMAIN に、指定した TYPE で名前の無いソケットのペアを生成します。
1415616756DOMAIN, TYPE, PROTOCOL は、同名のシステムコールと同じように指定します。
1415716757実装されていない場合には、例外が発生します。
1415816758成功時には真を返します。
1415916759
1416016760=begin original
1416116761
1416216762On systems that support a close-on-exec flag on files, the flag will
1416316763be set for the newly opened file descriptors, as determined by the value
14164of $^F. See L<perlvar/$^F>.
16764of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>.
1416516765
1416616766=end original
1416716767
1416816768ファイルに対する close-on-exec フラグをサポートしているシステムでは、
14169フラグは $^F の値で決定される、新しくオープンされたファイル記述子に対して
16769フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた
14170セットされます。
16770ファイル記述子に対してセットされます。
1417116771L<perlvar/$^F> を参照してください。
1417216772
1417316773=begin original
1417416774
14175Some systems defined C<pipe> in terms of C<socketpair>, in which a call
16775Some systems define L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> in terms of
14176to C<pipe(Rdr, Wtr)> is essentially:
16776L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL>, in
16777which a call to C<pipe($rdr, $wtr)> is essentially:
1417716778
1417816779=end original
1417916780
14180C<pipe> を C<socketpair> を使って定義しているシステムもあります;
16781L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> を
14181C<pipe(Rdr, Wtr)> は本質的には以下のようになります:
16782L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL> を使って
16783定義しているシステムもあります;
16784C<pipe($rdr, $wtr)> は本質的には以下のようになります:
1418216785
1418316786 use Socket;
14184 socketpair(Rdr, Wtr, AF_UNIX, SOCK_STREAM, PF_UNSPEC);
16787 socketpair(my $rdr, my $wtr, AF_UNIX, SOCK_STREAM, PF_UNSPEC);
14185 shutdown(Rdr, 1); # no more writing for reader
16788 shutdown($rdr, 1); # no more writing for reader
14186 shutdown(Wtr, 0); # no more reading for writer
16789 shutdown($wtr, 0); # no more reading for writer
1418716790
1418816791=begin original
1418916792
1419016793See L<perlipc> for an example of socketpair use. Perl 5.8 and later will
1419116794emulate socketpair using IP sockets to localhost if your system implements
1419216795sockets but not socketpair.
1419316796
1419416797=end original
1419516798
1419616799socketpair の使用例については L<perlipc> を参照してください。
1419716800Perl 5.8 以降では、システムがソケットを実装しているが socketpair を
1419816801実装していない場合、localhost に対して IP ソケットを使うことで
1419916802socketpair をエミュレートします。
1420016803
1420116804=begin original
1420216805
1420316806Portability issues: L<perlport/socketpair>.
1420416807
1420516808=end original
1420616809
1420716810移植性の問題: L<perlport/socketpair>。
1420816811
1420916812=item sort SUBNAME LIST
14210X<sort> X<qsort> X<quicksort> X<mergesort>
16813X<sort>
1421116814
1421216815=item sort BLOCK LIST
1421316816
1421416817=item sort LIST
1421516818
1421616819=for Pod::Functions sort a list of values
1421716820
1421816821=begin original
1421916822
1422016823In list context, this sorts the LIST and returns the sorted list value.
14221In scalar context, the behaviour of C<sort()> is undefined.
16824In scalar context, the behaviour of L<C<sort>|/sort SUBNAME LIST> is
16825undefined.
1422216826
1422316827=end original
1422416828
1422516829リストコンテキストでは、LIST をソートし、ソートされたリスト値を返します。
14226スカラコンテキストでは、C<sort()> の振る舞いは未定義です。
16830スカラコンテキストでは、L<C<sort>|/sort SUBNAME LIST> の振る舞いは未定義です。
1422716831
1422816832=begin original
1422916833
14230If SUBNAME or BLOCK is omitted, C<sort>s in standard string comparison
16834If SUBNAME or BLOCK is omitted, L<C<sort>|/sort SUBNAME LIST>s in
16835standard string comparison
1423116836order. If SUBNAME is specified, it gives the name of a subroutine
14232that returns an integer less than, equal to, or greater than C<0>,
16837that returns a numeric value less than, equal to, or greater than C<0>,
14233depending on how the elements of the list are to be ordered. (The
16838depending on how the elements of the list are to be ordered. (The
1423416839C<< <=> >> and C<cmp> operators are extremely useful in such routines.)
1423516840SUBNAME may be a scalar variable name (unsubscripted), in which case
1423616841the value provides the name of (or a reference to) the actual
1423716842subroutine to use. In place of a SUBNAME, you can provide a BLOCK as
1423816843an anonymous, in-line sort subroutine.
1423916844
1424016845=end original
1424116846
14242SUBNAME や BLOCK を省略すると、標準の文字列比較の順番でソートが
16847SUBNAME や BLOCK を省略すると、L<C<sort>|/sort SUBNAME LIST> は標準の
14243行なわれます。
16848文字列比較の順番で行なわれます。
1424416849SUBNAME を指定すると、それは、リストの要素をどのような順番に並べるかに
14245応じて、負、ゼロ、正の数を返すサブルーチンの名前であると解釈されます。
16850応じて、負の数C<0>、正の数を返すサブルーチンの名前であると解釈されます。
14246(このようなルーチンには、C<< <=> >> 演算子や cmp 演算子が、
16851(このようなルーチンには、C<< <=> >> 演算子や C<cmp> 演算子が、
1424716852たいへん便利です。)
14248SUBNAME は、スカラ変数名(添字なし)でもよく、
16853SUBNAME は、スカラ変数名(添字なし)でもよく、その場合には、その値が使用する
14249その場合には、その値が使用する実際のサブルーチンの
16854実際のサブルーチンの名前(またはそのリファレンス)と解釈されます。
14250前(またはそリファレス)解釈されます。
16855SUBNAME の代わりに、無名のラインソートルーチンして、BLOCK を
14251SUBNAME の代わりに、無名のインライン
16856書くことができます。
14252ソートルーチンとして、BLOCK を書くことができます。
1425316857
1425416858=begin original
1425516859
1425616860If the subroutine's prototype is C<($$)>, the elements to be compared are
14257passed by reference in C<@_>, as for a normal subroutine. This is slower
16861passed by reference in L<C<@_>|perlvar/@_>, as for a normal subroutine.
14258than unprototyped subroutines, where the elements to be compared are passed
16862This is slower than unprototyped subroutines, where the elements to be
14259into the subroutine as the package global variables $a and $b (see example
16863compared are passed into the subroutine as the package global variables
14260below). Note that in the latter case, it is usually highly counter-productive
16864C<$a> and C<$b> (see example below).
14261to declare $a and $b as lexicals.
1426216865
1426316866=end original
1426416867
14265サブルーチンのプロトタイプが C<($$)>の場合、比較する要素は通常の
16868サブルーチンのプロトタイプが C<($$)>の場合、比較する要素は通常のサブルーチンと
14266サブルーチンと同じように C<@_> の中にリファレンスとして渡されます。
16869同じように L<C<@_>|perlvar/@_> の中にリファレンスとして渡されます。
1426716870これはプロトタイプなしのサブルーチンより遅いです; この場合は比較のため
14268サブルーチンに渡される二つの要素は、パッケージのグローバル変数 $a と $b で
16871サブルーチンに渡される二つの要素は、パッケージのグローバル変数 C<$a>
14269渡されます(次の例を参照してください)。
16872C<$b> で渡されます(次の例を参照してください)。
14270後者の場合、レキシカルに $a と $b を宣言するのは普通とても逆効果になります。
1427116873
1427216874=begin original
1427316875
14274If the subroutine is an XSUB, the elements to be compared are pushed on to
16876If the subroutine is an XSUB, the elements to be compared are pushed on
14275the stack, the way arguments are usually passed to XSUBs. $a and $b are
16877to the stack, the way arguments are usually passed to XSUBs. C<$a> and
14276not set.
16878C<$b> are not set.
1427716879
1427816880=end original
1427916881
1428016882サブルーチンが XSUB の場合、比較される要素は、普通に引数を XSUB に渡す形で、
1428116883スタックにプッシュされます。
14282$a と $b は設定されません。
16884C<$a>C<$b> は設定されません。
1428316885
1428416886=begin original
1428516887
1428616888The values to be compared are always passed by reference and should not
1428716889be modified.
1428816890
1428916891=end original
1429016892
14291$a や $b はリファレンスによって渡されるので、変更するべきではありません。
16893比較される値はリファレンスによって渡されるので、変更するべきではありません。
1429216894
1429316895=begin original
1429416896
1429516897You also cannot exit out of the sort block or subroutine using any of the
14296loop control operators described in L<perlsyn> or with C<goto>.
16898loop control operators described in L<perlsyn> or with
16899L<C<goto>|/goto LABEL>.
1429716900
1429816901=end original
1429916902
1430016903また、ソートブロックやサブルーチンから L<perlsyn> で説明されている
14301ループ制御子や C<goto> を使って抜けてはいけません。
16904ループ制御子や L<C<goto>|/goto LABEL> を使って抜けてはいけません。
1430216905
1430316906=begin original
1430416907
14305When C<use locale> (but not C<use locale 'not_characters'>) is in
16908When L<C<use locale>|locale> (but not C<use locale ':not_characters'>)
14306effect, C<sort LIST> sorts LIST according to the
16909is in effect, C<sort LIST> sorts LIST according to the
1430716910current collation locale. See L<perllocale>.
1430816911
1430916912=end original
1431016913
14311C<use locale> が有効(そして C<use locale 'not_characters'> が有効でない)の
16914L<C<use locale>|locale> が有効(そして C<use locale ':not_characters'> が
14312場合、C<sort LIST> は LIST を現在の比較ロケールに従ってソートします。
16915有効でない)の場合、C<sort LIST> は LIST を現在の比較ロケールに従って
16916ソートします。
1431316917L<perllocale> を参照してください。
1431416918
1431516919=begin original
1431616920
14317sort() returns aliases into the original list, much as a for loop's index
16921L<C<sort>|/sort SUBNAME LIST> returns aliases into the original list,
14318variable aliases the list elements. That is, modifying an element of a
16922much as a for loop's index variable aliases the list elements. That is,
14319list returned by sort() (for example, in a C<foreach>, C<map> or C<grep>)
16923modifying an element of a list returned by L<C<sort>|/sort SUBNAME LIST>
16924(for example, in a C<foreach>, L<C<map>|/map BLOCK LIST> or
16925L<C<grep>|/grep BLOCK LIST>)
1432016926actually modifies the element in the original list. This is usually
1432116927something to be avoided when writing clear code.
1432216928
1432316929=end original
1432416930
14325sort() は元のリストへのエイリアスを返します; for ループのインデックス変数が
16931L<C<sort>|/sort SUBNAME LIST> は元のリストへのエイリアスを返します;
14326リスト要素へのエイリアスと同様です。
16932for ループのインデックス変数がリスト要素へのエイリアスと同様です。
14327つまり、sort() で返されるリストの要素を(例えば、C<foreach> や C<map> や
16933つまり、L<C<sort>|/sort SUBNAME LIST> で返されるリストの要素を(例えば、
14328C<grep> で)変更すると、実際に元のリストの要素が変更されます。
16934C<foreach> や L<C<map>|/map BLOCK LIST> や
16935L<C<grep>|/grep BLOCK LIST> で)変更すると、実際に元のリストの要素が
16936変更されます。
1432916937これはきれいなコードを書くときには普通は回避されます。
1433016938
1433116939=begin original
1433216940
14333Perl 5.6 and earlier used a quicksort algorithm to implement sort.
16941Historically Perl has varied in whether sorting is stable by default.
14334That algorithm was not stable, so I<could> go quadratic. (A I<stable> sort
16942If stability matters, it can be controlled explicitly by using the
14335preserves the input order of elements that compare equal. Although
16943L<sort> pragma.
14336quicksort's run time is O(NlogN) when averaged over all arrays of
14337length N, the time can be O(N**2), I<quadratic> behavior, for some
14338inputs.) In 5.7, the quicksort implementation was replaced with
14339a stable mergesort algorithm whose worst-case behavior is O(NlogN).
14340But benchmarks indicated that for some inputs, on some platforms,
14341the original quicksort was faster. 5.8 has a sort pragma for
14342limited control of the sort. Its rather blunt control of the
14343underlying algorithm may not persist into future Perls, but the
14344ability to characterize the input or output in implementation
14345independent ways quite probably will. See L<the sort pragma|sort>.
1434616944
1434716945=end original
1434816946
14349Perl 5.6 以前ではソートの実装にクイックソートアゴリズムを使っていました
16947歴史的にソートがデフォトで安定かどうかは様々です
14350このアルゴリズムは安定していいので2 乗の時間が掛かる
16948安定性が問題にる場合はL<sort> プラグマを使うことで明示的に制御できます。
14351I<可能性があります>。
14352(I<安定した> ソートは、比較した時に同じ要素の入力順が保存されます。
14353クイックソートの実行時間は、長さ N の全ての配列の平均では
14354O(NlogN) ですが、入力によっては O(N**2) という I<2 乗の> 振る舞いを
14355することがあります。)
143565.7 では、クイックソートによる実装は、最悪の場合の振る舞いも
14357O(NlogN) である、安定したマージソートアルゴリズムに置き換えられました。
14358しかし、入力とプラットフォームによっては、ベンチマークはクイックソートの
14359方が速くなります。
143605.8 ではソートを限定的に制御できる sort プラグマがあります。
14361この、アルゴリズムの直接的な制御方法は将来の perl では引き継がれないかも
14362しれませんが、実装に依存しない形で入力や出力を性格付ける機能は
14363おそらくあります。
14364L<the sort pragma|sort> を参照してください。
1436516949
1436616950=begin original
1436716951
1436816952Examples:
1436916953
1437016954=end original
1437116955
1437216956例:
1437316957
1437416958 # sort lexically
14375 @articles = sort @files;
16959 my @articles = sort @files;
1437616960
1437716961 # same thing, but with explicit sort routine
14378 @articles = sort {$a cmp $b} @files;
16962 my @articles = sort {$a cmp $b} @files;
1437916963
1438016964 # now case-insensitively
14381 @articles = sort {fc($a) cmp fc($b)} @files;
16965 my @articles = sort {fc($a) cmp fc($b)} @files;
1438216966
1438316967 # same thing in reversed order
14384 @articles = sort {$b cmp $a} @files;
16968 my @articles = sort {$b cmp $a} @files;
1438516969
1438616970 # sort numerically ascending
14387 @articles = sort {$a <=> $b} @files;
16971 my @articles = sort {$a <=> $b} @files;
1438816972
1438916973 # sort numerically descending
14390 @articles = sort {$b <=> $a} @files;
16974 my @articles = sort {$b <=> $a} @files;
1439116975
1439216976 # this sorts the %age hash by value instead of key
1439316977 # using an in-line function
14394 @eldest = sort { $age{$b} <=> $age{$a} } keys %age;
16978 my @eldest = sort { $age{$b} <=> $age{$a} } keys %age;
1439516979
1439616980 # sort using explicit subroutine name
1439716981 sub byage {
1439816982 $age{$a} <=> $age{$b}; # presuming numeric
1439916983 }
14400 @sortedclass = sort byage @class;
16984 my @sortedclass = sort byage @class;
1440116985
1440216986 sub backwards { $b cmp $a }
14403 @harry = qw(dog cat x Cain Abel);
16987 my @harry = qw(dog cat x Cain Abel);
14404 @george = qw(gone chased yz Punished Axed);
16988 my @george = qw(gone chased yz Punished Axed);
1440516989 print sort @harry;
1440616990 # prints AbelCaincatdogx
1440716991 print sort backwards @harry;
1440816992 # prints xdogcatCainAbel
1440916993 print sort @george, 'to', @harry;
1441016994 # prints AbelAxedCainPunishedcatchaseddoggonetoxyz
1441116995
1441216996 # inefficiently sort by descending numeric compare using
1441316997 # the first integer after the first = sign, or the
1441416998 # whole record case-insensitively otherwise
1441516999
1441617000 my @new = sort {
1441717001 ($b =~ /=(\d+)/)[0] <=> ($a =~ /=(\d+)/)[0]
1441817002 ||
1441917003 fc($a) cmp fc($b)
1442017004 } @old;
1442117005
1442217006 # same thing, but much more efficiently;
1442317007 # we'll build auxiliary indices instead
1442417008 # for speed
14425 my @nums = @caps = ();
17009 my (@nums, @caps);
1442617010 for (@old) {
1442717011 push @nums, ( /=(\d+)/ ? $1 : undef );
1442817012 push @caps, fc($_);
1442917013 }
1443017014
1443117015 my @new = @old[ sort {
1443217016 $nums[$b] <=> $nums[$a]
1443317017 ||
1443417018 $caps[$a] cmp $caps[$b]
1443517019 } 0..$#old
1443617020 ];
1443717021
1443817022 # same thing, but without any temps
14439 @new = map { $_->[0] }
17023 my @new = map { $_->[0] }
1444017024 sort { $b->[1] <=> $a->[1]
1444117025 ||
1444217026 $a->[2] cmp $b->[2]
1444317027 } map { [$_, /=(\d+)/, fc($_)] } @old;
1444417028
1444517029 # using a prototype allows you to use any comparison subroutine
1444617030 # as a sort subroutine (including other package's subroutines)
14447 package other;
17031 package Other;
1444817032 sub backwards ($$) { $_[1] cmp $_[0]; } # $a and $b are
14449 # not set here
17033 # not set here
1445017034 package main;
14451 @new = sort other::backwards @old;
17035 my @new = sort Other::backwards @old;
1445217036
14453 # guarantee stability, regardless of algorithm
17037 <#ins># using a prototype with function signature
14454 use sort 'stable';
17038 use feature 'signatures';
14455 @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old;
17039 sub function_with_signature :prototype($$) ($one, $two) {
17040 return $one <=> $two
17041 }
1445617042
14457 # force use of mergesort (not portable outside Perl 5.8)
17043 my @new = sort function_with_signature @old;
14458 use sort '_mergesort'; # note discouraging _
14459 @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old;
1446017044
17045 # guarantee stability
17046 use sort 'stable';
17047 my @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old;
17048
1446117049=begin original
1446217050
1446317051Warning: syntactical care is required when sorting the list returned from
1446417052a function. If you want to sort the list returned by the function call
1446517053C<find_records(@key)>, you can use:
1446617054
1446717055=end original
1446817056
14469警告: 関数からかえされたリストをソートするときには文法上の注意が必要です。
17057警告: 関数からされたリストをソートするときには文法上の注意が必要です。
1447017058関数呼び出し C<find_records(@key)> から返されたリストをソートしたい場合、
1447117059以下のように出来ます:
1447217060
14473 @contact = sort { $a cmp $b } find_records @key;
17061 my @contact = sort { $a cmp $b } find_records @key;
14474 @contact = sort +find_records(@key);
17062 my @contact = sort +find_records(@key);
14475 @contact = sort &find_records(@key);
17063 my @contact = sort &find_records(@key);
14476 @contact = sort(find_records(@key));
17064 my @contact = sort(find_records(@key));
1447717065
1447817066=begin original
1447917067
14480If instead you want to sort the array @key with the comparison routine
17068If instead you want to sort the array C<@key> with the comparison routine
1448117069C<find_records()> then you can use:
1448217070
1448317071=end original
1448417072
14485一方、配列 @key を比較ルーチン C<find_records()> でソートしたい場合は、
17073一方、配列 C<@key> を比較ルーチン C<find_records()> でソートしたい場合は、
1448617074以下のように出来ます:
1448717075
14488 @contact = sort { find_records() } @key;
17076 my @contact = sort { find_records() } @key;
14489 @contact = sort find_records(@key);
17077 my @contact = sort find_records(@key);
14490 @contact = sort(find_records @key);
17078 my @contact = sort(find_records @key);
14491 @contact = sort(find_records (@key));
17079 my @contact = sort(find_records (@key));
1449217080
1449317081=begin original
1449417082
14495If you're using strict, you I<must not> declare $a
17083C<$a> and C<$b> are set as package globals in the package the sort() is
14496and $b as lexicals. They are package globals. That means
17084called from. That means C<$main::a> and C<$main::b> (or C<$::a> and
14497that if you're in the C<main> package and type
17085C<$::b>) in the C<main> package, C<$FooPack::a> and C<$FooPack::b> in the
17086C<FooPack> package, etc. If the sort block is in scope of a C<my> or
17087C<state> declaration of C<$a> and/or C<$b>, you I<must> spell out the full
17088name of the variables in the sort block :
1449817089
1449917090=end original
1450017091
14501use strict している場合、$a と $b をレキシカルとして
17092C<$a>C<$b> は、sort() 呼び出したパッケージのパッケージグローバルとして
14502宣言しては I<いけせん>
17093設定され
14503これはパッケージグローバルです。
17094つまり、C<main> パッケージの C<$main::a> と C<$main::b>
14504つまり、C<main> パッケージで以下のように書いた場合:
17095(あるいは C<$::a> と C<$::b>) 、
17096C<FooPack> パッケージの C<$FooPack::a> と C<$FooPack::b>、などです。
17097ソートブロックが C<$a> や C<$b> の C<my> または C<state> のスコープ内の場合、
17098ソートブロックの変数の完全名を I<指定しなければなりません>:
1450517099
14506 @articles = sort {$b <=> $a} @files;
17100 package main;
17101 my $a = "C"; # DANGER, Will Robinson, DANGER !!!
1450717102
17103 print sort { $a cmp $b } qw(A C E G B D F H);
17104 # WRONG
17105 sub badlexi { $a cmp $b }
17106 print sort badlexi qw(A C E G B D F H);
17107 # WRONG
17108 # the above prints BACFEDGH or some other incorrect ordering
17109
17110 print sort { $::a cmp $::b } qw(A C E G B D F H);
17111 # OK
17112 print sort { our $a cmp our $b } qw(A C E G B D F H);
17113 # also OK
17114 print sort { our ($a, $b); $a cmp $b } qw(A C E G B D F H);
17115 # also OK
17116 sub lexi { our $a cmp our $b }
17117 print sort lexi qw(A C E G B D F H);
17118 # also OK
17119 # the above print ABCDEFGH
17120
1450817121=begin original
1450917122
14510then C<$a> and C<$b> are C<$main::a> and C<$main::b> (or C<$::a> and C<$::b>),
17123With proper care you may mix package and my (or state) C<$a> and/or C<$b>:
14511but if you're in the C<FooPack> package, it's the same as typing
1451217124
1451317125=end original
1451417126
14515C<$a> C<$b>C<$main::a> C<$main::b> (または C<$::a> と C<$::b>)
17127適切に注意すれば、パッケージmy (あるいstate) C<$a> C<$b> を
14516意味しますが、C<FooPack> パッケージ内の場合、れは以下同じになります:
17128混ぜることができます:
1451717129
14518 @articles = sort {$FooPack::b <=> $FooPack::a} @files;
17130 my $a = {
17131 tiny => -2,
17132 small => -1,
17133 normal => 0,
17134 big => 1,
17135 huge => 2
17136 };
1451917137
17138 say sort { $a->{our $a} <=> $a->{our $b} }
17139 qw{ huge normal tiny small big};
17140
17141 # prints tinysmallnormalbighuge
17142
1452017143=begin original
1452117144
17145C<$a> and C<$b> are implicitly local to the sort() execution and regain their
17146former values upon completing the sort.
17147
17148=end original
17149
17150C<$a> と C<$b> は sort() の実行中は暗黙にローカル化され、ソート終了時に
17151元の値に戻ります。
17152
17153=begin original
17154
17155Sort subroutines written using C<$a> and C<$b> are bound to their calling
17156package. It is possible, but of limited interest, to define them in a
17157different package, since the subroutine must still refer to the calling
17158package's C<$a> and C<$b> :
17159
17160=end original
17161
17162C<$a> と C<$b> を使って書かれたソートサブルーチンはその呼び出しパッケージに
17163しなければなりません。
17164異なるパッケージに定義することは可能ですが、
17165これは可能ですが、限られた関心しかありません;
17166サブルーチンは呼び出しパッケージの C<$a> と C<$b> を
17167参照しなければならないからです:
17168
17169 package Foo;
17170 sub lexi { $Bar::a cmp $Bar::b }
17171 package Bar;
17172 ... sort Foo::lexi ...
17173
17174=begin original
17175
17176Use the prototyped versions (see above) for a more generic alternative.
17177
17178=end original
17179
17180より一般的な代替案としては(前述の)プロトタイプ版を使ってください。
17181
17182=begin original
17183
1452217184The comparison function is required to behave. If it returns
1452317185inconsistent results (sometimes saying C<$x[1]> is less than C<$x[2]> and
1452417186sometimes saying the opposite, for example) the results are not
1452517187well-defined.
1452617188
1452717189=end original
1452817190
1452917191比較関数は一貫した振る舞いをすることが求められます。
1453017192一貫しない結果を返す(例えば、あるときは C<$x[1]> が C<$x[2]> より
1453117193小さいと返し、またあるときは逆を返す)場合、結果は未定義です。
1453217194
1453317195=begin original
1453417196
14535Because C<< <=> >> returns C<undef> when either operand is C<NaN>
17197Because C<< <=> >> returns L<C<undef>|/undef EXPR> when either operand
14536(not-a-number), be careful when sorting with a
17198is C<NaN> (not-a-number), be careful when sorting with a
1453717199comparison function like C<< $a <=> $b >> any lists that might contain a
1453817200C<NaN>. The following example takes advantage that C<NaN != NaN> to
1453917201eliminate any C<NaN>s from the input list.
1454017202
1454117203=end original
1454217204
1454317205C<< <=> >> はどちらかのオペランドが C<NaN> (not-a-number) のときに
14544C<undef> を返すので、
17206L<C<undef>|/undef EXPR> を返すので、C<< $a <=> $b >> といった比較関数で
14545C<< $a <=> $b >> といった比較関数でソートする場合はリストに C<NaN> が
17207ソートする場合はリストに C<NaN> が含まれないように注意してください。
14546含まれないように注意してください。
1454717208以下の例は 入力リストから C<NaN> を取り除くために C<NaN != NaN> という性質を
1454817209利用しています。
1454917210
14550 @result = sort { $a <=> $b } grep { $_ == $_ } @input;
17211 my @result = sort { $a <=> $b } grep { $_ == $_ } @input;
1455117212
14552=item splice ARRAY or EXPR,OFFSET,LENGTH,LIST
17213=begin original
17214
17215In this version of F<perl>, the C<sort> function is implemented via the
17216mergesort algorithm.
17217
17218=end original
17219
17220このバージョンの F<perl> では、C<sort> 関数はマージソートアルゴリズムで
17221実装されています。
17222
17223=item splice ARRAY,OFFSET,LENGTH,LIST
1455317224X<splice>
1455417225
14555=item splice ARRAY or EXPR,OFFSET,LENGTH
17226=item splice ARRAY,OFFSET,LENGTH
1455617227
14557=item splice ARRAY or EXPR,OFFSET
17228=item splice ARRAY,OFFSET
1455817229
14559=item splice ARRAY or EXPR
17230=item splice ARRAY
1456017231
1456117232=for Pod::Functions add or remove elements anywhere in an array
1456217233
1456317234=begin original
1456417235
1456517236Removes the elements designated by OFFSET and LENGTH from an array, and
1456617237replaces them with the elements of LIST, if any. In list context,
1456717238returns the elements removed from the array. In scalar context,
14568returns the last element removed, or C<undef> if no elements are
17239returns the last element removed, or L<C<undef>|/undef EXPR> if no
17240elements are
1456917241removed. The array grows or shrinks as necessary.
1457017242If OFFSET is negative then it starts that far from the end of the array.
1457117243If LENGTH is omitted, removes everything from OFFSET onward.
1457217244If LENGTH is negative, removes the elements from OFFSET onward
1457317245except for -LENGTH elements at the end of the array.
1457417246If both OFFSET and LENGTH are omitted, removes everything. If OFFSET is
14575past the end of the array, Perl issues a warning, and splices at the
17247past the end of the array and a LENGTH was provided, Perl issues a warning,
14576end of the array.
17248and splices at the end of the array.
1457717249
1457817250=end original
1457917251
1458017252ARRAY から OFFSET、LENGTH で指定される要素を取り除き、
1458117253LIST があれば、それを代わりに挿入します。
1458217254リストコンテキストでは、配列から取り除かれた要素を返します。
1458317255スカラコンテキストでは、取り除かれた最後の要素を返します; 要素が
14584取り除かれなかった場合は C<undef> を返します。
17256取り除かれなかった場合は L<C<undef>|/undef EXPR> を返します。
1458517257配列は、必要に応じて、大きくなったり、小さくなったりします。
1458617258OFFSET が負の数の場合は、配列の最後からの距離を示します。
1458717259LENGTH が省略されると、OFFSET 以降のすべての要素を取り除きます。
1458817260LENGTH が負の数の場合は、OFFSET から前方へ、配列の最後から -LENGTH 要素を
1458917261除いて取り除きます。
1459017262OFFSET と LENGTH の両方が省略されると、全ての要素を取り除きます。
14591OFFSET が配列の最後より後ろの場合、Perl は警告を出し、配列の最後に対して
17263OFFSET が配列の最後より後ろ LENGTH が指定されていると、Perl は警告を出し、
14592処理します。
17264配列の最後に対して処理します。
1459317265
1459417266=begin original
1459517267
1459617268The following equivalences hold (assuming C<< $#a >= $i >> )
1459717269
1459817270=end original
1459917271
1460017272以下は、(C<< $#a >= $i >> と仮定すると) それぞれ、等価です。
1460117273
1460217274 push(@a,$x,$y) splice(@a,@a,0,$x,$y)
1460317275 pop(@a) splice(@a,-1)
1460417276 shift(@a) splice(@a,0,1)
1460517277 unshift(@a,$x,$y) splice(@a,0,0,$x,$y)
1460617278 $a[$i] = $y splice(@a,$i,1,$y)
1460717279
1460817280=begin original
1460917281
14610Example, assuming array lengths are passed before arrays:
17282L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> can be used, for example,
17283to implement n-ary queue processing:
1461117284
1461217285=end original
1461317286
14614次の例では、配列の前にそれぞれ配列の大きさが渡されるものとしています:
17287L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> は、例えばn-ary キュー処理
17288実装に使えます:
1461517289
14616 sub aeq { # compare two list values
17290 sub nary_print {
14617 my(@a) = splice(@_,0,shift);
17291 my $n = shift;
14618 my(@b) = splice(@_,0,shift);
17292 while (my @next_n = splice @_, 0, $n) {
14619 return 0 unless @a == @b; # same len?
17293 say join q{ -- }, @next_n;
14620 while (@a) {
17294 }
14621 return 0 if pop(@a) ne pop(@b);
14622 }
14623 return 1;
1462417295 }
14625 if (&aeq($len,@foo[1..$len],0+@bar,@bar)) { ... }
1462617296
14627=begin original
17297 nary_print(3, qw(a b c d e f g h));
17298 # prints:
17299 # a -- b -- c
17300 # d -- e -- f
17301 # g -- h
1462817302
14629Starting with Perl 5.14, C<splice> can take scalar EXPR, which must hold a
14630reference to an unblessed array. The argument will be dereferenced
14631automatically. This aspect of C<splice> is considered highly experimental.
14632The exact behaviour may change in a future version of Perl.
14633
14634=end original
14635
14636Perl 5.14 から、C<splice> はスカラの EXPR を取ることができるようになりました;
14637これは bless されていない配列へのリファレンスでなければなりません。
14638引数は自動的にデリファレンスされます。
14639C<splice> のこの動作は高度に実験的であると考えられています。
14640正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
14641
1464217303=begin original
1464317304
14644To avoid confusing would-be users of your code who are running earlier
17305Starting with Perl 5.14, an experimental feature allowed
14645versions of Perl with mysterious syntax errors, put this sort of thing at
17306L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> to take a
14646the top of your file to signal that your code will work I<only> on Perls of
17307scalar expression. This experiment has been deemed unsuccessful, and was
14647a recent vintage:
17308removed as of Perl 5.24.
1464817309
1464917310=end original
1465017311
14651あなたのコードを以前のバージョンの Perl で実行したユーザー不思議な
17312Perl 5.14 から、L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> スカラ式を
14652文法エラーで混乱することを避けために、コード最近のバージョンの Perl で
17313ることが出来という実験的機能ありました。
14653I<のみ> 動作するとを示すためにファイル先頭に以下のようなこ
17314この実験は失敗見なされ、Perl 5.24 で削除されました。
14654書いてください:
1465517315
14656 use 5.014; # so push/pop/etc work on scalars (experimental)
14657
1465817316=item split /PATTERN/,EXPR,LIMIT
1465917317X<split>
1466017318
1466117319=item split /PATTERN/,EXPR
1466217320
1466317321=item split /PATTERN/
1466417322
1466517323=item split
1466617324
1466717325=for Pod::Functions split up a string using a regexp delimiter
1466817326
1466917327=begin original
1467017328
1467117329Splits the string EXPR into a list of strings and returns the
1467217330list in list context, or the size of the list in scalar context.
17331(Prior to Perl 5.11, it also overwrote C<@_> with the list in
17332void and scalar context. If you target old perls, beware.)
1467317333
1467417334=end original
1467517335
1467617336文字列 EXPR を文字列のリストに分割して、リストコンテキストではそのリストを
1467717337返し、スカラコンテキストではリストの大きさを返します。
17338(Perl 5.11 以前では、無効コンテキストやスカラコンテキストの場合は
17339C<@_> をリストで上書きします。
17340もし古い perl を対象にするなら、注意してください。)
1467817341
1467917342=begin original
1468017343
14681If only PATTERN is given, EXPR defaults to C<$_>.
17344If only PATTERN is given, EXPR defaults to L<C<$_>|perlvar/$_>.
1468217345
1468317346=end original
1468417347
14685PATTERN のみが与えられた場合、EXPR のデフォルトは C<$_> です。
17348PATTERN のみが与えられた場合、EXPR のデフォルトは L<C<$_>|perlvar/$_> です。
1468617349
1468717350=begin original
1468817351
1468917352Anything in EXPR that matches PATTERN is taken to be a separator
1469017353that separates the EXPR into substrings (called "I<fields>") that
1469117354do B<not> include the separator. Note that a separator may be
1469217355longer than one character or even have no characters at all (the
1469317356empty string, which is a zero-width match).
1469417357
1469517358=end original
1469617359
1469717360EXPR の中で PATTERN にマッチングするものは何でも EXPR を("I<fields>" と
1469817361呼ばれる)セパレータを B<含まない> 部分文字列に分割するための
1469917362セパレータとなります。
1470017363セパレータは一文字より長くてもよく、全く文字がなくてもよい(空文字列は
1470117364ゼロ幅マッチングです)ということに注意してください。
1470217365
1470317366=begin original
1470417367
1470517368The PATTERN need not be constant; an expression may be used
1470617369to specify a pattern that varies at runtime.
1470717370
1470817371=end original
1470917372
1471017373PATTERN は定数である必要はありません; 実行時に変更されるパターンを
1471117374指定するために式を使えます。
1471217375
1471317376=begin original
1471417377
1471517378If PATTERN matches the empty string, the EXPR is split at the match
1471617379position (between characters). As an example, the following:
1471717380
1471817381=end original
1471917382
1472017383PATTERN が空文字列にマッチングする場合、EXPR はマッチング位置
1472117384(文字の間)で分割されます。
1472217385例えば、以下のものは:
1472317386
14724 print join(':', split('b', 'abc')), "\n";
17387 my @x = split(/b/, "abc"); # ("a", "c")
1472517388
1472617389=begin original
1472717390
14728uses the 'b' in 'abc' as a separator to produce the output 'a:c'.
17391uses the C<b> in C<'abc'> as a separator to produce the list ("a", "c").
1472917392However, this:
1473017393
1473117394=end original
1473217395
14733'abc' の 'b' をセパレータとして使って出力 'a:c' を生成します。
17396C<'abc'>C<b> をセパレータとして使ってリスト ("a", "c") を生成します。
1473417397しかし、これは:
1473517398
14736 print join(':', split('', 'abc')), "\n";
17399 my @x = split(//, "abc"); # ("a", "b", "c")
1473717400
1473817401=begin original
1473917402
14740uses empty string matches as separators to produce the output
17403uses empty string matches as separators; thus, the empty string
14741'a:b:c'; thus, the empty string may be used to split EXPR into a
17404may be used to split EXPR into a list of its component characters.
14742list of its component characters.
1474317405
1474417406=end original
1474517407
14746空文字列マッチングをセパレータとして使って出力 'a:b:c' を生成します; 従って、
17408空文字列マッチングをセパレータとして使ます; 従って、
1474717409空文字列は EXPR を構成する文字のリストに分割するために使われます。
1474817410
1474917411=begin original
1475017412
14751As a special case for C<split>, the empty pattern given in
17413As a special case for L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>,
14752L<match operator|perlop/"m/PATTERN/msixpodualgc"> syntax (C<//>) specifically matches the empty string, which is contrary to its usual
17414the empty pattern given in
17415L<match operator|perlop/"m/PATTERN/msixpodualngc"> syntax (C<//>)
17416specifically matches the empty string, which is contrary to its usual
1475317417interpretation as the last successful match.
1475417418
1475517419=end original
1475617420
14757C<split> の特殊な場合として、
17421L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> の特殊な場合として、
14758L<マッチング演算子|perlop/"m/PATTERN/msixpodualgc"> 文法で与えられた
17422L<マッチング演算子|perlop/"m/PATTERN/msixpodualngc"> 文法で与えられた
1475917423空パターン (C<//>) は特に空文字列にマッチングし、最後に成功した
1476017424マッチングという普通の解釈と異なります。
1476117425
1476217426=begin original
1476317427
1476417428If PATTERN is C</^/>, then it is treated as if it used the
1476517429L<multiline modifier|perlreref/OPERATORS> (C</^/m>), since it
1476617430isn't much use otherwise.
1476717431
1476817432=end original
1476917433
1477017434PATTERN が C</^/> の場合、L<複数行修飾子|perlreref/OPERATORS>
1477117435(C</^/m>) が使われたかのように扱われます; そうでなければほとんど
1477217436使えないからです。
1477317437
1477417438=begin original
1477517439
14776As another special case, C<split> emulates the default behavior of the
17440C<E<sol>m> and any of the other pattern modifiers valid for C<qr>
14777command line tool B<awk> when the PATTERN is either omitted or a I<literal
17441(summarized in L<perlop/qrE<sol>STRINGE<sol>msixpodualn>) may be
14778string> composed of a single space character (such as S<C<' '>> or
17442specified explicitly.
17443
17444=end original
17445
17446C<qr> で有効な C<E<sol>m> 及びその他のパターン修飾子
17447(L<perlop/qrE<sol>STRINGE<sol>msixpodualn> にまとめられています) は
17448明示的に定義されます。
17449
17450=begin original
17451
17452As another special case,
17453L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> emulates the default
17454behavior of the
17455command line tool B<awk> when the PATTERN is either omitted or a
17456string composed of a single space character (such as S<C<' '>> or
1477917457S<C<"\x20">>, but not e.g. S<C</ />>). In this case, any leading
1478017458whitespace in EXPR is removed before splitting occurs, and the PATTERN is
1478117459instead treated as if it were C</\s+/>; in particular, this means that
1478217460I<any> contiguous whitespace (not just a single space character) is used as
14783a separator. However, this special treatment can be avoided by specifying
17461a separator.
14784the pattern S<C</ />> instead of the string S<C<" ">>, thereby allowing
14785only a single space character to be a separator. In earlier Perl's this
14786special case was restricted to the use of a plain S<C<" ">> as the
14787pattern argument to split, in Perl 5.18.0 and later this special case is
14788triggered by any expression which evaluates as the simple string S<C<" ">>.
1478917462
1479017463=end original
1479117464
14792もう一つの特別な場合として、C<split> は PATTERN が省略されるか
17465もう一つの特別な場合として、
14793単一のスペース文字からなる I<リテラル文字列> (つまり例えば
17466L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>
17467PATTERN が省略されるか単一のスペース文字からなる文字列 (つまり例えば
1479417468S<C</ />> ではなく S<C<' '>> や S<C<"\x20">>) の場合、コマンドラインツール
1479517469B<awk> のデフォルトの振る舞いをエミュレートします。
1479617470この場合、EXPR の先頭の空白は分割を行う前に削除され、PATTERN は
1479717471C</\s+/> であったかのように扱われます; 特に、これは (単に単一の
1479817472スペース文字ではなく) I<あらゆる> 連続した空白がセパレータとして
1479917473使われるということです。
17474
17475 my @x = split(" ", " Quick brown fox\n");
17476 # ("Quick", "brown", "fox")
17477
17478 my @x = split(" ", "RED\tGREEN\tBLUE");
17479 # ("RED", "GREEN", "BLUE")
17480
17481=begin original
17482
17483Using split in this fashion is very similar to how
17484L<C<qwE<sol>E<sol>>|/qwE<sol>STRINGE<sol>> works.
17485
17486=end original
17487
17488この方法で split を使うのは、
17489L<C<qwE<sol>E<sol>>|/qwE<sol>STRINGE<sol>> の動作と非常に似ています。
17490
17491=begin original
17492
17493However, this special treatment can be avoided by specifying
17494the pattern S<C</ />> instead of the string S<C<" ">>, thereby allowing
17495only a single space character to be a separator. In earlier Perls this
17496special case was restricted to the use of a plain S<C<" ">> as the
17497pattern argument to split; in Perl 5.18.0 and later this special case is
17498triggered by any expression which evaluates to the simple string S<C<" ">>.
17499
17500=end original
17501
1480017502しかし、この特別の扱いは文字列 S<C<" ">> の代わりにパターン S<C</ />> を
1480117503指定することで回避でき、それによってセパレータとして単一の
1480217504スペース文字のみが使われます。
1480317505以前の Perl ではこの特別な場合は split のパターン引数として単に S<C<" ">> を
14804使った場合に制限されていましたが、Perl 5.18.0 以降では、この特別な場合は
17506使った場合に制限されていました; Perl 5.18.0 以降では、この特別な場合は
14805単純な文字列 S<C<" ">> 評価される任意の式によって引き起こされます。
17507単純な文字列 S<C<" ">> 評価される任意の式によって引き起こされます。
1480617508
1480717509=begin original
1480817510
17511As of Perl 5.28, this special-cased whitespace splitting works as expected in
17512the scope of L<< S<C<"use feature 'unicode_strings'">>|feature/The
17513'unicode_strings' feature >>. In previous versions, and outside the scope of
17514that feature, it exhibits L<perlunicode/The "Unicode Bug">: characters that are
17515whitespace according to Unicode rules but not according to ASCII rules can be
17516treated as part of fields rather than as field separators, depending on the
17517string's internal encoding.
17518
17519=end original
17520
17521Perl 5.28 から、この特別な場合の空白分割は
17522L<< S<C<"use feature 'unicode_strings'">>|feature/The
17523'unicode_strings' feature >> のスコープの中では想定通りに動作します。
17524以前のバージョンでは、そしてこの機能のスコープの外側では、
17525これは L<perlunicode/The "Unicode Bug"> を引き起こします:
17526Unicode によれば空白だけれども ASCII の規則ではそうではない文字は、
17527文字列の内部エンコーディングに依存して、
17528フィールドの区切りではなくフィールドの一部として扱われることがあります。
17529
17530=begin original
17531
1480917532If omitted, PATTERN defaults to a single space, S<C<" ">>, triggering
1481017533the previously described I<awk> emulation.
1481117534
1481217535=end original
1481317536
1481417537省略されると、PATTERN のデフォルトは単一のスペース S<C<" ">> になり、
1481517538先に記述した I<awk> エミュレーションを起動します。
1481617539
1481717540=begin original
1481817541
1481917542If LIMIT is specified and positive, it represents the maximum number
1482017543of fields into which the EXPR may be split; in other words, LIMIT is
1482117544one greater than the maximum number of times EXPR may be split. Thus,
1482217545the LIMIT value C<1> means that EXPR may be split a maximum of zero
1482317546times, producing a maximum of one field (namely, the entire value of
1482417547EXPR). For instance:
1482517548
1482617549=end original
1482717550
1482817551LIMIT が指定された正数の場合、EXPR が分割されるフィールドの最大数を
14829表現します; 言い換えると、 LIMIT は EXPR が分割される数より一つ大きい
17552表現します; 言い換えると、 LIMIT は EXPR が分割される数より一つ大きい数です。
14830数です。
1483117553従って、LIMIT の値 C<1> は EXPR が最大 0 回分割されるということで、
1483217554最大で一つのフィールドを生成します (言い換えると、EXPR 全体の値です)。
1483317555例えば:
1483417556
14835 print join(':', split(//, 'abc', 1)), "\n";
17557 my @x = split(//, "abc", 1); # ("abc")
17558 my @x = split(//, "abc", 2); # ("a", "bc")
17559 my @x = split(//, "abc", 3); # ("a", "b", "c")
17560 my @x = split(//, "abc", 4); # ("a", "b", "c")
1483617561
1483717562=begin original
1483817563
14839produces the output 'abc', and this:
14840
14841=end original
14842
14843これは 'abc' を出力し、次のものは:
14844
14845 print join(':', split(//, 'abc', 2)), "\n";
14846
14847=begin original
14848
14849produces the output 'a:bc', and each of these:
14850
14851=end original
14852
14853'a:bc' を出力し、以下のものそれぞれは:
14854
14855 print join(':', split(//, 'abc', 3)), "\n";
14856 print join(':', split(//, 'abc', 4)), "\n";
14857
14858=begin original
14859
14860produces the output 'a:b:c'.
14861
14862=end original
14863
14864'a:b:c' を出力します。
14865
14866=begin original
14867
1486817564If LIMIT is negative, it is treated as if it were instead arbitrarily
1486917565large; as many fields as possible are produced.
1487017566
1487117567=end original
1487217568
1487317569LIMIT が負数なら、非常に大きい数であるかのように扱われます; できるだけ多くの
1487417570フィールドが生成されます。
1487517571
1487617572=begin original
1487717573
1487817574If LIMIT is omitted (or, equivalently, zero), then it is usually
1487917575treated as if it were instead negative but with the exception that
1488017576trailing empty fields are stripped (empty leading fields are always
1488117577preserved); if all fields are empty, then all fields are considered to
1488217578be trailing (and are thus stripped in this case). Thus, the following:
1488317579
1488417580=end original
1488517581
1488617582LIMIT が省略されると(あるいは等価な 0 なら)、普通は負数が指定されたかのように
1488717583動作しますが、末尾の空フィールドは取り除かれるという例外があります
1488817584(先頭の空フィールドは常に保存されます); もし全てのフィールドが空なら、
1488917585全てのフィールドが末尾として扱われます(そしてこの場合取り除かれます)。
1489017586従って、以下のようにすると:
1489117587
14892 print join(':', split(',', 'a,b,c,,,')), "\n";
17588 my @x = split(/,/, "a,b,c,,,"); # ("a", "b", "c")
1489317589
1489417590=begin original
1489517591
14896produces the output 'a:b:c', but the following:
17592produces only a three element list.
1489717593
1489817594=end original
1489917595
14900出力 'a:b:c' を生成しますが、以下のようにすると:
175963 要素だけのリストを生成します
1490117597
14902 print join(':', split(',', 'a,b,c,,,', -1)), "\n";
17598 my @x = split(/,/, "a,b,c,,,", -1); # ("a", "b", "c", "", "", "")
1490317599
1490417600=begin original
1490517601
14906produces the output 'a:b:c:::'.
17602produces a six element list.
1490717603
1490817604=end original
1490917605
14910出力 'a:b:c:::' を生成します。
176066 要素のリストを生成します。
1491117607
1491217608=begin original
1491317609
1491417610In time-critical applications, it is worthwhile to avoid splitting
1491517611into more fields than necessary. Thus, when assigning to a list,
1491617612if LIMIT is omitted (or zero), then LIMIT is treated as though it
1491717613were one larger than the number of variables in the list; for the
1491817614following, LIMIT is implicitly 3:
1491917615
1492017616=end original
1492117617
1492217618時間に厳しいアプリケーションでは、必要でないフィールドの分割を避けるのは
1492317619価値があります。
1492417620従って、リストに代入される場合に、LIMIT が省略される(または 0)と、
1492517621LIMIT は リストにある変数の数より一つ大きい数のように扱われます;
1492617622次の場合、LIMIT は暗黙に 3 になります:
1492717623
14928 ($login, $passwd) = split(/:/);
17624 my ($login, $passwd) = split(/:/);
1492917625
1493017626=begin original
1493117627
1493217628Note that splitting an EXPR that evaluates to the empty string always
1493317629produces zero fields, regardless of the LIMIT specified.
1493417630
1493517631=end original
1493617632
1493717633LIMIT の指定に関わらず、空文字列に評価される EXPR を分割すると常に 0 個の
1493817634フィールドを生成することに注意してください。
1493917635
1494017636=begin original
1494117637
1494217638An empty leading field is produced when there is a positive-width
1494317639match at the beginning of EXPR. For instance:
1494417640
1494517641=end original
1494617642
1494717643EXPR の先頭で正数幅でマッチングしたときには先頭に空のフィールドが
1494817644生成されます。
1494917645例えば:
1495017646
14951 print join(':', split(/ /, ' abc')), "\n";
17647 my @x = split(/ /, " abc"); # ("", "abc")
1495217648
1495317649=begin original
1495417650
14955produces the output ':abc'. However, a zero-width match at the
17651splits into two elements. However, a zero-width match at the
1495617652beginning of EXPR never produces an empty field, so that:
1495717653
1495817654=end original
1495917655
14960これは出力 ':abc' を生成します。
17656これは 2 要素に分割します。
1496117657しかし、EXPR の先頭でのゼロ幅マッチングは決して空フィールドを生成しないので:
1496217658
14963 print join(':', split(//, ' abc'));
17659 my @x = split(//, " abc"); # (" ", "a", "b", "c")
1496417660
1496517661=begin original
1496617662
14967produces the output S<' :a:b:c'> (rather than S<': :a:b:c'>).
17663splits into four elements instead of five.
1496817664
1496917665=end original
1497017666
14971これは(S<': :a:b:c'> ではなく)出力 S<' :a:b:c'> を生成します。
17667これは 5 要素ではなく 4 要素に分割します。
1497217668
1497317669=begin original
1497417670
1497517671An empty trailing field, on the other hand, is produced when there is a
1497617672match at the end of EXPR, regardless of the length of the match
1497717673(of course, unless a non-zero LIMIT is given explicitly, such fields are
1497817674removed, as in the last example). Thus:
1497917675
1498017676=end original
1498117677
1498217678一方、末尾の空のフィールドは、マッチングの長さに関わらず、EXPR の末尾で
1498317679マッチングしたときに生成されます(もちろん非 0 の LIMIT が明示的に
1498417680指定されていない場合です; このようなフィールドは前の例のように
1498517681取り除かれます)。
1498617682従って:
1498717683
14988 print join(':', split(//, ' abc', -1)), "\n";
17684 my @x = split(//, " abc", -1); # (" ", "a", "b", "c", "")
1498917685
1499017686=begin original
1499117687
14992produces the output S<' :a:b:c:'>.
14993
14994=end original
14995
14996これは出力 S<' :a:b:c:'> を生成します。
14997
14998=begin original
14999
1500017688If the PATTERN contains
1500117689L<capturing groups|perlretut/Grouping things and hierarchical matching>,
1500217690then for each separator, an additional field is produced for each substring
1500317691captured by a group (in the order in which the groups are specified,
1500417692as per L<backreferences|perlretut/Backreferences>); if any group does not
15005match, then it captures the C<undef> value instead of a substring. Also,
17693match, then it captures the L<C<undef>|/undef EXPR> value instead of a
17694substring. Also,
1500617695note that any such additional field is produced whenever there is a
1500717696separator (that is, whenever a split occurs), and such an additional field
1500817697does B<not> count towards the LIMIT. Consider the following expressions
1500917698evaluated in list context (each returned list is provided in the associated
1501017699comment):
1501117700
1501217701=end original
1501317702
1501417703PATTERN が
1501517704L<捕捉グループ|perlretut/Grouping things and hierarchical matching> を
1501617705含んでいる場合、それぞれのセパレータについて、
1501717706(L<後方参照|perlretut/Backreferences> のようにグループが指定された)
1501817707グループによって捕捉されたそれぞれの部分文字列について追加のフィールドが
1501917708生成されます; どのグループもマッチングしなかった場合、部分文字列の代わりに
15020C<undef> 値を捕捉します。
17709L<C<undef>|/undef EXPR> 値を捕捉します。
1502117710また、このような追加のフィールドはセパレータがあるとき(つまり、分割が
1502217711行われるとき)はいつでも生成され、このような追加のフィールドは
1502317712LIMIT に関してはカウント B<されない> ことに注意してください。
1502417713リストコンテキストで評価される以下のような式を考えます
1502517714(それぞれの返されるリストは関連づけられたコメントで提供されます):
1502617715
15027 split(/-|,/, "1-10,20", 3)
17716 my @x = split(/-|,/ , "1-10,20", 3);
15028 # ('1', '10', '20')
17717 # ("1", "10", "20")
1502917718
15030 split(/(-|,)/, "1-10,20", 3)
17719 my @x = split(/(-|,)/ , "1-10,20", 3);
15031 # ('1', '-', '10', ',', '20')
17720 # ("1", "-", "10", ",", "20")
1503217721
15033 split(/-|(,)/, "1-10,20", 3)
17722 my @x = split(/-|(,)/ , "1-10,20", 3);
15034 # ('1', undef, '10', ',', '20')
17723 # ("1", undef, "10", ",", "20")
1503517724
15036 split(/(-)|,/, "1-10,20", 3)
17725 my @x = split(/(-)|,/ , "1-10,20", 3);
15037 # ('1', '-', '10', undef, '20')
17726 # ("1", "-", "10", undef, "20")
1503817727
15039 split(/(-)|(,)/, "1-10,20", 3)
17728 my @x = split(/(-)|(,)/, "1-10,20", 3);
15040 # ('1', '-', undef, '10', undef, ',', '20')
17729 # ("1", "-", undef, "10", undef, ",", "20")
1504117730
1504217731=item sprintf FORMAT, LIST
1504317732X<sprintf>
1504417733
1504517734=for Pod::Functions formatted print into a string
1504617735
1504717736=begin original
1504817737
15049Returns a string formatted by the usual C<printf> conventions of the C
17738Returns a string formatted by the usual
15050library function C<sprintf>. See below for more details
17739L<C<printf>|/printf FILEHANDLE FORMAT, LIST> conventions of the C
15051and see L<sprintf(3)> or L<printf(3)> on your system for an explanation of
17740library function L<C<sprintf>|/sprintf FORMAT, LIST>. See below for
15052the general principles.
17741more details and see L<sprintf(3)> or L<printf(3)> on your system for an
17742explanation of the general principles.
1505317743
1505417744=end original
1505517745
15056普通の C 言語の C<printf> 記法フォーマットで、整形された文字列を返します。
17746C ライブラリ関数 L<C<sprintf>|/sprintf FORMAT, LIST>
17747普通の L<C<printf>|/printf FILEHANDLE FORMAT, LIST> 記法の
17748整形された文字列を返します。
1505717749一般的な原則の説明については以下の説明と、システムの
1505817750L<sprintf(3)> または L<printf(3)> の説明を参照してください。
1505917751
1506017752=begin original
1506117753
1506217754For example:
1506317755
1506417756=end original
1506517757
1506617758例えば:
1506717759
1506817760 # Format number with up to 8 leading zeroes
15069 $result = sprintf("%08d", $number);
17761 my $result = sprintf("%08d", $number);
1507017762
1507117763 # Round number to 3 digits after decimal point
15072 $rounded = sprintf("%.3f", $number);
17764 my $rounded = sprintf("%.3f", $number);
1507317765
1507417766=begin original
1507517767
15076Perl does its own C<sprintf> formatting: it emulates the C
17768Perl does its own L<C<sprintf>|/sprintf FORMAT, LIST> formatting: it
15077function sprintf(3), but doesn't use it except for floating-point
17769emulates the C
15078numbers, and even then only standard modifiers are allowed.
17770function L<sprintf(3)>, but doesn't use it except for floating-point
15079Non-standard extensions in your local sprintf(3) are
17771numbers, and even then only standard modifiers are allowed.
17772Non-standard extensions in your local L<sprintf(3)> are
1508017773therefore unavailable from Perl.
1508117774
1508217775=end original
1508317776
15084Perl は C<sprintf> フォーマット処理を自力で行います:
17777Perl は L<C<sprintf>|/sprintf FORMAT, LIST> フォーマット処理を自力で行います:
15085これは C の sprintf(3) 関数をエミュレートしますが、
17778これは C の L<sprintf(3)> 関数をエミュレートしますが、C の関数は使いません
15086C の関数は使いません(浮動小数点を除きますが、それでも標準の
17779(浮動小数点を除きますが、それでも標準の記述子のみが利用できます)。
15087記述子みが利用す)
17780従って、ローカルな非標準 L<sprintf(3)> 拡張機能は Perl は使えせん
15088従って、ローカルな非標準の C<sprintf> 拡張機能は Perl では使えません。
1508917781
1509017782=begin original
1509117783
15092Unlike C<printf>, C<sprintf> does not do what you probably mean when you
17784Unlike L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
15093pass it an array as your first argument.
17785L<C<sprintf>|/sprintf FORMAT, LIST> does not do what you probably mean
17786when you pass it an array as your first argument.
1509417787The array is given scalar context,
1509517788and instead of using the 0th element of the array as the format, Perl will
1509617789use the count of elements in the array as the format, which is almost never
1509717790useful.
1509817791
1509917792=end original
1510017793
15101C<printf> と違って、 C<sprintf> の最初の引数に配列を渡し
17794L<C<printf>|/printf FILEHANDLE FORMAT, LIST> と違っ
17795L<C<sprintf>|/sprintf FORMAT, LIST> の最初の引数に配列を渡しても
1510217796あなたが多分望むとおりには動作しません。
1510317797配列はスカラコンテキストで渡されるので、配列の 0 番目の要素ではなく、
1510417798配列の要素数をフォーマットとして扱います; これはほとんど役に立ちません。
1510517799
1510617800=begin original
1510717801
15108Perl's C<sprintf> permits the following universally-known conversions:
17802Perl's L<C<sprintf>|/sprintf FORMAT, LIST> permits the following
17803universally-known conversions:
1510917804
1511017805=end original
1511117806
15112Perl の C<sprintf> は以下の一般に知られている変換に対応しています:
17807Perl の L<C<sprintf>|/sprintf FORMAT, LIST> は以下の一般に知られている変換に
17808対応しています:
1511317809
1511417810=begin original
1511517811
1511617812 %% a percent sign
1511717813 %c a character with the given number
1511817814 %s a string
1511917815 %d a signed integer, in decimal
1512017816 %u an unsigned integer, in decimal
1512117817 %o an unsigned integer, in octal
1512217818 %x an unsigned integer, in hexadecimal
1512317819 %e a floating-point number, in scientific notation
1512417820 %f a floating-point number, in fixed decimal notation
1512517821 %g a floating-point number, in %e or %f notation
1512617822
1512717823=end original
1512817824
1512917825 %% パーセントマーク
1513017826 %c 与えられた番号の文字
1513117827 %s 文字列
1513217828 %d 符号付き 10 進数
1513317829 %u 符号なし 10 進数
1513417830 %o 符号なし 8 進数
1513517831 %x 符号なし 16 進数
1513617832 %e 科学的表記の浮動小数点数
1513717833 %f 固定 10 進数表記の浮動小数点数
1513817834 %g %e か %f の表記の浮動小数点数
1513917835
1514017836=begin original
1514117837
1514217838In addition, Perl permits the following widely-supported conversions:
1514317839
1514417840=end original
1514517841
1514617842さらに、Perl では以下のよく使われている変換に対応しています:
1514717843
1514817844=begin original
1514917845
1515017846 %X like %x, but using upper-case letters
1515117847 %E like %e, but using an upper-case "E"
1515217848 %G like %g, but with an upper-case "E" (if applicable)
1515317849 %b an unsigned integer, in binary
1515417850 %B like %b, but using an upper-case "B" with the # flag
1515517851 %p a pointer (outputs the Perl value's address in hexadecimal)
1515617852 %n special: *stores* the number of characters output so far
1515717853 into the next argument in the parameter list
17854 %a hexadecimal floating point
17855 %A like %a, but using upper-case letters
1515817856
1515917857=end original
1516017858
1516117859 %X %x と同様だが大文字を使う
1516217860 %E %e と同様だが大文字の "E" を使う
1516317861 %G %g と同様だが(適切なら)大文字の "E" を使う
1516417862 %b 符号なし 2 進数
1516517863 %B %b と同様だが、# フラグで大文字の "B" を使う
1516617864 %p ポインタ (Perl の値のアドレスを 16 進数で出力する)
1516717865 %n 特殊: 出力文字数を引数リストの次の変数に「格納」する
17866 %a 16 進浮動小数点
17867 %A %a と同様だが、大文字を使う
1516817868
1516917869=begin original
1517017870
1517117871Finally, for backward (and we do mean "backward") compatibility, Perl
1517217872permits these unnecessary but widely-supported conversions:
1517317873
1517417874=end original
1517517875
1517617876最後に、過去との互換性(これは「過去」だと考えています)のために、
1517717877Perl は以下の不要ではあるけれども広く使われている変換に対応しています。
1517817878
1517917879=begin original
1518017880
1518117881 %i a synonym for %d
1518217882 %D a synonym for %ld
1518317883 %U a synonym for %lu
1518417884 %O a synonym for %lo
1518517885 %F a synonym for %f
1518617886
1518717887=end original
1518817888
1518917889 %i %d の同義語
1519017890 %D %ld の同義語
1519117891 %U %lu の同義語
1519217892 %O %lo の同義語
1519317893 %F %f の同義語
1519417894
1519517895=begin original
1519617896
1519717897Note that the number of exponent digits in the scientific notation produced
1519817898by C<%e>, C<%E>, C<%g> and C<%G> for numbers with the modulus of the
1519917899exponent less than 100 is system-dependent: it may be three or less
1520017900(zero-padded as necessary). In other words, 1.23 times ten to the
1520199th may be either "1.23e99" or "1.23e099".
1790199th may be either "1.23e99" or "1.23e099". Similarly for C<%a> and C<%A>:
17902the exponent or the hexadecimal digits may float: especially the
17903"long doubles" Perl configuration option may cause surprises.
1520217904
1520317905=end original
1520417906
1520517907C<%e>, C<%E>, C<%g>, C<%G> において、指数部が 100 未満の場合の
1520617908指数部の科学的な表記法はシステム依存であることに注意してください:
15207179093 桁かもしれませんし、それ以下かもしれません(必要に応じて 0 で
1520817910パッディングされます)。
1520917911言い換えると、 1.23 掛ける 10 の 99 乗は "1.23e99" かもしれませんし
1521017912"1.23e099" かもしれません。
17913同様に C<%a> と C<%A> の場合:
17914指数部と 16 進数が浮動小数点かもしれません:
17915特に "long doubles" Perl 設定オプションが驚きを引き起こすかもしれません。
1521117916
1521217917=begin original
1521317918
1521417919Between the C<%> and the format letter, you may specify several
1521517920additional attributes controlling the interpretation of the format.
1521617921In order, these are:
1521717922
1521817923=end original
1521917924
1522017925C<%> とフォーマット文字の間に、フォーマットの解釈を制御するための、
1522117926いくつかの追加の属性を指定できます。
1522217927順番に、以下のものがあります:
1522317928
1522417929=over 4
1522517930
1522617931=item format parameter index
1522717932
1522817933(フォーマットパラメータインデックス)
1522917934
1523017935=begin original
1523117936
1523217937An explicit format parameter index, such as C<2$>. By default sprintf
1523317938will format the next unused argument in the list, but this allows you
1523417939to take the arguments out of order:
1523517940
1523617941=end original
1523717942
1523817943C<2$> のような明示的なフォーマットパラメータインデックス。
1523917944デフォルトでは sprintf はリストの次の使われていない引数を
1524017945フォーマットしますが、これによって異なった順番の引数を使えるようにします:
1524117946
1524217947 printf '%2$d %1$d', 12, 34; # prints "34 12"
1524317948 printf '%3$d %d %1$d', 1, 2, 3; # prints "3 1 1"
1524417949
1524517950=item flags
1524617951
1524717952(フラグ)
1524817953
1524917954=begin original
1525017955
1525117956one or more of:
1525217957
1525317958=end original
1525417959
1525517960以下のうちの一つまたは複数指定できます:
1525617961
1525717962=begin original
1525817963
1525917964 space prefix non-negative number with a space
1526017965 + prefix non-negative number with a plus sign
1526117966 - left-justify within the field
1526217967 0 use zeros, not spaces, to right-justify
1526317968 # ensure the leading "0" for any octal,
1526417969 prefix non-zero hexadecimal with "0x" or "0X",
1526517970 prefix non-zero binary with "0b" or "0B"
1526617971
1526717972=end original
1526817973
1526917974 space 非負数の前に空白をつける
1527017975 + 非負数の前にプラス記号をつける
1527117976 - フィールド内で左詰めする
1527217977 0 右詰めに空白ではなくゼロを使う
1527317978 # 8 進数では確実に先頭に "0" をつける;
1527417979 非 0 の 16 進数では "0x" か "0X" をつける;
1527517980 非 0 の 2 進数では "0b" か "0B" をつける
1527617981
1527717982=begin original
1527817983
1527917984For example:
1528017985
1528117986=end original
1528217987
1528317988例えば:
1528417989
1528517990 printf '<% d>', 12; # prints "< 12>"
17991 printf '<% d>', 0; # prints "< 0>"
17992 printf '<% d>', -12; # prints "<-12>"
1528617993 printf '<%+d>', 12; # prints "<+12>"
17994 printf '<%+d>', 0; # prints "<+0>"
17995 printf '<%+d>', -12; # prints "<-12>"
1528717996 printf '<%6s>', 12; # prints "< 12>"
1528817997 printf '<%-6s>', 12; # prints "<12 >"
1528917998 printf '<%06s>', 12; # prints "<000012>"
1529017999 printf '<%#o>', 12; # prints "<014>"
1529118000 printf '<%#x>', 12; # prints "<0xc>"
1529218001 printf '<%#X>', 12; # prints "<0XC>"
1529318002 printf '<%#b>', 12; # prints "<0b1100>"
1529418003 printf '<%#B>', 12; # prints "<0B1100>"
1529518004
1529618005=begin original
1529718006
1529818007When a space and a plus sign are given as the flags at once,
15299a plus sign is used to prefix a positive number.
18008the space is ignored.
1530018009
1530118010=end original
1530218011
15303空白とプラス記号がフラグとして同時に与えられると、プラス記号は正の数に
18012空白とプラス記号がフラグとして同時に与えられると、
15304前置するために使われます。
18013空白は無視されます。
1530518014
1530618015 printf '<%+ d>', 12; # prints "<+12>"
1530718016 printf '<% +d>', 12; # prints "<+12>"
1530818017
1530918018=begin original
1531018019
1531118020When the # flag and a precision are given in the %o conversion,
1531218021the precision is incremented if it's necessary for the leading "0".
1531318022
1531418023=end original
1531518024
1531618025%o 変換に # フラグと精度が与えられると、先頭の "0" が必要な場合は
1531718026精度に 1 が加えられます。
1531818027
1531918028 printf '<%#.5o>', 012; # prints "<00012>"
1532018029 printf '<%#.5o>', 012345; # prints "<012345>"
1532118030 printf '<%#.0o>', 0; # prints "<0>"
1532218031
1532318032=item vector flag
1532418033
1532518034(ベクタフラグ)
1532618035
1532718036=begin original
1532818037
1532918038This flag tells Perl to interpret the supplied string as a vector of
1533018039integers, one for each character in the string. Perl applies the format to
1533118040each integer in turn, then joins the resulting strings with a separator (a
1533218041dot C<.> by default). This can be useful for displaying ordinal values of
1533318042characters in arbitrary strings:
1533418043
1533518044=end original
1533618045
1533718046このフラグは Perl に、与えられた文字列を、文字毎に一つの整数のベクタとして
1533818047解釈させます。
1533918048Perl は各数値をフォーマットし、それから結果の文字列をセパレータ
1534018049(デフォルトでは C<.>)で連結します。
1534118050これは任意の文字列の文字を順序付きの値として表示するのに便利です:
1534218051
1534318052 printf "%vd", "AB\x{100}"; # prints "65.66.256"
1534418053 printf "version is v%vd\n", $^V; # Perl's version
1534518054
1534618055=begin original
1534718056
1534818057Put an asterisk C<*> before the C<v> to override the string to
1534918058use to separate the numbers:
1535018059
1535118060=end original
1535218061
1535318062アスタリスク C<*> を C<v> の前に置くと、数値を分けるために使われる文字列を
1535418063上書きします:
1535518064
1535618065 printf "address is %*vX\n", ":", $addr; # IPv6 address
1535718066 printf "bits are %0*v8b\n", " ", $bits; # random bitstring
1535818067
1535918068=begin original
1536018069
1536118070You can also explicitly specify the argument number to use for
1536218071the join string using something like C<*2$v>; for example:
1536318072
1536418073=end original
1536518074
1536618075また、C<*2$v> のように、連結する文字列として使う引数の番号を明示的に
1536718076指定できます; 例えば:
1536818077
1536918078 printf '%*4$vX %*4$vX %*4$vX', # 3 IPv6 addresses
1537018079 @addr[1..3], ":";
1537118080
1537218081=item (minimum) width
1537318082
1537418083((最小)幅)
1537518084
1537618085=begin original
1537718086
1537818087Arguments are usually formatted to be only as wide as required to
1537918088display the given value. You can override the width by putting
1538018089a number here, or get the width from the next argument (with C<*>)
1538118090or from a specified argument (e.g., with C<*2$>):
1538218091
1538318092=end original
1538418093
1538518094引数は、普通は値を表示するのに必要なちょうどの幅でフォーマットされます。
1538618095ここに数値を置くか、(C<*> で)次の引数か(C<*2$> で)明示的に指定した引数で
1538718096幅を上書きできます。
1538818097
1538918098 printf "<%s>", "a"; # prints "<a>"
1539018099 printf "<%6s>", "a"; # prints "< a>"
1539118100 printf "<%*s>", 6, "a"; # prints "< a>"
1539218101 printf '<%*2$s>', "a", 6; # prints "< a>"
1539318102 printf "<%2s>", "long"; # prints "<long>" (does not truncate)
1539418103
1539518104=begin original
1539618105
1539718106If a field width obtained through C<*> is negative, it has the same
1539818107effect as the C<-> flag: left-justification.
1539918108
1540018109=end original
1540118110
1540218111C<*> を通して得られたフィールドの値が負数の場合、C<-> フラグと
1540318112同様の効果 (左詰め) があります。
1540418113
1540518114=item precision, or maximum width
1540618115X<precision>
1540718116
1540818117(精度あるいは最大幅)
1540918118
1541018119=begin original
1541118120
1541218121You can specify a precision (for numeric conversions) or a maximum
1541318122width (for string conversions) by specifying a C<.> followed by a number.
1541418123For floating-point formats except C<g> and C<G>, this specifies
1541518124how many places right of the decimal point to show (the default being 6).
1541618125For example:
1541718126
1541818127=end original
1541918128
1542018129C<.> の後に数値を指定することで、(数値変換の場合)精度や(文字列変換の場合)
1542118130最大幅を指定できます。
1542218131小数点数フォーマットの場合、C<g> と C<G> を除いて、表示する小数点以下の
1542318132桁数を指定します(デフォルトは 6 です)。
1542418133例えば:
1542518134
1542618135 # these examples are subject to system-specific variation
1542718136 printf '<%f>', 1; # prints "<1.000000>"
1542818137 printf '<%.1f>', 1; # prints "<1.0>"
1542918138 printf '<%.0f>', 1; # prints "<1>"
1543018139 printf '<%e>', 10; # prints "<1.000000e+01>"
1543118140 printf '<%.1e>', 10; # prints "<1.0e+01>"
1543218141
1543318142=begin original
1543418143
15435For "g" and "G", this specifies the maximum number of digits to show,
18144For "g" and "G", this specifies the maximum number of significant digits to
15436including those prior to the decimal point and those after it; for
18145show; for example:
15437example:
1543818146
1543918147=end original
1544018148
15441"g" と "G" の場合、これは表示する値の数を指定します;
18149"g" と "G" の場合、これは最大有効を指定します; 例えば:
15442これには小数点の前の数値と後の数値を含みます; 例えば:
1544318150
1544418151 # These examples are subject to system-specific variation.
1544518152 printf '<%g>', 1; # prints "<1>"
1544618153 printf '<%.10g>', 1; # prints "<1>"
1544718154 printf '<%g>', 100; # prints "<100>"
1544818155 printf '<%.1g>', 100; # prints "<1e+02>"
1544918156 printf '<%.2g>', 100.01; # prints "<1e+02>"
1545018157 printf '<%.5g>', 100.01; # prints "<100.01>"
1545118158 printf '<%.4g>', 100.01; # prints "<100>"
18159 printf '<%.1g>', 0.0111; # prints "<0.01>"
18160 printf '<%.2g>', 0.0111; # prints "<0.011>"
18161 printf '<%.3g>', 0.0111; # prints "<0.0111>"
1545218162
1545318163=begin original
1545418164
1545518165For integer conversions, specifying a precision implies that the
1545618166output of the number itself should be zero-padded to this width,
1545718167where the 0 flag is ignored:
1545818168
1545918169=end original
1546018170
1546118171整数変換の場合、精度を指定すると、数値自体の出力はこの幅に 0 で
1546218172パッディングするべきであることを暗に示すことになり、0 フラグは
1546318173無視されます:
1546418174
1546518175 printf '<%.6d>', 1; # prints "<000001>"
1546618176 printf '<%+.6d>', 1; # prints "<+000001>"
1546718177 printf '<%-10.6d>', 1; # prints "<000001 >"
1546818178 printf '<%10.6d>', 1; # prints "< 000001>"
1546918179 printf '<%010.6d>', 1; # prints "< 000001>"
1547018180 printf '<%+10.6d>', 1; # prints "< +000001>"
1547118181
1547218182 printf '<%.6x>', 1; # prints "<000001>"
1547318183 printf '<%#.6x>', 1; # prints "<0x000001>"
1547418184 printf '<%-10.6x>', 1; # prints "<000001 >"
1547518185 printf '<%10.6x>', 1; # prints "< 000001>"
1547618186 printf '<%010.6x>', 1; # prints "< 000001>"
1547718187 printf '<%#10.6x>', 1; # prints "< 0x000001>"
1547818188
1547918189=begin original
1548018190
1548118191For string conversions, specifying a precision truncates the string
1548218192to fit the specified width:
1548318193
1548418194=end original
1548518195
1548618196文字列変換の場合、精度を指定すると、指定された幅に収まるように文字列を
1548718197切り詰めます:
1548818198
1548918199 printf '<%.5s>', "truncated"; # prints "<trunc>"
1549018200 printf '<%10.5s>', "truncated"; # prints "< trunc>"
1549118201
1549218202=begin original
1549318203
15494You can also get the precision from the next argument using C<.*>:
18204You can also get the precision from the next argument using C<.*>, or from a
18205specified argument (e.g., with C<.*2$>):
1549518206
1549618207=end original
1549718208
15498C<.*> を使って精度を次の引数から取ることも出来ます:
18209C<.*> を使って精度を次の引数から取ったり、
18210(C<.*2$> のように) 指定した引数から取ったりすることもできます:
1549918211
1550018212 printf '<%.6x>', 1; # prints "<000001>"
1550118213 printf '<%.*x>', 6, 1; # prints "<000001>"
1550218214
18215 printf '<%.*2$x>', 1, 6; # prints "<000001>"
18216
18217 printf '<%6.*2$x>', 1, 4; # prints "< 0001>"
18218
1550318219=begin original
1550418220
1550518221If a precision obtained through C<*> is negative, it counts
1550618222as having no precision at all.
1550718223
1550818224=end original
1550918225
1551018226C<*> によって得られた精度が負数の場合、精度が指定されなかった場合と
1551118227同じ効果となります。
1551218228
1551318229 printf '<%.*s>', 7, "string"; # prints "<string>"
1551418230 printf '<%.*s>', 3, "string"; # prints "<str>"
1551518231 printf '<%.*s>', 0, "string"; # prints "<>"
1551618232 printf '<%.*s>', -1, "string"; # prints "<string>"
1551718233
1551818234 printf '<%.*d>', 1, 0; # prints "<0>"
1551918235 printf '<%.*d>', 0, 0; # prints "<>"
1552018236 printf '<%.*d>', -1, 0; # prints "<0>"
1552118237
15522=begin original
15523
15524You cannot currently get the precision from a specified number,
15525but it is intended that this will be possible in the future, for
15526example using C<.*2$>:
15527
15528=end original
15529
15530現在のところ精度を指定した数値から得ることはできませんが、
15531将来は 例えば C<.*2$> のようにして可能にしようとしています:
15532
15533 printf '<%.*2$x>', 1, 6; # INVALID, but in future will print
15534 # "<000001>"
15535
1553618238=item size
1553718239
1553818240(サイズ)
1553918241
1554018242=begin original
1554118243
1554218244For numeric conversions, you can specify the size to interpret the
1554318245number as using C<l>, C<h>, C<V>, C<q>, C<L>, or C<ll>. For integer
1554418246conversions (C<d u o x X b i D U O>), numbers are usually assumed to be
1554518247whatever the default integer size is on your platform (usually 32 or 64
1554618248bits), but you can override this to use instead one of the standard C types,
1554718249as supported by the compiler used to build Perl:
1554818250
1554918251=end original
1555018252
1555118253数値変換では、C<l>, C<h>, C<V>, C<q>, C<L>, C<ll> を使って解釈する数値の
1555218254大きさを指定できます。
1555318255整数変換 (C<d u o x X b i D U O>) では、数値は通常プラットフォームの
1555418256デフォルトの整数のサイズ (通常は 32 ビットか 64 ビット) を仮定しますが、
1555518257これを Perl がビルドされたコンパイラが対応している標準 C の型の一つで
1555618258上書きできます:
1555718259
1555818260=begin original
1555918261
1556018262 hh interpret integer as C type "char" or "unsigned
1556118263 char" on Perl 5.14 or later
1556218264 h interpret integer as C type "short" or
1556318265 "unsigned short"
1556418266 j interpret integer as C type "intmax_t" on Perl
15565 5.14 or later, and only with a C99 compiler
18267 5.14 or later; and prior to Perl 5.30, only with
15566 (unportable)
18268 a C99 compiler (unportable)
1556718269 l interpret integer as C type "long" or
1556818270 "unsigned long"
1556918271 q, L, or ll interpret integer as C type "long long",
1557018272 "unsigned long long", or "quad" (typically
1557118273 64-bit integers)
1557218274 t interpret integer as C type "ptrdiff_t" on Perl
1557318275 5.14 or later
15574 z interpret integer as C type "size_t" on Perl 5.14
18276 z interpret integer as C types "size_t" or
15575 or later
18277 "ssize_t" on Perl 5.14 or later
1557618278
1557718279=end original
1557818280
1557918281 hh Perl 5.14 以降で整数を C の "char" または "unsigned char"
1558018282 型として解釈する
1558118283 h 整数を C の "char" または "unsigned char" 型として解釈する
15582 j Perl 5.14 以降 C99 コンパイラのみで整数を C の "intmax_t"
18284 j Perl 5.14 以降 Perl 5.30 以前の C99 コンパイラのみで整数を
15583 型として解釈する (移植性なし)
18285 C の "intmax_t" 型として解釈する (移植性なし)
1558418286 l 整数を C の "long" または "unsigned long" と解釈する
1558518287 h 整数を C の "short" または "unsigned short" と解釈する
1558618288 q, L or ll 整数を C の "long long", "unsigned long long",
1558718289 "quads"(典型的には 64 ビット整数) のどれかと解釈する
1558818290 t Perl 5.14 以降で整数を C の "ptrdiff_t" 型として解釈する
15589 z Perl 5.14 以降で整数を C の "size_t" 型として解釈する
18291 z Perl 5.14 以降で整数を C の "size_t" 型または "ssize_t" 型
18292 として解釈する
1559018293
1559118294=begin original
1559218295
18296Note that, in general, using the C<l> modifier (for example, when writing
18297C<"%ld"> or C<"%lu"> instead of C<"%d"> and C<"%u">) is unnecessary
18298when used from Perl code. Moreover, it may be harmful, for example on
18299Windows 64-bit where a long is 32-bits.
18300
18301=end original
18302
18303一般的に、C<l> 修飾子を使う (例えば、C<"%d"> と C<"%u"> ではなく
18304C<"%ld"> や C<"%lu"> と書く) ことは、Perl のコードから使われる場合は
18305不要であることに注意してください。
18306さらに、例えば long が 32 ビットのときの 64 ビット Windows のように、
18307有害な場合もあります。
18308
18309=begin original
18310
1559318311As of 5.14, none of these raises an exception if they are not supported on
1559418312your platform. However, if warnings are enabled, a warning of the
15595C<printf> warning class is issued on an unsupported conversion flag.
18313L<C<printf>|warnings> warning class is issued on an unsupported
15596Should you instead prefer an exception, do this:
18314conversion flag. Should you instead prefer an exception, do this:
1559718315
1559818316=end original
1559918317
15600183185.14 から、プラットフォームがこれらに対応していないときでも例外が
1560118319発生しなくなりました。
1560218320しかし、もし警告が有効になっているなら、
15603非対応変換フラグに関して C<printf> 警告クラスの警告が発生します。
18321非対応変換フラグに関して L<C<printf>|warnings> 警告クラスの警告が発生します。
1560418322例外の方がお好みなら、以下のようにします:
1560518323
1560618324 use warnings FATAL => "printf";
1560718325
1560818326=begin original
1560918327
1561018328If you would like to know about a version dependency before you
1561118329start running the program, put something like this at its top:
1561218330
1561318331=end original
1561418332
1561518333プログラムの実行開始前にバージョン依存について知りたいなら、先頭に
1561618334以下のようなものを書きます:
1561718335
15618 use 5.014; # for hh/j/t/z/ printf modifiers
18336 use v5.14; # for hh/j/t/z/ printf modifiers
1561918337
1562018338=begin original
1562118339
1562218340You can find out whether your Perl supports quads via L<Config>:
1562318341
1562418342=end original
1562518343
1562618344Perl が 64 ビット整数に対応しているかどうかは L<Config> を使って
1562718345調べられます:
1562818346
1562918347 use Config;
1563018348 if ($Config{use64bitint} eq "define"
1563118349 || $Config{longsize} >= 8) {
1563218350 print "Nice quads!\n";
1563318351 }
1563418352
1563518353=begin original
1563618354
1563718355For floating-point conversions (C<e f g E F G>), numbers are usually assumed
1563818356to be the default floating-point size on your platform (double or long double),
1563918357but you can force "long double" with C<q>, C<L>, or C<ll> if your
1564018358platform supports them. You can find out whether your Perl supports long
1564118359doubles via L<Config>:
1564218360
1564318361=end original
1564418362
1564518363浮動小数点数変換 (C<e f g E F G>) では、普通はプラットフォームのデフォルトの
15646不動小数点数のサイズ (double か long double) を仮定します
18364不動小数点数のサイズ (double か long double) を仮定しますが、
18365プラットフォームが対応しているなら、C<q>, C<L>, C<ll> に対して
18366"long double" を強制できます。
1564718367Perl が long double に対応しているかどうかは L<Config> を使って
1564818368調べられます:
1564918369
1565018370 use Config;
1565118371 print "long doubles\n" if $Config{d_longdbl} eq "define";
1565218372
1565318373=begin original
1565418374
1565518375You can find out whether Perl considers "long double" to be the default
1565618376floating-point size to use on your platform via L<Config>:
1565718377
1565818378=end original
1565918379
1566018380Perl が "long double" をデフォルトの浮動小数点数として扱っているかどうかは
1566118381L<Config> を使って調べられます:
1566218382
1566318383 use Config;
1566418384 if ($Config{uselongdouble} eq "define") {
1566518385 print "long doubles by default\n";
1566618386 }
1566718387
1566818388=begin original
1566918389
1567018390It can also be that long doubles and doubles are the same thing:
1567118391
1567218392=end original
1567318393
1567418394long double と double が同じ場合もあります:
1567518395
1567618396 use Config;
1567718397 ($Config{doublesize} == $Config{longdblsize}) &&
1567818398 print "doubles are long doubles\n";
1567918399
1568018400=begin original
1568118401
1568218402The size specifier C<V> has no effect for Perl code, but is supported for
1568318403compatibility with XS code. It means "use the standard size for a Perl
1568418404integer or floating-point number", which is the default.
1568518405
1568618406=end original
1568718407
1568818408サイズ指定子 C<V> は Perl のコードには何の影響もありませんが、これは
1568918409XS コードとの互換性のために対応しています。
1569018410これは「Perl 整数 (または浮動小数点数) として標準的なサイズを使う」ことを
1569118411意味し、これはデフォルトです。
1569218412
1569318413=item order of arguments
1569418414
1569518415(引数の順序)
1569618416
1569718417=begin original
1569818418
15699Normally, sprintf() takes the next unused argument as the value to
18419Normally, L<C<sprintf>|/sprintf FORMAT, LIST> takes the next unused
18420argument as the value to
1570018421format for each format specification. If the format specification
1570118422uses C<*> to require additional arguments, these are consumed from
1570218423the argument list in the order they appear in the format
1570318424specification I<before> the value to format. Where an argument is
1570418425specified by an explicit index, this does not affect the normal
1570518426order for the arguments, even when the explicitly specified index
1570618427would have been the next argument.
1570718428
1570818429=end original
1570918430
15710通常、sprintf() は各フォーマット指定について、使われていない次の引数を
18431通常、L<C<sprintf>|/sprintf FORMAT, LIST> は各フォーマット指定について、
18432使われていない次の引数を
1571118433フォーマットする値として使います。
1571218434追加の引数を要求するためにフォーマット指定 C<*> を使うと、
1571318435これらはフォーマットする値の I<前> のフォーマット指定に現れる順番に
1571418436引数リストから消費されます。
1571518437引数の位置が明示的なインデックスを使って指定された場合、
1571618438(明示的に指定したインデックスが次の引数の場合でも)
1571718439これは通常の引数の順番に影響を与えません。
1571818440
1571918441=begin original
1572018442
1572118443So:
1572218444
1572318445=end original
1572418446
1572518447それで:
1572618448
1572718449 printf "<%*.*s>", $a, $b, $c;
1572818450
1572918451=begin original
1573018452
1573118453uses C<$a> for the width, C<$b> for the precision, and C<$c>
1573218454as the value to format; while:
1573318455
1573418456=end original
1573518457
1573618458とすると C<$a> を幅に、C<$b> を精度に、C<$c> をフォーマットの値に
1573718459使います; 一方:
1573818460
1573918461 printf '<%*1$.*s>', $a, $b;
1574018462
1574118463=begin original
1574218464
1574318465would use C<$a> for the width and precision, and C<$b> as the
1574418466value to format.
1574518467
1574618468=end original
1574718469
1574818470とすると C<$a> を幅と精度に、C<$b> をフォーマットの値に使います。
1574918471
1575018472=begin original
1575118473
1575218474Here are some more examples; be aware that when using an explicit
1575318475index, the C<$> may need escaping:
1575418476
1575518477=end original
1575618478
1575718479以下にさらなる例を示します; 明示的にインデックスを使う場合、C<$> は
1575818480エスケープする必要があることに注意してください:
1575918481
15760 printf "%2\$d %d\n", 12, 34; # will print "34 12\n"
18482 printf "%2\$d %d\n", 12, 34; # will print "34 12\n"
15761 printf "%2\$d %d %d\n", 12, 34; # will print "34 12 34\n"
18483 printf "%2\$d %d %d\n", 12, 34; # will print "34 12 34\n"
15762 printf "%3\$d %d %d\n", 12, 34, 56; # will print "56 12 34\n"
18484 printf "%3\$d %d %d\n", 12, 34, 56; # will print "56 12 34\n"
15763 printf "%2\$*3\$d %d\n", 12, 34, 3; # will print " 34 12\n"
18485 printf "%2\$*3\$d %d\n", 12, 34, 3; # will print " 34 12\n"
18486 printf "%*1\$.*f\n", 4, 5, 10; # will print "5.0000\n"
1576418487
1576518488=back
1576618489
1576718490=begin original
1576818491
15769If C<use locale> (including C<use locale 'not_characters'>) is in effect
18492If L<C<use locale>|locale> (including C<use locale ':not_characters'>)
15770and POSIX::setlocale() has been called,
18493is in effect and L<C<POSIX::setlocale>|POSIX/C<setlocale>> has been
18494called,
1577118495the character used for the decimal separator in formatted floating-point
15772numbers is affected by the LC_NUMERIC locale. See L<perllocale>
18496numbers is affected by the C<LC_NUMERIC> locale. See L<perllocale>
1577318497and L<POSIX>.
1577418498
1577518499=end original
1577618500
15777(C<use locale 'not_characters'> を含む)C<use locale> が有効で、
18501(C<use locale ':not_characters'> を含む)L<C<use locale>|locale> が有効で、
15778POSIX::setlocale() が呼び出されている場合、フォーマットされた浮動小数点数の
18502L<C<POSIX::setlocale>|POSIX/C<setlocale>> が呼び出されている場合、
15779小数点として使われる文字は LC_NUMERIC ロケールの影響を受けます。
18503フォーマットされた浮動小数点数の小数点として使われる文字は
18504C<LC_NUMERIC> ロケールの影響を受けます。
1578018505L<perllocale> と L<POSIX> を参照してください。
1578118506
1578218507=item sqrt EXPR
1578318508X<sqrt> X<root> X<square root>
1578418509
1578518510=item sqrt
1578618511
1578718512=for Pod::Functions square root function
1578818513
1578918514=begin original
1579018515
1579118516Return the positive square root of EXPR. If EXPR is omitted, uses
15792C<$_>. Works only for non-negative operands unless you've
18517L<C<$_>|perlvar/$_>. Works only for non-negative operands unless you've
15793loaded the C<Math::Complex> module.
18518loaded the L<C<Math::Complex>|Math::Complex> module.
1579418519
1579518520=end original
1579618521
1579718522EXPR の正の平方根を返します。
15798EXPR が省略されると、C<$_> を使います。
18523EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
15799C<Math::Complex> モジュールを使わない場合は、負の数の引数は扱えません。
18524L<C<Math::Complex>|Math::Complex> モジュールを使わない場合は、負の数の引数は
18525扱えません。
1580018526
1580118527 use Math::Complex;
1580218528 print sqrt(-4); # prints 2i
1580318529
1580418530=item srand EXPR
1580518531X<srand> X<seed> X<randseed>
1580618532
1580718533=item srand
1580818534
1580918535=for Pod::Functions seed the random number generator
1581018536
1581118537=begin original
1581218538
15813Sets and returns the random number seed for the C<rand> operator.
18539Sets and returns the random number seed for the L<C<rand>|/rand EXPR>
18540operator.
1581418541
1581518542=end original
1581618543
15817C<rand> 演算子のためのシード値を設定して返します。
18544L<C<rand>|/rand EXPR> 演算子のためのシード値を設定して返します。
1581818545
1581918546=begin original
1582018547
15821The point of the function is to "seed" the C<rand> function so that C<rand>
18548The point of the function is to "seed" the L<C<rand>|/rand EXPR>
15822can produce a different sequence each time you run your program. When
18549function so that L<C<rand>|/rand EXPR> can produce a different sequence
15823called with a parameter, C<srand> uses that for the seed; otherwise it
18550each time you run your program. When called with a parameter,
15824(semi-)randomly chooses a seed. In either case, starting with Perl 5.14,
18551L<C<srand>|/srand EXPR> uses that for the seed; otherwise it
18552(semi-)randomly chooses a seed (see below). In either case, starting with Perl 5.14,
1582518553it returns the seed. To signal that your code will work I<only> on Perls
1582618554of a recent vintage:
1582718555
1582818556=end original
1582918557
15830この関数のポイントは、プログラムを実行するごとに C<rand> 関数が
18558この関数のポイントは、プログラムを実行するごとに L<C<rand>|/rand EXPR> 関数が
15831異なる乱数列を生成できるように C<rand> 関数の「種」を設定することです。
18559異なる乱数列を生成できるように L<C<rand>|/rand EXPR> 関数の「種」を
15832C<srand> を引数付きで呼び出と、れを種して使いま; さもなければ
18560設定こと
15833(だいたい)ランダムに種びます
18561L<C<srand>|/srand EXPR> 引数付きで呼出すと、これを種として使います;
18562さもなければ(だいたい)ランダムに種を選びます(後述)。
1583418563どちらの場合でも、Perl 5.14 からは種を返します。
1583518564特定の時期の Perl I<でのみ> 動作することを知らせるには以下のようにします:
1583618565
15837 use 5.014; # so srand returns the seed
18566 use v5.14; # so srand returns the seed
1583818567
1583918568=begin original
1584018569
15841If C<srand()> is not called explicitly, it is called implicitly without a
18570If L<C<srand>|/srand EXPR> is not called explicitly, it is called
15842parameter at the first use of the C<rand> operator.
18571implicitly without a parameter at the first use of the
15843However, there are a few situations where programs are likely to
18572L<C<rand>|/rand EXPR> operator. However, there are a few situations
15844want to call C<srand>. One is for generating predictable results, generally for
18573where programs are likely to want to call L<C<srand>|/srand EXPR>. One
15845testing or debugging. There, you use C<srand($seed)>, with the same C<$seed>
18574is for generating predictable results, generally for testing or
15846each time. Another case is that you may want to call C<srand()>
18575debugging. There, you use C<srand($seed)>, with the same C<$seed> each
15847after a C<fork()> to avoid child processes sharing the same seed value as the
18576time. Another case is that you may want to call L<C<srand>|/srand EXPR>
15848parent (and consequently each other).
18577after a L<C<fork>|/fork> to avoid child processes sharing the same seed
18578value as the parent (and consequently each other).
1584918579
1585018580=end original
1585118581
15852C<srand()> が明示的に呼び出されなかった場合、最初に C<rand> 演算子を使った
18582L<C<srand>|/srand EXPR> が明示的に呼び出されなかった場合、最初に
15853時点で暗黙に引数なしで呼び出されます。
18583L<C<rand>|/rand EXPR> 演算子を使った時点で暗黙に引数なしで呼び出されます。
15854しかし、最近の Perl でプログラムが C<srand> を呼び出したいであろう状況が
18584しかし、最近の Perl でプログラムが L<C<srand>|/srand EXPR>
15855いくつかあります。
18585呼び出したいであろう状況がいくつかあります。
1585618586一つはテストやデバッグのために予測可能な結果を生成するためです。
1585718587この場合、C<srand($seed)> (C<$seed> は毎回同じ値を使う) を使います。
1585818588もう一つの場合としては、子プロセスが親や他の子プロセスと同じ種の値を
15859共有することを避けるために、C<fork()> の後に C<srand()> を
18589共有することを避けるために、L<C<fork>|/fork> の後に L<C<srand>|/srand EXPR> を
1586018590呼び出したいかもしれません。
1586118591
1586218592=begin original
1586318593
1586418594Do B<not> call C<srand()> (i.e., without an argument) more than once per
1586518595process. The internal state of the random number generator should
1586618596contain more entropy than can be provided by any seed, so calling
15867C<srand()> again actually I<loses> randomness.
18597L<C<srand>|/srand EXPR> again actually I<loses> randomness.
1586818598
1586918599=end original
1587018600
15871C<srand()> (引数なし)をプロセス中で複数回呼び出しては B<いけません>。
18601L<C<srand>|/srand EXPR> (引数なし)をプロセス中で複数回
18602呼び出しては B<いけません>。
1587218603乱数生成器の内部状態はどのような種によって提供されるものよりも
1587318604高いエントロピーを持っているので、C<srand()> を再び呼び出すと
1587418605ランダム性が I<失われます>。
1587518606
1587618607=begin original
1587718608
15878Most implementations of C<srand> take an integer and will silently
18609Most implementations of L<C<srand>|/srand EXPR> take an integer and will
18610silently
1587918611truncate decimal numbers. This means C<srand(42)> will usually
1588018612produce the same results as C<srand(42.1)>. To be safe, always pass
15881C<srand> an integer.
18613L<C<srand>|/srand EXPR> an integer.
1588218614
1588318615=end original
1588418616
15885C<srand> のほとんどの実装では整数を取り、小数を暗黙に切り捨てます。
18617L<C<srand>|/srand EXPR> のほとんどの実装では整数を取り、小数を暗黙に
15886これは、C<srand(42)> は普通 C<srand(42.1)> と同じ結果になることを
18618切り捨てます。
15887意味します。
18619これは、C<srand(42)> は普通 C<srand(42.1)> と同じ結果になることを意味します。
15888安全のために、C<srand> には常に整数を渡しましょう。
18620安全のために、L<C<srand>|/srand EXPR> には常に整数を渡しましょう。
1588918621
1589018622=begin original
1589118623
1589218624A typical use of the returned seed is for a test program which has too many
1589318625combinations to test comprehensively in the time available to it each run. It
1589418626can test a random subset each time, and should there be a failure, log the seed
1589518627used for that run so that it can later be used to reproduce the same results.
1589618628
1589718629=end original
1589818630
1589918631返された種の典型的な利用法は、実行毎のテストを利用可能な時間内に完全に
1590018632行うには組み合わせが多すぎるテストプログラム用です。
1590118633毎回ランダムなサブセットをテストし、もし失敗したら、その実行で使った
1590218634種をログに出力することで、後で同じ結果を再現するために使えます。
1590318635
1590418636=begin original
1590518637
15906B<C<rand()> is not cryptographically secure. You should not rely
18638If the C<PERL_RAND_SEED> environment variable is set to a non-negative
18639integer during process startup then calls to C<srand()> with no
18640arguments will initialize the perl random number generator with a
18641consistent seed each time it is called, whether called explicitly with
18642no arguments or implicitly via use of C<rand()>. The exact seeding that
18643a given C<PERL_RAND_SEED> will produce is deliberately unspecified, but
18644using different values for C<PERL_RAND_SEED> should produce different
18645results. This is intended for debugging and performance analysis and is
18646only guaranteed to produce consistent results between invocations of the
18647same perl executable running the same code when all other factors are
18648equal. The environment variable is read only once during process
18649startup, and changing it during the program flow will not affect the
18650currently running process. See L<perlrun> for more details.
18651
18652=end original
18653
18654If the C<PERL_RAND_SEED> environment variable is set to a non-negative
18655integer during process startup then calls to C<srand()> with no
18656arguments will initialize the perl random number generator with a
18657consistent seed each time it is called, whether called explicitly with
18658no arguments or implicitly via use of C<rand()>. The exact seeding that
18659a given C<PERL_RAND_SEED> will produce is deliberately unspecified, but
18660using different values for C<PERL_RAND_SEED> should produce different
18661results. This is intended for debugging and performance analysis and is
18662only guaranteed to produce consistent results between invocations of the
18663same perl executable running the same code when all other factors are
18664equal. The environment variable is read only once during process
18665startup, and changing it during the program flow will not affect the
18666currently running process. See L<perlrun> for more details.
18667(TBT)
18668
18669=begin original
18670
18671B<L<C<rand>|/rand EXPR> is not cryptographically secure. You should not rely
1590718672on it in security-sensitive situations.> As of this writing, a
1590818673number of third-party CPAN modules offer random number generators
1590918674intended by their authors to be cryptographically secure,
1591018675including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
1591118676and L<Math::TrulyRandom>.
1591218677
1591318678=end original
1591418679
15915B<C<rand()> は暗号学的に安全ではありません。
18680B<L<C<rand>|/rand EXPR> は暗号学的に安全ではありません。
1591618681セキュリティ的に重要な状況でこれに頼るべきではありません。>
1591718682これを書いている時点で、いくつかのサードパーティ CPAN モジュールが
1591818683作者によって暗号学的に安全であることを目的とした乱数生成器を
1591918684提供しています: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
1592018685L<Math::TrulyRandom> などです。
1592118686
1592218687=item stat FILEHANDLE
1592318688X<stat> X<file, status> X<ctime>
1592418689
1592518690=item stat EXPR
1592618691
1592718692=item stat DIRHANDLE
1592818693
1592918694=item stat
1593018695
1593118696=for Pod::Functions get a file's status information
1593218697
1593318698=begin original
1593418699
1593518700Returns a 13-element list giving the status info for a file, either
15936the file opened via FILEHANDLE or DIRHANDLE, or named by EXPR. If EXPR is
18701the file opened via FILEHANDLE or DIRHANDLE, or named by EXPR. If EXPR is
15937omitted, it stats C<$_> (not C<_>!). Returns the empty list if C<stat> fails. Typically
18702omitted, it stats L<C<$_>|perlvar/$_> (not C<_>!). Returns the empty
18703list if L<C<stat>|/stat FILEHANDLE> fails. Typically
1593818704used as follows:
1593918705
1594018706=end original
1594118707
1594218708FILEHANDLE か DIRHANDLE を通じてオープンされているファイルか、
1594318709EXPR で指定されるファイルの情報を与える、13 要素のリストを返します。
15944EXPR が省略されると、 C<$_> が用いられます (C<_> ではありません!)。
18710EXPR が省略されると、 L<C<$_>|perlvar/$_> が用いられます
15945C<stat> に失敗した場合に、空リストを返し
18711(C<_> ありせん!)
18712L<C<stat>|/stat FILEHANDLE> に失敗した場合には、空リストを返します。
1594618713普通は、以下のようにして使います:
1594718714
15948 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
18715 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
15949 $atime,$mtime,$ctime,$blksize,$blocks)
18716 $atime,$mtime,$ctime,$blksize,$blocks)
1595018717 = stat($filename);
1595118718
1595218719=begin original
1595318720
1595418721Not all fields are supported on all filesystem types. Here are the
1595518722meanings of the fields:
1595618723
1595718724=end original
1595818725
1595918726全てのファイルシステムで全てのフィールドに対応しているわけではありません。
1596018727フィールドの意味は以下の通りです。
1596118728
1596218729=begin original
1596318730
1596418731 0 dev device number of filesystem
1596518732 1 ino inode number
1596618733 2 mode file mode (type and permissions)
1596718734 3 nlink number of (hard) links to the file
1596818735 4 uid numeric user ID of file's owner
1596918736 5 gid numeric group ID of file's owner
1597018737 6 rdev the device identifier (special files only)
1597118738 7 size total size of file, in bytes
1597218739 8 atime last access time in seconds since the epoch
1597318740 9 mtime last modify time in seconds since the epoch
1597418741 10 ctime inode change time in seconds since the epoch (*)
1597518742 11 blksize preferred I/O size in bytes for interacting with the
1597618743 file (may vary from file to file)
1597718744 12 blocks actual number of system-specific blocks allocated
1597818745 on disk (often, but not always, 512 bytes each)
1597918746
1598018747=end original
1598118748
1598218749 0 dev ファイルシステムのデバイス番号
1598318750 1 ino inode 番号
1598418751 2 mode ファイルモード (タイプとパーミッション)
1598518752 3 nlink ファイルへの(ハード)リンクの数
1598618753 4 uid ファイル所有者のユーザー ID の数値
1598718754 5 gid ファイル所有者のグループ ID の数値
1598818755 6 rdev デバイス識別子(特殊ファイルのみ)
1598918756 7 size ファイルサイズ(バイト単位)
1599018757 8 atime 紀元から、最後にアクセスされた時刻までの秒数
1599118758 9 mtime 紀元から、最後に修正(modify)された時刻までの秒数
1599218759 10 ctime 紀元から、inode 変更(change)された時刻までの秒数 (*)
1599318760 11 blksize ファイルとの相互作用のために適した I/O バイト数
1599418761 (ファイルごとに異なるかもしれない)
1599518762 12 blocks ディスクに割り当てたシステム依存のブロック(常にでは
1599618763 ありませんがたいていはそれぞれ 512 バイト)の数
1599718764
1599818765=begin original
1599918766
1600018767(The epoch was at 00:00 January 1, 1970 GMT.)
1600118768
1600218769=end original
1600318770
1600418771(紀元は GMT で 1970/01/01 00:00:00。)
1600518772
1600618773=begin original
1600718774
1600818775(*) Not all fields are supported on all filesystem types. Notably, the
1600918776ctime field is non-portable. In particular, you cannot expect it to be a
1601018777"creation time"; see L<perlport/"Files and Filesystems"> for details.
1601118778
1601218779=end original
1601318780
1601418781(*) 全てのフィールドが全てのファイルシステムタイプで対応しているわけでは
1601518782ありません。
1601618783明らかに、ctime のフィールドは移植性がありません。
1601718784特に、これから「作成時刻」を想定することは出来ません;
1601818785詳細については L<perlport/"Files and Filesystems"> を参照してください。
1601918786
1602018787=begin original
1602118788
16022If C<stat> is passed the special filehandle consisting of an underline, no
18789If L<C<stat>|/stat FILEHANDLE> is passed the special filehandle
16023stat is done, but the current contents of the stat structure from the
18790consisting of an underline, no stat is done, but the current contents of
16024last C<stat>, C<lstat>, or filetest are returned. Example:
18791the stat structure from the last L<C<stat>|/stat FILEHANDLE>,
18792L<C<lstat>|/lstat FILEHANDLE>, or filetest are returned. Example:
1602518793
1602618794=end original
1602718795
16028下線だけの _ という特別なファイルハンドルを C<stat> に渡すと、
18796下線だけの _ という特別なファイルハンドルを L<C<stat>|/stat FILEHANDLE>
16029実際には stat を行なわず、stat 構造体に残っている
18797渡すと、実際には stat を行なわず、stat 構造体に残っている
16030前回の stat やファイルテストの情報が返されます。
18798前回の L<C<stat>|/stat FILEHANDLE>, L<C<lstat>|/lstat FILEHANDLE>
18799ファイルテストの情報が返されます。
1603118800例:
1603218801
1603318802 if (-x $file && (($d) = stat(_)) && $d < 0) {
1603418803 print "$file is executable NFS file\n";
1603518804 }
1603618805
1603718806=begin original
1603818807
1603918808(This works on machines only for which the device number is negative
1604018809under NFS.)
1604118810
1604218811=end original
1604318812
16044(これは、NFS のもとでデバイス番号が負になるマシンで
18813(これは、NFS のもとでデバイス番号が負になるマシンでのみ動作します。)
16045のみ動作します。)
1604618814
1604718815=begin original
1604818816
18817On some platforms inode numbers are of a type larger than perl knows how
18818to handle as integer numerical values. If necessary, an inode number will
18819be returned as a decimal string in order to preserve the entire value.
18820If used in a numeric context, this will be converted to a floating-point
18821numerical value, with rounding, a fate that is best avoided. Therefore,
18822you should prefer to compare inode numbers using C<eq> rather than C<==>.
18823C<eq> will work fine on inode numbers that are represented numerically,
18824as well as those represented as strings.
18825
18826=end original
18827
18828一部のプラットフォームでは、inode 番号は perl が整数値として
18829扱い方を知っているものよりも大きい型になっています。
18830もし必要なら、inode 番号は、値全体を保存するために 10 進文字列として
18831返されます。
18832数値コンテキストで使うと、これは丸めを伴う浮動小数点数に変換され、
18833できるだけ避けるべき結果になります。
18834従って、inode 番号の比較には C<==> ではなく C<eq> を使うべきです。
18835C<eq> は、inode 番号が数値で表現されていても、文字列で表現されていても
18836うまく動作します。
18837
18838=begin original
18839
1604918840Because the mode contains both the file type and its permissions, you
1605018841should mask off the file type portion and (s)printf using a C<"%o">
1605118842if you want to see the real permissions.
1605218843
1605318844=end original
1605418845
1605518846モードにはファイルタイプとその権限の両方が含まれているので、
1605618847本当の権限を見たい場合は、(s)printf で C<"%"> を使うことで
1605718848ファイルタイプをマスクするべきです。
1605818849
16059 $mode = (stat($filename))[2];
18850 my $mode = (stat($filename))[2];
1606018851 printf "Permissions are %04o\n", $mode & 07777;
1606118852
1606218853=begin original
1606318854
16064In scalar context, C<stat> returns a boolean value indicating success
18855In scalar context, L<C<stat>|/stat FILEHANDLE> returns a boolean value
18856indicating success
1606518857or failure, and, if successful, sets the information associated with
1606618858the special filehandle C<_>.
1606718859
1606818860=end original
1606918861
16070スカラコンテキストでは、C<stat> は成功か失敗を表す真偽値を返し、
18862スカラコンテキストでは、L<C<stat>|/stat FILEHANDLE> は成功か失敗を表す真偽値を
16071成功した場合は、特別なファイルハンドル C<_> に結び付けられた
18863返し、成功した場合は、特別なファイルハンドル C<_> に結び付けられた
1607218864情報をセットします。
1607318865
1607418866=begin original
1607518867
1607618868The L<File::stat> module provides a convenient, by-name access mechanism:
1607718869
1607818870=end original
1607918871
1608018872L<File::stat> モジュールは、便利な名前によるアクセス機構を提供します。
1608118873
1608218874 use File::stat;
16083 $sb = stat($filename);
18875 my $sb = stat($filename);
1608418876 printf "File is %s, size is %s, perm %04o, mtime %s\n",
1608518877 $filename, $sb->size, $sb->mode & 07777,
1608618878 scalar localtime $sb->mtime;
1608718879
1608818880=begin original
1608918881
1609018882You can import symbolic mode constants (C<S_IF*>) and functions
16091(C<S_IS*>) from the Fcntl module:
18883(C<S_IS*>) from the L<Fcntl> module:
1609218884
1609318885=end original
1609418886
16095モード定数 (C<S_IF*>) と関数 (C<S_IS*>) を Fcntl モジュールから
18887モード定数 (C<S_IF*>) と関数 (C<S_IS*>) を L<Fcntl> モジュールから
1609618888インポートできます。
1609718889
1609818890 use Fcntl ':mode';
1609918891
16100 $mode = (stat($filename))[2];
18892 my $mode = (stat($filename))[2];
1610118893
16102 $user_rwx = ($mode & S_IRWXU) >> 6;
18894 my $user_rwx = ($mode & S_IRWXU) >> 6;
16103 $group_read = ($mode & S_IRGRP) >> 3;
18895 my $group_read = ($mode & S_IRGRP) >> 3;
16104 $other_execute = $mode & S_IXOTH;
18896 my $other_execute = $mode & S_IXOTH;
1610518897
1610618898 printf "Permissions are %04o\n", S_IMODE($mode), "\n";
1610718899
16108 $is_setuid = $mode & S_ISUID;
18900 my $is_setuid = $mode & S_ISUID;
16109 $is_directory = S_ISDIR($mode);
18901 my $is_directory = S_ISDIR($mode);
1611018902
1611118903=begin original
1611218904
1611318905You could write the last two using the C<-u> and C<-d> operators.
1611418906Commonly available C<S_IF*> constants are:
1611518907
1611618908=end original
1611718909
1611818910最後の二つは C<-u> と C<-d> 演算子を使っても書けます。
1611918911一般に利用可能な C<S_IF*> 定数は以下のものです。
1612018912
1612118913 # Permissions: read, write, execute, for user, group, others.
1612218914
1612318915 S_IRWXU S_IRUSR S_IWUSR S_IXUSR
1612418916 S_IRWXG S_IRGRP S_IWGRP S_IXGRP
1612518917 S_IRWXO S_IROTH S_IWOTH S_IXOTH
1612618918
1612718919 # Setuid/Setgid/Stickiness/SaveText.
1612818920 # Note that the exact meaning of these is system-dependent.
1612918921
1613018922 S_ISUID S_ISGID S_ISVTX S_ISTXT
1613118923
1613218924 # File types. Not all are necessarily available on
1613318925 # your system.
1613418926
1613518927 S_IFREG S_IFDIR S_IFLNK S_IFBLK S_IFCHR
1613618928 S_IFIFO S_IFSOCK S_IFWHT S_ENFMT
1613718929
1613818930 # The following are compatibility aliases for S_IRUSR,
1613918931 # S_IWUSR, and S_IXUSR.
1614018932
1614118933 S_IREAD S_IWRITE S_IEXEC
1614218934
1614318935=begin original
1614418936
1614518937and the C<S_IF*> functions are
1614618938
1614718939=end original
1614818940
1614918941一般に利用可能な C<S_IF*> 関数は以下のものです。
1615018942
1615118943 S_IMODE($mode) the part of $mode containing the permission
1615218944 bits and the setuid/setgid/sticky bits
1615318945
1615418946 S_IFMT($mode) the part of $mode containing the file type
1615518947 which can be bit-anded with (for example)
1615618948 S_IFREG or with the following functions
1615718949
1615818950 # The operators -f, -d, -l, -b, -c, -p, and -S.
1615918951
1616018952 S_ISREG($mode) S_ISDIR($mode) S_ISLNK($mode)
1616118953 S_ISBLK($mode) S_ISCHR($mode) S_ISFIFO($mode) S_ISSOCK($mode)
1616218954
1616318955 # No direct -X operator counterpart, but for the first one
1616418956 # the -g operator is often equivalent. The ENFMT stands for
1616518957 # record flocking enforcement, a platform-dependent feature.
1616618958
1616718959 S_ISENFMT($mode) S_ISWHT($mode)
1616818960
1616918961=begin original
1617018962
16171See your native chmod(2) and stat(2) documentation for more details
18963See your native L<chmod(2)> and L<stat(2)> documentation for more details
1617218964about the C<S_*> constants. To get status info for a symbolic link
16173instead of the target file behind the link, use the C<lstat> function.
18965instead of the target file behind the link, use the
18966L<C<lstat>|/lstat FILEHANDLE> function.
1617418967
1617518968=end original
1617618969
16177C<S_*> 定数に関する詳細についてはネイティブの chmod(2) と stat(2) の
18970C<S_*> 定数に関する詳細についてはネイティブの L<chmod(2)>L<stat(2)>
1617818971ドキュメントを参照してください。
1617918972リンクの先にあるファイルではなく、シンボリックリンクそのものの情報を
16180得たい場合は、C<lstat> 関数を使ってください。
18973得たい場合は、L<C<lstat>|/lstat FILEHANDLE> 関数を使ってください。
1618118974
1618218975=begin original
1618318976
1618418977Portability issues: L<perlport/stat>.
1618518978
1618618979=end original
1618718980
1618818981移植性の問題: L<perlport/stat>。
1618918982
16190=item state EXPR
18983=item state VARLIST
1619118984X<state>
1619218985
16193=item state TYPE EXPR
18986=item state TYPE VARLIST
1619418987
16195=item state EXPR : ATTRS
18988=item state VARLIST : ATTRS
1619618989
16197=item state TYPE EXPR : ATTRS
18990=item state TYPE VARLIST : ATTRS
1619818991
1619918992=for Pod::Functions +state declare and assign a persistent lexical variable
1620018993
1620118994=begin original
1620218995
16203C<state> declares a lexically scoped variable, just like C<my>.
18996L<C<state>|/state VARLIST> declares a lexically scoped variable, just
18997like L<C<my>|/my VARLIST>.
1620418998However, those variables will never be reinitialized, contrary to
1620518999lexical variables that are reinitialized each time their enclosing block
1620619000is entered.
1620719001See L<perlsub/"Persistent Private Variables"> for details.
1620819002
1620919003=end original
1621019004
16211C<state> はちょうど C<my> と同様に、レキシカルなスコープの変数を宣言します。
19005L<C<state>|/state VARLIST> はちょうど L<C<my>|/my VARLIST> と同様に、
19006レキシカルなスコープの変数を宣言します。
1621219007しかし、レキシカル変数がブロックに入る毎に再初期化されるのと異なり、
1621319008この変数は決して再初期化されません。
1621419009詳しくは L<perlsub/"Persistent Private Variables"> を参照してください。
1621519010
1621619011=begin original
1621719012
16218C<state> variables are enabled only when the C<use feature "state"> pragma
19013If more than one variable is listed, the list must be placed in
16219is in effect, unless the keyword is written as C<CORE::state>.
19014parentheses. With a parenthesised list, L<C<undef>|/undef EXPR> can be
16220See also L<feature>.
19015used as a
19016dummy placeholder. However, since initialization of state variables in
19017such lists is currently not possible this would serve no purpose.
1622119018
1622219019=end original
1622319020
16224C<state> 変数は、キーワードが C<CORE::state> として書かれていい限
19021複数の変数を指定する場合は、リストはっこで囲まなけなりません。
16225C<feature 'state'> プラグマが有効場合のみ有効です。
19022かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> はダミー
16226L<feature> も参照してください
19023プレースホルダとして使えます
19024しかし、そのようなリストでの state 変数の初期化は現在のところできないので、
19025これは無意味です。
1622719026
16228=item study SCALAR
16229X<study>
16230
16231=item study
16232
16233=for Pod::Functions optimize input data for repeated searches
16234
1623519027=begin original
1623619028
16237Takes extra time to study SCALAR (C<$_> if unspecified) in anticipation of
19029Redeclaring a variable in the same scope or statement will "shadow" the
16238doing many pattern matches on the string before it is next modified.
19030previous declaration, creating a new instance and preventing access to
16239This may or may not save time, depending on the nature and number of
19031the previous one. This is usually undesired and, if warnings are enabled,
16240patterns you are searching and the distribution of character
19032will result in a warning in the C<shadow> category.
16241frequencies in the string to be searched; you probably want to compare
16242run times with and without it to see which is faster. Those loops
16243that scan for many short constant strings (including the constant
16244parts of more complex patterns) will benefit most.
16245(The way C<study> works is this: a linked list of every
16246character in the string to be searched is made, so we know, for
16247example, where all the C<'k'> characters are. From each search string,
16248the rarest character is selected, based on some static frequency tables
16249constructed from some C programs and English text. Only those places
16250that contain this "rarest" character are examined.)
1625119033
1625219034=end original
1625319035
16254次に変更される前に、何回も字列に対するパターンマッチ行なう
19036同じスコープやで変数を再宣言すると、以前の宣言「隠し」、
16255アプリケーションでような文字列 SCALAR(省略時は C<$_>) を予め
19037新しい実体を作って以前実体アクセスできなくなります。
16256学習しておきす。
19038これは普通は望れているものではなく、警告が有効なら、
16257これは、検索ために、どのようなパターンを何回使うかによって、た、
19039C<shadow> カテゴリ警告が出す。
16258検索される文字列内の文字頻度の分布によって、時間を節約することに
16259なるかもしれませんし、逆に浪費することになるかもしれません; 予習をした場合と
16260しない場合の実行時間を比較して、どちらが速いか調べることが必要でしょう。
16261短い固定文字列 (複雑なパターンの固定部分を含みます) をたくさん検索する
16262ループで、もっとも効果があるでしょう。
16263(この C<study> の仕組みは、まず、検索される文字列内のすべての文字の
16264リンクされたリストが作られ、たとえば、すべての C<'k'> がどこにあるかが
16265わかるようになります。
16266各々の検索文字列から、C プログラムや英語のテキストから作られた頻度の
16267統計情報に基づいて、もっとも珍しい文字が選ばれます。
16268この「珍しい」文字を含む場所だけが調べられるのです。)
1626919040
1627019041=begin original
1627119042
16272For example, here is a loop that inserts index producing entries
19043L<C<state>|/state VARLIST> is available only if the
16273before any line containing a certain pattern:
19044L<C<"state"> feature|feature/The 'state' feature> is enabled or if it is
19045prefixed with C<CORE::>. The
19046L<C<"state"> feature|feature/The 'state' feature> is enabled
19047automatically with a C<use v5.10> (or higher) declaration in the current
19048scope.
1627419049
1627519050=end original
1627619051
16277たとえば、特定のパターンを含む行の前にインデックスを
19052L<C<state>|/state VARLIST> は
16278付けるエントリ入れる例を示します。
19053L<C<"state"> 機能|feature/The 'state' feature> が有効か C<CORE::>
19054前置した場合にのみ利用可能です。
19055L<C<"state"> 機能|feature/The 'state' feature> は現在のスコープで
19056C<use v5.10> (またはそれ以上) を宣言した場合自動的に有効になります。
1627919057
16280 while (<>) {
19058=item study SCALAR
16281 study;
19059X<study>
16282 print ".IX foo\n" if /\bfoo\b/;
16283 print ".IX bar\n" if /\bbar\b/;
16284 print ".IX blurfl\n" if /\bblurfl\b/;
16285 # ...
16286 print;
16287 }
1628819060
19061=item study
19062
19063=for Pod::Functions no-op, formerly optimized input data for repeated searches
19064
1628919065=begin original
1629019066
16291In searching for C</\bfoo\b/>, only locations in C<$_> that contain C<f>
19067At this time, C<study> does nothing. This may change in the future.
16292will be looked at, because C<f> is rarer than C<o>. In general, this is
16293a big win except in pathological cases. The only question is whether
16294it saves you more time than it took to build the linked list in the
16295first place.
1629619068
1629719069=end original
1629819070
16299C<f> C<o> よりいので、C</\bfoo\b/> を探すとき、C<$_> で C<f> を
19071現時点でC<study> は何もしません。
16300含む場所だけが探されま
19072これは将来変更されるかもしれせん
16301一般に、病的な場合を除いて、かなりの結果が得られます。
16302唯一の問題は、節約できる時間が、最初にリンクリストを作る
16303時間よりも多いかどうかです、
1630419073
1630519074=begin original
1630619075
16307Note that if you have to look for strings that you don't know till
19076Prior to Perl version 5.16, it would create an inverted index of all characters
16308runtime, you can build an entire loop as a string and C<eval> that to
19077that occurred in the given SCALAR (or L<C<$_>|perlvar/$_> if unspecified). When
16309avoid recompiling all your patterns all the time. Together with
19078matching a pattern, the rarest character from the pattern would be looked up in
16310undefining C<$/> to input entire files as one record, this can be quite
19079this index. Rarity was based on some static frequency tables constructed from
16311fast, often faster than specialized programs like fgrep(1). The following
19080some C programs and English text.
16312scans a list of files (C<@files>) for a list of words (C<@words>), and prints
16313out the names of those files that contain a match:
1631419081
1631519082=end original
1631619083
16317実行時ま、探そうとする文字列がわからないときには、
19084Perl バージョン 5.16 より前では、
16318ループ全体を文字列とし組み立てて、C<eval> すれば、
19085与えられた SCALAR (または指定されいなかった場合は L<C<$_>|perlvar/$_>)に
16319いつも、すべてのパターンを再コンパイルするという事態は避けられます。
19086現れた全ての文字の転置イデックス作ります。
16320ファイル全体を一つのレコドとて入力するめに
19087パタンにマッチングしたとき
16321C<$/> を未定義にすれば、かり速くなり、
19088パターン中の最も頻度の少い文字がこのインデックスから探されます。
16322多くの場合 fgrep(1) のような専用のプログラムより速くなります。
19089頻度は、C プログラムと英語の文章から構築された静的頻度テーブルを
16323以下の例は、ファイルのリスト (C<@files>) から単語のリスト (C<@words>) を
19090基にしています。
16324探して、マッチするものがあったファイル名を出力します。
1632519091
16326 $search = 'while (<>) { study;';
16327 foreach $word (@words) {
16328 $search .= "++\$seen{\$ARGV} if /\\b$word\\b/;\n";
16329 }
16330 $search .= "}";
16331 @ARGV = @files;
16332 undef $/;
16333 eval $search; # this screams
16334 $/ = "\n"; # put back to normal input delimiter
16335 foreach $file (sort keys(%seen)) {
16336 print $file, "\n";
16337 }
16338
1633919092=item sub NAME BLOCK
1634019093X<sub>
1634119094
1634219095=item sub NAME (PROTO) BLOCK
1634319096
1634419097=item sub NAME : ATTRS BLOCK
1634519098
1634619099=item sub NAME (PROTO) : ATTRS BLOCK
1634719100
1634819101=for Pod::Functions declare a subroutine, possibly anonymously
1634919102
1635019103=begin original
1635119104
1635219105This is subroutine definition, not a real function I<per se>. Without a
1635319106BLOCK it's just a forward declaration. Without a NAME, it's an anonymous
1635419107function declaration, so does return a value: the CODE ref of the closure
1635519108just created.
1635619109
1635719110=end original
1635819111
1635919112これはサブルーチン定義であり、I<本質的には> 実際の関数ではありません。
1636019113BLOCK なしの場合、これは単に前方宣言です。
1636119114NAME なしの場合は、無名関数定義であり、値(作成したブロックの
1636219115コードリファレンス)を返します: 単にクロージャの CODE リファレンスが
1636319116作成されます。
1636419117
1636519118=begin original
1636619119
1636719120See L<perlsub> and L<perlref> for details about subroutines and
1636819121references; see L<attributes> and L<Attribute::Handlers> for more
1636919122information about attributes.
1637019123
1637119124=end original
1637219125
1637319126サブルーチンとリファレンスに関する詳細については、L<perlsub> と
1637419127L<perlref> を参照してください; 属性に関する更なる情報については
1637519128L<attributes> と L<Attribute::Handlers> を参照してください。
1637619129
1637719130=item __SUB__
1637819131X<__SUB__>
1637919132
1638019133=for Pod::Functions +current_sub the current subroutine, or C<undef> if not in a subroutine
1638119134
1638219135=begin original
1638319136
1638419137A special token that returns a reference to the current subroutine, or
16385C<undef> outside of a subroutine.
19138L<C<undef>|/undef EXPR> outside of a subroutine.
1638619139
1638719140=end original
1638819141
1638919142現在のサブルーチンのリファレンスを返す特殊トークン; サブルーチンの外側では
16390C<undef>。
19143L<C<undef>|/undef EXPR>。
1639119144
1639219145=begin original
1639319146
16394The behaviour of C<__SUB__> within a regex code block (such as C</(?{...})/>)
19147The behaviour of L<C<__SUB__>|/__SUB__> within a regex code block (such
16395is subject to change.
19148as C</(?{...})/>) is subject to change.
1639619149
1639719150=end original
1639819151
16399(C</(?{...})/> のような) 正規表現コードブロックの中の C<__SUB__> の振る舞いは
19152(C</(?{...})/> のような) 正規表現コードブロックの中の
16400変更される予定です。
19153L<C<__SUB__>|/__SUB__> の振る舞いは変更される予定です。
1640119154
1640219155=begin original
1640319156
16404This token is only available under C<use v5.16> or the "current_sub"
19157This token is only available under C<use v5.16> or the
16405feature. See L<feature>.
19158L<C<"current_sub"> feature|feature/The 'current_sub' feature>.
19159See L<feature>.
1640619160
1640719161=end original
1640819162
16409このトークンは C<use v5.16> または "current_sub" 機能でのみ利用可能です。
19163このトークンは C<use v5.16> または
19164L<C<"current_sub"> 機能|feature/The 'current_sub' feature> でのみ
19165利用可能です。
1641019166L<feature> を参照してください。
1641119167
1641219168=item substr EXPR,OFFSET,LENGTH,REPLACEMENT
1641319169X<substr> X<substring> X<mid> X<left> X<right>
1641419170
1641519171=item substr EXPR,OFFSET,LENGTH
1641619172
1641719173=item substr EXPR,OFFSET
1641819174
1641919175=for Pod::Functions get or alter a portion of a string
1642019176
1642119177=begin original
1642219178
1642319179Extracts a substring out of EXPR and returns it. First character is at
1642419180offset zero. If OFFSET is negative, starts
1642519181that far back from the end of the string. If LENGTH is omitted, returns
1642619182everything through the end of the string. If LENGTH is negative, leaves that
1642719183many characters off the end of the string.
1642819184
1642919185=end original
1643019186
1643119187EXPR から、部分文字列を取り出して返します。
1643219188最初の文字がオフセット 0 となります。
1643319189OFFSET に負の値を設定すると、EXPR の終わりからのオフセットとなります。
1643419190LENGTH を省略すると、EXPR の最後まですべてが返されます。
1643519191LENGTH が負の値だと、文字列の最後から指定された数だけ文字を取り除きます。
1643619192
1643719193 my $s = "The black cat climbed the green tree";
1643819194 my $color = substr $s, 4, 5; # black
1643919195 my $middle = substr $s, 4, -11; # black cat climbed the
1644019196 my $end = substr $s, 14; # climbed the green tree
1644119197 my $tail = substr $s, -4; # tree
1644219198 my $z = substr $s, -4, 2; # tr
1644319199
1644419200=begin original
1644519201
16446You can use the substr() function as an lvalue, in which case EXPR
19202You can use the L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT>
19203function as an lvalue, in which case EXPR
1644719204must itself be an lvalue. If you assign something shorter than LENGTH,
1644819205the string will shrink, and if you assign something longer than LENGTH,
1644919206the string will grow to accommodate it. To keep the string the same
16450length, you may need to pad or chop your value using C<sprintf>.
19207length, you may need to pad or chop your value using
19208L<C<sprintf>|/sprintf FORMAT, LIST>.
1645119209
1645219210=end original
1645319211
16454substr() を左辺値として使用することも可能で、その場合には、
19212L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> を左辺値として
16455EXPR が自身左辺値でなければなりません。
19213使用することも可能で、その場合には、EXPR が自身左辺値でなければなりません。
1645619214LENGTH より短いものを代入したときには、
1645719215EXPR は短くなり、LENGTH より長いものを代入したときには、
1645819216EXPR はそれに合わせて伸びることになります。
16459EXPR の長さを一定に保つためには、C<sprintf> を使って、
19217EXPR の長さを一定に保つためには、L<C<sprintf>|/sprintf FORMAT, LIST>
16460代入する値の長さを調整することが、必要になるかもしれません。
19218使って、代入する値の長さを調整することが、必要になるかもしれません。
1646119219
1646219220=begin original
1646319221
1646419222If OFFSET and LENGTH specify a substring that is partly outside the
1646519223string, only the part within the string is returned. If the substring
16466is beyond either end of the string, substr() returns the undefined
19224is beyond either end of the string,
19225L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> returns the undefined
1646719226value and produces a warning. When used as an lvalue, specifying a
1646819227substring that is entirely outside the string raises an exception.
1646919228Here's an example showing the behavior for boundary cases:
1647019229
1647119230=end original
1647219231
1647319232OFFSET と LENGTH として文字列の外側を含むような部分文字列が指定されると、
1647419233文字列の内側の部分だけが返されます。
16475部分文字列が文字列の両端の外側の場合、substr() は未定義値を返し、
19234部分文字列が文字列の両端の外側の場合、
19235L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> は未定義値を返し、
1647619236警告が出力されます。
1647719237左辺値として使った場合、文字列の完全に外側を部分文字列として指定すると
1647819238例外が発生します。
1647919239以下は境界条件の振る舞いを示す例です:
1648019240
1648119241 my $name = 'fred';
1648219242 substr($name, 4) = 'dy'; # $name is now 'freddy'
1648319243 my $null = substr $name, 6, 2; # returns "" (no warning)
1648419244 my $oops = substr $name, 7; # returns undef, with warning
1648519245 substr($name, 7) = 'gap'; # raises an exception
1648619246
1648719247=begin original
1648819248
16489An alternative to using substr() as an lvalue is to specify the
19249An alternative to using
16490replacement string as the 4th argument. This allows you to replace
19250L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> as an lvalue is to
19251specify the
19252REPLACEMENT string as the 4th argument. This allows you to replace
1649119253parts of the EXPR and return what was there before in one operation,
16492just as you can with splice().
19254just as you can with
19255L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST>.
1649319256
1649419257=end original
1649519258
16496substr() を左辺値として使う代わりの方法は、置き換える文字列を 4 番目の
19259L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> を左辺値として使う
16497引数として指定することです。
19260代わりの方法は、置き換える文字列を 4 番目の引数として指定することです。
1649819261これにより、EXPR の一部を置き換え、置き換える前が何であったかを返す、
16499ということを(splice() と同様) 1 動作で行えます。
19262ということを(L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> と同様)
192631 動作で行えます。
1650019264
1650119265 my $s = "The black cat climbed the green tree";
1650219266 my $z = substr $s, 14, 7, "jumped from"; # climbed
1650319267 # $s is now "The black cat jumped from the green tree"
1650419268
1650519269=begin original
1650619270
16507Note that the lvalue returned by the three-argument version of substr() acts as
19271Note that the lvalue returned by the three-argument version of
19272L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> acts as
1650819273a 'magic bullet'; each time it is assigned to, it remembers which part
1650919274of the original string is being modified; for example:
1651019275
1651119276=end original
1651219277
165133 引数の substr() によって返された左辺値は「魔法の弾丸」のように振舞うことに
192783 引数の L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> によって返された
16514注意してください; これが代入される毎に、元の文字列のどの部分が変更されたかが
19279左辺値は「魔法の弾丸」のように振舞うことに注意してください;
16515思い出されます; 例えば:
19280これが代入される毎に、元の文字列のどの部分が変更されたかが思い出されます;
19281例えば:
1651619282
16517 $x = '1234';
19283 my $x = '1234';
1651819284 for (substr($x,1,2)) {
1651919285 $_ = 'a'; print $x,"\n"; # prints 1a4
1652019286 $_ = 'xyz'; print $x,"\n"; # prints 1xyz4
1652119287 $x = '56789';
1652219288 $_ = 'pq'; print $x,"\n"; # prints 5pq9
1652319289 }
1652419290
1652519291=begin original
1652619292
1652719293With negative offsets, it remembers its position from the end of the string
1652819294when the target string is modified:
1652919295
1653019296=end original
1653119297
1653219298負数のオフセットの場合、ターゲット文字列が修正されたときに文字列の末尾からの
1653319299位置を覚えます:
1653419300
16535 $x = '1234';
19301 my $x = '1234';
1653619302 for (substr($x, -3, 2)) {
1653719303 $_ = 'a'; print $x,"\n"; # prints 1a4, as above
1653819304 $x = 'abcdefg';
1653919305 print $_,"\n"; # prints f
1654019306 }
1654119307
1654219308=begin original
1654319309
1654419310Prior to Perl version 5.10, the result of using an lvalue multiple times was
1654519311unspecified. Prior to 5.16, the result with negative offsets was
1654619312unspecified.
1654719313
1654819314=end original
1654919315
1655019316バージョン 5.10 より前の Perl では、複数回左辺値を使った場合の結果は
1655119317未定義でした。
16552193185.16 より前では、負のオフセットの結果は未定義です。
1655319319
1655419320=item symlink OLDFILE,NEWFILE
1655519321X<symlink> X<link> X<symbolic link> X<link, symbolic>
1655619322
1655719323=for Pod::Functions create a symbolic link to a file
1655819324
1655919325=begin original
1656019326
1656119327Creates a new filename symbolically linked to the old filename.
1656219328Returns C<1> for success, C<0> otherwise. On systems that don't support
1656319329symbolic links, raises an exception. To check for that,
1656419330use eval:
1656519331
1656619332=end original
1656719333
1656819334NEWFILE として、OLDFILE へのシンボリックリンクを生成します。
1656919335成功時には C<1> を返し、失敗時には C<0> を返します。
1657019336シンボリックリンクをサポートしていないシステムでは、
1657119337例外が発生します。
1657219338これをチェックするには、eval を使用します:
1657319339
16574 $symlink_exists = eval { symlink("",""); 1 };
19340 my $symlink_exists = eval { symlink("",""); 1 };
1657519341
1657619342=begin original
1657719343
1657819344Portability issues: L<perlport/symlink>.
1657919345
1658019346=end original
1658119347
1658219348移植性の問題: L<perlport/symlink>。
1658319349
1658419350=item syscall NUMBER, LIST
1658519351X<syscall> X<system call>
1658619352
1658719353=for Pod::Functions execute an arbitrary system call
1658819354
1658919355=begin original
1659019356
1659119357Calls the system call specified as the first element of the list,
1659219358passing the remaining elements as arguments to the system call. If
1659319359unimplemented, raises an exception. The arguments are interpreted
1659419360as follows: if a given argument is numeric, the argument is passed as
1659519361an int. If not, the pointer to the string value is passed. You are
1659619362responsible to make sure a string is pre-extended long enough to
1659719363receive any result that might be written into a string. You can't use a
16598string literal (or other read-only string) as an argument to C<syscall>
19364string literal (or other read-only string) as an argument to
16599because Perl has to assume that any string pointer might be written
19365L<C<syscall>|/syscall NUMBER, LIST> because Perl has to assume that any
16600through. If your
19366string pointer might be written through. If your
1660119367integer arguments are not literals and have never been interpreted in a
1660219368numeric context, you may need to add C<0> to them to force them to look
16603like numbers. This emulates the C<syswrite> function (or vice versa):
19369like numbers. This emulates the
19370L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> function (or
19371vice versa):
1660419372
1660519373=end original
1660619374
1660719375LIST の最初の要素で指定するシステムコールを、残りの要素をその
1660819376システムコールの引数として呼び出します。
1660919377実装されていない場合には、例外が発生します。
1661019378引数は、以下のように解釈されます: 引数が数字であれば、int として
1661119379引数を渡します。
1661219380そうでなければ、文字列値へのポインタが渡されます。
1661319381文字列に結果を受け取るときには、その結果を受け取るのに十分なくらいに、
1661419382文字列を予め伸ばしておく必要があります。
16615文字列リテラル(あるいはその他の読み込み専用の文字列)を C<syscall> の
19383文字列リテラル(あるいはその他の読み込み専用の文字列)を
16616引数として使うことはできません; Perl は全ての文字列ポインタは書き込まれると
19384L<C<syscall>|/syscall NUMBER, LIST> の引数として使うことはできません;
16617仮定しなければならないからです。
19385Perl は全ての文字列ポインタは書き込まれると仮定しなければならないからです。
16618整数引数が、リテラルでなく、数値コンテキストで評価されたことの
19386整数引数が、リテラルでなく、数値コンテキストで評価されたことのない
16619ないものであれば、数値として解釈されるように、
19387ものであれば、数値として解釈されるように、
1662019388C<0> を足しておく必要があるかもしれません。
16621以下は C<syswrite> 関数(あるいはその逆)をエミュレートします。
19389以下は L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> 関数(あるいは
19390その逆)をエミュレートします。
1662219391
1662319392 require 'syscall.ph'; # may need to run h2ph
16624 $s = "hi there\n";
19393 my $s = "hi there\n";
16625 syscall(&SYS_write, fileno(STDOUT), $s, length $s);
19394 syscall(SYS_write(), fileno(STDOUT), $s, length $s);
1662619395
1662719396=begin original
1662819397
1662919398Note that Perl supports passing of up to only 14 arguments to your syscall,
1663019399which in practice should (usually) suffice.
1663119400
1663219401=end original
1663319402
1663419403Perl は、システムコールに最大 14 個の引数しか渡せませんが、
1663519404(普通は)実用上問題はないでしょう。
1663619405
1663719406=begin original
1663819407
1663919408Syscall returns whatever value returned by the system call it calls.
16640If the system call fails, C<syscall> returns C<-1> and sets C<$!> (errno).
19409If the system call fails, L<C<syscall>|/syscall NUMBER, LIST> returns
19410C<-1> and sets L<C<$!>|perlvar/$!> (errno).
1664119411Note that some system calls I<can> legitimately return C<-1>. The proper
16642way to handle such calls is to assign C<$!=0> before the call, then
19412way to handle such calls is to assign C<$! = 0> before the call, then
16643check the value of C<$!> if C<syscall> returns C<-1>.
19413check the value of L<C<$!>|perlvar/$!> if
19414L<C<syscall>|/syscall NUMBER, LIST> returns C<-1>.
1664419415
1664519416=end original
1664619417
1664719418syscall は、呼び出したシステムコールが返した値を返します。
16648システムコールが失敗すると、C<syscall> は C<-1> を返し、
19419システムコールが失敗すると、L<C<syscall>|/syscall NUMBER, LIST> は C<-1> を
16649C<$!>(errno) を設定します。
19420返し、L<C<$!>|perlvar/$!>(errno) を設定します。
1665019421システムコールが正常に C<-1> を返す I<場合がある> ことに注意してください。
1665119422このようなシステムコールを正しく扱うには、
16652C<$!=0> をシステムコールの前に実行し、それから
19423C<$! = 0> をシステムコールの前に実行し、それから
16653C<syscall> が C<-1> を返した時には C<$!> の値を調べてください。
19424L<C<syscall>|/syscall NUMBER, LIST> が C<-1> を返した時には
19425L<C<$!>|perlvar/$!> の値を調べてください。
1665419426
1665519427=begin original
1665619428
16657There's a problem with C<syscall(&SYS_pipe)>: it returns the file
19429There's a problem with C<syscall(SYS_pipe())>: it returns the file
1665819430number of the read end of the pipe it creates, but there is no way
1665919431to retrieve the file number of the other end. You can avoid this
16660problem by using C<pipe> instead.
19432problem by using L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> instead.
1666119433
1666219434=end original
1666319435
16664C<syscall(&SYS_pipe)> には問題があり、
19436C<syscall(&SYS_pipe)> には問題があり、作ったパイプの、読み出し側の
16665作ったパイプの、読み出し側のファイル番号を返しますが、
19437ファイル番号を返しますが、もう一方のファイル番号を得る方法がありません。
16666もう一方ファイル番号方法があません。
19438問題避けためには、代わに L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> を
16667この問題を避けるためには、代わりに C<pipe> を使ってください。
19439使ってください。
1666819440
1666919441=begin original
1667019442
1667119443Portability issues: L<perlport/syscall>.
1667219444
1667319445=end original
1667419446
1667519447移植性の問題: L<perlport/syscall>。
1667619448
1667719449=item sysopen FILEHANDLE,FILENAME,MODE
1667819450X<sysopen>
1667919451
1668019452=item sysopen FILEHANDLE,FILENAME,MODE,PERMS
1668119453
1668219454=for Pod::Functions +5.002 open a file, pipe, or descriptor
1668319455
1668419456=begin original
1668519457
1668619458Opens the file whose filename is given by FILENAME, and associates it with
1668719459FILEHANDLE. If FILEHANDLE is an expression, its value is used as the real
1668819460filehandle wanted; an undefined scalar will be suitably autovivified. This
16689function calls the underlying operating system's I<open>(2) function with the
19461function calls the underlying operating system's L<open(2)> function with the
1669019462parameters FILENAME, MODE, and PERMS.
1669119463
1669219464=end original
1669319465
1669419466FILENAME で与えられたファイル名のファイルをオープンし、
1669519467FILEHANDLE と結び付けます。
1669619468FILEHANDLE が式の場合、その値は実際の求めているファイルハンドルの名前として
1669719469扱われます; 未定義のスカラは適切に自動有効化されます。
16698この関数呼び出しはシステムの I<open>(2) 関数を FILENAME, MODE, PERMS の
19470この関数呼び出しはシステムの L<open(2)> 関数を FILENAME, MODE, PERMS の
1669919471引数で呼び出すことを基礎としています。
1670019472
1670119473=begin original
1670219474
19475Returns true on success and L<C<undef>|/undef EXPR> otherwise.
19476
19477=end original
19478
19479成功時は真を、さもなければ L<C<undef>|/undef EXPR> を返します。
19480
19481=begin original
19482
19483L<PerlIO> layers will be applied to the handle the same way they would in an
19484L<C<open>|/open FILEHANDLE,MODE,EXPR> call that does not specify layers. That is,
19485the current value of L<C<${^OPEN}>|perlvar/${^OPEN}> as set by the L<open>
19486pragma in a lexical scope, or the C<-C> commandline option or C<PERL_UNICODE>
19487environment variable in the main program scope, falling back to the platform
19488defaults as described in L<PerlIO/Defaults and how to override them>. If you
19489want to remove any layers that may transform the byte stream, use
19490L<C<binmode>|/binmode FILEHANDLE, LAYER> after opening it.
19491
19492=end original
19493
19494L<PerlIO> 層は、層を指定しない L<C<open>|/open FILEHANDLE,MODE,EXPR>
19495呼び出しでするのと同じ方法でハンドルに適用されます。
19496これは、レキシカルスコープの L<open> プラグマで設定された
19497L<C<${^OPEN}>|perlvar/${^OPEN}> の現在の値、
19498またはメインプログラムスコープの C<-C> コマンドラインオプションまたは
19499C<PERL_UNICODE> 環境変数、L<PerlIO/Defaults and how to override them> で
19500記述されているようにプラットフォームのデフォルトに
19501フォールバックしたものです。
19502バイトストリームを変換する全ての層を除去したい場合は、
19503それを開いた後に L<C<binmode>|/binmode FILEHANDLE, LAYER> を使ってください。
19504
19505=begin original
19506
1670319507The possible values and flag bits of the MODE parameter are
16704system-dependent; they are available via the standard module C<Fcntl>. See
19508system-dependent; they are available via the standard module
16705the documentation of your operating system's I<open>(2) syscall to see
19509L<C<Fcntl>|Fcntl>. See the documentation of your operating system's
19510L<open(2)> syscall to see
1670619511which values and flag bits are available. You may combine several flags
1670719512using the C<|>-operator.
1670819513
1670919514=end original
1671019515
1671119516MODE パラメータに指定できるフラグビットと値はシステム依存です;
16712これは標準モジュール C<Fcntl> 経由で利用可能です。
19517これは標準モジュール L<C<Fcntl>|Fcntl> 経由で利用可能です。
1671319518どのようなフラグビットと値が利用可能であるかについては、
16714OS の I<open>(2) システムコールに関する文書を参照してください。
19519OS の L<open(2)> システムコールに関する文書を参照してください。
1671519520C<|> 演算子を使って複数のフラグを結合することができます。
1671619521
1671719522=begin original
1671819523
1671919524Some of the most common values are C<O_RDONLY> for opening the file in
1672019525read-only mode, C<O_WRONLY> for opening the file in write-only mode,
1672119526and C<O_RDWR> for opening the file in read-write mode.
1672219527X<O_RDONLY> X<O_RDWR> X<O_WRONLY>
1672319528
1672419529=end original
1672519530
1672619531もっともよく使われる値は、ファイルを読み込み専用で開く C<O_RDONLY>、
1672719532ファイルを書き込み専用で開く C<O_WRONLY>、
1672819533ファイルを読み書き両用で開く C<O_RDWR> です。
1672919534X<O_RDONLY> X<O_RDWR> X<O_WRONLY>
1673019535
1673119536=begin original
1673219537
1673319538For historical reasons, some values work on almost every system
1673419539supported by Perl: 0 means read-only, 1 means write-only, and 2
1673519540means read/write. We know that these values do I<not> work under
16736OS/390 and on the Macintosh; you probably don't want to
19541OS/390; you probably don't want to use them in new code.
16737use them in new code.
1673819542
1673919543=end original
1674019544
1674119545歴史的な理由により、Perl が対応しているほとんどのシステムで使える値が
1674219546あります:0 は読み込み専用、1 は書き込み専用、2 は読み書き両用を意味します。
16743OS/390 と Macintosh では動作 I<しない> ことが分かっています;
19547OS/390 では動作 I<しない> ことが分かっています;
1674419548新しく書くコードではこれらは使わないほうがよいでしょう。
1674519549
1674619550=begin original
1674719551
16748If the file named by FILENAME does not exist and the C<open> call creates
19552If the file named by FILENAME does not exist and the
19553L<C<open>|/open FILEHANDLE,MODE,EXPR> call creates
1674919554it (typically because MODE includes the C<O_CREAT> flag), then the value of
1675019555PERMS specifies the permissions of the newly created file. If you omit
16751the PERMS argument to C<sysopen>, Perl uses the octal value C<0666>.
19556the PERMS argument to L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>,
19557Perl uses the octal value C<0666>.
1675219558These permission values need to be in octal, and are modified by your
16753process's current C<umask>.
19559process's current L<C<umask>|/umask EXPR>.
1675419560X<O_CREAT>
1675519561
1675619562=end original
1675719563
1675819564FILENAME という名前のファイルが存在せず、(典型的には MODE が
16759C<O_CREAT> フラグを含んでいたために) C<open> 呼び出しがそれを作った場合、
19565C<O_CREAT> フラグを含んでいたために)
19566L<C<open>|/open FILEHANDLE,MODE,EXPR> 呼び出しがそれを作った場合、
1676019567PERMS の値は新しく作られたファイルの権限を指定します。
16761C<sysopen> の PERMS 引数を省略した場合、Perl は 8 進数 C<0666> を使います。
19568L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> の PERMS 引数を省略した場合、
16762これらの権限は 8 進数である必要があり、プロセスの現在の C<umask>
19569Perl は 8 進数 C<0666> を使います。
16763修正さます。
19570らの権限は 8 進数である必要があり、プロセスの現在の
19571L<C<umask>|/umask EXPR> で修正されます。
1676419572X<O_CREAT>
1676519573
1676619574=begin original
1676719575
1676819576In many systems the C<O_EXCL> flag is available for opening files in
1676919577exclusive mode. This is B<not> locking: exclusiveness means here that
16770if the file already exists, sysopen() fails. C<O_EXCL> may not work
19578if the file already exists,
19579L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> fails. C<O_EXCL> may
19580not work
1677119581on network filesystems, and has no effect unless the C<O_CREAT> flag
1677219582is set as well. Setting C<O_CREAT|O_EXCL> prevents the file from
1677319583being opened if it is a symbolic link. It does not protect against
1677419584symbolic links in the file's path.
1677519585X<O_EXCL>
1677619586
1677719587=end original
1677819588
1677919589多くのシステムではファイルを排他モードで開くために C<O_EXCL> が
1678019590利用可能です。
1678119591これはロック B<ではありません>: 排他性というのは既にファイルが
16782存在していた場合、sysopen()失敗することを意味します。
19592存在していた場合、L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>
19593失敗することを意味します。
1678319594C<O_EXCL> はネットワークファイルシステムでは動作せず、
1678419595またC<O_CREAT> フラグも有効でない限りは効果がありません。
1678519596C<O_CREAT|O_EXCL> をセットすると、これがシンボリックリンクだった場合は
1678619597ファイルを開くことを妨げます。
1678719598これはファイルパス中のシンボリックリンクは守りません。
1678819599X<O_EXCL>
1678919600
1679019601=begin original
1679119602
1679219603Sometimes you may want to truncate an already-existing file. This
1679319604can be done using the C<O_TRUNC> flag. The behavior of
1679419605C<O_TRUNC> with C<O_RDONLY> is undefined.
1679519606X<O_TRUNC>
1679619607
1679719608=end original
1679819609
1679919610既に存在しているファイルを切り詰めたい場合もあるかもしれません。
1680019611これは C<O_TRUNC> フラグを使うことで行えます。
1680119612C<O_RDONLY> と C<O_TRUNC> を同時に指定したときの振る舞いは未定義です。
1680219613X<O_TRUNC>
1680319614
1680419615=begin original
1680519616
16806You should seldom if ever use C<0644> as argument to C<sysopen>, because
19617You should seldom if ever use C<0644> as argument to
19618L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>, because
1680719619that takes away the user's option to have a more permissive umask.
16808Better to omit it. See the perlfunc(1) entry on C<umask> for more
19620Better to omit it. See L<C<umask>|/umask EXPR> for more on this.
16809on this.
1681019621
1681119622=end original
1681219623
16813めったなことでは C<sysopen> の引数に C<0644> を指定するべきではないでしょう:
19624めったなことでは L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> の引数に
19625C<0644> を指定するべきではないでしょう:
1681419626ユーザーがより寛大な umask を指定する選択肢を奪うからです。
1681519627省略した方がいいです。
16816これに関するさらなる情報については perlfunc(1) の C<umask> を
19628これに関するさらなる情報については L<C<umask>|/umask EXPR> を
1681719629参照してください。
1681819630
1681919631=begin original
1682019632
16821Note that C<sysopen> depends on the fdopen() C library function.
19633This function has no direct relation to the usage of
16822On many Unix systems, fdopen() is known to fail when file descriptors
19634L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
16823exceed a certain value, typically 255. If you need more file
19635L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
16824descriptors than that, consider rebuilding Perl to use the C<sfio>
19636or L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>. A handle opened with
16825library, or perhaps using the POSIX::open() function.
19637this function can be used with buffered IO just as one opened with
19638L<C<open>|/open FILEHANDLE,MODE,EXPR> can be used with unbuffered IO.
1682619639
1682719640=end original
1682819641
16829C<sysopen> は C fdopen() ライブラリ関数に依存していることに注意してください。
19642の関数は、
16830多くの Unix システムでは、fdopen() はファイル記述子がある値(例えば 255)を超えると
19643L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
16831失敗することが知られています。
19644L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
19645L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> の使用法と
19646直接の関係はありません。
19647この関数で開かれたハンドルがバッファリングされた IO で使えるのと同様、
19648L<C<open>|/open FILEHANDLE,MODE,EXPR> で開かれたものは
19649バッファリングされない IO で使えます。
19650
19651=begin original
19652
19653Note that under Perls older than 5.8.0,
19654L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> depends on the
19655L<fdopen(3)> C library function. On many Unix systems, L<fdopen(3)> is known
19656to fail when file descriptors exceed a certain value, typically 255. If
19657you need more file descriptors than that, consider using the
19658L<C<POSIX::open>|POSIX/C<open>> function. For Perls 5.8.0 and later,
19659PerlIO is (most often) the default.
19660
19661=end original
19662
196635.8.0 より古い Perl では、
19664L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> は
19665C の L<fdopen(3)> ライブラリ関数に依存していることに注意してください。
19666多くの Unix システムでは、L<fdopen(3)> はファイル記述子がある値(例えば 255)を
19667超えると失敗することが知られています。
1683219668これより多くのファイル記述子が必要な場合は、
16833Perl を C<sfio> ライブラリを使再ビルドするか、
19669L<C<POSIX::open>|POSIX/C<open>> 関数を使うことを検討しください。
16834POSIX::open() 関数を使うことを健闘してください
196705.8.0 以降の Perl では、(ほぼ確実に) PerlIO がデフォルトです
1683519671
1683619672=begin original
1683719673
1683819674See L<perlopentut> for a kinder, gentler explanation of opening files.
1683919675
1684019676=end original
1684119677
16842ファイル操作に関するより親切な説明については L<perlopentut> を参照してください。
19678ファイルを開くことに関するより親切な説明については L<perlopentut> を
19679参照してください。
1684319680
1684419681=begin original
1684519682
1684619683Portability issues: L<perlport/sysopen>.
1684719684
1684819685=end original
1684919686
1685019687移植性の問題: L<perlport/sysopen>。
1685119688
1685219689=item sysread FILEHANDLE,SCALAR,LENGTH,OFFSET
1685319690X<sysread>
1685419691
1685519692=item sysread FILEHANDLE,SCALAR,LENGTH
1685619693
1685719694=for Pod::Functions fixed-length unbuffered input from a filehandle
1685819695
1685919696=begin original
1686019697
1686119698Attempts to read LENGTH bytes of data into variable SCALAR from the
16862specified FILEHANDLE, using the read(2). It bypasses
19699specified FILEHANDLE, using L<read(2)>. It bypasses any L<PerlIO> layers
16863buffered IO, so mixing this with other kinds of reads, C<print>,
19700including buffered IO (but is affected by the presence of the C<:utf8>
16864C<write>, C<seek>, C<tell>, or C<eof> can cause confusion because the
19701layer as described later), so mixing this with other kinds of reads,
16865perlio or stdio layers usually buffers data. Returns the number of
19702L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
19703L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
19704L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> can cause
19705confusion because the
19706C<:perlio> or C<:crlf> layers usually buffer data. Returns the number of
1686619707bytes actually read, C<0> at end of file, or undef if there was an
16867error (in the latter case C<$!> is also set). SCALAR will be grown or
19708error (in the latter case L<C<$!>|perlvar/$!> is also set). SCALAR will
19709be grown or
1686819710shrunk so that the last byte actually read is the last byte of the
1686919711scalar after the read.
1687019712
1687119713=end original
1687219714
16873read(2) を用いて、指定した FILEHANDLE から、変数 SCALAR へ、LENGTH バイトの
19715L<read(2)> を用いて、指定した FILEHANDLE から、変数 SCALAR へ、LENGTH バイトの
1687419716データの読み込みを試みます。
16875これは、バッファ付き IO ルーチンを通りませんから、他入力関数, C<print>,
19717これは、バッファ付き IO ルーチンを含むどL<PerlIO> も通らないので
16876C<write>, C<seek>, C<tell>, C<eof> と混ぜて使うと、入力がおかしくなるかも
19718(しかし、後述するように C<:utf8> の存在の影響を受けます)他の入力関数、
16877しれません; perlio 層や stdio 層は普通データをバッファリングするからです。
19719L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
16878ファイルの最後では C<0>が、エラー時には undef が、
19720L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>,
16879それ以外では実際に読み込まれたデータの長さが返されます (後者の場合は C<$!> も
19721L<C<eof>|/eof FILEHANDLE> と混ぜて使うと、入力がおかしくなるか
19722しれません;
19723C<:perlio> 層や C<:crlf> 層は普通データをバッファリングするからです。
19724ファイルの最後では C<0>が、エラー時には undef が、それ以外では実際に
19725読み込まれたデータの長さが返されます (後者の場合は L<C<$!>|perlvar/$!> も
1688019726セットされます)。
1688119727実際に読み込んだ最後のバイトが read した後の最後のバイトになるので、
1688219728SCALAR は伸び縮みします。
1688319729
1688419730=begin original
1688519731
1688619732An OFFSET may be specified to place the read data at some place in the
1688719733string other than the beginning. A negative OFFSET specifies
1688819734placement at that many characters counting backwards from the end of
1688919735the string. A positive OFFSET greater than the length of SCALAR
1689019736results in the string being padded to the required size with C<"\0">
1689119737bytes before the result of the read is appended.
1689219738
1689319739=end original
1689419740
16895OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行なうことが
19741OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行なえます。
16896できます。
1689719742OFFSET に負の値を指定すると、文字列の最後から逆向きに何文字目かで
1689819743位置を指定します。
16899OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は
19744OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は読み込みの結果が
16900読み込みの結果が追加される前に、必要なサイズまで C<"\0"> のバイトで
19745追加される前に、必要なサイズまで C<"\0"> のバイトでパッディングされます。
16901パッディングされます。
1690219746
1690319747=begin original
1690419748
16905There is no syseof() function, which is ok, since eof() doesn't work
19749There is no syseof() function, which is ok, since
16906well on device files (like ttys) anyway. Use sysread() and check
19750L<C<eof>|/eof FILEHANDLE> doesn't work well on device files (like ttys)
16907for a return value for 0 to decide whether you're done.
19751anyway. Use L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> and
19752check for a return value of 0 to decide whether you're done.
1690819753
1690919754=end original
1691019755
16911syseof() 関数はありませんが、問題ありません; どちらにしろ eof() は
19756syseof() 関数はありませんが、問題ありません; どちらにしろ
19757L<C<eof>|/eof FILEHANDLE> は
1691219758(tty のような)デバイスファイルに対してはうまく動作しないからです。
16913sysread() を使って、 返り値が 0 かどうかで最後まで読んだかを
19759L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を使って、
16914判断してください。
19760返り値が 0 かどうかで最後まで読んだかを判断してください。
1691519761
1691619762=begin original
1691719763
16918Note that if the filehandle has been marked as C<:utf8> Unicode
19764Note that if the filehandle has been marked as C<:utf8>, C<sysread> will
16919characters are read instead of bytes (the LENGTH, OFFSET, and the
19765throw an exception. The C<:encoding(...)> layer implicitly
16920return value of sysread() are in Unicode characters).
19766introduces the C<:utf8> layer. See
16921The C<:encoding(...)> layer implicitly introduces the C<:utf8> layer.
19767L<C<binmode>|/binmode FILEHANDLE, LAYER>,
16922See L</binmode>, L</open>, and the C<open> pragma, L<open>.
19768L<C<open>|/open FILEHANDLE,MODE,EXPR>, and the L<open> pragma.
1692319769
1692419770=end original
1692519771
16926ファイルハンドルが C<:utf8> であるとマークが付けられると、バイトではなく
19772ファイルハンドルが C<:utf8> であるとマークが付けられていると、
16927Unicode 文字が読み込まれます (sysread() の LENGTH, OFFSET および返り値
19773C<sysread>例外を投げます。
16928Unicode 文字なります)
19774C<:encoding(...)> 層は暗黙 C<:utf8> 層を導入します。
16929C<:encoding(...)> 層は暗黙のうちに C<:utf8> 層が導入されます。
19775L<C<binmode>|/binmode FILEHANDLE, LAYER>,
16930L</binmode>, L</open>, C<open> プラグマ, L<open> を参照してください。
19776L<C<open>|/open FILEHANDLE,MODE,EXPR>, L<open> プラグマを参照してください。
1693119777
1693219778=item sysseek FILEHANDLE,POSITION,WHENCE
1693319779X<sysseek> X<lseek>
1693419780
1693519781=for Pod::Functions +5.004 position I/O pointer on handle used with sysread and syswrite
1693619782
1693719783=begin original
1693819784
16939Sets FILEHANDLE's system position in bytes using lseek(2). FILEHANDLE may
19785Sets FILEHANDLE's system position I<in bytes> using L<lseek(2)>. FILEHANDLE may
1694019786be an expression whose value gives the name of the filehandle. The values
16941for WHENCE are C<0> to set the new position to POSITION; C<1> to set the it
19787for WHENCE are C<0> to set the new position to POSITION; C<1> to set it
1694219788to the current position plus POSITION; and C<2> to set it to EOF plus
1694319789POSITION, typically negative.
1694419790
1694519791=end original
1694619792
16947FILEHANDLE のシステム位置をバイト単位で lseek(2) を使って設定します。
19793FILEHANDLE のシステム位置を I<バイト単位> L<lseek(2)> を使って設定します。
1694819794FILEHANDLE は、実際のファイルハンドル名を与える式でもかまいません。
1694919795WHENCE の値が、C<0> ならば、新しい位置を POSITION の位置へ設定します;
1695019796C<1> ならば、現在位置から POSITION 加えた位置へ設定します; C<2> ならば、
1695119797EOF から POSITION だけ(普通は負の数です)加えた位置へ、新しい位置を
1695219798設定します。
1695319799
1695419800=begin original
1695519801
16956Note the I<in bytes>: even if the filehandle has been set to operate
19802Note the emphasis on bytes: even if the filehandle has been set to operate
16957on characters (for example by using the C<:encoding(utf8)> I/O layer),
19803on characters (for example using the C<:encoding(UTF-8)> I/O layer), the
16958tell() will return byte offsets, not character offsets (because
19804L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
16959implementing that would render sysseek() unacceptably slow).
19805L<C<tell>|/tell FILEHANDLE>, and
19806L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>
19807family of functions use byte offsets, not character offsets,
19808because seeking to a character offset would be very slow in a UTF-8 file.
1696019809
1696119810=end original
1696219811
16963I<バイト単位> する注意: 文字単位で扱ようにファイルハンドルが
19812バイト単位にする注意: 例え(例えば C<:encoding(UTF-8)> I/O 層を使などして)
16964設定されている場合(C<:encoding(utf8)> I/O 層を使っいる場合など)でも、
19813ファイルハンドルが文字単位で処理するように設定されていたとしても、
16965tell() は文字のオフセットではなくバイトのオフセットを返します
19814L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
16966(なぜならこれを実装すると sysseek() が受け入れられないほど
19815L<C<tell>|/tell FILEHANDLE>,
16967遅くなるからです)。
19816L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> シリーズの関数は
19817文字オフセットではなくバイトオフセットを使います;
19818文字オフセットでシークするのは UTF-8 ファイルではとても遅いからです。
1696819819
1696919820=begin original
1697019821
16971sysseek() bypasses normal buffered IO, so mixing it with reads other
19822L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> bypasses normal
16972than C<sysread> (for example C<< <> >> or read()) C<print>, C<write>,
19823buffered IO, so mixing it with reads other than
16973C<seek>, C<tell>, or C<eof> may cause confusion.
19824L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> (for example
19825L<C<readline>|/readline EXPR> or
19826L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>),
19827L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
19828L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
19829L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> may cause
19830confusion.
1697419831
1697519832=end original
1697619833
16977sysseek() は普通のバッファ付き IO をバイパスしますので、
19834L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> は普通のバッファ付き IO を
16978C<sysread> 以外 (例えば C<< <> >> や read() の)読み込み
19835バイパスします
16979C<print>, C<write>, C<seek>, C<tell>, C<eof> と混ぜて使うと
19836L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> 以外の (例えば
16980混乱を引き起こします。
19837L<C<readline>|/readline EXPR> や
19838L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> の)読み込み、
19839L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
19840L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>,
19841L<C<eof>|/eof FILEHANDLE> と混ぜて使うと混乱を引き起こします。
1698119842
1698219843=begin original
1698319844
1698419845For WHENCE, you may also use the constants C<SEEK_SET>, C<SEEK_CUR>,
1698519846and C<SEEK_END> (start of the file, current position, end of the file)
16986from the Fcntl module. Use of the constants is also more portable
19847from the L<Fcntl> module. Use of the constants is also more portable
1698719848than relying on 0, 1, and 2. For example to define a "systell" function:
1698819849
1698919850=end original
1699019851
16991WHENCE には、Fcntl モジュールで使われている C<SEEK_SET>, C<SEEK_CUR>,
19852WHENCE には、L<Fcntl> モジュールで使われている C<SEEK_SET>, C<SEEK_CUR>,
1699219853C<SEEK_END> (ファイルの先頭、現在位置、ファイルの最後)という定数を
1699319854使うこともできます。
1699419855定数の使用は 0, 1, 2 に依存するよりも移植性があります。
1699519856例えば "systell" 関数を定義するには:
1699619857
1699719858 use Fcntl 'SEEK_CUR';
1699819859 sub systell { sysseek($_[0], 0, SEEK_CUR) }
1699919860
1700019861=begin original
1700119862
1700219863Returns the new position, or the undefined value on failure. A position
17003of zero is returned as the string C<"0 but true">; thus C<sysseek> returns
19864of zero is returned as the string C<"0 but true">; thus
19865L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> returns
1700419866true on success and false on failure, yet you can still easily determine
1700519867the new position.
1700619868
1700719869=end original
1700819870
1700919871新しい位置を返します; 失敗したときは未定義値を返します。
1701019872位置がゼロの場合は、C<"0 but true"> の文字列として返されます; 従って
17011C<sysseek> は成功時に真を返し、失敗時に偽を返しますが、簡単に新しい位置を
19873L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> は成功時に真を返し、
17012判定できます。
19874失敗時に偽を返しますが、簡単に新しい位置を判定できます。
1701319875
1701419876=item system LIST
1701519877X<system> X<shell>
1701619878
1701719879=item system PROGRAM LIST
1701819880
1701919881=for Pod::Functions run a separate program
1702019882
1702119883=begin original
1702219884
17023Does exactly the same thing as C<exec LIST>, except that a fork is
19885Does exactly the same thing as L<C<exec>|/exec LIST>, except that a fork is
1702419886done first and the parent process waits for the child process to
1702519887exit. Note that argument processing varies depending on the
1702619888number of arguments. If there is more than one argument in LIST,
1702719889or if LIST is an array with more than one value, starts the program
1702819890given by the first element of the list with arguments given by the
1702919891rest of the list. If there is only one scalar argument, the argument
1703019892is checked for shell metacharacters, and if there are any, the
1703119893entire argument is passed to the system's command shell for parsing
1703219894(this is C</bin/sh -c> on Unix platforms, but varies on other
1703319895platforms). If there are no shell metacharacters in the argument,
1703419896it is split into words and passed directly to C<execvp>, which is
17035more efficient.
19897more efficient. On Windows, only the C<system PROGRAM LIST> syntax will
19898reliably avoid using the shell; C<system LIST>, even with more than one
19899element, will fall back to the shell if the first spawn fails.
1703619900
1703719901=end original
1703819902
17039C<exec LIST> とほとんど同じですが、まず fork を行ない、
19903L<C<exec>|/exec LIST> とほとんど同じですが、まず fork を行ない、
1704019904親プロセスではチャイルドプロセスが終了するのを wait します。
1704119905exec の項で述べたように、引数の処理は、引数の数によって異なることに
1704219906注意してください。
1704319907LIST に複数の引数がある場合、または LIST が複数の要素からなる配列の場合、
1704419908リストの最初の要素で与えられるプログラムを、リストの残りの要素を引数として
1704519909起動します。
1704619910スカラの引数が一つだけの場合、引数はシェルのメタ文字をチェックされ、もし
1704719911あればパースのために引数全体がシステムコマンドシェル (これは
1704819912Unix プラットフォームでは C</bin/sh -c> ですが、他のプラットフォームでは
1704919913異なります)に渡されます。
1705019914シェルのメタ文字がなかった場合、引数は単語に分解されて直接 C<execvp> に
1705119915渡されます; この方がより効率的です。
19916Windows では、C<system PROGRAM LIST> 構文のみが安定してシェルの使用を
19917回避します; C<system LIST> は、2 要素以上でも、最初の spawn が失敗すると
19918シェルにフォールバックします。
1705219919
1705319920=begin original
1705419921
1705519922Perl will attempt to flush all files opened for
1705619923output before any operation that may do a fork, but this may not be
1705719924supported on some platforms (see L<perlport>). To be safe, you may need
17058to set C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method
19925to set L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>)
17059of C<IO::Handle> on any open handles.
19926or call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS>
19927on any open handles.
1706019928
1706119929=end original
1706219930
17063v5.6.0 から、Perl は書き込み用に開いている全てのファイルに対して
19931Perl は書き込み用に開いている全てのファイルに対して
1706419932fork を行う前にフラッシュしようとしますが、これに対応していない
1706519933プラットフォームもあります(L<perlport> を参照してください)。
17066安全のために、C<$|> (English モジュールでは $AUTOFLUSH) をセットするか、
19934安全のために、L<C<$E<verbar>>|perlvar/$E<verbar>> (L<English> モジュールでは
17067全ての開いているハンドルに対して C<IO::Handle> の C<autoflush()> メソッドを
19935C<$AUTOFLUSH>) をセットするか、全ての開いているハンドルに対して
19936L<C<IO::Handle>|IO::Handle/METHODS> の C<autoflush> メソッドを
1706819937呼び出す必要があるかもしれません。
1706919938
1707019939=begin original
1707119940
1707219941The return value is the exit status of the program as returned by the
17073C<wait> call. To get the actual exit value, shift right by eight (see
19942L<C<wait>|/wait> call. To get the actual exit value, shift right by
17074below). See also L</exec>. This is I<not> what you want to use to capture
19943eight (see below). See also L<C<exec>|/exec LIST>. This is I<not> what
17075the output from a command; for that you should use merely backticks or
19944you want to use to capture the output from a command; for that you
17076C<qx//>, as described in L<perlop/"`STRING`">. Return value of -1
19945should use merely backticks or
17077indicates a failure to start the program or an error of the wait(2) system
19946L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>>, as described in
17078call (inspect $! for the reason).
19947L<perlop/"`STRING`">. Return value of -1 indicates a failure to start
19948the program or an error of the L<wait(2)> system call (inspect
19949L<C<$!>|perlvar/$!> for the reason).
1707919950
1708019951=end original
1708119952
17082返り値は、C<wait> が返すプログラムの exit 状態です。
19953返り値は、L<C<wait>|/wait> が返すプログラムの exit 状態です。
1708319954実際の exit 値を得るには 右に 8 ビットシフトしてください(後述)。
17084L</exec> も参照してください。
19955L<C<exec>|/exec LIST> も参照してください。
1708519956これはコマンドからの出力を捕らえるために使うものI<ではありません>;
1708619957そのような用途には、L<perlop/"`STRING`"> に記述されている
17087逆クォートや C<qx//> を使用してください。
19958逆クォートや L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>> を使用してください。
17088-1 の返り値はプログラムを開始させることに失敗したか、wait(2)
19959-1 の返り値はプログラムを開始させることに失敗したか、L<wait(2)>
1708919960システムコールがエラーを出したことを示します
17090(理由は $! を調べてください)。
19961(理由は L<C<$!>|perlvar/$!> を調べてください)。
1709119962
1709219963=begin original
1709319964
17094If you'd like to make C<system> (and many other bits of Perl) die on error,
19965If you'd like to make L<C<system>|/system LIST> (and many other bits of
17095have a look at the L<autodie> pragma.
19966Perl) die on error, have a look at the L<autodie> pragma.
1709619967
1709719968=end original
1709819969
17099もし C<system> (及び Perl のその他の多くの部分) でエラー時に
19970もし L<C<system>|/system LIST> (及び Perl のその他の多くの部分) でエラー時に
1710019971die したいなら、L<autodie> プラグマを見てみてください。
1710119972
1710219973=begin original
1710319974
17104Like C<exec>, C<system> allows you to lie to a program about its name if
19975Like L<C<exec>|/exec LIST>, L<C<system>|/system LIST> allows you to lie
17105you use the C<system PROGRAM LIST> syntax. Again, see L</exec>.
19976to a program about its name if you use the C<system PROGRAM LIST>
19977syntax. Again, see L<C<exec>|/exec LIST>.
1710619978
1710719979=end original
1710819980
17109C<exec> と同様に、C<system> でも C<system PROGRAM LIST> の文法を
19981L<C<exec>|/exec LIST> と同様に、L<C<system>|/system LIST> でも
17110使うことで、プログラムに対してその名前を嘘をつくことができます。
19982C<system PROGRAM LIST> の文法を使うことで、プログラムに対してその名前を
17111再び、L</exec> 参照してださい
19983ことができます
19984再び、L<C<exec>|/exec LIST> を参照してください。
1711219985
1711319986=begin original
1711419987
1711519988Since C<SIGINT> and C<SIGQUIT> are ignored during the execution of
17116C<system>, if you expect your program to terminate on receipt of these
19989L<C<system>|/system LIST>, if you expect your program to terminate on
17117signals you will need to arrange to do so yourself based on the return
19990receipt of these signals you will need to arrange to do so yourself
17118value.
19991based on the return value.
1711919992
1712019993=end original
1712119994
17122C<SIGINT> と C<SIGQUIT> は C<system> の実行中は無視されるので、
19995C<SIGINT> と C<SIGQUIT> は L<C<system>|/system LIST> の実行中は無視されるので、
1712319996これらのシグナルを受信して終了させることを想定したプログラムの場合、
1712419997返り値を利用するように変更する必要があります。
1712519998
17126 @args = ("command", "arg1", "arg2");
19999 my @args = ("command", "arg1", "arg2");
1712720000 system(@args) == 0
17128 or die "system @args failed: $?"
20001 or die "system @args failed: $?";
1712920002
1713020003=begin original
1713120004
17132If you'd like to manually inspect C<system>'s failure, you can check all
20005If you'd like to manually inspect L<C<system>|/system LIST>'s failure,
17133possible failure modes by inspecting C<$?> like this:
20006you can check all possible failure modes by inspecting
20007L<C<$?>|perlvar/$?> like this:
1713420008
1713520009=end original
1713620010
17137C<system> の失敗を手動で検査したいなら、
20011L<C<system>|/system LIST> の失敗を手動で検査したいなら、以下のように
17138以下のように C<$?> を調べることで、全ての失敗の可能性を
20012L<C<$?>|perlvar/$?> を調べることで、全ての失敗の可能性をチェックできます:
17139チェックできます:
1714020013
1714120014 if ($? == -1) {
1714220015 print "failed to execute: $!\n";
1714320016 }
1714420017 elsif ($? & 127) {
1714520018 printf "child died with signal %d, %s coredump\n",
1714620019 ($? & 127), ($? & 128) ? 'with' : 'without';
1714720020 }
1714820021 else {
1714920022 printf "child exited with value %d\n", $? >> 8;
1715020023 }
1715120024
1715220025=begin original
1715320026
17154Alternatively, you may inspect the value of C<${^CHILD_ERROR_NATIVE}>
20027Alternatively, you may inspect the value of
17155with the C<W*()> calls from the POSIX module.
20028L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> with the
20029L<C<W*()>|POSIX/C<WIFEXITED>> calls from the L<POSIX> module.
1715620030
1715720031=end original
1715820032
17159または、POSIX モジュールの C<W*()> 呼び出しを使って
20033または、L<POSIX> モジュールの L<C<W*()>|POSIX/C<WIFEXITED>> 呼び出しを使って
17160C<${^CHILD_ERROR_NATIVE}> の値を調べることもできます。
20034L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> の値を
20035調べることもできます。
1716120036
1716220037=begin original
1716320038
17164When C<system>'s arguments are executed indirectly by the shell,
20039When L<C<system>|/system LIST>'s arguments are executed indirectly by
17165results and return codes are subject to its quirks.
20040the shell, results and return codes are subject to its quirks.
17166See L<perlop/"`STRING`"> and L</exec> for details.
20041See L<perlop/"`STRING`"> and L<C<exec>|/exec LIST> for details.
1716720042
1716820043=end original
1716920044
17170C<system> の引数がシェルによって間接的に実行された場合、
20045L<C<system>|/system LIST> の引数がシェルによって間接的に実行された場合、
1717120046結果と返り値はシェルの癖によって変更されることがあります。
17172詳細については L<perlop/"`STRING`"> と L</exec> を参照してください。
20047詳細については L<perlop/"`STRING`"> と L<C<exec>|/exec LIST> を
20048参照してください。
1717320049
1717420050=begin original
1717520051
17176Since C<system> does a C<fork> and C<wait> it may affect a C<SIGCHLD>
20052Since L<C<system>|/system LIST> does a L<C<fork>|/fork> and
17177handler. See L<perlipc> for details.
20053L<C<wait>|/wait> it may affect a C<SIGCHLD> handler. See L<perlipc> for
20054details.
1717820055
1717920056=end original
1718020057
17181C<system> は C<fork> と C<wait> を行うので、C<SIGCHLD> ハンドラの影響を
20058L<C<system>|/system LIST> L<C<fork>|/fork>L<C<wait>|/wait> を行うので、
17182受けます。
20059C<SIGCHLD> ハンドラの影響を受けます。
1718320060詳しくは L<perlipc> を参照してください。
1718420061
1718520062=begin original
1718620063
1718720064Portability issues: L<perlport/system>.
1718820065
1718920066=end original
1719020067
1719120068移植性の問題: L<perlport/system>。
1719220069
1719320070=item syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET
1719420071X<syswrite>
1719520072
1719620073=item syswrite FILEHANDLE,SCALAR,LENGTH
1719720074
1719820075=item syswrite FILEHANDLE,SCALAR
1719920076
1720020077=for Pod::Functions fixed-length unbuffered output to a filehandle
1720120078
1720220079=begin original
1720320080
1720420081Attempts to write LENGTH bytes of data from variable SCALAR to the
17205specified FILEHANDLE, using write(2). If LENGTH is
20082specified FILEHANDLE, using L<write(2)>. If LENGTH is
17206not specified, writes whole SCALAR. It bypasses buffered IO, so
20083not specified, writes whole SCALAR. It bypasses any L<PerlIO> layers
17207mixing this with reads (other than C<sysread())>, C<print>, C<write>,
20084including buffered IO (but is affected by the presence of the C<:utf8>
17208C<seek>, C<tell>, or C<eof> may cause confusion because the perlio and
20085layer as described later), so
17209stdio layers usually buffer data. Returns the number of bytes
20086mixing this with reads (other than C<sysread)>),
17210actually written, or C<undef> if there was an error (in this case the
20087L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
17211errno variable C<$!> is also set). If the LENGTH is greater than the
20088L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
20089L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> may cause
20090confusion because the C<:perlio> and C<:crlf> layers usually buffer data.
20091Returns the number of bytes actually written, or L<C<undef>|/undef EXPR>
20092if there was an error (in this case the errno variable
20093L<C<$!>|perlvar/$!> is also set). If the LENGTH is greater than the
1721220094data available in the SCALAR after the OFFSET, only as much data as is
1721320095available will be written.
1721420096
1721520097=end original
1721620098
17217write(2) を使って、指定した FILEHANDLEへ、変数 SCALAR から、LENGTH バイトの
20099L<write(2)> を使って、指定した FILEHANDLEへ、変数 SCALAR から、LENGTH バイトの
1721820100データの書き込みを試みます。
1721920101LENGTH が指定されなかった場合、 SCALAR 全体を書き込みます。
17220これは、バッファ付き IO ルーチンを通りませんか、他入力関数
20102これは、バッファ付き IO ルーチンを含むどの L<PerlIO> も通らない
17221(C<sysread()> 以外), C<print>, C<write>, C<seek>, C<tell>, C<eof>
20103(しかし、後述するように C<:utf8> の存在の影響を受けます)、他の入力関数、
17222混ぜて使うと、出がおかしくなるかもしれません; perlio 層と stdio 層は普通
20104他の入関数 (C<sysread> 以外),
17223データをバッファリングするからです。
20105L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
17224実際に読み込まれたデータの長さか、エラー時には C<undef> が返されます
20106L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>,
17225(この場合エラー変数 C<$!> もセットされます)。
20107L<C<eof>|/eof FILEHANDLE> と混ぜて使うと、出力がおかしくなるかれません;
20108C<:perlio> 層と C<:crlf> 層は普通データをバッファリングするからです。
20109実際に読み込まれたデータの長さか、エラー時には L<C<undef>|/undef EXPR> が
20110返されます(この場合エラー変数 L<C<$!>|perlvar/$!> もセットされます)。
1722620111LENGTH が OFFSET 以降の SCALAR の利用可能なデータより大きかった場合、
1722720112利用可能なデータのみが書き込まれます。
1722820113
1722920114=begin original
1723020115
1723120116An OFFSET may be specified to write the data from some part of the
1723220117string other than the beginning. A negative OFFSET specifies writing
1723320118that many characters counting backwards from the end of the string.
1723420119If SCALAR is of length zero, you can only use an OFFSET of 0.
1723520120
1723620121=end original
1723720122
1723820123OFFSET を指定すると、SCALAR の先頭以外の場所から、
1723920124データを取り出して、書き込みを行なうことができます。
1724020125OFFSET に負の値を指定すると、文字列の最後から逆向きに数えて
1724120126何バイト目から書き込むかを示します。
1724220127SCALAR の長さが 0 の場合、OFFSET は 0 のみ使用できます。
1724320128
1724420129=begin original
1724520130
17246B<WARNING>: If the filehandle is marked C<:utf8>, Unicode characters
20131B<WARNING>: If the filehandle is marked C<:utf8>, C<syswrite> will raise an exception.
17247encoded in UTF-8 are written instead of bytes, and the LENGTH, OFFSET, and
17248return value of syswrite() are in (UTF8-encoded Unicode) characters.
1724920132The C<:encoding(...)> layer implicitly introduces the C<:utf8> layer.
1725020133Alternately, if the handle is not marked with an encoding but you
1725120134attempt to write characters with code points over 255, raises an exception.
17252See L</binmode>, L</open>, and the C<open> pragma, L<open>.
20135See L<C<binmode>|/binmode FILEHANDLE, LAYER>,
20136L<C<open>|/open FILEHANDLE,MODE,EXPR>, and the L<open> pragma.
1725320137
1725420138=end original
1725520139
17256B<警告>: ファイルハンドルが C<:utf8> であるとマークが付けられると、
20140B<警告>: ファイルハンドルが C<:utf8> であるとマークが付けられていると、
17257バイトではなく UTF-8 エンコードされた Unicode 文字が読み込れ、
20141C<syswrite> は例外を投げす。
17258syswrite() の LENGTH, OFFSET および返り値(UTF8 エンコードされた
20142C<:encoding(...)> 暗黙に C<:utf8> 層を導入します。
17259Unicode) 文字単位になります。
17260C<:encoding(...)> 層は暗黙のうちに C<:utf8> 層が導入されます。
1726120143または、もしハンドルにエンコーディングが記録されていない状態で
1726220144255 を超える符号位置の文字を書き込もうとすると、例外が発生します。
17263L</binmode>, L</open>, C<open> プラグマ, L<open> を参照してください。
20145L<C<binmode>|/binmode FILEHANDLE, LAYER>,
20146L<C<open>|/open FILEHANDLE,MODE,EXPR>,
20147L<open> プラグマを参照してください。
1726420148
1726520149=item tell FILEHANDLE
1726620150X<tell>
1726720151
1726820152=item tell
1726920153
1727020154=for Pod::Functions get current seekpointer on a filehandle
1727120155
1727220156=begin original
1727320157
1727420158Returns the current position I<in bytes> for FILEHANDLE, or -1 on
1727520159error. FILEHANDLE may be an expression whose value gives the name of
1727620160the actual filehandle. If FILEHANDLE is omitted, assumes the file
1727720161last read.
1727820162
1727920163=end original
1728020164
1728120165FILEHANDLE の現在の位置を I<バイト数で> 返します; エラーの場合は -1 を
1728220166返します。
1728320167FILEHANDLE は、実際のファイルハンドル名を示す式でもかまいません。
17284FILEHANDLE が省略された場合には、
20168FILEHANDLE が省略された場合には、最後に読み込みを行なったファイルについて
17285最後に読み込みを行なったファイルについて調べます。
20169調べます。
1728620170
1728720171=begin original
1728820172
17289Note the I<in bytes>: even if the filehandle has been set to
20173Note the emphasis on bytes: even if the filehandle has been set to operate
17290operate on characters (for example by using the C<:encoding(utf8)> open
20174on characters (for example using the C<:encoding(UTF-8)> I/O layer), the
17291layer), tell() will return byte offsets, not character offsets (because
20175L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
17292that would render seek() and tell() rather slow).
20176L<C<tell>|/tell FILEHANDLE>, and
20177L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>
20178family of functions use byte offsets, not character offsets,
20179because seeking to a character offset would be very slow in a UTF-8 file.
1729320180
1729420181=end original
1729520182
17296I<バイト単位> する注意: ファイルハンドルが (例えば
20183バイト単位にする注意: 例え(例えば C<:encoding(UTF-8)> I/O 層を使うなどして)
17297C<:encoding(utf8)> 層を使っ)
20184ファイルハンドルが文字単位で処理するように設定されいたとしても、
17298文字を操作するように設定されていたとしても、tell() は文字の
20185L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
17299オフセットではなくバイトのオフセットを返すことに注意してください
20186L<C<tell>|/tell FILEHANDLE>,
17300(なぜならこれは seek() と tell() が遅くなってしまうからです)。
20187L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> シリーズの関数は
20188文字オフセットではなくバイトオフセットを使います;
20189文字オフセットでシークするのは UTF-8 ファイルではとても遅いからです。
1730120190
1730220191=begin original
1730320192
17304The return value of tell() for the standard streams like the STDIN
20193The return value of L<C<tell>|/tell FILEHANDLE> for the standard streams
17305depends on the operating system: it may return -1 or something else.
20194like the STDIN depends on the operating system: it may return -1 or
17306tell() on pipes, fifos, and sockets usually returns -1.
20195something else. L<C<tell>|/tell FILEHANDLE> on pipes, fifos, and
20196sockets usually returns -1.
1730720197
1730820198=end original
1730920199
17310STDIN のような標準ストリームに対する tell() の返り値は OS に依存します:
20200STDIN のような標準ストリームに対する L<C<tell>|/tell FILEHANDLE> の返り値は
20201OS に依存します:
1731120202-1 やその他の値が返ってくるかもしれません。
17312パイプ、FIFO、ソケットに対して tell() を使うと、普通は -1 が返ります。
20203パイプ、FIFO、ソケットに対して L<C<tell>|/tell FILEHANDLE> を使うと、普通は
20204-1 が返ります。
1731320205
1731420206=begin original
1731520207
17316There is no C<systell> function. Use C<sysseek(FH, 0, 1)> for that.
20208There is no C<systell> function. Use
20209L<C<sysseek($fh, 0, 1)>|/sysseek FILEHANDLE,POSITION,WHENCE> for that.
1731720210
1731820211=end original
1731920212
1732020213C<systell> 関数はありません。
17321代わりに C<sysseek(FH, 0, 1)> を使ってください。
20214代わりに L<C<sysseek($fh, 0, 1)>|/sysseek FILEHANDLE,POSITION,WHENCE>
20215使ってください。
1732220216
1732320217=begin original
1732420218
17325Do not use tell() (or other buffered I/O operations) on a filehandle
20219Do not use L<C<tell>|/tell FILEHANDLE> (or other buffered I/O
17326that has been manipulated by sysread(), syswrite(), or sysseek().
20220operations) on a filehandle that has been manipulated by
17327Those functions ignore the buffering, while tell() does not.
20221L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
20222L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, or
20223L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>. Those functions
20224ignore the buffering, while L<C<tell>|/tell FILEHANDLE> does not.
1732820225
1732920226=end original
1733020227
17331sysread(), syswrite(), sysseek() で操作されたファイルハンドルに tell()
20228L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
20229L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
20230L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> で操作された
20231ファイルハンドルに L<C<tell>|/tell FILEHANDLE>
1733220232(またはその他のバッファリング I/O 操作) を使わないでください。
17333これらの関数はバッファリングを無視しますが、tell()違います。
20233これらの関数はバッファリングを無視しますが、L<C<tell>|/tell FILEHANDLE>
20234違います。
1733420235
1733520236=item telldir DIRHANDLE
1733620237X<telldir>
1733720238
1733820239=for Pod::Functions get current seekpointer on a directory handle
1733920240
1734020241=begin original
1734120242
17342Returns the current position of the C<readdir> routines on DIRHANDLE.
20243Returns the current position of the L<C<readdir>|/readdir DIRHANDLE>
17343Value may be given to C<seekdir> to access a particular location in a
20244routines on DIRHANDLE. Value may be given to
17344directory. C<telldir> has the same caveats about possible directory
20245L<C<seekdir>|/seekdir DIRHANDLE,POS> to access a particular location in
17345compaction as the corresponding system library routine.
20246a directory. L<C<telldir>|/telldir DIRHANDLE> has the same caveats
20247about possible directory compaction as the corresponding system library
20248routine.
1734620249
1734720250=end original
1734820251
17349DIRHANDLE 上の C<readdir> ルーチンに対する現在位置を返します。
20252DIRHANDLE 上の L<C<readdir>|/readdir DIRHANDLE> ルーチンに対する現在位置を
20253返します。
1735020254値は、そのディレクトリで特定の位置をアクセスするため、
17351C<seekdir> に渡すことができます。
20255L<C<seekdir>|/seekdir DIRHANDLE,POS> に渡すことができます。
17352C<telldir> は同名のシステムライブラリルーチンと同じく、
20256L<C<telldir>|/telldir DIRHANDLE> は同名のシステムライブラリルーチンと同じく、
1735320257ディレクトリ縮小時の問題が考えられます。
1735420258
1735520259=item tie VARIABLE,CLASSNAME,LIST
1735620260X<tie>
1735720261
1735820262=for Pod::Functions +5.002 bind a variable to an object class
1735920263
1736020264=begin original
1736120265
1736220266This function binds a variable to a package class that will provide the
1736320267implementation for the variable. VARIABLE is the name of the variable
1736420268to be enchanted. CLASSNAME is the name of a class implementing objects
1736520269of correct type. Any additional arguments are passed to the
1736620270appropriate constructor
1736720271method of the class (meaning C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>,
1736820272or C<TIEHASH>). Typically these are arguments such as might be passed
17369to the C<dbm_open()> function of C. The object returned by the
20273to the L<dbm_open(3)> function of C. The object returned by the
17370constructor is also returned by the C<tie> function, which would be useful
20274constructor is also returned by the
20275L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function, which would be useful
1737120276if you want to access other methods in CLASSNAME.
1737220277
1737320278=end original
1737420279
1737520280この関数は、変数を、その変数の実装を行なうクラスと結び付けます。
1737620281VARIABLE は、魔法をかける変数の名前です。
1737720282CLASSNAME は、正しい型のオブジェクトを実装するクラスの名前です。
1737820283他に引数があれば、そのクラスの適切なコンストラクタメソッドに渡されます
1737920284(つまり C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>, C<TIEHASH>)。
17380通常、これらは、C の C<dbm_open> などの関数に渡す引数となります。
20285通常、これらは、C の L<dbm_open(3)> などの関数に渡す引数となります。
17381コンストラクタで返されるオブジェクトはまた C<tie> 関数でも返されます;
20286コンストラクタで返されるオブジェクトはまた
20287L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数でも返されます;
1738220288これは CLASSNAME の他のメソッドにアクセスしたいときに便利です。
1738320289
1738420290=begin original
1738520291
17386Note that functions such as C<keys> and C<values> may return huge lists
20292Note that functions such as L<C<keys>|/keys HASH> and
17387when used on large objects, like DBM files. You may prefer to use the
20293L<C<values>|/values HASH> may return huge lists when used on large
17388C<each> function to iterate over such. Example:
20294objects, like DBM files. You may prefer to use the L<C<each>|/each
20295HASH> function to iterate over such. Example:
1738920296
1739020297=end original
1739120298
17392DBM ファイルのような大きなオブジェクトでは、C<keys> や C<values> のような
20299DBM ファイルのような大きなオブジェクトでは、L<C<keys>|/keys HASH>
17393関数は、大きなリストを返す可能性があります。
20300L<C<values>|/values HASH> のような関数は、大きなリストを返す可能性があります。
17394そのような場合では、C<each> 関数を使って繰り返しを行なった方が
20301そのような場合では、L<C<each>|/each HASH> 関数を使って繰り返しを行なった方が
1739520302よいかもしれません。
1739620303例:
1739720304
1739820305 # print out history file offsets
1739920306 use NDBM_File;
17400 tie(%HIST, 'NDBM_File', '/usr/lib/news/history', 1, 0);
20307 tie(my %HIST, 'NDBM_File', '/usr/lib/news/history', 1, 0);
17401 while (($key,$val) = each %HIST) {
20308 while (my ($key,$val) = each %HIST) {
17402 print $key, ' = ', unpack('L',$val), "\n";
20309 print $key, ' = ', unpack('L', $val), "\n";
1740320310 }
17404 untie(%HIST);
1740520311
1740620312=begin original
1740720313
1740820314A class implementing a hash should have the following methods:
1740920315
1741020316=end original
1741120317
1741220318ハッシュを実装するクラスでは、次のようなメソッドを用意します:
1741320319
1741420320 TIEHASH classname, LIST
1741520321 FETCH this, key
1741620322 STORE this, key, value
1741720323 DELETE this, key
1741820324 CLEAR this
1741920325 EXISTS this, key
1742020326 FIRSTKEY this
1742120327 NEXTKEY this, lastkey
1742220328 SCALAR this
1742320329 DESTROY this
1742420330 UNTIE this
1742520331
1742620332=begin original
1742720333
1742820334A class implementing an ordinary array should have the following methods:
1742920335
1743020336=end original
1743120337
1743220338通常の配列を実装するクラスでは、次のようなメソッドを用意します:
1743320339
1743420340 TIEARRAY classname, LIST
1743520341 FETCH this, key
1743620342 STORE this, key, value
1743720343 FETCHSIZE this
1743820344 STORESIZE this, count
1743920345 CLEAR this
1744020346 PUSH this, LIST
1744120347 POP this
1744220348 SHIFT this
1744320349 UNSHIFT this, LIST
1744420350 SPLICE this, offset, length, LIST
1744520351 EXTEND this, count
1744620352 DELETE this, key
1744720353 EXISTS this, key
1744820354 DESTROY this
1744920355 UNTIE this
1745020356
1745120357=begin original
1745220358
1745320359A class implementing a filehandle should have the following methods:
1745420360
1745520361=end original
1745620362
1745720363ファイルハンドルを実装するクラスでは、次のようなメソッドを用意します:
1745820364
1745920365 TIEHANDLE classname, LIST
1746020366 READ this, scalar, length, offset
1746120367 READLINE this
1746220368 GETC this
1746320369 WRITE this, scalar, length, offset
1746420370 PRINT this, LIST
1746520371 PRINTF this, format, LIST
1746620372 BINMODE this
1746720373 EOF this
1746820374 FILENO this
1746920375 SEEK this, position, whence
1747020376 TELL this
1747120377 OPEN this, mode, LIST
1747220378 CLOSE this
1747320379 DESTROY this
1747420380 UNTIE this
1747520381
1747620382=begin original
1747720383
1747820384A class implementing a scalar should have the following methods:
1747920385
1748020386=end original
1748120387
1748220388スカラ変数を実装するクラスでは、次のようなメソッドを用意します:
1748320389
1748420390 TIESCALAR classname, LIST
1748520391 FETCH this,
1748620392 STORE this, value
1748720393 DESTROY this
1748820394 UNTIE this
1748920395
1749020396=begin original
1749120397
1749220398Not all methods indicated above need be implemented. See L<perltie>,
1749320399L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>, and L<Tie::Handle>.
1749420400
1749520401=end original
1749620402
1749720403上記の全てのメソッドを実装する必要はありません。
1749820404L<perltie>, L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>,
1749920405L<Tie::Handle> を参照してください。
1750020406
1750120407=begin original
1750220408
17503Unlike C<dbmopen>, the C<tie> function will not C<use> or C<require> a module
20409Unlike L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, the
17504for you; you need to do that explicitly yourself. See L<DB_File>
20410L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function will not
17505or the F<Config> module for interesting C<tie> implementations.
20411L<C<use>|/use Module VERSION LIST> or L<C<require>|/require VERSION> a
20412module for you; you need to do that explicitly yourself. See L<DB_File>
20413or the L<Config> module for interesting
20414L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> implementations.
1750620415
1750720416=end original
1750820417
17509C<dbmopen> と違い、C<tie> 関数はモジュールを C<use> したり
20418L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> と違い、
17510C<require> したりしません; 自分で明示的に行う必要があります。
20419L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数はモジュールを
17511C<tie> の興味深い実装については L<DB_File> F<Config> モジュールを
20420L<C<use>|/use Module VERSION LIST> したり
17512参照てください。
20421L<C<require>|/require VERSION> たりしません;
20422自分で明示的に行う必要があります。
20423L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> の興味深い実装については
20424L<DB_File> や L<Config> モジュールを参照してください。
1751320425
1751420426=begin original
1751520427
17516For further details see L<perltie>, L<"tied VARIABLE">.
20428For further details see L<perltie>, L<C<tied>|/tied VARIABLE>.
1751720429
1751820430=end original
1751920431
17520更なる詳細については L<perltie> や L<"tied VARIABLE"> を参照してください。
20432更なる詳細については L<perltie> や L<C<tied>|/tied VARIABLE> を
20433参照してください。
1752120434
1752220435=item tied VARIABLE
1752320436X<tied>
1752420437
1752520438=for Pod::Functions get a reference to the object underlying a tied variable
1752620439
1752720440=begin original
1752820441
1752920442Returns a reference to the object underlying VARIABLE (the same value
17530that was originally returned by the C<tie> call that bound the variable
20443that was originally returned by the
20444L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> call that bound the variable
1753120445to a package.) Returns the undefined value if VARIABLE isn't tied to a
1753220446package.
1753320447
1753420448=end original
1753520449
1753620450VARIABLE の基となるオブジェクトへのリファレンスを返します
17537(変数をパッケージに結びつけるために C<tie> 呼び出しをしたときの
20451(変数をパッケージに結びつけるために
20452L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 呼び出しをしたときの
1753820453返り値と同じものです)。
1753920454VARIABLE がパッケージと結び付けられていない場合は未定義値を返します。
1754020455
1754120456=item time
1754220457X<time> X<epoch>
1754320458
1754420459=for Pod::Functions return number of seconds since 1970
1754520460
1754620461=begin original
1754720462
1754820463Returns the number of non-leap seconds since whatever time the system
17549considers to be the epoch, suitable for feeding to C<gmtime> and
20464considers to be the epoch, suitable for feeding to
17550C<localtime>. On most systems the epoch is 00:00:00 UTC, January 1, 1970;
20465L<C<gmtime>|/gmtime EXPR> and L<C<localtime>|/localtime EXPR>. On most
20466systems the epoch is 00:00:00 UTC, January 1, 1970;
1755120467a prominent exception being Mac OS Classic which uses 00:00:00, January 1,
17552204681904 in the current local time zone for its epoch.
1755320469
1755420470=end original
1755520471
17556C<gmtime> や C<localtime> への入力形式に合っている、
20472L<C<gmtime>|/gmtime EXPR> L<C<localtime>|/localtime EXPR> への入力形式に
17557システムが紀元と考える時点からの連続秒数を返します。
20473合っている、システムが紀元と考える時点からの連続秒数を返します。
1755820474ほとんどのシステムでは紀元は UTC 1970 年 1 月 1 日 00:00:00 です;
1755920475特徴的な例外としては、古い Mac OS ではローカルタイムゾーンの
17560204761904 年 1 月 1 日 00:00:00 を紀元として使います。
1756120477
1756220478=begin original
1756320479
1756420480For measuring time in better granularity than one second, use the
1756520481L<Time::HiRes> module from Perl 5.8 onwards (or from CPAN before then), or,
17566if you have gettimeofday(2), you may be able to use the C<syscall>
20482if you have L<gettimeofday(2)>, you may be able to use the
17567interface of Perl. See L<perlfaq8> for details.
20483L<C<syscall>|/syscall NUMBER, LIST> interface of Perl. See L<perlfaq8>
20484for details.
1756820485
1756920486=end original
1757020487
17571204881 秒よりも細かい時間を計測するためには、Perl 5.8 以降(それ以前では
1757220489CPANから)の L<Time::HiRes> モジュールを使うか、
17573gettimeofday(2) があるなら、Perl の C<syscall> インターフェースを
20490L<gettimeofday(2)> があるなら、Perl の
17574使ってください。
20491L<C<syscall>|/syscall NUMBER, LIST> インターフェースを使ってください。
1757520492詳しくは L<perlfaq8> を参照してください。
1757620493
1757720494=begin original
1757820495
1757920496For date and time processing look at the many related modules on CPAN.
1758020497For a comprehensive date and time representation look at the
1758120498L<DateTime> module.
1758220499
1758320500=end original
1758420501
1758520502日付と時刻の処理は、多くの関連するモジュールが CPAN にあります。
1758620503包括的な日付と時刻の表現については、CPAN の L<DateTime> モジュールを
1758720504参照してください。
1758820505
1758920506=item times
1759020507X<times>
1759120508
1759220509=for Pod::Functions return elapsed time for self and child processes
1759320510
1759420511=begin original
1759520512
1759620513Returns a four-element list giving the user and system times in
1759720514seconds for this process and any exited children of this process.
1759820515
1759920516=end original
1760020517
1760120518現プロセス及び終了したその子プロセスに対する、ユーザ時間とシステム時間を
1760220519秒で示した、4 要素のリスト値を返します。
1760320520
17604 ($user,$system,$cuser,$csystem) = times;
20521 my ($user,$system,$cuser,$csystem) = times;
1760520522
1760620523=begin original
1760720524
17608In scalar context, C<times> returns C<$user>.
20525In scalar context, L<C<times>|/times> returns C<$user>.
1760920526
1761020527=end original
1761120528
17612スカラコンテキストでは、C<times> は C<$user> を返します。
20529スカラコンテキストでは、L<C<times>|/times> は C<$user> を返します。
1761320530
1761420531=begin original
1761520532
1761620533Children's times are only included for terminated children.
1761720534
1761820535=end original
1761920536
1762020537子プロセスに対する times は、終了した子プロセスのみ含められます。
1762120538
1762220539=begin original
1762320540
1762420541Portability issues: L<perlport/times>.
1762520542
1762620543=end original
1762720544
1762820545移植性の問題: L<perlport/times>。
1762920546
1763020547=item tr///
1763120548
1763220549=for Pod::Functions transliterate a string
1763320550
1763420551=begin original
1763520552
17636The transliteration operator. Same as C<y///>. See
20553The transliteration operator. Same as
17637L<perlop/"Quote and Quote-like Operators">.
20554L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>>. See
20555L<perlop/"Quote-Like Operators">.
1763820556
1763920557=end original
1764020558
1764120559文字変換演算子です。
17642C<y///> と同じです。
20560L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>> と同じです。
17643L<perlop/"Quote and Quote-like Operators"> を参照してください。
20561L<perlop/"Quote-Like Operators"> を参照してください。
1764420562
1764520563=item truncate FILEHANDLE,LENGTH
1764620564X<truncate>
1764720565
1764820566=item truncate EXPR,LENGTH
1764920567
1765020568=for Pod::Functions shorten a file
1765120569
1765220570=begin original
1765320571
1765420572Truncates the file opened on FILEHANDLE, or named by EXPR, to the
1765520573specified length. Raises an exception if truncate isn't implemented
17656on your system. Returns true if successful, C<undef> on error.
20574on your system. Returns true if successful, L<C<undef>|/undef EXPR> on
20575error.
1765720576
1765820577=end original
1765920578
1766020579FILEHANDLE 上にオープンされたファイルか、EXPR で名前を表わしたファイルを、
1766120580指定した長さに切り詰めます。
1766220581システム上に truncate が実装されていなければ、例外が発生します。
17663成功すれば真を、エラー時には C<undef> を返します。
20582成功すれば真を、エラー時には L<C<undef>|/undef EXPR> を返します。
1766420583
1766520584=begin original
1766620585
1766720586The behavior is undefined if LENGTH is greater than the length of the
1766820587file.
1766920588
1767020589=end original
1767120590
1767220591LENGTH がファイルの長さより大きい場合の振る舞いは未定義です。
1767320592
1767420593=begin original
1767520594
1767620595The position in the file of FILEHANDLE is left unchanged. You may want to
17677call L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> before writing to the file.
20596call L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> before writing to the
20597file.
1767820598
1767920599=end original
1768020600
1768120601FILEHANDLE のファイルの位置は変わりません。
1768220602ファイルに書き込む前に L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> を
1768320603呼び出したいかもしれません。
1768420604
1768520605=begin original
1768620606
1768720607Portability issues: L<perlport/truncate>.
1768820608
1768920609=end original
1769020610
1769120611移植性の問題: L<perlport/truncate>。
1769220612
1769320613=item uc EXPR
1769420614X<uc> X<uppercase> X<toupper>
1769520615
1769620616=item uc
1769720617
1769820618=for Pod::Functions return upper-case version of a string
1769920619
1770020620=begin original
1770120621
17702Returns an uppercased version of EXPR. This is the internal function
20622Returns an uppercased version of EXPR. If EXPR is omitted, uses
17703implementing the C<\U> escape in double-quoted strings.
20623L<C<$_>|perlvar/$_>.
17704It does not attempt to do titlecase mapping on initial letters. See
17705L</ucfirst> for that.
1770620624
1770720625=end original
1770820626
17709EXPR 大文字に変換したものを返します。
20627EXPR 大文字を返します。
17710は、ダブルクォート文字列における、C<\U> エスケープ
20628EXPR が省略されるL<C<$_>|perlvar/$_>使います。
17711実装する内部関数です。
17712先頭文字の タイトル文字マッピングは試みません。
17713このためには L</ucfirst> を参照してください。
1771420629
20630 my $str = uc("Perl is GREAT"); # "PERL IS GREAT"
20631
1771520632=begin original
1771620633
17717If EXPR is omitted, uses C<$_>.
20634This function behaves the same way under various pragmas, such as in a locale,
20635as L<C<lc>|/lc EXPR> does.
1771820636
1771920637=end original
1772020638
17721EXPR が省略されるとC<$_> を使いす。
20639この関数はロケールのようなさざまなプラグマの影響下では、
20640L<C<lc>|/lc EXPR> と同様に振る舞います。
1772220641
1772320642=begin original
1772420643
17725This function behaves the same way under various pragma, such as in a locale,
20644If you want titlecase mapping on initial letters see
17726as L</lc> does.
20645L<C<ucfirst>|/ucfirst EXPR> instead.
1772720646
1772820647=end original
1772920648
17730関数は、ロケールようなさまざまなプラグの影響下では、
20649最初文字タイトル文字ッピングがほしい場合は、
17731L</lc> と同様に振る舞ます
20650代わりに L<C<ucfirst>|/ucfirst EXPR> を使ってください。
1773220651
20652=begin original
20653
20654B<Note:> This is the internal function implementing the
20655L<C<\U>|perlop/"Quote and Quote-like Operators"> escape in double-quoted
20656strings.
20657
20658=end original
20659
20660B<注意:> これは、ダブルクォート文字列における、
20661L<C<\U>|perlop/"Quote and Quote-like Operators"> エスケープを
20662実装する内部関数です。
20663
20664 my $str = "Perl is \Ugreat\E"; # "Perl is GREAT"
20665
1773320666=item ucfirst EXPR
1773420667X<ucfirst> X<uppercase>
1773520668
1773620669=item ucfirst
1773720670
17738=for Pod::Functions return a string with just the next letter in upper case
20671=for Pod::Functions return a string with the first letter in upper case
1773920672
1774020673=begin original
1774120674
17742Returns the value of EXPR with the first character in uppercase
20675Returns the value of EXPR with the B<first> character in uppercase
17743(titlecase in Unicode). This is the internal function implementing
20676(Unicode calls this titlecase). If EXPR is omitted, C<ucfirst> uses L<C<$_>|perlvar/$_>.
17744the C<\u> escape in double-quoted strings.
1774520677
1774620678=end original
1774720679
17748最初の文字だけを大文字にした、EXPR返します
20680B<最初の> 文字だけを大文字(Unicode ではこれタイトル文字と呼びます)にした、
17749(Unicode では titlecase)
20681EXPR を返します
17750は、ダブルクォート文字列における、C<\u> エスケープ
20682EXPR が省略される、C<ucfirst> は L<C<$_>|perlvar/$_> 使います。
17751実装する内部関数です。
1775220683
20684 my $str = ucfirst("hello world!"); # "Hello world!"
20685
1775320686=begin original
1775420687
17755If EXPR is omitted, uses C<$_>.
20688This function behaves the same way under various pragmas, such as in a locale,
20689as L<C<lc>|/lc EXPR> does.
1775620690
1775720691=end original
1775820692
17759EXPR が省略されるとC<$_> を使いす。
20693この関数はロケールのようなさざまなプラグマの影響下では、
20694L<C<lc>|/lc EXPR> と同様に振る舞います。
1776020695
1776120696=begin original
1776220697
17763This function behaves the same way under various pragma, such as in a locale,
20698B<Note:> This is the internal function implementing the C<\u> escape in
17764as L</lc> does.
20699double-quoted strings.
1776520700
1776620701=end original
1776720702
17768の関数は、ケールのようなさまざまなラグマの影響下では、
20703B<注意:> は、ダブルクォート文字列における、C<\u> エスケープ
17769L</lc> と同様に振舞います。
20704実装す内部関数です。
1777020705
20706 my $str = "\uperl\E is great"; # "Perl is great"
20707
1777120708=item umask EXPR
1777220709X<umask>
1777320710
1777420711=item umask
1777520712
1777620713=for Pod::Functions set file creation mode mask
1777720714
1777820715=begin original
1777920716
1778020717Sets the umask for the process to EXPR and returns the previous value.
1778120718If EXPR is omitted, merely returns the current umask.
1778220719
1778320720=end original
1778420721
1778520722現在のプロセスの umask を EXPR に設定し、以前の値を返します。
1778620723EXPR が省略されると、単にその時点の umask の値を返します。
1778720724
1778820725=begin original
1778920726
1779020727The Unix permission C<rwxr-x---> is represented as three sets of three
1779120728bits, or three octal digits: C<0750> (the leading 0 indicates octal
17792and isn't one of the digits). The C<umask> value is such a number
20729and isn't one of the digits). The L<C<umask>|/umask EXPR> value is such
17793representing disabled permissions bits. The permission (or "mode")
20730a number representing disabled permissions bits. The permission (or
17794values you pass C<mkdir> or C<sysopen> are modified by your umask, so
20731"mode") values you pass L<C<mkdir>|/mkdir FILENAME,MODE> or
17795even if you tell C<sysopen> to create a file with permissions C<0777>,
20732L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> are modified by your
17796if your umask is C<0022>, then the file will actually be created with
20733umask, so even if you tell
17797permissions C<0755>. If your C<umask> were C<0027> (group can't
20734L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> to create a file with
17798write; others can't read, write, or execute), then passing
20735permissions C<0777>, if your umask is C<0022>, then the file will
17799C<sysopen> C<0666> would create a file with mode C<0640> (because
20736actually be created with permissions C<0755>. If your
17800C<0666 &~ 027> is C<0640>).
20737L<C<umask>|/umask EXPR> were C<0027> (group can't write; others can't
20738read, write, or execute), then passing
20739L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> C<0666> would create a
20740file with mode C<0640> (because C<0666 &~ 027> is C<0640>).
1780120741
1780220742=end original
1780320743
1780420744Unix パーミッション C<rwxr-x---> は 3 ビットの三つの組、
1780520745または 3 桁の 8 進数として表現されます:
1780620746C<0750> (先頭の 0 は 8 進数を意味し、実際の値ではありません)。
17807C<umask> の値は無効にするパーミッションビットのこのような数値表現です。
20747L<C<umask>|/umask EXPR> の値は無効にするパーミッションビットのこのような
17808C<mkdir> や C<sysopen> で渡されたパーミッション(または「モード」)の
20748表現です。
17809umask で修正され、たとえ C<sysopen> で C<0777> のパーミッションで
20749L<C<mkdir>|/mkdir FILENAME,MODE>
20750L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> で渡されたパーミッション
20751(または「モード」)の値は umask で修正され、たとえ
20752L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> で C<0777> のパーミッションで
1781020753ファイルを作るように指定しても、umask が C<0022> なら、
1781120754結果としてファイルは C<0755> のパーミッションで作成されます。
17812C<umask> が C<0027> (グループは書き込めない; その他は読み込み、書き込み、
20755L<C<umask>|/umask EXPR> が C<0027> (グループは書き込めない; その他は読み込み、
17813実行できない) のとき、C<sysopen> に C<0666> を渡すと、
20756書き込み、実行できない) のとき
20757L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> に C<0666> を渡すと、
1781420758ファイルはモード C<0640> (なぜなら C<0666 &~ 027> は C<0640>)で作成されます。
1781520759
1781620760=begin original
1781720761
1781820762Here's some advice: supply a creation mode of C<0666> for regular
17819files (in C<sysopen>) and one of C<0777> for directories (in
20763files (in L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>) and one of
17820C<mkdir>) and executable files. This gives users the freedom of
20764C<0777> for directories (in L<C<mkdir>|/mkdir FILENAME,MODE>) and
20765executable files. This gives users the freedom of
1782120766choice: if they want protected files, they might choose process umasks
1782220767of C<022>, C<027>, or even the particularly antisocial mask of C<077>.
1782320768Programs should rarely if ever make policy decisions better left to
1782420769the user. The exception to this is when writing files that should be
17825kept private: mail files, web browser cookies, I<.rhosts> files, and
20770kept private: mail files, web browser cookies, F<.rhosts> files, and
1782620771so on.
1782720772
1782820773=end original
1782920774
17830以下は助言です: 作成モードとして、(C<sysopen> による)通常ファイルでは
20775以下は助言です: 作成モードとして、
17831C<0666> を、(C<mkdir> による)ディレクトリでは C<0777> を指定しましょう。
20776(L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> による)通常ファイルでは
20777C<0666> を、(L<C<mkdir>|/mkdir FILENAME,MODE> による)ディレクトリでは
20778C<0777> を指定しましょう。
1783220779これにより、ユーザーに選択の自由を与えます: もしファイルを守りたいなら、
1783320780プロセスの umask として C<022>, C<027>, あるいは特に非社交的な
1783420781C<077> を選択できます。
1783520782プログラムがユーザーより適切なポリシー選択ができることは稀です。
1783620783例外は、プライベートに保つべきファイル(メール、ウェブブラウザのクッキー、
17837I<.rhosts> ファイルなど)を書く場合です。
20784F<.rhosts> ファイルなど)を書く場合です。
1783820785
1783920786=begin original
1784020787
17841If umask(2) is not implemented on your system and you are trying to
20788If L<umask(2)> is not implemented on your system and you are trying to
17842restrict access for I<yourself> (i.e., C<< (EXPR & 0700) > 0 >>),
20789restrict access for I<yourself> (i.e., C<< (EXPR & 0700) > 0 >>),
17843raises an exception. If umask(2) is not implemented and you are
20790raises an exception. If L<umask(2)> is not implemented and you are
17844not trying to restrict access for yourself, returns C<undef>.
20791not trying to restrict access for yourself, returns
20792L<C<undef>|/undef EXPR>.
1784520793
1784620794=end original
1784720795
17848umask(2) が実装されていないシステムで、I<自分自身> へのアクセスを
20796L<umask(2)> が実装されていないシステムで、I<自分自身> へのアクセスを
1784920797制限しようとした(つまり C<< (EXPR & 0700) > 0 >>)場合、例外が発生します。
17850umask(2) が実装されていないシステムで、自分自身へのアクセスは
20798L<umask(2)> が実装されていないシステムで、自分自身へのアクセスは
17851制限しようとしなかった場合、C<undef> を返します。
20799制限しようとしなかった場合、L<C<undef>|/undef EXPR> を返します。
1785220800
1785320801=begin original
1785420802
1785520803Remember that a umask is a number, usually given in octal; it is I<not> a
17856string of octal digits. See also L</oct>, if all you have is a string.
20804string of octal digits. See also L<C<oct>|/oct EXPR>, if all you have
20805is a string.
1785720806
1785820807=end original
1785920808
1786020809umask は通常 8 進数で与えられる数値であることを忘れないでください; 8 進数の
1786120810文字列 I<ではありません>。
17862文字列しかない場合、 L</oct> も参照してください。
20811文字列しかない場合、 L<C<oct>|/oct EXPR> も参照してください。
1786320812
1786420813=begin original
1786520814
1786620815Portability issues: L<perlport/umask>.
1786720816
1786820817=end original
1786920818
1787020819移植性の問題: L<perlport/umask>。
1787120820
1787220821=item undef EXPR
1787320822X<undef> X<undefine>
1787420823
1787520824=item undef
1787620825
1787720826=for Pod::Functions remove a variable or function definition
1787820827
1787920828=begin original
1788020829
1788120830Undefines the value of EXPR, which must be an lvalue. Use only on a
1788220831scalar value, an array (using C<@>), a hash (using C<%>), a subroutine
1788320832(using C<&>), or a typeglob (using C<*>). Saying C<undef $hash{$key}>
1788420833will probably not do what you expect on most predefined variables or
17885DBM list values, so don't do that; see L</delete>. Always returns the
20834DBM list values, so don't do that; see L<C<delete>|/delete EXPR>.
17886undefined value. You can omit the EXPR, in which case nothing is
20835Always returns the undefined value.
20836You can omit the EXPR, in which case nothing is
1788720837undefined, but you still get an undefined value that you could, for
1788820838instance, return from a subroutine, assign to a variable, or pass as a
1788920839parameter. Examples:
1789020840
1789120841=end original
1789220842
1789320843左辺値である EXPR の値を未定義にします。
17894スカラ値、(C<@> を使った)配列、(C<%> を使った)ハッシュ、(C<&> を使った)
20844スカラ値、(C<@> を使った)配列、(C<%> を使った)ハッシュ、(C<&> を使った)
1789520845サブルーチン、(C<*> を使った)型グロブだけに使用します。
1789620846特殊変数や DBM リスト値に C<undef $hash{$key}> などとしても
1789720847おそらく期待通りの結果にはなりませんから、しないでください;
17898L</delete> を参照してください。
20848L<C<delete>|/delete EXPR> を参照してください。
1789920849常に未定義値を返します。
1790020850EXPR は省略することができ、その場合には何も未定義にされませんが
1790120851未定義値は返されますので、それをたとえば、
1790220852サブルーチンの返り値、変数への割り当て、引数などとして使うことができます。
1790320853例:
1790420854
1790520855 undef $foo;
1790620856 undef $bar{'blurfl'}; # Compare to: delete $bar{'blurfl'};
1790720857 undef @ary;
1790820858 undef %hash;
1790920859 undef &mysub;
1791020860 undef *xyz; # destroys $xyz, @xyz, %xyz, &xyz, etc.
1791120861 return (wantarray ? (undef, $errmsg) : undef) if $they_blew_it;
1791220862 select undef, undef, undef, 0.25;
17913 ($a, $b, undef, $c) = &foo; # Ignore third value returned
20863 my ($x, $y, undef, $z) = foo(); # Ignore third value returned
1791420864
1791520865=begin original
1791620866
1791720867Note that this is a unary operator, not a list operator.
1791820868
1791920869=end original
1792020870
1792120871これはリスト演算子ではなく、単項演算子であることに注意してください。
1792220872
1792320873=item unlink LIST
1792420874X<unlink> X<delete> X<remove> X<rm> X<del>
1792520875
1792620876=item unlink
1792720877
1792820878=for Pod::Functions remove one link to a file
1792920879
1793020880=begin original
1793120881
1793220882Deletes a list of files. On success, it returns the number of files
17933it successfully deleted. On failure, it returns false and sets C<$!>
20883it successfully deleted. On failure, it returns false and sets
17934(errno):
20884L<C<$!>|perlvar/$!> (errno):
1793520885
1793620886=end original
1793720887
1793820888LIST に含まれるファイルを削除します。
1793920889成功時は削除に成功したファイルの数を返します。
17940失敗時は偽を返して C<$!> (error) をセットします:
20890失敗時は偽を返して L<C<$!>|perlvar/$!> (error) をセットします:
1794120891
1794220892 my $unlinked = unlink 'a', 'b', 'c';
1794320893 unlink @goners;
1794420894 unlink glob "*.bak";
1794520895
1794620896=begin original
1794720897
17948On error, C<unlink> will not tell you which files it could not remove.
20898On error, L<C<unlink>|/unlink LIST> will not tell you which files it
20899could not remove.
1794920900If you want to know which files you could not remove, try them one
1795020901at a time:
1795120902
1795220903=end original
1795320904
17954エラーの場合、C<unlink> はどのファイルが削除できなかったかを知らせません。
20905エラーの場合、L<C<unlink>|/unlink LIST> はどのファイルが削除できなかったかを
20906知らせません。
1795520907どのファイルが削除できなかったかを知りたい場合は、一つずつ削除してください:
1795620908
1795720909 foreach my $file ( @goners ) {
1795820910 unlink $file or warn "Could not unlink $file: $!";
1795920911 }
1796020912
1796120913=begin original
1796220914
17963Note: C<unlink> will not attempt to delete directories unless you are
20915Note: L<C<unlink>|/unlink LIST> will not attempt to delete directories
20916unless you are
1796420917superuser and the B<-U> flag is supplied to Perl. Even if these
1796520918conditions are met, be warned that unlinking a directory can inflict
17966damage on your filesystem. Finally, using C<unlink> on directories is
20919damage on your filesystem. Finally, using L<C<unlink>|/unlink LIST> on
17967not supported on many operating systems. Use C<rmdir> instead.
20920directories is not supported on many operating systems. Use
20921L<C<rmdir>|/rmdir FILENAME> instead.
1796820922
1796920923=end original
1797020924
17971注: スーパーユーザ権限で、Perl に -U を付けて実行した場合でなければ、
20925注: スーパーユーザ権限で、Perl に B<-U> を付けて実行した場合でなければ、
17972C<unlink> はディレクトリを削除しようとすることはありません。
20926L<C<unlink>|/unlink LIST> はディレクトリを削除しようとすることはありません。
1797320927この条件にあう場合にも、ディレクトリの削除は、
1797420928ファイルシステムに多大な損害を与える可能性があります。
17975最後に、C<unlink> をディレクトリに使うのはほとんどの OS では
20929最後に、L<C<unlink>|/unlink LIST> をディレクトリに使うのはほとんどの OS では
1797620930対応していません。
17977代わりに C<rmdir> を使ってください。
20931代わりに L<C<rmdir>|/rmdir FILENAME> を使ってください。
1797820932
1797920933=begin original
1798020934
17981If LIST is omitted, C<unlink> uses C<$_>.
20935If LIST is omitted, L<C<unlink>|/unlink LIST> uses L<C<$_>|perlvar/$_>.
1798220936
1798320937=end original
1798420938
17985LIST が省略されると、C<unlink> は C<$_> を使います。
20939LIST が省略されると、L<C<unlink>|/unlink LIST> L<C<$_>|perlvar/$_>
20940使います。
1798620941
1798720942=item unpack TEMPLATE,EXPR
1798820943X<unpack>
1798920944
1799020945=item unpack TEMPLATE
1799120946
1799220947=for Pod::Functions convert binary structure into normal perl variables
1799320948
1799420949=begin original
1799520950
17996C<unpack> does the reverse of C<pack>: it takes a string
20951L<C<unpack>|/unpack TEMPLATE,EXPR> does the reverse of
20952L<C<pack>|/pack TEMPLATE,LIST>: it takes a string
1799720953and expands it out into a list of values.
1799820954(In scalar context, it returns merely the first value produced.)
1799920955
1800020956=end original
1800120957
18002C<unpack> は C<pack> の逆を行ないます: 構造体を表わす文字列をとり、
20958L<C<unpack>|/unpack TEMPLATE,EXPR> L<C<pack>|/pack TEMPLATE,LIST> の逆を
20959行ないます: 構造体を表わす文字列をとり、
1800320960リスト値に展開し、その配列値を返します。
1800420961(スカラコンテキストでは、単に最初の値を返します。)
1800520962
1800620963=begin original
1800720964
18008If EXPR is omitted, unpacks the C<$_> string.
20965If EXPR is omitted, unpacks the L<C<$_>|perlvar/$_> string.
1800920966See L<perlpacktut> for an introduction to this function.
1801020967
1801120968=end original
1801220969
18013EXPR が省略されると、C<$_> の文字列を unpack します。
20970EXPR が省略されると、L<C<$_>|perlvar/$_> の文字列を unpack します。
1801420971この関数の説明については L<perlpacktut> を参照してください。
1801520972
1801620973=begin original
1801720974
1801820975The string is broken into chunks described by the TEMPLATE. Each chunk
1801920976is converted separately to a value. Typically, either the string is a result
18020of C<pack>, or the characters of the string represent a C structure of some
20977of L<C<pack>|/pack TEMPLATE,LIST>, or the characters of the string
18021kind.
20978represent a C structure of some kind.
1802220979
1802320980=end original
1802420981
1802520982文字列は TEMPLATE で示された固まりに分割されます。
1802620983それぞれの固まりは別々に値に変換されます。
18027典型的には、文字列は C<pack> の結果あるいはある種の C の構造体
20984典型的には、文字列は L<C<pack>|/pack TEMPLATE,LIST> の結果あるいはある種の
18028文字列表現の文字列です。
20985C の構造体の文字列表現の文字列です。
1802920986
1803020987=begin original
1803120988
18032The TEMPLATE has the same format as in the C<pack> function.
20989The TEMPLATE has the same format as in the
20990L<C<pack>|/pack TEMPLATE,LIST> function.
1803320991Here's a subroutine that does substring:
1803420992
1803520993=end original
1803620994
18037TEMPLATE は、C<pack> 関数と同じフォーマットを使います。
20995TEMPLATE は、L<C<pack>|/pack TEMPLATE,LIST> 関数と同じフォーマットを使います。
1803820996部分文字列を取り出すうサブルーチンの例を示します:
1803920997
1804020998 sub substr {
18041 my($what,$where,$howmuch) = @_;
20999 my ($what, $where, $howmuch) = @_;
1804221000 unpack("x$where a$howmuch", $what);
1804321001 }
1804421002
1804521003=begin original
1804621004
1804721005and then there's
1804821006
1804921007=end original
1805021008
1805121009これもそうです。
1805221010
1805321011 sub ordinal { unpack("W",$_[0]); } # same as ord()
1805421012
1805521013=begin original
1805621014
18057In addition to fields allowed in pack(), you may prefix a field with
21015In addition to fields allowed in L<C<pack>|/pack TEMPLATE,LIST>, you may
18058a %<number> to indicate that
21016prefix a field with a %<number> to indicate that
1805921017you want a <number>-bit checksum of the items instead of the items
18060themselves. Default is a 16-bit checksum. Checksum is calculated by
21018themselves. Default is a 16-bit checksum. The checksum is calculated by
1806121019summing numeric values of expanded values (for string fields the sum of
1806221020C<ord($char)> is taken; for bit fields the sum of zeroes and ones).
1806321021
1806421022=end original
1806521023
18066pack() で利用可能なフィールドの他に、
21024L<C<pack>|/pack TEMPLATE,LIST> で利用可能なフィールドの他に、
1806721025フィールドの前に %<数値> というものを付けて、
1806821026項目自身の代わりに、その項目の <数値>-ビットのチェックサムを
1806921027計算させることができます。
1807021028デフォルトは、16-ビットチェックサムです。
1807121029チェックサムは展開された値の数値としての値の合計
1807221030(文字列フィールドの場合は C<ord($char)> の合計;
1807321031ビットフィールドの場合は 0 と 1 の合計) が用いられます。
1807421032
1807521033=begin original
1807621034
1807721035For example, the following
1807821036computes the same number as the System V sum program:
1807921037
1808021038=end original
1808121039
1808221040たとえば、以下のコードは
1808321041System V の sum プログラムと同じ値を計算します。
1808421042
18085 $checksum = do {
21043 my $checksum = do {
1808621044 local $/; # slurp!
18087 unpack("%32W*",<>) % 65535;
21045 unpack("%32W*", readline) % 65535;
1808821046 };
1808921047
1809021048=begin original
1809121049
1809221050The following efficiently counts the number of set bits in a bit vector:
1809321051
1809421052=end original
1809521053
1809621054以下は、効率的にビットベクターの設定されているビットを
1809721055数えるものです。
1809821056
18099 $setbits = unpack("%32b*", $selectmask);
21057 my $setbits = unpack("%32b*", $selectmask);
1810021058
1810121059=begin original
1810221060
1810321061The C<p> and C<P> formats should be used with care. Since Perl
18104has no way of checking whether the value passed to C<unpack()>
21062has no way of checking whether the value passed to
21063L<C<unpack>|/unpack TEMPLATE,EXPR>
1810521064corresponds to a valid memory location, passing a pointer value that's
1810621065not known to be valid is likely to have disastrous consequences.
1810721066
1810821067=end original
1810921068
1811021069C<p> と C<P> は注意深く使うべきです。
18111Perl は C<unpack()> に渡された値が有効なメモリ位置を指しているかどうか
21070Perl は L<C<unpack>|/unpack TEMPLATE,EXPR> に渡された値が有効なメモリ位置を
18112確認する方法がないので、有効かどうかわからないポインタ値を渡すと
21071指しているかどうかを確認する方法がないので、有効かどうかわからない
18113悲惨な結果を引き起こすかもしれません。
21072ポインタ値を渡すと悲惨な結果を引き起こすかもしれません。
1811421073
1811521074=begin original
1811621075
1811721076If there are more pack codes or if the repeat count of a field or a group
1811821077is larger than what the remainder of the input string allows, the result
1811921078is not well defined: the repeat count may be decreased, or
18120C<unpack()> may produce empty strings or zeros, or it may raise an exception.
21079L<C<unpack>|/unpack TEMPLATE,EXPR> may produce empty strings or zeros,
21080or it may raise an exception.
1812121081If the input string is longer than one described by the TEMPLATE,
1812221082the remainder of that input string is ignored.
1812321083
1812421084=end original
1812521085
1812621086多くの pack コードがある場合や、フィールドやグループの繰り返し回数が
1812721087入力文字列の残りより大きい場合、結果は未定義です:
18128繰り返し回数が減らされる場合もありますし、C<unpack()> が空文字列や 0 を
21088繰り返し回数が減らされる場合もありますし、
21089L<C<unpack>|/unpack TEMPLATE,EXPR> が空文字列や 0 を
1812921090返すこともありますし、例外が発生します。
1813021091もし入力文字列が TEMPLATE で表現されているものより大きい場合、
1813121092入力文字列の残りは無視されます。
1813221093
1813321094=begin original
1813421095
18135See L</pack> for more examples and notes.
21096See L<C<pack>|/pack TEMPLATE,LIST> for more examples and notes.
1813621097
1813721098=end original
1813821099
18139さらなる例と注意に関しては L</pack> を参照してください。
21100さらなる例と注意に関しては L<C<pack>|/pack TEMPLATE,LIST> を参照してください。
1814021101
1814121102=item unshift ARRAY,LIST
1814221103X<unshift>
1814321104
18144=item unshift EXPR,LIST
18145
1814621105=for Pod::Functions prepend more elements to the beginning of a list
1814721106
1814821107=begin original
1814921108
18150Does the opposite of a C<shift>. Or the opposite of a C<push>,
21109Add one or more elements to the B<beginning> of an array. This is the
18151depending on how you look at it. Prepends list to the front of the
21110opposite of a L<C<shift>|/shift ARRAY>.
18152array and returns the new number of elements in the array.
1815321111
1815421112=end original
1815521113
18156C<shift> の逆操作を行ないます。
21114一つまたは複数の要素を配列の B<先頭> に追加します。
18157見方を変えば、C<push> の逆操作とも考えられます。
21115は L<C<shift>|/shift ARRAY> の逆操作す。
18158LIST を ARRAY の先頭に入れて、新しくできた配列の要素の数を返します。
1815921116
18160 unshift(@ARGV, '-e') unless $ARGV[0] =~ /^-/;
21117 my @animals = ("cat");
21118 unshift(@animals, "mouse"); # ("mouse", "cat")
1816121119
21120 my @colors = ("red");
21121 unshift(@colors, ("blue", "green")); # ("blue", "green", "red")
21122
1816221123=begin original
1816321124
18164Note the LIST is prepended whole, not one element at a time, so the
21125Returns the new number of elements in the updated array.
18165prepended elements stay in the same order. Use C<reverse> to do the
18166reverse.
1816721126
1816821127=end original
1816921128
18170LIST は、はらばらにではなく、一度に登録されで、順番はそのままです。
21129更新された配列要素数を返します。
18171逆順に登録するには、C<reverse> を使ってください。
1817221130
21131 # Return value is the number of items in the updated array
21132 my $color_count = unshift(@colors, ("yellow", "purple"));
21133
21134 say "There are $color_count colors in the updated array";
21135
1817321136=begin original
1817421137
18175Starting with Perl 5.14, C<unshift> can take a scalar EXPR, which must hold
21138Note the LIST is prepended whole, not one element at a time, so the
18176a reference to an unblessed array. The argument will be dereferenced
21139prepended elements stay in the same order. Use
18177automatically. This aspect of C<unshift> is considered highly
21140L<C<reverse>|/reverse LIST> to do the reverse.
18178experimental. The exact behaviour may change in a future version of Perl.
1817921141
1818021142=end original
1818121143
18182Perl 5.14 からC<unshift> スカラの EXPR を取ることができるようになした;
21144LIST 、はらばらではく、一度に登録されるので、順番はそのまです。
18183これ bless されていない配列へのリファレンスでなければなりません
21145逆順に登録するに、L<C<reverse>|/reverse LIST> を使っください。
18184引数は自動的にデリファレンスされます。
18185C<unshift> のこの動作は高度に実験的であると考えられています。
18186正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
1818721146
1818821147=begin original
1818921148
18190To avoid confusing would-be users of your code who are running earlier
21149Starting with Perl 5.14, an experimental feature allowed
18191versions of Perl with mysterious syntax errors, put this sort of thing at
21150L<C<unshift>|/unshift ARRAY,LIST> to take
18192the top of your file to signal that your code will work I<only> on Perls of
21151a scalar expression. This experiment has been deemed unsuccessful, and was
18193a recent vintage:
21152removed as of Perl 5.24.
1819421153
1819521154=end original
1819621155
18197あなたのコードを以前のバージョンの Perl で実行したユーザー不思議な
21156Perl 5.14 から、L<C<unshift>|/unshift ARRAY,LIST> スカラ式を
18198文法エラーで混乱することを避けために、コード最近のバージョンの Perl で
21157ることが出来という実験的機能ありました。
18199I<のみ> 動作するとを示すためにファイル先頭に以下のようなこ
21158この実験は失敗見なされ、Perl 5.24 で削除されました。
18200書いてください:
1820121159
18202 use 5.014; # so push/pop/etc work on scalars (experimental)
18203
1820421160=item untie VARIABLE
1820521161X<untie>
1820621162
1820721163=for Pod::Functions break a tie binding to a variable
1820821164
1820921165=begin original
1821021166
1821121167Breaks the binding between a variable and a package.
1821221168(See L<tie|/tie VARIABLE,CLASSNAME,LIST>.)
1821321169Has no effect if the variable is not tied.
1821421170
1821521171=end original
1821621172
1821721173変数とパッケージの間の結合を解きます。
1821821174(L<tie|/tie VARIABLE,CLASSNAME,LIST> を参照してください。)
1821921175結合されていない場合は何も起きません。
1822021176
1822121177=item use Module VERSION LIST
1822221178X<use> X<module> X<import>
1822321179
1822421180=item use Module VERSION
1822521181
1822621182=item use Module LIST
1822721183
1822821184=item use Module
1822921185
18230=item use VERSION
18231
1823221186=for Pod::Functions load in a module at compile time and import its namespace
1823321187
1823421188=begin original
1823521189
1823621190Imports some semantics into the current package from the named module,
1823721191generally by aliasing certain subroutine or variable names into your
1823821192package. It is exactly equivalent to
1823921193
1824021194=end original
1824121195
1824221196指定したモジュールから、現在のパッケージにさまざまな内容をインポートします;
1824321197多くは、パッケージのサブルーチン名や、変数名に別名を付けることで、
1824421198実現されています。
1824521199これは、以下は等価ですが:
1824621200
1824721201 BEGIN { require Module; Module->import( LIST ); }
1824821202
1824921203=begin original
1825021204
1825121205except that Module I<must> be a bareword.
1825221206The importation can be made conditional by using the L<if> module.
1825321207
1825421208=end original
1825521209
1825621210Module が I<裸の単語でなければならない> ことを除けば、です。
1825721211インポートは、L<if> を使って条件付きで行うことができます。
1825821212
1825921213=begin original
1826021214
18261In the peculiar C<use VERSION> form, VERSION may be either a positive
21215The C<BEGIN> forces the L<C<require>|/require VERSION> and
18262decimal fraction such as 5.006, which will be compared to C<$]>, or a v-string
21216L<C<import>|/import LIST> to happen at compile time. The
18263of the form v5.6.1, which will be compared to C<$^V> (aka $PERL_VERSION). An
21217L<C<require>|/require VERSION> makes sure the module is loaded into
18264exception is raised if VERSION is greater than the version of the
21218memory if it hasn't been yet. The L<C<import>|/import LIST> is not a
18265current Perl interpreter; Perl will not attempt to parse the rest of the
21219builtin; it's just an ordinary static method
18266file. Compare with L</require>, which can do a similar check at run time.
21220call into the C<Module> package to tell the module to import the list of
18267Symmetrically, C<no VERSION> allows you to specify that you want a version
21221features back into the current package. The module can implement its
18268of Perl older than the specified one.
21222L<C<import>|/import LIST> method any way it likes, though most modules
21223just choose to derive their L<C<import>|/import LIST> method via
21224inheritance from the C<Exporter> class that is defined in the
21225L<C<Exporter>|Exporter> module. See L<Exporter>. If no
21226L<C<import>|/import LIST> method can be found, then the call is skipped,
21227even if there is an AUTOLOAD method.
1826921228
1827021229=end original
1827121230
18272特に C<use VERSION> の形式では、
21231C<BEGIN> によって、L<C<require>|/require VERSION>
18273VERSION は 5.006 のような正の 10 進小数 (C<$]> と比較されます)か、v5.6.1 の形
21232L<C<import>|/import LIST> は、コンパイル時に
18274(C<$^V> (またの名を $PERL_VERSION) と比較されます) のv-文字列で指定します。
21233実行されることになります。
18275VERSION が Perl の現在のバージョンより大きいと例外発生しす;
21234L<C<require>|/require VERSION> モジュールがまだメモリに
18276Perl はファイルの残りを読み込みせん
21235ロードされていなければ、ロードし
18277L</require> と似ていますがこれ実行時にチェックす。
21236L<C<import>|/import LIST> 組込みの関数でありません; さまざまな機能を
18278対称的C<no VERSION> は指定されたバージョンより古いバージョンの Perl で
21237現在のパッケージインポートするように C<Module> パッケージに伝えるために
18279動作させたいことを意味します。
21238呼ばれる、通常の静的メソッドです。
21239モジュール側では、L<C<import>|/import LIST> メソッドをどのようにでも
21240実装することができますが、多くのモジュールでは、
21241L<C<Exporter>|Exporter> モジュールで定義された、
21242C<Exporter> クラスからの継承によって、L<C<import>|/import LIST> メソッドを
21243行なうようにしています。
21244L<Exporter>モジュールを参照してください。
21245L<C<import>|/import LIST>メソッドが見つからなかった場合、AUTOLOAD メソッドが
21246あったとしても呼び出しはスキップされます。
1828021247
1828121248=begin original
1828221249
18283Specifying VERSION as a literal of the form v5.6.1 should generally be
21250If you do not want to call the package's L<C<import>|/import LIST>
18284avoided, because it leads to misleading error messages under earlier
21251method (for instance,
18285versions of Perl (that is, prior to 5.6.0) that do not support this
21252to stop your namespace from being altered), explicitly supply the empty list:
18286syntax. The equivalent numeric version should be used instead.
1828721253
1828821254=end original
1828921255
18290VERSION v5.6.1 の形のリテラル指定することは一般的には避けるべきです;
21256パッケージの L<C<import>|/import LIST> メソッド呼び出したくない場合(例えば、
18291この文法対応していない Perl の初期のバージョン
21257名前空間を変更したくい場合ど)は明示的空リストを指定してくださ:
18292(つまり、 5.6.0 以前) では誤解させるようなエラーメッセージが出るからです。
18293代わりに等価な数値表現を使うべきです。
1829421258
18295 use v5.6.1; # compile time version check
21259 use Module ();
18296 use 5.6.1; # ditto
18297 use 5.006_001; # ditto; preferred for backwards compatibility
1829821260
1829921261=begin original
1830021262
18301This is often useful if you need to check the current Perl version before
21263That is exactly equivalent to
18302C<use>ing library modules that won't work with older versions of Perl.
18303(We try not to do this more than we have to.)
1830421264
1830521265=end original
1830621266
18307これは古いバージョンの Perl 動かなくなったライブラリモジュールを
21267これは以下と完全に等価す:
18308C<use> する前に、現在の Perl のバージョンを調べたい場合に有用です。
18309(我々は必要な場合以外にそのようなことがないように努力していますが。)
1831021268
18311=begin original
21269 BEGIN { require Module }
1831221270
18313C<use VERSION> also enables all features available in the requested
18314version as defined by the C<feature> pragma, disabling any features
18315not in the requested version's feature bundle. See L<feature>.
18316Similarly, if the specified Perl version is greater than or equal to
183175.12.0, strictures are enabled lexically as
18318with C<use strict>. Any explicit use of
18319C<use strict> or C<no strict> overrides C<use VERSION>, even if it comes
18320before it. In both cases, the F<feature.pm> and F<strict.pm> files are
18321not actually loaded.
18322
18323=end original
18324
18325C<use VERSION> は、C<feature> プラグマで定義されたように、指定された
18326バージョンで利用可能な全ての機能を有効にし、指定されたバージョンの機能の
18327束にない機能を無効にします。
18328L<feature> を参照してください。
18329同様に、指定された Perl のバージョンが 5.12.0 以上の場合、
18330制限は C<use strict> と同様にレキシカルに有効になります。
18331明示的に C<use strict> や C<no strict> を使うと、例え先に
18332指定されていたとしても、C<use VERSION> を上書きします。
18333どちらの場合も、F<feature.pm> と F<strict.pm> ファイルは実際には
18334読み込まれません。
18335
1833621271=begin original
1833721272
18338The C<BEGIN> forces the C<require> and C<import> to happen at compile time. The
21273If the VERSION argument is present between Module and LIST, then the
18339C<require> makes sure the module is loaded into memory if it hasn't been
21274L<C<use>|/use Module VERSION LIST> will call the C<VERSION> method in
18340yet. The C<import> is not a builtin; it's just an ordinary static method
21275class Module with the given version as an argument:
18341call into the C<Module> package to tell the module to import the list of
18342features back into the current package. The module can implement its
18343C<import> method any way it likes, though most modules just choose to
18344derive their C<import> method via inheritance from the C<Exporter> class that
18345is defined in the C<Exporter> module. See L<Exporter>. If no C<import>
18346method can be found then the call is skipped, even if there is an AUTOLOAD
18347method.
1834821276
1834921277=end original
1835021278
18351C<BEGIN> によって、C<require> C<import> は、コンパイル時
21279Module LIST の間 VERSION 引数がある場合、
18352実行されることになります。
21280L<C<use>|/use Module VERSION LIST> は Module クラスの
18353C<require> は、モジュールがまだモリにローされていなければします
21281C<VERSION> メソッ与えられたバジョンを引数とて呼び出します:
18354C<import> は、組込みの関数ではありません; さまざまな機能を現在のパッケージに
18355インポートするように C<Module> パッケージに伝えるために呼ばれる、
18356通常の静的メソッドです。
18357モジュール側では、C<import> メソッドをどのようにでも実装することが
18358できますが、多くのモジュールでは、C<Exporter> モジュールで定義された、
18359C<Exporter> クラスからの継承によって、C<import> メソッドを行なうように
18360しています。
18361L<Exporter>モジュールを参照してください。
18362C<import>メソッドが見つからなかった場合、AUTOLOAD メソッドがあったとしても
18363呼び出しはスキップされます。
1836421282
21283 use Module 12.34;
21284
1836521285=begin original
1836621286
18367If you do not want to call the package's C<import> method (for instance,
21287is equivalent to:
18368to stop your namespace from being altered), explicitly supply the empty list:
1836921288
1837021289=end original
1837121290
18372パッケージの C<import> メソッドを呼び出したくない場合(例えば、名前空間を
21291は以下と等価です:
18373変更したくない場合など)は、明示的に空リストを指定してください:
1837421292
18375 use Module ();
21293 BEGIN { require Module; Module->VERSION(12.34) }
1837621294
1837721295=begin original
1837821296
18379That is exactly equivalent to
21297The L<default C<VERSION> method|UNIVERSAL/C<VERSION ( [ REQUIRE ] )>>,
21298inherited from the L<C<UNIVERSAL>|UNIVERSAL> class, croaks if the given
21299version is larger than the value of the variable C<$Module::VERSION>.
1838021300
1838121301=end original
1838221302
18383これは以下と完全に等価です:
21303デフォルトの
21304L<default C<VERSION> メソッド|UNIVERSAL/C<VERSION ( [ REQUIRE ] )>> は、
21305L<C<UNIVERSAL>|UNIVERSAL> クラスから継承したもので、
21306与えられたバージョンが 変数 C<$Module::VERSION> の値より大きい場合に
21307警告を出します。
1838421308
18385 BEGIN { require Module }
18386
1838721309=begin original
1838821310
18389If the VERSION argument is present between Module and LIST, then the
21311The VERSION argument cannot be an arbitrary expression. It only counts
18390C<use> will call the VERSION method in class Module with the given
21312as a VERSION argument if it is a version number literal, starting with
18391version as an argument. The default VERSION method, inherited from
21313either a digit or C<v> followed by a digit. Anything that doesn't
18392the UNIVERSAL class, croaks if the given version is larger than the
21314look like a version literal will be parsed as the start of the LIST.
18393value of the variable C<$Module::VERSION>.
21315Nevertheless, many attempts to use an arbitrary expression as a VERSION
21316argument will appear to work, because L<Exporter>'s C<import> method
21317handles numeric arguments specially, performing version checks rather
21318than treating them as things to export.
1839421319
1839521320=end original
1839621321
18397Module と LIST の間に VERSION 引数がある場合、C<use> Module クラス
21322VERSION 引数は任意式ではありません。
18398VERSION メソッドを、与えられたバージョンを引数として呼び出します。
21323VERSION 引数が数値まは C<v> に引き続いて数値であるバージョン番号リテラルの
18399デフォルト VERSION メソッドは、 UNIVERSAL クラスから継承したもので、
21324場合にみ扱われます。
18400与えられたバージョン 変数 C<$Module::VERSION>値より大きい場合に
21325バージョンリテラルのように見えないものは LIST開始としてパースされます。
18401警告を出
21326それにも関わらず、VERSION 引数とて任意の式を使おうと
21327多くの試みは動作しているように見えます; なぜなら
21328L<Exporter> の C<import> メソッドは数値引数を特別に扱い、
21329それらをエクスポートするべきものと扱わずにバージョンチェックを
21330実行するからです。
1840221331
1840321332=begin original
1840421333
18405Again, there is a distinction between omitting LIST (C<import> called
21334Again, there is a distinction between omitting LIST (L<C<import>|/import
18406with no arguments) and an explicit empty LIST C<()> (C<import> not
21335LIST> called with no arguments) and an explicit empty LIST C<()>
18407called). Note that there is no comma after VERSION!
21336(L<C<import>|/import LIST> not called). Note that there is no comma
21337after VERSION!
1840821338
1840921339=end original
1841021340
18411繰り返すと、LIST を省略する(C<import> が引数なしで呼び出される)ことと
21341繰り返すと、LIST を省略する(L<C<import>|/import LIST> が引数なしで
18412明示的に空の LIST C<()> を指定する (C<import> は呼び出されない)ことは
21342呼び出される)ことと明示的に空の LIST C<()> を指定する
18413違います。
21343(L<C<import>|/import LIST> は呼び出されない)ことは違います。
1841421344VERSION の後ろにカンマが不要なことに注意してください!
1841521345
1841621346=begin original
1841721347
1841821348Because this is a wide-open interface, pragmas (compiler directives)
18419are also implemented this way. Currently implemented pragmas are:
21349are also implemented this way. Some of the currently implemented
21350pragmas are:
1842021351
1842121352=end original
1842221353
1842321354これは、広く公開されているインタフェースですので、
1842421355プラグマ (コンパイラディレクティブ) も、この方法で実装されています。
18425現在実装されているプラグマには、以下のものがあります:
21356現在実装されているプラグマには、以下のようなものがあります:
1842621357
1842721358 use constant;
1842821359 use diagnostics;
1842921360 use integer;
1843021361 use sigtrap qw(SEGV BUS);
1843121362 use strict qw(subs vars refs);
1843221363 use subs qw(afunc blurfl);
1843321364 use warnings qw(all);
18434 use sort qw(stable _quicksort _mergesort);
21365 use sort qw(stable);
1843521366
1843621367=begin original
1843721368
1843821369Some of these pseudo-modules import semantics into the current
18439block scope (like C<strict> or C<integer>, unlike ordinary modules,
21370block scope (like L<C<strict>|strict> or L<C<integer>|integer>, unlike
18440which import symbols into the current package (which are effective
21371ordinary modules, which import symbols into the current package (which
18441through the end of the file).
21372are effective through the end of the file).
1844221373
1844321374=end original
1844421375
1844521376通常のモジュールが、現在のパッケージにシンボルをインポートする
18446(これは、ファイルの終わりまで有効です) のに対して、
21377(これは、ファイルの終わりまで有効です) のに対して、これらの擬似モジュールの
18447これらの擬似モジュールの一部(C<strict> や C<integer> など)は、
21378一部(L<C<strict>|strict>L<C<integer>|integer> など)は、現在の
18448現在のブロックスコープにインポートを行ないます。
21379ブロックスコープにインポートを行ないます。
1844921380
1845021381=begin original
1845121382
18452Because C<use> takes effect at compile time, it doesn't respect the
21383Because L<C<use>|/use Module VERSION LIST> takes effect at compile time,
18453ordinary flow control of the code being compiled. In particular, putting
21384it doesn't respect the ordinary flow control of the code being compiled.
18454a C<use> inside the false branch of a conditional doesn't prevent it
21385In particular, putting a L<C<use>|/use Module VERSION LIST> inside the
18455from being processed. If a module or pragma only needs to be loaded
21386false branch of a conditional doesn't prevent it
21387from being processed. If a module or pragma only needs to be loaded
1845621388conditionally, this can be done using the L<if> pragma:
1845721389
1845821390=end original
1845921391
18460C<use> はコンパイル時に有効なので、コードがコンパイルされる際の通常の
21392L<C<use>|/use Module VERSION LIST> はコンパイル時に有効なので、コードが
18461流れ制御には従いません。
21393コンパイルされる際の通常の流れ制御には従いません。
18462特に、条件文のうち成立しない側の中に C<use> を書いても、
21394特に、条件文のうち成立しない側の中に L<C<use>|/use Module VERSION LIST>
18463処理を妨げられません。
21395書いても、処理を妨げられません。
1846421396モジュールやプラグマを条件付きでのみ読み込みたい場合、
1846521397L<if> プラグマを使って実現できます:
1846621398
1846721399 use if $] < 5.008, "utf8";
1846821400 use if WANT_WARNINGS, warnings => qw(all);
1846921401
1847021402=begin original
1847121403
18472There's a corresponding C<no> declaration that unimports meanings imported
21404There's a corresponding L<C<no>|/no MODULE VERSION LIST> declaration
18473by C<use>, i.e., it calls C<unimport Module LIST> instead of C<import>.
21405that unimports meanings imported by L<C<use>|/use Module VERSION LIST>,
18474It behaves just as C<import> does with VERSION, an omitted or empty LIST,
21406i.e., it calls C<< Module->unimport(LIST) >> instead of
21407L<C<import>|/import LIST>. It behaves just as L<C<import>|/import LIST>
21408does with VERSION, an omitted or empty LIST,
1847521409or no unimport method being found.
1847621410
1847721411=end original
1847821412
18479これに対して、C<no> 宣言という、C<use> によってインポートされたものを
21413これに対して、L<C<no>|/no MODULE VERSION LIST> 宣言という、
18480インポートされていないことにするものがあります; つまりC<import> の代わりに
21414L<C<use>|/use Module VERSION LIST> によってインポートされもの
18481C<unimport Module LIST> を呼び出します
21415インポートされていないことにするものがあります; つまり、
21416L<C<import>|/import LIST> の代わりに
21417C<< Module->unimport(LIST) >> を呼び出します。
1848221418これは VERSION、省略された LIST、空の LIST、unimport メソッドが見つからない
18483場合などの観点では、C<import> と同様に振る舞います。
21419場合などの観点では、L<C<import>|/import LIST> と同様に振る舞います。
1848421420
1848521421 no integer;
1848621422 no strict 'refs';
1848721423 no warnings;
1848821424
1848921425=begin original
1849021426
18491Care should be taken when using the C<no VERSION> form of C<no>. It is
21427See L<perlmodlib> for a list of standard modules and pragmas. See
18492I<only> meant to be used to assert that the running Perl is of a earlier
21428L<perlrun|perlrun/-m[-]module> for the C<-M> and C<-m> command-line
18493version than its argument and I<not> to undo the feature-enabling side effects
21429options to Perl that give L<C<use>|/use Module VERSION LIST>
18494of C<use VERSION>.
21430functionality from the command-line.
1849521431
1849621432=end original
1849721433
18498C<no> C<no VERSION> 形式使うときには注意を払うべきです
21434標準モジュールやプラグマ一覧は、L<perlmodlib> を参照してください
18499これは引数で指定されたバージョよりも前の Perl で実行されたときに
21435コマドラインから L<C<use>|/use Module VERSION LIST> 機能を
18500アサートされることを意味する I<だけ> で、C<use VERSION> によって
21436指定するための C<-M> C<-m>
18501有効された副作用をなかったことにするもの I<でありません>。
21437コマンドラインオプションついて
21438L<perlrun|perlrun/-m[-]module> を参照してください。
1850221439
21440=item use VERSION
21441
21442=for Pod::Functions enable Perl language features and declare required version
21443
1850321444=begin original
1850421445
18505See L<perlmodlib> for a list of standard modules and pragmas. See L<perlrun>
21446Lexically enables all features available in the requested version as
18506for the C<-M> and C<-m> command-line options to Perl that give C<use>
21447defined by the L<feature> pragma, disabling any features not in the
18507functionality from the command-line.
21448requested version's feature bundle. See L<feature>.
1850821449
1850921450=end original
1851021451
18511標準モジュールやプラグマの一覧は、L<perlmodlib> を参照してくだい。
21452L<feature> プラグマで定義れた、指定されたバージョンで利用可能な
18512コマンドラインから C<use> 機能を指定する C<-M> と C<-m>
21453全ての機能を有効にし、指定されバージョン機能束で要求されていない
18513コマンドラインオプションについは L<perlrun> 参照てください
21454の機能無効にます
21455L<feature> を参照してください。
1851421456
21457=begin original
21458
21459VERSION may be either a v-string such as v5.24.1, which will be compared
21460to L<C<$^V>|perlvar/$^V> (aka $PERL_VERSION), or a numeric argument of the
21461form 5.024001, which will be compared to L<C<$]>|perlvar/$]>. An
21462exception is raised if VERSION is greater than the version of the current
21463Perl interpreter; Perl will not attempt to parse the rest of the file.
21464Compare with L<C<require>|/require VERSION>, which can do a similar check
21465at run time.
21466
21467=end original
21468
21469VERSION は v5.24.1 のような v-文字列
21470(L<C<$^V>|perlvar/$^V> (またの名を $PERL_VERSION) と比較されます)
21471か、5.024001 の形の数値形式 (L<C<$]>|perlvar/$]> と比較されます) で
21472指定します。
21473VERSION が Perl の現在のバージョンより大きいと、例外が発生します;
21474Perl はファイルの残りを読み込みません。
21475L<C<require>|/require VERSION> と似ていますが、これは実行時に
21476チェックされます。
21477
21478=begin original
21479
21480If the specified Perl version is 5.12 or higher, strictures are enabled
21481lexically as with L<C<use strict>|strict>. Similarly, if the specified
21482Perl version is 5.35.0 or higher, L<warnings> are enabled. Later use of
21483C<use VERSION> will override all behavior of a previous C<use VERSION>,
21484possibly removing the C<strict>, C<warnings>, and C<feature> added by it.
21485C<use VERSION> does not load the F<feature.pm>, F<strict.pm>, or
21486F<warnings.pm> files.
21487
21488=end original
21489
21490指定された Perl のバージョンが 5.12 以上の場合、
21491L<C<use strict>|strict> と同様に、strict 機能がレキシカルに有効になります。
21492同様に、指定された Perl のバージョンが 5.35.0 以上の場合、
21493L<warnings> が有効になります。
21494後から使った C<use VERSION> は先の
21495C<use VERSION> の全ての振る舞いを上書きするので、
21496それによって追加された C<strict>, C<feature>, C<feature> を
21497削除することがあります。
21498C<use VERSION> は F<feature.pm>, F<strict.pm>, F<warnings.pm> ファイルは
21499読み込みません。
21500
21501=begin original
21502
21503In the current implementation, any explicit use of C<use strict> or
21504C<no strict> overrides C<use VERSION>, even if it comes before it.
21505However, this may be subject to change in a future release of Perl, so new
21506code should not rely on this fact. It is recommended that a
21507C<use VERSION> declaration be the first significant statement within a
21508file (possibly after a C<package> statement or any amount of whitespace or
21509comment), so that its effects happen first, and other pragmata are applied
21510after it.
21511
21512=end original
21513
21514現在の実装では、明示的に C<use strict> や C<no strict> を使うと、例え先に
21515指定されていたとしても、C<use VERSION> を上書きします。
21516しかし、これは将来のリリースの Perl で変更されるかもしれないので、
21517新しいコードはこの事実に依存するべきではありません。
21518(場合によっては C<package> 文や任意の量の空白やコメントの後の)ファイルの
21519最初の有効な文として C<use VERSION> 宣言することを勧めます;
21520この機能が最初に怒り、その他のプラグマはその後に適用されるからです。
21521
21522=begin original
21523
21524Specifying VERSION as a numeric argument of the form 5.024001 should
21525generally be avoided as older less readable syntax compared to
21526v5.24.1. Before perl 5.8.0 released in 2002 the more verbose numeric
21527form was the only supported syntax, which is why you might see it in
21528older code.
21529
21530=end original
21531
21532VERSION に 5.024001 の形の数値引数を指定することは一般的には避けるべきです;
21533v5.24.1 に比べてより古く読みにくい文法だからです。
21534(2002 年にリリースされた) perl 5.8.0 より前では、より冗長な
21535数値形式が唯一対応している文法でした; これが古いコードでこれを
21536見るかも知れない理由です。
21537
21538=begin original
21539
21540 use v5.24.1; # compile time version check
21541 use 5.24.1; # ditto
21542 use 5.024_001; # ditto; older syntax compatible with perl 5.6
21543
21544=end original
21545
21546 use v5.24.1; # 実行時バージョンチェック
21547 use 5.24.1; # 同様
21548 use 5.024_001; # 同様; perl 5.6 と互換性のある古い文法
21549
21550=begin original
21551
21552This is often useful if you need to check the current Perl version before
21553L<C<use>|/use Module VERSION LIST>ing library modules that won't work
21554with older versions of Perl.
21555(We try not to do this more than we have to.)
21556
21557=end original
21558
21559これは古いバージョンの Perl で動かなくなったライブラリモジュールを
21560L<C<use>|/use Module VERSION LIST> する前に、現在の Perl のバージョンを
21561調べたい場合に有用です。
21562(我々は必要な場合以外にそのようなことがないように努力していますが。)
21563
21564=begin original
21565
21566Symmetrically, C<no VERSION> allows you to specify that you want a version
21567of Perl older than the specified one. Historically this was added during
21568early designs of the Raku language (formerly "Perl 6"), so that a Perl 5
21569program could begin
21570
21571=end original
21572
21573対称的に、C<no VERSION> は指定されたバージョンより古いバージョンの Perl で
21574動作させたいことを意味します。
21575歴史的には、これは Raku 言語 (以前は "Perl 6") の初期仕様で加えられたので、
21576Perl 5 のプログラムは次のもので始めて:
21577
21578 no 6;
21579
21580=begin original
21581
21582to declare that it is not a Perl 6 program. As the two languages have
21583different implementations, file naming conventions, and other
21584infrastructure, this feature is now little used in practice and should be
21585avoided in newly-written code.
21586
21587=end original
21588
21589Perl 6 プログラムでないことを宣言できました。
21590二つの言語は異なる実装、命名規則、およびその他のインフラを持つので、
21591今ではこの機能は実際にはほとんど使われておらず、新しいコードでは
21592避けるべきです。
21593
21594=begin original
21595
21596Care should be taken when using the C<no VERSION> form, as it is I<only>
21597meant to be used to assert that the running Perl is of a earlier version
21598than its argument and I<not> to undo the feature-enabling side effects
21599of C<use VERSION>.
21600
21601=end original
21602
21603C<no VERSION> 形式を使うときには注意を払うべきです;
21604これは引数で指定されたバージョンよりも前の Perl で実行されたときに
21605アサートされることを意味する I<だけ> で、C<use VERSION> によって
21606有効にされた副作用をなかったことにするもの I<ではありません>。
21607
1851521608=item utime LIST
1851621609X<utime>
1851721610
1851821611=for Pod::Functions set a file's last access and modify times
1851921612
1852021613=begin original
1852121614
1852221615Changes the access and modification times on each file of a list of
1852321616files. The first two elements of the list must be the NUMERIC access
1852421617and modification times, in that order. Returns the number of files
1852521618successfully changed. The inode change time of each file is set
1852621619to the current time. For example, this code has the same effect as the
18527Unix touch(1) command when the files I<already exist> and belong to
21620Unix L<touch(1)> command when the files I<already exist> and belong to
1852821621the user running the program:
1852921622
1853021623=end original
1853121624
1853221625ファイルのアクセス時刻と修正(modification) 時刻を変更します。
1853321626LIST の最初の二つの要素に、数値で表わしたアクセス時刻と修正時刻を
1853421627順に指定します。
1853521628変更に成功したファイルの数を返します。
1853621629各ファイルの inode 変更(change)時刻には、その時点の時刻が設定されます。
1853721630例えば、このコードはファイルが I<既に存在して> いて、ユーザーが
1853821631実行しているプログラムに従っているなら、
18539Unix の touch(1) コマンドと同じ効果があります。
21632Unix の L<touch(1)> コマンドと同じ効果があります。
1854021633
1854121634 #!/usr/bin/perl
18542 $atime = $mtime = time;
21635 my $atime = my $mtime = time;
1854321636 utime $atime, $mtime, @ARGV;
1854421637
1854521638=begin original
1854621639
18547Since Perl 5.8.0, if the first two elements of the list are C<undef>,
21640Since Perl 5.8.0, if the first two elements of the list are
18548the utime(2) syscall from your C library is called with a null second
21641L<C<undef>|/undef EXPR>,
21642the L<utime(2)> syscall from your C library is called with a null second
1854921643argument. On most systems, this will set the file's access and
1855021644modification times to the current time (i.e., equivalent to the example
1855121645above) and will work even on files you don't own provided you have write
1855221646permission:
1855321647
1855421648=end original
1855521649
18556Perl 5.8.0 から、リストの最初の二つの要素が C<undef> である場合、
21650Perl 5.8.0 から、リストの最初の二つの要素が L<C<undef>|/undef EXPR> である
18557C ライブラリの utime(2) システムコールを、秒の引数を null として
21651場合、C ライブラリの L<utime(2)> システムコールを、秒の引数を null として
1855821652呼び出します。
1855921653ほとんどのシステムでは、これによってファイルのアクセス時刻と修正時刻を
1856021654現在の時刻にセットし(つまり、上記の例と等価です)、
1856121655書き込み権限があれば他のユーザーのファイルに対しても動作します。
1856221656
18563 for $file (@ARGV) {
21657 for my $file (@ARGV) {
18564 utime(undef, undef, $file)
21658 utime(undef, undef, $file)
18565 || warn "couldn't touch $file: $!";
21659 || warn "Couldn't touch $file: $!";
18566 }
21660 }
1856721661
1856821662=begin original
1856921663
1857021664Under NFS this will use the time of the NFS server, not the time of
1857121665the local machine. If there is a time synchronization problem, the
1857221666NFS server and local machine will have different times. The Unix
18573touch(1) command will in fact normally use this form instead of the
21667L<touch(1)> command will in fact normally use this form instead of the
1857421668one shown in the first example.
1857521669
1857621670=end original
1857721671
1857821672NFS では、これはローカルマシンの時刻ではなく、NFS サーバーの時刻が
1857921673使われます。
1858021674時刻同期に問題がある場合、NFS サーバーとローカルマシンで違う時刻に
1858121675なっている場合があります。
18582実際のところ、Unix の touch(1) コマンドは普通、最初の例ではなく、
21676実際のところ、Unix の L<touch(1)> コマンドは普通、最初の例ではなく、
1858321677この形を使います。
1858421678
1858521679=begin original
1858621680
18587Passing only one of the first two elements as C<undef> is
21681Passing only one of the first two elements as L<C<undef>|/undef EXPR> is
18588equivalent to passing a 0 and will not have the effect
21682equivalent to passing a 0 and will not have the effect described when
18589described when both are C<undef>. This also triggers an
21683both are L<C<undef>|/undef EXPR>. This also triggers an
1859021684uninitialized warning.
1859121685
1859221686=end original
1859321687
18594最初の二つの要素のうち、一つだけに C<undef> を渡すと、その要素は 0 を
21688最初の二つの要素のうち、一つだけに L<C<undef>|/undef EXPR> を渡すと、その
18595渡すのと等価となり、上述の、両方に C<undef> を渡した時と同じ
21689要素は 0 を渡すのと等価となり、上述の、両方に L<C<undef>|/undef EXPR>
18596効果ではありません。
21690渡した時と同じ効果ではありません。
1859721691この場合は、未初期化の警告が出ます。
1859821692
1859921693=begin original
1860021694
18601On systems that support futimes(2), you may pass filehandles among the
21695On systems that support L<futimes(2)>, you may pass filehandles among the
18602files. On systems that don't support futimes(2), passing filehandles raises
21696files. On systems that don't support L<futimes(2)>, passing filehandles raises
1860321697an exception. Filehandles must be passed as globs or glob references to be
1860421698recognized; barewords are considered filenames.
1860521699
1860621700=end original
1860721701
18608futimes(2) に対応しているシステムでは、ファイルハンドルを引数として
21702L<futimes(2)> に対応しているシステムでは、ファイルハンドルを引数として
1860921703渡せます。
18610futimes(2) に対応していないシステムでは、ファイルハンドルを渡すと
21704L<futimes(2)> に対応していないシステムでは、ファイルハンドルを渡すと
1861121705例外が発生します。
1861221706ファイルハンドルを認識させるためには、グロブまたはリファレンスとして
1861321707渡されなければなりません; 裸の単語はファイル名として扱われます。
1861421708
1861521709=begin original
1861621710
1861721711Portability issues: L<perlport/utime>.
1861821712
1861921713=end original
1862021714
1862121715移植性の問題: L<perlport/utime>。
1862221716
1862321717=item values HASH
1862421718X<values>
1862521719
1862621720=item values ARRAY
1862721721
18628=item values EXPR
18629
1863021722=for Pod::Functions return a list of the values in a hash
1863121723
1863221724=begin original
1863321725
1863421726In list context, returns a list consisting of all the values of the named
1863521727hash. In Perl 5.12 or later only, will also return a list of the values of
1863621728an array; prior to that release, attempting to use an array argument will
1863721729produce a syntax error. In scalar context, returns the number of values.
1863821730
1863921731=end original
1864021732
1864121733リストコンテキストでは、指定したハッシュのすべての値を返します。
18642Perl 5.12 以降でのみ、配列の全ての値からなるリストも
21734Perl 5.12 以降でのみ、配列の全ての値からなるリストも返します;
18643返します; このリリースの前では、配列要素に使おうとすると文法エラーが
21735このリリースの前では、配列要素に使おうとすると文法エラーが発生します。
18644発生します。
1864521736スカラコンテキストでは、値の数を返します。
1864621737
1864721738=begin original
1864821739
1864921740Hash entries are returned in an apparently random order. The actual random
1865021741order is specific to a given hash; the exact same series of operations
18651on two hashes may result in a different order for each hash. Any insertion
21742on two hashes may result in a different order for each hash. Any insertion
1865221743into the hash may change the order, as will any deletion, with the exception
18653that the most recent key returned by C<each> or C<keys> may be deleted
21744that the most recent key returned by L<C<each>|/each HASH> or
18654without changing the order. So long as a given hash is unmodified you may
21745L<C<keys>|/keys HASH> may be deleted without changing the order. So
18655rely on C<keys>, C<values> and C<each> to repeatedly return the same order
21746long as a given hash is unmodified you may rely on
18656as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
21747L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and
18657details on why hash order is randomized. Aside from the guarantees
21748L<C<each>|/each HASH> to repeatedly return the same order
21749as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
21750details on why hash order is randomized. Aside from the guarantees
1865821751provided here the exact details of Perl's hash algorithm and the hash
18659traversal order are subject to change in any release of Perl.
21752traversal order are subject to change in any release of Perl. Tied hashes
21753may behave differently to Perl's hashes with respect to changes in order on
21754insertion and deletion of items.
1866021755
1866121756=end original
1866221757
1866321758ハッシュ要素は見かけ上、ランダムな順序で返されます。
1866421759実際のランダムな順序はハッシュに固有です; 二つのハッシュに全く同じ一連の
1866521760操作を行っても、ハッシュによって異なった順序になります。
1866621761ハッシュへの挿入によって順序が変わることがあります; 削除も同様ですが、
18667C<each> または C<keys> によって返されたもっとも最近のキーは順序を
21762L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも
18668変えることなく削除できます。
21763最近のキーは順序を変えることなく削除できます。
18669ハッシュが変更されない限り、C<keys>, C<values>, C<each> が繰り返し同じ順序で
21764ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>,
18670返すことに依存してもかまいません。
21765L<C<each>|/each HASH> が繰り返し同じ順序で返すことに依存してもかまいません。
1867121766なぜハッシュの順序がランダム化されているかの詳細については
1867221767L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。
1867321768ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の
1867421769正確な詳細は Perl のリリースによって変更される可能性があります。
21770tie されたハッシュは、アイテムの挿入と削除の順序に関して Perl のハッシュと
21771異なった振る舞いをします。
1867521772
1867621773=begin original
1867721774
18678As a side effect, calling values() resets the HASH or ARRAY's internal
21775As a side effect, calling L<C<values>|/values HASH> resets the HASH or
18679iterator, see L</each>. (In particular, calling values() in void context
21776ARRAY's internal iterator (see L<C<each>|/each HASH>) before yielding the
18680resets the iterator with no other overhead. Apart from resetting the
21777values. In particular,
18681iterator, C<values @array> in list context is the same as plain C<@array>.
21778calling L<C<values>|/values HASH> in void context resets the iterator
21779with no other overhead.
21780
21781=end original
21782
21783副作用として、L<C<values>|/values HASH> を呼び出すと、
21784値を取り出す前に HASH や ARRAY の
21785内部反復子(L<C<each>|/each HASH> 参照)をリセットします。
21786特に、L<C<values>|/values HASH> を無効コンテキストで呼び出すとその他の
21787オーバーヘッドなしで反復子をリセットします。
21788
21789=begin original
21790
21791Apart from resetting the iterator,
21792C<values @array> in list context is the same as plain C<@array>.
1868221793(We recommend that you use void context C<keys @array> for this, but
1868321794reasoned that taking C<values @array> out would require more
1868421795documentation than leaving it in.)
1868521796
1868621797=end original
1868721798
18688副作用として、values() を呼び出すと HASH や ARRAY の内部反復子を
18689リセットします; C</each> を参照してください。
18690(特に、values() を無効コンテキストで呼び出すとその他のオーバーヘッドなしで
18691反復子をリセットします。
1869221799反復子をリセットするということを除けば、
1869321800リストコンテキストでの C<values @array> は単なる C<@array> と同じです。
1869421801この目的のためには無効コンテキストで C<keys @array> を使うことを
1869521802お勧めしますが、C<values @array> を取り出すにはそのままにするよりも
1869621803より多くの文書が必要だと判断しました。)
1869721804
1869821805=begin original
1869921806
1870021807Note that the values are not copied, which means modifying them will
1870121808modify the contents of the hash:
1870221809
1870321810=end original
1870421811
1870521812値はコピーされないので、返されたリストを変更すると
1870621813ハッシュの中身が変更されることに注意してください。
1870721814
1870821815 for (values %hash) { s/foo/bar/g } # modifies %hash values
1870921816 for (@hash{keys %hash}) { s/foo/bar/g } # same
1871021817
1871121818=begin original
1871221819
18713Starting with Perl 5.14, C<values> can take a scalar EXPR, which must hold
21820Starting with Perl 5.14, an experimental feature allowed
18714a reference to an unblessed hash or array. The argument will be
21821L<C<values>|/values HASH> to take a
18715dereferenced automatically. This aspect of C<values> is considered highly
21822scalar expression. This experiment has been deemed unsuccessful, and was
18716experimental. The exact behaviour may change in a future version of Perl.
21823removed as of Perl 5.24.
1871721824
1871821825=end original
1871921826
18720Perl 5.14 から、C<values> スカラの EXPR を取ることができになりました;
21827Perl 5.14 から、L<C<values>|/values HASH> がスカラを取ることが出来とい
18721これは bless されていないハッシュや配列へのリファレンスでなければなりません
21828実験的機能がありました
18722引数自動的にデリファレンスされま
21829この実験失敗と見なされ、Perl 5.24 で削除されした
18723C<values> のこの動作は高度に実験的であると考えられています。
18724正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
1872521830
18726 for (values $hashref) { ... }
18727 for (values $obj->get_arrayref) { ... }
18728
1872921831=begin original
1873021832
1873121833To avoid confusing would-be users of your code who are running earlier
1873221834versions of Perl with mysterious syntax errors, put this sort of thing at
1873321835the top of your file to signal that your code will work I<only> on Perls of
1873421836a recent vintage:
1873521837
1873621838=end original
1873721839
1873821840あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
1873921841文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
1874021842I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
1874121843書いてください:
1874221844
18743 use 5.012; # so keys/values/each work on arrays
21845 use v5.12; # so keys/values/each work on arrays
18744 use 5.014; # so keys/values/each work on scalars (experimental)
1874521846
1874621847=begin original
1874721848
18748See also C<keys>, C<each>, and C<sort>.
21849See also L<C<keys>|/keys HASH>, L<C<each>|/each HASH>, and
21850L<C<sort>|/sort SUBNAME LIST>.
1874921851
1875021852=end original
1875121853
18752C<keys>, C<each>, C<sort> も参照してください。
21854L<C<keys>|/keys HASH>, L<C<each>|/each HASH>, L<C<sort>|/sort SUBNAME LIST>
21855参照してください。
1875321856
1875421857=item vec EXPR,OFFSET,BITS
1875521858X<vec> X<bit> X<bit vector>
1875621859
1875721860=for Pod::Functions test or set particular bits in a string
1875821861
1875921862=begin original
1876021863
1876121864Treats the string in EXPR as a bit vector made up of elements of
1876221865width BITS and returns the value of the element specified by OFFSET
1876321866as an unsigned integer. BITS therefore specifies the number of bits
1876421867that are reserved for each element in the bit vector. This must
1876521868be a power of two from 1 to 32 (or 64, if your platform supports
1876621869that).
1876721870
1876821871=end original
1876921872
1877021873文字列 EXPR を BITS 幅の要素からなるビットベクターとして扱い、
1877121874OFFSET で指定された要素を符号なし整数として返します。
1877221875従って、 BITS はビットベクターの中の各要素について予約されるビット数です。
1877321876BIT は、1 から 32 まで(プラットホームが
1877421877対応していれば 64 まで) の 2 のべき乗でなければなりません。
1877521878
1877621879=begin original
1877721880
1877821881If BITS is 8, "elements" coincide with bytes of the input string.
1877921882
1878021883=end original
1878121884
1878221885BITS が 8 の場合、「要素」は入力文字列の各バイトと一致します。
1878321886
1878421887=begin original
1878521888
1878621889If BITS is 16 or more, bytes of the input string are grouped into chunks
1878721890of size BITS/8, and each group is converted to a number as with
18788pack()/unpack() with big-endian formats C<n>/C<N> (and analogously
21891L<C<pack>|/pack TEMPLATE,LIST>/L<C<unpack>|/unpack TEMPLATE,EXPR> with
18789for BITS==64). See L<"pack"> for details.
21892big-endian formats C<n>/C<N> (and analogously for BITS==64). See
21893L<C<pack>|/pack TEMPLATE,LIST> for details.
1879021894
1879121895=end original
1879221896
1879321897BITS が 16 以上の場合、入力のバイト列は BITS/8 のサイズの固まりに
18794グループ化され、各グループは pack()/unpack() のビッグエンディアン
21898グループ化され、各グループは L<C<pack>|/pack TEMPLATE,LIST>/
21899L<C<unpack>|/unpack TEMPLATE,EXPR> のビッグエンディアン
1879521900フォーマット C<n>/C<N> を用いて(BITS==64 の類似として)数値に変換されます。
18796詳細は L<"pack"> を参照してください。
21901詳細は L<C<pack>|/pack TEMPLATE,LIST> を参照してください。
1879721902
1879821903=begin original
1879921904
1880021905If bits is 4 or less, the string is broken into bytes, then the bits
1880121906of each byte are broken into 8/BITS groups. Bits of a byte are
1880221907numbered in a little-endian-ish way, as in C<0x01>, C<0x02>,
1880321908C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80>. For example,
1880421909breaking the single input byte C<chr(0x36)> into two groups gives a list
1880521910C<(0x6, 0x3)>; breaking it into 4 groups gives C<(0x2, 0x1, 0x3, 0x0)>.
1880621911
1880721912=end original
1880821913
1880921914BITS が 4 以下の場合、文字列はバイトに分解され、バイトの各ビットは
18810219158/BITS 個のグループに分割されます。
1881121916ビットはリトルエンディアン風に、C<0x01>, C<0x02>,
1881221917C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80> の順になります。
1881321918例えば、入力バイト C<chr(0x36)> を二つのグループに分割すると、
1881421919C<(0x6, 0x3)> になります; 4 つに分割すると C<(0x2, 0x1, 0x3, 0x0)> に
1881521920なります。
1881621921
1881721922=begin original
1881821923
18819C<vec> may also be assigned to, in which case parentheses are needed
21924L<C<vec>|/vec EXPR,OFFSET,BITS> may also be assigned to, in which case
21925parentheses are needed
1882021926to give the expression the correct precedence as in
1882121927
1882221928=end original
1882321929
18824左辺値として、代入の対象にすることもできます; この場合、式を正しく
21930L<C<vec>|/vec EXPR,OFFSET,BITS> は左辺値として、代入の
21931対象にすることもできます; この場合、式を正しく
1882521932先行させるために以下のように括弧が必要です:
1882621933
1882721934 vec($image, $max_x * $x + $y, 8) = 3;
1882821935
1882921936=begin original
1883021937
1883121938If the selected element is outside the string, the value 0 is returned.
1883221939If an element off the end of the string is written to, Perl will first
1883321940extend the string with sufficiently many zero bytes. It is an error
1883421941to try to write off the beginning of the string (i.e., negative OFFSET).
1883521942
1883621943=end original
1883721944
1883821945選択された要素が文字列の外側だった場合、値 0 が返されます。
1883921946文字列の最後よりも後ろの要素に書き込もうとした場合、
1884021947Perl はまず文字列を必要な分だけ 0 のバイトで拡張します。
1884121948文字列の先頭より前に書き込もうとした(つまり OFFSET が負の数だった)
1884221949場合はエラーとなります。
1884321950
1884421951=begin original
1884521952
1884621953If the string happens to be encoded as UTF-8 internally (and thus has
18847the UTF8 flag set), this is ignored by C<vec>, and it operates on the
21954the UTF8 flag set), L<C<vec>|/vec EXPR,OFFSET,BITS> tries to convert it
18848internal byte string, not the conceptual character string, even if you
21955to use a one-byte-per-character internal representation. However, if the
18849only have characters with values less than 256.
21956string contains characters with values of 256 or higher, a fatal error
21957will occur.
1885021958
1885121959=end original
1885221960
18853文字列がなぜか内部で UTF-8 でエンコードされている場合(したがって UTF8 フラグが
21961文字列がたまたま内部で UTF-8 でエンコードされている場合(したがって
18854セットされている場合)、これは C<vec> では無視され、たとえ値が 256 未満の
21962UTF8 フラグがセットされている場合)、
18855文字だけであったとしても、概念的な
21963L<C<vec>|/vec EXPR,OFFSET,BITS> はこれを単一バイト文字内部表現に
18856文字列ではなく内部バイト文字列で操作されます。
21964変換しようとします。
21965しかし、この文字列に値が 256 以上の文字が含まれている場合、
21966致命的エラーが発生します。
1885721967
1885821968=begin original
1885921969
18860Strings created with C<vec> can also be manipulated with the logical
21970Strings created with L<C<vec>|/vec EXPR,OFFSET,BITS> can also be
21971manipulated with the logical
1886121972operators C<|>, C<&>, C<^>, and C<~>. These operators will assume a bit
1886221973vector operation is desired when both operands are strings.
1886321974See L<perlop/"Bitwise String Operators">.
1886421975
1886521976=end original
1886621977
18867C<vec> で作られた文字列は、論理演算子 C<|>、C<&>、C<^> で
21978L<C<vec>|/vec EXPR,OFFSET,BITS> で作られた文字列は、論理演算子 C<|>、C<&>、
18868扱うこともできます。
21979C<^>, C<~> で扱うこともできます。
1886921980これらの演算子は、両方の被演算子に文字列を使うと、
1887021981ビットベクター演算を行ないます。
1887121982L<perlop/"Bitwise String Operators"> を参照してください。
1887221983
1887321984=begin original
1887421985
1887521986The following code will build up an ASCII string saying C<'PerlPerlPerl'>.
1887621987The comments show the string after each step. Note that this code works
1887721988in the same way on big-endian or little-endian machines.
1887821989
1887921990=end original
1888021991
1888121992次のコードは C<'PerlPerlPerl'> という ASCII 文字列を作成します。
1888221993コメントは各行の実行後の文字列を示します。
1888321994このコードはビッグエンディアンでもリトルエンディアンでも同じように
1888421995動作することに注意してください。
1888521996
1888621997 my $foo = '';
1888721998 vec($foo, 0, 32) = 0x5065726C; # 'Perl'
1888821999
1888922000 # $foo eq "Perl" eq "\x50\x65\x72\x6C", 32 bits
1889022001 print vec($foo, 0, 8); # prints 80 == 0x50 == ord('P')
1889122002
1889222003 vec($foo, 2, 16) = 0x5065; # 'PerlPe'
1889322004 vec($foo, 3, 16) = 0x726C; # 'PerlPerl'
1889422005 vec($foo, 8, 8) = 0x50; # 'PerlPerlP'
1889522006 vec($foo, 9, 8) = 0x65; # 'PerlPerlPe'
1889622007 vec($foo, 20, 4) = 2; # 'PerlPerlPe' . "\x02"
1889722008 vec($foo, 21, 4) = 7; # 'PerlPerlPer'
1889822009 # 'r' is "\x72"
1889922010 vec($foo, 45, 2) = 3; # 'PerlPerlPer' . "\x0c"
1890022011 vec($foo, 93, 1) = 1; # 'PerlPerlPer' . "\x2c"
1890122012 vec($foo, 94, 1) = 1; # 'PerlPerlPerl'
1890222013 # 'l' is "\x6c"
1890322014
1890422015=begin original
1890522016
1890622017To transform a bit vector into a string or list of 0's and 1's, use these:
1890722018
1890822019=end original
1890922020
1891022021ビットベクターを、0 と 1 の文字列や配列に変換するには、
1891122022以下のようにします。
1891222023
18913 $bits = unpack("b*", $vector);
22024 my $bits = unpack("b*", $vector);
18914 @bits = split(//, unpack("b*", $vector));
22025 my @bits = split(//, unpack("b*", $vector));
1891522026
1891622027=begin original
1891722028
1891822029If you know the exact length in bits, it can be used in place of the C<*>.
1891922030
1892022031=end original
1892122032
1892222033ビット長が分かっていれば、C<*> の代わりにその長さを使うことができます。
1892322034
1892422035=begin original
1892522036
1892622037Here is an example to illustrate how the bits actually fall in place:
1892722038
1892822039=end original
1892922040
1893022041これはビットが実際にどのような位置に入るかを図示する例です。
1893122042
1893222043 #!/usr/bin/perl -wl
1893322044
1893422045 print <<'EOT';
1893522046 0 1 2 3
1893622047 unpack("V",$_) 01234567890123456789012345678901
1893722048 ------------------------------------------------------------------
1893822049 EOT
1893922050
1894022051 for $w (0..3) {
1894122052 $width = 2**$w;
1894222053 for ($shift=0; $shift < $width; ++$shift) {
1894322054 for ($off=0; $off < 32/$width; ++$off) {
1894422055 $str = pack("B*", "0"x32);
1894522056 $bits = (1<<$shift);
1894622057 vec($str, $off, $width) = $bits;
1894722058 $res = unpack("b*",$str);
1894822059 $val = unpack("V", $str);
1894922060 write;
1895022061 }
1895122062 }
1895222063 }
1895322064
1895422065 format STDOUT =
1895522066 vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1895622067 $off, $width, $bits, $val, $res
1895722068 .
1895822069 __END__
1895922070
1896022071=begin original
1896122072
18962Regardless of the machine architecture on which it runs, the
22073Regardless of the machine architecture on which it runs, the
1896322074example above should print the following table:
1896422075
1896522076=end original
1896622077
1896722078実行するマシンのアーキテクチャに関わらず、
1896822079上記の例は以下の表を出力します。
1896922080
1897022081 0 1 2 3
1897122082 unpack("V",$_) 01234567890123456789012345678901
1897222083 ------------------------------------------------------------------
1897322084 vec($_, 0, 1) = 1 == 1 10000000000000000000000000000000
1897422085 vec($_, 1, 1) = 1 == 2 01000000000000000000000000000000
1897522086 vec($_, 2, 1) = 1 == 4 00100000000000000000000000000000
1897622087 vec($_, 3, 1) = 1 == 8 00010000000000000000000000000000
1897722088 vec($_, 4, 1) = 1 == 16 00001000000000000000000000000000
1897822089 vec($_, 5, 1) = 1 == 32 00000100000000000000000000000000
1897922090 vec($_, 6, 1) = 1 == 64 00000010000000000000000000000000
1898022091 vec($_, 7, 1) = 1 == 128 00000001000000000000000000000000
1898122092 vec($_, 8, 1) = 1 == 256 00000000100000000000000000000000
1898222093 vec($_, 9, 1) = 1 == 512 00000000010000000000000000000000
1898322094 vec($_,10, 1) = 1 == 1024 00000000001000000000000000000000
1898422095 vec($_,11, 1) = 1 == 2048 00000000000100000000000000000000
1898522096 vec($_,12, 1) = 1 == 4096 00000000000010000000000000000000
1898622097 vec($_,13, 1) = 1 == 8192 00000000000001000000000000000000
1898722098 vec($_,14, 1) = 1 == 16384 00000000000000100000000000000000
1898822099 vec($_,15, 1) = 1 == 32768 00000000000000010000000000000000
1898922100 vec($_,16, 1) = 1 == 65536 00000000000000001000000000000000
1899022101 vec($_,17, 1) = 1 == 131072 00000000000000000100000000000000
1899122102 vec($_,18, 1) = 1 == 262144 00000000000000000010000000000000
1899222103 vec($_,19, 1) = 1 == 524288 00000000000000000001000000000000
1899322104 vec($_,20, 1) = 1 == 1048576 00000000000000000000100000000000
1899422105 vec($_,21, 1) = 1 == 2097152 00000000000000000000010000000000
1899522106 vec($_,22, 1) = 1 == 4194304 00000000000000000000001000000000
1899622107 vec($_,23, 1) = 1 == 8388608 00000000000000000000000100000000
1899722108 vec($_,24, 1) = 1 == 16777216 00000000000000000000000010000000
1899822109 vec($_,25, 1) = 1 == 33554432 00000000000000000000000001000000
1899922110 vec($_,26, 1) = 1 == 67108864 00000000000000000000000000100000
1900022111 vec($_,27, 1) = 1 == 134217728 00000000000000000000000000010000
1900122112 vec($_,28, 1) = 1 == 268435456 00000000000000000000000000001000
1900222113 vec($_,29, 1) = 1 == 536870912 00000000000000000000000000000100
1900322114 vec($_,30, 1) = 1 == 1073741824 00000000000000000000000000000010
1900422115 vec($_,31, 1) = 1 == 2147483648 00000000000000000000000000000001
1900522116 vec($_, 0, 2) = 1 == 1 10000000000000000000000000000000
1900622117 vec($_, 1, 2) = 1 == 4 00100000000000000000000000000000
1900722118 vec($_, 2, 2) = 1 == 16 00001000000000000000000000000000
1900822119 vec($_, 3, 2) = 1 == 64 00000010000000000000000000000000
1900922120 vec($_, 4, 2) = 1 == 256 00000000100000000000000000000000
1901022121 vec($_, 5, 2) = 1 == 1024 00000000001000000000000000000000
1901122122 vec($_, 6, 2) = 1 == 4096 00000000000010000000000000000000
1901222123 vec($_, 7, 2) = 1 == 16384 00000000000000100000000000000000
1901322124 vec($_, 8, 2) = 1 == 65536 00000000000000001000000000000000
1901422125 vec($_, 9, 2) = 1 == 262144 00000000000000000010000000000000
1901522126 vec($_,10, 2) = 1 == 1048576 00000000000000000000100000000000
1901622127 vec($_,11, 2) = 1 == 4194304 00000000000000000000001000000000
1901722128 vec($_,12, 2) = 1 == 16777216 00000000000000000000000010000000
1901822129 vec($_,13, 2) = 1 == 67108864 00000000000000000000000000100000
1901922130 vec($_,14, 2) = 1 == 268435456 00000000000000000000000000001000
1902022131 vec($_,15, 2) = 1 == 1073741824 00000000000000000000000000000010
1902122132 vec($_, 0, 2) = 2 == 2 01000000000000000000000000000000
1902222133 vec($_, 1, 2) = 2 == 8 00010000000000000000000000000000
1902322134 vec($_, 2, 2) = 2 == 32 00000100000000000000000000000000
1902422135 vec($_, 3, 2) = 2 == 128 00000001000000000000000000000000
1902522136 vec($_, 4, 2) = 2 == 512 00000000010000000000000000000000
1902622137 vec($_, 5, 2) = 2 == 2048 00000000000100000000000000000000
1902722138 vec($_, 6, 2) = 2 == 8192 00000000000001000000000000000000
1902822139 vec($_, 7, 2) = 2 == 32768 00000000000000010000000000000000
1902922140 vec($_, 8, 2) = 2 == 131072 00000000000000000100000000000000
1903022141 vec($_, 9, 2) = 2 == 524288 00000000000000000001000000000000
1903122142 vec($_,10, 2) = 2 == 2097152 00000000000000000000010000000000
1903222143 vec($_,11, 2) = 2 == 8388608 00000000000000000000000100000000
1903322144 vec($_,12, 2) = 2 == 33554432 00000000000000000000000001000000
1903422145 vec($_,13, 2) = 2 == 134217728 00000000000000000000000000010000
1903522146 vec($_,14, 2) = 2 == 536870912 00000000000000000000000000000100
1903622147 vec($_,15, 2) = 2 == 2147483648 00000000000000000000000000000001
1903722148 vec($_, 0, 4) = 1 == 1 10000000000000000000000000000000
1903822149 vec($_, 1, 4) = 1 == 16 00001000000000000000000000000000
1903922150 vec($_, 2, 4) = 1 == 256 00000000100000000000000000000000
1904022151 vec($_, 3, 4) = 1 == 4096 00000000000010000000000000000000
1904122152 vec($_, 4, 4) = 1 == 65536 00000000000000001000000000000000
1904222153 vec($_, 5, 4) = 1 == 1048576 00000000000000000000100000000000
1904322154 vec($_, 6, 4) = 1 == 16777216 00000000000000000000000010000000
1904422155 vec($_, 7, 4) = 1 == 268435456 00000000000000000000000000001000
1904522156 vec($_, 0, 4) = 2 == 2 01000000000000000000000000000000
1904622157 vec($_, 1, 4) = 2 == 32 00000100000000000000000000000000
1904722158 vec($_, 2, 4) = 2 == 512 00000000010000000000000000000000
1904822159 vec($_, 3, 4) = 2 == 8192 00000000000001000000000000000000
1904922160 vec($_, 4, 4) = 2 == 131072 00000000000000000100000000000000
1905022161 vec($_, 5, 4) = 2 == 2097152 00000000000000000000010000000000
1905122162 vec($_, 6, 4) = 2 == 33554432 00000000000000000000000001000000
1905222163 vec($_, 7, 4) = 2 == 536870912 00000000000000000000000000000100
1905322164 vec($_, 0, 4) = 4 == 4 00100000000000000000000000000000
1905422165 vec($_, 1, 4) = 4 == 64 00000010000000000000000000000000
1905522166 vec($_, 2, 4) = 4 == 1024 00000000001000000000000000000000
1905622167 vec($_, 3, 4) = 4 == 16384 00000000000000100000000000000000
1905722168 vec($_, 4, 4) = 4 == 262144 00000000000000000010000000000000
1905822169 vec($_, 5, 4) = 4 == 4194304 00000000000000000000001000000000
1905922170 vec($_, 6, 4) = 4 == 67108864 00000000000000000000000000100000
1906022171 vec($_, 7, 4) = 4 == 1073741824 00000000000000000000000000000010
1906122172 vec($_, 0, 4) = 8 == 8 00010000000000000000000000000000
1906222173 vec($_, 1, 4) = 8 == 128 00000001000000000000000000000000
1906322174 vec($_, 2, 4) = 8 == 2048 00000000000100000000000000000000
1906422175 vec($_, 3, 4) = 8 == 32768 00000000000000010000000000000000
1906522176 vec($_, 4, 4) = 8 == 524288 00000000000000000001000000000000
1906622177 vec($_, 5, 4) = 8 == 8388608 00000000000000000000000100000000
1906722178 vec($_, 6, 4) = 8 == 134217728 00000000000000000000000000010000
1906822179 vec($_, 7, 4) = 8 == 2147483648 00000000000000000000000000000001
1906922180 vec($_, 0, 8) = 1 == 1 10000000000000000000000000000000
1907022181 vec($_, 1, 8) = 1 == 256 00000000100000000000000000000000
1907122182 vec($_, 2, 8) = 1 == 65536 00000000000000001000000000000000
1907222183 vec($_, 3, 8) = 1 == 16777216 00000000000000000000000010000000
1907322184 vec($_, 0, 8) = 2 == 2 01000000000000000000000000000000
1907422185 vec($_, 1, 8) = 2 == 512 00000000010000000000000000000000
1907522186 vec($_, 2, 8) = 2 == 131072 00000000000000000100000000000000
1907622187 vec($_, 3, 8) = 2 == 33554432 00000000000000000000000001000000
1907722188 vec($_, 0, 8) = 4 == 4 00100000000000000000000000000000
1907822189 vec($_, 1, 8) = 4 == 1024 00000000001000000000000000000000
1907922190 vec($_, 2, 8) = 4 == 262144 00000000000000000010000000000000
1908022191 vec($_, 3, 8) = 4 == 67108864 00000000000000000000000000100000
1908122192 vec($_, 0, 8) = 8 == 8 00010000000000000000000000000000
1908222193 vec($_, 1, 8) = 8 == 2048 00000000000100000000000000000000
1908322194 vec($_, 2, 8) = 8 == 524288 00000000000000000001000000000000
1908422195 vec($_, 3, 8) = 8 == 134217728 00000000000000000000000000010000
1908522196 vec($_, 0, 8) = 16 == 16 00001000000000000000000000000000
1908622197 vec($_, 1, 8) = 16 == 4096 00000000000010000000000000000000
1908722198 vec($_, 2, 8) = 16 == 1048576 00000000000000000000100000000000
1908822199 vec($_, 3, 8) = 16 == 268435456 00000000000000000000000000001000
1908922200 vec($_, 0, 8) = 32 == 32 00000100000000000000000000000000
1909022201 vec($_, 1, 8) = 32 == 8192 00000000000001000000000000000000
1909122202 vec($_, 2, 8) = 32 == 2097152 00000000000000000000010000000000
1909222203 vec($_, 3, 8) = 32 == 536870912 00000000000000000000000000000100
1909322204 vec($_, 0, 8) = 64 == 64 00000010000000000000000000000000
1909422205 vec($_, 1, 8) = 64 == 16384 00000000000000100000000000000000
1909522206 vec($_, 2, 8) = 64 == 4194304 00000000000000000000001000000000
1909622207 vec($_, 3, 8) = 64 == 1073741824 00000000000000000000000000000010
1909722208 vec($_, 0, 8) = 128 == 128 00000001000000000000000000000000
1909822209 vec($_, 1, 8) = 128 == 32768 00000000000000010000000000000000
1909922210 vec($_, 2, 8) = 128 == 8388608 00000000000000000000000100000000
1910022211 vec($_, 3, 8) = 128 == 2147483648 00000000000000000000000000000001
1910122212
1910222213=item wait
1910322214X<wait>
1910422215
1910522216=for Pod::Functions wait for any child process to die
1910622217
1910722218=begin original
1910822219
19109Behaves like wait(2) on your system: it waits for a child
22220Behaves like L<wait(2)> on your system: it waits for a child
1911022221process to terminate and returns the pid of the deceased process, or
19111C<-1> if there are no child processes. The status is returned in C<$?>
22222C<-1> if there are no child processes. The status is returned in
19112and C<${^CHILD_ERROR_NATIVE}>.
22223L<C<$?>|perlvar/$?> and
22224L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>.
1911322225Note that a return value of C<-1> could mean that child processes are
1911422226being automatically reaped, as described in L<perlipc>.
1911522227
1911622228=end original
1911722229
19118wait(2) と同様に振る舞います: チャイルドプロセスが終了するのを待ち、消滅した
22230L<wait(2)> と同様に振る舞います: チャイルドプロセスが終了するのを待ち、
19119プロセスの pid を返します; チャイルドプロセスが存在しないときには、C<-1> を
22231消滅したプロセスの pid を返します; チャイルドプロセスが存在しないときには、
19120返します。
22232C<-1> を返します。
19121ステータスは C<$?> と C<${^CHILD_ERROR_NATIVE}> に返されます。
22233ステータスは L<C<$?>|perlvar/$?>
22234L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に返されます。
1912222235L<perlipc> に書いているように、返り値が C<-1> の場合は子プロセスが
1912322236自動的に刈り取られたことを意味するかもしれないことに注意してください。
1912422237
1912522238=begin original
1912622239
19127If you use wait in your handler for $SIG{CHLD} it may accidentally for the
22240If you use L<C<wait>|/wait> in your handler for
19128child created by qx() or system(). See L<perlipc> for details.
22241L<C<$SIG{CHLD}>|perlvar/%SIG>, it may accidentally wait for the child
22242created by L<C<qx>|/qxE<sol>STRINGE<sol>> or L<C<system>|/system LIST>.
22243See L<perlipc> for details.
1912922244
1913022245=end original
1913122246
19132wait を $SIG{CHLD} のハンドラで使うと、誤って qx() や system() に
22247L<C<wait>|/wait>L<C<$SIG{CHLD}>|perlvar/%SIG> のハンドラで使うと、誤って
19133適用されるかも知れません。
22248L<C<qx>|/qxE<sol>STRINGE<sol>> や L<C<system>|/system LIST> によって
22249作られた子を待つことになるかも知れません。
1913422250詳しくは L<perlipc> を参照してください。
1913522251
1913622252=begin original
1913722253
1913822254Portability issues: L<perlport/wait>.
1913922255
1914022256=end original
1914122257
1914222258移植性の問題: L<perlport/wait>。
1914322259
1914422260=item waitpid PID,FLAGS
1914522261X<waitpid>
1914622262
1914722263=for Pod::Functions wait for a particular child process to die
1914822264
1914922265=begin original
1915022266
1915122267Waits for a particular child process to terminate and returns the pid of
19152the deceased process, or C<-1> if there is no such child process. On some
22268the deceased process, or C<-1> if there is no such child process. A
19153systems, a value of 0 indicates that there are processes still running.
22269non-blocking wait (with L<WNOHANG|POSIX/C<WNOHANG>> in FLAGS) can return 0 if
19154The status is returned in C<$?> and C<${^CHILD_ERROR_NATIVE}>. If you say
22270there are child processes matching PID but none have terminated yet.
22271The status is returned in L<C<$?>|perlvar/$?> and
22272L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>.
1915522273
1915622274=end original
1915722275
19158特定のチャイルドプロセスが終了するのを待ち、消滅したプロセスの pid を
22276特定のプロセスが終了するのを待ち、消滅したプロセスの pid を
19159返します; 指定したチャイルドプロセスが存在しないときには、C<-1> を返します。
22277返します; 指定したプロセスが存在しないときには、C<-1> を返します。
19160 0 がプロセスがまだ実行中であること示すシステムもあります。
22278(FLAGS L<WNOHANG|POSIX/C<WNOHANG>> 指定した) 非ブロッキング wait は、
19161ステータスは C<$?> と C<${^CHILD_ERROR_NATIVE}> に返されま
22279PID がマッチングる子プロセスがいてもまだ終了していない場合に 0 を
19162以下のように
22280があります。
22281ステータスは L<C<$?>|perlvar/$?> と
22282L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に返されます。
1916322283
22284=begin original
22285
22286A PID of C<0> indicates to wait for any child process whose process group ID is
22287equal to that of the current process. A PID of less than C<-1> indicates to
22288wait for any child process whose process group ID is equal to -PID. A PID of
22289C<-1> indicates to wait for any child process.
22290
22291=end original
22292
22293PID に C<0> を指定すると、プロセスグループ ID が現在のプロセスと同じである
22294任意の子プロセスを wait します。
22295PID に C<-1> 以下を指定すると、プロセスグループ ID が -PID に等しい
22296任意の子プロセスを wait します。
22297PID に C<-1> を指定すると任意の子プロセスを wait します。
22298
22299=begin original
22300
22301If you say
22302
22303=end original
22304
22305以下のようにするか
22306
1916422307 use POSIX ":sys_wait_h";
19165 #...
22309 my $kid;
1916622310 do {
1916722311 $kid = waitpid(-1, WNOHANG);
1916822312 } while $kid > 0;
1916922313
1917022314=begin original
1917122315
19172then you can do a non-blocking wait for all pending zombie processes.
22316or
22317
22318=end original
22319
22320または
22321
22322 1 while waitpid(-1, WNOHANG) > 0;
22323
22324=begin original
22325
22326then you can do a non-blocking wait for all pending zombie processes (see
22327L<POSIX/WAIT>).
1917322328Non-blocking wait is available on machines supporting either the
19174waitpid(2) or wait4(2) syscalls. However, waiting for a particular
22329L<waitpid(2)> or L<wait4(2)> syscalls. However, waiting for a particular
1917522330pid with FLAGS of C<0> is implemented everywhere. (Perl emulates the
1917622331system call by remembering the status values of processes that have
1917722332exited but have not been harvested by the Perl script yet.)
1917822333
1917922334=end original
1918022335
19181ブロックが起こらないようにして、全ての待機中ゾンビプロセスを wait します。
22336とすると、ブロックが起こらないようにして、全ての待機中ゾンビプロセスを
19182ブロックなしの wait は、システムコール wait_pid(2) か、
22337wait します (L<POSIX/WAIT> を参照してください)。
19183システムコール wait4(2) をサポートしているマシンで利用可能です。
22338ブロックなしの wait は、システムコール L<wait_pid(2)> か、
22339システムコール L<wait4(2)> をサポートしているマシンで利用可能です。
1918422340しかしながら、特定の pid を C<0> の FLAGS での wait はどこでも
1918522341実装されています。
1918622342(exit したプロセスのステータス値を覚えておいて、Perl がシステムコールを
1918722343エミュレートしますが、Perl スクリプトには取り入れられていません。)
1918822344
1918922345=begin original
1919022346
1919122347Note that on some systems, a return value of C<-1> could mean that child
1919222348processes are being automatically reaped. See L<perlipc> for details,
1919322349and for other examples.
1919422350
1919522351=end original
1919622352
1919722353システムによっては、返り値が C<-1> の場合は子プロセスが自動的に
1919822354刈り取られたことを意味するかもしれないことに注意してください。
1919922355詳細やその他の例については L<perlipc> を参照してください。
1920022356
1920122357=begin original
1920222358
1920322359Portability issues: L<perlport/waitpid>.
1920422360
1920522361=end original
1920622362
1920722363移植性の問題: L<perlport/waitpid>。
1920822364
1920922365=item wantarray
1921022366X<wantarray> X<context>
1921122367
1921222368=for Pod::Functions get void vs scalar vs list context of current subroutine call
1921322369
1921422370=begin original
1921522371
1921622372Returns true if the context of the currently executing subroutine or
19217C<eval> is looking for a list value. Returns false if the context is
22373L<C<eval>|/eval EXPR> is looking for a list value. Returns false if the
22374context is
1921822375looking for a scalar. Returns the undefined value if the context is
1921922376looking for no value (void context).
1922022377
1922122378=end original
1922222379
19223現在実行中のサブルーチンか eval() ブロックのコンテキストが、リスト値を
22380現在実行中のサブルーチンか L<C<eval>|/eval EXPR> ブロックのコンテキストが、
19224要求するものであれば、真を返します。
22381リスト値を要求するものであれば、真を返します。
1922522382スカラを要求するコンテキストであれば、偽を返します。
1922622383何も値を要求しない(無効コンテキスト)場合は未定義値を返します。
1922722384
1922822385 return unless defined wantarray; # don't bother doing more
1922922386 my @a = complex_calculation();
1923022387 return wantarray ? @a : "@a";
1923122388
1923222389=begin original
1923322390
19234C<wantarray()>'s result is unspecified in the top level of a file,
22391L<C<wantarray>|/wantarray>'s result is unspecified in the top level of a file,
1923522392in a C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT> or C<END> block, or
1923622393in a C<DESTROY> method.
1923722394
1923822395=end original
1923922396
1924022397ファイルのトップレベル、C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT>, C<END>
19241ブロック内、C<DESTROY> メソッド内では C<wantarray()> の結果は未定義です。
22398ブロック内、C<DESTROY> メソッド内では L<C<wantarray>|/wantarray> の結果は
22399未定義です。
1924222400
1924322401=begin original
1924422402
1924522403This function should have been named wantlist() instead.
1924622404
1924722405=end original
1924822406
1924922407この関数は wantlist() という名前にするべきでした。
1925022408
1925122409=item warn LIST
1925222410X<warn> X<warning> X<STDERR>
1925322411
1925422412=for Pod::Functions print debugging info
1925522413
1925622414=begin original
1925722415
19258Prints the value of LIST to STDERR. If the last element of LIST does
22416Emits a warning, usually by printing it to C<STDERR>. C<warn> interprets
19259not end in a newline, it appends the same file/line number text as C<die>
22417its operand LIST in the same way as C<die>, but is slightly different
19260does.
22418in what it defaults to when LIST is empty or makes an empty string.
22419If it is empty and L<C<$@>|perlvar/$@> already contains an exception
22420value then that value is used after appending C<"\t...caught">. If it
22421is empty and C<$@> is also empty then the string C<"Warning: Something's
22422wrong"> is used.
1926122423
1926222424=end original
1926322425
19264LIST の値を STDERR に出力します。
22426(通常は C<STDERR>表示することで) 警告を出力します。
19265LIST の最後の要素が改行で終わっていない場合、C<die> が行うのと同様
22427C<warn> はそのオペランド LIST C<die> と同様に解釈しますが、
19266ァイ/行番号のテキストが追加されます。
22428LIST が空や空文字列を作る時に何をデルトとするか少し異なります。
22429それが空かつ、L<C<$@>|perlvar/$@> に既に
22430例外値が入っている場合、C<"\t...caught"> を追加した値が
22431用いられます。
22432もしこれが空で C<$@> も空の場合は、C<"Warning: Something's wrong"> という
22433文字列が使われます。
1926722434
1926822435=begin original
1926922436
19270If the output is empty and C<$@> already contains a value (typically from a
22437By default, the exception derived from the operand LIST is stringified
19271previous eval) that value is used after appending C<"\t...caught">
22438and printed to C<STDERR>. This behaviour can be altered by installing
19272to C<$@>. This is useful for staying almost, but not entirely similar to
22439a L<C<$SIG{__WARN__}>|perlvar/%SIG> handler. If there is such a
19273C<die>.
22440handler then no message is automatically printed; it is the handler's
22441responsibility to deal with the exception
19275=end original
22442as it sees fit (like, for instance, converting it into a
22443L<C<die>|/die LIST>). Most
19277出力が空かつ、(典型的には以前の eval によって) C<$@> に既に値が入っている
19278場合、C<$@> に C<"\t...caught"> を追加した値が用いられます。
19279これはほとんどそのままにするときに便利ですが、
19280C<die> と全体的に似ているわけではありません。
19281
19282=begin original
19283
19284If C<$@> is empty then the string C<"Warning: Something's wrong"> is used.
19285
19286=end original
19287
19288C<$@> が空の場合は、C<"Warning: Something's wrong"> という文字列が
19289使われます。
19290
19291=begin original
19292
19293No message is printed if there is a C<$SIG{__WARN__}> handler
19294installed. It is the handler's responsibility to deal with the message
19295as it sees fit (like, for instance, converting it into a C<die>). Most
1929622444handlers must therefore arrange to actually display the
19297warnings that they are not prepared to deal with, by calling C<warn>
22445warnings that they are not prepared to deal with, by calling
22446L<C<warn>|/warn LIST>
1929822447again in the handler. Note that this is quite safe and will not
1929922448produce an endless loop, since C<__WARN__> hooks are not called from
1930022449inside one.
1930122450
1930222451=end original
1930322452
19304C<$SIG{__WARN__}> ンドラが設定されている場合何のメッセージも
22453デフォルトでは、LIST オペランドから生成された例外
19305表示されません
22454文字列化されて C<STDERR> に表示されま
19306メッセージをどう扱うか(例えば C<die> に変換するか)はハンドラ
22455この振る舞いは、L<C<$SIG{__WARN__}>|perlvar/%SIG> ハンドラを設定することで
22456置き換えられます。
22457このようなハンドラが設定されている場合は何の
22458メッセージも自動的には表示されません;
22459例外をどう扱うか(例えば L<C<die>|/die LIST> に変換するか)はハンドラの
1930722460責任ということです。
1930822461従ってほとんどのハンドラは、扱おうと準備していない警告を表示するために、
19309ハンドラの中で C<warn> を再び呼び出します。
22462ハンドラの中で L<C<warn>|/warn LIST> を再び呼び出します。
1931022463C<__WARN__> フックはハンドラ内では呼び出されないので、これは十分安全で、
1931122464無限ループを引き起こすことはないということに注意してください。
1931222465
1931322466=begin original
1931422467
1931522468You will find this behavior is slightly different from that of
19316C<$SIG{__DIE__}> handlers (which don't suppress the error text, but can
22469L<C<$SIG{__DIE__}>|perlvar/%SIG> handlers (which don't suppress the
19317instead call C<die> again to change it).
22470error text, but can instead call L<C<die>|/die LIST> again to change
22471it).
1931822472
1931922473=end original
1932022474
19321この振る舞いは C<$SIG{__DIE__}> ハンドラ(エラーテキストは削除しませんが、
22475この振る舞いは L<C<$SIG{__DIE__}>|perlvar/%SIG> ハンドラ(エラーテキストは
19322代わりに C<die> をもう一度呼び出すことで変更できます)とは
22476削除しませんが、代わりに L<C<die>|/die LIST> をもう一度呼び出すことで
19323少し違うことに気付くことでしょう。
22477変更できます)とは少し違うことに気付くことでしょう。
1932422478
1932522479=begin original
1932622480
1932722481Using a C<__WARN__> handler provides a powerful way to silence all
1932822482warnings (even the so-called mandatory ones). An example:
1932922483
1933022484=end original
1933122485
1933222486C<__WARN__> ハンドラを使うと、(いわゆる必須のものを含む)全ての
1933322487警告を黙らせる強力な手段となります。
1933422488例:
1933522489
1933622490 # wipe out *all* compile-time warnings
1933722491 BEGIN { $SIG{'__WARN__'} = sub { warn $_[0] if $DOWARN } }
1933822492 my $foo = 10;
1933922493 my $foo = 20; # no warning about duplicate my $foo,
1934022494 # but hey, you asked for it!
1934122495 # no compile-time or run-time warnings before here
1934222496 $DOWARN = 1;
1934322497
1934422498 # run-time warnings enabled after here
1934522499 warn "\$foo is alive and $foo!"; # does show up
1934622500
1934722501=begin original
1934822502
19349See L<perlvar> for details on setting C<%SIG> entries and for more
22503See L<perlvar> for details on setting L<C<%SIG>|perlvar/%SIG> entries
19350examples. See the Carp module for other kinds of warnings using its
22504and for more
19351carp() and cluck() functions.
22505examples. See the L<Carp> module for other kinds of warnings using its
22506C<carp> and C<cluck> functions.
1935222507
1935322508=end original
1935422509
19355C<%SIG> エントリのセットに関する詳細とさらなる例に関しては
22510L<C<%SIG>|perlvar/%SIG> エントリのセットに関する詳細とさらなる例に関しては
1935622511L<perlvar> を参照してください。
19357carp() 関数と cluck() 関数を用いた警告の方法に関しては
22512C<carp> 関数と C<cluck> 関数を用いた警告の方法に関しては
19358Carp モジュールを参照してください。
22513L<Carp> モジュールを参照してください。
1935922514
1936022515=item write FILEHANDLE
1936122516X<write>
1936222517
1936322518=item write EXPR
1936422519
1936522520=item write
1936622521
1936722522=for Pod::Functions print a picture record
1936822523
1936922524=begin original
1937022525
1937122526Writes a formatted record (possibly multi-line) to the specified FILEHANDLE,
1937222527using the format associated with that file. By default the format for
1937322528a file is the one having the same name as the filehandle, but the
19374format for the current output channel (see the C<select> function) may be set
22529format for the current output channel (see the
19375explicitly by assigning the name of the format to the C<$~> variable.
22530L<C<select>|/select FILEHANDLE> function) may be set explicitly by
22531assigning the name of the format to the L<C<$~>|perlvar/$~> variable.
1937622532
1937722533=end original
1937822534
1937922535指定された FILEHANDLE に対して、そのファイルに対応させた
1938022536フォーマットを使って、(複数行の場合もある) 整形された
1938122537レコードを書き出します。
1938222538デフォルトでは、ファイルに対応するフォーマットは、ファイルハンドルと
19383同じ名前のものですが、その時点の出力チャネル (C<select> 関数の項を
22539同じ名前のものですが、その時点の出力チャネル
19384参照してください) のフォーマットは、その名前を明示的に変数 C<$~>
22540(L<C<select>|/select FILEHANDLE> 関数の項を
19385代入することで、変更が可能です。
22541参照してください) のフォーマットはその名前を明示的に
22542L<C<$~>|perlvar/$~> に代入することで、変更が可能です。
1938622543
1938722544=begin original
1938822545
1938922546Top of form processing is handled automatically: if there is insufficient
1939022547room on the current page for the formatted record, the page is advanced by
19391writing a form feed, a special top-of-page format is used to format the new
22548writing a form feed and a special top-of-page
22549format is used to format the new
1939222550page header before the record is written. By default, the top-of-page
19393format is the name of the filehandle with "_TOP" appended. This would be a
22551format is the name of the filehandle with C<_TOP> appended, or C<top>
22552in the current package if the former does not exist. This would be a
1939422553problem with autovivified filehandles, but it may be dynamically set to the
19395format of your choice by assigning the name to the C<$^> variable while
22554format of your choice by assigning the name to the L<C<$^>|perlvar/$^>
19396that filehandle is selected. The number of lines remaining on the current
22555variable while that filehandle is selected. The number of lines
19397page is in variable C<$->, which can be set to C<0> to force a new page.
22556remaining on the current page is in variable L<C<$->|perlvar/$->, which
22557can be set to C<0> to force a new page.
1939822558
1939922559=end original
1940022560
1940122561ページの先頭の処理は、自動的に行なわれます: 現在のページに整形された
1940222562レコードを出力するだけのスペースがない場合には、改ページを行なってページを
1940322563進め、新しいページヘッダを整形するため、ページ先頭フォーマットが使われ、
1940422564その後でレコードが書かれます。
1940522565デフォルトでは、ページ先頭フォーマットは、ファイルハンドルの名前に
19406"_TOP" をつなげたものです。
22566C<_TOP> をつなげたものか、前者が存在しないなら、現在のパッケージの
22567C<top> です。
1940722568これは自動有効化されたファイルハンドルで問題になる可能性がありますが、
1940822569ファイルハンドルが選択されている間に、
19409変数 C<$^> に名前を設定すれば、動的にフォーマットを
22570変数 L<C<$^>|perlvar/$^> に名前を設定すれば、動的にフォーマットを
1941022571変更することができます。
19411そのページの残り行数は、変数 C<$-> に入っており、この変数を 0 に
22572そのページの残り行数は、変数 L<C<$->|perlvar/$-> に入っており、この変数を
19412設定することで、強制的に改ページを行なうことができます。
22573C<0> に設定することで、強制的に改ページを行なうことができます。
1941322574
1941422575=begin original
1941522576
1941622577If FILEHANDLE is unspecified, output goes to the current default output
1941722578channel, which starts out as STDOUT but may be changed by the
19418C<select> operator. If the FILEHANDLE is an EXPR, then the expression
22579L<C<select>|/select FILEHANDLE> operator. If the FILEHANDLE is an EXPR,
22580then the expression
1941922581is evaluated and the resulting string is used to look up the name of
1942022582the FILEHANDLE at run time. For more on formats, see L<perlform>.
1942122583
1942222584=end original
1942322585
1942422586FILEHANDLE を指定しないと、出力はその時点のデフォルト出力チャネルに対して
1942522587行なわれます; これは、スクリプトの開始時点では STDOUT ですが、
19426select() 演算子で変更することができます。
22588L<C<select>|/select FILEHANDLE> 演算子で変更することができます。
1942722589FILEHANDLE が EXPR ならば、式が評価され、その結果の文字列が
1942822590実行時に FILEHANDLE の名前として見られます。
1942922591フォーマットについて、さらには、L<perlform> を参照してください。
1943022592
1943122593=begin original
1943222594
19433Note that write is I<not> the opposite of C<read>. Unfortunately.
22595Note that write is I<not> the opposite of
22596L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>. Unfortunately.
1943422597
1943522598=end original
1943622599
19437write は C<read> の反対のことをするもの I<ではありません>
22600write は L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>
22601反対のことをするもの I<ではありません>。
1943822602残念ながら。
1943922603
1944022604=item y///
1944122605
1944222606=for Pod::Functions transliterate a string
1944322607
1944422608=begin original
1944522609
19446The transliteration operator. Same as C<tr///>. See
22610The transliteration operator. Same as
19447L<perlop/"Quote and Quote-like Operators">.
22611L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>>. See
22612L<perlop/"Quote-Like Operators">.
1944822613
1944922614=end original
1945022615
1945122616文字変換演算子です。
19452C<tr///> と同じです。
22617L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>> と同じです。
19453L<perlop/"Quote and Quote-like Operators"> を参照してください。
22618L<perlop/"Quote-Like Operators"> を参照してください。
1945422619
1945522620=back
1945622621
1945722622=head2 Non-function Keywords by Cross-reference
1945822623
1945922624=head3 perldata
1946022625
1946122626=over
1946222627
1946322628=item __DATA__
1946422629
1946522630=item __END__
1946622631
1946722632=begin original
1946822633
1946922634These keywords are documented in L<perldata/"Special Literals">.
1947022635
1947122636=end original
1947222637
1947322638これらのキーワードは L<perldata/"Special Literals"> で文書化されています。
1947422639
1947522640=back
1947622641
1947722642=head3 perlmod
1947822643
1947922644=over
1948022645
1948122646=item BEGIN
1948222647
1948322648=item CHECK
1948422649
1948522650=item END
1948622651
1948722652=item INIT
1948822653
1948922654=item UNITCHECK
1949022655
1949122656=begin original
1949222657
1949322658These compile phase keywords are documented in L<perlmod/"BEGIN, UNITCHECK, CHECK, INIT and END">.
1949422659
1949522660=end original
1949622661
1949722662これらのコンパイルフェーズキーワードは
1949822663L<perlmod/"BEGIN, UNITCHECK, CHECK, INIT and END"> で文書化されています。
1949922664
1950022665=back
1950122666
1950222667=head3 perlobj
1950322668
1950422669=over
1950522670
1950622671=item DESTROY
1950722672
1950822673=begin original
1950922674
1951022675This method keyword is documented in L<perlobj/"Destructors">.
1951122676
1951222677=end original
1951322678
1951422679このメソッドキーワードは L<perlobj/"Destructors"> で文書化されています。
1951522680
1951622681=back
1951722682
1951822683=head3 perlop
1951922684
1952022685=over
1952122686
1952222687=item and
1952322688
1952422689=item cmp
1952522690
1952622691=item eq
1952722692
1952822693=item ge
1952922694
1953022695=item gt
1953122696
19532=item if
22697=item isa
1953322698
1953422699=item le
1953522700
1953622701=item lt
1953722702
1953822703=item ne
1953922704
1954022705=item not
1954122706
1954222707=item or
1954322708
1954422709=item x
1954522710
1954622711=item xor
1954722712
1954822713=begin original
1954922714
1955022715These operators are documented in L<perlop>.
1955122716
1955222717=end original
1955322718
1955422719これらの演算子は L<perlop> で文書化されています。
1955522720
1955622721=back
1955722722
1955822723=head3 perlsub
1955922724
1956022725=over
1956122726
1956222727=item AUTOLOAD
1956322728
1956422729=begin original
1956522730
1956622731This keyword is documented in L<perlsub/"Autoloading">.
1956722732
1956822733=end original
1956922734
1957022735このキーワードは L<perlsub/"Autoloading"> で文書化されています。
1957122736
1957222737=back
1957322738
1957422739=head3 perlsyn
1957522740
1957622741=over
1957722742
1957822743=item else
1957922744
19580=item elseif
19581
1958222745=item elsif
1958322746
1958422747=item for
1958522748
1958622749=item foreach
1958722750
22751=item if
22752
1958822753=item unless
1958922754
1959022755=item until
1959122756
1959222757=item while
1959322758
1959422759=begin original
1959522760
1959622761These flow-control keywords are documented in L<perlsyn/"Compound Statements">.
1959722762
1959822763=end original
1959922764
1960022765これらのフロー制御キーワードは L<perlsyn/"Compound Statements"> で
1960122766文書化されています。
1960222767
22768=item elseif
22769
22770=begin original
22771
22772The "else if" keyword is spelled C<elsif> in Perl. There's no C<elif>
22773or C<else if> either. It does parse C<elseif>, but only to warn you
22774about not using it.
22775
22776=end original
22777
22778"else if" キーワードは Perl では C<elsif> と綴ります。
22779C<elif> や C<else if> はありません。
22780C<elseif> はパースされますが、使わないように警告するためだけです。
22781
22782=begin original
22783
22784See the documentation for flow-control keywords in L<perlsyn/"Compound
22785Statements">.
22786
22787=end original
22788
22789L<perlsyn/"Compound Statements"> のフロー制御キーワードに関する文章を
22790参照してください。
22791
1960322792=back
1960422793
1960522794=over
1960622795
1960722796=item default
1960822797
1960922798=item given
1961022799
1961122800=item when
1961222801
1961322802=begin original
1961422803
1961522804These flow-control keywords related to the experimental switch feature are
19616documented in L<perlsyn/"Switch Statements"> .
22805documented in L<perlsyn/"Switch Statements">.
1961722806
1961822807=end original
1961922808
1962022809これらの実験的な switch 機能に関連するフロー制御キーワードは
1962122810L<perlsyn/"Switch Statements"> で文書化されています。
1962222811
1962322812=back
1962422813
22814=over
22815
22816=item try
22817
22818=item catch
22819
22820=item finally
22821
22822=begin original
22823
22824These flow-control keywords related to the experimental C<try> feature are
22825documented in L<perlsyn/"Try Catch Exception Handling">.
22826
22827=end original
22828
22829実験的な C<try> 機能に関係するこれらのフロー制御キーワードは
22830L<perlsyn/"Try Catch Exception Handling"> に文書化されています。
22831
22832=back
22833
22834=over
22835
22836=item defer
22837
22838=begin original
22839
22840This flow-control keyword related to the experimental C<defer> feature is
22841documented in L<perlsyn/"defer blocks">.
22842
22843=end original
22844
22845実験的な C<defer> 機能に関係するこれらのフロー制御キーワードは
22846L<perlsyn/"defer blocks"> に文書化されています。
22847
22848=back
22849
22850=over
22851
22852=item ADJUST
22853
22854=begin original
22855
22856This class-related phaser block is documented in L<perlclass>.
22857
22858=end original
22859
22860This class-related phaser block is documented in L<perlclass>.
22861(TBT)
22862
22863=back
22864
22865=cut
22866
1962522867=begin meta
1962622868
1962722869Translate: 吉村 寿人 <JAE00534@niftyserve.or.jp>
1962822870Update: SHIRAKATA Kentaro <argrath@ub32.org> (5.6.1-)
1962922871Status: in progress
1963022872
1963122873=end meta
19632
19633=cut