perlfunc >
5.26.1
との差分
perlfunc 5.26.1 と 5.32.0 の差分
1 | 1 | |
2 | 2 | =encoding euc-jp |
3 | 3 | |
4 | 4 | =head1 NAME |
5 | 5 | X<function> |
6 | 6 | |
7 | 7 | =begin original |
8 | 8 | |
9 | 9 | perlfunc - Perl builtin functions |
10 | 10 | |
11 | 11 | =end original |
12 | 12 | |
13 | 13 | perlfunc - Perl 組み込み関数 |
14 | 14 | |
15 | 15 | =head1 DESCRIPTION |
16 | 16 | |
17 | 17 | =begin original |
18 | 18 | |
19 | 19 | The functions in this section can serve as terms in an expression. |
20 | 20 | They fall into two major categories: list operators and named unary |
21 | 21 | operators. These differ in their precedence relationship with a |
22 | 22 | following comma. (See the precedence table in L<perlop>.) List |
23 | 23 | operators take more than one argument, while unary operators can never |
24 | 24 | take more than one argument. Thus, a comma terminates the argument of |
25 | 25 | a unary operator, but merely separates the arguments of a list |
26 | 26 | operator. A unary operator generally provides scalar context to its |
27 | 27 | argument, while a list operator may provide either scalar or list |
28 | 28 | contexts for its arguments. If it does both, scalar arguments |
29 | 29 | come first and list argument follow, and there can only ever |
30 | 30 | be one such list argument. For instance, |
31 | 31 | L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> has three scalar arguments |
32 | 32 | followed by a list, whereas L<C<gethostbyname>|/gethostbyname NAME> has |
33 | 33 | four scalar arguments. |
34 | 34 | |
35 | 35 | =end original |
36 | 36 | |
37 | 37 | この節の関数は、式の中で項として使うことができます。 |
38 | 38 | これらは、大きく二つに分けられます: |
39 | 39 | リスト演算子と名前付き単項演算子です。 |
40 | 40 | これらの違いは、その後に出て来るコンマとの優先順位の関係にあります。 |
41 | 41 | (L<perlop> の優先順位の表を参照してください。) |
42 | 42 | リスト演算子は 2 個以上の引数をとるのに対して、単項演算子が複数の引数を |
43 | 43 | とることはありません。 |
44 | 44 | つまり、コンマは単項演算子の引数の終わりとなりますが、リスト演算子の |
45 | 45 | 場合には、引数の区切りでしかありません。 |
46 | 46 | 単項演算子は一般に、引数に対してスカラコンテキストを与えるのに対して、 |
47 | 47 | スカラ演算子の場合には、引数に対してスカラコンテキストを与える場合も、 |
48 | 48 | リストコンテキストを与える場合もあります。 |
49 | 49 | 一つのリスト演算子が両方のコンテキストを与える場合には、スカラ引数が |
50 | 50 | いくつか並び、最後にリスト引数が一つ続きます; |
51 | 51 | そしてそのようなリスト引数は一つだけしかありません。 |
52 | 52 | たとえば、L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> は三つのスカラ引数に |
53 | 53 | 一つのリスト引数が続きます; |
54 | 54 | 一方 L<C<gethostbyname>|/gethostbyname NAME> は四つのスカラ引数を持ちます。 |
55 | 55 | |
56 | 56 | =begin original |
57 | 57 | |
58 | 58 | In the syntax descriptions that follow, list operators that expect a |
59 | 59 | list (and provide list context for elements of the list) are shown |
60 | 60 | with LIST as an argument. Such a list may consist of any combination |
61 | 61 | of scalar arguments or list values; the list values will be included |
62 | 62 | in the list as if each individual element were interpolated at that |
63 | 63 | point in the list, forming a longer single-dimensional list value. |
64 | 64 | Commas should separate literal elements of the LIST. |
65 | 65 | |
66 | 66 | =end original |
67 | 67 | |
68 | 68 | 後に載せる構文記述では、リストをとり (そのリストの要素にリストコンテキストを |
69 | 69 | 与える)リスト演算子は、引数として LIST をとるように書いています; |
70 | 70 | そのようなリストには、任意のスカラ引数の組み合わせやリスト値を |
71 | 71 | 含めることができ、リスト値はリストの中に、個々の要素が展開されたように |
72 | 72 | 埋め込まれます。 |
73 | 73 | 1 次元の長いリスト値が形成されることになります。 |
74 | 74 | LIST のリテラルな要素は、コンマで区切られます。 |
75 | 75 | |
76 | 76 | =begin original |
77 | 77 | |
78 | 78 | Any function in the list below may be used either with or without |
79 | 79 | parentheses around its arguments. (The syntax descriptions omit the |
80 | 80 | parentheses.) If you use parentheses, the simple but occasionally |
81 | 81 | surprising rule is this: It I<looks> like a function, therefore it I<is> a |
82 | 82 | function, and precedence doesn't matter. Otherwise it's a list |
83 | 83 | operator or unary operator, and precedence does matter. Whitespace |
84 | 84 | between the function and left parenthesis doesn't count, so sometimes |
85 | 85 | you need to be careful: |
86 | 86 | |
87 | 87 | =end original |
88 | 88 | |
89 | 89 | 以下のリストの関数はすべて、引数の前後の括弧は省略可能となっています。 |
90 | 90 | (構文記述では省略しています。) |
91 | 91 | 括弧を使うときには、単純な、(しかし、ときには驚く結果となる規則が |
92 | 92 | 適用できます: |
93 | 93 | I<関数に見える>ならば、I<それは関数>で、優先順位は関係ありません。 |
94 | 94 | そう見えなければ、それはリスト演算子か単項演算子で、優先順位が関係します。 |
95 | 95 | 関数と開き括弧の間の空白は関係ありませんので、ときに |
96 | 96 | 気を付けなければなりません: |
97 | 97 | |
98 | 98 | print 1+2+4; # Prints 7. |
99 | 99 | print(1+2) + 4; # Prints 3. |
100 | 100 | print (1+2)+4; # Also prints 3! |
101 | 101 | print +(1+2)+4; # Prints 7. |
102 | 102 | print ((1+2)+4); # Prints 7. |
103 | 103 | |
104 | 104 | =begin original |
105 | 105 | |
106 | 106 | If you run Perl with the L<C<use warnings>|warnings> pragma, it can warn |
107 | 107 | you about this. For example, the third line above produces: |
108 | 108 | |
109 | 109 | =end original |
110 | 110 | |
111 | 111 | Perl に L<C<use warnings>|warnings> プラグマを付けて実行すれば、 |
112 | 112 | こういったものには警告を出してくれます。 |
113 | 113 | たとえば、上記の三つめは、以下のような警告が出ます: |
114 | 114 | |
115 | 115 | print (...) interpreted as function at - line 1. |
116 | 116 | Useless use of integer addition in void context at - line 1. |
117 | 117 | |
118 | 118 | =begin original |
119 | 119 | |
120 | 120 | A few functions take no arguments at all, and therefore work as neither |
121 | 121 | unary nor list operators. These include such functions as |
122 | 122 | L<C<time>|/time> and L<C<endpwent>|/endpwent>. For example, |
123 | 123 | C<time+86_400> always means C<time() + 86_400>. |
124 | 124 | |
125 | 125 | =end original |
126 | 126 | |
127 | 127 | いくつかの関数は引数を全くとらないので、単項演算子としても |
128 | 128 | リスト演算子としても動作しません。 |
129 | 129 | このような関数としては L<C<time>|/time> や L<C<endpwent>|/endpwent> が |
130 | 130 | あります。 |
131 | 131 | 例えば、C<time+86_400> は常に C<time() + 86_400> として扱われます。 |
132 | 132 | |
133 | 133 | =begin original |
134 | 134 | |
135 | 135 | For functions that can be used in either a scalar or list context, |
136 | 136 | nonabortive failure is generally indicated in scalar context by |
137 | 137 | returning the undefined value, and in list context by returning the |
138 | 138 | empty list. |
139 | 139 | |
140 | 140 | =end original |
141 | 141 | |
142 | 142 | スカラコンテキストでも、リストコンテキストでも使える関数は、致命的でない |
143 | 143 | エラーを示すために、スカラコンテキストでは未定義値を返し、 |
144 | 144 | リストコンテキストでは空リストを返します。 |
145 | 145 | |
146 | 146 | =begin original |
147 | 147 | |
148 | 148 | Remember the following important rule: There is B<no rule> that relates |
149 | 149 | the behavior of an expression in list context to its behavior in scalar |
150 | 150 | context, or vice versa. It might do two totally different things. |
151 | 151 | Each operator and function decides which sort of value would be most |
152 | 152 | appropriate to return in scalar context. Some operators return the |
153 | 153 | length of the list that would have been returned in list context. Some |
154 | 154 | operators return the first value in the list. Some operators return the |
155 | 155 | last value in the list. Some operators return a count of successful |
156 | 156 | operations. In general, they do what you want, unless you want |
157 | 157 | consistency. |
158 | 158 | X<context> |
159 | 159 | |
160 | 160 | =end original |
161 | 161 | |
162 | 162 | 以下に述べる重要なルールを忘れないで下さい: リストコンテキストでの |
163 | 163 | 振る舞いとスカラコンテキストでの振る舞いの関係、あるいはその逆に |
164 | 164 | B<ルールはありません>。 |
165 | 165 | 2 つの全く異なったことがあります。 |
166 | 166 | それぞれの演算子と関数は、スカラコンテキストでは、もっとも適切と |
167 | 167 | 思われる値を返します。 |
168 | 168 | リストコンテキストで返す時のリストの長さを返す演算子もあります。 |
169 | 169 | リストの最初の値を返す演算子もあります。 |
170 | 170 | リストの最後の値を返す演算子もあります。 |
171 | 171 | 成功した操作の数を返す演算子もあります。 |
172 | 172 | 一般的には、一貫性を求めない限り、こちらが求めることをします。 |
173 | 173 | X<context> |
174 | 174 | |
175 | 175 | =begin original |
176 | 176 | |
177 | 177 | A named array in scalar context is quite different from what would at |
178 | 178 | first glance appear to be a list in scalar context. You can't get a list |
179 | 179 | like C<(1,2,3)> into being in scalar context, because the compiler knows |
180 | 180 | the context at compile time. It would generate the scalar comma operator |
181 | 181 | there, not the list concatenation version of the comma. That means it |
182 | 182 | was never a list to start with. |
183 | 183 | |
184 | 184 | =end original |
185 | 185 | |
186 | 186 | スカラコンテキストでの名前付き配列は、スカラコンテキストでのリストを |
187 | 187 | 一目見たものとは全く違います。 |
188 | 188 | コンパイラはコンパイル時にコンテキストを知っているので、 |
189 | 189 | C<(1,2,3)> のようなリストをスカラコンテキストで得ることはできません。 |
190 | 190 | これはスカラコンマ演算子を生成し、コンマのリスト結合版ではありません。 |
191 | 191 | これは初めからリストであることはないことを意味します。 |
192 | 192 | |
193 | 193 | =begin original |
194 | 194 | |
195 | 195 | In general, functions in Perl that serve as wrappers for system calls |
196 | 196 | ("syscalls") of the same name (like L<chown(2)>, L<fork(2)>, |
197 | 197 | L<closedir(2)>, etc.) return true when they succeed and |
198 | 198 | L<C<undef>|/undef EXPR> otherwise, as is usually mentioned in the |
199 | 199 | descriptions below. This is different from the C interfaces, which |
200 | 200 | return C<-1> on failure. Exceptions to this rule include |
201 | 201 | L<C<wait>|/wait>, L<C<waitpid>|/waitpid PID,FLAGS>, and |
202 | 202 | L<C<syscall>|/syscall NUMBER, LIST>. System calls also set the special |
203 | 203 | L<C<$!>|perlvar/$!> variable on failure. Other functions do not, except |
204 | 204 | accidentally. |
205 | 205 | |
206 | 206 | =end original |
207 | 207 | |
208 | 208 | 一般的に、同じ名前のシステムコールのラッパーとして動作する Perl の関数 |
209 | 209 | (L<chown(2)>, L<fork(2)>, L<closedir(2)> など)は、以下に述べるように、 |
210 | 210 | 成功時に真を返し、そうでなければ L<C<undef>|/undef EXPR> を返します。 |
211 | 211 | これは失敗時に C<-1> を返す C のインターフェースとは違います。 |
212 | 212 | このルールの例外は L<C<wait>|/wait>, L<C<waitpid>|/waitpid PID,FLAGS>, |
213 | 213 | L<C<syscall>|/syscall NUMBER, LIST> です。 |
214 | 214 | システムコールは失敗時に特殊変数 L<C<$!>|perlvar/$!> をセットします。 |
215 | 215 | その他の関数は、事故を除いて、セットしません。 |
216 | 216 | |
217 | 217 | =begin original |
218 | 218 | |
219 | 219 | Extension modules can also hook into the Perl parser to define new |
220 | 220 | kinds of keyword-headed expression. These may look like functions, but |
221 | 221 | may also look completely different. The syntax following the keyword |
222 | 222 | is defined entirely by the extension. If you are an implementor, see |
223 | 223 | L<perlapi/PL_keyword_plugin> for the mechanism. If you are using such |
224 | 224 | a module, see the module's documentation for details of the syntax that |
225 | 225 | it defines. |
226 | 226 | |
227 | 227 | =end original |
228 | 228 | |
229 | 229 | エクステンションモジュールは、新しい種類のキーワードが頭に付いた式を |
230 | 230 | 定義するために Perl パーサをフックできます。 |
231 | 231 | これらは関数のように見えるかもしれませんが、全く別物かもしれません。 |
232 | 232 | キーワード以降の文法は完全にエクステンションによって定義されます。 |
233 | 233 | もしあなたが実装者なら、この機構については L<perlapi/PL_keyword_plugin> を |
234 | 234 | 参照してください。 |
235 | 235 | もしあなたがそのようなモジュールを使っているなら、 |
236 | 236 | 定義されている文法の詳細についてはモジュールの文書を参照してください。 |
237 | 237 | |
238 | 238 | =head2 Perl Functions by Category |
239 | 239 | X<function> |
240 | 240 | |
241 | 241 | (カテゴリ別の Perl 関数) |
242 | 242 | |
243 | 243 | =begin original |
244 | 244 | |
245 | 245 | Here are Perl's functions (including things that look like |
246 | 246 | functions, like some keywords and named operators) |
247 | 247 | arranged by category. Some functions appear in more |
248 | than one place. | |
248 | than one place. Any warnings, including those produced by | |
249 | keywords, are described in L<perldiag> and L<warnings>. | |
249 | 250 | |
250 | 251 | =end original |
251 | 252 | |
252 | 253 | 以下に、カテゴリ別の関数(キーワードや名前付き演算子のような、 |
253 | 254 | 関数のように見えるものも含みます)を示します。 |
254 | 255 | 複数の場所に現れる関数もあります。 |
256 | キーワードによって生成されるものを含む全ての警告は | |
257 | L<perldiag> と L<warnings> に記述されています。 | |
255 | 258 | |
256 | 259 | =over 4 |
257 | 260 | |
258 | 261 | =item Functions for SCALARs or strings |
259 | 262 | X<scalar> X<string> X<character> |
260 | 263 | |
261 | 264 | (スカラや文字列のための関数) |
262 | 265 | |
263 | 266 | =for Pod::Functions =String |
264 | 267 | |
265 | 268 | L<C<chomp>|/chomp VARIABLE>, L<C<chop>|/chop VARIABLE>, |
266 | 269 | L<C<chr>|/chr NUMBER>, L<C<crypt>|/crypt PLAINTEXT,SALT>, |
267 | 270 | L<C<fc>|/fc EXPR>, L<C<hex>|/hex EXPR>, |
268 | 271 | L<C<index>|/index STR,SUBSTR,POSITION>, L<C<lc>|/lc EXPR>, |
269 | 272 | L<C<lcfirst>|/lcfirst EXPR>, L<C<length>|/length EXPR>, |
270 | 273 | L<C<oct>|/oct EXPR>, L<C<ord>|/ord EXPR>, |
271 | 274 | L<C<pack>|/pack TEMPLATE,LIST>, |
272 | 275 | L<C<qE<sol>E<sol>>|/qE<sol>STRINGE<sol>>, |
273 | 276 | L<C<qqE<sol>E<sol>>|/qqE<sol>STRINGE<sol>>, L<C<reverse>|/reverse LIST>, |
274 | 277 | L<C<rindex>|/rindex STR,SUBSTR,POSITION>, |
275 | 278 | L<C<sprintf>|/sprintf FORMAT, LIST>, |
276 | 279 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT>, |
277 | 280 | L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>>, L<C<uc>|/uc EXPR>, |
278 | 281 | L<C<ucfirst>|/ucfirst EXPR>, |
279 | 282 | L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>> |
280 | 283 | |
281 | 284 | =begin original |
282 | 285 | |
283 | 286 | L<C<fc>|/fc EXPR> is available only if the |
284 | 287 | L<C<"fc"> feature|feature/The 'fc' feature> is enabled or if it is |
285 | 288 | prefixed with C<CORE::>. The |
286 | 289 | L<C<"fc"> feature|feature/The 'fc' feature> is enabled automatically |
287 | 290 | with a C<use v5.16> (or higher) declaration in the current scope. |
288 | 291 | |
289 | 292 | =end original |
290 | 293 | |
291 | 294 | L<C<fc>|/fc EXPR> は L<C<"fc"> 機能|feature/The 'fc' feature> が有効か |
292 | 295 | C<CORE::> が前置されたときにのみ利用可能です。 |
293 | 296 | L<C<"fc"> 機能|feature/The 'fc' feature> は現在のスコープで |
294 | 297 | C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。 |
295 | 298 | |
296 | 299 | =item Regular expressions and pattern matching |
297 | 300 | X<regular expression> X<regex> X<regexp> |
298 | 301 | |
299 | 302 | (正規表現とパターンマッチング) |
300 | 303 | |
301 | 304 | =for Pod::Functions =Regexp |
302 | 305 | |
303 | 306 | L<C<mE<sol>E<sol>>|/mE<sol>E<sol>>, L<C<pos>|/pos SCALAR>, |
304 | 307 | L<C<qrE<sol>E<sol>>|/qrE<sol>STRINGE<sol>>, |
305 | 308 | L<C<quotemeta>|/quotemeta EXPR>, |
306 | 309 | L<C<sE<sol>E<sol>E<sol>>|/sE<sol>E<sol>E<sol>>, |
307 | 310 | L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>, |
308 | 311 | L<C<study>|/study SCALAR> |
309 | 312 | |
310 | 313 | =item Numeric functions |
311 | 314 | X<numeric> X<number> X<trigonometric> X<trigonometry> |
312 | 315 | |
313 | 316 | (数値関数) |
314 | 317 | |
315 | 318 | =for Pod::Functions =Math |
316 | 319 | |
317 | 320 | L<C<abs>|/abs VALUE>, L<C<atan2>|/atan2 Y,X>, L<C<cos>|/cos EXPR>, |
318 | 321 | L<C<exp>|/exp EXPR>, L<C<hex>|/hex EXPR>, L<C<int>|/int EXPR>, |
319 | 322 | L<C<log>|/log EXPR>, L<C<oct>|/oct EXPR>, L<C<rand>|/rand EXPR>, |
320 | 323 | L<C<sin>|/sin EXPR>, L<C<sqrt>|/sqrt EXPR>, L<C<srand>|/srand EXPR> |
321 | 324 | |
322 | 325 | =item Functions for real @ARRAYs |
323 | 326 | X<array> |
324 | 327 | |
325 | 328 | (実配列のための関数) |
326 | 329 | |
327 | 330 | =for Pod::Functions =ARRAY |
328 | 331 | |
329 | 332 | L<C<each>|/each HASH>, L<C<keys>|/keys HASH>, L<C<pop>|/pop ARRAY>, |
330 | 333 | L<C<push>|/push ARRAY,LIST>, L<C<shift>|/shift ARRAY>, |
331 | 334 | L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST>, |
332 | 335 | L<C<unshift>|/unshift ARRAY,LIST>, L<C<values>|/values HASH> |
333 | 336 | |
334 | 337 | =item Functions for list data |
335 | 338 | X<list> |
336 | 339 | |
337 | 340 | (リストデータのための関数) |
338 | 341 | |
339 | 342 | =for Pod::Functions =LIST |
340 | 343 | |
341 | 344 | L<C<grep>|/grep BLOCK LIST>, L<C<join>|/join EXPR,LIST>, |
342 | 345 | L<C<map>|/map BLOCK LIST>, L<C<qwE<sol>E<sol>>|/qwE<sol>STRINGE<sol>>, |
343 | 346 | L<C<reverse>|/reverse LIST>, L<C<sort>|/sort SUBNAME LIST>, |
344 | 347 | L<C<unpack>|/unpack TEMPLATE,EXPR> |
345 | 348 | |
346 | 349 | =item Functions for real %HASHes |
347 | 350 | X<hash> |
348 | 351 | |
349 | 352 | (実ハッシュのための関数) |
350 | 353 | |
351 | 354 | =for Pod::Functions =HASH |
352 | 355 | |
353 | 356 | L<C<delete>|/delete EXPR>, L<C<each>|/each HASH>, |
354 | 357 | L<C<exists>|/exists EXPR>, L<C<keys>|/keys HASH>, |
355 | 358 | L<C<values>|/values HASH> |
356 | 359 | |
357 | 360 | =item Input and output functions |
358 | 361 | X<I/O> X<input> X<output> X<dbm> |
359 | 362 | |
360 | 363 | (入出力関数) |
361 | 364 | |
362 | 365 | =for Pod::Functions =I/O |
363 | 366 | |
364 | 367 | L<C<binmode>|/binmode FILEHANDLE, LAYER>, L<C<close>|/close FILEHANDLE>, |
365 | 368 | L<C<closedir>|/closedir DIRHANDLE>, L<C<dbmclose>|/dbmclose HASH>, |
366 | 369 | L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, L<C<die>|/die LIST>, |
367 | 370 | L<C<eof>|/eof FILEHANDLE>, L<C<fileno>|/fileno FILEHANDLE>, |
368 | 371 | L<C<flock>|/flock FILEHANDLE,OPERATION>, L<C<format>|/format>, |
369 | 372 | L<C<getc>|/getc FILEHANDLE>, L<C<print>|/print FILEHANDLE LIST>, |
370 | 373 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, |
371 | 374 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>, |
372 | 375 | L<C<readdir>|/readdir DIRHANDLE>, L<C<readline>|/readline EXPR>, |
373 | 376 | L<C<rewinddir>|/rewinddir DIRHANDLE>, L<C<say>|/say FILEHANDLE LIST>, |
374 | 377 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, |
375 | 378 | L<C<seekdir>|/seekdir DIRHANDLE,POS>, |
376 | 379 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, |
377 | 380 | L<C<syscall>|/syscall NUMBER, LIST>, |
378 | 381 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, |
379 | 382 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>, |
380 | 383 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, |
381 | 384 | L<C<tell>|/tell FILEHANDLE>, L<C<telldir>|/telldir DIRHANDLE>, |
382 | 385 | L<C<truncate>|/truncate FILEHANDLE,LENGTH>, L<C<warn>|/warn LIST>, |
383 | 386 | L<C<write>|/write FILEHANDLE> |
384 | 387 | |
385 | 388 | =begin original |
386 | 389 | |
387 | 390 | L<C<say>|/say FILEHANDLE LIST> is available only if the |
388 | 391 | L<C<"say"> feature|feature/The 'say' feature> is enabled or if it is |
389 | 392 | prefixed with C<CORE::>. The |
390 | 393 | L<C<"say"> feature|feature/The 'say' feature> is enabled automatically |
391 | 394 | with a C<use v5.10> (or higher) declaration in the current scope. |
392 | 395 | |
393 | 396 | =end original |
394 | 397 | |
395 | 398 | L<C<say>|/say FILEHANDLE LIST> は |
396 | 399 | L<C<"say"> 機能|feature/The 'say' feature> が有効か C<CORE::> が |
397 | 400 | 前置されたときにのみ利用可能です。 |
398 | 401 | L<C<"say"> 機能|feature/The 'say' feature> は現在のスコープで |
399 | 402 | C<use v5.10> (またはそれ以上) が宣言されると自動的に有効になります。 |
400 | 403 | |
401 | 404 | =item Functions for fixed-length data or records |
402 | 405 | |
403 | 406 | (固定長データやレコードのための関数) |
404 | 407 | |
405 | 408 | =for Pod::Functions =Binary |
406 | 409 | |
407 | 410 | L<C<pack>|/pack TEMPLATE,LIST>, |
408 | 411 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>, |
409 | 412 | L<C<syscall>|/syscall NUMBER, LIST>, |
410 | 413 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, |
411 | 414 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>, |
412 | 415 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, |
413 | 416 | L<C<unpack>|/unpack TEMPLATE,EXPR>, L<C<vec>|/vec EXPR,OFFSET,BITS> |
414 | 417 | |
415 | 418 | =item Functions for filehandles, files, or directories |
416 | 419 | X<file> X<filehandle> X<directory> X<pipe> X<link> X<symlink> |
417 | 420 | |
418 | 421 | (ファイルハンドル、ファイル、ディレクトリのための関数) |
419 | 422 | |
420 | 423 | =for Pod::Functions =File |
421 | 424 | |
422 | 425 | L<C<-I<X>>|/-X FILEHANDLE>, L<C<chdir>|/chdir EXPR>, |
423 | 426 | L<C<chmod>|/chmod LIST>, L<C<chown>|/chown LIST>, |
424 | 427 | L<C<chroot>|/chroot FILENAME>, |
425 | 428 | L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>, L<C<glob>|/glob EXPR>, |
426 | 429 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>, |
427 | 430 | L<C<link>|/link OLDFILE,NEWFILE>, L<C<lstat>|/lstat FILEHANDLE>, |
428 | L<C<mkdir>|/mkdir FILENAME,M | |
431 | L<C<mkdir>|/mkdir FILENAME,MODE>, L<C<open>|/open FILEHANDLE,MODE,EXPR>, | |
429 | 432 | L<C<opendir>|/opendir DIRHANDLE,EXPR>, L<C<readlink>|/readlink EXPR>, |
430 | 433 | L<C<rename>|/rename OLDNAME,NEWNAME>, L<C<rmdir>|/rmdir FILENAME>, |
431 | 434 | L<C<select>|/select FILEHANDLE>, L<C<stat>|/stat FILEHANDLE>, |
432 | 435 | L<C<symlink>|/symlink OLDFILE,NEWFILE>, |
433 | 436 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>, |
434 | 437 | L<C<umask>|/umask EXPR>, L<C<unlink>|/unlink LIST>, |
435 | 438 | L<C<utime>|/utime LIST> |
436 | 439 | |
437 | 440 | =item Keywords related to the control flow of your Perl program |
438 | 441 | X<control flow> |
439 | 442 | |
440 | 443 | (プログラムの流れを制御することに関連するキーワード) |
441 | 444 | |
442 | 445 | =for Pod::Functions =Flow |
443 | 446 | |
444 | 447 | L<C<break>|/break>, L<C<caller>|/caller EXPR>, |
445 | 448 | L<C<continue>|/continue BLOCK>, L<C<die>|/die LIST>, L<C<do>|/do BLOCK>, |
446 | 449 | L<C<dump>|/dump LABEL>, L<C<eval>|/eval EXPR>, |
447 | 450 | L<C<evalbytes>|/evalbytes EXPR>, L<C<exit>|/exit EXPR>, |
448 | 451 | L<C<__FILE__>|/__FILE__>, L<C<goto>|/goto LABEL>, |
449 | 452 | L<C<last>|/last LABEL>, L<C<__LINE__>|/__LINE__>, |
450 | 453 | L<C<next>|/next LABEL>, L<C<__PACKAGE__>|/__PACKAGE__>, |
451 | 454 | L<C<redo>|/redo LABEL>, L<C<return>|/return EXPR>, |
452 | 455 | L<C<sub>|/sub NAME BLOCK>, L<C<__SUB__>|/__SUB__>, |
453 | 456 | L<C<wantarray>|/wantarray> |
454 | 457 | |
455 | 458 | =begin original |
456 | 459 | |
457 | 460 | L<C<break>|/break> is available only if you enable the experimental |
458 | 461 | L<C<"switch"> feature|feature/The 'switch' feature> or use the C<CORE::> |
459 | 462 | prefix. The L<C<"switch"> feature|feature/The 'switch' feature> also |
460 | 463 | enables the C<default>, C<given> and C<when> statements, which are |
461 | 464 | documented in L<perlsyn/"Switch Statements">. |
462 | 465 | The L<C<"switch"> feature|feature/The 'switch' feature> is enabled |
463 | 466 | automatically with a C<use v5.10> (or higher) declaration in the current |
464 | 467 | scope. In Perl v5.14 and earlier, L<C<continue>|/continue BLOCK> |
465 | 468 | required the L<C<"switch"> feature|feature/The 'switch' feature>, like |
466 | 469 | the other keywords. |
467 | 470 | |
468 | 471 | =end original |
469 | 472 | |
470 | 473 | L<C<break>|/break> は、実験的な |
471 | 474 | L<C<"switch"> 機能|feature/The 'switch' feature> が有効か C<CORE::> 接頭辞を |
472 | 475 | 使ったときにのみ利用可能です。 |
473 | 476 | L<C<"switch"> 機能|feature/The 'switch' feature> は、 |
474 | 477 | L<perlsyn/"Switch Statements"> で文書化されている |
475 | 478 | C<default>, C<given>, C<when> 文も有効にします。 |
476 | 479 | L<C<"switch"> 機能|feature/The 'switch' feature> は、現在のスコープで |
477 | 480 | C<use v5.10> (またはそれ以上) 宣言があると自動的に有効になります。 |
478 | 481 | Perl v5.14 以前では、L<C<continue>|/continue BLOCK> は他のキーワードと同様に |
479 | 482 | L<C<"switch"> 機能|feature/The 'switch' feature> が必要です。 |
480 | 483 | |
481 | 484 | =begin original |
482 | 485 | |
483 | 486 | L<C<evalbytes>|/evalbytes EXPR> is only available with the |
484 | 487 | L<C<"evalbytes"> feature|feature/The 'unicode_eval' and 'evalbytes' features> |
485 | 488 | (see L<feature>) or if prefixed with C<CORE::>. L<C<__SUB__>|/__SUB__> |
486 | 489 | is only available with the |
487 | 490 | L<C<"current_sub"> feature|feature/The 'current_sub' feature> or if |
488 | 491 | prefixed with C<CORE::>. Both the |
489 | 492 | L<C<"evalbytes">|feature/The 'unicode_eval' and 'evalbytes' features> |
490 | 493 | and L<C<"current_sub">|feature/The 'current_sub' feature> features are |
491 | 494 | enabled automatically with a C<use v5.16> (or higher) declaration in the |
492 | 495 | current scope. |
493 | 496 | |
494 | 497 | =end original |
495 | 498 | |
496 | 499 | L<C<evalbytes>|/evalbytes EXPR> は |
497 | 500 | L<C<"evalbytes"> 機能|feature/The 'unicode_eval' and 'evalbytes' features> |
498 | 501 | (L<feature> 参照) が有効か C<CORE::> が前置されたときにのみ利用可能です。 |
499 | 502 | L<C<__SUB__>|/__SUB__> は |
500 | 503 | L<C<"current_sub"> 機能|feature/The 'current_sub' feature> が有効か |
501 | 504 | C<CORE::> が前置されたときにのみ利用可能です。 |
502 | 505 | L<C<"evalbytes">|feature/The 'unicode_eval' and 'evalbytes' features> と |
503 | 506 | L<C<"current_sub">|feature/The 'current_sub' feature> の両方の機能は |
504 | 507 | 現在のスコープで |
505 | 508 | C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。 |
506 | 509 | |
507 | 510 | =item Keywords related to scoping |
508 | 511 | |
509 | 512 | (スコープに関するキーワード) |
510 | 513 | |
511 | 514 | =for Pod::Functions =Namespace |
512 | 515 | |
513 | 516 | L<C<caller>|/caller EXPR>, L<C<import>|/import LIST>, |
514 | 517 | L<C<local>|/local EXPR>, L<C<my>|/my VARLIST>, L<C<our>|/our VARLIST>, |
515 | 518 | L<C<package>|/package NAMESPACE>, L<C<state>|/state VARLIST>, |
516 | 519 | L<C<use>|/use Module VERSION LIST> |
517 | 520 | |
518 | 521 | =begin original |
519 | 522 | |
520 | 523 | L<C<state>|/state VARLIST> is available only if the |
521 | 524 | L<C<"state"> feature|feature/The 'state' feature> is enabled or if it is |
522 | 525 | prefixed with C<CORE::>. The |
523 | 526 | L<C<"state"> feature|feature/The 'state' feature> is enabled |
524 | 527 | automatically with a C<use v5.10> (or higher) declaration in the current |
525 | 528 | scope. |
526 | 529 | |
527 | 530 | =end original |
528 | 531 | |
529 | 532 | L<C<state>|/state VARLIST> は |
530 | 533 | L<C<"state"> 機能|feature/The 'state' feature> が有効か C<CORE::> を |
531 | 534 | 前置した場合にのみ利用可能です。 |
532 | 535 | L<C<"state"> 機能|feature/The 'state' feature> は現在のスコープで |
533 | 536 | C<use v5.10> (またはそれ以上) を宣言した場合自動的に有効になります。 |
534 | 537 | |
535 | 538 | =item Miscellaneous functions |
536 | 539 | |
537 | 540 | (さまざまな関数) |
538 | 541 | |
539 | 542 | =for Pod::Functions =Misc |
540 | 543 | |
541 | 544 | L<C<defined>|/defined EXPR>, L<C<formline>|/formline PICTURE,LIST>, |
542 | 545 | L<C<lock>|/lock THING>, L<C<prototype>|/prototype FUNCTION>, |
543 | 546 | L<C<reset>|/reset EXPR>, L<C<scalar>|/scalar EXPR>, |
544 | 547 | L<C<undef>|/undef EXPR> |
545 | 548 | |
546 | 549 | =item Functions for processes and process groups |
547 | 550 | X<process> X<pid> X<process id> |
548 | 551 | |
549 | 552 | (プロセスとプロセスグループのための関数) |
550 | 553 | |
551 | 554 | =for Pod::Functions =Process |
552 | 555 | |
553 | 556 | L<C<alarm>|/alarm SECONDS>, L<C<exec>|/exec LIST>, L<C<fork>|/fork>, |
554 | 557 | L<C<getpgrp>|/getpgrp PID>, L<C<getppid>|/getppid>, |
555 | 558 | L<C<getpriority>|/getpriority WHICH,WHO>, L<C<kill>|/kill SIGNAL, LIST>, |
556 | 559 | L<C<pipe>|/pipe READHANDLE,WRITEHANDLE>, |
557 | 560 | L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>>, |
558 | 561 | L<C<readpipe>|/readpipe EXPR>, L<C<setpgrp>|/setpgrp PID,PGRP>, |
559 | 562 | L<C<setpriority>|/setpriority WHICH,WHO,PRIORITY>, |
560 | 563 | L<C<sleep>|/sleep EXPR>, L<C<system>|/system LIST>, L<C<times>|/times>, |
561 | 564 | L<C<wait>|/wait>, L<C<waitpid>|/waitpid PID,FLAGS> |
562 | 565 | |
563 | 566 | =item Keywords related to Perl modules |
564 | 567 | X<module> |
565 | 568 | |
566 | 569 | (Perl モジュールに関するキーワード) |
567 | 570 | |
568 | 571 | =for Pod::Functions =Modules |
569 | 572 | |
570 | 573 | L<C<do>|/do EXPR>, L<C<import>|/import LIST>, |
571 | 574 | L<C<no>|/no MODULE VERSION LIST>, L<C<package>|/package NAMESPACE>, |
572 | 575 | L<C<require>|/require VERSION>, L<C<use>|/use Module VERSION LIST> |
573 | 576 | |
574 | 577 | =item Keywords related to classes and object-orientation |
575 | 578 | X<object> X<class> X<package> |
576 | 579 | |
577 | 580 | (クラスとオブジェクト指向に関するキーワード) |
578 | 581 | |
579 | 582 | =for Pod::Functions =Objects |
580 | 583 | |
581 | 584 | L<C<bless>|/bless REF,CLASSNAME>, L<C<dbmclose>|/dbmclose HASH>, |
582 | 585 | L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, |
583 | 586 | L<C<package>|/package NAMESPACE>, L<C<ref>|/ref EXPR>, |
584 | 587 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST>, L<C<tied>|/tied VARIABLE>, |
585 | 588 | L<C<untie>|/untie VARIABLE>, L<C<use>|/use Module VERSION LIST> |
586 | 589 | |
587 | 590 | =item Low-level socket functions |
588 | 591 | X<socket> X<sock> |
589 | 592 | |
590 | 593 | (低レベルソケット関数) |
591 | 594 | |
592 | 595 | =for Pod::Functions =Socket |
593 | 596 | |
594 | 597 | L<C<accept>|/accept NEWSOCKET,GENERICSOCKET>, |
595 | 598 | L<C<bind>|/bind SOCKET,NAME>, L<C<connect>|/connect SOCKET,NAME>, |
596 | 599 | L<C<getpeername>|/getpeername SOCKET>, |
597 | 600 | L<C<getsockname>|/getsockname SOCKET>, |
598 | 601 | L<C<getsockopt>|/getsockopt SOCKET,LEVEL,OPTNAME>, |
599 | 602 | L<C<listen>|/listen SOCKET,QUEUESIZE>, |
600 | 603 | L<C<recv>|/recv SOCKET,SCALAR,LENGTH,FLAGS>, |
601 | 604 | L<C<send>|/send SOCKET,MSG,FLAGS,TO>, |
602 | 605 | L<C<setsockopt>|/setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL>, |
603 | 606 | L<C<shutdown>|/shutdown SOCKET,HOW>, |
604 | 607 | L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL>, |
605 | 608 | L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL> |
606 | 609 | |
607 | 610 | =item System V interprocess communication functions |
608 | 611 | X<IPC> X<System V> X<semaphore> X<shared memory> X<memory> X<message> |
609 | 612 | |
610 | 613 | (System V プロセス間通信関数) |
611 | 614 | |
612 | 615 | =for Pod::Functions =SysV |
613 | 616 | |
614 | 617 | L<C<msgctl>|/msgctl ID,CMD,ARG>, L<C<msgget>|/msgget KEY,FLAGS>, |
615 | 618 | L<C<msgrcv>|/msgrcv ID,VAR,SIZE,TYPE,FLAGS>, |
616 | 619 | L<C<msgsnd>|/msgsnd ID,MSG,FLAGS>, |
617 | 620 | L<C<semctl>|/semctl ID,SEMNUM,CMD,ARG>, |
618 | 621 | L<C<semget>|/semget KEY,NSEMS,FLAGS>, L<C<semop>|/semop KEY,OPSTRING>, |
619 | 622 | L<C<shmctl>|/shmctl ID,CMD,ARG>, L<C<shmget>|/shmget KEY,SIZE,FLAGS>, |
620 | 623 | L<C<shmread>|/shmread ID,VAR,POS,SIZE>, |
621 | 624 | L<C<shmwrite>|/shmwrite ID,STRING,POS,SIZE> |
622 | 625 | |
623 | 626 | =item Fetching user and group info |
624 | 627 | X<user> X<group> X<password> X<uid> X<gid> X<passwd> X</etc/passwd> |
625 | 628 | |
626 | 629 | (ユーザーとグループの情報取得) |
627 | 630 | |
628 | 631 | =for Pod::Functions =User |
629 | 632 | |
630 | 633 | L<C<endgrent>|/endgrent>, L<C<endhostent>|/endhostent>, |
631 | 634 | L<C<endnetent>|/endnetent>, L<C<endpwent>|/endpwent>, |
632 | 635 | L<C<getgrent>|/getgrent>, L<C<getgrgid>|/getgrgid GID>, |
633 | 636 | L<C<getgrnam>|/getgrnam NAME>, L<C<getlogin>|/getlogin>, |
634 | 637 | L<C<getpwent>|/getpwent>, L<C<getpwnam>|/getpwnam NAME>, |
635 | 638 | L<C<getpwuid>|/getpwuid UID>, L<C<setgrent>|/setgrent>, |
636 | 639 | L<C<setpwent>|/setpwent> |
637 | 640 | |
638 | 641 | =item Fetching network info |
639 | 642 | X<network> X<protocol> X<host> X<hostname> X<IP> X<address> X<service> |
640 | 643 | |
641 | 644 | (ネットワーク情報取得) |
642 | 645 | |
643 | 646 | =for Pod::Functions =Network |
644 | 647 | |
645 | 648 | L<C<endprotoent>|/endprotoent>, L<C<endservent>|/endservent>, |
646 | 649 | L<C<gethostbyaddr>|/gethostbyaddr ADDR,ADDRTYPE>, |
647 | 650 | L<C<gethostbyname>|/gethostbyname NAME>, L<C<gethostent>|/gethostent>, |
648 | 651 | L<C<getnetbyaddr>|/getnetbyaddr ADDR,ADDRTYPE>, |
649 | 652 | L<C<getnetbyname>|/getnetbyname NAME>, L<C<getnetent>|/getnetent>, |
650 | 653 | L<C<getprotobyname>|/getprotobyname NAME>, |
651 | 654 | L<C<getprotobynumber>|/getprotobynumber NUMBER>, |
652 | 655 | L<C<getprotoent>|/getprotoent>, |
653 | 656 | L<C<getservbyname>|/getservbyname NAME,PROTO>, |
654 | 657 | L<C<getservbyport>|/getservbyport PORT,PROTO>, |
655 | 658 | L<C<getservent>|/getservent>, L<C<sethostent>|/sethostent STAYOPEN>, |
656 | 659 | L<C<setnetent>|/setnetent STAYOPEN>, |
657 | 660 | L<C<setprotoent>|/setprotoent STAYOPEN>, |
658 | 661 | L<C<setservent>|/setservent STAYOPEN> |
659 | 662 | |
660 | 663 | =item Time-related functions |
661 | 664 | X<time> X<date> |
662 | 665 | |
663 | 666 | (時刻に関する関数) |
664 | 667 | |
665 | 668 | =for Pod::Functions =Time |
666 | 669 | |
667 | 670 | L<C<gmtime>|/gmtime EXPR>, L<C<localtime>|/localtime EXPR>, |
668 | 671 | L<C<time>|/time>, L<C<times>|/times> |
669 | 672 | |
670 | 673 | =item Non-function keywords |
671 | 674 | |
672 | 675 | =for Pod::Functions =!Non-functions |
673 | 676 | |
674 | 677 | C<and>, C<AUTOLOAD>, C<BEGIN>, C<CHECK>, C<cmp>, C<CORE>, C<__DATA__>, |
675 | 678 | C<default>, C<DESTROY>, C<else>, C<elseif>, C<elsif>, C<END>, C<__END__>, |
676 | 679 | C<eq>, C<for>, C<foreach>, C<ge>, C<given>, C<gt>, C<if>, C<INIT>, C<le>, |
677 | 680 | C<lt>, C<ne>, C<not>, C<or>, C<UNITCHECK>, C<unless>, C<until>, C<when>, |
678 | 681 | C<while>, C<x>, C<xor> |
679 | 682 | |
680 | 683 | =back |
681 | 684 | |
682 | 685 | =head2 Portability |
683 | 686 | X<portability> X<Unix> X<portable> |
684 | 687 | |
685 | 688 | (移植性) |
686 | 689 | |
687 | 690 | =begin original |
688 | 691 | |
689 | 692 | Perl was born in Unix and can therefore access all common Unix |
690 | 693 | system calls. In non-Unix environments, the functionality of some |
691 | 694 | Unix system calls may not be available or details of the available |
692 | 695 | functionality may differ slightly. The Perl functions affected |
693 | 696 | by this are: |
694 | 697 | |
695 | 698 | =end original |
696 | 699 | |
697 | 700 | Perl は Unix 環境で生まれたので、全ての共通する Unix システムコールに |
698 | 701 | アクセスします。 |
699 | 702 | 非 Unix 環境では、いくつかの Unix システムコールの機能が使えなかったり、 |
700 | 703 | 使える機能の詳細が多少異なったりします。 |
701 | 704 | これによる影響を受ける Perl 関数は以下のものです: |
702 | 705 | |
703 | 706 | L<C<-I<X>>|/-X FILEHANDLE>, L<C<binmode>|/binmode FILEHANDLE, LAYER>, |
704 | 707 | L<C<chmod>|/chmod LIST>, L<C<chown>|/chown LIST>, |
705 | 708 | L<C<chroot>|/chroot FILENAME>, L<C<crypt>|/crypt PLAINTEXT,SALT>, |
706 | 709 | L<C<dbmclose>|/dbmclose HASH>, L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, |
707 | 710 | L<C<dump>|/dump LABEL>, L<C<endgrent>|/endgrent>, |
708 | 711 | L<C<endhostent>|/endhostent>, L<C<endnetent>|/endnetent>, |
709 | 712 | L<C<endprotoent>|/endprotoent>, L<C<endpwent>|/endpwent>, |
710 | 713 | L<C<endservent>|/endservent>, L<C<exec>|/exec LIST>, |
711 | 714 | L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>, |
712 | 715 | L<C<flock>|/flock FILEHANDLE,OPERATION>, L<C<fork>|/fork>, |
713 | 716 | L<C<getgrent>|/getgrent>, L<C<getgrgid>|/getgrgid GID>, |
714 | 717 | L<C<gethostbyname>|/gethostbyname NAME>, L<C<gethostent>|/gethostent>, |
715 | 718 | L<C<getlogin>|/getlogin>, |
716 | 719 | L<C<getnetbyaddr>|/getnetbyaddr ADDR,ADDRTYPE>, |
717 | 720 | L<C<getnetbyname>|/getnetbyname NAME>, L<C<getnetent>|/getnetent>, |
718 | 721 | L<C<getppid>|/getppid>, L<C<getpgrp>|/getpgrp PID>, |
719 | 722 | L<C<getpriority>|/getpriority WHICH,WHO>, |
720 | 723 | L<C<getprotobynumber>|/getprotobynumber NUMBER>, |
721 | 724 | L<C<getprotoent>|/getprotoent>, L<C<getpwent>|/getpwent>, |
722 | 725 | L<C<getpwnam>|/getpwnam NAME>, L<C<getpwuid>|/getpwuid UID>, |
723 | 726 | L<C<getservbyport>|/getservbyport PORT,PROTO>, |
724 | 727 | L<C<getservent>|/getservent>, |
725 | 728 | L<C<getsockopt>|/getsockopt SOCKET,LEVEL,OPTNAME>, |
726 | 729 | L<C<glob>|/glob EXPR>, L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>, |
727 | 730 | L<C<kill>|/kill SIGNAL, LIST>, L<C<link>|/link OLDFILE,NEWFILE>, |
728 | 731 | L<C<lstat>|/lstat FILEHANDLE>, L<C<msgctl>|/msgctl ID,CMD,ARG>, |
729 | 732 | L<C<msgget>|/msgget KEY,FLAGS>, |
730 | 733 | L<C<msgrcv>|/msgrcv ID,VAR,SIZE,TYPE,FLAGS>, |
731 | L<C<msgsnd>|/msgsnd ID,MSG,FLAGS>, L<C<open>|/open FILEHANDLE,EXPR>, | |
734 | L<C<msgsnd>|/msgsnd ID,MSG,FLAGS>, L<C<open>|/open FILEHANDLE,MODE,EXPR>, | |
732 | 735 | L<C<pipe>|/pipe READHANDLE,WRITEHANDLE>, L<C<readlink>|/readlink EXPR>, |
733 | 736 | L<C<rename>|/rename OLDNAME,NEWNAME>, |
734 | 737 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, |
735 | 738 | L<C<semctl>|/semctl ID,SEMNUM,CMD,ARG>, |
736 | 739 | L<C<semget>|/semget KEY,NSEMS,FLAGS>, L<C<semop>|/semop KEY,OPSTRING>, |
737 | 740 | L<C<setgrent>|/setgrent>, L<C<sethostent>|/sethostent STAYOPEN>, |
738 | 741 | L<C<setnetent>|/setnetent STAYOPEN>, L<C<setpgrp>|/setpgrp PID,PGRP>, |
739 | 742 | L<C<setpriority>|/setpriority WHICH,WHO,PRIORITY>, |
740 | 743 | L<C<setprotoent>|/setprotoent STAYOPEN>, L<C<setpwent>|/setpwent>, |
741 | 744 | L<C<setservent>|/setservent STAYOPEN>, |
742 | 745 | L<C<setsockopt>|/setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL>, |
743 | 746 | L<C<shmctl>|/shmctl ID,CMD,ARG>, L<C<shmget>|/shmget KEY,SIZE,FLAGS>, |
744 | 747 | L<C<shmread>|/shmread ID,VAR,POS,SIZE>, |
745 | 748 | L<C<shmwrite>|/shmwrite ID,STRING,POS,SIZE>, |
746 | 749 | L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL>, |
747 | 750 | L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL>, |
748 | 751 | L<C<stat>|/stat FILEHANDLE>, L<C<symlink>|/symlink OLDFILE,NEWFILE>, |
749 | 752 | L<C<syscall>|/syscall NUMBER, LIST>, |
750 | 753 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>, |
751 | 754 | L<C<system>|/system LIST>, L<C<times>|/times>, |
752 | 755 | L<C<truncate>|/truncate FILEHANDLE,LENGTH>, L<C<umask>|/umask EXPR>, |
753 | 756 | L<C<unlink>|/unlink LIST>, L<C<utime>|/utime LIST>, L<C<wait>|/wait>, |
754 | 757 | L<C<waitpid>|/waitpid PID,FLAGS> |
755 | 758 | |
756 | 759 | =begin original |
757 | 760 | |
758 | 761 | For more information about the portability of these functions, see |
759 | 762 | L<perlport> and other available platform-specific documentation. |
760 | 763 | |
761 | 764 | =end original |
762 | 765 | |
763 | 766 | これらの関数の移植性に関するさらなる情報については、 |
764 | 767 | L<perlport> とその他のプラットホーム固有のドキュメントを参照してください。 |
765 | 768 | |
766 | 769 | =head2 Alphabetical Listing of Perl Functions |
767 | 770 | |
768 | 771 | =over |
769 | 772 | |
770 | 773 | =item -X FILEHANDLE |
771 | 774 | X<-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> |
772 | 775 | X<-S>X<-b>X<-c>X<-t>X<-u>X<-g>X<-k>X<-T>X<-B>X<-M>X<-A>X<-C> |
773 | 776 | |
774 | 777 | =item -X EXPR |
775 | 778 | |
776 | 779 | =item -X DIRHANDLE |
777 | 780 | |
778 | 781 | =item -X |
779 | 782 | |
780 | 783 | =for Pod::Functions a file test (-r, -x, etc) |
781 | 784 | |
782 | 785 | =begin original |
783 | 786 | |
784 | 787 | A file test, where X is one of the letters listed below. This unary |
785 | 788 | operator takes one argument, either a filename, a filehandle, or a dirhandle, |
786 | 789 | and tests the associated file to see if something is true about it. If the |
787 | 790 | argument is omitted, tests L<C<$_>|perlvar/$_>, except for C<-t>, which |
788 | 791 | tests STDIN. Unless otherwise documented, it returns C<1> for true and |
789 | 792 | C<''> for false. If the file doesn't exist or can't be examined, it |
790 | 793 | returns L<C<undef>|/undef EXPR> and sets L<C<$!>|perlvar/$!> (errno). |
791 | ||
794 | With the exception of the C<-l> test they all follow symbolic links | |
792 | ||
795 | because they use C<stat()> and not C<lstat()> (so dangling symlinks can't | |
796 | be examined and will therefore report failure). | |
793 | 797 | |
794 | 798 | =end original |
795 | 799 | |
796 | 800 | X は以下にあげる文字で、ファイルテストを行ないます。 |
797 | 801 | この単項演算子は、ファイル名かファイルハンドルを唯一の引数として動作し、 |
798 | 802 | 「あること」について真であるか否かを判定した結果を返します。 |
799 | 803 | 引数が省略されると、C<-t> では STDIN を調べますが、その他は |
800 | 804 | L<C<$_>|perlvar/$_> を調べます。 |
801 | 805 | 特に記述されていなければ、真として C<1> を返し、偽として C<''> を返します。 |
802 | 806 | ファイルが存在しないか、テスト出来なければ、L<C<undef>|/undef EXPR> を返し、 |
803 | 807 | L<C<$!>|perlvar/$!> (errno) を設定します。 |
808 | C<-l> テストを例外として、これら全てはシンボリックリンクに従います; | |
809 | C<lstat()> ではなく C<stat()> を使っているからです | |
810 | (従って壊れたシンボリックリンクは検査されず、失敗が報告されます)。 | |
811 | ||
812 | =begin original | |
813 | ||
814 | Despite the funny names, precedence is the same as any other named unary | |
815 | operator. The operator may be any of: | |
816 | ||
817 | =end original | |
818 | ||
804 | 819 | みかけは変わっていますが、優先順位は名前付き単項演算子と同じで、 |
805 | 820 | 他の単項演算子と同じく、引数を括弧で括ることもできます。 |
806 | 821 | 演算子には以下のものがあります: |
807 | 822 | |
808 | 823 | =begin original |
809 | 824 | |
810 | 825 | -r File is readable by effective uid/gid. |
811 | 826 | -w File is writable by effective uid/gid. |
812 | 827 | -x File is executable by effective uid/gid. |
813 | 828 | -o File is owned by effective uid. |
814 | 829 | |
815 | 830 | =end original |
816 | 831 | |
817 | 832 | -r ファイルが実効 uid/gid で読み出し可。 |
818 | 833 | -w ファイルが実効 uid/gid で書き込み可。 |
819 | 834 | -x ファイルが実効 uid/gid で実行可。 |
820 | 835 | -o ファイルが実効 uid の所有物。 |
821 | 836 | |
822 | 837 | =begin original |
823 | 838 | |
824 | 839 | -R File is readable by real uid/gid. |
825 | 840 | -W File is writable by real uid/gid. |
826 | 841 | -X File is executable by real uid/gid. |
827 | 842 | -O File is owned by real uid. |
828 | 843 | |
829 | 844 | =end original |
830 | 845 | |
831 | 846 | -R ファイルが実 uid/gid で読み出し可。 |
832 | 847 | -W ファイルが実 uid/gid で書き込み可。 |
833 | 848 | -X ファイルが実 uid/gid で実行可。 |
834 | 849 | -O ファイルが実 uid の所有物。 |
835 | 850 | |
836 | 851 | =begin original |
837 | 852 | |
838 | 853 | -e File exists. |
839 | 854 | -z File has zero size (is empty). |
840 | 855 | -s File has nonzero size (returns size in bytes). |
841 | 856 | |
842 | 857 | =end original |
843 | 858 | |
844 | 859 | -e ファイルが存在する。 |
845 | 860 | -z ファイルの大きさがゼロ(空)。 |
846 | 861 | -s ファイルの大きさがゼロ以外 (バイト単位での大きさを返す)。 |
847 | 862 | |
848 | 863 | =begin original |
849 | 864 | |
850 | 865 | -f File is a plain file. |
851 | 866 | -d File is a directory. |
852 | 867 | -l File is a symbolic link (false if symlinks aren't |
853 | 868 | supported by the file system). |
854 | 869 | -p File is a named pipe (FIFO), or Filehandle is a pipe. |
855 | 870 | -S File is a socket. |
856 | 871 | -b File is a block special file. |
857 | 872 | -c File is a character special file. |
858 | 873 | -t Filehandle is opened to a tty. |
859 | 874 | |
860 | 875 | =end original |
861 | 876 | |
862 | 877 | -f ファイルは通常ファイル。 |
863 | 878 | -d ファイルはディレクトリ。 |
864 | 879 | -l ファイルはシンボリックリンク(ファイルシステムが非対応なら偽)。 |
865 | 880 | -p ファイルは名前付きパイプ (FIFO) またはファイルハンドルはパイプ。 |
866 | 881 | -S ファイルはソケット。 |
867 | 882 | -b ファイルはブロック特殊ファイル。 |
868 | 883 | -c ファイルはキャラクタ特殊ファイル。 |
869 | 884 | -t ファイルハンドルは tty にオープンされている。 |
870 | 885 | |
871 | 886 | =begin original |
872 | 887 | |
873 | 888 | -u File has setuid bit set. |
874 | 889 | -g File has setgid bit set. |
875 | 890 | -k File has sticky bit set. |
876 | 891 | |
877 | 892 | =end original |
878 | 893 | |
879 | 894 | -u ファイルの setuid ビットがセットされている。 |
880 | 895 | -g ファイルの setgid ビットがセットされている。 |
881 | 896 | -k ファイルの sticky ビットがセットされている。 |
882 | 897 | |
883 | 898 | =begin original |
884 | 899 | |
885 | 900 | -T File is an ASCII or UTF-8 text file (heuristic guess). |
886 | 901 | -B File is a "binary" file (opposite of -T). |
887 | 902 | |
888 | 903 | =end original |
889 | 904 | |
890 | 905 | -T ファイルは ASCII または UTF-8 テキストファイル (発見的に推測します)。 |
891 | 906 | -B ファイルは「バイナリ」ファイル (-T の反対)。 |
892 | 907 | |
893 | 908 | =begin original |
894 | 909 | |
895 | 910 | -M Script start time minus file modification time, in days. |
896 | 911 | -A Same for access time. |
897 | 912 | -C Same for inode change time (Unix, may differ for other |
898 | 913 | platforms) |
899 | 914 | |
900 | 915 | =end original |
901 | 916 | |
902 | 917 | -M スクリプト実行開始時刻からファイル修正時刻を引いたもの(日単位)。 |
903 | 918 | -A 同様にアクセスがあってからの日数。 |
904 | 919 | -C 同様に(Unix では) inode が変更されてからの日数(それ以外の |
905 | 920 | プラットフォームでは違うかもしれません)。 |
906 | 921 | |
907 | 922 | =begin original |
908 | 923 | |
909 | 924 | Example: |
910 | 925 | |
911 | 926 | =end original |
912 | 927 | |
913 | 928 | 例: |
914 | 929 | |
915 | 930 | while (<>) { |
916 | 931 | chomp; |
917 | 932 | next unless -f $_; # ignore specials |
918 | 933 | #... |
919 | 934 | } |
920 | 935 | |
921 | 936 | =begin original |
922 | 937 | |
923 | 938 | Note that C<-s/a/b/> does not do a negated substitution. Saying |
924 | 939 | C<-exp($foo)> still works as expected, however: only single letters |
925 | 940 | following a minus are interpreted as file tests. |
926 | 941 | |
927 | 942 | =end original |
928 | 943 | |
929 | 944 | C<-s/a/b> は、置換演算 (s///) の符号反転ではありません。 |
930 | 945 | しかし、C<-exp($foo)> は期待どおりに動作します; しかし、マイナス記号の後に |
931 | 946 | 英字が 1 字続くときにのみ、ファイルテストと解釈されます。 |
932 | 947 | |
933 | 948 | =begin original |
934 | 949 | |
935 | 950 | These operators are exempt from the "looks like a function rule" described |
936 | 951 | above. That is, an opening parenthesis after the operator does not affect |
937 | 952 | how much of the following code constitutes the argument. Put the opening |
938 | 953 | parentheses before the operator to separate it from code that follows (this |
939 | 954 | applies only to operators with higher precedence than unary operators, of |
940 | 955 | course): |
941 | 956 | |
942 | 957 | =end original |
943 | 958 | |
944 | 959 | これらの演算子は上述の「関数のように見えるルール」から免除されます。 |
945 | 960 | つまり、演算子の後の開きかっこは、引き続くコードのどこまでが引数を |
946 | 961 | 構成するかに影響を与えません。 |
947 | 962 | 演算子を引き続くコードから分離するには、演算子の前に開きかっこを |
948 | 963 | 置いてください (これはもちろん、単項演算子より高い優先順位を持つ |
949 | 964 | 演算子にのみ適用されます): |
950 | 965 | |
951 | 966 | -s($file) + 1024 # probably wrong; same as -s($file + 1024) |
952 | 967 | (-s $file) + 1024 # correct |
953 | 968 | |
954 | 969 | =begin original |
955 | 970 | |
956 | 971 | The interpretation of the file permission operators C<-r>, C<-R>, |
957 | 972 | C<-w>, C<-W>, C<-x>, and C<-X> is by default based solely on the mode |
958 | 973 | of the file and the uids and gids of the user. There may be other |
959 | 974 | reasons you can't actually read, write, or execute the file: for |
960 | 975 | example network filesystem access controls, ACLs (access control lists), |
961 | 976 | read-only filesystems, and unrecognized executable formats. Note |
962 | 977 | that the use of these six specific operators to verify if some operation |
963 | 978 | is possible is usually a mistake, because it may be open to race |
964 | 979 | conditions. |
965 | 980 | |
966 | 981 | =end original |
967 | 982 | |
968 | 983 | ファイルのパーミッション演算子 C<-r>, C<-R>, C<-w>, C<-W>, C<-x>, |
969 | 984 | C<-X> の解釈は、ファイルのモードとユーザの実効/実 uid と |
970 | 985 | 実効/実 gid のみから判断されます。 |
971 | 986 | 実際にファイルが読めたり、書けたり、実行できたりするためには、 |
972 | 987 | 別の条件が必要かもしれません: |
973 | 988 | 例えば、ネットワークファイルシステムアクセスコントロール、 |
974 | 989 | ACL(アクセスコントロールリスト)、読み込み専用ファイルシステム、 |
975 | 990 | 認識できない実行ファイルフォーマット、などです。 |
976 | 991 | これらの 6 つの演算子を、特定の操作が可能かどうかを確認するために使うのは |
977 | 992 | 通常は誤りであることに注意してください; なぜなら、これらは競合条件を |
978 | 993 | 招きやすいからです。 |
979 | 994 | |
980 | 995 | =begin original |
981 | 996 | |
982 | 997 | Also note that, for the superuser on the local filesystems, the C<-r>, |
983 | 998 | C<-R>, C<-w>, and C<-W> tests always return 1, and C<-x> and C<-X> return 1 |
984 | 999 | if any execute bit is set in the mode. Scripts run by the superuser |
985 | 1000 | may thus need to do a L<C<stat>|/stat FILEHANDLE> to determine the |
986 | 1001 | actual mode of the file, or temporarily set their effective uid to |
987 | 1002 | something else. |
988 | 1003 | |
989 | 1004 | =end original |
990 | 1005 | |
991 | 1006 | ローカルファイルシステムのスーパーユーザには、 |
992 | 1007 | C<-r>, C<-R>, C<-w>, C<-W> に対して、常に 1 が返り、モード中の |
993 | 1008 | いずれかの実行許可ビットが立っていれば、C<-x>, C<-X> にも 1 が |
994 | 1009 | 返ることにも注意してください。 |
995 | 1010 | スーパーユーザが実行するスクリプトでは、ファイルのモードを調べるためには、 |
996 | 1011 | L<C<stat>|/stat FILEHANDLE> を行なうか、実効 uid を一時的に別のものにする |
997 | 1012 | 必要があるでしょう。 |
998 | 1013 | |
999 | 1014 | =begin original |
1000 | 1015 | |
1001 | 1016 | If you are using ACLs, there is a pragma called L<C<filetest>|filetest> |
1002 | 1017 | that may produce more accurate results than the bare |
1003 | 1018 | L<C<stat>|/stat FILEHANDLE> mode bits. |
1004 | 1019 | When under C<use filetest 'access'>, the above-mentioned filetests |
1005 | 1020 | test whether the permission can(not) be granted using the L<access(2)> |
1006 | 1021 | family of system calls. Also note that the C<-x> and C<-X> tests may |
1007 | 1022 | under this pragma return true even if there are no execute permission |
1008 | 1023 | bits set (nor any extra execute permission ACLs). This strangeness is |
1009 | 1024 | due to the underlying system calls' definitions. Note also that, due to |
1010 | 1025 | the implementation of C<use filetest 'access'>, the C<_> special |
1011 | 1026 | filehandle won't cache the results of the file tests when this pragma is |
1012 | 1027 | in effect. Read the documentation for the L<C<filetest>|filetest> |
1013 | 1028 | pragma for more information. |
1014 | 1029 | |
1015 | 1030 | =end original |
1016 | 1031 | |
1017 | 1032 | ACL を使っている場合は、生の L<C<stat>|/stat FILEHANDLE> モードビットより |
1018 | 1033 | 精度の高い結果を作成する L<C<filetest>|filetest> プラグマがあります。 |
1019 | 1034 | C<use filetest 'access'> とした場合、上述したファイルテストは |
1020 | 1035 | システムコールの L<access(2)> ファミリーを使って権限が与えられているか |
1021 | 1036 | どうかをテストします。 |
1022 | 1037 | また、このプラグマが指定されている場合、C<-x> と C<-X> テストは |
1023 | 1038 | たとえ実行許可ビット(または追加の実行許可 ACL)がセットされていない |
1024 | 1039 | 場合でも真を返すことに注意してください。 |
1025 | 1040 | この挙動は使用するシステムコールの定義によるものです。 |
1026 | 1041 | C<use filetest 'access'> の実装により、このプラグマが有効の場合は |
1027 | 1042 | C<_> 特殊ファイルハンドルはファイルテストの結果をキャッシュしないことに |
1028 | 1043 | 注意してください。 |
1029 | 1044 | さらなる情報については L<C<filetest>|filetest> プラグマのドキュメントを |
1030 | 1045 | 参照してください。 |
1031 | 1046 | |
1032 | 1047 | =begin original |
1033 | 1048 | |
1034 | 1049 | The C<-T> and C<-B> tests work as follows. The first block or so of |
1035 | 1050 | the file is examined to see if it is valid UTF-8 that includes non-ASCII |
1036 | 1051 | characters. If so, it's a C<-T> file. Otherwise, that same portion of |
1037 | 1052 | the file is examined for odd characters such as strange control codes or |
1038 | 1053 | characters with the high bit set. If more than a third of the |
1039 | 1054 | characters are strange, it's a C<-B> file; otherwise it's a C<-T> file. |
1040 | 1055 | Also, any file containing a zero byte in the examined portion is |
1041 | 1056 | considered a binary file. (If executed within the scope of a L<S<use |
1042 | 1057 | locale>|perllocale> which includes C<LC_CTYPE>, odd characters are |
1043 | 1058 | anything that isn't a printable nor space in the current locale.) If |
1044 | 1059 | C<-T> or C<-B> is used on a filehandle, the current IO buffer is |
1045 | 1060 | examined |
1046 | 1061 | rather than the first block. Both C<-T> and C<-B> return true on an empty |
1047 | 1062 | file, or a file at EOF when testing a filehandle. Because you have to |
1048 | 1063 | read a file to do the C<-T> test, on most occasions you want to use a C<-f> |
1049 | 1064 | against the file first, as in C<next unless -f $file && -T $file>. |
1050 | 1065 | |
1051 | 1066 | =end original |
1052 | 1067 | |
1053 | 1068 | ファイルテスト C<-T> と C<-B> の動作原理は、次のようになっています。 |
1054 | 1069 | ファイルの最初の数ブロックを調べて、非 ASCII 文字を含む妥当な UTF-8 かどうかを |
1055 | 1070 | 調べます。 |
1056 | 1071 | もしそうなら、それは C<-T> ファイルです。 |
1057 | 1072 | さもなければ、ファイルの同じ位置から、変わった制御コードや |
1058 | 1073 | 上位ビットがセットされているような、通常のテキストには現れない文字を探します。 |
1059 | 1074 | 三分の一以上がおかしな文字なら、それは C<-B> ファイルでです; |
1060 | 1075 | さもなければ C<-T> ファイルです。 |
1061 | 1076 | また、調べた位置にヌル文字が含まれるファイルも、バイナリファイルと |
1062 | 1077 | みなされます。 |
1063 | 1078 | (C<LC_CTYPE> を含む L<S<use locale>|perllocale> のスコープの中で実行されると、 |
1064 | 1079 | おかしな文字というのは現在のロケールで表示可能でもスペースでもないものです。) |
1065 | 1080 | C<-T> や C<-B> をファイルハンドルに対して用いると、 |
1066 | 1081 | 最初のブロックを調べる代わりに、IO バッファを調べます。 |
1067 | 1082 | 調べたファイルの中身が何もないときや、 |
1068 | 1083 | ファイルハンドルを調べたときに EOF に達して |
1069 | 1084 | いたときには、C<-T> も C<-B> も「真」を返します。 |
1070 | 1085 | C<-T> テストをするためにはファイルを読み込まないといけないので、 |
1071 | 1086 | たいていは C<next unless -f $file && -T $file> というような形で |
1072 | 1087 | まず調べたいファイルに対して C<-f> を使いたいはずです。 |
1073 | 1088 | |
1074 | 1089 | =begin original |
1075 | 1090 | |
1076 | 1091 | If any of the file tests (or either the L<C<stat>|/stat FILEHANDLE> or |
1077 | 1092 | L<C<lstat>|/lstat FILEHANDLE> operator) is given the special filehandle |
1078 | 1093 | consisting of a solitary underline, then the stat structure of the |
1079 | 1094 | previous file test (or L<C<stat>|/stat FILEHANDLE> operator) is used, |
1080 | 1095 | saving a system call. (This doesn't work with C<-t>, and you need to |
1081 | 1096 | remember that L<C<lstat>|/lstat FILEHANDLE> and C<-l> leave values in |
1082 | 1097 | the stat structure for the symbolic link, not the real file.) (Also, if |
1083 | 1098 | the stat buffer was filled by an L<C<lstat>|/lstat FILEHANDLE> call, |
1084 | 1099 | C<-T> and C<-B> will reset it with the results of C<stat _>). |
1085 | 1100 | Example: |
1086 | 1101 | |
1087 | 1102 | =end original |
1088 | 1103 | |
1089 | 1104 | どのファイルテスト (あるいは、L<C<stat>|/stat FILEHANDLE> や |
1090 | 1105 | L<C<lstat>|/lstat FILEHANDLE>) 演算子にも、 |
1091 | 1106 | 下線だけから成る特別なファイルハンドルを与えると、 |
1092 | 1107 | 前回のファイルテスト (や L<C<stat>|/stat FILEHANDLE> 演算子) の |
1093 | 1108 | stat 構造体が使われ、システムコールを省きます。 |
1094 | 1109 | (C<-t> には使えませんし、L<C<lstat>|/lstat FILEHANDLE> や C<-l> は |
1095 | 1110 | 実ファイルではなく、シンボリックリンクの情報を stat 構造体に残すことを |
1096 | 1111 | 覚えておく必要があります。) |
1097 | 1112 | (また、stat バッファが L<C<lstat>|/lstat FILEHANDLE> 呼び出しで埋まった場合、 |
1098 | 1113 | C<-T> と C<-B> の結果は C<stat _> の結果でリセットされます。 |
1099 | 1114 | 例: |
1100 | 1115 | |
1101 | 1116 | print "Can do.\n" if -r $a || -w _ || -x _; |
1102 | 1117 | |
1103 | 1118 | stat($filename); |
1104 | 1119 | print "Readable\n" if -r _; |
1105 | 1120 | print "Writable\n" if -w _; |
1106 | 1121 | print "Executable\n" if -x _; |
1107 | 1122 | print "Setuid\n" if -u _; |
1108 | 1123 | print "Setgid\n" if -g _; |
1109 | 1124 | print "Sticky\n" if -k _; |
1110 | 1125 | print "Text\n" if -T _; |
1111 | 1126 | print "Binary\n" if -B _; |
1112 | 1127 | |
1113 | 1128 | =begin original |
1114 | 1129 | |
1115 | 1130 | As of Perl 5.10.0, as a form of purely syntactic sugar, you can stack file |
1116 | 1131 | test operators, in a way that C<-f -w -x $file> is equivalent to |
1117 | 1132 | C<-x $file && -w _ && -f _>. (This is only fancy syntax: if you use |
1118 | 1133 | the return value of C<-f $file> as an argument to another filetest |
1119 | 1134 | operator, no special magic will happen.) |
1120 | 1135 | |
1121 | 1136 | =end original |
1122 | 1137 | |
1123 | 1138 | Perl 5.10.0 から、純粋にシンタックスシュガーとして、ファイルテスト演算子を |
1124 | 1139 | スタックさせることができるので、C<-f -w -x $file> は |
1125 | 1140 | C<-x $file && -w _ && -f _> と等価です。 |
1126 | 1141 | (これは文法上だけの話です; もし C<-f $file> の返り値を他のファイルテスト |
1127 | 1142 | 演算子の引数として使う場合は、何の特別なことも起きません。) |
1128 | 1143 | |
1129 | 1144 | =begin original |
1130 | 1145 | |
1131 | 1146 | Portability issues: L<perlport/-X>. |
1132 | 1147 | |
1133 | 1148 | =end original |
1134 | 1149 | |
1135 | 1150 | 移植性の問題: L<perlport/-X>。 |
1136 | 1151 | |
1137 | 1152 | =begin original |
1138 | 1153 | |
1139 | 1154 | To avoid confusing would-be users of your code with mysterious |
1140 | 1155 | syntax errors, put something like this at the top of your script: |
1141 | 1156 | |
1142 | 1157 | =end original |
1143 | 1158 | |
1144 | 1159 | あなたのコードのユーザーが不思議な文法エラーで混乱することを |
1145 | 1160 | 避けるために、スクリプトの先頭に以下のようなことを書いてください: |
1146 | 1161 | |
1147 | 1162 | use 5.010; # so filetest ops can stack |
1148 | 1163 | |
1149 | 1164 | =item abs VALUE |
1150 | 1165 | X<abs> X<absolute> |
1151 | 1166 | |
1152 | 1167 | =item abs |
1153 | 1168 | |
1154 | 1169 | =for Pod::Functions absolute value function |
1155 | 1170 | |
1156 | 1171 | =begin original |
1157 | 1172 | |
1158 | 1173 | Returns the absolute value of its argument. |
1159 | 1174 | If VALUE is omitted, uses L<C<$_>|perlvar/$_>. |
1160 | 1175 | |
1161 | 1176 | =end original |
1162 | 1177 | |
1163 | 1178 | 引数の絶対値を返します。 |
1164 | 1179 | VALUE が省略された場合は、L<C<$_>|perlvar/$_> を使います。 |
1165 | 1180 | |
1166 | 1181 | =item accept NEWSOCKET,GENERICSOCKET |
1167 | 1182 | X<accept> |
1168 | 1183 | |
1169 | 1184 | =for Pod::Functions accept an incoming socket connect |
1170 | 1185 | |
1171 | 1186 | =begin original |
1172 | 1187 | |
1173 | 1188 | Accepts an incoming socket connect, just as L<accept(2)> |
1174 | 1189 | does. Returns the packed address if it succeeded, false otherwise. |
1175 | 1190 | See the example in L<perlipc/"Sockets: Client/Server Communication">. |
1176 | 1191 | |
1177 | 1192 | =end original |
1178 | 1193 | |
1179 | 1194 | L<accept(2)> システムコールと同様に、着信するソケットの接続を受け付けます。 |
1180 | 1195 | 成功時にはパックされたアドレスを返し、失敗すれば偽を返します。 |
1181 | 1196 | L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。 |
1182 | 1197 | |
1183 | 1198 | =begin original |
1184 | 1199 | |
1185 | 1200 | On systems that support a close-on-exec flag on files, the flag will |
1186 | 1201 | be set for the newly opened file descriptor, as determined by the |
1187 | 1202 | value of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>. |
1188 | 1203 | |
1189 | 1204 | =end original |
1190 | 1205 | |
1191 | 1206 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
1192 | 1207 | フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた |
1193 | 1208 | ファイル記述子に対してセットされます。 |
1194 | 1209 | L<perlvar/$^F> を参照してください。 |
1195 | 1210 | |
1196 | 1211 | =item alarm SECONDS |
1197 | 1212 | X<alarm> |
1198 | 1213 | X<SIGALRM> |
1199 | 1214 | X<timer> |
1200 | 1215 | |
1201 | 1216 | =item alarm |
1202 | 1217 | |
1203 | 1218 | =for Pod::Functions schedule a SIGALRM |
1204 | 1219 | |
1205 | 1220 | =begin original |
1206 | 1221 | |
1207 | 1222 | Arranges to have a SIGALRM delivered to this process after the |
1208 | 1223 | specified number of wallclock seconds has elapsed. If SECONDS is not |
1209 | 1224 | specified, the value stored in L<C<$_>|perlvar/$_> is used. (On some |
1210 | 1225 | machines, unfortunately, the elapsed time may be up to one second less |
1211 | 1226 | or more than you specified because of how seconds are counted, and |
1212 | 1227 | process scheduling may delay the delivery of the signal even further.) |
1213 | 1228 | |
1214 | 1229 | =end original |
1215 | 1230 | |
1216 | 1231 | 指定した壁時計秒数が経過した後に、自プロセスに SIGALRM が |
1217 | 1232 | 送られてくるようにします。 |
1218 | 1233 | SECONDS が指定されていない場合は、L<C<$_>|perlvar/$_> に格納されている値を |
1219 | 1234 | 使います。 |
1220 | 1235 | (マシンによっては、秒の数え方が異なるため、指定した秒数よりも最大で |
1221 | 1236 | 1 秒ずれます。) |
1222 | 1237 | |
1223 | 1238 | =begin original |
1224 | 1239 | |
1225 | 1240 | Only one timer may be counting at once. Each call disables the |
1226 | 1241 | previous timer, and an argument of C<0> may be supplied to cancel the |
1227 | 1242 | previous timer without starting a new one. The returned value is the |
1228 | 1243 | amount of time remaining on the previous timer. |
1229 | 1244 | |
1230 | 1245 | =end original |
1231 | 1246 | |
1232 | 1247 | 一度には一つのタイマだけが設定可能です。 |
1233 | 1248 | 呼び出しを行なう度に、以前のタイマを無効にしますし、 |
1234 | 1249 | 新しくタイマを起動しないで以前のタイマをキャンセルするために |
1235 | 1250 | 引数に C<0> を指定して呼び出すことができます。 |
1236 | 1251 | 以前のタイマの残り時間が、返り値となります。 |
1237 | 1252 | |
1238 | 1253 | =begin original |
1239 | 1254 | |
1240 | 1255 | For delays of finer granularity than one second, the L<Time::HiRes> module |
1241 | 1256 | (from CPAN, and starting from Perl 5.8 part of the standard |
1242 | 1257 | distribution) provides |
1243 | 1258 | L<C<ualarm>|Time::HiRes/ualarm ( $useconds [, $interval_useconds ] )>. |
1244 | 1259 | You may also use Perl's four-argument version of |
1245 | 1260 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> leaving the first three |
1246 | 1261 | arguments undefined, or you might be able to use the |
1247 | 1262 | L<C<syscall>|/syscall NUMBER, LIST> interface to access L<setitimer(2)> |
1248 | 1263 | if your system supports it. See L<perlfaq8> for details. |
1249 | 1264 | |
1250 | 1265 | =end original |
1251 | 1266 | |
1252 | 1267 | 1 秒より精度の高いスリープを行なうには、L<Time::HiRes> モジュール(CPAN から、 |
1253 | 1268 | また Perl 5.8 からは標準配布されています) が |
1254 | 1269 | L<C<usleep>|Time::HiRes/usleep ( $useconds )> を提供します。 |
1255 | 1270 | Perl の 4 引数版 L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を最初の |
1256 | 1271 | 3 引数を未定義にして使うか、L<setitimer(2)> をサポートしているシステムでは、 |
1257 | 1272 | Perl の L<C<syscall>|/syscall NUMBER, LIST> インタフェースを使って |
1258 | 1273 | アクセスすることもできます。 |
1259 | 1274 | 詳しくは L<perlfaq8> を参照してください。 |
1260 | 1275 | |
1261 | 1276 | =begin original |
1262 | 1277 | |
1263 | 1278 | It is usually a mistake to intermix L<C<alarm>|/alarm SECONDS> and |
1264 | 1279 | L<C<sleep>|/sleep EXPR> calls, because L<C<sleep>|/sleep EXPR> may be |
1265 | 1280 | internally implemented on your system with L<C<alarm>|/alarm SECONDS>. |
1266 | 1281 | |
1267 | 1282 | =end original |
1268 | 1283 | |
1269 | 1284 | L<C<alarm>|/alarm SECONDS> と L<C<sleep>|/sleep EXPR> を混ぜて使うのは |
1270 | 1285 | 普通は間違いです; なぜなら、L<C<sleep>|/sleep EXPR> は内部的に |
1271 | 1286 | L<C<alarm>|/alarm SECONDS> を使って内部的に実装されているかも |
1272 | 1287 | しれないからです。 |
1273 | 1288 | |
1274 | 1289 | =begin original |
1275 | 1290 | |
1276 | 1291 | If you want to use L<C<alarm>|/alarm SECONDS> to time out a system call |
1277 | 1292 | you need to use an L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> pair. You |
1278 | 1293 | can't rely on the alarm causing the system call to fail with |
1279 | 1294 | L<C<$!>|perlvar/$!> set to C<EINTR> because Perl sets up signal handlers |
1280 | 1295 | to restart system calls on some systems. Using |
1281 | 1296 | L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> always works, modulo the |
1282 | 1297 | caveats given in L<perlipc/"Signals">. |
1283 | 1298 | |
1284 | 1299 | =end original |
1285 | 1300 | |
1286 | 1301 | L<C<alarm>|/alarm SECONDS> をシステムコールの時間切れのために使いたいなら、 |
1287 | 1302 | L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> のペアで使う必要があります。 |
1288 | 1303 | システムコールが失敗したときに L<C<$!>|perlvar/$!> に C<EINTR> が |
1289 | 1304 | セットされることに頼ってはいけません; なぜならシステムによっては Perl は |
1290 | 1305 | システムコールを再開するためにシグナルハンドラを設定するからです。 |
1291 | 1306 | L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> は常にうまく動きます; |
1292 | 1307 | 注意点については L<perlipc/"Signals"> を参照してください。 |
1293 | 1308 | |
1294 | 1309 | eval { |
1295 | 1310 | local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required |
1296 | 1311 | alarm $timeout; |
1297 | 1312 | my $nread = sysread $socket, $buffer, $size; |
1298 | 1313 | alarm 0; |
1299 | 1314 | }; |
1300 | 1315 | if ($@) { |
1301 | 1316 | die unless $@ eq "alarm\n"; # propagate unexpected errors |
1302 | 1317 | # timed out |
1303 | 1318 | } |
1304 | 1319 | else { |
1305 | 1320 | # didn't |
1306 | 1321 | } |
1307 | 1322 | |
1308 | 1323 | =begin original |
1309 | 1324 | |
1310 | 1325 | For more information see L<perlipc>. |
1311 | 1326 | |
1312 | 1327 | =end original |
1313 | 1328 | |
1314 | 1329 | さらなる情報については L<perlipc> を参照してください。 |
1315 | 1330 | |
1316 | 1331 | =begin original |
1317 | 1332 | |
1318 | 1333 | Portability issues: L<perlport/alarm>. |
1319 | 1334 | |
1320 | 1335 | =end original |
1321 | 1336 | |
1322 | 1337 | 移植性の問題: L<perlport/alarm>。 |
1323 | 1338 | |
1324 | 1339 | =item atan2 Y,X |
1325 | 1340 | X<atan2> X<arctangent> X<tan> X<tangent> |
1326 | 1341 | |
1327 | 1342 | =for Pod::Functions arctangent of Y/X in the range -PI to PI |
1328 | 1343 | |
1329 | 1344 | =begin original |
1330 | 1345 | |
1331 | 1346 | Returns the arctangent of Y/X in the range -PI to PI. |
1332 | 1347 | |
1333 | 1348 | =end original |
1334 | 1349 | |
1335 | 1350 | -πからπの範囲で Y/X の逆正接を返します。 |
1336 | 1351 | |
1337 | 1352 | =begin original |
1338 | 1353 | |
1339 | 1354 | For the tangent operation, you may use the |
1340 | 1355 | L<C<Math::Trig::tan>|Math::Trig/B<tan>> function, or use the familiar |
1341 | 1356 | relation: |
1342 | 1357 | |
1343 | 1358 | =end original |
1344 | 1359 | |
1345 | 1360 | 正接を求めたいときは、L<C<Math::Trig::tan>|Math::Trig/B<tan>> を使うか、 |
1346 | 1361 | 以下のよく知られた関係を使ってください。 |
1347 | 1362 | |
1348 | 1363 | sub tan { sin($_[0]) / cos($_[0]) } |
1349 | 1364 | |
1350 | 1365 | =begin original |
1351 | 1366 | |
1352 | 1367 | The return value for C<atan2(0,0)> is implementation-defined; consult |
1353 | 1368 | your L<atan2(3)> manpage for more information. |
1354 | 1369 | |
1355 | 1370 | =end original |
1356 | 1371 | |
1357 | 1372 | C<atan2(0,0)> の返り値は実装依存です; さらなる情報については |
1358 | 1373 | L<atan2(3)> man ページを参照してください。 |
1359 | 1374 | |
1360 | 1375 | =begin original |
1361 | 1376 | |
1362 | 1377 | Portability issues: L<perlport/atan2>. |
1363 | 1378 | |
1364 | 1379 | =end original |
1365 | 1380 | |
1366 | 1381 | 移植性の問題: L<perlport/atan2>。 |
1367 | 1382 | |
1368 | 1383 | =item bind SOCKET,NAME |
1369 | 1384 | X<bind> |
1370 | 1385 | |
1371 | 1386 | =for Pod::Functions binds an address to a socket |
1372 | 1387 | |
1373 | 1388 | =begin original |
1374 | 1389 | |
1375 | 1390 | Binds a network address to a socket, just as L<bind(2)> |
1376 | 1391 | does. Returns true if it succeeded, false otherwise. NAME should be a |
1377 | 1392 | packed address of the appropriate type for the socket. See the examples in |
1378 | 1393 | L<perlipc/"Sockets: Client/Server Communication">. |
1379 | 1394 | |
1380 | 1395 | =end original |
1381 | 1396 | |
1382 | 1397 | L<bind(2)> システムコールと同様に、ネットワークアドレスをソケットに |
1383 | 1398 | 結び付けます。 |
1384 | 1399 | 成功時には真を、さもなければ偽を返します。 |
1385 | 1400 | NAME は、ソケットに対する、適切な型のパックされた |
1386 | 1401 | アドレスでなければなりません。 |
1387 | 1402 | L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。 |
1388 | 1403 | |
1389 | 1404 | =item binmode FILEHANDLE, LAYER |
1390 | 1405 | X<binmode> X<binary> X<text> X<DOS> X<Windows> |
1391 | 1406 | |
1392 | 1407 | =item binmode FILEHANDLE |
1393 | 1408 | |
1394 | 1409 | =for Pod::Functions prepare binary files for I/O |
1395 | 1410 | |
1396 | 1411 | =begin original |
1397 | 1412 | |
1398 | 1413 | Arranges for FILEHANDLE to be read or written in "binary" or "text" |
1399 | 1414 | mode on systems where the run-time libraries distinguish between |
1400 | 1415 | binary and text files. If FILEHANDLE is an expression, the value is |
1401 | 1416 | taken as the name of the filehandle. Returns true on success, |
1402 | 1417 | otherwise it returns L<C<undef>|/undef EXPR> and sets |
1403 | 1418 | L<C<$!>|perlvar/$!> (errno). |
1404 | 1419 | |
1405 | 1420 | =end original |
1406 | 1421 | |
1407 | 1422 | バイナリファイルとテキストファイルを区別する OS において、 |
1408 | 1423 | FILEHANDLE を「バイナリ」または「テキスト」で読み書きするように |
1409 | 1424 | 指定します。 |
1410 | 1425 | FILEHANDLE が式である場合には、その式の値がファイルハンドルの |
1411 | 1426 | 名前として使われます。 |
1412 | 1427 | 成功時には真を返し、失敗時には L<C<undef>|/undef EXPR> を返して |
1413 | 1428 | L<C<$!>|perlvar/$!> (errno) を設定します。 |
1414 | 1429 | |
1415 | 1430 | =begin original |
1416 | 1431 | |
1417 | 1432 | On some systems (in general, DOS- and Windows-based systems) |
1418 | 1433 | L<C<binmode>|/binmode FILEHANDLE, LAYER> is necessary when you're not |
1419 | 1434 | working with a text file. For the sake of portability it is a good idea |
1420 | 1435 | always to use it when appropriate, and never to use it when it isn't |
1421 | 1436 | appropriate. Also, people can set their I/O to be by default |
1422 | 1437 | UTF8-encoded Unicode, not bytes. |
1423 | 1438 | |
1424 | 1439 | =end original |
1425 | 1440 | |
1426 | 1441 | テキストファイルでないものを扱う場合に |
1427 | 1442 | L<C<binmode>|/binmode FILEHANDLE, LAYER> が必要な |
1428 | 1443 | システムもあります(一般的には DOS と Windows ベースのシステムです)。 |
1429 | 1444 | 移植性のために、適切なときには常にこれを使い、適切でないときには |
1430 | 1445 | 決して使わないというのは良い考えです。 |
1431 | 1446 | また、デフォルトとして I/O を bytes ではなく UTF-8 エンコードされた |
1432 | 1447 | Unicode にセットすることも出来ます。 |
1433 | 1448 | |
1434 | 1449 | =begin original |
1435 | 1450 | |
1436 | 1451 | In other words: regardless of platform, use |
1437 | 1452 | L<C<binmode>|/binmode FILEHANDLE, LAYER> on binary data, like images, |
1438 | 1453 | for example. |
1439 | 1454 | |
1440 | 1455 | =end original |
1441 | 1456 | |
1442 | 1457 | 言い換えると: プラットフォームに関わらず、 |
1443 | 1458 | 例えばイメージのようなバイナリファイルに対しては |
1444 | 1459 | L<C<binmode>|/binmode FILEHANDLE, LAYER> を使ってください。 |
1445 | 1460 | |
1446 | 1461 | =begin original |
1447 | 1462 | |
1448 | 1463 | If LAYER is present it is a single string, but may contain multiple |
1449 | 1464 | directives. The directives alter the behaviour of the filehandle. |
1450 | 1465 | When LAYER is present, using binmode on a text file makes sense. |
1451 | 1466 | |
1452 | 1467 | =end original |
1453 | 1468 | |
1454 | 1469 | LAYER が存在すると、それは単一の文字列ですが、複数の指示子を |
1455 | 1470 | 含むことができます。 |
1456 | 1471 | 指示子はファイルハンドルの振る舞いを変更します。 |
1457 | 1472 | LAYER が存在すると、テキストファイルでの binmode が意味を持ちます。 |
1458 | 1473 | |
1459 | 1474 | =begin original |
1460 | 1475 | |
1461 | 1476 | If LAYER is omitted or specified as C<:raw> the filehandle is made |
1462 | 1477 | suitable for passing binary data. This includes turning off possible CRLF |
1463 | 1478 | translation and marking it as bytes (as opposed to Unicode characters). |
1464 | 1479 | Note that, despite what may be implied in I<"Programming Perl"> (the |
1465 | 1480 | Camel, 3rd edition) or elsewhere, C<:raw> is I<not> simply the inverse of C<:crlf>. |
1466 | 1481 | Other layers that would affect the binary nature of the stream are |
1467 | I<also> disabled. See L<PerlIO>, | |
1482 | I<also> disabled. See L<PerlIO>, and the discussion about the PERLIO | |
1468 | ||
1483 | environment variable in L<perlrun|perlrun/PERLIO>. | |
1469 | 1484 | |
1470 | 1485 | =end original |
1471 | 1486 | |
1472 | 1487 | LAYER が省略されたり、C<:raw> が指定されると、ファイルハンドルはバイナリ |
1473 | 1488 | データの通過に適するように設定されます。 |
1474 | 1489 | これには CRLF 変換をオフにしたり、それぞれを(Unicode 文字ではなく) |
1475 | 1490 | バイトであるとマークしたりすることを含みます。 |
1476 | 1491 | I<"プログラミング Perl">(ラクダ本第三版) やその他で暗示されているにも関わらず、 |
1477 | 1492 | C<:raw> は単なる C<:crlf> の I<逆ではありません>。 |
1478 | 1493 | ストリームのバイナリとしての性質に影響を与える |
1479 | 1494 | I<その他の層も無効にされます>。 |
1480 | L<PerlIO>, L<perlrun> | |
1495 | L<PerlIO>, および L<perlrun|perlrun/PERLIO> の PERLIO 環境変数に関する議論を | |
1496 | 参照してください。 | |
1481 | 1497 | |
1482 | 1498 | =begin original |
1483 | 1499 | |
1484 | 1500 | The C<:bytes>, C<:crlf>, C<:utf8>, and any other directives of the |
1485 | 1501 | form C<:...>, are called I/O I<layers>. The L<open> pragma can be used to |
1486 | 1502 | establish default I/O layers. |
1487 | 1503 | |
1488 | 1504 | =end original |
1489 | 1505 | |
1490 | 1506 | C<:bytes>, C<:crlf>, and C<:utf8>, 及びその他の C<:...> 形式の指示子は |
1491 | 1507 | I/O I<層> が呼び出されます。 |
1492 | 1508 | L<open> プラグマはデフォルト I/O 層を指定するために使われます。 |
1493 | 1509 | |
1494 | 1510 | =begin original |
1495 | 1511 | |
1496 | 1512 | I<The LAYER parameter of the L<C<binmode>|/binmode FILEHANDLE, LAYER> |
1497 | 1513 | function is described as "DISCIPLINE" in "Programming Perl, 3rd |
1498 | 1514 | Edition". However, since the publishing of this book, by many known as |
1499 | 1515 | "Camel III", the consensus of the naming of this functionality has moved |
1500 | 1516 | from "discipline" to "layer". All documentation of this version of Perl |
1501 | 1517 | therefore refers to "layers" rather than to "disciplines". Now back to |
1502 | 1518 | the regularly scheduled documentation...> |
1503 | 1519 | |
1504 | 1520 | =end original |
1505 | 1521 | |
1506 | 1522 | I<L<C<binmode>|/binmode FILEHANDLE, LAYER> 関数の LAYER パラメータは |
1507 | 1523 | 「プログラミングPerl 第 3 版」では |
1508 | 1524 | 「ディシプリン(DISCIPLINE)」と表現されていました。 |
1509 | 1525 | しかし、「ラクダ本第 3 版」として知られているこの本の出版後、この機能の名前は |
1510 | 1526 | 「ディシプリン」から「層」に変更することで合意されました。 |
1511 | 1527 | 従って、このバージョンの Perl の全ての文書では「ディシプリン」ではなく |
1512 | 1528 | 「層」と記述されています。では通常の解説に戻ります…> |
1513 | 1529 | |
1514 | 1530 | =begin original |
1515 | 1531 | |
1516 | 1532 | To mark FILEHANDLE as UTF-8, use C<:utf8> or C<:encoding(UTF-8)>. |
1517 | 1533 | C<:utf8> just marks the data as UTF-8 without further checking, |
1518 | 1534 | while C<:encoding(UTF-8)> checks the data for actually being valid |
1519 | 1535 | UTF-8. More details can be found in L<PerlIO::encoding>. |
1520 | 1536 | |
1521 | 1537 | =end original |
1522 | 1538 | |
1523 | 1539 | FILEHANDLE が UTF-8 であるというマークをつけるには、C<:utf8> か |
1524 | 1540 | C<:encoding(UTF-8)> を使ってください。 |
1525 | 1541 | C<:utf8> は、さらなるチェックなしにデータが UTF-8 としてマークしますが、 |
1526 | 1542 | C<:encoding(UTF-8)> はデータが実際に有効な UTF-8 かどうかをチェックします。 |
1527 | 1543 | さらなる詳細は L<PerlIO::encoding> にあります。 |
1528 | 1544 | |
1529 | 1545 | =begin original |
1530 | 1546 | |
1531 | 1547 | In general, L<C<binmode>|/binmode FILEHANDLE, LAYER> should be called |
1532 | after L<C<open>|/open FILEHANDLE,EXPR> but before any I/O is done on the | |
1548 | after L<C<open>|/open FILEHANDLE,MODE,EXPR> but before any I/O is done on the | |
1533 | 1549 | filehandle. Calling L<C<binmode>|/binmode FILEHANDLE, LAYER> normally |
1534 | 1550 | flushes any pending buffered output data (and perhaps pending input |
1535 | 1551 | data) on the handle. An exception to this is the C<:encoding> layer |
1536 | 1552 | that changes the default character encoding of the handle. |
1537 | 1553 | The C<:encoding> layer sometimes needs to be called in |
1538 | 1554 | mid-stream, and it doesn't flush the stream. C<:encoding> |
1539 | 1555 | also implicitly pushes on top of itself the C<:utf8> layer because |
1540 | 1556 | internally Perl operates on UTF8-encoded Unicode characters. |
1541 | 1557 | |
1542 | 1558 | =end original |
1543 | 1559 | |
1544 | 1560 | 一般的に L<C<binmode>|/binmode FILEHANDLE, LAYER> は |
1545 | L<C<open>|/open FILEHANDLE,EXPR> を呼び出した後、このファイルハンドルに | |
1561 | L<C<open>|/open FILEHANDLE,MODE,EXPR> を呼び出した後、このファイルハンドルに | |
1546 | I/O 操作をする前に呼び出すべきです。 | |
1562 | 対するI/O 操作をする前に呼び出すべきです。 | |
1547 | 1563 | L<C<binmode>|/binmode FILEHANDLE, LAYER> を呼び出すと、普通はこの |
1548 | 1564 | ファイルハンドルに対してバッファリングされている全ての出力データ |
1549 | 1565 | (およびおそらくは入力データ)をフラッシュします。 |
1550 | 1566 | 例外は、このハンドルに対するデフォルト文字エンコーディングを変更する |
1551 | 1567 | C<:encoding> 層です。 |
1552 | 1568 | C<:encoding> 層はストリームの途中で呼び出す必要があることがあり、 |
1553 | 1569 | それによってストリームはフラッシュされません。 |
1554 | 1570 | Perl は内部で UTF-8 エンコードされた Unicode 文字を操作しているので、 |
1555 | 1571 | C<:encoding> は暗黙のうちに自身を C<:utf8> 層の上に押し上げます。 |
1556 | 1572 | |
1557 | 1573 | =begin original |
1558 | 1574 | |
1559 | 1575 | The operating system, device drivers, C libraries, and Perl run-time |
1560 | 1576 | system all conspire to let the programmer treat a single |
1561 | 1577 | character (C<\n>) as the line terminator, irrespective of external |
1562 | 1578 | representation. On many operating systems, the native text file |
1563 | 1579 | representation matches the internal representation, but on some |
1564 | 1580 | platforms the external representation of C<\n> is made up of more than |
1565 | 1581 | one character. |
1566 | 1582 | |
1567 | 1583 | =end original |
1568 | 1584 | |
1569 | 1585 | オペレーティングシステム、デバイスドライバ、C ライブラリ、 |
1570 | 1586 | Perl ランタイムシステムは全て、プログラマが外部表現に関わらず |
1571 | 1587 | 1 文字 (C<\n>) を行終端として扱えるように協調作業します。 |
1572 | 1588 | 多くのオペレーティングシステムでは、ネイティブテキストファイル表現は |
1573 | 1589 | 内部表現と同じですが、C<\n> の外部表現が複数文字になる |
1574 | 1590 | プラットフォームもあります。 |
1575 | 1591 | |
1576 | 1592 | =begin original |
1577 | 1593 | |
1578 | 1594 | All variants of Unix, Mac OS (old and new), and Stream_LF files on VMS use |
1579 | 1595 | a single character to end each line in the external representation of text |
1580 | 1596 | (even though that single character is CARRIAGE RETURN on old, pre-Darwin |
1581 | 1597 | flavors of Mac OS, and is LINE FEED on Unix and most VMS files). In other |
1582 | 1598 | systems like OS/2, DOS, and the various flavors of MS-Windows, your program |
1583 | 1599 | sees a C<\n> as a simple C<\cJ>, but what's stored in text files are the |
1584 | 1600 | two characters C<\cM\cJ>. That means that if you don't use |
1585 | 1601 | L<C<binmode>|/binmode FILEHANDLE, LAYER> on these systems, C<\cM\cJ> |
1586 | 1602 | sequences on disk will be converted to C<\n> on input, and any C<\n> in |
1587 | 1603 | your program will be converted back to C<\cM\cJ> on output. This is |
1588 | 1604 | what you want for text files, but it can be disastrous for binary files. |
1589 | 1605 | |
1590 | 1606 | =end original |
1591 | 1607 | |
1592 | 1608 | 全ての Unix 系、(新旧の)Mac OS、VMS の Stream_LF ファイルは |
1593 | 1609 | テキストの外部表現として各行の末尾に一つの文字を |
1594 | 1610 | 使っています(しかしその文字は古い Darwin 以前の Mac OS では復帰で、 |
1595 | 1611 | Unix とほとんどのVMS のファイルでは改行です)。 |
1596 | 1612 | VMS, MS-DOS, MS-Windows 系といったその他のシステムでは、 |
1597 | 1613 | プログラムからは C<\n> は単純に C<\cJ> に見えますが、 |
1598 | 1614 | テキストファイルとして保存される場合は C<\cM\cJ> の 2 文字になります。 |
1599 | 1615 | つまり、もしこれらのシステムで L<C<binmode>|/binmode FILEHANDLE, LAYER> を |
1600 | 1616 | 使わないと、ディスク上の C<\cM\cJ> という並びは入力時に C<\n> に変換され、 |
1601 | 1617 | プログラムが出力した全ての C<\n> は C<\cM\cJ> に逆変換されます。 |
1602 | 1618 | これはテキストファイルの場合は思い通りの結果でしょうが、 |
1603 | 1619 | バイナリファイルの場合は悲惨です。 |
1604 | 1620 | |
1605 | 1621 | =begin original |
1606 | 1622 | |
1607 | 1623 | Another consequence of using L<C<binmode>|/binmode FILEHANDLE, LAYER> |
1608 | 1624 | (on some systems) is that special end-of-file markers will be seen as |
1609 | 1625 | part of the data stream. For systems from the Microsoft family this |
1610 | 1626 | means that, if your binary data contain C<\cZ>, the I/O subsystem will |
1611 | 1627 | regard it as the end of the file, unless you use |
1612 | 1628 | L<C<binmode>|/binmode FILEHANDLE, LAYER>. |
1613 | 1629 | |
1614 | 1630 | =end original |
1615 | 1631 | |
1616 | 1632 | L<C<binmode>|/binmode FILEHANDLE, LAYER> を(いくつかのシステムで) |
1617 | 1633 | 使うことによるその他の作用としては、特別なファイル終端マーカーが |
1618 | 1634 | データストリームの一部として見られることです。 |
1619 | 1635 | Microsoft ファミリーのシステムでは、 |
1620 | 1636 | L<C<binmode>|/binmode FILEHANDLE, LAYER> を使っていないと、 |
1621 | 1637 | もしバイナリデータに C<\cZ> が含まれていたときに、 |
1622 | 1638 | I/O サブシステムがこれをファイル終端とみなすことを意味します。 |
1623 | 1639 | |
1624 | 1640 | =begin original |
1625 | 1641 | |
1626 | 1642 | L<C<binmode>|/binmode FILEHANDLE, LAYER> is important not only for |
1627 | 1643 | L<C<readline>|/readline EXPR> and L<C<print>|/print FILEHANDLE LIST> |
1628 | 1644 | operations, but also when using |
1629 | 1645 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>, |
1630 | 1646 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, |
1631 | 1647 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, |
1632 | 1648 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> and |
1633 | 1649 | L<C<tell>|/tell FILEHANDLE> (see L<perlport> for more details). See the |
1634 | 1650 | L<C<$E<sol>>|perlvar/$E<sol>> and L<C<$\>|perlvar/$\> variables in |
1635 | 1651 | L<perlvar> for how to manually set your input and output |
1636 | 1652 | line-termination sequences. |
1637 | 1653 | |
1638 | 1654 | =end original |
1639 | 1655 | |
1640 | 1656 | L<C<binmode>|/binmode FILEHANDLE, LAYER> は L<C<readline>|/readline EXPR> と |
1641 | 1657 | L<C<print>|/print FILEHANDLE LIST> 操作にだけではなく、 |
1642 | 1658 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>, |
1643 | 1659 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, |
1644 | 1660 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, |
1645 | 1661 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, |
1646 | 1662 | L<C<tell>|/tell FILEHANDLE> を使うときにも重要です |
1647 | 1663 | (詳細は L<perlport> を参照してください)。 |
1648 | 1664 | 入出力の行端末シーケンスを手動でセットする方法については |
1649 | 1665 | L<perlvar> の L<C<$E<sol>>|perlvar/$E<sol>> 変数と |
1650 | 1666 | L<C<$\>|perlvar/$\> 変数を参照してください。 |
1651 | 1667 | |
1652 | 1668 | =begin original |
1653 | 1669 | |
1654 | 1670 | Portability issues: L<perlport/binmode>. |
1655 | 1671 | |
1656 | 1672 | =end original |
1657 | 1673 | |
1658 | 1674 | 移植性の問題: L<perlport/binmode>。 |
1659 | 1675 | |
1660 | 1676 | =item bless REF,CLASSNAME |
1661 | 1677 | X<bless> |
1662 | 1678 | |
1663 | 1679 | =item bless REF |
1664 | 1680 | |
1665 | 1681 | =for Pod::Functions create an object |
1666 | 1682 | |
1667 | 1683 | =begin original |
1668 | 1684 | |
1669 | 1685 | This function tells the thingy referenced by REF that it is now an object |
1670 | in the CLASSNAME package. If CLASSNAME is | |
1686 | in the CLASSNAME package. If CLASSNAME is an empty string, it is | |
1687 | interpreted as referring to the C<main> package. | |
1688 | If CLASSNAME is omitted, the current package | |
1671 | 1689 | is used. Because a L<C<bless>|/bless REF,CLASSNAME> is often the last |
1672 | 1690 | thing in a constructor, it returns the reference for convenience. |
1673 | 1691 | Always use the two-argument version if a derived class might inherit the |
1674 | 1692 | method doing the blessing. See L<perlobj> for more about the blessing |
1675 | 1693 | (and blessings) of objects. |
1676 | 1694 | |
1677 | 1695 | =end original |
1678 | 1696 | |
1679 | 1697 | この関数は、REF で渡された オブジェクトに対し、 |
1680 | 1698 | CLASSNAME 内のオブジェクトとなったことを伝えます。 |
1699 | CLASSNAME が空文字列の場合、C<main> パッケージを参照しているものと | |
1700 | 解釈されます。 | |
1681 | 1701 | CLASSNAME が省略された場合には、その時点のパッケージとなります。 |
1682 | 1702 | L<C<bless>|/bless REF,CLASSNAME> は通常、コンストラクタの最後に |
1683 | 1703 | 置かれますので、簡便のためにそのリファレンスを返します。 |
1684 | 1704 | 派生クラスが bless されるメソッドを継承する場合は、 |
1685 | 1705 | 常に 2 引数版を使ってください。 |
1686 | 1706 | オブジェクトの bless (や再 bless) について、詳しくは と L<perlobj> を |
1687 | 1707 | 参照してください。 |
1688 | 1708 | |
1689 | 1709 | =begin original |
1690 | 1710 | |
1691 | 1711 | Consider always blessing objects in CLASSNAMEs that are mixed case. |
1692 | 1712 | Namespaces with all lowercase names are considered reserved for |
1693 | 1713 | Perl pragmas. Builtin types have all uppercase names. To prevent |
1694 | confusion, you may wish to avoid such package names as well. | |
1714 | confusion, you may wish to avoid such package names as well. | |
1695 | t | |
1715 | It is advised to avoid the class name C<0>, because much code erroneously | |
1716 | uses the result of L<C<ref>|/ref EXPR> as a truth value. | |
1696 | 1717 | |
1697 | 1718 | =end original |
1698 | 1719 | |
1699 | 1720 | 大文字小文字が混じっている CLASSNAME のオブジェクトは常に bless することを |
1700 | 1721 | 考慮してください。 |
1701 | 1722 | 全て小文字の名前を持つ名前空間は Perl プラグマのために予約されています。 |
1702 | 1723 | 組み込みの型は全て大文字の名前を持ちます。 |
1703 | 1724 | 混乱を避けるために、 |
1704 | 1725 | パッケージ名としてこのような名前は避けるべきです。 |
1705 | 1726 | CLASSNAME は真の値を持つようにしてください。 |
1727 | クラス名として C<0> は避けてください; 多くのコードが誤って | |
1728 | L<C<ref>|/ref EXPR> の結果を真の値として使っているからです。 | |
1706 | 1729 | |
1707 | 1730 | =begin original |
1708 | 1731 | |
1709 | 1732 | See L<perlmod/"Perl Modules">. |
1710 | 1733 | |
1711 | 1734 | =end original |
1712 | 1735 | |
1713 | 1736 | L<perlmod/"Perl Modules"> を参照してください。 |
1714 | 1737 | |
1715 | 1738 | =item break |
1716 | 1739 | |
1717 | 1740 | =for Pod::Functions +switch break out of a C<given> block |
1718 | 1741 | |
1719 | 1742 | =begin original |
1720 | 1743 | |
1721 | 1744 | Break out of a C<given> block. |
1722 | 1745 | |
1723 | 1746 | =end original |
1724 | 1747 | |
1725 | 1748 | C<given> ブロックから脱出します。 |
1726 | 1749 | |
1727 | 1750 | =begin original |
1728 | 1751 | |
1729 | 1752 | L<C<break>|/break> is available only if the |
1730 | 1753 | L<C<"switch"> feature|feature/The 'switch' feature> is enabled or if it |
1731 | 1754 | is prefixed with C<CORE::>. The |
1732 | 1755 | L<C<"switch"> feature|feature/The 'switch' feature> is enabled |
1733 | 1756 | automatically with a C<use v5.10> (or higher) declaration in the current |
1734 | 1757 | scope. |
1735 | 1758 | |
1736 | 1759 | =end original |
1737 | 1760 | |
1738 | 1761 | L<C<break>|/break> は、L<C<"switch"> 機能|feature/The 'switch' feature> が |
1739 | 1762 | 有効か、C<CORE::> 接頭辞を使ったときにのみ利用可能です。 |
1740 | 1763 | L<C<"switch"> 機能|feature/The 'switch' feature> は、現在のスコープで |
1741 | 1764 | C<use v5.10> (またはそれ以上) 宣言があると自動的に有効になります。 |
1742 | 1765 | |
1743 | 1766 | =item caller EXPR |
1744 | 1767 | X<caller> X<call stack> X<stack> X<stack trace> |
1745 | 1768 | |
1746 | 1769 | =item caller |
1747 | 1770 | |
1748 | 1771 | =for Pod::Functions get context of the current subroutine call |
1749 | 1772 | |
1750 | 1773 | =begin original |
1751 | 1774 | |
1752 | 1775 | Returns the context of the current pure perl subroutine call. In scalar |
1753 | 1776 | context, returns the caller's package name if there I<is> a caller (that is, if |
1754 | 1777 | we're in a subroutine or L<C<eval>|/eval EXPR> or |
1755 | 1778 | L<C<require>|/require VERSION>) and the undefined value otherwise. |
1756 | 1779 | caller never returns XS subs and they are skipped. The next pure perl |
1757 | 1780 | sub will appear instead of the XS sub in caller's return values. In |
1758 | 1781 | list context, caller returns |
1759 | 1782 | |
1760 | 1783 | =end original |
1761 | 1784 | |
1762 | 1785 | その時点のピュア perl サブルーチン呼び出しのコンテキストを返します。 |
1763 | 1786 | スカラコンテキストでは、呼び元が I<ある> 場合 |
1764 | 1787 | (サブルーチン、L<C<eval>|/eval EXPR>、L<C<require>|/require VERSION> の中に |
1765 | 1788 | いるとき) には呼び出し元のパッケージ名を返し、 |
1766 | 1789 | その他のときには未定義値を返します。 |
1767 | 1790 | caller は XS サブルーチンを返すことはなく、それらは飛ばされます。 |
1768 | 1791 | XS サブルーチンの代わりに次のピュア perl サブルーチンが caller の返り値に |
1769 | 1792 | なります。 |
1770 | 1793 | リストコンテキストでは、caller は以下を返します: |
1771 | 1794 | |
1772 | 1795 | # 0 1 2 |
1773 | 1796 | my ($package, $filename, $line) = caller; |
1774 | 1797 | |
1775 | 1798 | =begin original |
1776 | 1799 | |
1800 | Like L<C<__FILE__>|/__FILE__> and L<C<__LINE__>|/__LINE__>, the filename and | |
1801 | line number returned here may be altered by the mechanism described at | |
1802 | L<perlsyn/"Plain Old Comments (Not!)">. | |
1803 | ||
1804 | =end original | |
1805 | ||
1806 | L<C<__FILE__>|/__FILE__> と L<C<__LINE__>|/__LINE__> 同様、 | |
1807 | ここで返されるファイル名と行番号は | |
1808 | L<perlsyn/"Plain Old Comments (Not!)"> で記述されている機構によって | |
1809 | 置き換えられます。 | |
1810 | ||
1811 | =begin original | |
1812 | ||
1777 | 1813 | With EXPR, it returns some extra information that the debugger uses to |
1778 | 1814 | print a stack trace. The value of EXPR indicates how many call frames |
1779 | 1815 | to go back before the current one. |
1780 | 1816 | |
1781 | 1817 | =end original |
1782 | 1818 | |
1783 | 1819 | EXPR を付けると、デバッガがスタックトレースを表示するために使う情報を返します。 |
1784 | 1820 | EXPR の値は、現状から数えて、 |
1785 | 1821 | いくつ前のコールフレームまで戻るかを示します。 |
1786 | 1822 | |
1787 | 1823 | # 0 1 2 3 4 |
1788 | 1824 | my ($package, $filename, $line, $subroutine, $hasargs, |
1789 | 1825 | |
1790 | 1826 | # 5 6 7 8 9 10 |
1791 | 1827 | $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash) |
1792 | 1828 | = caller($i); |
1793 | 1829 | |
1794 | 1830 | =begin original |
1795 | 1831 | |
1796 | 1832 | Here, $subroutine is the function that the caller called (rather than the |
1797 | 1833 | function containing the caller). Note that $subroutine may be C<(eval)> if |
1798 | 1834 | the frame is not a subroutine call, but an L<C<eval>|/eval EXPR>. In |
1799 | 1835 | such a case additional elements $evaltext and C<$is_require> are set: |
1800 | 1836 | C<$is_require> is true if the frame is created by a |
1801 | 1837 | L<C<require>|/require VERSION> or L<C<use>|/use Module VERSION LIST> |
1802 | 1838 | statement, $evaltext contains the text of the C<eval EXPR> statement. |
1803 | 1839 | In particular, for an C<eval BLOCK> statement, $subroutine is C<(eval)>, |
1804 | 1840 | but $evaltext is undefined. (Note also that each |
1805 | 1841 | L<C<use>|/use Module VERSION LIST> statement creates a |
1806 | 1842 | L<C<require>|/require VERSION> frame inside an C<eval EXPR> frame.) |
1807 | 1843 | $subroutine may also be C<(unknown)> if this particular subroutine |
1808 | 1844 | happens to have been deleted from the symbol table. C<$hasargs> is true |
1809 | 1845 | if a new instance of L<C<@_>|perlvar/@_> was set up for the frame. |
1810 | 1846 | C<$hints> and C<$bitmask> contain pragmatic hints that the caller was |
1811 | 1847 | compiled with. C<$hints> corresponds to L<C<$^H>|perlvar/$^H>, and |
1812 | 1848 | C<$bitmask> corresponds to |
1813 | 1849 | L<C<${^WARNING_BITS}>|perlvar/${^WARNING_BITS}>. The C<$hints> and |
1814 | 1850 | C<$bitmask> values are subject to change between versions of Perl, and |
1815 | 1851 | are not meant for external use. |
1816 | 1852 | |
1817 | 1853 | =end original |
1818 | 1854 | |
1819 | 1855 | ここで、$subroutine は、(caller を含む関数ではなく) caller が呼び出した |
1820 | 1856 | 関数です。 |
1821 | 1857 | フレームがサブルーチン呼び出しではなく L<C<eval>|/eval EXPR> だった場合、この |
1822 | 1858 | $subroutine は C<(eval)> になることに注意してください。 |
1823 | 1859 | この場合、追加の要素である $evaltext と C<$is_require> がセットされます: |
1824 | 1860 | C<$is_require> はフレームが L<C<require>|/require VERSION> または |
1825 | 1861 | L<C<use>|/use Module VERSION LIST> で作られた場合に真になり、 |
1826 | 1862 | $evaltext は C<eval EXPR> のテキストが入ります。 |
1827 | 1863 | 特に、C<eval BLOCK> の場合、$subroutine は C<(eval)> になりますが、 |
1828 | 1864 | $evaltext は未定義値になります。 |
1829 | 1865 | (それぞれの L<C<use>|/use Module VERSION LIST> は C<eval EXPR> の中で |
1830 | 1866 | L<C<require>|/require VERSION> フレームを作ることに注意してください。) |
1831 | 1867 | $subroutine は、そのサブルーチンがシンボルテーブルから削除された場合は |
1832 | 1868 | C<(unknown)> になります。 |
1833 | 1869 | C<$hasargs> はこのフレーム用に L<C<@_>|perlvar/@_> の新しい実体が |
1834 | 1870 | 設定された場合に真となります。 |
1835 | 1871 | C<$hints> と C<$bitmask> は caller がコンパイルされたときの |
1836 | 1872 | 実際的なヒントを含みます。 |
1837 | 1873 | C<$hints> は L<C<$^H>|perlvar/$^H> に対応し、C<$bitmask> は |
1838 | 1874 | L<C<${^WARNING_BITS}>|perlvar/${^WARNING_BITS}> に |
1839 | 1875 | 対応します。 |
1840 | 1876 | C<$hints> は C<$bitmask> は Perl のバージョンによって変更される |
1841 | 1877 | 可能性があるので、外部での使用を想定していません。 |
1842 | 1878 | |
1843 | 1879 | =begin original |
1844 | 1880 | |
1845 | 1881 | C<$hinthash> is a reference to a hash containing the value of |
1846 | 1882 | L<C<%^H>|perlvar/%^H> when the caller was compiled, or |
1847 | 1883 | L<C<undef>|/undef EXPR> if L<C<%^H>|perlvar/%^H> was empty. Do not |
1848 | 1884 | modify the values of this hash, as they are the actual values stored in |
1849 | 1885 | the optree. |
1850 | 1886 | |
1851 | 1887 | =end original |
1852 | 1888 | |
1853 | 1889 | C<$hinthash> は、caller がコンパイルされた時の L<C<%^H>|perlvar/%^H> の値を |
1854 | 1890 | 含むハッシュへのリファレンスか、あるいは L<C<%^H>|perlvar/%^H> が空の場合は |
1855 | 1891 | L<C<undef>|/undef EXPR> です。 |
1856 | 1892 | このハッシュの値は構文木に保管されている実際の値なので、変更しないで下さい。 |
1857 | 1893 | |
1858 | 1894 | =begin original |
1859 | 1895 | |
1860 | 1896 | Furthermore, when called from within the DB package in |
1861 | 1897 | list context, and with an argument, caller returns more |
1862 | 1898 | detailed information: it sets the list variable C<@DB::args> to be the |
1863 | 1899 | arguments with which the subroutine was invoked. |
1864 | 1900 | |
1865 | 1901 | =end original |
1866 | 1902 | |
1867 | 1903 | さらに、DB パッケージの中からリストコンテキストで引数付きで呼ばれた場合は、 |
1868 | 1904 | caller はより詳細な情報を返します; サブルーチンが起動されたときの引数を |
1869 | 1905 | 変数 C<@DB::args> に設定します。 |
1870 | 1906 | |
1871 | 1907 | =begin original |
1872 | 1908 | |
1873 | 1909 | Be aware that the optimizer might have optimized call frames away before |
1874 | 1910 | L<C<caller>|/caller EXPR> had a chance to get the information. That |
1875 | 1911 | means that C<caller(N)> might not return information about the call |
1876 | 1912 | frame you expect it to, for C<< N > 1 >>. In particular, C<@DB::args> |
1877 | 1913 | might have information from the previous time L<C<caller>|/caller EXPR> |
1878 | 1914 | was called. |
1879 | 1915 | |
1880 | 1916 | =end original |
1881 | 1917 | |
1882 | 1918 | L<C<caller>|/caller EXPR> が情報を得る前にオプティマイザが呼び出しフレームを |
1883 | 1919 | 最適化してしまうかもしれないことに注意してください。 |
1884 | 1920 | これは、C<caller(N)> が C<< N > 1 >> のとき、 |
1885 | 1921 | あなたが予測した呼び出しフレームの情報を返さないかもしれないことを意味します。 |
1886 | 1922 | 特に、C<@DB::args> は L<C<caller>|/caller EXPR> が前回呼び出された時の情報を |
1887 | 1923 | 持っているかもしれません。 |
1888 | 1924 | |
1889 | 1925 | =begin original |
1890 | 1926 | |
1891 | 1927 | Be aware that setting C<@DB::args> is I<best effort>, intended for |
1892 | 1928 | debugging or generating backtraces, and should not be relied upon. In |
1893 | 1929 | particular, as L<C<@_>|perlvar/@_> contains aliases to the caller's |
1894 | 1930 | arguments, Perl does not take a copy of L<C<@_>|perlvar/@_>, so |
1895 | 1931 | C<@DB::args> will contain modifications the subroutine makes to |
1896 | 1932 | L<C<@_>|perlvar/@_> or its contents, not the original values at call |
1897 | 1933 | time. C<@DB::args>, like L<C<@_>|perlvar/@_>, does not hold explicit |
1898 | 1934 | references to its elements, so under certain cases its elements may have |
1899 | 1935 | become freed and reallocated for other variables or temporary values. |
1900 | 1936 | Finally, a side effect of the current implementation is that the effects |
1901 | 1937 | of C<shift @_> can I<normally> be undone (but not C<pop @_> or other |
1902 | 1938 | splicing, I<and> not if a reference to L<C<@_>|perlvar/@_> has been |
1903 | 1939 | taken, I<and> subject to the caveat about reallocated elements), so |
1904 | 1940 | C<@DB::args> is actually a hybrid of the current state and initial state |
1905 | 1941 | of L<C<@_>|perlvar/@_>. Buyer beware. |
1906 | 1942 | |
1907 | 1943 | =end original |
1908 | 1944 | |
1909 | 1945 | C<@DB::args> の設定は I<ベストエフォート> で、デバッグやバックトレースの |
1910 | 1946 | 生成を目的としていて、これに依存するべきではないということにも |
1911 | 1947 | 注意してください。 |
1912 | 1948 | 特に、L<C<@_>|perlvar/@_> は呼び出し元の引数へのエイリアスを含んでいるので、 |
1913 | 1949 | Perl は L<C<@_>|perlvar/@_> のコピーを取らず、従って C<@DB::args> は |
1914 | 1950 | サブルーチンが L<C<@_>|perlvar/@_> やその内容に行った変更を含んでいて、 |
1915 | 1951 | 呼び出し時の元の値ではありません。 |
1916 | 1952 | C<@DB::args> は、L<C<@_>|perlvar/@_> と同様、その要素への明示的な |
1917 | 1953 | リファレンスを保持しないので、ある種の状況では、解放されて他の変数や |
1918 | 1954 | 一時的な値のために再割り当てされているかもしれません。 |
1919 | 1955 | 最後に、現在の実装の副作用は、C<shift @_> の効果は I<普通は> 行われない |
1920 | 1956 | (しかし C<pop @_> やその他の splice は違い、I<そして> もし |
1921 | 1957 | L<C<@_>|perlvar/@_> のリファレンスが取られると違い、I<そして> 再割り当てされた |
1922 | 1958 | 要素に関する問題になりやすいです)ことなので、C<@DB::args> は実際には現在の |
1923 | 1959 | 状態と L<C<@_>|perlvar/@_> の初期状態との合成物となります。 |
1924 | 1960 | ご用心を。 |
1925 | 1961 | |
1926 | 1962 | =item chdir EXPR |
1927 | 1963 | X<chdir> |
1928 | 1964 | X<cd> |
1929 | 1965 | X<directory, change> |
1930 | 1966 | |
1931 | 1967 | =item chdir FILEHANDLE |
1932 | 1968 | |
1933 | 1969 | =item chdir DIRHANDLE |
1934 | 1970 | |
1935 | 1971 | =item chdir |
1936 | 1972 | |
1937 | 1973 | =for Pod::Functions change your current working directory |
1938 | 1974 | |
1939 | 1975 | =begin original |
1940 | 1976 | |
1941 | 1977 | Changes the working directory to EXPR, if possible. If EXPR is omitted, |
1942 | 1978 | changes to the directory specified by C<$ENV{HOME}>, if set; if not, |
1943 | 1979 | changes to the directory specified by C<$ENV{LOGDIR}>. (Under VMS, the |
1944 | 1980 | variable C<$ENV{'SYS$LOGIN'}> is also checked, and used if it is set.) If |
1945 | 1981 | neither is set, L<C<chdir>|/chdir EXPR> does nothing and fails. It |
1946 | 1982 | returns true on success, false otherwise. See the example under |
1947 | 1983 | L<C<die>|/die LIST>. |
1948 | 1984 | |
1949 | 1985 | =end original |
1950 | 1986 | |
1951 | 1987 | (可能であれば、) カレントディレクトリを EXPR に移します。 |
1952 | 1988 | EXPR を指定しないと、C<$ENV{HOME}> が設定されていれば、そのディレクトリに |
1953 | 1989 | 移ります; そうでなく、C<$ENV{LOGDIR}>が設定されていれば、そのディレクトリに |
1954 | 1990 | 移ります。 |
1955 | 1991 | (VMS では C<$ENV{'SYS$LOGIN'}> もチェックされ、もしセットされていれば |
1956 | 1992 | 使われます。) |
1957 | 1993 | どちらも設定されていなければ、L<C<chdir>|/chdir EXPR> は何もせずに失敗します。 |
1958 | 1994 | 成功時には真を返し、そうでなければ偽を返します。 |
1959 | 1995 | L<C<die>|/die LIST> の項の例を参照してください。 |
1960 | 1996 | |
1961 | 1997 | =begin original |
1962 | 1998 | |
1963 | 1999 | On systems that support L<fchdir(2)>, you may pass a filehandle or |
1964 | 2000 | directory handle as the argument. On systems that don't support L<fchdir(2)>, |
1965 | 2001 | passing handles raises an exception. |
1966 | 2002 | |
1967 | 2003 | =end original |
1968 | 2004 | |
1969 | 2005 | L<fchdir(2)> に対応しているシステムでは、ファイルハンドルや |
1970 | 2006 | ディレクトリハンドルを引数として渡せます。 |
1971 | 2007 | L<fchdir(2)> に対応していないシステムでは、ハンドルを渡すと例外が発生します。 |
1972 | 2008 | |
1973 | 2009 | =item chmod LIST |
1974 | 2010 | X<chmod> X<permission> X<mode> |
1975 | 2011 | |
1976 | 2012 | =for Pod::Functions changes the permissions on a list of files |
1977 | 2013 | |
1978 | 2014 | =begin original |
1979 | 2015 | |
1980 | 2016 | Changes the permissions of a list of files. The first element of the |
1981 | 2017 | list must be the numeric mode, which should probably be an octal |
1982 | 2018 | number, and which definitely should I<not> be a string of octal digits: |
1983 | 2019 | C<0644> is okay, but C<"0644"> is not. Returns the number of files |
1984 | 2020 | successfully changed. See also L<C<oct>|/oct EXPR> if all you have is a |
1985 | 2021 | string. |
1986 | 2022 | |
1987 | 2023 | =end original |
1988 | 2024 | |
1989 | 2025 | LIST に含まれるファイルの、パーミッションを変更します。 |
1990 | 2026 | LIST の最初の要素は、数値表現のモードでなければなりません; |
1991 | 2027 | 恐らく 8 進表記の数であるべきでしょう: しかし、8 進表記の |
1992 | 2028 | 文字列では I<いけません>: C<0644> は OK ですが、 C<"0644"> は |
1993 | 2029 | だめ、ということです。 |
1994 | 2030 | 変更に成功したファイルの数を返します。 |
1995 | 2031 | 文字列を使いたい場合は、L<C<oct>|/oct EXPR> を参照してください。 |
1996 | 2032 | |
1997 | 2033 | my $cnt = chmod 0755, "foo", "bar"; |
1998 | 2034 | chmod 0755, @executables; |
1999 | 2035 | my $mode = "0644"; chmod $mode, "foo"; # !!! sets mode to |
2000 | 2036 | # --w----r-T |
2001 | 2037 | my $mode = "0644"; chmod oct($mode), "foo"; # this is better |
2002 | 2038 | my $mode = 0644; chmod $mode, "foo"; # this is best |
2003 | 2039 | |
2004 | 2040 | =begin original |
2005 | 2041 | |
2006 | 2042 | On systems that support L<fchmod(2)>, you may pass filehandles among the |
2007 | 2043 | files. On systems that don't support L<fchmod(2)>, passing filehandles raises |
2008 | 2044 | an exception. Filehandles must be passed as globs or glob references to be |
2009 | 2045 | recognized; barewords are considered filenames. |
2010 | 2046 | |
2011 | 2047 | =end original |
2012 | 2048 | |
2013 | 2049 | L<fchmod(2)> に対応しているシステムでは、ファイルハンドルを引数として |
2014 | 2050 | 渡せます。 |
2015 | 2051 | L<fchmod(2)> に対応していないシステムでは、ファイルハンドルを渡すと |
2016 | 2052 | 例外が発生します。 |
2017 | 2053 | ファイルハンドルを認識させるためには、グロブまたはリファレンスとして |
2018 | 2054 | 渡されなければなりません; |
2019 | 2055 | 裸の単語はファイル名として扱われます。 |
2020 | 2056 | |
2021 | 2057 | open(my $fh, "<", "foo"); |
2022 | 2058 | my $perm = (stat $fh)[2] & 07777; |
2023 | 2059 | chmod($perm | 0600, $fh); |
2024 | 2060 | |
2025 | 2061 | =begin original |
2026 | 2062 | |
2027 | 2063 | You can also import the symbolic C<S_I*> constants from the |
2028 | 2064 | L<C<Fcntl>|Fcntl> module: |
2029 | 2065 | |
2030 | 2066 | =end original |
2031 | 2067 | |
2032 | 2068 | L<C<Fcntl>|Fcntl> モジュールから C<S_I*> シンボル定数を |
2033 | 2069 | インポートすることもできます: |
2034 | 2070 | |
2035 | 2071 | use Fcntl qw( :mode ); |
2036 | 2072 | chmod S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, @executables; |
2037 | 2073 | # Identical to the chmod 0755 of the example above. |
2038 | 2074 | |
2039 | 2075 | =begin original |
2040 | 2076 | |
2041 | 2077 | Portability issues: L<perlport/chmod>. |
2042 | 2078 | |
2043 | 2079 | =end original |
2044 | 2080 | |
2045 | 2081 | 移植性の問題: L<perlport/chmod>。 |
2046 | 2082 | |
2047 | 2083 | =item chomp VARIABLE |
2048 | 2084 | X<chomp> X<INPUT_RECORD_SEPARATOR> X<$/> X<newline> X<eol> |
2049 | 2085 | |
2050 | 2086 | =item chomp( LIST ) |
2051 | 2087 | |
2052 | 2088 | =item chomp |
2053 | 2089 | |
2054 | 2090 | =for Pod::Functions remove a trailing record separator from a string |
2055 | 2091 | |
2056 | 2092 | =begin original |
2057 | 2093 | |
2058 | 2094 | This safer version of L<C<chop>|/chop VARIABLE> removes any trailing |
2059 | 2095 | string that corresponds to the current value of |
2060 | 2096 | L<C<$E<sol>>|perlvar/$E<sol>> (also known as C<$INPUT_RECORD_SEPARATOR> |
2061 | 2097 | in the L<C<English>|English> module). It returns the total |
2062 | 2098 | number of characters removed from all its arguments. It's often used to |
2063 | 2099 | remove the newline from the end of an input record when you're worried |
2064 | 2100 | that the final record may be missing its newline. When in paragraph |
2065 | 2101 | mode (C<$/ = ''>), it removes all trailing newlines from the string. |
2066 | 2102 | When in slurp mode (C<$/ = undef>) or fixed-length record mode |
2067 | 2103 | (L<C<$E<sol>>|perlvar/$E<sol>> is a reference to an integer or the like; |
2068 | 2104 | see L<perlvar>), L<C<chomp>|/chomp VARIABLE> won't remove anything. |
2069 | 2105 | If VARIABLE is omitted, it chomps L<C<$_>|perlvar/$_>. Example: |
2070 | 2106 | |
2071 | 2107 | =end original |
2072 | 2108 | |
2073 | 2109 | より安全な L<C<chop>|/chop VARIABLE> (以下を参照してください) です; |
2074 | 2110 | L<C<$E<sol>>|perlvar/$E<sol>> (L<C<English>|English> モジュールでは、 |
2075 | 2111 | C<$INPUT_RECORD_SEPARATOR> とも言う) のその時点の |
2076 | 2112 | 値に対応する行末文字を削除します。 |
2077 | 2113 | 全ての引数から削除した文字数の合計を返します。 |
2078 | 2114 | 入力レコードから、改行を削除したいのだけれど、最後のレコードには改行が |
2079 | 2115 | 入っているのかわからないような場合に、使用できます。 |
2080 | 2116 | 段落モード (C<$/ = ''>) では、レコードの最後の改行をすべて取り除きます。 |
2081 | 2117 | 吸い込みモード (C<$/ = undef>) や 固定長レコードモード |
2082 | 2118 | (L<C<$E<sol>>|perlvar/$E<sol>> が整数へのリファレンスや類似のものの場合; |
2083 | 2119 | L<perlvar>を参照してください)では、L<C<chomp>|/chomp VARIABLE> は |
2084 | 2120 | 何も取り除きません。 |
2085 | 2121 | VARIABLE が省略されると、L<C<$_>|perlvar/$_> を対象として chomp します。 |
2086 | 2122 | 例: |
2087 | 2123 | |
2088 | 2124 | while (<>) { |
2089 | 2125 | chomp; # avoid \n on last field |
2090 | 2126 | my @array = split(/:/); |
2091 | 2127 | # ... |
2092 | 2128 | } |
2093 | 2129 | |
2094 | 2130 | =begin original |
2095 | 2131 | |
2096 | 2132 | If VARIABLE is a hash, it chomps the hash's values, but not its keys, |
2097 | 2133 | resetting the L<C<each>|/each HASH> iterator in the process. |
2098 | 2134 | |
2099 | 2135 | =end original |
2100 | 2136 | |
2101 | 2137 | VARIABLE がハッシュなら、ハッシュのキーではなく値について chomp し、 |
2102 | 2138 | このプロセスの L<C<each>|/each HASH> 反復子をリセットします。 |
2103 | 2139 | |
2104 | 2140 | =begin original |
2105 | 2141 | |
2106 | 2142 | You can actually chomp anything that's an lvalue, including an assignment: |
2107 | 2143 | |
2108 | 2144 | =end original |
2109 | 2145 | |
2110 | 2146 | 左辺値であれば、代入を含めて、任意のものを chomp できます: |
2111 | 2147 | |
2112 | 2148 | chomp(my $cwd = `pwd`); |
2113 | 2149 | chomp(my $answer = <STDIN>); |
2114 | 2150 | |
2115 | 2151 | =begin original |
2116 | 2152 | |
2117 | 2153 | If you chomp a list, each element is chomped, and the total number of |
2118 | 2154 | characters removed is returned. |
2119 | 2155 | |
2120 | 2156 | =end original |
2121 | 2157 | |
2122 | 2158 | リストを chomp すると、個々の要素が chomp され、 |
2123 | 2159 | 削除された文字数の合計が返されます。 |
2124 | 2160 | |
2125 | 2161 | =begin original |
2126 | 2162 | |
2127 | 2163 | Note that parentheses are necessary when you're chomping anything |
2128 | 2164 | that is not a simple variable. This is because C<chomp $cwd = `pwd`;> |
2129 | 2165 | is interpreted as C<(chomp $cwd) = `pwd`;>, rather than as |
2130 | 2166 | C<chomp( $cwd = `pwd` )> which you might expect. Similarly, |
2131 | 2167 | C<chomp $a, $b> is interpreted as C<chomp($a), $b> rather than |
2132 | 2168 | as C<chomp($a, $b)>. |
2133 | 2169 | |
2134 | 2170 | =end original |
2135 | 2171 | |
2136 | 2172 | 単純な変数以外のものを chomp する場合はかっこが必要であることに |
2137 | 2173 | 注意してください。 |
2138 | 2174 | これは、C<chomp $cwd = `pwd`;> は、予測している |
2139 | 2175 | C<chomp( $cwd = `pwd` )> ではなく、C<(chomp $cwd) = `pwd`;> と |
2140 | 2176 | 解釈されるからです。 |
2141 | 2177 | 同様に、C<chomp $a, $b> は C<chomp($a, $b)> ではなく C<chomp($a), $b> |
2142 | 2178 | と解釈されます。 |
2143 | 2179 | |
2144 | 2180 | =item chop VARIABLE |
2145 | 2181 | X<chop> |
2146 | 2182 | |
2147 | 2183 | =item chop( LIST ) |
2148 | 2184 | |
2149 | 2185 | =item chop |
2150 | 2186 | |
2151 | 2187 | =for Pod::Functions remove the last character from a string |
2152 | 2188 | |
2153 | 2189 | =begin original |
2154 | 2190 | |
2155 | 2191 | Chops off the last character of a string and returns the character |
2156 | 2192 | chopped. It is much more efficient than C<s/.$//s> because it neither |
2157 | 2193 | scans nor copies the string. If VARIABLE is omitted, chops |
2158 | 2194 | L<C<$_>|perlvar/$_>. |
2159 | 2195 | If VARIABLE is a hash, it chops the hash's values, but not its keys, |
2160 | 2196 | resetting the L<C<each>|/each HASH> iterator in the process. |
2161 | 2197 | |
2162 | 2198 | =end original |
2163 | 2199 | |
2164 | 2200 | 文字列の最後の文字を切り捨てて、その切り取った文字を返します。 |
2165 | 2201 | 文字列の検索もコピーも行ないませんので |
2166 | 2202 | C<s/.$//s> よりも、ずっと効率的です。 |
2167 | 2203 | VARIABLE が省略されると、L<C<$_>|perlvar/$_> を対象として chop します。 |
2168 | 2204 | VARIABLE がハッシュの場合、ハッシュのキーではなく値について chop し、 |
2169 | 2205 | このプロセスの L<C<each>|/each HASH> 反復子をリセットします。 |
2170 | 2206 | |
2171 | 2207 | =begin original |
2172 | 2208 | |
2173 | 2209 | You can actually chop anything that's an lvalue, including an assignment. |
2174 | 2210 | |
2175 | 2211 | =end original |
2176 | 2212 | |
2177 | 2213 | 実際のところ、代入を含む左辺値となりうるなんでも chop できます。 |
2178 | 2214 | |
2179 | 2215 | =begin original |
2180 | 2216 | |
2181 | 2217 | If you chop a list, each element is chopped. Only the value of the |
2182 | 2218 | last L<C<chop>|/chop VARIABLE> is returned. |
2183 | 2219 | |
2184 | 2220 | =end original |
2185 | 2221 | |
2186 | 2222 | リストを chop すると、個々の要素が chop されます。 |
2187 | 2223 | 最後の L<C<chop>|/chop VARIABLE> の値だけが返されます。 |
2188 | 2224 | |
2189 | 2225 | =begin original |
2190 | 2226 | |
2191 | 2227 | Note that L<C<chop>|/chop VARIABLE> returns the last character. To |
2192 | 2228 | return all but the last character, use C<substr($string, 0, -1)>. |
2193 | 2229 | |
2194 | 2230 | =end original |
2195 | 2231 | |
2196 | 2232 | L<C<chop>|/chop VARIABLE> は最後の文字を返すことに注意してください。 |
2197 | 2233 | 最後以外の全ての文字を返すためには、C<substr($string, 0, -1)> を |
2198 | 2234 | 使ってください。 |
2199 | 2235 | |
2200 | 2236 | =begin original |
2201 | 2237 | |
2202 | 2238 | See also L<C<chomp>|/chomp VARIABLE>. |
2203 | 2239 | |
2204 | 2240 | =end original |
2205 | 2241 | |
2206 | 2242 | L<C<chomp>|/chomp VARIABLE> も参照してください。 |
2207 | 2243 | |
2208 | 2244 | =item chown LIST |
2209 | 2245 | X<chown> X<owner> X<user> X<group> |
2210 | 2246 | |
2211 | 2247 | =for Pod::Functions change the ownership on a list of files |
2212 | 2248 | |
2213 | 2249 | =begin original |
2214 | 2250 | |
2215 | 2251 | Changes the owner (and group) of a list of files. The first two |
2216 | 2252 | elements of the list must be the I<numeric> uid and gid, in that |
2217 | 2253 | order. A value of -1 in either position is interpreted by most |
2218 | 2254 | systems to leave that value unchanged. Returns the number of files |
2219 | 2255 | successfully changed. |
2220 | 2256 | |
2221 | 2257 | =end original |
2222 | 2258 | |
2223 | 2259 | LIST に含まれるファイルの所有者 (とグループ) を変更します。 |
2224 | 2260 | LIST の最初の二つの要素には、I<数値表現> の uid と gid を |
2225 | 2261 | この順序で与えなければなりません。 |
2226 | 2262 | どちらかの値を -1 にすると、ほとんどのシステムではその値は |
2227 | 2263 | 変更しないと解釈します。 |
2228 | 2264 | 変更に成功したファイルの数を返します。 |
2229 | 2265 | |
2230 | 2266 | my $cnt = chown $uid, $gid, 'foo', 'bar'; |
2231 | 2267 | chown $uid, $gid, @filenames; |
2232 | 2268 | |
2233 | 2269 | =begin original |
2234 | 2270 | |
2235 | 2271 | On systems that support L<fchown(2)>, you may pass filehandles among the |
2236 | 2272 | files. On systems that don't support L<fchown(2)>, passing filehandles raises |
2237 | 2273 | an exception. Filehandles must be passed as globs or glob references to be |
2238 | 2274 | recognized; barewords are considered filenames. |
2239 | 2275 | |
2240 | 2276 | =end original |
2241 | 2277 | |
2242 | 2278 | L<fchown(2)> に対応しているシステムでは、ファイルハンドルを引数として渡せます。 |
2243 | 2279 | L<fchown(2)> に対応していないシステムでは、ファイルハンドルを渡すと |
2244 | 2280 | 例外が発生します。 |
2245 | 2281 | ファイルハンドルを認識させるためには、グロブまたはリファレンスとして |
2246 | 2282 | 渡されなければなりません; 裸の単語はファイル名として扱われます。 |
2247 | 2283 | |
2248 | 2284 | =begin original |
2249 | 2285 | |
2250 | 2286 | Here's an example that looks up nonnumeric uids in the passwd file: |
2251 | 2287 | |
2252 | 2288 | =end original |
2253 | 2289 | |
2254 | 2290 | passwd ファイルから数値表現でない uid を検索する例を |
2255 | 2291 | 示します: |
2256 | 2292 | |
2257 | 2293 | print "User: "; |
2258 | 2294 | chomp(my $user = <STDIN>); |
2259 | 2295 | print "Files: "; |
2260 | 2296 | chomp(my $pattern = <STDIN>); |
2261 | 2297 | |
2262 | 2298 | my ($login,$pass,$uid,$gid) = getpwnam($user) |
2263 | 2299 | or die "$user not in passwd file"; |
2264 | 2300 | |
2265 | 2301 | my @ary = glob($pattern); # expand filenames |
2266 | 2302 | chown $uid, $gid, @ary; |
2267 | 2303 | |
2268 | 2304 | =begin original |
2269 | 2305 | |
2270 | 2306 | On most systems, you are not allowed to change the ownership of the |
2271 | 2307 | file unless you're the superuser, although you should be able to change |
2272 | 2308 | the group to any of your secondary groups. On insecure systems, these |
2273 | 2309 | restrictions may be relaxed, but this is not a portable assumption. |
2274 | 2310 | On POSIX systems, you can detect this condition this way: |
2275 | 2311 | |
2276 | 2312 | =end original |
2277 | 2313 | |
2278 | 2314 | ほとんどのシステムでは、スーパーユーザーだけがファイルの所有者を |
2279 | 2315 | 変更できますが、グループは実行者の副グループに変更できるべきです。 |
2280 | 2316 | 安全でないシステムでは、この制限はゆるめられています; しかしこれは |
2281 | 2317 | 移植性のある仮定ではありません。 |
2282 | 2318 | POSIX システムでは、以下のようにしてこの条件を検出できます: |
2283 | 2319 | |
2284 | 2320 | use POSIX qw(sysconf _PC_CHOWN_RESTRICTED); |
2285 | 2321 | my $can_chown_giveaway = ! sysconf(_PC_CHOWN_RESTRICTED); |
2286 | 2322 | |
2287 | 2323 | =begin original |
2288 | 2324 | |
2289 | 2325 | Portability issues: L<perlport/chown>. |
2290 | 2326 | |
2291 | 2327 | =end original |
2292 | 2328 | |
2293 | 2329 | 移植性の問題: L<perlport/chown>。 |
2294 | 2330 | |
2295 | 2331 | =item chr NUMBER |
2296 | 2332 | X<chr> X<character> X<ASCII> X<Unicode> |
2297 | 2333 | |
2298 | 2334 | =item chr |
2299 | 2335 | |
2300 | 2336 | =for Pod::Functions get character this number represents |
2301 | 2337 | |
2302 | 2338 | =begin original |
2303 | 2339 | |
2304 | 2340 | Returns the character represented by that NUMBER in the character set. |
2305 | 2341 | For example, C<chr(65)> is C<"A"> in either ASCII or Unicode, and |
2306 | 2342 | chr(0x263a) is a Unicode smiley face. |
2307 | 2343 | |
2308 | 2344 | =end original |
2309 | 2345 | |
2310 | 2346 | 特定の文字セットでの NUMBER で表わされる文字を返します。 |
2311 | 2347 | たとえば、C<chr(65)> は ASCII と Unicode の両方で C<"A"> となります; |
2312 | 2348 | chr(0x263a) は Unicode のスマイリーフェイスです。 |
2313 | 2349 | |
2314 | 2350 | =begin original |
2315 | 2351 | |
2316 | 2352 | Negative values give the Unicode replacement character (chr(0xfffd)), |
2317 | 2353 | except under the L<bytes> pragma, where the low eight bits of the value |
2318 | 2354 | (truncated to an integer) are used. |
2319 | 2355 | |
2320 | 2356 | =end original |
2321 | 2357 | |
2322 | 2358 | 負の数は Unicode の置換文字 (chr(0xfffd)) を与えますが、 |
2323 | 2359 | L<bytes> プラグマの影響下では、(integer に切り詰められた)値の下位 8 ビットが |
2324 | 2360 | 使われます。 |
2325 | 2361 | |
2326 | 2362 | =begin original |
2327 | 2363 | |
2328 | 2364 | If NUMBER is omitted, uses L<C<$_>|perlvar/$_>. |
2329 | 2365 | |
2330 | 2366 | =end original |
2331 | 2367 | |
2332 | 2368 | NUMBER が省略された場合、L<C<$_>|perlvar/$_> を使います。 |
2333 | 2369 | |
2334 | 2370 | =begin original |
2335 | 2371 | |
2336 | 2372 | For the reverse, use L<C<ord>|/ord EXPR>. |
2337 | 2373 | |
2338 | 2374 | =end original |
2339 | 2375 | |
2340 | 2376 | 逆を行うためには、L<C<ord>|/ord EXPR> を参照してください。 |
2341 | 2377 | |
2342 | 2378 | =begin original |
2343 | 2379 | |
2344 | 2380 | Note that characters from 128 to 255 (inclusive) are by default |
2345 | 2381 | internally not encoded as UTF-8 for backward compatibility reasons. |
2346 | 2382 | |
2347 | 2383 | =end original |
2348 | 2384 | |
2349 | 2385 | 128 から 255 までの文字は過去との互換性のために |
2350 | 2386 | デフォルトでは UTF-8 Unicode にエンコードされません。 |
2351 | 2387 | |
2352 | 2388 | =begin original |
2353 | 2389 | |
2354 | 2390 | See L<perlunicode> for more about Unicode. |
2355 | 2391 | |
2356 | 2392 | =end original |
2357 | 2393 | |
2358 | 2394 | Unicode については L<perlunicode> を参照してください。 |
2359 | 2395 | |
2360 | 2396 | =item chroot FILENAME |
2361 | 2397 | X<chroot> X<root> |
2362 | 2398 | |
2363 | 2399 | =item chroot |
2364 | 2400 | |
2365 | 2401 | =for Pod::Functions make directory new root for path lookups |
2366 | 2402 | |
2367 | 2403 | =begin original |
2368 | 2404 | |
2369 | 2405 | This function works like the system call by the same name: it makes the |
2370 | 2406 | named directory the new root directory for all further pathnames that |
2371 | 2407 | begin with a C</> by your process and all its children. (It doesn't |
2372 | 2408 | change your current working directory, which is unaffected.) For security |
2373 | 2409 | reasons, this call is restricted to the superuser. If FILENAME is |
2374 | 2410 | omitted, does a L<C<chroot>|/chroot FILENAME> to L<C<$_>|perlvar/$_>. |
2375 | 2411 | |
2376 | 2412 | =end original |
2377 | 2413 | |
2378 | 2414 | 同じ名前のシステムコールと同じことをします: 現在のプロセス及び子プロセスに |
2379 | 2415 | 対して、C</>で始まるパス名に関して指定されたディレクトリを新しい |
2380 | 2416 | ルートディレクトリとして扱います。 |
2381 | 2417 | (これはカレントディレクトリを変更しません; カレントディレクトリは |
2382 | 2418 | そのままです。) |
2383 | 2419 | セキュリティ上の理由により、この呼び出しはスーパーユーザーしか行えません。 |
2384 | 2420 | FILENAME を省略すると、L<C<$_>|perlvar/$_> へ |
2385 | 2421 | L<C<chroot>|/chroot FILENAME> します。 |
2386 | 2422 | |
2387 | 2423 | =begin original |
2388 | 2424 | |
2389 | B<NOTE:> It is | |
2425 | B<NOTE:> It is mandatory for security to C<chdir("/")> | |
2390 | 2426 | (L<C<chdir>|/chdir EXPR> to the root directory) immediately after a |
2391 | L<C<chroot>|/chroot FILENAME> | |
2427 | L<C<chroot>|/chroot FILENAME>, otherwise the current working directory | |
2428 | may be outside of the new root. | |
2392 | 2429 | |
2393 | 2430 | =end original |
2394 | 2431 | |
2395 | 2432 | B<注意:> L<C<chroot>|/chroot FILENAME> の直後に (ルートディレクトリに |
2396 | 2433 | L<C<chdir>|/chdir EXPR> する) |
2397 | C<chdir("/")> するのはセキュリティ上 | |
2434 | C<chdir("/")> するのはセキュリティ上必須です; | |
2435 | さもなければ現在の作業ディレクトリは新しいルートの外側かもしれません。 | |
2398 | 2436 | |
2399 | 2437 | =begin original |
2400 | 2438 | |
2401 | 2439 | Portability issues: L<perlport/chroot>. |
2402 | 2440 | |
2403 | 2441 | =end original |
2404 | 2442 | |
2405 | 2443 | 移植性の問題: L<perlport/chroot>。 |
2406 | 2444 | |
2407 | 2445 | =item close FILEHANDLE |
2408 | 2446 | X<close> |
2409 | 2447 | |
2410 | 2448 | =item close |
2411 | 2449 | |
2412 | 2450 | =for Pod::Functions close file (or pipe or socket) handle |
2413 | 2451 | |
2414 | 2452 | =begin original |
2415 | 2453 | |
2416 | 2454 | Closes the file or pipe associated with the filehandle, flushes the IO |
2417 | 2455 | buffers, and closes the system file descriptor. Returns true if those |
2418 | 2456 | operations succeed and if no error was reported by any PerlIO |
2419 | 2457 | layer. Closes the currently selected filehandle if the argument is |
2420 | 2458 | omitted. |
2421 | 2459 | |
2422 | 2460 | =end original |
2423 | 2461 | |
2424 | 2462 | FILEHANDLE に対応したファイルまたはパイプをクローズして、 |
2425 | 2463 | IO バッファをフラッシュし、システムファイル記述子をクローズします。 |
2426 | 2464 | 操作が成功し、PerlIO 層からエラーが報告されなかった場合に真を返します。 |
2427 | 2465 | 引数が省略された場合、現在選択されているファイルハンドルをクローズします。 |
2428 | 2466 | |
2429 | 2467 | =begin original |
2430 | 2468 | |
2431 | 2469 | You don't have to close FILEHANDLE if you are immediately going to do |
2432 | another L<C<open>|/open FILEHANDLE,EXPR> on it, because | |
2470 | another L<C<open>|/open FILEHANDLE,MODE,EXPR> on it, because | |
2433 | L<C<open>|/open FILEHANDLE,EXPR> closes it for you. (See | |
2471 | L<C<open>|/open FILEHANDLE,MODE,EXPR> closes it for you. (See | |
2434 | L<C<open>|/open FILEHANDLE,EXPR>.) However, an explicit | |
2472 | L<C<open>|/open FILEHANDLE,MODE,EXPR>.) However, an explicit | |
2435 | 2473 | L<C<close>|/close FILEHANDLE> on an input file resets the line counter |
2436 | 2474 | (L<C<$.>|perlvar/$.>), while the implicit close done by |
2437 | L<C<open>|/open FILEHANDLE,EXPR> does not. | |
2475 | L<C<open>|/open FILEHANDLE,MODE,EXPR> does not. | |
2438 | 2476 | |
2439 | 2477 | =end original |
2440 | 2478 | |
2441 | 2479 | クローズしてすぐにまた、同じファイルハンドルに対してオープンを行なう |
2442 | 場合には、L<C<open>|/open FILEHANDLE,EXPR> が自動的に | |
2480 | 場合には、L<C<open>|/open FILEHANDLE,MODE,EXPR> が自動的に | |
2443 | 2481 | L<C<close>|/close FILEHANDLE> を行ないますので、 |
2444 | 2482 | close FILEHANDLE する必要はありません。 |
2445 | (L<C<open>|/open FILEHANDLE,EXPR> を参照してください。) | |
2483 | (L<C<open>|/open FILEHANDLE,MODE,EXPR> を参照してください。) | |
2446 | 2484 | ただし、明示的にクローズを行なったときにのみ入力ファイルの |
2447 | 2485 | 行番号 (L<C<$.>|perlvar/$.>) のリセットが行なわれ、 |
2448 | L<C<open>|/open FILEHANDLE,EXPR> によって行なわれる | |
2486 | L<C<open>|/open FILEHANDLE,MODE,EXPR> によって行なわれる | |
2449 | 2487 | 暗黙の L<C<close>|/close FILEHANDLE> では行なわれません。 |
2450 | 2488 | |
2451 | 2489 | =begin original |
2452 | 2490 | |
2453 | 2491 | If the filehandle came from a piped open, L<C<close>|/close FILEHANDLE> |
2454 | 2492 | returns false if one of the other syscalls involved fails or if its |
2455 | 2493 | program exits with non-zero status. If the only problem was that the |
2456 | 2494 | program exited non-zero, L<C<$!>|perlvar/$!> will be set to C<0>. |
2457 | 2495 | Closing a pipe also waits for the process executing on the pipe to |
2458 | 2496 | exit--in case you wish to look at the output of the pipe afterwards--and |
2459 | 2497 | implicitly puts the exit status value of that command into |
2460 | 2498 | L<C<$?>|perlvar/$?> and |
2461 | 2499 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>. |
2462 | 2500 | |
2463 | 2501 | =end original |
2464 | 2502 | |
2465 | 2503 | ファイルハンドルがパイプつきオープンなら、L<C<close>|/close FILEHANDLE> は |
2466 | 2504 | その他のシステムコールが失敗したりプログラムが非ゼロのステータスで終了した |
2467 | 2505 | 場合にも偽を返します。 |
2468 | 2506 | プログラムが非ゼロで終了しただけの場合は、L<C<$!>|perlvar/$!> が C<0> に |
2469 | 2507 | セットされます。 |
2470 | 2508 | 後でパイプの出力を見たい場合のために、パイプのクローズでは、パイプ上で |
2471 | 2509 | 実行されているプロセスの終了を待ち、また自動的にコマンドのステータス値を |
2472 | 2510 | L<C<$?>|perlvar/$?> と |
2473 | 2511 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に設定します。 |
2474 | 2512 | |
2475 | 2513 | =begin original |
2476 | 2514 | |
2477 | 2515 | If there are multiple threads running, L<C<close>|/close FILEHANDLE> on |
2478 | 2516 | a filehandle from a piped open returns true without waiting for the |
2479 | 2517 | child process to terminate, if the filehandle is still open in another |
2480 | 2518 | thread. |
2481 | 2519 | |
2482 | 2520 | =end original |
2483 | 2521 | |
2484 | 2522 | 複数のスレッドがある場合、パイプで開かれたファイルハンドルに対する |
2485 | 2523 | L<C<close>|/close FILEHANDLE> は、そのファイルハンドルが他のスレッドで |
2486 | 2524 | まだ開かれている場合、子プロセスの終了を待たずに真を返します。 |
2487 | 2525 | |
2488 | 2526 | =begin original |
2489 | 2527 | |
2490 | 2528 | Closing the read end of a pipe before the process writing to it at the |
2491 | 2529 | other end is done writing results in the writer receiving a SIGPIPE. If |
2492 | 2530 | the other end can't handle that, be sure to read all the data before |
2493 | 2531 | closing the pipe. |
2494 | 2532 | |
2495 | 2533 | =end original |
2496 | 2534 | |
2497 | 2535 | 書き込み側が閉じる前に途中でパイプの読み込み側が閉じた場合、 |
2498 | 2536 | 書き込み側に SIGPIPE が配送されます。 |
2499 | 2537 | 書き込み側がこれを扱えない場合、パイプを閉じる前に |
2500 | 2538 | 確実に全てのデータが読み込まれるようにする必要があります。 |
2501 | 2539 | |
2502 | 2540 | =begin original |
2503 | 2541 | |
2504 | 2542 | Example: |
2505 | 2543 | |
2506 | 2544 | =end original |
2507 | 2545 | |
2508 | 2546 | 例: |
2509 | 2547 | |
2510 | 2548 | open(OUTPUT, '|sort >foo') # pipe to sort |
2511 | 2549 | or die "Can't start sort: $!"; |
2512 | 2550 | #... # print stuff to output |
2513 | 2551 | close OUTPUT # wait for sort to finish |
2514 | 2552 | or warn $! ? "Error closing sort pipe: $!" |
2515 | 2553 | : "Exit status $? from sort"; |
2516 | 2554 | open(INPUT, 'foo') # get sort's results |
2517 | 2555 | or die "Can't open 'foo' for input: $!"; |
2518 | 2556 | |
2519 | 2557 | =begin original |
2520 | 2558 | |
2521 | 2559 | FILEHANDLE may be an expression whose value can be used as an indirect |
2522 | 2560 | filehandle, usually the real filehandle name or an autovivified handle. |
2523 | 2561 | |
2524 | 2562 | =end original |
2525 | 2563 | |
2526 | 2564 | FILEHANDLE は式でもかまいません; この場合、値は間接ファイルハンドルと |
2527 | 2565 | して扱われ、普通は実際のファイルハンドル名か自動有効化されたハンドルです。 |
2528 | 2566 | |
2529 | 2567 | =item closedir DIRHANDLE |
2530 | 2568 | X<closedir> |
2531 | 2569 | |
2532 | 2570 | =for Pod::Functions close directory handle |
2533 | 2571 | |
2534 | 2572 | =begin original |
2535 | 2573 | |
2536 | 2574 | Closes a directory opened by L<C<opendir>|/opendir DIRHANDLE,EXPR> and |
2537 | 2575 | returns the success of that system call. |
2538 | 2576 | |
2539 | 2577 | =end original |
2540 | 2578 | |
2541 | 2579 | L<C<opendir>|/opendir DIRHANDLE,EXPR> でオープンしたディレクトリをクローズし、 |
2542 | 2580 | システムコールの返り値を返します。 |
2543 | 2581 | |
2544 | 2582 | =item connect SOCKET,NAME |
2545 | 2583 | X<connect> |
2546 | 2584 | |
2547 | 2585 | =for Pod::Functions connect to a remote socket |
2548 | 2586 | |
2549 | 2587 | =begin original |
2550 | 2588 | |
2551 | 2589 | Attempts to connect to a remote socket, just like L<connect(2)>. |
2552 | 2590 | Returns true if it succeeded, false otherwise. NAME should be a |
2553 | 2591 | packed address of the appropriate type for the socket. See the examples in |
2554 | 2592 | L<perlipc/"Sockets: Client/Server Communication">. |
2555 | 2593 | |
2556 | 2594 | =end original |
2557 | 2595 | |
2558 | 2596 | L<connect(2)> システムコールと同様に、リモートソケットへの接続を試みます。 |
2559 | 2597 | 成功時には真を、さもなければ偽を返します。 |
2560 | 2598 | NAME は、ソケットに対する、適切な型のパックされた |
2561 | 2599 | アドレスでなければなりません。 |
2562 | 2600 | L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。 |
2563 | 2601 | |
2564 | 2602 | =item continue BLOCK |
2565 | 2603 | X<continue> |
2566 | 2604 | |
2567 | 2605 | =item continue |
2568 | 2606 | |
2569 | 2607 | =for Pod::Functions optional trailing block in a while or foreach |
2570 | 2608 | |
2571 | 2609 | =begin original |
2572 | 2610 | |
2573 | 2611 | When followed by a BLOCK, L<C<continue>|/continue BLOCK> is actually a |
2574 | 2612 | flow control statement rather than a function. If there is a |
2575 | 2613 | L<C<continue>|/continue BLOCK> BLOCK attached to a BLOCK (typically in a |
2576 | 2614 | C<while> or C<foreach>), it is always executed just before the |
2577 | 2615 | conditional is about to be evaluated again, just like the third part of |
2578 | 2616 | a C<for> loop in C. Thus it can be used to increment a loop variable, |
2579 | 2617 | even when the loop has been continued via the L<C<next>|/next LABEL> |
2580 | 2618 | statement (which is similar to the C L<C<continue>|/continue BLOCK> |
2581 | 2619 | statement). |
2582 | 2620 | |
2583 | 2621 | =end original |
2584 | 2622 | |
2585 | 2623 | BLOCK が引き続く場合、L<C<continue>|/continue BLOCK> は実際には関数ではなく、 |
2586 | 2624 | 実行制御文です。 |
2587 | 2625 | L<C<continue>|/continue BLOCK> BLOCK が BLOCK (典型的には C<while> または |
2588 | 2626 | C<foreach> の中)にあると、これは条件文が再評価される直前に常に実行されます; |
2589 | 2627 | これは C における C<for> ループの 3 番目の部分と同様です。 |
2590 | 2628 | 従って、これは L<C<next>|/next LABEL> 文 (これは C の |
2591 | 2629 | L<C<continue>|/continue BLOCK> 文と似ています) を使って |
2592 | 2630 | ループが繰り返されるときでもループ変数を増やしたいときに使えます。 |
2593 | 2631 | |
2594 | 2632 | =begin original |
2595 | 2633 | |
2596 | 2634 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, or |
2597 | 2635 | L<C<redo>|/redo LABEL> may appear within a |
2598 | 2636 | L<C<continue>|/continue BLOCK> block; L<C<last>|/last LABEL> and |
2599 | 2637 | L<C<redo>|/redo LABEL> behave as if they had been executed within the |
2600 | 2638 | main block. So will L<C<next>|/next LABEL>, but since it will execute a |
2601 | 2639 | L<C<continue>|/continue BLOCK> block, it may be more entertaining. |
2602 | 2640 | |
2603 | 2641 | =end original |
2604 | 2642 | |
2605 | 2643 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL> が |
2606 | 2644 | L<C<continue>|/continue BLOCK> ブロック内に現れる可能性があります; |
2607 | 2645 | L<C<last>|/last LABEL> と L<C<redo>|/redo LABEL> はメインブロックの中で |
2608 | 2646 | 実行されたのと同じように振舞います。 |
2609 | 2647 | L<C<next>|/next LABEL> の場合は、L<C<continue>|/continue BLOCK> ブロックを |
2610 | 2648 | 実行することになるので、より面白いことになります。 |
2611 | 2649 | |
2612 | 2650 | while (EXPR) { |
2613 | 2651 | ### redo always comes here |
2614 | 2652 | do_something; |
2615 | 2653 | } continue { |
2616 | 2654 | ### next always comes here |
2617 | 2655 | do_something_else; |
2618 | 2656 | # then back the top to re-check EXPR |
2619 | 2657 | } |
2620 | 2658 | ### last always comes here |
2621 | 2659 | |
2622 | 2660 | =begin original |
2623 | 2661 | |
2624 | 2662 | Omitting the L<C<continue>|/continue BLOCK> section is equivalent to |
2625 | 2663 | using an empty one, logically enough, so L<C<next>|/next LABEL> goes |
2626 | 2664 | directly back to check the condition at the top of the loop. |
2627 | 2665 | |
2628 | 2666 | =end original |
2629 | 2667 | |
2630 | 2668 | L<C<continue>|/continue BLOCK> 節を省略するのは、空の節を指定したのと同じで、 |
2631 | 2669 | 論理的には十分なので、この場合、L<C<next>|/next LABEL> は直接ループ先頭の |
2632 | 2670 | 条件チェックに戻ります。 |
2633 | 2671 | |
2634 | 2672 | =begin original |
2635 | 2673 | |
2636 | 2674 | When there is no BLOCK, L<C<continue>|/continue BLOCK> is a function |
2637 | 2675 | that falls through the current C<when> or C<default> block instead of |
2638 | 2676 | iterating a dynamically enclosing C<foreach> or exiting a lexically |
2639 | 2677 | enclosing C<given>. In Perl 5.14 and earlier, this form of |
2640 | 2678 | L<C<continue>|/continue BLOCK> was only available when the |
2641 | 2679 | L<C<"switch"> feature|feature/The 'switch' feature> was enabled. See |
2642 | 2680 | L<feature> and L<perlsyn/"Switch Statements"> for more information. |
2643 | 2681 | |
2644 | 2682 | =end original |
2645 | 2683 | |
2646 | 2684 | BLOCK がなければ、L<C<continue>|/continue BLOCK> は動的に囲まれた C<foreach> や |
2647 | 2685 | レキシカルに囲まれた C<given> で反復するのではなく、現在の C<when> または |
2648 | 2686 | C<default> のブロックを通り抜けるための文です。 |
2649 | 2687 | Perl 5.14 以前では、この形式の L<C<continue>|/continue BLOCK> は |
2650 | 2688 | L<C<"switch"> 機能|feature/The 'switch' feature> が有効の場合にのみ |
2651 | 2689 | 利用可能です。 |
2652 | 2690 | さらなる情報については L<feature> と L<perlsyn/"Switch Statements"> を |
2653 | 2691 | 参照してください。 |
2654 | 2692 | |
2655 | 2693 | =item cos EXPR |
2656 | 2694 | X<cos> X<cosine> X<acos> X<arccosine> |
2657 | 2695 | |
2658 | 2696 | =item cos |
2659 | 2697 | |
2660 | 2698 | =for Pod::Functions cosine function |
2661 | 2699 | |
2662 | 2700 | =begin original |
2663 | 2701 | |
2664 | 2702 | Returns the cosine of EXPR (expressed in radians). If EXPR is omitted, |
2665 | 2703 | takes the cosine of L<C<$_>|perlvar/$_>. |
2666 | 2704 | |
2667 | 2705 | =end original |
2668 | 2706 | |
2669 | 2707 | (ラジアンで示した) EXPR の余弦を返します。 |
2670 | 2708 | EXPR が省略されたときには、L<C<$_>|perlvar/$_> の余弦を取ります。 |
2671 | 2709 | |
2672 | 2710 | =begin original |
2673 | 2711 | |
2674 | 2712 | For the inverse cosine operation, you may use the |
2675 | 2713 | L<C<Math::Trig::acos>|Math::Trig> function, or use this relation: |
2676 | 2714 | |
2677 | 2715 | =end original |
2678 | 2716 | |
2679 | 2717 | 逆余弦を求めるためには、L<C<Math::Trig::acos>|Math::Trig> 関数を使うか、 |
2680 | 2718 | 以下の関係を使ってください。 |
2681 | 2719 | |
2682 | 2720 | sub acos { atan2( sqrt(1 - $_[0] * $_[0]), $_[0] ) } |
2683 | 2721 | |
2684 | 2722 | =item crypt PLAINTEXT,SALT |
2685 | 2723 | X<crypt> X<digest> X<hash> X<salt> X<plaintext> X<password> |
2686 | 2724 | X<decrypt> X<cryptography> X<passwd> X<encrypt> |
2687 | 2725 | |
2688 | 2726 | =for Pod::Functions one-way passwd-style encryption |
2689 | 2727 | |
2690 | 2728 | =begin original |
2691 | 2729 | |
2692 | 2730 | Creates a digest string exactly like the L<crypt(3)> function in the C |
2693 | 2731 | library (assuming that you actually have a version there that has not |
2694 | 2732 | been extirpated as a potential munition). |
2695 | 2733 | |
2696 | 2734 | =end original |
2697 | 2735 | |
2698 | 2736 | C ライブラリの L<crypt(3)> 関数と全く同じように、ダイジェスト文字列を |
2699 | 2737 | 作成します(一時的な必需品として、まだ絶滅していないバージョンを |
2700 | 2738 | 持っていると仮定しています)。 |
2701 | 2739 | |
2702 | 2740 | =begin original |
2703 | 2741 | |
2704 | 2742 | L<C<crypt>|/crypt PLAINTEXT,SALT> is a one-way hash function. The |
2705 | 2743 | PLAINTEXT and SALT are turned |
2706 | 2744 | into a short string, called a digest, which is returned. The same |
2707 | 2745 | PLAINTEXT and SALT will always return the same string, but there is no |
2708 | 2746 | (known) way to get the original PLAINTEXT from the hash. Small |
2709 | 2747 | changes in the PLAINTEXT or SALT will result in large changes in the |
2710 | 2748 | digest. |
2711 | 2749 | |
2712 | 2750 | =end original |
2713 | 2751 | |
2714 | 2752 | L<C<crypt>|/crypt PLAINTEXT,SALT> は一方向ハッシュ関数です。 |
2715 | 2753 | PLAINTEXT と SALT はダイジェストと呼ばれる短い文字列に変えられて、 |
2716 | 2754 | それが返されます。 |
2717 | 2755 | PLAINTEXT と SALT が同じ場合は常に同じ文字列を返しますが、ハッシュから |
2718 | 2756 | 元の PLAINTEXT を得る(既知の)方法はありません。 |
2719 | 2757 | PLAINTEXT や SALT を少し変更してもダイジェストは大きく変更されます。 |
2720 | 2758 | |
2721 | 2759 | =begin original |
2722 | 2760 | |
2723 | 2761 | There is no decrypt function. This function isn't all that useful for |
2724 | 2762 | cryptography (for that, look for F<Crypt> modules on your nearby CPAN |
2725 | 2763 | mirror) and the name "crypt" is a bit of a misnomer. Instead it is |
2726 | 2764 | primarily used to check if two pieces of text are the same without |
2727 | 2765 | having to transmit or store the text itself. An example is checking |
2728 | 2766 | if a correct password is given. The digest of the password is stored, |
2729 | 2767 | not the password itself. The user types in a password that is |
2730 | 2768 | L<C<crypt>|/crypt PLAINTEXT,SALT>'d with the same salt as the stored |
2731 | 2769 | digest. If the two digests match, the password is correct. |
2732 | 2770 | |
2733 | 2771 | =end original |
2734 | 2772 | |
2735 | 2773 | 復号化関数はありません。 |
2736 | 2774 | この関数は暗号化のためにはまったく役に立ちません(このためには、 |
2737 | 2775 | お近くの CPAN ミラーで F<Crypt> モジュールを探してください)ので、 |
2738 | 2776 | "crypt" という名前は少し間違った名前です。 |
2739 | 2777 | その代わりに、一般的には二つのテキスト片が同じかどうかをテキストそのものを |
2740 | 2778 | 転送したり保管したりせずにチェックするために使います。 |
2741 | 2779 | 例としては、正しいパスワードが与えられたかどうかをチェックがあります。 |
2742 | 2780 | パスワード自身ではなく、パスワードのダイジェストが保管されます。 |
2743 | 2781 | ユーザーがパスワードを入力すると、保管されているダイジェストと同じ |
2744 | 2782 | salt で L<C<crypt>|/crypt PLAINTEXT,SALT> します。 |
2745 | 2783 | 二つのダイジェストが同じなら、パスワードは正しいです。 |
2746 | 2784 | |
2747 | 2785 | =begin original |
2748 | 2786 | |
2749 | 2787 | When verifying an existing digest string you should use the digest as |
2750 | 2788 | the salt (like C<crypt($plain, $digest) eq $digest>). The SALT used |
2751 | 2789 | to create the digest is visible as part of the digest. This ensures |
2752 | 2790 | L<C<crypt>|/crypt PLAINTEXT,SALT> will hash the new string with the same |
2753 | 2791 | salt as the digest. This allows your code to work with the standard |
2754 | 2792 | L<C<crypt>|/crypt PLAINTEXT,SALT> and with more exotic implementations. |
2755 | 2793 | In other words, assume nothing about the returned string itself nor |
2756 | 2794 | about how many bytes of SALT may matter. |
2757 | 2795 | |
2758 | 2796 | =end original |
2759 | 2797 | |
2760 | 2798 | すでにあるダイジェスト文字列を検証するには、ダイジェストを |
2761 | 2799 | (C<crypt($plain, $digest) eq $digest> のようにして)salt として使います。 |
2762 | 2800 | ダイジェストを作るのに使われた SALT はダイジェストの一部として見えます。 |
2763 | 2801 | これにより、L<C<crypt>|/crypt PLAINTEXT,SALT> は同じ salt で新しい文字列を |
2764 | 2802 | ダイジェストとしてハッシュ化できるようにします。 |
2765 | 2803 | これによって標準的な L<C<crypt>|/crypt PLAINTEXT,SALT> や、より風変わりな |
2766 | 2804 | 実装でも動作します。 |
2767 | 2805 | 言い換えると、返される文字列や、SALT が何バイトあるかといったことに対して、 |
2768 | 2806 | どのような仮定もしてはいけません。 |
2769 | 2807 | |
2770 | 2808 | =begin original |
2771 | 2809 | |
2772 | 2810 | Traditionally the result is a string of 13 bytes: two first bytes of |
2773 | 2811 | the salt, followed by 11 bytes from the set C<[./0-9A-Za-z]>, and only |
2774 | 2812 | the first eight bytes of PLAINTEXT mattered. But alternative |
2775 | 2813 | hashing schemes (like MD5), higher level security schemes (like C2), |
2776 | 2814 | and implementations on non-Unix platforms may produce different |
2777 | 2815 | strings. |
2778 | 2816 | |
2779 | 2817 | =end original |
2780 | 2818 | |
2781 | 2819 | 伝統的には結果は 13 バイトの文字列です: 最初の 2 バイトは salt、引き続いて |
2782 | 2820 | 集合 C<[./0-9A-Za-z]> からの 11 バイトで、PLAINTEXT の最初の |
2783 | 2821 | 8 バイトだけが意味があります。 |
2784 | 2822 | しかし、(MD5 のように) 異なったハッシュ手法、 |
2785 | 2823 | (C2 のような) 高レベルセキュリティ手法、非 Unix プラットフォームでの |
2786 | 2824 | 実装などでは異なった文字列が生成されることがあります。 |
2787 | 2825 | |
2788 | 2826 | =begin original |
2789 | 2827 | |
2790 | 2828 | When choosing a new salt create a random two character string whose |
2791 | 2829 | characters come from the set C<[./0-9A-Za-z]> (like C<join '', ('.', |
2792 | 2830 | '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]>). This set of |
2793 | 2831 | characters is just a recommendation; the characters allowed in |
2794 | 2832 | the salt depend solely on your system's crypt library, and Perl can't |
2795 | 2833 | restrict what salts L<C<crypt>|/crypt PLAINTEXT,SALT> accepts. |
2796 | 2834 | |
2797 | 2835 | =end original |
2798 | 2836 | |
2799 | 2837 | 新しい salt を選択する場合は、集合 C<[./0-9A-Za-z]> から |
2800 | 2838 | (C<join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]> の |
2801 | 2839 | ようにして)ランダムに2 つの文字を選びます。 |
2802 | 2840 | この文字集合は単なる推薦です; salt として許される文字はシステムの暗号化 |
2803 | 2841 | ライブラリだけに依存し、Perl は L<C<crypt>|/crypt PLAINTEXT,SALT> が |
2804 | 2842 | どのような salt を受け付けるかについて制限しません。 |
2805 | 2843 | |
2806 | 2844 | =begin original |
2807 | 2845 | |
2808 | 2846 | Here's an example that makes sure that whoever runs this program knows |
2809 | 2847 | their password: |
2810 | 2848 | |
2811 | 2849 | =end original |
2812 | 2850 | |
2813 | 2851 | プログラムを実行する人が、 |
2814 | 2852 | 自分のパスワードを知っていることを確認する例です: |
2815 | 2853 | |
2816 | 2854 | my $pwd = (getpwuid($<))[1]; |
2817 | 2855 | |
2818 | 2856 | system "stty -echo"; |
2819 | 2857 | print "Password: "; |
2820 | 2858 | chomp(my $word = <STDIN>); |
2821 | 2859 | print "\n"; |
2822 | 2860 | system "stty echo"; |
2823 | 2861 | |
2824 | 2862 | if (crypt($word, $pwd) ne $pwd) { |
2825 | 2863 | die "Sorry...\n"; |
2826 | 2864 | } else { |
2827 | 2865 | print "ok\n"; |
2828 | 2866 | } |
2829 | 2867 | |
2830 | 2868 | =begin original |
2831 | 2869 | |
2832 | 2870 | Of course, typing in your own password to whoever asks you |
2833 | 2871 | for it is unwise. |
2834 | 2872 | |
2835 | 2873 | =end original |
2836 | 2874 | |
2837 | 2875 | もちろん、自分自身のパスワードを誰にでも入力するのは賢明ではありません。 |
2838 | 2876 | |
2839 | 2877 | =begin original |
2840 | 2878 | |
2841 | 2879 | The L<C<crypt>|/crypt PLAINTEXT,SALT> function is unsuitable for hashing |
2842 | 2880 | large quantities of data, not least of all because you can't get the |
2843 | 2881 | information back. Look at the L<Digest> module for more robust |
2844 | 2882 | algorithms. |
2845 | 2883 | |
2846 | 2884 | =end original |
2847 | 2885 | |
2848 | 2886 | L<C<crypt>|/crypt PLAINTEXT,SALT> 関数は大量のデータのハッシュ化には |
2849 | 2887 | 向いていません; これは情報を戻せないという理由だけではありません。 |
2850 | 2888 | より頑強なアルゴリズムについては L<Digest> モジュールを参照してください。 |
2851 | 2889 | |
2852 | 2890 | =begin original |
2853 | 2891 | |
2854 | 2892 | If using L<C<crypt>|/crypt PLAINTEXT,SALT> on a Unicode string (which |
2855 | 2893 | I<potentially> has characters with codepoints above 255), Perl tries to |
2856 | 2894 | make sense of the situation by trying to downgrade (a copy of) the |
2857 | 2895 | string back to an eight-bit byte string before calling |
2858 | 2896 | L<C<crypt>|/crypt PLAINTEXT,SALT> (on that copy). If that works, good. |
2859 | 2897 | If not, L<C<crypt>|/crypt PLAINTEXT,SALT> dies with |
2860 | 2898 | L<C<Wide character in crypt>|perldiag/Wide character in %s>. |
2861 | 2899 | |
2862 | 2900 | =end original |
2863 | 2901 | |
2864 | 2902 | Unicode 文字列(I<潜在的には> 255 を越えるコードポイントを持つ文字を |
2865 | 2903 | 含みます)に L<C<crypt>|/crypt PLAINTEXT,SALT> を使った場合、Perl は |
2866 | 2904 | L<C<crypt>|/crypt PLAINTEXT,SALT> を呼び出す前に与えられた |
2867 | 2905 | 文字列を8 ビットバイト文字列にダウングレードする(文字列のコピーを作る) |
2868 | 2906 | ことで状況のつじつまを合わせようとします。 |
2869 | 2907 | うまく動けば、それでよし。 |
2870 | 2908 | 動かなければ、L<C<crypt>|/crypt PLAINTEXT,SALT> は |
2871 | 2909 | L<C<Wide character in crypt>|perldiag/Wide character in %s> という |
2872 | 2910 | メッセージと共に die します。 |
2873 | 2911 | |
2874 | 2912 | =begin original |
2875 | 2913 | |
2876 | 2914 | Portability issues: L<perlport/crypt>. |
2877 | 2915 | |
2878 | 2916 | =end original |
2879 | 2917 | |
2880 | 2918 | 移植性の問題: L<perlport/crypt>。 |
2881 | 2919 | |
2882 | 2920 | =item dbmclose HASH |
2883 | 2921 | X<dbmclose> |
2884 | 2922 | |
2885 | 2923 | =for Pod::Functions breaks binding on a tied dbm file |
2886 | 2924 | |
2887 | 2925 | =begin original |
2888 | 2926 | |
2889 | 2927 | [This function has been largely superseded by the |
2890 | 2928 | L<C<untie>|/untie VARIABLE> function.] |
2891 | 2929 | |
2892 | 2930 | =end original |
2893 | 2931 | |
2894 | 2932 | [この関数は、L<C<untie>|/untie VARIABLE> 関数に大きくとって代わられました。] |
2895 | 2933 | |
2896 | 2934 | =begin original |
2897 | 2935 | |
2898 | 2936 | Breaks the binding between a DBM file and a hash. |
2899 | 2937 | |
2900 | 2938 | =end original |
2901 | 2939 | |
2902 | 2940 | DBM ファイルとハッシュの連結をはずします。 |
2903 | 2941 | |
2904 | 2942 | =begin original |
2905 | 2943 | |
2906 | 2944 | Portability issues: L<perlport/dbmclose>. |
2907 | 2945 | |
2908 | 2946 | =end original |
2909 | 2947 | |
2910 | 2948 | 移植性の問題: L<perlport/dbmclose>。 |
2911 | 2949 | |
2912 | 2950 | =item dbmopen HASH,DBNAME,MASK |
2913 | 2951 | X<dbmopen> X<dbm> X<ndbm> X<sdbm> X<gdbm> |
2914 | 2952 | |
2915 | 2953 | =for Pod::Functions create binding on a tied dbm file |
2916 | 2954 | |
2917 | 2955 | =begin original |
2918 | 2956 | |
2919 | 2957 | [This function has been largely superseded by the |
2920 | 2958 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function.] |
2921 | 2959 | |
2922 | 2960 | =end original |
2923 | 2961 | |
2924 | 2962 | [この関数は、L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数に |
2925 | 2963 | 大きくとって代わられました。] |
2926 | 2964 | |
2927 | 2965 | =begin original |
2928 | 2966 | |
2929 | 2967 | This binds a L<dbm(3)>, L<ndbm(3)>, L<sdbm(3)>, L<gdbm(3)>, or Berkeley |
2930 | 2968 | DB file to a hash. HASH is the name of the hash. (Unlike normal |
2931 | L<C<open>|/open FILEHANDLE,EXPR>, the first argument is I<not> a | |
2969 | L<C<open>|/open FILEHANDLE,MODE,EXPR>, the first argument is I<not> a | |
2932 | 2970 | filehandle, even though it looks like one). DBNAME is the name of the |
2933 | 2971 | database (without the F<.dir> or F<.pag> extension if any). If the |
2934 | 2972 | database does not exist, it is created with protection specified by MASK |
2935 | 2973 | (as modified by the L<C<umask>|/umask EXPR>). To prevent creation of |
2936 | 2974 | the database if it doesn't exist, you may specify a MODE of 0, and the |
2937 | 2975 | function will return a false value if it can't find an existing |
2938 | 2976 | database. If your system supports only the older DBM functions, you may |
2939 | 2977 | make only one L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> call in your |
2940 | 2978 | program. In older versions of Perl, if your system had neither DBM nor |
2941 | 2979 | ndbm, calling L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> produced a fatal |
2942 | 2980 | error; it now falls back to L<sdbm(3)>. |
2943 | 2981 | |
2944 | 2982 | =end original |
2945 | 2983 | |
2946 | 2984 | L<dbm(3)>, L<ndbm(3)>, L<sdbm(3)>, L<gdbm(3)> ファイルまたは |
2947 | 2985 | Berkeley DB ファイルを連想配列に結び付けます。 |
2948 | 2986 | HASH は、その連想配列の名前です。 |
2949 | (普通の L<C<open>|/open FILEHANDLE,EXPR> とは違って、最初の引数は | |
2987 | (普通の L<C<open>|/open FILEHANDLE,MODE,EXPR> とは違って、最初の引数は | |
2950 | 2988 | ファイルハンドル I<ではありません>; まあ、似たようなものですが)。 |
2951 | 2989 | DBNAME は、データベースの名前です (拡張子の .dir や .pag はもしあっても |
2952 | 2990 | つけません)。 |
2953 | 2991 | データベースが存在しなければ、MODE MASK (を L<C<umask>|/umask EXPR> で |
2954 | 2992 | 修正したもの) で指定されたモードで作られます。 |
2955 | 2993 | 存在しないときにデータベースを作成しないようにするには、MODE に 0 を |
2956 | 2994 | 設定でき、データベースを見つけられなかった場合は関数は偽を返します。 |
2957 | 2995 | 古い DBM 関数のみをサポートしているシステムでは、プログラム中で 1 度だけ |
2958 | 2996 | L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を実行することができます。 |
2959 | 2997 | 昔のバージョンの Perl では、DBM も ndbm も持っていないシステムでは、 |
2960 | 2998 | L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を呼び出すと致命的エラーになります; |
2961 | 2999 | 現在では L<sdbm(3)> にフォールバックします。 |
2962 | 3000 | |
2963 | 3001 | =begin original |
2964 | 3002 | |
2965 | 3003 | If you don't have write access to the DBM file, you can only read hash |
2966 | 3004 | variables, not set them. If you want to test whether you can write, |
2967 | 3005 | either use file tests or try setting a dummy hash entry inside an |
2968 | 3006 | L<C<eval>|/eval EXPR> to trap the error. |
2969 | 3007 | |
2970 | 3008 | =end original |
2971 | 3009 | |
2972 | 3010 | DBM ファイルに対して、書き込み権が無いときには、ハッシュ |
2973 | 3011 | 配列を読みだすことだけができ、設定することはできません。 |
2974 | 3012 | 書けるか否かを調べたい場合には、ファイルテスト |
2975 | 3013 | 演算子を使うか、エラーをトラップするための L<C<eval>|/eval EXPR> の中で、 |
2976 | 3014 | ダミーのハッシュエントリを設定してみることになります。 |
2977 | 3015 | |
2978 | 3016 | =begin original |
2979 | 3017 | |
2980 | 3018 | Note that functions such as L<C<keys>|/keys HASH> and |
2981 | 3019 | L<C<values>|/values HASH> may return huge lists when used on large DBM |
2982 | 3020 | files. You may prefer to use the L<C<each>|/each HASH> function to |
2983 | 3021 | iterate over large DBM files. Example: |
2984 | 3022 | |
2985 | 3023 | =end original |
2986 | 3024 | |
2987 | 3025 | 大きな DBM ファイルを扱うときには、L<C<keys>|/keys HASH> や |
2988 | 3026 | L<C<values>|/values HASH> のような関数は、巨大なリストを返します。 |
2989 | 3027 | 大きな DBM ファイルでは、L<C<each>|/each HASH> 関数を使って繰り返しを |
2990 | 3028 | 行なった方が良いかもしれません。 |
2991 | 3029 | 例: |
2992 | 3030 | |
2993 | 3031 | # print out history file offsets |
2994 | 3032 | dbmopen(%HIST,'/usr/lib/news/history',0666); |
2995 | 3033 | while (($key,$val) = each %HIST) { |
2996 | 3034 | print $key, ' = ', unpack('L',$val), "\n"; |
2997 | 3035 | } |
2998 | 3036 | dbmclose(%HIST); |
2999 | 3037 | |
3000 | 3038 | =begin original |
3001 | 3039 | |
3002 | 3040 | See also L<AnyDBM_File> for a more general description of the pros and |
3003 | 3041 | cons of the various dbm approaches, as well as L<DB_File> for a particularly |
3004 | 3042 | rich implementation. |
3005 | 3043 | |
3006 | 3044 | =end original |
3007 | 3045 | |
3008 | 3046 | 様々な dbm 手法に対する利点欠点に関するより一般的な記述および |
3009 | 3047 | 特にリッチな実装である L<DB_File> に関しては |
3010 | 3048 | L<AnyDBM_File> も参照してください。 |
3011 | 3049 | |
3012 | 3050 | =begin original |
3013 | 3051 | |
3014 | 3052 | You can control which DBM library you use by loading that library |
3015 | 3053 | before you call L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>: |
3016 | 3054 | |
3017 | 3055 | =end original |
3018 | 3056 | |
3019 | 3057 | L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を呼び出す前にライブラリを |
3020 | 3058 | 読み込むことで、どの DBM ライブラリを使うかを制御できます: |
3021 | 3059 | |
3022 | 3060 | use DB_File; |
3023 | 3061 | dbmopen(%NS_Hist, "$ENV{HOME}/.netscape/history.db") |
3024 | 3062 | or die "Can't open netscape history file: $!"; |
3025 | 3063 | |
3026 | 3064 | =begin original |
3027 | 3065 | |
3028 | 3066 | Portability issues: L<perlport/dbmopen>. |
3029 | 3067 | |
3030 | 3068 | =end original |
3031 | 3069 | |
3032 | 3070 | 移植性の問題: L<perlport/dbmopen>。 |
3033 | 3071 | |
3034 | 3072 | =item defined EXPR |
3035 | 3073 | X<defined> X<undef> X<undefined> |
3036 | 3074 | |
3037 | 3075 | =item defined |
3038 | 3076 | |
3039 | 3077 | =for Pod::Functions test whether a value, variable, or function is defined |
3040 | 3078 | |
3041 | 3079 | =begin original |
3042 | 3080 | |
3043 | 3081 | Returns a Boolean value telling whether EXPR has a value other than the |
3044 | 3082 | undefined value L<C<undef>|/undef EXPR>. If EXPR is not present, |
3045 | 3083 | L<C<$_>|perlvar/$_> is checked. |
3046 | 3084 | |
3047 | 3085 | =end original |
3048 | 3086 | |
3049 | 3087 | 左辺値 EXPR が未定義値 L<C<undef>|/undef EXPR> 以外の値を持つか否かを示す、 |
3050 | 3088 | ブール値を返します。 |
3051 | 3089 | EXPR がない場合は、L<C<$_>|perlvar/$_> がチェックされます。 |
3052 | 3090 | |
3053 | 3091 | =begin original |
3054 | 3092 | |
3055 | 3093 | Many operations return L<C<undef>|/undef EXPR> to indicate failure, end |
3056 | 3094 | of file, system error, uninitialized variable, and other exceptional |
3057 | 3095 | conditions. This function allows you to distinguish |
3058 | 3096 | L<C<undef>|/undef EXPR> from other values. (A simple Boolean test will |
3059 | 3097 | not distinguish among L<C<undef>|/undef EXPR>, zero, the empty string, |
3060 | 3098 | and C<"0">, which are all equally false.) Note that since |
3061 | 3099 | L<C<undef>|/undef EXPR> is a valid scalar, its presence doesn't |
3062 | 3100 | I<necessarily> indicate an exceptional condition: L<C<pop>|/pop ARRAY> |
3063 | 3101 | returns L<C<undef>|/undef EXPR> when its argument is an empty array, |
3064 | 3102 | I<or> when the element to return happens to be L<C<undef>|/undef EXPR>. |
3065 | 3103 | |
3066 | 3104 | =end original |
3067 | 3105 | |
3068 | 3106 | 多くの演算子が、EOF や未初期化変数、システムエラーといった、 |
3069 | 3107 | 例外的な条件で L<C<undef>|/undef EXPR> を返すようになっています。 |
3070 | 3108 | この関数は、他の値と L<C<undef>|/undef EXPR> とを区別するために使えます。 |
3071 | 3109 | (単純な真偽値テストでは、L<C<undef>|/undef EXPR>、0、C<"0"> のいずれも偽を |
3072 | 3110 | 返すので、区別することができません。) |
3073 | 3111 | L<C<undef>|/undef EXPR> は有効なスカラ値なので、その存在が I<必ずしも> |
3074 | 3112 | 例外的な状況を表すとは限らないということに注意してください: |
3075 | 3113 | L<C<pop>|/pop ARRAY> は引数が空の配列だったときに L<C<undef>|/undef EXPR> を |
3076 | 3114 | 返しますが、I<あるいは> 返すべき要素がたまたま |
3077 | 3115 | L<C<undef>|/undef EXPR> だったのかもしれません。 |
3078 | 3116 | |
3079 | 3117 | =begin original |
3080 | 3118 | |
3081 | 3119 | You may also use C<defined(&func)> to check whether subroutine C<func> |
3082 | 3120 | has ever been defined. The return value is unaffected by any forward |
3083 | 3121 | declarations of C<func>. A subroutine that is not defined |
3084 | 3122 | may still be callable: its package may have an C<AUTOLOAD> method that |
3085 | 3123 | makes it spring into existence the first time that it is called; see |
3086 | 3124 | L<perlsub>. |
3087 | 3125 | |
3088 | 3126 | =end original |
3089 | 3127 | |
3090 | 3128 | C<defined(&func)> とすることでサブルーチン C<func> の存在を、 |
3091 | 3129 | 確かめることもできます。 |
3092 | 3130 | 返り値は C<func> の前方定義には影響されません。 |
3093 | 3131 | 定義されていないサブルーチンも呼び出し可能です: |
3094 | 3132 | 最初に呼び出されたときに存在するようにするための |
3095 | 3133 | C<AUTOLOAD> メソッドを持ったパッケージかもしれません; |
3096 | 3134 | L<perlsub> を参照してください。 |
3097 | 3135 | |
3098 | 3136 | =begin original |
3099 | 3137 | |
3100 | 3138 | Use of L<C<defined>|/defined EXPR> on aggregates (hashes and arrays) is |
3101 | 3139 | no longer supported. It used to report whether memory for that |
3102 | 3140 | aggregate had ever been allocated. You should instead use a simple |
3103 | 3141 | test for size: |
3104 | 3142 | |
3105 | 3143 | =end original |
3106 | 3144 | |
3107 | 3145 | 集合(ハッシュや配列)への L<C<defined>|/defined EXPR> の使用は |
3108 | 3146 | もはや対応していません。 |
3109 | 3147 | これはその集合にメモリが割り当てられたかを報告するのに用いられていました。 |
3110 | 3148 | 代わりにサイズに対する簡単なテストを使うべきです。 |
3111 | 3149 | |
3112 | 3150 | if (@an_array) { print "has array elements\n" } |
3113 | 3151 | if (%a_hash) { print "has hash members\n" } |
3114 | 3152 | |
3115 | 3153 | =begin original |
3116 | 3154 | |
3117 | 3155 | When used on a hash element, it tells you whether the value is defined, |
3118 | 3156 | not whether the key exists in the hash. Use L<C<exists>|/exists EXPR> |
3119 | 3157 | for the latter purpose. |
3120 | 3158 | |
3121 | 3159 | =end original |
3122 | 3160 | |
3123 | 3161 | ハッシュの要素に対して用いると、value が定義されているか否かを |
3124 | 3162 | 返すものであって、ハッシュに key が存在するか否かを返すのではありません。 |
3125 | 3163 | この用途には、L<C<exists>|/exists EXPR> を使ってください。 |
3126 | 3164 | |
3127 | 3165 | =begin original |
3128 | 3166 | |
3129 | 3167 | Examples: |
3130 | 3168 | |
3131 | 3169 | =end original |
3132 | 3170 | |
3133 | 3171 | 例: |
3134 | 3172 | |
3135 | 3173 | print if defined $switch{D}; |
3136 | 3174 | print "$val\n" while defined($val = pop(@ary)); |
3137 | 3175 | die "Can't readlink $sym: $!" |
3138 | 3176 | unless defined($value = readlink $sym); |
3139 | 3177 | sub foo { defined &$bar ? $bar->(@_) : die "No bar"; } |
3140 | 3178 | $debugging = 0 unless defined $debugging; |
3141 | 3179 | |
3142 | 3180 | =begin original |
3143 | 3181 | |
3144 | 3182 | Note: Many folks tend to overuse L<C<defined>|/defined EXPR> and are |
3145 | 3183 | then surprised to discover that the number C<0> and C<""> (the |
3146 | 3184 | zero-length string) are, in fact, defined values. For example, if you |
3147 | 3185 | say |
3148 | 3186 | |
3149 | 3187 | =end original |
3150 | 3188 | |
3151 | 3189 | 注意: 多くの人々が L<C<defined>|/defined EXPR> を使いすぎて、C<0> と |
3152 | 3190 | C<"">(空文字列) が実際のところ定義された値であることに驚くようです。 |
3153 | 3191 | 例えば、以下のように書くと: |
3154 | 3192 | |
3155 | 3193 | "ab" =~ /a(.*)b/; |
3156 | 3194 | |
3157 | 3195 | =begin original |
3158 | 3196 | |
3159 | 3197 | The pattern match succeeds and C<$1> is defined, although it |
3160 | 3198 | matched "nothing". It didn't really fail to match anything. Rather, it |
3161 | 3199 | matched something that happened to be zero characters long. This is all |
3162 | 3200 | very above-board and honest. When a function returns an undefined value, |
3163 | 3201 | it's an admission that it couldn't give you an honest answer. So you |
3164 | 3202 | should use L<C<defined>|/defined EXPR> only when questioning the |
3165 | 3203 | integrity of what you're trying to do. At other times, a simple |
3166 | 3204 | comparison to C<0> or C<""> is what you want. |
3167 | 3205 | |
3168 | 3206 | =end original |
3169 | 3207 | |
3170 | 3208 | パターンマッチングが成功し、C<$1> が定義されても、実際には |
3171 | 3209 | 「なし」にマッチしています。 |
3172 | 3210 | しかしこれは何にもマッチしていないわけではありません。 |
3173 | 3211 | 何かにはマッチしているのですが、たまたまそれが長さ 0 だっただけです。 |
3174 | 3212 | これは非常に率直で正直なことです。 |
3175 | 3213 | 関数が未定義値を返すとき、正直な答えを返すことができないことを |
3176 | 3214 | 告白しています。 |
3177 | 3215 | ですので、あなたが自分がしようとしていることの完全性を確認するときにだけ |
3178 | 3216 | L<C<defined>|/defined EXPR> を使うべきです。 |
3179 | 3217 | その他の場合では、単に C<0> または C<""> と比較するというのがあなたの |
3180 | 3218 | 求めているものです。 |
3181 | 3219 | |
3182 | 3220 | =begin original |
3183 | 3221 | |
3184 | 3222 | See also L<C<undef>|/undef EXPR>, L<C<exists>|/exists EXPR>, |
3185 | 3223 | L<C<ref>|/ref EXPR>. |
3186 | 3224 | |
3187 | 3225 | =end original |
3188 | 3226 | |
3189 | 3227 | L<C<undef>|/undef EXPR>, L<C<exists>|/exists EXPR>, L<C<ref>|/ref EXPR> も |
3190 | 3228 | 参照してください。 |
3191 | 3229 | |
3192 | 3230 | =item delete EXPR |
3193 | 3231 | X<delete> |
3194 | 3232 | |
3195 | 3233 | =for Pod::Functions deletes a value from a hash |
3196 | 3234 | |
3197 | 3235 | =begin original |
3198 | 3236 | |
3199 | 3237 | Given an expression that specifies an element or slice of a hash, |
3200 | 3238 | L<C<delete>|/delete EXPR> deletes the specified elements from that hash |
3201 | 3239 | so that L<C<exists>|/exists EXPR> on that element no longer returns |
3202 | 3240 | true. Setting a hash element to the undefined value does not remove its |
3203 | 3241 | key, but deleting it does; see L<C<exists>|/exists EXPR>. |
3204 | 3242 | |
3205 | 3243 | =end original |
3206 | 3244 | |
3207 | 3245 | ハッシュの要素やスライスを指定する式を取り、L<C<delete>|/delete EXPR> は |
3208 | 3246 | 指定された要素をハッシュから削除するので、 |
3209 | 3247 | その要素に対する L<C<exists>|/exists EXPR> はもはや真を返さなくなります。 |
3210 | 3248 | ハッシュ要素に未定義値をセットしてもそのキーは削除されませんが、 |
3211 | 3249 | delete では削除されます; L<C<exists>|/exists EXPR> を参照してください。 |
3212 | 3250 | |
3213 | 3251 | =begin original |
3214 | 3252 | |
3215 | In list context, returns the value or values deleted, or the last such | |
3253 | In list context, usually returns the value or values deleted, or the last such | |
3216 | element in scalar context. The return list's length | |
3254 | element in scalar context. The return list's length corresponds to that of | |
3217 | 3255 | the argument list: deleting non-existent elements returns the undefined value |
3218 | in their corresponding positions. | |
3256 | in their corresponding positions. When a | |
3257 | L<keyE<sol>value hash slice|perldata/KeyE<sol>Value Hash Slices> is passed to | |
3258 | C<delete>, the return value is a list of key/value pairs (two elements for each | |
3259 | item deleted from the hash). | |
3219 | 3260 | |
3220 | 3261 | =end original |
3221 | 3262 | |
3222 | リストコンテキストでは削除された要素を返し、スカラコンテキストでは | |
3263 | リストコンテキストでは通常は削除された要素を返し、スカラコンテキストでは | |
3223 | 3264 | 削除された要素のうち最後のものを返します。 |
3224 | 返されたリストの長さは常に引数リストの長さ | |
3265 | 返されたリストの長さは常に引数リストの長さに対応します: | |
3225 | 3266 | 存在しない要素を削除すると、対応する位置に未定義値をセットして返します。 |
3267 | L<キーE<sol>値ハッシュスライス|perldata/KeyE<sol>Value Hash Slices> が | |
3268 | C<delete> に渡されると、返り値はキー/値の組(それぞれのアイテムについて | |
3269 | 二つの要素が元のハッシュから削除されたもの)です。 | |
3226 | 3270 | |
3227 | 3271 | =begin original |
3228 | 3272 | |
3229 | 3273 | L<C<delete>|/delete EXPR> may also be used on arrays and array slices, |
3230 | 3274 | but its behavior is less straightforward. Although |
3231 | 3275 | L<C<exists>|/exists EXPR> will return false for deleted entries, |
3232 | 3276 | deleting array elements never changes indices of existing values; use |
3233 | 3277 | L<C<shift>|/shift ARRAY> or L<C<splice>|/splice |
3234 | 3278 | ARRAY,OFFSET,LENGTH,LIST> for that. However, if any deleted elements |
3235 | 3279 | fall at the end of an array, the array's size shrinks to the position of |
3236 | 3280 | the highest element that still tests true for L<C<exists>|/exists EXPR>, |
3237 | 3281 | or to 0 if none do. In other words, an array won't have trailing |
3238 | 3282 | nonexistent elements after a delete. |
3239 | 3283 | |
3240 | 3284 | =end original |
3241 | 3285 | |
3242 | 3286 | L<C<delete>|/delete EXPR> は配列や配列のスライスに対しても使えますが、その |
3243 | 3287 | 振る舞いはあまり直感的ではありません。 |
3244 | 3288 | 削除されたエントリに対しては L<C<exists>|/exists EXPR> は偽を返しますが、 |
3245 | 3289 | 配列要素を削除しても、存在する値の添え字は変わりません; このためには |
3246 | 3290 | L<C<shift>|/shift ARRAY> や L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> を |
3247 | 3291 | 使ってください。 |
3248 | 3292 | しかし、削除された要素が配列の末尾であった場合、配列のサイズは |
3249 | 3293 | L<C<exists>|/exists EXPR> が真となる最大位置の要素(それがない場合は 0)に |
3250 | 3294 | 切り詰められます。 |
3251 | 3295 | 言い換えると、delete の後には配列の末尾に値のない要素はありません。 |
3252 | 3296 | |
3253 | 3297 | =begin original |
3254 | 3298 | |
3255 | 3299 | B<WARNING:> Calling L<C<delete>|/delete EXPR> on array values is |
3256 | 3300 | strongly discouraged. The |
3257 | 3301 | notion of deleting or checking the existence of Perl array elements is not |
3258 | 3302 | conceptually coherent, and can lead to surprising behavior. |
3259 | 3303 | |
3260 | 3304 | =end original |
3261 | 3305 | |
3262 | 3306 | B<警告:> 配列の値に対して L<C<delete>|/delete EXPR> を呼び出すことは強く |
3263 | 3307 | 非推奨です。 |
3264 | 3308 | Perl の配列要素を削除したり存在を調べたりする記法は概念的に一貫しておらず、 |
3265 | 3309 | 驚くべき振る舞いを引き起こすことがあります。 |
3266 | 3310 | |
3267 | 3311 | =begin original |
3268 | 3312 | |
3269 | 3313 | Deleting from L<C<%ENV>|perlvar/%ENV> modifies the environment. |
3270 | 3314 | Deleting from a hash tied to a DBM file deletes the entry from the DBM |
3271 | 3315 | file. Deleting from a L<C<tied>|/tied VARIABLE> hash or array may not |
3272 | 3316 | necessarily return anything; it depends on the implementation of the |
3273 | 3317 | L<C<tied>|/tied VARIABLE> package's DELETE method, which may do whatever |
3274 | 3318 | it pleases. |
3275 | 3319 | |
3276 | 3320 | =end original |
3277 | 3321 | |
3278 | 3322 | L<C<%ENV>|perlvar/%ENV> から削除を行なうと、実際に環境変数を変更します。 |
3279 | 3323 | DBM ファイルに tie された配列からの削除は、その DBM ファイルからエントリを |
3280 | 3324 | 削除します。 |
3281 | 3325 | しかし、L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> されたハッシュや配列からの |
3282 | 3326 | 削除は、値を返すとは限りません; これは |
3283 | 3327 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> されたパッケージの DELETE |
3284 | 3328 | メソッドの実装に依存するので、どんなことでも起こります。 |
3285 | 3329 | |
3286 | 3330 | =begin original |
3287 | 3331 | |
3288 | 3332 | The C<delete local EXPR> construct localizes the deletion to the current |
3289 | 3333 | block at run time. Until the block exits, elements locally deleted |
3290 | 3334 | temporarily no longer exist. See L<perlsub/"Localized deletion of elements |
3291 | 3335 | of composite types">. |
3292 | 3336 | |
3293 | 3337 | =end original |
3294 | 3338 | |
3295 | 3339 | C<delete local EXPR> 構文は、現在のブロックの削除を実行時にローカル化します。 |
3296 | 3340 | ブロックから出るまで、ローカルで削除された要素は存在しなくなります。 |
3297 | 3341 | L<perlsub/"Localized deletion of elements of composite types"> を |
3298 | 3342 | 参照してください。 |
3299 | 3343 | |
3300 | 3344 | my %hash = (foo => 11, bar => 22, baz => 33); |
3301 | 3345 | my $scalar = delete $hash{foo}; # $scalar is 11 |
3302 | 3346 | $scalar = delete @hash{qw(foo bar)}; # $scalar is 22 |
3303 | 3347 | my @array = delete @hash{qw(foo baz)}; # @array is (undef,33) |
3304 | 3348 | |
3305 | 3349 | =begin original |
3306 | 3350 | |
3307 | 3351 | The following (inefficiently) deletes all the values of %HASH and @ARRAY: |
3308 | 3352 | |
3309 | 3353 | =end original |
3310 | 3354 | |
3311 | 3355 | 以下は、%HASH と @ARRAY のすべての値を(非効率的に)削除します: |
3312 | 3356 | |
3313 | 3357 | foreach my $key (keys %HASH) { |
3314 | 3358 | delete $HASH{$key}; |
3315 | 3359 | } |
3316 | 3360 | |
3317 | 3361 | foreach my $index (0 .. $#ARRAY) { |
3318 | 3362 | delete $ARRAY[$index]; |
3319 | 3363 | } |
3320 | 3364 | |
3321 | 3365 | =begin original |
3322 | 3366 | |
3323 | 3367 | And so do these: |
3324 | 3368 | |
3325 | 3369 | =end original |
3326 | 3370 | |
3327 | 3371 | そして以下のようにもできます: |
3328 | 3372 | |
3329 | 3373 | delete @HASH{keys %HASH}; |
3330 | 3374 | |
3331 | 3375 | delete @ARRAY[0 .. $#ARRAY]; |
3332 | 3376 | |
3333 | 3377 | =begin original |
3334 | 3378 | |
3335 | 3379 | But both are slower than assigning the empty list |
3336 | 3380 | or undefining %HASH or @ARRAY, which is the customary |
3337 | 3381 | way to empty out an aggregate: |
3338 | 3382 | |
3339 | 3383 | =end original |
3340 | 3384 | |
3341 | 3385 | しかし、これら二つは両方とも、構造を空にするための慣習的な方法である、 |
3342 | 3386 | 単に空リストを代入するか、%HASH や @ARRAY を |
3343 | 3387 | undef するより遅いです: |
3344 | 3388 | |
3345 | 3389 | %HASH = (); # completely empty %HASH |
3346 | 3390 | undef %HASH; # forget %HASH ever existed |
3347 | 3391 | |
3348 | 3392 | @ARRAY = (); # completely empty @ARRAY |
3349 | 3393 | undef @ARRAY; # forget @ARRAY ever existed |
3350 | 3394 | |
3351 | 3395 | =begin original |
3352 | 3396 | |
3353 | 3397 | The EXPR can be arbitrarily complicated provided its |
3354 | 3398 | final operation is an element or slice of an aggregate: |
3355 | 3399 | |
3356 | 3400 | =end original |
3357 | 3401 | |
3358 | 3402 | 最終的な操作が集合の要素かスライスである限りは、 |
3359 | 3403 | いずれかである限りは、EXPR には任意の複雑な式を置くことができます: |
3360 | 3404 | |
3361 | 3405 | delete $ref->[$x][$y]{$key}; |
3362 | 3406 | delete @{$ref->[$x][$y]}{$key1, $key2, @morekeys}; |
3363 | 3407 | |
3364 | 3408 | delete $ref->[$x][$y][$index]; |
3365 | 3409 | delete @{$ref->[$x][$y]}[$index1, $index2, @moreindices]; |
3366 | 3410 | |
3367 | 3411 | =item die LIST |
3368 | 3412 | X<die> X<throw> X<exception> X<raise> X<$@> X<abort> |
3369 | 3413 | |
3370 | 3414 | =for Pod::Functions raise an exception or bail out |
3371 | 3415 | |
3372 | 3416 | =begin original |
3373 | 3417 | |
3374 | L<C<die>|/die LIST> raises an exception. Inside an | |
3418 | L<C<die>|/die LIST> raises an exception. Inside an L<C<eval>|/eval EXPR> | |
3375 | ||
3419 | the exception is stuffed into L<C<$@>|perlvar/$@> and the L<C<eval>|/eval | |
3376 | ||
3420 | EXPR> is terminated with the undefined value. If the exception is | |
3377 | ||
3421 | outside of all enclosing L<C<eval>|/eval EXPR>s, then the uncaught | |
3378 | ||
3422 | exception is printed to C<STDERR> and perl exits with an exit code | |
3379 | ||
3423 | indicating failure. If you need to exit the process with a specific | |
3380 | ||
3424 | exit code, see L<C<exit>|/exit EXPR>. | |
3381 | 3425 | |
3382 | 3426 | =end original |
3383 | 3427 | |
3384 | 3428 | L<C<die>|/die LIST> は例外を発生させます。 |
3385 | L<C<eval>|/eval EXPR> の中で使用すると、 | |
3429 | L<C<eval>|/eval EXPR> の中で使用すると、例外が | |
3386 | 3430 | L<C<$@>|perlvar/$@> に入り、L<C<eval>|/eval EXPR> は |
3387 | 3431 | 未定義値を返して終了します。 |
3388 | 3432 | 例外が全ての L<C<eval>|/eval EXPR> の外側の場合は、捕捉されなかった例外は |
3389 | ||
3433 | C<STDERR> に表示され、perl は失敗を示す終了コードで終了します。 | |
3390 | 3434 | 特定の終了コードでプロセスを終了させる必要がある場合は、 |
3391 | 3435 | L<C<exit>|/exit EXPR> を参照してください。 |
3392 | 3436 | |
3393 | 3437 | =begin original |
3394 | 3438 | |
3395 | 3439 | Equivalent examples: |
3396 | 3440 | |
3397 | 3441 | =end original |
3398 | 3442 | |
3399 | 3443 | 等価な例: |
3400 | 3444 | |
3401 | 3445 | die "Can't cd to spool: $!\n" unless chdir '/usr/spool/news'; |
3402 | 3446 | chdir '/usr/spool/news' or die "Can't cd to spool: $!\n" |
3403 | 3447 | |
3404 | 3448 | =begin original |
3405 | 3449 | |
3406 | ||
3450 | Most of the time, C<die> is called with a string to use as the exception. | |
3407 | ||
3451 | You may either give a single non-reference operand to serve as the | |
3408 | ||
3452 | exception, or a list of two or more items, which will be stringified | |
3453 | and concatenated to make the exception. | |
3454 | ||
3455 | =end original | |
3456 | ||
3457 | ほとんどの場合、C<die> は例外として使うための文字列と共に呼び出されます。 | |
3458 | 例外として圧から割れる単一の非リファレンスオペランドか、 | |
3459 | 例外を作るために文字列化されて連結される、二つ以上のアイテムのリストを | |
3460 | 指定することができます。 | |
3461 | ||
3462 | =begin original | |
3463 | ||
3464 | If the string exception does not end in a newline, the current | |
3465 | script line number and input line number (if any) and a newline | |
3466 | are appended to it. Note that the "input line number" (also | |
3409 | 3467 | known as "chunk") is subject to whatever notion of "line" happens to |
3410 | 3468 | be currently in effect, and is also available as the special variable |
3411 | 3469 | L<C<$.>|perlvar/$.>. See L<perlvar/"$/"> and L<perlvar/"$.">. |
3412 | 3470 | |
3413 | 3471 | =end original |
3414 | 3472 | |
3415 | ||
3473 | 文字列例外が改行で終わっていなければ、その時点のスクリプト名と | |
3416 | スクリプトの行番号、(もしあれば) 入力ファイルの行番号と改行文字が | |
3474 | スクリプトの行番号、(もしあれば) 入力ファイルの行番号と改行文字が | |
3417 | ||
3475 | それに追加されます。 | |
3418 | 3476 | 「入力行番号」("chunk" とも呼ばれます)は「行」という概念が現在有効であると |
3419 | 3477 | 仮定しています; また特殊変数 L<C<$.>|perlvar/$.> でも利用可能です。 |
3420 | 3478 | L<perlvar/"$/"> と L<perlvar/"$."> も参照してください。 |
3421 | 3479 | |
3422 | 3480 | =begin original |
3423 | 3481 | |
3424 | 3482 | Hint: sometimes appending C<", stopped"> to your message will cause it |
3425 | 3483 | to make better sense when the string C<"at foo line 123"> is appended. |
3426 | 3484 | Suppose you are running script "canasta". |
3427 | 3485 | |
3428 | 3486 | =end original |
3429 | 3487 | |
3430 | 3488 | ヒント: メッセージの最後を C<", stopped"> のようなもので |
3431 | 3489 | 終わるようにしておけば、C<"at foo line 123"> のように |
3432 | 3490 | 追加されて、わかりやすくなります。 |
3433 | 3491 | "canasta" というスクリプトを実行しているとします。 |
3434 | 3492 | |
3435 | 3493 | die "/etc/games is no good"; |
3436 | 3494 | die "/etc/games is no good, stopped"; |
3437 | 3495 | |
3438 | 3496 | =begin original |
3439 | 3497 | |
3440 | 3498 | produce, respectively |
3441 | 3499 | |
3442 | 3500 | =end original |
3443 | 3501 | |
3444 | 3502 | これは、それぞれ以下のように表示します。 |
3445 | 3503 | |
3446 | 3504 | /etc/games is no good at canasta line 123. |
3447 | 3505 | /etc/games is no good, stopped at canasta line 123. |
3448 | 3506 | |
3449 | 3507 | =begin original |
3450 | 3508 | |
3451 | If | |
3509 | If LIST was empty or made an empty string, and L<C<$@>|perlvar/$@> | |
3452 | (typically from a previous | |
3510 | already contains an exception value (typically from a previous | |
3511 | L<C<eval>|/eval EXPR>), then that value is reused after | |
3453 | 3512 | appending C<"\t...propagated">. This is useful for propagating exceptions: |
3454 | 3513 | |
3455 | 3514 | =end original |
3456 | 3515 | |
3457 | 出力が空 | |
3516 | 出力が空か空文字列を作り、L<C<$@>|perlvar/$@> が | |
3458 | ||
3517 | (典型的には前回の L<C<eval>|/eval EXPR> で) | |
3518 | 既に例外値を持っている場合、 | |
3519 | 値は C<"\t...propagated"> を追加した後再利用されます。 | |
3459 | 3520 | これは例外を伝播させる場合に有効です: |
3460 | 3521 | |
3461 | 3522 | eval { ... }; |
3462 | 3523 | die unless $@ =~ /Expected exception/; |
3463 | 3524 | |
3464 | 3525 | =begin original |
3465 | 3526 | |
3466 | If | |
3527 | If LIST was empty or made an empty string, | |
3528 | and L<C<$@>|perlvar/$@> contains an object | |
3467 | 3529 | reference that has a C<PROPAGATE> method, that method will be called |
3468 | 3530 | with additional file and line number parameters. The return value |
3469 | 3531 | replaces the value in L<C<$@>|perlvar/$@>; i.e., as if |
3470 | 3532 | C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >> were called. |
3471 | 3533 | |
3472 | 3534 | =end original |
3473 | 3535 | |
3474 | 出力が空 | |
3536 | 出力が空か空文字列を作り、L<C<$@>|perlvar/$@> が C<PROPAGATE> メソッドを | |
3475 | リファレンスを含む場合、 | |
3537 | 含むオブジェクトへのリファレンスを含む場合、 | |
3476 | 呼び出されます。 | |
3538 | このメソッドが追加ファイルと行番号を引数として呼び出されます。 | |
3477 | 3539 | 返り値は L<C<$@>|perlvar/$@> の値を置き換えます; |
3478 | 3540 | つまり、C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >> が |
3479 | 3541 | 呼び出されたかのようになります。 |
3480 | 3542 | |
3481 | 3543 | =begin original |
3482 | 3544 | |
3483 | If L | |
3545 | If LIST was empty or made an empty string, and L<C<$@>|perlvar/$@> | |
3546 | is also empty, then the string C<"Died"> is used. | |
3484 | 3547 | |
3485 | 3548 | =end original |
3486 | 3549 | |
3487 | L<C<$@>|perlvar/$@> | |
3550 | LIST が空か空文字列を作り、L<C<$@>|perlvar/$@> も空の場合、 | |
3551 | C<"Died"> が使われます。 | |
3488 | 3552 | |
3489 | 3553 | =begin original |
3490 | 3554 | |
3555 | You can also call L<C<die>|/die LIST> with a reference argument, and if | |
3556 | this is trapped within an L<C<eval>|/eval EXPR>, L<C<$@>|perlvar/$@> | |
3557 | contains that reference. This permits more elaborate exception handling | |
3558 | using objects that maintain arbitrary state about the exception. Such a | |
3559 | scheme is sometimes preferable to matching particular string values of | |
3560 | L<C<$@>|perlvar/$@> with regular expressions. | |
3561 | ||
3562 | =end original | |
3563 | ||
3564 | L<C<die>|/die LIST> はリファレンス引数と共に呼び出すこともでき、これが | |
3565 | L<C<eval>|/eval EXPR> 内部でトラップされた場合、L<C<$@>|perlvar/$@> は | |
3566 | そのリファレンスを持ちます。 | |
3567 | これは、例外の性質について任意の状態を管理するオブジェクトを使った | |
3568 | より複雑な例外処理の実装を可能にします。 | |
3569 | このようなスキームは L<C<$@>|perlvar/$@> の特定の文字列値を正規表現を使って | |
3570 | マッチングするときに時々好まれます。 | |
3571 | ||
3572 | =begin original | |
3573 | ||
3574 | Because Perl stringifies uncaught exception messages before display, | |
3575 | you'll probably want to overload stringification operations on | |
3576 | exception objects. See L<overload> for details about that. | |
3577 | The stringified message should be non-empty, and should end in a newline, | |
3578 | in order to fit in with the treatment of string exceptions. | |
3579 | Also, because an exception object reference cannot be stringified | |
3580 | without destroying it, Perl doesn't attempt to append location or other | |
3581 | information to a reference exception. If you want location information | |
3582 | with a complex exception object, you'll have to arrange to put the | |
3583 | location information into the object yourself. | |
3584 | ||
3585 | =end original | |
3586 | ||
3587 | perl は捕らえられなかった例外のメッセージを表示する前に文字列化するので、 | |
3588 | このようなカスタム例外オブジェクトの文字列化をオーバーロードしたいと | |
3589 | 思うかもしれません。 | |
3590 | これに関する詳細は L<overload> を参照してください。 | |
3591 | 文字列化されたメッセージは、文字列例外の扱いに合わせるために、 | |
3592 | 空ではなく、末尾は改行であるべきです。 | |
3593 | また、例外オブジェクトリファレンスはそれを破壊することなく | |
3594 | 文字列化することができないので、Perl はリファレンス例外に位置や | |
3595 | その他の情報を追加しようとしません。 | |
3596 | 複雑な例外オブジェクトに位置情報が欲しい場合、 | |
3597 | オブジェクト自身に位置情報を設定するように用意する必要があります。 | |
3598 | ||
3599 | =begin original | |
3600 | ||
3601 | Because L<C<$@>|perlvar/$@> is a global variable, be careful that | |
3602 | analyzing an exception caught by C<eval> doesn't replace the reference | |
3603 | in the global variable. It's | |
3604 | easiest to make a local copy of the reference before any manipulations. | |
3605 | Here's an example: | |
3606 | ||
3607 | =end original | |
3608 | ||
3609 | L<C<$@>|perlvar/$@> はグローバル変数なので、 | |
3610 | C<eval> により補足された例外の解析はグローバル変数の | |
3611 | リファレンスを置き換えないことに注意を払わなければなりません。 | |
3612 | 他の操作をする前にリファレンスのローカルコピーを | |
3613 | 作るのが一番簡単です。 | |
3614 | 以下に例を示します: | |
3615 | ||
3616 | use Scalar::Util "blessed"; | |
3617 | ||
3618 | eval { ... ; die Some::Module::Exception->new( FOO => "bar" ) }; | |
3619 | if (my $ev_err = $@) { | |
3620 | if (blessed($ev_err) | |
3621 | && $ev_err->isa("Some::Module::Exception")) { | |
3622 | # handle Some::Module::Exception | |
3623 | } | |
3624 | else { | |
3625 | # handle all other possible exceptions | |
3626 | } | |
3627 | } | |
3628 | ||
3629 | =begin original | |
3630 | ||
3491 | 3631 | If an uncaught exception results in interpreter exit, the exit code is |
3492 | 3632 | determined from the values of L<C<$!>|perlvar/$!> and |
3493 | 3633 | L<C<$?>|perlvar/$?> with this pseudocode: |
3494 | 3634 | |
3495 | 3635 | =end original |
3496 | 3636 | |
3497 | 3637 | 例外が捕捉されないとインタプリタは終了し、終了コードは以下の |
3498 | 3638 | 擬似コードのように、L<C<$!>|perlvar/$!> と L<C<$?>|perlvar/$?> の値から |
3499 | 3639 | 決定されます: |
3500 | 3640 | |
3501 | 3641 | exit $! if $!; # errno |
3502 | 3642 | exit $? >> 8 if $? >> 8; # child exit status |
3503 | 3643 | exit 255; # last resort |
3504 | 3644 | |
3505 | 3645 | =begin original |
3506 | 3646 | |
3507 | 3647 | As with L<C<exit>|/exit EXPR>, L<C<$?>|perlvar/$?> is set prior to |
3508 | 3648 | unwinding the call stack; any C<DESTROY> or C<END> handlers can then |
3509 | 3649 | alter this value, and thus Perl's exit code. |
3510 | 3650 | |
3511 | 3651 | =end original |
3512 | 3652 | |
3513 | 3653 | L<C<exit>|/exit EXPR> と同様に、コールスタックを巻き戻す前に |
3514 | 3654 | L<C<$?>|perlvar/$?> が設定されます; C<DESTROY> と C<END> のハンドラが |
3515 | 3655 | それからこの値を変更して、これが Perl の終了コードになります。 |
3516 | 3656 | |
3517 | 3657 | =begin original |
3518 | 3658 | |
3519 | 3659 | The intent is to squeeze as much possible information about the likely cause |
3520 | 3660 | into the limited space of the system exit code. However, as |
3521 | 3661 | L<C<$!>|perlvar/$!> is the value of C's C<errno>, which can be set by |
3522 | 3662 | any system call, this means that the value of the exit code used by |
3523 | 3663 | L<C<die>|/die LIST> can be non-predictable, so should not be relied |
3524 | 3664 | upon, other than to be non-zero. |
3525 | 3665 | |
3526 | 3666 | =end original |
3527 | 3667 | |
3528 | 3668 | この意図は、できるだけ多くの似たような原因に関する情報を、システム終了 |
3529 | 3669 | コードという限られた領域に圧縮することです。 |
3530 | 3670 | しかし、L<C<$!>|perlvar/$!> はシステムコールによって設定される可能性がある C の |
3531 | 3671 | C<errno> の値であり、L<C<die>|/die LIST> によって使われる終了コードの値は |
3532 | 3672 | 予測不能であることを意味するので、非 0 ということ以上にこの値に |
3533 | 3673 | 依存するべきではありません。 |
3534 | 3674 | |
3535 | 3675 | =begin original |
3536 | 3676 | |
3537 | You can also call L<C<die>|/die LIST> with a reference argument, and if | |
3538 | this is trapped within an L<C<eval>|/eval EXPR>, L<C<$@>|perlvar/$@> | |
3539 | contains that reference. This permits more elaborate exception handling | |
3540 | using objects that maintain arbitrary state about the exception. Such a | |
3541 | scheme is sometimes preferable to matching particular string values of | |
3542 | L<C<$@>|perlvar/$@> with regular expressions. Because | |
3543 | L<C<$@>|perlvar/$@> is a global variable and L<C<eval>|/eval EXPR> may | |
3544 | be used within object implementations, be careful that analyzing the | |
3545 | error object doesn't replace the reference in the global variable. It's | |
3546 | easiest to make a local copy of the reference before any manipulations. | |
3547 | Here's an example: | |
3548 | ||
3549 | =end original | |
3550 | ||
3551 | L<C<die>|/die LIST> はリファレンス引数と共に呼び出すこともでき、これが | |
3552 | L<C<eval>|/eval EXPR> 内部でトラップされた場合、L<C<$@>|perlvar/$@> は | |
3553 | そのリファレンスを持ちます。 | |
3554 | これは、例外の性質について任意の状態を管理するオブジェクトを使った | |
3555 | より複雑な例外処理の実装を可能にします。 | |
3556 | このようなスキームは L<C<$@>|perlvar/$@> の特定の文字列値を正規表現を使って | |
3557 | マッチングするときに時々好まれます。 | |
3558 | L<C<$@>|perlvar/$@> はグローバル変数で、L<C<eval>|/eval EXPR> はオブジェクト | |
3559 | 実装の内部で使われることがあるので、エラーオブジェクトの解析はグローバル変数の | |
3560 | リファレンスを置き換えないことに注意を払わなければなりません。 | |
3561 | 他の操作をする前にリファレンスのローカルコピーを | |
3562 | 作るのが一番簡単です。 | |
3563 | 以下に例を示します: | |
3564 | ||
3565 | use Scalar::Util "blessed"; | |
3566 | ||
3567 | eval { ... ; die Some::Module::Exception->new( FOO => "bar" ) }; | |
3568 | if (my $ev_err = $@) { | |
3569 | if (blessed($ev_err) | |
3570 | && $ev_err->isa("Some::Module::Exception")) { | |
3571 | # handle Some::Module::Exception | |
3572 | } | |
3573 | else { | |
3574 | # handle all other possible exceptions | |
3575 | } | |
3576 | } | |
3577 | ||
3578 | =begin original | |
3579 | ||
3580 | Because Perl stringifies uncaught exception messages before display, | |
3581 | you'll probably want to overload stringification operations on | |
3582 | exception objects. See L<overload> for details about that. | |
3583 | ||
3584 | =end original | |
3585 | ||
3586 | perl は捕らえられなかった例外のメッセージを表示する前に文字列化するので、 | |
3587 | このようなカスタム例外オブジェクトの文字列化をオーバーロードしたいと | |
3588 | 思うかもしれません。 | |
3589 | これに関する詳細は L<overload> を参照してください。 | |
3590 | ||
3591 | =begin original | |
3592 | ||
3593 | 3677 | You can arrange for a callback to be run just before the |
3594 | 3678 | L<C<die>|/die LIST> does its deed, by setting the |
3595 | 3679 | L<C<$SIG{__DIE__}>|perlvar/%SIG> hook. The associated handler is called |
3596 | with the e | |
3680 | with the exception as an argument, and can change the exception, | |
3681 | if it sees fit, by | |
3597 | 3682 | calling L<C<die>|/die LIST> again. See L<perlvar/%SIG> for details on |
3598 | 3683 | setting L<C<%SIG>|perlvar/%SIG> entries, and L<C<eval>|/eval EXPR> for some |
3599 | 3684 | examples. Although this feature was to be run only right before your |
3600 | 3685 | program was to exit, this is not currently so: the |
3601 | 3686 | L<C<$SIG{__DIE__}>|perlvar/%SIG> hook is currently called even inside |
3602 | 3687 | L<C<eval>|/eval EXPR>ed blocks/strings! If one wants the hook to do |
3603 | 3688 | nothing in such situations, put |
3604 | 3689 | |
3605 | 3690 | =end original |
3606 | 3691 | |
3607 | 3692 | L<C<$SIG{__DIE__}>|perlvar/%SIG> フックをセットすることで、 |
3608 | 3693 | L<C<die>|/die LIST> がその行動を行う |
3609 | 3694 | 直前に実行されるコールバックを設定できます。 |
3610 | 結び付けられたハンドラは | |
3695 | 結び付けられたハンドラは例外を引数として呼び出され、 | |
3611 | 必要なら再び L<C<die>|/die LIST> を呼び出すことで | |
3696 | 必要なら再び L<C<die>|/die LIST> を呼び出すことで例外を変更できます。 | |
3612 | 変更できます。 | |
3613 | 3697 | L<C<%SIG>|perlvar/%SIG> のエントリをセットする詳細については、 |
3614 | 3698 | L<perlvar/%SIG> を、例については L<C<eval>|/eval EXPR> を参照してください。 |
3615 | 3699 | この機能はプログラムが終了しようとする前に 1 回だけ実行していましたが、 |
3616 | 3700 | 現在ではそうではありません: |
3617 | 3701 | L<C<$SIG{__DIE__}>|perlvar/%SIG> フックは L<C<eval>|/eval EXPR> された |
3618 | 3702 | ブロック/文字列の中でも呼ばれるのです! |
3619 | 3703 | もしそのような状況で何もしなくない時は: |
3620 | 3704 | |
3621 | 3705 | die @_ if $^S; |
3622 | 3706 | |
3623 | 3707 | =begin original |
3624 | 3708 | |
3625 | 3709 | as the first line of the handler (see L<perlvar/$^S>). Because |
3626 | 3710 | this promotes strange action at a distance, this counterintuitive |
3627 | 3711 | behavior may be fixed in a future release. |
3628 | 3712 | |
3629 | 3713 | =end original |
3630 | 3714 | |
3631 | 3715 | をハンドラの最初の行に置いてください(L<perlvar/$^S> を参照してください)。 |
3632 | 3716 | これは離れたところで不思議な行動を引き起こすので、 |
3633 | 3717 | この直感的でない振る舞いは将来のリリースで修正されるかもしれません。 |
3634 | 3718 | |
3635 | 3719 | =begin original |
3636 | 3720 | |
3637 | 3721 | See also L<C<exit>|/exit EXPR>, L<C<warn>|/warn LIST>, and the L<Carp> |
3638 | 3722 | module. |
3639 | 3723 | |
3640 | 3724 | =end original |
3641 | 3725 | |
3642 | 3726 | L<C<exit>|/exit EXPR> と L<C<warn>|/warn LIST> と L<Carp> モジュールも |
3643 | 3727 | 参照してください。 |
3644 | 3728 | |
3645 | 3729 | =item do BLOCK |
3646 | 3730 | X<do> X<block> |
3647 | 3731 | |
3648 | 3732 | =for Pod::Functions turn a BLOCK into a TERM |
3649 | 3733 | |
3650 | 3734 | =begin original |
3651 | 3735 | |
3652 | 3736 | Not really a function. Returns the value of the last command in the |
3653 | 3737 | sequence of commands indicated by BLOCK. When modified by the C<while> or |
3654 | 3738 | C<until> loop modifier, executes the BLOCK once before testing the loop |
3655 | 3739 | condition. (On other statements the loop modifiers test the conditional |
3656 | 3740 | first.) |
3657 | 3741 | |
3658 | 3742 | =end original |
3659 | 3743 | |
3660 | 3744 | 実際は関数ではありません。 |
3661 | 3745 | BLOCK で示されるコマンド列の最後の値を返します。 |
3662 | 3746 | C<while> や C<until> ループ修飾子で修飾すると、 |
3663 | 3747 | ループ条件を調べる前に 1 度、BLOCK を実行します。 |
3664 | 3748 | (これ以外の実行文は、ループ修飾子により、条件が最初に |
3665 | 3749 | 調べられます。) |
3666 | 3750 | |
3667 | 3751 | =begin original |
3668 | 3752 | |
3669 | 3753 | C<do BLOCK> does I<not> count as a loop, so the loop control statements |
3670 | 3754 | L<C<next>|/next LABEL>, L<C<last>|/last LABEL>, or |
3671 | 3755 | L<C<redo>|/redo LABEL> cannot be used to leave or restart the block. |
3672 | 3756 | See L<perlsyn> for alternative strategies. |
3673 | 3757 | |
3674 | 3758 | =end original |
3675 | 3759 | |
3676 | 3760 | C<do BLOCK> はループとしては I<扱われません>; 従って、L<C<next>|/next LABEL>, |
3677 | 3761 | L<C<last>|/last LABEL>,L<C<redo>|/redo LABEL> といったループ制御文は |
3678 | 3762 | ブロックから抜けたり再開することはできません。 |
3679 | 3763 | その他の戦略については L<perlsyn> を参照してください。 |
3680 | 3764 | |
3681 | 3765 | =item do EXPR |
3682 | 3766 | X<do> |
3683 | 3767 | |
3684 | 3768 | =begin original |
3685 | 3769 | |
3686 | 3770 | Uses the value of EXPR as a filename and executes the contents of the |
3687 | 3771 | file as a Perl script: |
3688 | 3772 | |
3689 | 3773 | =end original |
3690 | 3774 | |
3691 | 3775 | EXPR の値をファイル名として用い、そのファイルの中身を |
3692 | 3776 | Perl のスクリプトとして実行します: |
3693 | 3777 | |
3694 | 3778 | # load the exact specified file (./ and ../ special-cased) |
3695 | 3779 | do '/foo/stat.pl'; |
3696 | 3780 | do './stat.pl'; |
3697 | 3781 | do '../foo/stat.pl'; |
3698 | 3782 | |
3699 | 3783 | # search for the named file within @INC |
3700 | 3784 | do 'stat.pl'; |
3701 | 3785 | do 'foo/stat.pl'; |
3702 | 3786 | |
3703 | 3787 | =begin original |
3704 | 3788 | |
3705 | 3789 | C<do './stat.pl'> is largely like |
3706 | 3790 | |
3707 | 3791 | =end original |
3708 | 3792 | |
3709 | 3793 | C<do './stat.pl'> はだいたい以下のものと同じようなものですが、 |
3710 | 3794 | |
3711 | 3795 | eval `cat stat.pl`; |
3712 | 3796 | |
3713 | 3797 | =begin original |
3714 | 3798 | |
3715 | 3799 | except that it's more concise, runs no external processes, and keeps |
3716 | 3800 | track of the current filename for error messages. It also differs in that |
3717 | 3801 | code evaluated with C<do FILE> cannot see lexicals in the enclosing |
3718 | 3802 | scope; C<eval STRING> does. It's the same, however, in that it does |
3719 | 3803 | reparse the file every time you call it, so you probably don't want |
3720 | 3804 | to do this inside a loop. |
3721 | 3805 | |
3722 | 3806 | =end original |
3723 | 3807 | |
3724 | 3808 | より簡潔で、外部プログラムを起動せず、エラーメッセージでファイル名がわかる、 |
3725 | 3809 | といったことがあります。 |
3726 | 3810 | C<do FILE> で評価されたコードは、入れ子のスコープにある |
3727 | 3811 | レキシカル変数を見ることができないのに対し、C<eval STRING>ではできる、 |
3728 | 3812 | という違いがあります。 |
3729 | 3813 | しかし、呼び出すたびにファイルを解析し直すという点では同じですから、 |
3730 | 3814 | ループ内でこれを使おうなどとは、間違っても思ったりしないように。 |
3731 | 3815 | |
3732 | 3816 | =begin original |
3733 | 3817 | |
3734 | 3818 | Using C<do> with a relative path (except for F<./> and F<../>), like |
3735 | 3819 | |
3736 | 3820 | =end original |
3737 | 3821 | |
3738 | 3822 | 次のように、C<do> に (F<./> と F<../> 以外の) 相対パスを使うと: |
3739 | 3823 | |
3740 | 3824 | do 'foo/stat.pl'; |
3741 | 3825 | |
3742 | 3826 | =begin original |
3743 | 3827 | |
3744 | 3828 | will search the L<C<@INC>|perlvar/@INC> directories, and update |
3745 | 3829 | L<C<%INC>|perlvar/%INC> if the file is found. See L<perlvar/@INC> |
3746 | 3830 | and L<perlvar/%INC> for these variables. In particular, note that |
3747 | 3831 | whilst historically L<C<@INC>|perlvar/@INC> contained '.' (the |
3748 | 3832 | current directory) making these two cases equivalent, that is no |
3749 | 3833 | longer necessarily the case, as '.' is not included in C<@INC> by default |
3750 | 3834 | in perl versions 5.26.0 onwards. Instead, perl will now warn: |
3751 | 3835 | |
3752 | 3836 | =end original |
3753 | 3837 | |
3754 | 3838 | L<C<@INC>|perlvar/@INC> ディレクトリを検索し、ファイルが見つかれば |
3755 | 3839 | L<C<%INC>|perlvar/%INC> を更新します。 |
3756 | 3840 | これらの変数については L<perlvar/@INC> と L<perlvar/%INC> を参照してください。 |
3757 | 3841 | 特に、歴史的には L<C<@INC>|perlvar/@INC> に '.' (カレントディレクトリ) を |
3758 | 3842 | 含んでいたのでこの二つの場合は等価でしたが、 |
3759 | 3843 | perl バージョン 5.26.0 以降ではデフォルトでは C<@INC> に '.' を |
3760 | 3844 | 含んでいないので、もはやそうではないことに注意してください。 |
3761 | 3845 | 代わりに、perl は次のような警告を出します: |
3762 | 3846 | |
3763 | 3847 | do "stat.pl" failed, '.' is no longer in @INC; |
3764 | 3848 | did you mean do "./stat.pl"? |
3765 | 3849 | |
3766 | 3850 | =begin original |
3767 | 3851 | |
3768 | 3852 | If L<C<do>|/do EXPR> can read the file but cannot compile it, it |
3769 | 3853 | returns L<C<undef>|/undef EXPR> and sets an error message in |
3770 | 3854 | L<C<$@>|perlvar/$@>. If L<C<do>|/do EXPR> cannot read the file, it |
3771 | 3855 | returns undef and sets L<C<$!>|perlvar/$!> to the error. Always check |
3772 | 3856 | L<C<$@>|perlvar/$@> first, as compilation could fail in a way that also |
3773 | 3857 | sets L<C<$!>|perlvar/$!>. If the file is successfully compiled, |
3774 | 3858 | L<C<do>|/do EXPR> returns the value of the last expression evaluated. |
3775 | 3859 | |
3776 | 3860 | =end original |
3777 | 3861 | |
3778 | 3862 | L<C<do>|/do EXPR> がファイルを読み込めたがコンパイルできなかった場合、 |
3779 | 3863 | L<C<undef>|/undef EXPR> を返して L<C<$@>|perlvar/$@> にエラーメッセージを |
3780 | 3864 | 設定します。 |
3781 | 3865 | L<C<do>|/do EXPR>がファイルを読み込めなかった場合、undef を返して |
3782 | 3866 | L<C<$!>|perlvar/$!> にエラーを設定します。 |
3783 | 3867 | コンパイルに失敗したときにも L<C<$!>|perlvar/$!> が設定されるので、 |
3784 | 3868 | 常に L<C<$@>|perlvar/$@> を先にチェックします。 |
3785 | 3869 | ファイルのコンパイルに成功した場合、L<C<do>|/do EXPR> は最後に評価した表現の |
3786 | 3870 | 値を返します。 |
3787 | 3871 | |
3788 | 3872 | =begin original |
3789 | 3873 | |
3790 | 3874 | Inclusion of library modules is better done with the |
3791 | 3875 | L<C<use>|/use Module VERSION LIST> and L<C<require>|/require VERSION> |
3792 | 3876 | operators, which also do automatic error checking and raise an exception |
3793 | 3877 | if there's a problem. |
3794 | 3878 | |
3795 | 3879 | =end original |
3796 | 3880 | |
3797 | 3881 | ライブラリモジュールのインクルードには、 |
3798 | 3882 | L<C<use>|/use Module VERSION LIST> 演算子や |
3799 | 3883 | L<C<require>|/require VERSION> 演算子を使った方がよいです; |
3800 | 3884 | これらは自動的にエラーをチェックして、問題があれば例外を発生させます。 |
3801 | 3885 | |
3802 | 3886 | =begin original |
3803 | 3887 | |
3804 | 3888 | You might like to use L<C<do>|/do EXPR> to read in a program |
3805 | 3889 | configuration file. Manual error checking can be done this way: |
3806 | 3890 | |
3807 | 3891 | =end original |
3808 | 3892 | |
3809 | 3893 | L<C<do>|/do EXPR> をプログラム設定ファイルを読み込むのに |
3810 | 3894 | 使いたいかもしれません。 |
3811 | 3895 | 手動のエラーチェックは以下のようにして行えます: |
3812 | 3896 | |
3813 | 3897 | # Read in config files: system first, then user. |
3814 | 3898 | # Beware of using relative pathnames here. |
3815 | 3899 | for $file ("/share/prog/defaults.rc", |
3816 | 3900 | "$ENV{HOME}/.someprogrc") |
3817 | 3901 | { |
3818 | 3902 | unless ($return = do $file) { |
3819 | 3903 | warn "couldn't parse $file: $@" if $@; |
3820 | 3904 | warn "couldn't do $file: $!" unless defined $return; |
3821 | 3905 | warn "couldn't run $file" unless $return; |
3822 | 3906 | } |
3823 | 3907 | } |
3824 | 3908 | |
3825 | 3909 | =item dump LABEL |
3826 | 3910 | X<dump> X<core> X<undump> |
3827 | 3911 | |
3828 | 3912 | =item dump EXPR |
3829 | 3913 | |
3830 | 3914 | =item dump |
3831 | 3915 | |
3832 | 3916 | =for Pod::Functions create an immediate core dump |
3833 | 3917 | |
3834 | 3918 | =begin original |
3835 | 3919 | |
3836 | 3920 | This function causes an immediate core dump. See also the B<-u> |
3837 | command-line switch in L<perlrun>, which does the same thing. | |
3921 | command-line switch in L<perlrun|perlrun/-u>, which does the same thing. | |
3838 | 3922 | Primarily this is so that you can use the B<undump> program (not |
3839 | 3923 | supplied) to turn your core dump into an executable binary after |
3840 | 3924 | having initialized all your variables at the beginning of the |
3841 | 3925 | program. When the new binary is executed it will begin by executing |
3842 | 3926 | a C<goto LABEL> (with all the restrictions that L<C<goto>|/goto LABEL> |
3843 | 3927 | suffers). |
3844 | 3928 | Think of it as a goto with an intervening core dump and reincarnation. |
3845 | 3929 | If C<LABEL> is omitted, restarts the program from the top. The |
3846 | 3930 | C<dump EXPR> form, available starting in Perl 5.18.0, allows a name to be |
3847 | 3931 | computed at run time, being otherwise identical to C<dump LABEL>. |
3848 | 3932 | |
3849 | 3933 | =end original |
3850 | 3934 | |
3851 | 3935 | この関数は即座にコアダンプを行ないます。 |
3852 | 同様のことを行う | |
3936 | 同様のことを行う <perlrun|perlrun/-u> の B<-u> オプションも参照してください。 | |
3853 | 3937 | プログラムの先頭で、 |
3854 | 3938 | すべての変数を初期化したあとのコアダンプを B<undump> |
3855 | 3939 | プログラム(提供していません)を使って実行ファイルに返ることができます。 |
3856 | 3940 | この新しいバイナリが実行されると、C<goto LABEL> から始めます |
3857 | 3941 | (L<C<goto>|/goto LABEL> に関する制限はすべて適用されます)。 |
3858 | 3942 | コアダンプをはさんで再生する goto と考えてください。 |
3859 | 3943 | C<LABEL> が省略されると、プログラムを先頭から再開します。 |
3860 | 3944 | Perl 5.18.0 から利用可能な C<dump EXPR> 形式では、実行時に計算される |
3861 | 3945 | 名前が使えます; その他は C<dump LABEL> と同一です。 |
3862 | 3946 | |
3863 | 3947 | =begin original |
3864 | 3948 | |
3865 | 3949 | B<WARNING>: Any files opened at the time of the dump will I<not> |
3866 | 3950 | be open any more when the program is reincarnated, with possible |
3867 | 3951 | resulting confusion by Perl. |
3868 | 3952 | |
3869 | 3953 | =end original |
3870 | 3954 | |
3871 | 3955 | B<警告>: dump 時点でオープンされていたファイルは、プログラムが |
3872 | 3956 | 再生されたときには、もはやオープンされて I<いません>; Perl を |
3873 | 3957 | 混乱させる可能性があります。 |
3874 | 3958 | |
3875 | 3959 | =begin original |
3876 | 3960 | |
3877 | 3961 | This function is now largely obsolete, mostly because it's very hard to |
3878 | convert a core file into an executable. | |
3962 | convert a core file into an executable. As of Perl 5.30, it must be invoked | |
3879 | ||
3963 | as C<CORE::dump()>. | |
3880 | typo. | |
3881 | 3964 | |
3882 | 3965 | =end original |
3883 | 3966 | |
3884 | 3967 | この関数は大幅に時代遅れのものです; 主な理由としては、コアファイルを |
3885 | 3968 | 実行形式に変換するのが非常に困難であることです。 |
3886 | これ | |
3969 | Perl 5.30 から、これは C<CORE::dump()> として起動しなければなりません。 | |
3887 | C<CORE::dump> として起動するべき理由です。 | |
3888 | 3970 | |
3889 | 3971 | =begin original |
3890 | 3972 | |
3891 | 3973 | Unlike most named operators, this has the same precedence as assignment. |
3892 | 3974 | It is also exempt from the looks-like-a-function rule, so |
3893 | 3975 | C<dump ("foo")."bar"> will cause "bar" to be part of the argument to |
3894 | 3976 | L<C<dump>|/dump LABEL>. |
3895 | 3977 | |
3896 | 3978 | =end original |
3897 | 3979 | |
3898 | 3980 | ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 |
3899 | 3981 | また、関数のように見えるものの規則からも免れるので、C<dump ("foo")."bar"> と |
3900 | 3982 | すると "bar" は L<C<dump>|/dump LABEL> への引数の一部になります。 |
3901 | 3983 | |
3902 | 3984 | =begin original |
3903 | 3985 | |
3904 | 3986 | Portability issues: L<perlport/dump>. |
3905 | 3987 | |
3906 | 3988 | =end original |
3907 | 3989 | |
3908 | 3990 | 移植性の問題: L<perlport/dump>。 |
3909 | 3991 | |
3910 | 3992 | =item each HASH |
3911 | 3993 | X<each> X<hash, iterator> |
3912 | 3994 | |
3913 | 3995 | =item each ARRAY |
3914 | 3996 | X<array, iterator> |
3915 | 3997 | |
3916 | 3998 | =for Pod::Functions retrieve the next key/value pair from a hash |
3917 | 3999 | |
3918 | 4000 | =begin original |
3919 | 4001 | |
3920 | 4002 | When called on a hash in list context, returns a 2-element list |
3921 | 4003 | consisting of the key and value for the next element of a hash. In Perl |
3922 | 4004 | 5.12 and later only, it will also return the index and value for the next |
3923 | 4005 | element of an array so that you can iterate over it; older Perls consider |
3924 | 4006 | this a syntax error. When called in scalar context, returns only the key |
3925 | 4007 | (not the value) in a hash, or the index in an array. |
3926 | 4008 | |
3927 | 4009 | =end original |
3928 | 4010 | |
3929 | 4011 | ハッシュに対してリストコンテキストで呼び出した場合は、次の要素に対する、 |
3930 | 4012 | ハッシュのキーと値を返します。 |
3931 | 4013 | Perl 5.12 以降でのみ、配列のインデックスと値からなる |
3932 | 4014 | 2 要素のリストを返すので、反復を行えます; より古い Perl ではこれは |
3933 | 4015 | 文法エラーと考えられます。 |
3934 | 4016 | スカラコンテキストで呼び出した場合は、 |
3935 | 4017 | ハッシュの場合は(値ではなく)キー、配列の場合はインデックスを返します。 |
3936 | 4018 | |
3937 | 4019 | =begin original |
3938 | 4020 | |
3939 | 4021 | Hash entries are returned in an apparently random order. The actual random |
3940 | 4022 | order is specific to a given hash; the exact same series of operations |
3941 | 4023 | on two hashes may result in a different order for each hash. Any insertion |
3942 | 4024 | into the hash may change the order, as will any deletion, with the exception |
3943 | 4025 | that the most recent key returned by L<C<each>|/each HASH> or |
3944 | 4026 | L<C<keys>|/keys HASH> may be deleted without changing the order. So |
3945 | 4027 | long as a given hash is unmodified you may rely on |
3946 | 4028 | L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and |
3947 | 4029 | L<C<each>|/each HASH> to repeatedly return the same order |
3948 | 4030 | as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for |
3949 | 4031 | details on why hash order is randomized. Aside from the guarantees |
3950 | 4032 | provided here the exact details of Perl's hash algorithm and the hash |
3951 | 4033 | traversal order are subject to change in any release of Perl. |
3952 | 4034 | |
3953 | 4035 | =end original |
3954 | 4036 | |
3955 | 4037 | ハッシュ要素は見かけ上、ランダムな順序で返されます。 |
3956 | 4038 | 実際のランダムな順序はハッシュに固有です; 二つのハッシュに全く同じ一連の |
3957 | 4039 | 操作を行っても、ハッシュによって異なった順序になります。 |
3958 | 4040 | ハッシュへの挿入によって順序が変わることがあります; 削除も同様ですが、 |
3959 | 4041 | L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも |
3960 | 4042 | 最近のキーは順序を変えることなく削除できます。 |
3961 | 4043 | ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>, |
3962 | 4044 | L<C<each>|/each HASH> が繰り返し同じ順序で |
3963 | 4045 | 返すことに依存してもかまいません。 |
3964 | 4046 | なぜハッシュの順序がランダム化されているかの詳細については |
3965 | 4047 | L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。 |
3966 | 4048 | ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の |
3967 | 4049 | 正確な詳細は Perl のリリースによって変更される可能性があります。 |
3968 | 4050 | |
3969 | 4051 | =begin original |
3970 | 4052 | |
3971 | 4053 | After L<C<each>|/each HASH> has returned all entries from the hash or |
3972 | 4054 | array, the next call to L<C<each>|/each HASH> returns the empty list in |
3973 | 4055 | list context and L<C<undef>|/undef EXPR> in scalar context; the next |
3974 | 4056 | call following I<that> one restarts iteration. Each hash or array has |
3975 | 4057 | its own internal iterator, accessed by L<C<each>|/each HASH>, |
3976 | 4058 | L<C<keys>|/keys HASH>, and L<C<values>|/values HASH>. The iterator is |
3977 | 4059 | implicitly reset when L<C<each>|/each HASH> has reached the end as just |
3978 | 4060 | described; it can be explicitly reset by calling L<C<keys>|/keys HASH> |
3979 | or L<C<values>|/values HASH> on the hash or array | |
4061 | or L<C<values>|/values HASH> on the hash or array, or by referencing | |
4062 | the hash (but not array) in list context. If you add or delete | |
3980 | 4063 | a hash's elements while iterating over it, the effect on the iterator is |
3981 | 4064 | unspecified; for example, entries may be skipped or duplicated--so don't |
3982 | 4065 | do that. Exception: It is always safe to delete the item most recently |
3983 | 4066 | returned by L<C<each>|/each HASH>, so the following code works properly: |
3984 | 4067 | |
3985 | 4068 | =end original |
3986 | 4069 | |
3987 | 4070 | L<C<each>|/each HASH> がハッシュをすべて読み込んでしまった後、 |
3988 | 4071 | 次の L<C<each>|/each HASH> 呼び出しでは、リストコンテキストでは空リストが |
3989 | 4072 | 返され、スカラコンテキストでは L<C<undef>|/undef EXPR> が返されます; |
3990 | 4073 | I<そのあと> もう一度呼び出すと、再び反復を始めます。 |
3991 | 4074 | ハッシュや配列毎にそれぞれ反復子があり、L<C<each>|/each HASH>、 |
3992 | 4075 | L<C<keys>|/keys HASH>、L<C<values>|/values HASH> でアクセスされます。 |
3993 | 4076 | 反復子は、前述したように L<C<each>|/each HASH> が要素をすべて読むことによって |
3994 | 4077 | 暗黙にリセットされます; また、ハッシュや配列に対して L<C<keys>|/keys HASH>, |
3995 | L<C<values>|/values HASH> を呼び出す | |
4078 | L<C<values>|/values HASH> を呼び出すか、リストコンテキストで | |
4079 | (配列ではなく)ハッシュを参照ことで明示的にリセットできます。 | |
3996 | 4080 | 繰り返しを行なっている間に、ハッシュに要素を追加したり削除したりすると、 |
3997 | 4081 | 反復子の動作は未定義です; 例えば、要素が飛ばされたり重複したりします-- |
3998 | 4082 | 従って、してはいけません。 |
3999 | 4083 | 例外: 一番最近に L<C<each>|/each HASH> から返されたものを削除するのは常に |
4000 | 4084 | 安全です; これは以下のようなコードが正しく動くことを意味します: |
4001 | 4085 | |
4002 | 4086 | while (my ($key, $value) = each %hash) { |
4003 | 4087 | print $key, "\n"; |
4004 | 4088 | delete $hash{$key}; # This is safe |
4005 | 4089 | } |
4006 | 4090 | |
4007 | 4091 | =begin original |
4008 | 4092 | |
4009 | 4093 | Tied hashes may have a different ordering behaviour to perl's hash |
4010 | 4094 | implementation. |
4011 | 4095 | |
4012 | 4096 | =end original |
4013 | 4097 | |
4014 | 4098 | tie されたハッシュは、順序に関して Perl のハッシュと異なった振る舞いをします。 |
4015 | 4099 | |
4016 | 4100 | =begin original |
4017 | 4101 | |
4102 | The iterator used by C<each> is attached to the hash or array, and is | |
4103 | shared between all iteration operations applied to the same hash or array. | |
4104 | Thus all uses of C<each> on a single hash or array advance the same | |
4105 | iterator location. All uses of C<each> are also subject to having the | |
4106 | iterator reset by any use of C<keys> or C<values> on the same hash or | |
4107 | array, or by the hash (but not array) being referenced in list context. | |
4108 | This makes C<each>-based loops quite fragile: it is easy to arrive at | |
4109 | such a loop with the iterator already part way through the object, or to | |
4110 | accidentally clobber the iterator state during execution of the loop body. | |
4111 | It's easy enough to explicitly reset the iterator before starting a loop, | |
4112 | but there is no way to insulate the iterator state used by a loop from | |
4113 | the iterator state used by anything else that might execute during the | |
4114 | loop body. To avoid these problems, use a C<foreach> loop rather than | |
4115 | C<while>-C<each>. | |
4116 | ||
4117 | =end original | |
4118 | ||
4119 | C<each> で使われる反復子はハッシュや配列に付随し、 | |
4120 | 同じハッシュや配列に適用される全ての反復操作の間で共有されます。 | |
4121 | 従って、一つのハッシュや配列での C<each> の全ての使用は同じ反復位置を | |
4122 | 進めます。 | |
4123 | また、全ての C<each> は、同じハッシュまたはキーに対する | |
4124 | C<keys> や C<values> の使用によって、または | |
4125 | (リストではなく)ハッシュがリストコンテキストで参照されることによって、 | |
4126 | 反復子がリセットされることになります。 | |
4127 | これは、C<each> を基にしたループをかなり不安定にします: | |
4128 | そのようなループが既にオブジェクトを部分的に通りぬけた反復子で行われたり、 | |
4129 | ループ本体の実行中に誤って反復子の状態を壊すことは容易です。 | |
4130 | ループを始める前に反復子を明示的にリセットするのは十分容易ですが、 | |
4131 | ループ本体の間に実行しているかもしれない他の何かによって使われている | |
4132 | 反復子の状態から、 | |
4133 | ループによって使われている反復子の状態を分離する方法はありません。 | |
4134 | これらの問題を避けるには、C<while>-C<each> ではなく | |
4135 | C<foreach> ループを使ってください。 | |
4136 | ||
4137 | =begin original | |
4138 | ||
4018 | 4139 | This prints out your environment like the L<printenv(1)> program, |
4019 | 4140 | but in a different order: |
4020 | 4141 | |
4021 | 4142 | =end original |
4022 | 4143 | |
4023 | 4144 | これは、L<printenv(1)> プログラムのように環境変数を表示しますが、 |
4024 | 4145 | 順序は異なっています: |
4025 | 4146 | |
4026 | 4147 | while (my ($key,$value) = each %ENV) { |
4027 | 4148 | print "$key=$value\n"; |
4028 | 4149 | } |
4029 | 4150 | |
4030 | 4151 | =begin original |
4031 | 4152 | |
4032 | 4153 | Starting with Perl 5.14, an experimental feature allowed |
4033 | 4154 | L<C<each>|/each HASH> to take a scalar expression. This experiment has |
4034 | 4155 | been deemed unsuccessful, and was removed as of Perl 5.24. |
4035 | 4156 | |
4036 | 4157 | =end original |
4037 | 4158 | |
4038 | 4159 | Perl 5.14 から、L<C<each>|/each HASH> がスカラ式を取ることが出来るという |
4039 | 4160 | 実験的機能がありました。 |
4040 | 4161 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 |
4041 | 4162 | |
4042 | 4163 | =begin original |
4043 | 4164 | |
4044 | 4165 | As of Perl 5.18 you can use a bare L<C<each>|/each HASH> in a C<while> |
4045 | 4166 | loop, which will set L<C<$_>|perlvar/$_> on every iteration. |
4167 | If either an C<each> expression or an explicit assignment of an C<each> | |
4168 | expression to a scalar is used as a C<while>/C<for> condition, then | |
4169 | the condition actually tests for definedness of the expression's value, | |
4170 | not for its regular truth value. | |
4046 | 4171 | |
4047 | 4172 | =end original |
4048 | 4173 | |
4049 | 4174 | Perl 5.18 から C<while> ループの中に裸の L<C<each>|/each HASH> を書けます; |
4050 | 4175 | これは繰り返し毎に L<C<$_>|perlvar/$_> を設定します。 |
4176 | C<each> 式または C<each> 式からスカラへの明示的な代入が | |
4177 | C<while>/C<for> の条件部として使われた場合、 | |
4178 | 条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを | |
4179 | テストします。 | |
4051 | 4180 | |
4052 | 4181 | while (each %ENV) { |
4053 | 4182 | print "$_=$ENV{$_}\n"; |
4054 | 4183 | } |
4055 | 4184 | |
4056 | 4185 | =begin original |
4057 | 4186 | |
4058 | 4187 | To avoid confusing would-be users of your code who are running earlier |
4059 | 4188 | versions of Perl with mysterious syntax errors, put this sort of thing at |
4060 | 4189 | the top of your file to signal that your code will work I<only> on Perls of |
4061 | 4190 | a recent vintage: |
4062 | 4191 | |
4063 | 4192 | =end original |
4064 | 4193 | |
4065 | 4194 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な |
4066 | 4195 | 文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で |
4067 | 4196 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを |
4068 | 4197 | 書いてください: |
4069 | 4198 | |
4070 | 4199 | use 5.012; # so keys/values/each work on arrays |
4071 | 4200 | use 5.018; # so each assigns to $_ in a lone while test |
4072 | 4201 | |
4073 | 4202 | =begin original |
4074 | 4203 | |
4075 | 4204 | See also L<C<keys>|/keys HASH>, L<C<values>|/values HASH>, and |
4076 | 4205 | L<C<sort>|/sort SUBNAME LIST>. |
4077 | 4206 | |
4078 | 4207 | =end original |
4079 | 4208 | |
4080 | 4209 | L<C<keys>|/keys HASH> や L<C<values>|/values HASH> や |
4081 | 4210 | L<C<sort>|/sort SUBNAME LIST> も参照してください。 |
4082 | 4211 | |
4083 | 4212 | =item eof FILEHANDLE |
4084 | 4213 | X<eof> |
4085 | 4214 | X<end of file> |
4086 | 4215 | X<end-of-file> |
4087 | 4216 | |
4088 | 4217 | =item eof () |
4089 | 4218 | |
4090 | 4219 | =item eof |
4091 | 4220 | |
4092 | 4221 | =for Pod::Functions test a filehandle for its end |
4093 | 4222 | |
4094 | 4223 | =begin original |
4095 | 4224 | |
4096 | 4225 | Returns 1 if the next read on FILEHANDLE will return end of file I<or> if |
4097 | 4226 | FILEHANDLE is not open. FILEHANDLE may be an expression whose value |
4098 | 4227 | gives the real filehandle. (Note that this function actually |
4099 | 4228 | reads a character and then C<ungetc>s it, so isn't useful in an |
4100 | 4229 | interactive context.) Do not read from a terminal file (or call |
4101 | 4230 | C<eof(FILEHANDLE)> on it) after end-of-file is reached. File types such |
4102 | 4231 | as terminals may lose the end-of-file condition if you do. |
4103 | 4232 | |
4104 | 4233 | =end original |
4105 | 4234 | |
4106 | 4235 | 次に FILEHANDLE 上で読み込みを行なったときに、EOF が返されるときか、 |
4107 | 4236 | I<または> FILEHANDLE がオープンされていないと、1 を返します。 |
4108 | 4237 | FILEHANDLE は、値が実際のファイルハンドルを示す式であってもかまいません。 |
4109 | 4238 | (この関数は、実際に文字を読み、C<ungetc> を行ないますので、 |
4110 | 4239 | 対話型の場合には有用ではありません。) |
4111 | 4240 | 端末ファイルは EOF に達した後にさらに読み込んだり C<eof(FILEHANDLE)> を |
4112 | 4241 | 呼び出したりしてはいけません。 |
4113 | 4242 | そのようなことをすると、端末のようなファイルタイプは |
4114 | 4243 | EOF 状態を失ってしまうかもしれません。 |
4115 | 4244 | |
4116 | 4245 | =begin original |
4117 | 4246 | |
4118 | 4247 | An L<C<eof>|/eof FILEHANDLE> without an argument uses the last file |
4119 | 4248 | read. Using L<C<eof()>|/eof FILEHANDLE> with empty parentheses is |
4120 | 4249 | different. It refers to the pseudo file formed from the files listed on |
4121 | 4250 | the command line and accessed via the C<< <> >> operator. Since |
4122 | 4251 | C<< <> >> isn't explicitly opened, as a normal filehandle is, an |
4123 | 4252 | L<C<eof()>|/eof FILEHANDLE> before C<< <> >> has been used will cause |
4124 | 4253 | L<C<@ARGV>|perlvar/@ARGV> to be examined to determine if input is |
4125 | 4254 | available. Similarly, an L<C<eof()>|/eof FILEHANDLE> after C<< <> >> |
4126 | 4255 | has returned end-of-file will assume you are processing another |
4127 | 4256 | L<C<@ARGV>|perlvar/@ARGV> list, and if you haven't set |
4128 | 4257 | L<C<@ARGV>|perlvar/@ARGV>, will read input from C<STDIN>; see |
4129 | 4258 | L<perlop/"I/O Operators">. |
4130 | 4259 | |
4131 | 4260 | =end original |
4132 | 4261 | |
4133 | 4262 | 引数を省略した L<C<eof>|/eof FILEHANDLE> は、最後に読み込みを行なった |
4134 | 4263 | ファイルを使います。 |
4135 | 4264 | 空の括弧をつけた L<C<eof()>|/eof FILEHANDLE> は異なります。 |
4136 | 4265 | これはコマンドラインのファイルリストで構成され、C<< <> >> 演算子経由で |
4137 | 4266 | アクセスされる擬似ファイルを示すために用いられます。 |
4138 | 4267 | 通常のファイルハンドルと違って C<< <> >> は明示的にオープンされないので、 |
4139 | 4268 | C<< <> >> を使う前に L<C<eof()>|/eof FILEHANDLE> を使うと、 |
4140 | 4269 | 入力が正常か確認するために L<C<@ARGV>|perlvar/@ARGV> がテストされます。 |
4141 | 4270 | 同様に、C<< <> >> が EOF を返した後の L<C<eof()>|/eof FILEHANDLE> は、 |
4142 | 4271 | 他の L<C<@ARGV>|perlvar/@ARGV> リストを処理していると仮定し、もし |
4143 | 4272 | L<C<@ARGV>|perlvar/@ARGV> をセットしていないときは C<STDIN> から読み込みます; |
4144 | 4273 | L<perlop/"I/O Operators"> を参照してください。 |
4145 | 4274 | |
4146 | 4275 | =begin original |
4147 | 4276 | |
4148 | 4277 | In a C<< while (<>) >> loop, L<C<eof>|/eof FILEHANDLE> or C<eof(ARGV)> |
4149 | 4278 | can be used to detect the end of each file, whereas |
4150 | 4279 | L<C<eof()>|/eof FILEHANDLE> will detect the end of the very last file |
4151 | 4280 | only. Examples: |
4152 | 4281 | |
4153 | 4282 | =end original |
4154 | 4283 | |
4155 | 4284 | C<< while (<>) >> ループの中では、個々のファイルの終わりを調べるには、 |
4156 | 4285 | L<C<eof>|/eof FILEHANDLE> か C<eof(ARGV)> を用いるのに対して |
4157 | 4286 | L<C<eof()>|/eof FILEHANDLE> は最後のファイルの終わりのみを調べます。 |
4158 | 4287 | 例: |
4159 | 4288 | |
4160 | 4289 | # reset line numbering on each input file |
4161 | 4290 | while (<>) { |
4162 | 4291 | next if /^\s*#/; # skip comments |
4163 | 4292 | print "$.\t$_"; |
4164 | 4293 | } continue { |
4165 | 4294 | close ARGV if eof; # Not eof()! |
4166 | 4295 | } |
4167 | 4296 | |
4168 | 4297 | # insert dashes just before last line of last file |
4169 | 4298 | while (<>) { |
4170 | 4299 | if (eof()) { # check for end of last file |
4171 | 4300 | print "--------------\n"; |
4172 | 4301 | } |
4173 | 4302 | print; |
4174 | 4303 | last if eof(); # needed if we're reading from a terminal |
4175 | 4304 | } |
4176 | 4305 | |
4177 | 4306 | =begin original |
4178 | 4307 | |
4179 | 4308 | Practical hint: you almost never need to use L<C<eof>|/eof FILEHANDLE> |
4180 | 4309 | in Perl, because the input operators typically return L<C<undef>|/undef |
4181 | 4310 | EXPR> when they run out of data or encounter an error. |
4182 | 4311 | |
4183 | 4312 | =end original |
4184 | 4313 | |
4185 | 4314 | 現実的なヒント: Perl で L<C<eof>|/eof FILEHANDLE> が必要となることは、 |
4186 | 4315 | ほとんどありません; |
4187 | 4316 | 基本的には、データがなくなったときやエラーがあったときに、入力演算子が |
4188 | 4317 | L<C<undef>|/undef EXPR> を返してくれるからです。 |
4189 | 4318 | |
4190 | 4319 | =item eval EXPR |
4191 | 4320 | X<eval> X<try> X<catch> X<evaluate> X<parse> X<execute> |
4192 | 4321 | X<error, handling> X<exception, handling> |
4193 | 4322 | |
4194 | 4323 | =item eval BLOCK |
4195 | 4324 | |
4196 | 4325 | =item eval |
4197 | 4326 | |
4198 | 4327 | =for Pod::Functions catch exceptions or compile and run code |
4199 | 4328 | |
4200 | 4329 | =begin original |
4201 | 4330 | |
4202 | 4331 | C<eval> in all its forms is used to execute a little Perl program, |
4203 | 4332 | trapping any errors encountered so they don't crash the calling program. |
4204 | 4333 | |
4205 | 4334 | =end original |
4206 | 4335 | |
4207 | 4336 | どの型式の C<eval> も、小さな Perl のプログラムであるかのように実行され、 |
4208 | 4337 | 遭遇した全てのエラーをトラップするので、呼び出したプログラムが |
4209 | 4338 | クラッシュすることはありません。 |
4210 | 4339 | |
4211 | 4340 | =begin original |
4212 | 4341 | |
4213 | 4342 | Plain C<eval> with no argument is just C<eval EXPR>, where the |
4214 | 4343 | expression is understood to be contained in L<C<$_>|perlvar/$_>. Thus |
4215 | 4344 | there are only two real C<eval> forms; the one with an EXPR is often |
4216 | 4345 | called "string eval". In a string eval, the value of the expression |
4217 | 4346 | (which is itself determined within scalar context) is first parsed, and |
4218 | 4347 | if there were no errors, executed as a block within the lexical context |
4219 | 4348 | of the current Perl program. This form is typically used to delay |
4220 | 4349 | parsing and subsequent execution of the text of EXPR until run time. |
4221 | 4350 | Note that the value is parsed every time the C<eval> executes. |
4222 | 4351 | |
4223 | 4352 | =end original |
4224 | 4353 | |
4225 | 4354 | 引数なしの C<eval> は単に C<eval EXPR> で、式は L<C<$_>|perlvar/$_> に |
4226 | 4355 | 含まれているものとして考えられます。 |
4227 | 4356 | 従って実際には二つだけの C<eval> 形式があります: |
4228 | 4357 | EXPR のものはしばしば「文字列 eval」(string eval) と呼ばれます。 |
4229 | 4358 | 「文字列 eval」では、 |
4230 | 4359 | 式の値(それ自身スカラコンテキストの中で決定されます)はまずパースされ、 |
4231 | 4360 | エラーがなければ Perl プログラムのレキシカルコンテキストの中のブロックとして |
4232 | 4361 | 実行されます。 |
4233 | 4362 | この形は主に EXPR のテキストのパースと実行を実行時にまで |
4234 | 4363 | 遅延させるのに用います。 |
4235 | 4364 | 返される値は C<eval> が実行されるごとにパースされることに注意してください。 |
4236 | 4365 | |
4237 | 4366 | =begin original |
4238 | 4367 | |
4239 | 4368 | The other form is called "block eval". It is less general than string |
4240 | 4369 | eval, but the code within the BLOCK is parsed only once (at the same |
4241 | 4370 | time the code surrounding the C<eval> itself was parsed) and executed |
4242 | 4371 | within the context of the current Perl program. This form is typically |
4243 | 4372 | used to trap exceptions more efficiently than the first, while also |
4244 | 4373 | providing the benefit of checking the code within BLOCK at compile time. |
4245 | 4374 | BLOCK is parsed and compiled just once. Since errors are trapped, it |
4246 | 4375 | often is used to check if a given feature is available. |
4247 | 4376 | |
4248 | 4377 | =end original |
4249 | 4378 | |
4250 | 4379 | もう一つの型式は「ブロック eval」と呼ばれます。 |
4251 | 4380 | これは文字列 eval ほど一般的ではありませんが、 |
4252 | 4381 | BLOCK 内部のコードは一度だけパースされ (コードを |
4253 | 4382 | 囲む C<eval> 自身がパースされるのと同じ時点です) 現在の |
4254 | 4383 | Perl プログラムのコンテキストで実行されます。 |
4255 | 4384 | この形式は典型的には第一の形式より効率的に例外をトラップします; |
4256 | 4385 | また BLOCK 内部のコードはコンパイル時にチェックされるという利点を提供します。 |
4257 | 4386 | BLOCK は一度だけパース及びコンパイルされます。 |
4258 | 4387 | エラーはトラップされてるので、しばしば与えられた機能が利用可能かを |
4259 | 4388 | チェックするために使われます。 |
4260 | 4389 | |
4261 | 4390 | =begin original |
4262 | 4391 | |
4263 | 4392 | In both forms, the value returned is the value of the last expression |
4264 | 4393 | evaluated inside the mini-program; a return statement may also be used, just |
4265 | 4394 | as with subroutines. The expression providing the return value is evaluated |
4266 | 4395 | in void, scalar, or list context, depending on the context of the |
4267 | 4396 | C<eval> itself. See L<C<wantarray>|/wantarray> for more |
4268 | 4397 | on how the evaluation context can be determined. |
4269 | 4398 | |
4270 | 4399 | =end original |
4271 | 4400 | |
4272 | 4401 | どちらの形式でも、返される値はミニプログラムの内部で最後に評価された |
4273 | 4402 | 表現の値です; サブルーチンと同様、return 文も使えます。 |
4274 | 4403 | 返り値として提供される表現は、C<eval> 自身のコンテキストに |
4275 | 4404 | 依存して無効・スカラ・リストのいずれかのコンテキストで評価されます。 |
4276 | 4405 | 評価コンテキストの決定方法についての詳細は L<C<wantarray>|/wantarray> を |
4277 | 4406 | 参照してください。 |
4278 | 4407 | |
4279 | 4408 | =begin original |
4280 | 4409 | |
4281 | 4410 | If there is a syntax error or runtime error, or a L<C<die>|/die LIST> |
4282 | 4411 | statement is executed, C<eval> returns |
4283 | 4412 | L<C<undef>|/undef EXPR> in scalar context, or an empty list in list |
4284 | 4413 | context, and L<C<$@>|perlvar/$@> is set to the error message. (Prior to |
4285 | 4414 | 5.16, a bug caused L<C<undef>|/undef EXPR> to be returned in list |
4286 | 4415 | context for syntax errors, but not for runtime errors.) If there was no |
4287 | 4416 | error, L<C<$@>|perlvar/$@> is set to the empty string. A control flow |
4288 | 4417 | operator like L<C<last>|/last LABEL> or L<C<goto>|/goto LABEL> can |
4289 | 4418 | bypass the setting of L<C<$@>|perlvar/$@>. Beware that using |
4290 | 4419 | C<eval> neither silences Perl from printing warnings to |
4291 | 4420 | STDERR, nor does it stuff the text of warning messages into |
4292 | 4421 | L<C<$@>|perlvar/$@>. To do either of those, you have to use the |
4293 | 4422 | L<C<$SIG{__WARN__}>|perlvar/%SIG> facility, or turn off warnings inside |
4294 | 4423 | the BLOCK or EXPR using S<C<no warnings 'all'>>. See |
4295 | 4424 | L<C<warn>|/warn LIST>, L<perlvar>, and L<warnings>. |
4296 | 4425 | |
4297 | 4426 | =end original |
4298 | 4427 | |
4299 | 4428 | 構文エラーや実行エラーが発生するか、L<C<die>|/die LIST> 文が実行されると、 |
4300 | 4429 | C<eval> はスカラコンテキストでは L<C<undef>|/undef EXPR> が、 |
4301 | 4430 | リストコンテキストでは空リストが設定され、 |
4302 | 4431 | L<C<$@>|perlvar/$@> にエラーメッセージが設定されます。 |
4303 | 4432 | (5.16 以前では、バグによって、リストコンテキストで構文エラーの時には |
4304 | 4433 | L<C<undef>|/undef EXPR> を返していましたが、実行エラーの時には |
4305 | 4434 | 返していませんでした。) |
4306 | 4435 | エラーがなければ、L<C<$@>|perlvar/$@> は空文字列に設定されます。 |
4307 | 4436 | L<C<last>|/last LABEL> や L<C<goto>|/goto LABEL> のようなフロー制御演算子は |
4308 | 4437 | L<C<$@>|perlvar/$@> の設定を回避できます。 |
4309 | 4438 | C<eval> を、STDERR に警告メッセージを表示させない目的や、 |
4310 | 4439 | 警告メッセージを L<C<$@>|perlvar/$@> に格納する目的では使わないでください。 |
4311 | 4440 | そのような用途では、L<C<$SIG{__WARN__}>|perlvar/%SIG> 機能を使うか、 |
4312 | 4441 | S<C<no warnings 'all'>> を使って BLOCK か EXPR の内部での警告を |
4313 | 4442 | オフにする必要があります。 |
4314 | 4443 | L<C<warn>|/warn LIST>, L<perlvar>, L<warnings> を参照してください。 |
4315 | 4444 | |
4316 | 4445 | =begin original |
4317 | 4446 | |
4318 | 4447 | Note that, because C<eval> traps otherwise-fatal errors, |
4319 | 4448 | it is useful for determining whether a particular feature (such as |
4320 | 4449 | L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL> or |
4321 | 4450 | L<C<symlink>|/symlink OLDFILE,NEWFILE>) is implemented. It is also |
4322 | 4451 | Perl's exception-trapping mechanism, where the L<C<die>|/die LIST> |
4323 | 4452 | operator is used to raise exceptions. |
4324 | 4453 | |
4325 | 4454 | =end original |
4326 | 4455 | |
4327 | 4456 | C<eval> は、致命的エラーとなるようなものを |
4328 | 4457 | トラップすることができるので、 |
4329 | 4458 | (L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL> や |
4330 | 4459 | L<C<symlink>|/symlink OLDFILE,NEWFILE> といった) 特定の機能が |
4331 | 4460 | 実装されているかを、 |
4332 | 4461 | 調べるために使うことができることに注意してください。 |
4333 | 4462 | L<C<die>|/die LIST> 演算子が例外を発生させるものとすれば、これはまた、 |
4334 | 4463 | Perl の例外捕捉機能と捉えることもできます。 |
4335 | 4464 | |
4336 | 4465 | =begin original |
4337 | 4466 | |
4338 | 4467 | Before Perl 5.14, the assignment to L<C<$@>|perlvar/$@> occurred before |
4339 | 4468 | restoration |
4340 | 4469 | of localized variables, which means that for your code to run on older |
4341 | 4470 | versions, a temporary is required if you want to mask some, but not all |
4342 | 4471 | errors: |
4343 | 4472 | |
4344 | 4473 | =end original |
4345 | 4474 | |
4346 | 4475 | Perl 5.14 より前では、L<C<$@>|perlvar/$@> への代入はローカル化された変数の |
4347 | 4476 | 復帰の前に起きるので、古いバージョンで実行される場合は、全てではなく一部だけの |
4348 | 4477 | エラーをマスクしたい場合には一時変数が必要です: |
4349 | 4478 | |
4350 | 4479 | # alter $@ on nefarious repugnancy only |
4351 | 4480 | { |
4352 | 4481 | my $e; |
4353 | 4482 | { |
4354 | 4483 | local $@; # protect existing $@ |
4355 | 4484 | eval { test_repugnancy() }; |
4356 | 4485 | # $@ =~ /nefarious/ and die $@; # Perl 5.14 and higher only |
4357 | 4486 | $@ =~ /nefarious/ and $e = $@; |
4358 | 4487 | } |
4359 | 4488 | die $e if defined $e |
4360 | 4489 | } |
4361 | 4490 | |
4362 | 4491 | =begin original |
4363 | 4492 | |
4364 | 4493 | There are some different considerations for each form: |
4365 | 4494 | |
4366 | 4495 | =end original |
4367 | 4496 | |
4368 | 4497 | それぞれの型式について、異なった考慮事項があります: |
4369 | 4498 | |
4370 | 4499 | =over 4 |
4371 | 4500 | |
4372 | 4501 | =item String eval |
4373 | 4502 | |
4374 | 4503 | (文字列 eval) |
4375 | 4504 | |
4376 | 4505 | =begin original |
4377 | 4506 | |
4378 | 4507 | Since the return value of EXPR is executed as a block within the lexical |
4379 | 4508 | context of the current Perl program, any outer lexical variables are |
4380 | 4509 | visible to it, and any package variable settings or subroutine and |
4381 | 4510 | format definitions remain afterwards. |
4382 | 4511 | |
4383 | 4512 | =end original |
4384 | 4513 | |
4385 | 4514 | EXPR の返り値は現在の Perl プログラムのレキシカルコンテキストの中で |
4386 | 4515 | 実行されるので、外側のレキシカルスコープはそこから見え、 |
4387 | 4516 | パッケージ変数設定やサブルーチンとフォーマット設定は後に残ります。 |
4388 | 4517 | |
4389 | 4518 | =over 4 |
4390 | 4519 | |
4391 | 4520 | =item Under the L<C<"unicode_eval"> feature|feature/The 'unicode_eval' and 'evalbytes' features> |
4392 | 4521 | |
4393 | 4522 | =begin original |
4394 | 4523 | |
4395 | 4524 | If this feature is enabled (which is the default under a C<use 5.16> or |
4396 | 4525 | higher declaration), EXPR is considered to be |
4397 | 4526 | in the same encoding as the surrounding program. Thus if |
4398 | 4527 | S<L<C<use utf8>|utf8>> is in effect, the string will be treated as being |
4399 | 4528 | UTF-8 encoded. Otherwise, the string is considered to be a sequence of |
4400 | 4529 | independent bytes. Bytes that correspond to ASCII-range code points |
4401 | 4530 | will have their normal meanings for operators in the string. The |
4402 | 4531 | treatment of the other bytes depends on if the |
4403 | 4532 | L<C<'unicode_strings"> feature|feature/The 'unicode_strings' feature> is |
4404 | 4533 | in effect. |
4405 | 4534 | |
4406 | 4535 | =end original |
4407 | 4536 | |
4408 | 4537 | この機能が有効の場合(これは C<use 5.16> またはそれ以上が |
4409 | 4538 | 宣言されている場合はデフォルトです)、 |
4410 | 4539 | EXPR は周りのプログラムと同じエンコーディングであるとして扱われます。 |
4411 | 4540 | 従って、S<L<C<use utf8>|utf8>> が有効の場合、 |
4412 | 4541 | 文字列は UTF-8 エンコードされているものとして扱われます。 |
4413 | 4542 | さもなければ、この文字列は個々のバイト列として扱われます。 |
4414 | 4543 | ASCII の範囲の符号位置に対応するバイトは、 |
4415 | 4544 | 文字列の操作に関して通常の意味を持ちます。 |
4416 | 4545 | その他のバイトの扱いは、 |
4417 | 4546 | <C<'unicode_strings"> feature|feature/'unicode_strings' 機能> が有効の場合か |
4418 | 4547 | どうかに依存します。 |
4419 | 4548 | |
4420 | 4549 | =begin original |
4421 | 4550 | |
4422 | 4551 | In a plain C<eval> without an EXPR argument, being in S<C<use utf8>> or |
4423 | 4552 | not is irrelevant; the UTF-8ness of C<$_> itself determines the |
4424 | 4553 | behavior. |
4425 | 4554 | |
4426 | 4555 | =end original |
4427 | 4556 | |
4428 | 4557 | EXPR 引数のない単なる C<eval> の場合、S<C<use utf8>> の有無は無関係です; |
4429 | 4558 | C<$_> 自身の UTF-8 性が振る舞いを決定します。 |
4430 | 4559 | |
4431 | 4560 | =begin original |
4432 | 4561 | |
4433 | 4562 | Any S<C<use utf8>> or S<C<no utf8>> declarations within the string have |
4434 | 4563 | no effect, and source filters are forbidden. (C<unicode_strings>, |
4435 | 4564 | however, can appear within the string.) See also the |
4436 | 4565 | L<C<evalbytes>|/evalbytes EXPR> operator, which works properly with |
4437 | 4566 | source filters. |
4438 | 4567 | |
4439 | 4568 | =end original |
4440 | 4569 | |
4441 | 4570 | 文字列中の S<C<use utf8>> や S<C<no utf8>> 宣言は無効で、ソースフィルタは |
4442 | 4571 | 禁止されます。 |
4443 | 4572 | (しかし、C<unicode_strings> は文字列の中に現れます。) |
4444 | 4573 | ソースフィルタが適切に動作する |
4445 | 4574 | L<C<evalbytes>|/evalbytes EXPR> 演算子も参照してください。 |
4446 | 4575 | |
4447 | 4576 | =begin original |
4448 | 4577 | |
4449 | 4578 | Variables defined outside the C<eval> and used inside it retain their |
4450 | 4579 | original UTF-8ness. Everything inside the string follows the normal |
4451 | 4580 | rules for a Perl program with the given state of S<C<use utf8>>. |
4452 | 4581 | |
4453 | 4582 | =end original |
4454 | 4583 | |
4455 | 4584 | Variables defined outside the |
4456 | 4585 | C<eval> の外側で定義され、内側で使われた変数は、 |
4457 | 4586 | 元の UTF-8 性を維持します。 |
4458 | 4587 | 内側の文字列は、S<C<use utf8>> の状態によって Perl プログラムに適用される |
4459 | 4588 | 通常の規則に従います。 |
4460 | 4589 | |
4461 | 4590 | =item Outside the C<"unicode_eval"> feature |
4462 | 4591 | |
4463 | 4592 | =begin original |
4464 | 4593 | |
4465 | 4594 | In this case, the behavior is problematic and is not so easily |
4466 | 4595 | described. Here are two bugs that cannot easily be fixed without |
4467 | 4596 | breaking existing programs: |
4468 | 4597 | |
4469 | 4598 | =end original |
4470 | 4599 | |
4471 | 4600 | この場合、振る舞いには問題があり、それほど簡単には説明できません。 |
4472 | 4601 | 既存のプログラムを壊さずに簡単に修正することが出来ない二つのバグがあります: |
4473 | 4602 | |
4474 | 4603 | =over 4 |
4475 | 4604 | |
4476 | 4605 | =item * |
4477 | 4606 | |
4478 | 4607 | =begin original |
4479 | 4608 | |
4480 | 4609 | It can lose track of whether something should be encoded as UTF-8 or |
4481 | 4610 | not. |
4482 | 4611 | |
4483 | 4612 | =end original |
4484 | 4613 | |
4485 | 4614 | あるものが UTF-8 でエンコードされているかどうかを見失うことがあります。 |
4486 | 4615 | |
4487 | 4616 | =item * |
4488 | 4617 | |
4489 | 4618 | =begin original |
4490 | 4619 | |
4491 | 4620 | Source filters activated within C<eval> leak out into whichever file |
4492 | 4621 | scope is currently being compiled. To give an example with the CPAN module |
4493 | 4622 | L<Semi::Semicolons>: |
4494 | 4623 | |
4495 | 4624 | =end original |
4496 | 4625 | |
4497 | 4626 | C<eval> の中で有効にされたソースフィルタは、現在どちらのファイルスコープで |
4498 | 4627 | コンパイルされているかをリークさせます。 |
4499 | 4628 | CPAN モジュール L<Semi::Semicolons> を使った例は: |
4500 | 4629 | |
4501 | 4630 | BEGIN { eval "use Semi::Semicolons; # not filtered" } |
4502 | 4631 | # filtered here! |
4503 | 4632 | |
4504 | 4633 | =begin original |
4505 | 4634 | |
4506 | 4635 | L<C<evalbytes>|/evalbytes EXPR> fixes that to work the way one would |
4507 | 4636 | expect: |
4508 | 4637 | |
4509 | 4638 | =end original |
4510 | 4639 | |
4511 | 4640 | L<C<evalbytes>|/evalbytes EXPR> は、人が想定するだろう手法で動作するように |
4512 | 4641 | これを修正します: |
4513 | 4642 | |
4514 | 4643 | use feature "evalbytes"; |
4515 | 4644 | BEGIN { evalbytes "use Semi::Semicolons; # filtered" } |
4516 | 4645 | # not filtered |
4517 | 4646 | |
4518 | 4647 | =back |
4519 | 4648 | |
4520 | 4649 | =back |
4521 | 4650 | |
4522 | 4651 | =begin original |
4523 | 4652 | |
4524 | 4653 | Problems can arise if the string expands a scalar containing a floating |
4525 | 4654 | point number. That scalar can expand to letters, such as C<"NaN"> or |
4526 | 4655 | C<"Infinity">; or, within the scope of a L<C<use locale>|locale>, the |
4527 | 4656 | decimal point character may be something other than a dot (such as a |
4528 | 4657 | comma). None of these are likely to parse as you are likely expecting. |
4529 | 4658 | |
4530 | 4659 | =end original |
4531 | 4660 | |
4532 | 4661 | 文字列をが小数点を含むスカラを展開するときに問題が起こることがあります。 |
4533 | 4662 | そのようなスカラは C<"NaN"> や C<"Infinity"> のような文字に |
4534 | 4663 | 展開されることがあります; または、L<C<use locale>|locale> のスコープの中では、 |
4535 | 4664 | 小数点文字は (カンマのような) ドット以外の文字かもしれません。 |
4536 | 4665 | これらはどれもあなたがおそらく予測しているようにはパースされません。 |
4537 | 4666 | |
4538 | 4667 | =begin original |
4539 | 4668 | |
4540 | 4669 | You should be especially careful to remember what's being looked at |
4541 | 4670 | when: |
4542 | 4671 | |
4543 | 4672 | =end original |
4544 | 4673 | |
4545 | 4674 | 以下のような場合に、何が調べられるかに特に注意しておくことが必要です: |
4546 | 4675 | |
4547 | 4676 | eval $x; # CASE 1 |
4548 | 4677 | eval "$x"; # CASE 2 |
4549 | 4678 | |
4550 | 4679 | eval '$x'; # CASE 3 |
4551 | 4680 | eval { $x }; # CASE 4 |
4552 | 4681 | |
4553 | 4682 | eval "\$$x++"; # CASE 5 |
4554 | 4683 | $$x++; # CASE 6 |
4555 | 4684 | |
4556 | 4685 | =begin original |
4557 | 4686 | |
4558 | 4687 | Cases 1 and 2 above behave identically: they run the code contained in |
4559 | 4688 | the variable $x. (Although case 2 has misleading double quotes making |
4560 | 4689 | the reader wonder what else might be happening (nothing is).) Cases 3 |
4561 | 4690 | and 4 likewise behave in the same way: they run the code C<'$x'>, which |
4562 | 4691 | does nothing but return the value of $x. (Case 4 is preferred for |
4563 | 4692 | purely visual reasons, but it also has the advantage of compiling at |
4564 | 4693 | compile-time instead of at run-time.) Case 5 is a place where |
4565 | 4694 | normally you I<would> like to use double quotes, except that in this |
4566 | 4695 | particular situation, you can just use symbolic references instead, as |
4567 | 4696 | in case 6. |
4568 | 4697 | |
4569 | 4698 | =end original |
4570 | 4699 | |
4571 | 4700 | 上記の CASE 1 と CASE 2 の動作は同一で、変数 $x 内の |
4572 | 4701 | コードを実行します。 |
4573 | 4702 | (ただし、CASE 2 では、必要のないダブルクォートによって、 |
4574 | 4703 | 読む人が何が起こるか混乱することでしょう (何も起こりませんが)。) |
4575 | 4704 | 同様に CASE 3 と CASE 4 の動作も等しく、$x の値を返す以外に |
4576 | 4705 | 何もしない C<$x> というコードを実行します |
4577 | 4706 | (純粋に見た目の問題で、CASE 4 が好まれますが、 |
4578 | 4707 | 実行時でなくコンパイル時にコンパイルされるという利点もあります)。 |
4579 | 4708 | CASE 5 の場合は、通常ダブルクォートを使用 I<します>; |
4580 | 4709 | この状況を除けば、CASE 6 のように、単に |
4581 | 4710 | シンボリックリファレンスを使えば良いでしょう。 |
4582 | 4711 | |
4583 | 4712 | =begin original |
4584 | 4713 | |
4585 | 4714 | An C<eval ''> executed within a subroutine defined |
4586 | 4715 | in the C<DB> package doesn't see the usual |
4587 | 4716 | surrounding lexical scope, but rather the scope of the first non-DB piece |
4588 | 4717 | of code that called it. You don't normally need to worry about this unless |
4589 | 4718 | you are writing a Perl debugger. |
4590 | 4719 | |
4591 | 4720 | =end original |
4592 | 4721 | |
4593 | 4722 | C<DB> パッケージで定義されたサブルーチン内で C<eval ''> を実行すると、通常の |
4594 | 4723 | レキシカルスコープではなく、これを呼び出した最初の非 DB コード片の |
4595 | 4724 | スコープになります。 |
4596 | 4725 | Perl デバッガを書いているのでない限り、普通はこれについて心配する必要は |
4597 | 4726 | ありません。 |
4598 | 4727 | |
4599 | 4728 | =begin original |
4600 | 4729 | |
4601 | 4730 | The final semicolon, if any, may be omitted from the value of EXPR. |
4602 | 4731 | |
4603 | 4732 | =end original |
4604 | 4733 | |
4605 | 4734 | 最後のセミコロンは、もしあれば、EXPR の値から省くことができます。 |
4606 | 4735 | |
4607 | 4736 | =item Block eval |
4608 | 4737 | |
4609 | 4738 | =begin original |
4610 | 4739 | |
4611 | 4740 | If the code to be executed doesn't vary, you may use the eval-BLOCK |
4612 | 4741 | form to trap run-time errors without incurring the penalty of |
4613 | 4742 | recompiling each time. The error, if any, is still returned in |
4614 | 4743 | L<C<$@>|perlvar/$@>. |
4615 | 4744 | Examples: |
4616 | 4745 | |
4617 | 4746 | =end original |
4618 | 4747 | |
4619 | 4748 | 実行するコードが変わらないのであれば、毎回多量の再コンパイルすることなしに、 |
4620 | 4749 | 実行時エラーのトラップを行なうために、 |
4621 | 4750 | eval-BLOCK 形式を使うことができます。 |
4622 | 4751 | エラーがあれば、やはり L<C<$@>|perlvar/$@> に返されます。 |
4623 | 4752 | 例: |
4624 | 4753 | |
4625 | 4754 | # make divide-by-zero nonfatal |
4626 | 4755 | eval { $answer = $a / $b; }; warn $@ if $@; |
4627 | 4756 | |
4628 | 4757 | # same thing, but less efficient |
4629 | 4758 | eval '$answer = $a / $b'; warn $@ if $@; |
4630 | 4759 | |
4631 | 4760 | # a compile-time error |
4632 | 4761 | eval { $answer = }; # WRONG |
4633 | 4762 | |
4634 | 4763 | # a run-time error |
4635 | 4764 | eval '$answer ='; # sets $@ |
4636 | 4765 | |
4637 | 4766 | =begin original |
4638 | 4767 | |
4639 | 4768 | If you want to trap errors when loading an XS module, some problems with |
4640 | 4769 | the binary interface (such as Perl version skew) may be fatal even with |
4641 | 4770 | C<eval> unless C<$ENV{PERL_DL_NONLAZY}> is set. See |
4642 | L<perlrun>. | |
4771 | L<perlrun|perlrun/PERL_DL_NONLAZY>. | |
4643 | 4772 | |
4644 | 4773 | =end original |
4645 | 4774 | |
4646 | 4775 | XS モジュールのロード中のエラーをトラップしたいなら、 |
4647 | 4776 | (Perl バージョンの違いのような) バイナリインターフェースに関する問題に |
4648 | 4777 | ついては C<$ENV{PERL_DL_NONLAZY}> がセットされていない |
4649 | 4778 | C<eval> でも致命的エラーになるかもしれません。 |
4650 | L<perlrun> を参照してください。 | |
4779 | L<perlrun|perlrun/PERL_DL_NONLAZY> を参照してください。 | |
4651 | 4780 | |
4652 | 4781 | =begin original |
4653 | 4782 | |
4654 | 4783 | Using the C<eval {}> form as an exception trap in libraries does have some |
4655 | 4784 | issues. Due to the current arguably broken state of C<__DIE__> hooks, you |
4656 | 4785 | may wish not to trigger any C<__DIE__> hooks that user code may have installed. |
4657 | 4786 | You can use the C<local $SIG{__DIE__}> construct for this purpose, |
4658 | 4787 | as this example shows: |
4659 | 4788 | |
4660 | 4789 | =end original |
4661 | 4790 | |
4662 | 4791 | C<eval{}> 形式をライブラリの例外を捕捉するために使うときには |
4663 | 4792 | 問題があります。 |
4664 | 4793 | 現在の C<__DIE__> フックの状態はほぼ確実に壊れているという理由で、 |
4665 | 4794 | ユーザーのコードが設定した C<__DIE__> フックを実行したくないかもしれません。 |
4666 | 4795 | この目的には以下の例のように、C<local $SIG{__DIE__}> 構造が使えます。 |
4667 | 4796 | |
4668 | 4797 | # a private exception trap for divide-by-zero |
4669 | 4798 | eval { local $SIG{'__DIE__'}; $answer = $a / $b; }; |
4670 | 4799 | warn $@ if $@; |
4671 | 4800 | |
4672 | 4801 | =begin original |
4673 | 4802 | |
4674 | 4803 | This is especially significant, given that C<__DIE__> hooks can call |
4675 | 4804 | L<C<die>|/die LIST> again, which has the effect of changing their error |
4676 | 4805 | messages: |
4677 | 4806 | |
4678 | 4807 | =end original |
4679 | 4808 | |
4680 | 4809 | これは特に顕著です; 与えられた C<__DIE__> フックは L<C<die>|/die LIST> を |
4681 | 4810 | もう一度呼び出すことができ、これによってエラーメッセージを変える |
4682 | 4811 | 効果があります: |
4683 | 4812 | |
4684 | 4813 | # __DIE__ hooks may modify error messages |
4685 | 4814 | { |
4686 | 4815 | local $SIG{'__DIE__'} = |
4687 | 4816 | sub { (my $x = $_[0]) =~ s/foo/bar/g; die $x }; |
4688 | 4817 | eval { die "foo lives here" }; |
4689 | 4818 | print $@ if $@; # prints "bar lives here" |
4690 | 4819 | } |
4691 | 4820 | |
4692 | 4821 | =begin original |
4693 | 4822 | |
4694 | 4823 | Because this promotes action at a distance, this counterintuitive behavior |
4695 | 4824 | may be fixed in a future release. |
4696 | 4825 | |
4697 | 4826 | =end original |
4698 | 4827 | |
4699 | 4828 | これは距離の離れた行動であるため、この直感的でない振る舞いは |
4700 | 4829 | 将来のリリースでは修正されるかもしれません。 |
4701 | 4830 | |
4702 | 4831 | =begin original |
4703 | 4832 | |
4704 | 4833 | C<eval BLOCK> does I<not> count as a loop, so the loop control statements |
4705 | 4834 | L<C<next>|/next LABEL>, L<C<last>|/last LABEL>, or |
4706 | 4835 | L<C<redo>|/redo LABEL> cannot be used to leave or restart the block. |
4707 | 4836 | |
4708 | 4837 | =end original |
4709 | 4838 | |
4710 | 4839 | C<eval BLOCK> はループとして I<扱われません>; 従って、L<C<next>|/next LABEL>, |
4711 | 4840 | L<C<last>|/last LABEL>, L<C<redo>|/redo LABEL> といったループ制御文で |
4712 | 4841 | ブロックから離れたり再実行したりはできません。 |
4713 | 4842 | |
4714 | 4843 | =begin original |
4715 | 4844 | |
4716 | 4845 | The final semicolon, if any, may be omitted from within the BLOCK. |
4717 | 4846 | |
4718 | 4847 | =end original |
4719 | 4848 | |
4720 | 4849 | 最後のセミコロンは、もしあれば、BLOCK の中から削除されます。 |
4721 | 4850 | |
4722 | 4851 | =back |
4723 | 4852 | |
4724 | 4853 | =item evalbytes EXPR |
4725 | 4854 | X<evalbytes> |
4726 | 4855 | |
4727 | 4856 | =item evalbytes |
4728 | 4857 | |
4729 | 4858 | =for Pod::Functions +evalbytes similar to string eval, but intend to parse a bytestream |
4730 | 4859 | |
4731 | 4860 | =begin original |
4732 | 4861 | |
4733 | 4862 | This function is similar to a L<string eval|/eval EXPR>, except it |
4734 | 4863 | always parses its argument (or L<C<$_>|perlvar/$_> if EXPR is omitted) |
4735 | 4864 | as a string of independent bytes. |
4736 | 4865 | |
4737 | 4866 | =end original |
4738 | 4867 | |
4739 | 4868 | この関数は L<文字列 eval|/eval EXPR> に似ていますが、引数(EXPR が |
4740 | 4869 | 省略された場合はL<C<$_>|perlvar/$_>) を常にバイト単位のの文字列として |
4741 | 4870 | 扱います。 |
4742 | 4871 | |
4743 | 4872 | =begin original |
4744 | 4873 | |
4745 | 4874 | If called when S<C<use utf8>> is in effect, the string will be assumed |
4746 | 4875 | to be encoded in UTF-8, and C<evalbytes> will make a temporary copy to |
4747 | 4876 | work from, downgraded to non-UTF-8. If this is not possible |
4748 | 4877 | (because one or more characters in it require UTF-8), the C<evalbytes> |
4749 | 4878 | will fail with the error stored in C<$@>. |
4750 | 4879 | |
4751 | 4880 | =end original |
4752 | 4881 | |
4753 | 4882 | S<C<use utf8>> が有効のときに呼び出されると、 |
4754 | 4883 | 文字列は UTF-8 でエンコードされていると仮定され、 |
4755 | 4884 | C<evalbytes> は、非 UTF-8 にダウングレードした一時的なコピーを作ります。 |
4756 | 4885 | (UTF-8 が必要な文字があるために) これが不可能な場合、 |
4757 | 4886 | C<evalbytes> は失敗し、エラーは C<$@> に保管されます。 |
4758 | 4887 | |
4759 | 4888 | =begin original |
4760 | 4889 | |
4761 | 4890 | Bytes that correspond to ASCII-range code points will have their normal |
4762 | 4891 | meanings for operators in the string. The treatment of the other bytes |
4763 | 4892 | depends on if the L<C<'unicode_strings"> feature|feature/The |
4764 | 4893 | 'unicode_strings' feature> is in effect. |
4765 | 4894 | |
4766 | 4895 | =end original |
4767 | 4896 | |
4768 | 4897 | ASCII の範囲の符号位置に対応するバイトは、 |
4769 | 4898 | 文字列の操作に関して通常の意味を持ちます。 |
4770 | 4899 | その他のバイトの扱いは、 |
4771 | 4900 | <C<'unicode_strings"> feature|feature/'unicode_strings' 機能> が有効の場合か |
4772 | 4901 | どうかに依存します。 |
4773 | 4902 | |
4774 | 4903 | =begin original |
4775 | 4904 | |
4776 | 4905 | Of course, variables that are UTF-8 and are referred to in the string |
4777 | 4906 | retain that: |
4778 | 4907 | |
4779 | 4908 | =end original |
4780 | 4909 | |
4781 | 4910 | もちろん、UTF-8 で文字列の中で参照されている変数はそのままです: |
4782 | 4911 | |
4783 | 4912 | my $a = "\x{100}"; |
4784 | 4913 | evalbytes 'print ord $a, "\n"'; |
4785 | 4914 | |
4786 | 4915 | =begin original |
4787 | 4916 | |
4788 | 4917 | prints |
4789 | 4918 | |
4790 | 4919 | =end original |
4791 | 4920 | |
4792 | 4921 | というのは、次を表示し、 |
4793 | 4922 | |
4794 | 4923 | 256 |
4795 | 4924 | |
4796 | 4925 | =begin original |
4797 | 4926 | |
4798 | 4927 | and C<$@> is empty. |
4799 | 4928 | |
4800 | 4929 | =end original |
4801 | 4930 | |
4802 | 4931 | C<$@> は空になります。 |
4803 | 4932 | |
4804 | 4933 | =begin original |
4805 | 4934 | |
4806 | 4935 | Source filters activated within the evaluated code apply to the code |
4807 | 4936 | itself. |
4808 | 4937 | |
4809 | 4938 | =end original |
4810 | 4939 | |
4811 | 4940 | eval されたコード内で有効になったソースフィルタはコード自体に適用されます。 |
4812 | 4941 | |
4813 | 4942 | =begin original |
4814 | 4943 | |
4815 | 4944 | L<C<evalbytes>|/evalbytes EXPR> is available starting in Perl v5.16. To |
4816 | 4945 | access it, you must say C<CORE::evalbytes>, but you can omit the |
4817 | 4946 | C<CORE::> if the |
4818 | 4947 | L<C<"evalbytes"> feature|feature/The 'unicode_eval' and 'evalbytes' features> |
4819 | 4948 | is enabled. This is enabled automatically with a C<use v5.16> (or |
4820 | 4949 | higher) declaration in the current scope. |
4821 | 4950 | |
4822 | 4951 | =end original |
4823 | 4952 | |
4824 | 4953 | L<C<evalbytes>|/evalbytes EXPR> は Perl v5.16 から利用可能です。 |
4825 | 4954 | これにアクセスするには C<CORE::evalbytes> とする必要がありますが、 |
4826 | 4955 | L<C<"evalbytes"> 機能|feature/The 'unicode_eval' and 'evalbytes' features> が |
4827 | 4956 | 有効なら C<CORE::> を省略できます。 |
4828 | 4957 | これは現在のスコープで C<use v5.16> (またはそれ以上) 宣言があると |
4829 | 4958 | 自動的に有効になります。 |
4830 | 4959 | |
4831 | 4960 | =item exec LIST |
4832 | 4961 | X<exec> X<execute> |
4833 | 4962 | |
4834 | 4963 | =item exec PROGRAM LIST |
4835 | 4964 | |
4836 | 4965 | =for Pod::Functions abandon this program to run another |
4837 | 4966 | |
4838 | 4967 | =begin original |
4839 | 4968 | |
4840 | 4969 | The L<C<exec>|/exec LIST> function executes a system command I<and never |
4841 | 4970 | returns>; use L<C<system>|/system LIST> instead of L<C<exec>|/exec LIST> |
4842 | 4971 | if you want it to return. It fails and |
4843 | 4972 | returns false only if the command does not exist I<and> it is executed |
4844 | 4973 | directly instead of via your system's command shell (see below). |
4845 | 4974 | |
4846 | 4975 | =end original |
4847 | 4976 | |
4848 | 4977 | L<C<exec>|/exec LIST> 関数は、システムのコマンドを実行し、I<戻ってはきません>; |
4849 | 4978 | 戻って欲しい場合には、L<C<exec>|/exec LIST>ではなく |
4850 | 4979 | L<C<system>|/system LIST> 関数を使ってください。 |
4851 | 4980 | コマンドが存在せず、I<しかも> システムのコマンドシェル経由でなく |
4852 | 4981 | 直接コマンドを実行しようとした場合にのみこの関数は失敗して偽を返します。 |
4853 | 4982 | |
4854 | 4983 | =begin original |
4855 | 4984 | |
4856 | 4985 | Since it's a common mistake to use L<C<exec>|/exec LIST> instead of |
4857 | 4986 | L<C<system>|/system LIST>, Perl warns you if L<C<exec>|/exec LIST> is |
4858 | 4987 | called in void context and if there is a following statement that isn't |
4859 | 4988 | L<C<die>|/die LIST>, L<C<warn>|/warn LIST>, or L<C<exit>|/exit EXPR> (if |
4860 | 4989 | L<warnings> are enabled--but you always do that, right?). If you |
4861 | 4990 | I<really> want to follow an L<C<exec>|/exec LIST> with some other |
4862 | 4991 | statement, you can use one of these styles to avoid the warning: |
4863 | 4992 | |
4864 | 4993 | =end original |
4865 | 4994 | |
4866 | 4995 | L<C<system>|/system LIST> の代わりに L<C<exec>|/exec LIST> を使うという |
4867 | 4996 | よくある間違いを防ぐために、L<C<exec>|/exec LIST> が無効コンテキストで |
4868 | 4997 | 呼び出されて、引き続く文が L<C<die>|/die LIST>, L<C<warn>|/warn LIST>, |
4869 | 4998 | L<C<exit>|/exit EXPR> 以外の場合、Perl は警告を出します(L<warnings> が |
4870 | 4999 | 有効の場合 -- でもいつもセットしてますよね?)。 |
4871 | 5000 | もし I<本当に> L<C<exec>|/exec LIST> の後に他の文を書きたい場合、以下の |
4872 | 5001 | どちらかのスタイルを使うことで警告を回避できます: |
4873 | 5002 | |
4874 | 5003 | exec ('foo') or print STDERR "couldn't exec foo: $!"; |
4875 | 5004 | { exec ('foo') }; print STDERR "couldn't exec foo: $!"; |
4876 | 5005 | |
4877 | 5006 | =begin original |
4878 | 5007 | |
4879 | 5008 | If there is more than one argument in LIST, this calls L<execvp(3)> with the |
4880 | 5009 | arguments in LIST. If there is only one element in LIST, the argument is |
4881 | 5010 | checked for shell metacharacters, and if there are any, the entire |
4882 | 5011 | argument is passed to the system's command shell for parsing (this is |
4883 | 5012 | C</bin/sh -c> on Unix platforms, but varies on other platforms). If |
4884 | 5013 | there are no shell metacharacters in the argument, it is split into words |
4885 | 5014 | and passed directly to C<execvp>, which is more efficient. Examples: |
4886 | 5015 | |
4887 | 5016 | =end original |
4888 | 5017 | |
4889 | 5018 | LIST に複数の引数がある場合は、LIST の引数を使って L<execvp(3)> を |
4890 | 5019 | 呼び出します。 |
4891 | 5020 | LIST に要素が一つのみの場合には、その引数からシェルのメタ文字をチェックし、 |
4892 | 5021 | もしメタ文字があれば、引数全体をシステムのコマンドシェル(これはUnix では |
4893 | 5022 | C</bin/sh -c> ですが、システムによって異なります)に渡して解析させます。 |
4894 | 5023 | シェルのメタ文字がなかった場合、引数は単語に分解されて直接 C<execvp> に |
4895 | 5024 | 渡されます; この方がより効率的です。 |
4896 | 5025 | 例: |
4897 | 5026 | |
4898 | 5027 | exec '/bin/echo', 'Your arguments are: ', @ARGV; |
4899 | 5028 | exec "sort $outfile | uniq"; |
4900 | 5029 | |
4901 | 5030 | =begin original |
4902 | 5031 | |
4903 | 5032 | If you don't really want to execute the first argument, but want to lie |
4904 | 5033 | to the program you are executing about its own name, you can specify |
4905 | 5034 | the program you actually want to run as an "indirect object" (without a |
4906 | 5035 | comma) in front of the LIST, as in C<exec PROGRAM LIST>. (This always |
4907 | 5036 | forces interpretation of the LIST as a multivalued list, even if there |
4908 | 5037 | is only a single scalar in the list.) Example: |
4909 | 5038 | |
4910 | 5039 | =end original |
4911 | 5040 | |
4912 | 5041 | 第一引数に指定するものを本当に実行したいが、実行するプログラムに対して別の |
4913 | 5042 | 名前を教えたい場合には、C<exec PROGRAM LIST> のように、LIST の前に |
4914 | 5043 | 「間接オブジェクト」(コンマなし) として実際に実行したいプログラムを |
4915 | 5044 | 指定することができます。 |
4916 | 5045 | (これによって、LIST に単一のスカラしかなくても、複数値のリストであるように、 |
4917 | 5046 | LIST の解釈を行ないます。) |
4918 | 5047 | 例: |
4919 | 5048 | |
4920 | 5049 | my $shell = '/bin/csh'; |
4921 | 5050 | exec $shell '-sh'; # pretend it's a login shell |
4922 | 5051 | |
4923 | 5052 | =begin original |
4924 | 5053 | |
4925 | 5054 | or, more directly, |
4926 | 5055 | |
4927 | 5056 | =end original |
4928 | 5057 | |
4929 | 5058 | あるいは、より直接的に、 |
4930 | 5059 | |
4931 | 5060 | exec {'/bin/csh'} '-sh'; # pretend it's a login shell |
4932 | 5061 | |
4933 | 5062 | =begin original |
4934 | 5063 | |
4935 | 5064 | When the arguments get executed via the system shell, results are |
4936 | 5065 | subject to its quirks and capabilities. See L<perlop/"`STRING`"> |
4937 | 5066 | for details. |
4938 | 5067 | |
4939 | 5068 | =end original |
4940 | 5069 | |
4941 | 5070 | 引数がシステムシェルで実行されるとき、結果はシェルの奇癖と能力によって |
4942 | 5071 | 変わります。 |
4943 | 5072 | 詳細については L<perlop/"`STRING`"> を参照してください。 |
4944 | 5073 | |
4945 | 5074 | =begin original |
4946 | 5075 | |
4947 | 5076 | Using an indirect object with L<C<exec>|/exec LIST> or |
4948 | 5077 | L<C<system>|/system LIST> is also more secure. This usage (which also |
4949 | 5078 | works fine with L<C<system>|/system LIST>) forces |
4950 | 5079 | interpretation of the arguments as a multivalued list, even if the |
4951 | 5080 | list had just one argument. That way you're safe from the shell |
4952 | 5081 | expanding wildcards or splitting up words with whitespace in them. |
4953 | 5082 | |
4954 | 5083 | =end original |
4955 | 5084 | |
4956 | 5085 | L<C<exec>|/exec LIST> や L<C<system>|/system LIST> で間接オブジェクトを |
4957 | 5086 | 使うのもより安全です。 |
4958 | 5087 | この使い方(L<C<system>|/system LIST> でも同様にうまく動きます)は、たとえ |
4959 | 5088 | 引数が一つだけの場合も、複数の値を持つリストとして引数を解釈することを |
4960 | 5089 | 強制します。 |
4961 | 5090 | この方法で、シェルによるワイルドカード展開や、空白による単語の分割から |
4962 | 5091 | 守られます。 |
4963 | 5092 | |
4964 | 5093 | my @args = ( "echo surprise" ); |
4965 | 5094 | |
4966 | 5095 | exec @args; # subject to shell escapes |
4967 | 5096 | # if @args == 1 |
4968 | 5097 | exec { $args[0] } @args; # safe even with one-arg list |
4969 | 5098 | |
4970 | 5099 | =begin original |
4971 | 5100 | |
4972 | 5101 | The first version, the one without the indirect object, ran the I<echo> |
4973 | 5102 | program, passing it C<"surprise"> an argument. The second version didn't; |
4974 | 5103 | it tried to run a program named I<"echo surprise">, didn't find it, and set |
4975 | 5104 | L<C<$?>|perlvar/$?> to a non-zero value indicating failure. |
4976 | 5105 | |
4977 | 5106 | =end original |
4978 | 5107 | |
4979 | 5108 | 間接オブジェクトなしの一つ目のバージョンでは、I<echo> プログラムが実行され、 |
4980 | 5109 | C<"surprise"> が引数として渡されます。 |
4981 | 5110 | 二つ目のバージョンでは違います; I<"echo surprise"> という名前の |
4982 | 5111 | プログラムを実行しようとして、見つからないので、失敗したことを示すために |
4983 | 5112 | L<C<$?>|perlvar/$?> に非 0 がセットされます。 |
4984 | 5113 | |
4985 | 5114 | =begin original |
4986 | 5115 | |
4987 | 5116 | On Windows, only the C<exec PROGRAM LIST> indirect object syntax will |
4988 | 5117 | reliably avoid using the shell; C<exec LIST>, even with more than one |
4989 | 5118 | element, will fall back to the shell if the first spawn fails. |
4990 | 5119 | |
4991 | 5120 | =end original |
4992 | 5121 | |
4993 | 5122 | Windows では、C<exec PROGRAM LIST> 間接オブジェクト構文のみが、シェルを |
4994 | 5123 | 使うのを回避するための信頼できる方法です; C<exec LIST> は、複数の要素が |
4995 | 5124 | あっても、最初の spawn が失敗したときにシェルに |
4996 | 5125 | フォールバックすることがあります。 |
4997 | 5126 | |
4998 | 5127 | =begin original |
4999 | 5128 | |
5000 | 5129 | Perl attempts to flush all files opened for output before the exec, |
5001 | 5130 | but this may not be supported on some platforms (see L<perlport>). |
5002 | 5131 | To be safe, you may need to set L<C<$E<verbar>>|perlvar/$E<verbar>> |
5003 | 5132 | (C<$AUTOFLUSH> in L<English>) or call the C<autoflush> method of |
5004 | 5133 | L<C<IO::Handle>|IO::Handle/METHODS> on any open handles to avoid lost |
5005 | 5134 | output. |
5006 | 5135 | |
5007 | 5136 | =end original |
5008 | 5137 | |
5009 | 5138 | v5.6.0 から、Perl は exec の前に出力用に開かれている全てのファイルを |
5010 | 5139 | フラッシュしようとしますが、これに対応していないプラットフォームもあります |
5011 | 5140 | (L<perlport> を参照してください)。 |
5012 | 5141 | 安全のためには、出力が重複するのを避けるために、全てのオープンしている |
5013 | 5142 | ハンドルに対して L<C<$E<verbar>>|perlvar/$E<verbar>> |
5014 | 5143 | (L<English> モジュールでは C<$AUTOFLUSH>) を設定するか、 |
5015 | 5144 | L<C<IO::Handle>|IO::Handle/METHODS> モジュールの C<autoflush> メソッドを |
5016 | 5145 | 呼ぶ必要があるかもしれません。 |
5017 | 5146 | |
5018 | 5147 | =begin original |
5019 | 5148 | |
5020 | 5149 | Note that L<C<exec>|/exec LIST> will not call your C<END> blocks, nor |
5021 | 5150 | will it invoke C<DESTROY> methods on your objects. |
5022 | 5151 | |
5023 | 5152 | =end original |
5024 | 5153 | |
5025 | 5154 | L<C<exec>|/exec LIST> は C<END> ブロックや、オブジェクトの |
5026 | 5155 | C<DESTROY> メソッドを起動しないことに注意してください。 |
5027 | 5156 | |
5028 | 5157 | =begin original |
5029 | 5158 | |
5030 | 5159 | Portability issues: L<perlport/exec>. |
5031 | 5160 | |
5032 | 5161 | =end original |
5033 | 5162 | |
5034 | 5163 | 移植性の問題: L<perlport/exec>。 |
5035 | 5164 | |
5036 | 5165 | =item exists EXPR |
5037 | 5166 | X<exists> X<autovivification> |
5038 | 5167 | |
5039 | 5168 | =for Pod::Functions test whether a hash key is present |
5040 | 5169 | |
5041 | 5170 | =begin original |
5042 | 5171 | |
5043 | 5172 | Given an expression that specifies an element of a hash, returns true if the |
5044 | 5173 | specified element in the hash has ever been initialized, even if the |
5045 | 5174 | corresponding value is undefined. |
5046 | 5175 | |
5047 | 5176 | =end original |
5048 | 5177 | |
5049 | 5178 | ハッシュ要素を示す表現が与えられ、指定された要素が、ハッシュに存在すれば、 |
5050 | 5179 | たとえ対応する値が未定義でも真を返します。 |
5051 | 5180 | |
5052 | 5181 | print "Exists\n" if exists $hash{$key}; |
5053 | 5182 | print "Defined\n" if defined $hash{$key}; |
5054 | 5183 | print "True\n" if $hash{$key}; |
5055 | 5184 | |
5056 | 5185 | =begin original |
5057 | 5186 | |
5058 | 5187 | exists may also be called on array elements, but its behavior is much less |
5059 | 5188 | obvious and is strongly tied to the use of L<C<delete>|/delete EXPR> on |
5060 | 5189 | arrays. |
5061 | 5190 | |
5062 | 5191 | =end original |
5063 | 5192 | |
5064 | 5193 | exists は配列の要素に対しても呼び出せますが、その振る舞いははるかに |
5065 | 5194 | 不明確で、配列に対する L<C<delete>|/delete EXPR> の使用と強く |
5066 | 5195 | 結びついています。 |
5067 | 5196 | |
5068 | 5197 | =begin original |
5069 | 5198 | |
5070 | 5199 | B<WARNING:> Calling L<C<exists>|/exists EXPR> on array values is |
5071 | 5200 | strongly discouraged. The |
5072 | 5201 | notion of deleting or checking the existence of Perl array elements is not |
5073 | 5202 | conceptually coherent, and can lead to surprising behavior. |
5074 | 5203 | |
5075 | 5204 | =end original |
5076 | 5205 | |
5077 | 5206 | B<警告:> 配列の値に対して L<C<exists>|/exists EXPR> を呼び出すことは強く |
5078 | 5207 | 非推奨です。 |
5079 | 5208 | Perl の配列要素を削除したり存在を調べたりする記法は概念的に一貫しておらず、 |
5080 | 5209 | 驚くべき振る舞いを引き起こすことがあります。 |
5081 | 5210 | |
5082 | 5211 | print "Exists\n" if exists $array[$index]; |
5083 | 5212 | print "Defined\n" if defined $array[$index]; |
5084 | 5213 | print "True\n" if $array[$index]; |
5085 | 5214 | |
5086 | 5215 | =begin original |
5087 | 5216 | |
5088 | 5217 | A hash or array element can be true only if it's defined and defined only if |
5089 | 5218 | it exists, but the reverse doesn't necessarily hold true. |
5090 | 5219 | |
5091 | 5220 | =end original |
5092 | 5221 | |
5093 | 5222 | ハッシュまたは配列要素は、定義されているときにのみ真となり、 |
5094 | 5223 | 存在しているときにのみ定義されますが、逆は必ずしも真ではありません。 |
5095 | 5224 | |
5096 | 5225 | =begin original |
5097 | 5226 | |
5098 | 5227 | Given an expression that specifies the name of a subroutine, |
5099 | 5228 | returns true if the specified subroutine has ever been declared, even |
5100 | 5229 | if it is undefined. Mentioning a subroutine name for exists or defined |
5101 | 5230 | does not count as declaring it. Note that a subroutine that does not |
5102 | 5231 | exist may still be callable: its package may have an C<AUTOLOAD> |
5103 | 5232 | method that makes it spring into existence the first time that it is |
5104 | 5233 | called; see L<perlsub>. |
5105 | 5234 | |
5106 | 5235 | =end original |
5107 | 5236 | |
5108 | 5237 | 引数としてサブルーチンの名前が指定された場合、 |
5109 | 5238 | 指定されたサブルーチンが宣言されていれば(たとえ未定義でも) |
5110 | 5239 | 真を返します。 |
5111 | 5240 | exists や defined のために言及されているサブルーチン名は |
5112 | 5241 | 宣言としてのカウントに入りません。 |
5113 | 5242 | 存在しないサブルーチンでも呼び出し可能かもしれないことに注意してください: |
5114 | 5243 | パッケージが C<AUTOLOAD> メソッドを持っていて、最初に呼び出された時に |
5115 | 5244 | 存在を作り出すかもしれません; L<perlsub> を参照してください。 |
5116 | 5245 | |
5117 | 5246 | print "Exists\n" if exists &subroutine; |
5118 | 5247 | print "Defined\n" if defined &subroutine; |
5119 | 5248 | |
5120 | 5249 | =begin original |
5121 | 5250 | |
5122 | 5251 | Note that the EXPR can be arbitrarily complicated as long as the final |
5123 | 5252 | operation is a hash or array key lookup or subroutine name: |
5124 | 5253 | |
5125 | 5254 | =end original |
5126 | 5255 | |
5127 | 5256 | 最終的な操作がハッシュや配列の key による検索または |
5128 | 5257 | サブルーチン名である限りは、EXPR には任意の複雑な式を置くことができます: |
5129 | 5258 | |
5130 | 5259 | if (exists $ref->{A}->{B}->{$key}) { } |
5131 | 5260 | if (exists $hash{A}{B}{$key}) { } |
5132 | 5261 | |
5133 | 5262 | if (exists $ref->{A}->{B}->[$ix]) { } |
5134 | 5263 | if (exists $hash{A}{B}[$ix]) { } |
5135 | 5264 | |
5136 | 5265 | if (exists &{$ref->{A}{B}{$key}}) { } |
5137 | 5266 | |
5138 | 5267 | =begin original |
5139 | 5268 | |
5140 | 5269 | Although the most deeply nested array or hash element will not spring into |
5141 | 5270 | existence just because its existence was tested, any intervening ones will. |
5142 | 5271 | Thus C<< $ref->{"A"} >> and C<< $ref->{"A"}->{"B"} >> will spring |
5143 | 5272 | into existence due to the existence test for the C<$key> element above. |
5144 | 5273 | This happens anywhere the arrow operator is used, including even here: |
5145 | 5274 | |
5146 | 5275 | =end original |
5147 | 5276 | |
5148 | 5277 | 最も深くネストした配列やハッシュの要素は、その存在をテストしただけでは |
5149 | 5278 | 存在するようにはなりませんが、途中のものは存在するようになります。 |
5150 | 5279 | 従って C<< $ref->{"A"} >> と C<< $ref->{"A"}->{"B"} >> は上記の C<$key> の |
5151 | 5280 | 存在をテストしたことによって存在するようになります。 |
5152 | 5281 | これは、矢印演算子が使われるところでは、以下のようなものを含むどこででも |
5153 | 5282 | 起こります。 |
5154 | 5283 | |
5155 | 5284 | undef $ref; |
5156 | 5285 | if (exists $ref->{"Some key"}) { } |
5157 | 5286 | print $ref; # prints HASH(0x80d3d5c) |
5158 | 5287 | |
5159 | 5288 | =begin original |
5160 | 5289 | |
5161 | This surprising autovivification in what does not at first--or even | |
5162 | second--glance appear to be an lvalue context may be fixed in a future | |
5163 | release. | |
5164 | ||
5165 | =end original | |
5166 | ||
5167 | 一目見ただけでは -- あるいは二目見ても -- 驚かされる、左辺値コンテキストでの | |
5168 | 自動有効化は将来のリリースでは修正されるでしょう。 | |
5169 | ||
5170 | =begin original | |
5171 | ||
5172 | 5290 | Use of a subroutine call, rather than a subroutine name, as an argument |
5173 | 5291 | to L<C<exists>|/exists EXPR> is an error. |
5174 | 5292 | |
5175 | 5293 | =end original |
5176 | 5294 | |
5177 | 5295 | L<C<exists>|/exists EXPR> の引数としてサブルーチン名でなくサブルーチン |
5178 | 5296 | 呼び出しを使うと、エラーになります。 |
5179 | 5297 | |
5180 | 5298 | exists ⊂ # OK |
5181 | 5299 | exists &sub(); # Error |
5182 | 5300 | |
5183 | 5301 | =item exit EXPR |
5184 | 5302 | X<exit> X<terminate> X<abort> |
5185 | 5303 | |
5186 | 5304 | =item exit |
5187 | 5305 | |
5188 | 5306 | =for Pod::Functions terminate this program |
5189 | 5307 | |
5190 | 5308 | =begin original |
5191 | 5309 | |
5192 | 5310 | Evaluates EXPR and exits immediately with that value. Example: |
5193 | 5311 | |
5194 | 5312 | =end original |
5195 | 5313 | |
5196 | 5314 | EXPR を評価し、即座にその値を持って終了します。 |
5197 | 5315 | 例: |
5198 | 5316 | |
5199 | 5317 | my $ans = <STDIN>; |
5200 | 5318 | exit 0 if $ans =~ /^[Xx]/; |
5201 | 5319 | |
5202 | 5320 | =begin original |
5203 | 5321 | |
5204 | 5322 | See also L<C<die>|/die LIST>. If EXPR is omitted, exits with C<0> |
5205 | 5323 | status. The only |
5206 | 5324 | universally recognized values for EXPR are C<0> for success and C<1> |
5207 | 5325 | for error; other values are subject to interpretation depending on the |
5208 | 5326 | environment in which the Perl program is running. For example, exiting |
5209 | 5327 | 69 (EX_UNAVAILABLE) from a I<sendmail> incoming-mail filter will cause |
5210 | 5328 | the mailer to return the item undelivered, but that's not true everywhere. |
5211 | 5329 | |
5212 | 5330 | =end original |
5213 | 5331 | |
5214 | 5332 | L<C<die>|/die LIST> も参照してください。 |
5215 | 5333 | EXPR が省略された場合には、ステータスを C<0> として終了します。 |
5216 | 5334 | EXPR の値として広く利用可能なのは C<0> が成功で C<1> が |
5217 | 5335 | エラーということだけです; その他の値は、 Perl が実行される環境によって異なる |
5218 | 5336 | 解釈がされる可能性があります。 |
5219 | 5337 | 例えば、I<sendmail> 到着メールフィルタから 69 (EX_UNAVAILABLE) で終了すると |
5220 | 5338 | メーラーはアイテムを配達せずに差し戻しますが、 |
5221 | 5339 | これはいつでも真ではありません。 |
5222 | 5340 | |
5223 | 5341 | =begin original |
5224 | 5342 | |
5225 | 5343 | Don't use L<C<exit>|/exit EXPR> to abort a subroutine if there's any |
5226 | 5344 | chance that someone might want to trap whatever error happened. Use |
5227 | 5345 | L<C<die>|/die LIST> instead, which can be trapped by an |
5228 | 5346 | L<C<eval>|/eval EXPR>. |
5229 | 5347 | |
5230 | 5348 | =end original |
5231 | 5349 | |
5232 | 5350 | 誰かが発生したエラーをトラップしようと考えている可能性がある場合は、 |
5233 | 5351 | サブルーチンの中断に L<C<exit>|/exit EXPR> を使わないでください。 |
5234 | 5352 | 代わりに L<C<eval>|/eval EXPR> でトラップできる L<C<die>|/die LIST> を |
5235 | 5353 | 使ってください。 |
5236 | 5354 | |
5237 | 5355 | =begin original |
5238 | 5356 | |
5239 | 5357 | The L<C<exit>|/exit EXPR> function does not always exit immediately. It |
5240 | 5358 | calls any defined C<END> routines first, but these C<END> routines may |
5241 | 5359 | not themselves abort the exit. Likewise any object destructors that |
5242 | 5360 | need to be called are called before the real exit. C<END> routines and |
5243 | 5361 | destructors can change the exit status by modifying L<C<$?>|perlvar/$?>. |
5244 | 5362 | If this is a problem, you can call |
5245 | 5363 | L<C<POSIX::_exit($status)>|POSIX/C<_exit>> to avoid C<END> and destructor |
5246 | 5364 | processing. See L<perlmod> for details. |
5247 | 5365 | |
5248 | 5366 | =end original |
5249 | 5367 | |
5250 | 5368 | L<C<exit>|/exit EXPR> 関数は常に直ちに終了するわけではありません。 |
5251 | 5369 | まず、定義されている C<END> ルーチンを呼び出しますが、 |
5252 | 5370 | C<END> ルーチン自身は exit を止められません。 |
5253 | 5371 | 同様に、呼び出す必要のあるオブジェクトデストラクタは |
5254 | 5372 | すべて、実際の終了前に呼び出されます。 |
5255 | 5373 | C<END> ルーチンとデストラクタは L<C<$?>|perlvar/$?> を修正することで |
5256 | 5374 | 終了コードを変更できます。 |
5257 | 5375 | これが問題になる場合は、C<END> やデストラクタが実行されることを |
5258 | 5376 | 防ぐために L<C<POSIX::_exit($status)>|POSIX/C<_exit>> を呼び出してください。 |
5259 | 5377 | 詳しくは L<perlmod> を参照してください。 |
5260 | 5378 | |
5261 | 5379 | =begin original |
5262 | 5380 | |
5263 | 5381 | Portability issues: L<perlport/exit>. |
5264 | 5382 | |
5265 | 5383 | =end original |
5266 | 5384 | |
5267 | 5385 | 移植性の問題: L<perlport/exit>。 |
5268 | 5386 | |
5269 | 5387 | =item exp EXPR |
5270 | 5388 | X<exp> X<exponential> X<antilog> X<antilogarithm> X<e> |
5271 | 5389 | |
5272 | 5390 | =item exp |
5273 | 5391 | |
5274 | 5392 | =for Pod::Functions raise I<e> to a power |
5275 | 5393 | |
5276 | 5394 | =begin original |
5277 | 5395 | |
5278 | 5396 | Returns I<e> (the natural logarithm base) to the power of EXPR. |
5279 | 5397 | If EXPR is omitted, gives C<exp($_)>. |
5280 | 5398 | |
5281 | 5399 | =end original |
5282 | 5400 | |
5283 | 5401 | I<e> (自然対数の底) の EXPR 乗を返します。 |
5284 | 5402 | EXPR を省略した場合には、C<exp($_)> を返します。 |
5285 | 5403 | |
5286 | 5404 | =item fc EXPR |
5287 | 5405 | X<fc> X<foldcase> X<casefold> X<fold-case> X<case-fold> |
5288 | 5406 | |
5289 | 5407 | =item fc |
5290 | 5408 | |
5291 | 5409 | =for Pod::Functions +fc return casefolded version of a string |
5292 | 5410 | |
5293 | 5411 | =begin original |
5294 | 5412 | |
5295 | 5413 | Returns the casefolded version of EXPR. This is the internal function |
5296 | 5414 | implementing the C<\F> escape in double-quoted strings. |
5297 | 5415 | |
5298 | 5416 | =end original |
5299 | 5417 | |
5300 | 5418 | EXPR の畳み込み版を返します。 |
5301 | 5419 | これは、ダブルクォート文字列における、C<\F> エスケープを |
5302 | 5420 | 実装する内部関数です。 |
5303 | 5421 | |
5304 | 5422 | =begin original |
5305 | 5423 | |
5306 | 5424 | Casefolding is the process of mapping strings to a form where case |
5307 | 5425 | differences are erased; comparing two strings in their casefolded |
5308 | 5426 | form is effectively a way of asking if two strings are equal, |
5309 | 5427 | regardless of case. |
5310 | 5428 | |
5311 | 5429 | =end original |
5312 | 5430 | |
5313 | 5431 | 畳み込みは大文字小文字の違いを消した形式に文字列をマッピングする処理です; |
5314 | 5432 | 畳み込み形式で二つの文字列を比較するのは二つの文字列が大文字小文字に |
5315 | 5433 | 関わらず等しいかどうかを比較する効率的な方法です。 |
5316 | 5434 | |
5317 | 5435 | =begin original |
5318 | 5436 | |
5319 | 5437 | Roughly, if you ever found yourself writing this |
5320 | 5438 | |
5321 | 5439 | =end original |
5322 | 5440 | |
5323 | 5441 | おおよそ、自分自身で以下のように書いていたとしても |
5324 | 5442 | |
5325 | 5443 | lc($this) eq lc($that) # Wrong! |
5326 | 5444 | # or |
5327 | 5445 | uc($this) eq uc($that) # Also wrong! |
5328 | 5446 | # or |
5329 | 5447 | $this =~ /^\Q$that\E\z/i # Right! |
5330 | 5448 | |
5331 | 5449 | =begin original |
5332 | 5450 | |
5333 | 5451 | Now you can write |
5334 | 5452 | |
5335 | 5453 | =end original |
5336 | 5454 | |
5337 | 5455 | 今では以下のように書けます |
5338 | 5456 | |
5339 | 5457 | fc($this) eq fc($that) |
5340 | 5458 | |
5341 | 5459 | =begin original |
5342 | 5460 | |
5343 | 5461 | And get the correct results. |
5344 | 5462 | |
5345 | 5463 | =end original |
5346 | 5464 | |
5347 | 5465 | そして正しい結果を得られます。 |
5348 | 5466 | |
5349 | 5467 | =begin original |
5350 | 5468 | |
5351 | 5469 | Perl only implements the full form of casefolding, but you can access |
5352 | 5470 | the simple folds using L<Unicode::UCD/B<casefold()>> and |
5353 | 5471 | L<Unicode::UCD/B<prop_invmap()>>. |
5354 | 5472 | For further information on casefolding, refer to |
5355 | 5473 | the Unicode Standard, specifically sections 3.13 C<Default Case Operations>, |
5356 | 5474 | 4.2 C<Case-Normative>, and 5.18 C<Case Mappings>, |
5357 | available at L<http://www.unicode.org/versions/latest/>, as well as the | |
5475 | available at L<https://www.unicode.org/versions/latest/>, as well as the | |
5358 | Case Charts available at L<http://www.unicode.org/charts/case/>. | |
5476 | Case Charts available at L<https://www.unicode.org/charts/case/>. | |
5359 | 5477 | |
5360 | 5478 | =end original |
5361 | 5479 | |
5362 | 5480 | Perl は完全な形式の畳み込みのみを実装していますが、 |
5363 | 5481 | L<Unicode::UCD/B<casefold()>> と L<Unicode::UCD/B<prop_invmap()>> を使って |
5364 | 5482 | 単純なたたみ込みにアクセスできます。 |
5365 | 5483 | 畳み込みに関するさらなる情報については、 |
5366 | L<http://www.unicode.org/versions/latest/> で利用可能な Unicode 標準、特に | |
5484 | L<https://www.unicode.org/versions/latest/> で利用可能な Unicode 標準、特に | |
5367 | 5485 | 3.13 C<Default Case Operations>, 4.2 C<Case-Normative>, 5.18 |
5368 | C<Case Mappings> および、L<http://www.unicode.org/charts/case/> で | |
5486 | C<Case Mappings> および、L<https://www.unicode.org/charts/case/> で | |
5369 | 5487 | 利用可能なケース表を参照してください。 |
5370 | 5488 | |
5371 | 5489 | =begin original |
5372 | 5490 | |
5373 | 5491 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. |
5374 | 5492 | |
5375 | 5493 | =end original |
5376 | 5494 | |
5377 | 5495 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 |
5378 | 5496 | |
5379 | 5497 | =begin original |
5380 | 5498 | |
5381 | 5499 | This function behaves the same way under various pragmas, such as within |
5382 | 5500 | L<S<C<"use feature 'unicode_strings">>|feature/The 'unicode_strings' feature>, |
5383 | 5501 | as L<C<lc>|/lc EXPR> does, with the single exception of |
5384 | 5502 | L<C<fc>|/fc EXPR> of I<LATIN CAPITAL LETTER SHARP S> (U+1E9E) within the |
5385 | 5503 | scope of L<S<C<use locale>>|locale>. The foldcase of this character |
5386 | 5504 | would normally be C<"ss">, but as explained in the L<C<lc>|/lc EXPR> |
5387 | 5505 | section, case |
5388 | 5506 | changes that cross the 255/256 boundary are problematic under locales, |
5389 | 5507 | and are hence prohibited. Therefore, this function under locale returns |
5390 | 5508 | instead the string C<"\x{17F}\x{17F}">, which is the I<LATIN SMALL LETTER |
5391 | 5509 | LONG S>. Since that character itself folds to C<"s">, the string of two |
5392 | 5510 | of them together should be equivalent to a single U+1E9E when foldcased. |
5393 | 5511 | |
5394 | 5512 | =end original |
5395 | 5513 | |
5396 | 5514 | この関数は、 |
5397 | 5515 | L<S<C<"use feature 'unicode_strings">>|feature/The 'unicode_strings' feature> |
5398 | 5516 | のようなさまざまなプラグマの影響下では、L<C<lc>|/lc EXPR> と同様に |
5399 | 5517 | 振る舞います; |
5400 | 5518 | 但し、L<S<C<use locale>>|locale> のスコープ内での |
5401 | 5519 | I<LATIN CAPITAL LETTER SHARP S> (U+1E9E) の L<C<fc>|/fc EXPR> は例外です。 |
5402 | 5520 | この文字の畳み込み文字は普通は C<"ss"> ですが、L<C<lc>|/lc EXPR> の節で |
5403 | 5521 | 説明しているように、ロケールの基での255/256 境界をまたぐ大文字小文字の変更は |
5404 | 5522 | 問題があるので、禁止されています。 |
5405 | 5523 | 従って、ロケールの基ではこの関数は代わりに I<LATIN SMALL LETTER LONG S> である |
5406 | 5524 | C<"\x{17F}\x{17F}"> を返します。 |
5407 | 5525 | この文字自体は C<"s"> の畳み込みなので、これら二つを合わせた文字列は |
5408 | 5526 | 畳み込まれた場合は単一の U+1E9E と等価になります。 |
5409 | 5527 | |
5410 | 5528 | =begin original |
5411 | 5529 | |
5412 | 5530 | While the Unicode Standard defines two additional forms of casefolding, |
5413 | 5531 | one for Turkic languages and one that never maps one character into multiple |
5414 | 5532 | characters, these are not provided by the Perl core. However, the CPAN module |
5415 | 5533 | L<C<Unicode::Casing>|Unicode::Casing> may be used to provide an implementation. |
5416 | 5534 | |
5417 | 5535 | =end original |
5418 | 5536 | |
5419 | 5537 | Unicode 標準はさらに二つの畳み込み形式、一つはツルキ語、もう一つは決して |
5420 | 5538 | 一つの文字が複数の文字にマッピングされないもの、を定義していますが、 |
5421 | 5539 | これらは Perl コアでは提供されません。 |
5422 | 5540 | しかし、CPAN モジュール L<C<Unicode::Casing>|Unicode::Casing> が実装を |
5423 | 5541 | 提供しています。 |
5424 | 5542 | |
5425 | 5543 | =begin original |
5426 | 5544 | |
5427 | 5545 | L<C<fc>|/fc EXPR> is available only if the |
5428 | 5546 | L<C<"fc"> feature|feature/The 'fc' feature> is enabled or if it is |
5429 | 5547 | prefixed with C<CORE::>. The |
5430 | 5548 | L<C<"fc"> feature|feature/The 'fc' feature> is enabled automatically |
5431 | 5549 | with a C<use v5.16> (or higher) declaration in the current scope. |
5432 | 5550 | |
5433 | 5551 | =end original |
5434 | 5552 | |
5435 | 5553 | L<C<fc>|/fc EXPR> は L<C<"fc"> 機能|feature/The 'fc' feature> が有効か |
5436 | 5554 | C<CORE::> が前置されたときにのみ利用可能です。 |
5437 | 5555 | L<C<"fc"> 機能|feature/The 'fc' feature> は現在のスコープで |
5438 | 5556 | C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。 |
5439 | 5557 | |
5440 | 5558 | =item fcntl FILEHANDLE,FUNCTION,SCALAR |
5441 | 5559 | X<fcntl> |
5442 | 5560 | |
5443 | 5561 | =for Pod::Functions file control system call |
5444 | 5562 | |
5445 | 5563 | =begin original |
5446 | 5564 | |
5447 | 5565 | Implements the L<fcntl(2)> function. You'll probably have to say |
5448 | 5566 | |
5449 | 5567 | =end original |
5450 | 5568 | |
5451 | 5569 | L<fcntl(2)> 関数を実装します。 |
5452 | 5570 | 正しい定数定義を得るために、まず |
5453 | 5571 | |
5454 | 5572 | use Fcntl; |
5455 | 5573 | |
5456 | 5574 | =begin original |
5457 | 5575 | |
5458 | 5576 | first to get the correct constant definitions. Argument processing and |
5459 | 5577 | value returned work just like L<C<ioctl>|/ioctl |
5460 | 5578 | FILEHANDLE,FUNCTION,SCALAR> below. For example: |
5461 | 5579 | |
5462 | 5580 | =end original |
5463 | 5581 | |
5464 | 5582 | と書くことが必要でしょう。 |
5465 | 5583 | 引数の処理と返り値については、下記の |
5466 | 5584 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同様に動作します。 |
5467 | 5585 | 例えば: |
5468 | 5586 | |
5469 | 5587 | use Fcntl; |
5470 | 5588 | my $flags = fcntl($filehandle, F_GETFL, 0) |
5471 | 5589 | or die "Can't fcntl F_GETFL: $!"; |
5472 | 5590 | |
5473 | 5591 | =begin original |
5474 | 5592 | |
5475 | 5593 | You don't have to check for L<C<defined>|/defined EXPR> on the return |
5476 | 5594 | from L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>. Like |
5477 | 5595 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>, it maps a C<0> return |
5478 | 5596 | from the system call into C<"0 but true"> in Perl. This string is true |
5479 | 5597 | in boolean context and C<0> in numeric context. It is also exempt from |
5480 | 5598 | the normal |
5481 | 5599 | L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s> |
5482 | 5600 | L<warnings> on improper numeric conversions. |
5483 | 5601 | |
5484 | 5602 | =end original |
5485 | 5603 | |
5486 | 5604 | L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> からの返り値のチェックに |
5487 | 5605 | L<C<defined>|/defined EXPR> を使う必要はありません。 |
5488 | 5606 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と違って、これは |
5489 | 5607 | システムコールの結果が C<0> だった場合は C<"0 だが真"> を返します。 |
5490 | 5608 | この文字列は真偽値コンテキストでは真となり、 |
5491 | 5609 | 数値コンテキストでは C<0> になります。 |
5492 | 5610 | これはまた、不適切な数値変換に関する通常の |
5493 | 5611 | L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s> |
5494 | 5612 | L<warnings> を回避します。 |
5495 | 5613 | |
5496 | 5614 | =begin original |
5497 | 5615 | |
5498 | 5616 | Note that L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> raises an |
5499 | 5617 | exception if used on a machine that doesn't implement L<fcntl(2)>. See |
5500 | 5618 | the L<Fcntl> module or your L<fcntl(2)> manpage to learn what functions |
5501 | 5619 | are available on your system. |
5502 | 5620 | |
5503 | 5621 | =end original |
5504 | 5622 | |
5505 | 5623 | L<fcntl(2)> が実装されていないマシンでは、 |
5506 | 5624 | L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> は例外を |
5507 | 5625 | 引き起こすことに注意してください。 |
5508 | 5626 | システムでどの関数が利用可能かについては L<Fcntl> モジュールや |
5509 | 5627 | L<fcntl(2)> man ページを参照してください。 |
5510 | 5628 | |
5511 | 5629 | =begin original |
5512 | 5630 | |
5513 | 5631 | Here's an example of setting a filehandle named C<$REMOTE> to be |
5514 | 5632 | non-blocking at the system level. You'll have to negotiate |
5515 | 5633 | L<C<$E<verbar>>|perlvar/$E<verbar>> on your own, though. |
5516 | 5634 | |
5517 | 5635 | =end original |
5518 | 5636 | |
5519 | 5637 | これは C<$REMOTE> というファイルハンドルをシステムレベルで |
5520 | 5638 | 非ブロックモードにセットする例です。 |
5521 | 5639 | ただし、 L<C<$E<verbar>>|perlvar/$E<verbar>> を自分で管理しなければなりません。 |
5522 | 5640 | |
5523 | 5641 | use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK); |
5524 | 5642 | |
5525 | 5643 | my $flags = fcntl($REMOTE, F_GETFL, 0) |
5526 | 5644 | or die "Can't get flags for the socket: $!\n"; |
5527 | 5645 | |
5528 | 5646 | fcntl($REMOTE, F_SETFL, $flags | O_NONBLOCK) |
5529 | 5647 | or die "Can't set flags for the socket: $!\n"; |
5530 | 5648 | |
5531 | 5649 | =begin original |
5532 | 5650 | |
5533 | 5651 | Portability issues: L<perlport/fcntl>. |
5534 | 5652 | |
5535 | 5653 | =end original |
5536 | 5654 | |
5537 | 5655 | 移植性の問題: L<perlport/fcntl>。 |
5538 | 5656 | |
5539 | 5657 | =item __FILE__ |
5540 | 5658 | X<__FILE__> |
5541 | 5659 | |
5542 | 5660 | =for Pod::Functions the name of the current source file |
5543 | 5661 | |
5544 | 5662 | =begin original |
5545 | 5663 | |
5546 | 5664 | A special token that returns the name of the file in which it occurs. |
5665 | It can be altered by the mechanism described at | |
5666 | L<perlsyn/"Plain Old Comments (Not!)">. | |
5547 | 5667 | |
5548 | 5668 | =end original |
5549 | 5669 | |
5550 | 5670 | これが書いてあるファイルの名前を返す特殊トークン。 |
5671 | L<perlsyn/"Plain Old Comments (Not!)"> で記述されている機構を使って | |
5672 | 置き換えられます。 | |
5551 | 5673 | |
5552 | 5674 | =item fileno FILEHANDLE |
5553 | 5675 | X<fileno> |
5554 | 5676 | |
5677 | =item fileno DIRHANDLE | |
5678 | ||
5555 | 5679 | =for Pod::Functions return file descriptor from filehandle |
5556 | 5680 | |
5557 | 5681 | =begin original |
5558 | 5682 | |
5559 | Returns the file descriptor for a filehandle | |
5683 | Returns the file descriptor for a filehandle or directory handle, | |
5684 | or undefined if the | |
5560 | 5685 | filehandle is not open. If there is no real file descriptor at the OS |
5561 | 5686 | level, as can happen with filehandles connected to memory objects via |
5562 | L<C<open>|/open FILEHANDLE,EXPR> with a reference for the third | |
5687 | L<C<open>|/open FILEHANDLE,MODE,EXPR> with a reference for the third | |
5563 | 5688 | argument, -1 is returned. |
5564 | 5689 | |
5565 | 5690 | =end original |
5566 | 5691 | |
5567 | ファイルハンドルに対するファイル記述子を返します; | |
5692 | ファイルハンドルやディレクトリハンドルに対するファイル記述子を返します; | |
5568 | オープンしていない場合は未定義値を返します。 | |
5693 | ファイルハンドルがオープンしていない場合は未定義値を返します。 | |
5569 | OS レベルで実際のファイル記述子がない( | |
5694 | OS レベルで実際のファイル記述子がない( | |
5570 | 第 3 引数にリファレンスを | |
5695 | L<C<open>|/open FILEHANDLE,MODE,EXPR> の第 3 引数にリファレンスを | |
5571 | 5696 | 指定してファイルハンドルがメモリオブジェクトと結びつけられたときに |
5572 | 5697 | 起こります)場合、-1 が返されます。 |
5573 | 5698 | |
5574 | 5699 | =begin original |
5575 | 5700 | |
5576 | 5701 | This is mainly useful for constructing bitmaps for |
5577 | 5702 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> and low-level POSIX |
5578 | 5703 | tty-handling operations. |
5579 | 5704 | If FILEHANDLE is an expression, the value is taken as an indirect |
5580 | 5705 | filehandle, generally its name. |
5581 | 5706 | |
5582 | 5707 | =end original |
5583 | 5708 | |
5584 | 5709 | これは主に L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> や低レベル |
5585 | 5710 | POSIX tty 操作に対する、ビットマップを構成するときに便利です。 |
5586 | 5711 | FILEHANDLE が式であれば、 |
5587 | 5712 | その値が間接ファイルハンドル(普通は名前)として使われます。 |
5588 | 5713 | |
5589 | 5714 | =begin original |
5590 | 5715 | |
5591 | 5716 | You can use this to find out whether two handles refer to the |
5592 | 5717 | same underlying descriptor: |
5593 | 5718 | |
5594 | 5719 | =end original |
5595 | 5720 | |
5596 | 5721 | これを、二つのハンドルが同じ識別子を参照しているかどうかを見つけるのに |
5597 | 5722 | 使えます: |
5598 | 5723 | |
5599 | 5724 | if (fileno($this) != -1 && fileno($this) == fileno($that)) { |
5600 | 5725 | print "\$this and \$that are dups\n"; |
5601 | 5726 | } elsif (fileno($this) != -1 && fileno($that) != -1) { |
5602 | 5727 | print "\$this and \$that have different " . |
5603 | 5728 | "underlying file descriptors\n"; |
5604 | 5729 | } else { |
5605 | 5730 | print "At least one of \$this and \$that does " . |
5606 | 5731 | "not have a real file descriptor\n"; |
5607 | 5732 | } |
5608 | 5733 | |
5609 | 5734 | =begin original |
5610 | 5735 | |
5611 | 5736 | The behavior of L<C<fileno>|/fileno FILEHANDLE> on a directory handle |
5612 | 5737 | depends on the operating system. On a system with L<dirfd(3)> or |
5613 | 5738 | similar, L<C<fileno>|/fileno FILEHANDLE> on a directory |
5614 | 5739 | handle returns the underlying file descriptor associated with the |
5615 | 5740 | handle; on systems with no such support, it returns the undefined value, |
5616 | 5741 | and sets L<C<$!>|perlvar/$!> (errno). |
5617 | 5742 | |
5618 | 5743 | =end original |
5619 | 5744 | |
5620 | 5745 | ディレクトリハンドルに対する L<C<fileno>|/fileno FILEHANDLE> の振る舞いは |
5621 | 5746 | オペレーティングシステムに依存します。 |
5622 | 5747 | L<dirfd(3)> のようなものがあるシステムでは、ディレクトリハンドルに対する |
5623 | 5748 | L<C<fileno>|/fileno FILEHANDLE> はハンドルに関連付けられた基となる |
5624 | 5749 | ファイル記述子を返します; |
5625 | 5750 | そのような対応がないシステムでは、未定義値を返し、 |
5626 | 5751 | L<C<$!>|perlvar/$!> (errno) を設定します。 |
5627 | 5752 | |
5628 | 5753 | =item flock FILEHANDLE,OPERATION |
5629 | 5754 | X<flock> X<lock> X<locking> |
5630 | 5755 | |
5631 | 5756 | =for Pod::Functions lock an entire file with an advisory lock |
5632 | 5757 | |
5633 | 5758 | =begin original |
5634 | 5759 | |
5635 | 5760 | Calls L<flock(2)>, or an emulation of it, on FILEHANDLE. Returns true |
5636 | 5761 | for success, false on failure. Produces a fatal error if used on a |
5637 | 5762 | machine that doesn't implement L<flock(2)>, L<fcntl(2)> locking, or |
5638 | 5763 | L<lockf(3)>. L<C<flock>|/flock FILEHANDLE,OPERATION> is Perl's portable |
5639 | 5764 | file-locking interface, although it locks entire files only, not |
5640 | 5765 | records. |
5641 | 5766 | |
5642 | 5767 | =end original |
5643 | 5768 | |
5644 | 5769 | FILEHANDLE に対して L<flock(2)>、またはそのエミュレーションを呼び出します。 |
5645 | 5770 | 成功時には真を、失敗時には偽を返します。 |
5646 | 5771 | L<flock(2)>, L<fcntl(2)> ロック, L<lockf(3)> のいずれかを実装していない |
5647 | 5772 | マシンで使うと、致命的エラーが発生します。 |
5648 | 5773 | L<C<flock>|/flock FILEHANDLE,OPERATION> は Perl の移植性のある |
5649 | 5774 | ファイルロックインターフェースです; |
5650 | 5775 | しかしレコードではなく、ファイル全体のみをロックします。 |
5651 | 5776 | |
5652 | 5777 | =begin original |
5653 | 5778 | |
5654 | 5779 | Two potentially non-obvious but traditional L<C<flock>|/flock |
5655 | 5780 | FILEHANDLE,OPERATION> semantics are |
5656 | 5781 | that it waits indefinitely until the lock is granted, and that its locks |
5657 | 5782 | are B<merely advisory>. Such discretionary locks are more flexible, but |
5658 | 5783 | offer fewer guarantees. This means that programs that do not also use |
5659 | 5784 | L<C<flock>|/flock FILEHANDLE,OPERATION> may modify files locked with |
5660 | 5785 | L<C<flock>|/flock FILEHANDLE,OPERATION>. See L<perlport>, |
5661 | 5786 | your port's specific documentation, and your system-specific local manpages |
5662 | 5787 | for details. It's best to assume traditional behavior if you're writing |
5663 | 5788 | portable programs. (But if you're not, you should as always feel perfectly |
5664 | 5789 | free to write for your own system's idiosyncrasies (sometimes called |
5665 | 5790 | "features"). Slavish adherence to portability concerns shouldn't get |
5666 | 5791 | in the way of your getting your job done.) |
5667 | 5792 | |
5668 | 5793 | =end original |
5669 | 5794 | |
5670 | 5795 | 明白ではないものの、伝統的な L<C<flock>|/flock FILEHANDLE,OPERATION> の |
5671 | 5796 | 動作としては、ロックが得られるまで |
5672 | 5797 | 無限に待ち続けるものと、B<単に勧告的に> ロックするものの二つがあります。 |
5673 | 5798 | このような自由裁量のロックはより柔軟ですが、保障されるものはより少ないです。 |
5674 | 5799 | これは、L<C<flock>|/flock FILEHANDLE,OPERATION> を使わないプログラムが |
5675 | 5800 | L<C<flock>|/flock FILEHANDLE,OPERATION> でロックされたファイルを |
5676 | 5801 | 書き換えるかもしれないことを意味します。 |
5677 | 5802 | 詳細については、L<perlport>、システム固有のドキュメント、システム固有の |
5678 | 5803 | ローカルの man ページを参照してください。 |
5679 | 5804 | 移植性のあるプログラムを書く場合は、伝統的な振る舞いを仮定するのが |
5680 | 5805 | ベストです。 |
5681 | 5806 | (しかし移植性のないプログラムを書く場合は、自身のシステムの性癖(しばしば |
5682 | 5807 | 「仕様」と呼ばれます)に合わせて書くことも完全に自由です。 |
5683 | 5808 | 盲目的に移植性に固執することで、あなたの作業を仕上げるのを邪魔するべきでは |
5684 | 5809 | ありません。) |
5685 | 5810 | |
5686 | 5811 | =begin original |
5687 | 5812 | |
5688 | 5813 | OPERATION is one of LOCK_SH, LOCK_EX, or LOCK_UN, possibly combined with |
5689 | 5814 | LOCK_NB. These constants are traditionally valued 1, 2, 8 and 4, but |
5690 | 5815 | you can use the symbolic names if you import them from the L<Fcntl> module, |
5691 | 5816 | either individually, or as a group using the C<:flock> tag. LOCK_SH |
5692 | 5817 | requests a shared lock, LOCK_EX requests an exclusive lock, and LOCK_UN |
5693 | 5818 | releases a previously requested lock. If LOCK_NB is bitwise-or'ed with |
5694 | 5819 | LOCK_SH or LOCK_EX, then L<C<flock>|/flock FILEHANDLE,OPERATION> returns |
5695 | 5820 | immediately rather than blocking waiting for the lock; check the return |
5696 | 5821 | status to see if you got it. |
5697 | 5822 | |
5698 | 5823 | =end original |
5699 | 5824 | |
5700 | 5825 | OPERATION は LOCK_SH, LOCK_EX, LOCK_UN のいずれかで、LOCK_NB と |
5701 | 5826 | 組み合わされることもあります。 |
5702 | 5827 | これらの定数は伝統的には 1, 2, 8, 4 の値を持ちますが、L<Fcntl> モジュールから |
5703 | 5828 | シンボル名を独立してインポートするか、C<:flock> タグを使うグループとして、 |
5704 | 5829 | シンボル名をを使うことができます。 |
5705 | 5830 | LOCK_SH は共有ロックを要求し、LOCK_EX は排他ロックを要求し、LOCK_UN は |
5706 | 5831 | 前回要求したロックを開放します。 |
5707 | 5832 | LOCK_NB と LOCK_SH か LOCK_EX がビット単位の論理和されると、 |
5708 | 5833 | L<C<flock>|/flock FILEHANDLE,OPERATION> は |
5709 | 5834 | ロックを取得するまで待つのではなく、すぐに返ります; |
5710 | 5835 | ロックが取得できたかどうかは返り値を調べます。 |
5711 | 5836 | |
5712 | 5837 | =begin original |
5713 | 5838 | |
5714 | 5839 | To avoid the possibility of miscoordination, Perl now flushes FILEHANDLE |
5715 | 5840 | before locking or unlocking it. |
5716 | 5841 | |
5717 | 5842 | =end original |
5718 | 5843 | |
5719 | 5844 | 不一致の可能性を避けるために、Perl はファイルをロック、アンロックする前に |
5720 | 5845 | FILEHANDLE をフラッシュします。 |
5721 | 5846 | |
5722 | 5847 | =begin original |
5723 | 5848 | |
5724 | 5849 | Note that the emulation built with L<lockf(3)> doesn't provide shared |
5725 | 5850 | locks, and it requires that FILEHANDLE be open with write intent. These |
5726 | 5851 | are the semantics that L<lockf(3)> implements. Most if not all systems |
5727 | 5852 | implement L<lockf(3)> in terms of L<fcntl(2)> locking, though, so the |
5728 | 5853 | differing semantics shouldn't bite too many people. |
5729 | 5854 | |
5730 | 5855 | =end original |
5731 | 5856 | |
5732 | 5857 | L<lockf(3)> で作成されたエミュレーションは共有ロックを提供せず、 |
5733 | 5858 | FILEHANDLE が書き込みモードで開いていることを必要とすることに |
5734 | 5859 | 注意してください。 |
5735 | 5860 | これは L<lockf(3)> が実装している動作です。 |
5736 | 5861 | しかし、全てではないにしてもほとんどのシステムでは L<fcntl(2)> を使って |
5737 | 5862 | L<lockf(3)> を実装しているので、異なった動作で多くの人々を混乱させることは |
5738 | 5863 | ないはずです。 |
5739 | 5864 | |
5740 | 5865 | =begin original |
5741 | 5866 | |
5742 | 5867 | Note that the L<fcntl(2)> emulation of L<flock(3)> requires that FILEHANDLE |
5743 | 5868 | be open with read intent to use LOCK_SH and requires that it be open |
5744 | 5869 | with write intent to use LOCK_EX. |
5745 | 5870 | |
5746 | 5871 | =end original |
5747 | 5872 | |
5748 | 5873 | L<flock(3)> の L<fcntl(2)> エミュレーションは、 LOCK_SH を使うためには |
5749 | 5874 | FILEHANDLE を読み込みで開いている必要があり、LOCK_EX を使うためには |
5750 | 5875 | 書き込みで開いている必要があることに注意してください。 |
5751 | 5876 | |
5752 | 5877 | =begin original |
5753 | 5878 | |
5754 | 5879 | Note also that some versions of L<C<flock>|/flock FILEHANDLE,OPERATION> |
5755 | 5880 | cannot lock things over the network; you would need to use the more |
5756 | 5881 | system-specific L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> for |
5757 | 5882 | that. If you like you can force Perl to ignore your system's L<flock(2)> |
5758 | 5883 | function, and so provide its own L<fcntl(2)>-based emulation, by passing |
5759 | 5884 | the switch C<-Ud_flock> to the F<Configure> program when you configure |
5760 | 5885 | and build a new Perl. |
5761 | 5886 | |
5762 | 5887 | =end original |
5763 | 5888 | |
5764 | 5889 | ネットワーク越しにはロックできない L<C<flock>|/flock FILEHANDLE,OPERATION> も |
5765 | 5890 | あることに注意してください; |
5766 | 5891 | このためには、よりシステム依存な |
5767 | 5892 | L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> を使う必要があります。 |
5768 | 5893 | Perl にシステムの L<flock(2)> 関数を無視させ、自身の L<fcntl(2)> ベースの |
5769 | 5894 | エミュレーションを使う場合は、新しい Perl を設定およびビルドするときに |
5770 | 5895 | F<Configure> プログラムに C<-Ud_flock> オプションを渡してください。 |
5771 | 5896 | |
5772 | 5897 | =begin original |
5773 | 5898 | |
5774 | 5899 | Here's a mailbox appender for BSD systems. |
5775 | 5900 | |
5776 | 5901 | =end original |
5777 | 5902 | |
5778 | 5903 | BSD システムでのメールボックスへの追加処理の例を示します。 |
5779 | 5904 | |
5780 | 5905 | # import LOCK_* and SEEK_END constants |
5781 | 5906 | use Fcntl qw(:flock SEEK_END); |
5782 | 5907 | |
5783 | 5908 | sub lock { |
5784 | 5909 | my ($fh) = @_; |
5785 | 5910 | flock($fh, LOCK_EX) or die "Cannot lock mailbox - $!\n"; |
5911 | # and, in case we're running on a very old UNIX | |
5787 | # an | |
5912 | # variant without the modern O_APPEND semantics... | |
5788 | 5913 | seek($fh, 0, SEEK_END) or die "Cannot seek - $!\n"; |
5789 | 5914 | } |
5790 | 5915 | |
5791 | 5916 | sub unlock { |
5792 | 5917 | my ($fh) = @_; |
5793 | 5918 | flock($fh, LOCK_UN) or die "Cannot unlock mailbox - $!\n"; |
5794 | 5919 | } |
5795 | 5920 | |
5796 | 5921 | open(my $mbox, ">>", "/usr/spool/mail/$ENV{'USER'}") |
5797 | 5922 | or die "Can't open mailbox: $!"; |
5798 | 5923 | |
5799 | 5924 | lock($mbox); |
5800 | 5925 | print $mbox $msg,"\n\n"; |
5801 | 5926 | unlock($mbox); |
5802 | 5927 | |
5803 | 5928 | =begin original |
5804 | 5929 | |
5805 | 5930 | On systems that support a real L<flock(2)>, locks are inherited across |
5806 | 5931 | L<C<fork>|/fork> calls, whereas those that must resort to the more |
5807 | 5932 | capricious L<fcntl(2)> function lose their locks, making it seriously |
5808 | 5933 | harder to write servers. |
5809 | 5934 | |
5810 | 5935 | =end original |
5811 | 5936 | |
5812 | 5937 | 真の L<flock(2)> に対応しているシステムではロックは L<C<fork>|/fork> を通して |
5813 | 5938 | 継承されるのに対して、より不安定な L<fcntl(2)> に頼らなければならない場合、 |
5814 | 5939 | サーバを書くのは本当により難しくなります。 |
5815 | 5940 | |
5816 | 5941 | =begin original |
5817 | 5942 | |
5818 | 5943 | See also L<DB_File> for other L<C<flock>|/flock FILEHANDLE,OPERATION> |
5819 | 5944 | examples. |
5820 | 5945 | |
5821 | 5946 | =end original |
5822 | 5947 | |
5823 | 5948 | その他の L<C<flock>|/flock FILEHANDLE,OPERATION> の例としては L<DB_File> も |
5824 | 5949 | 参照してください。 |
5825 | 5950 | |
5826 | 5951 | =begin original |
5827 | 5952 | |
5828 | 5953 | Portability issues: L<perlport/flock>. |
5829 | 5954 | |
5830 | 5955 | =end original |
5831 | 5956 | |
5832 | 5957 | 移植性の問題: L<perlport/flock>。 |
5833 | 5958 | |
5834 | 5959 | =item fork |
5835 | 5960 | X<fork> X<child> X<parent> |
5836 | 5961 | |
5837 | 5962 | =for Pod::Functions create a new process just like this one |
5838 | 5963 | |
5839 | 5964 | =begin original |
5840 | 5965 | |
5841 | 5966 | Does a L<fork(2)> system call to create a new process running the |
5842 | 5967 | same program at the same point. It returns the child pid to the |
5843 | 5968 | parent process, C<0> to the child process, or L<C<undef>|/undef EXPR> if |
5844 | 5969 | the fork is |
5845 | 5970 | unsuccessful. File descriptors (and sometimes locks on those descriptors) |
5846 | 5971 | are shared, while everything else is copied. On most systems supporting |
5847 | 5972 | L<fork(2)>, great care has gone into making it extremely efficient (for |
5848 | 5973 | example, using copy-on-write technology on data pages), making it the |
5849 | 5974 | dominant paradigm for multitasking over the last few decades. |
5850 | 5975 | |
5851 | 5976 | =end original |
5852 | 5977 | |
5853 | 5978 | 同じプログラムの同じ地点から開始する新しいプロセスを作成するために |
5854 | 5979 | システムコール L<fork(2)> を行ないます。 |
5855 | 5980 | 親プロセスには、チャイルドプロセスの pid を、 |
5856 | 5981 | チャイルドプロセスに C<0> を返しますが、 |
5857 | 5982 | fork に失敗したときには、L<C<undef>|/undef EXPR>を返します。 |
5858 | 5983 | ファイル記述子(および記述子に関連するロック)は共有され、 |
5859 | 5984 | その他の全てはコピーされます。 |
5860 | 5985 | L<fork(2)> に対応するほとんどのシステムでは、 |
5861 | 5986 | これを極めて効率的にするために多大な努力が払われてきました |
5862 | 5987 | (例えば、データページへの copy-on-write テクノロジーなどです); |
5863 | 5988 | これはここ 20 年にわたるマルチタスクに関する主要なパラダイムとなっています。 |
5864 | 5989 | |
5865 | 5990 | =begin original |
5866 | 5991 | |
5867 | 5992 | Perl attempts to flush all files opened for output before forking the |
5868 | 5993 | child process, but this may not be supported on some platforms (see |
5869 | 5994 | L<perlport>). To be safe, you may need to set |
5870 | 5995 | L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>) or |
5871 | 5996 | call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS> on |
5872 | 5997 | any open handles to avoid duplicate output. |
5873 | 5998 | |
5874 | 5999 | =end original |
5875 | 6000 | |
5876 | 6001 | v5.6.0 から、Perl は子プロセスを fork する前に出力用にオープンしている全ての |
5877 | 6002 | ファイルをフラッシュしようとしますが、これに対応していないプラットフォームも |
5878 | 6003 | あります(L<perlport> を参照してください)。 |
5879 | 6004 | 安全のためには、出力が重複するのを避けるために、 |
5880 | 6005 | 全てのオープンしているハンドルに対して L<C<$E<verbar>>|perlvar/$E<verbar>> |
5881 | 6006 | (L<English> モジュールでは C<$AUTOFLUSH>) を設定するか、 |
5882 | 6007 | L<C<IO::Handle>|IO::Handle/METHODS> モジュールの C<autoflush> メソッドを |
5883 | 6008 | 呼ぶ必要があるかもしれません。 |
5884 | 6009 | |
5885 | 6010 | =begin original |
5886 | 6011 | |
5887 | 6012 | If you L<C<fork>|/fork> without ever waiting on your children, you will |
5888 | 6013 | accumulate zombies. On some systems, you can avoid this by setting |
5889 | 6014 | L<C<$SIG{CHLD}>|perlvar/%SIG> to C<"IGNORE">. See also L<perlipc> for |
5890 | 6015 | more examples of forking and reaping moribund children. |
5891 | 6016 | |
5892 | 6017 | =end original |
5893 | 6018 | |
5894 | 6019 | チャイルドプロセスの終了を待たずに、L<C<fork>|/fork> を繰り返せば、 |
5895 | 6020 | ゾンビをためこむことになります。 |
5896 | 6021 | L<C<$SIG{CHLD}>|perlvar/%SIG> に C<"IGNORE"> を指定することでこれを |
5897 | 6022 | 回避できるシステムもあります。 |
5898 | 6023 | fork と消滅しかけている子プロセスを回収するための更なる例については |
5899 | 6024 | L<perlipc> も参照してください。 |
5900 | 6025 | |
5901 | 6026 | =begin original |
5902 | 6027 | |
5903 | 6028 | Note that if your forked child inherits system file descriptors like |
5904 | 6029 | STDIN and STDOUT that are actually connected by a pipe or socket, even |
5905 | 6030 | if you exit, then the remote server (such as, say, a CGI script or a |
5906 | 6031 | backgrounded job launched from a remote shell) won't think you're done. |
5907 | 6032 | You should reopen those to F</dev/null> if it's any issue. |
5908 | 6033 | |
5909 | 6034 | =end original |
5910 | 6035 | |
5911 | 6036 | fork した子プロセスが STDIN や STDOUT といったシステムファイル記述子を |
5912 | 6037 | 継承する場合、(CGI スクリプトやリモートシェルといった |
5913 | 6038 | バックグラウンドジョブのような)リモートサーバは考え通りに |
5914 | 6039 | 動かないであろうことに注意してください。 |
5915 | 6040 | このような場合ではこれらを F</dev/null> として再オープンするべきです。 |
5916 | 6041 | |
5917 | 6042 | =begin original |
5918 | 6043 | |
5919 | 6044 | On some platforms such as Windows, where the L<fork(2)> system call is |
5920 | 6045 | not available, Perl can be built to emulate L<C<fork>|/fork> in the Perl |
5921 | 6046 | interpreter. The emulation is designed, at the level of the Perl |
5922 | 6047 | program, to be as compatible as possible with the "Unix" L<fork(2)>. |
5923 | 6048 | However it has limitations that have to be considered in code intended |
5924 | 6049 | to be portable. See L<perlfork> for more details. |
5925 | 6050 | |
5926 | 6051 | =end original |
5927 | 6052 | |
5928 | 6053 | Windows のような L<fork(2)> が利用不能なシステムでは、Perl は |
5929 | 6054 | L<C<fork>|/fork> を Perl インタプリタでエミュレートします。 |
5930 | 6055 | エミュレーションは Perl プログラムのレベルではできるだけ "Unix" L<fork(2)> と |
5931 | 6056 | 互換性があるように設計されています。 |
5932 | 6057 | しかしコードが移植性があると考えられるように制限があります。 |
5933 | 6058 | さらなる詳細については L<perlfork> を参照してください。 |
5934 | 6059 | |
5935 | 6060 | =begin original |
5936 | 6061 | |
5937 | 6062 | Portability issues: L<perlport/fork>. |
5938 | 6063 | |
5939 | 6064 | =end original |
5940 | 6065 | |
5941 | 6066 | 移植性の問題: L<perlport/fork>。 |
5942 | 6067 | |
5943 | 6068 | =item format |
5944 | 6069 | X<format> |
5945 | 6070 | |
5946 | 6071 | =for Pod::Functions declare a picture format with use by the write() function |
5947 | 6072 | |
5948 | 6073 | =begin original |
5949 | 6074 | |
5950 | 6075 | Declare a picture format for use by the L<C<write>|/write FILEHANDLE> |
5951 | 6076 | function. For example: |
5952 | 6077 | |
5953 | 6078 | =end original |
5954 | 6079 | |
5955 | 6080 | L<C<write>|/write FILEHANDLE> 関数で使うピクチャーフォーマットを宣言します。 |
5956 | 6081 | 例えば: |
5957 | 6082 | |
5958 | 6083 | format Something = |
5959 | 6084 | Test: @<<<<<<<< @||||| @>>>>> |
5960 | 6085 | $str, $%, '$' . int($num) |
5961 | 6086 | . |
5962 | 6087 | |
5963 | 6088 | $str = "widget"; |
5964 | 6089 | $num = $cost/$quantity; |
5965 | 6090 | $~ = 'Something'; |
5966 | 6091 | write; |
5967 | 6092 | |
5968 | 6093 | =begin original |
5969 | 6094 | |
5970 | 6095 | See L<perlform> for many details and examples. |
5971 | 6096 | |
5972 | 6097 | =end original |
5973 | 6098 | |
5974 | 6099 | 詳細と例については L<perlform> を参照してください。 |
5975 | 6100 | |
5976 | 6101 | =item formline PICTURE,LIST |
5977 | 6102 | X<formline> |
5978 | 6103 | |
5979 | 6104 | =for Pod::Functions internal function used for formats |
5980 | 6105 | |
5981 | 6106 | =begin original |
5982 | 6107 | |
5983 | 6108 | This is an internal function used by L<C<format>|/format>s, though you |
5984 | 6109 | may call it, too. It formats (see L<perlform>) a list of values |
5985 | 6110 | according to the contents of PICTURE, placing the output into the format |
5986 | 6111 | output accumulator, L<C<$^A>|perlvar/$^A> (or C<$ACCUMULATOR> in |
5987 | 6112 | L<English>). Eventually, when a L<C<write>|/write FILEHANDLE> is done, |
5988 | 6113 | the contents of L<C<$^A>|perlvar/$^A> are written to some filehandle. |
5989 | 6114 | You could also read L<C<$^A>|perlvar/$^A> and then set |
5990 | 6115 | L<C<$^A>|perlvar/$^A> back to C<"">. Note that a format typically does |
5991 | 6116 | one L<C<formline>|/formline PICTURE,LIST> per line of form, but the |
5992 | 6117 | L<C<formline>|/formline PICTURE,LIST> function itself doesn't care how |
5993 | 6118 | many newlines are embedded in the PICTURE. This means that the C<~> and |
5994 | 6119 | C<~~> tokens treat the entire PICTURE as a single line. You may |
5995 | 6120 | therefore need to use multiple formlines to implement a single record |
5996 | 6121 | format, just like the L<C<format>|/format> compiler. |
5997 | 6122 | |
5998 | 6123 | =end original |
5999 | 6124 | |
6000 | 6125 | これは、L<C<format>|/format> が使用する内部関数ですが、直接呼び出すことも |
6001 | 6126 | できます。 |
6002 | 6127 | これは、PICTURE の内容にしたがって、LIST の値を整形し (L<perlform> を |
6003 | 6128 | 参照してください)、結果をフォーマット出力アキュムレータL<C<$^A>|perlvar/$^A> |
6004 | 6129 | (L<English> モジュールでは C<$ACCUMULATOR>) に納めます。 |
6005 | 6130 | 最終的に、L<C<write>|/write FILEHANDLE> が実行されると、 |
6006 | 6131 | L<C<$^A>|perlvar/$^A> の中身が、何らかのファイルハンドルに書き出されます。 |
6007 | 6132 | また、自分で L<C<$^A>|perlvar/$^A> を読んで、L<C<$^A>|perlvar/$^A> の内容を |
6008 | 6133 | C<""> に戻してもかまいません。 |
6009 | 6134 | format は通常、1 行ごとに L<C<formline>|/formline PICTURE,LIST> を |
6010 | 6135 | 行ないますが、L<C<formline>|/formline PICTURE,LIST> 関数自身は、PICTURE の中に |
6011 | 6136 | いくつの改行が入っているかは、関係がありません。 |
6012 | 6137 | これは、C<~> と C<~~>トークンは PICTURE 全体を一行として扱うことを意味します。 |
6013 | 6138 | 従って、1 レコードフォーマットを実装するためには |
6014 | 6139 | L<C<format>|/format> コンパイラのような複数 formline を使う必要があります。 |
6015 | 6140 | |
6016 | 6141 | =begin original |
6017 | 6142 | |
6018 | 6143 | Be careful if you put double quotes around the picture, because an C<@> |
6019 | 6144 | character may be taken to mean the beginning of an array name. |
6020 | 6145 | L<C<formline>|/formline PICTURE,LIST> always returns true. See |
6021 | 6146 | L<perlform> for other examples. |
6022 | 6147 | |
6023 | 6148 | =end original |
6024 | 6149 | |
6025 | 6150 | ダブルクォートで PICTURE を囲む場合には、C<@> という文字が |
6026 | 6151 | 配列名の始まりと解釈されますので、注意してください。 |
6027 | 6152 | L<C<formline>|/formline PICTURE,LIST> は常に真を返します。 |
6028 | 6153 | その他の例については L<perlform> を参照してください。 |
6029 | 6154 | |
6030 | 6155 | =begin original |
6031 | 6156 | |
6032 | 6157 | If you are trying to use this instead of L<C<write>|/write FILEHANDLE> |
6033 | 6158 | to capture the output, you may find it easier to open a filehandle to a |
6034 | 6159 | scalar (C<< open my $fh, ">", \$output >>) and write to that instead. |
6035 | 6160 | |
6036 | 6161 | =end original |
6037 | 6162 | |
6038 | 6163 | 出力を捕捉するために L<C<write>|/write FILEHANDLE> の代わりにこれを |
6039 | 6164 | 使おうとした場合、スカラにファイルハンドルを開いて |
6040 | 6165 | (C<< open my $fh, ">", \$output >>)、 |
6041 | 6166 | 代わりにここに出力する方が簡単であることに気付くでしょう。 |
6042 | 6167 | |
6043 | 6168 | =item getc FILEHANDLE |
6044 | 6169 | X<getc> X<getchar> X<character> X<file, read> |
6045 | 6170 | |
6046 | 6171 | =item getc |
6047 | 6172 | |
6048 | 6173 | =for Pod::Functions get the next character from the filehandle |
6049 | 6174 | |
6050 | 6175 | =begin original |
6051 | 6176 | |
6052 | 6177 | Returns the next character from the input file attached to FILEHANDLE, |
6053 | 6178 | or the undefined value at end of file or if there was an error (in |
6054 | 6179 | the latter case L<C<$!>|perlvar/$!> is set). If FILEHANDLE is omitted, |
6055 | 6180 | reads from |
6056 | 6181 | STDIN. This is not particularly efficient. However, it cannot be |
6057 | 6182 | used by itself to fetch single characters without waiting for the user |
6058 | 6183 | to hit enter. For that, try something more like: |
6059 | 6184 | |
6060 | 6185 | =end original |
6061 | 6186 | |
6062 | 6187 | FILEHANDLE につながれている入力ファイルから、次の一文字を返します; |
6063 | 6188 | ファイルの最後、またはエラーが発生した場合は、未定義値を返します |
6064 | 6189 | (後者の場合は L<C<$!>|perlvar/$!> がセットされます)。 |
6065 | 6190 | FILEHANDLE が省略された場合には、STDIN から読み込みを行ないます。 |
6066 | 6191 | これは特に効率的ではありません。 |
6067 | 6192 | しかし、これはユーザーがリターンキーを押すのを待つことなく |
6068 | 6193 | 一文字を読み込む用途には使えません。 |
6069 | 6194 | そのような場合には、以下のようなものを試して見てください: |
6070 | 6195 | |
6071 | 6196 | if ($BSD_STYLE) { |
6072 | 6197 | system "stty cbreak </dev/tty >/dev/tty 2>&1"; |
6073 | 6198 | } |
6074 | 6199 | else { |
6075 | 6200 | system "stty", '-icanon', 'eol', "\001"; |
6076 | 6201 | } |
6077 | 6202 | |
6078 | 6203 | my $key = getc(STDIN); |
6079 | 6204 | |
6080 | 6205 | if ($BSD_STYLE) { |
6081 | 6206 | system "stty -cbreak </dev/tty >/dev/tty 2>&1"; |
6082 | 6207 | } |
6083 | 6208 | else { |
6084 | 6209 | system 'stty', 'icanon', 'eol', '^@'; # ASCII NUL |
6085 | 6210 | } |
6086 | 6211 | print "\n"; |
6087 | 6212 | |
6088 | 6213 | =begin original |
6089 | 6214 | |
6090 | 6215 | Determination of whether C<$BSD_STYLE> should be set is left as an |
6091 | 6216 | exercise to the reader. |
6092 | 6217 | |
6093 | 6218 | =end original |
6094 | 6219 | |
6095 | 6220 | C<$BSD_STYLE> をセットするべきかどうかを決定する方法については |
6096 | 6221 | 読者への宿題として残しておきます。 |
6097 | 6222 | |
6098 | 6223 | =begin original |
6099 | 6224 | |
6100 | 6225 | The L<C<POSIX::getattr>|POSIX/C<getattr>> function can do this more |
6101 | 6226 | portably on systems purporting POSIX compliance. See also the |
6102 | 6227 | L<C<Term::ReadKey>|Term::ReadKey> module on CPAN. |
6103 | 6228 | |
6104 | 6229 | =end original |
6105 | 6230 | |
6106 | 6231 | L<C<POSIX::getattr>|POSIX/C<getattr>> 関数は POSIX 準拠を主張するシステムで |
6107 | 6232 | これをより移植性のある形で行います。 |
6108 | 6233 | CPAN にある L<C<Term::ReadKey>|Term::ReadKey> モジュールも |
6109 | 6234 | 参照してください。 |
6110 | 6235 | |
6111 | 6236 | =item getlogin |
6112 | 6237 | X<getlogin> X<login> |
6113 | 6238 | |
6114 | 6239 | =for Pod::Functions return who logged in at this tty |
6115 | 6240 | |
6116 | 6241 | =begin original |
6117 | 6242 | |
6118 | 6243 | This implements the C library function of the same name, which on most |
6119 | 6244 | systems returns the current login from F</etc/utmp>, if any. If it |
6120 | 6245 | returns the empty string, use L<C<getpwuid>|/getpwuid UID>. |
6121 | 6246 | |
6122 | 6247 | =end original |
6123 | 6248 | |
6124 | 6249 | これは同じ名前の C ライブラリ関数を実装していて、 |
6125 | 6250 | 多くのシステムでは、もしあれば、F</etc/utmp> から現在のログイン名を返します。 |
6126 | 6251 | もし空文字列が返ってきた場合は、L<C<getpwuid>|/getpwuid UID> を |
6127 | 6252 | 使ってください。 |
6128 | 6253 | |
6129 | 6254 | my $login = getlogin || getpwuid($<) || "Kilroy"; |
6130 | 6255 | |
6131 | 6256 | =begin original |
6132 | 6257 | |
6133 | 6258 | Do not consider L<C<getlogin>|/getlogin> for authentication: it is not |
6134 | 6259 | as secure as L<C<getpwuid>|/getpwuid UID>. |
6135 | 6260 | |
6136 | 6261 | =end original |
6137 | 6262 | |
6138 | 6263 | L<C<getlogin>|/getlogin> を認証に使ってはいけません: これは |
6139 | 6264 | L<C<getpwuid>|/getpwuid UID> のように安全ではありません。 |
6140 | 6265 | |
6141 | 6266 | =begin original |
6142 | 6267 | |
6143 | 6268 | Portability issues: L<perlport/getlogin>. |
6144 | 6269 | |
6145 | 6270 | =end original |
6146 | 6271 | |
6147 | 6272 | 移植性の問題: L<perlport/getlogin>。 |
6148 | 6273 | |
6149 | 6274 | =item getpeername SOCKET |
6150 | 6275 | X<getpeername> X<peer> |
6151 | 6276 | |
6152 | 6277 | =for Pod::Functions find the other end of a socket connection |
6153 | 6278 | |
6154 | 6279 | =begin original |
6155 | 6280 | |
6156 | 6281 | Returns the packed sockaddr address of the other end of the SOCKET |
6157 | 6282 | connection. |
6158 | 6283 | |
6159 | 6284 | =end original |
6160 | 6285 | |
6161 | 6286 | SOCKET コネクションの向こう側のパックされた aockaddr アドレスを返します。 |
6162 | 6287 | |
6163 | 6288 | use Socket; |
6164 | 6289 | my $hersockaddr = getpeername($sock); |
6165 | 6290 | my ($port, $iaddr) = sockaddr_in($hersockaddr); |
6166 | 6291 | my $herhostname = gethostbyaddr($iaddr, AF_INET); |
6167 | 6292 | my $herstraddr = inet_ntoa($iaddr); |
6168 | 6293 | |
6169 | 6294 | =item getpgrp PID |
6170 | 6295 | X<getpgrp> X<group> |
6171 | 6296 | |
6172 | 6297 | =for Pod::Functions get process group |
6173 | 6298 | |
6174 | 6299 | =begin original |
6175 | 6300 | |
6176 | 6301 | Returns the current process group for the specified PID. Use |
6177 | 6302 | a PID of C<0> to get the current process group for the |
6178 | 6303 | current process. Will raise an exception if used on a machine that |
6179 | 6304 | doesn't implement L<getpgrp(2)>. If PID is omitted, returns the process |
6180 | 6305 | group of the current process. Note that the POSIX version of |
6181 | 6306 | L<C<getpgrp>|/getpgrp PID> does not accept a PID argument, so only |
6182 | 6307 | C<PID==0> is truly portable. |
6183 | 6308 | |
6184 | 6309 | =end original |
6185 | 6310 | |
6186 | 6311 | 指定された PID の現在のプロセスグループを返します。 |
6187 | 6312 | PID に C<0> を与えるとカレントプロセスの指定となります。 |
6188 | 6313 | L<getpgrp(2)> を実装していないマシンで実行した場合には、例外が発生します。 |
6189 | 6314 | PID を省略するとカレントプロセスのプロセスグループを返します。 |
6190 | 6315 | POSIX 版の L<C<getpgrp>|/getpgrp PID> は PID 引数を受け付けないので、 |
6191 | 6316 | C<PID==0> のみが完全に移植性があります。 |
6192 | 6317 | |
6193 | 6318 | =begin original |
6194 | 6319 | |
6195 | 6320 | Portability issues: L<perlport/getpgrp>. |
6196 | 6321 | |
6197 | 6322 | =end original |
6198 | 6323 | |
6199 | 6324 | 移植性の問題: L<perlport/getpgrp>。 |
6200 | 6325 | |
6201 | 6326 | =item getppid |
6202 | 6327 | X<getppid> X<parent> X<pid> |
6203 | 6328 | |
6204 | 6329 | =for Pod::Functions get parent process ID |
6205 | 6330 | |
6206 | 6331 | =begin original |
6207 | 6332 | |
6208 | 6333 | Returns the process id of the parent process. |
6209 | 6334 | |
6210 | 6335 | =end original |
6211 | 6336 | |
6212 | 6337 | 親プロセスのプロセス id を返します。 |
6213 | 6338 | |
6214 | 6339 | =begin original |
6215 | 6340 | |
6216 | 6341 | Note for Linux users: Between v5.8.1 and v5.16.0 Perl would work |
6217 | 6342 | around non-POSIX thread semantics the minority of Linux systems (and |
6218 | 6343 | Debian GNU/kFreeBSD systems) that used LinuxThreads, this emulation |
6219 | 6344 | has since been removed. See the documentation for L<$$|perlvar/$$> for |
6220 | 6345 | details. |
6221 | 6346 | |
6222 | 6347 | =end original |
6223 | 6348 | |
6224 | 6349 | Linux ユーザーへの注意: v5.8.1 から v5.16.0 の間 Perl は |
6225 | 6350 | LinuxThreads という非 POSIX なスレッド文法を使っているマイナーな |
6226 | 6351 | Linux システム (および Debian GNU/kFreeBSD システム) に対応していました。 |
6227 | 6352 | このエミュレーションは削除されました; |
6228 | 6353 | 詳しくは L<$$|perlvar/$$> の文書を参照してください。 |
6229 | 6354 | |
6230 | 6355 | =begin original |
6231 | 6356 | |
6232 | 6357 | Portability issues: L<perlport/getppid>. |
6233 | 6358 | |
6234 | 6359 | =end original |
6235 | 6360 | |
6236 | 6361 | 移植性の問題: L<perlport/getppid>。 |
6237 | 6362 | |
6238 | 6363 | =item getpriority WHICH,WHO |
6239 | 6364 | X<getpriority> X<priority> X<nice> |
6240 | 6365 | |
6241 | 6366 | =for Pod::Functions get current nice value |
6242 | 6367 | |
6243 | 6368 | =begin original |
6244 | 6369 | |
6245 | 6370 | Returns the current priority for a process, a process group, or a user. |
6246 | 6371 | (See L<getpriority(2)>.) Will raise a fatal exception if used on a |
6247 | 6372 | machine that doesn't implement L<getpriority(2)>. |
6248 | 6373 | |
6249 | 6374 | =end original |
6250 | 6375 | |
6251 | 6376 | プロセス、プロセスグループ、ユーザに対する現在の優先度を返します。 |
6252 | 6377 | (L<getpriority(2)> を参照してください。) |
6253 | 6378 | L<getpriority(2)> を実装していない |
6254 | 6379 | マシンで実行した場合には、致命的例外が発生します。 |
6255 | 6380 | |
6256 | 6381 | =begin original |
6257 | 6382 | |
6383 | C<WHICH> can be any of C<PRIO_PROCESS>, C<PRIO_PGRP> or C<PRIO_USER> | |
6384 | imported from L<POSIX/RESOURCE CONSTANTS>. | |
6385 | ||
6386 | =end original | |
6387 | ||
6388 | C<WHICH> は L<POSIX/RESOURCE CONSTANTS> からインポートされた | |
6389 | C<PRIO_PROCESS>, C<PRIO_PGRP>, C<PRIO_USER> のいずれかです。 | |
6390 | ||
6391 | =begin original | |
6392 | ||
6258 | 6393 | Portability issues: L<perlport/getpriority>. |
6259 | 6394 | |
6260 | 6395 | =end original |
6261 | 6396 | |
6262 | 6397 | 移植性の問題: L<perlport/getpriority>。 |
6263 | 6398 | |
6264 | 6399 | =item getpwnam NAME |
6265 | 6400 | X<getpwnam> X<getgrnam> X<gethostbyname> X<getnetbyname> X<getprotobyname> |
6266 | 6401 | X<getpwuid> X<getgrgid> X<getservbyname> X<gethostbyaddr> X<getnetbyaddr> |
6267 | 6402 | X<getprotobynumber> X<getservbyport> X<getpwent> X<getgrent> X<gethostent> |
6268 | 6403 | X<getnetent> X<getprotoent> X<getservent> X<setpwent> X<setgrent> X<sethostent> |
6269 | 6404 | X<setnetent> X<setprotoent> X<setservent> X<endpwent> X<endgrent> X<endhostent> |
6270 | 6405 | X<endnetent> X<endprotoent> X<endservent> |
6271 | 6406 | |
6272 | 6407 | =for Pod::Functions get passwd record given user login name |
6273 | 6408 | |
6274 | 6409 | =item getgrnam NAME |
6275 | 6410 | |
6276 | 6411 | =for Pod::Functions get group record given group name |
6277 | 6412 | |
6278 | 6413 | =item gethostbyname NAME |
6279 | 6414 | |
6280 | 6415 | =for Pod::Functions get host record given name |
6281 | 6416 | |
6282 | 6417 | =item getnetbyname NAME |
6283 | 6418 | |
6284 | 6419 | =for Pod::Functions get networks record given name |
6285 | 6420 | |
6286 | 6421 | =item getprotobyname NAME |
6287 | 6422 | |
6288 | 6423 | =for Pod::Functions get protocol record given name |
6289 | 6424 | |
6290 | 6425 | =item getpwuid UID |
6291 | 6426 | |
6292 | 6427 | =for Pod::Functions get passwd record given user ID |
6293 | 6428 | |
6294 | 6429 | =item getgrgid GID |
6295 | 6430 | |
6296 | 6431 | =for Pod::Functions get group record given group user ID |
6297 | 6432 | |
6298 | 6433 | =item getservbyname NAME,PROTO |
6299 | 6434 | |
6300 | 6435 | =for Pod::Functions get services record given its name |
6301 | 6436 | |
6302 | 6437 | =item gethostbyaddr ADDR,ADDRTYPE |
6303 | 6438 | |
6304 | 6439 | =for Pod::Functions get host record given its address |
6305 | 6440 | |
6306 | 6441 | =item getnetbyaddr ADDR,ADDRTYPE |
6307 | 6442 | |
6308 | 6443 | =for Pod::Functions get network record given its address |
6309 | 6444 | |
6310 | 6445 | =item getprotobynumber NUMBER |
6311 | 6446 | |
6312 | 6447 | =for Pod::Functions get protocol record numeric protocol |
6313 | 6448 | |
6314 | 6449 | =item getservbyport PORT,PROTO |
6315 | 6450 | |
6316 | 6451 | =for Pod::Functions get services record given numeric port |
6317 | 6452 | |
6318 | 6453 | =item getpwent |
6319 | 6454 | |
6320 | 6455 | =for Pod::Functions get next passwd record |
6321 | 6456 | |
6322 | 6457 | =item getgrent |
6323 | 6458 | |
6324 | 6459 | =for Pod::Functions get next group record |
6325 | 6460 | |
6326 | 6461 | =item gethostent |
6327 | 6462 | |
6328 | 6463 | =for Pod::Functions get next hosts record |
6329 | 6464 | |
6330 | 6465 | =item getnetent |
6331 | 6466 | |
6332 | 6467 | =for Pod::Functions get next networks record |
6333 | 6468 | |
6334 | 6469 | =item getprotoent |
6335 | 6470 | |
6336 | 6471 | =for Pod::Functions get next protocols record |
6337 | 6472 | |
6338 | 6473 | =item getservent |
6339 | 6474 | |
6340 | 6475 | =for Pod::Functions get next services record |
6341 | 6476 | |
6342 | 6477 | =item setpwent |
6343 | 6478 | |
6344 | 6479 | =for Pod::Functions prepare passwd file for use |
6345 | 6480 | |
6346 | 6481 | =item setgrent |
6347 | 6482 | |
6348 | 6483 | =for Pod::Functions prepare group file for use |
6349 | 6484 | |
6350 | 6485 | =item sethostent STAYOPEN |
6351 | 6486 | |
6352 | 6487 | =for Pod::Functions prepare hosts file for use |
6353 | 6488 | |
6354 | 6489 | =item setnetent STAYOPEN |
6355 | 6490 | |
6356 | 6491 | =for Pod::Functions prepare networks file for use |
6357 | 6492 | |
6358 | 6493 | =item setprotoent STAYOPEN |
6359 | 6494 | |
6360 | 6495 | =for Pod::Functions prepare protocols file for use |
6361 | 6496 | |
6362 | 6497 | =item setservent STAYOPEN |
6363 | 6498 | |
6364 | 6499 | =for Pod::Functions prepare services file for use |
6365 | 6500 | |
6366 | 6501 | =item endpwent |
6367 | 6502 | |
6368 | 6503 | =for Pod::Functions be done using passwd file |
6369 | 6504 | |
6370 | 6505 | =item endgrent |
6371 | 6506 | |
6372 | 6507 | =for Pod::Functions be done using group file |
6373 | 6508 | |
6374 | 6509 | =item endhostent |
6375 | 6510 | |
6376 | 6511 | =for Pod::Functions be done using hosts file |
6377 | 6512 | |
6378 | 6513 | =item endnetent |
6379 | 6514 | |
6380 | 6515 | =for Pod::Functions be done using networks file |
6381 | 6516 | |
6382 | 6517 | =item endprotoent |
6383 | 6518 | |
6384 | 6519 | =for Pod::Functions be done using protocols file |
6385 | 6520 | |
6386 | 6521 | =item endservent |
6387 | 6522 | |
6388 | 6523 | =for Pod::Functions be done using services file |
6389 | 6524 | |
6390 | 6525 | =begin original |
6391 | 6526 | |
6392 | 6527 | These routines are the same as their counterparts in the |
6393 | 6528 | system C library. In list context, the return values from the |
6394 | 6529 | various get routines are as follows: |
6395 | 6530 | |
6396 | 6531 | =end original |
6397 | 6532 | |
6398 | 6533 | これらのルーチンは、システムの C ライブラリの同名の関数と同じです。 |
6399 | 6534 | リストコンテキストでは、さまざまな |
6400 | 6535 | get ルーチンからの返り値は、次のようになります: |
6401 | 6536 | |
6402 | 6537 | # 0 1 2 3 4 |
6403 | 6538 | my ( $name, $passwd, $gid, $members ) = getgr* |
6404 | 6539 | my ( $name, $aliases, $addrtype, $net ) = getnet* |
6405 | 6540 | my ( $name, $aliases, $port, $proto ) = getserv* |
6406 | 6541 | my ( $name, $aliases, $proto ) = getproto* |
6407 | 6542 | my ( $name, $aliases, $addrtype, $length, @addrs ) = gethost* |
6408 | 6543 | my ( $name, $passwd, $uid, $gid, $quota, |
6409 | 6544 | $comment, $gcos, $dir, $shell, $expire ) = getpw* |
6410 | 6545 | # 5 6 7 8 9 |
6411 | 6546 | |
6412 | 6547 | =begin original |
6413 | 6548 | |
6414 | 6549 | (If the entry doesn't exist, the return value is a single meaningless true |
6415 | 6550 | value.) |
6416 | 6551 | |
6417 | 6552 | =end original |
6418 | 6553 | |
6419 | 6554 | (エントリが存在しなければ、返り値は単一の意味のない真の値です。) |
6420 | 6555 | |
6421 | 6556 | =begin original |
6422 | 6557 | |
6423 | 6558 | The exact meaning of the $gcos field varies but it usually contains |
6424 | 6559 | the real name of the user (as opposed to the login name) and other |
6425 | 6560 | information pertaining to the user. Beware, however, that in many |
6426 | 6561 | system users are able to change this information and therefore it |
6427 | 6562 | cannot be trusted and therefore the $gcos is tainted (see |
6428 | 6563 | L<perlsec>). The $passwd and $shell, user's encrypted password and |
6429 | 6564 | login shell, are also tainted, for the same reason. |
6430 | 6565 | |
6431 | 6566 | =end original |
6432 | 6567 | |
6433 | 6568 | $gcos フィールドの正確な意味はさまざまですが、通常は(ログイン名ではなく) |
6434 | 6569 | ユーザーの実際の名前とユーザーに付随する情報を含みます。 |
6435 | 6570 | 但し、多くのシステムではユーザーがこの情報を変更できるので、この情報は |
6436 | 6571 | 信頼できず、従って $gcos は汚染されます(L<perlsec> を参照してください)。 |
6437 | 6572 | ユーザーの暗号化されたパスワードとログインシェルである $passwd と |
6438 | 6573 | $shell も、同様の理由で汚染されます。 |
6439 | 6574 | |
6440 | 6575 | =begin original |
6441 | 6576 | |
6442 | 6577 | In scalar context, you get the name, unless the function was a |
6443 | 6578 | lookup by name, in which case you get the other thing, whatever it is. |
6444 | 6579 | (If the entry doesn't exist you get the undefined value.) For example: |
6445 | 6580 | |
6446 | 6581 | =end original |
6447 | 6582 | |
6448 | 6583 | スカラコンテキストでは、*nam、*byname といった NAME で検索するもの以外は、 |
6449 | 6584 | name を返し、NAME で検索するものは、何か別のものを返します。 |
6450 | 6585 | (エントリが存在しなければ、未定義値が返ります。) |
6451 | 6586 | 例えば: |
6452 | 6587 | |
6453 | 6588 | my $uid = getpwnam($name); |
6454 | 6589 | my $name = getpwuid($num); |
6455 | 6590 | my $name = getpwent(); |
6456 | 6591 | my $gid = getgrnam($name); |
6457 | 6592 | my $name = getgrgid($num); |
6458 | 6593 | my $name = getgrent(); |
6459 | 6594 | # etc. |
6460 | 6595 | |
6461 | 6596 | =begin original |
6462 | 6597 | |
6463 | 6598 | In I<getpw*()> the fields $quota, $comment, and $expire are special |
6464 | 6599 | in that they are unsupported on many systems. If the |
6465 | 6600 | $quota is unsupported, it is an empty scalar. If it is supported, it |
6466 | 6601 | usually encodes the disk quota. If the $comment field is unsupported, |
6467 | 6602 | it is an empty scalar. If it is supported it usually encodes some |
6468 | 6603 | administrative comment about the user. In some systems the $quota |
6469 | 6604 | field may be $change or $age, fields that have to do with password |
6470 | 6605 | aging. In some systems the $comment field may be $class. The $expire |
6471 | 6606 | field, if present, encodes the expiration period of the account or the |
6472 | 6607 | password. For the availability and the exact meaning of these fields |
6473 | 6608 | in your system, please consult L<getpwnam(3)> and your system's |
6474 | 6609 | F<pwd.h> file. You can also find out from within Perl what your |
6475 | 6610 | $quota and $comment fields mean and whether you have the $expire field |
6476 | 6611 | by using the L<C<Config>|Config> module and the values C<d_pwquota>, C<d_pwage>, |
6477 | 6612 | C<d_pwchange>, C<d_pwcomment>, and C<d_pwexpire>. Shadow password |
6478 | 6613 | files are supported only if your vendor has implemented them in the |
6479 | 6614 | intuitive fashion that calling the regular C library routines gets the |
6480 | 6615 | shadow versions if you're running under privilege or if there exists |
6481 | 6616 | the L<shadow(3)> functions as found in System V (this includes Solaris |
6482 | 6617 | and Linux). Those systems that implement a proprietary shadow password |
6483 | 6618 | facility are unlikely to be supported. |
6484 | 6619 | |
6485 | 6620 | =end original |
6486 | 6621 | |
6487 | 6622 | I<getpw*()> では、$quota, $comment, $expire フィールドは、 |
6488 | 6623 | 多くのシステムでは対応していないので特別な処理がされます。 |
6489 | 6624 | $quota が非対応の場合、空のスカラになります。 |
6490 | 6625 | 対応している場合、通常はディスククォータの値が入ります。 |
6491 | 6626 | $comment フィールドが非対応の場合、空のスカラになります。 |
6492 | 6627 | 対応している場合、通常はユーザーに関する管理上のコメントが入ります。 |
6493 | 6628 | $quota フィールドはパスワードの寿命を示す $change や $age である |
6494 | 6629 | システムもあります。 |
6495 | 6630 | $comment フィールドは $class であるシステムもあります。 |
6496 | 6631 | $expire フィールドがある場合は、アカウントやパスワードが時間切れになる |
6497 | 6632 | 期間が入ります。 |
6498 | 6633 | 動作させるシステムでのこれらのフィールドの有効性と正確な意味については、 |
6499 | 6634 | L<getpwnam(3)> のドキュメントと F<pwd.h> ファイルを参照してください。 |
6500 | 6635 | $quota と $comment フィールドが何を意味しているかと、$expire フィールドが |
6501 | 6636 | あるかどうかは、L<C<Config>|Config> モジュールを使って、C<d_pwquota>, |
6502 | 6637 | C<d_pwage>, C<d_pwchange>, C<d_pwcomment>, C<d_pwexpire> の値を |
6503 | 6638 | 調べることによって Perl 自身で調べることも出来ます。 |
6504 | 6639 | シャドウパスワードは、通常の C ライブラリルーチンを権限がある状態で |
6505 | 6640 | 呼び出すことでシャドウ版が取得できるか、System V にあるような |
6506 | 6641 | (Solaris と Linux を含みます) L<shadow(3)> 関数があるといった、 |
6507 | 6642 | 直感的な方法で実装されている場合にのみ対応されます。 |
6508 | 6643 | 独占的なシャドウパスワード機能を実装しているシステムでは、 |
6509 | 6644 | それに対応されることはないでしょう。 |
6510 | 6645 | |
6511 | 6646 | =begin original |
6512 | 6647 | |
6513 | 6648 | The $members value returned by I<getgr*()> is a space-separated list of |
6514 | 6649 | the login names of the members of the group. |
6515 | 6650 | |
6516 | 6651 | =end original |
6517 | 6652 | |
6518 | 6653 | I<getgr*()> によって返る値 $members は、グループのメンバの |
6519 | 6654 | ログイン名をスペースで区切ったものです。 |
6520 | 6655 | |
6521 | 6656 | =begin original |
6522 | 6657 | |
6523 | 6658 | For the I<gethost*()> functions, if the C<h_errno> variable is supported in |
6524 | 6659 | C, it will be returned to you via L<C<$?>|perlvar/$?> if the function |
6525 | 6660 | call fails. The |
6526 | 6661 | C<@addrs> value returned by a successful call is a list of raw |
6527 | 6662 | addresses returned by the corresponding library call. In the |
6528 | 6663 | Internet domain, each address is four bytes long; you can unpack it |
6529 | 6664 | by saying something like: |
6530 | 6665 | |
6531 | 6666 | =end original |
6532 | 6667 | |
6533 | 6668 | I<gethost*()> 関数では、C で C<h_errno> 変数がサポートされていれば、 |
6534 | 6669 | 関数呼出が失敗したときに、L<C<$?>|perlvar/$?> を通して、その値が返されます。 |
6535 | 6670 | 成功時に返される C<@addrs> 値は、対応するシステムコールが返す、 |
6536 | 6671 | 生のアドレスのリストです。 |
6537 | 6672 | インターネットドメインでは、個々のアドレスは、4 バイト長です; |
6538 | 6673 | 以下のようにして unpack することができます: |
6539 | 6674 | |
6540 | 6675 | my ($w,$x,$y,$z) = unpack('W4',$addr[0]); |
6541 | 6676 | |
6542 | 6677 | =begin original |
6543 | 6678 | |
6544 | 6679 | The Socket library makes this slightly easier: |
6545 | 6680 | |
6546 | 6681 | =end original |
6547 | 6682 | |
6548 | 6683 | Socket ライブラリを使うともう少し簡単になります。 |
6549 | 6684 | |
6550 | 6685 | use Socket; |
6551 | 6686 | my $iaddr = inet_aton("127.1"); # or whatever address |
6552 | 6687 | my $name = gethostbyaddr($iaddr, AF_INET); |
6553 | 6688 | |
6554 | 6689 | # or going the other way |
6555 | 6690 | my $straddr = inet_ntoa($iaddr); |
6556 | 6691 | |
6557 | 6692 | =begin original |
6558 | 6693 | |
6559 | 6694 | In the opposite way, to resolve a hostname to the IP address |
6560 | 6695 | you can write this: |
6561 | 6696 | |
6562 | 6697 | =end original |
6563 | 6698 | |
6564 | 6699 | 逆方向に、ホスト名から IP アドレスを解決するには以下のように書けます: |
6565 | 6700 | |
6566 | 6701 | use Socket; |
6567 | 6702 | my $packed_ip = gethostbyname("www.perl.org"); |
6568 | 6703 | my $ip_address; |
6569 | 6704 | if (defined $packed_ip) { |
6570 | 6705 | $ip_address = inet_ntoa($packed_ip); |
6571 | 6706 | } |
6572 | 6707 | |
6573 | 6708 | =begin original |
6574 | 6709 | |
6575 | 6710 | Make sure L<C<gethostbyname>|/gethostbyname NAME> is called in SCALAR |
6576 | 6711 | context and that its return value is checked for definedness. |
6577 | 6712 | |
6578 | 6713 | =end original |
6579 | 6714 | |
6580 | 6715 | L<C<gethostbyname>|/gethostbyname NAME> はスカラコンテキストで |
6581 | 6716 | 呼び出すようにして、返り値が定義されているかを必ずチェックしてください。 |
6582 | 6717 | |
6583 | 6718 | =begin original |
6584 | 6719 | |
6585 | 6720 | The L<C<getprotobynumber>|/getprotobynumber NUMBER> function, even |
6586 | 6721 | though it only takes one argument, has the precedence of a list |
6587 | 6722 | operator, so beware: |
6588 | 6723 | |
6589 | 6724 | =end original |
6590 | 6725 | |
6591 | 6726 | L<C<getprotobynumber>|/getprotobynumber NUMBER> 関数は、一つの引数しか |
6592 | 6727 | 取らないにも関わらず、リスト演算子の優先順位を持ちます; 従って |
6593 | 6728 | 注意してください: |
6594 | 6729 | |
6595 | 6730 | getprotobynumber $number eq 'icmp' # WRONG |
6596 | 6731 | getprotobynumber($number eq 'icmp') # actually means this |
6597 | 6732 | getprotobynumber($number) eq 'icmp' # better this way |
6598 | 6733 | |
6599 | 6734 | =begin original |
6600 | 6735 | |
6601 | 6736 | If you get tired of remembering which element of the return list |
6602 | 6737 | contains which return value, by-name interfaces are provided in standard |
6603 | 6738 | modules: L<C<File::stat>|File::stat>, L<C<Net::hostent>|Net::hostent>, |
6604 | 6739 | L<C<Net::netent>|Net::netent>, L<C<Net::protoent>|Net::protoent>, |
6605 | 6740 | L<C<Net::servent>|Net::servent>, L<C<Time::gmtime>|Time::gmtime>, |
6606 | 6741 | L<C<Time::localtime>|Time::localtime>, and |
6607 | 6742 | L<C<User::grent>|User::grent>. These override the normal built-ins, |
6608 | 6743 | supplying versions that return objects with the appropriate names for |
6609 | 6744 | each field. For example: |
6610 | 6745 | |
6611 | 6746 | =end original |
6612 | 6747 | |
6613 | 6748 | 返り値のリストの何番目がどの要素かを覚えるのに疲れたなら、 |
6614 | 6749 | 名前ベースのインターフェースが標準モジュールで提供されています: |
6615 | 6750 | L<C<File::stat>|File::stat>, L<C<Net::hostent>|Net::hostent>, |
6616 | 6751 | L<C<Net::netent>|Net::netent>, L<C<Net::protoent>|Net::protoent>, |
6617 | 6752 | L<C<Net::servent>|Net::servent>, L<C<Time::gmtime>|Time::gmtime>, |
6618 | 6753 | L<C<Time::localtime>|Time::localtime>, |
6619 | 6754 | L<C<User::grent>|User::grent> です。 |
6620 | 6755 | これらは通常の組み込みを上書きし、 |
6621 | 6756 | それぞれのフィールドに適切な名前をつけたオブジェクトを返します。 |
6622 | 6757 | 例えば: |
6623 | 6758 | |
6624 | 6759 | use File::stat; |
6625 | 6760 | use User::pwent; |
6626 | 6761 | my $is_his = (stat($filename)->uid == pwent($whoever)->uid); |
6627 | 6762 | |
6628 | 6763 | =begin original |
6629 | 6764 | |
6630 | 6765 | Even though it looks as though they're the same method calls (uid), |
6631 | 6766 | they aren't, because a C<File::stat> object is different from |
6632 | 6767 | a C<User::pwent> object. |
6633 | 6768 | |
6634 | 6769 | =end original |
6635 | 6770 | |
6636 | 6771 | 同じメソッド(uid)を呼び出しているように見えますが、違います; |
6637 | 6772 | なぜなら C<File::stat> オブジェクトは C<User::pwent> オブジェクトとは |
6638 | 6773 | 異なるからです。 |
6639 | 6774 | |
6640 | 6775 | =begin original |
6641 | 6776 | |
6777 | Many of these functions are not safe in a multi-threaded environment | |
6778 | where more than one thread can be using them. In particular, functions | |
6779 | like C<getpwent()> iterate per-process and not per-thread, so if two | |
6780 | threads are simultaneously iterating, neither will get all the records. | |
6781 | ||
6782 | =end original | |
6783 | ||
6784 | これらの関数の多くは、複数のスレッドがこれらを使うような | |
6785 | マルチスレッド環境では安全ではありません。 | |
6786 | 特に、 | |
6787 | C<getpwent()> のような関数はスレッド単位ではなくプロセス単位で | |
6788 | 反復するので、二つのスレッドが同時に反復すると、 | |
6789 | どちらも全てのレコードを得られません。 | |
6790 | ||
6791 | =begin original | |
6792 | ||
6793 | Some systems have thread-safe versions of some of the functions, such as | |
6794 | C<getpwnam_r()> instead of C<getpwnam()>. There, Perl automatically and | |
6795 | invisibly substitutes the thread-safe version, without notice. This | |
6796 | means that code that safely runs on some systems can fail on others that | |
6797 | lack the thread-safe versions. | |
6798 | ||
6799 | =end original | |
6800 | ||
6801 | 一部のシステムは、 | |
6802 | C<getpwnam()> の代わりの C<getpwnam_r()> のように、一部の関数について | |
6803 | スレッドセーフ版を持っています。 | |
6804 | その場合、Perl は自動的かつ目に見えないように、通知なしで | |
6805 | スレッドセーフ版に置き換えます。 | |
6806 | つまり、一部のシステムで安全に実行できるコードが | |
6807 | スレッドセーフ版のないその他のシステムでは失敗することがあるということです。 | |
6808 | ||
6809 | =begin original | |
6810 | ||
6642 | 6811 | Portability issues: L<perlport/getpwnam> to L<perlport/endservent>. |
6643 | 6812 | |
6644 | 6813 | =end original |
6645 | 6814 | |
6646 | 6815 | 移植性の問題: L<perlport/getpwnam> から L<perlport/endservent>。 |
6647 | 6816 | |
6648 | 6817 | =item getsockname SOCKET |
6649 | 6818 | X<getsockname> |
6650 | 6819 | |
6651 | 6820 | =for Pod::Functions retrieve the sockaddr for a given socket |
6652 | 6821 | |
6653 | 6822 | =begin original |
6654 | 6823 | |
6655 | 6824 | Returns the packed sockaddr address of this end of the SOCKET connection, |
6656 | 6825 | in case you don't know the address because you have several different |
6657 | 6826 | IPs that the connection might have come in on. |
6658 | 6827 | |
6659 | 6828 | =end original |
6660 | 6829 | |
6661 | 6830 | SOCKET 接続のこちら側の pack された sockaddr アドレスを返します; |
6662 | 6831 | 複数の異なる IP から接続されるためにアドレスがわからない場合に使います。 |
6663 | 6832 | |
6664 | 6833 | use Socket; |
6665 | 6834 | my $mysockaddr = getsockname($sock); |
6666 | 6835 | my ($port, $myaddr) = sockaddr_in($mysockaddr); |
6667 | 6836 | printf "Connect to %s [%s]\n", |
6668 | 6837 | scalar gethostbyaddr($myaddr, AF_INET), |
6669 | 6838 | inet_ntoa($myaddr); |
6670 | 6839 | |
6671 | 6840 | =item getsockopt SOCKET,LEVEL,OPTNAME |
6672 | 6841 | X<getsockopt> |
6673 | 6842 | |
6674 | 6843 | =for Pod::Functions get socket options on a given socket |
6675 | 6844 | |
6676 | 6845 | =begin original |
6677 | 6846 | |
6678 | 6847 | Queries the option named OPTNAME associated with SOCKET at a given LEVEL. |
6679 | 6848 | Options may exist at multiple protocol levels depending on the socket |
6680 | 6849 | type, but at least the uppermost socket level SOL_SOCKET (defined in the |
6681 | 6850 | L<C<Socket>|Socket> module) will exist. To query options at another |
6682 | 6851 | level the protocol number of the appropriate protocol controlling the |
6683 | 6852 | option should be supplied. For example, to indicate that an option is |
6684 | 6853 | to be interpreted by the TCP protocol, LEVEL should be set to the |
6685 | 6854 | protocol number of TCP, which you can get using |
6686 | 6855 | L<C<getprotobyname>|/getprotobyname NAME>. |
6687 | 6856 | |
6688 | 6857 | =end original |
6689 | 6858 | |
6690 | 6859 | 与えられた LEVEL で SOCKET に関連付けられた OPTNAME と言う名前のオプションを |
6691 | 6860 | 問い合わせます。 |
6692 | 6861 | オプションはソケットの種類に依存しした複数のプロトコルレベルに存在することも |
6693 | 6862 | ありますが、少なくとも最上位ソケットレベル SOL_SOCKET |
6694 | 6863 | (L<C<Socket>|Socket> モジュールで定義されています)は存在します。 |
6695 | 6864 | その他のレベルのオプションを問い合わせるには、そのオプションを制御する |
6696 | 6865 | 適切なプロトコルのプロトコル番号を指定します。 |
6697 | 6866 | 例えば、オプションが TCP プロトコルで解釈されるべきであることを示すためには、 |
6698 | 6867 | LEVEL は L<C<getprotobyname>|/getprotobyname NAME> で得られる TCP の |
6699 | 6868 | プロトコル番号を設定します。 |
6700 | 6869 | |
6701 | 6870 | =begin original |
6702 | 6871 | |
6703 | 6872 | The function returns a packed string representing the requested socket |
6704 | 6873 | option, or L<C<undef>|/undef EXPR> on error, with the reason for the |
6705 | 6874 | error placed in L<C<$!>|perlvar/$!>. Just what is in the packed string |
6706 | 6875 | depends on LEVEL and OPTNAME; consult L<getsockopt(2)> for details. A |
6707 | 6876 | common case is that the option is an integer, in which case the result |
6708 | 6877 | is a packed integer, which you can decode using |
6709 | 6878 | L<C<unpack>|/unpack TEMPLATE,EXPR> with the C<i> (or C<I>) format. |
6710 | 6879 | |
6711 | 6880 | =end original |
6712 | 6881 | |
6713 | 6882 | この関数は、要求されたソケットオプションの pack された文字列表現か、 |
6714 | 6883 | あるいはエラーの場合は L<C<undef>|/undef EXPR> を返し、エラーの理由は |
6715 | 6884 | L<C<$!>|perlvar/$!> にあります。 |
6716 | 6885 | pack された文字列の中身は LEVEL と OPTNAME に依存します; |
6717 | 6886 | 詳細については L<getsockopt(2)> を確認してください。 |
6718 | 6887 | 一般的な場合はオプションが整数の場合で、この場合結果は |
6719 | 6888 | L<C<unpack>|/unpack TEMPLATE,EXPR> の C<i> |
6720 | 6889 | (あるいは C<I>)フォーマットでデコードできる pack された整数です。 |
6721 | 6890 | |
6722 | 6891 | =begin original |
6723 | 6892 | |
6724 | 6893 | Here's an example to test whether Nagle's algorithm is enabled on a socket: |
6725 | 6894 | |
6726 | 6895 | =end original |
6727 | 6896 | |
6728 | 6897 | あるソケットで Nagle のアルゴリズム有効かどうかを調べる例です: |
6729 | 6898 | |
6730 | 6899 | use Socket qw(:all); |
6731 | 6900 | |
6732 | 6901 | defined(my $tcp = getprotobyname("tcp")) |
6733 | 6902 | or die "Could not determine the protocol number for tcp"; |
6734 | 6903 | # my $tcp = IPPROTO_TCP; # Alternative |
6735 | 6904 | my $packed = getsockopt($socket, $tcp, TCP_NODELAY) |
6736 | 6905 | or die "getsockopt TCP_NODELAY: $!"; |
6737 | 6906 | my $nodelay = unpack("I", $packed); |
6738 | 6907 | print "Nagle's algorithm is turned ", |
6739 | 6908 | $nodelay ? "off\n" : "on\n"; |
6740 | 6909 | |
6741 | 6910 | =begin original |
6742 | 6911 | |
6743 | 6912 | Portability issues: L<perlport/getsockopt>. |
6744 | 6913 | |
6745 | 6914 | =end original |
6746 | 6915 | |
6747 | 6916 | 移植性の問題: L<perlport/getsockopt>。 |
6748 | 6917 | |
6749 | 6918 | =item glob EXPR |
6750 | 6919 | X<glob> X<wildcard> X<filename, expansion> X<expand> |
6751 | 6920 | |
6752 | 6921 | =item glob |
6753 | 6922 | |
6754 | 6923 | =for Pod::Functions expand filenames using wildcards |
6755 | 6924 | |
6756 | 6925 | =begin original |
6757 | 6926 | |
6758 | 6927 | In list context, returns a (possibly empty) list of filename expansions on |
6759 | 6928 | the value of EXPR such as the standard Unix shell F</bin/csh> would do. In |
6760 | 6929 | scalar context, glob iterates through such filename expansions, returning |
6761 | 6930 | undef when the list is exhausted. This is the internal function |
6762 | 6931 | implementing the C<< <*.c> >> operator, but you can use it directly. If |
6763 | 6932 | EXPR is omitted, L<C<$_>|perlvar/$_> is used. The C<< <*.c> >> operator |
6764 | 6933 | is discussed in more detail in L<perlop/"I/O Operators">. |
6765 | 6934 | |
6766 | 6935 | =end original |
6767 | 6936 | |
6768 | 6937 | リストコンテキストでは、 |
6769 | 6938 | EXPR の値を、標準 Unix シェル F</bin/csh> が行なうように |
6770 | 6939 | ファイル名の展開を行なった結果のリスト(空かもしれません)を返します。 |
6771 | 6940 | スカラコンテキストでは、glob はこのようなファイル名展開を繰り返し、 |
6772 | 6941 | リストがなくなったら undef を返します。 |
6773 | 6942 | これは、C<< <*.c> >> 演算子を実装する内部関数ですが、 |
6774 | 6943 | 直接使用することもできます。 |
6775 | 6944 | EXPR が省略されると、L<C<$_>|perlvar/$_> が使われます。 |
6776 | 6945 | C<< <*.c> >>演算子については |
6777 | 6946 | L<perlop/"I/O Operators"> でより詳細に議論しています。 |
6778 | 6947 | |
6779 | 6948 | =begin original |
6780 | 6949 | |
6781 | 6950 | Note that L<C<glob>|/glob EXPR> splits its arguments on whitespace and |
6782 | 6951 | treats |
6783 | 6952 | each segment as separate pattern. As such, C<glob("*.c *.h")> |
6784 | 6953 | matches all files with a F<.c> or F<.h> extension. The expression |
6785 | 6954 | C<glob(".* *")> matches all files in the current working directory. |
6786 | 6955 | If you want to glob filenames that might contain whitespace, you'll |
6787 | 6956 | have to use extra quotes around the spacey filename to protect it. |
6788 | 6957 | For example, to glob filenames that have an C<e> followed by a space |
6789 | 6958 | followed by an C<f>, use one of: |
6790 | 6959 | |
6791 | 6960 | =end original |
6792 | 6961 | |
6793 | 6962 | L<C<glob>|/glob EXPR> は引数を空白で分割して、それぞれを分割された |
6794 | 6963 | パターンとして扱います。 |
6795 | 6964 | 従って、C<glob("*.c *.h")> は F<.c> または F<.h> 拡張子を持つ全てのファイルに |
6796 | 6965 | マッチングします。 |
6797 | 6966 | 式 C<glob(".* *")> はカレントワーキングディレクトリの全てのファイルに |
6798 | 6967 | マッチングします。 |
6799 | 6968 | 空白を含んでいるかも知れないファイル名をグロブしたい場合、それを守るために |
6800 | 6969 | 空白入りファイル名の周りに追加のクォートを使う必要があります。 |
6801 | 6970 | 例えば、C<e> の後に空白、その後に C<f> というファイル名をグロブするには |
6802 | 6971 | 以下の一つを使います: |
6803 | 6972 | |
6804 | 6973 | my @spacies = <"*e f*">; |
6805 | 6974 | my @spacies = glob '"*e f*"'; |
6806 | 6975 | my @spacies = glob q("*e f*"); |
6807 | 6976 | |
6808 | 6977 | =begin original |
6809 | 6978 | |
6810 | 6979 | If you had to get a variable through, you could do this: |
6811 | 6980 | |
6812 | 6981 | =end original |
6813 | 6982 | |
6814 | 6983 | 変数を通す必要があった場合、以下のようにできました: |
6815 | 6984 | |
6816 | 6985 | my @spacies = glob "'*${var}e f*'"; |
6817 | 6986 | my @spacies = glob qq("*${var}e f*"); |
6818 | 6987 | |
6819 | 6988 | =begin original |
6820 | 6989 | |
6821 | 6990 | If non-empty braces are the only wildcard characters used in the |
6822 | 6991 | L<C<glob>|/glob EXPR>, no filenames are matched, but potentially many |
6823 | 6992 | strings are returned. For example, this produces nine strings, one for |
6824 | 6993 | each pairing of fruits and colors: |
6825 | 6994 | |
6826 | 6995 | =end original |
6827 | 6996 | |
6828 | 6997 | 空でない中かっこが L<C<glob>|/glob EXPR> で使われている唯一の |
6829 | 6998 | ワイルドカード文字列の場合、ファイル名とはマッチングせず、 |
6830 | 6999 | 可能性のある文字列が返されます。 |
6831 | 7000 | 例えば、これは 9 個の文字列を生成し、それぞれは果物と色の組み合わせに |
6832 | 7001 | なります: |
6833 | 7002 | |
6834 | 7003 | my @many = glob "{apple,tomato,cherry}={green,yellow,red}"; |
6835 | 7004 | |
6836 | 7005 | =begin original |
6837 | 7006 | |
6838 | 7007 | This operator is implemented using the standard C<File::Glob> extension. |
6839 | 7008 | See L<File::Glob> for details, including |
6840 | 7009 | L<C<bsd_glob>|File::Glob/C<bsd_glob>>, which does not treat whitespace |
6841 | 7010 | as a pattern separator. |
6842 | 7011 | |
6843 | 7012 | =end original |
6844 | 7013 | |
6845 | 7014 | v5.6.0 から、この演算子は標準の C<File::Glob> 拡張を使って |
6846 | 7015 | 実装されています。 |
6847 | 7016 | 空白をパターンのセパレータとして扱わない |
6848 | 7017 | L<C<bsd_glob>|File::Glob/C<bsd_glob>> を含めた |
6849 | 7018 | 詳細は L<File::Glob> を参照してください。 |
6850 | 7019 | |
6851 | 7020 | =begin original |
6852 | 7021 | |
7022 | If a C<glob> expression is used as the condition of a C<while> or C<for> | |
7023 | loop, then it will be implicitly assigned to C<$_>. If either a C<glob> | |
7024 | expression or an explicit assignment of a C<glob> expression to a scalar | |
7025 | is used as a C<while>/C<for> condition, then the condition actually | |
7026 | tests for definedness of the expression's value, not for its regular | |
7027 | truth value. | |
7028 | ||
7029 | =end original | |
7030 | ||
7031 | C<glob> 式が C<while> や C<for> ループの条件として使われた場合、 | |
7032 | これは暗黙に C<$_> に代入されます。 | |
7033 | C<glob> 式または C<glob> 式からスカラへの明示的な代入が | |
7034 | C<while>/C<for> の条件部として使われた場合、 | |
7035 | 条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを | |
7036 | テストします。 | |
7037 | ||
7038 | =begin original | |
7039 | ||
6853 | 7040 | Portability issues: L<perlport/glob>. |
6854 | 7041 | |
6855 | 7042 | =end original |
6856 | 7043 | |
6857 | 7044 | 移植性の問題: L<perlport/glob>。 |
6858 | 7045 | |
6859 | 7046 | =item gmtime EXPR |
6860 | 7047 | X<gmtime> X<UTC> X<Greenwich> |
6861 | 7048 | |
6862 | 7049 | =item gmtime |
6863 | 7050 | |
6864 | 7051 | =for Pod::Functions convert UNIX time into record or string using Greenwich time |
6865 | 7052 | |
6866 | 7053 | =begin original |
6867 | 7054 | |
6868 | 7055 | Works just like L<C<localtime>|/localtime EXPR> but the returned values |
6869 | 7056 | are localized for the standard Greenwich time zone. |
6870 | 7057 | |
6871 | 7058 | =end original |
6872 | 7059 | |
6873 | 7060 | L<C<localtime>|/localtime EXPR> と同様に働きますが、返り値はグリニッジ標準時に |
6874 | 7061 | ローカライズされています。 |
6875 | 7062 | |
6876 | 7063 | =begin original |
6877 | 7064 | |
6878 | 7065 | Note: When called in list context, $isdst, the last value |
6879 | 7066 | returned by gmtime, is always C<0>. There is no |
6880 | 7067 | Daylight Saving Time in GMT. |
6881 | 7068 | |
6882 | 7069 | =end original |
6883 | 7070 | |
6884 | 7071 | 注意: リストコンテキストで呼び出した時、gmtime が返す末尾の値である |
6885 | 7072 | $isdst は常に C<0> です。 |
6886 | 7073 | GMT には夏時間はありません。 |
6887 | 7074 | |
6888 | 7075 | =begin original |
6889 | 7076 | |
6890 | 7077 | Portability issues: L<perlport/gmtime>. |
6891 | 7078 | |
6892 | 7079 | =end original |
6893 | 7080 | |
6894 | 7081 | 移植性の問題: L<perlport/gmtime>。 |
6895 | 7082 | |
6896 | 7083 | =item goto LABEL |
6897 | 7084 | X<goto> X<jump> X<jmp> |
6898 | 7085 | |
6899 | 7086 | =item goto EXPR |
6900 | 7087 | |
6901 | 7088 | =item goto &NAME |
6902 | 7089 | |
6903 | 7090 | =for Pod::Functions create spaghetti code |
6904 | 7091 | |
6905 | 7092 | =begin original |
6906 | 7093 | |
6907 | 7094 | The C<goto LABEL> form finds the statement labeled with LABEL and |
6908 | 7095 | resumes execution there. It can't be used to get out of a block or |
6909 | 7096 | subroutine given to L<C<sort>|/sort SUBNAME LIST>. It can be used to go |
6910 | 7097 | almost anywhere else within the dynamic scope, including out of |
6911 | 7098 | subroutines, but it's usually better to use some other construct such as |
6912 | 7099 | L<C<last>|/last LABEL> or L<C<die>|/die LIST>. The author of Perl has |
6913 | 7100 | never felt the need to use this form of L<C<goto>|/goto LABEL> (in Perl, |
6914 | 7101 | that is; C is another matter). (The difference is that C does not offer |
6915 | 7102 | named loops combined with loop control. Perl does, and this replaces |
6916 | 7103 | most structured uses of L<C<goto>|/goto LABEL> in other languages.) |
6917 | 7104 | |
6918 | 7105 | =end original |
6919 | 7106 | |
6920 | 7107 | C<goto LABEL> の形式は、LABEL というラベルの付いた文を |
6921 | 7108 | 探して、そこへ実行を移すものです。 |
6922 | 7109 | L<C<sort>|/sort SUBNAME LIST> で与えられたブロックやサブルーチンから外へ |
6923 | 7110 | 出ることはできません。 |
6924 | 7111 | これ以外は、サブルーチンの外を含む、動的スコープ内の |
6925 | 7112 | ほとんどすべての場所へ行くために使用できますが、普通は、 |
6926 | 7113 | L<C<last>|/last LABEL> や L<C<die>|/die LIST> といった別の構造を使った方が |
6927 | 7114 | 良いでしょう。 |
6928 | 7115 | Perl の作者はこの形式の L<C<goto>|/goto LABEL> を使う必要を感じたことは、 |
6929 | 7116 | 1 度もありません (Perl では; C は別のお話です)。 |
6930 | 7117 | (違いは、C にはループ制御と結びついた名前つきのループがないことです。 |
6931 | 7118 | Perl にはあり、これが他の言語でのほとんどの構造的な L<C<goto>|/goto LABEL> の |
6932 | 7119 | 使用法を置き換えます。) |
6933 | 7120 | |
6934 | 7121 | =begin original |
6935 | 7122 | |
6936 | 7123 | The C<goto EXPR> form expects to evaluate C<EXPR> to a code reference or |
6937 | 7124 | a label name. If it evaluates to a code reference, it will be handled |
6938 | 7125 | like C<goto &NAME>, below. This is especially useful for implementing |
6939 | 7126 | tail recursion via C<goto __SUB__>. |
6940 | 7127 | |
6941 | 7128 | =end original |
6942 | 7129 | |
6943 | 7130 | C<goto EXPR> の形式は、C<EXPR> をコードリファレンスまたはラベル名として |
6944 | 7131 | 評価することを想定します。 |
6945 | 7132 | コードリファレンスとして評価する場合、後述する C<goto &NAME> のように |
6946 | 7133 | 扱います。 |
6947 | 7134 | これは特に、C<goto __SUB__> による末尾再帰の実装に有用です。 |
6948 | 7135 | |
6949 | 7136 | =begin original |
6950 | 7137 | |
6951 | 7138 | If the expression evaluates to a label name, its scope will be resolved |
6952 | 7139 | dynamically. This allows for computed L<C<goto>|/goto LABEL>s per |
6953 | 7140 | FORTRAN, but isn't necessarily recommended if you're optimizing for |
6954 | 7141 | maintainability: |
6955 | 7142 | |
6956 | 7143 | =end original |
6957 | 7144 | |
6958 | 7145 | 式がラベル名に評価される場合、このスコープは動的に解決されます。 |
6959 | 7146 | これにより FORTRAN のような算術 L<C<goto>|/goto LABEL> が可能になりますが、 |
6960 | 7147 | 保守性を重視するならお勧めしません。 |
6961 | 7148 | |
6962 | 7149 | goto ("FOO", "BAR", "GLARCH")[$i]; |
6963 | 7150 | |
6964 | 7151 | =begin original |
6965 | 7152 | |
6966 | 7153 | As shown in this example, C<goto EXPR> is exempt from the "looks like a |
6967 | 7154 | function" rule. A pair of parentheses following it does not (necessarily) |
6968 | 7155 | delimit its argument. C<goto("NE")."XT"> is equivalent to C<goto NEXT>. |
6969 | 7156 | Also, unlike most named operators, this has the same precedence as |
6970 | 7157 | assignment. |
6971 | 7158 | |
6972 | 7159 | =end original |
6973 | 7160 | |
6974 | 7161 | この例で示したように、C<goto EXPR> は「関数のように見える」ルールから |
6975 | 7162 | 除外されます。 |
6976 | 7163 | これに引き続くかっこの組は引数の区切りとは(必ずしも)なりません。 |
6977 | 7164 | C<goto("NE")."XT"> は C<goto NEXT> と等価です。 |
6978 | 7165 | また、ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 |
6979 | 7166 | |
6980 | 7167 | =begin original |
6981 | 7168 | |
6982 | 7169 | Use of C<goto LABEL> or C<goto EXPR> to jump into a construct is |
6983 | 7170 | deprecated and will issue a warning. Even then, it may not be used to |
6984 | 7171 | go into any construct that requires initialization, such as a |
6985 | subroutine | |
7172 | subroutine, a C<foreach> loop, or a C<given> | |
7173 | block. In general, it may not be used to jump into the parameter | |
7174 | of a binary or list operator, but it may be used to jump into the | |
7175 | I<first> parameter of a binary operator. (The C<=> | |
7176 | assignment operator's "first" operand is its right-hand | |
7177 | operand.) It also can't be used to go into a | |
6986 | 7178 | construct that is optimized away. |
6987 | 7179 | |
6988 | 7180 | =end original |
6989 | 7181 | |
6990 | 7182 | 構造の中に飛び込むために C<goto LABEL> や C<goto EXPR> を使うことは |
6991 | 7183 | 非推奨で、警告が発生します。 |
6992 | それでも、サブルーチンや C<foreach> ループのような、 | |
7184 | それでも、サブルーチンや C<foreach> ループや C<given> ブロックのような、 | |
7185 | 初期化が必要な | |
6993 | 7186 | 構造の中に入るために使うことは出来ません。 |
7187 | 一般的に、2 項演算子やリスト演算子の引数に飛び込むことはできませんが、 | |
7188 | 2 項演算子の I<最初の> 引数に飛び込むために使われていました。 | |
7189 | (C<=> 代入演算子の「最初の」オペランドはその右オペランドです。) | |
6994 | 7190 | また、最適化してなくなってしまった構造の中へ入るために使うことも出来ません。 |
6995 | 7191 | |
6996 | 7192 | =begin original |
6997 | 7193 | |
6998 | 7194 | The C<goto &NAME> form is quite different from the other forms of |
6999 | 7195 | L<C<goto>|/goto LABEL>. In fact, it isn't a goto in the normal sense at |
7000 | 7196 | all, and doesn't have the stigma associated with other gotos. Instead, |
7001 | 7197 | it exits the current subroutine (losing any changes set by |
7002 | 7198 | L<C<local>|/local EXPR>) and immediately calls in its place the named |
7003 | 7199 | subroutine using the current value of L<C<@_>|perlvar/@_>. This is used |
7004 | 7200 | by C<AUTOLOAD> subroutines that wish to load another subroutine and then |
7005 | 7201 | pretend that the other subroutine had been called in the first place |
7006 | 7202 | (except that any modifications to L<C<@_>|perlvar/@_> in the current |
7007 | 7203 | subroutine are propagated to the other subroutine.) After the |
7008 | 7204 | L<C<goto>|/goto LABEL>, not even L<C<caller>|/caller EXPR> will be able |
7009 | 7205 | to tell that this routine was called first. |
7010 | 7206 | |
7011 | 7207 | =end original |
7012 | 7208 | |
7013 | 7209 | C<goto &NAME> の形式は、その他の L<C<goto>|/goto LABEL> の形式とはかなり |
7014 | 7210 | 異なったものです。 |
7015 | 7211 | 実際、これは普通の感覚でいうところのどこかへ行くものでは全くなく、 |
7016 | 7212 | 他の goto が持つ不名誉を持っていません。 |
7017 | 7213 | 現在のサブルーチンを終了し (L<C<local>|/local EXPR> による変更は失われます)、 |
7018 | 7214 | 直ちに現在の L<C<@_>|perlvar/@_> の値を使って指定された名前のサブルーチンを |
7019 | 7215 | 呼び出します。 |
7020 | 7216 | これは、C<AUTOLOAD> サブルーチンが別のサブルーチンをロードして、 |
7021 | 7217 | その別のサブルーチンが最初に呼ばれたようにするために使われます |
7022 | 7218 | (ただし、現在のサブルーチンで L<C<@_>|perlvar/@_> を修正した場合には、 |
7023 | 7219 | その別のサブルーチンに伝えられます)。 |
7024 | 7220 | L<C<goto>|/goto LABEL> のあとは、L<C<caller>|/caller EXPR> でさえも、現在の |
7025 | 7221 | サブルーチンが最初に呼び出されたと言うことができません。 |
7026 | 7222 | |
7027 | 7223 | =begin original |
7028 | 7224 | |
7029 | 7225 | NAME needn't be the name of a subroutine; it can be a scalar variable |
7030 | 7226 | containing a code reference or a block that evaluates to a code |
7031 | 7227 | reference. |
7032 | 7228 | |
7033 | 7229 | =end original |
7034 | 7230 | |
7035 | 7231 | NAME はサブルーチンの名前である必要はありません; コードリファレンスを |
7036 | 7232 | 含むスカラ値や、コードリファレンスと評価されるブロックでも構いません。 |
7037 | 7233 | |
7038 | 7234 | =item grep BLOCK LIST |
7039 | 7235 | X<grep> |
7040 | 7236 | |
7041 | 7237 | =item grep EXPR,LIST |
7042 | 7238 | |
7043 | 7239 | =for Pod::Functions locate elements in a list test true against a given criterion |
7044 | 7240 | |
7045 | 7241 | =begin original |
7046 | 7242 | |
7047 | 7243 | This is similar in spirit to, but not the same as, L<grep(1)> and its |
7048 | 7244 | relatives. In particular, it is not limited to using regular expressions. |
7049 | 7245 | |
7050 | 7246 | =end original |
7051 | 7247 | |
7052 | 7248 | これは L<grep(1)> とその親類と同じようなものですが、同じではありません。 |
7053 | 7249 | 特に、正規表現の使用に制限されません。 |
7054 | 7250 | |
7055 | 7251 | =begin original |
7056 | 7252 | |
7057 | 7253 | Evaluates the BLOCK or EXPR for each element of LIST (locally setting |
7058 | 7254 | L<C<$_>|perlvar/$_> to each element) and returns the list value |
7059 | 7255 | consisting of those |
7060 | 7256 | elements for which the expression evaluated to true. In scalar |
7061 | 7257 | context, returns the number of times the expression was true. |
7062 | 7258 | |
7063 | 7259 | =end original |
7064 | 7260 | |
7065 | 7261 | LIST の個々の要素に対して、BLOCK か EXPR を評価し |
7066 | 7262 | (L<C<$_>|perlvar/$_> は、ローカルに個々の要素が設定されます) 、 |
7067 | 7263 | その要素のうち、評価した式が真となったものからなるリスト値が返されます。 |
7068 | 7264 | スカラコンテキストでは、式が真となった回数を返します。 |
7069 | 7265 | |
7070 | 7266 | my @foo = grep(!/^#/, @bar); # weed out comments |
7071 | 7267 | |
7072 | 7268 | =begin original |
7073 | 7269 | |
7074 | 7270 | or equivalently, |
7075 | 7271 | |
7076 | 7272 | =end original |
7077 | 7273 | |
7078 | 7274 | あるいは等価な例として: |
7079 | 7275 | |
7080 | 7276 | my @foo = grep {!/^#/} @bar; # weed out comments |
7081 | 7277 | |
7082 | 7278 | =begin original |
7083 | 7279 | |
7084 | 7280 | Note that L<C<$_>|perlvar/$_> is an alias to the list value, so it can |
7085 | 7281 | be used to |
7086 | 7282 | modify the elements of the LIST. While this is useful and supported, |
7087 | 7283 | it can cause bizarre results if the elements of LIST are not variables. |
7088 | 7284 | Similarly, grep returns aliases into the original list, much as a for |
7089 | 7285 | loop's index variable aliases the list elements. That is, modifying an |
7090 | 7286 | element of a list returned by grep (for example, in a C<foreach>, |
7091 | 7287 | L<C<map>|/map BLOCK LIST> or another L<C<grep>|/grep BLOCK LIST>) |
7092 | 7288 | actually modifies the element in the original list. |
7093 | 7289 | This is usually something to be avoided when writing clear code. |
7094 | 7290 | |
7095 | 7291 | =end original |
7096 | 7292 | |
7097 | 7293 | L<C<$_>|perlvar/$_> は、LIST の値へのエイリアスですので、LIST の要素を |
7098 | 7294 | 変更するために使うことができます。 |
7099 | 7295 | これは、便利でサポートされていますが、 |
7100 | 7296 | LIST の要素が変数でないと、おかしな結果になります。 |
7101 | 7297 | 同様に、grep は元のリストへのエイリアスを返します; for ループの |
7102 | 7298 | インデックス変数がリスト要素のエイリアスであるのと同様です。 |
7103 | 7299 | つまり、grep で返されたリストの要素を |
7104 | 7300 | (C<foreach>, L<C<map>|/map BLOCK LIST>, または他の |
7105 | 7301 | L<C<grep>|/grep BLOCK LIST> で)修正すると元のリストの要素が変更されます。 |
7106 | 7302 | これはきれいなコードを書くときには普通は回避されます。 |
7107 | 7303 | |
7108 | 7304 | =begin original |
7109 | 7305 | |
7110 | 7306 | See also L<C<map>|/map BLOCK LIST> for a list composed of the results of |
7111 | 7307 | the BLOCK or EXPR. |
7112 | 7308 | |
7113 | 7309 | =end original |
7114 | 7310 | |
7115 | 7311 | BLOCK や EXPR の結果をリストの形にしたい場合は L<C<map>|/map BLOCK LIST> を |
7116 | 7312 | 参照してください。 |
7117 | 7313 | |
7118 | 7314 | =item hex EXPR |
7119 | 7315 | X<hex> X<hexadecimal> |
7120 | 7316 | |
7121 | 7317 | =item hex |
7122 | 7318 | |
7123 | 7319 | =for Pod::Functions convert a hexadecimal string to a number |
7124 | 7320 | |
7125 | 7321 | =begin original |
7126 | 7322 | |
7127 | 7323 | Interprets EXPR as a hex string and returns the corresponding numeric value. |
7128 | 7324 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. |
7129 | 7325 | |
7130 | 7326 | =end original |
7131 | 7327 | |
7132 | 7328 | EXPR を 16 進数の文字列と解釈して、対応する数値を返します。 |
7133 | 7329 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 |
7134 | 7330 | |
7135 | 7331 | print hex '0xAf'; # prints '175' |
7136 | 7332 | print hex 'aF'; # same |
7137 | 7333 | $valid_input =~ /\A(?:0?[xX])?(?:_?[0-9a-fA-F])*\z/ |
7138 | 7334 | |
7139 | 7335 | =begin original |
7140 | 7336 | |
7141 | 7337 | A hex string consists of hex digits and an optional C<0x> or C<x> prefix. |
7142 | 7338 | Each hex digit may be preceded by a single underscore, which will be ignored. |
7143 | 7339 | Any other character triggers a warning and causes the rest of the string |
7144 | 7340 | to be ignored (even leading whitespace, unlike L<C<oct>|/oct EXPR>). |
7145 | 7341 | Only integers can be represented, and integer overflow triggers a warning. |
7146 | 7342 | |
7147 | 7343 | =end original |
7148 | 7344 | |
7149 | 7345 | 16 進文字列は 16 進数と、オプションの C<0x> または C<x> 接頭辞からなります。 |
7150 | 7346 | それぞれの 16 進数は一つの下線を前に置くことができ、これは無視されます。 |
7151 | 7347 | その他の文字は警告を引き起こし、(例え先頭の空白でも、L<C<oct>|/oct EXPR> と |
7152 | 7348 | 異なり)文字列の残りの部分は無視されます。 |
7153 | 7349 | 整数のみを表現でき、整数オーバーフローは警告を引き起こします。 |
7154 | 7350 | |
7155 | 7351 | =begin original |
7156 | 7352 | |
7157 | 7353 | To convert strings that might start with any of C<0>, C<0x>, or C<0b>, |
7158 | 7354 | see L<C<oct>|/oct EXPR>. To present something as hex, look into |
7159 | 7355 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, |
7160 | 7356 | L<C<sprintf>|/sprintf FORMAT, LIST>, and |
7161 | 7357 | L<C<unpack>|/unpack TEMPLATE,EXPR>. |
7162 | 7358 | |
7163 | 7359 | =end original |
7164 | 7360 | |
7165 | 7361 | C<0>, C<0x>, C<0b> のいずれかで始まるかもしれない文字列を変換するには、 |
7166 | 7362 | L<C<oct>|/oct EXPR> を参照してください。 |
7167 | 7363 | 何かを 16 進で表現したい場合は、L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, |
7168 | 7364 | L<C<sprintf>|/sprintf FORMAT, LIST>, L<C<unpack>|/unpack TEMPLATE,EXPR> を |
7169 | 7365 | 参照してください。 |
7170 | 7366 | |
7171 | 7367 | =item import LIST |
7172 | 7368 | X<import> |
7173 | 7369 | |
7174 | 7370 | =for Pod::Functions patch a module's namespace into your own |
7175 | 7371 | |
7176 | 7372 | =begin original |
7177 | 7373 | |
7178 | 7374 | There is no builtin L<C<import>|/import LIST> function. It is just an |
7179 | 7375 | ordinary method (subroutine) defined (or inherited) by modules that wish |
7180 | 7376 | to export names to another module. The |
7181 | 7377 | L<C<use>|/use Module VERSION LIST> function calls the |
7182 | 7378 | L<C<import>|/import LIST> method for the package used. See also |
7183 | 7379 | L<C<use>|/use Module VERSION LIST>, L<perlmod>, and L<Exporter>. |
7184 | 7380 | |
7185 | 7381 | =end original |
7186 | 7382 | |
7187 | 7383 | 組み込みの L<C<import>|/import LIST> 関数というものはありません。 |
7188 | 7384 | これは単に、別のモジュールに名前をエクスポートしたいモジュールが |
7189 | 7385 | 定義した(または継承した)、通常のメソッド(サブルーチン)です。 |
7190 | 7386 | L<C<use>|/use Module VERSION LIST> 関数はパッケージを使う時に |
7191 | 7387 | L<C<import>|/import LIST> メソッドを呼び出します。 |
7192 | 7388 | L<C<use>|/use Module VERSION LIST>, L<perlmod>, L<Exporter> も |
7193 | 7389 | 参照してください。 |
7194 | 7390 | |
7195 | 7391 | =item index STR,SUBSTR,POSITION |
7196 | 7392 | X<index> X<indexOf> X<InStr> |
7197 | 7393 | |
7198 | 7394 | =item index STR,SUBSTR |
7199 | 7395 | |
7200 | 7396 | =for Pod::Functions find a substring within a string |
7201 | 7397 | |
7202 | 7398 | =begin original |
7203 | 7399 | |
7204 | 7400 | The index function searches for one string within another, but without |
7205 | 7401 | the wildcard-like behavior of a full regular-expression pattern match. |
7206 | 7402 | It returns the position of the first occurrence of SUBSTR in STR at |
7207 | 7403 | or after POSITION. If POSITION is omitted, starts searching from the |
7208 | 7404 | beginning of the string. POSITION before the beginning of the string |
7209 | 7405 | or after its end is treated as if it were the beginning or the end, |
7210 | 7406 | respectively. POSITION and the return value are based at zero. |
7211 | 7407 | If the substring is not found, L<C<index>|/index STR,SUBSTR,POSITION> |
7212 | 7408 | returns -1. |
7213 | 7409 | |
7214 | 7410 | =end original |
7215 | 7411 | |
7216 | 7412 | index 関数は ある文字列をもうひとつの文字列から検索しますが、 |
7217 | 7413 | 完全正規表現パターンマッチのワイルドカード的な振る舞いはしません。 |
7218 | 7414 | STR の中の POSITION の位置以降で、最初に SUBSTR が見つかった位置を返します。 |
7219 | 7415 | POSITION が省略された場合には、STR の最初から探し始めます。 |
7220 | 7416 | POSITION が文字列の先頭より前、あるいは末尾より後ろを指定した場合は、 |
7221 | 7417 | それぞれ先頭と末尾を指定されたものとして扱われます。 |
7222 | 7418 | POSITION と返り値のベースは、0 です。 |
7223 | 7419 | SUBSTR が見つからなかった場合には、L<C<index>|/index STR,SUBSTR,POSITION> は |
7224 | 7420 | -1 が返されます。 |
7225 | 7421 | |
7226 | 7422 | =item int EXPR |
7227 | 7423 | X<int> X<integer> X<truncate> X<trunc> X<floor> |
7228 | 7424 | |
7229 | 7425 | =item int |
7230 | 7426 | |
7231 | 7427 | =for Pod::Functions get the integer portion of a number |
7232 | 7428 | |
7233 | 7429 | =begin original |
7234 | 7430 | |
7235 | 7431 | Returns the integer portion of EXPR. If EXPR is omitted, uses |
7236 | 7432 | L<C<$_>|perlvar/$_>. |
7237 | 7433 | You should not use this function for rounding: one because it truncates |
7238 | 7434 | towards C<0>, and two because machine representations of floating-point |
7239 | 7435 | numbers can sometimes produce counterintuitive results. For example, |
7240 | 7436 | C<int(-6.725/0.025)> produces -268 rather than the correct -269; that's |
7241 | 7437 | because it's really more like -268.99999999999994315658 instead. Usually, |
7242 | 7438 | the L<C<sprintf>|/sprintf FORMAT, LIST>, |
7243 | 7439 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, or the |
7244 | 7440 | L<C<POSIX::floor>|POSIX/C<floor>> and L<C<POSIX::ceil>|POSIX/C<ceil>> |
7245 | 7441 | functions will serve you better than will L<C<int>|/int EXPR>. |
7246 | 7442 | |
7247 | 7443 | =end original |
7248 | 7444 | |
7249 | 7445 | EXPR の整数部を返します。 |
7250 | 7446 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 |
7251 | 7447 | この関数を丸めのために使うべきではありません: 第一の理由として C<0> の |
7252 | 7448 | 方向への切捨てを行うから、第二の理由として浮動小数点数の機械表現は時々直感に |
7253 | 7449 | 反した結果を生み出すからです。 |
7254 | 7450 | たとえば、C<int(-6.725/0.025)> は正しい結果である -269 ではなく -268 を |
7255 | 7451 | 返します: これは実際には -268.99999999999994315658 というような値に |
7256 | 7452 | なっているからです。 |
7257 | 7453 | 通常、L<C<sprintf>|/sprintf FORMAT, LIST>, |
7258 | 7454 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, |
7259 | 7455 | L<C<POSIX::floor>|POSIX/C<floor>>, L<C<POSIX::ceil>|POSIX/C<ceil>> の方が |
7260 | 7456 | L<C<int>|/int EXPR> より便利です。 |
7261 | 7457 | |
7262 | 7458 | =item ioctl FILEHANDLE,FUNCTION,SCALAR |
7263 | 7459 | X<ioctl> |
7264 | 7460 | |
7265 | 7461 | =for Pod::Functions system-dependent device control system call |
7266 | 7462 | |
7267 | 7463 | =begin original |
7268 | 7464 | |
7269 | 7465 | Implements the L<ioctl(2)> function. You'll probably first have to say |
7270 | 7466 | |
7271 | 7467 | =end original |
7272 | 7468 | |
7273 | 7469 | L<ioctl(2)> 関数を実装します。 |
7274 | 7470 | 正しい関数の定義を得るために、おそらく最初に |
7275 | 7471 | |
7276 | 7472 | require "sys/ioctl.ph"; # probably in |
7277 | 7473 | # $Config{archlib}/sys/ioctl.ph |
7278 | 7474 | |
7279 | 7475 | =begin original |
7280 | 7476 | |
7281 | 7477 | to get the correct function definitions. If F<sys/ioctl.ph> doesn't |
7282 | 7478 | exist or doesn't have the correct definitions you'll have to roll your |
7283 | 7479 | own, based on your C header files such as F<< <sys/ioctl.h> >>. |
7284 | 7480 | (There is a Perl script called B<h2ph> that comes with the Perl kit that |
7285 | 7481 | may help you in this, but it's nontrivial.) SCALAR will be read and/or |
7286 | 7482 | written depending on the FUNCTION; a C pointer to the string value of SCALAR |
7287 | 7483 | will be passed as the third argument of the actual |
7288 | 7484 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> call. (If SCALAR |
7289 | 7485 | has no string value but does have a numeric value, that value will be |
7290 | 7486 | passed rather than a pointer to the string value. To guarantee this to be |
7291 | 7487 | true, add a C<0> to the scalar before using it.) The |
7292 | 7488 | L<C<pack>|/pack TEMPLATE,LIST> and L<C<unpack>|/unpack TEMPLATE,EXPR> |
7293 | 7489 | functions may be needed to manipulate the values of structures used by |
7294 | 7490 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>. |
7295 | 7491 | |
7296 | 7492 | =end original |
7297 | 7493 | |
7298 | 7494 | としなくてはならないでしょう。 |
7299 | 7495 | F<sys/ioctl.ph> がないか、間違った定義をしている場合には、 |
7300 | 7496 | F<< <sys/ioctl.h> >>のような C のヘッダファイルをもとに、 |
7301 | 7497 | 自分で作らなければなりません。 |
7302 | 7498 | (Perl の配布キットに入っている B<h2ph> という Perl スクリプトが |
7303 | 7499 | これを手助けしてくれるでしょうが、これは自明ではありません。) |
7304 | 7500 | FOUNCTION に応じて SCALAR が読み書きされます; |
7305 | 7501 | SCALAR の文字列値へのポインタが、実際の |
7306 | 7502 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> コールの |
7307 | 7503 | 3 番目の引数として渡されます。 |
7308 | 7504 | (SCALAR が文字列値を持っておらず、数値を持っている場合には、 |
7309 | 7505 | 文字列値へのポインタの代わりに、その値が渡されます。 |
7310 | 7506 | このことを保証するためには、使用する前に SCALAR にC<0> を足してください。) |
7311 | 7507 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> で使われる構造体の値を |
7312 | 7508 | 操作するには、L<C<pack>|/pack TEMPLATE,LIST> 関数と |
7313 | 7509 | L<C<unpack>|/unpack TEMPLATE,EXPR> 関数が必要となるでしょう。 |
7314 | 7510 | |
7315 | 7511 | =begin original |
7316 | 7512 | |
7317 | 7513 | The return value of L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> (and |
7318 | 7514 | L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>) is as follows: |
7319 | 7515 | |
7320 | 7516 | =end original |
7321 | 7517 | |
7322 | 7518 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> |
7323 | 7519 | (と L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>) の返り値は、 |
7324 | 7520 | 以下のようになります: |
7325 | 7521 | |
7326 | 7522 | =begin original |
7327 | 7523 | |
7328 | 7524 | if OS returns: then Perl returns: |
7329 | 7525 | -1 undefined value |
7330 | 7526 | 0 string "0 but true" |
7331 | 7527 | anything else that number |
7332 | 7528 | |
7333 | 7529 | =end original |
7334 | 7530 | |
7335 | 7531 | OS が返した値: Perl が返す値: |
7336 | 7532 | -1 未定義値 |
7337 | 7533 | 0 「0 だが真」の文字列 |
7338 | 7534 | その他 その値そのもの |
7339 | 7535 | |
7340 | 7536 | =begin original |
7341 | 7537 | |
7342 | 7538 | Thus Perl returns true on success and false on failure, yet you can |
7343 | 7539 | still easily determine the actual value returned by the operating |
7344 | 7540 | system: |
7345 | 7541 | |
7346 | 7542 | =end original |
7347 | 7543 | |
7348 | 7544 | つまり Perl は、成功時に「真」、失敗時に「偽」を返す |
7349 | 7545 | ことになり、OS が実際に返した値も、以下のように簡単に知ることができます。 |
7350 | 7546 | |
7351 | 7547 | my $retval = ioctl(...) || -1; |
7352 | 7548 | printf "System returned %d\n", $retval; |
7353 | 7549 | |
7354 | 7550 | =begin original |
7355 | 7551 | |
7356 | 7552 | The special string C<"0 but true"> is exempt from |
7357 | 7553 | L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s> |
7358 | 7554 | L<warnings> on improper numeric conversions. |
7359 | 7555 | |
7360 | 7556 | =end original |
7361 | 7557 | |
7362 | 7558 | 特別な文字列 C<"0 だが真"> は、不適切な数値変換に関する |
7363 | 7559 | L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s> |
7364 | 7560 | L<warnings> 警告を回避します。 |
7365 | 7561 | |
7366 | 7562 | =begin original |
7367 | 7563 | |
7368 | 7564 | Portability issues: L<perlport/ioctl>. |
7369 | 7565 | |
7370 | 7566 | =end original |
7371 | 7567 | |
7372 | 7568 | 移植性の問題: L<perlport/ioctl>。 |
7373 | 7569 | |
7374 | 7570 | =item join EXPR,LIST |
7375 | 7571 | X<join> |
7376 | 7572 | |
7377 | 7573 | =for Pod::Functions join a list into a string using a separator |
7378 | 7574 | |
7379 | 7575 | =begin original |
7380 | 7576 | |
7381 | 7577 | Joins the separate strings of LIST into a single string with fields |
7382 | 7578 | separated by the value of EXPR, and returns that new string. Example: |
7383 | 7579 | |
7384 | 7580 | =end original |
7385 | 7581 | |
7386 | 7582 | LIST の個別の文字列を、EXPR の値で区切って |
7387 | 7583 | 1 つの文字列につなげ、その文字列を返します。 |
7388 | 7584 | 例: |
7389 | 7585 | |
7390 | 7586 | my $rec = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell); |
7391 | 7587 | |
7392 | 7588 | =begin original |
7393 | 7589 | |
7394 | 7590 | Beware that unlike L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>, |
7395 | 7591 | L<C<join>|/join EXPR,LIST> doesn't take a pattern as its first argument. |
7396 | 7592 | Compare L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>. |
7397 | 7593 | |
7398 | 7594 | =end original |
7399 | 7595 | |
7400 | 7596 | L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> と違って、 |
7401 | 7597 | L<C<join>|/join EXPR,LIST> は最初の引数にパターンは取れないことに |
7402 | 7598 | 注意してください。 |
7403 | 7599 | L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> と比較してください。 |
7404 | 7600 | |
7405 | 7601 | =item keys HASH |
7406 | 7602 | X<keys> X<key> |
7407 | 7603 | |
7408 | 7604 | =item keys ARRAY |
7409 | 7605 | |
7410 | 7606 | =for Pod::Functions retrieve list of indices from a hash |
7411 | 7607 | |
7412 | 7608 | =begin original |
7413 | 7609 | |
7414 | 7610 | Called in list context, returns a list consisting of all the keys of the |
7415 | 7611 | named hash, or in Perl 5.12 or later only, the indices of an array. Perl |
7416 | 7612 | releases prior to 5.12 will produce a syntax error if you try to use an |
7417 | 7613 | array argument. In scalar context, returns the number of keys or indices. |
7418 | 7614 | |
7419 | 7615 | =end original |
7420 | 7616 | |
7421 | 7617 | リストコンテキストで呼び出されると、指定したハッシュのすべてのキー、あるいは |
7422 | 7618 | Perl 5.12 以降でのみ、配列のインデックスからなるリストを返します。 |
7423 | 7619 | 5.12 より前の Perl は配列引数を使おうとすると文法エラーを出力します。 |
7424 | 7620 | スカラコンテキストでは、キーやインデックスの数を返します。 |
7425 | 7621 | |
7426 | 7622 | =begin original |
7427 | 7623 | |
7428 | 7624 | Hash entries are returned in an apparently random order. The actual random |
7429 | 7625 | order is specific to a given hash; the exact same series of operations |
7430 | 7626 | on two hashes may result in a different order for each hash. Any insertion |
7431 | 7627 | into the hash may change the order, as will any deletion, with the exception |
7432 | 7628 | that the most recent key returned by L<C<each>|/each HASH> or |
7433 | 7629 | L<C<keys>|/keys HASH> may be deleted without changing the order. So |
7434 | 7630 | long as a given hash is unmodified you may rely on |
7435 | 7631 | L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and L<C<each>|/each |
7436 | 7632 | HASH> to repeatedly return the same order |
7437 | 7633 | as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for |
7438 | 7634 | details on why hash order is randomized. Aside from the guarantees |
7439 | 7635 | provided here the exact details of Perl's hash algorithm and the hash |
7440 | 7636 | traversal order are subject to change in any release of Perl. Tied hashes |
7441 | 7637 | may behave differently to Perl's hashes with respect to changes in order on |
7442 | 7638 | insertion and deletion of items. |
7443 | 7639 | |
7444 | 7640 | =end original |
7445 | 7641 | |
7446 | 7642 | ハッシュ要素は見かけ上、ランダムな順序で返されます。 |
7447 | 7643 | 実際のランダムな順序はハッシュに固有です; 二つのハッシュに全く同じ一連の |
7448 | 7644 | 操作を行っても、ハッシュによって異なった順序になります。 |
7449 | 7645 | ハッシュへの挿入によって順序が変わることがあります; 削除も同様ですが、 |
7450 | 7646 | L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも |
7451 | 7647 | 最近のキーは順序を変えることなく削除できます。 |
7452 | 7648 | ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>, |
7453 | 7649 | L<C<each>|/each HASH> が繰り返し同じ順序で |
7454 | 7650 | 返すことに依存してもかまいません。 |
7455 | 7651 | なぜハッシュの順序がランダム化されているかの詳細については |
7456 | 7652 | L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。 |
7457 | 7653 | ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の |
7458 | 7654 | 正確な詳細は Perl のリリースによって変更される可能性があります。 |
7459 | 7655 | tie されたハッシュは、アイテムの挿入と削除の順序に関して Perl のハッシュと |
7460 | 7656 | 異なった振る舞いをします。 |
7461 | 7657 | |
7462 | 7658 | =begin original |
7463 | 7659 | |
7464 | 7660 | As a side effect, calling L<C<keys>|/keys HASH> resets the internal |
7465 | iterator of the HASH or ARRAY (see L<C<each>|/each HASH>) | |
7661 | iterator of the HASH or ARRAY (see L<C<each>|/each HASH>) before | |
7662 | yielding the keys. In | |
7466 | 7663 | particular, calling L<C<keys>|/keys HASH> in void context resets the |
7467 | 7664 | iterator with no other overhead. |
7468 | 7665 | |
7469 | 7666 | =end original |
7470 | 7667 | |
7471 | 副作用として、L<C<keys>|/keys HASH> の呼び出しは | |
7668 | 副作用として、L<C<keys>|/keys HASH> の呼び出しは、 | |
7669 | キーを取り出す前に HASH や ARRAY の反復子を | |
7472 | 7670 | 初期化します (L<C<each>|/each HASH> を参照してください)。 |
7473 | 7671 | 特に、無効コンテキストで L<C<keys>|/keys HASH> を呼び出すと |
7474 | 7672 | オーバーヘッドなしで反復子を初期化します。 |
7475 | 7673 | |
7476 | 7674 | =begin original |
7477 | 7675 | |
7478 | 7676 | Here is yet another way to print your environment: |
7479 | 7677 | |
7480 | 7678 | =end original |
7481 | 7679 | |
7482 | 7680 | 環境変数を表示する別の例です: |
7483 | 7681 | |
7484 | 7682 | my @keys = keys %ENV; |
7485 | 7683 | my @values = values %ENV; |
7486 | 7684 | while (@keys) { |
7487 | 7685 | print pop(@keys), '=', pop(@values), "\n"; |
7488 | 7686 | } |
7489 | 7687 | |
7490 | 7688 | =begin original |
7491 | 7689 | |
7492 | 7690 | or how about sorted by key: |
7493 | 7691 | |
7494 | 7692 | =end original |
7495 | 7693 | |
7496 | 7694 | key でソートしてもいいでしょう: |
7497 | 7695 | |
7498 | 7696 | foreach my $key (sort(keys %ENV)) { |
7499 | 7697 | print $key, '=', $ENV{$key}, "\n"; |
7500 | 7698 | } |
7501 | 7699 | |
7502 | 7700 | =begin original |
7503 | 7701 | |
7504 | 7702 | The returned values are copies of the original keys in the hash, so |
7505 | 7703 | modifying them will not affect the original hash. Compare |
7506 | 7704 | L<C<values>|/values HASH>. |
7507 | 7705 | |
7508 | 7706 | =end original |
7509 | 7707 | |
7510 | 7708 | 返される値はハッシュにある元のキーのコピーなので、 |
7511 | 7709 | これを変更しても元のハッシュには影響を与えません。 |
7512 | 7710 | L<C<values>|/values HASH> と比較してください。 |
7513 | 7711 | |
7514 | 7712 | =begin original |
7515 | 7713 | |
7516 | 7714 | To sort a hash by value, you'll need to use a |
7517 | 7715 | L<C<sort>|/sort SUBNAME LIST> function. Here's a descending numeric |
7518 | 7716 | sort of a hash by its values: |
7519 | 7717 | |
7520 | 7718 | =end original |
7521 | 7719 | |
7522 | 7720 | ハッシュを値でソートするためには、L<C<sort>|/sort SUBNAME LIST> 関数を使う |
7523 | 7721 | 必要があります。 |
7524 | 7722 | 以下ではハッシュの値を数値の降順でソートしています: |
7525 | 7723 | |
7526 | 7724 | foreach my $key (sort { $hash{$b} <=> $hash{$a} } keys %hash) { |
7527 | 7725 | printf "%4d %s\n", $hash{$key}, $key; |
7528 | 7726 | } |
7529 | 7727 | |
7530 | 7728 | =begin original |
7531 | 7729 | |
7532 | 7730 | Used as an lvalue, L<C<keys>|/keys HASH> allows you to increase the |
7533 | 7731 | number of hash buckets |
7534 | 7732 | allocated for the given hash. This can gain you a measure of efficiency if |
7535 | 7733 | you know the hash is going to get big. (This is similar to pre-extending |
7536 | 7734 | an array by assigning a larger number to $#array.) If you say |
7537 | 7735 | |
7538 | 7736 | =end original |
7539 | 7737 | |
7540 | 7738 | 左辺値として使うことで、L<C<keys>|/keys HASH> を使うことで与えられたハッシュに |
7541 | 7739 | 割り当てられたハッシュ表の大きさを増やすことができます。 |
7542 | 7740 | これによって、ハッシュが大きくなっていくなっていくときの |
7543 | 7741 | 効率の測定ができます。 |
7544 | 7742 | (これは大きい値を $#array に代入することで配列を予め拡張することに |
7545 | 7743 | 似ています。) |
7546 | 7744 | 以下のようにすると: |
7547 | 7745 | |
7548 | 7746 | keys %hash = 200; |
7549 | 7747 | |
7550 | 7748 | =begin original |
7551 | 7749 | |
7552 | 7750 | then C<%hash> will have at least 200 buckets allocated for it--256 of them, |
7553 | 7751 | in fact, since it rounds up to the next power of two. These |
7554 | 7752 | buckets will be retained even if you do C<%hash = ()>, use C<undef |
7555 | 7753 | %hash> if you want to free the storage while C<%hash> is still in scope. |
7556 | 7754 | You can't shrink the number of buckets allocated for the hash using |
7557 | 7755 | L<C<keys>|/keys HASH> in this way (but you needn't worry about doing |
7558 | 7756 | this by accident, as trying has no effect). C<keys @array> in an lvalue |
7559 | 7757 | context is a syntax error. |
7560 | 7758 | |
7561 | 7759 | =end original |
7562 | 7760 | |
7563 | 7761 | C<%hash> は少なくとも 200 の大きさの表が割り当てられます -- |
7564 | 7762 | 実際には 2 のべき乗に切り上げられるので、256 が割り当てられます。 |
7565 | 7763 | この表はたとえ C<%hash = ()> としても残るので、 |
7566 | 7764 | もし C<%hash> がスコープにいるうちにこの領域を開放したい場合は |
7567 | 7765 | C<undef %hash> を使います。 |
7568 | 7766 | この方法で L<C<keys>|/keys HASH> を使うことで、表の大きさを小さくすることは |
7569 | 7767 | できません |
7570 | 7768 | (間違えてそのようなことをしても何も起きないので気にすることはありません)。 |
7571 | 7769 | 左辺値コンテキストでの C<keys @array> は文法エラーとなります。 |
7572 | 7770 | |
7573 | 7771 | =begin original |
7574 | 7772 | |
7575 | 7773 | Starting with Perl 5.14, an experimental feature allowed |
7576 | 7774 | L<C<keys>|/keys HASH> to take a scalar expression. This experiment has |
7577 | 7775 | been deemed unsuccessful, and was removed as of Perl 5.24. |
7578 | 7776 | |
7579 | 7777 | =end original |
7580 | 7778 | |
7581 | 7779 | Perl 5.14 から、L<C<keys>|/keys HASH> がスカラ式を取ることが出来るという |
7582 | 7780 | 実験的機能がありました。 |
7583 | 7781 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 |
7584 | 7782 | |
7585 | 7783 | =begin original |
7586 | 7784 | |
7587 | 7785 | To avoid confusing would-be users of your code who are running earlier |
7588 | 7786 | versions of Perl with mysterious syntax errors, put this sort of thing at |
7589 | 7787 | the top of your file to signal that your code will work I<only> on Perls of |
7590 | 7788 | a recent vintage: |
7591 | 7789 | |
7592 | 7790 | =end original |
7593 | 7791 | |
7594 | 7792 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な |
7595 | 7793 | 文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で |
7596 | 7794 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを |
7597 | 7795 | 書いてください: |
7598 | 7796 | |
7599 | 7797 | use 5.012; # so keys/values/each work on arrays |
7600 | 7798 | |
7601 | 7799 | =begin original |
7602 | 7800 | |
7603 | 7801 | See also L<C<each>|/each HASH>, L<C<values>|/values HASH>, and |
7604 | 7802 | L<C<sort>|/sort SUBNAME LIST>. |
7605 | 7803 | |
7606 | 7804 | =end original |
7607 | 7805 | |
7608 | 7806 | L<C<each>|/each HASH>, L<C<values>|/values HASH>, |
7609 | 7807 | L<C<sort>|/sort SUBNAME LIST> も参照してください。 |
7610 | 7808 | |
7611 | 7809 | =item kill SIGNAL, LIST |
7612 | 7810 | |
7613 | 7811 | =item kill SIGNAL |
7614 | 7812 | X<kill> X<signal> |
7615 | 7813 | |
7616 | 7814 | =for Pod::Functions send a signal to a process or process group |
7617 | 7815 | |
7618 | 7816 | =begin original |
7619 | 7817 | |
7620 | 7818 | Sends a signal to a list of processes. Returns the number of arguments |
7621 | 7819 | that were successfully used to signal (which is not necessarily the same |
7622 | 7820 | as the number of processes actually killed, e.g. where a process group is |
7623 | 7821 | killed). |
7624 | 7822 | |
7625 | 7823 | =end original |
7626 | 7824 | |
7627 | 7825 | プロセスのリストにシグナルを送ります。 |
7628 | 7826 | シグナル送信に使われた引数の数を返します |
7629 | 7827 | (例えばプロセスグループが kill された場合のように、実際に kill された |
7630 | 7828 | プロセスの数と同じとは限りません)。 |
7631 | 7829 | |
7632 | 7830 | my $cnt = kill 'HUP', $child1, $child2; |
7633 | 7831 | kill 'KILL', @goners; |
7634 | 7832 | |
7635 | 7833 | =begin original |
7636 | 7834 | |
7637 | 7835 | SIGNAL may be either a signal name (a string) or a signal number. A signal |
7638 | 7836 | name may start with a C<SIG> prefix, thus C<FOO> and C<SIGFOO> refer to the |
7639 | 7837 | same signal. The string form of SIGNAL is recommended for portability because |
7640 | 7838 | the same signal may have different numbers in different operating systems. |
7641 | 7839 | |
7642 | 7840 | =end original |
7643 | 7841 | |
7644 | 7842 | SIGNAL はシグナル名(文字列)かシグナル番号のどちらかです。 |
7645 | 7843 | シグナル名は C<SIG> 接頭辞で始まることがあるので、C<FOO> と C<SIGFOO> は同じ |
7646 | 7844 | シグナルを意味します。 |
7647 | 7845 | 移植性から文字列形式の SIGNAL が推奨されます; 同じシグナルが異なった |
7648 | 7846 | オペレーティングシステムでは異なった番号になることがあるからです。 |
7649 | 7847 | |
7650 | 7848 | =begin original |
7651 | 7849 | |
7652 | 7850 | A list of signal names supported by the current platform can be found in |
7653 | 7851 | C<$Config{sig_name}>, which is provided by the L<C<Config>|Config> |
7654 | 7852 | module. See L<Config> for more details. |
7655 | 7853 | |
7656 | 7854 | =end original |
7657 | 7855 | |
7658 | 7856 | 現在のプラットフォームが対応しているシグナル名の一覧は、L<C<Config>|Config> |
7659 | 7857 | モジュールによって提供される C<$Config{sig_name}> にあります。 |
7660 | 7858 | さらなる詳細については L<Config> を参照してください。 |
7661 | 7859 | |
7662 | 7860 | =begin original |
7663 | 7861 | |
7664 | 7862 | A negative signal name is the same as a negative signal number, killing process |
7665 | 7863 | groups instead of processes. For example, C<kill '-KILL', $pgrp> and |
7666 | 7864 | C<kill -9, $pgrp> will send C<SIGKILL> to |
7667 | 7865 | the entire process group specified. That |
7668 | 7866 | means you usually want to use positive not negative signals. |
7669 | 7867 | |
7670 | 7868 | =end original |
7671 | 7869 | |
7672 | 7870 | 負のシグナル名は負のシグナル番号と同じで、 |
7673 | 7871 | プロセスではなくプロセスグループに対して kill を行ないます。 |
7674 | 7872 | たとえば、C<kill '-KILL', $pgrp> と C<kill -9, $pgrp> は指定された |
7675 | 7873 | プロセスグループ全体に C<SIGKILL> を送ります。 |
7676 | 7874 | すなわち、通常は、負のシグナルは用いず、正のシグナルを使うことになります。 |
7677 | 7875 | |
7678 | 7876 | =begin original |
7679 | 7877 | |
7680 | 7878 | If SIGNAL is either the number 0 or the string C<ZERO> (or C<SIGZERO>), |
7681 | 7879 | no signal is sent to the process, but L<C<kill>|/kill SIGNAL, LIST> |
7682 | 7880 | checks whether it's I<possible> to send a signal to it |
7683 | 7881 | (that means, to be brief, that the process is owned by the same user, or we are |
7684 | 7882 | the super-user). This is useful to check that a child process is still |
7685 | 7883 | alive (even if only as a zombie) and hasn't changed its UID. See |
7686 | 7884 | L<perlport> for notes on the portability of this construct. |
7687 | 7885 | |
7688 | 7886 | =end original |
7689 | 7887 | |
7690 | 7888 | SIGNAL が数値 0 か文字列 C<ZERO> (または C<SIGZERO> の場合、プロセスに |
7691 | 7889 | シグナルは送られませんが、L<C<kill>|/kill SIGNAL, LIST> は、 |
7692 | 7890 | シグナルを送ることが I<可能> かどうかを調べます (これは、簡単に言うと、 |
7693 | 7891 | プロセスが同じユーザーに所有されているか、自分がスーパーユーザーであることを |
7694 | 7892 | 意味します)。 |
7695 | 7893 | これは子プロセスが(ゾンビとしてだけでも)まだ生きていて、 UID が |
7696 | 7894 | 変わっていないことを調べる時に有用です。 |
7697 | 7895 | この構成の移植性に関する注意については L<perlport> を参照してください。 |
7698 | 7896 | |
7699 | 7897 | =begin original |
7700 | 7898 | |
7701 | 7899 | The behavior of kill when a I<PROCESS> number is zero or negative depends on |
7702 | 7900 | the operating system. For example, on POSIX-conforming systems, zero will |
7703 | 7901 | signal the current process group, -1 will signal all processes, and any |
7704 | 7902 | other negative PROCESS number will act as a negative signal number and |
7705 | 7903 | kill the entire process group specified. |
7706 | 7904 | |
7707 | 7905 | =end original |
7708 | 7906 | |
7709 | 7907 | I<PROCESS> 番号が 0 あるいは負数の場合の kill の振る舞いは |
7710 | 7908 | オペレーティングシステムに依存します。 |
7711 | 7909 | 例えば、POSIX 準拠のシステムでは、0 は現在のプロセスグループにシグナルを送り、 |
7712 | 7910 | -1 は全てのプロセスにシグナルを送り、それ以外の負数の PROCESS 番号は |
7713 | 7911 | 負数のシグナル番号として動作し、指定されたプロセスグループ全体を kill します。 |
7714 | 7912 | |
7715 | 7913 | =begin original |
7716 | 7914 | |
7717 | 7915 | If both the SIGNAL and the PROCESS are negative, the results are undefined. |
7718 | 7916 | A warning may be produced in a future version. |
7719 | 7917 | |
7720 | 7918 | =end original |
7721 | 7919 | |
7722 | 7920 | SIGNAL と PROCESS の両方が負数の場合、結果は未定義です。 |
7723 | 7921 | 将来のバージョンでは警告が出るかも知れません。 |
7724 | 7922 | |
7725 | 7923 | =begin original |
7726 | 7924 | |
7727 | 7925 | See L<perlipc/"Signals"> for more details. |
7728 | 7926 | |
7729 | 7927 | =end original |
7730 | 7928 | |
7731 | 7929 | 詳細は L<perlipc/"Signals"> を参照してください。 |
7732 | 7930 | |
7733 | 7931 | =begin original |
7734 | 7932 | |
7735 | 7933 | On some platforms such as Windows where the L<fork(2)> system call is not |
7736 | 7934 | available, Perl can be built to emulate L<C<fork>|/fork> at the |
7737 | 7935 | interpreter level. |
7738 | 7936 | This emulation has limitations related to kill that have to be considered, |
7739 | 7937 | for code running on Windows and in code intended to be portable. |
7740 | 7938 | |
7741 | 7939 | =end original |
7742 | 7940 | |
7743 | 7941 | Windows のような L<fork(2)> が利用不能なシステムでは、Perl は |
7744 | 7942 | L<C<fork>|/fork> をインタプリタレベルでエミュレートします。 |
7745 | 7943 | エミュレーションは kill に関連して、コードが Windows で実行されて |
7746 | 7944 | しかしコードが移植性があると考えられるように制限があります。 |
7747 | 7945 | |
7748 | 7946 | =begin original |
7749 | 7947 | |
7750 | 7948 | See L<perlfork> for more details. |
7751 | 7949 | |
7752 | 7950 | =end original |
7753 | 7951 | |
7754 | 7952 | さらなる詳細については L<perlfork> を参照してください。 |
7755 | 7953 | |
7756 | 7954 | =begin original |
7757 | 7955 | |
7758 | 7956 | If there is no I<LIST> of processes, no signal is sent, and the return |
7759 | 7957 | value is 0. This form is sometimes used, however, because it causes |
7760 | 7958 | tainting checks to be run. But see |
7761 | 7959 | L<perlsec/Laundering and Detecting Tainted Data>. |
7762 | 7960 | |
7763 | 7961 | =end original |
7764 | 7962 | |
7765 | 7963 | 処理する I<LIST> がない場合、シグナルは送られず、返り値は 0 です。 |
7766 | 7964 | しかし、この形式は時々使われます; 実行するために汚染チェックを |
7767 | 7965 | 引き起こすからです。 |
7768 | 7966 | しかし L<perlsec/Laundering and Detecting Tainted Data> を参照してください。 |
7769 | 7967 | |
7770 | 7968 | =begin original |
7771 | 7969 | |
7772 | 7970 | Portability issues: L<perlport/kill>. |
7773 | 7971 | |
7774 | 7972 | =end original |
7775 | 7973 | |
7776 | 7974 | 移植性の問題: L<perlport/kill>。 |
7777 | 7975 | |
7778 | 7976 | =item last LABEL |
7779 | 7977 | X<last> X<break> |
7780 | 7978 | |
7781 | 7979 | =item last EXPR |
7782 | 7980 | |
7783 | 7981 | =item last |
7784 | 7982 | |
7785 | 7983 | =for Pod::Functions exit a block prematurely |
7786 | 7984 | |
7787 | 7985 | =begin original |
7788 | 7986 | |
7789 | 7987 | The L<C<last>|/last LABEL> command is like the C<break> statement in C |
7790 | 7988 | (as used in |
7791 | 7989 | loops); it immediately exits the loop in question. If the LABEL is |
7792 | 7990 | omitted, the command refers to the innermost enclosing |
7793 | 7991 | loop. The C<last EXPR> form, available starting in Perl |
7794 | 7992 | 5.18.0, allows a label name to be computed at run time, |
7795 | 7993 | and is otherwise identical to C<last LABEL>. The |
7796 | 7994 | L<C<continue>|/continue BLOCK> block, if any, is not executed: |
7797 | 7995 | |
7798 | 7996 | =end original |
7799 | 7997 | |
7800 | 7998 | L<C<last>|/last LABEL> コマンドは、(ループ内で使った) C の C<break> 文と |
7801 | 7999 | 同じようなもので、LABEL で指定されるループを即座に抜けます。 |
7802 | 8000 | LABEL が省略されると、コマンドは一番内側のループを参照します。 |
7803 | 8001 | Perl 5.18.0 から利用可能な C<last EXPR> 形式では、実行時に計算される |
7804 | 8002 | ラベル名を使えます; それ以外は C<last LABEL> と同一です。 |
7805 | 8003 | L<C<continue>|/continue BLOCK> ブロックがあっても実行されません: |
7806 | 8004 | |
7807 | 8005 | LINE: while (<STDIN>) { |
7808 | 8006 | last LINE if /^$/; # exit when done with header |
7809 | 8007 | #... |
7810 | 8008 | } |
7811 | 8009 | |
7812 | 8010 | =begin original |
7813 | 8011 | |
7814 | L<C<last>|/last LABEL> cannot | |
8012 | L<C<last>|/last LABEL> cannot return a value from a block that typically | |
7815 | value such as C<eval {}>, C<sub {}>, or C<do {}> | |
8013 | returns a value, such as C<eval {}>, C<sub {}>, or C<do {}>. It will perform | |
7816 | to e | |
8014 | its flow control behavior, which precludes any return value. It should not be | |
8015 | used to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST> | |
7817 | 8016 | operation. |
7818 | 8017 | |
7819 | 8018 | =end original |
7820 | 8019 | |
7821 | 8020 | L<C<last>|/last LABEL> は C<eval {}>, C<sub {}>, C<do {}> といった |
7822 | 値を返すブロックを | |
8021 | 典型的には値を返すブロックから値を返せません。 | |
8022 | これは、返り値を不可能にするフロー制御の振る舞いを実行します。 | |
7823 | 8023 | L<C<grep>|/grep BLOCK LIST> や L<C<map>|/map BLOCK LIST> 操作を終了するのに |
7824 | 8024 | 使うべきではありません。 |
7825 | 8025 | |
7826 | 8026 | =begin original |
7827 | 8027 | |
7828 | 8028 | Note that a block by itself is semantically identical to a loop |
7829 | 8029 | that executes once. Thus L<C<last>|/last LABEL> can be used to effect |
7830 | 8030 | an early exit out of such a block. |
7831 | 8031 | |
7832 | 8032 | =end original |
7833 | 8033 | |
7834 | 8034 | ブロック自身は一回だけ実行されるループと文法的に同一であることに |
7835 | 8035 | 注意してください。 |
7836 | 8036 | 従って、L<C<last>|/last LABEL> でそのようなブロックを途中で |
7837 | 8037 | 抜け出すことができます。 |
7838 | 8038 | |
7839 | 8039 | =begin original |
7840 | 8040 | |
7841 | 8041 | See also L<C<continue>|/continue BLOCK> for an illustration of how |
7842 | 8042 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and |
7843 | 8043 | L<C<redo>|/redo LABEL> work. |
7844 | 8044 | |
7845 | 8045 | =end original |
7846 | 8046 | |
7847 | 8047 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL> が |
7848 | 8048 | どのように働くかについては L<C<continue>|/continue BLOCK> も参照してください。 |
7849 | 8049 | |
7850 | 8050 | =begin original |
7851 | 8051 | |
7852 | 8052 | Unlike most named operators, this has the same precedence as assignment. |
7853 | 8053 | It is also exempt from the looks-like-a-function rule, so |
7854 | 8054 | C<last ("foo")."bar"> will cause "bar" to be part of the argument to |
7855 | 8055 | L<C<last>|/last LABEL>. |
7856 | 8056 | |
7857 | 8057 | =end original |
7858 | 8058 | |
7859 | 8059 | ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 |
7860 | 8060 | また、関数のように見えるものの規則からも免れるので、C<last ("foo")."bar"> と |
7861 | 8061 | すると "bar" は L<C<last>|/last LABEL> への引数の一部となります。 |
7862 | 8062 | |
7863 | 8063 | =item lc EXPR |
7864 | 8064 | X<lc> X<lowercase> |
7865 | 8065 | |
7866 | 8066 | =item lc |
7867 | 8067 | |
7868 | 8068 | =for Pod::Functions return lower-case version of a string |
7869 | 8069 | |
7870 | 8070 | =begin original |
7871 | 8071 | |
7872 | 8072 | Returns a lowercased version of EXPR. This is the internal function |
7873 | 8073 | implementing the C<\L> escape in double-quoted strings. |
7874 | 8074 | |
7875 | 8075 | =end original |
7876 | 8076 | |
7877 | 8077 | EXPR を小文字に変換したものを返します。 |
7878 | 8078 | これは、ダブルクォート文字列における、 |
7879 | 8079 | C<\L> エスケープを実装する内部関数です。 |
7880 | 8080 | |
7881 | 8081 | =begin original |
7882 | 8082 | |
7883 | 8083 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. |
7884 | 8084 | |
7885 | 8085 | =end original |
7886 | 8086 | |
7887 | 8087 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 |
7888 | 8088 | |
7889 | 8089 | =begin original |
7890 | 8090 | |
7891 | 8091 | What gets returned depends on several factors: |
7892 | 8092 | |
7893 | 8093 | =end original |
7894 | 8094 | |
7895 | 8095 | 返り値として得られるものは色々な要素に依存します: |
7896 | 8096 | |
7897 | 8097 | =over |
7898 | 8098 | |
7899 | 8099 | =item If C<use bytes> is in effect: |
7900 | 8100 | |
7901 | 8101 | (C<use bytes> が有効の場合) |
7902 | 8102 | |
7903 | 8103 | =begin original |
7904 | 8104 | |
7905 | 8105 | The results follow ASCII rules. Only the characters C<A-Z> change, |
7906 | 8106 | to C<a-z> respectively. |
7907 | 8107 | |
7908 | 8108 | =end original |
7909 | 8109 | |
7910 | 8110 | 結果は ASCII の規則に従います。 |
7911 | 8111 | C<A-Z> のみが変換され、それぞれ C<a-z> になります。 |
7912 | 8112 | |
7913 | 8113 | =item Otherwise, if C<use locale> for C<LC_CTYPE> is in effect: |
7914 | 8114 | |
7915 | 8115 | (それ以外の場合で、C<LC_CTYPE> に対して C<use locale> が有効の場合) |
7916 | 8116 | |
7917 | 8117 | =begin original |
7918 | 8118 | |
7919 | 8119 | Respects current C<LC_CTYPE> locale for code points < 256; and uses Unicode |
7920 | 8120 | rules for the remaining code points (this last can only happen if |
7921 | 8121 | the UTF8 flag is also set). See L<perllocale>. |
7922 | 8122 | |
7923 | 8123 | =end original |
7924 | 8124 | |
7925 | 8125 | 符号位置 < 256 に対しては現在の C<LC_CTYPE> ロケールに従います; そして |
7926 | 8126 | 残りの符号位置に付いては Unicode の規則を使います (これは UTF8 フラグも |
7927 | 8127 | 設定されている場合にのみ起こります)。 |
7928 | 8128 | L<perllocale> を参照してください。 |
7929 | 8129 | |
7930 | 8130 | =begin original |
7931 | 8131 | |
7932 | 8132 | Starting in v5.20, Perl uses full Unicode rules if the locale is |
7933 | 8133 | UTF-8. Otherwise, there is a deficiency in this scheme, which is that |
7934 | 8134 | case changes that cross the 255/256 |
7935 | 8135 | boundary are not well-defined. For example, the lower case of LATIN CAPITAL |
7936 | 8136 | LETTER SHARP S (U+1E9E) in Unicode rules is U+00DF (on ASCII |
7937 | 8137 | platforms). But under C<use locale> (prior to v5.20 or not a UTF-8 |
7938 | 8138 | locale), the lower case of U+1E9E is |
7939 | 8139 | itself, because 0xDF may not be LATIN SMALL LETTER SHARP S in the |
7940 | 8140 | current locale, and Perl has no way of knowing if that character even |
7941 | 8141 | exists in the locale, much less what code point it is. Perl returns |
7942 | 8142 | a result that is above 255 (almost always the input character unchanged), |
7943 | 8143 | for all instances (and there aren't many) where the 255/256 boundary |
7944 | 8144 | would otherwise be crossed; and starting in v5.22, it raises a |
7945 | 8145 | L<locale|perldiag/Can't do %s("%s") on non-UTF-8 locale; resolved to "%s".> warning. |
7946 | 8146 | |
7947 | 8147 | =end original |
7948 | 8148 | |
7949 | 8149 | v5.20 から、ロケールが UTF-8 の場合は Perl は完全な Unicode の規則を使います。 |
7950 | 8150 | さもなければ、この手法には、255/266 の境界をまたぐ大文字小文字の変換は |
7951 | 8151 | 未定義であるという欠点があります。 |
7952 | 8152 | 例えば、Unicode での LATIN CAPITAL LETTER SHARP S (U+1E9E) の小文字は |
7953 | 8153 | (ASCII プラットフォームでは) U+00DF です。 |
7954 | 8154 | しかし C<use locale> が有効(v5.20 より前か、UTF-8 ロケール以外)なら、U+1E9E の |
7955 | 8155 | 小文字は自分自身です; なぜなら 0xDF は現在のロケールでは |
7956 | 8156 | LATIN SMALL LETTER SHARP S ではなく、Perl は例えこのロケールに文字が |
7957 | 8157 | 存在するかどうかを知る方法がなく、ましてどの符号位置かを知る方法が |
7958 | 8158 | ないからです。 |
7959 | 8159 | Perl は 255/256 境界をまたぐ全ての(多くはありません)実体については |
7960 | 8160 | (ほとんど常に入力文字を変更せずに)256 以上の値を返します; |
7961 | 8161 | そして v5.22 から |
7962 | 8162 | L<locale|perldiag/Can't do %s("%s") on non-UTF-8 locale; resolved to "%s".> |
7963 | 8163 | 警告を出力します。 |
7964 | 8164 | |
7965 | 8165 | =item Otherwise, If EXPR has the UTF8 flag set: |
7966 | 8166 | |
7967 | 8167 | (その他の場合で、EXPR に UTF8 フラグがセットされている場合) |
7968 | 8168 | |
7969 | 8169 | =begin original |
7970 | 8170 | |
7971 | 8171 | Unicode rules are used for the case change. |
7972 | 8172 | |
7973 | 8173 | =end original |
7974 | 8174 | |
7975 | 8175 | 大文字小文字変換には Unicode の規則が使われます。 |
7976 | 8176 | |
7977 | 8177 | =item Otherwise, if C<use feature 'unicode_strings'> or C<use locale ':not_characters'> is in effect: |
7978 | 8178 | |
7979 | 8179 | (それ以外の場合で、C<use feature 'unicode_strings'> か C<use locale ':not_characters'> が有効の場合) |
7980 | 8180 | |
7981 | 8181 | =begin original |
7982 | 8182 | |
7983 | 8183 | Unicode rules are used for the case change. |
7984 | 8184 | |
7985 | 8185 | =end original |
7986 | 8186 | |
7987 | 8187 | 大文字小文字変換には Unicode の規則が使われます。 |
7988 | 8188 | |
7989 | 8189 | =item Otherwise: |
7990 | 8190 | |
7991 | 8191 | (それ以外の場合) |
7992 | 8192 | |
7993 | 8193 | =begin original |
7994 | 8194 | |
7995 | 8195 | ASCII rules are used for the case change. The lowercase of any character |
7996 | 8196 | outside the ASCII range is the character itself. |
7997 | 8197 | |
7998 | 8198 | =end original |
7999 | 8199 | |
8000 | 8200 | 大文字小文字変換には ASCII の規則が使われます。 |
8001 | 8201 | ASCII の範囲外の文字の「小文字」はその文字自身です。 |
8002 | 8202 | |
8003 | 8203 | =back |
8004 | 8204 | |
8005 | 8205 | =item lcfirst EXPR |
8006 | 8206 | X<lcfirst> X<lowercase> |
8007 | 8207 | |
8008 | 8208 | =item lcfirst |
8009 | 8209 | |
8010 | 8210 | =for Pod::Functions return a string with just the next letter in lower case |
8011 | 8211 | |
8012 | 8212 | =begin original |
8013 | 8213 | |
8014 | 8214 | Returns the value of EXPR with the first character lowercased. This |
8015 | 8215 | is the internal function implementing the C<\l> escape in |
8016 | 8216 | double-quoted strings. |
8017 | 8217 | |
8018 | 8218 | =end original |
8019 | 8219 | |
8020 | 8220 | 最初の文字だけを小文字にした、EXPR を返します。 |
8021 | 8221 | これは、ダブルクォート文字列における、C<\l> エスケープを |
8022 | 8222 | 実装する内部関数です。 |
8023 | 8223 | |
8024 | 8224 | =begin original |
8025 | 8225 | |
8026 | 8226 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. |
8027 | 8227 | |
8028 | 8228 | =end original |
8029 | 8229 | |
8030 | 8230 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 |
8031 | 8231 | |
8032 | 8232 | =begin original |
8033 | 8233 | |
8034 | 8234 | This function behaves the same way under various pragmas, such as in a locale, |
8035 | 8235 | as L<C<lc>|/lc EXPR> does. |
8036 | 8236 | |
8037 | 8237 | =end original |
8038 | 8238 | |
8039 | 8239 | この関数は、ロケールのようなさまざまなプラグマの影響下では、 |
8040 | 8240 | L<C<lc>|/lc EXPR> と同様に振る舞います。 |
8041 | 8241 | |
8042 | 8242 | =item length EXPR |
8043 | 8243 | X<length> X<size> |
8044 | 8244 | |
8045 | 8245 | =item length |
8046 | 8246 | |
8047 | 8247 | =for Pod::Functions return the number of characters in a string |
8048 | 8248 | |
8049 | 8249 | =begin original |
8050 | 8250 | |
8051 | 8251 | Returns the length in I<characters> of the value of EXPR. If EXPR is |
8052 | 8252 | omitted, returns the length of L<C<$_>|perlvar/$_>. If EXPR is |
8053 | 8253 | undefined, returns L<C<undef>|/undef EXPR>. |
8054 | 8254 | |
8055 | 8255 | =end original |
8056 | 8256 | |
8057 | 8257 | EXPR の値の I<文字> の長さを返します。 |
8058 | 8258 | EXPR が省略されたときには、L<C<$_>|perlvar/$_> の長さを返します。 |
8059 | 8259 | EXPR が未定義値の場合、L<C<undef>|/undef EXPR> を返します。 |
8060 | 8260 | |
8061 | 8261 | =begin original |
8062 | 8262 | |
8063 | 8263 | This function cannot be used on an entire array or hash to find out how |
8064 | 8264 | many elements these have. For that, use C<scalar @array> and C<scalar keys |
8065 | 8265 | %hash>, respectively. |
8066 | 8266 | |
8067 | 8267 | =end original |
8068 | 8268 | |
8069 | 8269 | この関数は配列やハッシュ全体に対してどれだけの要素を含んでいるかを |
8070 | 8270 | 調べるためには使えません。 |
8071 | 8271 | そのような用途には、それぞれ C<scalar @array> と C<scalar keys %hash> を |
8072 | 8272 | 利用してください。 |
8073 | 8273 | |
8074 | 8274 | =begin original |
8075 | 8275 | |
8076 | 8276 | Like all Perl character operations, L<C<length>|/length EXPR> normally |
8077 | 8277 | deals in logical |
8078 | 8278 | characters, not physical bytes. For how many bytes a string encoded as |
8079 | 8279 | UTF-8 would take up, use C<length(Encode::encode('UTF-8', EXPR))> |
8080 | 8280 | (you'll have to C<use Encode> first). See L<Encode> and L<perlunicode>. |
8081 | 8281 | |
8082 | 8282 | =end original |
8083 | 8283 | |
8084 | 8284 | 全ての Perl の文字操作と同様、L<C<length>|/length EXPR> は通常物理的な |
8085 | 8285 | バイトではなく論理文字を扱います。 |
8086 | 8286 | UTF-8 でエンコードされた文字列が何バイトかを知るには、 |
8087 | 8287 | C<length(Encode::encode('UTF-8', EXPR))> を使ってください (先に |
8088 | 8288 | C<use Encode> する必要があります)。 |
8089 | 8289 | L<Encode> と L<perlunicode> を参照してください。 |
8090 | 8290 | |
8091 | 8291 | =item __LINE__ |
8092 | 8292 | X<__LINE__> |
8093 | 8293 | |
8094 | 8294 | =for Pod::Functions the current source line number |
8095 | 8295 | |
8096 | 8296 | =begin original |
8097 | 8297 | |
8098 | 8298 | A special token that compiles to the current line number. |
8299 | It can be altered by the mechanism described at | |
8300 | L<perlsyn/"Plain Old Comments (Not!)">. | |
8099 | 8301 | |
8100 | 8302 | =end original |
8101 | 8303 | |
8102 | 8304 | 現在の行番号にコンパイルされる特殊トークン。 |
8305 | L<perlsyn/"Plain Old Comments (Not!)"> で記述されている機構を使って | |
8306 | 置き換えられます。 | |
8103 | 8307 | |
8104 | 8308 | =item link OLDFILE,NEWFILE |
8105 | 8309 | X<link> |
8106 | 8310 | |
8107 | 8311 | =for Pod::Functions create a hard link in the filesystem |
8108 | 8312 | |
8109 | 8313 | =begin original |
8110 | 8314 | |
8111 | 8315 | Creates a new filename linked to the old filename. Returns true for |
8112 | 8316 | success, false otherwise. |
8113 | 8317 | |
8114 | 8318 | =end original |
8115 | 8319 | |
8116 | 8320 | OLDFILE にリンクされた、新しいファイル NEWFILE を作ります。 |
8117 | 8321 | 成功時には真を、さもなければ偽を返します。 |
8118 | 8322 | |
8119 | 8323 | =begin original |
8120 | 8324 | |
8121 | 8325 | Portability issues: L<perlport/link>. |
8122 | 8326 | |
8123 | 8327 | =end original |
8124 | 8328 | |
8125 | 8329 | 移植性の問題: L<perlport/link>。 |
8126 | 8330 | |
8127 | 8331 | =item listen SOCKET,QUEUESIZE |
8128 | 8332 | X<listen> |
8129 | 8333 | |
8130 | 8334 | =for Pod::Functions register your socket as a server |
8131 | 8335 | |
8132 | 8336 | =begin original |
8133 | 8337 | |
8134 | 8338 | Does the same thing that the L<listen(2)> system call does. Returns true if |
8135 | 8339 | it succeeded, false otherwise. See the example in |
8136 | 8340 | L<perlipc/"Sockets: Client/Server Communication">. |
8137 | 8341 | |
8138 | 8342 | =end original |
8139 | 8343 | |
8140 | 8344 | L<listen(2)> システムコールと同じことをします。 |
8141 | 8345 | 成功時には真を、さもなければ偽を返します。 |
8142 | 8346 | L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。 |
8143 | 8347 | |
8144 | 8348 | =item local EXPR |
8145 | 8349 | X<local> |
8146 | 8350 | |
8147 | 8351 | =for Pod::Functions create a temporary value for a global variable (dynamic scoping) |
8148 | 8352 | |
8149 | 8353 | =begin original |
8150 | 8354 | |
8151 | 8355 | You really probably want to be using L<C<my>|/my VARLIST> instead, |
8152 | 8356 | because L<C<local>|/local EXPR> isn't what most people think of as |
8153 | 8357 | "local". See L<perlsub/"Private Variables via my()"> for details. |
8154 | 8358 | |
8155 | 8359 | =end original |
8156 | 8360 | |
8157 | 8361 | あなたはが本当に望んでいるのは L<C<my>|/my VARLIST> の方でしょう; |
8158 | 8362 | L<C<local>|/local EXPR> はほとんどの人々が「ローカル」と考えるものと |
8159 | 8363 | 違うからです。 |
8160 | 8364 | 詳細は L<perlsub/"Private Variables via my()"> を参照してください。 |
8161 | 8365 | |
8162 | 8366 | =begin original |
8163 | 8367 | |
8164 | 8368 | A local modifies the listed variables to be local to the enclosing |
8165 | 8369 | block, file, or eval. If more than one value is listed, the list must |
8166 | 8370 | be placed in parentheses. See L<perlsub/"Temporary Values via local()"> |
8167 | 8371 | for details, including issues with tied arrays and hashes. |
8168 | 8372 | |
8169 | 8373 | =end original |
8170 | 8374 | |
8171 | 8375 | "local" はリストアップされた変数を、囲っているブロック、 |
8172 | 8376 | ファイル、eval の中で、ローカルなものにします。 |
8173 | 8377 | 複数の値を指定する場合は、リストはかっこでくくらなければなりません。 |
8174 | 8378 | tie した配列とハッシュに関する事項を含む詳細については |
8175 | 8379 | L<perlsub/"Temporary Values via local()"> を参照してください。 |
8176 | 8380 | |
8177 | 8381 | =begin original |
8178 | 8382 | |
8179 | 8383 | The C<delete local EXPR> construct can also be used to localize the deletion |
8180 | 8384 | of array/hash elements to the current block. |
8181 | 8385 | See L<perlsub/"Localized deletion of elements of composite types">. |
8182 | 8386 | |
8183 | 8387 | =end original |
8184 | 8388 | |
8185 | 8389 | C<delete local EXPR> 構文は、配列/ハッシュの要素の削除を現在の |
8186 | 8390 | ブロックにローカル化するためにも使われていました。 |
8187 | 8391 | L<perlsub/"Localized deletion of elements of composite types"> を |
8188 | 8392 | 参照してください。 |
8189 | 8393 | |
8190 | 8394 | =item localtime EXPR |
8191 | 8395 | X<localtime> X<ctime> |
8192 | 8396 | |
8193 | 8397 | =item localtime |
8194 | 8398 | |
8195 | 8399 | =for Pod::Functions convert UNIX time into record or string using local time |
8196 | 8400 | |
8197 | 8401 | =begin original |
8198 | 8402 | |
8199 | 8403 | Converts a time as returned by the time function to a 9-element list |
8200 | 8404 | with the time analyzed for the local time zone. Typically used as |
8201 | 8405 | follows: |
8202 | 8406 | |
8203 | 8407 | =end original |
8204 | 8408 | |
8205 | 8409 | time 関数が返す時刻を、ローカルなタイムゾーンで測った時刻として、 |
8206 | 8410 | 9 要素の配列に変換します。 |
8207 | 8411 | 普通は、以下のようにして使います: |
8208 | 8412 | |
8209 | 8413 | # 0 1 2 3 4 5 6 7 8 |
8210 | 8414 | my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = |
8211 | 8415 | localtime(time); |
8212 | 8416 | |
8213 | 8417 | =begin original |
8214 | 8418 | |
8215 | 8419 | All list elements are numeric and come straight out of the C `struct |
8216 | 8420 | tm'. C<$sec>, C<$min>, and C<$hour> are the seconds, minutes, and hours |
8217 | 8421 | of the specified time. |
8218 | 8422 | |
8219 | 8423 | =end original |
8220 | 8424 | |
8221 | 8425 | すべてのリスト要素は数値で、C の `struct tm' 構造体から |
8222 | 8426 | 直接持ってきます。 |
8223 | 8427 | C<$sec>, C<$min>, C<$hour> は指定された時刻の秒、分、時です。 |
8224 | 8428 | |
8225 | 8429 | =begin original |
8226 | 8430 | |
8227 | 8431 | C<$mday> is the day of the month and C<$mon> the month in |
8228 | 8432 | the range C<0..11>, with 0 indicating January and 11 indicating December. |
8229 | 8433 | This makes it easy to get a month name from a list: |
8230 | 8434 | |
8231 | 8435 | =end original |
8232 | 8436 | |
8233 | 8437 | C<$mday> は月の何日目か、C<$mon> は月の値です; 月の値は C<0..11> で、0 が |
8234 | 8438 | 1 月、11 が 12 月です。 |
8235 | 8439 | これにより、リストから月の名前を得るのが簡単になります: |
8236 | 8440 | |
8237 | 8441 | my @abbr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); |
8238 | 8442 | print "$abbr[$mon] $mday"; |
8239 | 8443 | # $mon=9, $mday=18 gives "Oct 18" |
8240 | 8444 | |
8241 | 8445 | =begin original |
8242 | 8446 | |
8243 | 8447 | C<$year> contains the number of years since 1900. To get a 4-digit |
8244 | 8448 | year write: |
8245 | 8449 | |
8246 | 8450 | =end original |
8247 | 8451 | |
8248 | 8452 | C<$year> は 1900 年からの年数を持ちます。 |
8249 | 8453 | 4 桁の年を得るには以下のようにします: |
8250 | 8454 | |
8251 | 8455 | $year += 1900; |
8252 | 8456 | |
8253 | 8457 | =begin original |
8254 | 8458 | |
8255 | 8459 | To get the last two digits of the year (e.g., "01" in 2001) do: |
8256 | 8460 | |
8257 | 8461 | =end original |
8258 | 8462 | |
8259 | 8463 | 西暦の下 2 桁(2001 年では "01")がほしい場合は以下のようにします: |
8260 | 8464 | |
8261 | 8465 | $year = sprintf("%02d", $year % 100); |
8262 | 8466 | |
8263 | 8467 | =begin original |
8264 | 8468 | |
8265 | 8469 | C<$wday> is the day of the week, with 0 indicating Sunday and 3 indicating |
8266 | 8470 | Wednesday. C<$yday> is the day of the year, in the range C<0..364> |
8267 | 8471 | (or C<0..365> in leap years.) |
8268 | 8472 | |
8269 | 8473 | =end original |
8270 | 8474 | |
8271 | 8475 | C<$wday> は曜日で、0 が日曜日、3 が水曜日です。 |
8272 | 8476 | C<$yday> はその年の何日目かで、C<0..364> の値を取ります |
8273 | 8477 | (うるう年は C<0..365> です。) |
8274 | 8478 | |
8275 | 8479 | =begin original |
8276 | 8480 | |
8277 | 8481 | C<$isdst> is true if the specified time occurs during Daylight Saving |
8278 | 8482 | Time, false otherwise. |
8279 | 8483 | |
8280 | 8484 | =end original |
8281 | 8485 | |
8282 | 8486 | C<$isdst> は指定された時刻が夏時間の場合は真、そうでなければ偽です。 |
8283 | 8487 | |
8284 | 8488 | =begin original |
8285 | 8489 | |
8286 | 8490 | If EXPR is omitted, L<C<localtime>|/localtime EXPR> uses the current |
8287 | 8491 | time (as returned by L<C<time>|/time>). |
8288 | 8492 | |
8289 | 8493 | =end original |
8290 | 8494 | |
8291 | 8495 | EXPR が省略されると、L<C<localtime>|/localtime EXPR> は |
8292 | 8496 | (L<C<time>|/time> によって返される) 現在時刻を使います。 |
8293 | 8497 | |
8294 | 8498 | =begin original |
8295 | 8499 | |
8296 | 8500 | In scalar context, L<C<localtime>|/localtime EXPR> returns the |
8297 | 8501 | L<ctime(3)> value: |
8298 | 8502 | |
8299 | 8503 | =end original |
8300 | 8504 | |
8301 | 8505 | スカラコンテキストでは、L<C<localtime>|/localtime EXPR> は L<ctime(3)> の値を |
8302 | 8506 | 返します: |
8303 | 8507 | |
8304 | 8508 | my $now_string = localtime; # e.g., "Thu Oct 13 04:54:34 1994" |
8305 | 8509 | |
8306 | 8510 | =begin original |
8307 | 8511 | |
8308 | 8512 | The format of this scalar value is B<not> locale-dependent but built |
8309 | 8513 | into Perl. For GMT instead of local time use the |
8310 | 8514 | L<C<gmtime>|/gmtime EXPR> builtin. See also the |
8311 | 8515 | L<C<Time::Local>|Time::Local> module (for converting seconds, minutes, |
8312 | 8516 | hours, and such back to the integer value returned by L<C<time>|/time>), |
8313 | 8517 | and the L<POSIX> module's L<C<strftime>|POSIX/C<strftime>> and |
8314 | 8518 | L<C<mktime>|POSIX/C<mktime>> functions. |
8315 | 8519 | |
8316 | 8520 | =end original |
8317 | 8521 | |
8318 | 8522 | このスカラ値の形式はロケール依存 B<ではなく>、Perl の組み込みの値です。 |
8319 | 8523 | ローカル時刻ではなく GMT がほしい場合は L<C<gmtime>|/gmtime EXPR> 組み込み |
8320 | 8524 | 関数を使ってください。 |
8321 | 8525 | また、(秒、分、時などの形から、L<C<time>|/time> が返す値である |
8322 | 8526 | 1970 年 1 月 1 日の真夜中からの秒数に変換する) |
8323 | 8527 | L<C<Time::Local>|Time::Local> モジュール及び L<POSIX> モジュールで提供される |
8324 | 8528 | L<C<strftime>|POSIX/C<strftime>> と L<C<mktime>|POSIX/C<mktime>> 関数も |
8325 | 8529 | 参照してください。 |
8326 | 8530 | |
8327 | 8531 | =begin original |
8328 | 8532 | |
8329 | 8533 | To get somewhat similar but locale-dependent date strings, set up your |
8330 | 8534 | locale environment variables appropriately (please see L<perllocale>) and |
8331 | 8535 | try for example: |
8332 | 8536 | |
8333 | 8537 | =end original |
8334 | 8538 | |
8335 | 8539 | 似たような、しかしロケール依存の日付文字列がほしい場合は、 |
8336 | 8540 | ロケール環境変数を適切に設定して(L<perllocale> を参照してください)、 |
8337 | 8541 | 以下の例を試してください: |
8338 | 8542 | |
8339 | 8543 | use POSIX qw(strftime); |
8340 | 8544 | my $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime; |
8341 | 8545 | # or for GMT formatted appropriately for your locale: |
8342 | 8546 | my $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime; |
8343 | 8547 | |
8344 | 8548 | =begin original |
8345 | 8549 | |
8346 | 8550 | Note that C<%a> and C<%b>, the short forms of the day of the week |
8347 | 8551 | and the month of the year, may not necessarily be three characters wide. |
8348 | 8552 | |
8349 | 8553 | =end original |
8350 | 8554 | |
8351 | 8555 | 曜日と月の短い表現である C<%a> と C<%b> は、3 文字とは限らないことに |
8352 | 8556 | 注意してください。 |
8353 | 8557 | |
8354 | 8558 | =begin original |
8355 | 8559 | |
8356 | 8560 | The L<Time::gmtime> and L<Time::localtime> modules provide a convenient, |
8357 | 8561 | by-name access mechanism to the L<C<gmtime>|/gmtime EXPR> and |
8358 | 8562 | L<C<localtime>|/localtime EXPR> functions, respectively. |
8359 | 8563 | |
8360 | 8564 | =end original |
8361 | 8565 | |
8362 | 8566 | L<Time::gmtime> モジュールと L<Time::localtime> モジュールは、それぞれ |
8363 | 8567 | L<C<gmtime>|/gmtime EXPR> 関数と L<C<localtime>|/localtime EXPR> 関数に、 |
8364 | 8568 | 名前でアクセスする機構を提供する便利なモジュールです。 |
8365 | 8569 | |
8366 | 8570 | =begin original |
8367 | 8571 | |
8368 | 8572 | For a comprehensive date and time representation look at the |
8369 | 8573 | L<DateTime> module on CPAN. |
8370 | 8574 | |
8371 | 8575 | =end original |
8372 | 8576 | |
8373 | 8577 | 包括的な日付と時刻の表現については、CPAN の L<DateTime> モジュールを |
8374 | 8578 | 参照してください。 |
8375 | 8579 | |
8376 | 8580 | =begin original |
8377 | 8581 | |
8378 | 8582 | Portability issues: L<perlport/localtime>. |
8379 | 8583 | |
8380 | 8584 | =end original |
8381 | 8585 | |
8382 | 8586 | 移植性の問題: L<perlport/localtime>。 |
8383 | 8587 | |
8384 | 8588 | =item lock THING |
8385 | 8589 | X<lock> |
8386 | 8590 | |
8387 | 8591 | =for Pod::Functions +5.005 get a thread lock on a variable, subroutine, or method |
8388 | 8592 | |
8389 | 8593 | =begin original |
8390 | 8594 | |
8391 | 8595 | This function places an advisory lock on a shared variable or referenced |
8392 | 8596 | object contained in I<THING> until the lock goes out of scope. |
8393 | 8597 | |
8394 | 8598 | =end original |
8395 | 8599 | |
8396 | 8600 | この関数は I<THING> が含む共有変数またはリファレンスされたオブジェクトに、 |
8397 | 8601 | スコープから出るまでアドバイサリロックを掛けます. |
8398 | 8602 | |
8399 | 8603 | =begin original |
8400 | 8604 | |
8401 | 8605 | The value returned is the scalar itself, if the argument is a scalar, or a |
8402 | 8606 | reference, if the argument is a hash, array or subroutine. |
8403 | 8607 | |
8404 | 8608 | =end original |
8405 | 8609 | |
8406 | 8610 | 返される値は、引数がスカラならそのスカラ自身、引数がハッシュ、配列、 |
8407 | 8611 | サブルーチンならリファレンスです。 |
8408 | 8612 | |
8409 | 8613 | =begin original |
8410 | 8614 | |
8411 | 8615 | L<C<lock>|/lock THING> is a "weak keyword"; this means that if you've |
8412 | 8616 | defined a function |
8413 | 8617 | by this name (before any calls to it), that function will be called |
8414 | 8618 | instead. If you are not under C<use threads::shared> this does nothing. |
8415 | 8619 | See L<threads::shared>. |
8416 | 8620 | |
8417 | 8621 | =end original |
8418 | 8622 | |
8419 | 8623 | L<C<lock>|/lock THING> は「弱いキーワード」です; もしユーザーが(呼び出し前に) |
8420 | 8624 | この名前で関数を定義すると、定義された関数の方が呼び出されます。 |
8421 | 8625 | C<use threads::shared> の影響下でない場合は、これは何もしません。 |
8422 | 8626 | L<threads::shared> を参照してください。 |
8423 | 8627 | |
8424 | 8628 | =item log EXPR |
8425 | 8629 | X<log> X<logarithm> X<e> X<ln> X<base> |
8426 | 8630 | |
8427 | 8631 | =item log |
8428 | 8632 | |
8429 | 8633 | =for Pod::Functions retrieve the natural logarithm for a number |
8430 | 8634 | |
8431 | 8635 | =begin original |
8432 | 8636 | |
8433 | 8637 | Returns the natural logarithm (base I<e>) of EXPR. If EXPR is omitted, |
8434 | 8638 | returns the log of L<C<$_>|perlvar/$_>. To get the |
8435 | 8639 | log of another base, use basic algebra: |
8436 | 8640 | The base-N log of a number is equal to the natural log of that number |
8437 | 8641 | divided by the natural log of N. For example: |
8438 | 8642 | |
8439 | 8643 | =end original |
8440 | 8644 | |
8441 | 8645 | EXPR の (I<e> を底とする) 自然対数を返します。 |
8442 | 8646 | EXPR が省略されると、L<C<$_>|perlvar/$_> の対数を返します。 |
8443 | 8647 | 底の異なる対数を求めるためには、基礎代数を利用してください: |
8444 | 8648 | ある数の N を底とする対数は、その数の自然対数を N の自然対数で割ったものです。 |
8445 | 8649 | 例えば: |
8446 | 8650 | |
8447 | 8651 | sub log10 { |
8448 | 8652 | my $n = shift; |
8449 | 8653 | return log($n)/log(10); |
8450 | 8654 | } |
8451 | 8655 | |
8452 | 8656 | =begin original |
8453 | 8657 | |
8454 | 8658 | See also L<C<exp>|/exp EXPR> for the inverse operation. |
8455 | 8659 | |
8456 | 8660 | =end original |
8457 | 8661 | |
8458 | 8662 | 逆操作については L<C<exp>|/exp EXPR> を参照してください。 |
8459 | 8663 | |
8460 | 8664 | =item lstat FILEHANDLE |
8461 | 8665 | X<lstat> |
8462 | 8666 | |
8463 | 8667 | =item lstat EXPR |
8464 | 8668 | |
8465 | 8669 | =item lstat DIRHANDLE |
8466 | 8670 | |
8467 | 8671 | =item lstat |
8468 | 8672 | |
8469 | 8673 | =for Pod::Functions stat a symbolic link |
8470 | 8674 | |
8471 | 8675 | =begin original |
8472 | 8676 | |
8473 | 8677 | Does the same thing as the L<C<stat>|/stat FILEHANDLE> function |
8474 | 8678 | (including setting the special C<_> filehandle) but stats a symbolic |
8475 | 8679 | link instead of the file the symbolic link points to. If symbolic links |
8476 | 8680 | are unimplemented on your system, a normal L<C<stat>|/stat FILEHANDLE> |
8477 | 8681 | is done. For much more detailed information, please see the |
8478 | 8682 | documentation for L<C<stat>|/stat FILEHANDLE>. |
8479 | 8683 | |
8480 | 8684 | =end original |
8481 | 8685 | |
8482 | 8686 | (特別なファイルハンドルである C<_> の設定を含めて) |
8483 | 8687 | L<C<stat>|/stat FILEHANDLE> 関数と同じことをしますが、シンボリックリンクが |
8484 | 8688 | 指しているファイルではなく、シンボリックリンク自体の stat をとります。 |
8485 | 8689 | シンボリックリンクがシステムに実装されていないと、通常の |
8486 | 8690 | L<C<stat>|/stat FILEHANDLE> が行なわれます。 |
8487 | 8691 | さらにより詳細な情報については、L<C<stat>|/stat FILEHANDLE> の文書を |
8488 | 8692 | 参照してください。 |
8489 | 8693 | |
8490 | 8694 | =begin original |
8491 | 8695 | |
8492 | 8696 | If EXPR is omitted, stats L<C<$_>|perlvar/$_>. |
8493 | 8697 | |
8494 | 8698 | =end original |
8495 | 8699 | |
8496 | 8700 | EXPR が省略されると、L<C<$_>|perlvar/$_> の stat をとります。 |
8497 | 8701 | |
8498 | 8702 | =begin original |
8499 | 8703 | |
8500 | 8704 | Portability issues: L<perlport/lstat>. |
8501 | 8705 | |
8502 | 8706 | =end original |
8503 | 8707 | |
8504 | 8708 | 移植性の問題: L<perlport/lstat>。 |
8505 | 8709 | |
8506 | 8710 | =item m// |
8507 | 8711 | |
8508 | 8712 | =for Pod::Functions match a string with a regular expression pattern |
8509 | 8713 | |
8510 | 8714 | =begin original |
8511 | 8715 | |
8512 | 8716 | The match operator. See L<perlop/"Regexp Quote-Like Operators">. |
8513 | 8717 | |
8514 | 8718 | =end original |
8515 | 8719 | |
8516 | 8720 | マッチ演算子です。 |
8517 | 8721 | L<perlop/"Regexp Quote-Like Operators"> を参照してください。 |
8518 | 8722 | |
8519 | 8723 | =item map BLOCK LIST |
8520 | 8724 | X<map> |
8521 | 8725 | |
8522 | 8726 | =item map EXPR,LIST |
8523 | 8727 | |
8524 | 8728 | =for Pod::Functions apply a change to a list to get back a new list with the changes |
8525 | 8729 | |
8526 | 8730 | =begin original |
8527 | 8731 | |
8528 | 8732 | Evaluates the BLOCK or EXPR for each element of LIST (locally setting |
8529 | L<C<$_>|perlvar/$_> to each element) and | |
8733 | L<C<$_>|perlvar/$_> to each element) and composes a list of the results of | |
8530 | ||
8734 | each such evaluation. Each element of LIST may produce zero, one, or more | |
8531 | ||
8735 | elements in the generated list, so the number of elements in the generated | |
8532 | ||
8736 | list may differ from that in LIST. In scalar context, returns the total | |
8533 | ||
8737 | number of elements so generated. In list context, returns the generated list. | |
8534 | more elements in the returned value. | |
8535 | 8738 | |
8536 | 8739 | =end original |
8537 | 8740 | |
8538 | 8741 | LIST の個々の要素に対して、BLOCK か EXPR を評価し |
8539 | 8742 | (L<C<$_>|perlvar/$_> は、ローカルに個々の要素が設定されます) 、 |
8540 | それぞれの評価結果からなるリスト | |
8743 | それぞれの評価結果からなるリストを作ります。 | |
8744 | LIST の個々の要素によって作られる、生成されたリストの要素数は、 | |
8745 | 0 個の場合もあれば、複数の場合もあるので、 | |
8746 | 生成されたリストの要素数は LIST の要素数と異なるかも知れません。 | |
8541 | 8747 | スカラコンテキストでは、生成された要素の数を返します。 |
8542 | ||
8748 | リストコンテキストでは、生成されたリストを返します。 | |
8543 | 個々の要素によって作られる、返り値であるリストの要素数は、 | |
8544 | 0 個の場合もあれば、複数の場合もあります。 | |
8545 | 8749 | |
8546 | 8750 | my @chars = map(chr, @numbers); |
8547 | 8751 | |
8548 | 8752 | =begin original |
8549 | 8753 | |
8550 | 8754 | translates a list of numbers to the corresponding characters. |
8551 | 8755 | |
8552 | 8756 | =end original |
8553 | 8757 | |
8554 | 8758 | は、数のリストを対応する文字に変換します。 |
8555 | 8759 | |
8556 | 8760 | my @squares = map { $_ * $_ } @numbers; |
8557 | 8761 | |
8558 | 8762 | =begin original |
8559 | 8763 | |
8560 | 8764 | translates a list of numbers to their squared values. |
8561 | 8765 | |
8562 | 8766 | =end original |
8563 | 8767 | |
8564 | 8768 | これは数値のリストを、その 2 乗に変換します。 |
8565 | 8769 | |
8566 | 8770 | my @squares = map { $_ > 5 ? ($_ * $_) : () } @numbers; |
8567 | 8771 | |
8568 | 8772 | =begin original |
8569 | 8773 | |
8570 | 8774 | shows that number of returned elements can differ from the number of |
8571 | 8775 | input elements. To omit an element, return an empty list (). |
8572 | 8776 | This could also be achieved by writing |
8573 | 8777 | |
8574 | 8778 | =end original |
8575 | 8779 | |
8576 | 8780 | のように、返された要素の数が入力要素の数と異なる場合もあります。 |
8577 | 8781 | 要素を省略するには、空リスト () を返します。 |
8578 | 8782 | これは以下のように書くことでも達成できて |
8579 | 8783 | |
8580 | 8784 | my @squares = map { $_ * $_ } grep { $_ > 5 } @numbers; |
8581 | 8785 | |
8582 | 8786 | =begin original |
8583 | 8787 | |
8584 | 8788 | which makes the intention more clear. |
8585 | 8789 | |
8586 | 8790 | =end original |
8587 | 8791 | |
8588 | 8792 | この方が目的がよりはっきりします。 |
8589 | 8793 | |
8590 | 8794 | =begin original |
8591 | 8795 | |
8592 | 8796 | Map always returns a list, which can be |
8593 | 8797 | assigned to a hash such that the elements |
8594 | 8798 | become key/value pairs. See L<perldata> for more details. |
8595 | 8799 | |
8596 | 8800 | =end original |
8597 | 8801 | |
8598 | 8802 | map は常にリストを返し、要素がキー/値の組になるようなハッシュに |
8599 | 8803 | 代入できます。 |
8600 | 8804 | さらなる詳細については L<perldata> を参照してください。 |
8601 | 8805 | |
8602 | 8806 | my %hash = map { get_a_key_for($_) => $_ } @array; |
8603 | 8807 | |
8604 | 8808 | =begin original |
8605 | 8809 | |
8606 | 8810 | is just a funny way to write |
8607 | 8811 | |
8608 | 8812 | =end original |
8609 | 8813 | |
8610 | 8814 | は以下のものをちょっと変わった書き方で書いたものです。 |
8611 | 8815 | |
8612 | 8816 | my %hash; |
8613 | 8817 | foreach (@array) { |
8614 | 8818 | $hash{get_a_key_for($_)} = $_; |
8615 | 8819 | } |
8616 | 8820 | |
8617 | 8821 | =begin original |
8618 | 8822 | |
8619 | 8823 | Note that L<C<$_>|perlvar/$_> is an alias to the list value, so it can |
8620 | 8824 | be used to modify the elements of the LIST. While this is useful and |
8621 | 8825 | supported, it can cause bizarre results if the elements of LIST are not |
8622 | 8826 | variables. Using a regular C<foreach> loop for this purpose would be |
8623 | 8827 | clearer in most cases. See also L<C<grep>|/grep BLOCK LIST> for a |
8624 | 8828 | list composed of those items of the original list for which the BLOCK |
8625 | 8829 | or EXPR evaluates to true. |
8626 | 8830 | |
8627 | 8831 | =end original |
8628 | 8832 | |
8629 | 8833 | L<C<$_>|perlvar/$_> は、LIST の値へのエイリアスですので、LIST の要素を |
8630 | 8834 | 変更するために使うことができます。 |
8631 | 8835 | これは、便利でサポートされていますが、 |
8632 | 8836 | LIST の要素が変数でないと、おかしな結果になります。 |
8633 | 8837 | この目的には通常の C<foreach> ループを使うことで、ほとんどの場合は |
8634 | 8838 | より明確になります。 |
8635 | 8839 | BLOCK や EXPR が真になる元のリストの要素からなるリストについては、 |
8636 | 8840 | L<C<grep>|/grep BLOCK LIST> も参照してください。 |
8637 | 8841 | |
8638 | 8842 | =begin original |
8639 | 8843 | |
8640 | 8844 | C<{> starts both hash references and blocks, so C<map { ...> could be either |
8641 | 8845 | the start of map BLOCK LIST or map EXPR, LIST. Because Perl doesn't look |
8642 | 8846 | ahead for the closing C<}> it has to take a guess at which it's dealing with |
8643 | 8847 | based on what it finds just after the |
8644 | 8848 | C<{>. Usually it gets it right, but if it |
8645 | 8849 | doesn't it won't realize something is wrong until it gets to the C<}> and |
8646 | 8850 | encounters the missing (or unexpected) comma. The syntax error will be |
8647 | 8851 | reported close to the C<}>, but you'll need to change something near the C<{> |
8648 | 8852 | such as using a unary C<+> or semicolon to give Perl some help: |
8649 | 8853 | |
8650 | 8854 | =end original |
8651 | 8855 | |
8652 | 8856 | C<{> はハッシュリファレンスとブロックの両方の開始文字なので、 |
8653 | 8857 | C<map { ...> は map BLOCK LIST の場合と map EXPR, LIST の場合があります。 |
8654 | 8858 | Perl は終了文字の C<}> を先読みしないので、C<{> の直後の文字を見て |
8655 | 8859 | どちらとして扱うかを推測します。 |
8656 | 8860 | 通常この推測は正しいですが、もし間違った場合は、C<}> まで読み込んで |
8657 | 8861 | カンマが足りない(または多い)ことがわかるまで、何かがおかしいことに |
8658 | 8862 | 気付きません。 |
8659 | 8863 | C<}> の近くで文法エラーが出ますが、Perl を助けるために単項の C<+> や |
8660 | 8864 | セミコロンを使うというように、C<{> の近くの何かを変更する必要があります。 |
8661 | 8865 | |
8662 | 8866 | my %hash = map { "\L$_" => 1 } @array # perl guesses EXPR. wrong |
8663 | 8867 | my %hash = map { +"\L$_" => 1 } @array # perl guesses BLOCK. right |
8664 | 8868 | my %hash = map {; "\L$_" => 1 } @array # this also works |
8665 | 8869 | my %hash = map { ("\L$_" => 1) } @array # as does this |
8666 | 8870 | my %hash = map { lc($_) => 1 } @array # and this. |
8667 | 8871 | my %hash = map +( lc($_) => 1 ), @array # this is EXPR and works! |
8668 | 8872 | |
8669 | 8873 | my %hash = map ( lc($_), 1 ), @array # evaluates to (1, @array) |
8670 | 8874 | |
8671 | 8875 | =begin original |
8672 | 8876 | |
8673 | 8877 | or to force an anon hash constructor use C<+{>: |
8674 | 8878 | |
8675 | 8879 | =end original |
8676 | 8880 | |
8677 | 8881 | または C<+{> を使って無名ハッシュコンストラクタを強制します: |
8678 | 8882 | |
8679 | 8883 | my @hashes = map +{ lc($_) => 1 }, @array # EXPR, so needs |
8680 | 8884 | # comma at end |
8681 | 8885 | |
8682 | 8886 | =begin original |
8683 | 8887 | |
8684 | 8888 | to get a list of anonymous hashes each with only one entry apiece. |
8685 | 8889 | |
8686 | 8890 | =end original |
8687 | 8891 | |
8688 | 8892 | こうするとそれぞれ 1 要素だけの無名ハッシュのリストを得られます。 |
8689 | 8893 | |
8690 | =item mkdir FILENAME,M | |
8894 | =item mkdir FILENAME,MODE | |
8691 | 8895 | X<mkdir> X<md> X<directory, create> |
8692 | 8896 | |
8693 | 8897 | =item mkdir FILENAME |
8694 | 8898 | |
8695 | 8899 | =item mkdir |
8696 | 8900 | |
8697 | 8901 | =for Pod::Functions create a directory |
8698 | 8902 | |
8699 | 8903 | =begin original |
8700 | 8904 | |
8701 | 8905 | Creates the directory specified by FILENAME, with permissions |
8702 | specified by M | |
8906 | specified by MODE (as modified by L<C<umask>|/umask EXPR>). If it | |
8703 | 8907 | succeeds it returns true; otherwise it returns false and sets |
8704 | 8908 | L<C<$!>|perlvar/$!> (errno). |
8705 | M | |
8909 | MODE defaults to 0777 if omitted, and FILENAME defaults | |
8706 | 8910 | to L<C<$_>|perlvar/$_> if omitted. |
8707 | 8911 | |
8708 | 8912 | =end original |
8709 | 8913 | |
8710 | FILENAME で指定したディレクトリを、M | |
8914 | FILENAME で指定したディレクトリを、MODE で指定した許可モード(を | |
8711 | 8915 | L<C<umask>|/umask EXPR> で修正したもの) で作成します。 |
8712 | 8916 | 成功時には真を返します; さもなければ偽を返して |
8713 | 8917 | L<C<$!>|perlvar/$!> (errno) を設定します。 |
8714 | M | |
8918 | MODE を省略すると、0777 とみなし、 | |
8715 | 8919 | FILENAME を省略すると、L<C<$_>|perlvar/$_> を使います。 |
8716 | 8920 | |
8717 | 8921 | =begin original |
8718 | 8922 | |
8719 | In general, it is better to create directories with a permissive M | |
8923 | In general, it is better to create directories with a permissive MODE | |
8720 | 8924 | and let the user modify that with their L<C<umask>|/umask EXPR> than it |
8721 | 8925 | is to supply |
8722 | a restrictive M | |
8926 | a restrictive MODE and give the user no way to be more permissive. | |
8723 | 8927 | The exceptions to this rule are when the file or directory should be |
8724 | 8928 | kept private (mail files, for instance). The documentation for |
8725 | L<C<umask>|/umask EXPR> discusses the choice of M | |
8929 | L<C<umask>|/umask EXPR> discusses the choice of MODE in more detail. | |
8726 | 8930 | |
8727 | 8931 | =end original |
8728 | 8932 | |
8729 | 一般的に、制限された M | |
8933 | 一般的に、制限された MODE を使ってユーザーがより寛容にする方法を | |
8730 | 与えないより、寛容な M | |
8934 | 与えないより、寛容な MODE でディレクトリを作り、ユーザーが自身の | |
8731 | 8935 | L<C<umask>|/umask EXPR> で修正するようにした方がよいです。 |
8732 | 8936 | 例外は、(例えばメールファイルのような)プライベートに保つべきファイルや |
8733 | 8937 | ディレクトリを書く場合です。 |
8734 | L<C<umask>|/umask EXPR> の文書で、M | |
8938 | L<C<umask>|/umask EXPR> の文書で、MODE の選択に関して詳細に議論しています。 | |
8735 | 8939 | |
8736 | 8940 | =begin original |
8737 | 8941 | |
8738 | 8942 | Note that according to the POSIX 1003.1-1996 the FILENAME may have any |
8739 | 8943 | number of trailing slashes. Some operating and filesystems do not get |
8740 | 8944 | this right, so Perl automatically removes all trailing slashes to keep |
8741 | 8945 | everyone happy. |
8742 | 8946 | |
8743 | 8947 | =end original |
8744 | 8948 | |
8745 | 8949 | POSIX 1003.1-1996 によれば、FILENAME には末尾に任意の数のスラッシュを |
8746 | 8950 | つけることができます。 |
8747 | 8951 | このようには動かない OS やファイルシステムもあるので、Perl はみんなが |
8748 | 8952 | 幸せになれるように、自動的に末尾のスラッシュを削除します。 |
8749 | 8953 | |
8750 | 8954 | =begin original |
8751 | 8955 | |
8752 | 8956 | To recursively create a directory structure, look at |
8753 | 8957 | the L<C<make_path>|File::Path/make_path( $dir1, $dir2, .... )> function |
8754 | 8958 | of the L<File::Path> module. |
8755 | 8959 | |
8756 | 8960 | =end original |
8757 | 8961 | |
8758 | 8962 | ディレクトリ構造を再帰的に作成するには、L<File::Path> モジュールの |
8759 | 8963 | L<C<make_path>|File::Path/make_path( $dir1, $dir2, .... )> 関数を |
8760 | 8964 | 参照してください。 |
8761 | 8965 | |
8762 | 8966 | =item msgctl ID,CMD,ARG |
8763 | 8967 | X<msgctl> |
8764 | 8968 | |
8765 | 8969 | =for Pod::Functions SysV IPC message control operations |
8766 | 8970 | |
8767 | 8971 | =begin original |
8768 | 8972 | |
8769 | 8973 | Calls the System V IPC function L<msgctl(2)>. You'll probably have to say |
8770 | 8974 | |
8771 | 8975 | =end original |
8772 | 8976 | |
8773 | 8977 | System V IPC 関数 L<msgctl(2)> を呼び出します。 |
8774 | 8978 | 正しい定数定義を得るために、まず |
8775 | 8979 | |
8776 | 8980 | use IPC::SysV; |
8777 | 8981 | |
8778 | 8982 | =begin original |
8779 | 8983 | |
8780 | 8984 | first to get the correct constant definitions. If CMD is C<IPC_STAT>, |
8781 | 8985 | then ARG must be a variable that will hold the returned C<msqid_ds> |
8782 | 8986 | structure. Returns like L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>: |
8783 | 8987 | the undefined value for error, C<"0 but true"> for zero, or the actual |
8784 | 8988 | return value otherwise. See also L<perlipc/"SysV IPC"> and the |
8785 | 8989 | documentation for L<C<IPC::SysV>|IPC::SysV> and |
8786 | 8990 | L<C<IPC::Semaphore>|IPC::Semaphore>. |
8787 | 8991 | |
8788 | 8992 | =end original |
8789 | 8993 | |
8790 | 8994 | と書くことが必要でしょう。 |
8791 | 8995 | CMD が C<IPC_STAT> であれば、ARG は返される C<msqid_ds> 構造体を |
8792 | 8996 | 納める変数でなければなりません。 |
8793 | 8997 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同じように、エラー時には |
8794 | 8998 | 未定義値、ゼロのときは C<"0 but true">、それ以外なら、その値そのものを |
8795 | 8999 | 返します。 |
8796 | 9000 | L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>, |
8797 | 9001 | L<C<IPC::Semaphore>|IPC::Semaphore> の文書も参照してください。 |
8798 | 9002 | |
8799 | 9003 | =begin original |
8800 | 9004 | |
8801 | 9005 | Portability issues: L<perlport/msgctl>. |
8802 | 9006 | |
8803 | 9007 | =end original |
8804 | 9008 | |
8805 | 9009 | 移植性の問題: L<perlport/msgctl>。 |
8806 | 9010 | |
8807 | 9011 | =item msgget KEY,FLAGS |
8808 | 9012 | X<msgget> |
8809 | 9013 | |
8810 | 9014 | =for Pod::Functions get SysV IPC message queue |
8811 | 9015 | |
8812 | 9016 | =begin original |
8813 | 9017 | |
8814 | 9018 | Calls the System V IPC function L<msgget(2)>. Returns the message queue |
8815 | 9019 | id, or L<C<undef>|/undef EXPR> on error. See also L<perlipc/"SysV IPC"> |
8816 | 9020 | and the documentation for L<C<IPC::SysV>|IPC::SysV> and |
8817 | 9021 | L<C<IPC::Msg>|IPC::Msg>. |
8818 | 9022 | |
8819 | 9023 | =end original |
8820 | 9024 | |
8821 | 9025 | System V IPC 関数 L<msgget(2)> を呼び出します。 |
8822 | 9026 | メッセージキューの ID か、エラー時には L<C<undef>|/undef EXPR> を返します。 |
8823 | 9027 | L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>, |
8824 | 9028 | L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。 |
8825 | 9029 | |
8826 | 9030 | =begin original |
8827 | 9031 | |
8828 | 9032 | Portability issues: L<perlport/msgget>. |
8829 | 9033 | |
8830 | 9034 | =end original |
8831 | 9035 | |
8832 | 9036 | 移植性の問題: L<perlport/msgget>。 |
8833 | 9037 | |
8834 | 9038 | =item msgrcv ID,VAR,SIZE,TYPE,FLAGS |
8835 | 9039 | X<msgrcv> |
8836 | 9040 | |
8837 | 9041 | =for Pod::Functions receive a SysV IPC message from a message queue |
8838 | 9042 | |
8839 | 9043 | =begin original |
8840 | 9044 | |
8841 | 9045 | Calls the System V IPC function msgrcv to receive a message from |
8842 | 9046 | message queue ID into variable VAR with a maximum message size of |
8843 | 9047 | SIZE. Note that when a message is received, the message type as a |
8844 | 9048 | native long integer will be the first thing in VAR, followed by the |
8845 | 9049 | actual message. This packing may be opened with C<unpack("l! a*")>. |
8846 | 9050 | Taints the variable. Returns true if successful, false |
8847 | 9051 | on error. See also L<perlipc/"SysV IPC"> and the documentation for |
8848 | 9052 | L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Msg>|IPC::Msg>. |
8849 | 9053 | |
8850 | 9054 | =end original |
8851 | 9055 | |
8852 | 9056 | System V IPC 関数 msgrcv を呼び出し、メッセージキュー ID から、 |
8853 | 9057 | 変数 VAR に最大メッセージ長 SIZE のメッセージを受信します。 |
8854 | 9058 | メッセージが受信された時、ネイティブな long 整数のメッセージタイプが |
8855 | 9059 | VAR の先頭となり、実際のメッセージが続きます。 |
8856 | 9060 | このパッキングは C<unpack("l! a*")> で展開できます。 |
8857 | 9061 | 変数は汚染されます。 |
8858 | 9062 | 成功時には真を、エラー時には偽を返します。 |
8859 | 9063 | L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>, |
8860 | 9064 | L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。 |
8861 | 9065 | |
8862 | 9066 | =begin original |
8863 | 9067 | |
8864 | 9068 | Portability issues: L<perlport/msgrcv>. |
8865 | 9069 | |
8866 | 9070 | =end original |
8867 | 9071 | |
8868 | 9072 | 移植性の問題: L<perlport/msgrcv>。 |
8869 | 9073 | |
8870 | 9074 | =item msgsnd ID,MSG,FLAGS |
8871 | 9075 | X<msgsnd> |
8872 | 9076 | |
8873 | 9077 | =for Pod::Functions send a SysV IPC message to a message queue |
8874 | 9078 | |
8875 | 9079 | =begin original |
8876 | 9080 | |
8877 | 9081 | Calls the System V IPC function msgsnd to send the message MSG to the |
8878 | 9082 | message queue ID. MSG must begin with the native long integer message |
8879 | 9083 | type, be followed by the length of the actual message, and then finally |
8880 | 9084 | the message itself. This kind of packing can be achieved with |
8881 | 9085 | C<pack("l! a*", $type, $message)>. Returns true if successful, |
8882 | 9086 | false on error. See also L<perlipc/"SysV IPC"> and the documentation |
8883 | 9087 | for L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Msg>|IPC::Msg>. |
8884 | 9088 | |
8885 | 9089 | =end original |
8886 | 9090 | |
8887 | 9091 | System V IPC 関数 msgsnd を呼び出し、メッセージキュー ID に |
8888 | 9092 | メッセージ MSG を送信します。 |
8889 | 9093 | MSG の先頭は、ネイティブな long 整数のメッセージタイプでなければならず、 |
8890 | 9094 | メッセージの長さ、メッセージ本体と続きます。 |
8891 | 9095 | これは、C<pack("l! a*", $type, $message)> として生成できます。 |
8892 | 9096 | 成功時には真を、エラー時には偽を返します。 |
8893 | 9097 | L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>, |
8894 | 9098 | L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。 |
8895 | 9099 | |
8896 | 9100 | =begin original |
8897 | 9101 | |
8898 | 9102 | Portability issues: L<perlport/msgsnd>. |
8899 | 9103 | |
8900 | 9104 | =end original |
8901 | 9105 | |
8902 | 9106 | 移植性の問題: L<perlport/msgsnd>。 |
8903 | 9107 | |
8904 | 9108 | =item my VARLIST |
8905 | 9109 | X<my> |
8906 | 9110 | |
8907 | 9111 | =item my TYPE VARLIST |
8908 | 9112 | |
8909 | 9113 | =item my VARLIST : ATTRS |
8910 | 9114 | |
8911 | 9115 | =item my TYPE VARLIST : ATTRS |
8912 | 9116 | |
8913 | 9117 | =for Pod::Functions declare and assign a local variable (lexical scoping) |
8914 | 9118 | |
8915 | 9119 | =begin original |
8916 | 9120 | |
8917 | 9121 | A L<C<my>|/my VARLIST> declares the listed variables to be local |
8918 | 9122 | (lexically) to the enclosing block, file, or L<C<eval>|/eval EXPR>. If |
8919 | 9123 | more than one variable is listed, the list must be placed in |
8920 | 9124 | parentheses. |
8921 | 9125 | |
8922 | 9126 | =end original |
8923 | 9127 | |
8924 | 9128 | L<C<my>|/my VARLIST> はリストアップされた変数を、囲っているブロック、ファイル、 |
8925 | 9129 | L<C<eval>|/eval EXPR> の中でローカルな (レキシカルな) ものにします。 |
8926 | 9130 | 複数の変数を指定する場合は、リストはかっこでくくらなければなりません。 |
8927 | 9131 | |
8928 | 9132 | =begin original |
8929 | 9133 | |
8930 | 9134 | The exact semantics and interface of TYPE and ATTRS are still |
8931 | 9135 | evolving. TYPE may be a bareword, a constant declared |
8932 | 9136 | with L<C<use constant>|constant>, or L<C<__PACKAGE__>|/__PACKAGE__>. It |
8933 | 9137 | is |
8934 | 9138 | currently bound to the use of the L<fields> pragma, |
8935 | 9139 | and attributes are handled using the L<attributes> pragma, or starting |
8936 | 9140 | from Perl 5.8.0 also via the L<Attribute::Handlers> module. See |
8937 | 9141 | L<perlsub/"Private Variables via my()"> for details. |
8938 | 9142 | |
8939 | 9143 | =end original |
8940 | 9144 | |
8941 | 9145 | TYPE と ATTRS の正確な文法とインターフェースは今でも進化しています。 |
8942 | 9146 | TYPE は、裸の単語、L<C<use constant>|constant> で宣言された定数、 |
8943 | 9147 | L<C<__PACKAGE__>|/__PACKAGE__> のいずれかです。 |
8944 | 9148 | 現在のところ、TYPE は L<fields> プラグマの使用と結び付けられていて、 |
8945 | 9149 | 属性は L<attributes> プラグマか、Perl 5.8.0 からは |
8946 | 9150 | L<Attribute::Handlers> モジュールと結び付けられています。 |
8947 | 9151 | 詳しくは L<perlsub/"Private Variables via my()"> を参照してください。 |
8948 | 9152 | |
8949 | 9153 | =begin original |
8950 | 9154 | |
8951 | 9155 | Note that with a parenthesised list, L<C<undef>|/undef EXPR> can be used |
8952 | 9156 | as a dummy placeholder, for example to skip assignment of initial |
8953 | 9157 | values: |
8954 | 9158 | |
8955 | 9159 | =end original |
8956 | 9160 | |
8957 | 9161 | かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> は、例えば初期値の代入を |
8958 | 9162 | 飛ばすために、ダミーのプレースホルダとして使えることに注意してください: |
8959 | 9163 | |
8960 | 9164 | my ( undef, $min, $hour ) = localtime; |
8961 | 9165 | |
8962 | 9166 | =item next LABEL |
8963 | 9167 | X<next> X<continue> |
8964 | 9168 | |
8965 | 9169 | =item next EXPR |
8966 | 9170 | |
8967 | 9171 | =item next |
8968 | 9172 | |
8969 | 9173 | =for Pod::Functions iterate a block prematurely |
8970 | 9174 | |
8971 | 9175 | =begin original |
8972 | 9176 | |
8973 | 9177 | The L<C<next>|/next LABEL> command is like the C<continue> statement in |
8974 | 9178 | C; it starts the next iteration of the loop: |
8975 | 9179 | |
8976 | 9180 | =end original |
8977 | 9181 | |
8978 | 9182 | L<C<next>|/next LABEL> コマンドは、C での C<continue> 文のようなもので、 |
8979 | 9183 | ループの次の繰り返しを開始します: |
8980 | 9184 | |
8981 | 9185 | LINE: while (<STDIN>) { |
8982 | 9186 | next LINE if /^#/; # discard comments |
8983 | 9187 | #... |
8984 | 9188 | } |
8985 | 9189 | |
8986 | 9190 | =begin original |
8987 | 9191 | |
8988 | 9192 | Note that if there were a L<C<continue>|/continue BLOCK> block on the |
8989 | 9193 | above, it would get |
8990 | 9194 | executed even on discarded lines. If LABEL is omitted, the command |
8991 | 9195 | refers to the innermost enclosing loop. The C<next EXPR> form, available |
8992 | 9196 | as of Perl 5.18.0, allows a label name to be computed at run time, being |
8993 | 9197 | otherwise identical to C<next LABEL>. |
8994 | 9198 | |
8995 | 9199 | =end original |
8996 | 9200 | |
8997 | 9201 | L<C<continue>|/continue BLOCK> ブロックが存在すれば、たとえ捨てられる行に |
8998 | 9202 | あっても、それが実行されます。 |
8999 | 9203 | LABEL が省略されると、コマンドは一番内側のループを参照します。 |
9000 | 9204 | Perl 5.18.0 から利用可能な C<next EXPR> 形式では、実行時に計算される |
9001 | 9205 | ラベル名が使えます; それ以外は C<next LABEL> と同一です。 |
9002 | 9206 | |
9003 | 9207 | =begin original |
9004 | 9208 | |
9005 | L<C<next>|/next LABEL> cannot | |
9209 | L<C<next>|/next LABEL> cannot return a value from a block that typically | |
9006 | value such as C<eval {}>, C<sub {}>, or C<do {}> | |
9210 | returns a value, such as C<eval {}>, C<sub {}>, or C<do {}>. It will perform | |
9007 | to e | |
9211 | its flow control behavior, which precludes any return value. It should not be | |
9212 | used to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST> | |
9008 | 9213 | operation. |
9009 | 9214 | |
9010 | 9215 | =end original |
9011 | 9216 | |
9012 | L<C<next>|/next LABEL> は C<eval {}>, C<sub {}>, C<do {}> | |
9217 | L<C<next>|/next LABEL> は C<eval {}>, C<sub {}>, C<do {}> といった | |
9013 | ブロックから | |
9218 | 典型的には値を返すブロックから値を返せません。 | |
9014 | ||
9219 | これは、返り値を不可能にするフロー制御の振る舞いを実行します。 | |
9220 | L<C<grep>|/grep BLOCK LIST> や L<C<map>|/map BLOCK LIST> 操作を終了するのに | |
9221 | 使うべきではありません。 | |
9015 | 9222 | |
9016 | 9223 | =begin original |
9017 | 9224 | |
9018 | 9225 | Note that a block by itself is semantically identical to a loop |
9019 | 9226 | that executes once. Thus L<C<next>|/next LABEL> will exit such a block |
9020 | 9227 | early. |
9021 | 9228 | |
9022 | 9229 | =end original |
9023 | 9230 | |
9024 | 9231 | ブロック自身は一回だけ実行されるループと文法的に同一であることに |
9025 | 9232 | 注意してください。 |
9026 | 9233 | 従って、L<C<next>|/next LABEL> はそのようなブロックから早く抜けるのに使えます。 |
9027 | 9234 | |
9028 | 9235 | =begin original |
9029 | 9236 | |
9030 | 9237 | See also L<C<continue>|/continue BLOCK> for an illustration of how |
9031 | 9238 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and |
9032 | 9239 | L<C<redo>|/redo LABEL> work. |
9033 | 9240 | |
9034 | 9241 | =end original |
9035 | 9242 | |
9036 | 9243 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL> が |
9037 | 9244 | どのように働くかについては L<C<continue>|/continue BLOCK> も参照してください。 |
9038 | 9245 | |
9039 | 9246 | =begin original |
9040 | 9247 | |
9041 | 9248 | Unlike most named operators, this has the same precedence as assignment. |
9042 | 9249 | It is also exempt from the looks-like-a-function rule, so |
9043 | 9250 | C<next ("foo")."bar"> will cause "bar" to be part of the argument to |
9044 | 9251 | L<C<next>|/next LABEL>. |
9045 | 9252 | |
9046 | 9253 | =end original |
9047 | 9254 | |
9048 | 9255 | ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 |
9049 | 9256 | また、関数のように見えるものの規則からも免れるので、C<next ("foo")."bar"> と |
9050 | 9257 | すると "bar" は L<C<next>|/next LABEL> への引数の一部となります。 |
9051 | 9258 | |
9052 | 9259 | =item no MODULE VERSION LIST |
9053 | 9260 | X<no declarations> |
9054 | 9261 | X<unimporting> |
9055 | 9262 | |
9056 | 9263 | =item no MODULE VERSION |
9057 | 9264 | |
9058 | 9265 | =item no MODULE LIST |
9059 | 9266 | |
9060 | 9267 | =item no MODULE |
9061 | 9268 | |
9062 | 9269 | =item no VERSION |
9063 | 9270 | |
9064 | 9271 | =for Pod::Functions unimport some module symbols or semantics at compile time |
9065 | 9272 | |
9066 | 9273 | =begin original |
9067 | 9274 | |
9068 | 9275 | See the L<C<use>|/use Module VERSION LIST> function, of which |
9069 | 9276 | L<C<no>|/no MODULE VERSION LIST> is the opposite. |
9070 | 9277 | |
9071 | 9278 | =end original |
9072 | 9279 | |
9073 | 9280 | L<C<use>|/use Module VERSION LIST> 関数を参照してください; |
9074 | 9281 | L<C<no>|/no MODULE VERSION LIST> は、その逆を行なうものです。 |
9075 | 9282 | |
9076 | 9283 | =item oct EXPR |
9077 | 9284 | X<oct> X<octal> X<hex> X<hexadecimal> X<binary> X<bin> |
9078 | 9285 | |
9079 | 9286 | =item oct |
9080 | 9287 | |
9081 | 9288 | =for Pod::Functions convert a string to an octal number |
9082 | 9289 | |
9083 | 9290 | =begin original |
9084 | 9291 | |
9085 | 9292 | Interprets EXPR as an octal string and returns the corresponding |
9086 | 9293 | value. (If EXPR happens to start off with C<0x>, interprets it as a |
9087 | 9294 | hex string. If EXPR starts off with C<0b>, it is interpreted as a |
9088 | 9295 | binary string. Leading whitespace is ignored in all three cases.) |
9089 | 9296 | The following will handle decimal, binary, octal, and hex in standard |
9090 | 9297 | Perl notation: |
9091 | 9298 | |
9092 | 9299 | =end original |
9093 | 9300 | |
9094 | 9301 | EXPR を 8 進数文字列と解釈して、対応する値を返します。 |
9095 | 9302 | (EXPR が C<0x> で始まるときには、16 進数文字列と解釈します。 |
9096 | 9303 | EXPR が C<0b>で始まるときは、2 進数文字列と解釈します。 |
9097 | 9304 | どの場合でも、先頭の空白は無視されます。) |
9098 | 9305 | 以下の例は、標準的な Perl の記法での |
9099 | 9306 | 10 進数、2 進数、8 進数、16 進数を扱います: |
9100 | 9307 | |
9101 | 9308 | $val = oct($val) if $val =~ /^0/; |
9102 | 9309 | |
9103 | 9310 | =begin original |
9104 | 9311 | |
9105 | 9312 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. To go the other way |
9106 | 9313 | (produce a number in octal), use L<C<sprintf>|/sprintf FORMAT, LIST> or |
9107 | 9314 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST>: |
9108 | 9315 | |
9109 | 9316 | =end original |
9110 | 9317 | |
9111 | 9318 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 |
9112 | 9319 | (8 進数を扱う)その他の方法をとしては L<C<sprintf>|/sprintf FORMAT, LIST> や |
9113 | 9320 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST> があります: |
9114 | 9321 | |
9115 | 9322 | my $dec_perms = (stat("filename"))[2] & 07777; |
9116 | 9323 | my $oct_perm_str = sprintf "%o", $perms; |
9117 | 9324 | |
9118 | 9325 | =begin original |
9119 | 9326 | |
9120 | 9327 | The L<C<oct>|/oct EXPR> function is commonly used when a string such as |
9121 | 9328 | C<644> needs |
9122 | 9329 | to be converted into a file mode, for example. Although Perl |
9123 | 9330 | automatically converts strings into numbers as needed, this automatic |
9124 | 9331 | conversion assumes base 10. |
9125 | 9332 | |
9126 | 9333 | =end original |
9127 | 9334 | |
9128 | 9335 | L<C<oct>|/oct EXPR> 関数は例えば、 C<644> といった文字列をファイルモードに |
9129 | 9336 | 変換する時によく使います。 |
9130 | 9337 | Perl は必要に応じて自動的に文字列を数値に変換しますが、 |
9131 | 9338 | この自動変換は十進数を仮定します。 |
9132 | 9339 | |
9133 | 9340 | =begin original |
9134 | 9341 | |
9135 | 9342 | Leading white space is ignored without warning, as too are any trailing |
9136 | 9343 | non-digits, such as a decimal point (L<C<oct>|/oct EXPR> only handles |
9137 | 9344 | non-negative integers, not negative integers or floating point). |
9138 | 9345 | |
9139 | 9346 | =end original |
9140 | 9347 | |
9141 | 9348 | 先頭の空白や、末尾の(小数点のような)非数字は警告なしに無視されます |
9142 | 9349 | (L<C<oct>|/oct EXPR> は非負整数のみを扱えます; 負の整数や小数は扱えません)。 |
9143 | 9350 | |
9144 | =item open FILEHANDLE,EXPR | |
9145 | X<open> X<pipe> X<file, open> X<fopen> | |
9146 | 9351 | |
9147 | 9352 | =item open FILEHANDLE,MODE,EXPR |
9353 | X<open> X<pipe> X<file, open> X<fopen> | |
9148 | 9354 | |
9149 | 9355 | =item open FILEHANDLE,MODE,EXPR,LIST |
9150 | 9356 | |
9151 | 9357 | =item open FILEHANDLE,MODE,REFERENCE |
9152 | 9358 | |
9359 | =item open FILEHANDLE,EXPR | |
9360 | ||
9153 | 9361 | =item open FILEHANDLE |
9154 | 9362 | |
9155 | 9363 | =for Pod::Functions open a file, pipe, or descriptor |
9156 | 9364 | |
9157 | 9365 | =begin original |
9158 | 9366 | |
9159 | ||
9367 | Associates an internal FILEHANDLE with the external file specified by | |
9160 | ||
9368 | EXPR. That filehandle will subsequently allow you to perform | |
9369 | I/O operations on that file, such as reading from it or writing to it. | |
9161 | 9370 | |
9162 | 9371 | =end original |
9163 | 9372 | |
9164 | ||
9373 | 内部の FILEHANDLE を、EXPR で指定された外部ファイルに関連付けます。 | |
9374 | このファイルハンドルはその後、読んだり書いたりといったそのファイルへの | |
9375 | I/O 操作をできるようにします。 | |
9165 | 9376 | |
9166 | 9377 | =begin original |
9167 | 9378 | |
9168 | ||
9379 | Instead of a filename, you may specify an external command | |
9380 | (plus an optional argument list) or a scalar reference, in order to open | |
9381 | filehandles on commands or in-memory scalars, respectively. | |
9169 | 9382 | |
9170 | 9383 | =end original |
9171 | 9384 | |
9172 | ||
9385 | ファイル名の代わりに、コマンドやメモリ内スカラへのファイルハンドルを | |
9386 | 開くために、外部コマンド (とオプションの引数リスト) やスカラリファレンスを | |
9387 | 指定できます。 | |
9173 | 9388 | |
9389 | =begin original | |
9390 | ||
9391 | A thorough reference to C<open> follows. For a gentler introduction to | |
9392 | the basics of C<open>, see also the L<perlopentut> manual page. | |
9393 | ||
9394 | =end original | |
9395 | ||
9396 | C<open> の完全なリファレンスは後述します。 | |
9397 | C<open> の基本に関するより親切な導入に関しては、 | |
9398 | L<perlopentut> man ページも参照してください。 | |
9399 | ||
9400 | =over | |
9401 | ||
9402 | =item Working with files | |
9403 | ||
9404 | =begin original | |
9405 | ||
9406 | Most often, C<open> gets invoked with three arguments: the required | |
9407 | FILEHANDLE (usually an empty scalar variable), followed by MODE (usually | |
9408 | a literal describing the I/O mode the filehandle will use), and then the | |
9409 | filename that the new filehandle will refer to. | |
9410 | ||
9411 | =end original | |
9412 | ||
9413 | ほとんどの場合、C<open> は 3 引数で起動されます: | |
9414 | 必須の FILEHANDLE (通常は空のスカラ変数), 引き続いて MODE (通常は | |
9415 | ファイルハンドルを使う I/O モードを記述するリテラル)、 | |
9416 | それから新しいファイルハンドルが参照するファイル名です。 | |
9417 | ||
9418 | =over | |
9419 | ||
9420 | =item Simple examples | |
9421 | ||
9422 | (単純な例) | |
9423 | ||
9424 | =begin original | |
9425 | ||
9426 | Reading from a file: | |
9427 | ||
9428 | =end original | |
9429 | ||
9430 | ファイルからの読み込み: | |
9431 | ||
9174 | 9432 | open(my $fh, "<", "input.txt") |
9175 | ||
9433 | or die "Can't open < input.txt: $!"; | |
9176 | 9434 | |
9435 | # Process every line in input.txt | |
9436 | while (my $line = <$fh>) { | |
9437 | # | |
9438 | # ... do something interesting with $line here ... | |
9439 | # | |
9440 | } | |
9441 | ||
9177 | 9442 | =begin original |
9178 | 9443 | |
9179 | ||
9444 | or writing to one: | |
9180 | 9445 | |
9181 | 9446 | =end original |
9182 | 9447 | |
9183 | 書き込み | |
9448 | そして書き込み: | |
9184 | 9449 | |
9185 | 9450 | open(my $fh, ">", "output.txt") |
9186 | ||
9451 | or die "Can't open > output.txt: $!"; | |
9187 | 9452 | |
9453 | print $fh "This line gets printed into output.txt.\n"; | |
9454 | ||
9188 | 9455 | =begin original |
9189 | 9456 | |
9190 | ||
9457 | For a summary of common filehandle operations such as these, see | |
9191 | L< | |
9458 | L<perlintro/Files and I/O>. | |
9192 | consider L<perlopentut>.) | |
9193 | 9459 | |
9194 | 9460 | =end original |
9195 | 9461 | |
9196 | ||
9462 | このような基本的なファイルハンドル操作の要約については、 | |
9197 | ||
9463 | L<perlintro/Files and I/O> を参照してください。 | |
9198 | 9464 | |
9465 | =item About filehandles | |
9466 | ||
9467 | (ファイルハンドルについて) | |
9468 | ||
9199 | 9469 | =begin original |
9200 | 9470 | |
9201 | ||
9471 | The first argument to C<open>, labeled FILEHANDLE in this reference, is | |
9202 | ||
9472 | usually a scalar variable. (Exceptions exist, described in "Other | |
9203 | ||
9473 | considerations", below.) If the call to C<open> succeeds, then the | |
9204 | ||
9474 | expression provided as FILEHANDLE will get assigned an open | |
9205 | ||
9475 | I<filehandle>. That filehandle provides an internal reference to the | |
9206 | i | |
9476 | specified external file, conveniently stored in a Perl variable, and | |
9477 | ready for I/O operations such as reading and writing. | |
9207 | 9478 | |
9208 | 9479 | =end original |
9209 | 9480 | |
9210 | FILEHANDLE | |
9481 | このリファレンスでは FILEHANDLE というラベルが付いている、 | |
9211 | ||
9482 | C<open> の最初の引数は、通常はスカラ変数です。 | |
9212 | ||
9483 | (例外があります; 後述する "Other considerations" で記述されます。) | |
9213 | ||
9484 | C<open> の呼び出しが成功すると、 | |
9214 | ||
9485 | FILEHANDLE として提供された式には、 | |
9215 | ||
9486 | 開いた I<ファイルハンドル> が代入されます。 | |
9216 | ||
9487 | このファイルハンドルは指定された外部ファイルへの内部参照を提供し、 | |
9488 | 好都合なように Perl 変数に保管し、読み書きのような I/O 操作の準備をします。 | |
9217 | 9489 | |
9490 | =item About modes | |
9491 | ||
9492 | (モードについて) | |
9493 | ||
9218 | 9494 | =begin original |
9219 | 9495 | |
9220 | ||
9496 | When calling C<open> with three or more arguments, the second argument | |
9221 | ||
9497 | -- labeled MODE here -- defines the I<open mode>. MODE is usually a | |
9222 | t | |
9498 | literal string comprising special characters that define the intended | |
9499 | I/O role of the filehandle being created: whether it's read-only, or | |
9500 | read-and-write, and so on. | |
9501 | ||
9502 | =end original | |
9503 | ||
9504 | 3 引数以上で C<open> を呼び出すとき、 | |
9505 | 2 番目の引数 -- ここでは MODE -- は I<開くモード> を定義します。 | |
9506 | MODE は普通、作られるファイルハンドルが意図している I/O の役割 (読み込み専用、 | |
9507 | 読み書き、など)を定義する特別な文字で構成されるリテラルな文字列です。 | |
9508 | ||
9509 | =begin original | |
9510 | ||
9511 | If MODE is C<< < >>, the file is opened for input (read-only). | |
9223 | 9512 | If MODE is C<< > >>, the file is opened for output, with existing files |
9224 | 9513 | first being truncated ("clobbered") and nonexisting files newly created. |
9225 | 9514 | If MODE is C<<< >> >>>, the file is opened for appending, again being |
9226 | 9515 | created if necessary. |
9227 | 9516 | |
9228 | 9517 | =end original |
9229 | 9518 | |
9230 | ||
9519 | MODE が C<< < >> の場合、ファイルは入力用(読み込み専用)に開かれます。 | |
9231 | エンコーディングを含む)開く時のモードは、3 番目のファイル名と分離されます。 | |
9232 | MODE が C<< < >> か空の場合、ファイルは入力用に開かれます。 | |
9233 | 9520 | MODE が C<< > >> の場合、ファイルは出力用に開かれ、既にファイルが |
9234 | 9521 | ある場合は切り詰められ(上書きされ)、ない場合は新しく作られます。 |
9235 | 9522 | MODE が C<<< >> >>> の場合、ファイルは追加用に開かれ、やはり必要なら |
9236 | 9523 | 作成されます。 |
9237 | 9524 | |
9238 | 9525 | =begin original |
9239 | 9526 | |
9240 | 9527 | You can put a C<+> in front of the C<< > >> or C<< < >> to |
9241 | 9528 | indicate that you want both read and write access to the file; thus |
9242 | 9529 | C<< +< >> is almost always preferred for read/write updates--the |
9243 | 9530 | C<< +> >> mode would clobber the file first. You can't usually use |
9244 | 9531 | either read-write mode for updating textfiles, since they have |
9245 | variable-length records. See the B<-i> switch in | |
9532 | variable-length records. See the B<-i> switch in | |
9246 | better approach. The file is | |
9533 | L<perlrun|perlrun/-i[extension]> for a better approach. The file is | |
9247 | modified by the process's | |
9534 | created with permissions of C<0666> modified by the process's | |
9535 | L<C<umask>|/umask EXPR> value. | |
9248 | 9536 | |
9249 | 9537 | =end original |
9250 | 9538 | |
9251 | 9539 | ファイルに読み込みアクセスと書き込みアクセスの両方をしたいことを示すために、 |
9252 | 9540 | C<< > >> や C<< < >> の前に C<+> を付けることができます: |
9253 | 9541 | 従って、ほとんど常に C<< +< >> が読み書き更新のために使われます -- |
9254 | 9542 | C<< +> >> モードはまずファイルを上書きします。 |
9255 | 9543 | 普通はこれらの読み書きモードをテキストファイルの更新のためには使えません; |
9256 | 9544 | なぜなら可変長のレコードで構成されているからです。 |
9257 | よりよい手法については L<perlrun | |
9545 | よりよい手法については L<perlrun|perlrun/-i[extension]> の | |
9546 | B<-i> オプションを参照してください。 | |
9258 | 9547 | ファイルは C<0666> をプロセスの L<C<umask>|/umask EXPR> 値で修正した |
9259 | 9548 | パーミッションで作成されます。 |
9260 | 9549 | |
9261 | 9550 | =begin original |
9262 | 9551 | |
9263 | 9552 | These various prefixes correspond to the L<fopen(3)> modes of C<r>, |
9264 | 9553 | C<r+>, C<w>, C<w+>, C<a>, and C<a+>. |
9265 | 9554 | |
9266 | 9555 | =end original |
9267 | 9556 | |
9268 | 9557 | これらの様々な前置詞は L<fopen(3)> の C<r>, C<r+>, |
9269 | 9558 | C<w>, C<w+>, C<a>, C<a+> のモードに対応します。 |
9270 | 9559 | |
9271 | 9560 | =begin original |
9272 | 9561 | |
9273 | ||
9562 | More examples of different modes in action: | |
9274 | should be concatenated (in that order), preferably separated by white | |
9275 | space. You can--but shouldn't--omit the mode in these forms when that mode | |
9276 | is C<< < >>. It is safe to use the two-argument form of | |
9277 | L<C<open>|/open FILEHANDLE,EXPR> if the filename argument is a known literal. | |
9278 | 9563 | |
9279 | 9564 | =end original |
9280 | 9565 | |
9281 | ||
9566 | 実用的な異なったモードに関する更なる例: | |
9282 | 結合されます(空白によって分割されているかもしれません)。 | |
9283 | この形式で、モードが C<< '<' >> の場合はモードを省略できます (が、 | |
9284 | するべきではありません)。 | |
9285 | ファイル引数が既知のリテラルの場合、2 引数形式の | |
9286 | L<C<open>|/open FILEHANDLE,EXPR> は安全です。 | |
9287 | 9567 | |
9288 | ||
9568 | # Open a file for concatenation | |
9569 | open(my $log, ">>", "/usr/spool/news/twitlog") | |
9570 | or warn "Couldn't open log file; discarding input"; | |
9289 | 9571 | |
9290 | ||
9572 | # Open a file for reading and writing | |
9291 | ||
9573 | open(my $dbase, "+<", "dbase.mine") | |
9292 | ||
9574 | or die "Can't open 'dbase.mine' for update: $!"; | |
9293 | output to us. In the two-argument (and one-argument) form, one should | |
9294 | replace dash (C<->) with the command. | |
9295 | See L<perlipc/"Using open() for IPC"> for more examples of this. | |
9296 | (You are not allowed to L<C<open>|/open FILEHANDLE,EXPR> to a command | |
9297 | that pipes both in I<and> out, but see L<IPC::Open2>, L<IPC::Open3>, and | |
9298 | L<perlipc/"Bidirectional Communication with Another Process"> for | |
9299 | alternatives.) | |
9300 | 9575 | |
9301 | =e | |
9576 | =item Checking the return value | |
9302 | 9577 | |
9303 | ||
9578 | (返り値をチェックする) | |
9304 | MODE が C<|-> の場合、ファイル名は出力がパイプされるコマンドとして | |
9305 | 解釈され、MODE が C<-|> の場合、ファイル名は出力がこちらに | |
9306 | パイプされるコマンドとして解釈されます。 | |
9307 | 2 引数(と 1 引数) の形式ではハイフン(C<->)をコマンドの代わりに使えます。 | |
9308 | これに関するさらなる例については L<perlipc/"Using open() for IPC"> を | |
9309 | 参照してください。 | |
9310 | (L<C<open>|/open FILEHANDLE,EXPR> を入出力 I<両用> にパイプすることは | |
9311 | 出来ませんが、代替案としては L<IPC::Open2>, L<IPC::Open3>, | |
9312 | L<perlipc/"Bidirectional Communication with Another Process"> を | |
9313 | 参照してください。) | |
9314 | 9579 | |
9315 | 9580 | =begin original |
9316 | 9581 | |
9317 | ||
9582 | Open returns nonzero on success, the undefined value otherwise. If the | |
9318 | ||
9583 | C<open> involved a pipe, the return value happens to be the pid of the | |
9319 | ||
9584 | subprocess. | |
9320 | L<C<open>|/open FILEHANDLE,EXPR> with more than three arguments for | |
9321 | non-pipe modes is not yet defined, but experimental "layers" may give | |
9322 | extra LIST arguments meaning. | |
9323 | 9585 | |
9324 | 9586 | =end original |
9325 | 9587 | |
9326 | ||
9588 | open は、成功時にはゼロ以外を返し、失敗時には未定義値を返します。 | |
9327 | ||
9589 | パイプに関る C<open> のときには、返り値は | |
9328 | ||
9590 | サブプロセスの pid となります。 | |
9329 | パイプモードではない L<C<open>|/open FILEHANDLE,EXPR> での三つ以上の引数の | |
9330 | 意味はまだ未定義ですが、実験的な「層」は追加の LIST 引数の意味を与えます。 | |
9331 | 9591 | |
9332 | 9592 | =begin original |
9333 | 9593 | |
9334 | ||
9594 | When opening a file, it's seldom a good idea to continue if the request | |
9335 | o | |
9595 | failed, so C<open> is frequently used with L<C<die>|/die LIST>. Even if | |
9596 | you want your code to do something other than C<die> on a failed open, | |
9597 | you should still always check the return value from opening a file. | |
9336 | 9598 | |
9337 | 9599 | =end original |
9338 | 9600 | |
9339 | ||
9601 | ファイルを開く時、開くのに失敗した時に通常の処理を続けるのは普通は悪い | |
9340 | ||
9602 | 考えなので、C<open> はしばしば | |
9603 | L<C<die>|/die LIST> と結び付けられて使われます。 | |
9604 | 開くときに失敗したときに L<C<die>|/die LIST> 意外の何かを | |
9605 | したい場合でも、ファイルを開いた時の返り値を常にチェックするべきです。 | |
9341 | 9606 | |
9607 | =back | |
9608 | ||
9609 | =item Specifying I/O layers in MODE | |
9610 | ||
9611 | (MODE で I/O 層を指定する) | |
9612 | ||
9342 | 9613 | =begin original |
9343 | 9614 | |
9344 | You | |
9615 | You can use the three-argument form of open to specify | |
9345 | I/O layers (sometimes referred to as "disciplines") to apply to the | |
9616 | I/O layers (sometimes referred to as "disciplines") to apply to the new | |
9346 | ||
9617 | filehandle. These affect how the input and output are processed (see | |
9618 | L<open> and | |
9347 | 9619 | L<PerlIO> for more details). For example: |
9348 | 9620 | |
9349 | 9621 | =end original |
9350 | 9622 | |
9351 | ||
9623 | 新しいファイルハンドルに適用する | |
9352 | I/O 層(「ディシプリン」とも呼ばれます)を指定 | |
9624 | I/O 層(「ディシプリン」とも呼ばれます)を指定するために | |
9353 | ||
9625 | open の 3 引数形式を使えます。 | |
9626 | これらはどのように入出力が処理されるかに影響を与えます | |
9354 | 9627 | (詳細については L<open> と L<PerlIO> を参照してください)。 |
9355 | 9628 | 例えば: |
9356 | 9629 | |
9357 | open(my $fh, "<:encoding(UTF-8)", $filename) | |
9630 | open(my $fh, "<:encoding(UTF-8)", $filename) | |
9358 | || die "Can't open UTF-8 encoded $filename: $!"; | |
9631 | || die "Can't open UTF-8 encoded $filename: $!"; | |
9359 | 9632 | |
9360 | 9633 | =begin original |
9361 | 9634 | |
9362 | opens the UTF8-encoded file containing Unicode characters; | |
9635 | This opens the UTF8-encoded file containing Unicode characters; | |
9363 | 9636 | see L<perluniintro>. Note that if layers are specified in the |
9364 | three-argument form, then default layers stored in | |
9637 | three-argument form, then default layers stored in | |
9365 | ||
9638 | L<C<${^OPEN}>|perlvar/${^OPEN}> | |
9639 | (usually set by the L<open> pragma or the switch C<-CioD>) are ignored. | |
9366 | 9640 | Those layers will also be ignored if you specify a colon with no name |
9367 | 9641 | following it. In that case the default layer for the operating system |
9368 | 9642 | (:raw on Unix, :crlf on Windows) is used. |
9369 | 9643 | |
9370 | 9644 | =end original |
9371 | 9645 | |
9372 | は、Unicode 文字を含む UTF8 エンコードされたファイルを開きます; | |
9646 | これは、Unicode 文字を含む UTF8 エンコードされたファイルを開きます; | |
9373 | 9647 | L<perluniintro> を参照してください。 |
9374 | 3 引数形式で層を指定すると、${^OPEN} | |
9648 | 3 引数形式で層を指定すると、L<C<${^OPEN}>|perlvar/${^OPEN}> | |
9375 | 通常は L<open> プラグマか C<-CioD> オプションでセットされます) に | |
9649 | (通常は L<open> プラグマか C<-CioD> オプションでセットされます) に | |
9376 | デフォルト層は無視されることに注意してください。 | |
9650 | 保存されたデフォルト層は無視されることに注意してください。 | |
9377 | 9651 | これらの層は、名前なしでコロンを指定した場合にも無視されます。 |
9378 | 9652 | この場合 OS のデフォルトの層 (Unix では :raw、Windows では :crlf) が |
9379 | 9653 | 使われます。 |
9380 | 9654 | |
9381 | 9655 | =begin original |
9382 | 9656 | |
9383 | Open returns nonzero on success, the undefined value otherwise. If | |
9384 | the L<C<open>|/open FILEHANDLE,EXPR> involved a pipe, the return value | |
9385 | happens to be the pid of the subprocess. | |
9386 | ||
9387 | =end original | |
9388 | ||
9389 | open は、成功時にはゼロ以外を返し、失敗時には未定義値を返します。 | |
9390 | パイプに関る L<C<open>|/open FILEHANDLE,EXPR> のときには、返り値は | |
9391 | サブプロセスの pid となります。 | |
9392 | ||
9393 | =begin original | |
9394 | ||
9395 | 9657 | On some systems (in general, DOS- and Windows-based systems) |
9396 | 9658 | L<C<binmode>|/binmode FILEHANDLE, LAYER> is necessary when you're not |
9397 | 9659 | working with a text file. For the sake of portability it is a good idea |
9398 | 9660 | always to use it when appropriate, and never to use it when it isn't |
9399 | 9661 | appropriate. Also, people can set their I/O to be by default |
9400 | 9662 | UTF8-encoded Unicode, not bytes. |
9401 | 9663 | |
9402 | 9664 | =end original |
9403 | 9665 | |
9404 | 9666 | テキストファイルでないものを扱う場合に |
9405 | 9667 | L<C<binmode>|/binmode FILEHANDLE, LAYER> が必要な |
9406 | 9668 | システムもあります(一般的には DOS と Windows ベースのシステムです)。 |
9407 | 9669 | 移植性のために、適切なときには常にこれを使い、適切でないときには |
9408 | 9670 | 決して使わないというのは良い考えです。 |
9409 | 9671 | また、デフォルトとして I/O を bytes ではなく UTF-8 エンコードされた |
9410 | 9672 | Unicode にセットすることも出来ます。 |
9411 | 9673 | |
9674 | =item Using C<undef> for temporary files | |
9675 | ||
9676 | (一時ファイルとして C<undef> を使う) | |
9677 | ||
9412 | 9678 | =begin original |
9413 | 9679 | |
9414 | ||
9680 | As a special case the three-argument form with a read/write mode and the third | |
9415 | ||
9681 | argument being L<C<undef>|/undef EXPR>: | |
9416 | used with L<C<die>|/die LIST>. Even if L<C<die>|/die LIST> won't do | |
9417 | what you want (say, in a CGI script, | |
9418 | where you want to format a suitable error message (but there are | |
9419 | modules that can help with that problem)) always check | |
9420 | the return value from opening a file. | |
9421 | 9682 | |
9422 | 9683 | =end original |
9423 | 9684 | |
9424 | ||
9685 | 特別な場合として、3 引数の形で読み書きモードで 3 番目の引数が | |
9425 | ||
9686 | L<C<undef>|/undef EXPR> の場合: | |
9426 | L<C<die>|/die LIST> と結び付けられて使われます。 | |
9427 | 望むものが L<C<die>|/die LIST> でない場合(例えば、CGI スクリプトのように | |
9428 | きれいにフォーマットされたエラーメッセージを作りたい場合 | |
9429 | (但しこの問題を助けるモジュールがあります))でも、 | |
9430 | ファイルを開いた時の返り値を常にチェックするべきです。 | |
9431 | 9687 | |
9688 | open(my $tmp, "+>", undef) or die ... | |
9689 | ||
9432 | 9690 | =begin original |
9433 | 9691 | |
9434 | ||
9692 | opens a filehandle to a newly created empty anonymous temporary file. | |
9435 | ||
9693 | (This happens under any mode, which makes C<< +> >> the only useful and | |
9436 | t | |
9694 | sensible mode to use.) You will need to | |
9437 | ||
9695 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> to do the reading. | |
9438 | does not check for errors, so it is better to explicitly close | |
9439 | filehandles, especially those used for writing: | |
9440 | 9696 | |
9441 | 9697 | =end original |
9442 | 9698 | |
9443 | ファイルハンドル | |
9699 | 新しく作成した空の無名一時ファイルとしてファイルハンドルを開きます。 | |
9444 | これが | |
9700 | (これはどのモードでも起こりますが、C<< +> >> のみが有用で意味があります) | |
9445 | ||
9701 | 読み込みを行うためには L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> が | |
9446 | ||
9702 | 必要です。 | |
9447 | 明示的にファイルハンドルを閉じる方がよいです。 | |
9448 | 9703 | |
9449 | | |
9704 | =item Opening a filehandle into an in-memory scalar | |
9450 | || warn "close failed: $!"; | |
9451 | 9705 | |
9706 | (ファイルハンドルをメモリ内スカラに開く) | |
9707 | ||
9452 | 9708 | =begin original |
9453 | 9709 | |
9454 | ||
9710 | You can open filehandles directly to Perl scalars instead of a file or | |
9711 | other resource external to the program. To do so, provide a reference to | |
9712 | that scalar as the third argument to C<open>, like so: | |
9455 | 9713 | |
9456 | 9714 | =end original |
9457 | 9715 | |
9458 | ||
9716 | ファイルやその他のプログラムから見ての外部リソースではなく、 | |
9717 | Perl スカラに対して直接ファイルハンドルを開くことができます。 | |
9718 | そうするためには、次のように、C<open> の 3 番目の引数としてその | |
9719 | スカラへのリファレンスを提供します: | |
9459 | 9720 | |
9460 | | |
9721 | open(my $memory, ">", \$var) | |
9461 | | |
9722 | or die "Can't open memory file: $!"; | |
9723 | print $memory "foo!\n"; # output will appear in $var | |
9462 | 9724 | |
9463 | 9725 | =begin original |
9464 | 9726 | |
9465 | T | |
9727 | To (re)open C<STDOUT> or C<STDERR> as an in-memory file, close it first: | |
9466 | <FH> >> and so on. Note that it's a global variable, so this form is | |
9467 | not recommended in new code. | |
9468 | 9728 | |
9469 | 9729 | =end original |
9470 | 9730 | |
9471 | ||
9731 | C<STDOUT> や C<STDERR> を「オンメモリの」ファイルとして | |
9472 | ||
9732 | 再び開きたい場合は、先にそれを閉じます: | |
9473 | これはグローバル変数なので、新しいコードでは非推奨であることに | |
9474 | 注意してください。 | |
9475 | 9733 | |
9734 | close STDOUT; | |
9735 | open(STDOUT, ">", \$variable) | |
9736 | or die "Can't open STDOUT: $!"; | |
9737 | ||
9476 | 9738 | =begin original |
9477 | 9739 | |
9478 | ||
9740 | The scalars for in-memory files are treated as octet strings: unless | |
9479 | ||
9741 | the file is being opened with truncation the scalar may not contain | |
9742 | any code points over 0xFF. | |
9480 | 9743 | |
9481 | 9744 | =end original |
9482 | 9745 | |
9483 | ||
9746 | オンメモリファイルのためのスカラはオクテット文字列として扱われます: | |
9484 | ||
9747 | ファイルが切り詰められて開かれない限り、 | |
9748 | スカラは 0xFF を超える符号位置を含みません。 | |
9485 | 9749 | |
9486 | ||
9750 | =begin original | |
9487 | open(ARTICLE) or die "Can't find article $ARTICLE: $!\n"; | |
9488 | 9751 | |
9752 | Opening in-memory files I<can> fail for a variety of reasons. As with | |
9753 | any other C<open>, check the return value for success. | |
9754 | ||
9755 | =end original | |
9756 | ||
9757 | オンメモリファイルを開くのは様々な理由で失敗する I<ことがあります>。 | |
9758 | その他の C<open> と同様、成功したかを返り値でチェックしてください。 | |
9759 | ||
9489 | 9760 | =begin original |
9490 | 9761 | |
9491 | ||
9762 | I<Technical note>: This feature works only when Perl is built with | |
9492 | ||
9763 | PerlIO -- the default, except with older (pre-5.16) Perl installations | |
9764 | that were configured to not include it (e.g. via C<Configure | |
9765 | -Uuseperlio>). You can see whether your Perl was built with PerlIO by | |
9766 | running C<perl -V:useperlio>. If it says C<'define'>, you have PerlIO; | |
9767 | otherwise you don't. | |
9493 | 9768 | |
9494 | 9769 | =end original |
9495 | 9770 | |
9496 | ||
9771 | I<技術ノート>: この機能は Perl が PerlIO を使ってビルドされている | |
9497 | ||
9772 | 場合にのみ動作します; これは (C<Configure -Uuseperlio> によって) | |
9498 | ||
9773 | これを含まないように設定されていた古い (5.16 より前の) Perl でない限り、 | |
9774 | デフォルトです。 | |
9775 | Perl が PerlIO つきでビルドされているかどうかを確認するには、 | |
9776 | C<perl -V:useperlio> を見ます。 | |
9777 | これが C<'define'> なら PerlIO を使っています; | |
9778 | そうでなければ使っていません。 | |
9499 | 9779 | |
9500 | 9780 | =begin original |
9501 | 9781 | |
9502 | ||
9782 | See L<perliol> for detailed info on PerlIO. | |
9503 | argument being L<C<undef>|/undef EXPR>: | |
9504 | 9783 | |
9505 | 9784 | =end original |
9506 | 9785 | |
9507 | ||
9786 | PerlIO に関する詳しい情報については L<perliol> を参照してください。 | |
9508 | L<C<undef>|/undef EXPR> の場合: | |
9509 | 9787 | |
9510 | | |
9788 | =item Opening a filehandle into a command | |
9511 | 9789 | |
9790 | (ファイルハンドルをコマンドに開く) | |
9791 | ||
9512 | 9792 | =begin original |
9513 | 9793 | |
9514 | ||
9794 | If MODE is C<|->, then the filename is | |
9515 | ||
9795 | interpreted as a command to which output is to be piped, and if MODE | |
9516 | se | |
9796 | is C<-|>, the filename is interpreted as a command that pipes | |
9517 | ||
9797 | output to us. In the two-argument (and one-argument) form, one should | |
9798 | replace dash (C<->) with the command. | |
9799 | See L<perlipc/"Using open() for IPC"> for more examples of this. | |
9800 | (You are not allowed to L<C<open>|/open FILEHANDLE,MODE,EXPR> to a command | |
9801 | that pipes both in I<and> out, but see L<IPC::Open2>, L<IPC::Open3>, and | |
9802 | L<perlipc/"Bidirectional Communication with Another Process"> for | |
9803 | alternatives.) | |
9518 | 9804 | |
9519 | 9805 | =end original |
9520 | 9806 | |
9521 | ||
9807 | MODE が C<|-> の場合、ファイル名は出力がパイプされるコマンドとして | |
9522 | ||
9808 | 解釈され、MODE が C<-|> の場合、ファイル名は出力がこちらに | |
9523 | ||
9809 | パイプされるコマンドとして解釈されます。 | |
9524 | ||
9810 | 2 引数(と 1 引数) の形式ではハイフン(C<->)をコマンドの代わりに使えます。 | |
9811 | これに関するさらなる例については L<perlipc/"Using open() for IPC"> を | |
9812 | 参照してください。 | |
9813 | (L<C<open>|/open FILEHANDLE,MODE,EXPR> を入出力 I<両用> にパイプすることは | |
9814 | 出来ませんが、代替案としては L<IPC::Open2>, L<IPC::Open3>, | |
9815 | L<perlipc/"Bidirectional Communication with Another Process"> を | |
9816 | 参照してください。) | |
9525 | 9817 | |
9818 | open(my $article_fh, "-|", "caesar <$article") # decrypt | |
9819 | # article | |
9820 | or die "Can't start caesar: $!"; | |
9821 | ||
9822 | open(my $article_fh, "caesar <$article |") # ditto | |
9823 | or die "Can't start caesar: $!"; | |
9824 | ||
9825 | open(my $out_fh, "|-", "sort >Tmp$$") # $$ is our process id | |
9826 | or die "Can't start sort: $!"; | |
9827 | ||
9526 | 9828 | =begin original |
9527 | 9829 | |
9528 | ||
9830 | In the form of pipe opens taking three or more arguments, if LIST is specified | |
9529 | ||
9831 | (extra arguments after the command name) then LIST becomes arguments | |
9530 | o | |
9832 | to the command invoked if the platform supports it. The meaning of | |
9833 | L<C<open>|/open FILEHANDLE,MODE,EXPR> with more than three arguments for | |
9834 | non-pipe modes is not yet defined, but experimental "layers" may give | |
9835 | extra LIST arguments meaning. | |
9531 | 9836 | |
9532 | 9837 | =end original |
9533 | 9838 | |
9534 | ||
9839 | パイプでの三つ以上の引数の形式では、LIST (コマンド名の後の追加の引数) が | |
9535 | ||
9840 | 指定されると、プラットフォームが対応していれば、LIST は起動される | |
9536 | ||
9841 | コマンドへの引数となります。 | |
9537 | ||
9842 | パイプモードではない L<C<open>|/open FILEHANDLE,MODE,EXPR> での | |
9843 | 三つ以上の引数の意味はまだ未定義ですが、実験的な「層」は | |
9844 | 追加の LIST 引数の意味を与えます。 | |
9538 | 9845 | |
9539 | ||
9846 | =begin original | |
9540 | 9847 | |
9848 | If you open a pipe on the command C<-> (that is, specify either C<|-> or C<-|> | |
9849 | with the one- or two-argument forms of | |
9850 | L<C<open>|/open FILEHANDLE,MODE,EXPR>), an implicit L<C<fork>|/fork> is done, | |
9851 | so L<C<open>|/open FILEHANDLE,MODE,EXPR> returns twice: in the parent process | |
9852 | it returns the pid | |
9853 | of the child process, and in the child process it returns (a defined) C<0>. | |
9854 | Use C<defined($pid)> or C<//> to determine whether the open was successful. | |
9855 | ||
9856 | =end original | |
9857 | ||
9858 | 1 引数 または 2 引数の形の L<C<open>|/open FILEHANDLE,MODE,EXPR>) で | |
9859 | (C<-|> や C<|-> というふうに) C<-> というコマンドにパイプを開くと、 | |
9860 | 暗黙の L<C<fork>|/fork> が行なわれるので、 | |
9861 | L<C<open>|/open FILEHANDLE,MODE,EXPR> は 2 回返ります; | |
9862 | 親プロセスには子プロセスの pid が返され、子プロセスには (定義された) C<0> が | |
9863 | 返されます。 | |
9864 | open が成功したかどうかを調べるには、C<defined($pid)> または C<//> を | |
9865 | 使います。 | |
9866 | ||
9541 | 9867 | =begin original |
9542 | 9868 | |
9543 | ||
9869 | For example, use either | |
9544 | 9870 | |
9545 | 9871 | =end original |
9546 | 9872 | |
9547 | ||
9873 | 例えば、以下の二つ | |
9548 | 再び開きたい場合は、先にそれを閉じます: | |
9549 | 9874 | |
9550 | clo | |
9875 | my $child_pid = open(my $from_kid, "-|") | |
9551 | | |
9876 | // die "Can't fork: $!"; | |
9552 | or die "Can't open STDOUT: $!"; | |
9553 | 9877 | |
9554 | 9878 | =begin original |
9555 | 9879 | |
9556 | ||
9880 | or | |
9557 | 9881 | |
9558 | 9882 | =end original |
9559 | 9883 | |
9560 | ||
9884 | または | |
9561 | 9885 | |
9886 | my $child_pid = open(my $to_kid, "|-") | |
9887 | // die "Can't fork: $!"; | |
9888 | ||
9562 | 9889 | =begin original |
9563 | 9890 | |
9564 | ||
9891 | followed by | |
9565 | 9892 | |
9566 | 9893 | =end original |
9567 | 9894 | |
9568 | ||
9895 | を使って、後で以下のようにします。 | |
9569 | 9896 | |
9570 | | |
9897 | if ($child_pid) { | |
9571 | ||
9898 | # am the parent: | |
9899 | # either write $to_kid or else read $from_kid | |
9900 | ... | |
9901 | waitpid $child_pid, 0; | |
9902 | } else { | |
9903 | # am the child; use STDIN/STDOUT normally | |
9904 | ... | |
9905 | exit; | |
9906 | } | |
9572 | 9907 | |
9573 | ||
9908 | =begin original | |
9574 | or die "Can't open 'dbase.mine' for update: $!"; | |
9575 | 9909 | |
9576 | | |
9910 | The filehandle behaves normally for the parent, but I/O to that | |
9577 | ||
9911 | filehandle is piped from/to the STDOUT/STDIN of the child process. | |
9912 | In the child process, the filehandle isn't opened--I/O happens from/to | |
9913 | the new STDOUT/STDIN. Typically this is used like the normal | |
9914 | piped open when you want to exercise more control over just how the | |
9915 | pipe command gets executed, such as when running setuid and | |
9916 | you don't want to have to scan shell commands for metacharacters. | |
9578 | 9917 | |
9579 | ||
9918 | =end original | |
9580 | # article | |
9581 | or die "Can't start caesar: $!"; | |
9582 | 9919 | |
9583 | ||
9920 | 親プロセスでは、このファイルハンドルは通常通りに動作しますが、行なわれる | |
9584 | | |
9921 | 入出力は、子プロセスの STDIN/STDOUT にパイプされます。 | |
9922 | 子プロセス側では、そのファイルハンドルは開かれず、入出力は新しい STDOUT か | |
9923 | STDIN に対して行なわれます。 | |
9924 | これは、setuid で実行して、シェルコマンドのメタ文字を | |
9925 | 検索させたくないような場合に、パイプコマンドの起動の仕方を | |
9926 | 制御したいとき、普通のパイプの open と同じように使います。 | |
9585 | 9927 | |
9586 | ||
9928 | =begin original | |
9587 | or die "Can't start sort: $!"; | |
9588 | 9929 | |
9589 | | |
9930 | The following blocks are more or less equivalent: | |
9590 | open(my $memory, ">", \$var) | |
9591 | or die "Can't open memory file: $!"; | |
9592 | print $memory "foo!\n"; # output will appear in $var | |
9593 | 9931 | |
9932 | =end original | |
9933 | ||
9934 | 以下の組み合わせは、だいたい同じものです: | |
9935 | ||
9936 | open(my $fh, "|tr '[a-z]' '[A-Z]'"); | |
9937 | open(my $fh, "|-", "tr '[a-z]' '[A-Z]'"); | |
9938 | open(my $fh, "|-") || exec 'tr', '[a-z]', '[A-Z]'; | |
9939 | open(my $fh, "|-", "tr", '[a-z]', '[A-Z]'); | |
9940 | ||
9941 | open(my $fh, "cat -n '$file'|"); | |
9942 | open(my $fh, "-|", "cat -n '$file'"); | |
9943 | open(my $fh, "-|") || exec "cat", "-n", $file; | |
9944 | open(my $fh, "-|", "cat", "-n", $file); | |
9945 | ||
9594 | 9946 | =begin original |
9595 | 9947 | |
9948 | The last two examples in each block show the pipe as "list form", which | |
9949 | is not yet supported on all platforms. (If your platform has a real | |
9950 | L<C<fork>|/fork>, such as Linux and macOS, you can use the list form; it | |
9951 | also works on Windows with Perl 5.22 or later.) You would want to use | |
9952 | the list form of the pipe so you can pass literal arguments to the | |
9953 | command without risk of the shell interpreting any shell metacharacters | |
9954 | in them. However, this also bars you from opening pipes to commands that | |
9955 | intentionally contain shell metacharacters, such as: | |
9956 | ||
9957 | =end original | |
9958 | ||
9959 | それぞれのブロックの末尾二つの例ではパイプを「リスト形式」にしていますが、 | |
9960 | これはまだ全てのプラットフォームで対応しているわけではなりません。 | |
9961 | (もし実行しているプラットフォームで本当の | |
9962 | L<C<fork>|/fork> があれば(Linux や | |
9963 | MacOS X なら)リスト形式が使えます; Perl 5.22 以降では Windows でも | |
9964 | 動作します。) | |
9965 | パイプのリスト形式を使うことで、コマンドへのリテラルな引数を、 | |
9966 | シェルのメタ文字をシェルが解釈するリスクなしに渡すことができます。 | |
9967 | しかし、これは以下のように意図的にシェルメタ文字を含むコマンドをパイプとして | |
9968 | 開くことを妨げます: | |
9969 | ||
9970 | open(my $fh, "|cat -n | expand -4 | lpr") | |
9971 | || die "Can't open pipeline to lpr: $!"; | |
9972 | ||
9973 | =begin original | |
9974 | ||
9975 | See L<perlipc/"Safe Pipe Opens"> for more examples of this. | |
9976 | ||
9977 | =end original | |
9978 | ||
9979 | これに関する更なる例については L<perlipc/"Safe Pipe Opens"> を | |
9980 | 参照してください。 | |
9981 | ||
9982 | =item Duping filehandles | |
9983 | ||
9984 | (ハンドルの複製) | |
9985 | ||
9986 | =begin original | |
9987 | ||
9596 | 9988 | You may also, in the Bourne shell tradition, specify an EXPR beginning |
9597 | 9989 | with C<< >& >>, in which case the rest of the string is interpreted |
9598 | 9990 | as the name of a filehandle (or file descriptor, if numeric) to be |
9599 | 9991 | duped (as in L<dup(2)>) and opened. You may use C<&> after C<< > >>, |
9600 | 9992 | C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>, and C<< +< >>. |
9601 | 9993 | The mode you specify should match the mode of the original filehandle. |
9602 | 9994 | (Duping a filehandle does not take into account any existing contents |
9603 | 9995 | of IO buffers.) If you use the three-argument |
9604 | 9996 | form, then you can pass either a |
9605 | 9997 | number, the name of a filehandle, or the normal "reference to a glob". |
9606 | 9998 | |
9607 | 9999 | =end original |
9608 | 10000 | |
9609 | 10001 | Bourne シェルの慣例にしたがって、EXPR の先頭に C<< >& >> |
9610 | 10002 | を付けると、EXPR の残りの文字列をファイルハンドル名 |
9611 | 10003 | (数字であれば、ファイル記述子) と解釈して、それを (L<dup(2)> によって) |
9612 | 10004 | 複製してオープンします。 |
9613 | 10005 | C<&> は、C<< > >>, C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>, |
9614 | 10006 | C<< +< >>というモード指定に付けることができます。 |
9615 | 10007 | 指定するモード指定は、もとのファイルハンドルのモードと |
9616 | 10008 | 合っていないといけません。 |
9617 | 10009 | (ファイルハンドルの複製は既に存在する IO バッファの内容に含めません。) |
9618 | 10010 | 3 引数形式を使う場合は、数値を渡すか、ファイルハンドルの名前を渡すか、 |
9619 | 10011 | 通常の「グロブへのリファレンス」を渡します。 |
9620 | 10012 | |
9621 | 10013 | =begin original |
9622 | 10014 | |
9623 | 10015 | Here is a script that saves, redirects, and restores C<STDOUT> and |
9624 | 10016 | C<STDERR> using various methods: |
9625 | 10017 | |
9626 | 10018 | =end original |
9627 | 10019 | |
9628 | 10020 | C<STDOUT> と C<STDERR> 保存し、リダイレクトし、元に戻すスクリプトを示します: |
9629 | 10021 | |
9630 | 10022 | #!/usr/bin/perl |
9631 | open(my $oldout, ">&STDOUT") | |
10023 | open(my $oldout, ">&STDOUT") | |
9632 | | |
10024 | or die "Can't dup STDOUT: $!"; | |
10025 | open(OLDERR, ">&", \*STDERR) | |
10026 | or die "Can't dup STDERR: $!"; | |
9633 | 10027 | |
9634 | open(STDOUT, '>', "foo.out") | |
10028 | open(STDOUT, '>', "foo.out") | |
9635 | | |
10029 | or die "Can't redirect STDOUT: $!"; | |
10030 | open(STDERR, ">&STDOUT") | |
10031 | or die "Can't dup STDOUT: $!"; | |
9636 | 10032 | |
9637 | 10033 | select STDERR; $| = 1; # make unbuffered |
9638 | 10034 | select STDOUT; $| = 1; # make unbuffered |
9639 | 10035 | |
9640 | 10036 | print STDOUT "stdout 1\n"; # this works for |
9641 | 10037 | print STDERR "stderr 1\n"; # subprocesses too |
9642 | 10038 | |
9643 | open(STDOUT, ">&", $oldout) | |
10039 | open(STDOUT, ">&", $oldout) | |
9644 | | |
10040 | or die "Can't dup \$oldout: $!"; | |
10041 | open(STDERR, ">&OLDERR") | |
10042 | or die "Can't dup OLDERR: $!"; | |
9645 | 10043 | |
9646 | 10044 | print STDOUT "stdout 2\n"; |
9647 | 10045 | print STDERR "stderr 2\n"; |
9648 | 10046 | |
9649 | 10047 | =begin original |
9650 | 10048 | |
9651 | 10049 | If you specify C<< '<&=X' >>, where C<X> is a file descriptor number |
9652 | 10050 | or a filehandle, then Perl will do an equivalent of C's L<fdopen(3)> of |
9653 | 10051 | that file descriptor (and not call L<dup(2)>); this is more |
9654 | 10052 | parsimonious of file descriptors. For example: |
9655 | 10053 | |
9656 | 10054 | =end original |
9657 | 10055 | |
9658 | 10056 | C<X> をファイル記述子の番号かファイルハンドルとして、 |
9659 | 10057 | C<< '<&=X' >> と指定すると、Perl はそのファイル記述子に対する |
9660 | 10058 | C の L<fdopen(3)> と同じことを行ないます(そして L<dup(2)> は呼び出しません); |
9661 | 10059 | これはファイル記述子をより節約します。 |
9662 | 10060 | 例えば: |
9663 | 10061 | |
9664 | 10062 | # open for input, reusing the fileno of $fd |
9665 | 10063 | open(my $fh, "<&=", $fd) |
9666 | 10064 | |
9667 | 10065 | =begin original |
9668 | 10066 | |
9669 | 10067 | or |
9670 | 10068 | |
9671 | 10069 | =end original |
9672 | 10070 | |
9673 | 10071 | または |
9674 | 10072 | |
9675 | 10073 | open(my $fh, "<&=$fd") |
9676 | 10074 | |
9677 | 10075 | =begin original |
9678 | 10076 | |
9679 | 10077 | or |
9680 | 10078 | |
9681 | 10079 | =end original |
9682 | 10080 | |
9683 | 10081 | または |
9684 | 10082 | |
9685 | 10083 | # open for append, using the fileno of $oldfh |
9686 | 10084 | open(my $fh, ">>&=", $oldfh) |
9687 | 10085 | |
9688 | 10086 | =begin original |
9689 | 10087 | |
9690 | 10088 | Being parsimonious on filehandles is also useful (besides being |
9691 | 10089 | parsimonious) for example when something is dependent on file |
9692 | 10090 | descriptors, like for example locking using |
9693 | 10091 | L<C<flock>|/flock FILEHANDLE,OPERATION>. If you do just |
9694 | 10092 | C<< open(my $A, ">>&", $B) >>, the filehandle C<$A> will not have the |
9695 | 10093 | same file descriptor as C<$B>, and therefore C<flock($A)> will not |
9696 | 10094 | C<flock($B)> nor vice versa. But with C<< open(my $A, ">>&=", $B) >>, |
9697 | 10095 | the filehandles will share the same underlying system file descriptor. |
9698 | 10096 | |
9699 | 10097 | =end original |
9700 | 10098 | |
9701 | 10099 | ファイルハンドルを倹約することは、(倹約できること以外に)何かが |
9702 | 10100 | ファイル記述子に依存している場合、例えば |
9703 | 10101 | L<C<flock>|/flock FILEHANDLE,OPERATION> を使った |
9704 | 10102 | ファイルロックといった場合に有用です。 |
9705 | 10103 | C<< open(my $A, ">>&", $B) >> とすると、ファイルハンドル C<$A> は C<$B> と同じ |
9706 | 10104 | ファイル記述子にはならないので、C<flock($A)> と C<flock($B)> は別々になります。 |
9707 | 10105 | しかし C<< open(my $A, ">>&=", $B) >> ではファイルハンドルは基礎となるシステムの |
9708 | 10106 | 同じファイル記述子を共有します。 |
9709 | 10107 | |
9710 | 10108 | =begin original |
9711 | 10109 | |
9712 | 10110 | Note that under Perls older than 5.8.0, Perl uses the standard C library's' |
9713 | 10111 | L<fdopen(3)> to implement the C<=> functionality. On many Unix systems, |
9714 | 10112 | L<fdopen(3)> fails when file descriptors exceed a certain value, typically 255. |
9715 | 10113 | For Perls 5.8.0 and later, PerlIO is (most often) the default. |
9716 | 10114 | |
9717 | 10115 | =end original |
9718 | 10116 | |
9719 | 10117 | 5.8.0 より前の Perl の場合、C<=> 機能の実装は |
9720 | 10118 | 標準 C ライブラリの L<fdopen(3)> を使っています。 |
9721 | 10119 | 多くの Unix システムでは、L<fdopen(3)> はファイル記述子がある値 |
9722 | 10120 | (典型的には 255)を超えた場合に失敗することが知られています。 |
9723 | 10121 | 5.8.0 以降の Perl では、(ほとんどの場合) PerlIO がデフォルトです。 |
9724 | 10122 | |
10123 | =item Legacy usage | |
10124 | ||
10125 | (古い使い方) | |
10126 | ||
9725 | 10127 | =begin original |
9726 | 10128 | |
9727 | ||
10129 | This section describes ways to call C<open> outside of best practices; | |
9728 | ||
10130 | you may encounter these uses in older code. Perl does not consider their | |
9729 | ||
10131 | use deprecated, exactly, but neither is it recommended in new code, for | |
10132 | the sake of clarity and readability. | |
9730 | 10133 | |
9731 | 10134 | =end original |
9732 | 10135 | |
9733 | ||
10136 | この節では、ベストプラクティスではない C<open> の呼び出し方について | |
9734 | ||
10137 | 記述します; より古いコードでこれらが使われているのに遭遇するかもしれません。 | |
9735 | ||
10138 | 厳密には、Perl はこれらの仕様を廃止予定にはしていませんが、 | |
9736 | ||
10139 | 明瞭性と可読性のために、新しいコードには薦めません。 | |
9737 | 10140 | |
10141 | =over | |
10142 | ||
10143 | =item Specifying mode and filename as a single argument | |
10144 | ||
10145 | (モードとファイル名を一つの引数で指定する) | |
10146 | ||
9738 | 10147 | =begin original |
9739 | 10148 | |
9740 | I | |
10149 | In the one- and two-argument forms of the call, the mode and filename | |
9741 | ||
10150 | should be concatenated (in that order), preferably separated by white | |
9742 | ||
10151 | space. You can--but shouldn't--omit the mode in these forms when that mode | |
9743 | s | |
10152 | is C<< < >>. It is safe to use the two-argument form of | |
9744 | it | |
10153 | L<C<open>|/open FILEHANDLE,MODE,EXPR> if the filename argument is a known literal. | |
9745 | of the child process, and in the child process it returns (a defined) C<0>. | |
9746 | Use C<defined($pid)> or C<//> to determine whether the open was successful. | |
9747 | 10154 | |
9748 | 10155 | =end original |
9749 | 10156 | |
9750 | 1 引数 | |
10157 | 1 引数 と 2 引数の形式ではモードとファイル名は(この順番で) | |
9751 | ( | |
10158 | 結合されます(空白によって分割されているかもしれません)。 | |
9752 | ||
10159 | この形式で、モードが C<< '<' >> の場合はモードを省略できます (が、 | |
9753 | ||
10160 | するべきではありません)。 | |
9754 | ||
10161 | ファイル引数が既知のリテラルの場合、2 引数形式の | |
9755 | ||
10162 | L<C<open>|/open FILEHANDLE,MODE,EXPR> は安全です。 | |
9756 | open が成功したかどうかを調べるには、C<defined($pid)> または C<//> を | |
9757 | 使います。 | |
9758 | 10163 | |
10164 | open(my $dbase, "+<dbase.mine") # ditto | |
10165 | or die "Can't open 'dbase.mine' for update: $!"; | |
10166 | ||
9759 | 10167 | =begin original |
9760 | 10168 | |
9761 | ||
10169 | In the two-argument (and one-argument) form, opening C<< <- >> | |
10170 | or C<-> opens STDIN and opening C<< >- >> opens STDOUT. | |
9762 | 10171 | |
9763 | 10172 | =end original |
9764 | 10173 | |
9765 | ||
10174 | 2 引数(と 1 引数)で C<< <- >> か C<-> を open すると STDIN が | |
10175 | オープンされ、C<< >- >> を open すると STDOUT がオープンされます。 | |
9766 | 10176 | |
9767 | my $child_pid = open(my $from_kid, "-|") // die "Can't fork: $!"; | |
9768 | ||
9769 | 10177 | =begin original |
9770 | 10178 | |
9771 | or | |
10179 | New code should favor the three-argument form of C<open> over this older | |
10180 | form. Declaring the mode and the filename as two distinct arguments | |
10181 | avoids any confusion between the two. | |
9772 | 10182 | |
9773 | 10183 | =end original |
9774 | 10184 | |
9775 | ||
10185 | 新しいコードでは、このより古い形式ではなく、3 引数形式の C<open> を | |
10186 | 使うべきです。 | |
10187 | モードとファイル名を異なった二つの引数として指定することで、 | |
10188 | 二つの間の混乱を避けられます。 | |
9776 | 10189 | |
9777 | ||
10190 | =item Calling C<open> with one argument via global variables | |
9778 | 10191 | |
10192 | (グローバル変数を使って C<open> を 1 引数で呼び出す) | |
10193 | ||
9779 | 10194 | =begin original |
9780 | 10195 | |
9781 | ||
10196 | As a shortcut, a one-argument call takes the filename from the global | |
10197 | scalar variable of the same name as the filehandle: | |
9782 | 10198 | |
9783 | 10199 | =end original |
9784 | 10200 | |
9785 | ||
10201 | 短縮版として、1 引数呼び出しでは、ファイル名を、ファイルハンドルと同じ名前の | |
10202 | グローバルなスカラ変数から取ります: | |
9786 | 10203 | |
9787 | | |
10204 | $ARTICLE = 100; | |
9788 | ||
10205 | open(ARTICLE) | |
9789 | ||
10206 | or die "Can't find article $ARTICLE: $!\n"; | |
9790 | ... | |
9791 | waitpid $child_pid, 0; | |
9792 | } else { | |
9793 | # am the child; use STDIN/STDOUT normally | |
9794 | ... | |
9795 | exit; | |
9796 | } | |
9797 | 10207 | |
9798 | 10208 | =begin original |
9799 | 10209 | |
9800 | T | |
10210 | Here C<$ARTICLE> must be a global (package) scalar variable - not one | |
9801 | ||
10211 | declared with L<C<my>|/my VARLIST> or L<C<state>|/state VARLIST>. | |
9802 | In the child process, the filehandle isn't opened--I/O happens from/to | |
9803 | the new STDOUT/STDIN. Typically this is used like the normal | |
9804 | piped open when you want to exercise more control over just how the | |
9805 | pipe command gets executed, such as when running setuid and | |
9806 | you don't want to have to scan shell commands for metacharacters. | |
9807 | 10212 | |
9808 | 10213 | =end original |
9809 | 10214 | |
9810 | ||
10215 | ここで C<$ARTICLE> はグローバル(パッケージ)スカラ変数でなければなりません - | |
9811 | ||
10216 | L<C<my>|/my VARLIST> や L<C<state>|/state VARLIST> で宣言された | |
9812 | ||
10217 | 変数ではありません。 | |
9813 | STDIN に対して行なわれます。 | |
9814 | これは、setuid で実行して、シェルコマンドのメタ文字を | |
9815 | 検索させたくないような場合に、パイプコマンドの起動の仕方を | |
9816 | 制御したいとき、普通のパイプの open と同じように使います。 | |
9817 | 10218 | |
10219 | =item Assigning a filehandle to a bareword | |
10220 | ||
10221 | (ファイルハンドルを裸の単語に代入する) | |
10222 | ||
9818 | 10223 | =begin original |
9819 | 10224 | |
9820 | ||
10225 | An older style is to use a bareword as the filehandle, as | |
9821 | 10226 | |
9822 | 10227 | =end original |
9823 | 10228 | |
9824 | ||
10229 | より古いスタイルは、次のように、ファイルハンドルとして裸の単語を使います | |
9825 | 10230 | |
9826 | open( | |
10231 | open(FH, "<", "input.txt") | |
9827 | | |
10232 | or die "Can't open < input.txt: $!"; | |
9828 | open(my $fh, "|-") || exec 'tr', '[a-z]', '[A-Z]'; | |
9829 | open(my $fh, "|-", "tr", '[a-z]', '[A-Z]'); | |
9830 | 10233 | |
9831 | open(my $fh, "cat -n '$file'|"); | |
9832 | open(my $fh, "-|", "cat -n '$file'"); | |
9833 | open(my $fh, "-|") || exec "cat", "-n", $file; | |
9834 | open(my $fh, "-|", "cat", "-n", $file); | |
9835 | ||
9836 | 10234 | =begin original |
9837 | 10235 | |
9838 | The | |
10236 | Then you can use C<FH> as the filehandle, in C<< close FH >> and C<< | |
9839 | ||
10237 | <FH> >> and so on. Note that it's a global variable, so this form is | |
9840 | ||
10238 | not recommended when dealing with filehandles other than Perl's built-in ones (e.g. STDOUT and STDIN). | |
9841 | Unix, including Linux and MacOS X), you can use the list form. You would | |
9842 | want to use the list form of the pipe so you can pass literal arguments | |
9843 | to the command without risk of the shell interpreting any shell metacharacters | |
9844 | in them. However, this also bars you from opening pipes to commands | |
9845 | that intentionally contain shell metacharacters, such as: | |
9846 | 10239 | |
9847 | 10240 | =end original |
9848 | 10241 | |
9849 | それ | |
10242 | それから C<FH> を、C<< close FH >> や C<< <FH> >> などのように、 | |
9850 | ||
10243 | ファイルハンドルとして使えます。 | |
9851 | ||
10244 | これはグローバル変数なので、Perl の組み込みのもの (例えば STDOUT と STDIN) | |
9852 | ||
10245 | 以外では非推奨であることに注意してください。 | |
9853 | MacOS X を含む Unix なら)リスト形式が使えます。 | |
9854 | パイプのリスト形式を使うことで、コマンドへのリテラルな引数を、 | |
9855 | シェルのメタ文字をシェルが解釈するリスクなしに渡すことができます。 | |
9856 | しかし、これは以下のように意図的にシェルメタ文字を含むコマンドをパイプとして | |
9857 | 開くことを妨げます: | |
9858 | 10246 | |
9859 | ||
10247 | =back | |
9860 | || die "Can't open pipeline to lpr: $!"; | |
9861 | 10248 | |
10249 | =item Other considerations | |
10250 | ||
10251 | (その他の考慮点) | |
10252 | ||
10253 | =over | |
10254 | ||
10255 | =item Automatic filehandle closure | |
10256 | ||
10257 | (自動的にファイルハンドルを閉じる) | |
10258 | ||
9862 | 10259 | =begin original |
9863 | 10260 | |
9864 | ||
10261 | The filehandle will be closed when its reference count reaches zero. If | |
10262 | it is a lexically scoped variable declared with L<C<my>|/my VARLIST>, | |
10263 | that usually means the end of the enclosing scope. However, this | |
10264 | automatic close does not check for errors, so it is better to explicitly | |
10265 | close filehandles, especially those used for writing: | |
9865 | 10266 | |
9866 | 10267 | =end original |
9867 | 10268 | |
9868 | ||
10269 | ファイルハンドルは、参照カウントが 0 になったときに閉じられます。 | |
9869 | ||
10270 | これが L<C<my>|/my VARLIST> で宣言されたレキシカルスコープを持つ変数の場合、 | |
10271 | 普通は囲まれたスコープの終わりを意味します。 | |
10272 | しかし、この自動閉じはエラーをチェックしないので、特に書き込み用の場合は、 | |
10273 | 明示的にファイルハンドルを閉じる方がよいです。 | |
9870 | 10274 | |
10275 | close($handle) | |
10276 | || warn "close failed: $!"; | |
10277 | ||
10278 | =item Automatic pipe flushing | |
10279 | ||
10280 | (パイプの自動フラッシュ) | |
10281 | ||
9871 | 10282 | =begin original |
9872 | 10283 | |
9873 | 10284 | Perl will attempt to flush all files opened for |
9874 | 10285 | output before any operation that may do a fork, but this may not be |
9875 | 10286 | supported on some platforms (see L<perlport>). To be safe, you may need |
9876 | 10287 | to set L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>) |
9877 | 10288 | or call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS> |
9878 | 10289 | on any open handles. |
9879 | 10290 | |
9880 | 10291 | =end original |
9881 | 10292 | |
9882 | 10293 | v5.6.0 から、Perl は書き込み用に開いている全てのファイルに対して |
9883 | 10294 | fork を行う前にフラッシュしようとしますが、これに対応していない |
9884 | 10295 | プラットフォームもあります(L<perlport> を参照してください)。 |
9885 | 10296 | 安全のために、L<C<$E<verbar>>|perlvar/$E<verbar>> (L<English> モジュールでは |
9886 | 10297 | C<$AUTOFLUSH>) をセットするか、全ての開いているハンドルに対して |
9887 | 10298 | L<C<IO::Handle>|IO::Handle/METHODS> の C<autoflush> メソッドを |
9888 | 10299 | 呼び出す必要があるかもしれません。 |
9889 | 10300 | |
9890 | 10301 | =begin original |
9891 | 10302 | |
9892 | 10303 | On systems that support a close-on-exec flag on files, the flag will |
9893 | 10304 | be set for the newly opened file descriptor as determined by the value |
9894 | 10305 | of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>. |
9895 | 10306 | |
9896 | 10307 | =end original |
9897 | 10308 | |
9898 | 10309 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
9899 | 10310 | フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた |
9900 | 10311 | ファイル記述子に対してセットされます。 |
9901 | 10312 | L<perlvar/$^F> を参照してください。 |
9902 | 10313 | |
9903 | 10314 | =begin original |
9904 | 10315 | |
9905 | 10316 | Closing any piped filehandle causes the parent process to wait for the |
9906 | 10317 | child to finish, then returns the status value in L<C<$?>|perlvar/$?> and |
9907 | 10318 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>. |
9908 | 10319 | |
9909 | 10320 | =end original |
9910 | 10321 | |
9911 | 10322 | パイプのファイルハンドルを close することで、親プロセスは、子プロセスの終了を |
9912 | 10323 | 待ち、それから L<C<$?>|perlvar/$?> と |
9913 | 10324 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> にステータス値を |
9914 | 10325 | 返します。 |
9915 | 10326 | |
10327 | =item Direct versus by-reference assignment of filehandles | |
10328 | ||
10329 | (ファイルハンドルの直接代入とリファレンスによる代入) | |
10330 | ||
9916 | 10331 | =begin original |
9917 | 10332 | |
10333 | If FILEHANDLE -- the first argument in a call to C<open> -- is an | |
10334 | undefined scalar variable (or array or hash element), a new filehandle | |
10335 | is autovivified, meaning that the variable is assigned a reference to a | |
10336 | newly allocated anonymous filehandle. Otherwise if FILEHANDLE is an | |
10337 | expression, its value is the real filehandle. (This is considered a | |
10338 | symbolic reference, so C<use strict "refs"> should I<not> be in effect.) | |
10339 | ||
10340 | =end original | |
10341 | ||
10342 | FILEHANDLE (C<open> を呼び出すときの最初の引数) が未定義のスカラ変数 | |
10343 | (または配列かハッシュの要素)の場合、 | |
10344 | 新しいファイルハンドルが自動有効化され、その変数は新しく割り当てられた | |
10345 | 無名ファイルハンドルへのリファレンスが代入されます。 | |
10346 | さもなければ、もし FILEHANDLE が式なら、その値を求めている実際の | |
10347 | ファイルハンドルの名前として使います。 | |
10348 | (これはシンボリックリファレンスとして扱われるので、 | |
10349 | C<use strict "refs"> の影響を I<受けません>。) | |
10350 | ||
10351 | =item Whitespace and special characters in the filename argument | |
10352 | ||
10353 | (ファイル名引数の空白と特殊文字) | |
10354 | ||
10355 | =begin original | |
10356 | ||
9918 | 10357 | The filename passed to the one- and two-argument forms of |
9919 | L<C<open>|/open FILEHANDLE,EXPR> will | |
10358 | L<C<open>|/open FILEHANDLE,MODE,EXPR> will | |
9920 | 10359 | have leading and trailing whitespace deleted and normal |
9921 | 10360 | redirection characters honored. This property, known as "magic open", |
9922 | 10361 | can often be used to good effect. A user could specify a filename of |
9923 | 10362 | F<"rsh cat file |">, or you could change certain filenames as needed: |
9924 | 10363 | |
9925 | 10364 | =end original |
9926 | 10365 | |
9927 | 1 引数 と 2 引数の形の L<C<open>|/open FILEHANDLE,EXPR> に渡された | |
10366 | 1 引数 と 2 引数の形の L<C<open>|/open FILEHANDLE,MODE,EXPR> に渡された | |
9928 | 10367 | ファイル名は、はじめと終わりの空白が取り除かれ、通常のリダイレクト文字列を |
9929 | 10368 | 受け付けます。 |
9930 | 10369 | この機能は "magic open" として知られていますが、普通いい効果をもたらします。 |
9931 | 10370 | ユーザーは F<"rsh cat file |"> といったファイル名を指定できますし、 |
9932 | 10371 | 特定のファイル名を必要に応じて変更できます。 |
9933 | 10372 | |
9934 | 10373 | $filename =~ s/(.*\.gz)\s*$/gzip -dc < $1|/; |
9935 | open(my $fh, $filename) | |
10374 | open(my $fh, $filename) | |
10375 | or die "Can't open $filename: $!"; | |
9936 | 10376 | |
9937 | 10377 | =begin original |
9938 | 10378 | |
9939 | 10379 | Use the three-argument form to open a file with arbitrary weird characters in it, |
9940 | 10380 | |
9941 | 10381 | =end original |
9942 | 10382 | |
9943 | 10383 | 妙な文字が含まれているようなファイル名をオープンするには、 |
9944 | 10384 | 3 引数の形を使います。 |
9945 | 10385 | |
9946 | 10386 | open(my $fh, "<", $file) |
9947 | || die "Can't open $file: $!"; | |
10387 | || die "Can't open $file: $!"; | |
9948 | 10388 | |
9949 | 10389 | =begin original |
9950 | 10390 | |
9951 | 10391 | otherwise it's necessary to protect any leading and trailing whitespace: |
9952 | 10392 | |
9953 | 10393 | =end original |
9954 | 10394 | |
9955 | 10395 | あるいは、次のようにして、最初と最後の空白を保護します: |
9956 | 10396 | |
9957 | 10397 | $file =~ s#^(\s)#./$1#; |
9958 | 10398 | open(my $fh, "< $file\0") |
9959 | || die "Can't open $file: $!"; | |
10399 | || die "Can't open $file: $!"; | |
9960 | 10400 | |
9961 | 10401 | =begin original |
9962 | 10402 | |
9963 | 10403 | (this may not work on some bizarre filesystems). One should |
9964 | 10404 | conscientiously choose between the I<magic> and I<three-argument> form |
9965 | of L<C<open>|/open FILEHANDLE,EXPR>: | |
10405 | of L<C<open>|/open FILEHANDLE,MODE,EXPR>: | |
9966 | 10406 | |
9967 | 10407 | =end original |
9968 | 10408 | |
9969 | 10409 | (これは奇妙なファイルシステムでは動作しないかもしれません)。 |
9970 | L<C<open>|/open FILEHANDLE,EXPR> の I<magic> と I<3 引数> 形式を誠実に | |
10410 | L<C<open>|/open FILEHANDLE,MODE,EXPR> の I<magic> と I<3 引数> 形式を誠実に | |
9971 | 10411 | 選択するべきです。 |
9972 | 10412 | |
9973 | 10413 | open(my $in, $ARGV[0]) || die "Can't open $ARGV[0]: $!"; |
9974 | 10414 | |
9975 | 10415 | =begin original |
9976 | 10416 | |
9977 | 10417 | will allow the user to specify an argument of the form C<"rsh cat file |">, |
9978 | 10418 | but will not work on a filename that happens to have a trailing space, while |
9979 | 10419 | |
9980 | 10420 | =end original |
9981 | 10421 | |
9982 | 10422 | とするとユーザーは C<"rsh cat file |"> という形の引数を指定できますが、 |
9983 | 10423 | 末尾にスペースがついてしまったファイル名では動作しません; 一方: |
9984 | 10424 | |
9985 | 10425 | open(my $in, "<", $ARGV[0]) |
9986 | || die "Can't open $ARGV[0]: $!"; | |
10426 | || die "Can't open $ARGV[0]: $!"; | |
9987 | 10427 | |
9988 | 10428 | =begin original |
9989 | 10429 | |
9990 | 10430 | will have exactly the opposite restrictions. (However, some shells |
9991 | 10431 | support the syntax C<< perl your_program.pl <( rsh cat file ) >>, which |
9992 | 10432 | produces a filename that can be opened normally.) |
9993 | 10433 | |
9994 | 10434 | =end original |
9995 | 10435 | |
9996 | 10436 | はまったく逆の制限があります。 |
9997 | 10437 | (しかし、一部のシェルは C<< perl your_program.pl <( rsh cat file ) >> という |
9998 | 10438 | 文法に対応していて、普通に開くことが出来るファイル名を出力します。) |
9999 | 10439 | |
10440 | =item Invoking C-style C<open> | |
10441 | ||
10442 | (C 形式の C<open> の起動) | |
10443 | ||
10000 | 10444 | =begin original |
10001 | 10445 | |
10002 | 10446 | If you want a "real" C L<open(2)>, then you should use the |
10003 | 10447 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> function, which involves |
10004 | 10448 | no such magic (but uses different filemodes than Perl |
10005 | L<C<open>|/open FILEHANDLE,EXPR>, which corresponds to C L<fopen(3)>). | |
10449 | L<C<open>|/open FILEHANDLE,MODE,EXPR>, which corresponds to C L<fopen(3)>). | |
10006 | 10450 | This is another way to protect your filenames from interpretation. For |
10007 | 10451 | example: |
10008 | 10452 | |
10009 | 10453 | =end original |
10010 | 10454 | |
10011 | 10455 | もし「本当の」C 言語の L<open(2)> が必要なら、このような副作用のない |
10012 | 10456 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> 関数を使うべきです |
10013 | 10457 | (ただし、C の L<fopen(3)> に対応する Perl の |
10014 | L<C<open>|/open FILEHANDLE,EXPR> とは違うファイルモードを持ちます)。 | |
10458 | L<C<open>|/open FILEHANDLE,MODE,EXPR> とは違うファイルモードを持ちます)。 | |
10015 | 10459 | これはファイル名を解釈から守るもう一つの方法です。 |
10016 | 10460 | 例えば: |
10017 | 10461 | |
10018 | 10462 | use IO::Handle; |
10019 | 10463 | sysopen(my $fh, $path, O_RDWR|O_CREAT|O_EXCL) |
10020 | 10464 | or die "Can't open $path: $!"; |
10021 | 10465 | $fh->autoflush(1); |
10022 | 10466 | print $fh "stuff $$\n"; |
10023 | 10467 | seek($fh, 0, 0); |
10024 | 10468 | print "File contains: ", readline($fh); |
10025 | 10469 | |
10026 | 10470 | =begin original |
10027 | 10471 | |
10028 | 10472 | See L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> for some details about |
10029 | 10473 | mixing reading and writing. |
10030 | 10474 | |
10031 | 10475 | =end original |
10032 | 10476 | |
10033 | 10477 | 読み書きを混ぜる場合の詳細については |
10034 | 10478 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> を参照してください。 |
10035 | 10479 | |
10480 | =item Portability issues | |
10481 | ||
10482 | (移植性の問題) | |
10483 | ||
10036 | 10484 | =begin original |
10037 | 10485 | |
10038 | ||
10486 | See L<perlport/open>. | |
10039 | 10487 | |
10040 | 10488 | =end original |
10041 | 10489 | |
10042 | ||
10490 | L<perlport/open> を参照してください。 | |
10043 | 10491 | |
10492 | =back | |
10493 | ||
10494 | =back | |
10495 | ||
10044 | 10496 | =item opendir DIRHANDLE,EXPR |
10045 | 10497 | X<opendir> |
10046 | 10498 | |
10047 | 10499 | =for Pod::Functions open a directory |
10048 | 10500 | |
10049 | 10501 | =begin original |
10050 | 10502 | |
10051 | 10503 | Opens a directory named EXPR for processing by |
10052 | 10504 | L<C<readdir>|/readdir DIRHANDLE>, L<C<telldir>|/telldir DIRHANDLE>, |
10053 | 10505 | L<C<seekdir>|/seekdir DIRHANDLE,POS>, |
10054 | 10506 | L<C<rewinddir>|/rewinddir DIRHANDLE>, and |
10055 | 10507 | L<C<closedir>|/closedir DIRHANDLE>. Returns true if successful. |
10056 | 10508 | DIRHANDLE may be an expression whose value can be used as an indirect |
10057 | 10509 | dirhandle, usually the real dirhandle name. If DIRHANDLE is an undefined |
10058 | 10510 | scalar variable (or array or hash element), the variable is assigned a |
10059 | 10511 | reference to a new anonymous dirhandle; that is, it's autovivified. |
10060 | D | |
10512 | Dirhandles are the same objects as filehandles; an I/O object can only | |
10513 | be open as one of these handle types at once. | |
10061 | 10514 | |
10062 | 10515 | =end original |
10063 | 10516 | |
10064 | 10517 | L<C<readdir>|/readdir DIRHANDLE>、L<C<telldir>|/telldir DIRHANDLE>、 |
10065 | 10518 | L<C<seekdir>|/seekdir DIRHANDLE,POS>、L<C<rewinddir>|/rewinddir DIRHANDLE>、 |
10066 | 10519 | L<C<closedir>|/closedir DIRHANDLE> で処理するために、EXPR で指定された名前の |
10067 | 10520 | ディレクトリをオープンします。 |
10068 | 10521 | 成功時には真を返します。 |
10069 | 10522 | DIRHANDLE は間接ディレクトリハンドルとして使える値(普通は実際のディレクトリ |
10070 | 10523 | ハンドルの名前)となる式でも構いません。 |
10071 | 10524 | DIRHANDLE が未定義のスカラ値(または配列かハッシュの要素)の場合、その変数は |
10072 | 10525 | 新しい無名ディレクトリハンドルへのリファレンスが代入されます; つまり、 |
10073 | 10526 | 自動有効化されます。 |
10074 | ||
10527 | ディレクトリハンドルはファイルハンドルと同じオブジェクトです; | |
10528 | 一つの I/O オブジェクトは同時にこれらのハンドル型のどちらかとしてのみ | |
10529 | 開くことができます。 | |
10075 | 10530 | |
10076 | 10531 | =begin original |
10077 | 10532 | |
10078 | 10533 | See the example at L<C<readdir>|/readdir DIRHANDLE>. |
10079 | 10534 | |
10080 | 10535 | =end original |
10081 | 10536 | |
10082 | 10537 | L<C<readdir>|/readdir DIRHANDLE> の例を参照してください。 |
10083 | 10538 | |
10084 | 10539 | =item ord EXPR |
10085 | 10540 | X<ord> X<encoding> |
10086 | 10541 | |
10087 | 10542 | =item ord |
10088 | 10543 | |
10089 | 10544 | =for Pod::Functions find a character's numeric representation |
10090 | 10545 | |
10091 | 10546 | =begin original |
10092 | 10547 | |
10093 | 10548 | Returns the numeric value of the first character of EXPR. |
10094 | 10549 | If EXPR is an empty string, returns 0. If EXPR is omitted, uses |
10095 | 10550 | L<C<$_>|perlvar/$_>. |
10096 | 10551 | (Note I<character>, not byte.) |
10097 | 10552 | |
10098 | 10553 | =end original |
10099 | 10554 | |
10100 | 10555 | EXPR の最初の文字の数値としての値を返します。 |
10101 | 10556 | EXPR が空文字列の場合は、0 を返します。 |
10102 | 10557 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 |
10103 | 10558 | (バイトではなく I<文字> であることに注意してください。) |
10104 | 10559 | |
10105 | 10560 | =begin original |
10106 | 10561 | |
10107 | 10562 | For the reverse, see L<C<chr>|/chr NUMBER>. |
10108 | 10563 | See L<perlunicode> for more about Unicode. |
10109 | 10564 | |
10110 | 10565 | =end original |
10111 | 10566 | |
10112 | 10567 | 逆のことをするには L<C<chr>|/chr NUMBER> を参照してください。 |
10113 | 10568 | Unicode については L<perlunicode> を参照してください。 |
10114 | 10569 | |
10115 | 10570 | =item our VARLIST |
10116 | 10571 | X<our> X<global> |
10117 | 10572 | |
10118 | 10573 | =item our TYPE VARLIST |
10119 | 10574 | |
10120 | 10575 | =item our VARLIST : ATTRS |
10121 | 10576 | |
10122 | 10577 | =item our TYPE VARLIST : ATTRS |
10123 | 10578 | |
10124 | 10579 | =for Pod::Functions +5.6.0 declare and assign a package variable (lexical scoping) |
10125 | 10580 | |
10126 | 10581 | =begin original |
10127 | 10582 | |
10128 | 10583 | L<C<our>|/our VARLIST> makes a lexical alias to a package (i.e. global) |
10129 | 10584 | variable of the same name in the current package for use within the |
10130 | 10585 | current lexical scope. |
10131 | 10586 | |
10132 | 10587 | =end original |
10133 | 10588 | |
10134 | 10589 | L<C<our>|/our VARLIST> は単純名を、現在のレキシカルスコープ内で使うために、 |
10135 | 10590 | 現在のパッケージの同じ名前のパッケージ(つまりグローバルな)変数への |
10136 | 10591 | レキシカルな別名を作ります。 |
10137 | 10592 | |
10138 | 10593 | =begin original |
10139 | 10594 | |
10140 | 10595 | L<C<our>|/our VARLIST> has the same scoping rules as |
10141 | 10596 | L<C<my>|/my VARLIST> or L<C<state>|/state VARLIST>, meaning that it is |
10142 | 10597 | only valid within a lexical scope. Unlike L<C<my>|/my VARLIST> and |
10143 | 10598 | L<C<state>|/state VARLIST>, which both declare new (lexical) variables, |
10144 | 10599 | L<C<our>|/our VARLIST> only creates an alias to an existing variable: a |
10145 | 10600 | package variable of the same name. |
10146 | 10601 | |
10147 | 10602 | =end original |
10148 | 10603 | |
10149 | 10604 | L<C<our>|/our VARLIST> は L<C<my>|/my VARLIST> や |
10150 | 10605 | L<C<state>|/state VARLIST> と同じスコープルールを持ちます; つまり |
10151 | 10606 | レキシカルスコープの中でだけ有効です。 |
10152 | 10607 | 新しい(レキシカル)変数を宣言する L<C<my>|/my VARLIST> や |
10153 | 10608 | L<C<state>|/state VARLIST> と異なり、L<C<our>|/our VARLIST> は既に |
10154 | 10609 | 存在する変数への別名を作るだけです: 同じ名前のパッケージ変数です。 |
10155 | 10610 | |
10156 | 10611 | =begin original |
10157 | 10612 | |
10158 | 10613 | This means that when C<use strict 'vars'> is in effect, L<C<our>|/our |
10159 | 10614 | VARLIST> lets you use a package variable without qualifying it with the |
10160 | 10615 | package name, but only within the lexical scope of the |
10161 | 10616 | L<C<our>|/our VARLIST> declaration. This applies immediately--even |
10162 | 10617 | within the same statement. |
10163 | 10618 | |
10164 | 10619 | =end original |
10165 | 10620 | |
10166 | 10621 | つまり、C<use strict 'vars'> が有効の場合は、L<C<our>|/our VARLIST> を |
10167 | 10622 | 使うことで、 |
10168 | 10623 | パッケージ変数をパッケージ名で修飾することなく使うことができますが、 |
10169 | 10624 | L<C<our>|/our VARLIST> 宣言のレキシカルスコープ内だけということです。 |
10170 | 10625 | これは(たとえ同じ文の中でも)直ちに適用されます。 |
10171 | 10626 | |
10172 | 10627 | package Foo; |
10173 | 10628 | use strict; |
10174 | 10629 | |
10175 | 10630 | $Foo::foo = 23; |
10176 | 10631 | |
10177 | 10632 | { |
10178 | 10633 | our $foo; # alias to $Foo::foo |
10179 | 10634 | print $foo; # prints 23 |
10180 | 10635 | } |
10181 | 10636 | |
10182 | 10637 | print $Foo::foo; # prints 23 |
10183 | 10638 | |
10184 | 10639 | print $foo; # ERROR: requires explicit package name |
10185 | 10640 | |
10186 | 10641 | =begin original |
10187 | 10642 | |
10188 | 10643 | This works even if the package variable has not been used before, as |
10189 | 10644 | package variables spring into existence when first used. |
10190 | 10645 | |
10191 | 10646 | =end original |
10192 | 10647 | |
10193 | 10648 | これはパッケージ変数がまだ使われていなくても動作します; パッケージ変数は、 |
10194 | 10649 | 最初に使われた時にひょっこり現れるからです。 |
10195 | 10650 | |
10196 | 10651 | package Foo; |
10197 | 10652 | use strict; |
10198 | 10653 | |
10199 | 10654 | our $foo = 23; # just like $Foo::foo = 23 |
10200 | 10655 | |
10201 | 10656 | print $Foo::foo; # prints 23 |
10202 | 10657 | |
10203 | 10658 | =begin original |
10204 | 10659 | |
10205 | 10660 | Because the variable becomes legal immediately under C<use strict 'vars'>, so |
10206 | 10661 | long as there is no variable with that name is already in scope, you can then |
10207 | 10662 | reference the package variable again even within the same statement. |
10208 | 10663 | |
10209 | 10664 | =end original |
10210 | 10665 | |
10211 | 10666 | 変数は C<use strict 'vars'> の基で直ちに正当になるので、 |
10212 | 10667 | スコープ内に同じ名前の変数がない限り、 |
10213 | 10668 | たとえ同じ文の中でもパッケージ変数を再び参照できます。 |
10214 | 10669 | |
10215 | 10670 | package Foo; |
10216 | 10671 | use strict; |
10217 | 10672 | |
10218 | 10673 | my $foo = $foo; # error, undeclared $foo on right-hand side |
10219 | 10674 | our $foo = $foo; # no errors |
10220 | 10675 | |
10221 | 10676 | =begin original |
10222 | 10677 | |
10223 | 10678 | If more than one variable is listed, the list must be placed |
10224 | 10679 | in parentheses. |
10225 | 10680 | |
10226 | 10681 | =end original |
10227 | 10682 | |
10228 | 10683 | 複数の変数を指定する場合は、リストはかっこでくくらなければなりません。 |
10229 | 10684 | |
10230 | 10685 | our($bar, $baz); |
10231 | 10686 | |
10232 | 10687 | =begin original |
10233 | 10688 | |
10234 | 10689 | An L<C<our>|/our VARLIST> declaration declares an alias for a package |
10235 | 10690 | variable that will be visible |
10236 | 10691 | across its entire lexical scope, even across package boundaries. The |
10237 | 10692 | package in which the variable is entered is determined at the point |
10238 | 10693 | of the declaration, not at the point of use. This means the following |
10239 | 10694 | behavior holds: |
10240 | 10695 | |
10241 | 10696 | =end original |
10242 | 10697 | |
10243 | 10698 | L<C<our>|/our VARLIST> 宣言はレキシカルスコープ全体に対して (たとえ |
10244 | 10699 | パッケージ境界を越えていても)見える、パッケージ変数への別名を宣言します。 |
10245 | 10700 | この変数が入るパッケージは宣言した時点で定義され、 |
10246 | 10701 | 使用した時点ではありません。 |
10247 | 10702 | これにより、以下のような振る舞いになります: |
10248 | 10703 | |
10249 | 10704 | package Foo; |
10250 | 10705 | our $bar; # declares $Foo::bar for rest of lexical scope |
10251 | 10706 | $bar = 20; |
10252 | 10707 | |
10253 | 10708 | package Bar; |
10254 | 10709 | print $bar; # prints 20, as it refers to $Foo::bar |
10255 | 10710 | |
10256 | 10711 | =begin original |
10257 | 10712 | |
10258 | 10713 | Multiple L<C<our>|/our VARLIST> declarations with the same name in the |
10259 | 10714 | same lexical |
10260 | 10715 | scope are allowed if they are in different packages. If they happen |
10261 | 10716 | to be in the same package, Perl will emit warnings if you have asked |
10262 | 10717 | for them, just like multiple L<C<my>|/my VARLIST> declarations. Unlike |
10263 | 10718 | a second L<C<my>|/my VARLIST> declaration, which will bind the name to a |
10264 | 10719 | fresh variable, a second L<C<our>|/our VARLIST> declaration in the same |
10265 | 10720 | package, in the same scope, is merely redundant. |
10266 | 10721 | |
10267 | 10722 | =end original |
10268 | 10723 | |
10269 | 10724 | 同じレキシカルスコープでも、パッケージが異なっていれば、同じ名前で複数の |
10270 | 10725 | L<C<our>|/our VARLIST> 宣言ができます。 |
10271 | 10726 | 同じパッケージになっていると、警告が出力されるようになっていれば |
10272 | 10727 | 複数の L<C<my>|/my VARLIST> 宣言がある場合と同じように警告が出力されます。 |
10273 | 10728 | 新しい変数を名前に割り当てることになる 2 回目の L<C<my>|/my VARLIST> 宣言と |
10274 | 10729 | 違って、同じパッケージの同じスコープで 2 回 |
10275 | 10730 | L<C<our>|/our VARLIST> 宣言するのは単に冗長です。 |
10276 | 10731 | |
10277 | 10732 | use warnings; |
10278 | 10733 | package Foo; |
10279 | 10734 | our $bar; # declares $Foo::bar for rest of lexical scope |
10280 | 10735 | $bar = 20; |
10281 | 10736 | |
10282 | 10737 | package Bar; |
10283 | 10738 | our $bar = 30; # declares $Bar::bar for rest of lexical scope |
10284 | 10739 | print $bar; # prints 30 |
10285 | 10740 | |
10286 | 10741 | our $bar; # emits warning but has no other effect |
10287 | 10742 | print $bar; # still prints 30 |
10288 | 10743 | |
10289 | 10744 | =begin original |
10290 | 10745 | |
10291 | 10746 | An L<C<our>|/our VARLIST> declaration may also have a list of attributes |
10292 | 10747 | associated with it. |
10293 | 10748 | |
10294 | 10749 | =end original |
10295 | 10750 | |
10296 | 10751 | L<C<our>|/our VARLIST> 宣言には、それと結び付けられる属性のリストを |
10297 | 10752 | 持つこともあります。 |
10298 | 10753 | |
10299 | 10754 | =begin original |
10300 | 10755 | |
10301 | 10756 | The exact semantics and interface of TYPE and ATTRS are still |
10302 | 10757 | evolving. TYPE is currently bound to the use of the L<fields> pragma, |
10303 | 10758 | and attributes are handled using the L<attributes> pragma, or, starting |
10304 | 10759 | from Perl 5.8.0, also via the L<Attribute::Handlers> module. See |
10305 | 10760 | L<perlsub/"Private Variables via my()"> for details. |
10306 | 10761 | |
10307 | 10762 | =end original |
10308 | 10763 | |
10309 | 10764 | TYPE と ATTRS の正確な文法とインターフェースは今でも進化しています。 |
10310 | 10765 | 現在のところ、TYPE は L<fields> プラグマの使用と結び付けられていて、 |
10311 | 10766 | 属性は L<attributes> プラグマか、Perl 5.8.0 からは |
10312 | 10767 | L<Attribute::Handlers> モジュールと結び付けられています。 |
10313 | 10768 | 詳しくは L<perlsub/"Private Variables via my()"> を参照してください。 |
10314 | 10769 | |
10315 | 10770 | =begin original |
10316 | 10771 | |
10317 | 10772 | Note that with a parenthesised list, L<C<undef>|/undef EXPR> can be used |
10318 | 10773 | as a dummy placeholder, for example to skip assignment of initial |
10319 | 10774 | values: |
10320 | 10775 | |
10321 | 10776 | =end original |
10322 | 10777 | |
10323 | 10778 | かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> は、例えば初期値の代入を |
10324 | 10779 | 飛ばすために、ダミーのプレースホルダとして使えることに注意してください: |
10325 | 10780 | |
10326 | 10781 | our ( undef, $min, $hour ) = localtime; |
10327 | 10782 | |
10328 | 10783 | =begin original |
10329 | 10784 | |
10330 | 10785 | L<C<our>|/our VARLIST> differs from L<C<use vars>|vars>, which allows |
10331 | 10786 | use of an unqualified name I<only> within the affected package, but |
10332 | 10787 | across scopes. |
10333 | 10788 | |
10334 | 10789 | =end original |
10335 | 10790 | |
10336 | 10791 | L<C<our>|/our VARLIST> は L<C<use vars>|vars> と異なります; スコープを |
10337 | 10792 | またぐのではなく、影響するパッケージの内側 I<のみ> で完全修飾されていない |
10338 | 10793 | 名前を使えるようにします。 |
10339 | 10794 | |
10340 | 10795 | =item pack TEMPLATE,LIST |
10341 | 10796 | X<pack> |
10342 | 10797 | |
10343 | 10798 | =for Pod::Functions convert a list into a binary representation |
10344 | 10799 | |
10345 | 10800 | =begin original |
10346 | 10801 | |
10347 | 10802 | Takes a LIST of values and converts it into a string using the rules |
10348 | 10803 | given by the TEMPLATE. The resulting string is the concatenation of |
10349 | 10804 | the converted values. Typically, each converted value looks |
10350 | 10805 | like its machine-level representation. For example, on 32-bit machines |
10351 | 10806 | an integer may be represented by a sequence of 4 bytes, which will in |
10352 | 10807 | Perl be presented as a string that's 4 characters long. |
10353 | 10808 | |
10354 | 10809 | =end original |
10355 | 10810 | |
10356 | 10811 | LIST の値を TEMPLATE で与えられたルールを用いて文字列に変換します。 |
10357 | 10812 | 結果の文字列は変換した値を連結したものです。 |
10358 | 10813 | 典型的には、それぞれの変換された値はマシンレベルの表現のように見えます。 |
10359 | 10814 | 例えば、32-bit マシンでは、整数は 4 バイトで表現されるので、 |
10360 | 10815 | Perl では 4 文字の文字列で表現されます。 |
10361 | 10816 | |
10362 | 10817 | =begin original |
10363 | 10818 | |
10364 | 10819 | See L<perlpacktut> for an introduction to this function. |
10365 | 10820 | |
10366 | 10821 | =end original |
10367 | 10822 | |
10368 | 10823 | この関数の説明については L<perlpacktut> を参照してください。 |
10369 | 10824 | |
10370 | 10825 | =begin original |
10371 | 10826 | |
10372 | 10827 | The TEMPLATE is a sequence of characters that give the order and type |
10373 | 10828 | of values, as follows: |
10374 | 10829 | |
10375 | 10830 | =end original |
10376 | 10831 | |
10377 | 10832 | TEMPLATE は、以下のような値の型と順番を指定する文字を並べたものです: |
10378 | 10833 | |
10379 | 10834 | =begin original |
10380 | 10835 | |
10381 | 10836 | a A string with arbitrary binary data, will be null padded. |
10382 | 10837 | A A text (ASCII) string, will be space padded. |
10383 | 10838 | Z A null-terminated (ASCIZ) string, will be null padded. |
10384 | 10839 | |
10385 | 10840 | =end original |
10386 | 10841 | |
10387 | 10842 | a 任意のバイナリデータを含む文字列、ヌル文字で埋める。 |
10388 | 10843 | A テキスト (ASCII) 文字列、スペース文字で埋める。 |
10389 | 10844 | Z ヌル文字終端 (ASCIZ) 文字列、ヌル文字で埋める。 |
10390 | 10845 | |
10391 | 10846 | =begin original |
10392 | 10847 | |
10393 | 10848 | b A bit string (ascending bit order inside each byte, |
10394 | 10849 | like vec()). |
10395 | 10850 | B A bit string (descending bit order inside each byte). |
10396 | 10851 | h A hex string (low nybble first). |
10397 | 10852 | H A hex string (high nybble first). |
10398 | 10853 | |
10399 | 10854 | =end original |
10400 | 10855 | |
10401 | 10856 | b ビット列 (バイトごとに昇ビット順、vec() と同じ)。 |
10402 | 10857 | B ビット列 (バイトごとに降ビット順)。 |
10403 | 10858 | h 16 進数文字列 (低位ニブルが先)。 |
10404 | 10859 | H 16 進数文字列 (高位ニブルが先)。 |
10405 | 10860 | |
10406 | 10861 | =begin original |
10407 | 10862 | |
10408 | 10863 | c A signed char (8-bit) value. |
10409 | 10864 | C An unsigned char (octet) value. |
10410 | 10865 | W An unsigned char value (can be greater than 255). |
10411 | 10866 | |
10412 | 10867 | =end original |
10413 | 10868 | |
10414 | 10869 | c signed char (8 ビット) 値。 |
10415 | 10870 | C unsigned char (オクテット) 値。 |
10416 | 10871 | W unsigned char 値 (255 より大きいかもしれません)。 |
10417 | 10872 | |
10418 | 10873 | =begin original |
10419 | 10874 | |
10420 | 10875 | s A signed short (16-bit) value. |
10421 | 10876 | S An unsigned short value. |
10422 | 10877 | |
10423 | 10878 | =end original |
10424 | 10879 | |
10425 | 10880 | s signed short (16 ビット) 値。 |
10426 | 10881 | S unsigned short 値。 |
10427 | 10882 | |
10428 | 10883 | =begin original |
10429 | 10884 | |
10430 | 10885 | l A signed long (32-bit) value. |
10431 | 10886 | L An unsigned long value. |
10432 | 10887 | |
10433 | 10888 | =end original |
10434 | 10889 | |
10435 | 10890 | l signed long (32 ビット) 値。 |
10436 | 10891 | L unsigned long 値。 |
10437 | 10892 | |
10438 | 10893 | =begin original |
10439 | 10894 | |
10440 | 10895 | q A signed quad (64-bit) value. |
10441 | 10896 | Q An unsigned quad value. |
10442 | 10897 | (Quads are available only if your system supports 64-bit |
10443 | 10898 | integer values _and_ if Perl has been compiled to support |
10444 | 10899 | those. Raises an exception otherwise.) |
10445 | 10900 | |
10446 | 10901 | =end original |
10447 | 10902 | |
10448 | 10903 | q 符号付き 64 ビット整数。 |
10449 | 10904 | Q 符号なし 64 ビット整数。 |
10450 | 10905 | (64 ビット整数は、システムが 64 ビット整数に対応していて、かつ Perl が |
10451 | 10906 | 64 ビット整数対応としてコンパイルされている場合にのみ使用可能です。 |
10452 | 10907 | それ以外の場合は例外が発生します。) |
10453 | 10908 | |
10454 | 10909 | =begin original |
10455 | 10910 | |
10456 | 10911 | i A signed integer value. |
10457 | I A unsigned integer value. | |
10912 | I An unsigned integer value. | |
10458 | 10913 | (This 'integer' is _at_least_ 32 bits wide. Its exact |
10459 | 10914 | size depends on what a local C compiler calls 'int'.) |
10460 | 10915 | |
10461 | 10916 | =end original |
10462 | 10917 | |
10463 | 10918 | i signed int 値。 |
10464 | 10919 | I unsigned int 値。 |
10465 | 10920 | (ここでの 'integer' は 「最低」 32 ビット幅です。正確なサイズは |
10466 | 10921 | ローカルの C コンパイラの 'int' のサイズに依存します。) |
10467 | 10922 | |
10468 | 10923 | =begin original |
10469 | 10924 | |
10470 | 10925 | n An unsigned short (16-bit) in "network" (big-endian) order. |
10471 | 10926 | N An unsigned long (32-bit) in "network" (big-endian) order. |
10472 | 10927 | v An unsigned short (16-bit) in "VAX" (little-endian) order. |
10473 | 10928 | V An unsigned long (32-bit) in "VAX" (little-endian) order. |
10474 | 10929 | |
10475 | 10930 | =end original |
10476 | 10931 | |
10477 | 10932 | n "network" 順序 (ビッグエンディアン) の unsigned short (16 ビット)。 |
10478 | 10933 | N "network" 順序 (ビッグエンディアン) の unsigned long (32 ビット)。 |
10479 | 10934 | v "VAX" 順序 (リトルエンディアン) の unsigned short (16 ビット)。 |
10480 | 10935 | V "VAX" 順序 (リトルエンディアン) の unsigned long (32 ビット)。 |
10481 | 10936 | |
10482 | 10937 | =begin original |
10483 | 10938 | |
10484 | 10939 | j A Perl internal signed integer value (IV). |
10485 | 10940 | J A Perl internal unsigned integer value (UV). |
10486 | 10941 | |
10487 | 10942 | =end original |
10488 | 10943 | |
10489 | 10944 | j Perl 内部符号付き整数 (IV)。 |
10490 | 10945 | J Perl 内部符号なし整数 (UV)。 |
10491 | 10946 | |
10492 | 10947 | =begin original |
10493 | 10948 | |
10494 | 10949 | f A single-precision float in native format. |
10495 | 10950 | d A double-precision float in native format. |
10496 | 10951 | |
10497 | 10952 | =end original |
10498 | 10953 | |
10499 | 10954 | f 機種依存の単精度浮動小数点数。 |
10500 | 10955 | d 機種依存の倍精度浮動小数点数。 |
10501 | 10956 | |
10502 | 10957 | =begin original |
10503 | 10958 | |
10504 | 10959 | F A Perl internal floating-point value (NV) in native format |
10505 | 10960 | D A float of long-double precision in native format. |
10506 | 10961 | (Long doubles are available only if your system supports |
10507 | 10962 | long double values _and_ if Perl has been compiled to |
10508 | 10963 | support those. Raises an exception otherwise. |
10509 | 10964 | Note that there are different long double formats.) |
10510 | 10965 | |
10511 | 10966 | =end original |
10512 | 10967 | |
10513 | 10968 | F ネイティブフォーマットの Perl 内部浮動小数点数 (NV) |
10514 | 10969 | D ネイティブフォーマットの長い倍精度浮動小数点数(long double)。 |
10515 | 10970 | (long double は、システムが long double に対応していて、かつ Perl が |
10516 | 10971 | long double 対応としてコンパイルされている場合にのみ使用可能です。 |
10517 | 10972 | それ以外の場合は例外が発生します。 |
10518 | 10973 | long double 型式の場合は異なることに注意してください) |
10519 | 10974 | |
10520 | 10975 | =begin original |
10521 | 10976 | |
10522 | 10977 | p A pointer to a null-terminated string. |
10523 | 10978 | P A pointer to a structure (fixed-length string). |
10524 | 10979 | |
10525 | 10980 | =end original |
10526 | 10981 | |
10527 | 10982 | p ヌル文字で終端する文字列へのポインタ。 |
10528 | 10983 | P 構造体 (固定長文字列) へのポインタ。 |
10529 | 10984 | |
10530 | 10985 | =begin original |
10531 | 10986 | |
10532 | 10987 | u A uuencoded string. |
10533 | 10988 | U A Unicode character number. Encodes to a character in char- |
10534 | 10989 | acter mode and UTF-8 (or UTF-EBCDIC in EBCDIC platforms) in |
10535 | 10990 | byte mode. |
10536 | 10991 | |
10537 | 10992 | =end original |
10538 | 10993 | |
10539 | 10994 | u uuencode 文字列。 |
10540 | 10995 | U Unicode 文字番号。文字モードでは文字に、バイトモードなら UTF-8 に |
10541 | 10996 | (EBCDIC システムでは UTF-EBCDIC に)エンコードされます。 |
10542 | 10997 | |
10543 | 10998 | =begin original |
10544 | 10999 | |
10545 | 11000 | w A BER compressed integer (not an ASN.1 BER, see perlpacktut |
10546 | 11001 | for details). Its bytes represent an unsigned integer in |
10547 | 11002 | base 128, most significant digit first, with as few digits |
10548 | 11003 | as possible. Bit eight (the high bit) is set on each byte |
10549 | 11004 | except the last. |
10550 | 11005 | |
10551 | 11006 | =end original |
10552 | 11007 | |
10553 | 11008 | w A BER 圧縮変数(ASN.1 BER ではありません; 詳細については perlpacktut を |
10554 | 11009 | 参照してください)。このバイト列はできるだけ少ない桁数で表現された |
10555 | 11010 | 128 を基とした符号なし整数で、最上位ビットから順に並びます。 |
10556 | 11011 | 最後のバイト以外の各バイトのビット 8 (上位ビット) がセットされます。 |
10557 | 11012 | |
10558 | 11013 | =begin original |
10559 | 11014 | |
10560 | 11015 | x A null byte (a.k.a ASCII NUL, "\000", chr(0)) |
10561 | 11016 | X Back up a byte. |
10562 | 11017 | @ Null-fill or truncate to absolute position, counted from the |
10563 | 11018 | start of the innermost ()-group. |
10564 | 11019 | . Null-fill or truncate to absolute position specified by |
10565 | 11020 | the value. |
10566 | 11021 | ( Start of a ()-group. |
10567 | 11022 | |
10568 | 11023 | =end original |
10569 | 11024 | |
10570 | 11025 | x ヌル文字 (つまり ASCII NUL, "\000", chr(0)) |
10571 | 11026 | X 1 文字後退。 |
10572 | 11027 | @ 一番内側の () の組の開始位置から数えて、絶対位置までヌル文字で |
10573 | 11028 | 埋めるか切り詰める。 |
10574 | 11029 | . 値で指定した絶対位置までヌル文字で埋めるか切り詰める。 |
10575 | 11030 | ( () の組の開始。 |
10576 | 11031 | |
10577 | 11032 | =begin original |
10578 | 11033 | |
10579 | 11034 | One or more modifiers below may optionally follow certain letters in the |
10580 | 11035 | TEMPLATE (the second column lists letters for which the modifier is valid): |
10581 | 11036 | |
10582 | 11037 | =end original |
10583 | 11038 | |
10584 | 11039 | 以下に示す一つまたは複数の修飾子を、TEMPLATE の文字のいくつかにオプションで |
10585 | 11040 | 付けることができます(表の 2 列目は、その修飾子が有効な文字です): |
10586 | 11041 | |
10587 | 11042 | =begin original |
10588 | 11043 | |
10589 | 11044 | ! sSlLiI Forces native (short, long, int) sizes instead |
10590 | 11045 | of fixed (16-/32-bit) sizes. |
10591 | 11046 | |
10592 | 11047 | =end original |
10593 | 11048 | |
10594 | 11049 | ! sSlLiI 固定の(16/32 ビット)サイズではなく、ネイティブな |
10595 | 11050 | (short, long, int)サイズを強制する。 |
10596 | 11051 | |
10597 | 11052 | =begin original |
10598 | 11053 | |
10599 | 11054 | ! xX Make x and X act as alignment commands. |
10600 | 11055 | |
10601 | 11056 | =end original |
10602 | 11057 | |
10603 | 11058 | ! xX x と X をアライメントコマンドとして振舞わせる。 |
10604 | 11059 | |
10605 | 11060 | =begin original |
10606 | 11061 | |
10607 | 11062 | ! nNvV Treat integers as signed instead of unsigned. |
10608 | 11063 | |
10609 | 11064 | =end original |
10610 | 11065 | |
10611 | 11066 | ! nNvV 整数を符号なしではなく符号付きとして扱わせる。 |
10612 | 11067 | |
10613 | 11068 | =begin original |
10614 | 11069 | |
10615 | 11070 | ! @. Specify position as byte offset in the internal |
10616 | 11071 | representation of the packed string. Efficient |
10617 | 11072 | but dangerous. |
10618 | 11073 | |
10619 | 11074 | =end original |
10620 | 11075 | |
10621 | 11076 | ! @. pack された内部表現のバイトオフセットとして位置を指定する。 |
10622 | 11077 | 効率的ですが危険です。 |
10623 | 11078 | |
10624 | 11079 | =begin original |
10625 | 11080 | |
10626 | 11081 | > sSiIlLqQ Force big-endian byte-order on the type. |
10627 | 11082 | jJfFdDpP (The "big end" touches the construct.) |
10628 | 11083 | |
10629 | 11084 | =end original |
10630 | 11085 | |
10631 | 11086 | > sSiIlLqQ これらの型のバイト順をビッグエンディアンに強制します。 |
10632 | 11087 | jJfFdDpP (「大きい端」が構造に触れています。) |
10633 | 11088 | |
10634 | 11089 | =begin original |
10635 | 11090 | |
10636 | 11091 | < sSiIlLqQ Force little-endian byte-order on the type. |
10637 | 11092 | jJfFdDpP (The "little end" touches the construct.) |
10638 | 11093 | |
10639 | 11094 | =end original |
10640 | 11095 | |
10641 | 11096 | < sSiIlLqQ これらの型のバイト順をリトルエンディアンに強制します。 |
10642 | 11097 | jJfFdDpP (「小さい端」が構造に触れています。) |
10643 | 11098 | |
10644 | 11099 | =begin original |
10645 | 11100 | |
10646 | 11101 | The C<< > >> and C<< < >> modifiers can also be used on C<()> groups |
10647 | 11102 | to force a particular byte-order on all components in that group, |
10648 | 11103 | including all its subgroups. |
10649 | 11104 | |
10650 | 11105 | =end original |
10651 | 11106 | |
10652 | 11107 | C<< > >> と C<< < >> の修飾子は C<()>-グループでも使えます; |
10653 | 11108 | この場合はそのグループと全ての副グループ内の全ての要素を特定のバイト順に |
10654 | 11109 | 強制します。 |
10655 | 11110 | |
10656 | 11111 | =begin comment |
10657 | 11112 | |
10658 | 11113 | Larry recalls that the hex and bit string formats (H, h, B, b) were added to |
10659 | 11114 | pack for processing data from NASA's Magellan probe. Magellan was in an |
10660 | 11115 | elliptical orbit, using the antenna for the radar mapping when close to |
10661 | 11116 | Venus and for communicating data back to Earth for the rest of the orbit. |
10662 | 11117 | There were two transmission units, but one of these failed, and then the |
10663 | 11118 | other developed a fault whereby it would randomly flip the sense of all the |
10664 | 11119 | bits. It was easy to automatically detect complete records with the correct |
10665 | 11120 | sense, and complete records with all the bits flipped. However, this didn't |
10666 | 11121 | recover the records where the sense flipped midway. A colleague of Larry's |
10667 | 11122 | was able to pretty much eyeball where the records flipped, so they wrote an |
10668 | 11123 | editor named kybble (a pun on the dog food Kibbles 'n Bits) to enable him to |
10669 | 11124 | manually correct the records and recover the data. For this purpose pack |
10670 | 11125 | gained the hex and bit string format specifiers. |
10671 | 11126 | |
10672 | 11127 | git shows that they were added to perl 3.0 in patch #44 (Jan 1991, commit |
10673 | 11128 | 27e2fb84680b9cc1), but the patch description makes no mention of their |
10674 | 11129 | addition, let alone the story behind them. |
10675 | 11130 | |
10676 | 11131 | =end comment |
10677 | 11132 | |
10678 | 11133 | =begin original |
10679 | 11134 | |
10680 | 11135 | The following rules apply: |
10681 | 11136 | |
10682 | 11137 | =end original |
10683 | 11138 | |
10684 | 11139 | 以下の条件が適用されます: |
10685 | 11140 | |
10686 | 11141 | =over |
10687 | 11142 | |
10688 | 11143 | =item * |
10689 | 11144 | |
10690 | 11145 | =begin original |
10691 | 11146 | |
10692 | 11147 | Each letter may optionally be followed by a number indicating the repeat |
10693 | 11148 | count. A numeric repeat count may optionally be enclosed in brackets, as |
10694 | 11149 | in C<pack("C[80]", @arr)>. The repeat count gobbles that many values from |
10695 | 11150 | the LIST when used with all format types other than C<a>, C<A>, C<Z>, C<b>, |
10696 | 11151 | C<B>, C<h>, C<H>, C<@>, C<.>, C<x>, C<X>, and C<P>, where it means |
10697 | 11152 | something else, described below. Supplying a C<*> for the repeat count |
10698 | 11153 | instead of a number means to use however many items are left, except for: |
10699 | 11154 | |
10700 | 11155 | =end original |
10701 | 11156 | |
10702 | 11157 | これらの文字の後には、繰り返し数を示す数字を付けることができます。 |
10703 | 11158 | 数値の繰り返し数は C<pack "C[80]", @arr> のように大かっこで |
10704 | 11159 | 囲むこともできます。 |
10705 | 11160 | C<a>, C<A>, C<Z>, C<b>, C<B>, C<h>, C<H>, C<@>, C<.>, C<x>, C<X>, C<P> |
10706 | 11161 | 以外の全ての型では、LIST から繰り返し数の値を取り出して使います。 |
10707 | 11162 | 繰り返し数に C<*> を指定すると、以下の例外を除いて、 |
10708 | 11163 | その時点で残っているすべての要素を意味します。 |
10709 | 11164 | |
10710 | 11165 | =over |
10711 | 11166 | |
10712 | 11167 | =item * |
10713 | 11168 | |
10714 | 11169 | =begin original |
10715 | 11170 | |
10716 | 11171 | C<@>, C<x>, and C<X>, where it is equivalent to C<0>. |
10717 | 11172 | |
10718 | 11173 | =end original |
10719 | 11174 | |
10720 | 11175 | C<@>, C<x>, C<X> では C<0> と等価です。 |
10721 | 11176 | |
10722 | 11177 | =item * |
10723 | 11178 | |
10724 | 11179 | =begin original |
10725 | 11180 | |
10726 | 11181 | <.>, where it means relative to the start of the string. |
10727 | 11182 | |
10728 | 11183 | =end original |
10729 | 11184 | |
10730 | 11185 | <.> では文字列の先頭からの相対位置を意味します。 |
10731 | 11186 | |
10732 | 11187 | =item * |
10733 | 11188 | |
10734 | 11189 | =begin original |
10735 | 11190 | |
10736 | 11191 | C<u>, where it is equivalent to 1 (or 45, which here is equivalent). |
10737 | 11192 | |
10738 | 11193 | =end original |
10739 | 11194 | |
10740 | 11195 | C<u> では 1 (あるいはここでは 45 でも等価です) と等価です。 |
10741 | 11196 | |
10742 | 11197 | =back |
10743 | 11198 | |
10744 | 11199 | =begin original |
10745 | 11200 | |
10746 | 11201 | One can replace a numeric repeat count with a template letter enclosed in |
10747 | 11202 | brackets to use the packed byte length of the bracketed template for the |
10748 | 11203 | repeat count. |
10749 | 11204 | |
10750 | 11205 | =end original |
10751 | 11206 | |
10752 | 11207 | このテンプレートでパックされたバイト長を繰り返し数として使うために、 |
10753 | 11208 | 大かっこで囲まれたテンプレートで数値の繰り返し数を置き換えることが |
10754 | 11209 | できます。 |
10755 | 11210 | |
10756 | 11211 | =begin original |
10757 | 11212 | |
10758 | 11213 | For example, the template C<x[L]> skips as many bytes as in a packed long, |
10759 | 11214 | and the template C<"$t X[$t] $t"> unpacks twice whatever $t (when |
10760 | 11215 | variable-expanded) unpacks. If the template in brackets contains alignment |
10761 | 11216 | commands (such as C<x![d]>), its packed length is calculated as if the |
10762 | 11217 | start of the template had the maximal possible alignment. |
10763 | 11218 | |
10764 | 11219 | =end original |
10765 | 11220 | |
10766 | 11221 | 例えば、テンプレート C<x[L]> は long でパックされたバイト数分だけスキップし、 |
10767 | 11222 | テンプレート C<"$t X[$t] $t"> は $t (変数展開された場合)を |
10768 | 11223 | unpack したものの 2 倍を unpack します。 |
10769 | 11224 | (C<x![d]> のように) 大かっこにアライメントコマンドが含まれている場合、 |
10770 | 11225 | パックされた長さは、テンプレートの先頭で最大限可能なアライメントを |
10771 | 11226 | 持っているものとして計算されます。 |
10772 | 11227 | |
10773 | 11228 | =begin original |
10774 | 11229 | |
10775 | 11230 | When used with C<Z>, a C<*> as the repeat count is guaranteed to add a |
10776 | 11231 | trailing null byte, so the resulting string is always one byte longer than |
10777 | 11232 | the byte length of the item itself. |
10778 | 11233 | |
10779 | 11234 | =end original |
10780 | 11235 | |
10781 | 11236 | C<Z> で、繰り返し数として C<*> が使われた場合、末尾にヌルバイトが |
10782 | 11237 | 保証されるので、結果の文字列は常にアイテム自身のバイト長よりも 1 バイト |
10783 | 11238 | 長くなります。 |
10784 | 11239 | |
10785 | 11240 | =begin original |
10786 | 11241 | |
10787 | 11242 | When used with C<@>, the repeat count represents an offset from the start |
10788 | 11243 | of the innermost C<()> group. |
10789 | 11244 | |
10790 | 11245 | =end original |
10791 | 11246 | |
10792 | 11247 | C<@> で使うと、繰り返し数は一番内側の C<()> グループの先頭からのオフセットを |
10793 | 11248 | 表現します。 |
10794 | 11249 | |
10795 | 11250 | =begin original |
10796 | 11251 | |
10797 | 11252 | When used with C<.>, the repeat count determines the starting position to |
10798 | 11253 | calculate the value offset as follows: |
10799 | 11254 | |
10800 | 11255 | =end original |
10801 | 11256 | |
10802 | 11257 | C<.> で使われると、繰り返し数は以下のようにして、 |
10803 | 11258 | 値のオフセットを計算するための開始位置を決定するために使われます。 |
10804 | 11259 | |
10805 | 11260 | =over |
10806 | 11261 | |
10807 | 11262 | =item * |
10808 | 11263 | |
10809 | 11264 | =begin original |
10810 | 11265 | |
10811 | 11266 | If the repeat count is C<0>, it's relative to the current position. |
10812 | 11267 | |
10813 | 11268 | =end original |
10814 | 11269 | |
10815 | 11270 | 繰り返し数が C<0> なら、現在位置からの相対位置となります。 |
10816 | 11271 | |
10817 | 11272 | =item * |
10818 | 11273 | |
10819 | 11274 | =begin original |
10820 | 11275 | |
10821 | 11276 | If the repeat count is C<*>, the offset is relative to the start of the |
10822 | 11277 | packed string. |
10823 | 11278 | |
10824 | 11279 | =end original |
10825 | 11280 | |
10826 | 11281 | 繰り返し数が C<*> なら、オフセットは pack された文字列の先頭からの |
10827 | 11282 | 相対位置です。 |
10828 | 11283 | |
10829 | 11284 | =item * |
10830 | 11285 | |
10831 | 11286 | =begin original |
10832 | 11287 | |
10833 | 11288 | And if it's an integer I<n>, the offset is relative to the start of the |
10834 | 11289 | I<n>th innermost C<( )> group, or to the start of the string if I<n> is |
10835 | 11290 | bigger then the group level. |
10836 | 11291 | |
10837 | 11292 | =end original |
10838 | 11293 | |
10839 | 11294 | そして整数 I<n> なら、オフセットは一番内側から I<n> 番目の C<( )> グループの |
10840 | 11295 | 先頭、あるいは I<n> がグループレベルより大きい場合は文字列の先頭からの |
10841 | 11296 | 相対位置です。 |
10842 | 11297 | |
10843 | 11298 | =back |
10844 | 11299 | |
10845 | 11300 | =begin original |
10846 | 11301 | |
10847 | 11302 | The repeat count for C<u> is interpreted as the maximal number of bytes |
10848 | 11303 | to encode per line of output, with 0, 1 and 2 replaced by 45. The repeat |
10849 | 11304 | count should not be more than 65. |
10850 | 11305 | |
10851 | 11306 | =end original |
10852 | 11307 | |
10853 | 11308 | C<u> での繰り返し回数は、出力行毎に最大何バイトまでをエンコードするかを |
10854 | 11309 | 示します; 0, 1, 2 は 45 として扱われます。 |
10855 | 11310 | 繰り返し数は 65 を超えてはなりません。 |
10856 | 11311 | |
10857 | 11312 | =item * |
10858 | 11313 | |
10859 | 11314 | =begin original |
10860 | 11315 | |
10861 | 11316 | The C<a>, C<A>, and C<Z> types gobble just one value, but pack it as a |
10862 | 11317 | string of length count, padding with nulls or spaces as needed. When |
10863 | 11318 | unpacking, C<A> strips trailing whitespace and nulls, C<Z> strips everything |
10864 | 11319 | after the first null, and C<a> returns data with no stripping at all. |
10865 | 11320 | |
10866 | 11321 | =end original |
10867 | 11322 | |
10868 | 11323 | C<a>, C<A>, C<Z> という型を使うと、値を一つだけ取り出して使いますが、 |
10869 | 11324 | 繰り返し数で示す長さの文字列となるように、必要に応じてヌル文字か |
10870 | 11325 | スペース文字を付け足します。 |
10871 | 11326 | unpack するとき、C<A> は後続の空白やヌル文字を取り除きます; C<Z> は最初の |
10872 | 11327 | ヌル文字以降の全てを取り除きます; C<a> はデータを取り除くことなく |
10873 | 11328 | そのまま返します。 |
10874 | 11329 | |
10875 | 11330 | =begin original |
10876 | 11331 | |
10877 | 11332 | If the value to pack is too long, the result is truncated. If it's too |
10878 | 11333 | long and an explicit count is provided, C<Z> packs only C<$count-1> bytes, |
10879 | 11334 | followed by a null byte. Thus C<Z> always packs a trailing null, except |
10880 | 11335 | when the count is 0. |
10881 | 11336 | |
10882 | 11337 | =end original |
10883 | 11338 | |
10884 | 11339 | pack する値が長すぎる場合、結果は切り詰められます。 |
10885 | 11340 | 長すぎてかつ明示的に個数が指定されている場合、 |
10886 | 11341 | C<Z> は C<$count-1> バイトまで pack し、その後にヌルバイトがつきます。 |
10887 | 11342 | 従って、C<Z> は、繰り返し数が 0 の場合を除いて、常に末尾にヌルバイトが |
10888 | 11343 | つきます。 |
10889 | 11344 | |
10890 | 11345 | =item * |
10891 | 11346 | |
10892 | 11347 | =begin original |
10893 | 11348 | |
10894 | 11349 | Likewise, the C<b> and C<B> formats pack a string that's that many bits long. |
10895 | 11350 | Each such format generates 1 bit of the result. These are typically followed |
10896 | 11351 | by a repeat count like C<B8> or C<B64>. |
10897 | 11352 | |
10898 | 11353 | =end original |
10899 | 11354 | |
10900 | 11355 | 同様に、C<b> や C<B> は、繰り返し数で示すビット長のビット列に pack します。 |
10901 | 11356 | これらの各文字は結果の 1 ビットを生成します。 |
10902 | 11357 | これらは典型的には C<B8> や C<B64> のような繰り返しカウントが引き続きます。 |
10903 | 11358 | |
10904 | 11359 | =begin original |
10905 | 11360 | |
10906 | 11361 | Each result bit is based on the least-significant bit of the corresponding |
10907 | 11362 | input character, i.e., on C<ord($char)%2>. In particular, characters C<"0"> |
10908 | 11363 | and C<"1"> generate bits 0 and 1, as do characters C<"\000"> and C<"\001">. |
10909 | 11364 | |
10910 | 11365 | =end original |
10911 | 11366 | |
10912 | 11367 | 結果ビットのそれぞれは対応する入力文字の最下位ビットを基にします |
10913 | 11368 | (つまり C<ord($char)%2>)。 |
10914 | 11369 | 特に、文字 C<"0"> と C<"1"> は文字 C<"\000"> と C<"\001"> と同様に、 |
10915 | 11370 | ビット 0 と 1 を生成します。 |
10916 | 11371 | |
10917 | 11372 | =begin original |
10918 | 11373 | |
10919 | 11374 | Starting from the beginning of the input string, each 8-tuple |
10920 | 11375 | of characters is converted to 1 character of output. With format C<b>, |
10921 | 11376 | the first character of the 8-tuple determines the least-significant bit of a |
10922 | 11377 | character; with format C<B>, it determines the most-significant bit of |
10923 | 11378 | a character. |
10924 | 11379 | |
10925 | 11380 | =end original |
10926 | 11381 | |
10927 | 11382 | pack() の入力文字列の先頭から始めて、8 タプル毎に 1 文字の出力に変換されます。 |
10928 | 11383 | C<b> フォーマットでは 8 タプルの最初の文字が出力の最下位ビットとなります; |
10929 | 11384 | C<B> フォーマットでは出力の最上位ビットとなります。 |
10930 | 11385 | |
10931 | 11386 | =begin original |
10932 | 11387 | |
10933 | 11388 | If the length of the input string is not evenly divisible by 8, the |
10934 | 11389 | remainder is packed as if the input string were padded by null characters |
10935 | 11390 | at the end. Similarly during unpacking, "extra" bits are ignored. |
10936 | 11391 | |
10937 | 11392 | =end original |
10938 | 11393 | |
10939 | 11394 | もし入力文字列の長さが 8 で割り切れない場合、余りの部分は入力文字列の |
10940 | 11395 | 最後にヌル文字がパッディングされているものとしてパックされます。 |
10941 | 11396 | 同様に、unpack 中は「余分な」ビットは無視されます。 |
10942 | 11397 | |
10943 | 11398 | =begin original |
10944 | 11399 | |
10945 | 11400 | If the input string is longer than needed, remaining characters are ignored. |
10946 | 11401 | |
10947 | 11402 | =end original |
10948 | 11403 | |
10949 | 11404 | 入力文字列が必要な分よりも長い場合、余分な文字は無視されます。 |
10950 | 11405 | |
10951 | 11406 | =begin original |
10952 | 11407 | |
10953 | 11408 | A C<*> for the repeat count uses all characters of the input field. |
10954 | 11409 | On unpacking, bits are converted to a string of C<0>s and C<1>s. |
10955 | 11410 | |
10956 | 11411 | =end original |
10957 | 11412 | |
10958 | 11413 | 繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が使われます。 |
10959 | 11414 | unpack 時にはビット列は C<0> と C<1> の文字列に変換されます。 |
10960 | 11415 | |
10961 | 11416 | =item * |
10962 | 11417 | |
10963 | 11418 | =begin original |
10964 | 11419 | |
10965 | 11420 | The C<h> and C<H> formats pack a string that many nybbles (4-bit groups, |
10966 | 11421 | representable as hexadecimal digits, C<"0".."9"> C<"a".."f">) long. |
10967 | 11422 | |
10968 | 11423 | =end original |
10969 | 11424 | |
10970 | 11425 | C<h> や C<H> は、多ニブル長(16 進文字である C<"0".."9"> C<"a".."f"> で |
10971 | 11426 | 表現可能な 4 ビットグループ)のニブル列に pack します。 |
10972 | 11427 | |
10973 | 11428 | =begin original |
10974 | 11429 | |
10975 | 11430 | For each such format, L<C<pack>|/pack TEMPLATE,LIST> generates 4 bits of result. |
10976 | 11431 | With non-alphabetical characters, the result is based on the 4 least-significant |
10977 | 11432 | bits of the input character, i.e., on C<ord($char)%16>. In particular, |
10978 | 11433 | characters C<"0"> and C<"1"> generate nybbles 0 and 1, as do bytes |
10979 | 11434 | C<"\000"> and C<"\001">. For characters C<"a".."f"> and C<"A".."F">, the result |
10980 | 11435 | is compatible with the usual hexadecimal digits, so that C<"a"> and |
10981 | 11436 | C<"A"> both generate the nybble C<0xA==10>. Use only these specific hex |
10982 | 11437 | characters with this format. |
10983 | 11438 | |
10984 | 11439 | =end original |
10985 | 11440 | |
10986 | 11441 | このようなフォーマット文字のそれぞれについて、L<C<pack>|/pack TEMPLATE,LIST> は |
10987 | 11442 | 結果の 4 ビットを生成します。 |
10988 | 11443 | 英字でない文字の場合、結果は入力文字の下位 4 ビットを |
10989 | 11444 | 基にします(つまり C<ord($char)%16>)。 |
10990 | 11445 | 特に、文字 C<"0"> と C<"1"> はバイト C<"\000"> と C<"\001"> と同様に |
10991 | 11446 | ニブル 0 と 1 を生成します。 |
10992 | 11447 | 文字 C<"a".."f"> と C<"A".."F"> の場合は結果は通常の 16 進数と同じ結果に |
10993 | 11448 | なるので、C<"a"> と C<"A"> はどちらも ニブル C<0xa==10> を生成します。 |
10994 | 11449 | これらの 16 進文字はこの特定のフォーマットでだけ使ってください。 |
10995 | 11450 | |
10996 | 11451 | =begin original |
10997 | 11452 | |
10998 | 11453 | Starting from the beginning of the template to |
10999 | 11454 | L<C<pack>|/pack TEMPLATE,LIST>, each pair |
11000 | 11455 | of characters is converted to 1 character of output. With format C<h>, the |
11001 | 11456 | first character of the pair determines the least-significant nybble of the |
11002 | 11457 | output character; with format C<H>, it determines the most-significant |
11003 | 11458 | nybble. |
11004 | 11459 | |
11005 | 11460 | =end original |
11006 | 11461 | |
11007 | 11462 | L<C<pack>|/pack TEMPLATE,LIST> のテンプレートの先頭から始めて、2 文字毎に |
11008 | 11463 | 1 文字の出力に変換されます。 |
11009 | 11464 | C<h> フォーマットでは 1 文字目が出力の最下位ニブルとなり、 |
11010 | 11465 | C<H> フォーマットでは出力の最上位ニブルとなります。 |
11011 | 11466 | |
11012 | 11467 | =begin original |
11013 | 11468 | |
11014 | 11469 | If the length of the input string is not even, it behaves as if padded by |
11015 | 11470 | a null character at the end. Similarly, "extra" nybbles are ignored during |
11016 | 11471 | unpacking. |
11017 | 11472 | |
11018 | 11473 | =end original |
11019 | 11474 | |
11020 | 11475 | 入力文字列の長さが偶数でない場合、最後にヌル文字でパッディングされて |
11021 | 11476 | いるかのように振る舞います。 |
11022 | 11477 | 同様に、unpack 中は「余分な」ニブルは無視されます。 |
11023 | 11478 | |
11024 | 11479 | =begin original |
11025 | 11480 | |
11026 | 11481 | If the input string is longer than needed, extra characters are ignored. |
11027 | 11482 | |
11028 | 11483 | =end original |
11029 | 11484 | |
11030 | 11485 | 入力文字列が必要な分より長い場合、余分な部分は無視されます。 |
11031 | 11486 | |
11032 | 11487 | =begin original |
11033 | 11488 | |
11034 | 11489 | A C<*> for the repeat count uses all characters of the input field. For |
11035 | 11490 | L<C<unpack>|/unpack TEMPLATE,EXPR>, nybbles are converted to a string of |
11036 | 11491 | hexadecimal digits. |
11037 | 11492 | |
11038 | 11493 | =end original |
11039 | 11494 | |
11040 | 11495 | 繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が使われます。 |
11041 | 11496 | L<C<unpack>|/unpack TEMPLATE,EXPR> 時にはニブルは 16 進数の文字列に |
11042 | 11497 | 変換されます。 |
11043 | 11498 | |
11044 | 11499 | =item * |
11045 | 11500 | |
11046 | 11501 | =begin original |
11047 | 11502 | |
11048 | 11503 | The C<p> format packs a pointer to a null-terminated string. You are |
11049 | 11504 | responsible for ensuring that the string is not a temporary value, as that |
11050 | 11505 | could potentially get deallocated before you got around to using the packed |
11051 | 11506 | result. The C<P> format packs a pointer to a structure of the size indicated |
11052 | 11507 | by the length. A null pointer is created if the corresponding value for |
11053 | 11508 | C<p> or C<P> is L<C<undef>|/undef EXPR>; similarly with |
11054 | 11509 | L<C<unpack>|/unpack TEMPLATE,EXPR>, where a null pointer unpacks into |
11055 | 11510 | L<C<undef>|/undef EXPR>. |
11056 | 11511 | |
11057 | 11512 | =end original |
11058 | 11513 | |
11059 | 11514 | C<p> は、ヌル文字終端文字列へのポインタを pack します。 |
11060 | 11515 | 文字列が一時的な値でない(つまり pack された結果を使う前に文字列が |
11061 | 11516 | 解放されない) ことに責任を持つ必要があります。 |
11062 | 11517 | C<P> は、指定した長さの構造体へのポインタを pack します。 |
11063 | 11518 | C<p> または C<P> に対応する値が L<C<undef>|/undef EXPR> だった場合、 |
11064 | 11519 | ヌルポインタが作成されます; ヌルポインタが L<C<undef>|/undef EXPR> に |
11065 | 11520 | unpack される L<C<unpack>|/unpack TEMPLATE,EXPR> と同様です。 |
11066 | 11521 | |
11067 | 11522 | =begin original |
11068 | 11523 | |
11069 | 11524 | If your system has a strange pointer size--meaning a pointer is neither as |
11070 | 11525 | big as an int nor as big as a long--it may not be possible to pack or |
11071 | 11526 | unpack pointers in big- or little-endian byte order. Attempting to do |
11072 | 11527 | so raises an exception. |
11073 | 11528 | |
11074 | 11529 | =end original |
11075 | 11530 | |
11076 | 11531 | システムのポインタが変わったサイズの場合--つまり、int の大きさでも |
11077 | 11532 | long の大きさでもない場合--ポインタをビッグエンディアンやリトルエンディアンの |
11078 | 11533 | バイト順で pack や unpack することはできません。 |
11079 | 11534 | そうしようとすると例外が発生します。 |
11080 | 11535 | |
11081 | 11536 | =item * |
11082 | 11537 | |
11083 | 11538 | =begin original |
11084 | 11539 | |
11085 | 11540 | The C</> template character allows packing and unpacking of a sequence of |
11086 | 11541 | items where the packed structure contains a packed item count followed by |
11087 | 11542 | the packed items themselves. This is useful when the structure you're |
11088 | 11543 | unpacking has encoded the sizes or repeat counts for some of its fields |
11089 | 11544 | within the structure itself as separate fields. |
11090 | 11545 | |
11091 | 11546 | =end original |
11092 | 11547 | |
11093 | 11548 | C</> テンプレート文字は、アイテムの数の後にアイテムそのものが入っている形の |
11094 | 11549 | アイテム列を pack 及び unpack します。 |
11095 | 11550 | これは、unpack したい構造体が、サイズや繰り返し数が構造体自身の中に |
11096 | 11551 | 独立したフィールドとしてエンコードされている場合に有効です。 |
11097 | 11552 | |
11098 | 11553 | =begin original |
11099 | 11554 | |
11100 | 11555 | For L<C<pack>|/pack TEMPLATE,LIST>, you write |
11101 | 11556 | I<length-item>C</>I<sequence-item>, and the |
11102 | 11557 | I<length-item> describes how the length value is packed. Formats likely |
11103 | 11558 | to be of most use are integer-packing ones like C<n> for Java strings, |
11104 | 11559 | C<w> for ASN.1 or SNMP, and C<N> for Sun XDR. |
11105 | 11560 | |
11106 | 11561 | =end original |
11107 | 11562 | |
11108 | 11563 | L<C<pack>|/pack TEMPLATE,LIST> では I<length-item>C</>I<string-item> の |
11109 | 11564 | 形になり、 |
11110 | 11565 | I<length-item> は長さの値がどのように pack されているかを指定します。 |
11111 | 11566 | もっともよく使われるのは Java 文字列 のための C<n>、ASN.1 や SNMP のための |
11112 | 11567 | C<w>、Sun XDR のための C<N> といった整数型です。 |
11113 | 11568 | |
11114 | 11569 | =begin original |
11115 | 11570 | |
11116 | 11571 | For L<C<pack>|/pack TEMPLATE,LIST>, I<sequence-item> may have a repeat |
11117 | 11572 | count, in which case |
11118 | 11573 | the minimum of that and the number of available items is used as the argument |
11119 | 11574 | for I<length-item>. If it has no repeat count or uses a '*', the number |
11120 | 11575 | of available items is used. |
11121 | 11576 | |
11122 | 11577 | =end original |
11123 | 11578 | |
11124 | 11579 | L<C<pack>|/pack TEMPLATE,LIST> では、I<sequence-item> は繰り返し数を |
11125 | 11580 | 持つことがあり、その場合はその最小値と利用可能なアイテムの数は |
11126 | 11581 | I<length-item> のための引数として使われます。 |
11127 | 11582 | 繰り返し数がなかったり、'*' を使うと、利用可能なアイテムの数が使われます。 |
11128 | 11583 | |
11129 | 11584 | =begin original |
11130 | 11585 | |
11131 | 11586 | For L<C<unpack>|/unpack TEMPLATE,EXPR>, an internal stack of integer |
11132 | 11587 | arguments unpacked so far is |
11133 | 11588 | used. You write C</>I<sequence-item> and the repeat count is obtained by |
11134 | 11589 | popping off the last element from the stack. The I<sequence-item> must not |
11135 | 11590 | have a repeat count. |
11136 | 11591 | |
11137 | 11592 | =end original |
11138 | 11593 | |
11139 | 11594 | L<C<unpack>|/unpack TEMPLATE,EXPR> では、今まで unpack した数値引数の |
11140 | 11595 | 内部スタックが使われます。 |
11141 | 11596 | C</>I<sequence-item> と書いて、繰り返し数はスタックから最後の要素を |
11142 | 11597 | 取り出すことで得ます。 |
11143 | 11598 | I<sequence-item> は繰り返し数を持っていてはいけません。 |
11144 | 11599 | |
11145 | 11600 | =begin original |
11146 | 11601 | |
11147 | 11602 | If I<sequence-item> refers to a string type (C<"A">, C<"a">, or C<"Z">), |
11148 | 11603 | the I<length-item> is the string length, not the number of strings. With |
11149 | 11604 | an explicit repeat count for pack, the packed string is adjusted to that |
11150 | 11605 | length. For example: |
11151 | 11606 | |
11152 | 11607 | =end original |
11153 | 11608 | |
11154 | 11609 | I<sequence-item> が文字列型 (C<"A">, C<"a">, C<"Z">) を参照している場合、 |
11155 | 11610 | I<length-item> は文字列の数ではなく、文字列の長さです。 |
11156 | 11611 | pack で明示的な繰り返し数があると、pack された文字列は与えられた |
11157 | 11612 | 長さに調整されます。 |
11158 | 11613 | 例えば: |
11159 | 11614 | |
11160 | 11615 | This code: gives this result: |
11161 | 11616 | |
11162 | 11617 | unpack("W/a", "\004Gurusamy") ("Guru") |
11163 | 11618 | unpack("a3/A A*", "007 Bond J ") (" Bond", "J") |
11164 | 11619 | unpack("a3 x2 /A A*", "007: Bond, J.") ("Bond, J", ".") |
11165 | 11620 | |
11166 | 11621 | pack("n/a* w/a","hello,","world") "\000\006hello,\005world" |
11167 | 11622 | pack("a/W2", ord("a") .. ord("z")) "2ab" |
11168 | 11623 | |
11169 | 11624 | =begin original |
11170 | 11625 | |
11171 | 11626 | The I<length-item> is not returned explicitly from |
11172 | 11627 | L<C<unpack>|/unpack TEMPLATE,EXPR>. |
11173 | 11628 | |
11174 | 11629 | =end original |
11175 | 11630 | |
11176 | 11631 | I<length-item> は L<C<unpack>|/unpack TEMPLATE,EXPR> から明示的には |
11177 | 11632 | 返されません。 |
11178 | 11633 | |
11179 | 11634 | =begin original |
11180 | 11635 | |
11181 | 11636 | Supplying a count to the I<length-item> format letter is only useful with |
11182 | 11637 | C<A>, C<a>, or C<Z>. Packing with a I<length-item> of C<a> or C<Z> may |
11183 | 11638 | introduce C<"\000"> characters, which Perl does not regard as legal in |
11184 | 11639 | numeric strings. |
11185 | 11640 | |
11186 | 11641 | =end original |
11187 | 11642 | |
11188 | 11643 | I<length-item> 文字に繰り返し数をつけるのは、 |
11189 | 11644 | 文字が C<A>, C<a>, C<Z> でない限りは有用ではありません。 |
11190 | 11645 | C<a> や C<Z> を I<length-item> として pack すると C<"\000"> 文字が |
11191 | 11646 | 出力されることがあり、Perl はこれを有効な数値文字列として認識しません。 |
11192 | 11647 | |
11193 | 11648 | =item * |
11194 | 11649 | |
11195 | 11650 | =begin original |
11196 | 11651 | |
11197 | 11652 | The integer types C<s>, C<S>, C<l>, and C<L> may be |
11198 | 11653 | followed by a C<!> modifier to specify native shorts or |
11199 | 11654 | longs. As shown in the example above, a bare C<l> means |
11200 | 11655 | exactly 32 bits, although the native C<long> as seen by the local C compiler |
11201 | 11656 | may be larger. This is mainly an issue on 64-bit platforms. You can |
11202 | 11657 | see whether using C<!> makes any difference this way: |
11203 | 11658 | |
11204 | 11659 | =end original |
11205 | 11660 | |
11206 | 11661 | C<s>, C<S>, C<l>, C<L> の整数タイプに引き続いて C<!> 修飾子を |
11207 | 11662 | つけることで、ネイティブの short や long を指定できます。 |
11208 | 11663 | 上述のように、C<l> は正確に 32 ビットですが、ネイティブな |
11209 | 11664 | (ローカルな C コンパイラによる)C<long> はもっと大きいかもしれません。 |
11210 | 11665 | これは主に 64 ビットプラットフォームで意味があります。 |
11211 | 11666 | C<!> を使うことによって違いがあるかどうかは以下のようにして調べられます: |
11212 | 11667 | |
11213 | 11668 | printf "format s is %d, s! is %d\n", |
11214 | 11669 | length pack("s"), length pack("s!"); |
11215 | 11670 | |
11216 | 11671 | printf "format l is %d, l! is %d\n", |
11217 | 11672 | length pack("l"), length pack("l!"); |
11218 | 11673 | |
11219 | 11674 | =begin original |
11220 | 11675 | |
11221 | 11676 | C<i!> and C<I!> are also allowed, but only for completeness' sake: |
11222 | 11677 | they are identical to C<i> and C<I>. |
11223 | 11678 | |
11224 | 11679 | =end original |
11225 | 11680 | |
11226 | 11681 | C<i!> と C<I!> も動作しますが、単に完全性のためだけです; |
11227 | 11682 | これは C<i> 及び C<I> と同じです。 |
11228 | 11683 | |
11229 | 11684 | =begin original |
11230 | 11685 | |
11231 | 11686 | The actual sizes (in bytes) of native shorts, ints, longs, and long |
11232 | 11687 | longs on the platform where Perl was built are also available from |
11233 | 11688 | the command line: |
11234 | 11689 | |
11235 | 11690 | =end original |
11236 | 11691 | |
11237 | 11692 | Perl がビルドされたプラットフォームでの short, int, long, long long の |
11238 | 11693 | 実際の(バイト数での)サイズはコマンドラインから: |
11239 | 11694 | |
11240 | 11695 | $ perl -V:{short,int,long{,long}}size |
11241 | 11696 | shortsize='2'; |
11242 | 11697 | intsize='4'; |
11243 | 11698 | longsize='4'; |
11244 | 11699 | longlongsize='8'; |
11245 | 11700 | |
11246 | 11701 | =begin original |
11247 | 11702 | |
11248 | 11703 | or programmatically via the L<C<Config>|Config> module: |
11249 | 11704 | |
11250 | 11705 | =end original |
11251 | 11706 | |
11252 | 11707 | あるいは L<C<Config>|Config> モジュールからプログラムで: |
11253 | 11708 | |
11254 | 11709 | use Config; |
11255 | 11710 | print $Config{shortsize}, "\n"; |
11256 | 11711 | print $Config{intsize}, "\n"; |
11257 | 11712 | print $Config{longsize}, "\n"; |
11258 | 11713 | print $Config{longlongsize}, "\n"; |
11259 | 11714 | |
11260 | 11715 | =begin original |
11261 | 11716 | |
11262 | 11717 | C<$Config{longlongsize}> is undefined on systems without |
11263 | 11718 | long long support. |
11264 | 11719 | |
11265 | 11720 | =end original |
11266 | 11721 | |
11267 | 11722 | システムが long long に対応していない場合は C<$Config{longlongsize}> は |
11268 | 11723 | 未定義値になります。 |
11269 | 11724 | |
11270 | 11725 | =item * |
11271 | 11726 | |
11272 | 11727 | =begin original |
11273 | 11728 | |
11274 | 11729 | The integer formats C<s>, C<S>, C<i>, C<I>, C<l>, C<L>, C<j>, and C<J> are |
11275 | 11730 | inherently non-portable between processors and operating systems because |
11276 | 11731 | they obey native byteorder and endianness. For example, a 4-byte integer |
11277 | 11732 | 0x12345678 (305419896 decimal) would be ordered natively (arranged in and |
11278 | 11733 | handled by the CPU registers) into bytes as |
11279 | 11734 | |
11280 | 11735 | =end original |
11281 | 11736 | |
11282 | 11737 | 整数フォーマット C<s>, C<S>, C<i>, C<I>, C<l>, C<L>, C<j>, C<J> は |
11283 | 11738 | ネイティブなバイト順序とエンディアンに従っているため、 |
11284 | 11739 | 本質的にプロセッサ間や OS 間で移植性がありません。 |
11285 | 11740 | 例えば 4 バイトの整数 0x12345678 (10 進数では 305419896) は |
11286 | 11741 | 内部では(CPU レジスタによって変換され扱われる形では) |
11287 | 11742 | 以下のようなバイト列に並べられます: |
11288 | 11743 | |
11289 | 11744 | 0x12 0x34 0x56 0x78 # big-endian |
11290 | 11745 | 0x78 0x56 0x34 0x12 # little-endian |
11291 | 11746 | |
11292 | 11747 | =begin original |
11293 | 11748 | |
11294 | 11749 | Basically, Intel and VAX CPUs are little-endian, while everybody else, |
11295 | 11750 | including Motorola m68k/88k, PPC, Sparc, HP PA, Power, and Cray, are |
11296 | 11751 | big-endian. Alpha and MIPS can be either: Digital/Compaq uses (well, used) |
11297 | 11752 | them in little-endian mode, but SGI/Cray uses them in big-endian mode. |
11298 | 11753 | |
11299 | 11754 | =end original |
11300 | 11755 | |
11301 | 11756 | 基本的に、Intel と VAX の CPU はリトルエンディアンです; 一方、 |
11302 | 11757 | Motorola m68k/88k, PPC, Sparc, HP PA, Power, Cray などを含むその他の全ては |
11303 | 11758 | ビッグエンディアンです。 |
11304 | 11759 | Alpha と MIPS は両方ともあります: Digital/Compaq はリトルエンディアンモードで |
11305 | 11760 | 使っています (えーと、いました) が、SGI/Cray はビッグエンディアンモードで |
11306 | 11761 | 使っています。 |
11307 | 11762 | |
11308 | 11763 | =begin original |
11309 | 11764 | |
11310 | 11765 | The names I<big-endian> and I<little-endian> are comic references to the |
11311 | 11766 | egg-eating habits of the little-endian Lilliputians and the big-endian |
11312 | 11767 | Blefuscudians from the classic Jonathan Swift satire, I<Gulliver's Travels>. |
11313 | 11768 | This entered computer lingo via the paper "On Holy Wars and a Plea for |
11314 | 11769 | Peace" by Danny Cohen, USC/ISI IEN 137, April 1, 1980. |
11315 | 11770 | |
11316 | 11771 | =end original |
11317 | 11772 | |
11318 | 11773 | I<ビッグエンディアン> と I<リトルエンディアン> の名前は、 |
11319 | 11774 | ジョナサン=スウィフトによる風刺小説の古典 I<ガリバー旅行記> での、卵を |
11320 | 11775 | 小さい方からむくリリパット国と大きい方からむくブレフスキュ国から |
11321 | 11776 | 取られています。 |
11322 | 11777 | "On Holy Wars and a Plea for Peace" by Danny Cohen, USC/ISI IEN 137, |
11323 | 11778 | April 1, 1980 の文書からコンピュータ用語として取り入れられました。 |
11324 | 11779 | |
11325 | 11780 | =begin original |
11326 | 11781 | |
11327 | 11782 | Some systems may have even weirder byte orders such as |
11328 | 11783 | |
11329 | 11784 | =end original |
11330 | 11785 | |
11331 | 11786 | 以下のような、さらに変わったバイト順序を持つシステムもあるかもしれません: |
11332 | 11787 | |
11333 | 11788 | 0x56 0x78 0x12 0x34 |
11334 | 11789 | 0x34 0x12 0x78 0x56 |
11335 | 11790 | |
11336 | 11791 | =begin original |
11337 | 11792 | |
11338 | 11793 | These are called mid-endian, middle-endian, mixed-endian, or just weird. |
11339 | 11794 | |
11340 | 11795 | =end original |
11341 | 11796 | |
11342 | 11797 | これらは mid-endian, middle-endian, mixed-endian あるいは単におかしなものと |
11343 | 11798 | 呼ばれます。 |
11344 | 11799 | |
11345 | 11800 | =begin original |
11346 | 11801 | |
11347 | 11802 | You can determine your system endianness with this incantation: |
11348 | 11803 | |
11349 | 11804 | =end original |
11350 | 11805 | |
11351 | 11806 | システムの設定は以下のようにして調べられます: |
11352 | 11807 | |
11353 | 11808 | printf("%#02x ", $_) for unpack("W*", pack L=>0x12345678); |
11354 | 11809 | |
11355 | 11810 | =begin original |
11356 | 11811 | |
11357 | 11812 | The byteorder on the platform where Perl was built is also available |
11358 | 11813 | via L<Config>: |
11359 | 11814 | |
11360 | 11815 | =end original |
11361 | 11816 | |
11362 | 11817 | Perl がビルドされたプラットフォームでのバイト順序は |
11363 | 11818 | L<Config> 経由か: |
11364 | 11819 | |
11365 | 11820 | use Config; |
11366 | 11821 | print "$Config{byteorder}\n"; |
11367 | 11822 | |
11368 | 11823 | =begin original |
11369 | 11824 | |
11370 | 11825 | or from the command line: |
11371 | 11826 | |
11372 | 11827 | =end original |
11373 | 11828 | |
11374 | 11829 | あるいはコマンドラインで: |
11375 | 11830 | |
11376 | 11831 | $ perl -V:byteorder |
11377 | 11832 | |
11378 | 11833 | =begin original |
11379 | 11834 | |
11380 | 11835 | Byteorders C<"1234"> and C<"12345678"> are little-endian; C<"4321"> |
11381 | 11836 | and C<"87654321"> are big-endian. Systems with multiarchitecture binaries |
11382 | 11837 | will have C<"ffff">, signifying that static information doesn't work, |
11383 | 11838 | one must use runtime probing. |
11384 | 11839 | |
11385 | 11840 | =end original |
11386 | 11841 | |
11387 | 11842 | C<"1234"> と C<"12345678"> はリトルエンディアンです; |
11388 | 11843 | C<"4321"> と C<"87654321"> はビッグエンディアンです。 |
11389 | 11844 | マルチアーキテクチャバイナリを持つシステムは |
11390 | 11845 | C<"ffff"> となります; これは静的な情報は動作せず、実行時調査を使う必要が |
11391 | 11846 | あることを示します。 |
11392 | 11847 | |
11393 | 11848 | =begin original |
11394 | 11849 | |
11395 | 11850 | For portably packed integers, either use the formats C<n>, C<N>, C<v>, |
11396 | 11851 | and C<V> or else use the C<< > >> and C<< < >> modifiers described |
11397 | 11852 | immediately below. See also L<perlport>. |
11398 | 11853 | |
11399 | 11854 | =end original |
11400 | 11855 | |
11401 | 11856 | 移植性のあるパック化された整数がほしい場合は、 |
11402 | 11857 | C<n>, C<N>, C<v>, C<V> フォーマットを使うか、 |
11403 | 11858 | 直後で説明する C<< > >> と C<< < >> の修飾子が使えます。 |
11404 | 11859 | L<perlport> も参照してください。 |
11405 | 11860 | |
11406 | 11861 | =item * |
11407 | 11862 | |
11408 | 11863 | =begin original |
11409 | 11864 | |
11410 | 11865 | Also floating point numbers have endianness. Usually (but not always) |
11411 | 11866 | this agrees with the integer endianness. Even though most platforms |
11412 | 11867 | these days use the IEEE 754 binary format, there are differences, |
11413 | 11868 | especially if the long doubles are involved. You can see the |
11414 | 11869 | C<Config> variables C<doublekind> and C<longdblkind> (also C<doublesize>, |
11415 | 11870 | C<longdblsize>): the "kind" values are enums, unlike C<byteorder>. |
11416 | 11871 | |
11417 | 11872 | =end original |
11418 | 11873 | |
11419 | 11874 | また、浮動小数点数にもエンディアンがあります。 |
11420 | 11875 | 通常は(但し常にではありません)これは整数のエンディアンと同じです。 |
11421 | 11876 | 最近のほとんどのプラットフォームが IEEE 754 バイナリ形式を使っているにも |
11422 | 11877 | 関わらず、(特に long double 関連で) 相違点があります。 |
11423 | 11878 | C<Config> 変数 C<doublekind> と C<longdblkind> (および C<doublesize>, |
11424 | 11879 | C<longdblsize>) を参照できます: "kind" 値は C<byteorder> と異なり、 |
11425 | 11880 | 順序値です。 |
11426 | 11881 | |
11427 | 11882 | =begin original |
11428 | 11883 | |
11429 | 11884 | Portability-wise the best option is probably to keep to the IEEE 754 |
11430 | 11885 | 64-bit doubles, and of agreed-upon endianness. Another possibility |
11431 | 11886 | is the C<"%a">) format of L<C<printf>|/printf FILEHANDLE FORMAT, LIST>. |
11432 | 11887 | |
11433 | 11888 | =end original |
11434 | 11889 | |
11435 | 11890 | 移植性を考慮した最良の選択肢はおそらく、IEEE 754 64-bit double と同意した |
11436 | 11891 | エンディアンを維持することです。 |
11437 | 11892 | もう一つの可能性は L<C<printf>|/printf FILEHANDLE FORMAT, LIST> の |
11438 | 11893 | C<"%a"> 型式です。 |
11439 | 11894 | |
11440 | 11895 | =item * |
11441 | 11896 | |
11442 | 11897 | =begin original |
11443 | 11898 | |
11444 | 11899 | Starting with Perl 5.10.0, integer and floating-point formats, along with |
11445 | 11900 | the C<p> and C<P> formats and C<()> groups, may all be followed by the |
11446 | 11901 | C<< > >> or C<< < >> endianness modifiers to respectively enforce big- |
11447 | 11902 | or little-endian byte-order. These modifiers are especially useful |
11448 | 11903 | given how C<n>, C<N>, C<v>, and C<V> don't cover signed integers, |
11449 | 11904 | 64-bit integers, or floating-point values. |
11450 | 11905 | |
11451 | 11906 | =end original |
11452 | 11907 | |
11453 | 11908 | Perl 5.10.0 から、C<p> と C<P> フォーマットや C<()> グループと同様、 |
11454 | 11909 | 全ての整数と浮動小数点数のフォーマットは、C<< > >> や C<< < >> の |
11455 | 11910 | エンディアン修飾子をつけることで、それぞれ |
11456 | 11911 | ビッグエンディアンとリトルエンディアンに強制させることができます。 |
11457 | 11912 | C<n>, C<N>, C<v>, C<V> は符号付き整数、64 ビット整数、浮動小数点数に |
11458 | 11913 | 対応していないので、これは特に有用です。 |
11459 | 11914 | |
11460 | 11915 | =begin original |
11461 | 11916 | |
11462 | 11917 | Here are some concerns to keep in mind when using an endianness modifier: |
11463 | 11918 | |
11464 | 11919 | =end original |
11465 | 11920 | |
11466 | 11921 | エンディアン修飾子を使うときに心に留めておくべきことを記します: |
11467 | 11922 | |
11468 | 11923 | =over |
11469 | 11924 | |
11470 | 11925 | =item * |
11471 | 11926 | |
11472 | 11927 | =begin original |
11473 | 11928 | |
11474 | 11929 | Exchanging signed integers between different platforms works only |
11475 | 11930 | when all platforms store them in the same format. Most platforms store |
11476 | 11931 | signed integers in two's-complement notation, so usually this is not an issue. |
11477 | 11932 | |
11478 | 11933 | =end original |
11479 | 11934 | |
11480 | 11935 | 異なったプラットフォームで符号付き整数を交換することは、全ての |
11481 | 11936 | プラットフォームで同じフォーマットで保存されている場合にのみうまくいきます。 |
11482 | 11937 | ほとんどのプラットフォームでは符号付き整数は 2 の補数記法で保存するので、 |
11483 | 11938 | 普通はこれは問題になりません。 |
11484 | 11939 | |
11485 | 11940 | =item * |
11486 | 11941 | |
11487 | 11942 | =begin original |
11488 | 11943 | |
11489 | 11944 | The C<< > >> or C<< < >> modifiers can only be used on floating-point |
11490 | 11945 | formats on big- or little-endian machines. Otherwise, attempting to |
11491 | 11946 | use them raises an exception. |
11492 | 11947 | |
11493 | 11948 | =end original |
11494 | 11949 | |
11495 | 11950 | C<< > >> や C<< < >> の修飾子はビッグエンディアンやリトルエンディアンの |
11496 | 11951 | マシンでの浮動小数点フォーマットでのみ使えます。 |
11497 | 11952 | それ以外では、そのようなことをすると例外が発生します。 |
11498 | 11953 | |
11499 | 11954 | =item * |
11500 | 11955 | |
11501 | 11956 | =begin original |
11502 | 11957 | |
11503 | 11958 | Forcing big- or little-endian byte-order on floating-point values for |
11504 | 11959 | data exchange can work only if all platforms use the same |
11505 | 11960 | binary representation such as IEEE floating-point. Even if all |
11506 | 11961 | platforms are using IEEE, there may still be subtle differences. Being able |
11507 | 11962 | to use C<< > >> or C<< < >> on floating-point values can be useful, |
11508 | 11963 | but also dangerous if you don't know exactly what you're doing. |
11509 | 11964 | It is not a general way to portably store floating-point values. |
11510 | 11965 | |
11511 | 11966 | =end original |
11512 | 11967 | |
11513 | 11968 | データ交換のために浮動小数点数のバイト順をビッグエンディアンかリトル |
11514 | 11969 | エンディアンに強制することは、全てのプラットフォームが |
11515 | 11970 | IEEE 浮動小数点フォーマットのような同じバイナリ表現の場合にのみ |
11516 | 11971 | うまくいきます。 |
11517 | 11972 | たとえ全てのプラットフォームが IEEE を使っていても、そこには微妙な違いが |
11518 | 11973 | あるかもしれません。 |
11519 | 11974 | 浮動小数点数に C<< > >> や C<< < >> が使えることは便利な場合がありますが、 |
11520 | 11975 | もし自分が何をしているかを正確に理解していなければ、危険です。 |
11521 | 11976 | 移植性のある浮動小数点数の保存のための一般的な方法はありません。 |
11522 | 11977 | |
11523 | 11978 | =item * |
11524 | 11979 | |
11525 | 11980 | =begin original |
11526 | 11981 | |
11527 | 11982 | When using C<< > >> or C<< < >> on a C<()> group, this affects |
11528 | 11983 | all types inside the group that accept byte-order modifiers, |
11529 | 11984 | including all subgroups. It is silently ignored for all other |
11530 | 11985 | types. You are not allowed to override the byte-order within a group |
11531 | 11986 | that already has a byte-order modifier suffix. |
11532 | 11987 | |
11533 | 11988 | =end original |
11534 | 11989 | |
11535 | 11990 | C<()> グループで C<< > >> や C<< < >> を使うと、これは、副グループを |
11536 | 11991 | 含む全ての型のうち、バイト順修飾子を受け入れる全てのものに影響与えます。 |
11537 | 11992 | その他の型については沈黙のうちに無視されます。 |
11538 | 11993 | 既にバイト順接尾辞を持っているグループ内のバイト順を上書きすることは |
11539 | 11994 | できません。 |
11540 | 11995 | |
11541 | 11996 | =back |
11542 | 11997 | |
11543 | 11998 | =item * |
11544 | 11999 | |
11545 | 12000 | =begin original |
11546 | 12001 | |
11547 | 12002 | Real numbers (floats and doubles) are in native machine format only. |
11548 | 12003 | Due to the multiplicity of floating-point formats and the lack of a |
11549 | 12004 | standard "network" representation for them, no facility for interchange has been |
11550 | 12005 | made. This means that packed floating-point data written on one machine |
11551 | 12006 | may not be readable on another, even if both use IEEE floating-point |
11552 | 12007 | arithmetic (because the endianness of the memory representation is not part |
11553 | 12008 | of the IEEE spec). See also L<perlport>. |
11554 | 12009 | |
11555 | 12010 | =end original |
11556 | 12011 | |
11557 | 12012 | 実数 (float と double) は、機種依存のフォーマットしかありません。 |
11558 | 12013 | いろんな浮動小数点数のフォーマットが在り、標準的な "network" 表現といったものが |
11559 | 12014 | ないため、データ交換のための機能は用意してありません。 |
11560 | 12015 | つまり、あるマシンで pack した浮動小数点数は、別のマシンでは |
11561 | 12016 | 読めないかもしれないということです; たとえ双方で IEEE フォーマットの |
11562 | 12017 | 浮動小数点数演算を行なっていてもです (IEEE の仕様では、メモリ表現上の |
11563 | 12018 | バイト順序までは、規定されていないからです)。 |
11564 | 12019 | L<perlport> も参照してください。 |
11565 | 12020 | |
11566 | 12021 | =begin original |
11567 | 12022 | |
11568 | 12023 | If you know I<exactly> what you're doing, you can use the C<< > >> or C<< < >> |
11569 | 12024 | modifiers to force big- or little-endian byte-order on floating-point values. |
11570 | 12025 | |
11571 | 12026 | =end original |
11572 | 12027 | |
11573 | 12028 | もし何をしようとしているのかを I<正確に> 理解しているなら、浮動小数点数の |
11574 | 12029 | バイト順をビッグエンディアンやリトルエンディアンに強制するために、 |
11575 | 12030 | C<< > >> と C<< < >> の修飾子が使えます。 |
11576 | 12031 | |
11577 | 12032 | =begin original |
11578 | 12033 | |
11579 | 12034 | Because Perl uses doubles (or long doubles, if configured) internally for |
11580 | 12035 | all numeric calculation, converting from double into float and thence |
11581 | 12036 | to double again loses precision, so C<unpack("f", pack("f", $foo)>) |
11582 | 12037 | will not in general equal $foo. |
11583 | 12038 | |
11584 | 12039 | =end original |
11585 | 12040 | |
11586 | 12041 | Perl では、すべての数値演算のために、内部的に double (または設定によっては |
11587 | 12042 | long double) を使用しているので、double から float へ変換し、それから再び |
11588 | 12043 | double に戻すと精度が落ちることになり、C<unpack("f", pack("f", $foo)>) は、 |
11589 | 12044 | 一般には $foo と同じではありません。 |
11590 | 12045 | |
11591 | 12046 | =item * |
11592 | 12047 | |
11593 | 12048 | =begin original |
11594 | 12049 | |
11595 | 12050 | Pack and unpack can operate in two modes: character mode (C<C0> mode) where |
11596 | 12051 | the packed string is processed per character, and UTF-8 byte mode (C<U0> mode) |
11597 | 12052 | where the packed string is processed in its UTF-8-encoded Unicode form on |
11598 | 12053 | a byte-by-byte basis. Character mode is the default |
11599 | 12054 | unless the format string starts with C<U>. You |
11600 | 12055 | can always switch mode mid-format with an explicit |
11601 | 12056 | C<C0> or C<U0> in the format. This mode remains in effect until the next |
11602 | 12057 | mode change, or until the end of the C<()> group it (directly) applies to. |
11603 | 12058 | |
11604 | 12059 | =end original |
11605 | 12060 | |
11606 | 12061 | pack と unpack は二つのモードで操作します: pack された文字列を文字単位で |
11607 | 12062 | 処理する文字モード (C<C0> モード) と、pack された文字列を、バイト毎に、 |
11608 | 12063 | その UTF-8 エンコードされた形式で処理するUTF-8 モード (C<U0> モード) です。 |
11609 | 12064 | 文字モードはフォーマット文字列が C<U> で始まっていない限りはデフォルトです。 |
11610 | 12065 | モードはフォーマット中に明示的に C<C0> または C<U0> と書くことでいつでも |
11611 | 12066 | 切り替えられます。 |
11612 | 12067 | モードは次のモードに切り替えられるか、(直接)適用された C<()> グループが |
11613 | 12068 | 終了するまで有効です。 |
11614 | 12069 | |
11615 | 12070 | =begin original |
11616 | 12071 | |
11617 | 12072 | Using C<C0> to get Unicode characters while using C<U0> to get I<non>-Unicode |
11618 | 12073 | bytes is not necessarily obvious. Probably only the first of these |
11619 | 12074 | is what you want: |
11620 | 12075 | |
11621 | 12076 | =end original |
11622 | 12077 | |
11623 | 12078 | Unicode 文字を取得するのに C<C0> を使い、I<非> Unicode バイトを取得するのに |
11624 | 12079 | C<U0> を使うというのは必ずしも明白ではありません。 |
11625 | 12080 | おそらく、これらのうち最初のものだけが望みのものでしょう: |
11626 | 12081 | |
11627 | 12082 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | |
11628 | 12083 | perl -CS -ne 'printf "%v04X\n", $_ for unpack("C0A*", $_)' |
11629 | 12084 | 03B1.03C9 |
11630 | 12085 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | |
11631 | 12086 | perl -CS -ne 'printf "%v02X\n", $_ for unpack("U0A*", $_)' |
11632 | 12087 | CE.B1.CF.89 |
11633 | 12088 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | |
11634 | 12089 | perl -C0 -ne 'printf "%v02X\n", $_ for unpack("C0A*", $_)' |
11635 | 12090 | CE.B1.CF.89 |
11636 | 12091 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | |
11637 | 12092 | perl -C0 -ne 'printf "%v02X\n", $_ for unpack("U0A*", $_)' |
11638 | 12093 | C3.8E.C2.B1.C3.8F.C2.89 |
11639 | 12094 | |
11640 | 12095 | =begin original |
11641 | 12096 | |
11642 | 12097 | Those examples also illustrate that you should not try to use |
11643 | 12098 | L<C<pack>|/pack TEMPLATE,LIST>/L<C<unpack>|/unpack TEMPLATE,EXPR> as a |
11644 | 12099 | substitute for the L<Encode> module. |
11645 | 12100 | |
11646 | 12101 | =end original |
11647 | 12102 | |
11648 | 12103 | これらの例は、L<C<pack>|/pack TEMPLATE,LIST>/ |
11649 | 12104 | L<C<unpack>|/unpack TEMPLATE,EXPR> を L<Encode> モジュールの代わりとして |
11650 | 12105 | 使おうとするべきではないということも示しています。 |
11651 | 12106 | |
11652 | 12107 | =item * |
11653 | 12108 | |
11654 | 12109 | =begin original |
11655 | 12110 | |
11656 | 12111 | You must yourself do any alignment or padding by inserting, for example, |
11657 | 12112 | enough C<"x">es while packing. There is no way for |
11658 | 12113 | L<C<pack>|/pack TEMPLATE,LIST> and L<C<unpack>|/unpack TEMPLATE,EXPR> |
11659 | 12114 | to know where characters are going to or coming from, so they |
11660 | 12115 | handle their output and input as flat sequences of characters. |
11661 | 12116 | |
11662 | 12117 | =end original |
11663 | 12118 | |
11664 | 12119 | pack するときに、例えば十分な数の C<"x"> を挿入することによって |
11665 | 12120 | アライメントやパッディングを行うのは全て自分でしなければなりません。 |
11666 | 12121 | L<C<pack>|/pack TEMPLATE,LIST> や L<C<unpack>|/unpack TEMPLATE,EXPR> は、 |
11667 | 12122 | 文字列がどこへ行くかやどこから来たかを |
11668 | 12123 | 知る方法はないので、出力と入力をフラットな文字列として扱います。 |
11669 | 12124 | |
11670 | 12125 | =item * |
11671 | 12126 | |
11672 | 12127 | =begin original |
11673 | 12128 | |
11674 | 12129 | A C<()> group is a sub-TEMPLATE enclosed in parentheses. A group may |
11675 | 12130 | take a repeat count either as postfix, or for |
11676 | 12131 | L<C<unpack>|/unpack TEMPLATE,EXPR>, also via the C</> |
11677 | 12132 | template character. Within each repetition of a group, positioning with |
11678 | 12133 | C<@> starts over at 0. Therefore, the result of |
11679 | 12134 | |
11680 | 12135 | =end original |
11681 | 12136 | |
11682 | 12137 | C<()> のグループはかっこで囲われた副テンプレートです。 |
11683 | 12138 | グループは繰り返し数を取ることができます; 接尾辞によるか、 |
11684 | 12139 | L<C<unpack>|/unpack TEMPLATE,EXPR> の場合は C</> テンプレート文字によります。 |
11685 | 12140 | グループの繰り返し毎に、C<@> の位置は 0 になります。 |
11686 | 12141 | 従って、以下の結果は: |
11687 | 12142 | |
11688 | 12143 | pack("@1A((@2A)@3A)", qw[X Y Z]) |
11689 | 12144 | |
11690 | 12145 | =begin original |
11691 | 12146 | |
11692 | 12147 | is the string C<"\0X\0\0YZ">. |
11693 | 12148 | |
11694 | 12149 | =end original |
11695 | 12150 | |
11696 | 12151 | 文字列 C<"\0X\0\0YZ"> です。 |
11697 | 12152 | |
11698 | 12153 | =item * |
11699 | 12154 | |
11700 | 12155 | =begin original |
11701 | 12156 | |
11702 | 12157 | C<x> and C<X> accept the C<!> modifier to act as alignment commands: they |
11703 | 12158 | jump forward or back to the closest position aligned at a multiple of C<count> |
11704 | 12159 | characters. For example, to L<C<pack>|/pack TEMPLATE,LIST> or |
11705 | 12160 | L<C<unpack>|/unpack TEMPLATE,EXPR> a C structure like |
11706 | 12161 | |
11707 | 12162 | =end original |
11708 | 12163 | |
11709 | 12164 | C<x> と C<X> にはアライメントコマンドとして C<!> 修飾子を付けることができます: |
11710 | 12165 | これは C<count> 文字の倍数のアライメントとなる、もっとも近い位置に移動します。 |
11711 | 12166 | 例えば、以下のような C 構造体を L<C<pack>|/pack TEMPLATE,LIST> または |
11712 | 12167 | L<C<unpack>|/unpack TEMPLATE,EXPR> するには |
11713 | 12168 | |
11714 | 12169 | struct { |
11715 | 12170 | char c; /* one signed, 8-bit character */ |
11716 | 12171 | double d; |
11717 | 12172 | char cc[2]; |
11718 | 12173 | } |
11719 | 12174 | |
11720 | 12175 | =begin original |
11721 | 12176 | |
11722 | 12177 | one may need to use the template C<c x![d] d c[2]>. This assumes that |
11723 | 12178 | doubles must be aligned to the size of double. |
11724 | 12179 | |
11725 | 12180 | =end original |
11726 | 12181 | |
11727 | 12182 | C<W x![d] d W[2]> というテンプレートを使う必要があるかもしれません。 |
11728 | 12183 | これは double が double のサイズでアライメントされていることを |
11729 | 12184 | 仮定しています。 |
11730 | 12185 | |
11731 | 12186 | =begin original |
11732 | 12187 | |
11733 | 12188 | For alignment commands, a C<count> of 0 is equivalent to a C<count> of 1; |
11734 | 12189 | both are no-ops. |
11735 | 12190 | |
11736 | 12191 | =end original |
11737 | 12192 | |
11738 | 12193 | アライメントコマンドに対しては、C<count> に 0 を指定するのは |
11739 | 12194 | C<count> に 1 を指定するのと等価です; どちらも何もしません。 |
11740 | 12195 | |
11741 | 12196 | =item * |
11742 | 12197 | |
11743 | 12198 | =begin original |
11744 | 12199 | |
11745 | 12200 | C<n>, C<N>, C<v> and C<V> accept the C<!> modifier to |
11746 | 12201 | represent signed 16-/32-bit integers in big-/little-endian order. |
11747 | 12202 | This is portable only when all platforms sharing packed data use the |
11748 | 12203 | same binary representation for signed integers; for example, when all |
11749 | 12204 | platforms use two's-complement representation. |
11750 | 12205 | |
11751 | 12206 | =end original |
11752 | 12207 | |
11753 | 12208 | C<n>, C<N>, C<v>, C<V> はビッグ/リトルエンディアンの順序で符号付き 16 または |
11754 | 12209 | 32 ビット整数で表現するための C<!> 修飾子を受け入れます。 |
11755 | 12210 | これは pack されたデータを共有する全てのプラットフォームが |
11756 | 12211 | 符号付き整数について同じバイナリ表現を使う場合にのみ移植性があります; |
11757 | 12212 | 例えば、全てのプラットフォームで 2 の補数表現を使う場合です。 |
11758 | 12213 | |
11759 | 12214 | =item * |
11760 | 12215 | |
11761 | 12216 | =begin original |
11762 | 12217 | |
11763 | 12218 | Comments can be embedded in a TEMPLATE using C<#> through the end of line. |
11764 | 12219 | White space can separate pack codes from each other, but modifiers and |
11765 | 12220 | repeat counts must follow immediately. Breaking complex templates into |
11766 | 12221 | individual line-by-line components, suitably annotated, can do as much to |
11767 | 12222 | improve legibility and maintainability of pack/unpack formats as C</x> can |
11768 | 12223 | for complicated pattern matches. |
11769 | 12224 | |
11770 | 12225 | =end original |
11771 | 12226 | |
11772 | 12227 | TEMPLATE の中の C<#> から行末まではコメントです。 |
11773 | 12228 | 空白は pack コードをそれぞれ分けるために使えますが、修飾子と |
11774 | 12229 | 繰り返し数は直後に置かなければなりません。 |
11775 | 12230 | 複雑なテンプレートを個々の行単位の要素に分解して適切に注釈をつけると、 |
11776 | 12231 | 複雑なパターンマッチングに対する C</x> と同じぐらい、pack/unpack |
11777 | 12232 | フォーマットの読みやすさと保守性が向上します。 |
11778 | 12233 | |
11779 | 12234 | =item * |
11780 | 12235 | |
11781 | 12236 | =begin original |
11782 | 12237 | |
11783 | 12238 | If TEMPLATE requires more arguments than L<C<pack>|/pack TEMPLATE,LIST> |
11784 | 12239 | is given, L<C<pack>|/pack TEMPLATE,LIST> |
11785 | 12240 | assumes additional C<""> arguments. If TEMPLATE requires fewer arguments |
11786 | 12241 | than given, extra arguments are ignored. |
11787 | 12242 | |
11788 | 12243 | =end original |
11789 | 12244 | |
11790 | 12245 | TEMPLATE が要求する引数の数が L<C<pack>|/pack TEMPLATE,LIST> が実際に |
11791 | 12246 | 与えている数より多い場合、 |
11792 | 12247 | L<C<pack>|/pack TEMPLATE,LIST> は追加の C<""> 引数があるものと仮定します。 |
11793 | 12248 | TEMPLATE が要求する引数の数の方が少ない場合、余分の引数は無視されます。 |
11794 | 12249 | |
11795 | 12250 | =item * |
11796 | 12251 | |
11797 | 12252 | =begin original |
11798 | 12253 | |
11799 | 12254 | Attempting to pack the special floating point values C<Inf> and C<NaN> |
11800 | 12255 | (infinity, also in negative, and not-a-number) into packed integer values |
11801 | 12256 | (like C<"L">) is a fatal error. The reason for this is that there simply |
11802 | 12257 | isn't any sensible mapping for these special values into integers. |
11803 | 12258 | |
11804 | 12259 | =end original |
11805 | 12260 | |
11806 | 12261 | 特殊浮動小数点値 C<Inf> と C<NaN> |
11807 | 12262 | ((負を含む)無限と非数) を (C<"L"> のような) 整数値に pack しようとすると |
11808 | 12263 | 致命的エラーとなります。 |
11809 | 12264 | この理由は、単に特殊値を整数に割り当てられないからです。 |
11810 | 12265 | |
11811 | 12266 | =back |
11812 | 12267 | |
11813 | 12268 | =begin original |
11814 | 12269 | |
11815 | 12270 | Examples: |
11816 | 12271 | |
11817 | 12272 | =end original |
11818 | 12273 | |
11819 | 12274 | 例: |
11820 | 12275 | |
11821 | 12276 | $foo = pack("WWWW",65,66,67,68); |
11822 | 12277 | # foo eq "ABCD" |
11823 | 12278 | $foo = pack("W4",65,66,67,68); |
11824 | 12279 | # same thing |
11825 | 12280 | $foo = pack("W4",0x24b6,0x24b7,0x24b8,0x24b9); |
11826 | 12281 | # same thing with Unicode circled letters. |
11827 | 12282 | $foo = pack("U4",0x24b6,0x24b7,0x24b8,0x24b9); |
11828 | 12283 | # same thing with Unicode circled letters. You don't get the |
11829 | 12284 | # UTF-8 bytes because the U at the start of the format caused |
11830 | 12285 | # a switch to U0-mode, so the UTF-8 bytes get joined into |
11831 | 12286 | # characters |
11832 | 12287 | $foo = pack("C0U4",0x24b6,0x24b7,0x24b8,0x24b9); |
11833 | 12288 | # foo eq "\xe2\x92\xb6\xe2\x92\xb7\xe2\x92\xb8\xe2\x92\xb9" |
11834 | 12289 | # This is the UTF-8 encoding of the string in the |
11835 | 12290 | # previous example |
11836 | 12291 | |
11837 | 12292 | $foo = pack("ccxxcc",65,66,67,68); |
11838 | 12293 | # foo eq "AB\0\0CD" |
11839 | 12294 | |
11840 | 12295 | # NOTE: The examples above featuring "W" and "c" are true |
11841 | 12296 | # only on ASCII and ASCII-derived systems such as ISO Latin 1 |
11842 | 12297 | # and UTF-8. On EBCDIC systems, the first example would be |
11843 | 12298 | # $foo = pack("WWWW",193,194,195,196); |
11844 | 12299 | |
11845 | 12300 | $foo = pack("s2",1,2); |
11846 | 12301 | # "\001\000\002\000" on little-endian |
11847 | 12302 | # "\000\001\000\002" on big-endian |
11848 | 12303 | |
11849 | 12304 | $foo = pack("a4","abcd","x","y","z"); |
11850 | 12305 | # "abcd" |
11851 | 12306 | |
11852 | 12307 | $foo = pack("aaaa","abcd","x","y","z"); |
11853 | 12308 | # "axyz" |
11854 | 12309 | |
11855 | 12310 | $foo = pack("a14","abcdefg"); |
11856 | 12311 | # "abcdefg\0\0\0\0\0\0\0" |
11857 | 12312 | |
11858 | 12313 | $foo = pack("i9pl", gmtime); |
11859 | 12314 | # a real struct tm (on my system anyway) |
11860 | 12315 | |
11861 | 12316 | $utmp_template = "Z8 Z8 Z16 L"; |
11862 | 12317 | $utmp = pack($utmp_template, @utmp1); |
11863 | 12318 | # a struct utmp (BSDish) |
11864 | 12319 | |
11865 | 12320 | @utmp2 = unpack($utmp_template, $utmp); |
11866 | 12321 | # "@utmp1" eq "@utmp2" |
11867 | 12322 | |
11868 | 12323 | sub bintodec { |
11869 | 12324 | unpack("N", pack("B32", substr("0" x 32 . shift, -32))); |
11870 | 12325 | } |
11871 | 12326 | |
11872 | 12327 | $foo = pack('sx2l', 12, 34); |
11873 | 12328 | # short 12, two zero bytes padding, long 34 |
11874 | 12329 | $bar = pack('s@4l', 12, 34); |
11875 | 12330 | # short 12, zero fill to position 4, long 34 |
11876 | 12331 | # $foo eq $bar |
11877 | 12332 | $baz = pack('s.l', 12, 4, 34); |
11878 | 12333 | # short 12, zero fill to position 4, long 34 |
11879 | 12334 | |
11880 | 12335 | $foo = pack('nN', 42, 4711); |
11881 | 12336 | # pack big-endian 16- and 32-bit unsigned integers |
11882 | 12337 | $foo = pack('S>L>', 42, 4711); |
11883 | 12338 | # exactly the same |
11884 | 12339 | $foo = pack('s<l<', -42, 4711); |
11885 | 12340 | # pack little-endian 16- and 32-bit signed integers |
11886 | 12341 | $foo = pack('(sl)<', -42, 4711); |
11887 | 12342 | # exactly the same |
11888 | 12343 | |
11889 | 12344 | =begin original |
11890 | 12345 | |
11891 | 12346 | The same template may generally also be used in |
11892 | 12347 | L<C<unpack>|/unpack TEMPLATE,EXPR>. |
11893 | 12348 | |
11894 | 12349 | =end original |
11895 | 12350 | |
11896 | 12351 | 一般的には、同じテンプレートが L<C<unpack>|/unpack TEMPLATE,EXPR> でも |
11897 | 12352 | 使用できます。 |
11898 | 12353 | |
11899 | 12354 | =item package NAMESPACE |
11900 | 12355 | |
11901 | 12356 | =item package NAMESPACE VERSION |
11902 | 12357 | X<package> X<module> X<namespace> X<version> |
11903 | 12358 | |
11904 | 12359 | =item package NAMESPACE BLOCK |
11905 | 12360 | |
11906 | 12361 | =item package NAMESPACE VERSION BLOCK |
11907 | 12362 | X<package> X<module> X<namespace> X<version> |
11908 | 12363 | |
11909 | 12364 | =for Pod::Functions declare a separate global namespace |
11910 | 12365 | |
11911 | 12366 | =begin original |
11912 | 12367 | |
11913 | 12368 | Declares the BLOCK or the rest of the compilation unit as being in the |
11914 | 12369 | given namespace. The scope of the package declaration is either the |
11915 | 12370 | supplied code BLOCK or, in the absence of a BLOCK, from the declaration |
11916 | 12371 | itself through the end of current scope (the enclosing block, file, or |
11917 | 12372 | L<C<eval>|/eval EXPR>). That is, the forms without a BLOCK are |
11918 | 12373 | operative through the end of the current scope, just like the |
11919 | 12374 | L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>, and |
11920 | 12375 | L<C<our>|/our VARLIST> operators. All unqualified dynamic identifiers |
11921 | 12376 | in this scope will be in the given namespace, except where overridden by |
11922 | 12377 | another L<C<package>|/package NAMESPACE> declaration or |
11923 | 12378 | when they're one of the special identifiers that qualify into C<main::>, |
11924 | 12379 | like C<STDOUT>, C<ARGV>, C<ENV>, and the punctuation variables. |
11925 | 12380 | |
11926 | 12381 | =end original |
11927 | 12382 | |
11928 | 12383 | BLOCK や残りのコンパイル単位を与えられた名前空間として宣言します。 |
11929 | 12384 | パッケージ宣言のスコープは BLOCK か、BLOCK がないばあいは宣言自身から |
11930 | 12385 | 現在のスコープの末尾 (閉じたブロック、ファイル、L<C<eval>|/eval EXPR>) です。 |
11931 | 12386 | つまり、BLOCK なしの形式は、L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>, |
11932 | 12387 | L<C<our>|/our VARLIST> 演算子と同様に現在のスコープの末尾にまで作用します。 |
11933 | 12388 | このスコープ内の、全ての完全修飾されていない動的識別子は、他の |
11934 | 12389 | L<C<package>|/package NAMESPACE> 宣言によって上書きされるか、 |
11935 | 12390 | C<STDOUT>, C<ARGV>, C<ENV> や句読点変数のように C<main::> に |
11936 | 12391 | 割り当てられる特殊変数でない限り、指定された |
11937 | 12392 | 名前空間になります。 |
11938 | 12393 | |
11939 | 12394 | =begin original |
11940 | 12395 | |
11941 | 12396 | A package statement affects dynamic variables only, including those |
11942 | 12397 | you've used L<C<local>|/local EXPR> on, but I<not> lexically-scoped |
11943 | 12398 | variables, which are created with L<C<my>|/my VARLIST>, |
11944 | 12399 | L<C<state>|/state VARLIST>, or L<C<our>|/our VARLIST>. Typically it |
11945 | 12400 | would be the first declaration in a file included by |
11946 | 12401 | L<C<require>|/require VERSION> or L<C<use>|/use Module VERSION LIST>. |
11947 | 12402 | You can switch into a |
11948 | 12403 | package in more than one place, since this only determines which default |
11949 | 12404 | symbol table the compiler uses for the rest of that block. You can refer to |
11950 | 12405 | identifiers in other packages than the current one by prefixing the identifier |
11951 | 12406 | with the package name and a double colon, as in C<$SomePack::var> |
11952 | 12407 | or C<ThatPack::INPUT_HANDLE>. If package name is omitted, the C<main> |
11953 | 12408 | package as assumed. That is, C<$::sail> is equivalent to |
11954 | 12409 | C<$main::sail> (as well as to C<$main'sail>, still seen in ancient |
11955 | 12410 | code, mostly from Perl 4). |
11956 | 12411 | |
11957 | 12412 | =end original |
11958 | 12413 | |
11959 | 12414 | package 文は動的変数にのみ影響します(L<C<local>|/local EXPR> で使ったものも |
11960 | 12415 | 含みます)が、L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>, |
11961 | 12416 | L<C<our>|/our VARLIST> のいずれかで作成された |
11962 | 12417 | レキシカルなスコープの変数には I<影響しません>。 |
11963 | 12418 | 典型的にはこれは L<C<require>|/require VERSION> や |
11964 | 12419 | L<C<use>|/use Module VERSION LIST> 演算子でインクルードされるファイルの |
11965 | 12420 | 最初に宣言されます。 |
11966 | 12421 | パッケージを複数の場所で切り替えることができます; |
11967 | 12422 | なぜならこれは単にコンパイラがこのブロックの残りに対してどの |
11968 | 12423 | シンボルテーブルを使うかにのみ影響するからです。 |
11969 | 12424 | 他のパッケージの識別子は、C<$SomePack::var> や |
11970 | 12425 | C<ThatPack::INPUT_HANDLE> のように、識別子にパッケージ名と |
11971 | 12426 | コロン二つをつけることで参照できます。 |
11972 | 12427 | パッケージ名が省略された場合、C<main> パッケージが仮定されます。 |
11973 | 12428 | つまり、C<$::sail> は C<$main::sail> と等価です(ほとんどは Perl 4 からの、 |
11974 | 12429 | 古いコードでは C<$main'sail> もまだ見られます)。 |
11975 | 12430 | |
11976 | 12431 | =begin original |
11977 | 12432 | |
11978 | 12433 | If VERSION is provided, L<C<package>|/package NAMESPACE> sets the |
11979 | 12434 | C<$VERSION> variable in the given |
11980 | 12435 | namespace to a L<version> object with the VERSION provided. VERSION must be a |
11981 | 12436 | "strict" style version number as defined by the L<version> module: a positive |
11982 | 12437 | decimal number (integer or decimal-fraction) without exponentiation or else a |
11983 | 12438 | dotted-decimal v-string with a leading 'v' character and at least three |
11984 | 12439 | components. You should set C<$VERSION> only once per package. |
11985 | 12440 | |
11986 | 12441 | =end original |
11987 | 12442 | |
11988 | 12443 | VERSION が指定されると、L<C<package>|/package NAMESPACE> は与えられた |
11989 | 12444 | 名前空間の C<$VERSION> 変数に、 |
11990 | 12445 | 指定された VERSION の L<version> オブジェクトをセットします。 |
11991 | 12446 | VERSION は L<version> で定義されている「厳密な」形式のバージョン番号で |
11992 | 12447 | なければなりません: 指数のない正の 10 進数 (整数か 10 進小数) か、 |
11993 | 12448 | さもなければ先頭に 'v' の文字が付いて、少なくとも三つの部分から |
11994 | 12449 | 構成されるドット付き 10 進v-文字列です。 |
11995 | 12450 | C<$VERSION> はパッケージ毎に 1 回だけセットするべきです。 |
11996 | 12451 | |
11997 | 12452 | =begin original |
11998 | 12453 | |
11999 | 12454 | See L<perlmod/"Packages"> for more information about packages, modules, |
12000 | 12455 | and classes. See L<perlsub> for other scoping issues. |
12001 | 12456 | |
12002 | 12457 | =end original |
12003 | 12458 | |
12004 | 12459 | パッケージ、モジュール、クラスに関するさらなる情報については |
12005 | 12460 | L<perlmod/"Packages"> を参照してください。 |
12006 | 12461 | その他のスコープに関する話題については L<perlsub> を参照してください。 |
12007 | 12462 | |
12008 | 12463 | =item __PACKAGE__ |
12009 | 12464 | X<__PACKAGE__> |
12010 | 12465 | |
12011 | 12466 | =for Pod::Functions +5.004 the current package |
12012 | 12467 | |
12013 | 12468 | =begin original |
12014 | 12469 | |
12015 | 12470 | A special token that returns the name of the package in which it occurs. |
12016 | 12471 | |
12017 | 12472 | =end original |
12018 | 12473 | |
12019 | 12474 | これが書いてあるパッケージの名前を返す特殊トークン。 |
12020 | 12475 | |
12021 | 12476 | =item pipe READHANDLE,WRITEHANDLE |
12022 | 12477 | X<pipe> |
12023 | 12478 | |
12024 | 12479 | =for Pod::Functions open a pair of connected filehandles |
12025 | 12480 | |
12026 | 12481 | =begin original |
12027 | 12482 | |
12028 | 12483 | Opens a pair of connected pipes like the corresponding system call. |
12029 | 12484 | Note that if you set up a loop of piped processes, deadlock can occur |
12030 | 12485 | unless you are very careful. In addition, note that Perl's pipes use |
12031 | 12486 | IO buffering, so you may need to set L<C<$E<verbar>>|perlvar/$E<verbar>> |
12032 | 12487 | to flush your WRITEHANDLE after each command, depending on the |
12033 | 12488 | application. |
12034 | 12489 | |
12035 | 12490 | =end original |
12036 | 12491 | |
12037 | 12492 | 対応するシステムコールと同じように、接続されたパイプのペアを開きます。 |
12038 | 12493 | パイプでプロセスをループにするときには、よほど気を付けないと、 |
12039 | 12494 | デッドロックが起こり得ます。 |
12040 | 12495 | さらに、Perl のパイプでは、IO のバッファリングを使ので、 |
12041 | 12496 | アプリケーションによっては、コマンドごとに WRITEHANDLE を |
12042 | 12497 | フラッシュするように、L<C<$E<verbar>>|perlvar/$E<verbar>> を設定することが |
12043 | 12498 | 必要になるかもしれません。 |
12044 | 12499 | |
12045 | 12500 | =begin original |
12046 | 12501 | |
12047 | 12502 | Returns true on success. |
12048 | 12503 | |
12049 | 12504 | =end original |
12050 | 12505 | |
12051 | 12506 | 成功時には真を返します。 |
12052 | 12507 | |
12053 | 12508 | =begin original |
12054 | 12509 | |
12055 | 12510 | See L<IPC::Open2>, L<IPC::Open3>, and |
12056 | 12511 | L<perlipc/"Bidirectional Communication with Another Process"> |
12057 | 12512 | for examples of such things. |
12058 | 12513 | |
12059 | 12514 | =end original |
12060 | 12515 | |
12061 | 12516 | これらに関する例については、L<IPC::Open2>, L<IPC::Open3>, |
12062 | 12517 | L<perlipc/"Bidirectional Communication with Another Process"> を |
12063 | 12518 | 参照してください。 |
12064 | 12519 | |
12065 | 12520 | =begin original |
12066 | 12521 | |
12067 | 12522 | On systems that support a close-on-exec flag on files, that flag is set |
12068 | 12523 | on all newly opened file descriptors whose |
12069 | 12524 | L<C<fileno>|/fileno FILEHANDLE>s are I<higher> than the current value of |
12070 | 12525 | L<C<$^F>|perlvar/$^F> (by default 2 for C<STDERR>). See L<perlvar/$^F>. |
12071 | 12526 | |
12072 | 12527 | =end original |
12073 | 12528 | |
12074 | 12529 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
12075 | 12530 | 新しくオープンされたファイル記述子のうち、 |
12076 | 12531 | L<C<fileno>|/fileno FILEHANDLE> が現在の L<C<$^F>|perlvar/$^F> の値 |
12077 | 12532 | (デフォルトでは C<STDERR> の 2) |
12078 | 12533 | I<よりも大きい> ものに対してフラグがセットされます。 |
12079 | 12534 | L<perlvar/$^F> を参照してください。 |
12080 | 12535 | |
12081 | 12536 | =item pop ARRAY |
12082 | 12537 | X<pop> X<stack> |
12083 | 12538 | |
12084 | 12539 | =item pop |
12085 | 12540 | |
12086 | 12541 | =for Pod::Functions remove the last element from an array and return it |
12087 | 12542 | |
12088 | 12543 | =begin original |
12089 | 12544 | |
12090 | 12545 | Pops and returns the last value of the array, shortening the array by |
12091 | 12546 | one element. |
12092 | 12547 | |
12093 | 12548 | =end original |
12094 | 12549 | |
12095 | 12550 | 配列の最後の値をポップして返し、配列の大きさを 1 だけ小さくします。 |
12096 | 12551 | |
12097 | 12552 | =begin original |
12098 | 12553 | |
12099 | 12554 | Returns the undefined value if the array is empty, although this may |
12100 | 12555 | also happen at other times. If ARRAY is omitted, pops the |
12101 | 12556 | L<C<@ARGV>|perlvar/@ARGV> array in the main program, but the |
12102 | 12557 | L<C<@_>|perlvar/@_> array in subroutines, just like |
12103 | 12558 | L<C<shift>|/shift ARRAY>. |
12104 | 12559 | |
12105 | 12560 | =end original |
12106 | 12561 | |
12107 | 12562 | 指定された配列に要素がなければ未定義値が返されますが、 |
12108 | 12563 | しかしこれは他の場合にも起こり得ます。 |
12109 | 12564 | ARRAY が省略されると、L<C<shift>|/shift ARRAY> と同様に、メインプログラムでは |
12110 | 12565 | L<C<@ARGV>|perlvar/@ARGV> が使われますが、 |
12111 | 12566 | サブルーチンでは L<C<@_>|perlvar/@_> が使われます。 |
12112 | 12567 | |
12113 | 12568 | =begin original |
12114 | 12569 | |
12115 | 12570 | Starting with Perl 5.14, an experimental feature allowed |
12116 | 12571 | L<C<pop>|/pop ARRAY> to take a |
12117 | 12572 | scalar expression. This experiment has been deemed unsuccessful, and was |
12118 | 12573 | removed as of Perl 5.24. |
12119 | 12574 | |
12120 | 12575 | =end original |
12121 | 12576 | |
12122 | 12577 | Perl 5.14 から、L<C<pop>|/pop ARRAY> がスカラ式を取ることが出来るという |
12123 | 12578 | 実験的機能がありました。 |
12124 | 12579 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 |
12125 | 12580 | |
12126 | 12581 | =item pos SCALAR |
12127 | 12582 | X<pos> X<match, position> |
12128 | 12583 | |
12129 | 12584 | =item pos |
12130 | 12585 | |
12131 | 12586 | =for Pod::Functions find or set the offset for the last/next m//g search |
12132 | 12587 | |
12133 | 12588 | =begin original |
12134 | 12589 | |
12135 | 12590 | Returns the offset of where the last C<m//g> search left off for the |
12136 | 12591 | variable in question (L<C<$_>|perlvar/$_> is used when the variable is not |
12137 | 12592 | specified). This offset is in characters unless the |
12138 | 12593 | (no-longer-recommended) L<C<use bytes>|bytes> pragma is in effect, in |
12139 | 12594 | which case the offset is in bytes. Note that 0 is a valid match offset. |
12140 | 12595 | L<C<undef>|/undef EXPR> indicates |
12141 | 12596 | that the search position is reset (usually due to match failure, but |
12142 | 12597 | can also be because no match has yet been run on the scalar). |
12143 | 12598 | |
12144 | 12599 | =end original |
12145 | 12600 | |
12146 | 12601 | 対象の変数に対して、前回の C<m//g> が終了した場所の |
12147 | 12602 | オフセットを返します(変数が指定されなかった場合は L<C<$_>|perlvar/$_> が |
12148 | 12603 | 使われます)。 |
12149 | 12604 | オフセットは、(もはや勧められない) L<C<use bytes>|bytes> プラグマが有効の |
12150 | 12605 | 場合(この場合はバイト単位です)を除いて、文字単位です。 |
12151 | 12606 | 0 は有効なマッチオフセットであることに注意してください。 |
12152 | 12607 | L<C<undef>|/undef EXPR> は検索位置がリセットされることを意味します (通常は |
12153 | 12608 | マッチ失敗が原因ですが、このスカラ値にまだマッチングが |
12154 | 12609 | 行われていないためかもしれません)。 |
12155 | 12610 | |
12156 | 12611 | =begin original |
12157 | 12612 | |
12158 | 12613 | L<C<pos>|/pos SCALAR> directly accesses the location used by the regexp |
12159 | 12614 | engine to store the offset, so assigning to L<C<pos>|/pos SCALAR> will |
12160 | 12615 | change that offset, and so will also influence the C<\G> zero-width |
12161 | 12616 | assertion in regular expressions. Both of these effects take place for |
12162 | 12617 | the next match, so you can't affect the position with |
12163 | 12618 | L<C<pos>|/pos SCALAR> during the current match, such as in |
12164 | 12619 | C<(?{pos() = 5})> or C<s//pos() = 5/e>. |
12165 | 12620 | |
12166 | 12621 | =end original |
12167 | 12622 | |
12168 | 12623 | L<C<pos>|/pos SCALAR> は正規表現エンジンがオフセットを保存するために使う場所を |
12169 | 12624 | 直接アクセスするので、L<C<pos>|/pos SCALAR> への代入はオフセットを変更し、 |
12170 | 12625 | そのような変更は正規表現における C<\G> ゼロ幅アサートにも影響を与えます。 |
12171 | 12626 | これらの効果の両方は次のマッチングのために行われるので、 |
12172 | 12627 | C<(?{pos() = 5})> や C<s//pos() = 5/e> のように現在のマッチング中の |
12173 | 12628 | L<C<pos>|/pos SCALAR> の位置には影響を与えません。 |
12174 | 12629 | |
12175 | 12630 | =begin original |
12176 | 12631 | |
12177 | 12632 | Setting L<C<pos>|/pos SCALAR> also resets the I<matched with |
12178 | 12633 | zero-length> flag, described |
12179 | 12634 | under L<perlre/"Repeated Patterns Matching a Zero-length Substring">. |
12180 | 12635 | |
12181 | 12636 | =end original |
12182 | 12637 | |
12183 | 12638 | L<C<pos>|/pos SCALAR> を設定すると、 |
12184 | 12639 | L<perlre/"Repeated Patterns Matching a Zero-length Substring"> に |
12185 | 12640 | 記述されている、I<長さ 0 でマッチング> フラグもリセットされます。 |
12186 | 12641 | |
12187 | 12642 | =begin original |
12188 | 12643 | |
12189 | 12644 | Because a failed C<m//gc> match doesn't reset the offset, the return |
12190 | 12645 | from L<C<pos>|/pos SCALAR> won't change either in this case. See |
12191 | 12646 | L<perlre> and L<perlop>. |
12192 | 12647 | |
12193 | 12648 | =end original |
12194 | 12649 | |
12195 | 12650 | C<m//gc> マッチに失敗してもオフセットはリセットしないので、 |
12196 | 12651 | L<C<pos>|/pos SCALAR> からの返り値はどちらの場合も変更されません。 |
12197 | 12652 | L<perlre> と L<perlop> を参照してください。 |
12198 | 12653 | |
12199 | 12654 | =item print FILEHANDLE LIST |
12200 | 12655 | X<print> |
12201 | 12656 | |
12202 | 12657 | =item print FILEHANDLE |
12203 | 12658 | |
12204 | 12659 | =item print LIST |
12205 | 12660 | |
12206 | 12661 | =item print |
12207 | 12662 | |
12208 | 12663 | =for Pod::Functions output a list to a filehandle |
12209 | 12664 | |
12210 | 12665 | =begin original |
12211 | 12666 | |
12212 | 12667 | Prints a string or a list of strings. Returns true if successful. |
12213 | 12668 | FILEHANDLE may be a scalar variable containing the name of or a reference |
12214 | 12669 | to the filehandle, thus introducing one level of indirection. (NOTE: If |
12215 | 12670 | FILEHANDLE is a variable and the next token is a term, it may be |
12216 | 12671 | misinterpreted as an operator unless you interpose a C<+> or put |
12217 | 12672 | parentheses around the arguments.) If FILEHANDLE is omitted, prints to the |
12218 | 12673 | last selected (see L<C<select>|/select FILEHANDLE>) output handle. If |
12219 | 12674 | LIST is omitted, prints L<C<$_>|perlvar/$_> to the currently selected |
12220 | 12675 | output handle. To use FILEHANDLE alone to print the content of |
12221 | 12676 | L<C<$_>|perlvar/$_> to it, you must use a bareword filehandle like |
12222 | 12677 | C<FH>, not an indirect one like C<$fh>. To set the default output handle |
12223 | 12678 | to something other than STDOUT, use the select operation. |
12224 | 12679 | |
12225 | 12680 | =end original |
12226 | 12681 | |
12227 | 12682 | 文字列か文字列のリストを出力します。 |
12228 | 12683 | 成功時には真を返します。 |
12229 | 12684 | FILEHANDLE は、ファイルハンドル名またはそのリファレンスが |
12230 | 12685 | 入っているスカラ変数名でもよいので、一段階の間接指定が行なえます。 |
12231 | 12686 | (注: FILEHANDLE に変数を使い、次のトークンが「項」のときには、 |
12232 | 12687 | 間に C<+> を置くか、引数の前後を括弧で括らなければ、 |
12233 | 12688 | 誤って解釈されることがあります。) |
12234 | 12689 | FILEHANDLE を省略した場合には、最後に選択された |
12235 | 12690 | (L<C<select>|/select FILEHANDLE> 参照) 出力チャネルに出力します。 |
12236 | 12691 | LIST を省略すると、L<C<$_>|perlvar/$_> が現在選択されている出力ハンドルに |
12237 | 12692 | 出力されます。 |
12238 | 12693 | L<C<$_>|perlvar/$_> の内容を表示するために FILEHANDLE のみを使用するには、 |
12239 | 12694 | C<$fh> のような間接ファイルハンドルではなく、C<FH> のような裸の単語の |
12240 | 12695 | ファイルハンドルを使わなければなりません。 |
12241 | 12696 | デフォルトの出力チャネルを STDOUT 以外にするには、select 演算子を |
12242 | 12697 | 使ってください。 |
12243 | 12698 | |
12244 | 12699 | =begin original |
12245 | 12700 | |
12246 | 12701 | The current value of L<C<$,>|perlvar/$,> (if any) is printed between |
12247 | 12702 | each LIST item. The current value of L<C<$\>|perlvar/$\> (if any) is |
12248 | 12703 | printed after the entire LIST has been printed. Because print takes a |
12249 | 12704 | LIST, anything in the LIST is evaluated in list context, including any |
12250 | 12705 | subroutines whose return lists you pass to |
12251 | 12706 | L<C<print>|/print FILEHANDLE LIST>. Be careful not to follow the print |
12252 | 12707 | keyword with a left |
12253 | 12708 | parenthesis unless you want the corresponding right parenthesis to |
12254 | 12709 | terminate the arguments to the print; put parentheses around all arguments |
12255 | 12710 | (or interpose a C<+>, but that doesn't look as good). |
12256 | 12711 | |
12257 | 12712 | =end original |
12258 | 12713 | |
12259 | 12714 | L<C<$,>|perlvar/$,> の値が(もしあれば)各 LIST 要素の間に出力されます。 |
12260 | 12715 | LIST 全体が出力された後、(もしあれば) L<C<$\>|perlvar/$\> の現在の値が |
12261 | 12716 | 出力されます。 |
12262 | 12717 | print の引数は LIST なので、LIST の中のものは、すべてリストコンテキストで |
12263 | 12718 | 評価されます; L<C<print>|/print FILEHANDLE LIST> に渡した、リストを返す |
12264 | 12719 | サブルーチンも含みます。 |
12265 | 12720 | また、すべての引数を括弧で括るのでなければ、print というキーワードの |
12266 | 12721 | 次に開き括弧を書いてはいけません; すべての引数を括弧で括ってください |
12267 | 12722 | (あるいは "print" と引数の間に C<+> を書きますが、これはあまり |
12268 | 12723 | よくありません)。 |
12269 | 12724 | |
12270 | 12725 | =begin original |
12271 | 12726 | |
12272 | 12727 | If you're storing handles in an array or hash, or in general whenever |
12273 | 12728 | you're using any expression more complex than a bareword handle or a plain, |
12274 | 12729 | unsubscripted scalar variable to retrieve it, you will have to use a block |
12275 | 12730 | returning the filehandle value instead, in which case the LIST may not be |
12276 | 12731 | omitted: |
12277 | 12732 | |
12278 | 12733 | =end original |
12279 | 12734 | |
12280 | 12735 | もし FILESHANDLE を配列、ハッシュあるいは一般的には裸の単語のハンドルや |
12281 | 12736 | 普通のスカラ変数よりも複雑な表現を使っている場合、代わりにその値を返す |
12282 | 12737 | ブロックを使う必要があります; この場合 LIST は省略できません: |
12283 | 12738 | |
12284 | 12739 | print { $files[$i] } "stuff\n"; |
12285 | 12740 | print { $OK ? *STDOUT : *STDERR } "stuff\n"; |
12286 | 12741 | |
12287 | 12742 | =begin original |
12288 | 12743 | |
12289 | 12744 | Printing to a closed pipe or socket will generate a SIGPIPE signal. See |
12290 | 12745 | L<perlipc> for more on signal handling. |
12291 | 12746 | |
12292 | 12747 | =end original |
12293 | 12748 | |
12294 | 12749 | 閉じたパイプやソケットに print すると SIGPIPE シグナルが生成されます。 |
12295 | 12750 | さらなるシグナル操作については L<perlipc> を参照してください。 |
12296 | 12751 | |
12297 | 12752 | =item printf FILEHANDLE FORMAT, LIST |
12298 | 12753 | X<printf> |
12299 | 12754 | |
12300 | 12755 | =item printf FILEHANDLE |
12301 | 12756 | |
12302 | 12757 | =item printf FORMAT, LIST |
12303 | 12758 | |
12304 | 12759 | =item printf |
12305 | 12760 | |
12306 | 12761 | =for Pod::Functions output a formatted list to a filehandle |
12307 | 12762 | |
12308 | 12763 | =begin original |
12309 | 12764 | |
12310 | 12765 | Equivalent to C<print FILEHANDLE sprintf(FORMAT, LIST)>, except that |
12311 | 12766 | L<C<$\>|perlvar/$\> (the output record separator) is not appended. The |
12312 | 12767 | FORMAT and the LIST are actually parsed as a single list. The first |
12313 | 12768 | argument of the list will be interpreted as the |
12314 | 12769 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST> format. This means that |
12315 | 12770 | C<printf(@_)> will use C<$_[0]> as the format. See |
12316 | 12771 | L<sprintf|/sprintf FORMAT, LIST> for an explanation of the format |
12317 | 12772 | argument. If C<use locale> (including C<use locale ':not_characters'>) |
12318 | 12773 | is in effect and L<C<POSIX::setlocale>|POSIX/C<setlocale>> has been |
12319 | 12774 | called, the character used for the decimal separator in formatted |
12320 | 12775 | floating-point numbers is affected by the C<LC_NUMERIC> locale setting. |
12321 | 12776 | See L<perllocale> and L<POSIX>. |
12322 | 12777 | |
12323 | 12778 | =end original |
12324 | 12779 | |
12325 | 12780 | L<C<$\>|perlvar/$\>(出力レコードセパレータ)を追加しないことを除けば、 |
12326 | 12781 | C<print FILEHANDLE sprintf(FORMAT, LIST)> と等価です。 |
12327 | 12782 | FORMAT と LIST は実際には単一のリストとしてパースされます。 |
12328 | 12783 | リストの最初の要素は、L<C<printf>|/printf FILEHANDLE FORMAT, LIST> |
12329 | 12784 | フォーマットと解釈されます。 |
12330 | 12785 | これは、C<printf(@_)> はフォーマットとして C<$_[0]> を使うということです。 |
12331 | 12786 | フォーマット引数の説明については L<sprintf|/sprintf FORMAT, LIST> を |
12332 | 12787 | 参照してください。 |
12333 | 12788 | (C<use locale ':not_characters'> を含む) C<use locale> が有効で、 |
12334 | 12789 | L<C<POSIX::setlocale>|POSIX/C<setlocale>> が呼び出されていれば、 |
12335 | 12790 | 小数点に使われる文字は C<LC_NUMERIC> ロケール設定の影響を受けます。 |
12336 | 12791 | L<perllocale> と L<POSIX> を参照してください。 |
12337 | 12792 | |
12338 | 12793 | =begin original |
12339 | 12794 | |
12340 | 12795 | For historical reasons, if you omit the list, L<C<$_>|perlvar/$_> is |
12341 | 12796 | used as the format; |
12342 | 12797 | to use FILEHANDLE without a list, you must use a bareword filehandle like |
12343 | 12798 | C<FH>, not an indirect one like C<$fh>. However, this will rarely do what |
12344 | 12799 | you want; if L<C<$_>|perlvar/$_> contains formatting codes, they will be |
12345 | 12800 | replaced with the empty string and a warning will be emitted if |
12346 | 12801 | L<warnings> are enabled. Just use L<C<print>|/print FILEHANDLE LIST> if |
12347 | 12802 | you want to print the contents of L<C<$_>|perlvar/$_>. |
12348 | 12803 | |
12349 | 12804 | =end original |
12350 | 12805 | |
12351 | 12806 | 歴史的な理由により、リストを省略すると、フォーマットとして |
12352 | 12807 | L<C<$_>|perlvar/$_> が使われます; |
12353 | 12808 | リストなしで FILEHANDLE を使用するには、C<$fh> のような |
12354 | 12809 | 間接ファイルハンドルではなく、C<FH> のような裸の単語の |
12355 | 12810 | ファイルハンドルを使わなければなりません。 |
12356 | 12811 | しかし、これがあなたが求めていることをすることはまれです; |
12357 | 12812 | L<C<$_>|perlvar/$_> がフォーマッティングコードの場合、空文字列に置き換えられ、 |
12358 | 12813 | L<warnings> が有効なら警告が出力されます。 |
12359 | 12814 | L<C<$_>|perlvar/$_> の内容を表示したい場合は、単に |
12360 | 12815 | L<C<print>|/print FILEHANDLE LIST> を使ってください。 |
12361 | 12816 | |
12362 | 12817 | =begin original |
12363 | 12818 | |
12364 | 12819 | Don't fall into the trap of using a |
12365 | 12820 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST> when a simple |
12366 | 12821 | L<C<print>|/print FILEHANDLE LIST> would do. The |
12367 | 12822 | L<C<print>|/print FILEHANDLE LIST> is more efficient and less error |
12368 | 12823 | prone. |
12369 | 12824 | |
12370 | 12825 | =end original |
12371 | 12826 | |
12372 | 12827 | 単純な L<C<print>|/print FILEHANDLE LIST> を使うべきところで |
12373 | 12828 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST> を使ってしまう |
12374 | 12829 | 罠にかからないようにしてください。 |
12375 | 12830 | L<C<print>|/print FILEHANDLE LIST> はより効率的で、間違いが起こりにくいです。 |
12376 | 12831 | |
12377 | 12832 | =item prototype FUNCTION |
12378 | 12833 | X<prototype> |
12379 | 12834 | |
12380 | 12835 | =item prototype |
12381 | 12836 | |
12382 | 12837 | =for Pod::Functions +5.002 get the prototype (if any) of a subroutine |
12383 | 12838 | |
12384 | 12839 | =begin original |
12385 | 12840 | |
12386 | 12841 | Returns the prototype of a function as a string (or |
12387 | 12842 | L<C<undef>|/undef EXPR> if the |
12388 | 12843 | function has no prototype). FUNCTION is a reference to, or the name of, |
12389 | 12844 | the function whose prototype you want to retrieve. If FUNCTION is omitted, |
12390 | 12845 | L<C<$_>|perlvar/$_> is used. |
12391 | 12846 | |
12392 | 12847 | =end original |
12393 | 12848 | |
12394 | 12849 | 関数のプロトタイプを文字列として返します(関数にプロトタイプがない場合は |
12395 | 12850 | L<C<undef>|/undef EXPR> を返します)。 |
12396 | 12851 | FUNCTION はプロトタイプを得たい関数の名前、またはリファレンスです。 |
12397 | 12852 | FUNCTION が省略された場合、L<C<$_>|perlvar/$_> が使われます。 |
12398 | 12853 | |
12399 | 12854 | =begin original |
12400 | 12855 | |
12401 | 12856 | If FUNCTION is a string starting with C<CORE::>, the rest is taken as a |
12402 | 12857 | name for a Perl builtin. If the builtin's arguments |
12403 | 12858 | cannot be adequately expressed by a prototype |
12404 | 12859 | (such as L<C<system>|/system LIST>), L<C<prototype>|/prototype FUNCTION> |
12405 | 12860 | returns L<C<undef>|/undef EXPR>, because the builtin |
12406 | 12861 | does not really behave like a Perl function. Otherwise, the string |
12407 | 12862 | describing the equivalent prototype is returned. |
12408 | 12863 | |
12409 | 12864 | =end original |
12410 | 12865 | |
12411 | 12866 | FUNCTION が C<CORE::> で始まっている場合、残りは Perl ビルドインの名前として |
12412 | 12867 | 扱われます。 |
12413 | 12868 | このビルドインの引数が(L<C<system>|/system LIST> のように)プロトタイプとして |
12414 | 12869 | 適切に記述できない場合、L<C<prototype>|/prototype FUNCTION> は |
12415 | 12870 | L<C<undef>|/undef EXPR> を返します; |
12416 | 12871 | なぜならビルドインは実際に Perl 関数のように振舞わないからです。 |
12417 | 12872 | それ以外では、等価なプロトタイプを表現した文字列が返されます。 |
12418 | 12873 | |
12419 | 12874 | =item push ARRAY,LIST |
12420 | 12875 | X<push> X<stack> |
12421 | 12876 | |
12422 | 12877 | =for Pod::Functions append one or more elements to an array |
12423 | 12878 | |
12424 | 12879 | =begin original |
12425 | 12880 | |
12426 | 12881 | Treats ARRAY as a stack by appending the values of LIST to the end of |
12427 | 12882 | ARRAY. The length of ARRAY increases by the length of LIST. Has the same |
12428 | 12883 | effect as |
12429 | 12884 | |
12430 | 12885 | =end original |
12431 | 12886 | |
12432 | 12887 | ARRAY をスタックとして扱い、LIST 内の値を ARRAY の終わりに追加します。 |
12433 | 12888 | ARRAY の大きさは、LIST の長さ分だけ大きくなります。 |
12434 | 12889 | これは、 |
12435 | 12890 | |
12436 | 12891 | for my $value (LIST) { |
12437 | 12892 | $ARRAY[++$#ARRAY] = $value; |
12438 | 12893 | } |
12439 | 12894 | |
12440 | 12895 | =begin original |
12441 | 12896 | |
12442 | 12897 | but is more efficient. Returns the number of elements in the array following |
12443 | 12898 | the completed L<C<push>|/push ARRAY,LIST>. |
12444 | 12899 | |
12445 | 12900 | =end original |
12446 | 12901 | |
12447 | 12902 | とするのと同じ効果がありますが、より効率的です。 |
12448 | 12903 | L<C<push>|/push ARRAY,LIST> の処理終了後の配列の要素数を返します。 |
12449 | 12904 | |
12450 | 12905 | =begin original |
12451 | 12906 | |
12452 | 12907 | Starting with Perl 5.14, an experimental feature allowed |
12453 | 12908 | L<C<push>|/push ARRAY,LIST> to take a |
12454 | 12909 | scalar expression. This experiment has been deemed unsuccessful, and was |
12455 | 12910 | removed as of Perl 5.24. |
12456 | 12911 | |
12457 | 12912 | =end original |
12458 | 12913 | |
12459 | 12914 | Perl 5.14 から、L<C<push>|/push ARRAY,LIST> がスカラ式を取ることが出来るという |
12460 | 12915 | 実験的機能がありました。 |
12461 | 12916 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 |
12462 | 12917 | |
12463 | 12918 | =item q/STRING/ |
12464 | 12919 | |
12465 | 12920 | =for Pod::Functions singly quote a string |
12466 | 12921 | |
12467 | 12922 | =item qq/STRING/ |
12468 | 12923 | |
12469 | 12924 | =for Pod::Functions doubly quote a string |
12470 | 12925 | |
12471 | 12926 | =item qw/STRING/ |
12472 | 12927 | |
12473 | 12928 | =for Pod::Functions quote a list of words |
12474 | 12929 | |
12475 | 12930 | =item qx/STRING/ |
12476 | 12931 | |
12477 | 12932 | =for Pod::Functions backquote quote a string |
12478 | 12933 | |
12479 | 12934 | =begin original |
12480 | 12935 | |
12481 | 12936 | Generalized quotes. See L<perlop/"Quote-Like Operators">. |
12482 | 12937 | |
12483 | 12938 | =end original |
12484 | 12939 | |
12485 | 12940 | 汎用のクォートです。 |
12486 | 12941 | L<perlop/"Quote-Like Operators"> を参照してください。 |
12487 | 12942 | |
12488 | 12943 | =item qr/STRING/ |
12489 | 12944 | |
12490 | 12945 | =for Pod::Functions +5.005 compile pattern |
12491 | 12946 | |
12492 | 12947 | =begin original |
12493 | 12948 | |
12494 | 12949 | Regexp-like quote. See L<perlop/"Regexp Quote-Like Operators">. |
12495 | 12950 | |
12496 | 12951 | =end original |
12497 | 12952 | |
12498 | 12953 | 正規表現風のクォートです。 |
12499 | 12954 | L<perlop/"Regexp Quote-Like Operators"> を参照してください。 |
12500 | 12955 | |
12501 | 12956 | =item quotemeta EXPR |
12502 | 12957 | X<quotemeta> X<metacharacter> |
12503 | 12958 | |
12504 | 12959 | =item quotemeta |
12505 | 12960 | |
12506 | 12961 | =for Pod::Functions quote regular expression magic characters |
12507 | 12962 | |
12508 | 12963 | =begin original |
12509 | 12964 | |
12510 | 12965 | Returns the value of EXPR with all the ASCII non-"word" |
12511 | 12966 | characters backslashed. (That is, all ASCII characters not matching |
12512 | 12967 | C</[A-Za-z_0-9]/> will be preceded by a backslash in the |
12513 | 12968 | returned string, regardless of any locale settings.) |
12514 | 12969 | This is the internal function implementing |
12515 | 12970 | the C<\Q> escape in double-quoted strings. |
12516 | 12971 | (See below for the behavior on non-ASCII code points.) |
12517 | 12972 | |
12518 | 12973 | =end original |
12519 | 12974 | |
12520 | 12975 | EXPR の中のすべての ASCII 非英数字キャラクタをバックスラッシュで |
12521 | 12976 | エスケープしたものを返します。 |
12522 | 12977 | (つまり、C</[A-Za-z_0-9]/> にマッチしない全ての ASCII 文字の前には |
12523 | 12978 | ロケールに関わらずバックスラッシュが前置されます。) |
12524 | 12979 | これは、ダブルクォート文字列での C<\Q> エスケープを実装するための |
12525 | 12980 | 内部関数です。 |
12526 | 12981 | (非 ASCII 符号位置での振る舞いについては以下を参照してください。) |
12527 | 12982 | |
12528 | 12983 | =begin original |
12529 | 12984 | |
12530 | 12985 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. |
12531 | 12986 | |
12532 | 12987 | =end original |
12533 | 12988 | |
12534 | 12989 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 |
12535 | 12990 | |
12536 | 12991 | =begin original |
12537 | 12992 | |
12538 | 12993 | quotemeta (and C<\Q> ... C<\E>) are useful when interpolating strings into |
12539 | 12994 | regular expressions, because by default an interpolated variable will be |
12540 | 12995 | considered a mini-regular expression. For example: |
12541 | 12996 | |
12542 | 12997 | =end original |
12543 | 12998 | |
12544 | 12999 | クォートメタ (と C<\Q> ... C<\E>) は、文字列を正規表現に展開するのに |
12545 | 13000 | 便利です; なぜなら、デフォルトでは展開された変数は小さな正規表現として |
12546 | 13001 | 扱われるからです。 |
12547 | 13002 | 例えば: |
12548 | 13003 | |
12549 | 13004 | my $sentence = 'The quick brown fox jumped over the lazy dog'; |
12550 | 13005 | my $substring = 'quick.*?fox'; |
12551 | 13006 | $sentence =~ s{$substring}{big bad wolf}; |
12552 | 13007 | |
12553 | 13008 | =begin original |
12554 | 13009 | |
12555 | 13010 | Will cause C<$sentence> to become C<'The big bad wolf jumped over...'>. |
12556 | 13011 | |
12557 | 13012 | =end original |
12558 | 13013 | |
12559 | 13014 | とすると、C<$sentence> は C<'The big bad wolf jumped over...'> になります。 |
12560 | 13015 | |
12561 | 13016 | =begin original |
12562 | 13017 | |
12563 | 13018 | On the other hand: |
12564 | 13019 | |
12565 | 13020 | =end original |
12566 | 13021 | |
12567 | 13022 | 一方: |
12568 | 13023 | |
12569 | 13024 | my $sentence = 'The quick brown fox jumped over the lazy dog'; |
12570 | 13025 | my $substring = 'quick.*?fox'; |
12571 | 13026 | $sentence =~ s{\Q$substring\E}{big bad wolf}; |
12572 | 13027 | |
12573 | 13028 | =begin original |
12574 | 13029 | |
12575 | 13030 | Or: |
12576 | 13031 | |
12577 | 13032 | =end original |
12578 | 13033 | |
12579 | 13034 | あるいは: |
12580 | 13035 | |
12581 | 13036 | my $sentence = 'The quick brown fox jumped over the lazy dog'; |
12582 | 13037 | my $substring = 'quick.*?fox'; |
12583 | 13038 | my $quoted_substring = quotemeta($substring); |
12584 | 13039 | $sentence =~ s{$quoted_substring}{big bad wolf}; |
12585 | 13040 | |
12586 | 13041 | =begin original |
12587 | 13042 | |
12588 | 13043 | Will both leave the sentence as is. |
12589 | 13044 | Normally, when accepting literal string input from the user, |
12590 | 13045 | L<C<quotemeta>|/quotemeta EXPR> or C<\Q> must be used. |
12591 | 13046 | |
12592 | 13047 | =end original |
12593 | 13048 | |
12594 | 13049 | とすると、両方ともそのままです。 |
12595 | 13050 | 普通は、ユーザーからのリテラルな文字列入力を受け付ける場合は、 |
12596 | 13051 | 必ず L<C<quotemeta>|/quotemeta EXPR> か C<\Q> を使わなければなりません。 |
12597 | 13052 | |
12598 | 13053 | =begin original |
12599 | 13054 | |
12600 | 13055 | In Perl v5.14, all non-ASCII characters are quoted in non-UTF-8-encoded |
12601 | 13056 | strings, but not quoted in UTF-8 strings. |
12602 | 13057 | |
12603 | 13058 | =end original |
12604 | 13059 | |
12605 | 13060 | Perl v5.14 では、全ての非 ASCII 文字は非 UTF-8 エンコードされた |
12606 | 13061 | 文字列ではクォートされませんが、UTF-8 文字列ではクォートされます。 |
12607 | 13062 | |
12608 | 13063 | =begin original |
12609 | 13064 | |
12610 | 13065 | Starting in Perl v5.16, Perl adopted a Unicode-defined strategy for |
12611 | 13066 | quoting non-ASCII characters; the quoting of ASCII characters is |
12612 | 13067 | unchanged. |
12613 | 13068 | |
12614 | 13069 | =end original |
12615 | 13070 | |
12616 | 13071 | Perl v5.16 から、Perl は非 ASCII 文字をクォートするのに Unicode で |
12617 | 13072 | 定義された戦略を採用しました; ASCII 文字のクォートは変わりません。 |
12618 | 13073 | |
12619 | 13074 | =begin original |
12620 | 13075 | |
12621 | 13076 | Also unchanged is the quoting of non-UTF-8 strings when outside the |
12622 | 13077 | scope of a |
12623 | 13078 | L<C<use feature 'unicode_strings'>|feature/The 'unicode_strings' feature>, |
12624 | 13079 | which is to quote all |
12625 | 13080 | characters in the upper Latin1 range. This provides complete backwards |
12626 | 13081 | compatibility for old programs which do not use Unicode. (Note that |
12627 | 13082 | C<unicode_strings> is automatically enabled within the scope of a |
12628 | 13083 | S<C<use v5.12>> or greater.) |
12629 | 13084 | |
12630 | 13085 | =end original |
12631 | 13086 | |
12632 | 13087 | また、 |
12633 | 13088 | L<C<use feature 'unicode_strings'>|feature/The 'unicode_strings' feature> の |
12634 | 13089 | 範囲外で非 UTF-8 文字列をクォートするのも変わりません; 上位の Latin1 の範囲の |
12635 | 13090 | 全ての文字をクォートします。 |
12636 | 13091 | これは Unicode を使わない古いプログラムに対して完全な後方互換性を提供します。 |
12637 | 13092 | (C<unicode_strings> は S<C<use v5.12>> またはそれ以上のスコープでは |
12638 | 13093 | 自動的に有効になることに注意してください。) |
12639 | 13094 | |
12640 | 13095 | =begin original |
12641 | 13096 | |
12642 | 13097 | Within the scope of L<C<use locale>|locale>, all non-ASCII Latin1 code |
12643 | 13098 | points |
12644 | 13099 | are quoted whether the string is encoded as UTF-8 or not. As mentioned |
12645 | 13100 | above, locale does not affect the quoting of ASCII-range characters. |
12646 | 13101 | This protects against those locales where characters such as C<"|"> are |
12647 | 13102 | considered to be word characters. |
12648 | 13103 | |
12649 | 13104 | =end original |
12650 | 13105 | |
12651 | 13106 | L<C<use locale>|locale> スコープの内側では、全ての非 ASCII Latin1 符号位置は |
12652 | 13107 | 文字列が UTF-8 でエンコードされているかどうかに関わらずクォートされます。 |
12653 | 13108 | 上述のように、ロケールは ASCII の範囲の文字のクォートに影響を与えません。 |
12654 | 13109 | これは C<"|"> のような文字が単語文字として考えられるロケールから守ります。 |
12655 | 13110 | |
12656 | 13111 | =begin original |
12657 | 13112 | |
12658 | 13113 | Otherwise, Perl quotes non-ASCII characters using an adaptation from |
12659 | Unicode (see L<http://www.unicode.org/reports/tr31/>). | |
13114 | Unicode (see L<https://www.unicode.org/reports/tr31/>). | |
12660 | 13115 | The only code points that are quoted are those that have any of the |
12661 | 13116 | Unicode properties: Pattern_Syntax, Pattern_White_Space, White_Space, |
12662 | 13117 | Default_Ignorable_Code_Point, or General_Category=Control. |
12663 | 13118 | |
12664 | 13119 | =end original |
12665 | 13120 | |
12666 | 13121 | さもなければ、Perl は Unicode からの本版を使って非 ASCII 文字をクォートします |
12667 | (L<http://www.unicode.org/reports/tr31/> 参照)。 | |
13122 | (L<https://www.unicode.org/reports/tr31/> 参照)。 | |
12668 | 13123 | クォートされる符号位置は以下のどれかの Unicode を特性を持つものだけです: |
12669 | 13124 | Pattern_Syntax, Pattern_White_Space, White_Space, |
12670 | 13125 | Default_Ignorable_Code_Point, or General_Category=Control。 |
12671 | 13126 | |
12672 | 13127 | =begin original |
12673 | 13128 | |
12674 | 13129 | Of these properties, the two important ones are Pattern_Syntax and |
12675 | 13130 | Pattern_White_Space. They have been set up by Unicode for exactly this |
12676 | 13131 | purpose of deciding which characters in a regular expression pattern |
12677 | 13132 | should be quoted. No character that can be in an identifier has these |
12678 | 13133 | properties. |
12679 | 13134 | |
12680 | 13135 | =end original |
12681 | 13136 | |
12682 | 13137 | これらの特性の中で、重要な二つは Pattern_Syntax と Pattern_White_Space です。 |
12683 | 13138 | これらはまさに正規表現中パターン中のどの文字をクォートするべきかを |
12684 | 13139 | 決定するという目的のために Unicode によって設定されています。 |
12685 | 13140 | 識別子になる文字はこれらの特性はありません。 |
12686 | 13141 | |
12687 | 13142 | =begin original |
12688 | 13143 | |
12689 | 13144 | Perl promises, that if we ever add regular expression pattern |
12690 | 13145 | metacharacters to the dozen already defined |
12691 | 13146 | (C<\ E<verbar> ( ) [ { ^ $ * + ? .>), that we will only use ones that have the |
12692 | 13147 | Pattern_Syntax property. Perl also promises, that if we ever add |
12693 | 13148 | characters that are considered to be white space in regular expressions |
12694 | 13149 | (currently mostly affected by C</x>), they will all have the |
12695 | 13150 | Pattern_White_Space property. |
12696 | 13151 | |
12697 | 13152 | =end original |
12698 | 13153 | |
12699 | 13154 | Perl は、正規表現メタ文字として既に定義されている |
12700 | 13155 | (C<\ E<verbar> ( ) [ { ^ $ * + ? .>) ものに追加するときは、 |
12701 | 13156 | Pattern_Syntax 特性を持つものだけを使うことを約束します。 |
12702 | 13157 | Perl はまた、(現在の所ほとんどは C</x> よって影響される)正規表現中で空白と |
12703 | 13158 | 考えられる文字に追加するときは、Pattern_White_Space 特性を |
12704 | 13159 | 持つものであることを約束します。 |
12705 | 13160 | |
12706 | 13161 | =begin original |
12707 | 13162 | |
12708 | 13163 | Unicode promises that the set of code points that have these two |
12709 | 13164 | properties will never change, so something that is not quoted in v5.16 |
12710 | 13165 | will never need to be quoted in any future Perl release. (Not all the |
12711 | 13166 | code points that match Pattern_Syntax have actually had characters |
12712 | 13167 | assigned to them; so there is room to grow, but they are quoted |
12713 | 13168 | whether assigned or not. Perl, of course, would never use an |
12714 | 13169 | unassigned code point as an actual metacharacter.) |
12715 | 13170 | |
12716 | 13171 | =end original |
12717 | 13172 | |
12718 | 13173 | Unicode はこれら二つの特性を持つ符号位置の集合が決して変わらないことを |
12719 | 13174 | 約束しているので、v5.16 でクォートされないものは将来の Perl リリースでも |
12720 | 13175 | クォートする必要はありません。 |
12721 | 13176 | (Pattern_Syntax にマッチングする全ての符号位置が実際に割り当てられている |
12722 | 13177 | 文字を持っているわけではありません; したがって拡張する余地がありますが、 |
12723 | 13178 | 割り当てられているかどうかに関わらずクォートされます。 |
12724 | 13179 | Perl はもちろん割り当てられていない符号位置を実際のメタ文字として使うことは |
12725 | 13180 | ありません。) |
12726 | 13181 | |
12727 | 13182 | =begin original |
12728 | 13183 | |
12729 | 13184 | Quoting characters that have the other 3 properties is done to enhance |
12730 | 13185 | the readability of the regular expression and not because they actually |
12731 | 13186 | need to be quoted for regular expression purposes (characters with the |
12732 | 13187 | White_Space property are likely to be indistinguishable on the page or |
12733 | 13188 | screen from those with the Pattern_White_Space property; and the other |
12734 | 13189 | two properties contain non-printing characters). |
12735 | 13190 | |
12736 | 13191 | =end original |
12737 | 13192 | |
12738 | 13193 | その他の 3 特性を持つ文字のクォートは正規表現の可読性を向上させるために |
12739 | 13194 | 行われ、実際には正規表現の目的でクォートする必要があるからではありません |
12740 | 13195 | (White_Space 特性を持つ文字は表示上は Pattern_White_Space 特性を持つ文字と |
12741 | 13196 | おそらく区別が付かないでしょう; そして残りの |
12742 | 13197 | 二つの特性は非表示文字を含んでいます). |
12743 | 13198 | |
12744 | 13199 | =item rand EXPR |
12745 | 13200 | X<rand> X<random> |
12746 | 13201 | |
12747 | 13202 | =item rand |
12748 | 13203 | |
12749 | 13204 | =for Pod::Functions retrieve the next pseudorandom number |
12750 | 13205 | |
12751 | 13206 | =begin original |
12752 | 13207 | |
12753 | 13208 | Returns a random fractional number greater than or equal to C<0> and less |
12754 | 13209 | than the value of EXPR. (EXPR should be positive.) If EXPR is |
12755 | 13210 | omitted, the value C<1> is used. Currently EXPR with the value C<0> is |
12756 | 13211 | also special-cased as C<1> (this was undocumented before Perl 5.8.0 |
12757 | 13212 | and is subject to change in future versions of Perl). Automatically calls |
12758 | 13213 | L<C<srand>|/srand EXPR> unless L<C<srand>|/srand EXPR> has already been |
12759 | 13214 | called. See also L<C<srand>|/srand EXPR>. |
12760 | 13215 | |
12761 | 13216 | =end original |
12762 | 13217 | |
12763 | 13218 | C<0> 以上 EXPR の値未満の小数の乱数値を返します。 |
12764 | 13219 | (EXPR は正の数である必要があります。) |
12765 | 13220 | EXPR が省略されると、C<1> が使われます。 |
12766 | 13221 | 現在のところ、EXPR に値 C<0> をセットすると C<1> として特別扱いされます |
12767 | 13222 | (これは Perl 5.8.0 以前には文書化されておらず、将来のバージョンの perl では |
12768 | 13223 | 変更される可能性があります)。 |
12769 | 13224 | L<C<srand>|/srand EXPR> が既に呼ばれている場合以外は、自動的に |
12770 | 13225 | L<C<srand>|/srand EXPR> 関数を呼び出します。 |
12771 | 13226 | L<C<srand>|/srand EXPR> も参照してください。 |
12772 | 13227 | |
12773 | 13228 | =begin original |
12774 | 13229 | |
12775 | 13230 | Apply L<C<int>|/int EXPR> to the value returned by L<C<rand>|/rand EXPR> |
12776 | 13231 | if you want random integers instead of random fractional numbers. For |
12777 | 13232 | example, |
12778 | 13233 | |
12779 | 13234 | =end original |
12780 | 13235 | |
12781 | 13236 | ランダムな小数ではなく、ランダムな整数がほしい場合は、 |
12782 | 13237 | L<C<rand>|/rand EXPR> から返された値に L<C<int>|/int EXPR> を |
12783 | 13238 | 適用してください。 |
12784 | 13239 | 例えば: |
12785 | 13240 | |
12786 | 13241 | int(rand(10)) |
12787 | 13242 | |
12788 | 13243 | =begin original |
12789 | 13244 | |
12790 | 13245 | returns a random integer between C<0> and C<9>, inclusive. |
12791 | 13246 | |
12792 | 13247 | =end original |
12793 | 13248 | |
12794 | 13249 | これは C<0> から C<9> の値をランダムに返します。 |
12795 | 13250 | |
12796 | 13251 | =begin original |
12797 | 13252 | |
12798 | 13253 | (Note: If your rand function consistently returns numbers that are too |
12799 | 13254 | large or too small, then your version of Perl was probably compiled |
12800 | 13255 | with the wrong number of RANDBITS.) |
12801 | 13256 | |
12802 | 13257 | =end original |
12803 | 13258 | |
12804 | 13259 | (注: もし、rand 関数が、常に大きい値ばかりや、小さい数ばかりを |
12805 | 13260 | 返すようなら、お使いになっている Perl が、 |
12806 | 13261 | 良くない RANDBITS を使ってコンパイルされている可能性があります。) |
12807 | 13262 | |
12808 | 13263 | =begin original |
12809 | 13264 | |
12810 | 13265 | B<L<C<rand>|/rand EXPR> is not cryptographically secure. You should not rely |
12811 | 13266 | on it in security-sensitive situations.> As of this writing, a |
12812 | 13267 | number of third-party CPAN modules offer random number generators |
12813 | 13268 | intended by their authors to be cryptographically secure, |
12814 | 13269 | including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>, |
12815 | 13270 | and L<Math::TrulyRandom>. |
12816 | 13271 | |
12817 | 13272 | =end original |
12818 | 13273 | |
12819 | 13274 | B<L<C<rand>|/rand EXPR> は暗号学的に安全ではありません。 |
12820 | 13275 | セキュリティ的に重要な状況でこれに頼るべきではありません。> |
12821 | 13276 | これを書いている時点で、いくつかのサードパーティ CPAN モジュールが |
12822 | 13277 | 作者によって暗号学的に安全であることを目的とした乱数生成器を |
12823 | 13278 | 提供しています: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>, |
12824 | 13279 | L<Math::TrulyRandom> などです。 |
12825 | 13280 | |
12826 | 13281 | =item read FILEHANDLE,SCALAR,LENGTH,OFFSET |
12827 | 13282 | X<read> X<file, read> |
12828 | 13283 | |
12829 | 13284 | =item read FILEHANDLE,SCALAR,LENGTH |
12830 | 13285 | |
12831 | 13286 | =for Pod::Functions fixed-length buffered input from a filehandle |
12832 | 13287 | |
12833 | 13288 | =begin original |
12834 | 13289 | |
12835 | 13290 | Attempts to read LENGTH I<characters> of data into variable SCALAR |
12836 | 13291 | from the specified FILEHANDLE. Returns the number of characters |
12837 | 13292 | actually read, C<0> at end of file, or undef if there was an error (in |
12838 | 13293 | the latter case L<C<$!>|perlvar/$!> is also set). SCALAR will be grown |
12839 | 13294 | or shrunk |
12840 | 13295 | so that the last character actually read is the last character of the |
12841 | 13296 | scalar after the read. |
12842 | 13297 | |
12843 | 13298 | =end original |
12844 | 13299 | |
12845 | 13300 | 指定した FILEHANDLE から、変数 SCALAR に LENGTH I<文字> のデータを |
12846 | 13301 | 読み込みます。 |
12847 | 13302 | 実際に読み込まれた文字数、ファイル終端の場合は C<0>、エラーの場合は undef の |
12848 | 13303 | いずれかを返します (後者の場合、L<C<$!>|perlvar/$!> もセットされます)。 |
12849 | 13304 | SCALAR は伸び縮みするので、読み込み後は、実際に読み込んだ最後の文字がスカラの |
12850 | 13305 | 最後の文字になります。 |
12851 | 13306 | |
12852 | 13307 | =begin original |
12853 | 13308 | |
12854 | 13309 | An OFFSET may be specified to place the read data at some place in the |
12855 | 13310 | string other than the beginning. A negative OFFSET specifies |
12856 | 13311 | placement at that many characters counting backwards from the end of |
12857 | 13312 | the string. A positive OFFSET greater than the length of SCALAR |
12858 | 13313 | results in the string being padded to the required size with C<"\0"> |
12859 | 13314 | bytes before the result of the read is appended. |
12860 | 13315 | |
12861 | 13316 | =end original |
12862 | 13317 | |
12863 | 13318 | OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行なえます。 |
12864 | 13319 | OFFSET に負の値を指定すると、文字列の最後から逆向きに何文字目かで |
12865 | 13320 | 位置を指定します。 |
12866 | 13321 | OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は読み込みの結果が |
12867 | 13322 | 追加される前に、必要なサイズまで C<"\0"> のバイトでパッディングされます。 |
12868 | 13323 | |
12869 | 13324 | =begin original |
12870 | 13325 | |
12871 | 13326 | The call is implemented in terms of either Perl's or your system's native |
12872 | L<fread(3)> library function | |
13327 | L<fread(3)> library function, via the L<PerlIO> layers applied to the | |
13328 | handle. To get a true L<read(2)> system call, see | |
12873 | 13329 | L<sysread|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>. |
12874 | 13330 | |
12875 | 13331 | =end original |
12876 | 13332 | |
12877 | この関数は、Perl か システムの L<fread(3)> ライブラリ関数を使って | |
13333 | この関数は、Perl か システムの L<fread(3)> ライブラリ関数を使って、 | |
12878 | 実装 | |
13334 | ハンドルに適用されている L<PerlIO> 層経由で実装されています。 | |
12879 | 13335 | 本当の L<read(2)> システムコールを利用するには、 |
12880 | 13336 | L<sysread|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を参照してください。 |
12881 | 13337 | |
12882 | 13338 | =begin original |
12883 | 13339 | |
12884 | 13340 | Note the I<characters>: depending on the status of the filehandle, |
12885 | 13341 | either (8-bit) bytes or characters are read. By default, all |
12886 | 13342 | filehandles operate on bytes, but for example if the filehandle has |
12887 | 13343 | been opened with the C<:utf8> I/O layer (see |
12888 | L<C<open>|/open FILEHANDLE,EXPR>, and the L<open> | |
13344 | L<C<open>|/open FILEHANDLE,MODE,EXPR>, and the L<open> | |
12889 | 13345 | pragma), the I/O will operate on UTF8-encoded Unicode |
12890 | 13346 | characters, not bytes. Similarly for the C<:encoding> layer: |
12891 | 13347 | in that case pretty much any characters can be read. |
12892 | 13348 | |
12893 | 13349 | =end original |
12894 | 13350 | |
12895 | 13351 | I<文字> に関する注意: ファイルハンドルの状態によって、(8 ビットの) バイトか |
12896 | 13352 | 文字が読み込まれます。 |
12897 | 13353 | デフォルトでは全てのファイルハンドルはバイトを処理しますが、 |
12898 | 例えばファイルハンドルが C<:utf8> I/O 層 | |
13354 | 例えばファイルハンドルが C<:utf8> I/O 層 | |
12899 | L<open> プラグマを参照してください) で | |
13355 | (L<C<open>|/open FILEHANDLE,MODE,EXPR>, L<open> プラグマを参照してください) で | |
13356 | 開かれた場合、I/O はバイトではなく、 | |
12900 | 13357 | UTF8 エンコードされた Unicode 文字を操作します。 |
12901 | 13358 | C<:encoding> 層も同様です: |
12902 | 13359 | この場合、ほとんど大体全ての文字が読み込めます。 |
12903 | 13360 | |
12904 | 13361 | =item readdir DIRHANDLE |
12905 | 13362 | X<readdir> |
12906 | 13363 | |
12907 | 13364 | =for Pod::Functions get a directory from a directory handle |
12908 | 13365 | |
12909 | 13366 | =begin original |
12910 | 13367 | |
12911 | 13368 | Returns the next directory entry for a directory opened by |
12912 | 13369 | L<C<opendir>|/opendir DIRHANDLE,EXPR>. |
12913 | 13370 | If used in list context, returns all the rest of the entries in the |
12914 | 13371 | directory. If there are no more entries, returns the undefined value in |
12915 | 13372 | scalar context and the empty list in list context. |
12916 | 13373 | |
12917 | 13374 | =end original |
12918 | 13375 | |
12919 | 13376 | L<C<opendir>|/opendir DIRHANDLE,EXPR> でオープンしたディレクトリで、次の |
12920 | 13377 | ディレクトリエントリを返します。 |
12921 | 13378 | リストコンテキストで用いると、そのディレクトリの残りのエントリを、すべて |
12922 | 13379 | 返します。 |
12923 | 13380 | エントリが残っていない場合には、スカラコンテキストでは未定義値を、 |
12924 | 13381 | リストコンテキストでは空リストを返します。 |
12925 | 13382 | |
12926 | 13383 | =begin original |
12927 | 13384 | |
12928 | 13385 | If you're planning to filetest the return values out of a |
12929 | 13386 | L<C<readdir>|/readdir DIRHANDLE>, you'd better prepend the directory in |
12930 | 13387 | question. Otherwise, because we didn't L<C<chdir>|/chdir EXPR> there, |
12931 | 13388 | it would have been testing the wrong file. |
12932 | 13389 | |
12933 | 13390 | =end original |
12934 | 13391 | |
12935 | 13392 | L<C<readdir>|/readdir DIRHANDLE> の返り値をファイルテストに使おうと |
12936 | 13393 | 計画しているなら、頭にディレクトリをつける必要があります。 |
12937 | 13394 | さもなければ、ここでは L<C<chdir>|/chdir EXPR> はしないので、 |
12938 | 13395 | 間違ったファイルをテストしてしまうことになるでしょう。 |
12939 | 13396 | |
12940 | 13397 | opendir(my $dh, $some_dir) || die "Can't opendir $some_dir: $!"; |
12941 | 13398 | my @dots = grep { /^\./ && -f "$some_dir/$_" } readdir($dh); |
12942 | 13399 | closedir $dh; |
12943 | 13400 | |
12944 | 13401 | =begin original |
12945 | 13402 | |
12946 | 13403 | As of Perl 5.12 you can use a bare L<C<readdir>|/readdir DIRHANDLE> in a |
12947 | 13404 | C<while> loop, which will set L<C<$_>|perlvar/$_> on every iteration. |
13405 | If either a C<readdir> expression or an explicit assignment of a | |
13406 | C<readdir> expression to a scalar is used as a C<while>/C<for> condition, | |
13407 | then the condition actually tests for definedness of the expression's | |
13408 | value, not for its regular truth value. | |
12948 | 13409 | |
12949 | 13410 | =end original |
12950 | 13411 | |
12951 | 13412 | Perl 5.12 から裸の L<C<readdir>|/readdir DIRHANDLE> を C<while> で |
12952 | 13413 | 使うことができ、この場合繰り返し毎に L<C<$_>|perlvar/$_> にセットされます。 |
13414 | C<readdir> 式または C<readdir> 式からスカラへの明示的な代入が | |
13415 | C<while>/C<for> の条件部として使われた場合、 | |
13416 | 条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを | |
13417 | テストします。 | |
12953 | 13418 | |
12954 | 13419 | opendir(my $dh, $some_dir) || die "Can't open $some_dir: $!"; |
12955 | 13420 | while (readdir $dh) { |
12956 | 13421 | print "$some_dir/$_\n"; |
12957 | 13422 | } |
12958 | 13423 | closedir $dh; |
12959 | 13424 | |
12960 | 13425 | =begin original |
12961 | 13426 | |
12962 | 13427 | To avoid confusing would-be users of your code who are running earlier |
12963 | 13428 | versions of Perl with mysterious failures, put this sort of thing at the |
12964 | 13429 | top of your file to signal that your code will work I<only> on Perls of a |
12965 | 13430 | recent vintage: |
12966 | 13431 | |
12967 | 13432 | =end original |
12968 | 13433 | |
12969 | 13434 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な |
12970 | 13435 | 失敗で混乱することを避けるために、コードが最近のバージョンの Perl で |
12971 | 13436 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを |
12972 | 13437 | 書いてください: |
12973 | 13438 | |
12974 | 13439 | use 5.012; # so readdir assigns to $_ in a lone while test |
12975 | 13440 | |
12976 | 13441 | =item readline EXPR |
12977 | 13442 | |
12978 | 13443 | =item readline |
12979 | 13444 | X<readline> X<gets> X<fgets> |
12980 | 13445 | |
12981 | 13446 | =for Pod::Functions fetch a record from a file |
12982 | 13447 | |
12983 | 13448 | =begin original |
12984 | 13449 | |
12985 | 13450 | Reads from the filehandle whose typeglob is contained in EXPR (or from |
12986 | 13451 | C<*ARGV> if EXPR is not provided). In scalar context, each call reads and |
12987 | 13452 | returns the next line until end-of-file is reached, whereupon the |
12988 | 13453 | subsequent call returns L<C<undef>|/undef EXPR>. In list context, reads |
12989 | 13454 | until end-of-file is reached and returns a list of lines. Note that the |
12990 | 13455 | notion of "line" used here is whatever you may have defined with |
12991 | 13456 | L<C<$E<sol>>|perlvar/$E<sol>> (or C<$INPUT_RECORD_SEPARATOR> in |
12992 | 13457 | L<English>). See L<perlvar/"$/">. |
12993 | 13458 | |
12994 | 13459 | =end original |
12995 | 13460 | |
12996 | 13461 | 型グロブが EXPR (EXPR がない場合は C<*ARGV>) に含まれている |
12997 | 13462 | ファイルハンドルから読み込みます。 |
12998 | 13463 | スカラコンテキストでは、呼び出し毎に一行読み込んで返します; ファイルの |
12999 | 13464 | 最後まで読み込んだら、以後の呼び出しでは L<C<undef>|/undef EXPR> を返します。 |
13000 | 13465 | リストコンテキストでは、ファイルの最後まで読み込んで、行のリストを返します。 |
13001 | 13466 | ここでの「行」とは、L<C<$E<sol>>|perlvar/$E<sol>> (または |
13002 | 13467 | L<English> モジュールでは C<$INPUT_RECORD_SEPARATOR>) で |
13003 | 13468 | 定義されることに注意してください。 |
13004 | 13469 | L<perlvar/"$/"> を参照してください。 |
13005 | 13470 | |
13006 | 13471 | =begin original |
13007 | 13472 | |
13008 | 13473 | When L<C<$E<sol>>|perlvar/$E<sol>> is set to L<C<undef>|/undef EXPR>, |
13009 | 13474 | when L<C<readline>|/readline EXPR> is in scalar context (i.e., file |
13010 | 13475 | slurp mode), and when an empty file is read, it returns C<''> the first |
13011 | 13476 | time, followed by L<C<undef>|/undef EXPR> subsequently. |
13012 | 13477 | |
13013 | 13478 | =end original |
13014 | 13479 | |
13015 | 13480 | L<C<$E<sol>>|perlvar/$E<sol>> に L<C<undef>|/undef EXPR> を設定した場合は、 |
13016 | 13481 | L<C<readline>|/readline EXPR> はスカラコンテキスト (つまりファイル吸い込み |
13017 | 13482 | モード)となり、空のファイルを読み込んだ場合は、最初は C<''> を返し、 |
13018 | 13483 | それ以降は L<C<undef>|/undef EXPR> を返します。 |
13019 | 13484 | |
13020 | 13485 | =begin original |
13021 | 13486 | |
13022 | 13487 | This is the internal function implementing the C<< <EXPR> >> |
13023 | 13488 | operator, but you can use it directly. The C<< <EXPR> >> |
13024 | 13489 | operator is discussed in more detail in L<perlop/"I/O Operators">. |
13025 | 13490 | |
13026 | 13491 | =end original |
13027 | 13492 | |
13028 | 13493 | これは C<< <EXPR> >> 演算子を実装している内部関数ですが、 |
13029 | 13494 | 直接使うこともできます。 |
13030 | 13495 | C<< <EXPR> >> 演算子についてのさらなる詳細については |
13031 | 13496 | L<perlop/"I/O Operators"> で議論されています。 |
13032 | 13497 | |
13033 | 13498 | my $line = <STDIN>; |
13034 | 13499 | my $line = readline(STDIN); # same thing |
13035 | 13500 | |
13036 | 13501 | =begin original |
13037 | 13502 | |
13038 | 13503 | If L<C<readline>|/readline EXPR> encounters an operating system error, |
13039 | 13504 | L<C<$!>|perlvar/$!> will be set with the corresponding error message. |
13040 | 13505 | It can be helpful to check L<C<$!>|perlvar/$!> when you are reading from |
13041 | 13506 | filehandles you don't trust, such as a tty or a socket. The following |
13042 | 13507 | example uses the operator form of L<C<readline>|/readline EXPR> and dies |
13043 | 13508 | if the result is not defined. |
13044 | 13509 | |
13045 | 13510 | =end original |
13046 | 13511 | |
13047 | 13512 | L<C<readline>|/readline EXPR> が OS のシステムエラーになると、 |
13048 | 13513 | L<C<$!>|perlvar/$!> に対応するエラーメッセージがセットされます。 |
13049 | 13514 | tty やソケットといった、信頼できないファイルハンドルから読み込む時には |
13050 | 13515 | L<C<$!>|perlvar/$!> をチェックするのが助けになります。 |
13051 | 13516 | 以下の例は演算子の形の L<C<readline>|/readline EXPR> を使っており、結果が |
13052 | 13517 | 未定義の場合は die します。 |
13053 | 13518 | |
13054 | 13519 | while ( ! eof($fh) ) { |
13055 | 13520 | defined( $_ = readline $fh ) or die "readline failed: $!"; |
13056 | 13521 | ... |
13057 | 13522 | } |
13058 | 13523 | |
13059 | 13524 | =begin original |
13060 | 13525 | |
13061 | 13526 | Note that you have can't handle L<C<readline>|/readline EXPR> errors |
13062 | 13527 | that way with the C<ARGV> filehandle. In that case, you have to open |
13063 | 13528 | each element of L<C<@ARGV>|perlvar/@ARGV> yourself since |
13064 | 13529 | L<C<eof>|/eof FILEHANDLE> handles C<ARGV> differently. |
13065 | 13530 | |
13066 | 13531 | =end original |
13067 | 13532 | |
13068 | 13533 | L<C<readline>|/readline EXPR> のエラーは C<ARGV> ファイルハンドルの方法では |
13069 | 13534 | 扱えないことに注意してください。 |
13070 | 13535 | この場合、L<C<eof>|/eof FILEHANDLE> は C<ARGV> を異なった方法で扱うので、 |
13071 | 13536 | L<C<@ARGV>|perlvar/@ARGV> のそれぞれの要素を自分でオープンする必要があります。 |
13072 | 13537 | |
13073 | 13538 | foreach my $arg (@ARGV) { |
13074 | 13539 | open(my $fh, $arg) or warn "Can't open $arg: $!"; |
13075 | 13540 | |
13076 | 13541 | while ( ! eof($fh) ) { |
13077 | 13542 | defined( $_ = readline $fh ) |
13078 | 13543 | or die "readline failed for $arg: $!"; |
13079 | 13544 | ... |
13080 | 13545 | } |
13081 | 13546 | } |
13082 | 13547 | |
13548 | =begin original | |
13549 | ||
13550 | Like the C<< <EXPR> >> operator, if a C<readline> expression is | |
13551 | used as the condition of a C<while> or C<for> loop, then it will be | |
13552 | implicitly assigned to C<$_>. If either a C<readline> expression or | |
13553 | an explicit assignment of a C<readline> expression to a scalar is used | |
13554 | as a C<while>/C<for> condition, then the condition actually tests for | |
13555 | definedness of the expression's value, not for its regular truth value. | |
13556 | ||
13557 | =end original | |
13558 | ||
13559 | C<< <EXPR> >> 演算子と同様、 | |
13560 | C<readline> 式が C<while> や C<for> ループの条件として使われた場合、 | |
13561 | これは暗黙に C<$_> に代入されます。 | |
13562 | C<readline> 式または C<readline> 式からスカラへの明示的な代入が | |
13563 | C<while>/C<for> の条件部として使われた場合、 | |
13564 | 条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを | |
13565 | テストします。 | |
13566 | ||
13083 | 13567 | =item readlink EXPR |
13084 | 13568 | X<readlink> |
13085 | 13569 | |
13086 | 13570 | =item readlink |
13087 | 13571 | |
13088 | 13572 | =for Pod::Functions determine where a symbolic link is pointing |
13089 | 13573 | |
13090 | 13574 | =begin original |
13091 | 13575 | |
13092 | 13576 | Returns the value of a symbolic link, if symbolic links are |
13093 | 13577 | implemented. If not, raises an exception. If there is a system |
13094 | 13578 | error, returns the undefined value and sets L<C<$!>|perlvar/$!> (errno). |
13095 | 13579 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. |
13096 | 13580 | |
13097 | 13581 | =end original |
13098 | 13582 | |
13099 | 13583 | シンボリックリンクが実装されていれば、シンボリックリンクの値を返します。 |
13100 | 13584 | 実装されていないときには、例外が発生します。 |
13101 | 13585 | 何らかのシステムエラーが検出されると、未定義値を返し、 |
13102 | 13586 | L<C<$!>|perlvar/$!> (errno) を設定します。 |
13103 | 13587 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 |
13104 | 13588 | |
13105 | 13589 | =begin original |
13106 | 13590 | |
13107 | 13591 | Portability issues: L<perlport/readlink>. |
13108 | 13592 | |
13109 | 13593 | =end original |
13110 | 13594 | |
13111 | 13595 | 移植性の問題: L<perlport/readlink>。 |
13112 | 13596 | |
13113 | 13597 | =item readpipe EXPR |
13114 | 13598 | |
13115 | 13599 | =item readpipe |
13116 | 13600 | X<readpipe> |
13117 | 13601 | |
13118 | 13602 | =for Pod::Functions execute a system command and collect standard output |
13119 | 13603 | |
13120 | 13604 | =begin original |
13121 | 13605 | |
13122 | 13606 | EXPR is executed as a system command. |
13123 | 13607 | The collected standard output of the command is returned. |
13124 | 13608 | In scalar context, it comes back as a single (potentially |
13125 | 13609 | multi-line) string. In list context, returns a list of lines |
13126 | 13610 | (however you've defined lines with L<C<$E<sol>>|perlvar/$E<sol>> (or |
13127 | 13611 | C<$INPUT_RECORD_SEPARATOR> in L<English>)). |
13128 | 13612 | This is the internal function implementing the C<qx/EXPR/> |
13129 | 13613 | operator, but you can use it directly. The C<qx/EXPR/> |
13130 | operator is discussed in more detail in L<perlop/"I/ | |
13614 | operator is discussed in more detail in L<perlop/"C<qx/I<STRING>/>">. | |
13131 | 13615 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. |
13132 | 13616 | |
13133 | 13617 | =end original |
13134 | 13618 | |
13135 | 13619 | EXPR がシステムコマンドとして実行されます。 |
13136 | 13620 | コマンドの標準出力の内容が返されます。 |
13137 | 13621 | スカラコンテキストでは、単一の(内部的に複数行の)文字列を返します。 |
13138 | 13622 | リストコンテキストでは、行のリストを返します |
13139 | 13623 | (但し、行は L<C<$E<sol>>|perlvar/$E<sol>> (または L<English> モジュールでは |
13140 | 13624 | C<$INPUT_RECORD_SEPARATOR> で定義されます)。 |
13141 | 13625 | これは C<qx/EXPR/> 演算子を実装する内部関数ですが、直接使うことも出来ます。 |
13142 | C<qx/EXPR/> 演算子は L<perlop/"I/ | |
13626 | C<qx/EXPR/> 演算子は L<perlop/"C<qx/I<STRING>/>"> でより詳細に | |
13627 | 述べられています。 | |
13143 | 13628 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 |
13144 | 13629 | |
13145 | 13630 | =item recv SOCKET,SCALAR,LENGTH,FLAGS |
13146 | 13631 | X<recv> |
13147 | 13632 | |
13148 | 13633 | =for Pod::Functions receive a message over a Socket |
13149 | 13634 | |
13150 | 13635 | =begin original |
13151 | 13636 | |
13152 | 13637 | Receives a message on a socket. Attempts to receive LENGTH characters |
13153 | 13638 | of data into variable SCALAR from the specified SOCKET filehandle. |
13154 | 13639 | SCALAR will be grown or shrunk to the length actually read. Takes the |
13155 | 13640 | same flags as the system call of the same name. Returns the address |
13156 | 13641 | of the sender if SOCKET's protocol supports this; returns an empty |
13157 | 13642 | string otherwise. If there's an error, returns the undefined value. |
13158 | 13643 | This call is actually implemented in terms of the L<recvfrom(2)> system call. |
13159 | 13644 | See L<perlipc/"UDP: Message Passing"> for examples. |
13160 | 13645 | |
13161 | 13646 | =end original |
13162 | 13647 | |
13163 | 13648 | ソケット上のメッセージを受信します。 |
13164 | 13649 | 指定されたファイルハンドル SOCKET から、変数 SCALAR に |
13165 | 13650 | LENGTH 文字のデータを読み込もうとします。 |
13166 | 13651 | SCALAR は、実際に読まれた長さによって、大きくなったり、小さくなったりします。 |
13167 | 13652 | 同名のシステムコールと同じフラグが指定できます。 |
13168 | 13653 | SOCKET のプロトコルが対応していれば、送信側のアドレスを返します。 |
13169 | 13654 | エラー発生時には、未定義値を返します。 |
13170 | 13655 | 実際には、C の L<recvfrom(2)> を呼びます。 |
13171 | 13656 | 例については L<perlipc/"UDP: Message Passing"> を参照してください。 |
13172 | 13657 | |
13173 | 13658 | =begin original |
13174 | 13659 | |
13175 | Note th | |
13660 | Note that if the socket has been marked as C<:utf8>, C<recv> will | |
13176 | ||
13661 | throw an exception. The C<:encoding(...)> layer implicitly introduces | |
13177 | ||
13662 | the C<:utf8> layer. See L<C<binmode>|/binmode FILEHANDLE, LAYER>. | |
13178 | L<C<binmode>|/binmode FILEHANDLE, LAYER> to operate with the | |
13179 | C<:encoding(UTF-8)> I/O layer (see the L<open> pragma), the I/O will | |
13180 | operate on UTF8-encoded Unicode | |
13181 | characters, not bytes. Similarly for the C<:encoding> layer: in that | |
13182 | case pretty much any characters can be read. | |
13183 | 13663 | |
13184 | 13664 | =end original |
13185 | 13665 | |
13186 | ||
13666 | ソケットが C<:utf8> としてマークされている場合、 | |
13187 | ||
13667 | C<recv> は例外を投げることに注意してください。 | |
13188 | ||
13668 | C<:encoding(...)> 層は暗黙に C<:utf8> 層を導入します。 | |
13189 | L<C<binmode>|/binmode FILEHANDLE, LAYER> | |
13669 | L<C<binmode>|/binmode FILEHANDLE, LAYER> を参照してください。 | |
13190 | (L<open> プラグマを参照してください) を使うように指定された場合、 | |
13191 | I/O はバイトではなく、UTF8 エンコードされた Unicode 文字を操作します。 | |
13192 | C<:encoding> 層も同様です: | |
13193 | この場合、ほとんど大体全ての文字が読み込めます。 | |
13194 | 13670 | |
13195 | 13671 | =item redo LABEL |
13196 | 13672 | X<redo> |
13197 | 13673 | |
13198 | 13674 | =item redo EXPR |
13199 | 13675 | |
13200 | 13676 | =item redo |
13201 | 13677 | |
13202 | 13678 | =for Pod::Functions start this loop iteration over again |
13203 | 13679 | |
13204 | 13680 | =begin original |
13205 | 13681 | |
13206 | 13682 | The L<C<redo>|/redo LABEL> command restarts the loop block without |
13207 | 13683 | evaluating the conditional again. The L<C<continue>|/continue BLOCK> |
13208 | 13684 | block, if any, is not executed. If |
13209 | 13685 | the LABEL is omitted, the command refers to the innermost enclosing |
13210 | 13686 | loop. The C<redo EXPR> form, available starting in Perl 5.18.0, allows a |
13211 | 13687 | label name to be computed at run time, and is otherwise identical to C<redo |
13212 | 13688 | LABEL>. Programs that want to lie to themselves about what was just input |
13213 | 13689 | normally use this command: |
13214 | 13690 | |
13215 | 13691 | =end original |
13216 | 13692 | |
13217 | 13693 | L<C<redo>|/redo LABEL> コマンドは、条件を再評価しないで、ループブロックの |
13218 | 13694 | 始めからもう一度実行を開始します。 |
13219 | 13695 | L<C<continue>|/continue BLOCK> ブロックがあっても、実行されません。 |
13220 | 13696 | LABEL が省略されると、コマンドは一番内側のループを参照します。 |
13221 | 13697 | Perl 5.18.0 から利用可能な C<redo EXPR> 形式では、実行時に計算されるラベル名が |
13222 | 13698 | 使えます; それ以外は C<redo LABEL> と同一です。 |
13223 | 13699 | このコマンドは通常、自分への入力を欺くために使用します: |
13224 | 13700 | |
13225 | 13701 | # a simpleminded Pascal comment stripper |
13226 | 13702 | # (warning: assumes no { or } in strings) |
13227 | 13703 | LINE: while (<STDIN>) { |
13228 | 13704 | while (s|({.*}.*){.*}|$1 |) {} |
13229 | 13705 | s|{.*}| |; |
13230 | 13706 | if (s|{.*| |) { |
13231 | 13707 | my $front = $_; |
13232 | 13708 | while (<STDIN>) { |
13233 | 13709 | if (/}/) { # end of comment? |
13234 | 13710 | s|^|$front\{|; |
13235 | 13711 | redo LINE; |
13236 | 13712 | } |
13237 | 13713 | } |
13238 | 13714 | } |
13239 | 13715 | print; |
13240 | 13716 | } |
13241 | 13717 | |
13242 | 13718 | =begin original |
13243 | 13719 | |
13244 | L<C<redo>|/redo LABEL> cannot | |
13720 | L<C<redo>|/redo LABEL> cannot return a value from a block that typically | |
13245 | value such as C<eval {}>, C<sub {}>, or C<do {}> | |
13721 | returns a value, such as C<eval {}>, C<sub {}>, or C<do {}>. It will perform | |
13246 | to e | |
13722 | its flow control behavior, which precludes any return value. It should not be | |
13723 | used to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST> | |
13247 | 13724 | operation. |
13248 | 13725 | |
13249 | 13726 | =end original |
13250 | 13727 | |
13251 | L<C<redo>|/redo LABEL> は C<eval {}>, C<sub {}>, C<do {}> | |
13728 | L<C<redo>|/redo LABEL> は C<eval {}>, C<sub {}>, C<do {}> といった | |
13252 | ブロックを | |
13729 | 典型的には値を返すブロックから値を返せません。 | |
13253 | ||
13730 | これは、返り値を不可能にするフロー制御の振る舞いを実行します。 | |
13731 | L<C<grep>|/grep BLOCK LIST> や L<C<map>|/map BLOCK LIST> 操作を終了するのに | |
13732 | 使うべきではありません。 | |
13254 | 13733 | |
13255 | 13734 | =begin original |
13256 | 13735 | |
13257 | 13736 | Note that a block by itself is semantically identical to a loop |
13258 | 13737 | that executes once. Thus L<C<redo>|/redo LABEL> inside such a block |
13259 | 13738 | will effectively turn it into a looping construct. |
13260 | 13739 | |
13261 | 13740 | =end original |
13262 | 13741 | |
13263 | 13742 | ブロック自身は一回だけ実行されるループと文法的に同一であることに |
13264 | 13743 | 注意してください。 |
13265 | 13744 | 従って、ブロックの中で L<C<redo>|/redo LABEL> を使うことで効果的に |
13266 | 13745 | ループ構造に変換します。 |
13267 | 13746 | |
13268 | 13747 | =begin original |
13269 | 13748 | |
13270 | 13749 | See also L<C<continue>|/continue BLOCK> for an illustration of how |
13271 | 13750 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and |
13272 | 13751 | L<C<redo>|/redo LABEL> work. |
13273 | 13752 | |
13274 | 13753 | =end original |
13275 | 13754 | |
13276 | 13755 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL> が |
13277 | 13756 | どのように働くかについては L<C<continue>|/continue BLOCK> も参照してください。 |
13278 | 13757 | |
13279 | 13758 | =begin original |
13280 | 13759 | |
13281 | 13760 | Unlike most named operators, this has the same precedence as assignment. |
13282 | 13761 | It is also exempt from the looks-like-a-function rule, so |
13283 | 13762 | C<redo ("foo")."bar"> will cause "bar" to be part of the argument to |
13284 | 13763 | L<C<redo>|/redo LABEL>. |
13285 | 13764 | |
13286 | 13765 | =end original |
13287 | 13766 | |
13288 | 13767 | ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 |
13289 | 13768 | また、関数のように見えるものの規則からも免れるので、C<redo ("foo")."bar"> と |
13290 | 13769 | すると "bar" は L<C<redo>|/redo LABEL> への引数の一部となります。 |
13291 | 13770 | |
13292 | 13771 | =item ref EXPR |
13293 | 13772 | X<ref> X<reference> |
13294 | 13773 | |
13295 | 13774 | =item ref |
13296 | 13775 | |
13297 | 13776 | =for Pod::Functions find out the type of thing being referenced |
13298 | 13777 | |
13299 | 13778 | =begin original |
13300 | 13779 | |
13301 | ||
13780 | Examines the value of EXPR, expecting it to be a reference, and returns | |
13302 | string | |
13781 | a string giving information about the reference and the type of referent. | |
13303 | ||
13782 | If EXPR is not specified, L<C<$_>|perlvar/$_> will be used. | |
13304 | a reference to. | |
13305 | 13783 | |
13306 | 13784 | =end original |
13307 | 13785 | |
13308 | E | |
13786 | Examines the value of | |
13309 | ||
13787 | リファレンスと想定される EXPR の値を調べて、 | |
13310 | ||
13788 | そのリファレンスとリファレンス先の型に関する情報を表す | |
13311 | 返 | |
13789 | 文字列を返します。 | |
13790 | EXPR が指定されていない場合、L<C<$_>|perlvar/$_> が使われます。 | |
13312 | 13791 | |
13313 | 13792 | =begin original |
13314 | 13793 | |
13315 | ||
13794 | If the operand is not a reference, then the empty string will be returned. | |
13795 | An empty string will only be returned in this situation. C<ref> is often | |
13796 | useful to just test whether a value is a reference, which can be done | |
13797 | by comparing the result to the empty string. It is a common mistake | |
13798 | to use the result of C<ref> directly as a truth value: this goes wrong | |
13799 | because C<0> (which is false) can be returned for a reference. | |
13316 | 13800 | |
13317 | 13801 | =end original |
13318 | 13802 | |
13319 | ||
13803 | オペランドがリファレンスでない場合、空文字列が返されます。 | |
13804 | 空文字列はこの場合にのみ返されます。 | |
13805 | 結果を空文字列を比較することでできるので、 | |
13806 | C<ref> は単にある値がリファレンスかどうかを調べるのにしばしば有用です。 | |
13807 | C<ref> の結果を直接真の値として使うのは良くある誤りです: | |
13808 | リファレンスの場合に (偽である) C<0> が返されることがあるので、 | |
13809 | これは誤りです。 | |
13320 | 13810 | |
13321 | SCALAR | |
13322 | ARRAY | |
13323 | HASH | |
13324 | CODE | |
13325 | REF | |
13326 | GLOB | |
13327 | LVALUE | |
13328 | FORMAT | |
13329 | IO | |
13330 | VSTRING | |
13331 | Regexp | |
13332 | ||
13333 | 13811 | =begin original |
13334 | 13812 | |
13335 | ||
13813 | If the operand is a reference to a blessed object, then the name of | |
13814 | the class into which the referent is blessed will be returned. C<ref> | |
13815 | doesn't care what the physical type of the referent is; blessing takes | |
13816 | precedence over such concerns. Beware that exact comparison of C<ref> | |
13817 | results against a class name doesn't perform a class membership test: | |
13818 | a class's members also include objects blessed into subclasses, for | |
13819 | which C<ref> will return the name of the subclass. Also beware that | |
13820 | class names can clash with the built-in type names (described below). | |
13336 | 13821 | |
13337 | 13822 | =end original |
13338 | 13823 | |
13339 | ||
13824 | オペランドが bless されたオブジェクトへのリファレンスの場合、 | |
13825 | リファレンス先が bless されているクラス名が返されます。 | |
13826 | C<ref> はリファレンス先の物理的な種類については気にしません; | |
13827 | bless されているかがそのような関心より優先されます。 | |
13828 | C<ref> の結果とクラス名の正確な比較は、クラスの所属のテストを | |
13829 | 実行しないことに注意してください: | |
13830 | C<ref> がサブクラスの名前を返す場合、 | |
13831 | あるクラスのメンバはサブクラスに bless されているオブジェクトを | |
13832 | 含んでいます。 | |
13833 | クラス名は(後述する)組み込みの型名と衝突することにも注意してください。 | |
13340 | 13834 | |
13341 | if (ref($r) eq "HASH") { | |
13342 | print "r is a reference to a hash.\n"; | |
13343 | } | |
13344 | unless (ref($r)) { | |
13345 | print "r is not a reference at all.\n"; | |
13346 | } | |
13347 | ||
13348 | 13835 | =begin original |
13349 | 13836 | |
13350 | ||
13837 | If the operand is a reference to an unblessed object, then the return | |
13351 | ||
13838 | value indicates the type of object. If the unblessed referent is not | |
13352 | ||
13839 | a scalar, then the return value will be one of the strings C<ARRAY>, | |
13353 | ||
13840 | C<HASH>, C<CODE>, C<FORMAT>, or C<IO>, indicating only which kind of | |
13354 | ||
13841 | object it is. If the unblessed referent is a scalar, then the return | |
13355 | ||
13842 | value will be one of the strings C<SCALAR>, C<VSTRING>, C<REF>, C<GLOB>, | |
13843 | C<LVALUE>, or C<REGEXP>, depending on the kind of value the scalar | |
13844 | currently has. But note that C<qr//> scalars are created already | |
13845 | blessed, so C<ref qr/.../> will likely return C<Regexp>. Beware that | |
13846 | these built-in type names can also be used as | |
13847 | class names, so C<ref> returning one of these names doesn't unambiguously | |
13848 | indicate that the referent is of the kind to which the name refers. | |
13356 | 13849 | |
13357 | 13850 | =end original |
13358 | 13851 | |
13359 | ||
13852 | オペランドが bless されていないオブジェクトへのリファレンスの場合、 | |
13360 | ||
13853 | 返り値はオブジェクトの型を示します。 | |
13361 | ||
13854 | bless されていないリファレンス先がスカラではない場合、 | |
13362 | ||
13855 | 返り値はオブジェクトの種類を示す、 | |
13363 | C< | |
13856 | C<ARRAY>, C<HASH>, C<CODE>, C<FORMAT>, C<IO> のいずれかの文字列です。 | |
13364 | ||
13857 | bless されていないリファレンス先がスカラの場合、 | |
13858 | 返り値はそのスカラが現在保持している種類に依存して、 | |
13859 | C<SCALAR>, C<VSTRING>, C<REF>, C<GLOB>, C<LVALUE>, C<REGEXP> の | |
13860 | いずれかの文字列です。 | |
13861 | しかし、C<qr//> は既に bless されて作成されるので、 | |
13862 | C<ref qr/.../> はおそらく C<Regexp> を返すことに注意してください。 | |
13863 | これらの組み込み型名はまたクラス名として使われることができるので、 | |
13864 | C<ref> がこれらの名前の一つを返すことは、 | |
13865 | 明らかにリファレンス先がその名前が示している種類のものであることを | |
13866 | 示しているわけではないことに注意してください。 | |
13365 | 13867 | |
13366 | 13868 | =begin original |
13367 | 13869 | |
13368 | The | |
13870 | The ambiguity between built-in type names and class names significantly | |
13369 | ||
13871 | limits the utility of C<ref>. For unambiguous information, use | |
13872 | L<C<Scalar::Util::blessed()>|Scalar::Util/blessed> for information about | |
13873 | blessing, and L<C<Scalar::Util::reftype()>|Scalar::Util/reftype> for | |
13874 | information about physical types. Use L<the C<isa> method|UNIVERSAL/C<< | |
13875 | $obj->isa( TYPE ) >>> for class membership tests, though one must be | |
13876 | sure of blessedness before attempting a method call. | |
13370 | 13877 | |
13371 | 13878 | =end original |
13372 | 13879 | |
13373 | C< | |
13880 | 組み込み型とクラス名の間の曖昧さは C<ref> の有用性を大きく制限しています。 | |
13374 | ||
13881 | 曖昧でない情報のためには、bless に関する情報については | |
13375 | ||
13882 | L<C<Scalar::Util::blessed()>|Scalar::Util/blessed> を、 | |
13883 | 物理的な型の情報については | |
13884 | L<C<Scalar::Util::reftype()>|Scalar::Util/reftype> を使ってください。 | |
13885 | クラスの所属メンバテストには | |
13886 | L<the C<isa> method|UNIVERSAL/C<< | |
13887 | $obj->isa( TYPE ) >>> を使ってください; | |
13888 | 但し、メソッド呼び出しを試みる前に bless されていることを | |
13889 | 確認しなければなりません。 | |
13376 | 13890 | |
13377 | 13891 | =begin original |
13378 | 13892 | |
13379 | ||
13893 | See also L<perlref> and L<perlobj>. | |
13380 | name is returned instead. But don't use that, as it's now considered | |
13381 | "bad practice". For one reason, an object could be using a class called | |
13382 | C<Regexp> or C<IO>, or even C<HASH>. Also, L<C<ref>|/ref EXPR> doesn't | |
13383 | take into account subclasses, like | |
13384 | L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>> does. | |
13385 | 13894 | |
13386 | 13895 | =end original |
13387 | 13896 | |
13388 | ||
13897 | L<perlref> と L<perlobj> も参照してください。 | |
13389 | これらの代わりに、そのパッケージ名が返されます。 | |
13390 | しかし、これは今では「悪い習慣」と考えられているので、しないでください。 | |
13391 | 理由の一つは、オブジェクトは C<Regexp>, C<IO> や C<HASH> などと呼ばれる | |
13392 | クラスを使うかも知れないからです。 | |
13393 | また、L<C<ref>|/ref EXPR> は | |
13394 | L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>> のようにサブクラスを | |
13395 | 考慮したりはしません。 | |
13396 | 13898 | |
13397 | =begin original | |
13398 | ||
13399 | Instead, use L<C<blessed>|Scalar::Util/blessed> (in the L<Scalar::Util> | |
13400 | module) for boolean checks, L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>> | |
13401 | for specific class checks and L<C<reftype>|Scalar::Util/reftype> (also | |
13402 | from L<Scalar::Util>) for type checks. (See L<perlobj> for details and | |
13403 | a L<C<blessed>|Scalar::Util/blessed>/L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>> | |
13404 | example.) | |
13405 | ||
13406 | =end original | |
13407 | ||
13408 | 代わりに、真偽値チェックには (L<Scalar::Util> モジュールにある) | |
13409 | L<C<blessed>|Scalar::Util/blessed> を、特定のクラスのチェックには | |
13410 | L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>> を、型のチェックには | |
13411 | (これも L<Scalar::Util> にある) L<C<reftype>|Scalar::Util/reftype> を | |
13412 | 使ってください。 | |
13413 | (詳細と L<C<blessed>|Scalar::Util/blessed>/ | |
13414 | L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>> の例については | |
13415 | L<perlobj> を参照してください。) | |
13416 | ||
13417 | =begin original | |
13418 | ||
13419 | See also L<perlref>. | |
13420 | ||
13421 | =end original | |
13422 | ||
13423 | L<perlref> も参照してください。 | |
13424 | ||
13425 | 13899 | =item rename OLDNAME,NEWNAME |
13426 | 13900 | X<rename> X<move> X<mv> X<ren> |
13427 | 13901 | |
13428 | 13902 | =for Pod::Functions change a filename |
13429 | 13903 | |
13430 | 13904 | =begin original |
13431 | 13905 | |
13432 | 13906 | Changes the name of a file; an existing file NEWNAME will be |
13433 | 13907 | clobbered. Returns true for success, false otherwise. |
13434 | 13908 | |
13435 | 13909 | =end original |
13436 | 13910 | |
13437 | 13911 | ファイルの名前を変更します; NEWNAME というファイルが既に存在した場合、 |
13438 | 13912 | 上書きされるかもしれません。 |
13439 | 13913 | 成功時には真を、さもなければ偽を返します。 |
13440 | 13914 | |
13441 | 13915 | =begin original |
13442 | 13916 | |
13443 | 13917 | Behavior of this function varies wildly depending on your system |
13444 | 13918 | implementation. For example, it will usually not work across file system |
13445 | 13919 | boundaries, even though the system I<mv> command sometimes compensates |
13446 | 13920 | for this. Other restrictions include whether it works on directories, |
13447 | 13921 | open files, or pre-existing files. Check L<perlport> and either the |
13448 | 13922 | L<rename(2)> manpage or equivalent system documentation for details. |
13449 | 13923 | |
13450 | 13924 | =end original |
13451 | 13925 | |
13452 | 13926 | この関数の振る舞いはシステムの実装に大きく依存して異なります。 |
13453 | 13927 | 例えば、普通はファイルシステムにまたがってパス名を付け替えることはできません; |
13454 | 13928 | システムの I<mv> がこれを補完している場合でもそうです。 |
13455 | 13929 | その他の制限には、ディレクトリ、オープンしているファイル、既に存在している |
13456 | 13930 | ファイルに対して使えるか、といったことを含みます。 |
13457 | 13931 | 詳しくは、L<perlport> および L<rename(2)> man ページあるいは同様の |
13458 | 13932 | システムドキュメントを参照してください。 |
13459 | 13933 | |
13460 | 13934 | =begin original |
13461 | 13935 | |
13462 | 13936 | For a platform independent L<C<move>|File::Copy/move> function look at |
13463 | 13937 | the L<File::Copy> module. |
13464 | 13938 | |
13465 | 13939 | =end original |
13466 | 13940 | |
13467 | 13941 | プラットフォームに依存しない L<C<move>|File::Copy/move> 関数については |
13468 | 13942 | L<File::Copy> モジュールを参照してください。 |
13469 | 13943 | |
13470 | 13944 | =begin original |
13471 | 13945 | |
13472 | 13946 | Portability issues: L<perlport/rename>. |
13473 | 13947 | |
13474 | 13948 | =end original |
13475 | 13949 | |
13476 | 13950 | 移植性の問題: L<perlport/rename>。 |
13477 | 13951 | |
13478 | 13952 | =item require VERSION |
13479 | 13953 | X<require> |
13480 | 13954 | |
13481 | 13955 | =item require EXPR |
13482 | 13956 | |
13483 | 13957 | =item require |
13484 | 13958 | |
13485 | 13959 | =for Pod::Functions load in external functions from a library at runtime |
13486 | 13960 | |
13487 | 13961 | =begin original |
13488 | 13962 | |
13489 | 13963 | Demands a version of Perl specified by VERSION, or demands some semantics |
13490 | 13964 | specified by EXPR or by L<C<$_>|perlvar/$_> if EXPR is not supplied. |
13491 | 13965 | |
13492 | 13966 | =end original |
13493 | 13967 | |
13494 | 13968 | VERSION で指定される Perl のバージョンを要求するか、 |
13495 | 13969 | EXPR (省略時には L<C<$_>|perlvar/$_>) によって指定されるいくつかの動作を |
13496 | 13970 | 要求します。 |
13497 | 13971 | |
13498 | 13972 | =begin original |
13499 | 13973 | |
13500 | VERSION may be either a | |
13974 | VERSION may be either a literal such as v5.24.1, which will be | |
13501 | compared to L<C<$ | |
13975 | compared to L<C<$^V>|perlvar/$^V> (or C<$PERL_VERSION> in L<English>), | |
13502 | will be compared to | |
13976 | or a numeric argument of the form 5.024001, which will be compared to | |
13503 | L< | |
13977 | L<C<$]>|perlvar/$]>. An exception is raised if VERSION is greater than | |
13504 | version of the current Perl interpreter. Compare with | |
13978 | the version of the current Perl interpreter. Compare with | |
13505 | 13979 | L<C<use>|/use Module VERSION LIST>, which can do a similar check at |
13506 | 13980 | compile time. |
13507 | 13981 | |
13508 | 13982 | =end original |
13509 | 13983 | |
13510 | VERSION は | |
13984 | VERSION は、v5.24.1 のようなリテラル | |
13511 | ||
13985 | (L<C<$^V>|perlvar/$^V> (または L<English> モジュールでは | |
13512 | C<$PERL_VERSION>) と比較されます) | |
13986 | C<$PERL_VERSION>) と比較されます) か、 | |
13987 | 5.024001 の数値形式(L<C<$]>|perlvar/$]> と比較されます)で指定します。 | |
13513 | 13988 | VERSION が Perl の現在のバージョンより大きいと、例外が発生します。 |
13514 | 13989 | L<C<use>|/use Module VERSION LIST> と似ていますが、これはコンパイル時に |
13515 | 13990 | チェックされます。 |
13516 | 13991 | |
13517 | 13992 | =begin original |
13518 | 13993 | |
13519 | Specifying VERSION as a | |
13994 | Specifying VERSION as a numeric argument of the form 5.024001 should | |
13520 | avoided | |
13995 | generally be avoided as older less readable syntax compared to | |
13521 | ve | |
13996 | v5.24.1. Before perl 5.8.0 (released in 2002), the more verbose numeric | |
13522 | ||
13997 | form was the only supported syntax, which is why you might see it in | |
13998 | older code. | |
13523 | 13999 | |
13524 | 14000 | =end original |
13525 | 14001 | |
13526 | VERSION に | |
14002 | VERSION に 5.024001 の形の数値引数を指定することは一般的には避けるべきです; | |
13527 | ||
14003 | v5.24.1 に比べてより古く読みにくい文法だからです。 | |
13528 | ||
14004 | (2002 年にリリースされた) perl 5.8.0 より前では、より冗長な | |
13529 | ||
14005 | 数値形式が唯一対応している文法でした; これが古いコードでこれを | |
14006 | 見るかも知れない理由です。 | |
13530 | 14007 | |
13531 | 14008 | =begin original |
13532 | 14009 | |
13533 | require v5. | |
14010 | require v5.24.1; # run time version check | |
13534 | require 5. | |
14011 | require 5.24.1; # ditto | |
13535 | require 5.0 | |
14012 | require 5.024_001; # ditto; older syntax compatible | |
13536 | | |
14013 | with perl 5.6 | |
13537 | 14014 | |
13538 | 14015 | =end original |
13539 | 14016 | |
13540 | require v5. | |
14017 | require v5.24.1; # 実行時バージョンチェック | |
13541 | require 5. | |
14018 | require 5.24.1; # 同様 | |
13542 | require 5.0 | |
14019 | require 5.024_001; # 同様; perl 5.6 と互換性のある古い文法 | |
13543 | 14020 | |
13544 | 14021 | =begin original |
13545 | 14022 | |
13546 | 14023 | Otherwise, L<C<require>|/require VERSION> demands that a library file be |
13547 | 14024 | included if it hasn't already been included. The file is included via |
13548 | 14025 | the do-FILE mechanism, which is essentially just a variety of |
13549 | 14026 | L<C<eval>|/eval EXPR> with the |
13550 | 14027 | caveat that lexical variables in the invoking script will be invisible |
13551 | 14028 | to the included code. If it were implemented in pure Perl, it |
13552 | 14029 | would have semantics similar to the following: |
13553 | 14030 | |
13554 | 14031 | =end original |
13555 | 14032 | |
13556 | 14033 | それ以外の場合には、L<C<require>|/require VERSION> は、既に |
13557 | 14034 | 読み込まれていないときに読み込むライブラリファイルを要求するものとなります。 |
13558 | 14035 | そのファイルは、基本的には L<C<eval>|/eval EXPR> の一種である、 |
13559 | 14036 | do-FILE によって読み込まれますが、起動したスクリプトのレキシカル変数は |
13560 | 14037 | 読み込まれたコードから見えないという欠点があります。 |
13561 | 14038 | ピュア Perl で実装した場合、意味的には、次のようなサブルーチンと |
13562 | 14039 | 同じようなものです: |
13563 | 14040 | |
13564 | 14041 | use Carp 'croak'; |
13565 | 14042 | use version; |
13566 | 14043 | |
13567 | 14044 | sub require { |
13568 | 14045 | my ($filename) = @_; |
13569 | 14046 | if ( my $version = eval { version->parse($filename) } ) { |
13570 | 14047 | if ( $version > $^V ) { |
13571 | 14048 | my $vn = $version->normal; |
13572 | 14049 | croak "Perl $vn required--this is only $^V, stopped"; |
13573 | 14050 | } |
13574 | 14051 | return 1; |
13575 | 14052 | } |
13576 | 14053 | |
13577 | 14054 | if (exists $INC{$filename}) { |
13578 | 14055 | return 1 if $INC{$filename}; |
13579 | 14056 | croak "Compilation failed in require"; |
13580 | 14057 | } |
13581 | 14058 | |
13582 | 14059 | foreach $prefix (@INC) { |
13583 | 14060 | if (ref($prefix)) { |
13584 | 14061 | #... do other stuff - see text below .... |
13585 | 14062 | } |
13586 | 14063 | # (see text below about possible appending of .pmc |
13587 | 14064 | # suffix to $filename) |
13588 | 14065 | my $realfilename = "$prefix/$filename"; |
13589 | 14066 | next if ! -e $realfilename || -d _ || -b _; |
13590 | 14067 | $INC{$filename} = $realfilename; |
13591 | 14068 | my $result = do($realfilename); |
13592 | 14069 | # but run in caller's namespace |
13593 | 14070 | |
13594 | 14071 | if (!defined $result) { |
13595 | 14072 | $INC{$filename} = undef; |
13596 | 14073 | croak $@ ? "$@Compilation failed in require" |
13597 | 14074 | : "Can't locate $filename: $!\n"; |
13598 | 14075 | } |
13599 | 14076 | if (!$result) { |
13600 | 14077 | delete $INC{$filename}; |
13601 | 14078 | croak "$filename did not return true value"; |
13602 | 14079 | } |
13603 | 14080 | $! = 0; |
13604 | 14081 | return $result; |
13605 | 14082 | } |
13606 | 14083 | croak "Can't locate $filename in \@INC ..."; |
13607 | 14084 | } |
13608 | 14085 | |
13609 | 14086 | =begin original |
13610 | 14087 | |
13611 | 14088 | Note that the file will not be included twice under the same specified |
13612 | 14089 | name. |
13613 | 14090 | |
13614 | 14091 | =end original |
13615 | 14092 | |
13616 | 14093 | ファイルは、同じ名前で 2 回読み込まれることはないことに注意してください。 |
13617 | 14094 | |
13618 | 14095 | =begin original |
13619 | 14096 | |
13620 | 14097 | The file must return true as the last statement to indicate |
13621 | 14098 | successful execution of any initialization code, so it's customary to |
13622 | 14099 | end such a file with C<1;> unless you're sure it'll return true |
13623 | 14100 | otherwise. But it's better just to put the C<1;>, in case you add more |
13624 | 14101 | statements. |
13625 | 14102 | |
13626 | 14103 | =end original |
13627 | 14104 | |
13628 | 14105 | 初期化コードの実行がうまくいったことを示すために、ファイルは真を |
13629 | 14106 | 返さなければならないので、真を返すようになっている自信がある場合を除いては、 |
13630 | 14107 | ファイルの最後に C<1;> と書くのが習慣です。 |
13631 | 14108 | しかし、実行文を追加するような場合に備えて、C<1;> と書いておいた方が良いです。 |
13632 | 14109 | |
13633 | 14110 | =begin original |
13634 | 14111 | |
13635 | 14112 | If EXPR is a bareword, L<C<require>|/require VERSION> assumes a F<.pm> |
13636 | 14113 | extension and replaces C<::> with C</> in the filename for you, |
13637 | 14114 | to make it easy to load standard modules. This form of loading of |
13638 | modules does not risk altering your namespace | |
14115 | modules does not risk altering your namespace, however it will autovivify | |
14116 | the stash for the required module. | |
13639 | 14117 | |
13640 | 14118 | =end original |
13641 | 14119 | |
13642 | 14120 | EXPR が裸の単語であるときには、標準モジュールのロードを簡単にするように、 |
13643 | 14121 | L<C<require>|/require VERSION> は拡張子が F<.pm> であり、C<::> を C</> に |
13644 | 14122 | 変えたものがファイル名であると仮定します。 |
13645 | この形式のモジュールロードは、名前空間を変更してしまう危険はありません | |
14123 | この形式のモジュールロードは、名前空間を変更してしまう危険はありませんが、 | |
14124 | 要求されたモジュールのためのスタッシュが自動有効化されます。 | |
13646 | 14125 | |
13647 | 14126 | =begin original |
13648 | 14127 | |
13649 | 14128 | In other words, if you try this: |
13650 | 14129 | |
13651 | 14130 | =end original |
13652 | 14131 | |
13653 | 14132 | 言い換えると、以下のようにすると: |
13654 | 14133 | |
13655 | 14134 | require Foo::Bar; # a splendid bareword |
13656 | 14135 | |
13657 | 14136 | =begin original |
13658 | 14137 | |
13659 | 14138 | The require function will actually look for the F<Foo/Bar.pm> file in the |
13660 | directories specified in the L<C<@INC>|perlvar/@INC> array | |
14139 | directories specified in the L<C<@INC>|perlvar/@INC> array, and it will | |
14140 | autovivify the C<Foo::Bar::> stash at compile time. | |
13661 | 14141 | |
13662 | 14142 | =end original |
13663 | 14143 | |
13664 | 14144 | require 関数は L<C<@INC>|perlvar/@INC> 配列で指定されたディレクトリにある |
13665 | F<Foo/Bar.pm> ファイルを探し | |
14145 | F<Foo/Bar.pm> ファイルを探し、コンパイル時に | |
14146 | C<Foo::Bar::> のスタッシュを自動有効化します。 | |
13666 | 14147 | |
13667 | 14148 | =begin original |
13668 | 14149 | |
13669 | 14150 | But if you try this: |
13670 | 14151 | |
13671 | 14152 | =end original |
13672 | 14153 | |
13673 | 14154 | しかし、以下のようにすると: |
13674 | 14155 | |
13675 | 14156 | my $class = 'Foo::Bar'; |
13676 | 14157 | require $class; # $class is not a bareword |
13677 | 14158 | #or |
13678 | 14159 | require "Foo::Bar"; # not a bareword because of the "" |
13679 | 14160 | |
13680 | 14161 | =begin original |
13681 | 14162 | |
13682 | 14163 | The require function will look for the F<Foo::Bar> file in the |
13683 | 14164 | L<C<@INC>|perlvar/@INC> array and |
13684 | 14165 | will complain about not finding F<Foo::Bar> there. In this case you can do: |
13685 | 14166 | |
13686 | 14167 | =end original |
13687 | 14168 | |
13688 | 14169 | require 関数は L<C<@INC>|perlvar/@INC> 配列の F<Foo::Bar> ファイルを探し、 |
13689 | 14170 | おそらくそこに F<Foo::Bar> がないと文句をいうことになるでしょう。 |
13690 | このような場合には、以下のように | |
14171 | このような場合には、以下のように: | |
13691 | 14172 | |
13692 | 14173 | eval "require $class"; |
13693 | 14174 | |
13694 | 14175 | =begin original |
13695 | 14176 | |
14177 | or you could do | |
14178 | ||
14179 | =end original | |
14180 | ||
14181 | あるいは次のようにも出来ます | |
14182 | ||
14183 | require "Foo/Bar.pm"; | |
14184 | ||
14185 | =begin original | |
14186 | ||
14187 | Neither of these forms will autovivify any stashes at compile time and | |
14188 | only have run time effects. | |
14189 | ||
14190 | =end original | |
14191 | ||
14192 | これらのどちらもコンパイル時にスタッシュを自動有効化せず、 | |
14193 | 実行時の効果のみを持ちます。 | |
14194 | ||
14195 | =begin original | |
14196 | ||
13696 | 14197 | Now that you understand how L<C<require>|/require VERSION> looks for |
13697 | 14198 | files with a bareword argument, there is a little extra functionality |
13698 | 14199 | going on behind the scenes. Before L<C<require>|/require VERSION> looks |
13699 | 14200 | for a F<.pm> extension, it will first look for a similar filename with a |
13700 | 14201 | F<.pmc> extension. If this file is found, it will be loaded in place of |
13701 | any file ending in a F<.pm> extension. | |
14202 | any file ending in a F<.pm> extension. This applies to both the explicit | |
14203 | C<require "Foo/Bar.pm";> form and the C<require Foo::Bar;> form. | |
13702 | 14204 | |
13703 | 14205 | =end original |
13704 | 14206 | |
13705 | 14207 | 引数が裸の単語の場合、L<C<require>|/require VERSION> がどのようにファイルを |
13706 | 14208 | 探すかを理解してください; 水面下でちょっとした追加の機能があります。 |
13707 | 14209 | L<C<require>|/require VERSION> が拡張子 F<.pm> のファイルを探す前に、まず |
13708 | 14210 | 拡張子 F<.pmc> を持つファイルを探します。 |
13709 | 14211 | このファイルが見つかると、このファイルが拡張子 F<.pm> の代わりに |
13710 | 14212 | 読み込まれます。 |
14213 | これは明示的な C<require "Foo/Bar.pm";> 形式と C<require Foo::Bar;> 形式の | |
14214 | 両方に適用されます。 | |
13711 | 14215 | |
13712 | 14216 | =begin original |
13713 | 14217 | |
13714 | 14218 | You can also insert hooks into the import facility by putting Perl code |
13715 | 14219 | directly into the L<C<@INC>|perlvar/@INC> array. There are three forms |
13716 | 14220 | of hooks: subroutine references, array references, and blessed objects. |
13717 | 14221 | |
13718 | 14222 | =end original |
13719 | 14223 | |
13720 | 14224 | L<C<@INC>|perlvar/@INC> 配列に直接 Perl コードを入れることで、インポート機能に |
13721 | 14225 | フックを挿入できます。 |
13722 | 14226 | 3 種類のフックがあります: サブルーチンリファレンス、配列リファレンス、 |
13723 | 14227 | bless されたオブジェクトです。 |
13724 | 14228 | |
13725 | 14229 | =begin original |
13726 | 14230 | |
13727 | 14231 | Subroutine references are the simplest case. When the inclusion system |
13728 | 14232 | walks through L<C<@INC>|perlvar/@INC> and encounters a subroutine, this |
13729 | 14233 | subroutine gets called with two parameters, the first a reference to |
13730 | 14234 | itself, and the second the name of the file to be included (e.g., |
13731 | 14235 | F<Foo/Bar.pm>). The subroutine should return either nothing or else a |
13732 | 14236 | list of up to four values in the following order: |
13733 | 14237 | |
13734 | 14238 | =end original |
13735 | 14239 | |
13736 | 14240 | サブルーチンへのリファレンスは一番単純な場合です。 |
13737 | 14241 | インクルード機能が L<C<@INC>|perlvar/@INC> を走査してサブルーチンに |
13738 | 14242 | 出会った場合、このサブルーチンは二つの引数と共に呼び出されます; |
13739 | 14243 | 一つ目は自身へのリファレンス、二つ目はインクルードされるファイル名 |
13740 | 14244 | (F<Foo/Bar.pm> など)です。 |
13741 | 14245 | サブルーチンは何も返さないか、以下の順で最大四つの値のリストを返します。 |
13742 | 14246 | |
13743 | 14247 | =over |
13744 | 14248 | |
13745 | 14249 | =item 1 |
13746 | 14250 | |
13747 | 14251 | =begin original |
13748 | 14252 | |
13749 | 14253 | A reference to a scalar, containing any initial source code to prepend to |
13750 | 14254 | the file or generator output. |
13751 | 14255 | |
13752 | 14256 | =end original |
13753 | 14257 | |
13754 | 14258 | ファイルやジェネレータの出力の前に追加される初期化ソースコードを含む |
13755 | 14259 | スカラへのリファレンス。 |
13756 | 14260 | |
13757 | 14261 | =item 2 |
13758 | 14262 | |
13759 | 14263 | =begin original |
13760 | 14264 | |
13761 | 14265 | A filehandle, from which the file will be read. |
13762 | 14266 | |
13763 | 14267 | =end original |
13764 | 14268 | |
13765 | 14269 | ファイルが読み込まれるファイルハンドル。 |
13766 | 14270 | |
13767 | 14271 | =item 3 |
13768 | 14272 | |
13769 | 14273 | =begin original |
13770 | 14274 | |
13771 | 14275 | A reference to a subroutine. If there is no filehandle (previous item), |
13772 | 14276 | then this subroutine is expected to generate one line of source code per |
13773 | 14277 | call, writing the line into L<C<$_>|perlvar/$_> and returning 1, then |
13774 | 14278 | finally at end of file returning 0. If there is a filehandle, then the |
13775 | 14279 | subroutine will be called to act as a simple source filter, with the |
13776 | 14280 | line as read in L<C<$_>|perlvar/$_>. |
13777 | 14281 | Again, return 1 for each valid line, and 0 after all lines have been |
13778 | 14282 | returned. |
14283 | For historical reasons the subroutine will receive a meaningless argument | |
14284 | (in fact always the numeric value zero) as C<$_[0]>. | |
13779 | 14285 | |
13780 | 14286 | =end original |
13781 | 14287 | |
13782 | 14288 | サブルーチンへのリファレンス。 |
13783 | 14289 | (一つ前のアイテムである)ファイルハンドルがない場合、サブルーチンは呼び出し毎に |
13784 | 14290 | 一行のソースコードを生成し、その行を L<C<$_>|perlvar/$_> に書き込んで 1 を |
13785 | 14291 | 返し、それから最終的にファイル終端で 0 を返すものと想定されます。 |
13786 | 14292 | ファイルハンドルがある場合、サブルーチンは単純なソースフィルタとして |
13787 | 14293 | 振舞うように呼び出され、行は L<C<$_>|perlvar/$_> から読み込まれます。 |
13788 | 14294 | 再び、有効な行ごとに 1 を返し、全ての行を返した後では 0 を返します。 |
14295 | 歴史的な理由により、サブルーチンは C<$_[0]> として意味のない引数 | |
14296 | (実際には常に数値 0) を受け取ります。 | |
13789 | 14297 | |
13790 | 14298 | =item 4 |
13791 | 14299 | |
13792 | 14300 | =begin original |
13793 | 14301 | |
13794 | Optional state for the subroutine. The state is passed in as C<$_[1]>. | |
14302 | Optional state for the subroutine. The state is passed in as C<$_[1]>. | |
13795 | reference to the subroutine itself is passed in as C<$_[0]>. | |
13796 | 14303 | |
13797 | 14304 | =end original |
13798 | 14305 | |
13799 | 14306 | サブルーチンのための状態(オプション)。 |
13800 | 14307 | 状態は C<$_[1]> として渡されます。 |
13801 | サブルーチンへのリファレンス自身は C<$_[0]> として渡されます。 | |
13802 | 14308 | |
13803 | 14309 | =back |
13804 | 14310 | |
13805 | 14311 | =begin original |
13806 | 14312 | |
13807 | 14313 | If an empty list, L<C<undef>|/undef EXPR>, or nothing that matches the |
13808 | 14314 | first 3 values above is returned, then L<C<require>|/require VERSION> |
13809 | 14315 | looks at the remaining elements of L<C<@INC>|perlvar/@INC>. |
13810 | 14316 | Note that this filehandle must be a real filehandle (strictly a typeglob |
13811 | 14317 | or reference to a typeglob, whether blessed or unblessed); tied filehandles |
13812 | 14318 | will be ignored and processing will stop there. |
13813 | 14319 | |
13814 | 14320 | =end original |
13815 | 14321 | |
13816 | 14322 | 空リスト、L<C<undef>|/undef EXPR>、または上記の最初の三つの値のどれとも |
13817 | 14323 | 一致しないものが返されると、L<C<require>|/require VERSION> は |
13818 | 14324 | L<C<@INC>|perlvar/@INC> の残りの要素を見ます。 |
13819 | 14325 | このファイルハンドルは実際のファイルハンドル(厳密には型グロブ、型グロブへの |
13820 | 14326 | リファレンス、bless されているかに関わらず)でなければなりません; |
13821 | 14327 | tie されたファイルハンドルは無視され、返り値の処理はそこで停止します。 |
13822 | 14328 | |
13823 | 14329 | =begin original |
13824 | 14330 | |
13825 | 14331 | If the hook is an array reference, its first element must be a subroutine |
13826 | 14332 | reference. This subroutine is called as above, but the first parameter is |
13827 | 14333 | the array reference. This lets you indirectly pass arguments to |
13828 | 14334 | the subroutine. |
13829 | 14335 | |
13830 | 14336 | =end original |
13831 | 14337 | |
13832 | 14338 | フックが配列のリファレンスの場合、その最初の要素はサブルーチンへの |
13833 | 14339 | リファレンスでなければなりません。 |
13834 | 14340 | このサブルーチンは上述のように呼び出されますが、その最初の引数は |
13835 | 14341 | 配列のリファレンスです。 |
13836 | 14342 | これによって、間接的にサブルーチンに引数を渡すことが出来ます。 |
13837 | 14343 | |
13838 | 14344 | =begin original |
13839 | 14345 | |
13840 | 14346 | In other words, you can write: |
13841 | 14347 | |
13842 | 14348 | =end original |
13843 | 14349 | |
13844 | 14350 | 言い換えると、以下のように書いたり: |
13845 | 14351 | |
13846 | 14352 | push @INC, \&my_sub; |
13847 | 14353 | sub my_sub { |
13848 | 14354 | my ($coderef, $filename) = @_; # $coderef is \&my_sub |
13849 | 14355 | ... |
13850 | 14356 | } |
13851 | 14357 | |
13852 | 14358 | =begin original |
13853 | 14359 | |
13854 | 14360 | or: |
13855 | 14361 | |
13856 | 14362 | =end original |
13857 | 14363 | |
13858 | 14364 | または以下のように書けます: |
13859 | 14365 | |
13860 | 14366 | push @INC, [ \&my_sub, $x, $y, ... ]; |
13861 | 14367 | sub my_sub { |
13862 | 14368 | my ($arrayref, $filename) = @_; |
13863 | 14369 | # Retrieve $x, $y, ... |
13864 | 14370 | my (undef, @parameters) = @$arrayref; |
13865 | 14371 | ... |
13866 | 14372 | } |
13867 | 14373 | |
13868 | 14374 | =begin original |
13869 | 14375 | |
13870 | 14376 | If the hook is an object, it must provide an C<INC> method that will be |
13871 | 14377 | called as above, the first parameter being the object itself. (Note that |
13872 | 14378 | you must fully qualify the sub's name, as unqualified C<INC> is always forced |
13873 | 14379 | into package C<main>.) Here is a typical code layout: |
13874 | 14380 | |
13875 | 14381 | =end original |
13876 | 14382 | |
13877 | 14383 | フックがオブジェクトの場合、C<INC> メソッドを提供している必要があります; |
13878 | 14384 | それが、最初の引数をオブジェクト自身として上述のように呼び出されます。 |
13879 | 14385 | (修飾されていない C<INC> は常にパッケージ C<main> に強制されるため、 |
13880 | 14386 | サブルーチン名は完全修飾する必要があることに注意してください。) |
13881 | 14387 | 以下は典型的なコードレイアウトです: |
13882 | 14388 | |
13883 | 14389 | # In Foo.pm |
13884 | 14390 | package Foo; |
13885 | 14391 | sub new { ... } |
13886 | 14392 | sub Foo::INC { |
13887 | 14393 | my ($self, $filename) = @_; |
13888 | 14394 | ... |
13889 | 14395 | } |
13890 | 14396 | |
13891 | 14397 | # In the main program |
13892 | 14398 | push @INC, Foo->new(...); |
13893 | 14399 | |
13894 | 14400 | =begin original |
13895 | 14401 | |
13896 | 14402 | These hooks are also permitted to set the L<C<%INC>|perlvar/%INC> entry |
13897 | 14403 | corresponding to the files they have loaded. See L<perlvar/%INC>. |
13898 | 14404 | |
13899 | 14405 | =end original |
13900 | 14406 | |
13901 | 14407 | これらのフックは、読み込まれるファイルに対応する |
13902 | 14408 | L<C<%INC>|perlvar/%INC> エントリをセットすることも許可します。 |
13903 | 14409 | L<perlvar/%INC> を参照してください。 |
13904 | 14410 | |
13905 | 14411 | =begin original |
13906 | 14412 | |
13907 | 14413 | For a yet-more-powerful import facility, see |
13908 | 14414 | L<C<use>|/use Module VERSION LIST> and L<perlmod>. |
13909 | 14415 | |
13910 | 14416 | =end original |
13911 | 14417 | |
13912 | 14418 | より強力な import 機能については、このドキュメントの |
13913 | 14419 | L<C<use>|/use Module VERSION LIST> の項と、L<perlmod> を参照してください。 |
13914 | 14420 | |
13915 | 14421 | =item reset EXPR |
13916 | 14422 | X<reset> |
13917 | 14423 | |
13918 | 14424 | =item reset |
13919 | 14425 | |
13920 | 14426 | =for Pod::Functions clear all variables of a given name |
13921 | 14427 | |
13922 | 14428 | =begin original |
13923 | 14429 | |
13924 | 14430 | Generally used in a L<C<continue>|/continue BLOCK> block at the end of a |
13925 | 14431 | loop to clear variables and reset C<m?pattern?> searches so that they |
13926 | 14432 | work again. The |
13927 | 14433 | expression is interpreted as a list of single characters (hyphens |
13928 | allowed for ranges). All variables a | |
14434 | allowed for ranges). All variables (scalars, arrays, and hashes) | |
14435 | in the current package beginning with one of | |
13929 | 14436 | those letters are reset to their pristine state. If the expression is |
13930 | 14437 | omitted, one-match searches (C<m?pattern?>) are reset to match again. |
13931 | 14438 | Only resets variables or searches in the current package. Always returns |
13932 | 14439 | 1. Examples: |
13933 | 14440 | |
13934 | 14441 | =end original |
13935 | 14442 | |
13936 | 14443 | 通常、ループの最後に、変数をクリアし、C<m?pattern?> 検索を再び動作するように |
13937 | 14444 | リセットするため、L<C<continue>|/continue BLOCK> ブロックで使われます。 |
13938 | 14445 | EXPR は、文字を並べたもの (範囲を指定するのに、ハイフンが使えます) と |
13939 | 14446 | 解釈されます。 |
13940 | 名前がその文字のいずれかで始まる変数 | |
14447 | 名前がその文字のいずれかで始まる、現在のパッケージの全ての変数 | |
14448 | (スカラ、配列、ハッシュ)は、 | |
13941 | 14449 | 最初の状態にリセットされます。 |
13942 | 14450 | EXPR を省略すると、1 回検索 (C<m?pattern?>) を再びマッチするように |
13943 | 14451 | リセットできます。 |
13944 | 14452 | カレントパッケージの変数もしくは検索だけがリセットされます。 |
13945 | 14453 | 常に 1 を返します。 |
13946 | 14454 | 例: |
13947 | 14455 | |
13948 | 14456 | reset 'X'; # reset all X variables |
13949 | 14457 | reset 'a-z'; # reset lower case variables |
13950 | 14458 | reset; # just reset m?one-time? searches |
13951 | 14459 | |
13952 | 14460 | =begin original |
13953 | 14461 | |
13954 | 14462 | Resetting C<"A-Z"> is not recommended because you'll wipe out your |
13955 | 14463 | L<C<@ARGV>|perlvar/@ARGV> and L<C<@INC>|perlvar/@INC> arrays and your |
13956 | 14464 | L<C<%ENV>|perlvar/%ENV> hash. |
13957 | Resets only package variables; lexical variables are unaffected, but | |
13958 | they clean themselves up on scope exit anyway, so you'll probably want | |
13959 | to use them instead. See L<C<my>|/my VARLIST>. | |
13960 | 14465 | |
13961 | 14466 | =end original |
13962 | 14467 | |
13963 | 14468 | reset C<"A-Z"> とすると、L<C<@ARGV>|perlvar/@ARGV>, |
13964 | 14469 | L<C<@INC>|perlvar/@INC> 配列や L<C<%ENV>|perlvar/%ENV> ハッシュも |
13965 | 14470 | なくなってしまうので、止めた方が良いでしょう。 |
14471 | ||
14472 | =begin original | |
14473 | ||
14474 | Resets only package variables; lexical variables are unaffected, but | |
14475 | they clean themselves up on scope exit anyway, so you'll probably want | |
14476 | to use them instead. See L<C<my>|/my VARLIST>. | |
14477 | ||
14478 | =end original | |
14479 | ||
13966 | 14480 | パッケージ変数だけがリセットされます; レキシカル変数は影響を受けませんが、 |
13967 | 14481 | スコープから外れれば自動的に綺麗になるので、これからはこちらを |
13968 | 14482 | 使うようにした方がよいでしょう。 |
13969 | 14483 | L<C<my>|/my VARLIST> を参照してください。 |
13970 | 14484 | |
13971 | 14485 | =item return EXPR |
13972 | 14486 | X<return> |
13973 | 14487 | |
13974 | 14488 | =item return |
13975 | 14489 | |
13976 | 14490 | =for Pod::Functions get out of a function early |
13977 | 14491 | |
13978 | 14492 | =begin original |
13979 | 14493 | |
13980 | 14494 | Returns from a subroutine, L<C<eval>|/eval EXPR>, |
13981 | 14495 | L<C<do FILE>|/do EXPR>, L<C<sort>|/sort SUBNAME LIST> block or regex |
13982 | eval block (but not a L<C<grep>|/grep BLOCK LIST> | |
14496 | eval block (but not a L<C<grep>|/grep BLOCK LIST>, | |
13983 | L<C<map>|/map BLOCK LIST> block) with the value | |
14497 | L<C<map>|/map BLOCK LIST>, or L<C<do BLOCK>|/do BLOCK> block) with the value | |
13984 | 14498 | given in EXPR. Evaluation of EXPR may be in list, scalar, or void |
13985 | 14499 | context, depending on how the return value will be used, and the context |
13986 | 14500 | may vary from one execution to the next (see |
13987 | 14501 | L<C<wantarray>|/wantarray>). If no EXPR |
13988 | 14502 | is given, returns an empty list in list context, the undefined value in |
13989 | 14503 | scalar context, and (of course) nothing at all in void context. |
13990 | 14504 | |
13991 | 14505 | =end original |
13992 | 14506 | |
13993 | 14507 | サブルーチン, L<C<eval>|/eval EXPR>, L<C<do FILE>|/do EXPR>, |
13994 | 14508 | L<C<sort>|/sort SUBNAME LIST> ブロックまたは正規表現 eval ブロック |
13995 | (但し L<C<grep>|/grep BLOCK LIST> | |
14509 | (但し L<C<grep>|/grep BLOCK LIST>, | |
13996 | L<C<map>|/map BLOCK LIST> ブロックではない) から | |
14510 | L<C<map>|/map BLOCK LIST>, L<C<do BLOCK>|/do BLOCK> ブロックではない) から | |
13997 | 14511 | EXPR で与えられた値をもって、リターンします。 |
13998 | 14512 | EXPR の評価は、返り値がどのように使われるかによってリスト、スカラ、 |
13999 | 14513 | 無効コンテキストになります; またコンテキストは実行毎に変わります |
14000 | 14514 | (L<C<wantarray>|/wantarray> を参照してください)。 |
14001 | 14515 | EXPR が指定されなかった場合は、リストコンテキストでは空リストを、 |
14002 | 14516 | スカラコンテキストでは未定義値を返します; そして(もちろん) |
14003 | 14517 | 無効コンテキストでは何も返しません。 |
14004 | 14518 | |
14005 | 14519 | =begin original |
14006 | 14520 | |
14007 | 14521 | (In the absence of an explicit L<C<return>|/return EXPR>, a subroutine, |
14008 | 14522 | L<C<eval>|/eval EXPR>, |
14009 | 14523 | or L<C<do FILE>|/do EXPR> automatically returns the value of the last expression |
14010 | 14524 | evaluated.) |
14011 | 14525 | |
14012 | 14526 | =end original |
14013 | 14527 | |
14014 | 14528 | (サブルーチン, L<C<eval>|/eval EXPR>, L<C<do FILE>|/do EXPR> に明示的に |
14015 | 14529 | L<C<return>|/return EXPR> がなければ、最後に評価された値で、 |
14016 | 14530 | 自動的にリターンします。) |
14017 | 14531 | |
14018 | 14532 | =begin original |
14019 | 14533 | |
14020 | 14534 | Unlike most named operators, this is also exempt from the |
14021 | 14535 | looks-like-a-function rule, so C<return ("foo")."bar"> will |
14022 | 14536 | cause C<"bar"> to be part of the argument to L<C<return>|/return EXPR>. |
14023 | 14537 | |
14024 | 14538 | =end original |
14025 | 14539 | |
14026 | 14540 | ほとんどの名前付き演算子と異なり、関数のように見えるものの規則からも |
14027 | 14541 | 免れるので、C<return ("foo")."bar"> とすると C<"bar"> は |
14028 | 14542 | L<C<return>|/return EXPR> への引数の一部となります。 |
14029 | 14543 | |
14030 | 14544 | =item reverse LIST |
14031 | 14545 | X<reverse> X<rev> X<invert> |
14032 | 14546 | |
14033 | 14547 | =for Pod::Functions flip a string or a list |
14034 | 14548 | |
14035 | 14549 | =begin original |
14036 | 14550 | |
14037 | 14551 | In list context, returns a list value consisting of the elements |
14038 | 14552 | of LIST in the opposite order. In scalar context, concatenates the |
14039 | 14553 | elements of LIST and returns a string value with all characters |
14040 | 14554 | in the opposite order. |
14041 | 14555 | |
14042 | 14556 | =end original |
14043 | 14557 | |
14044 | 14558 | リストコンテキストでは、LIST を構成する要素を逆順に並べた |
14045 | 14559 | リスト値を返します。 |
14046 | 14560 | スカラコンテキストでは、LIST の要素を連結して、 |
14047 | 14561 | 全ての文字を逆順にした文字列を返します。 |
14048 | 14562 | |
14049 | 14563 | print join(", ", reverse "world", "Hello"); # Hello, world |
14050 | 14564 | |
14051 | 14565 | print scalar reverse "dlrow ,", "olleH"; # Hello, world |
14052 | 14566 | |
14053 | 14567 | =begin original |
14054 | 14568 | |
14055 | 14569 | Used without arguments in scalar context, L<C<reverse>|/reverse LIST> |
14056 | 14570 | reverses L<C<$_>|perlvar/$_>. |
14057 | 14571 | |
14058 | 14572 | =end original |
14059 | 14573 | |
14060 | 14574 | スカラコンテキストで引数なしで使うと、L<C<reverse>|/reverse LIST> は |
14061 | 14575 | L<C<$_>|perlvar/$_> を逆順にします。 |
14062 | 14576 | |
14063 | 14577 | $_ = "dlrow ,olleH"; |
14064 | 14578 | print reverse; # No output, list context |
14065 | 14579 | print scalar reverse; # Hello, world |
14066 | 14580 | |
14067 | 14581 | =begin original |
14068 | 14582 | |
14069 | 14583 | Note that reversing an array to itself (as in C<@a = reverse @a>) will |
14070 | 14584 | preserve non-existent elements whenever possible; i.e., for non-magical |
14071 | 14585 | arrays or for tied arrays with C<EXISTS> and C<DELETE> methods. |
14072 | 14586 | |
14073 | 14587 | =end original |
14074 | 14588 | |
14075 | 14589 | (C<@a = reverse @a> のように) 反転した配列を自分自身に代入すると、 |
14076 | 14590 | 存在しない要素は可能なら(つまりマジカルでない配列や |
14077 | 14591 | C<EXISTS> と C<DELETE> メソッドがある tie された配列) |
14078 | 14592 | いつでも保存されることに注意してください。 |
14079 | 14593 | |
14080 | 14594 | =begin original |
14081 | 14595 | |
14082 | 14596 | This operator is also handy for inverting a hash, although there are some |
14083 | 14597 | caveats. If a value is duplicated in the original hash, only one of those |
14084 | 14598 | can be represented as a key in the inverted hash. Also, this has to |
14085 | 14599 | unwind one hash and build a whole new one, which may take some time |
14086 | 14600 | on a large hash, such as from a DBM file. |
14087 | 14601 | |
14088 | 14602 | =end original |
14089 | 14603 | |
14090 | 14604 | この演算子はハッシュの逆順にするのにも便利ですが、いくつかの弱点があります。 |
14091 | 14605 | 元のハッシュで値が重複していると、それらのうち一つだけが |
14092 | 14606 | 逆順になったハッシュのキーとして表現されます。 |
14093 | 14607 | また、これは一つのハッシュをほどいて完全に新しいハッシュを作るので、 |
14094 | 14608 | DBM ファイルからのような大きなハッシュでは少し時間がかかります。 |
14095 | 14609 | |
14096 | 14610 | my %by_name = reverse %by_address; # Invert the hash |
14097 | 14611 | |
14098 | 14612 | =item rewinddir DIRHANDLE |
14099 | 14613 | X<rewinddir> |
14100 | 14614 | |
14101 | 14615 | =for Pod::Functions reset directory handle |
14102 | 14616 | |
14103 | 14617 | =begin original |
14104 | 14618 | |
14105 | 14619 | Sets the current position to the beginning of the directory for the |
14106 | 14620 | L<C<readdir>|/readdir DIRHANDLE> routine on DIRHANDLE. |
14107 | 14621 | |
14108 | 14622 | =end original |
14109 | 14623 | |
14110 | 14624 | DIRHANDLE に対する L<C<readdir>|/readdir DIRHANDLE> ルーチンの現在位置を |
14111 | 14625 | ディレクトリの最初に設定します。 |
14112 | 14626 | |
14113 | 14627 | =begin original |
14114 | 14628 | |
14115 | 14629 | Portability issues: L<perlport/rewinddir>. |
14116 | 14630 | |
14117 | 14631 | =end original |
14118 | 14632 | |
14119 | 14633 | 移植性の問題: L<perlport/rewinddir>。 |
14120 | 14634 | |
14121 | 14635 | =item rindex STR,SUBSTR,POSITION |
14122 | 14636 | X<rindex> |
14123 | 14637 | |
14124 | 14638 | =item rindex STR,SUBSTR |
14125 | 14639 | |
14126 | 14640 | =for Pod::Functions right-to-left substring search |
14127 | 14641 | |
14128 | 14642 | =begin original |
14129 | 14643 | |
14130 | 14644 | Works just like L<C<index>|/index STR,SUBSTR,POSITION> except that it |
14131 | 14645 | returns the position of the I<last> |
14132 | 14646 | occurrence of SUBSTR in STR. If POSITION is specified, returns the |
14133 | 14647 | last occurrence beginning at or before that position. |
14134 | 14648 | |
14135 | 14649 | =end original |
14136 | 14650 | |
14137 | 14651 | STR 中で I<最後に> 見つかった SUBSTR の位置を返すことを除いて、 |
14138 | 14652 | L<C<index>|/index STR,SUBSTR,POSITION> と同じように動作します。 |
14139 | 14653 | POSITION を指定すると、その位置から始まるか、その位置より前の、 |
14140 | 14654 | 最後の位置を返します。 |
14141 | 14655 | |
14142 | 14656 | =item rmdir FILENAME |
14143 | 14657 | X<rmdir> X<rd> X<directory, remove> |
14144 | 14658 | |
14145 | 14659 | =item rmdir |
14146 | 14660 | |
14147 | 14661 | =for Pod::Functions remove a directory |
14148 | 14662 | |
14149 | 14663 | =begin original |
14150 | 14664 | |
14151 | 14665 | Deletes the directory specified by FILENAME if that directory is |
14152 | 14666 | empty. If it succeeds it returns true; otherwise it returns false and |
14153 | 14667 | sets L<C<$!>|perlvar/$!> (errno). If FILENAME is omitted, uses |
14154 | 14668 | L<C<$_>|perlvar/$_>. |
14155 | 14669 | |
14156 | 14670 | =end original |
14157 | 14671 | |
14158 | 14672 | FILENAME で指定したディレクトリが空であれば、 |
14159 | 14673 | そのディレクトリを削除します。 |
14160 | 14674 | 成功時には真を返します; さもなければ偽を返して L<C<$!>|perlvar/$!> (errno) を |
14161 | 14675 | 設定します。 |
14162 | 14676 | FILENAME を省略した場合には、L<C<$_>|perlvar/$_> を使用します。 |
14163 | 14677 | |
14164 | 14678 | =begin original |
14165 | 14679 | |
14166 | 14680 | To remove a directory tree recursively (C<rm -rf> on Unix) look at |
14167 | 14681 | the L<C<rmtree>|File::Path/rmtree( $dir )> function of the L<File::Path> |
14168 | 14682 | module. |
14169 | 14683 | |
14170 | 14684 | =end original |
14171 | 14685 | |
14172 | 14686 | ディレクトリツリーを再帰的に削除したい (Unix での C<rm -rf>) 場合、 |
14173 | 14687 | L<File::Path> モジュールの L<C<rmtree>|File::Path/rmtree( $dir )> 関数を |
14174 | 14688 | 参照してください。 |
14175 | 14689 | |
14176 | 14690 | =item s/// |
14177 | 14691 | |
14178 | 14692 | =for Pod::Functions replace a pattern with a string |
14179 | 14693 | |
14180 | 14694 | =begin original |
14181 | 14695 | |
14182 | 14696 | The substitution operator. See L<perlop/"Regexp Quote-Like Operators">. |
14183 | 14697 | |
14184 | 14698 | =end original |
14185 | 14699 | |
14186 | 14700 | 置換演算子。 |
14187 | 14701 | L<perlop/"Regexp Quote-Like Operators"> を参照してください。 |
14188 | 14702 | |
14189 | 14703 | =item say FILEHANDLE LIST |
14190 | 14704 | X<say> |
14191 | 14705 | |
14192 | 14706 | =item say FILEHANDLE |
14193 | 14707 | |
14194 | 14708 | =item say LIST |
14195 | 14709 | |
14196 | 14710 | =item say |
14197 | 14711 | |
14198 | 14712 | =for Pod::Functions +say output a list to a filehandle, appending a newline |
14199 | 14713 | |
14200 | 14714 | =begin original |
14201 | 14715 | |
14202 | 14716 | Just like L<C<print>|/print FILEHANDLE LIST>, but implicitly appends a |
14203 | newline | |
14717 | newline at the end of the LIST instead of any value L<C<$\>|perlvar/$\> | |
14204 | ||
14718 | might have. To use FILEHANDLE without a LIST to | |
14205 | 14719 | print the contents of L<C<$_>|perlvar/$_> to it, you must use a bareword |
14206 | 14720 | filehandle like C<FH>, not an indirect one like C<$fh>. |
14207 | 14721 | |
14208 | 14722 | =end original |
14209 | 14723 | |
14210 | L<C<print>|/print FILEHANDLE LIST> と同様ですが、 | |
14724 | L<C<print>|/print FILEHANDLE LIST> と同様ですが、 | |
14211 | ||
14725 | L<C<$\>|perlvar/$\> の値の代わりに LIST の末尾に | |
14726 | 改行が暗黙に追加されます。 | |
14212 | 14727 | L<C<$_>|perlvar/$_> の内容を表示するために LIST なしで FILEHANDLE を |
14213 | 14728 | 使用するには、C<$fh> のような間接ファイルハンドルではなく、C<FH> のような |
14214 | 14729 | 裸の単語のファイルハンドルを使わなければなりません。 |
14215 | 14730 | |
14216 | 14731 | =begin original |
14217 | 14732 | |
14218 | 14733 | L<C<say>|/say FILEHANDLE LIST> is available only if the |
14219 | 14734 | L<C<"say"> feature|feature/The 'say' feature> is enabled or if it is |
14220 | 14735 | prefixed with C<CORE::>. The |
14221 | 14736 | L<C<"say"> feature|feature/The 'say' feature> is enabled automatically |
14222 | 14737 | with a C<use v5.10> (or higher) declaration in the current scope. |
14223 | 14738 | |
14224 | 14739 | =end original |
14225 | 14740 | |
14226 | 14741 | L<C<say>|/say FILEHANDLE LIST> は |
14227 | 14742 | L<C<"say"> 機能|feature/The 'say' feature> が有効か C<CORE::> が |
14228 | 14743 | 前置されたときにのみ利用可能です。 |
14229 | 14744 | L<C<"say"> 機能|feature/The 'say' feature> は現在のスコープで |
14230 | 14745 | C<use v5.10> (またはそれ以上) が宣言されると自動的に有効になります。 |
14231 | 14746 | |
14232 | 14747 | =item scalar EXPR |
14233 | 14748 | X<scalar> X<context> |
14234 | 14749 | |
14235 | 14750 | =for Pod::Functions force a scalar context |
14236 | 14751 | |
14237 | 14752 | =begin original |
14238 | 14753 | |
14239 | 14754 | Forces EXPR to be interpreted in scalar context and returns the value |
14240 | 14755 | of EXPR. |
14241 | 14756 | |
14242 | 14757 | =end original |
14243 | 14758 | |
14244 | 14759 | EXPR を強制的にスカラコンテキストで解釈されるようにして、 |
14245 | 14760 | EXPR の値を返します。 |
14246 | 14761 | |
14247 | 14762 | my @counts = ( scalar @a, scalar @b, scalar @c ); |
14248 | 14763 | |
14249 | 14764 | =begin original |
14250 | 14765 | |
14251 | 14766 | There is no equivalent operator to force an expression to |
14252 | 14767 | be interpolated in list context because in practice, this is never |
14253 | 14768 | needed. If you really wanted to do so, however, you could use |
14254 | 14769 | the construction C<@{[ (some expression) ]}>, but usually a simple |
14255 | 14770 | C<(some expression)> suffices. |
14256 | 14771 | |
14257 | 14772 | =end original |
14258 | 14773 | |
14259 | 14774 | 式を強制的にリストコンテキストで解釈させるようにする演算子はありません; |
14260 | 14775 | 理論的には不要だからです。 |
14261 | 14776 | それでも、もしそうしたいのなら、C<@{[ (some expression) ]}> という構造を |
14262 | 14777 | 使えます; しかし、普通は単に C<(some expression)> とすれば十分です。 |
14263 | 14778 | |
14264 | 14779 | =begin original |
14265 | 14780 | |
14266 | 14781 | Because L<C<scalar>|/scalar EXPR> is a unary operator, if you |
14267 | 14782 | accidentally use a |
14268 | 14783 | parenthesized list for the EXPR, this behaves as a scalar comma expression, |
14269 | 14784 | evaluating all but the last element in void context and returning the final |
14270 | 14785 | element evaluated in scalar context. This is seldom what you want. |
14271 | 14786 | |
14272 | 14787 | =end original |
14273 | 14788 | |
14274 | 14789 | L<C<scalar>|/scalar EXPR> は単項演算子なので、EXPR として括弧でくくった |
14275 | 14790 | リストを使った場合、これはスカラカンマ表現として振舞い、最後以外の全ては |
14276 | 14791 | 無効コンテキストとして扱われ、最後の要素をスカラコンテキストとして扱った |
14277 | 14792 | 結果が返されます。 |
14278 | 14793 | これがあなたの望むものであることはめったにないでしょう。 |
14279 | 14794 | |
14280 | 14795 | =begin original |
14281 | 14796 | |
14282 | 14797 | The following single statement: |
14283 | 14798 | |
14284 | 14799 | =end original |
14285 | 14800 | |
14286 | 14801 | 以下の一つの文は: |
14287 | 14802 | |
14288 | 14803 | print uc(scalar(foo(), $bar)), $baz; |
14289 | 14804 | |
14290 | 14805 | =begin original |
14291 | 14806 | |
14292 | 14807 | is the moral equivalent of these two: |
14293 | 14808 | |
14294 | 14809 | =end original |
14295 | 14810 | |
14296 | 14811 | 以下の二つの文と等価です。 |
14297 | 14812 | |
14298 | 14813 | foo(); |
14299 | 14814 | print(uc($bar), $baz); |
14300 | 14815 | |
14301 | 14816 | =begin original |
14302 | 14817 | |
14303 | 14818 | See L<perlop> for more details on unary operators and the comma operator, |
14304 | 14819 | and L<perldata> for details on evaluating a hash in scalar contex. |
14305 | 14820 | |
14306 | 14821 | =end original |
14307 | 14822 | |
14308 | 14823 | 単項演算子とカンマ演算子に関する詳細については L<perlop> を、 |
14309 | 14824 | スカラコンテキストでのハッシュの評価に関する詳細については L<perldata> を |
14310 | 14825 | 参照してください。 |
14311 | 14826 | |
14312 | 14827 | =item seek FILEHANDLE,POSITION,WHENCE |
14313 | 14828 | X<seek> X<fseek> X<filehandle, position> |
14314 | 14829 | |
14315 | 14830 | =for Pod::Functions reposition file pointer for random-access I/O |
14316 | 14831 | |
14317 | 14832 | =begin original |
14318 | 14833 | |
14319 | 14834 | Sets FILEHANDLE's position, just like the L<fseek(3)> call of C C<stdio>. |
14320 | 14835 | FILEHANDLE may be an expression whose value gives the name of the |
14321 | 14836 | filehandle. The values for WHENCE are C<0> to set the new position |
14322 | 14837 | I<in bytes> to POSITION; C<1> to set it to the current position plus |
14323 | 14838 | POSITION; and C<2> to set it to EOF plus POSITION, typically |
14324 | 14839 | negative. For WHENCE you may use the constants C<SEEK_SET>, |
14325 | 14840 | C<SEEK_CUR>, and C<SEEK_END> (start of the file, current position, end |
14326 | 14841 | of the file) from the L<Fcntl> module. Returns C<1> on success, false |
14327 | 14842 | otherwise. |
14328 | 14843 | |
14329 | 14844 | =end original |
14330 | 14845 | |
14331 | 14846 | C の C<stdio> ライブラリの L<fseek(3)> 関数のように、FILEHANDLE の |
14332 | 14847 | ファイルポインタを任意の位置に設定します。 |
14333 | 14848 | FILEHANDLE は、実際のファイルハンドル名を与える式でもかまいません。 |
14334 | 14849 | WHENCE の値が、C<0> ならば、新しい位置を I<バイト単位で> POSITION の位置へ |
14335 | 14850 | 設定します; C<1> ならば、現在位置から POSITION 加えた位置へ |
14336 | 14851 | 設定します; C<2> ならば、EOF からPOSITION だけ加えた位置へ、新しい位置を |
14337 | 14852 | 設定します。 |
14338 | 14853 | この値には、L<Fcntl> モジュールで使われている C<SEEK_SET>、C<SEEK_CUR>、 |
14339 | 14854 | C<SEEK_END> (ファイルの先頭、現在位置、ファイルの最後)という定数を |
14340 | 14855 | 使うこともできます。 |
14341 | 14856 | 成功時には、C<1> を、失敗時にはそれ以外を返します。 |
14342 | 14857 | |
14343 | 14858 | =begin original |
14344 | 14859 | |
14345 | 14860 | Note the emphasis on bytes: even if the filehandle has been set to operate |
14346 | 14861 | on characters (for example using the C<:encoding(UTF-8)> I/O layer), the |
14347 | 14862 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, |
14348 | 14863 | L<C<tell>|/tell FILEHANDLE>, and |
14349 | 14864 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> |
14350 | 14865 | family of functions use byte offsets, not character offsets, |
14351 | 14866 | because seeking to a character offset would be very slow in a UTF-8 file. |
14352 | 14867 | |
14353 | 14868 | =end original |
14354 | 14869 | |
14355 | 14870 | バイト単位に対する注意: 例え(例えば C<:encoding(UTF-8)> I/O 層を使うなどして) |
14356 | 14871 | ファイルハンドルが文字単位で処理するように設定されていたとしても、 |
14357 | 14872 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, |
14358 | 14873 | L<C<tell>|/tell FILEHANDLE>, |
14359 | 14874 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> シリーズの関数は |
14360 | 14875 | 文字オフセットではなくバイトオフセットを使います; |
14361 | 14876 | 文字オフセットでシークするのは UTF-8 ファイルではとても遅いからです。 |
14362 | 14877 | |
14363 | 14878 | =begin original |
14364 | 14879 | |
14365 | 14880 | If you want to position the file for |
14366 | 14881 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> or |
14367 | 14882 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, don't use |
14368 | 14883 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, because buffering makes its |
14369 | 14884 | effect on the file's read-write position unpredictable and non-portable. |
14370 | 14885 | Use L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> instead. |
14371 | 14886 | |
14372 | 14887 | =end original |
14373 | 14888 | |
14374 | 14889 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> や |
14375 | 14890 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> のためにファイルの |
14376 | 14891 | 位置を指定したい場合は、L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> は |
14377 | 14892 | 使えません; なぜならバッファリングのためにファイルの読み込み位置は |
14378 | 14893 | 動作は予測不能で移植性のないものになってしまいます。 |
14379 | 14894 | 代わりに L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> を使ってください。 |
14380 | 14895 | |
14381 | 14896 | =begin original |
14382 | 14897 | |
14383 | 14898 | Due to the rules and rigors of ANSI C, on some systems you have to do a |
14384 | 14899 | seek whenever you switch between reading and writing. Amongst other |
14385 | 14900 | things, this may have the effect of calling stdio's L<clearerr(3)>. |
14386 | 14901 | A WHENCE of C<1> (C<SEEK_CUR>) is useful for not moving the file position: |
14387 | 14902 | |
14388 | 14903 | =end original |
14389 | 14904 | |
14390 | 14905 | ANSI C の規則と困難により、システムによっては読み込みと書き込みを |
14391 | 14906 | 切り替える度にシークしなければならない場合があります。 |
14392 | 14907 | その他のことの中で、これは stdio の L<clearerr(3)> を呼び出す効果があります。 |
14393 | 14908 | WHENCE の C<1> (C<SEEK_CUR>) が、ファイル位置を変えないので有用です: |
14394 | 14909 | |
14395 | 14910 | seek($fh, 0, 1); |
14396 | 14911 | |
14397 | 14912 | =begin original |
14398 | 14913 | |
14399 | 14914 | This is also useful for applications emulating C<tail -f>. Once you hit |
14400 | 14915 | EOF on your read and then sleep for a while, you (probably) have to stick in a |
14401 | 14916 | dummy L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> to reset things. The |
14402 | 14917 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> doesn't change the position, |
14403 | 14918 | but it I<does> clear the end-of-file condition on the handle, so that the |
14404 | 14919 | next C<readline FILE> makes Perl try again to read something. (We hope.) |
14405 | 14920 | |
14406 | 14921 | =end original |
14407 | 14922 | |
14408 | 14923 | これはアプリケーションで C<tail -f> をエミュレートするのにも有用です。 |
14409 | 14924 | 一度読み込み時に EOF に到達すると、しばらくスリープし、 |
14410 | 14925 | (おそらく) ダミーの L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> をすることで |
14411 | 14926 | リセットする必要があります。 |
14412 | 14927 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> は現在の位置を変更しませんが、 |
14413 | 14928 | ハンドルの EOF 状態をI<クリアします> ので、次の C<readline FILE> で Perl は |
14414 | 14929 | 再び何かを読み込もうとします。(そのはずです。) |
14415 | 14930 | |
14416 | 14931 | =begin original |
14417 | 14932 | |
14418 | 14933 | If that doesn't work (some I/O implementations are particularly |
14419 | 14934 | cantankerous), you might need something like this: |
14420 | 14935 | |
14421 | 14936 | =end original |
14422 | 14937 | |
14423 | 14938 | これが動かない場合(特に意地の悪い I/O 実装もあります)、 |
14424 | 14939 | 以下のようなことをする必要があります: |
14425 | 14940 | |
14426 | 14941 | for (;;) { |
14427 | 14942 | for ($curpos = tell($fh); $_ = readline($fh); |
14428 | 14943 | $curpos = tell($fh)) { |
14429 | 14944 | # search for some stuff and put it into files |
14430 | 14945 | } |
14431 | 14946 | sleep($for_a_while); |
14432 | 14947 | seek($fh, $curpos, 0); |
14433 | 14948 | } |
14434 | 14949 | |
14435 | 14950 | =item seekdir DIRHANDLE,POS |
14436 | 14951 | X<seekdir> |
14437 | 14952 | |
14438 | 14953 | =for Pod::Functions reposition directory pointer |
14439 | 14954 | |
14440 | 14955 | =begin original |
14441 | 14956 | |
14442 | 14957 | Sets the current position for the L<C<readdir>|/readdir DIRHANDLE> |
14443 | 14958 | routine on DIRHANDLE. POS must be a value returned by |
14444 | 14959 | L<C<telldir>|/telldir DIRHANDLE>. L<C<seekdir>|/seekdir DIRHANDLE,POS> |
14445 | 14960 | also has the same caveats about possible directory compaction as the |
14446 | 14961 | corresponding system library routine. |
14447 | 14962 | |
14448 | 14963 | =end original |
14449 | 14964 | |
14450 | 14965 | DIRHANDLE での L<C<readdir>|/readdir DIRHANDLE> ルーチンの現在位置を |
14451 | 14966 | 設定します。 |
14452 | 14967 | POS は、L<C<telldir>|/telldir DIRHANDLE> が返す値でなければなりません。 |
14453 | 14968 | L<C<seekdir>|/seekdir DIRHANDLE,POS> は同名のシステムライブラリルーチンと |
14454 | 14969 | 同じく、ディレクトリ縮小時の問題が考えられます。 |
14455 | 14970 | |
14456 | 14971 | =item select FILEHANDLE |
14457 | 14972 | X<select> X<filehandle, default> |
14458 | 14973 | |
14459 | 14974 | =item select |
14460 | 14975 | |
14461 | 14976 | =for Pod::Functions reset default output or do I/O multiplexing |
14462 | 14977 | |
14463 | 14978 | =begin original |
14464 | 14979 | |
14465 | 14980 | Returns the currently selected filehandle. If FILEHANDLE is supplied, |
14466 | 14981 | sets the new current default filehandle for output. This has two |
14467 | 14982 | effects: first, a L<C<write>|/write FILEHANDLE> or a L<C<print>|/print |
14468 | 14983 | FILEHANDLE LIST> without a filehandle |
14469 | 14984 | default to this FILEHANDLE. Second, references to variables related to |
14470 | 14985 | output will refer to this output channel. |
14471 | 14986 | |
14472 | 14987 | =end original |
14473 | 14988 | |
14474 | 14989 | その時点で、選択されていたファイルハンドルを返します。 |
14475 | 14990 | FILEHANDLE を指定した場合には、その値を出力のデフォルトファイルハンドルに |
14476 | 14991 | 設定します。 |
14477 | 14992 | これには、2 つの効果があります: まず、ファイルハンドルを指定しないで |
14478 | 14993 | L<C<write>|/write FILEHANDLE> や L<C<print>|/print FILEHANDLE LIST> を |
14479 | 14994 | 行なった場合のデフォルトが、この FILEHANDLE になります。 |
14480 | 14995 | もう一つは、出力関連の変数への参照は、この出力チャネルを |
14481 | 14996 | 参照するようになります。 |
14482 | 14997 | |
14483 | 14998 | =begin original |
14484 | 14999 | |
14485 | 15000 | For example, to set the top-of-form format for more than one |
14486 | 15001 | output channel, you might do the following: |
14487 | 15002 | |
14488 | 15003 | =end original |
14489 | 15004 | |
14490 | 15005 | 例えば、複数の出力チャネルに対して、ページ先頭フォーマットを |
14491 | 15006 | 設定するには: |
14492 | 15007 | |
14493 | 15008 | select(REPORT1); |
14494 | 15009 | $^ = 'report1_top'; |
14495 | 15010 | select(REPORT2); |
14496 | 15011 | $^ = 'report2_top'; |
14497 | 15012 | |
14498 | 15013 | =begin original |
14499 | 15014 | |
14500 | 15015 | FILEHANDLE may be an expression whose value gives the name of the |
14501 | 15016 | actual filehandle. Thus: |
14502 | 15017 | |
14503 | 15018 | =end original |
14504 | 15019 | |
14505 | 15020 | FILEHANDLE は、実際のファイルハンドル名を示す式でもかまいません。 |
14506 | 15021 | つまり、以下のようなものです: |
14507 | 15022 | |
14508 | 15023 | my $oldfh = select(STDERR); $| = 1; select($oldfh); |
14509 | 15024 | |
14510 | 15025 | =begin original |
14511 | 15026 | |
14512 | 15027 | Some programmers may prefer to think of filehandles as objects with |
14513 | 15028 | methods, preferring to write the last example as: |
14514 | 15029 | |
14515 | 15030 | =end original |
14516 | 15031 | |
14517 | 15032 | ファイルハンドルはメソッドを持ったオブジェクトであると考えることを好む |
14518 | 15033 | プログラマもいるかもしれません; そのような場合のための最後の例は |
14519 | 15034 | 以下のようなものです: |
14520 | 15035 | |
14521 | 15036 | STDERR->autoflush(1); |
14522 | 15037 | |
14523 | 15038 | =begin original |
14524 | 15039 | |
14525 | 15040 | (Prior to Perl version 5.14, you have to C<use IO::Handle;> explicitly |
14526 | 15041 | first.) |
14527 | 15042 | |
14528 | 15043 | =end original |
14529 | 15044 | |
14530 | 15045 | (Perl バージョン 5.14 以前では、まず明示的に C<use IO::Handle;> とする |
14531 | 15046 | 必要があります。) |
14532 | 15047 | |
14533 | 15048 | =begin original |
14534 | 15049 | |
14535 | 15050 | Portability issues: L<perlport/select>. |
14536 | 15051 | |
14537 | 15052 | =end original |
14538 | 15053 | |
14539 | 15054 | 移植性の問題: L<perlport/select>。 |
14540 | 15055 | |
14541 | 15056 | =item select RBITS,WBITS,EBITS,TIMEOUT |
14542 | 15057 | X<select> |
14543 | 15058 | |
14544 | 15059 | =begin original |
14545 | 15060 | |
14546 | 15061 | This calls the L<select(2)> syscall with the bit masks specified, which |
14547 | 15062 | can be constructed using L<C<fileno>|/fileno FILEHANDLE> and |
14548 | 15063 | L<C<vec>|/vec EXPR,OFFSET,BITS>, along these lines: |
14549 | 15064 | |
14550 | 15065 | =end original |
14551 | 15066 | |
14552 | 15067 | これは、L<select(2)> システムコールを、指定したビットマスクで呼び出します; |
14553 | 15068 | ビットマスクは、L<C<fileno>|/fileno FILEHANDLE> と |
14554 | 15069 | L<C<vec>|/vec EXPR,OFFSET,BITS> を使って、以下のようにして作成できます: |
14555 | 15070 | |
14556 | 15071 | my $rin = my $win = my $ein = ''; |
14557 | 15072 | vec($rin, fileno(STDIN), 1) = 1; |
14558 | 15073 | vec($win, fileno(STDOUT), 1) = 1; |
14559 | 15074 | $ein = $rin | $win; |
14560 | 15075 | |
14561 | 15076 | =begin original |
14562 | 15077 | |
14563 | 15078 | If you want to select on many filehandles, you may wish to write a |
14564 | 15079 | subroutine like this: |
14565 | 15080 | |
14566 | 15081 | =end original |
14567 | 15082 | |
14568 | 15083 | 複数のファイルハンドルに select を行ないたいのであれば、 |
14569 | 15084 | 以下のようにします: |
14570 | 15085 | |
14571 | 15086 | sub fhbits { |
14572 | 15087 | my @fhlist = @_; |
14573 | 15088 | my $bits = ""; |
14574 | 15089 | for my $fh (@fhlist) { |
14575 | 15090 | vec($bits, fileno($fh), 1) = 1; |
14576 | 15091 | } |
14577 | 15092 | return $bits; |
14578 | 15093 | } |
14579 | 15094 | my $rin = fhbits(\*STDIN, $tty, $mysock); |
14580 | 15095 | |
14581 | 15096 | =begin original |
14582 | 15097 | |
14583 | 15098 | The usual idiom is: |
14584 | 15099 | |
14585 | 15100 | =end original |
14586 | 15101 | |
14587 | 15102 | 通常は、 |
14588 | 15103 | |
14589 | 15104 | my ($nfound, $timeleft) = |
14590 | 15105 | select(my $rout = $rin, my $wout = $win, my $eout = $ein, |
14591 | 15106 | $timeout); |
14592 | 15107 | |
14593 | 15108 | =begin original |
14594 | 15109 | |
14595 | 15110 | or to block until something becomes ready just do this |
14596 | 15111 | |
14597 | 15112 | =end original |
14598 | 15113 | |
14599 | 15114 | のように使い、いずれかの準備が整うまでブロックするには、 |
14600 | 15115 | 以下のようにします。 |
14601 | 15116 | |
14602 | 15117 | my $nfound = |
14603 | 15118 | select(my $rout = $rin, my $wout = $win, my $eout = $ein, undef); |
14604 | 15119 | |
14605 | 15120 | =begin original |
14606 | 15121 | |
14607 | 15122 | Most systems do not bother to return anything useful in C<$timeleft>, so |
14608 | 15123 | calling L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> in scalar context |
14609 | 15124 | just returns C<$nfound>. |
14610 | 15125 | |
14611 | 15126 | =end original |
14612 | 15127 | |
14613 | 15128 | ほとんどのシステムではわざわざ意味のある値を C<$timeleft> に返さないので、 |
14614 | 15129 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> をスカラコンテキストで |
14615 | 15130 | 呼び出すと、単に C<$nfound> を返します。 |
14616 | 15131 | |
14617 | 15132 | =begin original |
14618 | 15133 | |
14619 | 15134 | Any of the bit masks can also be L<C<undef>|/undef EXPR>. The timeout, |
14620 | 15135 | if specified, is |
14621 | 15136 | in seconds, which may be fractional. Note: not all implementations are |
14622 | 15137 | capable of returning the C<$timeleft>. If not, they always return |
14623 | 15138 | C<$timeleft> equal to the supplied C<$timeout>. |
14624 | 15139 | |
14625 | 15140 | =end original |
14626 | 15141 | |
14627 | 15142 | どのビットマスクにも L<C<undef>|/undef EXPR> を設定することができます。 |
14628 | 15143 | TIMEOUT を指定するときは、秒数で指定し、小数でかまいません。 |
14629 | 15144 | 注: すべての実装で、C<$timeleft> が返せるものではありません。 |
14630 | 15145 | その場合、C<$timeleft> には、常に指定した C<$timeout> と同じ値が返されます。 |
14631 | 15146 | |
14632 | 15147 | =begin original |
14633 | 15148 | |
14634 | 15149 | You can effect a sleep of 250 milliseconds this way: |
14635 | 15150 | |
14636 | 15151 | =end original |
14637 | 15152 | |
14638 | 15153 | 250 ミリ秒の sleep と同じ効果が、以下のようにして得られます。 |
14639 | 15154 | |
14640 | 15155 | select(undef, undef, undef, 0.25); |
14641 | 15156 | |
14642 | 15157 | =begin original |
14643 | 15158 | |
14644 | 15159 | Note that whether L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> gets |
14645 | 15160 | restarted after signals (say, SIGALRM) is implementation-dependent. See |
14646 | 15161 | also L<perlport> for notes on the portability of |
14647 | 15162 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>. |
14648 | 15163 | |
14649 | 15164 | =end original |
14650 | 15165 | |
14651 | 15166 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> がシグナル (例えば、SIGALRM) の |
14652 | 15167 | 後に再起動するかどうかは実装依存であることに注意してください。 |
14653 | 15168 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> の移植性に関する |
14654 | 15169 | 注意については L<perlport> も参照してください。 |
14655 | 15170 | |
14656 | 15171 | =begin original |
14657 | 15172 | |
14658 | 15173 | On error, L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> behaves just |
14659 | 15174 | like L<select(2)>: it returns C<-1> and sets L<C<$!>|perlvar/$!>. |
14660 | 15175 | |
14661 | 15176 | =end original |
14662 | 15177 | |
14663 | 15178 | エラー時は、L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> は |
14664 | 15179 | L<select(2)> のように振舞います: |
14665 | 15180 | C<-1> を返し、L<C<$!>|perlvar/$!> をセットします。 |
14666 | 15181 | |
14667 | 15182 | =begin original |
14668 | 15183 | |
14669 | 15184 | On some Unixes, L<select(2)> may report a socket file descriptor as |
14670 | 15185 | "ready for reading" even when no data is available, and thus any |
14671 | 15186 | subsequent L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> would block. |
14672 | 15187 | This can be avoided if you always use C<O_NONBLOCK> on the socket. See |
14673 | 15188 | L<select(2)> and L<fcntl(2)> for further details. |
14674 | 15189 | |
14675 | 15190 | =end original |
14676 | 15191 | |
14677 | 15192 | Unix の中には、実際に利用可能なデータがないために引き続く |
14678 | 15193 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> が |
14679 | 15194 | ブロックされる場合でも、L<select(2)> が、ソケットファイル記述子が |
14680 | 15195 | 「読み込み準備中」であると報告するものもあります。 |
14681 | 15196 | これは、ソケットに対して常に C<O_NONBLOCK> フラグを使うことで回避できます。 |
14682 | 15197 | さらなる詳細については L<select(2)> と L<fcntl(2)> を参照してください。 |
14683 | 15198 | |
14684 | 15199 | =begin original |
14685 | 15200 | |
14686 | 15201 | The standard L<C<IO::Select>|IO::Select> module provides a |
14687 | 15202 | user-friendlier interface to |
14688 | 15203 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, mostly because it does |
14689 | 15204 | all the bit-mask work for you. |
14690 | 15205 | |
14691 | 15206 | =end original |
14692 | 15207 | |
14693 | 15208 | 標準の L<C<IO::Select>|IO::Select> モジュールは |
14694 | 15209 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> へのよりユーザーフレンドリーな |
14695 | 15210 | インターフェースを提供します; 主な理由はビットマスクの仕事を |
14696 | 15211 | してくれることです。 |
14697 | 15212 | |
14698 | 15213 | =begin original |
14699 | 15214 | |
14700 | 15215 | B<WARNING>: One should not attempt to mix buffered I/O (like |
14701 | 15216 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> or |
14702 | 15217 | L<C<readline>|/readline EXPR>) with |
14703 | 15218 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, except as permitted by |
14704 | 15219 | POSIX, and even then only on POSIX systems. You have to use |
14705 | 15220 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> instead. |
14706 | 15221 | |
14707 | 15222 | =end original |
14708 | 15223 | |
14709 | 15224 | B<警告>: バッファ付き I/O (L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> や |
14710 | 15225 | L<C<readline>|/readline EXPR>) と |
14711 | 15226 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を |
14712 | 15227 | 混ぜて使ってはいけません(例外: POSIX で認められている形で使い、 |
14713 | 15228 | POSIX システムでだけ動かす場合を除きます)。 |
14714 | 15229 | 代わりに L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を |
14715 | 15230 | 使わなければなりません。 |
14716 | 15231 | |
14717 | 15232 | =begin original |
14718 | 15233 | |
14719 | 15234 | Portability issues: L<perlport/select>. |
14720 | 15235 | |
14721 | 15236 | =end original |
14722 | 15237 | |
14723 | 15238 | 移植性の問題: L<perlport/select>。 |
14724 | 15239 | |
14725 | 15240 | =item semctl ID,SEMNUM,CMD,ARG |
14726 | 15241 | X<semctl> |
14727 | 15242 | |
14728 | 15243 | =for Pod::Functions SysV semaphore control operations |
14729 | 15244 | |
14730 | 15245 | =begin original |
14731 | 15246 | |
14732 | 15247 | Calls the System V IPC function L<semctl(2)>. You'll probably have to say |
14733 | 15248 | |
14734 | 15249 | =end original |
14735 | 15250 | |
14736 | 15251 | System V IPC 関数 L<semctl(2)> を呼び出します。 |
14737 | 15252 | 正しい定数定義を得るために、まず |
14738 | 15253 | |
14739 | 15254 | use IPC::SysV; |
14740 | 15255 | |
14741 | 15256 | =begin original |
14742 | 15257 | |
14743 | 15258 | first to get the correct constant definitions. If CMD is IPC_STAT or |
14744 | 15259 | GETALL, then ARG must be a variable that will hold the returned |
14745 | 15260 | semid_ds structure or semaphore value array. Returns like |
14746 | 15261 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>: |
14747 | 15262 | the undefined value for error, "C<0 but true>" for zero, or the actual |
14748 | 15263 | return value otherwise. The ARG must consist of a vector of native |
14749 | 15264 | short integers, which may be created with C<pack("s!",(0)x$nsem)>. |
14750 | 15265 | See also L<perlipc/"SysV IPC"> and the documentation for |
14751 | 15266 | L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>. |
14752 | 15267 | |
14753 | 15268 | =end original |
14754 | 15269 | |
14755 | 15270 | と書くことが必要でしょう。 |
14756 | 15271 | CMD が、IPC_STAT か GETALL のときには、ARG は、返される |
14757 | 15272 | semid_ds 構造体か、セマフォ値の配列を納める変数でなければなりません。 |
14758 | 15273 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同じように、エラー時には |
14759 | 15274 | 未定義値、ゼロのときは C<"0 だが真">、それ以外なら、その値そのものを返します。 |
14760 | 15275 | ARG はネイティブな short int のベクターから成っていなければなりません; これは |
14761 | 15276 | C<pack("s!",(0)x$nsem)> で作成できます。 |
14762 | 15277 | L<perlipc/"SysV IPC"> と、 |
14763 | 15278 | L<C<IPC::SysV>|IPC::SysV>, L<C<IPC::Semaphore>|IPC::Semaphore> の文書も |
14764 | 15279 | 参照してください。 |
14765 | 15280 | |
14766 | 15281 | =begin original |
14767 | 15282 | |
14768 | 15283 | Portability issues: L<perlport/semctl>. |
14769 | 15284 | |
14770 | 15285 | =end original |
14771 | 15286 | |
14772 | 15287 | 移植性の問題: L<perlport/semctl>。 |
14773 | 15288 | |
14774 | 15289 | =item semget KEY,NSEMS,FLAGS |
14775 | 15290 | X<semget> |
14776 | 15291 | |
14777 | 15292 | =for Pod::Functions get set of SysV semaphores |
14778 | 15293 | |
14779 | 15294 | =begin original |
14780 | 15295 | |
14781 | 15296 | Calls the System V IPC function L<semget(2)>. Returns the semaphore id, or |
14782 | 15297 | the undefined value on error. See also |
14783 | 15298 | L<perlipc/"SysV IPC"> and the documentation for |
14784 | 15299 | L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>. |
14785 | 15300 | |
14786 | 15301 | =end original |
14787 | 15302 | |
14788 | 15303 | System V IPC 関数 L<semget(2)> を呼び出します。 |
14789 | 15304 | セマフォ ID か、エラー時には未定義値を返します。 |
14790 | 15305 | L<perlipc/"SysV IPC"> と、L<C<IPC::SysV>|IPC::SysV>, |
14791 | 15306 | L<C<IPC::Semaphore>|IPC::Semaphore> 文書も参照してください。 |
14792 | 15307 | |
14793 | 15308 | =begin original |
14794 | 15309 | |
14795 | 15310 | Portability issues: L<perlport/semget>. |
14796 | 15311 | |
14797 | 15312 | =end original |
14798 | 15313 | |
14799 | 15314 | 移植性の問題: L<perlport/semget>。 |
14800 | 15315 | |
14801 | 15316 | =item semop KEY,OPSTRING |
14802 | 15317 | X<semop> |
14803 | 15318 | |
14804 | 15319 | =for Pod::Functions SysV semaphore operations |
14805 | 15320 | |
14806 | 15321 | =begin original |
14807 | 15322 | |
14808 | 15323 | Calls the System V IPC function L<semop(2)> for semaphore operations |
14809 | 15324 | such as signalling and waiting. OPSTRING must be a packed array of |
14810 | 15325 | semop structures. Each semop structure can be generated with |
14811 | 15326 | C<pack("s!3", $semnum, $semop, $semflag)>. The length of OPSTRING |
14812 | 15327 | implies the number of semaphore operations. Returns true if |
14813 | 15328 | successful, false on error. As an example, the |
14814 | 15329 | following code waits on semaphore $semnum of semaphore id $semid: |
14815 | 15330 | |
14816 | 15331 | =end original |
14817 | 15332 | |
14818 | 15333 | シグナルを送信や、待ち合わせなどのセマフォ操作を行なうために、 |
14819 | 15334 | System V IPC 関数 L<semop(2)> を呼び出します。 |
14820 | 15335 | OPSTRING は、semop 構造体の pack された配列でなければなりません。 |
14821 | 15336 | semop 構造体は、それぞれ、C<pack("s!3", $semnum, $semop, $semflag)> のように |
14822 | 15337 | 作ることができます。 |
14823 | 15338 | セマフォ操作の数は、OPSTRING の長さからわかります。 |
14824 | 15339 | 成功時には真を、エラー時には偽を返します。 |
14825 | 15340 | 以下の例は、セマフォ ID $semid のセマフォ $semnum で |
14826 | 15341 | 待ち合わせを行ないます。 |
14827 | 15342 | |
14828 | 15343 | my $semop = pack("s!3", $semnum, -1, 0); |
14829 | 15344 | die "Semaphore trouble: $!\n" unless semop($semid, $semop); |
14830 | 15345 | |
14831 | 15346 | =begin original |
14832 | 15347 | |
14833 | 15348 | To signal the semaphore, replace C<-1> with C<1>. See also |
14834 | 15349 | L<perlipc/"SysV IPC"> and the documentation for |
14835 | 15350 | L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>. |
14836 | 15351 | |
14837 | 15352 | =end original |
14838 | 15353 | |
14839 | 15354 | セマフォにシグナルを送るには、C<-1> を C<1> に変更してください。 |
14840 | 15355 | L<perlipc/"SysV IPC"> と L<C<IPC::SysV>|IPC::SysV>, |
14841 | 15356 | L<C<IPC::Semaphore>|IPC::Semaphore> の文書も参照してください。 |
14842 | 15357 | |
14843 | 15358 | =begin original |
14844 | 15359 | |
14845 | 15360 | Portability issues: L<perlport/semop>. |
14846 | 15361 | |
14847 | 15362 | =end original |
14848 | 15363 | |
14849 | 15364 | 移植性の問題: L<perlport/semop>。 |
14850 | 15365 | |
14851 | 15366 | =item send SOCKET,MSG,FLAGS,TO |
14852 | 15367 | X<send> |
14853 | 15368 | |
14854 | 15369 | =item send SOCKET,MSG,FLAGS |
14855 | 15370 | |
14856 | 15371 | =for Pod::Functions send a message over a socket |
14857 | 15372 | |
14858 | 15373 | =begin original |
14859 | 15374 | |
14860 | 15375 | Sends a message on a socket. Attempts to send the scalar MSG to the SOCKET |
14861 | 15376 | filehandle. Takes the same flags as the system call of the same name. On |
14862 | 15377 | unconnected sockets, you must specify a destination to I<send to>, in which |
14863 | 15378 | case it does a L<sendto(2)> syscall. Returns the number of characters sent, |
14864 | 15379 | or the undefined value on error. The L<sendmsg(2)> syscall is currently |
14865 | 15380 | unimplemented. See L<perlipc/"UDP: Message Passing"> for examples. |
14866 | 15381 | |
14867 | 15382 | =end original |
14868 | 15383 | |
14869 | 15384 | ソケットにメッセージを送ります。 |
14870 | 15385 | スカラ MSG を ファイルハンドル SOCKET に送ろうとします。 |
14871 | 15386 | 同名のシステムコールと同じフラグが指定できます。 |
14872 | 15387 | 接続していないソケットには、I<send to> に接続先を指定しなければならず、 |
14873 | 15388 | この場合、L<sendto(2)> を実行します。 |
14874 | 15389 | 送信した文字数か、エラー時には、未定義値を返します。 |
14875 | 15390 | システムコール L<sendmsg(2)> は現在実装されていません。 |
14876 | 15391 | 例については L<perlipc/"UDP: Message Passing"> を参照してください。 |
14877 | 15392 | |
14878 | 15393 | =begin original |
14879 | 15394 | |
14880 | Note th | |
15395 | Note that if the socket has been marked as C<:utf8>, C<send> will | |
14881 | ||
15396 | throw an exception. The C<:encoding(...)> layer implicitly introduces | |
14882 | ||
15397 | the C<:utf8> layer. See L<C<binmode>|/binmode FILEHANDLE, LAYER>. | |
14883 | L<C<binmode>|/binmode FILEHANDLE, LAYER> to operate with the | |
14884 | C<:encoding(UTF-8)> I/O layer (see L<C<open>|/open FILEHANDLE,EXPR>, or | |
14885 | the L<open> pragma), the I/O will operate on UTF-8 | |
14886 | encoded Unicode characters, not bytes. Similarly for the C<:encoding> | |
14887 | layer: in that case pretty much any characters can be sent. | |
14888 | 15398 | |
14889 | 15399 | =end original |
14890 | 15400 | |
14891 | ||
15401 | ソケットが C<:utf8> とマークされている場合、 | |
14892 | ||
15402 | C<send> は例外を投げることに注意してください。 | |
14893 | ||
15403 | C<:encoding(...)> 層は暗黙に C<:utf8> 層を導入します。 | |
14894 | ||
15404 | L<C<binmode>|/binmode FILEHANDLE, LAYER> を参照してください。 | |
14895 | C<:encoding(UTF-8)> I/O 層(L<C<open>|/open FILEHANDLE,EXPR>、 | |
14896 | L<open> プラグマを参照してください) を使うように指定された場合、 | |
14897 | I/O はバイトではなく、UTF-8 エンコードされた Unicode 文字を操作します。 | |
14898 | C<:encoding> 層も同様です: | |
14899 | この場合、ほとんど大体全ての文字が書き込めます。 | |
14900 | 15405 | |
14901 | 15406 | =item setpgrp PID,PGRP |
14902 | 15407 | X<setpgrp> X<group> |
14903 | 15408 | |
14904 | 15409 | =for Pod::Functions set the process group of a process |
14905 | 15410 | |
14906 | 15411 | =begin original |
14907 | 15412 | |
14908 | 15413 | Sets the current process group for the specified PID, C<0> for the current |
14909 | 15414 | process. Raises an exception when used on a machine that doesn't |
14910 | 15415 | implement POSIX L<setpgid(2)> or BSD L<setpgrp(2)>. If the arguments |
14911 | 15416 | are omitted, it defaults to C<0,0>. Note that the BSD 4.2 version of |
14912 | 15417 | L<C<setpgrp>|/setpgrp PID,PGRP> does not accept any arguments, so only |
14913 | 15418 | C<setpgrp(0,0)> is portable. See also |
14914 | 15419 | L<C<POSIX::setsid()>|POSIX/C<setsid>>. |
14915 | 15420 | |
14916 | 15421 | =end original |
14917 | 15422 | |
14918 | 15423 | 指定した PID (C<0> を指定するとカレントプロセス) に |
14919 | 15424 | 対するプロセスグループを設定します。 |
14920 | 15425 | POSIX L<setpgrp(2)> または BSD L<setpgrp(2)> が実装されていないマシンでは、 |
14921 | 15426 | 例外が発生します。 |
14922 | 15427 | 引数が省略された場合は、C<0,0>が使われます。 |
14923 | 15428 | BSD 4.2 版の L<C<setpgrp>|/setpgrp PID,PGRP> は引数を取ることができないので、 |
14924 | 15429 | C<setpgrp(0,0)> のみが移植性があることに注意してください。 |
14925 | 15430 | L<C<POSIX::setsid()>|POSIX/C<setsid>> も参照してください。 |
14926 | 15431 | |
14927 | 15432 | =begin original |
14928 | 15433 | |
14929 | 15434 | Portability issues: L<perlport/setpgrp>. |
14930 | 15435 | |
14931 | 15436 | =end original |
14932 | 15437 | |
14933 | 15438 | 移植性の問題: L<perlport/setpgrp>。 |
14934 | 15439 | |
14935 | 15440 | =item setpriority WHICH,WHO,PRIORITY |
14936 | 15441 | X<setpriority> X<priority> X<nice> X<renice> |
14937 | 15442 | |
14938 | 15443 | =for Pod::Functions set a process's nice value |
14939 | 15444 | |
14940 | 15445 | =begin original |
14941 | 15446 | |
14942 | 15447 | Sets the current priority for a process, a process group, or a user. |
14943 | 15448 | (See L<setpriority(2)>.) Raises an exception when used on a machine |
14944 | 15449 | that doesn't implement L<setpriority(2)>. |
14945 | 15450 | |
14946 | 15451 | =end original |
14947 | 15452 | |
14948 | 15453 | プロセス、プロセスグループ、ユーザに対する優先順位を設定します。 |
14949 | 15454 | (L<setpriority(2)> を参照してください。) |
14950 | 15455 | L<setpriority(2)> が実装されていないマシンでは、例外が発生します。 |
14951 | 15456 | |
14952 | 15457 | =begin original |
14953 | 15458 | |
15459 | C<WHICH> can be any of C<PRIO_PROCESS>, C<PRIO_PGRP> or C<PRIO_USER> | |
15460 | imported from L<POSIX/RESOURCE CONSTANTS>. | |
15461 | ||
15462 | =end original | |
15463 | ||
15464 | C<WHICH> は、L<POSIX/RESOURCE CONSTANTS> からインポートされた | |
15465 | C<PRIO_PROCESS>, C<PRIO_PGRP>, C<PRIO_USER> のいずれかです。 | |
15466 | ||
15467 | =begin original | |
15468 | ||
14954 | 15469 | Portability issues: L<perlport/setpriority>. |
14955 | 15470 | |
14956 | 15471 | =end original |
14957 | 15472 | |
14958 | 15473 | 移植性の問題: L<perlport/setpriority>。 |
14959 | 15474 | |
14960 | 15475 | =item setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL |
14961 | 15476 | X<setsockopt> |
14962 | 15477 | |
14963 | 15478 | =for Pod::Functions set some socket options |
14964 | 15479 | |
14965 | 15480 | =begin original |
14966 | 15481 | |
14967 | 15482 | Sets the socket option requested. Returns L<C<undef>|/undef EXPR> on |
14968 | 15483 | error. Use integer constants provided by the L<C<Socket>|Socket> module |
14969 | 15484 | for |
14970 | 15485 | LEVEL and OPNAME. Values for LEVEL can also be obtained from |
14971 | 15486 | getprotobyname. OPTVAL might either be a packed string or an integer. |
14972 | 15487 | An integer OPTVAL is shorthand for pack("i", OPTVAL). |
14973 | 15488 | |
14974 | 15489 | =end original |
14975 | 15490 | |
14976 | 15491 | 要求したソケットオプションを設定します。 |
14977 | 15492 | エラー時には、L<C<undef>|/undef EXPR> を返します。 |
14978 | 15493 | LEVEL と OPNAME には L<C<Socket>|Socket> モジュールが提供する |
14979 | 15494 | 整数定数を使います。 |
14980 | 15495 | LEVEL の値は getprotobyname から得ることもできます。 |
14981 | 15496 | OPTVAL は pack された文字列か整数です。 |
14982 | 15497 | 整数の OPTVAL は pack("i", OPTVAL) の省略表現です。 |
14983 | 15498 | |
14984 | 15499 | =begin original |
14985 | 15500 | |
14986 | 15501 | An example disabling Nagle's algorithm on a socket: |
14987 | 15502 | |
14988 | 15503 | =end original |
14989 | 15504 | |
14990 | 15505 | ソケットに対する Nagle のアルゴリズムを無効にする例です: |
14991 | 15506 | |
14992 | 15507 | use Socket qw(IPPROTO_TCP TCP_NODELAY); |
14993 | 15508 | setsockopt($socket, IPPROTO_TCP, TCP_NODELAY, 1); |
14994 | 15509 | |
14995 | 15510 | =begin original |
14996 | 15511 | |
14997 | 15512 | Portability issues: L<perlport/setsockopt>. |
14998 | 15513 | |
14999 | 15514 | =end original |
15000 | 15515 | |
15001 | 15516 | 移植性の問題: L<perlport/setsockopt>。 |
15002 | 15517 | |
15003 | 15518 | =item shift ARRAY |
15004 | 15519 | X<shift> |
15005 | 15520 | |
15006 | 15521 | =item shift |
15007 | 15522 | |
15008 | 15523 | =for Pod::Functions remove the first element of an array, and return it |
15009 | 15524 | |
15010 | 15525 | =begin original |
15011 | 15526 | |
15012 | 15527 | Shifts the first value of the array off and returns it, shortening the |
15013 | 15528 | array by 1 and moving everything down. If there are no elements in the |
15014 | 15529 | array, returns the undefined value. If ARRAY is omitted, shifts the |
15015 | 15530 | L<C<@_>|perlvar/@_> array within the lexical scope of subroutines and |
15016 | 15531 | formats, and the L<C<@ARGV>|perlvar/@ARGV> array outside a subroutine |
15017 | 15532 | and also within the lexical scopes |
15018 | 15533 | established by the C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}>, |
15019 | 15534 | C<UNITCHECK {}>, and C<END {}> constructs. |
15020 | 15535 | |
15021 | 15536 | =end original |
15022 | 15537 | |
15023 | 15538 | 配列の最初の値を取り出して、その値を返し、配列を一つ短くして、すべての要素を |
15024 | 15539 | 前へずらします。 |
15025 | 15540 | 配列に要素がなければ、未定義値を返します。 |
15026 | 15541 | ARRAY を省略すると、サブルーチンやフォーマットのレキシカルスコープでは |
15027 | 15542 | L<C<@_>|perlvar/@_> を、サブルーチンの外側で、C<eval STRING>, C<BEGIN {}>, |
15028 | 15543 | C<INIT {}>, C<CHECK {}>, C<UNITCHECK {}>, C<END {}> で作成された |
15029 | 15544 | レキシカルスコープでは L<C<@ARGV>|perlvar/@ARGV> が用いられます。 |
15030 | 15545 | |
15031 | 15546 | =begin original |
15032 | 15547 | |
15033 | 15548 | Starting with Perl 5.14, an experimental feature allowed |
15034 | 15549 | L<C<shift>|/shift ARRAY> to take a |
15035 | 15550 | scalar expression. This experiment has been deemed unsuccessful, and was |
15036 | 15551 | removed as of Perl 5.24. |
15037 | 15552 | |
15038 | 15553 | =end original |
15039 | 15554 | |
15040 | 15555 | Perl 5.14 から、L<C<shift>|/shift ARRAY> がスカラ式を取ることが出来るという |
15041 | 15556 | 実験的機能がありました。 |
15042 | 15557 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 |
15043 | 15558 | |
15044 | 15559 | =begin original |
15045 | 15560 | |
15046 | 15561 | See also L<C<unshift>|/unshift ARRAY,LIST>, L<C<push>|/push ARRAY,LIST>, |
15047 | 15562 | and L<C<pop>|/pop ARRAY>. L<C<shift>|/shift ARRAY> and |
15048 | 15563 | L<C<unshift>|/unshift ARRAY,LIST> do the same thing to the left end of |
15049 | 15564 | an array that L<C<pop>|/pop ARRAY> and L<C<push>|/push ARRAY,LIST> do to |
15050 | 15565 | the right end. |
15051 | 15566 | |
15052 | 15567 | =end original |
15053 | 15568 | |
15054 | 15569 | L<C<unshift>|/unshift ARRAY,LIST>、L<C<push>|/push ARRAY,LIST>、 |
15055 | 15570 | L<C<pop>|/pop ARRAY> も参照してください。 |
15056 | 15571 | L<C<shift>|/shift ARRAY> と L<C<unshift>|/unshift ARRAY,LIST> は、 |
15057 | 15572 | L<C<pop>|/pop ARRAY> と L<C<push>|/push ARRAY,LIST> が配列の右端で |
15058 | 15573 | 行なうことを、左端で行ないます。 |
15059 | 15574 | |
15060 | 15575 | =item shmctl ID,CMD,ARG |
15061 | 15576 | X<shmctl> |
15062 | 15577 | |
15063 | 15578 | =for Pod::Functions SysV shared memory operations |
15064 | 15579 | |
15065 | 15580 | =begin original |
15066 | 15581 | |
15067 | 15582 | Calls the System V IPC function shmctl. You'll probably have to say |
15068 | 15583 | |
15069 | 15584 | =end original |
15070 | 15585 | |
15071 | 15586 | System V IPC 関数 shmctl を呼び出します。 |
15072 | 15587 | 正しい定数定義を得るために、まず |
15073 | 15588 | |
15074 | 15589 | use IPC::SysV; |
15075 | 15590 | |
15076 | 15591 | =begin original |
15077 | 15592 | |
15078 | 15593 | first to get the correct constant definitions. If CMD is C<IPC_STAT>, |
15079 | 15594 | then ARG must be a variable that will hold the returned C<shmid_ds> |
15080 | 15595 | structure. Returns like ioctl: L<C<undef>|/undef EXPR> for error; "C<0> |
15081 | 15596 | but true" for zero; and the actual return value otherwise. |
15082 | 15597 | See also L<perlipc/"SysV IPC"> and the documentation for |
15083 | 15598 | L<C<IPC::SysV>|IPC::SysV>. |
15084 | 15599 | |
15085 | 15600 | =end original |
15086 | 15601 | |
15087 | 15602 | と書くことが必要でしょう。 |
15088 | 15603 | CMD が、C<IPC_STAT> ならば、ARG は、返される C<shmid_ds> 構造体を |
15089 | 15604 | 納める変数でなければなりません。 |
15090 | 15605 | ioctl と同様です: エラー時には L<C<undef>|/undef EXPR>; ゼロのときは |
15091 | 15606 | "C<0> だが真"; それ以外なら、その値そのものを返します。 |
15092 | 15607 | L<perlipc/"SysV IPC"> と L<C<IPC::SysV>|IPC::SysV> の文書も参照してください。 |
15093 | 15608 | |
15094 | 15609 | =begin original |
15095 | 15610 | |
15096 | 15611 | Portability issues: L<perlport/shmctl>. |
15097 | 15612 | |
15098 | 15613 | =end original |
15099 | 15614 | |
15100 | 15615 | 移植性の問題: L<perlport/shmctl>。 |
15101 | 15616 | |
15102 | 15617 | =item shmget KEY,SIZE,FLAGS |
15103 | 15618 | X<shmget> |
15104 | 15619 | |
15105 | 15620 | =for Pod::Functions get SysV shared memory segment identifier |
15106 | 15621 | |
15107 | 15622 | =begin original |
15108 | 15623 | |
15109 | 15624 | Calls the System V IPC function shmget. Returns the shared memory |
15110 | 15625 | segment id, or L<C<undef>|/undef EXPR> on error. |
15111 | 15626 | See also L<perlipc/"SysV IPC"> and the documentation for |
15112 | 15627 | L<C<IPC::SysV>|IPC::SysV>. |
15113 | 15628 | |
15114 | 15629 | =end original |
15115 | 15630 | |
15116 | 15631 | System V IPC 関数 shmget を呼び出します。 |
15117 | 15632 | 共有メモリのセグメント ID か、エラー時には L<C<undef>|/undef EXPR> を返します。 |
15118 | 15633 | L<perlipc/"SysV IPC"> と L<C<IPC::SysV>|IPC::SysV> の文書も参照してください。 |
15119 | 15634 | |
15120 | 15635 | =begin original |
15121 | 15636 | |
15122 | 15637 | Portability issues: L<perlport/shmget>. |
15123 | 15638 | |
15124 | 15639 | =end original |
15125 | 15640 | |
15126 | 15641 | 移植性の問題: L<perlport/shmget>。 |
15127 | 15642 | |
15128 | 15643 | =item shmread ID,VAR,POS,SIZE |
15129 | 15644 | X<shmread> |
15130 | 15645 | X<shmwrite> |
15131 | 15646 | |
15132 | 15647 | =for Pod::Functions read SysV shared memory |
15133 | 15648 | |
15134 | 15649 | =item shmwrite ID,STRING,POS,SIZE |
15135 | 15650 | |
15136 | 15651 | =for Pod::Functions write SysV shared memory |
15137 | 15652 | |
15138 | 15653 | =begin original |
15139 | 15654 | |
15140 | 15655 | Reads or writes the System V shared memory segment ID starting at |
15141 | 15656 | position POS for size SIZE by attaching to it, copying in/out, and |
15142 | 15657 | detaching from it. When reading, VAR must be a variable that will |
15143 | 15658 | hold the data read. When writing, if STRING is too long, only SIZE |
15144 | 15659 | bytes are used; if STRING is too short, nulls are written to fill out |
15145 | 15660 | SIZE bytes. Return true if successful, false on error. |
15146 | 15661 | L<C<shmread>|/shmread ID,VAR,POS,SIZE> taints the variable. See also |
15147 | 15662 | L<perlipc/"SysV IPC"> and the documentation for |
15148 | 15663 | L<C<IPC::SysV>|IPC::SysV> and the L<C<IPC::Shareable>|IPC::Shareable> |
15149 | 15664 | module from CPAN. |
15150 | 15665 | |
15151 | 15666 | =end original |
15152 | 15667 | |
15153 | 15668 | System V 共有メモリセグメント ID に対し、アタッチして、コピーを行ない、 |
15154 | 15669 | デタッチするという形で、位置 POS から、サイズ SIZE だけ、読み込みか書き込みを |
15155 | 15670 | 行ないます。 |
15156 | 15671 | 読み込み時には、VAR は読み込んだデータを納める変数でなければなりません。 |
15157 | 15672 | 書き込み時には、STRING が長すぎても、SIZE バイトだけが使われます; STRING が |
15158 | 15673 | 短すぎる場合には、SIZE バイトを埋めるために、ヌル文字が書き込まれます。 |
15159 | 15674 | 成功時には真を、エラー時には偽を返します。 |
15160 | 15675 | L<C<shmread>|/shmread ID,VAR,POS,SIZE> は変数を汚染します。 |
15161 | 15676 | L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV> と CPAN の |
15162 | 15677 | L<C<IPC::Shareable>|IPC::Shareable> の文書も参照してください。 |
15163 | 15678 | |
15164 | 15679 | =begin original |
15165 | 15680 | |
15166 | 15681 | Portability issues: L<perlport/shmread> and L<perlport/shmwrite>. |
15167 | 15682 | |
15168 | 15683 | =end original |
15169 | 15684 | |
15170 | 15685 | 移植性の問題: L<perlport/shmread> と L<perlport/shmwrite>。 |
15171 | 15686 | |
15172 | 15687 | =item shutdown SOCKET,HOW |
15173 | 15688 | X<shutdown> |
15174 | 15689 | |
15175 | 15690 | =for Pod::Functions close down just half of a socket connection |
15176 | 15691 | |
15177 | 15692 | =begin original |
15178 | 15693 | |
15179 | 15694 | Shuts down a socket connection in the manner indicated by HOW, which |
15180 | 15695 | has the same interpretation as in the syscall of the same name. |
15181 | 15696 | |
15182 | 15697 | =end original |
15183 | 15698 | |
15184 | 15699 | 同名のシステムコールと同じように解釈される HOW によって、 |
15185 | 15700 | 指定された方法でソケット接続のシャットダウンを行ないます。 |
15186 | 15701 | |
15187 | 15702 | shutdown($socket, 0); # I/we have stopped reading data |
15188 | 15703 | shutdown($socket, 1); # I/we have stopped writing data |
15189 | 15704 | shutdown($socket, 2); # I/we have stopped using this socket |
15190 | 15705 | |
15191 | 15706 | =begin original |
15192 | 15707 | |
15193 | 15708 | This is useful with sockets when you want to tell the other |
15194 | 15709 | side you're done writing but not done reading, or vice versa. |
15195 | 15710 | It's also a more insistent form of close because it also |
15196 | 15711 | disables the file descriptor in any forked copies in other |
15197 | 15712 | processes. |
15198 | 15713 | |
15199 | 15714 | =end original |
15200 | 15715 | |
15201 | 15716 | これは、こちらがソケットを書き終わったが読み終わっていない、 |
15202 | 15717 | またはその逆を相手側に伝えたいときに便利です。 |
15203 | 15718 | これはその他のプロセスでフォークしたファイル記述子のコピーも |
15204 | 15719 | 無効にするので、よりしつこい閉じ方です。 |
15205 | 15720 | |
15206 | 15721 | =begin original |
15207 | 15722 | |
15208 | 15723 | Returns C<1> for success; on error, returns L<C<undef>|/undef EXPR> if |
15209 | 15724 | the first argument is not a valid filehandle, or returns C<0> and sets |
15210 | 15725 | L<C<$!>|perlvar/$!> for any other failure. |
15211 | 15726 | |
15212 | 15727 | =end original |
15213 | 15728 | |
15214 | 15729 | 成功時には C<1> を返します; |
15215 | 15730 | エラーの場合、最初の引数が有効なファイルハンドルでない場合は |
15216 | 15731 | L<C<undef>|/undef EXPR> を返し、その他のエラーの場合は C<0> を返して |
15217 | 15732 | L<C<$!>|perlvar/$!> をセットします。 |
15218 | 15733 | |
15219 | 15734 | =item sin EXPR |
15220 | 15735 | X<sin> X<sine> X<asin> X<arcsine> |
15221 | 15736 | |
15222 | 15737 | =item sin |
15223 | 15738 | |
15224 | 15739 | =for Pod::Functions return the sine of a number |
15225 | 15740 | |
15226 | 15741 | =begin original |
15227 | 15742 | |
15228 | 15743 | Returns the sine of EXPR (expressed in radians). If EXPR is omitted, |
15229 | 15744 | returns sine of L<C<$_>|perlvar/$_>. |
15230 | 15745 | |
15231 | 15746 | =end original |
15232 | 15747 | |
15233 | 15748 | (ラジアンで示した) EXPR の正弦を返します。 |
15234 | 15749 | EXPR が省略されたときには、L<C<$_>|perlvar/$_> の正弦を返します。 |
15235 | 15750 | |
15236 | 15751 | =begin original |
15237 | 15752 | |
15238 | 15753 | For the inverse sine operation, you may use the C<Math::Trig::asin> |
15239 | 15754 | function, or use this relation: |
15240 | 15755 | |
15241 | 15756 | =end original |
15242 | 15757 | |
15243 | 15758 | 逆正弦を求めるためには、C<Math::Trig::asin> 関数を使うか、 |
15244 | 15759 | 以下の関係を使ってください: |
15245 | 15760 | |
15246 | 15761 | sub asin { atan2($_[0], sqrt(1 - $_[0] * $_[0])) } |
15247 | 15762 | |
15248 | 15763 | =item sleep EXPR |
15249 | 15764 | X<sleep> X<pause> |
15250 | 15765 | |
15251 | 15766 | =item sleep |
15252 | 15767 | |
15253 | 15768 | =for Pod::Functions block for some number of seconds |
15254 | 15769 | |
15255 | 15770 | =begin original |
15256 | 15771 | |
15257 | 15772 | Causes the script to sleep for (integer) EXPR seconds, or forever if no |
15258 | 15773 | argument is given. Returns the integer number of seconds actually slept. |
15259 | 15774 | |
15260 | 15775 | =end original |
15261 | 15776 | |
15262 | 15777 | スクリプトを(整数の) EXPR で指定した秒数 (省略時には、永久に) |
15263 | 15778 | スリープさせます。 |
15264 | 15779 | 実際にスリープした秒数を返します。 |
15265 | 15780 | |
15266 | 15781 | =begin original |
15267 | 15782 | |
15268 | 15783 | May be interrupted if the process receives a signal such as C<SIGALRM>. |
15269 | 15784 | |
15270 | 15785 | =end original |
15271 | 15786 | |
15272 | 15787 | そのプロセスが C<SIGALRM>のようなシグナルを受信すると、 |
15273 | 15788 | 割り込みがかかります。 |
15274 | 15789 | |
15275 | 15790 | eval { |
15276 | 15791 | local $SIG{ALRM} = sub { die "Alarm!\n" }; |
15277 | 15792 | sleep; |
15278 | 15793 | }; |
15279 | 15794 | die $@ unless $@ eq "Alarm!\n"; |
15280 | 15795 | |
15281 | 15796 | =begin original |
15282 | 15797 | |
15283 | 15798 | You probably cannot mix L<C<alarm>|/alarm SECONDS> and |
15284 | 15799 | L<C<sleep>|/sleep EXPR> calls, because L<C<sleep>|/sleep EXPR> is often |
15285 | 15800 | implemented using L<C<alarm>|/alarm SECONDS>. |
15286 | 15801 | |
15287 | 15802 | =end original |
15288 | 15803 | |
15289 | 15804 | L<C<sleep>|/sleep EXPR> は、L<C<alarm>|/alarm SECONDS> を使って |
15290 | 15805 | 実装されることが多いので、L<C<alarm>|/alarm SECONDS> と |
15291 | 15806 | L<C<sleep>|/sleep EXPR> は、混ぜて使用することはおそらくできません。 |
15292 | 15807 | |
15293 | 15808 | =begin original |
15294 | 15809 | |
15295 | 15810 | On some older systems, it may sleep up to a full second less than what |
15296 | 15811 | you requested, depending on how it counts seconds. Most modern systems |
15297 | 15812 | always sleep the full amount. They may appear to sleep longer than that, |
15298 | 15813 | however, because your process might not be scheduled right away in a |
15299 | 15814 | busy multitasking system. |
15300 | 15815 | |
15301 | 15816 | =end original |
15302 | 15817 | |
15303 | 15818 | 古いシステムでは、どのように秒を数えるかによって、要求した秒数に完全に |
15304 | 15819 | 満たないうちに、スリープから抜ける場合があります。 |
15305 | 15820 | 最近のシステムでは、常に完全にスリープします。 |
15306 | 15821 | しかし、負荷の高いマルチタスクシステムでは |
15307 | 15822 | 正しくスケジューリングされないがために |
15308 | 15823 | より長い時間スリープすることがあります。 |
15309 | 15824 | |
15310 | 15825 | =begin original |
15311 | 15826 | |
15312 | 15827 | For delays of finer granularity than one second, the L<Time::HiRes> |
15313 | 15828 | module (from CPAN, and starting from Perl 5.8 part of the standard |
15314 | 15829 | distribution) provides L<C<usleep>|Time::HiRes/usleep ( $useconds )>. |
15315 | 15830 | You may also use Perl's four-argument |
15316 | 15831 | version of L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> leaving the |
15317 | 15832 | first three arguments undefined, or you might be able to use the |
15318 | 15833 | L<C<syscall>|/syscall NUMBER, LIST> interface to access L<setitimer(2)> |
15319 | 15834 | if your system supports it. See L<perlfaq8> for details. |
15320 | 15835 | |
15321 | 15836 | =end original |
15322 | 15837 | |
15323 | 15838 | 1 秒より精度の高いスリープを行なうには、L<Time::HiRes> モジュール(CPAN から、 |
15324 | 15839 | また Perl 5.8 からは標準配布されています) が |
15325 | 15840 | L<C<usleep>|Time::HiRes/usleep ( $useconds )> を提供します。 |
15326 | 15841 | Perl の 4 引数版 L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を最初の |
15327 | 15842 | 3 引数を未定義にして使うか、L<setitimer(2)> をサポートしているシステムでは、 |
15328 | 15843 | Perl の L<C<syscall>|/syscall NUMBER, LIST> インタフェースを使って |
15329 | 15844 | アクセスすることもできます。 |
15330 | 15845 | 詳しくは L<perlfaq8> を参照してください。 |
15331 | 15846 | |
15332 | 15847 | =begin original |
15333 | 15848 | |
15334 | 15849 | See also the L<POSIX> module's L<C<pause>|POSIX/C<pause>> function. |
15335 | 15850 | |
15336 | 15851 | =end original |
15337 | 15852 | |
15338 | 15853 | L<POSIX> モジュールの L<C<pause>|POSIX/C<pause>> 関数も参照してください。 |
15339 | 15854 | |
15340 | 15855 | =item socket SOCKET,DOMAIN,TYPE,PROTOCOL |
15341 | 15856 | X<socket> |
15342 | 15857 | |
15343 | 15858 | =for Pod::Functions create a socket |
15344 | 15859 | |
15345 | 15860 | =begin original |
15346 | 15861 | |
15347 | 15862 | Opens a socket of the specified kind and attaches it to filehandle |
15348 | 15863 | SOCKET. DOMAIN, TYPE, and PROTOCOL are specified the same as for |
15349 | 15864 | the syscall of the same name. You should C<use Socket> first |
15350 | 15865 | to get the proper definitions imported. See the examples in |
15351 | 15866 | L<perlipc/"Sockets: Client/Server Communication">. |
15352 | 15867 | |
15353 | 15868 | =end original |
15354 | 15869 | |
15355 | 15870 | 指定した種類のソケットをオープンし、ファイルハンドル SOCKET にアタッチします。 |
15356 | 15871 | DOMAIN, TYPE, PROTOCOL は、同名のシステムコールと同じように指定します。 |
15357 | 15872 | 適切な定義を import するために、まず、C<use Socket> とするとよいでしょう。 |
15358 | 15873 | L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。 |
15359 | 15874 | |
15360 | 15875 | =begin original |
15361 | 15876 | |
15362 | 15877 | On systems that support a close-on-exec flag on files, the flag will |
15363 | 15878 | be set for the newly opened file descriptor, as determined by the |
15364 | 15879 | value of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>. |
15365 | 15880 | |
15366 | 15881 | =end original |
15367 | 15882 | |
15368 | 15883 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
15369 | 15884 | フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた |
15370 | 15885 | ファイル記述子に対してセットされます。 |
15371 | 15886 | L<perlvar/$^F> を参照してください。 |
15372 | 15887 | |
15373 | 15888 | =item socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL |
15374 | 15889 | X<socketpair> |
15375 | 15890 | |
15376 | 15891 | =for Pod::Functions create a pair of sockets |
15377 | 15892 | |
15378 | 15893 | =begin original |
15379 | 15894 | |
15380 | 15895 | Creates an unnamed pair of sockets in the specified domain, of the |
15381 | 15896 | specified type. DOMAIN, TYPE, and PROTOCOL are specified the same as |
15382 | 15897 | for the syscall of the same name. If unimplemented, raises an exception. |
15383 | 15898 | Returns true if successful. |
15384 | 15899 | |
15385 | 15900 | =end original |
15386 | 15901 | |
15387 | 15902 | 指定した DOMAIN に、指定した TYPE で名前の無いソケットのペアを生成します。 |
15388 | 15903 | DOMAIN, TYPE, PROTOCOL は、同名のシステムコールと同じように指定します。 |
15389 | 15904 | 実装されていない場合には、例外が発生します。 |
15390 | 15905 | 成功時には真を返します。 |
15391 | 15906 | |
15392 | 15907 | =begin original |
15393 | 15908 | |
15394 | 15909 | On systems that support a close-on-exec flag on files, the flag will |
15395 | 15910 | be set for the newly opened file descriptors, as determined by the value |
15396 | 15911 | of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>. |
15397 | 15912 | |
15398 | 15913 | =end original |
15399 | 15914 | |
15400 | 15915 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
15401 | 15916 | フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた |
15402 | 15917 | ファイル記述子に対してセットされます。 |
15403 | 15918 | L<perlvar/$^F> を参照してください。 |
15404 | 15919 | |
15405 | 15920 | =begin original |
15406 | 15921 | |
15407 | 15922 | Some systems define L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> in terms of |
15408 | 15923 | L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL>, in |
15409 | 15924 | which a call to C<pipe($rdr, $wtr)> is essentially: |
15410 | 15925 | |
15411 | 15926 | =end original |
15412 | 15927 | |
15413 | 15928 | L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> を |
15414 | 15929 | L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL> を使って |
15415 | 15930 | 定義しているシステムもあります; |
15416 | 15931 | C<pipe($rdr, $wtr)> は本質的には以下のようになります: |
15417 | 15932 | |
15418 | 15933 | use Socket; |
15419 | 15934 | socketpair(my $rdr, my $wtr, AF_UNIX, SOCK_STREAM, PF_UNSPEC); |
15420 | 15935 | shutdown($rdr, 1); # no more writing for reader |
15421 | 15936 | shutdown($wtr, 0); # no more reading for writer |
15422 | 15937 | |
15423 | 15938 | =begin original |
15424 | 15939 | |
15425 | 15940 | See L<perlipc> for an example of socketpair use. Perl 5.8 and later will |
15426 | 15941 | emulate socketpair using IP sockets to localhost if your system implements |
15427 | 15942 | sockets but not socketpair. |
15428 | 15943 | |
15429 | 15944 | =end original |
15430 | 15945 | |
15431 | 15946 | socketpair の使用例については L<perlipc> を参照してください。 |
15432 | 15947 | Perl 5.8 以降では、システムがソケットを実装しているが socketpair を |
15433 | 15948 | 実装していない場合、localhost に対して IP ソケットを使うことで |
15434 | 15949 | socketpair をエミュレートします。 |
15435 | 15950 | |
15436 | 15951 | =begin original |
15437 | 15952 | |
15438 | 15953 | Portability issues: L<perlport/socketpair>. |
15439 | 15954 | |
15440 | 15955 | =end original |
15441 | 15956 | |
15442 | 15957 | 移植性の問題: L<perlport/socketpair>。 |
15443 | 15958 | |
15444 | 15959 | =item sort SUBNAME LIST |
15445 | X<sort> | |
15960 | X<sort> | |
15446 | 15961 | |
15447 | 15962 | =item sort BLOCK LIST |
15448 | 15963 | |
15449 | 15964 | =item sort LIST |
15450 | 15965 | |
15451 | 15966 | =for Pod::Functions sort a list of values |
15452 | 15967 | |
15453 | 15968 | =begin original |
15454 | 15969 | |
15455 | 15970 | In list context, this sorts the LIST and returns the sorted list value. |
15456 | 15971 | In scalar context, the behaviour of L<C<sort>|/sort SUBNAME LIST> is |
15457 | 15972 | undefined. |
15458 | 15973 | |
15459 | 15974 | =end original |
15460 | 15975 | |
15461 | 15976 | リストコンテキストでは、LIST をソートし、ソートされたリスト値を返します。 |
15462 | 15977 | スカラコンテキストでは、L<C<sort>|/sort SUBNAME LIST> の振る舞いは未定義です。 |
15463 | 15978 | |
15464 | 15979 | =begin original |
15465 | 15980 | |
15466 | 15981 | If SUBNAME or BLOCK is omitted, L<C<sort>|/sort SUBNAME LIST>s in |
15467 | 15982 | standard string comparison |
15468 | 15983 | order. If SUBNAME is specified, it gives the name of a subroutine |
15469 | 15984 | that returns an integer less than, equal to, or greater than C<0>, |
15470 | 15985 | depending on how the elements of the list are to be ordered. (The |
15471 | 15986 | C<< <=> >> and C<cmp> operators are extremely useful in such routines.) |
15472 | 15987 | SUBNAME may be a scalar variable name (unsubscripted), in which case |
15473 | 15988 | the value provides the name of (or a reference to) the actual |
15474 | 15989 | subroutine to use. In place of a SUBNAME, you can provide a BLOCK as |
15475 | 15990 | an anonymous, in-line sort subroutine. |
15476 | 15991 | |
15477 | 15992 | =end original |
15478 | 15993 | |
15479 | 15994 | SUBNAME や BLOCK を省略すると、L<C<sort>|/sort SUBNAME LIST> は標準の |
15480 | 15995 | 文字列比較の順番で行なわれます。 |
15481 | 15996 | SUBNAME を指定すると、それは、リストの要素をどのような順番に並べるかに |
15482 | 15997 | 応じて、負の整数、C<0>、正の整数を返すサブルーチンの名前であると解釈されます。 |
15483 | 15998 | (このようなルーチンには、C<< <=> >> 演算子や C<cmp> 演算子が、 |
15484 | 15999 | たいへん便利です。) |
15485 | 16000 | SUBNAME は、スカラ変数名(添字なし)でもよく、その場合には、その値が使用する |
15486 | 16001 | 実際のサブルーチンの名前(またはそのリファレンス)と解釈されます。 |
15487 | 16002 | SUBNAME の代わりに、無名のインラインソートルーチンとして、BLOCK を |
15488 | 16003 | 書くことができます。 |
15489 | 16004 | |
15490 | 16005 | =begin original |
15491 | 16006 | |
15492 | 16007 | If the subroutine's prototype is C<($$)>, the elements to be compared are |
15493 | 16008 | passed by reference in L<C<@_>|perlvar/@_>, as for a normal subroutine. |
15494 | 16009 | This is slower than unprototyped subroutines, where the elements to be |
15495 | 16010 | compared are passed into the subroutine as the package global variables |
15496 | 16011 | C<$a> and C<$b> (see example below). |
15497 | 16012 | |
15498 | 16013 | =end original |
15499 | 16014 | |
15500 | 16015 | サブルーチンのプロトタイプが C<($$)>の場合、比較する要素は通常のサブルーチンと |
15501 | 16016 | 同じように L<C<@_>|perlvar/@_> の中にリファレンスとして渡されます。 |
15502 | 16017 | これはプロトタイプなしのサブルーチンより遅いです; この場合は比較のため |
15503 | 16018 | サブルーチンに渡される二つの要素は、パッケージのグローバル変数 C<$a> と |
15504 | 16019 | C<$b> で渡されます(次の例を参照してください)。 |
15505 | 16020 | |
15506 | 16021 | =begin original |
15507 | 16022 | |
15508 | 16023 | If the subroutine is an XSUB, the elements to be compared are pushed on |
15509 | 16024 | to the stack, the way arguments are usually passed to XSUBs. C<$a> and |
15510 | 16025 | C<$b> are not set. |
15511 | 16026 | |
15512 | 16027 | =end original |
15513 | 16028 | |
15514 | 16029 | サブルーチンが XSUB の場合、比較される要素は、普通に引数を XSUB に渡す形で、 |
15515 | 16030 | スタックにプッシュされます。 |
15516 | 16031 | C<$a> と C<$b> は設定されません。 |
15517 | 16032 | |
15518 | 16033 | =begin original |
15519 | 16034 | |
15520 | 16035 | The values to be compared are always passed by reference and should not |
15521 | 16036 | be modified. |
15522 | 16037 | |
15523 | 16038 | =end original |
15524 | 16039 | |
15525 | 16040 | 比較される値はリファレンスによって渡されるので、変更するべきではありません。 |
15526 | 16041 | |
15527 | 16042 | =begin original |
15528 | 16043 | |
15529 | 16044 | You also cannot exit out of the sort block or subroutine using any of the |
15530 | 16045 | loop control operators described in L<perlsyn> or with |
15531 | 16046 | L<C<goto>|/goto LABEL>. |
15532 | 16047 | |
15533 | 16048 | =end original |
15534 | 16049 | |
15535 | 16050 | また、ソートブロックやサブルーチンから L<perlsyn> で説明されている |
15536 | 16051 | ループ制御子や L<C<goto>|/goto LABEL> を使って抜けてはいけません。 |
15537 | 16052 | |
15538 | 16053 | =begin original |
15539 | 16054 | |
15540 | 16055 | When L<C<use locale>|locale> (but not C<use locale ':not_characters'>) |
15541 | 16056 | is in effect, C<sort LIST> sorts LIST according to the |
15542 | 16057 | current collation locale. See L<perllocale>. |
15543 | 16058 | |
15544 | 16059 | =end original |
15545 | 16060 | |
15546 | 16061 | L<C<use locale>|locale> が有効(そして C<use locale ':not_characters'> が |
15547 | 16062 | 有効でない)の場合、C<sort LIST> は LIST を現在の比較ロケールに従って |
15548 | 16063 | ソートします。 |
15549 | 16064 | L<perllocale> を参照してください。 |
15550 | 16065 | |
15551 | 16066 | =begin original |
15552 | 16067 | |
15553 | 16068 | L<C<sort>|/sort SUBNAME LIST> returns aliases into the original list, |
15554 | 16069 | much as a for loop's index variable aliases the list elements. That is, |
15555 | 16070 | modifying an element of a list returned by L<C<sort>|/sort SUBNAME LIST> |
15556 | 16071 | (for example, in a C<foreach>, L<C<map>|/map BLOCK LIST> or |
15557 | 16072 | L<C<grep>|/grep BLOCK LIST>) |
15558 | 16073 | actually modifies the element in the original list. This is usually |
15559 | 16074 | something to be avoided when writing clear code. |
15560 | 16075 | |
15561 | 16076 | =end original |
15562 | 16077 | |
15563 | 16078 | L<C<sort>|/sort SUBNAME LIST> は元のリストへのエイリアスを返します; |
15564 | 16079 | for ループのインデックス変数がリスト要素へのエイリアスと同様です。 |
15565 | 16080 | つまり、L<C<sort>|/sort SUBNAME LIST> で返されるリストの要素を(例えば、 |
15566 | 16081 | C<foreach> や L<C<map>|/map BLOCK LIST> や |
15567 | 16082 | L<C<grep>|/grep BLOCK LIST> で)変更すると、実際に元のリストの要素が |
15568 | 16083 | 変更されます。 |
15569 | 16084 | これはきれいなコードを書くときには普通は回避されます。 |
15570 | 16085 | |
15571 | 16086 | =begin original |
15572 | 16087 | |
15573 | Perl | |
16088 | Historically Perl has varied in whether sorting is stable by default. | |
15574 | ||
16089 | If stability matters, it can be controlled explicitly by using the | |
15575 | ||
16090 | L<sort> pragma. | |
15576 | quicksort's run time is O(NlogN) when averaged over all arrays of | |
15577 | length N, the time can be O(N**2), I<quadratic> behavior, for some | |
15578 | inputs.) In 5.7, the quicksort implementation was replaced with | |
15579 | a stable mergesort algorithm whose worst-case behavior is O(NlogN). | |
15580 | But benchmarks indicated that for some inputs, on some platforms, | |
15581 | the original quicksort was faster. 5.8 has a L<sort> pragma for | |
15582 | limited control of the sort. Its rather blunt control of the | |
15583 | underlying algorithm may not persist into future Perls, but the | |
15584 | ability to characterize the input or output in implementation | |
15585 | independent ways quite probably will. | |
15586 | 16091 | |
15587 | 16092 | =end original |
15588 | 16093 | |
15589 | ||
16094 | 歴史的には、ソートがデフォルトで安定かどうかは様々です。 | |
15590 | ||
16095 | 安定性が問題になる場合は、L<sort> プラグマを使うことで明示的に制御できます。 | |
15591 | (I<安定した> ソートは、比較した時に同じ要素の入力順が保存されます。 | |
15592 | クイックソートの実行時間は、長さ N の全ての配列の平均では O(NlogN) ですが、 | |
15593 | 入力によっては O(N**2) という I<2 乗の> 振る舞いをすることがあります。) | |
15594 | 5.7 では、クイックソートによる実装は、最悪の場合の振る舞いも O(NlogN) である、 | |
15595 | 安定したマージソートアルゴリズムに置き換えられました。 | |
15596 | しかし、入力とプラットフォームによっては、ベンチマークはクイックソートの方が | |
15597 | 速くなります。 | |
15598 | 5.8 ではソートを限定的に制御できる L<sort> プラグマがあります。 | |
15599 | この、アルゴリズムの直接的な制御方法は将来の perl では引き継がれないかも | |
15600 | しれませんが、実装に依存しない形で入力や出力を性格付ける機能は | |
15601 | おそらくあります。 | |
15602 | 16096 | |
15603 | 16097 | =begin original |
15604 | 16098 | |
15605 | 16099 | Examples: |
15606 | 16100 | |
15607 | 16101 | =end original |
15608 | 16102 | |
15609 | 16103 | 例: |
15610 | 16104 | |
15611 | 16105 | # sort lexically |
15612 | 16106 | my @articles = sort @files; |
15613 | 16107 | |
15614 | 16108 | # same thing, but with explicit sort routine |
15615 | 16109 | my @articles = sort {$a cmp $b} @files; |
15616 | 16110 | |
15617 | 16111 | # now case-insensitively |
15618 | 16112 | my @articles = sort {fc($a) cmp fc($b)} @files; |
15619 | 16113 | |
15620 | 16114 | # same thing in reversed order |
15621 | 16115 | my @articles = sort {$b cmp $a} @files; |
15622 | 16116 | |
15623 | 16117 | # sort numerically ascending |
15624 | 16118 | my @articles = sort {$a <=> $b} @files; |
15625 | 16119 | |
15626 | 16120 | # sort numerically descending |
15627 | 16121 | my @articles = sort {$b <=> $a} @files; |
15628 | 16122 | |
15629 | 16123 | # this sorts the %age hash by value instead of key |
15630 | 16124 | # using an in-line function |
15631 | 16125 | my @eldest = sort { $age{$b} <=> $age{$a} } keys %age; |
15632 | 16126 | |
15633 | 16127 | # sort using explicit subroutine name |
15634 | 16128 | sub byage { |
15635 | 16129 | $age{$a} <=> $age{$b}; # presuming numeric |
15636 | 16130 | } |
15637 | 16131 | my @sortedclass = sort byage @class; |
15638 | 16132 | |
15639 | 16133 | sub backwards { $b cmp $a } |
15640 | 16134 | my @harry = qw(dog cat x Cain Abel); |
15641 | 16135 | my @george = qw(gone chased yz Punished Axed); |
15642 | 16136 | print sort @harry; |
15643 | 16137 | # prints AbelCaincatdogx |
15644 | 16138 | print sort backwards @harry; |
15645 | 16139 | # prints xdogcatCainAbel |
15646 | 16140 | print sort @george, 'to', @harry; |
15647 | 16141 | # prints AbelAxedCainPunishedcatchaseddoggonetoxyz |
15648 | 16142 | |
15649 | 16143 | # inefficiently sort by descending numeric compare using |
15650 | 16144 | # the first integer after the first = sign, or the |
15651 | 16145 | # whole record case-insensitively otherwise |
15652 | 16146 | |
15653 | 16147 | my @new = sort { |
15654 | 16148 | ($b =~ /=(\d+)/)[0] <=> ($a =~ /=(\d+)/)[0] |
15655 | 16149 | || |
15656 | 16150 | fc($a) cmp fc($b) |
15657 | 16151 | } @old; |
15658 | 16152 | |
15659 | 16153 | # same thing, but much more efficiently; |
15660 | 16154 | # we'll build auxiliary indices instead |
15661 | 16155 | # for speed |
15662 | 16156 | my (@nums, @caps); |
15663 | 16157 | for (@old) { |
15664 | 16158 | push @nums, ( /=(\d+)/ ? $1 : undef ); |
15665 | 16159 | push @caps, fc($_); |
15666 | 16160 | } |
15667 | 16161 | |
15668 | 16162 | my @new = @old[ sort { |
15669 | 16163 | $nums[$b] <=> $nums[$a] |
15670 | 16164 | || |
15671 | 16165 | $caps[$a] cmp $caps[$b] |
15672 | 16166 | } 0..$#old |
15673 | 16167 | ]; |
15674 | 16168 | |
15675 | 16169 | # same thing, but without any temps |
15676 | 16170 | my @new = map { $_->[0] } |
15677 | 16171 | sort { $b->[1] <=> $a->[1] |
15678 | 16172 | || |
15679 | 16173 | $a->[2] cmp $b->[2] |
15680 | 16174 | } map { [$_, /=(\d+)/, fc($_)] } @old; |
15681 | 16175 | |
15682 | 16176 | # using a prototype allows you to use any comparison subroutine |
15683 | 16177 | # as a sort subroutine (including other package's subroutines) |
15684 | 16178 | package Other; |
15685 | 16179 | sub backwards ($$) { $_[1] cmp $_[0]; } # $a and $b are |
15686 | 16180 | # not set here |
15687 | 16181 | package main; |
15688 | 16182 | my @new = sort Other::backwards @old; |
15689 | 16183 | |
15690 | # guarantee stability | |
16184 | # guarantee stability | |
15691 | 16185 | use sort 'stable'; |
15692 | 16186 | my @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old; |
15693 | 16187 | |
15694 | # force use of mergesort (not portable outside Perl 5.8) | |
15695 | use sort '_mergesort'; # note discouraging _ | |
15696 | my @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old; | |
15697 | ||
15698 | 16188 | =begin original |
15699 | 16189 | |
15700 | 16190 | Warning: syntactical care is required when sorting the list returned from |
15701 | 16191 | a function. If you want to sort the list returned by the function call |
15702 | 16192 | C<find_records(@key)>, you can use: |
15703 | 16193 | |
15704 | 16194 | =end original |
15705 | 16195 | |
15706 | 警告: 関数から | |
16196 | 警告: 関数から返されたリストをソートするときには文法上の注意が必要です。 | |
15707 | 16197 | 関数呼び出し C<find_records(@key)> から返されたリストをソートしたい場合、 |
15708 | 16198 | 以下のように出来ます: |
15709 | 16199 | |
15710 | 16200 | my @contact = sort { $a cmp $b } find_records @key; |
15711 | 16201 | my @contact = sort +find_records(@key); |
15712 | 16202 | my @contact = sort &find_records(@key); |
15713 | 16203 | my @contact = sort(find_records(@key)); |
15714 | 16204 | |
15715 | 16205 | =begin original |
15716 | 16206 | |
15717 | 16207 | If instead you want to sort the array C<@key> with the comparison routine |
15718 | 16208 | C<find_records()> then you can use: |
15719 | 16209 | |
15720 | 16210 | =end original |
15721 | 16211 | |
15722 | 16212 | 一方、配列 C<@key> を比較ルーチン C<find_records()> でソートしたい場合は、 |
15723 | 16213 | 以下のように出来ます: |
15724 | 16214 | |
15725 | 16215 | my @contact = sort { find_records() } @key; |
15726 | 16216 | my @contact = sort find_records(@key); |
15727 | 16217 | my @contact = sort(find_records @key); |
15728 | 16218 | my @contact = sort(find_records (@key)); |
15729 | 16219 | |
15730 | 16220 | =begin original |
15731 | 16221 | |
15732 | 16222 | C<$a> and C<$b> are set as package globals in the package the sort() is |
15733 | 16223 | called from. That means C<$main::a> and C<$main::b> (or C<$::a> and |
15734 | 16224 | C<$::b>) in the C<main> package, C<$FooPack::a> and C<$FooPack::b> in the |
15735 | 16225 | C<FooPack> package, etc. If the sort block is in scope of a C<my> or |
15736 | 16226 | C<state> declaration of C<$a> and/or C<$b>, you I<must> spell out the full |
15737 | 16227 | name of the variables in the sort block : |
15738 | 16228 | |
15739 | 16229 | =end original |
15740 | 16230 | |
15741 | 16231 | C<$a> と C<$b> は、sort() を呼び出したパッケージのパッケージグローバルとして |
15742 | 16232 | 設定されます。 |
15743 | 16233 | つまり、C<main> パッケージの C<$main::a> と C<$main::b> |
15744 | 16234 | (あるいは C<$::a> と C<$::b>) 、 |
15745 | 16235 | C<FooPack> パッケージの C<$FooPack::a> と C<$FooPack::b>、などです。 |
15746 | 16236 | ソートブロックが C<$a> や C<$b> の C<my> または C<state> のスコープ内の場合、 |
15747 | 16237 | ソートブロックの変数の完全名を I<指定しなければなりません>: |
15748 | 16238 | |
15749 | 16239 | package main; |
15750 | 16240 | my $a = "C"; # DANGER, Will Robinson, DANGER !!! |
15751 | 16241 | |
15752 | 16242 | print sort { $a cmp $b } qw(A C E G B D F H); |
15753 | 16243 | # WRONG |
15754 | 16244 | sub badlexi { $a cmp $b } |
15755 | 16245 | print sort badlexi qw(A C E G B D F H); |
15756 | 16246 | # WRONG |
15757 | 16247 | # the above prints BACFEDGH or some other incorrect ordering |
15758 | 16248 | |
15759 | 16249 | print sort { $::a cmp $::b } qw(A C E G B D F H); |
15760 | 16250 | # OK |
15761 | 16251 | print sort { our $a cmp our $b } qw(A C E G B D F H); |
15762 | 16252 | # also OK |
15763 | 16253 | print sort { our ($a, $b); $a cmp $b } qw(A C E G B D F H); |
15764 | 16254 | # also OK |
15765 | 16255 | sub lexi { our $a cmp our $b } |
15766 | 16256 | print sort lexi qw(A C E G B D F H); |
15767 | 16257 | # also OK |
15768 | 16258 | # the above print ABCDEFGH |
15769 | 16259 | |
15770 | 16260 | =begin original |
15771 | 16261 | |
15772 | 16262 | With proper care you may mix package and my (or state) C<$a> and/or C<$b>: |
15773 | 16263 | |
15774 | 16264 | =end original |
15775 | 16265 | |
15776 | 16266 | 適切に注意すれば、パッケージと my (あるいは state) C<$a> や C<$b> を |
15777 | 16267 | 混ぜることができます: |
15778 | 16268 | |
15779 | 16269 | my $a = { |
15780 | 16270 | tiny => -2, |
15781 | 16271 | small => -1, |
15782 | 16272 | normal => 0, |
15783 | 16273 | big => 1, |
15784 | 16274 | huge => 2 |
15785 | 16275 | }; |
15786 | 16276 | |
15787 | 16277 | say sort { $a->{our $a} <=> $a->{our $b} } |
15788 | 16278 | qw{ huge normal tiny small big}; |
15789 | 16279 | |
15790 | 16280 | # prints tinysmallnormalbighuge |
15791 | 16281 | |
15792 | 16282 | =begin original |
15793 | 16283 | |
15794 | C<$a> and C<$b> are implicit | |
16284 | C<$a> and C<$b> are implicitly local to the sort() execution and regain their | |
15795 | 16285 | former values upon completing the sort. |
15796 | 16286 | |
15797 | 16287 | =end original |
15798 | 16288 | |
15799 | 16289 | C<$a> と C<$b> は sort() の実行中は暗黙にローカル化され、ソート終了時に |
15800 | 16290 | 元の値に戻ります。 |
15801 | 16291 | |
15802 | 16292 | =begin original |
15803 | 16293 | |
15804 | 16294 | Sort subroutines written using C<$a> and C<$b> are bound to their calling |
15805 | 16295 | package. It is possible, but of limited interest, to define them in a |
15806 | 16296 | different package, since the subroutine must still refer to the calling |
15807 | 16297 | package's C<$a> and C<$b> : |
15808 | 16298 | |
15809 | 16299 | =end original |
15810 | 16300 | |
15811 | 16301 | C<$a> と C<$b> を使って書かれたソートサブルーチンはその呼び出しパッケージに |
15812 | 16302 | しなければなりません。 |
15813 | 16303 | 異なるパッケージに定義することは可能ですが、 |
15814 | 16304 | これは可能ですが、限られた関心しかありません; |
15815 | 16305 | サブルーチンは呼び出しパッケージの C<$a> と C<$b> を |
15816 | 16306 | 参照しなければならないからです: |
15817 | 16307 | |
15818 | 16308 | package Foo; |
15819 | 16309 | sub lexi { $Bar::a cmp $Bar::b } |
15820 | 16310 | package Bar; |
15821 | 16311 | ... sort Foo::lexi ... |
15822 | 16312 | |
15823 | 16313 | =begin original |
15824 | 16314 | |
15825 | 16315 | Use the prototyped versions (see above) for a more generic alternative. |
15826 | 16316 | |
15827 | 16317 | =end original |
15828 | 16318 | |
15829 | 16319 | より一般的な代替案としては(前述の)プロトタイプ版を使ってください。 |
15830 | 16320 | |
15831 | 16321 | =begin original |
15832 | 16322 | |
15833 | 16323 | The comparison function is required to behave. If it returns |
15834 | 16324 | inconsistent results (sometimes saying C<$x[1]> is less than C<$x[2]> and |
15835 | 16325 | sometimes saying the opposite, for example) the results are not |
15836 | 16326 | well-defined. |
15837 | 16327 | |
15838 | 16328 | =end original |
15839 | 16329 | |
15840 | 16330 | 比較関数は一貫した振る舞いをすることが求められます。 |
15841 | 16331 | 一貫しない結果を返す(例えば、あるときは C<$x[1]> が C<$x[2]> より |
15842 | 16332 | 小さいと返し、またあるときは逆を返す)場合、結果は未定義です。 |
15843 | 16333 | |
15844 | 16334 | =begin original |
15845 | 16335 | |
15846 | 16336 | Because C<< <=> >> returns L<C<undef>|/undef EXPR> when either operand |
15847 | 16337 | is C<NaN> (not-a-number), be careful when sorting with a |
15848 | 16338 | comparison function like C<< $a <=> $b >> any lists that might contain a |
15849 | 16339 | C<NaN>. The following example takes advantage that C<NaN != NaN> to |
15850 | 16340 | eliminate any C<NaN>s from the input list. |
15851 | 16341 | |
15852 | 16342 | =end original |
15853 | 16343 | |
15854 | 16344 | C<< <=> >> はどちらかのオペランドが C<NaN> (not-a-number) のときに |
15855 | 16345 | L<C<undef>|/undef EXPR> を返すので、C<< $a <=> $b >> といった比較関数で |
15856 | 16346 | ソートする場合はリストに C<NaN> が含まれないように注意してください。 |
15857 | 16347 | 以下の例は 入力リストから C<NaN> を取り除くために C<NaN != NaN> という性質を |
15858 | 16348 | 利用しています。 |
15859 | 16349 | |
15860 | 16350 | my @result = sort { $a <=> $b } grep { $_ == $_ } @input; |
15861 | 16351 | |
15862 | 16352 | =item splice ARRAY,OFFSET,LENGTH,LIST |
15863 | 16353 | X<splice> |
15864 | 16354 | |
15865 | 16355 | =item splice ARRAY,OFFSET,LENGTH |
15866 | 16356 | |
15867 | 16357 | =item splice ARRAY,OFFSET |
15868 | 16358 | |
15869 | 16359 | =item splice ARRAY |
15870 | 16360 | |
15871 | 16361 | =for Pod::Functions add or remove elements anywhere in an array |
15872 | 16362 | |
15873 | 16363 | =begin original |
15874 | 16364 | |
15875 | 16365 | Removes the elements designated by OFFSET and LENGTH from an array, and |
15876 | 16366 | replaces them with the elements of LIST, if any. In list context, |
15877 | 16367 | returns the elements removed from the array. In scalar context, |
15878 | 16368 | returns the last element removed, or L<C<undef>|/undef EXPR> if no |
15879 | 16369 | elements are |
15880 | 16370 | removed. The array grows or shrinks as necessary. |
15881 | 16371 | If OFFSET is negative then it starts that far from the end of the array. |
15882 | 16372 | If LENGTH is omitted, removes everything from OFFSET onward. |
15883 | 16373 | If LENGTH is negative, removes the elements from OFFSET onward |
15884 | 16374 | except for -LENGTH elements at the end of the array. |
15885 | 16375 | If both OFFSET and LENGTH are omitted, removes everything. If OFFSET is |
15886 | 16376 | past the end of the array and a LENGTH was provided, Perl issues a warning, |
15887 | 16377 | and splices at the end of the array. |
15888 | 16378 | |
15889 | 16379 | =end original |
15890 | 16380 | |
15891 | 16381 | ARRAY から OFFSET、LENGTH で指定される要素を取り除き、 |
15892 | 16382 | LIST があれば、それを代わりに挿入します。 |
15893 | 16383 | リストコンテキストでは、配列から取り除かれた要素を返します。 |
15894 | 16384 | スカラコンテキストでは、取り除かれた最後の要素を返します; 要素が |
15895 | 16385 | 取り除かれなかった場合は L<C<undef>|/undef EXPR> を返します。 |
15896 | 16386 | 配列は、必要に応じて、大きくなったり、小さくなったりします。 |
15897 | 16387 | OFFSET が負の数の場合は、配列の最後からの距離を示します。 |
15898 | 16388 | LENGTH が省略されると、OFFSET 以降のすべての要素を取り除きます。 |
15899 | 16389 | LENGTH が負の数の場合は、OFFSET から前方へ、配列の最後から -LENGTH 要素を |
15900 | 16390 | 除いて取り除きます。 |
15901 | 16391 | OFFSET と LENGTH の両方が省略されると、全ての要素を取り除きます。 |
15902 | 16392 | OFFSET が配列の最後より後ろで、 LENGTH が指定されていると、Perl は警告を出し、 |
15903 | 16393 | 配列の最後に対して処理します。 |
15904 | 16394 | |
15905 | 16395 | =begin original |
15906 | 16396 | |
15907 | 16397 | The following equivalences hold (assuming C<< $#a >= $i >> ) |
15908 | 16398 | |
15909 | 16399 | =end original |
15910 | 16400 | |
15911 | 16401 | 以下は、(C<< $#a >= $i >> と仮定すると) それぞれ、等価です。 |
15912 | 16402 | |
15913 | 16403 | push(@a,$x,$y) splice(@a,@a,0,$x,$y) |
15914 | 16404 | pop(@a) splice(@a,-1) |
15915 | 16405 | shift(@a) splice(@a,0,1) |
15916 | 16406 | unshift(@a,$x,$y) splice(@a,0,0,$x,$y) |
15917 | 16407 | $a[$i] = $y splice(@a,$i,1,$y) |
15918 | 16408 | |
15919 | 16409 | =begin original |
15920 | 16410 | |
15921 | 16411 | L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> can be used, for example, |
15922 | 16412 | to implement n-ary queue processing: |
15923 | 16413 | |
15924 | 16414 | =end original |
15925 | 16415 | |
15926 | 16416 | L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> は、例えば、n-ary キュー処理の |
15927 | 16417 | 実装に使えます: |
15928 | 16418 | |
15929 | 16419 | sub nary_print { |
15930 | 16420 | my $n = shift; |
15931 | 16421 | while (my @next_n = splice @_, 0, $n) { |
15932 | 16422 | say join q{ -- }, @next_n; |
15933 | 16423 | } |
15934 | 16424 | } |
15935 | 16425 | |
15936 | 16426 | nary_print(3, qw(a b c d e f g h)); |
15937 | 16427 | # prints: |
15938 | 16428 | # a -- b -- c |
15939 | 16429 | # d -- e -- f |
15940 | 16430 | # g -- h |
15941 | 16431 | |
15942 | 16432 | =begin original |
15943 | 16433 | |
15944 | 16434 | Starting with Perl 5.14, an experimental feature allowed |
15945 | 16435 | L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> to take a |
15946 | 16436 | scalar expression. This experiment has been deemed unsuccessful, and was |
15947 | 16437 | removed as of Perl 5.24. |
15948 | 16438 | |
15949 | 16439 | =end original |
15950 | 16440 | |
15951 | 16441 | Perl 5.14 から、L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> がスカラ式を |
15952 | 16442 | 取ることが出来るという実験的機能がありました。 |
15953 | 16443 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 |
15954 | 16444 | |
15955 | 16445 | =item split /PATTERN/,EXPR,LIMIT |
15956 | 16446 | X<split> |
15957 | 16447 | |
15958 | 16448 | =item split /PATTERN/,EXPR |
15959 | 16449 | |
15960 | 16450 | =item split /PATTERN/ |
15961 | 16451 | |
15962 | 16452 | =item split |
15963 | 16453 | |
15964 | 16454 | =for Pod::Functions split up a string using a regexp delimiter |
15965 | 16455 | |
15966 | 16456 | =begin original |
15967 | 16457 | |
15968 | 16458 | Splits the string EXPR into a list of strings and returns the |
15969 | 16459 | list in list context, or the size of the list in scalar context. |
15970 | 16460 | (Prior to Perl 5.11, it also overwrote C<@_> with the list in |
15971 | 16461 | void and scalar context. If you target old perls, beware.) |
15972 | 16462 | |
15973 | 16463 | =end original |
15974 | 16464 | |
15975 | 16465 | 文字列 EXPR を文字列のリストに分割して、リストコンテキストではそのリストを |
15976 | 16466 | 返し、スカラコンテキストではリストの大きさを返します。 |
15977 | 16467 | (Perl 5.11 以前では、無効コンテキストやスカラコンテキストの場合は |
15978 | 16468 | C<@_> をリストで上書きします。 |
15979 | 16469 | もし古い perl を対象にするなら、注意してください。) |
15980 | 16470 | |
15981 | 16471 | =begin original |
15982 | 16472 | |
15983 | 16473 | If only PATTERN is given, EXPR defaults to L<C<$_>|perlvar/$_>. |
15984 | 16474 | |
15985 | 16475 | =end original |
15986 | 16476 | |
15987 | 16477 | PATTERN のみが与えられた場合、EXPR のデフォルトは L<C<$_>|perlvar/$_> です。 |
15988 | 16478 | |
15989 | 16479 | =begin original |
15990 | 16480 | |
15991 | 16481 | Anything in EXPR that matches PATTERN is taken to be a separator |
15992 | 16482 | that separates the EXPR into substrings (called "I<fields>") that |
15993 | 16483 | do B<not> include the separator. Note that a separator may be |
15994 | 16484 | longer than one character or even have no characters at all (the |
15995 | 16485 | empty string, which is a zero-width match). |
15996 | 16486 | |
15997 | 16487 | =end original |
15998 | 16488 | |
15999 | 16489 | EXPR の中で PATTERN にマッチングするものは何でも EXPR を("I<fields>" と |
16000 | 16490 | 呼ばれる)セパレータを B<含まない> 部分文字列に分割するための |
16001 | 16491 | セパレータとなります。 |
16002 | 16492 | セパレータは一文字より長くてもよく、全く文字がなくてもよい(空文字列は |
16003 | 16493 | ゼロ幅マッチングです)ということに注意してください。 |
16004 | 16494 | |
16005 | 16495 | =begin original |
16006 | 16496 | |
16007 | 16497 | The PATTERN need not be constant; an expression may be used |
16008 | 16498 | to specify a pattern that varies at runtime. |
16009 | 16499 | |
16010 | 16500 | =end original |
16011 | 16501 | |
16012 | 16502 | PATTERN は定数である必要はありません; 実行時に変更されるパターンを |
16013 | 16503 | 指定するために式を使えます。 |
16014 | 16504 | |
16015 | 16505 | =begin original |
16016 | 16506 | |
16017 | 16507 | If PATTERN matches the empty string, the EXPR is split at the match |
16018 | 16508 | position (between characters). As an example, the following: |
16019 | 16509 | |
16020 | 16510 | =end original |
16021 | 16511 | |
16022 | 16512 | PATTERN が空文字列にマッチングする場合、EXPR はマッチング位置 |
16023 | 16513 | (文字の間)で分割されます。 |
16024 | 16514 | 例えば、以下のものは: |
16025 | 16515 | |
16026 | 16516 | print join(':', split(/b/, 'abc')), "\n"; |
16027 | 16517 | |
16028 | 16518 | =begin original |
16029 | 16519 | |
16030 | 16520 | uses the C<b> in C<'abc'> as a separator to produce the output C<a:c>. |
16031 | 16521 | However, this: |
16032 | 16522 | |
16033 | 16523 | =end original |
16034 | 16524 | |
16035 | 16525 | C<'abc'> の C<b> をセパレータとして使って出力 C<a:c> を生成します。 |
16036 | 16526 | しかし、これは: |
16037 | 16527 | |
16038 | 16528 | print join(':', split(//, 'abc')), "\n"; |
16039 | 16529 | |
16040 | 16530 | =begin original |
16041 | 16531 | |
16042 | 16532 | uses empty string matches as separators to produce the output |
16043 | 16533 | C<a:b:c>; thus, the empty string may be used to split EXPR into a |
16044 | 16534 | list of its component characters. |
16045 | 16535 | |
16046 | 16536 | =end original |
16047 | 16537 | |
16048 | 16538 | 空文字列マッチングをセパレータとして使って出力 C<a:b:c> を生成します; 従って、 |
16049 | 16539 | 空文字列は EXPR を構成する文字のリストに分割するために使われます。 |
16050 | 16540 | |
16051 | 16541 | =begin original |
16052 | 16542 | |
16053 | 16543 | As a special case for L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>, |
16054 | 16544 | the empty pattern given in |
16055 | 16545 | L<match operator|perlop/"m/PATTERN/msixpodualngc"> syntax (C<//>) |
16056 | 16546 | specifically matches the empty string, which is contrary to its usual |
16057 | 16547 | interpretation as the last successful match. |
16058 | 16548 | |
16059 | 16549 | =end original |
16060 | 16550 | |
16061 | 16551 | L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> の特殊な場合として、 |
16062 | 16552 | L<マッチング演算子|perlop/"m/PATTERN/msixpodualngc"> 文法で与えられた |
16063 | 16553 | 空パターン (C<//>) は特に空文字列にマッチングし、最後に成功した |
16064 | 16554 | マッチングという普通の解釈と異なります。 |
16065 | 16555 | |
16066 | 16556 | =begin original |
16067 | 16557 | |
16068 | 16558 | If PATTERN is C</^/>, then it is treated as if it used the |
16069 | 16559 | L<multiline modifier|perlreref/OPERATORS> (C</^/m>), since it |
16070 | 16560 | isn't much use otherwise. |
16071 | 16561 | |
16072 | 16562 | =end original |
16073 | 16563 | |
16074 | 16564 | PATTERN が C</^/> の場合、L<複数行修飾子|perlreref/OPERATORS> |
16075 | 16565 | (C</^/m>) が使われたかのように扱われます; そうでなければほとんど |
16076 | 16566 | 使えないからです。 |
16077 | 16567 | |
16078 | 16568 | =begin original |
16079 | 16569 | |
16080 | 16570 | C<E<sol>m> and any of the other pattern modifiers valid for C<qr> |
16081 | 16571 | (summarized in L<perlop/qrE<sol>STRINGE<sol>msixpodualn>) may be |
16082 | 16572 | specified explicitly. |
16083 | 16573 | |
16084 | 16574 | =end original |
16085 | 16575 | |
16086 | 16576 | C<qr> で有効な C<E<sol>m> 及びその他のパターン修飾子 |
16087 | 16577 | (L<perlop/qrE<sol>STRINGE<sol>msixpodualn> にまとめられています) は |
16088 | 16578 | 明示的に定義されます。 |
16089 | 16579 | |
16090 | 16580 | =begin original |
16091 | 16581 | |
16092 | 16582 | As another special case, |
16093 | 16583 | L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> emulates the default |
16094 | 16584 | behavior of the |
16095 | 16585 | command line tool B<awk> when the PATTERN is either omitted or a |
16096 | 16586 | string composed of a single space character (such as S<C<' '>> or |
16097 | 16587 | S<C<"\x20">>, but not e.g. S<C</ />>). In this case, any leading |
16098 | 16588 | whitespace in EXPR is removed before splitting occurs, and the PATTERN is |
16099 | 16589 | instead treated as if it were C</\s+/>; in particular, this means that |
16100 | 16590 | I<any> contiguous whitespace (not just a single space character) is used as |
16101 | 16591 | a separator. However, this special treatment can be avoided by specifying |
16102 | 16592 | the pattern S<C</ />> instead of the string S<C<" ">>, thereby allowing |
16103 | 16593 | only a single space character to be a separator. In earlier Perls this |
16104 | 16594 | special case was restricted to the use of a plain S<C<" ">> as the |
16105 | 16595 | pattern argument to split; in Perl 5.18.0 and later this special case is |
16106 | 16596 | triggered by any expression which evaluates to the simple string S<C<" ">>. |
16107 | 16597 | |
16108 | 16598 | =end original |
16109 | 16599 | |
16110 | 16600 | もう一つの特別な場合として、 |
16111 | 16601 | L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> は |
16112 | 16602 | PATTERN が省略されるか単一のスペース文字からなる文字列 (つまり例えば |
16113 | 16603 | S<C</ />> ではなく S<C<' '>> や S<C<"\x20">>) の場合、コマンドラインツール |
16114 | 16604 | B<awk> のデフォルトの振る舞いをエミュレートします。 |
16115 | 16605 | この場合、EXPR の先頭の空白は分割を行う前に削除され、PATTERN は |
16116 | 16606 | C</\s+/> であったかのように扱われます; 特に、これは (単に単一の |
16117 | 16607 | スペース文字ではなく) I<あらゆる> 連続した空白がセパレータとして |
16118 | 16608 | 使われるということです。 |
16119 | 16609 | しかし、この特別の扱いは文字列 S<C<" ">> の代わりにパターン S<C</ />> を |
16120 | 16610 | 指定することで回避でき、それによってセパレータとして単一の |
16121 | 16611 | スペース文字のみが使われます。 |
16122 | 16612 | 以前の Perl ではこの特別な場合は split のパターン引数として単に S<C<" ">> を |
16123 | 16613 | 使った場合に制限されていました; Perl 5.18.0 以降では、この特別な場合は |
16124 | 16614 | 単純な文字列 S<C<" ">> と評価される任意の式によって引き起こされます。 |
16125 | 16615 | |
16126 | 16616 | =begin original |
16127 | 16617 | |
16618 | As of Perl 5.28, this special-cased whitespace splitting works as expected in | |
16619 | the scope of L<< S<C<"use feature 'unicode_strings">>|feature/The | |
16620 | 'unicode_strings' feature >>. In previous versions, and outside the scope of | |
16621 | that feature, it exhibits L<perlunicode/The "Unicode Bug">: characters that are | |
16622 | whitespace according to Unicode rules but not according to ASCII rules can be | |
16623 | treated as part of fields rather than as field separators, depending on the | |
16624 | string's internal encoding. | |
16625 | ||
16626 | =end original | |
16627 | ||
16628 | Perl 5.28 から、この特別な場合の空白分割は | |
16629 | L<< S<C<"use feature 'unicode_strings">>|feature/The | |
16630 | 'unicode_strings' feature >> のスコープの中では想定通りに動作します。 | |
16631 | 以前のバージョンでは、そしてこの機能のスコープの外側では、 | |
16632 | これは L<perlunicode/The "Unicode Bug"> を引き起こします: | |
16633 | Unicode によれば空白だけれども ASCII の規則ではそうではない文字は、 | |
16634 | 文字列の内部エンコーディングに依存して、 | |
16635 | フィールドの区切りではなくフィールドの一部として扱われることがあります。 | |
16636 | ||
16637 | =begin original | |
16638 | ||
16128 | 16639 | If omitted, PATTERN defaults to a single space, S<C<" ">>, triggering |
16129 | 16640 | the previously described I<awk> emulation. |
16130 | 16641 | |
16131 | 16642 | =end original |
16132 | 16643 | |
16133 | 16644 | 省略されると、PATTERN のデフォルトは単一のスペース S<C<" ">> になり、 |
16134 | 16645 | 先に記述した I<awk> エミュレーションを起動します。 |
16135 | 16646 | |
16136 | 16647 | =begin original |
16137 | 16648 | |
16138 | 16649 | If LIMIT is specified and positive, it represents the maximum number |
16139 | 16650 | of fields into which the EXPR may be split; in other words, LIMIT is |
16140 | 16651 | one greater than the maximum number of times EXPR may be split. Thus, |
16141 | 16652 | the LIMIT value C<1> means that EXPR may be split a maximum of zero |
16142 | 16653 | times, producing a maximum of one field (namely, the entire value of |
16143 | 16654 | EXPR). For instance: |
16144 | 16655 | |
16145 | 16656 | =end original |
16146 | 16657 | |
16147 | 16658 | LIMIT が指定された正数の場合、EXPR が分割されるフィールドの最大数を |
16148 | 16659 | 表現します; 言い換えると、 LIMIT は EXPR が分割される数より一つ大きい数です。 |
16149 | 16660 | 従って、LIMIT の値 C<1> は EXPR が最大 0 回分割されるということで、 |
16150 | 16661 | 最大で一つのフィールドを生成します (言い換えると、EXPR 全体の値です)。 |
16151 | 16662 | 例えば: |
16152 | 16663 | |
16153 | 16664 | print join(':', split(//, 'abc', 1)), "\n"; |
16154 | 16665 | |
16155 | 16666 | =begin original |
16156 | 16667 | |
16157 | 16668 | produces the output C<abc>, and this: |
16158 | 16669 | |
16159 | 16670 | =end original |
16160 | 16671 | |
16161 | 16672 | これは C<abc> を出力し、次のものは: |
16162 | 16673 | |
16163 | 16674 | print join(':', split(//, 'abc', 2)), "\n"; |
16164 | 16675 | |
16165 | 16676 | =begin original |
16166 | 16677 | |
16167 | 16678 | produces the output C<a:bc>, and each of these: |
16168 | 16679 | |
16169 | 16680 | =end original |
16170 | 16681 | |
16171 | 16682 | C<a:bc> を出力し、以下のものそれぞれは: |
16172 | 16683 | |
16173 | 16684 | print join(':', split(//, 'abc', 3)), "\n"; |
16174 | 16685 | print join(':', split(//, 'abc', 4)), "\n"; |
16175 | 16686 | |
16176 | 16687 | =begin original |
16177 | 16688 | |
16178 | 16689 | produces the output C<a:b:c>. |
16179 | 16690 | |
16180 | 16691 | =end original |
16181 | 16692 | |
16182 | 16693 | C<a:b:c> を出力します。 |
16183 | 16694 | |
16184 | 16695 | =begin original |
16185 | 16696 | |
16186 | 16697 | If LIMIT is negative, it is treated as if it were instead arbitrarily |
16187 | 16698 | large; as many fields as possible are produced. |
16188 | 16699 | |
16189 | 16700 | =end original |
16190 | 16701 | |
16191 | 16702 | LIMIT が負数なら、非常に大きい数であるかのように扱われます; できるだけ多くの |
16192 | 16703 | フィールドが生成されます。 |
16193 | 16704 | |
16194 | 16705 | =begin original |
16195 | 16706 | |
16196 | 16707 | If LIMIT is omitted (or, equivalently, zero), then it is usually |
16197 | 16708 | treated as if it were instead negative but with the exception that |
16198 | 16709 | trailing empty fields are stripped (empty leading fields are always |
16199 | 16710 | preserved); if all fields are empty, then all fields are considered to |
16200 | 16711 | be trailing (and are thus stripped in this case). Thus, the following: |
16201 | 16712 | |
16202 | 16713 | =end original |
16203 | 16714 | |
16204 | 16715 | LIMIT が省略されると(あるいは等価な 0 なら)、普通は負数が指定されたかのように |
16205 | 16716 | 動作しますが、末尾の空フィールドは取り除かれるという例外があります |
16206 | 16717 | (先頭の空フィールドは常に保存されます); もし全てのフィールドが空なら、 |
16207 | 16718 | 全てのフィールドが末尾として扱われます(そしてこの場合取り除かれます)。 |
16208 | 16719 | 従って、以下のようにすると: |
16209 | 16720 | |
16210 | 16721 | print join(':', split(/,/, 'a,b,c,,,')), "\n"; |
16211 | 16722 | |
16212 | 16723 | =begin original |
16213 | 16724 | |
16214 | 16725 | produces the output C<a:b:c>, but the following: |
16215 | 16726 | |
16216 | 16727 | =end original |
16217 | 16728 | |
16218 | 16729 | 出力 C<a:b:c> を生成しますが、以下のようにすると: |
16219 | 16730 | |
16220 | 16731 | print join(':', split(/,/, 'a,b,c,,,', -1)), "\n"; |
16221 | 16732 | |
16222 | 16733 | =begin original |
16223 | 16734 | |
16224 | 16735 | produces the output C<a:b:c:::>. |
16225 | 16736 | |
16226 | 16737 | =end original |
16227 | 16738 | |
16228 | 16739 | 出力 C<a:b:c:::> を生成します。 |
16229 | 16740 | |
16230 | 16741 | =begin original |
16231 | 16742 | |
16232 | 16743 | In time-critical applications, it is worthwhile to avoid splitting |
16233 | 16744 | into more fields than necessary. Thus, when assigning to a list, |
16234 | 16745 | if LIMIT is omitted (or zero), then LIMIT is treated as though it |
16235 | 16746 | were one larger than the number of variables in the list; for the |
16236 | 16747 | following, LIMIT is implicitly 3: |
16237 | 16748 | |
16238 | 16749 | =end original |
16239 | 16750 | |
16240 | 16751 | 時間に厳しいアプリケーションでは、必要でないフィールドの分割を避けるのは |
16241 | 16752 | 価値があります。 |
16242 | 16753 | 従って、リストに代入される場合に、LIMIT が省略される(または 0)と、 |
16243 | 16754 | LIMIT は リストにある変数の数より一つ大きい数のように扱われます; |
16244 | 16755 | 次の場合、LIMIT は暗黙に 3 になります: |
16245 | 16756 | |
16246 | 16757 | my ($login, $passwd) = split(/:/); |
16247 | 16758 | |
16248 | 16759 | =begin original |
16249 | 16760 | |
16250 | 16761 | Note that splitting an EXPR that evaluates to the empty string always |
16251 | 16762 | produces zero fields, regardless of the LIMIT specified. |
16252 | 16763 | |
16253 | 16764 | =end original |
16254 | 16765 | |
16255 | 16766 | LIMIT の指定に関わらず、空文字列に評価される EXPR を分割すると常に 0 個の |
16256 | 16767 | フィールドを生成することに注意してください。 |
16257 | 16768 | |
16258 | 16769 | =begin original |
16259 | 16770 | |
16260 | 16771 | An empty leading field is produced when there is a positive-width |
16261 | 16772 | match at the beginning of EXPR. For instance: |
16262 | 16773 | |
16263 | 16774 | =end original |
16264 | 16775 | |
16265 | 16776 | EXPR の先頭で正数幅でマッチングしたときには先頭に空のフィールドが |
16266 | 16777 | 生成されます。 |
16267 | 16778 | 例えば: |
16268 | 16779 | |
16269 | 16780 | print join(':', split(/ /, ' abc')), "\n"; |
16270 | 16781 | |
16271 | 16782 | =begin original |
16272 | 16783 | |
16273 | 16784 | produces the output C<:abc>. However, a zero-width match at the |
16274 | 16785 | beginning of EXPR never produces an empty field, so that: |
16275 | 16786 | |
16276 | 16787 | =end original |
16277 | 16788 | |
16278 | 16789 | これは出力 C<:abc> を生成します。 |
16279 | 16790 | しかし、EXPR の先頭でのゼロ幅マッチングは決して空フィールドを生成しないので: |
16280 | 16791 | |
16281 | 16792 | print join(':', split(//, ' abc')); |
16282 | 16793 | |
16283 | 16794 | =begin original |
16284 | 16795 | |
16285 | 16796 | produces the output S<C< :a:b:c>> (rather than S<C<: :a:b:c>>). |
16286 | 16797 | |
16287 | 16798 | =end original |
16288 | 16799 | |
16289 | 16800 | これは(S<C<: :a:b:c>> ではなく)出力 S<C< :a:b:c>> を生成します。 |
16290 | 16801 | |
16291 | 16802 | =begin original |
16292 | 16803 | |
16293 | 16804 | An empty trailing field, on the other hand, is produced when there is a |
16294 | 16805 | match at the end of EXPR, regardless of the length of the match |
16295 | 16806 | (of course, unless a non-zero LIMIT is given explicitly, such fields are |
16296 | 16807 | removed, as in the last example). Thus: |
16297 | 16808 | |
16298 | 16809 | =end original |
16299 | 16810 | |
16300 | 16811 | 一方、末尾の空のフィールドは、マッチングの長さに関わらず、EXPR の末尾で |
16301 | 16812 | マッチングしたときに生成されます(もちろん非 0 の LIMIT が明示的に |
16302 | 16813 | 指定されていない場合です; このようなフィールドは前の例のように |
16303 | 16814 | 取り除かれます)。 |
16304 | 16815 | 従って: |
16305 | 16816 | |
16306 | 16817 | print join(':', split(//, ' abc', -1)), "\n"; |
16307 | 16818 | |
16308 | 16819 | =begin original |
16309 | 16820 | |
16310 | 16821 | produces the output S<C< :a:b:c:>>. |
16311 | 16822 | |
16312 | 16823 | =end original |
16313 | 16824 | |
16314 | 16825 | これは出力 S<C< :a:b:c:>> を生成します。 |
16315 | 16826 | |
16316 | 16827 | =begin original |
16317 | 16828 | |
16318 | 16829 | If the PATTERN contains |
16319 | 16830 | L<capturing groups|perlretut/Grouping things and hierarchical matching>, |
16320 | 16831 | then for each separator, an additional field is produced for each substring |
16321 | 16832 | captured by a group (in the order in which the groups are specified, |
16322 | 16833 | as per L<backreferences|perlretut/Backreferences>); if any group does not |
16323 | 16834 | match, then it captures the L<C<undef>|/undef EXPR> value instead of a |
16324 | 16835 | substring. Also, |
16325 | 16836 | note that any such additional field is produced whenever there is a |
16326 | 16837 | separator (that is, whenever a split occurs), and such an additional field |
16327 | 16838 | does B<not> count towards the LIMIT. Consider the following expressions |
16328 | 16839 | evaluated in list context (each returned list is provided in the associated |
16329 | 16840 | comment): |
16330 | 16841 | |
16331 | 16842 | =end original |
16332 | 16843 | |
16333 | 16844 | PATTERN が |
16334 | 16845 | L<捕捉グループ|perlretut/Grouping things and hierarchical matching> を |
16335 | 16846 | 含んでいる場合、それぞれのセパレータについて、 |
16336 | 16847 | (L<後方参照|perlretut/Backreferences> のようにグループが指定された) |
16337 | 16848 | グループによって捕捉されたそれぞれの部分文字列について追加のフィールドが |
16338 | 16849 | 生成されます; どのグループもマッチングしなかった場合、部分文字列の代わりに |
16339 | 16850 | L<C<undef>|/undef EXPR> 値を捕捉します。 |
16340 | 16851 | また、このような追加のフィールドはセパレータがあるとき(つまり、分割が |
16341 | 16852 | 行われるとき)はいつでも生成され、このような追加のフィールドは |
16342 | 16853 | LIMIT に関してはカウント B<されない> ことに注意してください。 |
16343 | 16854 | リストコンテキストで評価される以下のような式を考えます |
16344 | 16855 | (それぞれの返されるリストは関連づけられたコメントで提供されます): |
16345 | 16856 | |
16346 | 16857 | split(/-|,/, "1-10,20", 3) |
16347 | 16858 | # ('1', '10', '20') |
16348 | 16859 | |
16349 | 16860 | split(/(-|,)/, "1-10,20", 3) |
16350 | 16861 | # ('1', '-', '10', ',', '20') |
16351 | 16862 | |
16352 | 16863 | split(/-|(,)/, "1-10,20", 3) |
16353 | 16864 | # ('1', undef, '10', ',', '20') |
16354 | 16865 | |
16355 | 16866 | split(/(-)|,/, "1-10,20", 3) |
16356 | 16867 | # ('1', '-', '10', undef, '20') |
16357 | 16868 | |
16358 | 16869 | split(/(-)|(,)/, "1-10,20", 3) |
16359 | 16870 | # ('1', '-', undef, '10', undef, ',', '20') |
16360 | 16871 | |
16361 | 16872 | =item sprintf FORMAT, LIST |
16362 | 16873 | X<sprintf> |
16363 | 16874 | |
16364 | 16875 | =for Pod::Functions formatted print into a string |
16365 | 16876 | |
16366 | 16877 | =begin original |
16367 | 16878 | |
16368 | 16879 | Returns a string formatted by the usual |
16369 | 16880 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST> conventions of the C |
16370 | 16881 | library function L<C<sprintf>|/sprintf FORMAT, LIST>. See below for |
16371 | 16882 | more details and see L<sprintf(3)> or L<printf(3)> on your system for an |
16372 | 16883 | explanation of the general principles. |
16373 | 16884 | |
16374 | 16885 | =end original |
16375 | 16886 | |
16376 | 16887 | C ライブラリ関数 L<C<sprintf>|/sprintf FORMAT, LIST> の |
16377 | 16888 | 普通の L<C<printf>|/printf FILEHANDLE FORMAT, LIST> 記法の |
16378 | 16889 | 整形された文字列を返します。 |
16379 | 16890 | 一般的な原則の説明については以下の説明と、システムの |
16380 | 16891 | L<sprintf(3)> または L<printf(3)> の説明を参照してください。 |
16381 | 16892 | |
16382 | 16893 | =begin original |
16383 | 16894 | |
16384 | 16895 | For example: |
16385 | 16896 | |
16386 | 16897 | =end original |
16387 | 16898 | |
16388 | 16899 | 例えば: |
16389 | 16900 | |
16390 | 16901 | # Format number with up to 8 leading zeroes |
16391 | 16902 | my $result = sprintf("%08d", $number); |
16392 | 16903 | |
16393 | 16904 | # Round number to 3 digits after decimal point |
16394 | 16905 | my $rounded = sprintf("%.3f", $number); |
16395 | 16906 | |
16396 | 16907 | =begin original |
16397 | 16908 | |
16398 | 16909 | Perl does its own L<C<sprintf>|/sprintf FORMAT, LIST> formatting: it |
16399 | 16910 | emulates the C |
16400 | 16911 | function L<sprintf(3)>, but doesn't use it except for floating-point |
16401 | 16912 | numbers, and even then only standard modifiers are allowed. |
16402 | 16913 | Non-standard extensions in your local L<sprintf(3)> are |
16403 | 16914 | therefore unavailable from Perl. |
16404 | 16915 | |
16405 | 16916 | =end original |
16406 | 16917 | |
16407 | 16918 | Perl は L<C<sprintf>|/sprintf FORMAT, LIST> フォーマット処理を自力で行います: |
16408 | 16919 | これは C の L<sprintf(3)> 関数をエミュレートしますが、C の関数は使いません |
16409 | 16920 | (浮動小数点を除きますが、それでも標準の記述子のみが利用できます)。 |
16410 | 16921 | 従って、ローカルな非標準の L<sprintf(3)> 拡張機能は Perl では使えません。 |
16411 | 16922 | |
16412 | 16923 | =begin original |
16413 | 16924 | |
16414 | 16925 | Unlike L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, |
16415 | 16926 | L<C<sprintf>|/sprintf FORMAT, LIST> does not do what you probably mean |
16416 | 16927 | when you pass it an array as your first argument. |
16417 | 16928 | The array is given scalar context, |
16418 | 16929 | and instead of using the 0th element of the array as the format, Perl will |
16419 | 16930 | use the count of elements in the array as the format, which is almost never |
16420 | 16931 | useful. |
16421 | 16932 | |
16422 | 16933 | =end original |
16423 | 16934 | |
16424 | 16935 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST> と違って、 |
16425 | 16936 | L<C<sprintf>|/sprintf FORMAT, LIST> の最初の引数に配列を渡しても |
16426 | 16937 | あなたが多分望むとおりには動作しません。 |
16427 | 16938 | 配列はスカラコンテキストで渡されるので、配列の 0 番目の要素ではなく、 |
16428 | 16939 | 配列の要素数をフォーマットとして扱います; これはほとんど役に立ちません。 |
16429 | 16940 | |
16430 | 16941 | =begin original |
16431 | 16942 | |
16432 | 16943 | Perl's L<C<sprintf>|/sprintf FORMAT, LIST> permits the following |
16433 | 16944 | universally-known conversions: |
16434 | 16945 | |
16435 | 16946 | =end original |
16436 | 16947 | |
16437 | 16948 | Perl の L<C<sprintf>|/sprintf FORMAT, LIST> は以下の一般に知られている変換に |
16438 | 16949 | 対応しています: |
16439 | 16950 | |
16440 | 16951 | =begin original |
16441 | 16952 | |
16442 | 16953 | %% a percent sign |
16443 | 16954 | %c a character with the given number |
16444 | 16955 | %s a string |
16445 | 16956 | %d a signed integer, in decimal |
16446 | 16957 | %u an unsigned integer, in decimal |
16447 | 16958 | %o an unsigned integer, in octal |
16448 | 16959 | %x an unsigned integer, in hexadecimal |
16449 | 16960 | %e a floating-point number, in scientific notation |
16450 | 16961 | %f a floating-point number, in fixed decimal notation |
16451 | 16962 | %g a floating-point number, in %e or %f notation |
16452 | 16963 | |
16453 | 16964 | =end original |
16454 | 16965 | |
16455 | 16966 | %% パーセントマーク |
16456 | 16967 | %c 与えられた番号の文字 |
16457 | 16968 | %s 文字列 |
16458 | 16969 | %d 符号付き 10 進数 |
16459 | 16970 | %u 符号なし 10 進数 |
16460 | 16971 | %o 符号なし 8 進数 |
16461 | 16972 | %x 符号なし 16 進数 |
16462 | 16973 | %e 科学的表記の浮動小数点数 |
16463 | 16974 | %f 固定 10 進数表記の浮動小数点数 |
16464 | 16975 | %g %e か %f の表記の浮動小数点数 |
16465 | 16976 | |
16466 | 16977 | =begin original |
16467 | 16978 | |
16468 | 16979 | In addition, Perl permits the following widely-supported conversions: |
16469 | 16980 | |
16470 | 16981 | =end original |
16471 | 16982 | |
16472 | 16983 | さらに、Perl では以下のよく使われている変換に対応しています: |
16473 | 16984 | |
16474 | 16985 | =begin original |
16475 | 16986 | |
16476 | 16987 | %X like %x, but using upper-case letters |
16477 | 16988 | %E like %e, but using an upper-case "E" |
16478 | 16989 | %G like %g, but with an upper-case "E" (if applicable) |
16479 | 16990 | %b an unsigned integer, in binary |
16480 | 16991 | %B like %b, but using an upper-case "B" with the # flag |
16481 | 16992 | %p a pointer (outputs the Perl value's address in hexadecimal) |
16482 | 16993 | %n special: *stores* the number of characters output so far |
16483 | 16994 | into the next argument in the parameter list |
16484 | 16995 | %a hexadecimal floating point |
16485 | 16996 | %A like %a, but using upper-case letters |
16486 | 16997 | |
16487 | 16998 | =end original |
16488 | 16999 | |
16489 | 17000 | %X %x と同様だが大文字を使う |
16490 | 17001 | %E %e と同様だが大文字の "E" を使う |
16491 | 17002 | %G %g と同様だが(適切なら)大文字の "E" を使う |
16492 | 17003 | %b 符号なし 2 進数 |
16493 | 17004 | %B %b と同様だが、# フラグで大文字の "B" を使う |
16494 | 17005 | %p ポインタ (Perl の値のアドレスを 16 進数で出力する) |
16495 | 17006 | %n 特殊: 出力文字数を引数リストの次の変数に「格納」する |
16496 | 17007 | %a 16 進浮動小数点 |
16497 | 17008 | %A %a と同様だが、大文字を使う |
16498 | 17009 | |
16499 | 17010 | =begin original |
16500 | 17011 | |
16501 | 17012 | Finally, for backward (and we do mean "backward") compatibility, Perl |
16502 | 17013 | permits these unnecessary but widely-supported conversions: |
16503 | 17014 | |
16504 | 17015 | =end original |
16505 | 17016 | |
16506 | 17017 | 最後に、過去との互換性(これは「過去」だと考えています)のために、 |
16507 | 17018 | Perl は以下の不要ではあるけれども広く使われている変換に対応しています。 |
16508 | 17019 | |
16509 | 17020 | =begin original |
16510 | 17021 | |
16511 | 17022 | %i a synonym for %d |
16512 | 17023 | %D a synonym for %ld |
16513 | 17024 | %U a synonym for %lu |
16514 | 17025 | %O a synonym for %lo |
16515 | 17026 | %F a synonym for %f |
16516 | 17027 | |
16517 | 17028 | =end original |
16518 | 17029 | |
16519 | 17030 | %i %d の同義語 |
16520 | 17031 | %D %ld の同義語 |
16521 | 17032 | %U %lu の同義語 |
16522 | 17033 | %O %lo の同義語 |
16523 | 17034 | %F %f の同義語 |
16524 | 17035 | |
16525 | 17036 | =begin original |
16526 | 17037 | |
16527 | 17038 | Note that the number of exponent digits in the scientific notation produced |
16528 | 17039 | by C<%e>, C<%E>, C<%g> and C<%G> for numbers with the modulus of the |
16529 | 17040 | exponent less than 100 is system-dependent: it may be three or less |
16530 | 17041 | (zero-padded as necessary). In other words, 1.23 times ten to the |
16531 | 17042 | 99th may be either "1.23e99" or "1.23e099". Similarly for C<%a> and C<%A>: |
16532 | 17043 | the exponent or the hexadecimal digits may float: especially the |
16533 | 17044 | "long doubles" Perl configuration option may cause surprises. |
16534 | 17045 | |
16535 | 17046 | =end original |
16536 | 17047 | |
16537 | 17048 | C<%e>, C<%E>, C<%g>, C<%G> において、指数部が 100 未満の場合の |
16538 | 17049 | 指数部の科学的な表記法はシステム依存であることに注意してください: |
16539 | 17050 | 3 桁かもしれませんし、それ以下かもしれません(必要に応じて 0 で |
16540 | 17051 | パッディングされます)。 |
16541 | 17052 | 言い換えると、 1.23 掛ける 10 の 99 乗は "1.23e99" かもしれませんし |
16542 | 17053 | "1.23e099" かもしれません。 |
16543 | 17054 | 同様に C<%a> と C<%A> の場合: |
16544 | 17055 | 指数部と 16 進数が浮動小数点かもしれません: |
16545 | 17056 | 特に "long doubles" Perl 設定オプションが驚きを引き起こすかもしれません。 |
16546 | 17057 | |
16547 | 17058 | =begin original |
16548 | 17059 | |
16549 | 17060 | Between the C<%> and the format letter, you may specify several |
16550 | 17061 | additional attributes controlling the interpretation of the format. |
16551 | 17062 | In order, these are: |
16552 | 17063 | |
16553 | 17064 | =end original |
16554 | 17065 | |
16555 | 17066 | C<%> とフォーマット文字の間に、フォーマットの解釈を制御するための、 |
16556 | 17067 | いくつかの追加の属性を指定できます。 |
16557 | 17068 | 順番に、以下のものがあります: |
16558 | 17069 | |
16559 | 17070 | =over 4 |
16560 | 17071 | |
16561 | 17072 | =item format parameter index |
16562 | 17073 | |
16563 | 17074 | (フォーマットパラメータインデックス) |
16564 | 17075 | |
16565 | 17076 | =begin original |
16566 | 17077 | |
16567 | 17078 | An explicit format parameter index, such as C<2$>. By default sprintf |
16568 | 17079 | will format the next unused argument in the list, but this allows you |
16569 | 17080 | to take the arguments out of order: |
16570 | 17081 | |
16571 | 17082 | =end original |
16572 | 17083 | |
16573 | 17084 | C<2$> のような明示的なフォーマットパラメータインデックス。 |
16574 | 17085 | デフォルトでは sprintf はリストの次の使われていない引数を |
16575 | 17086 | フォーマットしますが、これによって異なった順番の引数を使えるようにします: |
16576 | 17087 | |
16577 | 17088 | printf '%2$d %1$d', 12, 34; # prints "34 12" |
16578 | 17089 | printf '%3$d %d %1$d', 1, 2, 3; # prints "3 1 1" |
16579 | 17090 | |
16580 | 17091 | =item flags |
16581 | 17092 | |
16582 | 17093 | (フラグ) |
16583 | 17094 | |
16584 | 17095 | =begin original |
16585 | 17096 | |
16586 | 17097 | one or more of: |
16587 | 17098 | |
16588 | 17099 | =end original |
16589 | 17100 | |
16590 | 17101 | 以下のうちの一つまたは複数指定できます: |
16591 | 17102 | |
16592 | 17103 | =begin original |
16593 | 17104 | |
16594 | 17105 | space prefix non-negative number with a space |
16595 | 17106 | + prefix non-negative number with a plus sign |
16596 | 17107 | - left-justify within the field |
16597 | 17108 | 0 use zeros, not spaces, to right-justify |
16598 | 17109 | # ensure the leading "0" for any octal, |
16599 | 17110 | prefix non-zero hexadecimal with "0x" or "0X", |
16600 | 17111 | prefix non-zero binary with "0b" or "0B" |
16601 | 17112 | |
16602 | 17113 | =end original |
16603 | 17114 | |
16604 | 17115 | space 非負数の前に空白をつける |
16605 | 17116 | + 非負数の前にプラス記号をつける |
16606 | 17117 | - フィールド内で左詰めする |
16607 | 17118 | 0 右詰めに空白ではなくゼロを使う |
16608 | 17119 | # 8 進数では確実に先頭に "0" をつける; |
16609 | 17120 | 非 0 の 16 進数では "0x" か "0X" をつける; |
16610 | 17121 | 非 0 の 2 進数では "0b" か "0B" をつける |
16611 | 17122 | |
16612 | 17123 | =begin original |
16613 | 17124 | |
16614 | 17125 | For example: |
16615 | 17126 | |
16616 | 17127 | =end original |
16617 | 17128 | |
16618 | 17129 | 例えば: |
16619 | 17130 | |
16620 | 17131 | printf '<% d>', 12; # prints "< 12>" |
16621 | 17132 | printf '<% d>', 0; # prints "< 0>" |
16622 | 17133 | printf '<% d>', -12; # prints "<-12>" |
16623 | 17134 | printf '<%+d>', 12; # prints "<+12>" |
16624 | 17135 | printf '<%+d>', 0; # prints "<+0>" |
16625 | 17136 | printf '<%+d>', -12; # prints "<-12>" |
16626 | 17137 | printf '<%6s>', 12; # prints "< 12>" |
16627 | 17138 | printf '<%-6s>', 12; # prints "<12 >" |
16628 | 17139 | printf '<%06s>', 12; # prints "<000012>" |
16629 | 17140 | printf '<%#o>', 12; # prints "<014>" |
16630 | 17141 | printf '<%#x>', 12; # prints "<0xc>" |
16631 | 17142 | printf '<%#X>', 12; # prints "<0XC>" |
16632 | 17143 | printf '<%#b>', 12; # prints "<0b1100>" |
16633 | 17144 | printf '<%#B>', 12; # prints "<0B1100>" |
16634 | 17145 | |
16635 | 17146 | =begin original |
16636 | 17147 | |
16637 | 17148 | When a space and a plus sign are given as the flags at once, |
16638 | 17149 | the space is ignored. |
16639 | 17150 | |
16640 | 17151 | =end original |
16641 | 17152 | |
16642 | 17153 | 空白とプラス記号がフラグとして同時に与えられると、 |
16643 | 17154 | 空白は無視されます。 |
16644 | 17155 | |
16645 | 17156 | printf '<%+ d>', 12; # prints "<+12>" |
16646 | 17157 | printf '<% +d>', 12; # prints "<+12>" |
16647 | 17158 | |
16648 | 17159 | =begin original |
16649 | 17160 | |
16650 | 17161 | When the # flag and a precision are given in the %o conversion, |
16651 | 17162 | the precision is incremented if it's necessary for the leading "0". |
16652 | 17163 | |
16653 | 17164 | =end original |
16654 | 17165 | |
16655 | 17166 | %o 変換に # フラグと精度が与えられると、先頭の "0" が必要な場合は |
16656 | 17167 | 精度に 1 が加えられます。 |
16657 | 17168 | |
16658 | 17169 | printf '<%#.5o>', 012; # prints "<00012>" |
16659 | 17170 | printf '<%#.5o>', 012345; # prints "<012345>" |
16660 | 17171 | printf '<%#.0o>', 0; # prints "<0>" |
16661 | 17172 | |
16662 | 17173 | =item vector flag |
16663 | 17174 | |
16664 | 17175 | (ベクタフラグ) |
16665 | 17176 | |
16666 | 17177 | =begin original |
16667 | 17178 | |
16668 | 17179 | This flag tells Perl to interpret the supplied string as a vector of |
16669 | 17180 | integers, one for each character in the string. Perl applies the format to |
16670 | 17181 | each integer in turn, then joins the resulting strings with a separator (a |
16671 | 17182 | dot C<.> by default). This can be useful for displaying ordinal values of |
16672 | 17183 | characters in arbitrary strings: |
16673 | 17184 | |
16674 | 17185 | =end original |
16675 | 17186 | |
16676 | 17187 | このフラグは Perl に、与えられた文字列を、文字毎に一つの整数のベクタとして |
16677 | 17188 | 解釈させます。 |
16678 | 17189 | Perl は各数値をフォーマットし、それから結果の文字列をセパレータ |
16679 | 17190 | (デフォルトでは C<.>)で連結します。 |
16680 | 17191 | これは任意の文字列の文字を順序付きの値として表示するのに便利です: |
16681 | 17192 | |
16682 | 17193 | printf "%vd", "AB\x{100}"; # prints "65.66.256" |
16683 | 17194 | printf "version is v%vd\n", $^V; # Perl's version |
16684 | 17195 | |
16685 | 17196 | =begin original |
16686 | 17197 | |
16687 | 17198 | Put an asterisk C<*> before the C<v> to override the string to |
16688 | 17199 | use to separate the numbers: |
16689 | 17200 | |
16690 | 17201 | =end original |
16691 | 17202 | |
16692 | 17203 | アスタリスク C<*> を C<v> の前に置くと、数値を分けるために使われる文字列を |
16693 | 17204 | 上書きします: |
16694 | 17205 | |
16695 | 17206 | printf "address is %*vX\n", ":", $addr; # IPv6 address |
16696 | 17207 | printf "bits are %0*v8b\n", " ", $bits; # random bitstring |
16697 | 17208 | |
16698 | 17209 | =begin original |
16699 | 17210 | |
16700 | 17211 | You can also explicitly specify the argument number to use for |
16701 | 17212 | the join string using something like C<*2$v>; for example: |
16702 | 17213 | |
16703 | 17214 | =end original |
16704 | 17215 | |
16705 | 17216 | また、C<*2$v> のように、連結する文字列として使う引数の番号を明示的に |
16706 | 17217 | 指定できます; 例えば: |
16707 | 17218 | |
16708 | 17219 | printf '%*4$vX %*4$vX %*4$vX', # 3 IPv6 addresses |
16709 | 17220 | @addr[1..3], ":"; |
16710 | 17221 | |
16711 | 17222 | =item (minimum) width |
16712 | 17223 | |
16713 | 17224 | ((最小)幅) |
16714 | 17225 | |
16715 | 17226 | =begin original |
16716 | 17227 | |
16717 | 17228 | Arguments are usually formatted to be only as wide as required to |
16718 | 17229 | display the given value. You can override the width by putting |
16719 | 17230 | a number here, or get the width from the next argument (with C<*>) |
16720 | 17231 | or from a specified argument (e.g., with C<*2$>): |
16721 | 17232 | |
16722 | 17233 | =end original |
16723 | 17234 | |
16724 | 17235 | 引数は、普通は値を表示するのに必要なちょうどの幅でフォーマットされます。 |
16725 | 17236 | ここに数値を置くか、(C<*> で)次の引数か(C<*2$> で)明示的に指定した引数で |
16726 | 17237 | 幅を上書きできます。 |
16727 | 17238 | |
16728 | 17239 | printf "<%s>", "a"; # prints "<a>" |
16729 | 17240 | printf "<%6s>", "a"; # prints "< a>" |
16730 | 17241 | printf "<%*s>", 6, "a"; # prints "< a>" |
16731 | 17242 | printf '<%*2$s>', "a", 6; # prints "< a>" |
16732 | 17243 | printf "<%2s>", "long"; # prints "<long>" (does not truncate) |
16733 | 17244 | |
16734 | 17245 | =begin original |
16735 | 17246 | |
16736 | 17247 | If a field width obtained through C<*> is negative, it has the same |
16737 | 17248 | effect as the C<-> flag: left-justification. |
16738 | 17249 | |
16739 | 17250 | =end original |
16740 | 17251 | |
16741 | 17252 | C<*> を通して得られたフィールドの値が負数の場合、C<-> フラグと |
16742 | 17253 | 同様の効果 (左詰め) があります。 |
16743 | 17254 | |
16744 | 17255 | =item precision, or maximum width |
16745 | 17256 | X<precision> |
16746 | 17257 | |
16747 | 17258 | (精度あるいは最大幅) |
16748 | 17259 | |
16749 | 17260 | =begin original |
16750 | 17261 | |
16751 | 17262 | You can specify a precision (for numeric conversions) or a maximum |
16752 | 17263 | width (for string conversions) by specifying a C<.> followed by a number. |
16753 | 17264 | For floating-point formats except C<g> and C<G>, this specifies |
16754 | 17265 | how many places right of the decimal point to show (the default being 6). |
16755 | 17266 | For example: |
16756 | 17267 | |
16757 | 17268 | =end original |
16758 | 17269 | |
16759 | 17270 | C<.> の後に数値を指定することで、(数値変換の場合)精度や(文字列変換の場合) |
16760 | 17271 | 最大幅を指定できます。 |
16761 | 17272 | 小数点数フォーマットの場合、C<g> と C<G> を除いて、表示する小数点以下の |
16762 | 17273 | 桁数を指定します(デフォルトは 6 です)。 |
16763 | 17274 | 例えば: |
16764 | 17275 | |
16765 | 17276 | # these examples are subject to system-specific variation |
16766 | 17277 | printf '<%f>', 1; # prints "<1.000000>" |
16767 | 17278 | printf '<%.1f>', 1; # prints "<1.0>" |
16768 | 17279 | printf '<%.0f>', 1; # prints "<1>" |
16769 | 17280 | printf '<%e>', 10; # prints "<1.000000e+01>" |
16770 | 17281 | printf '<%.1e>', 10; # prints "<1.0e+01>" |
16771 | 17282 | |
16772 | 17283 | =begin original |
16773 | 17284 | |
16774 | 17285 | For "g" and "G", this specifies the maximum number of significant digits to |
16775 | 17286 | show; for example: |
16776 | 17287 | |
16777 | 17288 | =end original |
16778 | 17289 | |
16779 | 17290 | "g" と "G" の場合、これは最大有効数字を指定します; 例えば: |
16780 | 17291 | |
16781 | 17292 | # These examples are subject to system-specific variation. |
16782 | 17293 | printf '<%g>', 1; # prints "<1>" |
16783 | 17294 | printf '<%.10g>', 1; # prints "<1>" |
16784 | 17295 | printf '<%g>', 100; # prints "<100>" |
16785 | 17296 | printf '<%.1g>', 100; # prints "<1e+02>" |
16786 | 17297 | printf '<%.2g>', 100.01; # prints "<1e+02>" |
16787 | 17298 | printf '<%.5g>', 100.01; # prints "<100.01>" |
16788 | 17299 | printf '<%.4g>', 100.01; # prints "<100>" |
16789 | 17300 | printf '<%.1g>', 0.0111; # prints "<0.01>" |
16790 | 17301 | printf '<%.2g>', 0.0111; # prints "<0.011>" |
16791 | 17302 | printf '<%.3g>', 0.0111; # prints "<0.0111>" |
16792 | 17303 | |
16793 | 17304 | =begin original |
16794 | 17305 | |
16795 | 17306 | For integer conversions, specifying a precision implies that the |
16796 | 17307 | output of the number itself should be zero-padded to this width, |
16797 | 17308 | where the 0 flag is ignored: |
16798 | 17309 | |
16799 | 17310 | =end original |
16800 | 17311 | |
16801 | 17312 | 整数変換の場合、精度を指定すると、数値自体の出力はこの幅に 0 で |
16802 | 17313 | パッディングするべきであることを暗に示すことになり、0 フラグは |
16803 | 17314 | 無視されます: |
16804 | 17315 | |
16805 | 17316 | printf '<%.6d>', 1; # prints "<000001>" |
16806 | 17317 | printf '<%+.6d>', 1; # prints "<+000001>" |
16807 | 17318 | printf '<%-10.6d>', 1; # prints "<000001 >" |
16808 | 17319 | printf '<%10.6d>', 1; # prints "< 000001>" |
16809 | 17320 | printf '<%010.6d>', 1; # prints "< 000001>" |
16810 | 17321 | printf '<%+10.6d>', 1; # prints "< +000001>" |
16811 | 17322 | |
16812 | 17323 | printf '<%.6x>', 1; # prints "<000001>" |
16813 | 17324 | printf '<%#.6x>', 1; # prints "<0x000001>" |
16814 | 17325 | printf '<%-10.6x>', 1; # prints "<000001 >" |
16815 | 17326 | printf '<%10.6x>', 1; # prints "< 000001>" |
16816 | 17327 | printf '<%010.6x>', 1; # prints "< 000001>" |
16817 | 17328 | printf '<%#10.6x>', 1; # prints "< 0x000001>" |
16818 | 17329 | |
16819 | 17330 | =begin original |
16820 | 17331 | |
16821 | 17332 | For string conversions, specifying a precision truncates the string |
16822 | 17333 | to fit the specified width: |
16823 | 17334 | |
16824 | 17335 | =end original |
16825 | 17336 | |
16826 | 17337 | 文字列変換の場合、精度を指定すると、指定された幅に収まるように文字列を |
16827 | 17338 | 切り詰めます: |
16828 | 17339 | |
16829 | 17340 | printf '<%.5s>', "truncated"; # prints "<trunc>" |
16830 | 17341 | printf '<%10.5s>', "truncated"; # prints "< trunc>" |
16831 | 17342 | |
16832 | 17343 | =begin original |
16833 | 17344 | |
16834 | 17345 | You can also get the precision from the next argument using C<.*>, or from a |
16835 | 17346 | specified argument (e.g., with C<.*2$>): |
16836 | 17347 | |
16837 | 17348 | =end original |
16838 | 17349 | |
16839 | 17350 | C<.*> を使って精度を次の引数から取ったり、 |
16840 | 17351 | (C<.*2$> のように) 指定した引数から取ったりすることもできます: |
16841 | 17352 | |
16842 | 17353 | printf '<%.6x>', 1; # prints "<000001>" |
16843 | 17354 | printf '<%.*x>', 6, 1; # prints "<000001>" |
16844 | 17355 | |
16845 | 17356 | printf '<%.*2$x>', 1, 6; # prints "<000001>" |
16846 | 17357 | |
16847 | 17358 | printf '<%6.*2$x>', 1, 4; # prints "< 0001>" |
16848 | 17359 | |
16849 | 17360 | =begin original |
16850 | 17361 | |
16851 | 17362 | If a precision obtained through C<*> is negative, it counts |
16852 | 17363 | as having no precision at all. |
16853 | 17364 | |
16854 | 17365 | =end original |
16855 | 17366 | |
16856 | 17367 | C<*> によって得られた精度が負数の場合、精度が指定されなかった場合と |
16857 | 17368 | 同じ効果となります。 |
16858 | 17369 | |
16859 | 17370 | printf '<%.*s>', 7, "string"; # prints "<string>" |
16860 | 17371 | printf '<%.*s>', 3, "string"; # prints "<str>" |
16861 | 17372 | printf '<%.*s>', 0, "string"; # prints "<>" |
16862 | 17373 | printf '<%.*s>', -1, "string"; # prints "<string>" |
16863 | 17374 | |
16864 | 17375 | printf '<%.*d>', 1, 0; # prints "<0>" |
16865 | 17376 | printf '<%.*d>', 0, 0; # prints "<>" |
16866 | 17377 | printf '<%.*d>', -1, 0; # prints "<0>" |
16867 | 17378 | |
16868 | 17379 | =item size |
16869 | 17380 | |
16870 | 17381 | (サイズ) |
16871 | 17382 | |
16872 | 17383 | =begin original |
16873 | 17384 | |
16874 | 17385 | For numeric conversions, you can specify the size to interpret the |
16875 | 17386 | number as using C<l>, C<h>, C<V>, C<q>, C<L>, or C<ll>. For integer |
16876 | 17387 | conversions (C<d u o x X b i D U O>), numbers are usually assumed to be |
16877 | 17388 | whatever the default integer size is on your platform (usually 32 or 64 |
16878 | 17389 | bits), but you can override this to use instead one of the standard C types, |
16879 | 17390 | as supported by the compiler used to build Perl: |
16880 | 17391 | |
16881 | 17392 | =end original |
16882 | 17393 | |
16883 | 17394 | 数値変換では、C<l>, C<h>, C<V>, C<q>, C<L>, C<ll> を使って解釈する数値の |
16884 | 17395 | 大きさを指定できます。 |
16885 | 17396 | 整数変換 (C<d u o x X b i D U O>) では、数値は通常プラットフォームの |
16886 | 17397 | デフォルトの整数のサイズ (通常は 32 ビットか 64 ビット) を仮定しますが、 |
16887 | 17398 | これを Perl がビルドされたコンパイラが対応している標準 C の型の一つで |
16888 | 17399 | 上書きできます: |
16889 | 17400 | |
16890 | 17401 | =begin original |
16891 | 17402 | |
16892 | 17403 | hh interpret integer as C type "char" or "unsigned |
16893 | 17404 | char" on Perl 5.14 or later |
16894 | 17405 | h interpret integer as C type "short" or |
16895 | 17406 | "unsigned short" |
16896 | 17407 | j interpret integer as C type "intmax_t" on Perl |
16897 | 5.14 or later | |
17408 | 5.14 or later; and prior to Perl 5.30, only with | |
16898 | (unportable) | |
17409 | a C99 compiler (unportable) | |
16899 | 17410 | l interpret integer as C type "long" or |
16900 | 17411 | "unsigned long" |
16901 | 17412 | q, L, or ll interpret integer as C type "long long", |
16902 | 17413 | "unsigned long long", or "quad" (typically |
16903 | 17414 | 64-bit integers) |
16904 | 17415 | t interpret integer as C type "ptrdiff_t" on Perl |
16905 | 17416 | 5.14 or later |
16906 | z interpret integer as C type "size_t" o | |
17417 | z interpret integer as C types "size_t" or | |
16907 | or later | |
17418 | "ssize_t" on Perl 5.14 or later | |
16908 | 17419 | |
16909 | 17420 | =end original |
16910 | 17421 | |
16911 | 17422 | hh Perl 5.14 以降で整数を C の "char" または "unsigned char" |
16912 | 17423 | 型として解釈する |
16913 | 17424 | h 整数を C の "char" または "unsigned char" 型として解釈する |
16914 | j Perl 5.14 以降 C99 コンパイラのみで整数を | |
17425 | j Perl 5.14 以降 Perl 5.30 以前の C99 コンパイラのみで整数を | |
16915 | 型として解釈する (移植性なし) | |
17426 | C の "intmax_t" 型として解釈する (移植性なし) | |
16916 | 17427 | l 整数を C の "long" または "unsigned long" と解釈する |
16917 | 17428 | h 整数を C の "short" または "unsigned short" と解釈する |
16918 | 17429 | q, L or ll 整数を C の "long long", "unsigned long long", |
16919 | 17430 | "quads"(典型的には 64 ビット整数) のどれかと解釈する |
16920 | 17431 | t Perl 5.14 以降で整数を C の "ptrdiff_t" 型として解釈する |
16921 | z Perl 5.14 以降で整数を C の "size_t" 型 | |
17432 | z Perl 5.14 以降で整数を C の "size_t" 型または "ssize_t" 型 | |
17433 | として解釈する | |
16922 | 17434 | |
16923 | 17435 | =begin original |
16924 | 17436 | |
16925 | 17437 | As of 5.14, none of these raises an exception if they are not supported on |
16926 | 17438 | your platform. However, if warnings are enabled, a warning of the |
16927 | 17439 | L<C<printf>|warnings> warning class is issued on an unsupported |
16928 | 17440 | conversion flag. Should you instead prefer an exception, do this: |
16929 | 17441 | |
16930 | 17442 | =end original |
16931 | 17443 | |
16932 | 17444 | 5.14 から、プラットフォームがこれらに対応していないときでも例外が |
16933 | 17445 | 発生しなくなりました。 |
16934 | 17446 | しかし、もし警告が有効になっているなら、 |
16935 | 17447 | 非対応変換フラグに関して L<C<printf>|warnings> 警告クラスの警告が発生します。 |
16936 | 17448 | 例外の方がお好みなら、以下のようにします: |
16937 | 17449 | |
16938 | 17450 | use warnings FATAL => "printf"; |
16939 | 17451 | |
16940 | 17452 | =begin original |
16941 | 17453 | |
16942 | 17454 | If you would like to know about a version dependency before you |
16943 | 17455 | start running the program, put something like this at its top: |
16944 | 17456 | |
16945 | 17457 | =end original |
16946 | 17458 | |
16947 | 17459 | プログラムの実行開始前にバージョン依存について知りたいなら、先頭に |
16948 | 17460 | 以下のようなものを書きます: |
16949 | 17461 | |
16950 | 17462 | use 5.014; # for hh/j/t/z/ printf modifiers |
16951 | 17463 | |
16952 | 17464 | =begin original |
16953 | 17465 | |
16954 | 17466 | You can find out whether your Perl supports quads via L<Config>: |
16955 | 17467 | |
16956 | 17468 | =end original |
16957 | 17469 | |
16958 | 17470 | Perl が 64 ビット整数に対応しているかどうかは L<Config> を使って |
16959 | 17471 | 調べられます: |
16960 | 17472 | |
16961 | 17473 | use Config; |
16962 | 17474 | if ($Config{use64bitint} eq "define" |
16963 | 17475 | || $Config{longsize} >= 8) { |
16964 | 17476 | print "Nice quads!\n"; |
16965 | 17477 | } |
16966 | 17478 | |
16967 | 17479 | =begin original |
16968 | 17480 | |
16969 | 17481 | For floating-point conversions (C<e f g E F G>), numbers are usually assumed |
16970 | 17482 | to be the default floating-point size on your platform (double or long double), |
16971 | 17483 | but you can force "long double" with C<q>, C<L>, or C<ll> if your |
16972 | 17484 | platform supports them. You can find out whether your Perl supports long |
16973 | 17485 | doubles via L<Config>: |
16974 | 17486 | |
16975 | 17487 | =end original |
16976 | 17488 | |
16977 | 17489 | 浮動小数点数変換 (C<e f g E F G>) では、普通はプラットフォームのデフォルトの |
16978 | 17490 | 不動小数点数のサイズ (double か long double) を仮定しますが、 |
16979 | 17491 | プラットフォームが対応しているなら、C<q>, C<L>, C<ll> に対して |
16980 | 17492 | "long double" を強制できます。 |
16981 | 17493 | Perl が long double に対応しているかどうかは L<Config> を使って |
16982 | 17494 | 調べられます: |
16983 | 17495 | |
16984 | 17496 | use Config; |
16985 | 17497 | print "long doubles\n" if $Config{d_longdbl} eq "define"; |
16986 | 17498 | |
16987 | 17499 | =begin original |
16988 | 17500 | |
16989 | 17501 | You can find out whether Perl considers "long double" to be the default |
16990 | 17502 | floating-point size to use on your platform via L<Config>: |
16991 | 17503 | |
16992 | 17504 | =end original |
16993 | 17505 | |
16994 | 17506 | Perl が "long double" をデフォルトの浮動小数点数として扱っているかどうかは |
16995 | 17507 | L<Config> を使って調べられます: |
16996 | 17508 | |
16997 | 17509 | use Config; |
16998 | 17510 | if ($Config{uselongdouble} eq "define") { |
16999 | 17511 | print "long doubles by default\n"; |
17000 | 17512 | } |
17001 | 17513 | |
17002 | 17514 | =begin original |
17003 | 17515 | |
17004 | 17516 | It can also be that long doubles and doubles are the same thing: |
17005 | 17517 | |
17006 | 17518 | =end original |
17007 | 17519 | |
17008 | 17520 | long double と double が同じ場合もあります: |
17009 | 17521 | |
17010 | 17522 | use Config; |
17011 | 17523 | ($Config{doublesize} == $Config{longdblsize}) && |
17012 | 17524 | print "doubles are long doubles\n"; |
17013 | 17525 | |
17014 | 17526 | =begin original |
17015 | 17527 | |
17016 | 17528 | The size specifier C<V> has no effect for Perl code, but is supported for |
17017 | 17529 | compatibility with XS code. It means "use the standard size for a Perl |
17018 | 17530 | integer or floating-point number", which is the default. |
17019 | 17531 | |
17020 | 17532 | =end original |
17021 | 17533 | |
17022 | 17534 | サイズ指定子 C<V> は Perl のコードには何の影響もありませんが、これは |
17023 | 17535 | XS コードとの互換性のために対応しています。 |
17024 | 17536 | これは「Perl 整数 (または浮動小数点数) として標準的なサイズを使う」ことを |
17025 | 17537 | 意味し、これはデフォルトです。 |
17026 | 17538 | |
17027 | 17539 | =item order of arguments |
17028 | 17540 | |
17029 | 17541 | (引数の順序) |
17030 | 17542 | |
17031 | 17543 | =begin original |
17032 | 17544 | |
17033 | 17545 | Normally, L<C<sprintf>|/sprintf FORMAT, LIST> takes the next unused |
17034 | 17546 | argument as the value to |
17035 | 17547 | format for each format specification. If the format specification |
17036 | 17548 | uses C<*> to require additional arguments, these are consumed from |
17037 | 17549 | the argument list in the order they appear in the format |
17038 | 17550 | specification I<before> the value to format. Where an argument is |
17039 | 17551 | specified by an explicit index, this does not affect the normal |
17040 | 17552 | order for the arguments, even when the explicitly specified index |
17041 | 17553 | would have been the next argument. |
17042 | 17554 | |
17043 | 17555 | =end original |
17044 | 17556 | |
17045 | 17557 | 通常、L<C<sprintf>|/sprintf FORMAT, LIST> は各フォーマット指定について、 |
17046 | 17558 | 使われていない次の引数を |
17047 | 17559 | フォーマットする値として使います。 |
17048 | 17560 | 追加の引数を要求するためにフォーマット指定 C<*> を使うと、 |
17049 | 17561 | これらはフォーマットする値の I<前> のフォーマット指定に現れる順番に |
17050 | 17562 | 引数リストから消費されます。 |
17051 | 17563 | 引数の位置が明示的なインデックスを使って指定された場合、 |
17052 | 17564 | (明示的に指定したインデックスが次の引数の場合でも) |
17053 | 17565 | これは通常の引数の順番に影響を与えません。 |
17054 | 17566 | |
17055 | 17567 | =begin original |
17056 | 17568 | |
17057 | 17569 | So: |
17058 | 17570 | |
17059 | 17571 | =end original |
17060 | 17572 | |
17061 | 17573 | それで: |
17062 | 17574 | |
17063 | 17575 | printf "<%*.*s>", $a, $b, $c; |
17064 | 17576 | |
17065 | 17577 | =begin original |
17066 | 17578 | |
17067 | 17579 | uses C<$a> for the width, C<$b> for the precision, and C<$c> |
17068 | 17580 | as the value to format; while: |
17069 | 17581 | |
17070 | 17582 | =end original |
17071 | 17583 | |
17072 | 17584 | とすると C<$a> を幅に、C<$b> を精度に、C<$c> をフォーマットの値に |
17073 | 17585 | 使います; 一方: |
17074 | 17586 | |
17075 | 17587 | printf '<%*1$.*s>', $a, $b; |
17076 | 17588 | |
17077 | 17589 | =begin original |
17078 | 17590 | |
17079 | 17591 | would use C<$a> for the width and precision, and C<$b> as the |
17080 | 17592 | value to format. |
17081 | 17593 | |
17082 | 17594 | =end original |
17083 | 17595 | |
17084 | 17596 | とすると C<$a> を幅と精度に、C<$b> をフォーマットの値に使います。 |
17085 | 17597 | |
17086 | 17598 | =begin original |
17087 | 17599 | |
17088 | 17600 | Here are some more examples; be aware that when using an explicit |
17089 | 17601 | index, the C<$> may need escaping: |
17090 | 17602 | |
17091 | 17603 | =end original |
17092 | 17604 | |
17093 | 17605 | 以下にさらなる例を示します; 明示的にインデックスを使う場合、C<$> は |
17094 | 17606 | エスケープする必要があることに注意してください: |
17095 | 17607 | |
17096 | 17608 | printf "%2\$d %d\n", 12, 34; # will print "34 12\n" |
17097 | 17609 | printf "%2\$d %d %d\n", 12, 34; # will print "34 12 34\n" |
17098 | 17610 | printf "%3\$d %d %d\n", 12, 34, 56; # will print "56 12 34\n" |
17099 | 17611 | printf "%2\$*3\$d %d\n", 12, 34, 3; # will print " 34 12\n" |
17100 | 17612 | printf "%*1\$.*f\n", 4, 5, 10; # will print "5.0000\n" |
17101 | 17613 | |
17102 | 17614 | =back |
17103 | 17615 | |
17104 | 17616 | =begin original |
17105 | 17617 | |
17106 | 17618 | If L<C<use locale>|locale> (including C<use locale ':not_characters'>) |
17107 | 17619 | is in effect and L<C<POSIX::setlocale>|POSIX/C<setlocale>> has been |
17108 | 17620 | called, |
17109 | 17621 | the character used for the decimal separator in formatted floating-point |
17110 | 17622 | numbers is affected by the C<LC_NUMERIC> locale. See L<perllocale> |
17111 | 17623 | and L<POSIX>. |
17112 | 17624 | |
17113 | 17625 | =end original |
17114 | 17626 | |
17115 | 17627 | (C<use locale ':not_characters'> を含む)L<C<use locale>|locale> が有効で、 |
17116 | 17628 | L<C<POSIX::setlocale>|POSIX/C<setlocale>> が呼び出されている場合、 |
17117 | 17629 | フォーマットされた浮動小数点数の小数点として使われる文字は |
17118 | 17630 | C<LC_NUMERIC> ロケールの影響を受けます。 |
17119 | 17631 | L<perllocale> と L<POSIX> を参照してください。 |
17120 | 17632 | |
17121 | 17633 | =item sqrt EXPR |
17122 | 17634 | X<sqrt> X<root> X<square root> |
17123 | 17635 | |
17124 | 17636 | =item sqrt |
17125 | 17637 | |
17126 | 17638 | =for Pod::Functions square root function |
17127 | 17639 | |
17128 | 17640 | =begin original |
17129 | 17641 | |
17130 | 17642 | Return the positive square root of EXPR. If EXPR is omitted, uses |
17131 | 17643 | L<C<$_>|perlvar/$_>. Works only for non-negative operands unless you've |
17132 | 17644 | loaded the L<C<Math::Complex>|Math::Complex> module. |
17133 | 17645 | |
17134 | 17646 | =end original |
17135 | 17647 | |
17136 | 17648 | EXPR の正の平方根を返します。 |
17137 | 17649 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 |
17138 | 17650 | L<C<Math::Complex>|Math::Complex> モジュールを使わない場合は、負の数の引数は |
17139 | 17651 | 扱えません。 |
17140 | 17652 | |
17141 | 17653 | use Math::Complex; |
17142 | 17654 | print sqrt(-4); # prints 2i |
17143 | 17655 | |
17144 | 17656 | =item srand EXPR |
17145 | 17657 | X<srand> X<seed> X<randseed> |
17146 | 17658 | |
17147 | 17659 | =item srand |
17148 | 17660 | |
17149 | 17661 | =for Pod::Functions seed the random number generator |
17150 | 17662 | |
17151 | 17663 | =begin original |
17152 | 17664 | |
17153 | 17665 | Sets and returns the random number seed for the L<C<rand>|/rand EXPR> |
17154 | 17666 | operator. |
17155 | 17667 | |
17156 | 17668 | =end original |
17157 | 17669 | |
17158 | 17670 | L<C<rand>|/rand EXPR> 演算子のためのシード値を設定して返します。 |
17159 | 17671 | |
17160 | 17672 | =begin original |
17161 | 17673 | |
17162 | 17674 | The point of the function is to "seed" the L<C<rand>|/rand EXPR> |
17163 | 17675 | function so that L<C<rand>|/rand EXPR> can produce a different sequence |
17164 | 17676 | each time you run your program. When called with a parameter, |
17165 | 17677 | L<C<srand>|/srand EXPR> uses that for the seed; otherwise it |
17166 | 17678 | (semi-)randomly chooses a seed. In either case, starting with Perl 5.14, |
17167 | 17679 | it returns the seed. To signal that your code will work I<only> on Perls |
17168 | 17680 | of a recent vintage: |
17169 | 17681 | |
17170 | 17682 | =end original |
17171 | 17683 | |
17172 | 17684 | この関数のポイントは、プログラムを実行するごとに L<C<rand>|/rand EXPR> 関数が |
17173 | 17685 | 異なる乱数列を生成できるように L<C<rand>|/rand EXPR> 関数の「種」を |
17174 | 17686 | 設定することです。 |
17175 | 17687 | L<C<srand>|/srand EXPR> を引数付きで呼び出すと、これを種として使います; |
17176 | 17688 | さもなければ(だいたい)ランダムに種を選びます。 |
17177 | 17689 | どちらの場合でも、Perl 5.14 からは種を返します。 |
17178 | 17690 | 特定の時期の Perl I<でのみ> 動作することを知らせるには以下のようにします: |
17179 | 17691 | |
17180 | 17692 | use 5.014; # so srand returns the seed |
17181 | 17693 | |
17182 | 17694 | =begin original |
17183 | 17695 | |
17184 | 17696 | If L<C<srand>|/srand EXPR> is not called explicitly, it is called |
17185 | 17697 | implicitly without a parameter at the first use of the |
17186 | 17698 | L<C<rand>|/rand EXPR> operator. However, there are a few situations |
17187 | 17699 | where programs are likely to want to call L<C<srand>|/srand EXPR>. One |
17188 | 17700 | is for generating predictable results, generally for testing or |
17189 | 17701 | debugging. There, you use C<srand($seed)>, with the same C<$seed> each |
17190 | 17702 | time. Another case is that you may want to call L<C<srand>|/srand EXPR> |
17191 | 17703 | after a L<C<fork>|/fork> to avoid child processes sharing the same seed |
17192 | 17704 | value as the parent (and consequently each other). |
17193 | 17705 | |
17194 | 17706 | =end original |
17195 | 17707 | |
17196 | 17708 | L<C<srand>|/srand EXPR> が明示的に呼び出されなかった場合、最初に |
17197 | 17709 | L<C<rand>|/rand EXPR> 演算子を使った時点で暗黙に引数なしで呼び出されます。 |
17198 | 17710 | しかし、最近の Perl でプログラムが L<C<srand>|/srand EXPR> を |
17199 | 17711 | 呼び出したいであろう状況がいくつかあります。 |
17200 | 17712 | 一つはテストやデバッグのために予測可能な結果を生成するためです。 |
17201 | 17713 | この場合、C<srand($seed)> (C<$seed> は毎回同じ値を使う) を使います。 |
17202 | 17714 | もう一つの場合としては、子プロセスが親や他の子プロセスと同じ種の値を |
17203 | 17715 | 共有することを避けるために、L<C<fork>|/fork> の後に L<C<srand>|/srand EXPR> を |
17204 | 17716 | 呼び出したいかもしれません。 |
17205 | 17717 | |
17206 | 17718 | =begin original |
17207 | 17719 | |
17208 | 17720 | Do B<not> call C<srand()> (i.e., without an argument) more than once per |
17209 | 17721 | process. The internal state of the random number generator should |
17210 | 17722 | contain more entropy than can be provided by any seed, so calling |
17211 | 17723 | L<C<srand>|/srand EXPR> again actually I<loses> randomness. |
17212 | 17724 | |
17213 | 17725 | =end original |
17214 | 17726 | |
17215 | 17727 | L<C<srand>|/srand EXPR> (引数なし)をプロセス中で複数回 |
17216 | 17728 | 呼び出しては B<いけません>。 |
17217 | 17729 | 乱数生成器の内部状態はどのような種によって提供されるものよりも |
17218 | 17730 | 高いエントロピーを持っているので、C<srand()> を再び呼び出すと |
17219 | 17731 | ランダム性が I<失われます>。 |
17220 | 17732 | |
17221 | 17733 | =begin original |
17222 | 17734 | |
17223 | 17735 | Most implementations of L<C<srand>|/srand EXPR> take an integer and will |
17224 | 17736 | silently |
17225 | 17737 | truncate decimal numbers. This means C<srand(42)> will usually |
17226 | 17738 | produce the same results as C<srand(42.1)>. To be safe, always pass |
17227 | 17739 | L<C<srand>|/srand EXPR> an integer. |
17228 | 17740 | |
17229 | 17741 | =end original |
17230 | 17742 | |
17231 | 17743 | L<C<srand>|/srand EXPR> のほとんどの実装では整数を取り、小数を暗黙に |
17232 | 17744 | 切り捨てます。 |
17233 | 17745 | これは、C<srand(42)> は普通 C<srand(42.1)> と同じ結果になることを意味します。 |
17234 | 17746 | 安全のために、L<C<srand>|/srand EXPR> には常に整数を渡しましょう。 |
17235 | 17747 | |
17236 | 17748 | =begin original |
17237 | 17749 | |
17238 | 17750 | A typical use of the returned seed is for a test program which has too many |
17239 | 17751 | combinations to test comprehensively in the time available to it each run. It |
17240 | 17752 | can test a random subset each time, and should there be a failure, log the seed |
17241 | 17753 | used for that run so that it can later be used to reproduce the same results. |
17242 | 17754 | |
17243 | 17755 | =end original |
17244 | 17756 | |
17245 | 17757 | 返された種の典型的な利用法は、実行毎のテストを利用可能な時間内に完全に |
17246 | 17758 | 行うには組み合わせが多すぎるテストプログラム用です。 |
17247 | 17759 | 毎回ランダムなサブセットをテストし、もし失敗したら、その実行で使った |
17248 | 17760 | 種をログに出力することで、後で同じ結果を再現するために使えます。 |
17249 | 17761 | |
17250 | 17762 | =begin original |
17251 | 17763 | |
17252 | 17764 | B<L<C<rand>|/rand EXPR> is not cryptographically secure. You should not rely |
17253 | 17765 | on it in security-sensitive situations.> As of this writing, a |
17254 | 17766 | number of third-party CPAN modules offer random number generators |
17255 | 17767 | intended by their authors to be cryptographically secure, |
17256 | 17768 | including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>, |
17257 | 17769 | and L<Math::TrulyRandom>. |
17258 | 17770 | |
17259 | 17771 | =end original |
17260 | 17772 | |
17261 | 17773 | B<L<C<rand>|/rand EXPR> は暗号学的に安全ではありません。 |
17262 | 17774 | セキュリティ的に重要な状況でこれに頼るべきではありません。> |
17263 | 17775 | これを書いている時点で、いくつかのサードパーティ CPAN モジュールが |
17264 | 17776 | 作者によって暗号学的に安全であることを目的とした乱数生成器を |
17265 | 17777 | 提供しています: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>, |
17266 | 17778 | L<Math::TrulyRandom> などです。 |
17267 | 17779 | |
17268 | 17780 | =item stat FILEHANDLE |
17269 | 17781 | X<stat> X<file, status> X<ctime> |
17270 | 17782 | |
17271 | 17783 | =item stat EXPR |
17272 | 17784 | |
17273 | 17785 | =item stat DIRHANDLE |
17274 | 17786 | |
17275 | 17787 | =item stat |
17276 | 17788 | |
17277 | 17789 | =for Pod::Functions get a file's status information |
17278 | 17790 | |
17279 | 17791 | =begin original |
17280 | 17792 | |
17281 | 17793 | Returns a 13-element list giving the status info for a file, either |
17282 | 17794 | the file opened via FILEHANDLE or DIRHANDLE, or named by EXPR. If EXPR is |
17283 | 17795 | omitted, it stats L<C<$_>|perlvar/$_> (not C<_>!). Returns the empty |
17284 | 17796 | list if L<C<stat>|/stat FILEHANDLE> fails. Typically |
17285 | 17797 | used as follows: |
17286 | 17798 | |
17287 | 17799 | =end original |
17288 | 17800 | |
17289 | 17801 | FILEHANDLE か DIRHANDLE を通じてオープンされているファイルか、 |
17290 | 17802 | EXPR で指定されるファイルの情報を与える、13 要素のリストを返します。 |
17291 | 17803 | EXPR が省略されると、 L<C<$_>|perlvar/$_> が用いられます |
17292 | 17804 | (C<_> ではありません!)。 |
17293 | 17805 | L<C<stat>|/stat FILEHANDLE> に失敗した場合には、空リストを返します。 |
17294 | 17806 | 普通は、以下のようにして使います: |
17295 | 17807 | |
17296 | 17808 | my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, |
17297 | 17809 | $atime,$mtime,$ctime,$blksize,$blocks) |
17298 | 17810 | = stat($filename); |
17299 | 17811 | |
17300 | 17812 | =begin original |
17301 | 17813 | |
17302 | 17814 | Not all fields are supported on all filesystem types. Here are the |
17303 | 17815 | meanings of the fields: |
17304 | 17816 | |
17305 | 17817 | =end original |
17306 | 17818 | |
17307 | 17819 | 全てのファイルシステムで全てのフィールドに対応しているわけではありません。 |
17308 | 17820 | フィールドの意味は以下の通りです。 |
17309 | 17821 | |
17310 | 17822 | =begin original |
17311 | 17823 | |
17312 | 17824 | 0 dev device number of filesystem |
17313 | 17825 | 1 ino inode number |
17314 | 17826 | 2 mode file mode (type and permissions) |
17315 | 17827 | 3 nlink number of (hard) links to the file |
17316 | 17828 | 4 uid numeric user ID of file's owner |
17317 | 17829 | 5 gid numeric group ID of file's owner |
17318 | 17830 | 6 rdev the device identifier (special files only) |
17319 | 17831 | 7 size total size of file, in bytes |
17320 | 17832 | 8 atime last access time in seconds since the epoch |
17321 | 17833 | 9 mtime last modify time in seconds since the epoch |
17322 | 17834 | 10 ctime inode change time in seconds since the epoch (*) |
17323 | 17835 | 11 blksize preferred I/O size in bytes for interacting with the |
17324 | 17836 | file (may vary from file to file) |
17325 | 17837 | 12 blocks actual number of system-specific blocks allocated |
17326 | 17838 | on disk (often, but not always, 512 bytes each) |
17327 | 17839 | |
17328 | 17840 | =end original |
17329 | 17841 | |
17330 | 17842 | 0 dev ファイルシステムのデバイス番号 |
17331 | 17843 | 1 ino inode 番号 |
17332 | 17844 | 2 mode ファイルモード (タイプとパーミッション) |
17333 | 17845 | 3 nlink ファイルへの(ハード)リンクの数 |
17334 | 17846 | 4 uid ファイル所有者のユーザー ID の数値 |
17335 | 17847 | 5 gid ファイル所有者のグループ ID の数値 |
17336 | 17848 | 6 rdev デバイス識別子(特殊ファイルのみ) |
17337 | 17849 | 7 size ファイルサイズ(バイト単位) |
17338 | 17850 | 8 atime 紀元から、最後にアクセスされた時刻までの秒数 |
17339 | 17851 | 9 mtime 紀元から、最後に修正(modify)された時刻までの秒数 |
17340 | 17852 | 10 ctime 紀元から、inode 変更(change)された時刻までの秒数 (*) |
17341 | 17853 | 11 blksize ファイルとの相互作用のために適した I/O バイト数 |
17342 | 17854 | (ファイルごとに異なるかもしれない) |
17343 | 17855 | 12 blocks ディスクに割り当てたシステム依存のブロック(常にでは |
17344 | 17856 | ありませんがたいていはそれぞれ 512 バイト)の数 |
17345 | 17857 | |
17346 | 17858 | =begin original |
17347 | 17859 | |
17348 | 17860 | (The epoch was at 00:00 January 1, 1970 GMT.) |
17349 | 17861 | |
17350 | 17862 | =end original |
17351 | 17863 | |
17352 | 17864 | (紀元は GMT で 1970/01/01 00:00:00。) |
17353 | 17865 | |
17354 | 17866 | =begin original |
17355 | 17867 | |
17356 | 17868 | (*) Not all fields are supported on all filesystem types. Notably, the |
17357 | 17869 | ctime field is non-portable. In particular, you cannot expect it to be a |
17358 | 17870 | "creation time"; see L<perlport/"Files and Filesystems"> for details. |
17359 | 17871 | |
17360 | 17872 | =end original |
17361 | 17873 | |
17362 | 17874 | (*) 全てのフィールドが全てのファイルシステムタイプで対応しているわけでは |
17363 | 17875 | ありません。 |
17364 | 17876 | 明らかに、ctime のフィールドは移植性がありません。 |
17365 | 17877 | 特に、これから「作成時刻」を想定することは出来ません; |
17366 | 17878 | 詳細については L<perlport/"Files and Filesystems"> を参照してください。 |
17367 | 17879 | |
17368 | 17880 | =begin original |
17369 | 17881 | |
17370 | 17882 | If L<C<stat>|/stat FILEHANDLE> is passed the special filehandle |
17371 | 17883 | consisting of an underline, no stat is done, but the current contents of |
17372 | 17884 | the stat structure from the last L<C<stat>|/stat FILEHANDLE>, |
17373 | 17885 | L<C<lstat>|/lstat FILEHANDLE>, or filetest are returned. Example: |
17374 | 17886 | |
17375 | 17887 | =end original |
17376 | 17888 | |
17377 | 17889 | 下線だけの _ という特別なファイルハンドルを L<C<stat>|/stat FILEHANDLE> に |
17378 | 17890 | 渡すと、実際には stat を行なわず、stat 構造体に残っている |
17379 | 17891 | 前回の L<C<stat>|/stat FILEHANDLE>, L<C<lstat>|/lstat FILEHANDLE> や |
17380 | 17892 | ファイルテストの情報が返されます。 |
17381 | 17893 | 例: |
17382 | 17894 | |
17383 | 17895 | if (-x $file && (($d) = stat(_)) && $d < 0) { |
17384 | 17896 | print "$file is executable NFS file\n"; |
17385 | 17897 | } |
17386 | 17898 | |
17387 | 17899 | =begin original |
17388 | 17900 | |
17389 | 17901 | (This works on machines only for which the device number is negative |
17390 | 17902 | under NFS.) |
17391 | 17903 | |
17392 | 17904 | =end original |
17393 | 17905 | |
17394 | 17906 | (これは、NFS のもとでデバイス番号が負になるマシンでのみ動作します。) |
17395 | 17907 | |
17396 | 17908 | =begin original |
17397 | 17909 | |
17910 | On some platforms inode numbers are of a type larger than perl knows how | |
17911 | to handle as integer numerical values. If necessary, an inode number will | |
17912 | be returned as a decimal string in order to preserve the entire value. | |
17913 | If used in a numeric context, this will be converted to a floating-point | |
17914 | numerical value, with rounding, a fate that is best avoided. Therefore, | |
17915 | you should prefer to compare inode numbers using C<eq> rather than C<==>. | |
17916 | C<eq> will work fine on inode numbers that are represented numerically, | |
17917 | as well as those represented as strings. | |
17918 | ||
17919 | =end original | |
17920 | ||
17921 | 一部のプラットフォームでは、inode 番号は perl が整数値として | |
17922 | 扱い方を知っているものよりも大きい型になっています。 | |
17923 | もし必要なら、inode 番号は、値全体を保存するために 10 進文字列として | |
17924 | 返されます。 | |
17925 | 数値コンテキストで使うと、これは丸めを伴う浮動小数点数に変換され、 | |
17926 | できるだけ避けるべき結果になります。 | |
17927 | 従って、inode 番号の比較には C<==> ではなく C<eq> を使うべきです。 | |
17928 | C<eq> は、inode 番号が数値で表現されていても、文字列で表現されていても | |
17929 | うまく動作します。 | |
17930 | ||
17931 | =begin original | |
17932 | ||
17398 | 17933 | Because the mode contains both the file type and its permissions, you |
17399 | 17934 | should mask off the file type portion and (s)printf using a C<"%o"> |
17400 | 17935 | if you want to see the real permissions. |
17401 | 17936 | |
17402 | 17937 | =end original |
17403 | 17938 | |
17404 | 17939 | モードにはファイルタイプとその権限の両方が含まれているので、 |
17405 | 17940 | 本当の権限を見たい場合は、(s)printf で C<"%"> を使うことで |
17406 | 17941 | ファイルタイプをマスクするべきです。 |
17407 | 17942 | |
17408 | 17943 | my $mode = (stat($filename))[2]; |
17409 | 17944 | printf "Permissions are %04o\n", $mode & 07777; |
17410 | 17945 | |
17411 | 17946 | =begin original |
17412 | 17947 | |
17413 | 17948 | In scalar context, L<C<stat>|/stat FILEHANDLE> returns a boolean value |
17414 | 17949 | indicating success |
17415 | 17950 | or failure, and, if successful, sets the information associated with |
17416 | 17951 | the special filehandle C<_>. |
17417 | 17952 | |
17418 | 17953 | =end original |
17419 | 17954 | |
17420 | 17955 | スカラコンテキストでは、L<C<stat>|/stat FILEHANDLE> は成功か失敗を表す真偽値を |
17421 | 17956 | 返し、成功した場合は、特別なファイルハンドル C<_> に結び付けられた |
17422 | 17957 | 情報をセットします。 |
17423 | 17958 | |
17424 | 17959 | =begin original |
17425 | 17960 | |
17426 | 17961 | The L<File::stat> module provides a convenient, by-name access mechanism: |
17427 | 17962 | |
17428 | 17963 | =end original |
17429 | 17964 | |
17430 | 17965 | L<File::stat> モジュールは、便利な名前によるアクセス機構を提供します。 |
17431 | 17966 | |
17432 | 17967 | use File::stat; |
17433 | 17968 | my $sb = stat($filename); |
17434 | 17969 | printf "File is %s, size is %s, perm %04o, mtime %s\n", |
17435 | 17970 | $filename, $sb->size, $sb->mode & 07777, |
17436 | 17971 | scalar localtime $sb->mtime; |
17437 | 17972 | |
17438 | 17973 | =begin original |
17439 | 17974 | |
17440 | 17975 | You can import symbolic mode constants (C<S_IF*>) and functions |
17441 | 17976 | (C<S_IS*>) from the L<Fcntl> module: |
17442 | 17977 | |
17443 | 17978 | =end original |
17444 | 17979 | |
17445 | 17980 | モード定数 (C<S_IF*>) と関数 (C<S_IS*>) を L<Fcntl> モジュールから |
17446 | 17981 | インポートできます。 |
17447 | 17982 | |
17448 | 17983 | use Fcntl ':mode'; |
17449 | 17984 | |
17450 | 17985 | my $mode = (stat($filename))[2]; |
17451 | 17986 | |
17452 | 17987 | my $user_rwx = ($mode & S_IRWXU) >> 6; |
17453 | 17988 | my $group_read = ($mode & S_IRGRP) >> 3; |
17454 | 17989 | my $other_execute = $mode & S_IXOTH; |
17455 | 17990 | |
17456 | 17991 | printf "Permissions are %04o\n", S_IMODE($mode), "\n"; |
17457 | 17992 | |
17458 | 17993 | my $is_setuid = $mode & S_ISUID; |
17459 | 17994 | my $is_directory = S_ISDIR($mode); |
17460 | 17995 | |
17461 | 17996 | =begin original |
17462 | 17997 | |
17463 | 17998 | You could write the last two using the C<-u> and C<-d> operators. |
17464 | 17999 | Commonly available C<S_IF*> constants are: |
17465 | 18000 | |
17466 | 18001 | =end original |
17467 | 18002 | |
17468 | 18003 | 最後の二つは C<-u> と C<-d> 演算子を使っても書けます。 |
17469 | 18004 | 一般に利用可能な C<S_IF*> 定数は以下のものです。 |
17470 | 18005 | |
17471 | 18006 | # Permissions: read, write, execute, for user, group, others. |
17472 | 18007 | |
17473 | 18008 | S_IRWXU S_IRUSR S_IWUSR S_IXUSR |
17474 | 18009 | S_IRWXG S_IRGRP S_IWGRP S_IXGRP |
17475 | 18010 | S_IRWXO S_IROTH S_IWOTH S_IXOTH |
17476 | 18011 | |
17477 | 18012 | # Setuid/Setgid/Stickiness/SaveText. |
17478 | 18013 | # Note that the exact meaning of these is system-dependent. |
17479 | 18014 | |
17480 | 18015 | S_ISUID S_ISGID S_ISVTX S_ISTXT |
17481 | 18016 | |
17482 | 18017 | # File types. Not all are necessarily available on |
17483 | 18018 | # your system. |
17484 | 18019 | |
17485 | 18020 | S_IFREG S_IFDIR S_IFLNK S_IFBLK S_IFCHR |
17486 | 18021 | S_IFIFO S_IFSOCK S_IFWHT S_ENFMT |
17487 | 18022 | |
17488 | 18023 | # The following are compatibility aliases for S_IRUSR, |
17489 | 18024 | # S_IWUSR, and S_IXUSR. |
17490 | 18025 | |
17491 | 18026 | S_IREAD S_IWRITE S_IEXEC |
17492 | 18027 | |
17493 | 18028 | =begin original |
17494 | 18029 | |
17495 | 18030 | and the C<S_IF*> functions are |
17496 | 18031 | |
17497 | 18032 | =end original |
17498 | 18033 | |
17499 | 18034 | 一般に利用可能な C<S_IF*> 関数は以下のものです。 |
17500 | 18035 | |
17501 | 18036 | S_IMODE($mode) the part of $mode containing the permission |
17502 | 18037 | bits and the setuid/setgid/sticky bits |
17503 | 18038 | |
17504 | 18039 | S_IFMT($mode) the part of $mode containing the file type |
17505 | 18040 | which can be bit-anded with (for example) |
17506 | 18041 | S_IFREG or with the following functions |
17507 | 18042 | |
17508 | 18043 | # The operators -f, -d, -l, -b, -c, -p, and -S. |
17509 | 18044 | |
17510 | 18045 | S_ISREG($mode) S_ISDIR($mode) S_ISLNK($mode) |
17511 | 18046 | S_ISBLK($mode) S_ISCHR($mode) S_ISFIFO($mode) S_ISSOCK($mode) |
17512 | 18047 | |
17513 | 18048 | # No direct -X operator counterpart, but for the first one |
17514 | 18049 | # the -g operator is often equivalent. The ENFMT stands for |
17515 | 18050 | # record flocking enforcement, a platform-dependent feature. |
17516 | 18051 | |
17517 | 18052 | S_ISENFMT($mode) S_ISWHT($mode) |
17518 | 18053 | |
17519 | 18054 | =begin original |
17520 | 18055 | |
17521 | 18056 | See your native L<chmod(2)> and L<stat(2)> documentation for more details |
17522 | 18057 | about the C<S_*> constants. To get status info for a symbolic link |
17523 | 18058 | instead of the target file behind the link, use the |
17524 | 18059 | L<C<lstat>|/lstat FILEHANDLE> function. |
17525 | 18060 | |
17526 | 18061 | =end original |
17527 | 18062 | |
17528 | 18063 | C<S_*> 定数に関する詳細についてはネイティブの L<chmod(2)> と L<stat(2)> の |
17529 | 18064 | ドキュメントを参照してください。 |
17530 | 18065 | リンクの先にあるファイルではなく、シンボリックリンクそのものの情報を |
17531 | 18066 | 得たい場合は、L<C<lstat>|/lstat FILEHANDLE> 関数を使ってください。 |
17532 | 18067 | |
17533 | 18068 | =begin original |
17534 | 18069 | |
17535 | 18070 | Portability issues: L<perlport/stat>. |
17536 | 18071 | |
17537 | 18072 | =end original |
17538 | 18073 | |
17539 | 18074 | 移植性の問題: L<perlport/stat>。 |
17540 | 18075 | |
17541 | 18076 | =item state VARLIST |
17542 | 18077 | X<state> |
17543 | 18078 | |
17544 | 18079 | =item state TYPE VARLIST |
17545 | 18080 | |
17546 | 18081 | =item state VARLIST : ATTRS |
17547 | 18082 | |
17548 | 18083 | =item state TYPE VARLIST : ATTRS |
17549 | 18084 | |
17550 | 18085 | =for Pod::Functions +state declare and assign a persistent lexical variable |
17551 | 18086 | |
17552 | 18087 | =begin original |
17553 | 18088 | |
17554 | 18089 | L<C<state>|/state VARLIST> declares a lexically scoped variable, just |
17555 | 18090 | like L<C<my>|/my VARLIST>. |
17556 | 18091 | However, those variables will never be reinitialized, contrary to |
17557 | 18092 | lexical variables that are reinitialized each time their enclosing block |
17558 | 18093 | is entered. |
17559 | 18094 | See L<perlsub/"Persistent Private Variables"> for details. |
17560 | 18095 | |
17561 | 18096 | =end original |
17562 | 18097 | |
17563 | 18098 | L<C<state>|/state VARLIST> はちょうど L<C<my>|/my VARLIST> と同様に、 |
17564 | 18099 | レキシカルなスコープの変数を宣言します。 |
17565 | 18100 | しかし、レキシカル変数がブロックに入る毎に再初期化されるのと異なり、 |
17566 | 18101 | この変数は決して再初期化されません。 |
17567 | 18102 | 詳しくは L<perlsub/"Persistent Private Variables"> を参照してください。 |
17568 | 18103 | |
17569 | 18104 | =begin original |
17570 | 18105 | |
17571 | 18106 | If more than one variable is listed, the list must be placed in |
17572 | 18107 | parentheses. With a parenthesised list, L<C<undef>|/undef EXPR> can be |
17573 | 18108 | used as a |
17574 | 18109 | dummy placeholder. However, since initialization of state variables in |
17575 | list | |
18110 | such lists is currently not possible this would serve no purpose. | |
17576 | 18111 | |
17577 | 18112 | =end original |
17578 | 18113 | |
17579 | 18114 | 複数の変数を指定する場合、かっこで囲まなければなりません。 |
17580 | 18115 | かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> はダミーの |
17581 | 18116 | プレースホルダとして使えます。 |
17582 | しかし、リ | |
18117 | しかし、そのようなリストでの state 変数の初期化は現在のところできないので、 | |
17583 | 18118 | これは無意味です。 |
17584 | 18119 | |
17585 | 18120 | =begin original |
17586 | 18121 | |
17587 | 18122 | L<C<state>|/state VARLIST> is available only if the |
17588 | 18123 | L<C<"state"> feature|feature/The 'state' feature> is enabled or if it is |
17589 | 18124 | prefixed with C<CORE::>. The |
17590 | 18125 | L<C<"state"> feature|feature/The 'state' feature> is enabled |
17591 | 18126 | automatically with a C<use v5.10> (or higher) declaration in the current |
17592 | 18127 | scope. |
17593 | 18128 | |
17594 | 18129 | =end original |
17595 | 18130 | |
17596 | 18131 | L<C<state>|/state VARLIST> は |
17597 | 18132 | L<C<"state"> 機能|feature/The 'state' feature> が有効か C<CORE::> を |
17598 | 18133 | 前置した場合にのみ利用可能です。 |
17599 | 18134 | L<C<"state"> 機能|feature/The 'state' feature> は現在のスコープで |
17600 | 18135 | C<use v5.10> (またはそれ以上) を宣言した場合自動的に有効になります。 |
17601 | 18136 | |
17602 | 18137 | =item study SCALAR |
17603 | 18138 | X<study> |
17604 | 18139 | |
17605 | 18140 | =item study |
17606 | 18141 | |
17607 | 18142 | =for Pod::Functions no-op, formerly optimized input data for repeated searches |
17608 | 18143 | |
17609 | 18144 | =begin original |
17610 | 18145 | |
17611 | 18146 | At this time, C<study> does nothing. This may change in the future. |
17612 | 18147 | |
17613 | 18148 | =end original |
17614 | 18149 | |
17615 | 18150 | 現時点では、C<study> は何もしません。 |
17616 | 18151 | これは将来変更されるかもしれません。 |
17617 | 18152 | |
17618 | 18153 | =begin original |
17619 | 18154 | |
17620 | 18155 | Prior to Perl version 5.16, it would create an inverted index of all characters |
17621 | 18156 | that occurred in the given SCALAR (or L<C<$_>|perlvar/$_> if unspecified). When |
17622 | 18157 | matching a pattern, the rarest character from the pattern would be looked up in |
17623 | 18158 | this index. Rarity was based on some static frequency tables constructed from |
17624 | 18159 | some C programs and English text. |
17625 | 18160 | |
17626 | 18161 | =end original |
17627 | 18162 | |
17628 | 18163 | Perl バージョン 5.16 より前では、 |
17629 | 18164 | 与えられた SCALAR (または指定されていなかった場合は L<C<$_>|perlvar/$_>)に |
17630 | 18165 | 現れた全ての文字の転置インデックスを作ります。 |
17631 | 18166 | パターンにマッチングしたとき、 |
17632 | 18167 | パターン中の最も頻度の少ない文字がこのインデックスから探されます。 |
17633 | 18168 | 頻度は、C プログラムと英語の文章から構築された静的頻度テーブルを |
17634 | 18169 | 基にしています。 |
17635 | 18170 | |
17636 | 18171 | =item sub NAME BLOCK |
17637 | 18172 | X<sub> |
17638 | 18173 | |
17639 | 18174 | =item sub NAME (PROTO) BLOCK |
17640 | 18175 | |
17641 | 18176 | =item sub NAME : ATTRS BLOCK |
17642 | 18177 | |
17643 | 18178 | =item sub NAME (PROTO) : ATTRS BLOCK |
17644 | 18179 | |
17645 | 18180 | =for Pod::Functions declare a subroutine, possibly anonymously |
17646 | 18181 | |
17647 | 18182 | =begin original |
17648 | 18183 | |
17649 | 18184 | This is subroutine definition, not a real function I<per se>. Without a |
17650 | 18185 | BLOCK it's just a forward declaration. Without a NAME, it's an anonymous |
17651 | 18186 | function declaration, so does return a value: the CODE ref of the closure |
17652 | 18187 | just created. |
17653 | 18188 | |
17654 | 18189 | =end original |
17655 | 18190 | |
17656 | 18191 | これはサブルーチン定義であり、I<本質的には> 実際の関数ではありません。 |
17657 | 18192 | BLOCK なしの場合、これは単に前方宣言です。 |
17658 | 18193 | NAME なしの場合は、無名関数定義であり、値(作成したブロックの |
17659 | 18194 | コードリファレンス)を返します: 単にクロージャの CODE リファレンスが |
17660 | 18195 | 作成されます。 |
17661 | 18196 | |
17662 | 18197 | =begin original |
17663 | 18198 | |
17664 | 18199 | See L<perlsub> and L<perlref> for details about subroutines and |
17665 | 18200 | references; see L<attributes> and L<Attribute::Handlers> for more |
17666 | 18201 | information about attributes. |
17667 | 18202 | |
17668 | 18203 | =end original |
17669 | 18204 | |
17670 | 18205 | サブルーチンとリファレンスに関する詳細については、L<perlsub> と |
17671 | 18206 | L<perlref> を参照してください; 属性に関する更なる情報については |
17672 | 18207 | L<attributes> と L<Attribute::Handlers> を参照してください。 |
17673 | 18208 | |
17674 | 18209 | =item __SUB__ |
17675 | 18210 | X<__SUB__> |
17676 | 18211 | |
17677 | 18212 | =for Pod::Functions +current_sub the current subroutine, or C<undef> if not in a subroutine |
17678 | 18213 | |
17679 | 18214 | =begin original |
17680 | 18215 | |
17681 | 18216 | A special token that returns a reference to the current subroutine, or |
17682 | 18217 | L<C<undef>|/undef EXPR> outside of a subroutine. |
17683 | 18218 | |
17684 | 18219 | =end original |
17685 | 18220 | |
17686 | 18221 | 現在のサブルーチンのリファレンスを返す特殊トークン; サブルーチンの外側では |
17687 | 18222 | L<C<undef>|/undef EXPR>。 |
17688 | 18223 | |
17689 | 18224 | =begin original |
17690 | 18225 | |
17691 | 18226 | The behaviour of L<C<__SUB__>|/__SUB__> within a regex code block (such |
17692 | 18227 | as C</(?{...})/>) is subject to change. |
17693 | 18228 | |
17694 | 18229 | =end original |
17695 | 18230 | |
17696 | 18231 | (C</(?{...})/> のような) 正規表現コードブロックの中の |
17697 | 18232 | L<C<__SUB__>|/__SUB__> の振る舞いは変更される予定です。 |
17698 | 18233 | |
17699 | 18234 | =begin original |
17700 | 18235 | |
17701 | 18236 | This token is only available under C<use v5.16> or the |
17702 | 18237 | L<C<"current_sub"> feature|feature/The 'current_sub' feature>. |
17703 | 18238 | See L<feature>. |
17704 | 18239 | |
17705 | 18240 | =end original |
17706 | 18241 | |
17707 | 18242 | このトークンは C<use v5.16> または |
17708 | 18243 | L<C<"current_sub"> 機能|feature/The 'current_sub' feature> でのみ |
17709 | 18244 | 利用可能です。 |
17710 | 18245 | L<feature> を参照してください。 |
17711 | 18246 | |
17712 | 18247 | =item substr EXPR,OFFSET,LENGTH,REPLACEMENT |
17713 | 18248 | X<substr> X<substring> X<mid> X<left> X<right> |
17714 | 18249 | |
17715 | 18250 | =item substr EXPR,OFFSET,LENGTH |
17716 | 18251 | |
17717 | 18252 | =item substr EXPR,OFFSET |
17718 | 18253 | |
17719 | 18254 | =for Pod::Functions get or alter a portion of a string |
17720 | 18255 | |
17721 | 18256 | =begin original |
17722 | 18257 | |
17723 | 18258 | Extracts a substring out of EXPR and returns it. First character is at |
17724 | 18259 | offset zero. If OFFSET is negative, starts |
17725 | 18260 | that far back from the end of the string. If LENGTH is omitted, returns |
17726 | 18261 | everything through the end of the string. If LENGTH is negative, leaves that |
17727 | 18262 | many characters off the end of the string. |
17728 | 18263 | |
17729 | 18264 | =end original |
17730 | 18265 | |
17731 | 18266 | EXPR から、部分文字列を取り出して返します。 |
17732 | 18267 | 最初の文字がオフセット 0 となります。 |
17733 | 18268 | OFFSET に負の値を設定すると、EXPR の終わりからのオフセットとなります。 |
17734 | 18269 | LENGTH を省略すると、EXPR の最後まですべてが返されます。 |
17735 | 18270 | LENGTH が負の値だと、文字列の最後から指定された数だけ文字を取り除きます。 |
17736 | 18271 | |
17737 | 18272 | my $s = "The black cat climbed the green tree"; |
17738 | 18273 | my $color = substr $s, 4, 5; # black |
17739 | 18274 | my $middle = substr $s, 4, -11; # black cat climbed the |
17740 | 18275 | my $end = substr $s, 14; # climbed the green tree |
17741 | 18276 | my $tail = substr $s, -4; # tree |
17742 | 18277 | my $z = substr $s, -4, 2; # tr |
17743 | 18278 | |
17744 | 18279 | =begin original |
17745 | 18280 | |
17746 | 18281 | You can use the L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> |
17747 | 18282 | function as an lvalue, in which case EXPR |
17748 | 18283 | must itself be an lvalue. If you assign something shorter than LENGTH, |
17749 | 18284 | the string will shrink, and if you assign something longer than LENGTH, |
17750 | 18285 | the string will grow to accommodate it. To keep the string the same |
17751 | 18286 | length, you may need to pad or chop your value using |
17752 | 18287 | L<C<sprintf>|/sprintf FORMAT, LIST>. |
17753 | 18288 | |
17754 | 18289 | =end original |
17755 | 18290 | |
17756 | 18291 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> を左辺値として |
17757 | 18292 | 使用することも可能で、その場合には、EXPR が自身左辺値でなければなりません。 |
17758 | 18293 | LENGTH より短いものを代入したときには、 |
17759 | 18294 | EXPR は短くなり、LENGTH より長いものを代入したときには、 |
17760 | 18295 | EXPR はそれに合わせて伸びることになります。 |
17761 | 18296 | EXPR の長さを一定に保つためには、L<C<sprintf>|/sprintf FORMAT, LIST> を |
17762 | 18297 | 使って、代入する値の長さを調整することが、必要になるかもしれません。 |
17763 | 18298 | |
17764 | 18299 | =begin original |
17765 | 18300 | |
17766 | 18301 | If OFFSET and LENGTH specify a substring that is partly outside the |
17767 | 18302 | string, only the part within the string is returned. If the substring |
17768 | 18303 | is beyond either end of the string, |
17769 | 18304 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> returns the undefined |
17770 | 18305 | value and produces a warning. When used as an lvalue, specifying a |
17771 | 18306 | substring that is entirely outside the string raises an exception. |
17772 | 18307 | Here's an example showing the behavior for boundary cases: |
17773 | 18308 | |
17774 | 18309 | =end original |
17775 | 18310 | |
17776 | 18311 | OFFSET と LENGTH として文字列の外側を含むような部分文字列が指定されると、 |
17777 | 18312 | 文字列の内側の部分だけが返されます。 |
17778 | 18313 | 部分文字列が文字列の両端の外側の場合、 |
17779 | 18314 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> は未定義値を返し、 |
17780 | 18315 | 警告が出力されます。 |
17781 | 18316 | 左辺値として使った場合、文字列の完全に外側を部分文字列として指定すると |
17782 | 18317 | 例外が発生します。 |
17783 | 18318 | 以下は境界条件の振る舞いを示す例です: |
17784 | 18319 | |
17785 | 18320 | my $name = 'fred'; |
17786 | 18321 | substr($name, 4) = 'dy'; # $name is now 'freddy' |
17787 | 18322 | my $null = substr $name, 6, 2; # returns "" (no warning) |
17788 | 18323 | my $oops = substr $name, 7; # returns undef, with warning |
17789 | 18324 | substr($name, 7) = 'gap'; # raises an exception |
17790 | 18325 | |
17791 | 18326 | =begin original |
17792 | 18327 | |
17793 | 18328 | An alternative to using |
17794 | 18329 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> as an lvalue is to |
17795 | 18330 | specify the |
17796 | 18331 | replacement string as the 4th argument. This allows you to replace |
17797 | 18332 | parts of the EXPR and return what was there before in one operation, |
17798 | 18333 | just as you can with |
17799 | 18334 | L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST>. |
17800 | 18335 | |
17801 | 18336 | =end original |
17802 | 18337 | |
17803 | 18338 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> を左辺値として使う |
17804 | 18339 | 代わりの方法は、置き換える文字列を 4 番目の引数として指定することです。 |
17805 | 18340 | これにより、EXPR の一部を置き換え、置き換える前が何であったかを返す、 |
17806 | 18341 | ということを(L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> と同様) |
17807 | 18342 | 1 動作で行えます。 |
17808 | 18343 | |
17809 | 18344 | my $s = "The black cat climbed the green tree"; |
17810 | 18345 | my $z = substr $s, 14, 7, "jumped from"; # climbed |
17811 | 18346 | # $s is now "The black cat jumped from the green tree" |
17812 | 18347 | |
17813 | 18348 | =begin original |
17814 | 18349 | |
17815 | 18350 | Note that the lvalue returned by the three-argument version of |
17816 | 18351 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> acts as |
17817 | 18352 | a 'magic bullet'; each time it is assigned to, it remembers which part |
17818 | 18353 | of the original string is being modified; for example: |
17819 | 18354 | |
17820 | 18355 | =end original |
17821 | 18356 | |
17822 | 18357 | 3 引数の L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> によって返された |
17823 | 18358 | 左辺値は「魔法の弾丸」のように振舞うことに注意してください; |
17824 | 18359 | これが代入される毎に、元の文字列のどの部分が変更されたかが思い出されます; |
17825 | 18360 | 例えば: |
17826 | 18361 | |
17827 | 18362 | my $x = '1234'; |
17828 | 18363 | for (substr($x,1,2)) { |
17829 | 18364 | $_ = 'a'; print $x,"\n"; # prints 1a4 |
17830 | 18365 | $_ = 'xyz'; print $x,"\n"; # prints 1xyz4 |
17831 | 18366 | $x = '56789'; |
17832 | 18367 | $_ = 'pq'; print $x,"\n"; # prints 5pq9 |
17833 | 18368 | } |
17834 | 18369 | |
17835 | 18370 | =begin original |
17836 | 18371 | |
17837 | 18372 | With negative offsets, it remembers its position from the end of the string |
17838 | 18373 | when the target string is modified: |
17839 | 18374 | |
17840 | 18375 | =end original |
17841 | 18376 | |
17842 | 18377 | 負数のオフセットの場合、ターゲット文字列が修正されたときに文字列の末尾からの |
17843 | 18378 | 位置を覚えます: |
17844 | 18379 | |
17845 | 18380 | my $x = '1234'; |
17846 | 18381 | for (substr($x, -3, 2)) { |
17847 | 18382 | $_ = 'a'; print $x,"\n"; # prints 1a4, as above |
17848 | 18383 | $x = 'abcdefg'; |
17849 | 18384 | print $_,"\n"; # prints f |
17850 | 18385 | } |
17851 | 18386 | |
17852 | 18387 | =begin original |
17853 | 18388 | |
17854 | 18389 | Prior to Perl version 5.10, the result of using an lvalue multiple times was |
17855 | 18390 | unspecified. Prior to 5.16, the result with negative offsets was |
17856 | 18391 | unspecified. |
17857 | 18392 | |
17858 | 18393 | =end original |
17859 | 18394 | |
17860 | 18395 | バージョン 5.10 より前の Perl では、複数回左辺値を使った場合の結果は |
17861 | 18396 | 未定義でした。 |
17862 | 18397 | 5.16 より前では、負のオフセットの結果は未定義です。 |
17863 | 18398 | |
17864 | 18399 | =item symlink OLDFILE,NEWFILE |
17865 | 18400 | X<symlink> X<link> X<symbolic link> X<link, symbolic> |
17866 | 18401 | |
17867 | 18402 | =for Pod::Functions create a symbolic link to a file |
17868 | 18403 | |
17869 | 18404 | =begin original |
17870 | 18405 | |
17871 | 18406 | Creates a new filename symbolically linked to the old filename. |
17872 | 18407 | Returns C<1> for success, C<0> otherwise. On systems that don't support |
17873 | 18408 | symbolic links, raises an exception. To check for that, |
17874 | 18409 | use eval: |
17875 | 18410 | |
17876 | 18411 | =end original |
17877 | 18412 | |
17878 | 18413 | NEWFILE として、OLDFILE へのシンボリックリンクを生成します。 |
17879 | 18414 | 成功時には C<1> を返し、失敗時には C<0> を返します。 |
17880 | 18415 | シンボリックリンクをサポートしていないシステムでは、 |
17881 | 18416 | 例外が発生します。 |
17882 | 18417 | これをチェックするには、eval を使用します: |
17883 | 18418 | |
17884 | 18419 | my $symlink_exists = eval { symlink("",""); 1 }; |
17885 | 18420 | |
17886 | 18421 | =begin original |
17887 | 18422 | |
17888 | 18423 | Portability issues: L<perlport/symlink>. |
17889 | 18424 | |
17890 | 18425 | =end original |
17891 | 18426 | |
17892 | 18427 | 移植性の問題: L<perlport/symlink>。 |
17893 | 18428 | |
17894 | 18429 | =item syscall NUMBER, LIST |
17895 | 18430 | X<syscall> X<system call> |
17896 | 18431 | |
17897 | 18432 | =for Pod::Functions execute an arbitrary system call |
17898 | 18433 | |
17899 | 18434 | =begin original |
17900 | 18435 | |
17901 | 18436 | Calls the system call specified as the first element of the list, |
17902 | 18437 | passing the remaining elements as arguments to the system call. If |
17903 | 18438 | unimplemented, raises an exception. The arguments are interpreted |
17904 | 18439 | as follows: if a given argument is numeric, the argument is passed as |
17905 | 18440 | an int. If not, the pointer to the string value is passed. You are |
17906 | 18441 | responsible to make sure a string is pre-extended long enough to |
17907 | 18442 | receive any result that might be written into a string. You can't use a |
17908 | 18443 | string literal (or other read-only string) as an argument to |
17909 | 18444 | L<C<syscall>|/syscall NUMBER, LIST> because Perl has to assume that any |
17910 | 18445 | string pointer might be written through. If your |
17911 | 18446 | integer arguments are not literals and have never been interpreted in a |
17912 | 18447 | numeric context, you may need to add C<0> to them to force them to look |
17913 | 18448 | like numbers. This emulates the |
17914 | 18449 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> function (or |
17915 | 18450 | vice versa): |
17916 | 18451 | |
17917 | 18452 | =end original |
17918 | 18453 | |
17919 | 18454 | LIST の最初の要素で指定するシステムコールを、残りの要素をその |
17920 | 18455 | システムコールの引数として呼び出します。 |
17921 | 18456 | 実装されていない場合には、例外が発生します。 |
17922 | 18457 | 引数は、以下のように解釈されます: 引数が数字であれば、int として |
17923 | 18458 | 引数を渡します。 |
17924 | 18459 | そうでなければ、文字列値へのポインタが渡されます。 |
17925 | 18460 | 文字列に結果を受け取るときには、その結果を受け取るのに十分なくらいに、 |
17926 | 18461 | 文字列を予め伸ばしておく必要があります。 |
17927 | 18462 | 文字列リテラル(あるいはその他の読み込み専用の文字列)を |
17928 | 18463 | L<C<syscall>|/syscall NUMBER, LIST> の引数として使うことはできません; |
17929 | 18464 | Perl は全ての文字列ポインタは書き込まれると仮定しなければならないからです。 |
17930 | 18465 | 整数引数が、リテラルでなく、数値コンテキストで評価されたことのない |
17931 | 18466 | ものであれば、数値として解釈されるように、 |
17932 | 18467 | C<0> を足しておく必要があるかもしれません。 |
17933 | 18468 | 以下は L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> 関数(あるいは |
17934 | 18469 | その逆)をエミュレートします。 |
17935 | 18470 | |
17936 | 18471 | require 'syscall.ph'; # may need to run h2ph |
17937 | 18472 | my $s = "hi there\n"; |
17938 | 18473 | syscall(SYS_write(), fileno(STDOUT), $s, length $s); |
17939 | 18474 | |
17940 | 18475 | =begin original |
17941 | 18476 | |
17942 | 18477 | Note that Perl supports passing of up to only 14 arguments to your syscall, |
17943 | 18478 | which in practice should (usually) suffice. |
17944 | 18479 | |
17945 | 18480 | =end original |
17946 | 18481 | |
17947 | 18482 | Perl は、システムコールに最大 14 個の引数しか渡せませんが、 |
17948 | 18483 | (普通は)実用上問題はないでしょう。 |
17949 | 18484 | |
17950 | 18485 | =begin original |
17951 | 18486 | |
17952 | 18487 | Syscall returns whatever value returned by the system call it calls. |
17953 | 18488 | If the system call fails, L<C<syscall>|/syscall NUMBER, LIST> returns |
17954 | 18489 | C<-1> and sets L<C<$!>|perlvar/$!> (errno). |
17955 | 18490 | Note that some system calls I<can> legitimately return C<-1>. The proper |
17956 | 18491 | way to handle such calls is to assign C<$! = 0> before the call, then |
17957 | 18492 | check the value of L<C<$!>|perlvar/$!> if |
17958 | 18493 | L<C<syscall>|/syscall NUMBER, LIST> returns C<-1>. |
17959 | 18494 | |
17960 | 18495 | =end original |
17961 | 18496 | |
17962 | 18497 | syscall は、呼び出したシステムコールが返した値を返します。 |
17963 | 18498 | システムコールが失敗すると、L<C<syscall>|/syscall NUMBER, LIST> は C<-1> を |
17964 | 18499 | 返し、L<C<$!>|perlvar/$!>(errno) を設定します。 |
17965 | 18500 | システムコールが正常に C<-1> を返す I<場合がある> ことに注意してください。 |
17966 | 18501 | このようなシステムコールを正しく扱うには、 |
17967 | 18502 | C<$! = 0> をシステムコールの前に実行し、それから |
17968 | 18503 | L<C<syscall>|/syscall NUMBER, LIST> が C<-1> を返した時には |
17969 | 18504 | L<C<$!>|perlvar/$!> の値を調べてください。 |
17970 | 18505 | |
17971 | 18506 | =begin original |
17972 | 18507 | |
17973 | 18508 | There's a problem with C<syscall(SYS_pipe())>: it returns the file |
17974 | 18509 | number of the read end of the pipe it creates, but there is no way |
17975 | 18510 | to retrieve the file number of the other end. You can avoid this |
17976 | 18511 | problem by using L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> instead. |
17977 | 18512 | |
17978 | 18513 | =end original |
17979 | 18514 | |
17980 | 18515 | C<syscall(&SYS_pipe)> には問題があり、作ったパイプの、読み出し側の |
17981 | 18516 | ファイル番号を返しますが、もう一方のファイル番号を得る方法がありません。 |
17982 | 18517 | この問題を避けるためには、代わりに L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> を |
17983 | 18518 | 使ってください。 |
17984 | 18519 | |
17985 | 18520 | =begin original |
17986 | 18521 | |
17987 | 18522 | Portability issues: L<perlport/syscall>. |
17988 | 18523 | |
17989 | 18524 | =end original |
17990 | 18525 | |
17991 | 18526 | 移植性の問題: L<perlport/syscall>。 |
17992 | 18527 | |
17993 | 18528 | =item sysopen FILEHANDLE,FILENAME,MODE |
17994 | 18529 | X<sysopen> |
17995 | 18530 | |
17996 | 18531 | =item sysopen FILEHANDLE,FILENAME,MODE,PERMS |
17997 | 18532 | |
17998 | 18533 | =for Pod::Functions +5.002 open a file, pipe, or descriptor |
17999 | 18534 | |
18000 | 18535 | =begin original |
18001 | 18536 | |
18002 | 18537 | Opens the file whose filename is given by FILENAME, and associates it with |
18003 | 18538 | FILEHANDLE. If FILEHANDLE is an expression, its value is used as the real |
18004 | 18539 | filehandle wanted; an undefined scalar will be suitably autovivified. This |
18005 | 18540 | function calls the underlying operating system's L<open(2)> function with the |
18006 | 18541 | parameters FILENAME, MODE, and PERMS. |
18007 | 18542 | |
18008 | 18543 | =end original |
18009 | 18544 | |
18010 | 18545 | FILENAME で与えられたファイル名のファイルをオープンし、 |
18011 | 18546 | FILEHANDLE と結び付けます。 |
18012 | 18547 | FILEHANDLE が式の場合、その値は実際の求めているファイルハンドルの名前として |
18013 | 18548 | 扱われます; 未定義のスカラは適切に自動有効化されます。 |
18014 | 18549 | この関数呼び出しはシステムの L<open(2)> 関数を FILENAME, MODE, PERMS の |
18015 | 18550 | 引数で呼び出すことを基礎としています。 |
18016 | 18551 | |
18017 | 18552 | =begin original |
18018 | 18553 | |
18019 | 18554 | Returns true on success and L<C<undef>|/undef EXPR> otherwise. |
18020 | 18555 | |
18021 | 18556 | =end original |
18022 | 18557 | |
18023 | 18558 | 成功時は真を、さもなければ L<C<undef>|/undef EXPR> を返します。 |
18024 | 18559 | |
18025 | 18560 | =begin original |
18026 | 18561 | |
18562 | L<PerlIO> layers will be applied to the handle the same way they would in an | |
18563 | L<C<open>|/open FILEHANDLE,MODE,EXPR> call that does not specify layers. That is, | |
18564 | the current value of L<C<${^OPEN}>|perlvar/${^OPEN}> as set by the L<open> | |
18565 | pragma in a lexical scope, or the C<-C> commandline option or C<PERL_UNICODE> | |
18566 | environment variable in the main program scope, falling back to the platform | |
18567 | defaults as described in L<PerlIO/Defaults and how to override them>. If you | |
18568 | want to remove any layers that may transform the byte stream, use | |
18569 | L<C<binmode>|/binmode FILEHANDLE, LAYER> after opening it. | |
18570 | ||
18571 | =end original | |
18572 | ||
18573 | L<PerlIO> 層は、層を指定しない L<C<open>|/open FILEHANDLE,MODE,EXPR> | |
18574 | 呼び出しでするのと同じ方法でハンドルに適用されます。 | |
18575 | これは、レキシカルスコープの L<open> プラグマで設定された | |
18576 | L<C<${^OPEN}>|perlvar/${^OPEN}> の現在の値、 | |
18577 | またはメインプログラムスコープの C<-C> コマンドラインオプションまたは | |
18578 | C<PERL_UNICODE> 環境変数、L<PerlIO/Defaults and how to override them> で | |
18579 | 記述されているようにプラットフォームのデフォルトに | |
18580 | フォールバックしたものです。 | |
18581 | バイトストリームを変換する全ての層を除去したい場合は、 | |
18582 | それを開いた後に L<C<binmode>|/binmode FILEHANDLE, LAYER> を使ってください。 | |
18583 | ||
18584 | =begin original | |
18585 | ||
18027 | 18586 | The possible values and flag bits of the MODE parameter are |
18028 | 18587 | system-dependent; they are available via the standard module |
18029 | 18588 | L<C<Fcntl>|Fcntl>. See the documentation of your operating system's |
18030 | 18589 | L<open(2)> syscall to see |
18031 | 18590 | which values and flag bits are available. You may combine several flags |
18032 | 18591 | using the C<|>-operator. |
18033 | 18592 | |
18034 | 18593 | =end original |
18035 | 18594 | |
18036 | 18595 | MODE パラメータに指定できるフラグビットと値はシステム依存です; |
18037 | 18596 | これは標準モジュール L<C<Fcntl>|Fcntl> 経由で利用可能です。 |
18038 | 18597 | どのようなフラグビットと値が利用可能であるかについては、 |
18039 | 18598 | OS の L<open(2)> システムコールに関する文書を参照してください。 |
18040 | 18599 | C<|> 演算子を使って複数のフラグを結合することができます。 |
18041 | 18600 | |
18042 | 18601 | =begin original |
18043 | 18602 | |
18044 | 18603 | Some of the most common values are C<O_RDONLY> for opening the file in |
18045 | 18604 | read-only mode, C<O_WRONLY> for opening the file in write-only mode, |
18046 | 18605 | and C<O_RDWR> for opening the file in read-write mode. |
18047 | 18606 | X<O_RDONLY> X<O_RDWR> X<O_WRONLY> |
18048 | 18607 | |
18049 | 18608 | =end original |
18050 | 18609 | |
18051 | 18610 | もっともよく使われる値は、ファイルを読み込み専用で開く C<O_RDONLY>、 |
18052 | 18611 | ファイルを書き込み専用で開く C<O_WRONLY>、 |
18053 | 18612 | ファイルを読み書き両用で開く C<O_RDWR> です。 |
18054 | 18613 | X<O_RDONLY> X<O_RDWR> X<O_WRONLY> |
18055 | 18614 | |
18056 | 18615 | =begin original |
18057 | 18616 | |
18058 | 18617 | For historical reasons, some values work on almost every system |
18059 | 18618 | supported by Perl: 0 means read-only, 1 means write-only, and 2 |
18060 | 18619 | means read/write. We know that these values do I<not> work under |
18061 | 18620 | OS/390 and on the Macintosh; you probably don't want to |
18062 | 18621 | use them in new code. |
18063 | 18622 | |
18064 | 18623 | =end original |
18065 | 18624 | |
18066 | 18625 | 歴史的な理由により、Perl が対応しているほとんどのシステムで使える値が |
18067 | 18626 | あります:0 は読み込み専用、1 は書き込み専用、2 は読み書き両用を意味します。 |
18068 | 18627 | OS/390 と Macintosh では動作 I<しない> ことが分かっています; |
18069 | 18628 | 新しく書くコードではこれらは使わないほうがよいでしょう。 |
18070 | 18629 | |
18071 | 18630 | =begin original |
18072 | 18631 | |
18073 | 18632 | If the file named by FILENAME does not exist and the |
18074 | L<C<open>|/open FILEHANDLE,EXPR> call creates | |
18633 | L<C<open>|/open FILEHANDLE,MODE,EXPR> call creates | |
18075 | 18634 | it (typically because MODE includes the C<O_CREAT> flag), then the value of |
18076 | 18635 | PERMS specifies the permissions of the newly created file. If you omit |
18077 | 18636 | the PERMS argument to L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>, |
18078 | 18637 | Perl uses the octal value C<0666>. |
18079 | 18638 | These permission values need to be in octal, and are modified by your |
18080 | 18639 | process's current L<C<umask>|/umask EXPR>. |
18081 | 18640 | X<O_CREAT> |
18082 | 18641 | |
18083 | 18642 | =end original |
18084 | 18643 | |
18085 | 18644 | FILENAME という名前のファイルが存在せず、(典型的には MODE が |
18086 | 18645 | C<O_CREAT> フラグを含んでいたために) |
18087 | L<C<open>|/open FILEHANDLE,EXPR> 呼び出しがそれを作った場合、 | |
18646 | L<C<open>|/open FILEHANDLE,MODE,EXPR> 呼び出しがそれを作った場合、 | |
18088 | 18647 | PERMS の値は新しく作られたファイルの権限を指定します。 |
18089 | 18648 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> の PERMS 引数を省略した場合、 |
18090 | 18649 | Perl は 8 進数 C<0666> を使います。 |
18091 | 18650 | これらの権限は 8 進数である必要があり、プロセスの現在の |
18092 | 18651 | L<C<umask>|/umask EXPR> で修正されます。 |
18093 | 18652 | X<O_CREAT> |
18094 | 18653 | |
18095 | 18654 | =begin original |
18096 | 18655 | |
18097 | 18656 | In many systems the C<O_EXCL> flag is available for opening files in |
18098 | 18657 | exclusive mode. This is B<not> locking: exclusiveness means here that |
18099 | 18658 | if the file already exists, |
18100 | 18659 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> fails. C<O_EXCL> may |
18101 | 18660 | not work |
18102 | 18661 | on network filesystems, and has no effect unless the C<O_CREAT> flag |
18103 | 18662 | is set as well. Setting C<O_CREAT|O_EXCL> prevents the file from |
18104 | 18663 | being opened if it is a symbolic link. It does not protect against |
18105 | 18664 | symbolic links in the file's path. |
18106 | 18665 | X<O_EXCL> |
18107 | 18666 | |
18108 | 18667 | =end original |
18109 | 18668 | |
18110 | 18669 | 多くのシステムではファイルを排他モードで開くために C<O_EXCL> が |
18111 | 18670 | 利用可能です。 |
18112 | 18671 | これはロック B<ではありません>: 排他性というのは既にファイルが |
18113 | 18672 | 存在していた場合、L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> が |
18114 | 18673 | 失敗することを意味します。 |
18115 | 18674 | C<O_EXCL> はネットワークファイルシステムでは動作せず、 |
18116 | 18675 | またC<O_CREAT> フラグも有効でない限りは効果がありません。 |
18117 | 18676 | C<O_CREAT|O_EXCL> をセットすると、これがシンボリックリンクだった場合は |
18118 | 18677 | ファイルを開くことを妨げます。 |
18119 | 18678 | これはファイルパス中のシンボリックリンクは守りません。 |
18120 | 18679 | X<O_EXCL> |
18121 | 18680 | |
18122 | 18681 | =begin original |
18123 | 18682 | |
18124 | 18683 | Sometimes you may want to truncate an already-existing file. This |
18125 | 18684 | can be done using the C<O_TRUNC> flag. The behavior of |
18126 | 18685 | C<O_TRUNC> with C<O_RDONLY> is undefined. |
18127 | 18686 | X<O_TRUNC> |
18128 | 18687 | |
18129 | 18688 | =end original |
18130 | 18689 | |
18131 | 18690 | 既に存在しているファイルを切り詰めたい場合もあるかもしれません。 |
18132 | 18691 | これは C<O_TRUNC> フラグを使うことで行えます。 |
18133 | 18692 | C<O_RDONLY> と C<O_TRUNC> を同時に指定したときの振る舞いは未定義です。 |
18134 | 18693 | X<O_TRUNC> |
18135 | 18694 | |
18136 | 18695 | =begin original |
18137 | 18696 | |
18138 | 18697 | You should seldom if ever use C<0644> as argument to |
18139 | 18698 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>, because |
18140 | 18699 | that takes away the user's option to have a more permissive umask. |
18141 | 18700 | Better to omit it. See L<C<umask>|/umask EXPR> for more on this. |
18142 | 18701 | |
18143 | 18702 | =end original |
18144 | 18703 | |
18145 | 18704 | めったなことでは L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> の引数に |
18146 | 18705 | C<0644> を指定するべきではないでしょう: |
18147 | 18706 | ユーザーがより寛大な umask を指定する選択肢を奪うからです。 |
18148 | 18707 | 省略した方がいいです。 |
18149 | 18708 | これに関するさらなる情報については L<C<umask>|/umask EXPR> を |
18150 | 18709 | 参照してください。 |
18151 | 18710 | |
18152 | 18711 | =begin original |
18153 | 18712 | |
18713 | This function has no direct relation to the usage of | |
18714 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
18715 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
18716 | or L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>. A handle opened with | |
18717 | this function can be used with buffered IO just as one opened with | |
18718 | L<C<open>|/open FILEHANDLE,MODE,EXPR> can be used with unbuffered IO. | |
18719 | ||
18720 | =end original | |
18721 | ||
18722 | この関数は、 | |
18723 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
18724 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
18725 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> の使用法と | |
18726 | 直接の関係はありません。 | |
18727 | この関数で開かれたハンドルがバッファリングされた IO で使えるのと同様、 | |
18728 | L<C<open>|/open FILEHANDLE,MODE,EXPR> で開かれたものは | |
18729 | バッファリングされない IO で使えます。 | |
18730 | ||
18731 | =begin original | |
18732 | ||
18154 | 18733 | Note that under Perls older than 5.8.0, |
18155 | 18734 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> depends on the |
18156 | 18735 | L<fdopen(3)> C library function. On many Unix systems, L<fdopen(3)> is known |
18157 | 18736 | to fail when file descriptors exceed a certain value, typically 255. If |
18158 | 18737 | you need more file descriptors than that, consider using the |
18159 | 18738 | L<C<POSIX::open>|POSIX/C<open>> function. For Perls 5.8.0 and later, |
18160 | 18739 | PerlIO is (most often) the default. |
18161 | 18740 | |
18162 | 18741 | =end original |
18163 | 18742 | |
18164 | 18743 | 5.8.0 より古い Perl では、 |
18165 | 18744 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> は |
18166 | 18745 | C の L<fdopen(3)> ライブラリ関数に依存していることに注意してください。 |
18167 | 18746 | 多くの Unix システムでは、L<fdopen(3)> はファイル記述子がある値(例えば 255)を |
18168 | 18747 | 超えると失敗することが知られています。 |
18169 | 18748 | これより多くのファイル記述子が必要な場合は、 |
18170 | 18749 | L<C<POSIX::open>|POSIX/C<open>> 関数を使うことを検討してください。 |
18171 | 18750 | Perl 5.8.0 以降では、(ほぼ確実に) PerlIO がデフォルトです。 |
18172 | 18751 | |
18173 | 18752 | =begin original |
18174 | 18753 | |
18175 | 18754 | See L<perlopentut> for a kinder, gentler explanation of opening files. |
18176 | 18755 | |
18177 | 18756 | =end original |
18178 | 18757 | |
18179 | 18758 | ファイルを開くことに関するより親切な説明については L<perlopentut> を |
18180 | 18759 | 参照してください。 |
18181 | 18760 | |
18182 | 18761 | =begin original |
18183 | 18762 | |
18184 | 18763 | Portability issues: L<perlport/sysopen>. |
18185 | 18764 | |
18186 | 18765 | =end original |
18187 | 18766 | |
18188 | 18767 | 移植性の問題: L<perlport/sysopen>。 |
18189 | 18768 | |
18190 | 18769 | =item sysread FILEHANDLE,SCALAR,LENGTH,OFFSET |
18191 | 18770 | X<sysread> |
18192 | 18771 | |
18193 | 18772 | =item sysread FILEHANDLE,SCALAR,LENGTH |
18194 | 18773 | |
18195 | 18774 | =for Pod::Functions fixed-length unbuffered input from a filehandle |
18196 | 18775 | |
18197 | 18776 | =begin original |
18198 | 18777 | |
18199 | 18778 | Attempts to read LENGTH bytes of data into variable SCALAR from the |
18200 | specified FILEHANDLE, using L<read(2)>. It bypasses | |
18779 | specified FILEHANDLE, using L<read(2)>. It bypasses any L<PerlIO> layers | |
18201 | buffered IO | |
18780 | including buffered IO (but is affected by the presence of the C<:utf8> | |
18781 | layer as described later), so mixing this with other kinds of reads, | |
18202 | 18782 | L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>, |
18203 | 18783 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, |
18204 | 18784 | L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> can cause |
18205 | 18785 | confusion because the |
18206 | perlio or | |
18786 | C<:perlio> or C<:crlf> layers usually buffer data. Returns the number of | |
18207 | 18787 | bytes actually read, C<0> at end of file, or undef if there was an |
18208 | 18788 | error (in the latter case L<C<$!>|perlvar/$!> is also set). SCALAR will |
18209 | 18789 | be grown or |
18210 | 18790 | shrunk so that the last byte actually read is the last byte of the |
18211 | 18791 | scalar after the read. |
18212 | 18792 | |
18213 | 18793 | =end original |
18214 | 18794 | |
18215 | 18795 | L<read(2)> を用いて、指定した FILEHANDLE から、変数 SCALAR へ、LENGTH バイトの |
18216 | 18796 | データの読み込みを試みます。 |
18217 | これは、バッファ付き IO ルーチンを通 | |
18797 | これは、バッファ付き IO ルーチンを含むどの L<PerlIO> も通らないので | |
18798 | (しかし、後述するように C<:utf8> の存在の影響を受けます)、他の入力関数、 | |
18218 | 18799 | L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>, |
18219 | 18800 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>, |
18220 | 18801 | L<C<eof>|/eof FILEHANDLE> と混ぜて使うと、入力がおかしくなるかも |
18221 | しれません; | |
18802 | しれません; | |
18803 | C<:perlio> 層や C<:crlf> 層は普通データをバッファリングするからです。 | |
18222 | 18804 | ファイルの最後では C<0>が、エラー時には undef が、それ以外では実際に |
18223 | 18805 | 読み込まれたデータの長さが返されます (後者の場合は L<C<$!>|perlvar/$!> も |
18224 | 18806 | セットされます)。 |
18225 | 18807 | 実際に読み込んだ最後のバイトが read した後の最後のバイトになるので、 |
18226 | 18808 | SCALAR は伸び縮みします。 |
18227 | 18809 | |
18228 | 18810 | =begin original |
18229 | 18811 | |
18230 | 18812 | An OFFSET may be specified to place the read data at some place in the |
18231 | 18813 | string other than the beginning. A negative OFFSET specifies |
18232 | 18814 | placement at that many characters counting backwards from the end of |
18233 | 18815 | the string. A positive OFFSET greater than the length of SCALAR |
18234 | 18816 | results in the string being padded to the required size with C<"\0"> |
18235 | 18817 | bytes before the result of the read is appended. |
18236 | 18818 | |
18237 | 18819 | =end original |
18238 | 18820 | |
18239 | 18821 | OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行なえます。 |
18240 | 18822 | OFFSET に負の値を指定すると、文字列の最後から逆向きに何文字目かで |
18241 | 18823 | 位置を指定します。 |
18242 | 18824 | OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は読み込みの結果が |
18243 | 18825 | 追加される前に、必要なサイズまで C<"\0"> のバイトでパッディングされます。 |
18244 | 18826 | |
18245 | 18827 | =begin original |
18246 | 18828 | |
18247 | 18829 | There is no syseof() function, which is ok, since |
18248 | 18830 | L<C<eof>|/eof FILEHANDLE> doesn't work well on device files (like ttys) |
18249 | 18831 | anyway. Use L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> and |
18250 | check for a return value | |
18832 | check for a return value of 0 to decide whether you're done. | |
18251 | 18833 | |
18252 | 18834 | =end original |
18253 | 18835 | |
18254 | 18836 | syseof() 関数はありませんが、問題ありません; どちらにしろ |
18255 | 18837 | L<C<eof>|/eof FILEHANDLE> は |
18256 | 18838 | (tty のような)デバイスファイルに対してはうまく動作しないからです。 |
18257 | 18839 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を使って、 |
18258 | 18840 | 返り値が 0 かどうかで最後まで読んだかを判断してください。 |
18259 | 18841 | |
18260 | 18842 | =begin original |
18261 | 18843 | |
18262 | Note that if the filehandle has been marked as C<:utf8>, | |
18844 | Note that if the filehandle has been marked as C<:utf8>, C<sysread> will | |
18263 | ||
18845 | throw an exception. The C<:encoding(...)> layer implicitly | |
18264 | return value of L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> | |
18265 | are in Unicode characters). The C<:encoding(...)> layer implicitly | |
18266 | 18846 | introduces the C<:utf8> layer. See |
18267 | 18847 | L<C<binmode>|/binmode FILEHANDLE, LAYER>, |
18268 | L<C<open>|/open FILEHANDLE,EXPR>, and the L<open> pragma. | |
18848 | L<C<open>|/open FILEHANDLE,MODE,EXPR>, and the L<open> pragma. | |
18269 | 18849 | |
18270 | 18850 | =end original |
18271 | 18851 | |
18272 | ファイルハンドルが C<:utf8> であるとマークが付けられると、 | |
18852 | ファイルハンドルが C<:utf8> であるとマークが付けられていると、 | |
18273 | ||
18853 | C<sysread> は例外を投げます。 | |
18274 | (L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> の LENGTH, OFFSET | |
18275 | および返り値は Unicode 文字になります)。 | |
18276 | 18854 | C<:encoding(...)> 層は暗黙のうちに C<:utf8> 層が導入されます。 |
18277 | L<C<binmode>|/binmode FILEHANDLE, LAYER>, | |
18855 | L<C<binmode>|/binmode FILEHANDLE, LAYER>, | |
18278 | L<open> プラグマを参照してください。 | |
18856 | L<C<open>|/open FILEHANDLE,MODE,EXPR>, L<open> プラグマを参照してください。 | |
18279 | 18857 | |
18280 | 18858 | =item sysseek FILEHANDLE,POSITION,WHENCE |
18281 | 18859 | X<sysseek> X<lseek> |
18282 | 18860 | |
18283 | 18861 | =for Pod::Functions +5.004 position I/O pointer on handle used with sysread and syswrite |
18284 | 18862 | |
18285 | 18863 | =begin original |
18286 | 18864 | |
18287 | 18865 | Sets FILEHANDLE's system position I<in bytes> using L<lseek(2)>. FILEHANDLE may |
18288 | 18866 | be an expression whose value gives the name of the filehandle. The values |
18289 | for WHENCE are C<0> to set the new position to POSITION; C<1> to set | |
18867 | for WHENCE are C<0> to set the new position to POSITION; C<1> to set it | |
18290 | 18868 | to the current position plus POSITION; and C<2> to set it to EOF plus |
18291 | 18869 | POSITION, typically negative. |
18292 | 18870 | |
18293 | 18871 | =end original |
18294 | 18872 | |
18295 | 18873 | FILEHANDLE のシステム位置を I<バイト単位> で L<lseek(2)> を使って設定します。 |
18296 | 18874 | FILEHANDLE は、実際のファイルハンドル名を与える式でもかまいません。 |
18297 | 18875 | WHENCE の値が、C<0> ならば、新しい位置を POSITION の位置へ設定します; |
18298 | 18876 | C<1> ならば、現在位置から POSITION 加えた位置へ設定します; C<2> ならば、 |
18299 | 18877 | EOF から POSITION だけ(普通は負の数です)加えた位置へ、新しい位置を |
18300 | 18878 | 設定します。 |
18301 | 18879 | |
18302 | 18880 | =begin original |
18303 | 18881 | |
18304 | 18882 | Note the emphasis on bytes: even if the filehandle has been set to operate |
18305 | 18883 | on characters (for example using the C<:encoding(UTF-8)> I/O layer), the |
18306 | 18884 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, |
18307 | 18885 | L<C<tell>|/tell FILEHANDLE>, and |
18308 | 18886 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> |
18309 | 18887 | family of functions use byte offsets, not character offsets, |
18310 | 18888 | because seeking to a character offset would be very slow in a UTF-8 file. |
18311 | 18889 | |
18312 | 18890 | =end original |
18313 | 18891 | |
18314 | 18892 | バイト単位に対する注意: 例え(例えば C<:encoding(UTF-8)> I/O 層を使うなどして) |
18315 | 18893 | ファイルハンドルが文字単位で処理するように設定されていたとしても、 |
18316 | 18894 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, |
18317 | 18895 | L<C<tell>|/tell FILEHANDLE>, |
18318 | 18896 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> シリーズの関数は |
18319 | 18897 | 文字オフセットではなくバイトオフセットを使います; |
18320 | 18898 | 文字オフセットでシークするのは UTF-8 ファイルではとても遅いからです。 |
18321 | 18899 | |
18322 | 18900 | =begin original |
18323 | 18901 | |
18324 | 18902 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> bypasses normal |
18325 | 18903 | buffered IO, so mixing it with reads other than |
18326 | 18904 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> (for example |
18327 | 18905 | L<C<readline>|/readline EXPR> or |
18328 | 18906 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>), |
18329 | 18907 | L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>, |
18330 | 18908 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, |
18331 | 18909 | L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> may cause |
18332 | 18910 | confusion. |
18333 | 18911 | |
18334 | 18912 | =end original |
18335 | 18913 | |
18336 | 18914 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> は普通のバッファ付き IO を |
18337 | 18915 | バイパスしますので、 |
18338 | 18916 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> 以外の (例えば |
18339 | 18917 | L<C<readline>|/readline EXPR> や |
18340 | 18918 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> の)読み込み、 |
18341 | 18919 | L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>, |
18342 | 18920 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>, |
18343 | 18921 | L<C<eof>|/eof FILEHANDLE> と混ぜて使うと混乱を引き起こします。 |
18344 | 18922 | |
18345 | 18923 | =begin original |
18346 | 18924 | |
18347 | 18925 | For WHENCE, you may also use the constants C<SEEK_SET>, C<SEEK_CUR>, |
18348 | 18926 | and C<SEEK_END> (start of the file, current position, end of the file) |
18349 | 18927 | from the L<Fcntl> module. Use of the constants is also more portable |
18350 | 18928 | than relying on 0, 1, and 2. For example to define a "systell" function: |
18351 | 18929 | |
18352 | 18930 | =end original |
18353 | 18931 | |
18354 | 18932 | WHENCE には、L<Fcntl> モジュールで使われている C<SEEK_SET>, C<SEEK_CUR>, |
18355 | 18933 | C<SEEK_END> (ファイルの先頭、現在位置、ファイルの最後)という定数を |
18356 | 18934 | 使うこともできます。 |
18357 | 18935 | 定数の使用は 0, 1, 2 に依存するよりも移植性があります。 |
18358 | 18936 | 例えば "systell" 関数を定義するには: |
18359 | 18937 | |
18360 | 18938 | use Fcntl 'SEEK_CUR'; |
18361 | 18939 | sub systell { sysseek($_[0], 0, SEEK_CUR) } |
18362 | 18940 | |
18363 | 18941 | =begin original |
18364 | 18942 | |
18365 | 18943 | Returns the new position, or the undefined value on failure. A position |
18366 | 18944 | of zero is returned as the string C<"0 but true">; thus |
18367 | 18945 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> returns |
18368 | 18946 | true on success and false on failure, yet you can still easily determine |
18369 | 18947 | the new position. |
18370 | 18948 | |
18371 | 18949 | =end original |
18372 | 18950 | |
18373 | 18951 | 新しい位置を返します; 失敗したときは未定義値を返します。 |
18374 | 18952 | 位置がゼロの場合は、C<"0 but true"> の文字列として返されます; 従って |
18375 | 18953 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> は成功時に真を返し、 |
18376 | 18954 | 失敗時に偽を返しますが、簡単に新しい位置を判定できます。 |
18377 | 18955 | |
18378 | 18956 | =item system LIST |
18379 | 18957 | X<system> X<shell> |
18380 | 18958 | |
18381 | 18959 | =item system PROGRAM LIST |
18382 | 18960 | |
18383 | 18961 | =for Pod::Functions run a separate program |
18384 | 18962 | |
18385 | 18963 | =begin original |
18386 | 18964 | |
18387 | 18965 | Does exactly the same thing as L<C<exec>|/exec LIST>, except that a fork is |
18388 | 18966 | done first and the parent process waits for the child process to |
18389 | 18967 | exit. Note that argument processing varies depending on the |
18390 | 18968 | number of arguments. If there is more than one argument in LIST, |
18391 | 18969 | or if LIST is an array with more than one value, starts the program |
18392 | 18970 | given by the first element of the list with arguments given by the |
18393 | 18971 | rest of the list. If there is only one scalar argument, the argument |
18394 | 18972 | is checked for shell metacharacters, and if there are any, the |
18395 | 18973 | entire argument is passed to the system's command shell for parsing |
18396 | 18974 | (this is C</bin/sh -c> on Unix platforms, but varies on other |
18397 | 18975 | platforms). If there are no shell metacharacters in the argument, |
18398 | 18976 | it is split into words and passed directly to C<execvp>, which is |
18399 | 18977 | more efficient. On Windows, only the C<system PROGRAM LIST> syntax will |
18400 | 18978 | reliably avoid using the shell; C<system LIST>, even with more than one |
18401 | 18979 | element, will fall back to the shell if the first spawn fails. |
18402 | 18980 | |
18403 | 18981 | =end original |
18404 | 18982 | |
18405 | 18983 | L<C<exec>|/exec LIST> とほとんど同じですが、まず fork を行ない、 |
18406 | 18984 | 親プロセスではチャイルドプロセスが終了するのを wait します。 |
18407 | 18985 | exec の項で述べたように、引数の処理は、引数の数によって異なることに |
18408 | 18986 | 注意してください。 |
18409 | 18987 | LIST に複数の引数がある場合、または LIST が複数の要素からなる配列の場合、 |
18410 | 18988 | リストの最初の要素で与えられるプログラムを、リストの残りの要素を引数として |
18411 | 18989 | 起動します。 |
18412 | 18990 | スカラの引数が一つだけの場合、引数はシェルのメタ文字をチェックされ、もし |
18413 | 18991 | あればパースのために引数全体がシステムコマンドシェル (これは |
18414 | 18992 | Unix プラットフォームでは C</bin/sh -c> ですが、他のプラットフォームでは |
18415 | 18993 | 異なります)に渡されます。 |
18416 | 18994 | シェルのメタ文字がなかった場合、引数は単語に分解されて直接 C<execvp> に |
18417 | 18995 | 渡されます; この方がより効率的です。 |
18418 | 18996 | Windows では、C<system PROGRAM LIST> 構文のみが安定してシェルの使用を |
18419 | 18997 | 回避します; C<system LIST> は、2 要素以上でも、最初の spawn が失敗すると |
18420 | 18998 | シェルにフォールバックします。 |
18421 | 18999 | |
18422 | 19000 | =begin original |
18423 | 19001 | |
18424 | 19002 | Perl will attempt to flush all files opened for |
18425 | 19003 | output before any operation that may do a fork, but this may not be |
18426 | 19004 | supported on some platforms (see L<perlport>). To be safe, you may need |
18427 | 19005 | to set L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>) |
18428 | 19006 | or call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS> |
18429 | 19007 | on any open handles. |
18430 | 19008 | |
18431 | 19009 | =end original |
18432 | 19010 | |
18433 | 19011 | v5.6.0 から、Perl は書き込み用に開いている全てのファイルに対して |
18434 | 19012 | fork を行う前にフラッシュしようとしますが、これに対応していない |
18435 | 19013 | プラットフォームもあります(L<perlport> を参照してください)。 |
18436 | 19014 | 安全のために、L<C<$E<verbar>>|perlvar/$E<verbar>> (L<English> モジュールでは |
18437 | 19015 | C<$AUTOFLUSH>) をセットするか、全ての開いているハンドルに対して |
18438 | 19016 | L<C<IO::Handle>|IO::Handle/METHODS> の C<autoflush> メソッドを |
18439 | 19017 | 呼び出す必要があるかもしれません。 |
18440 | 19018 | |
18441 | 19019 | =begin original |
18442 | 19020 | |
18443 | 19021 | The return value is the exit status of the program as returned by the |
18444 | 19022 | L<C<wait>|/wait> call. To get the actual exit value, shift right by |
18445 | 19023 | eight (see below). See also L<C<exec>|/exec LIST>. This is I<not> what |
18446 | 19024 | you want to use to capture the output from a command; for that you |
18447 | 19025 | should use merely backticks or |
18448 | 19026 | L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>>, as described in |
18449 | 19027 | L<perlop/"`STRING`">. Return value of -1 indicates a failure to start |
18450 | 19028 | the program or an error of the L<wait(2)> system call (inspect |
18451 | 19029 | L<C<$!>|perlvar/$!> for the reason). |
18452 | 19030 | |
18453 | 19031 | =end original |
18454 | 19032 | |
18455 | 19033 | 返り値は、L<C<wait>|/wait> が返すプログラムの exit 状態です。 |
18456 | 19034 | 実際の exit 値を得るには 右に 8 ビットシフトしてください(後述)。 |
18457 | 19035 | L<C<exec>|/exec LIST> も参照してください。 |
18458 | 19036 | これはコマンドからの出力を捕らえるために使うものI<ではありません>; |
18459 | 19037 | そのような用途には、L<perlop/"`STRING`"> に記述されている |
18460 | 19038 | 逆クォートや L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>> を使用してください。 |
18461 | 19039 | -1 の返り値はプログラムを開始させることに失敗したか、L<wait(2)> |
18462 | 19040 | システムコールがエラーを出したことを示します |
18463 | 19041 | (理由は L<C<$!>|perlvar/$!> を調べてください)。 |
18464 | 19042 | |
18465 | 19043 | =begin original |
18466 | 19044 | |
18467 | 19045 | If you'd like to make L<C<system>|/system LIST> (and many other bits of |
18468 | 19046 | Perl) die on error, have a look at the L<autodie> pragma. |
18469 | 19047 | |
18470 | 19048 | =end original |
18471 | 19049 | |
18472 | 19050 | もし L<C<system>|/system LIST> (及び Perl のその他の多くの部分) でエラー時に |
18473 | 19051 | die したいなら、L<autodie> プラグマを見てみてください。 |
18474 | 19052 | |
18475 | 19053 | =begin original |
18476 | 19054 | |
18477 | 19055 | Like L<C<exec>|/exec LIST>, L<C<system>|/system LIST> allows you to lie |
18478 | 19056 | to a program about its name if you use the C<system PROGRAM LIST> |
18479 | 19057 | syntax. Again, see L<C<exec>|/exec LIST>. |
18480 | 19058 | |
18481 | 19059 | =end original |
18482 | 19060 | |
18483 | 19061 | L<C<exec>|/exec LIST> と同様に、L<C<system>|/system LIST> でも |
18484 | 19062 | C<system PROGRAM LIST> の文法を使うことで、プログラムに対してその名前を |
18485 | 19063 | 嘘をつくことができます。 |
18486 | 19064 | 再び、L<C<exec>|/exec LIST> を参照してください。 |
18487 | 19065 | |
18488 | 19066 | =begin original |
18489 | 19067 | |
18490 | 19068 | Since C<SIGINT> and C<SIGQUIT> are ignored during the execution of |
18491 | 19069 | L<C<system>|/system LIST>, if you expect your program to terminate on |
18492 | 19070 | receipt of these signals you will need to arrange to do so yourself |
18493 | 19071 | based on the return value. |
18494 | 19072 | |
18495 | 19073 | =end original |
18496 | 19074 | |
18497 | 19075 | C<SIGINT> と C<SIGQUIT> は L<C<system>|/system LIST> の実行中は無視されるので、 |
18498 | 19076 | これらのシグナルを受信して終了させることを想定したプログラムの場合、 |
18499 | 19077 | 返り値を利用するように変更する必要があります。 |
18500 | 19078 | |
18501 | 19079 | my @args = ("command", "arg1", "arg2"); |
18502 | 19080 | system(@args) == 0 |
18503 | 19081 | or die "system @args failed: $?"; |
18504 | 19082 | |
18505 | 19083 | =begin original |
18506 | 19084 | |
18507 | 19085 | If you'd like to manually inspect L<C<system>|/system LIST>'s failure, |
18508 | 19086 | you can check all possible failure modes by inspecting |
18509 | 19087 | L<C<$?>|perlvar/$?> like this: |
18510 | 19088 | |
18511 | 19089 | =end original |
18512 | 19090 | |
18513 | 19091 | L<C<system>|/system LIST> の失敗を手動で検査したいなら、以下のように |
18514 | 19092 | L<C<$?>|perlvar/$?> を調べることで、全ての失敗の可能性をチェックできます: |
18515 | 19093 | |
18516 | 19094 | if ($? == -1) { |
18517 | 19095 | print "failed to execute: $!\n"; |
18518 | 19096 | } |
18519 | 19097 | elsif ($? & 127) { |
18520 | 19098 | printf "child died with signal %d, %s coredump\n", |
18521 | 19099 | ($? & 127), ($? & 128) ? 'with' : 'without'; |
18522 | 19100 | } |
18523 | 19101 | else { |
18524 | 19102 | printf "child exited with value %d\n", $? >> 8; |
18525 | 19103 | } |
18526 | 19104 | |
18527 | 19105 | =begin original |
18528 | 19106 | |
18529 | 19107 | Alternatively, you may inspect the value of |
18530 | 19108 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> with the |
18531 | 19109 | L<C<W*()>|POSIX/C<WIFEXITED>> calls from the L<POSIX> module. |
18532 | 19110 | |
18533 | 19111 | =end original |
18534 | 19112 | |
18535 | 19113 | または、L<POSIX> モジュールの L<C<W*()>|POSIX/C<WIFEXITED>> 呼び出しを使って |
18536 | 19114 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> の値を |
18537 | 19115 | 調べることもできます。 |
18538 | 19116 | |
18539 | 19117 | =begin original |
18540 | 19118 | |
18541 | 19119 | When L<C<system>|/system LIST>'s arguments are executed indirectly by |
18542 | 19120 | the shell, results and return codes are subject to its quirks. |
18543 | 19121 | See L<perlop/"`STRING`"> and L<C<exec>|/exec LIST> for details. |
18544 | 19122 | |
18545 | 19123 | =end original |
18546 | 19124 | |
18547 | 19125 | L<C<system>|/system LIST> の引数がシェルによって間接的に実行された場合、 |
18548 | 19126 | 結果と返り値はシェルの癖によって変更されることがあります。 |
18549 | 19127 | 詳細については L<perlop/"`STRING`"> と L<C<exec>|/exec LIST> を |
18550 | 19128 | 参照してください。 |
18551 | 19129 | |
18552 | 19130 | =begin original |
18553 | 19131 | |
18554 | 19132 | Since L<C<system>|/system LIST> does a L<C<fork>|/fork> and |
18555 | 19133 | L<C<wait>|/wait> it may affect a C<SIGCHLD> handler. See L<perlipc> for |
18556 | 19134 | details. |
18557 | 19135 | |
18558 | 19136 | =end original |
18559 | 19137 | |
18560 | 19138 | L<C<system>|/system LIST> は L<C<fork>|/fork> と L<C<wait>|/wait> を行うので、 |
18561 | 19139 | C<SIGCHLD> ハンドラの影響を受けます。 |
18562 | 19140 | 詳しくは L<perlipc> を参照してください。 |
18563 | 19141 | |
18564 | 19142 | =begin original |
18565 | 19143 | |
18566 | 19144 | Portability issues: L<perlport/system>. |
18567 | 19145 | |
18568 | 19146 | =end original |
18569 | 19147 | |
18570 | 19148 | 移植性の問題: L<perlport/system>。 |
18571 | 19149 | |
18572 | 19150 | =item syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET |
18573 | 19151 | X<syswrite> |
18574 | 19152 | |
18575 | 19153 | =item syswrite FILEHANDLE,SCALAR,LENGTH |
18576 | 19154 | |
18577 | 19155 | =item syswrite FILEHANDLE,SCALAR |
18578 | 19156 | |
18579 | 19157 | =for Pod::Functions fixed-length unbuffered output to a filehandle |
18580 | 19158 | |
18581 | 19159 | =begin original |
18582 | 19160 | |
18583 | 19161 | Attempts to write LENGTH bytes of data from variable SCALAR to the |
18584 | 19162 | specified FILEHANDLE, using L<write(2)>. If LENGTH is |
18585 | not specified, writes whole SCALAR. It bypasses | |
19163 | not specified, writes whole SCALAR. It bypasses any L<PerlIO> layers | |
19164 | including buffered IO (but is affected by the presence of the C<:utf8> | |
19165 | layer as described later), so | |
18586 | 19166 | mixing this with reads (other than C<sysread)>), |
18587 | 19167 | L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>, |
18588 | 19168 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, |
18589 | 19169 | L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> may cause |
18590 | confusion because the perlio and | |
19170 | confusion because the C<:perlio> and C<:crlf> layers usually buffer data. | |
18591 | 19171 | Returns the number of bytes actually written, or L<C<undef>|/undef EXPR> |
18592 | 19172 | if there was an error (in this case the errno variable |
18593 | 19173 | L<C<$!>|perlvar/$!> is also set). If the LENGTH is greater than the |
18594 | 19174 | data available in the SCALAR after the OFFSET, only as much data as is |
18595 | 19175 | available will be written. |
18596 | 19176 | |
18597 | 19177 | =end original |
18598 | 19178 | |
18599 | 19179 | L<write(2)> を使って、指定した FILEHANDLEへ、変数 SCALAR から、LENGTH バイトの |
18600 | 19180 | データの書き込みを試みます。 |
18601 | 19181 | LENGTH が指定されなかった場合、 SCALAR 全体を書き込みます。 |
18602 | これは、バッファ付き IO ルーチンを通 | |
19182 | これは、バッファ付き IO ルーチンを含むどの L<PerlIO> も通らないので | |
18603 | (C< | |
19183 | (しかし、後述するように C<:utf8> の存在の影響を受けます)、他の入力関数、 | |
19184 | 他の入力関数 (C<sysread> 以外), | |
18604 | 19185 | L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>, |
18605 | 19186 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>, |
18606 | 19187 | L<C<eof>|/eof FILEHANDLE> と混ぜて使うと、出力がおかしくなるかもしれません; |
18607 | perlio 層と | |
19188 | C<:perlio> 層と C<:crlf> 層は普通データをバッファリングするからです。 | |
18608 | 19189 | 実際に読み込まれたデータの長さか、エラー時には L<C<undef>|/undef EXPR> が |
18609 | 19190 | 返されます(この場合エラー変数 L<C<$!>|perlvar/$!> もセットされます)。 |
18610 | 19191 | LENGTH が OFFSET 以降の SCALAR の利用可能なデータより大きかった場合、 |
18611 | 19192 | 利用可能なデータのみが書き込まれます。 |
18612 | 19193 | |
18613 | 19194 | =begin original |
18614 | 19195 | |
18615 | 19196 | An OFFSET may be specified to write the data from some part of the |
18616 | 19197 | string other than the beginning. A negative OFFSET specifies writing |
18617 | 19198 | that many characters counting backwards from the end of the string. |
18618 | 19199 | If SCALAR is of length zero, you can only use an OFFSET of 0. |
18619 | 19200 | |
18620 | 19201 | =end original |
18621 | 19202 | |
18622 | 19203 | OFFSET を指定すると、SCALAR の先頭以外の場所から、 |
18623 | 19204 | データを取り出して、書き込みを行なうことができます。 |
18624 | 19205 | OFFSET に負の値を指定すると、文字列の最後から逆向きに数えて |
18625 | 19206 | 何バイト目から書き込むかを示します。 |
18626 | 19207 | SCALAR の長さが 0 の場合、OFFSET は 0 のみ使用できます。 |
18627 | 19208 | |
18628 | 19209 | =begin original |
18629 | 19210 | |
18630 | B<WARNING>: If the filehandle is marked C<:utf8>, | |
19211 | B<WARNING>: If the filehandle is marked C<:utf8>, C<syswrite> will raise an exception. | |
18631 | encoded in UTF-8 are written instead of bytes, and the LENGTH, OFFSET, and | |
18632 | return value of L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> | |
18633 | are in (UTF8-encoded Unicode) characters. | |
18634 | 19212 | The C<:encoding(...)> layer implicitly introduces the C<:utf8> layer. |
18635 | 19213 | Alternately, if the handle is not marked with an encoding but you |
18636 | 19214 | attempt to write characters with code points over 255, raises an exception. |
18637 | 19215 | See L<C<binmode>|/binmode FILEHANDLE, LAYER>, |
18638 | L<C<open>|/open FILEHANDLE,EXPR>, and the L<open> pragma. | |
19216 | L<C<open>|/open FILEHANDLE,MODE,EXPR>, and the L<open> pragma. | |
18639 | 19217 | |
18640 | 19218 | =end original |
18641 | 19219 | |
18642 | B<警告>: ファイルハンドルが C<:utf8> であるとマークが付けられると、 | |
19220 | B<警告>: ファイルハンドルが C<:utf8> であるとマークが付けられていると、 | |
18643 | ||
19221 | C<syswrite> は例外を投げます。 | |
18644 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> の LENGTH, OFFSET | |
18645 | および返り値は (UTF8 エンコードされた Unicode) 文字単位になります。 | |
18646 | 19222 | C<:encoding(...)> 層は暗黙のうちに C<:utf8> 層が導入されます。 |
18647 | 19223 | または、もしハンドルにエンコーディングが記録されていない状態で |
18648 | 19224 | 255 を超える符号位置の文字を書き込もうとすると、例外が発生します。 |
18649 | L<C<binmode>|/binmode FILEHANDLE, LAYER>, | |
19225 | L<C<binmode>|/binmode FILEHANDLE, LAYER>, | |
19226 | L<C<open>|/open FILEHANDLE,MODE,EXPR>, | |
18650 | 19227 | L<open> プラグマを参照してください。 |
18651 | 19228 | |
18652 | 19229 | =item tell FILEHANDLE |
18653 | 19230 | X<tell> |
18654 | 19231 | |
18655 | 19232 | =item tell |
18656 | 19233 | |
18657 | 19234 | =for Pod::Functions get current seekpointer on a filehandle |
18658 | 19235 | |
18659 | 19236 | =begin original |
18660 | 19237 | |
18661 | 19238 | Returns the current position I<in bytes> for FILEHANDLE, or -1 on |
18662 | 19239 | error. FILEHANDLE may be an expression whose value gives the name of |
18663 | 19240 | the actual filehandle. If FILEHANDLE is omitted, assumes the file |
18664 | 19241 | last read. |
18665 | 19242 | |
18666 | 19243 | =end original |
18667 | 19244 | |
18668 | 19245 | FILEHANDLE の現在の位置を I<バイト数で> 返します; エラーの場合は -1 を |
18669 | 19246 | 返します。 |
18670 | 19247 | FILEHANDLE は、実際のファイルハンドル名を示す式でもかまいません。 |
18671 | 19248 | FILEHANDLE が省略された場合には、最後に読み込みを行なったファイルについて |
18672 | 19249 | 調べます。 |
18673 | 19250 | |
18674 | 19251 | =begin original |
18675 | 19252 | |
18676 | 19253 | Note the emphasis on bytes: even if the filehandle has been set to operate |
18677 | 19254 | on characters (for example using the C<:encoding(UTF-8)> I/O layer), the |
18678 | 19255 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, |
18679 | 19256 | L<C<tell>|/tell FILEHANDLE>, and |
18680 | 19257 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> |
18681 | 19258 | family of functions use byte offsets, not character offsets, |
18682 | 19259 | because seeking to a character offset would be very slow in a UTF-8 file. |
18683 | 19260 | |
18684 | 19261 | =end original |
18685 | 19262 | |
18686 | 19263 | バイト単位に対する注意: 例え(例えば C<:encoding(UTF-8)> I/O 層を使うなどして) |
18687 | 19264 | ファイルハンドルが文字単位で処理するように設定されていたとしても、 |
18688 | 19265 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, |
18689 | 19266 | L<C<tell>|/tell FILEHANDLE>, |
18690 | 19267 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> シリーズの関数は |
18691 | 19268 | 文字オフセットではなくバイトオフセットを使います; |
18692 | 19269 | 文字オフセットでシークするのは UTF-8 ファイルではとても遅いからです。 |
18693 | 19270 | |
18694 | 19271 | =begin original |
18695 | 19272 | |
18696 | 19273 | The return value of L<C<tell>|/tell FILEHANDLE> for the standard streams |
18697 | 19274 | like the STDIN depends on the operating system: it may return -1 or |
18698 | 19275 | something else. L<C<tell>|/tell FILEHANDLE> on pipes, fifos, and |
18699 | 19276 | sockets usually returns -1. |
18700 | 19277 | |
18701 | 19278 | =end original |
18702 | 19279 | |
18703 | 19280 | STDIN のような標準ストリームに対する L<C<tell>|/tell FILEHANDLE> の返り値は |
18704 | 19281 | OS に依存します: |
18705 | 19282 | -1 やその他の値が返ってくるかもしれません。 |
18706 | 19283 | パイプ、FIFO、ソケットに対して L<C<tell>|/tell FILEHANDLE> を使うと、普通は |
18707 | 19284 | -1 が返ります。 |
18708 | 19285 | |
18709 | 19286 | =begin original |
18710 | 19287 | |
18711 | 19288 | There is no C<systell> function. Use |
18712 | 19289 | L<C<sysseek($fh, 0, 1)>|/sysseek FILEHANDLE,POSITION,WHENCE> for that. |
18713 | 19290 | |
18714 | 19291 | =end original |
18715 | 19292 | |
18716 | 19293 | C<systell> 関数はありません。 |
18717 | 19294 | 代わりに L<C<sysseek($fh, 0, 1)>|/sysseek FILEHANDLE,POSITION,WHENCE> を |
18718 | 19295 | 使ってください。 |
18719 | 19296 | |
18720 | 19297 | =begin original |
18721 | 19298 | |
18722 | 19299 | Do not use L<C<tell>|/tell FILEHANDLE> (or other buffered I/O |
18723 | 19300 | operations) on a filehandle that has been manipulated by |
18724 | 19301 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, |
18725 | 19302 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, or |
18726 | 19303 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>. Those functions |
18727 | 19304 | ignore the buffering, while L<C<tell>|/tell FILEHANDLE> does not. |
18728 | 19305 | |
18729 | 19306 | =end original |
18730 | 19307 | |
18731 | 19308 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, |
18732 | 19309 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, |
18733 | 19310 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> で操作された |
18734 | 19311 | ファイルハンドルに L<C<tell>|/tell FILEHANDLE> |
18735 | 19312 | (またはその他のバッファリング I/O 操作) を使わないでください。 |
18736 | 19313 | これらの関数はバッファリングを無視しますが、L<C<tell>|/tell FILEHANDLE> は |
18737 | 19314 | 違います。 |
18738 | 19315 | |
18739 | 19316 | =item telldir DIRHANDLE |
18740 | 19317 | X<telldir> |
18741 | 19318 | |
18742 | 19319 | =for Pod::Functions get current seekpointer on a directory handle |
18743 | 19320 | |
18744 | 19321 | =begin original |
18745 | 19322 | |
18746 | 19323 | Returns the current position of the L<C<readdir>|/readdir DIRHANDLE> |
18747 | 19324 | routines on DIRHANDLE. Value may be given to |
18748 | 19325 | L<C<seekdir>|/seekdir DIRHANDLE,POS> to access a particular location in |
18749 | 19326 | a directory. L<C<telldir>|/telldir DIRHANDLE> has the same caveats |
18750 | 19327 | about possible directory compaction as the corresponding system library |
18751 | 19328 | routine. |
18752 | 19329 | |
18753 | 19330 | =end original |
18754 | 19331 | |
18755 | 19332 | DIRHANDLE 上の L<C<readdir>|/readdir DIRHANDLE> ルーチンに対する現在位置を |
18756 | 19333 | 返します。 |
18757 | 19334 | 値は、そのディレクトリで特定の位置をアクセスするため、 |
18758 | 19335 | L<C<seekdir>|/seekdir DIRHANDLE,POS> に渡すことができます。 |
18759 | 19336 | L<C<telldir>|/telldir DIRHANDLE> は同名のシステムライブラリルーチンと同じく、 |
18760 | 19337 | ディレクトリ縮小時の問題が考えられます。 |
18761 | 19338 | |
18762 | 19339 | =item tie VARIABLE,CLASSNAME,LIST |
18763 | 19340 | X<tie> |
18764 | 19341 | |
18765 | 19342 | =for Pod::Functions +5.002 bind a variable to an object class |
18766 | 19343 | |
18767 | 19344 | =begin original |
18768 | 19345 | |
18769 | 19346 | This function binds a variable to a package class that will provide the |
18770 | 19347 | implementation for the variable. VARIABLE is the name of the variable |
18771 | 19348 | to be enchanted. CLASSNAME is the name of a class implementing objects |
18772 | 19349 | of correct type. Any additional arguments are passed to the |
18773 | 19350 | appropriate constructor |
18774 | 19351 | method of the class (meaning C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>, |
18775 | 19352 | or C<TIEHASH>). Typically these are arguments such as might be passed |
18776 | 19353 | to the L<dbm_open(3)> function of C. The object returned by the |
18777 | 19354 | constructor is also returned by the |
18778 | 19355 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function, which would be useful |
18779 | 19356 | if you want to access other methods in CLASSNAME. |
18780 | 19357 | |
18781 | 19358 | =end original |
18782 | 19359 | |
18783 | 19360 | この関数は、変数を、その変数の実装を行なうクラスと結び付けます。 |
18784 | 19361 | VARIABLE は、魔法をかける変数の名前です。 |
18785 | 19362 | CLASSNAME は、正しい型のオブジェクトを実装するクラスの名前です。 |
18786 | 19363 | 他に引数があれば、そのクラスの適切なコンストラクタメソッドに渡されます |
18787 | 19364 | (つまり C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>, C<TIEHASH>)。 |
18788 | 19365 | 通常、これらは、C の L<dbm_open(3)> などの関数に渡す引数となります。 |
18789 | 19366 | コンストラクタで返されるオブジェクトはまた |
18790 | 19367 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数でも返されます; |
18791 | 19368 | これは CLASSNAME の他のメソッドにアクセスしたいときに便利です。 |
18792 | 19369 | |
18793 | 19370 | =begin original |
18794 | 19371 | |
18795 | 19372 | Note that functions such as L<C<keys>|/keys HASH> and |
18796 | 19373 | L<C<values>|/values HASH> may return huge lists when used on large |
18797 | 19374 | objects, like DBM files. You may prefer to use the L<C<each>|/each |
18798 | 19375 | HASH> function to iterate over such. Example: |
18799 | 19376 | |
18800 | 19377 | =end original |
18801 | 19378 | |
18802 | 19379 | DBM ファイルのような大きなオブジェクトでは、L<C<keys>|/keys HASH> や |
18803 | 19380 | L<C<values>|/values HASH> のような関数は、大きなリストを返す可能性があります。 |
18804 | 19381 | そのような場合では、L<C<each>|/each HASH> 関数を使って繰り返しを行なった方が |
18805 | 19382 | よいかもしれません。 |
18806 | 19383 | 例: |
18807 | 19384 | |
18808 | 19385 | # print out history file offsets |
18809 | 19386 | use NDBM_File; |
18810 | 19387 | tie(my %HIST, 'NDBM_File', '/usr/lib/news/history', 1, 0); |
18811 | 19388 | while (my ($key,$val) = each %HIST) { |
18812 | 19389 | print $key, ' = ', unpack('L', $val), "\n"; |
18813 | 19390 | } |
18814 | 19391 | |
18815 | 19392 | =begin original |
18816 | 19393 | |
18817 | 19394 | A class implementing a hash should have the following methods: |
18818 | 19395 | |
18819 | 19396 | =end original |
18820 | 19397 | |
18821 | 19398 | ハッシュを実装するクラスでは、次のようなメソッドを用意します: |
18822 | 19399 | |
18823 | 19400 | TIEHASH classname, LIST |
18824 | 19401 | FETCH this, key |
18825 | 19402 | STORE this, key, value |
18826 | 19403 | DELETE this, key |
18827 | 19404 | CLEAR this |
18828 | 19405 | EXISTS this, key |
18829 | 19406 | FIRSTKEY this |
18830 | 19407 | NEXTKEY this, lastkey |
18831 | 19408 | SCALAR this |
18832 | 19409 | DESTROY this |
18833 | 19410 | UNTIE this |
18834 | 19411 | |
18835 | 19412 | =begin original |
18836 | 19413 | |
18837 | 19414 | A class implementing an ordinary array should have the following methods: |
18838 | 19415 | |
18839 | 19416 | =end original |
18840 | 19417 | |
18841 | 19418 | 通常の配列を実装するクラスでは、次のようなメソッドを用意します: |
18842 | 19419 | |
18843 | 19420 | TIEARRAY classname, LIST |
18844 | 19421 | FETCH this, key |
18845 | 19422 | STORE this, key, value |
18846 | 19423 | FETCHSIZE this |
18847 | 19424 | STORESIZE this, count |
18848 | 19425 | CLEAR this |
18849 | 19426 | PUSH this, LIST |
18850 | 19427 | POP this |
18851 | 19428 | SHIFT this |
18852 | 19429 | UNSHIFT this, LIST |
18853 | 19430 | SPLICE this, offset, length, LIST |
18854 | 19431 | EXTEND this, count |
18855 | 19432 | DELETE this, key |
18856 | 19433 | EXISTS this, key |
18857 | 19434 | DESTROY this |
18858 | 19435 | UNTIE this |
18859 | 19436 | |
18860 | 19437 | =begin original |
18861 | 19438 | |
18862 | 19439 | A class implementing a filehandle should have the following methods: |
18863 | 19440 | |
18864 | 19441 | =end original |
18865 | 19442 | |
18866 | 19443 | ファイルハンドルを実装するクラスでは、次のようなメソッドを用意します: |
18867 | 19444 | |
18868 | 19445 | TIEHANDLE classname, LIST |
18869 | 19446 | READ this, scalar, length, offset |
18870 | 19447 | READLINE this |
18871 | 19448 | GETC this |
18872 | 19449 | WRITE this, scalar, length, offset |
18873 | 19450 | PRINT this, LIST |
18874 | 19451 | PRINTF this, format, LIST |
18875 | 19452 | BINMODE this |
18876 | 19453 | EOF this |
18877 | 19454 | FILENO this |
18878 | 19455 | SEEK this, position, whence |
18879 | 19456 | TELL this |
18880 | 19457 | OPEN this, mode, LIST |
18881 | 19458 | CLOSE this |
18882 | 19459 | DESTROY this |
18883 | 19460 | UNTIE this |
18884 | 19461 | |
18885 | 19462 | =begin original |
18886 | 19463 | |
18887 | 19464 | A class implementing a scalar should have the following methods: |
18888 | 19465 | |
18889 | 19466 | =end original |
18890 | 19467 | |
18891 | 19468 | スカラ変数を実装するクラスでは、次のようなメソッドを用意します: |
18892 | 19469 | |
18893 | 19470 | TIESCALAR classname, LIST |
18894 | 19471 | FETCH this, |
18895 | 19472 | STORE this, value |
18896 | 19473 | DESTROY this |
18897 | 19474 | UNTIE this |
18898 | 19475 | |
18899 | 19476 | =begin original |
18900 | 19477 | |
18901 | 19478 | Not all methods indicated above need be implemented. See L<perltie>, |
18902 | 19479 | L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>, and L<Tie::Handle>. |
18903 | 19480 | |
18904 | 19481 | =end original |
18905 | 19482 | |
18906 | 19483 | 上記の全てのメソッドを実装する必要はありません。 |
18907 | 19484 | L<perltie>, L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>, |
18908 | 19485 | L<Tie::Handle> を参照してください。 |
18909 | 19486 | |
18910 | 19487 | =begin original |
18911 | 19488 | |
18912 | 19489 | Unlike L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, the |
18913 | 19490 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function will not |
18914 | 19491 | L<C<use>|/use Module VERSION LIST> or L<C<require>|/require VERSION> a |
18915 | 19492 | module for you; you need to do that explicitly yourself. See L<DB_File> |
18916 | 19493 | or the L<Config> module for interesting |
18917 | 19494 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> implementations. |
18918 | 19495 | |
18919 | 19496 | =end original |
18920 | 19497 | |
18921 | 19498 | L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> と違い、 |
18922 | 19499 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数はモジュールを |
18923 | 19500 | L<C<use>|/use Module VERSION LIST> したり |
18924 | 19501 | L<C<require>|/require VERSION> したりしません; |
18925 | 19502 | 自分で明示的に行う必要があります。 |
18926 | 19503 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> の興味深い実装については |
18927 | 19504 | L<DB_File> や L<Config> モジュールを参照してください。 |
18928 | 19505 | |
18929 | 19506 | =begin original |
18930 | 19507 | |
18931 | 19508 | For further details see L<perltie>, L<C<tied>|/tied VARIABLE>. |
18932 | 19509 | |
18933 | 19510 | =end original |
18934 | 19511 | |
18935 | 19512 | 更なる詳細については L<perltie> や L<C<tied>|/tied VARIABLE> を |
18936 | 19513 | 参照してください。 |
18937 | 19514 | |
18938 | 19515 | =item tied VARIABLE |
18939 | 19516 | X<tied> |
18940 | 19517 | |
18941 | 19518 | =for Pod::Functions get a reference to the object underlying a tied variable |
18942 | 19519 | |
18943 | 19520 | =begin original |
18944 | 19521 | |
18945 | 19522 | Returns a reference to the object underlying VARIABLE (the same value |
18946 | 19523 | that was originally returned by the |
18947 | 19524 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> call that bound the variable |
18948 | 19525 | to a package.) Returns the undefined value if VARIABLE isn't tied to a |
18949 | 19526 | package. |
18950 | 19527 | |
18951 | 19528 | =end original |
18952 | 19529 | |
18953 | 19530 | VARIABLE の基となるオブジェクトへのリファレンスを返します |
18954 | 19531 | (変数をパッケージに結びつけるために |
18955 | 19532 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 呼び出しをしたときの |
18956 | 19533 | 返り値と同じものです)。 |
18957 | 19534 | VARIABLE がパッケージと結び付けられていない場合は未定義値を返します。 |
18958 | 19535 | |
18959 | 19536 | =item time |
18960 | 19537 | X<time> X<epoch> |
18961 | 19538 | |
18962 | 19539 | =for Pod::Functions return number of seconds since 1970 |
18963 | 19540 | |
18964 | 19541 | =begin original |
18965 | 19542 | |
18966 | 19543 | Returns the number of non-leap seconds since whatever time the system |
18967 | 19544 | considers to be the epoch, suitable for feeding to |
18968 | 19545 | L<C<gmtime>|/gmtime EXPR> and L<C<localtime>|/localtime EXPR>. On most |
18969 | 19546 | systems the epoch is 00:00:00 UTC, January 1, 1970; |
18970 | 19547 | a prominent exception being Mac OS Classic which uses 00:00:00, January 1, |
18971 | 19548 | 1904 in the current local time zone for its epoch. |
18972 | 19549 | |
18973 | 19550 | =end original |
18974 | 19551 | |
18975 | 19552 | L<C<gmtime>|/gmtime EXPR> や L<C<localtime>|/localtime EXPR> への入力形式に |
18976 | 19553 | 合っている、システムが紀元と考える時点からの連続秒数を返します。 |
18977 | 19554 | ほとんどのシステムでは紀元は UTC 1970 年 1 月 1 日 00:00:00 です; |
18978 | 19555 | 特徴的な例外としては、古い Mac OS ではローカルタイムゾーンの |
18979 | 19556 | 1904 年 1 月 1 日 00:00:00 を紀元として使います。 |
18980 | 19557 | |
18981 | 19558 | =begin original |
18982 | 19559 | |
18983 | 19560 | For measuring time in better granularity than one second, use the |
18984 | 19561 | L<Time::HiRes> module from Perl 5.8 onwards (or from CPAN before then), or, |
18985 | 19562 | if you have L<gettimeofday(2)>, you may be able to use the |
18986 | 19563 | L<C<syscall>|/syscall NUMBER, LIST> interface of Perl. See L<perlfaq8> |
18987 | 19564 | for details. |
18988 | 19565 | |
18989 | 19566 | =end original |
18990 | 19567 | |
18991 | 19568 | 1 秒よりも細かい時間を計測するためには、Perl 5.8 以降(それ以前では |
18992 | 19569 | CPANから)の L<Time::HiRes> モジュールを使うか、 |
18993 | 19570 | L<gettimeofday(2)> があるなら、Perl の |
18994 | 19571 | L<C<syscall>|/syscall NUMBER, LIST> インターフェースを使ってください。 |
18995 | 19572 | 詳しくは L<perlfaq8> を参照してください。 |
18996 | 19573 | |
18997 | 19574 | =begin original |
18998 | 19575 | |
18999 | 19576 | For date and time processing look at the many related modules on CPAN. |
19000 | 19577 | For a comprehensive date and time representation look at the |
19001 | 19578 | L<DateTime> module. |
19002 | 19579 | |
19003 | 19580 | =end original |
19004 | 19581 | |
19005 | 19582 | 日付と時刻の処理は、多くの関連するモジュールが CPAN にあります。 |
19006 | 19583 | 包括的な日付と時刻の表現については、CPAN の L<DateTime> モジュールを |
19007 | 19584 | 参照してください。 |
19008 | 19585 | |
19009 | 19586 | =item times |
19010 | 19587 | X<times> |
19011 | 19588 | |
19012 | 19589 | =for Pod::Functions return elapsed time for self and child processes |
19013 | 19590 | |
19014 | 19591 | =begin original |
19015 | 19592 | |
19016 | 19593 | Returns a four-element list giving the user and system times in |
19017 | 19594 | seconds for this process and any exited children of this process. |
19018 | 19595 | |
19019 | 19596 | =end original |
19020 | 19597 | |
19021 | 19598 | 現プロセス及び終了したその子プロセスに対する、ユーザ時間とシステム時間を |
19022 | 19599 | 秒で示した、4 要素のリスト値を返します。 |
19023 | 19600 | |
19024 | 19601 | my ($user,$system,$cuser,$csystem) = times; |
19025 | 19602 | |
19026 | 19603 | =begin original |
19027 | 19604 | |
19028 | 19605 | In scalar context, L<C<times>|/times> returns C<$user>. |
19029 | 19606 | |
19030 | 19607 | =end original |
19031 | 19608 | |
19032 | 19609 | スカラコンテキストでは、L<C<times>|/times> は C<$user> を返します。 |
19033 | 19610 | |
19034 | 19611 | =begin original |
19035 | 19612 | |
19036 | 19613 | Children's times are only included for terminated children. |
19037 | 19614 | |
19038 | 19615 | =end original |
19039 | 19616 | |
19040 | 19617 | 子プロセスに対する times は、終了した子プロセスのみ含められます。 |
19041 | 19618 | |
19042 | 19619 | =begin original |
19043 | 19620 | |
19044 | 19621 | Portability issues: L<perlport/times>. |
19045 | 19622 | |
19046 | 19623 | =end original |
19047 | 19624 | |
19048 | 19625 | 移植性の問題: L<perlport/times>。 |
19049 | 19626 | |
19050 | 19627 | =item tr/// |
19051 | 19628 | |
19052 | 19629 | =for Pod::Functions transliterate a string |
19053 | 19630 | |
19054 | 19631 | =begin original |
19055 | 19632 | |
19056 | 19633 | The transliteration operator. Same as |
19057 | 19634 | L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>>. See |
19058 | 19635 | L<perlop/"Quote-Like Operators">. |
19059 | 19636 | |
19060 | 19637 | =end original |
19061 | 19638 | |
19062 | 19639 | 文字変換演算子です。 |
19063 | 19640 | L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>> と同じです。 |
19064 | 19641 | L<perlop/"Quote-Like Operators"> を参照してください。 |
19065 | 19642 | |
19066 | 19643 | =item truncate FILEHANDLE,LENGTH |
19067 | 19644 | X<truncate> |
19068 | 19645 | |
19069 | 19646 | =item truncate EXPR,LENGTH |
19070 | 19647 | |
19071 | 19648 | =for Pod::Functions shorten a file |
19072 | 19649 | |
19073 | 19650 | =begin original |
19074 | 19651 | |
19075 | 19652 | Truncates the file opened on FILEHANDLE, or named by EXPR, to the |
19076 | 19653 | specified length. Raises an exception if truncate isn't implemented |
19077 | 19654 | on your system. Returns true if successful, L<C<undef>|/undef EXPR> on |
19078 | 19655 | error. |
19079 | 19656 | |
19080 | 19657 | =end original |
19081 | 19658 | |
19082 | 19659 | FILEHANDLE 上にオープンされたファイルか、EXPR で名前を表わしたファイルを、 |
19083 | 19660 | 指定した長さに切り詰めます。 |
19084 | 19661 | システム上に truncate が実装されていなければ、例外が発生します。 |
19085 | 19662 | 成功すれば真を、エラー時には L<C<undef>|/undef EXPR> を返します。 |
19086 | 19663 | |
19087 | 19664 | =begin original |
19088 | 19665 | |
19089 | 19666 | The behavior is undefined if LENGTH is greater than the length of the |
19090 | 19667 | file. |
19091 | 19668 | |
19092 | 19669 | =end original |
19093 | 19670 | |
19094 | 19671 | LENGTH がファイルの長さより大きい場合の振る舞いは未定義です。 |
19095 | 19672 | |
19096 | 19673 | =begin original |
19097 | 19674 | |
19098 | 19675 | The position in the file of FILEHANDLE is left unchanged. You may want to |
19099 | 19676 | call L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> before writing to the |
19100 | 19677 | file. |
19101 | 19678 | |
19102 | 19679 | =end original |
19103 | 19680 | |
19104 | 19681 | FILEHANDLE のファイルの位置は変わりません。 |
19105 | 19682 | ファイルに書き込む前に L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> を |
19106 | 19683 | 呼び出したいかもしれません。 |
19107 | 19684 | |
19108 | 19685 | =begin original |
19109 | 19686 | |
19110 | 19687 | Portability issues: L<perlport/truncate>. |
19111 | 19688 | |
19112 | 19689 | =end original |
19113 | 19690 | |
19114 | 19691 | 移植性の問題: L<perlport/truncate>。 |
19115 | 19692 | |
19116 | 19693 | =item uc EXPR |
19117 | 19694 | X<uc> X<uppercase> X<toupper> |
19118 | 19695 | |
19119 | 19696 | =item uc |
19120 | 19697 | |
19121 | 19698 | =for Pod::Functions return upper-case version of a string |
19122 | 19699 | |
19123 | 19700 | =begin original |
19124 | 19701 | |
19125 | 19702 | Returns an uppercased version of EXPR. This is the internal function |
19126 | 19703 | implementing the C<\U> escape in double-quoted strings. |
19127 | 19704 | It does not attempt to do titlecase mapping on initial letters. See |
19128 | 19705 | L<C<ucfirst>|/ucfirst EXPR> for that. |
19129 | 19706 | |
19130 | 19707 | =end original |
19131 | 19708 | |
19132 | 19709 | EXPR を大文字に変換したものを返します。 |
19133 | 19710 | これは、ダブルクォート文字列における、C<\U> エスケープを |
19134 | 19711 | 実装する内部関数です。 |
19135 | 19712 | 先頭文字の タイトル文字マッピングは試みません。 |
19136 | 19713 | このためには L<C<ucfirst>|/ucfirst EXPR> を参照してください。 |
19137 | 19714 | |
19138 | 19715 | =begin original |
19139 | 19716 | |
19140 | 19717 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. |
19141 | 19718 | |
19142 | 19719 | =end original |
19143 | 19720 | |
19144 | 19721 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 |
19145 | 19722 | |
19146 | 19723 | =begin original |
19147 | 19724 | |
19148 | 19725 | This function behaves the same way under various pragmas, such as in a locale, |
19149 | 19726 | as L<C<lc>|/lc EXPR> does. |
19150 | 19727 | |
19151 | 19728 | =end original |
19152 | 19729 | |
19153 | 19730 | この関数は、ロケールのようなさまざまなプラグマの影響下では、 |
19154 | 19731 | L<C<lc>|/lc EXPR> と同様に振る舞います。 |
19155 | 19732 | |
19156 | 19733 | =item ucfirst EXPR |
19157 | 19734 | X<ucfirst> X<uppercase> |
19158 | 19735 | |
19159 | 19736 | =item ucfirst |
19160 | 19737 | |
19161 | 19738 | =for Pod::Functions return a string with just the next letter in upper case |
19162 | 19739 | |
19163 | 19740 | =begin original |
19164 | 19741 | |
19165 | 19742 | Returns the value of EXPR with the first character in uppercase |
19166 | 19743 | (titlecase in Unicode). This is the internal function implementing |
19167 | 19744 | the C<\u> escape in double-quoted strings. |
19168 | 19745 | |
19169 | 19746 | =end original |
19170 | 19747 | |
19171 | 19748 | 最初の文字だけを大文字にした、EXPR を返します |
19172 | 19749 | (Unicode では titlecase)。 |
19173 | 19750 | これは、ダブルクォート文字列における、C<\u> エスケープを |
19174 | 19751 | 実装する内部関数です。 |
19175 | 19752 | |
19176 | 19753 | =begin original |
19177 | 19754 | |
19178 | 19755 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. |
19179 | 19756 | |
19180 | 19757 | =end original |
19181 | 19758 | |
19182 | 19759 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 |
19183 | 19760 | |
19184 | 19761 | =begin original |
19185 | 19762 | |
19186 | 19763 | This function behaves the same way under various pragmas, such as in a locale, |
19187 | 19764 | as L<C<lc>|/lc EXPR> does. |
19188 | 19765 | |
19189 | 19766 | =end original |
19190 | 19767 | |
19191 | 19768 | この関数は、ロケールのようなさまざまなプラグマの影響下では、 |
19192 | 19769 | L<C<lc>|/lc EXPR> と同様に振る舞います。 |
19193 | 19770 | |
19194 | 19771 | =item umask EXPR |
19195 | 19772 | X<umask> |
19196 | 19773 | |
19197 | 19774 | =item umask |
19198 | 19775 | |
19199 | 19776 | =for Pod::Functions set file creation mode mask |
19200 | 19777 | |
19201 | 19778 | =begin original |
19202 | 19779 | |
19203 | 19780 | Sets the umask for the process to EXPR and returns the previous value. |
19204 | 19781 | If EXPR is omitted, merely returns the current umask. |
19205 | 19782 | |
19206 | 19783 | =end original |
19207 | 19784 | |
19208 | 19785 | 現在のプロセスの umask を EXPR に設定し、以前の値を返します。 |
19209 | 19786 | EXPR が省略されると、単にその時点の umask の値を返します。 |
19210 | 19787 | |
19211 | 19788 | =begin original |
19212 | 19789 | |
19213 | 19790 | The Unix permission C<rwxr-x---> is represented as three sets of three |
19214 | 19791 | bits, or three octal digits: C<0750> (the leading 0 indicates octal |
19215 | 19792 | and isn't one of the digits). The L<C<umask>|/umask EXPR> value is such |
19216 | 19793 | a number representing disabled permissions bits. The permission (or |
19217 | "mode") values you pass L<C<mkdir>|/mkdir FILENAME,M | |
19794 | "mode") values you pass L<C<mkdir>|/mkdir FILENAME,MODE> or | |
19218 | 19795 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> are modified by your |
19219 | 19796 | umask, so even if you tell |
19220 | 19797 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> to create a file with |
19221 | 19798 | permissions C<0777>, if your umask is C<0022>, then the file will |
19222 | 19799 | actually be created with permissions C<0755>. If your |
19223 | 19800 | L<C<umask>|/umask EXPR> were C<0027> (group can't write; others can't |
19224 | 19801 | read, write, or execute), then passing |
19225 | 19802 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> C<0666> would create a |
19226 | 19803 | file with mode C<0640> (because C<0666 &~ 027> is C<0640>). |
19227 | 19804 | |
19228 | 19805 | =end original |
19229 | 19806 | |
19230 | 19807 | Unix パーミッション C<rwxr-x---> は 3 ビットの三つの組、 |
19231 | 19808 | または 3 桁の 8 進数として表現されます: |
19232 | 19809 | C<0750> (先頭の 0 は 8 進数を意味し、実際の値ではありません)。 |
19233 | 19810 | L<C<umask>|/umask EXPR> の値は無効にするパーミッションビットのこのような |
19234 | 19811 | 数値表現です。 |
19235 | L<C<mkdir>|/mkdir FILENAME,M | |
19812 | L<C<mkdir>|/mkdir FILENAME,MODE> や | |
19236 | 19813 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> で渡されたパーミッション |
19237 | 19814 | (または「モード」)の値は umask で修正され、たとえ |
19238 | 19815 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> で C<0777> のパーミッションで |
19239 | 19816 | ファイルを作るように指定しても、umask が C<0022> なら、 |
19240 | 19817 | 結果としてファイルは C<0755> のパーミッションで作成されます。 |
19241 | 19818 | L<C<umask>|/umask EXPR> が C<0027> (グループは書き込めない; その他は読み込み、 |
19242 | 19819 | 書き込み、実行できない) のとき |
19243 | 19820 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> に C<0666> を渡すと、 |
19244 | 19821 | ファイルはモード C<0640> (なぜなら C<0666 &~ 027> は C<0640>)で作成されます。 |
19245 | 19822 | |
19246 | 19823 | =begin original |
19247 | 19824 | |
19248 | 19825 | Here's some advice: supply a creation mode of C<0666> for regular |
19249 | 19826 | files (in L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>) and one of |
19250 | C<0777> for directories (in L<C<mkdir>|/mkdir FILENAME,M | |
19827 | C<0777> for directories (in L<C<mkdir>|/mkdir FILENAME,MODE>) and | |
19251 | 19828 | executable files. This gives users the freedom of |
19252 | 19829 | choice: if they want protected files, they might choose process umasks |
19253 | 19830 | of C<022>, C<027>, or even the particularly antisocial mask of C<077>. |
19254 | 19831 | Programs should rarely if ever make policy decisions better left to |
19255 | 19832 | the user. The exception to this is when writing files that should be |
19256 | 19833 | kept private: mail files, web browser cookies, F<.rhosts> files, and |
19257 | 19834 | so on. |
19258 | 19835 | |
19259 | 19836 | =end original |
19260 | 19837 | |
19261 | 19838 | 以下は助言です: 作成モードとして、 |
19262 | 19839 | (L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> による)通常ファイルでは |
19263 | C<0666> を、(L<C<mkdir>|/mkdir FILENAME,M | |
19840 | C<0666> を、(L<C<mkdir>|/mkdir FILENAME,MODE> による)ディレクトリでは | |
19264 | 19841 | C<0777> を指定しましょう。 |
19265 | 19842 | これにより、ユーザーに選択の自由を与えます: もしファイルを守りたいなら、 |
19266 | 19843 | プロセスの umask として C<022>, C<027>, あるいは特に非社交的な |
19267 | 19844 | C<077> を選択できます。 |
19268 | 19845 | プログラムがユーザーより適切なポリシー選択ができることは稀です。 |
19269 | 19846 | 例外は、プライベートに保つべきファイル(メール、ウェブブラウザのクッキー、 |
19270 | 19847 | F<.rhosts> ファイルなど)を書く場合です。 |
19271 | 19848 | |
19272 | 19849 | =begin original |
19273 | 19850 | |
19274 | 19851 | If L<umask(2)> is not implemented on your system and you are trying to |
19275 | 19852 | restrict access for I<yourself> (i.e., C<< (EXPR & 0700) > 0 >>), |
19276 | 19853 | raises an exception. If L<umask(2)> is not implemented and you are |
19277 | 19854 | not trying to restrict access for yourself, returns |
19278 | 19855 | L<C<undef>|/undef EXPR>. |
19279 | 19856 | |
19280 | 19857 | =end original |
19281 | 19858 | |
19282 | 19859 | L<umask(2)> が実装されていないシステムで、I<自分自身> へのアクセスを |
19283 | 19860 | 制限しようとした(つまり C<< (EXPR & 0700) > 0 >>)場合、例外が発生します。 |
19284 | 19861 | L<umask(2)> が実装されていないシステムで、自分自身へのアクセスは |
19285 | 19862 | 制限しようとしなかった場合、L<C<undef>|/undef EXPR> を返します。 |
19286 | 19863 | |
19287 | 19864 | =begin original |
19288 | 19865 | |
19289 | 19866 | Remember that a umask is a number, usually given in octal; it is I<not> a |
19290 | 19867 | string of octal digits. See also L<C<oct>|/oct EXPR>, if all you have |
19291 | 19868 | is a string. |
19292 | 19869 | |
19293 | 19870 | =end original |
19294 | 19871 | |
19295 | 19872 | umask は通常 8 進数で与えられる数値であることを忘れないでください; 8 進数の |
19296 | 19873 | 文字列 I<ではありません>。 |
19297 | 19874 | 文字列しかない場合、 L<C<oct>|/oct EXPR> も参照してください。 |
19298 | 19875 | |
19299 | 19876 | =begin original |
19300 | 19877 | |
19301 | 19878 | Portability issues: L<perlport/umask>. |
19302 | 19879 | |
19303 | 19880 | =end original |
19304 | 19881 | |
19305 | 19882 | 移植性の問題: L<perlport/umask>。 |
19306 | 19883 | |
19307 | 19884 | =item undef EXPR |
19308 | 19885 | X<undef> X<undefine> |
19309 | 19886 | |
19310 | 19887 | =item undef |
19311 | 19888 | |
19312 | 19889 | =for Pod::Functions remove a variable or function definition |
19313 | 19890 | |
19314 | 19891 | =begin original |
19315 | 19892 | |
19316 | 19893 | Undefines the value of EXPR, which must be an lvalue. Use only on a |
19317 | 19894 | scalar value, an array (using C<@>), a hash (using C<%>), a subroutine |
19318 | 19895 | (using C<&>), or a typeglob (using C<*>). Saying C<undef $hash{$key}> |
19319 | 19896 | will probably not do what you expect on most predefined variables or |
19320 | 19897 | DBM list values, so don't do that; see L<C<delete>|/delete EXPR>. |
19321 | 19898 | Always returns the undefined value. |
19322 | 19899 | You can omit the EXPR, in which case nothing is |
19323 | 19900 | undefined, but you still get an undefined value that you could, for |
19324 | 19901 | instance, return from a subroutine, assign to a variable, or pass as a |
19325 | 19902 | parameter. Examples: |
19326 | 19903 | |
19327 | 19904 | =end original |
19328 | 19905 | |
19329 | 19906 | 左辺値である EXPR の値を未定義にします。 |
19330 | 19907 | スカラ値、(C<@> を使った)配列、(C<%> を使った)ハッシュ、(C<&> を使った) |
19331 | 19908 | サブルーチン、(C<*> を使った)型グロブだけに使用します。 |
19332 | 19909 | 特殊変数や DBM リスト値に C<undef $hash{$key}> などとしても |
19333 | 19910 | おそらく期待通りの結果にはなりませんから、しないでください; |
19334 | 19911 | L<C<delete>|/delete EXPR> を参照してください。 |
19335 | 19912 | 常に未定義値を返します。 |
19336 | 19913 | EXPR は省略することができ、その場合には何も未定義にされませんが |
19337 | 19914 | 未定義値は返されますので、それをたとえば、 |
19338 | 19915 | サブルーチンの返り値、変数への割り当て、引数などとして使うことができます。 |
19339 | 19916 | 例: |
19340 | 19917 | |
19341 | 19918 | undef $foo; |
19342 | 19919 | undef $bar{'blurfl'}; # Compare to: delete $bar{'blurfl'}; |
19343 | 19920 | undef @ary; |
19344 | 19921 | undef %hash; |
19345 | 19922 | undef &mysub; |
19346 | 19923 | undef *xyz; # destroys $xyz, @xyz, %xyz, &xyz, etc. |
19347 | 19924 | return (wantarray ? (undef, $errmsg) : undef) if $they_blew_it; |
19348 | 19925 | select undef, undef, undef, 0.25; |
19349 | 19926 | my ($x, $y, undef, $z) = foo(); # Ignore third value returned |
19350 | 19927 | |
19351 | 19928 | =begin original |
19352 | 19929 | |
19353 | 19930 | Note that this is a unary operator, not a list operator. |
19354 | 19931 | |
19355 | 19932 | =end original |
19356 | 19933 | |
19357 | 19934 | これはリスト演算子ではなく、単項演算子であることに注意してください。 |
19358 | 19935 | |
19359 | 19936 | =item unlink LIST |
19360 | 19937 | X<unlink> X<delete> X<remove> X<rm> X<del> |
19361 | 19938 | |
19362 | 19939 | =item unlink |
19363 | 19940 | |
19364 | 19941 | =for Pod::Functions remove one link to a file |
19365 | 19942 | |
19366 | 19943 | =begin original |
19367 | 19944 | |
19368 | 19945 | Deletes a list of files. On success, it returns the number of files |
19369 | 19946 | it successfully deleted. On failure, it returns false and sets |
19370 | 19947 | L<C<$!>|perlvar/$!> (errno): |
19371 | 19948 | |
19372 | 19949 | =end original |
19373 | 19950 | |
19374 | 19951 | LIST に含まれるファイルを削除します。 |
19375 | 19952 | 成功時は削除に成功したファイルの数を返します。 |
19376 | 19953 | 失敗時は偽を返して L<C<$!>|perlvar/$!> (error) をセットします: |
19377 | 19954 | |
19378 | 19955 | my $unlinked = unlink 'a', 'b', 'c'; |
19379 | 19956 | unlink @goners; |
19380 | 19957 | unlink glob "*.bak"; |
19381 | 19958 | |
19382 | 19959 | =begin original |
19383 | 19960 | |
19384 | 19961 | On error, L<C<unlink>|/unlink LIST> will not tell you which files it |
19385 | 19962 | could not remove. |
19386 | 19963 | If you want to know which files you could not remove, try them one |
19387 | 19964 | at a time: |
19388 | 19965 | |
19389 | 19966 | =end original |
19390 | 19967 | |
19391 | 19968 | エラーの場合、L<C<unlink>|/unlink LIST> はどのファイルが削除できなかったかを |
19392 | 19969 | 知らせません。 |
19393 | 19970 | どのファイルが削除できなかったかを知りたい場合は、一つずつ削除してください: |
19394 | 19971 | |
19395 | 19972 | foreach my $file ( @goners ) { |
19396 | 19973 | unlink $file or warn "Could not unlink $file: $!"; |
19397 | 19974 | } |
19398 | 19975 | |
19399 | 19976 | =begin original |
19400 | 19977 | |
19401 | 19978 | Note: L<C<unlink>|/unlink LIST> will not attempt to delete directories |
19402 | 19979 | unless you are |
19403 | 19980 | superuser and the B<-U> flag is supplied to Perl. Even if these |
19404 | 19981 | conditions are met, be warned that unlinking a directory can inflict |
19405 | 19982 | damage on your filesystem. Finally, using L<C<unlink>|/unlink LIST> on |
19406 | 19983 | directories is not supported on many operating systems. Use |
19407 | 19984 | L<C<rmdir>|/rmdir FILENAME> instead. |
19408 | 19985 | |
19409 | 19986 | =end original |
19410 | 19987 | |
19411 | 19988 | 注: スーパーユーザ権限で、Perl に B<-U> を付けて実行した場合でなければ、 |
19412 | 19989 | L<C<unlink>|/unlink LIST> はディレクトリを削除しようとすることはありません。 |
19413 | 19990 | この条件にあう場合にも、ディレクトリの削除は、 |
19414 | 19991 | ファイルシステムに多大な損害を与える可能性があります。 |
19415 | 19992 | 最後に、L<C<unlink>|/unlink LIST> をディレクトリに使うのはほとんどの OS では |
19416 | 19993 | 対応していません。 |
19417 | 19994 | 代わりに L<C<rmdir>|/rmdir FILENAME> を使ってください。 |
19418 | 19995 | |
19419 | 19996 | =begin original |
19420 | 19997 | |
19421 | 19998 | If LIST is omitted, L<C<unlink>|/unlink LIST> uses L<C<$_>|perlvar/$_>. |
19422 | 19999 | |
19423 | 20000 | =end original |
19424 | 20001 | |
19425 | 20002 | LIST が省略されると、L<C<unlink>|/unlink LIST> は L<C<$_>|perlvar/$_> を |
19426 | 20003 | 使います。 |
19427 | 20004 | |
19428 | 20005 | =item unpack TEMPLATE,EXPR |
19429 | 20006 | X<unpack> |
19430 | 20007 | |
19431 | 20008 | =item unpack TEMPLATE |
19432 | 20009 | |
19433 | 20010 | =for Pod::Functions convert binary structure into normal perl variables |
19434 | 20011 | |
19435 | 20012 | =begin original |
19436 | 20013 | |
19437 | 20014 | L<C<unpack>|/unpack TEMPLATE,EXPR> does the reverse of |
19438 | 20015 | L<C<pack>|/pack TEMPLATE,LIST>: it takes a string |
19439 | 20016 | and expands it out into a list of values. |
19440 | 20017 | (In scalar context, it returns merely the first value produced.) |
19441 | 20018 | |
19442 | 20019 | =end original |
19443 | 20020 | |
19444 | 20021 | L<C<unpack>|/unpack TEMPLATE,EXPR> は L<C<pack>|/pack TEMPLATE,LIST> の逆を |
19445 | 20022 | 行ないます: 構造体を表わす文字列をとり、 |
19446 | 20023 | リスト値に展開し、その配列値を返します。 |
19447 | 20024 | (スカラコンテキストでは、単に最初の値を返します。) |
19448 | 20025 | |
19449 | 20026 | =begin original |
19450 | 20027 | |
19451 | 20028 | If EXPR is omitted, unpacks the L<C<$_>|perlvar/$_> string. |
19452 | 20029 | See L<perlpacktut> for an introduction to this function. |
19453 | 20030 | |
19454 | 20031 | =end original |
19455 | 20032 | |
19456 | 20033 | EXPR が省略されると、L<C<$_>|perlvar/$_> の文字列を unpack します。 |
19457 | 20034 | この関数の説明については L<perlpacktut> を参照してください。 |
19458 | 20035 | |
19459 | 20036 | =begin original |
19460 | 20037 | |
19461 | 20038 | The string is broken into chunks described by the TEMPLATE. Each chunk |
19462 | 20039 | is converted separately to a value. Typically, either the string is a result |
19463 | 20040 | of L<C<pack>|/pack TEMPLATE,LIST>, or the characters of the string |
19464 | 20041 | represent a C structure of some kind. |
19465 | 20042 | |
19466 | 20043 | =end original |
19467 | 20044 | |
19468 | 20045 | 文字列は TEMPLATE で示された固まりに分割されます。 |
19469 | 20046 | それぞれの固まりは別々に値に変換されます。 |
19470 | 20047 | 典型的には、文字列は L<C<pack>|/pack TEMPLATE,LIST> の結果あるいはある種の |
19471 | 20048 | C の構造体の文字列表現の文字列です。 |
19472 | 20049 | |
19473 | 20050 | =begin original |
19474 | 20051 | |
19475 | 20052 | The TEMPLATE has the same format as in the |
19476 | 20053 | L<C<pack>|/pack TEMPLATE,LIST> function. |
19477 | 20054 | Here's a subroutine that does substring: |
19478 | 20055 | |
19479 | 20056 | =end original |
19480 | 20057 | |
19481 | 20058 | TEMPLATE は、L<C<pack>|/pack TEMPLATE,LIST> 関数と同じフォーマットを使います。 |
19482 | 20059 | 部分文字列を取り出すうサブルーチンの例を示します: |
19483 | 20060 | |
19484 | 20061 | sub substr { |
19485 | 20062 | my ($what, $where, $howmuch) = @_; |
19486 | 20063 | unpack("x$where a$howmuch", $what); |
19487 | 20064 | } |
19488 | 20065 | |
19489 | 20066 | =begin original |
19490 | 20067 | |
19491 | 20068 | and then there's |
19492 | 20069 | |
19493 | 20070 | =end original |
19494 | 20071 | |
19495 | 20072 | これもそうです。 |
19496 | 20073 | |
19497 | 20074 | sub ordinal { unpack("W",$_[0]); } # same as ord() |
19498 | 20075 | |
19499 | 20076 | =begin original |
19500 | 20077 | |
19501 | 20078 | In addition to fields allowed in L<C<pack>|/pack TEMPLATE,LIST>, you may |
19502 | 20079 | prefix a field with a %<number> to indicate that |
19503 | 20080 | you want a <number>-bit checksum of the items instead of the items |
19504 | 20081 | themselves. Default is a 16-bit checksum. The checksum is calculated by |
19505 | 20082 | summing numeric values of expanded values (for string fields the sum of |
19506 | 20083 | C<ord($char)> is taken; for bit fields the sum of zeroes and ones). |
19507 | 20084 | |
19508 | 20085 | =end original |
19509 | 20086 | |
19510 | 20087 | L<C<pack>|/pack TEMPLATE,LIST> で利用可能なフィールドの他に、 |
19511 | 20088 | フィールドの前に %<数値> というものを付けて、 |
19512 | 20089 | 項目自身の代わりに、その項目の <数値>-ビットのチェックサムを |
19513 | 20090 | 計算させることができます。 |
19514 | 20091 | デフォルトは、16-ビットチェックサムです。 |
19515 | 20092 | チェックサムは展開された値の数値としての値の合計 |
19516 | 20093 | (文字列フィールドの場合は C<ord($char)> の合計; |
19517 | 20094 | ビットフィールドの場合は 0 と 1 の合計) が用いられます。 |
19518 | 20095 | |
19519 | 20096 | =begin original |
19520 | 20097 | |
19521 | 20098 | For example, the following |
19522 | 20099 | computes the same number as the System V sum program: |
19523 | 20100 | |
19524 | 20101 | =end original |
19525 | 20102 | |
19526 | 20103 | たとえば、以下のコードは |
19527 | 20104 | System V の sum プログラムと同じ値を計算します。 |
19528 | 20105 | |
19529 | 20106 | my $checksum = do { |
19530 | 20107 | local $/; # slurp! |
19531 | 20108 | unpack("%32W*", readline) % 65535; |
19532 | 20109 | }; |
19533 | 20110 | |
19534 | 20111 | =begin original |
19535 | 20112 | |
19536 | 20113 | The following efficiently counts the number of set bits in a bit vector: |
19537 | 20114 | |
19538 | 20115 | =end original |
19539 | 20116 | |
19540 | 20117 | 以下は、効率的にビットベクターの設定されているビットを |
19541 | 20118 | 数えるものです。 |
19542 | 20119 | |
19543 | 20120 | my $setbits = unpack("%32b*", $selectmask); |
19544 | 20121 | |
19545 | 20122 | =begin original |
19546 | 20123 | |
19547 | 20124 | The C<p> and C<P> formats should be used with care. Since Perl |
19548 | 20125 | has no way of checking whether the value passed to |
19549 | 20126 | L<C<unpack>|/unpack TEMPLATE,EXPR> |
19550 | 20127 | corresponds to a valid memory location, passing a pointer value that's |
19551 | 20128 | not known to be valid is likely to have disastrous consequences. |
19552 | 20129 | |
19553 | 20130 | =end original |
19554 | 20131 | |
19555 | 20132 | C<p> と C<P> は注意深く使うべきです。 |
19556 | 20133 | Perl は L<C<unpack>|/unpack TEMPLATE,EXPR> に渡された値が有効なメモリ位置を |
19557 | 20134 | 指しているかどうかを確認する方法がないので、有効かどうかわからない |
19558 | 20135 | ポインタ値を渡すと悲惨な結果を引き起こすかもしれません。 |
19559 | 20136 | |
19560 | 20137 | =begin original |
19561 | 20138 | |
19562 | 20139 | If there are more pack codes or if the repeat count of a field or a group |
19563 | 20140 | is larger than what the remainder of the input string allows, the result |
19564 | 20141 | is not well defined: the repeat count may be decreased, or |
19565 | 20142 | L<C<unpack>|/unpack TEMPLATE,EXPR> may produce empty strings or zeros, |
19566 | 20143 | or it may raise an exception. |
19567 | 20144 | If the input string is longer than one described by the TEMPLATE, |
19568 | 20145 | the remainder of that input string is ignored. |
19569 | 20146 | |
19570 | 20147 | =end original |
19571 | 20148 | |
19572 | 20149 | 多くの pack コードがある場合や、フィールドやグループの繰り返し回数が |
19573 | 20150 | 入力文字列の残りより大きい場合、結果は未定義です: |
19574 | 20151 | 繰り返し回数が減らされる場合もありますし、 |
19575 | 20152 | L<C<unpack>|/unpack TEMPLATE,EXPR> が空文字列や 0 を |
19576 | 20153 | 返すこともありますし、例外が発生します。 |
19577 | 20154 | もし入力文字列が TEMPLATE で表現されているものより大きい場合、 |
19578 | 20155 | 入力文字列の残りは無視されます。 |
19579 | 20156 | |
19580 | 20157 | =begin original |
19581 | 20158 | |
19582 | 20159 | See L<C<pack>|/pack TEMPLATE,LIST> for more examples and notes. |
19583 | 20160 | |
19584 | 20161 | =end original |
19585 | 20162 | |
19586 | 20163 | さらなる例と注意に関しては L<C<pack>|/pack TEMPLATE,LIST> を参照してください。 |
19587 | 20164 | |
19588 | 20165 | =item unshift ARRAY,LIST |
19589 | 20166 | X<unshift> |
19590 | 20167 | |
19591 | 20168 | =for Pod::Functions prepend more elements to the beginning of a list |
19592 | 20169 | |
19593 | 20170 | =begin original |
19594 | 20171 | |
19595 | 20172 | Does the opposite of a L<C<shift>|/shift ARRAY>. Or the opposite of a |
19596 | 20173 | L<C<push>|/push ARRAY,LIST>, |
19597 | 20174 | depending on how you look at it. Prepends list to the front of the |
19598 | 20175 | array and returns the new number of elements in the array. |
19599 | 20176 | |
19600 | 20177 | =end original |
19601 | 20178 | |
19602 | 20179 | L<C<shift>|/shift ARRAY> の逆操作を行ないます。 |
19603 | 20180 | 見方を変えれば、L<C<push>|/push ARRAY,LIST> の逆操作とも考えられます。 |
19604 | 20181 | LIST を ARRAY の先頭に入れて、新しくできた配列の要素の数を返します。 |
19605 | 20182 | |
19606 | 20183 | unshift(@ARGV, '-e') unless $ARGV[0] =~ /^-/; |
19607 | 20184 | |
19608 | 20185 | =begin original |
19609 | 20186 | |
19610 | 20187 | Note the LIST is prepended whole, not one element at a time, so the |
19611 | 20188 | prepended elements stay in the same order. Use |
19612 | 20189 | L<C<reverse>|/reverse LIST> to do the reverse. |
19613 | 20190 | |
19614 | 20191 | =end original |
19615 | 20192 | |
19616 | 20193 | LIST は、はらばらにではなく、一度に登録されるので、順番はそのままです。 |
19617 | 20194 | 逆順に登録するには、L<C<reverse>|/reverse LIST> を使ってください。 |
19618 | 20195 | |
19619 | 20196 | =begin original |
19620 | 20197 | |
19621 | 20198 | Starting with Perl 5.14, an experimental feature allowed |
19622 | 20199 | L<C<unshift>|/unshift ARRAY,LIST> to take |
19623 | 20200 | a scalar expression. This experiment has been deemed unsuccessful, and was |
19624 | 20201 | removed as of Perl 5.24. |
19625 | 20202 | |
19626 | 20203 | =end original |
19627 | 20204 | |
19628 | 20205 | Perl 5.14 から、L<C<unshift>|/unshift ARRAY,LIST> がスカラ式を |
19629 | 20206 | 取ることが出来るという実験的機能がありました。 |
19630 | 20207 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 |
19631 | 20208 | |
19632 | 20209 | =item untie VARIABLE |
19633 | 20210 | X<untie> |
19634 | 20211 | |
19635 | 20212 | =for Pod::Functions break a tie binding to a variable |
19636 | 20213 | |
19637 | 20214 | =begin original |
19638 | 20215 | |
19639 | 20216 | Breaks the binding between a variable and a package. |
19640 | 20217 | (See L<tie|/tie VARIABLE,CLASSNAME,LIST>.) |
19641 | 20218 | Has no effect if the variable is not tied. |
19642 | 20219 | |
19643 | 20220 | =end original |
19644 | 20221 | |
19645 | 20222 | 変数とパッケージの間の結合を解きます。 |
19646 | 20223 | (L<tie|/tie VARIABLE,CLASSNAME,LIST> を参照してください。) |
19647 | 20224 | 結合されていない場合は何も起きません。 |
19648 | 20225 | |
19649 | 20226 | =item use Module VERSION LIST |
19650 | 20227 | X<use> X<module> X<import> |
19651 | 20228 | |
19652 | 20229 | =item use Module VERSION |
19653 | 20230 | |
19654 | 20231 | =item use Module LIST |
19655 | 20232 | |
19656 | 20233 | =item use Module |
19657 | 20234 | |
19658 | 20235 | =item use VERSION |
19659 | 20236 | |
19660 | 20237 | =for Pod::Functions load in a module at compile time and import its namespace |
19661 | 20238 | |
19662 | 20239 | =begin original |
19663 | 20240 | |
19664 | 20241 | Imports some semantics into the current package from the named module, |
19665 | 20242 | generally by aliasing certain subroutine or variable names into your |
19666 | 20243 | package. It is exactly equivalent to |
19667 | 20244 | |
19668 | 20245 | =end original |
19669 | 20246 | |
19670 | 20247 | 指定したモジュールから、現在のパッケージにさまざまな内容をインポートします; |
19671 | 20248 | 多くは、パッケージのサブルーチン名や、変数名に別名を付けることで、 |
19672 | 20249 | 実現されています。 |
19673 | 20250 | これは、以下は等価ですが: |
19674 | 20251 | |
19675 | 20252 | BEGIN { require Module; Module->import( LIST ); } |
19676 | 20253 | |
19677 | 20254 | =begin original |
19678 | 20255 | |
19679 | 20256 | except that Module I<must> be a bareword. |
19680 | 20257 | The importation can be made conditional by using the L<if> module. |
19681 | 20258 | |
19682 | 20259 | =end original |
19683 | 20260 | |
19684 | 20261 | Module が I<裸の単語でなければならない> ことを除けば、です。 |
19685 | 20262 | インポートは、L<if> を使って条件付きで行うことができます。 |
19686 | 20263 | |
19687 | 20264 | =begin original |
19688 | 20265 | |
19689 | In the | |
20266 | In the C<use VERSION> form, VERSION may be either a v-string such as | |
19690 | ||
20267 | v5.24.1, which will be compared to L<C<$^V>|perlvar/$^V> (aka | |
19691 | ||
20268 | $PERL_VERSION), or a numeric argument of the form 5.024001, which will | |
19692 | compared to L<C<$ | |
20269 | be compared to L<C<$]>|perlvar/$]>. An exception is raised if VERSION | |
19693 | ||
20270 | is greater than the version of the current Perl interpreter; Perl will | |
19694 | ||
20271 | not attempt to parse the rest of the file. Compare with | |
19695 | ||
20272 | L<C<require>|/require VERSION>, which can do a similar check at run | |
19696 | ||
20273 | time. Symmetrically, C<no VERSION> allows you to specify that you | |
19697 | ||
20274 | want a version of Perl older than the specified one. | |
19698 | of Perl older than the specified one. | |
19699 | 20275 | |
19700 | 20276 | =end original |
19701 | 20277 | |
19702 | ||
20278 | C<use VERSION> の形式では、VERSION は v5.24.1 のような v-文字列 | |
19703 | (L<C<$ | |
20279 | (L<C<$^V>|perlvar/$^V> (またの名を $PERL_VERSION) と比較されます) | |
19704 | (L<C<$ | |
20280 | か、5.024001 の形の数値形式 (L<C<$]>|perlvar/$]> と比較されます) で | |
19705 | ||
20281 | 指定します。 | |
19706 | 20282 | VERSION が Perl の現在のバージョンより大きいと、例外が発生します; |
19707 | 20283 | Perl はファイルの残りを読み込みません。 |
19708 | L<C<require>|/require VERSION> と似ていますが、これは実行時に | |
20284 | L<C<require>|/require VERSION> と似ていますが、これは実行時に | |
20285 | チェックされます。 | |
19709 | 20286 | 対称的に、C<no VERSION> は指定されたバージョンより古いバージョンの Perl で |
19710 | 20287 | 動作させたいことを意味します。 |
19711 | 20288 | |
19712 | 20289 | =begin original |
19713 | 20290 | |
19714 | Specifying VERSION as a | |
20291 | Specifying VERSION as a numeric argument of the form 5.024001 should | |
19715 | avoided | |
20292 | generally be avoided as older less readable syntax compared to | |
19716 | ve | |
20293 | v5.24.1. Before perl 5.8.0 released in 2002 the more verbose numeric | |
19717 | ||
20294 | form was the only supported syntax, which is why you might see it in | |
19718 | 20295 | |
19719 | 20296 | =end original |
19720 | 20297 | |
19721 | VERSION に | |
20298 | VERSION に 5.024001 の形の数値引数を指定することは一般的には避けるべきです; | |
19722 | ||
20299 | v5.24.1 に比べてより古く読みにくい文法だからです。 | |
19723 | ( | |
20300 | (2002 年にリリースされた) perl 5.8.0 より前では、より冗長な | |
19724 | ||
20301 | 数値形式が唯一対応している文法でした; これが古いコードでこれを | |
20302 | 見るかも知れない理由です。 | |
19725 | 20303 | |
19726 | ||
20304 | =begin original | |
19727 | use 5.6.1; # ditto | |
19728 | use 5.006_001; # ditto; preferred for backwards compatibility | |
19729 | 20305 | |
20306 | use v5.24.1; # compile time version check | |
20307 | use 5.24.1; # ditto | |
20308 | use 5.024_001; # ditto; older syntax compatible with perl 5.6 | |
20309 | ||
20310 | =end original | |
20311 | ||
20312 | use v5.24.1; # 実行時バージョンチェック | |
20313 | use 5.24.1; # 同様 | |
20314 | use 5.024_001; # 同様; perl 5.6 と互換性のある古い文法 | |
20315 | ||
19730 | 20316 | =begin original |
19731 | 20317 | |
19732 | 20318 | This is often useful if you need to check the current Perl version before |
19733 | 20319 | L<C<use>|/use Module VERSION LIST>ing library modules that won't work |
19734 | 20320 | with older versions of Perl. |
19735 | 20321 | (We try not to do this more than we have to.) |
19736 | 20322 | |
19737 | 20323 | =end original |
19738 | 20324 | |
19739 | 20325 | これは古いバージョンの Perl で動かなくなったライブラリモジュールを |
19740 | 20326 | L<C<use>|/use Module VERSION LIST> する前に、現在の Perl のバージョンを |
19741 | 20327 | 調べたい場合に有用です。 |
19742 | 20328 | (我々は必要な場合以外にそのようなことがないように努力していますが。) |
19743 | 20329 | |
19744 | 20330 | =begin original |
19745 | 20331 | |
19746 | 20332 | C<use VERSION> also lexically enables all features available in the requested |
19747 | 20333 | version as defined by the L<feature> pragma, disabling any features |
19748 | 20334 | not in the requested version's feature bundle. See L<feature>. |
19749 | 20335 | Similarly, if the specified Perl version is greater than or equal to |
19750 | 20336 | 5.12.0, strictures are enabled lexically as |
19751 | 20337 | with L<C<use strict>|strict>. Any explicit use of |
19752 | 20338 | C<use strict> or C<no strict> overrides C<use VERSION>, even if it comes |
19753 | 20339 | before it. Later use of C<use VERSION> |
19754 | 20340 | will override all behavior of a previous |
19755 | 20341 | C<use VERSION>, possibly removing the C<strict> and C<feature> added by |
19756 | 20342 | C<use VERSION>. C<use VERSION> does not |
19757 | 20343 | load the F<feature.pm> or F<strict.pm> |
19758 | 20344 | files. |
19759 | 20345 | |
19760 | 20346 | =end original |
19761 | 20347 | |
19762 | 20348 | C<use VERSION> は、L<feature> プラグマで定義されたように、指定された |
19763 | 20349 | バージョンで利用可能な全ての機能を有効にし、指定されたバージョンの機能の |
19764 | 20350 | 束にない機能をレキシカルに無効にします。 |
19765 | 20351 | L<feature> を参照してください。 |
19766 | 20352 | 同様に、指定された Perl のバージョンが 5.12.0 以上の場合、 |
19767 | 20353 | 制限は L<C<use strict>|strict> と同様にレキシカルに有効になります。 |
19768 | 20354 | 明示的に C<use strict> や C<no strict> を使うと、例え先に |
19769 | 20355 | 指定されていたとしても、C<use VERSION> を上書きします。 |
19770 | 20356 | 後から使った C<use VERSION> は先の |
19771 | 20357 | C<use VERSION> の全ての振る舞いを上書きするので、 |
19772 | 20358 | C<use VERSION> によって追加された C<strict> と C<feature> を |
19773 | 20359 | 削除することがあります。 |
19774 | 20360 | C<use VERSION> は F<feature.pm> と F<strict.pm> ファイルは読み込みません。 |
19775 | 20361 | |
19776 | 20362 | =begin original |
19777 | 20363 | |
19778 | 20364 | The C<BEGIN> forces the L<C<require>|/require VERSION> and |
19779 | 20365 | L<C<import>|/import LIST> to happen at compile time. The |
19780 | 20366 | L<C<require>|/require VERSION> makes sure the module is loaded into |
19781 | 20367 | memory if it hasn't been yet. The L<C<import>|/import LIST> is not a |
19782 | 20368 | builtin; it's just an ordinary static method |
19783 | 20369 | call into the C<Module> package to tell the module to import the list of |
19784 | 20370 | features back into the current package. The module can implement its |
19785 | 20371 | L<C<import>|/import LIST> method any way it likes, though most modules |
19786 | 20372 | just choose to derive their L<C<import>|/import LIST> method via |
19787 | 20373 | inheritance from the C<Exporter> class that is defined in the |
19788 | 20374 | L<C<Exporter>|Exporter> module. See L<Exporter>. If no |
19789 | 20375 | L<C<import>|/import LIST> method can be found, then the call is skipped, |
19790 | 20376 | even if there is an AUTOLOAD method. |
19791 | 20377 | |
19792 | 20378 | =end original |
19793 | 20379 | |
19794 | 20380 | C<BEGIN> によって、L<C<require>|/require VERSION> や |
19795 | 20381 | L<C<import>|/import LIST> は、コンパイル時に |
19796 | 20382 | 実行されることになります。 |
19797 | 20383 | L<C<require>|/require VERSION> は、モジュールがまだメモリに |
19798 | 20384 | ロードされていなければ、ロードします。 |
19799 | 20385 | L<C<import>|/import LIST> は、組込みの関数ではありません; さまざまな機能を |
19800 | 20386 | 現在のパッケージにインポートするように C<Module> パッケージに伝えるために |
19801 | 20387 | 呼ばれる、通常の静的メソッドです。 |
19802 | 20388 | モジュール側では、L<C<import>|/import LIST> メソッドをどのようにでも |
19803 | 20389 | 実装することができますが、多くのモジュールでは、 |
19804 | 20390 | L<C<Exporter>|Exporter> モジュールで定義された、 |
19805 | 20391 | C<Exporter> クラスからの継承によって、L<C<import>|/import LIST> メソッドを |
19806 | 20392 | 行なうようにしています。 |
19807 | 20393 | L<Exporter>モジュールを参照してください。 |
19808 | 20394 | L<C<import>|/import LIST>メソッドが見つからなかった場合、AUTOLOAD メソッドが |
19809 | 20395 | あったとしても呼び出しはスキップされます。 |
19810 | 20396 | |
19811 | 20397 | =begin original |
19812 | 20398 | |
19813 | 20399 | If you do not want to call the package's L<C<import>|/import LIST> |
19814 | 20400 | method (for instance, |
19815 | 20401 | to stop your namespace from being altered), explicitly supply the empty list: |
19816 | 20402 | |
19817 | 20403 | =end original |
19818 | 20404 | |
19819 | 20405 | パッケージの L<C<import>|/import LIST> メソッドを呼び出したくない場合(例えば、 |
19820 | 20406 | 名前空間を変更したくない場合など)は、明示的に空リストを指定してください: |
19821 | 20407 | |
19822 | 20408 | use Module (); |
19823 | 20409 | |
19824 | 20410 | =begin original |
19825 | 20411 | |
19826 | 20412 | That is exactly equivalent to |
19827 | 20413 | |
19828 | 20414 | =end original |
19829 | 20415 | |
19830 | 20416 | これは以下と完全に等価です: |
19831 | 20417 | |
19832 | 20418 | BEGIN { require Module } |
19833 | 20419 | |
19834 | 20420 | =begin original |
19835 | 20421 | |
19836 | 20422 | If the VERSION argument is present between Module and LIST, then the |
19837 | 20423 | L<C<use>|/use Module VERSION LIST> will call the C<VERSION> method in |
19838 | 20424 | class Module with the given version as an argument: |
19839 | 20425 | |
19840 | 20426 | =end original |
19841 | 20427 | |
19842 | 20428 | Module と LIST の間に VERSION 引数がある場合、 |
19843 | 20429 | L<C<use>|/use Module VERSION LIST> は Module クラスの |
19844 | 20430 | C<VERSION> メソッドを、与えられたバージョンを引数として呼び出します: |
19845 | 20431 | |
19846 | 20432 | use Module 12.34; |
19847 | 20433 | |
19848 | 20434 | =begin original |
19849 | 20435 | |
19850 | 20436 | is equivalent to: |
19851 | 20437 | |
19852 | 20438 | =end original |
19853 | 20439 | |
19854 | 20440 | は以下と等価です: |
19855 | 20441 | |
19856 | 20442 | BEGIN { require Module; Module->VERSION(12.34) } |
19857 | 20443 | |
19858 | 20444 | =begin original |
19859 | 20445 | |
19860 | 20446 | The L<default C<VERSION> method|UNIVERSAL/C<VERSION ( [ REQUIRE ] )>>, |
19861 | 20447 | inherited from the L<C<UNIVERSAL>|UNIVERSAL> class, croaks if the given |
19862 | 20448 | version is larger than the value of the variable C<$Module::VERSION>. |
19863 | 20449 | |
19864 | 20450 | =end original |
19865 | 20451 | |
19866 | 20452 | デフォルトの |
19867 | 20453 | L<default C<VERSION> メソッド|UNIVERSAL/C<VERSION ( [ REQUIRE ] )>> は、 |
19868 | 20454 | L<C<UNIVERSAL>|UNIVERSAL> クラスから継承したもので、 |
19869 | 20455 | 与えられたバージョンが 変数 C<$Module::VERSION> の値より大きい場合に |
19870 | 20456 | 警告を出します。 |
19871 | 20457 | |
19872 | 20458 | =begin original |
19873 | 20459 | |
20460 | The VERSION argument cannot be an arbitrary expression. It only counts | |
20461 | as a VERSION argument if it is a version number literal, starting with | |
20462 | either a digit or C<v> followed by a digit. Anything that doesn't | |
20463 | look like a version literal will be parsed as the start of the LIST. | |
20464 | Nevertheless, many attempts to use an arbitrary expression as a VERSION | |
20465 | argument will appear to work, because L<Exporter>'s C<import> method | |
20466 | handles numeric arguments specially, performing version checks rather | |
20467 | than treating them as things to export. | |
20468 | ||
20469 | =end original | |
20470 | ||
20471 | VERSION 引数は任意の式ではありません。 | |
20472 | VERSION 引数が数値または C<v> に引き続いて数値であるバージョン番号リテラルの | |
20473 | 場合にのみ扱われます。 | |
20474 | バージョンリテラルのように見えないものは LIST の開始としてパースされます。 | |
20475 | それにも関わらず、VERSION 引数として任意の式を使おうとする | |
20476 | 多くの試みは動作しているように見えます; なぜなら | |
20477 | L<Exporter> の C<import> メソッドは数値引数を特別に扱い、 | |
20478 | それらをエクスポートするべきものと扱わずにバージョンチェックを | |
20479 | 実行するからです。 | |
20480 | ||
20481 | =begin original | |
20482 | ||
19874 | 20483 | Again, there is a distinction between omitting LIST (L<C<import>|/import |
19875 | 20484 | LIST> called with no arguments) and an explicit empty LIST C<()> |
19876 | 20485 | (L<C<import>|/import LIST> not called). Note that there is no comma |
19877 | 20486 | after VERSION! |
19878 | 20487 | |
19879 | 20488 | =end original |
19880 | 20489 | |
19881 | 20490 | 繰り返すと、LIST を省略する(L<C<import>|/import LIST> が引数なしで |
19882 | 20491 | 呼び出される)ことと明示的に空の LIST C<()> を指定する |
19883 | 20492 | (L<C<import>|/import LIST> は呼び出されない)ことは違います。 |
19884 | 20493 | VERSION の後ろにカンマが不要なことに注意してください! |
19885 | 20494 | |
19886 | 20495 | =begin original |
19887 | 20496 | |
19888 | 20497 | Because this is a wide-open interface, pragmas (compiler directives) |
19889 | 20498 | are also implemented this way. Some of the currently implemented |
19890 | 20499 | pragmas are: |
19891 | 20500 | |
19892 | 20501 | =end original |
19893 | 20502 | |
19894 | 20503 | これは、広く公開されているインタフェースですので、 |
19895 | 20504 | プラグマ (コンパイラディレクティブ) も、この方法で実装されています。 |
19896 | 20505 | 現在実装されているプラグマには、以下のようなものがあります: |
19897 | 20506 | |
19898 | 20507 | use constant; |
19899 | 20508 | use diagnostics; |
19900 | 20509 | use integer; |
19901 | 20510 | use sigtrap qw(SEGV BUS); |
19902 | 20511 | use strict qw(subs vars refs); |
19903 | 20512 | use subs qw(afunc blurfl); |
19904 | 20513 | use warnings qw(all); |
19905 | use sort qw(stable | |
20514 | use sort qw(stable); | |
19906 | 20515 | |
19907 | 20516 | =begin original |
19908 | 20517 | |
19909 | 20518 | Some of these pseudo-modules import semantics into the current |
19910 | 20519 | block scope (like L<C<strict>|strict> or L<C<integer>|integer>, unlike |
19911 | 20520 | ordinary modules, which import symbols into the current package (which |
19912 | 20521 | are effective through the end of the file). |
19913 | 20522 | |
19914 | 20523 | =end original |
19915 | 20524 | |
19916 | 20525 | 通常のモジュールが、現在のパッケージにシンボルをインポートする |
19917 | 20526 | (これは、ファイルの終わりまで有効です) のに対して、これらの擬似モジュールの |
19918 | 20527 | 一部(L<C<strict>|strict> や L<C<integer>|integer> など)は、現在の |
19919 | 20528 | ブロックスコープにインポートを行ないます。 |
19920 | 20529 | |
19921 | 20530 | =begin original |
19922 | 20531 | |
19923 | 20532 | Because L<C<use>|/use Module VERSION LIST> takes effect at compile time, |
19924 | 20533 | it doesn't respect the ordinary flow control of the code being compiled. |
19925 | 20534 | In particular, putting a L<C<use>|/use Module VERSION LIST> inside the |
19926 | 20535 | false branch of a conditional doesn't prevent it |
19927 | 20536 | from being processed. If a module or pragma only needs to be loaded |
19928 | 20537 | conditionally, this can be done using the L<if> pragma: |
19929 | 20538 | |
19930 | 20539 | =end original |
19931 | 20540 | |
19932 | 20541 | L<C<use>|/use Module VERSION LIST> はコンパイル時に有効なので、コードが |
19933 | 20542 | コンパイルされる際の通常の流れ制御には従いません。 |
19934 | 20543 | 特に、条件文のうち成立しない側の中に L<C<use>|/use Module VERSION LIST> を |
19935 | 20544 | 書いても、処理を妨げられません。 |
19936 | 20545 | モジュールやプラグマを条件付きでのみ読み込みたい場合、 |
19937 | 20546 | L<if> プラグマを使って実現できます: |
19938 | 20547 | |
19939 | 20548 | use if $] < 5.008, "utf8"; |
19940 | 20549 | use if WANT_WARNINGS, warnings => qw(all); |
19941 | 20550 | |
19942 | 20551 | =begin original |
19943 | 20552 | |
19944 | 20553 | There's a corresponding L<C<no>|/no MODULE VERSION LIST> declaration |
19945 | 20554 | that unimports meanings imported by L<C<use>|/use Module VERSION LIST>, |
19946 | 20555 | i.e., it calls C<< Module->unimport(LIST) >> instead of |
19947 | 20556 | L<C<import>|/import LIST>. It behaves just as L<C<import>|/import LIST> |
19948 | 20557 | does with VERSION, an omitted or empty LIST, |
19949 | 20558 | or no unimport method being found. |
19950 | 20559 | |
19951 | 20560 | =end original |
19952 | 20561 | |
19953 | 20562 | これに対して、L<C<no>|/no MODULE VERSION LIST> 宣言という、 |
19954 | 20563 | L<C<use>|/use Module VERSION LIST> によってインポートされたものを、 |
19955 | 20564 | インポートされていないことにするものがあります; つまり、 |
19956 | 20565 | L<C<import>|/import LIST> の代わりに |
19957 | 20566 | C<< Module->unimport(LIST) >> を呼び出します。 |
19958 | 20567 | これは VERSION、省略された LIST、空の LIST、unimport メソッドが見つからない |
19959 | 20568 | 場合などの観点では、L<C<import>|/import LIST> と同様に振る舞います。 |
19960 | 20569 | |
19961 | 20570 | no integer; |
19962 | 20571 | no strict 'refs'; |
19963 | 20572 | no warnings; |
19964 | 20573 | |
19965 | 20574 | =begin original |
19966 | 20575 | |
19967 | 20576 | Care should be taken when using the C<no VERSION> form of L<C<no>|/no |
19968 | 20577 | MODULE VERSION LIST>. It is |
19969 | 20578 | I<only> meant to be used to assert that the running Perl is of a earlier |
19970 | 20579 | version than its argument and I<not> to undo the feature-enabling side effects |
19971 | 20580 | of C<use VERSION>. |
19972 | 20581 | |
19973 | 20582 | =end original |
19974 | 20583 | |
19975 | 20584 | L<C<no>|/no MODULE VERSION LIST> の C<no VERSION> 形式を使うときには |
19976 | 20585 | 注意を払うべきです。 |
19977 | 20586 | これは引数で指定されたバージョンよりも前の Perl で実行されたときに |
19978 | 20587 | アサートされることを意味する I<だけ> で、C<use VERSION> によって |
19979 | 20588 | 有効にされた副作用をなかったことにするもの I<ではありません>。 |
19980 | 20589 | |
19981 | 20590 | =begin original |
19982 | 20591 | |
19983 | See L<perlmodlib> for a list of standard modules and pragmas. See | |
20592 | See L<perlmodlib> for a list of standard modules and pragmas. See | |
19984 | for the C<-M> and C<-m> command-lin | |
20593 | L<perlrun|perlrun/-m[-]module> for the C<-M> and C<-m> command-line | |
19985 | L<C<use>|/use Module VERSION LIST> | |
20594 | options to Perl that give L<C<use>|/use Module VERSION LIST> | |
20595 | functionality from the command-line. | |
19986 | 20596 | |
19987 | 20597 | =end original |
19988 | 20598 | |
19989 | 20599 | 標準モジュールやプラグマの一覧は、L<perlmodlib> を参照してください。 |
19990 | 20600 | コマンドラインから L<C<use>|/use Module VERSION LIST> 機能を |
19991 | 20601 | 指定するための C<-M> と C<-m> の |
19992 | コマンドラインオプションについては | |
20602 | コマンドラインオプションについては | |
20603 | L<perlrun|perlrun/-m[-]module> を参照してください。 | |
19993 | 20604 | |
19994 | 20605 | =item utime LIST |
19995 | 20606 | X<utime> |
19996 | 20607 | |
19997 | 20608 | =for Pod::Functions set a file's last access and modify times |
19998 | 20609 | |
19999 | 20610 | =begin original |
20000 | 20611 | |
20001 | 20612 | Changes the access and modification times on each file of a list of |
20002 | 20613 | files. The first two elements of the list must be the NUMERIC access |
20003 | 20614 | and modification times, in that order. Returns the number of files |
20004 | 20615 | successfully changed. The inode change time of each file is set |
20005 | 20616 | to the current time. For example, this code has the same effect as the |
20006 | 20617 | Unix L<touch(1)> command when the files I<already exist> and belong to |
20007 | 20618 | the user running the program: |
20008 | 20619 | |
20009 | 20620 | =end original |
20010 | 20621 | |
20011 | 20622 | ファイルのアクセス時刻と修正(modification) 時刻を変更します。 |
20012 | 20623 | LIST の最初の二つの要素に、数値で表わしたアクセス時刻と修正時刻を |
20013 | 20624 | 順に指定します。 |
20014 | 20625 | 変更に成功したファイルの数を返します。 |
20015 | 20626 | 各ファイルの inode 変更(change)時刻には、その時点の時刻が設定されます。 |
20016 | 20627 | 例えば、このコードはファイルが I<既に存在して> いて、ユーザーが |
20017 | 20628 | 実行しているプログラムに従っているなら、 |
20018 | 20629 | Unix の L<touch(1)> コマンドと同じ効果があります。 |
20019 | 20630 | |
20020 | 20631 | #!/usr/bin/perl |
20021 | 20632 | my $atime = my $mtime = time; |
20022 | 20633 | utime $atime, $mtime, @ARGV; |
20023 | 20634 | |
20024 | 20635 | =begin original |
20025 | 20636 | |
20026 | 20637 | Since Perl 5.8.0, if the first two elements of the list are |
20027 | 20638 | L<C<undef>|/undef EXPR>, |
20028 | 20639 | the L<utime(2)> syscall from your C library is called with a null second |
20029 | 20640 | argument. On most systems, this will set the file's access and |
20030 | 20641 | modification times to the current time (i.e., equivalent to the example |
20031 | 20642 | above) and will work even on files you don't own provided you have write |
20032 | 20643 | permission: |
20033 | 20644 | |
20034 | 20645 | =end original |
20035 | 20646 | |
20036 | 20647 | Perl 5.8.0 から、リストの最初の二つの要素が L<C<undef>|/undef EXPR> である |
20037 | 20648 | 場合、C ライブラリの L<utime(2)> システムコールを、秒の引数を null として |
20038 | 20649 | 呼び出します。 |
20039 | 20650 | ほとんどのシステムでは、これによってファイルのアクセス時刻と修正時刻を |
20040 | 20651 | 現在の時刻にセットし(つまり、上記の例と等価です)、 |
20041 | 20652 | 書き込み権限があれば他のユーザーのファイルに対しても動作します。 |
20042 | 20653 | |
20043 | 20654 | for my $file (@ARGV) { |
20044 | 20655 | utime(undef, undef, $file) |
20045 | 20656 | || warn "Couldn't touch $file: $!"; |
20046 | 20657 | } |
20047 | 20658 | |
20048 | 20659 | =begin original |
20049 | 20660 | |
20050 | 20661 | Under NFS this will use the time of the NFS server, not the time of |
20051 | 20662 | the local machine. If there is a time synchronization problem, the |
20052 | 20663 | NFS server and local machine will have different times. The Unix |
20053 | 20664 | L<touch(1)> command will in fact normally use this form instead of the |
20054 | 20665 | one shown in the first example. |
20055 | 20666 | |
20056 | 20667 | =end original |
20057 | 20668 | |
20058 | 20669 | NFS では、これはローカルマシンの時刻ではなく、NFS サーバーの時刻が |
20059 | 20670 | 使われます。 |
20060 | 20671 | 時刻同期に問題がある場合、NFS サーバーとローカルマシンで違う時刻に |
20061 | 20672 | なっている場合があります。 |
20062 | 20673 | 実際のところ、Unix の L<touch(1)> コマンドは普通、最初の例ではなく、 |
20063 | 20674 | この形を使います。 |
20064 | 20675 | |
20065 | 20676 | =begin original |
20066 | 20677 | |
20067 | 20678 | Passing only one of the first two elements as L<C<undef>|/undef EXPR> is |
20068 | 20679 | equivalent to passing a 0 and will not have the effect described when |
20069 | 20680 | both are L<C<undef>|/undef EXPR>. This also triggers an |
20070 | 20681 | uninitialized warning. |
20071 | 20682 | |
20072 | 20683 | =end original |
20073 | 20684 | |
20074 | 20685 | 最初の二つの要素のうち、一つだけに L<C<undef>|/undef EXPR> を渡すと、その |
20075 | 20686 | 要素は 0 を渡すのと等価となり、上述の、両方に L<C<undef>|/undef EXPR> を |
20076 | 20687 | 渡した時と同じ効果ではありません。 |
20077 | 20688 | この場合は、未初期化の警告が出ます。 |
20078 | 20689 | |
20079 | 20690 | =begin original |
20080 | 20691 | |
20081 | 20692 | On systems that support L<futimes(2)>, you may pass filehandles among the |
20082 | 20693 | files. On systems that don't support L<futimes(2)>, passing filehandles raises |
20083 | 20694 | an exception. Filehandles must be passed as globs or glob references to be |
20084 | 20695 | recognized; barewords are considered filenames. |
20085 | 20696 | |
20086 | 20697 | =end original |
20087 | 20698 | |
20088 | 20699 | L<futimes(2)> に対応しているシステムでは、ファイルハンドルを引数として |
20089 | 20700 | 渡せます。 |
20090 | 20701 | L<futimes(2)> に対応していないシステムでは、ファイルハンドルを渡すと |
20091 | 20702 | 例外が発生します。 |
20092 | 20703 | ファイルハンドルを認識させるためには、グロブまたはリファレンスとして |
20093 | 20704 | 渡されなければなりません; 裸の単語はファイル名として扱われます。 |
20094 | 20705 | |
20095 | 20706 | =begin original |
20096 | 20707 | |
20097 | 20708 | Portability issues: L<perlport/utime>. |
20098 | 20709 | |
20099 | 20710 | =end original |
20100 | 20711 | |
20101 | 20712 | 移植性の問題: L<perlport/utime>。 |
20102 | 20713 | |
20103 | 20714 | =item values HASH |
20104 | 20715 | X<values> |
20105 | 20716 | |
20106 | 20717 | =item values ARRAY |
20107 | 20718 | |
20108 | 20719 | =for Pod::Functions return a list of the values in a hash |
20109 | 20720 | |
20110 | 20721 | =begin original |
20111 | 20722 | |
20112 | 20723 | In list context, returns a list consisting of all the values of the named |
20113 | 20724 | hash. In Perl 5.12 or later only, will also return a list of the values of |
20114 | 20725 | an array; prior to that release, attempting to use an array argument will |
20115 | 20726 | produce a syntax error. In scalar context, returns the number of values. |
20116 | 20727 | |
20117 | 20728 | =end original |
20118 | 20729 | |
20119 | 20730 | リストコンテキストでは、指定したハッシュのすべての値を返します。 |
20120 | 20731 | Perl 5.12 以降でのみ、配列の全ての値からなるリストも返します; |
20121 | 20732 | このリリースの前では、配列要素に使おうとすると文法エラーが発生します。 |
20122 | 20733 | スカラコンテキストでは、値の数を返します。 |
20123 | 20734 | |
20124 | 20735 | =begin original |
20125 | 20736 | |
20126 | 20737 | Hash entries are returned in an apparently random order. The actual random |
20127 | 20738 | order is specific to a given hash; the exact same series of operations |
20128 | 20739 | on two hashes may result in a different order for each hash. Any insertion |
20129 | 20740 | into the hash may change the order, as will any deletion, with the exception |
20130 | 20741 | that the most recent key returned by L<C<each>|/each HASH> or |
20131 | 20742 | L<C<keys>|/keys HASH> may be deleted without changing the order. So |
20132 | 20743 | long as a given hash is unmodified you may rely on |
20133 | 20744 | L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and |
20134 | 20745 | L<C<each>|/each HASH> to repeatedly return the same order |
20135 | 20746 | as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for |
20136 | 20747 | details on why hash order is randomized. Aside from the guarantees |
20137 | 20748 | provided here the exact details of Perl's hash algorithm and the hash |
20138 | 20749 | traversal order are subject to change in any release of Perl. Tied hashes |
20139 | 20750 | may behave differently to Perl's hashes with respect to changes in order on |
20140 | 20751 | insertion and deletion of items. |
20141 | 20752 | |
20142 | 20753 | =end original |
20143 | 20754 | |
20144 | 20755 | ハッシュ要素は見かけ上、ランダムな順序で返されます。 |
20145 | 20756 | 実際のランダムな順序はハッシュに固有です; 二つのハッシュに全く同じ一連の |
20146 | 20757 | 操作を行っても、ハッシュによって異なった順序になります。 |
20147 | 20758 | ハッシュへの挿入によって順序が変わることがあります; 削除も同様ですが、 |
20148 | 20759 | L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも |
20149 | 20760 | 最近のキーは順序を変えることなく削除できます。 |
20150 | 20761 | ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>, |
20151 | 20762 | L<C<each>|/each HASH> が繰り返し同じ順序で返すことに依存してもかまいません。 |
20152 | 20763 | なぜハッシュの順序がランダム化されているかの詳細については |
20153 | 20764 | L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。 |
20154 | 20765 | ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の |
20155 | 20766 | 正確な詳細は Perl のリリースによって変更される可能性があります。 |
20156 | 20767 | tie されたハッシュは、アイテムの挿入と削除の順序に関して Perl のハッシュと |
20157 | 20768 | 異なった振る舞いをします。 |
20158 | 20769 | |
20159 | 20770 | =begin original |
20160 | 20771 | |
20161 | 20772 | As a side effect, calling L<C<values>|/values HASH> resets the HASH or |
20162 | ARRAY's internal iterator | |
20773 | ARRAY's internal iterator (see L<C<each>|/each HASH>) before yielding the | |
20774 | values. In particular, | |
20163 | 20775 | calling L<C<values>|/values HASH> in void context resets the iterator |
20164 | with no other overhead. | |
20776 | with no other overhead. | |
20777 | ||
20778 | =end original | |
20779 | ||
20780 | 副作用として、L<C<values>|/values HASH> を呼び出すと、 | |
20781 | 値を取り出す前に HASH や ARRAY の | |
20782 | 内部反復子(L<C<each>|/each HASH> 参照)をリセットします。 | |
20783 | 特に、L<C<values>|/values HASH> を無効コンテキストで呼び出すとその他の | |
20784 | オーバーヘッドなしで反復子をリセットします。 | |
20785 | ||
20786 | =begin original | |
20787 | ||
20788 | Apart from resetting the iterator, | |
20165 | 20789 | C<values @array> in list context is the same as plain C<@array>. |
20166 | 20790 | (We recommend that you use void context C<keys @array> for this, but |
20167 | 20791 | reasoned that taking C<values @array> out would require more |
20168 | 20792 | documentation than leaving it in.) |
20169 | 20793 | |
20170 | 20794 | =end original |
20171 | 20795 | |
20172 | 副作用として、L<C<values>|/values HASH> を呼び出すと HASH や ARRAY の | |
20173 | 内部反復子をリセットします; L<C<each>|/each HASH> を参照してください。 | |
20174 | (特に、L<C<values>|/values HASH> を無効コンテキストで呼び出すとその他の | |
20175 | オーバーヘッドなしで反復子をリセットします。 | |
20176 | 20796 | 反復子をリセットするということを除けば、 |
20177 | 20797 | リストコンテキストでの C<values @array> は単なる C<@array> と同じです。 |
20178 | 20798 | この目的のためには無効コンテキストで C<keys @array> を使うことを |
20179 | 20799 | お勧めしますが、C<values @array> を取り出すにはそのままにするよりも |
20180 | 20800 | より多くの文書が必要だと判断しました。) |
20181 | 20801 | |
20182 | 20802 | =begin original |
20183 | 20803 | |
20184 | 20804 | Note that the values are not copied, which means modifying them will |
20185 | 20805 | modify the contents of the hash: |
20186 | 20806 | |
20187 | 20807 | =end original |
20188 | 20808 | |
20189 | 20809 | 値はコピーされないので、返されたリストを変更すると |
20190 | 20810 | ハッシュの中身が変更されることに注意してください。 |
20191 | 20811 | |
20192 | 20812 | for (values %hash) { s/foo/bar/g } # modifies %hash values |
20193 | 20813 | for (@hash{keys %hash}) { s/foo/bar/g } # same |
20194 | 20814 | |
20195 | 20815 | =begin original |
20196 | 20816 | |
20197 | 20817 | Starting with Perl 5.14, an experimental feature allowed |
20198 | 20818 | L<C<values>|/values HASH> to take a |
20199 | 20819 | scalar expression. This experiment has been deemed unsuccessful, and was |
20200 | 20820 | removed as of Perl 5.24. |
20201 | 20821 | |
20202 | 20822 | =end original |
20203 | 20823 | |
20204 | 20824 | Perl 5.14 から、L<C<values>|/values HASH> がスカラ式を取ることが出来るという |
20205 | 20825 | 実験的機能がありました。 |
20206 | 20826 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 |
20207 | 20827 | |
20208 | 20828 | =begin original |
20209 | 20829 | |
20210 | 20830 | To avoid confusing would-be users of your code who are running earlier |
20211 | 20831 | versions of Perl with mysterious syntax errors, put this sort of thing at |
20212 | 20832 | the top of your file to signal that your code will work I<only> on Perls of |
20213 | 20833 | a recent vintage: |
20214 | 20834 | |
20215 | 20835 | =end original |
20216 | 20836 | |
20217 | 20837 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な |
20218 | 20838 | 文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で |
20219 | 20839 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを |
20220 | 20840 | 書いてください: |
20221 | 20841 | |
20222 | 20842 | use 5.012; # so keys/values/each work on arrays |
20223 | 20843 | |
20224 | 20844 | =begin original |
20225 | 20845 | |
20226 | 20846 | See also L<C<keys>|/keys HASH>, L<C<each>|/each HASH>, and |
20227 | 20847 | L<C<sort>|/sort SUBNAME LIST>. |
20228 | 20848 | |
20229 | 20849 | =end original |
20230 | 20850 | |
20231 | 20851 | L<C<keys>|/keys HASH>, L<C<each>|/each HASH>, L<C<sort>|/sort SUBNAME LIST> も |
20232 | 20852 | 参照してください。 |
20233 | 20853 | |
20234 | 20854 | =item vec EXPR,OFFSET,BITS |
20235 | 20855 | X<vec> X<bit> X<bit vector> |
20236 | 20856 | |
20237 | 20857 | =for Pod::Functions test or set particular bits in a string |
20238 | 20858 | |
20239 | 20859 | =begin original |
20240 | 20860 | |
20241 | 20861 | Treats the string in EXPR as a bit vector made up of elements of |
20242 | 20862 | width BITS and returns the value of the element specified by OFFSET |
20243 | 20863 | as an unsigned integer. BITS therefore specifies the number of bits |
20244 | 20864 | that are reserved for each element in the bit vector. This must |
20245 | 20865 | be a power of two from 1 to 32 (or 64, if your platform supports |
20246 | 20866 | that). |
20247 | 20867 | |
20248 | 20868 | =end original |
20249 | 20869 | |
20250 | 20870 | 文字列 EXPR を BITS 幅の要素からなるビットベクターとして扱い、 |
20251 | 20871 | OFFSET で指定された要素を符号なし整数として返します。 |
20252 | 20872 | 従って、 BITS はビットベクターの中の各要素について予約されるビット数です。 |
20253 | 20873 | BIT は、1 から 32 まで(プラットホームが |
20254 | 20874 | 対応していれば 64 まで) の 2 のべき乗でなければなりません。 |
20255 | 20875 | |
20256 | 20876 | =begin original |
20257 | 20877 | |
20258 | 20878 | If BITS is 8, "elements" coincide with bytes of the input string. |
20259 | 20879 | |
20260 | 20880 | =end original |
20261 | 20881 | |
20262 | 20882 | BITS が 8 の場合、「要素」は入力文字列の各バイトと一致します。 |
20263 | 20883 | |
20264 | 20884 | =begin original |
20265 | 20885 | |
20266 | 20886 | If BITS is 16 or more, bytes of the input string are grouped into chunks |
20267 | 20887 | of size BITS/8, and each group is converted to a number as with |
20268 | 20888 | L<C<pack>|/pack TEMPLATE,LIST>/L<C<unpack>|/unpack TEMPLATE,EXPR> with |
20269 | 20889 | big-endian formats C<n>/C<N> (and analogously for BITS==64). See |
20270 | 20890 | L<C<pack>|/pack TEMPLATE,LIST> for details. |
20271 | 20891 | |
20272 | 20892 | =end original |
20273 | 20893 | |
20274 | 20894 | BITS が 16 以上の場合、入力のバイト列は BITS/8 のサイズの固まりに |
20275 | 20895 | グループ化され、各グループは L<C<pack>|/pack TEMPLATE,LIST>/ |
20276 | 20896 | L<C<unpack>|/unpack TEMPLATE,EXPR> のビッグエンディアン |
20277 | 20897 | フォーマット C<n>/C<N> を用いて(BITS==64 の類似として)数値に変換されます。 |
20278 | 20898 | 詳細は L<C<pack>|/pack TEMPLATE,LIST> を参照してください。 |
20279 | 20899 | |
20280 | 20900 | =begin original |
20281 | 20901 | |
20282 | 20902 | If bits is 4 or less, the string is broken into bytes, then the bits |
20283 | 20903 | of each byte are broken into 8/BITS groups. Bits of a byte are |
20284 | 20904 | numbered in a little-endian-ish way, as in C<0x01>, C<0x02>, |
20285 | 20905 | C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80>. For example, |
20286 | 20906 | breaking the single input byte C<chr(0x36)> into two groups gives a list |
20287 | 20907 | C<(0x6, 0x3)>; breaking it into 4 groups gives C<(0x2, 0x1, 0x3, 0x0)>. |
20288 | 20908 | |
20289 | 20909 | =end original |
20290 | 20910 | |
20291 | 20911 | BITS が 4 以下の場合、文字列はバイトに分解され、バイトの各ビットは |
20292 | 20912 | 8/BITS 個のグループに分割されます。 |
20293 | 20913 | ビットはリトルエンディアン風に、C<0x01>, C<0x02>, |
20294 | 20914 | C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80> の順になります。 |
20295 | 20915 | 例えば、入力バイト C<chr(0x36)> を二つのグループに分割すると、 |
20296 | 20916 | C<(0x6, 0x3)> になります; 4 つに分割すると C<(0x2, 0x1, 0x3, 0x0)> に |
20297 | 20917 | なります。 |
20298 | 20918 | |
20299 | 20919 | =begin original |
20300 | 20920 | |
20301 | 20921 | L<C<vec>|/vec EXPR,OFFSET,BITS> may also be assigned to, in which case |
20302 | 20922 | parentheses are needed |
20303 | 20923 | to give the expression the correct precedence as in |
20304 | 20924 | |
20305 | 20925 | =end original |
20306 | 20926 | |
20307 | 20927 | L<C<vec>|/vec EXPR,OFFSET,BITS> は左辺値として、代入の |
20308 | 20928 | 対象にすることもできます; この場合、式を正しく |
20309 | 20929 | 先行させるために以下のように括弧が必要です: |
20310 | 20930 | |
20311 | 20931 | vec($image, $max_x * $x + $y, 8) = 3; |
20312 | 20932 | |
20313 | 20933 | =begin original |
20314 | 20934 | |
20315 | 20935 | If the selected element is outside the string, the value 0 is returned. |
20316 | 20936 | If an element off the end of the string is written to, Perl will first |
20317 | 20937 | extend the string with sufficiently many zero bytes. It is an error |
20318 | 20938 | to try to write off the beginning of the string (i.e., negative OFFSET). |
20319 | 20939 | |
20320 | 20940 | =end original |
20321 | 20941 | |
20322 | 20942 | 選択された要素が文字列の外側だった場合、値 0 が返されます。 |
20323 | 20943 | 文字列の最後よりも後ろの要素に書き込もうとした場合、 |
20324 | 20944 | Perl はまず文字列を必要な分だけ 0 のバイトで拡張します。 |
20325 | 20945 | 文字列の先頭より前に書き込もうとした(つまり OFFSET が負の数だった) |
20326 | 20946 | 場合はエラーとなります。 |
20327 | 20947 | |
20328 | 20948 | =begin original |
20329 | 20949 | |
20330 | 20950 | If the string happens to be encoded as UTF-8 internally (and thus has |
20331 | 20951 | the UTF8 flag set), L<C<vec>|/vec EXPR,OFFSET,BITS> tries to convert it |
20332 | 20952 | to use a one-byte-per-character internal representation. However, if the |
20333 | string contains characters with values of 256 or higher, | |
20953 | string contains characters with values of 256 or higher, a fatal error | |
20334 | will | |
20954 | will occur. | |
20335 | regardless, in its internal UTF-8 representation. | |
20336 | 20955 | |
20337 | 20956 | =end original |
20338 | 20957 | |
20339 | 文字列が | |
20958 | 文字列がたまたま内部で UTF-8 でエンコードされている場合(したがって | |
20340 | セットされている場合)、 | |
20959 | UTF8 フラグがセットされている場合)、 | |
20341 | 20960 | L<C<vec>|/vec EXPR,OFFSET,BITS> はこれを単一バイト文字内部表現に |
20342 | 20961 | 変換しようとします。 |
20343 | 20962 | しかし、この文字列に値が 256 以上の文字が含まれている場合、 |
20344 | ||
20963 | 致命的エラーが発生します。 | |
20345 | この場合、C<vec> は内部の UTF-8 表現を気にせず、 | |
20346 | 基となっているバッファに対して操作します。 | |
20347 | 20964 | |
20348 | 20965 | =begin original |
20349 | 20966 | |
20350 | 20967 | Strings created with L<C<vec>|/vec EXPR,OFFSET,BITS> can also be |
20351 | 20968 | manipulated with the logical |
20352 | 20969 | operators C<|>, C<&>, C<^>, and C<~>. These operators will assume a bit |
20353 | 20970 | vector operation is desired when both operands are strings. |
20354 | 20971 | See L<perlop/"Bitwise String Operators">. |
20355 | 20972 | |
20356 | 20973 | =end original |
20357 | 20974 | |
20358 | 20975 | L<C<vec>|/vec EXPR,OFFSET,BITS> で作られた文字列は、論理演算子 C<|>、C<&>、 |
20359 | 20976 | C<^>, C<~> で扱うこともできます。 |
20360 | 20977 | これらの演算子は、両方の被演算子に文字列を使うと、 |
20361 | 20978 | ビットベクター演算を行ないます。 |
20362 | 20979 | L<perlop/"Bitwise String Operators"> を参照してください。 |
20363 | 20980 | |
20364 | 20981 | =begin original |
20365 | 20982 | |
20366 | 20983 | The following code will build up an ASCII string saying C<'PerlPerlPerl'>. |
20367 | 20984 | The comments show the string after each step. Note that this code works |
20368 | 20985 | in the same way on big-endian or little-endian machines. |
20369 | 20986 | |
20370 | 20987 | =end original |
20371 | 20988 | |
20372 | 20989 | 次のコードは C<'PerlPerlPerl'> という ASCII 文字列を作成します。 |
20373 | 20990 | コメントは各行の実行後の文字列を示します。 |
20374 | 20991 | このコードはビッグエンディアンでもリトルエンディアンでも同じように |
20375 | 20992 | 動作することに注意してください。 |
20376 | 20993 | |
20377 | 20994 | my $foo = ''; |
20378 | 20995 | vec($foo, 0, 32) = 0x5065726C; # 'Perl' |
20379 | 20996 | |
20380 | 20997 | # $foo eq "Perl" eq "\x50\x65\x72\x6C", 32 bits |
20381 | 20998 | print vec($foo, 0, 8); # prints 80 == 0x50 == ord('P') |
20382 | 20999 | |
20383 | 21000 | vec($foo, 2, 16) = 0x5065; # 'PerlPe' |
20384 | 21001 | vec($foo, 3, 16) = 0x726C; # 'PerlPerl' |
20385 | 21002 | vec($foo, 8, 8) = 0x50; # 'PerlPerlP' |
20386 | 21003 | vec($foo, 9, 8) = 0x65; # 'PerlPerlPe' |
20387 | 21004 | vec($foo, 20, 4) = 2; # 'PerlPerlPe' . "\x02" |
20388 | 21005 | vec($foo, 21, 4) = 7; # 'PerlPerlPer' |
20389 | 21006 | # 'r' is "\x72" |
20390 | 21007 | vec($foo, 45, 2) = 3; # 'PerlPerlPer' . "\x0c" |
20391 | 21008 | vec($foo, 93, 1) = 1; # 'PerlPerlPer' . "\x2c" |
20392 | 21009 | vec($foo, 94, 1) = 1; # 'PerlPerlPerl' |
20393 | 21010 | # 'l' is "\x6c" |
20394 | 21011 | |
20395 | 21012 | =begin original |
20396 | 21013 | |
20397 | 21014 | To transform a bit vector into a string or list of 0's and 1's, use these: |
20398 | 21015 | |
20399 | 21016 | =end original |
20400 | 21017 | |
20401 | 21018 | ビットベクターを、0 と 1 の文字列や配列に変換するには、 |
20402 | 21019 | 以下のようにします。 |
20403 | 21020 | |
20404 | 21021 | my $bits = unpack("b*", $vector); |
20405 | 21022 | my @bits = split(//, unpack("b*", $vector)); |
20406 | 21023 | |
20407 | 21024 | =begin original |
20408 | 21025 | |
20409 | 21026 | If you know the exact length in bits, it can be used in place of the C<*>. |
20410 | 21027 | |
20411 | 21028 | =end original |
20412 | 21029 | |
20413 | 21030 | ビット長が分かっていれば、C<*> の代わりにその長さを使うことができます。 |
20414 | 21031 | |
20415 | 21032 | =begin original |
20416 | 21033 | |
20417 | 21034 | Here is an example to illustrate how the bits actually fall in place: |
20418 | 21035 | |
20419 | 21036 | =end original |
20420 | 21037 | |
20421 | 21038 | これはビットが実際にどのような位置に入るかを図示する例です。 |
20422 | 21039 | |
20423 | 21040 | #!/usr/bin/perl -wl |
20424 | 21041 | |
20425 | 21042 | print <<'EOT'; |
20426 | 21043 | 0 1 2 3 |
20427 | 21044 | unpack("V",$_) 01234567890123456789012345678901 |
20428 | 21045 | ------------------------------------------------------------------ |
20429 | 21046 | EOT |
20430 | 21047 | |
20431 | 21048 | for $w (0..3) { |
20432 | 21049 | $width = 2**$w; |
20433 | 21050 | for ($shift=0; $shift < $width; ++$shift) { |
20434 | 21051 | for ($off=0; $off < 32/$width; ++$off) { |
20435 | 21052 | $str = pack("B*", "0"x32); |
20436 | 21053 | $bits = (1<<$shift); |
20437 | 21054 | vec($str, $off, $width) = $bits; |
20438 | 21055 | $res = unpack("b*",$str); |
20439 | 21056 | $val = unpack("V", $str); |
20440 | 21057 | write; |
20441 | 21058 | } |
20442 | 21059 | } |
20443 | 21060 | } |
20444 | 21061 | |
20445 | 21062 | format STDOUT = |
20446 | 21063 | vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
20447 | 21064 | $off, $width, $bits, $val, $res |
20448 | 21065 | . |
20449 | 21066 | __END__ |
20450 | 21067 | |
20451 | 21068 | =begin original |
20452 | 21069 | |
20453 | 21070 | Regardless of the machine architecture on which it runs, the |
20454 | 21071 | example above should print the following table: |
20455 | 21072 | |
20456 | 21073 | =end original |
20457 | 21074 | |
20458 | 21075 | 実行するマシンのアーキテクチャに関わらず、 |
20459 | 21076 | 上記の例は以下の表を出力します。 |
20460 | 21077 | |
20461 | 21078 | 0 1 2 3 |
20462 | 21079 | unpack("V",$_) 01234567890123456789012345678901 |
20463 | 21080 | ------------------------------------------------------------------ |
20464 | 21081 | vec($_, 0, 1) = 1 == 1 10000000000000000000000000000000 |
20465 | 21082 | vec($_, 1, 1) = 1 == 2 01000000000000000000000000000000 |
20466 | 21083 | vec($_, 2, 1) = 1 == 4 00100000000000000000000000000000 |
20467 | 21084 | vec($_, 3, 1) = 1 == 8 00010000000000000000000000000000 |
20468 | 21085 | vec($_, 4, 1) = 1 == 16 00001000000000000000000000000000 |
20469 | 21086 | vec($_, 5, 1) = 1 == 32 00000100000000000000000000000000 |
20470 | 21087 | vec($_, 6, 1) = 1 == 64 00000010000000000000000000000000 |
20471 | 21088 | vec($_, 7, 1) = 1 == 128 00000001000000000000000000000000 |
20472 | 21089 | vec($_, 8, 1) = 1 == 256 00000000100000000000000000000000 |
20473 | 21090 | vec($_, 9, 1) = 1 == 512 00000000010000000000000000000000 |
20474 | 21091 | vec($_,10, 1) = 1 == 1024 00000000001000000000000000000000 |
20475 | 21092 | vec($_,11, 1) = 1 == 2048 00000000000100000000000000000000 |
20476 | 21093 | vec($_,12, 1) = 1 == 4096 00000000000010000000000000000000 |
20477 | 21094 | vec($_,13, 1) = 1 == 8192 00000000000001000000000000000000 |
20478 | 21095 | vec($_,14, 1) = 1 == 16384 00000000000000100000000000000000 |
20479 | 21096 | vec($_,15, 1) = 1 == 32768 00000000000000010000000000000000 |
20480 | 21097 | vec($_,16, 1) = 1 == 65536 00000000000000001000000000000000 |
20481 | 21098 | vec($_,17, 1) = 1 == 131072 00000000000000000100000000000000 |
20482 | 21099 | vec($_,18, 1) = 1 == 262144 00000000000000000010000000000000 |
20483 | 21100 | vec($_,19, 1) = 1 == 524288 00000000000000000001000000000000 |
20484 | 21101 | vec($_,20, 1) = 1 == 1048576 00000000000000000000100000000000 |
20485 | 21102 | vec($_,21, 1) = 1 == 2097152 00000000000000000000010000000000 |
20486 | 21103 | vec($_,22, 1) = 1 == 4194304 00000000000000000000001000000000 |
20487 | 21104 | vec($_,23, 1) = 1 == 8388608 00000000000000000000000100000000 |
20488 | 21105 | vec($_,24, 1) = 1 == 16777216 00000000000000000000000010000000 |
20489 | 21106 | vec($_,25, 1) = 1 == 33554432 00000000000000000000000001000000 |
20490 | 21107 | vec($_,26, 1) = 1 == 67108864 00000000000000000000000000100000 |
20491 | 21108 | vec($_,27, 1) = 1 == 134217728 00000000000000000000000000010000 |
20492 | 21109 | vec($_,28, 1) = 1 == 268435456 00000000000000000000000000001000 |
20493 | 21110 | vec($_,29, 1) = 1 == 536870912 00000000000000000000000000000100 |
20494 | 21111 | vec($_,30, 1) = 1 == 1073741824 00000000000000000000000000000010 |
20495 | 21112 | vec($_,31, 1) = 1 == 2147483648 00000000000000000000000000000001 |
20496 | 21113 | vec($_, 0, 2) = 1 == 1 10000000000000000000000000000000 |
20497 | 21114 | vec($_, 1, 2) = 1 == 4 00100000000000000000000000000000 |
20498 | 21115 | vec($_, 2, 2) = 1 == 16 00001000000000000000000000000000 |
20499 | 21116 | vec($_, 3, 2) = 1 == 64 00000010000000000000000000000000 |
20500 | 21117 | vec($_, 4, 2) = 1 == 256 00000000100000000000000000000000 |
20501 | 21118 | vec($_, 5, 2) = 1 == 1024 00000000001000000000000000000000 |
20502 | 21119 | vec($_, 6, 2) = 1 == 4096 00000000000010000000000000000000 |
20503 | 21120 | vec($_, 7, 2) = 1 == 16384 00000000000000100000000000000000 |
20504 | 21121 | vec($_, 8, 2) = 1 == 65536 00000000000000001000000000000000 |
20505 | 21122 | vec($_, 9, 2) = 1 == 262144 00000000000000000010000000000000 |
20506 | 21123 | vec($_,10, 2) = 1 == 1048576 00000000000000000000100000000000 |
20507 | 21124 | vec($_,11, 2) = 1 == 4194304 00000000000000000000001000000000 |
20508 | 21125 | vec($_,12, 2) = 1 == 16777216 00000000000000000000000010000000 |
20509 | 21126 | vec($_,13, 2) = 1 == 67108864 00000000000000000000000000100000 |
20510 | 21127 | vec($_,14, 2) = 1 == 268435456 00000000000000000000000000001000 |
20511 | 21128 | vec($_,15, 2) = 1 == 1073741824 00000000000000000000000000000010 |
20512 | 21129 | vec($_, 0, 2) = 2 == 2 01000000000000000000000000000000 |
20513 | 21130 | vec($_, 1, 2) = 2 == 8 00010000000000000000000000000000 |
20514 | 21131 | vec($_, 2, 2) = 2 == 32 00000100000000000000000000000000 |
20515 | 21132 | vec($_, 3, 2) = 2 == 128 00000001000000000000000000000000 |
20516 | 21133 | vec($_, 4, 2) = 2 == 512 00000000010000000000000000000000 |
20517 | 21134 | vec($_, 5, 2) = 2 == 2048 00000000000100000000000000000000 |
20518 | 21135 | vec($_, 6, 2) = 2 == 8192 00000000000001000000000000000000 |
20519 | 21136 | vec($_, 7, 2) = 2 == 32768 00000000000000010000000000000000 |
20520 | 21137 | vec($_, 8, 2) = 2 == 131072 00000000000000000100000000000000 |
20521 | 21138 | vec($_, 9, 2) = 2 == 524288 00000000000000000001000000000000 |
20522 | 21139 | vec($_,10, 2) = 2 == 2097152 00000000000000000000010000000000 |
20523 | 21140 | vec($_,11, 2) = 2 == 8388608 00000000000000000000000100000000 |
20524 | 21141 | vec($_,12, 2) = 2 == 33554432 00000000000000000000000001000000 |
20525 | 21142 | vec($_,13, 2) = 2 == 134217728 00000000000000000000000000010000 |
20526 | 21143 | vec($_,14, 2) = 2 == 536870912 00000000000000000000000000000100 |
20527 | 21144 | vec($_,15, 2) = 2 == 2147483648 00000000000000000000000000000001 |
20528 | 21145 | vec($_, 0, 4) = 1 == 1 10000000000000000000000000000000 |
20529 | 21146 | vec($_, 1, 4) = 1 == 16 00001000000000000000000000000000 |
20530 | 21147 | vec($_, 2, 4) = 1 == 256 00000000100000000000000000000000 |
20531 | 21148 | vec($_, 3, 4) = 1 == 4096 00000000000010000000000000000000 |
20532 | 21149 | vec($_, 4, 4) = 1 == 65536 00000000000000001000000000000000 |
20533 | 21150 | vec($_, 5, 4) = 1 == 1048576 00000000000000000000100000000000 |
20534 | 21151 | vec($_, 6, 4) = 1 == 16777216 00000000000000000000000010000000 |
20535 | 21152 | vec($_, 7, 4) = 1 == 268435456 00000000000000000000000000001000 |
20536 | 21153 | vec($_, 0, 4) = 2 == 2 01000000000000000000000000000000 |
20537 | 21154 | vec($_, 1, 4) = 2 == 32 00000100000000000000000000000000 |
20538 | 21155 | vec($_, 2, 4) = 2 == 512 00000000010000000000000000000000 |
20539 | 21156 | vec($_, 3, 4) = 2 == 8192 00000000000001000000000000000000 |
20540 | 21157 | vec($_, 4, 4) = 2 == 131072 00000000000000000100000000000000 |
20541 | 21158 | vec($_, 5, 4) = 2 == 2097152 00000000000000000000010000000000 |
20542 | 21159 | vec($_, 6, 4) = 2 == 33554432 00000000000000000000000001000000 |
20543 | 21160 | vec($_, 7, 4) = 2 == 536870912 00000000000000000000000000000100 |
20544 | 21161 | vec($_, 0, 4) = 4 == 4 00100000000000000000000000000000 |
20545 | 21162 | vec($_, 1, 4) = 4 == 64 00000010000000000000000000000000 |
20546 | 21163 | vec($_, 2, 4) = 4 == 1024 00000000001000000000000000000000 |
20547 | 21164 | vec($_, 3, 4) = 4 == 16384 00000000000000100000000000000000 |
20548 | 21165 | vec($_, 4, 4) = 4 == 262144 00000000000000000010000000000000 |
20549 | 21166 | vec($_, 5, 4) = 4 == 4194304 00000000000000000000001000000000 |
20550 | 21167 | vec($_, 6, 4) = 4 == 67108864 00000000000000000000000000100000 |
20551 | 21168 | vec($_, 7, 4) = 4 == 1073741824 00000000000000000000000000000010 |
20552 | 21169 | vec($_, 0, 4) = 8 == 8 00010000000000000000000000000000 |
20553 | 21170 | vec($_, 1, 4) = 8 == 128 00000001000000000000000000000000 |
20554 | 21171 | vec($_, 2, 4) = 8 == 2048 00000000000100000000000000000000 |
20555 | 21172 | vec($_, 3, 4) = 8 == 32768 00000000000000010000000000000000 |
20556 | 21173 | vec($_, 4, 4) = 8 == 524288 00000000000000000001000000000000 |
20557 | 21174 | vec($_, 5, 4) = 8 == 8388608 00000000000000000000000100000000 |
20558 | 21175 | vec($_, 6, 4) = 8 == 134217728 00000000000000000000000000010000 |
20559 | 21176 | vec($_, 7, 4) = 8 == 2147483648 00000000000000000000000000000001 |
20560 | 21177 | vec($_, 0, 8) = 1 == 1 10000000000000000000000000000000 |
20561 | 21178 | vec($_, 1, 8) = 1 == 256 00000000100000000000000000000000 |
20562 | 21179 | vec($_, 2, 8) = 1 == 65536 00000000000000001000000000000000 |
20563 | 21180 | vec($_, 3, 8) = 1 == 16777216 00000000000000000000000010000000 |
20564 | 21181 | vec($_, 0, 8) = 2 == 2 01000000000000000000000000000000 |
20565 | 21182 | vec($_, 1, 8) = 2 == 512 00000000010000000000000000000000 |
20566 | 21183 | vec($_, 2, 8) = 2 == 131072 00000000000000000100000000000000 |
20567 | 21184 | vec($_, 3, 8) = 2 == 33554432 00000000000000000000000001000000 |
20568 | 21185 | vec($_, 0, 8) = 4 == 4 00100000000000000000000000000000 |
20569 | 21186 | vec($_, 1, 8) = 4 == 1024 00000000001000000000000000000000 |
20570 | 21187 | vec($_, 2, 8) = 4 == 262144 00000000000000000010000000000000 |
20571 | 21188 | vec($_, 3, 8) = 4 == 67108864 00000000000000000000000000100000 |
20572 | 21189 | vec($_, 0, 8) = 8 == 8 00010000000000000000000000000000 |
20573 | 21190 | vec($_, 1, 8) = 8 == 2048 00000000000100000000000000000000 |
20574 | 21191 | vec($_, 2, 8) = 8 == 524288 00000000000000000001000000000000 |
20575 | 21192 | vec($_, 3, 8) = 8 == 134217728 00000000000000000000000000010000 |
20576 | 21193 | vec($_, 0, 8) = 16 == 16 00001000000000000000000000000000 |
20577 | 21194 | vec($_, 1, 8) = 16 == 4096 00000000000010000000000000000000 |
20578 | 21195 | vec($_, 2, 8) = 16 == 1048576 00000000000000000000100000000000 |
20579 | 21196 | vec($_, 3, 8) = 16 == 268435456 00000000000000000000000000001000 |
20580 | 21197 | vec($_, 0, 8) = 32 == 32 00000100000000000000000000000000 |
20581 | 21198 | vec($_, 1, 8) = 32 == 8192 00000000000001000000000000000000 |
20582 | 21199 | vec($_, 2, 8) = 32 == 2097152 00000000000000000000010000000000 |
20583 | 21200 | vec($_, 3, 8) = 32 == 536870912 00000000000000000000000000000100 |
20584 | 21201 | vec($_, 0, 8) = 64 == 64 00000010000000000000000000000000 |
20585 | 21202 | vec($_, 1, 8) = 64 == 16384 00000000000000100000000000000000 |
20586 | 21203 | vec($_, 2, 8) = 64 == 4194304 00000000000000000000001000000000 |
20587 | 21204 | vec($_, 3, 8) = 64 == 1073741824 00000000000000000000000000000010 |
20588 | 21205 | vec($_, 0, 8) = 128 == 128 00000001000000000000000000000000 |
20589 | 21206 | vec($_, 1, 8) = 128 == 32768 00000000000000010000000000000000 |
20590 | 21207 | vec($_, 2, 8) = 128 == 8388608 00000000000000000000000100000000 |
20591 | 21208 | vec($_, 3, 8) = 128 == 2147483648 00000000000000000000000000000001 |
20592 | 21209 | |
20593 | 21210 | =item wait |
20594 | 21211 | X<wait> |
20595 | 21212 | |
20596 | 21213 | =for Pod::Functions wait for any child process to die |
20597 | 21214 | |
20598 | 21215 | =begin original |
20599 | 21216 | |
20600 | 21217 | Behaves like L<wait(2)> on your system: it waits for a child |
20601 | 21218 | process to terminate and returns the pid of the deceased process, or |
20602 | 21219 | C<-1> if there are no child processes. The status is returned in |
20603 | 21220 | L<C<$?>|perlvar/$?> and |
20604 | 21221 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>. |
20605 | 21222 | Note that a return value of C<-1> could mean that child processes are |
20606 | 21223 | being automatically reaped, as described in L<perlipc>. |
20607 | 21224 | |
20608 | 21225 | =end original |
20609 | 21226 | |
20610 | 21227 | L<wait(2)> と同様に振る舞います: チャイルドプロセスが終了するのを待ち、 |
20611 | 21228 | 消滅したプロセスの pid を返します; チャイルドプロセスが存在しないときには、 |
20612 | 21229 | C<-1> を返します。 |
20613 | 21230 | ステータスは L<C<$?>|perlvar/$?> と |
20614 | 21231 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に返されます。 |
20615 | 21232 | L<perlipc> に書いているように、返り値が C<-1> の場合は子プロセスが |
20616 | 21233 | 自動的に刈り取られたことを意味するかもしれないことに注意してください。 |
20617 | 21234 | |
20618 | 21235 | =begin original |
20619 | 21236 | |
20620 | 21237 | If you use L<C<wait>|/wait> in your handler for |
20621 | 21238 | L<C<$SIG{CHLD}>|perlvar/%SIG>, it may accidentally wait for the child |
20622 | 21239 | created by L<C<qx>|/qxE<sol>STRINGE<sol>> or L<C<system>|/system LIST>. |
20623 | 21240 | See L<perlipc> for details. |
20624 | 21241 | |
20625 | 21242 | =end original |
20626 | 21243 | |
20627 | 21244 | L<C<wait>|/wait> を L<C<$SIG{CHLD}>|perlvar/%SIG> のハンドラで使うと、誤って |
20628 | 21245 | L<C<qx>|/qxE<sol>STRINGE<sol>> や L<C<system>|/system LIST> によって |
20629 | 21246 | 作られた子を待つことになるかも知れません。 |
20630 | 21247 | 詳しくは L<perlipc> を参照してください。 |
20631 | 21248 | |
20632 | 21249 | =begin original |
20633 | 21250 | |
20634 | 21251 | Portability issues: L<perlport/wait>. |
20635 | 21252 | |
20636 | 21253 | =end original |
20637 | 21254 | |
20638 | 21255 | 移植性の問題: L<perlport/wait>。 |
20639 | 21256 | |
20640 | 21257 | =item waitpid PID,FLAGS |
20641 | 21258 | X<waitpid> |
20642 | 21259 | |
20643 | 21260 | =for Pod::Functions wait for a particular child process to die |
20644 | 21261 | |
20645 | 21262 | =begin original |
20646 | 21263 | |
20647 | 21264 | Waits for a particular child process to terminate and returns the pid of |
20648 | 21265 | the deceased process, or C<-1> if there is no such child process. A |
20649 | 21266 | non-blocking wait (with L<WNOHANG|POSIX/C<WNOHANG>> in FLAGS) can return 0 if |
20650 | 21267 | there are child processes matching PID but none have terminated yet. |
20651 | 21268 | The status is returned in L<C<$?>|perlvar/$?> and |
20652 | 21269 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>. |
20653 | 21270 | |
20654 | 21271 | =end original |
20655 | 21272 | |
20656 | 21273 | 特定の子プロセスが終了するのを待ち、消滅したプロセスの pid を |
20657 | 21274 | 返します; 指定した子プロセスが存在しないときには、C<-1> を返します。 |
20658 | 21275 | (FLAGS に L<WNOHANG|POSIX/C<WNOHANG>> を指定した) 非ブロッキング wait は、 |
20659 | 21276 | PID がマッチングする子プロセスがいてもまだ終了していない場合に 0 を |
20660 | 21277 | 返すことがあります。 |
20661 | 21278 | ステータスは L<C<$?>|perlvar/$?> と |
20662 | 21279 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に返されます。 |
20663 | 21280 | |
20664 | 21281 | =begin original |
20665 | 21282 | |
20666 | 21283 | A PID of C<0> indicates to wait for any child process whose process group ID is |
20667 | 21284 | equal to that of the current process. A PID of less than C<-1> indicates to |
20668 | 21285 | wait for any child process whose process group ID is equal to -PID. A PID of |
20669 | 21286 | C<-1> indicates to wait for any child process. |
20670 | 21287 | |
20671 | 21288 | =end original |
20672 | 21289 | |
20673 | 21290 | PID に C<0> を指定すると、プロセスグループ ID が現在のプロセスと同じである |
20674 | 21291 | 任意の子プロセスを wait します。 |
20675 | 21292 | PID に C<-1> 以下を指定すると、プロセスグループ ID が -PID に等しい |
20676 | 21293 | 任意の子プロセスを wait します。 |
20677 | 21294 | PID に C<-1> を指定すると任意の子プロセスを wait します。 |
20678 | 21295 | |
20679 | 21296 | =begin original |
20680 | 21297 | |
20681 | 21298 | If you say |
20682 | 21299 | |
20683 | 21300 | =end original |
20684 | 21301 | |
20685 | 21302 | 以下のようにするか |
20686 | 21303 | |
20687 | 21304 | use POSIX ":sys_wait_h"; |
20688 | 21305 | |
20689 | 21306 | my $kid; |
20690 | 21307 | do { |
20691 | 21308 | $kid = waitpid(-1, WNOHANG); |
20692 | 21309 | } while $kid > 0; |
20693 | 21310 | |
20694 | 21311 | =begin original |
20695 | 21312 | |
20696 | 21313 | or |
20697 | 21314 | |
20698 | 21315 | =end original |
20699 | 21316 | |
20700 | 21317 | または |
20701 | 21318 | |
20702 | 21319 | 1 while waitpid(-1, WNOHANG) > 0; |
20703 | 21320 | |
20704 | 21321 | =begin original |
20705 | 21322 | |
20706 | 21323 | then you can do a non-blocking wait for all pending zombie processes (see |
20707 | 21324 | L<POSIX/WAIT>). |
20708 | 21325 | Non-blocking wait is available on machines supporting either the |
20709 | 21326 | L<waitpid(2)> or L<wait4(2)> syscalls. However, waiting for a particular |
20710 | 21327 | pid with FLAGS of C<0> is implemented everywhere. (Perl emulates the |
20711 | 21328 | system call by remembering the status values of processes that have |
20712 | 21329 | exited but have not been harvested by the Perl script yet.) |
20713 | 21330 | |
20714 | 21331 | =end original |
20715 | 21332 | |
20716 | 21333 | とすると、ブロックが起こらないようにして、全ての待機中ゾンビプロセスを |
20717 | 21334 | wait します (L<POSIX/WAIT> を参照してください)。 |
20718 | 21335 | ブロックなしの wait は、システムコール L<wait_pid(2)> か、 |
20719 | 21336 | システムコール L<wait4(2)> をサポートしているマシンで利用可能です。 |
20720 | 21337 | しかしながら、特定の pid を C<0> の FLAGS での wait はどこでも |
20721 | 21338 | 実装されています。 |
20722 | 21339 | (exit したプロセスのステータス値を覚えておいて、Perl がシステムコールを |
20723 | 21340 | エミュレートしますが、Perl スクリプトには取り入れられていません。) |
20724 | 21341 | |
20725 | 21342 | =begin original |
20726 | 21343 | |
20727 | 21344 | Note that on some systems, a return value of C<-1> could mean that child |
20728 | 21345 | processes are being automatically reaped. See L<perlipc> for details, |
20729 | 21346 | and for other examples. |
20730 | 21347 | |
20731 | 21348 | =end original |
20732 | 21349 | |
20733 | 21350 | システムによっては、返り値が C<-1> の場合は子プロセスが自動的に |
20734 | 21351 | 刈り取られたことを意味するかもしれないことに注意してください。 |
20735 | 21352 | 詳細やその他の例については L<perlipc> を参照してください。 |
20736 | 21353 | |
20737 | 21354 | =begin original |
20738 | 21355 | |
20739 | 21356 | Portability issues: L<perlport/waitpid>. |
20740 | 21357 | |
20741 | 21358 | =end original |
20742 | 21359 | |
20743 | 21360 | 移植性の問題: L<perlport/waitpid>。 |
20744 | 21361 | |
20745 | 21362 | =item wantarray |
20746 | 21363 | X<wantarray> X<context> |
20747 | 21364 | |
20748 | 21365 | =for Pod::Functions get void vs scalar vs list context of current subroutine call |
20749 | 21366 | |
20750 | 21367 | =begin original |
20751 | 21368 | |
20752 | 21369 | Returns true if the context of the currently executing subroutine or |
20753 | 21370 | L<C<eval>|/eval EXPR> is looking for a list value. Returns false if the |
20754 | 21371 | context is |
20755 | 21372 | looking for a scalar. Returns the undefined value if the context is |
20756 | 21373 | looking for no value (void context). |
20757 | 21374 | |
20758 | 21375 | =end original |
20759 | 21376 | |
20760 | 21377 | 現在実行中のサブルーチンか L<C<eval>|/eval EXPR> ブロックのコンテキストが、 |
20761 | 21378 | リスト値を要求するものであれば、真を返します。 |
20762 | 21379 | スカラを要求するコンテキストであれば、偽を返します。 |
20763 | 21380 | 何も値を要求しない(無効コンテキスト)場合は未定義値を返します。 |
20764 | 21381 | |
20765 | 21382 | return unless defined wantarray; # don't bother doing more |
20766 | 21383 | my @a = complex_calculation(); |
20767 | 21384 | return wantarray ? @a : "@a"; |
20768 | 21385 | |
20769 | 21386 | =begin original |
20770 | 21387 | |
20771 | 21388 | L<C<wantarray>|/wantarray>'s result is unspecified in the top level of a file, |
20772 | 21389 | in a C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT> or C<END> block, or |
20773 | 21390 | in a C<DESTROY> method. |
20774 | 21391 | |
20775 | 21392 | =end original |
20776 | 21393 | |
20777 | 21394 | ファイルのトップレベル、C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT>, C<END> |
20778 | 21395 | ブロック内、C<DESTROY> メソッド内では L<C<wantarray>|/wantarray> の結果は |
20779 | 21396 | 未定義です。 |
20780 | 21397 | |
20781 | 21398 | =begin original |
20782 | 21399 | |
20783 | 21400 | This function should have been named wantlist() instead. |
20784 | 21401 | |
20785 | 21402 | =end original |
20786 | 21403 | |
20787 | 21404 | この関数は wantlist() という名前にするべきでした。 |
20788 | 21405 | |
20789 | 21406 | =item warn LIST |
20790 | 21407 | X<warn> X<warning> X<STDERR> |
20791 | 21408 | |
20792 | 21409 | =for Pod::Functions print debugging info |
20793 | 21410 | |
20794 | 21411 | =begin original |
20795 | 21412 | |
20796 | ||
21413 | Emits a warning, usually by printing it to C<STDERR>. C<warn> interprets | |
20797 | ||
21414 | its operand LIST in the same way as C<die>, but is slightly different | |
20798 | ||
21415 | in what it defaults to when LIST is empty or makes an empty string. | |
21416 | If it is empty and L<C<$@>|perlvar/$@> already contains an exception | |
21417 | value then that value is used after appending C<"\t...caught">. If it | |
21418 | is empty and C<$@> is also empty then the string C<"Warning: Something's | |
21419 | wrong"> is used. | |
20799 | 21420 | |
20800 | 21421 | =end original |
20801 | 21422 | |
20802 | ||
21423 | (通常は C<STDERR> に表示することで) 警告を出力します。 | |
20803 | LIST | |
21424 | C<warn> はそのオペランド LIST を C<die> と同様に解釈しますが、 | |
20804 | ||
21425 | LIST が空や空文字列を作る時に何をデフォルトとするかが少し異なります。 | |
21426 | それが空かつ、L<C<$@>|perlvar/$@> に既に | |
20806 | ||
21427 | 例外値が入っている場合、C<"\t...caught"> を追加した値が | |
20807 | ||
20808 | If the output is empty and L<C<$@>|perlvar/$@> already contains a value | |
20809 | (typically from a previous eval) that value is used after appending | |
20810 | C<"\t...caught"> to L<C<$@>|perlvar/$@>. This is useful for staying | |
20811 | almost, but not entirely similar to L<C<die>|/die LIST>. | |
20812 | ||
20813 | =end original | |
20814 | ||
20815 | 出力が空かつ、(典型的には以前の eval によって) L<C<$@>|perlvar/$@> に既に値が | |
20816 | 入っている場合、L<C<$@>|perlvar/$@> に C<"\t...caught"> を追加した値が | |
20817 | 21428 | 用いられます。 |
20818 | これ | |
21429 | もしこれが空で C<$@> も空の場合は、C<"Warning: Something's wrong"> という | |
20819 | L<C<die>|/die LIST> と全体的に似ているわけではありません。 | |
20820 | ||
20821 | =begin original | |
20822 | ||
20823 | If L<C<$@>|perlvar/$@> is empty, then the string | |
20824 | C<"Warning: Something's wrong"> is used. | |
20825 | ||
20826 | =end original | |
20827 | ||
20828 | L<C<$@>|perlvar/$@> が空の場合は、C<"Warning: Something's wrong"> という | |
20829 | 21430 | 文字列が使われます。 |
20830 | 21431 | |
20831 | 21432 | =begin original |
20832 | 21433 | |
20833 | ||
21434 | By default, the exception derived from the operand LIST is stringified | |
20834 | ||
21435 | and printed to C<STDERR>. This behaviour can be altered by installing | |
20835 | ||
21436 | a L<C<$SIG{__WARN__}>|perlvar/%SIG> handler. If there is such a | |
21437 | handler then no message is automatically printed; it is the handler's | |
21438 | responsibility to deal with the exception | |
20836 | 21439 | as it sees fit (like, for instance, converting it into a |
20837 | 21440 | L<C<die>|/die LIST>). Most |
20838 | 21441 | handlers must therefore arrange to actually display the |
20839 | 21442 | warnings that they are not prepared to deal with, by calling |
20840 | 21443 | L<C<warn>|/warn LIST> |
20841 | 21444 | again in the handler. Note that this is quite safe and will not |
20842 | 21445 | produce an endless loop, since C<__WARN__> hooks are not called from |
20843 | 21446 | inside one. |
20844 | 21447 | |
20845 | 21448 | =end original |
20846 | 21449 | |
20847 | L | |
21450 | デフォルトでは、LIST オペランドから生成された例外は | |
20848 | ||
21451 | 文字列化されて C<STDERR> に表示されます。 | |
20849 | ||
21452 | この振る舞いは、L<C<$SIG{__WARN__}>|perlvar/%SIG> ハンドラを設定することで | |
21453 | 置き換えられます。 | |
21454 | このようなハンドラが設定されている場合は何の | |
21455 | メッセージも自動的には表示されません; | |
21456 | 例外をどう扱うか(例えば L<C<die>|/die LIST> に変換するか)はハンドラの | |
20850 | 21457 | 責任ということです。 |
20851 | 21458 | 従ってほとんどのハンドラは、扱おうと準備していない警告を表示するために、 |
20852 | 21459 | ハンドラの中で L<C<warn>|/warn LIST> を再び呼び出します。 |
20853 | 21460 | C<__WARN__> フックはハンドラ内では呼び出されないので、これは十分安全で、 |
20854 | 21461 | 無限ループを引き起こすことはないということに注意してください。 |
20855 | 21462 | |
20856 | 21463 | =begin original |
20857 | 21464 | |
20858 | 21465 | You will find this behavior is slightly different from that of |
20859 | 21466 | L<C<$SIG{__DIE__}>|perlvar/%SIG> handlers (which don't suppress the |
20860 | 21467 | error text, but can instead call L<C<die>|/die LIST> again to change |
20861 | 21468 | it). |
20862 | 21469 | |
20863 | 21470 | =end original |
20864 | 21471 | |
20865 | 21472 | この振る舞いは L<C<$SIG{__DIE__}>|perlvar/%SIG> ハンドラ(エラーテキストは |
20866 | 21473 | 削除しませんが、代わりに L<C<die>|/die LIST> をもう一度呼び出すことで |
20867 | 21474 | 変更できます)とは少し違うことに気付くことでしょう。 |
20868 | 21475 | |
20869 | 21476 | =begin original |
20870 | 21477 | |
20871 | 21478 | Using a C<__WARN__> handler provides a powerful way to silence all |
20872 | 21479 | warnings (even the so-called mandatory ones). An example: |
20873 | 21480 | |
20874 | 21481 | =end original |
20875 | 21482 | |
20876 | 21483 | C<__WARN__> ハンドラを使うと、(いわゆる必須のものを含む)全ての |
20877 | 21484 | 警告を黙らせる強力な手段となります。 |
20878 | 21485 | 例: |
20879 | 21486 | |
20880 | 21487 | # wipe out *all* compile-time warnings |
20881 | 21488 | BEGIN { $SIG{'__WARN__'} = sub { warn $_[0] if $DOWARN } } |
20882 | 21489 | my $foo = 10; |
20883 | 21490 | my $foo = 20; # no warning about duplicate my $foo, |
20884 | 21491 | # but hey, you asked for it! |
20885 | 21492 | # no compile-time or run-time warnings before here |
20886 | 21493 | $DOWARN = 1; |
20887 | 21494 | |
20888 | 21495 | # run-time warnings enabled after here |
20889 | 21496 | warn "\$foo is alive and $foo!"; # does show up |
20890 | 21497 | |
20891 | 21498 | =begin original |
20892 | 21499 | |
20893 | 21500 | See L<perlvar> for details on setting L<C<%SIG>|perlvar/%SIG> entries |
20894 | 21501 | and for more |
20895 | 21502 | examples. See the L<Carp> module for other kinds of warnings using its |
20896 | 21503 | C<carp> and C<cluck> functions. |
20897 | 21504 | |
20898 | 21505 | =end original |
20899 | 21506 | |
20900 | 21507 | L<C<%SIG>|perlvar/%SIG> エントリのセットに関する詳細とさらなる例に関しては |
20901 | 21508 | L<perlvar> を参照してください。 |
20902 | 21509 | C<carp> 関数と C<cluck> 関数を用いた警告の方法に関しては |
20903 | 21510 | L<Carp> モジュールを参照してください。 |
20904 | 21511 | |
20905 | 21512 | =item write FILEHANDLE |
20906 | 21513 | X<write> |
20907 | 21514 | |
20908 | 21515 | =item write EXPR |
20909 | 21516 | |
20910 | 21517 | =item write |
20911 | 21518 | |
20912 | 21519 | =for Pod::Functions print a picture record |
20913 | 21520 | |
20914 | 21521 | =begin original |
20915 | 21522 | |
20916 | 21523 | Writes a formatted record (possibly multi-line) to the specified FILEHANDLE, |
20917 | 21524 | using the format associated with that file. By default the format for |
20918 | 21525 | a file is the one having the same name as the filehandle, but the |
20919 | 21526 | format for the current output channel (see the |
20920 | 21527 | L<C<select>|/select FILEHANDLE> function) may be set explicitly by |
20921 | 21528 | assigning the name of the format to the L<C<$~>|perlvar/$~> variable. |
20922 | 21529 | |
20923 | 21530 | =end original |
20924 | 21531 | |
20925 | 21532 | 指定された FILEHANDLE に対して、そのファイルに対応させた |
20926 | 21533 | フォーマットを使って、(複数行の場合もある) 整形された |
20927 | 21534 | レコードを書き出します。 |
20928 | 21535 | デフォルトでは、ファイルに対応するフォーマットは、ファイルハンドルと |
20929 | 21536 | 同じ名前のものですが、その時点の出力チャネル |
20930 | 21537 | (L<C<select>|/select FILEHANDLE> 関数の項を |
20931 | 21538 | 参照してください) のフォーマットは、その名前を明示的に変数 |
20932 | 21539 | L<C<$~>|perlvar/$~> に代入することで、変更が可能です。 |
20933 | 21540 | |
20934 | 21541 | =begin original |
20935 | 21542 | |
20936 | 21543 | Top of form processing is handled automatically: if there is insufficient |
20937 | 21544 | room on the current page for the formatted record, the page is advanced by |
20938 | 21545 | writing a form feed and a special top-of-page |
20939 | 21546 | format is used to format the new |
20940 | 21547 | page header before the record is written. By default, the top-of-page |
20941 | 21548 | format is the name of the filehandle with C<_TOP> appended, or C<top> |
20942 | 21549 | in the current package if the former does not exist. This would be a |
20943 | 21550 | problem with autovivified filehandles, but it may be dynamically set to the |
20944 | 21551 | format of your choice by assigning the name to the L<C<$^>|perlvar/$^> |
20945 | 21552 | variable while that filehandle is selected. The number of lines |
20946 | 21553 | remaining on the current page is in variable L<C<$->|perlvar/$->, which |
20947 | 21554 | can be set to C<0> to force a new page. |
20948 | 21555 | |
20949 | 21556 | =end original |
20950 | 21557 | |
20951 | 21558 | ページの先頭の処理は、自動的に行なわれます: 現在のページに整形された |
20952 | 21559 | レコードを出力するだけのスペースがない場合には、改ページを行なってページを |
20953 | 21560 | 進め、新しいページヘッダを整形するため、ページ先頭フォーマットが使われ、 |
20954 | 21561 | その後でレコードが書かれます。 |
20955 | 21562 | デフォルトでは、ページ先頭フォーマットは、ファイルハンドルの名前に |
20956 | 21563 | C<_TOP> をつなげたものか、前者が存在しないなら、現在のパッケージの |
20957 | 21564 | C<top> です。 |
20958 | 21565 | これは自動有効化されたファイルハンドルで問題になる可能性がありますが、 |
20959 | 21566 | ファイルハンドルが選択されている間に、 |
20960 | 21567 | 変数 L<C<$^>|perlvar/$^> に名前を設定すれば、動的にフォーマットを |
20961 | 21568 | 変更することができます。 |
20962 | 21569 | そのページの残り行数は、変数 L<C<$->|perlvar/$-> に入っており、この変数を |
20963 | 21570 | C<0> に設定することで、強制的に改ページを行なうことができます。 |
20964 | 21571 | |
20965 | 21572 | =begin original |
20966 | 21573 | |
20967 | 21574 | If FILEHANDLE is unspecified, output goes to the current default output |
20968 | 21575 | channel, which starts out as STDOUT but may be changed by the |
20969 | 21576 | L<C<select>|/select FILEHANDLE> operator. If the FILEHANDLE is an EXPR, |
20970 | 21577 | then the expression |
20971 | 21578 | is evaluated and the resulting string is used to look up the name of |
20972 | 21579 | the FILEHANDLE at run time. For more on formats, see L<perlform>. |
20973 | 21580 | |
20974 | 21581 | =end original |
20975 | 21582 | |
20976 | 21583 | FILEHANDLE を指定しないと、出力はその時点のデフォルト出力チャネルに対して |
20977 | 21584 | 行なわれます; これは、スクリプトの開始時点では STDOUT ですが、 |
20978 | 21585 | L<C<select>|/select FILEHANDLE> 演算子で変更することができます。 |
20979 | 21586 | FILEHANDLE が EXPR ならば、式が評価され、その結果の文字列が |
20980 | 21587 | 実行時に FILEHANDLE の名前として見られます。 |
20981 | 21588 | フォーマットについて、さらには、L<perlform> を参照してください。 |
20982 | 21589 | |
20983 | 21590 | =begin original |
20984 | 21591 | |
20985 | 21592 | Note that write is I<not> the opposite of |
20986 | 21593 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>. Unfortunately. |
20987 | 21594 | |
20988 | 21595 | =end original |
20989 | 21596 | |
20990 | 21597 | write は L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> の |
20991 | 21598 | 反対のことをするもの I<ではありません>。 |
20992 | 21599 | 残念ながら。 |
20993 | 21600 | |
20994 | 21601 | =item y/// |
20995 | 21602 | |
20996 | 21603 | =for Pod::Functions transliterate a string |
20997 | 21604 | |
20998 | 21605 | =begin original |
20999 | 21606 | |
21000 | 21607 | The transliteration operator. Same as |
21001 | 21608 | L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>>. See |
21002 | 21609 | L<perlop/"Quote-Like Operators">. |
21003 | 21610 | |
21004 | 21611 | =end original |
21005 | 21612 | |
21006 | 21613 | 文字変換演算子です。 |
21007 | 21614 | L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>> と同じです。 |
21008 | 21615 | L<perlop/"Quote-Like Operators"> を参照してください。 |
21009 | 21616 | |
21010 | 21617 | =back |
21011 | 21618 | |
21012 | 21619 | =head2 Non-function Keywords by Cross-reference |
21013 | 21620 | |
21014 | 21621 | =head3 perldata |
21015 | 21622 | |
21016 | 21623 | =over |
21017 | 21624 | |
21018 | 21625 | =item __DATA__ |
21019 | 21626 | |
21020 | 21627 | =item __END__ |
21021 | 21628 | |
21022 | 21629 | =begin original |
21023 | 21630 | |
21024 | 21631 | These keywords are documented in L<perldata/"Special Literals">. |
21025 | 21632 | |
21026 | 21633 | =end original |
21027 | 21634 | |
21028 | 21635 | これらのキーワードは L<perldata/"Special Literals"> で文書化されています。 |
21029 | 21636 | |
21030 | 21637 | =back |
21031 | 21638 | |
21032 | 21639 | =head3 perlmod |
21033 | 21640 | |
21034 | 21641 | =over |
21035 | 21642 | |
21036 | 21643 | =item BEGIN |
21037 | 21644 | |
21038 | 21645 | =item CHECK |
21039 | 21646 | |
21040 | 21647 | =item END |
21041 | 21648 | |
21042 | 21649 | =item INIT |
21043 | 21650 | |
21044 | 21651 | =item UNITCHECK |
21045 | 21652 | |
21046 | 21653 | =begin original |
21047 | 21654 | |
21048 | 21655 | These compile phase keywords are documented in L<perlmod/"BEGIN, UNITCHECK, CHECK, INIT and END">. |
21049 | 21656 | |
21050 | 21657 | =end original |
21051 | 21658 | |
21052 | 21659 | これらのコンパイルフェーズキーワードは |
21053 | 21660 | L<perlmod/"BEGIN, UNITCHECK, CHECK, INIT and END"> で文書化されています。 |
21054 | 21661 | |
21055 | 21662 | =back |
21056 | 21663 | |
21057 | 21664 | =head3 perlobj |
21058 | 21665 | |
21059 | 21666 | =over |
21060 | 21667 | |
21061 | 21668 | =item DESTROY |
21062 | 21669 | |
21063 | 21670 | =begin original |
21064 | 21671 | |
21065 | 21672 | This method keyword is documented in L<perlobj/"Destructors">. |
21066 | 21673 | |
21067 | 21674 | =end original |
21068 | 21675 | |
21069 | 21676 | このメソッドキーワードは L<perlobj/"Destructors"> で文書化されています。 |
21070 | 21677 | |
21071 | 21678 | =back |
21072 | 21679 | |
21073 | 21680 | =head3 perlop |
21074 | 21681 | |
21075 | 21682 | =over |
21076 | 21683 | |
21077 | 21684 | =item and |
21078 | 21685 | |
21079 | 21686 | =item cmp |
21080 | 21687 | |
21081 | 21688 | =item eq |
21082 | 21689 | |
21083 | 21690 | =item ge |
21084 | 21691 | |
21085 | 21692 | =item gt |
21086 | 21693 | |
21087 | 21694 | =item le |
21088 | 21695 | |
21089 | 21696 | =item lt |
21090 | 21697 | |
21091 | 21698 | =item ne |
21092 | 21699 | |
21093 | 21700 | =item not |
21094 | 21701 | |
21095 | 21702 | =item or |
21096 | 21703 | |
21097 | 21704 | =item x |
21098 | 21705 | |
21099 | 21706 | =item xor |
21100 | 21707 | |
21101 | 21708 | =begin original |
21102 | 21709 | |
21103 | 21710 | These operators are documented in L<perlop>. |
21104 | 21711 | |
21105 | 21712 | =end original |
21106 | 21713 | |
21107 | 21714 | これらの演算子は L<perlop> で文書化されています。 |
21108 | 21715 | |
21109 | 21716 | =back |
21110 | 21717 | |
21111 | 21718 | =head3 perlsub |
21112 | 21719 | |
21113 | 21720 | =over |
21114 | 21721 | |
21115 | 21722 | =item AUTOLOAD |
21116 | 21723 | |
21117 | 21724 | =begin original |
21118 | 21725 | |
21119 | 21726 | This keyword is documented in L<perlsub/"Autoloading">. |
21120 | 21727 | |
21121 | 21728 | =end original |
21122 | 21729 | |
21123 | 21730 | このキーワードは L<perlsub/"Autoloading"> で文書化されています。 |
21124 | 21731 | |
21125 | 21732 | =back |
21126 | 21733 | |
21127 | 21734 | =head3 perlsyn |
21128 | 21735 | |
21129 | 21736 | =over |
21130 | 21737 | |
21131 | 21738 | =item else |
21132 | 21739 | |
21133 | 21740 | =item elsif |
21134 | 21741 | |
21135 | 21742 | =item for |
21136 | 21743 | |
21137 | 21744 | =item foreach |
21138 | 21745 | |
21139 | 21746 | =item if |
21140 | 21747 | |
21141 | 21748 | =item unless |
21142 | 21749 | |
21143 | 21750 | =item until |
21144 | 21751 | |
21145 | 21752 | =item while |
21146 | 21753 | |
21147 | 21754 | =begin original |
21148 | 21755 | |
21149 | 21756 | These flow-control keywords are documented in L<perlsyn/"Compound Statements">. |
21150 | 21757 | |
21151 | 21758 | =end original |
21152 | 21759 | |
21153 | 21760 | これらのフロー制御キーワードは L<perlsyn/"Compound Statements"> で |
21154 | 21761 | 文書化されています。 |
21155 | 21762 | |
21156 | 21763 | =item elseif |
21157 | 21764 | |
21158 | 21765 | =begin original |
21159 | 21766 | |
21160 | 21767 | The "else if" keyword is spelled C<elsif> in Perl. There's no C<elif> |
21161 | 21768 | or C<else if> either. It does parse C<elseif>, but only to warn you |
21162 | 21769 | about not using it. |
21163 | 21770 | |
21164 | 21771 | =end original |
21165 | 21772 | |
21166 | 21773 | "else if" キーワードは Perl では C<elsif> と綴ります。 |
21167 | 21774 | C<elif> や C<else if> はありません。 |
21168 | 21775 | C<elseif> はパースされますが、使わないように警告するためだけです。 |
21169 | 21776 | |
21170 | 21777 | =begin original |
21171 | 21778 | |
21172 | 21779 | See the documentation for flow-control keywords in L<perlsyn/"Compound |
21173 | 21780 | Statements">. |
21174 | 21781 | |
21175 | 21782 | =end original |
21176 | 21783 | |
21177 | 21784 | L<perlsyn/"Compound Statements"> のフロー制御キーワードに関する文章を |
21178 | 21785 | 参照してください。 |
21179 | 21786 | |
21180 | 21787 | =back |
21181 | 21788 | |
21182 | 21789 | =over |
21183 | 21790 | |
21184 | 21791 | =item default |
21185 | 21792 | |
21186 | 21793 | =item given |
21187 | 21794 | |
21188 | 21795 | =item when |
21189 | 21796 | |
21190 | 21797 | =begin original |
21191 | 21798 | |
21192 | 21799 | These flow-control keywords related to the experimental switch feature are |
21193 | 21800 | documented in L<perlsyn/"Switch Statements">. |
21194 | 21801 | |
21195 | 21802 | =end original |
21196 | 21803 | |
21197 | 21804 | これらの実験的な switch 機能に関連するフロー制御キーワードは |
21198 | 21805 | L<perlsyn/"Switch Statements"> で文書化されています。 |
21199 | 21806 | |
21200 | 21807 | =back |
21201 | 21808 | |
21202 | 21809 | =cut |
21203 | 21810 | |
21204 | 21811 | =begin meta |
21205 | 21812 | |
21206 | 21813 | Translate: 吉村 寿人 <JAE00534@niftyserve.or.jp> |
21207 | 21814 | Update: SHIRAKATA Kentaro <argrath@ub32.org> (5.6.1-) |
21208 | 21815 | Status: completed |
21209 | 21816 | |
21210 | 21817 | =end meta |