perlfunc >
5.20.1
との差分
perlfunc 5.20.1 と 5.16.1 の差分
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, splice() has three scalar |
31 | 31 | arguments followed by a list, whereas gethostbyname() has four scalar |
32 | 32 | arguments. |
33 | 33 | |
34 | 34 | =end original |
35 | 35 | |
36 | 36 | この節の関数は、式の中で項として使うことができます。 |
37 | 37 | これらは、大きく二つに分けられます: |
38 | 38 | リスト演算子と名前付き単項演算子です。 |
39 | 39 | これらの違いは、その後に出て来るコンマとの優先順位の関係にあります。 |
40 | 40 | (L<perlop> の優先順位の表を参照してください。) |
41 | 41 | リスト演算子は 2 個以上の引数をとるのに対して、単項演算子が複数の引数を |
42 | 42 | とることはありません。 |
43 | 43 | つまり、コンマは単項演算子の引数の終わりとなりますが、リスト演算子の |
44 | 44 | 場合には、引数の区切りでしかありません。 |
45 | 45 | 単項演算子は一般に、引数に対してスカラコンテキストを与えるのに対して、 |
46 | 46 | スカラ演算子の場合には、引数に対してスカラコンテキストを与える場合も、 |
47 | 47 | リストコンテキストを与える場合もあります。 |
48 | 48 | 一つのリスト演算子が両方のコンテキストを与える場合には、スカラ引数が |
49 | 49 | いくつか並び、最後にリスト引数が一つ続きます; |
50 | 50 | そしてそのようなリスト引数は一つだけしかありません。 |
51 | 51 | たとえば、splice() は三つのスカラ引数に一つのリスト引数が続きます; |
52 | 52 | 一方 gethostbyname() は四つのスカラ引数を持ちます。 |
53 | 53 | |
54 | 54 | =begin original |
55 | 55 | |
56 | 56 | In the syntax descriptions that follow, list operators that expect a |
57 | 57 | list (and provide list context for elements of the list) are shown |
58 | 58 | with LIST as an argument. Such a list may consist of any combination |
59 | 59 | of scalar arguments or list values; the list values will be included |
60 | 60 | in the list as if each individual element were interpolated at that |
61 | 61 | point in the list, forming a longer single-dimensional list value. |
62 | 62 | Commas should separate literal elements of the LIST. |
63 | 63 | |
64 | 64 | =end original |
65 | 65 | |
66 | 66 | 後に載せる構文記述では、リストをとり (そのリストの要素にリストコンテキストを |
67 | 67 | 与える)リスト演算子は、引数として LIST をとるように書いています; |
68 | 68 | そのようなリストには、任意のスカラ引数の組み合わせやリスト値を |
69 | 69 | 含めることができ、リスト値はリストの中に、個々の要素が展開されたように |
70 | 70 | 埋め込まれます。 |
71 | 71 | 1 次元の長いリスト値が形成されることになります。 |
72 | 72 | LIST のリテラルな要素は、コンマで区切られます。 |
73 | 73 | |
74 | 74 | =begin original |
75 | 75 | |
76 | 76 | Any function in the list below may be used either with or without |
77 | 77 | parentheses around its arguments. (The syntax descriptions omit the |
78 | 78 | parentheses.) If you use parentheses, the simple but occasionally |
79 | 79 | surprising rule is this: It I<looks> like a function, therefore it I<is> a |
80 | 80 | function, and precedence doesn't matter. Otherwise it's a list |
81 | 81 | operator or unary operator, and precedence does matter. Whitespace |
82 | 82 | between the function and left parenthesis doesn't count, so sometimes |
83 | 83 | you need to be careful: |
84 | 84 | |
85 | 85 | =end original |
86 | 86 | |
87 | 87 | 以下のリストの関数はすべて、引数の前後の括弧は省略可能となっています。 |
88 | 88 | (構文記述では省略しています。) |
89 | 89 | 括弧を使うときには、単純な、(しかし、ときには驚く結果となる規則が |
90 | 90 | 適用できます: |
91 | 91 | I<関数に見える>ならば、I<それは関数>で、優先順位は関係ありません。 |
92 | 92 | そう見えなければ、それはリスト演算子か単項演算子で、優先順位が関係します。 |
93 | 93 | 関数と開き括弧の間の空白は関係ありませんので、ときに |
94 | 94 | 気を付けなければなりません: |
95 | 95 | |
96 | 96 | print 1+2+4; # Prints 7. |
97 | 97 | print(1+2) + 4; # Prints 3. |
98 | 98 | print (1+2)+4; # Also prints 3! |
99 | 99 | print +(1+2)+4; # Prints 7. |
100 | 100 | print ((1+2)+4); # Prints 7. |
101 | 101 | |
102 | 102 | =begin original |
103 | 103 | |
104 | 104 | If you run Perl with the B<-w> switch it can warn you about this. For |
105 | 105 | example, the third line above produces: |
106 | 106 | |
107 | 107 | =end original |
108 | 108 | |
109 | 109 | Perl に B<-w> スイッチを付けて実行すれば、こういったものには警告を |
110 | 110 | 出してくれます。 |
111 | 111 | たとえば、上記の三つめは、以下のような警告が出ます: |
112 | 112 | |
113 | 113 | print (...) interpreted as function at - line 1. |
114 | 114 | Useless use of integer addition in void context at - line 1. |
115 | 115 | |
116 | 116 | =begin original |
117 | 117 | |
118 | 118 | A few functions take no arguments at all, and therefore work as neither |
119 | 119 | unary nor list operators. These include such functions as C<time> |
120 | 120 | and C<endpwent>. For example, C<time+86_400> always means |
121 | 121 | C<time() + 86_400>. |
122 | 122 | |
123 | 123 | =end original |
124 | 124 | |
125 | 125 | いくつかの関数は引数を全くとらないので、単項演算子としても |
126 | 126 | リスト演算子としても動作しません。 |
127 | 127 | このような関数としては C<time> や C<endpwent> があります。 |
128 | 128 | 例えば、C<time+86_400> は常に C<time() + 86_400> として扱われます。 |
129 | 129 | |
130 | 130 | =begin original |
131 | 131 | |
132 | 132 | For functions that can be used in either a scalar or list context, |
133 | 133 | nonabortive failure is generally indicated in scalar context by |
134 | 134 | returning the undefined value, and in list context by returning the |
135 | 135 | empty list. |
136 | 136 | |
137 | 137 | =end original |
138 | 138 | |
139 | 139 | スカラコンテキストでも、リストコンテキストでも使える関数は、致命的でない |
140 | 140 | エラーを示すために、スカラコンテキストでは未定義値を返し、 |
141 | 141 | リストコンテキストでは空リストを返します。 |
142 | 142 | |
143 | 143 | =begin original |
144 | 144 | |
145 | 145 | Remember the following important rule: There is B<no rule> that relates |
146 | 146 | the behavior of an expression in list context to its behavior in scalar |
147 | 147 | context, or vice versa. It might do two totally different things. |
148 | 148 | Each operator and function decides which sort of value would be most |
149 | 149 | appropriate to return in scalar context. Some operators return the |
150 | 150 | length of the list that would have been returned in list context. Some |
151 | 151 | operators return the first value in the list. Some operators return the |
152 | 152 | last value in the list. Some operators return a count of successful |
153 | 153 | operations. In general, they do what you want, unless you want |
154 | 154 | consistency. |
155 | 155 | X<context> |
156 | 156 | |
157 | 157 | =end original |
158 | 158 | |
159 | 159 | 以下に述べる重要なルールを忘れないで下さい: リストコンテキストでの |
160 | 160 | 振る舞いとスカラコンテキストでの振る舞いの関係、あるいはその逆に |
161 | 161 | B<ルールはありません>。 |
162 | 162 | 2 つの全く異なったことがあります。 |
163 | 163 | それぞれの演算子と関数は、スカラコンテキストでは、もっとも適切と |
164 | 164 | 思われる値を返します。 |
165 | 165 | リストコンテキストで返す時のリストの長さを返す演算子もあります。 |
166 | 166 | リストの最初の値を返す演算子もあります。 |
167 | 167 | リストの最後の値を返す演算子もあります。 |
168 | 168 | 成功した操作の数を返す演算子もあります。 |
169 | 169 | 一般的には、一貫性を求めない限り、こちらが求めることをします。 |
170 | 170 | X<context> |
171 | 171 | |
172 | 172 | =begin original |
173 | 173 | |
174 | 174 | A named array in scalar context is quite different from what would at |
175 | 175 | first glance appear to be a list in scalar context. You can't get a list |
176 | 176 | like C<(1,2,3)> into being in scalar context, because the compiler knows |
177 | 177 | the context at compile time. It would generate the scalar comma operator |
178 | 178 | there, not the list construction version of the comma. That means it |
179 | 179 | was never a list to start with. |
180 | 180 | |
181 | 181 | =end original |
182 | 182 | |
183 | 183 | スカラコンテキストでの名前付き配列は、スカラコンテキストでのリストを |
184 | 184 | 一目見たものとは全く違います。 |
185 | 185 | コンパイラはコンパイル時にコンテキストを知っているので、 |
186 | 186 | C<(1,2,3)> のようなリストをスカラコンテキストで得ることはできません。 |
187 | 187 | これはスカラコンマ演算子を生成し、コンマのリスト作成版ではありません。 |
188 | 188 | これは初めからリストであることはないことを意味します。 |
189 | 189 | |
190 | 190 | =begin original |
191 | 191 | |
192 | 192 | In general, functions in Perl that serve as wrappers for system calls ("syscalls") |
193 | 193 | of the same name (like chown(2), fork(2), closedir(2), etc.) return |
194 | 194 | true when they succeed and C<undef> otherwise, as is usually mentioned |
195 | 195 | in the descriptions below. This is different from the C interfaces, |
196 | 196 | which return C<-1> on failure. Exceptions to this rule include C<wait>, |
197 | 197 | C<waitpid>, and C<syscall>. System calls also set the special C<$!> |
198 | 198 | variable on failure. Other functions do not, except accidentally. |
199 | 199 | |
200 | 200 | =end original |
201 | 201 | |
202 | 202 | 一般的に、同じ名前のシステムコールのラッパーとして動作する Perl の関数 |
203 | 203 | (chown(2), fork(2), closedir(2) など)は、以下に述べるように、 |
204 | 204 | 成功時に真を返し、そうでなければ C<undef> を返します。 |
205 | 205 | これは失敗時に C<-1> を返す C のインターフェースとは違います。 |
206 | 206 | このルールの例外は C<wait>, C<waitpid>, C<syscall> です。 |
207 | 207 | システムコールは失敗時に特殊変数 C<$!> をセットします。 |
208 | 208 | その他の関数は、事故を除いて、セットしません。 |
209 | 209 | |
210 | 210 | =begin original |
211 | 211 | |
212 | 212 | Extension modules can also hook into the Perl parser to define new |
213 | 213 | kinds of keyword-headed expression. These may look like functions, but |
214 | 214 | may also look completely different. The syntax following the keyword |
215 | 215 | is defined entirely by the extension. If you are an implementor, see |
216 | 216 | L<perlapi/PL_keyword_plugin> for the mechanism. If you are using such |
217 | 217 | a module, see the module's documentation for details of the syntax that |
218 | 218 | it defines. |
219 | 219 | |
220 | 220 | =end original |
221 | 221 | |
222 | 222 | エクステンションモジュールは、新しい種類のキーワードが頭に付いた式を |
223 | 223 | 定義するために Perl パーサをフックできます。 |
224 | 224 | これらは関数のように見えるかもしれませんが、全く別物かもしれません。 |
225 | 225 | キーワード以降の文法は完全にエクステンションによって定義されます。 |
226 | 226 | もしあなたが実装者なら、この機構については L<perlapi/PL_keyword_plugin> を |
227 | 227 | 参照してください。 |
228 | 228 | もしあなたがそのようなモジュールを使っているなら、 |
229 | 229 | 定義されている文法の詳細についてはモジュールの文書を参照してください。 |
230 | 230 | |
231 | 231 | =head2 Perl Functions by Category |
232 | 232 | X<function> |
233 | 233 | |
234 | 234 | (カテゴリ別の Perl 関数) |
235 | 235 | |
236 | 236 | =begin original |
237 | 237 | |
238 | 238 | Here are Perl's functions (including things that look like |
239 | 239 | functions, like some keywords and named operators) |
240 | 240 | arranged by category. Some functions appear in more |
241 | 241 | than one place. |
242 | 242 | |
243 | 243 | =end original |
244 | 244 | |
245 | 245 | 以下に、カテゴリ別の関数(キーワードや名前付き演算子のような、 |
246 | 246 | 関数のように見えるものも含みます)を示します。 |
247 | 247 | 複数の場所に現れる関数もあります。 |
248 | 248 | |
249 | 249 | =over 4 |
250 | 250 | |
251 | 251 | =item Functions for SCALARs or strings |
252 | 252 | X<scalar> X<string> X<character> |
253 | 253 | |
254 | 254 | (スカラや文字列のための関数) |
255 | 255 | |
256 | 256 | =for Pod::Functions =String |
257 | 257 | |
258 | 258 | C<chomp>, C<chop>, C<chr>, C<crypt>, C<fc>, C<hex>, C<index>, C<lc>, |
259 | 259 | C<lcfirst>, C<length>, C<oct>, C<ord>, C<pack>, C<q//>, C<qq//>, C<reverse>, |
260 | 260 | C<rindex>, C<sprintf>, C<substr>, C<tr///>, C<uc>, C<ucfirst>, C<y///> |
261 | 261 | |
262 | 262 | =begin original |
263 | 263 | |
264 | 264 | C<fc> is available only if the C<"fc"> feature is enabled or if it is |
265 | 265 | prefixed with C<CORE::>. The C<"fc"> feature is enabled automatically |
266 | 266 | with a C<use v5.16> (or higher) declaration in the current scope. |
267 | 267 | |
268 | 268 | =end original |
269 | 269 | |
270 | 270 | C<fc> は C<"fc"> 機能が有効か C<CORE::> が前置されたときにのみ利用可能です。 |
271 | 271 | C<"fc"> 機能は現在のスコープで C<use v5.16> (またはそれ以上) が宣言されると |
272 | 272 | 自動的に有効になります。 |
273 | 273 | |
274 | 274 | =item Regular expressions and pattern matching |
275 | 275 | X<regular expression> X<regex> X<regexp> |
276 | 276 | |
277 | 277 | (正規表現とパターンマッチング) |
278 | 278 | |
279 | 279 | =for Pod::Functions =Regexp |
280 | 280 | |
281 | 281 | C<m//>, C<pos>, C<qr//>, C<quotemeta>, C<s///>, C<split>, C<study> |
282 | 282 | |
283 | 283 | =item Numeric functions |
284 | 284 | X<numeric> X<number> X<trigonometric> X<trigonometry> |
285 | 285 | |
286 | 286 | (数値関数) |
287 | 287 | |
288 | 288 | =for Pod::Functions =Math |
289 | 289 | |
290 | 290 | C<abs>, C<atan2>, C<cos>, C<exp>, C<hex>, C<int>, C<log>, C<oct>, C<rand>, |
291 | 291 | C<sin>, C<sqrt>, C<srand> |
292 | 292 | |
293 | 293 | =item Functions for real @ARRAYs |
294 | 294 | X<array> |
295 | 295 | |
296 | 296 | (実配列のための関数) |
297 | 297 | |
298 | 298 | =for Pod::Functions =ARRAY |
299 | 299 | |
300 | 300 | C<each>, C<keys>, C<pop>, C<push>, C<shift>, C<splice>, C<unshift>, C<values> |
301 | 301 | |
302 | 302 | =item Functions for list data |
303 | 303 | X<list> |
304 | 304 | |
305 | 305 | (リストデータのための関数) |
306 | 306 | |
307 | 307 | =for Pod::Functions =LIST |
308 | 308 | |
309 | 309 | C<grep>, C<join>, C<map>, C<qw//>, C<reverse>, C<sort>, C<unpack> |
310 | 310 | |
311 | 311 | =item Functions for real %HASHes |
312 | 312 | X<hash> |
313 | 313 | |
314 | 314 | (実ハッシュのための関数) |
315 | 315 | |
316 | 316 | =for Pod::Functions =HASH |
317 | 317 | |
318 | 318 | C<delete>, C<each>, C<exists>, C<keys>, C<values> |
319 | 319 | |
320 | 320 | =item Input and output functions |
321 | 321 | X<I/O> X<input> X<output> X<dbm> |
322 | 322 | |
323 | 323 | (入出力関数) |
324 | 324 | |
325 | 325 | =for Pod::Functions =I/O |
326 | 326 | |
327 | 327 | C<binmode>, C<close>, C<closedir>, C<dbmclose>, C<dbmopen>, C<die>, C<eof>, |
328 | 328 | C<fileno>, C<flock>, C<format>, C<getc>, C<print>, C<printf>, C<read>, |
329 | 329 | C<readdir>, C<readline> C<rewinddir>, C<say>, C<seek>, C<seekdir>, C<select>, |
330 | 330 | C<syscall>, C<sysread>, C<sysseek>, C<syswrite>, C<tell>, C<telldir>, |
331 | 331 | C<truncate>, C<warn>, C<write> |
332 | 332 | |
333 | 333 | =begin original |
334 | 334 | |
335 | 335 | C<say> is available only if the C<"say"> feature is enabled or if it is |
336 | 336 | prefixed with C<CORE::>. The C<"say"> feature is enabled automatically |
337 | 337 | with a C<use v5.10> (or higher) declaration in the current scope. |
338 | 338 | |
339 | 339 | =end original |
340 | 340 | |
341 | 341 | C<say> は C<"say"> 機能が有効か C<CORE::> が前置されたときにのみ利用可能です。 |
342 | 342 | C<"say"> 機能は現在のスコープで C<use v5.10> (またはそれ以上) が宣言されると |
343 | 343 | 自動的に有効になります。 |
344 | 344 | |
345 | 345 | =item Functions for fixed-length data or records |
346 | 346 | |
347 | 347 | (固定長データやレコードのための関数) |
348 | 348 | |
349 | 349 | =for Pod::Functions =Binary |
350 | 350 | |
351 | 351 | C<pack>, C<read>, C<syscall>, C<sysread>, C<sysseek>, C<syswrite>, C<unpack>, |
352 | 352 | C<vec> |
353 | 353 | |
354 | 354 | =item Functions for filehandles, files, or directories |
355 | 355 | X<file> X<filehandle> X<directory> X<pipe> X<link> X<symlink> |
356 | 356 | |
357 | 357 | (ファイルハンドル、ファイル、ディレクトリのための関数) |
358 | 358 | |
359 | 359 | =for Pod::Functions =File |
360 | 360 | |
361 | 361 | C<-I<X>>, C<chdir>, C<chmod>, C<chown>, C<chroot>, C<fcntl>, C<glob>, |
362 | 362 | C<ioctl>, C<link>, C<lstat>, C<mkdir>, C<open>, C<opendir>, |
363 | 363 | C<readlink>, C<rename>, C<rmdir>, C<stat>, C<symlink>, C<sysopen>, |
364 | 364 | C<umask>, C<unlink>, C<utime> |
365 | 365 | |
366 | 366 | =item Keywords related to the control flow of your Perl program |
367 | 367 | X<control flow> |
368 | 368 | |
369 | 369 | (プログラムの流れを制御することに関連するキーワード) |
370 | 370 | |
371 | 371 | =for Pod::Functions =Flow |
372 | 372 | |
373 | 373 | C<break>, C<caller>, C<continue>, C<die>, C<do>, |
374 | 374 | C<dump>, C<eval>, C<evalbytes> C<exit>, |
375 | 375 | C<__FILE__>, C<goto>, C<last>, C<__LINE__>, C<next>, C<__PACKAGE__>, |
376 | 376 | C<redo>, C<return>, C<sub>, C<__SUB__>, C<wantarray> |
377 | 377 | |
378 | 378 | =begin original |
379 | 379 | |
380 | 380 | C<break> is available only if you enable the experimental C<"switch"> |
381 | feature or use the C<CORE::> prefix. | |
381 | feature or use the C<CORE::> prefix. The C<"switch"> feature also enables | |
382 | 382 | the C<default>, C<given> and C<when> statements, which are documented in |
383 | L<perlsyn/"Switch Statements">. | |
383 | L<perlsyn/"Switch Statements">. The C<"switch"> feature is enabled | |
384 | 384 | automatically with a C<use v5.10> (or higher) declaration in the current |
385 | scope. | |
385 | scope. In Perl v5.14 and earlier, C<continue> required the C<"switch"> | |
386 | 386 | feature, like the other keywords. |
387 | 387 | |
388 | 388 | =end original |
389 | 389 | |
390 | 390 | C<break> は C<"switch"> 機能が有効か C<CORE::> 接頭辞を使ったときにのみ |
391 | 391 | 利用可能です。 |
392 | 392 | C<"switch"> 機能は L<perlsyn/"Switch Statements"> で文書化されている |
393 | 393 | C<default>, C<given>, C<when> 文も有効にします。 |
394 | 394 | C<"switch"> 機能は現在のスコープで C<use v5.10> (またはそれ以上) が |
395 | 395 | 宣言されると自動的に有効になります。 |
396 | 396 | Perl v5.14 以前では、C<continue> は他のキーワードと同様に C<"switch"> 機能が |
397 | 397 | 必要です。 |
398 | 398 | |
399 | 399 | =begin original |
400 | 400 | |
401 | C<evalbytes> is only available with the C<"evalbytes"> feature (see | |
401 | C<evalbytes> is only available with with the C<"evalbytes"> feature (see | |
402 | 402 | L<feature>) or if prefixed with C<CORE::>. C<__SUB__> is only available |
403 | with the C<"current_sub"> feature or if prefixed with C<CORE::>. | |
403 | with with the C<"current_sub"> feature or if prefixed with C<CORE::>. Both | |
404 | 404 | the C<"evalbytes"> and C<"current_sub"> features are enabled automatically |
405 | 405 | with a C<use v5.16> (or higher) declaration in the current scope. |
406 | 406 | |
407 | 407 | =end original |
408 | 408 | |
409 | 409 | C<evalbytes> は C<"evalbytes"> 機能 (L<feature> 参照) が有効か C<CORE::> が |
410 | 410 | 前置されたときにのみ利用可能です。 |
411 | 411 | C<__SUB__> は C<"current_sub"> 機能が有効か C<CORE::> が前置されたときにのみ |
412 | 412 | 利用可能です。 |
413 | 413 | C<"evalbytes"> と C<"current_sub"> の両方の機能は現在のスコープで |
414 | 414 | C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。 |
415 | 415 | |
416 | 416 | =item Keywords related to scoping |
417 | 417 | |
418 | 418 | (スコープに関するキーワード) |
419 | 419 | |
420 | 420 | =for Pod::Functions =Namespace |
421 | 421 | |
422 | 422 | C<caller>, C<import>, C<local>, C<my>, C<our>, C<package>, C<state>, C<use> |
423 | 423 | |
424 | 424 | =begin original |
425 | 425 | |
426 | 426 | C<state> is available only if the C<"state"> feature is enabled or if it is |
427 | 427 | prefixed with C<CORE::>. The C<"state"> feature is enabled automatically |
428 | 428 | with a C<use v5.10> (or higher) declaration in the current scope. |
429 | 429 | |
430 | 430 | =end original |
431 | 431 | |
432 | 432 | C<state> は C<"state"> 機能が有効か C<CORE::> を前置した場合にのみ |
433 | 433 | 利用可能です。 |
434 | 434 | C<"state"> 機能は現在のスコープで C<use v5.10> (またはそれ以上) を宣言した |
435 | 435 | 場合自動的に有効になります。 |
436 | 436 | |
437 | 437 | =item Miscellaneous functions |
438 | 438 | |
439 | 439 | (さまざまな関数) |
440 | 440 | |
441 | 441 | =for Pod::Functions =Misc |
442 | 442 | |
443 | 443 | C<defined>, C<formline>, C<lock>, C<prototype>, C<reset>, C<scalar>, C<undef> |
444 | 444 | |
445 | 445 | =item Functions for processes and process groups |
446 | 446 | X<process> X<pid> X<process id> |
447 | 447 | |
448 | 448 | (プロセスとプロセスグループのための関数) |
449 | 449 | |
450 | 450 | =for Pod::Functions =Process |
451 | 451 | |
452 | 452 | C<alarm>, C<exec>, C<fork>, C<getpgrp>, C<getppid>, C<getpriority>, C<kill>, |
453 | 453 | C<pipe>, C<qx//>, C<readpipe>, C<setpgrp>, |
454 | 454 | C<setpriority>, C<sleep>, C<system>, |
455 | 455 | C<times>, C<wait>, C<waitpid> |
456 | 456 | |
457 | 457 | =item Keywords related to Perl modules |
458 | 458 | X<module> |
459 | 459 | |
460 | 460 | (Perl モジュールに関するキーワード) |
461 | 461 | |
462 | 462 | =for Pod::Functions =Modules |
463 | 463 | |
464 | 464 | C<do>, C<import>, C<no>, C<package>, C<require>, C<use> |
465 | 465 | |
466 | 466 | =item Keywords related to classes and object-orientation |
467 | 467 | X<object> X<class> X<package> |
468 | 468 | |
469 | 469 | (クラスとオブジェクト指向に関するキーワード) |
470 | 470 | |
471 | 471 | =for Pod::Functions =Objects |
472 | 472 | |
473 | 473 | C<bless>, C<dbmclose>, C<dbmopen>, C<package>, C<ref>, C<tie>, C<tied>, |
474 | 474 | C<untie>, C<use> |
475 | 475 | |
476 | 476 | =item Low-level socket functions |
477 | 477 | X<socket> X<sock> |
478 | 478 | |
479 | 479 | (低レベルソケット関数) |
480 | 480 | |
481 | 481 | =for Pod::Functions =Socket |
482 | 482 | |
483 | 483 | C<accept>, C<bind>, C<connect>, C<getpeername>, C<getsockname>, |
484 | 484 | C<getsockopt>, C<listen>, C<recv>, C<send>, C<setsockopt>, C<shutdown>, |
485 | 485 | C<socket>, C<socketpair> |
486 | 486 | |
487 | 487 | =item System V interprocess communication functions |
488 | 488 | X<IPC> X<System V> X<semaphore> X<shared memory> X<memory> X<message> |
489 | 489 | |
490 | 490 | (System V プロセス間通信関数) |
491 | 491 | |
492 | 492 | =for Pod::Functions =SysV |
493 | 493 | |
494 | 494 | C<msgctl>, C<msgget>, C<msgrcv>, C<msgsnd>, C<semctl>, C<semget>, C<semop>, |
495 | 495 | C<shmctl>, C<shmget>, C<shmread>, C<shmwrite> |
496 | 496 | |
497 | 497 | =item Fetching user and group info |
498 | 498 | X<user> X<group> X<password> X<uid> X<gid> X<passwd> X</etc/passwd> |
499 | 499 | |
500 | 500 | (ユーザーとグループの情報取得) |
501 | 501 | |
502 | 502 | =for Pod::Functions =User |
503 | 503 | |
504 | 504 | C<endgrent>, C<endhostent>, C<endnetent>, C<endpwent>, C<getgrent>, |
505 | 505 | C<getgrgid>, C<getgrnam>, C<getlogin>, C<getpwent>, C<getpwnam>, |
506 | 506 | C<getpwuid>, C<setgrent>, C<setpwent> |
507 | 507 | |
508 | 508 | =item Fetching network info |
509 | 509 | X<network> X<protocol> X<host> X<hostname> X<IP> X<address> X<service> |
510 | 510 | |
511 | 511 | (ネットワーク情報取得) |
512 | 512 | |
513 | 513 | =for Pod::Functions =Network |
514 | 514 | |
515 | 515 | C<endprotoent>, C<endservent>, C<gethostbyaddr>, C<gethostbyname>, |
516 | 516 | C<gethostent>, C<getnetbyaddr>, C<getnetbyname>, C<getnetent>, |
517 | 517 | C<getprotobyname>, C<getprotobynumber>, C<getprotoent>, |
518 | 518 | C<getservbyname>, C<getservbyport>, C<getservent>, C<sethostent>, |
519 | 519 | C<setnetent>, C<setprotoent>, C<setservent> |
520 | 520 | |
521 | 521 | =item Time-related functions |
522 | 522 | X<time> X<date> |
523 | 523 | |
524 | 524 | (時刻に関する関数) |
525 | 525 | |
526 | 526 | =for Pod::Functions =Time |
527 | 527 | |
528 | 528 | C<gmtime>, C<localtime>, C<time>, C<times> |
529 | 529 | |
530 | 530 | =item Non-function keywords |
531 | 531 | |
532 | 532 | =for Pod::Functions =!Non-functions |
533 | 533 | |
534 | 534 | C<and>, C<AUTOLOAD>, C<BEGIN>, C<CHECK>, C<cmp>, C<CORE>, C<__DATA__>, |
535 | 535 | C<default>, C<DESTROY>, C<else>, C<elseif>, C<elsif>, C<END>, C<__END__>, |
536 | 536 | C<eq>, C<for>, C<foreach>, C<ge>, C<given>, C<gt>, C<if>, C<INIT>, C<le>, |
537 | 537 | C<lt>, C<ne>, C<not>, C<or>, C<UNITCHECK>, C<unless>, C<until>, C<when>, |
538 | 538 | C<while>, C<x>, C<xor> |
539 | 539 | |
540 | 540 | =back |
541 | 541 | |
542 | 542 | =head2 Portability |
543 | 543 | X<portability> X<Unix> X<portable> |
544 | 544 | |
545 | 545 | (移植性) |
546 | 546 | |
547 | 547 | =begin original |
548 | 548 | |
549 | 549 | Perl was born in Unix and can therefore access all common Unix |
550 | 550 | system calls. In non-Unix environments, the functionality of some |
551 | 551 | Unix system calls may not be available or details of the available |
552 | 552 | functionality may differ slightly. The Perl functions affected |
553 | 553 | by this are: |
554 | 554 | |
555 | 555 | =end original |
556 | 556 | |
557 | 557 | Perl は Unix 環境で生まれたので、全ての共通する Unix システムコールに |
558 | 558 | アクセスします。 |
559 | 559 | 非 Unix 環境では、いくつかの Unix システムコールの機能が使えなかったり、 |
560 | 560 | 使える機能の詳細が多少異なったりします。 |
561 | 561 | これによる影響を受ける Perl 関数は以下のものです: |
562 | 562 | |
563 | 563 | C<-X>, C<binmode>, C<chmod>, C<chown>, C<chroot>, C<crypt>, |
564 | 564 | C<dbmclose>, C<dbmopen>, C<dump>, C<endgrent>, C<endhostent>, |
565 | 565 | C<endnetent>, C<endprotoent>, C<endpwent>, C<endservent>, C<exec>, |
566 | 566 | C<fcntl>, C<flock>, C<fork>, C<getgrent>, C<getgrgid>, C<gethostbyname>, |
567 | 567 | C<gethostent>, C<getlogin>, C<getnetbyaddr>, C<getnetbyname>, C<getnetent>, |
568 | 568 | C<getppid>, C<getpgrp>, C<getpriority>, C<getprotobynumber>, |
569 | 569 | C<getprotoent>, C<getpwent>, C<getpwnam>, C<getpwuid>, |
570 | 570 | C<getservbyport>, C<getservent>, C<getsockopt>, C<glob>, C<ioctl>, |
571 | 571 | C<kill>, C<link>, C<lstat>, C<msgctl>, C<msgget>, C<msgrcv>, |
572 | 572 | C<msgsnd>, C<open>, C<pipe>, C<readlink>, C<rename>, C<select>, C<semctl>, |
573 | 573 | C<semget>, C<semop>, C<setgrent>, C<sethostent>, C<setnetent>, |
574 | 574 | C<setpgrp>, C<setpriority>, C<setprotoent>, C<setpwent>, |
575 | 575 | C<setservent>, C<setsockopt>, C<shmctl>, C<shmget>, C<shmread>, |
576 | 576 | C<shmwrite>, C<socket>, C<socketpair>, |
577 | 577 | C<stat>, C<symlink>, C<syscall>, C<sysopen>, C<system>, |
578 | 578 | C<times>, C<truncate>, C<umask>, C<unlink>, |
579 | 579 | C<utime>, C<wait>, C<waitpid> |
580 | 580 | |
581 | 581 | =begin original |
582 | 582 | |
583 | 583 | For more information about the portability of these functions, see |
584 | 584 | L<perlport> and other available platform-specific documentation. |
585 | 585 | |
586 | 586 | =end original |
587 | 587 | |
588 | 588 | これらの関数の移植性に関するさらなる情報については、 |
589 | 589 | L<perlport> とその他のプラットホーム固有のドキュメントを参照してください。 |
590 | 590 | |
591 | 591 | =head2 Alphabetical Listing of Perl Functions |
592 | 592 | |
593 | 593 | =over |
594 | 594 | |
595 | 595 | =item -X FILEHANDLE |
596 | 596 | 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> |
597 | 597 | X<-S>X<-b>X<-c>X<-t>X<-u>X<-g>X<-k>X<-T>X<-B>X<-M>X<-A>X<-C> |
598 | 598 | |
599 | 599 | =item -X EXPR |
600 | 600 | |
601 | 601 | =item -X DIRHANDLE |
602 | 602 | |
603 | 603 | =item -X |
604 | 604 | |
605 | 605 | =for Pod::Functions a file test (-r, -x, etc) |
606 | 606 | |
607 | 607 | =begin original |
608 | 608 | |
609 | 609 | A file test, where X is one of the letters listed below. This unary |
610 | 610 | operator takes one argument, either a filename, a filehandle, or a dirhandle, |
611 | 611 | and tests the associated file to see if something is true about it. If the |
612 | 612 | argument is omitted, tests C<$_>, except for C<-t>, which tests STDIN. |
613 | Unless otherwise documented, it returns C<1> for true and C<''> for false | |
613 | Unless otherwise documented, it returns C<1> for true and C<''> for false, or | |
614 | ||
614 | the undefined value if the file doesn't exist. Despite the funny | |
615 | ||
615 | names, precedence is the same as any other named unary operator. The | |
616 | o | |
616 | operator may be any of: | |
617 | 617 | |
618 | 618 | =end original |
619 | 619 | |
620 | 620 | X は以下にあげる文字で、ファイルテストを行ないます。 |
621 | この単項演算子は、ファイル名かファイルハンドルを唯一の | |
621 | この単項演算子は、ファイル名かファイルハンドルを唯一の | |
622 | 「あること」について真であるか否かを | |
622 | 引数として動作し、「あること」について真であるか否かを | |
623 | 判定した結果を返します。 | |
623 | 624 | 引数が省略されると、C<-t> では STDIN を調べますが、その他は C<$_> を調べます。 |
624 | 特に記述されていなければ、真として C<1> を返し、偽として | |
625 | 特に記述されていなければ、真として C<1> を返し、偽として | |
625 | ファイルが存在しな | |
626 | C<''> を返し、ファイルが存在しなければ、未定義値を返します。 | |
626 | 設定します。 | |
627 | 627 | みかけは変わっていますが、優先順位は名前付き単項演算子と同じで、 |
628 | 628 | 他の単項演算子と同じく、引数を括弧で括ることもできます。 |
629 | 629 | 演算子には以下のものがあります: |
630 | 630 | |
631 | 631 | =begin original |
632 | 632 | |
633 | 633 | -r File is readable by effective uid/gid. |
634 | 634 | -w File is writable by effective uid/gid. |
635 | 635 | -x File is executable by effective uid/gid. |
636 | 636 | -o File is owned by effective uid. |
637 | 637 | |
638 | 638 | =end original |
639 | 639 | |
640 | 640 | -r ファイルが実効 uid/gid で読み出し可。 |
641 | 641 | -w ファイルが実効 uid/gid で書き込み可。 |
642 | 642 | -x ファイルが実効 uid/gid で実行可。 |
643 | 643 | -o ファイルが実効 uid の所有物。 |
644 | 644 | |
645 | 645 | =begin original |
646 | 646 | |
647 | 647 | -R File is readable by real uid/gid. |
648 | 648 | -W File is writable by real uid/gid. |
649 | 649 | -X File is executable by real uid/gid. |
650 | 650 | -O File is owned by real uid. |
651 | 651 | |
652 | 652 | =end original |
653 | 653 | |
654 | 654 | -R ファイルが実 uid/gid で読み出し可。 |
655 | 655 | -W ファイルが実 uid/gid で書き込み可。 |
656 | 656 | -X ファイルが実 uid/gid で実行可。 |
657 | 657 | -O ファイルが実 uid の所有物。 |
658 | 658 | |
659 | 659 | =begin original |
660 | 660 | |
661 | 661 | -e File exists. |
662 | 662 | -z File has zero size (is empty). |
663 | 663 | -s File has nonzero size (returns size in bytes). |
664 | 664 | |
665 | 665 | =end original |
666 | 666 | |
667 | 667 | -e ファイルが存在する。 |
668 | 668 | -z ファイルの大きさがゼロ(空)。 |
669 | 669 | -s ファイルの大きさがゼロ以外 (バイト単位での大きさを返す)。 |
670 | 670 | |
671 | 671 | =begin original |
672 | 672 | |
673 | 673 | -f File is a plain file. |
674 | 674 | -d File is a directory. |
675 | -l File is a symbolic link | |
675 | -l File is a symbolic link. | |
676 | supported by the file system). | |
677 | 676 | -p File is a named pipe (FIFO), or Filehandle is a pipe. |
678 | 677 | -S File is a socket. |
679 | 678 | -b File is a block special file. |
680 | 679 | -c File is a character special file. |
681 | 680 | -t Filehandle is opened to a tty. |
682 | 681 | |
683 | 682 | =end original |
684 | 683 | |
685 | 684 | -f ファイルは通常ファイル。 |
686 | 685 | -d ファイルはディレクトリ。 |
687 | -l ファイルはシンボリックリンク | |
686 | -l ファイルはシンボリックリンク。 | |
688 | 687 | -p ファイルは名前付きパイプ (FIFO) またはファイルハンドルはパイプ。 |
689 | 688 | -S ファイルはソケット。 |
690 | 689 | -b ファイルはブロック特殊ファイル。 |
691 | 690 | -c ファイルはキャラクタ特殊ファイル。 |
692 | 691 | -t ファイルハンドルは tty にオープンされている。 |
693 | 692 | |
694 | 693 | =begin original |
695 | 694 | |
696 | 695 | -u File has setuid bit set. |
697 | 696 | -g File has setgid bit set. |
698 | 697 | -k File has sticky bit set. |
699 | 698 | |
700 | 699 | =end original |
701 | 700 | |
702 | 701 | -u ファイルの setuid ビットがセットされている。 |
703 | 702 | -g ファイルの setgid ビットがセットされている。 |
704 | 703 | -k ファイルの sticky ビットがセットされている。 |
705 | 704 | |
706 | 705 | =begin original |
707 | 706 | |
708 | -T File is an ASCII | |
707 | -T File is an ASCII text file (heuristic guess). | |
709 | 708 | -B File is a "binary" file (opposite of -T). |
710 | 709 | |
711 | 710 | =end original |
712 | 711 | |
713 | -T ファイルは ASCII | |
712 | -T ファイルは ASCII テキストファイル (発見的に推測します)。 | |
714 | 713 | -B ファイルは「バイナリ」ファイル (-T の反対)。 |
715 | 714 | |
716 | 715 | =begin original |
717 | 716 | |
718 | 717 | -M Script start time minus file modification time, in days. |
719 | 718 | -A Same for access time. |
720 | -C Same for inode change time (Unix, may differ for other | |
719 | -C Same for inode change time (Unix, may differ for other platforms) | |
721 | platforms) | |
722 | 720 | |
723 | 721 | =end original |
724 | 722 | |
725 | 723 | -M スクリプト実行開始時刻からファイル修正時刻を引いたもの(日単位)。 |
726 | 724 | -A 同様にアクセスがあってからの日数。 |
727 | -C 同様に(Unix では) inode が変更されてからの日数(それ以外の | |
725 | -C 同様に(Unix では) inode が変更されてからの日数(それ以外のプラットフォームでは違うかもしれません)。 | |
728 | プラットフォームでは違うかもしれません)。 | |
729 | 726 | |
730 | 727 | =begin original |
731 | 728 | |
732 | 729 | Example: |
733 | 730 | |
734 | 731 | =end original |
735 | 732 | |
736 | 733 | 例: |
737 | 734 | |
738 | 735 | while (<>) { |
739 | 736 | chomp; |
740 | 737 | next unless -f $_; # ignore specials |
741 | 738 | #... |
742 | 739 | } |
743 | 740 | |
744 | 741 | =begin original |
745 | 742 | |
746 | 743 | Note that C<-s/a/b/> does not do a negated substitution. Saying |
747 | 744 | C<-exp($foo)> still works as expected, however: only single letters |
748 | 745 | following a minus are interpreted as file tests. |
749 | 746 | |
750 | 747 | =end original |
751 | 748 | |
752 | 749 | C<-s/a/b> は、置換演算 (s///) の符号反転ではありません。 |
753 | 750 | しかし、C<-exp($foo)> は期待どおりに動作します; しかし、マイナス記号の後に |
754 | 751 | 英字が 1 字続くときにのみ、ファイルテストと解釈されます。 |
755 | 752 | |
756 | 753 | =begin original |
757 | 754 | |
758 | 755 | These operators are exempt from the "looks like a function rule" described |
759 | 756 | above. That is, an opening parenthesis after the operator does not affect |
760 | 757 | how much of the following code constitutes the argument. Put the opening |
761 | 758 | parentheses before the operator to separate it from code that follows (this |
762 | 759 | applies only to operators with higher precedence than unary operators, of |
763 | 760 | course): |
764 | 761 | |
765 | 762 | =end original |
766 | 763 | |
767 | 764 | これらの演算子は上述の「関数のように見えるルール」から免除されます。 |
768 | 765 | つまり、演算子の後の開きかっこは、引き続くコードのどこまでが引数を |
769 | 766 | 構成するかに影響を与えません。 |
770 | 767 | 演算子を引き続くコードから分離するには、演算子の前に開きかっこを |
771 | 768 | 置いてください (これはもちろん、単項演算子より高い優先順位を持つ |
772 | 769 | 演算子にのみ適用されます): |
773 | 770 | |
774 | 771 | -s($file) + 1024 # probably wrong; same as -s($file + 1024) |
775 | 772 | (-s $file) + 1024 # correct |
776 | 773 | |
777 | 774 | =begin original |
778 | 775 | |
779 | 776 | The interpretation of the file permission operators C<-r>, C<-R>, |
780 | 777 | C<-w>, C<-W>, C<-x>, and C<-X> is by default based solely on the mode |
781 | 778 | of the file and the uids and gids of the user. There may be other |
782 | 779 | reasons you can't actually read, write, or execute the file: for |
783 | 780 | example network filesystem access controls, ACLs (access control lists), |
784 | 781 | read-only filesystems, and unrecognized executable formats. Note |
785 | 782 | that the use of these six specific operators to verify if some operation |
786 | 783 | is possible is usually a mistake, because it may be open to race |
787 | 784 | conditions. |
788 | 785 | |
789 | 786 | =end original |
790 | 787 | |
791 | 788 | ファイルのパーミッション演算子 C<-r>, C<-R>, C<-w>, C<-W>, C<-x>, |
792 | 789 | C<-X> の解釈は、ファイルのモードとユーザの実効/実 uid と |
793 | 790 | 実効/実 gid のみから判断されます。 |
794 | 791 | 実際にファイルが読めたり、書けたり、実行できたりするためには、 |
795 | 792 | 別の条件が必要かもしれません: |
796 | 793 | 例えば、ネットワークファイルシステムアクセスコントロール、 |
797 | 794 | ACL(アクセスコントロールリスト)、読み込み専用ファイルシステム、 |
798 | 795 | 認識できない実行ファイルフォーマット、などです。 |
799 | 796 | これらの 6 つの演算子を、特定の操作が可能かどうかを確認するために使うのは |
800 | 797 | 通常は誤りであることに注意してください; なぜなら、これらは競合条件を |
801 | 798 | 招きやすいからです。 |
802 | 799 | |
803 | 800 | =begin original |
804 | 801 | |
805 | 802 | Also note that, for the superuser on the local filesystems, the C<-r>, |
806 | 803 | C<-R>, C<-w>, and C<-W> tests always return 1, and C<-x> and C<-X> return 1 |
807 | 804 | if any execute bit is set in the mode. Scripts run by the superuser |
808 | 805 | may thus need to do a stat() to determine the actual mode of the file, |
809 | 806 | or temporarily set their effective uid to something else. |
810 | 807 | |
811 | 808 | =end original |
812 | 809 | |
813 | 810 | ローカルファイルシステムのスーパーユーザには、 |
814 | 811 | C<-r>, C<-R>, C<-w>, C<-W> に対して、常に 1 が返り、モード中の |
815 | 812 | いずれかの実行許可ビットが立っていれば、C<-x>, C<-X> にも 1 が |
816 | 813 | 返ることにも注意してください。 |
817 | 814 | スーパーユーザが実行するスクリプトでは、ファイルのモードを調べるためには、 |
818 | 815 | stat() を行なうか、実効 uid を一時的に別のものにする |
819 | 816 | 必要があるでしょう。 |
820 | 817 | |
821 | 818 | =begin original |
822 | 819 | |
823 | 820 | If you are using ACLs, there is a pragma called C<filetest> that may |
824 | 821 | produce more accurate results than the bare stat() mode bits. |
825 | 822 | When under C<use filetest 'access'> the above-mentioned filetests |
826 | 823 | test whether the permission can(not) be granted using the |
827 | 824 | access(2) family of system calls. Also note that the C<-x> and C<-X> may |
828 | 825 | under this pragma return true even if there are no execute permission |
829 | 826 | bits set (nor any extra execute permission ACLs). This strangeness is |
830 | 827 | due to the underlying system calls' definitions. Note also that, due to |
831 | 828 | the implementation of C<use filetest 'access'>, the C<_> special |
832 | 829 | filehandle won't cache the results of the file tests when this pragma is |
833 | 830 | in effect. Read the documentation for the C<filetest> pragma for more |
834 | 831 | information. |
835 | 832 | |
836 | 833 | =end original |
837 | 834 | |
838 | 835 | ACL を使っている場合は、生の stat() モードビットより |
839 | 836 | 精度の高い結果を作成する C<filetest> プラグマがあります。 |
840 | 837 | C<use filetest 'access'> とした場合、上述したファイルテストは |
841 | 838 | システムコールの access(2) ファミリーを使って権限が与えられているか |
842 | 839 | どうかをテストします。 |
843 | 840 | また、このプラグマが指定されている場合、C<-x> と C<-X> は |
844 | 841 | たとえ実行許可ビット(または追加の実行許可 ACL)がセットされていない |
845 | 842 | 場合でも真を返すことに注意してください。 |
846 | 843 | この挙動は使用するシステムコールの定義によるものです。 |
847 | 844 | C<use filetest 'access'> の実装により、このプラグマが有効の場合は |
848 | 845 | C<_> 特殊ファイルハンドルはファイルテストの結果をキャッシュしないことに |
849 | 846 | 注意してください。 |
850 | 847 | さらなる情報については C<filetest> プラグマのドキュメントを |
851 | 848 | 参照してください。 |
852 | 849 | |
853 | 850 | =begin original |
854 | 851 | |
855 | The C<-T> and C<-B> switches work as follows. The first block or so of | |
852 | The C<-T> and C<-B> switches work as follows. The first block or so of the | |
856 | ||
853 | file is examined for odd characters such as strange control codes or | |
857 | characters | |
854 | characters with the high bit set. If too many strange characters (>30%) | |
858 | ||
855 | are found, it's a C<-B> file; otherwise it's a C<-T> file. Also, any file | |
859 | c | |
856 | containing a zero byte in the first block is considered a binary file. If C<-T> | |
860 | ||
857 | or C<-B> is used on a filehandle, the current IO buffer is examined | |
861 | Also, any file containing a zero byte in the examined portion is | |
862 | considered a binary file. (If executed within the scope of a L<S<use | |
863 | locale>|perllocale> which includes C<LC_CTYPE>, odd characters are | |
864 | anything that isn't a printable nor space in the current locale.) If | |
865 | C<-T> or C<-B> is used on a filehandle, the current IO buffer is | |
866 | examined | |
867 | 858 | rather than the first block. Both C<-T> and C<-B> return true on an empty |
868 | 859 | file, or a file at EOF when testing a filehandle. Because you have to |
869 | 860 | read a file to do the C<-T> test, on most occasions you want to use a C<-f> |
870 | 861 | against the file first, as in C<next unless -f $file && -T $file>. |
871 | 862 | |
872 | 863 | =end original |
873 | 864 | |
874 | 865 | ファイルテスト C<-T> と C<-B> の動作原理は、次のようになっています。 |
875 | ファイルの最初の数ブロックを調べて、 | |
866 | ファイルの最初の数ブロックを調べて、変わった制御コードや | |
876 | 調べます。 | |
877 | もしそうなら、それは C<-T> ファイルです。 | |
878 | さもなければ、ファイルの同じ位置から、変わった制御コードや | |
879 | 867 | 上位ビットがセットされているような、通常のテキストには現れない文字を探します。 |
880 | ||
868 | そのような文字が、たくさん (>30%) 見つかるようであれば、 | |
881 | ||
869 | そのファイルは C<-B> ファイルであると判断されます; | |
882 | ||
870 | さもなければ C<-T> ファイルとなります。 | |
883 | ||
871 | 最初のブロックにヌル文字が含まれるファイルも、 | |
884 | ||
872 | バイナリファイルとみなされます。 | |
885 | おかしな文字というのは現在のロケールで表示可能でもスペースでもないものです。) | |
886 | 873 | C<-T> や C<-B> をファイルハンドルに対して用いると、 |
887 | 874 | 最初のブロックを調べる代わりに、IO バッファを調べます。 |
888 | 875 | 調べたファイルの中身が何もないときや、 |
889 | 876 | ファイルハンドルを調べたときに EOF に達して |
890 | 877 | いたときには、C<-T> も C<-B> も「真」を返します。 |
891 | 878 | C<-T> テストをするためにはファイルを読み込まないといけないので、 |
892 | 879 | たいていは C<next unless -f $file && -T $file> というような形で |
893 | 880 | まず調べたいファイルに対して C<-f> を使いたいはずです。 |
894 | 881 | |
895 | 882 | =begin original |
896 | 883 | |
897 | 884 | If any of the file tests (or either the C<stat> or C<lstat> operator) is given |
898 | 885 | the special filehandle consisting of a solitary underline, then the stat |
899 | 886 | structure of the previous file test (or stat operator) is used, saving |
900 | 887 | a system call. (This doesn't work with C<-t>, and you need to remember |
901 | 888 | that lstat() and C<-l> leave values in the stat structure for the |
902 | 889 | symbolic link, not the real file.) (Also, if the stat buffer was filled by |
903 | 890 | an C<lstat> call, C<-T> and C<-B> will reset it with the results of C<stat _>). |
904 | 891 | Example: |
905 | 892 | |
906 | 893 | =end original |
907 | 894 | |
908 | 895 | どのファイルテスト (あるいは、C<stat> や C<lstat>) 演算子にも、 |
909 | 896 | 下線だけから成る特別なファイルハンドルを与えると、 |
910 | 897 | 前回のファイルテスト (や stat) の stat 構造体が使われ、 |
911 | 898 | システムコールを省きます。 |
912 | 899 | (C<-t> には使えませんし、lstat() や C<-l> は実ファイルではなく、 |
913 | 900 | シンボリックリンクの情報を stat 構造体に残すことを |
914 | 901 | 覚えておく必要があります。) |
915 | 902 | (また、stat バッファが C<lstat> 呼び出しで埋まった場合、 |
916 | 903 | C<-T> と C<-B> の結果は C<stat _> の結果でリセットされます。 |
917 | 904 | 例: |
918 | 905 | |
919 | 906 | print "Can do.\n" if -r $a || -w _ || -x _; |
920 | 907 | |
921 | 908 | stat($filename); |
922 | 909 | print "Readable\n" if -r _; |
923 | 910 | print "Writable\n" if -w _; |
924 | 911 | print "Executable\n" if -x _; |
925 | 912 | print "Setuid\n" if -u _; |
926 | 913 | print "Setgid\n" if -g _; |
927 | 914 | print "Sticky\n" if -k _; |
928 | 915 | print "Text\n" if -T _; |
929 | 916 | print "Binary\n" if -B _; |
930 | 917 | |
931 | 918 | =begin original |
932 | 919 | |
933 | As of Perl 5. | |
920 | As of Perl 5.9.1, as a form of purely syntactic sugar, you can stack file | |
934 | 921 | test operators, in a way that C<-f -w -x $file> is equivalent to |
935 | C<-x $file && -w _ && -f _>. (This is only fancy | |
922 | C<-x $file && -w _ && -f _>. (This is only fancy fancy: if you use | |
936 | 923 | the return value of C<-f $file> as an argument to another filetest |
937 | 924 | operator, no special magic will happen.) |
938 | 925 | |
939 | 926 | =end original |
940 | 927 | |
941 | Perl 5. | |
928 | Perl 5.9.1 から、純粋にシンタックスシュガーとして、ファイルテスト演算子を | |
942 | 929 | スタックさせることができるので、C<-f -w -x $file> は |
943 | 930 | C<-x $file && -w _ && -f _> と等価です。 |
944 | 931 | (これは文法上だけの話です; もし C<-f $file> の返り値を他のファイルテスト |
945 | 932 | 演算子の引数として使う場合は、何の特別なことも起きません。) |
946 | 933 | |
947 | 934 | =begin original |
948 | 935 | |
949 | 936 | Portability issues: L<perlport/-X>. |
950 | 937 | |
951 | 938 | =end original |
952 | 939 | |
953 | 940 | 移植性の問題: L<perlport/-X>。 |
954 | 941 | |
955 | 942 | =begin original |
956 | 943 | |
957 | 944 | To avoid confusing would-be users of your code with mysterious |
958 | 945 | syntax errors, put something like this at the top of your script: |
959 | 946 | |
960 | 947 | =end original |
961 | 948 | |
962 | 949 | あなたのコードのユーザーが不思議な文法エラーで混乱することを |
963 | 950 | 避けるために、スクリプトの先頭に以下のようなことを書いてください: |
964 | 951 | |
965 | 952 | use 5.010; # so filetest ops can stack |
966 | 953 | |
967 | 954 | =item abs VALUE |
968 | 955 | X<abs> X<absolute> |
969 | 956 | |
970 | 957 | =item abs |
971 | 958 | |
972 | 959 | =for Pod::Functions absolute value function |
973 | 960 | |
974 | 961 | =begin original |
975 | 962 | |
976 | 963 | Returns the absolute value of its argument. |
977 | 964 | If VALUE is omitted, uses C<$_>. |
978 | 965 | |
979 | 966 | =end original |
980 | 967 | |
981 | 968 | 引数の絶対値を返します。 |
982 | 969 | VALUE が省略された場合は、C<$_> を使います。 |
983 | 970 | |
984 | 971 | =item accept NEWSOCKET,GENERICSOCKET |
985 | 972 | X<accept> |
986 | 973 | |
987 | 974 | =for Pod::Functions accept an incoming socket connect |
988 | 975 | |
989 | 976 | =begin original |
990 | 977 | |
991 | 978 | Accepts an incoming socket connect, just as accept(2) |
992 | 979 | does. Returns the packed address if it succeeded, false otherwise. |
993 | 980 | See the example in L<perlipc/"Sockets: Client/Server Communication">. |
994 | 981 | |
995 | 982 | =end original |
996 | 983 | |
997 | 984 | accept(2) システムコールと同様に、着信するソケットの接続を受け付けます。 |
998 | 985 | 成功時にはパックされたアドレスを返し、失敗すれば偽を返します。 |
999 | 986 | L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。 |
1000 | 987 | |
1001 | 988 | =begin original |
1002 | 989 | |
1003 | 990 | On systems that support a close-on-exec flag on files, the flag will |
1004 | 991 | be set for the newly opened file descriptor, as determined by the |
1005 | 992 | value of $^F. See L<perlvar/$^F>. |
1006 | 993 | |
1007 | 994 | =end original |
1008 | 995 | |
1009 | 996 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
1010 | 997 | フラグは $^F の値で決定される、新しくオープンされたファイル記述子に対して |
1011 | 998 | セットされます。 |
1012 | 999 | L<perlvar/$^F> を参照してください。 |
1013 | 1000 | |
1014 | 1001 | =item alarm SECONDS |
1015 | 1002 | X<alarm> |
1016 | 1003 | X<SIGALRM> |
1017 | 1004 | X<timer> |
1018 | 1005 | |
1019 | 1006 | =item alarm |
1020 | 1007 | |
1021 | 1008 | =for Pod::Functions schedule a SIGALRM |
1022 | 1009 | |
1023 | 1010 | =begin original |
1024 | 1011 | |
1025 | 1012 | Arranges to have a SIGALRM delivered to this process after the |
1026 | 1013 | specified number of wallclock seconds has elapsed. If SECONDS is not |
1027 | 1014 | specified, the value stored in C<$_> is used. (On some machines, |
1028 | 1015 | unfortunately, the elapsed time may be up to one second less or more |
1029 | 1016 | than you specified because of how seconds are counted, and process |
1030 | 1017 | scheduling may delay the delivery of the signal even further.) |
1031 | 1018 | |
1032 | 1019 | =end original |
1033 | 1020 | |
1034 | 1021 | 指定した壁時計秒数が経過した後に、自プロセスに SIGALRM が |
1035 | 1022 | 送られてくるようにします。 |
1036 | 1023 | SECONDS が指定されていない場合は、C<$_> に格納されている値を使います。 |
1037 | 1024 | (マシンによっては、秒の数え方が異なるため、指定した秒数よりも最大で |
1038 | 1025 | 1 秒ずれます。) |
1039 | 1026 | |
1040 | 1027 | =begin original |
1041 | 1028 | |
1042 | 1029 | Only one timer may be counting at once. Each call disables the |
1043 | 1030 | previous timer, and an argument of C<0> may be supplied to cancel the |
1044 | 1031 | previous timer without starting a new one. The returned value is the |
1045 | 1032 | amount of time remaining on the previous timer. |
1046 | 1033 | |
1047 | 1034 | =end original |
1048 | 1035 | |
1049 | 1036 | 一度には一つのタイマだけが設定可能です。 |
1050 | 1037 | 呼び出しを行なう度に、以前のタイマを無効にしますし、 |
1051 | 1038 | 新しくタイマを起動しないで以前のタイマをキャンセルするために |
1052 | 1039 | 引数に C<0> を指定して呼び出すことができます。 |
1053 | 1040 | 以前のタイマの残り時間が、返り値となります。 |
1054 | 1041 | |
1055 | 1042 | =begin original |
1056 | 1043 | |
1057 | 1044 | For delays of finer granularity than one second, the Time::HiRes module |
1058 | 1045 | (from CPAN, and starting from Perl 5.8 part of the standard |
1059 | 1046 | distribution) provides ualarm(). You may also use Perl's four-argument |
1060 | 1047 | version of select() leaving the first three arguments undefined, or you |
1061 | 1048 | might be able to use the C<syscall> interface to access setitimer(2) if |
1062 | 1049 | your system supports it. See L<perlfaq8> for details. |
1063 | 1050 | |
1064 | 1051 | =end original |
1065 | 1052 | |
1066 | 1053 | 1 秒より精度の高いスリープを行なうには、 |
1067 | 1054 | Time::HiRes モジュール(CPAN から、また Perl 5.8 からは |
1068 | 1055 | 標準配布されています) が ualarm() を提供します。 |
1069 | 1056 | Perl の 4 引数版 select() を最初の 3 引数を未定義にして使うか、 |
1070 | 1057 | setitimer(2) をサポートしているシステムでは、Perl の |
1071 | 1058 | C<syscall> インタフェースを使ってアクセスすることもできます。 |
1072 | 1059 | 詳しくは L<perlfaq8> を参照してください。 |
1073 | 1060 | |
1074 | 1061 | =begin original |
1075 | 1062 | |
1076 | 1063 | It is usually a mistake to intermix C<alarm> and C<sleep> calls, because |
1077 | 1064 | C<sleep> may be internally implemented on your system with C<alarm>. |
1078 | 1065 | |
1079 | 1066 | =end original |
1080 | 1067 | |
1081 | 1068 | C<alarm> と C<sleep> を混ぜて使うのは普通は間違いです; なぜなら、 |
1082 | 1069 | C<sleep> は内部的に C<alarm> を使って内部的に実装されているかも |
1083 | 1070 | しれないからです。 |
1084 | 1071 | |
1085 | 1072 | =begin original |
1086 | 1073 | |
1087 | 1074 | If you want to use C<alarm> to time out a system call you need to use an |
1088 | 1075 | C<eval>/C<die> pair. You can't rely on the alarm causing the system call to |
1089 | 1076 | fail with C<$!> set to C<EINTR> because Perl sets up signal handlers to |
1090 | 1077 | restart system calls on some systems. Using C<eval>/C<die> always works, |
1091 | 1078 | modulo the caveats given in L<perlipc/"Signals">. |
1092 | 1079 | |
1093 | 1080 | =end original |
1094 | 1081 | |
1095 | 1082 | C<alarm> をシステムコールの時間切れのために使いたいなら、 |
1096 | 1083 | C<eval>/C<die> のペアで使う必要があります。 |
1097 | 1084 | システムコールが失敗したときに C<$!> に C<EINTR> がセットされることに |
1098 | 1085 | 頼ってはいけません; なぜならシステムによっては Perl は |
1099 | 1086 | システムコールを再開するためにシグナルハンドラを設定するからです。 |
1100 | 1087 | C<eval>/C<die> は常にうまく動きます; 注意点については |
1101 | 1088 | L<perlipc/"Signals"> を参照してください。 |
1102 | 1089 | |
1103 | 1090 | eval { |
1104 | 1091 | local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required |
1105 | 1092 | alarm $timeout; |
1106 | 1093 | $nread = sysread SOCKET, $buffer, $size; |
1107 | 1094 | alarm 0; |
1108 | 1095 | }; |
1109 | 1096 | if ($@) { |
1110 | 1097 | die unless $@ eq "alarm\n"; # propagate unexpected errors |
1111 | 1098 | # timed out |
1112 | 1099 | } |
1113 | 1100 | else { |
1114 | 1101 | # didn't |
1115 | 1102 | } |
1116 | 1103 | |
1117 | 1104 | =begin original |
1118 | 1105 | |
1119 | 1106 | For more information see L<perlipc>. |
1120 | 1107 | |
1121 | 1108 | =end original |
1122 | 1109 | |
1123 | 1110 | さらなる情報については L<perlipc> を参照してください。 |
1124 | 1111 | |
1125 | 1112 | =begin original |
1126 | 1113 | |
1127 | 1114 | Portability issues: L<perlport/alarm>. |
1128 | 1115 | |
1129 | 1116 | =end original |
1130 | 1117 | |
1131 | 1118 | 移植性の問題: L<perlport/alarm>。 |
1132 | 1119 | |
1133 | 1120 | =item atan2 Y,X |
1134 | 1121 | X<atan2> X<arctangent> X<tan> X<tangent> |
1135 | 1122 | |
1136 | 1123 | =for Pod::Functions arctangent of Y/X in the range -PI to PI |
1137 | 1124 | |
1138 | 1125 | =begin original |
1139 | 1126 | |
1140 | 1127 | Returns the arctangent of Y/X in the range -PI to PI. |
1141 | 1128 | |
1142 | 1129 | =end original |
1143 | 1130 | |
1144 | 1131 | -πからπの範囲で Y/X の逆正接を返します。 |
1145 | 1132 | |
1146 | 1133 | =begin original |
1147 | 1134 | |
1148 | 1135 | For the tangent operation, you may use the C<Math::Trig::tan> |
1149 | 1136 | function, or use the familiar relation: |
1150 | 1137 | |
1151 | 1138 | =end original |
1152 | 1139 | |
1153 | 1140 | 正接を求めたいときは、C<Math::Trig::tan> を使うか、 |
1154 | 1141 | 以下のよく知られた関係を使ってください。 |
1155 | 1142 | |
1156 | 1143 | sub tan { sin($_[0]) / cos($_[0]) } |
1157 | 1144 | |
1158 | 1145 | =begin original |
1159 | 1146 | |
1160 | 1147 | The return value for C<atan2(0,0)> is implementation-defined; consult |
1161 | 1148 | your atan2(3) manpage for more information. |
1162 | 1149 | |
1163 | 1150 | =end original |
1164 | 1151 | |
1165 | 1152 | C<atan2(0,0)> の返り値は実装依存です; さらなる情報については |
1166 | 1153 | atan2(3) man ページを参照してください。 |
1167 | 1154 | |
1168 | 1155 | =begin original |
1169 | 1156 | |
1170 | 1157 | Portability issues: L<perlport/atan2>. |
1171 | 1158 | |
1172 | 1159 | =end original |
1173 | 1160 | |
1174 | 1161 | 移植性の問題: L<perlport/atan2>。 |
1175 | 1162 | |
1176 | 1163 | =item bind SOCKET,NAME |
1177 | 1164 | X<bind> |
1178 | 1165 | |
1179 | 1166 | =for Pod::Functions binds an address to a socket |
1180 | 1167 | |
1181 | 1168 | =begin original |
1182 | 1169 | |
1183 | 1170 | Binds a network address to a socket, just as bind(2) |
1184 | 1171 | does. Returns true if it succeeded, false otherwise. NAME should be a |
1185 | 1172 | packed address of the appropriate type for the socket. See the examples in |
1186 | 1173 | L<perlipc/"Sockets: Client/Server Communication">. |
1187 | 1174 | |
1188 | 1175 | =end original |
1189 | 1176 | |
1190 | 1177 | bind(2) システムコールと同様に、ネットワークアドレスをソケットに結び付けます。 |
1191 | 1178 | 成功時には真を、さもなければ偽を返します。 |
1192 | 1179 | NAME は、ソケットに対する、適切な型のパックされた |
1193 | 1180 | アドレスでなければなりません。 |
1194 | 1181 | L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。 |
1195 | 1182 | |
1196 | 1183 | =item binmode FILEHANDLE, LAYER |
1197 | 1184 | X<binmode> X<binary> X<text> X<DOS> X<Windows> |
1198 | 1185 | |
1199 | 1186 | =item binmode FILEHANDLE |
1200 | 1187 | |
1201 | 1188 | =for Pod::Functions prepare binary files for I/O |
1202 | 1189 | |
1203 | 1190 | =begin original |
1204 | 1191 | |
1205 | 1192 | Arranges for FILEHANDLE to be read or written in "binary" or "text" |
1206 | 1193 | mode on systems where the run-time libraries distinguish between |
1207 | 1194 | binary and text files. If FILEHANDLE is an expression, the value is |
1208 | 1195 | taken as the name of the filehandle. Returns true on success, |
1209 | 1196 | otherwise it returns C<undef> and sets C<$!> (errno). |
1210 | 1197 | |
1211 | 1198 | =end original |
1212 | 1199 | |
1213 | 1200 | バイナリファイルとテキストファイルを区別する OS において、 |
1214 | 1201 | FILEHANDLE を「バイナリ」または「テキスト」で読み書きするように |
1215 | 1202 | 指定します。 |
1216 | 1203 | FILEHANDLE が式である場合には、その式の値がファイルハンドルの |
1217 | 1204 | 名前として使われます。 |
1218 | 1205 | 成功時には真を返し、失敗時には C<undef> を返して C<$!> (errno) を設定します。 |
1219 | 1206 | |
1220 | 1207 | =begin original |
1221 | 1208 | |
1222 | 1209 | On some systems (in general, DOS- and Windows-based systems) binmode() |
1223 | 1210 | is necessary when you're not working with a text file. For the sake |
1224 | 1211 | of portability it is a good idea always to use it when appropriate, |
1225 | 1212 | and never to use it when it isn't appropriate. Also, people can |
1226 | 1213 | set their I/O to be by default UTF8-encoded Unicode, not bytes. |
1227 | 1214 | |
1228 | 1215 | =end original |
1229 | 1216 | |
1230 | 1217 | テキストファイルでないものを扱う場合に binmode() が必要な |
1231 | 1218 | システムもあります(一般的には DOS と Windows ベースのシステムです)。 |
1232 | 1219 | 移植性のために、適切なときには常にこれを使い、適切でないときには |
1233 | 1220 | 決して使わないというのは良い考えです。 |
1234 | 1221 | また、デフォルトとして I/O を bytes ではなく UTF-8 エンコードされた |
1235 | 1222 | Unicode にセットすることも出来ます。 |
1236 | 1223 | |
1237 | 1224 | =begin original |
1238 | 1225 | |
1239 | 1226 | In other words: regardless of platform, use binmode() on binary data, |
1240 | 1227 | like images, for example. |
1241 | 1228 | |
1242 | 1229 | =end original |
1243 | 1230 | |
1244 | 1231 | 言い換えると: プラットフォームに関わらず、 |
1245 | 1232 | 例えばイメージのようなバイナリファイルに対しては binmode() を |
1246 | 1233 | 使ってください。 |
1247 | 1234 | |
1248 | 1235 | =begin original |
1249 | 1236 | |
1250 | 1237 | If LAYER is present it is a single string, but may contain multiple |
1251 | 1238 | directives. The directives alter the behaviour of the filehandle. |
1252 | 1239 | When LAYER is present, using binmode on a text file makes sense. |
1253 | 1240 | |
1254 | 1241 | =end original |
1255 | 1242 | |
1256 | 1243 | LAYER が存在すると、それは単一の文字列ですが、複数の指示子を |
1257 | 1244 | 含むことができます。 |
1258 | 1245 | 指示子はファイルハンドルの振る舞いを変更します。 |
1259 | 1246 | LAYER が存在すると、テキストファイルでの binmode が意味を持ちます。 |
1260 | 1247 | |
1261 | 1248 | =begin original |
1262 | 1249 | |
1263 | 1250 | If LAYER is omitted or specified as C<:raw> the filehandle is made |
1264 | 1251 | suitable for passing binary data. This includes turning off possible CRLF |
1265 | 1252 | translation and marking it as bytes (as opposed to Unicode characters). |
1266 | 1253 | Note that, despite what may be implied in I<"Programming Perl"> (the |
1267 | 1254 | Camel, 3rd edition) or elsewhere, C<:raw> is I<not> simply the inverse of C<:crlf>. |
1268 | 1255 | Other layers that would affect the binary nature of the stream are |
1269 | 1256 | I<also> disabled. See L<PerlIO>, L<perlrun>, and the discussion about the |
1270 | 1257 | PERLIO environment variable. |
1271 | 1258 | |
1272 | 1259 | =end original |
1273 | 1260 | |
1274 | 1261 | LAYER が省略されたり、C<:raw> が指定されると、ファイルハンドルはバイナリ |
1275 | 1262 | データの通過に適するように設定されます。 |
1276 | 1263 | これには CRLF 変換をオフにしたり、それぞれを(Unicode 文字ではなく) |
1277 | 1264 | バイトであるとマークしたりすることを含みます。 |
1278 | 1265 | I<"プログラミング Perl">(ラクダ本第三版) やその他で暗示されているにも関わらず、 |
1279 | 1266 | C<:raw> は単なる C<:crlf> の I<逆ではありません>。 |
1280 | 1267 | ストリームのバイナリとしての性質に影響を与える |
1281 | 1268 | I<その他の層も無効にされます>。 |
1282 | 1269 | L<PerlIO>, L<perlrun> およびPERLIO 環境変数に関する議論を参照してください。 |
1283 | 1270 | |
1284 | 1271 | =begin original |
1285 | 1272 | |
1286 | 1273 | The C<:bytes>, C<:crlf>, C<:utf8>, and any other directives of the |
1287 | 1274 | form C<:...>, are called I/O I<layers>. The C<open> pragma can be used to |
1288 | 1275 | establish default I/O layers. See L<open>. |
1289 | 1276 | |
1290 | 1277 | =end original |
1291 | 1278 | |
1292 | 1279 | C<:bytes>, C<:crlf>, and C<:utf8>, 及びその他の C<:...> 形式の指示子は |
1293 | 1280 | I/O I<層> が呼び出されます。 |
1294 | 1281 | C<open> プラグマはデフォルト I/O 層を指定するために使われます。 |
1295 | 1282 | L<open> を参照してください。 |
1296 | 1283 | |
1297 | 1284 | =begin original |
1298 | 1285 | |
1299 | 1286 | I<The LAYER parameter of the binmode() function is described as "DISCIPLINE" |
1300 | 1287 | in "Programming Perl, 3rd Edition". However, since the publishing of this |
1301 | 1288 | book, by many known as "Camel III", the consensus of the naming of this |
1302 | 1289 | functionality has moved from "discipline" to "layer". All documentation |
1303 | 1290 | of this version of Perl therefore refers to "layers" rather than to |
1304 | 1291 | "disciplines". Now back to the regularly scheduled documentation...> |
1305 | 1292 | |
1306 | 1293 | =end original |
1307 | 1294 | |
1308 | 1295 | I<binmode() 関数の LAYER パラメータは 「プログラミングPerl 第3版」では |
1309 | 1296 | 「ディシプリン(DISCIPLINE)」と表現されていました。 |
1310 | 1297 | しかし、「ラクダ本第3版」として知られているこの本の出版後、この機能の名前は |
1311 | 1298 | 「ディシプリン」から「層」に変更することで合意されました。 |
1312 | 1299 | 従って、このバージョンの Perl の全ての文書では「ディシプリン」ではなく |
1313 | 1300 | 「層」と記述されています。では通常の解説に戻ります…> |
1314 | 1301 | |
1315 | 1302 | =begin original |
1316 | 1303 | |
1317 | 1304 | To mark FILEHANDLE as UTF-8, use C<:utf8> or C<:encoding(UTF-8)>. |
1318 | 1305 | C<:utf8> just marks the data as UTF-8 without further checking, |
1319 | 1306 | while C<:encoding(UTF-8)> checks the data for actually being valid |
1320 | 1307 | UTF-8. More details can be found in L<PerlIO::encoding>. |
1321 | 1308 | |
1322 | 1309 | =end original |
1323 | 1310 | |
1324 | 1311 | FILEHANDLE が UTF-8 であるというマークをつけるには、C<:utf8> か |
1325 | 1312 | C<:encoding(UTF-8)> を使ってください。 |
1326 | 1313 | C<:utf8> は、さらなるチェックなしにデータが UTF-8 としてマークしますが、 |
1327 | 1314 | C<:encoding(UTF-8)> はデータが実際に有効な UTF-8 かどうかをチェックします。 |
1328 | 1315 | さらなる詳細は L<PerlIO::encoding> にあります。 |
1329 | 1316 | |
1330 | 1317 | =begin original |
1331 | 1318 | |
1332 | 1319 | In general, binmode() should be called after open() but before any I/O |
1333 | 1320 | is done on the filehandle. Calling binmode() normally flushes any |
1334 | 1321 | pending buffered output data (and perhaps pending input data) on the |
1335 | 1322 | handle. An exception to this is the C<:encoding> layer that |
1336 | 1323 | changes the default character encoding of the handle; see L</open>. |
1337 | 1324 | The C<:encoding> layer sometimes needs to be called in |
1338 | 1325 | mid-stream, and it doesn't flush the stream. The C<:encoding> |
1339 | 1326 | also implicitly pushes on top of itself the C<:utf8> layer because |
1340 | 1327 | internally Perl operates on UTF8-encoded Unicode characters. |
1341 | 1328 | |
1342 | 1329 | =end original |
1343 | 1330 | |
1344 | 1331 | 一般的に binmode() は open() を呼び出した後、このファイルハンドルに対する |
1345 | 1332 | I/O 操作をする前に呼び出すべきです。 |
1346 | 1333 | binmode() を呼び出すと、普通はこのファイルハンドルに対して |
1347 | 1334 | バッファリングされている全ての出力データ |
1348 | 1335 | (およびおそらくは入力データ)をフラッシュします。 |
1349 | 1336 | 例外は、このハンドルに対するデフォルト文字エンコーディングを変更する |
1350 | 1337 | C<:encoding> 層です; L</open> を参照してください。 |
1351 | 1338 | C<:encoding> 層はストリームの途中で呼び出す必要があることがあり、 |
1352 | 1339 | それによってストリームはフラッシュされません。 |
1353 | 1340 | Perl は内部で UTF-8 エンコードされた Unicode 文字を操作しているので、 |
1354 | 1341 | C<:encoding> は暗黙のうちに自身を C<:utf8> 層の上に押し上げます。 |
1355 | 1342 | |
1356 | 1343 | =begin original |
1357 | 1344 | |
1358 | 1345 | The operating system, device drivers, C libraries, and Perl run-time |
1359 | 1346 | system all conspire to let the programmer treat a single |
1360 | 1347 | character (C<\n>) as the line terminator, irrespective of external |
1361 | 1348 | representation. On many operating systems, the native text file |
1362 | 1349 | representation matches the internal representation, but on some |
1363 | 1350 | platforms the external representation of C<\n> is made up of more than |
1364 | 1351 | one character. |
1365 | 1352 | |
1366 | 1353 | =end original |
1367 | 1354 | |
1368 | 1355 | オペレーティングシステム、デバイスドライバ、C ライブラリ、 |
1369 | 1356 | Perl ランタイムシステムは全て、プログラマが外部表現に関わらず |
1370 | 1357 | 1 文字 (C<\n>) を行終端として扱えるように協調作業します。 |
1371 | 1358 | 多くのオペレーティングシステムでは、ネイティブテキストファイル表現は |
1372 | 1359 | 内部表現と同じですが、C<\n> の外部表現が複数文字になる |
1373 | 1360 | プラットフォームもあります。 |
1374 | 1361 | |
1375 | 1362 | =begin original |
1376 | 1363 | |
1377 | 1364 | All variants of Unix, Mac OS (old and new), and Stream_LF files on VMS use |
1378 | 1365 | a single character to end each line in the external representation of text |
1379 | 1366 | (even though that single character is CARRIAGE RETURN on old, pre-Darwin |
1380 | 1367 | flavors of Mac OS, and is LINE FEED on Unix and most VMS files). In other |
1381 | 1368 | systems like OS/2, DOS, and the various flavors of MS-Windows, your program |
1382 | 1369 | sees a C<\n> as a simple C<\cJ>, but what's stored in text files are the |
1383 | 1370 | two characters C<\cM\cJ>. That means that if you don't use binmode() on |
1384 | 1371 | these systems, C<\cM\cJ> sequences on disk will be converted to C<\n> on |
1385 | 1372 | input, and any C<\n> in your program will be converted back to C<\cM\cJ> on |
1386 | 1373 | output. This is what you want for text files, but it can be disastrous for |
1387 | 1374 | binary files. |
1388 | 1375 | |
1389 | 1376 | =end original |
1390 | 1377 | |
1391 | 1378 | 全ての Unix 系、(新旧の)Mac OS、VMS の Stream_LF ファイルは |
1392 | 1379 | テキストの外部表現として各行の末尾に一つの文字を |
1393 | 1380 | 使っています(しかしその文字は古い Darwin 以前の Mac OS では復帰で、 |
1394 | 1381 | Unix とほとんどのVMS のファイルでは改行です)。 |
1395 | 1382 | VMS, MS-DOS, MS-Windows 系といったその他のシステムでは、 |
1396 | 1383 | プログラムからは C<\n> は単純に C<\cJ> に見えますが、 |
1397 | 1384 | テキストファイルとして保存される場合は C<\cM\cJ> の 2 文字になります。 |
1398 | 1385 | つまり、もしこれらのシステムで binmode() を使わないと、 |
1399 | 1386 | ディスク上の C<\cM\cJ> という並びは入力時に C<\n> に変換され、 |
1400 | 1387 | プログラムが出力した全ての C<\n> は C<\cM\cJ> に逆変換されます。 |
1401 | 1388 | これはテキストファイルの場合は思い通りの結果でしょうが、 |
1402 | 1389 | バイナリファイルの場合は悲惨です。 |
1403 | 1390 | |
1404 | 1391 | =begin original |
1405 | 1392 | |
1406 | 1393 | Another consequence of using binmode() (on some systems) is that |
1407 | 1394 | special end-of-file markers will be seen as part of the data stream. |
1408 | 1395 | For systems from the Microsoft family this means that, if your binary |
1409 | 1396 | data contain C<\cZ>, the I/O subsystem will regard it as the end of |
1410 | 1397 | the file, unless you use binmode(). |
1411 | 1398 | |
1412 | 1399 | =end original |
1413 | 1400 | |
1414 | 1401 | binmode() を(いくつかのシステムで)使うことによるその他の作用としては、 |
1415 | 1402 | 特別なファイル終端マーカーがデータストリームの一部として |
1416 | 1403 | 見られることです。 |
1417 | 1404 | Microsoft ファミリーのシステムでは、binmode() を使っていないと |
1418 | 1405 | もしバイナリデータに C<\cZ> が含まれていたときに、I/O サブシステムが |
1419 | 1406 | これをファイル終端とみなすことを意味します。 |
1420 | 1407 | |
1421 | 1408 | =begin original |
1422 | 1409 | |
1423 | 1410 | binmode() is important not only for readline() and print() operations, |
1424 | 1411 | but also when using read(), seek(), sysread(), syswrite() and tell() |
1425 | 1412 | (see L<perlport> for more details). See the C<$/> and C<$\> variables |
1426 | 1413 | in L<perlvar> for how to manually set your input and output |
1427 | 1414 | line-termination sequences. |
1428 | 1415 | |
1429 | 1416 | =end original |
1430 | 1417 | |
1431 | 1418 | binmode() は readline() と print() 操作にだけではなく、 |
1432 | 1419 | read(), seek(), sysread(), syswrite(), tell() を使うときにも重要です |
1433 | 1420 | (詳細は L<perlport> を参照してください)。 |
1434 | 1421 | 入出力の行端末シーケンスを手動でセットする方法については |
1435 | 1422 | L<perlvar> の C<$/> 変数と C<$\> 変数を参照してください。 |
1436 | 1423 | |
1437 | 1424 | =begin original |
1438 | 1425 | |
1439 | 1426 | Portability issues: L<perlport/binmode>. |
1440 | 1427 | |
1441 | 1428 | =end original |
1442 | 1429 | |
1443 | 1430 | 移植性の問題: L<perlport/binmode>。 |
1444 | 1431 | |
1445 | 1432 | =item bless REF,CLASSNAME |
1446 | 1433 | X<bless> |
1447 | 1434 | |
1448 | 1435 | =item bless REF |
1449 | 1436 | |
1450 | 1437 | =for Pod::Functions create an object |
1451 | 1438 | |
1452 | 1439 | =begin original |
1453 | 1440 | |
1454 | 1441 | This function tells the thingy referenced by REF that it is now an object |
1455 | 1442 | in the CLASSNAME package. If CLASSNAME is omitted, the current package |
1456 | 1443 | is used. Because a C<bless> is often the last thing in a constructor, |
1457 | 1444 | it returns the reference for convenience. Always use the two-argument |
1458 | 1445 | version if a derived class might inherit the function doing the blessing. |
1459 | See | |
1446 | SeeL<perlobj> for more about the blessing (and blessings) of objects. | |
1460 | 1447 | |
1461 | 1448 | =end original |
1462 | 1449 | |
1463 | 1450 | この関数は、REF で渡された オブジェクトに対し、 |
1464 | 1451 | CLASSNAME 内のオブジェクトとなったことを伝えます。 |
1465 | 1452 | CLASSNAME が省略された場合には、その時点のパッケージとなります。 |
1466 | 1453 | C<bless> は通常、コンストラクタの最後に置かれますので、 |
1467 | 1454 | 簡便のためにそのリファレンスを返します。 |
1468 | 1455 | 派生クラスが bless される関数を継承する場合は、 |
1469 | 1456 | 常に 2 引数版を使ってください。 |
1470 | 1457 | オブジェクトの bless (や再 bless) について、詳しくは と L<perlobj> を |
1471 | 1458 | 参照してください。 |
1472 | 1459 | |
1473 | 1460 | =begin original |
1474 | 1461 | |
1475 | 1462 | Consider always blessing objects in CLASSNAMEs that are mixed case. |
1476 | 1463 | Namespaces with all lowercase names are considered reserved for |
1477 | 1464 | Perl pragmata. Builtin types have all uppercase names. To prevent |
1478 | 1465 | confusion, you may wish to avoid such package names as well. Make sure |
1479 | 1466 | that CLASSNAME is a true value. |
1480 | 1467 | |
1481 | 1468 | =end original |
1482 | 1469 | |
1483 | 1470 | 大文字小文字が混じっている CLASSNAME のオブジェクトは常に bless することを |
1484 | 1471 | 考慮してください。 |
1485 | 1472 | 全て小文字の名前を持つ名前空間は Perl プラグマのために予約されています。 |
1486 | 1473 | 組み込みの型は全て大文字の名前を持ちます。 |
1487 | 1474 | 混乱を避けるために、 |
1488 | 1475 | パッケージ名としてこのような名前は避けるべきです。 |
1489 | 1476 | CLASSNAME は真の値を持つようにしてください。 |
1490 | 1477 | |
1491 | 1478 | =begin original |
1492 | 1479 | |
1493 | 1480 | See L<perlmod/"Perl Modules">. |
1494 | 1481 | |
1495 | 1482 | =end original |
1496 | 1483 | |
1497 | 1484 | L<perlmod/"Perl Modules"> を参照してください。 |
1498 | 1485 | |
1499 | 1486 | =item break |
1500 | 1487 | |
1501 | 1488 | =for Pod::Functions +switch break out of a C<given> block |
1502 | 1489 | |
1503 | 1490 | =begin original |
1504 | 1491 | |
1505 | 1492 | Break out of a C<given()> block. |
1506 | 1493 | |
1507 | 1494 | =end original |
1508 | 1495 | |
1509 | 1496 | C<given()> ブロックから脱出します。 |
1510 | 1497 | |
1511 | 1498 | =begin original |
1512 | 1499 | |
1513 | This keyword is enabled by the C<"switch"> feature | |
1500 | This keyword is enabled by the C<"switch"> feature: see | |
1514 | more information | |
1501 | L<feature> for more information. You can also access it by | |
1515 | with C<CORE::>. Alternat | |
1502 | prefixing it with C<CORE::>. Alternately, include a C<use | |
1516 | current scope. | |
1503 | v5.10> or later to the current scope. | |
1517 | 1504 | |
1518 | 1505 | =end original |
1519 | 1506 | |
1520 | このキーワードは C<"switch"> 機能によって有効になります | |
1507 | このキーワードは C<"switch"> 機能によって有効になります: | |
1521 | 1508 | さらなる情報については L<feature> を参照してください。 |
1522 | 1509 | C<CORE::> を前置することによってもアクセスできます。 |
1523 | 1510 | または、現在のスコープに C<use v5.10> 以降を含めてください。 |
1524 | 1511 | |
1525 | 1512 | =item caller EXPR |
1526 | 1513 | X<caller> X<call stack> X<stack> X<stack trace> |
1527 | 1514 | |
1528 | 1515 | =item caller |
1529 | 1516 | |
1530 | 1517 | =for Pod::Functions get context of the current subroutine call |
1531 | 1518 | |
1532 | 1519 | =begin original |
1533 | 1520 | |
1534 | Returns the context of the current | |
1521 | Returns the context of the current subroutine call. In scalar context, | |
1535 | ||
1522 | returns the caller's package name if there I<is> a caller (that is, if | |
1536 | 1523 | we're in a subroutine or C<eval> or C<require>) and the undefined value |
1537 | otherwise. | |
1524 | otherwise. In list context, returns | |
1538 | perl sub will appear instead of the XS sub in caller's return values. In list | |
1539 | context, caller returns | |
1540 | 1525 | |
1541 | 1526 | =end original |
1542 | 1527 | |
1543 | その時点の | |
1528 | その時点のサブルーチン呼び出しのコンテキストを返します。 | |
1544 | 1529 | スカラコンテキストでは、呼び元が I<ある> 場合 |
1545 | 1530 | (サブルーチン、C<eval>、C<require> の中にいるとき) には |
1546 | 1531 | 呼び出し元のパッケージ名を返し、その他のときには未定義値を返します。 |
1547 | ||
1532 | リストコンテキストでは、以下を返します: | |
1548 | XS サブルーチンの代わりに次のピュア perl サブルーチンが caller の返り値に | |
1549 | なります。 | |
1550 | リストコンテキストでは、caller は以下を返します: | |
1551 | 1533 | |
1552 | 1534 | # 0 1 2 |
1553 | 1535 | ($package, $filename, $line) = caller; |
1554 | 1536 | |
1555 | 1537 | =begin original |
1556 | 1538 | |
1557 | 1539 | With EXPR, it returns some extra information that the debugger uses to |
1558 | 1540 | print a stack trace. The value of EXPR indicates how many call frames |
1559 | 1541 | to go back before the current one. |
1560 | 1542 | |
1561 | 1543 | =end original |
1562 | 1544 | |
1563 | 1545 | EXPR を付けると、デバッガがスタックトレースを表示するために使う情報を返します。 |
1564 | 1546 | EXPR の値は、現状から数えて、 |
1565 | 1547 | いくつ前のコールフレームまで戻るかを示します。 |
1566 | 1548 | |
1567 | 1549 | # 0 1 2 3 4 |
1568 | 1550 | ($package, $filename, $line, $subroutine, $hasargs, |
1569 | 1551 | |
1570 | 1552 | # 5 6 7 8 9 10 |
1571 | 1553 | $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash) |
1572 | 1554 | = caller($i); |
1573 | 1555 | |
1574 | 1556 | =begin original |
1575 | 1557 | |
1576 | Here | |
1558 | Here $subroutine may be C<(eval)> if the frame is not a subroutine | |
1577 | ||
1559 | call, but an C<eval>. In such a case additional elements $evaltext and | |
1578 | the frame is not a subroutine call, but an C<eval>. In such a case | |
1579 | additional elements $evaltext and | |
1580 | 1560 | C<$is_require> are set: C<$is_require> is true if the frame is created by a |
1581 | 1561 | C<require> or C<use> statement, $evaltext contains the text of the |
1582 | 1562 | C<eval EXPR> statement. In particular, for an C<eval BLOCK> statement, |
1583 | 1563 | $subroutine is C<(eval)>, but $evaltext is undefined. (Note also that |
1584 | 1564 | each C<use> statement creates a C<require> frame inside an C<eval EXPR> |
1585 | 1565 | frame.) $subroutine may also be C<(unknown)> if this particular |
1586 | 1566 | subroutine happens to have been deleted from the symbol table. |
1587 | 1567 | C<$hasargs> is true if a new instance of C<@_> was set up for the frame. |
1588 | 1568 | C<$hints> and C<$bitmask> contain pragmatic hints that the caller was |
1589 | compiled with. C<$hints> | |
1569 | compiled with. The C<$hints> and C<$bitmask> values are subject to change | |
1590 | ||
1570 | between versions of Perl, and are not meant for external use. | |
1591 | C<$hints> and C<$bitmask> values are subject | |
1592 | to change between versions of Perl, and are not meant for external use. | |
1593 | 1571 | |
1594 | 1572 | =end original |
1595 | 1573 | |
1596 | ||
1574 | もしフレームがサブルーチン呼び出しではなく C<eval> だった場合、この | |
1597 | ||
1575 | $subroutine は C<(eval)> になります。 | |
1598 | フレームがサブルーチン呼び出しではなく C<eval> だった場合、この | |
1599 | $subroutine は C<(eval)> になることに注意してください。 | |
1600 | 1576 | この場合、追加の要素である $evaltext と C<$is_require> がセットされます: |
1601 | 1577 | C<$is_require> はフレームが C<require> または C<use> で作られた場合に |
1602 | 1578 | 真になり、$evaltext は C<eval EXPR> のテキストが入ります。 |
1603 | 1579 | 特に、C<eval BLOCK> の場合、$subroutine は C<(eval)> になりますが、 |
1604 | 1580 | $evaltext は未定義値になります。 |
1605 | 1581 | (それぞれの C<use> は C<eval EXPR> の中で C<require> フレームを作ることに |
1606 | 1582 | 注意してください。) |
1607 | 1583 | $subroutine は、そのサブルーチンがシンボルテーブルから削除された場合は |
1608 | 1584 | C<(unknown)> になります。 |
1609 | C<$hasargs> はこのフレーム用に C<@_> の新しい実体が設定された場合に | |
1585 | C<$hasargs> はこのフレーム用に C<@_> の新しい実体が設定された場合に真となります。 | |
1610 | 真となります。 | |
1611 | 1586 | C<$hints> と C<$bitmask> は caller がコンパイルされたときの |
1612 | 1587 | 実際的なヒントを含みます。 |
1613 | C<$hints> は C<$^H> に対応し、C<$bitmask> は C<${^WARNING_BITS}> に | |
1614 | 対応します。 | |
1615 | 1588 | C<$hints> は C<$bitmask> は Perl のバージョンによって変更される |
1616 | 1589 | 可能性があるので、外部での使用を想定していません。 |
1617 | 1590 | |
1618 | 1591 | =begin original |
1619 | 1592 | |
1620 | 1593 | C<$hinthash> is a reference to a hash containing the value of C<%^H> when the |
1621 | 1594 | caller was compiled, or C<undef> if C<%^H> was empty. Do not modify the values |
1622 | 1595 | of this hash, as they are the actual values stored in the optree. |
1623 | 1596 | |
1624 | 1597 | =end original |
1625 | 1598 | |
1626 | 1599 | C<$hinthash> は、caller がコンパイルされた時の C<%^H> の値を含む |
1627 | 1600 | ハッシュへのリファレンスか、あるいは C<%^H> が空の場合は C<undef> です。 |
1628 | 1601 | このハッシュの値は構文木に保管されている実際の値なので、変更しないで下さい。 |
1629 | 1602 | |
1630 | 1603 | =begin original |
1631 | 1604 | |
1632 | 1605 | Furthermore, when called from within the DB package in |
1633 | 1606 | list context, and with an argument, caller returns more |
1634 | 1607 | detailed information: it sets the list variable C<@DB::args> to be the |
1635 | 1608 | arguments with which the subroutine was invoked. |
1636 | 1609 | |
1637 | 1610 | =end original |
1638 | 1611 | |
1639 | 1612 | さらに、DB パッケージの中からリストコンテキストで引数付きで呼ばれた場合は、 |
1640 | 1613 | caller はより詳細な情報を返します; サブルーチンが起動されたときの引数を |
1641 | 1614 | 変数 C<@DB::args> に設定します。 |
1642 | 1615 | |
1643 | 1616 | =begin original |
1644 | 1617 | |
1645 | 1618 | Be aware that the optimizer might have optimized call frames away before |
1646 | 1619 | C<caller> had a chance to get the information. That means that C<caller(N)> |
1647 | 1620 | might not return information about the call frame you expect it to, for |
1648 | 1621 | C<< N > 1 >>. In particular, C<@DB::args> might have information from the |
1649 | 1622 | previous time C<caller> was called. |
1650 | 1623 | |
1651 | 1624 | =end original |
1652 | 1625 | |
1653 | 1626 | C<caller> が情報を得る前にオプティマイザが呼び出しフレームを最適化して |
1654 | 1627 | しまうかもしれないことに注意してください。 |
1655 | 1628 | これは、C<caller(N)> が C<< N > 1 >> のとき、 |
1656 | 1629 | あなたが予測した呼び出しフレームの情報を返さないかもしれないことを意味します。 |
1657 | 1630 | 特に、C<@DB::args> は C<caller> が前回呼び出された時の情報を |
1658 | 1631 | 持っているかもしれません。 |
1659 | 1632 | |
1660 | 1633 | =begin original |
1661 | 1634 | |
1662 | 1635 | Be aware that setting C<@DB::args> is I<best effort>, intended for |
1663 | 1636 | debugging or generating backtraces, and should not be relied upon. In |
1664 | 1637 | particular, as C<@_> contains aliases to the caller's arguments, Perl does |
1665 | 1638 | not take a copy of C<@_>, so C<@DB::args> will contain modifications the |
1666 | 1639 | subroutine makes to C<@_> or its contents, not the original values at call |
1667 | 1640 | time. C<@DB::args>, like C<@_>, does not hold explicit references to its |
1668 | 1641 | elements, so under certain cases its elements may have become freed and |
1669 | 1642 | reallocated for other variables or temporary values. Finally, a side effect |
1670 | 1643 | of the current implementation is that the effects of C<shift @_> can |
1671 | 1644 | I<normally> be undone (but not C<pop @_> or other splicing, I<and> not if a |
1672 | 1645 | reference to C<@_> has been taken, I<and> subject to the caveat about reallocated |
1673 | 1646 | elements), so C<@DB::args> is actually a hybrid of the current state and |
1674 | 1647 | initial state of C<@_>. Buyer beware. |
1675 | 1648 | |
1676 | 1649 | =end original |
1677 | 1650 | |
1678 | 1651 | C<@DB::args> の設定は I<ベストエフォート> で、デバッグやバックトレースの |
1679 | 1652 | 生成を目的としていて、これに依存するべきではないということにも |
1680 | 1653 | 注意してください。 |
1681 | 1654 | 特に、C<@_> は呼び出し元の引数へのエイリアスを含んでいるので、Perl は |
1682 | 1655 | C<@_> のコピーを取らず、従って C<@DB::args> はサブルーチンが |
1683 | 1656 | C<@_> やその内容に行った変更を含んでいて、呼び出し時の元の値ではありません。 |
1684 | 1657 | C<@DB::args> は、C<@_> と同様、その要素への明示的なリファレンスを |
1685 | 1658 | 保持しないので、ある種の状況では、解放されて他の変数や一時的な値のために |
1686 | 1659 | 再割り当てされているかもしれません。 |
1687 | 1660 | 最後に、現在の実装の副作用は、C<shift @_> の効果は I<普通は> 行われない |
1688 | 1661 | (しかし C<pop @_> やその他の splice は違い、I<そして> もし |
1689 | 1662 | C<@_> のリファレンスが取られると違い、I<そして> 再割り当てされた要素に関する |
1690 | 1663 | 問題になりやすいです)ことなので、C<@DB::args> は実際には現在の状態と |
1691 | 1664 | C<@_> の初期状態との合成物となります。 |
1692 | 1665 | ご用心を。 |
1693 | 1666 | |
1694 | 1667 | =item chdir EXPR |
1695 | 1668 | X<chdir> |
1696 | 1669 | X<cd> |
1697 | 1670 | X<directory, change> |
1698 | 1671 | |
1699 | 1672 | =item chdir FILEHANDLE |
1700 | 1673 | |
1701 | 1674 | =item chdir DIRHANDLE |
1702 | 1675 | |
1703 | 1676 | =item chdir |
1704 | 1677 | |
1705 | 1678 | =for Pod::Functions change your current working directory |
1706 | 1679 | |
1707 | 1680 | =begin original |
1708 | 1681 | |
1709 | 1682 | Changes the working directory to EXPR, if possible. If EXPR is omitted, |
1710 | 1683 | changes to the directory specified by C<$ENV{HOME}>, if set; if not, |
1711 | 1684 | changes to the directory specified by C<$ENV{LOGDIR}>. (Under VMS, the |
1712 | 1685 | variable C<$ENV{SYS$LOGIN}> is also checked, and used if it is set.) If |
1713 | 1686 | neither is set, C<chdir> does nothing. It returns true on success, |
1714 | 1687 | false otherwise. See the example under C<die>. |
1715 | 1688 | |
1716 | 1689 | =end original |
1717 | 1690 | |
1718 | 1691 | (可能であれば、) カレントディレクトリを EXPR に移します。 |
1719 | 1692 | EXPR を指定しないと、C<$ENV{HOME}> が設定されていれば、そのディレクトリに |
1720 | 1693 | 移ります; そうでなく、C<$ENV{LOGDIR}>が設定されていれば、そのディレクトリに |
1721 | 1694 | 移ります。 |
1722 | 1695 | (VMS では C<$ENV{SYS$LOGIN}> もチェックされ、もしセットされていれば |
1723 | 1696 | 使われます。) |
1724 | 1697 | どちらも設定されていなければ、C<chdir> は何もしません。 |
1725 | 1698 | 成功時には真を返し、そうでなければ偽を返します。 |
1726 | 1699 | C<die> の項の例を参照してください。 |
1727 | 1700 | |
1728 | 1701 | =begin original |
1729 | 1702 | |
1730 | 1703 | On systems that support fchdir(2), you may pass a filehandle or |
1731 | 1704 | directory handle as the argument. On systems that don't support fchdir(2), |
1732 | 1705 | passing handles raises an exception. |
1733 | 1706 | |
1734 | 1707 | =end original |
1735 | 1708 | |
1736 | 1709 | fchdir(2) に対応しているシステムでは、ファイルハンドルや |
1737 | 1710 | ディレクトリハンドルを引数として渡せます。 |
1738 | 1711 | fchdir に対応していないシステムでは、ハンドルを渡すと例外が発生します。 |
1739 | 1712 | |
1740 | 1713 | =item chmod LIST |
1741 | 1714 | X<chmod> X<permission> X<mode> |
1742 | 1715 | |
1743 | 1716 | =for Pod::Functions changes the permissions on a list of files |
1744 | 1717 | |
1745 | 1718 | =begin original |
1746 | 1719 | |
1747 | 1720 | Changes the permissions of a list of files. The first element of the |
1748 | 1721 | list must be the numeric mode, which should probably be an octal |
1749 | 1722 | number, and which definitely should I<not> be a string of octal digits: |
1750 | 1723 | C<0644> is okay, but C<"0644"> is not. Returns the number of files |
1751 | 1724 | successfully changed. See also L</oct> if all you have is a string. |
1752 | 1725 | |
1753 | 1726 | =end original |
1754 | 1727 | |
1755 | 1728 | LIST に含まれるファイルの、パーミッションを変更します。 |
1756 | 1729 | LIST の最初の要素は、数値表現のモードでなければなりません; |
1757 | 1730 | 恐らく 8 進表記の数であるべきでしょう: しかし、8 進表記の |
1758 | 1731 | C<文字列ではいけません>: C<0644> は OK ですが、 C<'0644'> は |
1759 | 1732 | だめ、ということです。 |
1760 | 1733 | 変更に成功したファイルの数を返します。 |
1761 | 1734 | 文字列を使いたい場合は、L</oct> を参照してください。 |
1762 | 1735 | |
1763 | 1736 | $cnt = chmod 0755, "foo", "bar"; |
1764 | 1737 | chmod 0755, @executables; |
1765 | 1738 | $mode = "0644"; chmod $mode, "foo"; # !!! sets mode to |
1766 | 1739 | # --w----r-T |
1767 | 1740 | $mode = "0644"; chmod oct($mode), "foo"; # this is better |
1768 | 1741 | $mode = 0644; chmod $mode, "foo"; # this is best |
1769 | 1742 | |
1770 | 1743 | =begin original |
1771 | 1744 | |
1772 | 1745 | On systems that support fchmod(2), you may pass filehandles among the |
1773 | 1746 | files. On systems that don't support fchmod(2), passing filehandles raises |
1774 | 1747 | an exception. Filehandles must be passed as globs or glob references to be |
1775 | 1748 | recognized; barewords are considered filenames. |
1776 | 1749 | |
1777 | 1750 | =end original |
1778 | 1751 | |
1779 | 1752 | fchmod(2) に対応しているシステムでは、ファイルハンドルを引数として渡せます。 |
1780 | 1753 | fchmod(2) に対応していないシステムでは、ファイルハンドルを渡すと |
1781 | 1754 | 例外が発生します。 |
1782 | 1755 | ファイルハンドルを認識させるためには、グロブまたはリファレンスとして |
1783 | 1756 | 渡されなければなりません; |
1784 | 1757 | 裸の単語はファイル名として扱われます。 |
1785 | 1758 | |
1786 | 1759 | open(my $fh, "<", "foo"); |
1787 | 1760 | my $perm = (stat $fh)[2] & 07777; |
1788 | 1761 | chmod($perm | 0600, $fh); |
1789 | 1762 | |
1790 | 1763 | =begin original |
1791 | 1764 | |
1792 | 1765 | You can also import the symbolic C<S_I*> constants from the C<Fcntl> |
1793 | 1766 | module: |
1794 | 1767 | |
1795 | 1768 | =end original |
1796 | 1769 | |
1797 | 1770 | C<Fcntl> モジュールから C<S_I*> シンボル定数をインポートすることもできます: |
1798 | 1771 | |
1799 | 1772 | use Fcntl qw( :mode ); |
1800 | 1773 | chmod S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, @executables; |
1801 | 1774 | # Identical to the chmod 0755 of the example above. |
1802 | 1775 | |
1803 | 1776 | =begin original |
1804 | 1777 | |
1805 | 1778 | Portability issues: L<perlport/chmod>. |
1806 | 1779 | |
1807 | 1780 | =end original |
1808 | 1781 | |
1809 | 1782 | 移植性の問題: L<perlport/chmod>。 |
1810 | 1783 | |
1811 | 1784 | =item chomp VARIABLE |
1812 | 1785 | X<chomp> X<INPUT_RECORD_SEPARATOR> X<$/> X<newline> X<eol> |
1813 | 1786 | |
1814 | 1787 | =item chomp( LIST ) |
1815 | 1788 | |
1816 | 1789 | =item chomp |
1817 | 1790 | |
1818 | 1791 | =for Pod::Functions remove a trailing record separator from a string |
1819 | 1792 | |
1820 | 1793 | =begin original |
1821 | 1794 | |
1822 | 1795 | This safer version of L</chop> removes any trailing string |
1823 | 1796 | that corresponds to the current value of C<$/> (also known as |
1824 | 1797 | $INPUT_RECORD_SEPARATOR in the C<English> module). It returns the total |
1825 | 1798 | number of characters removed from all its arguments. It's often used to |
1826 | 1799 | remove the newline from the end of an input record when you're worried |
1827 | 1800 | that the final record may be missing its newline. When in paragraph |
1828 | 1801 | mode (C<$/ = "">), it removes all trailing newlines from the string. |
1829 | 1802 | When in slurp mode (C<$/ = undef>) or fixed-length record mode (C<$/> is |
1830 | 1803 | a reference to an integer or the like; see L<perlvar>) chomp() won't |
1831 | 1804 | remove anything. |
1832 | 1805 | If VARIABLE is omitted, it chomps C<$_>. Example: |
1833 | 1806 | |
1834 | 1807 | =end original |
1835 | 1808 | |
1836 | 1809 | より安全な C<chop> (以下を参照してください) です; C<$/> |
1837 | 1810 | (C<English> モジュールでは、$INPUT_RECORD_SEPARATOR とも言う) のその時点の |
1838 | 1811 | 値に対応する行末文字を削除します。 |
1839 | 1812 | 全ての引数から削除した文字数の合計を返します。 |
1840 | 1813 | 入力レコードから、改行を削除したいのだけれど、最後のレコードには改行が |
1841 | 1814 | 入っているのかわからないような場合に、使用できます。 |
1842 | 1815 | 段落モード (C<$/ = "">) では、レコードの最後の改行をすべて取り除きます。 |
1843 | 1816 | 吸い込みモード (C<$/ = undef>) や 固定長レコードモード |
1844 | 1817 | (C<$/> が整数へのリファレンスや類似のものの場合; L<perlvar>を参照してください) |
1845 | 1818 | では、chomp() は何も取り除きません。 |
1846 | 1819 | VARIABLE が省略されると、$_ を対象として chomp します。 |
1847 | 1820 | 例: |
1848 | 1821 | |
1849 | 1822 | while (<>) { |
1850 | 1823 | chomp; # avoid \n on last field |
1851 | 1824 | @array = split(/:/); |
1852 | 1825 | # ... |
1853 | 1826 | } |
1854 | 1827 | |
1855 | 1828 | =begin original |
1856 | 1829 | |
1857 | If VARIABLE is a hash, it chomps the hash's values, but not its keys | |
1830 | If VARIABLE is a hash, it chomps the hash's values, but not its keys. | |
1858 | resetting the C<each> iterator in the process. | |
1859 | 1831 | |
1860 | 1832 | =end original |
1861 | 1833 | |
1862 | VARIABLE がハッシュなら、ハッシュのキーではなく値について chomp し | |
1834 | VARIABLE がハッシュなら、ハッシュのキーではなく値について chomp します。 | |
1863 | このプロセスの C<each> 反復子をリセットします。 | |
1864 | 1835 | |
1865 | 1836 | =begin original |
1866 | 1837 | |
1867 | 1838 | You can actually chomp anything that's an lvalue, including an assignment: |
1868 | 1839 | |
1869 | 1840 | =end original |
1870 | 1841 | |
1871 | 1842 | 左辺値であれば、代入を含めて、任意のものを chomp できます: |
1872 | 1843 | |
1873 | 1844 | chomp($cwd = `pwd`); |
1874 | 1845 | chomp($answer = <STDIN>); |
1875 | 1846 | |
1876 | 1847 | =begin original |
1877 | 1848 | |
1878 | 1849 | If you chomp a list, each element is chomped, and the total number of |
1879 | 1850 | characters removed is returned. |
1880 | 1851 | |
1881 | 1852 | =end original |
1882 | 1853 | |
1883 | 1854 | リストを chomp すると、個々の要素が chomp され、 |
1884 | 1855 | 削除された文字数の合計が返されます。 |
1885 | 1856 | |
1886 | 1857 | =begin original |
1887 | 1858 | |
1888 | 1859 | Note that parentheses are necessary when you're chomping anything |
1889 | 1860 | that is not a simple variable. This is because C<chomp $cwd = `pwd`;> |
1890 | 1861 | is interpreted as C<(chomp $cwd) = `pwd`;>, rather than as |
1891 | 1862 | C<chomp( $cwd = `pwd` )> which you might expect. Similarly, |
1892 | 1863 | C<chomp $a, $b> is interpreted as C<chomp($a), $b> rather than |
1893 | 1864 | as C<chomp($a, $b)>. |
1894 | 1865 | |
1895 | 1866 | =end original |
1896 | 1867 | |
1897 | 1868 | 単純な変数以外のものを chomp する場合はかっこが必要であることに |
1898 | 1869 | 注意してください。 |
1899 | 1870 | これは、C<chomp $cwd = `pwd`;> は、予測している |
1900 | 1871 | C<chomp( $cwd = `pwd` )> ではなく、C<(chomp $cwd) = `pwd`;> と |
1901 | 1872 | 解釈されるからです。 |
1902 | 1873 | 同様に、C<chomp $a, $b> は C<chomp($a, $b)> ではなく C<chomp($a), $b> |
1903 | 1874 | と解釈されます。 |
1904 | 1875 | |
1905 | 1876 | =item chop VARIABLE |
1906 | 1877 | X<chop> |
1907 | 1878 | |
1908 | 1879 | =item chop( LIST ) |
1909 | 1880 | |
1910 | 1881 | =item chop |
1911 | 1882 | |
1912 | 1883 | =for Pod::Functions remove the last character from a string |
1913 | 1884 | |
1914 | 1885 | =begin original |
1915 | 1886 | |
1916 | 1887 | Chops off the last character of a string and returns the character |
1917 | 1888 | chopped. It is much more efficient than C<s/.$//s> because it neither |
1918 | 1889 | scans nor copies the string. If VARIABLE is omitted, chops C<$_>. |
1919 | If VARIABLE is a hash, it chops the hash's values, but not its keys | |
1890 | If VARIABLE is a hash, it chops the hash's values, but not its keys. | |
1920 | resetting the C<each> iterator in the process. | |
1921 | 1891 | |
1922 | 1892 | =end original |
1923 | 1893 | |
1924 | 1894 | 文字列の最後の文字を切り捨てて、その切り取った文字を返します。 |
1925 | 1895 | 文字列の検索もコピーも行ないませんので |
1926 | 1896 | C<s/.$//s> よりも、ずっと効率的です。 |
1927 | 1897 | VARIABLE が省略されると、C<$_> を対象として chop します。 |
1928 | VARIABLE がハッシュの場合、ハッシュの | |
1898 | VARIABLE がハッシュの場合、ハッシュの value を chop しますが、 | |
1929 | ||
1899 | key は chop しません。 | |
1930 | 1900 | |
1931 | 1901 | =begin original |
1932 | 1902 | |
1933 | 1903 | You can actually chop anything that's an lvalue, including an assignment. |
1934 | 1904 | |
1935 | 1905 | =end original |
1936 | 1906 | |
1937 | 1907 | 実際のところ、代入を含む左辺値となりうるなんでも chop できます。 |
1938 | 1908 | |
1939 | 1909 | =begin original |
1940 | 1910 | |
1941 | 1911 | If you chop a list, each element is chopped. Only the value of the |
1942 | 1912 | last C<chop> is returned. |
1943 | 1913 | |
1944 | 1914 | =end original |
1945 | 1915 | |
1946 | 1916 | リストを chop すると、個々の要素が chop されます。 |
1947 | 1917 | 最後の C<chop> の値だけが返されます。 |
1948 | 1918 | |
1949 | 1919 | =begin original |
1950 | 1920 | |
1951 | 1921 | Note that C<chop> returns the last character. To return all but the last |
1952 | 1922 | character, use C<substr($string, 0, -1)>. |
1953 | 1923 | |
1954 | 1924 | =end original |
1955 | 1925 | |
1956 | 1926 | C<chop> は最後の文字を返すことに注意してください。 |
1957 | 1927 | 最後以外の全ての文字を返すためには、C<substr($string, 0, -1)> を |
1958 | 1928 | 使ってください。 |
1959 | 1929 | |
1960 | 1930 | =begin original |
1961 | 1931 | |
1962 | 1932 | See also L</chomp>. |
1963 | 1933 | |
1964 | 1934 | =end original |
1965 | 1935 | |
1966 | 1936 | L</chomp> も参照してください。 |
1967 | 1937 | |
1968 | 1938 | =item chown LIST |
1969 | 1939 | X<chown> X<owner> X<user> X<group> |
1970 | 1940 | |
1971 | 1941 | =for Pod::Functions change the ownership on a list of files |
1972 | 1942 | |
1973 | 1943 | =begin original |
1974 | 1944 | |
1975 | 1945 | Changes the owner (and group) of a list of files. The first two |
1976 | 1946 | elements of the list must be the I<numeric> uid and gid, in that |
1977 | 1947 | order. A value of -1 in either position is interpreted by most |
1978 | 1948 | systems to leave that value unchanged. Returns the number of files |
1979 | 1949 | successfully changed. |
1980 | 1950 | |
1981 | 1951 | =end original |
1982 | 1952 | |
1983 | 1953 | LIST に含まれるファイルの所有者 (とグループ) を変更します。 |
1984 | 1954 | LIST の最初の二つの要素には、I<数値表現> の uid と gid を |
1985 | 1955 | この順序で与えなければなりません。 |
1986 | 1956 | どちらかの値を -1 にすると、ほとんどのシステムではその値は |
1987 | 1957 | 変更しないと解釈します。 |
1988 | 1958 | 変更に成功したファイルの数を返します。 |
1989 | 1959 | |
1990 | 1960 | $cnt = chown $uid, $gid, 'foo', 'bar'; |
1991 | 1961 | chown $uid, $gid, @filenames; |
1992 | 1962 | |
1993 | 1963 | =begin original |
1994 | 1964 | |
1995 | 1965 | On systems that support fchown(2), you may pass filehandles among the |
1996 | 1966 | files. On systems that don't support fchown(2), passing filehandles raises |
1997 | 1967 | an exception. Filehandles must be passed as globs or glob references to be |
1998 | 1968 | recognized; barewords are considered filenames. |
1999 | 1969 | |
2000 | 1970 | =end original |
2001 | 1971 | |
2002 | 1972 | fchown(2) に対応しているシステムでは、ファイルハンドルを引数として渡せます。 |
2003 | 1973 | fchown(2) に対応していないシステムでは、ファイルハンドルを渡すと |
2004 | 1974 | 例外が発生します。 |
2005 | 1975 | ファイルハンドルを認識させるためには、グロブまたはリファレンスとして |
2006 | 1976 | 渡されなければなりません; 裸の単語はファイル名として扱われます。 |
2007 | 1977 | |
2008 | 1978 | =begin original |
2009 | 1979 | |
2010 | 1980 | Here's an example that looks up nonnumeric uids in the passwd file: |
2011 | 1981 | |
2012 | 1982 | =end original |
2013 | 1983 | |
2014 | 1984 | passwd ファイルから数値表現でない uid を検索する例を |
2015 | 1985 | 示します: |
2016 | 1986 | |
2017 | 1987 | print "User: "; |
2018 | 1988 | chomp($user = <STDIN>); |
2019 | 1989 | print "Files: "; |
2020 | 1990 | chomp($pattern = <STDIN>); |
2021 | 1991 | |
2022 | 1992 | ($login,$pass,$uid,$gid) = getpwnam($user) |
2023 | 1993 | or die "$user not in passwd file"; |
2024 | 1994 | |
2025 | 1995 | @ary = glob($pattern); # expand filenames |
2026 | 1996 | chown $uid, $gid, @ary; |
2027 | 1997 | |
2028 | 1998 | =begin original |
2029 | 1999 | |
2030 | 2000 | On most systems, you are not allowed to change the ownership of the |
2031 | 2001 | file unless you're the superuser, although you should be able to change |
2032 | 2002 | the group to any of your secondary groups. On insecure systems, these |
2033 | 2003 | restrictions may be relaxed, but this is not a portable assumption. |
2034 | 2004 | On POSIX systems, you can detect this condition this way: |
2035 | 2005 | |
2036 | 2006 | =end original |
2037 | 2007 | |
2038 | 2008 | ほとんどのシステムでは、スーパーユーザーだけがファイルの所有者を |
2039 | 2009 | 変更できますが、グループは実行者の副グループに変更できるべきです。 |
2040 | 2010 | 安全でないシステムでは、この制限はゆるめられています; しかしこれは |
2041 | 2011 | 移植性のある仮定ではありません。 |
2042 | 2012 | POSIX システムでは、以下のようにしてこの条件を検出できます: |
2043 | 2013 | |
2044 | 2014 | use POSIX qw(sysconf _PC_CHOWN_RESTRICTED); |
2045 | 2015 | $can_chown_giveaway = not sysconf(_PC_CHOWN_RESTRICTED); |
2046 | 2016 | |
2047 | 2017 | =begin original |
2048 | 2018 | |
2049 | Portability issues: L<perlport/cho | |
2019 | Portability issues: L<perlport/chmod>. | |
2050 | 2020 | |
2051 | 2021 | =end original |
2052 | 2022 | |
2053 | 移植性の問題: L<perlport/cho | |
2023 | 移植性の問題: L<perlport/chmod>。 | |
2054 | 2024 | |
2055 | 2025 | =item chr NUMBER |
2056 | 2026 | X<chr> X<character> X<ASCII> X<Unicode> |
2057 | 2027 | |
2058 | 2028 | =item chr |
2059 | 2029 | |
2060 | 2030 | =for Pod::Functions get character this number represents |
2061 | 2031 | |
2062 | 2032 | =begin original |
2063 | 2033 | |
2064 | 2034 | Returns the character represented by that NUMBER in the character set. |
2065 | 2035 | For example, C<chr(65)> is C<"A"> in either ASCII or Unicode, and |
2066 | 2036 | chr(0x263a) is a Unicode smiley face. |
2067 | 2037 | |
2068 | 2038 | =end original |
2069 | 2039 | |
2070 | 2040 | 特定の文字セットでの NUMBER で表わされる文字を返します。 |
2071 | 2041 | たとえば、C<chr(65)> は ASCII と Unicode の両方で C<"A"> となります; |
2072 | 2042 | chr(0x263a) は Unicode のスマイリーフェイスです。 |
2073 | 2043 | |
2074 | 2044 | =begin original |
2075 | 2045 | |
2076 | 2046 | Negative values give the Unicode replacement character (chr(0xfffd)), |
2077 | 2047 | except under the L<bytes> pragma, where the low eight bits of the value |
2078 | 2048 | (truncated to an integer) are used. |
2079 | 2049 | |
2080 | 2050 | =end original |
2081 | 2051 | |
2082 | 2052 | 負の数は Unicode の置換文字 (chr(0xfffd)) を与えますが、 |
2083 | 2053 | L<bytes> プラグマの影響下では、(integer に切り詰められた)値の下位 8 ビットが |
2084 | 2054 | 使われます。 |
2085 | 2055 | |
2086 | 2056 | =begin original |
2087 | 2057 | |
2088 | 2058 | If NUMBER is omitted, uses C<$_>. |
2089 | 2059 | |
2090 | 2060 | =end original |
2091 | 2061 | |
2092 | 2062 | NUMBER が省略された場合、C<$_> を使います。 |
2093 | 2063 | |
2094 | 2064 | =begin original |
2095 | 2065 | |
2096 | 2066 | For the reverse, use L</ord>. |
2097 | 2067 | |
2098 | 2068 | =end original |
2099 | 2069 | |
2100 | 2070 | 逆を行うためには、L</ord> を参照してください。 |
2101 | 2071 | |
2102 | 2072 | =begin original |
2103 | 2073 | |
2104 | 2074 | Note that characters from 128 to 255 (inclusive) are by default |
2105 | 2075 | internally not encoded as UTF-8 for backward compatibility reasons. |
2106 | 2076 | |
2107 | 2077 | =end original |
2108 | 2078 | |
2109 | 2079 | 128 から 255 までの文字は過去との互換性のために |
2110 | 2080 | デフォルトでは UTF-8 Unicode にエンコードされません。 |
2111 | 2081 | |
2112 | 2082 | =begin original |
2113 | 2083 | |
2114 | 2084 | See L<perlunicode> for more about Unicode. |
2115 | 2085 | |
2116 | 2086 | =end original |
2117 | 2087 | |
2118 | 2088 | Unicode については L<perlunicode> を参照してください。 |
2119 | 2089 | |
2120 | 2090 | =item chroot FILENAME |
2121 | 2091 | X<chroot> X<root> |
2122 | 2092 | |
2123 | 2093 | =item chroot |
2124 | 2094 | |
2125 | 2095 | =for Pod::Functions make directory new root for path lookups |
2126 | 2096 | |
2127 | 2097 | =begin original |
2128 | 2098 | |
2129 | 2099 | This function works like the system call by the same name: it makes the |
2130 | 2100 | named directory the new root directory for all further pathnames that |
2131 | 2101 | begin with a C</> by your process and all its children. (It doesn't |
2132 | 2102 | change your current working directory, which is unaffected.) For security |
2133 | 2103 | reasons, this call is restricted to the superuser. If FILENAME is |
2134 | 2104 | omitted, does a C<chroot> to C<$_>. |
2135 | 2105 | |
2136 | 2106 | =end original |
2137 | 2107 | |
2138 | 2108 | 同じ名前のシステムコールと同じことをします: 現在のプロセス及び子プロセスに |
2139 | 2109 | 対して、C</>で始まるパス名に関して指定されたディレクトリを新しい |
2140 | 2110 | ルートディレクトリとして扱います。 |
2141 | 2111 | (これはカレントディレクトリを変更しません; カレントディレクトリは |
2142 | 2112 | そのままです。) |
2143 | 2113 | セキュリティ上の理由により、この呼び出しはスーパーユーザーしか行えません。 |
2144 | 2114 | FILENAME を省略すると、C<$_> へ C<chroot> します。 |
2145 | 2115 | |
2146 | 2116 | =begin original |
2147 | 2117 | |
2148 | B<NOTE:> It is good security practice to do C<chdir("/")> (to the root | |
2149 | directory) immediately after a C<chroot()>. | |
2150 | ||
2151 | =end original | |
2152 | ||
2153 | B<注意:> C<chroot()> の直後に (ルートディレクトリに) C<chdir("/")> するのは | |
2154 | セキュリティ上の良い習慣です。 | |
2155 | ||
2156 | =begin original | |
2157 | ||
2158 | 2118 | Portability issues: L<perlport/chroot>. |
2159 | 2119 | |
2160 | 2120 | =end original |
2161 | 2121 | |
2162 | 2122 | 移植性の問題: L<perlport/chroot>。 |
2163 | 2123 | |
2164 | 2124 | =item close FILEHANDLE |
2165 | 2125 | X<close> |
2166 | 2126 | |
2167 | 2127 | =item close |
2168 | 2128 | |
2169 | 2129 | =for Pod::Functions close file (or pipe or socket) handle |
2170 | 2130 | |
2171 | 2131 | =begin original |
2172 | 2132 | |
2173 | 2133 | Closes the file or pipe associated with the filehandle, flushes the IO |
2174 | 2134 | buffers, and closes the system file descriptor. Returns true if those |
2175 | 2135 | operations succeed and if no error was reported by any PerlIO |
2176 | 2136 | layer. Closes the currently selected filehandle if the argument is |
2177 | 2137 | omitted. |
2178 | 2138 | |
2179 | 2139 | =end original |
2180 | 2140 | |
2181 | 2141 | FILEHANDLE に対応したファイルまたはパイプをクローズして、 |
2182 | 2142 | IO バッファをフラッシュし、システムファイル記述子をクローズします。 |
2183 | 2143 | 操作が成功し、PerlIO 層からエラーが報告されなかった場合に真を返します。 |
2184 | 2144 | 引数が省略された場合、現在選択されているファイルハンドルをクローズします。 |
2185 | 2145 | |
2186 | 2146 | =begin original |
2187 | 2147 | |
2188 | 2148 | You don't have to close FILEHANDLE if you are immediately going to do |
2189 | 2149 | another C<open> on it, because C<open> closes it for you. (See |
2190 | 2150 | L<open|/open FILEHANDLE>.) However, an explicit C<close> on an input file resets the line |
2191 | 2151 | counter (C<$.>), while the implicit close done by C<open> does not. |
2192 | 2152 | |
2193 | 2153 | =end original |
2194 | 2154 | |
2195 | 2155 | クローズしてすぐにまた、同じファイルハンドルに対してオープンを行なう |
2196 | 2156 | 場合には、C<open> が自動的に C<close> を行ないますので、 |
2197 | 2157 | close FILEHANDLE する必要はありません。 |
2198 | 2158 | (L<open|/open FILEHANDLE> を参照してください。) |
2199 | 2159 | ただし、明示的にクローズを行なったときにのみ入力ファイルの |
2200 | 2160 | 行番号 (C<$.>) のリセットが行なわれ、C<open> によって行なわれる |
2201 | 2161 | 暗黙の C<close> では行なわれません。 |
2202 | 2162 | |
2203 | 2163 | =begin original |
2204 | 2164 | |
2205 | 2165 | If the filehandle came from a piped open, C<close> returns false if one of |
2206 | 2166 | the other syscalls involved fails or if its program exits with non-zero |
2207 | 2167 | status. If the only problem was that the program exited non-zero, C<$!> |
2208 | 2168 | will be set to C<0>. Closing a pipe also waits for the process executing |
2209 | 2169 | on the pipe to exit--in case you wish to look at the output of the pipe |
2210 | 2170 | afterwards--and implicitly puts the exit status value of that command into |
2211 | 2171 | C<$?> and C<${^CHILD_ERROR_NATIVE}>. |
2212 | 2172 | |
2213 | 2173 | =end original |
2214 | 2174 | |
2215 | 2175 | ファイルハンドルがパイプつきオープンなら、C<close> はその他の |
2216 | 2176 | システムコールが失敗したりプログラムが非ゼロのステータスで終了した場合にも |
2217 | 2177 | 偽を返します。 |
2218 | 2178 | プログラムが非ゼロで終了しただけの場合は、C<$!>がC<0>にセットされます。 |
2219 | 2179 | 後でパイプの出力を見たい場合のために、パイプのクローズでは、パイプ上で |
2220 | 2180 | 実行されているプロセスの終了を待ち、また自動的にコマンドのステータス値を |
2221 | 2181 | C<$?> と C<${^CHILD_ERROR_NATIVE}> に設定します。 |
2222 | 2182 | |
2223 | 2183 | =begin original |
2224 | 2184 | |
2225 | 2185 | If there are multiple threads running, C<close> on a filehandle from a |
2226 | 2186 | piped open returns true without waiting for the child process to terminate, |
2227 | 2187 | if the filehandle is still open in another thread. |
2228 | 2188 | |
2229 | 2189 | =end original |
2230 | 2190 | |
2231 | 2191 | 複数のスレッドがある場合、パイプで開かれたファイルハンドルに対する |
2232 | 2192 | C<close> は、そのファイルハンドルが他のスレッドでまだ開かれている場合、 |
2233 | 2193 | 子プロセスの終了を待たずに真を返します。 |
2234 | 2194 | |
2235 | 2195 | =begin original |
2236 | 2196 | |
2237 | 2197 | Closing the read end of a pipe before the process writing to it at the |
2238 | 2198 | other end is done writing results in the writer receiving a SIGPIPE. If |
2239 | 2199 | the other end can't handle that, be sure to read all the data before |
2240 | 2200 | closing the pipe. |
2241 | 2201 | |
2242 | 2202 | =end original |
2243 | 2203 | |
2244 | 2204 | 書き込み側が閉じる前に途中でパイプの読み込み側が閉じた場合、 |
2245 | 2205 | 書き込み側に SIGPIPE が配送されます。 |
2246 | 2206 | 書き込み側がこれを扱えない場合、パイプを閉じる前に |
2247 | 2207 | 確実に全てのデータが読み込まれるようにする必要があります。 |
2248 | 2208 | |
2249 | 2209 | =begin original |
2250 | 2210 | |
2251 | 2211 | Example: |
2252 | 2212 | |
2253 | 2213 | =end original |
2254 | 2214 | |
2255 | 2215 | 例: |
2256 | 2216 | |
2257 | 2217 | open(OUTPUT, '|sort >foo') # pipe to sort |
2258 | 2218 | or die "Can't start sort: $!"; |
2259 | 2219 | #... # print stuff to output |
2260 | 2220 | close OUTPUT # wait for sort to finish |
2261 | 2221 | or warn $! ? "Error closing sort pipe: $!" |
2262 | 2222 | : "Exit status $? from sort"; |
2263 | 2223 | open(INPUT, 'foo') # get sort's results |
2264 | 2224 | or die "Can't open 'foo' for input: $!"; |
2265 | 2225 | |
2266 | 2226 | =begin original |
2267 | 2227 | |
2268 | 2228 | FILEHANDLE may be an expression whose value can be used as an indirect |
2269 | 2229 | filehandle, usually the real filehandle name or an autovivified handle. |
2270 | 2230 | |
2271 | 2231 | =end original |
2272 | 2232 | |
2273 | 2233 | FILEHANDLE は式でもかまいません; この場合、値は間接ファイルハンドルと |
2274 | 2234 | して扱われ、普通は実際のファイルハンドル名か自動有効化されたハンドルです。 |
2275 | 2235 | |
2276 | 2236 | =item closedir DIRHANDLE |
2277 | 2237 | X<closedir> |
2278 | 2238 | |
2279 | 2239 | =for Pod::Functions close directory handle |
2280 | 2240 | |
2281 | 2241 | =begin original |
2282 | 2242 | |
2283 | 2243 | Closes a directory opened by C<opendir> and returns the success of that |
2284 | 2244 | system call. |
2285 | 2245 | |
2286 | 2246 | =end original |
2287 | 2247 | |
2288 | 2248 | C<opendir> でオープンしたディレクトリをクローズし、 |
2289 | 2249 | システムコールの返り値を返します。 |
2290 | 2250 | |
2291 | 2251 | =item connect SOCKET,NAME |
2292 | 2252 | X<connect> |
2293 | 2253 | |
2294 | 2254 | =for Pod::Functions connect to a remote socket |
2295 | 2255 | |
2296 | 2256 | =begin original |
2297 | 2257 | |
2298 | 2258 | Attempts to connect to a remote socket, just like connect(2). |
2299 | 2259 | Returns true if it succeeded, false otherwise. NAME should be a |
2300 | 2260 | packed address of the appropriate type for the socket. See the examples in |
2301 | 2261 | L<perlipc/"Sockets: Client/Server Communication">. |
2302 | 2262 | |
2303 | 2263 | =end original |
2304 | 2264 | |
2305 | 2265 | connect(2) システムコールと同様に、リモートソケットへの接続を試みます。 |
2306 | 2266 | 成功時には真を、さもなければ偽を返します。 |
2307 | 2267 | NAME は、ソケットに対する、適切な型のパックされた |
2308 | 2268 | アドレスでなければなりません。 |
2309 | 2269 | L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。 |
2310 | 2270 | |
2311 | 2271 | =item continue BLOCK |
2312 | 2272 | X<continue> |
2313 | 2273 | |
2314 | 2274 | =item continue |
2315 | 2275 | |
2316 | 2276 | =for Pod::Functions optional trailing block in a while or foreach |
2317 | 2277 | |
2318 | 2278 | =begin original |
2319 | 2279 | |
2320 | 2280 | When followed by a BLOCK, C<continue> is actually a |
2321 | 2281 | flow control statement rather than a function. If |
2322 | 2282 | there is a C<continue> BLOCK attached to a BLOCK (typically in a C<while> or |
2323 | 2283 | C<foreach>), it is always executed just before the conditional is about to |
2324 | 2284 | be evaluated again, just like the third part of a C<for> loop in C. Thus |
2325 | 2285 | it can be used to increment a loop variable, even when the loop has been |
2326 | 2286 | continued via the C<next> statement (which is similar to the C C<continue> |
2327 | 2287 | statement). |
2328 | 2288 | |
2329 | 2289 | =end original |
2330 | 2290 | |
2331 | 2291 | BLOCK が引き続く場合、C<continue> は実際には関数ではなく、実行制御文です。 |
2332 | C<continue> BLOCK が BLOCK (典型的には C<while> または C<foreach> の中)に | |
2292 | C<continue> BLOCK が BLOCK (典型的には C<while> または C<foreach> の中)にあると、 | |
2333 | ||
2293 | これは条件文が再評価される直前に常に実行されます; これは C における | |
2334 | 2294 | C<for> ループの 3 番目の部分と同様です。 |
2335 | 2295 | 従って、これは C<next> 文 (これは C の C<continue> 文と似ています) を使って |
2336 | 2296 | ループが繰り返されるときでもループ変数を増やしたいときに使えます。 |
2337 | 2297 | |
2338 | 2298 | =begin original |
2339 | 2299 | |
2340 | 2300 | C<last>, C<next>, or C<redo> may appear within a C<continue> |
2341 | 2301 | block; C<last> and C<redo> behave as if they had been executed within |
2342 | 2302 | the main block. So will C<next>, but since it will execute a C<continue> |
2343 | 2303 | block, it may be more entertaining. |
2344 | 2304 | |
2345 | 2305 | =end original |
2346 | 2306 | |
2347 | 2307 | C<last>, C<next>, C<redo> が C<continue> ブロック内に現れる可能性があります; |
2348 | 2308 | C<last> と C<redo> はメインブロックの中で実行されたのと同じように振舞います。 |
2349 | 2309 | C<next> の場合は、C<continue> ブロックを実行することになるので、 |
2350 | 2310 | より面白いことになります。 |
2351 | 2311 | |
2352 | 2312 | while (EXPR) { |
2353 | 2313 | ### redo always comes here |
2354 | 2314 | do_something; |
2355 | 2315 | } continue { |
2356 | 2316 | ### next always comes here |
2357 | 2317 | do_something_else; |
2358 | 2318 | # then back the top to re-check EXPR |
2359 | 2319 | } |
2360 | 2320 | ### last always comes here |
2361 | 2321 | |
2362 | 2322 | =begin original |
2363 | 2323 | |
2364 | 2324 | Omitting the C<continue> section is equivalent to using an |
2365 | 2325 | empty one, logically enough, so C<next> goes directly back |
2366 | 2326 | to check the condition at the top of the loop. |
2367 | 2327 | |
2368 | 2328 | =end original |
2369 | 2329 | |
2370 | 2330 | C<continue> 節を省略するのは、空の節を指定したのと同じで、 |
2371 | 2331 | 論理的には十分なので、この場合、C<next> は直接ループ先頭の |
2372 | 2332 | 条件チェックに戻ります。 |
2373 | 2333 | |
2374 | 2334 | =begin original |
2375 | 2335 | |
2376 | 2336 | When there is no BLOCK, C<continue> is a function that |
2377 | 2337 | falls through the current C<when> or C<default> block instead of iterating |
2378 | 2338 | a dynamically enclosing C<foreach> or exiting a lexically enclosing C<given>. |
2379 | 2339 | In Perl 5.14 and earlier, this form of C<continue> was |
2380 | 2340 | only available when the C<"switch"> feature was enabled. |
2381 | 2341 | See L<feature> and L<perlsyn/"Switch Statements"> for more |
2382 | 2342 | information. |
2383 | 2343 | |
2384 | 2344 | =end original |
2385 | 2345 | |
2386 | 2346 | BLOCK がなければ、C<continue> は動的に囲まれた C<foreach> や |
2387 | 2347 | レキシカルに囲まれた C<given> で反復するのではなく、現在の C<when> または |
2388 | 2348 | C<default> のブロックを通り抜けるための文です。 |
2389 | 2349 | Perl 5.14 以前では、この形式の C<continue> は C<"switch"> 機能が有効の |
2390 | 2350 | 場合にのみ利用可能です。 |
2391 | 2351 | さらなる情報については L<feature> と L<perlsyn/"Switch Statements"> を |
2392 | 2352 | 参照してください。 |
2393 | 2353 | |
2394 | 2354 | =item cos EXPR |
2395 | 2355 | X<cos> X<cosine> X<acos> X<arccosine> |
2396 | 2356 | |
2397 | 2357 | =item cos |
2398 | 2358 | |
2399 | 2359 | =for Pod::Functions cosine function |
2400 | 2360 | |
2401 | 2361 | =begin original |
2402 | 2362 | |
2403 | 2363 | Returns the cosine of EXPR (expressed in radians). If EXPR is omitted, |
2404 | 2364 | takes the cosine of C<$_>. |
2405 | 2365 | |
2406 | 2366 | =end original |
2407 | 2367 | |
2408 | 2368 | (ラジアンで示した) EXPR の余弦を返します。 |
2409 | 2369 | EXPR が省略されたときには、C<$_> の余弦を取ります。 |
2410 | 2370 | |
2411 | 2371 | =begin original |
2412 | 2372 | |
2413 | 2373 | For the inverse cosine operation, you may use the C<Math::Trig::acos()> |
2414 | 2374 | function, or use this relation: |
2415 | 2375 | |
2416 | 2376 | =end original |
2417 | 2377 | |
2418 | 2378 | 逆余弦を求めるためには、C<Math::Trig::acos()> 関数を使うか、 |
2419 | 2379 | 以下の関係を使ってください。 |
2420 | 2380 | |
2421 | 2381 | sub acos { atan2( sqrt(1 - $_[0] * $_[0]), $_[0] ) } |
2422 | 2382 | |
2423 | 2383 | =item crypt PLAINTEXT,SALT |
2424 | 2384 | X<crypt> X<digest> X<hash> X<salt> X<plaintext> X<password> |
2425 | 2385 | X<decrypt> X<cryptography> X<passwd> X<encrypt> |
2426 | 2386 | |
2427 | 2387 | =for Pod::Functions one-way passwd-style encryption |
2428 | 2388 | |
2429 | 2389 | =begin original |
2430 | 2390 | |
2431 | 2391 | Creates a digest string exactly like the crypt(3) function in the C |
2432 | 2392 | library (assuming that you actually have a version there that has not |
2433 | 2393 | been extirpated as a potential munition). |
2434 | 2394 | |
2435 | 2395 | =end original |
2436 | 2396 | |
2437 | 2397 | C ライブラリの crypt(3) 関数と全く同じように、ダイジェスト文字列を |
2438 | 2398 | 作成します(一時的な必需品として、まだ絶滅していないバージョンを |
2439 | 2399 | 持っていると仮定しています)。 |
2440 | 2400 | |
2441 | 2401 | =begin original |
2442 | 2402 | |
2443 | 2403 | crypt() is a one-way hash function. The PLAINTEXT and SALT are turned |
2444 | 2404 | into a short string, called a digest, which is returned. The same |
2445 | 2405 | PLAINTEXT and SALT will always return the same string, but there is no |
2446 | 2406 | (known) way to get the original PLAINTEXT from the hash. Small |
2447 | 2407 | changes in the PLAINTEXT or SALT will result in large changes in the |
2448 | 2408 | digest. |
2449 | 2409 | |
2450 | 2410 | =end original |
2451 | 2411 | |
2452 | 2412 | crypt() は一方向ハッシュ関数です。 |
2453 | 2413 | PLAINTEXT と SALT はダイジェストと呼ばれる短い文字列に変えられて、 |
2454 | 2414 | それが返されます。 |
2455 | 2415 | PLAINTEXT と SALT が同じ場合は常に同じ文字列を返しますが、ハッシュから |
2456 | 2416 | 元の PLAINTEXT を得る(既知の)方法はありません。 |
2457 | 2417 | PLAINTEXT や SALT を少し変更してもダイジェストは大きく変更されます。 |
2458 | 2418 | |
2459 | 2419 | =begin original |
2460 | 2420 | |
2461 | 2421 | There is no decrypt function. This function isn't all that useful for |
2462 | 2422 | cryptography (for that, look for F<Crypt> modules on your nearby CPAN |
2463 | 2423 | mirror) and the name "crypt" is a bit of a misnomer. Instead it is |
2464 | 2424 | primarily used to check if two pieces of text are the same without |
2465 | 2425 | having to transmit or store the text itself. An example is checking |
2466 | 2426 | if a correct password is given. The digest of the password is stored, |
2467 | 2427 | not the password itself. The user types in a password that is |
2468 | 2428 | crypt()'d with the same salt as the stored digest. If the two digests |
2469 | 2429 | match, the password is correct. |
2470 | 2430 | |
2471 | 2431 | =end original |
2472 | 2432 | |
2473 | 2433 | 復号化関数はありません。 |
2474 | 2434 | この関数は暗号化のためにはまったく役に立ちません(このためには、 |
2475 | 2435 | お近くの CPAN ミラーで F<Crypt> モジュールを探してください)ので、 |
2476 | 2436 | "crypt" という名前は少し間違った名前です。 |
2477 | 2437 | その代わりに、一般的には二つのテキスト片が同じかどうかをテキストそのものを |
2478 | 2438 | 転送したり保管したりせずにチェックするために使います。 |
2479 | 2439 | 例としては、正しいパスワードが与えられたかどうかをチェックがあります。 |
2480 | 2440 | パスワード自身ではなく、パスワードのダイジェストが保管されます。 |
2481 | 2441 | ユーザーがパスワードを入力すると、保管されているダイジェストと同じ |
2482 | 2442 | salt で crypt() します。 |
2483 | 2443 | 二つのダイジェストが同じなら、パスワードは正しいです。 |
2484 | 2444 | |
2485 | 2445 | =begin original |
2486 | 2446 | |
2487 | 2447 | When verifying an existing digest string you should use the digest as |
2488 | 2448 | the salt (like C<crypt($plain, $digest) eq $digest>). The SALT used |
2489 | 2449 | to create the digest is visible as part of the digest. This ensures |
2490 | 2450 | crypt() will hash the new string with the same salt as the digest. |
2491 | 2451 | This allows your code to work with the standard L<crypt|/crypt> and |
2492 | 2452 | with more exotic implementations. In other words, assume |
2493 | 2453 | nothing about the returned string itself nor about how many bytes |
2494 | 2454 | of SALT may matter. |
2495 | 2455 | |
2496 | 2456 | =end original |
2497 | 2457 | |
2498 | 2458 | すでにあるダイジェスト文字列を検証するには、ダイジェストを |
2499 | 2459 | (C<crypt($plain, $digest) eq $digest> のようにして)salt として使います。 |
2500 | 2460 | ダイジェストを作るのに使われた SALT はダイジェストの一部として見えます。 |
2501 | 2461 | これにより、crypt() は同じ salt で新しい文字列をダイジェストとして |
2502 | 2462 | ハッシュ化できるようにします。 |
2503 | 2463 | これによって標準的な C<crypt|/crypt> や、より風変わりな実装でも動作します。 |
2504 | 2464 | 言い換えると、返される文字列や、SALT が何バイトあるかといったことに対して、 |
2505 | 2465 | どのような仮定もしてはいけません。 |
2506 | 2466 | |
2507 | 2467 | =begin original |
2508 | 2468 | |
2509 | 2469 | Traditionally the result is a string of 13 bytes: two first bytes of |
2510 | 2470 | the salt, followed by 11 bytes from the set C<[./0-9A-Za-z]>, and only |
2511 | 2471 | the first eight bytes of PLAINTEXT mattered. But alternative |
2512 | 2472 | hashing schemes (like MD5), higher level security schemes (like C2), |
2513 | 2473 | and implementations on non-Unix platforms may produce different |
2514 | 2474 | strings. |
2515 | 2475 | |
2516 | 2476 | =end original |
2517 | 2477 | |
2518 | 2478 | 伝統的には結果は 13 バイトの文字列です: 最初の 2 バイトは salt、引き続いて |
2519 | 2479 | 集合 C<[./0-9A-Za-z]> からの 11 バイトで、PLAINTEXT の最初の |
2520 | 2480 | 8 バイトだけが意味があります。 |
2521 | 2481 | しかし、(MD5 のように) 異なったハッシュ手法、 |
2522 | 2482 | (C2 のような) 高レベルセキュリティ手法、非 Unix プラットフォームでの |
2523 | 2483 | 実装などでは異なった文字列が生成されることがあります。 |
2524 | 2484 | |
2525 | 2485 | =begin original |
2526 | 2486 | |
2527 | 2487 | When choosing a new salt create a random two character string whose |
2528 | 2488 | characters come from the set C<[./0-9A-Za-z]> (like C<join '', ('.', |
2529 | 2489 | '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]>). This set of |
2530 | 2490 | characters is just a recommendation; the characters allowed in |
2531 | 2491 | the salt depend solely on your system's crypt library, and Perl can't |
2532 | 2492 | restrict what salts C<crypt()> accepts. |
2533 | 2493 | |
2534 | 2494 | =end original |
2535 | 2495 | |
2536 | 2496 | 新しい salt を選択する場合は、集合 C<[./0-9A-Za-z]> から |
2537 | (C<join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]> の | |
2497 | (C<join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]> のようにして) | |
2538 | ||
2498 | ランダムに2 つの文字を選びます。 | |
2539 | 2499 | この文字集合は単なる推薦です; salt として許される文字はシステムの暗号化 |
2540 | 2500 | ライブラリだけに依存し、Perl は C<crypt()> がどのような salt を受け付けるかに |
2541 | 2501 | ついて制限しません。 |
2542 | 2502 | |
2543 | 2503 | =begin original |
2544 | 2504 | |
2545 | 2505 | Here's an example that makes sure that whoever runs this program knows |
2546 | 2506 | their password: |
2547 | 2507 | |
2548 | 2508 | =end original |
2549 | 2509 | |
2550 | 2510 | プログラムを実行する人が、 |
2551 | 2511 | 自分のパスワードを知っていることを確認する例です: |
2552 | 2512 | |
2553 | 2513 | $pwd = (getpwuid($<))[1]; |
2554 | 2514 | |
2555 | 2515 | system "stty -echo"; |
2556 | 2516 | print "Password: "; |
2557 | 2517 | chomp($word = <STDIN>); |
2558 | 2518 | print "\n"; |
2559 | 2519 | system "stty echo"; |
2560 | 2520 | |
2561 | 2521 | if (crypt($word, $pwd) ne $pwd) { |
2562 | 2522 | die "Sorry...\n"; |
2563 | 2523 | } else { |
2564 | 2524 | print "ok\n"; |
2565 | 2525 | } |
2566 | 2526 | |
2567 | 2527 | =begin original |
2568 | 2528 | |
2569 | 2529 | Of course, typing in your own password to whoever asks you |
2570 | 2530 | for it is unwise. |
2571 | 2531 | |
2572 | 2532 | =end original |
2573 | 2533 | |
2574 | 2534 | もちろん、自分自身のパスワードを誰にでも入力するのは賢明ではありません。 |
2575 | 2535 | |
2576 | 2536 | =begin original |
2577 | 2537 | |
2578 | 2538 | The L<crypt|/crypt> function is unsuitable for hashing large quantities |
2579 | 2539 | of data, not least of all because you can't get the information |
2580 | 2540 | back. Look at the L<Digest> module for more robust algorithms. |
2581 | 2541 | |
2582 | 2542 | =end original |
2583 | 2543 | |
2584 | 2544 | L<crypt|/crypt> 関数は大量のデータのハッシュ化には向いていません; これは |
2585 | 2545 | 情報を戻せないという理由だけではありません。 |
2586 | 2546 | より頑強なアルゴリズムについては L<Digest> モジュールを参照してください。 |
2587 | 2547 | |
2588 | 2548 | =begin original |
2589 | 2549 | |
2590 | 2550 | If using crypt() on a Unicode string (which I<potentially> has |
2591 | 2551 | characters with codepoints above 255), Perl tries to make sense |
2592 | 2552 | of the situation by trying to downgrade (a copy of) |
2593 | 2553 | the string back to an eight-bit byte string before calling crypt() |
2594 | 2554 | (on that copy). If that works, good. If not, crypt() dies with |
2595 | 2555 | C<Wide character in crypt>. |
2596 | 2556 | |
2597 | 2557 | =end original |
2598 | 2558 | |
2599 | 2559 | Unicode 文字列(I<潜在的には> 255 を越えるコードポイントを持つ文字を |
2600 | 2560 | 含みます)に crypt() を使った場合、Perl は crypt() を呼び出す前に与えられた |
2601 | 2561 | 文字列を8 ビットバイト文字列にダウングレードする(文字列のコピーを作る) |
2602 | 2562 | ことで状況のつじつまを合わせようとします。 |
2603 | 2563 | うまく動けば、それでよし。 |
2604 | 2564 | 動かなければ、crypt() は C<Wide character in crypt> というメッセージと共に |
2605 | 2565 | die します。 |
2606 | 2566 | |
2607 | 2567 | =begin original |
2608 | 2568 | |
2609 | 2569 | Portability issues: L<perlport/crypt>. |
2610 | 2570 | |
2611 | 2571 | =end original |
2612 | 2572 | |
2613 | 2573 | 移植性の問題: L<perlport/crypt>。 |
2614 | 2574 | |
2615 | 2575 | =item dbmclose HASH |
2616 | 2576 | X<dbmclose> |
2617 | 2577 | |
2618 | 2578 | =for Pod::Functions breaks binding on a tied dbm file |
2619 | 2579 | |
2620 | 2580 | =begin original |
2621 | 2581 | |
2622 | 2582 | [This function has been largely superseded by the C<untie> function.] |
2623 | 2583 | |
2624 | 2584 | =end original |
2625 | 2585 | |
2626 | 2586 | [この関数は、C<untie> 関数に大きくとって代わられました。] |
2627 | 2587 | |
2628 | 2588 | =begin original |
2629 | 2589 | |
2630 | 2590 | Breaks the binding between a DBM file and a hash. |
2631 | 2591 | |
2632 | 2592 | =end original |
2633 | 2593 | |
2634 | 2594 | DBM ファイルとハッシュの連結をはずします。 |
2635 | 2595 | |
2636 | 2596 | =begin original |
2637 | 2597 | |
2638 | 2598 | Portability issues: L<perlport/dbmclose>. |
2639 | 2599 | |
2640 | 2600 | =end original |
2641 | 2601 | |
2642 | 2602 | 移植性の問題: L<perlport/dbmclose>。 |
2643 | 2603 | |
2644 | 2604 | =item dbmopen HASH,DBNAME,MASK |
2645 | 2605 | X<dbmopen> X<dbm> X<ndbm> X<sdbm> X<gdbm> |
2646 | 2606 | |
2647 | 2607 | =for Pod::Functions create binding on a tied dbm file |
2648 | 2608 | |
2649 | 2609 | =begin original |
2650 | 2610 | |
2651 | 2611 | [This function has been largely superseded by the |
2652 | 2612 | L<tie|/tie VARIABLE,CLASSNAME,LIST> function.] |
2653 | 2613 | |
2654 | 2614 | =end original |
2655 | 2615 | |
2656 | 2616 | [この関数は、L<tie|/tie VARIABLE,CLASSNAME,LIST> 関数に |
2657 | 2617 | 大きくとって代わられました。] |
2658 | 2618 | |
2659 | 2619 | =begin original |
2660 | 2620 | |
2661 | 2621 | This binds a dbm(3), ndbm(3), sdbm(3), gdbm(3), or Berkeley DB file to a |
2662 | 2622 | hash. HASH is the name of the hash. (Unlike normal C<open>, the first |
2663 | 2623 | argument is I<not> a filehandle, even though it looks like one). DBNAME |
2664 | 2624 | is the name of the database (without the F<.dir> or F<.pag> extension if |
2665 | 2625 | any). If the database does not exist, it is created with protection |
2666 | 2626 | specified by MASK (as modified by the C<umask>). To prevent creation of |
2667 | 2627 | the database if it doesn't exist, you may specify a MODE |
2668 | 2628 | of 0, and the function will return a false value if it |
2669 | 2629 | can't find an existing database. If your system supports |
2670 | 2630 | only the older DBM functions, you may make only one C<dbmopen> call in your |
2671 | 2631 | program. In older versions of Perl, if your system had neither DBM nor |
2672 | 2632 | ndbm, calling C<dbmopen> produced a fatal error; it now falls back to |
2673 | 2633 | sdbm(3). |
2674 | 2634 | |
2675 | 2635 | =end original |
2676 | 2636 | |
2677 | 2637 | dbm(3), ndbm(3), sdbm(3), gdbm(3) ファイルまたは Berkeley DB ファイルを |
2678 | 2638 | 連想配列に結び付けます。 |
2679 | 2639 | HASH は、その連想配列の名前です。 |
2680 | 2640 | (普通の C<open> とは違って、最初の引数はファイルハンドル I<ではありません>; |
2681 | 2641 | まあ、似たようなものですが)。 |
2682 | 2642 | DBNAME は、データベースの名前です (拡張子の .dir や .pag はもしあっても |
2683 | 2643 | つけません)。 |
2684 | 2644 | データベースが存在しなければ、MODE MASK (を C<umask> で修正したもの) で |
2685 | 2645 | 指定されたモードで作られます。 |
2686 | 2646 | 存在しないときにデータベースを作成しないようにするには、MODE に 0 を |
2687 | 2647 | 設定でき、データベースを見つけられなかった場合は関数は偽を返します。 |
2688 | 2648 | 古い DBM 関数のみをサポートしているシステムでは、プログラム中で 1 度だけ |
2689 | 2649 | dbmopen() を実行することができます。 |
2690 | 2650 | 昔のバージョンの Perl では、DBM も ndbm も持っていないシステムでは、 |
2691 | 2651 | dbmopen() を呼び出すと致命的エラーになります; 現在では sdbm(3) に |
2692 | 2652 | フォールバックします。 |
2693 | 2653 | |
2694 | 2654 | =begin original |
2695 | 2655 | |
2696 | 2656 | If you don't have write access to the DBM file, you can only read hash |
2697 | 2657 | variables, not set them. If you want to test whether you can write, |
2698 | 2658 | either use file tests or try setting a dummy hash entry inside an C<eval> |
2699 | 2659 | to trap the error. |
2700 | 2660 | |
2701 | 2661 | =end original |
2702 | 2662 | |
2703 | 2663 | DBM ファイルに対して、書き込み権が無いときには、ハッシュ |
2704 | 2664 | 配列を読みだすことだけができ、設定することはできません。 |
2705 | 2665 | 書けるか否かを調べたい場合には、ファイルテスト |
2706 | 2666 | 演算子を使うか、エラーをトラップするための C<eval> の中で、 |
2707 | 2667 | ダミーのハッシュエントリを設定してみることになります。 |
2708 | 2668 | |
2709 | 2669 | =begin original |
2710 | 2670 | |
2711 | 2671 | Note that functions such as C<keys> and C<values> may return huge lists |
2712 | 2672 | when used on large DBM files. You may prefer to use the C<each> |
2713 | 2673 | function to iterate over large DBM files. Example: |
2714 | 2674 | |
2715 | 2675 | =end original |
2716 | 2676 | |
2717 | 2677 | 大きな DBM ファイルを扱うときには、C<keys> や C<values> のような関数は、 |
2718 | 2678 | 巨大なリストを返します。 |
2719 | 2679 | 大きな DBM ファイルでは、C<each> 関数を使って繰り返しを行なった方が |
2720 | 2680 | 良いかもしれません。 |
2721 | 2681 | 例: |
2722 | 2682 | |
2723 | 2683 | # print out history file offsets |
2724 | 2684 | dbmopen(%HIST,'/usr/lib/news/history',0666); |
2725 | 2685 | while (($key,$val) = each %HIST) { |
2726 | 2686 | print $key, ' = ', unpack('L',$val), "\n"; |
2727 | 2687 | } |
2728 | 2688 | dbmclose(%HIST); |
2729 | 2689 | |
2730 | 2690 | =begin original |
2731 | 2691 | |
2732 | 2692 | See also L<AnyDBM_File> for a more general description of the pros and |
2733 | 2693 | cons of the various dbm approaches, as well as L<DB_File> for a particularly |
2734 | 2694 | rich implementation. |
2735 | 2695 | |
2736 | 2696 | =end original |
2737 | 2697 | |
2738 | 2698 | 様々な dbm 手法に対する利点欠点に関するより一般的な記述および |
2739 | 2699 | 特にリッチな実装である L<DB_File> に関しては |
2740 | 2700 | L<AnyDBM_File> も参照してください。 |
2741 | 2701 | |
2742 | 2702 | =begin original |
2743 | 2703 | |
2744 | 2704 | You can control which DBM library you use by loading that library |
2745 | 2705 | before you call dbmopen(): |
2746 | 2706 | |
2747 | 2707 | =end original |
2748 | 2708 | |
2749 | 2709 | dbmopen() を呼び出す前にライブラリを読み込むことで、 |
2750 | 2710 | どの DBM ライブラリを使うかを制御できます: |
2751 | 2711 | |
2752 | 2712 | use DB_File; |
2753 | 2713 | dbmopen(%NS_Hist, "$ENV{HOME}/.netscape/history.db") |
2754 | 2714 | or die "Can't open netscape history file: $!"; |
2755 | 2715 | |
2756 | 2716 | =begin original |
2757 | 2717 | |
2758 | 2718 | Portability issues: L<perlport/dbmopen>. |
2759 | 2719 | |
2760 | 2720 | =end original |
2761 | 2721 | |
2762 | 2722 | 移植性の問題: L<perlport/dbmopen>。 |
2763 | 2723 | |
2764 | 2724 | =item defined EXPR |
2765 | 2725 | X<defined> X<undef> X<undefined> |
2766 | 2726 | |
2767 | 2727 | =item defined |
2768 | 2728 | |
2769 | 2729 | =for Pod::Functions test whether a value, variable, or function is defined |
2770 | 2730 | |
2771 | 2731 | =begin original |
2772 | 2732 | |
2773 | 2733 | Returns a Boolean value telling whether EXPR has a value other than |
2774 | 2734 | the undefined value C<undef>. If EXPR is not present, C<$_> is |
2775 | 2735 | checked. |
2776 | 2736 | |
2777 | 2737 | =end original |
2778 | 2738 | |
2779 | 2739 | 左辺値 EXPR が未定義値 C<undef> 以外の値を持つか否かを示す、ブール値を |
2780 | 2740 | 返します。 |
2781 | 2741 | EXPR がない場合は、C<$_> がチェックされます。 |
2782 | 2742 | |
2783 | 2743 | =begin original |
2784 | 2744 | |
2785 | 2745 | Many operations return C<undef> to indicate failure, end of file, |
2786 | 2746 | system error, uninitialized variable, and other exceptional |
2787 | 2747 | conditions. This function allows you to distinguish C<undef> from |
2788 | 2748 | other values. (A simple Boolean test will not distinguish among |
2789 | 2749 | C<undef>, zero, the empty string, and C<"0">, which are all equally |
2790 | 2750 | false.) Note that since C<undef> is a valid scalar, its presence |
2791 | 2751 | doesn't I<necessarily> indicate an exceptional condition: C<pop> |
2792 | 2752 | returns C<undef> when its argument is an empty array, I<or> when the |
2793 | 2753 | element to return happens to be C<undef>. |
2794 | 2754 | |
2795 | 2755 | =end original |
2796 | 2756 | |
2797 | 2757 | 多くの演算子が、EOF や未初期化変数、システムエラーといった、 |
2798 | 2758 | 例外的な条件で C<undef> を返すようになっています。 |
2799 | 2759 | この関数は、他の値と C<undef> とを区別するために使えます。 |
2800 | 2760 | (単純な真偽値テストでは、C<undef>、0、C<"0"> のいずれも偽を返すので、 |
2801 | 2761 | 区別することができません。) |
2802 | 2762 | C<undef> は有効なスカラ値なので、その存在が I<必ずしも> |
2803 | 2763 | 例外的な状況を表すとは限らないということに注意してください: |
2804 | 2764 | C<pop> は引数が空の配列だったときに C<undef> を返しますが、 |
2805 | 2765 | I<あるいは> 返すべき要素がたまたま C<undef> だったのかもしれません。 |
2806 | 2766 | |
2807 | 2767 | =begin original |
2808 | 2768 | |
2809 | 2769 | You may also use C<defined(&func)> to check whether subroutine C<&func> |
2810 | 2770 | has ever been defined. The return value is unaffected by any forward |
2811 | 2771 | declarations of C<&func>. A subroutine that is not defined |
2812 | 2772 | may still be callable: its package may have an C<AUTOLOAD> method that |
2813 | 2773 | makes it spring into existence the first time that it is called; see |
2814 | 2774 | L<perlsub>. |
2815 | 2775 | |
2816 | 2776 | =end original |
2817 | 2777 | |
2818 | 2778 | C<defined(&func)> とすることでサブルーチン C<&func> の存在を、 |
2819 | 2779 | 確かめることもできます。 |
2820 | 2780 | 返り値は C<&func> の前方定義には影響されません。 |
2821 | 2781 | 定義されていないサブルーチンも呼び出し可能です: |
2822 | 2782 | 最初に呼び出されたときに存在するようにするための |
2823 | 2783 | C<AUTOLOAD> メソッドを持ったパッケージかもしれません; |
2824 | 2784 | L<perlsub> を参照してください。 |
2825 | 2785 | |
2826 | 2786 | =begin original |
2827 | 2787 | |
2828 | 2788 | Use of C<defined> on aggregates (hashes and arrays) is deprecated. It |
2829 | 2789 | used to report whether memory for that aggregate had ever been |
2830 | 2790 | allocated. This behavior may disappear in future versions of Perl. |
2831 | 2791 | You should instead use a simple test for size: |
2832 | 2792 | |
2833 | 2793 | =end original |
2834 | 2794 | |
2835 | 2795 | 集合(ハッシュや配列)への C<defined> の使用は非推奨です。 |
2836 | 2796 | これはその集合にメモリが割り当てられたかを報告するのに |
2837 | 2797 | 用いられていました。 |
2838 | 2798 | この振る舞いは将来のバージョンの Perl では消滅するかもしれません。 |
2839 | 2799 | 代わりにサイズに対する簡単なテストを使うべきです。 |
2840 | 2800 | |
2841 | 2801 | if (@an_array) { print "has array elements\n" } |
2842 | 2802 | if (%a_hash) { print "has hash members\n" } |
2843 | 2803 | |
2844 | 2804 | =begin original |
2845 | 2805 | |
2846 | 2806 | When used on a hash element, it tells you whether the value is defined, |
2847 | 2807 | not whether the key exists in the hash. Use L</exists> for the latter |
2848 | 2808 | purpose. |
2849 | 2809 | |
2850 | 2810 | =end original |
2851 | 2811 | |
2852 | 2812 | ハッシュの要素に対して用いると、value が定義されているか否かを |
2853 | 2813 | 返すものであって、ハッシュに key が存在するか否かを返すのではありません。 |
2854 | 2814 | この用途には、L</exists> を使ってください。 |
2855 | 2815 | |
2856 | 2816 | =begin original |
2857 | 2817 | |
2858 | 2818 | Examples: |
2859 | 2819 | |
2860 | 2820 | =end original |
2861 | 2821 | |
2862 | 2822 | 例: |
2863 | 2823 | |
2864 | 2824 | print if defined $switch{D}; |
2865 | 2825 | print "$val\n" while defined($val = pop(@ary)); |
2866 | 2826 | die "Can't readlink $sym: $!" |
2867 | 2827 | unless defined($value = readlink $sym); |
2868 | 2828 | sub foo { defined &$bar ? &$bar(@_) : die "No bar"; } |
2869 | 2829 | $debugging = 0 unless defined $debugging; |
2870 | 2830 | |
2871 | 2831 | =begin original |
2872 | 2832 | |
2873 | 2833 | Note: Many folks tend to overuse C<defined> and are then surprised to |
2874 | 2834 | discover that the number C<0> and C<""> (the zero-length string) are, in fact, |
2875 | 2835 | defined values. For example, if you say |
2876 | 2836 | |
2877 | 2837 | =end original |
2878 | 2838 | |
2879 | 2839 | 注意: 多くの人々が C<defined> を使いすぎて、C<0> と C<"">(空文字列) が |
2880 | 2840 | 実際のところ定義された値であることに驚くようです。 |
2881 | 2841 | 例えば、以下のように書くと: |
2882 | 2842 | |
2883 | 2843 | "ab" =~ /a(.*)b/; |
2884 | 2844 | |
2885 | 2845 | =begin original |
2886 | 2846 | |
2887 | 2847 | The pattern match succeeds and C<$1> is defined, although it |
2888 | 2848 | matched "nothing". It didn't really fail to match anything. Rather, it |
2889 | 2849 | matched something that happened to be zero characters long. This is all |
2890 | 2850 | very above-board and honest. When a function returns an undefined value, |
2891 | 2851 | it's an admission that it couldn't give you an honest answer. So you |
2892 | 2852 | should use C<defined> only when questioning the integrity of what |
2893 | 2853 | you're trying to do. At other times, a simple comparison to C<0> or C<""> is |
2894 | 2854 | what you want. |
2895 | 2855 | |
2896 | 2856 | =end original |
2897 | 2857 | |
2898 | 2858 | パターンマッチングが成功し、C<$1> が定義されても、実際には |
2899 | 2859 | 「なし」にマッチしています。 |
2900 | 2860 | しかしこれは何にもマッチしていないわけではありません。 |
2901 | 2861 | 何かにはマッチしているのですが、たまたまそれが長さ 0 だっただけです。 |
2902 | 2862 | これは非常に率直で正直なことです。 |
2903 | 2863 | 関数が未定義値を返すとき、正直な答えを返すことができないことを |
2904 | 2864 | 告白しています。 |
2905 | 2865 | ですので、あなたが自分がしようとしていることの完全性を確認するときにだけ |
2906 | 2866 | C<defined> を使うべきです。 |
2907 | 2867 | その他の場合では、単に C<0> または C<""> と比較するというのがあなたの |
2908 | 2868 | 求めているものです。 |
2909 | 2869 | |
2910 | 2870 | =begin original |
2911 | 2871 | |
2912 | 2872 | See also L</undef>, L</exists>, L</ref>. |
2913 | 2873 | |
2914 | 2874 | =end original |
2915 | 2875 | |
2916 | 2876 | L</undef>, L</exists>, L</ref> も参照してください。 |
2917 | 2877 | |
2918 | 2878 | =item delete EXPR |
2919 | 2879 | X<delete> |
2920 | 2880 | |
2921 | 2881 | =for Pod::Functions deletes a value from a hash |
2922 | 2882 | |
2923 | 2883 | =begin original |
2924 | 2884 | |
2925 | 2885 | Given an expression that specifies an element or slice of a hash, C<delete> |
2926 | 2886 | deletes the specified elements from that hash so that exists() on that element |
2927 | 2887 | no longer returns true. Setting a hash element to the undefined value does |
2928 | 2888 | not remove its key, but deleting it does; see L</exists>. |
2929 | 2889 | |
2930 | 2890 | =end original |
2931 | 2891 | |
2932 | 2892 | ハッシュの要素やスライスを指定する式を取り、C<delete> は |
2933 | 2893 | 指定された要素をハッシュから削除するので、 |
2934 | 2894 | その要素に対する exists() はもはや真を返さなくなります。 |
2935 | 2895 | ハッシュ要素に未定義値をセットしてもそのキーは削除されませんが、 |
2936 | 2896 | delete では削除されます; L</exists> を参照してください。 |
2937 | 2897 | |
2938 | 2898 | =begin original |
2939 | 2899 | |
2940 | 2900 | In list context, returns the value or values deleted, or the last such |
2941 | 2901 | element in scalar context. The return list's length always matches that of |
2942 | 2902 | the argument list: deleting non-existent elements returns the undefined value |
2943 | 2903 | in their corresponding positions. |
2944 | 2904 | |
2945 | 2905 | =end original |
2946 | 2906 | |
2947 | 2907 | リストコンテキストでは削除された要素を返し、スカラコンテキストでは |
2948 | 2908 | 削除された要素のうち最後のものを返します。 |
2949 | 2909 | 返されたリストの長さは常に引数リストの長さと一致します: |
2950 | 2910 | 存在しない要素を削除すると、対応する位置に未定義値をセットして返します。 |
2951 | 2911 | |
2952 | 2912 | =begin original |
2953 | 2913 | |
2954 | 2914 | delete() may also be used on arrays and array slices, but its behavior is less |
2955 | 2915 | straightforward. Although exists() will return false for deleted entries, |
2956 | 2916 | deleting array elements never changes indices of existing values; use shift() |
2957 | or splice() for that. However, if a | |
2917 | or splice() for that. However, if all deleted elements fall at the end of an | |
2958 | 2918 | array, the array's size shrinks to the position of the highest element that |
2959 | still tests true for exists(), or to 0 if none do. | |
2919 | still tests true for exists(), or to 0 if none do. | |
2960 | array won't have trailing nonexistent elements after a delete. | |
2961 | 2920 | |
2962 | 2921 | =end original |
2963 | 2922 | |
2964 | 2923 | delete() は配列や配列のスライスに対しても使えますが、その振る舞いは |
2965 | 2924 | あまり直感的ではありません。 |
2966 | 2925 | 削除されたエントリに対しては exists() は偽を返しますが、 |
2967 | 2926 | 配列要素を削除しても、存在する値の添え字は変わりません; このためには |
2968 | 2927 | shift() や splice() を使ってください。 |
2969 | しかし、削除された要素が配列の末尾であった場合、配列のサイズは | |
2928 | しかし、全ての削除された要素が配列の末尾であった場合、配列のサイズは | |
2970 | 2929 | exists() が真となる最大位置の要素(それがない場合は 0)に切り詰められます。 |
2971 | 言い換えると、delete の後には配列の末尾に値のない要素はありません。 | |
2972 | 2930 | |
2973 | 2931 | =begin original |
2974 | 2932 | |
2975 | 2933 | B<WARNING:> Calling delete on array values is deprecated and likely to |
2976 | 2934 | be removed in a future version of Perl. |
2977 | 2935 | |
2978 | 2936 | =end original |
2979 | 2937 | |
2980 | 2938 | B<警告:> 配列の値に対して delete を呼び出すことは非推奨で、将来の |
2981 | 2939 | バージョンの Perl では削除される予定です。 |
2982 | 2940 | |
2983 | 2941 | =begin original |
2984 | 2942 | |
2985 | 2943 | Deleting from C<%ENV> modifies the environment. Deleting from a hash tied to |
2986 | 2944 | a DBM file deletes the entry from the DBM file. Deleting from a C<tied> hash |
2987 | 2945 | or array may not necessarily return anything; it depends on the implementation |
2988 | 2946 | of the C<tied> package's DELETE method, which may do whatever it pleases. |
2989 | 2947 | |
2990 | 2948 | =end original |
2991 | 2949 | |
2992 | 2950 | C<%ENV> から削除を行なうと、実際に環境変数を変更します。 |
2993 | 2951 | DBM ファイルに tie された配列からの削除は、その DBM ファイルからエントリを |
2994 | 2952 | 削除します。 |
2995 | 2953 | しかし、C<tie> されたハッシュや配列からの削除は、 |
2996 | 2954 | 値を返すとは限りません; これは C<tie> されたパッケージの DELETE |
2997 | 2955 | メソッドの実装に依存するので、どんなことでも起こります。 |
2998 | 2956 | |
2999 | 2957 | =begin original |
3000 | 2958 | |
3001 | 2959 | The C<delete local EXPR> construct localizes the deletion to the current |
3002 | 2960 | block at run time. Until the block exits, elements locally deleted |
3003 | 2961 | temporarily no longer exist. See L<perlsub/"Localized deletion of elements |
3004 | 2962 | of composite types">. |
3005 | 2963 | |
3006 | 2964 | =end original |
3007 | 2965 | |
3008 | 2966 | C<delete local EXPR> 構文は、現在のブロックの削除を実行時にローカル化します。 |
3009 | 2967 | ブロックから出るまで、ローカルで削除された要素は存在しなくなります。 |
3010 | 2968 | L<perlsub/"Localized deletion of elements of composite types"> を |
3011 | 2969 | 参照してください。 |
3012 | 2970 | |
3013 | 2971 | %hash = (foo => 11, bar => 22, baz => 33); |
3014 | $scalar = delete $hash{foo}; # $scalar is 11 | |
2972 | $scalar = delete $hash{foo}; # $scalar is 11 | |
3015 | $scalar = delete @hash{qw(foo bar)}; # $scalar is 22 | |
2973 | $scalar = delete @hash{qw(foo bar)}; # $scalar is 22 | |
3016 | @array = delete @hash{qw(foo baz)}; # @array is (undef,33) | |
2974 | @array = delete @hash{qw(foo bar baz)}; # @array is (undef,undef,33) | |
3017 | 2975 | |
3018 | 2976 | =begin original |
3019 | 2977 | |
3020 | 2978 | The following (inefficiently) deletes all the values of %HASH and @ARRAY: |
3021 | 2979 | |
3022 | 2980 | =end original |
3023 | 2981 | |
3024 | 2982 | 以下は、%HASH と @ARRAY のすべての値を(非効率的に)削除します: |
3025 | 2983 | |
3026 | 2984 | foreach $key (keys %HASH) { |
3027 | 2985 | delete $HASH{$key}; |
3028 | 2986 | } |
3029 | 2987 | |
3030 | 2988 | foreach $index (0 .. $#ARRAY) { |
3031 | 2989 | delete $ARRAY[$index]; |
3032 | 2990 | } |
3033 | 2991 | |
3034 | 2992 | =begin original |
3035 | 2993 | |
3036 | 2994 | And so do these: |
3037 | 2995 | |
3038 | 2996 | =end original |
3039 | 2997 | |
3040 | 2998 | そして以下のようにもできます: |
3041 | 2999 | |
3042 | 3000 | delete @HASH{keys %HASH}; |
3043 | 3001 | |
3044 | 3002 | delete @ARRAY[0 .. $#ARRAY]; |
3045 | 3003 | |
3046 | 3004 | =begin original |
3047 | 3005 | |
3048 | 3006 | But both are slower than assigning the empty list |
3049 | 3007 | or undefining %HASH or @ARRAY, which is the customary |
3050 | 3008 | way to empty out an aggregate: |
3051 | 3009 | |
3052 | 3010 | =end original |
3053 | 3011 | |
3054 | 3012 | しかし、これら二つは両方とも、構造を空にするための慣習的な方法である、 |
3055 | 3013 | 単に空リストを代入するか、%HASH や @ARRAY を |
3056 | 3014 | undef するより遅いです: |
3057 | 3015 | |
3058 | 3016 | %HASH = (); # completely empty %HASH |
3059 | 3017 | undef %HASH; # forget %HASH ever existed |
3060 | 3018 | |
3061 | 3019 | @ARRAY = (); # completely empty @ARRAY |
3062 | 3020 | undef @ARRAY; # forget @ARRAY ever existed |
3063 | 3021 | |
3064 | 3022 | =begin original |
3065 | 3023 | |
3066 | 3024 | The EXPR can be arbitrarily complicated provided its |
3067 | 3025 | final operation is an element or slice of an aggregate: |
3068 | 3026 | |
3069 | 3027 | =end original |
3070 | 3028 | |
3071 | 3029 | 最終的な操作が集合の要素かスライスである限りは、 |
3072 | 3030 | いずれかである限りは、EXPR には任意の複雑な式を置くことができます: |
3073 | 3031 | |
3074 | 3032 | delete $ref->[$x][$y]{$key}; |
3075 | 3033 | delete @{$ref->[$x][$y]}{$key1, $key2, @morekeys}; |
3076 | 3034 | |
3077 | 3035 | delete $ref->[$x][$y][$index]; |
3078 | 3036 | delete @{$ref->[$x][$y]}[$index1, $index2, @moreindices]; |
3079 | 3037 | |
3080 | 3038 | =item die LIST |
3081 | 3039 | X<die> X<throw> X<exception> X<raise> X<$@> X<abort> |
3082 | 3040 | |
3083 | 3041 | =for Pod::Functions raise an exception or bail out |
3084 | 3042 | |
3085 | 3043 | =begin original |
3086 | 3044 | |
3087 | 3045 | C<die> raises an exception. Inside an C<eval> the error message is stuffed |
3088 | 3046 | into C<$@> and the C<eval> is terminated with the undefined value. |
3089 | 3047 | If the exception is outside of all enclosing C<eval>s, then the uncaught |
3090 | 3048 | exception prints LIST to C<STDERR> and exits with a non-zero value. If you |
3091 | 3049 | need to exit the process with a specific exit code, see L</exit>. |
3092 | 3050 | |
3093 | 3051 | =end original |
3094 | 3052 | |
3095 | 3053 | C<die> は例外を発生させます。 |
3096 | 3054 | C<eval> の中で使用すると、エラーメッセージが C<$@> に入り、C<eval> は |
3097 | 3055 | 未定義値を返して終了します。 |
3098 | 3056 | 例外が全ての C<eval> の外側の場合は、捕捉されなかった例外は LIST を |
3099 | 3057 | C<STDERR> に表示して、非 0 の値で終了します。 |
3100 | 3058 | 特定の終了コードでプロセスを終了させる必要がある場合は、L</exit> を |
3101 | 3059 | 参照してください。 |
3102 | 3060 | |
3103 | 3061 | =begin original |
3104 | 3062 | |
3105 | 3063 | Equivalent examples: |
3106 | 3064 | |
3107 | 3065 | =end original |
3108 | 3066 | |
3109 | 3067 | 等価な例: |
3110 | 3068 | |
3111 | 3069 | die "Can't cd to spool: $!\n" unless chdir '/usr/spool/news'; |
3112 | 3070 | chdir '/usr/spool/news' or die "Can't cd to spool: $!\n" |
3113 | 3071 | |
3114 | 3072 | =begin original |
3115 | 3073 | |
3116 | 3074 | If the last element of LIST does not end in a newline, the current |
3117 | 3075 | script line number and input line number (if any) are also printed, |
3118 | 3076 | and a newline is supplied. Note that the "input line number" (also |
3119 | 3077 | known as "chunk") is subject to whatever notion of "line" happens to |
3120 | 3078 | be currently in effect, and is also available as the special variable |
3121 | 3079 | C<$.>. See L<perlvar/"$/"> and L<perlvar/"$.">. |
3122 | 3080 | |
3123 | 3081 | =end original |
3124 | 3082 | |
3125 | 3083 | LIST の最後の要素が改行で終わっていなければ、その時点のスクリプト名と |
3126 | 3084 | スクリプトの行番号、(もしあれば) 入力ファイルの行番号と改行文字が、続けて |
3127 | 3085 | 表示されます。 |
3128 | 3086 | 「入力行番号」("chunk" とも呼ばれます)は「行」という概念が現在有効であると |
3129 | 3087 | 仮定しています; また特殊変数 C<$.> でも利用可能です。 |
3130 | 3088 | L<perlvar/"$/"> と L<perlvar/"$."> も参照してください。 |
3131 | 3089 | |
3132 | 3090 | =begin original |
3133 | 3091 | |
3134 | 3092 | Hint: sometimes appending C<", stopped"> to your message will cause it |
3135 | 3093 | to make better sense when the string C<"at foo line 123"> is appended. |
3136 | 3094 | Suppose you are running script "canasta". |
3137 | 3095 | |
3138 | 3096 | =end original |
3139 | 3097 | |
3140 | 3098 | ヒント: メッセージの最後を C<", stopped"> のようなもので |
3141 | 3099 | 終わるようにしておけば、C<"at foo line 123"> のように |
3142 | 3100 | 追加されて、わかりやすくなります。 |
3143 | 3101 | "canasta" というスクリプトを実行しているとします。 |
3144 | 3102 | |
3145 | 3103 | die "/etc/games is no good"; |
3146 | 3104 | die "/etc/games is no good, stopped"; |
3147 | 3105 | |
3148 | 3106 | =begin original |
3149 | 3107 | |
3150 | 3108 | produce, respectively |
3151 | 3109 | |
3152 | 3110 | =end original |
3153 | 3111 | |
3154 | 3112 | これは、それぞれ以下のように表示します。 |
3155 | 3113 | |
3156 | 3114 | /etc/games is no good at canasta line 123. |
3157 | 3115 | /etc/games is no good, stopped at canasta line 123. |
3158 | 3116 | |
3159 | 3117 | =begin original |
3160 | 3118 | |
3161 | 3119 | If the output is empty and C<$@> already contains a value (typically from a |
3162 | 3120 | previous eval) that value is reused after appending C<"\t...propagated">. |
3163 | 3121 | This is useful for propagating exceptions: |
3164 | 3122 | |
3165 | 3123 | =end original |
3166 | 3124 | |
3167 | 3125 | 出力が空で C<$@> が(典型的には前回の eval で)既に値を持っている場合、 |
3168 | 3126 | 値は C<"\t...propagated"> を追加した後再利用されます。 |
3169 | 3127 | これは例外を伝播させる場合に有効です: |
3170 | 3128 | |
3171 | 3129 | eval { ... }; |
3172 | 3130 | die unless $@ =~ /Expected exception/; |
3173 | 3131 | |
3174 | 3132 | =begin original |
3175 | 3133 | |
3176 | 3134 | If the output is empty and C<$@> contains an object reference that has a |
3177 | 3135 | C<PROPAGATE> method, that method will be called with additional file |
3178 | 3136 | and line number parameters. The return value replaces the value in |
3179 | 3137 | C<$@>; i.e., as if C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >> |
3180 | 3138 | were called. |
3181 | 3139 | |
3182 | 3140 | =end original |
3183 | 3141 | |
3184 | 3142 | 出力が空で、C<$@> が C<PROPAGATE> メソッドを含むオブジェクトへの |
3185 | 3143 | リファレンスを含む場合、このメソッドが追加ファイルと行番号を引数として |
3186 | 3144 | 呼び出されます。 |
3187 | 3145 | 返り値は C<$@> の値を置き換えます; |
3188 | 3146 | つまり、C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >> が |
3189 | 3147 | 呼び出されたかのようになります。 |
3190 | 3148 | |
3191 | 3149 | =begin original |
3192 | 3150 | |
3193 | 3151 | If C<$@> is empty then the string C<"Died"> is used. |
3194 | 3152 | |
3195 | 3153 | =end original |
3196 | 3154 | |
3197 | 3155 | C<$@> が空の場合、C<"Died"> が使われます。 |
3198 | 3156 | |
3199 | 3157 | =begin original |
3200 | 3158 | |
3201 | 3159 | If an uncaught exception results in interpreter exit, the exit code is |
3202 | 3160 | determined from the values of C<$!> and C<$?> with this pseudocode: |
3203 | 3161 | |
3204 | 3162 | =end original |
3205 | 3163 | |
3206 | 3164 | 例外が捕捉されないとインタプリタは終了し、終了コードは以下の |
3207 | 3165 | 擬似コードのように、C<$!> と C<$?> の値から決定されます: |
3208 | 3166 | |
3209 | 3167 | exit $! if $!; # errno |
3210 | 3168 | exit $? >> 8 if $? >> 8; # child exit status |
3211 | 3169 | exit 255; # last resort |
3212 | 3170 | |
3213 | 3171 | =begin original |
3214 | 3172 | |
3215 | 3173 | The intent is to squeeze as much possible information about the likely cause |
3216 | 3174 | into the limited space of the system exit |
3217 | 3175 | code. However, as C<$!> is the value |
3218 | 3176 | of C's C<errno>, which can be set by any system call, this means that the value |
3219 | 3177 | of the exit code used by C<die> can be non-predictable, so should not be relied |
3220 | 3178 | upon, other than to be non-zero. |
3221 | 3179 | |
3222 | 3180 | =end original |
3223 | 3181 | |
3224 | 3182 | この意図は、できるだけ多くの似たような原因に関する情報を、システム終了 |
3225 | 3183 | コードという限られた領域に圧縮することです。 |
3226 | 3184 | しかし、C<$!> はシステムコールによって設定される可能性がある C の |
3227 | 3185 | C<errno> の値であり、C<die> によって使われる終了コードの値は |
3228 | 3186 | 予測不能であることを意味するので、非 0 ということ以上にこの値に |
3229 | 3187 | 依存するべきではありません。 |
3230 | 3188 | |
3231 | 3189 | =begin original |
3232 | 3190 | |
3233 | 3191 | You can also call C<die> with a reference argument, and if this is trapped |
3234 | 3192 | within an C<eval>, C<$@> contains that reference. This permits more |
3235 | 3193 | elaborate exception handling using objects that maintain arbitrary state |
3236 | 3194 | about the exception. Such a scheme is sometimes preferable to matching |
3237 | 3195 | particular string values of C<$@> with regular expressions. Because C<$@> |
3238 | 3196 | is a global variable and C<eval> may be used within object implementations, |
3239 | 3197 | be careful that analyzing the error object doesn't replace the reference in |
3240 | 3198 | the global variable. It's easiest to make a local copy of the reference |
3241 | 3199 | before any manipulations. Here's an example: |
3242 | 3200 | |
3243 | 3201 | =end original |
3244 | 3202 | |
3245 | 3203 | die() はリファレンス引数と共に呼び出すこともでき、これが |
3246 | 3204 | eval() 内部でトラップされた場合、C<$@> はそのリファレンスを持ちます。 |
3247 | 3205 | これは、例外の性質について任意の状態を管理するオブジェクトを使った |
3248 | 3206 | より複雑な例外処理の実装を可能にします。 |
3249 | 3207 | このようなスキームは C<$@> の特定の文字列値を正規表現を使って |
3250 | 3208 | マッチングするときに時々好まれます。 |
3251 | 3209 | C<$@> はグローバル変数で、C<eval> はオブジェクト実装の内部で |
3252 | 3210 | 使われることがあるので、エラーオブジェクトの解析はグローバル変数の |
3253 | 3211 | リファレンスを置き換えないことに注意を払わなければなりません。 |
3254 | 3212 | 他の操作をする前にリファレンスのローカルコピーを |
3255 | 3213 | 作るのが一番簡単です。 |
3256 | 3214 | 以下に例を示します: |
3257 | 3215 | |
3258 | 3216 | use Scalar::Util "blessed"; |
3259 | 3217 | |
3260 | 3218 | eval { ... ; die Some::Module::Exception->new( FOO => "bar" ) }; |
3261 | 3219 | if (my $ev_err = $@) { |
3262 | if (blessed($ev_err) | |
3220 | if (blessed($ev_err) && $ev_err->isa("Some::Module::Exception")) { | |
3263 | && $ev_err->isa("Some::Module::Exception")) { | |
3264 | 3221 | # handle Some::Module::Exception |
3265 | 3222 | } |
3266 | 3223 | else { |
3267 | 3224 | # handle all other possible exceptions |
3268 | 3225 | } |
3269 | 3226 | } |
3270 | 3227 | |
3271 | 3228 | =begin original |
3272 | 3229 | |
3273 | 3230 | Because Perl stringifies uncaught exception messages before display, |
3274 | 3231 | you'll probably want to overload stringification operations on |
3275 | 3232 | exception objects. See L<overload> for details about that. |
3276 | 3233 | |
3277 | 3234 | =end original |
3278 | 3235 | |
3279 | 3236 | perl は捕らえられなかった例外のメッセージを表示する前に文字列化するので、 |
3280 | 3237 | このようなカスタム例外オブジェクトの文字列化をオーバーロードしたいと |
3281 | 3238 | 思うかもしれません。 |
3282 | 3239 | これに関する詳細は L<overload> を参照してください。 |
3283 | 3240 | |
3284 | 3241 | =begin original |
3285 | 3242 | |
3286 | 3243 | You can arrange for a callback to be run just before the C<die> |
3287 | 3244 | does its deed, by setting the C<$SIG{__DIE__}> hook. The associated |
3288 | 3245 | handler is called with the error text and can change the error |
3289 | 3246 | message, if it sees fit, by calling C<die> again. See |
3290 | 3247 | L<perlvar/%SIG> for details on setting C<%SIG> entries, and |
3291 | 3248 | L<"eval BLOCK"> for some examples. Although this feature was |
3292 | 3249 | to be run only right before your program was to exit, this is not |
3293 | 3250 | currently so: the C<$SIG{__DIE__}> hook is currently called |
3294 | 3251 | even inside eval()ed blocks/strings! If one wants the hook to do |
3295 | 3252 | nothing in such situations, put |
3296 | 3253 | |
3297 | 3254 | =end original |
3298 | 3255 | |
3299 | 3256 | C<$SIG{__DIE__}> フックをセットすることで、C<die> がその行動を行う |
3300 | 3257 | 直前に実行されるコールバックを設定できます。 |
3301 | 3258 | 結び付けられたハンドラはエラーテキストと共に呼び出され、 |
3302 | 3259 | 必要なら再び C<die> を呼び出すことでエラーテキストを変更できアス。 |
3303 | 3260 | C<%SIG> のエントリをセットする詳細については、L<perlvar/%SIG> を、 |
3304 | 3261 | 例については L<"eval BLOCK"> を参照してください。 |
3305 | 3262 | この機能はプログラムが終了しようとする前に 1 回だけ実行していましたが、 |
3306 | 3263 | 現在ではそうではありません: |
3307 | 3264 | C<$SIG{__DIE__}> フックは eval() されたブロック/文字列の中でも |
3308 | 3265 | 呼ばれるのです! |
3309 | 3266 | もしそのような状況で何もしなくない時は: |
3310 | 3267 | |
3311 | 3268 | die @_ if $^S; |
3312 | 3269 | |
3313 | 3270 | =begin original |
3314 | 3271 | |
3315 | 3272 | as the first line of the handler (see L<perlvar/$^S>). Because |
3316 | 3273 | this promotes strange action at a distance, this counterintuitive |
3317 | 3274 | behavior may be fixed in a future release. |
3318 | 3275 | |
3319 | 3276 | =end original |
3320 | 3277 | |
3321 | 3278 | をハンドラの最初の行に置いてください(L<perlvar/$^S> を参照してください)。 |
3322 | 3279 | これは離れたところで不思議な行動を引き起こすので、 |
3323 | 3280 | この直感的でない振る舞いは将来のリリースで修正されるかもしれません。 |
3324 | 3281 | |
3325 | 3282 | =begin original |
3326 | 3283 | |
3327 | 3284 | See also exit(), warn(), and the Carp module. |
3328 | 3285 | |
3329 | 3286 | =end original |
3330 | 3287 | |
3331 | 3288 | exit() と warn() と Carp モジュールも参照してください。 |
3332 | 3289 | |
3333 | 3290 | =item do BLOCK |
3334 | 3291 | X<do> X<block> |
3335 | 3292 | |
3336 | 3293 | =for Pod::Functions turn a BLOCK into a TERM |
3337 | 3294 | |
3338 | 3295 | =begin original |
3339 | 3296 | |
3340 | 3297 | Not really a function. Returns the value of the last command in the |
3341 | 3298 | sequence of commands indicated by BLOCK. When modified by the C<while> or |
3342 | 3299 | C<until> loop modifier, executes the BLOCK once before testing the loop |
3343 | 3300 | condition. (On other statements the loop modifiers test the conditional |
3344 | 3301 | first.) |
3345 | 3302 | |
3346 | 3303 | =end original |
3347 | 3304 | |
3348 | 3305 | 実際は関数ではありません。 |
3349 | 3306 | BLOCK で示されるコマンド列の最後の値を返します。 |
3350 | 3307 | C<while> や C<until> ループ修飾子で修飾すると、 |
3351 | 3308 | ループ条件を調べる前に 1 度、BLOCK を実行します。 |
3352 | 3309 | (これ以外の実行文は、ループ修飾子により、条件が最初に |
3353 | 3310 | 調べられます。) |
3354 | 3311 | |
3355 | 3312 | =begin original |
3356 | 3313 | |
3357 | 3314 | C<do BLOCK> does I<not> count as a loop, so the loop control statements |
3358 | 3315 | C<next>, C<last>, or C<redo> cannot be used to leave or restart the block. |
3359 | 3316 | See L<perlsyn> for alternative strategies. |
3360 | 3317 | |
3361 | 3318 | =end original |
3362 | 3319 | |
3363 | 3320 | C<do BLOCK> はループとしては I<扱われません>; 従って、C<next>, C<last>, |
3364 | 3321 | C<redo> といったループ制御文はブロックから抜けたり |
3365 | 3322 | 再開することはできません。 |
3366 | 3323 | その他の戦略については L<perlsyn> を参照してください。 |
3367 | 3324 | |
3325 | =item do SUBROUTINE(LIST) | |
3326 | X<do> | |
3327 | ||
3328 | =begin original | |
3329 | ||
3330 | This form of subroutine call is deprecated. SUBROUTINE can be a bareword, | |
3331 | a scalar variable or a subroutine beginning with C<&>. | |
3332 | ||
3333 | =end original | |
3334 | ||
3335 | この形のサブルーチン呼び出しは非推奨です。 | |
3336 | SUBROUTINE には裸の単語、スカラ変数、C<&> で始まるサブルーチンが使えます。 | |
3337 | ||
3368 | 3338 | =item do EXPR |
3369 | 3339 | X<do> |
3370 | 3340 | |
3371 | 3341 | =begin original |
3372 | 3342 | |
3373 | 3343 | Uses the value of EXPR as a filename and executes the contents of the |
3374 | 3344 | file as a Perl script. |
3375 | 3345 | |
3376 | 3346 | =end original |
3377 | 3347 | |
3378 | 3348 | EXPR の値をファイル名として用い、そのファイルの中身を |
3379 | 3349 | Perl のスクリプトとして実行します。 |
3380 | 3350 | |
3381 | 3351 | do 'stat.pl'; |
3382 | 3352 | |
3383 | 3353 | =begin original |
3384 | 3354 | |
3385 | is | |
3355 | is just like | |
3386 | 3356 | |
3387 | 3357 | =end original |
3388 | 3358 | |
3389 | は | |
3359 | は以下のものと同じようなものですが、 | |
3390 | 3360 | |
3391 | 3361 | eval `cat stat.pl`; |
3392 | 3362 | |
3393 | 3363 | =begin original |
3394 | 3364 | |
3395 | except that it's more c | |
3365 | except that it's more efficient and concise, keeps track of the current | |
3396 | the current | |
3397 | 3366 | filename for error messages, searches the C<@INC> directories, and updates |
3398 | 3367 | C<%INC> if the file is found. See L<perlvar/@INC> and L<perlvar/%INC> for |
3399 | 3368 | these variables. It also differs in that code evaluated with C<do FILENAME> |
3400 | 3369 | cannot see lexicals in the enclosing scope; C<eval STRING> does. It's the |
3401 | 3370 | same, however, in that it does reparse the file every time you call it, |
3402 | 3371 | so you probably don't want to do this inside a loop. |
3403 | 3372 | |
3404 | 3373 | =end original |
3405 | 3374 | |
3406 | より簡潔で | |
3375 | より効率的で、簡潔であり、エラーメッセージでファイル名がわかる、 | |
3407 | 3376 | カレントディレクトリでファイルが見つからなかったときに |
3408 | 3377 | C<@INC> ディレクトリを検索する、ファイルがあったときに C<%INC> を更新する、 |
3409 | 3378 | といったことがあります。 |
3410 | 3379 | これらの変数については L<perlvar/@INC> と L<perlvar/%INC> を |
3411 | 3380 | 参照してください。 |
3412 | 3381 | C<do FILENAME> で評価されたコードは、入れ子のスコープにある |
3413 | 3382 | レキシカル変数を見ることができないのに対し、C<eval STRING>ではできる、 |
3414 | 3383 | という違いがあります。 |
3415 | 3384 | しかし、呼び出すたびにファイルを解析し直すという点では同じですから、 |
3416 | 3385 | ループ内でこれを使おうなどとは、間違っても思ったりしないように。 |
3417 | 3386 | |
3418 | 3387 | =begin original |
3419 | 3388 | |
3420 | 3389 | If C<do> can read the file but cannot compile it, it returns C<undef> and sets |
3421 | 3390 | an error message in C<$@>. If C<do> cannot read the file, it returns undef |
3422 | 3391 | and sets C<$!> to the error. Always check C<$@> first, as compilation |
3423 | 3392 | could fail in a way that also sets C<$!>. If the file is successfully |
3424 | 3393 | compiled, C<do> returns the value of the last expression evaluated. |
3425 | 3394 | |
3426 | 3395 | =end original |
3427 | 3396 | |
3428 | 3397 | C<do> がファイルを読み込めたがコンパイルできなかった場合、 |
3429 | 3398 | C<undef> を返して C<$@> にエラーメッセージを設定します。 |
3430 | 3399 | C<do>がファイルを読み込めなかった場合、undef を返して C<$!> に |
3431 | 3400 | エラーを設定します。 |
3432 | 3401 | コンパイルに失敗したときにも C<$!> が設定されるので、常に C<$@> を |
3433 | 3402 | 先にチェックします。 |
3434 | 3403 | ファイルのコンパイルに成功した場合、C<do> は最後に評価した表現の値を返します。 |
3435 | 3404 | |
3436 | 3405 | =begin original |
3437 | 3406 | |
3438 | 3407 | Inclusion of library modules is better done with the |
3439 | 3408 | C<use> and C<require> operators, which also do automatic error checking |
3440 | 3409 | and raise an exception if there's a problem. |
3441 | 3410 | |
3442 | 3411 | =end original |
3443 | 3412 | |
3444 | 3413 | ライブラリモジュールのインクルードには、C<use> 演算子や C<require> 演算子を |
3445 | 3414 | 使った方がよいです; これらは自動的にエラーをチェックして、問題があれば例外を |
3446 | 3415 | 発生させます。 |
3447 | 3416 | |
3448 | 3417 | =begin original |
3449 | 3418 | |
3450 | 3419 | You might like to use C<do> to read in a program configuration |
3451 | 3420 | file. Manual error checking can be done this way: |
3452 | 3421 | |
3453 | 3422 | =end original |
3454 | 3423 | |
3455 | 3424 | C<do> をプログラム設定ファイルを読み込むのに使いたいかもしれません。 |
3456 | 3425 | 手動のエラーチェックは以下のようにして行えます: |
3457 | 3426 | |
3458 | 3427 | # read in config files: system first, then user |
3459 | 3428 | for $file ("/share/prog/defaults.rc", |
3460 | 3429 | "$ENV{HOME}/.someprogrc") |
3461 | 3430 | { |
3462 | 3431 | unless ($return = do $file) { |
3463 | 3432 | warn "couldn't parse $file: $@" if $@; |
3464 | 3433 | warn "couldn't do $file: $!" unless defined $return; |
3465 | 3434 | warn "couldn't run $file" unless $return; |
3466 | 3435 | } |
3467 | 3436 | } |
3468 | 3437 | |
3469 | 3438 | =item dump LABEL |
3470 | 3439 | X<dump> X<core> X<undump> |
3471 | 3440 | |
3472 | =item dump EXPR | |
3473 | ||
3474 | 3441 | =item dump |
3475 | 3442 | |
3476 | 3443 | =for Pod::Functions create an immediate core dump |
3477 | 3444 | |
3478 | 3445 | =begin original |
3479 | 3446 | |
3480 | 3447 | This function causes an immediate core dump. See also the B<-u> |
3481 | 3448 | command-line switch in L<perlrun>, which does the same thing. |
3482 | 3449 | Primarily this is so that you can use the B<undump> program (not |
3483 | 3450 | supplied) to turn your core dump into an executable binary after |
3484 | 3451 | having initialized all your variables at the beginning of the |
3485 | 3452 | program. When the new binary is executed it will begin by executing |
3486 | 3453 | a C<goto LABEL> (with all the restrictions that C<goto> suffers). |
3487 | 3454 | Think of it as a goto with an intervening core dump and reincarnation. |
3488 | If C<LABEL> is omitted, restarts the program from the top. | |
3455 | If C<LABEL> is omitted, restarts the program from the top. | |
3489 | C<dump EXPR> form, available starting in Perl 5.18.0, allows a name to be | |
3490 | computed at run time, being otherwise identical to C<dump LABEL>. | |
3491 | 3456 | |
3492 | 3457 | =end original |
3493 | 3458 | |
3494 | 3459 | この関数は即座にコアダンプを行ないます。 |
3495 | 3460 | 同様のことを行う L<perlrun> の B<-u> オプションも参照してください。 |
3496 | 3461 | プログラムの先頭で、 |
3497 | 3462 | すべての変数を初期化したあとのコアダンプを B<undump> |
3498 | 3463 | プログラム(提供していません)を使って実行ファイルに返ることができます。 |
3499 | 3464 | この新しいバイナリが実行されると、C<goto LABEL> から始めます |
3500 | 3465 | (C<goto> に関する制限はすべて適用されます)。 |
3501 | 3466 | コアダンプをはさんで再生する goto と考えてください。 |
3502 | 3467 | C<LABEL> が省略されると、プログラムを先頭から再開します。 |
3503 | Perl 5.18.0 から利用可能な C<dump EXPR> 形式では、実行時に計算される | |
3504 | 名前が使えます; その他は C<dump LABEL> と同一です。 | |
3505 | 3468 | |
3506 | 3469 | =begin original |
3507 | 3470 | |
3508 | 3471 | B<WARNING>: Any files opened at the time of the dump will I<not> |
3509 | 3472 | be open any more when the program is reincarnated, with possible |
3510 | 3473 | resulting confusion by Perl. |
3511 | 3474 | |
3512 | 3475 | =end original |
3513 | 3476 | |
3514 | 3477 | B<警告>: dump 時点でオープンされていたファイルは、プログラムが |
3515 | 3478 | 再生されたときには、もはやオープンされていません; Perl を混乱させる可能性が |
3516 | 3479 | あります。 |
3517 | 3480 | |
3518 | 3481 | =begin original |
3519 | 3482 | |
3520 | 3483 | This function is now largely obsolete, mostly because it's very hard to |
3521 | 3484 | convert a core file into an executable. That's why you should now invoke |
3522 | 3485 | it as C<CORE::dump()>, if you don't want to be warned against a possible |
3523 | 3486 | typo. |
3524 | 3487 | |
3525 | 3488 | =end original |
3526 | 3489 | |
3527 | 3490 | この関数は大幅に時代遅れのものです; 主な理由としては、コアファイルを |
3528 | 3491 | 実行形式に変換するのが非常に困難であることです。 |
3529 | 3492 | これが、今ではタイプミスの可能性を警告されたくないなら |
3530 | 3493 | C<CORE::dump()> として起動するべき理由です。 |
3531 | 3494 | |
3532 | 3495 | =begin original |
3533 | 3496 | |
3534 | Unlike most named operators, this has the same precedence as assignment. | |
3535 | It is also exempt from the looks-like-a-function rule, so | |
3536 | C<dump ("foo")."bar"> will cause "bar" to be part of the argument to | |
3537 | C<dump>. | |
3538 | ||
3539 | =end original | |
3540 | ||
3541 | ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 | |
3542 | また、関数のように見えるものの規則からも免れるので、C<dump ("foo")."bar"> と | |
3543 | すると "bar" は C<dump> への引数の一部になります。 | |
3544 | ||
3545 | =begin original | |
3546 | ||
3547 | 3497 | Portability issues: L<perlport/dump>. |
3548 | 3498 | |
3549 | 3499 | =end original |
3550 | 3500 | |
3551 | 3501 | 移植性の問題: L<perlport/dump>。 |
3552 | 3502 | |
3553 | 3503 | =item each HASH |
3554 | 3504 | X<each> X<hash, iterator> |
3555 | 3505 | |
3556 | 3506 | =item each ARRAY |
3557 | 3507 | X<array, iterator> |
3558 | 3508 | |
3559 | 3509 | =item each EXPR |
3560 | 3510 | |
3561 | 3511 | =for Pod::Functions retrieve the next key/value pair from a hash |
3562 | 3512 | |
3563 | 3513 | =begin original |
3564 | 3514 | |
3565 | 3515 | When called on a hash in list context, returns a 2-element list |
3566 | 3516 | consisting of the key and value for the next element of a hash. In Perl |
3567 | 3517 | 5.12 and later only, it will also return the index and value for the next |
3568 | 3518 | element of an array so that you can iterate over it; older Perls consider |
3569 | 3519 | this a syntax error. When called in scalar context, returns only the key |
3570 | 3520 | (not the value) in a hash, or the index in an array. |
3571 | 3521 | |
3572 | 3522 | =end original |
3573 | 3523 | |
3574 | 3524 | ハッシュに対してリストコンテキストで呼び出した場合は、次の要素に対する、 |
3575 | 3525 | ハッシュのキーと値を返します。 |
3576 | 3526 | Perl 5.12 以降でのみ、配列のインデックスと値からなる |
3577 | 3527 | 2 要素のリストを返すので、反復を行えます; より古い Perl ではこれは |
3578 | 3528 | 文法エラーと考えられます。 |
3579 | 3529 | スカラコンテキストで呼び出した場合は、 |
3580 | 3530 | ハッシュの場合は(値ではなく)キー、配列の場合はインデックスを返します。 |
3581 | 3531 | |
3582 | 3532 | =begin original |
3583 | 3533 | |
3584 | 3534 | Hash entries are returned in an apparently random order. The actual random |
3585 | order is s | |
3535 | order is subject to change in future versions of Perl, but it is | |
3586 | ||
3536 | guaranteed to be in the same order as either the C<keys> or C<values> | |
3587 | ||
3537 | function would produce on the same (unmodified) hash. Since Perl | |
3588 | ||
3538 | 5.8.2 the ordering can be different even between different runs of Perl | |
3589 | ||
3539 | for security reasons (see L<perlsec/"Algorithmic Complexity Attacks">). | |
3590 | rely on C<keys>, C<values> and C<each> to repeatedly return the same order | |
3591 | as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for | |
3592 | details on why hash order is randomized. Aside from the guarantees | |
3593 | provided here the exact details of Perl's hash algorithm and the hash | |
3594 | traversal order are subject to change in any release of Perl. | |
3595 | 3540 | |
3596 | 3541 | =end original |
3597 | 3542 | |
3598 | ハッシュ | |
3543 | ハッシュエントリは見かけ上、ランダムな順序で返されます。 | |
3599 | 実際のランダムな順 | |
3544 | 実際のランダムな順番は perl の将来のバージョンでは変わるかもしれませんが、 | |
3600 | ||
3545 | C<keys> や C<values> 関数が同じ(変更されていない)ハッシュに対して | |
3601 | ||
3546 | 生成するのと同じ順番であることは保証されます。 | |
3602 | ||
3547 | Perl 5.8.2 以降ではセキュリティ上の理由により、 | |
3603 | 変 | |
3548 | 実行される毎に順番は変わるかもしれません | |
3604 | ||
3549 | (L<perlsec/"Algorithmic Complexity Attacks"> を参照してください)。 | |
3605 | 返すことに依存してもかまいません。 | |
3606 | なぜハッシュの順序がランダム化されているかの詳細については | |
3607 | L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。 | |
3608 | ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の | |
3609 | 正確な詳細は Perl のリリースによって変更される可能性があります。 | |
3610 | 3550 | |
3611 | 3551 | =begin original |
3612 | 3552 | |
3613 | 3553 | After C<each> has returned all entries from the hash or array, the next |
3614 | 3554 | call to C<each> returns the empty list in list context and C<undef> in |
3615 | 3555 | scalar context; the next call following I<that> one restarts iteration. |
3616 | 3556 | Each hash or array has its own internal iterator, accessed by C<each>, |
3617 | 3557 | C<keys>, and C<values>. The iterator is implicitly reset when C<each> has |
3618 | 3558 | reached the end as just described; it can be explicitly reset by calling |
3619 | 3559 | C<keys> or C<values> on the hash or array. If you add or delete a hash's |
3620 | elements while iterating over it, t | |
3560 | elements while iterating over it, entries may be skipped or duplicated--so | |
3621 | ||
3561 | don't do that. Exception: In the current implementation, it is always safe | |
3622 | ||
3562 | to delete the item most recently returned by C<each()>, so the following | |
3623 | ||
3563 | code works properly: | |
3624 | 3564 | |
3625 | 3565 | =end original |
3626 | 3566 | |
3627 | 3567 | C<each> がハッシュをすべて読み込んでしまった後、リストコンテキストでは |
3628 | 3568 | 空リストが返され、スカラコンテキストでは C<undef> が返されます; |
3629 | 3569 | I<そのあと> もう一度呼び出すと、再び反復を始めます。 |
3630 | 3570 | ハッシュや配列毎にそれぞれ反復子があり、C<each>、C<keys>、C<values> で |
3631 | 3571 | アクセスされます。 |
3632 | 3572 | 反復子は、前述したように C<each> が要素をすべて読むことによって |
3633 | 3573 | 暗黙にリセットされます; また、ハッシュや配列に対して |
3634 | 3574 | C<keys HASH>, C<values HASH> を呼び出すことで明示的にリセットできます。 |
3635 | 3575 | 繰り返しを行なっている間に、ハッシュに要素を追加したり削除したりすると、 |
3636 | ||
3576 | 要素が飛ばされたり重複したりするので、してはいけません。 | |
3637 | ||
3577 | 例外: 現在の実装では一番最近に C<each()> から返されたものを削除するのは常に | |
3638 | 例外: 一番最近に C<each()> から返されたものを削除するのは常に | |
3639 | 3578 | 安全です; これは以下のようなコードが正しく動くことを意味します: |
3640 | 3579 | |
3641 | 3580 | while (($key, $value) = each %hash) { |
3642 | 3581 | print $key, "\n"; |
3643 | 3582 | delete $hash{$key}; # This is safe |
3644 | 3583 | } |
3645 | 3584 | |
3646 | 3585 | =begin original |
3647 | 3586 | |
3648 | Tied hashes may have a different ordering behaviour to perl's hash | |
3649 | implementation. | |
3650 | ||
3651 | =end original | |
3652 | ||
3653 | tie されたハッシュは、順序に関して Perl のハッシュと異なった振る舞いをします。 | |
3654 | ||
3655 | =begin original | |
3656 | ||
3657 | 3587 | This prints out your environment like the printenv(1) program, |
3658 | 3588 | but in a different order: |
3659 | 3589 | |
3660 | 3590 | =end original |
3661 | 3591 | |
3662 | 3592 | これは、printenv(1) プログラムのように環境変数を表示しますが、 |
3663 | 3593 | 順序は異なっています: |
3664 | 3594 | |
3665 | 3595 | while (($key,$value) = each %ENV) { |
3666 | 3596 | print "$key=$value\n"; |
3667 | 3597 | } |
3668 | 3598 | |
3669 | 3599 | =begin original |
3670 | 3600 | |
3671 | 3601 | Starting with Perl 5.14, C<each> can take a scalar EXPR, which must hold |
3672 | 3602 | reference to an unblessed hash or array. The argument will be dereferenced |
3673 | 3603 | automatically. This aspect of C<each> is considered highly experimental. |
3674 | 3604 | The exact behaviour may change in a future version of Perl. |
3675 | 3605 | |
3676 | 3606 | =end original |
3677 | 3607 | |
3678 | 3608 | Perl 5.14 から、C<each> はスカラの EXPR を取ることができるようになりました; |
3679 | 3609 | これは bless されていないハッシュや配列へのリファレンスでなければなりません。 |
3680 | 3610 | 引数は自動的にデリファレンスされます。 |
3681 | 3611 | C<each> のこの動作は高度に実験的であると考えられています。 |
3682 | 3612 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 |
3683 | 3613 | |
3684 | 3614 | while (($key,$value) = each $hashref) { ... } |
3685 | 3615 | |
3686 | 3616 | =begin original |
3687 | 3617 | |
3688 | As of Perl 5.18 you can use a bare C<each> in a C<while> loop, | |
3689 | which will set C<$_> on every iteration. | |
3690 | ||
3691 | =end original | |
3692 | ||
3693 | Perl 5.18 から C<while> ループの中に裸の C<each> を書けます; これは | |
3694 | 繰り返し毎に C<$_> を設定します。 | |
3695 | ||
3696 | while(each %ENV) { | |
3697 | print "$_=$ENV{$_}\n"; | |
3698 | } | |
3699 | ||
3700 | =begin original | |
3701 | ||
3702 | 3618 | To avoid confusing would-be users of your code who are running earlier |
3703 | 3619 | versions of Perl with mysterious syntax errors, put this sort of thing at |
3704 | 3620 | the top of your file to signal that your code will work I<only> on Perls of |
3705 | 3621 | a recent vintage: |
3706 | 3622 | |
3707 | 3623 | =end original |
3708 | 3624 | |
3709 | 3625 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な |
3710 | 3626 | 文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で |
3711 | 3627 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを |
3712 | 3628 | 書いてください: |
3713 | 3629 | |
3714 | 3630 | use 5.012; # so keys/values/each work on arrays |
3715 | 3631 | use 5.014; # so keys/values/each work on scalars (experimental) |
3716 | use 5.018; # so each assigns to $_ in a lone while test | |
3717 | 3632 | |
3718 | 3633 | =begin original |
3719 | 3634 | |
3720 | 3635 | See also C<keys>, C<values>, and C<sort>. |
3721 | 3636 | |
3722 | 3637 | =end original |
3723 | 3638 | |
3724 | 3639 | C<keys> や C<values> や C<sort> も参照してください。 |
3725 | 3640 | |
3726 | 3641 | =item eof FILEHANDLE |
3727 | 3642 | X<eof> |
3728 | 3643 | X<end of file> |
3729 | 3644 | X<end-of-file> |
3730 | 3645 | |
3731 | 3646 | =item eof () |
3732 | 3647 | |
3733 | 3648 | =item eof |
3734 | 3649 | |
3735 | 3650 | =for Pod::Functions test a filehandle for its end |
3736 | 3651 | |
3737 | 3652 | =begin original |
3738 | 3653 | |
3739 | 3654 | Returns 1 if the next read on FILEHANDLE will return end of file I<or> if |
3740 | 3655 | FILEHANDLE is not open. FILEHANDLE may be an expression whose value |
3741 | 3656 | gives the real filehandle. (Note that this function actually |
3742 | 3657 | reads a character and then C<ungetc>s it, so isn't useful in an |
3743 | 3658 | interactive context.) Do not read from a terminal file (or call |
3744 | 3659 | C<eof(FILEHANDLE)> on it) after end-of-file is reached. File types such |
3745 | 3660 | as terminals may lose the end-of-file condition if you do. |
3746 | 3661 | |
3747 | 3662 | =end original |
3748 | 3663 | |
3749 | 3664 | 次に FILEHANDLE 上で読み込みを行なったときに、EOF が返されるときか、 |
3750 | 3665 | I<または> FILEHANDLE がオープンされていないと、1 を返します。 |
3751 | 3666 | FILEHANDLE は、値が実際のファイルハンドルを示す式であってもかまいません。 |
3752 | 3667 | (この関数は、実際に文字を読み、C<ungetc> を行ないますので、 |
3753 | 3668 | 対話型の場合には有用ではありません。) |
3754 | 3669 | 端末ファイルは EOF に達した後にさらに読み込んだり C<eof(FILEHANDLE)> を |
3755 | 3670 | 呼び出したりしてはいけません。 |
3756 | 3671 | そのようなことをすると、端末のようなファイルタイプは |
3757 | 3672 | EOF 状態を失ってしまうかもしれません。 |
3758 | 3673 | |
3759 | 3674 | =begin original |
3760 | 3675 | |
3761 | 3676 | An C<eof> without an argument uses the last file read. Using C<eof()> |
3762 | 3677 | with empty parentheses is different. It refers to the pseudo file |
3763 | 3678 | formed from the files listed on the command line and accessed via the |
3764 | 3679 | C<< <> >> operator. Since C<< <> >> isn't explicitly opened, |
3765 | 3680 | as a normal filehandle is, an C<eof()> before C<< <> >> has been |
3766 | 3681 | used will cause C<@ARGV> to be examined to determine if input is |
3767 | 3682 | available. Similarly, an C<eof()> after C<< <> >> has returned |
3768 | 3683 | end-of-file will assume you are processing another C<@ARGV> list, |
3769 | 3684 | and if you haven't set C<@ARGV>, will read input from C<STDIN>; |
3770 | 3685 | see L<perlop/"I/O Operators">. |
3771 | 3686 | |
3772 | 3687 | =end original |
3773 | 3688 | |
3774 | 3689 | 引数を省略した C<eof> は、最後に読み込みを行なったファイルを使います。 |
3775 | 3690 | 空の括弧をつけた C<eof()> は異なります。 |
3776 | 3691 | これはコマンドラインのファイルリストで構成され、C<< <> >> 演算子経由で |
3777 | 3692 | アクセスされる擬似ファイルを示すために用いられます。 |
3778 | 3693 | 通常のファイルハンドルと違って C<< <> >> は明示的にオープンされないので、 |
3779 | 3694 | C<< <> >> を使う前に C<eof()> を使うと、 |
3780 | 3695 | 入力が正常か確認するために C<@ARGV> がテストされます。 |
3781 | 3696 | 同様に、C<< <> >> が EOF を返した後の C<eof()> は、 |
3782 | 3697 | 他の C<@ARGV> リストを処理していると仮定し、もし C<@ARGV> を |
3783 | 3698 | セットしていないときは C<STDIN> から読み込みます; |
3784 | 3699 | L<perlop/"I/O Operators"> を参照してください。 |
3785 | 3700 | |
3786 | 3701 | =begin original |
3787 | 3702 | |
3788 | 3703 | In a C<< while (<>) >> loop, C<eof> or C<eof(ARGV)> can be used to |
3789 | 3704 | detect the end of each file, whereas C<eof()> will detect the end |
3790 | 3705 | of the very last file only. Examples: |
3791 | 3706 | |
3792 | 3707 | =end original |
3793 | 3708 | |
3794 | 3709 | C<< while (<>) >> ループの中では、個々のファイルの終わりを調べるには、 |
3795 | 3710 | C<eof> か C<eof(ARGV)> を用いるのに対して |
3796 | 3711 | C<eof()> は最後のファイルの終わりのみを調べます。 |
3797 | 3712 | 例: |
3798 | 3713 | |
3799 | 3714 | # reset line numbering on each input file |
3800 | 3715 | while (<>) { |
3801 | 3716 | next if /^\s*#/; # skip comments |
3802 | 3717 | print "$.\t$_"; |
3803 | 3718 | } continue { |
3804 | 3719 | close ARGV if eof; # Not eof()! |
3805 | 3720 | } |
3806 | 3721 | |
3807 | 3722 | # insert dashes just before last line of last file |
3808 | 3723 | while (<>) { |
3809 | 3724 | if (eof()) { # check for end of last file |
3810 | 3725 | print "--------------\n"; |
3811 | 3726 | } |
3812 | 3727 | print; |
3813 | last if eof(); # needed if we're reading from a terminal | |
3728 | last if eof(); # needed if we're reading from a terminal | |
3814 | 3729 | } |
3815 | 3730 | |
3816 | 3731 | =begin original |
3817 | 3732 | |
3818 | 3733 | Practical hint: you almost never need to use C<eof> in Perl, because the |
3819 | 3734 | input operators typically return C<undef> when they run out of data or |
3820 | 3735 | encounter an error. |
3821 | 3736 | |
3822 | 3737 | =end original |
3823 | 3738 | |
3824 | 3739 | 現実的なヒント: Perl で C<eof> が必要となることは、ほとんどありません; |
3825 | 3740 | 基本的には、データがなくなったときやエラーがあったときに、入力演算子が |
3826 | 3741 | C<undef> を返してくれるからです。 |
3827 | 3742 | |
3828 | 3743 | =item eval EXPR |
3829 | 3744 | X<eval> X<try> X<catch> X<evaluate> X<parse> X<execute> |
3830 | 3745 | X<error, handling> X<exception, handling> |
3831 | 3746 | |
3832 | 3747 | =item eval BLOCK |
3833 | 3748 | |
3834 | 3749 | =item eval |
3835 | 3750 | |
3836 | 3751 | =for Pod::Functions catch exceptions or compile and run code |
3837 | 3752 | |
3838 | 3753 | =begin original |
3839 | 3754 | |
3840 | In the first form, | |
3755 | In the first form, the return value of EXPR is parsed and executed as if it | |
3841 | value of EXPR is parsed and executed as if it | |
3842 | 3756 | were a little Perl program. The value of the expression (which is itself |
3843 | 3757 | determined within scalar context) is first parsed, and if there were no |
3844 | 3758 | errors, executed as a block within the lexical context of the current Perl |
3845 | 3759 | program. This means, that in particular, any outer lexical variables are |
3846 | 3760 | visible to it, and any package variable settings or subroutine and format |
3847 | 3761 | definitions remain afterwards. |
3848 | 3762 | |
3849 | 3763 | =end original |
3850 | 3764 | |
3851 | 第一の形式 | |
3765 | 第一の形式では、EXPR の返り値が Perl のプログラムであるかのように | |
3852 | ||
3766 | 解析され、実行されます。 | |
3853 | 3767 | 式の値(それ自身スカラコンテキストの中で決定されます)はまずパースされ、 |
3854 | エラーがなければ | |
3768 | エラーがなければ | |
3855 | 実行されます。 | |
3769 | Perl プログラムのレキシカルコンテキストの中のブロックとして実行されます。 | |
3856 | 3770 | これは、特に、外側のレキシカル変数は見えていて、パッケージ変数の設定や |
3857 | 3771 | サブルーチンやフォーマットの定義はその後も残っているということです。 |
3858 | 3772 | |
3859 | 3773 | =begin original |
3860 | 3774 | |
3861 | 3775 | Note that the value is parsed every time the C<eval> executes. |
3862 | 3776 | If EXPR is omitted, evaluates C<$_>. This form is typically used to |
3863 | 3777 | delay parsing and subsequent execution of the text of EXPR until run time. |
3864 | 3778 | |
3865 | 3779 | =end original |
3866 | 3780 | |
3867 | 3781 | 返される値は C<eval> が実行されるごとにパースされることに注意してください。 |
3868 | 3782 | EXPR が省略されると、C<$_> を評価します。 |
3869 | 3783 | この形は主に EXPR のテキストのパースと実行を実行時にまで |
3870 | 3784 | 遅延させるのに用います。 |
3871 | 3785 | |
3872 | 3786 | =begin original |
3873 | 3787 | |
3874 | 3788 | If the C<unicode_eval> feature is enabled (which is the default under a |
3875 | 3789 | C<use 5.16> or higher declaration), EXPR or C<$_> is treated as a string of |
3876 | 3790 | characters, so C<use utf8> declarations have no effect, and source filters |
3877 | 3791 | are forbidden. In the absence of the C<unicode_eval> feature, the string |
3878 | 3792 | will sometimes be treated as characters and sometimes as bytes, depending |
3879 | 3793 | on the internal encoding, and source filters activated within the C<eval> |
3880 | 3794 | exhibit the erratic, but historical, behaviour of affecting some outer file |
3881 | 3795 | scope that is still compiling. See also the L</evalbytes> keyword, which |
3882 | 3796 | always treats its input as a byte stream and works properly with source |
3883 | 3797 | filters, and the L<feature> pragma. |
3884 | 3798 | |
3885 | 3799 | =end original |
3886 | 3800 | |
3887 | 3801 | C<unicode_eval> 機能が有効の場合(これは C<use 5.16> またはそれ以上が |
3888 | 3802 | 宣言されている場合はデフォルトです)、EXPR や C<$_> は文字単位の文字列として |
3889 | 3803 | 扱われるので、C<use utf8> 宣言は無効で、ソースフィルタは禁止されます。 |
3890 | 3804 | C<unicode_eval> 機能がなければ、文字列は内部エンコーディングに依存して |
3891 | 3805 | 時々文字単位として扱われ、時々バイト単位で扱われます; そして C<eval> の |
3892 | 3806 | 中で有効になったソースフィルタは、まだコンパイル中である一部の外側のファイル |
3893 | 3807 | スコープに影響を与えるという、間違っているけれども歴史的な振る舞いを |
3894 | 3808 | 見せます。 |
3895 | 3809 | 入力を常にバイト列として扱い、ソースフィルタが適切に動作する |
3896 | 3810 | L</evalbytes> キーワードおよび L<feature> プラグマを参照してください。 |
3897 | 3811 | |
3898 | 3812 | =begin original |
3899 | 3813 | |
3900 | Problems can arise if the string expands a scalar containing a floating | |
3901 | point number. That scalar can expand to letters, such as C<"NaN"> or | |
3902 | C<"Infinity">; or, within the scope of a C<use locale>, the decimal | |
3903 | point character may be something other than a dot (such as a comma). | |
3904 | None of these are likely to parse as you are likely expecting. | |
3905 | ||
3906 | =end original | |
3907 | ||
3908 | 文字列をが小数点を含むスカラを展開するときに問題が起こることがあります。 | |
3909 | そのようなスカラは C<"NaN"> や C<"Infinity"> のような文字に | |
3910 | 展開されることがあります; または、C<use locale> のスコープの中では、 | |
3911 | 小数点文字は (カンマのような) ドット以外の文字かもしれません。 | |
3912 | これらはどれもあなたがおそらく予測しているようにはパースされません。 | |
3913 | ||
3914 | =begin original | |
3915 | ||
3916 | 3814 | In the second form, the code within the BLOCK is parsed only once--at the |
3917 | 3815 | same time the code surrounding the C<eval> itself was parsed--and executed |
3918 | 3816 | within the context of the current Perl program. This form is typically |
3919 | 3817 | used to trap exceptions more efficiently than the first (see below), while |
3920 | 3818 | also providing the benefit of checking the code within BLOCK at compile |
3921 | 3819 | time. |
3922 | 3820 | |
3923 | 3821 | =end original |
3924 | 3822 | |
3925 | 3823 | 第二の形式では、BLOCK 内部のコードは一度だけパースされ -- コードを |
3926 | 3824 | 囲む C<eval> 自身がパースされるのと同じ時点です -- 現在の Perl プログラムの |
3927 | 3825 | コンテキストで実行されます。 |
3928 | 3826 | この形式は典型的には第一の形式より効率的に例外をトラップします(後述); |
3929 | 3827 | また BLOCK 内部のコードはコンパイル時にチェックされるという利点を提供します。 |
3930 | 3828 | |
3931 | 3829 | =begin original |
3932 | 3830 | |
3933 | 3831 | The final semicolon, if any, may be omitted from the value of EXPR or within |
3934 | 3832 | the BLOCK. |
3935 | 3833 | |
3936 | 3834 | =end original |
3937 | 3835 | |
3938 | 最後のセミコロンは、もしあれば、EXPR の値や BLOCK の中身から | |
3836 | 最後のセミコロンは、もしあれば、EXPR の値や BLOCK の中身から省くことができます。 | |
3939 | 省くことができます。 | |
3940 | 3837 | |
3941 | 3838 | =begin original |
3942 | 3839 | |
3943 | 3840 | In both forms, the value returned is the value of the last expression |
3944 | 3841 | evaluated inside the mini-program; a return statement may be also used, just |
3945 | 3842 | as with subroutines. The expression providing the return value is evaluated |
3946 | 3843 | in void, scalar, or list context, depending on the context of the C<eval> |
3947 | 3844 | itself. See L</wantarray> for more on how the evaluation context can be |
3948 | 3845 | determined. |
3949 | 3846 | |
3950 | 3847 | =end original |
3951 | 3848 | |
3952 | 3849 | どちらの形式でも、返される値はミニプログラムの内部で最後に評価された |
3953 | 3850 | 表現の値です; サブルーチンと同様、return 文も使えます。 |
3954 | 3851 | 返り値として提供される表現は、C<eval> 自身のコンテキストに依存して |
3955 | 3852 | 無効・スカラ・リストのいずれかのコンテキストで評価されます。 |
3956 | 3853 | 評価コンテキストの決定方法についての詳細は L</wantarray> を参照してください。 |
3957 | 3854 | |
3958 | 3855 | =begin original |
3959 | 3856 | |
3960 | 3857 | If there is a syntax error or runtime error, or a C<die> statement is |
3961 | 3858 | executed, C<eval> returns C<undef> in scalar context |
3962 | 3859 | or an empty list in list context, and C<$@> is set to the error |
3963 | 3860 | message. (Prior to 5.16, a bug caused C<undef> to be returned |
3964 | 3861 | in list context for syntax errors, but not for runtime errors.) |
3965 | 3862 | If there was no error, C<$@> is set to the empty string. A |
3966 | 3863 | control flow operator like C<last> or C<goto> can bypass the setting of |
3967 | 3864 | C<$@>. Beware that using C<eval> neither silences Perl from printing |
3968 | 3865 | warnings to STDERR, nor does it stuff the text of warning messages into C<$@>. |
3969 | 3866 | To do either of those, you have to use the C<$SIG{__WARN__}> facility, or |
3970 | 3867 | turn off warnings inside the BLOCK or EXPR using S<C<no warnings 'all'>>. |
3971 | See L</warn>, L<perlvar>, | |
3868 | See L</warn>, L<perlvar>, L<warnings> and L<perllexwarn>. | |
3972 | 3869 | |
3973 | 3870 | =end original |
3974 | 3871 | |
3975 | 3872 | 構文エラーや実行エラーが発生するか、C<die> 文が実行されると、 |
3976 | 3873 | C<eval> はスカラコンテキストでは C<undef> が、リストコンテキストでは |
3977 | 3874 | 空リスト が設定されます。 |
3978 | (5.16 | |
3875 | (Prior to 5.16, a bug caused C<undef> to be returned | |
3979 | ||
3876 | in list context for syntax errors, but not for runtime errors.) | |
3980 | 3877 | エラーがなければ、C<$@> は空文字列に設定されます。 |
3981 | ||
3878 | A | |
3879 | control flow operator like C<last> or C<goto> can bypass the setting of | |
3880 | C<$@>. | |
3982 | 3881 | C<eval> を、STDERR に警告メッセージを表示させない目的や、 |
3983 | 3882 | 警告メッセージを C<$@> に格納する目的では使わないでください。 |
3984 | 3883 | そのような用途では、C<$SIG{__WARN__}> 機能を使うか、 |
3985 | 3884 | S<C<no warnings 'all'>> を使って BLOCK か EXPR の内部での警告を |
3986 | 3885 | オフにする必要があります。 |
3987 | L</warn>, L<perlvar>, L<warnings>, L<warn | |
3886 | L</warn>, L<perlvar>, L<warnings>, L<perllexwarn> を参照してください。 | |
3988 | 3887 | |
3989 | 3888 | =begin original |
3990 | 3889 | |
3991 | 3890 | Note that, because C<eval> traps otherwise-fatal errors, it is useful for |
3992 | 3891 | determining whether a particular feature (such as C<socket> or C<symlink>) |
3993 | 3892 | is implemented. It is also Perl's exception-trapping mechanism, where |
3994 | 3893 | the die operator is used to raise exceptions. |
3995 | 3894 | |
3996 | 3895 | =end original |
3997 | 3896 | |
3998 | 3897 | C<eval> は、致命的エラーとなるようなものをトラップすることができるので、 |
3999 | 3898 | (C<socket> や C<symlink> といった) 特定の機能が実装されているかを、 |
4000 | 3899 | 調べるために使うことができることに注意してください。 |
4001 | 3900 | die 演算子が例外を発生させるものとすれば、これはまた、Perl の例外捕捉機能と |
4002 | 3901 | 捉えることもできます。 |
4003 | 3902 | |
4004 | 3903 | =begin original |
4005 | 3904 | |
4006 | 3905 | If you want to trap errors when loading an XS module, some problems with |
4007 | 3906 | the binary interface (such as Perl version skew) may be fatal even with |
4008 | 3907 | C<eval> unless C<$ENV{PERL_DL_NONLAZY}> is set. See L<perlrun>. |
4009 | 3908 | |
4010 | 3909 | =end original |
4011 | 3910 | |
4012 | 3911 | XS モジュールのロード中のエラーをトラップしたいなら、 |
4013 | 3912 | (Perl バージョンの違いのような) バイナリインターフェースに関する問題に |
4014 | 3913 | ついては C<$ENV{PERL_DL_NONLAZY}> がセットされていない C<eval> でも |
4015 | 3914 | 致命的エラーになるかもしれません。 |
4016 | 3915 | L<perlrun> を参照してください。 |
4017 | 3916 | |
4018 | 3917 | =begin original |
4019 | 3918 | |
4020 | 3919 | If the code to be executed doesn't vary, you may use the eval-BLOCK |
4021 | 3920 | form to trap run-time errors without incurring the penalty of |
4022 | 3921 | recompiling each time. The error, if any, is still returned in C<$@>. |
4023 | 3922 | Examples: |
4024 | 3923 | |
4025 | 3924 | =end original |
4026 | 3925 | |
4027 | 3926 | 実行するコードが変わらないのであれば、毎回多量の再コンパイルすることなしに、 |
4028 | 3927 | 実行時エラーのトラップを行なうために、 |
4029 | 3928 | eval-BLOCK 形式を使うことができます。 |
4030 | 3929 | エラーがあれば、やはり $@ に返されます。 |
4031 | 3930 | 例: |
4032 | 3931 | |
4033 | 3932 | # make divide-by-zero nonfatal |
4034 | 3933 | eval { $answer = $a / $b; }; warn $@ if $@; |
4035 | 3934 | |
4036 | 3935 | # same thing, but less efficient |
4037 | 3936 | eval '$answer = $a / $b'; warn $@ if $@; |
4038 | 3937 | |
4039 | 3938 | # a compile-time error |
4040 | 3939 | eval { $answer = }; # WRONG |
4041 | 3940 | |
4042 | 3941 | # a run-time error |
4043 | 3942 | eval '$answer ='; # sets $@ |
4044 | 3943 | |
4045 | 3944 | =begin original |
4046 | 3945 | |
4047 | 3946 | Using the C<eval{}> form as an exception trap in libraries does have some |
4048 | 3947 | issues. Due to the current arguably broken state of C<__DIE__> hooks, you |
4049 | 3948 | may wish not to trigger any C<__DIE__> hooks that user code may have installed. |
4050 | 3949 | You can use the C<local $SIG{__DIE__}> construct for this purpose, |
4051 | 3950 | as this example shows: |
4052 | 3951 | |
4053 | 3952 | =end original |
4054 | 3953 | |
4055 | 3954 | C<eval{}> 形式をライブラリの例外を捕捉するために使うときには |
4056 | 3955 | 問題があります。 |
4057 | 3956 | 現在の C<__DIE__> フックの状態はほぼ確実に壊れているという理由で、 |
4058 | 3957 | ユーザーのコードが設定した C<__DIE__> フックを実行したくないかもしれません。 |
4059 | 3958 | この目的には以下の例のように、C<local $SIG{__DIE__}> 構造が使えます。 |
4060 | 3959 | |
4061 | 3960 | # a private exception trap for divide-by-zero |
4062 | 3961 | eval { local $SIG{'__DIE__'}; $answer = $a / $b; }; |
4063 | 3962 | warn $@ if $@; |
4064 | 3963 | |
4065 | 3964 | =begin original |
4066 | 3965 | |
4067 | 3966 | This is especially significant, given that C<__DIE__> hooks can call |
4068 | 3967 | C<die> again, which has the effect of changing their error messages: |
4069 | 3968 | |
4070 | 3969 | =end original |
4071 | 3970 | |
4072 | 3971 | これは特に顕著です; 与えられた C<__DIE__> フックは C<die> をもう一度 |
4073 | 3972 | 呼び出すことができ、これによってエラーメッセージを変える効果があります: |
4074 | 3973 | |
4075 | 3974 | # __DIE__ hooks may modify error messages |
4076 | 3975 | { |
4077 | 3976 | local $SIG{'__DIE__'} = |
4078 | 3977 | sub { (my $x = $_[0]) =~ s/foo/bar/g; die $x }; |
4079 | 3978 | eval { die "foo lives here" }; |
4080 | 3979 | print $@ if $@; # prints "bar lives here" |
4081 | 3980 | } |
4082 | 3981 | |
4083 | 3982 | =begin original |
4084 | 3983 | |
4085 | 3984 | Because this promotes action at a distance, this counterintuitive behavior |
4086 | 3985 | may be fixed in a future release. |
4087 | 3986 | |
4088 | 3987 | =end original |
4089 | 3988 | |
4090 | 3989 | これは距離の離れた行動であるため、この直感的でない振る舞いは |
4091 | 3990 | 将来のリリースでは修正されるかもしれません。 |
4092 | 3991 | |
4093 | 3992 | =begin original |
4094 | 3993 | |
4095 | 3994 | With an C<eval>, you should be especially careful to remember what's |
4096 | 3995 | being looked at when: |
4097 | 3996 | |
4098 | 3997 | =end original |
4099 | 3998 | |
4100 | 3999 | C<eval> では、以下のような場合に、 |
4101 | 4000 | 何が調べられるかに特に注意しておくことが必要です: |
4102 | 4001 | |
4103 | 4002 | eval $x; # CASE 1 |
4104 | 4003 | eval "$x"; # CASE 2 |
4105 | 4004 | |
4106 | 4005 | eval '$x'; # CASE 3 |
4107 | 4006 | eval { $x }; # CASE 4 |
4108 | 4007 | |
4109 | 4008 | eval "\$$x++"; # CASE 5 |
4110 | 4009 | $$x++; # CASE 6 |
4111 | 4010 | |
4112 | 4011 | =begin original |
4113 | 4012 | |
4114 | 4013 | Cases 1 and 2 above behave identically: they run the code contained in |
4115 | 4014 | the variable $x. (Although case 2 has misleading double quotes making |
4116 | 4015 | the reader wonder what else might be happening (nothing is).) Cases 3 |
4117 | 4016 | and 4 likewise behave in the same way: they run the code C<'$x'>, which |
4118 | 4017 | does nothing but return the value of $x. (Case 4 is preferred for |
4119 | 4018 | purely visual reasons, but it also has the advantage of compiling at |
4120 | 4019 | compile-time instead of at run-time.) Case 5 is a place where |
4121 | 4020 | normally you I<would> like to use double quotes, except that in this |
4122 | 4021 | particular situation, you can just use symbolic references instead, as |
4123 | 4022 | in case 6. |
4124 | 4023 | |
4125 | 4024 | =end original |
4126 | 4025 | |
4127 | 4026 | 上記の CASE 1 と CASE 2 の動作は同一で、変数 $x 内の |
4128 | 4027 | コードを実行します。 |
4129 | 4028 | (ただし、CASE 2 では、必要のないダブルクォートによって、 |
4130 | 4029 | 読む人が何が起こるか混乱することでしょう (何も起こりませんが)。) |
4131 | 4030 | 同様に CASE 3 と CASE 4 の動作も等しく、$x の値を返す以外に |
4132 | 4031 | 何もしない C<$x> というコードを実行します |
4133 | 4032 | (純粋に見た目の問題で、CASE 4 が好まれますが、 |
4134 | 4033 | 実行時でなくコンパイル時にコンパイルされるという利点もあります)。 |
4135 | 4034 | CASE 5 の場合は、通常ダブルクォートを使用します。 |
4136 | 4035 | この状況を除けば、CASE 6 のように、単に |
4137 | 4036 | シンボリックリファレンスを使えば良いでしょう。 |
4138 | 4037 | |
4139 | 4038 | =begin original |
4140 | 4039 | |
4141 | 4040 | Before Perl 5.14, the assignment to C<$@> occurred before restoration |
4142 | 4041 | of localized variables, which means that for your code to run on older |
4143 | 4042 | versions, a temporary is required if you want to mask some but not all |
4144 | 4043 | errors: |
4145 | 4044 | |
4146 | 4045 | =end original |
4147 | 4046 | |
4148 | 4047 | Perl 5.14 より前では、C<$@> への代入はローカル化された変数の復帰の前に |
4149 | 4048 | 起きるので、古いバージョンで実行される場合は、全てではなく一部だけの |
4150 | 4049 | エラーをマスクしたい場合には一時変数が必要です: |
4151 | 4050 | |
4152 | 4051 | # alter $@ on nefarious repugnancy only |
4153 | 4052 | { |
4154 | 4053 | my $e; |
4155 | 4054 | { |
4156 | local $@; # protect existing $@ | |
4055 | local $@; # protect existing $@ | |
4157 | eval { test_repugnancy() }; | |
4056 | eval { test_repugnancy() }; | |
4158 | # $@ =~ /nefarious/ and die $@; # Perl 5.14 and higher only | |
4057 | # $@ =~ /nefarious/ and die $@; # Perl 5.14 and higher only | |
4159 | $@ =~ /nefarious/ and $e = $@; | |
4058 | $@ =~ /nefarious/ and $e = $@; | |
4160 | 4059 | } |
4161 | 4060 | die $e if defined $e |
4162 | 4061 | } |
4163 | 4062 | |
4164 | 4063 | =begin original |
4165 | 4064 | |
4166 | 4065 | C<eval BLOCK> does I<not> count as a loop, so the loop control statements |
4167 | 4066 | C<next>, C<last>, or C<redo> cannot be used to leave or restart the block. |
4168 | 4067 | |
4169 | 4068 | =end original |
4170 | 4069 | |
4171 | 4070 | C<eval BLOCK> はループとして I<扱われません>; 従って、C<next>, C<last>, |
4172 | 4071 | C<redo> といったループ制御文でブロックから離れたり再実行したりはできません。 |
4173 | 4072 | |
4174 | 4073 | =begin original |
4175 | 4074 | |
4176 | An C<eval ''> executed within | |
4075 | An C<eval ''> executed within the C<DB> package doesn't see the usual | |
4177 | in the C<DB> package doesn't see the usual | |
4178 | 4076 | surrounding lexical scope, but rather the scope of the first non-DB piece |
4179 | 4077 | of code that called it. You don't normally need to worry about this unless |
4180 | 4078 | you are writing a Perl debugger. |
4181 | 4079 | |
4182 | 4080 | =end original |
4183 | 4081 | |
4184 | C<DB> パッケージ | |
4082 | C<DB> パッケージ内で C<eval ''> を実行すると、通常の | |
4185 | 4083 | レキシカルスコープではなく、これを呼び出した最初の非 DB コード片の |
4186 | 4084 | スコープになります。 |
4187 | 4085 | Perl デバッガを書いているのでない限り、普通はこれについて心配する必要は |
4188 | 4086 | ありません。 |
4189 | 4087 | |
4190 | 4088 | =item evalbytes EXPR |
4191 | 4089 | X<evalbytes> |
4192 | 4090 | |
4193 | 4091 | =item evalbytes |
4194 | 4092 | |
4195 | 4093 | =for Pod::Functions +evalbytes similar to string eval, but intend to parse a bytestream |
4196 | 4094 | |
4197 | 4095 | =begin original |
4198 | 4096 | |
4199 | 4097 | This function is like L</eval> with a string argument, except it always |
4200 | 4098 | parses its argument, or C<$_> if EXPR is omitted, as a string of bytes. A |
4201 | 4099 | string containing characters whose ordinal value exceeds 255 results in an |
4202 | 4100 | error. Source filters activated within the evaluated code apply to the |
4203 | 4101 | code itself. |
4204 | 4102 | |
4205 | 4103 | =end original |
4206 | 4104 | |
4207 | 4105 | この関数は文字列引数の L</eval> と同様ですが、引数(EXPR が省略された場合は |
4208 | 4106 | C<$_>) を常にバイト単位のの文字列として扱います。 |
4209 | 4107 | 序数が 255 を超える文字を含む文字列はエラーになります。 |
4210 | 4108 | eval されたコード内で有効になったソースフィルタはコード自体に適用されます。 |
4211 | 4109 | |
4212 | 4110 | =begin original |
4213 | 4111 | |
4214 | 4112 | This function is only available under the C<evalbytes> feature, a |
4215 | 4113 | C<use v5.16> (or higher) declaration, or with a C<CORE::> prefix. See |
4216 | 4114 | L<feature> for more information. |
4217 | 4115 | |
4218 | 4116 | =end original |
4219 | 4117 | |
4220 | 4118 | この関数は C<evalbytes> 機能が有効か、C<use v5.16> (またはそれ以上) が |
4221 | 4119 | 宣言されるか、C<CORE::> 接頭辞付きの場合にのみ有効です。 |
4222 | 4120 | さらなる情報については L<feature> を参照してください。 |
4223 | 4121 | |
4224 | 4122 | =item exec LIST |
4225 | 4123 | X<exec> X<execute> |
4226 | 4124 | |
4227 | 4125 | =item exec PROGRAM LIST |
4228 | 4126 | |
4229 | 4127 | =for Pod::Functions abandon this program to run another |
4230 | 4128 | |
4231 | 4129 | =begin original |
4232 | 4130 | |
4233 | 4131 | The C<exec> function executes a system command I<and never returns>; |
4234 | 4132 | use C<system> instead of C<exec> if you want it to return. It fails and |
4235 | 4133 | returns false only if the command does not exist I<and> it is executed |
4236 | 4134 | directly instead of via your system's command shell (see below). |
4237 | 4135 | |
4238 | 4136 | =end original |
4239 | 4137 | |
4240 | 4138 | C<exec> 関数は、システムのコマンドを実行し、I<戻ってはきません>; |
4241 | 4139 | 戻って欲しい場合には、C<exec>ではなく C<system> 関数を使ってください。 |
4242 | 4140 | コマンドが存在せず、I<しかも> システムのコマンドシェル経由でなく |
4243 | 4141 | 直接コマンドを実行しようとした場合にのみこの関数は失敗して偽を返します。 |
4244 | 4142 | |
4245 | 4143 | =begin original |
4246 | 4144 | |
4247 | 4145 | Since it's a common mistake to use C<exec> instead of C<system>, Perl |
4248 | 4146 | warns you if C<exec> is called in void context and if there is a following |
4249 | 4147 | statement that isn't C<die>, C<warn>, or C<exit> (if C<-w> is set--but |
4250 | 4148 | you always do that, right?). If you I<really> want to follow an C<exec> |
4251 | 4149 | with some other statement, you can use one of these styles to avoid the warning: |
4252 | 4150 | |
4253 | 4151 | =end original |
4254 | 4152 | |
4255 | 4153 | C<system> の代わりに C<exec> を使うというよくある間違いを防ぐために、 |
4256 | 4154 | C<exec> が無効コンテキストで呼び出されて、引き続く文が C<die>, C<warn>, |
4257 | 4155 | C<exit> 以外の場合、Perl は警告を出します(C<-w> がセットされている場合 -- |
4258 | 4156 | でもいつもセットしてますよね?)。 |
4259 | 4157 | もし I<本当に> C<exec> の後に他の文を書きたい場合、以下のどちらかの |
4260 | 4158 | スタイルを使うことで警告を回避できます: |
4261 | 4159 | |
4262 | 4160 | exec ('foo') or print STDERR "couldn't exec foo: $!"; |
4263 | 4161 | { exec ('foo') }; print STDERR "couldn't exec foo: $!"; |
4264 | 4162 | |
4265 | 4163 | =begin original |
4266 | 4164 | |
4267 | If there is more than one argument in LIST, | |
4165 | If there is more than one argument in LIST, or if LIST is an array | |
4268 | ||
4166 | with more than one value, calls execvp(3) with the arguments in LIST. | |
4269 | ||
4167 | If there is only one scalar argument or an array with one element in it, | |
4270 | argument is | |
4168 | the argument is checked for shell metacharacters, and if there are any, | |
4271 | ||
4169 | the entire argument is passed to the system's command shell for parsing | |
4272 | th | |
4170 | (this is C</bin/sh -c> on Unix platforms, but varies on other platforms). | |
4273 | ||
4171 | If there are no shell metacharacters in the argument, it is split into | |
4172 | words and passed directly to C<execvp>, which is more efficient. | |
4173 | Examples: | |
4274 | 4174 | |
4275 | 4175 | =end original |
4276 | 4176 | |
4277 | LIST に複数の引数がある場合 | |
4177 | LIST に複数の引数がある場合か、LIST が複数の値を持つ | |
4278 | ||
4178 | 配列の場合には、LIST の引数を使って、execvp(3) を呼び出します。 | |
4279 | ||
4179 | 1 つのスカラ引数のみまたは要素が一つの配列の場合には、その引数から | |
4180 | シェルのメタ文字をチェックし、もし、メタ文字があれば、 | |
4181 | 引数全体をシステムのコマンドシェル(これはUnix では | |
4280 | 4182 | C</bin/sh -c> ですが、システムによって異なります)に渡して解析させます。 |
4281 | 4183 | シェルのメタ文字がなかった場合、引数は単語に分解されて直接 C<execvp> に |
4282 | 4184 | 渡されます; この方がより効率的です。 |
4283 | 4185 | 例: |
4284 | 4186 | |
4285 | 4187 | exec '/bin/echo', 'Your arguments are: ', @ARGV; |
4286 | 4188 | exec "sort $outfile | uniq"; |
4287 | 4189 | |
4288 | 4190 | =begin original |
4289 | 4191 | |
4290 | 4192 | If you don't really want to execute the first argument, but want to lie |
4291 | 4193 | to the program you are executing about its own name, you can specify |
4292 | 4194 | the program you actually want to run as an "indirect object" (without a |
4293 | comma) in front of the LIST | |
4195 | comma) in front of the LIST. (This always forces interpretation of the | |
4294 | ||
4196 | LIST as a multivalued list, even if there is only a single scalar in | |
4295 | ||
4197 | the list.) Example: | |
4296 | 4198 | |
4297 | 4199 | =end original |
4298 | 4200 | |
4299 | 第一引数に指定するものを本当に実行したいが、実行する | |
4201 | 第一引数に指定するものを本当に実行したいが、実行する | |
4300 | 名前を教えたい場合には、 | |
4202 | プログラムに対して別の名前を教えたい場合には、LISTの前に、 | |
4301 | 「間接オブジェクト」(コンマなし) として実際に | |
4203 | 「間接オブジェクト」(コンマなし) として、実際に | |
4302 | 指定することができます。 | |
4204 | 実行したいプログラムを指定することができます。 | |
4303 | (これによって、LIST に単一のスカラしかなくても、複数 | |
4205 | (これによって、LIST に単一のスカラしかなくても、複数 | |
4304 | LIST の解釈を行ないます。) | |
4206 | 値のリストであるように、LIST の解釈を行ないます。) | |
4305 | 4207 | 例: |
4306 | 4208 | |
4307 | 4209 | $shell = '/bin/csh'; |
4308 | 4210 | exec $shell '-sh'; # pretend it's a login shell |
4309 | 4211 | |
4310 | 4212 | =begin original |
4311 | 4213 | |
4312 | 4214 | or, more directly, |
4313 | 4215 | |
4314 | 4216 | =end original |
4315 | 4217 | |
4316 | 4218 | あるいは、より直接的に、 |
4317 | 4219 | |
4318 | 4220 | exec {'/bin/csh'} '-sh'; # pretend it's a login shell |
4319 | 4221 | |
4320 | 4222 | =begin original |
4321 | 4223 | |
4322 | 4224 | When the arguments get executed via the system shell, results are |
4323 | 4225 | subject to its quirks and capabilities. See L<perlop/"`STRING`"> |
4324 | 4226 | for details. |
4325 | 4227 | |
4326 | 4228 | =end original |
4327 | 4229 | |
4328 | 4230 | 引数がシステムシェルで実行されるとき、結果はシェルの奇癖と能力によって |
4329 | 4231 | 変わります。 |
4330 | 4232 | 詳細については L<perlop/"`STRING`"> を参照してください。 |
4331 | 4233 | |
4332 | 4234 | =begin original |
4333 | 4235 | |
4334 | 4236 | Using an indirect object with C<exec> or C<system> is also more |
4335 | 4237 | secure. This usage (which also works fine with system()) forces |
4336 | 4238 | interpretation of the arguments as a multivalued list, even if the |
4337 | 4239 | list had just one argument. That way you're safe from the shell |
4338 | 4240 | expanding wildcards or splitting up words with whitespace in them. |
4339 | 4241 | |
4340 | 4242 | =end original |
4341 | 4243 | |
4342 | 4244 | C<exec> や C<system> で間接オブジェクトを使うのもより安全です。 |
4343 | 4245 | この使い方(system() でも同様にうまく動きます)は、たとえ引数が一つだけの |
4344 | 4246 | 場合も、複数の値を持つリストとして引数を解釈することを強制します。 |
4345 | 4247 | この方法で、シェルによるワイルドカード展開や、空白による単語の分割から |
4346 | 4248 | 守られます。 |
4347 | 4249 | |
4348 | 4250 | @args = ( "echo surprise" ); |
4349 | 4251 | |
4350 | 4252 | exec @args; # subject to shell escapes |
4351 | 4253 | # if @args == 1 |
4352 | 4254 | exec { $args[0] } @args; # safe even with one-arg list |
4353 | 4255 | |
4354 | 4256 | =begin original |
4355 | 4257 | |
4356 | 4258 | The first version, the one without the indirect object, ran the I<echo> |
4357 | 4259 | program, passing it C<"surprise"> an argument. The second version didn't; |
4358 | 4260 | it tried to run a program named I<"echo surprise">, didn't find it, and set |
4359 | 4261 | C<$?> to a non-zero value indicating failure. |
4360 | 4262 | |
4361 | 4263 | =end original |
4362 | 4264 | |
4363 | 4265 | 間接オブジェクトなしの一つ目のバージョンでは、I<echo> プログラムが実行され、 |
4364 | 4266 | C<"surprise"> が引数として渡されます。 |
4365 | 4267 | 二つ目のバージョンでは違います; I<"echo surprise"> という名前の |
4366 | 4268 | プログラムを実行しようとして、見つからないので、失敗したことを示すために |
4367 | 4269 | C<$?> に非 0 がセットされます。 |
4368 | 4270 | |
4369 | 4271 | =begin original |
4370 | 4272 | |
4371 | ||
4273 | Beginning with v5.6.0, Perl attempts to flush all files opened for | |
4372 | ||
4274 | output before the exec, but this may not be supported on some platforms | |
4373 | e | |
4275 | (see L<perlport>). To be safe, you may need to set C<$|> ($AUTOFLUSH | |
4276 | in English) or call the C<autoflush()> method of C<IO::Handle> on any | |
4277 | open handles to avoid lost output. | |
4374 | 4278 | |
4375 | 4279 | =end original |
4376 | 4280 | |
4377 | Windows では、C<exec PROGRAM LIST> 間接オブジェクト構文のみが、シェルを | |
4378 | 使うのを回避するための信頼できる方法です; C<exec LIST> は、複数の要素が | |
4379 | あっても、最初の spawn が失敗したときにシェルに | |
4380 | フォールバックすることがあります。 | |
4381 | ||
4382 | =begin original | |
4383 | ||
4384 | Perl attempts to flush all files opened for output before the exec, | |
4385 | but this may not be supported on some platforms (see L<perlport>). | |
4386 | To be safe, you may need to set C<$|> ($AUTOFLUSH in English) or | |
4387 | call the C<autoflush()> method of C<IO::Handle> on any open handles | |
4388 | to avoid lost output. | |
4389 | ||
4390 | =end original | |
4391 | ||
4392 | 4281 | v5.6.0 から、Perl は exec の前に出力用に開かれている全てのファイルを |
4393 | 4282 | フラッシュしようとしますが、これに対応していないプラットフォームもあります |
4394 | 4283 | (L<perlport> を参照してください)。 |
4395 | 4284 | 安全のためには、出力が重複するのを避けるために、全てのオープンしている |
4396 | 4285 | ハンドルに対して C<$|> (English モジュールでは $AUTOFLUSH) を設定するか、 |
4397 | 4286 | C<IO::Handle> モジュールの C<autoflush()> メソッドをを呼ぶ必要が |
4398 | 4287 | あるかもしれません。 |
4399 | 4288 | |
4400 | 4289 | =begin original |
4401 | 4290 | |
4402 | 4291 | Note that C<exec> will not call your C<END> blocks, nor will it invoke |
4403 | 4292 | C<DESTROY> methods on your objects. |
4404 | 4293 | |
4405 | 4294 | =end original |
4406 | 4295 | |
4407 | 4296 | C<exec> は C<END> ブロックや、オブジェクトの C<DESTROY> メソッドを |
4408 | 4297 | 起動しないことに注意してください。 |
4409 | 4298 | |
4410 | 4299 | =begin original |
4411 | 4300 | |
4412 | 4301 | Portability issues: L<perlport/exec>. |
4413 | 4302 | |
4414 | 4303 | =end original |
4415 | 4304 | |
4416 | 4305 | 移植性の問題: L<perlport/exec>。 |
4417 | 4306 | |
4418 | 4307 | =item exists EXPR |
4419 | 4308 | X<exists> X<autovivification> |
4420 | 4309 | |
4421 | 4310 | =for Pod::Functions test whether a hash key is present |
4422 | 4311 | |
4423 | 4312 | =begin original |
4424 | 4313 | |
4425 | 4314 | Given an expression that specifies an element of a hash, returns true if the |
4426 | 4315 | specified element in the hash has ever been initialized, even if the |
4427 | 4316 | corresponding value is undefined. |
4428 | 4317 | |
4429 | 4318 | =end original |
4430 | 4319 | |
4431 | 4320 | ハッシュ要素を示す表現が与えられ、指定された要素が、ハッシュに存在すれば、 |
4432 | 4321 | たとえ対応する値が未定義でも真を返します。 |
4433 | 4322 | |
4434 | 4323 | print "Exists\n" if exists $hash{$key}; |
4435 | 4324 | print "Defined\n" if defined $hash{$key}; |
4436 | 4325 | print "True\n" if $hash{$key}; |
4437 | 4326 | |
4438 | 4327 | =begin original |
4439 | 4328 | |
4440 | 4329 | exists may also be called on array elements, but its behavior is much less |
4441 | 4330 | obvious and is strongly tied to the use of L</delete> on arrays. B<Be aware> |
4442 | 4331 | that calling exists on array values is deprecated and likely to be removed in |
4443 | 4332 | a future version of Perl. |
4444 | 4333 | |
4445 | 4334 | =end original |
4446 | 4335 | |
4447 | 4336 | exists は配列の要素に対しても呼び出せますが、その振る舞いははるかに |
4448 | 4337 | 不明確で、配列に対する L</delete> の使用と強く結びついています。 |
4449 | 4338 | 配列の値に対して exists を呼び出すのは非推奨であり、将来のバージョンの |
4450 | 4339 | Perl では削除されるかもしれないことを B<注意してください> 。 |
4451 | 4340 | |
4452 | 4341 | print "Exists\n" if exists $array[$index]; |
4453 | 4342 | print "Defined\n" if defined $array[$index]; |
4454 | 4343 | print "True\n" if $array[$index]; |
4455 | 4344 | |
4456 | 4345 | =begin original |
4457 | 4346 | |
4458 | 4347 | A hash or array element can be true only if it's defined and defined only if |
4459 | 4348 | it exists, but the reverse doesn't necessarily hold true. |
4460 | 4349 | |
4461 | 4350 | =end original |
4462 | 4351 | |
4463 | 4352 | ハッシュまたは配列要素は、定義されているときにのみ真となり、 |
4464 | 4353 | 存在しているときにのみ定義されますが、逆は必ずしも真ではありません。 |
4465 | 4354 | |
4466 | 4355 | =begin original |
4467 | 4356 | |
4468 | 4357 | Given an expression that specifies the name of a subroutine, |
4469 | 4358 | returns true if the specified subroutine has ever been declared, even |
4470 | 4359 | if it is undefined. Mentioning a subroutine name for exists or defined |
4471 | 4360 | does not count as declaring it. Note that a subroutine that does not |
4472 | 4361 | exist may still be callable: its package may have an C<AUTOLOAD> |
4473 | 4362 | method that makes it spring into existence the first time that it is |
4474 | 4363 | called; see L<perlsub>. |
4475 | 4364 | |
4476 | 4365 | =end original |
4477 | 4366 | |
4478 | 4367 | 引数としてサブルーチンの名前が指定された場合、 |
4479 | 4368 | 指定されたサブルーチンが宣言されていれば(たとえ未定義でも) |
4480 | 4369 | 真を返します。 |
4481 | 4370 | exists や defined のために言及されているサブルーチン名は |
4482 | 4371 | 宣言としてのカウントに入りません。 |
4483 | 4372 | 存在しないサブルーチンでも呼び出し可能かもしれないことに注意してください: |
4484 | 4373 | パッケージが C<AUTOLOAD> メソッドを持っていて、最初に呼び出された時に |
4485 | 4374 | 存在を作り出すかもしれません; L<perlsub> を参照してください。 |
4486 | 4375 | |
4487 | 4376 | print "Exists\n" if exists &subroutine; |
4488 | 4377 | print "Defined\n" if defined &subroutine; |
4489 | 4378 | |
4490 | 4379 | =begin original |
4491 | 4380 | |
4492 | 4381 | Note that the EXPR can be arbitrarily complicated as long as the final |
4493 | 4382 | operation is a hash or array key lookup or subroutine name: |
4494 | 4383 | |
4495 | 4384 | =end original |
4496 | 4385 | |
4497 | 4386 | 最終的な操作がハッシュや配列の key による検索またはサブルーチン名である限りは、 |
4498 | 4387 | EXPR には任意の複雑な式を置くことができます: |
4499 | 4388 | |
4500 | 4389 | if (exists $ref->{A}->{B}->{$key}) { } |
4501 | 4390 | if (exists $hash{A}{B}{$key}) { } |
4502 | 4391 | |
4503 | 4392 | if (exists $ref->{A}->{B}->[$ix]) { } |
4504 | 4393 | if (exists $hash{A}{B}[$ix]) { } |
4505 | 4394 | |
4506 | 4395 | if (exists &{$ref->{A}{B}{$key}}) { } |
4507 | 4396 | |
4508 | 4397 | =begin original |
4509 | 4398 | |
4510 | 4399 | Although the most deeply nested array or hash element will not spring into |
4511 | 4400 | existence just because its existence was tested, any intervening ones will. |
4512 | 4401 | Thus C<< $ref->{"A"} >> and C<< $ref->{"A"}->{"B"} >> will spring |
4513 | 4402 | into existence due to the existence test for the $key element above. |
4514 | 4403 | This happens anywhere the arrow operator is used, including even here: |
4515 | 4404 | |
4516 | 4405 | =end original |
4517 | 4406 | |
4518 | 4407 | 最も深くネストした配列やハッシュの要素は、その存在をテストしただけでは |
4519 | 4408 | 存在するようにはなりませんが、途中のものは存在するようになります。 |
4520 | 4409 | 従って C<< $ref->{"A"} >> と C<< $ref->{"A"}->{"B"} >> は上記の $key の |
4521 | 4410 | 存在をテストしたことによって存在するようになります。 |
4522 | 4411 | これは、矢印演算子が使われるところでは、以下のようなものを含むどこででも |
4523 | 4412 | 起こります。 |
4524 | 4413 | |
4525 | 4414 | undef $ref; |
4526 | 4415 | if (exists $ref->{"Some key"}) { } |
4527 | 4416 | print $ref; # prints HASH(0x80d3d5c) |
4528 | 4417 | |
4529 | 4418 | =begin original |
4530 | 4419 | |
4531 | 4420 | This surprising autovivification in what does not at first--or even |
4532 | 4421 | second--glance appear to be an lvalue context may be fixed in a future |
4533 | 4422 | release. |
4534 | 4423 | |
4535 | 4424 | =end original |
4536 | 4425 | |
4537 | 4426 | 一目見ただけでは -- あるいは二目見ても -- 驚かされる、左辺値コンテキストでの |
4538 | 4427 | 自動有効化は将来のリリースでは修正されるでしょう。 |
4539 | 4428 | |
4540 | 4429 | =begin original |
4541 | 4430 | |
4542 | 4431 | Use of a subroutine call, rather than a subroutine name, as an argument |
4543 | 4432 | to exists() is an error. |
4544 | 4433 | |
4545 | 4434 | =end original |
4546 | 4435 | |
4547 | 4436 | exists() の引数としてサブルーチン名でなくサブルーチン呼び出しを使うと、 |
4548 | 4437 | エラーになります。 |
4549 | 4438 | |
4550 | 4439 | exists ⊂ # OK |
4551 | 4440 | exists &sub(); # Error |
4552 | 4441 | |
4553 | 4442 | =item exit EXPR |
4554 | 4443 | X<exit> X<terminate> X<abort> |
4555 | 4444 | |
4556 | 4445 | =item exit |
4557 | 4446 | |
4558 | 4447 | =for Pod::Functions terminate this program |
4559 | 4448 | |
4560 | 4449 | =begin original |
4561 | 4450 | |
4562 | 4451 | Evaluates EXPR and exits immediately with that value. Example: |
4563 | 4452 | |
4564 | 4453 | =end original |
4565 | 4454 | |
4566 | 4455 | EXPR を評価し、即座にその値を持って終了します。 |
4567 | 4456 | 例: |
4568 | 4457 | |
4569 | 4458 | $ans = <STDIN>; |
4570 | 4459 | exit 0 if $ans =~ /^[Xx]/; |
4571 | 4460 | |
4572 | 4461 | =begin original |
4573 | 4462 | |
4574 | 4463 | See also C<die>. If EXPR is omitted, exits with C<0> status. The only |
4575 | 4464 | universally recognized values for EXPR are C<0> for success and C<1> |
4576 | 4465 | for error; other values are subject to interpretation depending on the |
4577 | 4466 | environment in which the Perl program is running. For example, exiting |
4578 | 4467 | 69 (EX_UNAVAILABLE) from a I<sendmail> incoming-mail filter will cause |
4579 | 4468 | the mailer to return the item undelivered, but that's not true everywhere. |
4580 | 4469 | |
4581 | 4470 | =end original |
4582 | 4471 | |
4583 | 4472 | C<die> も参照してください。 |
4584 | 4473 | EXPR が省略された場合には、ステータスを C<0> として終了します。 |
4585 | 4474 | EXPR の値として広く利用可能なのは C<0> が成功で C<1> が |
4586 | 4475 | エラーということだけです; その他の値は、 Perl が実行される環境によって異なる |
4587 | 4476 | 解釈がされる可能性があります。 |
4588 | 4477 | 例えば、I<sendmail> 到着メールフィルタから 69 (EX_UNAVAILABLE) で終了すると |
4589 | 4478 | メーラーはアイテムを配達せずに差し戻しますが、 |
4590 | 4479 | これはいつでも真ではありません。 |
4591 | 4480 | |
4592 | 4481 | =begin original |
4593 | 4482 | |
4594 | 4483 | Don't use C<exit> to abort a subroutine if there's any chance that |
4595 | 4484 | someone might want to trap whatever error happened. Use C<die> instead, |
4596 | 4485 | which can be trapped by an C<eval>. |
4597 | 4486 | |
4598 | 4487 | =end original |
4599 | 4488 | |
4600 | 4489 | 誰かが発生したエラーをトラップしようと考えている可能性がある場合は、 |
4601 | 4490 | サブルーチンの中断に C<exit> を使わないでください。 |
4602 | 4491 | 代わりに C<eval> でトラップできる C<die> を使ってください。 |
4603 | 4492 | |
4604 | 4493 | =begin original |
4605 | 4494 | |
4606 | 4495 | The exit() function does not always exit immediately. It calls any |
4607 | 4496 | defined C<END> routines first, but these C<END> routines may not |
4608 | 4497 | themselves abort the exit. Likewise any object destructors that need to |
4609 | 4498 | be called are called before the real exit. C<END> routines and destructors |
4610 | 4499 | can change the exit status by modifying C<$?>. If this is a problem, you |
4611 | 4500 | can call C<POSIX::_exit($status)> to avoid END and destructor processing. |
4612 | 4501 | See L<perlmod> for details. |
4613 | 4502 | |
4614 | 4503 | =end original |
4615 | 4504 | |
4616 | 4505 | exit() 関数は常に直ちに終了するわけではありません。 |
4617 | 4506 | まず、定義されている END ルーチンを呼び出しますが、 |
4618 | 4507 | C<END> ルーチン自身は exit を止められません。 |
4619 | 4508 | 同様に、呼び出す必要のあるオブジェクトデストラクタは |
4620 | 4509 | すべて、実際の終了前に呼び出されます。 |
4621 | 4510 | C<END> ルーチンとデストラクタは C<$?> を修正することで終了コードを |
4622 | 4511 | 変更できます。 |
4623 | 4512 | これが問題になる場合は、END やデストラクタが実行されることを |
4624 | 4513 | 防ぐために C<POSIX::_exit($status)> を呼び出してください。 |
4625 | 4514 | 詳しくは L<perlmod> を参照してください。 |
4626 | 4515 | |
4627 | 4516 | =begin original |
4628 | 4517 | |
4629 | 4518 | Portability issues: L<perlport/exit>. |
4630 | 4519 | |
4631 | 4520 | =end original |
4632 | 4521 | |
4633 | 4522 | 移植性の問題: L<perlport/exit>。 |
4634 | 4523 | |
4635 | 4524 | =item exp EXPR |
4636 | 4525 | X<exp> X<exponential> X<antilog> X<antilogarithm> X<e> |
4637 | 4526 | |
4638 | 4527 | =item exp |
4639 | 4528 | |
4640 | 4529 | =for Pod::Functions raise I<e> to a power |
4641 | 4530 | |
4642 | 4531 | =begin original |
4643 | 4532 | |
4644 | 4533 | Returns I<e> (the natural logarithm base) to the power of EXPR. |
4645 | 4534 | If EXPR is omitted, gives C<exp($_)>. |
4646 | 4535 | |
4647 | 4536 | =end original |
4648 | 4537 | |
4649 | 4538 | I<e> (自然対数の底) の EXPR 乗を返します。 |
4650 | 4539 | EXPR を省略した場合には、C<exp($_)> を返します。 |
4651 | 4540 | |
4652 | 4541 | =item fc EXPR |
4653 | 4542 | X<fc> X<foldcase> X<casefold> X<fold-case> X<case-fold> |
4654 | 4543 | |
4655 | 4544 | =item fc |
4656 | 4545 | |
4657 | 4546 | =for Pod::Functions +fc return casefolded version of a string |
4658 | 4547 | |
4659 | 4548 | =begin original |
4660 | 4549 | |
4661 | 4550 | Returns the casefolded version of EXPR. This is the internal function |
4662 | 4551 | implementing the C<\F> escape in double-quoted strings. |
4663 | 4552 | |
4664 | 4553 | =end original |
4665 | 4554 | |
4666 | 4555 | EXPR の畳み込み版を返します。 |
4667 | 4556 | これは、ダブルクォート文字列における、C<\F> エスケープを |
4668 | 4557 | 実装する内部関数です。 |
4669 | 4558 | |
4670 | 4559 | =begin original |
4671 | 4560 | |
4672 | 4561 | Casefolding is the process of mapping strings to a form where case |
4673 | 4562 | differences are erased; comparing two strings in their casefolded |
4674 | 4563 | form is effectively a way of asking if two strings are equal, |
4675 | 4564 | regardless of case. |
4676 | 4565 | |
4677 | 4566 | =end original |
4678 | 4567 | |
4679 | 4568 | 畳み込みは大文字小文字の違いを消した形式に文字列をマッピングする処理です; |
4680 | 4569 | 畳み込み形式で二つの文字列を比較するのは二つの文字列が大文字小文字に |
4681 | 4570 | 関わらず等しいかどうかを比較する効率的な方法です。 |
4682 | 4571 | |
4683 | 4572 | =begin original |
4684 | 4573 | |
4685 | 4574 | Roughly, if you ever found yourself writing this |
4686 | 4575 | |
4687 | 4576 | =end original |
4688 | 4577 | |
4689 | 4578 | おおよそ、自分自身で以下のように書いていたとしても |
4690 | 4579 | |
4691 | lc($this) eq lc($that) | |
4580 | lc($this) eq lc($that) # Wrong! | |
4692 | 4581 | # or |
4693 | uc($this) eq uc($that) | |
4582 | uc($this) eq uc($that) # Also wrong! | |
4694 | 4583 | # or |
4695 | $this =~ / | |
4584 | $this =~ /\Q$that/i # Right! | |
4696 | 4585 | |
4697 | 4586 | =begin original |
4698 | 4587 | |
4699 | 4588 | Now you can write |
4700 | 4589 | |
4701 | 4590 | =end original |
4702 | 4591 | |
4703 | 4592 | 今では以下のように書けます |
4704 | 4593 | |
4705 | 4594 | fc($this) eq fc($that) |
4706 | 4595 | |
4707 | 4596 | =begin original |
4708 | 4597 | |
4709 | 4598 | And get the correct results. |
4710 | 4599 | |
4711 | 4600 | =end original |
4712 | 4601 | |
4713 | 4602 | そして正しい結果を得られます。 |
4714 | 4603 | |
4715 | 4604 | =begin original |
4716 | 4605 | |
4717 | Perl only implements the full form of casefolding | |
4606 | Perl only implements the full form of casefolding. | |
4718 | but you can access the simple folds using L<Unicode::UCD/casefold()> and | |
4719 | L<Unicode::UCD/prop_invmap()>. | |
4720 | 4607 | For further information on casefolding, refer to |
4721 | 4608 | the Unicode Standard, specifically sections 3.13 C<Default Case Operations>, |
4722 | 4609 | 4.2 C<Case-Normative>, and 5.18 C<Case Mappings>, |
4723 | 4610 | available at L<http://www.unicode.org/versions/latest/>, as well as the |
4724 | 4611 | Case Charts available at L<http://www.unicode.org/charts/case/>. |
4725 | 4612 | |
4726 | 4613 | =end original |
4727 | 4614 | |
4728 | Perl は完全な形式の畳み込みのみを実装しています | |
4615 | Perl は完全な形式の畳み込みのみを実装しています。 | |
4729 | L<Unicode::UCD/casefold()> と L<Unicode::UCD/prop_invmap()> を使って | |
4730 | 単純なたたみ込みにアクセスできます。 | |
4731 | 4616 | 畳み込みに関するさらなる情報については、 |
4732 | 4617 | L<http://www.unicode.org/versions/latest/> で利用可能な Unicode 標準、特に |
4733 | 4618 | 3.13 C<Default Case Operations>, 4.2 C<Case-Normative>, 5.18 |
4734 | 4619 | C<Case Mappings> および、L<http://www.unicode.org/charts/case/> で |
4735 | 4620 | 利用可能なケース表を参照してください。 |
4736 | 4621 | |
4737 | 4622 | =begin original |
4738 | 4623 | |
4739 | 4624 | If EXPR is omitted, uses C<$_>. |
4740 | 4625 | |
4741 | 4626 | =end original |
4742 | 4627 | |
4743 | 4628 | EXPR が省略されると、C<$_> を使います。 |
4744 | 4629 | |
4745 | 4630 | =begin original |
4746 | 4631 | |
4747 | This function behaves the same way under various pragma, such as | |
4632 | This function behaves the same way under various pragma, such as in a locale, | |
4748 | ||
4633 | as L</lc> does. | |
4749 | exception of C<fc> of LATIN CAPITAL LETTER SHARP S (U+1E9E) within the | |
4750 | scope of S<C<use locale>>. The foldcase of this character would | |
4751 | normally be C<"ss">, but as explained in the L</lc> section, case | |
4752 | changes that cross the 255/256 boundary are problematic under locales, | |
4753 | and are hence prohibited. Therefore, this function under locale returns | |
4754 | instead the string C<"\x{17F}\x{17F}">, which is the LATIN SMALL LETTER | |
4755 | LONG S. Since that character itself folds to C<"s">, the string of two | |
4756 | of them together should be equivalent to a single U+1E9E when foldcased. | |
4757 | 4634 | |
4758 | 4635 | =end original |
4759 | 4636 | |
4760 | この関数は、 | |
4637 | この関数は、ロケールのようなさまざまなプラグマの影響下では、 | |
4761 | ||
4638 | L</lc> と同様に振る舞います。 | |
4762 | スコープ内での LATIN CAPITAL LETTER SHARP S (U+1E9E) の C<fc> は例外です。 | |
4763 | この文字の畳み込み文字は普通は C<"ss"> ですが、L</lc> の節で | |
4764 | 説明しているように、ロケールの基での255/256 境界をまたぐ大文字小文字の変更は | |
4765 | 問題があるので、禁止されています。 | |
4766 | 従って、ロケールの基ではこの関数は代わりに LATIN SMALL LETTER LONG S である | |
4767 | C<"\x{17F}\x{17F}"> を返します。 | |
4768 | この文字自体は C<"s"> の畳み込みなので、これら二つを合わせた文字列は | |
4769 | 畳み込まれた場合は単一の U+1E9E と等価になります。 | |
4770 | 4639 | |
4771 | 4640 | =begin original |
4772 | 4641 | |
4773 | 4642 | While the Unicode Standard defines two additional forms of casefolding, |
4774 | 4643 | one for Turkic languages and one that never maps one character into multiple |
4775 | 4644 | characters, these are not provided by the Perl core; However, the CPAN module |
4776 | 4645 | C<Unicode::Casing> may be used to provide an implementation. |
4777 | 4646 | |
4778 | 4647 | =end original |
4779 | 4648 | |
4780 | 4649 | Unicode 標準はさらに二つの畳み込み形式、一つはツルキ語、もう一つは決して |
4781 | 4650 | 一つの文字が複数の文字にマッピングされないもの、を定義していますが、 |
4782 | 4651 | これらは Perl コアでは提供されません; しかし、CPAN モジュール |
4783 | 4652 | C<Unicode::Casing> が実装を提供しています。 |
4784 | 4653 | |
4785 | 4654 | =begin original |
4786 | 4655 | |
4787 | 4656 | This keyword is available only when the C<"fc"> feature is enabled, |
4788 | or when prefixed with C<CORE::>; See L<feature>. | |
4657 | or when prefixed with C<CORE::>; See L<feature>. Alternately, | |
4789 | 4658 | include a C<use v5.16> or later to the current scope. |
4790 | 4659 | |
4791 | 4660 | =end original |
4792 | 4661 | |
4793 | 4662 | このキーワードは C<"fc"> 機能が有効のときか、C<CORE::> が |
4794 | 4663 | 前置されたときにのみ利用可能です; L<feature> を参照してください。 |
4795 | 4664 | または、現在のスコープに C<use v5.16> またはそれ以上を含めてください。 |
4796 | 4665 | |
4797 | 4666 | =item fcntl FILEHANDLE,FUNCTION,SCALAR |
4798 | 4667 | X<fcntl> |
4799 | 4668 | |
4800 | 4669 | =for Pod::Functions file control system call |
4801 | 4670 | |
4802 | 4671 | =begin original |
4803 | 4672 | |
4804 | 4673 | Implements the fcntl(2) function. You'll probably have to say |
4805 | 4674 | |
4806 | 4675 | =end original |
4807 | 4676 | |
4808 | 4677 | fcntl(2) 関数を実装します。 |
4809 | 4678 | 正しい定数定義を得るために、まず |
4810 | 4679 | |
4811 | 4680 | use Fcntl; |
4812 | 4681 | |
4813 | 4682 | =begin original |
4814 | 4683 | |
4815 | 4684 | first to get the correct constant definitions. Argument processing and |
4816 | 4685 | value returned work just like C<ioctl> below. |
4817 | 4686 | For example: |
4818 | 4687 | |
4819 | 4688 | =end original |
4820 | 4689 | |
4821 | 4690 | と書くことが必要でしょう。 |
4822 | 4691 | 引数の処理と返り値については、下記の C<ioctl> と同様に動作します。 |
4823 | 4692 | 例えば: |
4824 | 4693 | |
4825 | 4694 | use Fcntl; |
4826 | 4695 | fcntl($filehandle, F_GETFL, $packed_return_buffer) |
4827 | 4696 | or die "can't fcntl F_GETFL: $!"; |
4828 | 4697 | |
4829 | 4698 | =begin original |
4830 | 4699 | |
4831 | 4700 | You don't have to check for C<defined> on the return from C<fcntl>. |
4832 | 4701 | Like C<ioctl>, it maps a C<0> return from the system call into |
4833 | 4702 | C<"0 but true"> in Perl. This string is true in boolean context and C<0> |
4834 | 4703 | in numeric context. It is also exempt from the normal B<-w> warnings |
4835 | 4704 | on improper numeric conversions. |
4836 | 4705 | |
4837 | 4706 | =end original |
4838 | 4707 | |
4839 | 4708 | C<fcntl> からの返り値のチェックに C<defined> を使う必要はありません。 |
4840 | 4709 | C<ioctl> と違って、C<fnctl> はシステムコールの結果が C<0> だった場合は |
4841 | 4710 | C<"0 だが真">を返します。 |
4842 | 4711 | この文字列は真偽値コンテキストでは真となり、 |
4843 | 4712 | 数値コンテキストでは C<0> になります。 |
4844 | 4713 | これはまた、不適切な数値変換に関する通常の B<-w> 警告を回避します。 |
4845 | 4714 | |
4846 | 4715 | =begin original |
4847 | 4716 | |
4848 | 4717 | Note that C<fcntl> raises an exception if used on a machine that |
4849 | 4718 | doesn't implement fcntl(2). See the Fcntl module or your fcntl(2) |
4850 | 4719 | manpage to learn what functions are available on your system. |
4851 | 4720 | |
4852 | 4721 | =end original |
4853 | 4722 | |
4854 | 4723 | fcntl(2) が実装されていないマシンでは、C<fcntl>は例外を |
4855 | 4724 | 引き起こすことに注意してください。 |
4856 | 4725 | システムでどの関数が利用可能かについては Fcntl モジュールや |
4857 | 4726 | fcntl(2) man ページを参照してください。 |
4858 | 4727 | |
4859 | 4728 | =begin original |
4860 | 4729 | |
4861 | 4730 | Here's an example of setting a filehandle named C<REMOTE> to be |
4862 | 4731 | non-blocking at the system level. You'll have to negotiate C<$|> |
4863 | 4732 | on your own, though. |
4864 | 4733 | |
4865 | 4734 | =end original |
4866 | 4735 | |
4867 | 4736 | これは C<REMOTE> というファイルハンドルをシステムレベルで |
4868 | 4737 | 非ブロックモードにセットする例です。 |
4869 | 4738 | ただし、 C<$|> を自分で管理しなければなりません。 |
4870 | 4739 | |
4871 | 4740 | use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK); |
4872 | 4741 | |
4873 | 4742 | $flags = fcntl(REMOTE, F_GETFL, 0) |
4874 | 4743 | or die "Can't get flags for the socket: $!\n"; |
4875 | 4744 | |
4876 | 4745 | $flags = fcntl(REMOTE, F_SETFL, $flags | O_NONBLOCK) |
4877 | 4746 | or die "Can't set flags for the socket: $!\n"; |
4878 | 4747 | |
4879 | 4748 | =begin original |
4880 | 4749 | |
4881 | 4750 | Portability issues: L<perlport/fcntl>. |
4882 | 4751 | |
4883 | 4752 | =end original |
4884 | 4753 | |
4885 | 4754 | 移植性の問題: L<perlport/fcntl>。 |
4886 | 4755 | |
4887 | 4756 | =item __FILE__ |
4888 | 4757 | X<__FILE__> |
4889 | 4758 | |
4890 | 4759 | =for Pod::Functions the name of the current source file |
4891 | 4760 | |
4892 | 4761 | =begin original |
4893 | 4762 | |
4894 | 4763 | A special token that returns the name of the file in which it occurs. |
4895 | 4764 | |
4896 | 4765 | =end original |
4897 | 4766 | |
4898 | 4767 | これが書いてあるファイルの名前を返す特殊トークン。 |
4899 | 4768 | |
4900 | 4769 | =item fileno FILEHANDLE |
4901 | 4770 | X<fileno> |
4902 | 4771 | |
4903 | 4772 | =for Pod::Functions return file descriptor from filehandle |
4904 | 4773 | |
4905 | 4774 | =begin original |
4906 | 4775 | |
4907 | 4776 | Returns the file descriptor for a filehandle, or undefined if the |
4908 | 4777 | filehandle is not open. If there is no real file descriptor at the OS |
4909 | 4778 | level, as can happen with filehandles connected to memory objects via |
4910 | 4779 | C<open> with a reference for the third argument, -1 is returned. |
4911 | 4780 | |
4912 | 4781 | =end original |
4913 | 4782 | |
4914 | 4783 | ファイルハンドルに対するファイル記述子を返します; ファイルハンドルが |
4915 | 4784 | オープンしていない場合は未定義値を返します。 |
4916 | 4785 | OS レベルで実際のファイル記述子がない(C<open> の第 3 引数にリファレンスを |
4917 | 4786 | 指定してファイルハンドルがメモリオブジェクトと結びつけられたときに |
4918 | 4787 | 起こります)場合、-1 が返されます。 |
4919 | 4788 | |
4920 | 4789 | =begin original |
4921 | 4790 | |
4922 | 4791 | This is mainly useful for constructing |
4923 | 4792 | bitmaps for C<select> and low-level POSIX tty-handling operations. |
4924 | 4793 | If FILEHANDLE is an expression, the value is taken as an indirect |
4925 | 4794 | filehandle, generally its name. |
4926 | 4795 | |
4927 | 4796 | =end original |
4928 | 4797 | |
4929 | 4798 | これは主に C<select> や低レベル POSIX tty 操作に対する、ビットマップを |
4930 | 4799 | 構成するときに便利です。 |
4931 | 4800 | FILEHANDLE が式であれば、 |
4932 | 4801 | その値が間接ファイルハンドル(普通は名前)として使われます。 |
4933 | 4802 | |
4934 | 4803 | =begin original |
4935 | 4804 | |
4936 | 4805 | You can use this to find out whether two handles refer to the |
4937 | 4806 | same underlying descriptor: |
4938 | 4807 | |
4939 | 4808 | =end original |
4940 | 4809 | |
4941 | 4810 | これを、二つのハンドルが同じ識別子を参照しているかどうかを見つけるのに |
4942 | 4811 | 使えます: |
4943 | 4812 | |
4944 | if (fileno(THIS) | |
4813 | if (fileno(THIS) == fileno(THAT)) { | |
4945 | 4814 | print "THIS and THAT are dups\n"; |
4946 | } elsif (fileno(THIS) != -1 && fileno(THAT) != -1) { | |
4947 | print "THIS and THAT have different " . | |
4948 | "underlying file descriptors\n"; | |
4949 | } else { | |
4950 | print "At least one of THIS and THAT does " . | |
4951 | "not have a real file descriptor\n"; | |
4952 | 4815 | } |
4953 | 4816 | |
4954 | 4817 | =item flock FILEHANDLE,OPERATION |
4955 | 4818 | X<flock> X<lock> X<locking> |
4956 | 4819 | |
4957 | 4820 | =for Pod::Functions lock an entire file with an advisory lock |
4958 | 4821 | |
4959 | 4822 | =begin original |
4960 | 4823 | |
4961 | 4824 | Calls flock(2), or an emulation of it, on FILEHANDLE. Returns true |
4962 | 4825 | for success, false on failure. Produces a fatal error if used on a |
4963 | 4826 | machine that doesn't implement flock(2), fcntl(2) locking, or lockf(3). |
4964 | 4827 | C<flock> is Perl's portable file-locking interface, although it locks |
4965 | 4828 | entire files only, not records. |
4966 | 4829 | |
4967 | 4830 | =end original |
4968 | 4831 | |
4969 | 4832 | FILEHANDLE に対して flock(2)、またはそのエミュレーションを呼び出します。 |
4970 | 4833 | 成功時には真を、失敗時には偽を返します。 |
4971 | 4834 | flock(2), fcntl(2) ロック, lockf(3) のいずれかを実装していない |
4972 | 4835 | マシンで使うと、致命的エラーが発生します。 |
4973 | 4836 | C<flock> は Perl の移植性のあるファイルロックインターフェースです; |
4974 | 4837 | しかしレコードではなく、ファイル全体のみをロックします。 |
4975 | 4838 | |
4976 | 4839 | =begin original |
4977 | 4840 | |
4978 | 4841 | Two potentially non-obvious but traditional C<flock> semantics are |
4979 | 4842 | that it waits indefinitely until the lock is granted, and that its locks |
4980 | 4843 | are B<merely advisory>. Such discretionary locks are more flexible, but |
4981 | 4844 | offer fewer guarantees. This means that programs that do not also use |
4982 | 4845 | C<flock> may modify files locked with C<flock>. See L<perlport>, |
4983 | 4846 | your port's specific documentation, and your system-specific local manpages |
4984 | 4847 | for details. It's best to assume traditional behavior if you're writing |
4985 | 4848 | portable programs. (But if you're not, you should as always feel perfectly |
4986 | 4849 | free to write for your own system's idiosyncrasies (sometimes called |
4987 | 4850 | "features"). Slavish adherence to portability concerns shouldn't get |
4988 | 4851 | in the way of your getting your job done.) |
4989 | 4852 | |
4990 | 4853 | =end original |
4991 | 4854 | |
4992 | 4855 | 明白ではないものの、伝統的な C<flock> の動作としては、ロックが得られるまで |
4993 | 4856 | 無限に待ち続けるものと、B<単に勧告的に> ロックするものの二つがあります。 |
4994 | 4857 | このような自由裁量のロックはより柔軟ですが、保障されるものはより少ないです。 |
4995 | 4858 | これは、C<flock> を使わないプログラムが C<flock> でロックされたファイルを |
4996 | 4859 | 書き換えるかもしれないことを意味します。 |
4997 | 4860 | 詳細については、L<perlport>、システム固有のドキュメント、システム固有の |
4998 | 4861 | ローカルの man ページを参照してください。 |
4999 | 4862 | 移植性のあるプログラムを書く場合は、伝統的な振る舞いを仮定するのが |
5000 | 4863 | ベストです。 |
5001 | 4864 | (しかし移植性のないプログラムを書く場合は、自身のシステムの性癖(しばしば |
5002 | 4865 | 「仕様」と呼ばれます)に合わせて書くことも完全に自由です。 |
5003 | 4866 | 盲目的に移植性に固執することで、あなたの作業を仕上げるのを邪魔するべきでは |
5004 | 4867 | ありません。) |
5005 | 4868 | |
5006 | 4869 | =begin original |
5007 | 4870 | |
5008 | 4871 | OPERATION is one of LOCK_SH, LOCK_EX, or LOCK_UN, possibly combined with |
5009 | 4872 | LOCK_NB. These constants are traditionally valued 1, 2, 8 and 4, but |
5010 | 4873 | you can use the symbolic names if you import them from the L<Fcntl> module, |
5011 | 4874 | either individually, or as a group using the C<:flock> tag. LOCK_SH |
5012 | 4875 | requests a shared lock, LOCK_EX requests an exclusive lock, and LOCK_UN |
5013 | 4876 | releases a previously requested lock. If LOCK_NB is bitwise-or'ed with |
5014 | 4877 | LOCK_SH or LOCK_EX, then C<flock> returns immediately rather than blocking |
5015 | 4878 | waiting for the lock; check the return status to see if you got it. |
5016 | 4879 | |
5017 | 4880 | =end original |
5018 | 4881 | |
5019 | 4882 | OPERATION は LOCK_SH, LOCK_EX, LOCK_UN のいずれかで、LOCK_NB と |
5020 | 4883 | 組み合わされることもあります。 |
5021 | 4884 | これらの定数は伝統的には 1, 2, 8, 4 の値を持ちますが、L<Fcntl> モジュールから |
5022 | 4885 | シンボル名を独立してインポートするか、C<:flock> タグを使うグループとして、 |
5023 | 4886 | シンボル名をを使うことができます。 |
5024 | 4887 | LOCK_SH は共有ロックを要求し、LOCK_EX は排他ロックを要求し、LOCK_UN は |
5025 | 4888 | 前回要求したロックを開放します。 |
5026 | 4889 | LOCK_NB と LOCK_SH か LOCK_EX がビット単位の論理和されると、C<flock> は |
5027 | 4890 | ロックを取得するまで待つのではなく、すぐに返ります; |
5028 | 4891 | ロックが取得できたかどうかは返り値を調べます。 |
5029 | 4892 | |
5030 | 4893 | =begin original |
5031 | 4894 | |
5032 | 4895 | To avoid the possibility of miscoordination, Perl now flushes FILEHANDLE |
5033 | 4896 | before locking or unlocking it. |
5034 | 4897 | |
5035 | 4898 | =end original |
5036 | 4899 | |
5037 | 4900 | 不一致の可能性を避けるために、Perl はファイルをロック、アンロックする前に |
5038 | 4901 | FILEHANDLE をフラッシュします。 |
5039 | 4902 | |
5040 | 4903 | =begin original |
5041 | 4904 | |
5042 | 4905 | Note that the emulation built with lockf(3) doesn't provide shared |
5043 | 4906 | locks, and it requires that FILEHANDLE be open with write intent. These |
5044 | 4907 | are the semantics that lockf(3) implements. Most if not all systems |
5045 | 4908 | implement lockf(3) in terms of fcntl(2) locking, though, so the |
5046 | 4909 | differing semantics shouldn't bite too many people. |
5047 | 4910 | |
5048 | 4911 | =end original |
5049 | 4912 | |
5050 | 4913 | lockf(3) で作成されたエミュレーションは共有ロックを提供せず、 |
5051 | 4914 | FILEHANDLE が書き込みモードで開いていることを必要とすることに |
5052 | 4915 | 注意してください。 |
5053 | 4916 | これは lockf(3) が実装している動作です。 |
5054 | 4917 | しかし、全てではないにしてもほとんどのシステムでは fcntl(2) を使って |
5055 | 4918 | lockf(3) を実装しているので、異なった動作で多くの人々を混乱させることは |
5056 | 4919 | ないはずです。 |
5057 | 4920 | |
5058 | 4921 | =begin original |
5059 | 4922 | |
5060 | 4923 | Note that the fcntl(2) emulation of flock(3) requires that FILEHANDLE |
5061 | 4924 | be open with read intent to use LOCK_SH and requires that it be open |
5062 | 4925 | with write intent to use LOCK_EX. |
5063 | 4926 | |
5064 | 4927 | =end original |
5065 | 4928 | |
5066 | 4929 | flock(3) の fcntl(2) エミュレーションは、 LOCK_SH を使うためには |
5067 | 4930 | FILEHANDLE を読み込みで開いている必要があり、LOCK_EX を使うためには |
5068 | 4931 | 書き込みで開いている必要があることに注意してください。 |
5069 | 4932 | |
5070 | 4933 | =begin original |
5071 | 4934 | |
5072 | 4935 | Note also that some versions of C<flock> cannot lock things over the |
5073 | 4936 | network; you would need to use the more system-specific C<fcntl> for |
5074 | 4937 | that. If you like you can force Perl to ignore your system's flock(2) |
5075 | 4938 | function, and so provide its own fcntl(2)-based emulation, by passing |
5076 | 4939 | the switch C<-Ud_flock> to the F<Configure> program when you configure |
5077 | 4940 | and build a new Perl. |
5078 | 4941 | |
5079 | 4942 | =end original |
5080 | 4943 | |
5081 | 4944 | ネットワーク越しにはロックできない C<flock> もあることに注意してください; |
5082 | 4945 | このためには、よりシステム依存な C<fcntl> を使う必要があります。 |
5083 | 4946 | Perl にシステムの flock(2) 関数を無視させ、自身の fcntl(2) ベースの |
5084 | 4947 | エミュレーションを使う場合は、新しい Perl を設定およびビルドするときに |
5085 | 4948 | F<Configure> プログラムに C<-Ud_flock> オプションを渡してください。 |
5086 | 4949 | |
5087 | 4950 | =begin original |
5088 | 4951 | |
5089 | 4952 | Here's a mailbox appender for BSD systems. |
5090 | 4953 | |
5091 | 4954 | =end original |
5092 | 4955 | |
5093 | 4956 | BSD システムでのメールボックスへの追加処理の例を示します。 |
5094 | 4957 | |
5095 | # import LOCK_* and SEEK_END constants | |
4958 | use Fcntl qw(:flock SEEK_END); # import LOCK_* and SEEK_END constants | |
5096 | use Fcntl qw(:flock SEEK_END); | |
5097 | 4959 | |
5098 | 4960 | sub lock { |
5099 | 4961 | my ($fh) = @_; |
5100 | 4962 | flock($fh, LOCK_EX) or die "Cannot lock mailbox - $!\n"; |
5101 | 4963 | |
5102 | 4964 | # and, in case someone appended while we were waiting... |
5103 | 4965 | seek($fh, 0, SEEK_END) or die "Cannot seek - $!\n"; |
5104 | 4966 | } |
5105 | 4967 | |
5106 | 4968 | sub unlock { |
5107 | 4969 | my ($fh) = @_; |
5108 | 4970 | flock($fh, LOCK_UN) or die "Cannot unlock mailbox - $!\n"; |
5109 | 4971 | } |
5110 | 4972 | |
5111 | 4973 | open(my $mbox, ">>", "/usr/spool/mail/$ENV{'USER'}") |
5112 | 4974 | or die "Can't open mailbox: $!"; |
5113 | 4975 | |
5114 | 4976 | lock($mbox); |
5115 | 4977 | print $mbox $msg,"\n\n"; |
5116 | 4978 | unlock($mbox); |
5117 | 4979 | |
5118 | 4980 | =begin original |
5119 | 4981 | |
5120 | 4982 | On systems that support a real flock(2), locks are inherited across fork() |
5121 | 4983 | calls, whereas those that must resort to the more capricious fcntl(2) |
5122 | 4984 | function lose their locks, making it seriously harder to write servers. |
5123 | 4985 | |
5124 | 4986 | =end original |
5125 | 4987 | |
5126 | 4988 | 真の flock(2) に対応しているシステムではロックは fork() を通して |
5127 | 4989 | 継承されるのに対して、より不安定な fcntl(2) に頼らなければならない場合、 |
5128 | 4990 | サーバを書くのは本当により難しくなります。 |
5129 | 4991 | |
5130 | 4992 | =begin original |
5131 | 4993 | |
5132 | 4994 | See also L<DB_File> for other flock() examples. |
5133 | 4995 | |
5134 | 4996 | =end original |
5135 | 4997 | |
5136 | 4998 | その他の flock() の例としては L<DB_File> も参照してください。 |
5137 | 4999 | |
5138 | 5000 | =begin original |
5139 | 5001 | |
5140 | 5002 | Portability issues: L<perlport/flock>. |
5141 | 5003 | |
5142 | 5004 | =end original |
5143 | 5005 | |
5144 | 5006 | 移植性の問題: L<perlport/flock>。 |
5145 | 5007 | |
5146 | 5008 | =item fork |
5147 | 5009 | X<fork> X<child> X<parent> |
5148 | 5010 | |
5149 | 5011 | =for Pod::Functions create a new process just like this one |
5150 | 5012 | |
5151 | 5013 | =begin original |
5152 | 5014 | |
5153 | 5015 | Does a fork(2) system call to create a new process running the |
5154 | 5016 | same program at the same point. It returns the child pid to the |
5155 | 5017 | parent process, C<0> to the child process, or C<undef> if the fork is |
5156 | 5018 | unsuccessful. File descriptors (and sometimes locks on those descriptors) |
5157 | 5019 | are shared, while everything else is copied. On most systems supporting |
5158 | 5020 | fork(), great care has gone into making it extremely efficient (for |
5159 | 5021 | example, using copy-on-write technology on data pages), making it the |
5160 | 5022 | dominant paradigm for multitasking over the last few decades. |
5161 | 5023 | |
5162 | 5024 | =end original |
5163 | 5025 | |
5164 | 5026 | 同じプログラムの同じ地点から開始する新しいプロセスを作成するために |
5165 | 5027 | システムコール fork(2) を行ないます。 |
5166 | 5028 | 親プロセスには、チャイルドプロセスの pid を、 |
5167 | 5029 | チャイルドプロセスに C<0> を返しますが、 |
5168 | 5030 | fork に失敗したときには、C<undef>を返します。 |
5169 | 5031 | ファイル記述子(および記述子に関連するロック)は共有され、 |
5170 | 5032 | その他の全てはコピーされます。 |
5171 | 5033 | fork() に対応するほとんどのシステムでは、 |
5172 | 5034 | これを極めて効率的にするために多大な努力が払われてきました |
5173 | 5035 | (例えば、データページへの copy-on-write テクノロジーなどです); |
5174 | 5036 | これはここ 20 年にわたるマルチタスクに関する主要なパラダイムとなっています。 |
5175 | 5037 | |
5176 | 5038 | =begin original |
5177 | 5039 | |
5178 | Perl attempts to flush all files opened for | |
5040 | Beginning with v5.6.0, Perl attempts to flush all files opened for | |
5179 | 5041 | output before forking the child process, but this may not be supported |
5180 | 5042 | on some platforms (see L<perlport>). To be safe, you may need to set |
5181 | 5043 | C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method of |
5182 | 5044 | C<IO::Handle> on any open handles to avoid duplicate output. |
5183 | 5045 | |
5184 | 5046 | =end original |
5185 | 5047 | |
5186 | 5048 | v5.6.0 から、Perl は子プロセスを fork する前に出力用にオープンしている全ての |
5187 | 5049 | ファイルをフラッシュしようとしますが、これに対応していないプラットフォームも |
5188 | 5050 | あります(L<perlport> を参照してください)。 |
5189 | 5051 | 安全のためには、出力が重複するのを避けるために、 |
5190 | 5052 | 全てのオープンしているハンドルに対して C<$|> (English モジュールでは |
5191 | 5053 | $AUTOFLUSH) を設定するか、 |
5192 | 5054 | C<IO::Handle> モジュールの C<autoflush()>メソッドをを呼ぶ必要が |
5193 | 5055 | あるかもしれません。 |
5194 | 5056 | |
5195 | 5057 | =begin original |
5196 | 5058 | |
5197 | 5059 | If you C<fork> without ever waiting on your children, you will |
5198 | 5060 | accumulate zombies. On some systems, you can avoid this by setting |
5199 | 5061 | C<$SIG{CHLD}> to C<"IGNORE">. See also L<perlipc> for more examples of |
5200 | 5062 | forking and reaping moribund children. |
5201 | 5063 | |
5202 | 5064 | =end original |
5203 | 5065 | |
5204 | 5066 | チャイルドプロセスの終了を待たずに、C<fork> を繰り返せば、 |
5205 | 5067 | ゾンビをためこむことになります。 |
5206 | 5068 | C<$SIG{CHLD}> に C<"IGNORE"> を指定することでこれを回避できるシステムもあります。 |
5207 | 5069 | fork と消滅しかけている子プロセスを回収するための更なる例については |
5208 | 5070 | L<perlipc> も参照してください。 |
5209 | 5071 | |
5210 | 5072 | =begin original |
5211 | 5073 | |
5212 | 5074 | Note that if your forked child inherits system file descriptors like |
5213 | 5075 | STDIN and STDOUT that are actually connected by a pipe or socket, even |
5214 | 5076 | if you exit, then the remote server (such as, say, a CGI script or a |
5215 | 5077 | backgrounded job launched from a remote shell) won't think you're done. |
5216 | 5078 | You should reopen those to F</dev/null> if it's any issue. |
5217 | 5079 | |
5218 | 5080 | =end original |
5219 | 5081 | |
5220 | 5082 | fork した子プロセスが STDIN や STDOUT といったシステムファイル記述子を |
5221 | 5083 | 継承する場合、(CGI スクリプトやリモートシェルといった |
5222 | 5084 | バックグラウンドジョブのような)リモートサーバは考え通りに |
5223 | 5085 | 動かないであろうことに注意してください。 |
5224 | 5086 | このような場合ではこれらを F</dev/null> として再オープンするべきです。 |
5225 | 5087 | |
5226 | 5088 | =begin original |
5227 | 5089 | |
5228 | 5090 | On some platforms such as Windows, where the fork() system call is not available, |
5229 | 5091 | Perl can be built to emulate fork() in the Perl interpreter. |
5230 | 5092 | The emulation is designed, at the level of the Perl program, |
5231 | 5093 | to be as compatible as possible with the "Unix" fork(). |
5232 | 5094 | However it has limitations that have to be considered in code intended to be portable. |
5233 | 5095 | See L<perlfork> for more details. |
5234 | 5096 | |
5235 | 5097 | =end original |
5236 | 5098 | |
5237 | 5099 | Windows のような fork() が利用不能なシステムでは、Perl は fork() を Perl |
5238 | 5100 | インタプリタでエミュレートします。 |
5239 | 5101 | エミュレーションは Perl プログラムのレベルではできるだけ "Unix" fork() と |
5240 | 5102 | 互換性があるように設計されています。 |
5241 | 5103 | しかしコードが移植性があると考えられるように制限があります。 |
5242 | 5104 | さらなる詳細については L<perlfork> を参照してください。 |
5243 | 5105 | |
5244 | 5106 | =begin original |
5245 | 5107 | |
5246 | 5108 | Portability issues: L<perlport/fork>. |
5247 | 5109 | |
5248 | 5110 | =end original |
5249 | 5111 | |
5250 | 5112 | 移植性の問題: L<perlport/fork>。 |
5251 | 5113 | |
5252 | 5114 | =item format |
5253 | 5115 | X<format> |
5254 | 5116 | |
5255 | 5117 | =for Pod::Functions declare a picture format with use by the write() function |
5256 | 5118 | |
5257 | 5119 | =begin original |
5258 | 5120 | |
5259 | 5121 | Declare a picture format for use by the C<write> function. For |
5260 | 5122 | example: |
5261 | 5123 | |
5262 | 5124 | =end original |
5263 | 5125 | |
5264 | 5126 | C<write> 関数で使うピクチャーフォーマットを宣言します。 |
5265 | 5127 | 例えば: |
5266 | 5128 | |
5267 | 5129 | format Something = |
5268 | 5130 | Test: @<<<<<<<< @||||| @>>>>> |
5269 | 5131 | $str, $%, '$' . int($num) |
5270 | 5132 | . |
5271 | 5133 | |
5272 | 5134 | $str = "widget"; |
5273 | 5135 | $num = $cost/$quantity; |
5274 | 5136 | $~ = 'Something'; |
5275 | 5137 | write; |
5276 | 5138 | |
5277 | 5139 | =begin original |
5278 | 5140 | |
5279 | 5141 | See L<perlform> for many details and examples. |
5280 | 5142 | |
5281 | 5143 | =end original |
5282 | 5144 | |
5283 | 5145 | 詳細と例については L<perlform> を参照してください。 |
5284 | 5146 | |
5285 | 5147 | =item formline PICTURE,LIST |
5286 | 5148 | X<formline> |
5287 | 5149 | |
5288 | 5150 | =for Pod::Functions internal function used for formats |
5289 | 5151 | |
5290 | 5152 | =begin original |
5291 | 5153 | |
5292 | 5154 | This is an internal function used by C<format>s, though you may call it, |
5293 | 5155 | too. It formats (see L<perlform>) a list of values according to the |
5294 | 5156 | contents of PICTURE, placing the output into the format output |
5295 | 5157 | accumulator, C<$^A> (or C<$ACCUMULATOR> in English). |
5296 | 5158 | Eventually, when a C<write> is done, the contents of |
5297 | 5159 | C<$^A> are written to some filehandle. You could also read C<$^A> |
5298 | 5160 | and then set C<$^A> back to C<"">. Note that a format typically |
5299 | 5161 | does one C<formline> per line of form, but the C<formline> function itself |
5300 | 5162 | doesn't care how many newlines are embedded in the PICTURE. This means |
5301 | 5163 | that the C<~> and C<~~> tokens treat the entire PICTURE as a single line. |
5302 | 5164 | You may therefore need to use multiple formlines to implement a single |
5303 | 5165 | record format, just like the C<format> compiler. |
5304 | 5166 | |
5305 | 5167 | =end original |
5306 | 5168 | |
5307 | 5169 | これは、C<format> が使用する内部関数ですが、直接呼び出すこともできます。 |
5308 | 5170 | これは、PICTURE の内容にしたがって、LIST の値を整形し (L<perlform> を |
5309 | 5171 | 参照してください)、結果をフォーマット出力アキュムレータC<$^A> |
5310 | 5172 | (English モジュールでは C<$ACCUMULATOR>) に納めます。 |
5311 | 5173 | 最終的に、C<write> が実行されると、C<$^A> の中身が、 |
5312 | 5174 | 何らかのファイルハンドルに書き出されます。 |
5313 | 5175 | また、自分で C<$^A> を読んで、C<$^A> の内容を C<""> に戻してもかまいません。 |
5314 | 5176 | format は通常、1 行ごとに C<formline> を行ないますが、 |
5315 | 5177 | C<formline> 関数自身は、PICTURE の中にいくつの改行が入っているかは、 |
5316 | 5178 | 関係がありません。 |
5317 | 5179 | これは、C<~> と C<~~>トークンは PICTURE 全体を一行として扱うことを意味します。 |
5318 | 5180 | 従って、1 レコードフォーマットを実装するためには |
5319 | 5181 | フォーマットコンパイラのような複数 formline を使う必要があります。 |
5320 | 5182 | |
5321 | 5183 | =begin original |
5322 | 5184 | |
5323 | 5185 | Be careful if you put double quotes around the picture, because an C<@> |
5324 | 5186 | character may be taken to mean the beginning of an array name. |
5325 | 5187 | C<formline> always returns true. See L<perlform> for other examples. |
5326 | 5188 | |
5327 | 5189 | =end original |
5328 | 5190 | |
5329 | 5191 | ダブルクォートで PICTURE を囲む場合には、C<@> という文字が |
5330 | 5192 | 配列名の始まりと解釈されますので、注意してください。 |
5331 | 5193 | C<formline> は常に真を返します。 |
5332 | 5194 | その他の例については L<perlform> を参照してください。 |
5333 | 5195 | |
5334 | 5196 | =begin original |
5335 | 5197 | |
5336 | 5198 | If you are trying to use this instead of C<write> to capture the output, |
5337 | 5199 | you may find it easier to open a filehandle to a scalar |
5338 | 5200 | (C<< open $fh, ">", \$output >>) and write to that instead. |
5339 | 5201 | |
5340 | 5202 | =end original |
5341 | 5203 | |
5342 | 5204 | 出力を捕捉するために C<write> の代わりにこれを使おうとした場合、 |
5343 | 5205 | スカラにファイルハンドルを開いて (C<< open $fh, ">", \$output >>)、 |
5344 | 5206 | 代わりにここに出力する方が簡単であることに気付くでしょう。 |
5345 | 5207 | |
5346 | 5208 | =item getc FILEHANDLE |
5347 | 5209 | X<getc> X<getchar> X<character> X<file, read> |
5348 | 5210 | |
5349 | 5211 | =item getc |
5350 | 5212 | |
5351 | 5213 | =for Pod::Functions get the next character from the filehandle |
5352 | 5214 | |
5353 | 5215 | =begin original |
5354 | 5216 | |
5355 | 5217 | Returns the next character from the input file attached to FILEHANDLE, |
5356 | 5218 | or the undefined value at end of file or if there was an error (in |
5357 | 5219 | the latter case C<$!> is set). If FILEHANDLE is omitted, reads from |
5358 | 5220 | STDIN. This is not particularly efficient. However, it cannot be |
5359 | 5221 | used by itself to fetch single characters without waiting for the user |
5360 | 5222 | to hit enter. For that, try something more like: |
5361 | 5223 | |
5362 | 5224 | =end original |
5363 | 5225 | |
5364 | 5226 | FILEHANDLE につながれている入力ファイルから、次の一文字を返します; |
5365 | 5227 | ファイルの最後、またはエラーが発生した場合は、未定義値を返します |
5366 | 5228 | (後者の場合は C<$!> がセットされます)。 |
5367 | 5229 | FILEHANDLE が省略された場合には、STDIN から読み込みを行ないます。 |
5368 | 5230 | これは特に効率的ではありません。 |
5369 | 5231 | しかし、これはユーザーがリターンキーを押すのを待つことなく |
5370 | 5232 | 一文字を読み込む用途には使えません。 |
5371 | 5233 | そのような場合には、以下のようなものを試して見てください: |
5372 | 5234 | |
5373 | 5235 | if ($BSD_STYLE) { |
5374 | 5236 | system "stty cbreak </dev/tty >/dev/tty 2>&1"; |
5375 | 5237 | } |
5376 | 5238 | else { |
5377 | 5239 | system "stty", '-icanon', 'eol', "\001"; |
5378 | 5240 | } |
5379 | 5241 | |
5380 | 5242 | $key = getc(STDIN); |
5381 | 5243 | |
5382 | 5244 | if ($BSD_STYLE) { |
5383 | 5245 | system "stty -cbreak </dev/tty >/dev/tty 2>&1"; |
5384 | 5246 | } |
5385 | 5247 | else { |
5386 | 5248 | system 'stty', 'icanon', 'eol', '^@'; # ASCII NUL |
5387 | 5249 | } |
5388 | 5250 | print "\n"; |
5389 | 5251 | |
5390 | 5252 | =begin original |
5391 | 5253 | |
5392 | 5254 | Determination of whether $BSD_STYLE should be set |
5393 | 5255 | is left as an exercise to the reader. |
5394 | 5256 | |
5395 | 5257 | =end original |
5396 | 5258 | |
5397 | 5259 | $BSD_STYLE をセットするべきかどうかを決定する方法については |
5398 | 5260 | 読者への宿題として残しておきます。 |
5399 | 5261 | |
5400 | 5262 | =begin original |
5401 | 5263 | |
5402 | 5264 | The C<POSIX::getattr> function can do this more portably on |
5403 | 5265 | systems purporting POSIX compliance. See also the C<Term::ReadKey> |
5404 | module from your nearest | |
5266 | module from your nearest CPAN site; details on CPAN can be found under | |
5267 | L<perlmodlib/CPAN>. | |
5405 | 5268 | |
5406 | 5269 | =end original |
5407 | 5270 | |
5408 | 5271 | C<POSIX::getattr> 関数は POSIX 準拠を主張するシステムでこれを |
5409 | 5272 | より移植性のある形で行います。 |
5410 | ||
5273 | お近くの CPAN サイトから C<Term::ReadKey> モジュールも参照してください; | |
5411 | ||
5274 | CPAN に関する詳細は L<perlmodlib/CPAN> にあります。 | |
5412 | 5275 | |
5413 | 5276 | =item getlogin |
5414 | 5277 | X<getlogin> X<login> |
5415 | 5278 | |
5416 | 5279 | =for Pod::Functions return who logged in at this tty |
5417 | 5280 | |
5418 | 5281 | =begin original |
5419 | 5282 | |
5420 | 5283 | This implements the C library function of the same name, which on most |
5421 | 5284 | systems returns the current login from F</etc/utmp>, if any. If it |
5422 | 5285 | returns the empty string, use C<getpwuid>. |
5423 | 5286 | |
5424 | 5287 | =end original |
5425 | 5288 | |
5426 | 5289 | これは同じ名前の C ライブラリ関数を実装していて、 |
5427 | 5290 | 多くのシステムでは、もしあれば、/etc/utmp から現在のログイン名を返します。 |
5428 | 5291 | もし空文字列が返ってきた場合は、getpwuid() を使ってください。 |
5429 | 5292 | |
5430 | 5293 | $login = getlogin || getpwuid($<) || "Kilroy"; |
5431 | 5294 | |
5432 | 5295 | =begin original |
5433 | 5296 | |
5434 | 5297 | Do not consider C<getlogin> for authentication: it is not as |
5435 | 5298 | secure as C<getpwuid>. |
5436 | 5299 | |
5437 | 5300 | =end original |
5438 | 5301 | |
5439 | 5302 | C<getlogin> を認証に使ってはいけません: これは C<getpwuid> のように |
5440 | 5303 | 安全ではありません。 |
5441 | 5304 | |
5442 | 5305 | =begin original |
5443 | 5306 | |
5444 | 5307 | Portability issues: L<perlport/getlogin>. |
5445 | 5308 | |
5446 | 5309 | =end original |
5447 | 5310 | |
5448 | 5311 | 移植性の問題: L<perlport/getlogin>。 |
5449 | 5312 | |
5450 | 5313 | =item getpeername SOCKET |
5451 | 5314 | X<getpeername> X<peer> |
5452 | 5315 | |
5453 | 5316 | =for Pod::Functions find the other end of a socket connection |
5454 | 5317 | |
5455 | 5318 | =begin original |
5456 | 5319 | |
5457 | 5320 | Returns the packed sockaddr address of the other end of the SOCKET |
5458 | 5321 | connection. |
5459 | 5322 | |
5460 | 5323 | =end original |
5461 | 5324 | |
5462 | 5325 | SOCKET コネクションの向こう側のパックされた aockaddr アドレスを返します。 |
5463 | 5326 | |
5464 | 5327 | use Socket; |
5465 | 5328 | $hersockaddr = getpeername(SOCK); |
5466 | 5329 | ($port, $iaddr) = sockaddr_in($hersockaddr); |
5467 | 5330 | $herhostname = gethostbyaddr($iaddr, AF_INET); |
5468 | 5331 | $herstraddr = inet_ntoa($iaddr); |
5469 | 5332 | |
5470 | 5333 | =item getpgrp PID |
5471 | 5334 | X<getpgrp> X<group> |
5472 | 5335 | |
5473 | 5336 | =for Pod::Functions get process group |
5474 | 5337 | |
5475 | 5338 | =begin original |
5476 | 5339 | |
5477 | 5340 | Returns the current process group for the specified PID. Use |
5478 | 5341 | a PID of C<0> to get the current process group for the |
5479 | 5342 | current process. Will raise an exception if used on a machine that |
5480 | 5343 | doesn't implement getpgrp(2). If PID is omitted, returns the process |
5481 | 5344 | group of the current process. Note that the POSIX version of C<getpgrp> |
5482 | 5345 | does not accept a PID argument, so only C<PID==0> is truly portable. |
5483 | 5346 | |
5484 | 5347 | =end original |
5485 | 5348 | |
5486 | 5349 | 指定された PID の現在のプロセスグループを返します。 |
5487 | 5350 | PID に C<0> を与えるとカレントプロセスの指定となります。 |
5488 | 5351 | getpgrp(2) を実装していないマシンで実行した場合には、例外が発生します。 |
5489 | 5352 | PID を省略するとカレントプロセスのプロセスグループを返します。 |
5490 | 5353 | POSIX 版の C<getpgrp> は PID 引数を受け付けないので、 |
5491 | 5354 | C<PID==0> のみが完全に移植性があります。 |
5492 | 5355 | |
5493 | 5356 | =begin original |
5494 | 5357 | |
5495 | 5358 | Portability issues: L<perlport/getpgrp>. |
5496 | 5359 | |
5497 | 5360 | =end original |
5498 | 5361 | |
5499 | 5362 | 移植性の問題: L<perlport/getpgrp>。 |
5500 | 5363 | |
5501 | 5364 | =item getppid |
5502 | 5365 | X<getppid> X<parent> X<pid> |
5503 | 5366 | |
5504 | 5367 | =for Pod::Functions get parent process ID |
5505 | 5368 | |
5506 | 5369 | =begin original |
5507 | 5370 | |
5508 | 5371 | Returns the process id of the parent process. |
5509 | 5372 | |
5510 | 5373 | =end original |
5511 | 5374 | |
5512 | 5375 | 親プロセスのプロセス id を返します。 |
5513 | 5376 | |
5514 | 5377 | =begin original |
5515 | 5378 | |
5516 | 5379 | Note for Linux users: Between v5.8.1 and v5.16.0 Perl would work |
5517 | 5380 | around non-POSIX thread semantics the minority of Linux systems (and |
5518 | 5381 | Debian GNU/kFreeBSD systems) that used LinuxThreads, this emulation |
5519 | has since been removed. | |
5382 | has since been removed. See the documentation for L<$$|perlvar/$$> for | |
5520 | 5383 | details. |
5521 | 5384 | |
5522 | 5385 | =end original |
5523 | 5386 | |
5524 | 5387 | Linux ユーザーへの注意: v5.8.1 から v5.16.0 の間 Perl は |
5525 | 5388 | LinuxThreads という非 POSIX なスレッド文法を使っているマイナーな |
5526 | 5389 | Linux システム (および Debian GNU/kFreeBSD システム) に対応していました。 |
5527 | 5390 | このエミュレーションは削除されました; |
5528 | 5391 | 詳しくは L<$$|perlvar/$$> の文書を参照してください。 |
5529 | 5392 | |
5530 | 5393 | =begin original |
5531 | 5394 | |
5532 | 5395 | Portability issues: L<perlport/getppid>. |
5533 | 5396 | |
5534 | 5397 | =end original |
5535 | 5398 | |
5536 | 5399 | 移植性の問題: L<perlport/getppid>。 |
5537 | 5400 | |
5538 | 5401 | =item getpriority WHICH,WHO |
5539 | 5402 | X<getpriority> X<priority> X<nice> |
5540 | 5403 | |
5541 | 5404 | =for Pod::Functions get current nice value |
5542 | 5405 | |
5543 | 5406 | =begin original |
5544 | 5407 | |
5545 | 5408 | Returns the current priority for a process, a process group, or a user. |
5546 | 5409 | (See L<getpriority(2)>.) Will raise a fatal exception if used on a |
5547 | 5410 | machine that doesn't implement getpriority(2). |
5548 | 5411 | |
5549 | 5412 | =end original |
5550 | 5413 | |
5551 | 5414 | プロセス、プロセスグループ、ユーザに対する現在の優先度を返します。 |
5552 | 5415 | (L<getpriority(2)> を参照してください。) |
5553 | 5416 | getpriority(2) を実装していない |
5554 | 5417 | マシンで実行した場合には、致命的例外が発生します。 |
5555 | 5418 | |
5556 | 5419 | =begin original |
5557 | 5420 | |
5558 | 5421 | Portability issues: L<perlport/getpriority>. |
5559 | 5422 | |
5560 | 5423 | =end original |
5561 | 5424 | |
5562 | 5425 | 移植性の問題: L<perlport/getpriority>。 |
5563 | 5426 | |
5564 | 5427 | =item getpwnam NAME |
5565 | 5428 | X<getpwnam> X<getgrnam> X<gethostbyname> X<getnetbyname> X<getprotobyname> |
5566 | 5429 | X<getpwuid> X<getgrgid> X<getservbyname> X<gethostbyaddr> X<getnetbyaddr> |
5567 | 5430 | X<getprotobynumber> X<getservbyport> X<getpwent> X<getgrent> X<gethostent> |
5568 | 5431 | X<getnetent> X<getprotoent> X<getservent> X<setpwent> X<setgrent> X<sethostent> |
5569 | 5432 | X<setnetent> X<setprotoent> X<setservent> X<endpwent> X<endgrent> X<endhostent> |
5570 | 5433 | X<endnetent> X<endprotoent> X<endservent> |
5571 | 5434 | |
5572 | 5435 | =for Pod::Functions get passwd record given user login name |
5573 | 5436 | |
5574 | 5437 | =item getgrnam NAME |
5575 | 5438 | |
5576 | 5439 | =for Pod::Functions get group record given group name |
5577 | 5440 | |
5578 | 5441 | =item gethostbyname NAME |
5579 | 5442 | |
5580 | 5443 | =for Pod::Functions get host record given name |
5581 | 5444 | |
5582 | 5445 | =item getnetbyname NAME |
5583 | 5446 | |
5584 | 5447 | =for Pod::Functions get networks record given name |
5585 | 5448 | |
5586 | 5449 | =item getprotobyname NAME |
5587 | 5450 | |
5588 | 5451 | =for Pod::Functions get protocol record given name |
5589 | 5452 | |
5590 | 5453 | =item getpwuid UID |
5591 | 5454 | |
5592 | 5455 | =for Pod::Functions get passwd record given user ID |
5593 | 5456 | |
5594 | 5457 | =item getgrgid GID |
5595 | 5458 | |
5596 | 5459 | =for Pod::Functions get group record given group user ID |
5597 | 5460 | |
5598 | 5461 | =item getservbyname NAME,PROTO |
5599 | 5462 | |
5600 | 5463 | =for Pod::Functions get services record given its name |
5601 | 5464 | |
5602 | 5465 | =item gethostbyaddr ADDR,ADDRTYPE |
5603 | 5466 | |
5604 | 5467 | =for Pod::Functions get host record given its address |
5605 | 5468 | |
5606 | 5469 | =item getnetbyaddr ADDR,ADDRTYPE |
5607 | 5470 | |
5608 | 5471 | =for Pod::Functions get network record given its address |
5609 | 5472 | |
5610 | 5473 | =item getprotobynumber NUMBER |
5611 | 5474 | |
5612 | 5475 | =for Pod::Functions get protocol record numeric protocol |
5613 | 5476 | |
5614 | 5477 | =item getservbyport PORT,PROTO |
5615 | 5478 | |
5616 | 5479 | =for Pod::Functions get services record given numeric port |
5617 | 5480 | |
5618 | 5481 | =item getpwent |
5619 | 5482 | |
5620 | 5483 | =for Pod::Functions get next passwd record |
5621 | 5484 | |
5622 | 5485 | =item getgrent |
5623 | 5486 | |
5624 | 5487 | =for Pod::Functions get next group record |
5625 | 5488 | |
5626 | 5489 | =item gethostent |
5627 | 5490 | |
5628 | 5491 | =for Pod::Functions get next hosts record |
5629 | 5492 | |
5630 | 5493 | =item getnetent |
5631 | 5494 | |
5632 | 5495 | =for Pod::Functions get next networks record |
5633 | 5496 | |
5634 | 5497 | =item getprotoent |
5635 | 5498 | |
5636 | 5499 | =for Pod::Functions get next protocols record |
5637 | 5500 | |
5638 | 5501 | =item getservent |
5639 | 5502 | |
5640 | 5503 | =for Pod::Functions get next services record |
5641 | 5504 | |
5642 | 5505 | =item setpwent |
5643 | 5506 | |
5644 | 5507 | =for Pod::Functions prepare passwd file for use |
5645 | 5508 | |
5646 | 5509 | =item setgrent |
5647 | 5510 | |
5648 | 5511 | =for Pod::Functions prepare group file for use |
5649 | 5512 | |
5650 | 5513 | =item sethostent STAYOPEN |
5651 | 5514 | |
5652 | 5515 | =for Pod::Functions prepare hosts file for use |
5653 | 5516 | |
5654 | 5517 | =item setnetent STAYOPEN |
5655 | 5518 | |
5656 | 5519 | =for Pod::Functions prepare networks file for use |
5657 | 5520 | |
5658 | 5521 | =item setprotoent STAYOPEN |
5659 | 5522 | |
5660 | 5523 | =for Pod::Functions prepare protocols file for use |
5661 | 5524 | |
5662 | 5525 | =item setservent STAYOPEN |
5663 | 5526 | |
5664 | 5527 | =for Pod::Functions prepare services file for use |
5665 | 5528 | |
5666 | 5529 | =item endpwent |
5667 | 5530 | |
5668 | 5531 | =for Pod::Functions be done using passwd file |
5669 | 5532 | |
5670 | 5533 | =item endgrent |
5671 | 5534 | |
5672 | 5535 | =for Pod::Functions be done using group file |
5673 | 5536 | |
5674 | 5537 | =item endhostent |
5675 | 5538 | |
5676 | 5539 | =for Pod::Functions be done using hosts file |
5677 | 5540 | |
5678 | 5541 | =item endnetent |
5679 | 5542 | |
5680 | 5543 | =for Pod::Functions be done using networks file |
5681 | 5544 | |
5682 | 5545 | =item endprotoent |
5683 | 5546 | |
5684 | 5547 | =for Pod::Functions be done using protocols file |
5685 | 5548 | |
5686 | 5549 | =item endservent |
5687 | 5550 | |
5688 | 5551 | =for Pod::Functions be done using services file |
5689 | 5552 | |
5690 | 5553 | =begin original |
5691 | 5554 | |
5692 | 5555 | These routines are the same as their counterparts in the |
5693 | 5556 | system C library. In list context, the return values from the |
5694 | 5557 | various get routines are as follows: |
5695 | 5558 | |
5696 | 5559 | =end original |
5697 | 5560 | |
5698 | 5561 | これらのルーチンは、システムの C ライブラリの同名の関数と同じです。 |
5699 | 5562 | リストコンテキストでは、さまざまな |
5700 | 5563 | get ルーチンからの返り値は、次のようになります: |
5701 | 5564 | |
5702 | | |
5565 | ($name,$passwd,$uid,$gid, | |
5703 | | |
5566 | $quota,$comment,$gcos,$dir,$shell,$expire) = getpw* | |
5704 | | |
5567 | ($name,$passwd,$gid,$members) = getgr* | |
5705 | | |
5568 | ($name,$aliases,$addrtype,$length,@addrs) = gethost* | |
5706 | | |
5569 | ($name,$aliases,$addrtype,$net) = getnet* | |
5707 | | |
5570 | ($name,$aliases,$proto) = getproto* | |
5708 | | |
5571 | ($name,$aliases,$port,$proto) = getserv* | |
5709 | $comment, $gcos, $dir, $shell, $expire ) = getpw* | |
5710 | # 5 6 7 8 9 | |
5711 | 5572 | |
5712 | 5573 | =begin original |
5713 | 5574 | |
5714 | 5575 | (If the entry doesn't exist you get an empty list.) |
5715 | 5576 | |
5716 | 5577 | =end original |
5717 | 5578 | |
5718 | 5579 | (エントリが存在しなければ、空リストが返されます。) |
5719 | 5580 | |
5720 | 5581 | =begin original |
5721 | 5582 | |
5722 | 5583 | The exact meaning of the $gcos field varies but it usually contains |
5723 | 5584 | the real name of the user (as opposed to the login name) and other |
5724 | 5585 | information pertaining to the user. Beware, however, that in many |
5725 | 5586 | system users are able to change this information and therefore it |
5726 | 5587 | cannot be trusted and therefore the $gcos is tainted (see |
5727 | 5588 | L<perlsec>). The $passwd and $shell, user's encrypted password and |
5728 | 5589 | login shell, are also tainted, for the same reason. |
5729 | 5590 | |
5730 | 5591 | =end original |
5731 | 5592 | |
5732 | 5593 | $gcos フィールドの正確な意味はさまざまですが、通常は(ログイン名ではなく) |
5733 | 5594 | ユーザーの実際の名前とユーザーに付随する情報を含みます。 |
5734 | 5595 | 但し、多くのシステムではユーザーがこの情報を変更できるので、この情報は |
5735 | 5596 | 信頼できず、従って $gcos は汚染されます(L<perlsec> を参照してください)。 |
5736 | 5597 | ユーザーの暗号化されたパスワードとログインシェルである $passwd と |
5737 | 5598 | $shell も、同様の理由で汚染されます。 |
5738 | 5599 | |
5739 | 5600 | =begin original |
5740 | 5601 | |
5741 | 5602 | In scalar context, you get the name, unless the function was a |
5742 | 5603 | lookup by name, in which case you get the other thing, whatever it is. |
5743 | 5604 | (If the entry doesn't exist you get the undefined value.) For example: |
5744 | 5605 | |
5745 | 5606 | =end original |
5746 | 5607 | |
5747 | 5608 | スカラコンテキストでは、*nam、*byname といった NAME で検索するもの以外は、 |
5748 | 5609 | name を返し、NAME で検索するものは、何か別のものを返します。 |
5749 | 5610 | (エントリが存在しなければ、未定義値が返ります。) |
5750 | 5611 | 例えば: |
5751 | 5612 | |
5752 | 5613 | $uid = getpwnam($name); |
5753 | 5614 | $name = getpwuid($num); |
5754 | 5615 | $name = getpwent(); |
5755 | 5616 | $gid = getgrnam($name); |
5756 | 5617 | $name = getgrgid($num); |
5757 | 5618 | $name = getgrent(); |
5758 | 5619 | #etc. |
5759 | 5620 | |
5760 | 5621 | =begin original |
5761 | 5622 | |
5762 | 5623 | In I<getpw*()> the fields $quota, $comment, and $expire are special |
5763 | 5624 | in that they are unsupported on many systems. If the |
5764 | 5625 | $quota is unsupported, it is an empty scalar. If it is supported, it |
5765 | 5626 | usually encodes the disk quota. If the $comment field is unsupported, |
5766 | 5627 | it is an empty scalar. If it is supported it usually encodes some |
5767 | 5628 | administrative comment about the user. In some systems the $quota |
5768 | 5629 | field may be $change or $age, fields that have to do with password |
5769 | 5630 | aging. In some systems the $comment field may be $class. The $expire |
5770 | 5631 | field, if present, encodes the expiration period of the account or the |
5771 | 5632 | password. For the availability and the exact meaning of these fields |
5772 | 5633 | in your system, please consult getpwnam(3) and your system's |
5773 | 5634 | F<pwd.h> file. You can also find out from within Perl what your |
5774 | 5635 | $quota and $comment fields mean and whether you have the $expire field |
5775 | 5636 | by using the C<Config> module and the values C<d_pwquota>, C<d_pwage>, |
5776 | 5637 | C<d_pwchange>, C<d_pwcomment>, and C<d_pwexpire>. Shadow password |
5777 | 5638 | files are supported only if your vendor has implemented them in the |
5778 | 5639 | intuitive fashion that calling the regular C library routines gets the |
5779 | 5640 | shadow versions if you're running under privilege or if there exists |
5780 | 5641 | the shadow(3) functions as found in System V (this includes Solaris |
5781 | 5642 | and Linux). Those systems that implement a proprietary shadow password |
5782 | 5643 | facility are unlikely to be supported. |
5783 | 5644 | |
5784 | 5645 | =end original |
5785 | 5646 | |
5786 | 5647 | I<getpw*()> では、$quota, $comment, $expire フィールドは、 |
5787 | 5648 | 多くのシステムでは対応していないので特別な処理がされます。 |
5788 | 5649 | $quota が非対応の場合、空のスカラになります。 |
5789 | 5650 | 対応している場合、通常はディスククォータの値が入ります。 |
5790 | 5651 | $comment フィールドが非対応の場合、空のスカラになります。 |
5791 | 5652 | 対応している場合、通常はユーザーに関する管理上のコメントが入ります。 |
5792 | 5653 | $quota フィールドはパスワードの寿命を示す $change や $age である |
5793 | 5654 | システムもあります。 |
5794 | 5655 | $comment フィールドは $class であるシステムもあります。 |
5795 | 5656 | $expire フィールドがある場合は、アカウントやパスワードが時間切れになる |
5796 | 5657 | 期間が入ります。 |
5797 | 5658 | 動作させるシステムでのこれらのフィールドの有効性と正確な意味については、 |
5798 | 5659 | getpwnam(3) のドキュメントと F<pwd.h> ファイルを参照してください。 |
5799 | 5660 | $quota と $comment フィールドが何を意味しているかと、$expire フィールドが |
5800 | 5661 | あるかどうかは、C<Config> モジュールを使って、C<d_pwquota>, C<d_pwage>, |
5801 | 5662 | C<d_pwchange>, C<d_pwcomment>, C<d_pwexpire> の値を調べることによって |
5802 | 5663 | Perl 自身で調べることも出来ます。 |
5803 | 5664 | シャドウパスワードは、通常の C ライブラリルーチンを権限がある状態で |
5804 | 5665 | 呼び出すことでシャドウ版が取得できるか、System V にあるような |
5805 | 5666 | (Solaris と Linux を含みます) shadow(3) 関数があるといった、 |
5806 | 5667 | 直感的な方法で実装されている場合にのみ対応されます。 |
5807 | 5668 | 独占的なシャドウパスワード機能を実装しているシステムでは、 |
5808 | 5669 | それに対応されることはないでしょう。 |
5809 | 5670 | |
5810 | 5671 | =begin original |
5811 | 5672 | |
5812 | 5673 | The $members value returned by I<getgr*()> is a space-separated list of |
5813 | 5674 | the login names of the members of the group. |
5814 | 5675 | |
5815 | 5676 | =end original |
5816 | 5677 | |
5817 | 5678 | I<getgr*()> によって返る値 $members は、グループのメンバの |
5818 | 5679 | ログイン名をスペースで区切ったものです。 |
5819 | 5680 | |
5820 | 5681 | =begin original |
5821 | 5682 | |
5822 | 5683 | For the I<gethost*()> functions, if the C<h_errno> variable is supported in |
5823 | 5684 | C, it will be returned to you via C<$?> if the function call fails. The |
5824 | 5685 | C<@addrs> value returned by a successful call is a list of raw |
5825 | 5686 | addresses returned by the corresponding library call. In the |
5826 | 5687 | Internet domain, each address is four bytes long; you can unpack it |
5827 | 5688 | by saying something like: |
5828 | 5689 | |
5829 | 5690 | =end original |
5830 | 5691 | |
5831 | 5692 | I<gethost*()> 関数では、C で C<h_errno> 変数がサポートされていれば、 |
5832 | 5693 | 関数呼出が失敗したときに、C<$?> を通して、その値が返されます。 |
5833 | 5694 | 成功時に返される C<@addrs> 値は、対応するシステムコールが返す、 |
5834 | 5695 | 生のアドレスのリストです。 |
5835 | 5696 | インターネットドメインでは、個々のアドレスは、4 バイト長です; |
5836 | 5697 | 以下のようにして unpack することができます: |
5837 | 5698 | |
5838 | 5699 | ($a,$b,$c,$d) = unpack('W4',$addr[0]); |
5839 | 5700 | |
5840 | 5701 | =begin original |
5841 | 5702 | |
5842 | 5703 | The Socket library makes this slightly easier: |
5843 | 5704 | |
5844 | 5705 | =end original |
5845 | 5706 | |
5846 | 5707 | Socket ライブラリを使うともう少し簡単になります。 |
5847 | 5708 | |
5848 | 5709 | use Socket; |
5849 | 5710 | $iaddr = inet_aton("127.1"); # or whatever address |
5850 | 5711 | $name = gethostbyaddr($iaddr, AF_INET); |
5851 | 5712 | |
5852 | 5713 | # or going the other way |
5853 | 5714 | $straddr = inet_ntoa($iaddr); |
5854 | 5715 | |
5855 | 5716 | =begin original |
5856 | 5717 | |
5857 | 5718 | In the opposite way, to resolve a hostname to the IP address |
5858 | 5719 | you can write this: |
5859 | 5720 | |
5860 | 5721 | =end original |
5861 | 5722 | |
5862 | 5723 | 逆方向に、ホスト名から IP アドレスを解決するには以下のように書けます: |
5863 | 5724 | |
5864 | 5725 | use Socket; |
5865 | 5726 | $packed_ip = gethostbyname("www.perl.org"); |
5866 | 5727 | if (defined $packed_ip) { |
5867 | 5728 | $ip_address = inet_ntoa($packed_ip); |
5868 | 5729 | } |
5869 | 5730 | |
5870 | 5731 | =begin original |
5871 | 5732 | |
5872 | 5733 | Make sure C<gethostbyname()> is called in SCALAR context and that |
5873 | 5734 | its return value is checked for definedness. |
5874 | 5735 | |
5875 | 5736 | =end original |
5876 | 5737 | |
5877 | 5738 | C<gethostbyname()> はスカラコンテキストで呼び出すようにして、返り値が |
5878 | 5739 | 定義されているかを必ずチェックしてください。 |
5879 | 5740 | |
5880 | 5741 | =begin original |
5881 | 5742 | |
5882 | 5743 | The C<getprotobynumber> function, even though it only takes one argument, |
5883 | 5744 | has the precedence of a list operator, so beware: |
5884 | 5745 | |
5885 | 5746 | =end original |
5886 | 5747 | |
5887 | 5748 | C<getprotobynumber> 関数は、一つの引数しか取らないにも関わらず、リスト |
5888 | 5749 | 演算子の優先順位を持ちます; 従って注意してください: |
5889 | 5750 | |
5890 | 5751 | getprotobynumber $number eq 'icmp' # WRONG |
5891 | 5752 | getprotobynumber($number eq 'icmp') # actually means this |
5892 | 5753 | getprotobynumber($number) eq 'icmp' # better this way |
5893 | 5754 | |
5894 | 5755 | =begin original |
5895 | 5756 | |
5896 | 5757 | If you get tired of remembering which element of the return list |
5897 | 5758 | contains which return value, by-name interfaces are provided |
5898 | 5759 | in standard modules: C<File::stat>, C<Net::hostent>, C<Net::netent>, |
5899 | 5760 | C<Net::protoent>, C<Net::servent>, C<Time::gmtime>, C<Time::localtime>, |
5900 | 5761 | and C<User::grent>. These override the normal built-ins, supplying |
5901 | 5762 | versions that return objects with the appropriate names |
5902 | 5763 | for each field. For example: |
5903 | 5764 | |
5904 | 5765 | =end original |
5905 | 5766 | |
5906 | 5767 | 返り値のリストの何番目がどの要素かを覚えるのに疲れたなら、 |
5907 | 5768 | 名前ベースのインターフェースが標準モジュールで提供されています: |
5908 | 5769 | C<File::stat>, C<Net::hostent>, C<Net::netent>, |
5909 | 5770 | C<Net::protoent>, C<Net::servent>, C<Time::gmtime>, C<Time::localtime>, |
5910 | 5771 | C<User::grent> です。 |
5911 | 5772 | これらは通常の組み込みを上書きし、 |
5912 | 5773 | それぞれのフィールドに適切な名前をつけたオブジェクトを返します。 |
5913 | 5774 | 例えば: |
5914 | 5775 | |
5915 | 5776 | use File::stat; |
5916 | 5777 | use User::pwent; |
5917 | 5778 | $is_his = (stat($filename)->uid == pwent($whoever)->uid); |
5918 | 5779 | |
5919 | 5780 | =begin original |
5920 | 5781 | |
5921 | 5782 | Even though it looks as though they're the same method calls (uid), |
5922 | 5783 | they aren't, because a C<File::stat> object is different from |
5923 | 5784 | a C<User::pwent> object. |
5924 | 5785 | |
5925 | 5786 | =end original |
5926 | 5787 | |
5927 | 5788 | 同じメソッド(uid)を呼び出しているように見えますが、違います; |
5928 | 5789 | なぜなら C<File::stat> オブジェクトは C<User::pwent> オブジェクトとは |
5929 | 5790 | 異なるからです。 |
5930 | 5791 | |
5931 | 5792 | =begin original |
5932 | 5793 | |
5933 | 5794 | Portability issues: L<perlport/getpwnam> to L<perlport/endservent>. |
5934 | 5795 | |
5935 | 5796 | =end original |
5936 | 5797 | |
5937 | 5798 | 移植性の問題: L<perlport/getpwnam> から L<perlport/endservent>。 |
5938 | 5799 | |
5939 | 5800 | =item getsockname SOCKET |
5940 | 5801 | X<getsockname> |
5941 | 5802 | |
5942 | 5803 | =for Pod::Functions retrieve the sockaddr for a given socket |
5943 | 5804 | |
5944 | 5805 | =begin original |
5945 | 5806 | |
5946 | 5807 | Returns the packed sockaddr address of this end of the SOCKET connection, |
5947 | 5808 | in case you don't know the address because you have several different |
5948 | 5809 | IPs that the connection might have come in on. |
5949 | 5810 | |
5950 | 5811 | =end original |
5951 | 5812 | |
5952 | 5813 | SOCKET 接続のこちら側の pack された sockaddr アドレスを返します; |
5953 | 5814 | 複数の異なる IP から接続されるためにアドレスがわからない場合に使います。 |
5954 | 5815 | |
5955 | 5816 | use Socket; |
5956 | 5817 | $mysockaddr = getsockname(SOCK); |
5957 | 5818 | ($port, $myaddr) = sockaddr_in($mysockaddr); |
5958 | 5819 | printf "Connect to %s [%s]\n", |
5959 | 5820 | scalar gethostbyaddr($myaddr, AF_INET), |
5960 | 5821 | inet_ntoa($myaddr); |
5961 | 5822 | |
5962 | 5823 | =item getsockopt SOCKET,LEVEL,OPTNAME |
5963 | 5824 | X<getsockopt> |
5964 | 5825 | |
5965 | 5826 | =for Pod::Functions get socket options on a given socket |
5966 | 5827 | |
5967 | 5828 | =begin original |
5968 | 5829 | |
5969 | 5830 | Queries the option named OPTNAME associated with SOCKET at a given LEVEL. |
5970 | 5831 | Options may exist at multiple protocol levels depending on the socket |
5971 | 5832 | type, but at least the uppermost socket level SOL_SOCKET (defined in the |
5972 | 5833 | C<Socket> module) will exist. To query options at another level the |
5973 | 5834 | protocol number of the appropriate protocol controlling the option |
5974 | 5835 | should be supplied. For example, to indicate that an option is to be |
5975 | 5836 | interpreted by the TCP protocol, LEVEL should be set to the protocol |
5976 | 5837 | number of TCP, which you can get using C<getprotobyname>. |
5977 | 5838 | |
5978 | 5839 | =end original |
5979 | 5840 | |
5980 | 5841 | 与えられた LEVEL で SOCKET に関連付けられた OPTNAME と言う名前のオプションを |
5981 | 5842 | 問い合わせます。 |
5982 | 5843 | オプションはソケットの種類に依存しした複数のプロトコルレベルに存在することも |
5983 | 5844 | ありますが、少なくとも最上位ソケットレベル SOL_SOCKET (C<Socket> モジュールで |
5984 | 5845 | 定義されています)は存在します。 |
5985 | 5846 | その他のレベルのオプションを問い合わせるには、そのオプションを制御する |
5986 | 5847 | 適切なプロトコルのプロトコル番号を指定します。 |
5987 | 5848 | 例えば、オプションが TCP プロトコルで解釈されるべきであることを示すためには、 |
5988 | 5849 | LEVEL は C<getprotobyname> で得られる TCP のプロトコル番号を設定します。 |
5989 | 5850 | |
5990 | 5851 | =begin original |
5991 | 5852 | |
5992 | 5853 | The function returns a packed string representing the requested socket |
5993 | 5854 | option, or C<undef> on error, with the reason for the error placed in |
5994 | 5855 | C<$!>. Just what is in the packed string depends on LEVEL and OPTNAME; |
5995 | 5856 | consult getsockopt(2) for details. A common case is that the option is an |
5996 | 5857 | integer, in which case the result is a packed integer, which you can decode |
5997 | 5858 | using C<unpack> with the C<i> (or C<I>) format. |
5998 | 5859 | |
5999 | 5860 | =end original |
6000 | 5861 | |
6001 | 5862 | この関数は、要求されたソケットオプションの pack された文字列表現か、 |
6002 | 5863 | あるいはエラーの場合は C<undef> を返し、エラーの理由は C<$!> にあります。 |
6003 | 5864 | pack された文字列の中身は LEVEL と OPTNAME に依存します; |
6004 | 5865 | 詳細については getsockopt(2) を確認してください。 |
6005 | 5866 | 一般的な場合はオプションが整数の場合で、この場合結果は C<unpack> の C<i> |
6006 | 5867 | (あるいは C<I>)フォーマットでデコードできる pack された整数です。 |
6007 | 5868 | |
6008 | 5869 | =begin original |
6009 | 5870 | |
6010 | 5871 | Here's an example to test whether Nagle's algorithm is enabled on a socket: |
6011 | 5872 | |
6012 | 5873 | =end original |
6013 | 5874 | |
6014 | 5875 | あるソケットで Nagle のアルゴリズム有効かどうかを調べる例です: |
6015 | 5876 | |
6016 | 5877 | use Socket qw(:all); |
6017 | 5878 | |
6018 | 5879 | defined(my $tcp = getprotobyname("tcp")) |
6019 | 5880 | or die "Could not determine the protocol number for tcp"; |
6020 | 5881 | # my $tcp = IPPROTO_TCP; # Alternative |
6021 | 5882 | my $packed = getsockopt($socket, $tcp, TCP_NODELAY) |
6022 | 5883 | or die "getsockopt TCP_NODELAY: $!"; |
6023 | 5884 | my $nodelay = unpack("I", $packed); |
6024 | print "Nagle's algorithm is turned ", | |
5885 | print "Nagle's algorithm is turned ", $nodelay ? "off\n" : "on\n"; | |
6025 | $nodelay ? "off\n" : "on\n"; | |
6026 | 5886 | |
6027 | 5887 | =begin original |
6028 | 5888 | |
6029 | 5889 | Portability issues: L<perlport/getsockopt>. |
6030 | 5890 | |
6031 | 5891 | =end original |
6032 | 5892 | |
6033 | 5893 | 移植性の問題: L<perlport/getsockopt>。 |
6034 | 5894 | |
6035 | 5895 | =item glob EXPR |
6036 | 5896 | X<glob> X<wildcard> X<filename, expansion> X<expand> |
6037 | 5897 | |
6038 | 5898 | =item glob |
6039 | 5899 | |
6040 | 5900 | =for Pod::Functions expand filenames using wildcards |
6041 | 5901 | |
6042 | 5902 | =begin original |
6043 | 5903 | |
6044 | 5904 | In list context, returns a (possibly empty) list of filename expansions on |
6045 | 5905 | the value of EXPR such as the standard Unix shell F</bin/csh> would do. In |
6046 | 5906 | scalar context, glob iterates through such filename expansions, returning |
6047 | 5907 | undef when the list is exhausted. This is the internal function |
6048 | 5908 | implementing the C<< <*.c> >> operator, but you can use it directly. If |
6049 | 5909 | EXPR is omitted, C<$_> is used. The C<< <*.c> >> operator is discussed in |
6050 | 5910 | more detail in L<perlop/"I/O Operators">. |
6051 | 5911 | |
6052 | 5912 | =end original |
6053 | 5913 | |
6054 | 5914 | リストコンテキストでは、 |
6055 | 5915 | EXPR の値を、標準 Unix シェル F</bin/csh> が行なうように |
6056 | 5916 | ファイル名の展開を行なった結果のリスト(空かもしれません)を返します。 |
6057 | 5917 | スカラコンテキストでは、glob はこのようなファイル名展開を繰り返し、 |
6058 | 5918 | リストがなくなったら undef を返します。 |
6059 | 5919 | これは、C<< <*.c> >> 演算子を実装する内部関数ですが、 |
6060 | 5920 | 直接使用することもできます。 |
6061 | 5921 | EXPR が省略されると、C<$_> が使われます。 |
6062 | 5922 | C<< <*.c> >>演算子については |
6063 | 5923 | L<perlop/"I/O Operators"> でより詳細に議論しています。 |
6064 | 5924 | |
6065 | 5925 | =begin original |
6066 | 5926 | |
6067 | 5927 | Note that C<glob> splits its arguments on whitespace and treats |
6068 | 5928 | each segment as separate pattern. As such, C<glob("*.c *.h")> |
6069 | 5929 | matches all files with a F<.c> or F<.h> extension. The expression |
6070 | 5930 | C<glob(".* *")> matches all files in the current working directory. |
6071 | 5931 | If you want to glob filenames that might contain whitespace, you'll |
6072 | 5932 | have to use extra quotes around the spacey filename to protect it. |
6073 | 5933 | For example, to glob filenames that have an C<e> followed by a space |
6074 | 5934 | followed by an C<f>, use either of: |
6075 | 5935 | |
6076 | 5936 | =end original |
6077 | 5937 | |
6078 | 5938 | C<glob> は引数を空白で分割して、それぞれを分割されたパターンとして扱います。 |
6079 | 5939 | 従って、C<glob("*.c *.h")> は F<.c> または F<.h> 拡張子を持つ全てのファイルに |
6080 | 5940 | マッチングします。 |
6081 | 5941 | 式 C<glob(".* *")> はカレントワーキングディレクトリの全てのファイルに |
6082 | 5942 | マッチングします。 |
6083 | 5943 | 空白を含んでいるかも知れないファイル名をグロブしたい場合、それを守るために |
6084 | 5944 | 空白入りファイル名の周りに追加のクォートを使う必要があります。 |
6085 | 5945 | 例えば、C<e> の後に空白、その後に C<f> というファイル名をグロブするには |
6086 | 5946 | 以下のどちらかを使います: |
6087 | 5947 | |
6088 | 5948 | @spacies = <"*e f*">; |
6089 | 5949 | @spacies = glob '"*e f*"'; |
6090 | 5950 | @spacies = glob q("*e f*"); |
6091 | 5951 | |
6092 | 5952 | =begin original |
6093 | 5953 | |
6094 | 5954 | If you had to get a variable through, you could do this: |
6095 | 5955 | |
6096 | 5956 | =end original |
6097 | 5957 | |
6098 | 5958 | 変数を通す必要があった場合、以下のようにできました: |
6099 | 5959 | |
6100 | 5960 | @spacies = glob "'*${var}e f*'"; |
6101 | 5961 | @spacies = glob qq("*${var}e f*"); |
6102 | 5962 | |
6103 | 5963 | =begin original |
6104 | 5964 | |
6105 | 5965 | If non-empty braces are the only wildcard characters used in the |
6106 | 5966 | C<glob>, no filenames are matched, but potentially many strings |
6107 | 5967 | are returned. For example, this produces nine strings, one for |
6108 | 5968 | each pairing of fruits and colors: |
6109 | 5969 | |
6110 | 5970 | =end original |
6111 | 5971 | |
6112 | 5972 | 空でない中かっこが C<glob> で使われている唯一のワイルドカード文字列の |
6113 | 5973 | 場合、ファイル名とはマッチングせず、可能性のある文字列が返されます。 |
6114 | 5974 | 例えば、これは 9 個の文字列を生成し、それぞれは果物と色の組み合わせに |
6115 | 5975 | なります: |
6116 | 5976 | |
6117 | 5977 | @many = glob "{apple,tomato,cherry}={green,yellow,red}"; |
6118 | 5978 | |
6119 | 5979 | =begin original |
6120 | 5980 | |
6121 | ||
5981 | Beginning with v5.6.0, this operator is implemented using the standard | |
6122 | 5982 | C<File::Glob> extension. See L<File::Glob> for details, including |
6123 | 5983 | C<bsd_glob> which does not treat whitespace as a pattern separator. |
6124 | 5984 | |
6125 | 5985 | =end original |
6126 | 5986 | |
6127 | 5987 | v5.6.0 から、この演算子は標準の C<File::Glob> 拡張を使って |
6128 | 5988 | 実装されています。 |
6129 | 5989 | 空白をパターンのセパレータとして扱わない C<bsd_glob> を含めた |
6130 | 5990 | 詳細は L<File::Glob> を参照してください。 |
6131 | 5991 | |
6132 | 5992 | =begin original |
6133 | 5993 | |
6134 | 5994 | Portability issues: L<perlport/glob>. |
6135 | 5995 | |
6136 | 5996 | =end original |
6137 | 5997 | |
6138 | 5998 | 移植性の問題: L<perlport/glob>。 |
6139 | 5999 | |
6140 | 6000 | =item gmtime EXPR |
6141 | 6001 | X<gmtime> X<UTC> X<Greenwich> |
6142 | 6002 | |
6143 | 6003 | =item gmtime |
6144 | 6004 | |
6145 | 6005 | =for Pod::Functions convert UNIX time into record or string using Greenwich time |
6146 | 6006 | |
6147 | 6007 | =begin original |
6148 | 6008 | |
6149 | 6009 | Works just like L</localtime> but the returned values are |
6150 | 6010 | localized for the standard Greenwich time zone. |
6151 | 6011 | |
6152 | 6012 | =end original |
6153 | 6013 | |
6154 | 6014 | L</localtime> と同様に働きますが、返り値はグリニッジ標準時に |
6155 | 6015 | ローカライズされています。 |
6156 | 6016 | |
6157 | 6017 | =begin original |
6158 | 6018 | |
6159 | 6019 | Note: When called in list context, $isdst, the last value |
6160 | 6020 | returned by gmtime, is always C<0>. There is no |
6161 | 6021 | Daylight Saving Time in GMT. |
6162 | 6022 | |
6163 | 6023 | =end original |
6164 | 6024 | |
6165 | 6025 | 注意: リストコンテキストで呼び出した時、gmtime が返す末尾の値である |
6166 | 6026 | $isdst は常に C<0> です。 |
6167 | 6027 | GMT には夏時間はありません。 |
6168 | 6028 | |
6169 | 6029 | =begin original |
6170 | 6030 | |
6171 | 6031 | Portability issues: L<perlport/gmtime>. |
6172 | 6032 | |
6173 | 6033 | =end original |
6174 | 6034 | |
6175 | 6035 | 移植性の問題: L<perlport/gmtime>。 |
6176 | 6036 | |
6177 | =item goto LABEL | |
6178 | 6037 | X<goto> X<jump> X<jmp> |
6179 | 6038 | |
6180 | 6039 | =item goto EXPR |
6181 | 6040 | |
6182 | 6041 | =item goto &NAME |
6183 | 6042 | |
6184 | 6043 | =for Pod::Functions create spaghetti code |
6185 | 6044 | |
6186 | 6045 | =begin original |
6187 | 6046 | |
6188 | The C<goto | |
6047 | The C<goto-LABEL> form finds the statement labeled with LABEL and | |
6189 | 6048 | resumes execution there. It can't be used to get out of a block or |
6190 | 6049 | subroutine given to C<sort>. It can be used to go almost anywhere |
6191 | 6050 | else within the dynamic scope, including out of subroutines, but it's |
6192 | 6051 | usually better to use some other construct such as C<last> or C<die>. |
6193 | 6052 | The author of Perl has never felt the need to use this form of C<goto> |
6194 | 6053 | (in Perl, that is; C is another matter). (The difference is that C |
6195 | 6054 | does not offer named loops combined with loop control. Perl does, and |
6196 | 6055 | this replaces most structured uses of C<goto> in other languages.) |
6197 | 6056 | |
6198 | 6057 | =end original |
6199 | 6058 | |
6200 | C<goto | |
6059 | C<goto-LABEL> の形式は、LABEL というラベルの付いた文を | |
6201 | 6060 | 探して、そこへ実行を移すものです。 |
6202 | 6061 | C<sort> で与えられたブロックやサブルーチンから外へ出ることはできません。 |
6203 | 6062 | これ以外は、サブルーチンの外を含む、動的スコープ内の |
6204 | 6063 | ほとんどすべての場所へ行くために使用できますが、普通は、 |
6205 | 6064 | C<last> や C<die> といった別の構造を使った方が良いでしょう。 |
6206 | 6065 | Perl の作者はこの形式の C<goto> を使う必要を感じたことは、 |
6207 | 6066 | 1 度もありません (Perl では; C は別のお話です)。 |
6208 | 6067 | (違いは、C にはループ制御と結びついた名前つきのループがないことです。 |
6209 | 6068 | Perl にはあり、これが他の言語でのほとんどの構造的な C<goto> の使用法を |
6210 | 6069 | 置き換えます。) |
6211 | 6070 | |
6212 | 6071 | =begin original |
6213 | 6072 | |
6214 | The C<goto | |
6073 | The C<goto-EXPR> form expects a label name, whose scope will be resolved | |
6215 | a label name. If it evaluates to a code reference, it will be handled | |
6216 | like C<goto &NAME>, below. This is especially useful for implementing | |
6217 | tail recursion via C<goto __SUB__>. | |
6218 | ||
6219 | =end original | |
6220 | ||
6221 | C<goto EXPR> の形式は、C<EXPR> をコードリファレンスまたはラベル名として | |
6222 | 評価することを想定します。 | |
6223 | コードリファレンスとして評価する場合、後述する C<goto &NAME> のように | |
6224 | 扱います。 | |
6225 | これは特に、C<goto __SUB__> による末尾再帰の実装に有用です。 | |
6226 | ||
6227 | =begin original | |
6228 | ||
6229 | If the expression evaluates to a label name, its scope will be resolved | |
6230 | 6074 | dynamically. This allows for computed C<goto>s per FORTRAN, but isn't |
6231 | 6075 | necessarily recommended if you're optimizing for maintainability: |
6232 | 6076 | |
6233 | 6077 | =end original |
6234 | 6078 | |
6235 | 式 | |
6079 | C<goto-EXPR> の形式はラベル名を予測し、このスコープは動的に解決されます。 | |
6236 | 6080 | これにより FORTRAN のような算術 C<goto> が可能になりますが、 |
6237 | 6081 | 保守性を重視するならお勧めしません。 |
6238 | 6082 | |
6239 | 6083 | goto ("FOO", "BAR", "GLARCH")[$i]; |
6240 | 6084 | |
6241 | 6085 | =begin original |
6242 | 6086 | |
6243 | As shown in this example, C<goto | |
6087 | As shown in this example, C<goto-EXPR> is exempt from the "looks like a | |
6244 | 6088 | function" rule. A pair of parentheses following it does not (necessarily) |
6245 | 6089 | delimit its argument. C<goto("NE")."XT"> is equivalent to C<goto NEXT>. |
6246 | Also, unlike most named operators, this has the same precedence as | |
6247 | assignment. | |
6248 | 6090 | |
6249 | 6091 | =end original |
6250 | 6092 | |
6251 | この例で示したように、C<goto | |
6093 | この例で示したように、C<goto-EXPR> は「関数のように見える」ルールから | |
6252 | 6094 | 除外されます。 |
6253 | 6095 | これに引き続くかっこの組は引数の区切りとは(必ずしも)なりません。 |
6254 | 6096 | C<goto("NE")."XT"> は C<goto NEXT> と等価です。 |
6255 | また、ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 | |
6256 | 6097 | |
6257 | 6098 | =begin original |
6258 | 6099 | |
6259 | Use of C<goto | |
6100 | Use of C<goto-LABEL> or C<goto-EXPR> to jump into a construct is | |
6260 | 6101 | deprecated and will issue a warning. Even then, it may not be used to |
6261 | 6102 | go into any construct that requires initialization, such as a |
6262 | 6103 | subroutine or a C<foreach> loop. It also can't be used to go into a |
6263 | 6104 | construct that is optimized away. |
6264 | 6105 | |
6265 | 6106 | =end original |
6266 | 6107 | |
6267 | 構造の中に飛び込むために C<goto | |
6108 | 構造の中に飛び込むために C<goto-LABEL> や C<goto-EXPR> を使うことは | |
6268 | 6109 | 非推奨で、警告が発生します。 |
6269 | 6110 | それでも、サブルーチンや C<foreach> ループのような、初期化が必要な |
6270 | 6111 | 構造の中に入るために使うことは出来ません。 |
6271 | 6112 | また、最適化してなくなってしまった構造の中へ入るために使うことも出来ません。 |
6272 | 6113 | |
6273 | 6114 | =begin original |
6274 | 6115 | |
6275 | The C<goto | |
6116 | The C<goto-&NAME> form is quite different from the other forms of | |
6276 | 6117 | C<goto>. In fact, it isn't a goto in the normal sense at all, and |
6277 | 6118 | doesn't have the stigma associated with other gotos. Instead, it |
6278 | 6119 | exits the current subroutine (losing any changes set by local()) and |
6279 | 6120 | immediately calls in its place the named subroutine using the current |
6280 | 6121 | value of @_. This is used by C<AUTOLOAD> subroutines that wish to |
6281 | 6122 | load another subroutine and then pretend that the other subroutine had |
6282 | 6123 | been called in the first place (except that any modifications to C<@_> |
6283 | 6124 | in the current subroutine are propagated to the other subroutine.) |
6284 | 6125 | After the C<goto>, not even C<caller> will be able to tell that this |
6285 | 6126 | routine was called first. |
6286 | 6127 | |
6287 | 6128 | =end original |
6288 | 6129 | |
6289 | C<goto | |
6130 | C<goto-&NAME> の形式は、その他の C<goto> の形式とはかなり | |
6290 | 6131 | 異なったものです。 |
6291 | 6132 | 実際、これは普通の感覚でいうところのどこかへ行くものでは全くなく、 |
6292 | 6133 | 他の goto が持つ不名誉を持っていません。 |
6293 | 6134 | 現在のサブルーチンを終了し (local() による変更は失われます)、 |
6294 | 6135 | 直ちに現在の @_ の値を使って指定された名前のサブルーチンを呼び出します。 |
6295 | 6136 | これは、C<AUTOLOAD> サブルーチンが別のサブルーチンをロードして、 |
6296 | 6137 | その別のサブルーチンが最初に呼ばれたようにするために使われます |
6297 | 6138 | (ただし、現在のサブルーチンで C<@_> を修正した場合には、 |
6298 | 6139 | その別のサブルーチンに伝えられます)。 |
6299 | 6140 | C<goto> のあとは、C<caller> でさえも、現在のサブルーチンが |
6300 | 6141 | 最初に呼び出されたと言うことができません。 |
6301 | 6142 | |
6302 | 6143 | =begin original |
6303 | 6144 | |
6304 | 6145 | NAME needn't be the name of a subroutine; it can be a scalar variable |
6305 | 6146 | containing a code reference or a block that evaluates to a code |
6306 | 6147 | reference. |
6307 | 6148 | |
6308 | 6149 | =end original |
6309 | 6150 | |
6310 | 6151 | NAME はサブルーチンの名前である必要はありません; コードリファレンスを |
6311 | 6152 | 含むスカラ値や、コードリファレンスと評価されるブロックでも構いません。 |
6312 | 6153 | |
6313 | 6154 | =item grep BLOCK LIST |
6314 | 6155 | X<grep> |
6315 | 6156 | |
6316 | 6157 | =item grep EXPR,LIST |
6317 | 6158 | |
6318 | 6159 | =for Pod::Functions locate elements in a list test true against a given criterion |
6319 | 6160 | |
6320 | 6161 | =begin original |
6321 | 6162 | |
6322 | 6163 | This is similar in spirit to, but not the same as, grep(1) and its |
6323 | 6164 | relatives. In particular, it is not limited to using regular expressions. |
6324 | 6165 | |
6325 | 6166 | =end original |
6326 | 6167 | |
6327 | 6168 | これは grep(1) とその親類と同じようなものですが、同じではありません。 |
6328 | 6169 | 特に、正規表現の使用に制限されません。 |
6329 | 6170 | |
6330 | 6171 | =begin original |
6331 | 6172 | |
6332 | 6173 | Evaluates the BLOCK or EXPR for each element of LIST (locally setting |
6333 | 6174 | C<$_> to each element) and returns the list value consisting of those |
6334 | 6175 | elements for which the expression evaluated to true. In scalar |
6335 | 6176 | context, returns the number of times the expression was true. |
6336 | 6177 | |
6337 | 6178 | =end original |
6338 | 6179 | |
6339 | 6180 | LIST の個々の要素に対して、BLOCK か EXPR を評価し |
6340 | 6181 | (C<$_> は、ローカルに個々の要素が設定されます) 、 |
6341 | 6182 | その要素のうち、評価した式が真となったものからなるリスト値が返されます。 |
6342 | 6183 | スカラコンテキストでは、式が真となった回数を返します。 |
6343 | 6184 | |
6344 | 6185 | @foo = grep(!/^#/, @bar); # weed out comments |
6345 | 6186 | |
6346 | 6187 | =begin original |
6347 | 6188 | |
6348 | 6189 | or equivalently, |
6349 | 6190 | |
6350 | 6191 | =end original |
6351 | 6192 | |
6352 | 6193 | あるいは等価な例として: |
6353 | 6194 | |
6354 | 6195 | @foo = grep {!/^#/} @bar; # weed out comments |
6355 | 6196 | |
6356 | 6197 | =begin original |
6357 | 6198 | |
6358 | 6199 | Note that C<$_> is an alias to the list value, so it can be used to |
6359 | 6200 | modify the elements of the LIST. While this is useful and supported, |
6360 | 6201 | it can cause bizarre results if the elements of LIST are not variables. |
6361 | 6202 | Similarly, grep returns aliases into the original list, much as a for |
6362 | 6203 | loop's index variable aliases the list elements. That is, modifying an |
6363 | 6204 | element of a list returned by grep (for example, in a C<foreach>, C<map> |
6364 | 6205 | or another C<grep>) actually modifies the element in the original list. |
6365 | 6206 | This is usually something to be avoided when writing clear code. |
6366 | 6207 | |
6367 | 6208 | =end original |
6368 | 6209 | |
6369 | 6210 | C<$_> は、LIST の値へのエイリアスですので、LIST の要素を |
6370 | 6211 | 変更するために使うことができます。 |
6371 | 6212 | これは、便利でサポートされていますが、 |
6372 | 6213 | LIST の要素が変数でないと、おかしな結果になります。 |
6373 | 6214 | 同様に、grep は元のリストへのエイリアスを返します; for ループの |
6374 | 6215 | インデックス変数がリスト要素のエイリアスであるのと同様です。 |
6375 | 6216 | つまり、grep で返されたリストの要素を |
6376 | 6217 | (C<foreach>, C<map>, または他の C<grep> で)修正すると |
6377 | 6218 | 元のリストの要素が変更されます。 |
6378 | 6219 | これはきれいなコードを書くときには普通は回避されます。 |
6379 | 6220 | |
6380 | 6221 | =begin original |
6381 | 6222 | |
6382 | 6223 | If C<$_> is lexical in the scope where the C<grep> appears (because it has |
6383 | been declared with | |
6224 | been declared with C<my $_>) then, in addition to being locally aliased to | |
6384 | then, in addition to being locally aliased to | |
6385 | 6225 | the list elements, C<$_> keeps being lexical inside the block; i.e., it |
6386 | 6226 | can't be seen from the outside, avoiding any potential side-effects. |
6387 | 6227 | |
6388 | 6228 | =end original |
6389 | 6229 | |
6390 | ( | |
6230 | (C<my $_> として宣言されることによって) C<$_> が C<grep> が現れるスコープ内で | |
6391 | ||
6231 | レキシカルな場合は、ローカルではリスト要素へのエイリアスであることに加えて、 | |
6392 | ||
6232 | C<$_> はブロック内でレキシカルでありつづけます; つまり、外側からは見えず、 | |
6393 | ||
6233 | 起こりうる副作用を回避します。 | |
6394 | 6234 | |
6395 | 6235 | =begin original |
6396 | 6236 | |
6397 | 6237 | See also L</map> for a list composed of the results of the BLOCK or EXPR. |
6398 | 6238 | |
6399 | 6239 | =end original |
6400 | 6240 | |
6401 | 6241 | BLOCK や EXPR の結果をリストの形にしたい場合は L</map> を参照してください。 |
6402 | 6242 | |
6403 | 6243 | =item hex EXPR |
6404 | 6244 | X<hex> X<hexadecimal> |
6405 | 6245 | |
6406 | 6246 | =item hex |
6407 | 6247 | |
6408 | 6248 | =for Pod::Functions convert a string to a hexadecimal number |
6409 | 6249 | |
6410 | 6250 | =begin original |
6411 | 6251 | |
6412 | 6252 | Interprets EXPR as a hex string and returns the corresponding value. |
6413 | 6253 | (To convert strings that might start with either C<0>, C<0x>, or C<0b>, see |
6414 | 6254 | L</oct>.) If EXPR is omitted, uses C<$_>. |
6415 | 6255 | |
6416 | 6256 | =end original |
6417 | 6257 | |
6418 | 6258 | EXPR を 16 進数の文字列と解釈して、対応する値を返します。 |
6419 | 6259 | (C<0>, C<0x>, C<0b> で始まる文字列の変換には、L</oct> を |
6420 | 6260 | 参照してください。) |
6421 | 6261 | EXPR が省略されると、C<$_> を使います。 |
6422 | 6262 | |
6423 | 6263 | print hex '0xAf'; # prints '175' |
6424 | 6264 | print hex 'aF'; # same |
6425 | 6265 | |
6426 | 6266 | =begin original |
6427 | 6267 | |
6428 | 6268 | Hex strings may only represent integers. Strings that would cause |
6429 | 6269 | integer overflow trigger a warning. Leading whitespace is not stripped, |
6430 | 6270 | unlike oct(). To present something as hex, look into L</printf>, |
6431 | 6271 | L</sprintf>, and L</unpack>. |
6432 | 6272 | |
6433 | 6273 | =end original |
6434 | 6274 | |
6435 | 6275 | 16 進文字列は整数のみを表現します。 |
6436 | 6276 | 整数オーバーフローを起こすような文字列は警告を引き起こします。 |
6437 | 6277 | oct() とは違って、先頭の空白は除去されません。 |
6438 | 6278 | 何かを 16 進で表現したい場合は、L</printf>, L</sprintf>, L</unpack> を |
6439 | 6279 | 参照してください。 |
6440 | 6280 | |
6441 | 6281 | =item import LIST |
6442 | 6282 | X<import> |
6443 | 6283 | |
6444 | 6284 | =for Pod::Functions patch a module's namespace into your own |
6445 | 6285 | |
6446 | 6286 | =begin original |
6447 | 6287 | |
6448 | 6288 | There is no builtin C<import> function. It is just an ordinary |
6449 | 6289 | method (subroutine) defined (or inherited) by modules that wish to export |
6450 | 6290 | names to another module. The C<use> function calls the C<import> method |
6451 | 6291 | for the package used. See also L</use>, L<perlmod>, and L<Exporter>. |
6452 | 6292 | |
6453 | 6293 | =end original |
6454 | 6294 | |
6455 | 6295 | 組み込みの C<import> 関数というものはありません。 |
6456 | 6296 | これは単に、別のモジュールに名前をエクスポートしたいモジュールが |
6457 | 6297 | 定義した(または継承した)、通常のメソッド(サブルーチン)です。 |
6458 | 6298 | C<use> 関数はパッケージを使う時に C<import> メソッドを呼び出します。 |
6459 | 6299 | L</use>, L<perlmod>, L<Exporter> も参照してください。 |
6460 | 6300 | |
6461 | 6301 | =item index STR,SUBSTR,POSITION |
6462 | 6302 | X<index> X<indexOf> X<InStr> |
6463 | 6303 | |
6464 | 6304 | =item index STR,SUBSTR |
6465 | 6305 | |
6466 | 6306 | =for Pod::Functions find a substring within a string |
6467 | 6307 | |
6468 | 6308 | =begin original |
6469 | 6309 | |
6470 | 6310 | The index function searches for one string within another, but without |
6471 | 6311 | the wildcard-like behavior of a full regular-expression pattern match. |
6472 | 6312 | It returns the position of the first occurrence of SUBSTR in STR at |
6473 | 6313 | or after POSITION. If POSITION is omitted, starts searching from the |
6474 | 6314 | beginning of the string. POSITION before the beginning of the string |
6475 | 6315 | or after its end is treated as if it were the beginning or the end, |
6476 | 6316 | respectively. POSITION and the return value are based at zero. |
6477 | 6317 | If the substring is not found, C<index> returns -1. |
6478 | 6318 | |
6479 | 6319 | =end original |
6480 | 6320 | |
6481 | 6321 | index 関数は ある文字列をもうひとつの文字列から検索しますが、 |
6482 | 6322 | 完全正規表現パターンマッチのワイルドカード的な振る舞いはしません。 |
6483 | 6323 | STR の中の POSITION の位置以降で、最初に SUBSTR が見つかった位置を返します。 |
6484 | 6324 | POSITION が省略された場合には、STR の最初から探し始めます。 |
6485 | 6325 | POSITION が文字列の先頭より前、あるいは末尾より後ろを指定した場合は、 |
6486 | 6326 | それぞれ先頭と末尾を指定されたものとして扱われます。 |
6487 | 6327 | POSITION と返り値のベースは、0 です。 |
6488 | 6328 | SUBSTR が見つからなかった場合には、C<index> は -1 が返されます。 |
6489 | 6329 | |
6490 | 6330 | =item int EXPR |
6491 | 6331 | X<int> X<integer> X<truncate> X<trunc> X<floor> |
6492 | 6332 | |
6493 | 6333 | =item int |
6494 | 6334 | |
6495 | 6335 | =for Pod::Functions get the integer portion of a number |
6496 | 6336 | |
6497 | 6337 | =begin original |
6498 | 6338 | |
6499 | 6339 | Returns the integer portion of EXPR. If EXPR is omitted, uses C<$_>. |
6500 | 6340 | You should not use this function for rounding: one because it truncates |
6501 | 6341 | towards C<0>, and two because machine representations of floating-point |
6502 | 6342 | numbers can sometimes produce counterintuitive results. For example, |
6503 | 6343 | C<int(-6.725/0.025)> produces -268 rather than the correct -269; that's |
6504 | 6344 | because it's really more like -268.99999999999994315658 instead. Usually, |
6505 | 6345 | the C<sprintf>, C<printf>, or the C<POSIX::floor> and C<POSIX::ceil> |
6506 | 6346 | functions will serve you better than will int(). |
6507 | 6347 | |
6508 | 6348 | =end original |
6509 | 6349 | |
6510 | 6350 | EXPR の整数部を返します。 |
6511 | 6351 | EXPR が省略されると、C<$_> を使います。 |
6512 | 6352 | この関数を丸めのために使うべきではありません: 第一の理由として C<0> の |
6513 | 6353 | 方向への切捨てを行うから、第二の理由として浮動小数点数の機械表現は時々直感に |
6514 | 6354 | 反した結果を生み出すからです。 |
6515 | 6355 | たとえば、C<int(-6.725/0.025)> は正しい結果である -269 ではなく -268 を |
6516 | 6356 | 返します: これは実際には -268.99999999999994315658 というような値に |
6517 | 6357 | なっているからです。 |
6518 | 6358 | 通常、C<sprintf>, C<printf>, C<POSIX::floor>, C<POSIX::ceil> の方が |
6519 | 6359 | int() より便利です。 |
6520 | 6360 | |
6521 | 6361 | =item ioctl FILEHANDLE,FUNCTION,SCALAR |
6522 | 6362 | X<ioctl> |
6523 | 6363 | |
6524 | 6364 | =for Pod::Functions system-dependent device control system call |
6525 | 6365 | |
6526 | 6366 | =begin original |
6527 | 6367 | |
6528 | 6368 | Implements the ioctl(2) function. You'll probably first have to say |
6529 | 6369 | |
6530 | 6370 | =end original |
6531 | 6371 | |
6532 | 6372 | ioctl(2) 関数を実装します。 |
6533 | 6373 | 正しい関数の定義を得るために、おそらく最初に |
6534 | 6374 | |
6535 | require "sys/ioctl.ph"; # probably in | |
6375 | require "sys/ioctl.ph"; # probably in $Config{archlib}/sys/ioctl.ph | |
6536 | # $Config{archlib}/sys/ioctl.ph | |
6537 | 6376 | |
6538 | 6377 | =begin original |
6539 | 6378 | |
6540 | 6379 | to get the correct function definitions. If F<sys/ioctl.ph> doesn't |
6541 | 6380 | exist or doesn't have the correct definitions you'll have to roll your |
6542 | 6381 | own, based on your C header files such as F<< <sys/ioctl.h> >>. |
6543 | 6382 | (There is a Perl script called B<h2ph> that comes with the Perl kit that |
6544 | 6383 | may help you in this, but it's nontrivial.) SCALAR will be read and/or |
6545 | 6384 | written depending on the FUNCTION; a C pointer to the string value of SCALAR |
6546 | 6385 | will be passed as the third argument of the actual C<ioctl> call. (If SCALAR |
6547 | 6386 | has no string value but does have a numeric value, that value will be |
6548 | 6387 | passed rather than a pointer to the string value. To guarantee this to be |
6549 | 6388 | true, add a C<0> to the scalar before using it.) The C<pack> and C<unpack> |
6550 | 6389 | functions may be needed to manipulate the values of structures used by |
6551 | 6390 | C<ioctl>. |
6552 | 6391 | |
6553 | 6392 | =end original |
6554 | 6393 | |
6555 | 6394 | としなくてはならないでしょう。 |
6556 | 6395 | F<sys/ioctl.ph> がないか、間違った定義をしている場合には、 |
6557 | F<< <sys/ioctl.h> >>のような C のヘッダファイルをもとに、 | |
6396 | F<< <sys/ioctl.ph> >>のような C のヘッダファイルをもとに、 | |
6558 | 6397 | 自分で作らなければなりません。 |
6559 | (Perl の配布キットに入っている B<h2ph> という | |
6398 | (Perl の配布キットに入っている B<h2ph> という | |
6560 | これを手助けしてくれるでしょうが、これは | |
6399 | Perl スクリプトがこれを手助けしてくれるでしょうが、これは重要です。) | |
6561 | 6400 | FOUNCTION に応じて SCALAR が読み書きされます; |
6562 | 6401 | SCALAR の文字列値へのポインタが、実際の C<ioctl> コールの |
6563 | 6402 | 3 番目の引数として渡されます。 |
6564 | 6403 | (SCALAR が文字列値を持っておらず、数値を持っている場合には、 |
6565 | 6404 | 文字列値へのポインタの代わりに、その値が渡されます。 |
6566 | 6405 | このことを保証するためには、使用する前に SCALAR にC<0> を足してください。) |
6567 | 6406 | C<ioctl> で使われる構造体の値を操作するには、 |
6568 | 6407 | C<pack> 関数と C<unpack> 関数が必要となるでしょう。 |
6569 | 6408 | |
6570 | 6409 | =begin original |
6571 | 6410 | |
6572 | 6411 | The return value of C<ioctl> (and C<fcntl>) is as follows: |
6573 | 6412 | |
6574 | 6413 | =end original |
6575 | 6414 | |
6576 | 6415 | C<ioctl> (と C<fcntl>) の返り値は、以下のようになります: |
6577 | 6416 | |
6578 | 6417 | =begin original |
6579 | 6418 | |
6580 | 6419 | if OS returns: then Perl returns: |
6581 | 6420 | -1 undefined value |
6582 | 6421 | 0 string "0 but true" |
6583 | 6422 | anything else that number |
6584 | 6423 | |
6585 | 6424 | =end original |
6586 | 6425 | |
6587 | 6426 | OS が返した値: Perl が返す値: |
6588 | 6427 | -1 未定義値 |
6589 | 6428 | 0 「0 だが真」の文字列 |
6590 | 6429 | その他 その値そのもの |
6591 | 6430 | |
6592 | 6431 | =begin original |
6593 | 6432 | |
6594 | 6433 | Thus Perl returns true on success and false on failure, yet you can |
6595 | 6434 | still easily determine the actual value returned by the operating |
6596 | 6435 | system: |
6597 | 6436 | |
6598 | 6437 | =end original |
6599 | 6438 | |
6600 | 6439 | つまり Perl は、成功時に「真」、失敗時に「偽」を返す |
6601 | 6440 | ことになり、OS が実際に返した値も、以下のように簡単に知ることができます。 |
6602 | 6441 | |
6603 | 6442 | $retval = ioctl(...) || -1; |
6604 | 6443 | printf "System returned %d\n", $retval; |
6605 | 6444 | |
6606 | 6445 | =begin original |
6607 | 6446 | |
6608 | 6447 | The special string C<"0 but true"> is exempt from B<-w> complaints |
6609 | 6448 | about improper numeric conversions. |
6610 | 6449 | |
6611 | 6450 | =end original |
6612 | 6451 | |
6613 | 6452 | 特別な文字列 C<"0 だが真"> は、不適切な数値変換に関する |
6614 | 6453 | B<-w> 警告を回避します。 |
6615 | 6454 | |
6616 | 6455 | =begin original |
6617 | 6456 | |
6618 | 6457 | Portability issues: L<perlport/ioctl>. |
6619 | 6458 | |
6620 | 6459 | =end original |
6621 | 6460 | |
6622 | 6461 | 移植性の問題: L<perlport/ioctl>。 |
6623 | 6462 | |
6624 | 6463 | =item join EXPR,LIST |
6625 | 6464 | X<join> |
6626 | 6465 | |
6627 | 6466 | =for Pod::Functions join a list into a string using a separator |
6628 | 6467 | |
6629 | 6468 | =begin original |
6630 | 6469 | |
6631 | 6470 | Joins the separate strings of LIST into a single string with fields |
6632 | 6471 | separated by the value of EXPR, and returns that new string. Example: |
6633 | 6472 | |
6634 | 6473 | =end original |
6635 | 6474 | |
6636 | 6475 | LIST の個別の文字列を、EXPR の値で区切って |
6637 | 6476 | 1 つの文字列につなげ、その文字列を返します。 |
6638 | 6477 | 例: |
6639 | 6478 | |
6640 | 6479 | $rec = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell); |
6641 | 6480 | |
6642 | 6481 | =begin original |
6643 | 6482 | |
6644 | 6483 | Beware that unlike C<split>, C<join> doesn't take a pattern as its |
6645 | 6484 | first argument. Compare L</split>. |
6646 | 6485 | |
6647 | 6486 | =end original |
6648 | 6487 | |
6649 | 6488 | C<split> と違って、C<join> は最初の引数にパターンは取れないことに |
6650 | 6489 | 注意してください。 |
6651 | 6490 | L</split> と比較してください。 |
6652 | 6491 | |
6653 | 6492 | =item keys HASH |
6654 | 6493 | X<keys> X<key> |
6655 | 6494 | |
6656 | 6495 | =item keys ARRAY |
6657 | 6496 | |
6658 | 6497 | =item keys EXPR |
6659 | 6498 | |
6660 | 6499 | =for Pod::Functions retrieve list of indices from a hash |
6661 | 6500 | |
6662 | 6501 | =begin original |
6663 | 6502 | |
6664 | 6503 | Called in list context, returns a list consisting of all the keys of the |
6665 | 6504 | named hash, or in Perl 5.12 or later only, the indices of an array. Perl |
6666 | 6505 | releases prior to 5.12 will produce a syntax error if you try to use an |
6667 | 6506 | array argument. In scalar context, returns the number of keys or indices. |
6668 | 6507 | |
6669 | 6508 | =end original |
6670 | 6509 | |
6671 | 6510 | リストコンテキストで呼び出されると、指定したハッシュのすべてのキー、あるいは |
6672 | Perl 5.12 以降でのみ、配列のインデックスからなるリストを | |
6511 | Perl 5.12 以降でのみ、配列のインデックスからなるリストを | |
6512 | 返します。 | |
6673 | 6513 | 5.12 より前の Perl は配列引数を使おうとすると文法エラーを出力します。 |
6674 | 6514 | スカラコンテキストでは、キーやインデックスの数を返します。 |
6675 | 6515 | |
6676 | 6516 | =begin original |
6677 | 6517 | |
6678 | ||
6518 | The keys of a hash are returned in an apparently random order. The actual | |
6679 | order is s | |
6519 | random order is subject to change in future versions of Perl, but it | |
6680 | ||
6520 | is guaranteed to be the same order as either the C<values> or C<each> | |
6681 | ||
6521 | function produces (given that the hash has not been modified). Since | |
6682 | ||
6522 | Perl 5.8.1 the ordering can be different even between different runs of | |
6683 | ||
6523 | Perl for security reasons (see L<perlsec/"Algorithmic Complexity | |
6684 | ||
6524 | Attacks">). | |
6685 | as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for | |
6686 | details on why hash order is randomized. Aside from the guarantees | |
6687 | provided here the exact details of Perl's hash algorithm and the hash | |
6688 | traversal order are subject to change in any release of Perl. Tied hashes | |
6689 | may behave differently to Perl's hashes with respect to changes in order on | |
6690 | insertion and deletion of items. | |
6691 | 6525 | |
6692 | 6526 | =end original |
6693 | 6527 | |
6694 | ハッシュ | |
6528 | ハッシュのキーは見たところではランダムな順番に返されます。 | |
6695 | 実際のランダムな順 | |
6529 | 実際のランダムな順番は Perl の将来のバージョンでは変わるかもしれませんが、 | |
6696 | ||
6530 | C<values> や C<each> 関数が同じ(変更されていない)ハッシュに対して | |
6697 | ||
6531 | 生成するのと同じ順番であることは保証されます。 | |
6698 | ||
6532 | Perl 5.8.1 以降ではセキュリティ上の理由により、 | |
6699 | ||
6533 | 実行される毎に順番は変わります | |
6700 | ||
6534 | (L<perlsec/"Algorithmic Complexity Attacks"> を参照してください)。 | |
6701 | 返すことに依存してもかまいません。 | |
6702 | なぜハッシュの順序がランダム化されているかの詳細については | |
6703 | L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。 | |
6704 | ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の | |
6705 | 正確な詳細は Perl のリリースによって変更される可能性があります。 | |
6706 | tie されたハッシュは、アイテムの挿入と削除の順序に関して Perl のハッシュと | |
6707 | 異なった振る舞いをします。 | |
6708 | 6535 | |
6709 | 6536 | =begin original |
6710 | 6537 | |
6711 | As a side effect, calling keys() resets the internal iterator of the HASH or | |
6538 | As a side effect, calling keys() resets the internal interator of the HASH or ARRAY | |
6712 | ||
6539 | (see L</each>). In particular, calling keys() in void context resets | |
6713 | 6540 | the iterator with no other overhead. |
6714 | 6541 | |
6715 | 6542 | =end original |
6716 | 6543 | |
6717 | 6544 | 副作用として、HASH や ARRAY の反復子を初期化します |
6718 | 6545 | (L</each> を参照してください)。 |
6719 | 6546 | 特に、無効コンテキストで keys() を呼び出すと |
6720 | 6547 | オーバーヘッドなしで反復子を初期化します。 |
6721 | 6548 | |
6722 | 6549 | =begin original |
6723 | 6550 | |
6724 | 6551 | Here is yet another way to print your environment: |
6725 | 6552 | |
6726 | 6553 | =end original |
6727 | 6554 | |
6728 | 6555 | 環境変数を表示する別の例です: |
6729 | 6556 | |
6730 | 6557 | @keys = keys %ENV; |
6731 | 6558 | @values = values %ENV; |
6732 | 6559 | while (@keys) { |
6733 | 6560 | print pop(@keys), '=', pop(@values), "\n"; |
6734 | 6561 | } |
6735 | 6562 | |
6736 | 6563 | =begin original |
6737 | 6564 | |
6738 | 6565 | or how about sorted by key: |
6739 | 6566 | |
6740 | 6567 | =end original |
6741 | 6568 | |
6742 | 6569 | key でソートしてもいいでしょう: |
6743 | 6570 | |
6744 | 6571 | foreach $key (sort(keys %ENV)) { |
6745 | 6572 | print $key, '=', $ENV{$key}, "\n"; |
6746 | 6573 | } |
6747 | 6574 | |
6748 | 6575 | =begin original |
6749 | 6576 | |
6750 | 6577 | The returned values are copies of the original keys in the hash, so |
6751 | 6578 | modifying them will not affect the original hash. Compare L</values>. |
6752 | 6579 | |
6753 | 6580 | =end original |
6754 | 6581 | |
6755 | 6582 | 返される値はハッシュにある元のキーのコピーなので、 |
6756 | 6583 | これを変更しても元のハッシュには影響を与えません。 |
6757 | 6584 | L</values> と比較してください。 |
6758 | 6585 | |
6759 | 6586 | =begin original |
6760 | 6587 | |
6761 | 6588 | To sort a hash by value, you'll need to use a C<sort> function. |
6762 | 6589 | Here's a descending numeric sort of a hash by its values: |
6763 | 6590 | |
6764 | 6591 | =end original |
6765 | 6592 | |
6766 | 6593 | ハッシュを値でソートするためには、C<sort> 関数を使う必要があります。 |
6767 | 6594 | 以下ではハッシュの値を数値の降順でソートしています: |
6768 | 6595 | |
6769 | 6596 | foreach $key (sort { $hash{$b} <=> $hash{$a} } keys %hash) { |
6770 | 6597 | printf "%4d %s\n", $hash{$key}, $key; |
6771 | 6598 | } |
6772 | 6599 | |
6773 | 6600 | =begin original |
6774 | 6601 | |
6775 | 6602 | Used as an lvalue, C<keys> allows you to increase the number of hash buckets |
6776 | 6603 | allocated for the given hash. This can gain you a measure of efficiency if |
6777 | 6604 | you know the hash is going to get big. (This is similar to pre-extending |
6778 | 6605 | an array by assigning a larger number to $#array.) If you say |
6779 | 6606 | |
6780 | 6607 | =end original |
6781 | 6608 | |
6782 | 6609 | 左辺値として使うことで、C<keys> を使うことで与えられたハッシュに割り当てられた |
6783 | 6610 | ハッシュ表の大きさを増やすことができます。 |
6784 | 6611 | これによって、ハッシュが大きくなっていくなっていくときの |
6785 | 6612 | 効率の測定ができます。 |
6786 | 6613 | (これは大きい値を $#array に代入することで配列を予め拡張することに |
6787 | 6614 | 似ています。) |
6788 | 6615 | 以下のようにすると: |
6789 | 6616 | |
6790 | 6617 | keys %hash = 200; |
6791 | 6618 | |
6792 | 6619 | =begin original |
6793 | 6620 | |
6794 | 6621 | then C<%hash> will have at least 200 buckets allocated for it--256 of them, |
6795 | 6622 | in fact, since it rounds up to the next power of two. These |
6796 | 6623 | buckets will be retained even if you do C<%hash = ()>, use C<undef |
6797 | 6624 | %hash> if you want to free the storage while C<%hash> is still in scope. |
6798 | 6625 | You can't shrink the number of buckets allocated for the hash using |
6799 | 6626 | C<keys> in this way (but you needn't worry about doing this by accident, |
6800 | 6627 | as trying has no effect). C<keys @array> in an lvalue context is a syntax |
6801 | 6628 | error. |
6802 | 6629 | |
6803 | 6630 | =end original |
6804 | 6631 | |
6805 | 6632 | C<%hash> は少なくとも 200 の大きさの表が割り当てられます -- |
6806 | 6633 | 実際には 2 のべき乗に切り上げられるので、256 が割り当てられます。 |
6807 | 6634 | この表はたとえ C<%hash = ()> としても残るので、 |
6808 | 6635 | もし C<%hash> がスコープにいるうちにこの領域を開放したい場合は |
6809 | 6636 | C<undef %hash> を使います。 |
6810 | 6637 | この方法で C<keys> を使うことで、表の大きさを小さくすることはできません |
6811 | 6638 | (間違えてそのようなことをしても何も起きないので気にすることはありません)。 |
6812 | 6639 | 左辺値コンテキストでの C<keys @array> は文法エラーとなります。 |
6813 | 6640 | |
6814 | 6641 | =begin original |
6815 | 6642 | |
6816 | 6643 | Starting with Perl 5.14, C<keys> can take a scalar EXPR, which must contain |
6817 | 6644 | a reference to an unblessed hash or array. The argument will be |
6818 | 6645 | dereferenced automatically. This aspect of C<keys> is considered highly |
6819 | 6646 | experimental. The exact behaviour may change in a future version of Perl. |
6820 | 6647 | |
6821 | 6648 | =end original |
6822 | 6649 | |
6823 | 6650 | Perl 5.14 から、C<keys> はスカラの EXPR を取ることができるようになりました; |
6824 | 6651 | これは bless されていないハッシュや配列へのリファレンスでなければなりません。 |
6825 | 6652 | 引数は自動的にデリファレンスされます。 |
6826 | 6653 | C<keys> のこの動作は高度に実験的であると考えられています。 |
6827 | 6654 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 |
6828 | 6655 | |
6829 | 6656 | for (keys $hashref) { ... } |
6830 | 6657 | for (keys $obj->get_arrayref) { ... } |
6831 | 6658 | |
6832 | 6659 | =begin original |
6833 | 6660 | |
6834 | 6661 | To avoid confusing would-be users of your code who are running earlier |
6835 | 6662 | versions of Perl with mysterious syntax errors, put this sort of thing at |
6836 | 6663 | the top of your file to signal that your code will work I<only> on Perls of |
6837 | 6664 | a recent vintage: |
6838 | 6665 | |
6839 | 6666 | =end original |
6840 | 6667 | |
6841 | 6668 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な |
6842 | 6669 | 文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で |
6843 | 6670 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを |
6844 | 6671 | 書いてください: |
6845 | 6672 | |
6846 | 6673 | use 5.012; # so keys/values/each work on arrays |
6847 | 6674 | use 5.014; # so keys/values/each work on scalars (experimental) |
6848 | 6675 | |
6849 | 6676 | =begin original |
6850 | 6677 | |
6851 | 6678 | See also C<each>, C<values>, and C<sort>. |
6852 | 6679 | |
6853 | 6680 | =end original |
6854 | 6681 | |
6855 | 6682 | C<each>, C<values>, C<sort> も参照してください。 |
6856 | 6683 | |
6857 | 6684 | =item kill SIGNAL, LIST |
6858 | 6685 | |
6859 | 6686 | =item kill SIGNAL |
6860 | 6687 | X<kill> X<signal> |
6861 | 6688 | |
6862 | 6689 | =for Pod::Functions send a signal to a process or process group |
6863 | 6690 | |
6864 | 6691 | =begin original |
6865 | 6692 | |
6866 | Sends a signal to a list of processes. Returns the number of | |
6693 | Sends a signal to a list of processes. Returns the number of | |
6867 | ||
6694 | processes successfully signaled (which is not necessarily the | |
6868 | as the number | |
6695 | same as the number actually killed). | |
6869 | killed). | |
6870 | 6696 | |
6871 | 6697 | =end original |
6872 | 6698 | |
6873 | 6699 | プロセスのリストにシグナルを送ります。 |
6874 | シグナル送信に | |
6700 | シグナル送信に成功したプロセスの数を返します | |
6875 | ( | |
6701 | (実際に kill に成功したプロセスと同じとは限りません)。 | |
6876 | プロセスの数と同じとは限りません)。 | |
6877 | 6702 | |
6878 | $cnt = kill | |
6703 | $cnt = kill 1, $child1, $child2; | |
6879 | kill | |
6704 | kill 9, @goners; | |
6880 | 6705 | |
6881 | 6706 | =begin original |
6882 | 6707 | |
6883 | SIGNAL | |
6708 | If SIGNAL is zero, no signal is sent to the process, but C<kill> | |
6884 | ||
6709 | checks whether it's I<possible> to send a signal to it (that | |
6885 | ||
6710 | means, to be brief, that the process is owned by the same user, or we are | |
6886 | the s | |
6711 | the super-user). This is useful to check that a child process is still | |
6712 | alive (even if only as a zombie) and hasn't changed its UID. See | |
6713 | L<perlport> for notes on the portability of this construct. | |
6887 | 6714 | |
6888 | 6715 | =end original |
6889 | 6716 | |
6890 | SIGNAL | |
6717 | SIGNAL がゼロの場合、プロセスにシグナルは送られませんが、 | |
6891 | ||
6718 | C<kill> は、シグナルを送ることが I<可能> かどうかを調べます | |
6892 | ||
6719 | (これは、簡単に言うと、プロセスが同じユーザーに所有されているか、 | |
6893 | ||
6720 | 自分がスーパーユーザーであることを意味します)。 | |
6894 | ||
6721 | これは子プロセスが(ゾンビとしてだけでも)まだ生きていて、 UID が | |
6722 | 変わっていないことを調べる時に有用です。 | |
6723 | この構成の移植性に関する注意については L<perlport> を参照してください。 | |
6895 | 6724 | |
6896 | 6725 | =begin original |
6897 | 6726 | |
6898 | ||
6727 | Unlike in the shell, if SIGNAL is negative, it kills process groups instead | |
6899 | ||
6728 | of processes. That means you usually | |
6900 | ||
6729 | want to use positive not negative signals. | |
6730 | You may also use a signal name in quotes. | |
6901 | 6731 | |
6902 | 6732 | =end original |
6903 | 6733 | |
6904 | ||
6734 | シェルとは異なり、シグナルに負の数を与えると、 | |
6905 | モジュールによって提供される C<$Config{sig_name}> にあります。 | |
6906 | さらなる詳細については L<Config> を参照してください。 | |
6907 | ||
6908 | =begin original | |
6909 | ||
6910 | A negative signal name is the same as a negative signal number, killing process | |
6911 | groups instead of processes. For example, C<kill '-KILL', $pgrp> and | |
6912 | C<kill -9, $pgrp> will send C<SIGKILL> to | |
6913 | the entire process group specified. That | |
6914 | means you usually want to use positive not negative signals. | |
6915 | ||
6916 | =end original | |
6917 | ||
6918 | 負のシグナル名は負のシグナル番号と同じで、 | |
6919 | 6735 | プロセスではなくプロセスグループに対して kill を行ないます。 |
6920 | たとえば、C<kill '-KILL', $pgrp> と C<kill -9, $pgrp> は指定された | |
6921 | プロセスグループ全体に C<SIGKILL> を送ります。 | |
6922 | 6736 | すなわち、通常は、負のシグナルは用いず、正のシグナルを使うことになります。 |
6737 | シグナル名をクォートして使うこともできます。 | |
6923 | 6738 | |
6924 | 6739 | =begin original |
6925 | 6740 | |
6926 | If SIGNAL is either the number 0 or the string C<ZERO> (or C<SIGZERO>), | |
6927 | no signal is sent to | |
6928 | the process, but C<kill> checks whether it's I<possible> to send a signal to it | |
6929 | (that means, to be brief, that the process is owned by the same user, or we are | |
6930 | the super-user). This is useful to check that a child process is still | |
6931 | alive (even if only as a zombie) and hasn't changed its UID. See | |
6932 | L<perlport> for notes on the portability of this construct. | |
6933 | ||
6934 | =end original | |
6935 | ||
6936 | SIGNAL が数値 0 か文字列 C<ZERO> (または C<SIGZERO> の場合、プロセスに | |
6937 | シグナルは送られませんが、C<kill> は、シグナルを送ることが I<可能> かどうかを | |
6938 | 調べます (これは、簡単に言うと、プロセスが同じユーザーに所有されているか、 | |
6939 | 自分がスーパーユーザーであることを意味します)。 | |
6940 | これは子プロセスが(ゾンビとしてだけでも)まだ生きていて、 UID が | |
6941 | 変わっていないことを調べる時に有用です。 | |
6942 | この構成の移植性に関する注意については L<perlport> を参照してください。 | |
6943 | ||
6944 | =begin original | |
6945 | ||
6946 | 6741 | The behavior of kill when a I<PROCESS> number is zero or negative depends on |
6947 | 6742 | the operating system. For example, on POSIX-conforming systems, zero will |
6948 | signal the current process group | |
6743 | signal the current process group and -1 will signal all processes. | |
6949 | other negative PROCESS number will act as a negative signal number and | |
6950 | kill the entire process group specified. | |
6951 | 6744 | |
6952 | 6745 | =end original |
6953 | 6746 | |
6954 | 6747 | I<PROCESS> 番号が 0 あるいは負数の場合の kill の振る舞いは |
6955 | 6748 | オペレーティングシステムに依存します。 |
6956 | 6749 | 例えば、POSIX 準拠のシステムでは、0 は現在のプロセスグループにシグナルを送り、 |
6957 | -1 は全てのプロセスにシグナルを送り | |
6750 | -1 は全てのプロセスにシグナルを送ります。 | |
6958 | 負数のシグナル番号として動作し、指定されたプロセスグループ全体を kill します。 | |
6959 | 6751 | |
6960 | 6752 | =begin original |
6961 | 6753 | |
6962 | If both the SIGNAL and the PROCESS are negative, the results are undefined. | |
6963 | A warning may be produced in a future version. | |
6964 | ||
6965 | =end original | |
6966 | ||
6967 | SIGNAL と PROCESS の両方が負数の場合、結果は未定義です。 | |
6968 | 将来のバージョンでは警告が出るかも知れません。 | |
6969 | ||
6970 | =begin original | |
6971 | ||
6972 | 6754 | See L<perlipc/"Signals"> for more details. |
6973 | 6755 | |
6974 | 6756 | =end original |
6975 | 6757 | |
6976 | 6758 | 詳細は L<perlipc/"Signals"> を参照してください。 |
6977 | 6759 | |
6978 | 6760 | =begin original |
6979 | 6761 | |
6980 | On some platforms such as Windows where the fork() system call is not | |
6762 | On some platforms such as Windows where the fork() system call is not available. | |
6981 | ||
6763 | Perl can be built to emulate fork() at the interpreter level. | |
6982 | 6764 | This emulation has limitations related to kill that have to be considered, |
6983 | 6765 | for code running on Windows and in code intended to be portable. |
6984 | 6766 | |
6985 | 6767 | =end original |
6986 | 6768 | |
6987 | 6769 | Windows のような fork() が利用不能なシステムでは、Perl は fork() を |
6988 | 6770 | インタプリタレベルでエミュレートします。 |
6989 | 6771 | エミュレーションは kill に関連して、コードが Windows で実行されて |
6990 | 6772 | しかしコードが移植性があると考えられるように制限があります。 |
6991 | 6773 | |
6992 | 6774 | =begin original |
6993 | 6775 | |
6994 | 6776 | See L<perlfork> for more details. |
6995 | 6777 | |
6996 | 6778 | =end original |
6997 | 6779 | |
6998 | 6780 | さらなる詳細については L<perlfork> を参照してください。 |
6999 | 6781 | |
7000 | 6782 | =begin original |
7001 | 6783 | |
7002 | 6784 | If there is no I<LIST> of processes, no signal is sent, and the return |
7003 | 6785 | value is 0. This form is sometimes used, however, because it causes |
7004 | 6786 | tainting checks to be run. But see |
7005 | 6787 | L<perlsec/Laundering and Detecting Tainted Data>. |
7006 | 6788 | |
7007 | 6789 | =end original |
7008 | 6790 | |
7009 | 6791 | 処理する I<LIST> がない場合、シグナルは送られず、返り値は 0 です。 |
7010 | 6792 | しかし、この形式は時々使われます; 実行するために汚染チェックを |
7011 | 6793 | 引き起こすからです。 |
7012 | 6794 | しかし L<perlsec/Laundering and Detecting Tainted Data> を参照してください。 |
7013 | 6795 | |
7014 | 6796 | =begin original |
7015 | 6797 | |
7016 | 6798 | Portability issues: L<perlport/kill>. |
7017 | 6799 | |
7018 | 6800 | =end original |
7019 | 6801 | |
7020 | 6802 | 移植性の問題: L<perlport/kill>。 |
7021 | 6803 | |
7022 | 6804 | =item last LABEL |
7023 | 6805 | X<last> X<break> |
7024 | 6806 | |
7025 | =item last EXPR | |
7026 | ||
7027 | 6807 | =item last |
7028 | 6808 | |
7029 | 6809 | =for Pod::Functions exit a block prematurely |
7030 | 6810 | |
7031 | 6811 | =begin original |
7032 | 6812 | |
7033 | 6813 | The C<last> command is like the C<break> statement in C (as used in |
7034 | 6814 | loops); it immediately exits the loop in question. If the LABEL is |
7035 | omitted, the command refers to the innermost enclosing | |
6815 | omitted, the command refers to the innermost enclosing loop. The | |
7036 | loop. The C<last EXPR> form, available starting in Perl | |
7037 | 5.18.0, allows a label name to be computed at run time, | |
7038 | and is otherwise identical to C<last LABEL>. The | |
7039 | 6816 | C<continue> block, if any, is not executed: |
7040 | 6817 | |
7041 | 6818 | =end original |
7042 | 6819 | |
7043 | 6820 | C<last> コマンドは、(ループ内で使った) C の C<break> 文と |
7044 | 6821 | 同じようなもので、LABEL で指定されるループを即座に抜けます。 |
7045 | 6822 | LABEL が省略されると、コマンドは一番内側のループを参照します。 |
7046 | Perl 5.18.0 から利用可能な C<last EXPR> 形式では、実行時に計算される | |
7047 | ラベル名を使えます; それ以外は C<last LABEL> と同一です。 | |
7048 | 6823 | C<continue> ブロックがあっても実行されません: |
7049 | 6824 | |
7050 | 6825 | LINE: while (<STDIN>) { |
7051 | 6826 | last LINE if /^$/; # exit when done with header |
7052 | 6827 | #... |
7053 | 6828 | } |
7054 | 6829 | |
7055 | 6830 | =begin original |
7056 | 6831 | |
7057 | 6832 | C<last> cannot be used to exit a block that returns a value such as |
7058 | 6833 | C<eval {}>, C<sub {}>, or C<do {}>, and should not be used to exit |
7059 | 6834 | a grep() or map() operation. |
7060 | 6835 | |
7061 | 6836 | =end original |
7062 | 6837 | |
7063 | 6838 | C<last> は C<eval {}>, C<sub {}>, C<do {}> といった |
7064 | 6839 | 値を返すブロックを終了するのには使えませんし、 |
7065 | 6840 | grep() や map() 操作を終了するのに使うべきではありません。 |
7066 | 6841 | |
7067 | 6842 | =begin original |
7068 | 6843 | |
7069 | 6844 | Note that a block by itself is semantically identical to a loop |
7070 | 6845 | that executes once. Thus C<last> can be used to effect an early |
7071 | 6846 | exit out of such a block. |
7072 | 6847 | |
7073 | 6848 | =end original |
7074 | 6849 | |
7075 | 6850 | ブロック自身は一回だけ実行されるループと文法的に同一であることに |
7076 | 6851 | 注意してください。 |
7077 | 6852 | 従って、C<last> でそのようなブロックを途中で抜け出すことができます。 |
7078 | 6853 | |
7079 | 6854 | =begin original |
7080 | 6855 | |
7081 | 6856 | See also L</continue> for an illustration of how C<last>, C<next>, and |
7082 | 6857 | C<redo> work. |
7083 | 6858 | |
7084 | 6859 | =end original |
7085 | 6860 | |
7086 | 6861 | C<last>, C<next>, C<redo> がどのように働くかについては |
7087 | 6862 | L</continue> も参照してください。 |
7088 | 6863 | |
7089 | =begin original | |
7090 | ||
7091 | Unlike most named operators, this has the same precedence as assignment. | |
7092 | It is also exempt from the looks-like-a-function rule, so | |
7093 | C<last ("foo")."bar"> will cause "bar" to be part of the argument to | |
7094 | C<last>. | |
7095 | ||
7096 | =end original | |
7097 | ||
7098 | ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 | |
7099 | また、関数のように見えるものの規則からも免れるので、C<last ("foo")."bar"> と | |
7100 | すると "bar" は C<last> への引数の一部となります。 | |
7101 | ||
7102 | 6864 | =item lc EXPR |
7103 | 6865 | X<lc> X<lowercase> |
7104 | 6866 | |
7105 | 6867 | =item lc |
7106 | 6868 | |
7107 | 6869 | =for Pod::Functions return lower-case version of a string |
7108 | 6870 | |
7109 | 6871 | =begin original |
7110 | 6872 | |
7111 | 6873 | Returns a lowercased version of EXPR. This is the internal function |
7112 | 6874 | implementing the C<\L> escape in double-quoted strings. |
7113 | 6875 | |
7114 | 6876 | =end original |
7115 | 6877 | |
7116 | 6878 | EXPR を小文字に変換したものを返します。 |
7117 | 6879 | これは、ダブルクォート文字列における、 |
7118 | 6880 | C<\L> エスケープを実装する内部関数です。 |
7119 | 6881 | |
7120 | 6882 | =begin original |
7121 | 6883 | |
7122 | 6884 | If EXPR is omitted, uses C<$_>. |
7123 | 6885 | |
7124 | 6886 | =end original |
7125 | 6887 | |
7126 | 6888 | EXPR が省略されると、C<$_> を使います。 |
7127 | 6889 | |
7128 | 6890 | =begin original |
7129 | 6891 | |
7130 | 6892 | What gets returned depends on several factors: |
7131 | 6893 | |
7132 | 6894 | =end original |
7133 | 6895 | |
7134 | 6896 | 返り値として得られるものは色々な要素に依存します: |
7135 | 6897 | |
7136 | 6898 | =over |
7137 | 6899 | |
7138 | 6900 | =item If C<use bytes> is in effect: |
7139 | 6901 | |
7140 | 6902 | (C<use bytes> が有効の場合) |
7141 | 6903 | |
6904 | =over | |
6905 | ||
6906 | =item On EBCDIC platforms | |
6907 | ||
7142 | 6908 | =begin original |
7143 | 6909 | |
7144 | The results | |
6910 | The results are what the C language system call C<tolower()> returns. | |
7145 | to C<a-z> respectively. | |
7146 | 6911 | |
7147 | 6912 | =end original |
7148 | 6913 | |
7149 | 結果は | |
6914 | 結果は、C 言語のシステムコール C<tolower()> が返すものです。 | |
6915 | ||
6916 | =item On ASCII platforms | |
6917 | ||
6918 | =begin original | |
6919 | ||
6920 | The results follow ASCII semantics. Only characters C<A-Z> change, to C<a-z> | |
6921 | respectively. | |
6922 | ||
6923 | =end original | |
6924 | ||
6925 | 結果は ASCII の意味論に従います。 | |
7150 | 6926 | C<A-Z> のみが変換され、それぞれ C<a-z> になります。 |
7151 | 6927 | |
6928 | =back | |
6929 | ||
7152 | 6930 | =item Otherwise, if C<use locale> (but not C<use locale ':not_characters'>) is in effect: |
7153 | 6931 | |
7154 | 6932 | (それ以外の場合で、C<use locale> が有効の(そして C<use locale 'not_characters'> が有効でない)場合) |
7155 | 6933 | |
7156 | 6934 | =begin original |
7157 | 6935 | |
7158 | 6936 | Respects current LC_CTYPE locale for code points < 256; and uses Unicode |
7159 | ||
6937 | semantics for the remaining code points (this last can only happen if | |
7160 | 6938 | the UTF8 flag is also set). See L<perllocale>. |
7161 | 6939 | |
7162 | 6940 | =end original |
7163 | 6941 | |
7164 | 6942 | 符号位置 < 256 に対しては現在の LC_CTYPE ロケールに従います; そして |
7165 | 残りの符号位置に付いては Unicode の | |
6943 | 残りの符号位置に付いては Unicode の意味論を使います (これは UTF8 フラグも | |
7166 | 6944 | 設定されている場合にのみ起こります)。 |
7167 | 6945 | L<perllocale> を参照してください。 |
7168 | 6946 | |
7169 | 6947 | =begin original |
7170 | 6948 | |
7171 | ||
6949 | A deficiency in this is that case changes that cross the 255/256 | |
7172 | UTF-8. Otherwise, there is a deficiency in this scheme, which is that | |
7173 | case changes that cross the 255/256 | |
7174 | 6950 | boundary are not well-defined. For example, the lower case of LATIN CAPITAL |
7175 | LETTER SHARP S (U+1E9E) in Unicode | |
6951 | LETTER SHARP S (U+1E9E) in Unicode semantics is U+00DF (on ASCII | |
7176 | platforms). But under C<use locale> | |
6952 | platforms). But under C<use locale>, the lower case of U+1E9E is | |
7177 | locale), the lower case of U+1E9E is | |
7178 | 6953 | itself, because 0xDF may not be LATIN SMALL LETTER SHARP S in the |
7179 | 6954 | current locale, and Perl has no way of knowing if that character even |
7180 | 6955 | exists in the locale, much less what code point it is. Perl returns |
7181 | 6956 | the input character unchanged, for all instances (and there aren't |
7182 | 6957 | many) where the 255/256 boundary would otherwise be crossed. |
7183 | 6958 | |
7184 | 6959 | =end original |
7185 | 6960 | |
7186 | ||
6961 | これの欠点は、255/266 の境界をまたぐ大文字小文字の変換は | |
7187 | ||
6962 | 未定義であることです。 | |
7188 | 未定義であるという欠点があります。 | |
7189 | 6963 | 例えば、Unicode での LATIN CAPITAL LETTER SHARP S (U+1E9E) の小文字は |
7190 | 6964 | (ASCII プラットフォームでは) U+00DF です。 |
7191 | しかし C<use locale> が有効 | |
6965 | しかし C<use locale> が有効なら、U+1E9E の小文字は自分自身です; なぜなら | |
7192 | ||
6966 | 0xDF は現在のロケールでは LATIN SMALL LETTER SHARP S ではなく、Perl は | |
7193 | ||
6967 | 例えこのロケールに文字が存在するかどうかを知る方法がなく、まして | |
7194 | ||
6968 | どの符号位置かを知る方法がないからです。 | |
7195 | ないからです。 | |
7196 | 6969 | Perl は 255/256 境界をまたぐ全ての(多くはありません)実体については |
7197 | 6970 | 入力文字を変更せずに返します。 |
7198 | 6971 | |
7199 | 6972 | =item Otherwise, If EXPR has the UTF8 flag set: |
7200 | 6973 | |
7201 | 6974 | (その他の場合で、EXPR に UTF8 フラグがセットされている場合) |
7202 | 6975 | |
7203 | 6976 | =begin original |
7204 | 6977 | |
7205 | Unicode | |
6978 | Unicode semantics are used for the case change. | |
7206 | 6979 | |
7207 | 6980 | =end original |
7208 | 6981 | |
7209 | 大文字小文字変換には Unicode の | |
6982 | 大文字小文字変換には Unicode の意味論が使われます。 | |
7210 | 6983 | |
7211 | =item Otherwise, if C<use feature 'unicode_strings'> or C<use locale ':not_characters'> is in effect: | |
6984 | =item Otherwise, if C<use feature 'unicode_strings'> or C<use locale ':not_characters'>) is in effect: | |
7212 | 6985 | |
7213 | 6986 | (それ以外の場合で、C<use feature 'unicode_strings'> か C<use locale ':not_characters'> が有効の場合) |
7214 | 6987 | |
7215 | 6988 | =begin original |
7216 | 6989 | |
7217 | Unicode | |
6990 | Unicode semantics are used for the case change. | |
7218 | 6991 | |
7219 | 6992 | =end original |
7220 | 6993 | |
7221 | 大文字小文字変換には Unicode の | |
6994 | 大文字小文字変換には Unicode の意味論が使われます。 | |
7222 | 6995 | |
7223 | 6996 | =item Otherwise: |
7224 | 6997 | |
7225 | 6998 | (それ以外の場合) |
7226 | 6999 | |
7000 | =over | |
7001 | ||
7002 | =item On EBCDIC platforms | |
7003 | ||
7227 | 7004 | =begin original |
7228 | 7005 | |
7229 | ||
7006 | The results are what the C language system call C<tolower()> returns. | |
7007 | ||
7008 | =end original | |
7009 | ||
7010 | 結果は、C 言語のシステムコール C<tolower()> が返すものです。 | |
7011 | ||
7012 | =item On ASCII platforms | |
7013 | ||
7014 | =begin original | |
7015 | ||
7016 | ASCII semantics are used for the case change. The lowercase of any character | |
7230 | 7017 | outside the ASCII range is the character itself. |
7231 | 7018 | |
7232 | 7019 | =end original |
7233 | 7020 | |
7234 | 大文字小文字変換には ASCII の | |
7021 | 大文字小文字変換には ASCII の意味論が使われます。 | |
7235 | 7022 | ASCII の範囲外の文字の「小文字」はその文字自身です。 |
7236 | 7023 | |
7237 | 7024 | =back |
7238 | 7025 | |
7026 | =back | |
7027 | ||
7239 | 7028 | =item lcfirst EXPR |
7240 | 7029 | X<lcfirst> X<lowercase> |
7241 | 7030 | |
7242 | 7031 | =item lcfirst |
7243 | 7032 | |
7244 | 7033 | =for Pod::Functions return a string with just the next letter in lower case |
7245 | 7034 | |
7246 | 7035 | =begin original |
7247 | 7036 | |
7248 | 7037 | Returns the value of EXPR with the first character lowercased. This |
7249 | 7038 | is the internal function implementing the C<\l> escape in |
7250 | 7039 | double-quoted strings. |
7251 | 7040 | |
7252 | 7041 | =end original |
7253 | 7042 | |
7254 | 7043 | 最初の文字だけを小文字にした、EXPR を返します。 |
7255 | 7044 | これは、ダブルクォート文字列における、C<\l> エスケープを |
7256 | 7045 | 実装する内部関数です。 |
7257 | 7046 | |
7258 | 7047 | =begin original |
7259 | 7048 | |
7260 | 7049 | If EXPR is omitted, uses C<$_>. |
7261 | 7050 | |
7262 | 7051 | =end original |
7263 | 7052 | |
7264 | 7053 | EXPR が省略されると、C<$_> を使います。 |
7265 | 7054 | |
7266 | 7055 | =begin original |
7267 | 7056 | |
7268 | 7057 | This function behaves the same way under various pragmata, such as in a locale, |
7269 | 7058 | as L</lc> does. |
7270 | 7059 | |
7271 | 7060 | =end original |
7272 | 7061 | |
7273 | 7062 | この関数は、ロケールのようなさまざまなプラグマの影響下では、 |
7274 | 7063 | L</lc> と同様に振る舞います。 |
7275 | 7064 | |
7276 | 7065 | =item length EXPR |
7277 | 7066 | X<length> X<size> |
7278 | 7067 | |
7279 | 7068 | =item length |
7280 | 7069 | |
7281 | =for Pod::Functions return the number of | |
7070 | =for Pod::Functions return the number of bytes in a string | |
7282 | 7071 | |
7283 | 7072 | =begin original |
7284 | 7073 | |
7285 | 7074 | Returns the length in I<characters> of the value of EXPR. If EXPR is |
7286 | 7075 | omitted, returns the length of C<$_>. If EXPR is undefined, returns |
7287 | 7076 | C<undef>. |
7288 | 7077 | |
7289 | 7078 | =end original |
7290 | 7079 | |
7291 | 7080 | EXPR の値の I<文字> の長さを返します。 |
7292 | 7081 | EXPR が省略されたときには、C<$_> の長さを返します。 |
7293 | 7082 | EXPR が未定義値の場合、C<undef> を返します。 |
7294 | 7083 | |
7295 | 7084 | =begin original |
7296 | 7085 | |
7297 | 7086 | This function cannot be used on an entire array or hash to find out how |
7298 | 7087 | many elements these have. For that, use C<scalar @array> and C<scalar keys |
7299 | 7088 | %hash>, respectively. |
7300 | 7089 | |
7301 | 7090 | =end original |
7302 | 7091 | |
7303 | 7092 | この関数は配列やハッシュ全体に対してどれだけの要素を含んでいるかを |
7304 | 7093 | 調べるためには使えません。 |
7305 | 7094 | そのような用途には、それぞれ C<scalar @array> と C<scalar keys %hash> を |
7306 | 7095 | 利用してください。 |
7307 | 7096 | |
7308 | 7097 | =begin original |
7309 | 7098 | |
7310 | 7099 | Like all Perl character operations, length() normally deals in logical |
7311 | 7100 | characters, not physical bytes. For how many bytes a string encoded as |
7312 | 7101 | UTF-8 would take up, use C<length(Encode::encode_utf8(EXPR))> (you'll have |
7313 | 7102 | to C<use Encode> first). See L<Encode> and L<perlunicode>. |
7314 | 7103 | |
7315 | 7104 | =end original |
7316 | 7105 | |
7317 | 7106 | 全ての Perl の文字操作と同様、length() は通常物理的なバイトではなく |
7318 | 7107 | 論理文字を扱います。 |
7319 | 7108 | UTF-8 でエンコードされた文字列が何バイトかを知るには、 |
7320 | 7109 | C<length(Encode::encode_utf8(EXPR))> を使ってください (先に |
7321 | 7110 | C<use Encode> する必要があります)。 |
7322 | 7111 | L<Encode> と L<perlunicode> を参照してください。 |
7323 | 7112 | |
7324 | 7113 | =item __LINE__ |
7325 | 7114 | X<__LINE__> |
7326 | 7115 | |
7327 | 7116 | =for Pod::Functions the current source line number |
7328 | 7117 | |
7329 | 7118 | =begin original |
7330 | 7119 | |
7331 | 7120 | A special token that compiles to the current line number. |
7332 | 7121 | |
7333 | 7122 | =end original |
7334 | 7123 | |
7335 | 7124 | 現在の行番号にコンパイルされる特殊トークン。 |
7336 | 7125 | |
7337 | 7126 | =item link OLDFILE,NEWFILE |
7338 | 7127 | X<link> |
7339 | 7128 | |
7340 | 7129 | =for Pod::Functions create a hard link in the filesystem |
7341 | 7130 | |
7342 | 7131 | =begin original |
7343 | 7132 | |
7344 | 7133 | Creates a new filename linked to the old filename. Returns true for |
7345 | 7134 | success, false otherwise. |
7346 | 7135 | |
7347 | 7136 | =end original |
7348 | 7137 | |
7349 | 7138 | OLDFILE にリンクされた、新しいファイル NEWFILE を作ります。 |
7350 | 7139 | 成功時には真を、さもなければ偽を返します。 |
7351 | 7140 | |
7352 | 7141 | =begin original |
7353 | 7142 | |
7354 | 7143 | Portability issues: L<perlport/link>. |
7355 | 7144 | |
7356 | 7145 | =end original |
7357 | 7146 | |
7358 | 7147 | 移植性の問題: L<perlport/link>。 |
7359 | 7148 | |
7360 | 7149 | =item listen SOCKET,QUEUESIZE |
7361 | 7150 | X<listen> |
7362 | 7151 | |
7363 | 7152 | =for Pod::Functions register your socket as a server |
7364 | 7153 | |
7365 | 7154 | =begin original |
7366 | 7155 | |
7367 | 7156 | Does the same thing that the listen(2) system call does. Returns true if |
7368 | 7157 | it succeeded, false otherwise. See the example in |
7369 | 7158 | L<perlipc/"Sockets: Client/Server Communication">. |
7370 | 7159 | |
7371 | 7160 | =end original |
7372 | 7161 | |
7373 | 7162 | listen(2) システムコールと同じことをします。 |
7374 | 7163 | 成功時には真を、さもなければ偽を返します。 |
7375 | 7164 | L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。 |
7376 | 7165 | |
7377 | 7166 | =item local EXPR |
7378 | 7167 | X<local> |
7379 | 7168 | |
7380 | 7169 | =for Pod::Functions create a temporary value for a global variable (dynamic scoping) |
7381 | 7170 | |
7382 | 7171 | =begin original |
7383 | 7172 | |
7384 | 7173 | You really probably want to be using C<my> instead, because C<local> isn't |
7385 | 7174 | what most people think of as "local". See |
7386 | 7175 | L<perlsub/"Private Variables via my()"> for details. |
7387 | 7176 | |
7388 | 7177 | =end original |
7389 | 7178 | |
7390 | 7179 | あなたはが本当に望んでいるのは C<my> の方でしょう; C<local> はほとんどの |
7391 | 7180 | 人々が「ローカル」と考えるものと違うからです。 |
7392 | 7181 | 詳細は L<perlsub/"Private Variables via my()"> を参照してください。 |
7393 | 7182 | |
7394 | 7183 | =begin original |
7395 | 7184 | |
7396 | 7185 | A local modifies the listed variables to be local to the enclosing |
7397 | 7186 | block, file, or eval. If more than one value is listed, the list must |
7398 | 7187 | be placed in parentheses. See L<perlsub/"Temporary Values via local()"> |
7399 | 7188 | for details, including issues with tied arrays and hashes. |
7400 | 7189 | |
7401 | 7190 | =end original |
7402 | 7191 | |
7403 | 7192 | "local" はリストアップされた変数を、囲っているブロック、 |
7404 | 7193 | ファイル、eval の中で、ローカルなものにします。 |
7405 | 7194 | 複数の値を指定する場合は、リストはかっこでくくらなければなりません。 |
7406 | 7195 | tie した配列とハッシュに関する事項を含む詳細については |
7407 | 7196 | L<perlsub/"Temporary Values via local()"> を参照してください。 |
7408 | 7197 | |
7409 | 7198 | =begin original |
7410 | 7199 | |
7411 | 7200 | The C<delete local EXPR> construct can also be used to localize the deletion |
7412 | 7201 | of array/hash elements to the current block. |
7413 | 7202 | See L<perlsub/"Localized deletion of elements of composite types">. |
7414 | 7203 | |
7415 | 7204 | =end original |
7416 | 7205 | |
7417 | 7206 | C<delete local EXPR> 構文は、配列/ハッシュの要素の削除を現在の |
7418 | 7207 | ブロックにローカル化するためにも使われていました。 |
7419 | 7208 | L<perlsub/"Localized deletion of elements of composite types"> を |
7420 | 7209 | 参照してください。 |
7421 | 7210 | |
7422 | 7211 | =item localtime EXPR |
7423 | 7212 | X<localtime> X<ctime> |
7424 | 7213 | |
7425 | 7214 | =item localtime |
7426 | 7215 | |
7427 | 7216 | =for Pod::Functions convert UNIX time into record or string using local time |
7428 | 7217 | |
7429 | 7218 | =begin original |
7430 | 7219 | |
7431 | 7220 | Converts a time as returned by the time function to a 9-element list |
7432 | 7221 | with the time analyzed for the local time zone. Typically used as |
7433 | 7222 | follows: |
7434 | 7223 | |
7435 | 7224 | =end original |
7436 | 7225 | |
7437 | 7226 | time 関数が返す時刻を、ローカルなタイムゾーンで測った時刻として、 |
7438 | 7227 | 9 要素の配列に変換します。 |
7439 | 7228 | 普通は、以下のようにして使います: |
7440 | 7229 | |
7441 | 7230 | # 0 1 2 3 4 5 6 7 8 |
7442 | 7231 | ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = |
7443 | 7232 | localtime(time); |
7444 | 7233 | |
7445 | 7234 | =begin original |
7446 | 7235 | |
7447 | 7236 | All list elements are numeric and come straight out of the C `struct |
7448 | 7237 | tm'. C<$sec>, C<$min>, and C<$hour> are the seconds, minutes, and hours |
7449 | 7238 | of the specified time. |
7450 | 7239 | |
7451 | 7240 | =end original |
7452 | 7241 | |
7453 | 7242 | すべてのリスト要素は数値で、C の `struct tm' 構造体から |
7454 | 7243 | 直接持ってきます。 |
7455 | 7244 | C<$sec>, C<$min>, C<$hour> は指定された時刻の秒、分、時です。 |
7456 | 7245 | |
7457 | 7246 | =begin original |
7458 | 7247 | |
7459 | 7248 | C<$mday> is the day of the month and C<$mon> the month in |
7460 | 7249 | the range C<0..11>, with 0 indicating January and 11 indicating December. |
7461 | 7250 | This makes it easy to get a month name from a list: |
7462 | 7251 | |
7463 | 7252 | =end original |
7464 | 7253 | |
7465 | 7254 | C<$mday> は月の何日目か、C<$mon> は月の値です; 月の値は C<0..11> で、0 が |
7466 | 7255 | 1 月、11 が 12 月です。 |
7467 | 7256 | これにより、リストから月の名前を得るのが簡単になります: |
7468 | 7257 | |
7469 | my @abbr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); | |
7258 | my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); | |
7470 | 7259 | print "$abbr[$mon] $mday"; |
7471 | 7260 | # $mon=9, $mday=18 gives "Oct 18" |
7472 | 7261 | |
7473 | 7262 | =begin original |
7474 | 7263 | |
7475 | 7264 | C<$year> contains the number of years since 1900. To get a 4-digit |
7476 | 7265 | year write: |
7477 | 7266 | |
7478 | 7267 | =end original |
7479 | 7268 | |
7480 | 7269 | C<$year> は 1900 年からの年数を持ちます。 |
7481 | 7270 | 4 桁の年を得るには以下のようにします: |
7482 | 7271 | |
7483 | 7272 | $year += 1900; |
7484 | 7273 | |
7485 | 7274 | =begin original |
7486 | 7275 | |
7487 | 7276 | To get the last two digits of the year (e.g., "01" in 2001) do: |
7488 | 7277 | |
7489 | 7278 | =end original |
7490 | 7279 | |
7491 | 7280 | 西暦の下 2 桁(2001 年では "01")がほしい場合は以下のようにします: |
7492 | 7281 | |
7493 | 7282 | $year = sprintf("%02d", $year % 100); |
7494 | 7283 | |
7495 | 7284 | =begin original |
7496 | 7285 | |
7497 | 7286 | C<$wday> is the day of the week, with 0 indicating Sunday and 3 indicating |
7498 | 7287 | Wednesday. C<$yday> is the day of the year, in the range C<0..364> |
7499 | 7288 | (or C<0..365> in leap years.) |
7500 | 7289 | |
7501 | 7290 | =end original |
7502 | 7291 | |
7503 | 7292 | C<$wday> は曜日で、0 が日曜日、3 が水曜日です。 |
7504 | 7293 | C<$yday> はその年の何日目かで、C<0..364> の値を取ります |
7505 | 7294 | (うるう年は C<0..365> です。) |
7506 | 7295 | |
7507 | 7296 | =begin original |
7508 | 7297 | |
7509 | 7298 | C<$isdst> is true if the specified time occurs during Daylight Saving |
7510 | 7299 | Time, false otherwise. |
7511 | 7300 | |
7512 | 7301 | =end original |
7513 | 7302 | |
7514 | 7303 | C<$isdst> は指定された時刻が夏時間の場合は真、そうでなければ偽です。 |
7515 | 7304 | |
7516 | 7305 | =begin original |
7517 | 7306 | |
7518 | 7307 | If EXPR is omitted, C<localtime()> uses the current time (as returned |
7519 | 7308 | by time(3)). |
7520 | 7309 | |
7521 | 7310 | =end original |
7522 | 7311 | |
7523 | 7312 | EXPR が省略されると、C<localtime()> は(time(3) によって返される) |
7524 | 7313 | 現在時刻を使います。 |
7525 | 7314 | |
7526 | 7315 | =begin original |
7527 | 7316 | |
7528 | 7317 | In scalar context, C<localtime()> returns the ctime(3) value: |
7529 | 7318 | |
7530 | 7319 | =end original |
7531 | 7320 | |
7532 | 7321 | スカラコンテキストでは、C<localtime()> は ctime(3) の値を返します: |
7533 | 7322 | |
7534 | 7323 | $now_string = localtime; # e.g., "Thu Oct 13 04:54:34 1994" |
7535 | 7324 | |
7536 | 7325 | =begin original |
7537 | 7326 | |
7538 | 7327 | The format of this scalar value is B<not> locale-dependent |
7539 | 7328 | but built into Perl. For GMT instead of local |
7540 | 7329 | time use the L</gmtime> builtin. See also the |
7541 | 7330 | C<Time::Local> module (for converting seconds, minutes, hours, and such back to |
7542 | 7331 | the integer value returned by time()), and the L<POSIX> module's strftime(3) |
7543 | 7332 | and mktime(3) functions. |
7544 | 7333 | |
7545 | 7334 | =end original |
7546 | 7335 | |
7547 | 7336 | このスカラ値の形式はロケール依存 B<ではなく>、Perl の組み込みの値です。 |
7548 | 7337 | ローカル時刻ではなく GMT がほしい場合は L</gmtime> 組み込み関数を |
7549 | 7338 | 使ってください。 |
7550 | 7339 | また、(秒、分、時などの形から、time() が返す値である |
7551 | 7340 | 1970 年 1 月 1 日の真夜中からの秒数に変換する) C<Time::Local> モジュール |
7552 | 7341 | 及び POSIX モジュールで提供される strftime(3) と mktime(3) 関数も |
7553 | 7342 | 参照してください。 |
7554 | 7343 | |
7555 | 7344 | =begin original |
7556 | 7345 | |
7557 | 7346 | To get somewhat similar but locale-dependent date strings, set up your |
7558 | 7347 | locale environment variables appropriately (please see L<perllocale>) and |
7559 | 7348 | try for example: |
7560 | 7349 | |
7561 | 7350 | =end original |
7562 | 7351 | |
7563 | 7352 | 似たような、しかしロケール依存の日付文字列がほしい場合は、 |
7564 | 7353 | ロケール環境変数を適切に設定して(L<perllocale> を参照してください)、 |
7565 | 7354 | 以下の例を試してください: |
7566 | 7355 | |
7567 | 7356 | use POSIX qw(strftime); |
7568 | 7357 | $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime; |
7569 | 7358 | # or for GMT formatted appropriately for your locale: |
7570 | 7359 | $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime; |
7571 | 7360 | |
7572 | 7361 | =begin original |
7573 | 7362 | |
7574 | 7363 | Note that the C<%a> and C<%b>, the short forms of the day of the week |
7575 | 7364 | and the month of the year, may not necessarily be three characters wide. |
7576 | 7365 | |
7577 | 7366 | =end original |
7578 | 7367 | |
7579 | 7368 | 曜日と月の短い表現である C<%a> と C<%b> は、3 文字とは限らないことに |
7580 | 7369 | 注意してください。 |
7581 | 7370 | |
7582 | 7371 | =begin original |
7583 | 7372 | |
7584 | 7373 | The L<Time::gmtime> and L<Time::localtime> modules provide a convenient, |
7585 | 7374 | by-name access mechanism to the gmtime() and localtime() functions, |
7586 | 7375 | respectively. |
7587 | 7376 | |
7588 | 7377 | =end original |
7589 | 7378 | |
7590 | 7379 | L<Time::gmtime> モジュールと L<Time::localtime> モジュールは、それぞれ |
7591 | 7380 | gmtime() 関数と localtime() 関数に、名前でアクセスする機構を提供する |
7592 | 7381 | 便利なモジュールです。 |
7593 | 7382 | |
7594 | 7383 | =begin original |
7595 | 7384 | |
7596 | 7385 | For a comprehensive date and time representation look at the |
7597 | 7386 | L<DateTime> module on CPAN. |
7598 | 7387 | |
7599 | 7388 | =end original |
7600 | 7389 | |
7601 | 7390 | 包括的な日付と時刻の表現については、CPAN の L<DateTime> モジュールを |
7602 | 7391 | 参照してください。 |
7603 | 7392 | |
7604 | 7393 | =begin original |
7605 | 7394 | |
7606 | 7395 | Portability issues: L<perlport/localtime>. |
7607 | 7396 | |
7608 | 7397 | =end original |
7609 | 7398 | |
7610 | 7399 | 移植性の問題: L<perlport/localtime>。 |
7611 | 7400 | |
7612 | 7401 | =item lock THING |
7613 | 7402 | X<lock> |
7614 | 7403 | |
7615 | 7404 | =for Pod::Functions +5.005 get a thread lock on a variable, subroutine, or method |
7616 | 7405 | |
7617 | 7406 | =begin original |
7618 | 7407 | |
7619 | 7408 | This function places an advisory lock on a shared variable or referenced |
7620 | 7409 | object contained in I<THING> until the lock goes out of scope. |
7621 | 7410 | |
7622 | 7411 | =end original |
7623 | 7412 | |
7624 | 7413 | この関数は I<THING> が含む共有変数またはリファレンスされたオブジェクトに、 |
7625 | 7414 | スコープから出るまでアドバイサリロックを掛けます. |
7626 | 7415 | |
7627 | 7416 | =begin original |
7628 | 7417 | |
7629 | 7418 | The value returned is the scalar itself, if the argument is a scalar, or a |
7630 | 7419 | reference, if the argument is a hash, array or subroutine. |
7631 | 7420 | |
7632 | 7421 | =end original |
7633 | 7422 | |
7634 | 7423 | 返される値は、引数がスカラならそのスカラ自身、引数がハッシュ、配列、 |
7635 | 7424 | サブルーチンならリファレンスです。 |
7636 | 7425 | |
7637 | 7426 | =begin original |
7638 | 7427 | |
7639 | 7428 | lock() is a "weak keyword" : this means that if you've defined a function |
7640 | 7429 | by this name (before any calls to it), that function will be called |
7641 | 7430 | instead. If you are not under C<use threads::shared> this does nothing. |
7642 | 7431 | See L<threads::shared>. |
7643 | 7432 | |
7644 | 7433 | =end original |
7645 | 7434 | |
7646 | 7435 | lock() は「弱いキーワード」です: もしユーザーが(呼び出し前に) |
7647 | 7436 | この名前で関数を定義すると、定義された関数の方が呼び出されます。 |
7648 | 7437 | C<use threads::shared> の影響下でない場合は、これは何もしません。 |
7649 | 7438 | L<threads::shared> を参照してください。 |
7650 | 7439 | |
7651 | 7440 | =item log EXPR |
7652 | 7441 | X<log> X<logarithm> X<e> X<ln> X<base> |
7653 | 7442 | |
7654 | 7443 | =item log |
7655 | 7444 | |
7656 | 7445 | =for Pod::Functions retrieve the natural logarithm for a number |
7657 | 7446 | |
7658 | 7447 | =begin original |
7659 | 7448 | |
7660 | 7449 | Returns the natural logarithm (base I<e>) of EXPR. If EXPR is omitted, |
7661 | 7450 | returns the log of C<$_>. To get the |
7662 | 7451 | log of another base, use basic algebra: |
7663 | 7452 | The base-N log of a number is equal to the natural log of that number |
7664 | 7453 | divided by the natural log of N. For example: |
7665 | 7454 | |
7666 | 7455 | =end original |
7667 | 7456 | |
7668 | 7457 | EXPR の (I<e> を底とする) 自然対数を返します。 |
7669 | 7458 | EXPR が省略されると、C<$_> の対数を返します。 |
7670 | 7459 | 底の異なる対数を求めるためには、基礎代数を利用してください: |
7671 | 7460 | ある数の N を底とする対数は、その数の自然対数を N の自然対数で割ったものです。 |
7672 | 7461 | 例えば: |
7673 | 7462 | |
7674 | 7463 | sub log10 { |
7675 | 7464 | my $n = shift; |
7676 | 7465 | return log($n)/log(10); |
7677 | 7466 | } |
7678 | 7467 | |
7679 | 7468 | =begin original |
7680 | 7469 | |
7681 | 7470 | See also L</exp> for the inverse operation. |
7682 | 7471 | |
7683 | 7472 | =end original |
7684 | 7473 | |
7685 | 7474 | 逆操作については L</exp> を参照してください。 |
7686 | 7475 | |
7687 | 7476 | =item lstat FILEHANDLE |
7688 | 7477 | X<lstat> |
7689 | 7478 | |
7690 | 7479 | =item lstat EXPR |
7691 | 7480 | |
7692 | 7481 | =item lstat DIRHANDLE |
7693 | 7482 | |
7694 | 7483 | =item lstat |
7695 | 7484 | |
7696 | 7485 | =for Pod::Functions stat a symbolic link |
7697 | 7486 | |
7698 | 7487 | =begin original |
7699 | 7488 | |
7700 | 7489 | Does the same thing as the C<stat> function (including setting the |
7701 | 7490 | special C<_> filehandle) but stats a symbolic link instead of the file |
7702 | 7491 | the symbolic link points to. If symbolic links are unimplemented on |
7703 | 7492 | your system, a normal C<stat> is done. For much more detailed |
7704 | 7493 | information, please see the documentation for C<stat>. |
7705 | 7494 | |
7706 | 7495 | =end original |
7707 | 7496 | |
7708 | 7497 | (特別なファイルハンドルである C<_> の設定を含めて) |
7709 | 7498 | C<stat> 関数と同じことをしますが、シンボリックリンクが |
7710 | 7499 | 指しているファイルではなく、シンボリックリンク自体の stat をとります。 |
7711 | シンボリックリンクがシステムに実装されていないと、通常の C<stat> が | |
7500 | シンボリックリンクがシステムに実装されていないと、通常の C<stat> が行なわれます。 | |
7712 | 行なわれます。 | |
7713 | 7501 | さらにより詳細な情報については、L<stat> の文書を参照してください。 |
7714 | 7502 | |
7715 | 7503 | =begin original |
7716 | 7504 | |
7717 | 7505 | If EXPR is omitted, stats C<$_>. |
7718 | 7506 | |
7719 | 7507 | =end original |
7720 | 7508 | |
7721 | 7509 | EXPR が省略されると、C<$_> の stat をとります。 |
7722 | 7510 | |
7723 | 7511 | =begin original |
7724 | 7512 | |
7725 | 7513 | Portability issues: L<perlport/lstat>. |
7726 | 7514 | |
7727 | 7515 | =end original |
7728 | 7516 | |
7729 | 7517 | 移植性の問題: L<perlport/lstat>。 |
7730 | 7518 | |
7731 | 7519 | =item m// |
7732 | 7520 | |
7733 | 7521 | =for Pod::Functions match a string with a regular expression pattern |
7734 | 7522 | |
7735 | 7523 | =begin original |
7736 | 7524 | |
7737 | 7525 | The match operator. See L<perlop/"Regexp Quote-Like Operators">. |
7738 | 7526 | |
7739 | 7527 | =end original |
7740 | 7528 | |
7741 | 7529 | マッチ演算子です。 |
7742 | 7530 | L<perlop/"Regexp Quote-Like Operators"> を参照してください。 |
7743 | 7531 | |
7744 | 7532 | =item map BLOCK LIST |
7745 | 7533 | X<map> |
7746 | 7534 | |
7747 | 7535 | =item map EXPR,LIST |
7748 | 7536 | |
7749 | 7537 | =for Pod::Functions apply a change to a list to get back a new list with the changes |
7750 | 7538 | |
7751 | 7539 | =begin original |
7752 | 7540 | |
7753 | 7541 | Evaluates the BLOCK or EXPR for each element of LIST (locally setting |
7754 | 7542 | C<$_> to each element) and returns the list value composed of the |
7755 | 7543 | results of each such evaluation. In scalar context, returns the |
7756 | 7544 | total number of elements so generated. Evaluates BLOCK or EXPR in |
7757 | 7545 | list context, so each element of LIST may produce zero, one, or |
7758 | 7546 | more elements in the returned value. |
7759 | 7547 | |
7760 | 7548 | =end original |
7761 | 7549 | |
7762 | 7550 | LIST の個々の要素に対して、BLOCK か EXPR を評価し |
7763 | 7551 | (C<$_> は、ローカルに個々の要素が設定されます) 、 |
7764 | 7552 | それぞれの評価結果からなるリスト値が返されます。 |
7765 | 7553 | スカラコンテキストでは、生成された要素の数を返します。 |
7766 | 7554 | BLOCK や EXPR をリストコンテキストで評価しますので、LIST の |
7767 | 7555 | 個々の要素によって作られる、返り値であるリストの要素数は、 |
7768 | 7556 | 0 個の場合もあれば、複数の場合もあります。 |
7769 | 7557 | |
7770 | 7558 | @chars = map(chr, @numbers); |
7771 | 7559 | |
7772 | 7560 | =begin original |
7773 | 7561 | |
7774 | 7562 | translates a list of numbers to the corresponding characters. |
7775 | 7563 | |
7776 | 7564 | =end original |
7777 | 7565 | |
7778 | 7566 | は、数のリストを対応する文字に変換します。 |
7779 | 7567 | |
7780 | 7568 | my @squares = map { $_ * $_ } @numbers; |
7781 | 7569 | |
7782 | 7570 | =begin original |
7783 | 7571 | |
7784 | 7572 | translates a list of numbers to their squared values. |
7785 | 7573 | |
7786 | 7574 | =end original |
7787 | 7575 | |
7788 | 7576 | これは数値のリストを、その 2 乗に変換します。 |
7789 | 7577 | |
7790 | 7578 | my @squares = map { $_ > 5 ? ($_ * $_) : () } @numbers; |
7791 | 7579 | |
7792 | 7580 | =begin original |
7793 | 7581 | |
7794 | 7582 | shows that number of returned elements can differ from the number of |
7795 | 7583 | input elements. To omit an element, return an empty list (). |
7796 | 7584 | This could also be achieved by writing |
7797 | 7585 | |
7798 | 7586 | =end original |
7799 | 7587 | |
7800 | 7588 | のように、返された要素の数が入力要素の数と異なる場合もあります。 |
7801 | 7589 | 要素を省略するには、空リスト () を返します。 |
7802 | 7590 | これは以下のように書くことでも達成できて |
7803 | 7591 | |
7804 | 7592 | my @squares = map { $_ * $_ } grep { $_ > 5 } @numbers; |
7805 | 7593 | |
7806 | 7594 | =begin original |
7807 | 7595 | |
7808 | 7596 | which makes the intention more clear. |
7809 | 7597 | |
7810 | 7598 | =end original |
7811 | 7599 | |
7812 | 7600 | この方が目的がよりはっきりします。 |
7813 | 7601 | |
7814 | 7602 | =begin original |
7815 | 7603 | |
7816 | 7604 | Map always returns a list, which can be |
7817 | 7605 | assigned to a hash such that the elements |
7818 | 7606 | become key/value pairs. See L<perldata> for more details. |
7819 | 7607 | |
7820 | 7608 | =end original |
7821 | 7609 | |
7822 | 7610 | map は常にリストを返し、要素がキー/値の組になるようなハッシュに |
7823 | 7611 | 代入できます。 |
7824 | 7612 | さらなる詳細については L<perldata> を参照してください。 |
7825 | 7613 | |
7826 | 7614 | %hash = map { get_a_key_for($_) => $_ } @array; |
7827 | 7615 | |
7828 | 7616 | =begin original |
7829 | 7617 | |
7830 | 7618 | is just a funny way to write |
7831 | 7619 | |
7832 | 7620 | =end original |
7833 | 7621 | |
7834 | 7622 | は以下のものをちょっと変わった書き方で書いたものです。 |
7835 | 7623 | |
7836 | 7624 | %hash = (); |
7837 | 7625 | foreach (@array) { |
7838 | 7626 | $hash{get_a_key_for($_)} = $_; |
7839 | 7627 | } |
7840 | 7628 | |
7841 | 7629 | =begin original |
7842 | 7630 | |
7843 | 7631 | Note that C<$_> is an alias to the list value, so it can be used to |
7844 | 7632 | modify the elements of the LIST. While this is useful and supported, |
7845 | 7633 | it can cause bizarre results if the elements of LIST are not variables. |
7846 | 7634 | Using a regular C<foreach> loop for this purpose would be clearer in |
7847 | 7635 | most cases. See also L</grep> for an array composed of those items of |
7848 | 7636 | the original list for which the BLOCK or EXPR evaluates to true. |
7849 | 7637 | |
7850 | 7638 | =end original |
7851 | 7639 | |
7852 | 7640 | C<$_> は、LIST の値へのエイリアスですので、LIST の要素を |
7853 | 7641 | 変更するために使うことができます。 |
7854 | 7642 | これは、便利でサポートされていますが、 |
7855 | 7643 | LIST の要素が変数でないと、おかしな結果になります。 |
7856 | 7644 | この目的には通常の C<foreach> ループを使うことで、ほとんどの場合は |
7857 | 7645 | より明確になります。 |
7858 | 7646 | BLOCK や EXPR が真になる元のリストの要素からなる配列については、 |
7859 | 7647 | L</grep> も参照してください。 |
7860 | 7648 | |
7861 | 7649 | =begin original |
7862 | 7650 | |
7863 | 7651 | If C<$_> is lexical in the scope where the C<map> appears (because it has |
7864 | been declared with | |
7652 | been declared with C<my $_>), then, in addition to being locally aliased to | |
7865 | then, in addition to being locally aliased to | |
7866 | 7653 | the list elements, C<$_> keeps being lexical inside the block; that is, it |
7867 | 7654 | can't be seen from the outside, avoiding any potential side-effects. |
7868 | 7655 | |
7869 | 7656 | =end original |
7870 | 7657 | |
7871 | ( | |
7658 | (C<my $_> として宣言されることによって) C<$_> が C<map> が現れるスコープ内で | |
7872 | ||
7659 | レキシカルな場合は、ローカルではリスト要素へのエイリアスであることに加えて、 | |
7873 | ||
7660 | C<$_> はブロック内でレキシカルでありつづけます; つまり、外側からは見えず、 | |
7874 | ||
7661 | 起こりうる副作用を回避します。 | |
7875 | 7662 | |
7876 | 7663 | =begin original |
7877 | 7664 | |
7878 | 7665 | C<{> starts both hash references and blocks, so C<map { ...> could be either |
7879 | 7666 | the start of map BLOCK LIST or map EXPR, LIST. Because Perl doesn't look |
7880 | 7667 | ahead for the closing C<}> it has to take a guess at which it's dealing with |
7881 | 7668 | based on what it finds just after the |
7882 | 7669 | C<{>. Usually it gets it right, but if it |
7883 | 7670 | doesn't it won't realize something is wrong until it gets to the C<}> and |
7884 | 7671 | encounters the missing (or unexpected) comma. The syntax error will be |
7885 | 7672 | reported close to the C<}>, but you'll need to change something near the C<{> |
7886 | 7673 | such as using a unary C<+> to give Perl some help: |
7887 | 7674 | |
7888 | 7675 | =end original |
7889 | 7676 | |
7890 | 7677 | C<{> はハッシュリファレンスとブロックの両方の開始文字なので、 |
7891 | 7678 | C<map { ...> は map BLOCK LIST の場合と map EXPR, LIST の場合があります。 |
7892 | 7679 | Perl は終了文字の C<}> を先読みしないので、C<{> の直後の文字を見て |
7893 | 7680 | どちらとして扱うかを推測します。 |
7894 | 7681 | 通常この推測は正しいですが、もし間違った場合は、C<}> まで読み込んで |
7895 | 7682 | カンマが足りない(または多い)ことがわかるまで、何かがおかしいことに |
7896 | 7683 | 気付きません。 |
7897 | 7684 | C<}> の近くで文法エラーが出ますが、Perl を助けるために単項の C<+> を |
7898 | 7685 | 使うというように、C<{> の近くの何かを変更する必要があります。 |
7899 | 7686 | |
7900 | %hash = map { "\L$_" => 1 } @array # perl guesses EXPR. wrong | |
7687 | %hash = map { "\L$_" => 1 } @array # perl guesses EXPR. wrong | |
7901 | %hash = map { +"\L$_" => 1 } @array # perl guesses BLOCK. right | |
7688 | %hash = map { +"\L$_" => 1 } @array # perl guesses BLOCK. right | |
7902 | %hash = map { ("\L$_" => 1) } @array # this also works | |
7689 | %hash = map { ("\L$_" => 1) } @array # this also works | |
7903 | %hash = map { lc($_) => 1 } @array # as does this. | |
7690 | %hash = map { lc($_) => 1 } @array # as does this. | |
7904 | %hash = map +( lc($_) => 1 ), @array # this is EXPR and works! | |
7691 | %hash = map +( lc($_) => 1 ), @array # this is EXPR and works! | |
7905 | 7692 | |
7906 | %hash = map ( lc($_), 1 ), @array # evaluates to (1, @array) | |
7693 | %hash = map ( lc($_), 1 ), @array # evaluates to (1, @array) | |
7907 | 7694 | |
7908 | 7695 | =begin original |
7909 | 7696 | |
7910 | 7697 | or to force an anon hash constructor use C<+{>: |
7911 | 7698 | |
7912 | 7699 | =end original |
7913 | 7700 | |
7914 | 7701 | または C<+{> を使って無名ハッシュコンストラクタを強制します: |
7915 | 7702 | |
7916 | | |
7703 | @hashes = map +{ lc($_) => 1 }, @array # EXPR, so needs comma at end | |
7917 | # comma at end | |
7918 | 7704 | |
7919 | 7705 | =begin original |
7920 | 7706 | |
7921 | 7707 | to get a list of anonymous hashes each with only one entry apiece. |
7922 | 7708 | |
7923 | 7709 | =end original |
7924 | 7710 | |
7925 | 7711 | こうするとそれぞれ 1 要素だけの無名ハッシュのリストを得られます。 |
7926 | 7712 | |
7927 | 7713 | =item mkdir FILENAME,MASK |
7928 | 7714 | X<mkdir> X<md> X<directory, create> |
7929 | 7715 | |
7930 | 7716 | =item mkdir FILENAME |
7931 | 7717 | |
7932 | 7718 | =item mkdir |
7933 | 7719 | |
7934 | 7720 | =for Pod::Functions create a directory |
7935 | 7721 | |
7936 | 7722 | =begin original |
7937 | 7723 | |
7938 | 7724 | Creates the directory specified by FILENAME, with permissions |
7939 | 7725 | specified by MASK (as modified by C<umask>). If it succeeds it |
7940 | 7726 | returns true; otherwise it returns false and sets C<$!> (errno). |
7941 | 7727 | MASK defaults to 0777 if omitted, and FILENAME defaults |
7942 | 7728 | to C<$_> if omitted. |
7943 | 7729 | |
7944 | 7730 | =end original |
7945 | 7731 | |
7946 | 7732 | FILENAME で指定したディレクトリを、MASK で指定した許可モード(を |
7947 | 7733 | C<umask> で修正したもの) で作成します。 |
7948 | 7734 | 成功時には真を返します; さもなければ偽を返して C<$!> (errno) を設定します。 |
7949 | 7735 | MASK を省略すると、0777 とみなし、 |
7950 | 7736 | FILENAME を省略すると、C<$_> を使います。 |
7951 | 7737 | |
7952 | 7738 | =begin original |
7953 | 7739 | |
7954 | 7740 | In general, it is better to create directories with a permissive MASK |
7955 | 7741 | and let the user modify that with their C<umask> than it is to supply |
7956 | 7742 | a restrictive MASK and give the user no way to be more permissive. |
7957 | 7743 | The exceptions to this rule are when the file or directory should be |
7958 | 7744 | kept private (mail files, for instance). The perlfunc(1) entry on |
7959 | 7745 | C<umask> discusses the choice of MASK in more detail. |
7960 | 7746 | |
7961 | 7747 | =end original |
7962 | 7748 | |
7963 | 7749 | 一般的に、制限された MASK を使ってユーザーがより寛容にする方法を |
7964 | 7750 | 与えないより、寛容な MASK でディレクトリを作り、ユーザーが自身の C<umask> で |
7965 | 7751 | 修正するようにした方がよいです。 |
7966 | 7752 | 例外は、(例えばメールファイルのような)プライベートに保つべきファイルや |
7967 | 7753 | ディレクトリを書く場合です。 |
7968 | 7754 | perlfunc(1) の C<umask> で、MASK の選択に関して詳細に議論しています。 |
7969 | 7755 | |
7970 | 7756 | =begin original |
7971 | 7757 | |
7972 | 7758 | Note that according to the POSIX 1003.1-1996 the FILENAME may have any |
7973 | 7759 | number of trailing slashes. Some operating and filesystems do not get |
7974 | 7760 | this right, so Perl automatically removes all trailing slashes to keep |
7975 | 7761 | everyone happy. |
7976 | 7762 | |
7977 | 7763 | =end original |
7978 | 7764 | |
7979 | 7765 | POSIX 1003.1-1996 によれば、FILENAME には末尾に任意の数のスラッシュを |
7980 | 7766 | つけることができます。 |
7981 | 7767 | このようには動かない OS やファイルシステムもあるので、Perl はみんなが |
7982 | 7768 | 幸せになれるように、自動的に末尾のスラッシュを削除します。 |
7983 | 7769 | |
7984 | 7770 | =begin original |
7985 | 7771 | |
7986 | 7772 | To recursively create a directory structure, look at |
7987 | the C<m | |
7773 | the C<mkpath> function of the L<File::Path> module. | |
7988 | 7774 | |
7989 | 7775 | =end original |
7990 | 7776 | |
7991 | 7777 | ディレクトリ構造を再帰的に作成するには、L<File::Path> モジュールの |
7992 | C<make | |
7778 | C<makepath> 関数を参照してください。 | |
7993 | 7779 | |
7994 | 7780 | =item msgctl ID,CMD,ARG |
7995 | 7781 | X<msgctl> |
7996 | 7782 | |
7997 | 7783 | =for Pod::Functions SysV IPC message control operations |
7998 | 7784 | |
7999 | 7785 | =begin original |
8000 | 7786 | |
8001 | 7787 | Calls the System V IPC function msgctl(2). You'll probably have to say |
8002 | 7788 | |
8003 | 7789 | =end original |
8004 | 7790 | |
8005 | 7791 | System V IPC 関数 msgctl を呼び出します。 |
8006 | 7792 | 正しい定数定義を得るために、まず |
8007 | 7793 | |
8008 | 7794 | use IPC::SysV; |
8009 | 7795 | |
8010 | 7796 | =begin original |
8011 | 7797 | |
8012 | 7798 | first to get the correct constant definitions. If CMD is C<IPC_STAT>, |
8013 | 7799 | then ARG must be a variable that will hold the returned C<msqid_ds> |
8014 | 7800 | structure. Returns like C<ioctl>: the undefined value for error, |
8015 | 7801 | C<"0 but true"> for zero, or the actual return value otherwise. See also |
8016 | 7802 | L<perlipc/"SysV IPC"> and the documentation for C<IPC::SysV> and |
8017 | 7803 | C<IPC::Semaphore>. |
8018 | 7804 | |
8019 | 7805 | =end original |
8020 | 7806 | |
8021 | 7807 | と書くことが必要でしょう。 |
8022 | 7808 | CMD が C<IPC_STAT> であれば、ARG は返される C<msqid_ds> 構造体を |
8023 | 7809 | 納める変数でなければなりません。 |
8024 | 7810 | C<ioctl> と同じように、エラー時には未定義値、 |
8025 | 7811 | ゼロのときは C<"0 but true">、それ以外なら、その値そのものを返します。 |
8026 | 7812 | L<perlipc/"SysV IPC"> および、C<IPC::SysV>, C<IPC::Semaphore> の文書も |
8027 | 7813 | 参照してください。 |
8028 | 7814 | |
8029 | 7815 | =begin original |
8030 | 7816 | |
8031 | 7817 | Portability issues: L<perlport/msgctl>. |
8032 | 7818 | |
8033 | 7819 | =end original |
8034 | 7820 | |
8035 | 7821 | 移植性の問題: L<perlport/msgctl>。 |
8036 | 7822 | |
8037 | 7823 | =item msgget KEY,FLAGS |
8038 | 7824 | X<msgget> |
8039 | 7825 | |
8040 | 7826 | =for Pod::Functions get SysV IPC message queue |
8041 | 7827 | |
8042 | 7828 | =begin original |
8043 | 7829 | |
8044 | 7830 | Calls the System V IPC function msgget(2). Returns the message queue |
8045 | 7831 | id, or C<undef> on error. See also |
8046 | 7832 | L<perlipc/"SysV IPC"> and the documentation for C<IPC::SysV> and |
8047 | 7833 | C<IPC::Msg>. |
8048 | 7834 | |
8049 | 7835 | =end original |
8050 | 7836 | |
8051 | 7837 | System V IPC 関数 msgget を呼び出します。 |
8052 | 7838 | メッセージキューの ID か、エラー時には C<undef> を返します。 |
8053 | 7839 | L<perlipc/"SysV IPC"> よよび、C<IPC::SysV>, C<IPC::Msg> の文書も |
8054 | 7840 | 参照してください。 |
8055 | 7841 | |
8056 | 7842 | =begin original |
8057 | 7843 | |
8058 | 7844 | Portability issues: L<perlport/msgget>. |
8059 | 7845 | |
8060 | 7846 | =end original |
8061 | 7847 | |
8062 | 7848 | 移植性の問題: L<perlport/msgget>。 |
8063 | 7849 | |
8064 | 7850 | =item msgrcv ID,VAR,SIZE,TYPE,FLAGS |
8065 | 7851 | X<msgrcv> |
8066 | 7852 | |
8067 | 7853 | =for Pod::Functions receive a SysV IPC message from a message queue |
8068 | 7854 | |
8069 | 7855 | =begin original |
8070 | 7856 | |
8071 | 7857 | Calls the System V IPC function msgrcv to receive a message from |
8072 | 7858 | message queue ID into variable VAR with a maximum message size of |
8073 | 7859 | SIZE. Note that when a message is received, the message type as a |
8074 | 7860 | native long integer will be the first thing in VAR, followed by the |
8075 | 7861 | actual message. This packing may be opened with C<unpack("l! a*")>. |
8076 | 7862 | Taints the variable. Returns true if successful, false |
8077 | 7863 | on error. See also L<perlipc/"SysV IPC"> and the documentation for |
8078 | 7864 | C<IPC::SysV> and C<IPC::SysV::Msg>. |
8079 | 7865 | |
8080 | 7866 | =end original |
8081 | 7867 | |
8082 | 7868 | System V IPC 関数 msgrcv を呼び出し、メッセージキュー ID から、 |
8083 | 7869 | 変数 VAR に最大メッセージ長 SIZE のメッセージを受信します。 |
8084 | 7870 | メッセージが受信された時、ネイティブな long 整数のメッセージタイプが |
8085 | 7871 | VAR の先頭となり、実際のメッセージが続きます。 |
8086 | 7872 | このパッキングは C<unpack("l! a*")> で展開できます。 |
8087 | 7873 | 変数は汚染されます。 |
8088 | 7874 | 成功時には真を、エラー時には偽を返します。 |
8089 | 7875 | L<perlipc/"SysV IPC"> および、C<IPC::SysV>, C<IPC::SysV::Msg> の文書も |
8090 | 7876 | 参照してください。 |
8091 | 7877 | |
8092 | 7878 | =begin original |
8093 | 7879 | |
8094 | 7880 | Portability issues: L<perlport/msgrcv>. |
8095 | 7881 | |
8096 | 7882 | =end original |
8097 | 7883 | |
8098 | 7884 | 移植性の問題: L<perlport/msgrcv>。 |
8099 | 7885 | |
8100 | 7886 | =item msgsnd ID,MSG,FLAGS |
8101 | 7887 | X<msgsnd> |
8102 | 7888 | |
8103 | 7889 | =for Pod::Functions send a SysV IPC message to a message queue |
8104 | 7890 | |
8105 | 7891 | =begin original |
8106 | 7892 | |
8107 | 7893 | Calls the System V IPC function msgsnd to send the message MSG to the |
8108 | 7894 | message queue ID. MSG must begin with the native long integer message |
8109 | 7895 | type, be followed by the length of the actual message, and then finally |
8110 | 7896 | the message itself. This kind of packing can be achieved with |
8111 | 7897 | C<pack("l! a*", $type, $message)>. Returns true if successful, |
8112 | 7898 | false on error. See also the C<IPC::SysV> |
8113 | 7899 | and C<IPC::SysV::Msg> documentation. |
8114 | 7900 | |
8115 | 7901 | =end original |
8116 | 7902 | |
8117 | 7903 | System V IPC 関数 msgsnd を呼び出し、メッセージキュー ID に |
8118 | 7904 | メッセージ MSG を送信します。 |
8119 | MSG の先頭は、ネイティブな | |
7905 | MSG の先頭は、ネイティブなlong 整数のメッセージタイプでなければならず、 | |
8120 | 7906 | メッセージの長さ、メッセージ本体と続きます。 |
8121 | 7907 | これは、C<pack("l! a*", $type, $message)> として生成できます。 |
8122 | 7908 | 成功時には真を、エラー時には偽を返します。 |
8123 | 7909 | C<IPC::SysV> と C<IPC::SysV::Msg> の文書も参照してください。 |
8124 | 7910 | |
8125 | 7911 | =begin original |
8126 | 7912 | |
8127 | 7913 | Portability issues: L<perlport/msgsnd>. |
8128 | 7914 | |
8129 | 7915 | =end original |
8130 | 7916 | |
8131 | 7917 | 移植性の問題: L<perlport/msgsnd>。 |
8132 | 7918 | |
8133 | =item my | |
7919 | =item my EXPR | |
8134 | 7920 | X<my> |
8135 | 7921 | |
8136 | =item my TYPE | |
7922 | =item my TYPE EXPR | |
8137 | 7923 | |
8138 | =item my | |
7924 | =item my EXPR : ATTRS | |
8139 | 7925 | |
8140 | =item my TYPE | |
7926 | =item my TYPE EXPR : ATTRS | |
8141 | 7927 | |
8142 | 7928 | =for Pod::Functions declare and assign a local variable (lexical scoping) |
8143 | 7929 | |
8144 | 7930 | =begin original |
8145 | 7931 | |
8146 | 7932 | A C<my> declares the listed variables to be local (lexically) to the |
8147 | enclosing block, file, or C<eval>. If more than one va | |
7933 | enclosing block, file, or C<eval>. If more than one value is listed, | |
8148 | 7934 | the list must be placed in parentheses. |
8149 | 7935 | |
8150 | 7936 | =end original |
8151 | 7937 | |
8152 | 7938 | C<my> はリストアップされた変数を、囲っているブロック、ファイル、 |
8153 | 7939 | C<eval> の中でローカルな (レキシカルな) ものにします。 |
8154 | 複数の | |
7940 | 複数の値を指定する場合は、リストはかっこでくくらなければなりません。 | |
8155 | 7941 | |
8156 | 7942 | =begin original |
8157 | 7943 | |
8158 | 7944 | The exact semantics and interface of TYPE and ATTRS are still |
8159 | evolving. TYPE | |
7945 | evolving. TYPE is currently bound to the use of the C<fields> pragma, | |
8160 | with C<use constant>, or C<__PACKAGE__>. It is | |
8161 | currently bound to the use of the C<fields> pragma, | |
8162 | 7946 | and attributes are handled using the C<attributes> pragma, or starting |
8163 | 7947 | from Perl 5.8.0 also via the C<Attribute::Handlers> module. See |
8164 | 7948 | L<perlsub/"Private Variables via my()"> for details, and L<fields>, |
8165 | 7949 | L<attributes>, and L<Attribute::Handlers>. |
8166 | 7950 | |
8167 | 7951 | =end original |
8168 | 7952 | |
8169 | 7953 | TYPE と ATTRS の正確な文法とインターフェースは今でも進化しています。 |
8170 | TYPE は、裸の単語、C<use constant> で宣言された定数、C<__PACKAGE__> の | |
8171 | いずれかです。 | |
8172 | 7954 | 現在のところ、TYPE は C<fields> プラグマの使用と結び付けられていて、 |
8173 | 7955 | 属性は C<attributes> プラグマか、Perl 5.8.0 からは |
8174 | 7956 | C<Attribute::Handlers> モジュールと結び付けられています。 |
8175 | 詳しくは | |
7957 | 詳しくはL<perlsub/"Private Variables via my()">, L<fields>, | |
8176 | 7958 | L<attributes>, L<Attribute::Handlers> を参照してください。 |
8177 | 7959 | |
8178 | =begin original | |
8179 | ||
8180 | Note that with a parenthesised list, C<undef> can be used as a dummy | |
8181 | placeholder, for example to skip assignment of initial values: | |
8182 | ||
8183 | =end original | |
8184 | ||
8185 | かっこで囲まれたリストでは、C<undef> は、例えば初期値の代入を飛ばすために、 | |
8186 | ダミーのプレースホルダとして使えることに注意してください: | |
8187 | ||
8188 | my ( undef, $min, $hour ) = localtime; | |
8189 | ||
8190 | 7960 | =item next LABEL |
8191 | 7961 | X<next> X<continue> |
8192 | 7962 | |
8193 | =item next EXPR | |
8194 | ||
8195 | 7963 | =item next |
8196 | 7964 | |
8197 | 7965 | =for Pod::Functions iterate a block prematurely |
8198 | 7966 | |
8199 | 7967 | =begin original |
8200 | 7968 | |
8201 | 7969 | The C<next> command is like the C<continue> statement in C; it starts |
8202 | 7970 | the next iteration of the loop: |
8203 | 7971 | |
8204 | 7972 | =end original |
8205 | 7973 | |
8206 | 7974 | C<next> コマンドは、C での C<continue> 文のようなもので、 |
8207 | 7975 | ループの次の繰り返しを開始します: |
8208 | 7976 | |
8209 | 7977 | LINE: while (<STDIN>) { |
8210 | 7978 | next LINE if /^#/; # discard comments |
8211 | 7979 | #... |
8212 | 7980 | } |
8213 | 7981 | |
8214 | 7982 | =begin original |
8215 | 7983 | |
8216 | 7984 | Note that if there were a C<continue> block on the above, it would get |
8217 | 7985 | executed even on discarded lines. If LABEL is omitted, the command |
8218 | refers to the innermost enclosing loop. | |
7986 | refers to the innermost enclosing loop. | |
8219 | as of Perl 5.18.0, allows a label name to be computed at run time, being | |
8220 | otherwise identical to C<next LABEL>. | |
8221 | 7987 | |
8222 | 7988 | =end original |
8223 | 7989 | |
8224 | 7990 | C<continue> ブロックが存在すれば、たとえ捨てられる行に |
8225 | 7991 | あっても、それが実行されます。 |
8226 | 7992 | LABEL が省略されると、コマンドは一番内側のループを参照します。 |
8227 | Perl 5.18.0 から利用可能な C<next EXPR> 形式では、実行時に計算される | |
8228 | ラベル名が使えます; それ以外は C<next LABEL> と同一です。 | |
8229 | 7993 | |
8230 | 7994 | =begin original |
8231 | 7995 | |
8232 | 7996 | C<next> cannot be used to exit a block which returns a value such as |
8233 | 7997 | C<eval {}>, C<sub {}>, or C<do {}>, and should not be used to exit |
8234 | 7998 | a grep() or map() operation. |
8235 | 7999 | |
8236 | 8000 | =end original |
8237 | 8001 | |
8238 | 8002 | C<next> は C<eval {}>, C<sub {}>, C<do {}> のように値を返すブロックから |
8239 | 8003 | 抜けるのには使えません; また、grep() や map() 操作から抜けるのに |
8240 | 8004 | 使うべきではありません。 |
8241 | 8005 | |
8242 | 8006 | =begin original |
8243 | 8007 | |
8244 | 8008 | Note that a block by itself is semantically identical to a loop |
8245 | 8009 | that executes once. Thus C<next> will exit such a block early. |
8246 | 8010 | |
8247 | 8011 | =end original |
8248 | 8012 | |
8249 | 8013 | ブロック自身は一回だけ実行されるループと文法的に同一であることに |
8250 | 8014 | 注意してください。 |
8251 | 8015 | 従って、C<next> はそのようなブロックから早く抜けるのに使えます。 |
8252 | 8016 | |
8253 | 8017 | =begin original |
8254 | 8018 | |
8255 | 8019 | See also L</continue> for an illustration of how C<last>, C<next>, and |
8256 | 8020 | C<redo> work. |
8257 | 8021 | |
8258 | 8022 | =end original |
8259 | 8023 | |
8260 | 8024 | C<last>, C<next>, C<redo> がどのように働くかについては |
8261 | 8025 | L</continue> も参照してください。 |
8262 | 8026 | |
8263 | =begin original | |
8264 | ||
8265 | Unlike most named operators, this has the same precedence as assignment. | |
8266 | It is also exempt from the looks-like-a-function rule, so | |
8267 | C<next ("foo")."bar"> will cause "bar" to be part of the argument to | |
8268 | C<next>. | |
8269 | ||
8270 | =end original | |
8271 | ||
8272 | ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 | |
8273 | また、関数のように見えるものの規則からも免れるので、C<next ("foo")."bar"> と | |
8274 | すると "bar" は C<next> への引数の一部となります。 | |
8275 | ||
8276 | 8027 | =item no MODULE VERSION LIST |
8277 | 8028 | X<no declarations> |
8278 | 8029 | X<unimporting> |
8279 | 8030 | |
8280 | 8031 | =item no MODULE VERSION |
8281 | 8032 | |
8282 | 8033 | =item no MODULE LIST |
8283 | 8034 | |
8284 | 8035 | =item no MODULE |
8285 | 8036 | |
8286 | 8037 | =item no VERSION |
8287 | 8038 | |
8288 | 8039 | =for Pod::Functions unimport some module symbols or semantics at compile time |
8289 | 8040 | |
8290 | 8041 | =begin original |
8291 | 8042 | |
8292 | 8043 | See the C<use> function, of which C<no> is the opposite. |
8293 | 8044 | |
8294 | 8045 | =end original |
8295 | 8046 | |
8296 | 8047 | L<use> 関数を参照してください; C<no> は、その逆を行なうものです。 |
8297 | 8048 | |
8298 | 8049 | =item oct EXPR |
8299 | 8050 | X<oct> X<octal> X<hex> X<hexadecimal> X<binary> X<bin> |
8300 | 8051 | |
8301 | 8052 | =item oct |
8302 | 8053 | |
8303 | 8054 | =for Pod::Functions convert a string to an octal number |
8304 | 8055 | |
8305 | 8056 | =begin original |
8306 | 8057 | |
8307 | 8058 | Interprets EXPR as an octal string and returns the corresponding |
8308 | 8059 | value. (If EXPR happens to start off with C<0x>, interprets it as a |
8309 | 8060 | hex string. If EXPR starts off with C<0b>, it is interpreted as a |
8310 | 8061 | binary string. Leading whitespace is ignored in all three cases.) |
8311 | 8062 | The following will handle decimal, binary, octal, and hex in standard |
8312 | 8063 | Perl notation: |
8313 | 8064 | |
8314 | 8065 | =end original |
8315 | 8066 | |
8316 | 8067 | EXPR を 8 進数文字列と解釈して、対応する値を返します。 |
8317 | 8068 | (EXPR が C<0x> で始まるときには、16 進数文字列と解釈します。 |
8318 | 8069 | EXPR が C<0b>で始まるときは、2 進数文字列と解釈します。 |
8319 | 8070 | どの場合でも、先頭の空白は無視されます。) |
8320 | 8071 | 以下の例は、標準的な Perl の記法での |
8321 | 8072 | 10 進数、2 進数、8 進数、16 進数を扱います: |
8322 | 8073 | |
8323 | 8074 | $val = oct($val) if $val =~ /^0/; |
8324 | 8075 | |
8325 | 8076 | =begin original |
8326 | 8077 | |
8327 | 8078 | If EXPR is omitted, uses C<$_>. To go the other way (produce a number |
8328 | 8079 | in octal), use sprintf() or printf(): |
8329 | 8080 | |
8330 | 8081 | =end original |
8331 | 8082 | |
8332 | 8083 | EXPR が省略されると、C<$_> を使います。 |
8333 | 8084 | (8 進数を扱う)その他の方法としては sprintf() または printf()があります。 |
8334 | 8085 | |
8335 | 8086 | $dec_perms = (stat("filename"))[2] & 07777; |
8336 | 8087 | $oct_perm_str = sprintf "%o", $perms; |
8337 | 8088 | |
8338 | 8089 | =begin original |
8339 | 8090 | |
8340 | 8091 | The oct() function is commonly used when a string such as C<644> needs |
8341 | 8092 | to be converted into a file mode, for example. Although Perl |
8342 | 8093 | automatically converts strings into numbers as needed, this automatic |
8343 | 8094 | conversion assumes base 10. |
8344 | 8095 | |
8345 | 8096 | =end original |
8346 | 8097 | |
8347 | 8098 | oct() 関数は例えば、 C<644> といった文字列をファイルモードに変換する時に |
8348 | 8099 | よく使います。 |
8349 | 8100 | Perl は必要に応じて自動的に文字列を数値に変換しますが、 |
8350 | 8101 | この自動変換は十進数を仮定します。 |
8351 | 8102 | |
8352 | 8103 | =begin original |
8353 | 8104 | |
8354 | 8105 | Leading white space is ignored without warning, as too are any trailing |
8355 | 8106 | non-digits, such as a decimal point (C<oct> only handles non-negative |
8356 | 8107 | integers, not negative integers or floating point). |
8357 | 8108 | |
8358 | 8109 | =end original |
8359 | 8110 | |
8360 | 8111 | 先頭の空白や、末尾の(小数点のような)非数字は警告なしに無視されます |
8361 | 8112 | (C<oct> は非負整数のみを扱えます; 負の整数や小数は扱えません)。 |
8362 | 8113 | |
8363 | 8114 | =item open FILEHANDLE,EXPR |
8364 | 8115 | X<open> X<pipe> X<file, open> X<fopen> |
8365 | 8116 | |
8366 | 8117 | =item open FILEHANDLE,MODE,EXPR |
8367 | 8118 | |
8368 | 8119 | =item open FILEHANDLE,MODE,EXPR,LIST |
8369 | 8120 | |
8370 | 8121 | =item open FILEHANDLE,MODE,REFERENCE |
8371 | 8122 | |
8372 | 8123 | =item open FILEHANDLE |
8373 | 8124 | |
8374 | 8125 | =for Pod::Functions open a file, pipe, or descriptor |
8375 | 8126 | |
8376 | 8127 | =begin original |
8377 | 8128 | |
8378 | 8129 | Opens the file whose filename is given by EXPR, and associates it with |
8379 | 8130 | FILEHANDLE. |
8380 | 8131 | |
8381 | 8132 | =end original |
8382 | 8133 | |
8383 | 8134 | EXPR で与えられたファイル名のファイルを開き、FILEHANDLE と結び付けます。 |
8384 | 8135 | |
8385 | 8136 | =begin original |
8386 | 8137 | |
8387 | 8138 | Simple examples to open a file for reading: |
8388 | 8139 | |
8389 | 8140 | =end original |
8390 | 8141 | |
8391 | 8142 | 読み込みのためにファイルを開くための簡単な例は以下のもので: |
8392 | 8143 | |
8393 | 8144 | open(my $fh, "<", "input.txt") |
8394 | 8145 | or die "cannot open < input.txt: $!"; |
8395 | 8146 | |
8396 | 8147 | =begin original |
8397 | 8148 | |
8398 | 8149 | and for writing: |
8399 | 8150 | |
8400 | 8151 | =end original |
8401 | 8152 | |
8402 | 8153 | 書き込み用は以下のものです: |
8403 | 8154 | |
8404 | 8155 | open(my $fh, ">", "output.txt") |
8405 | 8156 | or die "cannot open > output.txt: $!"; |
8406 | 8157 | |
8407 | 8158 | =begin original |
8408 | 8159 | |
8409 | 8160 | (The following is a comprehensive reference to open(): for a gentler |
8410 | 8161 | introduction you may consider L<perlopentut>.) |
8411 | 8162 | |
8412 | 8163 | =end original |
8413 | 8164 | |
8414 | 8165 | (以下は総合的な open() のリファレンスです: より親切な説明については |
8415 | 8166 | L<perlopentut> を参照してください。) |
8416 | 8167 | |
8417 | 8168 | =begin original |
8418 | 8169 | |
8419 | 8170 | If FILEHANDLE is an undefined scalar variable (or array or hash element), a |
8420 | 8171 | new filehandle is autovivified, meaning that the variable is assigned a |
8421 | 8172 | reference to a newly allocated anonymous filehandle. Otherwise if |
8422 | 8173 | FILEHANDLE is an expression, its value is the real filehandle. (This is |
8423 | 8174 | considered a symbolic reference, so C<use strict "refs"> should I<not> be |
8424 | 8175 | in effect.) |
8425 | 8176 | |
8426 | 8177 | =end original |
8427 | 8178 | |
8428 | 8179 | FILEHANDLE が未定義のスカラ変数(または配列かハッシュの要素)の場合、 |
8429 | 8180 | 新しいファイルハンドルが自動有効化され、その変数は新しく割り当てられた |
8430 | 8181 | 無名ファイルハンドルへのリファレンスが代入されます。 |
8431 | 8182 | さもなければ、もし FILEHANDLE が式なら、その値を求めている実際の |
8432 | 8183 | ファイルハンドルの名前として使います。 |
8433 | 8184 | (これはシンボリックリファレンスとして扱われるので、 |
8434 | 8185 | C<use strict "refs"> の影響を I<受けません>。) |
8435 | 8186 | |
8436 | 8187 | =begin original |
8437 | 8188 | |
8189 | If EXPR is omitted, the global (package) scalar variable of the same | |
8190 | name as the FILEHANDLE contains the filename. (Note that lexical | |
8191 | variables--those declared with C<my> or C<state>--will not work for this | |
8192 | purpose; so if you're using C<my> or C<state>, specify EXPR in your | |
8193 | call to open.) | |
8194 | ||
8195 | =end original | |
8196 | ||
8197 | EXPR が省略された場合、FILEHANDLE と同じ名前のグローバル(パッケージ) | |
8198 | スカラ変数にファイル名が入っています。 | |
8199 | (レキシカル変数 -- C<my> や C<state> で宣言されたもの -- はこの用途には | |
8200 | 使えないことに注意してください; 従って、C<my> や C<state> を使っている場合は、 | |
8201 | open を呼び出すときに EXPR を指定してください。) | |
8202 | ||
8203 | =begin original | |
8204 | ||
8438 | 8205 | If three (or more) arguments are specified, the open mode (including |
8439 | 8206 | optional encoding) in the second argument are distinct from the filename in |
8440 | 8207 | the third. If MODE is C<< < >> or nothing, the file is opened for input. |
8441 | 8208 | If MODE is C<< > >>, the file is opened for output, with existing files |
8442 | 8209 | first being truncated ("clobbered") and nonexisting files newly created. |
8443 | 8210 | If MODE is C<<< >> >>>, the file is opened for appending, again being |
8444 | 8211 | created if necessary. |
8445 | 8212 | |
8446 | 8213 | =end original |
8447 | 8214 | |
8448 | 8215 | 3 (またはそれ以上)の引数が指定された場合、2 番目の引数の(オプションの |
8449 | 8216 | エンコーディングを含む)開く時のモードは、3 番目のファイル名と分離されます。 |
8450 | 8217 | MODE が C<< < >> か空の場合、ファイルは入力用に開かれます。 |
8451 | 8218 | MODE が C<< > >> の場合、ファイルは出力用に開かれ、既にファイルが |
8452 | 8219 | ある場合は切り詰められ(上書きされ)、ない場合は新しく作られます。 |
8453 | 8220 | MODE が C<<< >> >>> の場合、ファイルは追加用に開かれ、やはり必要なら |
8454 | 8221 | 作成されます。 |
8455 | 8222 | |
8456 | 8223 | =begin original |
8457 | 8224 | |
8458 | 8225 | You can put a C<+> in front of the C<< > >> or C<< < >> to |
8459 | 8226 | indicate that you want both read and write access to the file; thus |
8460 | 8227 | C<< +< >> is almost always preferred for read/write updates--the |
8461 | 8228 | C<< +> >> mode would clobber the file first. You can't usually use |
8462 | 8229 | either read-write mode for updating textfiles, since they have |
8463 | 8230 | variable-length records. See the B<-i> switch in L<perlrun> for a |
8464 | 8231 | better approach. The file is created with permissions of C<0666> |
8465 | 8232 | modified by the process's C<umask> value. |
8466 | 8233 | |
8467 | 8234 | =end original |
8468 | 8235 | |
8469 | 8236 | ファイルに読み込みアクセスと書き込みアクセスの両方をしたいことを示すために、 |
8470 | 8237 | C<< > >> や C<< < >> の前に C<+> を付けることができます: |
8471 | 8238 | 従って、ほとんど常に C<< +< >> が読み書き更新のために使われます -- |
8472 | 8239 | C<< +> >> モードはまずファイルを上書きします。 |
8473 | 8240 | 普通はこれらの読み書きモードをテキストファイルの更新のためには使えません; |
8474 | 8241 | なぜなら可変長のレコードで構成されているからです。 |
8475 | 8242 | よりよい手法については L<perlrun> の B<-i> オプションを参照してください。 |
8476 | 8243 | ファイルは C<0666> をプロセスの C<umask> 値で修正したパーミッションで |
8477 | 8244 | 作成されます。 |
8478 | 8245 | |
8479 | 8246 | =begin original |
8480 | 8247 | |
8481 | 8248 | These various prefixes correspond to the fopen(3) modes of C<r>, |
8482 | 8249 | C<r+>, C<w>, C<w+>, C<a>, and C<a+>. |
8483 | 8250 | |
8484 | 8251 | =end original |
8485 | 8252 | |
8486 | 8253 | これらの様々な前置詞は fopen(3) の C<r>, C<r+>, |
8487 | 8254 | C<w>, C<w+>, C<a>, C<a+> のモードに対応します。 |
8488 | 8255 | |
8489 | 8256 | =begin original |
8490 | 8257 | |
8491 | 8258 | In the one- and two-argument forms of the call, the mode and filename |
8492 | 8259 | should be concatenated (in that order), preferably separated by white |
8493 | 8260 | space. You can--but shouldn't--omit the mode in these forms when that mode |
8494 | 8261 | is C<< < >>. It is always safe to use the two-argument form of C<open> if |
8495 | 8262 | the filename argument is a known literal. |
8496 | 8263 | |
8497 | 8264 | =end original |
8498 | 8265 | |
8499 | 8266 | 1 引数 と 2 引数の形式ではモードとファイル名は(この順番で) |
8500 | 8267 | 結合されます(空白によって分割されているかもしれません)。 |
8501 | 8268 | この形式で、モードが C<< '<' >> の場合はモードを省略できます (が、 |
8502 | 8269 | するべきではありません)。 |
8503 | 8270 | ファイル引数が既知のリテラルの場合、2 引数形式の C<open> は常に安全です。 |
8504 | 8271 | |
8505 | 8272 | =begin original |
8506 | 8273 | |
8507 | 8274 | For three or more arguments if MODE is C<|->, the filename is |
8508 | 8275 | interpreted as a command to which output is to be piped, and if MODE |
8509 | 8276 | is C<-|>, the filename is interpreted as a command that pipes |
8510 | 8277 | output to us. In the two-argument (and one-argument) form, one should |
8511 | 8278 | replace dash (C<->) with the command. |
8512 | 8279 | See L<perlipc/"Using open() for IPC"> for more examples of this. |
8513 | 8280 | (You are not allowed to C<open> to a command that pipes both in I<and> |
8514 | 8281 | out, but see L<IPC::Open2>, L<IPC::Open3>, and |
8515 | 8282 | L<perlipc/"Bidirectional Communication with Another Process"> for |
8516 | 8283 | alternatives.) |
8517 | 8284 | |
8518 | 8285 | =end original |
8519 | 8286 | |
8520 | 8287 | 3 引数以上の形式で |
8521 | 8288 | MODE が C<|-> の場合、ファイル名は出力がパイプされるコマンドとして |
8522 | 8289 | 解釈され、MODE が C<-|> の場合、ファイル名は出力がこちらに |
8523 | 8290 | パイプされるコマンドとして解釈されます。 |
8524 | 2 引数(と 1 引数) の形式ではハイフン(C<->)をコマンドの代わりに | |
8291 | 2 引数(と 1 引数) の形式ではハイフン(C<->)をコマンドの代わりに | |
8292 | 使えます。 | |
8525 | 8293 | これに関するさらなる例については L<perlipc/"Using open() for IPC"> を |
8526 | 8294 | 参照してください。 |
8527 | 8295 | (C<open> を入出力 I<両用> にパイプすることは出来ませんが |
8528 | 8296 | 代替案としては L<IPC::Open2>, L<IPC::Open3>, |
8529 | 8297 | L<perlipc/"Bidirectional Communication with Another Process"> を |
8530 | 8298 | 参照してください。) |
8531 | 8299 | |
8532 | 8300 | =begin original |
8533 | 8301 | |
8534 | 8302 | In the form of pipe opens taking three or more arguments, if LIST is specified |
8535 | 8303 | (extra arguments after the command name) then LIST becomes arguments |
8536 | 8304 | to the command invoked if the platform supports it. The meaning of |
8537 | 8305 | C<open> with more than three arguments for non-pipe modes is not yet |
8538 | 8306 | defined, but experimental "layers" may give extra LIST arguments |
8539 | 8307 | meaning. |
8540 | 8308 | |
8541 | 8309 | =end original |
8542 | 8310 | |
8543 | 8311 | パイプでの三つ以上の引数の形式では、LIST (コマンド名の後の追加の引数) が |
8544 | 8312 | 指定されると、プラットフォームが対応していれば、LIST は起動される |
8545 | 8313 | コマンドへの引数となります。 |
8546 | 8314 | パイプモードではない C<open> での三つ以上の引数の意味はまだ未定義ですが、 |
8547 | 8315 | 実験的な「層」は追加の LIST 引数の意味を与えます。 |
8548 | 8316 | |
8549 | 8317 | =begin original |
8550 | 8318 | |
8551 | 8319 | In the two-argument (and one-argument) form, opening C<< <- >> |
8552 | 8320 | or C<-> opens STDIN and opening C<< >- >> opens STDOUT. |
8553 | 8321 | |
8554 | 8322 | =end original |
8555 | 8323 | |
8556 | 8324 | 2 引数(と 1 引数)で C<< <- >> か C<-> を open すると STDIN が |
8557 | 8325 | オープンされ、C<< >- >> を open すると STDOUT がオープンされます。 |
8558 | 8326 | |
8559 | 8327 | =begin original |
8560 | 8328 | |
8561 | 8329 | You may (and usually should) use the three-argument form of open to specify |
8562 | 8330 | I/O layers (sometimes referred to as "disciplines") to apply to the handle |
8563 | 8331 | that affect how the input and output are processed (see L<open> and |
8564 | 8332 | L<PerlIO> for more details). For example: |
8565 | 8333 | |
8566 | 8334 | =end original |
8567 | 8335 | |
8568 | 8336 | open の 3 引数形式では、どのように入出力が処理されるかに影響を与える |
8569 | 8337 | I/O 層(「ディシプリン」とも呼ばれます)を指定できます |
8570 | 8338 | (そして普通はそうするべきです) |
8571 | 8339 | (詳細については L<open> と L<PerlIO> を参照してください)。 |
8572 | 8340 | 例えば: |
8573 | 8341 | |
8574 | 8342 | open(my $fh, "<:encoding(UTF-8)", "filename") |
8575 | 8343 | || die "can't open UTF-8 encoded filename: $!"; |
8576 | 8344 | |
8577 | 8345 | =begin original |
8578 | 8346 | |
8579 | 8347 | opens the UTF8-encoded file containing Unicode characters; |
8580 | 8348 | see L<perluniintro>. Note that if layers are specified in the |
8581 | 8349 | three-argument form, then default layers stored in ${^OPEN} (see L<perlvar>; |
8582 | 8350 | usually set by the B<open> pragma or the switch B<-CioD>) are ignored. |
8583 | 8351 | Those layers will also be ignored if you specifying a colon with no name |
8584 | 8352 | following it. In that case the default layer for the operating system |
8585 | 8353 | (:raw on Unix, :crlf on Windows) is used. |
8586 | 8354 | |
8587 | 8355 | =end original |
8588 | 8356 | |
8589 | 8357 | は、Unicode 文字を含む UTF8 エンコードされたファイルを開きます; |
8590 | 8358 | L<perluniintro> を参照してください。 |
8591 | 8359 | 3 引数形式で層を指定すると、${^OPEN} (L<perlvar> を参照してください; |
8592 | 通常は | |
8360 | 通常はC<open> プラグマか B<-CioD> オプションでセットされます) | |
8593 | デフォルト層は無視されることに注意してください。 | |
8361 | に保存されたデフォルト層は無視されることに注意してください。 | |
8594 | 8362 | これらの層は、名前なしでコロンを指定した場合にも無視されます。 |
8595 | 8363 | この場合 OS のデフォルトの層 (Unix では :raw、Windows では :crlf) が |
8596 | 8364 | 使われます。 |
8597 | 8365 | |
8598 | 8366 | =begin original |
8599 | 8367 | |
8600 | 8368 | Open returns nonzero on success, the undefined value otherwise. If |
8601 | 8369 | the C<open> involved a pipe, the return value happens to be the pid of |
8602 | 8370 | the subprocess. |
8603 | 8371 | |
8604 | 8372 | =end original |
8605 | 8373 | |
8606 | 8374 | open は、成功時にはゼロ以外を返し、失敗時には未定義値を返します。 |
8607 | 8375 | パイプに関る C<open> のときには、返り値はサブプロセスの pid となります。 |
8608 | 8376 | |
8609 | 8377 | =begin original |
8610 | 8378 | |
8611 | 8379 | If you're running Perl on a system that distinguishes between text |
8612 | 8380 | files and binary files, then you should check out L</binmode> for tips |
8613 | 8381 | for dealing with this. The key distinction between systems that need |
8614 | 8382 | C<binmode> and those that don't is their text file formats. Systems |
8615 | 8383 | like Unix, Mac OS, and Plan 9, that end lines with a single |
8616 | 8384 | character and encode that character in C as C<"\n"> do not |
8617 | 8385 | need C<binmode>. The rest need it. |
8618 | 8386 | |
8619 | 8387 | =end original |
8620 | 8388 | |
8621 | 8389 | テキストファイルとバイナリファイルを区別するシステムで Perl を実行している |
8622 | 8390 | 場合、これを扱うための小技のために L</binmode> をチェックするべきです。 |
8623 | 8391 | 動作させているシステムで C<binmode> が必要か不要化を区別する鍵は、テキスト |
8624 | 8392 | ファイルの形式です。 |
8625 | 8393 | Unix, Mac OS, Plan 9 といった、行の境界を 1 文字で表現し、それが C では |
8626 | 8394 | C<"\n"> でエンコードされる場合、C<binmode> は不要です。 |
8627 | 8395 | それ以外では必要です。 |
8628 | 8396 | |
8629 | 8397 | =begin original |
8630 | 8398 | |
8631 | 8399 | When opening a file, it's seldom a good idea to continue |
8632 | 8400 | if the request failed, so C<open> is frequently used with |
8633 | 8401 | C<die>. Even if C<die> won't do what you want (say, in a CGI script, |
8634 | 8402 | where you want to format a suitable error message (but there are |
8635 | 8403 | modules that can help with that problem)) always check |
8636 | 8404 | the return value from opening a file. |
8637 | 8405 | |
8638 | 8406 | =end original |
8639 | 8407 | |
8640 | ファイルを開く時、開くのに失敗した時に通常の処理を続けるのは | |
8408 | ファイルを開く時、開くのに失敗した時に通常の処理を続けるのは | |
8641 | 考え | |
8409 | 普通は悪い考えですので、C<open> はしばしば C<die> と結び付けられて | |
8642 | ||
8410 | 使われます。 | |
8643 | ||
8411 | 望むものが C<die> でない場合(例えば、CGI スクリプト のように | |
8412 | きれいにフォーマットされたエラーメッセージを作りたい場合 | |
8644 | 8413 | (但しこの問題を助けるモジュールがあります))でも、 |
8645 | ファイルを開いた時の返り値を常にチェックするべきです。 | |
8414 | ファイルを開いた時の返り値を常にチェックするべきです。 | |
8646 | 8415 | |
8647 | 8416 | =begin original |
8648 | 8417 | |
8649 | The filehandle will be closed when its reference count reaches zero. | |
8650 | If it is a lexically scoped variable declared with C<my>, that usually | |
8651 | means the end of the enclosing scope. However, this automatic close | |
8652 | does not check for errors, so it is better to explicitly close | |
8653 | filehandles, especially those used for writing: | |
8654 | ||
8655 | =end original | |
8656 | ||
8657 | ファイルハンドルは、参照カウントが 0 になったときに閉じられます。 | |
8658 | これが C<my> で宣言されたレキシカルスコープを持つ変数の場合、普通は | |
8659 | 囲まれたスコープの終わりを意味します。 | |
8660 | しかし、この自動閉じはエラーをチェックしないので、特に書き込み用の場合は、 | |
8661 | 明示的にファイルハンドルを閉じる方がよいです。 | |
8662 | ||
8663 | close($handle) | |
8664 | || warn "close failed: $!"; | |
8665 | ||
8666 | =begin original | |
8667 | ||
8668 | An older style is to use a bareword as the filehandle, as | |
8669 | ||
8670 | =end original | |
8671 | ||
8672 | より古いスタイルは、次のように、ファイルハンドルとして裸の単語を使います | |
8673 | ||
8674 | open(FH, "<", "input.txt") | |
8675 | or die "cannot open < input.txt: $!"; | |
8676 | ||
8677 | =begin original | |
8678 | ||
8679 | Then you can use C<FH> as the filehandle, in C<< close FH >> and C<< | |
8680 | <FH> >> and so on. Note that it's a global variable, so this form is | |
8681 | not recommended in new code. | |
8682 | ||
8683 | =end original | |
8684 | ||
8685 | それから C<FH> を、C<< close FH >> や C<< <FH> >> などのように、 | |
8686 | ファイルハンドルとして使えます。 | |
8687 | これはグローバル変数なので、新しいコードでは非推奨であることに | |
8688 | 注意してください。 | |
8689 | ||
8690 | =begin original | |
8691 | ||
8692 | As a shortcut a one-argument call takes the filename from the global | |
8693 | scalar variable of the same name as the filehandle: | |
8694 | ||
8695 | =end original | |
8696 | ||
8697 | 短縮版として、1 引数呼び出しでは、ファイル名を、ファイルハンドルと同じ名前の | |
8698 | グローバルなスカラ変数から取ります: | |
8699 | ||
8700 | $ARTICLE = 100; | |
8701 | open(ARTICLE) or die "Can't find article $ARTICLE: $!\n"; | |
8702 | ||
8703 | =begin original | |
8704 | ||
8705 | Here C<$ARTICLE> must be a global (package) scalar variable - not one | |
8706 | declared with C<my> or C<state>. | |
8707 | ||
8708 | =end original | |
8709 | ||
8710 | ここで C<$ARTICLE> はグローバル(パッケージ)スカラ変数でなければなりません - | |
8711 | C<my> や C<state> で宣言された変数ではありません。 | |
8712 | ||
8713 | =begin original | |
8714 | ||
8715 | 8418 | As a special case the three-argument form with a read/write mode and the third |
8716 | 8419 | argument being C<undef>: |
8717 | 8420 | |
8718 | 8421 | =end original |
8719 | 8422 | |
8720 | 特別な場合として、3 引数の形で読み書きモードで 3 番目の引数が | |
8423 | 特別な場合として、3 引数の形で読み書きモードで 3 番目の引数が | |
8424 | C<undef> の場合: | |
8721 | 8425 | |
8722 | 8426 | open(my $tmp, "+>", undef) or die ... |
8723 | 8427 | |
8724 | 8428 | =begin original |
8725 | 8429 | |
8726 | 8430 | opens a filehandle to an anonymous temporary file. Also using C<< +< >> |
8727 | 8431 | works for symmetry, but you really should consider writing something |
8728 | 8432 | to the temporary file first. You will need to seek() to do the |
8729 | 8433 | reading. |
8730 | 8434 | |
8731 | 8435 | =end original |
8732 | 8436 | |
8733 | 8437 | 無名一時ファイルとしてファイルハンドルを開きます。 |
8734 | 8438 | また C<< +< >> も対称性のために動作しますが、 |
8735 | 8439 | 一時ファイルにはまず何かを書き込みたいはずです。 |
8736 | 8440 | 読み込みを行うためには seek() が必要です。 |
8737 | 8441 | |
8738 | 8442 | =begin original |
8739 | 8443 | |
8740 | Perl | |
8444 | Since v5.8.0, Perl has built using PerlIO by default. Unless you've | |
8741 | 8445 | changed this (such as building Perl with C<Configure -Uuseperlio>), you can |
8742 | 8446 | open filehandles directly to Perl scalars via: |
8743 | 8447 | |
8744 | 8448 | =end original |
8745 | 8449 | |
8746 | Perl はデフォルトで PerlIO を使ってビルドされています | |
8450 | v5.8.0 から、Perl はデフォルトで PerlIO を使ってビルドされています。 | |
8747 | 8451 | (C<Configure -Uuseperlio> して Perl をビルドするなどして)これを |
8748 | 8452 | 変更していない限り、以下のようにして、Perl スカラを直接ファイルハンドルで |
8749 | 8453 | 開くことができます: |
8750 | 8454 | |
8751 | 8455 | open($fh, ">", \$variable) || .. |
8752 | 8456 | |
8753 | 8457 | =begin original |
8754 | 8458 | |
8755 | 8459 | To (re)open C<STDOUT> or C<STDERR> as an in-memory file, close it first: |
8756 | 8460 | |
8757 | 8461 | =end original |
8758 | 8462 | |
8759 | 8463 | C<STDOUT> や C<STDERR> を「オンメモリの」ファイルとして |
8760 | 8464 | 再び開きたい場合は、先にそれを閉じます: |
8761 | 8465 | |
8762 | 8466 | close STDOUT; |
8763 | 8467 | open(STDOUT, ">", \$variable) |
8764 | 8468 | or die "Can't open STDOUT: $!"; |
8765 | 8469 | |
8766 | 8470 | =begin original |
8767 | 8471 | |
8768 | 8472 | General examples: |
8769 | 8473 | |
8770 | 8474 | =end original |
8771 | 8475 | |
8772 | 8476 | 一般的な例: |
8773 | 8477 | |
8478 | $ARTICLE = 100; | |
8479 | open(ARTICLE) or die "Can't find article $ARTICLE: $!\n"; | |
8480 | while (<ARTICLE>) {... | |
8481 | ||
8774 | 8482 | open(LOG, ">>/usr/spool/news/twitlog"); # (log is reserved) |
8775 | 8483 | # if the open fails, output is discarded |
8776 | 8484 | |
8777 | 8485 | open(my $dbase, "+<", "dbase.mine") # open for update |
8778 | 8486 | or die "Can't open 'dbase.mine' for update: $!"; |
8779 | 8487 | |
8780 | 8488 | open(my $dbase, "+<dbase.mine") # ditto |
8781 | 8489 | or die "Can't open 'dbase.mine' for update: $!"; |
8782 | 8490 | |
8783 | 8491 | open(ARTICLE, "-|", "caesar <$article") # decrypt article |
8784 | 8492 | or die "Can't start caesar: $!"; |
8785 | 8493 | |
8786 | 8494 | open(ARTICLE, "caesar <$article |") # ditto |
8787 | 8495 | or die "Can't start caesar: $!"; |
8788 | 8496 | |
8789 | 8497 | open(EXTRACT, "|sort >Tmp$$") # $$ is our process id |
8790 | 8498 | or die "Can't start sort: $!"; |
8791 | 8499 | |
8792 | 8500 | # in-memory files |
8793 | 8501 | open(MEMORY, ">", \$var) |
8794 | 8502 | or die "Can't open memory file: $!"; |
8795 | print MEMORY "foo!\n"; # output will appear in $var | |
8503 | print MEMORY "foo!\n"; # output will appear in $var | |
8796 | 8504 | |
8797 | 8505 | # process argument list of files along with any includes |
8798 | 8506 | |
8799 | 8507 | foreach $file (@ARGV) { |
8800 | 8508 | process($file, "fh00"); |
8801 | 8509 | } |
8802 | 8510 | |
8803 | 8511 | sub process { |
8804 | 8512 | my($filename, $input) = @_; |
8805 | 8513 | $input++; # this is a string increment |
8806 | 8514 | unless (open($input, "<", $filename)) { |
8807 | 8515 | print STDERR "Can't open $filename: $!\n"; |
8808 | 8516 | return; |
8809 | 8517 | } |
8810 | 8518 | |
8811 | 8519 | local $_; |
8812 | 8520 | while (<$input>) { # note use of indirection |
8813 | 8521 | if (/^#include "(.*)"/) { |
8814 | 8522 | process($1, $input); |
8815 | 8523 | next; |
8816 | 8524 | } |
8817 | 8525 | #... # whatever |
8818 | 8526 | } |
8819 | 8527 | } |
8820 | 8528 | |
8821 | 8529 | =begin original |
8822 | 8530 | |
8823 | 8531 | See L<perliol> for detailed info on PerlIO. |
8824 | 8532 | |
8825 | 8533 | =end original |
8826 | 8534 | |
8827 | 8535 | PerlIO に関する詳しい情報については L<perliol> を参照してください。 |
8828 | 8536 | |
8829 | 8537 | =begin original |
8830 | 8538 | |
8831 | 8539 | You may also, in the Bourne shell tradition, specify an EXPR beginning |
8832 | 8540 | with C<< >& >>, in which case the rest of the string is interpreted |
8833 | 8541 | as the name of a filehandle (or file descriptor, if numeric) to be |
8834 | 8542 | duped (as C<dup(2)>) and opened. You may use C<&> after C<< > >>, |
8835 | 8543 | C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>, and C<< +< >>. |
8836 | 8544 | The mode you specify should match the mode of the original filehandle. |
8837 | 8545 | (Duping a filehandle does not take into account any existing contents |
8838 | 8546 | of IO buffers.) If you use the three-argument |
8839 | 8547 | form, then you can pass either a |
8840 | 8548 | number, the name of a filehandle, or the normal "reference to a glob". |
8841 | 8549 | |
8842 | 8550 | =end original |
8843 | 8551 | |
8844 | 8552 | Bourne シェルの慣例にしたがって、EXPR の先頭に C<< >& >> |
8845 | 8553 | を付けると、EXPR の残りの文字列をファイルハンドル名 |
8846 | 8554 | (数字であれば、ファイル記述子) と解釈して、それを (C<dup(2)> によって) |
8847 | 8555 | 複製してオープンします。 |
8848 | 8556 | C<&> は、C<< > >>, C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>, |
8849 | 8557 | C<< +< >>というモード指定に付けることができます。 |
8850 | 8558 | 指定するモード指定は、もとのファイルハンドルのモードと |
8851 | 8559 | 合っていないといけません。 |
8852 | 8560 | (ファイルハンドルの複製は既に存在する IO バッファの内容に含めません。) |
8853 | 8561 | 3 引数形式を使う場合は、数値を渡すか、ファイルハンドルの名前を渡すか、 |
8854 | 8562 | 通常の「グロブへのリファレンス」を渡します。 |
8855 | 8563 | |
8856 | 8564 | =begin original |
8857 | 8565 | |
8858 | 8566 | Here is a script that saves, redirects, and restores C<STDOUT> and |
8859 | 8567 | C<STDERR> using various methods: |
8860 | 8568 | |
8861 | 8569 | =end original |
8862 | 8570 | |
8863 | 8571 | C<STDOUT> と C<STDERR> 保存し、リダイレクトし、元に戻すスクリプトを示します: |
8864 | 8572 | |
8865 | 8573 | #!/usr/bin/perl |
8866 | 8574 | open(my $oldout, ">&STDOUT") or die "Can't dup STDOUT: $!"; |
8867 | 8575 | open(OLDERR, ">&", \*STDERR) or die "Can't dup STDERR: $!"; |
8868 | 8576 | |
8869 | 8577 | open(STDOUT, '>', "foo.out") or die "Can't redirect STDOUT: $!"; |
8870 | 8578 | open(STDERR, ">&STDOUT") or die "Can't dup STDOUT: $!"; |
8871 | 8579 | |
8872 | 8580 | select STDERR; $| = 1; # make unbuffered |
8873 | 8581 | select STDOUT; $| = 1; # make unbuffered |
8874 | 8582 | |
8875 | 8583 | print STDOUT "stdout 1\n"; # this works for |
8876 | 8584 | print STDERR "stderr 1\n"; # subprocesses too |
8877 | 8585 | |
8878 | 8586 | open(STDOUT, ">&", $oldout) or die "Can't dup \$oldout: $!"; |
8879 | 8587 | open(STDERR, ">&OLDERR") or die "Can't dup OLDERR: $!"; |
8880 | 8588 | |
8881 | 8589 | print STDOUT "stdout 2\n"; |
8882 | 8590 | print STDERR "stderr 2\n"; |
8883 | 8591 | |
8884 | 8592 | =begin original |
8885 | 8593 | |
8886 | 8594 | If you specify C<< '<&=X' >>, where C<X> is a file descriptor number |
8887 | 8595 | or a filehandle, then Perl will do an equivalent of C's C<fdopen> of |
8888 | 8596 | that file descriptor (and not call C<dup(2)>); this is more |
8889 | 8597 | parsimonious of file descriptors. For example: |
8890 | 8598 | |
8891 | 8599 | =end original |
8892 | 8600 | |
8893 | 8601 | C<X> をファイル記述子の番号かファイルハンドルとして、 |
8894 | 8602 | C<< '<&=X' >> と指定すると、Perl はそのファイル記述子に対する |
8895 | 8603 | C の C<fdopen> と同じことを行ないます(そして C<dup(2)> は呼び出しません); |
8896 | 8604 | これはファイル記述子をより節約します。 |
8897 | 8605 | 例えば: |
8898 | 8606 | |
8899 | 8607 | # open for input, reusing the fileno of $fd |
8900 | 8608 | open(FILEHANDLE, "<&=$fd") |
8901 | 8609 | |
8902 | 8610 | =begin original |
8903 | 8611 | |
8904 | 8612 | or |
8905 | 8613 | |
8906 | 8614 | =end original |
8907 | 8615 | |
8908 | 8616 | または |
8909 | 8617 | |
8910 | 8618 | open(FILEHANDLE, "<&=", $fd) |
8911 | 8619 | |
8912 | 8620 | =begin original |
8913 | 8621 | |
8914 | 8622 | or |
8915 | 8623 | |
8916 | 8624 | =end original |
8917 | 8625 | |
8918 | 8626 | または |
8919 | 8627 | |
8920 | 8628 | # open for append, using the fileno of OLDFH |
8921 | 8629 | open(FH, ">>&=", OLDFH) |
8922 | 8630 | |
8923 | 8631 | =begin original |
8924 | 8632 | |
8925 | 8633 | or |
8926 | 8634 | |
8927 | 8635 | =end original |
8928 | 8636 | |
8929 | 8637 | または |
8930 | 8638 | |
8931 | 8639 | open(FH, ">>&=OLDFH") |
8932 | 8640 | |
8933 | 8641 | =begin original |
8934 | 8642 | |
8935 | 8643 | Being parsimonious on filehandles is also useful (besides being |
8936 | 8644 | parsimonious) for example when something is dependent on file |
8937 | 8645 | descriptors, like for example locking using flock(). If you do just |
8938 | 8646 | C<< open(A, ">>&B") >>, the filehandle A will not have the same file |
8939 | 8647 | descriptor as B, and therefore flock(A) will not flock(B) nor vice |
8940 | 8648 | versa. But with C<< open(A, ">>&=B") >>, the filehandles will share |
8941 | 8649 | the same underlying system file descriptor. |
8942 | 8650 | |
8943 | 8651 | =end original |
8944 | 8652 | |
8945 | ファイルハンドルを倹約することは、 | |
8653 | ファイルハンドルを倹約することは、何かがファイル記述子に依存している場合、 | |
8946 | ||
8654 | 例えば flock() を使ったファイルロックといった場合に有用です | |
8947 | ||
8655 | (しかも倹約できます)。 | |
8948 | 8656 | C<< open(A, ">>&B") >> とすると、ファイルハンドル A は B と同じ |
8949 | 8657 | ファイル記述子にはならないので、flock(A) と flock(B) は別々になります。 |
8950 | 8658 | しかし C<< open(A, ">>&=B") >> ではファイルハンドルは基礎となるシステムの |
8951 | 8659 | 同じファイル記述子を共有します。 |
8952 | 8660 | |
8953 | 8661 | =begin original |
8954 | 8662 | |
8955 | 8663 | Note that under Perls older than 5.8.0, Perl uses the standard C library's' |
8956 | 8664 | fdopen() to implement the C<=> functionality. On many Unix systems, |
8957 | 8665 | fdopen() fails when file descriptors exceed a certain value, typically 255. |
8958 | 8666 | For Perls 5.8.0 and later, PerlIO is (most often) the default. |
8959 | 8667 | |
8960 | 8668 | =end original |
8961 | 8669 | |
8962 | 8670 | 5.8.0 より前の Perl の場合、C<=> 機能の実装は |
8963 | 8671 | 標準 C ライブラリの fdopen() を使っています。 |
8964 | 8672 | 多くの Unix システムでは、fdopen() はファイル記述子がある値 |
8965 | 8673 | (典型的には 255)を超えた場合に失敗することが知られています。 |
8966 | 8674 | 5.8.0 以降の Perl では、(ほとんどの場合) PerlIO がデフォルトです。 |
8967 | 8675 | |
8968 | 8676 | =begin original |
8969 | 8677 | |
8970 | 8678 | You can see whether your Perl was built with PerlIO by running C<perl -V> |
8971 | 8679 | and looking for the C<useperlio=> line. If C<useperlio> is C<define>, you |
8972 | 8680 | have PerlIO; otherwise you don't. |
8973 | 8681 | |
8974 | 8682 | =end original |
8975 | 8683 | |
8976 | 8684 | Perl が PerlIO つきでビルドされているかどうかを確認するには、 |
8977 | 8685 | C<perl -V> として C<useperlio=> の行を見ます。 |
8978 | 8686 | C<useperlio> が C<define> なら PerlIO を使っています; |
8979 | 8687 | そうでなければ使っていません。 |
8980 | 8688 | |
8981 | 8689 | =begin original |
8982 | 8690 | |
8983 | 8691 | If you open a pipe on the command C<-> (that is, specify either C<|-> or C<-|> |
8984 | 8692 | with the one- or two-argument forms of C<open>), |
8985 | 8693 | an implicit C<fork> is done, so C<open> returns twice: in the parent |
8986 | 8694 | process it returns the pid |
8987 | 8695 | of the child process, and in the child process it returns (a defined) C<0>. |
8988 | 8696 | Use C<defined($pid)> or C<//> to determine whether the open was successful. |
8989 | 8697 | |
8990 | 8698 | =end original |
8991 | 8699 | |
8992 | 8700 | 1 引数 または 2 引数の形の C<open()> で (C<-|> や C<|-> というふうに) |
8993 | 8701 | C<-> というコマンドにパイプを開くと、暗黙の C<fork> が行なわれるので、 |
8994 | 8702 | C<open> は 2 回返ります; |
8995 | 8703 | 親プロセスには子プロセスの pid が返され、子プロセスには (定義された) C<0> が |
8996 | 8704 | 返されます。 |
8997 | 8705 | open が成功したかどうかを調べるには、C<defined($pid)> または C<//> を |
8998 | 8706 | 使います。 |
8999 | 8707 | |
9000 | 8708 | =begin original |
9001 | 8709 | |
9002 | 8710 | For example, use either |
9003 | 8711 | |
9004 | 8712 | =end original |
9005 | 8713 | |
9006 | 8714 | 例えば、以下の二つ |
9007 | 8715 | |
9008 | 8716 | $child_pid = open(FROM_KID, "-|") // die "can't fork: $!"; |
9009 | 8717 | |
9010 | 8718 | =begin original |
9011 | 8719 | |
9012 | 8720 | or |
9013 | 8721 | |
9014 | 8722 | =end original |
9015 | 8723 | |
9016 | 8724 | または |
9017 | 8725 | |
9018 | 8726 | $child_pid = open(TO_KID, "|-") // die "can't fork: $!"; |
9019 | 8727 | |
9020 | 8728 | =begin original |
9021 | 8729 | |
9022 | 8730 | followed by |
9023 | 8731 | |
9024 | 8732 | =end original |
9025 | 8733 | |
9026 | 8734 | を使って、後で以下のようにします。 |
9027 | 8735 | |
9028 | 8736 | if ($child_pid) { |
9029 | 8737 | # am the parent: |
9030 | 8738 | # either write TO_KID or else read FROM_KID |
9031 | 8739 | ... |
9032 | ||
8740 | wait $child_pid; | |
9033 | 8741 | } else { |
9034 | 8742 | # am the child; use STDIN/STDOUT normally |
9035 | 8743 | ... |
9036 | 8744 | exit; |
9037 | 8745 | } |
9038 | 8746 | |
9039 | 8747 | =begin original |
9040 | 8748 | |
9041 | 8749 | The filehandle behaves normally for the parent, but I/O to that |
9042 | 8750 | filehandle is piped from/to the STDOUT/STDIN of the child process. |
9043 | 8751 | In the child process, the filehandle isn't opened--I/O happens from/to |
9044 | 8752 | the new STDOUT/STDIN. Typically this is used like the normal |
9045 | 8753 | piped open when you want to exercise more control over just how the |
9046 | 8754 | pipe command gets executed, such as when running setuid and |
9047 | 8755 | you don't want to have to scan shell commands for metacharacters. |
9048 | 8756 | |
9049 | 8757 | =end original |
9050 | 8758 | |
9051 | 親プロセスでは、このファイルハンドルは | |
8759 | 親プロセスでは、このファイルハンドルは | |
9052 | 入出力は、 | |
8760 | 通常通りに動作しますが、行なわれる入出力は、 | |
9053 | ||
8761 | チャイルドプロセスの STDIN/STDOUT にパイプされます。 | |
9054 | ||
8762 | チャイルドプロセス側では、そのファイルハンドルは | |
8763 | オープンされず、入出力は新しい STDOUT か STDIN に対して行なわれます。 | |
9055 | 8764 | これは、setuid で実行して、シェルコマンドのメタ文字を |
9056 | 8765 | 検索させたくないような場合に、パイプコマンドの起動の仕方を |
9057 | 8766 | 制御したいとき、普通のパイプの open と同じように使います。 |
9058 | 8767 | |
9059 | 8768 | =begin original |
9060 | 8769 | |
9061 | 8770 | The following blocks are more or less equivalent: |
9062 | 8771 | |
9063 | 8772 | =end original |
9064 | 8773 | |
9065 | 8774 | 以下の組み合わせは、だいたい同じものです: |
9066 | 8775 | |
9067 | 8776 | open(FOO, "|tr '[a-z]' '[A-Z]'"); |
9068 | 8777 | open(FOO, "|-", "tr '[a-z]' '[A-Z]'"); |
9069 | 8778 | open(FOO, "|-") || exec 'tr', '[a-z]', '[A-Z]'; |
9070 | 8779 | open(FOO, "|-", "tr", '[a-z]', '[A-Z]'); |
9071 | 8780 | |
9072 | 8781 | open(FOO, "cat -n '$file'|"); |
9073 | 8782 | open(FOO, "-|", "cat -n '$file'"); |
9074 | 8783 | open(FOO, "-|") || exec "cat", "-n", $file; |
9075 | 8784 | open(FOO, "-|", "cat", "-n", $file); |
9076 | 8785 | |
9077 | 8786 | =begin original |
9078 | 8787 | |
9079 | 8788 | The last two examples in each block show the pipe as "list form", which is |
9080 | 8789 | not yet supported on all platforms. A good rule of thumb is that if |
9081 | 8790 | your platform has a real C<fork()> (in other words, if your platform is |
9082 | 8791 | Unix, including Linux and MacOS X), you can use the list form. You would |
9083 | 8792 | want to use the list form of the pipe so you can pass literal arguments |
9084 | 8793 | to the command without risk of the shell interpreting any shell metacharacters |
9085 | 8794 | in them. However, this also bars you from opening pipes to commands |
9086 | 8795 | that intentionally contain shell metacharacters, such as: |
9087 | 8796 | |
9088 | 8797 | =end original |
9089 | 8798 | |
9090 | 8799 | それぞれのブロックの末尾二つの例ではパイプを「リスト形式」にしていますが、 |
9091 | 8800 | これはまだ全てのプラットフォームで対応しているわけではなりません。 |
9092 | 8801 | よい経験則としては、もし実行しているプラットフォームで本当の C<fork()> が |
9093 | 8802 | あれば(言い換えると、プラットフォームが Linux や MacOS X を含む Unix なら) |
9094 | 8803 | リスト形式が使えます。 |
9095 | 8804 | パイプのリスト形式を使うことで、コマンドへのリテラルな引数を、 |
9096 | 8805 | シェルのメタ文字をシェルが解釈するリスクなしに渡すことができます。 |
9097 | 8806 | しかし、これは以下のように意図的にシェルメタ文字を含むコマンドをパイプとして |
9098 | 8807 | 開くことを妨げます: |
9099 | 8808 | |
9100 | 8809 | open(FOO, "|cat -n | expand -4 | lpr") |
9101 | 8810 | // die "Can't open pipeline to lpr: $!"; |
9102 | 8811 | |
9103 | 8812 | =begin original |
9104 | 8813 | |
9105 | 8814 | See L<perlipc/"Safe Pipe Opens"> for more examples of this. |
9106 | 8815 | |
9107 | 8816 | =end original |
9108 | 8817 | |
9109 | 8818 | これに関する更なる例については L<perlipc/"Safe Pipe Opens"> を |
9110 | 8819 | 参照してください。 |
9111 | 8820 | |
9112 | 8821 | =begin original |
9113 | 8822 | |
9114 | Perl will attempt to flush all files opened for | |
8823 | Beginning with v5.6.0, Perl will attempt to flush all files opened for | |
9115 | 8824 | output before any operation that may do a fork, but this may not be |
9116 | 8825 | supported on some platforms (see L<perlport>). To be safe, you may need |
9117 | 8826 | to set C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method |
9118 | 8827 | of C<IO::Handle> on any open handles. |
9119 | 8828 | |
9120 | 8829 | =end original |
9121 | 8830 | |
9122 | 8831 | v5.6.0 から、Perl は書き込み用に開いている全てのファイルに対して |
9123 | 8832 | fork を行う前にフラッシュしようとしますが、これに対応していない |
9124 | 8833 | プラットフォームもあります(L<perlport> を参照してください)。 |
9125 | 8834 | 安全のために、C<$|> (English モジュールでは $AUTOFLUSH) をセットするか、 |
9126 | 8835 | 全ての開いているハンドルに対して C<IO::Handle> の C<autoflush()> メソッドを |
9127 | 8836 | 呼び出す必要があるかもしれません。 |
9128 | 8837 | |
9129 | 8838 | =begin original |
9130 | 8839 | |
9131 | 8840 | On systems that support a close-on-exec flag on files, the flag will |
9132 | 8841 | be set for the newly opened file descriptor as determined by the value |
9133 | 8842 | of C<$^F>. See L<perlvar/$^F>. |
9134 | 8843 | |
9135 | 8844 | =end original |
9136 | 8845 | |
9137 | 8846 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
9138 | 8847 | フラグは C<$^F> の値で決定される、新しくオープンされたファイル記述子に対して |
9139 | 8848 | セットされます。 |
9140 | 8849 | L<perlvar/$^F> を参照してください。 |
9141 | 8850 | |
9142 | 8851 | =begin original |
9143 | 8852 | |
9144 | 8853 | Closing any piped filehandle causes the parent process to wait for the |
9145 | 8854 | child to finish, then returns the status value in C<$?> and |
9146 | 8855 | C<${^CHILD_ERROR_NATIVE}>. |
9147 | 8856 | |
9148 | 8857 | =end original |
9149 | 8858 | |
9150 | パイプのファイルハンドルを close することで、 | |
8859 | パイプのファイルハンドルを close することで、 | |
9151 | 待ち、それから C<$?> と | |
8860 | 親プロセスは、チャイルドプロセスの終了を待ち、それから C<$?> と | |
8861 | C<${^CHILD_ERROR_NATIVE}> にステータス値を返します。 | |
9152 | 8862 | |
9153 | 8863 | =begin original |
9154 | 8864 | |
9155 | 8865 | The filename passed to the one- and two-argument forms of open() will |
9156 | 8866 | have leading and trailing whitespace deleted and normal |
9157 | 8867 | redirection characters honored. This property, known as "magic open", |
9158 | 8868 | can often be used to good effect. A user could specify a filename of |
9159 | 8869 | F<"rsh cat file |">, or you could change certain filenames as needed: |
9160 | 8870 | |
9161 | 8871 | =end original |
9162 | 8872 | |
9163 | 1 引数 と 2 引数の形の open() に渡されたファイル名は、 | |
8873 | 1 引数 と 2 引数の形の open() に渡されたファイル名は、 | |
9164 | 取り除かれ、 | |
8874 | はじめと終わりの空白が取り除かれ、 | |
9165 | ||
8875 | 通常のリダイレクト文字列を受け付けます。 | |
8876 | この機能は "magic open" として知られていますが、 | |
8877 | 普通いい効果をもたらします。 | |
9166 | 8878 | ユーザーは F<"rsh cat file |"> といったファイル名を指定できますし、 |
9167 | 8879 | 特定のファイル名を必要に応じて変更できます。 |
9168 | 8880 | |
9169 | 8881 | $filename =~ s/(.*\.gz)\s*$/gzip -dc < $1|/; |
9170 | 8882 | open(FH, $filename) or die "Can't open $filename: $!"; |
9171 | 8883 | |
9172 | 8884 | =begin original |
9173 | 8885 | |
9174 | 8886 | Use the three-argument form to open a file with arbitrary weird characters in it, |
9175 | 8887 | |
9176 | 8888 | =end original |
9177 | 8889 | |
9178 | 8890 | 妙な文字が含まれているようなファイル名をオープンするには、 |
9179 | 8891 | 3 引数の形を使います。 |
9180 | 8892 | |
9181 | 8893 | open(FOO, "<", $file) |
9182 | 8894 | || die "can't open < $file: $!"; |
9183 | 8895 | |
9184 | 8896 | =begin original |
9185 | 8897 | |
9186 | 8898 | otherwise it's necessary to protect any leading and trailing whitespace: |
9187 | 8899 | |
9188 | 8900 | =end original |
9189 | 8901 | |
9190 | 8902 | あるいは、次のようにして、最初と最後の空白を保護します: |
9191 | 8903 | |
9192 | 8904 | $file =~ s#^(\s)#./$1#; |
9193 | 8905 | open(FOO, "< $file\0") |
9194 | 8906 | || die "open failed: $!"; |
9195 | 8907 | |
9196 | 8908 | =begin original |
9197 | 8909 | |
9198 | 8910 | (this may not work on some bizarre filesystems). One should |
9199 | 8911 | conscientiously choose between the I<magic> and I<three-argument> form |
9200 | 8912 | of open(): |
9201 | 8913 | |
9202 | 8914 | =end original |
9203 | 8915 | |
9204 | 8916 | (これは奇妙なファイルシステムでは動作しないかもしれません)。 |
9205 | 8917 | open() の I<magic> と I<3 引数> 形式を誠実に選択するべきです。 |
9206 | 8918 | |
9207 | 8919 | open(IN, $ARGV[0]) || die "can't open $ARGV[0]: $!"; |
9208 | 8920 | |
9209 | 8921 | =begin original |
9210 | 8922 | |
9211 | 8923 | will allow the user to specify an argument of the form C<"rsh cat file |">, |
9212 | 8924 | but will not work on a filename that happens to have a trailing space, while |
9213 | 8925 | |
9214 | 8926 | =end original |
9215 | 8927 | |
9216 | 8928 | とするとユーザーは C<"rsh cat file |"> という形の引数を指定できますが、 |
9217 | 8929 | 末尾にスペースがついてしまったファイル名では動作しません; 一方: |
9218 | 8930 | |
9219 | 8931 | open(IN, "<", $ARGV[0]) |
9220 | 8932 | || die "can't open < $ARGV[0]: $!"; |
9221 | 8933 | |
9222 | 8934 | =begin original |
9223 | 8935 | |
9224 | 8936 | will have exactly the opposite restrictions. |
9225 | 8937 | |
9226 | 8938 | =end original |
9227 | 8939 | |
9228 | 8940 | はまったく逆の制限があります。 |
9229 | 8941 | |
9230 | 8942 | =begin original |
9231 | 8943 | |
9232 | 8944 | If you want a "real" C C<open> (see L<open(2)> on your system), then you |
9233 | 8945 | should use the C<sysopen> function, which involves no such magic (but may |
9234 | 8946 | use subtly different filemodes than Perl open(), which is mapped to C |
9235 | 8947 | fopen()). This is another way to protect your filenames from |
9236 | 8948 | interpretation. For example: |
9237 | 8949 | |
9238 | 8950 | =end original |
9239 | 8951 | |
9240 | 8952 | もし「本当の」C 言語の C<open> (システムの C<open(2)> を参照してください)が |
9241 | 8953 | 必要なら、このような副作用のない C<sysopen> 関数を使うべきです |
9242 | 8954 | (ただし、C の fopen() に割り付けられる Perl の open() とは |
9243 | 8955 | かすかに違うファイルモードを持ちます)。 |
9244 | 8956 | これはファイル名を解釈から守るもう一つの方法です。 |
9245 | 8957 | 例えば: |
9246 | 8958 | |
9247 | 8959 | use IO::Handle; |
9248 | 8960 | sysopen(HANDLE, $path, O_RDWR|O_CREAT|O_EXCL) |
9249 | 8961 | or die "sysopen $path: $!"; |
9250 | 8962 | $oldfh = select(HANDLE); $| = 1; select($oldfh); |
9251 | 8963 | print HANDLE "stuff $$\n"; |
9252 | 8964 | seek(HANDLE, 0, 0); |
9253 | 8965 | print "File contains: ", <HANDLE>; |
9254 | 8966 | |
9255 | 8967 | =begin original |
9256 | 8968 | |
8969 | Using the constructor from the C<IO::Handle> package (or one of its | |
8970 | subclasses, such as C<IO::File> or C<IO::Socket>), you can generate anonymous | |
8971 | filehandles that have the scope of the variables used to hold them, then | |
8972 | automatically (but silently) close once their reference counts become | |
8973 | zero, typically at scope exit: | |
8974 | ||
8975 | =end original | |
8976 | ||
8977 | C<IO::Handle> パッケージ(または C<IO::File> や C<IO::Socket> といった | |
8978 | サブパッケージ)のコンストラクタを使うことで、 | |
8979 | これらへのリファレンスを保持している変数のスコープを持ち、それから | |
8980 | 参照カウントが 0 になると自動的に (しかし暗黙に) 閉じる | |
8981 | 無名ファイルハンドルを作成できます: | |
8982 | ||
8983 | use IO::File; | |
8984 | #... | |
8985 | sub read_myfile_munged { | |
8986 | my $ALL = shift; | |
8987 | # or just leave it undef to autoviv | |
8988 | my $handle = IO::File->new; | |
8989 | open($handle, "<", "myfile") or die "myfile: $!"; | |
8990 | $first = <$handle> | |
8991 | or return (); # Automatically closed here. | |
8992 | mung($first) or die "mung failed"; # Or here. | |
8993 | return (first, <$handle>) if $ALL; # Or here. | |
8994 | return $first; # Or here. | |
8995 | } | |
8996 | ||
8997 | =begin original | |
8998 | ||
8999 | B<WARNING:> The previous example has a bug because the automatic | |
9000 | close that happens when the refcount on C<handle> does not | |
9001 | properly detect and report failures. I<Always> close the handle | |
9002 | yourself and inspect the return value. | |
9003 | ||
9004 | =end original | |
9005 | ||
9006 | B<警告:> 自動的に閉じると、C<handle> の参照カウントが適切に検出できない | |
9007 | ときに失敗が報告されるのでバグがあります。 | |
9008 | I<常に> ハンドルを自分自身で閉じて、返り値を調べてください。 | |
9009 | ||
9010 | close($handle) | |
9011 | || warn "close failed: $!"; | |
9012 | ||
9013 | =begin original | |
9014 | ||
9257 | 9015 | See L</seek> for some details about mixing reading and writing. |
9258 | 9016 | |
9259 | 9017 | =end original |
9260 | 9018 | |
9261 | 9019 | 読み書きを混ぜる場合の詳細については L</seek> を参照してください。 |
9262 | 9020 | |
9263 | 9021 | =begin original |
9264 | 9022 | |
9265 | 9023 | Portability issues: L<perlport/open>. |
9266 | 9024 | |
9267 | 9025 | =end original |
9268 | 9026 | |
9269 | 9027 | 移植性の問題: L<perlport/open>。 |
9270 | 9028 | |
9271 | 9029 | =item opendir DIRHANDLE,EXPR |
9272 | 9030 | X<opendir> |
9273 | 9031 | |
9274 | 9032 | =for Pod::Functions open a directory |
9275 | 9033 | |
9276 | 9034 | =begin original |
9277 | 9035 | |
9278 | 9036 | Opens a directory named EXPR for processing by C<readdir>, C<telldir>, |
9279 | 9037 | C<seekdir>, C<rewinddir>, and C<closedir>. Returns true if successful. |
9280 | 9038 | DIRHANDLE may be an expression whose value can be used as an indirect |
9281 | 9039 | dirhandle, usually the real dirhandle name. If DIRHANDLE is an undefined |
9282 | 9040 | scalar variable (or array or hash element), the variable is assigned a |
9283 | 9041 | reference to a new anonymous dirhandle; that is, it's autovivified. |
9284 | 9042 | DIRHANDLEs have their own namespace separate from FILEHANDLEs. |
9285 | 9043 | |
9286 | 9044 | =end original |
9287 | 9045 | |
9288 | 9046 | C<readdir>、C<telldir>、C<seekdir>、C<rewinddir>、C<closedir> で |
9289 | 9047 | 処理するために、EXPR で指定された名前のディレクトリをオープンします。 |
9290 | 9048 | 成功時には真を返します。 |
9291 | 9049 | DIRHANDLE は間接ディレクトリハンドルとして使える値(普通は実際のディレクトリ |
9292 | 9050 | ハンドルの名前)となる式でも構いません。 |
9293 | 9051 | DIRHANDLE が未定義のスカラ値(または配列かハッシュの要素)の場合、その変数は |
9294 | 9052 | 新しい無名ディレクトリハンドルへのリファレンスが代入されます; つまり、 |
9295 | 9053 | 自動有効化されます。 |
9296 | 9054 | DIRHANDLE は、FILEHANDLE とは別に名前空間を持っています。 |
9297 | 9055 | |
9298 | 9056 | =begin original |
9299 | 9057 | |
9300 | 9058 | See the example at C<readdir>. |
9301 | 9059 | |
9302 | 9060 | =end original |
9303 | 9061 | |
9304 | 9062 | C<readdir> の例を参照してください。 |
9305 | 9063 | |
9306 | 9064 | =item ord EXPR |
9307 | 9065 | X<ord> X<encoding> |
9308 | 9066 | |
9309 | 9067 | =item ord |
9310 | 9068 | |
9311 | 9069 | =for Pod::Functions find a character's numeric representation |
9312 | 9070 | |
9313 | 9071 | =begin original |
9314 | 9072 | |
9315 | 9073 | Returns the numeric value of the first character of EXPR. |
9316 | 9074 | If EXPR is an empty string, returns 0. If EXPR is omitted, uses C<$_>. |
9317 | 9075 | (Note I<character>, not byte.) |
9318 | 9076 | |
9319 | 9077 | =end original |
9320 | 9078 | |
9321 | 9079 | EXPR の最初の文字の数値としての値を返します。 |
9322 | 9080 | EXPR が空文字列の場合は、0 を返します。 |
9323 | 9081 | EXPR が省略されると、C<$_> を使います。 |
9324 | 9082 | (バイトではなく I<文字> であることに注意してください。) |
9325 | 9083 | |
9326 | 9084 | =begin original |
9327 | 9085 | |
9328 | 9086 | For the reverse, see L</chr>. |
9329 | 9087 | See L<perlunicode> for more about Unicode. |
9330 | 9088 | |
9331 | 9089 | =end original |
9332 | 9090 | |
9333 | 9091 | 逆のことをするには L</chr> を参照してください。 |
9334 | 9092 | Unicode については L<perlunicode> を参照してください。 |
9335 | 9093 | |
9336 | =item our | |
9094 | =item our EXPR | |
9337 | 9095 | X<our> X<global> |
9338 | 9096 | |
9339 | =item our TYPE | |
9097 | =item our TYPE EXPR | |
9340 | 9098 | |
9341 | =item our | |
9099 | =item our EXPR : ATTRS | |
9342 | 9100 | |
9343 | =item our TYPE | |
9101 | =item our TYPE EXPR : ATTRS | |
9344 | 9102 | |
9345 | 9103 | =for Pod::Functions +5.6.0 declare and assign a package variable (lexical scoping) |
9346 | 9104 | |
9347 | 9105 | =begin original |
9348 | 9106 | |
9349 | C<our> | |
9107 | C<our> associates a simple name with a package variable in the current | |
9350 | ||
9108 | package for use within the current scope. When C<use strict 'vars'> is in | |
9109 | effect, C<our> lets you use declared global variables without qualifying | |
9110 | them with package names, within the lexical scope of the C<our> declaration. | |
9111 | In this way C<our> differs from C<use vars>, which is package-scoped. | |
9351 | 9112 | |
9352 | 9113 | =end original |
9353 | 9114 | |
9354 | C<our> は単純名を、現在の | |
9115 | C<our> は単純名を、現在のスコープ内で使うために、現在のパッケージの | |
9355 | ||
9116 | パッケージ変数と結び付けます。 | |
9117 | C<use strict 'vars'> が有効の場合は、C<our> を使うことで、C<our> 宣言の | |
9118 | レキシカルスコープ内で、宣言されたグローバル変数をパッケージ名で | |
9119 | 修飾することなく使うことができます。 | |
9120 | この意味では、C<use vars> はパッケージスコープなので、C<our> とは異なります。 | |
9356 | 9121 | |
9357 | 9122 | =begin original |
9358 | 9123 | |
9359 | ||
9124 | Unlike C<my> or C<state>, which allocates storage for a variable and | |
9360 | ||
9125 | associates a simple name with that storage for use within the current | |
9361 | ||
9126 | scope, C<our> associates a simple name with a package (read: global) | |
9362 | ||
9127 | variable in the current package, for use within the current lexical scope. | |
9128 | In other words, C<our> has the same scoping rules as C<my> or C<state>, but | |
9129 | does not necessarily create a variable. | |
9363 | 9130 | |
9364 | 9131 | =end original |
9365 | 9132 | |
9366 | ||
9133 | 記憶領域を変数に割り当て、単純名を現在のスコープ内で使うためにその記憶領域に | |
9367 | レキシカル | |
9134 | 割り当てる C<my> や C<state> と違って、C<our> は単純名を、現在のレキシカル | |
9368 | ||
9135 | スコープ内で使うために、現在のパッケージの(読み込み: グローバル) パッケージ | |
9369 | ||
9136 | 変数と結び付けます。 | |
9137 | 言い換えると、C<our> は C<my> や C<state> と同じスコープルールを持ちますが、 | |
9138 | 変数を作る必要はありません。 | |
9370 | 9139 | |
9371 | 9140 | =begin original |
9372 | 9141 | |
9373 | ||
9142 | If more than one value is listed, the list must be placed | |
9374 | a package variable without qualifying it with the package name, but only within | |
9375 | the lexical scope of the C<our> declaration. | |
9376 | ||
9377 | =end original | |
9378 | ||
9379 | つまり、C<use strict 'vars'> が有効の場合は、C<our> を使うことで、 | |
9380 | パッケージ変数をパッケージ名で修飾することなく使うことができますが、 | |
9381 | C<our> 宣言のレキシカルスコープ内だけということです。 | |
9382 | ||
9383 | package Foo; | |
9384 | use strict; | |
9385 | ||
9386 | $Foo::foo = 23; | |
9387 | ||
9388 | { | |
9389 | our $foo; # alias to $Foo::foo | |
9390 | print $foo; # prints 23 | |
9391 | } | |
9392 | ||
9393 | print $Foo::foo; # prints 23 | |
9394 | ||
9395 | print $foo; # ERROR: requires explicit package name | |
9396 | ||
9397 | =begin original | |
9398 | ||
9399 | This works even if the package variable has not been used before, as | |
9400 | package variables spring into existence when first used. | |
9401 | ||
9402 | =end original | |
9403 | ||
9404 | これはパッケージ変数がまだ使われていなくても動作します; パッケージ変数は、 | |
9405 | 最初に使われた時にひょっこり現れるからです。 | |
9406 | ||
9407 | package Foo; | |
9408 | use strict; | |
9409 | ||
9410 | our $foo = 23; # just like $Foo::foo = 23 | |
9411 | ||
9412 | print $Foo::foo; # prints 23 | |
9413 | ||
9414 | =begin original | |
9415 | ||
9416 | If more than one variable is listed, the list must be placed | |
9417 | 9143 | in parentheses. |
9418 | 9144 | |
9419 | 9145 | =end original |
9420 | 9146 | |
9421 | 複数の | |
9147 | 複数の値を指定する場合は、リストはかっこでくくらなければなりません。 | |
9422 | 9148 | |
9149 | our $foo; | |
9423 | 9150 | our($bar, $baz); |
9424 | 9151 | |
9425 | 9152 | =begin original |
9426 | 9153 | |
9427 | An C<our> declaration declares a | |
9154 | An C<our> declaration declares a global variable that will be visible | |
9428 | 9155 | across its entire lexical scope, even across package boundaries. The |
9429 | 9156 | package in which the variable is entered is determined at the point |
9430 | 9157 | of the declaration, not at the point of use. This means the following |
9431 | 9158 | behavior holds: |
9432 | 9159 | |
9433 | 9160 | =end original |
9434 | 9161 | |
9435 | 9162 | C<our> 宣言はレキシカルスコープ全体に対して(たとえパッケージ境界を |
9436 | 越えていても)見える | |
9163 | 越えていても)見えるグローバル変数を宣言します。 | |
9437 | 9164 | この変数が入るパッケージは宣言した時点で定義され、 |
9438 | 9165 | 使用した時点ではありません。 |
9439 | 9166 | これにより、以下のような振る舞いになります: |
9440 | 9167 | |
9441 | 9168 | package Foo; |
9442 | 9169 | our $bar; # declares $Foo::bar for rest of lexical scope |
9443 | 9170 | $bar = 20; |
9444 | 9171 | |
9445 | 9172 | package Bar; |
9446 | 9173 | print $bar; # prints 20, as it refers to $Foo::bar |
9447 | 9174 | |
9448 | 9175 | =begin original |
9449 | 9176 | |
9450 | 9177 | Multiple C<our> declarations with the same name in the same lexical |
9451 | 9178 | scope are allowed if they are in different packages. If they happen |
9452 | 9179 | to be in the same package, Perl will emit warnings if you have asked |
9453 | 9180 | for them, just like multiple C<my> declarations. Unlike a second |
9454 | 9181 | C<my> declaration, which will bind the name to a fresh variable, a |
9455 | 9182 | second C<our> declaration in the same package, in the same scope, is |
9456 | 9183 | merely redundant. |
9457 | 9184 | |
9458 | 9185 | =end original |
9459 | 9186 | |
9460 | 9187 | 同じレキシカルスコープでも、パッケージが異なっていれば、同じ名前で複数の |
9461 | 9188 | C<our> 宣言ができます。 |
9462 | 9189 | 同じパッケージになっていると、警告が出力されるようになっていれば |
9463 | 9190 | 複数の C<my> 宣言がある場合と同じように警告が出力されます。 |
9464 | 9191 | 新しい変数を名前に割り当てることになる 2 回目の C<my> 宣言と違って、 |
9465 | 9192 | 同じパッケージの同じスコープで 2 回 C<our> 宣言するのは単に冗長です。 |
9466 | 9193 | |
9467 | 9194 | use warnings; |
9468 | 9195 | package Foo; |
9469 | 9196 | our $bar; # declares $Foo::bar for rest of lexical scope |
9470 | 9197 | $bar = 20; |
9471 | 9198 | |
9472 | 9199 | package Bar; |
9473 | 9200 | our $bar = 30; # declares $Bar::bar for rest of lexical scope |
9474 | 9201 | print $bar; # prints 30 |
9475 | 9202 | |
9476 | 9203 | our $bar; # emits warning but has no other effect |
9477 | 9204 | print $bar; # still prints 30 |
9478 | 9205 | |
9479 | 9206 | =begin original |
9480 | 9207 | |
9481 | 9208 | An C<our> declaration may also have a list of attributes associated |
9482 | 9209 | with it. |
9483 | 9210 | |
9484 | 9211 | =end original |
9485 | 9212 | |
9486 | 9213 | C<our> 宣言には、それと結び付けられる属性のリストを持つこともあります。 |
9487 | 9214 | |
9488 | 9215 | =begin original |
9489 | 9216 | |
9490 | 9217 | The exact semantics and interface of TYPE and ATTRS are still |
9491 | 9218 | evolving. TYPE is currently bound to the use of the C<fields> pragma, |
9492 | 9219 | and attributes are handled using the C<attributes> pragma, or, starting |
9493 | 9220 | from Perl 5.8.0, also via the C<Attribute::Handlers> module. See |
9494 | 9221 | L<perlsub/"Private Variables via my()"> for details, and L<fields>, |
9495 | 9222 | L<attributes>, and L<Attribute::Handlers>. |
9496 | 9223 | |
9497 | 9224 | =end original |
9498 | 9225 | |
9499 | 9226 | TYPE と ATTRS の正確な文法とインターフェースは今でも進化しています。 |
9500 | 9227 | 現在のところ、TYPE は C<fields> プラグマの使用と結び付けられていて、 |
9501 | 9228 | 属性は C<attributes> プラグマか、Perl 5.8.0 からは |
9502 | 9229 | C<Attribute::Handlers> モジュールと結び付けられています。 |
9503 | 9230 | 詳しくはL<perlsub/"Private Variables via my()">, L<fields>, |
9504 | 9231 | L<attributes>, L<Attribute::Handlers> を参照してください。 |
9505 | 9232 | |
9506 | =begin original | |
9507 | ||
9508 | Note that with a parenthesised list, C<undef> can be used as a dummy | |
9509 | placeholder, for example to skip assignment of initial values: | |
9510 | ||
9511 | =end original | |
9512 | ||
9513 | かっこで囲まれたリストでは、C<undef> は、例えば初期値の代入を飛ばすために、 | |
9514 | ダミーのプレースホルダとして使えることに注意してください: | |
9515 | ||
9516 | our ( undef, $min, $hour ) = localtime; | |
9517 | ||
9518 | =begin original | |
9519 | ||
9520 | C<our> differs from C<use vars>, which allows use of an unqualified name | |
9521 | I<only> within the affected package, but across scopes. | |
9522 | ||
9523 | =end original | |
9524 | ||
9525 | C<our> は C<use vars> と異なります; スコープをまたぐのではなく、影響する | |
9526 | パッケージの内側 I<のみ> で完全修飾されていない名前を使えるようにします。 | |
9527 | ||
9528 | 9233 | =item pack TEMPLATE,LIST |
9529 | 9234 | X<pack> |
9530 | 9235 | |
9531 | 9236 | =for Pod::Functions convert a list into a binary representation |
9532 | 9237 | |
9533 | 9238 | =begin original |
9534 | 9239 | |
9535 | 9240 | Takes a LIST of values and converts it into a string using the rules |
9536 | 9241 | given by the TEMPLATE. The resulting string is the concatenation of |
9537 | 9242 | the converted values. Typically, each converted value looks |
9538 | 9243 | like its machine-level representation. For example, on 32-bit machines |
9539 | 9244 | an integer may be represented by a sequence of 4 bytes, which will in |
9540 | 9245 | Perl be presented as a string that's 4 characters long. |
9541 | 9246 | |
9542 | 9247 | =end original |
9543 | 9248 | |
9544 | 9249 | LIST の値を TEMPLATE で与えられたルールを用いて文字列に変換します。 |
9545 | 9250 | 結果の文字列は変換した値を連結したものです。 |
9546 | 9251 | 典型的には、それぞれの変換された値はマシンレベルの表現のように見えます。 |
9547 | 9252 | 例えば、32-bit マシンでは、整数は 4 バイトで表現されるので、 |
9548 | 9253 | Perl では 4 文字の文字列で表現されます。 |
9549 | 9254 | |
9550 | 9255 | =begin original |
9551 | 9256 | |
9552 | 9257 | See L<perlpacktut> for an introduction to this function. |
9553 | 9258 | |
9554 | 9259 | =end original |
9555 | 9260 | |
9556 | 9261 | この関数の説明については L<perlpacktut> を参照してください。 |
9557 | 9262 | |
9558 | 9263 | =begin original |
9559 | 9264 | |
9560 | 9265 | The TEMPLATE is a sequence of characters that give the order and type |
9561 | 9266 | of values, as follows: |
9562 | 9267 | |
9563 | 9268 | =end original |
9564 | 9269 | |
9565 | 9270 | TEMPLATE は、以下のような値の型と順番を指定する文字を並べたものです: |
9566 | 9271 | |
9567 | 9272 | =begin original |
9568 | 9273 | |
9569 | 9274 | a A string with arbitrary binary data, will be null padded. |
9570 | 9275 | A A text (ASCII) string, will be space padded. |
9571 | 9276 | Z A null-terminated (ASCIZ) string, will be null padded. |
9572 | 9277 | |
9573 | 9278 | =end original |
9574 | 9279 | |
9575 | 9280 | a 任意のバイナリデータを含む文字列、ヌル文字で埋める。 |
9576 | 9281 | A テキスト (ASCII) 文字列、スペース文字で埋める。 |
9577 | 9282 | Z ヌル文字終端 (ASCIZ) 文字列、ヌル文字で埋める。 |
9578 | 9283 | |
9579 | 9284 | =begin original |
9580 | 9285 | |
9581 | 9286 | b A bit string (ascending bit order inside each byte, |
9582 | 9287 | like vec()). |
9583 | 9288 | B A bit string (descending bit order inside each byte). |
9584 | 9289 | h A hex string (low nybble first). |
9585 | 9290 | H A hex string (high nybble first). |
9586 | 9291 | |
9587 | 9292 | =end original |
9588 | 9293 | |
9589 | 9294 | b ビット列 (バイトごとに昇ビット順、vec() と同じ)。 |
9590 | 9295 | B ビット列 (バイトごとに降ビット順)。 |
9591 | 9296 | h 16 進数文字列 (低位ニブルが先)。 |
9592 | 9297 | H 16 進数文字列 (高位ニブルが先)。 |
9593 | 9298 | |
9594 | 9299 | =begin original |
9595 | 9300 | |
9596 | 9301 | c A signed char (8-bit) value. |
9597 | 9302 | C An unsigned char (octet) value. |
9598 | 9303 | W An unsigned char value (can be greater than 255). |
9599 | 9304 | |
9600 | 9305 | =end original |
9601 | 9306 | |
9602 | 9307 | c signed char (8 ビット) 値。 |
9603 | 9308 | C unsigned char (オクテット) 値。 |
9604 | 9309 | W unsigned char 値 (255 より大きいかもしれません)。 |
9605 | 9310 | |
9606 | 9311 | =begin original |
9607 | 9312 | |
9608 | 9313 | s A signed short (16-bit) value. |
9609 | 9314 | S An unsigned short value. |
9610 | 9315 | |
9611 | 9316 | =end original |
9612 | 9317 | |
9613 | 9318 | s signed short (16 ビット) 値。 |
9614 | 9319 | S unsigned short 値。 |
9615 | 9320 | |
9616 | 9321 | =begin original |
9617 | 9322 | |
9618 | 9323 | l A signed long (32-bit) value. |
9619 | 9324 | L An unsigned long value. |
9620 | 9325 | |
9621 | 9326 | =end original |
9622 | 9327 | |
9623 | 9328 | l signed long (32 ビット) 値。 |
9624 | 9329 | L unsigned long 値。 |
9625 | 9330 | |
9626 | 9331 | =begin original |
9627 | 9332 | |
9628 | 9333 | q A signed quad (64-bit) value. |
9629 | 9334 | Q An unsigned quad value. |
9630 | 9335 | (Quads are available only if your system supports 64-bit |
9631 | 9336 | integer values _and_ if Perl has been compiled to support |
9632 | 9337 | those. Raises an exception otherwise.) |
9633 | 9338 | |
9634 | 9339 | =end original |
9635 | 9340 | |
9636 | 9341 | q 符号付き 64 ビット整数。 |
9637 | 9342 | Q 符号なし 64 ビット整数。 |
9638 | 9343 | (64 ビット整数は、システムが 64 ビット整数に対応していて、かつ Perl が |
9639 | 9344 | 64 ビット整数対応としてコンパイルされている場合にのみ使用可能です。 |
9640 | 9345 | それ以外の場合は例外が発生します。) |
9641 | 9346 | |
9642 | 9347 | =begin original |
9643 | 9348 | |
9644 | 9349 | i A signed integer value. |
9645 | 9350 | I A unsigned integer value. |
9646 | 9351 | (This 'integer' is _at_least_ 32 bits wide. Its exact |
9647 | 9352 | size depends on what a local C compiler calls 'int'.) |
9648 | 9353 | |
9649 | 9354 | =end original |
9650 | 9355 | |
9651 | 9356 | i signed int 値。 |
9652 | 9357 | I unsigned int 値。 |
9653 | (ここでの 'integer' は 「最低」 32 | |
9358 | (ここでの 'integer' は 「最低」 32 bits 幅です。正確なサイズは | |
9654 | ローカルの C コンパイラの | |
9359 | ローカルの C コンパイラの'int'のサイズに依存します。) | |
9655 | 9360 | |
9656 | 9361 | =begin original |
9657 | 9362 | |
9658 | 9363 | n An unsigned short (16-bit) in "network" (big-endian) order. |
9659 | 9364 | N An unsigned long (32-bit) in "network" (big-endian) order. |
9660 | 9365 | v An unsigned short (16-bit) in "VAX" (little-endian) order. |
9661 | 9366 | V An unsigned long (32-bit) in "VAX" (little-endian) order. |
9662 | 9367 | |
9663 | 9368 | =end original |
9664 | 9369 | |
9665 | 9370 | n "network" 順序 (ビッグエンディアン) の unsigned short (16 ビット)。 |
9666 | 9371 | N "network" 順序 (ビッグエンディアン) の unsigned long (32 ビット)。 |
9667 | 9372 | v "VAX" 順序 (リトルエンディアン) の unsigned short (16 ビット)。 |
9668 | 9373 | V "VAX" 順序 (リトルエンディアン) の unsigned long (32 ビット)。 |
9669 | 9374 | |
9670 | 9375 | =begin original |
9671 | 9376 | |
9672 | 9377 | j A Perl internal signed integer value (IV). |
9673 | 9378 | J A Perl internal unsigned integer value (UV). |
9674 | 9379 | |
9675 | 9380 | =end original |
9676 | 9381 | |
9677 | 9382 | j Perl 内部符号付き整数 (IV)。 |
9678 | 9383 | J Perl 内部符号なし整数 (UV)。 |
9679 | 9384 | |
9680 | 9385 | =begin original |
9681 | 9386 | |
9682 | 9387 | f A single-precision float in native format. |
9683 | 9388 | d A double-precision float in native format. |
9684 | 9389 | |
9685 | 9390 | =end original |
9686 | 9391 | |
9687 | 9392 | f 機種依存の単精度浮動小数点数。 |
9688 | 9393 | d 機種依存の倍精度浮動小数点数。 |
9689 | 9394 | |
9690 | 9395 | =begin original |
9691 | 9396 | |
9692 | 9397 | F A Perl internal floating-point value (NV) in native format |
9693 | 9398 | D A float of long-double precision in native format. |
9694 | 9399 | (Long doubles are available only if your system supports |
9695 | 9400 | long double values _and_ if Perl has been compiled to |
9696 | 9401 | support those. Raises an exception otherwise.) |
9697 | 9402 | |
9698 | 9403 | =end original |
9699 | 9404 | |
9700 | 9405 | F ネイティブフォーマットの Perl 内部浮動小数点数 (NV) |
9701 | 9406 | D ネイティブフォーマットの長い倍精度浮動小数点数(long double)。 |
9702 | 9407 | (long double は、システムが long double に対応していて、かつ Perl が |
9703 | 9408 | long double 対応としてコンパイルされている場合にのみ使用可能です。 |
9704 | 9409 | それ以外の場合は例外が発生します。) |
9705 | 9410 | |
9706 | 9411 | =begin original |
9707 | 9412 | |
9708 | 9413 | p A pointer to a null-terminated string. |
9709 | 9414 | P A pointer to a structure (fixed-length string). |
9710 | 9415 | |
9711 | 9416 | =end original |
9712 | 9417 | |
9713 | 9418 | p ヌル文字で終端する文字列へのポインタ。 |
9714 | 9419 | P 構造体 (固定長文字列) へのポインタ。 |
9715 | 9420 | |
9716 | 9421 | =begin original |
9717 | 9422 | |
9718 | 9423 | u A uuencoded string. |
9719 | 9424 | U A Unicode character number. Encodes to a character in char- |
9720 | 9425 | acter mode and UTF-8 (or UTF-EBCDIC in EBCDIC platforms) in |
9721 | 9426 | byte mode. |
9722 | 9427 | |
9723 | 9428 | =end original |
9724 | 9429 | |
9725 | 9430 | u uuencode 文字列。 |
9726 | 9431 | U Unicode 文字番号。文字モードでは文字に、バイトモードなら UTF-8 に |
9727 | 9432 | (EBCDIC システムでは UTF-EBCDIC に)エンコードされます。 |
9728 | 9433 | |
9729 | 9434 | =begin original |
9730 | 9435 | |
9731 | 9436 | w A BER compressed integer (not an ASN.1 BER, see perlpacktut |
9732 | 9437 | for details). Its bytes represent an unsigned integer in |
9733 | 9438 | base 128, most significant digit first, with as few digits |
9734 | 9439 | as possible. Bit eight (the high bit) is set on each byte |
9735 | 9440 | except the last. |
9736 | 9441 | |
9737 | 9442 | =end original |
9738 | 9443 | |
9739 | 9444 | w A BER 圧縮変数(ASN.1 BER ではありません; 詳細については perlpacktut を |
9740 | 9445 | 参照してください)。このバイト列はできるだけ少ない桁数で表現された |
9741 | 9446 | 128 を基とした符号なし整数で、最上位ビットから順に並びます。 |
9742 | 9447 | 最後のバイト以外の各バイトのビット 8 (上位ビット) がセットされます。 |
9743 | 9448 | |
9744 | 9449 | =begin original |
9745 | 9450 | |
9746 | 9451 | x A null byte (a.k.a ASCII NUL, "\000", chr(0)) |
9747 | 9452 | X Back up a byte. |
9748 | 9453 | @ Null-fill or truncate to absolute position, counted from the |
9749 | 9454 | start of the innermost ()-group. |
9750 | 9455 | . Null-fill or truncate to absolute position specified by |
9751 | 9456 | the value. |
9752 | 9457 | ( Start of a ()-group. |
9753 | 9458 | |
9754 | 9459 | =end original |
9755 | 9460 | |
9756 | 9461 | x ヌル文字 (つまり ASCII NUL, "\000", chr(0)) |
9757 | 9462 | X 1 文字後退。 |
9758 | 9463 | @ 一番内側の () の組の開始位置から数えて、絶対位置までヌル文字で |
9759 | 9464 | 埋めるか切り詰める。 |
9760 | 9465 | . 値で指定した絶対位置までヌル文字で埋めるか切り詰める。 |
9761 | 9466 | ( () の組の開始。 |
9762 | 9467 | |
9763 | 9468 | =begin original |
9764 | 9469 | |
9765 | 9470 | One or more modifiers below may optionally follow certain letters in the |
9766 | 9471 | TEMPLATE (the second column lists letters for which the modifier is valid): |
9767 | 9472 | |
9768 | 9473 | =end original |
9769 | 9474 | |
9770 | 9475 | 以下に示す一つまたは複数の修飾子を、TEMPLATE の文字のいくつかにオプションで |
9771 | 9476 | 付けることができます(表の 2 列目は、その修飾子が有効な文字です): |
9772 | 9477 | |
9773 | 9478 | =begin original |
9774 | 9479 | |
9775 | 9480 | ! sSlLiI Forces native (short, long, int) sizes instead |
9776 | 9481 | of fixed (16-/32-bit) sizes. |
9777 | 9482 | |
9778 | 9483 | =end original |
9779 | 9484 | |
9780 | 9485 | ! sSlLiI 固定の(16/32 ビット)サイズではなく、ネイティブな |
9781 | 9486 | (short, long, int)サイズを強制する。 |
9782 | 9487 | |
9783 | 9488 | =begin original |
9784 | 9489 | |
9785 | | |
9490 | xX Make x and X act as alignment commands. | |
9786 | 9491 | |
9787 | 9492 | =end original |
9788 | 9493 | |
9789 | | |
9494 | xX x と X をアライメントコマンドとして振舞わせる。 | |
9790 | 9495 | |
9791 | 9496 | =begin original |
9792 | 9497 | |
9793 | | |
9498 | nNvV Treat integers as signed instead of unsigned. | |
9794 | 9499 | |
9795 | 9500 | =end original |
9796 | 9501 | |
9797 | | |
9502 | nNvV 整数を符号なしではなく符号付きとして扱わせる。 | |
9798 | 9503 | |
9799 | 9504 | =begin original |
9800 | 9505 | |
9801 | | |
9506 | @. Specify position as byte offset in the internal | |
9802 | 9507 | representation of the packed string. Efficient |
9803 | 9508 | but dangerous. |
9804 | 9509 | |
9805 | 9510 | =end original |
9806 | 9511 | |
9807 | | |
9512 | @. pack された内部表現のバイトオフセットとして位置を指定する。 | |
9808 | 9513 | 効率的ですが危険です。 |
9809 | 9514 | |
9810 | 9515 | =begin original |
9811 | 9516 | |
9812 | 9517 | > sSiIlLqQ Force big-endian byte-order on the type. |
9813 | 9518 | jJfFdDpP (The "big end" touches the construct.) |
9814 | 9519 | |
9815 | 9520 | =end original |
9816 | 9521 | |
9817 | 9522 | > sSiIlLqQ これらの型のバイト順をビッグエンディアンに強制します。 |
9818 | 9523 | jJfFdDpP (「大きい端」が構造に触れています。) |
9819 | 9524 | |
9820 | 9525 | =begin original |
9821 | 9526 | |
9822 | 9527 | < sSiIlLqQ Force little-endian byte-order on the type. |
9823 | 9528 | jJfFdDpP (The "little end" touches the construct.) |
9824 | 9529 | |
9825 | 9530 | =end original |
9826 | 9531 | |
9827 | 9532 | < sSiIlLqQ これらの型のバイト順をリトルエンディアンに強制します。 |
9828 | 9533 | jJfFdDpP (「小さい端」が構造に触れています。) |
9829 | 9534 | |
9830 | 9535 | =begin original |
9831 | 9536 | |
9832 | 9537 | The C<< > >> and C<< < >> modifiers can also be used on C<()> groups |
9833 | 9538 | to force a particular byte-order on all components in that group, |
9834 | 9539 | including all its subgroups. |
9835 | 9540 | |
9836 | 9541 | =end original |
9837 | 9542 | |
9838 | 9543 | C<< > >> と C<< < >> の修飾子は C<()>-グループでも使えます; |
9839 | 9544 | この場合はそのグループと全ての副グループ内の全ての要素を特定のバイト順に |
9840 | 9545 | 強制します。 |
9841 | 9546 | |
9842 | =begin comment | |
9843 | ||
9844 | Larry recalls that the hex and bit string formats (H, h, B, b) were added to | |
9845 | pack for processing data from NASA's Magellan probe. Magellan was in an | |
9846 | elliptical orbit, using the antenna for the radar mapping when close to | |
9847 | Venus and for communicating data back to Earth for the rest of the orbit. | |
9848 | There were two transmission units, but one of these failed, and then the | |
9849 | other developed a fault whereby it would randomly flip the sense of all the | |
9850 | bits. It was easy to automatically detect complete records with the correct | |
9851 | sense, and complete records with all the bits flipped. However, this didn't | |
9852 | recover the records where the sense flipped midway. A colleague of Larry's | |
9853 | was able to pretty much eyeball where the records flipped, so they wrote an | |
9854 | editor named kybble (a pun on the dog food Kibbles 'n Bits) to enable him to | |
9855 | manually correct the records and recover the data. For this purpose pack | |
9856 | gained the hex and bit string format specifiers. | |
9857 | ||
9858 | git shows that they were added to perl 3.0 in patch #44 (Jan 1991, commit | |
9859 | 27e2fb84680b9cc1), but the patch description makes no mention of their | |
9860 | addition, let alone the story behind them. | |
9861 | ||
9862 | =end comment | |
9863 | ||
9864 | 9547 | =begin original |
9865 | 9548 | |
9866 | 9549 | The following rules apply: |
9867 | 9550 | |
9868 | 9551 | =end original |
9869 | 9552 | |
9870 | 9553 | 以下の条件が適用されます: |
9871 | 9554 | |
9872 | 9555 | =over |
9873 | 9556 | |
9874 | 9557 | =item * |
9875 | 9558 | |
9876 | 9559 | =begin original |
9877 | 9560 | |
9878 | 9561 | Each letter may optionally be followed by a number indicating the repeat |
9879 | 9562 | count. A numeric repeat count may optionally be enclosed in brackets, as |
9880 | 9563 | in C<pack("C[80]", @arr)>. The repeat count gobbles that many values from |
9881 | 9564 | the LIST when used with all format types other than C<a>, C<A>, C<Z>, C<b>, |
9882 | 9565 | C<B>, C<h>, C<H>, C<@>, C<.>, C<x>, C<X>, and C<P>, where it means |
9883 | 9566 | something else, described below. Supplying a C<*> for the repeat count |
9884 | 9567 | instead of a number means to use however many items are left, except for: |
9885 | 9568 | |
9886 | 9569 | =end original |
9887 | 9570 | |
9888 | 9571 | これらの文字の後には、繰り返し数を示す数字を付けることができます。 |
9889 | 9572 | 数値の繰り返し数は C<pack "C[80]", @arr> のように大かっこで |
9890 | 9573 | 囲むこともできます。 |
9891 | 9574 | C<a>, C<A>, C<Z>, C<b>, C<B>, C<h>, C<H>, C<@>, C<.>, C<x>, C<X>, C<P> |
9892 | 9575 | 以外の全ての型では、LIST から繰り返し数の値を取り出して使います。 |
9893 | 9576 | 繰り返し数に C<*> を指定すると、以下の例外を除いて、 |
9894 | 9577 | その時点で残っているすべての要素を意味します。 |
9895 | 9578 | |
9896 | 9579 | =over |
9897 | 9580 | |
9898 | 9581 | =item * |
9899 | 9582 | |
9900 | 9583 | =begin original |
9901 | 9584 | |
9902 | 9585 | C<@>, C<x>, and C<X>, where it is equivalent to C<0>. |
9903 | 9586 | |
9904 | 9587 | =end original |
9905 | 9588 | |
9906 | 9589 | C<@>, C<x>, C<X> では C<0> と等価です。 |
9907 | 9590 | |
9908 | 9591 | =item * |
9909 | 9592 | |
9910 | 9593 | =begin original |
9911 | 9594 | |
9912 | 9595 | <.>, where it means relative to the start of the string. |
9913 | 9596 | |
9914 | 9597 | =end original |
9915 | 9598 | |
9916 | 9599 | C<.> では文字列の先頭からの相対位置を意味します。 |
9917 | 9600 | |
9918 | 9601 | =item * |
9919 | 9602 | |
9920 | 9603 | =begin original |
9921 | 9604 | |
9922 | 9605 | C<u>, where it is equivalent to 1 (or 45, which here is equivalent). |
9923 | 9606 | |
9924 | 9607 | =end original |
9925 | 9608 | |
9926 | 9609 | C<u> では 1 (あるいはここでは 45 でも等価です) と等価です。 |
9927 | 9610 | |
9928 | 9611 | =back |
9929 | 9612 | |
9930 | 9613 | =begin original |
9931 | 9614 | |
9932 | 9615 | One can replace a numeric repeat count with a template letter enclosed in |
9933 | 9616 | brackets to use the packed byte length of the bracketed template for the |
9934 | 9617 | repeat count. |
9935 | 9618 | |
9936 | 9619 | =end original |
9937 | 9620 | |
9938 | 9621 | このテンプレートでパックされたバイト長を繰り返し数として使うために、 |
9939 | 9622 | 大かっこで囲まれたテンプレートで数値の繰り返し数を置き換えることが |
9940 | 9623 | できます。 |
9941 | 9624 | |
9942 | 9625 | =begin original |
9943 | 9626 | |
9944 | 9627 | For example, the template C<x[L]> skips as many bytes as in a packed long, |
9945 | 9628 | and the template C<"$t X[$t] $t"> unpacks twice whatever $t (when |
9946 | 9629 | variable-expanded) unpacks. If the template in brackets contains alignment |
9947 | 9630 | commands (such as C<x![d]>), its packed length is calculated as if the |
9948 | 9631 | start of the template had the maximal possible alignment. |
9949 | 9632 | |
9950 | 9633 | =end original |
9951 | 9634 | |
9952 | 9635 | 例えば、テンプレート C<x[L]> は long でパックされたバイト数分だけスキップし、 |
9953 | 9636 | テンプレート C<"$t X[$t] $t"> は $t (変数展開された場合)を |
9954 | 9637 | unpack したものの 2 倍を unpack します。 |
9955 | 9638 | (C<x![d]> のように) 大かっこにアライメントコマンドが含まれている場合、 |
9956 | 9639 | パックされた長さは、テンプレートの先頭で最大限可能なアライメントを |
9957 | 9640 | 持っているものとして計算されます。 |
9958 | 9641 | |
9959 | 9642 | =begin original |
9960 | 9643 | |
9961 | 9644 | When used with C<Z>, a C<*> as the repeat count is guaranteed to add a |
9962 | 9645 | trailing null byte, so the resulting string is always one byte longer than |
9963 | 9646 | the byte length of the item itself. |
9964 | 9647 | |
9965 | 9648 | =end original |
9966 | 9649 | |
9967 | 9650 | C<Z> で、繰り返し数として C<*> が使われた場合、末尾にヌルバイトが |
9968 | 9651 | 保証されるので、パックされた結果は常に要素の C<length> の値より |
9969 | 9652 | 1 大きくなります。 |
9970 | 9653 | |
9971 | 9654 | =begin original |
9972 | 9655 | |
9973 | 9656 | When used with C<@>, the repeat count represents an offset from the start |
9974 | 9657 | of the innermost C<()> group. |
9975 | 9658 | |
9976 | 9659 | =end original |
9977 | 9660 | |
9978 | 9661 | C<@> で使うと、繰り返し数は一番内側の C<()> グループの先頭からのオフセットを |
9979 | 9662 | 表現します。 |
9980 | 9663 | |
9981 | 9664 | =begin original |
9982 | 9665 | |
9983 | 9666 | When used with C<.>, the repeat count determines the starting position to |
9984 | 9667 | calculate the value offset as follows: |
9985 | 9668 | |
9986 | 9669 | =end original |
9987 | 9670 | |
9988 | 9671 | C<.> で使われると、繰り返し数は以下のようにして、 |
9989 | 9672 | 値のオフセットを計算するための開始位置を決定するために使われます。 |
9990 | 9673 | |
9991 | 9674 | =over |
9992 | 9675 | |
9993 | 9676 | =item * |
9994 | 9677 | |
9995 | 9678 | =begin original |
9996 | 9679 | |
9997 | 9680 | If the repeat count is C<0>, it's relative to the current position. |
9998 | 9681 | |
9999 | 9682 | =end original |
10000 | 9683 | |
10001 | 9684 | 繰り返し数が C<0> なら、現在位置からの相対位置となります。 |
10002 | 9685 | |
10003 | 9686 | =item * |
10004 | 9687 | |
10005 | 9688 | =begin original |
10006 | 9689 | |
10007 | 9690 | If the repeat count is C<*>, the offset is relative to the start of the |
10008 | 9691 | packed string. |
10009 | 9692 | |
10010 | 9693 | =end original |
10011 | 9694 | |
10012 | 繰り返し数が C<*> なら、オフセットは pack された文字列の先頭からの | |
9695 | 繰り返し数が C<*> なら、オフセットは pack された文字列の先頭からの相対位置です。 | |
10013 | 相対位置です。 | |
10014 | 9696 | |
10015 | 9697 | =item * |
10016 | 9698 | |
10017 | 9699 | =begin original |
10018 | 9700 | |
10019 | 9701 | And if it's an integer I<n>, the offset is relative to the start of the |
10020 | 9702 | I<n>th innermost C<( )> group, or to the start of the string if I<n> is |
10021 | 9703 | bigger then the group level. |
10022 | 9704 | |
10023 | 9705 | =end original |
10024 | 9706 | |
10025 | 9707 | そして整数 I<n> なら、オフセットは一番内側から I<n> 番目の C<( )> グループの |
10026 | 9708 | 先頭、あるいは I<n> がグループレベルより大きい場合は文字列の先頭からの |
10027 | 9709 | 相対位置です。 |
10028 | 9710 | |
10029 | 9711 | =back |
10030 | 9712 | |
10031 | 9713 | =begin original |
10032 | 9714 | |
10033 | 9715 | The repeat count for C<u> is interpreted as the maximal number of bytes |
10034 | 9716 | to encode per line of output, with 0, 1 and 2 replaced by 45. The repeat |
10035 | 9717 | count should not be more than 65. |
10036 | 9718 | |
10037 | 9719 | =end original |
10038 | 9720 | |
10039 | 9721 | C<u> での繰り返し回数は、出力行毎に最大何バイトまでをエンコードするかを |
10040 | 9722 | 示します; 0, 1, 2 は 45 として扱われます。 |
10041 | 9723 | 繰り返し数は 65 を超えてはなりません。 |
10042 | 9724 | |
10043 | 9725 | =item * |
10044 | 9726 | |
10045 | 9727 | =begin original |
10046 | 9728 | |
10047 | 9729 | The C<a>, C<A>, and C<Z> types gobble just one value, but pack it as a |
10048 | 9730 | string of length count, padding with nulls or spaces as needed. When |
10049 | 9731 | unpacking, C<A> strips trailing whitespace and nulls, C<Z> strips everything |
10050 | 9732 | after the first null, and C<a> returns data with no stripping at all. |
10051 | 9733 | |
10052 | 9734 | =end original |
10053 | 9735 | |
10054 | 9736 | C<a>, C<A>, C<Z> という型を使うと、値を一つだけ取り出して使いますが、 |
10055 | 9737 | 繰り返し数で示す長さの文字列となるように、必要に応じてヌル文字か |
10056 | 9738 | スペース文字を付け足します。 |
10057 | 9739 | unpack するとき、C<A> は後続の空白やヌル文字を取り除きます; C<Z> は最初の |
10058 | 9740 | ヌル文字以降の全てを取り除きます; C<a> はデータを取り除くことなく |
10059 | 9741 | そのまま返します。 |
10060 | 9742 | |
10061 | 9743 | =begin original |
10062 | 9744 | |
10063 | 9745 | If the value to pack is too long, the result is truncated. If it's too |
10064 | 9746 | long and an explicit count is provided, C<Z> packs only C<$count-1> bytes, |
10065 | 9747 | followed by a null byte. Thus C<Z> always packs a trailing null, except |
10066 | 9748 | when the count is 0. |
10067 | 9749 | |
10068 | 9750 | =end original |
10069 | 9751 | |
10070 | 9752 | pack する値が長すぎる場合、結果は切り詰められます。 |
10071 | 9753 | 長すぎてかつ明示的に個数が指定されている場合、 |
10072 | 9754 | C<Z> は C<$count-1> バイトまで pack し、その後にヌルバイトがつきます。 |
10073 | 9755 | 従って、C<Z> は、繰り返し数が 0 の場合を除いて、常に末尾にヌルバイトが |
10074 | 9756 | つきます。 |
10075 | 9757 | |
10076 | 9758 | =item * |
10077 | 9759 | |
10078 | 9760 | =begin original |
10079 | 9761 | |
10080 | 9762 | Likewise, the C<b> and C<B> formats pack a string that's that many bits long. |
10081 | 9763 | Each such format generates 1 bit of the result. These are typically followed |
10082 | 9764 | by a repeat count like C<B8> or C<B64>. |
10083 | 9765 | |
10084 | 9766 | =end original |
10085 | 9767 | |
10086 | 9768 | 同様に、C<b> や C<B> は、繰り返し数で示すビット長のビット列に pack します。 |
10087 | 9769 | これらの各文字は結果の 1 ビットを生成します。 |
10088 | 9770 | これらは典型的には C<B8> や C<B64> のような繰り返しカウントが引き続きます。 |
10089 | 9771 | |
10090 | 9772 | =begin original |
10091 | 9773 | |
10092 | 9774 | Each result bit is based on the least-significant bit of the corresponding |
10093 | 9775 | input character, i.e., on C<ord($char)%2>. In particular, characters C<"0"> |
10094 | 9776 | and C<"1"> generate bits 0 and 1, as do characters C<"\000"> and C<"\001">. |
10095 | 9777 | |
10096 | 9778 | =end original |
10097 | 9779 | |
10098 | 9780 | 結果ビットのそれぞれは対応する入力文字の最下位ビットを基にします |
10099 | 9781 | (つまり C<ord($char)%2>)。 |
10100 | 9782 | 特に、文字 C<"0"> と C<"1"> は文字 C<"\000"> と C<"\001"> と同様に、 |
10101 | 9783 | ビット 0 と 1 を生成します。 |
10102 | 9784 | |
10103 | 9785 | =begin original |
10104 | 9786 | |
10105 | 9787 | Starting from the beginning of the input string, each 8-tuple |
10106 | 9788 | of characters is converted to 1 character of output. With format C<b>, |
10107 | 9789 | the first character of the 8-tuple determines the least-significant bit of a |
10108 | 9790 | character; with format C<B>, it determines the most-significant bit of |
10109 | 9791 | a character. |
10110 | 9792 | |
10111 | 9793 | =end original |
10112 | 9794 | |
10113 | pack() の入力文字列の先頭から始めて、8 タプル毎に 1 文字の出力に | |
9795 | pack() の入力文字列の先頭から始めて、8 タプル毎に 1 文字の出力に | |
9796 | 変換されます。 | |
10114 | 9797 | C<b> フォーマットでは 8 タプルの最初の文字が出力の最下位ビットとなります; |
10115 | 9798 | C<B> フォーマットでは出力の最上位ビットとなります。 |
10116 | 9799 | |
10117 | 9800 | =begin original |
10118 | 9801 | |
10119 | 9802 | If the length of the input string is not evenly divisible by 8, the |
10120 | 9803 | remainder is packed as if the input string were padded by null characters |
10121 | 9804 | at the end. Similarly during unpacking, "extra" bits are ignored. |
10122 | 9805 | |
10123 | 9806 | =end original |
10124 | 9807 | |
10125 | 9808 | もし入力文字列の長さが 8 で割り切れない場合、余りの部分は入力文字列の |
10126 | 9809 | 最後にヌル文字がパッディングされているものとしてパックされます。 |
10127 | 9810 | 同様に、unpack 中は「余分な」ビットは無視されます。 |
10128 | 9811 | |
10129 | 9812 | =begin original |
10130 | 9813 | |
10131 | 9814 | If the input string is longer than needed, remaining characters are ignored. |
10132 | 9815 | |
10133 | 9816 | =end original |
10134 | 9817 | |
10135 | 9818 | 入力文字列が必要な分よりも長い場合、余分な文字は無視されます。 |
10136 | 9819 | |
10137 | 9820 | =begin original |
10138 | 9821 | |
10139 | 9822 | A C<*> for the repeat count uses all characters of the input field. |
10140 | 9823 | On unpacking, bits are converted to a string of C<0>s and C<1>s. |
10141 | 9824 | |
10142 | 9825 | =end original |
10143 | 9826 | |
10144 | 9827 | 繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が |
10145 | 9828 | 使われます。 |
10146 | 9829 | unpack 時にはビット列は C<0> と C<1> の文字列に変換されます。 |
10147 | 9830 | |
10148 | 9831 | =item * |
10149 | 9832 | |
10150 | 9833 | =begin original |
10151 | 9834 | |
10152 | 9835 | The C<h> and C<H> formats pack a string that many nybbles (4-bit groups, |
10153 | 9836 | representable as hexadecimal digits, C<"0".."9"> C<"a".."f">) long. |
10154 | 9837 | |
10155 | 9838 | =end original |
10156 | 9839 | |
10157 | 9840 | C<h> や C<H> は、多ニブル長(16 進文字である C<"0".."9"> C<"a".."f"> で |
10158 | 9841 | 表現可能な 4 ビットグループ)のニブル列に pack します。 |
10159 | 9842 | |
10160 | 9843 | =begin original |
10161 | 9844 | |
10162 | 9845 | For each such format, pack() generates 4 bits of result. |
10163 | 9846 | With non-alphabetical characters, the result is based on the 4 least-significant |
10164 | 9847 | bits of the input character, i.e., on C<ord($char)%16>. In particular, |
10165 | 9848 | characters C<"0"> and C<"1"> generate nybbles 0 and 1, as do bytes |
10166 | 9849 | C<"\000"> and C<"\001">. For characters C<"a".."f"> and C<"A".."F">, the result |
10167 | 9850 | is compatible with the usual hexadecimal digits, so that C<"a"> and |
10168 | 9851 | C<"A"> both generate the nybble C<0xA==10>. Use only these specific hex |
10169 | 9852 | characters with this format. |
10170 | 9853 | |
10171 | 9854 | =end original |
10172 | 9855 | |
10173 | 9856 | このようなフォーマット文字のそれぞれについて、pack() は |
10174 | 9857 | 結果の 4 ビットを生成します。 |
10175 | 9858 | 英字でない文字の場合、結果は入力文字の下位 4 ビットを |
10176 | 9859 | 基にします(つまり C<ord($char)%16>)。 |
10177 | 9860 | 特に、文字 C<"0"> と C<"1"> はバイト C<"\000"> と C<"\001"> と同様に |
10178 | 9861 | ニブル 0 と 1 を生成します。 |
10179 | 文字 C<"a".."f"> と C<"A".."F"> の場合は結果は通常の | |
9862 | 文字 C<"a".."f"> と C<"A".."F"> の場合は結果は通常の | |
10180 | な | |
9863 | 16 進数と同じ結果になりますので、C<"a"> と C<"A"> はどちらも | |
9864 | ニブル C<0xa==10> を生成します。 | |
10181 | 9865 | これらの 16 進文字はこの特定のフォーマットでだけ使ってください。 |
10182 | 9866 | |
10183 | 9867 | =begin original |
10184 | 9868 | |
10185 | 9869 | Starting from the beginning of the template to pack(), each pair |
10186 | 9870 | of characters is converted to 1 character of output. With format C<h>, the |
10187 | 9871 | first character of the pair determines the least-significant nybble of the |
10188 | 9872 | output character; with format C<H>, it determines the most-significant |
10189 | 9873 | nybble. |
10190 | 9874 | |
10191 | 9875 | =end original |
10192 | 9876 | |
10193 | 9877 | pack() のテンプレートの先頭から始めて、2 文字毎に 1 文字の出力に |
10194 | 9878 | 変換されます。 |
10195 | 9879 | C<h> フォーマットでは 1 文字目が出力の最下位ニブルとなり、 |
10196 | 9880 | C<H> フォーマットでは出力の最上位ニブルとなります。 |
10197 | 9881 | |
10198 | 9882 | =begin original |
10199 | 9883 | |
10200 | 9884 | If the length of the input string is not even, it behaves as if padded by |
10201 | 9885 | a null character at the end. Similarly, "extra" nybbles are ignored during |
10202 | 9886 | unpacking. |
10203 | 9887 | |
10204 | 9888 | =end original |
10205 | 9889 | |
10206 | 9890 | 入力文字列の長さが偶数でない場合、最後にヌル文字でパッディングされて |
10207 | 9891 | いるかのように振る舞います。 |
10208 | 9892 | 同様に、unpack 中は「余分な」ニブルは無視されます。 |
10209 | 9893 | |
10210 | 9894 | =begin original |
10211 | 9895 | |
10212 | 9896 | If the input string is longer than needed, extra characters are ignored. |
10213 | 9897 | |
10214 | 9898 | =end original |
10215 | 9899 | |
10216 | 9900 | 入力文字列が必要な分より長い場合、余分な部分は無視されます。 |
10217 | 9901 | |
10218 | 9902 | =begin original |
10219 | 9903 | |
10220 | 9904 | A C<*> for the repeat count uses all characters of the input field. For |
10221 | 9905 | unpack(), nybbles are converted to a string of hexadecimal digits. |
10222 | 9906 | |
10223 | 9907 | =end original |
10224 | 9908 | |
10225 | 繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が | |
9909 | 繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が | |
9910 | 使われます。 | |
10226 | 9911 | unpack() 時にはニブルは 16 進数の文字列に変換されます。 |
10227 | 9912 | |
10228 | 9913 | =item * |
10229 | 9914 | |
10230 | 9915 | =begin original |
10231 | 9916 | |
10232 | 9917 | The C<p> format packs a pointer to a null-terminated string. You are |
10233 | 9918 | responsible for ensuring that the string is not a temporary value, as that |
10234 | 9919 | could potentially get deallocated before you got around to using the packed |
10235 | 9920 | result. The C<P> format packs a pointer to a structure of the size indicated |
10236 | 9921 | by the length. A null pointer is created if the corresponding value for |
10237 | 9922 | C<p> or C<P> is C<undef>; similarly with unpack(), where a null pointer |
10238 | 9923 | unpacks into C<undef>. |
10239 | 9924 | |
10240 | 9925 | =end original |
10241 | 9926 | |
10242 | 9927 | C<p> は、ヌル文字終端文字列へのポインタを pack します。 |
10243 | 9928 | 文字列が一時的な値でない(つまり pack された結果を使う前に文字列が |
10244 | 9929 | 解放されない) ことに責任を持つ必要があります。 |
10245 | 9930 | C<P> は、指定した長さの構造体へのポインタを pack します。 |
10246 | 9931 | C<p> または C<P> に対応する値が C<undef> だった場合、 |
10247 | 9932 | ヌルポインタが作成されます; ヌルポインタが C<undef> に unpack される |
10248 | 9933 | unpack() と同様です。 |
10249 | 9934 | |
10250 | 9935 | =begin original |
10251 | 9936 | |
10252 | 9937 | If your system has a strange pointer size--meaning a pointer is neither as |
10253 | 9938 | big as an int nor as big as a long--it may not be possible to pack or |
10254 | 9939 | unpack pointers in big- or little-endian byte order. Attempting to do |
10255 | 9940 | so raises an exception. |
10256 | 9941 | |
10257 | 9942 | =end original |
10258 | 9943 | |
10259 | 9944 | システムのポインタが変わったサイズの場合--つまり、int の大きさでも |
10260 | 9945 | long の大きさでもない場合--ポインタをビッグエンディアンやリトルエンディアンの |
10261 | 9946 | バイト順で pack や unpack することはできません。 |
10262 | 9947 | そうしようとすると例外が発生します。 |
10263 | 9948 | |
10264 | 9949 | =item * |
10265 | 9950 | |
10266 | 9951 | =begin original |
10267 | 9952 | |
10268 | 9953 | The C</> template character allows packing and unpacking of a sequence of |
10269 | 9954 | items where the packed structure contains a packed item count followed by |
10270 | 9955 | the packed items themselves. This is useful when the structure you're |
10271 | 9956 | unpacking has encoded the sizes or repeat counts for some of its fields |
10272 | 9957 | within the structure itself as separate fields. |
10273 | 9958 | |
10274 | 9959 | =end original |
10275 | 9960 | |
10276 | 9961 | C</> テンプレート文字は、アイテムの数の後にアイテムそのものが入っている形の |
10277 | 9962 | アイテム列を pack 及び unpack します。 |
10278 | 9963 | これは、unpack したい構造体が、サイズや繰り返し数が構造体自身の中に |
10279 | 9964 | 独立したフィールドとしてエンコードされている場合に有効です。 |
10280 | 9965 | |
10281 | 9966 | =begin original |
10282 | 9967 | |
10283 | 9968 | For C<pack>, you write I<length-item>C</>I<sequence-item>, and the |
10284 | 9969 | I<length-item> describes how the length value is packed. Formats likely |
10285 | 9970 | to be of most use are integer-packing ones like C<n> for Java strings, |
10286 | 9971 | C<w> for ASN.1 or SNMP, and C<N> for Sun XDR. |
10287 | 9972 | |
10288 | 9973 | =end original |
10289 | 9974 | |
10290 | 9975 | C<pack> では I<length-item>C</>I<string-item> の形になり、 |
10291 | 9976 | I<length-item> は長さの値がどのように pack されているかを指定します。 |
10292 | 9977 | もっともよく使われるのは Java 文字列 のための C<n>、ASN.1 や SNMP のための |
10293 | 9978 | C<w>、Sun XDR のための C<N> といった整数型です。 |
10294 | 9979 | |
10295 | 9980 | =begin original |
10296 | 9981 | |
10297 | 9982 | For C<pack>, I<sequence-item> may have a repeat count, in which case |
10298 | 9983 | the minimum of that and the number of available items is used as the argument |
10299 | 9984 | for I<length-item>. If it has no repeat count or uses a '*', the number |
10300 | 9985 | of available items is used. |
10301 | 9986 | |
10302 | 9987 | =end original |
10303 | 9988 | |
10304 | 9989 | C<pack> では、I<sequence-item> は繰り返し数を持つことがあり、その場合は |
10305 | 9990 | その最小値と利用可能なアイテムの数は I<length-item> のための引数として |
10306 | 9991 | 使われます。 |
10307 | 9992 | 繰り返し数がなかったり、'*' を使うと、利用可能なアイテムの数が使われます。 |
10308 | 9993 | |
10309 | 9994 | =begin original |
10310 | 9995 | |
10311 | 9996 | For C<unpack>, an internal stack of integer arguments unpacked so far is |
10312 | 9997 | used. You write C</>I<sequence-item> and the repeat count is obtained by |
10313 | 9998 | popping off the last element from the stack. The I<sequence-item> must not |
10314 | 9999 | have a repeat count. |
10315 | 10000 | |
10316 | 10001 | =end original |
10317 | 10002 | |
10318 | 10003 | C<unpack> では、今まで unpack した数値引数の内部スタックが使われます。 |
10319 | 10004 | C</>I<sequence-item> と書いて、繰り返し数はスタックから最後の要素を |
10320 | 10005 | 取り出すことで得ます。 |
10321 | 10006 | I<sequence-item> は繰り返し数を持っていてはいけません。 |
10322 | 10007 | |
10323 | 10008 | =begin original |
10324 | 10009 | |
10325 | 10010 | If I<sequence-item> refers to a string type (C<"A">, C<"a">, or C<"Z">), |
10326 | 10011 | the I<length-item> is the string length, not the number of strings. With |
10327 | 10012 | an explicit repeat count for pack, the packed string is adjusted to that |
10328 | 10013 | length. For example: |
10329 | 10014 | |
10330 | 10015 | =end original |
10331 | 10016 | |
10332 | 10017 | I<sequence-item> が文字列型 (C<"A">, C<"a">, C<"Z">) を参照している場合、 |
10333 | 10018 | I<length-item> は文字列の数ではなく、文字列の長さです。 |
10334 | 10019 | pack で明示的な繰り返し数があると、pack された文字列は与えられた |
10335 | 10020 | 長さに調整されます。 |
10336 | 10021 | 例えば: |
10337 | 10022 | |
10338 | This code: gives this result: | |
10023 | This code: gives this result: | |
10024 | ||
10025 | unpack("W/a", "\004Gurusamy") ("Guru") | |
10026 | unpack("a3/A A*", "007 Bond J ") (" Bond", "J") | |
10027 | unpack("a3 x2 /A A*", "007: Bond, J.") ("Bond, J", ".") | |
10339 | 10028 | |
10340 | | |
10029 | pack("n/a* w/a","hello,","world") "\000\006hello,\005world" | |
10341 | | |
10030 | pack("a/W2", ord("a") .. ord("z")) "2ab" | |
10342 | unpack("a3 x2 /A A*", "007: Bond, J.") ("Bond, J", ".") | |
10343 | 10031 | |
10344 | pack("n/a* w/a","hello,","world") "\000\006hello,\005world" | |
10345 | pack("a/W2", ord("a") .. ord("z")) "2ab" | |
10346 | ||
10347 | 10032 | =begin original |
10348 | 10033 | |
10349 | 10034 | The I<length-item> is not returned explicitly from C<unpack>. |
10350 | 10035 | |
10351 | 10036 | =end original |
10352 | 10037 | |
10353 | 10038 | I<length-item> は C<unpack> から明示的には返されません。 |
10354 | 10039 | |
10355 | 10040 | =begin original |
10356 | 10041 | |
10357 | 10042 | Supplying a count to the I<length-item> format letter is only useful with |
10358 | 10043 | C<A>, C<a>, or C<Z>. Packing with a I<length-item> of C<a> or C<Z> may |
10359 | 10044 | introduce C<"\000"> characters, which Perl does not regard as legal in |
10360 | 10045 | numeric strings. |
10361 | 10046 | |
10362 | 10047 | =end original |
10363 | 10048 | |
10364 | 10049 | I<length-item> 文字に繰り返し数をつけるのは、 |
10365 | 10050 | 文字が C<A>, C<a>, C<Z> でない限りは有用ではありません。 |
10366 | 10051 | C<a> や C<Z> を I<length-item> として pack すると C<"\000"> 文字が |
10367 | 10052 | 出力されることがあり、Perl はこれを有効な数値文字列として認識しません。 |
10368 | 10053 | |
10369 | 10054 | =item * |
10370 | 10055 | |
10371 | 10056 | =begin original |
10372 | 10057 | |
10373 | 10058 | The integer types C<s>, C<S>, C<l>, and C<L> may be |
10374 | 10059 | followed by a C<!> modifier to specify native shorts or |
10375 | 10060 | longs. As shown in the example above, a bare C<l> means |
10376 | 10061 | exactly 32 bits, although the native C<long> as seen by the local C compiler |
10377 | 10062 | may be larger. This is mainly an issue on 64-bit platforms. You can |
10378 | 10063 | see whether using C<!> makes any difference this way: |
10379 | 10064 | |
10380 | 10065 | =end original |
10381 | 10066 | |
10382 | 10067 | C<s>, C<S>, C<l>, C<L> の整数タイプに引き続いて C<!> 修飾子を |
10383 | 10068 | つけることで、ネイティブの short や long を指定できます。 |
10384 | 10069 | 上述のように、C<l> は正確に 32 ビットですが、ネイティブな |
10385 | 10070 | (ローカルな C コンパイラによる)C<long> はもっと大きいかもしれません。 |
10386 | 10071 | これは主に 64 ビットプラットフォームで意味があります。 |
10387 | 10072 | C<!> を使うことによって違いがあるかどうかは以下のようにして調べられます: |
10388 | 10073 | |
10389 | 10074 | printf "format s is %d, s! is %d\n", |
10390 | 10075 | length pack("s"), length pack("s!"); |
10391 | 10076 | |
10392 | 10077 | printf "format l is %d, l! is %d\n", |
10393 | 10078 | length pack("l"), length pack("l!"); |
10394 | 10079 | |
10395 | 10080 | =begin original |
10396 | 10081 | |
10397 | 10082 | C<i!> and C<I!> are also allowed, but only for completeness' sake: |
10398 | 10083 | they are identical to C<i> and C<I>. |
10399 | 10084 | |
10400 | 10085 | =end original |
10401 | 10086 | |
10402 | 10087 | C<i!> と C<I!> も動作しますが、単に完全性のためだけです; |
10403 | 10088 | これは C<i> 及び C<I> と同じです。 |
10404 | 10089 | |
10405 | 10090 | =begin original |
10406 | 10091 | |
10407 | 10092 | The actual sizes (in bytes) of native shorts, ints, longs, and long |
10408 | 10093 | longs on the platform where Perl was built are also available from |
10409 | 10094 | the command line: |
10410 | 10095 | |
10411 | 10096 | =end original |
10412 | 10097 | |
10413 | 10098 | Perl がビルドされたプラットフォームでの short, int, long, long long の |
10414 | 10099 | 実際の(バイト数での)サイズはコマンドラインから: |
10415 | 10100 | |
10416 | 10101 | $ perl -V:{short,int,long{,long}}size |
10417 | 10102 | shortsize='2'; |
10418 | 10103 | intsize='4'; |
10419 | 10104 | longsize='4'; |
10420 | 10105 | longlongsize='8'; |
10421 | 10106 | |
10422 | 10107 | =begin original |
10423 | 10108 | |
10424 | 10109 | or programmatically via the C<Config> module: |
10425 | 10110 | |
10426 | 10111 | =end original |
10427 | 10112 | |
10428 | 10113 | あるいは C<Config> モジュールからプログラムで: |
10429 | 10114 | |
10430 | 10115 | use Config; |
10431 | 10116 | print $Config{shortsize}, "\n"; |
10432 | 10117 | print $Config{intsize}, "\n"; |
10433 | 10118 | print $Config{longsize}, "\n"; |
10434 | 10119 | print $Config{longlongsize}, "\n"; |
10435 | 10120 | |
10436 | 10121 | =begin original |
10437 | 10122 | |
10438 | 10123 | C<$Config{longlongsize}> is undefined on systems without |
10439 | 10124 | long long support. |
10440 | 10125 | |
10441 | 10126 | =end original |
10442 | 10127 | |
10443 | 10128 | システムが long long に対応していない場合は C<$Config{longlongsize}> は |
10444 | 10129 | 未定義値になります。 |
10445 | 10130 | |
10446 | 10131 | =item * |
10447 | 10132 | |
10448 | 10133 | =begin original |
10449 | 10134 | |
10450 | 10135 | The integer formats C<s>, C<S>, C<i>, C<I>, C<l>, C<L>, C<j>, and C<J> are |
10451 | 10136 | inherently non-portable between processors and operating systems because |
10452 | 10137 | they obey native byteorder and endianness. For example, a 4-byte integer |
10453 | 10138 | 0x12345678 (305419896 decimal) would be ordered natively (arranged in and |
10454 | 10139 | handled by the CPU registers) into bytes as |
10455 | 10140 | |
10456 | 10141 | =end original |
10457 | 10142 | |
10458 | 10143 | 整数フォーマット C<s>, C<S>, C<i>, C<I>, C<l>, C<L>, C<j>, C<J> は |
10459 | 10144 | ネイティブなバイト順序とエンディアンに従っているため、 |
10460 | 10145 | 本質的にプロセッサ間や OS 間で移植性がありません。 |
10461 | 10146 | 例えば 4 バイトの整数 0x12345678 (10 進数では 305419896) は |
10462 | 10147 | 内部では(CPU レジスタによって変換され扱われる形では) |
10463 | 10148 | 以下のようなバイト列に並べられます: |
10464 | 10149 | |
10465 | 10150 | 0x12 0x34 0x56 0x78 # big-endian |
10466 | 10151 | 0x78 0x56 0x34 0x12 # little-endian |
10467 | 10152 | |
10468 | 10153 | =begin original |
10469 | 10154 | |
10470 | 10155 | Basically, Intel and VAX CPUs are little-endian, while everybody else, |
10471 | 10156 | including Motorola m68k/88k, PPC, Sparc, HP PA, Power, and Cray, are |
10472 | 10157 | big-endian. Alpha and MIPS can be either: Digital/Compaq uses (well, used) |
10473 | 10158 | them in little-endian mode, but SGI/Cray uses them in big-endian mode. |
10474 | 10159 | |
10475 | 10160 | =end original |
10476 | 10161 | |
10477 | 10162 | 基本的に、Intel と VAX の CPU はリトルエンディアンです; 一方、 |
10478 | 10163 | Motorola m68k/88k, PPC, Sparc, HP PA, Power, Cray などを含むその他の全ては |
10479 | 10164 | ビッグエンディアンです。 |
10480 | 10165 | Alpha と MIPS は両方ともあります: Digital/Compaq はリトルエンディアンモードで |
10481 | 10166 | 使っています (えーと、いました) が、SGI/Cray はビッグエンディアンモードで |
10482 | 10167 | 使っています。 |
10483 | 10168 | |
10484 | 10169 | =begin original |
10485 | 10170 | |
10486 | 10171 | The names I<big-endian> and I<little-endian> are comic references to the |
10487 | 10172 | egg-eating habits of the little-endian Lilliputians and the big-endian |
10488 | 10173 | Blefuscudians from the classic Jonathan Swift satire, I<Gulliver's Travels>. |
10489 | 10174 | This entered computer lingo via the paper "On Holy Wars and a Plea for |
10490 | 10175 | Peace" by Danny Cohen, USC/ISI IEN 137, April 1, 1980. |
10491 | 10176 | |
10492 | 10177 | =end original |
10493 | 10178 | |
10494 | I<ビッグエンディアン> と I<リトルエンディアン> の名前は | |
10179 | I<ビッグエンディアン> と I<リトルエンディアン> の名前は | |
10495 | ||
10180 | 古典である「ガリバー旅行記」とリリパット族の卵を食べる習慣から | |
10496 | 小さい方からむくリリパット国と大きい方からむくブレフスキュ国から | |
10497 | 10181 | 取られています。 |
10498 | 10182 | "On Holy Wars and a Plea for Peace" by Danny Cohen, USC/ISI IEN 137, |
10499 | 10183 | April 1, 1980 の文書からコンピュータ用語として取り入れられました。 |
10500 | 10184 | |
10501 | 10185 | =begin original |
10502 | 10186 | |
10503 | 10187 | Some systems may have even weirder byte orders such as |
10504 | 10188 | |
10505 | 10189 | =end original |
10506 | 10190 | |
10507 | 10191 | 以下のような、さらに変わったバイト順序を持つシステムもあるかもしれません: |
10508 | 10192 | |
10509 | 10193 | 0x56 0x78 0x12 0x34 |
10510 | 10194 | 0x34 0x12 0x78 0x56 |
10511 | 10195 | |
10512 | 10196 | =begin original |
10513 | 10197 | |
10514 | 10198 | You can determine your system endianness with this incantation: |
10515 | 10199 | |
10516 | 10200 | =end original |
10517 | 10201 | |
10518 | 10202 | システムの設定は以下のようにして調べられます: |
10519 | 10203 | |
10520 | 10204 | printf("%#02x ", $_) for unpack("W*", pack L=>0x12345678); |
10521 | 10205 | |
10522 | 10206 | =begin original |
10523 | 10207 | |
10524 | 10208 | The byteorder on the platform where Perl was built is also available |
10525 | 10209 | via L<Config>: |
10526 | 10210 | |
10527 | 10211 | =end original |
10528 | 10212 | |
10529 | 10213 | Perl がビルドされたプラットフォームでのバイト順序は |
10530 | 10214 | L<Config> 経由か: |
10531 | 10215 | |
10532 | 10216 | use Config; |
10533 | 10217 | print "$Config{byteorder}\n"; |
10534 | 10218 | |
10535 | 10219 | =begin original |
10536 | 10220 | |
10537 | 10221 | or from the command line: |
10538 | 10222 | |
10539 | 10223 | =end original |
10540 | 10224 | |
10541 | 10225 | あるいはコマンドラインで: |
10542 | 10226 | |
10543 | 10227 | $ perl -V:byteorder |
10544 | 10228 | |
10545 | 10229 | =begin original |
10546 | 10230 | |
10547 | 10231 | Byteorders C<"1234"> and C<"12345678"> are little-endian; C<"4321"> |
10548 | 10232 | and C<"87654321"> are big-endian. |
10549 | 10233 | |
10550 | 10234 | =end original |
10551 | 10235 | |
10552 | 10236 | C<"1234"> と C<"12345678"> はリトルエンディアンです; |
10553 | 10237 | C<"4321"> と C<"87654321"> はビッグエンディアンです。 |
10554 | 10238 | |
10555 | 10239 | =begin original |
10556 | 10240 | |
10557 | 10241 | For portably packed integers, either use the formats C<n>, C<N>, C<v>, |
10558 | 10242 | and C<V> or else use the C<< > >> and C<< < >> modifiers described |
10559 | 10243 | immediately below. See also L<perlport>. |
10560 | 10244 | |
10561 | 10245 | =end original |
10562 | 10246 | |
10563 | 10247 | 移植性のあるパック化された整数がほしい場合は、 |
10564 | 10248 | C<n>, C<N>, C<v>, C<V> フォーマットを使うか、 |
10565 | 10249 | 直後で説明する C<< > >> と C<< < >> の修飾子が使えます。 |
10566 | 10250 | L<perlport> も参照してください。 |
10567 | 10251 | |
10568 | 10252 | =item * |
10569 | 10253 | |
10570 | 10254 | =begin original |
10571 | 10255 | |
10572 | Starting with Perl 5. | |
10256 | Starting with Perl 5.9.2, integer and floating-point formats, along with | |
10573 | 10257 | the C<p> and C<P> formats and C<()> groups, may all be followed by the |
10574 | 10258 | C<< > >> or C<< < >> endianness modifiers to respectively enforce big- |
10575 | 10259 | or little-endian byte-order. These modifiers are especially useful |
10576 | 10260 | given how C<n>, C<N>, C<v>, and C<V> don't cover signed integers, |
10577 | 10261 | 64-bit integers, or floating-point values. |
10578 | 10262 | |
10579 | 10263 | =end original |
10580 | 10264 | |
10581 | Perl 5. | |
10265 | Perl 5.9.2 から、C<p> と C<P> フォーマットや C<()> グループと同様、 | |
10582 | 10266 | 全ての整数と浮動小数点数のフォーマットは、C<< > >> や C<< < >> の |
10583 | 10267 | エンディアン修飾子をつけることで、それぞれ |
10584 | 10268 | ビッグエンディアンとリトルエンディアンに強制させることができます。 |
10585 | 10269 | C<n>, C<N>, C<v>, C<V> は符号付き整数、64 ビット整数、浮動小数点数に |
10586 | 10270 | 対応していないので、これは特に有用です。 |
10587 | 10271 | |
10588 | 10272 | =begin original |
10589 | 10273 | |
10590 | 10274 | Here are some concerns to keep in mind when using an endianness modifier: |
10591 | 10275 | |
10592 | 10276 | =end original |
10593 | 10277 | |
10594 | 10278 | エンディアン修飾子を使うときに心に留めておくべきことを記します: |
10595 | 10279 | |
10596 | 10280 | =over |
10597 | 10281 | |
10598 | 10282 | =item * |
10599 | 10283 | |
10600 | 10284 | =begin original |
10601 | 10285 | |
10602 | 10286 | Exchanging signed integers between different platforms works only |
10603 | 10287 | when all platforms store them in the same format. Most platforms store |
10604 | 10288 | signed integers in two's-complement notation, so usually this is not an issue. |
10605 | 10289 | |
10606 | 10290 | =end original |
10607 | 10291 | |
10608 | 10292 | 異なったプラットフォームで符号付き整数を交換することは、全ての |
10609 | 10293 | プラットフォームで同じフォーマットで保存されている場合にのみうまくいきます。 |
10610 | 10294 | ほとんどのプラットフォームでは符号付き整数は 2 の補数記法で保存するので、 |
10611 | 10295 | 普通はこれは問題になりません。 |
10612 | 10296 | |
10613 | 10297 | =item * |
10614 | 10298 | |
10615 | 10299 | =begin original |
10616 | 10300 | |
10617 | 10301 | The C<< > >> or C<< < >> modifiers can only be used on floating-point |
10618 | 10302 | formats on big- or little-endian machines. Otherwise, attempting to |
10619 | 10303 | use them raises an exception. |
10620 | 10304 | |
10621 | 10305 | =end original |
10622 | 10306 | |
10623 | 10307 | C<< > >> や C<< < >> の修飾子はビッグエンディアンやリトルエンディアンの |
10624 | 10308 | マシンでの浮動小数点フォーマットでのみ使えます。 |
10625 | 10309 | それ以外では、そのようなことをすると例外が発生します。 |
10626 | 10310 | |
10627 | 10311 | =item * |
10628 | 10312 | |
10629 | 10313 | =begin original |
10630 | 10314 | |
10631 | 10315 | Forcing big- or little-endian byte-order on floating-point values for |
10632 | 10316 | data exchange can work only if all platforms use the same |
10633 | 10317 | binary representation such as IEEE floating-point. Even if all |
10634 | 10318 | platforms are using IEEE, there may still be subtle differences. Being able |
10635 | 10319 | to use C<< > >> or C<< < >> on floating-point values can be useful, |
10636 | 10320 | but also dangerous if you don't know exactly what you're doing. |
10637 | 10321 | It is not a general way to portably store floating-point values. |
10638 | 10322 | |
10639 | 10323 | =end original |
10640 | 10324 | |
10641 | 10325 | データ交換のために浮動小数点数のバイト順をビッグエンディアンかリトル |
10642 | 10326 | エンディアンに強制することは、全てのプラットフォームが |
10643 | 10327 | IEEE 浮動小数点フォーマットのような同じバイナリ表現の場合にのみ |
10644 | 10328 | うまくいきます。 |
10645 | 10329 | たとえ全てのプラットフォームが IEEE を使っていても、そこには微妙な違いが |
10646 | 10330 | あるかもしれません。 |
10647 | 浮動小数点数に C<< > >> や C<< < >> が使えることは便利な場合が | |
10331 | 浮動小数点数に C<< > >> や C<< < >> が使えることは便利な場合が | |
10648 | もし自分が何をしているかを正確に理解していなければ、 | |
10332 | ありますが、もし自分が何をしているかを正確に理解していなければ、 | |
10333 | 危険です。 | |
10649 | 10334 | 移植性のある浮動小数点数の保存のための一般的な方法はありません。 |
10650 | 10335 | |
10651 | 10336 | =item * |
10652 | 10337 | |
10653 | 10338 | =begin original |
10654 | 10339 | |
10655 | 10340 | When using C<< > >> or C<< < >> on a C<()> group, this affects |
10656 | 10341 | all types inside the group that accept byte-order modifiers, |
10657 | 10342 | including all subgroups. It is silently ignored for all other |
10658 | 10343 | types. You are not allowed to override the byte-order within a group |
10659 | 10344 | that already has a byte-order modifier suffix. |
10660 | 10345 | |
10661 | 10346 | =end original |
10662 | 10347 | |
10663 | 10348 | C<()> グループで C<< > >> や C<< < >> を使うと、これは、副グループを |
10664 | 10349 | 含む全ての型のうち、バイト順修飾子を受け入れる全てのものに影響与えます。 |
10665 | 10350 | その他の型については沈黙のうちに無視されます。 |
10666 | 10351 | 既にバイト順接尾辞を持っているグループ内のバイト順を上書きすることは |
10667 | 10352 | できません。 |
10668 | 10353 | |
10669 | 10354 | =back |
10670 | 10355 | |
10671 | 10356 | =item * |
10672 | 10357 | |
10673 | 10358 | =begin original |
10674 | 10359 | |
10675 | 10360 | Real numbers (floats and doubles) are in native machine format only. |
10676 | 10361 | Due to the multiplicity of floating-point formats and the lack of a |
10677 | 10362 | standard "network" representation for them, no facility for interchange has been |
10678 | 10363 | made. This means that packed floating-point data written on one machine |
10679 | 10364 | may not be readable on another, even if both use IEEE floating-point |
10680 | 10365 | arithmetic (because the endianness of the memory representation is not part |
10681 | 10366 | of the IEEE spec). See also L<perlport>. |
10682 | 10367 | |
10683 | 10368 | =end original |
10684 | 10369 | |
10685 | 10370 | 実数 (float と double) は、機種依存のフォーマットしかありません。 |
10686 | いろんな浮動小数点数のフォーマットが在り、標準的な | |
10371 | いろんな浮動小数点数のフォーマットが在り、標準的な | |
10687 | ないため、データ交換のための機能は | |
10372 | "network" 表現といったものがないため、データ交換のための機能は | |
10373 | 用意してありません。 | |
10688 | 10374 | つまり、あるマシンで pack した浮動小数点数は、別のマシンでは |
10689 | 10375 | 読めないかもしれないということです; たとえ双方で IEEE フォーマットの |
10690 | 10376 | 浮動小数点数演算を行なっていてもです (IEEE の仕様では、メモリ表現上の |
10691 | 10377 | バイト順序までは、規定されていないからです)。 |
10692 | 10378 | L<perlport> も参照してください。 |
10693 | 10379 | |
10694 | 10380 | =begin original |
10695 | 10381 | |
10696 | 10382 | If you know I<exactly> what you're doing, you can use the C<< > >> or C<< < >> |
10697 | 10383 | modifiers to force big- or little-endian byte-order on floating-point values. |
10698 | 10384 | |
10699 | 10385 | =end original |
10700 | 10386 | |
10701 | 10387 | もし何をしようとしているのかを I<正確に> 理解しているなら、浮動小数点数の |
10702 | 10388 | バイト順をビッグエンディアンやリトルエンディアンに強制するために、 |
10703 | 10389 | C<< > >> と C<< < >> の修飾子が使えます。 |
10704 | 10390 | |
10705 | 10391 | =begin original |
10706 | 10392 | |
10707 | 10393 | Because Perl uses doubles (or long doubles, if configured) internally for |
10708 | 10394 | all numeric calculation, converting from double into float and thence |
10709 | 10395 | to double again loses precision, so C<unpack("f", pack("f", $foo)>) |
10710 | 10396 | will not in general equal $foo. |
10711 | 10397 | |
10712 | 10398 | =end original |
10713 | 10399 | |
10714 | Perl では、すべての数値演算のために、内部的に double (または | |
10400 | Perl では、すべての数値演算のために、内部的に double (または | |
10715 | long double) を使用しているので、 | |
10401 | 設定によっては long double) を使用しているので、 | |
10716 | double | |
10402 | double から float へ変換し、それから再び double に戻すと | |
10403 | 精度が落ちることになり、C<unpack("f", pack("f", $foo)>) は、 | |
10717 | 10404 | 一般には $foo と同じではありません。 |
10718 | 10405 | |
10719 | 10406 | =item * |
10720 | 10407 | |
10721 | 10408 | =begin original |
10722 | 10409 | |
10723 | 10410 | Pack and unpack can operate in two modes: character mode (C<C0> mode) where |
10724 | 10411 | the packed string is processed per character, and UTF-8 mode (C<U0> mode) |
10725 | 10412 | where the packed string is processed in its UTF-8-encoded Unicode form on |
10726 | 10413 | a byte-by-byte basis. Character mode is the default |
10727 | 10414 | unless the format string starts with C<U>. You |
10728 | 10415 | can always switch mode mid-format with an explicit |
10729 | 10416 | C<C0> or C<U0> in the format. This mode remains in effect until the next |
10730 | 10417 | mode change, or until the end of the C<()> group it (directly) applies to. |
10731 | 10418 | |
10732 | 10419 | =end original |
10733 | 10420 | |
10734 | 10421 | pack と unpack は二つのモードで操作します: pack された文字列を文字単位で |
10735 | 10422 | 処理する文字モード (C<C0> モード) と、pack された文字列を、バイト毎に、 |
10736 | 10423 | その UTF-8 エンコードされた形式で処理するUTF-8 モード (C<U0> モード) です。 |
10737 | 10424 | 文字モードはフォーマット文字列が C<U> で始まっていない限りはデフォルトです。 |
10738 | 10425 | モードはフォーマット中に明示的に C<C0> または C<U0> と書くことでいつでも |
10739 | 10426 | 切り替えられます。 |
10740 | 10427 | モードは次のモードに切り替えられるか、(直接)適用された () グループが |
10741 | 10428 | 終了するまで有効です。 |
10742 | 10429 | |
10743 | 10430 | =begin original |
10744 | 10431 | |
10745 | 10432 | Using C<C0> to get Unicode characters while using C<U0> to get I<non>-Unicode |
10746 | 10433 | bytes is not necessarily obvious. Probably only the first of these |
10747 | 10434 | is what you want: |
10748 | 10435 | |
10749 | 10436 | =end original |
10750 | 10437 | |
10751 | 10438 | Unicode 文字を取得するのに C<C0> を使い、I<非> Unicode バイトを取得するのに |
10752 | 10439 | C<U0> を使うというのは必ずしも明白ではありません。 |
10753 | 10440 | おそらく、これらのうち最初のものだけが望みのものでしょう: |
10754 | 10441 | |
10755 | 10442 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | |
10756 | 10443 | perl -CS -ne 'printf "%v04X\n", $_ for unpack("C0A*", $_)' |
10757 | 10444 | 03B1.03C9 |
10758 | 10445 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | |
10759 | 10446 | perl -CS -ne 'printf "%v02X\n", $_ for unpack("U0A*", $_)' |
10760 | 10447 | CE.B1.CF.89 |
10761 | 10448 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | |
10762 | 10449 | perl -C0 -ne 'printf "%v02X\n", $_ for unpack("C0A*", $_)' |
10763 | 10450 | CE.B1.CF.89 |
10764 | 10451 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | |
10765 | 10452 | perl -C0 -ne 'printf "%v02X\n", $_ for unpack("U0A*", $_)' |
10766 | 10453 | C3.8E.C2.B1.C3.8F.C2.89 |
10767 | 10454 | |
10768 | 10455 | =begin original |
10769 | 10456 | |
10770 | 10457 | Those examples also illustrate that you should not try to use |
10771 | 10458 | C<pack>/C<unpack> as a substitute for the L<Encode> module. |
10772 | 10459 | |
10773 | 10460 | =end original |
10774 | 10461 | |
10775 | 10462 | これらの例は、C<pack>/C<unpack> を L<Encode> モジュールの代わりとして |
10776 | 10463 | 使おうとするべきではないということも示しています。 |
10777 | 10464 | |
10778 | 10465 | =item * |
10779 | 10466 | |
10780 | 10467 | =begin original |
10781 | 10468 | |
10782 | 10469 | You must yourself do any alignment or padding by inserting, for example, |
10783 | 10470 | enough C<"x">es while packing. There is no way for pack() and unpack() |
10784 | 10471 | to know where characters are going to or coming from, so they |
10785 | 10472 | handle their output and input as flat sequences of characters. |
10786 | 10473 | |
10787 | 10474 | =end original |
10788 | 10475 | |
10789 | 10476 | pack するときに、例えば十分な数の C<"x"> を挿入することによって |
10790 | 10477 | アライメントやパッディングを行うのは全て自分でしなければなりません。 |
10791 | 10478 | 文字列がどこへ行くかやどこから来たかを pack() や unpack() が |
10792 | 10479 | 知る方法はないので、C<pack> (と C<unpack>) は出力と入力をフラットな |
10793 | 10480 | 文字列として扱います。 |
10794 | 10481 | |
10795 | 10482 | =item * |
10796 | 10483 | |
10797 | 10484 | =begin original |
10798 | 10485 | |
10799 | 10486 | A C<()> group is a sub-TEMPLATE enclosed in parentheses. A group may |
10800 | 10487 | take a repeat count either as postfix, or for unpack(), also via the C</> |
10801 | 10488 | template character. Within each repetition of a group, positioning with |
10802 | 10489 | C<@> starts over at 0. Therefore, the result of |
10803 | 10490 | |
10804 | 10491 | =end original |
10805 | 10492 | |
10806 | 10493 | C<()> のグループはかっこで囲われた副テンプレートです。 |
10807 | 10494 | グループは繰り返し数を取ることができます; 接尾辞によるか、unpack() の場合は |
10808 | 10495 | C</> テンプレート文字によります。 |
10809 | 10496 | グループの繰り返し毎に、C<@> の位置は 0 になります。 |
10810 | 10497 | 従って、以下の結果は: |
10811 | 10498 | |
10812 | 10499 | pack("@1A((@2A)@3A)", qw[X Y Z]) |
10813 | 10500 | |
10814 | 10501 | =begin original |
10815 | 10502 | |
10816 | 10503 | is the string C<"\0X\0\0YZ">. |
10817 | 10504 | |
10818 | 10505 | =end original |
10819 | 10506 | |
10820 | 10507 | 文字列 C<"\0X\0\0YZ"> です。 |
10821 | 10508 | |
10822 | 10509 | =item * |
10823 | 10510 | |
10824 | 10511 | =begin original |
10825 | 10512 | |
10826 | 10513 | C<x> and C<X> accept the C<!> modifier to act as alignment commands: they |
10827 | 10514 | jump forward or back to the closest position aligned at a multiple of C<count> |
10828 | 10515 | characters. For example, to pack() or unpack() a C structure like |
10829 | 10516 | |
10830 | 10517 | =end original |
10831 | 10518 | |
10832 | 10519 | C<x> と C<X> にはアライメントコマンドとして C<!> 修飾子を付けることができます: |
10833 | 10520 | これは C<count> 文字の倍数のアライメントとなる、もっとも近い位置に移動します。 |
10834 | 10521 | 例えば、以下のような構造体を pack() または unpack() するためには |
10835 | 10522 | |
10836 | 10523 | struct { |
10837 | 10524 | char c; /* one signed, 8-bit character */ |
10838 | 10525 | double d; |
10839 | 10526 | char cc[2]; |
10840 | 10527 | } |
10841 | 10528 | |
10842 | 10529 | =begin original |
10843 | 10530 | |
10844 | 10531 | one may need to use the template C<c x![d] d c[2]>. This assumes that |
10845 | 10532 | doubles must be aligned to the size of double. |
10846 | 10533 | |
10847 | 10534 | =end original |
10848 | 10535 | |
10849 | 10536 | C<W x![d] d W[2]> というテンプレートを使う必要があるかもしれません。 |
10850 | 10537 | これは double が double のサイズでアライメントされていることを |
10851 | 10538 | 仮定しています。 |
10852 | 10539 | |
10853 | 10540 | =begin original |
10854 | 10541 | |
10855 | 10542 | For alignment commands, a C<count> of 0 is equivalent to a C<count> of 1; |
10856 | 10543 | both are no-ops. |
10857 | 10544 | |
10858 | 10545 | =end original |
10859 | 10546 | |
10860 | 10547 | アライメントコマンドに対しては、C<count> に 0 を指定するのは 1 を |
10861 | 10548 | 指定するのと等価です; どちらも何もしません。 |
10862 | 10549 | |
10863 | 10550 | =item * |
10864 | 10551 | |
10865 | 10552 | =begin original |
10866 | 10553 | |
10867 | 10554 | C<n>, C<N>, C<v> and C<V> accept the C<!> modifier to |
10868 | 10555 | represent signed 16-/32-bit integers in big-/little-endian order. |
10869 | 10556 | This is portable only when all platforms sharing packed data use the |
10870 | 10557 | same binary representation for signed integers; for example, when all |
10871 | 10558 | platforms use two's-complement representation. |
10872 | 10559 | |
10873 | 10560 | =end original |
10874 | 10561 | |
10875 | C<n>, C<N>, C<v>, C<V> は | |
10562 | C<n>, C<N>, C<v>, C<V> は | |
10563 | ビッグ/リトルエンディアンの順序で符号付き 16 または | |
10876 | 10564 | 32 ビット整数で表現するための C<!> 修飾子を受け入れます。 |
10877 | 10565 | これは pack されたデータを共有する全てのプラットフォームが |
10878 | 10566 | 符号付き整数について同じバイナリ表現を使う場合にのみ移植性があります; |
10879 | 10567 | 例えば、全てのプラットフォームで 2 の補数表現を使う場合です。 |
10880 | 10568 | |
10881 | 10569 | =item * |
10882 | 10570 | |
10883 | 10571 | =begin original |
10884 | 10572 | |
10885 | 10573 | Comments can be embedded in a TEMPLATE using C<#> through the end of line. |
10886 | 10574 | White space can separate pack codes from each other, but modifiers and |
10887 | 10575 | repeat counts must follow immediately. Breaking complex templates into |
10888 | 10576 | individual line-by-line components, suitably annotated, can do as much to |
10889 | 10577 | improve legibility and maintainability of pack/unpack formats as C</x> can |
10890 | 10578 | for complicated pattern matches. |
10891 | 10579 | |
10892 | 10580 | =end original |
10893 | 10581 | |
10894 | 10582 | TEMPLATE の中の C<#> から行末まではコメントです。 |
10895 | 10583 | 空白は pack コードをそれぞれ分けるために使えますが、修飾子と |
10896 | 10584 | 繰り返し数は直後に置かなければなりません。 |
10897 | 10585 | 複雑なテンプレートを個々の行単位の要素に分解して適切に注釈をつけると、 |
10898 | 10586 | 複雑なパターンマッチングに対する C</x> と同じぐらい、pack/unpack |
10899 | 10587 | フォーマットの読みやすさと保守性が向上します。 |
10900 | 10588 | |
10901 | 10589 | =item * |
10902 | 10590 | |
10903 | 10591 | =begin original |
10904 | 10592 | |
10905 | 10593 | If TEMPLATE requires more arguments than pack() is given, pack() |
10906 | 10594 | assumes additional C<""> arguments. If TEMPLATE requires fewer arguments |
10907 | 10595 | than given, extra arguments are ignored. |
10908 | 10596 | |
10909 | 10597 | =end original |
10910 | 10598 | |
10911 | 10599 | TEMPLATE が要求する引数の数が pack() が実際に与えている数より多い場合、 |
10912 | 10600 | pack() は追加の C<""> 引数があるものと仮定します。 |
10913 | 10601 | TEMPLATE が要求する引数の数の方が少ない場合、余分の引数は無視されます。 |
10914 | 10602 | |
10915 | 10603 | =back |
10916 | 10604 | |
10917 | 10605 | =begin original |
10918 | 10606 | |
10919 | 10607 | Examples: |
10920 | 10608 | |
10921 | 10609 | =end original |
10922 | 10610 | |
10923 | 10611 | 例: |
10924 | 10612 | |
10925 | 10613 | $foo = pack("WWWW",65,66,67,68); |
10926 | 10614 | # foo eq "ABCD" |
10927 | 10615 | $foo = pack("W4",65,66,67,68); |
10928 | 10616 | # same thing |
10929 | 10617 | $foo = pack("W4",0x24b6,0x24b7,0x24b8,0x24b9); |
10930 | 10618 | # same thing with Unicode circled letters. |
10931 | 10619 | $foo = pack("U4",0x24b6,0x24b7,0x24b8,0x24b9); |
10932 | 10620 | # same thing with Unicode circled letters. You don't get the |
10933 | 10621 | # UTF-8 bytes because the U at the start of the format caused |
10934 | 10622 | # a switch to U0-mode, so the UTF-8 bytes get joined into |
10935 | 10623 | # characters |
10936 | 10624 | $foo = pack("C0U4",0x24b6,0x24b7,0x24b8,0x24b9); |
10937 | 10625 | # foo eq "\xe2\x92\xb6\xe2\x92\xb7\xe2\x92\xb8\xe2\x92\xb9" |
10938 | 10626 | # This is the UTF-8 encoding of the string in the |
10939 | 10627 | # previous example |
10940 | 10628 | |
10941 | 10629 | $foo = pack("ccxxcc",65,66,67,68); |
10942 | 10630 | # foo eq "AB\0\0CD" |
10943 | 10631 | |
10944 | 10632 | # NOTE: The examples above featuring "W" and "c" are true |
10945 | 10633 | # only on ASCII and ASCII-derived systems such as ISO Latin 1 |
10946 | 10634 | # and UTF-8. On EBCDIC systems, the first example would be |
10947 | 10635 | # $foo = pack("WWWW",193,194,195,196); |
10948 | 10636 | |
10949 | 10637 | $foo = pack("s2",1,2); |
10950 | 10638 | # "\001\000\002\000" on little-endian |
10951 | 10639 | # "\000\001\000\002" on big-endian |
10952 | 10640 | |
10953 | 10641 | $foo = pack("a4","abcd","x","y","z"); |
10954 | 10642 | # "abcd" |
10955 | 10643 | |
10956 | 10644 | $foo = pack("aaaa","abcd","x","y","z"); |
10957 | 10645 | # "axyz" |
10958 | 10646 | |
10959 | 10647 | $foo = pack("a14","abcdefg"); |
10960 | 10648 | # "abcdefg\0\0\0\0\0\0\0" |
10961 | 10649 | |
10962 | 10650 | $foo = pack("i9pl", gmtime); |
10963 | 10651 | # a real struct tm (on my system anyway) |
10964 | 10652 | |
10965 | 10653 | $utmp_template = "Z8 Z8 Z16 L"; |
10966 | 10654 | $utmp = pack($utmp_template, @utmp1); |
10967 | 10655 | # a struct utmp (BSDish) |
10968 | 10656 | |
10969 | 10657 | @utmp2 = unpack($utmp_template, $utmp); |
10970 | 10658 | # "@utmp1" eq "@utmp2" |
10971 | 10659 | |
10972 | 10660 | sub bintodec { |
10973 | 10661 | unpack("N", pack("B32", substr("0" x 32 . shift, -32))); |
10974 | 10662 | } |
10975 | 10663 | |
10976 | 10664 | $foo = pack('sx2l', 12, 34); |
10977 | 10665 | # short 12, two zero bytes padding, long 34 |
10978 | 10666 | $bar = pack('s@4l', 12, 34); |
10979 | 10667 | # short 12, zero fill to position 4, long 34 |
10980 | 10668 | # $foo eq $bar |
10981 | 10669 | $baz = pack('s.l', 12, 4, 34); |
10982 | 10670 | # short 12, zero fill to position 4, long 34 |
10983 | 10671 | |
10984 | 10672 | $foo = pack('nN', 42, 4711); |
10985 | 10673 | # pack big-endian 16- and 32-bit unsigned integers |
10986 | 10674 | $foo = pack('S>L>', 42, 4711); |
10987 | 10675 | # exactly the same |
10988 | 10676 | $foo = pack('s<l<', -42, 4711); |
10989 | 10677 | # pack little-endian 16- and 32-bit signed integers |
10990 | 10678 | $foo = pack('(sl)<', -42, 4711); |
10991 | 10679 | # exactly the same |
10992 | 10680 | |
10993 | 10681 | =begin original |
10994 | 10682 | |
10995 | 10683 | The same template may generally also be used in unpack(). |
10996 | 10684 | |
10997 | 10685 | =end original |
10998 | 10686 | |
10999 | 10687 | 一般には、pack で使用したものと同じテンプレートが、 |
11000 | 10688 | unpack() 関数でも使用できます。 |
11001 | 10689 | |
11002 | 10690 | =item package NAMESPACE |
11003 | 10691 | |
11004 | 10692 | =item package NAMESPACE VERSION |
11005 | 10693 | X<package> X<module> X<namespace> X<version> |
11006 | 10694 | |
11007 | 10695 | =item package NAMESPACE BLOCK |
11008 | 10696 | |
11009 | 10697 | =item package NAMESPACE VERSION BLOCK |
11010 | 10698 | X<package> X<module> X<namespace> X<version> |
11011 | 10699 | |
11012 | 10700 | =for Pod::Functions declare a separate global namespace |
11013 | 10701 | |
11014 | 10702 | =begin original |
11015 | 10703 | |
11016 | 10704 | Declares the BLOCK or the rest of the compilation unit as being in the |
11017 | 10705 | given namespace. The scope of the package declaration is either the |
11018 | 10706 | supplied code BLOCK or, in the absence of a BLOCK, from the declaration |
11019 | 10707 | itself through the end of current scope (the enclosing block, file, or |
11020 | 10708 | C<eval>). That is, the forms without a BLOCK are operative through the end |
11021 | 10709 | of the current scope, just like the C<my>, C<state>, and C<our> operators. |
11022 | 10710 | All unqualified dynamic identifiers in this scope will be in the given |
11023 | 10711 | namespace, except where overridden by another C<package> declaration or |
11024 | 10712 | when they're one of the special identifiers that qualify into C<main::>, |
11025 | 10713 | like C<STDOUT>, C<ARGV>, C<ENV>, and the punctuation variables. |
11026 | 10714 | |
11027 | 10715 | =end original |
11028 | 10716 | |
11029 | 10717 | BLOCK や残りのコンパイル単位を与えられた名前空間として宣言します。 |
11030 | 10718 | パッケージ宣言のスコープは BLOCK か、BLOCK がないばあいは宣言自身から |
11031 | 10719 | 現在のスコープの末尾 (閉じたブロック、ファイル、C<eval>) です。 |
11032 | 10720 | つまり、BLOCK なしの形式は、C<my>, C<state>, C<our> 演算子と同様に |
11033 | 10721 | 現在のスコープの末尾にまで作用します。 |
11034 | 10722 | このスコープ内の、全ての完全修飾されていない動的識別子は、他の |
11035 | 10723 | C<package> 宣言によって上書きされるか、 |
11036 | 10724 | C<STDOUT>, C<ARGV>, C<ENV> や句読点変数のように C<main::> に |
11037 | 10725 | 割り当てられる特殊変数でない限り、指定された |
11038 | 10726 | 名前空間になります。 |
11039 | 10727 | |
11040 | 10728 | =begin original |
11041 | 10729 | |
11042 | 10730 | A package statement affects dynamic variables only, including those |
11043 | you've used C<local> on, but I<not> lexical | |
10731 | you've used C<local> on, but I<not> lexical variables, which are created | |
11044 | 10732 | with C<my>, C<state>, or C<our>. Typically it would be the first |
11045 | 10733 | declaration in a file included by C<require> or C<use>. You can switch into a |
11046 | 10734 | package in more than one place, since this only determines which default |
11047 | 10735 | symbol table the compiler uses for the rest of that block. You can refer to |
11048 | 10736 | identifiers in other packages than the current one by prefixing the identifier |
11049 | 10737 | with the package name and a double colon, as in C<$SomePack::var> |
11050 | 10738 | or C<ThatPack::INPUT_HANDLE>. If package name is omitted, the C<main> |
11051 | 10739 | package as assumed. That is, C<$::sail> is equivalent to |
11052 | 10740 | C<$main::sail> (as well as to C<$main'sail>, still seen in ancient |
11053 | 10741 | code, mostly from Perl 4). |
11054 | 10742 | |
11055 | 10743 | =end original |
11056 | 10744 | |
11057 | 10745 | package 文は動的変数にのみ影響します(C<local> で使ったものも |
11058 | 10746 | 含みます)が、C<my>, C<state>, C<our> のいずれかで作成された |
11059 | レキシカル | |
10747 | レキシカル変数には I<影響しません>。 | |
11060 | 10748 | 典型的にはこれは C<require> や C<use> 演算子でインクルードされるファイルの |
11061 | 10749 | 最初に宣言されます。 |
11062 | 10750 | パッケージを複数の場所で切り替えることができます; |
11063 | 10751 | なぜならこれは単にコンパイラがこのブロックの残りに対してどの |
11064 | 10752 | シンボルテーブルを使うかにのみ影響するからです。 |
11065 | 10753 | 他のパッケージの識別子は、C<$SomePack::var> や |
11066 | 10754 | C<ThatPack::INPUT_HANDLE> のように、識別子にパッケージ名と |
11067 | 10755 | コロン二つをつけることで参照できます。 |
11068 | 10756 | パッケージ名が省略された場合、C<main> パッケージが仮定されます。 |
11069 | 10757 | つまり、C<$::sail> は C<$main::sail> と等価です(ほとんどは Perl 4 からの、 |
11070 | 10758 | 古いコードでは C<$main'sail> もまだ見られます)。 |
11071 | 10759 | |
11072 | 10760 | =begin original |
11073 | 10761 | |
11074 | 10762 | If VERSION is provided, C<package> sets the C<$VERSION> variable in the given |
11075 | 10763 | namespace to a L<version> object with the VERSION provided. VERSION must be a |
11076 | 10764 | "strict" style version number as defined by the L<version> module: a positive |
11077 | 10765 | decimal number (integer or decimal-fraction) without exponentiation or else a |
11078 | 10766 | dotted-decimal v-string with a leading 'v' character and at least three |
11079 | 10767 | components. You should set C<$VERSION> only once per package. |
11080 | 10768 | |
11081 | 10769 | =end original |
11082 | 10770 | |
11083 | 10771 | VERSION が指定されると、C<package> は与えられた名前空間の C<$VERSION> 変数に、 |
11084 | 10772 | 指定された VERSION の L<version> オブジェクトをセットします。 |
11085 | 10773 | VERSION は L<version> で定義されている「厳密な」形式のバージョン番号で |
11086 | 10774 | なければなりません: 指数のない正の 10 進数 (整数か 10 進小数) か、 |
11087 | 10775 | さもなければ先頭に 'v' の文字が付いて、少なくとも三つの部分から |
11088 | 10776 | 構成されるドット付き 10 進v-文字列です。 |
11089 | 10777 | C<$VERSION> はパッケージ毎に 1 回だけセットするべきです。 |
11090 | 10778 | |
11091 | 10779 | =begin original |
11092 | 10780 | |
11093 | 10781 | See L<perlmod/"Packages"> for more information about packages, modules, |
11094 | 10782 | and classes. See L<perlsub> for other scoping issues. |
11095 | 10783 | |
11096 | 10784 | =end original |
11097 | 10785 | |
11098 | 10786 | パッケージ、モジュール、クラスに関するさらなる情報については |
11099 | 10787 | L<perlmod/"Packages"> を参照してください。 |
11100 | 10788 | その他のスコープに関する話題については L<perlsub> を参照してください。 |
11101 | 10789 | |
11102 | 10790 | =item __PACKAGE__ |
11103 | 10791 | X<__PACKAGE__> |
11104 | 10792 | |
11105 | 10793 | =for Pod::Functions +5.004 the current package |
11106 | 10794 | |
11107 | 10795 | =begin original |
11108 | 10796 | |
11109 | 10797 | A special token that returns the name of the package in which it occurs. |
11110 | 10798 | |
11111 | 10799 | =end original |
11112 | 10800 | |
11113 | 10801 | これが書いてあるパッケージの名前を返す特殊トークン。 |
11114 | 10802 | |
11115 | 10803 | =item pipe READHANDLE,WRITEHANDLE |
11116 | 10804 | X<pipe> |
11117 | 10805 | |
11118 | 10806 | =for Pod::Functions open a pair of connected filehandles |
11119 | 10807 | |
11120 | 10808 | =begin original |
11121 | 10809 | |
11122 | 10810 | Opens a pair of connected pipes like the corresponding system call. |
11123 | 10811 | Note that if you set up a loop of piped processes, deadlock can occur |
11124 | 10812 | unless you are very careful. In addition, note that Perl's pipes use |
11125 | 10813 | IO buffering, so you may need to set C<$|> to flush your WRITEHANDLE |
11126 | 10814 | after each command, depending on the application. |
11127 | 10815 | |
11128 | 10816 | =end original |
11129 | 10817 | |
11130 | 対応するシステムコールと同じように、 | |
10818 | 対応するシステムコールと同じように、 | |
10819 | 接続されたパイプのペアをオープンします。 | |
11131 | 10820 | パイプでプロセスをループにするときには、よほど気を付けないと、 |
11132 | 10821 | デッドロックが起こり得ます。 |
11133 | さらに、Perl のパイプでは、IO のバッファリングを使 | |
10822 | さらに、Perl のパイプでは、IO のバッファリングを使いますから、 | |
11134 | 10823 | アプリケーションによっては、コマンドごとに WRITEHANDLE を |
11135 | 10824 | フラッシュするように、C<$|> を設定することが必要になるかもしれません。 |
11136 | 10825 | |
11137 | 10826 | =begin original |
11138 | 10827 | |
11139 | Returns true on success. | |
11140 | ||
11141 | =end original | |
11142 | ||
11143 | 成功時には真を返します。 | |
11144 | ||
11145 | =begin original | |
11146 | ||
11147 | 10828 | See L<IPC::Open2>, L<IPC::Open3>, and |
11148 | 10829 | L<perlipc/"Bidirectional Communication with Another Process"> |
11149 | 10830 | for examples of such things. |
11150 | 10831 | |
11151 | 10832 | =end original |
11152 | 10833 | |
11153 | 10834 | これらに関する例については、L<IPC::Open2>, L<IPC::Open3>, |
11154 | 10835 | L<perlipc/"Bidirectional Communication with Another Process"> を |
11155 | 10836 | 参照してください。 |
11156 | 10837 | |
11157 | 10838 | =begin original |
11158 | 10839 | |
11159 | 10840 | On systems that support a close-on-exec flag on files, that flag is set |
11160 | 10841 | on all newly opened file descriptors whose C<fileno>s are I<higher> than |
11161 | 10842 | the current value of $^F (by default 2 for C<STDERR>). See L<perlvar/$^F>. |
11162 | 10843 | |
11163 | 10844 | =end original |
11164 | 10845 | |
11165 | 10846 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
11166 | 10847 | 新しくオープンされたファイル記述子のうち、 |
11167 | 10848 | C<fileno> が現在の $^F の値(デフォルトでは C<STDERR> の 2) |
11168 | 10849 | I<よりも大きい> ものに対してフラグがセットされます。 |
11169 | 10850 | L<perlvar/$^F> を参照してください。 |
11170 | 10851 | |
11171 | 10852 | =item pop ARRAY |
11172 | 10853 | X<pop> X<stack> |
11173 | 10854 | |
11174 | 10855 | =item pop EXPR |
11175 | 10856 | |
11176 | 10857 | =item pop |
11177 | 10858 | |
11178 | 10859 | =for Pod::Functions remove the last element from an array and return it |
11179 | 10860 | |
11180 | 10861 | =begin original |
11181 | 10862 | |
11182 | 10863 | Pops and returns the last value of the array, shortening the array by |
11183 | 10864 | one element. |
11184 | 10865 | |
11185 | 10866 | =end original |
11186 | 10867 | |
11187 | 10868 | 配列の最後の値をポップして返し、配列の大きさを 1 だけ小さくします。 |
11188 | 10869 | |
11189 | 10870 | =begin original |
11190 | 10871 | |
11191 | 10872 | Returns the undefined value if the array is empty, although this may also |
11192 | 10873 | happen at other times. If ARRAY is omitted, pops the C<@ARGV> array in the |
11193 | 10874 | main program, but the C<@_> array in subroutines, just like C<shift>. |
11194 | 10875 | |
11195 | 10876 | =end original |
11196 | 10877 | |
11197 | 10878 | 指定された配列に要素がなければ未定義値が返されますが、 |
11198 | 10879 | しかしこれは他の場合にも起こり得ます。 |
11199 | 10880 | ARRAY が省略されると、C<shift> と同様に、メインプログラムでは C<@ARGV> が |
11200 | 10881 | 使われますが、サブルーチンでは C<@_> が使われます。 |
11201 | 10882 | |
11202 | 10883 | =begin original |
11203 | 10884 | |
11204 | 10885 | Starting with Perl 5.14, C<pop> can take a scalar EXPR, which must hold a |
11205 | 10886 | reference to an unblessed array. The argument will be dereferenced |
11206 | 10887 | automatically. This aspect of C<pop> is considered highly experimental. |
11207 | 10888 | The exact behaviour may change in a future version of Perl. |
11208 | 10889 | |
11209 | 10890 | =end original |
11210 | 10891 | |
11211 | 10892 | Perl 5.14 から、C<pop> はスカラの EXPR を取ることができるようになりました; |
11212 | 10893 | これは bless されていない配列へのリファレンスでなければなりません。 |
11213 | 10894 | 引数は自動的にデリファレンスされます。 |
11214 | 10895 | C<pop> のこの動作は高度に実験的であると考えられています。 |
11215 | 10896 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 |
11216 | 10897 | |
11217 | 10898 | =begin original |
11218 | 10899 | |
11219 | 10900 | To avoid confusing would-be users of your code who are running earlier |
11220 | 10901 | versions of Perl with mysterious syntax errors, put this sort of thing at |
11221 | 10902 | the top of your file to signal that your code will work I<only> on Perls of |
11222 | 10903 | a recent vintage: |
11223 | 10904 | |
11224 | 10905 | =end original |
11225 | 10906 | |
11226 | 10907 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な |
11227 | 10908 | 文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で |
11228 | 10909 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを |
11229 | 10910 | 書いてください: |
11230 | 10911 | |
11231 | 10912 | use 5.014; # so push/pop/etc work on scalars (experimental) |
11232 | 10913 | |
11233 | 10914 | =item pos SCALAR |
11234 | 10915 | X<pos> X<match, position> |
11235 | 10916 | |
11236 | 10917 | =item pos |
11237 | 10918 | |
11238 | 10919 | =for Pod::Functions find or set the offset for the last/next m//g search |
11239 | 10920 | |
11240 | 10921 | =begin original |
11241 | 10922 | |
11242 | 10923 | Returns the offset of where the last C<m//g> search left off for the |
11243 | 10924 | variable in question (C<$_> is used when the variable is not |
11244 | 10925 | specified). Note that 0 is a valid match offset. C<undef> indicates |
11245 | 10926 | that the search position is reset (usually due to match failure, but |
11246 | 10927 | can also be because no match has yet been run on the scalar). |
11247 | 10928 | |
11248 | 10929 | =end original |
11249 | 10930 | |
11250 | 10931 | 対象の変数に対して、前回の C<m//g> が終了した場所の |
11251 | 10932 | オフセットを返します(変数が指定されなかった場合は C<$_> が使われます)。 |
11252 | 10933 | 0 は有効なマッチオフセットであることに注意してください。 |
11253 | 10934 | C<undef> は検索位置がリセットされることを意味します (通常はマッチ失敗が |
11254 | 10935 | 原因ですが、このスカラ値にまだマッチングが行われていないためかもしれません)。 |
11255 | 10936 | |
11256 | 10937 | =begin original |
11257 | 10938 | |
11258 | 10939 | C<pos> directly accesses the location used by the regexp engine to |
11259 | 10940 | store the offset, so assigning to C<pos> will change that offset, and |
11260 | 10941 | so will also influence the C<\G> zero-width assertion in regular |
11261 | 10942 | expressions. Both of these effects take place for the next match, so |
11262 | 10943 | you can't affect the position with C<pos> during the current match, |
11263 | 10944 | such as in C<(?{pos() = 5})> or C<s//pos() = 5/e>. |
11264 | 10945 | |
11265 | 10946 | =end original |
11266 | 10947 | |
11267 | 10948 | C<pos> は正規表現エンジンがオフセットを保存するために使う場所を直接 |
11268 | 10949 | アクセスするので、C<pos> への代入はオフセットを変更し、そのような変更は |
11269 | 10950 | 正規表現における C<\G> ゼロ幅アサートにも影響を与えます。 |
11270 | 10951 | これらの効果の両方は次のマッチングのために行われるので、 |
11271 | 10952 | C<(?{pos() = 5})> や C<s//pos() = 5/e> のように現在のマッチング中の |
11272 | 10953 | C<pos> の位置には影響を与えません。 |
11273 | 10954 | |
11274 | 10955 | =begin original |
11275 | 10956 | |
11276 | 10957 | Setting C<pos> also resets the I<matched with zero-length> flag, described |
11277 | 10958 | under L<perlre/"Repeated Patterns Matching a Zero-length Substring">. |
11278 | 10959 | |
11279 | 10960 | =end original |
11280 | 10961 | |
11281 | 10962 | C<pos> を設定すると、 |
11282 | 10963 | L<perlre/"Repeated Patterns Matching a Zero-length Substring"> に |
11283 | 10964 | 記述されている、I<長さ 0 でマッチング> フラグもリセットされます。 |
11284 | 10965 | |
11285 | 10966 | =begin original |
11286 | 10967 | |
11287 | 10968 | Because a failed C<m//gc> match doesn't reset the offset, the return |
11288 | 10969 | from C<pos> won't change either in this case. See L<perlre> and |
11289 | 10970 | L<perlop>. |
11290 | 10971 | |
11291 | 10972 | =end original |
11292 | 10973 | |
11293 | 10974 | C<m//gc> マッチに失敗してもオフセットはリセットしないので、 |
11294 | 10975 | C<pos> からの返り値はどちらの場合も変更されません。 |
11295 | 10976 | L<perlre> と L<perlop> を参照してください。 |
11296 | 10977 | |
11297 | 10978 | =item print FILEHANDLE LIST |
11298 | 10979 | X<print> |
11299 | 10980 | |
11300 | 10981 | =item print FILEHANDLE |
11301 | 10982 | |
11302 | 10983 | =item print LIST |
11303 | 10984 | |
11304 | 10985 | =item print |
11305 | 10986 | |
11306 | 10987 | =for Pod::Functions output a list to a filehandle |
11307 | 10988 | |
11308 | 10989 | =begin original |
11309 | 10990 | |
11310 | 10991 | Prints a string or a list of strings. Returns true if successful. |
11311 | 10992 | FILEHANDLE may be a scalar variable containing the name of or a reference |
11312 | 10993 | to the filehandle, thus introducing one level of indirection. (NOTE: If |
11313 | 10994 | FILEHANDLE is a variable and the next token is a term, it may be |
11314 | 10995 | misinterpreted as an operator unless you interpose a C<+> or put |
11315 | 10996 | parentheses around the arguments.) If FILEHANDLE is omitted, prints to the |
11316 | 10997 | last selected (see L</select>) output handle. If LIST is omitted, prints |
11317 | 10998 | C<$_> to the currently selected output handle. To use FILEHANDLE alone to |
11318 | 10999 | print the content of C<$_> to it, you must use a real filehandle like |
11319 | 11000 | C<FH>, not an indirect one like C<$fh>. To set the default output handle |
11320 | 11001 | to something other than STDOUT, use the select operation. |
11321 | 11002 | |
11322 | 11003 | =end original |
11323 | 11004 | |
11324 | 11005 | 文字列か文字列のリストを出力します。 |
11325 | 11006 | 成功時には真を返します。 |
11326 | 11007 | FILEHANDLE は、ファイルハンドル名またはそのリファレンスが |
11327 | 11008 | 入っているスカラ変数名でもよいので、一段階の間接指定が行なえます。 |
11328 | 11009 | (注: FILEHANDLE に変数を使い、次のトークンが「項」のときには、 |
11329 | 11010 | 間に C<+> を置くか、引数の前後を括弧で括らなければ、 |
11330 | 11011 | 誤って解釈されることがあります。) |
11331 | 11012 | FILEHANDLE を省略した場合には、最後に選択された (L</select> 参照) 出力 |
11332 | 11013 | チャネルに出力します。 |
11333 | 11014 | LIST を省略すると、C<$_> が現在選択されている出力ハンドルに出力されます。 |
11334 | 11015 | C<$_> の内容を表示するために FILEHANDLE のみを使用するには、 |
11335 | 11016 | C<$fh> のような間接ファイルハンドルではなく、C<FH> のような実際の |
11336 | 11017 | ファイルハンドルを使わなければなりません。 |
11337 | 11018 | デフォルトの出力チャネルを STDOUT 以外にするには、select 演算子を |
11338 | 11019 | 使ってください。 |
11339 | 11020 | |
11340 | 11021 | =begin original |
11341 | 11022 | |
11342 | 11023 | The current value of C<$,> (if any) is printed between each LIST item. The |
11343 | 11024 | current value of C<$\> (if any) is printed after the entire LIST has been |
11344 | 11025 | printed. Because print takes a LIST, anything in the LIST is evaluated in |
11345 | 11026 | list context, including any subroutines whose return lists you pass to |
11346 | 11027 | C<print>. Be careful not to follow the print keyword with a left |
11347 | 11028 | parenthesis unless you want the corresponding right parenthesis to |
11348 | 11029 | terminate the arguments to the print; put parentheses around all arguments |
11349 | 11030 | (or interpose a C<+>, but that doesn't look as good). |
11350 | 11031 | |
11351 | 11032 | =end original |
11352 | 11033 | |
11353 | 11034 | C<$,> の値が(もしあれば)各 LIST 要素の間に出力されます。 |
11354 | 11035 | LIST 全体が出力された後、(もしあれば) C<$\> の現在の値が出力されます。 |
11355 | 11036 | print の引数は LIST なので、LIST の中のものは、すべてリストコンテキストで |
11356 | 11037 | 評価されます; C<print> に渡した、リストを返すサブルーチンも含みます。 |
11357 | 11038 | また、すべての引数を括弧で括るのでなければ、print というキーワードの |
11358 | 11039 | 次に開き括弧を書いてはいけません; すべての引数を括弧で括ってください |
11359 | 11040 | (あるいは "print" と引数の間に C<+> を書きますが、これはあまり |
11360 | 11041 | よくありません)。 |
11361 | 11042 | |
11362 | 11043 | =begin original |
11363 | 11044 | |
11364 | 11045 | If you're storing handles in an array or hash, or in general whenever |
11365 | 11046 | you're using any expression more complex than a bareword handle or a plain, |
11366 | 11047 | unsubscripted scalar variable to retrieve it, you will have to use a block |
11367 | 11048 | returning the filehandle value instead, in which case the LIST may not be |
11368 | 11049 | omitted: |
11369 | 11050 | |
11370 | 11051 | =end original |
11371 | 11052 | |
11372 | 11053 | もし FILESHANDLE を配列、ハッシュあるいは一般的には裸の単語のハンドルや |
11373 | 11054 | 普通のスカラ変数よりも複雑な表現を使っている場合、代わりにその値を返す |
11374 | 11055 | ブロックを使う必要があります; この場合 LIST は省略できません: |
11375 | 11056 | |
11376 | 11057 | print { $files[$i] } "stuff\n"; |
11377 | 11058 | print { $OK ? STDOUT : STDERR } "stuff\n"; |
11378 | 11059 | |
11379 | 11060 | =begin original |
11380 | 11061 | |
11381 | 11062 | Printing to a closed pipe or socket will generate a SIGPIPE signal. See |
11382 | 11063 | L<perlipc> for more on signal handling. |
11383 | 11064 | |
11384 | 11065 | =end original |
11385 | 11066 | |
11386 | 11067 | 閉じたパイプやソケットに print すると SIGPIPE シグナルが生成されます。 |
11387 | 11068 | さらなるシグナル操作については L<perlipc> を参照してください。 |
11388 | 11069 | |
11389 | 11070 | =item printf FILEHANDLE FORMAT, LIST |
11390 | 11071 | X<printf> |
11391 | 11072 | |
11392 | 11073 | =item printf FILEHANDLE |
11393 | 11074 | |
11394 | 11075 | =item printf FORMAT, LIST |
11395 | 11076 | |
11396 | 11077 | =item printf |
11397 | 11078 | |
11398 | 11079 | =for Pod::Functions output a formatted list to a filehandle |
11399 | 11080 | |
11400 | 11081 | =begin original |
11401 | 11082 | |
11402 | 11083 | Equivalent to C<print FILEHANDLE sprintf(FORMAT, LIST)>, except that C<$\> |
11403 | (the output record separator) is not appended. The | |
11084 | (the output record separator) is not appended. The first argument of the | |
11404 | ||
11085 | list will be interpreted as the C<printf> format. See | |
11405 | of the list will be interpreted as the C<printf> format. This | |
11406 | means that C<printf(@_)> will use C<$_[0]> as the format. See | |
11407 | 11086 | L<sprintf|/sprintf FORMAT, LIST> for an |
11408 | explanation of the format argument. If | |
11087 | explanation of the format argument. If you omit the LIST, C<$_> is used; | |
11088 | to use FILEHANDLE without a LIST, you must use a real filehandle like | |
11089 | C<FH>, not an indirect one like C<$fh>. If C<use locale> (including | |
11409 | 11090 | C<use locale ':not_characters'>) is in effect and |
11410 | 11091 | POSIX::setlocale() has been called, the character used for the decimal |
11411 | 11092 | separator in formatted floating-point numbers is affected by the LC_NUMERIC |
11412 | 11093 | locale setting. See L<perllocale> and L<POSIX>. |
11413 | 11094 | |
11414 | 11095 | =end original |
11415 | 11096 | |
11416 | 11097 | C<$\>(出力レコードセパレータ)を追加しないことを除けば、 |
11417 | 11098 | C<print FILEHANDLE sprintf(FORMAT, LIST)> と等価です。 |
11418 | FORMAT と LIST は実際には単一のリストとしてパースされます。 | |
11419 | 11099 | リストの最初の要素は、C<printf> フォーマットと解釈されます。 |
11420 | これは、C<printf(@_)> はフォーマットとして C<$_[0]> を使うということです。 | |
11421 | 11100 | フォーマット引数の説明については L<sprintf|/sprintf FORMAT, LIST> を |
11422 | 11101 | 参照してください。 |
11102 | LIST を省略すると、C<$_> が使われます; | |
11103 | LIST なしで FILEHANDLE を使用するには、 | |
11104 | C<$fh> のような間接ファイルハンドルではなく、C<FH> のような実際の | |
11105 | ファイルハンドルを使わなければなりません。 | |
11423 | 11106 | (C<use locale ':not_characters'> を含む) C<use locale> が効力をもっていて、 |
11424 | 11107 | POSIX::setlocale() が呼び出されていれば、 |
11425 | 11108 | 小数点に使われる文字は LC_NUMERIC ロケール設定の影響を受けます。 |
11426 | 11109 | L<perllocale> と L<POSIX> を参照してください。 |
11427 | 11110 | |
11428 | 11111 | =begin original |
11429 | 11112 | |
11430 | For historical reasons, if you omit the list, C<$_> is used as the format; | |
11431 | to use FILEHANDLE without a list, you must use a real filehandle like | |
11432 | C<FH>, not an indirect one like C<$fh>. However, this will rarely do what | |
11433 | you want; if $_ contains formatting codes, they will be replaced with the | |
11434 | empty string and a warning will be emitted if warnings are enabled. Just | |
11435 | use C<print> if you want to print the contents of $_. | |
11436 | ||
11437 | =end original | |
11438 | ||
11439 | 歴史的な理由により、リストを省略すると、フォーマットとして C<$_> が使われます; | |
11440 | リストなしで FILEHANDLE を使用するには、C<$fh> のような | |
11441 | 間接ファイルハンドルではなく、C<FH> のような実際の | |
11442 | ファイルハンドルを使わなければなりません。 | |
11443 | しかし、これがあなたが求めていることをすることはまれです; $_ が | |
11444 | フォーマッティングコードの場合、空文字列に置き換えられ、警告が有効なら | |
11445 | 警告が出力されます。 | |
11446 | $_ の内容を表示したい場合は、単に C<print> を使ってください。 | |
11447 | ||
11448 | =begin original | |
11449 | ||
11450 | 11113 | Don't fall into the trap of using a C<printf> when a simple |
11451 | 11114 | C<print> would do. The C<print> is more efficient and less |
11452 | 11115 | error prone. |
11453 | 11116 | |
11454 | 11117 | =end original |
11455 | 11118 | |
11456 | 11119 | 単純な C<print> を使うべきところで C<printf> を使ってしまう |
11457 | 11120 | 罠にかからないようにしてください。 |
11458 | 11121 | C<print> はより効率的で、間違いが起こりにくいです。 |
11459 | 11122 | |
11460 | 11123 | =item prototype FUNCTION |
11461 | 11124 | X<prototype> |
11462 | 11125 | |
11463 | 11126 | =for Pod::Functions +5.002 get the prototype (if any) of a subroutine |
11464 | 11127 | |
11465 | 11128 | =begin original |
11466 | 11129 | |
11467 | 11130 | Returns the prototype of a function as a string (or C<undef> if the |
11468 | 11131 | function has no prototype). FUNCTION is a reference to, or the name of, |
11469 | 11132 | the function whose prototype you want to retrieve. |
11470 | 11133 | |
11471 | 11134 | =end original |
11472 | 11135 | |
11473 | 11136 | 関数のプロトタイプを文字列として返します(関数にプロトタイプがない場合は |
11474 | 11137 | C<undef> を返します)。 |
11475 | 11138 | FUNCTION はプロトタイプを得たい関数の名前、またはリファレンスです。 |
11476 | 11139 | |
11477 | 11140 | =begin original |
11478 | 11141 | |
11479 | 11142 | If FUNCTION is a string starting with C<CORE::>, the rest is taken as a |
11480 | name for a Perl builtin. If the builtin | |
11143 | name for a Perl builtin. If the builtin is not I<overridable> (such as | |
11481 | cannot be adequately expressed by a prototype | |
11144 | C<qw//>) or if its arguments cannot be adequately expressed by a prototype | |
11482 | 11145 | (such as C<system>), prototype() returns C<undef>, because the builtin |
11483 | 11146 | does not really behave like a Perl function. Otherwise, the string |
11484 | 11147 | describing the equivalent prototype is returned. |
11485 | 11148 | |
11486 | 11149 | =end original |
11487 | 11150 | |
11488 | 11151 | FUNCTION が C<CORE::> で始まっている場合、残りは Perl ビルドインの名前として |
11489 | 11152 | 扱われます。 |
11490 | このビルドイン | |
11153 | このビルドインが(C<qw//> のように) I<オーバーライド可能> でない、 | |
11491 | 記述できない場合、 | |
11154 | またはこの引数が(C<system> のように)プロトタイプとして適切に記述できない場合、 | |
11155 | prototype() は C<undef> を返します; | |
11492 | 11156 | なぜならビルドインは実際に Perl 関数のように振舞わないからです。 |
11493 | 11157 | それ以外では、等価なプロトタイプを表現した文字列が返されます。 |
11494 | 11158 | |
11495 | 11159 | =item push ARRAY,LIST |
11496 | 11160 | X<push> X<stack> |
11497 | 11161 | |
11498 | 11162 | =item push EXPR,LIST |
11499 | 11163 | |
11500 | 11164 | =for Pod::Functions append one or more elements to an array |
11501 | 11165 | |
11502 | 11166 | =begin original |
11503 | 11167 | |
11504 | 11168 | Treats ARRAY as a stack by appending the values of LIST to the end of |
11505 | 11169 | ARRAY. The length of ARRAY increases by the length of LIST. Has the same |
11506 | 11170 | effect as |
11507 | 11171 | |
11508 | 11172 | =end original |
11509 | 11173 | |
11510 | 11174 | ARRAY をスタックとして扱い、LIST 内の値を ARRAY の終わりに追加します。 |
11511 | 11175 | ARRAY の大きさは、LIST の長さ分だけ大きくなります。 |
11512 | 11176 | これは、 |
11513 | 11177 | |
11514 | 11178 | for $value (LIST) { |
11515 | 11179 | $ARRAY[++$#ARRAY] = $value; |
11516 | 11180 | } |
11517 | 11181 | |
11518 | 11182 | =begin original |
11519 | 11183 | |
11520 | 11184 | but is more efficient. Returns the number of elements in the array following |
11521 | 11185 | the completed C<push>. |
11522 | 11186 | |
11523 | 11187 | =end original |
11524 | 11188 | |
11525 | 11189 | とするのと同じ効果がありますが、より効率的です。 |
11526 | 11190 | C<push> の処理終了後の配列の要素数を返します。 |
11527 | 11191 | |
11528 | 11192 | =begin original |
11529 | 11193 | |
11530 | 11194 | Starting with Perl 5.14, C<push> can take a scalar EXPR, which must hold a |
11531 | 11195 | reference to an unblessed array. The argument will be dereferenced |
11532 | 11196 | automatically. This aspect of C<push> is considered highly experimental. |
11533 | 11197 | The exact behaviour may change in a future version of Perl. |
11534 | 11198 | |
11535 | 11199 | =end original |
11536 | 11200 | |
11537 | 11201 | Perl 5.14 から、C<push> はスカラの EXPR を取ることができるようになりました; |
11538 | 11202 | これは bless されていない配列へのリファレンスでなければなりません。 |
11539 | 11203 | 引数は自動的にデリファレンスされます。 |
11540 | 11204 | C<push> のこの動作は高度に実験的であると考えられています。 |
11541 | 11205 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 |
11542 | 11206 | |
11543 | 11207 | =begin original |
11544 | 11208 | |
11545 | 11209 | To avoid confusing would-be users of your code who are running earlier |
11546 | 11210 | versions of Perl with mysterious syntax errors, put this sort of thing at |
11547 | 11211 | the top of your file to signal that your code will work I<only> on Perls of |
11548 | 11212 | a recent vintage: |
11549 | 11213 | |
11550 | 11214 | =end original |
11551 | 11215 | |
11552 | 11216 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な |
11553 | 11217 | 文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で |
11554 | 11218 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを |
11555 | 11219 | 書いてください: |
11556 | 11220 | |
11557 | 11221 | use 5.014; # so push/pop/etc work on scalars (experimental) |
11558 | 11222 | |
11559 | 11223 | =item q/STRING/ |
11560 | 11224 | |
11561 | 11225 | =for Pod::Functions singly quote a string |
11562 | 11226 | |
11563 | 11227 | =item qq/STRING/ |
11564 | 11228 | |
11565 | 11229 | =for Pod::Functions doubly quote a string |
11566 | 11230 | |
11567 | 11231 | =item qw/STRING/ |
11568 | 11232 | |
11569 | 11233 | =for Pod::Functions quote a list of words |
11570 | 11234 | |
11571 | 11235 | =item qx/STRING/ |
11572 | 11236 | |
11573 | 11237 | =for Pod::Functions backquote quote a string |
11574 | 11238 | |
11575 | 11239 | =begin original |
11576 | 11240 | |
11577 | 11241 | Generalized quotes. See L<perlop/"Quote-Like Operators">. |
11578 | 11242 | |
11579 | 11243 | =end original |
11580 | 11244 | |
11581 | 11245 | 汎用のクォートです。 |
11582 | 11246 | L<perlop/"Quote-Like Operators"> を参照してください。 |
11583 | 11247 | |
11584 | 11248 | =item qr/STRING/ |
11585 | 11249 | |
11586 | 11250 | =for Pod::Functions +5.005 compile pattern |
11587 | 11251 | |
11588 | 11252 | =begin original |
11589 | 11253 | |
11590 | 11254 | Regexp-like quote. See L<perlop/"Regexp Quote-Like Operators">. |
11591 | 11255 | |
11592 | 11256 | =end original |
11593 | 11257 | |
11594 | 11258 | 正規表現風のクォートです。 |
11595 | 11259 | L<perlop/"Regexp Quote-Like Operators"> を参照してください。 |
11596 | 11260 | |
11597 | 11261 | =item quotemeta EXPR |
11598 | 11262 | X<quotemeta> X<metacharacter> |
11599 | 11263 | |
11600 | 11264 | =item quotemeta |
11601 | 11265 | |
11602 | 11266 | =for Pod::Functions quote regular expression magic characters |
11603 | 11267 | |
11604 | 11268 | =begin original |
11605 | 11269 | |
11606 | 11270 | Returns the value of EXPR with all the ASCII non-"word" |
11607 | 11271 | characters backslashed. (That is, all ASCII characters not matching |
11608 | 11272 | C</[A-Za-z_0-9]/> will be preceded by a backslash in the |
11609 | 11273 | returned string, regardless of any locale settings.) |
11610 | 11274 | This is the internal function implementing |
11611 | 11275 | the C<\Q> escape in double-quoted strings. |
11612 | 11276 | (See below for the behavior on non-ASCII code points.) |
11613 | 11277 | |
11614 | 11278 | =end original |
11615 | 11279 | |
11616 | 11280 | EXPR の中のすべての ASCII 非英数字キャラクタをバックスラッシュで |
11617 | 11281 | エスケープしたものを返します。 |
11618 | 11282 | (つまり、C</[A-Za-z_0-9]/> にマッチしない全ての ASCII 文字の前には |
11619 | 11283 | ロケールに関わらずバックスラッシュが前置されます。) |
11620 | 11284 | これは、ダブルクォート文字列での C<\Q> エスケープを実装するための |
11621 | 11285 | 内部関数です。 |
11622 | 11286 | (非 ASCII 符号位置での振る舞いについては以下を参照してください。) |
11623 | 11287 | |
11624 | 11288 | =begin original |
11625 | 11289 | |
11626 | 11290 | If EXPR is omitted, uses C<$_>. |
11627 | 11291 | |
11628 | 11292 | =end original |
11629 | 11293 | |
11630 | 11294 | EXPR が省略されると、C<$_> を使います。 |
11631 | 11295 | |
11632 | 11296 | =begin original |
11633 | 11297 | |
11634 | 11298 | quotemeta (and C<\Q> ... C<\E>) are useful when interpolating strings into |
11635 | 11299 | regular expressions, because by default an interpolated variable will be |
11636 | 11300 | considered a mini-regular expression. For example: |
11637 | 11301 | |
11638 | 11302 | =end original |
11639 | 11303 | |
11640 | 11304 | クォートメタ (と C<\Q> ... C<\E>) は、文字列を正規表現に展開するのに |
11641 | 11305 | 便利です; なぜなら、デフォルトでは展開された変数は小さな正規表現として |
11642 | 11306 | 扱われるからです。 |
11643 | 11307 | 例えば: |
11644 | 11308 | |
11645 | 11309 | my $sentence = 'The quick brown fox jumped over the lazy dog'; |
11646 | 11310 | my $substring = 'quick.*?fox'; |
11647 | 11311 | $sentence =~ s{$substring}{big bad wolf}; |
11648 | 11312 | |
11649 | 11313 | =begin original |
11650 | 11314 | |
11651 | 11315 | Will cause C<$sentence> to become C<'The big bad wolf jumped over...'>. |
11652 | 11316 | |
11653 | 11317 | =end original |
11654 | 11318 | |
11655 | 11319 | とすると、C<$sentence> は C<'The big bad wolf jumped over...'> になります。 |
11656 | 11320 | |
11657 | 11321 | =begin original |
11658 | 11322 | |
11659 | 11323 | On the other hand: |
11660 | 11324 | |
11661 | 11325 | =end original |
11662 | 11326 | |
11663 | 11327 | 一方: |
11664 | 11328 | |
11665 | 11329 | my $sentence = 'The quick brown fox jumped over the lazy dog'; |
11666 | 11330 | my $substring = 'quick.*?fox'; |
11667 | 11331 | $sentence =~ s{\Q$substring\E}{big bad wolf}; |
11668 | 11332 | |
11669 | 11333 | =begin original |
11670 | 11334 | |
11671 | 11335 | Or: |
11672 | 11336 | |
11673 | 11337 | =end original |
11674 | 11338 | |
11675 | 11339 | あるいは: |
11676 | 11340 | |
11677 | 11341 | my $sentence = 'The quick brown fox jumped over the lazy dog'; |
11678 | 11342 | my $substring = 'quick.*?fox'; |
11679 | 11343 | my $quoted_substring = quotemeta($substring); |
11680 | 11344 | $sentence =~ s{$quoted_substring}{big bad wolf}; |
11681 | 11345 | |
11682 | 11346 | =begin original |
11683 | 11347 | |
11684 | 11348 | Will both leave the sentence as is. |
11685 | 11349 | Normally, when accepting literal string |
11686 | 11350 | input from the user, quotemeta() or C<\Q> must be used. |
11687 | 11351 | |
11688 | 11352 | =end original |
11689 | 11353 | |
11690 | 11354 | とすると、両方ともそのままです。 |
11691 | 11355 | 普通は、ユーザーからのリテラルな文字列入力を受け付ける場合は、 |
11692 | 11356 | 必ず quotemeta() か C<\Q> を使わなければなりません。 |
11693 | 11357 | |
11694 | 11358 | =begin original |
11695 | 11359 | |
11696 | 11360 | In Perl v5.14, all non-ASCII characters are quoted in non-UTF-8-encoded |
11697 | 11361 | strings, but not quoted in UTF-8 strings. |
11698 | 11362 | |
11699 | 11363 | =end original |
11700 | 11364 | |
11701 | 11365 | Perl v5.14 では、全ての非 ASCII 文字は非 UTF-8 エンコードされた |
11702 | 11366 | 文字列ではクォートされませんが、UTF-8 文字列ではクォートされます。 |
11703 | 11367 | |
11704 | 11368 | =begin original |
11705 | 11369 | |
11706 | 11370 | Starting in Perl v5.16, Perl adopted a Unicode-defined strategy for |
11707 | 11371 | quoting non-ASCII characters; the quoting of ASCII characters is |
11708 | 11372 | unchanged. |
11709 | 11373 | |
11710 | 11374 | =end original |
11711 | 11375 | |
11712 | 11376 | Perl v5.16 から、Perl は非 ASCII 文字をクォートするのに Unicode で |
11713 | 11377 | 定義された戦略を採用しました; ASCII 文字のクォートは変わりません。 |
11714 | 11378 | |
11715 | 11379 | =begin original |
11716 | 11380 | |
11717 | 11381 | Also unchanged is the quoting of non-UTF-8 strings when outside the |
11718 | 11382 | scope of a C<use feature 'unicode_strings'>, which is to quote all |
11719 | 11383 | characters in the upper Latin1 range. This provides complete backwards |
11720 | 11384 | compatibility for old programs which do not use Unicode. (Note that |
11721 | 11385 | C<unicode_strings> is automatically enabled within the scope of a |
11722 | 11386 | S<C<use v5.12>> or greater.) |
11723 | 11387 | |
11724 | 11388 | =end original |
11725 | 11389 | |
11726 | 11390 | また、C<use feature 'unicode_strings'> の範囲外で非 UTF-8 文字列を |
11727 | 11391 | クォートするのも変わりません; 上位の Latin1 の範囲の全ての文字を |
11728 | 11392 | クォートします。 |
11729 | これは Unicode を使わない古いプログラムに対して完全な後方互換性を | |
11393 | これは Unicode を使わない古いプログラムに対して完全な後方互換性を | |
11394 | 提供します。 | |
11730 | 11395 | (C<unicode_strings> は S<C<use v5.12>> またはそれ以上のスコープでは |
11731 | 11396 | 自動的に有効になることに注意してください。) |
11732 | 11397 | |
11733 | 11398 | =begin original |
11734 | 11399 | |
11735 | 11400 | Within the scope of C<use locale>, all non-ASCII Latin1 code points |
11736 | 11401 | are quoted whether the string is encoded as UTF-8 or not. As mentioned |
11737 | 11402 | above, locale does not affect the quoting of ASCII-range characters. |
11738 | 11403 | This protects against those locales where characters such as C<"|"> are |
11739 | 11404 | considered to be word characters. |
11740 | 11405 | |
11741 | 11406 | =end original |
11742 | 11407 | |
11743 | 11408 | C<use locale> スコープの内側では、全ての非 ASCII Latin1 符号位置は |
11744 | 11409 | 文字列が UTF-8 でエンコードされているかどうかに関わらずクォートされます。 |
11745 | 11410 | 上述のように、ロケールは ASCII の範囲の文字のクォートに影響を与えません。 |
11746 | 11411 | これは C<"|"> のような文字が単語文字として考えられるロケールから守ります。 |
11747 | 11412 | |
11748 | 11413 | =begin original |
11749 | 11414 | |
11750 | 11415 | Otherwise, Perl quotes non-ASCII characters using an adaptation from |
11751 | Unicode (see L<http://www.unicode.org/reports/tr31/> | |
11416 | Unicode (see L<http://www.unicode.org/reports/tr31/>.) | |
11752 | 11417 | The only code points that are quoted are those that have any of the |
11753 | 11418 | Unicode properties: Pattern_Syntax, Pattern_White_Space, White_Space, |
11754 | 11419 | Default_Ignorable_Code_Point, or General_Category=Control. |
11755 | 11420 | |
11756 | 11421 | =end original |
11757 | 11422 | |
11758 | 11423 | さもなければ、Perl は Unicode からの本版を使って非 ASCII 文字をクォートします |
11759 | 11424 | (L<http://www.unicode.org/reports/tr31/> 参照)。 |
11760 | 11425 | クォートされる符号位置は以下のどれかの Unicode を特性を持つものだけです: |
11761 | 11426 | Pattern_Syntax, Pattern_White_Space, White_Space, |
11762 | 11427 | Default_Ignorable_Code_Point, or General_Category=Control。 |
11763 | 11428 | |
11764 | 11429 | =begin original |
11765 | 11430 | |
11766 | 11431 | Of these properties, the two important ones are Pattern_Syntax and |
11767 | 11432 | Pattern_White_Space. They have been set up by Unicode for exactly this |
11768 | 11433 | purpose of deciding which characters in a regular expression pattern |
11769 | 11434 | should be quoted. No character that can be in an identifier has these |
11770 | 11435 | properties. |
11771 | 11436 | |
11772 | 11437 | =end original |
11773 | 11438 | |
11774 | 11439 | これらの特性の中で、重要な二つは Pattern_Syntax と Pattern_White_Space です。 |
11775 | 11440 | これらはまさに正規表現中パターン中のどの文字をクォートするべきかを |
11776 | 11441 | 決定するという目的のために Unicode によって設定されています。 |
11777 | 11442 | 識別子になる文字はこれらの特性はありません。 |
11778 | 11443 | |
11779 | 11444 | =begin original |
11780 | 11445 | |
11781 | 11446 | Perl promises, that if we ever add regular expression pattern |
11782 | 11447 | metacharacters to the dozen already defined |
11783 | 11448 | (C<\ E<verbar> ( ) [ { ^ $ * + ? .>), that we will only use ones that have the |
11784 | 11449 | Pattern_Syntax property. Perl also promises, that if we ever add |
11785 | 11450 | characters that are considered to be white space in regular expressions |
11786 | 11451 | (currently mostly affected by C</x>), they will all have the |
11787 | 11452 | Pattern_White_Space property. |
11788 | 11453 | |
11789 | 11454 | =end original |
11790 | 11455 | |
11791 | 11456 | Perl は、正規表現メタ文字として既に定義されている |
11792 | 11457 | (C<\ E<verbar> ( ) [ { ^ $ * + ? .>) ものに追加するときは、 |
11793 | 11458 | Pattern_Syntax 特性を持つものだけを使うことを約束します。 |
11794 | 11459 | Perl はまた、(現在の所ほとんどは C</x> よって影響される)正規表現中で空白と |
11795 | 11460 | 考えられる文字に追加するときは、Pattern_White_Space 特性を |
11796 | 11461 | 持つものであることを約束します。 |
11797 | 11462 | |
11798 | 11463 | =begin original |
11799 | 11464 | |
11800 | 11465 | Unicode promises that the set of code points that have these two |
11801 | 11466 | properties will never change, so something that is not quoted in v5.16 |
11802 | 11467 | will never need to be quoted in any future Perl release. (Not all the |
11803 | 11468 | code points that match Pattern_Syntax have actually had characters |
11804 | 11469 | assigned to them; so there is room to grow, but they are quoted |
11805 | 11470 | whether assigned or not. Perl, of course, would never use an |
11806 | 11471 | unassigned code point as an actual metacharacter.) |
11807 | 11472 | |
11808 | 11473 | =end original |
11809 | 11474 | |
11810 | 11475 | Unicode はこれら二つの特性を持つ符号位置の集合が決して変わらないことを |
11811 | 11476 | 約束しているので、v5.16 でクォートされないものは将来の Perl リリースでも |
11812 | 11477 | クォートする必要はありません。 |
11813 | 11478 | (Pattern_Syntax にマッチングする全ての符号位置が実際に割り当てられている |
11814 | 11479 | 文字を持っているわけではありません; したがって拡張する余地がありますが、 |
11815 | 11480 | 割り当てられているかどうかに関わらずクォートされます。 |
11816 | 11481 | Perl はもちろん割り当てられていない符号位置を実際のメタ文字として使うことは |
11817 | 11482 | ありません。) |
11818 | 11483 | |
11819 | 11484 | =begin original |
11820 | 11485 | |
11821 | 11486 | Quoting characters that have the other 3 properties is done to enhance |
11822 | 11487 | the readability of the regular expression and not because they actually |
11823 | 11488 | need to be quoted for regular expression purposes (characters with the |
11824 | 11489 | White_Space property are likely to be indistinguishable on the page or |
11825 | 11490 | screen from those with the Pattern_White_Space property; and the other |
11826 | 11491 | two properties contain non-printing characters). |
11827 | 11492 | |
11828 | 11493 | =end original |
11829 | 11494 | |
11830 | 11495 | その他の 3 特性を持つ文字のクォートは正規表現の可読性を向上させるために |
11831 | 11496 | 行われ、実際には正規表現の目的でクォートする必要があるからではありません |
11832 | 11497 | (White_Space 特性を持つ文字は表示上は Pattern_White_Space 特性を持つ文字と |
11833 | 11498 | おそらく区別が付かないでしょう; そして残りの |
11834 | 11499 | 二つの特性は非表示文字を含んでいます). |
11835 | 11500 | |
11836 | 11501 | =item rand EXPR |
11837 | 11502 | X<rand> X<random> |
11838 | 11503 | |
11839 | 11504 | =item rand |
11840 | 11505 | |
11841 | 11506 | =for Pod::Functions retrieve the next pseudorandom number |
11842 | 11507 | |
11843 | 11508 | =begin original |
11844 | 11509 | |
11845 | 11510 | Returns a random fractional number greater than or equal to C<0> and less |
11846 | 11511 | than the value of EXPR. (EXPR should be positive.) If EXPR is |
11847 | 11512 | omitted, the value C<1> is used. Currently EXPR with the value C<0> is |
11848 | 11513 | also special-cased as C<1> (this was undocumented before Perl 5.8.0 |
11849 | 11514 | and is subject to change in future versions of Perl). Automatically calls |
11850 | 11515 | C<srand> unless C<srand> has already been called. See also C<srand>. |
11851 | 11516 | |
11852 | 11517 | =end original |
11853 | 11518 | |
11854 | 11519 | C<0> 以上 EXPR の値未満の小数の乱数値を返します。 |
11855 | 11520 | (EXPR は正の数である必要があります。) |
11856 | 11521 | EXPR が省略されると、C<1> が使われます。 |
11857 | 11522 | 現在のところ、EXPR に値 C<0> をセットすると C<1> として特別扱いされます |
11858 | 11523 | (これは Perl 5.8.0 以前には文書化されておらず、将来のバージョンの perl では |
11859 | 11524 | 変更される可能性があります)。 |
11860 | C<srand> が既に呼ばれている場合以外は、自動的に C<srand> 関数を | |
11525 | C<srand> が既に呼ばれている場合以外は、自動的に C<srand> 関数を | |
11526 | 呼び出します。 | |
11861 | 11527 | C<srand> も参照してください。 |
11862 | 11528 | |
11863 | 11529 | =begin original |
11864 | 11530 | |
11865 | 11531 | Apply C<int()> to the value returned by C<rand()> if you want random |
11866 | 11532 | integers instead of random fractional numbers. For example, |
11867 | 11533 | |
11868 | 11534 | =end original |
11869 | 11535 | |
11870 | 11536 | ランダムな小数ではなく、ランダムな整数がほしい場合は、C<rand()> から |
11871 | 11537 | 返された値に C<int()> を適用してください。 |
11872 | 11538 | 例えば: |
11873 | 11539 | |
11874 | 11540 | int(rand(10)) |
11875 | 11541 | |
11876 | 11542 | =begin original |
11877 | 11543 | |
11878 | 11544 | returns a random integer between C<0> and C<9>, inclusive. |
11879 | 11545 | |
11880 | 11546 | =end original |
11881 | 11547 | |
11882 | 11548 | これは C<0> から C<9> の値をランダムに返します。 |
11883 | 11549 | |
11884 | 11550 | =begin original |
11885 | 11551 | |
11886 | 11552 | (Note: If your rand function consistently returns numbers that are too |
11887 | 11553 | large or too small, then your version of Perl was probably compiled |
11888 | 11554 | with the wrong number of RANDBITS.) |
11889 | 11555 | |
11890 | 11556 | =end original |
11891 | 11557 | |
11892 | 11558 | (注: もし、rand 関数が、常に大きい値ばかりや、小さい数ばかりを |
11893 | 11559 | 返すようなら、お使いになっている Perl が、 |
11894 | 11560 | 良くない RANDBITS を使ってコンパイルされている可能性があります。) |
11895 | 11561 | |
11896 | 11562 | =begin original |
11897 | 11563 | |
11898 | 11564 | B<C<rand()> is not cryptographically secure. You should not rely |
11899 | 11565 | on it in security-sensitive situations.> As of this writing, a |
11900 | 11566 | number of third-party CPAN modules offer random number generators |
11901 | 11567 | intended by their authors to be cryptographically secure, |
11902 | 11568 | including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>, |
11903 | 11569 | and L<Math::TrulyRandom>. |
11904 | 11570 | |
11905 | 11571 | =end original |
11906 | 11572 | |
11907 | 11573 | B<C<rand()> は暗号学的に安全ではありません。 |
11908 | 11574 | セキュリティ的に重要な状況でこれに頼るべきではありません。> |
11909 | 11575 | これを書いている時点で、いくつかのサードパーティ CPAN モジュールが |
11910 | 作者によって暗号学的に安全であることを目的とした乱数生成器を | |
11576 | 作者によって暗号学的に安全であることを目的とした乱数生成器を | |
11911 | L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>, | |
11577 | 提供しています: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>, | |
11912 | 11578 | L<Math::TrulyRandom> などです。 |
11913 | 11579 | |
11914 | 11580 | =item read FILEHANDLE,SCALAR,LENGTH,OFFSET |
11915 | 11581 | X<read> X<file, read> |
11916 | 11582 | |
11917 | 11583 | =item read FILEHANDLE,SCALAR,LENGTH |
11918 | 11584 | |
11919 | 11585 | =for Pod::Functions fixed-length buffered input from a filehandle |
11920 | 11586 | |
11921 | 11587 | =begin original |
11922 | 11588 | |
11923 | 11589 | Attempts to read LENGTH I<characters> of data into variable SCALAR |
11924 | 11590 | from the specified FILEHANDLE. Returns the number of characters |
11925 | 11591 | actually read, C<0> at end of file, or undef if there was an error (in |
11926 | 11592 | the latter case C<$!> is also set). SCALAR will be grown or shrunk |
11927 | 11593 | so that the last character actually read is the last character of the |
11928 | 11594 | scalar after the read. |
11929 | 11595 | |
11930 | 11596 | =end original |
11931 | 11597 | |
11932 | 指定した FILEHANDLE から、変数 SCALAR に LENGTH I<文字> の | |
11598 | 指定した FILEHANDLE から、変数 SCALAR に LENGTH I<文字> の | |
11933 | 読み込みます。 | |
11599 | データを読み込みます。 | |
11934 | 実際に読み込まれた文字数、 | |
11600 | 実際に読み込まれた文字数、 | |
11935 | ||
11601 | ファイル終端の場合は C<0>、エラーの場合は undef のいずれかを返します | |
11936 | ||
11602 | (後者の場合、C<$!> もセットされます)。 | |
11937 | ||
11603 | SCALAR は伸び縮みするので、 | |
11604 | 読み込み後は、実際に読み込んだ最後の文字がスカラの最後の文字になります。 | |
11938 | 11605 | |
11939 | 11606 | =begin original |
11940 | 11607 | |
11941 | 11608 | An OFFSET may be specified to place the read data at some place in the |
11942 | 11609 | string other than the beginning. A negative OFFSET specifies |
11943 | 11610 | placement at that many characters counting backwards from the end of |
11944 | 11611 | the string. A positive OFFSET greater than the length of SCALAR |
11945 | 11612 | results in the string being padded to the required size with C<"\0"> |
11946 | 11613 | bytes before the result of the read is appended. |
11947 | 11614 | |
11948 | 11615 | =end original |
11949 | 11616 | |
11950 | 11617 | OFFSET を指定すると、文字列の先頭以外の場所から、読み込みを行なうことが |
11951 | 11618 | できます。 |
11952 | 11619 | OFFSET に負の値を指定すると、文字列の最後から逆向きに何文字目かで |
11953 | 11620 | 位置を指定します。 |
11954 | OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は | |
11621 | OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は | |
11955 | 追加される前に、必要なサイズまで C<"\0"> のバイトで | |
11622 | 読み込みの結果が追加される前に、必要なサイズまで C<"\0"> のバイトで | |
11623 | パッディングされます。 | |
11956 | 11624 | |
11957 | 11625 | =begin original |
11958 | 11626 | |
11959 | 11627 | The call is implemented in terms of either Perl's or your system's native |
11960 | 11628 | fread(3) library function. To get a true read(2) system call, see |
11961 | 11629 | L<sysread|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>. |
11962 | 11630 | |
11963 | 11631 | =end original |
11964 | 11632 | |
11965 | 11633 | この関数は、Perl か システムの fread(3) ライブラリ関数を使って実装しています。 |
11966 | 11634 | 本当の read(2) システムコールを利用するには、 |
11967 | 11635 | L<sysread|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を参照してください。 |
11968 | 11636 | |
11969 | 11637 | =begin original |
11970 | 11638 | |
11971 | 11639 | Note the I<characters>: depending on the status of the filehandle, |
11972 | 11640 | either (8-bit) bytes or characters are read. By default, all |
11973 | 11641 | filehandles operate on bytes, but for example if the filehandle has |
11974 | 11642 | been opened with the C<:utf8> I/O layer (see L</open>, and the C<open> |
11975 | 11643 | pragma, L<open>), the I/O will operate on UTF8-encoded Unicode |
11976 | 11644 | characters, not bytes. Similarly for the C<:encoding> pragma: |
11977 | 11645 | in that case pretty much any characters can be read. |
11978 | 11646 | |
11979 | 11647 | =end original |
11980 | 11648 | |
11981 | 11649 | I<文字> に関する注意: ファイルハンドルの状態によって、(8 ビットの) バイトか |
11982 | 11650 | 文字が読み込まれます。 |
11983 | 11651 | デフォルトでは全てのファイルハンドルはバイトを処理しますが、 |
11984 | 11652 | 例えばファイルハンドルが C<:utf8> I/O 層(L</open>, C<open> プラグマ、 |
11985 | 11653 | L<open> を参照してください) で開かれた場合、I/O はバイトではなく、 |
11986 | 11654 | UTF8 エンコードされた Unicode 文字を操作します。 |
11987 | 11655 | C<:encoding> プラグマも同様です: |
11988 | 11656 | この場合、ほとんど大体全ての文字が読み込めます。 |
11989 | 11657 | |
11990 | 11658 | =item readdir DIRHANDLE |
11991 | 11659 | X<readdir> |
11992 | 11660 | |
11993 | 11661 | =for Pod::Functions get a directory from a directory handle |
11994 | 11662 | |
11995 | 11663 | =begin original |
11996 | 11664 | |
11997 | 11665 | Returns the next directory entry for a directory opened by C<opendir>. |
11998 | 11666 | If used in list context, returns all the rest of the entries in the |
11999 | 11667 | directory. If there are no more entries, returns the undefined value in |
12000 | 11668 | scalar context and the empty list in list context. |
12001 | 11669 | |
12002 | 11670 | =end original |
12003 | 11671 | |
12004 | C<opendir> でオープンしたディレクトリで、 | |
11672 | C<opendir> でオープンしたディレクトリで、 | |
12005 | ||
11673 | 次のディレクトリエントリを返します。 | |
12006 | ||
11674 | リストコンテキストで用いると、 | |
11675 | そのディレクトリの残りのエントリを、すべて返します。 | |
12007 | 11676 | エントリが残っていない場合には、スカラコンテキストでは未定義値を、 |
12008 | 11677 | リストコンテキストでは空リストを返します。 |
12009 | 11678 | |
12010 | 11679 | =begin original |
12011 | 11680 | |
12012 | 11681 | If you're planning to filetest the return values out of a C<readdir>, you'd |
12013 | 11682 | better prepend the directory in question. Otherwise, because we didn't |
12014 | 11683 | C<chdir> there, it would have been testing the wrong file. |
12015 | 11684 | |
12016 | 11685 | =end original |
12017 | 11686 | |
12018 | 11687 | C<readdir> の返り値をファイルテストに使おうと計画しているなら、 |
12019 | 11688 | 頭にディレクトリをつける必要があります。 |
12020 | 11689 | さもなければ、ここでは C<chdir> はしないので、 |
12021 | 11690 | 間違ったファイルをテストしてしまうことになるでしょう。 |
12022 | 11691 | |
12023 | 11692 | opendir(my $dh, $some_dir) || die "can't opendir $some_dir: $!"; |
12024 | 11693 | @dots = grep { /^\./ && -f "$some_dir/$_" } readdir($dh); |
12025 | 11694 | closedir $dh; |
12026 | 11695 | |
12027 | 11696 | =begin original |
12028 | 11697 | |
12029 | As of Perl 5.12 you can use a bare C<readdir> in a C<while> loop, | |
11698 | As of Perl 5.11.2 you can use a bare C<readdir> in a C<while> loop, | |
12030 | 11699 | which will set C<$_> on every iteration. |
12031 | 11700 | |
12032 | 11701 | =end original |
12033 | 11702 | |
12034 | Perl 5.12 から裸の C<readdir> を C<while> で使うことができ、 | |
11703 | Perl 5.11.2 から裸の C<readdir> を C<while> で使うことができ、 | |
12035 | 11704 | この場合繰り返し毎に C<$_> にセットされます。 |
12036 | 11705 | |
12037 | 11706 | opendir(my $dh, $some_dir) || die; |
12038 | 11707 | while(readdir $dh) { |
12039 | 11708 | print "$some_dir/$_\n"; |
12040 | 11709 | } |
12041 | 11710 | closedir $dh; |
12042 | 11711 | |
12043 | 11712 | =begin original |
12044 | 11713 | |
12045 | 11714 | To avoid confusing would-be users of your code who are running earlier |
12046 | 11715 | versions of Perl with mysterious failures, put this sort of thing at the |
12047 | 11716 | top of your file to signal that your code will work I<only> on Perls of a |
12048 | 11717 | recent vintage: |
12049 | 11718 | |
12050 | 11719 | =end original |
12051 | 11720 | |
12052 | 11721 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な |
12053 | 11722 | 失敗で混乱することを避けるために、コードが最近のバージョンの Perl で |
12054 | 11723 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを |
12055 | 11724 | 書いてください: |
12056 | 11725 | |
12057 | 11726 | use 5.012; # so readdir assigns to $_ in a lone while test |
12058 | 11727 | |
12059 | 11728 | =item readline EXPR |
12060 | 11729 | |
12061 | 11730 | =item readline |
12062 | 11731 | X<readline> X<gets> X<fgets> |
12063 | 11732 | |
12064 | 11733 | =for Pod::Functions fetch a record from a file |
12065 | 11734 | |
12066 | 11735 | =begin original |
12067 | 11736 | |
12068 | 11737 | Reads from the filehandle whose typeglob is contained in EXPR (or from |
12069 | 11738 | C<*ARGV> if EXPR is not provided). In scalar context, each call reads and |
12070 | 11739 | returns the next line until end-of-file is reached, whereupon the |
12071 | 11740 | subsequent call returns C<undef>. In list context, reads until end-of-file |
12072 | 11741 | is reached and returns a list of lines. Note that the notion of "line" |
12073 | 11742 | used here is whatever you may have defined with C<$/> or |
12074 | 11743 | C<$INPUT_RECORD_SEPARATOR>). See L<perlvar/"$/">. |
12075 | 11744 | |
12076 | 11745 | =end original |
12077 | 11746 | |
12078 | 11747 | 型グロブが EXPR (EXPR がない場合は C<*ARGV>) に含まれている |
12079 | 11748 | ファイルハンドルから読み込みます。 |
12080 | 11749 | スカラコンテキストでは、呼び出し毎に一行読み込んで返します; ファイルの |
12081 | 11750 | 最後まで読み込んだら、以後の呼び出しでは C<undef> を返します。 |
12082 | 11751 | リストコンテキストでは、ファイルの最後まで読み込んで、行のリストを返します。 |
12083 | 11752 | ここでの「行」とは、C<$/> または C<$INPUT_RECORD_SEPARATOR> で |
12084 | 11753 | 定義されることに注意してください。 |
12085 | 11754 | L<perlvar/"$/"> を参照してください。 |
12086 | 11755 | |
12087 | 11756 | =begin original |
12088 | 11757 | |
12089 | 11758 | When C<$/> is set to C<undef>, when C<readline> is in scalar |
12090 | 11759 | context (i.e., file slurp mode), and when an empty file is read, it |
12091 | 11760 | returns C<''> the first time, followed by C<undef> subsequently. |
12092 | 11761 | |
12093 | 11762 | =end original |
12094 | 11763 | |
12095 | 11764 | C<$/> に C<undef> を設定した場合は、C<readline> はスカラコンテキスト |
12096 | 11765 | (つまりファイル吸い込みモード)となり、 |
12097 | 11766 | 空のファイルを読み込んだ場合は、最初は C<''> を返し、 |
12098 | 11767 | それ以降は C<undef> を返します。 |
12099 | 11768 | |
12100 | 11769 | =begin original |
12101 | 11770 | |
12102 | 11771 | This is the internal function implementing the C<< <EXPR> >> |
12103 | 11772 | operator, but you can use it directly. The C<< <EXPR> >> |
12104 | 11773 | operator is discussed in more detail in L<perlop/"I/O Operators">. |
12105 | 11774 | |
12106 | 11775 | =end original |
12107 | 11776 | |
12108 | 11777 | これは C<< <EXPR> >> 演算子を実装している内部関数ですが、 |
12109 | 11778 | 直接使うこともできます。 |
12110 | 11779 | C<< <EXPR> >> 演算子についてのさらなる詳細については |
12111 | 11780 | L<perlop/"I/O Operators"> で議論されています。 |
12112 | 11781 | |
12113 | 11782 | $line = <STDIN>; |
12114 | 11783 | $line = readline(*STDIN); # same thing |
12115 | 11784 | |
12116 | 11785 | =begin original |
12117 | 11786 | |
12118 | 11787 | If C<readline> encounters an operating system error, C<$!> will be set |
12119 | 11788 | with the corresponding error message. It can be helpful to check |
12120 | 11789 | C<$!> when you are reading from filehandles you don't trust, such as a |
12121 | 11790 | tty or a socket. The following example uses the operator form of |
12122 | 11791 | C<readline> and dies if the result is not defined. |
12123 | 11792 | |
12124 | 11793 | =end original |
12125 | 11794 | |
12126 | 11795 | C<readline> が OS のシステムエラーになると、C<$!> に対応するエラーメッセージが |
12127 | 11796 | セットされます。 |
12128 | 11797 | tty やソケットといった、信頼できないファイルハンドルから読み込む時には |
12129 | 11798 | C<$!> をチェックするのが助けになります。 |
12130 | 11799 | 以下の例は演算子の形の C<readline> を使っており、結果が |
12131 | 11800 | 未定義の場合は die します。 |
12132 | 11801 | |
12133 | 11802 | while ( ! eof($fh) ) { |
12134 | 11803 | defined( $_ = <$fh> ) or die "readline failed: $!"; |
12135 | 11804 | ... |
12136 | 11805 | } |
12137 | 11806 | |
12138 | 11807 | =begin original |
12139 | 11808 | |
12140 | 11809 | Note that you have can't handle C<readline> errors that way with the |
12141 | 11810 | C<ARGV> filehandle. In that case, you have to open each element of |
12142 | 11811 | C<@ARGV> yourself since C<eof> handles C<ARGV> differently. |
12143 | 11812 | |
12144 | 11813 | =end original |
12145 | 11814 | |
12146 | 11815 | C<readline> のエラーは C<ARGV> ファイルハンドルの方法では扱えないことに |
12147 | 11816 | 注意してください。 |
12148 | 11817 | この場合、C<eof> は C<ARGV> を異なった方法で扱うので、 |
12149 | 11818 | C<@ARGV> のそれぞれの要素を自分でオープンする必要があります。 |
12150 | 11819 | |
12151 | 11820 | foreach my $arg (@ARGV) { |
12152 | 11821 | open(my $fh, $arg) or warn "Can't open $arg: $!"; |
12153 | 11822 | |
12154 | 11823 | while ( ! eof($fh) ) { |
12155 | 11824 | defined( $_ = <$fh> ) |
12156 | 11825 | or die "readline failed for $arg: $!"; |
12157 | 11826 | ... |
12158 | 11827 | } |
12159 | 11828 | } |
12160 | 11829 | |
12161 | 11830 | =item readlink EXPR |
12162 | 11831 | X<readlink> |
12163 | 11832 | |
12164 | 11833 | =item readlink |
12165 | 11834 | |
12166 | 11835 | =for Pod::Functions determine where a symbolic link is pointing |
12167 | 11836 | |
12168 | 11837 | =begin original |
12169 | 11838 | |
12170 | 11839 | Returns the value of a symbolic link, if symbolic links are |
12171 | 11840 | implemented. If not, raises an exception. If there is a system |
12172 | 11841 | error, returns the undefined value and sets C<$!> (errno). If EXPR is |
12173 | 11842 | omitted, uses C<$_>. |
12174 | 11843 | |
12175 | 11844 | =end original |
12176 | 11845 | |
12177 | シンボリックリンクが実装されていれば、 | |
11846 | シンボリックリンクが実装されていれば、 | |
11847 | シンボリックリンクの値を返します。 | |
12178 | 11848 | 実装されていないときには、例外が発生します。 |
12179 | 11849 | 何らかのシステムエラーが検出されると、未定義値を返し、 |
12180 | 11850 | C<$!> (errno) を設定します。 |
12181 | 11851 | EXPR が省略されると、C<$_> を使います。 |
12182 | 11852 | |
12183 | 11853 | =begin original |
12184 | 11854 | |
12185 | 11855 | Portability issues: L<perlport/readlink>. |
12186 | 11856 | |
12187 | 11857 | =end original |
12188 | 11858 | |
12189 | 11859 | 移植性の問題: L<perlport/readlink>。 |
12190 | 11860 | |
12191 | 11861 | =item readpipe EXPR |
12192 | 11862 | |
12193 | 11863 | =item readpipe |
12194 | 11864 | X<readpipe> |
12195 | 11865 | |
12196 | 11866 | =for Pod::Functions execute a system command and collect standard output |
12197 | 11867 | |
12198 | 11868 | =begin original |
12199 | 11869 | |
12200 | 11870 | EXPR is executed as a system command. |
12201 | 11871 | The collected standard output of the command is returned. |
12202 | 11872 | In scalar context, it comes back as a single (potentially |
12203 | 11873 | multi-line) string. In list context, returns a list of lines |
12204 | 11874 | (however you've defined lines with C<$/> or C<$INPUT_RECORD_SEPARATOR>). |
12205 | 11875 | This is the internal function implementing the C<qx/EXPR/> |
12206 | 11876 | operator, but you can use it directly. The C<qx/EXPR/> |
12207 | 11877 | operator is discussed in more detail in L<perlop/"I/O Operators">. |
12208 | 11878 | If EXPR is omitted, uses C<$_>. |
12209 | 11879 | |
12210 | 11880 | =end original |
12211 | 11881 | |
12212 | 11882 | EXPR がシステムコマンドとして実行されます。 |
12213 | 11883 | コマンドの標準出力の内容が返されます。 |
12214 | 11884 | スカラコンテキストでは、単一の(内部的に複数行の)文字列を返します。 |
12215 | 11885 | リストコンテキストでは、行のリストを返します |
12216 | 11886 | (但し、行は C<$/> または C<$INPUT_RECORD_SEPARATOR> で定義されます)。 |
12217 | これは C<qx/EXPR/> 演算子を実装する内部関数ですが、 | |
11887 | これは C<qx/EXPR/> 演算子を実装する内部関数ですが、 | |
12218 | ||
11888 | 直接使うことも出来ます。 | |
11889 | C<qx/EXPR/> 演算子は L<perlop/"I/O Operators"> でより詳細に | |
11890 | 述べられています。 | |
12219 | 11891 | EXPR が省略されると、C<$_> を使います。 |
12220 | 11892 | |
12221 | 11893 | =item recv SOCKET,SCALAR,LENGTH,FLAGS |
12222 | 11894 | X<recv> |
12223 | 11895 | |
12224 | 11896 | =for Pod::Functions receive a message over a Socket |
12225 | 11897 | |
12226 | 11898 | =begin original |
12227 | 11899 | |
12228 | 11900 | Receives a message on a socket. Attempts to receive LENGTH characters |
12229 | 11901 | of data into variable SCALAR from the specified SOCKET filehandle. |
12230 | 11902 | SCALAR will be grown or shrunk to the length actually read. Takes the |
12231 | 11903 | same flags as the system call of the same name. Returns the address |
12232 | 11904 | of the sender if SOCKET's protocol supports this; returns an empty |
12233 | 11905 | string otherwise. If there's an error, returns the undefined value. |
12234 | 11906 | This call is actually implemented in terms of recvfrom(2) system call. |
12235 | 11907 | See L<perlipc/"UDP: Message Passing"> for examples. |
12236 | 11908 | |
12237 | 11909 | =end original |
12238 | 11910 | |
12239 | 11911 | ソケット上のメッセージを受信します。 |
12240 | 指定されたファイルハンドル SOCKET から、変数 SCALAR に | |
11912 | 指定されたファイルハンドル SOCKET から、変数 SCALAR に | |
12241 | 11913 | LENGTH 文字のデータを読み込もうとします。 |
12242 | SCALAR は、実際に読まれた長さによって、大きくなったり、 | |
11914 | SCALAR は、実際に読まれた長さによって、大きくなったり、 | |
11915 | 小さくなったりします。 | |
12243 | 11916 | 同名のシステムコールと同じフラグが指定できます。 |
12244 | 11917 | SOCKET のプロトコルが対応していれば、送信側のアドレスを返します。 |
12245 | 11918 | エラー発生時には、未定義値を返します。 |
12246 | 11919 | 実際には、C のrecvfrom(2) を呼びます。 |
12247 | 11920 | 例については L<perlipc/"UDP: Message Passing"> を参照してください。 |
12248 | 11921 | |
12249 | 11922 | =begin original |
12250 | 11923 | |
12251 | 11924 | Note the I<characters>: depending on the status of the socket, either |
12252 | 11925 | (8-bit) bytes or characters are received. By default all sockets |
12253 | 11926 | operate on bytes, but for example if the socket has been changed using |
12254 | 11927 | binmode() to operate with the C<:encoding(utf8)> I/O layer (see the |
12255 | 11928 | C<open> pragma, L<open>), the I/O will operate on UTF8-encoded Unicode |
12256 | 11929 | characters, not bytes. Similarly for the C<:encoding> pragma: in that |
12257 | 11930 | case pretty much any characters can be read. |
12258 | 11931 | |
12259 | 11932 | =end original |
12260 | 11933 | |
12261 | 11934 | I<文字> に関する注意: ソケットの状態によって、(8 ビットの) バイトか |
12262 | 11935 | 文字を受信します。 |
12263 | 11936 | デフォルトでは全てのソケットはバイトを処理しますが、 |
12264 | 11937 | 例えばソケットが binmode() で C<:encoding(utf8)> I/O 層(C<open> プラグマ、 |
12265 | 11938 | L<open> を参照してください) を使うように指定された場合、I/O はバイトではなく、 |
12266 | 11939 | UTF8 エンコードされた Unicode 文字を操作します。 |
12267 | 11940 | C<:encoding> プラグマも同様です: |
12268 | 11941 | この場合、ほとんど大体全ての文字が読み込めます。 |
12269 | 11942 | |
12270 | 11943 | =item redo LABEL |
12271 | 11944 | X<redo> |
12272 | 11945 | |
12273 | =item redo EXPR | |
12274 | ||
12275 | 11946 | =item redo |
12276 | 11947 | |
12277 | 11948 | =for Pod::Functions start this loop iteration over again |
12278 | 11949 | |
12279 | 11950 | =begin original |
12280 | 11951 | |
12281 | 11952 | The C<redo> command restarts the loop block without evaluating the |
12282 | 11953 | conditional again. The C<continue> block, if any, is not executed. If |
12283 | 11954 | the LABEL is omitted, the command refers to the innermost enclosing |
12284 | loop. | |
11955 | loop. Programs that want to lie to themselves about what was just input | |
12285 | label name to be computed at run time, and is otherwise identical to C<redo | |
12286 | LABEL>. Programs that want to lie to themselves about what was just input | |
12287 | 11956 | normally use this command: |
12288 | 11957 | |
12289 | 11958 | =end original |
12290 | 11959 | |
12291 | 11960 | C<redo> コマンドは、条件を再評価しないで、ループブロックの始めからもう一度 |
12292 | 11961 | 実行を開始します。 |
12293 | 11962 | C<continue> ブロックがあっても、実行されません。 |
12294 | 11963 | LABEL が省略されると、コマンドは一番内側のループを参照します。 |
12295 | Perl 5.18.0 から利用可能な C<redo EXPR> 形式では、実行時に計算されるラベル名が | |
12296 | 使えます; それ以外は C<redo LABEL> と同一です。 | |
12297 | 11964 | このコマンドは通常、自分への入力を欺くために使用します: |
12298 | 11965 | |
12299 | 11966 | # a simpleminded Pascal comment stripper |
12300 | 11967 | # (warning: assumes no { or } in strings) |
12301 | 11968 | LINE: while (<STDIN>) { |
12302 | 11969 | while (s|({.*}.*){.*}|$1 |) {} |
12303 | 11970 | s|{.*}| |; |
12304 | 11971 | if (s|{.*| |) { |
12305 | 11972 | $front = $_; |
12306 | 11973 | while (<STDIN>) { |
12307 | 11974 | if (/}/) { # end of comment? |
12308 | 11975 | s|^|$front\{|; |
12309 | 11976 | redo LINE; |
12310 | 11977 | } |
12311 | 11978 | } |
12312 | 11979 | } |
12313 | 11980 | print; |
12314 | 11981 | } |
12315 | 11982 | |
12316 | 11983 | =begin original |
12317 | 11984 | |
12318 | 11985 | C<redo> cannot be used to retry a block that returns a value such as |
12319 | 11986 | C<eval {}>, C<sub {}>, or C<do {}>, and should not be used to exit |
12320 | 11987 | a grep() or map() operation. |
12321 | 11988 | |
12322 | 11989 | =end original |
12323 | 11990 | |
12324 | C<redo> は C<eval {}>, C<sub {}>, C<do {}> のように値を返す | |
11991 | C<redo> は C<eval {}>, C<sub {}>, C<do {}> のように値を返す | |
12325 | 繰り返すのには使えません; また、grep() や map() 操作から抜けるのに | |
11992 | ブロックを繰り返すのには使えません; また、grep() や map() 操作から抜けるのに | |
12326 | 11993 | 使うべきではありません。 |
12327 | 11994 | |
12328 | 11995 | =begin original |
12329 | 11996 | |
12330 | 11997 | Note that a block by itself is semantically identical to a loop |
12331 | 11998 | that executes once. Thus C<redo> inside such a block will effectively |
12332 | 11999 | turn it into a looping construct. |
12333 | 12000 | |
12334 | 12001 | =end original |
12335 | 12002 | |
12336 | 12003 | ブロック自身は一回だけ実行されるループと文法的に同一であることに |
12337 | 12004 | 注意してください。 |
12338 | 12005 | 従って、ブロックの中で C<redo> を使うことで効果的に |
12339 | 12006 | ループ構造に変換します。 |
12340 | 12007 | |
12341 | 12008 | =begin original |
12342 | 12009 | |
12343 | 12010 | See also L</continue> for an illustration of how C<last>, C<next>, and |
12344 | 12011 | C<redo> work. |
12345 | 12012 | |
12346 | 12013 | =end original |
12347 | 12014 | |
12348 | 12015 | C<last>, C<next>, C<redo> がどのように働くかについては |
12349 | 12016 | L</continue> も参照してください。 |
12350 | 12017 | |
12351 | =begin original | |
12352 | ||
12353 | Unlike most named operators, this has the same precedence as assignment. | |
12354 | It is also exempt from the looks-like-a-function rule, so | |
12355 | C<redo ("foo")."bar"> will cause "bar" to be part of the argument to | |
12356 | C<redo>. | |
12357 | ||
12358 | =end original | |
12359 | ||
12360 | ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 | |
12361 | また、関数のように見えるものの規則からも免れるので、C<redo ("foo")."bar"> と | |
12362 | すると "bar" は C<redo> への引数の一部となります。 | |
12363 | ||
12364 | 12018 | =item ref EXPR |
12365 | 12019 | X<ref> X<reference> |
12366 | 12020 | |
12367 | 12021 | =item ref |
12368 | 12022 | |
12369 | 12023 | =for Pod::Functions find out the type of thing being referenced |
12370 | 12024 | |
12371 | 12025 | =begin original |
12372 | 12026 | |
12373 | 12027 | Returns a non-empty string if EXPR is a reference, the empty |
12374 | string otherwise. If EXPR | |
12028 | string otherwise. If EXPR | |
12375 | value returned depends on the | |
12029 | is not specified, C<$_> will be used. The value returned depends on the | |
12030 | type of thing the reference is a reference to. | |
12031 | Builtin types include: | |
12376 | 12032 | |
12377 | 12033 | =end original |
12378 | 12034 | |
12379 | 12035 | EXPR がリファレンスであれば、空でない文字列を返し、さもなくば、 |
12380 | 12036 | 空文字列を返します。 |
12381 | 12037 | EXPR が指定されなければ、C<$_> が使われます。 |
12382 | 12038 | 返される値は、リファレンスが参照するものの型に依存します。 |
12383 | ||
12384 | =begin original | |
12385 | ||
12386 | Builtin types include: | |
12387 | ||
12388 | =end original | |
12389 | ||
12390 | 12039 | 組み込みの型には、以下のものがあります。 |
12391 | 12040 | |
12392 | 12041 | SCALAR |
12393 | 12042 | ARRAY |
12394 | 12043 | HASH |
12395 | 12044 | CODE |
12396 | 12045 | REF |
12397 | 12046 | GLOB |
12398 | 12047 | LVALUE |
12399 | 12048 | FORMAT |
12400 | 12049 | IO |
12401 | 12050 | VSTRING |
12402 | 12051 | Regexp |
12403 | 12052 | |
12404 | 12053 | =begin original |
12405 | 12054 | |
12406 | ||
12055 | If the referenced object has been blessed into a package, then that package | |
12056 | name is returned instead. You can think of C<ref> as a C<typeof> operator. | |
12407 | 12057 | |
12408 | 12058 | =end original |
12409 | 12059 | |
12060 | 参照されるオブジェクトが、何らかのパッケージに | |
12061 | bless されたものであれば、これらの代わりに、 | |
12062 | そのパッケージ名が返されます。 | |
12410 | 12063 | C<ref> は、C<typeof> 演算子のように考えることができます。 |
12411 | 12064 | |
12412 | 12065 | if (ref($r) eq "HASH") { |
12413 | 12066 | print "r is a reference to a hash.\n"; |
12414 | 12067 | } |
12415 | 12068 | unless (ref($r)) { |
12416 | 12069 | print "r is not a reference at all.\n"; |
12417 | 12070 | } |
12418 | 12071 | |
12419 | 12072 | =begin original |
12420 | 12073 | |
12421 | 12074 | The return value C<LVALUE> indicates a reference to an lvalue that is not |
12422 | 12075 | a variable. You get this from taking the reference of function calls like |
12423 | 12076 | C<pos()> or C<substr()>. C<VSTRING> is returned if the reference points |
12424 | 12077 | to a L<version string|perldata/"Version Strings">. |
12425 | 12078 | |
12426 | 12079 | =end original |
12427 | 12080 | |
12428 | 12081 | 返り値 C<LVALUE> は、変数ではない左辺値へのリファレンスを示します。 |
12429 | 12082 | これは、C<pos()> や C<substr()> のようの関数呼び出しのリファレンスから |
12430 | 12083 | 得られます。 |
12431 | 12084 | C<VSTRING> は、リファレンスが L<version string|perldata/"Version Strings"> を |
12432 | 12085 | 指している場合に返されます。 |
12433 | 12086 | |
12434 | 12087 | =begin original |
12435 | 12088 | |
12436 | 12089 | The result C<Regexp> indicates that the argument is a regular expression |
12437 | 12090 | resulting from C<qr//>. |
12438 | 12091 | |
12439 | 12092 | =end original |
12440 | 12093 | |
12441 | 12094 | C<Regexp> という結果は、引数が C<qr//> からの結果である |
12442 | 12095 | 正規表現であることを意味します。 |
12443 | 12096 | |
12444 | 12097 | =begin original |
12445 | 12098 | |
12446 | If the referenced object has been blessed into a package, then that package | |
12447 | name is returned instead. But don't use that, as it's now considered | |
12448 | "bad practice". For one reason, an object could be using a class called | |
12449 | C<Regexp> or C<IO>, or even C<HASH>. Also, C<ref> doesn't take into account | |
12450 | subclasses, like C<isa> does. | |
12451 | ||
12452 | =end original | |
12453 | ||
12454 | 参照されるオブジェクトが、何らかのパッケージに bless されたものであれば、 | |
12455 | これらの代わりに、そのパッケージ名が返されます。 | |
12456 | しかし、これは今では「悪い習慣」と考えられているので、しないでください。 | |
12457 | 理由の一つは、オブジェクトは C<Regexp>, C<IO> や C<HASH> などと呼ばれる | |
12458 | クラスを使うかも知れないからです。 | |
12459 | また、C<ref> は C<isa> のようにサブクラスを考慮したりはしません。 | |
12460 | ||
12461 | =begin original | |
12462 | ||
12463 | Instead, use C<blessed> (in the L<Scalar::Util> module) for boolean | |
12464 | checks, C<isa> for specific class checks and C<reftype> (also from | |
12465 | L<Scalar::Util>) for type checks. (See L<perlobj> for details and a | |
12466 | C<blessed/isa> example.) | |
12467 | ||
12468 | =end original | |
12469 | ||
12470 | 代わりに、真偽値チェックには (L<Scalar::Util> モジュールにある) | |
12471 | C<blessed> を、特定のクラスのチェックには C<isa> を、型のチェックには | |
12472 | (これも L<Scalar::Util> にある) C<reftype> を使ってください。 | |
12473 | (詳細と C<blessed/isa> の例については L<perlobj> を参照してください。) | |
12474 | ||
12475 | =begin original | |
12476 | ||
12477 | 12099 | See also L<perlref>. |
12478 | 12100 | |
12479 | 12101 | =end original |
12480 | 12102 | |
12481 | 12103 | L<perlref> も参照してください。 |
12482 | 12104 | |
12483 | 12105 | =item rename OLDNAME,NEWNAME |
12484 | 12106 | X<rename> X<move> X<mv> X<ren> |
12485 | 12107 | |
12486 | 12108 | =for Pod::Functions change a filename |
12487 | 12109 | |
12488 | 12110 | =begin original |
12489 | 12111 | |
12490 | 12112 | Changes the name of a file; an existing file NEWNAME will be |
12491 | 12113 | clobbered. Returns true for success, false otherwise. |
12492 | 12114 | |
12493 | 12115 | =end original |
12494 | 12116 | |
12495 | 12117 | ファイルの名前を変更します; NEWNAME というファイルが既に存在した場合、 |
12496 | 12118 | 上書きされるかもしれません。 |
12497 | 12119 | 成功時には真を、さもなければ偽を返します。 |
12498 | 12120 | |
12499 | 12121 | =begin original |
12500 | 12122 | |
12501 | 12123 | Behavior of this function varies wildly depending on your system |
12502 | 12124 | implementation. For example, it will usually not work across file system |
12503 | 12125 | boundaries, even though the system I<mv> command sometimes compensates |
12504 | 12126 | for this. Other restrictions include whether it works on directories, |
12505 | 12127 | open files, or pre-existing files. Check L<perlport> and either the |
12506 | 12128 | rename(2) manpage or equivalent system documentation for details. |
12507 | 12129 | |
12508 | 12130 | =end original |
12509 | 12131 | |
12510 | 12132 | この関数の振る舞いはシステムの実装に大きく依存して異なります。 |
12511 | 12133 | 例えば、普通はファイルシステムにまたがってパス名を付け替えることはできません; |
12512 | 12134 | システムの I<mv> がこれを補完している場合でもそうです。 |
12513 | 12135 | その他の制限には、ディレクトリ、オープンしているファイル、既に存在している |
12514 | 12136 | ファイルに対して使えるか、といったことを含みます。 |
12515 | 12137 | 詳しくは、L<perlport> および rename(2) man ページあるいは同様の |
12516 | 12138 | システムドキュメントを参照してください。 |
12517 | 12139 | |
12518 | 12140 | =begin original |
12519 | 12141 | |
12520 | 12142 | For a platform independent C<move> function look at the L<File::Copy> |
12521 | 12143 | module. |
12522 | 12144 | |
12523 | 12145 | =end original |
12524 | 12146 | |
12525 | 12147 | プラットフォームに依存しない C<move> 関数については L<File::Copy> モジュールを |
12526 | 12148 | 参照してください。 |
12527 | 12149 | |
12528 | 12150 | =begin original |
12529 | 12151 | |
12530 | 12152 | Portability issues: L<perlport/rename>. |
12531 | 12153 | |
12532 | 12154 | =end original |
12533 | 12155 | |
12534 | 12156 | 移植性の問題: L<perlport/rename>。 |
12535 | 12157 | |
12536 | 12158 | =item require VERSION |
12537 | 12159 | X<require> |
12538 | 12160 | |
12539 | 12161 | =item require EXPR |
12540 | 12162 | |
12541 | 12163 | =item require |
12542 | 12164 | |
12543 | 12165 | =for Pod::Functions load in external functions from a library at runtime |
12544 | 12166 | |
12545 | 12167 | =begin original |
12546 | 12168 | |
12547 | 12169 | Demands a version of Perl specified by VERSION, or demands some semantics |
12548 | 12170 | specified by EXPR or by C<$_> if EXPR is not supplied. |
12549 | 12171 | |
12550 | 12172 | =end original |
12551 | 12173 | |
12552 | 12174 | VERSION で指定される Perl のバージョンを要求するか、 |
12553 | 12175 | EXPR (省略時には C<$_>) によって指定されるいくつかの動作を要求します。 |
12554 | 12176 | |
12555 | 12177 | =begin original |
12556 | 12178 | |
12557 | 12179 | VERSION may be either a numeric argument such as 5.006, which will be |
12558 | 12180 | compared to C<$]>, or a literal of the form v5.6.1, which will be compared |
12559 | 12181 | to C<$^V> (aka $PERL_VERSION). An exception is raised if |
12560 | 12182 | VERSION is greater than the version of the current Perl interpreter. |
12561 | 12183 | Compare with L</use>, which can do a similar check at compile time. |
12562 | 12184 | |
12563 | 12185 | =end original |
12564 | 12186 | |
12565 | 12187 | VERSION は 5.006 のような数値(C<$]> と比較されます)か、v5.6.1 の形 |
12566 | 12188 | (C<$^V> (またの名を $PERL_VERSION) と比較されます)で指定します。 |
12567 | 12189 | VERSION が Perl の現在のバージョンより大きいと、例外が発生します。 |
12568 | 12190 | L</use> と似ていますが、これはコンパイル時にチェックされます。 |
12569 | 12191 | |
12570 | 12192 | =begin original |
12571 | 12193 | |
12572 | 12194 | Specifying VERSION as a literal of the form v5.6.1 should generally be |
12573 | 12195 | avoided, because it leads to misleading error messages under earlier |
12574 | 12196 | versions of Perl that do not support this syntax. The equivalent numeric |
12575 | 12197 | version should be used instead. |
12576 | 12198 | |
12577 | 12199 | =end original |
12578 | 12200 | |
12579 | 12201 | VERSION に v5.6.1 の形のリテラルを指定することは一般的には避けるべきです; |
12580 | 12202 | なぜなら、この文法に対応していない Perl の初期のバージョンでは |
12581 | 12203 | 誤解させるようなエラーメッセージが出るからです。 |
12582 | 12204 | 代わりに等価な数値表現を使うべきです。 |
12583 | 12205 | |
12584 | 12206 | =begin original |
12585 | 12207 | |
12586 | 12208 | require v5.6.1; # run time version check |
12587 | 12209 | require 5.6.1; # ditto |
12588 | require 5.006_001; # ditto; preferred for backwards | |
12210 | require 5.006_001; # ditto; preferred for backwards compatibility | |
12589 | compatibility | |
12590 | 12211 | |
12591 | 12212 | =end original |
12592 | 12213 | |
12593 | 12214 | require v5.6.1; # 実行時バージョンチェック |
12594 | 12215 | require 5.6.1; # 同様 |
12595 | 12216 | require 5.006_001; # 同様; 後方互換性のためには望ましい |
12596 | 12217 | |
12597 | 12218 | =begin original |
12598 | 12219 | |
12599 | 12220 | Otherwise, C<require> demands that a library file be included if it |
12600 | 12221 | hasn't already been included. The file is included via the do-FILE |
12601 | 12222 | mechanism, which is essentially just a variety of C<eval> with the |
12602 | 12223 | caveat that lexical variables in the invoking script will be invisible |
12603 | to the included code. | |
12224 | to the included code. Has semantics similar to the following subroutine: | |
12604 | would have semantics similar to the following: | |
12605 | 12225 | |
12606 | 12226 | =end original |
12607 | 12227 | |
12608 | 12228 | それ以外の場合には、C<require> は、既に読み込まれていないときに読み込む |
12609 | 12229 | ライブラリファイルを要求するものとなります。 |
12610 | 12230 | そのファイルは、基本的には C<eval> の一種である、do-FILE によって |
12611 | 12231 | 読み込まれますが、起動したスクリプトのレキシカル変数は読み込まれたコードから |
12612 | 12232 | 見えないという欠点があります。 |
12613 | ||
12233 | 意味的には、次のようなサブルーチンと同じようなものです: | |
12614 | 同じようなものです: | |
12615 | 12234 | |
12616 | use Carp 'croak'; | |
12617 | use version; | |
12618 | ||
12619 | 12235 | sub require { |
12620 | | |
12236 | my ($filename) = @_; | |
12621 | | |
12237 | if (exists $INC{$filename}) { | |
12622 | | |
12238 | return 1 if $INC{$filename}; | |
12623 | | |
12239 | die "Compilation failed in require"; | |
12624 | | |
12240 | } | |
12625 | | |
12241 | my ($realfilename,$result); | |
12626 | | |
12242 | ITER: { | |
12627 | | |
12243 | foreach $prefix (@INC) { | |
12244 | $realfilename = "$prefix/$filename"; | |
12629 | if ( | |
12245 | if (-f $realfilename) { | |
12630 | | |
12246 | $INC{$filename} = $realfilename; | |
12631 | | |
12247 | $result = do $realfilename; | |
12632 | | |
12248 | last ITER; | |
12249 | } | |
12634 | | |
12250 | } | |
12635 | | |
12251 | die "Can't find $filename in \@INC"; | |
12636 | | |
12252 | } | |
12637 | | |
12253 | if ($@) { | |
12638 | | |
12254 | $INC{$filename} = undef; | |
12639 | | |
12255 | die $@; | |
12640 | | |
12256 | } elsif (!$result) { | |
12641 | | |
12257 | delete $INC{$filename}; | |
12642 | $ | |
12258 | die "$filename did not return true value"; | |
12643 | | |
12259 | } else { | |
12644 | | |
12260 | return $result; | |
12261 | } | |
12646 | if (!defined $result) { | |
12647 | $INC{$filename} = undef; | |
12648 | croak $@ ? "$@Compilation failed in require" | |
12649 | : "Can't locate $filename: $!\n"; | |
12650 | } | |
12651 | if (!$result) { | |
12652 | delete $INC{$filename}; | |
12653 | croak "$filename did not return true value"; | |
12654 | } | |
12655 | $! = 0; | |
12656 | return $result; | |
12657 | } | |
12658 | croak "Can't locate $filename in \@INC ..."; | |
12659 | 12262 | } |
12660 | 12263 | |
12661 | 12264 | =begin original |
12662 | 12265 | |
12663 | 12266 | Note that the file will not be included twice under the same specified |
12664 | 12267 | name. |
12665 | 12268 | |
12666 | 12269 | =end original |
12667 | 12270 | |
12668 | 12271 | ファイルは、同じ名前で 2 回読み込まれることはないことに注意してください。 |
12669 | 12272 | |
12670 | 12273 | =begin original |
12671 | 12274 | |
12672 | 12275 | The file must return true as the last statement to indicate |
12673 | 12276 | successful execution of any initialization code, so it's customary to |
12674 | 12277 | end such a file with C<1;> unless you're sure it'll return true |
12675 | 12278 | otherwise. But it's better just to put the C<1;>, in case you add more |
12676 | 12279 | statements. |
12677 | 12280 | |
12678 | 12281 | =end original |
12679 | 12282 | |
12680 | 初期化コードの実行がうまくいったことを示すために、 | |
12283 | 初期化コードの実行がうまくいったことを示すために、 | |
12681 | 返さなければなら | |
12284 | ファイルは真を返さなければなりませんから、 | |
12285 | 真を返すようになっている自信がある場合を除いては、 | |
12682 | 12286 | ファイルの最後に C<1;> と書くのが習慣です。 |
12683 | ||
12287 | 実行文を追加するような場合に備えて、C<1;> と書いておいた方が | |
12288 | 良いでしょう。 | |
12684 | 12289 | |
12685 | 12290 | =begin original |
12686 | 12291 | |
12687 | 12292 | If EXPR is a bareword, the require assumes a "F<.pm>" extension and |
12688 | 12293 | replaces "F<::>" with "F</>" in the filename for you, |
12689 | 12294 | to make it easy to load standard modules. This form of loading of |
12690 | 12295 | modules does not risk altering your namespace. |
12691 | 12296 | |
12692 | 12297 | =end original |
12693 | 12298 | |
12694 | EXPR が裸の単語であるときには、標準モジュールのロードを | |
12299 | EXPR が裸の単語であるときには、標準モジュールのロードを | |
12695 | require は拡張子が "F<.pm>" であり、 | |
12300 | 簡単にするように、require は拡張子が "F<.pm>" であり、 | |
12696 | ファイル名であると仮定します。 | |
12301 | "F<::>" を "F</>" に変えたものがファイル名であると仮定します。 | |
12697 | この形式のモジュールロードは、 | |
12302 | この形式のモジュールロードは、 | |
12303 | 名前空間を変更してしまう危険はありません。 | |
12698 | 12304 | |
12699 | 12305 | =begin original |
12700 | 12306 | |
12701 | 12307 | In other words, if you try this: |
12702 | 12308 | |
12703 | 12309 | =end original |
12704 | 12310 | |
12705 | 12311 | 言い換えると、以下のようにすると: |
12706 | 12312 | |
12707 | 12313 | require Foo::Bar; # a splendid bareword |
12708 | 12314 | |
12709 | 12315 | =begin original |
12710 | 12316 | |
12711 | 12317 | The require function will actually look for the "F<Foo/Bar.pm>" file in the |
12712 | 12318 | directories specified in the C<@INC> array. |
12713 | 12319 | |
12714 | 12320 | =end original |
12715 | 12321 | |
12716 | 12322 | require 関数は C<@INC> 配列で指定されたディレクトリにある |
12717 | 12323 | "F<Foo/Bar.pm>" ファイルを探します。 |
12718 | 12324 | |
12719 | 12325 | =begin original |
12720 | 12326 | |
12721 | 12327 | But if you try this: |
12722 | 12328 | |
12723 | 12329 | =end original |
12724 | 12330 | |
12725 | 12331 | しかし、以下のようにすると: |
12726 | 12332 | |
12727 | 12333 | $class = 'Foo::Bar'; |
12728 | 12334 | require $class; # $class is not a bareword |
12729 | 12335 | #or |
12730 | 12336 | require "Foo::Bar"; # not a bareword because of the "" |
12731 | 12337 | |
12732 | 12338 | =begin original |
12733 | 12339 | |
12734 | 12340 | The require function will look for the "F<Foo::Bar>" file in the @INC array and |
12735 | 12341 | will complain about not finding "F<Foo::Bar>" there. In this case you can do: |
12736 | 12342 | |
12737 | 12343 | =end original |
12738 | 12344 | |
12739 | 12345 | require 関数は @INC 配列の "F<Foo::Bar>" ファイルを探し、 |
12740 | 12346 | おそらくそこに "F<Foo::Bar>" がないと文句をいうことになるでしょう。 |
12741 | 12347 | このような場合には、以下のようにします: |
12742 | 12348 | |
12743 | 12349 | eval "require $class"; |
12744 | 12350 | |
12745 | 12351 | =begin original |
12746 | 12352 | |
12747 | 12353 | Now that you understand how C<require> looks for files with a |
12748 | 12354 | bareword argument, there is a little extra functionality going on behind |
12749 | 12355 | the scenes. Before C<require> looks for a "F<.pm>" extension, it will |
12750 | 12356 | first look for a similar filename with a "F<.pmc>" extension. If this file |
12751 | 12357 | is found, it will be loaded in place of any file ending in a "F<.pm>" |
12752 | 12358 | extension. |
12753 | 12359 | |
12754 | 12360 | =end original |
12755 | 12361 | |
12756 | 12362 | 引数が裸の単語の場合、C<require> がどのようにファイルを探すかを |
12757 | 12363 | 理解してください; 水面下でちょっとした追加の機能があります。 |
12758 | 12364 | C<require> が拡張子 "F<.pm>" のファイルを探す前に、まず拡張子 "F<.pmc>" を |
12759 | 12365 | 持つファイルを探します。 |
12760 | 12366 | このファイルが見つかると、このファイルが拡張子 "F<.pm>" の代わりに |
12761 | 12367 | 読み込まれます。 |
12762 | 12368 | |
12763 | 12369 | =begin original |
12764 | 12370 | |
12765 | 12371 | You can also insert hooks into the import facility by putting Perl code |
12766 | 12372 | directly into the @INC array. There are three forms of hooks: subroutine |
12767 | 12373 | references, array references, and blessed objects. |
12768 | 12374 | |
12769 | 12375 | =end original |
12770 | 12376 | |
12771 | 12377 | @INC 配列に直接 Perl コードを入れることで、インポート機能にフックを |
12772 | 12378 | 挿入できます。 |
12773 | 12379 | 3 種類のフックがあります: サブルーチンリファレンス、配列リファレンス、 |
12774 | 12380 | bless されたオブジェクトです。 |
12775 | 12381 | |
12776 | 12382 | =begin original |
12777 | 12383 | |
12778 | 12384 | Subroutine references are the simplest case. When the inclusion system |
12779 | 12385 | walks through @INC and encounters a subroutine, this subroutine gets |
12780 | 12386 | called with two parameters, the first a reference to itself, and the |
12781 | 12387 | second the name of the file to be included (e.g., "F<Foo/Bar.pm>"). The |
12782 | subroutine should return either nothing or else a list of up to | |
12388 | subroutine should return either nothing or else a list of up to three | |
12783 | 12389 | values in the following order: |
12784 | 12390 | |
12785 | 12391 | =end original |
12786 | 12392 | |
12787 | 12393 | サブルーチンへのリファレンスは一番単純な場合です。 |
12788 | 12394 | インクルード機能が @INC を走査してサブルーチンに出会った場合、この |
12789 | 12395 | サブルーチンは二つの引数と共に呼び出されます; |
12790 | 12396 | 一つ目は自身へのリファレンス、二つ目はインクルードされるファイル名 |
12791 | 12397 | ("F<Foo/Bar.pm>" など)です。 |
12792 | サブルーチンは何も返さないか、以下の順で最大 | |
12398 | サブルーチンは何も返さないか、以下の順で最大三つの値のリストを | |
12399 | 返します。 | |
12793 | 12400 | |
12794 | 12401 | =over |
12795 | 12402 | |
12796 | 12403 | =item 1 |
12797 | 12404 | |
12798 | 12405 | =begin original |
12799 | 12406 | |
12800 | A reference to a scalar, containing any initial source code to prepend to | |
12801 | the file or generator output. | |
12802 | ||
12803 | =end original | |
12804 | ||
12805 | ファイルやジェネレータの出力の前に追加される初期化ソースコードを含む | |
12806 | スカラへのリファレンス。 | |
12807 | ||
12808 | =item 2 | |
12809 | ||
12810 | =begin original | |
12811 | ||
12812 | 12407 | A filehandle, from which the file will be read. |
12813 | 12408 | |
12814 | 12409 | =end original |
12815 | 12410 | |
12816 | 12411 | ファイルが読み込まれるファイルハンドル。 |
12817 | 12412 | |
12818 | =item | |
12413 | =item 2 | |
12819 | 12414 | |
12820 | 12415 | =begin original |
12821 | 12416 | |
12822 | 12417 | A reference to a subroutine. If there is no filehandle (previous item), |
12823 | 12418 | then this subroutine is expected to generate one line of source code per |
12824 | 12419 | call, writing the line into C<$_> and returning 1, then finally at end of |
12825 | 12420 | file returning 0. If there is a filehandle, then the subroutine will be |
12826 | 12421 | called to act as a simple source filter, with the line as read in C<$_>. |
12827 | 12422 | Again, return 1 for each valid line, and 0 after all lines have been |
12828 | 12423 | returned. |
12829 | 12424 | |
12830 | 12425 | =end original |
12831 | 12426 | |
12832 | 12427 | サブルーチンへのリファレンス。 |
12833 | (一つ前のアイテムである)ファイルハンドルがない場合、 | |
12428 | (一つ前のアイテムである)ファイルハンドルがない場合、 | |
12834 | 一行のソースコードを生成し、その行を C<$_> に | |
12429 | サブルーチンは呼び出し毎に一行のソースコードを生成し、その行を C<$_> に | |
12835 | 最終的にファイル終端で 0 を返すものと | |
12430 | 書き込んで 1 を返し、それから最終的にファイル終端で 0 を返すものと | |
12431 | 想定されます。 | |
12836 | 12432 | ファイルハンドルがある場合、サブルーチンは単純なソースフィルタとして |
12837 | 12433 | 振舞うように呼び出され、行は C<$_> から読み込まれます。 |
12838 | 12434 | 再び、有効な行ごとに 1 を返し、全ての行を返した後では 0 を返します。 |
12839 | 12435 | |
12840 | =item | |
12436 | =item 3 | |
12841 | 12437 | |
12842 | 12438 | =begin original |
12843 | 12439 | |
12844 | 12440 | Optional state for the subroutine. The state is passed in as C<$_[1]>. A |
12845 | 12441 | reference to the subroutine itself is passed in as C<$_[0]>. |
12846 | 12442 | |
12847 | 12443 | =end original |
12848 | 12444 | |
12849 | 12445 | サブルーチンのための状態(オプション)。 |
12850 | 12446 | 状態は C<$_[1]> として渡されます。 |
12851 | 12447 | サブルーチンへのリファレンス自身は C<$_[0]> として渡されます。 |
12852 | 12448 | |
12853 | 12449 | =back |
12854 | 12450 | |
12855 | 12451 | =begin original |
12856 | 12452 | |
12857 | 12453 | If an empty list, C<undef>, or nothing that matches the first 3 values above |
12858 | 12454 | is returned, then C<require> looks at the remaining elements of @INC. |
12859 | 12455 | Note that this filehandle must be a real filehandle (strictly a typeglob |
12860 | 12456 | or reference to a typeglob, whether blessed or unblessed); tied filehandles |
12861 | 12457 | will be ignored and processing will stop there. |
12862 | 12458 | |
12863 | 12459 | =end original |
12864 | 12460 | |
12865 | 12461 | 空リスト、C<undef>、または上記の最初の三つの値のどれとも一致しないものが |
12866 | 12462 | 返されると、C<require> は @INC の残りの要素を見ます。 |
12867 | 12463 | このファイルハンドルは実際のファイルハンドル(厳密には型グロブ、型グロブへの |
12868 | 12464 | リファレンス、bless されているかに関わらず)でなければなりません; |
12869 | 12465 | tie されたファイルハンドルは無視され、返り値の処理はそこで停止します。 |
12870 | 12466 | |
12871 | 12467 | =begin original |
12872 | 12468 | |
12873 | 12469 | If the hook is an array reference, its first element must be a subroutine |
12874 | 12470 | reference. This subroutine is called as above, but the first parameter is |
12875 | 12471 | the array reference. This lets you indirectly pass arguments to |
12876 | 12472 | the subroutine. |
12877 | 12473 | |
12878 | 12474 | =end original |
12879 | 12475 | |
12880 | 12476 | フックが配列のリファレンスの場合、その最初の要素はサブルーチンへの |
12881 | 12477 | リファレンスでなければなりません。 |
12882 | 12478 | このサブルーチンは上述のように呼び出されますが、その最初の引数は |
12883 | 12479 | 配列のリファレンスです。 |
12884 | 12480 | これによって、間接的にサブルーチンに引数を渡すことが出来ます。 |
12885 | 12481 | |
12886 | 12482 | =begin original |
12887 | 12483 | |
12888 | 12484 | In other words, you can write: |
12889 | 12485 | |
12890 | 12486 | =end original |
12891 | 12487 | |
12892 | 12488 | 言い換えると、以下のように書いたり: |
12893 | 12489 | |
12894 | 12490 | push @INC, \&my_sub; |
12895 | 12491 | sub my_sub { |
12896 | 12492 | my ($coderef, $filename) = @_; # $coderef is \&my_sub |
12897 | 12493 | ... |
12898 | 12494 | } |
12899 | 12495 | |
12900 | 12496 | =begin original |
12901 | 12497 | |
12902 | 12498 | or: |
12903 | 12499 | |
12904 | 12500 | =end original |
12905 | 12501 | |
12906 | 12502 | または以下のように書けます: |
12907 | 12503 | |
12908 | 12504 | push @INC, [ \&my_sub, $x, $y, ... ]; |
12909 | 12505 | sub my_sub { |
12910 | 12506 | my ($arrayref, $filename) = @_; |
12911 | 12507 | # Retrieve $x, $y, ... |
12912 | 12508 | my @parameters = @$arrayref[1..$#$arrayref]; |
12913 | 12509 | ... |
12914 | 12510 | } |
12915 | 12511 | |
12916 | 12512 | =begin original |
12917 | 12513 | |
12918 | 12514 | If the hook is an object, it must provide an INC method that will be |
12919 | 12515 | called as above, the first parameter being the object itself. (Note that |
12920 | 12516 | you must fully qualify the sub's name, as unqualified C<INC> is always forced |
12921 | 12517 | into package C<main>.) Here is a typical code layout: |
12922 | 12518 | |
12923 | 12519 | =end original |
12924 | 12520 | |
12925 | 12521 | フックがオブジェクトの場合、INC メソッドを提供している必要があります; |
12926 | 12522 | それが、最初の引数をオブジェクト自身として上述のように呼び出されます。 |
12927 | 12523 | (修飾されていない C<INC> は常にパッケージ C<main> に強制されるため、 |
12928 | 12524 | サブルーチン名は完全修飾する必要があることに注意してください。) |
12929 | 12525 | 以下は典型的なコードレイアウトです: |
12930 | 12526 | |
12931 | 12527 | # In Foo.pm |
12932 | 12528 | package Foo; |
12933 | 12529 | sub new { ... } |
12934 | 12530 | sub Foo::INC { |
12935 | 12531 | my ($self, $filename) = @_; |
12936 | 12532 | ... |
12937 | 12533 | } |
12938 | 12534 | |
12939 | 12535 | # In the main program |
12940 | 12536 | push @INC, Foo->new(...); |
12941 | 12537 | |
12942 | 12538 | =begin original |
12943 | 12539 | |
12944 | 12540 | These hooks are also permitted to set the %INC entry |
12945 | 12541 | corresponding to the files they have loaded. See L<perlvar/%INC>. |
12946 | 12542 | |
12947 | 12543 | =end original |
12948 | 12544 | |
12949 | 12545 | これらのフックは、読み込まれるファイルに対応する %INC エントリを |
12950 | 12546 | セットすることも許可します。 |
12951 | 12547 | L<perlvar/%INC> を参照してください。 |
12952 | 12548 | |
12953 | 12549 | =begin original |
12954 | 12550 | |
12955 | 12551 | For a yet-more-powerful import facility, see L</use> and L<perlmod>. |
12956 | 12552 | |
12957 | 12553 | =end original |
12958 | 12554 | |
12959 | 12555 | より強力な import 機能については、このドキュメントの |
12960 | 12556 | L</use> の項と、L<perlmod> を参照してください。 |
12961 | 12557 | |
12962 | 12558 | =item reset EXPR |
12963 | 12559 | X<reset> |
12964 | 12560 | |
12965 | 12561 | =item reset |
12966 | 12562 | |
12967 | 12563 | =for Pod::Functions clear all variables of a given name |
12968 | 12564 | |
12969 | 12565 | =begin original |
12970 | 12566 | |
12971 | 12567 | Generally used in a C<continue> block at the end of a loop to clear |
12972 | 12568 | variables and reset C<??> searches so that they work again. The |
12973 | 12569 | expression is interpreted as a list of single characters (hyphens |
12974 | 12570 | allowed for ranges). All variables and arrays beginning with one of |
12975 | 12571 | those letters are reset to their pristine state. If the expression is |
12976 | 12572 | omitted, one-match searches (C<?pattern?>) are reset to match again. |
12977 | 12573 | Only resets variables or searches in the current package. Always returns |
12978 | 12574 | 1. Examples: |
12979 | 12575 | |
12980 | 12576 | =end original |
12981 | 12577 | |
12982 | 通常、ループの最後に、変数をクリアし、C<??> 検索を再び | |
12578 | 通常、ループの最後に、変数をクリアし、C<??> 検索を再び | |
12983 | リセットするため、C<continue> ブロックで使われます。 | |
12579 | 動作するようにリセットするため、C<continue> ブロックで使われます。 | |
12984 | 12580 | EXPR は、文字を並べたもの (範囲を指定するのに、ハイフンが使えます) と |
12985 | 12581 | 解釈されます。 |
12986 | 12582 | 名前がその文字のいずれかで始まる変数や配列は、 |
12987 | 12583 | 最初の状態にリセットされます。 |
12988 | 12584 | EXPR を省略すると、1 回検索 (C<?PATTERN?>) を再びマッチするように |
12989 | 12585 | リセットできます。 |
12990 | 12586 | カレントパッケージの変数もしくは検索だけがリセットされます。 |
12991 | 12587 | 常に 1 を返します。 |
12992 | 12588 | 例: |
12993 | 12589 | |
12994 | 12590 | reset 'X'; # reset all X variables |
12995 | 12591 | reset 'a-z'; # reset lower case variables |
12996 | 12592 | reset; # just reset ?one-time? searches |
12997 | 12593 | |
12998 | 12594 | =begin original |
12999 | 12595 | |
13000 | 12596 | Resetting C<"A-Z"> is not recommended because you'll wipe out your |
13001 | 12597 | C<@ARGV> and C<@INC> arrays and your C<%ENV> hash. Resets only package |
13002 | 12598 | variables; lexical variables are unaffected, but they clean themselves |
13003 | 12599 | up on scope exit anyway, so you'll probably want to use them instead. |
13004 | 12600 | See L</my>. |
13005 | 12601 | |
13006 | 12602 | =end original |
13007 | 12603 | |
13008 | 12604 | reset C<"A-Z"> とすると、C<@ARGV>, C<@INC> 配列や C<%ENV> ハッシュも |
13009 | なくなってしま | |
12605 | なくなってしまいますから、止めた方が良いでしょう。 | |
13010 | パッケージ変数だけがリセットされます; | |
12606 | パッケージ変数だけがリセットされます; | |
13011 | スコープから外れれば | |
12607 | レキシカル変数は、影響を受けませんが、スコープから外れれば、 | |
13012 | 使うようにした方が | |
12608 | 自動的に綺麗になりますので、これからは、こちらを使うようにした方が | |
12609 | よいでしょう。 | |
13013 | 12610 | L</my> を参照してください。 |
13014 | 12611 | |
13015 | 12612 | =item return EXPR |
13016 | 12613 | X<return> |
13017 | 12614 | |
13018 | 12615 | =item return |
13019 | 12616 | |
13020 | 12617 | =for Pod::Functions get out of a function early |
13021 | 12618 | |
13022 | 12619 | =begin original |
13023 | 12620 | |
13024 | 12621 | Returns from a subroutine, C<eval>, or C<do FILE> with the value |
13025 | 12622 | given in EXPR. Evaluation of EXPR may be in list, scalar, or void |
13026 | 12623 | context, depending on how the return value will be used, and the context |
13027 | 12624 | may vary from one execution to the next (see L</wantarray>). If no EXPR |
13028 | 12625 | is given, returns an empty list in list context, the undefined value in |
13029 | 12626 | scalar context, and (of course) nothing at all in void context. |
13030 | 12627 | |
13031 | 12628 | =end original |
13032 | 12629 | |
13033 | 12630 | サブルーチン, C<eval>, C<do FILE> から EXPR で与えられた値をもって、 |
13034 | 12631 | リターンします。 |
13035 | 12632 | EXPR の評価は、返り値がどのように使われるかによってリスト、スカラ、 |
13036 | 12633 | 無効コンテキストになります; またコンテキストは実行毎に変わります |
13037 | 12634 | (C<wantarray> を参照してください)。 |
13038 | 12635 | EXPR が指定されなかった場合は、リストコンテキストでは空リストを、 |
13039 | 12636 | スカラコンテキストでは未定義値を返します; そして(もちろん) |
13040 | 12637 | 無効コンテキストでは何も返しません。 |
13041 | 12638 | |
13042 | 12639 | =begin original |
13043 | 12640 | |
13044 | 12641 | (In the absence of an explicit C<return>, a subroutine, eval, |
13045 | 12642 | or do FILE automatically returns the value of the last expression |
13046 | 12643 | evaluated.) |
13047 | 12644 | |
13048 | 12645 | =end original |
13049 | 12646 | |
13050 | (サブルーチン, eval, do FILE に明示的に C<return> が | |
12647 | (サブルーチン, eval, do FILE に明示的に C<return> が | |
13051 | 評価された値で、自動的にリターンします。) | |
12648 | なければ、最後に評価された値で、自動的にリターンします。) | |
13052 | 12649 | |
13053 | =begin original | |
13054 | ||
13055 | Unlike most named operators, this is also exempt from the | |
13056 | looks-like-a-function rule, so C<return ("foo")."bar"> will | |
13057 | cause "bar" to be part of the argument to C<return>. | |
13058 | ||
13059 | =end original | |
13060 | ||
13061 | ほとんどの名前付き演算子と異なり、関数のように見えるものの規則からも | |
13062 | 免れるので、C<return ("foo")."bar"> とすると "bar" は C<return> への引数の | |
13063 | 一部となります。 | |
13064 | ||
13065 | 12650 | =item reverse LIST |
13066 | 12651 | X<reverse> X<rev> X<invert> |
13067 | 12652 | |
13068 | 12653 | =for Pod::Functions flip a string or a list |
13069 | 12654 | |
13070 | 12655 | =begin original |
13071 | 12656 | |
13072 | 12657 | In list context, returns a list value consisting of the elements |
13073 | 12658 | of LIST in the opposite order. In scalar context, concatenates the |
13074 | 12659 | elements of LIST and returns a string value with all characters |
13075 | 12660 | in the opposite order. |
13076 | 12661 | |
13077 | 12662 | =end original |
13078 | 12663 | |
13079 | 12664 | リストコンテキストでは、LIST を構成する要素を逆順に並べた |
13080 | 12665 | リスト値を返します。 |
13081 | 12666 | スカラコンテキストでは、LIST の要素を連結して、 |
13082 | 12667 | 全ての文字を逆順にした文字列を返します。 |
13083 | 12668 | |
13084 | 12669 | print join(", ", reverse "world", "Hello"); # Hello, world |
13085 | 12670 | |
13086 | 12671 | print scalar reverse "dlrow ,", "olleH"; # Hello, world |
13087 | 12672 | |
13088 | 12673 | =begin original |
13089 | 12674 | |
13090 | 12675 | Used without arguments in scalar context, reverse() reverses C<$_>. |
13091 | 12676 | |
13092 | 12677 | =end original |
13093 | 12678 | |
13094 | 12679 | スカラコンテキストで引数なしで使うと、reverse() は C<$_> を逆順にします。 |
13095 | 12680 | |
13096 | 12681 | $_ = "dlrow ,olleH"; |
13097 | print reverse; # No output, list context | |
12682 | print reverse; # No output, list context | |
13098 | print scalar reverse; # Hello, world | |
12683 | print scalar reverse; # Hello, world | |
13099 | 12684 | |
13100 | 12685 | =begin original |
13101 | 12686 | |
13102 | 12687 | Note that reversing an array to itself (as in C<@a = reverse @a>) will |
13103 | preserve non-existent elements whenever possible | |
12688 | preserve non-existent elements whenever possible, i.e., for non magical | |
13104 | arrays or | |
12689 | arrays or tied arrays with C<EXISTS> and C<DELETE> methods. | |
13105 | 12690 | |
13106 | 12691 | =end original |
13107 | 12692 | |
13108 | 12693 | (C<@a = reverse @a> のように) 反転した配列を自分自身に代入すると、 |
13109 | 12694 | 存在しない要素は可能なら(つまりマジカルでない配列や |
13110 | 12695 | C<EXISTS> と C<DELETE> メソッドがある tie された配列) |
13111 | 12696 | いつでも保存されることに注意してください。 |
13112 | 12697 | |
13113 | 12698 | =begin original |
13114 | 12699 | |
13115 | 12700 | This operator is also handy for inverting a hash, although there are some |
13116 | 12701 | caveats. If a value is duplicated in the original hash, only one of those |
13117 | 12702 | can be represented as a key in the inverted hash. Also, this has to |
13118 | 12703 | unwind one hash and build a whole new one, which may take some time |
13119 | 12704 | on a large hash, such as from a DBM file. |
13120 | 12705 | |
13121 | 12706 | =end original |
13122 | 12707 | |
13123 | 12708 | この演算子はハッシュの逆順にするのにも便利ですが、いくつかの弱点があります。 |
13124 | 12709 | 元のハッシュで値が重複していると、それらのうち一つだけが |
13125 | 12710 | 逆順になったハッシュのキーとして表現されます。 |
13126 | 12711 | また、これは一つのハッシュをほどいて完全に新しいハッシュを作るので、 |
13127 | 12712 | DBM ファイルからのような大きなハッシュでは少し時間がかかります。 |
13128 | 12713 | |
13129 | 12714 | %by_name = reverse %by_address; # Invert the hash |
13130 | 12715 | |
13131 | 12716 | =item rewinddir DIRHANDLE |
13132 | 12717 | X<rewinddir> |
13133 | 12718 | |
13134 | 12719 | =for Pod::Functions reset directory handle |
13135 | 12720 | |
13136 | 12721 | =begin original |
13137 | 12722 | |
13138 | 12723 | Sets the current position to the beginning of the directory for the |
13139 | 12724 | C<readdir> routine on DIRHANDLE. |
13140 | 12725 | |
13141 | 12726 | =end original |
13142 | 12727 | |
13143 | 12728 | DIRHANDLE に対する C<readdir> ルーチンの現在位置を |
13144 | 12729 | ディレクトリの最初に設定します。 |
13145 | 12730 | |
13146 | 12731 | =begin original |
13147 | 12732 | |
13148 | 12733 | Portability issues: L<perlport/rewinddir>. |
13149 | 12734 | |
13150 | 12735 | =end original |
13151 | 12736 | |
13152 | 12737 | 移植性の問題: L<perlport/rewinddir>。 |
13153 | 12738 | |
13154 | 12739 | =item rindex STR,SUBSTR,POSITION |
13155 | 12740 | X<rindex> |
13156 | 12741 | |
13157 | 12742 | =item rindex STR,SUBSTR |
13158 | 12743 | |
13159 | 12744 | =for Pod::Functions right-to-left substring search |
13160 | 12745 | |
13161 | 12746 | =begin original |
13162 | 12747 | |
13163 | 12748 | Works just like index() except that it returns the position of the I<last> |
13164 | 12749 | occurrence of SUBSTR in STR. If POSITION is specified, returns the |
13165 | 12750 | last occurrence beginning at or before that position. |
13166 | 12751 | |
13167 | 12752 | =end original |
13168 | 12753 | |
13169 | 12754 | STR 中で I<最後に> 見つかった SUBSTR の位置を返すことを除いて、 |
13170 | 12755 | index() と同じように動作します。 |
13171 | 12756 | POSITION を指定すると、その位置から始まるか、その位置より前の、 |
13172 | 12757 | 最後の位置を返します。 |
13173 | 12758 | |
13174 | 12759 | =item rmdir FILENAME |
13175 | 12760 | X<rmdir> X<rd> X<directory, remove> |
13176 | 12761 | |
13177 | 12762 | =item rmdir |
13178 | 12763 | |
13179 | 12764 | =for Pod::Functions remove a directory |
13180 | 12765 | |
13181 | 12766 | =begin original |
13182 | 12767 | |
13183 | 12768 | Deletes the directory specified by FILENAME if that directory is |
13184 | 12769 | empty. If it succeeds it returns true; otherwise it returns false and |
13185 | 12770 | sets C<$!> (errno). If FILENAME is omitted, uses C<$_>. |
13186 | 12771 | |
13187 | 12772 | =end original |
13188 | 12773 | |
13189 | 12774 | FILENAME で指定したディレクトリが空であれば、 |
13190 | 12775 | そのディレクトリを削除します。 |
13191 | 12776 | 成功時には真を返します; さもなければ偽を返して C<$!> (errno) を設定します。 |
13192 | 12777 | FILENAME を省略した場合には、C<$_> を使用します。 |
13193 | 12778 | |
13194 | 12779 | =begin original |
13195 | 12780 | |
13196 | 12781 | To remove a directory tree recursively (C<rm -rf> on Unix) look at |
13197 | 12782 | the C<rmtree> function of the L<File::Path> module. |
13198 | 12783 | |
13199 | 12784 | =end original |
13200 | 12785 | |
13201 | 12786 | ディレクトリツリーを再帰的に削除したい (Unix での C<rm -rf>) 場合、 |
13202 | 12787 | L<File::Path> モジュールの C<rmtree> 関数を参照してください。 |
13203 | 12788 | |
13204 | 12789 | =item s/// |
13205 | 12790 | |
13206 | 12791 | =for Pod::Functions replace a pattern with a string |
13207 | 12792 | |
13208 | 12793 | =begin original |
13209 | 12794 | |
13210 | 12795 | The substitution operator. See L<perlop/"Regexp Quote-Like Operators">. |
13211 | 12796 | |
13212 | 12797 | =end original |
13213 | 12798 | |
13214 | 12799 | 置換演算子。 |
13215 | 12800 | L<perlop/"Regexp Quote-Like Operators"> を参照してください。 |
13216 | 12801 | |
13217 | 12802 | =item say FILEHANDLE LIST |
13218 | 12803 | X<say> |
13219 | 12804 | |
13220 | 12805 | =item say FILEHANDLE |
13221 | 12806 | |
13222 | 12807 | =item say LIST |
13223 | 12808 | |
13224 | 12809 | =item say |
13225 | 12810 | |
13226 | 12811 | =for Pod::Functions +say output a list to a filehandle, appending a newline |
13227 | 12812 | |
13228 | 12813 | =begin original |
13229 | 12814 | |
13230 | 12815 | Just like C<print>, but implicitly appends a newline. C<say LIST> is |
13231 | 12816 | simply an abbreviation for C<{ local $\ = "\n"; print LIST }>. To use |
13232 | 12817 | FILEHANDLE without a LIST to print the contents of C<$_> to it, you must |
13233 | 12818 | use a real filehandle like C<FH>, not an indirect one like C<$fh>. |
13234 | 12819 | |
13235 | 12820 | =end original |
13236 | 12821 | |
13237 | 12822 | C<print> と同様ですが、暗黙に改行が追加されます。 |
13238 | 12823 | C<say LIST> は単に C<{ local $\ = "\n"; print LIST }> の省略形です。 |
13239 | 12824 | C<$_> の内容を表示するために LIST なしで FILEHANDLE を使用するには、 |
13240 | 12825 | C<$fh> のような間接ファイルハンドルではなく、C<FH> のような実際の |
13241 | 12826 | ファイルハンドルを使わなければなりません。 |
13242 | 12827 | |
13243 | 12828 | =begin original |
13244 | 12829 | |
13245 | 12830 | This keyword is available only when the C<"say"> feature |
13246 | 12831 | is enabled, or when prefixed with C<CORE::>; see |
13247 | 12832 | L<feature>. Alternately, include a C<use v5.10> or later to the current |
13248 | 12833 | scope. |
13249 | 12834 | |
13250 | 12835 | =end original |
13251 | 12836 | |
13252 | 12837 | このキーワードは、C<"say"> 機能が有効か、C<CORE::> が前置された場合にのみ |
13253 | 12838 | 利用可能です; L<feature> を参照してください。 |
13254 | 12839 | または、現在のスコープに C<use v5.10> 以降を含めてください。 |
13255 | 12840 | |
13256 | 12841 | =item scalar EXPR |
13257 | 12842 | X<scalar> X<context> |
13258 | 12843 | |
13259 | 12844 | =for Pod::Functions force a scalar context |
13260 | 12845 | |
13261 | 12846 | =begin original |
13262 | 12847 | |
13263 | 12848 | Forces EXPR to be interpreted in scalar context and returns the value |
13264 | 12849 | of EXPR. |
13265 | 12850 | |
13266 | 12851 | =end original |
13267 | 12852 | |
13268 | 12853 | EXPR を強制的にスカラコンテキストで解釈されるようにして、 |
13269 | 12854 | EXPR の値を返します。 |
13270 | 12855 | |
13271 | 12856 | @counts = ( scalar @a, scalar @b, scalar @c ); |
13272 | 12857 | |
13273 | 12858 | =begin original |
13274 | 12859 | |
13275 | 12860 | There is no equivalent operator to force an expression to |
13276 | 12861 | be interpolated in list context because in practice, this is never |
13277 | 12862 | needed. If you really wanted to do so, however, you could use |
13278 | 12863 | the construction C<@{[ (some expression) ]}>, but usually a simple |
13279 | 12864 | C<(some expression)> suffices. |
13280 | 12865 | |
13281 | 12866 | =end original |
13282 | 12867 | |
13283 | 12868 | 式を強制的にリストコンテキストで解釈させるようにする演算子はありません; |
13284 | 12869 | 理論的には不要だからです。 |
13285 | 12870 | それでも、もしそうしたいのなら、C<@{[ (some expression) ]}> という構造を |
13286 | 12871 | 使えます; しかし、普通は単に C<(some expression)> とすれば十分です。 |
13287 | 12872 | |
13288 | 12873 | =begin original |
13289 | 12874 | |
13290 | 12875 | Because C<scalar> is a unary operator, if you accidentally use a |
13291 | 12876 | parenthesized list for the EXPR, this behaves as a scalar comma expression, |
13292 | 12877 | evaluating all but the last element in void context and returning the final |
13293 | 12878 | element evaluated in scalar context. This is seldom what you want. |
13294 | 12879 | |
13295 | 12880 | =end original |
13296 | 12881 | |
13297 | 12882 | C<scalar> は単項演算子なので、EXPR として括弧でくくったリストを使った場合、 |
13298 | 12883 | これはスカラカンマ表現として振舞い、最後以外の全ては無効コンテキストとして |
13299 | 12884 | 扱われ、最後の要素をスカラコンテキストとして扱った結果が返されます。 |
13300 | 12885 | これがあなたの望むものであることはめったにないでしょう。 |
13301 | 12886 | |
13302 | 12887 | =begin original |
13303 | 12888 | |
13304 | 12889 | The following single statement: |
13305 | 12890 | |
13306 | 12891 | =end original |
13307 | 12892 | |
13308 | 12893 | 以下の一つの文は: |
13309 | 12894 | |
13310 | 12895 | print uc(scalar(&foo,$bar)),$baz; |
13311 | 12896 | |
13312 | 12897 | =begin original |
13313 | 12898 | |
13314 | 12899 | is the moral equivalent of these two: |
13315 | 12900 | |
13316 | 12901 | =end original |
13317 | 12902 | |
13318 | 12903 | 以下の二つの文と等価です。 |
13319 | 12904 | |
13320 | 12905 | &foo; |
13321 | 12906 | print(uc($bar),$baz); |
13322 | 12907 | |
13323 | 12908 | =begin original |
13324 | 12909 | |
13325 | 12910 | See L<perlop> for more details on unary operators and the comma operator. |
13326 | 12911 | |
13327 | 12912 | =end original |
13328 | 12913 | |
13329 | 12914 | 単項演算子とカンマ演算子に関する詳細については L<perlop> を参照してください。 |
13330 | 12915 | |
13331 | 12916 | =item seek FILEHANDLE,POSITION,WHENCE |
13332 | 12917 | X<seek> X<fseek> X<filehandle, position> |
13333 | 12918 | |
13334 | 12919 | =for Pod::Functions reposition file pointer for random-access I/O |
13335 | 12920 | |
13336 | 12921 | =begin original |
13337 | 12922 | |
13338 | 12923 | Sets FILEHANDLE's position, just like the C<fseek> call of C<stdio>. |
13339 | 12924 | FILEHANDLE may be an expression whose value gives the name of the |
13340 | 12925 | filehandle. The values for WHENCE are C<0> to set the new position |
13341 | 12926 | I<in bytes> to POSITION; C<1> to set it to the current position plus |
13342 | 12927 | POSITION; and C<2> to set it to EOF plus POSITION, typically |
13343 | 12928 | negative. For WHENCE you may use the constants C<SEEK_SET>, |
13344 | 12929 | C<SEEK_CUR>, and C<SEEK_END> (start of the file, current position, end |
13345 | 12930 | of the file) from the L<Fcntl> module. Returns C<1> on success, false |
13346 | 12931 | otherwise. |
13347 | 12932 | |
13348 | 12933 | =end original |
13349 | 12934 | |
13350 | 12935 | C<stdio> ライブラリの C<fseek> 関数のように、FILEHANDLE の |
13351 | 12936 | ファイルポインタを任意の位置に設定します。 |
13352 | 12937 | FILEHANDLE は、実際のファイルハンドル名を与える式でもかまいません。 |
13353 | 12938 | WHENCE の値が、C<0> ならば、新しい位置を I<バイト単位で> POSITION の位置へ |
13354 | 12939 | 設定します; C<1> ならば、現在位置から I<バイト数で> POSITION 加えた位置へ |
13355 | 12940 | 設定します; C<2> ならば、EOF からPOSITION だけ加えた位置へ、新しい位置を |
13356 | 12941 | 設定します。 |
13357 | 12942 | この値には、L<Fcntl> モジュールで使われている C<SEEK_SET>、C<SEEK_CUR>、 |
13358 | 12943 | C<SEEK_END> (ファイルの先頭、現在位置、ファイルの最後)という定数を |
13359 | 12944 | 使うこともできます。 |
13360 | 12945 | 成功時には、C<1> を、失敗時には C<0> を返します。 |
13361 | 12946 | |
13362 | 12947 | =begin original |
13363 | 12948 | |
13364 | 12949 | Note the I<in bytes>: even if the filehandle has been set to |
13365 | 12950 | operate on characters (for example by using the C<:encoding(utf8)> open |
13366 | 12951 | layer), tell() will return byte offsets, not character offsets |
13367 | 12952 | (because implementing that would render seek() and tell() rather slow). |
13368 | 12953 | |
13369 | 12954 | =end original |
13370 | 12955 | |
13371 | 12956 | I<バイト単位> に関する注意: ファイルハンドルが (例えば C<:encoding(utf8)> 層を |
13372 | 12957 | 使って)文字を操作するように設定されていたとしても、tell() は文字の |
13373 | 12958 | オフセットではなくバイトのオフセットを返すことに注意してください |
13374 | 12959 | (なぜならこれを実装すると seek() と tell() が遅くなってしまうからです)。 |
13375 | 12960 | |
13376 | 12961 | =begin original |
13377 | 12962 | |
13378 | 12963 | If you want to position the file for C<sysread> or C<syswrite>, don't use |
13379 | 12964 | C<seek>, because buffering makes its effect on the file's read-write position |
13380 | 12965 | unpredictable and non-portable. Use C<sysseek> instead. |
13381 | 12966 | |
13382 | 12967 | =end original |
13383 | 12968 | |
13384 | 12969 | C<sysread> や C<syswrite> のためにファイルの位置を指定したい場合は、 |
13385 | 12970 | C<seek> は使えません; なぜならバッファリングのためにファイルの読み込み位置は |
13386 | 12971 | 動作は予測不能で移植性のないものになってしまいます。 |
13387 | 12972 | 代わりに C<sysseek> を使ってください。 |
13388 | 12973 | |
13389 | 12974 | =begin original |
13390 | 12975 | |
13391 | 12976 | Due to the rules and rigors of ANSI C, on some systems you have to do a |
13392 | 12977 | seek whenever you switch between reading and writing. Amongst other |
13393 | 12978 | things, this may have the effect of calling stdio's clearerr(3). |
13394 | 12979 | A WHENCE of C<1> (C<SEEK_CUR>) is useful for not moving the file position: |
13395 | 12980 | |
13396 | 12981 | =end original |
13397 | 12982 | |
13398 | 12983 | ANSI C の規則と困難により、システムによっては読み込みと書き込みを |
13399 | 12984 | 切り替える度にシークしなければならない場合があります。 |
13400 | 12985 | その他のことの中で、これは stdio の clearerr(3) を呼び出す効果があります。 |
13401 | 12986 | WHENCE の C<1> (C<SEEK_CUR>) が、ファイル位置を変えないので有用です: |
13402 | 12987 | |
13403 | 12988 | seek(TEST,0,1); |
13404 | 12989 | |
13405 | 12990 | =begin original |
13406 | 12991 | |
13407 | 12992 | This is also useful for applications emulating C<tail -f>. Once you hit |
13408 | 12993 | EOF on your read and then sleep for a while, you (probably) have to stick in a |
13409 | 12994 | dummy seek() to reset things. The C<seek> doesn't change the position, |
13410 | 12995 | but it I<does> clear the end-of-file condition on the handle, so that the |
13411 | 12996 | next C<< <FILE> >> makes Perl try again to read something. (We hope.) |
13412 | 12997 | |
13413 | 12998 | =end original |
13414 | 12999 | |
13415 | 13000 | これはアプリケーションで C<tail -f> をエミュレートするのにも有用です。 |
13416 | 13001 | 一度読み込み時に EOF に到達すると、しばらくスリープし、 |
13417 | 13002 | (おそらく) ダミーの seek() をすることでリセットする必要があります。 |
13418 | 13003 | C<seek> は現在の位置を変更しませんが、ハンドルの EOF 状態を |
13419 | 13004 | I<クリアします> ので、次の C<< <FILE> >> で Perl は再び何かを |
13420 | 13005 | 読み込もうとします。(そのはずです。) |
13421 | 13006 | |
13422 | 13007 | =begin original |
13423 | 13008 | |
13424 | 13009 | If that doesn't work (some I/O implementations are particularly |
13425 | 13010 | cantankerous), you might need something like this: |
13426 | 13011 | |
13427 | 13012 | =end original |
13428 | 13013 | |
13429 | 13014 | これが動かない場合(特に意地の悪い I/O 実装もあります)、 |
13430 | 13015 | 以下のようなことをする必要があります: |
13431 | 13016 | |
13432 | 13017 | for (;;) { |
13433 | 13018 | for ($curpos = tell(FILE); $_ = <FILE>; |
13434 | 13019 | $curpos = tell(FILE)) { |
13435 | 13020 | # search for some stuff and put it into files |
13436 | 13021 | } |
13437 | 13022 | sleep($for_a_while); |
13438 | 13023 | seek(FILE, $curpos, 0); |
13439 | 13024 | } |
13440 | 13025 | |
13441 | 13026 | =item seekdir DIRHANDLE,POS |
13442 | 13027 | X<seekdir> |
13443 | 13028 | |
13444 | 13029 | =for Pod::Functions reposition directory pointer |
13445 | 13030 | |
13446 | 13031 | =begin original |
13447 | 13032 | |
13448 | 13033 | Sets the current position for the C<readdir> routine on DIRHANDLE. POS |
13449 | 13034 | must be a value returned by C<telldir>. C<seekdir> also has the same caveats |
13450 | 13035 | about possible directory compaction as the corresponding system library |
13451 | 13036 | routine. |
13452 | 13037 | |
13453 | 13038 | =end original |
13454 | 13039 | |
13455 | 13040 | DIRHANDLE での C<readdir> ルーチンの現在位置を設定します。 |
13456 | 13041 | POS は、C<telldir> が返す値でなければなりません。 |
13457 | 13042 | C<seekdir> は同名のシステムライブラリルーチンと同じく、 |
13458 | 13043 | ディレクトリ縮小時の問題が考えられます。 |
13459 | 13044 | |
13460 | 13045 | =item select FILEHANDLE |
13461 | 13046 | X<select> X<filehandle, default> |
13462 | 13047 | |
13463 | 13048 | =item select |
13464 | 13049 | |
13465 | 13050 | =for Pod::Functions reset default output or do I/O multiplexing |
13466 | 13051 | |
13467 | 13052 | =begin original |
13468 | 13053 | |
13469 | 13054 | Returns the currently selected filehandle. If FILEHANDLE is supplied, |
13470 | 13055 | sets the new current default filehandle for output. This has two |
13471 | 13056 | effects: first, a C<write> or a C<print> without a filehandle |
13472 | 13057 | default to this FILEHANDLE. Second, references to variables related to |
13473 | 13058 | output will refer to this output channel. |
13474 | 13059 | |
13475 | 13060 | =end original |
13476 | 13061 | |
13477 | 13062 | その時点で、選択されていたファイルハンドルを返します。 |
13478 | 13063 | FILEHANDLE を指定した場合には、その値を出力のデフォルトファイルハンドルに |
13479 | 13064 | 設定します。 |
13480 | 13065 | これには、2 つの効果があります: まず、ファイルハンドルを指定しないで |
13481 | 13066 | C<write> や C<print> を行なった場合のデフォルトが、この FILEHANDLE に |
13482 | 13067 | なります。 |
13483 | 13068 | もう一つは、出力関連の変数への参照は、この出力チャネルを |
13484 | 13069 | 参照するようになります。 |
13485 | 13070 | |
13486 | 13071 | =begin original |
13487 | 13072 | |
13488 | 13073 | For example, to set the top-of-form format for more than one |
13489 | 13074 | output channel, you might do the following: |
13490 | 13075 | |
13491 | 13076 | =end original |
13492 | 13077 | |
13493 | 13078 | 例えば、複数の出力チャネルに対して、ページ先頭フォーマットを |
13494 | 13079 | 設定するには: |
13495 | 13080 | |
13496 | 13081 | select(REPORT1); |
13497 | 13082 | $^ = 'report1_top'; |
13498 | 13083 | select(REPORT2); |
13499 | 13084 | $^ = 'report2_top'; |
13500 | 13085 | |
13501 | 13086 | =begin original |
13502 | 13087 | |
13503 | 13088 | FILEHANDLE may be an expression whose value gives the name of the |
13504 | 13089 | actual filehandle. Thus: |
13505 | 13090 | |
13506 | 13091 | =end original |
13507 | 13092 | |
13508 | 13093 | FILEHANDLE は、実際のファイルハンドル名を示す式でもかまいません。 |
13509 | 13094 | つまり、以下のようなものです: |
13510 | 13095 | |
13511 | 13096 | $oldfh = select(STDERR); $| = 1; select($oldfh); |
13512 | 13097 | |
13513 | 13098 | =begin original |
13514 | 13099 | |
13515 | 13100 | Some programmers may prefer to think of filehandles as objects with |
13516 | 13101 | methods, preferring to write the last example as: |
13517 | 13102 | |
13518 | 13103 | =end original |
13519 | 13104 | |
13520 | 13105 | ファイルハンドルはメソッドを持ったオブジェクトであると考えることを好む |
13521 | 13106 | プログラマもいるかもしれません; そのような場合のための最後の例は |
13522 | 13107 | 以下のようなものです: |
13523 | 13108 | |
13524 | 13109 | use IO::Handle; |
13525 | 13110 | STDERR->autoflush(1); |
13526 | 13111 | |
13527 | 13112 | =begin original |
13528 | 13113 | |
13529 | 13114 | Portability issues: L<perlport/select>. |
13530 | 13115 | |
13531 | 13116 | =end original |
13532 | 13117 | |
13533 | 13118 | 移植性の問題: L<perlport/select>。 |
13534 | 13119 | |
13535 | 13120 | =item select RBITS,WBITS,EBITS,TIMEOUT |
13536 | 13121 | X<select> |
13537 | 13122 | |
13538 | 13123 | =begin original |
13539 | 13124 | |
13540 | 13125 | This calls the select(2) syscall with the bit masks specified, which |
13541 | 13126 | can be constructed using C<fileno> and C<vec>, along these lines: |
13542 | 13127 | |
13543 | 13128 | =end original |
13544 | 13129 | |
13545 | 13130 | これは、select(2) システムコールを、指定したビットマスクで呼び出します; |
13546 | 13131 | ビットマスクは、C<fileno> と C<vec> を使って、以下のようにして |
13547 | 13132 | 作成できます: |
13548 | 13133 | |
13549 | 13134 | $rin = $win = $ein = ''; |
13550 | 13135 | vec($rin, fileno(STDIN), 1) = 1; |
13551 | 13136 | vec($win, fileno(STDOUT), 1) = 1; |
13552 | 13137 | $ein = $rin | $win; |
13553 | 13138 | |
13554 | 13139 | =begin original |
13555 | 13140 | |
13556 | 13141 | If you want to select on many filehandles, you may wish to write a |
13557 | 13142 | subroutine like this: |
13558 | 13143 | |
13559 | 13144 | =end original |
13560 | 13145 | |
13561 | 13146 | 複数のファイルハンドルに select を行ないたいのであれば、 |
13562 | 13147 | 以下のようにします: |
13563 | 13148 | |
13564 | 13149 | sub fhbits { |
13565 | 13150 | my @fhlist = @_; |
13566 | 13151 | my $bits = ""; |
13567 | 13152 | for my $fh (@fhlist) { |
13568 | 13153 | vec($bits, fileno($fh), 1) = 1; |
13569 | 13154 | } |
13570 | 13155 | return $bits; |
13571 | 13156 | } |
13572 | 13157 | $rin = fhbits(*STDIN, *TTY, *MYSOCK); |
13573 | 13158 | |
13574 | 13159 | =begin original |
13575 | 13160 | |
13576 | 13161 | The usual idiom is: |
13577 | 13162 | |
13578 | 13163 | =end original |
13579 | 13164 | |
13580 | 13165 | 通常は、 |
13581 | 13166 | |
13582 | 13167 | ($nfound,$timeleft) = |
13583 | 13168 | select($rout=$rin, $wout=$win, $eout=$ein, $timeout); |
13584 | 13169 | |
13585 | 13170 | =begin original |
13586 | 13171 | |
13587 | 13172 | or to block until something becomes ready just do this |
13588 | 13173 | |
13589 | 13174 | =end original |
13590 | 13175 | |
13591 | 13176 | のように使い、いずれかの準備が整うまでブロックするには、 |
13592 | 13177 | 以下のようにします。 |
13593 | 13178 | |
13594 | 13179 | $nfound = select($rout=$rin, $wout=$win, $eout=$ein, undef); |
13595 | 13180 | |
13596 | 13181 | =begin original |
13597 | 13182 | |
13598 | 13183 | Most systems do not bother to return anything useful in $timeleft, so |
13599 | 13184 | calling select() in scalar context just returns $nfound. |
13600 | 13185 | |
13601 | 13186 | =end original |
13602 | 13187 | |
13603 | 13188 | ほとんどのシステムではわざわざ意味のある値を $timeleft に返さないので、 |
13604 | 13189 | select() をスカラコンテキストで呼び出すと、単に $nfound を返します。 |
13605 | 13190 | |
13606 | 13191 | =begin original |
13607 | 13192 | |
13608 | 13193 | Any of the bit masks can also be undef. The timeout, if specified, is |
13609 | 13194 | in seconds, which may be fractional. Note: not all implementations are |
13610 | 13195 | capable of returning the $timeleft. If not, they always return |
13611 | 13196 | $timeleft equal to the supplied $timeout. |
13612 | 13197 | |
13613 | 13198 | =end original |
13614 | 13199 | |
13615 | 13200 | どのビットマスクにも undef を設定することができます。 |
13616 | 13201 | TIMEOUT を指定するときは、秒数で指定し、小数でかまいません。 |
13617 | 13202 | 注: すべての実装で、$timeleft が返せるものではありません。 |
13618 | 13203 | その場合、$timeleft には、常に指定した TIMEOUT と同じ値が返されます。 |
13619 | 13204 | |
13620 | 13205 | =begin original |
13621 | 13206 | |
13622 | 13207 | You can effect a sleep of 250 milliseconds this way: |
13623 | 13208 | |
13624 | 13209 | =end original |
13625 | 13210 | |
13626 | 13211 | 250 ミリ秒の sleep と同じ効果が、以下のようにして得られます。 |
13627 | 13212 | |
13628 | 13213 | select(undef, undef, undef, 0.25); |
13629 | 13214 | |
13630 | 13215 | =begin original |
13631 | 13216 | |
13632 | 13217 | Note that whether C<select> gets restarted after signals (say, SIGALRM) |
13633 | 13218 | is implementation-dependent. See also L<perlport> for notes on the |
13634 | 13219 | portability of C<select>. |
13635 | 13220 | |
13636 | 13221 | =end original |
13637 | 13222 | |
13638 | 13223 | C<select> がシグナル (例えば、SIGALRM) の後に再起動するかどうかは |
13639 | 13224 | 実装依存であることに注意してください。 |
13640 | 13225 | C<select> の移植性に関する注意については L<perlport> も参照してください。 |
13641 | 13226 | |
13642 | 13227 | =begin original |
13643 | 13228 | |
13644 | 13229 | On error, C<select> behaves just like select(2): it returns |
13645 | 13230 | -1 and sets C<$!>. |
13646 | 13231 | |
13647 | 13232 | =end original |
13648 | 13233 | |
13649 | 13234 | エラー時は、C<select> は select(2) のように振舞います: |
13650 | 13235 | -1 を返し、C<$!> をセットします。 |
13651 | 13236 | |
13652 | 13237 | =begin original |
13653 | 13238 | |
13654 | 13239 | On some Unixes, select(2) may report a socket file descriptor as "ready for |
13655 | 13240 | reading" even when no data is available, and thus any subsequent C<read> |
13656 | 13241 | would block. This can be avoided if you always use O_NONBLOCK on the |
13657 | 13242 | socket. See select(2) and fcntl(2) for further details. |
13658 | 13243 | |
13659 | 13244 | =end original |
13660 | 13245 | |
13661 | 13246 | Unix の中には、実際に利用可能なデータがないために引き続く C<read> が |
13662 | 13247 | ブロックされる場合でも、select(2) が、ソケットファイル記述子が |
13663 | 13248 | 「読み込み準備中」であると報告するものもあります。 |
13664 | 13249 | これは、ソケットに対して常に O_NONBLOCK フラグを使うことで回避できます。 |
13665 | 13250 | さらなる詳細については select(2) と fcntl(2) を参照してください。 |
13666 | 13251 | |
13667 | 13252 | =begin original |
13668 | 13253 | |
13669 | 13254 | The standard C<IO::Select> module provides a user-friendlier interface |
13670 | 13255 | to C<select>, mostly because it does all the bit-mask work for you. |
13671 | 13256 | |
13672 | 13257 | =end original |
13673 | 13258 | |
13674 | 13259 | 標準の C<IO::Select> モジュールは C<select> へのよりユーザーフレンドリーな |
13675 | 13260 | インターフェースを提供します; 主な理由はビットマスクの仕事を |
13676 | 13261 | してくれることです。 |
13677 | 13262 | |
13678 | 13263 | =begin original |
13679 | 13264 | |
13680 | 13265 | B<WARNING>: One should not attempt to mix buffered I/O (like C<read> |
13681 | 13266 | or <FH>) with C<select>, except as permitted by POSIX, and even |
13682 | 13267 | then only on POSIX systems. You have to use C<sysread> instead. |
13683 | 13268 | |
13684 | 13269 | =end original |
13685 | 13270 | |
13686 | 13271 | B<警告>: バッファ付き I/O (C<read> や <FH>) と C<select> を |
13687 | 13272 | 混ぜて使ってはいけません(例外: POSIX で認められている形で使い、 |
13688 | 13273 | POSIX システムでだけ動かす場合を除きます)。 |
13689 | 13274 | 代わりに C<sysread> を使わなければなりません。 |
13690 | 13275 | |
13691 | 13276 | =begin original |
13692 | 13277 | |
13693 | 13278 | Portability issues: L<perlport/select>. |
13694 | 13279 | |
13695 | 13280 | =end original |
13696 | 13281 | |
13697 | 13282 | 移植性の問題: L<perlport/select>。 |
13698 | 13283 | |
13699 | 13284 | =item semctl ID,SEMNUM,CMD,ARG |
13700 | 13285 | X<semctl> |
13701 | 13286 | |
13702 | 13287 | =for Pod::Functions SysV semaphore control operations |
13703 | 13288 | |
13704 | 13289 | =begin original |
13705 | 13290 | |
13706 | 13291 | Calls the System V IPC function semctl(2). You'll probably have to say |
13707 | 13292 | |
13708 | 13293 | =end original |
13709 | 13294 | |
13710 | 13295 | System V IPC 関数 semctl(2) を呼び出します。 |
13711 | 13296 | 正しい定数定義を得るために、まず |
13712 | 13297 | |
13713 | 13298 | use IPC::SysV; |
13714 | 13299 | |
13715 | 13300 | =begin original |
13716 | 13301 | |
13717 | 13302 | first to get the correct constant definitions. If CMD is IPC_STAT or |
13718 | 13303 | GETALL, then ARG must be a variable that will hold the returned |
13719 | 13304 | semid_ds structure or semaphore value array. Returns like C<ioctl>: |
13720 | 13305 | the undefined value for error, "C<0 but true>" for zero, or the actual |
13721 | 13306 | return value otherwise. The ARG must consist of a vector of native |
13722 | 13307 | short integers, which may be created with C<pack("s!",(0)x$nsem)>. |
13723 | 13308 | See also L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::Semaphore> |
13724 | 13309 | documentation. |
13725 | 13310 | |
13726 | 13311 | =end original |
13727 | 13312 | |
13728 | 13313 | と書くことが必要でしょう。 |
13729 | 13314 | CMD が、IPC_STAT か GETALL のときには、ARG は、返される |
13730 | 13315 | semid_ds 構造体か、セマフォ値の配列を納める変数でなければなりません。 |
13731 | 13316 | C<ioctl> と同じように、エラー時には未定義値、 |
13732 | 13317 | ゼロのときは C<"0 だが真">、それ以外なら、その値そのものを返します。 |
13733 | 13318 | ARG はネイティブな short int のベクターから成っていなければなりません; これは |
13734 | 13319 | C<pack("s!",(0)x$nsem)> で作成できます。 |
13735 | 13320 | L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::Semaphore> も参照してください。 |
13736 | 13321 | |
13737 | 13322 | =begin original |
13738 | 13323 | |
13739 | 13324 | Portability issues: L<perlport/semctl>. |
13740 | 13325 | |
13741 | 13326 | =end original |
13742 | 13327 | |
13743 | 13328 | 移植性の問題: L<perlport/semctl>。 |
13744 | 13329 | |
13745 | 13330 | =item semget KEY,NSEMS,FLAGS |
13746 | 13331 | X<semget> |
13747 | 13332 | |
13748 | 13333 | =for Pod::Functions get set of SysV semaphores |
13749 | 13334 | |
13750 | 13335 | =begin original |
13751 | 13336 | |
13752 | 13337 | Calls the System V IPC function semget(2). Returns the semaphore id, or |
13753 | 13338 | the undefined value on error. See also |
13754 | 13339 | L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Semaphore> |
13755 | 13340 | documentation. |
13756 | 13341 | |
13757 | 13342 | =end original |
13758 | 13343 | |
13759 | 13344 | System V IPC 関数 semget(2) を呼び出します。 |
13760 | 13345 | セマフォ ID か、エラー時には未定義値を返します。 |
13761 | 13346 | L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Semaphore> も |
13762 | 13347 | 参照してください。 |
13763 | 13348 | |
13764 | 13349 | =begin original |
13765 | 13350 | |
13766 | 13351 | Portability issues: L<perlport/semget>. |
13767 | 13352 | |
13768 | 13353 | =end original |
13769 | 13354 | |
13770 | 13355 | 移植性の問題: L<perlport/semget>。 |
13771 | 13356 | |
13772 | 13357 | =item semop KEY,OPSTRING |
13773 | 13358 | X<semop> |
13774 | 13359 | |
13775 | 13360 | =for Pod::Functions SysV semaphore operations |
13776 | 13361 | |
13777 | 13362 | =begin original |
13778 | 13363 | |
13779 | 13364 | Calls the System V IPC function semop(2) for semaphore operations |
13780 | 13365 | such as signalling and waiting. OPSTRING must be a packed array of |
13781 | 13366 | semop structures. Each semop structure can be generated with |
13782 | 13367 | C<pack("s!3", $semnum, $semop, $semflag)>. The length of OPSTRING |
13783 | 13368 | implies the number of semaphore operations. Returns true if |
13784 | 13369 | successful, false on error. As an example, the |
13785 | 13370 | following code waits on semaphore $semnum of semaphore id $semid: |
13786 | 13371 | |
13787 | 13372 | =end original |
13788 | 13373 | |
13789 | 13374 | シグナルを送信や、待ち合わせなどのセマフォ操作を行なうために、 |
13790 | 13375 | System V IPC 関数 semop(2) を呼び出します。 |
13791 | 13376 | OPSTRING は、semop 構造体の pack された配列でなければなりません。 |
13792 | semop 構造体は、それぞれ、 | |
13377 | semop 構造体は、それぞれ、 | |
13793 | 作ることができます。 | |
13378 | C<pack("s!3", $semnum, $semop, $semflag)> のように作ることができます。 | |
13794 | 13379 | セマフォ操作の数は、OPSTRING の長さからわかります。 |
13795 | 13380 | 成功時には真を、エラー時には偽を返します。 |
13796 | 13381 | 以下の例は、セマフォ ID $semid のセマフォ $semnum で |
13797 | 13382 | 待ち合わせを行ないます。 |
13798 | 13383 | |
13799 | 13384 | $semop = pack("s!3", $semnum, -1, 0); |
13800 | 13385 | die "Semaphore trouble: $!\n" unless semop($semid, $semop); |
13801 | 13386 | |
13802 | 13387 | =begin original |
13803 | 13388 | |
13804 | 13389 | To signal the semaphore, replace C<-1> with C<1>. See also |
13805 | 13390 | L<perlipc/"SysV IPC">, C<IPC::SysV>, and C<IPC::SysV::Semaphore> |
13806 | 13391 | documentation. |
13807 | 13392 | |
13808 | 13393 | =end original |
13809 | 13394 | |
13810 | 13395 | セマフォにシグナルを送るには、C<-1> を C<1> に変更してください。 |
13811 | 13396 | L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Semaphore> も |
13812 | 13397 | 参照してください。 |
13813 | 13398 | |
13814 | 13399 | =begin original |
13815 | 13400 | |
13816 | 13401 | Portability issues: L<perlport/semop>. |
13817 | 13402 | |
13818 | 13403 | =end original |
13819 | 13404 | |
13820 | 13405 | 移植性の問題: L<perlport/semop>。 |
13821 | 13406 | |
13822 | 13407 | =item send SOCKET,MSG,FLAGS,TO |
13823 | 13408 | X<send> |
13824 | 13409 | |
13825 | 13410 | =item send SOCKET,MSG,FLAGS |
13826 | 13411 | |
13827 | 13412 | =for Pod::Functions send a message over a socket |
13828 | 13413 | |
13829 | 13414 | =begin original |
13830 | 13415 | |
13831 | 13416 | Sends a message on a socket. Attempts to send the scalar MSG to the SOCKET |
13832 | 13417 | filehandle. Takes the same flags as the system call of the same name. On |
13833 | 13418 | unconnected sockets, you must specify a destination to I<send to>, in which |
13834 | 13419 | case it does a sendto(2) syscall. Returns the number of characters sent, |
13835 | 13420 | or the undefined value on error. The sendmsg(2) syscall is currently |
13836 | 13421 | unimplemented. See L<perlipc/"UDP: Message Passing"> for examples. |
13837 | 13422 | |
13838 | 13423 | =end original |
13839 | 13424 | |
13840 | 13425 | ソケットにメッセージを送ります。 |
13841 | 13426 | スカラ MSG を ファイルハンドル SOCKET に送ろうとします。 |
13842 | 13427 | 同名のシステムコールと同じフラグが指定できます。 |
13843 | 13428 | 接続していないソケットには、I<send to> に接続先を指定しなければならず、 |
13844 | 13429 | この場合、sendto(2) を実行します。 |
13845 | 13430 | 送信した文字数か、エラー時には、未定義値を返します。 |
13846 | 13431 | システムコール sendmsg(2) は現在実装されていません。 |
13847 | 13432 | 例については L<perlipc/"UDP: Message Passing"> を参照してください。 |
13848 | 13433 | |
13849 | 13434 | =begin original |
13850 | 13435 | |
13851 | 13436 | Note the I<characters>: depending on the status of the socket, either |
13852 | 13437 | (8-bit) bytes or characters are sent. By default all sockets operate |
13853 | 13438 | on bytes, but for example if the socket has been changed using |
13854 | 13439 | binmode() to operate with the C<:encoding(utf8)> I/O layer (see |
13855 | 13440 | L</open>, or the C<open> pragma, L<open>), the I/O will operate on UTF-8 |
13856 | 13441 | encoded Unicode characters, not bytes. Similarly for the C<:encoding> |
13857 | 13442 | pragma: in that case pretty much any characters can be sent. |
13858 | 13443 | |
13859 | 13444 | =end original |
13860 | 13445 | |
13861 | 13446 | I<文字> に関する注意: ソケットの状態によって、(8 ビットの) バイトか |
13862 | 13447 | 文字を送信します。 |
13863 | 13448 | デフォルトでは全てのソケットはバイトを処理しますが、 |
13864 | 13449 | 例えばソケットが binmode() で C<:encoding(utf8)> I/O 層(L</open>、 |
13865 | 13450 | C<open> プラグマ、L<open> を参照してください) を使うように指定された場合、 |
13866 | 13451 | I/O はバイトではなく、UTF-8 エンコードされた Unicode 文字を操作します。 |
13867 | 13452 | C<:encoding> プラグマも同様です: |
13868 | 13453 | この場合、ほとんど大体全ての文字が書き込めます。 |
13869 | 13454 | |
13870 | 13455 | =item setpgrp PID,PGRP |
13871 | 13456 | X<setpgrp> X<group> |
13872 | 13457 | |
13873 | 13458 | =for Pod::Functions set the process group of a process |
13874 | 13459 | |
13875 | 13460 | =begin original |
13876 | 13461 | |
13877 | 13462 | Sets the current process group for the specified PID, C<0> for the current |
13878 | 13463 | process. Raises an exception when used on a machine that doesn't |
13879 | 13464 | implement POSIX setpgid(2) or BSD setpgrp(2). If the arguments are omitted, |
13880 | 13465 | it defaults to C<0,0>. Note that the BSD 4.2 version of C<setpgrp> does not |
13881 | 13466 | accept any arguments, so only C<setpgrp(0,0)> is portable. See also |
13882 | 13467 | C<POSIX::setsid()>. |
13883 | 13468 | |
13884 | 13469 | =end original |
13885 | 13470 | |
13886 | 13471 | 指定した PID (C<0> を指定するとカレントプロセス) に |
13887 | 13472 | 対するプロセスグループを設定します。 |
13888 | 13473 | POSIX setpgrp(2) または BSD setpgrp(2) が実装されていないマシンでは、 |
13889 | 13474 | 例外が発生します。 |
13890 | 13475 | 引数が省略された場合は、C<0,0>が使われます。 |
13891 | 13476 | BSD 4.2 版の C<setpgrp> は引数を取ることができないので、 |
13892 | 13477 | C<setpgrp(0,0)> のみが移植性があることに注意してください。 |
13893 | 13478 | C<POSIX::setsid()> も参照してください。 |
13894 | 13479 | |
13895 | 13480 | =begin original |
13896 | 13481 | |
13897 | 13482 | Portability issues: L<perlport/setpgrp>. |
13898 | 13483 | |
13899 | 13484 | =end original |
13900 | 13485 | |
13901 | 13486 | 移植性の問題: L<perlport/setpgrp>。 |
13902 | 13487 | |
13903 | 13488 | =item setpriority WHICH,WHO,PRIORITY |
13904 | 13489 | X<setpriority> X<priority> X<nice> X<renice> |
13905 | 13490 | |
13906 | 13491 | =for Pod::Functions set a process's nice value |
13907 | 13492 | |
13908 | 13493 | =begin original |
13909 | 13494 | |
13910 | 13495 | Sets the current priority for a process, a process group, or a user. |
13911 | 13496 | (See setpriority(2).) Raises an exception when used on a machine |
13912 | 13497 | that doesn't implement setpriority(2). |
13913 | 13498 | |
13914 | 13499 | =end original |
13915 | 13500 | |
13916 | 13501 | プロセス、プロセスグループ、ユーザに対する優先順位を設定します。 |
13917 | 13502 | (setpriority(2) を参照してください。) |
13918 | setpriority(2) が実装されていないマシンでは、 | |
13503 | setpriority(2) が実装されていないマシンでは、 | |
13504 | 例外が発生します。 | |
13919 | 13505 | |
13920 | 13506 | =begin original |
13921 | 13507 | |
13922 | 13508 | Portability issues: L<perlport/setpriority>. |
13923 | 13509 | |
13924 | 13510 | =end original |
13925 | 13511 | |
13926 | 13512 | 移植性の問題: L<perlport/setpriority>。 |
13927 | 13513 | |
13928 | 13514 | =item setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL |
13929 | 13515 | X<setsockopt> |
13930 | 13516 | |
13931 | 13517 | =for Pod::Functions set some socket options |
13932 | 13518 | |
13933 | 13519 | =begin original |
13934 | 13520 | |
13935 | 13521 | Sets the socket option requested. Returns C<undef> on error. |
13936 | 13522 | Use integer constants provided by the C<Socket> module for |
13937 | 13523 | LEVEL and OPNAME. Values for LEVEL can also be obtained from |
13938 | 13524 | getprotobyname. OPTVAL might either be a packed string or an integer. |
13939 | 13525 | An integer OPTVAL is shorthand for pack("i", OPTVAL). |
13940 | 13526 | |
13941 | 13527 | =end original |
13942 | 13528 | |
13943 | 13529 | 要求したソケットオプションを設定します。 |
13944 | 13530 | エラー時には、C<undef> を返します。 |
13945 | 13531 | LEVEL と OPNAME には C<Socket> モジュールが提供する整数定数を使います。 |
13946 | 13532 | LEVEL の値は getprotobyname から得ることもできます。 |
13947 | 13533 | OPTVAL は pack された文字列か整数です。 |
13948 | 13534 | 整数の OPTVAL は pack("i", OPTVAL) の省略表現です。 |
13949 | 13535 | |
13950 | 13536 | =begin original |
13951 | 13537 | |
13952 | 13538 | An example disabling Nagle's algorithm on a socket: |
13953 | 13539 | |
13954 | 13540 | =end original |
13955 | 13541 | |
13956 | 13542 | ソケットに対する Nagle のアルゴリズムを無効にする例です: |
13957 | 13543 | |
13958 | 13544 | use Socket qw(IPPROTO_TCP TCP_NODELAY); |
13959 | 13545 | setsockopt($socket, IPPROTO_TCP, TCP_NODELAY, 1); |
13960 | 13546 | |
13961 | 13547 | =begin original |
13962 | 13548 | |
13963 | 13549 | Portability issues: L<perlport/setsockopt>. |
13964 | 13550 | |
13965 | 13551 | =end original |
13966 | 13552 | |
13967 | 13553 | 移植性の問題: L<perlport/setsockopt>。 |
13968 | 13554 | |
13969 | 13555 | =item shift ARRAY |
13970 | 13556 | X<shift> |
13971 | 13557 | |
13972 | 13558 | =item shift EXPR |
13973 | 13559 | |
13974 | 13560 | =item shift |
13975 | 13561 | |
13976 | 13562 | =for Pod::Functions remove the first element of an array, and return it |
13977 | 13563 | |
13978 | 13564 | =begin original |
13979 | 13565 | |
13980 | 13566 | Shifts the first value of the array off and returns it, shortening the |
13981 | 13567 | array by 1 and moving everything down. If there are no elements in the |
13982 | 13568 | array, returns the undefined value. If ARRAY is omitted, shifts the |
13983 | 13569 | C<@_> array within the lexical scope of subroutines and formats, and the |
13984 | 13570 | C<@ARGV> array outside a subroutine and also within the lexical scopes |
13985 | 13571 | established by the C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}>, |
13986 | 13572 | C<UNITCHECK {}>, and C<END {}> constructs. |
13987 | 13573 | |
13988 | 13574 | =end original |
13989 | 13575 | |
13990 | 配列の最初の値を取り出して、その値を返し、配列を一つ | |
13576 | 配列の最初の値を取り出して、その値を返し、配列を一つ | |
13991 | 前へずらします。 | |
13577 | 短くして、すべての要素を前へずらします。 | |
13992 | 13578 | 配列に要素がなければ、未定義値を返します。 |
13993 | ARRAY を省略すると、 | |
13579 | ARRAY を省略すると、 | |
13994 | ||
13580 | サブルーチンやフォーマットのレキシカルスコープでは C<@_> を、 | |
13995 | C<C | |
13581 | サブルーチンの外側で、C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}>, | |
13582 | C<UNITCHECK {}>, C<END {}> で作成されたレキシカルスコープでは | |
13996 | 13583 | C<@ARGV> が用いられます。 |
13997 | 13584 | |
13998 | 13585 | =begin original |
13999 | 13586 | |
14000 | 13587 | Starting with Perl 5.14, C<shift> can take a scalar EXPR, which must hold a |
14001 | 13588 | reference to an unblessed array. The argument will be dereferenced |
14002 | 13589 | automatically. This aspect of C<shift> is considered highly experimental. |
14003 | 13590 | The exact behaviour may change in a future version of Perl. |
14004 | 13591 | |
14005 | 13592 | =end original |
14006 | 13593 | |
14007 | 13594 | Perl 5.14 から、C<shift> はスカラの EXPR を取ることができるようになりました; |
14008 | 13595 | これは bless されていない配列へのリファレンスでなければなりません。 |
14009 | 13596 | 引数は自動的にデリファレンスされます。 |
14010 | 13597 | C<shift> のこの動作は高度に実験的であると考えられています。 |
14011 | 13598 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 |
14012 | 13599 | |
14013 | 13600 | =begin original |
14014 | 13601 | |
14015 | 13602 | To avoid confusing would-be users of your code who are running earlier |
14016 | 13603 | versions of Perl with mysterious syntax errors, put this sort of thing at |
14017 | 13604 | the top of your file to signal that your code will work I<only> on Perls of |
14018 | 13605 | a recent vintage: |
14019 | 13606 | |
14020 | 13607 | =end original |
14021 | 13608 | |
14022 | 13609 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な |
14023 | 13610 | 文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で |
14024 | 13611 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを |
14025 | 13612 | 書いてください: |
14026 | 13613 | |
14027 | 13614 | use 5.014; # so push/pop/etc work on scalars (experimental) |
14028 | 13615 | |
14029 | 13616 | =begin original |
14030 | 13617 | |
14031 | 13618 | See also C<unshift>, C<push>, and C<pop>. C<shift> and C<unshift> do the |
14032 | 13619 | same thing to the left end of an array that C<pop> and C<push> do to the |
14033 | 13620 | right end. |
14034 | 13621 | |
14035 | 13622 | =end original |
14036 | 13623 | |
14037 | 13624 | C<unshift>、C<push>、C<pop> も参照してください。 |
14038 | C<shift> と C<unshift> は、C<pop> と | |
13625 | C<shift> と C<unshift> は、C<pop> と | |
14039 | 左端で行ないます。 | |
13626 | C<push> が配列の右端で行なうことを、左端で行ないます。 | |
14040 | 13627 | |
14041 | 13628 | =item shmctl ID,CMD,ARG |
14042 | 13629 | X<shmctl> |
14043 | 13630 | |
14044 | 13631 | =for Pod::Functions SysV shared memory operations |
14045 | 13632 | |
14046 | 13633 | =begin original |
14047 | 13634 | |
14048 | 13635 | Calls the System V IPC function shmctl. You'll probably have to say |
14049 | 13636 | |
14050 | 13637 | =end original |
14051 | 13638 | |
14052 | 13639 | System V IPC 関数 shmctl を呼び出します。 |
14053 | 13640 | 正しい定数定義を得るために、まず |
14054 | 13641 | |
14055 | 13642 | use IPC::SysV; |
14056 | 13643 | |
14057 | 13644 | =begin original |
14058 | 13645 | |
14059 | 13646 | first to get the correct constant definitions. If CMD is C<IPC_STAT>, |
14060 | 13647 | then ARG must be a variable that will hold the returned C<shmid_ds> |
14061 | 13648 | structure. Returns like ioctl: C<undef> for error; "C<0> but |
14062 | 13649 | true" for zero; and the actual return value otherwise. |
14063 | 13650 | See also L<perlipc/"SysV IPC"> and C<IPC::SysV> documentation. |
14064 | 13651 | |
14065 | 13652 | =end original |
14066 | 13653 | |
14067 | 13654 | と書くことが必要でしょう。 |
14068 | 13655 | CMD が、C<IPC_STAT> ならば、ARG は、返される C<shmid_ds> 構造体を |
14069 | 13656 | 納める変数でなければなりません。 |
14070 | 13657 | ioctl と同様です: エラー時には C<undef>; ゼロのときは "C<0> だが真"; |
14071 | 13658 | それ以外なら、その値そのものを返します。 |
14072 | 13659 | L<perlipc/"SysV IPC"> と C<IPC::SysV> も参照してください。 |
14073 | 13660 | |
14074 | 13661 | =begin original |
14075 | 13662 | |
14076 | 13663 | Portability issues: L<perlport/shmctl>. |
14077 | 13664 | |
14078 | 13665 | =end original |
14079 | 13666 | |
14080 | 13667 | 移植性の問題: L<perlport/shmctl>。 |
14081 | 13668 | |
14082 | 13669 | =item shmget KEY,SIZE,FLAGS |
14083 | 13670 | X<shmget> |
14084 | 13671 | |
14085 | 13672 | =for Pod::Functions get SysV shared memory segment identifier |
14086 | 13673 | |
14087 | 13674 | =begin original |
14088 | 13675 | |
14089 | 13676 | Calls the System V IPC function shmget. Returns the shared memory |
14090 | 13677 | segment id, or C<undef> on error. |
14091 | 13678 | See also L<perlipc/"SysV IPC"> and C<IPC::SysV> documentation. |
14092 | 13679 | |
14093 | 13680 | =end original |
14094 | 13681 | |
14095 | 13682 | System V IPC 関数 shmget を呼び出します。 |
14096 | 13683 | 共有メモリのセグメント ID か、エラー時には C<undef> を返します。 |
14097 | 13684 | L<perlipc/"SysV IPC"> と C<IPC::SysV> も参照してください。 |
14098 | 13685 | |
14099 | 13686 | =begin original |
14100 | 13687 | |
14101 | 13688 | Portability issues: L<perlport/shmget>. |
14102 | 13689 | |
14103 | 13690 | =end original |
14104 | 13691 | |
14105 | 13692 | 移植性の問題: L<perlport/shmget>。 |
14106 | 13693 | |
14107 | 13694 | =item shmread ID,VAR,POS,SIZE |
14108 | 13695 | X<shmread> |
14109 | 13696 | X<shmwrite> |
14110 | 13697 | |
14111 | 13698 | =for Pod::Functions read SysV shared memory |
14112 | 13699 | |
14113 | 13700 | =item shmwrite ID,STRING,POS,SIZE |
14114 | 13701 | |
14115 | 13702 | =for Pod::Functions write SysV shared memory |
14116 | 13703 | |
14117 | 13704 | =begin original |
14118 | 13705 | |
14119 | 13706 | Reads or writes the System V shared memory segment ID starting at |
14120 | 13707 | position POS for size SIZE by attaching to it, copying in/out, and |
14121 | 13708 | detaching from it. When reading, VAR must be a variable that will |
14122 | 13709 | hold the data read. When writing, if STRING is too long, only SIZE |
14123 | 13710 | bytes are used; if STRING is too short, nulls are written to fill out |
14124 | 13711 | SIZE bytes. Return true if successful, false on error. |
14125 | 13712 | shmread() taints the variable. See also L<perlipc/"SysV IPC">, |
14126 | 13713 | C<IPC::SysV>, and the C<IPC::Shareable> module from CPAN. |
14127 | 13714 | |
14128 | 13715 | =end original |
14129 | 13716 | |
14130 | System V 共有メモリセグメント ID に対し、アタッチして、 | |
13717 | System V 共有メモリセグメント ID に対し、アタッチして、 | |
14131 | デタッチするという形で、位置 POS から、 | |
13718 | コピーを行ない、デタッチするという形で、位置 POS から、 | |
14132 | 行ないます。 | |
13719 | サイズ SIZE だけ、読み込みか書き込みを行ないます。 | |
14133 | 読み込み時には、VAR は読み込んだデータを納める | |
13720 | 読み込み時には、VAR は読み込んだデータを納める | |
13721 | 変数でなければなりません。 | |
14134 | 13722 | 書き込み時には、STRING が長すぎても、SIZE バイトだけが使われます; STRING が |
14135 | 13723 | 短すぎる場合には、SIZE バイトを埋めるために、ヌル文字が書き込まれます。 |
14136 | 13724 | 成功時には真を、エラー時には偽を返します。 |
14137 | 13725 | shmread() は変数を汚染します。 |
14138 | L<perlipc/"SysV IPC"> および C<IPC::SysV> と、 | |
13726 | L<perlipc/"SysV IPC"> および C<IPC::SysV> と、 | |
14139 | 参照してください。 | |
13727 | CPAN の C<IPC::Shareable> も参照してください。 | |
14140 | 13728 | |
14141 | 13729 | =begin original |
14142 | 13730 | |
14143 | 13731 | Portability issues: L<perlport/shmread> and L<perlport/shmwrite>. |
14144 | 13732 | |
14145 | 13733 | =end original |
14146 | 13734 | |
14147 | 13735 | 移植性の問題: L<perlport/shmread> と L<perlport/shmwrite>。 |
14148 | 13736 | |
14149 | 13737 | =item shutdown SOCKET,HOW |
14150 | 13738 | X<shutdown> |
14151 | 13739 | |
14152 | 13740 | =for Pod::Functions close down just half of a socket connection |
14153 | 13741 | |
14154 | 13742 | =begin original |
14155 | 13743 | |
14156 | 13744 | Shuts down a socket connection in the manner indicated by HOW, which |
14157 | 13745 | has the same interpretation as in the syscall of the same name. |
14158 | 13746 | |
14159 | 13747 | =end original |
14160 | 13748 | |
14161 | 13749 | 同名のシステムコールと同じように解釈される HOW によって、 |
14162 | 13750 | 指定された方法でソケット接続のシャットダウンを行ないます。 |
14163 | 13751 | |
14164 | 13752 | shutdown(SOCKET, 0); # I/we have stopped reading data |
14165 | 13753 | shutdown(SOCKET, 1); # I/we have stopped writing data |
14166 | 13754 | shutdown(SOCKET, 2); # I/we have stopped using this socket |
14167 | 13755 | |
14168 | 13756 | =begin original |
14169 | 13757 | |
14170 | 13758 | This is useful with sockets when you want to tell the other |
14171 | 13759 | side you're done writing but not done reading, or vice versa. |
14172 | 13760 | It's also a more insistent form of close because it also |
14173 | 13761 | disables the file descriptor in any forked copies in other |
14174 | 13762 | processes. |
14175 | 13763 | |
14176 | 13764 | =end original |
14177 | 13765 | |
14178 | 13766 | これは、こちらがソケットを書き終わったが読み終わっていない、 |
14179 | 13767 | またはその逆を相手側に伝えたいときに便利です。 |
14180 | 13768 | これはその他のプロセスでフォークしたファイル記述子のコピーも |
14181 | 13769 | 無効にするので、よりしつこい閉じ方です。 |
14182 | 13770 | |
14183 | 13771 | =begin original |
14184 | 13772 | |
14185 | 13773 | Returns C<1> for success; on error, returns C<undef> if |
14186 | 13774 | the first argument is not a valid filehandle, or returns C<0> and sets |
14187 | 13775 | C<$!> for any other failure. |
14188 | 13776 | |
14189 | 13777 | =end original |
14190 | 13778 | |
14191 | 13779 | 成功時には C<1> を返します; |
14192 | 13780 | エラーの場合、最初の引数が有効なファイルハンドルでない場合は C<undef> を |
14193 | 13781 | 返し、その他のエラーの場合は C<0> を返してC<$!> をセットします。 |
14194 | 13782 | |
14195 | 13783 | =item sin EXPR |
14196 | 13784 | X<sin> X<sine> X<asin> X<arcsine> |
14197 | 13785 | |
14198 | 13786 | =item sin |
14199 | 13787 | |
14200 | 13788 | =for Pod::Functions return the sine of a number |
14201 | 13789 | |
14202 | 13790 | =begin original |
14203 | 13791 | |
14204 | 13792 | Returns the sine of EXPR (expressed in radians). If EXPR is omitted, |
14205 | 13793 | returns sine of C<$_>. |
14206 | 13794 | |
14207 | 13795 | =end original |
14208 | 13796 | |
14209 | 13797 | (ラジアンで示した) EXPR の正弦を返します。 |
14210 | 13798 | EXPR が省略されたときには、C<$_> の正弦を返します。 |
14211 | 13799 | |
14212 | 13800 | =begin original |
14213 | 13801 | |
14214 | 13802 | For the inverse sine operation, you may use the C<Math::Trig::asin> |
14215 | 13803 | function, or use this relation: |
14216 | 13804 | |
14217 | 13805 | =end original |
14218 | 13806 | |
14219 | 13807 | 逆正弦を求めるためには、C<Math::Trig::asin> 関数を使うか、 |
14220 | 13808 | 以下の関係を使ってください: |
14221 | 13809 | |
14222 | 13810 | sub asin { atan2($_[0], sqrt(1 - $_[0] * $_[0])) } |
14223 | 13811 | |
14224 | 13812 | =item sleep EXPR |
14225 | 13813 | X<sleep> X<pause> |
14226 | 13814 | |
14227 | 13815 | =item sleep |
14228 | 13816 | |
14229 | 13817 | =for Pod::Functions block for some number of seconds |
14230 | 13818 | |
14231 | 13819 | =begin original |
14232 | 13820 | |
14233 | 13821 | Causes the script to sleep for (integer) EXPR seconds, or forever if no |
14234 | 13822 | argument is given. Returns the integer number of seconds actually slept. |
14235 | 13823 | |
14236 | 13824 | =end original |
14237 | 13825 | |
14238 | 13826 | スクリプトを(整数の) EXPR で指定した秒数 (省略時には、永久に) |
14239 | 13827 | スリープさせます。 |
14240 | 13828 | 実際にスリープした秒数を返します。 |
14241 | 13829 | |
14242 | 13830 | =begin original |
14243 | 13831 | |
14244 | 13832 | May be interrupted if the process receives a signal such as C<SIGALRM>. |
14245 | 13833 | |
14246 | 13834 | =end original |
14247 | 13835 | |
14248 | 13836 | そのプロセスが C<SIGALRM>のようなシグナルを受信すると、 |
14249 | 13837 | 割り込みがかかります。 |
14250 | 13838 | |
14251 | 13839 | eval { |
14252 | 13840 | local $SIG{ALARM} = sub { die "Alarm!\n" }; |
14253 | 13841 | sleep; |
14254 | 13842 | }; |
14255 | 13843 | die $@ unless $@ eq "Alarm!\n"; |
14256 | 13844 | |
14257 | 13845 | =begin original |
14258 | 13846 | |
14259 | 13847 | You probably cannot mix C<alarm> and C<sleep> calls, because C<sleep> |
14260 | 13848 | is often implemented using C<alarm>. |
14261 | 13849 | |
14262 | 13850 | =end original |
14263 | 13851 | |
14264 | 13852 | C<sleep> は、C<alarm> を使って実装されることが多いので、C<alarm> と |
14265 | 13853 | C<sleep> は、混ぜて使用することはおそらくできません。 |
14266 | 13854 | |
14267 | 13855 | =begin original |
14268 | 13856 | |
14269 | 13857 | On some older systems, it may sleep up to a full second less than what |
14270 | 13858 | you requested, depending on how it counts seconds. Most modern systems |
14271 | 13859 | always sleep the full amount. They may appear to sleep longer than that, |
14272 | 13860 | however, because your process might not be scheduled right away in a |
14273 | 13861 | busy multitasking system. |
14274 | 13862 | |
14275 | 13863 | =end original |
14276 | 13864 | |
14277 | 13865 | 古いシステムでは、どのように秒を数えるかによって、要求した秒数に完全に |
14278 | 13866 | 満たないうちに、スリープから抜ける場合があります。 |
14279 | 13867 | 最近のシステムでは、常に完全にスリープします。 |
14280 | 13868 | しかし、負荷の高いマルチタスクシステムでは |
14281 | 13869 | 正しくスケジューリングされないがために |
14282 | 13870 | より長い時間スリープすることがあります。 |
14283 | 13871 | |
14284 | 13872 | =begin original |
14285 | 13873 | |
14286 | 13874 | For delays of finer granularity than one second, the Time::HiRes module |
14287 | 13875 | (from CPAN, and starting from Perl 5.8 part of the standard |
14288 | 13876 | distribution) provides usleep(). You may also use Perl's four-argument |
14289 | 13877 | version of select() leaving the first three arguments undefined, or you |
14290 | 13878 | might be able to use the C<syscall> interface to access setitimer(2) if |
14291 | 13879 | your system supports it. See L<perlfaq8> for details. |
14292 | 13880 | |
14293 | 13881 | =end original |
14294 | 13882 | |
14295 | 1 秒より精度の高いスリープを行なうには、 | |
13883 | 1 秒より精度の高いスリープを行なうには、 | |
14296 | また Perl 5.8 からは | |
13884 | Time::HiRes モジュール(CPAN から、また Perl 5.8 からは | |
13885 | 標準配布されています) が usleep() を提供します。 | |
14297 | 13886 | Perl の 4 引数版 select() を最初の 3 引数を未定義にして使うか、 |
14298 | 13887 | setitimer(2) をサポートしているシステムでは、Perl の |
14299 | 13888 | C<syscall> インタフェースを使ってアクセスすることもできます。 |
14300 | 13889 | 詳しくは L<perlfaq8> を参照してください。 |
14301 | 13890 | |
14302 | 13891 | =begin original |
14303 | 13892 | |
14304 | 13893 | See also the POSIX module's C<pause> function. |
14305 | 13894 | |
14306 | 13895 | =end original |
14307 | 13896 | |
14308 | 13897 | POSIX モジュールの C<pause> 関数も参照してください。 |
14309 | 13898 | |
14310 | 13899 | =item socket SOCKET,DOMAIN,TYPE,PROTOCOL |
14311 | 13900 | X<socket> |
14312 | 13901 | |
14313 | 13902 | =for Pod::Functions create a socket |
14314 | 13903 | |
14315 | 13904 | =begin original |
14316 | 13905 | |
14317 | 13906 | Opens a socket of the specified kind and attaches it to filehandle |
14318 | 13907 | SOCKET. DOMAIN, TYPE, and PROTOCOL are specified the same as for |
14319 | 13908 | the syscall of the same name. You should C<use Socket> first |
14320 | 13909 | to get the proper definitions imported. See the examples in |
14321 | 13910 | L<perlipc/"Sockets: Client/Server Communication">. |
14322 | 13911 | |
14323 | 13912 | =end original |
14324 | 13913 | |
14325 | 指定した種類のソケットをオープンし、ファイルハンドル | |
13914 | 指定した種類のソケットをオープンし、ファイルハンドル | |
13915 | SOCKET にアタッチします。 | |
14326 | 13916 | DOMAIN, TYPE, PROTOCOL は、同名のシステムコールと同じように指定します。 |
14327 | 適切な定義を import するために、まず、C<use Socket> と | |
13917 | 適切な定義を import するために、まず、C<use Socket> と | |
13918 | するとよいでしょう。 | |
14328 | 13919 | L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。 |
14329 | 13920 | |
14330 | 13921 | =begin original |
14331 | 13922 | |
14332 | 13923 | On systems that support a close-on-exec flag on files, the flag will |
14333 | 13924 | be set for the newly opened file descriptor, as determined by the |
14334 | 13925 | value of $^F. See L<perlvar/$^F>. |
14335 | 13926 | |
14336 | 13927 | =end original |
14337 | 13928 | |
14338 | 13929 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
14339 | 13930 | フラグは $^F の値で決定される、新しくオープンされたファイル記述子に対して |
14340 | 13931 | セットされます。 |
14341 | 13932 | L<perlvar/$^F> を参照してください。 |
14342 | 13933 | |
14343 | 13934 | =item socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL |
14344 | 13935 | X<socketpair> |
14345 | 13936 | |
14346 | 13937 | =for Pod::Functions create a pair of sockets |
14347 | 13938 | |
14348 | 13939 | =begin original |
14349 | 13940 | |
14350 | 13941 | Creates an unnamed pair of sockets in the specified domain, of the |
14351 | 13942 | specified type. DOMAIN, TYPE, and PROTOCOL are specified the same as |
14352 | 13943 | for the syscall of the same name. If unimplemented, raises an exception. |
14353 | 13944 | Returns true if successful. |
14354 | 13945 | |
14355 | 13946 | =end original |
14356 | 13947 | |
14357 | 13948 | 指定した DOMAIN に、指定した TYPE で名前の無いソケットのペアを生成します。 |
14358 | 13949 | DOMAIN, TYPE, PROTOCOL は、同名のシステムコールと同じように指定します。 |
14359 | 13950 | 実装されていない場合には、例外が発生します。 |
14360 | 13951 | 成功時には真を返します。 |
14361 | 13952 | |
14362 | 13953 | =begin original |
14363 | 13954 | |
14364 | 13955 | On systems that support a close-on-exec flag on files, the flag will |
14365 | 13956 | be set for the newly opened file descriptors, as determined by the value |
14366 | 13957 | of $^F. See L<perlvar/$^F>. |
14367 | 13958 | |
14368 | 13959 | =end original |
14369 | 13960 | |
14370 | 13961 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
14371 | 13962 | フラグは $^F の値で決定される、新しくオープンされたファイル記述子に対して |
14372 | 13963 | セットされます。 |
14373 | 13964 | L<perlvar/$^F> を参照してください。 |
14374 | 13965 | |
14375 | 13966 | =begin original |
14376 | 13967 | |
14377 | 13968 | Some systems defined C<pipe> in terms of C<socketpair>, in which a call |
14378 | 13969 | to C<pipe(Rdr, Wtr)> is essentially: |
14379 | 13970 | |
14380 | 13971 | =end original |
14381 | 13972 | |
14382 | 13973 | C<pipe> を C<socketpair> を使って定義しているシステムもあります; |
14383 | 13974 | C<pipe(Rdr, Wtr)> は本質的には以下のようになります: |
14384 | 13975 | |
14385 | 13976 | use Socket; |
14386 | 13977 | socketpair(Rdr, Wtr, AF_UNIX, SOCK_STREAM, PF_UNSPEC); |
14387 | 13978 | shutdown(Rdr, 1); # no more writing for reader |
14388 | 13979 | shutdown(Wtr, 0); # no more reading for writer |
14389 | 13980 | |
14390 | 13981 | =begin original |
14391 | 13982 | |
14392 | 13983 | See L<perlipc> for an example of socketpair use. Perl 5.8 and later will |
14393 | 13984 | emulate socketpair using IP sockets to localhost if your system implements |
14394 | 13985 | sockets but not socketpair. |
14395 | 13986 | |
14396 | 13987 | =end original |
14397 | 13988 | |
14398 | 13989 | socketpair の使用例については L<perlipc> を参照してください。 |
14399 | 13990 | Perl 5.8 以降では、システムがソケットを実装しているが socketpair を |
14400 | 13991 | 実装していない場合、localhost に対して IP ソケットを使うことで |
14401 | 13992 | socketpair をエミュレートします。 |
14402 | 13993 | |
14403 | 13994 | =begin original |
14404 | 13995 | |
14405 | 13996 | Portability issues: L<perlport/socketpair>. |
14406 | 13997 | |
14407 | 13998 | =end original |
14408 | 13999 | |
14409 | 14000 | 移植性の問題: L<perlport/socketpair>。 |
14410 | 14001 | |
14411 | 14002 | =item sort SUBNAME LIST |
14412 | 14003 | X<sort> X<qsort> X<quicksort> X<mergesort> |
14413 | 14004 | |
14414 | 14005 | =item sort BLOCK LIST |
14415 | 14006 | |
14416 | 14007 | =item sort LIST |
14417 | 14008 | |
14418 | 14009 | =for Pod::Functions sort a list of values |
14419 | 14010 | |
14420 | 14011 | =begin original |
14421 | 14012 | |
14422 | 14013 | In list context, this sorts the LIST and returns the sorted list value. |
14423 | 14014 | In scalar context, the behaviour of C<sort()> is undefined. |
14424 | 14015 | |
14425 | 14016 | =end original |
14426 | 14017 | |
14427 | 14018 | リストコンテキストでは、LIST をソートし、ソートされたリスト値を返します。 |
14428 | 14019 | スカラコンテキストでは、C<sort()> の振る舞いは未定義です。 |
14429 | 14020 | |
14430 | 14021 | =begin original |
14431 | 14022 | |
14432 | 14023 | If SUBNAME or BLOCK is omitted, C<sort>s in standard string comparison |
14433 | 14024 | order. If SUBNAME is specified, it gives the name of a subroutine |
14434 | 14025 | that returns an integer less than, equal to, or greater than C<0>, |
14435 | 14026 | depending on how the elements of the list are to be ordered. (The |
14436 | 14027 | C<< <=> >> and C<cmp> operators are extremely useful in such routines.) |
14437 | 14028 | SUBNAME may be a scalar variable name (unsubscripted), in which case |
14438 | 14029 | the value provides the name of (or a reference to) the actual |
14439 | 14030 | subroutine to use. In place of a SUBNAME, you can provide a BLOCK as |
14440 | 14031 | an anonymous, in-line sort subroutine. |
14441 | 14032 | |
14442 | 14033 | =end original |
14443 | 14034 | |
14444 | SUBNAME や BLOCK を省略すると、標準の文字列比較の順番でソートが | |
14035 | SUBNAME や BLOCK を省略すると、標準の文字列比較の順番でソートが | |
14036 | 行なわれます。 | |
14445 | 14037 | SUBNAME を指定すると、それは、リストの要素をどのような順番に並べるかに |
14446 | 14038 | 応じて、負、ゼロ、正の整数を返すサブルーチンの名前であると解釈されます。 |
14447 | 14039 | (このようなルーチンには、C<< <=> >> 演算子や cmp 演算子が、 |
14448 | 14040 | たいへん便利です。) |
14449 | SUBNAME は、スカラ変数名(添字なし)でもよく、 | |
14041 | SUBNAME は、スカラ変数名(添字なし)でもよく、 | |
14450 | 実際のサブルーチンの | |
14042 | その場合には、その値が使用する実際のサブルーチンの | |
14451 | ||
14043 | 名前(またはそのリファレンス)と解釈されます。 | |
14452 | ||
14044 | SUBNAME の代わりに、無名のインライン | |
14045 | ソートルーチンとして、BLOCK を書くことができます。 | |
14453 | 14046 | |
14454 | 14047 | =begin original |
14455 | 14048 | |
14456 | 14049 | If the subroutine's prototype is C<($$)>, the elements to be compared are |
14457 | 14050 | passed by reference in C<@_>, as for a normal subroutine. This is slower |
14458 | 14051 | than unprototyped subroutines, where the elements to be compared are passed |
14459 | 14052 | into the subroutine as the package global variables $a and $b (see example |
14460 | 14053 | below). Note that in the latter case, it is usually highly counter-productive |
14461 | 14054 | to declare $a and $b as lexicals. |
14462 | 14055 | |
14463 | 14056 | =end original |
14464 | 14057 | |
14465 | 14058 | サブルーチンのプロトタイプが C<($$)>の場合、比較する要素は通常の |
14466 | 14059 | サブルーチンと同じように C<@_> の中にリファレンスとして渡されます。 |
14467 | 14060 | これはプロトタイプなしのサブルーチンより遅いです; この場合は比較のため |
14468 | 14061 | サブルーチンに渡される二つの要素は、パッケージのグローバル変数 $a と $b で |
14469 | 14062 | 渡されます(次の例を参照してください)。 |
14470 | 14063 | 後者の場合、レキシカルに $a と $b を宣言するのは普通とても逆効果になります。 |
14471 | 14064 | |
14472 | 14065 | =begin original |
14473 | 14066 | |
14474 | 14067 | If the subroutine is an XSUB, the elements to be compared are pushed on to |
14475 | 14068 | the stack, the way arguments are usually passed to XSUBs. $a and $b are |
14476 | 14069 | not set. |
14477 | 14070 | |
14478 | 14071 | =end original |
14479 | 14072 | |
14480 | 14073 | サブルーチンが XSUB の場合、比較される要素は、普通に引数を XSUB に渡す形で、 |
14481 | 14074 | スタックにプッシュされます。 |
14482 | 14075 | $a と $b は設定されません。 |
14483 | 14076 | |
14484 | 14077 | =begin original |
14485 | 14078 | |
14486 | 14079 | The values to be compared are always passed by reference and should not |
14487 | 14080 | be modified. |
14488 | 14081 | |
14489 | 14082 | =end original |
14490 | 14083 | |
14491 | 14084 | $a や $b はリファレンスによって渡されるので、変更するべきではありません。 |
14492 | 14085 | |
14493 | 14086 | =begin original |
14494 | 14087 | |
14495 | 14088 | You also cannot exit out of the sort block or subroutine using any of the |
14496 | 14089 | loop control operators described in L<perlsyn> or with C<goto>. |
14497 | 14090 | |
14498 | 14091 | =end original |
14499 | 14092 | |
14500 | 14093 | また、ソートブロックやサブルーチンから L<perlsyn> で説明されている |
14501 | 14094 | ループ制御子や C<goto> を使って抜けてはいけません。 |
14502 | 14095 | |
14503 | 14096 | =begin original |
14504 | 14097 | |
14505 | 14098 | When C<use locale> (but not C<use locale 'not_characters'>) is in |
14506 | 14099 | effect, C<sort LIST> sorts LIST according to the |
14507 | 14100 | current collation locale. See L<perllocale>. |
14508 | 14101 | |
14509 | 14102 | =end original |
14510 | 14103 | |
14511 | 14104 | C<use locale> が有効(そして C<use locale 'not_characters'> が有効でない)の |
14512 | 14105 | 場合、C<sort LIST> は LIST を現在の比較ロケールに従ってソートします。 |
14513 | 14106 | L<perllocale> を参照してください。 |
14514 | 14107 | |
14515 | 14108 | =begin original |
14516 | 14109 | |
14517 | 14110 | sort() returns aliases into the original list, much as a for loop's index |
14518 | 14111 | variable aliases the list elements. That is, modifying an element of a |
14519 | 14112 | list returned by sort() (for example, in a C<foreach>, C<map> or C<grep>) |
14520 | 14113 | actually modifies the element in the original list. This is usually |
14521 | 14114 | something to be avoided when writing clear code. |
14522 | 14115 | |
14523 | 14116 | =end original |
14524 | 14117 | |
14525 | 14118 | sort() は元のリストへのエイリアスを返します; for ループのインデックス変数が |
14526 | 14119 | リスト要素へのエイリアスと同様です。 |
14527 | 14120 | つまり、sort() で返されるリストの要素を(例えば、C<foreach> や C<map> や |
14528 | 14121 | C<grep> で)変更すると、実際に元のリストの要素が変更されます。 |
14529 | 14122 | これはきれいなコードを書くときには普通は回避されます。 |
14530 | 14123 | |
14531 | 14124 | =begin original |
14532 | 14125 | |
14533 | 14126 | Perl 5.6 and earlier used a quicksort algorithm to implement sort. |
14534 | 14127 | That algorithm was not stable, so I<could> go quadratic. (A I<stable> sort |
14535 | 14128 | preserves the input order of elements that compare equal. Although |
14536 | 14129 | quicksort's run time is O(NlogN) when averaged over all arrays of |
14537 | 14130 | length N, the time can be O(N**2), I<quadratic> behavior, for some |
14538 | 14131 | inputs.) In 5.7, the quicksort implementation was replaced with |
14539 | 14132 | a stable mergesort algorithm whose worst-case behavior is O(NlogN). |
14540 | 14133 | But benchmarks indicated that for some inputs, on some platforms, |
14541 | 14134 | the original quicksort was faster. 5.8 has a sort pragma for |
14542 | 14135 | limited control of the sort. Its rather blunt control of the |
14543 | 14136 | underlying algorithm may not persist into future Perls, but the |
14544 | 14137 | ability to characterize the input or output in implementation |
14545 | 14138 | independent ways quite probably will. See L<the sort pragma|sort>. |
14546 | 14139 | |
14547 | 14140 | =end original |
14548 | 14141 | |
14549 | 14142 | Perl 5.6 以前ではソートの実装にクイックソートアルゴリズムを使っていました。 |
14550 | このアルゴリズムは安定していないので、2 乗の時間が掛かる | |
14143 | このアルゴリズムは安定していないので、2 乗の時間が掛かる | |
14144 | I<可能性があります>。 | |
14551 | 14145 | (I<安定した> ソートは、比較した時に同じ要素の入力順が保存されます。 |
14552 | クイックソートの実行時間は、長さ N の全ての配列の平均では | |
14146 | クイックソートの実行時間は、長さ N の全ての配列の平均では | |
14553 | 入力によっては O(N**2) という I<2 乗の> 振る舞いを | |
14147 | O(NlogN) ですが、入力によっては O(N**2) という I<2 乗の> 振る舞いを | |
14554 | ||
14148 | することがあります。) | |
14555 | ||
14149 | 5.7 では、クイックソートによる実装は、最悪の場合の振る舞いも | |
14556 | ||
14150 | O(NlogN) である、安定したマージソートアルゴリズムに置き換えられました。 | |
14557 | ||
14151 | しかし、入力とプラットフォームによっては、ベンチマークはクイックソートの | |
14152 | 方が速くなります。 | |
14558 | 14153 | 5.8 ではソートを限定的に制御できる sort プラグマがあります。 |
14559 | 14154 | この、アルゴリズムの直接的な制御方法は将来の perl では引き継がれないかも |
14560 | 14155 | しれませんが、実装に依存しない形で入力や出力を性格付ける機能は |
14561 | 14156 | おそらくあります。 |
14562 | 14157 | L<the sort pragma|sort> を参照してください。 |
14563 | 14158 | |
14564 | 14159 | =begin original |
14565 | 14160 | |
14566 | 14161 | Examples: |
14567 | 14162 | |
14568 | 14163 | =end original |
14569 | 14164 | |
14570 | 14165 | 例: |
14571 | 14166 | |
14572 | 14167 | # sort lexically |
14573 | 14168 | @articles = sort @files; |
14169 | ||
14575 | 14170 | # same thing, but with explicit sort routine |
14576 | 14171 | @articles = sort {$a cmp $b} @files; |
14172 | ||
14578 | 14173 | # now case-insensitively |
14579 | 14174 | @articles = sort {fc($a) cmp fc($b)} @files; |
14175 | ||
14581 | 14176 | # same thing in reversed order |
14582 | 14177 | @articles = sort {$b cmp $a} @files; |
14178 | ||
14584 | 14179 | # sort numerically ascending |
14585 | 14180 | @articles = sort {$a <=> $b} @files; |
14181 | ||
14587 | 14182 | # sort numerically descending |
14588 | 14183 | @articles = sort {$b <=> $a} @files; |
14184 | ||
14590 | 14185 | # this sorts the %age hash by value instead of key |
14591 | 14186 | # using an in-line function |
14592 | 14187 | @eldest = sort { $age{$b} <=> $age{$a} } keys %age; |
14188 | ||
14594 | 14189 | # sort using explicit subroutine name |
14595 | 14190 | sub byage { |
14596 | 14191 | $age{$a} <=> $age{$b}; # presuming numeric |
14597 | 14192 | } |
14598 | 14193 | @sortedclass = sort byage @class; |
14194 | ||
14600 | 14195 | sub backwards { $b cmp $a } |
14601 | 14196 | @harry = qw(dog cat x Cain Abel); |
14602 | 14197 | @george = qw(gone chased yz Punished Axed); |
14603 | 14198 | print sort @harry; |
14604 | 14199 | # prints AbelCaincatdogx |
14605 | 14200 | print sort backwards @harry; |
14606 | 14201 | # prints xdogcatCainAbel |
14607 | 14202 | print sort @george, 'to', @harry; |
14608 | 14203 | # prints AbelAxedCainPunishedcatchaseddoggonetoxyz |
14609 | 14204 | |
14610 | 14205 | # inefficiently sort by descending numeric compare using |
14611 | 14206 | # the first integer after the first = sign, or the |
14612 | 14207 | # whole record case-insensitively otherwise |
14613 | 14208 | |
14614 | 14209 | my @new = sort { |
14615 | 14210 | ($b =~ /=(\d+)/)[0] <=> ($a =~ /=(\d+)/)[0] |
14616 | 14211 | || |
14617 | 14212 | fc($a) cmp fc($b) |
14618 | 14213 | } @old; |
14619 | 14214 | |
14620 | 14215 | # same thing, but much more efficiently; |
14621 | 14216 | # we'll build auxiliary indices instead |
14622 | 14217 | # for speed |
14623 | 14218 | my @nums = @caps = (); |
14624 | 14219 | for (@old) { |
14625 | 14220 | push @nums, ( /=(\d+)/ ? $1 : undef ); |
14626 | 14221 | push @caps, fc($_); |
14627 | 14222 | } |
14628 | 14223 | |
14629 | 14224 | my @new = @old[ sort { |
14630 | 14225 | $nums[$b] <=> $nums[$a] |
14631 | 14226 | || |
14632 | 14227 | $caps[$a] cmp $caps[$b] |
14633 | 14228 | } 0..$#old |
14634 | 14229 | ]; |
14635 | 14230 | |
14636 | 14231 | # same thing, but without any temps |
14637 | 14232 | @new = map { $_->[0] } |
14638 | 14233 | sort { $b->[1] <=> $a->[1] |
14639 | 14234 | || |
14640 | 14235 | $a->[2] cmp $b->[2] |
14641 | 14236 | } map { [$_, /=(\d+)/, fc($_)] } @old; |
14642 | 14237 | |
14643 | 14238 | # using a prototype allows you to use any comparison subroutine |
14644 | 14239 | # as a sort subroutine (including other package's subroutines) |
14645 | 14240 | package other; |
14646 | sub backwards ($$) { $_[1] cmp $_[0]; } # $a and $b are | |
14241 | sub backwards ($$) { $_[1] cmp $_[0]; } # $a and $b are not set here | |
14647 | | |
14242 | ||
14648 | 14243 | package main; |
14649 | 14244 | @new = sort other::backwards @old; |
14245 | ||
14651 | 14246 | # guarantee stability, regardless of algorithm |
14652 | 14247 | use sort 'stable'; |
14653 | 14248 | @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old; |
14249 | ||
14655 | 14250 | # force use of mergesort (not portable outside Perl 5.8) |
14656 | 14251 | use sort '_mergesort'; # note discouraging _ |
14657 | 14252 | @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old; |
14658 | 14253 | |
14659 | 14254 | =begin original |
14660 | 14255 | |
14661 | 14256 | Warning: syntactical care is required when sorting the list returned from |
14662 | 14257 | a function. If you want to sort the list returned by the function call |
14663 | 14258 | C<find_records(@key)>, you can use: |
14664 | 14259 | |
14665 | 14260 | =end original |
14666 | 14261 | |
14667 | 14262 | 警告: 関数からかえされたリストをソートするときには文法上の注意が必要です。 |
14668 | 14263 | 関数呼び出し C<find_records(@key)> から返されたリストをソートしたい場合、 |
14669 | 14264 | 以下のように出来ます: |
14670 | 14265 | |
14671 | 14266 | @contact = sort { $a cmp $b } find_records @key; |
14672 | 14267 | @contact = sort +find_records(@key); |
14673 | 14268 | @contact = sort &find_records(@key); |
14674 | 14269 | @contact = sort(find_records(@key)); |
14675 | 14270 | |
14676 | 14271 | =begin original |
14677 | 14272 | |
14678 | 14273 | If instead you want to sort the array @key with the comparison routine |
14679 | 14274 | C<find_records()> then you can use: |
14680 | 14275 | |
14681 | 14276 | =end original |
14682 | 14277 | |
14683 | 14278 | 一方、配列 @key を比較ルーチン C<find_records()> でソートしたい場合は、 |
14684 | 14279 | 以下のように出来ます: |
14685 | 14280 | |
14686 | 14281 | @contact = sort { find_records() } @key; |
14687 | 14282 | @contact = sort find_records(@key); |
14688 | 14283 | @contact = sort(find_records @key); |
14689 | 14284 | @contact = sort(find_records (@key)); |
14690 | 14285 | |
14691 | 14286 | =begin original |
14692 | 14287 | |
14693 | 14288 | If you're using strict, you I<must not> declare $a |
14694 | 14289 | and $b as lexicals. They are package globals. That means |
14695 | 14290 | that if you're in the C<main> package and type |
14696 | 14291 | |
14697 | 14292 | =end original |
14698 | 14293 | |
14699 | use strict している場合、$a と $b をレキシカルとして | |
14294 | use strict している場合、$a と $b をレキシカルとして | |
14295 | 宣言しては I<いけません>。 | |
14700 | 14296 | これはパッケージグローバルです。 |
14701 | 14297 | つまり、C<main> パッケージで以下のように書いた場合: |
14702 | 14298 | |
14703 | 14299 | @articles = sort {$b <=> $a} @files; |
14704 | 14300 | |
14705 | 14301 | =begin original |
14706 | 14302 | |
14707 | 14303 | then C<$a> and C<$b> are C<$main::a> and C<$main::b> (or C<$::a> and C<$::b>), |
14708 | 14304 | but if you're in the C<FooPack> package, it's the same as typing |
14709 | 14305 | |
14710 | 14306 | =end original |
14711 | 14307 | |
14712 | 14308 | C<$a> と C<$b> は C<$main::a> と C<$main::b> (または C<$::a> と C<$::b>) を |
14713 | 14309 | 意味しますが、C<FooPack> パッケージ内の場合、これは以下と同じになります: |
14714 | 14310 | |
14715 | 14311 | @articles = sort {$FooPack::b <=> $FooPack::a} @files; |
14716 | 14312 | |
14717 | 14313 | =begin original |
14718 | 14314 | |
14719 | 14315 | The comparison function is required to behave. If it returns |
14720 | 14316 | inconsistent results (sometimes saying C<$x[1]> is less than C<$x[2]> and |
14721 | 14317 | sometimes saying the opposite, for example) the results are not |
14722 | 14318 | well-defined. |
14723 | 14319 | |
14724 | 14320 | =end original |
14725 | 14321 | |
14726 | 14322 | 比較関数は一貫した振る舞いをすることが求められます。 |
14727 | 14323 | 一貫しない結果を返す(例えば、あるときは C<$x[1]> が C<$x[2]> より |
14728 | 14324 | 小さいと返し、またあるときは逆を返す)場合、結果は未定義です。 |
14729 | 14325 | |
14730 | 14326 | =begin original |
14731 | 14327 | |
14732 | 14328 | Because C<< <=> >> returns C<undef> when either operand is C<NaN> |
14733 | 14329 | (not-a-number), be careful when sorting with a |
14734 | 14330 | comparison function like C<< $a <=> $b >> any lists that might contain a |
14735 | 14331 | C<NaN>. The following example takes advantage that C<NaN != NaN> to |
14736 | 14332 | eliminate any C<NaN>s from the input list. |
14737 | 14333 | |
14738 | 14334 | =end original |
14739 | 14335 | |
14740 | C<< <=> >> はどちらかのオペランドが C<NaN> (not-a-number) のときに | |
14336 | C<< <=> >> はどちらかのオペランドが C<NaN> (not-a-number) のときに | |
14741 | ||
14337 | C<undef> を返すので、 | |
14742 | C<NaN> が | |
14338 | C<< $a <=> $b >> といった比較関数でソートする場合はリストに C<NaN> が | |
14339 | 含まれないように注意してください。 | |
14743 | 14340 | 以下の例は 入力リストから C<NaN> を取り除くために C<NaN != NaN> という性質を |
14744 | 14341 | 利用しています。 |
14745 | 14342 | |
14746 | 14343 | @result = sort { $a <=> $b } grep { $_ == $_ } @input; |
14747 | 14344 | |
14748 | 14345 | =item splice ARRAY or EXPR,OFFSET,LENGTH,LIST |
14749 | 14346 | X<splice> |
14750 | 14347 | |
14751 | 14348 | =item splice ARRAY or EXPR,OFFSET,LENGTH |
14752 | 14349 | |
14753 | 14350 | =item splice ARRAY or EXPR,OFFSET |
14754 | 14351 | |
14755 | 14352 | =item splice ARRAY or EXPR |
14756 | 14353 | |
14757 | 14354 | =for Pod::Functions add or remove elements anywhere in an array |
14758 | 14355 | |
14759 | 14356 | =begin original |
14760 | 14357 | |
14761 | 14358 | Removes the elements designated by OFFSET and LENGTH from an array, and |
14762 | 14359 | replaces them with the elements of LIST, if any. In list context, |
14763 | 14360 | returns the elements removed from the array. In scalar context, |
14764 | 14361 | returns the last element removed, or C<undef> if no elements are |
14765 | 14362 | removed. The array grows or shrinks as necessary. |
14766 | 14363 | If OFFSET is negative then it starts that far from the end of the array. |
14767 | 14364 | If LENGTH is omitted, removes everything from OFFSET onward. |
14768 | 14365 | If LENGTH is negative, removes the elements from OFFSET onward |
14769 | 14366 | except for -LENGTH elements at the end of the array. |
14770 | 14367 | If both OFFSET and LENGTH are omitted, removes everything. If OFFSET is |
14771 | past the end of the array | |
14368 | past the end of the array, Perl issues a warning, and splices at the | |
14772 | ||
14369 | end of the array. | |
14773 | 14370 | |
14774 | 14371 | =end original |
14775 | 14372 | |
14776 | 14373 | ARRAY から OFFSET、LENGTH で指定される要素を取り除き、 |
14777 | 14374 | LIST があれば、それを代わりに挿入します。 |
14778 | 14375 | リストコンテキストでは、配列から取り除かれた要素を返します。 |
14779 | 14376 | スカラコンテキストでは、取り除かれた最後の要素を返します; 要素が |
14780 | 14377 | 取り除かれなかった場合は C<undef> を返します。 |
14781 | 14378 | 配列は、必要に応じて、大きくなったり、小さくなったりします。 |
14782 | 14379 | OFFSET が負の数の場合は、配列の最後からの距離を示します。 |
14783 | 14380 | LENGTH が省略されると、OFFSET 以降のすべての要素を取り除きます。 |
14784 | 14381 | LENGTH が負の数の場合は、OFFSET から前方へ、配列の最後から -LENGTH 要素を |
14785 | 14382 | 除いて取り除きます。 |
14786 | 14383 | OFFSET と LENGTH の両方が省略されると、全ての要素を取り除きます。 |
14787 | OFFSET が配列の最後より後ろ | |
14384 | OFFSET が配列の最後より後ろの場合、Perl は警告を出し、配列の最後に対して | |
14788 | ||
14385 | 処理します。 | |
14789 | 14386 | |
14790 | 14387 | =begin original |
14791 | 14388 | |
14792 | 14389 | The following equivalences hold (assuming C<< $#a >= $i >> ) |
14793 | 14390 | |
14794 | 14391 | =end original |
14795 | 14392 | |
14796 | 14393 | 以下は、(C<< $#a >= $i >> と仮定すると) それぞれ、等価です。 |
14797 | 14394 | |
14798 | 14395 | push(@a,$x,$y) splice(@a,@a,0,$x,$y) |
14799 | 14396 | pop(@a) splice(@a,-1) |
14800 | 14397 | shift(@a) splice(@a,0,1) |
14801 | 14398 | unshift(@a,$x,$y) splice(@a,0,0,$x,$y) |
14802 | 14399 | $a[$i] = $y splice(@a,$i,1,$y) |
14803 | 14400 | |
14804 | 14401 | =begin original |
14805 | 14402 | |
14806 | ||
14403 | Example, assuming array lengths are passed before arrays: | |
14807 | 14404 | |
14808 | 14405 | =end original |
14809 | 14406 | |
14810 | ||
14407 | 次の例では、配列の前に、それぞれの配列の大きさが渡されるものとしています: | |
14811 | 14408 | |
14812 | sub | |
14409 | sub aeq { # compare two list values | |
14813 | my | |
14410 | my(@a) = splice(@_,0,shift); | |
14814 | | |
14411 | my(@b) = splice(@_,0,shift); | |
14815 | sa | |
14412 | return 0 unless @a == @b; # same len? | |
14816 | | |
14413 | while (@a) { | |
14414 | return 0 if pop(@a) ne pop(@b); | |
14415 | } | |
14416 | return 1; | |
14817 | 14417 | } |
14418 | if (&aeq($len,@foo[1..$len],0+@bar,@bar)) { ... } | |
14818 | 14419 | |
14819 | nary_print(3, qw(a b c d e f g h)); | |
14820 | # prints: | |
14821 | # a -- b -- c | |
14822 | # d -- e -- f | |
14823 | # g -- h | |
14824 | ||
14825 | 14420 | =begin original |
14826 | 14421 | |
14827 | 14422 | Starting with Perl 5.14, C<splice> can take scalar EXPR, which must hold a |
14828 | 14423 | reference to an unblessed array. The argument will be dereferenced |
14829 | 14424 | automatically. This aspect of C<splice> is considered highly experimental. |
14830 | 14425 | The exact behaviour may change in a future version of Perl. |
14831 | 14426 | |
14832 | 14427 | =end original |
14833 | 14428 | |
14834 | 14429 | Perl 5.14 から、C<splice> はスカラの EXPR を取ることができるようになりました; |
14835 | 14430 | これは bless されていない配列へのリファレンスでなければなりません。 |
14836 | 14431 | 引数は自動的にデリファレンスされます。 |
14837 | 14432 | C<splice> のこの動作は高度に実験的であると考えられています。 |
14838 | 14433 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 |
14839 | 14434 | |
14840 | 14435 | =begin original |
14841 | 14436 | |
14842 | 14437 | To avoid confusing would-be users of your code who are running earlier |
14843 | 14438 | versions of Perl with mysterious syntax errors, put this sort of thing at |
14844 | 14439 | the top of your file to signal that your code will work I<only> on Perls of |
14845 | 14440 | a recent vintage: |
14846 | 14441 | |
14847 | 14442 | =end original |
14848 | 14443 | |
14849 | 14444 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な |
14850 | 14445 | 文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で |
14851 | 14446 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを |
14852 | 14447 | 書いてください: |
14853 | 14448 | |
14854 | 14449 | use 5.014; # so push/pop/etc work on scalars (experimental) |
14855 | 14450 | |
14856 | 14451 | =item split /PATTERN/,EXPR,LIMIT |
14857 | 14452 | X<split> |
14858 | 14453 | |
14859 | 14454 | =item split /PATTERN/,EXPR |
14860 | 14455 | |
14861 | 14456 | =item split /PATTERN/ |
14862 | 14457 | |
14863 | 14458 | =item split |
14864 | 14459 | |
14865 | 14460 | =for Pod::Functions split up a string using a regexp delimiter |
14866 | 14461 | |
14867 | 14462 | =begin original |
14868 | 14463 | |
14869 | 14464 | Splits the string EXPR into a list of strings and returns the |
14870 | 14465 | list in list context, or the size of the list in scalar context. |
14871 | 14466 | |
14872 | 14467 | =end original |
14873 | 14468 | |
14874 | 14469 | 文字列 EXPR を文字列のリストに分割して、リストコンテキストではそのリストを |
14875 | 14470 | 返し、スカラコンテキストではリストの大きさを返します。 |
14876 | 14471 | |
14877 | 14472 | =begin original |
14878 | 14473 | |
14879 | 14474 | If only PATTERN is given, EXPR defaults to C<$_>. |
14880 | 14475 | |
14881 | 14476 | =end original |
14882 | 14477 | |
14883 | 14478 | PATTERN のみが与えられた場合、EXPR のデフォルトは C<$_> です。 |
14884 | 14479 | |
14885 | 14480 | =begin original |
14886 | 14481 | |
14887 | 14482 | Anything in EXPR that matches PATTERN is taken to be a separator |
14888 | 14483 | that separates the EXPR into substrings (called "I<fields>") that |
14889 | 14484 | do B<not> include the separator. Note that a separator may be |
14890 | 14485 | longer than one character or even have no characters at all (the |
14891 | 14486 | empty string, which is a zero-width match). |
14892 | 14487 | |
14893 | 14488 | =end original |
14894 | 14489 | |
14895 | 14490 | EXPR の中で PATTERN にマッチングするものは何でも EXPR を("I<fields>" と |
14896 | 14491 | 呼ばれる)セパレータを B<含まない> 部分文字列に分割するための |
14897 | 14492 | セパレータとなります。 |
14898 | 14493 | セパレータは一文字より長くてもよく、全く文字がなくてもよい(空文字列は |
14899 | 14494 | ゼロ幅マッチングです)ということに注意してください。 |
14900 | 14495 | |
14901 | 14496 | =begin original |
14902 | 14497 | |
14903 | 14498 | The PATTERN need not be constant; an expression may be used |
14904 | 14499 | to specify a pattern that varies at runtime. |
14905 | 14500 | |
14906 | 14501 | =end original |
14907 | 14502 | |
14908 | 14503 | PATTERN は定数である必要はありません; 実行時に変更されるパターンを |
14909 | 14504 | 指定するために式を使えます。 |
14910 | 14505 | |
14911 | 14506 | =begin original |
14912 | 14507 | |
14913 | 14508 | If PATTERN matches the empty string, the EXPR is split at the match |
14914 | 14509 | position (between characters). As an example, the following: |
14915 | 14510 | |
14916 | 14511 | =end original |
14917 | 14512 | |
14918 | 14513 | PATTERN が空文字列にマッチングする場合、EXPR はマッチング位置 |
14919 | 14514 | (文字の間)で分割されます。 |
14920 | 14515 | 例えば、以下のものは: |
14921 | 14516 | |
14922 | 14517 | print join(':', split('b', 'abc')), "\n"; |
14923 | 14518 | |
14924 | 14519 | =begin original |
14925 | 14520 | |
14926 | 14521 | uses the 'b' in 'abc' as a separator to produce the output 'a:c'. |
14927 | 14522 | However, this: |
14928 | 14523 | |
14929 | 14524 | =end original |
14930 | 14525 | |
14931 | 14526 | 'abc' の 'b' をセパレータとして使って出力 'a:c' を生成します。 |
14932 | 14527 | しかし、これは: |
14933 | 14528 | |
14934 | 14529 | print join(':', split('', 'abc')), "\n"; |
14935 | 14530 | |
14936 | 14531 | =begin original |
14937 | 14532 | |
14938 | 14533 | uses empty string matches as separators to produce the output |
14939 | 14534 | 'a:b:c'; thus, the empty string may be used to split EXPR into a |
14940 | 14535 | list of its component characters. |
14941 | 14536 | |
14942 | 14537 | =end original |
14943 | 14538 | |
14944 | 14539 | 空文字列マッチングをセパレータとして使って出力 'a:b:c' を生成します; 従って、 |
14945 | 14540 | 空文字列は EXPR を構成する文字のリストに分割するために使われます。 |
14946 | 14541 | |
14947 | 14542 | =begin original |
14948 | 14543 | |
14949 | 14544 | As a special case for C<split>, the empty pattern given in |
14950 | 14545 | L<match operator|perlop/"m/PATTERN/msixpodualgc"> syntax (C<//>) specifically matches the empty string, which is contrary to its usual |
14951 | 14546 | interpretation as the last successful match. |
14952 | 14547 | |
14953 | 14548 | =end original |
14954 | 14549 | |
14955 | 14550 | C<split> の特殊な場合として、 |
14956 | 14551 | L<マッチング演算子|perlop/"m/PATTERN/msixpodualgc"> 文法で与えられた |
14957 | 14552 | 空パターン (C<//>) は特に空文字列にマッチングし、最後に成功した |
14958 | 14553 | マッチングという普通の解釈と異なります。 |
14959 | 14554 | |
14960 | 14555 | =begin original |
14961 | 14556 | |
14962 | 14557 | If PATTERN is C</^/>, then it is treated as if it used the |
14963 | 14558 | L<multiline modifier|perlreref/OPERATORS> (C</^/m>), since it |
14964 | 14559 | isn't much use otherwise. |
14965 | 14560 | |
14966 | 14561 | =end original |
14967 | 14562 | |
14968 | 14563 | PATTERN が C</^/> の場合、L<複数行修飾子|perlreref/OPERATORS> |
14969 | 14564 | (C</^/m>) が使われたかのように扱われます; そうでなければほとんど |
14970 | 14565 | 使えないからです。 |
14971 | 14566 | |
14972 | 14567 | =begin original |
14973 | 14568 | |
14974 | 14569 | As another special case, C<split> emulates the default behavior of the |
14975 | 14570 | command line tool B<awk> when the PATTERN is either omitted or a I<literal |
14976 | 14571 | string> composed of a single space character (such as S<C<' '>> or |
14977 | 14572 | S<C<"\x20">>, but not e.g. S<C</ />>). In this case, any leading |
14978 | 14573 | whitespace in EXPR is removed before splitting occurs, and the PATTERN is |
14979 | 14574 | instead treated as if it were C</\s+/>; in particular, this means that |
14980 | 14575 | I<any> contiguous whitespace (not just a single space character) is used as |
14981 | 14576 | a separator. However, this special treatment can be avoided by specifying |
14982 | 14577 | the pattern S<C</ />> instead of the string S<C<" ">>, thereby allowing |
14983 | only a single space character to be a separator. | |
14578 | only a single space character to be a separator. | |
14984 | special case was restricted to the use of a plain S<C<" ">> as the | |
14985 | pattern argument to split, in Perl 5.18.0 and later this special case is | |
14986 | triggered by any expression which evaluates as the simple string S<C<" ">>. | |
14987 | 14579 | |
14988 | 14580 | =end original |
14989 | 14581 | |
14990 | 14582 | もう一つの特別な場合として、C<split> は PATTERN が省略されるか |
14991 | 14583 | 単一のスペース文字からなる I<リテラル文字列> (つまり例えば |
14992 | 14584 | S<C</ />> ではなく S<C<' '>> や S<C<"\x20">>) の場合、コマンドラインツール |
14993 | 14585 | B<awk> のデフォルトの振る舞いをエミュレートします。 |
14994 | 14586 | この場合、EXPR の先頭の空白は分割を行う前に削除され、PATTERN は |
14995 | 14587 | C</\s+/> であったかのように扱われます; 特に、これは (単に単一の |
14996 | 14588 | スペース文字ではなく) I<あらゆる> 連続した空白がセパレータとして |
14997 | 14589 | 使われるということです。 |
14998 | 14590 | しかし、この特別の扱いは文字列 S<C<" ">> の代わりにパターン S<C</ />> を |
14999 | 指定することで回避でき、それによってセパレータとして単一の | |
14591 | 指定することで回避でき、それによってセパレータとして単一のの | |
15000 | 14592 | スペース文字のみが使われます。 |
15001 | 以前の Perl ではこの特別な場合は split のパターン引数として単に S<C<" ">> を | |
15002 | 使った場合に制限されていましたが、Perl 5.18.0 以降では、この特別な場合は | |
15003 | 単純な文字列 S<C<" ">> に評価される任意の式によって引き起こされます。 | |
15004 | 14593 | |
15005 | 14594 | =begin original |
15006 | 14595 | |
15007 | 14596 | If omitted, PATTERN defaults to a single space, S<C<" ">>, triggering |
15008 | 14597 | the previously described I<awk> emulation. |
15009 | 14598 | |
15010 | 14599 | =end original |
15011 | 14600 | |
15012 | 14601 | 省略されると、PATTERN のデフォルトは単一のスペース S<C<" ">> になり、 |
15013 | 14602 | 先に記述した I<awk> エミュレーションを起動します。 |
15014 | 14603 | |
15015 | 14604 | =begin original |
15016 | 14605 | |
15017 | 14606 | If LIMIT is specified and positive, it represents the maximum number |
15018 | 14607 | of fields into which the EXPR may be split; in other words, LIMIT is |
15019 | 14608 | one greater than the maximum number of times EXPR may be split. Thus, |
15020 | 14609 | the LIMIT value C<1> means that EXPR may be split a maximum of zero |
15021 | 14610 | times, producing a maximum of one field (namely, the entire value of |
15022 | 14611 | EXPR). For instance: |
15023 | 14612 | |
15024 | 14613 | =end original |
15025 | 14614 | |
15026 | 14615 | LIMIT が指定された正数の場合、EXPR が分割されるフィールドの最大数を |
15027 | 表現します; 言い換えると、 LIMIT は EXPR が分割される数より一つ大きい | |
14616 | 表現します; 言い換えると、 LIMIT は EXPR が分割される数より一つ大きい | |
14617 | 数です。 | |
15028 | 14618 | 従って、LIMIT の値 C<1> は EXPR が最大 0 回分割されるということで、 |
15029 | 14619 | 最大で一つのフィールドを生成します (言い換えると、EXPR 全体の値です)。 |
15030 | 14620 | 例えば: |
15031 | 14621 | |
15032 | 14622 | print join(':', split(//, 'abc', 1)), "\n"; |
15033 | 14623 | |
15034 | 14624 | =begin original |
15035 | 14625 | |
15036 | 14626 | produces the output 'abc', and this: |
15037 | 14627 | |
15038 | 14628 | =end original |
15039 | 14629 | |
15040 | 14630 | これは 'abc' を出力し、次のものは: |
15041 | 14631 | |
15042 | 14632 | print join(':', split(//, 'abc', 2)), "\n"; |
15043 | 14633 | |
15044 | 14634 | =begin original |
15045 | 14635 | |
15046 | 14636 | produces the output 'a:bc', and each of these: |
15047 | 14637 | |
15048 | 14638 | =end original |
15049 | 14639 | |
15050 | 14640 | 'a:bc' を出力し、以下のものそれぞれは: |
15051 | 14641 | |
15052 | 14642 | print join(':', split(//, 'abc', 3)), "\n"; |
15053 | 14643 | print join(':', split(//, 'abc', 4)), "\n"; |
15054 | 14644 | |
15055 | 14645 | =begin original |
15056 | 14646 | |
15057 | 14647 | produces the output 'a:b:c'. |
15058 | 14648 | |
15059 | 14649 | =end original |
15060 | 14650 | |
15061 | 14651 | 'a:b:c' を出力します。 |
15062 | 14652 | |
15063 | 14653 | =begin original |
15064 | 14654 | |
15065 | 14655 | If LIMIT is negative, it is treated as if it were instead arbitrarily |
15066 | 14656 | large; as many fields as possible are produced. |
15067 | 14657 | |
15068 | 14658 | =end original |
15069 | 14659 | |
15070 | 14660 | LIMIT が負数なら、非常に大きい数であるかのように扱われます; できるだけ多くの |
15071 | 14661 | フィールドが生成されます。 |
15072 | 14662 | |
15073 | 14663 | =begin original |
15074 | 14664 | |
15075 | 14665 | If LIMIT is omitted (or, equivalently, zero), then it is usually |
15076 | 14666 | treated as if it were instead negative but with the exception that |
15077 | 14667 | trailing empty fields are stripped (empty leading fields are always |
15078 | 14668 | preserved); if all fields are empty, then all fields are considered to |
15079 | 14669 | be trailing (and are thus stripped in this case). Thus, the following: |
15080 | 14670 | |
15081 | 14671 | =end original |
15082 | 14672 | |
15083 | 14673 | LIMIT が省略されると(あるいは等価な 0 なら)、普通は負数が指定されたかのように |
15084 | 14674 | 動作しますが、末尾の空フィールドは取り除かれるという例外があります |
15085 | 14675 | (先頭の空フィールドは常に保存されます); もし全てのフィールドが空なら、 |
15086 | 14676 | 全てのフィールドが末尾として扱われます(そしてこの場合取り除かれます)。 |
15087 | 14677 | 従って、以下のようにすると: |
15088 | 14678 | |
15089 | 14679 | print join(':', split(',', 'a,b,c,,,')), "\n"; |
15090 | 14680 | |
15091 | 14681 | =begin original |
15092 | 14682 | |
15093 | 14683 | produces the output 'a:b:c', but the following: |
15094 | 14684 | |
15095 | 14685 | =end original |
15096 | 14686 | |
15097 | 14687 | 出力 'a:b:c' を生成しますが、以下のようにすると: |
15098 | 14688 | |
15099 | 14689 | print join(':', split(',', 'a,b,c,,,', -1)), "\n"; |
15100 | 14690 | |
15101 | 14691 | =begin original |
15102 | 14692 | |
15103 | 14693 | produces the output 'a:b:c:::'. |
15104 | 14694 | |
15105 | 14695 | =end original |
15106 | 14696 | |
15107 | 14697 | 出力 'a:b:c:::' を生成します。 |
15108 | 14698 | |
15109 | 14699 | =begin original |
15110 | 14700 | |
15111 | 14701 | In time-critical applications, it is worthwhile to avoid splitting |
15112 | 14702 | into more fields than necessary. Thus, when assigning to a list, |
15113 | 14703 | if LIMIT is omitted (or zero), then LIMIT is treated as though it |
15114 | 14704 | were one larger than the number of variables in the list; for the |
15115 | following, LIMIT is implicitly | |
14705 | following, LIMIT is implicitly 4: | |
15116 | 14706 | |
15117 | 14707 | =end original |
15118 | 14708 | |
15119 | 14709 | 時間に厳しいアプリケーションでは、必要でないフィールドの分割を避けるのは |
15120 | 14710 | 価値があります。 |
15121 | 14711 | 従って、リストに代入される場合に、LIMIT が省略される(または 0)と、 |
15122 | 14712 | LIMIT は リストにある変数の数より一つ大きい数のように扱われます; |
15123 | 次の場合、LIMIT は暗黙に | |
14713 | 次の場合、LIMIT は暗黙に 4 になります: | |
15124 | 14714 | |
15125 | ($login, $passwd) = split(/:/); | |
14715 | ($login, $passwd, $remainder) = split(/:/); | |
15126 | 14716 | |
15127 | 14717 | =begin original |
15128 | 14718 | |
15129 | 14719 | Note that splitting an EXPR that evaluates to the empty string always |
15130 | 14720 | produces zero fields, regardless of the LIMIT specified. |
15131 | 14721 | |
15132 | 14722 | =end original |
15133 | 14723 | |
15134 | 14724 | LIMIT の指定に関わらず、空文字列に評価される EXPR を分割すると常に 0 個の |
15135 | 14725 | フィールドを生成することに注意してください。 |
15136 | 14726 | |
15137 | 14727 | =begin original |
15138 | 14728 | |
15139 | 14729 | An empty leading field is produced when there is a positive-width |
15140 | 14730 | match at the beginning of EXPR. For instance: |
15141 | 14731 | |
15142 | 14732 | =end original |
15143 | 14733 | |
15144 | 14734 | EXPR の先頭で正数幅でマッチングしたときには先頭に空のフィールドが |
15145 | 14735 | 生成されます。 |
15146 | 14736 | 例えば: |
15147 | 14737 | |
15148 | 14738 | print join(':', split(/ /, ' abc')), "\n"; |
15149 | 14739 | |
15150 | 14740 | =begin original |
15151 | 14741 | |
15152 | 14742 | produces the output ':abc'. However, a zero-width match at the |
15153 | 14743 | beginning of EXPR never produces an empty field, so that: |
15154 | 14744 | |
15155 | 14745 | =end original |
15156 | 14746 | |
15157 | 14747 | これは出力 ':abc' を生成します。 |
15158 | 14748 | しかし、EXPR の先頭でのゼロ幅マッチングは決して空フィールドを生成しないので: |
15159 | 14749 | |
15160 | 14750 | print join(':', split(//, ' abc')); |
15161 | 14751 | |
15162 | 14752 | =begin original |
15163 | 14753 | |
15164 | 14754 | produces the output S<' :a:b:c'> (rather than S<': :a:b:c'>). |
15165 | 14755 | |
15166 | 14756 | =end original |
15167 | 14757 | |
15168 | 14758 | これは(S<': :a:b:c'> ではなく)出力 S<' :a:b:c'> を生成します。 |
15169 | 14759 | |
15170 | 14760 | =begin original |
15171 | 14761 | |
15172 | 14762 | An empty trailing field, on the other hand, is produced when there is a |
15173 | 14763 | match at the end of EXPR, regardless of the length of the match |
15174 | 14764 | (of course, unless a non-zero LIMIT is given explicitly, such fields are |
15175 | 14765 | removed, as in the last example). Thus: |
15176 | 14766 | |
15177 | 14767 | =end original |
15178 | 14768 | |
15179 | 14769 | 一方、末尾の空のフィールドは、マッチングの長さに関わらず、EXPR の末尾で |
15180 | 14770 | マッチングしたときに生成されます(もちろん非 0 の LIMIT が明示的に |
15181 | 14771 | 指定されていない場合です; このようなフィールドは前の例のように |
15182 | 14772 | 取り除かれます)。 |
15183 | 14773 | 従って: |
15184 | 14774 | |
15185 | 14775 | print join(':', split(//, ' abc', -1)), "\n"; |
15186 | 14776 | |
15187 | 14777 | =begin original |
15188 | 14778 | |
15189 | 14779 | produces the output S<' :a:b:c:'>. |
15190 | 14780 | |
15191 | 14781 | =end original |
15192 | 14782 | |
15193 | 14783 | これは出力 S<' :a:b:c:'> を生成します。 |
15194 | 14784 | |
15195 | 14785 | =begin original |
15196 | 14786 | |
15197 | 14787 | If the PATTERN contains |
15198 | 14788 | L<capturing groups|perlretut/Grouping things and hierarchical matching>, |
15199 | 14789 | then for each separator, an additional field is produced for each substring |
15200 | 14790 | captured by a group (in the order in which the groups are specified, |
15201 | 14791 | as per L<backreferences|perlretut/Backreferences>); if any group does not |
15202 | 14792 | match, then it captures the C<undef> value instead of a substring. Also, |
15203 | 14793 | note that any such additional field is produced whenever there is a |
15204 | 14794 | separator (that is, whenever a split occurs), and such an additional field |
15205 | 14795 | does B<not> count towards the LIMIT. Consider the following expressions |
15206 | 14796 | evaluated in list context (each returned list is provided in the associated |
15207 | 14797 | comment): |
15208 | 14798 | |
15209 | 14799 | =end original |
15210 | 14800 | |
15211 | 14801 | PATTERN が |
15212 | 14802 | L<捕捉グループ|perlretut/Grouping things and hierarchical matching> を |
15213 | 14803 | 含んでいる場合、それぞれのセパレータについて、 |
15214 | 14804 | (L<後方参照|perlretut/Backreferences> のようにグループが指定された) |
15215 | 14805 | グループによって捕捉されたそれぞれの部分文字列について追加のフィールドが |
15216 | 14806 | 生成されます; どのグループもマッチングしなかった場合、部分文字列の代わりに |
15217 | 14807 | C<undef> 値を捕捉します。 |
15218 | 14808 | また、このような追加のフィールドはセパレータがあるとき(つまり、分割が |
15219 | 14809 | 行われるとき)はいつでも生成され、このような追加のフィールドは |
15220 | 14810 | LIMIT に関してはカウント B<されない> ことに注意してください。 |
15221 | 14811 | リストコンテキストで評価される以下のような式を考えます |
15222 | 14812 | (それぞれの返されるリストは関連づけられたコメントで提供されます): |
15223 | 14813 | |
15224 | 14814 | split(/-|,/, "1-10,20", 3) |
15225 | 14815 | # ('1', '10', '20') |
15226 | 14816 | |
15227 | 14817 | split(/(-|,)/, "1-10,20", 3) |
15228 | 14818 | # ('1', '-', '10', ',', '20') |
15229 | 14819 | |
15230 | 14820 | split(/-|(,)/, "1-10,20", 3) |
15231 | 14821 | # ('1', undef, '10', ',', '20') |
15232 | 14822 | |
15233 | 14823 | split(/(-)|,/, "1-10,20", 3) |
15234 | 14824 | # ('1', '-', '10', undef, '20') |
15235 | 14825 | |
15236 | 14826 | split(/(-)|(,)/, "1-10,20", 3) |
15237 | 14827 | # ('1', '-', undef, '10', undef, ',', '20') |
15238 | 14828 | |
15239 | 14829 | =item sprintf FORMAT, LIST |
15240 | 14830 | X<sprintf> |
15241 | 14831 | |
15242 | 14832 | =for Pod::Functions formatted print into a string |
15243 | 14833 | |
15244 | 14834 | =begin original |
15245 | 14835 | |
15246 | 14836 | Returns a string formatted by the usual C<printf> conventions of the C |
15247 | 14837 | library function C<sprintf>. See below for more details |
15248 | 14838 | and see L<sprintf(3)> or L<printf(3)> on your system for an explanation of |
15249 | 14839 | the general principles. |
15250 | 14840 | |
15251 | 14841 | =end original |
15252 | 14842 | |
15253 | 14843 | 普通の C 言語の C<printf> 記法のフォーマットで、整形された文字列を返します。 |
15254 | 14844 | 一般的な原則の説明については以下の説明と、システムの |
15255 | 14845 | L<sprintf(3)> または L<printf(3)> の説明を参照してください。 |
15256 | 14846 | |
15257 | 14847 | =begin original |
15258 | 14848 | |
15259 | 14849 | For example: |
15260 | 14850 | |
15261 | 14851 | =end original |
15262 | 14852 | |
15263 | 14853 | 例えば: |
15264 | 14854 | |
15265 | 14855 | # Format number with up to 8 leading zeroes |
15266 | 14856 | $result = sprintf("%08d", $number); |
15267 | 14857 | |
15268 | 14858 | # Round number to 3 digits after decimal point |
15269 | 14859 | $rounded = sprintf("%.3f", $number); |
15270 | 14860 | |
15271 | 14861 | =begin original |
15272 | 14862 | |
15273 | 14863 | Perl does its own C<sprintf> formatting: it emulates the C |
15274 | 14864 | function sprintf(3), but doesn't use it except for floating-point |
15275 | 14865 | numbers, and even then only standard modifiers are allowed. |
15276 | 14866 | Non-standard extensions in your local sprintf(3) are |
15277 | 14867 | therefore unavailable from Perl. |
15278 | 14868 | |
15279 | 14869 | =end original |
15280 | 14870 | |
15281 | Perl は C<sprintf> フォーマット処理を自力で行います: | |
14871 | Perl は C<sprintf> フォーマット処理を自力で行います: | |
15282 | sprintf(3) 関数をエミュレートしますが、 | |
14872 | これは C の sprintf(3) 関数をエミュレートしますが、 | |
15283 | 除きますが、それでも標準の | |
14873 | C の関数は使いません(浮動小数点を除きますが、それでも標準の | |
14874 | 記述子のみが利用できます)。 | |
15284 | 14875 | 従って、ローカルな非標準の C<sprintf> 拡張機能は Perl では使えません。 |
15285 | 14876 | |
15286 | 14877 | =begin original |
15287 | 14878 | |
15288 | 14879 | Unlike C<printf>, C<sprintf> does not do what you probably mean when you |
15289 | 14880 | pass it an array as your first argument. |
15290 | 14881 | The array is given scalar context, |
15291 | 14882 | and instead of using the 0th element of the array as the format, Perl will |
15292 | 14883 | use the count of elements in the array as the format, which is almost never |
15293 | 14884 | useful. |
15294 | 14885 | |
15295 | 14886 | =end original |
15296 | 14887 | |
15297 | 14888 | C<printf> と違って、 C<sprintf> の最初の引数に配列を渡しても |
15298 | 14889 | あなたが多分望むとおりには動作しません。 |
15299 | 14890 | 配列はスカラコンテキストで渡されるので、配列の 0 番目の要素ではなく、 |
15300 | 14891 | 配列の要素数をフォーマットとして扱います; これはほとんど役に立ちません。 |
15301 | 14892 | |
15302 | 14893 | =begin original |
15303 | 14894 | |
15304 | 14895 | Perl's C<sprintf> permits the following universally-known conversions: |
15305 | 14896 | |
15306 | 14897 | =end original |
15307 | 14898 | |
15308 | 14899 | Perl の C<sprintf> は以下の一般に知られている変換に対応しています: |
15309 | 14900 | |
15310 | 14901 | =begin original |
15311 | 14902 | |
15312 | 14903 | %% a percent sign |
15313 | 14904 | %c a character with the given number |
15314 | 14905 | %s a string |
15315 | 14906 | %d a signed integer, in decimal |
15316 | 14907 | %u an unsigned integer, in decimal |
15317 | 14908 | %o an unsigned integer, in octal |
15318 | 14909 | %x an unsigned integer, in hexadecimal |
15319 | 14910 | %e a floating-point number, in scientific notation |
15320 | 14911 | %f a floating-point number, in fixed decimal notation |
15321 | 14912 | %g a floating-point number, in %e or %f notation |
15322 | 14913 | |
15323 | 14914 | =end original |
15324 | 14915 | |
15325 | 14916 | %% パーセントマーク |
15326 | 14917 | %c 与えられた番号の文字 |
15327 | 14918 | %s 文字列 |
15328 | 14919 | %d 符号付き 10 進数 |
15329 | 14920 | %u 符号なし 10 進数 |
15330 | 14921 | %o 符号なし 8 進数 |
15331 | 14922 | %x 符号なし 16 進数 |
15332 | 14923 | %e 科学的表記の浮動小数点数 |
15333 | 14924 | %f 固定 10 進数表記の浮動小数点数 |
15334 | 14925 | %g %e か %f の表記の浮動小数点数 |
15335 | 14926 | |
15336 | 14927 | =begin original |
15337 | 14928 | |
15338 | 14929 | In addition, Perl permits the following widely-supported conversions: |
15339 | 14930 | |
15340 | 14931 | =end original |
15341 | 14932 | |
15342 | 14933 | さらに、Perl では以下のよく使われている変換に対応しています: |
15343 | 14934 | |
15344 | 14935 | =begin original |
15345 | 14936 | |
15346 | 14937 | %X like %x, but using upper-case letters |
15347 | 14938 | %E like %e, but using an upper-case "E" |
15348 | 14939 | %G like %g, but with an upper-case "E" (if applicable) |
15349 | 14940 | %b an unsigned integer, in binary |
15350 | 14941 | %B like %b, but using an upper-case "B" with the # flag |
15351 | 14942 | %p a pointer (outputs the Perl value's address in hexadecimal) |
15352 | 14943 | %n special: *stores* the number of characters output so far |
15353 | 14944 | into the next argument in the parameter list |
15354 | 14945 | |
15355 | 14946 | =end original |
15356 | 14947 | |
15357 | 14948 | %X %x と同様だが大文字を使う |
15358 | 14949 | %E %e と同様だが大文字の "E" を使う |
15359 | 14950 | %G %g と同様だが(適切なら)大文字の "E" を使う |
15360 | 14951 | %b 符号なし 2 進数 |
15361 | 14952 | %B %b と同様だが、# フラグで大文字の "B" を使う |
15362 | 14953 | %p ポインタ (Perl の値のアドレスを 16 進数で出力する) |
15363 | 14954 | %n 特殊: 出力文字数を引数リストの次の変数に「格納」する |
15364 | 14955 | |
15365 | 14956 | =begin original |
15366 | 14957 | |
15367 | 14958 | Finally, for backward (and we do mean "backward") compatibility, Perl |
15368 | 14959 | permits these unnecessary but widely-supported conversions: |
15369 | 14960 | |
15370 | 14961 | =end original |
15371 | 14962 | |
15372 | 14963 | 最後に、過去との互換性(これは「過去」だと考えています)のために、 |
15373 | 14964 | Perl は以下の不要ではあるけれども広く使われている変換に対応しています。 |
15374 | 14965 | |
15375 | 14966 | =begin original |
15376 | 14967 | |
15377 | 14968 | %i a synonym for %d |
15378 | 14969 | %D a synonym for %ld |
15379 | 14970 | %U a synonym for %lu |
15380 | 14971 | %O a synonym for %lo |
15381 | 14972 | %F a synonym for %f |
15382 | 14973 | |
15383 | 14974 | =end original |
15384 | 14975 | |
15385 | 14976 | %i %d の同義語 |
15386 | 14977 | %D %ld の同義語 |
15387 | 14978 | %U %lu の同義語 |
15388 | 14979 | %O %lo の同義語 |
15389 | 14980 | %F %f の同義語 |
15390 | 14981 | |
15391 | 14982 | =begin original |
15392 | 14983 | |
15393 | 14984 | Note that the number of exponent digits in the scientific notation produced |
15394 | 14985 | by C<%e>, C<%E>, C<%g> and C<%G> for numbers with the modulus of the |
15395 | 14986 | exponent less than 100 is system-dependent: it may be three or less |
15396 | 14987 | (zero-padded as necessary). In other words, 1.23 times ten to the |
15397 | 14988 | 99th may be either "1.23e99" or "1.23e099". |
15398 | 14989 | |
15399 | 14990 | =end original |
15400 | 14991 | |
15401 | 14992 | C<%e>, C<%E>, C<%g>, C<%G> において、指数部が 100 未満の場合の |
15402 | 14993 | 指数部の科学的な表記法はシステム依存であることに注意してください: |
15403 | 14994 | 3 桁かもしれませんし、それ以下かもしれません(必要に応じて 0 で |
15404 | 14995 | パッディングされます)。 |
15405 | 14996 | 言い換えると、 1.23 掛ける 10 の 99 乗は "1.23e99" かもしれませんし |
15406 | 14997 | "1.23e099" かもしれません。 |
15407 | 14998 | |
15408 | 14999 | =begin original |
15409 | 15000 | |
15410 | 15001 | Between the C<%> and the format letter, you may specify several |
15411 | 15002 | additional attributes controlling the interpretation of the format. |
15412 | 15003 | In order, these are: |
15413 | 15004 | |
15414 | 15005 | =end original |
15415 | 15006 | |
15416 | 15007 | C<%> とフォーマット文字の間に、フォーマットの解釈を制御するための、 |
15417 | 15008 | いくつかの追加の属性を指定できます。 |
15418 | 15009 | 順番に、以下のものがあります: |
15419 | 15010 | |
15420 | 15011 | =over 4 |
15421 | 15012 | |
15422 | 15013 | =item format parameter index |
15423 | 15014 | |
15424 | 15015 | (フォーマットパラメータインデックス) |
15425 | 15016 | |
15426 | 15017 | =begin original |
15427 | 15018 | |
15428 | 15019 | An explicit format parameter index, such as C<2$>. By default sprintf |
15429 | 15020 | will format the next unused argument in the list, but this allows you |
15430 | 15021 | to take the arguments out of order: |
15431 | 15022 | |
15432 | 15023 | =end original |
15433 | 15024 | |
15434 | 15025 | C<2$> のような明示的なフォーマットパラメータインデックス。 |
15435 | 15026 | デフォルトでは sprintf はリストの次の使われていない引数を |
15436 | 15027 | フォーマットしますが、これによって異なった順番の引数を使えるようにします: |
15437 | 15028 | |
15438 | 15029 | printf '%2$d %1$d', 12, 34; # prints "34 12" |
15439 | 15030 | printf '%3$d %d %1$d', 1, 2, 3; # prints "3 1 1" |
15440 | 15031 | |
15441 | 15032 | =item flags |
15442 | 15033 | |
15443 | 15034 | (フラグ) |
15444 | 15035 | |
15445 | 15036 | =begin original |
15446 | 15037 | |
15447 | 15038 | one or more of: |
15448 | 15039 | |
15449 | 15040 | =end original |
15450 | 15041 | |
15451 | 15042 | 以下のうちの一つまたは複数指定できます: |
15452 | 15043 | |
15453 | 15044 | =begin original |
15454 | 15045 | |
15455 | 15046 | space prefix non-negative number with a space |
15456 | 15047 | + prefix non-negative number with a plus sign |
15457 | 15048 | - left-justify within the field |
15458 | 15049 | 0 use zeros, not spaces, to right-justify |
15459 | 15050 | # ensure the leading "0" for any octal, |
15460 | 15051 | prefix non-zero hexadecimal with "0x" or "0X", |
15461 | 15052 | prefix non-zero binary with "0b" or "0B" |
15462 | 15053 | |
15463 | 15054 | =end original |
15464 | 15055 | |
15465 | 15056 | space 非負数の前に空白をつける |
15466 | 15057 | + 非負数の前にプラス記号をつける |
15467 | 15058 | - フィールド内で左詰めする |
15468 | 15059 | 0 右詰めに空白ではなくゼロを使う |
15469 | 15060 | # 8 進数では確実に先頭に "0" をつける; |
15470 | 15061 | 非 0 の 16 進数では "0x" か "0X" をつける; |
15471 | 15062 | 非 0 の 2 進数では "0b" か "0B" をつける |
15472 | 15063 | |
15473 | 15064 | =begin original |
15474 | 15065 | |
15475 | 15066 | For example: |
15476 | 15067 | |
15477 | 15068 | =end original |
15478 | 15069 | |
15479 | 15070 | 例えば: |
15480 | 15071 | |
15481 | 15072 | printf '<% d>', 12; # prints "< 12>" |
15482 | 15073 | printf '<%+d>', 12; # prints "<+12>" |
15483 | 15074 | printf '<%6s>', 12; # prints "< 12>" |
15484 | 15075 | printf '<%-6s>', 12; # prints "<12 >" |
15485 | 15076 | printf '<%06s>', 12; # prints "<000012>" |
15486 | 15077 | printf '<%#o>', 12; # prints "<014>" |
15487 | 15078 | printf '<%#x>', 12; # prints "<0xc>" |
15488 | 15079 | printf '<%#X>', 12; # prints "<0XC>" |
15489 | 15080 | printf '<%#b>', 12; # prints "<0b1100>" |
15490 | 15081 | printf '<%#B>', 12; # prints "<0B1100>" |
15491 | 15082 | |
15492 | 15083 | =begin original |
15493 | 15084 | |
15494 | 15085 | When a space and a plus sign are given as the flags at once, |
15495 | 15086 | a plus sign is used to prefix a positive number. |
15496 | 15087 | |
15497 | 15088 | =end original |
15498 | 15089 | |
15499 | 15090 | 空白とプラス記号がフラグとして同時に与えられると、プラス記号は正の数に |
15500 | 15091 | 前置するために使われます。 |
15501 | 15092 | |
15502 | 15093 | printf '<%+ d>', 12; # prints "<+12>" |
15503 | 15094 | printf '<% +d>', 12; # prints "<+12>" |
15504 | 15095 | |
15505 | 15096 | =begin original |
15506 | 15097 | |
15507 | 15098 | When the # flag and a precision are given in the %o conversion, |
15508 | 15099 | the precision is incremented if it's necessary for the leading "0". |
15509 | 15100 | |
15510 | 15101 | =end original |
15511 | 15102 | |
15512 | 15103 | %o 変換に # フラグと精度が与えられると、先頭の "0" が必要な場合は |
15513 | 15104 | 精度に 1 が加えられます。 |
15514 | 15105 | |
15515 | 15106 | printf '<%#.5o>', 012; # prints "<00012>" |
15516 | 15107 | printf '<%#.5o>', 012345; # prints "<012345>" |
15517 | 15108 | printf '<%#.0o>', 0; # prints "<0>" |
15518 | 15109 | |
15519 | 15110 | =item vector flag |
15520 | 15111 | |
15521 | 15112 | (ベクタフラグ) |
15522 | 15113 | |
15523 | 15114 | =begin original |
15524 | 15115 | |
15525 | 15116 | This flag tells Perl to interpret the supplied string as a vector of |
15526 | 15117 | integers, one for each character in the string. Perl applies the format to |
15527 | 15118 | each integer in turn, then joins the resulting strings with a separator (a |
15528 | 15119 | dot C<.> by default). This can be useful for displaying ordinal values of |
15529 | 15120 | characters in arbitrary strings: |
15530 | 15121 | |
15531 | 15122 | =end original |
15532 | 15123 | |
15533 | 15124 | このフラグは Perl に、与えられた文字列を、文字毎に一つの整数のベクタとして |
15534 | 15125 | 解釈させます。 |
15535 | 15126 | Perl は各数値をフォーマットし、それから結果の文字列をセパレータ |
15536 | 15127 | (デフォルトでは C<.>)で連結します。 |
15537 | 15128 | これは任意の文字列の文字を順序付きの値として表示するのに便利です: |
15538 | 15129 | |
15539 | 15130 | printf "%vd", "AB\x{100}"; # prints "65.66.256" |
15540 | 15131 | printf "version is v%vd\n", $^V; # Perl's version |
15541 | 15132 | |
15542 | 15133 | =begin original |
15543 | 15134 | |
15544 | 15135 | Put an asterisk C<*> before the C<v> to override the string to |
15545 | 15136 | use to separate the numbers: |
15546 | 15137 | |
15547 | 15138 | =end original |
15548 | 15139 | |
15549 | 15140 | アスタリスク C<*> を C<v> の前に置くと、数値を分けるために使われる文字列を |
15550 | 15141 | 上書きします: |
15551 | 15142 | |
15552 | 15143 | printf "address is %*vX\n", ":", $addr; # IPv6 address |
15553 | 15144 | printf "bits are %0*v8b\n", " ", $bits; # random bitstring |
15554 | 15145 | |
15555 | 15146 | =begin original |
15556 | 15147 | |
15557 | 15148 | You can also explicitly specify the argument number to use for |
15558 | 15149 | the join string using something like C<*2$v>; for example: |
15559 | 15150 | |
15560 | 15151 | =end original |
15561 | 15152 | |
15562 | 15153 | また、C<*2$v> のように、連結する文字列として使う引数の番号を明示的に |
15563 | 15154 | 指定できます; 例えば: |
15564 | 15155 | |
15565 | printf '%*4$vX %*4$vX %*4$vX', | |
15156 | printf '%*4$vX %*4$vX %*4$vX', @addr[1..3], ":"; # 3 IPv6 addresses | |
15566 | @addr[1..3], ":"; | |
15567 | 15157 | |
15568 | 15158 | =item (minimum) width |
15569 | 15159 | |
15570 | 15160 | ((最小)幅) |
15571 | 15161 | |
15572 | 15162 | =begin original |
15573 | 15163 | |
15574 | 15164 | Arguments are usually formatted to be only as wide as required to |
15575 | 15165 | display the given value. You can override the width by putting |
15576 | 15166 | a number here, or get the width from the next argument (with C<*>) |
15577 | 15167 | or from a specified argument (e.g., with C<*2$>): |
15578 | 15168 | |
15579 | 15169 | =end original |
15580 | 15170 | |
15581 | 15171 | 引数は、普通は値を表示するのに必要なちょうどの幅でフォーマットされます。 |
15582 | 15172 | ここに数値を置くか、(C<*> で)次の引数か(C<*2$> で)明示的に指定した引数で |
15583 | 15173 | 幅を上書きできます。 |
15584 | 15174 | |
15585 | printf "<%s>", "a"; # prints "<a>" | |
15175 | printf "<%s>", "a"; # prints "<a>" | |
15586 | printf "<%6s>", "a"; # prints "< a>" | |
15176 | printf "<%6s>", "a"; # prints "< a>" | |
15587 | printf "<%*s>", 6, "a"; # prints "< a>" | |
15177 | printf "<%*s>", 6, "a"; # prints "< a>" | |
15588 | printf | |
15178 | printf "<%*2$s>", "a", 6; # prints "< a>" | |
15589 | printf "<%2s>", "long"; # prints "<long>" (does not truncate) | |
15179 | printf "<%2s>", "long"; # prints "<long>" (does not truncate) | |
15590 | 15180 | |
15591 | 15181 | =begin original |
15592 | 15182 | |
15593 | 15183 | If a field width obtained through C<*> is negative, it has the same |
15594 | 15184 | effect as the C<-> flag: left-justification. |
15595 | 15185 | |
15596 | 15186 | =end original |
15597 | 15187 | |
15598 | 15188 | C<*> を通して得られたフィールドの値が負数の場合、C<-> フラグと |
15599 | 15189 | 同様の効果 (左詰め) があります。 |
15600 | 15190 | |
15601 | 15191 | =item precision, or maximum width |
15602 | 15192 | X<precision> |
15603 | 15193 | |
15604 | 15194 | (精度あるいは最大幅) |
15605 | 15195 | |
15606 | 15196 | =begin original |
15607 | 15197 | |
15608 | 15198 | You can specify a precision (for numeric conversions) or a maximum |
15609 | 15199 | width (for string conversions) by specifying a C<.> followed by a number. |
15610 | 15200 | For floating-point formats except C<g> and C<G>, this specifies |
15611 | 15201 | how many places right of the decimal point to show (the default being 6). |
15612 | 15202 | For example: |
15613 | 15203 | |
15614 | 15204 | =end original |
15615 | 15205 | |
15616 | 15206 | C<.> の後に数値を指定することで、(数値変換の場合)精度や(文字列変換の場合) |
15617 | 15207 | 最大幅を指定できます。 |
15618 | 15208 | 小数点数フォーマットの場合、C<g> と C<G> を除いて、表示する小数点以下の |
15619 | 15209 | 桁数を指定します(デフォルトは 6 です)。 |
15620 | 15210 | 例えば: |
15621 | 15211 | |
15622 | 15212 | # these examples are subject to system-specific variation |
15623 | 15213 | printf '<%f>', 1; # prints "<1.000000>" |
15624 | 15214 | printf '<%.1f>', 1; # prints "<1.0>" |
15625 | 15215 | printf '<%.0f>', 1; # prints "<1>" |
15626 | 15216 | printf '<%e>', 10; # prints "<1.000000e+01>" |
15627 | 15217 | printf '<%.1e>', 10; # prints "<1.0e+01>" |
15628 | 15218 | |
15629 | 15219 | =begin original |
15630 | 15220 | |
15631 | 15221 | For "g" and "G", this specifies the maximum number of digits to show, |
15632 | 15222 | including those prior to the decimal point and those after it; for |
15633 | 15223 | example: |
15634 | 15224 | |
15635 | 15225 | =end original |
15636 | 15226 | |
15637 | 15227 | "g" と "G" の場合、これは表示する数値の数を指定します; |
15638 | 15228 | これには小数点の前の数値と後の数値を含みます; 例えば: |
15639 | 15229 | |
15640 | 15230 | # These examples are subject to system-specific variation. |
15641 | 15231 | printf '<%g>', 1; # prints "<1>" |
15642 | 15232 | printf '<%.10g>', 1; # prints "<1>" |
15643 | 15233 | printf '<%g>', 100; # prints "<100>" |
15644 | 15234 | printf '<%.1g>', 100; # prints "<1e+02>" |
15645 | 15235 | printf '<%.2g>', 100.01; # prints "<1e+02>" |
15646 | 15236 | printf '<%.5g>', 100.01; # prints "<100.01>" |
15647 | 15237 | printf '<%.4g>', 100.01; # prints "<100>" |
15648 | 15238 | |
15649 | 15239 | =begin original |
15650 | 15240 | |
15651 | 15241 | For integer conversions, specifying a precision implies that the |
15652 | 15242 | output of the number itself should be zero-padded to this width, |
15653 | 15243 | where the 0 flag is ignored: |
15654 | 15244 | |
15655 | 15245 | =end original |
15656 | 15246 | |
15657 | 15247 | 整数変換の場合、精度を指定すると、数値自体の出力はこの幅に 0 で |
15658 | 15248 | パッディングするべきであることを暗に示すことになり、0 フラグは |
15659 | 15249 | 無視されます: |
15660 | 15250 | |
15661 | 15251 | printf '<%.6d>', 1; # prints "<000001>" |
15662 | 15252 | printf '<%+.6d>', 1; # prints "<+000001>" |
15663 | 15253 | printf '<%-10.6d>', 1; # prints "<000001 >" |
15664 | 15254 | printf '<%10.6d>', 1; # prints "< 000001>" |
15665 | 15255 | printf '<%010.6d>', 1; # prints "< 000001>" |
15666 | 15256 | printf '<%+10.6d>', 1; # prints "< +000001>" |
15667 | 15257 | |
15668 | 15258 | printf '<%.6x>', 1; # prints "<000001>" |
15669 | 15259 | printf '<%#.6x>', 1; # prints "<0x000001>" |
15670 | 15260 | printf '<%-10.6x>', 1; # prints "<000001 >" |
15671 | 15261 | printf '<%10.6x>', 1; # prints "< 000001>" |
15672 | 15262 | printf '<%010.6x>', 1; # prints "< 000001>" |
15673 | 15263 | printf '<%#10.6x>', 1; # prints "< 0x000001>" |
15674 | 15264 | |
15675 | 15265 | =begin original |
15676 | 15266 | |
15677 | 15267 | For string conversions, specifying a precision truncates the string |
15678 | 15268 | to fit the specified width: |
15679 | 15269 | |
15680 | 15270 | =end original |
15681 | 15271 | |
15682 | 15272 | 文字列変換の場合、精度を指定すると、指定された幅に収まるように文字列を |
15683 | 15273 | 切り詰めます: |
15684 | 15274 | |
15685 | 15275 | printf '<%.5s>', "truncated"; # prints "<trunc>" |
15686 | 15276 | printf '<%10.5s>', "truncated"; # prints "< trunc>" |
15687 | 15277 | |
15688 | 15278 | =begin original |
15689 | 15279 | |
15690 | 15280 | You can also get the precision from the next argument using C<.*>: |
15691 | 15281 | |
15692 | 15282 | =end original |
15693 | 15283 | |
15694 | 15284 | C<.*> を使って精度を次の引数から取ることも出来ます: |
15695 | 15285 | |
15696 | 15286 | printf '<%.6x>', 1; # prints "<000001>" |
15697 | 15287 | printf '<%.*x>', 6, 1; # prints "<000001>" |
15698 | 15288 | |
15699 | 15289 | =begin original |
15700 | 15290 | |
15701 | 15291 | If a precision obtained through C<*> is negative, it counts |
15702 | 15292 | as having no precision at all. |
15703 | 15293 | |
15704 | 15294 | =end original |
15705 | 15295 | |
15706 | 15296 | C<*> によって得られた精度が負数の場合、精度が指定されなかった場合と |
15707 | 15297 | 同じ効果となります。 |
15708 | 15298 | |
15709 | 15299 | printf '<%.*s>', 7, "string"; # prints "<string>" |
15710 | 15300 | printf '<%.*s>', 3, "string"; # prints "<str>" |
15711 | 15301 | printf '<%.*s>', 0, "string"; # prints "<>" |
15712 | 15302 | printf '<%.*s>', -1, "string"; # prints "<string>" |
15713 | 15303 | |
15714 | 15304 | printf '<%.*d>', 1, 0; # prints "<0>" |
15715 | 15305 | printf '<%.*d>', 0, 0; # prints "<>" |
15716 | 15306 | printf '<%.*d>', -1, 0; # prints "<0>" |
15717 | 15307 | |
15718 | 15308 | =begin original |
15719 | 15309 | |
15720 | 15310 | You cannot currently get the precision from a specified number, |
15721 | 15311 | but it is intended that this will be possible in the future, for |
15722 | 15312 | example using C<.*2$>: |
15723 | 15313 | |
15724 | 15314 | =end original |
15725 | 15315 | |
15726 | 15316 | 現在のところ精度を指定した数値から得ることはできませんが、 |
15727 | 15317 | 将来は 例えば C<.*2$> のようにして可能にしようとしています: |
15728 | 15318 | |
15729 | printf | |
15319 | printf "<%.*2$x>", 1, 6; # INVALID, but in future will print "<000001>" | |
15730 | # "<000001>" | |
15731 | 15320 | |
15732 | 15321 | =item size |
15733 | 15322 | |
15734 | 15323 | (サイズ) |
15735 | 15324 | |
15736 | 15325 | =begin original |
15737 | 15326 | |
15738 | 15327 | For numeric conversions, you can specify the size to interpret the |
15739 | 15328 | number as using C<l>, C<h>, C<V>, C<q>, C<L>, or C<ll>. For integer |
15740 | 15329 | conversions (C<d u o x X b i D U O>), numbers are usually assumed to be |
15741 | 15330 | whatever the default integer size is on your platform (usually 32 or 64 |
15742 | 15331 | bits), but you can override this to use instead one of the standard C types, |
15743 | 15332 | as supported by the compiler used to build Perl: |
15744 | 15333 | |
15745 | 15334 | =end original |
15746 | 15335 | |
15747 | 15336 | 数値変換では、C<l>, C<h>, C<V>, C<q>, C<L>, C<ll> を使って解釈する数値の |
15748 | 15337 | 大きさを指定できます。 |
15749 | 15338 | 整数変換 (C<d u o x X b i D U O>) では、数値は通常プラットフォームの |
15750 | 15339 | デフォルトの整数のサイズ (通常は 32 ビットか 64 ビット) を仮定しますが、 |
15751 | 15340 | これを Perl がビルドされたコンパイラが対応している標準 C の型の一つで |
15752 | 15341 | 上書きできます: |
15753 | 15342 | |
15754 | 15343 | =begin original |
15755 | 15344 | |
15756 | hh interpret integer as C type "char" or "unsigned | |
15345 | hh interpret integer as C type "char" or "unsigned char" | |
15757 | | |
15346 | on Perl 5.14 or later | |
15758 | h interpret integer as C type "short" or | |
15347 | h interpret integer as C type "short" or "unsigned short" | |
15759 | " | |
15348 | j interpret integer as C type "intmax_t" on Perl 5.14 | |
15760 | | |
15349 | or later, and only with a C99 compiler (unportable) | |
15761 | | |
15350 | l interpret integer as C type "long" or "unsigned long" | |
15762 | | |
15351 | q, L, or ll interpret integer as C type "long long", "unsigned long long", | |
15763 | | |
15352 | or "quad" (typically 64-bit integers) | |
15764 | " | |
15353 | t interpret integer as C type "ptrdiff_t" on Perl 5.14 or later | |
15765 | | |
15354 | z interpret integer as C type "size_t" on Perl 5.14 or later | |
15766 | "unsigned long long", or "quad" (typically | |
15767 | 64-bit integers) | |
15768 | t interpret integer as C type "ptrdiff_t" on Perl | |
15769 | 5.14 or later | |
15770 | z interpret integer as C type "size_t" on Perl 5.14 | |
15771 | or later | |
15772 | 15355 | |
15773 | 15356 | =end original |
15774 | 15357 | |
15775 | 15358 | hh Perl 5.14 以降で整数を C の "char" または "unsigned char" |
15776 | ||
15359 | 型として解釈する | |
15777 | 15360 | h 整数を C の "char" または "unsigned char" 型として解釈する |
15778 | j | |
15361 | j Perl 5.14 以降 C99 コンパイラのみで整数を C の "intmax_t" | |
15779 | ||
15362 | 型として解釈する (移植性なし) | |
15780 | 15363 | l 整数を C の "long" または "unsigned long" と解釈する |
15781 | 15364 | h 整数を C の "short" または "unsigned short" と解釈する |
15782 | 15365 | q, L or ll 整数を C の "long long", "unsigned long long", |
15783 | 15366 | "quads"(典型的には 64 ビット整数) のどれかと解釈する |
15784 | t | |
15367 | t Perl 5.14 以降で整数を C の "ptrdiff_t" 型として解釈する | |
15785 | z | |
15368 | z Perl 5.14 以降で整数を C の "size_t" 型として解釈する | |
15786 | 15369 | |
15787 | 15370 | =begin original |
15788 | 15371 | |
15789 | 15372 | As of 5.14, none of these raises an exception if they are not supported on |
15790 | 15373 | your platform. However, if warnings are enabled, a warning of the |
15791 | 15374 | C<printf> warning class is issued on an unsupported conversion flag. |
15792 | 15375 | Should you instead prefer an exception, do this: |
15793 | 15376 | |
15794 | 15377 | =end original |
15795 | 15378 | |
15796 | 15379 | 5.14 から、プラットフォームがこれらに対応していないときでも例外が |
15797 | 15380 | 発生しなくなりました。 |
15798 | 15381 | しかし、もし警告が有効になっているなら、 |
15799 | 15382 | 非対応変換フラグに関して C<printf> 警告クラスの警告が発生します。 |
15800 | 15383 | 例外の方がお好みなら、以下のようにします: |
15801 | 15384 | |
15802 | 15385 | use warnings FATAL => "printf"; |
15803 | 15386 | |
15804 | 15387 | =begin original |
15805 | 15388 | |
15806 | 15389 | If you would like to know about a version dependency before you |
15807 | 15390 | start running the program, put something like this at its top: |
15808 | 15391 | |
15809 | 15392 | =end original |
15810 | 15393 | |
15811 | 15394 | プログラムの実行開始前にバージョン依存について知りたいなら、先頭に |
15812 | 15395 | 以下のようなものを書きます: |
15813 | 15396 | |
15814 | 15397 | use 5.014; # for hh/j/t/z/ printf modifiers |
15815 | 15398 | |
15816 | 15399 | =begin original |
15817 | 15400 | |
15818 | 15401 | You can find out whether your Perl supports quads via L<Config>: |
15819 | 15402 | |
15820 | 15403 | =end original |
15821 | 15404 | |
15822 | 15405 | Perl が 64 ビット整数に対応しているかどうかは L<Config> を使って |
15823 | 15406 | 調べられます: |
15824 | 15407 | |
15825 | 15408 | use Config; |
15826 | if ($Config{use64bitint} eq "define" | |
15409 | if ($Config{use64bitint} eq "define" || $Config{longsize} >= 8) { | |
15827 | || $Config{longsize} >= 8) { | |
15828 | 15410 | print "Nice quads!\n"; |
15829 | 15411 | } |
15830 | 15412 | |
15831 | 15413 | =begin original |
15832 | 15414 | |
15833 | 15415 | For floating-point conversions (C<e f g E F G>), numbers are usually assumed |
15834 | 15416 | to be the default floating-point size on your platform (double or long double), |
15835 | 15417 | but you can force "long double" with C<q>, C<L>, or C<ll> if your |
15836 | 15418 | platform supports them. You can find out whether your Perl supports long |
15837 | 15419 | doubles via L<Config>: |
15838 | 15420 | |
15839 | 15421 | =end original |
15840 | 15422 | |
15841 | 15423 | 浮動小数点数変換 (C<e f g E F G>) では、普通はプラットフォームのデフォルトの |
15842 | 15424 | 不動小数点数のサイズ (double か long double) を仮定します。 |
15843 | 15425 | Perl が long double に対応しているかどうかは L<Config> を使って |
15844 | 15426 | 調べられます: |
15845 | 15427 | |
15846 | 15428 | use Config; |
15847 | 15429 | print "long doubles\n" if $Config{d_longdbl} eq "define"; |
15848 | 15430 | |
15849 | 15431 | =begin original |
15850 | 15432 | |
15851 | 15433 | You can find out whether Perl considers "long double" to be the default |
15852 | 15434 | floating-point size to use on your platform via L<Config>: |
15853 | 15435 | |
15854 | 15436 | =end original |
15855 | 15437 | |
15856 | 15438 | Perl が "long double" をデフォルトの浮動小数点数として扱っているかどうかは |
15857 | 15439 | L<Config> を使って調べられます: |
15858 | 15440 | |
15859 | 15441 | use Config; |
15860 | 15442 | if ($Config{uselongdouble} eq "define") { |
15861 | ||
15443 | print "long doubles by default\n"; | |
15862 | 15444 | } |
15863 | 15445 | |
15864 | 15446 | =begin original |
15865 | 15447 | |
15866 | 15448 | It can also be that long doubles and doubles are the same thing: |
15867 | 15449 | |
15868 | 15450 | =end original |
15869 | 15451 | |
15870 | 15452 | long double と double が同じ場合もあります: |
15871 | 15453 | |
15872 | 15454 | use Config; |
15873 | 15455 | ($Config{doublesize} == $Config{longdblsize}) && |
15874 | 15456 | print "doubles are long doubles\n"; |
15875 | 15457 | |
15876 | 15458 | =begin original |
15877 | 15459 | |
15878 | 15460 | The size specifier C<V> has no effect for Perl code, but is supported for |
15879 | 15461 | compatibility with XS code. It means "use the standard size for a Perl |
15880 | 15462 | integer or floating-point number", which is the default. |
15881 | 15463 | |
15882 | 15464 | =end original |
15883 | 15465 | |
15884 | 15466 | サイズ指定子 C<V> は Perl のコードには何の影響もありませんが、これは |
15885 | 15467 | XS コードとの互換性のために対応しています。 |
15886 | 15468 | これは「Perl 整数 (または浮動小数点数) として標準的なサイズを使う」ことを |
15887 | 15469 | 意味し、これはデフォルトです。 |
15888 | 15470 | |
15889 | 15471 | =item order of arguments |
15890 | 15472 | |
15891 | 15473 | (引数の順序) |
15892 | 15474 | |
15893 | 15475 | =begin original |
15894 | 15476 | |
15895 | 15477 | Normally, sprintf() takes the next unused argument as the value to |
15896 | 15478 | format for each format specification. If the format specification |
15897 | 15479 | uses C<*> to require additional arguments, these are consumed from |
15898 | 15480 | the argument list in the order they appear in the format |
15899 | 15481 | specification I<before> the value to format. Where an argument is |
15900 | 15482 | specified by an explicit index, this does not affect the normal |
15901 | 15483 | order for the arguments, even when the explicitly specified index |
15902 | 15484 | would have been the next argument. |
15903 | 15485 | |
15904 | 15486 | =end original |
15905 | 15487 | |
15906 | 15488 | 通常、sprintf() は各フォーマット指定について、使われていない次の引数を |
15907 | 15489 | フォーマットする値として使います。 |
15908 | 15490 | 追加の引数を要求するためにフォーマット指定 C<*> を使うと、 |
15909 | 15491 | これらはフォーマットする値の I<前> のフォーマット指定に現れる順番に |
15910 | 15492 | 引数リストから消費されます。 |
15911 | 15493 | 引数の位置が明示的なインデックスを使って指定された場合、 |
15912 | 15494 | (明示的に指定したインデックスが次の引数の場合でも) |
15913 | 15495 | これは通常の引数の順番に影響を与えません。 |
15914 | 15496 | |
15915 | 15497 | =begin original |
15916 | 15498 | |
15917 | 15499 | So: |
15918 | 15500 | |
15919 | 15501 | =end original |
15920 | 15502 | |
15921 | 15503 | それで: |
15922 | 15504 | |
15923 | 15505 | printf "<%*.*s>", $a, $b, $c; |
15924 | 15506 | |
15925 | 15507 | =begin original |
15926 | 15508 | |
15927 | 15509 | uses C<$a> for the width, C<$b> for the precision, and C<$c> |
15928 | 15510 | as the value to format; while: |
15929 | 15511 | |
15930 | 15512 | =end original |
15931 | 15513 | |
15932 | 15514 | とすると C<$a> を幅に、C<$b> を精度に、C<$c> をフォーマットの値に |
15933 | 15515 | 使います; 一方: |
15934 | 15516 | |
15935 | printf | |
15517 | printf "<%*1$.*s>", $a, $b; | |
15936 | 15518 | |
15937 | 15519 | =begin original |
15938 | 15520 | |
15939 | 15521 | would use C<$a> for the width and precision, and C<$b> as the |
15940 | 15522 | value to format. |
15941 | 15523 | |
15942 | 15524 | =end original |
15943 | 15525 | |
15944 | 15526 | とすると C<$a> を幅と精度に、C<$b> をフォーマットの値に使います。 |
15945 | 15527 | |
15946 | 15528 | =begin original |
15947 | 15529 | |
15948 | 15530 | Here are some more examples; be aware that when using an explicit |
15949 | 15531 | index, the C<$> may need escaping: |
15950 | 15532 | |
15951 | 15533 | =end original |
15952 | 15534 | |
15953 | 15535 | 以下にさらなる例を示します; 明示的にインデックスを使う場合、C<$> は |
15954 | 15536 | エスケープする必要があることに注意してください: |
15955 | 15537 | |
15956 | printf "%2\$d %d\n", 12, 34; # will print "34 12\n" | |
15538 | printf "%2\$d %d\n", 12, 34; # will print "34 12\n" | |
15957 | printf "%2\$d %d %d\n", 12, 34; # will print "34 12 34\n" | |
15539 | printf "%2\$d %d %d\n", 12, 34; # will print "34 12 34\n" | |
15958 | printf "%3\$d %d %d\n", 12, 34, 56; # will print "56 12 34\n" | |
15540 | printf "%3\$d %d %d\n", 12, 34, 56; # will print "56 12 34\n" | |
15959 | printf "%2\$*3\$d %d\n", 12, 34, 3; # will print " 34 12\n" | |
15541 | printf "%2\$*3\$d %d\n", 12, 34, 3; # will print " 34 12\n" | |
15960 | 15542 | |
15961 | 15543 | =back |
15962 | 15544 | |
15963 | 15545 | =begin original |
15964 | 15546 | |
15965 | 15547 | If C<use locale> (including C<use locale 'not_characters'>) is in effect |
15966 | 15548 | and POSIX::setlocale() has been called, |
15967 | 15549 | the character used for the decimal separator in formatted floating-point |
15968 | 15550 | numbers is affected by the LC_NUMERIC locale. See L<perllocale> |
15969 | 15551 | and L<POSIX>. |
15970 | 15552 | |
15971 | 15553 | =end original |
15972 | 15554 | |
15973 | 15555 | (C<use locale 'not_characters'> を含む)C<use locale> が有効で、 |
15974 | 15556 | POSIX::setlocale() が呼び出されている場合、フォーマットされた浮動小数点数の |
15975 | 15557 | 小数点として使われる文字は LC_NUMERIC ロケールの影響を受けます。 |
15976 | 15558 | L<perllocale> と L<POSIX> を参照してください。 |
15977 | 15559 | |
15978 | 15560 | =item sqrt EXPR |
15979 | 15561 | X<sqrt> X<root> X<square root> |
15980 | 15562 | |
15981 | 15563 | =item sqrt |
15982 | 15564 | |
15983 | 15565 | =for Pod::Functions square root function |
15984 | 15566 | |
15985 | 15567 | =begin original |
15986 | 15568 | |
15987 | 15569 | Return the positive square root of EXPR. If EXPR is omitted, uses |
15988 | 15570 | C<$_>. Works only for non-negative operands unless you've |
15989 | 15571 | loaded the C<Math::Complex> module. |
15990 | 15572 | |
15991 | 15573 | =end original |
15992 | 15574 | |
15993 | 15575 | EXPR の正の平方根を返します。 |
15994 | 15576 | EXPR が省略されると、C<$_> を使います。 |
15995 | 15577 | C<Math::Complex> モジュールを使わない場合は、負の数の引数は扱えません。 |
15996 | 15578 | |
15997 | 15579 | use Math::Complex; |
15998 | 15580 | print sqrt(-4); # prints 2i |
15999 | 15581 | |
16000 | 15582 | =item srand EXPR |
16001 | 15583 | X<srand> X<seed> X<randseed> |
16002 | 15584 | |
16003 | 15585 | =item srand |
16004 | 15586 | |
16005 | 15587 | =for Pod::Functions seed the random number generator |
16006 | 15588 | |
16007 | 15589 | =begin original |
16008 | 15590 | |
16009 | 15591 | Sets and returns the random number seed for the C<rand> operator. |
16010 | 15592 | |
16011 | 15593 | =end original |
16012 | 15594 | |
16013 | 15595 | C<rand> 演算子のためのシード値を設定して返します。 |
16014 | 15596 | |
16015 | 15597 | =begin original |
16016 | 15598 | |
16017 | 15599 | The point of the function is to "seed" the C<rand> function so that C<rand> |
16018 | 15600 | can produce a different sequence each time you run your program. When |
16019 | 15601 | called with a parameter, C<srand> uses that for the seed; otherwise it |
16020 | 15602 | (semi-)randomly chooses a seed. In either case, starting with Perl 5.14, |
16021 | 15603 | it returns the seed. To signal that your code will work I<only> on Perls |
16022 | 15604 | of a recent vintage: |
16023 | 15605 | |
16024 | 15606 | =end original |
16025 | 15607 | |
16026 | 15608 | この関数のポイントは、プログラムを実行するごとに C<rand> 関数が |
16027 | 15609 | 異なる乱数列を生成できるように C<rand> 関数の「種」を設定することです。 |
16028 | 15610 | C<srand> を引数付きで呼び出すと、これを種として使います; さもなければ |
16029 | 15611 | (だいたい)ランダムに種を選びます。 |
16030 | 15612 | どちらの場合でも、Perl 5.14 からは種を返します。 |
16031 | 15613 | 特定の時期の Perl I<でのみ> 動作することを知らせるには以下のようにします: |
16032 | 15614 | |
16033 | 15615 | use 5.014; # so srand returns the seed |
16034 | 15616 | |
16035 | 15617 | =begin original |
16036 | 15618 | |
16037 | 15619 | If C<srand()> is not called explicitly, it is called implicitly without a |
16038 | parameter at the first use of the C<rand> operator. | |
15620 | parameter at the first use of the C<rand> operator. However, this was not true | |
16039 | ||
15621 | of versions of Perl before 5.004, so if your script will run under older | |
16040 | ||
15622 | Perl versions, it should call C<srand>; otherwise most programs won't call | |
15623 | C<srand()> at all. | |
15624 | ||
15625 | =end original | |
15626 | ||
15627 | C<srand()> が明示的に呼び出されなかった場合、最初に C<rand> 演算子を使った | |
15628 | 時点で暗黙に引数なしで呼び出されます。 | |
15629 | しかし、これは Perl のバージョンが 5.004 より前では行われませんので、 | |
15630 | プログラムが古い Perl で実行される場合は、C<srand> を呼ぶべきです; | |
15631 | さもなければ、ほとんどのプログラムは C<srand()> を一切呼び出す必要は | |
15632 | ありません。 | |
15633 | ||
15634 | =begin original | |
15635 | ||
15636 | But there are a few situations in recent Perls where programs are likely to | |
15637 | want to call C<srand>. One is for generating predictable results generally for | |
16041 | 15638 | testing or debugging. There, you use C<srand($seed)>, with the same C<$seed> |
16042 | 15639 | each time. Another case is that you may want to call C<srand()> |
16043 | 15640 | after a C<fork()> to avoid child processes sharing the same seed value as the |
16044 | 15641 | parent (and consequently each other). |
16045 | 15642 | |
16046 | 15643 | =end original |
16047 | 15644 | |
16048 | C<srand()> が明示的に呼び出されなかった場合、最初に C<rand> 演算子を使った | |
16049 | 時点で暗黙に引数なしで呼び出されます。 | |
16050 | 15645 | しかし、最近の Perl でプログラムが C<srand> を呼び出したいであろう状況が |
16051 | 15646 | いくつかあります。 |
16052 | 15647 | 一つはテストやデバッグのために予測可能な結果を生成するためです。 |
16053 | 15648 | この場合、C<srand($seed)> (C<$seed> は毎回同じ値を使う) を使います。 |
16054 | 15649 | もう一つの場合としては、子プロセスが親や他の子プロセスと同じ種の値を |
16055 | 15650 | 共有することを避けるために、C<fork()> の後に C<srand()> を |
16056 | 15651 | 呼び出したいかもしれません。 |
16057 | 15652 | |
16058 | 15653 | =begin original |
16059 | 15654 | |
16060 | 15655 | Do B<not> call C<srand()> (i.e., without an argument) more than once per |
16061 | 15656 | process. The internal state of the random number generator should |
16062 | 15657 | contain more entropy than can be provided by any seed, so calling |
16063 | 15658 | C<srand()> again actually I<loses> randomness. |
16064 | 15659 | |
16065 | 15660 | =end original |
16066 | 15661 | |
16067 | 15662 | C<srand()> (引数なし)をプロセス中で複数回呼び出しては B<いけません>。 |
16068 | 15663 | 乱数生成器の内部状態はどのような種によって提供されるものよりも |
16069 | 15664 | 高いエントロピーを持っているので、C<srand()> を再び呼び出すと |
16070 | 15665 | ランダム性が I<失われます>。 |
16071 | 15666 | |
16072 | 15667 | =begin original |
16073 | 15668 | |
16074 | 15669 | Most implementations of C<srand> take an integer and will silently |
16075 | 15670 | truncate decimal numbers. This means C<srand(42)> will usually |
16076 | 15671 | produce the same results as C<srand(42.1)>. To be safe, always pass |
16077 | 15672 | C<srand> an integer. |
16078 | 15673 | |
16079 | 15674 | =end original |
16080 | 15675 | |
16081 | 15676 | C<srand> のほとんどの実装では整数を取り、小数を暗黙に切り捨てます。 |
16082 | 15677 | これは、C<srand(42)> は普通 C<srand(42.1)> と同じ結果になることを |
16083 | 15678 | 意味します。 |
16084 | 15679 | 安全のために、C<srand> には常に整数を渡しましょう。 |
16085 | 15680 | |
16086 | 15681 | =begin original |
16087 | 15682 | |
15683 | In versions of Perl prior to 5.004 the default seed was just the | |
15684 | current C<time>. This isn't a particularly good seed, so many old | |
15685 | programs supply their own seed value (often C<time ^ $$> or C<time ^ | |
15686 | ($$ + ($$ << 15))>), but that isn't necessary any more. | |
15687 | ||
15688 | =end original | |
15689 | ||
15690 | 5.004 以前の Perl では、デフォルトのシード値は現在の C<time> でした。 | |
15691 | これは特によいシード値ではありませんでしたので、 | |
15692 | 多くの古いプログラムは自力でシード値を指定しています | |
15693 | (C<time ^ $$> または C<time ^ ($$ + ($$ << 15))> がよく使われました)が、 | |
15694 | もはやこれは必要ありません。 | |
15695 | ||
15696 | =begin original | |
15697 | ||
15698 | Frequently called programs (like CGI scripts) that simply use | |
15699 | ||
15700 | =end original | |
15701 | ||
15702 | (CGI スクリプトのような)頻繁に呼び出されるプログラムで単純に | |
15703 | ||
15704 | time ^ $$ | |
15705 | ||
15706 | =begin original | |
15707 | ||
15708 | for a seed can fall prey to the mathematical property that | |
15709 | ||
15710 | =end original | |
15711 | ||
15712 | を種として使うと、3 回に 1 回は以下の数学特性 | |
15713 | ||
15714 | a^b == (a+1)^(b+1) | |
15715 | ||
15716 | =begin original | |
15717 | ||
15718 | one-third of the time. So don't do that. | |
15719 | ||
15720 | =end original | |
15721 | ||
15722 | の餌食になります。 | |
15723 | 従ってこのようなことはしてはいけません。 | |
15724 | ||
15725 | =begin original | |
15726 | ||
16088 | 15727 | A typical use of the returned seed is for a test program which has too many |
16089 | 15728 | combinations to test comprehensively in the time available to it each run. It |
16090 | 15729 | can test a random subset each time, and should there be a failure, log the seed |
16091 | 15730 | used for that run so that it can later be used to reproduce the same results. |
16092 | 15731 | |
16093 | 15732 | =end original |
16094 | 15733 | |
16095 | 15734 | 返された種の典型的な利用法は、実行毎のテストを利用可能な時間内に完全に |
16096 | 15735 | 行うには組み合わせが多すぎるテストプログラム用です。 |
16097 | 15736 | 毎回ランダムなサブセットをテストし、もし失敗したら、その実行で使った |
16098 | 15737 | 種をログに出力することで、後で同じ結果を再現するために使えます。 |
16099 | 15738 | |
16100 | 15739 | =begin original |
16101 | 15740 | |
16102 | 15741 | B<C<rand()> is not cryptographically secure. You should not rely |
16103 | 15742 | on it in security-sensitive situations.> As of this writing, a |
16104 | 15743 | number of third-party CPAN modules offer random number generators |
16105 | 15744 | intended by their authors to be cryptographically secure, |
16106 | 15745 | including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>, |
16107 | 15746 | and L<Math::TrulyRandom>. |
16108 | 15747 | |
16109 | 15748 | =end original |
16110 | 15749 | |
16111 | 15750 | B<C<rand()> は暗号学的に安全ではありません。 |
16112 | 15751 | セキュリティ的に重要な状況でこれに頼るべきではありません。> |
16113 | 15752 | これを書いている時点で、いくつかのサードパーティ CPAN モジュールが |
16114 | 15753 | 作者によって暗号学的に安全であることを目的とした乱数生成器を |
16115 | 15754 | 提供しています: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>, |
16116 | 15755 | L<Math::TrulyRandom> などです。 |
16117 | 15756 | |
16118 | 15757 | =item stat FILEHANDLE |
16119 | 15758 | X<stat> X<file, status> X<ctime> |
16120 | 15759 | |
16121 | 15760 | =item stat EXPR |
16122 | 15761 | |
16123 | 15762 | =item stat DIRHANDLE |
16124 | 15763 | |
16125 | 15764 | =item stat |
16126 | 15765 | |
16127 | 15766 | =for Pod::Functions get a file's status information |
16128 | 15767 | |
16129 | 15768 | =begin original |
16130 | 15769 | |
16131 | 15770 | Returns a 13-element list giving the status info for a file, either |
16132 | 15771 | the file opened via FILEHANDLE or DIRHANDLE, or named by EXPR. If EXPR is |
16133 | 15772 | omitted, it stats C<$_> (not C<_>!). Returns the empty list if C<stat> fails. Typically |
16134 | 15773 | used as follows: |
16135 | 15774 | |
16136 | 15775 | =end original |
16137 | 15776 | |
16138 | 15777 | FILEHANDLE か DIRHANDLE を通じてオープンされているファイルか、 |
16139 | 15778 | EXPR で指定されるファイルの情報を与える、13 要素のリストを返します。 |
16140 | 15779 | EXPR が省略されると、 C<$_> が用いられます (C<_> ではありません!)。 |
16141 | 15780 | C<stat> に失敗した場合には、空リストを返します。 |
16142 | 15781 | 普通は、以下のようにして使います: |
16143 | 15782 | |
16144 | 15783 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, |
16145 | 15784 | $atime,$mtime,$ctime,$blksize,$blocks) |
16146 | 15785 | = stat($filename); |
16147 | 15786 | |
16148 | 15787 | =begin original |
16149 | 15788 | |
16150 | 15789 | Not all fields are supported on all filesystem types. Here are the |
16151 | 15790 | meanings of the fields: |
16152 | 15791 | |
16153 | 15792 | =end original |
16154 | 15793 | |
16155 | 15794 | 全てのファイルシステムで全てのフィールドに対応しているわけではありません。 |
16156 | 15795 | フィールドの意味は以下の通りです。 |
16157 | 15796 | |
16158 | 15797 | =begin original |
16159 | 15798 | |
16160 | 15799 | 0 dev device number of filesystem |
16161 | 15800 | 1 ino inode number |
16162 | 15801 | 2 mode file mode (type and permissions) |
16163 | 15802 | 3 nlink number of (hard) links to the file |
16164 | 15803 | 4 uid numeric user ID of file's owner |
16165 | 15804 | 5 gid numeric group ID of file's owner |
16166 | 15805 | 6 rdev the device identifier (special files only) |
16167 | 15806 | 7 size total size of file, in bytes |
16168 | 15807 | 8 atime last access time in seconds since the epoch |
16169 | 15808 | 9 mtime last modify time in seconds since the epoch |
16170 | 15809 | 10 ctime inode change time in seconds since the epoch (*) |
16171 | 11 blksize preferred | |
15810 | 11 blksize preferred block size for file system I/O | |
16172 | | |
15811 | 12 blocks actual number of blocks allocated | |
16173 | 12 blocks actual number of system-specific blocks allocated | |
16174 | on disk (often, but not always, 512 bytes each) | |
16175 | 15812 | |
16176 | 15813 | =end original |
16177 | 15814 | |
16178 | 15815 | 0 dev ファイルシステムのデバイス番号 |
16179 | 15816 | 1 ino inode 番号 |
16180 | 15817 | 2 mode ファイルモード (タイプとパーミッション) |
16181 | 15818 | 3 nlink ファイルへの(ハード)リンクの数 |
16182 | 15819 | 4 uid ファイル所有者のユーザー ID の数値 |
16183 | 15820 | 5 gid ファイル所有者のグループ ID の数値 |
16184 | 15821 | 6 rdev デバイス識別子(特殊ファイルのみ) |
16185 | 15822 | 7 size ファイルサイズ(バイト単位) |
16186 | 15823 | 8 atime 紀元から、最後にアクセスされた時刻までの秒数 |
16187 | 15824 | 9 mtime 紀元から、最後に修正(modify)された時刻までの秒数 |
16188 | 15825 | 10 ctime 紀元から、inode 変更(change)された時刻までの秒数 (*) |
16189 | 11 blksize ファイル | |
15826 | 11 blksize ファイルシステム I/O に適したブロックサイズ | |
16190 | | |
15827 | 12 blocks 実際に割り当てられているブロックの数 | |
16191 | 12 blocks ディスクに割り当てたシステム依存のブロック(常にでは | |
16192 | ありませんがたいていはそれぞれ 512 バイト)の数 | |
16193 | 15828 | |
16194 | 15829 | =begin original |
16195 | 15830 | |
16196 | 15831 | (The epoch was at 00:00 January 1, 1970 GMT.) |
16197 | 15832 | |
16198 | 15833 | =end original |
16199 | 15834 | |
16200 | 15835 | (紀元は GMT で 1970/01/01 00:00:00。) |
16201 | 15836 | |
16202 | 15837 | =begin original |
16203 | 15838 | |
16204 | 15839 | (*) Not all fields are supported on all filesystem types. Notably, the |
16205 | 15840 | ctime field is non-portable. In particular, you cannot expect it to be a |
16206 | 15841 | "creation time"; see L<perlport/"Files and Filesystems"> for details. |
16207 | 15842 | |
16208 | 15843 | =end original |
16209 | 15844 | |
16210 | 15845 | (*) 全てのフィールドが全てのファイルシステムタイプで対応しているわけでは |
16211 | 15846 | ありません。 |
16212 | 15847 | 明らかに、ctime のフィールドは移植性がありません。 |
16213 | 15848 | 特に、これから「作成時刻」を想定することは出来ません; |
16214 | 15849 | 詳細については L<perlport/"Files and Filesystems"> を参照してください。 |
16215 | 15850 | |
16216 | 15851 | =begin original |
16217 | 15852 | |
16218 | 15853 | If C<stat> is passed the special filehandle consisting of an underline, no |
16219 | 15854 | stat is done, but the current contents of the stat structure from the |
16220 | 15855 | last C<stat>, C<lstat>, or filetest are returned. Example: |
16221 | 15856 | |
16222 | 15857 | =end original |
16223 | 15858 | |
16224 | 15859 | 下線だけの _ という特別なファイルハンドルを C<stat> に渡すと、 |
16225 | 15860 | 実際には stat を行なわず、stat 構造体に残っている |
16226 | 15861 | 前回の stat やファイルテストの情報が返されます。 |
16227 | 15862 | 例: |
16228 | 15863 | |
16229 | 15864 | if (-x $file && (($d) = stat(_)) && $d < 0) { |
16230 | 15865 | print "$file is executable NFS file\n"; |
16231 | 15866 | } |
16232 | 15867 | |
16233 | 15868 | =begin original |
16234 | 15869 | |
16235 | 15870 | (This works on machines only for which the device number is negative |
16236 | 15871 | under NFS.) |
16237 | 15872 | |
16238 | 15873 | =end original |
16239 | 15874 | |
16240 | (これは、NFS のもとでデバイス番号が負になるマシンで | |
15875 | (これは、NFS のもとでデバイス番号が負になるマシンで | |
15876 | のみ動作します。) | |
16241 | 15877 | |
16242 | 15878 | =begin original |
16243 | 15879 | |
16244 | 15880 | Because the mode contains both the file type and its permissions, you |
16245 | 15881 | should mask off the file type portion and (s)printf using a C<"%o"> |
16246 | 15882 | if you want to see the real permissions. |
16247 | 15883 | |
16248 | 15884 | =end original |
16249 | 15885 | |
16250 | 15886 | モードにはファイルタイプとその権限の両方が含まれているので、 |
16251 | 15887 | 本当の権限を見たい場合は、(s)printf で C<"%"> を使うことで |
16252 | 15888 | ファイルタイプをマスクするべきです。 |
16253 | 15889 | |
16254 | 15890 | $mode = (stat($filename))[2]; |
16255 | 15891 | printf "Permissions are %04o\n", $mode & 07777; |
16256 | 15892 | |
16257 | 15893 | =begin original |
16258 | 15894 | |
16259 | 15895 | In scalar context, C<stat> returns a boolean value indicating success |
16260 | 15896 | or failure, and, if successful, sets the information associated with |
16261 | 15897 | the special filehandle C<_>. |
16262 | 15898 | |
16263 | 15899 | =end original |
16264 | 15900 | |
16265 | 15901 | スカラコンテキストでは、C<stat> は成功か失敗を表す真偽値を返し、 |
16266 | 15902 | 成功した場合は、特別なファイルハンドル C<_> に結び付けられた |
16267 | 15903 | 情報をセットします。 |
16268 | 15904 | |
16269 | 15905 | =begin original |
16270 | 15906 | |
16271 | 15907 | The L<File::stat> module provides a convenient, by-name access mechanism: |
16272 | 15908 | |
16273 | 15909 | =end original |
16274 | 15910 | |
16275 | 15911 | L<File::stat> モジュールは、便利な名前によるアクセス機構を提供します。 |
16276 | 15912 | |
16277 | 15913 | use File::stat; |
16278 | 15914 | $sb = stat($filename); |
16279 | 15915 | printf "File is %s, size is %s, perm %04o, mtime %s\n", |
16280 | 15916 | $filename, $sb->size, $sb->mode & 07777, |
16281 | 15917 | scalar localtime $sb->mtime; |
16282 | 15918 | |
16283 | 15919 | =begin original |
16284 | 15920 | |
16285 | 15921 | You can import symbolic mode constants (C<S_IF*>) and functions |
16286 | 15922 | (C<S_IS*>) from the Fcntl module: |
16287 | 15923 | |
16288 | 15924 | =end original |
16289 | 15925 | |
16290 | 15926 | モード定数 (C<S_IF*>) と関数 (C<S_IS*>) を Fcntl モジュールから |
16291 | 15927 | インポートできます。 |
16292 | 15928 | |
16293 | 15929 | use Fcntl ':mode'; |
16294 | 15930 | |
16295 | 15931 | $mode = (stat($filename))[2]; |
16296 | 15932 | |
16297 | 15933 | $user_rwx = ($mode & S_IRWXU) >> 6; |
16298 | 15934 | $group_read = ($mode & S_IRGRP) >> 3; |
16299 | 15935 | $other_execute = $mode & S_IXOTH; |
16300 | 15936 | |
16301 | 15937 | printf "Permissions are %04o\n", S_IMODE($mode), "\n"; |
16302 | 15938 | |
16303 | 15939 | $is_setuid = $mode & S_ISUID; |
16304 | 15940 | $is_directory = S_ISDIR($mode); |
16305 | 15941 | |
16306 | 15942 | =begin original |
16307 | 15943 | |
16308 | 15944 | You could write the last two using the C<-u> and C<-d> operators. |
16309 | 15945 | Commonly available C<S_IF*> constants are: |
16310 | 15946 | |
16311 | 15947 | =end original |
16312 | 15948 | |
16313 | 15949 | 最後の二つは C<-u> と C<-d> 演算子を使っても書けます。 |
16314 | 15950 | 一般に利用可能な C<S_IF*> 定数は以下のものです。 |
16315 | 15951 | |
16316 | 15952 | # Permissions: read, write, execute, for user, group, others. |
16317 | 15953 | |
16318 | 15954 | S_IRWXU S_IRUSR S_IWUSR S_IXUSR |
16319 | 15955 | S_IRWXG S_IRGRP S_IWGRP S_IXGRP |
16320 | 15956 | S_IRWXO S_IROTH S_IWOTH S_IXOTH |
16321 | 15957 | |
16322 | 15958 | # Setuid/Setgid/Stickiness/SaveText. |
16323 | 15959 | # Note that the exact meaning of these is system-dependent. |
16324 | 15960 | |
16325 | 15961 | S_ISUID S_ISGID S_ISVTX S_ISTXT |
16326 | 15962 | |
16327 | 15963 | # File types. Not all are necessarily available on |
16328 | 15964 | # your system. |
16329 | 15965 | |
16330 | 15966 | S_IFREG S_IFDIR S_IFLNK S_IFBLK S_IFCHR |
16331 | 15967 | S_IFIFO S_IFSOCK S_IFWHT S_ENFMT |
16332 | 15968 | |
16333 | 15969 | # The following are compatibility aliases for S_IRUSR, |
16334 | 15970 | # S_IWUSR, and S_IXUSR. |
16335 | 15971 | |
16336 | 15972 | S_IREAD S_IWRITE S_IEXEC |
16337 | 15973 | |
16338 | 15974 | =begin original |
16339 | 15975 | |
16340 | 15976 | and the C<S_IF*> functions are |
16341 | 15977 | |
16342 | 15978 | =end original |
16343 | 15979 | |
16344 | 15980 | 一般に利用可能な C<S_IF*> 関数は以下のものです。 |
16345 | 15981 | |
16346 | 15982 | S_IMODE($mode) the part of $mode containing the permission |
16347 | 15983 | bits and the setuid/setgid/sticky bits |
16348 | 15984 | |
16349 | 15985 | S_IFMT($mode) the part of $mode containing the file type |
16350 | 15986 | which can be bit-anded with (for example) |
16351 | 15987 | S_IFREG or with the following functions |
16352 | 15988 | |
16353 | 15989 | # The operators -f, -d, -l, -b, -c, -p, and -S. |
16354 | 15990 | |
16355 | 15991 | S_ISREG($mode) S_ISDIR($mode) S_ISLNK($mode) |
16356 | 15992 | S_ISBLK($mode) S_ISCHR($mode) S_ISFIFO($mode) S_ISSOCK($mode) |
16357 | 15993 | |
16358 | 15994 | # No direct -X operator counterpart, but for the first one |
16359 | 15995 | # the -g operator is often equivalent. The ENFMT stands for |
16360 | 15996 | # record flocking enforcement, a platform-dependent feature. |
16361 | 15997 | |
16362 | 15998 | S_ISENFMT($mode) S_ISWHT($mode) |
16363 | 15999 | |
16364 | 16000 | =begin original |
16365 | 16001 | |
16366 | 16002 | See your native chmod(2) and stat(2) documentation for more details |
16367 | 16003 | about the C<S_*> constants. To get status info for a symbolic link |
16368 | 16004 | instead of the target file behind the link, use the C<lstat> function. |
16369 | 16005 | |
16370 | 16006 | =end original |
16371 | 16007 | |
16372 | 16008 | C<S_*> 定数に関する詳細についてはネイティブの chmod(2) と stat(2) の |
16373 | 16009 | ドキュメントを参照してください。 |
16374 | 16010 | リンクの先にあるファイルではなく、シンボリックリンクそのものの情報を |
16375 | 16011 | 得たい場合は、C<lstat> 関数を使ってください。 |
16376 | 16012 | |
16377 | 16013 | =begin original |
16378 | 16014 | |
16379 | 16015 | Portability issues: L<perlport/stat>. |
16380 | 16016 | |
16381 | 16017 | =end original |
16382 | 16018 | |
16383 | 16019 | 移植性の問題: L<perlport/stat>。 |
16384 | 16020 | |
16385 | =item state | |
16021 | =item state EXPR | |
16386 | 16022 | X<state> |
16387 | 16023 | |
16388 | =item state TYPE | |
16024 | =item state TYPE EXPR | |
16389 | 16025 | |
16390 | =item state | |
16026 | =item state EXPR : ATTRS | |
16391 | 16027 | |
16392 | =item state TYPE | |
16028 | =item state TYPE EXPR : ATTRS | |
16393 | 16029 | |
16394 | 16030 | =for Pod::Functions +state declare and assign a persistent lexical variable |
16395 | 16031 | |
16396 | 16032 | =begin original |
16397 | 16033 | |
16398 | 16034 | C<state> declares a lexically scoped variable, just like C<my>. |
16399 | 16035 | However, those variables will never be reinitialized, contrary to |
16400 | 16036 | lexical variables that are reinitialized each time their enclosing block |
16401 | 16037 | is entered. |
16402 | 16038 | See L<perlsub/"Persistent Private Variables"> for details. |
16403 | 16039 | |
16404 | 16040 | =end original |
16405 | 16041 | |
16406 | 16042 | C<state> はちょうど C<my> と同様に、レキシカルなスコープの変数を宣言します。 |
16407 | 16043 | しかし、レキシカル変数がブロックに入る毎に再初期化されるのと異なり、 |
16408 | 16044 | この変数は決して再初期化されません。 |
16409 | 16045 | 詳しくは L<perlsub/"Persistent Private Variables"> を参照してください。 |
16410 | 16046 | |
16411 | 16047 | =begin original |
16412 | 16048 | |
16413 | If more than one variable is listed, the list must be placed in | |
16414 | parentheses. With a parenthesised list, C<undef> can be used as a | |
16415 | dummy placeholder. However, since initialization of state variables in | |
16416 | list context is currently not possible this would serve no purpose. | |
16417 | ||
16418 | =end original | |
16419 | ||
16420 | 複数の変数を指定する場合、かっこで囲まなければなりません。 | |
16421 | かっこで囲まれたリストでは、C<undef> はダミーのプレースホルダとして使えます。 | |
16422 | しかし、リストコンテキストでの state 変数の初期化は現在のところできないので、 | |
16423 | これは無意味です。 | |
16424 | ||
16425 | =begin original | |
16426 | ||
16427 | 16049 | C<state> variables are enabled only when the C<use feature "state"> pragma |
16428 | 16050 | is in effect, unless the keyword is written as C<CORE::state>. |
16429 | 16051 | See also L<feature>. |
16430 | 16052 | |
16431 | 16053 | =end original |
16432 | 16054 | |
16433 | 16055 | C<state> 変数は、キーワードが C<CORE::state> として書かれていない限り、 |
16434 | 16056 | C<feature 'state'> プラグマが有効の場合のみ有効です。 |
16435 | 16057 | L<feature> も参照してください。 |
16436 | 16058 | |
16437 | 16059 | =item study SCALAR |
16438 | 16060 | X<study> |
16439 | 16061 | |
16440 | 16062 | =item study |
16441 | 16063 | |
16442 | 16064 | =for Pod::Functions optimize input data for repeated searches |
16443 | 16065 | |
16444 | 16066 | =begin original |
16445 | 16067 | |
16446 | 16068 | Takes extra time to study SCALAR (C<$_> if unspecified) in anticipation of |
16447 | 16069 | doing many pattern matches on the string before it is next modified. |
16448 | 16070 | This may or may not save time, depending on the nature and number of |
16449 | 16071 | patterns you are searching and the distribution of character |
16450 | 16072 | frequencies in the string to be searched; you probably want to compare |
16451 | 16073 | run times with and without it to see which is faster. Those loops |
16452 | 16074 | that scan for many short constant strings (including the constant |
16453 | 16075 | parts of more complex patterns) will benefit most. |
16454 | 16076 | (The way C<study> works is this: a linked list of every |
16455 | 16077 | character in the string to be searched is made, so we know, for |
16456 | 16078 | example, where all the C<'k'> characters are. From each search string, |
16457 | 16079 | the rarest character is selected, based on some static frequency tables |
16458 | 16080 | constructed from some C programs and English text. Only those places |
16459 | 16081 | that contain this "rarest" character are examined.) |
16460 | 16082 | |
16461 | 16083 | =end original |
16462 | 16084 | |
16463 | 16085 | 次に変更される前に、何回も文字列に対するパターンマッチを行なう |
16464 | 16086 | アプリケーションで、そのような文字列 SCALAR(省略時には C<$_>) を予め |
16465 | 16087 | 学習しておきます。 |
16466 | 16088 | これは、検索のために、どのようなパターンを何回使うかによって、また、 |
16467 | 16089 | 検索される文字列内の文字頻度の分布によって、時間を節約することに |
16468 | 16090 | なるかもしれませんし、逆に浪費することになるかもしれません; 予習をした場合と |
16469 | 16091 | しない場合の実行時間を比較して、どちらが速いか調べることが必要でしょう。 |
16470 | 16092 | 短い固定文字列 (複雑なパターンの固定部分を含みます) をたくさん検索する |
16471 | 16093 | ループで、もっとも効果があるでしょう。 |
16472 | 16094 | (この C<study> の仕組みは、まず、検索される文字列内のすべての文字の |
16473 | 16095 | リンクされたリストが作られ、たとえば、すべての C<'k'> がどこにあるかが |
16474 | 16096 | わかるようになります。 |
16475 | 16097 | 各々の検索文字列から、C プログラムや英語のテキストから作られた頻度の |
16476 | 16098 | 統計情報に基づいて、もっとも珍しい文字が選ばれます。 |
16477 | 16099 | この「珍しい」文字を含む場所だけが調べられるのです。) |
16478 | 16100 | |
16479 | 16101 | =begin original |
16480 | 16102 | |
16481 | 16103 | For example, here is a loop that inserts index producing entries |
16482 | 16104 | before any line containing a certain pattern: |
16483 | 16105 | |
16484 | 16106 | =end original |
16485 | 16107 | |
16486 | 16108 | たとえば、特定のパターンを含む行の前にインデックスを |
16487 | 16109 | 付けるエントリを入れる例を示します。 |
16488 | 16110 | |
16489 | 16111 | while (<>) { |
16490 | 16112 | study; |
16491 | 16113 | print ".IX foo\n" if /\bfoo\b/; |
16492 | 16114 | print ".IX bar\n" if /\bbar\b/; |
16493 | 16115 | print ".IX blurfl\n" if /\bblurfl\b/; |
16494 | 16116 | # ... |
16495 | 16117 | print; |
16496 | 16118 | } |
16497 | 16119 | |
16498 | 16120 | =begin original |
16499 | 16121 | |
16500 | 16122 | In searching for C</\bfoo\b/>, only locations in C<$_> that contain C<f> |
16501 | 16123 | will be looked at, because C<f> is rarer than C<o>. In general, this is |
16502 | 16124 | a big win except in pathological cases. The only question is whether |
16503 | 16125 | it saves you more time than it took to build the linked list in the |
16504 | 16126 | first place. |
16505 | 16127 | |
16506 | 16128 | =end original |
16507 | 16129 | |
16508 | 16130 | C<f> は C<o> よりも珍しいので、C</\bfoo\b/> を探すとき、C<$_> で C<f> を |
16509 | 16131 | 含む場所だけが探されます。 |
16510 | 16132 | 一般に、病的な場合を除いて、かなりの結果が得られます。 |
16511 | 16133 | 唯一の問題は、節約できる時間が、最初にリンクリストを作る |
16512 | 16134 | 時間よりも多いかどうかです、 |
16513 | 16135 | |
16514 | 16136 | =begin original |
16515 | 16137 | |
16516 | 16138 | Note that if you have to look for strings that you don't know till |
16517 | 16139 | runtime, you can build an entire loop as a string and C<eval> that to |
16518 | 16140 | avoid recompiling all your patterns all the time. Together with |
16519 | 16141 | undefining C<$/> to input entire files as one record, this can be quite |
16520 | 16142 | fast, often faster than specialized programs like fgrep(1). The following |
16521 | 16143 | scans a list of files (C<@files>) for a list of words (C<@words>), and prints |
16522 | 16144 | out the names of those files that contain a match: |
16523 | 16145 | |
16524 | 16146 | =end original |
16525 | 16147 | |
16526 | 16148 | 実行時まで、探そうとする文字列がわからないときには、 |
16527 | 16149 | ループ全体を文字列として組み立てて、C<eval> すれば、 |
16528 | 16150 | いつも、すべてのパターンを再コンパイルするという事態は避けられます。 |
16529 | 16151 | ファイル全体を一つのレコードとして入力するために、 |
16530 | 16152 | C<$/> を未定義にすれば、かなり速くなり、 |
16531 | 16153 | 多くの場合 fgrep(1) のような専用のプログラムより速くなります。 |
16532 | 16154 | 以下の例は、ファイルのリスト (C<@files>) から単語のリスト (C<@words>) を |
16533 | 16155 | 探して、マッチするものがあったファイル名を出力します。 |
16534 | 16156 | |
16535 | 16157 | $search = 'while (<>) { study;'; |
16536 | 16158 | foreach $word (@words) { |
16537 | 16159 | $search .= "++\$seen{\$ARGV} if /\\b$word\\b/;\n"; |
16538 | 16160 | } |
16539 | 16161 | $search .= "}"; |
16540 | 16162 | @ARGV = @files; |
16541 | 16163 | undef $/; |
16542 | 16164 | eval $search; # this screams |
16543 | 16165 | $/ = "\n"; # put back to normal input delimiter |
16544 | 16166 | foreach $file (sort keys(%seen)) { |
16545 | 16167 | print $file, "\n"; |
16546 | 16168 | } |
16547 | 16169 | |
16548 | 16170 | =item sub NAME BLOCK |
16549 | 16171 | X<sub> |
16550 | 16172 | |
16551 | 16173 | =item sub NAME (PROTO) BLOCK |
16552 | 16174 | |
16553 | 16175 | =item sub NAME : ATTRS BLOCK |
16554 | 16176 | |
16555 | 16177 | =item sub NAME (PROTO) : ATTRS BLOCK |
16556 | 16178 | |
16557 | 16179 | =for Pod::Functions declare a subroutine, possibly anonymously |
16558 | 16180 | |
16559 | 16181 | =begin original |
16560 | 16182 | |
16561 | 16183 | This is subroutine definition, not a real function I<per se>. Without a |
16562 | 16184 | BLOCK it's just a forward declaration. Without a NAME, it's an anonymous |
16563 | 16185 | function declaration, so does return a value: the CODE ref of the closure |
16564 | 16186 | just created. |
16565 | 16187 | |
16566 | 16188 | =end original |
16567 | 16189 | |
16568 | 16190 | これはサブルーチン定義であり、I<本質的には> 実際の関数ではありません。 |
16569 | 16191 | BLOCK なしの場合、これは単に前方宣言です。 |
16570 | 16192 | NAME なしの場合は、無名関数定義であり、値(作成したブロックの |
16571 | 16193 | コードリファレンス)を返します: 単にクロージャの CODE リファレンスが |
16572 | 16194 | 作成されます。 |
16573 | 16195 | |
16574 | 16196 | =begin original |
16575 | 16197 | |
16576 | 16198 | See L<perlsub> and L<perlref> for details about subroutines and |
16577 | 16199 | references; see L<attributes> and L<Attribute::Handlers> for more |
16578 | 16200 | information about attributes. |
16579 | 16201 | |
16580 | 16202 | =end original |
16581 | 16203 | |
16582 | 16204 | サブルーチンとリファレンスに関する詳細については、L<perlsub> と |
16583 | 16205 | L<perlref> を参照してください; 属性に関する更なる情報については |
16584 | 16206 | L<attributes> と L<Attribute::Handlers> を参照してください。 |
16585 | 16207 | |
16586 | 16208 | =item __SUB__ |
16587 | 16209 | X<__SUB__> |
16588 | 16210 | |
16589 | 16211 | =for Pod::Functions +current_sub the current subroutine, or C<undef> if not in a subroutine |
16590 | 16212 | |
16591 | 16213 | =begin original |
16592 | 16214 | |
16593 | A special token that returns a reference to the current subroutine, or | |
16215 | A special token that returns the a reference to the current subroutine, or | |
16594 | 16216 | C<undef> outside of a subroutine. |
16595 | 16217 | |
16596 | 16218 | =end original |
16597 | 16219 | |
16598 | 16220 | 現在のサブルーチンのリファレンスを返す特殊トークン; サブルーチンの外側では |
16599 | 16221 | C<undef>。 |
16600 | 16222 | |
16601 | 16223 | =begin original |
16602 | 16224 | |
16603 | The behaviour of C<__SUB__> within a regex code block (such as C</(?{...})/>) | |
16604 | is subject to change. | |
16605 | ||
16606 | =end original | |
16607 | ||
16608 | (C</(?{...})/> のような) 正規表現コードブロックの中の C<__SUB__> の振る舞いは | |
16609 | 変更される予定です。 | |
16610 | ||
16611 | =begin original | |
16612 | ||
16613 | 16225 | This token is only available under C<use v5.16> or the "current_sub" |
16614 | 16226 | feature. See L<feature>. |
16615 | 16227 | |
16616 | 16228 | =end original |
16617 | 16229 | |
16618 | 16230 | このトークンは C<use v5.16> または "current_sub" 機能でのみ利用可能です。 |
16619 | 16231 | L<feature> を参照してください。 |
16620 | 16232 | |
16621 | 16233 | =item substr EXPR,OFFSET,LENGTH,REPLACEMENT |
16622 | 16234 | X<substr> X<substring> X<mid> X<left> X<right> |
16623 | 16235 | |
16624 | 16236 | =item substr EXPR,OFFSET,LENGTH |
16625 | 16237 | |
16626 | 16238 | =item substr EXPR,OFFSET |
16627 | 16239 | |
16628 | 16240 | =for Pod::Functions get or alter a portion of a string |
16629 | 16241 | |
16630 | 16242 | =begin original |
16631 | 16243 | |
16632 | 16244 | Extracts a substring out of EXPR and returns it. First character is at |
16633 | 16245 | offset zero. If OFFSET is negative, starts |
16634 | 16246 | that far back from the end of the string. If LENGTH is omitted, returns |
16635 | 16247 | everything through the end of the string. If LENGTH is negative, leaves that |
16636 | 16248 | many characters off the end of the string. |
16637 | 16249 | |
16638 | 16250 | =end original |
16639 | 16251 | |
16640 | 16252 | EXPR から、部分文字列を取り出して返します。 |
16641 | 16253 | 最初の文字がオフセット 0 となります。 |
16642 | 16254 | OFFSET に負の値を設定すると、EXPR の終わりからのオフセットとなります。 |
16643 | 16255 | LENGTH を省略すると、EXPR の最後まですべてが返されます。 |
16644 | 16256 | LENGTH が負の値だと、文字列の最後から指定された数だけ文字を取り除きます。 |
16645 | 16257 | |
16646 | 16258 | my $s = "The black cat climbed the green tree"; |
16647 | 16259 | my $color = substr $s, 4, 5; # black |
16648 | 16260 | my $middle = substr $s, 4, -11; # black cat climbed the |
16649 | 16261 | my $end = substr $s, 14; # climbed the green tree |
16650 | 16262 | my $tail = substr $s, -4; # tree |
16651 | 16263 | my $z = substr $s, -4, 2; # tr |
16652 | 16264 | |
16653 | 16265 | =begin original |
16654 | 16266 | |
16655 | 16267 | You can use the substr() function as an lvalue, in which case EXPR |
16656 | 16268 | must itself be an lvalue. If you assign something shorter than LENGTH, |
16657 | 16269 | the string will shrink, and if you assign something longer than LENGTH, |
16658 | 16270 | the string will grow to accommodate it. To keep the string the same |
16659 | 16271 | length, you may need to pad or chop your value using C<sprintf>. |
16660 | 16272 | |
16661 | 16273 | =end original |
16662 | 16274 | |
16663 | 16275 | substr() を左辺値として使用することも可能で、その場合には、 |
16664 | 16276 | EXPR が自身左辺値でなければなりません。 |
16665 | 16277 | LENGTH より短いものを代入したときには、 |
16666 | 16278 | EXPR は短くなり、LENGTH より長いものを代入したときには、 |
16667 | 16279 | EXPR はそれに合わせて伸びることになります。 |
16668 | 16280 | EXPR の長さを一定に保つためには、C<sprintf> を使って、 |
16669 | 16281 | 代入する値の長さを調整することが、必要になるかもしれません。 |
16670 | 16282 | |
16671 | 16283 | =begin original |
16672 | 16284 | |
16673 | 16285 | If OFFSET and LENGTH specify a substring that is partly outside the |
16674 | 16286 | string, only the part within the string is returned. If the substring |
16675 | 16287 | is beyond either end of the string, substr() returns the undefined |
16676 | 16288 | value and produces a warning. When used as an lvalue, specifying a |
16677 | 16289 | substring that is entirely outside the string raises an exception. |
16678 | 16290 | Here's an example showing the behavior for boundary cases: |
16679 | 16291 | |
16680 | 16292 | =end original |
16681 | 16293 | |
16682 | 16294 | OFFSET と LENGTH として文字列の外側を含むような部分文字列が指定されると、 |
16683 | 16295 | 文字列の内側の部分だけが返されます。 |
16684 | 16296 | 部分文字列が文字列の両端の外側の場合、substr() は未定義値を返し、 |
16685 | 16297 | 警告が出力されます。 |
16686 | 16298 | 左辺値として使った場合、文字列の完全に外側を部分文字列として指定すると |
16687 | 16299 | 例外が発生します。 |
16688 | 16300 | 以下は境界条件の振る舞いを示す例です: |
16689 | 16301 | |
16690 | 16302 | my $name = 'fred'; |
16691 | 16303 | substr($name, 4) = 'dy'; # $name is now 'freddy' |
16692 | 16304 | my $null = substr $name, 6, 2; # returns "" (no warning) |
16693 | 16305 | my $oops = substr $name, 7; # returns undef, with warning |
16694 | 16306 | substr($name, 7) = 'gap'; # raises an exception |
16695 | 16307 | |
16696 | 16308 | =begin original |
16697 | 16309 | |
16698 | 16310 | An alternative to using substr() as an lvalue is to specify the |
16699 | 16311 | replacement string as the 4th argument. This allows you to replace |
16700 | 16312 | parts of the EXPR and return what was there before in one operation, |
16701 | 16313 | just as you can with splice(). |
16702 | 16314 | |
16703 | 16315 | =end original |
16704 | 16316 | |
16705 | 16317 | substr() を左辺値として使う代わりの方法は、置き換える文字列を 4 番目の |
16706 | 16318 | 引数として指定することです。 |
16707 | 16319 | これにより、EXPR の一部を置き換え、置き換える前が何であったかを返す、 |
16708 | 16320 | ということを(splice() と同様) 1 動作で行えます。 |
16709 | 16321 | |
16710 | 16322 | my $s = "The black cat climbed the green tree"; |
16711 | 16323 | my $z = substr $s, 14, 7, "jumped from"; # climbed |
16712 | 16324 | # $s is now "The black cat jumped from the green tree" |
16713 | 16325 | |
16714 | 16326 | =begin original |
16715 | 16327 | |
16716 | 16328 | Note that the lvalue returned by the three-argument version of substr() acts as |
16717 | 16329 | a 'magic bullet'; each time it is assigned to, it remembers which part |
16718 | 16330 | of the original string is being modified; for example: |
16719 | 16331 | |
16720 | 16332 | =end original |
16721 | 16333 | |
16722 | 16334 | 3 引数の substr() によって返された左辺値は「魔法の弾丸」のように振舞うことに |
16723 | 16335 | 注意してください; これが代入される毎に、元の文字列のどの部分が変更されたかが |
16724 | 16336 | 思い出されます; 例えば: |
16725 | 16337 | |
16726 | 16338 | $x = '1234'; |
16727 | 16339 | for (substr($x,1,2)) { |
16728 | 16340 | $_ = 'a'; print $x,"\n"; # prints 1a4 |
16729 | 16341 | $_ = 'xyz'; print $x,"\n"; # prints 1xyz4 |
16730 | 16342 | $x = '56789'; |
16731 | 16343 | $_ = 'pq'; print $x,"\n"; # prints 5pq9 |
16732 | 16344 | } |
16733 | 16345 | |
16734 | 16346 | =begin original |
16735 | 16347 | |
16736 | 16348 | With negative offsets, it remembers its position from the end of the string |
16737 | 16349 | when the target string is modified: |
16738 | 16350 | |
16739 | 16351 | =end original |
16740 | 16352 | |
16741 | 16353 | 負数のオフセットの場合、ターゲット文字列が修正されたときに文字列の末尾からの |
16742 | 16354 | 位置を覚えます: |
16743 | 16355 | |
16744 | 16356 | $x = '1234'; |
16745 | 16357 | for (substr($x, -3, 2)) { |
16746 | 16358 | $_ = 'a'; print $x,"\n"; # prints 1a4, as above |
16747 | 16359 | $x = 'abcdefg'; |
16748 | 16360 | print $_,"\n"; # prints f |
16749 | 16361 | } |
16750 | 16362 | |
16751 | 16363 | =begin original |
16752 | 16364 | |
16753 | 16365 | Prior to Perl version 5.10, the result of using an lvalue multiple times was |
16754 | 16366 | unspecified. Prior to 5.16, the result with negative offsets was |
16755 | 16367 | unspecified. |
16756 | 16368 | |
16757 | 16369 | =end original |
16758 | 16370 | |
16759 | 16371 | バージョン 5.10 より前の Perl では、複数回左辺値を使った場合の結果は |
16760 | 16372 | 未定義でした。 |
16761 | 16373 | 5.16 より前では、負のオフセットの結果は未定義です。 |
16762 | 16374 | |
16763 | 16375 | =item symlink OLDFILE,NEWFILE |
16764 | 16376 | X<symlink> X<link> X<symbolic link> X<link, symbolic> |
16765 | 16377 | |
16766 | 16378 | =for Pod::Functions create a symbolic link to a file |
16767 | 16379 | |
16768 | 16380 | =begin original |
16769 | 16381 | |
16770 | 16382 | Creates a new filename symbolically linked to the old filename. |
16771 | 16383 | Returns C<1> for success, C<0> otherwise. On systems that don't support |
16772 | 16384 | symbolic links, raises an exception. To check for that, |
16773 | 16385 | use eval: |
16774 | 16386 | |
16775 | 16387 | =end original |
16776 | 16388 | |
16777 | 16389 | NEWFILE として、OLDFILE へのシンボリックリンクを生成します。 |
16778 | 16390 | 成功時には C<1> を返し、失敗時には C<0> を返します。 |
16779 | 16391 | シンボリックリンクをサポートしていないシステムでは、 |
16780 | 16392 | 例外が発生します。 |
16781 | 16393 | これをチェックするには、eval を使用します: |
16782 | 16394 | |
16783 | 16395 | $symlink_exists = eval { symlink("",""); 1 }; |
16784 | 16396 | |
16785 | 16397 | =begin original |
16786 | 16398 | |
16787 | 16399 | Portability issues: L<perlport/symlink>. |
16788 | 16400 | |
16789 | 16401 | =end original |
16790 | 16402 | |
16791 | 16403 | 移植性の問題: L<perlport/symlink>。 |
16792 | 16404 | |
16793 | 16405 | =item syscall NUMBER, LIST |
16794 | 16406 | X<syscall> X<system call> |
16795 | 16407 | |
16796 | 16408 | =for Pod::Functions execute an arbitrary system call |
16797 | 16409 | |
16798 | 16410 | =begin original |
16799 | 16411 | |
16800 | 16412 | Calls the system call specified as the first element of the list, |
16801 | 16413 | passing the remaining elements as arguments to the system call. If |
16802 | 16414 | unimplemented, raises an exception. The arguments are interpreted |
16803 | 16415 | as follows: if a given argument is numeric, the argument is passed as |
16804 | 16416 | an int. If not, the pointer to the string value is passed. You are |
16805 | 16417 | responsible to make sure a string is pre-extended long enough to |
16806 | 16418 | receive any result that might be written into a string. You can't use a |
16807 | 16419 | string literal (or other read-only string) as an argument to C<syscall> |
16808 | 16420 | because Perl has to assume that any string pointer might be written |
16809 | 16421 | through. If your |
16810 | 16422 | integer arguments are not literals and have never been interpreted in a |
16811 | 16423 | numeric context, you may need to add C<0> to them to force them to look |
16812 | 16424 | like numbers. This emulates the C<syswrite> function (or vice versa): |
16813 | 16425 | |
16814 | 16426 | =end original |
16815 | 16427 | |
16816 | 16428 | LIST の最初の要素で指定するシステムコールを、残りの要素をその |
16817 | 16429 | システムコールの引数として呼び出します。 |
16818 | 16430 | 実装されていない場合には、例外が発生します。 |
16819 | 16431 | 引数は、以下のように解釈されます: 引数が数字であれば、int として |
16820 | 16432 | 引数を渡します。 |
16821 | 16433 | そうでなければ、文字列値へのポインタが渡されます。 |
16822 | 16434 | 文字列に結果を受け取るときには、その結果を受け取るのに十分なくらいに、 |
16823 | 16435 | 文字列を予め伸ばしておく必要があります。 |
16824 | 16436 | 文字列リテラル(あるいはその他の読み込み専用の文字列)を C<syscall> の |
16825 | 16437 | 引数として使うことはできません; Perl は全ての文字列ポインタは書き込まれると |
16826 | 16438 | 仮定しなければならないからです。 |
16827 | 整数引数が、リテラルでなく、数値コンテキストで評価されたことの | |
16439 | 整数引数が、リテラルでなく、数値コンテキストで評価されたことの | |
16828 | ものであれば、数値として解釈されるように、 | |
16440 | ないものであれば、数値として解釈されるように、 | |
16829 | 16441 | C<0> を足しておく必要があるかもしれません。 |
16830 | 16442 | 以下は C<syswrite> 関数(あるいはその逆)をエミュレートします。 |
16831 | 16443 | |
16832 | 16444 | require 'syscall.ph'; # may need to run h2ph |
16833 | 16445 | $s = "hi there\n"; |
16834 | 16446 | syscall(&SYS_write, fileno(STDOUT), $s, length $s); |
16835 | 16447 | |
16836 | 16448 | =begin original |
16837 | 16449 | |
16838 | 16450 | Note that Perl supports passing of up to only 14 arguments to your syscall, |
16839 | 16451 | which in practice should (usually) suffice. |
16840 | 16452 | |
16841 | 16453 | =end original |
16842 | 16454 | |
16843 | 16455 | Perl は、システムコールに最大 14 個の引数しか渡せませんが、 |
16844 | 16456 | (普通は)実用上問題はないでしょう。 |
16845 | 16457 | |
16846 | 16458 | =begin original |
16847 | 16459 | |
16848 | 16460 | Syscall returns whatever value returned by the system call it calls. |
16849 | 16461 | If the system call fails, C<syscall> returns C<-1> and sets C<$!> (errno). |
16850 | 16462 | Note that some system calls I<can> legitimately return C<-1>. The proper |
16851 | 16463 | way to handle such calls is to assign C<$!=0> before the call, then |
16852 | 16464 | check the value of C<$!> if C<syscall> returns C<-1>. |
16853 | 16465 | |
16854 | 16466 | =end original |
16855 | 16467 | |
16856 | 16468 | syscall は、呼び出したシステムコールが返した値を返します。 |
16857 | 16469 | システムコールが失敗すると、C<syscall> は C<-1> を返し、 |
16858 | 16470 | C<$!>(errno) を設定します。 |
16859 | 16471 | システムコールが正常に C<-1> を返す I<場合がある> ことに注意してください。 |
16860 | 16472 | このようなシステムコールを正しく扱うには、 |
16861 | 16473 | C<$!=0> をシステムコールの前に実行し、それから |
16862 | 16474 | C<syscall> が C<-1> を返した時には C<$!> の値を調べてください。 |
16863 | 16475 | |
16864 | 16476 | =begin original |
16865 | 16477 | |
16866 | 16478 | There's a problem with C<syscall(&SYS_pipe)>: it returns the file |
16867 | 16479 | number of the read end of the pipe it creates, but there is no way |
16868 | 16480 | to retrieve the file number of the other end. You can avoid this |
16869 | 16481 | problem by using C<pipe> instead. |
16870 | 16482 | |
16871 | 16483 | =end original |
16872 | 16484 | |
16873 | C<syscall(&SYS_pipe)> には問題があり、 | |
16485 | C<syscall(&SYS_pipe)> には問題があり、 | |
16874 | ファイル番号を返しますが、 | |
16486 | 作ったパイプの、読み出し側のファイル番号を返しますが、 | |
16487 | もう一方のファイル番号を得る方法がありません。 | |
16875 | 16488 | この問題を避けるためには、代わりに C<pipe> を使ってください。 |
16876 | 16489 | |
16877 | 16490 | =begin original |
16878 | 16491 | |
16879 | 16492 | Portability issues: L<perlport/syscall>. |
16880 | 16493 | |
16881 | 16494 | =end original |
16882 | 16495 | |
16883 | 16496 | 移植性の問題: L<perlport/syscall>。 |
16884 | 16497 | |
16885 | 16498 | =item sysopen FILEHANDLE,FILENAME,MODE |
16886 | 16499 | X<sysopen> |
16887 | 16500 | |
16888 | 16501 | =item sysopen FILEHANDLE,FILENAME,MODE,PERMS |
16889 | 16502 | |
16890 | 16503 | =for Pod::Functions +5.002 open a file, pipe, or descriptor |
16891 | 16504 | |
16892 | 16505 | =begin original |
16893 | 16506 | |
16894 | 16507 | Opens the file whose filename is given by FILENAME, and associates it with |
16895 | 16508 | FILEHANDLE. If FILEHANDLE is an expression, its value is used as the real |
16896 | 16509 | filehandle wanted; an undefined scalar will be suitably autovivified. This |
16897 | 16510 | function calls the underlying operating system's I<open>(2) function with the |
16898 | 16511 | parameters FILENAME, MODE, and PERMS. |
16899 | 16512 | |
16900 | 16513 | =end original |
16901 | 16514 | |
16902 | 16515 | FILENAME で与えられたファイル名のファイルをオープンし、 |
16903 | 16516 | FILEHANDLE と結び付けます。 |
16904 | 16517 | FILEHANDLE が式の場合、その値は実際の求めているファイルハンドルの名前として |
16905 | 16518 | 扱われます; 未定義のスカラは適切に自動有効化されます。 |
16906 | 16519 | この関数呼び出しはシステムの I<open>(2) 関数を FILENAME, MODE, PERMS の |
16907 | 16520 | 引数で呼び出すことを基礎としています。 |
16908 | 16521 | |
16909 | 16522 | =begin original |
16910 | 16523 | |
16911 | 16524 | The possible values and flag bits of the MODE parameter are |
16912 | 16525 | system-dependent; they are available via the standard module C<Fcntl>. See |
16913 | 16526 | the documentation of your operating system's I<open>(2) syscall to see |
16914 | 16527 | which values and flag bits are available. You may combine several flags |
16915 | 16528 | using the C<|>-operator. |
16916 | 16529 | |
16917 | 16530 | =end original |
16918 | 16531 | |
16919 | 16532 | MODE パラメータに指定できるフラグビットと値はシステム依存です; |
16920 | 16533 | これは標準モジュール C<Fcntl> 経由で利用可能です。 |
16921 | 16534 | どのようなフラグビットと値が利用可能であるかについては、 |
16922 | 16535 | OS の I<open>(2) システムコールに関する文書を参照してください。 |
16923 | 16536 | C<|> 演算子を使って複数のフラグを結合することができます。 |
16924 | 16537 | |
16925 | 16538 | =begin original |
16926 | 16539 | |
16927 | 16540 | Some of the most common values are C<O_RDONLY> for opening the file in |
16928 | 16541 | read-only mode, C<O_WRONLY> for opening the file in write-only mode, |
16929 | 16542 | and C<O_RDWR> for opening the file in read-write mode. |
16930 | 16543 | X<O_RDONLY> X<O_RDWR> X<O_WRONLY> |
16931 | 16544 | |
16932 | 16545 | =end original |
16933 | 16546 | |
16934 | 16547 | もっともよく使われる値は、ファイルを読み込み専用で開く C<O_RDONLY>、 |
16935 | 16548 | ファイルを書き込み専用で開く C<O_WRONLY>、 |
16936 | 16549 | ファイルを読み書き両用で開く C<O_RDWR> です。 |
16937 | 16550 | X<O_RDONLY> X<O_RDWR> X<O_WRONLY> |
16938 | 16551 | |
16939 | 16552 | =begin original |
16940 | 16553 | |
16941 | 16554 | For historical reasons, some values work on almost every system |
16942 | 16555 | supported by Perl: 0 means read-only, 1 means write-only, and 2 |
16943 | 16556 | means read/write. We know that these values do I<not> work under |
16944 | OS/390 and on the Macintosh; you probably don't want to | |
16557 | OS/390 & VM/ESA Unix and on the Macintosh; you probably don't want to | |
16945 | 16558 | use them in new code. |
16946 | 16559 | |
16947 | 16560 | =end original |
16948 | 16561 | |
16949 | 16562 | 歴史的な理由により、Perl が対応しているほとんどのシステムで使える値が |
16950 | 16563 | あります:0 は読み込み専用、1 は書き込み専用、2 は読み書き両用を意味します。 |
16951 | OS/390 と Macintosh では動作 I<しない> ことが分かっています; | |
16564 | OS/390 & VM/ESA Unix と Macintosh では動作 I<しない> ことが分かっています; | |
16952 | 16565 | 新しく書くコードではこれらは使わないほうがよいでしょう。 |
16953 | 16566 | |
16954 | 16567 | =begin original |
16955 | 16568 | |
16956 | 16569 | If the file named by FILENAME does not exist and the C<open> call creates |
16957 | 16570 | it (typically because MODE includes the C<O_CREAT> flag), then the value of |
16958 | 16571 | PERMS specifies the permissions of the newly created file. If you omit |
16959 | 16572 | the PERMS argument to C<sysopen>, Perl uses the octal value C<0666>. |
16960 | 16573 | These permission values need to be in octal, and are modified by your |
16961 | 16574 | process's current C<umask>. |
16962 | 16575 | X<O_CREAT> |
16963 | 16576 | |
16964 | 16577 | =end original |
16965 | 16578 | |
16966 | 16579 | FILENAME という名前のファイルが存在せず、(典型的には MODE が |
16967 | 16580 | C<O_CREAT> フラグを含んでいたために) C<open> 呼び出しがそれを作った場合、 |
16968 | 16581 | PERMS の値は新しく作られたファイルの権限を指定します。 |
16969 | 16582 | C<sysopen> の PERMS 引数を省略した場合、Perl は 8 進数 C<0666> を使います。 |
16970 | 16583 | これらの権限は 8 進数である必要があり、プロセスの現在の C<umask> で |
16971 | 16584 | 修正されます。 |
16972 | 16585 | X<O_CREAT> |
16973 | 16586 | |
16974 | 16587 | =begin original |
16975 | 16588 | |
16976 | 16589 | In many systems the C<O_EXCL> flag is available for opening files in |
16977 | 16590 | exclusive mode. This is B<not> locking: exclusiveness means here that |
16978 | 16591 | if the file already exists, sysopen() fails. C<O_EXCL> may not work |
16979 | 16592 | on network filesystems, and has no effect unless the C<O_CREAT> flag |
16980 | 16593 | is set as well. Setting C<O_CREAT|O_EXCL> prevents the file from |
16981 | 16594 | being opened if it is a symbolic link. It does not protect against |
16982 | 16595 | symbolic links in the file's path. |
16983 | 16596 | X<O_EXCL> |
16984 | 16597 | |
16985 | 16598 | =end original |
16986 | 16599 | |
16987 | 16600 | 多くのシステムではファイルを排他モードで開くために C<O_EXCL> が |
16988 | 16601 | 利用可能です。 |
16989 | 16602 | これはロック B<ではありません>: 排他性というのは既にファイルが |
16990 | 16603 | 存在していた場合、sysopen() が失敗することを意味します。 |
16991 | 16604 | C<O_EXCL> はネットワークファイルシステムでは動作せず、 |
16992 | 16605 | またC<O_CREAT> フラグも有効でない限りは効果がありません。 |
16993 | 16606 | C<O_CREAT|O_EXCL> をセットすると、これがシンボリックリンクだった場合は |
16994 | 16607 | ファイルを開くことを妨げます。 |
16995 | 16608 | これはファイルパス中のシンボリックリンクは守りません。 |
16996 | 16609 | X<O_EXCL> |
16997 | 16610 | |
16998 | 16611 | =begin original |
16999 | 16612 | |
17000 | 16613 | Sometimes you may want to truncate an already-existing file. This |
17001 | 16614 | can be done using the C<O_TRUNC> flag. The behavior of |
17002 | 16615 | C<O_TRUNC> with C<O_RDONLY> is undefined. |
17003 | 16616 | X<O_TRUNC> |
17004 | 16617 | |
17005 | 16618 | =end original |
17006 | 16619 | |
17007 | 16620 | 既に存在しているファイルを切り詰めたい場合もあるかもしれません。 |
17008 | 16621 | これは C<O_TRUNC> フラグを使うことで行えます。 |
17009 | 16622 | C<O_RDONLY> と C<O_TRUNC> を同時に指定したときの振る舞いは未定義です。 |
17010 | 16623 | X<O_TRUNC> |
17011 | 16624 | |
17012 | 16625 | =begin original |
17013 | 16626 | |
17014 | 16627 | You should seldom if ever use C<0644> as argument to C<sysopen>, because |
17015 | 16628 | that takes away the user's option to have a more permissive umask. |
17016 | 16629 | Better to omit it. See the perlfunc(1) entry on C<umask> for more |
17017 | 16630 | on this. |
17018 | 16631 | |
17019 | 16632 | =end original |
17020 | 16633 | |
17021 | 16634 | めったなことでは C<sysopen> の引数に C<0644> を指定するべきではないでしょう: |
17022 | 16635 | ユーザーがより寛大な umask を指定する選択肢を奪うからです。 |
17023 | 16636 | 省略した方がいいです。 |
17024 | 16637 | これに関するさらなる情報については perlfunc(1) の C<umask> を |
17025 | 16638 | 参照してください。 |
17026 | 16639 | |
17027 | 16640 | =begin original |
17028 | 16641 | |
17029 | 16642 | Note that C<sysopen> depends on the fdopen() C library function. |
17030 | 16643 | On many Unix systems, fdopen() is known to fail when file descriptors |
17031 | 16644 | exceed a certain value, typically 255. If you need more file |
17032 | descriptors than that, consider u | |
16645 | descriptors than that, consider rebuilding Perl to use the C<sfio> | |
16646 | library, or perhaps using the POSIX::open() function. | |
17033 | 16647 | |
17034 | 16648 | =end original |
17035 | 16649 | |
17036 | C<sysopen> は C の fdopen() ライブラリ関数に依存していることに | |
16650 | C<sysopen> は C の fdopen() ライブラリ関数に依存していることに注意してください。 | |
17037 | ||
16651 | 多くの Unix システムでは、fdopen() はファイル記述子がある値(例えば 255)を超えると | |
17038 | ||
16652 | 失敗することが知られています。 | |
17039 | ||
16653 | これより多くのファイル記述子が必要な場合は、 | |
17040 | ||
16654 | Perl を C<sfio> ライブラリを使って再ビルドするか、 | |
17041 | ||
16655 | POSIX::open() 関数を使うことを健闘してください。 | |
17042 | 16656 | |
17043 | 16657 | =begin original |
17044 | 16658 | |
17045 | 16659 | See L<perlopentut> for a kinder, gentler explanation of opening files. |
17046 | 16660 | |
17047 | 16661 | =end original |
17048 | 16662 | |
17049 | ファイル | |
16663 | ファイル操作に関するより親切な説明については L<perlopentut> を参照してください。 | |
17050 | 参照してください。 | |
17051 | 16664 | |
17052 | 16665 | =begin original |
17053 | 16666 | |
17054 | 16667 | Portability issues: L<perlport/sysopen>. |
17055 | 16668 | |
17056 | 16669 | =end original |
17057 | 16670 | |
17058 | 16671 | 移植性の問題: L<perlport/sysopen>。 |
17059 | 16672 | |
17060 | 16673 | =item sysread FILEHANDLE,SCALAR,LENGTH,OFFSET |
17061 | 16674 | X<sysread> |
17062 | 16675 | |
17063 | 16676 | =item sysread FILEHANDLE,SCALAR,LENGTH |
17064 | 16677 | |
17065 | 16678 | =for Pod::Functions fixed-length unbuffered input from a filehandle |
17066 | 16679 | |
17067 | 16680 | =begin original |
17068 | 16681 | |
17069 | 16682 | Attempts to read LENGTH bytes of data into variable SCALAR from the |
17070 | 16683 | specified FILEHANDLE, using the read(2). It bypasses |
17071 | 16684 | buffered IO, so mixing this with other kinds of reads, C<print>, |
17072 | 16685 | C<write>, C<seek>, C<tell>, or C<eof> can cause confusion because the |
17073 | 16686 | perlio or stdio layers usually buffers data. Returns the number of |
17074 | 16687 | bytes actually read, C<0> at end of file, or undef if there was an |
17075 | 16688 | error (in the latter case C<$!> is also set). SCALAR will be grown or |
17076 | 16689 | shrunk so that the last byte actually read is the last byte of the |
17077 | 16690 | scalar after the read. |
17078 | 16691 | |
17079 | 16692 | =end original |
17080 | 16693 | |
17081 | 16694 | read(2) を用いて、指定した FILEHANDLE から、変数 SCALAR へ、LENGTH バイトの |
17082 | 16695 | データの読み込みを試みます。 |
17083 | 16696 | これは、バッファ付き IO ルーチンを通りませんから、他の入力関数, C<print>, |
17084 | 16697 | C<write>, C<seek>, C<tell>, C<eof> と混ぜて使うと、入力がおかしくなるかも |
17085 | 16698 | しれません; perlio 層や stdio 層は普通データをバッファリングするからです。 |
17086 | 16699 | ファイルの最後では C<0>が、エラー時には undef が、 |
17087 | 16700 | それ以外では実際に読み込まれたデータの長さが返されます (後者の場合は C<$!> も |
17088 | 16701 | セットされます)。 |
17089 | 16702 | 実際に読み込んだ最後のバイトが read した後の最後のバイトになるので、 |
17090 | 16703 | SCALAR は伸び縮みします。 |
17091 | 16704 | |
17092 | 16705 | =begin original |
17093 | 16706 | |
17094 | 16707 | An OFFSET may be specified to place the read data at some place in the |
17095 | 16708 | string other than the beginning. A negative OFFSET specifies |
17096 | 16709 | placement at that many characters counting backwards from the end of |
17097 | 16710 | the string. A positive OFFSET greater than the length of SCALAR |
17098 | 16711 | results in the string being padded to the required size with C<"\0"> |
17099 | 16712 | bytes before the result of the read is appended. |
17100 | 16713 | |
17101 | 16714 | =end original |
17102 | 16715 | |
17103 | OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行な | |
16716 | OFFSET を指定すると、文字列の先頭以外の場所から、読み込みを行なうことが | |
16717 | できます。 | |
17104 | 16718 | OFFSET に負の値を指定すると、文字列の最後から逆向きに何文字目かで |
17105 | 16719 | 位置を指定します。 |
17106 | OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は | |
16720 | OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は | |
17107 | 追加される前に、必要なサイズまで C<"\0"> のバイトで | |
16721 | 読み込みの結果が追加される前に、必要なサイズまで C<"\0"> のバイトで | |
16722 | パッディングされます。 | |
17108 | 16723 | |
17109 | 16724 | =begin original |
17110 | 16725 | |
17111 | 16726 | There is no syseof() function, which is ok, since eof() doesn't work |
17112 | 16727 | well on device files (like ttys) anyway. Use sysread() and check |
17113 | 16728 | for a return value for 0 to decide whether you're done. |
17114 | 16729 | |
17115 | 16730 | =end original |
17116 | 16731 | |
17117 | 16732 | syseof() 関数はありませんが、問題ありません; どちらにしろ eof() は |
17118 | 16733 | (tty のような)デバイスファイルに対してはうまく動作しないからです。 |
17119 | sysread() を使って、 返り値が 0 かどうかで最後まで読んだかを | |
16734 | sysread() を使って、 返り値が 0 かどうかで最後まで読んだかを | |
16735 | 判断してください。 | |
17120 | 16736 | |
17121 | 16737 | =begin original |
17122 | 16738 | |
17123 | 16739 | Note that if the filehandle has been marked as C<:utf8> Unicode |
17124 | 16740 | characters are read instead of bytes (the LENGTH, OFFSET, and the |
17125 | 16741 | return value of sysread() are in Unicode characters). |
17126 | 16742 | The C<:encoding(...)> layer implicitly introduces the C<:utf8> layer. |
17127 | 16743 | See L</binmode>, L</open>, and the C<open> pragma, L<open>. |
17128 | 16744 | |
17129 | 16745 | =end original |
17130 | 16746 | |
17131 | 16747 | ファイルハンドルが C<:utf8> であるとマークが付けられると、バイトではなく |
17132 | 16748 | Unicode 文字が読み込まれます (sysread() の LENGTH, OFFSET および返り値は |
17133 | 16749 | Unicode 文字になります)。 |
17134 | 16750 | C<:encoding(...)> 層は暗黙のうちに C<:utf8> 層が導入されます。 |
17135 | 16751 | L</binmode>, L</open>, C<open> プラグマ, L<open> を参照してください。 |
17136 | 16752 | |
17137 | 16753 | =item sysseek FILEHANDLE,POSITION,WHENCE |
17138 | 16754 | X<sysseek> X<lseek> |
17139 | 16755 | |
17140 | 16756 | =for Pod::Functions +5.004 position I/O pointer on handle used with sysread and syswrite |
17141 | 16757 | |
17142 | 16758 | =begin original |
17143 | 16759 | |
17144 | 16760 | Sets FILEHANDLE's system position in bytes using lseek(2). FILEHANDLE may |
17145 | 16761 | be an expression whose value gives the name of the filehandle. The values |
17146 | 16762 | for WHENCE are C<0> to set the new position to POSITION; C<1> to set the it |
17147 | 16763 | to the current position plus POSITION; and C<2> to set it to EOF plus |
17148 | 16764 | POSITION, typically negative. |
17149 | 16765 | |
17150 | 16766 | =end original |
17151 | 16767 | |
17152 | 16768 | FILEHANDLE のシステム位置をバイト単位で lseek(2) を使って設定します。 |
17153 | 16769 | FILEHANDLE は、実際のファイルハンドル名を与える式でもかまいません。 |
17154 | 16770 | WHENCE の値が、C<0> ならば、新しい位置を POSITION の位置へ設定します; |
17155 | 16771 | C<1> ならば、現在位置から POSITION 加えた位置へ設定します; C<2> ならば、 |
17156 | 16772 | EOF から POSITION だけ(普通は負の数です)加えた位置へ、新しい位置を |
17157 | 16773 | 設定します。 |
17158 | 16774 | |
17159 | 16775 | =begin original |
17160 | 16776 | |
17161 | 16777 | Note the I<in bytes>: even if the filehandle has been set to operate |
17162 | 16778 | on characters (for example by using the C<:encoding(utf8)> I/O layer), |
17163 | 16779 | tell() will return byte offsets, not character offsets (because |
17164 | 16780 | implementing that would render sysseek() unacceptably slow). |
17165 | 16781 | |
17166 | 16782 | =end original |
17167 | 16783 | |
17168 | 16784 | I<バイト単位> に関する注意: 文字単位で扱うようにファイルハンドルが |
17169 | 16785 | 設定されている場合(C<:encoding(utf8)> I/O 層を使っている場合など)でも、 |
17170 | 16786 | tell() は文字のオフセットではなくバイトのオフセットを返します |
17171 | 16787 | (なぜならこれを実装すると sysseek() が受け入れられないほど |
17172 | 16788 | 遅くなるからです)。 |
17173 | 16789 | |
17174 | 16790 | =begin original |
17175 | 16791 | |
17176 | 16792 | sysseek() bypasses normal buffered IO, so mixing it with reads other |
17177 | 16793 | than C<sysread> (for example C<< <> >> or read()) C<print>, C<write>, |
17178 | 16794 | C<seek>, C<tell>, or C<eof> may cause confusion. |
17179 | 16795 | |
17180 | 16796 | =end original |
17181 | 16797 | |
17182 | 16798 | sysseek() は普通のバッファ付き IO をバイパスしますので、 |
17183 | 16799 | C<sysread> 以外の (例えば C<< <> >> や read() の)読み込み、 |
17184 | 16800 | C<print>, C<write>, C<seek>, C<tell>, C<eof> と混ぜて使うと |
17185 | 16801 | 混乱を引き起こします。 |
17186 | 16802 | |
17187 | 16803 | =begin original |
17188 | 16804 | |
17189 | 16805 | For WHENCE, you may also use the constants C<SEEK_SET>, C<SEEK_CUR>, |
17190 | 16806 | and C<SEEK_END> (start of the file, current position, end of the file) |
17191 | 16807 | from the Fcntl module. Use of the constants is also more portable |
17192 | 16808 | than relying on 0, 1, and 2. For example to define a "systell" function: |
17193 | 16809 | |
17194 | 16810 | =end original |
17195 | 16811 | |
17196 | 16812 | WHENCE には、Fcntl モジュールで使われている C<SEEK_SET>, C<SEEK_CUR>, |
17197 | 16813 | C<SEEK_END> (ファイルの先頭、現在位置、ファイルの最後)という定数を |
17198 | 16814 | 使うこともできます。 |
17199 | 16815 | 定数の使用は 0, 1, 2 に依存するよりも移植性があります。 |
17200 | 16816 | 例えば "systell" 関数を定義するには: |
17201 | 16817 | |
17202 | 16818 | use Fcntl 'SEEK_CUR'; |
17203 | 16819 | sub systell { sysseek($_[0], 0, SEEK_CUR) } |
17204 | 16820 | |
17205 | 16821 | =begin original |
17206 | 16822 | |
17207 | 16823 | Returns the new position, or the undefined value on failure. A position |
17208 | 16824 | of zero is returned as the string C<"0 but true">; thus C<sysseek> returns |
17209 | 16825 | true on success and false on failure, yet you can still easily determine |
17210 | 16826 | the new position. |
17211 | 16827 | |
17212 | 16828 | =end original |
17213 | 16829 | |
17214 | 16830 | 新しい位置を返します; 失敗したときは未定義値を返します。 |
17215 | 16831 | 位置がゼロの場合は、C<"0 but true"> の文字列として返されます; 従って |
17216 | 16832 | C<sysseek> は成功時に真を返し、失敗時に偽を返しますが、簡単に新しい位置を |
17217 | 16833 | 判定できます。 |
17218 | 16834 | |
17219 | 16835 | =item system LIST |
17220 | 16836 | X<system> X<shell> |
17221 | 16837 | |
17222 | 16838 | =item system PROGRAM LIST |
17223 | 16839 | |
17224 | 16840 | =for Pod::Functions run a separate program |
17225 | 16841 | |
17226 | 16842 | =begin original |
17227 | 16843 | |
17228 | 16844 | Does exactly the same thing as C<exec LIST>, except that a fork is |
17229 | 16845 | done first and the parent process waits for the child process to |
17230 | 16846 | exit. Note that argument processing varies depending on the |
17231 | 16847 | number of arguments. If there is more than one argument in LIST, |
17232 | 16848 | or if LIST is an array with more than one value, starts the program |
17233 | 16849 | given by the first element of the list with arguments given by the |
17234 | 16850 | rest of the list. If there is only one scalar argument, the argument |
17235 | 16851 | is checked for shell metacharacters, and if there are any, the |
17236 | 16852 | entire argument is passed to the system's command shell for parsing |
17237 | 16853 | (this is C</bin/sh -c> on Unix platforms, but varies on other |
17238 | 16854 | platforms). If there are no shell metacharacters in the argument, |
17239 | 16855 | it is split into words and passed directly to C<execvp>, which is |
17240 | more efficient. | |
16856 | more efficient. | |
17241 | reliably avoid using the shell; C<system LIST>, even with more than one | |
17242 | element, will fall back to the shell if the first spawn fails. | |
17243 | 16857 | |
17244 | 16858 | =end original |
17245 | 16859 | |
17246 | 16860 | C<exec LIST> とほとんど同じですが、まず fork を行ない、 |
17247 | 16861 | 親プロセスではチャイルドプロセスが終了するのを wait します。 |
17248 | 16862 | exec の項で述べたように、引数の処理は、引数の数によって異なることに |
17249 | 16863 | 注意してください。 |
17250 | 16864 | LIST に複数の引数がある場合、または LIST が複数の要素からなる配列の場合、 |
17251 | 16865 | リストの最初の要素で与えられるプログラムを、リストの残りの要素を引数として |
17252 | 16866 | 起動します。 |
17253 | 16867 | スカラの引数が一つだけの場合、引数はシェルのメタ文字をチェックされ、もし |
17254 | 16868 | あればパースのために引数全体がシステムコマンドシェル (これは |
17255 | 16869 | Unix プラットフォームでは C</bin/sh -c> ですが、他のプラットフォームでは |
17256 | 16870 | 異なります)に渡されます。 |
17257 | 16871 | シェルのメタ文字がなかった場合、引数は単語に分解されて直接 C<execvp> に |
17258 | 16872 | 渡されます; この方がより効率的です。 |
17259 | Windows では、C<system PROGRAM LIST> 構文のみが安定してシェルの使用を | |
17260 | 回避します; C<system LIST> は、2 要素以上でも、最初の spawn が失敗すると | |
17261 | シェルにフォールバックします。 | |
17262 | 16873 | |
17263 | 16874 | =begin original |
17264 | 16875 | |
17265 | Perl will attempt to flush all files opened for | |
16876 | Beginning with v5.6.0, Perl will attempt to flush all files opened for | |
17266 | 16877 | output before any operation that may do a fork, but this may not be |
17267 | 16878 | supported on some platforms (see L<perlport>). To be safe, you may need |
17268 | 16879 | to set C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method |
17269 | 16880 | of C<IO::Handle> on any open handles. |
17270 | 16881 | |
17271 | 16882 | =end original |
17272 | 16883 | |
17273 | 16884 | v5.6.0 から、Perl は書き込み用に開いている全てのファイルに対して |
17274 | 16885 | fork を行う前にフラッシュしようとしますが、これに対応していない |
17275 | 16886 | プラットフォームもあります(L<perlport> を参照してください)。 |
17276 | 16887 | 安全のために、C<$|> (English モジュールでは $AUTOFLUSH) をセットするか、 |
17277 | 16888 | 全ての開いているハンドルに対して C<IO::Handle> の C<autoflush()> メソッドを |
17278 | 16889 | 呼び出す必要があるかもしれません。 |
17279 | 16890 | |
17280 | 16891 | =begin original |
17281 | 16892 | |
17282 | 16893 | The return value is the exit status of the program as returned by the |
17283 | 16894 | C<wait> call. To get the actual exit value, shift right by eight (see |
17284 | 16895 | below). See also L</exec>. This is I<not> what you want to use to capture |
17285 | 16896 | the output from a command; for that you should use merely backticks or |
17286 | 16897 | C<qx//>, as described in L<perlop/"`STRING`">. Return value of -1 |
17287 | 16898 | indicates a failure to start the program or an error of the wait(2) system |
17288 | 16899 | call (inspect $! for the reason). |
17289 | 16900 | |
17290 | 16901 | =end original |
17291 | 16902 | |
17292 | 16903 | 返り値は、C<wait> が返すプログラムの exit 状態です。 |
17293 | 16904 | 実際の exit 値を得るには 右に 8 ビットシフトしてください(後述)。 |
17294 | 16905 | L</exec> も参照してください。 |
17295 | 16906 | これはコマンドからの出力を捕らえるために使うものI<ではありません>; |
17296 | 16907 | そのような用途には、L<perlop/"`STRING`"> に記述されている |
17297 | 16908 | 逆クォートや C<qx//> を使用してください。 |
17298 | 16909 | -1 の返り値はプログラムを開始させることに失敗したか、wait(2) |
17299 | 16910 | システムコールがエラーを出したことを示します |
17300 | 16911 | (理由は $! を調べてください)。 |
17301 | 16912 | |
17302 | 16913 | =begin original |
17303 | 16914 | |
17304 | 16915 | If you'd like to make C<system> (and many other bits of Perl) die on error, |
17305 | 16916 | have a look at the L<autodie> pragma. |
17306 | 16917 | |
17307 | 16918 | =end original |
17308 | 16919 | |
17309 | 16920 | もし C<system> (及び Perl のその他の多くの部分) でエラー時に |
17310 | 16921 | die したいなら、L<autodie> プラグマを見てみてください。 |
17311 | 16922 | |
17312 | 16923 | =begin original |
17313 | 16924 | |
17314 | 16925 | Like C<exec>, C<system> allows you to lie to a program about its name if |
17315 | 16926 | you use the C<system PROGRAM LIST> syntax. Again, see L</exec>. |
17316 | 16927 | |
17317 | 16928 | =end original |
17318 | 16929 | |
17319 | 16930 | C<exec> と同様に、C<system> でも C<system PROGRAM LIST> の文法を |
17320 | 16931 | 使うことで、プログラムに対してその名前を嘘をつくことができます。 |
17321 | 16932 | 再び、L</exec> を参照してください。 |
17322 | 16933 | |
17323 | 16934 | =begin original |
17324 | 16935 | |
17325 | 16936 | Since C<SIGINT> and C<SIGQUIT> are ignored during the execution of |
17326 | 16937 | C<system>, if you expect your program to terminate on receipt of these |
17327 | 16938 | signals you will need to arrange to do so yourself based on the return |
17328 | 16939 | value. |
17329 | 16940 | |
17330 | 16941 | =end original |
17331 | 16942 | |
17332 | 16943 | C<SIGINT> と C<SIGQUIT> は C<system> の実行中は無視されるので、 |
17333 | 16944 | これらのシグナルを受信して終了させることを想定したプログラムの場合、 |
17334 | 16945 | 返り値を利用するように変更する必要があります。 |
17335 | 16946 | |
17336 | 16947 | @args = ("command", "arg1", "arg2"); |
17337 | 16948 | system(@args) == 0 |
17338 | 16949 | or die "system @args failed: $?" |
17339 | 16950 | |
17340 | 16951 | =begin original |
17341 | 16952 | |
17342 | 16953 | If you'd like to manually inspect C<system>'s failure, you can check all |
17343 | 16954 | possible failure modes by inspecting C<$?> like this: |
17344 | 16955 | |
17345 | 16956 | =end original |
17346 | 16957 | |
17347 | C<system> の失敗を手動で検査したいなら、 | |
16958 | C<system> の失敗を手動で検査したいなら、 | |
17348 | 全ての失敗の可能性を | |
16959 | 以下のように C<$?> を調べることで、全ての失敗の可能性を | |
16960 | チェックできます: | |
17349 | 16961 | |
17350 | 16962 | if ($? == -1) { |
17351 | 16963 | print "failed to execute: $!\n"; |
17352 | 16964 | } |
17353 | 16965 | elsif ($? & 127) { |
17354 | 16966 | printf "child died with signal %d, %s coredump\n", |
17355 | 16967 | ($? & 127), ($? & 128) ? 'with' : 'without'; |
17356 | 16968 | } |
17357 | 16969 | else { |
17358 | 16970 | printf "child exited with value %d\n", $? >> 8; |
17359 | 16971 | } |
17360 | 16972 | |
17361 | 16973 | =begin original |
17362 | 16974 | |
17363 | 16975 | Alternatively, you may inspect the value of C<${^CHILD_ERROR_NATIVE}> |
17364 | 16976 | with the C<W*()> calls from the POSIX module. |
17365 | 16977 | |
17366 | 16978 | =end original |
17367 | 16979 | |
17368 | 16980 | または、POSIX モジュールの C<W*()> 呼び出しを使って |
17369 | 16981 | C<${^CHILD_ERROR_NATIVE}> の値を調べることもできます。 |
17370 | 16982 | |
17371 | 16983 | =begin original |
17372 | 16984 | |
17373 | 16985 | When C<system>'s arguments are executed indirectly by the shell, |
17374 | 16986 | results and return codes are subject to its quirks. |
17375 | 16987 | See L<perlop/"`STRING`"> and L</exec> for details. |
17376 | 16988 | |
17377 | 16989 | =end original |
17378 | 16990 | |
17379 | 16991 | C<system> の引数がシェルによって間接的に実行された場合、 |
17380 | 16992 | 結果と返り値はシェルの癖によって変更されることがあります。 |
17381 | 16993 | 詳細については L<perlop/"`STRING`"> と L</exec> を参照してください。 |
17382 | 16994 | |
17383 | 16995 | =begin original |
17384 | 16996 | |
17385 | 16997 | Since C<system> does a C<fork> and C<wait> it may affect a C<SIGCHLD> |
17386 | 16998 | handler. See L<perlipc> for details. |
17387 | 16999 | |
17388 | 17000 | =end original |
17389 | 17001 | |
17390 | 17002 | C<system> は C<fork> と C<wait> を行うので、C<SIGCHLD> ハンドラの影響を |
17391 | 17003 | 受けます。 |
17392 | 17004 | 詳しくは L<perlipc> を参照してください。 |
17393 | 17005 | |
17394 | 17006 | =begin original |
17395 | 17007 | |
17396 | 17008 | Portability issues: L<perlport/system>. |
17397 | 17009 | |
17398 | 17010 | =end original |
17399 | 17011 | |
17400 | 17012 | 移植性の問題: L<perlport/system>。 |
17401 | 17013 | |
17402 | 17014 | =item syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET |
17403 | 17015 | X<syswrite> |
17404 | 17016 | |
17405 | 17017 | =item syswrite FILEHANDLE,SCALAR,LENGTH |
17406 | 17018 | |
17407 | 17019 | =item syswrite FILEHANDLE,SCALAR |
17408 | 17020 | |
17409 | 17021 | =for Pod::Functions fixed-length unbuffered output to a filehandle |
17410 | 17022 | |
17411 | 17023 | =begin original |
17412 | 17024 | |
17413 | 17025 | Attempts to write LENGTH bytes of data from variable SCALAR to the |
17414 | 17026 | specified FILEHANDLE, using write(2). If LENGTH is |
17415 | 17027 | not specified, writes whole SCALAR. It bypasses buffered IO, so |
17416 | 17028 | mixing this with reads (other than C<sysread())>, C<print>, C<write>, |
17417 | 17029 | C<seek>, C<tell>, or C<eof> may cause confusion because the perlio and |
17418 | 17030 | stdio layers usually buffer data. Returns the number of bytes |
17419 | 17031 | actually written, or C<undef> if there was an error (in this case the |
17420 | 17032 | errno variable C<$!> is also set). If the LENGTH is greater than the |
17421 | 17033 | data available in the SCALAR after the OFFSET, only as much data as is |
17422 | 17034 | available will be written. |
17423 | 17035 | |
17424 | 17036 | =end original |
17425 | 17037 | |
17426 | 17038 | write(2) を使って、指定した FILEHANDLEへ、変数 SCALAR から、LENGTH バイトの |
17427 | 17039 | データの書き込みを試みます。 |
17428 | 17040 | LENGTH が指定されなかった場合、 SCALAR 全体を書き込みます。 |
17429 | 17041 | これは、バッファ付き IO ルーチンを通りませんから、他の入力関数 |
17430 | 17042 | (C<sysread()> 以外), C<print>, C<write>, C<seek>, C<tell>, C<eof> と |
17431 | 17043 | 混ぜて使うと、出力がおかしくなるかもしれません; perlio 層と stdio 層は普通 |
17432 | 17044 | データをバッファリングするからです。 |
17433 | 17045 | 実際に読み込まれたデータの長さか、エラー時には C<undef> が返されます |
17434 | 17046 | (この場合エラー変数 C<$!> もセットされます)。 |
17435 | 17047 | LENGTH が OFFSET 以降の SCALAR の利用可能なデータより大きかった場合、 |
17436 | 17048 | 利用可能なデータのみが書き込まれます。 |
17437 | 17049 | |
17438 | 17050 | =begin original |
17439 | 17051 | |
17440 | 17052 | An OFFSET may be specified to write the data from some part of the |
17441 | 17053 | string other than the beginning. A negative OFFSET specifies writing |
17442 | 17054 | that many characters counting backwards from the end of the string. |
17443 | 17055 | If SCALAR is of length zero, you can only use an OFFSET of 0. |
17444 | 17056 | |
17445 | 17057 | =end original |
17446 | 17058 | |
17447 | 17059 | OFFSET を指定すると、SCALAR の先頭以外の場所から、 |
17448 | 17060 | データを取り出して、書き込みを行なうことができます。 |
17449 | 17061 | OFFSET に負の値を指定すると、文字列の最後から逆向きに数えて |
17450 | 17062 | 何バイト目から書き込むかを示します。 |
17451 | 17063 | SCALAR の長さが 0 の場合、OFFSET は 0 のみ使用できます。 |
17452 | 17064 | |
17453 | 17065 | =begin original |
17454 | 17066 | |
17455 | 17067 | B<WARNING>: If the filehandle is marked C<:utf8>, Unicode characters |
17456 | 17068 | encoded in UTF-8 are written instead of bytes, and the LENGTH, OFFSET, and |
17457 | 17069 | return value of syswrite() are in (UTF8-encoded Unicode) characters. |
17458 | 17070 | The C<:encoding(...)> layer implicitly introduces the C<:utf8> layer. |
17459 | 17071 | Alternately, if the handle is not marked with an encoding but you |
17460 | 17072 | attempt to write characters with code points over 255, raises an exception. |
17461 | 17073 | See L</binmode>, L</open>, and the C<open> pragma, L<open>. |
17462 | 17074 | |
17463 | 17075 | =end original |
17464 | 17076 | |
17465 | 17077 | B<警告>: ファイルハンドルが C<:utf8> であるとマークが付けられると、 |
17466 | 17078 | バイトではなく UTF-8 エンコードされた Unicode 文字が読み込まれ、 |
17467 | 17079 | syswrite() の LENGTH, OFFSET および返り値は (UTF8 エンコードされた |
17468 | 17080 | Unicode) 文字単位になります。 |
17469 | 17081 | C<:encoding(...)> 層は暗黙のうちに C<:utf8> 層が導入されます。 |
17470 | 17082 | または、もしハンドルにエンコーディングが記録されていない状態で |
17471 | 17083 | 255 を超える符号位置の文字を書き込もうとすると、例外が発生します。 |
17472 | 17084 | L</binmode>, L</open>, C<open> プラグマ, L<open> を参照してください。 |
17473 | 17085 | |
17474 | 17086 | =item tell FILEHANDLE |
17475 | 17087 | X<tell> |
17476 | 17088 | |
17477 | 17089 | =item tell |
17478 | 17090 | |
17479 | 17091 | =for Pod::Functions get current seekpointer on a filehandle |
17480 | 17092 | |
17481 | 17093 | =begin original |
17482 | 17094 | |
17483 | 17095 | Returns the current position I<in bytes> for FILEHANDLE, or -1 on |
17484 | 17096 | error. FILEHANDLE may be an expression whose value gives the name of |
17485 | 17097 | the actual filehandle. If FILEHANDLE is omitted, assumes the file |
17486 | 17098 | last read. |
17487 | 17099 | |
17488 | 17100 | =end original |
17489 | 17101 | |
17490 | 17102 | FILEHANDLE の現在の位置を I<バイト数で> 返します; エラーの場合は -1 を |
17491 | 17103 | 返します。 |
17492 | 17104 | FILEHANDLE は、実際のファイルハンドル名を示す式でもかまいません。 |
17493 | FILEHANDLE が省略された場合には、 | |
17105 | FILEHANDLE が省略された場合には、 | |
17494 | 調べます。 | |
17106 | 最後に読み込みを行なったファイルについて調べます。 | |
17495 | 17107 | |
17496 | 17108 | =begin original |
17497 | 17109 | |
17498 | 17110 | Note the I<in bytes>: even if the filehandle has been set to |
17499 | 17111 | operate on characters (for example by using the C<:encoding(utf8)> open |
17500 | 17112 | layer), tell() will return byte offsets, not character offsets (because |
17501 | 17113 | that would render seek() and tell() rather slow). |
17502 | 17114 | |
17503 | 17115 | =end original |
17504 | 17116 | |
17505 | 17117 | I<バイト単位> に関する注意: ファイルハンドルが (例えば |
17506 | 17118 | C<:encoding(utf8)> 層を使って) |
17507 | 17119 | 文字を操作するように設定されていたとしても、tell() は文字の |
17508 | 17120 | オフセットではなくバイトのオフセットを返すことに注意してください |
17509 | 17121 | (なぜならこれは seek() と tell() が遅くなってしまうからです)。 |
17510 | 17122 | |
17511 | 17123 | =begin original |
17512 | 17124 | |
17513 | 17125 | The return value of tell() for the standard streams like the STDIN |
17514 | 17126 | depends on the operating system: it may return -1 or something else. |
17515 | 17127 | tell() on pipes, fifos, and sockets usually returns -1. |
17516 | 17128 | |
17517 | 17129 | =end original |
17518 | 17130 | |
17519 | 17131 | STDIN のような標準ストリームに対する tell() の返り値は OS に依存します: |
17520 | 17132 | -1 やその他の値が返ってくるかもしれません。 |
17521 | 17133 | パイプ、FIFO、ソケットに対して tell() を使うと、普通は -1 が返ります。 |
17522 | 17134 | |
17523 | 17135 | =begin original |
17524 | 17136 | |
17525 | 17137 | There is no C<systell> function. Use C<sysseek(FH, 0, 1)> for that. |
17526 | 17138 | |
17527 | 17139 | =end original |
17528 | 17140 | |
17529 | 17141 | C<systell> 関数はありません。 |
17530 | 17142 | 代わりに C<sysseek(FH, 0, 1)> を使ってください。 |
17531 | 17143 | |
17532 | 17144 | =begin original |
17533 | 17145 | |
17534 | 17146 | Do not use tell() (or other buffered I/O operations) on a filehandle |
17535 | 17147 | that has been manipulated by sysread(), syswrite(), or sysseek(). |
17536 | 17148 | Those functions ignore the buffering, while tell() does not. |
17537 | 17149 | |
17538 | 17150 | =end original |
17539 | 17151 | |
17540 | 17152 | sysread(), syswrite(), sysseek() で操作されたファイルハンドルに tell() |
17541 | 17153 | (またはその他のバッファリング I/O 操作) を使わないでください。 |
17542 | 17154 | これらの関数はバッファリングを無視しますが、tell() は違います。 |
17543 | 17155 | |
17544 | 17156 | =item telldir DIRHANDLE |
17545 | 17157 | X<telldir> |
17546 | 17158 | |
17547 | 17159 | =for Pod::Functions get current seekpointer on a directory handle |
17548 | 17160 | |
17549 | 17161 | =begin original |
17550 | 17162 | |
17551 | 17163 | Returns the current position of the C<readdir> routines on DIRHANDLE. |
17552 | 17164 | Value may be given to C<seekdir> to access a particular location in a |
17553 | 17165 | directory. C<telldir> has the same caveats about possible directory |
17554 | 17166 | compaction as the corresponding system library routine. |
17555 | 17167 | |
17556 | 17168 | =end original |
17557 | 17169 | |
17558 | 17170 | DIRHANDLE 上の C<readdir> ルーチンに対する現在位置を返します。 |
17559 | 17171 | 値は、そのディレクトリで特定の位置をアクセスするため、 |
17560 | 17172 | C<seekdir> に渡すことができます。 |
17561 | 17173 | C<telldir> は同名のシステムライブラリルーチンと同じく、 |
17562 | 17174 | ディレクトリ縮小時の問題が考えられます。 |
17563 | 17175 | |
17564 | 17176 | =item tie VARIABLE,CLASSNAME,LIST |
17565 | 17177 | X<tie> |
17566 | 17178 | |
17567 | 17179 | =for Pod::Functions +5.002 bind a variable to an object class |
17568 | 17180 | |
17569 | 17181 | =begin original |
17570 | 17182 | |
17571 | 17183 | This function binds a variable to a package class that will provide the |
17572 | 17184 | implementation for the variable. VARIABLE is the name of the variable |
17573 | 17185 | to be enchanted. CLASSNAME is the name of a class implementing objects |
17574 | of correct type. Any additional arguments are passed to the | |
17186 | of correct type. Any additional arguments are passed to the C<new> | |
17575 | appropriate constructor | |
17576 | 17187 | method of the class (meaning C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>, |
17577 | 17188 | or C<TIEHASH>). Typically these are arguments such as might be passed |
17578 | to the C<dbm_open()> function of C. The object returned by the | |
17189 | to the C<dbm_open()> function of C. The object returned by the C<new> | |
17579 | ||
17190 | method is also returned by the C<tie> function, which would be useful | |
17580 | 17191 | if you want to access other methods in CLASSNAME. |
17581 | 17192 | |
17582 | 17193 | =end original |
17583 | 17194 | |
17584 | 17195 | この関数は、変数を、その変数の実装を行なうクラスと結び付けます。 |
17585 | 17196 | VARIABLE は、魔法をかける変数の名前です。 |
17586 | 17197 | CLASSNAME は、正しい型のオブジェクトを実装するクラスの名前です。 |
17587 | 他に引数があれば、そのクラスの | |
17198 | 他に引数があれば、そのクラスの C<new> メソッドに渡されます | |
17588 | 17199 | (つまり C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>, C<TIEHASH>)。 |
17589 | 17200 | 通常、これらは、C の C<dbm_open> などの関数に渡す引数となります。 |
17590 | ||
17201 | C<new> メソッドで返されるオブジェクトはまた C<tie> 関数でも返されます; | |
17591 | 17202 | これは CLASSNAME の他のメソッドにアクセスしたいときに便利です。 |
17592 | 17203 | |
17593 | 17204 | =begin original |
17594 | 17205 | |
17595 | 17206 | Note that functions such as C<keys> and C<values> may return huge lists |
17596 | 17207 | when used on large objects, like DBM files. You may prefer to use the |
17597 | 17208 | C<each> function to iterate over such. Example: |
17598 | 17209 | |
17599 | 17210 | =end original |
17600 | 17211 | |
17601 | 17212 | DBM ファイルのような大きなオブジェクトでは、C<keys> や C<values> のような |
17602 | 17213 | 関数は、大きなリストを返す可能性があります。 |
17603 | 17214 | そのような場合では、C<each> 関数を使って繰り返しを行なった方が |
17604 | 17215 | よいかもしれません。 |
17605 | 17216 | 例: |
17606 | 17217 | |
17607 | 17218 | # print out history file offsets |
17608 | 17219 | use NDBM_File; |
17609 | 17220 | tie(%HIST, 'NDBM_File', '/usr/lib/news/history', 1, 0); |
17610 | 17221 | while (($key,$val) = each %HIST) { |
17611 | 17222 | print $key, ' = ', unpack('L',$val), "\n"; |
17612 | 17223 | } |
17613 | 17224 | untie(%HIST); |
17614 | 17225 | |
17615 | 17226 | =begin original |
17616 | 17227 | |
17617 | 17228 | A class implementing a hash should have the following methods: |
17618 | 17229 | |
17619 | 17230 | =end original |
17620 | 17231 | |
17621 | 17232 | ハッシュを実装するクラスでは、次のようなメソッドを用意します: |
17622 | 17233 | |
17623 | 17234 | TIEHASH classname, LIST |
17624 | 17235 | FETCH this, key |
17625 | 17236 | STORE this, key, value |
17626 | 17237 | DELETE this, key |
17627 | 17238 | CLEAR this |
17628 | 17239 | EXISTS this, key |
17629 | 17240 | FIRSTKEY this |
17630 | 17241 | NEXTKEY this, lastkey |
17631 | 17242 | SCALAR this |
17632 | 17243 | DESTROY this |
17633 | 17244 | UNTIE this |
17634 | 17245 | |
17635 | 17246 | =begin original |
17636 | 17247 | |
17637 | 17248 | A class implementing an ordinary array should have the following methods: |
17638 | 17249 | |
17639 | 17250 | =end original |
17640 | 17251 | |
17641 | 17252 | 通常の配列を実装するクラスでは、次のようなメソッドを用意します: |
17642 | 17253 | |
17643 | 17254 | TIEARRAY classname, LIST |
17644 | 17255 | FETCH this, key |
17645 | 17256 | STORE this, key, value |
17646 | 17257 | FETCHSIZE this |
17647 | 17258 | STORESIZE this, count |
17648 | 17259 | CLEAR this |
17649 | 17260 | PUSH this, LIST |
17650 | 17261 | POP this |
17651 | 17262 | SHIFT this |
17652 | 17263 | UNSHIFT this, LIST |
17653 | 17264 | SPLICE this, offset, length, LIST |
17654 | 17265 | EXTEND this, count |
17655 | DELETE this, key | |
17656 | EXISTS this, key | |
17657 | 17266 | DESTROY this |
17658 | 17267 | UNTIE this |
17659 | 17268 | |
17660 | 17269 | =begin original |
17661 | 17270 | |
17662 | 17271 | A class implementing a filehandle should have the following methods: |
17663 | 17272 | |
17664 | 17273 | =end original |
17665 | 17274 | |
17666 | 17275 | ファイルハンドルを実装するクラスでは、次のようなメソッドを用意します: |
17667 | 17276 | |
17668 | 17277 | TIEHANDLE classname, LIST |
17669 | 17278 | READ this, scalar, length, offset |
17670 | 17279 | READLINE this |
17671 | 17280 | GETC this |
17672 | 17281 | WRITE this, scalar, length, offset |
17673 | 17282 | PRINT this, LIST |
17674 | 17283 | PRINTF this, format, LIST |
17675 | 17284 | BINMODE this |
17676 | 17285 | EOF this |
17677 | 17286 | FILENO this |
17678 | 17287 | SEEK this, position, whence |
17679 | 17288 | TELL this |
17680 | 17289 | OPEN this, mode, LIST |
17681 | 17290 | CLOSE this |
17682 | 17291 | DESTROY this |
17683 | 17292 | UNTIE this |
17684 | 17293 | |
17685 | 17294 | =begin original |
17686 | 17295 | |
17687 | 17296 | A class implementing a scalar should have the following methods: |
17688 | 17297 | |
17689 | 17298 | =end original |
17690 | 17299 | |
17691 | 17300 | スカラ変数を実装するクラスでは、次のようなメソッドを用意します: |
17692 | 17301 | |
17693 | 17302 | TIESCALAR classname, LIST |
17694 | 17303 | FETCH this, |
17695 | 17304 | STORE this, value |
17696 | 17305 | DESTROY this |
17697 | 17306 | UNTIE this |
17698 | 17307 | |
17699 | 17308 | =begin original |
17700 | 17309 | |
17701 | 17310 | Not all methods indicated above need be implemented. See L<perltie>, |
17702 | 17311 | L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>, and L<Tie::Handle>. |
17703 | 17312 | |
17704 | 17313 | =end original |
17705 | 17314 | |
17706 | 17315 | 上記の全てのメソッドを実装する必要はありません。 |
17707 | 17316 | L<perltie>, L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>, |
17708 | 17317 | L<Tie::Handle> を参照してください。 |
17709 | 17318 | |
17710 | 17319 | =begin original |
17711 | 17320 | |
17712 | 17321 | Unlike C<dbmopen>, the C<tie> function will not C<use> or C<require> a module |
17713 | 17322 | for you; you need to do that explicitly yourself. See L<DB_File> |
17714 | 17323 | or the F<Config> module for interesting C<tie> implementations. |
17715 | 17324 | |
17716 | 17325 | =end original |
17717 | 17326 | |
17718 | 17327 | C<dbmopen> と違い、C<tie> 関数はモジュールを C<use> したり |
17719 | 17328 | C<require> したりしません; 自分で明示的に行う必要があります。 |
17720 | 17329 | C<tie> の興味深い実装については L<DB_File> や F<Config> モジュールを |
17721 | 17330 | 参照してください。 |
17722 | 17331 | |
17723 | 17332 | =begin original |
17724 | 17333 | |
17725 | 17334 | For further details see L<perltie>, L<"tied VARIABLE">. |
17726 | 17335 | |
17727 | 17336 | =end original |
17728 | 17337 | |
17729 | 17338 | 更なる詳細については L<perltie> や L<"tied VARIABLE"> を参照してください。 |
17730 | 17339 | |
17731 | 17340 | =item tied VARIABLE |
17732 | 17341 | X<tied> |
17733 | 17342 | |
17734 | 17343 | =for Pod::Functions get a reference to the object underlying a tied variable |
17735 | 17344 | |
17736 | 17345 | =begin original |
17737 | 17346 | |
17738 | 17347 | Returns a reference to the object underlying VARIABLE (the same value |
17739 | 17348 | that was originally returned by the C<tie> call that bound the variable |
17740 | 17349 | to a package.) Returns the undefined value if VARIABLE isn't tied to a |
17741 | 17350 | package. |
17742 | 17351 | |
17743 | 17352 | =end original |
17744 | 17353 | |
17745 | 17354 | VARIABLE の基となるオブジェクトへのリファレンスを返します |
17746 | 17355 | (変数をパッケージに結びつけるために C<tie> 呼び出しをしたときの |
17747 | 17356 | 返り値と同じものです)。 |
17748 | 17357 | VARIABLE がパッケージと結び付けられていない場合は未定義値を返します。 |
17749 | 17358 | |
17750 | 17359 | =item time |
17751 | 17360 | X<time> X<epoch> |
17752 | 17361 | |
17753 | 17362 | =for Pod::Functions return number of seconds since 1970 |
17754 | 17363 | |
17755 | 17364 | =begin original |
17756 | 17365 | |
17757 | 17366 | Returns the number of non-leap seconds since whatever time the system |
17758 | 17367 | considers to be the epoch, suitable for feeding to C<gmtime> and |
17759 | 17368 | C<localtime>. On most systems the epoch is 00:00:00 UTC, January 1, 1970; |
17760 | 17369 | a prominent exception being Mac OS Classic which uses 00:00:00, January 1, |
17761 | 17370 | 1904 in the current local time zone for its epoch. |
17762 | 17371 | |
17763 | 17372 | =end original |
17764 | 17373 | |
17765 | 17374 | C<gmtime> や C<localtime> への入力形式に合っている、 |
17766 | 17375 | システムが紀元と考える時点からの連続秒数を返します。 |
17767 | 17376 | ほとんどのシステムでは紀元は UTC 1970 年 1 月 1 日 00:00:00 です; |
17768 | 17377 | 特徴的な例外としては、古い Mac OS ではローカルタイムゾーンの |
17769 | 17378 | 1904 年 1 月 1 日 00:00:00 を紀元として使います。 |
17770 | 17379 | |
17771 | 17380 | =begin original |
17772 | 17381 | |
17773 | 17382 | For measuring time in better granularity than one second, use the |
17774 | 17383 | L<Time::HiRes> module from Perl 5.8 onwards (or from CPAN before then), or, |
17775 | 17384 | if you have gettimeofday(2), you may be able to use the C<syscall> |
17776 | 17385 | interface of Perl. See L<perlfaq8> for details. |
17777 | 17386 | |
17778 | 17387 | =end original |
17779 | 17388 | |
17780 | 17389 | 1 秒よりも細かい時間を計測するためには、Perl 5.8 以降(それ以前では |
17781 | 17390 | CPANから)の L<Time::HiRes> モジュールを使うか、 |
17782 | 17391 | gettimeofday(2) があるなら、Perl の C<syscall> インターフェースを |
17783 | 17392 | 使ってください。 |
17784 | 17393 | 詳しくは L<perlfaq8> を参照してください。 |
17785 | 17394 | |
17786 | 17395 | =begin original |
17787 | 17396 | |
17788 | 17397 | For date and time processing look at the many related modules on CPAN. |
17789 | 17398 | For a comprehensive date and time representation look at the |
17790 | 17399 | L<DateTime> module. |
17791 | 17400 | |
17792 | 17401 | =end original |
17793 | 17402 | |
17794 | 17403 | 日付と時刻の処理は、多くの関連するモジュールが CPAN にあります。 |
17795 | 17404 | 包括的な日付と時刻の表現については、CPAN の L<DateTime> モジュールを |
17796 | 17405 | 参照してください。 |
17797 | 17406 | |
17798 | 17407 | =item times |
17799 | 17408 | X<times> |
17800 | 17409 | |
17801 | 17410 | =for Pod::Functions return elapsed time for self and child processes |
17802 | 17411 | |
17803 | 17412 | =begin original |
17804 | 17413 | |
17805 | 17414 | Returns a four-element list giving the user and system times in |
17806 | 17415 | seconds for this process and any exited children of this process. |
17807 | 17416 | |
17808 | 17417 | =end original |
17809 | 17418 | |
17810 | 17419 | 現プロセス及び終了したその子プロセスに対する、ユーザ時間とシステム時間を |
17811 | 17420 | 秒で示した、4 要素のリスト値を返します。 |
17812 | 17421 | |
17813 | 17422 | ($user,$system,$cuser,$csystem) = times; |
17814 | 17423 | |
17815 | 17424 | =begin original |
17816 | 17425 | |
17817 | 17426 | In scalar context, C<times> returns C<$user>. |
17818 | 17427 | |
17819 | 17428 | =end original |
17820 | 17429 | |
17821 | 17430 | スカラコンテキストでは、C<times> は C<$user> を返します。 |
17822 | 17431 | |
17823 | 17432 | =begin original |
17824 | 17433 | |
17825 | 17434 | Children's times are only included for terminated children. |
17826 | 17435 | |
17827 | 17436 | =end original |
17828 | 17437 | |
17829 | 17438 | 子プロセスに対する times は、終了した子プロセスのみ含められます。 |
17830 | 17439 | |
17831 | 17440 | =begin original |
17832 | 17441 | |
17833 | 17442 | Portability issues: L<perlport/times>. |
17834 | 17443 | |
17835 | 17444 | =end original |
17836 | 17445 | |
17837 | 17446 | 移植性の問題: L<perlport/times>。 |
17838 | 17447 | |
17839 | 17448 | =item tr/// |
17840 | 17449 | |
17841 | 17450 | =for Pod::Functions transliterate a string |
17842 | 17451 | |
17843 | 17452 | =begin original |
17844 | 17453 | |
17845 | 17454 | The transliteration operator. Same as C<y///>. See |
17846 | L<perlop/"Quote- | |
17455 | L<perlop/"Quote and Quote-like Operators">. | |
17847 | 17456 | |
17848 | 17457 | =end original |
17849 | 17458 | |
17850 | 17459 | 文字変換演算子です。 |
17851 | 17460 | C<y///> と同じです。 |
17852 | L<perlop/"Quote- | |
17461 | L<perlop/"Quote and Quote-like Operators"> を参照してください。 | |
17853 | 17462 | |
17854 | 17463 | =item truncate FILEHANDLE,LENGTH |
17855 | 17464 | X<truncate> |
17856 | 17465 | |
17857 | 17466 | =item truncate EXPR,LENGTH |
17858 | 17467 | |
17859 | 17468 | =for Pod::Functions shorten a file |
17860 | 17469 | |
17861 | 17470 | =begin original |
17862 | 17471 | |
17863 | 17472 | Truncates the file opened on FILEHANDLE, or named by EXPR, to the |
17864 | 17473 | specified length. Raises an exception if truncate isn't implemented |
17865 | 17474 | on your system. Returns true if successful, C<undef> on error. |
17866 | 17475 | |
17867 | 17476 | =end original |
17868 | 17477 | |
17869 | 17478 | FILEHANDLE 上にオープンされたファイルか、EXPR で名前を表わしたファイルを、 |
17870 | 17479 | 指定した長さに切り詰めます。 |
17871 | 17480 | システム上に truncate が実装されていなければ、例外が発生します。 |
17872 | 17481 | 成功すれば真を、エラー時には C<undef> を返します。 |
17873 | 17482 | |
17874 | 17483 | =begin original |
17875 | 17484 | |
17876 | 17485 | The behavior is undefined if LENGTH is greater than the length of the |
17877 | 17486 | file. |
17878 | 17487 | |
17879 | 17488 | =end original |
17880 | 17489 | |
17881 | 17490 | LENGTH がファイルの長さより大きい場合の振る舞いは未定義です。 |
17882 | 17491 | |
17883 | 17492 | =begin original |
17884 | 17493 | |
17885 | 17494 | The position in the file of FILEHANDLE is left unchanged. You may want to |
17886 | 17495 | call L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> before writing to the file. |
17887 | 17496 | |
17888 | 17497 | =end original |
17889 | 17498 | |
17890 | 17499 | FILEHANDLE のファイルの位置は変わりません。 |
17891 | 17500 | ファイルに書き込む前に L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> を |
17892 | 17501 | 呼び出したいかもしれません。 |
17893 | 17502 | |
17894 | 17503 | =begin original |
17895 | 17504 | |
17896 | 17505 | Portability issues: L<perlport/truncate>. |
17897 | 17506 | |
17898 | 17507 | =end original |
17899 | 17508 | |
17900 | 17509 | 移植性の問題: L<perlport/truncate>。 |
17901 | 17510 | |
17902 | 17511 | =item uc EXPR |
17903 | 17512 | X<uc> X<uppercase> X<toupper> |
17904 | 17513 | |
17905 | 17514 | =item uc |
17906 | 17515 | |
17907 | 17516 | =for Pod::Functions return upper-case version of a string |
17908 | 17517 | |
17909 | 17518 | =begin original |
17910 | 17519 | |
17911 | 17520 | Returns an uppercased version of EXPR. This is the internal function |
17912 | 17521 | implementing the C<\U> escape in double-quoted strings. |
17913 | 17522 | It does not attempt to do titlecase mapping on initial letters. See |
17914 | 17523 | L</ucfirst> for that. |
17915 | 17524 | |
17916 | 17525 | =end original |
17917 | 17526 | |
17918 | 17527 | EXPR を大文字に変換したものを返します。 |
17919 | 17528 | これは、ダブルクォート文字列における、C<\U> エスケープを |
17920 | 17529 | 実装する内部関数です。 |
17921 | 17530 | 先頭文字の タイトル文字マッピングは試みません。 |
17922 | 17531 | このためには L</ucfirst> を参照してください。 |
17923 | 17532 | |
17924 | 17533 | =begin original |
17925 | 17534 | |
17926 | 17535 | If EXPR is omitted, uses C<$_>. |
17927 | 17536 | |
17928 | 17537 | =end original |
17929 | 17538 | |
17930 | 17539 | EXPR が省略されると、C<$_> を使います。 |
17931 | 17540 | |
17932 | 17541 | =begin original |
17933 | 17542 | |
17934 | 17543 | This function behaves the same way under various pragma, such as in a locale, |
17935 | 17544 | as L</lc> does. |
17936 | 17545 | |
17937 | 17546 | =end original |
17938 | 17547 | |
17939 | 17548 | この関数は、ロケールのようなさまざまなプラグマの影響下では、 |
17940 | 17549 | L</lc> と同様に振る舞います。 |
17941 | 17550 | |
17942 | 17551 | =item ucfirst EXPR |
17943 | 17552 | X<ucfirst> X<uppercase> |
17944 | 17553 | |
17945 | 17554 | =item ucfirst |
17946 | 17555 | |
17947 | 17556 | =for Pod::Functions return a string with just the next letter in upper case |
17948 | 17557 | |
17949 | 17558 | =begin original |
17950 | 17559 | |
17951 | 17560 | Returns the value of EXPR with the first character in uppercase |
17952 | 17561 | (titlecase in Unicode). This is the internal function implementing |
17953 | 17562 | the C<\u> escape in double-quoted strings. |
17954 | 17563 | |
17955 | 17564 | =end original |
17956 | 17565 | |
17957 | 17566 | 最初の文字だけを大文字にした、EXPR を返します |
17958 | 17567 | (Unicode では titlecase)。 |
17959 | 17568 | これは、ダブルクォート文字列における、C<\u> エスケープを |
17960 | 17569 | 実装する内部関数です。 |
17961 | 17570 | |
17962 | 17571 | =begin original |
17963 | 17572 | |
17964 | 17573 | If EXPR is omitted, uses C<$_>. |
17965 | 17574 | |
17966 | 17575 | =end original |
17967 | 17576 | |
17968 | 17577 | EXPR が省略されると、C<$_> を使います。 |
17969 | 17578 | |
17970 | 17579 | =begin original |
17971 | 17580 | |
17972 | 17581 | This function behaves the same way under various pragma, such as in a locale, |
17973 | 17582 | as L</lc> does. |
17974 | 17583 | |
17975 | 17584 | =end original |
17976 | 17585 | |
17977 | 17586 | この関数は、ロケールのようなさまざまなプラグマの影響下では、 |
17978 | 17587 | L</lc> と同様に振る舞います。 |
17979 | 17588 | |
17980 | 17589 | =item umask EXPR |
17981 | 17590 | X<umask> |
17982 | 17591 | |
17983 | 17592 | =item umask |
17984 | 17593 | |
17985 | 17594 | =for Pod::Functions set file creation mode mask |
17986 | 17595 | |
17987 | 17596 | =begin original |
17988 | 17597 | |
17989 | 17598 | Sets the umask for the process to EXPR and returns the previous value. |
17990 | 17599 | If EXPR is omitted, merely returns the current umask. |
17991 | 17600 | |
17992 | 17601 | =end original |
17993 | 17602 | |
17994 | 17603 | 現在のプロセスの umask を EXPR に設定し、以前の値を返します。 |
17995 | 17604 | EXPR が省略されると、単にその時点の umask の値を返します。 |
17996 | 17605 | |
17997 | 17606 | =begin original |
17998 | 17607 | |
17999 | 17608 | The Unix permission C<rwxr-x---> is represented as three sets of three |
18000 | 17609 | bits, or three octal digits: C<0750> (the leading 0 indicates octal |
18001 | 17610 | and isn't one of the digits). The C<umask> value is such a number |
18002 | 17611 | representing disabled permissions bits. The permission (or "mode") |
18003 | 17612 | values you pass C<mkdir> or C<sysopen> are modified by your umask, so |
18004 | 17613 | even if you tell C<sysopen> to create a file with permissions C<0777>, |
18005 | 17614 | if your umask is C<0022>, then the file will actually be created with |
18006 | 17615 | permissions C<0755>. If your C<umask> were C<0027> (group can't |
18007 | 17616 | write; others can't read, write, or execute), then passing |
18008 | 17617 | C<sysopen> C<0666> would create a file with mode C<0640> (because |
18009 | 17618 | C<0666 &~ 027> is C<0640>). |
18010 | 17619 | |
18011 | 17620 | =end original |
18012 | 17621 | |
18013 | 17622 | Unix パーミッション C<rwxr-x---> は 3 ビットの三つの組、 |
18014 | 17623 | または 3 桁の 8 進数として表現されます: |
18015 | 17624 | C<0750> (先頭の 0 は 8 進数を意味し、実際の値ではありません)。 |
18016 | 17625 | C<umask> の値は無効にするパーミッションビットのこのような数値表現です。 |
18017 | 17626 | C<mkdir> や C<sysopen> で渡されたパーミッション(または「モード」)の値は |
18018 | 17627 | umask で修正され、たとえ C<sysopen> で C<0777> のパーミッションで |
18019 | 17628 | ファイルを作るように指定しても、umask が C<0022> なら、 |
18020 | 17629 | 結果としてファイルは C<0755> のパーミッションで作成されます。 |
18021 | 17630 | C<umask> が C<0027> (グループは書き込めない; その他は読み込み、書き込み、 |
18022 | 17631 | 実行できない) のとき、C<sysopen> に C<0666> を渡すと、 |
18023 | 17632 | ファイルはモード C<0640> (なぜなら C<0666 &~ 027> は C<0640>)で作成されます。 |
18024 | 17633 | |
18025 | 17634 | =begin original |
18026 | 17635 | |
18027 | 17636 | Here's some advice: supply a creation mode of C<0666> for regular |
18028 | 17637 | files (in C<sysopen>) and one of C<0777> for directories (in |
18029 | 17638 | C<mkdir>) and executable files. This gives users the freedom of |
18030 | 17639 | choice: if they want protected files, they might choose process umasks |
18031 | 17640 | of C<022>, C<027>, or even the particularly antisocial mask of C<077>. |
18032 | 17641 | Programs should rarely if ever make policy decisions better left to |
18033 | 17642 | the user. The exception to this is when writing files that should be |
18034 | 17643 | kept private: mail files, web browser cookies, I<.rhosts> files, and |
18035 | 17644 | so on. |
18036 | 17645 | |
18037 | 17646 | =end original |
18038 | 17647 | |
18039 | 17648 | 以下は助言です: 作成モードとして、(C<sysopen> による)通常ファイルでは |
18040 | 17649 | C<0666> を、(C<mkdir> による)ディレクトリでは C<0777> を指定しましょう。 |
18041 | 17650 | これにより、ユーザーに選択の自由を与えます: もしファイルを守りたいなら、 |
18042 | 17651 | プロセスの umask として C<022>, C<027>, あるいは特に非社交的な |
18043 | 17652 | C<077> を選択できます。 |
18044 | 17653 | プログラムがユーザーより適切なポリシー選択ができることは稀です。 |
18045 | 17654 | 例外は、プライベートに保つべきファイル(メール、ウェブブラウザのクッキー、 |
18046 | 17655 | I<.rhosts> ファイルなど)を書く場合です。 |
18047 | 17656 | |
18048 | 17657 | =begin original |
18049 | 17658 | |
18050 | 17659 | If umask(2) is not implemented on your system and you are trying to |
18051 | 17660 | restrict access for I<yourself> (i.e., C<< (EXPR & 0700) > 0 >>), |
18052 | 17661 | raises an exception. If umask(2) is not implemented and you are |
18053 | 17662 | not trying to restrict access for yourself, returns C<undef>. |
18054 | 17663 | |
18055 | 17664 | =end original |
18056 | 17665 | |
18057 | 17666 | umask(2) が実装されていないシステムで、I<自分自身> へのアクセスを |
18058 | 17667 | 制限しようとした(つまり C<< (EXPR & 0700) > 0 >>)場合、例外が発生します。 |
18059 | 17668 | umask(2) が実装されていないシステムで、自分自身へのアクセスは |
18060 | 17669 | 制限しようとしなかった場合、C<undef> を返します。 |
18061 | 17670 | |
18062 | 17671 | =begin original |
18063 | 17672 | |
18064 | 17673 | Remember that a umask is a number, usually given in octal; it is I<not> a |
18065 | 17674 | string of octal digits. See also L</oct>, if all you have is a string. |
18066 | 17675 | |
18067 | 17676 | =end original |
18068 | 17677 | |
18069 | 17678 | umask は通常 8 進数で与えられる数値であることを忘れないでください; 8 進数の |
18070 | 17679 | 文字列 I<ではありません>。 |
18071 | 17680 | 文字列しかない場合、 L</oct> も参照してください。 |
18072 | 17681 | |
18073 | 17682 | =begin original |
18074 | 17683 | |
18075 | 17684 | Portability issues: L<perlport/umask>. |
18076 | 17685 | |
18077 | 17686 | =end original |
18078 | 17687 | |
18079 | 17688 | 移植性の問題: L<perlport/umask>。 |
18080 | 17689 | |
18081 | 17690 | =item undef EXPR |
18082 | 17691 | X<undef> X<undefine> |
18083 | 17692 | |
18084 | 17693 | =item undef |
18085 | 17694 | |
18086 | 17695 | =for Pod::Functions remove a variable or function definition |
18087 | 17696 | |
18088 | 17697 | =begin original |
18089 | 17698 | |
18090 | 17699 | Undefines the value of EXPR, which must be an lvalue. Use only on a |
18091 | 17700 | scalar value, an array (using C<@>), a hash (using C<%>), a subroutine |
18092 | 17701 | (using C<&>), or a typeglob (using C<*>). Saying C<undef $hash{$key}> |
18093 | 17702 | will probably not do what you expect on most predefined variables or |
18094 | 17703 | DBM list values, so don't do that; see L</delete>. Always returns the |
18095 | 17704 | undefined value. You can omit the EXPR, in which case nothing is |
18096 | 17705 | undefined, but you still get an undefined value that you could, for |
18097 | 17706 | instance, return from a subroutine, assign to a variable, or pass as a |
18098 | 17707 | parameter. Examples: |
18099 | 17708 | |
18100 | 17709 | =end original |
18101 | 17710 | |
18102 | 17711 | 左辺値である EXPR の値を未定義にします。 |
18103 | 17712 | スカラ値、(C<@> を使った)配列、(C<%> を使った)ハッシュ、(C<&> を使った) |
18104 | 17713 | サブルーチン、(C<*> を使った)型グロブだけに使用します。 |
18105 | 17714 | 特殊変数や DBM リスト値に C<undef $hash{$key}> などとしても |
18106 | 17715 | おそらく期待通りの結果にはなりませんから、しないでください; |
18107 | 17716 | L</delete> を参照してください。 |
18108 | 17717 | 常に未定義値を返します。 |
18109 | 17718 | EXPR は省略することができ、その場合には何も未定義にされませんが |
18110 | 17719 | 未定義値は返されますので、それをたとえば、 |
18111 | 17720 | サブルーチンの返り値、変数への割り当て、引数などとして使うことができます。 |
18112 | 17721 | 例: |
18113 | 17722 | |
18114 | 17723 | undef $foo; |
18115 | 17724 | undef $bar{'blurfl'}; # Compare to: delete $bar{'blurfl'}; |
18116 | 17725 | undef @ary; |
18117 | 17726 | undef %hash; |
18118 | 17727 | undef &mysub; |
18119 | 17728 | undef *xyz; # destroys $xyz, @xyz, %xyz, &xyz, etc. |
18120 | 17729 | return (wantarray ? (undef, $errmsg) : undef) if $they_blew_it; |
18121 | 17730 | select undef, undef, undef, 0.25; |
18122 | 17731 | ($a, $b, undef, $c) = &foo; # Ignore third value returned |
18123 | 17732 | |
18124 | 17733 | =begin original |
18125 | 17734 | |
18126 | 17735 | Note that this is a unary operator, not a list operator. |
18127 | 17736 | |
18128 | 17737 | =end original |
18129 | 17738 | |
18130 | 17739 | これはリスト演算子ではなく、単項演算子であることに注意してください。 |
18131 | 17740 | |
18132 | 17741 | =item unlink LIST |
18133 | 17742 | X<unlink> X<delete> X<remove> X<rm> X<del> |
18134 | 17743 | |
18135 | 17744 | =item unlink |
18136 | 17745 | |
18137 | 17746 | =for Pod::Functions remove one link to a file |
18138 | 17747 | |
18139 | 17748 | =begin original |
18140 | 17749 | |
18141 | 17750 | Deletes a list of files. On success, it returns the number of files |
18142 | 17751 | it successfully deleted. On failure, it returns false and sets C<$!> |
18143 | 17752 | (errno): |
18144 | 17753 | |
18145 | 17754 | =end original |
18146 | 17755 | |
18147 | 17756 | LIST に含まれるファイルを削除します。 |
18148 | 17757 | 成功時は削除に成功したファイルの数を返します。 |
18149 | 17758 | 失敗時は偽を返して C<$!> (error) をセットします: |
18150 | 17759 | |
18151 | 17760 | my $unlinked = unlink 'a', 'b', 'c'; |
18152 | 17761 | unlink @goners; |
18153 | 17762 | unlink glob "*.bak"; |
18154 | 17763 | |
18155 | 17764 | =begin original |
18156 | 17765 | |
18157 | 17766 | On error, C<unlink> will not tell you which files it could not remove. |
18158 | 17767 | If you want to know which files you could not remove, try them one |
18159 | 17768 | at a time: |
18160 | 17769 | |
18161 | 17770 | =end original |
18162 | 17771 | |
18163 | 17772 | エラーの場合、C<unlink> はどのファイルが削除できなかったかを知らせません。 |
18164 | 17773 | どのファイルが削除できなかったかを知りたい場合は、一つずつ削除してください: |
18165 | 17774 | |
18166 | 17775 | foreach my $file ( @goners ) { |
18167 | 17776 | unlink $file or warn "Could not unlink $file: $!"; |
18168 | 17777 | } |
18169 | 17778 | |
18170 | 17779 | =begin original |
18171 | 17780 | |
18172 | 17781 | Note: C<unlink> will not attempt to delete directories unless you are |
18173 | 17782 | superuser and the B<-U> flag is supplied to Perl. Even if these |
18174 | 17783 | conditions are met, be warned that unlinking a directory can inflict |
18175 | 17784 | damage on your filesystem. Finally, using C<unlink> on directories is |
18176 | 17785 | not supported on many operating systems. Use C<rmdir> instead. |
18177 | 17786 | |
18178 | 17787 | =end original |
18179 | 17788 | |
18180 | 17789 | 注: スーパーユーザ権限で、Perl に -U を付けて実行した場合でなければ、 |
18181 | 17790 | C<unlink> はディレクトリを削除しようとすることはありません。 |
18182 | 17791 | この条件にあう場合にも、ディレクトリの削除は、 |
18183 | 17792 | ファイルシステムに多大な損害を与える可能性があります。 |
18184 | 17793 | 最後に、C<unlink> をディレクトリに使うのはほとんどの OS では |
18185 | 17794 | 対応していません。 |
18186 | 17795 | 代わりに C<rmdir> を使ってください。 |
18187 | 17796 | |
18188 | 17797 | =begin original |
18189 | 17798 | |
18190 | 17799 | If LIST is omitted, C<unlink> uses C<$_>. |
18191 | 17800 | |
18192 | 17801 | =end original |
18193 | 17802 | |
18194 | 17803 | LIST が省略されると、C<unlink> は C<$_> を使います。 |
18195 | 17804 | |
18196 | 17805 | =item unpack TEMPLATE,EXPR |
18197 | 17806 | X<unpack> |
18198 | 17807 | |
18199 | 17808 | =item unpack TEMPLATE |
18200 | 17809 | |
18201 | 17810 | =for Pod::Functions convert binary structure into normal perl variables |
18202 | 17811 | |
18203 | 17812 | =begin original |
18204 | 17813 | |
18205 | 17814 | C<unpack> does the reverse of C<pack>: it takes a string |
18206 | 17815 | and expands it out into a list of values. |
18207 | 17816 | (In scalar context, it returns merely the first value produced.) |
18208 | 17817 | |
18209 | 17818 | =end original |
18210 | 17819 | |
18211 | 17820 | C<unpack> は C<pack> の逆を行ないます: 構造体を表わす文字列をとり、 |
18212 | 17821 | リスト値に展開し、その配列値を返します。 |
18213 | 17822 | (スカラコンテキストでは、単に最初の値を返します。) |
18214 | 17823 | |
18215 | 17824 | =begin original |
18216 | 17825 | |
18217 | 17826 | If EXPR is omitted, unpacks the C<$_> string. |
18218 | 17827 | See L<perlpacktut> for an introduction to this function. |
18219 | 17828 | |
18220 | 17829 | =end original |
18221 | 17830 | |
18222 | 17831 | EXPR が省略されると、C<$_> の文字列を unpack します。 |
18223 | 17832 | この関数の説明については L<perlpacktut> を参照してください。 |
18224 | 17833 | |
18225 | 17834 | =begin original |
18226 | 17835 | |
18227 | 17836 | The string is broken into chunks described by the TEMPLATE. Each chunk |
18228 | 17837 | is converted separately to a value. Typically, either the string is a result |
18229 | 17838 | of C<pack>, or the characters of the string represent a C structure of some |
18230 | 17839 | kind. |
18231 | 17840 | |
18232 | 17841 | =end original |
18233 | 17842 | |
18234 | 17843 | 文字列は TEMPLATE で示された固まりに分割されます。 |
18235 | 17844 | それぞれの固まりは別々に値に変換されます。 |
18236 | 17845 | 典型的には、文字列は C<pack> の結果あるいはある種の C の構造体の |
18237 | 17846 | 文字列表現の文字列です。 |
18238 | 17847 | |
18239 | 17848 | =begin original |
18240 | 17849 | |
18241 | 17850 | The TEMPLATE has the same format as in the C<pack> function. |
18242 | 17851 | Here's a subroutine that does substring: |
18243 | 17852 | |
18244 | 17853 | =end original |
18245 | 17854 | |
18246 | 17855 | TEMPLATE は、C<pack> 関数と同じフォーマットを使います。 |
18247 | 17856 | 部分文字列を取り出すうサブルーチンの例を示します: |
18248 | 17857 | |
18249 | 17858 | sub substr { |
18250 | 17859 | my($what,$where,$howmuch) = @_; |
18251 | 17860 | unpack("x$where a$howmuch", $what); |
18252 | 17861 | } |
18253 | 17862 | |
18254 | 17863 | =begin original |
18255 | 17864 | |
18256 | 17865 | and then there's |
18257 | 17866 | |
18258 | 17867 | =end original |
18259 | 17868 | |
18260 | 17869 | これもそうです。 |
18261 | 17870 | |
18262 | 17871 | sub ordinal { unpack("W",$_[0]); } # same as ord() |
18263 | 17872 | |
18264 | 17873 | =begin original |
18265 | 17874 | |
18266 | 17875 | In addition to fields allowed in pack(), you may prefix a field with |
18267 | 17876 | a %<number> to indicate that |
18268 | 17877 | you want a <number>-bit checksum of the items instead of the items |
18269 | 17878 | themselves. Default is a 16-bit checksum. Checksum is calculated by |
18270 | 17879 | summing numeric values of expanded values (for string fields the sum of |
18271 | 17880 | C<ord($char)> is taken; for bit fields the sum of zeroes and ones). |
18272 | 17881 | |
18273 | 17882 | =end original |
18274 | 17883 | |
18275 | 17884 | pack() で利用可能なフィールドの他に、 |
18276 | 17885 | フィールドの前に %<数値> というものを付けて、 |
18277 | 17886 | 項目自身の代わりに、その項目の <数値>-ビットのチェックサムを |
18278 | 17887 | 計算させることができます。 |
18279 | 17888 | デフォルトは、16-ビットチェックサムです。 |
18280 | 17889 | チェックサムは展開された値の数値としての値の合計 |
18281 | 17890 | (文字列フィールドの場合は C<ord($char)> の合計; |
18282 | 17891 | ビットフィールドの場合は 0 と 1 の合計) が用いられます。 |
18283 | 17892 | |
18284 | 17893 | =begin original |
18285 | 17894 | |
18286 | 17895 | For example, the following |
18287 | 17896 | computes the same number as the System V sum program: |
18288 | 17897 | |
18289 | 17898 | =end original |
18290 | 17899 | |
18291 | 17900 | たとえば、以下のコードは |
18292 | 17901 | System V の sum プログラムと同じ値を計算します。 |
18293 | 17902 | |
18294 | 17903 | $checksum = do { |
18295 | 17904 | local $/; # slurp! |
18296 | 17905 | unpack("%32W*",<>) % 65535; |
18297 | 17906 | }; |
18298 | 17907 | |
18299 | 17908 | =begin original |
18300 | 17909 | |
18301 | 17910 | The following efficiently counts the number of set bits in a bit vector: |
18302 | 17911 | |
18303 | 17912 | =end original |
18304 | 17913 | |
18305 | 17914 | 以下は、効率的にビットベクターの設定されているビットを |
18306 | 17915 | 数えるものです。 |
18307 | 17916 | |
18308 | 17917 | $setbits = unpack("%32b*", $selectmask); |
18309 | 17918 | |
18310 | 17919 | =begin original |
18311 | 17920 | |
18312 | 17921 | The C<p> and C<P> formats should be used with care. Since Perl |
18313 | 17922 | has no way of checking whether the value passed to C<unpack()> |
18314 | 17923 | corresponds to a valid memory location, passing a pointer value that's |
18315 | 17924 | not known to be valid is likely to have disastrous consequences. |
18316 | 17925 | |
18317 | 17926 | =end original |
18318 | 17927 | |
18319 | 17928 | C<p> と C<P> は注意深く使うべきです。 |
18320 | 17929 | Perl は C<unpack()> に渡された値が有効なメモリ位置を指しているかどうかを |
18321 | 17930 | 確認する方法がないので、有効かどうかわからないポインタ値を渡すと |
18322 | 17931 | 悲惨な結果を引き起こすかもしれません。 |
18323 | 17932 | |
18324 | 17933 | =begin original |
18325 | 17934 | |
18326 | 17935 | If there are more pack codes or if the repeat count of a field or a group |
18327 | 17936 | is larger than what the remainder of the input string allows, the result |
18328 | 17937 | is not well defined: the repeat count may be decreased, or |
18329 | 17938 | C<unpack()> may produce empty strings or zeros, or it may raise an exception. |
18330 | 17939 | If the input string is longer than one described by the TEMPLATE, |
18331 | 17940 | the remainder of that input string is ignored. |
18332 | 17941 | |
18333 | 17942 | =end original |
18334 | 17943 | |
18335 | 17944 | 多くの pack コードがある場合や、フィールドやグループの繰り返し回数が |
18336 | 17945 | 入力文字列の残りより大きい場合、結果は未定義です: |
18337 | 17946 | 繰り返し回数が減らされる場合もありますし、C<unpack()> が空文字列や 0 を |
18338 | 17947 | 返すこともありますし、例外が発生します。 |
18339 | 17948 | もし入力文字列が TEMPLATE で表現されているものより大きい場合、 |
18340 | 17949 | 入力文字列の残りは無視されます。 |
18341 | 17950 | |
18342 | 17951 | =begin original |
18343 | 17952 | |
18344 | 17953 | See L</pack> for more examples and notes. |
18345 | 17954 | |
18346 | 17955 | =end original |
18347 | 17956 | |
18348 | 17957 | さらなる例と注意に関しては L</pack> を参照してください。 |
18349 | 17958 | |
18350 | 17959 | =item unshift ARRAY,LIST |
18351 | 17960 | X<unshift> |
18352 | 17961 | |
18353 | 17962 | =item unshift EXPR,LIST |
18354 | 17963 | |
18355 | 17964 | =for Pod::Functions prepend more elements to the beginning of a list |
18356 | 17965 | |
18357 | 17966 | =begin original |
18358 | 17967 | |
18359 | 17968 | Does the opposite of a C<shift>. Or the opposite of a C<push>, |
18360 | 17969 | depending on how you look at it. Prepends list to the front of the |
18361 | 17970 | array and returns the new number of elements in the array. |
18362 | 17971 | |
18363 | 17972 | =end original |
18364 | 17973 | |
18365 | 17974 | C<shift> の逆操作を行ないます。 |
18366 | 17975 | 見方を変えれば、C<push> の逆操作とも考えられます。 |
18367 | 17976 | LIST を ARRAY の先頭に入れて、新しくできた配列の要素の数を返します。 |
18368 | 17977 | |
18369 | 17978 | unshift(@ARGV, '-e') unless $ARGV[0] =~ /^-/; |
18370 | 17979 | |
18371 | 17980 | =begin original |
18372 | 17981 | |
18373 | 17982 | Note the LIST is prepended whole, not one element at a time, so the |
18374 | 17983 | prepended elements stay in the same order. Use C<reverse> to do the |
18375 | 17984 | reverse. |
18376 | 17985 | |
18377 | 17986 | =end original |
18378 | 17987 | |
18379 | 17988 | LIST は、はらばらにではなく、一度に登録されるので、順番はそのままです。 |
18380 | 17989 | 逆順に登録するには、C<reverse> を使ってください。 |
18381 | 17990 | |
18382 | 17991 | =begin original |
18383 | 17992 | |
18384 | 17993 | Starting with Perl 5.14, C<unshift> can take a scalar EXPR, which must hold |
18385 | 17994 | a reference to an unblessed array. The argument will be dereferenced |
18386 | 17995 | automatically. This aspect of C<unshift> is considered highly |
18387 | 17996 | experimental. The exact behaviour may change in a future version of Perl. |
18388 | 17997 | |
18389 | 17998 | =end original |
18390 | 17999 | |
18391 | 18000 | Perl 5.14 から、C<unshift> はスカラの EXPR を取ることができるようになりました; |
18392 | 18001 | これは bless されていない配列へのリファレンスでなければなりません。 |
18393 | 18002 | 引数は自動的にデリファレンスされます。 |
18394 | 18003 | C<unshift> のこの動作は高度に実験的であると考えられています。 |
18395 | 18004 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 |
18396 | 18005 | |
18397 | 18006 | =begin original |
18398 | 18007 | |
18399 | 18008 | To avoid confusing would-be users of your code who are running earlier |
18400 | 18009 | versions of Perl with mysterious syntax errors, put this sort of thing at |
18401 | 18010 | the top of your file to signal that your code will work I<only> on Perls of |
18402 | 18011 | a recent vintage: |
18403 | 18012 | |
18404 | 18013 | =end original |
18405 | 18014 | |
18406 | 18015 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な |
18407 | 18016 | 文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で |
18408 | 18017 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを |
18409 | 18018 | 書いてください: |
18410 | 18019 | |
18411 | 18020 | use 5.014; # so push/pop/etc work on scalars (experimental) |
18412 | 18021 | |
18413 | 18022 | =item untie VARIABLE |
18414 | 18023 | X<untie> |
18415 | 18024 | |
18416 | 18025 | =for Pod::Functions break a tie binding to a variable |
18417 | 18026 | |
18418 | 18027 | =begin original |
18419 | 18028 | |
18420 | 18029 | Breaks the binding between a variable and a package. |
18421 | 18030 | (See L<tie|/tie VARIABLE,CLASSNAME,LIST>.) |
18422 | 18031 | Has no effect if the variable is not tied. |
18423 | 18032 | |
18424 | 18033 | =end original |
18425 | 18034 | |
18426 | 18035 | 変数とパッケージの間の結合を解きます。 |
18427 | 18036 | (L<tie|/tie VARIABLE,CLASSNAME,LIST> を参照してください。) |
18428 | 18037 | 結合されていない場合は何も起きません。 |
18429 | 18038 | |
18430 | 18039 | =item use Module VERSION LIST |
18431 | 18040 | X<use> X<module> X<import> |
18432 | 18041 | |
18433 | 18042 | =item use Module VERSION |
18434 | 18043 | |
18435 | 18044 | =item use Module LIST |
18436 | 18045 | |
18437 | 18046 | =item use Module |
18438 | 18047 | |
18439 | 18048 | =item use VERSION |
18440 | 18049 | |
18441 | 18050 | =for Pod::Functions load in a module at compile time and import its namespace |
18442 | 18051 | |
18443 | 18052 | =begin original |
18444 | 18053 | |
18445 | 18054 | Imports some semantics into the current package from the named module, |
18446 | 18055 | generally by aliasing certain subroutine or variable names into your |
18447 | 18056 | package. It is exactly equivalent to |
18448 | 18057 | |
18449 | 18058 | =end original |
18450 | 18059 | |
18451 | 18060 | 指定したモジュールから、現在のパッケージにさまざまな内容をインポートします; |
18452 | 18061 | 多くは、パッケージのサブルーチン名や、変数名に別名を付けることで、 |
18453 | 18062 | 実現されています。 |
18454 | 18063 | これは、以下は等価ですが: |
18455 | 18064 | |
18456 | 18065 | BEGIN { require Module; Module->import( LIST ); } |
18457 | 18066 | |
18458 | 18067 | =begin original |
18459 | 18068 | |
18460 | 18069 | except that Module I<must> be a bareword. |
18461 | The importation can be made conditional | |
18070 | The importation can be made conditional; see L<if>. | |
18462 | 18071 | |
18463 | 18072 | =end original |
18464 | 18073 | |
18465 | 18074 | Module が I<裸の単語でなければならない> ことを除けば、です。 |
18466 | インポートは | |
18075 | インポートは条件付きで行うことができます; L<if> を参照してください。 | |
18467 | 18076 | |
18468 | 18077 | =begin original |
18469 | 18078 | |
18470 | 18079 | In the peculiar C<use VERSION> form, VERSION may be either a positive |
18471 | 18080 | decimal fraction such as 5.006, which will be compared to C<$]>, or a v-string |
18472 | 18081 | of the form v5.6.1, which will be compared to C<$^V> (aka $PERL_VERSION). An |
18473 | 18082 | exception is raised if VERSION is greater than the version of the |
18474 | 18083 | current Perl interpreter; Perl will not attempt to parse the rest of the |
18475 | 18084 | file. Compare with L</require>, which can do a similar check at run time. |
18476 | 18085 | Symmetrically, C<no VERSION> allows you to specify that you want a version |
18477 | 18086 | of Perl older than the specified one. |
18478 | 18087 | |
18479 | 18088 | =end original |
18480 | 18089 | |
18481 | 18090 | 特に C<use VERSION> の形式では、 |
18482 | 18091 | VERSION は 5.006 のような正の 10 進小数 (C<$]> と比較されます)か、v5.6.1 の形 |
18483 | 18092 | (C<$^V> (またの名を $PERL_VERSION) と比較されます) のv-文字列で指定します。 |
18484 | 18093 | VERSION が Perl の現在のバージョンより大きいと、例外が発生します; |
18485 | 18094 | Perl はファイルの残りを読み込みません。 |
18486 | 18095 | L</require> と似ていますが、これは実行時にチェックされます。 |
18487 | 18096 | 対称的に、C<no VERSION> は指定されたバージョンより古いバージョンの Perl で |
18488 | 18097 | 動作させたいことを意味します。 |
18489 | 18098 | |
18490 | 18099 | =begin original |
18491 | 18100 | |
18492 | 18101 | Specifying VERSION as a literal of the form v5.6.1 should generally be |
18493 | 18102 | avoided, because it leads to misleading error messages under earlier |
18494 | 18103 | versions of Perl (that is, prior to 5.6.0) that do not support this |
18495 | 18104 | syntax. The equivalent numeric version should be used instead. |
18496 | 18105 | |
18497 | 18106 | =end original |
18498 | 18107 | |
18499 | 18108 | VERSION に v5.6.1 の形のリテラルを指定することは一般的には避けるべきです; |
18500 | 18109 | なぜなら、この文法に対応していない Perl の初期のバージョン |
18501 | 18110 | (つまり、 5.6.0 以前) では誤解させるようなエラーメッセージが出るからです。 |
18502 | 18111 | 代わりに等価な数値表現を使うべきです。 |
18503 | 18112 | |
18504 | 18113 | use v5.6.1; # compile time version check |
18505 | 18114 | use 5.6.1; # ditto |
18506 | 18115 | use 5.006_001; # ditto; preferred for backwards compatibility |
18507 | 18116 | |
18508 | 18117 | =begin original |
18509 | 18118 | |
18510 | 18119 | This is often useful if you need to check the current Perl version before |
18511 | 18120 | C<use>ing library modules that won't work with older versions of Perl. |
18512 | 18121 | (We try not to do this more than we have to.) |
18513 | 18122 | |
18514 | 18123 | =end original |
18515 | 18124 | |
18516 | 18125 | これは古いバージョンの Perl で動かなくなったライブラリモジュールを |
18517 | 18126 | C<use> する前に、現在の Perl のバージョンを調べたい場合に有用です。 |
18518 | 18127 | (我々は必要な場合以外にそのようなことがないように努力していますが。) |
18519 | 18128 | |
18520 | 18129 | =begin original |
18521 | 18130 | |
18522 | 18131 | C<use VERSION> also enables all features available in the requested |
18523 | 18132 | version as defined by the C<feature> pragma, disabling any features |
18524 | 18133 | not in the requested version's feature bundle. See L<feature>. |
18525 | 18134 | Similarly, if the specified Perl version is greater than or equal to |
18526 | 5.1 | |
18135 | 5.11.0, strictures are enabled lexically as | |
18527 | 18136 | with C<use strict>. Any explicit use of |
18528 | 18137 | C<use strict> or C<no strict> overrides C<use VERSION>, even if it comes |
18529 | 18138 | before it. In both cases, the F<feature.pm> and F<strict.pm> files are |
18530 | 18139 | not actually loaded. |
18531 | 18140 | |
18532 | 18141 | =end original |
18533 | 18142 | |
18534 | 18143 | C<use VERSION> は、C<feature> プラグマで定義されたように、指定された |
18535 | 18144 | バージョンで利用可能な全ての機能を有効にし、指定されたバージョンの機能の |
18536 | 18145 | 束にない機能を無効にします。 |
18537 | 18146 | L<feature> を参照してください。 |
18538 | 同様に、指定された Perl のバージョンが 5.1 | |
18147 | 同様に、指定された Perl のバージョンが 5.11.0 以上の場合、 | |
18539 | 18148 | 制限は C<use strict> と同様にレキシカルに有効になります。 |
18540 | 18149 | 明示的に C<use strict> や C<no strict> を使うと、例え先に |
18541 | 18150 | 指定されていたとしても、C<use VERSION> を上書きします。 |
18542 | 18151 | どちらの場合も、F<feature.pm> と F<strict.pm> ファイルは実際には |
18543 | 18152 | 読み込まれません。 |
18544 | 18153 | |
18545 | 18154 | =begin original |
18546 | 18155 | |
18547 | 18156 | The C<BEGIN> forces the C<require> and C<import> to happen at compile time. The |
18548 | 18157 | C<require> makes sure the module is loaded into memory if it hasn't been |
18549 | 18158 | yet. The C<import> is not a builtin; it's just an ordinary static method |
18550 | 18159 | call into the C<Module> package to tell the module to import the list of |
18551 | 18160 | features back into the current package. The module can implement its |
18552 | 18161 | C<import> method any way it likes, though most modules just choose to |
18553 | 18162 | derive their C<import> method via inheritance from the C<Exporter> class that |
18554 | 18163 | is defined in the C<Exporter> module. See L<Exporter>. If no C<import> |
18555 | 18164 | method can be found then the call is skipped, even if there is an AUTOLOAD |
18556 | 18165 | method. |
18557 | 18166 | |
18558 | 18167 | =end original |
18559 | 18168 | |
18560 | 18169 | C<BEGIN> によって、C<require> や C<import> は、コンパイル時に |
18561 | 18170 | 実行されることになります。 |
18562 | 18171 | C<require> は、モジュールがまだメモリにロードされていなければ、ロードします。 |
18563 | 18172 | C<import> は、組込みの関数ではありません; さまざまな機能を現在のパッケージに |
18564 | 18173 | インポートするように C<Module> パッケージに伝えるために呼ばれる、 |
18565 | 18174 | 通常の静的メソッドです。 |
18566 | 18175 | モジュール側では、C<import> メソッドをどのようにでも実装することが |
18567 | 18176 | できますが、多くのモジュールでは、C<Exporter> モジュールで定義された、 |
18568 | 18177 | C<Exporter> クラスからの継承によって、C<import> メソッドを行なうように |
18569 | 18178 | しています。 |
18570 | 18179 | L<Exporter>モジュールを参照してください。 |
18571 | 18180 | C<import>メソッドが見つからなかった場合、AUTOLOAD メソッドがあったとしても |
18572 | 18181 | 呼び出しはスキップされます。 |
18573 | 18182 | |
18574 | 18183 | =begin original |
18575 | 18184 | |
18576 | 18185 | If you do not want to call the package's C<import> method (for instance, |
18577 | 18186 | to stop your namespace from being altered), explicitly supply the empty list: |
18578 | 18187 | |
18579 | 18188 | =end original |
18580 | 18189 | |
18581 | 18190 | パッケージの C<import> メソッドを呼び出したくない場合(例えば、名前空間を |
18582 | 18191 | 変更したくない場合など)は、明示的に空リストを指定してください: |
18583 | 18192 | |
18584 | 18193 | use Module (); |
18585 | 18194 | |
18586 | 18195 | =begin original |
18587 | 18196 | |
18588 | 18197 | That is exactly equivalent to |
18589 | 18198 | |
18590 | 18199 | =end original |
18591 | 18200 | |
18592 | 18201 | これは以下と完全に等価です: |
18593 | 18202 | |
18594 | 18203 | BEGIN { require Module } |
18595 | 18204 | |
18596 | 18205 | =begin original |
18597 | 18206 | |
18598 | 18207 | If the VERSION argument is present between Module and LIST, then the |
18599 | 18208 | C<use> will call the VERSION method in class Module with the given |
18600 | 18209 | version as an argument. The default VERSION method, inherited from |
18601 | 18210 | the UNIVERSAL class, croaks if the given version is larger than the |
18602 | 18211 | value of the variable C<$Module::VERSION>. |
18603 | 18212 | |
18604 | 18213 | =end original |
18605 | 18214 | |
18606 | 18215 | Module と LIST の間に VERSION 引数がある場合、C<use> は Module クラスの |
18607 | 18216 | VERSION メソッドを、与えられたバージョンを引数として呼び出します。 |
18608 | 18217 | デフォルトの VERSION メソッドは、 UNIVERSAL クラスから継承したもので、 |
18609 | 18218 | 与えられたバージョンが 変数 C<$Module::VERSION> の値より大きい場合に |
18610 | 18219 | 警告を出します。 |
18611 | 18220 | |
18612 | 18221 | =begin original |
18613 | 18222 | |
18614 | 18223 | Again, there is a distinction between omitting LIST (C<import> called |
18615 | 18224 | with no arguments) and an explicit empty LIST C<()> (C<import> not |
18616 | 18225 | called). Note that there is no comma after VERSION! |
18617 | 18226 | |
18618 | 18227 | =end original |
18619 | 18228 | |
18620 | 18229 | 繰り返すと、LIST を省略する(C<import> が引数なしで呼び出される)ことと |
18621 | 18230 | 明示的に空の LIST C<()> を指定する (C<import> は呼び出されない)ことは |
18622 | 18231 | 違います。 |
18623 | 18232 | VERSION の後ろにカンマが不要なことに注意してください! |
18624 | 18233 | |
18625 | 18234 | =begin original |
18626 | 18235 | |
18627 | 18236 | Because this is a wide-open interface, pragmas (compiler directives) |
18628 | 18237 | are also implemented this way. Currently implemented pragmas are: |
18629 | 18238 | |
18630 | 18239 | =end original |
18631 | 18240 | |
18632 | 18241 | これは、広く公開されているインタフェースですので、 |
18633 | 18242 | プラグマ (コンパイラディレクティブ) も、この方法で実装されています。 |
18634 | 18243 | 現在実装されているプラグマには、以下のものがあります: |
18635 | 18244 | |
18636 | 18245 | use constant; |
18637 | 18246 | use diagnostics; |
18638 | 18247 | use integer; |
18639 | 18248 | use sigtrap qw(SEGV BUS); |
18640 | 18249 | use strict qw(subs vars refs); |
18641 | 18250 | use subs qw(afunc blurfl); |
18642 | 18251 | use warnings qw(all); |
18643 | 18252 | use sort qw(stable _quicksort _mergesort); |
18644 | 18253 | |
18645 | 18254 | =begin original |
18646 | 18255 | |
18647 | 18256 | Some of these pseudo-modules import semantics into the current |
18648 | 18257 | block scope (like C<strict> or C<integer>, unlike ordinary modules, |
18649 | 18258 | which import symbols into the current package (which are effective |
18650 | 18259 | through the end of the file). |
18651 | 18260 | |
18652 | 18261 | =end original |
18653 | 18262 | |
18654 | 18263 | 通常のモジュールが、現在のパッケージにシンボルをインポートする |
18655 | 18264 | (これは、ファイルの終わりまで有効です) のに対して、 |
18656 | 18265 | これらの擬似モジュールの一部(C<strict> や C<integer> など)は、 |
18657 | 18266 | 現在のブロックスコープにインポートを行ないます。 |
18658 | 18267 | |
18659 | 18268 | =begin original |
18660 | 18269 | |
18661 | 18270 | Because C<use> takes effect at compile time, it doesn't respect the |
18662 | 18271 | ordinary flow control of the code being compiled. In particular, putting |
18663 | 18272 | a C<use> inside the false branch of a conditional doesn't prevent it |
18664 | 18273 | from being processed. If a module or pragma only needs to be loaded |
18665 | 18274 | conditionally, this can be done using the L<if> pragma: |
18666 | 18275 | |
18667 | 18276 | =end original |
18668 | 18277 | |
18669 | 18278 | C<use> はコンパイル時に有効なので、コードがコンパイルされる際の通常の |
18670 | 18279 | 流れ制御には従いません。 |
18671 | 18280 | 特に、条件文のうち成立しない側の中に C<use> を書いても、 |
18672 | 18281 | 処理を妨げられません。 |
18673 | 18282 | モジュールやプラグマを条件付きでのみ読み込みたい場合、 |
18674 | 18283 | L<if> プラグマを使って実現できます: |
18675 | 18284 | |
18676 | 18285 | use if $] < 5.008, "utf8"; |
18677 | 18286 | use if WANT_WARNINGS, warnings => qw(all); |
18678 | 18287 | |
18679 | 18288 | =begin original |
18680 | 18289 | |
18681 | 18290 | There's a corresponding C<no> declaration that unimports meanings imported |
18682 | 18291 | by C<use>, i.e., it calls C<unimport Module LIST> instead of C<import>. |
18683 | 18292 | It behaves just as C<import> does with VERSION, an omitted or empty LIST, |
18684 | 18293 | or no unimport method being found. |
18685 | 18294 | |
18686 | 18295 | =end original |
18687 | 18296 | |
18688 | 18297 | これに対して、C<no> 宣言という、C<use> によってインポートされたものを、 |
18689 | 18298 | インポートされていないことにするものがあります; つまり、C<import> の代わりに |
18690 | 18299 | C<unimport Module LIST> を呼び出します。 |
18691 | 18300 | これは VERSION、省略された LIST、空の LIST、unimport メソッドが見つからない |
18692 | 18301 | 場合などの観点では、C<import> と同様に振る舞います。 |
18693 | 18302 | |
18694 | 18303 | no integer; |
18695 | 18304 | no strict 'refs'; |
18696 | 18305 | no warnings; |
18697 | 18306 | |
18698 | 18307 | =begin original |
18699 | 18308 | |
18700 | 18309 | Care should be taken when using the C<no VERSION> form of C<no>. It is |
18701 | 18310 | I<only> meant to be used to assert that the running Perl is of a earlier |
18702 | 18311 | version than its argument and I<not> to undo the feature-enabling side effects |
18703 | 18312 | of C<use VERSION>. |
18704 | 18313 | |
18705 | 18314 | =end original |
18706 | 18315 | |
18707 | 18316 | C<no> の C<no VERSION> 形式を使うときには注意を払うべきです。 |
18708 | 18317 | これは引数で指定されたバージョンよりも前の Perl で実行されたときに |
18709 | 18318 | アサートされることを意味する I<だけ> で、C<use VERSION> によって |
18710 | 18319 | 有効にされた副作用をなかったことにするもの I<ではありません>。 |
18711 | 18320 | |
18712 | 18321 | =begin original |
18713 | 18322 | |
18714 | 18323 | See L<perlmodlib> for a list of standard modules and pragmas. See L<perlrun> |
18715 | 18324 | for the C<-M> and C<-m> command-line options to Perl that give C<use> |
18716 | 18325 | functionality from the command-line. |
18717 | 18326 | |
18718 | 18327 | =end original |
18719 | 18328 | |
18720 | 18329 | 標準モジュールやプラグマの一覧は、L<perlmodlib> を参照してください。 |
18721 | 18330 | コマンドラインから C<use> 機能を指定するための C<-M> と C<-m> の |
18722 | 18331 | コマンドラインオプションについては L<perlrun> を参照してください。 |
18723 | 18332 | |
18724 | 18333 | =item utime LIST |
18725 | 18334 | X<utime> |
18726 | 18335 | |
18727 | 18336 | =for Pod::Functions set a file's last access and modify times |
18728 | 18337 | |
18729 | 18338 | =begin original |
18730 | 18339 | |
18731 | 18340 | Changes the access and modification times on each file of a list of |
18732 | 18341 | files. The first two elements of the list must be the NUMERIC access |
18733 | 18342 | and modification times, in that order. Returns the number of files |
18734 | 18343 | successfully changed. The inode change time of each file is set |
18735 | 18344 | to the current time. For example, this code has the same effect as the |
18736 | 18345 | Unix touch(1) command when the files I<already exist> and belong to |
18737 | 18346 | the user running the program: |
18738 | 18347 | |
18739 | 18348 | =end original |
18740 | 18349 | |
18741 | 18350 | ファイルのアクセス時刻と修正(modification) 時刻を変更します。 |
18742 | 18351 | LIST の最初の二つの要素に、数値で表わしたアクセス時刻と修正時刻を |
18743 | 18352 | 順に指定します。 |
18744 | 18353 | 変更に成功したファイルの数を返します。 |
18745 | 18354 | 各ファイルの inode 変更(change)時刻には、その時点の時刻が設定されます。 |
18746 | 18355 | 例えば、このコードはファイルが I<既に存在して> いて、ユーザーが |
18747 | 18356 | 実行しているプログラムに従っているなら、 |
18748 | 18357 | Unix の touch(1) コマンドと同じ効果があります。 |
18749 | 18358 | |
18750 | 18359 | #!/usr/bin/perl |
18751 | 18360 | $atime = $mtime = time; |
18752 | 18361 | utime $atime, $mtime, @ARGV; |
18753 | 18362 | |
18754 | 18363 | =begin original |
18755 | 18364 | |
18756 | Since Perl 5. | |
18365 | Since Perl 5.7.2, if the first two elements of the list are C<undef>, | |
18757 | 18366 | the utime(2) syscall from your C library is called with a null second |
18758 | 18367 | argument. On most systems, this will set the file's access and |
18759 | 18368 | modification times to the current time (i.e., equivalent to the example |
18760 | 18369 | above) and will work even on files you don't own provided you have write |
18761 | 18370 | permission: |
18762 | 18371 | |
18763 | 18372 | =end original |
18764 | 18373 | |
18765 | Perl 5. | |
18374 | Perl 5.7.2 から、リストの最初の二つの要素が C<undef> である場合、 | |
18766 | 18375 | C ライブラリの utime(2) システムコールを、秒の引数を null として |
18767 | 18376 | 呼び出します。 |
18768 | 18377 | ほとんどのシステムでは、これによってファイルのアクセス時刻と修正時刻を |
18769 | 18378 | 現在の時刻にセットし(つまり、上記の例と等価です)、 |
18770 | 18379 | 書き込み権限があれば他のユーザーのファイルに対しても動作します。 |
18771 | 18380 | |
18772 | 18381 | for $file (@ARGV) { |
18773 | 18382 | utime(undef, undef, $file) |
18774 | 18383 | || warn "couldn't touch $file: $!"; |
18775 | 18384 | } |
18776 | 18385 | |
18777 | 18386 | =begin original |
18778 | 18387 | |
18779 | 18388 | Under NFS this will use the time of the NFS server, not the time of |
18780 | 18389 | the local machine. If there is a time synchronization problem, the |
18781 | 18390 | NFS server and local machine will have different times. The Unix |
18782 | 18391 | touch(1) command will in fact normally use this form instead of the |
18783 | 18392 | one shown in the first example. |
18784 | 18393 | |
18785 | 18394 | =end original |
18786 | 18395 | |
18787 | 18396 | NFS では、これはローカルマシンの時刻ではなく、NFS サーバーの時刻が |
18788 | 18397 | 使われます。 |
18789 | 18398 | 時刻同期に問題がある場合、NFS サーバーとローカルマシンで違う時刻に |
18790 | 18399 | なっている場合があります。 |
18791 | 18400 | 実際のところ、Unix の touch(1) コマンドは普通、最初の例ではなく、 |
18792 | 18401 | この形を使います。 |
18793 | 18402 | |
18794 | 18403 | =begin original |
18795 | 18404 | |
18796 | 18405 | Passing only one of the first two elements as C<undef> is |
18797 | 18406 | equivalent to passing a 0 and will not have the effect |
18798 | 18407 | described when both are C<undef>. This also triggers an |
18799 | 18408 | uninitialized warning. |
18800 | 18409 | |
18801 | 18410 | =end original |
18802 | 18411 | |
18803 | 18412 | 最初の二つの要素のうち、一つだけに C<undef> を渡すと、その要素は 0 を |
18804 | 18413 | 渡すのと等価となり、上述の、両方に C<undef> を渡した時と同じ |
18805 | 18414 | 効果ではありません。 |
18806 | 18415 | この場合は、未初期化の警告が出ます。 |
18807 | 18416 | |
18808 | 18417 | =begin original |
18809 | 18418 | |
18810 | 18419 | On systems that support futimes(2), you may pass filehandles among the |
18811 | 18420 | files. On systems that don't support futimes(2), passing filehandles raises |
18812 | 18421 | an exception. Filehandles must be passed as globs or glob references to be |
18813 | 18422 | recognized; barewords are considered filenames. |
18814 | 18423 | |
18815 | 18424 | =end original |
18816 | 18425 | |
18817 | 18426 | futimes(2) に対応しているシステムでは、ファイルハンドルを引数として |
18818 | 18427 | 渡せます。 |
18819 | 18428 | futimes(2) に対応していないシステムでは、ファイルハンドルを渡すと |
18820 | 18429 | 例外が発生します。 |
18821 | 18430 | ファイルハンドルを認識させるためには、グロブまたはリファレンスとして |
18822 | 18431 | 渡されなければなりません; 裸の単語はファイル名として扱われます。 |
18823 | 18432 | |
18824 | 18433 | =begin original |
18825 | 18434 | |
18826 | 18435 | Portability issues: L<perlport/utime>. |
18827 | 18436 | |
18828 | 18437 | =end original |
18829 | 18438 | |
18830 | 18439 | 移植性の問題: L<perlport/utime>。 |
18831 | 18440 | |
18832 | 18441 | =item values HASH |
18833 | 18442 | X<values> |
18834 | 18443 | |
18835 | 18444 | =item values ARRAY |
18836 | 18445 | |
18837 | 18446 | =item values EXPR |
18838 | 18447 | |
18839 | 18448 | =for Pod::Functions return a list of the values in a hash |
18840 | 18449 | |
18841 | 18450 | =begin original |
18842 | 18451 | |
18843 | 18452 | In list context, returns a list consisting of all the values of the named |
18844 | 18453 | hash. In Perl 5.12 or later only, will also return a list of the values of |
18845 | 18454 | an array; prior to that release, attempting to use an array argument will |
18846 | 18455 | produce a syntax error. In scalar context, returns the number of values. |
18847 | 18456 | |
18848 | 18457 | =end original |
18849 | 18458 | |
18850 | 18459 | リストコンテキストでは、指定したハッシュのすべての値を返します。 |
18851 | Perl 5.12 以降でのみ、配列の全ての値からなるリストも | |
18460 | Perl 5.12 以降でのみ、配列の全ての値からなるリストも | |
18852 | このリリースの前では、配列要素に使おうとすると文法エラーが | |
18461 | 返します; このリリースの前では、配列要素に使おうとすると文法エラーが | |
18462 | 発生します。 | |
18853 | 18463 | スカラコンテキストでは、値の数を返します。 |
18854 | 18464 | |
18855 | 18465 | =begin original |
18856 | 18466 | |
18857 | ||
18467 | When called on a hash, the values are returned in an apparently random | |
18858 | order | |
18468 | order. The actual random order is subject to change in future versions of | |
18859 | ||
18469 | Perl, but it is guaranteed to be the same order as either the C<keys> or | |
18860 | ||
18470 | C<each> function would produce on the same (unmodified) hash. Since Perl | |
18861 | ||
18471 | 5.8.1 the ordering is different even between different runs of Perl for | |
18862 | ||
18472 | security reasons (see L<perlsec/"Algorithmic Complexity Attacks">). | |
18863 | rely on C<keys>, C<values> and C<each> to repeatedly return the same order | |
18864 | as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for | |
18865 | details on why hash order is randomized. Aside from the guarantees | |
18866 | provided here the exact details of Perl's hash algorithm and the hash | |
18867 | traversal order are subject to change in any release of Perl. Tied hashes | |
18868 | may behave differently to Perl's hashes with respect to changes in order on | |
18869 | insertion and deletion of items. | |
18870 | 18473 | |
18871 | 18474 | =end original |
18872 | 18475 | |
18873 | ハッシュ | |
18476 | ハッシュに対して呼び出されると、返される value の順序は、見た目に | |
18874 | ||
18477 | ばらばらなものです。 | |
18875 | ||
18478 | 実際のランダムな順序は将来のバージョンの Perl では変わる可能性が | |
18876 | ハッシュ | |
18479 | ありますが、同じ(変更されていない)ハッシュに対して、 | |
18877 | C<e | |
18480 | C<keys>関数や C<each>関数が返すものと同じ順序であることは保証されます。 | |
18878 | ||
18481 | Perl 5.8.1 以降ではセキュリティ上の理由により、 | |
18879 | ||
18482 | 実行される毎に順番は変わります | |
18880 | ||
18483 | (L<perlsec/"Algorithmic Complexity Attacks"> を参照してください)。 | |
18881 | なぜハッシュの順序がランダム化されているかの詳細については | |
18882 | L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。 | |
18883 | ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の | |
18884 | 正確な詳細は Perl のリリースによって変更される可能性があります。 | |
18885 | tie されたハッシュは、アイテムの挿入と削除の順序に関して Perl のハッシュと | |
18886 | 異なった振る舞いをします。 | |
18887 | 18484 | |
18888 | 18485 | =begin original |
18889 | 18486 | |
18890 | 18487 | As a side effect, calling values() resets the HASH or ARRAY's internal |
18891 | 18488 | iterator, see L</each>. (In particular, calling values() in void context |
18892 | 18489 | resets the iterator with no other overhead. Apart from resetting the |
18893 | 18490 | iterator, C<values @array> in list context is the same as plain C<@array>. |
18894 | 18491 | (We recommend that you use void context C<keys @array> for this, but |
18895 | 18492 | reasoned that taking C<values @array> out would require more |
18896 | 18493 | documentation than leaving it in.) |
18897 | 18494 | |
18898 | 18495 | =end original |
18899 | 18496 | |
18900 | 18497 | 副作用として、values() を呼び出すと HASH や ARRAY の内部反復子を |
18901 | 18498 | リセットします; C</each> を参照してください。 |
18902 | 18499 | (特に、values() を無効コンテキストで呼び出すとその他のオーバーヘッドなしで |
18903 | 18500 | 反復子をリセットします。 |
18904 | 18501 | 反復子をリセットするということを除けば、 |
18905 | 18502 | リストコンテキストでの C<values @array> は単なる C<@array> と同じです。 |
18906 | 18503 | この目的のためには無効コンテキストで C<keys @array> を使うことを |
18907 | 18504 | お勧めしますが、C<values @array> を取り出すにはそのままにするよりも |
18908 | 18505 | より多くの文書が必要だと判断しました。) |
18909 | 18506 | |
18910 | 18507 | =begin original |
18911 | 18508 | |
18912 | 18509 | Note that the values are not copied, which means modifying them will |
18913 | 18510 | modify the contents of the hash: |
18914 | 18511 | |
18915 | 18512 | =end original |
18916 | 18513 | |
18917 | 18514 | 値はコピーされないので、返されたリストを変更すると |
18918 | 18515 | ハッシュの中身が変更されることに注意してください。 |
18919 | 18516 | |
18920 | for (values %hash) { s/foo/bar/g } # modifies %hash values | |
18517 | for (values %hash) { s/foo/bar/g } # modifies %hash values | |
18921 | for (@hash{keys %hash}) { s/foo/bar/g } # same | |
18518 | for (@hash{keys %hash}) { s/foo/bar/g } # same | |
18922 | 18519 | |
18923 | 18520 | =begin original |
18924 | 18521 | |
18925 | 18522 | Starting with Perl 5.14, C<values> can take a scalar EXPR, which must hold |
18926 | 18523 | a reference to an unblessed hash or array. The argument will be |
18927 | 18524 | dereferenced automatically. This aspect of C<values> is considered highly |
18928 | 18525 | experimental. The exact behaviour may change in a future version of Perl. |
18929 | 18526 | |
18930 | 18527 | =end original |
18931 | 18528 | |
18932 | 18529 | Perl 5.14 から、C<values> はスカラの EXPR を取ることができるようになりました; |
18933 | 18530 | これは bless されていないハッシュや配列へのリファレンスでなければなりません。 |
18934 | 18531 | 引数は自動的にデリファレンスされます。 |
18935 | 18532 | C<values> のこの動作は高度に実験的であると考えられています。 |
18936 | 18533 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 |
18937 | 18534 | |
18938 | 18535 | for (values $hashref) { ... } |
18939 | 18536 | for (values $obj->get_arrayref) { ... } |
18940 | 18537 | |
18941 | 18538 | =begin original |
18942 | 18539 | |
18943 | 18540 | To avoid confusing would-be users of your code who are running earlier |
18944 | 18541 | versions of Perl with mysterious syntax errors, put this sort of thing at |
18945 | 18542 | the top of your file to signal that your code will work I<only> on Perls of |
18946 | 18543 | a recent vintage: |
18947 | 18544 | |
18948 | 18545 | =end original |
18949 | 18546 | |
18950 | 18547 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な |
18951 | 18548 | 文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で |
18952 | 18549 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを |
18953 | 18550 | 書いてください: |
18954 | 18551 | |
18955 | 18552 | use 5.012; # so keys/values/each work on arrays |
18956 | 18553 | use 5.014; # so keys/values/each work on scalars (experimental) |
18957 | 18554 | |
18958 | 18555 | =begin original |
18959 | 18556 | |
18960 | 18557 | See also C<keys>, C<each>, and C<sort>. |
18961 | 18558 | |
18962 | 18559 | =end original |
18963 | 18560 | |
18964 | 18561 | C<keys>, C<each>, C<sort> も参照してください。 |
18965 | 18562 | |
18966 | 18563 | =item vec EXPR,OFFSET,BITS |
18967 | 18564 | X<vec> X<bit> X<bit vector> |
18968 | 18565 | |
18969 | 18566 | =for Pod::Functions test or set particular bits in a string |
18970 | 18567 | |
18971 | 18568 | =begin original |
18972 | 18569 | |
18973 | 18570 | Treats the string in EXPR as a bit vector made up of elements of |
18974 | 18571 | width BITS and returns the value of the element specified by OFFSET |
18975 | 18572 | as an unsigned integer. BITS therefore specifies the number of bits |
18976 | 18573 | that are reserved for each element in the bit vector. This must |
18977 | 18574 | be a power of two from 1 to 32 (or 64, if your platform supports |
18978 | 18575 | that). |
18979 | 18576 | |
18980 | 18577 | =end original |
18981 | 18578 | |
18982 | 18579 | 文字列 EXPR を BITS 幅の要素からなるビットベクターとして扱い、 |
18983 | 18580 | OFFSET で指定された要素を符号なし整数として返します。 |
18984 | 18581 | 従って、 BITS はビットベクターの中の各要素について予約されるビット数です。 |
18985 | 18582 | BIT は、1 から 32 まで(プラットホームが |
18986 | 18583 | 対応していれば 64 まで) の 2 のべき乗でなければなりません。 |
18987 | 18584 | |
18988 | 18585 | =begin original |
18989 | 18586 | |
18990 | 18587 | If BITS is 8, "elements" coincide with bytes of the input string. |
18991 | 18588 | |
18992 | 18589 | =end original |
18993 | 18590 | |
18994 | 18591 | BITS が 8 の場合、「要素」は入力文字列の各バイトと一致します。 |
18995 | 18592 | |
18996 | 18593 | =begin original |
18997 | 18594 | |
18998 | 18595 | If BITS is 16 or more, bytes of the input string are grouped into chunks |
18999 | 18596 | of size BITS/8, and each group is converted to a number as with |
19000 | 18597 | pack()/unpack() with big-endian formats C<n>/C<N> (and analogously |
19001 | 18598 | for BITS==64). See L<"pack"> for details. |
19002 | 18599 | |
19003 | 18600 | =end original |
19004 | 18601 | |
19005 | 18602 | BITS が 16 以上の場合、入力のバイト列は BITS/8 のサイズの固まりに |
19006 | 18603 | グループ化され、各グループは pack()/unpack() のビッグエンディアン |
19007 | 18604 | フォーマット C<n>/C<N> を用いて(BITS==64 の類似として)数値に変換されます。 |
19008 | 18605 | 詳細は L<"pack"> を参照してください。 |
19009 | 18606 | |
19010 | 18607 | =begin original |
19011 | 18608 | |
19012 | 18609 | If bits is 4 or less, the string is broken into bytes, then the bits |
19013 | 18610 | of each byte are broken into 8/BITS groups. Bits of a byte are |
19014 | 18611 | numbered in a little-endian-ish way, as in C<0x01>, C<0x02>, |
19015 | 18612 | C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80>. For example, |
19016 | 18613 | breaking the single input byte C<chr(0x36)> into two groups gives a list |
19017 | 18614 | C<(0x6, 0x3)>; breaking it into 4 groups gives C<(0x2, 0x1, 0x3, 0x0)>. |
19018 | 18615 | |
19019 | 18616 | =end original |
19020 | 18617 | |
19021 | 18618 | BITS が 4 以下の場合、文字列はバイトに分解され、バイトの各ビットは |
19022 | 18619 | 8/BITS 個のグループに分割されます。 |
19023 | 18620 | ビットはリトルエンディアン風に、C<0x01>, C<0x02>, |
19024 | 18621 | C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80> の順になります。 |
19025 | 18622 | 例えば、入力バイト C<chr(0x36)> を二つのグループに分割すると、 |
19026 | 18623 | C<(0x6, 0x3)> になります; 4 つに分割すると C<(0x2, 0x1, 0x3, 0x0)> に |
19027 | 18624 | なります。 |
19028 | 18625 | |
19029 | 18626 | =begin original |
19030 | 18627 | |
19031 | 18628 | C<vec> may also be assigned to, in which case parentheses are needed |
19032 | 18629 | to give the expression the correct precedence as in |
19033 | 18630 | |
19034 | 18631 | =end original |
19035 | 18632 | |
19036 | 18633 | 左辺値として、代入の対象にすることもできます; この場合、式を正しく |
19037 | 18634 | 先行させるために以下のように括弧が必要です: |
19038 | 18635 | |
19039 | 18636 | vec($image, $max_x * $x + $y, 8) = 3; |
19040 | 18637 | |
19041 | 18638 | =begin original |
19042 | 18639 | |
19043 | 18640 | If the selected element is outside the string, the value 0 is returned. |
19044 | 18641 | If an element off the end of the string is written to, Perl will first |
19045 | 18642 | extend the string with sufficiently many zero bytes. It is an error |
19046 | 18643 | to try to write off the beginning of the string (i.e., negative OFFSET). |
19047 | 18644 | |
19048 | 18645 | =end original |
19049 | 18646 | |
19050 | 18647 | 選択された要素が文字列の外側だった場合、値 0 が返されます。 |
19051 | 18648 | 文字列の最後よりも後ろの要素に書き込もうとした場合、 |
19052 | 18649 | Perl はまず文字列を必要な分だけ 0 のバイトで拡張します。 |
19053 | 18650 | 文字列の先頭より前に書き込もうとした(つまり OFFSET が負の数だった) |
19054 | 18651 | 場合はエラーとなります。 |
19055 | 18652 | |
19056 | 18653 | =begin original |
19057 | 18654 | |
19058 | 18655 | If the string happens to be encoded as UTF-8 internally (and thus has |
19059 | 18656 | the UTF8 flag set), this is ignored by C<vec>, and it operates on the |
19060 | 18657 | internal byte string, not the conceptual character string, even if you |
19061 | 18658 | only have characters with values less than 256. |
19062 | 18659 | |
19063 | 18660 | =end original |
19064 | 18661 | |
19065 | 18662 | 文字列がなぜか内部で UTF-8 でエンコードされている場合(したがって UTF8 フラグが |
19066 | 18663 | セットされている場合)、これは C<vec> では無視され、たとえ値が 256 未満の |
19067 | 18664 | 文字だけであったとしても、概念的な |
19068 | 18665 | 文字列ではなく内部バイト文字列で操作されます。 |
19069 | 18666 | |
19070 | 18667 | =begin original |
19071 | 18668 | |
19072 | 18669 | Strings created with C<vec> can also be manipulated with the logical |
19073 | 18670 | operators C<|>, C<&>, C<^>, and C<~>. These operators will assume a bit |
19074 | 18671 | vector operation is desired when both operands are strings. |
19075 | 18672 | See L<perlop/"Bitwise String Operators">. |
19076 | 18673 | |
19077 | 18674 | =end original |
19078 | 18675 | |
19079 | 18676 | C<vec> で作られた文字列は、論理演算子 C<|>、C<&>、C<^> で |
19080 | 18677 | 扱うこともできます。 |
19081 | 18678 | これらの演算子は、両方の被演算子に文字列を使うと、 |
19082 | 18679 | ビットベクター演算を行ないます。 |
19083 | 18680 | L<perlop/"Bitwise String Operators"> を参照してください。 |
19084 | 18681 | |
19085 | 18682 | =begin original |
19086 | 18683 | |
19087 | 18684 | The following code will build up an ASCII string saying C<'PerlPerlPerl'>. |
19088 | 18685 | The comments show the string after each step. Note that this code works |
19089 | 18686 | in the same way on big-endian or little-endian machines. |
19090 | 18687 | |
19091 | 18688 | =end original |
19092 | 18689 | |
19093 | 18690 | 次のコードは C<'PerlPerlPerl'> という ASCII 文字列を作成します。 |
19094 | 18691 | コメントは各行の実行後の文字列を示します。 |
19095 | 18692 | このコードはビッグエンディアンでもリトルエンディアンでも同じように |
19096 | 18693 | 動作することに注意してください。 |
19097 | 18694 | |
19098 | 18695 | my $foo = ''; |
19099 | 18696 | vec($foo, 0, 32) = 0x5065726C; # 'Perl' |
19100 | 18697 | |
19101 | 18698 | # $foo eq "Perl" eq "\x50\x65\x72\x6C", 32 bits |
19102 | 18699 | print vec($foo, 0, 8); # prints 80 == 0x50 == ord('P') |
19103 | 18700 | |
19104 | 18701 | vec($foo, 2, 16) = 0x5065; # 'PerlPe' |
19105 | 18702 | vec($foo, 3, 16) = 0x726C; # 'PerlPerl' |
19106 | 18703 | vec($foo, 8, 8) = 0x50; # 'PerlPerlP' |
19107 | 18704 | vec($foo, 9, 8) = 0x65; # 'PerlPerlPe' |
19108 | 18705 | vec($foo, 20, 4) = 2; # 'PerlPerlPe' . "\x02" |
19109 | 18706 | vec($foo, 21, 4) = 7; # 'PerlPerlPer' |
19110 | 18707 | # 'r' is "\x72" |
19111 | 18708 | vec($foo, 45, 2) = 3; # 'PerlPerlPer' . "\x0c" |
19112 | 18709 | vec($foo, 93, 1) = 1; # 'PerlPerlPer' . "\x2c" |
19113 | 18710 | vec($foo, 94, 1) = 1; # 'PerlPerlPerl' |
19114 | 18711 | # 'l' is "\x6c" |
19115 | 18712 | |
19116 | 18713 | =begin original |
19117 | 18714 | |
19118 | 18715 | To transform a bit vector into a string or list of 0's and 1's, use these: |
19119 | 18716 | |
19120 | 18717 | =end original |
19121 | 18718 | |
19122 | 18719 | ビットベクターを、0 と 1 の文字列や配列に変換するには、 |
19123 | 18720 | 以下のようにします。 |
19124 | 18721 | |
19125 | 18722 | $bits = unpack("b*", $vector); |
19126 | 18723 | @bits = split(//, unpack("b*", $vector)); |
19127 | 18724 | |
19128 | 18725 | =begin original |
19129 | 18726 | |
19130 | 18727 | If you know the exact length in bits, it can be used in place of the C<*>. |
19131 | 18728 | |
19132 | 18729 | =end original |
19133 | 18730 | |
19134 | 18731 | ビット長が分かっていれば、C<*> の代わりにその長さを使うことができます。 |
19135 | 18732 | |
19136 | 18733 | =begin original |
19137 | 18734 | |
19138 | 18735 | Here is an example to illustrate how the bits actually fall in place: |
19139 | 18736 | |
19140 | 18737 | =end original |
19141 | 18738 | |
19142 | 18739 | これはビットが実際にどのような位置に入るかを図示する例です。 |
19143 | 18740 | |
19144 | #!/usr/bin/perl -wl | |
18741 | #!/usr/bin/perl -wl | |
19145 | 18742 | |
19146 | print <<'EOT'; | |
18743 | print <<'EOT'; | |
19147 | 0 1 2 3 | |
18744 | 0 1 2 3 | |
19148 | unpack("V",$_) 01234567890123456789012345678901 | |
18745 | unpack("V",$_) 01234567890123456789012345678901 | |
19149 | ------------------------------------------------------------------ | |
18746 | ------------------------------------------------------------------ | |
19150 | EOT | |
18747 | EOT | |
19151 | 18748 | |
19152 | for $w (0..3) { | |
18749 | for $w (0..3) { | |
19153 | $width = 2**$w; | |
18750 | $width = 2**$w; | |
19154 | for ($shift=0; $shift < $width; ++$shift) { | |
18751 | for ($shift=0; $shift < $width; ++$shift) { | |
19155 | for ($off=0; $off < 32/$width; ++$off) { | |
18752 | for ($off=0; $off < 32/$width; ++$off) { | |
19156 | $str = pack("B*", "0"x32); | |
18753 | $str = pack("B*", "0"x32); | |
19157 | $bits = (1<<$shift); | |
18754 | $bits = (1<<$shift); | |
19158 | vec($str, $off, $width) = $bits; | |
18755 | vec($str, $off, $width) = $bits; | |
19159 | $res = unpack("b*",$str); | |
18756 | $res = unpack("b*",$str); | |
19160 | $val = unpack("V", $str); | |
18757 | $val = unpack("V", $str); | |
19161 | write; | |
18758 | write; | |
19162 | } | |
18759 | } | |
19163 | } | |
18760 | } | |
19164 | } | |
18761 | } | |
19165 | 18762 | |
19166 | format STDOUT = | |
18763 | format STDOUT = | |
19167 | vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
18764 | vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
19168 | $off, $width, $bits, $val, $res | |
18765 | $off, $width, $bits, $val, $res | |
19169 | . | |
18766 | . | |
19170 | __END__ | |
18767 | __END__ | |
19171 | 18768 | |
19172 | 18769 | =begin original |
19173 | 18770 | |
19174 | 18771 | Regardless of the machine architecture on which it runs, the |
19175 | 18772 | example above should print the following table: |
19176 | 18773 | |
19177 | 18774 | =end original |
19178 | 18775 | |
19179 | 18776 | 実行するマシンのアーキテクチャに関わらず、 |
19180 | 18777 | 上記の例は以下の表を出力します。 |
19181 | 18778 | |
19182 | 0 1 2 3 | |
18779 | 0 1 2 3 | |
19183 | unpack("V",$_) 01234567890123456789012345678901 | |
18780 | unpack("V",$_) 01234567890123456789012345678901 | |
19184 | ------------------------------------------------------------------ | |
18781 | ------------------------------------------------------------------ | |
19185 | vec($_, 0, 1) = 1 == 1 10000000000000000000000000000000 | |
18782 | vec($_, 0, 1) = 1 == 1 10000000000000000000000000000000 | |
19186 | vec($_, 1, 1) = 1 == 2 01000000000000000000000000000000 | |
18783 | vec($_, 1, 1) = 1 == 2 01000000000000000000000000000000 | |
19187 | vec($_, 2, 1) = 1 == 4 00100000000000000000000000000000 | |
18784 | vec($_, 2, 1) = 1 == 4 00100000000000000000000000000000 | |
19188 | vec($_, 3, 1) = 1 == 8 00010000000000000000000000000000 | |
18785 | vec($_, 3, 1) = 1 == 8 00010000000000000000000000000000 | |
19189 | vec($_, 4, 1) = 1 == 16 00001000000000000000000000000000 | |
18786 | vec($_, 4, 1) = 1 == 16 00001000000000000000000000000000 | |
19190 | vec($_, 5, 1) = 1 == 32 00000100000000000000000000000000 | |
18787 | vec($_, 5, 1) = 1 == 32 00000100000000000000000000000000 | |
19191 | vec($_, 6, 1) = 1 == 64 00000010000000000000000000000000 | |
18788 | vec($_, 6, 1) = 1 == 64 00000010000000000000000000000000 | |
19192 | vec($_, 7, 1) = 1 == 128 00000001000000000000000000000000 | |
18789 | vec($_, 7, 1) = 1 == 128 00000001000000000000000000000000 | |
19193 | vec($_, 8, 1) = 1 == 256 00000000100000000000000000000000 | |
18790 | vec($_, 8, 1) = 1 == 256 00000000100000000000000000000000 | |
19194 | vec($_, 9, 1) = 1 == 512 00000000010000000000000000000000 | |
18791 | vec($_, 9, 1) = 1 == 512 00000000010000000000000000000000 | |
19195 | vec($_,10, 1) = 1 == 1024 00000000001000000000000000000000 | |
18792 | vec($_,10, 1) = 1 == 1024 00000000001000000000000000000000 | |
19196 | vec($_,11, 1) = 1 == 2048 00000000000100000000000000000000 | |
18793 | vec($_,11, 1) = 1 == 2048 00000000000100000000000000000000 | |
19197 | vec($_,12, 1) = 1 == 4096 00000000000010000000000000000000 | |
18794 | vec($_,12, 1) = 1 == 4096 00000000000010000000000000000000 | |
19198 | vec($_,13, 1) = 1 == 8192 00000000000001000000000000000000 | |
18795 | vec($_,13, 1) = 1 == 8192 00000000000001000000000000000000 | |
19199 | vec($_,14, 1) = 1 == 16384 00000000000000100000000000000000 | |
18796 | vec($_,14, 1) = 1 == 16384 00000000000000100000000000000000 | |
19200 | vec($_,15, 1) = 1 == 32768 00000000000000010000000000000000 | |
18797 | vec($_,15, 1) = 1 == 32768 00000000000000010000000000000000 | |
19201 | vec($_,16, 1) = 1 == 65536 00000000000000001000000000000000 | |
18798 | vec($_,16, 1) = 1 == 65536 00000000000000001000000000000000 | |
19202 | vec($_,17, 1) = 1 == 131072 00000000000000000100000000000000 | |
18799 | vec($_,17, 1) = 1 == 131072 00000000000000000100000000000000 | |
19203 | vec($_,18, 1) = 1 == 262144 00000000000000000010000000000000 | |
18800 | vec($_,18, 1) = 1 == 262144 00000000000000000010000000000000 | |
19204 | vec($_,19, 1) = 1 == 524288 00000000000000000001000000000000 | |
18801 | vec($_,19, 1) = 1 == 524288 00000000000000000001000000000000 | |
19205 | vec($_,20, 1) = 1 == 1048576 00000000000000000000100000000000 | |
18802 | vec($_,20, 1) = 1 == 1048576 00000000000000000000100000000000 | |
19206 | vec($_,21, 1) = 1 == 2097152 00000000000000000000010000000000 | |
18803 | vec($_,21, 1) = 1 == 2097152 00000000000000000000010000000000 | |
19207 | vec($_,22, 1) = 1 == 4194304 00000000000000000000001000000000 | |
18804 | vec($_,22, 1) = 1 == 4194304 00000000000000000000001000000000 | |
19208 | vec($_,23, 1) = 1 == 8388608 00000000000000000000000100000000 | |
18805 | vec($_,23, 1) = 1 == 8388608 00000000000000000000000100000000 | |
19209 | vec($_,24, 1) = 1 == 16777216 00000000000000000000000010000000 | |
18806 | vec($_,24, 1) = 1 == 16777216 00000000000000000000000010000000 | |
19210 | vec($_,25, 1) = 1 == 33554432 00000000000000000000000001000000 | |
18807 | vec($_,25, 1) = 1 == 33554432 00000000000000000000000001000000 | |
19211 | vec($_,26, 1) = 1 == 67108864 00000000000000000000000000100000 | |
18808 | vec($_,26, 1) = 1 == 67108864 00000000000000000000000000100000 | |
19212 | vec($_,27, 1) = 1 == 134217728 00000000000000000000000000010000 | |
18809 | vec($_,27, 1) = 1 == 134217728 00000000000000000000000000010000 | |
19213 | vec($_,28, 1) = 1 == 268435456 00000000000000000000000000001000 | |
18810 | vec($_,28, 1) = 1 == 268435456 00000000000000000000000000001000 | |
19214 | vec($_,29, 1) = 1 == 536870912 00000000000000000000000000000100 | |
18811 | vec($_,29, 1) = 1 == 536870912 00000000000000000000000000000100 | |
19215 | vec($_,30, 1) = 1 == 1073741824 00000000000000000000000000000010 | |
18812 | vec($_,30, 1) = 1 == 1073741824 00000000000000000000000000000010 | |
19216 | vec($_,31, 1) = 1 == 2147483648 00000000000000000000000000000001 | |
18813 | vec($_,31, 1) = 1 == 2147483648 00000000000000000000000000000001 | |
19217 | vec($_, 0, 2) = 1 == 1 10000000000000000000000000000000 | |
18814 | vec($_, 0, 2) = 1 == 1 10000000000000000000000000000000 | |
19218 | vec($_, 1, 2) = 1 == 4 00100000000000000000000000000000 | |
18815 | vec($_, 1, 2) = 1 == 4 00100000000000000000000000000000 | |
19219 | vec($_, 2, 2) = 1 == 16 00001000000000000000000000000000 | |
18816 | vec($_, 2, 2) = 1 == 16 00001000000000000000000000000000 | |
19220 | vec($_, 3, 2) = 1 == 64 00000010000000000000000000000000 | |
18817 | vec($_, 3, 2) = 1 == 64 00000010000000000000000000000000 | |
19221 | vec($_, 4, 2) = 1 == 256 00000000100000000000000000000000 | |
18818 | vec($_, 4, 2) = 1 == 256 00000000100000000000000000000000 | |
19222 | vec($_, 5, 2) = 1 == 1024 00000000001000000000000000000000 | |
18819 | vec($_, 5, 2) = 1 == 1024 00000000001000000000000000000000 | |
19223 | vec($_, 6, 2) = 1 == 4096 00000000000010000000000000000000 | |
18820 | vec($_, 6, 2) = 1 == 4096 00000000000010000000000000000000 | |
19224 | vec($_, 7, 2) = 1 == 16384 00000000000000100000000000000000 | |
18821 | vec($_, 7, 2) = 1 == 16384 00000000000000100000000000000000 | |
19225 | vec($_, 8, 2) = 1 == 65536 00000000000000001000000000000000 | |
18822 | vec($_, 8, 2) = 1 == 65536 00000000000000001000000000000000 | |
19226 | vec($_, 9, 2) = 1 == 262144 00000000000000000010000000000000 | |
18823 | vec($_, 9, 2) = 1 == 262144 00000000000000000010000000000000 | |
19227 | vec($_,10, 2) = 1 == 1048576 00000000000000000000100000000000 | |
18824 | vec($_,10, 2) = 1 == 1048576 00000000000000000000100000000000 | |
19228 | vec($_,11, 2) = 1 == 4194304 00000000000000000000001000000000 | |
18825 | vec($_,11, 2) = 1 == 4194304 00000000000000000000001000000000 | |
19229 | vec($_,12, 2) = 1 == 16777216 00000000000000000000000010000000 | |
18826 | vec($_,12, 2) = 1 == 16777216 00000000000000000000000010000000 | |
19230 | vec($_,13, 2) = 1 == 67108864 00000000000000000000000000100000 | |
18827 | vec($_,13, 2) = 1 == 67108864 00000000000000000000000000100000 | |
19231 | vec($_,14, 2) = 1 == 268435456 00000000000000000000000000001000 | |
18828 | vec($_,14, 2) = 1 == 268435456 00000000000000000000000000001000 | |
19232 | vec($_,15, 2) = 1 == 1073741824 00000000000000000000000000000010 | |
18829 | vec($_,15, 2) = 1 == 1073741824 00000000000000000000000000000010 | |
19233 | vec($_, 0, 2) = 2 == 2 01000000000000000000000000000000 | |
18830 | vec($_, 0, 2) = 2 == 2 01000000000000000000000000000000 | |
19234 | vec($_, 1, 2) = 2 == 8 00010000000000000000000000000000 | |
18831 | vec($_, 1, 2) = 2 == 8 00010000000000000000000000000000 | |
19235 | vec($_, 2, 2) = 2 == 32 00000100000000000000000000000000 | |
18832 | vec($_, 2, 2) = 2 == 32 00000100000000000000000000000000 | |
19236 | vec($_, 3, 2) = 2 == 128 00000001000000000000000000000000 | |
18833 | vec($_, 3, 2) = 2 == 128 00000001000000000000000000000000 | |
19237 | vec($_, 4, 2) = 2 == 512 00000000010000000000000000000000 | |
18834 | vec($_, 4, 2) = 2 == 512 00000000010000000000000000000000 | |
19238 | vec($_, 5, 2) = 2 == 2048 00000000000100000000000000000000 | |
18835 | vec($_, 5, 2) = 2 == 2048 00000000000100000000000000000000 | |
19239 | vec($_, 6, 2) = 2 == 8192 00000000000001000000000000000000 | |
18836 | vec($_, 6, 2) = 2 == 8192 00000000000001000000000000000000 | |
19240 | vec($_, 7, 2) = 2 == 32768 00000000000000010000000000000000 | |
18837 | vec($_, 7, 2) = 2 == 32768 00000000000000010000000000000000 | |
19241 | vec($_, 8, 2) = 2 == 131072 00000000000000000100000000000000 | |
18838 | vec($_, 8, 2) = 2 == 131072 00000000000000000100000000000000 | |
19242 | vec($_, 9, 2) = 2 == 524288 00000000000000000001000000000000 | |
18839 | vec($_, 9, 2) = 2 == 524288 00000000000000000001000000000000 | |
19243 | vec($_,10, 2) = 2 == 2097152 00000000000000000000010000000000 | |
18840 | vec($_,10, 2) = 2 == 2097152 00000000000000000000010000000000 | |
19244 | vec($_,11, 2) = 2 == 8388608 00000000000000000000000100000000 | |
18841 | vec($_,11, 2) = 2 == 8388608 00000000000000000000000100000000 | |
19245 | vec($_,12, 2) = 2 == 33554432 00000000000000000000000001000000 | |
18842 | vec($_,12, 2) = 2 == 33554432 00000000000000000000000001000000 | |
19246 | vec($_,13, 2) = 2 == 134217728 00000000000000000000000000010000 | |
18843 | vec($_,13, 2) = 2 == 134217728 00000000000000000000000000010000 | |
19247 | vec($_,14, 2) = 2 == 536870912 00000000000000000000000000000100 | |
18844 | vec($_,14, 2) = 2 == 536870912 00000000000000000000000000000100 | |
19248 | vec($_,15, 2) = 2 == 2147483648 00000000000000000000000000000001 | |
18845 | vec($_,15, 2) = 2 == 2147483648 00000000000000000000000000000001 | |
19249 | vec($_, 0, 4) = 1 == 1 10000000000000000000000000000000 | |
18846 | vec($_, 0, 4) = 1 == 1 10000000000000000000000000000000 | |
19250 | vec($_, 1, 4) = 1 == 16 00001000000000000000000000000000 | |
18847 | vec($_, 1, 4) = 1 == 16 00001000000000000000000000000000 | |
19251 | vec($_, 2, 4) = 1 == 256 00000000100000000000000000000000 | |
18848 | vec($_, 2, 4) = 1 == 256 00000000100000000000000000000000 | |
19252 | vec($_, 3, 4) = 1 == 4096 00000000000010000000000000000000 | |
18849 | vec($_, 3, 4) = 1 == 4096 00000000000010000000000000000000 | |
19253 | vec($_, 4, 4) = 1 == 65536 00000000000000001000000000000000 | |
18850 | vec($_, 4, 4) = 1 == 65536 00000000000000001000000000000000 | |
19254 | vec($_, 5, 4) = 1 == 1048576 00000000000000000000100000000000 | |
18851 | vec($_, 5, 4) = 1 == 1048576 00000000000000000000100000000000 | |
19255 | vec($_, 6, 4) = 1 == 16777216 00000000000000000000000010000000 | |
18852 | vec($_, 6, 4) = 1 == 16777216 00000000000000000000000010000000 | |
19256 | vec($_, 7, 4) = 1 == 268435456 00000000000000000000000000001000 | |
18853 | vec($_, 7, 4) = 1 == 268435456 00000000000000000000000000001000 | |
19257 | vec($_, 0, 4) = 2 == 2 01000000000000000000000000000000 | |
18854 | vec($_, 0, 4) = 2 == 2 01000000000000000000000000000000 | |
19258 | vec($_, 1, 4) = 2 == 32 00000100000000000000000000000000 | |
18855 | vec($_, 1, 4) = 2 == 32 00000100000000000000000000000000 | |
19259 | vec($_, 2, 4) = 2 == 512 00000000010000000000000000000000 | |
18856 | vec($_, 2, 4) = 2 == 512 00000000010000000000000000000000 | |
19260 | vec($_, 3, 4) = 2 == 8192 00000000000001000000000000000000 | |
18857 | vec($_, 3, 4) = 2 == 8192 00000000000001000000000000000000 | |
19261 | vec($_, 4, 4) = 2 == 131072 00000000000000000100000000000000 | |
18858 | vec($_, 4, 4) = 2 == 131072 00000000000000000100000000000000 | |
19262 | vec($_, 5, 4) = 2 == 2097152 00000000000000000000010000000000 | |
18859 | vec($_, 5, 4) = 2 == 2097152 00000000000000000000010000000000 | |
19263 | vec($_, 6, 4) = 2 == 33554432 00000000000000000000000001000000 | |
18860 | vec($_, 6, 4) = 2 == 33554432 00000000000000000000000001000000 | |
19264 | vec($_, 7, 4) = 2 == 536870912 00000000000000000000000000000100 | |
18861 | vec($_, 7, 4) = 2 == 536870912 00000000000000000000000000000100 | |
19265 | vec($_, 0, 4) = 4 == 4 00100000000000000000000000000000 | |
18862 | vec($_, 0, 4) = 4 == 4 00100000000000000000000000000000 | |
19266 | vec($_, 1, 4) = 4 == 64 00000010000000000000000000000000 | |
18863 | vec($_, 1, 4) = 4 == 64 00000010000000000000000000000000 | |
19267 | vec($_, 2, 4) = 4 == 1024 00000000001000000000000000000000 | |
18864 | vec($_, 2, 4) = 4 == 1024 00000000001000000000000000000000 | |
19268 | vec($_, 3, 4) = 4 == 16384 00000000000000100000000000000000 | |
18865 | vec($_, 3, 4) = 4 == 16384 00000000000000100000000000000000 | |
19269 | vec($_, 4, 4) = 4 == 262144 00000000000000000010000000000000 | |
18866 | vec($_, 4, 4) = 4 == 262144 00000000000000000010000000000000 | |
19270 | vec($_, 5, 4) = 4 == 4194304 00000000000000000000001000000000 | |
18867 | vec($_, 5, 4) = 4 == 4194304 00000000000000000000001000000000 | |
19271 | vec($_, 6, 4) = 4 == 67108864 00000000000000000000000000100000 | |
18868 | vec($_, 6, 4) = 4 == 67108864 00000000000000000000000000100000 | |
19272 | vec($_, 7, 4) = 4 == 1073741824 00000000000000000000000000000010 | |
18869 | vec($_, 7, 4) = 4 == 1073741824 00000000000000000000000000000010 | |
19273 | vec($_, 0, 4) = 8 == 8 00010000000000000000000000000000 | |
18870 | vec($_, 0, 4) = 8 == 8 00010000000000000000000000000000 | |
19274 | vec($_, 1, 4) = 8 == 128 00000001000000000000000000000000 | |
18871 | vec($_, 1, 4) = 8 == 128 00000001000000000000000000000000 | |
19275 | vec($_, 2, 4) = 8 == 2048 00000000000100000000000000000000 | |
18872 | vec($_, 2, 4) = 8 == 2048 00000000000100000000000000000000 | |
19276 | vec($_, 3, 4) = 8 == 32768 00000000000000010000000000000000 | |
18873 | vec($_, 3, 4) = 8 == 32768 00000000000000010000000000000000 | |
19277 | vec($_, 4, 4) = 8 == 524288 00000000000000000001000000000000 | |
18874 | vec($_, 4, 4) = 8 == 524288 00000000000000000001000000000000 | |
19278 | vec($_, 5, 4) = 8 == 8388608 00000000000000000000000100000000 | |
18875 | vec($_, 5, 4) = 8 == 8388608 00000000000000000000000100000000 | |
19279 | vec($_, 6, 4) = 8 == 134217728 00000000000000000000000000010000 | |
18876 | vec($_, 6, 4) = 8 == 134217728 00000000000000000000000000010000 | |
19280 | vec($_, 7, 4) = 8 == 2147483648 00000000000000000000000000000001 | |
18877 | vec($_, 7, 4) = 8 == 2147483648 00000000000000000000000000000001 | |
19281 | vec($_, 0, 8) = 1 == 1 10000000000000000000000000000000 | |
18878 | vec($_, 0, 8) = 1 == 1 10000000000000000000000000000000 | |
19282 | vec($_, 1, 8) = 1 == 256 00000000100000000000000000000000 | |
18879 | vec($_, 1, 8) = 1 == 256 00000000100000000000000000000000 | |
19283 | vec($_, 2, 8) = 1 == 65536 00000000000000001000000000000000 | |
18880 | vec($_, 2, 8) = 1 == 65536 00000000000000001000000000000000 | |
19284 | vec($_, 3, 8) = 1 == 16777216 00000000000000000000000010000000 | |
18881 | vec($_, 3, 8) = 1 == 16777216 00000000000000000000000010000000 | |
19285 | vec($_, 0, 8) = 2 == 2 01000000000000000000000000000000 | |
18882 | vec($_, 0, 8) = 2 == 2 01000000000000000000000000000000 | |
19286 | vec($_, 1, 8) = 2 == 512 00000000010000000000000000000000 | |
18883 | vec($_, 1, 8) = 2 == 512 00000000010000000000000000000000 | |
19287 | vec($_, 2, 8) = 2 == 131072 00000000000000000100000000000000 | |
18884 | vec($_, 2, 8) = 2 == 131072 00000000000000000100000000000000 | |
19288 | vec($_, 3, 8) = 2 == 33554432 00000000000000000000000001000000 | |
18885 | vec($_, 3, 8) = 2 == 33554432 00000000000000000000000001000000 | |
19289 | vec($_, 0, 8) = 4 == 4 00100000000000000000000000000000 | |
18886 | vec($_, 0, 8) = 4 == 4 00100000000000000000000000000000 | |
19290 | vec($_, 1, 8) = 4 == 1024 00000000001000000000000000000000 | |
18887 | vec($_, 1, 8) = 4 == 1024 00000000001000000000000000000000 | |
19291 | vec($_, 2, 8) = 4 == 262144 00000000000000000010000000000000 | |
18888 | vec($_, 2, 8) = 4 == 262144 00000000000000000010000000000000 | |
19292 | vec($_, 3, 8) = 4 == 67108864 00000000000000000000000000100000 | |
18889 | vec($_, 3, 8) = 4 == 67108864 00000000000000000000000000100000 | |
19293 | vec($_, 0, 8) = 8 == 8 00010000000000000000000000000000 | |
18890 | vec($_, 0, 8) = 8 == 8 00010000000000000000000000000000 | |
19294 | vec($_, 1, 8) = 8 == 2048 00000000000100000000000000000000 | |
18891 | vec($_, 1, 8) = 8 == 2048 00000000000100000000000000000000 | |
19295 | vec($_, 2, 8) = 8 == 524288 00000000000000000001000000000000 | |
18892 | vec($_, 2, 8) = 8 == 524288 00000000000000000001000000000000 | |
19296 | vec($_, 3, 8) = 8 == 134217728 00000000000000000000000000010000 | |
18893 | vec($_, 3, 8) = 8 == 134217728 00000000000000000000000000010000 | |
19297 | vec($_, 0, 8) = 16 == 16 00001000000000000000000000000000 | |
18894 | vec($_, 0, 8) = 16 == 16 00001000000000000000000000000000 | |
19298 | vec($_, 1, 8) = 16 == 4096 00000000000010000000000000000000 | |
18895 | vec($_, 1, 8) = 16 == 4096 00000000000010000000000000000000 | |
19299 | vec($_, 2, 8) = 16 == 1048576 00000000000000000000100000000000 | |
18896 | vec($_, 2, 8) = 16 == 1048576 00000000000000000000100000000000 | |
19300 | vec($_, 3, 8) = 16 == 268435456 00000000000000000000000000001000 | |
18897 | vec($_, 3, 8) = 16 == 268435456 00000000000000000000000000001000 | |
19301 | vec($_, 0, 8) = 32 == 32 00000100000000000000000000000000 | |
18898 | vec($_, 0, 8) = 32 == 32 00000100000000000000000000000000 | |
19302 | vec($_, 1, 8) = 32 == 8192 00000000000001000000000000000000 | |
18899 | vec($_, 1, 8) = 32 == 8192 00000000000001000000000000000000 | |
19303 | vec($_, 2, 8) = 32 == 2097152 00000000000000000000010000000000 | |
18900 | vec($_, 2, 8) = 32 == 2097152 00000000000000000000010000000000 | |
19304 | vec($_, 3, 8) = 32 == 536870912 00000000000000000000000000000100 | |
18901 | vec($_, 3, 8) = 32 == 536870912 00000000000000000000000000000100 | |
19305 | vec($_, 0, 8) = 64 == 64 00000010000000000000000000000000 | |
18902 | vec($_, 0, 8) = 64 == 64 00000010000000000000000000000000 | |
19306 | vec($_, 1, 8) = 64 == 16384 00000000000000100000000000000000 | |
18903 | vec($_, 1, 8) = 64 == 16384 00000000000000100000000000000000 | |
19307 | vec($_, 2, 8) = 64 == 4194304 00000000000000000000001000000000 | |
18904 | vec($_, 2, 8) = 64 == 4194304 00000000000000000000001000000000 | |
19308 | vec($_, 3, 8) = 64 == 1073741824 00000000000000000000000000000010 | |
18905 | vec($_, 3, 8) = 64 == 1073741824 00000000000000000000000000000010 | |
19309 | vec($_, 0, 8) = 128 == 128 00000001000000000000000000000000 | |
18906 | vec($_, 0, 8) = 128 == 128 00000001000000000000000000000000 | |
19310 | vec($_, 1, 8) = 128 == 32768 00000000000000010000000000000000 | |
18907 | vec($_, 1, 8) = 128 == 32768 00000000000000010000000000000000 | |
19311 | vec($_, 2, 8) = 128 == 8388608 00000000000000000000000100000000 | |
18908 | vec($_, 2, 8) = 128 == 8388608 00000000000000000000000100000000 | |
19312 | vec($_, 3, 8) = 128 == 2147483648 00000000000000000000000000000001 | |
18909 | vec($_, 3, 8) = 128 == 2147483648 00000000000000000000000000000001 | |
19313 | 18910 | |
19314 | 18911 | =item wait |
19315 | 18912 | X<wait> |
19316 | 18913 | |
19317 | 18914 | =for Pod::Functions wait for any child process to die |
19318 | 18915 | |
19319 | 18916 | =begin original |
19320 | 18917 | |
19321 | 18918 | Behaves like wait(2) on your system: it waits for a child |
19322 | 18919 | process to terminate and returns the pid of the deceased process, or |
19323 | 18920 | C<-1> if there are no child processes. The status is returned in C<$?> |
19324 | 18921 | and C<${^CHILD_ERROR_NATIVE}>. |
19325 | 18922 | Note that a return value of C<-1> could mean that child processes are |
19326 | 18923 | being automatically reaped, as described in L<perlipc>. |
19327 | 18924 | |
19328 | 18925 | =end original |
19329 | 18926 | |
19330 | 18927 | wait(2) と同様に振る舞います: チャイルドプロセスが終了するのを待ち、消滅した |
19331 | 18928 | プロセスの pid を返します; チャイルドプロセスが存在しないときには、C<-1> を |
19332 | 18929 | 返します。 |
19333 | 18930 | ステータスは C<$?> と C<${^CHILD_ERROR_NATIVE}> に返されます。 |
19334 | 18931 | L<perlipc> に書いているように、返り値が C<-1> の場合は子プロセスが |
19335 | 18932 | 自動的に刈り取られたことを意味するかもしれないことに注意してください。 |
19336 | 18933 | |
19337 | 18934 | =begin original |
19338 | 18935 | |
19339 | 18936 | If you use wait in your handler for $SIG{CHLD} it may accidentally for the |
19340 | 18937 | child created by qx() or system(). See L<perlipc> for details. |
19341 | 18938 | |
19342 | 18939 | =end original |
19343 | 18940 | |
19344 | 18941 | wait を $SIG{CHLD} のハンドラで使うと、誤って qx() や system() に |
19345 | 18942 | 適用されるかも知れません。 |
19346 | 18943 | 詳しくは L<perlipc> を参照してください。 |
19347 | 18944 | |
19348 | 18945 | =begin original |
19349 | 18946 | |
19350 | 18947 | Portability issues: L<perlport/wait>. |
19351 | 18948 | |
19352 | 18949 | =end original |
19353 | 18950 | |
19354 | 18951 | 移植性の問題: L<perlport/wait>。 |
19355 | 18952 | |
19356 | 18953 | =item waitpid PID,FLAGS |
19357 | 18954 | X<waitpid> |
19358 | 18955 | |
19359 | =for Pod::Functions wait for a particular child process to die | |
18956 | =for Pod::Functions wait for a particular child process to die | |
19360 | 18957 | |
19361 | 18958 | =begin original |
19362 | 18959 | |
19363 | 18960 | Waits for a particular child process to terminate and returns the pid of |
19364 | 18961 | the deceased process, or C<-1> if there is no such child process. On some |
19365 | 18962 | systems, a value of 0 indicates that there are processes still running. |
19366 | 18963 | The status is returned in C<$?> and C<${^CHILD_ERROR_NATIVE}>. If you say |
19367 | 18964 | |
19368 | 18965 | =end original |
19369 | 18966 | |
19370 | 18967 | 特定のチャイルドプロセスが終了するのを待ち、消滅したプロセスの pid を |
19371 | 18968 | 返します; 指定したチャイルドプロセスが存在しないときには、C<-1> を返します。 |
19372 | 18969 | 値 0 がプロセスがまだ実行中であることを示すシステムもあります。 |
19373 | 18970 | ステータスは C<$?> と C<${^CHILD_ERROR_NATIVE}> に返されます。 |
19374 | 18971 | 以下のようにすると |
19375 | 18972 | |
19376 | 18973 | use POSIX ":sys_wait_h"; |
19377 | 18974 | #... |
19378 | 18975 | do { |
19379 | 18976 | $kid = waitpid(-1, WNOHANG); |
19380 | 18977 | } while $kid > 0; |
19381 | 18978 | |
19382 | 18979 | =begin original |
19383 | 18980 | |
19384 | 18981 | then you can do a non-blocking wait for all pending zombie processes. |
19385 | 18982 | Non-blocking wait is available on machines supporting either the |
19386 | 18983 | waitpid(2) or wait4(2) syscalls. However, waiting for a particular |
19387 | 18984 | pid with FLAGS of C<0> is implemented everywhere. (Perl emulates the |
19388 | 18985 | system call by remembering the status values of processes that have |
19389 | 18986 | exited but have not been harvested by the Perl script yet.) |
19390 | 18987 | |
19391 | 18988 | =end original |
19392 | 18989 | |
19393 | 18990 | ブロックが起こらないようにして、全ての待機中ゾンビプロセスを wait します。 |
19394 | 18991 | ブロックなしの wait は、システムコール wait_pid(2) か、 |
19395 | 18992 | システムコール wait4(2) をサポートしているマシンで利用可能です。 |
19396 | 18993 | しかしながら、特定の pid を C<0> の FLAGS での wait はどこでも |
19397 | 18994 | 実装されています。 |
19398 | 18995 | (exit したプロセスのステータス値を覚えておいて、Perl がシステムコールを |
19399 | 18996 | エミュレートしますが、Perl スクリプトには取り入れられていません。) |
19400 | 18997 | |
19401 | 18998 | =begin original |
19402 | 18999 | |
19403 | 19000 | Note that on some systems, a return value of C<-1> could mean that child |
19404 | 19001 | processes are being automatically reaped. See L<perlipc> for details, |
19405 | 19002 | and for other examples. |
19406 | 19003 | |
19407 | 19004 | =end original |
19408 | 19005 | |
19409 | 19006 | システムによっては、返り値が C<-1> の場合は子プロセスが自動的に |
19410 | 19007 | 刈り取られたことを意味するかもしれないことに注意してください。 |
19411 | 19008 | 詳細やその他の例については L<perlipc> を参照してください。 |
19412 | 19009 | |
19413 | 19010 | =begin original |
19414 | 19011 | |
19415 | 19012 | Portability issues: L<perlport/waitpid>. |
19416 | 19013 | |
19417 | 19014 | =end original |
19418 | 19015 | |
19419 | 19016 | 移植性の問題: L<perlport/waitpid>。 |
19420 | 19017 | |
19421 | 19018 | =item wantarray |
19422 | 19019 | X<wantarray> X<context> |
19423 | 19020 | |
19424 | 19021 | =for Pod::Functions get void vs scalar vs list context of current subroutine call |
19425 | 19022 | |
19426 | 19023 | =begin original |
19427 | 19024 | |
19428 | 19025 | Returns true if the context of the currently executing subroutine or |
19429 | 19026 | C<eval> is looking for a list value. Returns false if the context is |
19430 | 19027 | looking for a scalar. Returns the undefined value if the context is |
19431 | 19028 | looking for no value (void context). |
19432 | 19029 | |
19433 | 19030 | =end original |
19434 | 19031 | |
19435 | 19032 | 現在実行中のサブルーチンか eval() ブロックのコンテキストが、リスト値を |
19436 | 19033 | 要求するものであれば、真を返します。 |
19437 | 19034 | スカラを要求するコンテキストであれば、偽を返します。 |
19438 | 19035 | 何も値を要求しない(無効コンテキスト)場合は未定義値を返します。 |
19439 | 19036 | |
19440 | 19037 | return unless defined wantarray; # don't bother doing more |
19441 | 19038 | my @a = complex_calculation(); |
19442 | 19039 | return wantarray ? @a : "@a"; |
19443 | 19040 | |
19444 | 19041 | =begin original |
19445 | 19042 | |
19446 | 19043 | C<wantarray()>'s result is unspecified in the top level of a file, |
19447 | 19044 | in a C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT> or C<END> block, or |
19448 | 19045 | in a C<DESTROY> method. |
19449 | 19046 | |
19450 | 19047 | =end original |
19451 | 19048 | |
19452 | 19049 | ファイルのトップレベル、C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT>, C<END> |
19453 | 19050 | ブロック内、C<DESTROY> メソッド内では C<wantarray()> の結果は未定義です。 |
19454 | 19051 | |
19455 | 19052 | =begin original |
19456 | 19053 | |
19457 | 19054 | This function should have been named wantlist() instead. |
19458 | 19055 | |
19459 | 19056 | =end original |
19460 | 19057 | |
19461 | 19058 | この関数は wantlist() という名前にするべきでした。 |
19462 | 19059 | |
19463 | 19060 | =item warn LIST |
19464 | 19061 | X<warn> X<warning> X<STDERR> |
19465 | 19062 | |
19466 | 19063 | =for Pod::Functions print debugging info |
19467 | 19064 | |
19468 | 19065 | =begin original |
19469 | 19066 | |
19470 | 19067 | Prints the value of LIST to STDERR. If the last element of LIST does |
19471 | 19068 | not end in a newline, it appends the same file/line number text as C<die> |
19472 | 19069 | does. |
19473 | 19070 | |
19474 | 19071 | =end original |
19475 | 19072 | |
19476 | 19073 | LIST の値を STDERR に出力します。 |
19477 | 19074 | LIST の最後の要素が改行で終わっていない場合、C<die> が行うのと同様の |
19478 | 19075 | ファイル/行番号のテキストが追加されます。 |
19479 | 19076 | |
19480 | 19077 | =begin original |
19481 | 19078 | |
19482 | 19079 | If the output is empty and C<$@> already contains a value (typically from a |
19483 | 19080 | previous eval) that value is used after appending C<"\t...caught"> |
19484 | 19081 | to C<$@>. This is useful for staying almost, but not entirely similar to |
19485 | 19082 | C<die>. |
19486 | 19083 | |
19487 | 19084 | =end original |
19488 | 19085 | |
19489 | 19086 | 出力が空かつ、(典型的には以前の eval によって) C<$@> に既に値が入っている |
19490 | 19087 | 場合、C<$@> に C<"\t...caught"> を追加した値が用いられます。 |
19491 | 19088 | これはほとんどそのままにするときに便利ですが、 |
19492 | 19089 | C<die> と全体的に似ているわけではありません。 |
19493 | 19090 | |
19494 | 19091 | =begin original |
19495 | 19092 | |
19496 | 19093 | If C<$@> is empty then the string C<"Warning: Something's wrong"> is used. |
19497 | 19094 | |
19498 | 19095 | =end original |
19499 | 19096 | |
19500 | 19097 | C<$@> が空の場合は、C<"Warning: Something's wrong"> という文字列が |
19501 | 19098 | 使われます。 |
19502 | 19099 | |
19503 | 19100 | =begin original |
19504 | 19101 | |
19505 | 19102 | No message is printed if there is a C<$SIG{__WARN__}> handler |
19506 | 19103 | installed. It is the handler's responsibility to deal with the message |
19507 | 19104 | as it sees fit (like, for instance, converting it into a C<die>). Most |
19508 | 19105 | handlers must therefore arrange to actually display the |
19509 | 19106 | warnings that they are not prepared to deal with, by calling C<warn> |
19510 | 19107 | again in the handler. Note that this is quite safe and will not |
19511 | 19108 | produce an endless loop, since C<__WARN__> hooks are not called from |
19512 | 19109 | inside one. |
19513 | 19110 | |
19514 | 19111 | =end original |
19515 | 19112 | |
19516 | 19113 | C<$SIG{__WARN__}> ハンドラが設定されている場合は何のメッセージも |
19517 | 19114 | 表示されません。 |
19518 | 19115 | メッセージをどう扱うか(例えば C<die> に変換するか)はハンドラの |
19519 | 19116 | 責任ということです。 |
19520 | 19117 | 従ってほとんどのハンドラは、扱おうと準備していない警告を表示するために、 |
19521 | 19118 | ハンドラの中で C<warn> を再び呼び出します。 |
19522 | 19119 | C<__WARN__> フックはハンドラ内では呼び出されないので、これは十分安全で、 |
19523 | 19120 | 無限ループを引き起こすことはないということに注意してください。 |
19524 | 19121 | |
19525 | 19122 | =begin original |
19526 | 19123 | |
19527 | 19124 | You will find this behavior is slightly different from that of |
19528 | 19125 | C<$SIG{__DIE__}> handlers (which don't suppress the error text, but can |
19529 | 19126 | instead call C<die> again to change it). |
19530 | 19127 | |
19531 | 19128 | =end original |
19532 | 19129 | |
19533 | 19130 | この振る舞いは C<$SIG{__DIE__}> ハンドラ(エラーテキストは削除しませんが、 |
19534 | 19131 | 代わりに C<die> をもう一度呼び出すことで変更できます)とは |
19535 | 19132 | 少し違うことに気付くことでしょう。 |
19536 | 19133 | |
19537 | 19134 | =begin original |
19538 | 19135 | |
19539 | 19136 | Using a C<__WARN__> handler provides a powerful way to silence all |
19540 | 19137 | warnings (even the so-called mandatory ones). An example: |
19541 | 19138 | |
19542 | 19139 | =end original |
19543 | 19140 | |
19544 | 19141 | C<__WARN__> ハンドラを使うと、(いわゆる必須のものを含む)全ての |
19545 | 19142 | 警告を黙らせる強力な手段となります。 |
19546 | 19143 | 例: |
19547 | 19144 | |
19548 | 19145 | # wipe out *all* compile-time warnings |
19549 | 19146 | BEGIN { $SIG{'__WARN__'} = sub { warn $_[0] if $DOWARN } } |
19550 | 19147 | my $foo = 10; |
19551 | 19148 | my $foo = 20; # no warning about duplicate my $foo, |
19552 | 19149 | # but hey, you asked for it! |
19553 | 19150 | # no compile-time or run-time warnings before here |
19554 | 19151 | $DOWARN = 1; |
19555 | 19152 | |
19556 | 19153 | # run-time warnings enabled after here |
19557 | 19154 | warn "\$foo is alive and $foo!"; # does show up |
19558 | 19155 | |
19559 | 19156 | =begin original |
19560 | 19157 | |
19561 | 19158 | See L<perlvar> for details on setting C<%SIG> entries and for more |
19562 | 19159 | examples. See the Carp module for other kinds of warnings using its |
19563 | 19160 | carp() and cluck() functions. |
19564 | 19161 | |
19565 | 19162 | =end original |
19566 | 19163 | |
19567 | 19164 | C<%SIG> エントリのセットに関する詳細とさらなる例に関しては |
19568 | 19165 | L<perlvar> を参照してください。 |
19569 | 19166 | carp() 関数と cluck() 関数を用いた警告の方法に関しては |
19570 | 19167 | Carp モジュールを参照してください。 |
19571 | 19168 | |
19572 | 19169 | =item write FILEHANDLE |
19573 | 19170 | X<write> |
19574 | 19171 | |
19575 | 19172 | =item write EXPR |
19576 | 19173 | |
19577 | 19174 | =item write |
19578 | 19175 | |
19579 | 19176 | =for Pod::Functions print a picture record |
19580 | 19177 | |
19581 | 19178 | =begin original |
19582 | 19179 | |
19583 | 19180 | Writes a formatted record (possibly multi-line) to the specified FILEHANDLE, |
19584 | 19181 | using the format associated with that file. By default the format for |
19585 | 19182 | a file is the one having the same name as the filehandle, but the |
19586 | 19183 | format for the current output channel (see the C<select> function) may be set |
19587 | 19184 | explicitly by assigning the name of the format to the C<$~> variable. |
19588 | 19185 | |
19589 | 19186 | =end original |
19590 | 19187 | |
19591 | 19188 | 指定された FILEHANDLE に対して、そのファイルに対応させた |
19592 | 19189 | フォーマットを使って、(複数行の場合もある) 整形された |
19593 | 19190 | レコードを書き出します。 |
19594 | 19191 | デフォルトでは、ファイルに対応するフォーマットは、ファイルハンドルと |
19595 | 19192 | 同じ名前のものですが、その時点の出力チャネル (C<select> 関数の項を |
19596 | 19193 | 参照してください) のフォーマットは、その名前を明示的に変数 C<$~> に |
19597 | 19194 | 代入することで、変更が可能です。 |
19598 | 19195 | |
19599 | 19196 | =begin original |
19600 | 19197 | |
19601 | 19198 | Top of form processing is handled automatically: if there is insufficient |
19602 | 19199 | room on the current page for the formatted record, the page is advanced by |
19603 | writing a form feed a | |
19200 | writing a form feed, a special top-of-page format is used to format the new | |
19604 | format is used to format the new | |
19605 | 19201 | page header before the record is written. By default, the top-of-page |
19606 | format is the name of the filehandle with "_TOP" appended | |
19202 | format is the name of the filehandle with "_TOP" appended. This would be a | |
19607 | in the current package if the former does not exist. This would be a | |
19608 | 19203 | problem with autovivified filehandles, but it may be dynamically set to the |
19609 | 19204 | format of your choice by assigning the name to the C<$^> variable while |
19610 | 19205 | that filehandle is selected. The number of lines remaining on the current |
19611 | 19206 | page is in variable C<$->, which can be set to C<0> to force a new page. |
19612 | 19207 | |
19613 | 19208 | =end original |
19614 | 19209 | |
19615 | 19210 | ページの先頭の処理は、自動的に行なわれます: 現在のページに整形された |
19616 | 19211 | レコードを出力するだけのスペースがない場合には、改ページを行なってページを |
19617 | 19212 | 進め、新しいページヘッダを整形するため、ページ先頭フォーマットが使われ、 |
19618 | 19213 | その後でレコードが書かれます。 |
19619 | 19214 | デフォルトでは、ページ先頭フォーマットは、ファイルハンドルの名前に |
19620 | "_TOP" をつなげたもの | |
19215 | "_TOP" をつなげたものです。 | |
19621 | 19216 | これは自動有効化されたファイルハンドルで問題になる可能性がありますが、 |
19622 | 19217 | ファイルハンドルが選択されている間に、 |
19623 | 変数 C<$^> に名前を設定すれば、動的にフォーマットを | |
19218 | 変数 C<$^> に名前を設定すれば、動的にフォーマットを | |
19219 | 変更することができます。 | |
19624 | 19220 | そのページの残り行数は、変数 C<$-> に入っており、この変数を 0 に |
19625 | 19221 | 設定することで、強制的に改ページを行なうことができます。 |
19626 | 19222 | |
19627 | 19223 | =begin original |
19628 | 19224 | |
19629 | 19225 | If FILEHANDLE is unspecified, output goes to the current default output |
19630 | 19226 | channel, which starts out as STDOUT but may be changed by the |
19631 | 19227 | C<select> operator. If the FILEHANDLE is an EXPR, then the expression |
19632 | 19228 | is evaluated and the resulting string is used to look up the name of |
19633 | 19229 | the FILEHANDLE at run time. For more on formats, see L<perlform>. |
19634 | 19230 | |
19635 | 19231 | =end original |
19636 | 19232 | |
19637 | 19233 | FILEHANDLE を指定しないと、出力はその時点のデフォルト出力チャネルに対して |
19638 | 19234 | 行なわれます; これは、スクリプトの開始時点では STDOUT ですが、 |
19639 | 19235 | select() 演算子で変更することができます。 |
19640 | 19236 | FILEHANDLE が EXPR ならば、式が評価され、その結果の文字列が |
19641 | 19237 | 実行時に FILEHANDLE の名前として見られます。 |
19642 | 19238 | フォーマットについて、さらには、L<perlform> を参照してください。 |
19643 | 19239 | |
19644 | 19240 | =begin original |
19645 | 19241 | |
19646 | 19242 | Note that write is I<not> the opposite of C<read>. Unfortunately. |
19647 | 19243 | |
19648 | 19244 | =end original |
19649 | 19245 | |
19650 | 19246 | write は C<read> の反対のことをするもの I<ではありません>。 |
19651 | 19247 | 残念ながら。 |
19652 | 19248 | |
19653 | 19249 | =item y/// |
19654 | 19250 | |
19655 | 19251 | =for Pod::Functions transliterate a string |
19656 | 19252 | |
19657 | 19253 | =begin original |
19658 | 19254 | |
19659 | 19255 | The transliteration operator. Same as C<tr///>. See |
19660 | L<perlop/"Quote- | |
19256 | L<perlop/"Quote and Quote-like Operators">. | |
19661 | 19257 | |
19662 | 19258 | =end original |
19663 | 19259 | |
19664 | 19260 | 文字変換演算子です。 |
19665 | 19261 | C<tr///> と同じです。 |
19666 | L<perlop/"Quote- | |
19262 | L<perlop/"Quote and Quote-like Operators"> を参照してください。 | |
19667 | 19263 | |
19668 | 19264 | =back |
19669 | 19265 | |
19670 | 19266 | =head2 Non-function Keywords by Cross-reference |
19671 | 19267 | |
19672 | 19268 | =head3 perldata |
19673 | 19269 | |
19674 | 19270 | =over |
19675 | 19271 | |
19676 | 19272 | =item __DATA__ |
19677 | 19273 | |
19678 | 19274 | =item __END__ |
19679 | 19275 | |
19680 | 19276 | =begin original |
19681 | 19277 | |
19682 | 19278 | These keywords are documented in L<perldata/"Special Literals">. |
19683 | 19279 | |
19684 | 19280 | =end original |
19685 | 19281 | |
19686 | 19282 | これらのキーワードは L<perldata/"Special Literals"> で文書化されています。 |
19687 | 19283 | |
19688 | 19284 | =back |
19689 | 19285 | |
19690 | 19286 | =head3 perlmod |
19691 | 19287 | |
19692 | 19288 | =over |
19693 | 19289 | |
19694 | 19290 | =item BEGIN |
19695 | 19291 | |
19696 | 19292 | =item CHECK |
19697 | 19293 | |
19698 | 19294 | =item END |
19699 | 19295 | |
19700 | 19296 | =item INIT |
19701 | 19297 | |
19702 | 19298 | =item UNITCHECK |
19703 | 19299 | |
19704 | 19300 | =begin original |
19705 | 19301 | |
19706 | 19302 | These compile phase keywords are documented in L<perlmod/"BEGIN, UNITCHECK, CHECK, INIT and END">. |
19707 | 19303 | |
19708 | 19304 | =end original |
19709 | 19305 | |
19710 | 19306 | これらのコンパイルフェーズキーワードは |
19711 | 19307 | L<perlmod/"BEGIN, UNITCHECK, CHECK, INIT and END"> で文書化されています。 |
19712 | 19308 | |
19713 | 19309 | =back |
19714 | 19310 | |
19715 | 19311 | =head3 perlobj |
19716 | 19312 | |
19717 | 19313 | =over |
19718 | 19314 | |
19719 | 19315 | =item DESTROY |
19720 | 19316 | |
19721 | 19317 | =begin original |
19722 | 19318 | |
19723 | 19319 | This method keyword is documented in L<perlobj/"Destructors">. |
19724 | 19320 | |
19725 | 19321 | =end original |
19726 | 19322 | |
19727 | 19323 | このメソッドキーワードは L<perlobj/"Destructors"> で文書化されています。 |
19728 | 19324 | |
19729 | 19325 | =back |
19730 | 19326 | |
19731 | 19327 | =head3 perlop |
19732 | 19328 | |
19733 | 19329 | =over |
19734 | 19330 | |
19735 | 19331 | =item and |
19736 | 19332 | |
19737 | 19333 | =item cmp |
19738 | 19334 | |
19739 | 19335 | =item eq |
19740 | 19336 | |
19741 | 19337 | =item ge |
19742 | 19338 | |
19743 | 19339 | =item gt |
19744 | 19340 | |
19341 | =item if | |
19342 | ||
19745 | 19343 | =item le |
19746 | 19344 | |
19747 | 19345 | =item lt |
19748 | 19346 | |
19749 | 19347 | =item ne |
19750 | 19348 | |
19751 | 19349 | =item not |
19752 | 19350 | |
19753 | 19351 | =item or |
19754 | 19352 | |
19755 | 19353 | =item x |
19756 | 19354 | |
19757 | 19355 | =item xor |
19758 | 19356 | |
19759 | 19357 | =begin original |
19760 | 19358 | |
19761 | 19359 | These operators are documented in L<perlop>. |
19762 | 19360 | |
19763 | 19361 | =end original |
19764 | 19362 | |
19765 | 19363 | これらの演算子は L<perlop> で文書化されています。 |
19766 | 19364 | |
19767 | 19365 | =back |
19768 | 19366 | |
19769 | 19367 | =head3 perlsub |
19770 | 19368 | |
19771 | 19369 | =over |
19772 | 19370 | |
19773 | 19371 | =item AUTOLOAD |
19774 | 19372 | |
19775 | 19373 | =begin original |
19776 | 19374 | |
19777 | 19375 | This keyword is documented in L<perlsub/"Autoloading">. |
19778 | 19376 | |
19779 | 19377 | =end original |
19780 | 19378 | |
19781 | 19379 | このキーワードは L<perlsub/"Autoloading"> で文書化されています。 |
19782 | 19380 | |
19783 | 19381 | =back |
19784 | 19382 | |
19785 | 19383 | =head3 perlsyn |
19786 | 19384 | |
19787 | 19385 | =over |
19788 | 19386 | |
19789 | 19387 | =item else |
19790 | 19388 | |
19791 | 19389 | =item elseif |
19792 | 19390 | |
19793 | 19391 | =item elsif |
19794 | 19392 | |
19795 | 19393 | =item for |
19796 | 19394 | |
19797 | 19395 | =item foreach |
19798 | 19396 | |
19799 | =item if | |
19800 | ||
19801 | 19397 | =item unless |
19802 | 19398 | |
19803 | 19399 | =item until |
19804 | 19400 | |
19805 | 19401 | =item while |
19806 | 19402 | |
19807 | 19403 | =begin original |
19808 | 19404 | |
19809 | 19405 | These flow-control keywords are documented in L<perlsyn/"Compound Statements">. |
19810 | 19406 | |
19811 | 19407 | =end original |
19812 | 19408 | |
19813 | 19409 | これらのフロー制御キーワードは L<perlsyn/"Compound Statements"> で |
19814 | 19410 | 文書化されています。 |
19815 | 19411 | |
19816 | 19412 | =back |
19817 | 19413 | |
19818 | 19414 | =over |
19819 | 19415 | |
19820 | 19416 | =item default |
19821 | 19417 | |
19822 | 19418 | =item given |
19823 | 19419 | |
19824 | 19420 | =item when |
19825 | 19421 | |
19826 | 19422 | =begin original |
19827 | 19423 | |
19828 | 19424 | These flow-control keywords related to the experimental switch feature are |
19829 | documented in L<perlsyn/"Switch Statements">. | |
19425 | documented in L<perlsyn/"Switch Statements"> . | |
19830 | 19426 | |
19831 | 19427 | =end original |
19832 | 19428 | |
19833 | 19429 | これらの実験的な switch 機能に関連するフロー制御キーワードは |
19834 | 19430 | L<perlsyn/"Switch Statements"> で文書化されています。 |
19835 | 19431 | |
19836 | 19432 | =back |
19837 | 19433 | |
19838 | =cut | |
19839 | ||
19840 | 19434 | =begin meta |
19841 | 19435 | |
19842 | 19436 | Translate: 吉村 寿人 <JAE00534@niftyserve.or.jp> |
19843 | 19437 | Update: SHIRAKATA Kentaro <argrath@ub32.org> (5.6.1-) |
19844 | Status: | |
19438 | Status: in progress | |
19845 | 19439 | |
19846 | 19440 | =end meta |
19441 | ||
19442 | =cut |