perlfunc >
5.14.1
との差分
perlfunc 5.14.1 と 5.24.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 | contexts for its arguments. If it does both, scalar arguments | |
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 | be one such list argument. For instance, | |
30 | be one such list argument. For instance, | |
31 | ||
31 | L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> has three scalar arguments | |
32 | arg | |
32 | followed by a list, whereas L<C<gethostbyname>|/gethostbyname NAME> has | |
33 | four scalar arguments. | |
33 | 34 | |
34 | 35 | =end original |
35 | 36 | |
36 | 37 | この節の関数は、式の中で項として使うことができます。 |
37 | 38 | これらは、大きく二つに分けられます: |
38 | 39 | リスト演算子と名前付き単項演算子です。 |
39 | これらの違いは、その後に出て来るコンマとの優先順位の関係にあります。 | |
40 | これらの違いは、その後に出て来るコンマとの優先順位の関係にあります。 | |
40 | 41 | (L<perlop> の優先順位の表を参照してください。) |
41 | 42 | リスト演算子は 2 個以上の引数をとるのに対して、単項演算子が複数の引数を |
42 | 43 | とることはありません。 |
43 | 44 | つまり、コンマは単項演算子の引数の終わりとなりますが、リスト演算子の |
44 | 45 | 場合には、引数の区切りでしかありません。 |
45 | 46 | 単項演算子は一般に、引数に対してスカラコンテキストを与えるのに対して、 |
46 | 47 | スカラ演算子の場合には、引数に対してスカラコンテキストを与える場合も、 |
47 | 48 | リストコンテキストを与える場合もあります。 |
48 | 49 | 一つのリスト演算子が両方のコンテキストを与える場合には、スカラ引数が |
49 | 50 | いくつか並び、最後にリスト引数が一つ続きます; |
50 | 51 | そしてそのようなリスト引数は一つだけしかありません。 |
51 | たとえば、splice | |
52 | たとえば、L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> は三つのスカラ引数に | |
52 | 一 | |
53 | 一つのリスト引数が続きます; | |
54 | 一方 L<C<gethostbyname>|/gethostbyname NAME> は四つのスカラ引数を持ちます。 | |
53 | 55 | |
54 | 56 | =begin original |
55 | 57 | |
56 | 58 | In the syntax descriptions that follow, list operators that expect a |
57 | 59 | list (and provide list context for elements of the list) are shown |
58 | 60 | with LIST as an argument. Such a list may consist of any combination |
59 | 61 | of scalar arguments or list values; the list values will be included |
60 | 62 | in the list as if each individual element were interpolated at that |
61 | 63 | point in the list, forming a longer single-dimensional list value. |
62 | 64 | Commas should separate literal elements of the LIST. |
63 | 65 | |
64 | 66 | =end original |
65 | 67 | |
66 | 68 | 後に載せる構文記述では、リストをとり (そのリストの要素にリストコンテキストを |
67 | 与える)リスト演算子は、引数として LIST をとるように書いています | |
69 | 与える)リスト演算子は、引数として LIST をとるように書いています; | |
68 | 70 | そのようなリストには、任意のスカラ引数の組み合わせやリスト値を |
69 | 71 | 含めることができ、リスト値はリストの中に、個々の要素が展開されたように |
70 | 72 | 埋め込まれます。 |
71 | 73 | 1 次元の長いリスト値が形成されることになります。 |
72 | 74 | LIST のリテラルな要素は、コンマで区切られます。 |
73 | 75 | |
74 | 76 | =begin original |
75 | 77 | |
76 | 78 | Any function in the list below may be used either with or without |
77 | 79 | parentheses around its arguments. (The syntax descriptions omit the |
78 | parentheses.) If you use parentheses, the simple but occasionally | |
80 | parentheses.) If you use parentheses, the simple but occasionally | |
79 | 81 | surprising rule is this: It I<looks> like a function, therefore it I<is> a |
80 | 82 | function, and precedence doesn't matter. Otherwise it's a list |
81 | 83 | operator or unary operator, and precedence does matter. Whitespace |
82 | 84 | between the function and left parenthesis doesn't count, so sometimes |
83 | 85 | you need to be careful: |
84 | 86 | |
85 | 87 | =end original |
86 | 88 | |
87 | 89 | 以下のリストの関数はすべて、引数の前後の括弧は省略可能となっています。 |
88 | 90 | (構文記述では省略しています。) |
89 | 91 | 括弧を使うときには、単純な、(しかし、ときには驚く結果となる規則が |
90 | 92 | 適用できます: |
91 | 93 | I<関数に見える>ならば、I<それは関数>で、優先順位は関係ありません。 |
92 | 94 | そう見えなければ、それはリスト演算子か単項演算子で、優先順位が関係します。 |
93 | 95 | 関数と開き括弧の間の空白は関係ありませんので、ときに |
94 | 96 | 気を付けなければなりません: |
95 | 97 | |
96 | 98 | print 1+2+4; # Prints 7. |
97 | 99 | print(1+2) + 4; # Prints 3. |
98 | 100 | print (1+2)+4; # Also prints 3! |
99 | 101 | print +(1+2)+4; # Prints 7. |
100 | 102 | print ((1+2)+4); # Prints 7. |
101 | 103 | |
102 | 104 | =begin original |
103 | 105 | |
104 | If you run Perl with the | |
106 | If you run Perl with the L<C<use warnings>|warnings> pragma, it can warn | |
105 | example, the third line above produces: | |
107 | you about this. For example, the third line above produces: | |
106 | 108 | |
107 | 109 | =end original |
108 | 110 | |
109 | Perl に | |
111 | Perl に L<C<use warnings>|warnings> プラグマを付けて実行すれば、 | |
110 | 出してくれます。 | |
112 | こういったものには警告を出してくれます。 | |
111 | 113 | たとえば、上記の三つめは、以下のような警告が出ます: |
112 | 114 | |
113 | 115 | print (...) interpreted as function at - line 1. |
114 | 116 | Useless use of integer addition in void context at - line 1. |
115 | 117 | |
116 | 118 | =begin original |
117 | 119 | |
118 | 120 | A few functions take no arguments at all, and therefore work as neither |
119 | unary nor list operators. These include such functions as | |
121 | unary nor list operators. These include such functions as | |
120 | and C<endpwent>. For example, | |
122 | L<C<time>|/time> and L<C<endpwent>|/endpwent>. For example, | |
121 | C<time() + 86_400>. | |
123 | C<time+86_400> always means C<time() + 86_400>. | |
122 | 124 | |
123 | 125 | =end original |
124 | 126 | |
125 | 127 | いくつかの関数は引数を全くとらないので、単項演算子としても |
126 | 128 | リスト演算子としても動作しません。 |
127 | このような関数としては C<time> や C<endpwent> が | |
129 | このような関数としては L<C<time>|/time> や L<C<endpwent>|/endpwent> が | |
130 | あります。 | |
128 | 131 | 例えば、C<time+86_400> は常に C<time() + 86_400> として扱われます。 |
129 | 132 | |
130 | 133 | =begin original |
131 | 134 | |
132 | 135 | For functions that can be used in either a scalar or list context, |
133 | 136 | nonabortive failure is generally indicated in scalar context by |
134 | 137 | returning the undefined value, and in list context by returning the |
135 | 138 | empty list. |
136 | 139 | |
137 | 140 | =end original |
138 | 141 | |
139 | 142 | スカラコンテキストでも、リストコンテキストでも使える関数は、致命的でない |
140 | 143 | エラーを示すために、スカラコンテキストでは未定義値を返し、 |
141 | 144 | リストコンテキストでは空リストを返します。 |
142 | 145 | |
143 | 146 | =begin original |
144 | 147 | |
145 | 148 | Remember the following important rule: There is B<no rule> that relates |
146 | 149 | the behavior of an expression in list context to its behavior in scalar |
147 | 150 | context, or vice versa. It might do two totally different things. |
148 | 151 | Each operator and function decides which sort of value would be most |
149 | 152 | appropriate to return in scalar context. Some operators return the |
150 | 153 | length of the list that would have been returned in list context. Some |
151 | 154 | operators return the first value in the list. Some operators return the |
152 | 155 | last value in the list. Some operators return a count of successful |
153 | 156 | operations. In general, they do what you want, unless you want |
154 | 157 | consistency. |
155 | 158 | X<context> |
156 | 159 | |
157 | 160 | =end original |
158 | 161 | |
159 | 162 | 以下に述べる重要なルールを忘れないで下さい: リストコンテキストでの |
160 | 163 | 振る舞いとスカラコンテキストでの振る舞いの関係、あるいはその逆に |
161 | 164 | B<ルールはありません>。 |
162 | 165 | 2 つの全く異なったことがあります。 |
163 | 166 | それぞれの演算子と関数は、スカラコンテキストでは、もっとも適切と |
164 | 167 | 思われる値を返します。 |
165 | 168 | リストコンテキストで返す時のリストの長さを返す演算子もあります。 |
166 | 169 | リストの最初の値を返す演算子もあります。 |
167 | 170 | リストの最後の値を返す演算子もあります。 |
168 | 171 | 成功した操作の数を返す演算子もあります。 |
169 | 172 | 一般的には、一貫性を求めない限り、こちらが求めることをします。 |
170 | 173 | X<context> |
171 | 174 | |
172 | 175 | =begin original |
173 | 176 | |
174 | 177 | A named array in scalar context is quite different from what would at |
175 | 178 | first glance appear to be a list in scalar context. You can't get a list |
176 | 179 | like C<(1,2,3)> into being in scalar context, because the compiler knows |
177 | 180 | the context at compile time. It would generate the scalar comma operator |
178 | there, not the list con | |
181 | there, not the list concatenation version of the comma. That means it | |
179 | 182 | was never a list to start with. |
180 | 183 | |
181 | 184 | =end original |
182 | 185 | |
183 | 186 | スカラコンテキストでの名前付き配列は、スカラコンテキストでのリストを |
184 | 187 | 一目見たものとは全く違います。 |
185 | 188 | コンパイラはコンパイル時にコンテキストを知っているので、 |
186 | 189 | C<(1,2,3)> のようなリストをスカラコンテキストで得ることはできません。 |
187 | これはスカラコンマ演算子を生成し、コンマのリスト | |
190 | これはスカラコンマ演算子を生成し、コンマのリスト結合版ではありません。 | |
188 | 191 | これは初めからリストであることはないことを意味します。 |
189 | 192 | |
190 | 193 | =begin original |
191 | 194 | |
192 | In general, functions in Perl that serve as wrappers for system calls | |
195 | In general, functions in Perl that serve as wrappers for system calls | |
193 | of the same name (like chown(2), fork(2), | |
196 | ("syscalls") of the same name (like L<chown(2)>, L<fork(2)>, | |
194 | true when they succeed an | |
197 | L<closedir(2)>, etc.) return true when they succeed and | |
195 | ||
198 | L<C<undef>|/undef EXPR> otherwise, as is usually mentioned in the | |
196 | ||
199 | descriptions below. This is different from the C interfaces, which | |
197 | C< | |
200 | return C<-1> on failure. Exceptions to this rule include | |
198 | ||
201 | L<C<wait>|/wait>, L<C<waitpid>|/waitpid PID,FLAGS>, and | |
202 | L<C<syscall>|/syscall NUMBER, LIST>. System calls also set the special | |
203 | L<C<$!>|perlvar/$!> variable on failure. Other functions do not, except | |
204 | accidentally. | |
199 | 205 | |
200 | 206 | =end original |
201 | 207 | |
202 | 208 | 一般的に、同じ名前のシステムコールのラッパーとして動作する Perl の関数 |
203 | (chown(2), fork(2), closedir(2) など)は、以下に述べるように、 | |
209 | (L<chown(2)>, L<fork(2)>, L<closedir(2)> など)は、以下に述べるように、 | |
204 | 成功時に真を返し、そうでなければ C<undef> を返します。 | |
210 | 成功時に真を返し、そうでなければ L<C<undef>|/undef EXPR> を返します。 | |
205 | 211 | これは失敗時に C<-1> を返す C のインターフェースとは違います。 |
206 | このルールの例外は C<wait>, C<waitpid> | |
212 | このルールの例外は L<C<wait>|/wait>, L<C<waitpid>|/waitpid PID,FLAGS>, | |
207 | ||
213 | L<C<syscall>|/syscall NUMBER, LIST> です。 | |
214 | システムコールは失敗時に特殊変数 L<C<$!>|perlvar/$!> をセットします。 | |
208 | 215 | その他の関数は、事故を除いて、セットしません。 |
209 | 216 | |
210 | 217 | =begin original |
211 | 218 | |
212 | 219 | Extension modules can also hook into the Perl parser to define new |
213 | 220 | kinds of keyword-headed expression. These may look like functions, but |
214 | 221 | may also look completely different. The syntax following the keyword |
215 | 222 | is defined entirely by the extension. If you are an implementor, see |
216 | 223 | L<perlapi/PL_keyword_plugin> for the mechanism. If you are using such |
217 | 224 | a module, see the module's documentation for details of the syntax that |
218 | 225 | it defines. |
219 | 226 | |
220 | 227 | =end original |
221 | 228 | |
222 | 229 | エクステンションモジュールは、新しい種類のキーワードが頭に付いた式を |
223 | 230 | 定義するために Perl パーサをフックできます。 |
224 | 231 | これらは関数のように見えるかもしれませんが、全く別物かもしれません。 |
225 | 232 | キーワード以降の文法は完全にエクステンションによって定義されます。 |
226 | 233 | もしあなたが実装者なら、この機構については L<perlapi/PL_keyword_plugin> を |
227 | 234 | 参照してください。 |
228 | 235 | もしあなたがそのようなモジュールを使っているなら、 |
229 | 236 | 定義されている文法の詳細についてはモジュールの文書を参照してください。 |
230 | 237 | |
231 | 238 | =head2 Perl Functions by Category |
232 | 239 | X<function> |
233 | 240 | |
234 | 241 | (カテゴリ別の Perl 関数) |
235 | 242 | |
236 | 243 | =begin original |
237 | 244 | |
238 | 245 | Here are Perl's functions (including things that look like |
239 | 246 | functions, like some keywords and named operators) |
240 | 247 | arranged by category. Some functions appear in more |
241 | 248 | than one place. |
242 | 249 | |
243 | 250 | =end original |
244 | 251 | |
245 | 252 | 以下に、カテゴリ別の関数(キーワードや名前付き演算子のような、 |
246 | 253 | 関数のように見えるものも含みます)を示します。 |
247 | 254 | 複数の場所に現れる関数もあります。 |
248 | 255 | |
249 | 256 | =over 4 |
250 | 257 | |
251 | 258 | =item Functions for SCALARs or strings |
252 | 259 | X<scalar> X<string> X<character> |
253 | 260 | |
254 | 261 | (スカラや文字列のための関数) |
255 | 262 | |
256 | ||
263 | =for Pod::Functions =String | |
257 | C<length>, C<oct>, C<ord>, C<pack>, C<q//>, C<qq//>, C<reverse>, | |
258 | C<rindex>, C<sprintf>, C<substr>, C<tr///>, C<uc>, C<ucfirst>, C<y///> | |
259 | 264 | |
265 | L<C<chomp>|/chomp VARIABLE>, L<C<chop>|/chop VARIABLE>, | |
266 | L<C<chr>|/chr NUMBER>, L<C<crypt>|/crypt PLAINTEXT,SALT>, | |
267 | L<C<fc>|/fc EXPR>, L<C<hex>|/hex EXPR>, | |
268 | L<C<index>|/index STR,SUBSTR,POSITION>, L<C<lc>|/lc EXPR>, | |
269 | L<C<lcfirst>|/lcfirst EXPR>, L<C<length>|/length EXPR>, | |
270 | L<C<oct>|/oct EXPR>, L<C<ord>|/ord EXPR>, | |
271 | L<C<pack>|/pack TEMPLATE,LIST>, | |
272 | L<C<qE<sol>E<sol>>|/qE<sol>STRINGE<sol>>, | |
273 | L<C<qqE<sol>E<sol>>|/qqE<sol>STRINGE<sol>>, L<C<reverse>|/reverse LIST>, | |
274 | L<C<rindex>|/rindex STR,SUBSTR,POSITION>, | |
275 | L<C<sprintf>|/sprintf FORMAT, LIST>, | |
276 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT>, | |
277 | L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>>, L<C<uc>|/uc EXPR>, | |
278 | L<C<ucfirst>|/ucfirst EXPR>, | |
279 | L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>> | |
280 | ||
281 | =begin original | |
282 | ||
283 | L<C<fc>|/fc EXPR> is available only if the | |
284 | L<C<"fc"> feature|feature/The 'fc' feature> is enabled or if it is | |
285 | prefixed with C<CORE::>. The | |
286 | L<C<"fc"> feature|feature/The 'fc' feature> is enabled automatically | |
287 | with a C<use v5.16> (or higher) declaration in the current scope. | |
288 | ||
289 | =end original | |
290 | ||
291 | L<C<fc>|/fc EXPR> は L<C<"fc"> 機能|feature/The 'fc' feature> が有効か | |
292 | C<CORE::> が前置されたときにのみ利用可能です。 | |
293 | L<C<"fc"> 機能|feature/The 'fc' feature> は現在のスコープで | |
294 | C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。 | |
295 | ||
260 | 296 | =item Regular expressions and pattern matching |
261 | 297 | X<regular expression> X<regex> X<regexp> |
262 | 298 | |
263 | 299 | (正規表現とパターンマッチング) |
264 | 300 | |
265 | ||
301 | =for Pod::Functions =Regexp | |
266 | 302 | |
303 | L<C<mE<sol>E<sol>>|/mE<sol>E<sol>>, L<C<pos>|/pos SCALAR>, | |
304 | L<C<qrE<sol>E<sol>>|/qrE<sol>STRINGE<sol>>, | |
305 | L<C<quotemeta>|/quotemeta EXPR>, | |
306 | L<C<sE<sol>E<sol>E<sol>>|/sE<sol>E<sol>E<sol>>, | |
307 | L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>, | |
308 | L<C<study>|/study SCALAR> | |
309 | ||
267 | 310 | =item Numeric functions |
268 | 311 | X<numeric> X<number> X<trigonometric> X<trigonometry> |
269 | 312 | |
270 | 313 | (数値関数) |
271 | 314 | |
272 | ||
315 | =for Pod::Functions =Math | |
273 | C<sin>, C<sqrt>, C<srand> | |
274 | 316 | |
317 | L<C<abs>|/abs VALUE>, L<C<atan2>|/atan2 Y,X>, L<C<cos>|/cos EXPR>, | |
318 | L<C<exp>|/exp EXPR>, L<C<hex>|/hex EXPR>, L<C<int>|/int EXPR>, | |
319 | L<C<log>|/log EXPR>, L<C<oct>|/oct EXPR>, L<C<rand>|/rand EXPR>, | |
320 | L<C<sin>|/sin EXPR>, L<C<sqrt>|/sqrt EXPR>, L<C<srand>|/srand EXPR> | |
321 | ||
275 | 322 | =item Functions for real @ARRAYs |
276 | 323 | X<array> |
277 | 324 | |
278 | 325 | (実配列のための関数) |
279 | 326 | |
280 | ||
327 | =for Pod::Functions =ARRAY | |
281 | 328 | |
329 | L<C<each>|/each HASH>, L<C<keys>|/keys HASH>, L<C<pop>|/pop ARRAY>, | |
330 | L<C<push>|/push ARRAY,LIST>, L<C<shift>|/shift ARRAY>, | |
331 | L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST>, | |
332 | L<C<unshift>|/unshift ARRAY,LIST>, L<C<values>|/values HASH> | |
333 | ||
282 | 334 | =item Functions for list data |
283 | 335 | X<list> |
284 | 336 | |
285 | 337 | (リストデータのための関数) |
286 | 338 | |
287 | ||
339 | =for Pod::Functions =LIST | |
288 | 340 | |
341 | L<C<grep>|/grep BLOCK LIST>, L<C<join>|/join EXPR,LIST>, | |
342 | L<C<map>|/map BLOCK LIST>, L<C<qwE<sol>E<sol>>|/qwE<sol>STRINGE<sol>>, | |
343 | L<C<reverse>|/reverse LIST>, L<C<sort>|/sort SUBNAME LIST>, | |
344 | L<C<unpack>|/unpack TEMPLATE,EXPR> | |
345 | ||
289 | 346 | =item Functions for real %HASHes |
290 | 347 | X<hash> |
291 | 348 | |
292 | 349 | (実ハッシュのための関数) |
293 | 350 | |
294 | ||
351 | =for Pod::Functions =HASH | |
295 | 352 | |
353 | L<C<delete>|/delete EXPR>, L<C<each>|/each HASH>, | |
354 | L<C<exists>|/exists EXPR>, L<C<keys>|/keys HASH>, | |
355 | L<C<values>|/values HASH> | |
356 | ||
296 | 357 | =item Input and output functions |
297 | 358 | X<I/O> X<input> X<output> X<dbm> |
298 | 359 | |
299 | 360 | (入出力関数) |
300 | 361 | |
301 | ||
362 | =for Pod::Functions =I/O | |
302 | C<fileno>, C<flock>, C<format>, C<getc>, C<print>, C<printf>, C<read>, | |
303 | C<readdir>, C<rewinddir>, C<say>, C<seek>, C<seekdir>, C<select>, C<syscall>, | |
304 | C<sysread>, C<sysseek>, C<syswrite>, C<tell>, C<telldir>, C<truncate>, | |
305 | C<warn>, C<write> | |
306 | 363 | |
364 | L<C<binmode>|/binmode FILEHANDLE, LAYER>, L<C<close>|/close FILEHANDLE>, | |
365 | L<C<closedir>|/closedir DIRHANDLE>, L<C<dbmclose>|/dbmclose HASH>, | |
366 | L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, L<C<die>|/die LIST>, | |
367 | L<C<eof>|/eof FILEHANDLE>, L<C<fileno>|/fileno FILEHANDLE>, | |
368 | L<C<flock>|/flock FILEHANDLE,OPERATION>, L<C<format>|/format>, | |
369 | L<C<getc>|/getc FILEHANDLE>, L<C<print>|/print FILEHANDLE LIST>, | |
370 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, | |
371 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
372 | L<C<readdir>|/readdir DIRHANDLE>, L<C<readline>|/readline EXPR> | |
373 | L<C<rewinddir>|/rewinddir DIRHANDLE>, L<C<say>|/say FILEHANDLE LIST>, | |
374 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
375 | L<C<seekdir>|/seekdir DIRHANDLE,POS>, | |
376 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, | |
377 | L<C<syscall>|/syscall NUMBER, LIST>, | |
378 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
379 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>, | |
380 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
381 | L<C<tell>|/tell FILEHANDLE>, L<C<telldir>|/telldir DIRHANDLE>, | |
382 | L<C<truncate>|/truncate FILEHANDLE,LENGTH>, L<C<warn>|/warn LIST>, | |
383 | L<C<write>|/write FILEHANDLE> | |
384 | ||
385 | =begin original | |
386 | ||
387 | L<C<say>|/say FILEHANDLE LIST> is available only if the | |
388 | L<C<"say"> feature|feature/The 'say' feature> is enabled or if it is | |
389 | prefixed with C<CORE::>. The | |
390 | L<C<"say"> feature|feature/The 'say' feature> is enabled automatically | |
391 | with a C<use v5.10> (or higher) declaration in the current scope. | |
392 | ||
393 | =end original | |
394 | ||
395 | L<C<say>|/say FILEHANDLE LIST> は | |
396 | L<C<"say"> 機能|feature/The 'say' feature> が有効か C<CORE::> が | |
397 | 前置されたときにのみ利用可能です。 | |
398 | L<C<"say"> 機能|feature/The 'say' feature> は現在のスコープで | |
399 | C<use v5.10> (またはそれ以上) が宣言されると自動的に有効になります。 | |
400 | ||
307 | 401 | =item Functions for fixed-length data or records |
308 | 402 | |
309 | 403 | (固定長データやレコードのための関数) |
310 | 404 | |
311 | ||
405 | =for Pod::Functions =Binary | |
312 | 406 | |
407 | L<C<pack>|/pack TEMPLATE,LIST>, | |
408 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
409 | L<C<syscall>|/syscall NUMBER, LIST>, | |
410 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
411 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>, | |
412 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
413 | L<C<unpack>|/unpack TEMPLATE,EXPR>, L<C<vec>|/vec EXPR,OFFSET,BITS> | |
414 | ||
313 | 415 | =item Functions for filehandles, files, or directories |
314 | 416 | X<file> X<filehandle> X<directory> X<pipe> X<link> X<symlink> |
315 | 417 | |
316 | 418 | (ファイルハンドル、ファイル、ディレクトリのための関数) |
317 | 419 | |
318 | ||
420 | =for Pod::Functions =File | |
319 | C<ioctl>, C<link>, C<lstat>, C<mkdir>, C<open>, C<opendir>, | |
320 | C<readlink>, C<rename>, C<rmdir>, C<stat>, C<symlink>, C<sysopen>, | |
321 | C<umask>, C<unlink>, C<utime> | |
322 | 421 | |
422 | L<C<-I<X>>|/-X FILEHANDLE>, L<C<chdir>|/chdir EXPR>, | |
423 | L<C<chmod>|/chmod LIST>, L<C<chown>|/chown LIST>, | |
424 | L<C<chroot>|/chroot FILENAME>, | |
425 | L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>, L<C<glob>|/glob EXPR>, | |
426 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>, | |
427 | L<C<link>|/link OLDFILE,NEWFILE>, L<C<lstat>|/lstat FILEHANDLE>, | |
428 | L<C<mkdir>|/mkdir FILENAME,MASK>, L<C<open>|/open FILEHANDLE,EXPR>, | |
429 | L<C<opendir>|/opendir DIRHANDLE,EXPR>, L<C<readlink>|/readlink EXPR>, | |
430 | L<C<rename>|/rename OLDNAME,NEWNAME>, L<C<rmdir>|/rmdir FILENAME>, | |
431 | L<C<select>|/select FILEHANDLE>, L<C<stat>|/stat FILEHANDLE>, | |
432 | L<C<symlink>|/symlink OLDFILE,NEWFILE>, | |
433 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>, | |
434 | L<C<umask>|/umask EXPR>, L<C<unlink>|/unlink LIST>, | |
435 | L<C<utime>|/utime LIST> | |
436 | ||
323 | 437 | =item Keywords related to the control flow of your Perl program |
324 | 438 | X<control flow> |
325 | 439 | |
326 | 440 | (プログラムの流れを制御することに関連するキーワード) |
327 | 441 | |
328 | ||
442 | =for Pod::Functions =Flow | |
329 | C<goto>, C<last>, C<next>, C<redo>, C<return>, C<sub>, C<wantarray> | |
330 | 443 | |
331 | ||
444 | L<C<break>|/break>, L<C<caller>|/caller EXPR>, | |
445 | L<C<continue>|/continue BLOCK>, L<C<die>|/die LIST>, L<C<do>|/do BLOCK>, | |
446 | L<C<dump>|/dump LABEL>, L<C<eval>|/eval EXPR>, | |
447 | L<C<evalbytes>|/evalbytes EXPR> L<C<exit>|/exit EXPR>, | |
448 | L<C<__FILE__>|/__FILE__>, L<C<goto>|/goto LABEL>, | |
449 | L<C<last>|/last LABEL>, L<C<__LINE__>|/__LINE__>, | |
450 | L<C<next>|/next LABEL>, L<C<__PACKAGE__>|/__PACKAGE__>, | |
451 | L<C<redo>|/redo LABEL>, L<C<return>|/return EXPR>, | |
452 | L<C<sub>|/sub NAME BLOCK>, L<C<__SUB__>|/__SUB__>, | |
453 | L<C<wantarray>|/wantarray> | |
332 | 454 | |
333 | ||
455 | =begin original | |
334 | 456 | |
335 | C<break> | |
457 | L<C<break>|/break> is available only if you enable the experimental | |
458 | L<C<"switch"> feature|feature/The 'switch' feature> or use the C<CORE::> | |
459 | prefix. The L<C<"switch"> feature|feature/The 'switch' feature> also | |
460 | enables the C<default>, C<given> and C<when> statements, which are | |
461 | documented in L<perlsyn/"Switch Statements">. | |
462 | The L<C<"switch"> feature|feature/The 'switch' feature> is enabled | |
463 | automatically with a C<use v5.10> (or higher) declaration in the current | |
464 | scope. In Perl v5.14 and earlier, L<C<continue>|/continue BLOCK> | |
465 | required the L<C<"switch"> feature|feature/The 'switch' feature>, like | |
466 | the other keywords. | |
336 | 467 | |
468 | =end original | |
469 | ||
470 | L<C<break>|/break> は、実験的な | |
471 | L<C<"switch"> 機能|feature/The 'switch' feature> が有効か C<CORE::> 接頭辞を | |
472 | 使ったときにのみ利用可能です。 | |
473 | L<C<"switch"> 機能|feature/The 'switch' feature> は、 | |
474 | L<perlsyn/"Switch Statements"> で文書化されている | |
475 | C<default>, C<given>, C<when> 文も有効にします。 | |
476 | L<C<"switch"> 機能|feature/The 'switch' feature> は、現在のスコープで | |
477 | C<use v5.10> (またはそれ以上) 宣言があると自動的に有効になります。 | |
478 | Perl v5.14 以前では、L<C<continue>|/continue BLOCK> は他のキーワードと同様に | |
479 | L<C<"switch"> 機能|feature/The 'switch' feature> が必要です。 | |
480 | ||
337 | 481 | =begin original |
338 | 482 | |
339 | ||
483 | L<C<evalbytes>|/evalbytes EXPR> is only available with the | |
340 | ||
484 | L<C<"evalbytes"> feature|feature/The 'unicode_eval' and 'evalbytes' features> | |
341 | ||
485 | (see L<feature>) or if prefixed with C<CORE::>. L<C<__SUB__>|/__SUB__> | |
486 | is only available with the | |
487 | L<C<"current_sub"> feature|feature/The 'current_sub' feature> or if | |
488 | prefixed with C<CORE::>. Both the | |
489 | L<C<"evalbytes">|feature/The 'unicode_eval' and 'evalbytes' features> | |
490 | and L<C<"current_sub">|feature/The 'current_sub' feature> features are | |
491 | enabled automatically with a C<use v5.16> (or higher) declaration in the | |
492 | current scope. | |
342 | 493 | |
343 | 494 | =end original |
344 | 495 | |
345 | ||
496 | L<C<evalbytes>|/evalbytes EXPR> は | |
346 | L< | |
497 | L<C<"evalbytes"> 機能|feature/The 'unicode_eval' and 'evalbytes' features> | |
347 | ||
498 | (L<feature> 参照) が有効か C<CORE::> が前置されたときにのみ利用可能です。 | |
499 | L<C<__SUB__>|/__SUB__> は | |
500 | L<C<"current_sub"> 機能|feature/The 'current_sub' feature> が有効か | |
501 | C<CORE::> が前置されたときにのみ利用可能です。 | |
502 | L<C<"evalbytes">|feature/The 'unicode_eval' and 'evalbytes' features> と | |
503 | L<C<"current_sub">|feature/The 'current_sub' feature> の両方の機能は | |
504 | 現在のスコープで | |
505 | C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。 | |
348 | 506 | |
349 | 507 | =item Keywords related to scoping |
350 | 508 | |
351 | 509 | (スコープに関するキーワード) |
352 | 510 | |
353 | ||
511 | =for Pod::Functions =Namespace | |
354 | 512 | |
513 | L<C<caller>|/caller EXPR>, L<C<import>|/import LIST>, | |
514 | L<C<local>|/local EXPR>, L<C<my>|/my VARLIST>, L<C<our>|/our VARLIST>, | |
515 | L<C<package>|/package NAMESPACE>, L<C<state>|/state VARLIST>, | |
516 | L<C<use>|/use Module VERSION LIST> | |
517 | ||
355 | 518 | =begin original |
356 | 519 | |
357 | C<state> is available only if th | |
520 | L<C<state>|/state VARLIST> is available only if the | |
358 | L<feature | |
521 | L<C<"state"> feature|feature/The 'state' feature> is enabled or if it is | |
522 | prefixed with C<CORE::>. The | |
523 | L<C<"state"> feature|feature/The 'state' feature> is enabled | |
524 | automatically with a C<use v5.10> (or higher) declaration in the current | |
525 | scope. | |
359 | 526 | |
360 | 527 | =end original |
361 | 528 | |
362 | C<state> | |
529 | L<C<state>|/state VARLIST> は | |
363 | L<feature> を | |
530 | L<C<"state"> 機能|feature/The 'state' feature> が有効か C<CORE::> を | |
364 | ||
531 | 前置した場合にのみ利用可能です。 | |
532 | L<C<"state"> 機能|feature/The 'state' feature> は現在のスコープで | |
533 | C<use v5.10> (またはそれ以上) を宣言した場合自動的に有効になります。 | |
365 | 534 | |
366 | 535 | =item Miscellaneous functions |
367 | 536 | |
368 | 537 | (さまざまな関数) |
369 | 538 | |
370 | ||
539 | =for Pod::Functions =Misc | |
371 | C<reset>, C<scalar>, C<state>, C<undef>, C<wantarray> | |
372 | 540 | |
541 | L<C<defined>|/defined EXPR>, L<C<formline>|/formline PICTURE,LIST>, | |
542 | L<C<lock>|/lock THING>, L<C<prototype>|/prototype FUNCTION>, | |
543 | L<C<reset>|/reset EXPR>, L<C<scalar>|/scalar EXPR>, | |
544 | L<C<undef>|/undef EXPR> | |
545 | ||
373 | 546 | =item Functions for processes and process groups |
374 | 547 | X<process> X<pid> X<process id> |
375 | 548 | |
376 | 549 | (プロセスとプロセスグループのための関数) |
377 | 550 | |
378 | ||
551 | =for Pod::Functions =Process | |
379 | C<pipe>, C<qx//>, C<setpgrp>, C<setpriority>, C<sleep>, C<system>, | |
380 | C<times>, C<wait>, C<waitpid> | |
381 | 552 | |
553 | L<C<alarm>|/alarm SECONDS>, L<C<exec>|/exec LIST>, L<C<fork>|/fork>, | |
554 | L<C<getpgrp>|/getpgrp PID>, L<C<getppid>|/getppid>, | |
555 | L<C<getpriority>|/getpriority WHICH,WHO>, L<C<kill>|/kill SIGNAL, LIST>, | |
556 | L<C<pipe>|/pipe READHANDLE,WRITEHANDLE>, | |
557 | L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>>, | |
558 | L<C<readpipe>|/readpipe EXPR>, L<C<setpgrp>|/setpgrp PID,PGRP>, | |
559 | L<C<setpriority>|/setpriority WHICH,WHO,PRIORITY>, | |
560 | L<C<sleep>|/sleep EXPR>, L<C<system>|/system LIST>, L<C<times>|/times>, | |
561 | L<C<wait>|/wait>, L<C<waitpid>|/waitpid PID,FLAGS> | |
562 | ||
382 | 563 | =item Keywords related to Perl modules |
383 | 564 | X<module> |
384 | 565 | |
385 | 566 | (Perl モジュールに関するキーワード) |
386 | 567 | |
387 | ||
568 | =for Pod::Functions =Modules | |
388 | 569 | |
570 | L<C<do>|/do EXPR>, L<C<import>|/import LIST>, | |
571 | L<C<no>|/no MODULE VERSION LIST>, L<C<package>|/package NAMESPACE>, | |
572 | L<C<require>|/require VERSION>, L<C<use>|/use Module VERSION LIST> | |
573 | ||
389 | 574 | =item Keywords related to classes and object-orientation |
390 | 575 | X<object> X<class> X<package> |
391 | 576 | |
392 | 577 | (クラスとオブジェクト指向に関するキーワード) |
393 | 578 | |
394 | ||
579 | =for Pod::Functions =Objects | |
395 | C<untie>, C<use> | |
396 | 580 | |
581 | L<C<bless>|/bless REF,CLASSNAME>, L<C<dbmclose>|/dbmclose HASH>, | |
582 | L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, | |
583 | L<C<package>|/package NAMESPACE>, L<C<ref>|/ref EXPR>, | |
584 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST>, L<C<tied>|/tied VARIABLE>, | |
585 | L<C<untie>|/untie VARIABLE>, L<C<use>|/use Module VERSION LIST> | |
586 | ||
397 | 587 | =item Low-level socket functions |
398 | 588 | X<socket> X<sock> |
399 | 589 | |
400 | 590 | (低レベルソケット関数) |
401 | 591 | |
402 | ||
592 | =for Pod::Functions =Socket | |
403 | C<getsockopt>, C<listen>, C<recv>, C<send>, C<setsockopt>, C<shutdown>, | |
404 | C<socket>, C<socketpair> | |
405 | 593 | |
594 | L<C<accept>|/accept NEWSOCKET,GENERICSOCKET>, | |
595 | L<C<bind>|/bind SOCKET,NAME>, L<C<connect>|/connect SOCKET,NAME>, | |
596 | L<C<getpeername>|/getpeername SOCKET>, | |
597 | L<C<getsockname>|/getsockname SOCKET>, | |
598 | L<C<getsockopt>|/getsockopt SOCKET,LEVEL,OPTNAME>, | |
599 | L<C<listen>|/listen SOCKET,QUEUESIZE>, | |
600 | L<C<recv>|/recv SOCKET,SCALAR,LENGTH,FLAGS>, | |
601 | L<C<send>|/send SOCKET,MSG,FLAGS,TO>, | |
602 | L<C<setsockopt>|/setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL>, | |
603 | L<C<shutdown>|/shutdown SOCKET,HOW>, | |
604 | L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL>, | |
605 | L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL> | |
606 | ||
406 | 607 | =item System V interprocess communication functions |
407 | 608 | X<IPC> X<System V> X<semaphore> X<shared memory> X<memory> X<message> |
408 | 609 | |
409 | 610 | (System V プロセス間通信関数) |
410 | 611 | |
411 | ||
612 | =for Pod::Functions =SysV | |
412 | C<shmctl>, C<shmget>, C<shmread>, C<shmwrite> | |
413 | 613 | |
614 | L<C<msgctl>|/msgctl ID,CMD,ARG>, L<C<msgget>|/msgget KEY,FLAGS>, | |
615 | L<C<msgrcv>|/msgrcv ID,VAR,SIZE,TYPE,FLAGS>, | |
616 | L<C<msgsnd>|/msgsnd ID,MSG,FLAGS>, | |
617 | L<C<semctl>|/semctl ID,SEMNUM,CMD,ARG>, | |
618 | L<C<semget>|/semget KEY,NSEMS,FLAGS>, L<C<semop>|/semop KEY,OPSTRING>, | |
619 | L<C<shmctl>|/shmctl ID,CMD,ARG>, L<C<shmget>|/shmget KEY,SIZE,FLAGS>, | |
620 | L<C<shmread>|/shmread ID,VAR,POS,SIZE>, | |
621 | L<C<shmwrite>|/shmwrite ID,STRING,POS,SIZE> | |
622 | ||
414 | 623 | =item Fetching user and group info |
415 | 624 | X<user> X<group> X<password> X<uid> X<gid> X<passwd> X</etc/passwd> |
416 | 625 | |
417 | 626 | (ユーザーとグループの情報取得) |
418 | 627 | |
419 | ||
628 | =for Pod::Functions =User | |
420 | C<getgrgid>, C<getgrnam>, C<getlogin>, C<getpwent>, C<getpwnam>, | |
421 | C<getpwuid>, C<setgrent>, C<setpwent> | |
422 | 629 | |
630 | L<C<endgrent>|/endgrent>, L<C<endhostent>|/endhostent>, | |
631 | L<C<endnetent>|/endnetent>, L<C<endpwent>|/endpwent>, | |
632 | L<C<getgrent>|/getgrent>, L<C<getgrgid>|/getgrgid GID>, | |
633 | L<C<getgrnam>|/getgrnam NAME>, L<C<getlogin>|/getlogin>, | |
634 | L<C<getpwent>|/getpwent>, L<C<getpwnam>|/getpwnam NAME>, | |
635 | L<C<getpwuid>|/getpwuid UID>, L<C<setgrent>|/setgrent>, | |
636 | L<C<setpwent>|/setpwent> | |
637 | ||
423 | 638 | =item Fetching network info |
424 | 639 | X<network> X<protocol> X<host> X<hostname> X<IP> X<address> X<service> |
425 | 640 | |
426 | 641 | (ネットワーク情報取得) |
427 | 642 | |
428 | ||
643 | =for Pod::Functions =Network | |
429 | C<gethostent>, C<getnetbyaddr>, C<getnetbyname>, C<getnetent>, | |
430 | C<getprotobyname>, C<getprotobynumber>, C<getprotoent>, | |
431 | C<getservbyname>, C<getservbyport>, C<getservent>, C<sethostent>, | |
432 | C<setnetent>, C<setprotoent>, C<setservent> | |
433 | 644 | |
645 | L<C<endprotoent>|/endprotoent>, L<C<endservent>|/endservent>, | |
646 | L<C<gethostbyaddr>|/gethostbyaddr ADDR,ADDRTYPE>, | |
647 | L<C<gethostbyname>|/gethostbyname NAME>, L<C<gethostent>|/gethostent>, | |
648 | L<C<getnetbyaddr>|/getnetbyaddr ADDR,ADDRTYPE>, | |
649 | L<C<getnetbyname>|/getnetbyname NAME>, L<C<getnetent>|/getnetent>, | |
650 | L<C<getprotobyname>|/getprotobyname NAME>, | |
651 | L<C<getprotobynumber>|/getprotobynumber NUMBER>, | |
652 | L<C<getprotoent>|/getprotoent>, | |
653 | L<C<getservbyname>|/getservbyname NAME,PROTO>, | |
654 | L<C<getservbyport>|/getservbyport PORT,PROTO>, | |
655 | L<C<getservent>|/getservent>, L<C<sethostent>|/sethostent STAYOPEN>, | |
656 | L<C<setnetent>|/setnetent STAYOPEN>, | |
657 | L<C<setprotoent>|/setprotoent STAYOPEN>, | |
658 | L<C<setservent>|/setservent STAYOPEN> | |
659 | ||
434 | 660 | =item Time-related functions |
435 | 661 | X<time> X<date> |
436 | 662 | |
437 | 663 | (時刻に関する関数) |
438 | 664 | |
439 | ||
665 | =for Pod::Functions =Time | |
440 | 666 | |
441 | ||
667 | L<C<gmtime>|/gmtime EXPR>, L<C<localtime>|/localtime EXPR>, | |
442 | ||
668 | L<C<time>|/time>, L<C<times>|/times> | |
443 | 669 | |
444 | ||
670 | =item Non-function keywords | |
445 | 671 | |
446 | ||
672 | =for Pod::Functions =!Non-functions | |
447 | C<exists>, C<formline>, C<given>, C<glob>, C<import>, C<lc>, C<lcfirst>, | |
448 | C<lock>, C<map>, C<my>, C<no>, C<our>, C<prototype>, C<qr//>, C<qw//>, C<qx//>, | |
449 | C<readline>, C<readpipe>, C<ref>, C<sub>*, C<sysopen>, C<tie>, C<tied>, C<uc>, | |
450 | C<ucfirst>, C<untie>, C<use>, C<when> | |
451 | 673 | |
452 | ||
674 | C<and>, C<AUTOLOAD>, C<BEGIN>, C<CHECK>, C<cmp>, C<CORE>, C<__DATA__>, | |
675 | C<default>, C<DESTROY>, C<else>, C<elseif>, C<elsif>, C<END>, C<__END__>, | |
676 | C<eq>, C<for>, C<foreach>, C<ge>, C<given>, C<gt>, C<if>, C<INIT>, C<le>, | |
677 | C<lt>, C<ne>, C<not>, C<or>, C<UNITCHECK>, C<unless>, C<until>, C<when>, | |
678 | C<while>, C<x>, C<xor> | |
453 | 679 | |
454 | * C<sub> was a keyword in Perl 4, but in Perl 5 it is an | |
455 | operator, which can be used in expressions. | |
456 | ||
457 | =end original | |
458 | ||
459 | * - C<sub> は Perl4 ではキーワードですが、Perl5 では演算子なので、 | |
460 | 式で使えます。 | |
461 | ||
462 | =item Functions obsoleted in perl5 | |
463 | ||
464 | (perl5 では古いものとなった関数) | |
465 | ||
466 | C<dbmclose>, C<dbmopen> | |
467 | ||
468 | 680 | =back |
469 | 681 | |
470 | 682 | =head2 Portability |
471 | 683 | X<portability> X<Unix> X<portable> |
472 | 684 | |
473 | 685 | (移植性) |
474 | 686 | |
475 | 687 | =begin original |
476 | 688 | |
477 | 689 | Perl was born in Unix and can therefore access all common Unix |
478 | 690 | system calls. In non-Unix environments, the functionality of some |
479 | 691 | Unix system calls may not be available or details of the available |
480 | 692 | functionality may differ slightly. The Perl functions affected |
481 | 693 | by this are: |
482 | 694 | |
483 | 695 | =end original |
484 | 696 | |
485 | 697 | Perl は Unix 環境で生まれたので、全ての共通する Unix システムコールに |
486 | アクセスします。 | |
698 | アクセスします。 | |
487 | 機能が使えなかったり、 | |
699 | 非 Unix 環境では、いくつかの Unix システムコールの機能が使えなかったり、 | |
700 | 使える機能の詳細が多少異なったりします。 | |
488 | 701 | これによる影響を受ける Perl 関数は以下のものです: |
489 | 702 | |
490 | C<-X>, C<binmode> | |
703 | L<C<-I<X>>|/-X FILEHANDLE>, L<C<binmode>|/binmode FILEHANDLE, LAYER>, | |
491 | C< | |
704 | L<C<chmod>|/chmod LIST>, L<C<chown>|/chown LIST>, | |
492 | ||
705 | L<C<chroot>|/chroot FILENAME>, L<C<crypt>|/crypt PLAINTEXT,SALT>, | |
493 | C< | |
706 | L<C<dbmclose>|/dbmclose HASH>, L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, | |
494 | C< | |
707 | L<C<dump>|/dump LABEL>, L<C<endgrent>|/endgrent>, | |
495 | C< | |
708 | L<C<endhostent>|/endhostent>, L<C<endnetent>|/endnetent>, | |
496 | C< | |
709 | L<C<endprotoent>|/endprotoent>, L<C<endpwent>|/endpwent>, | |
497 | C< | |
710 | L<C<endservent>|/endservent>, L<C<exec>|/exec LIST>, | |
498 | ||
711 | L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>, | |
499 | ||
712 | L<C<flock>|/flock FILEHANDLE,OPERATION>, L<C<fork>|/fork>, | |
500 | C< | |
713 | L<C<getgrent>|/getgrent>, L<C<getgrgid>|/getgrgid GID>, | |
501 | C< | |
714 | L<C<gethostbyname>|/gethostbyname NAME>, L<C<gethostent>|/gethostent>, | |
502 | ||
715 | L<C<getlogin>|/getlogin>, | |
503 | C< | |
716 | L<C<getnetbyaddr>|/getnetbyaddr ADDR,ADDRTYPE>, | |
504 | C< | |
717 | L<C<getnetbyname>|/getnetbyname NAME>, L<C<getnetent>|/getnetent>, | |
505 | C<ti | |
718 | L<C<getppid>|/getppid>, L<C<getpgrp>|/getpgrp PID>, | |
506 | C< | |
719 | L<C<getpriority>|/getpriority WHICH,WHO>, | |
720 | L<C<getprotobynumber>|/getprotobynumber NUMBER>, | |
721 | L<C<getprotoent>|/getprotoent>, L<C<getpwent>|/getpwent>, | |
722 | L<C<getpwnam>|/getpwnam NAME>, L<C<getpwuid>|/getpwuid UID>, | |
723 | L<C<getservbyport>|/getservbyport PORT,PROTO>, | |
724 | L<C<getservent>|/getservent>, | |
725 | L<C<getsockopt>|/getsockopt SOCKET,LEVEL,OPTNAME>, | |
726 | L<C<glob>|/glob EXPR>, L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>, | |
727 | L<C<kill>|/kill SIGNAL, LIST>, L<C<link>|/link OLDFILE,NEWFILE>, | |
728 | L<C<lstat>|/lstat FILEHANDLE>, L<C<msgctl>|/msgctl ID,CMD,ARG>, | |
729 | L<C<msgget>|/msgget KEY,FLAGS>, | |
730 | L<C<msgrcv>|/msgrcv ID,VAR,SIZE,TYPE,FLAGS>, | |
731 | L<C<msgsnd>|/msgsnd ID,MSG,FLAGS>, L<C<open>|/open FILEHANDLE,EXPR>, | |
732 | L<C<pipe>|/pipe READHANDLE,WRITEHANDLE>, L<C<readlink>|/readlink EXPR>, | |
733 | L<C<rename>|/rename OLDNAME,NEWNAME>, | |
734 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, | |
735 | L<C<semctl>|/semctl ID,SEMNUM,CMD,ARG>, | |
736 | L<C<semget>|/semget KEY,NSEMS,FLAGS>, L<C<semop>|/semop KEY,OPSTRING>, | |
737 | L<C<setgrent>|/setgrent>, L<C<sethostent>|/sethostent STAYOPEN>, | |
738 | L<C<setnetent>|/setnetent STAYOPEN>, L<C<setpgrp>|/setpgrp PID,PGRP>, | |
739 | L<C<setpriority>|/setpriority WHICH,WHO,PRIORITY>, | |
740 | L<C<setprotoent>|/setprotoent STAYOPEN>, L<C<setpwent>|/setpwent>, | |
741 | L<C<setservent>|/setservent STAYOPEN>, | |
742 | L<C<setsockopt>|/setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL>, | |
743 | L<C<shmctl>|/shmctl ID,CMD,ARG>, L<C<shmget>|/shmget KEY,SIZE,FLAGS>, | |
744 | L<C<shmread>|/shmread ID,VAR,POS,SIZE>, | |
745 | L<C<shmwrite>|/shmwrite ID,STRING,POS,SIZE>, | |
746 | L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL>, | |
747 | L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL>, | |
748 | L<C<stat>|/stat FILEHANDLE>, L<C<symlink>|/symlink OLDFILE,NEWFILE>, | |
749 | L<C<syscall>|/syscall NUMBER, LIST>, | |
750 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>, | |
751 | L<C<system>|/system LIST>, L<C<times>|/times>, | |
752 | L<C<truncate>|/truncate FILEHANDLE,LENGTH>, L<C<umask>|/umask EXPR>, | |
753 | L<C<unlink>|/unlink LIST>, L<C<utime>|/utime LIST>, L<C<wait>|/wait>, | |
754 | L<C<waitpid>|/waitpid PID,FLAGS> | |
507 | 755 | |
508 | 756 | =begin original |
509 | 757 | |
510 | 758 | For more information about the portability of these functions, see |
511 | 759 | L<perlport> and other available platform-specific documentation. |
512 | 760 | |
513 | 761 | =end original |
514 | 762 | |
515 | 763 | これらの関数の移植性に関するさらなる情報については、 |
516 | L<perlport> とその他のプラットホーム固有のドキュメントを参照して | |
764 | L<perlport> とその他のプラットホーム固有のドキュメントを参照してください。 | |
517 | 765 | |
518 | 766 | =head2 Alphabetical Listing of Perl Functions |
519 | 767 | |
520 | =over | |
768 | =over | |
521 | 769 | |
522 | 770 | =item -X FILEHANDLE |
523 | 771 | 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> |
524 | 772 | X<-S>X<-b>X<-c>X<-t>X<-u>X<-g>X<-k>X<-T>X<-B>X<-M>X<-A>X<-C> |
525 | 773 | |
526 | 774 | =item -X EXPR |
527 | 775 | |
528 | 776 | =item -X DIRHANDLE |
529 | 777 | |
530 | 778 | =item -X |
531 | 779 | |
780 | =for Pod::Functions a file test (-r, -x, etc) | |
781 | ||
532 | 782 | =begin original |
533 | 783 | |
534 | 784 | A file test, where X is one of the letters listed below. This unary |
535 | operator takes one argument, either a filename, a filehandle, or a dirhandle, | |
785 | operator takes one argument, either a filename, a filehandle, or a dirhandle, | |
536 | 786 | and tests the associated file to see if something is true about it. If the |
537 | argument is omitted, tests C<$_>, except for C<-t>, which | |
787 | argument is omitted, tests L<C<$_>|perlvar/$_>, except for C<-t>, which | |
538 | Unless otherwise documented, it returns C<1> for true and | |
788 | tests STDIN. Unless otherwise documented, it returns C<1> for true and | |
539 | ||
789 | C<''> for false. If the file doesn't exist or can't be examined, it | |
540 | ||
790 | returns L<C<undef>|/undef EXPR> and sets L<C<$!>|perlvar/$!> (errno). | |
541 | ||
791 | Despite the funny names, precedence is the same as any other named unary | |
792 | operator. The operator may be any of: | |
542 | 793 | |
543 | 794 | =end original |
544 | 795 | |
545 | 796 | X は以下にあげる文字で、ファイルテストを行ないます。 |
546 | この単項演算子は、ファイル名かファイルハンドルを唯一の | |
797 | この単項演算子は、ファイル名かファイルハンドルを唯一の引数として動作し、 | |
547 | ||
798 | 「あること」について真であるか否かを判定した結果を返します。 | |
548 | ||
799 | 引数が省略されると、C<-t> では STDIN を調べますが、その他は | |
549 | ||
800 | L<C<$_>|perlvar/$_> を調べます。 | |
550 | 特に記述されていなければ、真として C<1> を返し、偽として | |
801 | 特に記述されていなければ、真として C<1> を返し、偽として C<''> を返します。 | |
551 | ||
802 | ファイルが存在しないか、テスト出来なければ、L<C<undef>|/undef EXPR> を返し、 | |
803 | L<C<$!>|perlvar/$!> (errno) を設定します。 | |
552 | 804 | みかけは変わっていますが、優先順位は名前付き単項演算子と同じで、 |
553 | 805 | 他の単項演算子と同じく、引数を括弧で括ることもできます。 |
554 | 806 | 演算子には以下のものがあります: |
555 | 807 | |
556 | 808 | =begin original |
557 | 809 | |
558 | 810 | -r File is readable by effective uid/gid. |
559 | 811 | -w File is writable by effective uid/gid. |
560 | 812 | -x File is executable by effective uid/gid. |
561 | 813 | -o File is owned by effective uid. |
562 | 814 | |
563 | 815 | =end original |
564 | 816 | |
565 | -r ファイルが実効 uid/gid で読み出し可 | |
817 | -r ファイルが実効 uid/gid で読み出し可。 | |
566 | -w ファイルが実効 uid/gid で書き込み可 | |
818 | -w ファイルが実効 uid/gid で書き込み可。 | |
567 | -x ファイルが実効 uid/gid で実行可 | |
819 | -x ファイルが実効 uid/gid で実行可。 | |
568 | -o ファイルが実効 uid の所有物 | |
820 | -o ファイルが実効 uid の所有物。 | |
569 | 821 | |
570 | 822 | =begin original |
571 | 823 | |
572 | 824 | -R File is readable by real uid/gid. |
573 | 825 | -W File is writable by real uid/gid. |
574 | 826 | -X File is executable by real uid/gid. |
575 | 827 | -O File is owned by real uid. |
576 | 828 | |
577 | 829 | =end original |
578 | 830 | |
579 | -R ファイルが実 uid/gid で読み出し可 | |
831 | -R ファイルが実 uid/gid で読み出し可。 | |
580 | -W ファイルが実 uid/gid で書き込み可 | |
832 | -W ファイルが実 uid/gid で書き込み可。 | |
581 | -X ファイルが実 uid/gid で実行可 | |
833 | -X ファイルが実 uid/gid で実行可。 | |
582 | -O ファイルが実 uid の所有物 | |
834 | -O ファイルが実 uid の所有物。 | |
583 | 835 | |
584 | 836 | =begin original |
585 | 837 | |
586 | 838 | -e File exists. |
587 | 839 | -z File has zero size (is empty). |
588 | 840 | -s File has nonzero size (returns size in bytes). |
589 | 841 | |
590 | 842 | =end original |
591 | 843 | |
592 | -e ファイルが存在する | |
844 | -e ファイルが存在する。 | |
593 | -z ファイルの大きさがゼロ(空) | |
845 | -z ファイルの大きさがゼロ(空)。 | |
594 | -s ファイルの大きさがゼロ以外 (バイト単位での大きさを返す) | |
846 | -s ファイルの大きさがゼロ以外 (バイト単位での大きさを返す)。 | |
595 | 847 | |
596 | 848 | =begin original |
597 | 849 | |
598 | 850 | -f File is a plain file. |
599 | 851 | -d File is a directory. |
600 | -l File is a symbolic link | |
852 | -l File is a symbolic link (false if symlinks aren't | |
853 | supported by the file system). | |
601 | 854 | -p File is a named pipe (FIFO), or Filehandle is a pipe. |
602 | 855 | -S File is a socket. |
603 | 856 | -b File is a block special file. |
604 | 857 | -c File is a character special file. |
605 | 858 | -t Filehandle is opened to a tty. |
606 | 859 | |
607 | 860 | =end original |
608 | 861 | |
609 | -f ファイルは通常ファイル | |
862 | -f ファイルは通常ファイル。 | |
610 | -d ファイルはディレクトリ | |
863 | -d ファイルはディレクトリ。 | |
611 | -l ファイルはシンボリックリンク | |
864 | -l ファイルはシンボリックリンク(ファイルシステムが非対応なら偽)。 | |
612 | -p ファイルは名前付きパイプ (FIFO) またはファイルハンドルはパイプ | |
865 | -p ファイルは名前付きパイプ (FIFO) またはファイルハンドルはパイプ。 | |
613 | -S ファイルはソケット | |
866 | -S ファイルはソケット。 | |
614 | -b ファイルはブロック特殊ファイル | |
867 | -b ファイルはブロック特殊ファイル。 | |
615 | -c ファイルはキャラクタ特殊ファイル | |
868 | -c ファイルはキャラクタ特殊ファイル。 | |
616 | -t ファイルハンドルは tty にオープンされている | |
869 | -t ファイルハンドルは tty にオープンされている。 | |
617 | 870 | |
618 | 871 | =begin original |
619 | 872 | |
620 | 873 | -u File has setuid bit set. |
621 | 874 | -g File has setgid bit set. |
622 | 875 | -k File has sticky bit set. |
623 | 876 | |
624 | 877 | =end original |
625 | 878 | |
626 | -u ファイルの setuid ビットがセットされている | |
879 | -u ファイルの setuid ビットがセットされている。 | |
627 | -g ファイルの setgid ビットがセットされている | |
880 | -g ファイルの setgid ビットがセットされている。 | |
628 | -k ファイルの sticky ビットがセットされている | |
881 | -k ファイルの sticky ビットがセットされている。 | |
629 | 882 | |
630 | 883 | =begin original |
631 | 884 | |
632 | -T File is an ASCII text file (heuristic guess). | |
885 | -T File is an ASCII or UTF-8 text file (heuristic guess). | |
633 | 886 | -B File is a "binary" file (opposite of -T). |
634 | 887 | |
635 | 888 | =end original |
636 | 889 | |
637 | -T ファイルは ASCII テキストファイル (発見的に推測します) | |
890 | -T ファイルは ASCII または UTF-8 テキストファイル (発見的に推測します)。 | |
638 | -B ファイルは「バイナリ」ファイル (-T の反対) | |
891 | -B ファイルは「バイナリ」ファイル (-T の反対)。 | |
639 | 892 | |
640 | 893 | =begin original |
641 | 894 | |
642 | 895 | -M Script start time minus file modification time, in days. |
643 | 896 | -A Same for access time. |
644 | -C Same for inode change time (Unix, may differ for other | |
897 | -C Same for inode change time (Unix, may differ for other | |
898 | platforms) | |
645 | 899 | |
646 | 900 | =end original |
647 | 901 | |
648 | -M スクリプト実行開始時刻からファイル修正時刻を引いたもの(日単位) | |
902 | -M スクリプト実行開始時刻からファイル修正時刻を引いたもの(日単位)。 | |
649 | -A 同様にアクセスがあってからの日数 | |
903 | -A 同様にアクセスがあってからの日数。 | |
650 | -C 同様に(Unix では) inode が変更されてからの日数(それ以外の | |
904 | -C 同様に(Unix では) inode が変更されてからの日数(それ以外の | |
905 | プラットフォームでは違うかもしれません)。 | |
651 | 906 | |
652 | 907 | =begin original |
653 | 908 | |
654 | 909 | Example: |
655 | 910 | |
656 | 911 | =end original |
657 | 912 | |
658 | 913 | 例: |
659 | 914 | |
660 | 915 | while (<>) { |
661 | 916 | chomp; |
662 | 917 | next unless -f $_; # ignore specials |
663 | 918 | #... |
664 | 919 | } |
665 | 920 | |
666 | 921 | =begin original |
667 | 922 | |
668 | 923 | Note that C<-s/a/b/> does not do a negated substitution. Saying |
669 | 924 | C<-exp($foo)> still works as expected, however: only single letters |
670 | 925 | following a minus are interpreted as file tests. |
671 | 926 | |
672 | 927 | =end original |
673 | 928 | |
674 | 929 | C<-s/a/b> は、置換演算 (s///) の符号反転ではありません。 |
675 | しかし、C<-exp($foo)> は期待どおりに動作します | |
930 | しかし、C<-exp($foo)> は期待どおりに動作します; しかし、マイナス記号の後に | |
676 | ||
931 | 英字が 1 字続くときにのみ、ファイルテストと解釈されます。 | |
677 | 解釈されます。 | |
678 | 932 | |
679 | 933 | =begin original |
680 | 934 | |
681 | 935 | These operators are exempt from the "looks like a function rule" described |
682 | above. That is, an opening parenthesis after the operator does not affect | |
936 | above. That is, an opening parenthesis after the operator does not affect | |
683 | how much of the following code constitutes the argument. Put the opening | |
937 | how much of the following code constitutes the argument. Put the opening | |
684 | 938 | parentheses before the operator to separate it from code that follows (this |
685 | 939 | applies only to operators with higher precedence than unary operators, of |
686 | 940 | course): |
687 | 941 | |
688 | 942 | =end original |
689 | 943 | |
690 | 944 | これらの演算子は上述の「関数のように見えるルール」から免除されます。 |
691 | 945 | つまり、演算子の後の開きかっこは、引き続くコードのどこまでが引数を |
692 | 946 | 構成するかに影響を与えません。 |
693 | 947 | 演算子を引き続くコードから分離するには、演算子の前に開きかっこを |
694 | 948 | 置いてください (これはもちろん、単項演算子より高い優先順位を持つ |
695 | 949 | 演算子にのみ適用されます): |
696 | 950 | |
697 | 951 | -s($file) + 1024 # probably wrong; same as -s($file + 1024) |
698 | 952 | (-s $file) + 1024 # correct |
699 | 953 | |
700 | 954 | =begin original |
701 | 955 | |
702 | 956 | The interpretation of the file permission operators C<-r>, C<-R>, |
703 | 957 | C<-w>, C<-W>, C<-x>, and C<-X> is by default based solely on the mode |
704 | 958 | of the file and the uids and gids of the user. There may be other |
705 | 959 | reasons you can't actually read, write, or execute the file: for |
706 | 960 | example network filesystem access controls, ACLs (access control lists), |
707 | 961 | read-only filesystems, and unrecognized executable formats. Note |
708 | 962 | that the use of these six specific operators to verify if some operation |
709 | 963 | is possible is usually a mistake, because it may be open to race |
710 | 964 | conditions. |
711 | 965 | |
712 | 966 | =end original |
713 | 967 | |
714 | 968 | ファイルのパーミッション演算子 C<-r>, C<-R>, C<-w>, C<-W>, C<-x>, |
715 | 969 | C<-X> の解釈は、ファイルのモードとユーザの実効/実 uid と |
716 | 970 | 実効/実 gid のみから判断されます。 |
717 | 971 | 実際にファイルが読めたり、書けたり、実行できたりするためには、 |
718 | 972 | 別の条件が必要かもしれません: |
719 | 973 | 例えば、ネットワークファイルシステムアクセスコントロール、 |
720 | 974 | ACL(アクセスコントロールリスト)、読み込み専用ファイルシステム、 |
721 | 975 | 認識できない実行ファイルフォーマット、などです。 |
722 | 976 | これらの 6 つの演算子を、特定の操作が可能かどうかを確認するために使うのは |
723 | 977 | 通常は誤りであることに注意してください; なぜなら、これらは競合条件を |
724 | 978 | 招きやすいからです。 |
725 | 979 | |
726 | 980 | =begin original |
727 | 981 | |
728 | 982 | Also note that, for the superuser on the local filesystems, the C<-r>, |
729 | 983 | C<-R>, C<-w>, and C<-W> tests always return 1, and C<-x> and C<-X> return 1 |
730 | 984 | if any execute bit is set in the mode. Scripts run by the superuser |
731 | may thus need to do a stat | |
985 | may thus need to do a L<C<stat>|/stat FILEHANDLE> to determine the | |
732 | or temporarily set their effective uid to | |
986 | actual mode of the file, or temporarily set their effective uid to | |
987 | something else. | |
733 | 988 | |
734 | 989 | =end original |
735 | 990 | |
736 | 991 | ローカルファイルシステムのスーパーユーザには、 |
737 | 992 | C<-r>, C<-R>, C<-w>, C<-W> に対して、常に 1 が返り、モード中の |
738 | 993 | いずれかの実行許可ビットが立っていれば、C<-x>, C<-X> にも 1 が |
739 | 994 | 返ることにも注意してください。 |
740 | 995 | スーパーユーザが実行するスクリプトでは、ファイルのモードを調べるためには、 |
741 | stat | |
996 | L<C<stat>|/stat FILEHANDLE> を行なうか、実効 uid を一時的に別のものにする | |
742 | 997 | 必要があるでしょう。 |
743 | 998 | |
744 | 999 | =begin original |
745 | 1000 | |
746 | If you are using ACLs, there is a pragma called C<filetest> | |
1001 | If you are using ACLs, there is a pragma called L<C<filetest>|filetest> | |
747 | produce more accurate results than the bare | |
1002 | that may produce more accurate results than the bare | |
748 | ||
1003 | L<C<stat>|/stat FILEHANDLE> mode bits. | |
749 | ||
1004 | When under C<use filetest 'access'>, the above-mentioned filetests | |
750 | ||
1005 | test whether the permission can(not) be granted using the L<access(2)> | |
1006 | family of system calls. Also note that the C<-x> and C<-X> tests may | |
751 | 1007 | under this pragma return true even if there are no execute permission |
752 | 1008 | bits set (nor any extra execute permission ACLs). This strangeness is |
753 | due to the underlying system calls' definitions. Note also that, due to | |
1009 | due to the underlying system calls' definitions. Note also that, due to | |
754 | 1010 | the implementation of C<use filetest 'access'>, the C<_> special |
755 | 1011 | filehandle won't cache the results of the file tests when this pragma is |
756 | in effect. Read the documentation for the C<filetest> | |
1012 | in effect. Read the documentation for the L<C<filetest>|filetest> | |
757 | information. | |
1013 | pragma for more information. | |
758 | 1014 | |
759 | 1015 | =end original |
760 | 1016 | |
761 | ACL を使っている場合は、生の stat | |
1017 | ACL を使っている場合は、生の L<C<stat>|/stat FILEHANDLE> モードビットより | |
762 | 精度の高い結果を作成する C<filetest> プラグマがあります。 | |
1018 | 精度の高い結果を作成する L<C<filetest>|filetest> プラグマがあります。 | |
763 | 1019 | C<use filetest 'access'> とした場合、上述したファイルテストは |
764 | システムコールの access(2) ファミリーを使って権限が与えられているか | |
1020 | システムコールの L<access(2)> ファミリーを使って権限が与えられているか | |
765 | 1021 | どうかをテストします。 |
766 | また、このプラグマが指定されている場合、C<-x> と C<-X> は | |
1022 | また、このプラグマが指定されている場合、C<-x> と C<-X> テストは | |
767 | 1023 | たとえ実行許可ビット(または追加の実行許可 ACL)がセットされていない |
768 | 1024 | 場合でも真を返すことに注意してください。 |
769 | 1025 | この挙動は使用するシステムコールの定義によるものです。 |
770 | 1026 | C<use filetest 'access'> の実装により、このプラグマが有効の場合は |
771 | 1027 | C<_> 特殊ファイルハンドルはファイルテストの結果をキャッシュしないことに |
772 | 1028 | 注意してください。 |
773 | さらなる情報については C<filetest> プラグマのドキュメントを | |
1029 | さらなる情報については L<C<filetest>|filetest> プラグマのドキュメントを | |
774 | 1030 | 参照してください。 |
775 | 1031 | |
776 | 1032 | =begin original |
777 | 1033 | |
778 | The C<-T> and C<-B> | |
1034 | The C<-T> and C<-B> tests work as follows. The first block or so of | |
779 | file is examined | |
1035 | the file is examined to see if it is valid UTF-8 that includes non-ASCII | |
780 | characters | |
1036 | characters. If so, it's a C<-T> file. Otherwise, that same portion of | |
781 | ||
1037 | the file is examined for odd characters such as strange control codes or | |
782 | c | |
1038 | characters with the high bit set. If more than a third of the | |
783 | ||
1039 | characters are strange, it's a C<-B> file; otherwise it's a C<-T> file. | |
1040 | Also, any file containing a zero byte in the examined portion is | |
1041 | considered a binary file. (If executed within the scope of a L<S<use | |
1042 | locale>|perllocale> which includes C<LC_CTYPE>, odd characters are | |
1043 | anything that isn't a printable nor space in the current locale.) If | |
1044 | C<-T> or C<-B> is used on a filehandle, the current IO buffer is | |
1045 | examined | |
784 | 1046 | rather than the first block. Both C<-T> and C<-B> return true on an empty |
785 | 1047 | file, or a file at EOF when testing a filehandle. Because you have to |
786 | 1048 | read a file to do the C<-T> test, on most occasions you want to use a C<-f> |
787 | 1049 | against the file first, as in C<next unless -f $file && -T $file>. |
788 | 1050 | |
789 | 1051 | =end original |
790 | 1052 | |
791 | 1053 | ファイルテスト C<-T> と C<-B> の動作原理は、次のようになっています。 |
792 | ファイルの最初の数ブロックを調べて、 | |
1054 | ファイルの最初の数ブロックを調べて、非 ASCII 文字を含む妥当な UTF-8 かどうかを | |
1055 | 調べます。 | |
1056 | もしそうなら、それは C<-T> ファイルです。 | |
1057 | さもなければ、ファイルの同じ位置から、変わった制御コードや | |
793 | 1058 | 上位ビットがセットされているような、通常のテキストには現れない文字を探します。 |
794 | ||
1059 | 三分の一以上がおかしな文字なら、それは C<-B> ファイルでです; | |
795 | ||
1060 | さもなければ C<-T> ファイルです。 | |
796 | ||
1061 | また、調べた位置にヌル文字が含まれるファイルも、バイナリファイルと | |
797 | ||
1062 | みなされます。 | |
798 | ||
1063 | (C<LC_CTYPE> を含む L<S<use locale>|perllocale> のスコープの中で実行されると、 | |
1064 | おかしな文字というのは現在のロケールで表示可能でもスペースでもないものです。) | |
799 | 1065 | C<-T> や C<-B> をファイルハンドルに対して用いると、 |
800 | 1066 | 最初のブロックを調べる代わりに、IO バッファを調べます。 |
801 | 1067 | 調べたファイルの中身が何もないときや、 |
802 | 1068 | ファイルハンドルを調べたときに EOF に達して |
803 | 1069 | いたときには、C<-T> も C<-B> も「真」を返します。 |
804 | 1070 | C<-T> テストをするためにはファイルを読み込まないといけないので、 |
805 | 1071 | たいていは C<next unless -f $file && -T $file> というような形で |
806 | 1072 | まず調べたいファイルに対して C<-f> を使いたいはずです。 |
807 | 1073 | |
808 | 1074 | =begin original |
809 | 1075 | |
810 | If any of the file tests (or either the C<stat> | |
1076 | If any of the file tests (or either the L<C<stat>|/stat FILEHANDLE> or | |
811 | ||
1077 | L<C<lstat>|/lstat FILEHANDLE> operator) is given the special filehandle | |
812 | st | |
1078 | consisting of a solitary underline, then the stat structure of the | |
813 | ||
1079 | previous file test (or L<C<stat>|/stat FILEHANDLE> operator) is used, | |
814 | ||
1080 | saving a system call. (This doesn't work with C<-t>, and you need to | |
815 | ||
1081 | remember that L<C<lstat>|/lstat FILEHANDLE> and C<-l> leave values in | |
816 | ||
1082 | the stat structure for the symbolic link, not the real file.) (Also, if | |
1083 | the stat buffer was filled by an L<C<lstat>|/lstat FILEHANDLE> call, | |
1084 | C<-T> and C<-B> will reset it with the results of C<stat _>). | |
817 | 1085 | Example: |
818 | 1086 | |
819 | 1087 | =end original |
820 | 1088 | |
821 | どのファイルテスト (あるいは、C<stat> | |
1089 | どのファイルテスト (あるいは、L<C<stat>|/stat FILEHANDLE> や | |
1090 | L<C<lstat>|/lstat FILEHANDLE>) 演算子にも、 | |
822 | 1091 | 下線だけから成る特別なファイルハンドルを与えると、 |
823 | 前回のファイルテスト (や stat | |
1092 | 前回のファイルテスト (や L<C<stat>|/stat FILEHANDLE> 演算子) の | |
824 | システムコールを省きます。 | |
1093 | stat 構造体が使われ、システムコールを省きます。 | |
825 | (C<-t> には使えませんし、lstat | |
1094 | (C<-t> には使えませんし、L<C<lstat>|/lstat FILEHANDLE> や C<-l> は | |
826 | シンボリックリンクの情報を stat 構造体に残すことを | |
1095 | 実ファイルではなく、シンボリックリンクの情報を stat 構造体に残すことを | |
827 | 1096 | 覚えておく必要があります。) |
828 | (また、stat バッファが C<lstat> 呼び出しで埋まった場合、 | |
1097 | (また、stat バッファが L<C<lstat>|/lstat FILEHANDLE> 呼び出しで埋まった場合、 | |
829 | 1098 | C<-T> と C<-B> の結果は C<stat _> の結果でリセットされます。 |
830 | 1099 | 例: |
831 | 1100 | |
832 | 1101 | print "Can do.\n" if -r $a || -w _ || -x _; |
833 | 1102 | |
834 | 1103 | stat($filename); |
835 | 1104 | print "Readable\n" if -r _; |
836 | 1105 | print "Writable\n" if -w _; |
837 | 1106 | print "Executable\n" if -x _; |
838 | 1107 | print "Setuid\n" if -u _; |
839 | 1108 | print "Setgid\n" if -g _; |
840 | 1109 | print "Sticky\n" if -k _; |
841 | 1110 | print "Text\n" if -T _; |
842 | 1111 | print "Binary\n" if -B _; |
843 | 1112 | |
844 | 1113 | =begin original |
845 | 1114 | |
846 | As of Perl 5. | |
1115 | As of Perl 5.10.0, as a form of purely syntactic sugar, you can stack file | |
847 | 1116 | test operators, in a way that C<-f -w -x $file> is equivalent to |
848 | C<-x $file && -w _ && -f _>. (This is only fancy | |
1117 | C<-x $file && -w _ && -f _>. (This is only fancy syntax: if you use | |
849 | 1118 | the return value of C<-f $file> as an argument to another filetest |
850 | 1119 | operator, no special magic will happen.) |
851 | 1120 | |
852 | 1121 | =end original |
853 | 1122 | |
854 | Perl 5. | |
1123 | Perl 5.10.0 から、純粋にシンタックスシュガーとして、ファイルテスト演算子を | |
855 | 1124 | スタックさせることができるので、C<-f -w -x $file> は |
856 | 1125 | C<-x $file && -w _ && -f _> と等価です。 |
857 | 1126 | (これは文法上だけの話です; もし C<-f $file> の返り値を他のファイルテスト |
858 | 1127 | 演算子の引数として使う場合は、何の特別なことも起きません。) |
859 | 1128 | |
1129 | =begin original | |
1130 | ||
1131 | Portability issues: L<perlport/-X>. | |
1132 | ||
1133 | =end original | |
1134 | ||
1135 | 移植性の問題: L<perlport/-X>。 | |
1136 | ||
1137 | =begin original | |
1138 | ||
1139 | To avoid confusing would-be users of your code with mysterious | |
1140 | syntax errors, put something like this at the top of your script: | |
1141 | ||
1142 | =end original | |
1143 | ||
1144 | あなたのコードのユーザーが不思議な文法エラーで混乱することを | |
1145 | 避けるために、スクリプトの先頭に以下のようなことを書いてください: | |
1146 | ||
1147 | use 5.010; # so filetest ops can stack | |
1148 | ||
860 | 1149 | =item abs VALUE |
861 | 1150 | X<abs> X<absolute> |
862 | 1151 | |
863 | 1152 | =item abs |
864 | 1153 | |
1154 | =for Pod::Functions absolute value function | |
1155 | ||
865 | 1156 | =begin original |
866 | 1157 | |
867 | 1158 | Returns the absolute value of its argument. |
868 | If VALUE is omitted, uses C<$_>. | |
1159 | If VALUE is omitted, uses L<C<$_>|perlvar/$_>. | |
869 | 1160 | |
870 | 1161 | =end original |
871 | 1162 | |
872 | 1163 | 引数の絶対値を返します。 |
873 | VALUE が省略された場合は、C<$_> を使います。 | |
1164 | VALUE が省略された場合は、L<C<$_>|perlvar/$_> を使います。 | |
874 | 1165 | |
875 | 1166 | =item accept NEWSOCKET,GENERICSOCKET |
876 | 1167 | X<accept> |
877 | 1168 | |
1169 | =for Pod::Functions accept an incoming socket connect | |
1170 | ||
878 | 1171 | =begin original |
879 | 1172 | |
880 | Accepts an incoming socket connect, just as accept(2) | |
1173 | Accepts an incoming socket connect, just as L<accept(2)> | |
881 | 1174 | does. Returns the packed address if it succeeded, false otherwise. |
882 | 1175 | See the example in L<perlipc/"Sockets: Client/Server Communication">. |
883 | 1176 | |
884 | 1177 | =end original |
885 | 1178 | |
886 | accept(2) システムコールと同様に、着信するソケットの接続を受け付けます。 | |
1179 | L<accept(2)> システムコールと同様に、着信するソケットの接続を受け付けます。 | |
887 | 1180 | 成功時にはパックされたアドレスを返し、失敗すれば偽を返します。 |
888 | L<perlipc/"Sockets: Client/Server Communication"> の | |
1181 | L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。 | |
889 | 例を参照してください。 | |
890 | 1182 | |
891 | 1183 | =begin original |
892 | 1184 | |
893 | 1185 | On systems that support a close-on-exec flag on files, the flag will |
894 | 1186 | be set for the newly opened file descriptor, as determined by the |
895 | value of $^F. See L<perlvar/$^F>. | |
1187 | value of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>. | |
896 | 1188 | |
897 | 1189 | =end original |
898 | 1190 | |
899 | 1191 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
900 | フラグは $^F の値で決定される、新しくオープンされた | |
1192 | フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた | |
901 | セットされます。 | |
1193 | ファイル記述子に対してセットされます。 | |
902 | 1194 | L<perlvar/$^F> を参照してください。 |
903 | 1195 | |
904 | 1196 | =item alarm SECONDS |
905 | 1197 | X<alarm> |
906 | 1198 | X<SIGALRM> |
907 | 1199 | X<timer> |
908 | 1200 | |
909 | 1201 | =item alarm |
910 | 1202 | |
1203 | =for Pod::Functions schedule a SIGALRM | |
1204 | ||
911 | 1205 | =begin original |
912 | 1206 | |
913 | 1207 | Arranges to have a SIGALRM delivered to this process after the |
914 | 1208 | specified number of wallclock seconds has elapsed. If SECONDS is not |
915 | specified, the value stored in C<$_> is used. (On some | |
1209 | specified, the value stored in L<C<$_>|perlvar/$_> is used. (On some | |
916 | unfortunately, the elapsed time may be up to one second less | |
1210 | machines, unfortunately, the elapsed time may be up to one second less | |
917 | than you specified because of how seconds are counted, and | |
1211 | or more than you specified because of how seconds are counted, and | |
918 | scheduling may delay the delivery of the signal even further.) | |
1212 | process scheduling may delay the delivery of the signal even further.) | |
919 | 1213 | |
920 | 1214 | =end original |
921 | 1215 | |
922 | 1216 | 指定した壁時計秒数が経過した後に、自プロセスに SIGALRM が |
923 | 送られてくるようにします。 | |
1217 | 送られてくるようにします。 | |
924 | C<$_>に格納されている値を | |
1218 | SECONDS が指定されていない場合は、L<C<$_>|perlvar/$_> に格納されている値を | |
925 | ||
1219 | 使います。 | |
926 | 最大で | |
1220 | (マシンによっては、秒の数え方が異なるため、指定した秒数よりも最大で | |
1221 | 1 秒ずれます。) | |
927 | 1222 | |
928 | 1223 | =begin original |
929 | 1224 | |
930 | 1225 | Only one timer may be counting at once. Each call disables the |
931 | 1226 | previous timer, and an argument of C<0> may be supplied to cancel the |
932 | 1227 | previous timer without starting a new one. The returned value is the |
933 | 1228 | amount of time remaining on the previous timer. |
934 | 1229 | |
935 | 1230 | =end original |
936 | 1231 | |
937 | 1232 | 一度には一つのタイマだけが設定可能です。 |
938 | 1233 | 呼び出しを行なう度に、以前のタイマを無効にしますし、 |
939 | 1234 | 新しくタイマを起動しないで以前のタイマをキャンセルするために |
940 | 1235 | 引数に C<0> を指定して呼び出すことができます。 |
941 | 1236 | 以前のタイマの残り時間が、返り値となります。 |
942 | 1237 | |
943 | 1238 | =begin original |
944 | 1239 | |
945 | For delays of finer granularity than one second, the Time::HiRes module | |
1240 | For delays of finer granularity than one second, the L<Time::HiRes> module | |
946 | 1241 | (from CPAN, and starting from Perl 5.8 part of the standard |
947 | distribution) provides | |
1242 | distribution) provides | |
948 | ||
1243 | L<C<ualarm>|Time::HiRes/ualarm ( $useconds [, $interval_useconds ] )>. | |
949 | m | |
1244 | You may also use Perl's four-argument version of | |
950 | ||
1245 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> leaving the first three | |
1246 | arguments undefined, or you might be able to use the | |
1247 | L<C<syscall>|/syscall NUMBER, LIST> interface to access L<setitimer(2)> | |
1248 | if your system supports it. See L<perlfaq8> for details. | |
951 | 1249 | |
952 | 1250 | =end original |
953 | 1251 | |
954 | 1 秒より精度の高いスリープを行なうには、 | |
1252 | 1 秒より精度の高いスリープを行なうには、L<Time::HiRes> モジュール(CPAN から、 | |
955 | ||
1253 | また Perl 5.8 からは標準配布されています) が | |
956 | ||
1254 | L<C<usleep>|Time::HiRes/usleep ( $useconds )> を提供します。 | |
957 | Perl の 4 引数版 select | |
1255 | Perl の 4 引数版 L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を最初の | |
958 | setitimer(2) をサポートしているシステムでは、 | |
1256 | 3 引数を未定義にして使うか、L<setitimer(2)> をサポートしているシステムでは、 | |
959 | C<syscall> インタフェースを使って | |
1257 | Perl の L<C<syscall>|/syscall NUMBER, LIST> インタフェースを使って | |
1258 | アクセスすることもできます。 | |
960 | 1259 | 詳しくは L<perlfaq8> を参照してください。 |
961 | 1260 | |
962 | 1261 | =begin original |
963 | 1262 | |
964 | It is usually a mistake to intermix C<alarm> | |
1263 | It is usually a mistake to intermix L<C<alarm>|/alarm SECONDS> and | |
965 | C<sleep> | |
1264 | L<C<sleep>|/sleep EXPR> calls, because L<C<sleep>|/sleep EXPR> may be | |
1265 | internally implemented on your system with L<C<alarm>|/alarm SECONDS>. | |
966 | 1266 | |
967 | 1267 | =end original |
968 | 1268 | |
969 | C<alarm> と C<sleep> を混ぜて使うのは | |
1269 | L<C<alarm>|/alarm SECONDS> と L<C<sleep>|/sleep EXPR> を混ぜて使うのは | |
970 | C<sleep> | |
1270 | 普通は間違いです; なぜなら、L<C<sleep>|/sleep EXPR> は内部的に | |
1271 | L<C<alarm>|/alarm SECONDS> を使って内部的に実装されているかも | |
971 | 1272 | しれないからです。 |
972 | 1273 | |
973 | 1274 | =begin original |
974 | 1275 | |
975 | If you want to use C<alarm> to time out a system call | |
1276 | If you want to use L<C<alarm>|/alarm SECONDS> to time out a system call | |
976 | C<eval>/C<die> pair. You | |
1277 | you need to use an L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> pair. You | |
977 | ||
1278 | can't rely on the alarm causing the system call to fail with | |
978 | ||
1279 | L<C<$!>|perlvar/$!> set to C<EINTR> because Perl sets up signal handlers | |
979 | ||
1280 | to restart system calls on some systems. Using | |
1281 | L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> always works, modulo the | |
1282 | caveats given in L<perlipc/"Signals">. | |
980 | 1283 | |
981 | 1284 | =end original |
982 | 1285 | |
983 | C<alarm> をシステムコールの時間切れのために使いたいなら、 | |
1286 | L<C<alarm>|/alarm SECONDS> をシステムコールの時間切れのために使いたいなら、 | |
984 | C<eval>/C<die> のペアで使う必要があります。 | |
1287 | L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> のペアで使う必要があります。 | |
985 | システムコールが失敗したときに C<$!> に C<EINTR> が | |
1288 | システムコールが失敗したときに L<C<$!>|perlvar/$!> に C<EINTR> が | |
986 | 頼ってはいけません | |
1289 | セットされることに頼ってはいけません; なぜならシステムによっては Perl は | |
987 | 1290 | システムコールを再開するためにシグナルハンドラを設定するからです。 |
988 | C<eval>/C<die> は常にうまく動きます | |
1291 | L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> は常にうまく動きます; | |
989 | 注意点については L<perlipc/"Signals"> を参照して | |
1292 | 注意点については L<perlipc/"Signals"> を参照してください。 | |
990 | 1293 | |
991 | 1294 | eval { |
992 | 1295 | local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required |
993 | 1296 | alarm $timeout; |
994 | $nread = sysread | |
1297 | my $nread = sysread $socket, $buffer, $size; | |
995 | 1298 | alarm 0; |
996 | 1299 | }; |
997 | 1300 | if ($@) { |
998 | 1301 | die unless $@ eq "alarm\n"; # propagate unexpected errors |
999 | 1302 | # timed out |
1000 | 1303 | } |
1001 | 1304 | else { |
1002 | 1305 | # didn't |
1003 | 1306 | } |
1004 | 1307 | |
1005 | 1308 | =begin original |
1006 | 1309 | |
1007 | 1310 | For more information see L<perlipc>. |
1008 | 1311 | |
1009 | 1312 | =end original |
1010 | 1313 | |
1011 | 1314 | さらなる情報については L<perlipc> を参照してください。 |
1012 | 1315 | |
1316 | =begin original | |
1317 | ||
1318 | Portability issues: L<perlport/alarm>. | |
1319 | ||
1320 | =end original | |
1321 | ||
1322 | 移植性の問題: L<perlport/alarm>。 | |
1323 | ||
1013 | 1324 | =item atan2 Y,X |
1014 | 1325 | X<atan2> X<arctangent> X<tan> X<tangent> |
1015 | 1326 | |
1327 | =for Pod::Functions arctangent of Y/X in the range -PI to PI | |
1328 | ||
1016 | 1329 | =begin original |
1017 | 1330 | |
1018 | 1331 | Returns the arctangent of Y/X in the range -PI to PI. |
1019 | 1332 | |
1020 | 1333 | =end original |
1021 | 1334 | |
1022 | 1335 | -πからπの範囲で Y/X の逆正接を返します。 |
1023 | 1336 | |
1024 | 1337 | =begin original |
1025 | 1338 | |
1026 | For the tangent operation, you may use the | |
1339 | For the tangent operation, you may use the | |
1027 | function, or use the familiar | |
1340 | L<C<Math::Trig::tan>|Math::Trig/B<tan>> function, or use the familiar | |
1341 | relation: | |
1028 | 1342 | |
1029 | 1343 | =end original |
1030 | 1344 | |
1031 | 正接を求めたいときは、C<Math::Trig::tan> を使うか、 | |
1345 | 正接を求めたいときは、L<C<Math::Trig::tan>|Math::Trig/B<tan>> を使うか、 | |
1032 | 1346 | 以下のよく知られた関係を使ってください。 |
1033 | 1347 | |
1034 | 1348 | sub tan { sin($_[0]) / cos($_[0]) } |
1035 | 1349 | |
1036 | 1350 | =begin original |
1037 | 1351 | |
1038 | 1352 | The return value for C<atan2(0,0)> is implementation-defined; consult |
1039 | your atan2(3) manpage for more information. | |
1353 | your L<atan2(3)> manpage for more information. | |
1040 | 1354 | |
1041 | 1355 | =end original |
1042 | 1356 | |
1043 | 1357 | C<atan2(0,0)> の返り値は実装依存です; さらなる情報については |
1044 | atan2(3) man ページを参照してください。 | |
1358 | L<atan2(3)> man ページを参照してください。 | |
1045 | 1359 | |
1360 | =begin original | |
1361 | ||
1362 | Portability issues: L<perlport/atan2>. | |
1363 | ||
1364 | =end original | |
1365 | ||
1366 | 移植性の問題: L<perlport/atan2>。 | |
1367 | ||
1046 | 1368 | =item bind SOCKET,NAME |
1047 | 1369 | X<bind> |
1048 | 1370 | |
1371 | =for Pod::Functions binds an address to a socket | |
1372 | ||
1049 | 1373 | =begin original |
1050 | 1374 | |
1051 | Binds a network address to a socket, just as bind(2) | |
1375 | Binds a network address to a socket, just as L<bind(2)> | |
1052 | 1376 | does. Returns true if it succeeded, false otherwise. NAME should be a |
1053 | 1377 | packed address of the appropriate type for the socket. See the examples in |
1054 | 1378 | L<perlipc/"Sockets: Client/Server Communication">. |
1055 | 1379 | |
1056 | 1380 | =end original |
1057 | 1381 | |
1058 | bind(2) システムコールと同様に、ネットワークアドレスをソケットに | |
1382 | L<bind(2)> システムコールと同様に、ネットワークアドレスをソケットに | |
1059 | ||
1383 | 結び付けます。 | |
1060 | ||
1384 | 成功時には真を、さもなければ偽を返します。 | |
1385 | NAME は、ソケットに対する、適切な型のパックされた | |
1386 | アドレスでなければなりません。 | |
1061 | 1387 | L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。 |
1062 | 1388 | |
1063 | 1389 | =item binmode FILEHANDLE, LAYER |
1064 | 1390 | X<binmode> X<binary> X<text> X<DOS> X<Windows> |
1065 | 1391 | |
1066 | 1392 | =item binmode FILEHANDLE |
1067 | 1393 | |
1394 | =for Pod::Functions prepare binary files for I/O | |
1395 | ||
1068 | 1396 | =begin original |
1069 | 1397 | |
1070 | 1398 | Arranges for FILEHANDLE to be read or written in "binary" or "text" |
1071 | 1399 | mode on systems where the run-time libraries distinguish between |
1072 | 1400 | binary and text files. If FILEHANDLE is an expression, the value is |
1073 | 1401 | taken as the name of the filehandle. Returns true on success, |
1074 | otherwise it returns C<undef> and sets | |
1402 | otherwise it returns L<C<undef>|/undef EXPR> and sets | |
1403 | L<C<$!>|perlvar/$!> (errno). | |
1075 | 1404 | |
1076 | 1405 | =end original |
1077 | 1406 | |
1078 | 1407 | バイナリファイルとテキストファイルを区別する OS において、 |
1079 | 1408 | FILEHANDLE を「バイナリ」または「テキスト」で読み書きするように |
1080 | 1409 | 指定します。 |
1081 | 1410 | FILEHANDLE が式である場合には、その式の値がファイルハンドルの |
1082 | 1411 | 名前として使われます。 |
1083 | 成功時には真を返し、失敗時には C<undef> | |
1412 | 成功時には真を返し、失敗時には L<C<undef>|/undef EXPR> を返して | |
1413 | L<C<$!>|perlvar/$!> (errno) を設定します。 | |
1084 | 1414 | |
1085 | 1415 | =begin original |
1086 | 1416 | |
1087 | On some systems (in general, DOS- and Windows-based systems) | |
1417 | On some systems (in general, DOS- and Windows-based systems) | |
1088 | is necessary when you're not | |
1418 | L<C<binmode>|/binmode FILEHANDLE, LAYER> is necessary when you're not | |
1089 | of portability it is a good idea | |
1419 | working with a text file. For the sake of portability it is a good idea | |
1090 | a | |
1420 | always to use it when appropriate, and never to use it when it isn't | |
1091 | set their I/O to be by default | |
1421 | appropriate. Also, people can set their I/O to be by default | |
1422 | UTF8-encoded Unicode, not bytes. | |
1092 | 1423 | |
1093 | 1424 | =end original |
1094 | 1425 | |
1095 | テキストファイルでないものを扱う場合に | |
1426 | テキストファイルでないものを扱う場合に | |
1427 | L<C<binmode>|/binmode FILEHANDLE, LAYER> が必要な | |
1096 | 1428 | システムもあります(一般的には DOS と Windows ベースのシステムです)。 |
1097 | 1429 | 移植性のために、適切なときには常にこれを使い、適切でないときには |
1098 | 1430 | 決して使わないというのは良い考えです。 |
1099 | 1431 | また、デフォルトとして I/O を bytes ではなく UTF-8 エンコードされた |
1100 | 1432 | Unicode にセットすることも出来ます。 |
1101 | 1433 | |
1102 | 1434 | =begin original |
1103 | 1435 | |
1104 | In other words: regardless of platform, use | |
1436 | In other words: regardless of platform, use | |
1105 | ||
1437 | L<C<binmode>|/binmode FILEHANDLE, LAYER> on binary data, like images, | |
1438 | for example. | |
1106 | 1439 | |
1107 | 1440 | =end original |
1108 | 1441 | |
1109 | 1442 | 言い換えると: プラットフォームに関わらず、 |
1110 | 例えばイメージのようなバイナリファイルに対しては | |
1443 | 例えばイメージのようなバイナリファイルに対しては | |
1111 | 使ってください。 | |
1444 | L<C<binmode>|/binmode FILEHANDLE, LAYER> を使ってください。 | |
1112 | 1445 | |
1113 | 1446 | =begin original |
1114 | 1447 | |
1115 | 1448 | If LAYER is present it is a single string, but may contain multiple |
1116 | directives. The directives alter the behaviour of the filehandle. | |
1449 | directives. The directives alter the behaviour of the filehandle. | |
1117 | 1450 | When LAYER is present, using binmode on a text file makes sense. |
1118 | 1451 | |
1119 | 1452 | =end original |
1120 | 1453 | |
1121 | 1454 | LAYER が存在すると、それは単一の文字列ですが、複数の指示子を |
1122 | 1455 | 含むことができます。 |
1123 | 1456 | 指示子はファイルハンドルの振る舞いを変更します。 |
1124 | 1457 | LAYER が存在すると、テキストファイルでの binmode が意味を持ちます。 |
1125 | 1458 | |
1126 | 1459 | =begin original |
1127 | 1460 | |
1128 | 1461 | If LAYER is omitted or specified as C<:raw> the filehandle is made |
1129 | suitable for passing binary data. This includes turning off possible CRLF | |
1462 | suitable for passing binary data. This includes turning off possible CRLF | |
1130 | 1463 | translation and marking it as bytes (as opposed to Unicode characters). |
1131 | 1464 | Note that, despite what may be implied in I<"Programming Perl"> (the |
1132 | 1465 | Camel, 3rd edition) or elsewhere, C<:raw> is I<not> simply the inverse of C<:crlf>. |
1133 | 1466 | Other layers that would affect the binary nature of the stream are |
1134 | I<also> disabled. See L<PerlIO>, L<perlrun>, and the discussion about the | |
1467 | I<also> disabled. See L<PerlIO>, L<perlrun>, and the discussion about the | |
1135 | 1468 | PERLIO environment variable. |
1136 | 1469 | |
1137 | 1470 | =end original |
1138 | 1471 | |
1139 | 1472 | LAYER が省略されたり、C<:raw> が指定されると、ファイルハンドルはバイナリ |
1140 | 1473 | データの通過に適するように設定されます。 |
1141 | 1474 | これには CRLF 変換をオフにしたり、それぞれを(Unicode 文字ではなく) |
1142 | 1475 | バイトであるとマークしたりすることを含みます。 |
1143 | 1476 | I<"プログラミング Perl">(ラクダ本第三版) やその他で暗示されているにも関わらず、 |
1144 | 1477 | C<:raw> は単なる C<:crlf> の I<逆ではありません>。 |
1145 | 1478 | ストリームのバイナリとしての性質に影響を与える |
1146 | 1479 | I<その他の層も無効にされます>。 |
1147 | 1480 | L<PerlIO>, L<perlrun> およびPERLIO 環境変数に関する議論を参照してください。 |
1148 | 1481 | |
1149 | 1482 | =begin original |
1150 | 1483 | |
1151 | 1484 | The C<:bytes>, C<:crlf>, C<:utf8>, and any other directives of the |
1152 | form C<:...>, are called I/O I<layers>. The | |
1485 | form C<:...>, are called I/O I<layers>. The L<open> pragma can be used to | |
1153 | establish default I/O layers. | |
1486 | establish default I/O layers. | |
1154 | 1487 | |
1155 | 1488 | =end original |
1156 | 1489 | |
1157 | 1490 | C<:bytes>, C<:crlf>, and C<:utf8>, 及びその他の C<:...> 形式の指示子は |
1158 | 1491 | I/O I<層> が呼び出されます。 |
1159 | ||
1492 | L<open> プラグマはデフォルト I/O 層を指定するために使われます。 | |
1160 | L<open> を参照してください。 | |
1161 | 1493 | |
1162 | 1494 | =begin original |
1163 | 1495 | |
1164 | I<The LAYER parameter of the binmode | |
1496 | I<The LAYER parameter of the L<C<binmode>|/binmode FILEHANDLE, LAYER> | |
1165 | in "Programming Perl, 3rd | |
1497 | function is described as "DISCIPLINE" in "Programming Perl, 3rd | |
1166 | ||
1498 | Edition". However, since the publishing of this book, by many known as | |
1167 | ||
1499 | "Camel III", the consensus of the naming of this functionality has moved | |
1168 | ||
1500 | from "discipline" to "layer". All documentation of this version of Perl | |
1169 | "disciplines". Now back to | |
1501 | therefore refers to "layers" rather than to "disciplines". Now back to | |
1502 | the regularly scheduled documentation...> | |
1170 | 1503 | |
1171 | 1504 | =end original |
1172 | 1505 | |
1173 | I<binmode | |
1506 | I<L<C<binmode>|/binmode FILEHANDLE, LAYER> 関数の LAYER パラメータは | |
1507 | 「プログラミングPerl 第 3 版」では | |
1174 | 1508 | 「ディシプリン(DISCIPLINE)」と表現されていました。 |
1175 | しかし、「ラクダ本第3版」として知られているこの本の出版後、この機能の名前は | |
1509 | しかし、「ラクダ本第 3 版」として知られているこの本の出版後、この機能の名前は | |
1176 | 1510 | 「ディシプリン」から「層」に変更することで合意されました。 |
1177 | 1511 | 従って、このバージョンの Perl の全ての文書では「ディシプリン」ではなく |
1178 | 「層」と記述されています。では通常の解説に戻ります… | |
1512 | 「層」と記述されています。では通常の解説に戻ります…> | |
1179 | 1513 | |
1180 | 1514 | =begin original |
1181 | 1515 | |
1182 | 1516 | To mark FILEHANDLE as UTF-8, use C<:utf8> or C<:encoding(UTF-8)>. |
1183 | 1517 | C<:utf8> just marks the data as UTF-8 without further checking, |
1184 | 1518 | while C<:encoding(UTF-8)> checks the data for actually being valid |
1185 | UTF-8. More details can be found in L<PerlIO::encoding>. | |
1519 | UTF-8. More details can be found in L<PerlIO::encoding>. | |
1186 | 1520 | |
1187 | 1521 | =end original |
1188 | 1522 | |
1189 | 1523 | FILEHANDLE が UTF-8 であるというマークをつけるには、C<:utf8> か |
1190 | 1524 | C<:encoding(UTF-8)> を使ってください。 |
1191 | 1525 | C<:utf8> は、さらなるチェックなしにデータが UTF-8 としてマークしますが、 |
1192 | 1526 | C<:encoding(UTF-8)> はデータが実際に有効な UTF-8 かどうかをチェックします。 |
1193 | 1527 | さらなる詳細は L<PerlIO::encoding> にあります。 |
1194 | 1528 | |
1195 | 1529 | =begin original |
1196 | 1530 | |
1197 | In general, binmode | |
1531 | In general, L<C<binmode>|/binmode FILEHANDLE, LAYER> should be called | |
1198 | ||
1532 | after L<C<open>|/open FILEHANDLE,EXPR> but before any I/O is done on the | |
1199 | ||
1533 | filehandle. Calling L<C<binmode>|/binmode FILEHANDLE, LAYER> normally | |
1200 | han | |
1534 | flushes any pending buffered output data (and perhaps pending input | |
1201 | ||
1535 | data) on the handle. An exception to this is the C<:encoding> layer | |
1536 | that changes the default character encoding of the handle. | |
1202 | 1537 | The C<:encoding> layer sometimes needs to be called in |
1203 | mid-stream, and it doesn't flush the stream. | |
1538 | mid-stream, and it doesn't flush the stream. C<:encoding> | |
1204 | 1539 | also implicitly pushes on top of itself the C<:utf8> layer because |
1205 | 1540 | internally Perl operates on UTF8-encoded Unicode characters. |
1206 | 1541 | |
1207 | 1542 | =end original |
1208 | 1543 | |
1209 | 一般的に binmode | |
1544 | 一般的に L<C<binmode>|/binmode FILEHANDLE, LAYER> は | |
1545 | L<C<open>|/open FILEHANDLE,EXPR> を呼び出した後、このファイルハンドルに対する | |
1210 | 1546 | I/O 操作をする前に呼び出すべきです。 |
1211 | binmode | |
1547 | L<C<binmode>|/binmode FILEHANDLE, LAYER> を呼び出すと、普通はこの | |
1212 | バッファリングされている全ての出力データ | |
1548 | ファイルハンドルに対してバッファリングされている全ての出力データ | |
1213 | 1549 | (およびおそらくは入力データ)をフラッシュします。 |
1214 | 1550 | 例外は、このハンドルに対するデフォルト文字エンコーディングを変更する |
1215 | C<:encoding> 層です | |
1551 | C<:encoding> 層です。 | |
1216 | 1552 | C<:encoding> 層はストリームの途中で呼び出す必要があることがあり、 |
1217 | 1553 | それによってストリームはフラッシュされません。 |
1218 | 1554 | Perl は内部で UTF-8 エンコードされた Unicode 文字を操作しているので、 |
1219 | 1555 | C<:encoding> は暗黙のうちに自身を C<:utf8> 層の上に押し上げます。 |
1220 | 1556 | |
1221 | 1557 | =begin original |
1222 | 1558 | |
1223 | 1559 | The operating system, device drivers, C libraries, and Perl run-time |
1224 | 1560 | system all conspire to let the programmer treat a single |
1225 | 1561 | character (C<\n>) as the line terminator, irrespective of external |
1226 | 1562 | representation. On many operating systems, the native text file |
1227 | 1563 | representation matches the internal representation, but on some |
1228 | 1564 | platforms the external representation of C<\n> is made up of more than |
1229 | 1565 | one character. |
1230 | 1566 | |
1231 | 1567 | =end original |
1232 | 1568 | |
1233 | 1569 | オペレーティングシステム、デバイスドライバ、C ライブラリ、 |
1234 | 1570 | Perl ランタイムシステムは全て、プログラマが外部表現に関わらず |
1235 | 1571 | 1 文字 (C<\n>) を行終端として扱えるように協調作業します。 |
1236 | 1572 | 多くのオペレーティングシステムでは、ネイティブテキストファイル表現は |
1237 | 1573 | 内部表現と同じですが、C<\n> の外部表現が複数文字になる |
1238 | 1574 | プラットフォームもあります。 |
1239 | 1575 | |
1240 | 1576 | =begin original |
1241 | 1577 | |
1242 | 1578 | All variants of Unix, Mac OS (old and new), and Stream_LF files on VMS use |
1243 | 1579 | a single character to end each line in the external representation of text |
1244 | 1580 | (even though that single character is CARRIAGE RETURN on old, pre-Darwin |
1245 | flavors of Mac OS, and is LINE FEED on Unix and most VMS files). In other | |
1581 | flavors of Mac OS, and is LINE FEED on Unix and most VMS files). In other | |
1246 | 1582 | systems like OS/2, DOS, and the various flavors of MS-Windows, your program |
1247 | 1583 | sees a C<\n> as a simple C<\cJ>, but what's stored in text files are the |
1248 | two characters C<\cM\cJ>. That means that if you don't use | |
1584 | two characters C<\cM\cJ>. That means that if you don't use | |
1249 | these systems, C<\cM\cJ> | |
1585 | L<C<binmode>|/binmode FILEHANDLE, LAYER> on these systems, C<\cM\cJ> | |
1250 | ||
1586 | sequences on disk will be converted to C<\n> on input, and any C<\n> in | |
1251 | ou | |
1587 | your program will be converted back to C<\cM\cJ> on output. This is | |
1252 | binary files. | |
1588 | what you want for text files, but it can be disastrous for binary files. | |
1253 | 1589 | |
1254 | 1590 | =end original |
1255 | 1591 | |
1256 | 1592 | 全ての Unix 系、(新旧の)Mac OS、VMS の Stream_LF ファイルは |
1257 | 1593 | テキストの外部表現として各行の末尾に一つの文字を |
1258 | 1594 | 使っています(しかしその文字は古い Darwin 以前の Mac OS では復帰で、 |
1259 | 1595 | Unix とほとんどのVMS のファイルでは改行です)。 |
1260 | 1596 | VMS, MS-DOS, MS-Windows 系といったその他のシステムでは、 |
1261 | 1597 | プログラムからは C<\n> は単純に C<\cJ> に見えますが、 |
1262 | 1598 | テキストファイルとして保存される場合は C<\cM\cJ> の 2 文字になります。 |
1263 | つまり、もしこれらのシステムで binmode | |
1599 | つまり、もしこれらのシステムで L<C<binmode>|/binmode FILEHANDLE, LAYER> を | |
1264 | ディスク上の C<\cM\cJ> という並びは入力時に C<\n> に変換され、 | |
1600 | 使わないと、ディスク上の C<\cM\cJ> という並びは入力時に C<\n> に変換され、 | |
1265 | 1601 | プログラムが出力した全ての C<\n> は C<\cM\cJ> に逆変換されます。 |
1266 | 1602 | これはテキストファイルの場合は思い通りの結果でしょうが、 |
1267 | 1603 | バイナリファイルの場合は悲惨です。 |
1268 | 1604 | |
1269 | 1605 | =begin original |
1270 | 1606 | |
1271 | Another consequence of using binmode | |
1607 | Another consequence of using L<C<binmode>|/binmode FILEHANDLE, LAYER> | |
1272 | special end-of-file markers will be seen as | |
1608 | (on some systems) is that special end-of-file markers will be seen as | |
1273 | For systems from the Microsoft family this | |
1609 | part of the data stream. For systems from the Microsoft family this | |
1274 | data contain C<\cZ>, the I/O subsystem will | |
1610 | means that, if your binary data contain C<\cZ>, the I/O subsystem will | |
1275 | the file, unless you use | |
1611 | regard it as the end of the file, unless you use | |
1612 | L<C<binmode>|/binmode FILEHANDLE, LAYER>. | |
1276 | 1613 | |
1277 | 1614 | =end original |
1278 | 1615 | |
1279 | binmode | |
1616 | L<C<binmode>|/binmode FILEHANDLE, LAYER> を(いくつかのシステムで) | |
1280 | 特別なファイル終端マーカーが | |
1617 | 使うことによるその他の作用としては、特別なファイル終端マーカーが | |
1281 | 見られることです。 | |
1618 | データストリームの一部として見られることです。 | |
1282 | Microsoft ファミリーのシステムでは、 | |
1619 | Microsoft ファミリーのシステムでは、 | |
1283 | ||
1620 | L<C<binmode>|/binmode FILEHANDLE, LAYER> を使っていないと、 | |
1284 | ||
1621 | もしバイナリデータに C<\cZ> が含まれていたときに、 | |
1622 | I/O サブシステムがこれをファイル終端とみなすことを意味します。 | |
1285 | 1623 | |
1286 | 1624 | =begin original |
1287 | 1625 | |
1288 | binmode | |
1626 | L<C<binmode>|/binmode FILEHANDLE, LAYER> is important not only for | |
1289 | ||
1627 | L<C<readline>|/readline EXPR> and L<C<print>|/print FILEHANDLE LIST> | |
1290 | ||
1628 | operations, but also when using | |
1291 | ||
1629 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
1630 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
1631 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
1632 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> and | |
1633 | L<C<tell>|/tell FILEHANDLE> (see L<perlport> for more details). See the | |
1634 | L<C<$E<sol>>|perlvar/$E<sol>> and L<C<$\>|perlvar/$\> variables in | |
1635 | L<perlvar> for how to manually set your input and output | |
1292 | 1636 | line-termination sequences. |
1293 | 1637 | |
1294 | 1638 | =end original |
1295 | 1639 | |
1296 | binmode | |
1640 | L<C<binmode>|/binmode FILEHANDLE, LAYER> は L<C<readline>|/readline EXPR> と | |
1297 | r | |
1641 | L<C<print>|/print FILEHANDLE LIST> 操作にだけではなく、 | |
1642 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
1643 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
1644 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
1645 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
1646 | L<C<tell>|/tell FILEHANDLE> を使うときにも重要です | |
1298 | 1647 | (詳細は L<perlport> を参照してください)。 |
1299 | 1648 | 入出力の行端末シーケンスを手動でセットする方法については |
1300 | L<perlvar> の C<$ | |
1649 | L<perlvar> の L<C<$E<sol>>|perlvar/$E<sol>> 変数と | |
1650 | L<C<$\>|perlvar/$\> 変数を参照してください。 | |
1301 | 1651 | |
1652 | =begin original | |
1653 | ||
1654 | Portability issues: L<perlport/binmode>. | |
1655 | ||
1656 | =end original | |
1657 | ||
1658 | 移植性の問題: L<perlport/binmode>。 | |
1659 | ||
1302 | 1660 | =item bless REF,CLASSNAME |
1303 | 1661 | X<bless> |
1304 | 1662 | |
1305 | 1663 | =item bless REF |
1306 | 1664 | |
1665 | =for Pod::Functions create an object | |
1666 | ||
1307 | 1667 | =begin original |
1308 | 1668 | |
1309 | 1669 | This function tells the thingy referenced by REF that it is now an object |
1310 | 1670 | in the CLASSNAME package. If CLASSNAME is omitted, the current package |
1311 | is used. Because a C<bless> is often the last | |
1671 | is used. Because a L<C<bless>|/bless REF,CLASSNAME> is often the last | |
1312 | it returns the reference for convenience. | |
1672 | thing in a constructor, it returns the reference for convenience. | |
1313 | version if a derived class might inherit the | |
1673 | Always use the two-argument version if a derived class might inherit the | |
1314 | ||
1674 | method doing the blessing. See L<perlobj> for more about the blessing | |
1315 | of objects. | |
1675 | (and blessings) of objects. | |
1316 | 1676 | |
1317 | 1677 | =end original |
1318 | 1678 | |
1319 | 1679 | この関数は、REF で渡された オブジェクトに対し、 |
1320 | 1680 | CLASSNAME 内のオブジェクトとなったことを伝えます。 |
1321 | 1681 | CLASSNAME が省略された場合には、その時点のパッケージとなります。 |
1322 | C<bless> は通常、コンストラクタの最後に | |
1682 | L<C<bless>|/bless REF,CLASSNAME> は通常、コンストラクタの最後に | |
1323 | 簡便のためにそのリファレンスを返します。 | |
1683 | 置かれますので、簡便のためにそのリファレンスを返します。 | |
1324 | 派生クラスが bless される | |
1684 | 派生クラスが bless されるメソッドを継承する場合は、 | |
1325 | 1685 | 常に 2 引数版を使ってください。 |
1326 | オブジェクトの bless (や再 bless) について、 | |
1686 | オブジェクトの bless (や再 bless) について、詳しくは と L<perlobj> を | |
1327 | ||
1687 | 参照してください。 | |
1328 | 1688 | |
1329 | 1689 | =begin original |
1330 | 1690 | |
1331 | 1691 | Consider always blessing objects in CLASSNAMEs that are mixed case. |
1332 | 1692 | Namespaces with all lowercase names are considered reserved for |
1333 | Perl pragma | |
1693 | Perl pragmas. Builtin types have all uppercase names. To prevent | |
1334 | 1694 | confusion, you may wish to avoid such package names as well. Make sure |
1335 | 1695 | that CLASSNAME is a true value. |
1336 | 1696 | |
1337 | 1697 | =end original |
1338 | 1698 | |
1339 | 1699 | 大文字小文字が混じっている CLASSNAME のオブジェクトは常に bless することを |
1340 | 1700 | 考慮してください。 |
1341 | 1701 | 全て小文字の名前を持つ名前空間は Perl プラグマのために予約されています。 |
1342 | 1702 | 組み込みの型は全て大文字の名前を持ちます。 |
1343 | 1703 | 混乱を避けるために、 |
1344 | 1704 | パッケージ名としてこのような名前は避けるべきです。 |
1345 | 1705 | CLASSNAME は真の値を持つようにしてください。 |
1346 | 1706 | |
1347 | 1707 | =begin original |
1348 | 1708 | |
1349 | 1709 | See L<perlmod/"Perl Modules">. |
1350 | 1710 | |
1351 | 1711 | =end original |
1352 | 1712 | |
1353 | L<perlmod/"Perl Modules"> を参照して | |
1713 | L<perlmod/"Perl Modules"> を参照してください。 | |
1354 | 1714 | |
1355 | 1715 | =item break |
1356 | 1716 | |
1717 | =for Pod::Functions +switch break out of a C<given> block | |
1718 | ||
1357 | 1719 | =begin original |
1358 | 1720 | |
1359 | Break out of a C<given | |
1721 | Break out of a C<given> block. | |
1360 | 1722 | |
1361 | 1723 | =end original |
1362 | 1724 | |
1363 | C<given | |
1725 | C<given> ブロックから脱出します。 | |
1364 | 1726 | |
1365 | 1727 | =begin original |
1366 | 1728 | |
1367 | ||
1729 | L<C<break>|/break> is available only if the | |
1368 | L<feature | |
1730 | L<C<"switch"> feature|feature/The 'switch' feature> is enabled or if it | |
1369 | ||
1731 | is prefixed with C<CORE::>. The | |
1732 | L<C<"switch"> feature|feature/The 'switch' feature> is enabled | |
1733 | automatically with a C<use v5.10> (or higher) declaration in the current | |
1734 | scope. | |
1370 | 1735 | |
1371 | 1736 | =end original |
1372 | 1737 | |
1373 | ||
1738 | L<C<break>|/break> は、L<C<"switch"> 機能|feature/The 'switch' feature> が | |
1374 | ||
1739 | 有効か、C<CORE::> 接頭辞を使ったときにのみ利用可能です。 | |
1375 | ||
1740 | L<C<"switch"> 機能|feature/The 'switch' feature> は、現在のスコープで | |
1741 | C<use v5.10> (またはそれ以上) 宣言があると自動的に有効になります。 | |
1376 | 1742 | |
1377 | 1743 | =item caller EXPR |
1378 | 1744 | X<caller> X<call stack> X<stack> X<stack trace> |
1379 | 1745 | |
1380 | 1746 | =item caller |
1381 | 1747 | |
1748 | =for Pod::Functions get context of the current subroutine call | |
1749 | ||
1382 | 1750 | =begin original |
1383 | 1751 | |
1384 | Returns the context of the current subroutine call. In scalar | |
1752 | Returns the context of the current pure perl subroutine call. In scalar | |
1385 | returns the caller's package name if there I<is> a caller (that is, if | |
1753 | context, returns the caller's package name if there I<is> a caller (that is, if | |
1386 | we're in a subroutine or C<eval> | |
1754 | we're in a subroutine or L<C<eval>|/eval EXPR> or | |
1387 | ||
1755 | L<C<require>|/require VERSION>) and the undefined value otherwise. | |
1756 | caller never returns XS subs and they are skipped. The next pure perl | |
1757 | sub will appear instead of the XS sub in caller's return values. In | |
1758 | list context, caller returns | |
1388 | 1759 | |
1389 | 1760 | =end original |
1390 | 1761 | |
1391 | その時点のサブルーチン呼び出しのコンテキストを返します。 | |
1762 | その時点のピュア perl サブルーチン呼び出しのコンテキストを返します。 | |
1392 | 1763 | スカラコンテキストでは、呼び元が I<ある> 場合 |
1393 | (サブルーチン、C<eval>、C<require> の中に | |
1764 | (サブルーチン、L<C<eval>|/eval EXPR>、L<C<require>|/require VERSION> の中に | |
1394 | 呼び出し元のパッケージ名を返し、 | |
1765 | いるとき) には呼び出し元のパッケージ名を返し、 | |
1395 | ||
1766 | その他のときには未定義値を返します。 | |
1767 | caller は XS サブルーチンを返すことはなく、それらは飛ばされます。 | |
1768 | XS サブルーチンの代わりに次のピュア perl サブルーチンが caller の返り値に | |
1769 | なります。 | |
1770 | リストコンテキストでは、caller は以下を返します: | |
1396 | 1771 | |
1397 | # 0 1 2 | |
1772 | # 0 1 2 | |
1398 | ($package, $filename, $line) = caller; | |
1773 | my ($package, $filename, $line) = caller; | |
1399 | 1774 | |
1400 | 1775 | =begin original |
1401 | 1776 | |
1402 | 1777 | With EXPR, it returns some extra information that the debugger uses to |
1403 | 1778 | print a stack trace. The value of EXPR indicates how many call frames |
1404 | 1779 | to go back before the current one. |
1405 | 1780 | |
1406 | 1781 | =end original |
1407 | 1782 | |
1408 | 1783 | EXPR を付けると、デバッガがスタックトレースを表示するために使う情報を返します。 |
1409 | 1784 | EXPR の値は、現状から数えて、 |
1410 | 1785 | いくつ前のコールフレームまで戻るかを示します。 |
1411 | 1786 | |
1412 | 1787 | # 0 1 2 3 4 |
1413 | | |
1788 | my ($package, $filename, $line, $subroutine, $hasargs, | |
1414 | 1789 | |
1415 | 1790 | # 5 6 7 8 9 10 |
1416 | 1791 | $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash) |
1417 | | |
1792 | = caller($i); | |
1418 | 1793 | |
1419 | 1794 | =begin original |
1420 | 1795 | |
1421 | Here $subroutine | |
1796 | Here, $subroutine is the function that the caller called (rather than the | |
1422 | ||
1797 | function containing the caller). Note that $subroutine may be C<(eval)> if | |
1423 | ||
1798 | the frame is not a subroutine call, but an L<C<eval>|/eval EXPR>. In | |
1424 | ||
1799 | such a case additional elements $evaltext and C<$is_require> are set: | |
1425 | C<e | |
1800 | C<$is_require> is true if the frame is created by a | |
1426 | ||
1801 | L<C<require>|/require VERSION> or L<C<use>|/use Module VERSION LIST> | |
1427 | ||
1802 | statement, $evaltext contains the text of the C<eval EXPR> statement. | |
1428 | fra | |
1803 | In particular, for an C<eval BLOCK> statement, $subroutine is C<(eval)>, | |
1429 | ||
1804 | but $evaltext is undefined. (Note also that each | |
1430 | C< | |
1805 | L<C<use>|/use Module VERSION LIST> statement creates a | |
1806 | L<C<require>|/require VERSION> frame inside an C<eval EXPR> frame.) | |
1807 | $subroutine may also be C<(unknown)> if this particular subroutine | |
1808 | happens to have been deleted from the symbol table. C<$hasargs> is true | |
1809 | if a new instance of L<C<@_>|perlvar/@_> was set up for the frame. | |
1431 | 1810 | C<$hints> and C<$bitmask> contain pragmatic hints that the caller was |
1432 | compiled with. | |
1811 | compiled with. C<$hints> corresponds to L<C<$^H>|perlvar/$^H>, and | |
1433 | b | |
1812 | C<$bitmask> corresponds to | |
1813 | L<C<${^WARNING_BITS}>|perlvar/${^WARNING_BITS}>. The C<$hints> and | |
1814 | C<$bitmask> values are subject to change between versions of Perl, and | |
1815 | are not meant for external use. | |
1434 | 1816 | |
1435 | 1817 | =end original |
1436 | 1818 | |
1437 | ||
1819 | ここで、$subroutine は、(caller を含む関数ではなく) caller が呼び出した | |
1438 | ||
1820 | 関数です。 | |
1821 | フレームがサブルーチン呼び出しではなく L<C<eval>|/eval EXPR> だった場合、この | |
1822 | $subroutine は C<(eval)> になることに注意してください。 | |
1439 | 1823 | この場合、追加の要素である $evaltext と C<$is_require> がセットされます: |
1440 | C<$is_require> はフレームが C<require> | |
1824 | C<$is_require> はフレームが L<C<require>|/require VERSION> または | |
1441 | ||
1825 | L<C<use>|/use Module VERSION LIST> で作られた場合に真になり、 | |
1826 | $evaltext は C<eval EXPR> のテキストが入ります。 | |
1442 | 1827 | 特に、C<eval BLOCK> の場合、$subroutine は C<(eval)> になりますが、 |
1443 | 1828 | $evaltext は未定義値になります。 |
1444 | (それぞれの C<use> は C<eval EXPR> の中で | |
1829 | (それぞれの L<C<use>|/use Module VERSION LIST> は C<eval EXPR> の中で | |
1445 | 注意してください。) | |
1830 | L<C<require>|/require VERSION> フレームを作ることに注意してください。) | |
1446 | 1831 | $subroutine は、そのサブルーチンがシンボルテーブルから削除された場合は |
1447 | 1832 | C<(unknown)> になります。 |
1448 | C<$hasargs> はこのフレーム用に C<@_> の新しい実体が | |
1833 | C<$hasargs> はこのフレーム用に L<C<@_>|perlvar/@_> の新しい実体が | |
1834 | 設定された場合に真となります。 | |
1449 | 1835 | C<$hints> と C<$bitmask> は caller がコンパイルされたときの |
1450 | 1836 | 実際的なヒントを含みます。 |
1837 | C<$hints> は L<C<$^H>|perlvar/$^H> に対応し、C<$bitmask> は | |
1838 | L<C<${^WARNING_BITS}>|perlvar/${^WARNING_BITS}> に | |
1839 | 対応します。 | |
1451 | 1840 | C<$hints> は C<$bitmask> は Perl のバージョンによって変更される |
1452 | 可能性があるので、外部での使用を想定していません。 | |
1841 | 可能性があるので、外部での使用を想定していません。 | |
1453 | 1842 | |
1454 | 1843 | =begin original |
1455 | 1844 | |
1456 | C<$hinthash> is a reference to a hash containing the value of | |
1845 | C<$hinthash> is a reference to a hash containing the value of | |
1457 | caller was compiled, or | |
1846 | L<C<%^H>|perlvar/%^H> when the caller was compiled, or | |
1458 | ||
1847 | L<C<undef>|/undef EXPR> if L<C<%^H>|perlvar/%^H> was empty. Do not | |
1848 | modify the values of this hash, as they are the actual values stored in | |
1849 | the optree. | |
1459 | 1850 | |
1460 | 1851 | =end original |
1461 | 1852 | |
1462 | C<$hinthash> は、caller がコンパイルされた時の C<%^H> の値を | |
1853 | C<$hinthash> は、caller がコンパイルされた時の L<C<%^H>|perlvar/%^H> の値を | |
1463 | ハッシュへのリファレンスか、あるいは C<%^H> が空の場合は | |
1854 | 含むハッシュへのリファレンスか、あるいは L<C<%^H>|perlvar/%^H> が空の場合は | |
1855 | L<C<undef>|/undef EXPR> です。 | |
1464 | 1856 | このハッシュの値は構文木に保管されている実際の値なので、変更しないで下さい。 |
1465 | 1857 | |
1466 | 1858 | =begin original |
1467 | 1859 | |
1468 | Furthermore, when called from within the DB package | |
1860 | Furthermore, when called from within the DB package in | |
1861 | list context, and with an argument, caller returns more | |
1469 | 1862 | detailed information: it sets the list variable C<@DB::args> to be the |
1470 | 1863 | arguments with which the subroutine was invoked. |
1471 | 1864 | |
1472 | 1865 | =end original |
1473 | 1866 | |
1474 | さらに、DB パッケージの中から呼ばれた場合は、 | |
1867 | さらに、DB パッケージの中からリストコンテキストで引数付きで呼ばれた場合は、 | |
1475 | より詳細な情報を返します | |
1868 | caller はより詳細な情報を返します; サブルーチンが起動されたときの引数を | |
1476 | ||
1869 | 変数 C<@DB::args> に設定します。 | |
1477 | 1870 | |
1478 | 1871 | =begin original |
1479 | 1872 | |
1480 | 1873 | Be aware that the optimizer might have optimized call frames away before |
1481 | C<caller> had a chance to get the information. That | |
1874 | L<C<caller>|/caller EXPR> had a chance to get the information. That | |
1482 | might not return information about the call | |
1875 | means that C<caller(N)> might not return information about the call | |
1483 | C<< N > 1 >>. In particular, C<@DB::args> | |
1876 | frame you expect it to, for C<< N > 1 >>. In particular, C<@DB::args> | |
1484 | previous time C<caller> | |
1877 | might have information from the previous time L<C<caller>|/caller EXPR> | |
1878 | was called. | |
1485 | 1879 | |
1486 | 1880 | =end original |
1487 | 1881 | |
1488 | C<caller> が情報を得る前にオプティマイザが呼び出しフレームを | |
1882 | L<C<caller>|/caller EXPR> が情報を得る前にオプティマイザが呼び出しフレームを | |
1489 | しまうかもしれないことに注意してください。 | |
1883 | 最適化してしまうかもしれないことに注意してください。 | |
1490 | 1884 | これは、C<caller(N)> が C<< N > 1 >> のとき、 |
1491 | 1885 | あなたが予測した呼び出しフレームの情報を返さないかもしれないことを意味します。 |
1492 | 特に、C<@DB::args> は C<caller> が前回呼び出された時の情報を | |
1886 | 特に、C<@DB::args> は L<C<caller>|/caller EXPR> が前回呼び出された時の情報を | |
1493 | 1887 | 持っているかもしれません。 |
1494 | 1888 | |
1495 | 1889 | =begin original |
1496 | 1890 | |
1497 | 1891 | Be aware that setting C<@DB::args> is I<best effort>, intended for |
1498 | debugging or generating backtraces, and should not be relied upon. In | |
1892 | debugging or generating backtraces, and should not be relied upon. In | |
1499 | particular, as C<@_> contains aliases to the caller' | |
1893 | particular, as L<C<@_>|perlvar/@_> contains aliases to the caller's | |
1500 | not take a copy of C<@_> | |
1894 | arguments, Perl does not take a copy of L<C<@_>|perlvar/@_>, so | |
1501 | ||
1895 | C<@DB::args> will contain modifications the subroutine makes to | |
1502 | ||
1896 | L<C<@_>|perlvar/@_> or its contents, not the original values at call | |
1503 | ||
1897 | time. C<@DB::args>, like L<C<@_>|perlvar/@_>, does not hold explicit | |
1504 | re | |
1898 | references to its elements, so under certain cases its elements may have | |
1505 | o | |
1899 | become freed and reallocated for other variables or temporary values. | |
1506 | ||
1900 | Finally, a side effect of the current implementation is that the effects | |
1507 | ||
1901 | of C<shift @_> can I<normally> be undone (but not C<pop @_> or other | |
1508 | ||
1902 | splicing, I<and> not if a reference to L<C<@_>|perlvar/@_> has been | |
1509 | ||
1903 | taken, I<and> subject to the caveat about reallocated elements), so | |
1904 | C<@DB::args> is actually a hybrid of the current state and initial state | |
1905 | of L<C<@_>|perlvar/@_>. Buyer beware. | |
1510 | 1906 | |
1511 | 1907 | =end original |
1512 | 1908 | |
1513 | 1909 | C<@DB::args> の設定は I<ベストエフォート> で、デバッグやバックトレースの |
1514 | 1910 | 生成を目的としていて、これに依存するべきではないということにも |
1515 | 1911 | 注意してください。 |
1516 | 特に、C<@_> は呼び出し元の引数へのエイリアスを含んでいるので、 | |
1912 | 特に、L<C<@_>|perlvar/@_> は呼び出し元の引数へのエイリアスを含んでいるので、 | |
1517 | C<@_> のコピーを取らず、従って C<@DB::args> は | |
1913 | Perl は L<C<@_>|perlvar/@_> のコピーを取らず、従って C<@DB::args> は | |
1518 | C<@_> やその内容に行った変更を含んでいて、 | |
1914 | サブルーチンが L<C<@_>|perlvar/@_> やその内容に行った変更を含んでいて、 | |
1519 | ||
1915 | 呼び出し時の元の値ではありません。 | |
1520 | ||
1916 | C<@DB::args> は、L<C<@_>|perlvar/@_> と同様、その要素への明示的な | |
1521 | ||
1917 | リファレンスを保持しないので、ある種の状況では、解放されて他の変数や | |
1918 | 一時的な値のために再割り当てされているかもしれません。 | |
1522 | 1919 | 最後に、現在の実装の副作用は、C<shift @_> の効果は I<普通は> 行われない |
1523 | 1920 | (しかし C<pop @_> やその他の splice は違い、I<そして> もし |
1524 | C<@_> のリファレンスが取られると違い、I<そして> 再割り当てされた | |
1921 | L<C<@_>|perlvar/@_> のリファレンスが取られると違い、I<そして> 再割り当てされた | |
1525 | 問題になりやすいです)ことなので、C<@DB::args> は実際には現在の | |
1922 | 要素に関する問題になりやすいです)ことなので、C<@DB::args> は実際には現在の | |
1526 | C<@_> の初期状態との合成物となります。 | |
1923 | 状態と L<C<@_>|perlvar/@_> の初期状態との合成物となります。 | |
1527 | 1924 | ご用心を。 |
1528 | 1925 | |
1529 | 1926 | =item chdir EXPR |
1530 | 1927 | X<chdir> |
1531 | 1928 | X<cd> |
1532 | 1929 | X<directory, change> |
1533 | 1930 | |
1534 | 1931 | =item chdir FILEHANDLE |
1535 | 1932 | |
1536 | 1933 | =item chdir DIRHANDLE |
1537 | 1934 | |
1538 | 1935 | =item chdir |
1539 | 1936 | |
1937 | =for Pod::Functions change your current working directory | |
1938 | ||
1540 | 1939 | =begin original |
1541 | 1940 | |
1542 | Changes the working directory to EXPR, if possible. If EXPR is omitted, | |
1941 | Changes the working directory to EXPR, if possible. If EXPR is omitted, | |
1543 | 1942 | changes to the directory specified by C<$ENV{HOME}>, if set; if not, |
1544 | changes to the directory specified by C<$ENV{LOGDIR}>. (Under VMS, the | |
1943 | changes to the directory specified by C<$ENV{LOGDIR}>. (Under VMS, the | |
1545 | variable C<$ENV{SYS$LOGIN}> is also checked, and used if it is set.) If | |
1944 | variable C<$ENV{'SYS$LOGIN'}> is also checked, and used if it is set.) If | |
1546 | neither is set, C<chdir> does nothing | |
1945 | neither is set, L<C<chdir>|/chdir EXPR> does nothing and fails. It | |
1547 | false otherwise. See the example under | |
1946 | returns true on success, false otherwise. See the example under | |
1947 | L<C<die>|/die LIST>. | |
1548 | 1948 | |
1549 | 1949 | =end original |
1550 | 1950 | |
1551 | 1951 | (可能であれば、) カレントディレクトリを EXPR に移します。 |
1552 | EXPR を指定しないと、C<$ENV{HOME}> が設定されていれば、 | |
1952 | EXPR を指定しないと、C<$ENV{HOME}> が設定されていれば、そのディレクトリに | |
1553 | そのディレクトリに | |
1953 | 移ります; そうでなく、C<$ENV{LOGDIR}>が設定されていれば、そのディレクトリに | |
1554 | ||
1954 | 移ります。 | |
1555 | (VMS では C<$ENV{SYS$LOGIN}> もチェックされ、もしセットされていれば | |
1955 | (VMS では C<$ENV{'SYS$LOGIN'}> もチェックされ、もしセットされていれば | |
1556 | ||
1956 | 使われます。) | |
1957 | どちらも設定されていなければ、L<C<chdir>|/chdir EXPR> は何もせずに失敗します。 | |
1557 | 1958 | 成功時には真を返し、そうでなければ偽を返します。 |
1558 | C<die> の項の例を参照してください。 | |
1959 | L<C<die>|/die LIST> の項の例を参照してください。 | |
1559 | 1960 | |
1560 | 1961 | =begin original |
1561 | 1962 | |
1562 | On systems that support fchdir(2), you may pass a filehandle or | |
1963 | On systems that support L<fchdir(2)>, you may pass a filehandle or | |
1563 | directory handle as the argument. On systems that don't support fchdir(2), | |
1964 | directory handle as the argument. On systems that don't support L<fchdir(2)>, | |
1564 | 1965 | passing handles raises an exception. |
1565 | 1966 | |
1566 | 1967 | =end original |
1567 | 1968 | |
1568 | fchdir(2) に対応しているシステムでは、ファイルハンドルや | |
1969 | L<fchdir(2)> に対応しているシステムでは、ファイルハンドルや | |
1569 | 1970 | ディレクトリハンドルを引数として渡せます。 |
1570 | fchdir に対応していないシステムでは、ハンドルを渡すと例外が発生します。 | |
1971 | L<fchdir(2)> に対応していないシステムでは、ハンドルを渡すと例外が発生します。 | |
1571 | 1972 | |
1572 | 1973 | =item chmod LIST |
1573 | 1974 | X<chmod> X<permission> X<mode> |
1574 | 1975 | |
1976 | =for Pod::Functions changes the permissions on a list of files | |
1977 | ||
1575 | 1978 | =begin original |
1576 | 1979 | |
1577 | 1980 | Changes the permissions of a list of files. The first element of the |
1578 | 1981 | list must be the numeric mode, which should probably be an octal |
1579 | 1982 | number, and which definitely should I<not> be a string of octal digits: |
1580 | 1983 | C<0644> is okay, but C<"0644"> is not. Returns the number of files |
1581 | successfully changed. See also L</oct> if all you have is a | |
1984 | successfully changed. See also L<C<oct>|/oct EXPR> if all you have is a | |
1985 | string. | |
1582 | 1986 | |
1583 | 1987 | =end original |
1584 | 1988 | |
1585 | 1989 | LIST に含まれるファイルの、パーミッションを変更します。 |
1586 | LIST の最初の要素は、数値表現のモードでなければなりません | |
1990 | LIST の最初の要素は、数値表現のモードでなければなりません; | |
1587 | 恐らく 8 進表記の数であるべきでしょう | |
1991 | 恐らく 8 進表記の数であるべきでしょう: しかし、8 進表記の | |
1588 | C<0644> は OK ですが、 C< | |
1992 | 文字列では I<いけません>: C<0644> は OK ですが、 C<"0644"> は | |
1993 | だめ、ということです。 | |
1589 | 1994 | 変更に成功したファイルの数を返します。 |
1590 | 文字列を使いたい場合は、L</oct> を参照してください。 | |
1995 | 文字列を使いたい場合は、L<C<oct>|/oct EXPR> を参照してください。 | |
1591 | 1996 | |
1592 | $cnt = chmod 0755, "foo", "bar"; | |
1997 | my $cnt = chmod 0755, "foo", "bar"; | |
1593 | 1998 | chmod 0755, @executables; |
1594 | $mode = "0644"; chmod $mode, "foo"; # !!! sets mode to | |
1999 | my $mode = "0644"; chmod $mode, "foo"; # !!! sets mode to | |
1595 | # --w----r-T | |
2000 | # --w----r-T | |
1596 | $mode = "0644"; chmod oct($mode), "foo"; # this is better | |
2001 | my $mode = "0644"; chmod oct($mode), "foo"; # this is better | |
1597 | $mode = 0644; chmod $mode, "foo"; # this is best | |
2002 | my $mode = 0644; chmod $mode, "foo"; # this is best | |
1598 | 2003 | |
1599 | 2004 | =begin original |
1600 | 2005 | |
1601 | On systems that support fchmod(2), you may pass filehandles among the | |
2006 | On systems that support L<fchmod(2)>, you may pass filehandles among the | |
1602 | files. On systems that don't support fchmod(2), passing filehandles raises | |
2007 | files. On systems that don't support L<fchmod(2)>, passing filehandles raises | |
1603 | 2008 | an exception. Filehandles must be passed as globs or glob references to be |
1604 | 2009 | recognized; barewords are considered filenames. |
1605 | 2010 | |
1606 | 2011 | =end original |
1607 | 2012 | |
1608 | fchmod(2) に対応しているシステムでは、ファイルハンドルを引数として | |
2013 | L<fchmod(2)> に対応しているシステムでは、ファイルハンドルを引数として | |
1609 | ||
2014 | 渡せます。 | |
2015 | L<fchmod(2)> に対応していないシステムでは、ファイルハンドルを渡すと | |
1610 | 2016 | 例外が発生します。 |
1611 | 2017 | ファイルハンドルを認識させるためには、グロブまたはリファレンスとして |
1612 | 2018 | 渡されなければなりません; |
1613 | 2019 | 裸の単語はファイル名として扱われます。 |
1614 | 2020 | |
1615 | 2021 | open(my $fh, "<", "foo"); |
1616 | 2022 | my $perm = (stat $fh)[2] & 07777; |
1617 | 2023 | chmod($perm | 0600, $fh); |
1618 | 2024 | |
1619 | 2025 | =begin original |
1620 | 2026 | |
1621 | You can also import the symbolic C<S_I*> constants from the | |
2027 | You can also import the symbolic C<S_I*> constants from the | |
2028 | L<C<Fcntl>|Fcntl> module: | |
1622 | 2029 | |
1623 | module: | |
1624 | ||
1625 | 2030 | =end original |
1626 | 2031 | |
1627 | ||
2032 | L<C<Fcntl>|Fcntl> モジュールから C<S_I*> シンボル定数を | |
1628 | インポートすることもできます | |
2033 | インポートすることもできます: | |
1629 | 2034 | |
1630 | 2035 | use Fcntl qw( :mode ); |
1631 | 2036 | chmod S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, @executables; |
1632 | 2037 | # Identical to the chmod 0755 of the example above. |
1633 | 2038 | |
2039 | =begin original | |
2040 | ||
2041 | Portability issues: L<perlport/chmod>. | |
2042 | ||
2043 | =end original | |
2044 | ||
2045 | 移植性の問題: L<perlport/chmod>。 | |
2046 | ||
1634 | 2047 | =item chomp VARIABLE |
1635 | 2048 | X<chomp> X<INPUT_RECORD_SEPARATOR> X<$/> X<newline> X<eol> |
1636 | 2049 | |
1637 | 2050 | =item chomp( LIST ) |
1638 | 2051 | |
1639 | 2052 | =item chomp |
1640 | 2053 | |
2054 | =for Pod::Functions remove a trailing record separator from a string | |
2055 | ||
1641 | 2056 | =begin original |
1642 | 2057 | |
1643 | This safer version of L</chop> removes any trail | |
2058 | This safer version of L<C<chop>|/chop VARIABLE> removes any trailing | |
1644 | that corresponds to the current value of | |
2059 | string that corresponds to the current value of | |
1645 | $INPUT_RECORD_SEPARATOR | |
2060 | L<C<$E<sol>>|perlvar/$E<sol>> (also known as C<$INPUT_RECORD_SEPARATOR> | |
2061 | in the L<C<English>|English> module). It returns the total | |
1646 | 2062 | number of characters removed from all its arguments. It's often used to |
1647 | 2063 | remove the newline from the end of an input record when you're worried |
1648 | 2064 | that the final record may be missing its newline. When in paragraph |
1649 | mode (C<$/ = | |
2065 | mode (C<$/ = ''>), it removes all trailing newlines from the string. | |
1650 | When in slurp mode (C<$/ = undef>) or fixed-length record mode | |
2066 | When in slurp mode (C<$/ = undef>) or fixed-length record mode | |
1651 | a reference to an integer or the like; | |
2067 | (L<C<$E<sol>>|perlvar/$E<sol>> is a reference to an integer or the like; | |
1652 | remove anything. | |
2068 | see L<perlvar>), L<C<chomp>|/chomp VARIABLE> won't remove anything. | |
1653 | If VARIABLE is omitted, it chomps C<$_>. Example: | |
2069 | If VARIABLE is omitted, it chomps L<C<$_>|perlvar/$_>. Example: | |
1654 | 2070 | |
1655 | 2071 | =end original |
1656 | 2072 | |
1657 | より安全な C<chop> (以下を参照してください) です | |
2073 | より安全な L<C<chop>|/chop VARIABLE> (以下を参照してください) です; | |
1658 | C<$/> (C<English> モジュールでは、 | |
2074 | L<C<$E<sol>>|perlvar/$E<sol>> (L<C<English>|English> モジュールでは、 | |
1659 | とも言う) のその時点の | |
2075 | C<$INPUT_RECORD_SEPARATOR> とも言う) のその時点の | |
2076 | 値に対応する行末文字を削除します。 | |
1660 | 2077 | 全ての引数から削除した文字数の合計を返します。 |
1661 | 2078 | 入力レコードから、改行を削除したいのだけれど、最後のレコードには改行が |
1662 | 2079 | 入っているのかわからないような場合に、使用できます。 |
1663 | 段落モード (C<$/ = | |
2080 | 段落モード (C<$/ = ''>) では、レコードの最後の改行をすべて取り除きます。 | |
1664 | 2081 | 吸い込みモード (C<$/ = undef>) や 固定長レコードモード |
1665 | (C<$/> が整数へのリファレンスや類似のものの場合; | |
2082 | (L<C<$E<sol>>|perlvar/$E<sol>> が整数へのリファレンスや類似のものの場合; | |
1666 | では、chomp | |
2083 | L<perlvar>を参照してください)では、L<C<chomp>|/chomp VARIABLE> は | |
1667 | ||
2084 | 何も取り除きません。 | |
2085 | VARIABLE が省略されると、L<C<$_>|perlvar/$_> を対象として chomp します。 | |
1668 | 2086 | 例: |
1669 | 2087 | |
1670 | 2088 | while (<>) { |
1671 | 2089 | chomp; # avoid \n on last field |
1672 | @array = split(/:/); | |
2090 | my @array = split(/:/); | |
1673 | 2091 | # ... |
1674 | 2092 | } |
1675 | 2093 | |
1676 | 2094 | =begin original |
1677 | 2095 | |
1678 | If VARIABLE is a hash, it chomps the hash's values, but not its keys | |
2096 | If VARIABLE is a hash, it chomps the hash's values, but not its keys, | |
2097 | resetting the L<C<each>|/each HASH> iterator in the process. | |
1679 | 2098 | |
1680 | 2099 | =end original |
1681 | 2100 | |
1682 | VARIABLE がハッシュなら、ハッシュのキーではなく値について chomp し | |
2101 | VARIABLE がハッシュなら、ハッシュのキーではなく値について chomp し、 | |
2102 | このプロセスの L<C<each>|/each HASH> 反復子をリセットします。 | |
1683 | 2103 | |
1684 | 2104 | =begin original |
1685 | 2105 | |
1686 | 2106 | You can actually chomp anything that's an lvalue, including an assignment: |
1687 | 2107 | |
1688 | 2108 | =end original |
1689 | 2109 | |
1690 | 2110 | 左辺値であれば、代入を含めて、任意のものを chomp できます: |
1691 | 2111 | |
1692 | chomp($cwd = `pwd`); | |
2112 | chomp(my $cwd = `pwd`); | |
1693 | chomp($answer = <STDIN>); | |
2113 | chomp(my $answer = <STDIN>); | |
1694 | 2114 | |
1695 | 2115 | =begin original |
1696 | 2116 | |
1697 | 2117 | If you chomp a list, each element is chomped, and the total number of |
1698 | 2118 | characters removed is returned. |
1699 | 2119 | |
1700 | 2120 | =end original |
1701 | 2121 | |
1702 | 2122 | リストを chomp すると、個々の要素が chomp され、 |
1703 | 2123 | 削除された文字数の合計が返されます。 |
1704 | 2124 | |
1705 | 2125 | =begin original |
1706 | 2126 | |
1707 | 2127 | Note that parentheses are necessary when you're chomping anything |
1708 | 2128 | that is not a simple variable. This is because C<chomp $cwd = `pwd`;> |
1709 | 2129 | is interpreted as C<(chomp $cwd) = `pwd`;>, rather than as |
1710 | 2130 | C<chomp( $cwd = `pwd` )> which you might expect. Similarly, |
1711 | 2131 | C<chomp $a, $b> is interpreted as C<chomp($a), $b> rather than |
1712 | 2132 | as C<chomp($a, $b)>. |
1713 | 2133 | |
1714 | 2134 | =end original |
1715 | 2135 | |
1716 | 2136 | 単純な変数以外のものを chomp する場合はかっこが必要であることに |
1717 | 2137 | 注意してください。 |
1718 | 2138 | これは、C<chomp $cwd = `pwd`;> は、予測している |
1719 | 2139 | C<chomp( $cwd = `pwd` )> ではなく、C<(chomp $cwd) = `pwd`;> と |
1720 | 2140 | 解釈されるからです。 |
1721 | 2141 | 同様に、C<chomp $a, $b> は C<chomp($a, $b)> ではなく C<chomp($a), $b> |
1722 | 2142 | と解釈されます。 |
1723 | 2143 | |
1724 | 2144 | =item chop VARIABLE |
1725 | 2145 | X<chop> |
1726 | 2146 | |
1727 | 2147 | =item chop( LIST ) |
1728 | 2148 | |
1729 | 2149 | =item chop |
1730 | 2150 | |
2151 | =for Pod::Functions remove the last character from a string | |
2152 | ||
1731 | 2153 | =begin original |
1732 | 2154 | |
1733 | 2155 | Chops off the last character of a string and returns the character |
1734 | 2156 | chopped. It is much more efficient than C<s/.$//s> because it neither |
1735 | scans nor copies the string. If VARIABLE is omitted, chops | |
2157 | scans nor copies the string. If VARIABLE is omitted, chops | |
1736 | ||
2158 | L<C<$_>|perlvar/$_>. | |
2159 | If VARIABLE is a hash, it chops the hash's values, but not its keys, | |
2160 | resetting the L<C<each>|/each HASH> iterator in the process. | |
1737 | 2161 | |
1738 | 2162 | =end original |
1739 | 2163 | |
1740 | 2164 | 文字列の最後の文字を切り捨てて、その切り取った文字を返します。 |
1741 | 2165 | 文字列の検索もコピーも行ないませんので |
1742 | 2166 | C<s/.$//s> よりも、ずっと効率的です。 |
1743 | VARIABLE が省略されると、C<$_> を対象として chop します。 | |
2167 | VARIABLE が省略されると、L<C<$_>|perlvar/$_> を対象として chop します。 | |
1744 | VARIABLE がハッシュの場合、ハッシュの | |
2168 | VARIABLE がハッシュの場合、ハッシュのキーではなく値について chop し、 | |
1745 | ||
2169 | このプロセスの L<C<each>|/each HASH> 反復子をリセットします。 | |
1746 | 2170 | |
1747 | 2171 | =begin original |
1748 | 2172 | |
1749 | 2173 | You can actually chop anything that's an lvalue, including an assignment. |
1750 | 2174 | |
1751 | 2175 | =end original |
1752 | 2176 | |
1753 | 2177 | 実際のところ、代入を含む左辺値となりうるなんでも chop できます。 |
1754 | 2178 | |
1755 | 2179 | =begin original |
1756 | 2180 | |
1757 | 2181 | If you chop a list, each element is chopped. Only the value of the |
1758 | last C<chop> is returned. | |
2182 | last L<C<chop>|/chop VARIABLE> is returned. | |
1759 | 2183 | |
1760 | 2184 | =end original |
1761 | 2185 | |
1762 | 2186 | リストを chop すると、個々の要素が chop されます。 |
1763 | 最後の C<chop> の値だけが返されます。 | |
2187 | 最後の L<C<chop>|/chop VARIABLE> の値だけが返されます。 | |
1764 | 2188 | |
1765 | 2189 | =begin original |
1766 | 2190 | |
1767 | Note that C<chop> returns the last character. To | |
2191 | Note that L<C<chop>|/chop VARIABLE> returns the last character. To | |
1768 | character, use C<substr($string, 0, -1)>. | |
2192 | return all but the last character, use C<substr($string, 0, -1)>. | |
1769 | 2193 | |
1770 | 2194 | =end original |
1771 | 2195 | |
1772 | C<chop> は最後の文字を返すことに注意してください。 | |
2196 | L<C<chop>|/chop VARIABLE> は最後の文字を返すことに注意してください。 | |
1773 | 2197 | 最後以外の全ての文字を返すためには、C<substr($string, 0, -1)> を |
1774 | 2198 | 使ってください。 |
1775 | 2199 | |
1776 | 2200 | =begin original |
1777 | 2201 | |
1778 | See also L</chomp>. | |
2202 | See also L<C<chomp>|/chomp VARIABLE>. | |
1779 | 2203 | |
1780 | 2204 | =end original |
1781 | 2205 | |
1782 | L</chomp> も参照してください。 | |
2206 | L<C<chomp>|/chomp VARIABLE> も参照してください。 | |
1783 | 2207 | |
1784 | 2208 | =item chown LIST |
1785 | 2209 | X<chown> X<owner> X<user> X<group> |
1786 | 2210 | |
2211 | =for Pod::Functions change the ownership on a list of files | |
2212 | ||
1787 | 2213 | =begin original |
1788 | 2214 | |
1789 | 2215 | Changes the owner (and group) of a list of files. The first two |
1790 | 2216 | elements of the list must be the I<numeric> uid and gid, in that |
1791 | 2217 | order. A value of -1 in either position is interpreted by most |
1792 | 2218 | systems to leave that value unchanged. Returns the number of files |
1793 | 2219 | successfully changed. |
1794 | 2220 | |
1795 | 2221 | =end original |
1796 | 2222 | |
1797 | 2223 | LIST に含まれるファイルの所有者 (とグループ) を変更します。 |
1798 | 2224 | LIST の最初の二つの要素には、I<数値表現> の uid と gid を |
1799 | 2225 | この順序で与えなければなりません。 |
1800 | 2226 | どちらかの値を -1 にすると、ほとんどのシステムではその値は |
1801 | 2227 | 変更しないと解釈します。 |
1802 | 変更に成功したファイルの数 | |
2228 | 変更に成功したファイルの数を返します。 | |
1803 | 2229 | |
1804 | $cnt = chown $uid, $gid, 'foo', 'bar'; | |
2230 | my $cnt = chown $uid, $gid, 'foo', 'bar'; | |
1805 | 2231 | chown $uid, $gid, @filenames; |
1806 | 2232 | |
1807 | 2233 | =begin original |
1808 | 2234 | |
1809 | On systems that support fchown(2), you may pass filehandles among the | |
2235 | On systems that support L<fchown(2)>, you may pass filehandles among the | |
1810 | files. On systems that don't support fchown(2), passing filehandles raises | |
2236 | files. On systems that don't support L<fchown(2)>, passing filehandles raises | |
1811 | 2237 | an exception. Filehandles must be passed as globs or glob references to be |
1812 | 2238 | recognized; barewords are considered filenames. |
1813 | 2239 | |
1814 | 2240 | =end original |
1815 | 2241 | |
1816 | fchown(2) に対応しているシステムでは、ファイルハンドルを引数として渡せます。 | |
2242 | L<fchown(2)> に対応しているシステムでは、ファイルハンドルを引数として渡せます。 | |
1817 | fchown(2) に対応していないシステムでは、ファイルハンドルを渡すと | |
2243 | L<fchown(2)> に対応していないシステムでは、ファイルハンドルを渡すと | |
1818 | 2244 | 例外が発生します。 |
1819 | 2245 | ファイルハンドルを認識させるためには、グロブまたはリファレンスとして |
1820 | 2246 | 渡されなければなりません; 裸の単語はファイル名として扱われます。 |
1821 | 2247 | |
1822 | 2248 | =begin original |
1823 | 2249 | |
1824 | 2250 | Here's an example that looks up nonnumeric uids in the passwd file: |
1825 | 2251 | |
1826 | 2252 | =end original |
1827 | 2253 | |
1828 | 2254 | passwd ファイルから数値表現でない uid を検索する例を |
1829 | 2255 | 示します: |
1830 | 2256 | |
1831 | 2257 | print "User: "; |
1832 | chomp($user = <STDIN>); | |
2258 | chomp(my $user = <STDIN>); | |
1833 | 2259 | print "Files: "; |
1834 | chomp($pattern = <STDIN>); | |
2260 | chomp(my $pattern = <STDIN>); | |
1835 | 2261 | |
1836 | ($login,$pass,$uid,$gid) = getpwnam($user) | |
2262 | my ($login,$pass,$uid,$gid) = getpwnam($user) | |
1837 | 2263 | or die "$user not in passwd file"; |
1838 | 2264 | |
1839 | @ary = glob($pattern); # expand filenames | |
2265 | my @ary = glob($pattern); # expand filenames | |
1840 | 2266 | chown $uid, $gid, @ary; |
1841 | 2267 | |
1842 | 2268 | =begin original |
1843 | 2269 | |
1844 | 2270 | On most systems, you are not allowed to change the ownership of the |
1845 | 2271 | file unless you're the superuser, although you should be able to change |
1846 | 2272 | the group to any of your secondary groups. On insecure systems, these |
1847 | 2273 | restrictions may be relaxed, but this is not a portable assumption. |
1848 | 2274 | On POSIX systems, you can detect this condition this way: |
1849 | 2275 | |
1850 | 2276 | =end original |
1851 | 2277 | |
1852 | 2278 | ほとんどのシステムでは、スーパーユーザーだけがファイルの所有者を |
1853 | 2279 | 変更できますが、グループは実行者の副グループに変更できるべきです。 |
1854 | 安全でないシステムでは、この制限はゆるめられています | |
2280 | 安全でないシステムでは、この制限はゆるめられています; しかしこれは | |
1855 | ||
2281 | 移植性のある仮定ではありません。 | |
1856 | 2282 | POSIX システムでは、以下のようにしてこの条件を検出できます: |
1857 | 2283 | |
1858 | 2284 | use POSIX qw(sysconf _PC_CHOWN_RESTRICTED); |
1859 | $can_chown_giveaway = | |
2285 | my $can_chown_giveaway = ! sysconf(_PC_CHOWN_RESTRICTED); | |
1860 | 2286 | |
2287 | =begin original | |
2288 | ||
2289 | Portability issues: L<perlport/chown>. | |
2290 | ||
2291 | =end original | |
2292 | ||
2293 | 移植性の問題: L<perlport/chown>。 | |
2294 | ||
1861 | 2295 | =item chr NUMBER |
1862 | 2296 | X<chr> X<character> X<ASCII> X<Unicode> |
1863 | 2297 | |
1864 | 2298 | =item chr |
1865 | 2299 | |
2300 | =for Pod::Functions get character this number represents | |
2301 | ||
1866 | 2302 | =begin original |
1867 | 2303 | |
1868 | 2304 | Returns the character represented by that NUMBER in the character set. |
1869 | 2305 | For example, C<chr(65)> is C<"A"> in either ASCII or Unicode, and |
1870 | chr(0x263a) is a Unicode smiley face. | |
2306 | chr(0x263a) is a Unicode smiley face. | |
1871 | 2307 | |
1872 | 2308 | =end original |
1873 | 2309 | |
1874 | 2310 | 特定の文字セットでの NUMBER で表わされる文字を返します。 |
1875 | たとえば、C<chr(65)> は ASCII と Unicode の両方で C<"A"> となります | |
2311 | たとえば、C<chr(65)> は ASCII と Unicode の両方で C<"A"> となります; | |
1876 | chr(0x263a) は Unicode のスマイリーフェイスです。 | |
2312 | chr(0x263a) は Unicode のスマイリーフェイスです。 | |
1877 | 2313 | |
1878 | 2314 | =begin original |
1879 | 2315 | |
1880 | 2316 | Negative values give the Unicode replacement character (chr(0xfffd)), |
1881 | 2317 | except under the L<bytes> pragma, where the low eight bits of the value |
1882 | 2318 | (truncated to an integer) are used. |
1883 | 2319 | |
1884 | 2320 | =end original |
1885 | 2321 | |
1886 | 2322 | 負の数は Unicode の置換文字 (chr(0xfffd)) を与えますが、 |
1887 | 2323 | L<bytes> プラグマの影響下では、(integer に切り詰められた)値の下位 8 ビットが |
1888 | 2324 | 使われます。 |
1889 | 2325 | |
1890 | 2326 | =begin original |
1891 | 2327 | |
1892 | If NUMBER is omitted, uses C<$_>. | |
2328 | If NUMBER is omitted, uses L<C<$_>|perlvar/$_>. | |
1893 | 2329 | |
1894 | 2330 | =end original |
1895 | 2331 | |
1896 | NUMBER が省略された場合、C<$_> を使います。 | |
2332 | NUMBER が省略された場合、L<C<$_>|perlvar/$_> を使います。 | |
1897 | 2333 | |
1898 | 2334 | =begin original |
1899 | 2335 | |
1900 | For the reverse, use L</ord>. | |
2336 | For the reverse, use L<C<ord>|/ord EXPR>. | |
1901 | 2337 | |
1902 | 2338 | =end original |
1903 | 2339 | |
1904 | 逆を行うためには、L</ord> を参照してください。 | |
2340 | 逆を行うためには、L<C<ord>|/ord EXPR> を参照してください。 | |
1905 | 2341 | |
1906 | 2342 | =begin original |
1907 | 2343 | |
1908 | 2344 | Note that characters from 128 to 255 (inclusive) are by default |
1909 | 2345 | internally not encoded as UTF-8 for backward compatibility reasons. |
1910 | 2346 | |
1911 | 2347 | =end original |
1912 | 2348 | |
1913 | 2349 | 128 から 255 までの文字は過去との互換性のために |
1914 | 2350 | デフォルトでは UTF-8 Unicode にエンコードされません。 |
1915 | 2351 | |
1916 | 2352 | =begin original |
1917 | 2353 | |
1918 | 2354 | See L<perlunicode> for more about Unicode. |
1919 | 2355 | |
1920 | 2356 | =end original |
1921 | 2357 | |
1922 | Unicode について | |
2358 | Unicode については L<perlunicode> を参照してください。 | |
1923 | 参照してください。 | |
1924 | 2359 | |
1925 | 2360 | =item chroot FILENAME |
1926 | 2361 | X<chroot> X<root> |
1927 | 2362 | |
1928 | 2363 | =item chroot |
1929 | 2364 | |
2365 | =for Pod::Functions make directory new root for path lookups | |
2366 | ||
1930 | 2367 | =begin original |
1931 | 2368 | |
1932 | 2369 | This function works like the system call by the same name: it makes the |
1933 | 2370 | named directory the new root directory for all further pathnames that |
1934 | 2371 | begin with a C</> by your process and all its children. (It doesn't |
1935 | 2372 | change your current working directory, which is unaffected.) For security |
1936 | 2373 | reasons, this call is restricted to the superuser. If FILENAME is |
1937 | omitted, does a C<chroot> to C<$_>. | |
2374 | omitted, does a L<C<chroot>|/chroot FILENAME> to L<C<$_>|perlvar/$_>. | |
1938 | 2375 | |
1939 | 2376 | =end original |
1940 | 2377 | |
1941 | 同じ名前のシステムコールと同じことをします | |
2378 | 同じ名前のシステムコールと同じことをします: 現在のプロセス及び子プロセスに | |
1942 | ||
2379 | 対して、C</>で始まるパス名に関して指定されたディレクトリを新しい | |
1943 | ||
2380 | ルートディレクトリとして扱います。 | |
1944 | (これはカレントディレクトリを変更しません | |
2381 | (これはカレントディレクトリを変更しません; カレントディレクトリは | |
2382 | そのままです。) | |
1945 | 2383 | セキュリティ上の理由により、この呼び出しはスーパーユーザーしか行えません。 |
1946 | FILENAME を省略すると、C<$_> | |
2384 | FILENAME を省略すると、L<C<$_>|perlvar/$_> へ | |
2385 | L<C<chroot>|/chroot FILENAME> します。 | |
1947 | 2386 | |
2387 | =begin original | |
2388 | ||
2389 | B<NOTE:> It is good security practice to do C<chdir("/")> | |
2390 | (L<C<chdir>|/chdir EXPR> to the root directory) immediately after a | |
2391 | L<C<chroot>|/chroot FILENAME>. | |
2392 | ||
2393 | =end original | |
2394 | ||
2395 | B<注意:> L<C<chroot>|/chroot FILENAME> の直後に (ルートディレクトリに | |
2396 | L<C<chdir>|/chdir EXPR> する) | |
2397 | C<chdir("/")> するのはセキュリティ上の良い習慣です。 | |
2398 | ||
2399 | =begin original | |
2400 | ||
2401 | Portability issues: L<perlport/chroot>. | |
2402 | ||
2403 | =end original | |
2404 | ||
2405 | 移植性の問題: L<perlport/chroot>。 | |
2406 | ||
1948 | 2407 | =item close FILEHANDLE |
1949 | 2408 | X<close> |
1950 | 2409 | |
1951 | 2410 | =item close |
1952 | 2411 | |
2412 | =for Pod::Functions close file (or pipe or socket) handle | |
2413 | ||
1953 | 2414 | =begin original |
1954 | 2415 | |
1955 | 2416 | Closes the file or pipe associated with the filehandle, flushes the IO |
1956 | 2417 | buffers, and closes the system file descriptor. Returns true if those |
1957 | 2418 | operations succeed and if no error was reported by any PerlIO |
1958 | 2419 | layer. Closes the currently selected filehandle if the argument is |
1959 | 2420 | omitted. |
1960 | 2421 | |
1961 | 2422 | =end original |
1962 | 2423 | |
1963 | 2424 | FILEHANDLE に対応したファイルまたはパイプをクローズして、 |
1964 | 2425 | IO バッファをフラッシュし、システムファイル記述子をクローズします。 |
1965 | 2426 | 操作が成功し、PerlIO 層からエラーが報告されなかった場合に真を返します。 |
1966 | 2427 | 引数が省略された場合、現在選択されているファイルハンドルをクローズします。 |
1967 | 2428 | |
1968 | 2429 | =begin original |
1969 | 2430 | |
1970 | 2431 | You don't have to close FILEHANDLE if you are immediately going to do |
1971 | another C<open> on it, becaus | |
2432 | another L<C<open>|/open FILEHANDLE,EXPR> on it, because | |
1972 | C<open> | |
2433 | L<C<open>|/open FILEHANDLE,EXPR> closes it for you. (See | |
1973 | ||
2434 | L<C<open>|/open FILEHANDLE,EXPR>.) However, an explicit | |
2435 | L<C<close>|/close FILEHANDLE> on an input file resets the line counter | |
2436 | (L<C<$.>|perlvar/$.>), while the implicit close done by | |
2437 | L<C<open>|/open FILEHANDLE,EXPR> does not. | |
1974 | 2438 | |
1975 | 2439 | =end original |
1976 | 2440 | |
1977 | クローズしてすぐにまた、同じファイルハンドルに | |
2441 | クローズしてすぐにまた、同じファイルハンドルに対してオープンを行なう | |
1978 | ||
2442 | 場合には、L<C<open>|/open FILEHANDLE,EXPR> が自動的に | |
1979 | ||
2443 | L<C<close>|/close FILEHANDLE> を行ないますので、 | |
1980 | ||
2444 | close FILEHANDLE する必要はありません。 | |
2445 | (L<C<open>|/open FILEHANDLE,EXPR> を参照してください。) | |
1981 | 2446 | ただし、明示的にクローズを行なったときにのみ入力ファイルの |
1982 | 行番号 (C<$.>) のリセットが行なわれ、 | |
2447 | 行番号 (L<C<$.>|perlvar/$.>) のリセットが行なわれ、 | |
1983 | ||
2448 | L<C<open>|/open FILEHANDLE,EXPR> によって行なわれる | |
2449 | 暗黙の L<C<close>|/close FILEHANDLE> では行なわれません。 | |
1984 | 2450 | |
1985 | 2451 | =begin original |
1986 | 2452 | |
1987 | If the filehandle came from a piped open, C<close> | |
2453 | If the filehandle came from a piped open, L<C<close>|/close FILEHANDLE> | |
1988 | the other syscalls involved fails or if its | |
2454 | returns false if one of the other syscalls involved fails or if its | |
1989 | status. If the only problem was that the | |
2455 | program exits with non-zero status. If the only problem was that the | |
1990 | ||
2456 | program exited non-zero, L<C<$!>|perlvar/$!> will be set to C<0>. | |
1991 | on | |
2457 | Closing a pipe also waits for the process executing on the pipe to | |
1992 | ||
2458 | exit--in case you wish to look at the output of the pipe afterwards--and | |
1993 | ||
2459 | implicitly puts the exit status value of that command into | |
2460 | L<C<$?>|perlvar/$?> and | |
2461 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>. | |
1994 | 2462 | |
1995 | 2463 | =end original |
1996 | 2464 | |
1997 | ファイルハンドルがパイプつきオープンなら、 | |
2465 | ファイルハンドルがパイプつきオープンなら、L<C<close>|/close FILEHANDLE> は | |
1998 | ||
2466 | その他のシステムコールが失敗したりプログラムが非ゼロのステータスで終了した | |
1999 | ||
2467 | 場合にも偽を返します。 | |
2000 | ||
2468 | プログラムが非ゼロで終了しただけの場合は、L<C<$!>|perlvar/$!> が C<0> に | |
2001 | ||
2469 | セットされます。 | |
2002 | パイプ | |
2470 | 後でパイプの出力を見たい場合のために、パイプのクローズでは、パイプ上で | |
2003 | また自動的にコマンドのステータス値を | |
2471 | 実行されているプロセスの終了を待ち、また自動的にコマンドのステータス値を | |
2004 | C<$ | |
2472 | L<C<$?>|perlvar/$?> と | |
2473 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に設定します。 | |
2005 | 2474 | |
2006 | 2475 | =begin original |
2007 | 2476 | |
2008 | If there are multiple threads running, C<close> | |
2477 | If there are multiple threads running, L<C<close>|/close FILEHANDLE> on | |
2009 | piped open returns true without waiting for the | |
2478 | a filehandle from a piped open returns true without waiting for the | |
2010 | if the filehandle is still open in another | |
2479 | child process to terminate, if the filehandle is still open in another | |
2480 | thread. | |
2011 | 2481 | |
2012 | 2482 | =end original |
2013 | 2483 | |
2014 | 2484 | 複数のスレッドがある場合、パイプで開かれたファイルハンドルに対する |
2015 | C<close> は、そのファイルハンドルが他のスレッドで | |
2485 | L<C<close>|/close FILEHANDLE> は、そのファイルハンドルが他のスレッドで | |
2016 | 子プロセスの終了を待たずに真を返します。 | |
2486 | まだ開かれている場合、子プロセスの終了を待たずに真を返します。 | |
2017 | 2487 | |
2018 | 2488 | =begin original |
2019 | 2489 | |
2020 | 2490 | Closing the read end of a pipe before the process writing to it at the |
2021 | 2491 | other end is done writing results in the writer receiving a SIGPIPE. If |
2022 | 2492 | the other end can't handle that, be sure to read all the data before |
2023 | 2493 | closing the pipe. |
2024 | 2494 | |
2025 | 2495 | =end original |
2026 | 2496 | |
2027 | 2497 | 書き込み側が閉じる前に途中でパイプの読み込み側が閉じた場合、 |
2028 | 2498 | 書き込み側に SIGPIPE が配送されます。 |
2029 | 2499 | 書き込み側がこれを扱えない場合、パイプを閉じる前に |
2030 | 2500 | 確実に全てのデータが読み込まれるようにする必要があります。 |
2031 | 2501 | |
2032 | 2502 | =begin original |
2033 | 2503 | |
2034 | 2504 | Example: |
2035 | 2505 | |
2036 | 2506 | =end original |
2037 | 2507 | |
2038 | 2508 | 例: |
2039 | 2509 | |
2040 | 2510 | open(OUTPUT, '|sort >foo') # pipe to sort |
2041 | 2511 | or die "Can't start sort: $!"; |
2042 | 2512 | #... # print stuff to output |
2043 | 2513 | close OUTPUT # wait for sort to finish |
2044 | 2514 | or warn $! ? "Error closing sort pipe: $!" |
2045 | 2515 | : "Exit status $? from sort"; |
2046 | 2516 | open(INPUT, 'foo') # get sort's results |
2047 | 2517 | or die "Can't open 'foo' for input: $!"; |
2048 | 2518 | |
2049 | 2519 | =begin original |
2050 | 2520 | |
2051 | 2521 | FILEHANDLE may be an expression whose value can be used as an indirect |
2052 | 2522 | filehandle, usually the real filehandle name or an autovivified handle. |
2053 | 2523 | |
2054 | 2524 | =end original |
2055 | 2525 | |
2056 | FILEHANDLE は式でもかまいません | |
2526 | FILEHANDLE は式でもかまいません; この場合、値は間接ファイルハンドルと | |
2057 | 2527 | して扱われ、普通は実際のファイルハンドル名か自動有効化されたハンドルです。 |
2058 | 2528 | |
2059 | 2529 | =item closedir DIRHANDLE |
2060 | 2530 | X<closedir> |
2061 | 2531 | |
2532 | =for Pod::Functions close directory handle | |
2533 | ||
2062 | 2534 | =begin original |
2063 | 2535 | |
2064 | Closes a directory opened by C<opendir> | |
2536 | Closes a directory opened by L<C<opendir>|/opendir DIRHANDLE,EXPR> and | |
2065 | system call. | |
2537 | returns the success of that system call. | |
2066 | 2538 | |
2067 | 2539 | =end original |
2068 | 2540 | |
2069 | C<opendir> でオープンしたディレクトリをクローズし、 | |
2541 | L<C<opendir>|/opendir DIRHANDLE,EXPR> でオープンしたディレクトリをクローズし、 | |
2070 | 2542 | システムコールの返り値を返します。 |
2071 | 2543 | |
2072 | 2544 | =item connect SOCKET,NAME |
2073 | 2545 | X<connect> |
2074 | 2546 | |
2547 | =for Pod::Functions connect to a remote socket | |
2548 | ||
2075 | 2549 | =begin original |
2076 | 2550 | |
2077 | Attempts to connect to a remote socket, just like connect(2). | |
2551 | Attempts to connect to a remote socket, just like L<connect(2)>. | |
2078 | 2552 | Returns true if it succeeded, false otherwise. NAME should be a |
2079 | 2553 | packed address of the appropriate type for the socket. See the examples in |
2080 | 2554 | L<perlipc/"Sockets: Client/Server Communication">. |
2081 | 2555 | |
2082 | 2556 | =end original |
2083 | 2557 | |
2084 | connect(2) システムコールと同様に、リモートソケットへの接続を試みます。 | |
2558 | L<connect(2)> システムコールと同様に、リモートソケットへの接続を試みます。 | |
2085 | 成功時には真を | |
2559 | 成功時には真を、さもなければ偽を返します。 | |
2086 | 2560 | NAME は、ソケットに対する、適切な型のパックされた |
2087 | 2561 | アドレスでなければなりません。 |
2088 | 2562 | L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。 |
2089 | 2563 | |
2090 | 2564 | =item continue BLOCK |
2091 | 2565 | X<continue> |
2092 | 2566 | |
2093 | 2567 | =item continue |
2094 | 2568 | |
2569 | =for Pod::Functions optional trailing block in a while or foreach | |
2570 | ||
2095 | 2571 | =begin original |
2096 | 2572 | |
2097 | C<continue> is actually a | |
2573 | When followed by a BLOCK, L<C<continue>|/continue BLOCK> is actually a | |
2098 | ||
2574 | flow control statement rather than a function. If there is a | |
2099 | C< | |
2575 | L<C<continue>|/continue BLOCK> BLOCK attached to a BLOCK (typically in a | |
2100 | ||
2576 | C<while> or C<foreach>), it is always executed just before the | |
2101 | it | |
2577 | conditional is about to be evaluated again, just like the third part of | |
2102 | ||
2578 | a C<for> loop in C. Thus it can be used to increment a loop variable, | |
2579 | even when the loop has been continued via the L<C<next>|/next LABEL> | |
2580 | statement (which is similar to the C L<C<continue>|/continue BLOCK> | |
2103 | 2581 | statement). |
2104 | 2582 | |
2105 | 2583 | =end original |
2106 | 2584 | |
2107 | C<continue> は実際には関数ではなく、 | |
2585 | BLOCK が引き続く場合、L<C<continue>|/continue BLOCK> は実際には関数ではなく、 | |
2108 | ||
2586 | 実行制御文です。 | |
2109 | ||
2587 | L<C<continue>|/continue BLOCK> BLOCK が BLOCK (典型的には C<while> または | |
2588 | C<foreach> の中)にあると、これは条件文が再評価される直前に常に実行されます; | |
2110 | 2589 | これは C における C<for> ループの 3 番目の部分と同様です。 |
2111 | 従って、これは C<next> 文 | |
2590 | 従って、これは L<C<next>|/next LABEL> 文 (これは C の | |
2112 | ||
2591 | L<C<continue>|/continue BLOCK> 文と似ています) を使って | |
2113 | ループ変数を増やしたいときに使えます。 | |
2592 | ループが繰り返されるときでもループ変数を増やしたいときに使えます。 | |
2114 | 2593 | |
2115 | 2594 | =begin original |
2116 | 2595 | |
2117 | C<last>, C<next> | |
2596 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, or | |
2118 | ||
2597 | L<C<redo>|/redo LABEL> may appear within a | |
2119 | t | |
2598 | L<C<continue>|/continue BLOCK> block; L<C<last>|/last LABEL> and | |
2120 | ||
2599 | L<C<redo>|/redo LABEL> behave as if they had been executed within the | |
2600 | main block. So will L<C<next>|/next LABEL>, but since it will execute a | |
2601 | L<C<continue>|/continue BLOCK> block, it may be more entertaining. | |
2121 | 2602 | |
2122 | 2603 | =end original |
2123 | 2604 | |
2124 | C<last>, C<next>, C<redo> | |
2605 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL> が | |
2125 | C< | |
2606 | L<C<continue>|/continue BLOCK> ブロック内に現れる可能性があります; | |
2126 | C< | |
2607 | L<C<last>|/last LABEL> と L<C<redo>|/redo LABEL> はメインブロックの中で | |
2127 | ||
2608 | 実行されたのと同じように振舞います。 | |
2609 | L<C<next>|/next LABEL> の場合は、L<C<continue>|/continue BLOCK> ブロックを | |
2610 | 実行することになるので、より面白いことになります。 | |
2128 | 2611 | |
2129 | 2612 | while (EXPR) { |
2130 | 2613 | ### redo always comes here |
2131 | 2614 | do_something; |
2132 | 2615 | } continue { |
2133 | 2616 | ### next always comes here |
2134 | 2617 | do_something_else; |
2135 | 2618 | # then back the top to re-check EXPR |
2136 | 2619 | } |
2137 | 2620 | ### last always comes here |
2138 | 2621 | |
2139 | 2622 | =begin original |
2140 | 2623 | |
2141 | Omitting the C<continue> section is equivalent to | |
2624 | Omitting the L<C<continue>|/continue BLOCK> section is equivalent to | |
2142 | empty one, logically enough, so C<next> goes | |
2625 | using an empty one, logically enough, so L<C<next>|/next LABEL> goes | |
2143 | to check the condition at the top of the loop. | |
2626 | directly back to check the condition at the top of the loop. | |
2144 | 2627 | |
2145 | 2628 | =end original |
2146 | 2629 | |
2147 | C<continue> 節を省略するのは、空の節を指定したのと同じで、 | |
2630 | L<C<continue>|/continue BLOCK> 節を省略するのは、空の節を指定したのと同じで、 | |
2148 | 論理的には十分なので、この場合、C<next> は直接ループ先頭の | |
2631 | 論理的には十分なので、この場合、L<C<next>|/next LABEL> は直接ループ先頭の | |
2149 | 2632 | 条件チェックに戻ります。 |
2150 | 2633 | |
2151 | 2634 | =begin original |
2152 | 2635 | |
2153 | ||
2636 | When there is no BLOCK, L<C<continue>|/continue BLOCK> is a function | |
2154 | falls through the current C<when> or C<default> block instead of | |
2637 | that falls through the current C<when> or C<default> block instead of | |
2155 | a dynamically enclosing C<foreach> or exiting a lexically | |
2638 | iterating a dynamically enclosing C<foreach> or exiting a lexically | |
2156 | ||
2639 | enclosing C<given>. In Perl 5.14 and earlier, this form of | |
2157 | in | |
2640 | L<C<continue>|/continue BLOCK> was only available when the | |
2641 | L<C<"switch"> feature|feature/The 'switch' feature> was enabled. See | |
2642 | L<feature> and L<perlsyn/"Switch Statements"> for more information. | |
2158 | 2643 | |
2159 | 2644 | =end original |
2160 | 2645 | |
2161 | C | |
2646 | BLOCK がなければ、L<C<continue>|/continue BLOCK> は動的に囲まれた C<foreach> や | |
2162 | 2647 | レキシカルに囲まれた C<given> で反復するのではなく、現在の C<when> または |
2163 | C<default> のブロックを通り抜けるための文 | |
2648 | C<default> のブロックを通り抜けるための文です。 | |
2164 | ||
2649 | Perl 5.14 以前では、この形式の L<C<continue>|/continue BLOCK> は | |
2650 | L<C<"switch"> 機能|feature/The 'switch' feature> が有効の場合にのみ | |
2651 | 利用可能です。 | |
2652 | さらなる情報については L<feature> と L<perlsyn/"Switch Statements"> を | |
2165 | 2653 | 参照してください。 |
2166 | 2654 | |
2167 | 2655 | =item cos EXPR |
2168 | 2656 | X<cos> X<cosine> X<acos> X<arccosine> |
2169 | 2657 | |
2170 | 2658 | =item cos |
2171 | 2659 | |
2660 | =for Pod::Functions cosine function | |
2661 | ||
2172 | 2662 | =begin original |
2173 | 2663 | |
2174 | 2664 | Returns the cosine of EXPR (expressed in radians). If EXPR is omitted, |
2175 | takes the cosine of C<$_>. | |
2665 | takes the cosine of L<C<$_>|perlvar/$_>. | |
2176 | 2666 | |
2177 | 2667 | =end original |
2178 | 2668 | |
2179 | 2669 | (ラジアンで示した) EXPR の余弦を返します。 |
2180 | EXPR が省略されたときには、C<$_> の余弦を取ります。 | |
2670 | EXPR が省略されたときには、L<C<$_>|perlvar/$_> の余弦を取ります。 | |
2181 | 2671 | |
2182 | 2672 | =begin original |
2183 | 2673 | |
2184 | For the inverse cosine operation, you may use the | |
2674 | For the inverse cosine operation, you may use the | |
2185 | function, or use this relation: | |
2675 | L<C<Math::Trig::acos>|Math::Trig> function, or use this relation: | |
2186 | 2676 | |
2187 | 2677 | =end original |
2188 | 2678 | |
2189 | 逆余弦を求めるためには、C<Math::Trig::acos | |
2679 | 逆余弦を求めるためには、L<C<Math::Trig::acos>|Math::Trig> 関数を使うか、 | |
2190 | 2680 | 以下の関係を使ってください。 |
2191 | 2681 | |
2192 | 2682 | sub acos { atan2( sqrt(1 - $_[0] * $_[0]), $_[0] ) } |
2193 | 2683 | |
2194 | 2684 | =item crypt PLAINTEXT,SALT |
2195 | 2685 | X<crypt> X<digest> X<hash> X<salt> X<plaintext> X<password> |
2196 | 2686 | X<decrypt> X<cryptography> X<passwd> X<encrypt> |
2197 | 2687 | |
2688 | =for Pod::Functions one-way passwd-style encryption | |
2689 | ||
2198 | 2690 | =begin original |
2199 | 2691 | |
2200 | Creates a digest string exactly like the crypt(3) function in the C | |
2692 | Creates a digest string exactly like the L<crypt(3)> function in the C | |
2201 | 2693 | library (assuming that you actually have a version there that has not |
2202 | 2694 | been extirpated as a potential munition). |
2203 | 2695 | |
2204 | 2696 | =end original |
2205 | 2697 | |
2206 | C ライブラリの crypt(3) 関数と全く同じように、ダイジェスト文字列を | |
2698 | C ライブラリの L<crypt(3)> 関数と全く同じように、ダイジェスト文字列を | |
2207 | 2699 | 作成します(一時的な必需品として、まだ絶滅していないバージョンを |
2208 | 2700 | 持っていると仮定しています)。 |
2209 | 2701 | |
2210 | 2702 | =begin original |
2211 | 2703 | |
2212 | crypt | |
2704 | L<C<crypt>|/crypt PLAINTEXT,SALT> is a one-way hash function. The | |
2705 | PLAINTEXT and SALT are turned | |
2213 | 2706 | into a short string, called a digest, which is returned. The same |
2214 | 2707 | PLAINTEXT and SALT will always return the same string, but there is no |
2215 | 2708 | (known) way to get the original PLAINTEXT from the hash. Small |
2216 | 2709 | changes in the PLAINTEXT or SALT will result in large changes in the |
2217 | 2710 | digest. |
2218 | 2711 | |
2219 | 2712 | =end original |
2220 | 2713 | |
2221 | crypt | |
2714 | L<C<crypt>|/crypt PLAINTEXT,SALT> は一方向ハッシュ関数です。 | |
2222 | 2715 | PLAINTEXT と SALT はダイジェストと呼ばれる短い文字列に変えられて、 |
2223 | 2716 | それが返されます。 |
2224 | 2717 | PLAINTEXT と SALT が同じ場合は常に同じ文字列を返しますが、ハッシュから |
2225 | 2718 | 元の PLAINTEXT を得る(既知の)方法はありません。 |
2226 | 2719 | PLAINTEXT や SALT を少し変更してもダイジェストは大きく変更されます。 |
2227 | 2720 | |
2228 | 2721 | =begin original |
2229 | 2722 | |
2230 | 2723 | There is no decrypt function. This function isn't all that useful for |
2231 | 2724 | cryptography (for that, look for F<Crypt> modules on your nearby CPAN |
2232 | 2725 | mirror) and the name "crypt" is a bit of a misnomer. Instead it is |
2233 | 2726 | primarily used to check if two pieces of text are the same without |
2234 | 2727 | having to transmit or store the text itself. An example is checking |
2235 | 2728 | if a correct password is given. The digest of the password is stored, |
2236 | 2729 | not the password itself. The user types in a password that is |
2237 | crypt | |
2730 | L<C<crypt>|/crypt PLAINTEXT,SALT>'d with the same salt as the stored | |
2238 | match, the password is correct. | |
2731 | digest. If the two digests match, the password is correct. | |
2239 | 2732 | |
2240 | 2733 | =end original |
2241 | 2734 | |
2242 | 2735 | 復号化関数はありません。 |
2243 | 2736 | この関数は暗号化のためにはまったく役に立ちません(このためには、 |
2244 | 2737 | お近くの CPAN ミラーで F<Crypt> モジュールを探してください)ので、 |
2245 | 2738 | "crypt" という名前は少し間違った名前です。 |
2246 | 2739 | その代わりに、一般的には二つのテキスト片が同じかどうかをテキストそのものを |
2247 | 2740 | 転送したり保管したりせずにチェックするために使います。 |
2248 | 2741 | 例としては、正しいパスワードが与えられたかどうかをチェックがあります。 |
2249 | 2742 | パスワード自身ではなく、パスワードのダイジェストが保管されます。 |
2250 | 2743 | ユーザーがパスワードを入力すると、保管されているダイジェストと同じ |
2251 | salt で crypt | |
2744 | salt で L<C<crypt>|/crypt PLAINTEXT,SALT> します。 | |
2252 | 2745 | 二つのダイジェストが同じなら、パスワードは正しいです。 |
2253 | 2746 | |
2254 | 2747 | =begin original |
2255 | 2748 | |
2256 | 2749 | When verifying an existing digest string you should use the digest as |
2257 | 2750 | the salt (like C<crypt($plain, $digest) eq $digest>). The SALT used |
2258 | 2751 | to create the digest is visible as part of the digest. This ensures |
2259 | crypt | |
2752 | L<C<crypt>|/crypt PLAINTEXT,SALT> will hash the new string with the same | |
2260 | This allows your code to work with the standar | |
2753 | salt as the digest. This allows your code to work with the standard | |
2261 | with more exotic implementations. | |
2754 | L<C<crypt>|/crypt PLAINTEXT,SALT> and with more exotic implementations. | |
2262 | nothing about the returned string itself nor | |
2755 | In other words, assume nothing about the returned string itself nor | |
2263 | of SALT may matter. | |
2756 | about how many bytes of SALT may matter. | |
2264 | 2757 | |
2265 | 2758 | =end original |
2266 | 2759 | |
2267 | 2760 | すでにあるダイジェスト文字列を検証するには、ダイジェストを |
2268 | 2761 | (C<crypt($plain, $digest) eq $digest> のようにして)salt として使います。 |
2269 | 2762 | ダイジェストを作るのに使われた SALT はダイジェストの一部として見えます。 |
2270 | これにより、crypt | |
2763 | これにより、L<C<crypt>|/crypt PLAINTEXT,SALT> は同じ salt で新しい文字列を | |
2271 | ハッシュ化できるようにします。 | |
2764 | ダイジェストとしてハッシュ化できるようにします。 | |
2272 | これによって標準的な C<crypt|/crypt> や、より風変わりな | |
2765 | これによって標準的な L<C<crypt>|/crypt PLAINTEXT,SALT> や、より風変わりな | |
2766 | 実装でも動作します。 | |
2273 | 2767 | 言い換えると、返される文字列や、SALT が何バイトあるかといったことに対して、 |
2274 | 2768 | どのような仮定もしてはいけません。 |
2275 | 2769 | |
2276 | 2770 | =begin original |
2277 | 2771 | |
2278 | 2772 | Traditionally the result is a string of 13 bytes: two first bytes of |
2279 | 2773 | the salt, followed by 11 bytes from the set C<[./0-9A-Za-z]>, and only |
2280 | the first eight bytes of PLAINTEXT mattered. But alternative | |
2774 | the first eight bytes of PLAINTEXT mattered. But alternative | |
2281 | 2775 | hashing schemes (like MD5), higher level security schemes (like C2), |
2282 | 2776 | and implementations on non-Unix platforms may produce different |
2283 | 2777 | strings. |
2284 | 2778 | |
2285 | 2779 | =end original |
2286 | 2780 | |
2287 | 2781 | 伝統的には結果は 13 バイトの文字列です: 最初の 2 バイトは salt、引き続いて |
2288 | 2782 | 集合 C<[./0-9A-Za-z]> からの 11 バイトで、PLAINTEXT の最初の |
2289 | 2783 | 8 バイトだけが意味があります。 |
2290 | 2784 | しかし、(MD5 のように) 異なったハッシュ手法、 |
2291 | 2785 | (C2 のような) 高レベルセキュリティ手法、非 Unix プラットフォームでの |
2292 | 2786 | 実装などでは異なった文字列が生成されることがあります。 |
2293 | 2787 | |
2294 | 2788 | =begin original |
2295 | 2789 | |
2296 | 2790 | When choosing a new salt create a random two character string whose |
2297 | 2791 | characters come from the set C<[./0-9A-Za-z]> (like C<join '', ('.', |
2298 | 2792 | '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]>). This set of |
2299 | 2793 | characters is just a recommendation; the characters allowed in |
2300 | 2794 | the salt depend solely on your system's crypt library, and Perl can't |
2301 | restrict what salts C<crypt | |
2795 | restrict what salts L<C<crypt>|/crypt PLAINTEXT,SALT> accepts. | |
2302 | 2796 | |
2303 | 2797 | =end original |
2304 | 2798 | |
2305 | 2799 | 新しい salt を選択する場合は、集合 C<[./0-9A-Za-z]> から |
2306 | (C<join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]> の | |
2800 | (C<join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]> の | |
2307 | ランダムに2 つの文字を選びます。 | |
2801 | ようにして)ランダムに2 つの文字を選びます。 | |
2308 | 2802 | この文字集合は単なる推薦です; salt として許される文字はシステムの暗号化 |
2309 | ライブラリだけに依存し、Perl は C<crypt | |
2803 | ライブラリだけに依存し、Perl は L<C<crypt>|/crypt PLAINTEXT,SALT> が | |
2310 | ついて制限しません。 | |
2804 | どのような salt を受け付けるかについて制限しません。 | |
2311 | 2805 | |
2312 | 2806 | =begin original |
2313 | 2807 | |
2314 | 2808 | Here's an example that makes sure that whoever runs this program knows |
2315 | 2809 | their password: |
2316 | 2810 | |
2317 | 2811 | =end original |
2318 | 2812 | |
2319 | 2813 | プログラムを実行する人が、 |
2320 | 2814 | 自分のパスワードを知っていることを確認する例です: |
2321 | 2815 | |
2322 | $pwd = (getpwuid($<))[1]; | |
2816 | my $pwd = (getpwuid($<))[1]; | |
2323 | 2817 | |
2324 | 2818 | system "stty -echo"; |
2325 | 2819 | print "Password: "; |
2326 | chomp($word = <STDIN>); | |
2820 | chomp(my $word = <STDIN>); | |
2327 | 2821 | print "\n"; |
2328 | 2822 | system "stty echo"; |
2329 | 2823 | |
2330 | 2824 | if (crypt($word, $pwd) ne $pwd) { |
2331 | 2825 | die "Sorry...\n"; |
2332 | 2826 | } else { |
2333 | 2827 | print "ok\n"; |
2334 | 2828 | } |
2335 | 2829 | |
2336 | 2830 | =begin original |
2337 | 2831 | |
2338 | 2832 | Of course, typing in your own password to whoever asks you |
2339 | 2833 | for it is unwise. |
2340 | 2834 | |
2341 | 2835 | =end original |
2342 | 2836 | |
2343 | 2837 | もちろん、自分自身のパスワードを誰にでも入力するのは賢明ではありません。 |
2344 | 2838 | |
2345 | 2839 | =begin original |
2346 | 2840 | |
2347 | The L<crypt|/crypt> function is unsuitable for hashing | |
2841 | The L<C<crypt>|/crypt PLAINTEXT,SALT> function is unsuitable for hashing | |
2348 | of data, not least of all because you can't get the | |
2842 | large quantities of data, not least of all because you can't get the | |
2349 | back. Look at the L<Digest> module for more robust | |
2843 | information back. Look at the L<Digest> module for more robust | |
2844 | algorithms. | |
2350 | 2845 | |
2351 | 2846 | =end original |
2352 | 2847 | |
2353 | L<crypt|/crypt> 関数は大量のデータのハッシュ化には | |
2848 | L<C<crypt>|/crypt PLAINTEXT,SALT> 関数は大量のデータのハッシュ化には | |
2354 | これは情報を戻せないという理由だけではありません。 | |
2849 | 向いていません; これは情報を戻せないという理由だけではありません。 | |
2355 | 2850 | より頑強なアルゴリズムについては L<Digest> モジュールを参照してください。 |
2356 | 2851 | |
2357 | 2852 | =begin original |
2358 | 2853 | |
2359 | If using crypt | |
2854 | If using L<C<crypt>|/crypt PLAINTEXT,SALT> on a Unicode string (which | |
2360 | characters with codepoints above 255), Perl tries to | |
2855 | I<potentially> has characters with codepoints above 255), Perl tries to | |
2361 | of the situation by trying to downgrade (a copy of) | |
2856 | make sense of the situation by trying to downgrade (a copy of) the | |
2362 | ||
2857 | string back to an eight-bit byte string before calling | |
2363 | (on that copy). If that works, good. | |
2858 | L<C<crypt>|/crypt PLAINTEXT,SALT> (on that copy). If that works, good. | |
2364 | C< | |
2859 | If not, L<C<crypt>|/crypt PLAINTEXT,SALT> dies with | |
2860 | L<C<Wide character in crypt>|perldiag/Wide character in %s>. | |
2365 | 2861 | |
2366 | 2862 | =end original |
2367 | 2863 | |
2368 | 2864 | Unicode 文字列(I<潜在的には> 255 を越えるコードポイントを持つ文字を |
2369 | 含みます)に crypt | |
2865 | 含みます)に L<C<crypt>|/crypt PLAINTEXT,SALT> を使った場合、Perl は | |
2866 | L<C<crypt>|/crypt PLAINTEXT,SALT> を呼び出す前に与えられた | |
2370 | 2867 | 文字列を8 ビットバイト文字列にダウングレードする(文字列のコピーを作る) |
2371 | 2868 | ことで状況のつじつまを合わせようとします。 |
2372 | うまく動けば、それでよし。 | |
2869 | うまく動けば、それでよし。 | |
2373 | C< | |
2870 | 動かなければ、L<C<crypt>|/crypt PLAINTEXT,SALT> は | |
2871 | L<C<Wide character in crypt>|perldiag/Wide character in %s> という | |
2872 | メッセージと共に die します。 | |
2374 | 2873 | |
2874 | =begin original | |
2875 | ||
2876 | Portability issues: L<perlport/crypt>. | |
2877 | ||
2878 | =end original | |
2879 | ||
2880 | 移植性の問題: L<perlport/crypt>。 | |
2881 | ||
2375 | 2882 | =item dbmclose HASH |
2376 | 2883 | X<dbmclose> |
2377 | 2884 | |
2885 | =for Pod::Functions breaks binding on a tied dbm file | |
2886 | ||
2378 | 2887 | =begin original |
2379 | 2888 | |
2380 | [This function has been largely superseded by the | |
2889 | [This function has been largely superseded by the | |
2890 | L<C<untie>|/untie VARIABLE> function.] | |
2381 | 2891 | |
2382 | 2892 | =end original |
2383 | 2893 | |
2384 | [この関数は、C<untie> 関数に大きくとって代わられました。] | |
2894 | [この関数は、L<C<untie>|/untie VARIABLE> 関数に大きくとって代わられました。] | |
2385 | 2895 | |
2386 | 2896 | =begin original |
2387 | 2897 | |
2388 | 2898 | Breaks the binding between a DBM file and a hash. |
2389 | 2899 | |
2390 | 2900 | =end original |
2391 | 2901 | |
2392 | 2902 | DBM ファイルとハッシュの連結をはずします。 |
2393 | 2903 | |
2904 | =begin original | |
2905 | ||
2906 | Portability issues: L<perlport/dbmclose>. | |
2907 | ||
2908 | =end original | |
2909 | ||
2910 | 移植性の問題: L<perlport/dbmclose>。 | |
2911 | ||
2394 | 2912 | =item dbmopen HASH,DBNAME,MASK |
2395 | 2913 | X<dbmopen> X<dbm> X<ndbm> X<sdbm> X<gdbm> |
2396 | 2914 | |
2915 | =for Pod::Functions create binding on a tied dbm file | |
2916 | ||
2397 | 2917 | =begin original |
2398 | 2918 | |
2399 | [This function has been largely superseded by the | |
2919 | [This function has been largely superseded by the | |
2920 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function.] | |
2400 | 2921 | |
2401 | 2922 | =end original |
2402 | 2923 | |
2403 | [この関数は、C<tie> 関数に | |
2924 | [この関数は、L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数に | |
2925 | 大きくとって代わられました。] | |
2404 | 2926 | |
2405 | 2927 | =begin original |
2406 | 2928 | |
2407 | This binds a dbm(3), ndbm(3), sdbm(3), gdbm(3), or Berkeley | |
2929 | This binds a L<dbm(3)>, L<ndbm(3)>, L<sdbm(3)>, L<gdbm(3)>, or Berkeley | |
2408 | hash. HASH is the name of the hash. (Unlike normal | |
2930 | DB file to a hash. HASH is the name of the hash. (Unlike normal | |
2409 | argument is I<not> a | |
2931 | L<C<open>|/open FILEHANDLE,EXPR>, the first argument is I<not> a | |
2410 | i | |
2932 | filehandle, even though it looks like one). DBNAME is the name of the | |
2411 | ||
2933 | database (without the F<.dir> or F<.pag> extension if any). If the | |
2412 | ||
2934 | database does not exist, it is created with protection specified by MASK | |
2413 | ||
2935 | (as modified by the L<C<umask>|/umask EXPR>). To prevent creation of | |
2936 | the database if it doesn't exist, you may specify a MODE of 0, and the | |
2937 | function will return a false value if it can't find an existing | |
2938 | database. If your system supports only the older DBM functions, you may | |
2939 | make only one L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> call in your | |
2414 | 2940 | program. In older versions of Perl, if your system had neither DBM nor |
2415 | ndbm, calling C<dbmopen> produced a fatal | |
2941 | ndbm, calling L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> produced a fatal | |
2416 | sdbm(3). | |
2942 | error; it now falls back to L<sdbm(3)>. | |
2417 | 2943 | |
2418 | 2944 | =end original |
2419 | 2945 | |
2420 | dbm(3), ndbm(3), sdbm(3), gdbm(3) ファイルまたは | |
2946 | L<dbm(3)>, L<ndbm(3)>, L<sdbm(3)>, L<gdbm(3)> ファイルまたは | |
2421 | ファイルを連想配列に結び付けます。 | |
2947 | Berkeley DB ファイルを連想配列に結び付けます。 | |
2422 | 2948 | HASH は、その連想配列の名前です。 |
2423 | (普通の C<open> とは違って、最初の引数は | |
2949 | (普通の L<C<open>|/open FILEHANDLE,EXPR> とは違って、最初の引数は | |
2424 | I<ではありません> | |
2950 | ファイルハンドル I<ではありません>; まあ、似たようなものですが)。 | |
2425 | DBNAME は、データベースの名前です (拡張子の .dir や | |
2951 | DBNAME は、データベースの名前です (拡張子の .dir や .pag はもしあっても | |
2426 | ||
2952 | つけません)。 | |
2427 | データベースが存在しなければ、MODE MASK (を C<umask> | |
2953 | データベースが存在しなければ、MODE MASK (を L<C<umask>|/umask EXPR> で | |
2428 | 指定されたモードで作られます。 | |
2954 | 修正したもの) で指定されたモードで作られます。 | |
2955 | 存在しないときにデータベースを作成しないようにするには、MODE に 0 を | |
2956 | 設定でき、データベースを見つけられなかった場合は関数は偽を返します。 | |
2429 | 2957 | 古い DBM 関数のみをサポートしているシステムでは、プログラム中で 1 度だけ |
2430 | dbmopen | |
2958 | L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を実行することができます。 | |
2431 | 2959 | 昔のバージョンの Perl では、DBM も ndbm も持っていないシステムでは、 |
2432 | dbmopen | |
2960 | L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を呼び出すと致命的エラーになります; | |
2433 | 現在では sdbm(3) にフォールバックします。 | |
2961 | 現在では L<sdbm(3)> にフォールバックします。 | |
2434 | 2962 | |
2435 | 2963 | =begin original |
2436 | 2964 | |
2437 | 2965 | If you don't have write access to the DBM file, you can only read hash |
2438 | 2966 | variables, not set them. If you want to test whether you can write, |
2439 | either use file tests or try setting a dummy hash entry inside an | |
2967 | either use file tests or try setting a dummy hash entry inside an | |
2440 | to trap the error. | |
2968 | L<C<eval>|/eval EXPR> to trap the error. | |
2441 | 2969 | |
2442 | 2970 | =end original |
2443 | 2971 | |
2444 | 2972 | DBM ファイルに対して、書き込み権が無いときには、ハッシュ |
2445 | 2973 | 配列を読みだすことだけができ、設定することはできません。 |
2446 | 2974 | 書けるか否かを調べたい場合には、ファイルテスト |
2447 | 演算子を使うか、エラーをトラップするための C<eval> の中で、 | |
2975 | 演算子を使うか、エラーをトラップするための L<C<eval>|/eval EXPR> の中で、 | |
2448 | 2976 | ダミーのハッシュエントリを設定してみることになります。 |
2449 | 2977 | |
2450 | 2978 | =begin original |
2451 | 2979 | |
2452 | Note that functions such as C<keys> | |
2980 | Note that functions such as L<C<keys>|/keys HASH> and | |
2453 | ||
2981 | L<C<values>|/values HASH> may return huge lists when used on large DBM | |
2454 | f | |
2982 | files. You may prefer to use the L<C<each>|/each HASH> function to | |
2983 | iterate over large DBM files. Example: | |
2455 | 2984 | |
2456 | 2985 | =end original |
2457 | 2986 | |
2458 | 大きな DBM ファイルを扱うときには、C<keys> | |
2987 | 大きな DBM ファイルを扱うときには、L<C<keys>|/keys HASH> や | |
2459 | 巨大なリストを返します。 | |
2988 | L<C<values>|/values HASH> のような関数は、巨大なリストを返します。 | |
2460 | 大きな DBM ファイルでは、C<each> 関数を使って繰り返しを | |
2989 | 大きな DBM ファイルでは、L<C<each>|/each HASH> 関数を使って繰り返しを | |
2461 | 良いかもしれません。 | |
2990 | 行なった方が良いかもしれません。 | |
2462 | 2991 | 例: |
2463 | 2992 | |
2464 | 2993 | # print out history file offsets |
2465 | 2994 | dbmopen(%HIST,'/usr/lib/news/history',0666); |
2466 | 2995 | while (($key,$val) = each %HIST) { |
2467 | 2996 | print $key, ' = ', unpack('L',$val), "\n"; |
2468 | 2997 | } |
2469 | 2998 | dbmclose(%HIST); |
2470 | 2999 | |
2471 | 3000 | =begin original |
2472 | 3001 | |
2473 | 3002 | See also L<AnyDBM_File> for a more general description of the pros and |
2474 | 3003 | cons of the various dbm approaches, as well as L<DB_File> for a particularly |
2475 | 3004 | rich implementation. |
2476 | 3005 | |
2477 | 3006 | =end original |
2478 | 3007 | |
2479 | 3008 | 様々な dbm 手法に対する利点欠点に関するより一般的な記述および |
2480 | 3009 | 特にリッチな実装である L<DB_File> に関しては |
2481 | 3010 | L<AnyDBM_File> も参照してください。 |
2482 | 3011 | |
2483 | 3012 | =begin original |
2484 | 3013 | |
2485 | 3014 | You can control which DBM library you use by loading that library |
2486 | before you call dbmopen | |
3015 | before you call L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>: | |
2487 | 3016 | |
2488 | 3017 | =end original |
2489 | 3018 | |
2490 | dbmopen | |
3019 | L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を呼び出す前にライブラリを | |
2491 | どの DBM ライブラリを使うかを制御できます: | |
3020 | 読み込むことで、どの DBM ライブラリを使うかを制御できます: | |
2492 | 3021 | |
2493 | 3022 | use DB_File; |
2494 | 3023 | dbmopen(%NS_Hist, "$ENV{HOME}/.netscape/history.db") |
2495 | 3024 | or die "Can't open netscape history file: $!"; |
2496 | 3025 | |
2497 | =item default BLOCK | |
2498 | ||
2499 | 3026 | =begin original |
2500 | 3027 | |
2501 | ||
3028 | Portability issues: L<perlport/dbmopen>. | |
2502 | that's always true. Only available after Perl 5.10, and only if the | |
2503 | C<switch> feature has been requested. See L</when>. | |
2504 | 3029 | |
2505 | 3030 | =end original |
2506 | 3031 | |
2507 | ||
3032 | 移植性の問題: L<perlport/dbmopen>。 | |
2508 | ように動作します。 | |
2509 | Perl 5.10 以降でのみ、かつ C<switch> 機能が有効の場合にのみ利用可能です。 | |
2510 | L</when> を参照してください。 | |
2511 | 3033 | |
2512 | 3034 | =item defined EXPR |
2513 | 3035 | X<defined> X<undef> X<undefined> |
2514 | 3036 | |
2515 | 3037 | =item defined |
2516 | 3038 | |
3039 | =for Pod::Functions test whether a value, variable, or function is defined | |
3040 | ||
2517 | 3041 | =begin original |
2518 | 3042 | |
2519 | Returns a Boolean value telling whether EXPR has a value other than | |
3043 | Returns a Boolean value telling whether EXPR has a value other than the | |
2520 | ||
3044 | undefined value L<C<undef>|/undef EXPR>. If EXPR is not present, | |
2521 | checked. | |
3045 | L<C<$_>|perlvar/$_> is checked. | |
2522 | 3046 | |
2523 | 3047 | =end original |
2524 | 3048 | |
2525 | 左辺値 EXPR が未定義値 C<undef> 以外の値を持つか否かを示す、 | |
3049 | 左辺値 EXPR が未定義値 L<C<undef>|/undef EXPR> 以外の値を持つか否かを示す、 | |
2526 | 返します。 | |
3050 | ブール値を返します。 | |
2527 | EXPR がない場合は、C<$_> がチェックされます。 | |
3051 | EXPR がない場合は、L<C<$_>|perlvar/$_> がチェックされます。 | |
2528 | 3052 | |
2529 | 3053 | =begin original |
2530 | 3054 | |
2531 | Many operations return C<undef> to indicate failure, end | |
3055 | Many operations return L<C<undef>|/undef EXPR> to indicate failure, end | |
2532 | system error, uninitialized variable, and other exceptional | |
3056 | of file, system error, uninitialized variable, and other exceptional | |
2533 | conditions. This function allows you to distinguish | |
3057 | conditions. This function allows you to distinguish | |
2534 | other values. (A simple Boolean test will | |
3058 | L<C<undef>|/undef EXPR> from other values. (A simple Boolean test will | |
2535 | C<undef>, zero, the empty string, | |
3059 | not distinguish among L<C<undef>|/undef EXPR>, zero, the empty string, | |
2536 | ||
3060 | and C<"0">, which are all equally false.) Note that since | |
2537 | d | |
3061 | L<C<undef>|/undef EXPR> is a valid scalar, its presence doesn't | |
2538 | ||
3062 | I<necessarily> indicate an exceptional condition: L<C<pop>|/pop ARRAY> | |
2539 | ||
3063 | returns L<C<undef>|/undef EXPR> when its argument is an empty array, | |
3064 | I<or> when the element to return happens to be L<C<undef>|/undef EXPR>. | |
2540 | 3065 | |
2541 | 3066 | =end original |
2542 | 3067 | |
2543 | 3068 | 多くの演算子が、EOF や未初期化変数、システムエラーといった、 |
2544 | 例外的な条件で C<undef> を返すようになっています。 | |
3069 | 例外的な条件で L<C<undef>|/undef EXPR> を返すようになっています。 | |
2545 | この関数は、他の値と C<undef> とを区別するために使えます。 | |
3070 | この関数は、他の値と L<C<undef>|/undef EXPR> とを区別するために使えます。 | |
2546 | (単純な真偽値テストでは、C<undef>、0、C<"0"> のいずれも偽を | |
3071 | (単純な真偽値テストでは、L<C<undef>|/undef EXPR>、0、C<"0"> のいずれも偽を | |
2547 | 区別することができません。) | |
3072 | 返すので、区別することができません。) | |
2548 | C<undef> は有効なスカラ値なので、その存在が I<必ずしも> | |
3073 | L<C<undef>|/undef EXPR> は有効なスカラ値なので、その存在が I<必ずしも> | |
2549 | 3074 | 例外的な状況を表すとは限らないということに注意してください: |
2550 | C<pop> は引数が空の配列だったときに C<undef> を | |
3075 | L<C<pop>|/pop ARRAY> は引数が空の配列だったときに L<C<undef>|/undef EXPR> を | |
2551 | I<あるいは> 返すべき要素がたまたま | |
3076 | 返しますが、I<あるいは> 返すべき要素がたまたま | |
3077 | L<C<undef>|/undef EXPR> だったのかもしれません。 | |
2552 | 3078 | |
2553 | 3079 | =begin original |
2554 | 3080 | |
2555 | You may also use C<defined(&func)> to check whether subroutine C< | |
3081 | You may also use C<defined(&func)> to check whether subroutine C<func> | |
2556 | 3082 | has ever been defined. The return value is unaffected by any forward |
2557 | declarations of C< | |
3083 | declarations of C<func>. A subroutine that is not defined | |
2558 | 3084 | may still be callable: its package may have an C<AUTOLOAD> method that |
2559 | 3085 | makes it spring into existence the first time that it is called; see |
2560 | 3086 | L<perlsub>. |
2561 | 3087 | |
2562 | 3088 | =end original |
2563 | 3089 | |
2564 | C<defined(&func)> とすることでサブルーチン C< | |
3090 | C<defined(&func)> とすることでサブルーチン C<func> の存在を、 | |
2565 | 3091 | 確かめることもできます。 |
2566 | 返り値は C< | |
3092 | 返り値は C<func> の前方定義には影響されません。 | |
2567 | 3093 | 定義されていないサブルーチンも呼び出し可能です: |
2568 | 3094 | 最初に呼び出されたときに存在するようにするための |
2569 | 3095 | C<AUTOLOAD> メソッドを持ったパッケージかもしれません; |
2570 | L<perlsub> を参照して | |
3096 | L<perlsub> を参照してください。 | |
2571 | 3097 | |
2572 | 3098 | =begin original |
2573 | 3099 | |
2574 | Use of C<defined> on aggregates (hashes and arrays) is | |
3100 | Use of L<C<defined>|/defined EXPR> on aggregates (hashes and arrays) is | |
3101 | deprecated. It | |
2575 | 3102 | used to report whether memory for that aggregate had ever been |
2576 | 3103 | allocated. This behavior may disappear in future versions of Perl. |
2577 | 3104 | You should instead use a simple test for size: |
2578 | 3105 | |
2579 | 3106 | =end original |
2580 | 3107 | |
2581 | 集合(ハッシュや配列)への C<defined> の使用は非推奨です。 | |
3108 | 集合(ハッシュや配列)への L<C<defined>|/defined EXPR> の使用は非推奨です。 | |
2582 | 3109 | これはその集合にメモリが割り当てられたかを報告するのに |
2583 | 3110 | 用いられていました。 |
2584 | 3111 | この振る舞いは将来のバージョンの Perl では消滅するかもしれません。 |
2585 | 3112 | 代わりにサイズに対する簡単なテストを使うべきです。 |
2586 | 3113 | |
2587 | 3114 | if (@an_array) { print "has array elements\n" } |
2588 | 3115 | if (%a_hash) { print "has hash members\n" } |
2589 | 3116 | |
2590 | 3117 | =begin original |
2591 | 3118 | |
2592 | 3119 | When used on a hash element, it tells you whether the value is defined, |
2593 | not whether the key exists in the hash. Use L< | |
3120 | not whether the key exists in the hash. Use L<C<exists>|/exists EXPR> | |
2594 | purpose. | |
3121 | for the latter purpose. | |
2595 | 3122 | |
2596 | 3123 | =end original |
2597 | 3124 | |
2598 | 3125 | ハッシュの要素に対して用いると、value が定義されているか否かを |
2599 | 3126 | 返すものであって、ハッシュに key が存在するか否かを返すのではありません。 |
2600 | この用途には、L</exists> を使ってください。 | |
3127 | この用途には、L<C<exists>|/exists EXPR> を使ってください。 | |
2601 | 3128 | |
2602 | 3129 | =begin original |
2603 | 3130 | |
2604 | 3131 | Examples: |
2605 | 3132 | |
2606 | 3133 | =end original |
2607 | 3134 | |
2608 | 3135 | 例: |
2609 | 3136 | |
2610 | 3137 | print if defined $switch{D}; |
2611 | 3138 | print "$val\n" while defined($val = pop(@ary)); |
2612 | 3139 | die "Can't readlink $sym: $!" |
2613 | 3140 | unless defined($value = readlink $sym); |
2614 | sub foo { defined &$bar ? | |
3141 | sub foo { defined &$bar ? $bar->(@_) : die "No bar"; } | |
2615 | 3142 | $debugging = 0 unless defined $debugging; |
2616 | 3143 | |
2617 | 3144 | =begin original |
2618 | 3145 | |
2619 | Note: Many folks tend to overuse C<defined> and are | |
3146 | Note: Many folks tend to overuse L<C<defined>|/defined EXPR> and are | |
2620 | discover that the number C<0> and C<""> (the | |
3147 | then surprised to discover that the number C<0> and C<""> (the | |
2621 | defined values. For example, if you | |
3148 | zero-length string) are, in fact, defined values. For example, if you | |
3149 | say | |
2622 | 3150 | |
2623 | 3151 | =end original |
2624 | 3152 | |
2625 | 注意: 多くの人々が C<defined> を使いすぎて、C<0> と | |
3153 | 注意: 多くの人々が L<C<defined>|/defined EXPR> を使いすぎて、C<0> と | |
2626 | 実際のところ定義された値であることに驚くようです。 | |
3154 | C<"">(空文字列) が実際のところ定義された値であることに驚くようです。 | |
2627 | 3155 | 例えば、以下のように書くと: |
2628 | 3156 | |
2629 | 3157 | "ab" =~ /a(.*)b/; |
2630 | 3158 | |
2631 | 3159 | =begin original |
2632 | 3160 | |
2633 | 3161 | The pattern match succeeds and C<$1> is defined, although it |
2634 | 3162 | matched "nothing". It didn't really fail to match anything. Rather, it |
2635 | 3163 | matched something that happened to be zero characters long. This is all |
2636 | 3164 | very above-board and honest. When a function returns an undefined value, |
2637 | 3165 | it's an admission that it couldn't give you an honest answer. So you |
2638 | should use C<defined> only when questioning the | |
3166 | should use L<C<defined>|/defined EXPR> only when questioning the | |
2639 | you're trying to do. At other times, a simple | |
3167 | integrity of what you're trying to do. At other times, a simple | |
2640 | what you want. | |
3168 | comparison to C<0> or C<""> is what you want. | |
2641 | 3169 | |
2642 | 3170 | =end original |
2643 | 3171 | |
2644 | 3172 | パターンマッチングが成功し、C<$1> が定義されても、実際には |
2645 | 3173 | 「なし」にマッチしています。 |
2646 | 3174 | しかしこれは何にもマッチしていないわけではありません。 |
2647 | 3175 | 何かにはマッチしているのですが、たまたまそれが長さ 0 だっただけです。 |
2648 | 3176 | これは非常に率直で正直なことです。 |
2649 | 3177 | 関数が未定義値を返すとき、正直な答えを返すことができないことを |
2650 | 3178 | 告白しています。 |
2651 | 3179 | ですので、あなたが自分がしようとしていることの完全性を確認するときにだけ |
2652 | C<defined> を使うべきです。 | |
3180 | L<C<defined>|/defined EXPR> を使うべきです。 | |
2653 | 3181 | その他の場合では、単に C<0> または C<""> と比較するというのがあなたの |
2654 | 3182 | 求めているものです。 |
2655 | 3183 | |
2656 | 3184 | =begin original |
2657 | 3185 | |
2658 | See also L</undef>, L< | |
3186 | See also L<C<undef>|/undef EXPR>, L<C<exists>|/exists EXPR>, | |
3187 | L<C<ref>|/ref EXPR>. | |
2659 | 3188 | |
2660 | 3189 | =end original |
2661 | 3190 | |
2662 | L</undef>, L</exists>, L</ref> も | |
3191 | L<C<undef>|/undef EXPR>, L<C<exists>|/exists EXPR>, L<C<ref>|/ref EXPR> も | |
3192 | 参照してください。 | |
2663 | 3193 | |
2664 | 3194 | =item delete EXPR |
2665 | 3195 | X<delete> |
2666 | 3196 | |
3197 | =for Pod::Functions deletes a value from a hash | |
3198 | ||
2667 | 3199 | =begin original |
2668 | 3200 | |
2669 | Given an expression that specifies an element or slice of a hash, | |
3201 | Given an expression that specifies an element or slice of a hash, | |
2670 | deletes the specified elements from that hash | |
3202 | L<C<delete>|/delete EXPR> deletes the specified elements from that hash | |
2671 | ||
3203 | so that L<C<exists>|/exists EXPR> on that element no longer returns | |
2672 | ||
3204 | true. Setting a hash element to the undefined value does not remove its | |
3205 | key, but deleting it does; see L<C<exists>|/exists EXPR>. | |
2673 | 3206 | |
2674 | 3207 | =end original |
2675 | 3208 | |
2676 | ハッシュの要素やスライスを指定する式を取り、C<delete> は | |
3209 | ハッシュの要素やスライスを指定する式を取り、L<C<delete>|/delete EXPR> は | |
2677 | 3210 | 指定された要素をハッシュから削除するので、 |
2678 | その要素に対する exists | |
3211 | その要素に対する L<C<exists>|/exists EXPR> はもはや真を返さなくなります。 | |
2679 | 3212 | ハッシュ要素に未定義値をセットしてもそのキーは削除されませんが、 |
2680 | delete では削除されます; L</exists> を参照してください。 | |
3213 | delete では削除されます; L<C<exists>|/exists EXPR> を参照してください。 | |
2681 | 3214 | |
2682 | 3215 | =begin original |
2683 | 3216 | |
2684 | 3217 | In list context, returns the value or values deleted, or the last such |
2685 | 3218 | element in scalar context. The return list's length always matches that of |
2686 | 3219 | the argument list: deleting non-existent elements returns the undefined value |
2687 | 3220 | in their corresponding positions. |
2688 | 3221 | |
2689 | 3222 | =end original |
2690 | 3223 | |
2691 | 3224 | リストコンテキストでは削除された要素を返し、スカラコンテキストでは |
2692 | 3225 | 削除された要素のうち最後のものを返します。 |
2693 | 3226 | 返されたリストの長さは常に引数リストの長さと一致します: |
2694 | 3227 | 存在しない要素を削除すると、対応する位置に未定義値をセットして返します。 |
2695 | 3228 | |
2696 | 3229 | =begin original |
2697 | 3230 | |
2698 | delete | |
3231 | L<C<delete>|/delete EXPR> may also be used on arrays and array slices, | |
2699 | straightforward. Although | |
3232 | but its behavior is less straightforward. Although | |
2700 | ||
3233 | L<C<exists>|/exists EXPR> will return false for deleted entries, | |
2701 | ||
3234 | deleting array elements never changes indices of existing values; use | |
2702 | ||
3235 | L<C<shift>|/shift ARRAY> or L<C<splice>|/splice | |
2703 | ||
3236 | ARRAY,OFFSET,LENGTH,LIST> for that. However, if any deleted elements | |
3237 | fall at the end of an array, the array's size shrinks to the position of | |
3238 | the highest element that still tests true for L<C<exists>|/exists EXPR>, | |
3239 | or to 0 if none do. In other words, an array won't have trailing | |
3240 | nonexistent elements after a delete. | |
2704 | 3241 | |
2705 | 3242 | =end original |
2706 | 3243 | |
2707 | delete | |
3244 | L<C<delete>|/delete EXPR> は配列や配列のスライスに対しても使えますが、その | |
2708 | あまり直感的ではありません。 | |
3245 | 振る舞いはあまり直感的ではありません。 | |
2709 | 削除されたエントリに対しては exists | |
3246 | 削除されたエントリに対しては L<C<exists>|/exists EXPR> は偽を返しますが、 | |
2710 | 3247 | 配列要素を削除しても、存在する値の添え字は変わりません; このためには |
2711 | shift | |
3248 | L<C<shift>|/shift ARRAY> や L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> を | |
2712 | ||
3249 | 使ってください。 | |
2713 | ||
3250 | しかし、削除された要素が配列の末尾であった場合、配列のサイズは | |
3251 | L<C<exists>|/exists EXPR> が真となる最大位置の要素(それがない場合は 0)に | |
3252 | 切り詰められます。 | |
3253 | 言い換えると、delete の後には配列の末尾に値のない要素はありません。 | |
2714 | 3254 | |
2715 | 3255 | =begin original |
2716 | 3256 | |
2717 | B<WARNING:> Calling delete on array values is | |
3257 | B<WARNING:> Calling L<C<delete>|/delete EXPR> on array values is | |
2718 | ||
3258 | strongly discouraged. The | |
3259 | notion of deleting or checking the existence of Perl array elements is not | |
3260 | conceptually coherent, and can lead to surprising behavior. | |
2719 | 3261 | |
2720 | 3262 | =end original |
2721 | 3263 | |
2722 | B<警告:> 配列の値に対して delete を呼び出すことは | |
3264 | B<警告:> 配列の値に対して L<C<delete>|/delete EXPR> を呼び出すことは強く | |
2723 | ||
3265 | 非推奨です。 | |
3266 | Perl の配列要素を削除したり存在を調べたりする記法は概念的に一貫しておらず、 | |
3267 | 驚くべき振る舞いを引き起こすことがあります。 | |
2724 | 3268 | |
2725 | 3269 | =begin original |
2726 | 3270 | |
2727 | Deleting from C<%ENV> modifies the environment. | |
3271 | Deleting from L<C<%ENV>|perlvar/%ENV> modifies the environment. | |
2728 | a DBM file deletes the entry from the DBM | |
3272 | Deleting from a hash tied to a DBM file deletes the entry from the DBM | |
2729 | ||
3273 | file. Deleting from a L<C<tied>|/tied VARIABLE> hash or array may not | |
2730 | ||
3274 | necessarily return anything; it depends on the implementation of the | |
3275 | L<C<tied>|/tied VARIABLE> package's DELETE method, which may do whatever | |
3276 | it pleases. | |
2731 | 3277 | |
2732 | 3278 | =end original |
2733 | 3279 | |
2734 | C<%ENV> から削除を行なうと、実際に環境変数を変更します。 | |
3280 | L<C<%ENV>|perlvar/%ENV> から削除を行なうと、実際に環境変数を変更します。 | |
2735 | 3281 | DBM ファイルに tie された配列からの削除は、その DBM ファイルからエントリを |
2736 | 3282 | 削除します。 |
2737 | しかし、C<tie> されたハッシュや配列からの | |
3283 | しかし、L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> されたハッシュや配列からの | |
2738 | 値を返すとは限りません; これは | |
3284 | 削除は、値を返すとは限りません; これは | |
3285 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> されたパッケージの DELETE | |
2739 | 3286 | メソッドの実装に依存するので、どんなことでも起こります。 |
2740 | 3287 | |
2741 | 3288 | =begin original |
2742 | 3289 | |
2743 | 3290 | The C<delete local EXPR> construct localizes the deletion to the current |
2744 | 3291 | block at run time. Until the block exits, elements locally deleted |
2745 | 3292 | temporarily no longer exist. See L<perlsub/"Localized deletion of elements |
2746 | 3293 | of composite types">. |
2747 | 3294 | |
2748 | 3295 | =end original |
2749 | 3296 | |
2750 | 3297 | C<delete local EXPR> 構文は、現在のブロックの削除を実行時にローカル化します。 |
2751 | 3298 | ブロックから出るまで、ローカルで削除された要素は存在しなくなります。 |
2752 | 3299 | L<perlsub/"Localized deletion of elements of composite types"> を |
2753 | 3300 | 参照してください。 |
2754 | 3301 | |
2755 | %hash = (foo => 11, bar => 22, baz => 33); | |
3302 | my %hash = (foo => 11, bar => 22, baz => 33); | |
2756 | $scalar = delete $hash{foo}; | |
3303 | my $scalar = delete $hash{foo}; # $scalar is 11 | |
2757 | $scalar = delete @hash{qw(foo bar)}; | |
3304 | $scalar = delete @hash{qw(foo bar)}; # $scalar is 22 | |
2758 | @array = delete @hash{qw(foo ba | |
3305 | my @array = delete @hash{qw(foo baz)}; # @array is (undef,33) | |
2759 | 3306 | |
2760 | 3307 | =begin original |
2761 | 3308 | |
2762 | 3309 | The following (inefficiently) deletes all the values of %HASH and @ARRAY: |
2763 | 3310 | |
2764 | 3311 | =end original |
2765 | 3312 | |
2766 | 3313 | 以下は、%HASH と @ARRAY のすべての値を(非効率的に)削除します: |
2767 | 3314 | |
2768 | foreach $key (keys %HASH) { | |
3315 | foreach my $key (keys %HASH) { | |
2769 | 3316 | delete $HASH{$key}; |
2770 | 3317 | } |
2771 | 3318 | |
2772 | foreach $index (0 .. $#ARRAY) { | |
3319 | foreach my $index (0 .. $#ARRAY) { | |
2773 | 3320 | delete $ARRAY[$index]; |
2774 | 3321 | } |
2775 | 3322 | |
2776 | 3323 | =begin original |
2777 | 3324 | |
2778 | 3325 | And so do these: |
2779 | 3326 | |
2780 | 3327 | =end original |
2781 | 3328 | |
2782 | 3329 | そして以下のようにもできます: |
2783 | 3330 | |
2784 | 3331 | delete @HASH{keys %HASH}; |
2785 | 3332 | |
2786 | 3333 | delete @ARRAY[0 .. $#ARRAY]; |
2787 | 3334 | |
2788 | 3335 | =begin original |
2789 | 3336 | |
2790 | 3337 | But both are slower than assigning the empty list |
2791 | or undefining %HASH or @ARRAY, which is the customary | |
3338 | or undefining %HASH or @ARRAY, which is the customary | |
2792 | 3339 | way to empty out an aggregate: |
2793 | 3340 | |
2794 | 3341 | =end original |
2795 | 3342 | |
2796 | 3343 | しかし、これら二つは両方とも、構造を空にするための慣習的な方法である、 |
2797 | 3344 | 単に空リストを代入するか、%HASH や @ARRAY を |
2798 | 3345 | undef するより遅いです: |
2799 | 3346 | |
2800 | 3347 | %HASH = (); # completely empty %HASH |
2801 | 3348 | undef %HASH; # forget %HASH ever existed |
2802 | 3349 | |
2803 | 3350 | @ARRAY = (); # completely empty @ARRAY |
2804 | 3351 | undef @ARRAY; # forget @ARRAY ever existed |
2805 | 3352 | |
2806 | 3353 | =begin original |
2807 | 3354 | |
2808 | 3355 | The EXPR can be arbitrarily complicated provided its |
2809 | 3356 | final operation is an element or slice of an aggregate: |
2810 | 3357 | |
2811 | 3358 | =end original |
2812 | 3359 | |
2813 | 3360 | 最終的な操作が集合の要素かスライスである限りは、 |
2814 | 3361 | いずれかである限りは、EXPR には任意の複雑な式を置くことができます: |
2815 | 3362 | |
2816 | 3363 | delete $ref->[$x][$y]{$key}; |
2817 | 3364 | delete @{$ref->[$x][$y]}{$key1, $key2, @morekeys}; |
2818 | 3365 | |
2819 | 3366 | delete $ref->[$x][$y][$index]; |
2820 | 3367 | delete @{$ref->[$x][$y]}[$index1, $index2, @moreindices]; |
2821 | 3368 | |
2822 | 3369 | =item die LIST |
2823 | 3370 | X<die> X<throw> X<exception> X<raise> X<$@> X<abort> |
2824 | 3371 | |
3372 | =for Pod::Functions raise an exception or bail out | |
3373 | ||
2825 | 3374 | =begin original |
2826 | 3375 | |
2827 | C<die> raises an exception. Inside an | |
3376 | L<C<die>|/die LIST> raises an exception. Inside an | |
2828 | ||
3377 | L<C<eval>|/eval EXPR> the error message is stuffed into | |
2829 | ||
3378 | L<C<$@>|perlvar/$@> and the L<C<eval>|/eval EXPR> is terminated with the | |
2830 | exception | |
3379 | undefined value. If the exception is outside of all enclosing | |
2831 | ||
3380 | L<C<eval>|/eval EXPR>s, then the uncaught exception prints LIST to | |
3381 | C<STDERR> and exits with a non-zero value. If you need to exit the | |
3382 | process with a specific exit code, see L<C<exit>|/exit EXPR>. | |
2832 | 3383 | |
2833 | 3384 | =end original |
2834 | 3385 | |
2835 | C<die> は例外を発生させます。 | |
3386 | L<C<die>|/die LIST> は例外を発生させます。 | |
2836 | C<eval> の中で使用すると、エラーメッセージが | |
3387 | L<C<eval>|/eval EXPR> の中で使用すると、エラーメッセージが | |
3388 | L<C<$@>|perlvar/$@> に入り、L<C<eval>|/eval EXPR> は | |
2837 | 3389 | 未定義値を返して終了します。 |
2838 | 例外が全ての C<eval> の外側の場合は、捕捉されなかった例外は | |
3390 | 例外が全ての L<C<eval>|/eval EXPR> の外側の場合は、捕捉されなかった例外は | |
2839 | C<STDERR> に表示して、非 0 の値で終了します。 | |
3391 | LIST を C<STDERR> に表示して、非 0 の値で終了します。 | |
2840 | 特定の終了コードでプロセスを終了させる必要がある場合は、 | |
3392 | 特定の終了コードでプロセスを終了させる必要がある場合は、 | |
2841 | 参照してください。 | |
3393 | L<C<exit>|/exit EXPR> を参照してください。 | |
2842 | 3394 | |
2843 | 3395 | =begin original |
2844 | 3396 | |
2845 | 3397 | Equivalent examples: |
2846 | 3398 | |
2847 | 3399 | =end original |
2848 | 3400 | |
2849 | 3401 | 等価な例: |
2850 | 3402 | |
2851 | 3403 | die "Can't cd to spool: $!\n" unless chdir '/usr/spool/news'; |
2852 | 3404 | chdir '/usr/spool/news' or die "Can't cd to spool: $!\n" |
2853 | 3405 | |
2854 | 3406 | =begin original |
2855 | 3407 | |
2856 | 3408 | If the last element of LIST does not end in a newline, the current |
2857 | 3409 | script line number and input line number (if any) are also printed, |
2858 | 3410 | and a newline is supplied. Note that the "input line number" (also |
2859 | 3411 | known as "chunk") is subject to whatever notion of "line" happens to |
2860 | 3412 | be currently in effect, and is also available as the special variable |
2861 | C<$.>. See L<perlvar/"$/"> and L<perlvar/"$.">. | |
3413 | L<C<$.>|perlvar/$.>. See L<perlvar/"$/"> and L<perlvar/"$.">. | |
2862 | 3414 | |
2863 | 3415 | =end original |
2864 | 3416 | |
2865 | LIST の最後の要素が改行で終わっていなければ、その時点の | |
3417 | LIST の最後の要素が改行で終わっていなければ、その時点のスクリプト名と | |
2866 | スクリプト | |
3418 | スクリプトの行番号、(もしあれば) 入力ファイルの行番号と改行文字が、続けて | |
2867 | ||
3419 | 表示されます。 | |
2868 | 「入力行番号」("chunk" とも呼ばれます)は | |
3420 | 「入力行番号」("chunk" とも呼ばれます)は「行」という概念が現在有効であると | |
2869 | ||
3421 | 仮定しています; また特殊変数 L<C<$.>|perlvar/$.> でも利用可能です。 | |
2870 | また特殊変数 C<$.> でも利用可能です。 | |
2871 | 3422 | L<perlvar/"$/"> と L<perlvar/"$."> も参照してください。 |
2872 | 3423 | |
2873 | 3424 | =begin original |
2874 | 3425 | |
2875 | 3426 | Hint: sometimes appending C<", stopped"> to your message will cause it |
2876 | 3427 | to make better sense when the string C<"at foo line 123"> is appended. |
2877 | 3428 | Suppose you are running script "canasta". |
2878 | 3429 | |
2879 | 3430 | =end original |
2880 | 3431 | |
2881 | 3432 | ヒント: メッセージの最後を C<", stopped"> のようなもので |
2882 | 3433 | 終わるようにしておけば、C<"at foo line 123"> のように |
2883 | 3434 | 追加されて、わかりやすくなります。 |
2884 | 3435 | "canasta" というスクリプトを実行しているとします。 |
2885 | 3436 | |
2886 | 3437 | die "/etc/games is no good"; |
2887 | 3438 | die "/etc/games is no good, stopped"; |
2888 | 3439 | |
2889 | 3440 | =begin original |
2890 | 3441 | |
2891 | 3442 | produce, respectively |
2892 | 3443 | |
2893 | 3444 | =end original |
2894 | 3445 | |
2895 | 3446 | これは、それぞれ以下のように表示します。 |
2896 | 3447 | |
2897 | 3448 | /etc/games is no good at canasta line 123. |
2898 | 3449 | /etc/games is no good, stopped at canasta line 123. |
2899 | 3450 | |
2900 | 3451 | =begin original |
2901 | 3452 | |
2902 | If the output is empty and C<$@> already contains a value | |
3453 | If the output is empty and L<C<$@>|perlvar/$@> already contains a value | |
2903 | previous eval) that value is reused after appending | |
3454 | (typically from a previous eval) that value is reused after appending | |
2904 | This is useful for propagating exceptions: | |
3455 | C<"\t...propagated">. This is useful for propagating exceptions: | |
2905 | 3456 | |
2906 | 3457 | =end original |
2907 | 3458 | |
2908 | 出力が空で C<$@> が(典型的には前回の eval で)既に値を持っている | |
3459 | 出力が空で L<C<$@>|perlvar/$@> が(典型的には前回の eval で)既に値を持っている | |
2909 | 値は C<"\t...propagated"> を追加した後再利用されます。 | |
3460 | 場合、値は C<"\t...propagated"> を追加した後再利用されます。 | |
2910 | 3461 | これは例外を伝播させる場合に有効です: |
2911 | 3462 | |
2912 | 3463 | eval { ... }; |
2913 | 3464 | die unless $@ =~ /Expected exception/; |
2914 | 3465 | |
2915 | 3466 | =begin original |
2916 | 3467 | |
2917 | If the output is empty and C<$@> contains an object | |
3468 | If the output is empty and L<C<$@>|perlvar/$@> contains an object | |
2918 | C<PROPAGATE> method, that method will be called | |
3469 | reference that has a C<PROPAGATE> method, that method will be called | |
2919 | and line number parameters. The return value | |
3470 | with additional file and line number parameters. The return value | |
2920 | ||
3471 | replaces the value in L<C<$@>|perlvar/$@>; i.e., as if | |
2921 | were called. | |
3472 | C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >> were called. | |
2922 | 3473 | |
2923 | 3474 | =end original |
2924 | 3475 | |
2925 | 出力が空で、C<$@> が C<PROPAGATE> メソッドを含むオブジェクトへの | |
3476 | 出力が空で、L<C<$@>|perlvar/$@> が C<PROPAGATE> メソッドを含むオブジェクトへの | |
2926 | 3477 | リファレンスを含む場合、このメソッドが追加ファイルと行番号を引数として |
2927 | 3478 | 呼び出されます。 |
2928 | 返り値は C<$@> の値を置き換えます; | |
3479 | 返り値は L<C<$@>|perlvar/$@> の値を置き換えます; | |
2929 | 3480 | つまり、C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >> が |
2930 | 3481 | 呼び出されたかのようになります。 |
2931 | 3482 | |
2932 | 3483 | =begin original |
2933 | 3484 | |
2934 | If C<$@> is empty then the string C<"Died"> is used. | |
3485 | If L<C<$@>|perlvar/$@> is empty, then the string C<"Died"> is used. | |
2935 | 3486 | |
2936 | 3487 | =end original |
2937 | 3488 | |
2938 | C<$@> が空の場合、C<"Died"> が使われます。 | |
3489 | L<C<$@>|perlvar/$@> が空の場合、C<"Died"> が使われます。 | |
2939 | 3490 | |
2940 | 3491 | =begin original |
2941 | 3492 | |
2942 | 3493 | If an uncaught exception results in interpreter exit, the exit code is |
2943 | determined from the values of C<$!> | |
3494 | determined from the values of L<C<$!>|perlvar/$!> and | |
3495 | L<C<$?>|perlvar/$?> with this pseudocode: | |
2944 | 3496 | |
2945 | 3497 | =end original |
2946 | 3498 | |
2947 | 3499 | 例外が捕捉されないとインタプリタは終了し、終了コードは以下の |
2948 | 擬似コードのように、C<$!> と C<$?> の値から | |
3500 | 擬似コードのように、L<C<$!>|perlvar/$!> と L<C<$?>|perlvar/$?> の値から | |
3501 | 決定されます: | |
2949 | 3502 | |
2950 | 3503 | exit $! if $!; # errno |
2951 | 3504 | exit $? >> 8 if $? >> 8; # child exit status |
2952 | 3505 | exit 255; # last resort |
2953 | 3506 | |
2954 | 3507 | =begin original |
2955 | 3508 | |
3509 | As with L<C<exit>|/exit EXPR>, L<C<$?>|perlvar/$?> is set prior to | |
3510 | unwinding the call stack; any C<DESTROY> or C<END> handlers can then | |
3511 | alter this value, and thus Perl's exit code. | |
3512 | ||
3513 | =end original | |
3514 | ||
3515 | L<C<exit>|/exit EXPR> と同様に、コールスタックを巻き戻す前に | |
3516 | L<C<$?>|perlvar/$?> が設定されます; C<DESTROY> と C<END> のハンドラが | |
3517 | それからこの値を変更して、これが Perl の終了コードになります。 | |
3518 | ||
3519 | =begin original | |
3520 | ||
2956 | 3521 | The intent is to squeeze as much possible information about the likely cause |
2957 | into the limited space of the system exit code. However, as | |
3522 | into the limited space of the system exit code. However, as | |
2958 | of C's C<errno>, which can be set by | |
3523 | L<C<$!>|perlvar/$!> is the value of C's C<errno>, which can be set by | |
2959 | ||
3524 | any system call, this means that the value of the exit code used by | |
3525 | L<C<die>|/die LIST> can be non-predictable, so should not be relied | |
2960 | 3526 | upon, other than to be non-zero. |
2961 | 3527 | |
2962 | 3528 | =end original |
2963 | 3529 | |
2964 | 3530 | この意図は、できるだけ多くの似たような原因に関する情報を、システム終了 |
2965 | 3531 | コードという限られた領域に圧縮することです。 |
2966 | しかし、C<$!> はシステムコールによって設定される可能性がある C の | |
3532 | しかし、L<C<$!>|perlvar/$!> はシステムコールによって設定される可能性がある C の | |
2967 | C<errno> の値であり、C<die> によって使われる終了コードの値は | |
3533 | C<errno> の値であり、L<C<die>|/die LIST> によって使われる終了コードの値は | |
2968 | 3534 | 予測不能であることを意味するので、非 0 ということ以上にこの値に |
2969 | 3535 | 依存するべきではありません。 |
2970 | 3536 | |
2971 | 3537 | =begin original |
2972 | 3538 | |
2973 | You can also call C<die> with a reference argument, and if | |
3539 | You can also call L<C<die>|/die LIST> with a reference argument, and if | |
2974 | within an C<eval>, C<$@> | |
3540 | this is trapped within an L<C<eval>|/eval EXPR>, L<C<$@>|perlvar/$@> | |
2975 | elaborate exception handling | |
3541 | contains that reference. This permits more elaborate exception handling | |
2976 | about the exception. Such a | |
3542 | using objects that maintain arbitrary state about the exception. Such a | |
2977 | ||
3543 | scheme is sometimes preferable to matching particular string values of | |
2978 | ||
3544 | L<C<$@>|perlvar/$@> with regular expressions. Because | |
2979 | ||
3545 | L<C<$@>|perlvar/$@> is a global variable and L<C<eval>|/eval EXPR> may | |
2980 | th | |
3546 | be used within object implementations, be careful that analyzing the | |
2981 | ||
3547 | error object doesn't replace the reference in the global variable. It's | |
3548 | easiest to make a local copy of the reference before any manipulations. | |
3549 | Here's an example: | |
2982 | 3550 | |
2983 | 3551 | =end original |
2984 | 3552 | |
2985 | die | |
3553 | L<C<die>|/die LIST> はリファレンス引数と共に呼び出すこともでき、これが | |
2986 | eval | |
3554 | L<C<eval>|/eval EXPR> 内部でトラップされた場合、L<C<$@>|perlvar/$@> は | |
3555 | そのリファレンスを持ちます。 | |
2987 | 3556 | これは、例外の性質について任意の状態を管理するオブジェクトを使った |
2988 | 3557 | より複雑な例外処理の実装を可能にします。 |
2989 | このようなスキームは C<$@> の特定の文字列値を正規表現を使って | |
3558 | このようなスキームは L<C<$@>|perlvar/$@> の特定の文字列値を正規表現を使って | |
2990 | 3559 | マッチングするときに時々好まれます。 |
2991 | C<$@> はグローバル変数で、C<eval> はオブジェクト | |
3560 | L<C<$@>|perlvar/$@> はグローバル変数で、L<C<eval>|/eval EXPR> はオブジェクト | |
2992 | 使われることがあるので、エラーオブジェクトの解析はグローバル変数の | |
3561 | 実装の内部で使われることがあるので、エラーオブジェクトの解析はグローバル変数の | |
2993 | 3562 | リファレンスを置き換えないことに注意を払わなければなりません。 |
2994 | 3563 | 他の操作をする前にリファレンスのローカルコピーを |
2995 | 3564 | 作るのが一番簡単です。 |
2996 | 3565 | 以下に例を示します: |
2997 | 3566 | |
2998 | 3567 | use Scalar::Util "blessed"; |
2999 | 3568 | |
3000 | 3569 | eval { ... ; die Some::Module::Exception->new( FOO => "bar" ) }; |
3001 | 3570 | if (my $ev_err = $@) { |
3002 | if (blessed($ev_err) | |
3571 | if (blessed($ev_err) | |
3572 | && $ev_err->isa("Some::Module::Exception")) { | |
3003 | 3573 | # handle Some::Module::Exception |
3004 | 3574 | } |
3005 | 3575 | else { |
3006 | 3576 | # handle all other possible exceptions |
3007 | 3577 | } |
3008 | 3578 | } |
3009 | 3579 | |
3010 | 3580 | =begin original |
3011 | 3581 | |
3012 | 3582 | Because Perl stringifies uncaught exception messages before display, |
3013 | 3583 | you'll probably want to overload stringification operations on |
3014 | 3584 | exception objects. See L<overload> for details about that. |
3015 | 3585 | |
3016 | 3586 | =end original |
3017 | 3587 | |
3018 | 3588 | perl は捕らえられなかった例外のメッセージを表示する前に文字列化するので、 |
3019 | 3589 | このようなカスタム例外オブジェクトの文字列化をオーバーロードしたいと |
3020 | 3590 | 思うかもしれません。 |
3021 | 3591 | これに関する詳細は L<overload> を参照してください。 |
3022 | 3592 | |
3023 | 3593 | =begin original |
3024 | 3594 | |
3025 | You can arrange for a callback to be run just before the | |
3595 | You can arrange for a callback to be run just before the | |
3026 | does its deed, by setting the | |
3596 | L<C<die>|/die LIST> does its deed, by setting the | |
3027 | ||
3597 | L<C<$SIG{__DIE__}>|perlvar/%SIG> hook. The associated handler is called | |
3028 | message, if it sees fit, by | |
3598 | with the error text and can change the error message, if it sees fit, by | |
3029 | L<perlvar/%SIG> for details on | |
3599 | calling L<C<die>|/die LIST> again. See L<perlvar/%SIG> for details on | |
3030 | L< | |
3600 | setting L<C<%SIG>|perlvar/%SIG> entries, and L<C<eval>|/eval EXPR> for some | |
3031 | to be run only right before your | |
3601 | examples. Although this feature was to be run only right before your | |
3032 | ||
3602 | program was to exit, this is not currently so: the | |
3033 | ev | |
3603 | L<C<$SIG{__DIE__}>|perlvar/%SIG> hook is currently called even inside | |
3604 | L<C<eval>|/eval EXPR>ed blocks/strings! If one wants the hook to do | |
3034 | 3605 | nothing in such situations, put |
3035 | 3606 | |
3036 | 3607 | =end original |
3037 | 3608 | |
3038 | C<$SIG{__DIE__}> フックをセットすることで、 | |
3609 | L<C<$SIG{__DIE__}>|perlvar/%SIG> フックをセットすることで、 | |
3610 | L<C<die>|/die LIST> がその行動を行う | |
3039 | 3611 | 直前に実行されるコールバックを設定できます。 |
3040 | 3612 | 結び付けられたハンドラはエラーテキストと共に呼び出され、 |
3041 | 必要なら再び C<die> を呼び出すことでエラーテキストを | |
3613 | 必要なら再び L<C<die>|/die LIST> を呼び出すことでエラーテキストを | |
3042 | ||
3614 | 変更できます。 | |
3043 | ||
3615 | L<C<%SIG>|perlvar/%SIG> のエントリをセットする詳細については、 | |
3616 | L<perlvar/%SIG> を、例については L<C<eval>|/eval EXPR> を参照してください。 | |
3044 | 3617 | この機能はプログラムが終了しようとする前に 1 回だけ実行していましたが、 |
3045 | 3618 | 現在ではそうではありません: |
3046 | C<$SIG{__DIE__}> フックは eval | |
3619 | L<C<$SIG{__DIE__}>|perlvar/%SIG> フックは L<C<eval>|/eval EXPR> された | |
3047 | 呼ばれるのです! | |
3620 | ブロック/文字列の中でも呼ばれるのです! | |
3048 | 3621 | もしそのような状況で何もしなくない時は: |
3049 | 3622 | |
3050 | 3623 | die @_ if $^S; |
3051 | 3624 | |
3052 | 3625 | =begin original |
3053 | 3626 | |
3054 | 3627 | as the first line of the handler (see L<perlvar/$^S>). Because |
3055 | 3628 | this promotes strange action at a distance, this counterintuitive |
3056 | 3629 | behavior may be fixed in a future release. |
3057 | 3630 | |
3058 | 3631 | =end original |
3059 | 3632 | |
3060 | 3633 | をハンドラの最初の行に置いてください(L<perlvar/$^S> を参照してください)。 |
3061 | 3634 | これは離れたところで不思議な行動を引き起こすので、 |
3062 | 3635 | この直感的でない振る舞いは将来のリリースで修正されるかもしれません。 |
3063 | 3636 | |
3064 | 3637 | =begin original |
3065 | 3638 | |
3066 | See also exit | |
3639 | See also L<C<exit>|/exit EXPR>, L<C<warn>|/warn LIST>, and the L<Carp> | |
3640 | module. | |
3067 | 3641 | |
3068 | 3642 | =end original |
3069 | 3643 | |
3070 | exit | |
3644 | L<C<exit>|/exit EXPR> と L<C<warn>|/warn LIST> と L<Carp> モジュールも | |
3645 | 参照してください。 | |
3071 | 3646 | |
3072 | 3647 | =item do BLOCK |
3073 | 3648 | X<do> X<block> |
3074 | 3649 | |
3650 | =for Pod::Functions turn a BLOCK into a TERM | |
3651 | ||
3075 | 3652 | =begin original |
3076 | 3653 | |
3077 | 3654 | Not really a function. Returns the value of the last command in the |
3078 | 3655 | sequence of commands indicated by BLOCK. When modified by the C<while> or |
3079 | 3656 | C<until> loop modifier, executes the BLOCK once before testing the loop |
3080 | condition. (On other statements the loop modifiers test the conditional | |
3657 | condition. (On other statements the loop modifiers test the conditional | |
3081 | 3658 | first.) |
3082 | 3659 | |
3083 | 3660 | =end original |
3084 | 3661 | |
3085 | 3662 | 実際は関数ではありません。 |
3086 | 3663 | BLOCK で示されるコマンド列の最後の値を返します。 |
3087 | 3664 | C<while> や C<until> ループ修飾子で修飾すると、 |
3088 | 3665 | ループ条件を調べる前に 1 度、BLOCK を実行します。 |
3089 | 3666 | (これ以外の実行文は、ループ修飾子により、条件が最初に |
3090 | 3667 | 調べられます。) |
3091 | 3668 | |
3092 | 3669 | =begin original |
3093 | 3670 | |
3094 | 3671 | C<do BLOCK> does I<not> count as a loop, so the loop control statements |
3095 | C<next> | |
3672 | L<C<next>|/next LABEL>, L<C<last>|/last LABEL>, or | |
3673 | L<C<redo>|/redo LABEL> cannot be used to leave or restart the block. | |
3096 | 3674 | See L<perlsyn> for alternative strategies. |
3097 | 3675 | |
3098 | 3676 | =end original |
3099 | 3677 | |
3100 | C<do BLOCK> はループとしては I<扱われません> | |
3678 | C<do BLOCK> はループとしては I<扱われません>; 従って、L<C<next>|/next LABEL>, | |
3101 | ||
3679 | L<C<last>|/last LABEL>,L<C<redo>|/redo LABEL> といったループ制御文は | |
3102 | 3680 | ブロックから抜けたり再開することはできません。 |
3103 | その他の戦略については L<perlsyn> を参照して | |
3681 | その他の戦略については L<perlsyn> を参照してください。 | |
3104 | 3682 | |
3105 | =item do SUBROUTINE(LIST) | |
3106 | X<do> | |
3107 | ||
3108 | =begin original | |
3109 | ||
3110 | This form of subroutine call is deprecated. SUBROUTINE can be a bareword, | |
3111 | a scalar variable or a subroutine beginning with C<&>. | |
3112 | ||
3113 | =end original | |
3114 | ||
3115 | この形のサブルーチン呼び出しは非推奨です。 | |
3116 | SUBROUTINE には裸の単語、スカラ変数、C<&> で始まるサブルーチンが使えます。 | |
3117 | ||
3118 | 3683 | =item do EXPR |
3119 | 3684 | X<do> |
3120 | 3685 | |
3121 | 3686 | =begin original |
3122 | 3687 | |
3123 | 3688 | Uses the value of EXPR as a filename and executes the contents of the |
3124 | 3689 | file as a Perl script. |
3125 | 3690 | |
3126 | 3691 | =end original |
3127 | 3692 | |
3128 | 3693 | EXPR の値をファイル名として用い、そのファイルの中身を |
3129 | 3694 | Perl のスクリプトとして実行します。 |
3130 | 3695 | |
3131 | 3696 | do 'stat.pl'; |
3132 | 3697 | |
3133 | 3698 | =begin original |
3134 | 3699 | |
3135 | is | |
3700 | is largely like | |
3136 | 3701 | |
3137 | 3702 | =end original |
3138 | 3703 | |
3139 | は以下のものと同じようなものですが、 | |
3704 | はだいたい以下のものと同じようなものですが、 | |
3140 | 3705 | |
3141 | 3706 | eval `cat stat.pl`; |
3142 | 3707 | |
3143 | 3708 | =begin original |
3144 | 3709 | |
3145 | except that it's more | |
3710 | except that it's more concise, runs no external processes, keeps track of | |
3146 | filename for error messages, searches the | |
3711 | the current filename for error messages, searches the | |
3147 | C< | |
3712 | L<C<@INC>|perlvar/@INC> directories, and updates L<C<%INC>|perlvar/%INC> | |
3148 | the | |
3713 | if the file is found. See L<perlvar/@INC> and L<perlvar/%INC> for these | |
3149 | ||
3714 | variables. It also differs in that code evaluated with C<do FILE> | |
3150 | ||
3715 | cannot see lexicals in the enclosing scope; C<eval STRING> does. It's | |
3151 | s | |
3716 | the same, however, in that it does reparse the file every time you call | |
3717 | it, so you probably don't want to do this inside a loop. | |
3152 | 3718 | |
3153 | 3719 | =end original |
3154 | 3720 | |
3155 | より | |
3721 | より簡潔で、外部プログラムを起動せず、エラーメッセージでファイル名がわかる、 | |
3156 | 3722 | カレントディレクトリでファイルが見つからなかったときに |
3157 | C<@INC> ディレクトリを検索する、ファイルがあったときに | |
3723 | L<C<@INC>|perlvar/@INC> ディレクトリを検索する、ファイルがあったときに | |
3158 | といったことがあります。 | |
3724 | L<C<%INC>|perlvar/%INC> を更新する、といったことがあります。 | |
3159 | 3725 | これらの変数については L<perlvar/@INC> と L<perlvar/%INC> を |
3160 | 3726 | 参照してください。 |
3161 | C<do FILE | |
3727 | C<do FILE> で評価されたコードは、入れ子のスコープにある | |
3162 | 3728 | レキシカル変数を見ることができないのに対し、C<eval STRING>ではできる、 |
3163 | 3729 | という違いがあります。 |
3164 | 3730 | しかし、呼び出すたびにファイルを解析し直すという点では同じですから、 |
3165 | 3731 | ループ内でこれを使おうなどとは、間違っても思ったりしないように。 |
3166 | 3732 | |
3167 | 3733 | =begin original |
3168 | 3734 | |
3169 | If C<do> can read the file but cannot compile it, it | |
3735 | If L<C<do>|/do EXPR> can read the file but cannot compile it, it | |
3170 | ||
3736 | returns L<C<undef>|/undef EXPR> and sets an error message in | |
3171 | ||
3737 | L<C<$@>|perlvar/$@>. If L<C<do>|/do EXPR> cannot read the file, it | |
3172 | ||
3738 | returns undef and sets L<C<$!>|perlvar/$!> to the error. Always check | |
3173 | ||
3739 | L<C<$@>|perlvar/$@> first, as compilation could fail in a way that also | |
3740 | sets L<C<$!>|perlvar/$!>. If the file is successfully compiled, | |
3741 | L<C<do>|/do EXPR> returns the value of the last expression evaluated. | |
3174 | 3742 | |
3175 | 3743 | =end original |
3176 | 3744 | |
3177 | C<do> がファイルを読み込めたがコンパイルできなかった場合、 | |
3745 | L<C<do>|/do EXPR> がファイルを読み込めたがコンパイルできなかった場合、 | |
3178 | C<undef> を返して C<$@> にエラーメッセージを | |
3746 | L<C<undef>|/undef EXPR> を返して L<C<$@>|perlvar/$@> にエラーメッセージを | |
3179 | ||
3747 | 設定します。 | |
3180 | ||
3748 | L<C<do>|/do EXPR>がファイルを読み込めなかった場合、undef を返して | |
3181 | ||
3749 | L<C<$!>|perlvar/$!> にエラーを設定します。 | |
3182 | ||
3750 | コンパイルに失敗したときにも L<C<$!>|perlvar/$!> が設定されるので、 | |
3183 | ||
3751 | 常に L<C<$@>|perlvar/$@> を先にチェックします。 | |
3752 | ファイルのコンパイルに成功した場合、L<C<do>|/do EXPR> は最後に評価した表現の | |
3753 | 値を返します。 | |
3184 | 3754 | |
3185 | 3755 | =begin original |
3186 | 3756 | |
3187 | 3757 | Inclusion of library modules is better done with the |
3188 | C<use> and C<require> | |
3758 | L<C<use>|/use Module VERSION LIST> and L<C<require>|/require VERSION> | |
3189 | and raise an exception | |
3759 | operators, which also do automatic error checking and raise an exception | |
3760 | if there's a problem. | |
3190 | 3761 | |
3191 | 3762 | =end original |
3192 | 3763 | |
3193 | ライブラリモジュールのインクルードには、 | |
3764 | ライブラリモジュールのインクルードには、 | |
3194 | C< | |
3765 | L<C<use>|/use Module VERSION LIST> 演算子や | |
3766 | L<C<require>|/require VERSION> 演算子を使った方がよいです; | |
3195 | 3767 | これらは自動的にエラーをチェックして、問題があれば例外を発生させます。 |
3196 | 3768 | |
3197 | 3769 | =begin original |
3198 | 3770 | |
3199 | You might like to use C<do> to read in a program | |
3771 | You might like to use L<C<do>|/do EXPR> to read in a program | |
3200 | file. Manual error checking can be done this way: | |
3772 | configuration file. Manual error checking can be done this way: | |
3201 | 3773 | |
3202 | 3774 | =end original |
3203 | 3775 | |
3204 | C<do> をプログラム設定ファイルを読み込むのに | |
3776 | L<C<do>|/do EXPR> をプログラム設定ファイルを読み込むのに | |
3777 | 使いたいかもしれません。 | |
3205 | 3778 | 手動のエラーチェックは以下のようにして行えます: |
3206 | 3779 | |
3207 | 3780 | # read in config files: system first, then user |
3208 | 3781 | for $file ("/share/prog/defaults.rc", |
3209 | 3782 | "$ENV{HOME}/.someprogrc") |
3210 | 3783 | { |
3211 | 3784 | unless ($return = do $file) { |
3212 | 3785 | warn "couldn't parse $file: $@" if $@; |
3213 | 3786 | warn "couldn't do $file: $!" unless defined $return; |
3214 | 3787 | warn "couldn't run $file" unless $return; |
3215 | 3788 | } |
3216 | 3789 | } |
3217 | 3790 | |
3218 | 3791 | =item dump LABEL |
3219 | 3792 | X<dump> X<core> X<undump> |
3220 | 3793 | |
3794 | =item dump EXPR | |
3795 | ||
3221 | 3796 | =item dump |
3222 | 3797 | |
3798 | =for Pod::Functions create an immediate core dump | |
3799 | ||
3223 | 3800 | =begin original |
3224 | 3801 | |
3225 | 3802 | This function causes an immediate core dump. See also the B<-u> |
3226 | 3803 | command-line switch in L<perlrun>, which does the same thing. |
3227 | 3804 | Primarily this is so that you can use the B<undump> program (not |
3228 | 3805 | supplied) to turn your core dump into an executable binary after |
3229 | 3806 | having initialized all your variables at the beginning of the |
3230 | 3807 | program. When the new binary is executed it will begin by executing |
3231 | a C<goto LABEL> (with all the restrictions that C<goto> | |
3808 | a C<goto LABEL> (with all the restrictions that L<C<goto>|/goto LABEL> | |
3809 | suffers). | |
3232 | 3810 | Think of it as a goto with an intervening core dump and reincarnation. |
3233 | If C<LABEL> is omitted, restarts the program from the top. | |
3811 | If C<LABEL> is omitted, restarts the program from the top. The | |
3812 | C<dump EXPR> form, available starting in Perl 5.18.0, allows a name to be | |
3813 | computed at run time, being otherwise identical to C<dump LABEL>. | |
3234 | 3814 | |
3235 | 3815 | =end original |
3236 | 3816 | |
3237 | 3817 | この関数は即座にコアダンプを行ないます。 |
3238 | 3818 | 同様のことを行う L<perlrun> の B<-u> オプションも参照してください。 |
3239 | 3819 | プログラムの先頭で、 |
3240 | 3820 | すべての変数を初期化したあとのコアダンプを B<undump> |
3241 | 3821 | プログラム(提供していません)を使って実行ファイルに返ることができます。 |
3242 | 3822 | この新しいバイナリが実行されると、C<goto LABEL> から始めます |
3243 | (C<goto> に関する制限はすべて適用されます)。 | |
3823 | (L<C<goto>|/goto LABEL> に関する制限はすべて適用されます)。 | |
3244 | 3824 | コアダンプをはさんで再生する goto と考えてください。 |
3245 | 3825 | C<LABEL> が省略されると、プログラムを先頭から再開します。 |
3826 | Perl 5.18.0 から利用可能な C<dump EXPR> 形式では、実行時に計算される | |
3827 | 名前が使えます; その他は C<dump LABEL> と同一です。 | |
3246 | 3828 | |
3247 | 3829 | =begin original |
3248 | 3830 | |
3249 | 3831 | B<WARNING>: Any files opened at the time of the dump will I<not> |
3250 | 3832 | be open any more when the program is reincarnated, with possible |
3251 | 3833 | resulting confusion by Perl. |
3252 | 3834 | |
3253 | 3835 | =end original |
3254 | 3836 | |
3255 | B<警告>: dump 時点でオープンされていたファイルは、 | |
3837 | B<警告>: dump 時点でオープンされていたファイルは、プログラムが | |
3256 | ||
3838 | 再生されたときには、もはやオープンされて I<いません>; Perl を | |
3257 | ||
3839 | 混乱させる可能性があります。 | |
3258 | 3840 | |
3259 | 3841 | =begin original |
3260 | 3842 | |
3261 | 3843 | This function is now largely obsolete, mostly because it's very hard to |
3262 | convert a core file into an executable. That's why you should now invoke | |
3844 | convert a core file into an executable. That's why you should now invoke | |
3263 | it as C<CORE::dump()> | |
3845 | it as C<CORE::dump()> if you don't want to be warned against a possible | |
3264 | 3846 | typo. |
3265 | 3847 | |
3266 | 3848 | =end original |
3267 | 3849 | |
3268 | 3850 | この関数は大幅に時代遅れのものです; 主な理由としては、コアファイルを |
3269 | 3851 | 実行形式に変換するのが非常に困難であることです。 |
3270 | 3852 | これが、今ではタイプミスの可能性を警告されたくないなら |
3271 | C<CORE::dump | |
3853 | C<CORE::dump> として起動するべき理由です。 | |
3272 | 3854 | |
3855 | =begin original | |
3856 | ||
3857 | Unlike most named operators, this has the same precedence as assignment. | |
3858 | It is also exempt from the looks-like-a-function rule, so | |
3859 | C<dump ("foo")."bar"> will cause "bar" to be part of the argument to | |
3860 | L<C<dump>|/dump LABEL>. | |
3861 | ||
3862 | =end original | |
3863 | ||
3864 | ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 | |
3865 | また、関数のように見えるものの規則からも免れるので、C<dump ("foo")."bar"> と | |
3866 | すると "bar" は L<C<dump>|/dump LABEL> への引数の一部になります。 | |
3867 | ||
3868 | =begin original | |
3869 | ||
3870 | Portability issues: L<perlport/dump>. | |
3871 | ||
3872 | =end original | |
3873 | ||
3874 | 移植性の問題: L<perlport/dump>。 | |
3875 | ||
3273 | 3876 | =item each HASH |
3274 | 3877 | X<each> X<hash, iterator> |
3275 | 3878 | |
3276 | 3879 | =item each ARRAY |
3277 | 3880 | X<array, iterator> |
3278 | 3881 | |
3279 | =ite | |
3882 | =for Pod::Functions retrieve the next key/value pair from a hash | |
3280 | 3883 | |
3281 | 3884 | =begin original |
3282 | 3885 | |
3283 | When called in list context, returns a 2-element list | |
3886 | When called on a hash in list context, returns a 2-element list | |
3284 | and value for the next element of a hash | |
3887 | consisting of the key and value for the next element of a hash. In Perl | |
3285 | n | |
3888 | 5.12 and later only, it will also return the index and value for the next | |
3286 | ||
3889 | element of an array so that you can iterate over it; older Perls consider | |
3287 | in an arr | |
3890 | this a syntax error. When called in scalar context, returns only the key | |
3891 | (not the value) in a hash, or the index in an array. | |
3288 | 3892 | |
3289 | 3893 | =end original |
3290 | 3894 | |
3291 | リストコンテキストで呼び出した場合は、次の要素に対する、 | |
3895 | ハッシュに対してリストコンテキストで呼び出した場合は、次の要素に対する、 | |
3292 | ハッシュのキーと値 | |
3896 | ハッシュのキーと値を返します。 | |
3293 | 2 | |
3897 | Perl 5.12 以降でのみ、配列のインデックスと値からなる | |
3898 | 2 要素のリストを返すので、反復を行えます; より古い Perl ではこれは | |
3899 | 文法エラーと考えられます。 | |
3294 | 3900 | スカラコンテキストで呼び出した場合は、 |
3295 | 3901 | ハッシュの場合は(値ではなく)キー、配列の場合はインデックスを返します。 |
3296 | 3902 | |
3297 | 3903 | =begin original |
3298 | 3904 | |
3299 | 3905 | Hash entries are returned in an apparently random order. The actual random |
3300 | order is s | |
3906 | order is specific to a given hash; the exact same series of operations | |
3301 | ||
3907 | on two hashes may result in a different order for each hash. Any insertion | |
3302 | ||
3908 | into the hash may change the order, as will any deletion, with the exception | |
3303 | ||
3909 | that the most recent key returned by L<C<each>|/each HASH> or | |
3304 | ||
3910 | L<C<keys>|/keys HASH> may be deleted without changing the order. So | |
3911 | long as a given hash is unmodified you may rely on | |
3912 | L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and | |
3913 | L<C<each>|/each HASH> to repeatedly return the same order | |
3914 | as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for | |
3915 | details on why hash order is randomized. Aside from the guarantees | |
3916 | provided here the exact details of Perl's hash algorithm and the hash | |
3917 | traversal order are subject to change in any release of Perl. | |
3305 | 3918 | |
3306 | 3919 | =end original |
3307 | 3920 | |
3308 | ハッシュ | |
3921 | ハッシュ要素は見かけ上、ランダムな順序で返されます。 | |
3309 | 実際のランダムな順 | |
3922 | 実際のランダムな順序はハッシュに固有です; 二つのハッシュに全く同じ一連の | |
3310 | ||
3923 | 操作を行っても、ハッシュによって異なった順序になります。 | |
3311 | ||
3924 | ハッシュへの挿入によって順序が変わることがあります; 削除も同様ですが、 | |
3312 | ||
3925 | L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも | |
3313 | ||
3926 | 最近のキーは順序を変えることなく削除できます。 | |
3314 | ||
3927 | ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>, | |
3928 | L<C<each>|/each HASH> が繰り返し同じ順序で | |
3929 | 返すことに依存してもかまいません。 | |
3930 | なぜハッシュの順序がランダム化されているかの詳細については | |
3931 | L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。 | |
3932 | ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の | |
3933 | 正確な詳細は Perl のリリースによって変更される可能性があります。 | |
3315 | 3934 | |
3316 | 3935 | =begin original |
3317 | 3936 | |
3318 | After C<each> has returned all entries from the hash or | |
3937 | After L<C<each>|/each HASH> has returned all entries from the hash or | |
3319 | call to C<each> returns the empty list | |
3938 | array, the next call to L<C<each>|/each HASH> returns the empty list in | |
3320 | ||
3939 | list context and L<C<undef>|/undef EXPR> in scalar context; the next | |
3321 | ||
3940 | call following I<that> one restarts iteration. Each hash or array has | |
3322 | ||
3941 | its own internal iterator, accessed by L<C<each>|/each HASH>, | |
3323 | ||
3942 | L<C<keys>|/keys HASH>, and L<C<values>|/values HASH>. The iterator is | |
3324 | ||
3943 | implicitly reset when L<C<each>|/each HASH> has reached the end as just | |
3325 | ||
3944 | described; it can be explicitly reset by calling L<C<keys>|/keys HASH> | |
3326 | ||
3945 | or L<C<values>|/values HASH> on the hash or array. If you add or delete | |
3327 | ||
3946 | a hash's elements while iterating over it, the effect on the iterator is | |
3947 | unspecified; for example, entries may be skipped or duplicated--so don't | |
3948 | do that. Exception: It is always safe to delete the item most recently | |
3949 | returned by L<C<each>|/each HASH>, so the following code works properly: | |
3328 | 3950 | |
3329 | 3951 | =end original |
3330 | 3952 | |
3331 | C<each> がハッシュをすべて読み込んでしまった後、 | |
3953 | L<C<each>|/each HASH> がハッシュをすべて読み込んでしまった後、 | |
3332 | ||
3954 | 次の L<C<each>|/each HASH> 呼び出しでは、リストコンテキストでは空リストが | |
3333 | ||
3955 | 返され、スカラコンテキストでは L<C<undef>|/undef EXPR> が返されます; | |
3334 | ||
3956 | I<そのあと> もう一度呼び出すと、再び反復を始めます。 | |
3335 | ||
3957 | ハッシュや配列毎にそれぞれ反復子があり、L<C<each>|/each HASH>、 | |
3336 | ||
3958 | L<C<keys>|/keys HASH>、L<C<values>|/values HASH> でアクセスされます。 | |
3337 | ||
3959 | 反復子は、前述したように L<C<each>|/each HASH> が要素をすべて読むことによって | |
3338 | C<keys | |
3960 | 暗黙にリセットされます; また、ハッシュや配列に対して L<C<keys>|/keys HASH>, | |
3961 | L<C<values>|/values HASH> を呼び出すことで明示的にリセットできます。 | |
3339 | 3962 | 繰り返しを行なっている間に、ハッシュに要素を追加したり削除したりすると、 |
3340 | 要素が飛ばされたり重複したり | |
3963 | 反復子の動作は未定義です; 例えば、要素が飛ばされたり重複したりします-- | |
3341 | ||
3964 | 従って、してはいけません。 | |
3342 | ||
3965 | 例外: 一番最近に L<C<each>|/each HASH> から返されたものを削除するのは常に | |
3966 | 安全です; これは以下のようなコードが正しく動くことを意味します: | |
3343 | 3967 | |
3344 | | |
3968 | while (my ($key, $value) = each %hash) { | |
3345 | | |
3969 | print $key, "\n"; | |
3346 | | |
3970 | delete $hash{$key}; # This is safe | |
3347 | | |
3971 | } | |
3348 | 3972 | |
3349 | 3973 | =begin original |
3350 | 3974 | |
3351 | T | |
3975 | Tied hashes may have a different ordering behaviour to perl's hash | |
3976 | implementation. | |
3977 | ||
3978 | =end original | |
3979 | ||
3980 | tie されたハッシュは、順序に関して Perl のハッシュと異なった振る舞いをします。 | |
3981 | ||
3982 | =begin original | |
3983 | ||
3984 | This prints out your environment like the L<printenv(1)> program, | |
3352 | 3985 | but in a different order: |
3353 | 3986 | |
3354 | 3987 | =end original |
3355 | 3988 | |
3356 | これは、printenv(1) プログラムのように環境変数を表示しますが、 | |
3989 | これは、L<printenv(1)> プログラムのように環境変数を表示しますが、 | |
3357 | 3990 | 順序は異なっています: |
3358 | 3991 | |
3359 | while (($key,$value) = each %ENV) { | |
3992 | while (my ($key,$value) = each %ENV) { | |
3360 | 3993 | print "$key=$value\n"; |
3361 | 3994 | } |
3362 | 3995 | |
3363 | 3996 | =begin original |
3364 | 3997 | |
3365 | Starting with Perl 5.14, | |
3998 | Starting with Perl 5.14, an experimental feature allowed | |
3366 | ||
3999 | L<C<each>|/each HASH> to take a scalar expression. This experiment has | |
3367 | ||
4000 | been deemed unsuccessful, and was removed as of Perl 5.24. | |
3368 | The exact behaviour may change in a future version of Perl. | |
3369 | 4001 | |
3370 | 4002 | =end original |
3371 | 4003 | |
3372 | Perl 5.14 から、C<each> | |
4004 | Perl 5.14 から、L<C<each>|/each HASH> がスカラ式を取ることが出来るという | |
3373 | ||
4005 | 実験的機能がありました。 | |
3374 | ||
4006 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 | |
3375 | C<each> のこの動作は高度に実験的であると考えられています。 | |
3376 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 | |
3377 | 4007 | |
3378 | ||
4008 | =begin original | |
3379 | 4009 | |
4010 | As of Perl 5.18 you can use a bare L<C<each>|/each HASH> in a C<while> | |
4011 | loop, which will set L<C<$_>|perlvar/$_> on every iteration. | |
4012 | ||
4013 | =end original | |
4014 | ||
4015 | Perl 5.18 から C<while> ループの中に裸の L<C<each>|/each HASH> を書けます; | |
4016 | これは繰り返し毎に L<C<$_>|perlvar/$_> を設定します。 | |
4017 | ||
4018 | while (each %ENV) { | |
4019 | print "$_=$ENV{$_}\n"; | |
4020 | } | |
4021 | ||
3380 | 4022 | =begin original |
3381 | 4023 | |
3382 | ||
4024 | To avoid confusing would-be users of your code who are running earlier | |
4025 | versions of Perl with mysterious syntax errors, put this sort of thing at | |
4026 | the top of your file to signal that your code will work I<only> on Perls of | |
4027 | a recent vintage: | |
3383 | 4028 | |
3384 | 4029 | =end original |
3385 | 4030 | |
3386 | ||
4031 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な | |
4032 | 文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で | |
4033 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを | |
4034 | 書いてください: | |
3387 | 4035 | |
4036 | use 5.012; # so keys/values/each work on arrays | |
4037 | use 5.018; # so each assigns to $_ in a lone while test | |
4038 | ||
4039 | =begin original | |
4040 | ||
4041 | See also L<C<keys>|/keys HASH>, L<C<values>|/values HASH>, and | |
4042 | L<C<sort>|/sort SUBNAME LIST>. | |
4043 | ||
4044 | =end original | |
4045 | ||
4046 | L<C<keys>|/keys HASH> や L<C<values>|/values HASH> や | |
4047 | L<C<sort>|/sort SUBNAME LIST> も参照してください。 | |
4048 | ||
3388 | 4049 | =item eof FILEHANDLE |
3389 | 4050 | X<eof> |
3390 | 4051 | X<end of file> |
3391 | 4052 | X<end-of-file> |
3392 | 4053 | |
3393 | 4054 | =item eof () |
3394 | 4055 | |
3395 | 4056 | =item eof |
3396 | 4057 | |
4058 | =for Pod::Functions test a filehandle for its end | |
4059 | ||
3397 | 4060 | =begin original |
3398 | 4061 | |
3399 | 4062 | Returns 1 if the next read on FILEHANDLE will return end of file I<or> if |
3400 | 4063 | FILEHANDLE is not open. FILEHANDLE may be an expression whose value |
3401 | 4064 | gives the real filehandle. (Note that this function actually |
3402 | 4065 | reads a character and then C<ungetc>s it, so isn't useful in an |
3403 | 4066 | interactive context.) Do not read from a terminal file (or call |
3404 | 4067 | C<eof(FILEHANDLE)> on it) after end-of-file is reached. File types such |
3405 | 4068 | as terminals may lose the end-of-file condition if you do. |
3406 | 4069 | |
3407 | 4070 | =end original |
3408 | 4071 | |
3409 | 4072 | 次に FILEHANDLE 上で読み込みを行なったときに、EOF が返されるときか、 |
3410 | 4073 | I<または> FILEHANDLE がオープンされていないと、1 を返します。 |
3411 | 4074 | FILEHANDLE は、値が実際のファイルハンドルを示す式であってもかまいません。 |
3412 | 4075 | (この関数は、実際に文字を読み、C<ungetc> を行ないますので、 |
3413 | 4076 | 対話型の場合には有用ではありません。) |
3414 | 4077 | 端末ファイルは EOF に達した後にさらに読み込んだり C<eof(FILEHANDLE)> を |
3415 | 4078 | 呼び出したりしてはいけません。 |
3416 | 4079 | そのようなことをすると、端末のようなファイルタイプは |
3417 | 4080 | EOF 状態を失ってしまうかもしれません。 |
3418 | 4081 | |
3419 | 4082 | =begin original |
3420 | 4083 | |
3421 | An C<eof> without an argument uses the last file | |
4084 | An L<C<eof>|/eof FILEHANDLE> without an argument uses the last file | |
3422 | with empty parentheses is | |
4085 | read. Using L<C<eof()>|/eof FILEHANDLE> with empty parentheses is | |
3423 | f | |
4086 | different. It refers to the pseudo file formed from the files listed on | |
3424 | C<< <> >> operator. Since | |
4087 | the command line and accessed via the C<< <> >> operator. Since | |
3425 | as a normal filehandle is, a | |
4088 | C<< <> >> isn't explicitly opened, as a normal filehandle is, an | |
3426 | ||
4089 | L<C<eof()>|/eof FILEHANDLE> before C<< <> >> has been used will cause | |
3427 | ||
4090 | L<C<@ARGV>|perlvar/@ARGV> to be examined to determine if input is | |
3428 | ||
4091 | available. Similarly, an L<C<eof()>|/eof FILEHANDLE> after C<< <> >> | |
3429 | and | |
4092 | has returned end-of-file will assume you are processing another | |
3430 | ||
4093 | L<C<@ARGV>|perlvar/@ARGV> list, and if you haven't set | |
4094 | L<C<@ARGV>|perlvar/@ARGV>, will read input from C<STDIN>; see | |
4095 | L<perlop/"I/O Operators">. | |
3431 | 4096 | |
3432 | 4097 | =end original |
3433 | 4098 | |
3434 | 引数を省略した C<eof> は、最後に読み込みを行なった | |
4099 | 引数を省略した L<C<eof>|/eof FILEHANDLE> は、最後に読み込みを行なった | |
3435 | ||
4100 | ファイルを使います。 | |
4101 | 空の括弧をつけた L<C<eof()>|/eof FILEHANDLE> は異なります。 | |
3436 | 4102 | これはコマンドラインのファイルリストで構成され、C<< <> >> 演算子経由で |
3437 | 4103 | アクセスされる擬似ファイルを示すために用いられます。 |
3438 | 4104 | 通常のファイルハンドルと違って C<< <> >> は明示的にオープンされないので、 |
3439 | C<< <> >> を使う前に C<eof()> を使うと、 | |
4105 | C<< <> >> を使う前に L<C<eof()>|/eof FILEHANDLE> を使うと、 | |
3440 | 入力が正常か確認するために C<@ARGV> がテストされます。 | |
4106 | 入力が正常か確認するために L<C<@ARGV>|perlvar/@ARGV> がテストされます。 | |
3441 | 同様に、C<< <> >> が EOF を返した後の C<eof()> は、 | |
4107 | 同様に、C<< <> >> が EOF を返した後の L<C<eof()>|/eof FILEHANDLE> は、 | |
3442 | 他の C<@ARGV> リストを処理していると仮定し、もし | |
4108 | 他の L<C<@ARGV>|perlvar/@ARGV> リストを処理していると仮定し、もし | |
3443 | セットしていないときは C<STDIN> から読み込みます; | |
4109 | L<C<@ARGV>|perlvar/@ARGV> をセットしていないときは C<STDIN> から読み込みます; | |
3444 | 4110 | L<perlop/"I/O Operators"> を参照してください。 |
3445 | 4111 | |
3446 | 4112 | =begin original |
3447 | 4113 | |
3448 | In a C<< while (<>) >> loop, C<eof> or C<eof(ARGV)> | |
4114 | In a C<< while (<>) >> loop, L<C<eof>|/eof FILEHANDLE> or C<eof(ARGV)> | |
3449 | detect the end of each file, whereas | |
4115 | can be used to detect the end of each file, whereas | |
3450 | of the very last file | |
4116 | L<C<eof()>|/eof FILEHANDLE> will detect the end of the very last file | |
4117 | only. Examples: | |
3451 | 4118 | |
3452 | 4119 | =end original |
3453 | 4120 | |
3454 | 4121 | C<< while (<>) >> ループの中では、個々のファイルの終わりを調べるには、 |
3455 | C<eof> か C<eof(ARGV)> を用いるのに対して | |
4122 | L<C<eof>|/eof FILEHANDLE> か C<eof(ARGV)> を用いるのに対して | |
3456 | C<eof()> は最後のファイルの終わりのみを調べます。 | |
4123 | L<C<eof()>|/eof FILEHANDLE> は最後のファイルの終わりのみを調べます。 | |
3457 | 4124 | 例: |
3458 | 4125 | |
3459 | 4126 | # reset line numbering on each input file |
3460 | 4127 | while (<>) { |
3461 | 4128 | next if /^\s*#/; # skip comments |
3462 | 4129 | print "$.\t$_"; |
3463 | 4130 | } continue { |
3464 | 4131 | close ARGV if eof; # Not eof()! |
3465 | 4132 | } |
3466 | 4133 | |
3467 | 4134 | # insert dashes just before last line of last file |
3468 | 4135 | while (<>) { |
3469 | 4136 | if (eof()) { # check for end of last file |
3470 | 4137 | print "--------------\n"; |
3471 | 4138 | } |
3472 | 4139 | print; |
3473 | last if eof(); | |
4140 | last if eof(); # needed if we're reading from a terminal | |
3474 | 4141 | } |
3475 | 4142 | |
3476 | 4143 | =begin original |
3477 | 4144 | |
3478 | Practical hint: you almost never need to use C<eof> | |
4145 | Practical hint: you almost never need to use L<C<eof>|/eof FILEHANDLE> | |
3479 | input operators typically return C<undef> | |
4146 | in Perl, because the input operators typically return L<C<undef>|/undef | |
3480 | encounter an error. | |
4147 | EXPR> when they run out of data or encounter an error. | |
3481 | 4148 | |
3482 | 4149 | =end original |
3483 | 4150 | |
3484 | 現実的なヒント: Perl で C<eof> が必要となることは、 | |
4151 | 現実的なヒント: Perl で L<C<eof>|/eof FILEHANDLE> が必要となることは、 | |
4152 | ほとんどありません; | |
3485 | 4153 | 基本的には、データがなくなったときやエラーがあったときに、入力演算子が |
3486 | C<undef> を返してくれるからです。 | |
4154 | L<C<undef>|/undef EXPR> を返してくれるからです。 | |
3487 | 4155 | |
3488 | 4156 | =item eval EXPR |
3489 | 4157 | X<eval> X<try> X<catch> X<evaluate> X<parse> X<execute> |
3490 | 4158 | X<error, handling> X<exception, handling> |
3491 | 4159 | |
3492 | 4160 | =item eval BLOCK |
3493 | 4161 | |
3494 | 4162 | =item eval |
3495 | 4163 | |
4164 | =for Pod::Functions catch exceptions or compile and run code | |
4165 | ||
3496 | 4166 | =begin original |
3497 | 4167 | |
3498 | In the first form, t | |
4168 | In the first form, often referred to as a "string eval", the return | |
4169 | value of EXPR is parsed and executed as if it | |
3499 | 4170 | were a little Perl program. The value of the expression (which is itself |
3500 | 4171 | determined within scalar context) is first parsed, and if there were no |
3501 | errors, executed in the lexical context of the current Perl | |
4172 | errors, executed as a block within the lexical context of the current Perl | |
3502 | ||
4173 | program. This means, that in particular, any outer lexical variables are | |
3503 | ||
4174 | visible to it, and any package variable settings or subroutine and format | |
3504 | ||
4175 | definitions remain afterwards. | |
3505 | delay parsing and subsequent execution of the text of EXPR until run time. | |
3506 | 4176 | |
3507 | 4177 | =end original |
3508 | 4178 | |
3509 | 第一の形式では、EXPR の返り値が | |
4179 | 第一の形式(しばしば「文字列 eval」として参照されます)では、EXPR の返り値が | |
3510 | 解析され、実行されます。 | |
4180 | Perl のプログラムであるかのように解析され、実行されます。 | |
3511 | 4181 | 式の値(それ自身スカラコンテキストの中で決定されます)はまずパースされ、 |
3512 | エラーがなければ | |
4182 | エラーがなければ Perl プログラムのレキシカルコンテキストの中のブロックとして | |
3513 | ||
4183 | 実行されます。 | |
3514 | ||
4184 | これは、特に、外側のレキシカル変数は見えていて、パッケージ変数の設定や | |
3515 | ||
4185 | サブルーチンやフォーマットの定義はその後も残っているということです。 | |
3516 | ||
4187 | =begin original | |
4188 | ||
4189 | Note that the value is parsed every time the L<C<eval>|/eval EXPR> | |
4190 | executes. If EXPR is omitted, evaluates L<C<$_>|perlvar/$_>. This form | |
4191 | is typically used to delay parsing and subsequent execution of the text | |
4192 | of EXPR until run time. | |
4193 | ||
4194 | =end original | |
4195 | ||
4196 | 返される値は L<C<eval>|/eval EXPR> が実行されるごとにパースされることに | |
4197 | 注意してください。 | |
4198 | EXPR が省略されると、L<C<$_>|perlvar/$_> を評価します。 | |
3517 | 4199 | この形は主に EXPR のテキストのパースと実行を実行時にまで |
3518 | 4200 | 遅延させるのに用います。 |
3519 | 4201 | |
3520 | 4202 | =begin original |
3521 | 4203 | |
4204 | If the | |
4205 | L<C<"unicode_eval"> feature|feature/The 'unicode_eval' and 'evalbytes' features> | |
4206 | is enabled (which is the default under a | |
4207 | C<use 5.16> or higher declaration), EXPR or L<C<$_>|perlvar/$_> is | |
4208 | treated as a string of characters, so L<C<use utf8>|utf8> declarations | |
4209 | have no effect, and source filters are forbidden. In the absence of the | |
4210 | L<C<"unicode_eval"> feature|feature/The 'unicode_eval' and 'evalbytes' features>, | |
4211 | will sometimes be treated as characters and sometimes as bytes, | |
4212 | depending on the internal encoding, and source filters activated within | |
4213 | the L<C<eval>|/eval EXPR> exhibit the erratic, but historical, behaviour | |
4214 | of affecting some outer file scope that is still compiling. See also | |
4215 | the L<C<evalbytes>|/evalbytes EXPR> operator, which always treats its | |
4216 | input as a byte stream and works properly with source filters, and the | |
4217 | L<feature> pragma. | |
4218 | ||
4219 | =end original | |
4220 | ||
4221 | L<C<"unicode_eval"> 機能|feature/The 'unicode_eval' and 'evalbytes' features> | |
4222 | が有効の場合(これは C<use 5.16> またはそれ以上が | |
4223 | 宣言されている場合はデフォルトです)、EXPR や L<C<$_>|perlvar/$_> は文字単位の | |
4224 | 文字列として扱われるので、L<C<use utf8>|utf8> 宣言は無効で、ソースフィルタは | |
4225 | 禁止されます。 | |
4226 | L<C<"unicode_eval"> 機能|feature/The 'unicode_eval' and 'evalbytes' features> | |
4227 | がなければ、内部エンコーディングに依存して | |
4228 | 時々文字単位として扱われ、時々バイト単位で扱われます; そして | |
4229 | L<C<eval>|/eval EXPR> の中で有効になったソースフィルタは、まだ | |
4230 | コンパイル中である一部の外側のファイルスコープに影響を与えるという、 | |
4231 | 間違っているけれども歴史的な振る舞いを見せます。 | |
4232 | 入力を常にバイト列として扱い、ソースフィルタが適切に動作する | |
4233 | L<C<evalbytes>|/evalbytes EXPR> 演算子および L<feature> プラグマを | |
4234 | 参照してください。 | |
4235 | ||
4236 | =begin original | |
4237 | ||
4238 | Problems can arise if the string expands a scalar containing a floating | |
4239 | point number. That scalar can expand to letters, such as C<"NaN"> or | |
4240 | C<"Infinity">; or, within the scope of a L<C<use locale>|locale>, the | |
4241 | decimal point character may be something other than a dot (such as a | |
4242 | comma). None of these are likely to parse as you are likely expecting. | |
4243 | ||
4244 | =end original | |
4245 | ||
4246 | 文字列をが小数点を含むスカラを展開するときに問題が起こることがあります。 | |
4247 | そのようなスカラは C<"NaN"> や C<"Infinity"> のような文字に | |
4248 | 展開されることがあります; または、L<C<use locale>|locale> のスコープの中では、 | |
4249 | 小数点文字は (カンマのような) ドット以外の文字かもしれません。 | |
4250 | これらはどれもあなたがおそらく予測しているようにはパースされません。 | |
4251 | ||
4252 | =begin original | |
4253 | ||
3522 | 4254 | In the second form, the code within the BLOCK is parsed only once--at the |
3523 | same time the code surrounding the C<eval> itself was | |
4255 | same time the code surrounding the L<C<eval>|/eval EXPR> itself was | |
4256 | parsed--and executed | |
3524 | 4257 | within the context of the current Perl program. This form is typically |
3525 | 4258 | used to trap exceptions more efficiently than the first (see below), while |
3526 | 4259 | also providing the benefit of checking the code within BLOCK at compile |
3527 | 4260 | time. |
3528 | 4261 | |
3529 | 4262 | =end original |
3530 | 4263 | |
3531 | 4264 | 第二の形式では、BLOCK 内部のコードは一度だけパースされ -- コードを |
3532 | 囲む C<eval> 自身がパースされるのと同じ時点です -- 現在 | |
4265 | 囲む L<C<eval>|/eval EXPR> 自身がパースされるのと同じ時点です -- 現在の | |
3533 | コンテキストで実行されます。 | |
4266 | Perl プログラムのコンテキストで実行されます。 | |
3534 | この形式は典型的には第一の形式より効率的に例外をトラップします(後述) | |
4267 | この形式は典型的には第一の形式より効率的に例外をトラップします(後述); | |
3535 | 4268 | また BLOCK 内部のコードはコンパイル時にチェックされるという利点を提供します。 |
3536 | 4269 | |
3537 | 4270 | =begin original |
3538 | 4271 | |
3539 | 4272 | The final semicolon, if any, may be omitted from the value of EXPR or within |
3540 | 4273 | the BLOCK. |
3541 | 4274 | |
3542 | 4275 | =end original |
3543 | 4276 | |
3544 | 最後のセミコロンは、もしあれば、EXPR の値や BLOCK の中身から | |
4277 | 最後のセミコロンは、もしあれば、EXPR の値や BLOCK の中身から | |
4278 | 省くことができます。 | |
3545 | 4279 | |
3546 | 4280 | =begin original |
3547 | 4281 | |
3548 | 4282 | In both forms, the value returned is the value of the last expression |
3549 | 4283 | evaluated inside the mini-program; a return statement may be also used, just |
3550 | 4284 | as with subroutines. The expression providing the return value is evaluated |
3551 | in void, scalar, or list context, depending on the context of the | |
4285 | in void, scalar, or list context, depending on the context of the | |
3552 | itself. See L</wantarray> for more | |
4286 | L<C<eval>|/eval EXPR> itself. See L<C<wantarray>|/wantarray> for more | |
3553 | determined. | |
4287 | on how the evaluation context can be determined. | |
3554 | 4288 | |
3555 | 4289 | =end original |
3556 | 4290 | |
3557 | 4291 | どちらの形式でも、返される値はミニプログラムの内部で最後に評価された |
3558 | 4292 | 表現の値です; サブルーチンと同様、return 文も使えます。 |
3559 | 返り値として提供される表現は、C<eval> 自身のコンテキストに | |
4293 | 返り値として提供される表現は、L<C<eval>|/eval EXPR> 自身のコンテキストに | |
3560 | 無効・スカラ・リストのいずれかのコンテキストで評価されます。 | |
4294 | 依存して無効・スカラ・リストのいずれかのコンテキストで評価されます。 | |
3561 | 評価コンテキストの決定方法についての詳細は L</wantarray> を | |
4295 | 評価コンテキストの決定方法についての詳細は L<C<wantarray>|/wantarray> を | |
4296 | 参照してください。 | |
3562 | 4297 | |
3563 | 4298 | =begin original |
3564 | 4299 | |
3565 | If there is a syntax error or runtime error, or a C<die> | |
4300 | If there is a syntax error or runtime error, or a L<C<die>|/die LIST> | |
3566 | executed, C<eval> returns | |
4301 | statement is executed, L<C<eval>|/eval EXPR> returns | |
3567 | ||
4302 | L<C<undef>|/undef EXPR> in scalar context or an empty list in list | |
3568 | ||
4303 | context, and L<C<$@>|perlvar/$@> is set to the error message. (Prior to | |
3569 | ||
4304 | 5.16, a bug caused L<C<undef>|/undef EXPR> to be returned in list | |
3570 | con | |
4305 | context for syntax errors, but not for runtime errors.) If there was no | |
3571 | ||
4306 | error, L<C<$@>|perlvar/$@> is set to the empty string. A control flow | |
3572 | ||
4307 | operator like L<C<last>|/last LABEL> or L<C<goto>|/goto LABEL> can | |
3573 | ||
4308 | bypass the setting of L<C<$@>|perlvar/$@>. Beware that using | |
3574 | ||
4309 | L<C<eval>|/eval EXPR> neither silences Perl from printing warnings to | |
3575 | ||
4310 | STDERR, nor does it stuff the text of warning messages into | |
3576 | ||
4311 | L<C<$@>|perlvar/$@>. To do either of those, you have to use the | |
4312 | L<C<$SIG{__WARN__}>|perlvar/%SIG> facility, or turn off warnings inside | |
4313 | the BLOCK or EXPR using S<C<no warnings 'all'>>. See | |
4314 | L<C<warn>|/warn LIST>, L<perlvar>, and L<warnings>. | |
3577 | 4315 | |
3578 | 4316 | =end original |
3579 | 4317 | |
3580 | 構文エラーや実行エラーが発生するか、C<die> 文が実行されると、 | |
4318 | 構文エラーや実行エラーが発生するか、L<C<die>|/die LIST> 文が実行されると、 | |
3581 | C<eval> はスカラコンテキストでは C<undef> が、 | |
4319 | L<C<eval>|/eval EXPR> はスカラコンテキストでは L<C<undef>|/undef EXPR> が、 | |
3582 | ||
4320 | リストコンテキストでは空リストが設定され、 | |
3583 | ||
4321 | L<C<$@>|perlvar/$@> にエラーメッセージが設定されます。 | |
3584 | リストコンテキストでの | |
4322 | (5.16 以前では、バグによって、リストコンテキストで構文エラーの時には | |
3585 | ||
4323 | L<C<undef>|/undef EXPR> を返していましたが、実行エラーの時には | |
3586 | ||
4324 | 返していませんでした。) | |
3587 | C<eva | |
4325 | エラーがなければ、L<C<$@>|perlvar/$@> は空文字列に設定されます。 | |
3588 | ||
4326 | L<C<last>|/last LABEL> や L<C<goto>|/goto LABEL> のようなフロー制御演算子は | |
3589 | ||
4327 | L<C<$@>|perlvar/$@> の設定を回避できます。 | |
4328 | L<C<eval>|/eval EXPR> を、STDERR に警告メッセージを表示させない目的や、 | |
4329 | 警告メッセージを L<C<$@>|perlvar/$@> に格納する目的では使わないでください。 | |
4330 | そのような用途では、L<C<$SIG{__WARN__}>|perlvar/%SIG> 機能を使うか、 | |
3590 | 4331 | S<C<no warnings 'all'>> を使って BLOCK か EXPR の内部での警告を |
3591 | 4332 | オフにする必要があります。 |
3592 | L</warn>, L<perlvar>, L<warnings | |
4333 | L<C<warn>|/warn LIST>, L<perlvar>, L<warnings> を参照してください。 | |
3593 | 4334 | |
3594 | 4335 | =begin original |
3595 | 4336 | |
3596 | Note that, because C<eval> traps otherwise-fatal errors, | |
4337 | Note that, because L<C<eval>|/eval EXPR> traps otherwise-fatal errors, | |
3597 | determining whether a particular feature (such as | |
4338 | it is useful for determining whether a particular feature (such as | |
3598 | ||
4339 | L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL> or | |
3599 | ||
4340 | L<C<symlink>|/symlink OLDFILE,NEWFILE>) is implemented. It is also | |
4341 | Perl's exception-trapping mechanism, where the L<C<die>|/die LIST> | |
4342 | operator is used to raise exceptions. | |
3600 | 4343 | |
3601 | 4344 | =end original |
3602 | 4345 | |
3603 | C<eval> は、致命的エラーとなるようなものを | |
4346 | L<C<eval>|/eval EXPR> は、致命的エラーとなるようなものを | |
3604 | ||
4347 | トラップすることができるので、 | |
4348 | (L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL> や | |
4349 | L<C<symlink>|/symlink OLDFILE,NEWFILE> といった) 特定の機能が | |
4350 | 実装されているかを、 | |
3605 | 4351 | 調べるために使うことができることに注意してください。 |
3606 | die 演算子が例外を発生させるものとすれば、これはまた、 | |
4352 | L<C<die>|/die LIST> 演算子が例外を発生させるものとすれば、これはまた、 | |
3607 | 捉えることもできます。 | |
4353 | Perl の例外捕捉機能と捉えることもできます。 | |
3608 | 4354 | |
3609 | 4355 | =begin original |
3610 | 4356 | |
3611 | 4357 | If you want to trap errors when loading an XS module, some problems with |
3612 | 4358 | the binary interface (such as Perl version skew) may be fatal even with |
3613 | C<eval> unless C<$ENV{PERL_DL_NONLAZY}> is set. See | |
4359 | L<C<eval>|/eval EXPR> unless C<$ENV{PERL_DL_NONLAZY}> is set. See | |
4360 | L<perlrun>. | |
3614 | 4361 | |
3615 | 4362 | =end original |
3616 | 4363 | |
3617 | 4364 | XS モジュールのロード中のエラーをトラップしたいなら、 |
3618 | 4365 | (Perl バージョンの違いのような) バイナリインターフェースに関する問題に |
3619 | ついては C<$ENV{PERL_DL_NONLAZY}> がセットされていない | |
4366 | ついては C<$ENV{PERL_DL_NONLAZY}> がセットされていない | |
3620 | 致命的エラーになるかもしれません。 | |
4367 | L<C<eval>|/eval EXPR> でも致命的エラーになるかもしれません。 | |
3621 | 4368 | L<perlrun> を参照してください。 |
3622 | 4369 | |
3623 | 4370 | =begin original |
3624 | 4371 | |
3625 | 4372 | If the code to be executed doesn't vary, you may use the eval-BLOCK |
3626 | 4373 | form to trap run-time errors without incurring the penalty of |
3627 | recompiling each time. The error, if any, is still returned in | |
4374 | recompiling each time. The error, if any, is still returned in | |
4375 | L<C<$@>|perlvar/$@>. | |
3628 | 4376 | Examples: |
3629 | 4377 | |
3630 | 4378 | =end original |
3631 | 4379 | |
3632 | 4380 | 実行するコードが変わらないのであれば、毎回多量の再コンパイルすることなしに、 |
3633 | 4381 | 実行時エラーのトラップを行なうために、 |
3634 | 4382 | eval-BLOCK 形式を使うことができます。 |
3635 | エラーがあれば、やはり $@ に返されます。 | |
4383 | エラーがあれば、やはり L<C<$@>|perlvar/$@> に返されます。 | |
3636 | 4384 | 例: |
3637 | 4385 | |
3638 | 4386 | # make divide-by-zero nonfatal |
3639 | 4387 | eval { $answer = $a / $b; }; warn $@ if $@; |
3640 | 4388 | |
3641 | 4389 | # same thing, but less efficient |
3642 | 4390 | eval '$answer = $a / $b'; warn $@ if $@; |
3643 | 4391 | |
3644 | 4392 | # a compile-time error |
3645 | 4393 | eval { $answer = }; # WRONG |
3646 | 4394 | |
3647 | 4395 | # a run-time error |
3648 | 4396 | eval '$answer ='; # sets $@ |
3649 | 4397 | |
3650 | 4398 | =begin original |
3651 | 4399 | |
3652 | Using the C<eval{}> form as an exception trap in libraries does have some | |
4400 | Using the C<eval {}> form as an exception trap in libraries does have some | |
3653 | 4401 | issues. Due to the current arguably broken state of C<__DIE__> hooks, you |
3654 | 4402 | may wish not to trigger any C<__DIE__> hooks that user code may have installed. |
3655 | 4403 | You can use the C<local $SIG{__DIE__}> construct for this purpose, |
3656 | 4404 | as this example shows: |
3657 | 4405 | |
3658 | 4406 | =end original |
3659 | 4407 | |
3660 | 4408 | C<eval{}> 形式をライブラリの例外を捕捉するために使うときには |
3661 | 4409 | 問題があります。 |
3662 | 4410 | 現在の C<__DIE__> フックの状態はほぼ確実に壊れているという理由で、 |
3663 | 4411 | ユーザーのコードが設定した C<__DIE__> フックを実行したくないかもしれません。 |
3664 | 4412 | この目的には以下の例のように、C<local $SIG{__DIE__}> 構造が使えます。 |
3665 | 4413 | |
3666 | 4414 | # a private exception trap for divide-by-zero |
3667 | 4415 | eval { local $SIG{'__DIE__'}; $answer = $a / $b; }; |
3668 | 4416 | warn $@ if $@; |
3669 | 4417 | |
3670 | 4418 | =begin original |
3671 | 4419 | |
3672 | 4420 | This is especially significant, given that C<__DIE__> hooks can call |
3673 | C<die> again, which has the effect of changing their error | |
4421 | L<C<die>|/die LIST> again, which has the effect of changing their error | |
4422 | messages: | |
3674 | 4423 | |
3675 | 4424 | =end original |
3676 | 4425 | |
3677 | これは特に顕著です | |
4426 | これは特に顕著です; 与えられた C<__DIE__> フックは L<C<die>|/die LIST> を | |
3678 | 呼び出すことができ、これによってエラーメッセージを変える | |
4427 | もう一度呼び出すことができ、これによってエラーメッセージを変える | |
4428 | 効果があります: | |
3679 | 4429 | |
3680 | 4430 | # __DIE__ hooks may modify error messages |
3681 | 4431 | { |
3682 | 4432 | local $SIG{'__DIE__'} = |
3683 | 4433 | sub { (my $x = $_[0]) =~ s/foo/bar/g; die $x }; |
3684 | 4434 | eval { die "foo lives here" }; |
3685 | 4435 | print $@ if $@; # prints "bar lives here" |
3686 | 4436 | } |
3687 | 4437 | |
3688 | 4438 | =begin original |
3689 | 4439 | |
3690 | 4440 | Because this promotes action at a distance, this counterintuitive behavior |
3691 | 4441 | may be fixed in a future release. |
3692 | 4442 | |
3693 | 4443 | =end original |
3694 | 4444 | |
3695 | 4445 | これは距離の離れた行動であるため、この直感的でない振る舞いは |
3696 | 4446 | 将来のリリースでは修正されるかもしれません。 |
3697 | 4447 | |
3698 | 4448 | =begin original |
3699 | 4449 | |
3700 | With an C<eval>, you should be especially careful to | |
4450 | With an L<C<eval>|/eval EXPR>, you should be especially careful to | |
3701 | being looked at when: | |
4451 | remember what's being looked at when: | |
3702 | 4452 | |
3703 | 4453 | =end original |
3704 | 4454 | |
3705 | C<eval> では、以下のような場合に、 | |
4455 | L<C<eval>|/eval EXPR> では、以下のような場合に、 | |
3706 | 4456 | 何が調べられるかに特に注意しておくことが必要です: |
3707 | 4457 | |
3708 | 4458 | eval $x; # CASE 1 |
3709 | 4459 | eval "$x"; # CASE 2 |
3710 | 4460 | |
3711 | 4461 | eval '$x'; # CASE 3 |
3712 | 4462 | eval { $x }; # CASE 4 |
3713 | 4463 | |
3714 | 4464 | eval "\$$x++"; # CASE 5 |
3715 | 4465 | $$x++; # CASE 6 |
3716 | 4466 | |
3717 | 4467 | =begin original |
3718 | 4468 | |
3719 | 4469 | Cases 1 and 2 above behave identically: they run the code contained in |
3720 | 4470 | the variable $x. (Although case 2 has misleading double quotes making |
3721 | 4471 | the reader wonder what else might be happening (nothing is).) Cases 3 |
3722 | 4472 | and 4 likewise behave in the same way: they run the code C<'$x'>, which |
3723 | 4473 | does nothing but return the value of $x. (Case 4 is preferred for |
3724 | 4474 | purely visual reasons, but it also has the advantage of compiling at |
3725 | 4475 | compile-time instead of at run-time.) Case 5 is a place where |
3726 | 4476 | normally you I<would> like to use double quotes, except that in this |
3727 | 4477 | particular situation, you can just use symbolic references instead, as |
3728 | 4478 | in case 6. |
3729 | 4479 | |
3730 | 4480 | =end original |
3731 | 4481 | |
3732 | 4482 | 上記の CASE 1 と CASE 2 の動作は同一で、変数 $x 内の |
3733 | 4483 | コードを実行します。 |
3734 | 4484 | (ただし、CASE 2 では、必要のないダブルクォートによって、 |
3735 | 4485 | 読む人が何が起こるか混乱することでしょう (何も起こりませんが)。) |
3736 | 4486 | 同様に CASE 3 と CASE 4 の動作も等しく、$x の値を返す以外に |
3737 | 4487 | 何もしない C<$x> というコードを実行します |
3738 | 4488 | (純粋に見た目の問題で、CASE 4 が好まれますが、 |
3739 | 4489 | 実行時でなくコンパイル時にコンパイルされるという利点もあります)。 |
3740 | CASE 5 の場合は、通常ダブルクォートを使用します | |
4490 | CASE 5 の場合は、通常ダブルクォートを使用 I<します>; | |
3741 | 4491 | この状況を除けば、CASE 6 のように、単に |
3742 | 4492 | シンボリックリファレンスを使えば良いでしょう。 |
3743 | 4493 | |
3744 | 4494 | =begin original |
3745 | 4495 | |
3746 | Before Perl 5.14, the assignment to C<$@> occurred before | |
4496 | Before Perl 5.14, the assignment to L<C<$@>|perlvar/$@> occurred before | |
3747 | ||
4497 | restoration | |
4498 | of localized variables, which means that for your code to run on older | |
3748 | 4499 | versions, a temporary is required if you want to mask some but not all |
3749 | 4500 | errors: |
3750 | 4501 | |
3751 | 4502 | =end original |
3752 | 4503 | |
3753 | Perl 5.14 より前では、C<$@> への代入はローカル化された変数の | |
4504 | Perl 5.14 より前では、L<C<$@>|perlvar/$@> への代入はローカル化された変数の | |
3754 | 起きるので、古いバージョンで実行される場合は、全てではなく一部だけの | |
4505 | 復帰の前に起きるので、古いバージョンで実行される場合は、全てではなく一部だけの | |
3755 | 4506 | エラーをマスクしたい場合には一時変数が必要です: |
3756 | 4507 | |
3757 | 4508 | # alter $@ on nefarious repugnancy only |
3758 | 4509 | { |
3759 | 4510 | my $e; |
3760 | 4511 | { |
3761 | | |
4512 | local $@; # protect existing $@ | |
3762 | | |
4513 | eval { test_repugnancy() }; | |
3763 | | |
4514 | # $@ =~ /nefarious/ and die $@; # Perl 5.14 and higher only | |
3764 | | |
4515 | $@ =~ /nefarious/ and $e = $@; | |
3765 | 4516 | } |
3766 | 4517 | die $e if defined $e |
3767 | 4518 | } |
3768 | 4519 | |
3769 | 4520 | =begin original |
3770 | 4521 | |
3771 | 4522 | C<eval BLOCK> does I<not> count as a loop, so the loop control statements |
3772 | C<next> | |
4523 | L<C<next>|/next LABEL>, L<C<last>|/last LABEL>, or | |
4524 | L<C<redo>|/redo LABEL> cannot be used to leave or restart the block. | |
3773 | 4525 | |
3774 | 4526 | =end original |
3775 | 4527 | |
3776 | C<eval BLOCK> はループとして I<扱われません> | |
4528 | C<eval BLOCK> はループとして I<扱われません>; 従って、L<C<next>|/next LABEL>, | |
3777 | ||
4529 | L<C<last>|/last LABEL>, L<C<redo>|/redo LABEL> といったループ制御文で | |
3778 | 再実行したりはできません。 | |
4530 | ブロックから離れたり再実行したりはできません。 | |
3779 | 4531 | |
3780 | 4532 | =begin original |
3781 | 4533 | |
3782 | An C<eval ''> executed within | |
4534 | An C<eval ''> executed within a subroutine defined | |
4535 | in the C<DB> package doesn't see the usual | |
3783 | 4536 | surrounding lexical scope, but rather the scope of the first non-DB piece |
3784 | of code that called it. You don't normally need to worry about this unless | |
4537 | of code that called it. You don't normally need to worry about this unless | |
3785 | 4538 | you are writing a Perl debugger. |
3786 | 4539 | |
3787 | 4540 | =end original |
3788 | 4541 | |
3789 | C<DB> パッケージ内で C<eval ''> を実行すると、通常の | |
4542 | C<DB> パッケージで定義されたサブルーチン内で C<eval ''> を実行すると、通常の | |
3790 | 4543 | レキシカルスコープではなく、これを呼び出した最初の非 DB コード片の |
3791 | 4544 | スコープになります。 |
3792 | 4545 | Perl デバッガを書いているのでない限り、普通はこれについて心配する必要は |
3793 | 4546 | ありません。 |
3794 | 4547 | |
4548 | =item evalbytes EXPR | |
4549 | X<evalbytes> | |
4550 | ||
4551 | =item evalbytes | |
4552 | ||
4553 | =for Pod::Functions +evalbytes similar to string eval, but intend to parse a bytestream | |
4554 | ||
4555 | =begin original | |
4556 | ||
4557 | This function is like L<C<eval>|/eval EXPR> with a string argument, | |
4558 | except it always parses its argument, or L<C<$_>|perlvar/$_> if EXPR is | |
4559 | omitted, as a string of bytes. A string containing characters whose | |
4560 | ordinal value exceeds 255 results in an error. Source filters activated | |
4561 | within the evaluated code apply to the code itself. | |
4562 | ||
4563 | =end original | |
4564 | ||
4565 | この関数は文字列引数の L<C<eval>|/eval EXPR> と同様ですが、引数(EXPR が | |
4566 | 省略された場合はL<C<$_>|perlvar/$_>) を常にバイト単位のの文字列として | |
4567 | 扱います。 | |
4568 | 序数が 255 を超える文字を含む文字列はエラーになります。 | |
4569 | eval されたコード内で有効になったソースフィルタはコード自体に適用されます。 | |
4570 | ||
4571 | =begin original | |
4572 | ||
4573 | L<C<evalbytes>|/evalbytes EXPR> is available only if the | |
4574 | L<C<"evalbytes"> feature|feature/The 'unicode_eval' and 'evalbytes' features> | |
4575 | is enabled or if it is prefixed with C<CORE::>. The | |
4576 | L<C<"evalbytes"> feature|feature/The 'unicode_eval' and 'evalbytes' features> | |
4577 | is enabled automatically with a C<use v5.16> (or higher) declaration in | |
4578 | the current scope. | |
4579 | ||
4580 | =end original | |
4581 | ||
4582 | L<C<evalbytes>|/evalbytes EXPR> は、 | |
4583 | L<C<"evalbytes"> 機能|feature/The 'unicode_eval' and 'evalbytes' features> が | |
4584 | 有効か、C<CORE::> 接頭辞を使ったときにのみ利用可能です。 | |
4585 | L<C<"evalbytes"> 機能|feature/The 'unicode_eval' and 'evalbytes' features> は、 | |
4586 | 現在のスコープで C<use v5.16> (またはそれ以上) 宣言があると自動的に | |
4587 | 有効になります。 | |
4588 | ||
3795 | 4589 | =item exec LIST |
3796 | 4590 | X<exec> X<execute> |
3797 | 4591 | |
3798 | 4592 | =item exec PROGRAM LIST |
3799 | 4593 | |
4594 | =for Pod::Functions abandon this program to run another | |
4595 | ||
3800 | 4596 | =begin original |
3801 | 4597 | |
3802 | The C<exec> function executes a system command I<and never | |
4598 | The L<C<exec>|/exec LIST> function executes a system command I<and never | |
3803 | use C<system> instead of C<exec> | |
4599 | returns>; use L<C<system>|/system LIST> instead of L<C<exec>|/exec LIST> | |
4600 | if you want it to return. It fails and | |
3804 | 4601 | returns false only if the command does not exist I<and> it is executed |
3805 | 4602 | directly instead of via your system's command shell (see below). |
3806 | 4603 | |
3807 | 4604 | =end original |
3808 | 4605 | |
3809 | C<exec> 関数は、システムのコマンドを実行し、I<戻ってはきません>; | |
4606 | L<C<exec>|/exec LIST> 関数は、システムのコマンドを実行し、I<戻ってはきません>; | |
3810 | 戻って欲しい場合には、C<exec>ではなく | |
4607 | 戻って欲しい場合には、L<C<exec>|/exec LIST>ではなく | |
4608 | L<C<system>|/system LIST> 関数を使ってください。 | |
3811 | 4609 | コマンドが存在せず、I<しかも> システムのコマンドシェル経由でなく |
3812 | 4610 | 直接コマンドを実行しようとした場合にのみこの関数は失敗して偽を返します。 |
3813 | 4611 | |
3814 | 4612 | =begin original |
3815 | 4613 | |
3816 | Since it's a common mistake to use C<exec> instead of | |
4614 | Since it's a common mistake to use L<C<exec>|/exec LIST> instead of | |
3817 | ||
4615 | L<C<system>|/system LIST>, Perl warns you if L<C<exec>|/exec LIST> is | |
3818 | o | |
4616 | called in void context and if there is a following statement that isn't | |
3819 | ||
4617 | L<C<die>|/die LIST>, L<C<warn>|/warn LIST>, or L<C<exit>|/exit EXPR> (if | |
3820 | ||
4618 | L<warnings> are enabled--but you always do that, right?). If you | |
4619 | I<really> want to follow an L<C<exec>|/exec LIST> with some other | |
4620 | statement, you can use one of these styles to avoid the warning: | |
3821 | 4621 | |
3822 | 4622 | =end original |
3823 | 4623 | |
3824 | C<system> の代わりに C<exec> を使うという | |
4624 | L<C<system>|/system LIST> の代わりに L<C<exec>|/exec LIST> を使うという | |
3825 | ||
4625 | よくある間違いを防ぐために、L<C<exec>|/exec LIST> が無効コンテキストで | |
3826 | ||
4626 | 呼び出されて、引き続く文が L<C<die>|/die LIST>, L<C<warn>|/warn LIST>, | |
3827 | ||
4627 | L<C<exit>|/exit EXPR> 以外の場合、Perl は警告を出します(L<warnings> が | |
3828 | ||
4628 | 有効の場合 -- でもいつもセットしてますよね?)。 | |
4629 | もし I<本当に> L<C<exec>|/exec LIST> の後に他の文を書きたい場合、以下の | |
4630 | どちらかのスタイルを使うことで警告を回避できます: | |
3829 | 4631 | |
3830 | 4632 | exec ('foo') or print STDERR "couldn't exec foo: $!"; |
3831 | 4633 | { exec ('foo') }; print STDERR "couldn't exec foo: $!"; |
3832 | 4634 | |
3833 | 4635 | =begin original |
3834 | 4636 | |
3835 | If there is more than one argument in LIST, | |
4637 | If there is more than one argument in LIST, this calls L<execvp(3)> with the | |
3836 | ||
4638 | arguments in LIST. If there is only one element in LIST, the argument is | |
3837 | ||
4639 | checked for shell metacharacters, and if there are any, the entire | |
3838 | ||
4640 | argument is passed to the system's command shell for parsing (this is | |
3839 | ||
4641 | C</bin/sh -c> on Unix platforms, but varies on other platforms). If | |
3840 | ||
4642 | there are no shell metacharacters in the argument, it is split into words | |
3841 | ||
4643 | and passed directly to C<execvp>, which is more efficient. Examples: | |
3842 | words and passed directly to C<execvp>, which is more efficient. | |
3843 | Examples: | |
3844 | 4644 | |
3845 | 4645 | =end original |
3846 | 4646 | |
3847 | LIST に複数の引数がある場合 | |
4647 | LIST に複数の引数がある場合は、LIST の引数を使って L<execvp(3)> を | |
3848 | ||
4648 | 呼び出します。 | |
3849 | ||
4649 | LIST に要素が一つのみの場合には、その引数からシェルのメタ文字をチェックし、 | |
3850 | ||
4650 | もしメタ文字があれば、引数全体をシステムのコマンドシェル(これはUnix では | |
3851 | 引数全体をシステムのコマンドシェル(これはUnix では | |
3852 | 4651 | C</bin/sh -c> ですが、システムによって異なります)に渡して解析させます。 |
3853 | ||
4652 | シェルのメタ文字がなかった場合、引数は単語に分解されて直接 C<execvp> に | |
3854 | より効率的 | |
4653 | 渡されます; この方がより効率的です。 | |
3855 | 4654 | 例: |
3856 | 4655 | |
3857 | 4656 | exec '/bin/echo', 'Your arguments are: ', @ARGV; |
3858 | 4657 | exec "sort $outfile | uniq"; |
3859 | 4658 | |
3860 | 4659 | =begin original |
3861 | 4660 | |
3862 | 4661 | If you don't really want to execute the first argument, but want to lie |
3863 | 4662 | to the program you are executing about its own name, you can specify |
3864 | 4663 | the program you actually want to run as an "indirect object" (without a |
3865 | comma) in front of the LIST. (This always | |
4664 | comma) in front of the LIST, as in C<exec PROGRAM LIST>. (This always | |
3866 | LIST as a multivalued list, even if there | |
4665 | forces interpretation of the LIST as a multivalued list, even if there | |
3867 | the list.) Example: | |
4666 | is only a single scalar in the list.) Example: | |
3868 | 4667 | |
3869 | 4668 | =end original |
3870 | 4669 | |
3871 | 第一引数に指定するものを本当に実行したいが、実行する | |
4670 | 第一引数に指定するものを本当に実行したいが、実行するプログラムに対して別の | |
3872 | ||
4671 | 名前を教えたい場合には、C<exec PROGRAM LIST> のように、LIST の前に | |
3873 | 「間接オブジェクト」(コンマなし) として | |
4672 | 「間接オブジェクト」(コンマなし) として実際に実行したいプログラムを | |
3874 | ||
4673 | 指定することができます。 | |
3875 | (これによって、LIST に単一のスカラしかなくても、複数 | |
4674 | (これによって、LIST に単一のスカラしかなくても、複数値のリストであるように、 | |
3876 | ||
4675 | LIST の解釈を行ないます。) | |
3877 | 4676 | 例: |
3878 | 4677 | |
3879 | $shell = '/bin/csh'; | |
4678 | my $shell = '/bin/csh'; | |
3880 | 4679 | exec $shell '-sh'; # pretend it's a login shell |
3881 | 4680 | |
3882 | 4681 | =begin original |
3883 | 4682 | |
3884 | 4683 | or, more directly, |
3885 | 4684 | |
3886 | 4685 | =end original |
3887 | 4686 | |
3888 | 4687 | あるいは、より直接的に、 |
3889 | 4688 | |
3890 | 4689 | exec {'/bin/csh'} '-sh'; # pretend it's a login shell |
3891 | 4690 | |
3892 | 4691 | =begin original |
3893 | 4692 | |
3894 | 4693 | When the arguments get executed via the system shell, results are |
3895 | 4694 | subject to its quirks and capabilities. See L<perlop/"`STRING`"> |
3896 | 4695 | for details. |
3897 | 4696 | |
3898 | 4697 | =end original |
3899 | 4698 | |
3900 | 4699 | 引数がシステムシェルで実行されるとき、結果はシェルの奇癖と能力によって |
3901 | 4700 | 変わります。 |
3902 | 4701 | 詳細については L<perlop/"`STRING`"> を参照してください。 |
3903 | 4702 | |
3904 | 4703 | =begin original |
3905 | 4704 | |
3906 | Using an indirect object with C<exec> | |
4705 | Using an indirect object with L<C<exec>|/exec LIST> or | |
3907 | secure. This usage (which also | |
4706 | L<C<system>|/system LIST> is also more secure. This usage (which also | |
4707 | works fine with L<C<system>|/system LIST>) forces | |
3908 | 4708 | interpretation of the arguments as a multivalued list, even if the |
3909 | 4709 | list had just one argument. That way you're safe from the shell |
3910 | 4710 | expanding wildcards or splitting up words with whitespace in them. |
3911 | 4711 | |
3912 | 4712 | =end original |
3913 | 4713 | |
3914 | C<exec> や C<system> で間接オブジェクトを | |
4714 | L<C<exec>|/exec LIST> や L<C<system>|/system LIST> で間接オブジェクトを | |
3915 | ||
4715 | 使うのもより安全です。 | |
3916 | ||
4716 | この使い方(L<C<system>|/system LIST> でも同様にうまく動きます)は、たとえ | |
4717 | 引数が一つだけの場合も、複数の値を持つリストとして引数を解釈することを | |
4718 | 強制します。 | |
3917 | 4719 | この方法で、シェルによるワイルドカード展開や、空白による単語の分割から |
3918 | 4720 | 守られます。 |
3919 | 4721 | |
3920 | @args = ( "echo surprise" ); | |
4722 | my @args = ( "echo surprise" ); | |
3921 | 4723 | |
3922 | 4724 | exec @args; # subject to shell escapes |
3923 | 4725 | # if @args == 1 |
3924 | 4726 | exec { $args[0] } @args; # safe even with one-arg list |
3925 | 4727 | |
3926 | 4728 | =begin original |
3927 | 4729 | |
3928 | 4730 | The first version, the one without the indirect object, ran the I<echo> |
3929 | 4731 | program, passing it C<"surprise"> an argument. The second version didn't; |
3930 | 4732 | it tried to run a program named I<"echo surprise">, didn't find it, and set |
3931 | C<$?> to a non-zero value indicating failure. | |
4733 | L<C<$?>|perlvar/$?> to a non-zero value indicating failure. | |
3932 | 4734 | |
3933 | 4735 | =end original |
3934 | 4736 | |
3935 | 4737 | 間接オブジェクトなしの一つ目のバージョンでは、I<echo> プログラムが実行され、 |
3936 | 4738 | C<"surprise"> が引数として渡されます。 |
3937 | 4739 | 二つ目のバージョンでは違います; I<"echo surprise"> という名前の |
3938 | 4740 | プログラムを実行しようとして、見つからないので、失敗したことを示すために |
3939 | C<$?> に非 0 がセットされます。 | |
4741 | L<C<$?>|perlvar/$?> に非 0 がセットされます。 | |
3940 | 4742 | |
3941 | 4743 | =begin original |
3942 | 4744 | |
3943 | ||
4745 | On Windows, only the C<exec PROGRAM LIST> indirect object syntax will | |
3944 | ou | |
4746 | reliably avoid using the shell; C<exec LIST>, even with more than one | |
3945 | ||
4747 | element, will fall back to the shell if the first spawn fails. | |
3946 | in English) or call the C<autoflush()> method of C<IO::Handle> on any | |
3947 | open handles to avoid lost output. | |
3948 | 4748 | |
3949 | 4749 | =end original |
3950 | 4750 | |
4751 | Windows では、C<exec PROGRAM LIST> 間接オブジェクト構文のみが、シェルを | |
4752 | 使うのを回避するための信頼できる方法です; C<exec LIST> は、複数の要素が | |
4753 | あっても、最初の spawn が失敗したときにシェルに | |
4754 | フォールバックすることがあります。 | |
4755 | ||
4756 | =begin original | |
4757 | ||
4758 | Perl attempts to flush all files opened for output before the exec, | |
4759 | but this may not be supported on some platforms (see L<perlport>). | |
4760 | To be safe, you may need to set L<C<$E<verbar>>|perlvar/$E<verbar>> | |
4761 | (C<$AUTOFLUSH> in L<English>) or call the C<autoflush> method of | |
4762 | L<C<IO::Handle>|IO::Handle/METHODS> on any open handles to avoid lost | |
4763 | output. | |
4764 | ||
4765 | =end original | |
4766 | ||
3951 | 4767 | v5.6.0 から、Perl は exec の前に出力用に開かれている全てのファイルを |
3952 | 4768 | フラッシュしようとしますが、これに対応していないプラットフォームもあります |
3953 | 4769 | (L<perlport> を参照してください)。 |
3954 | 4770 | 安全のためには、出力が重複するのを避けるために、全てのオープンしている |
3955 | ハンドルに対して C<$ | |
4771 | ハンドルに対して L<C<$E<verbar>>|perlvar/$E<verbar>> | |
3956 | ||
4772 | (L<English> モジュールでは C<$AUTOFLUSH>) を設定するか、 | |
3957 | ||
4773 | L<C<IO::Handle>|IO::Handle/METHODS> モジュールの C<autoflush> メソッドを | |
4774 | 呼ぶ必要があるかもしれません。 | |
3958 | 4775 | |
3959 | 4776 | =begin original |
3960 | 4777 | |
3961 | Note that C<exec> will not call your C<END> blocks, nor | |
4778 | Note that L<C<exec>|/exec LIST> will not call your C<END> blocks, nor | |
3962 | C<DESTROY> methods on your objects. | |
4779 | will it invoke C<DESTROY> methods on your objects. | |
3963 | 4780 | |
3964 | 4781 | =end original |
3965 | 4782 | |
3966 | C<exec> は C<END> ブロックや、オブジェクトの | |
4783 | L<C<exec>|/exec LIST> は C<END> ブロックや、オブジェクトの | |
3967 | 起動しないことに注意してください。 | |
4784 | C<DESTROY> メソッドを起動しないことに注意してください。 | |
3968 | 4785 | |
4786 | =begin original | |
4787 | ||
4788 | Portability issues: L<perlport/exec>. | |
4789 | ||
4790 | =end original | |
4791 | ||
4792 | 移植性の問題: L<perlport/exec>。 | |
4793 | ||
3969 | 4794 | =item exists EXPR |
3970 | 4795 | X<exists> X<autovivification> |
3971 | 4796 | |
4797 | =for Pod::Functions test whether a hash key is present | |
4798 | ||
3972 | 4799 | =begin original |
3973 | 4800 | |
3974 | 4801 | Given an expression that specifies an element of a hash, returns true if the |
3975 | 4802 | specified element in the hash has ever been initialized, even if the |
3976 | 4803 | corresponding value is undefined. |
3977 | 4804 | |
3978 | 4805 | =end original |
3979 | 4806 | |
3980 | 4807 | ハッシュ要素を示す表現が与えられ、指定された要素が、ハッシュに存在すれば、 |
3981 | 4808 | たとえ対応する値が未定義でも真を返します。 |
3982 | 4809 | |
3983 | 4810 | print "Exists\n" if exists $hash{$key}; |
3984 | 4811 | print "Defined\n" if defined $hash{$key}; |
3985 | 4812 | print "True\n" if $hash{$key}; |
3986 | 4813 | |
3987 | 4814 | =begin original |
3988 | 4815 | |
3989 | 4816 | exists may also be called on array elements, but its behavior is much less |
3990 | obvious and is strongly tied to the use of L</delete> on | |
4817 | obvious and is strongly tied to the use of L<C<delete>|/delete EXPR> on | |
3991 | ||
4818 | arrays. | |
3992 | a future version of Perl. | |
3993 | 4819 | |
3994 | 4820 | =end original |
3995 | 4821 | |
3996 | 4822 | exists は配列の要素に対しても呼び出せますが、その振る舞いははるかに |
3997 | 不明確で、配列に対する L</delete> の使用と強く | |
4823 | 不明確で、配列に対する L<C<delete>|/delete EXPR> の使用と強く | |
3998 | ||
4824 | 結びついています。 | |
3999 | Perl では削除されるかもしれないことを B<注意してください> 。 | |
4000 | 4825 | |
4826 | =begin original | |
4827 | ||
4828 | B<WARNING:> Calling L<C<exists>|/exists EXPR> on array values is | |
4829 | strongly discouraged. The | |
4830 | notion of deleting or checking the existence of Perl array elements is not | |
4831 | conceptually coherent, and can lead to surprising behavior. | |
4832 | ||
4833 | =end original | |
4834 | ||
4835 | B<警告:> 配列の値に対して L<C<exists>|/exists EXPR> を呼び出すことは強く | |
4836 | 非推奨です。 | |
4837 | Perl の配列要素を削除したり存在を調べたりする記法は概念的に一貫しておらず、 | |
4838 | 驚くべき振る舞いを引き起こすことがあります。 | |
4839 | ||
4001 | 4840 | print "Exists\n" if exists $array[$index]; |
4002 | 4841 | print "Defined\n" if defined $array[$index]; |
4003 | 4842 | print "True\n" if $array[$index]; |
4004 | 4843 | |
4005 | 4844 | =begin original |
4006 | 4845 | |
4007 | 4846 | A hash or array element can be true only if it's defined and defined only if |
4008 | 4847 | it exists, but the reverse doesn't necessarily hold true. |
4009 | 4848 | |
4010 | 4849 | =end original |
4011 | 4850 | |
4012 | 4851 | ハッシュまたは配列要素は、定義されているときにのみ真となり、 |
4013 | 4852 | 存在しているときにのみ定義されますが、逆は必ずしも真ではありません。 |
4014 | 4853 | |
4015 | 4854 | =begin original |
4016 | 4855 | |
4017 | 4856 | Given an expression that specifies the name of a subroutine, |
4018 | 4857 | returns true if the specified subroutine has ever been declared, even |
4019 | 4858 | if it is undefined. Mentioning a subroutine name for exists or defined |
4020 | 4859 | does not count as declaring it. Note that a subroutine that does not |
4021 | 4860 | exist may still be callable: its package may have an C<AUTOLOAD> |
4022 | 4861 | method that makes it spring into existence the first time that it is |
4023 | 4862 | called; see L<perlsub>. |
4024 | 4863 | |
4025 | 4864 | =end original |
4026 | 4865 | |
4027 | 4866 | 引数としてサブルーチンの名前が指定された場合、 |
4028 | 4867 | 指定されたサブルーチンが宣言されていれば(たとえ未定義でも) |
4029 | 4868 | 真を返します。 |
4030 | 4869 | exists や defined のために言及されているサブルーチン名は |
4031 | 4870 | 宣言としてのカウントに入りません。 |
4032 | 4871 | 存在しないサブルーチンでも呼び出し可能かもしれないことに注意してください: |
4033 | 4872 | パッケージが C<AUTOLOAD> メソッドを持っていて、最初に呼び出された時に |
4034 | 4873 | 存在を作り出すかもしれません; L<perlsub> を参照してください。 |
4035 | 4874 | |
4036 | 4875 | print "Exists\n" if exists &subroutine; |
4037 | 4876 | print "Defined\n" if defined &subroutine; |
4038 | 4877 | |
4039 | 4878 | =begin original |
4040 | 4879 | |
4041 | 4880 | Note that the EXPR can be arbitrarily complicated as long as the final |
4042 | 4881 | operation is a hash or array key lookup or subroutine name: |
4043 | 4882 | |
4044 | 4883 | =end original |
4045 | 4884 | |
4046 | 最終的な操作がハッシュや配列の key による検索または | |
4885 | 最終的な操作がハッシュや配列の key による検索または | |
4047 | EXPR には任意の複雑な式を置くことができます: | |
4886 | サブルーチン名である限りは、EXPR には任意の複雑な式を置くことができます: | |
4048 | 4887 | |
4049 | 4888 | if (exists $ref->{A}->{B}->{$key}) { } |
4050 | 4889 | if (exists $hash{A}{B}{$key}) { } |
4051 | 4890 | |
4052 | 4891 | if (exists $ref->{A}->{B}->[$ix]) { } |
4053 | 4892 | if (exists $hash{A}{B}[$ix]) { } |
4054 | 4893 | |
4055 | 4894 | if (exists &{$ref->{A}{B}{$key}}) { } |
4056 | 4895 | |
4057 | 4896 | =begin original |
4058 | 4897 | |
4059 | Although the most | |
4898 | Although the most deeply nested array or hash element will not spring into | |
4060 | 4899 | existence just because its existence was tested, any intervening ones will. |
4061 | 4900 | Thus C<< $ref->{"A"} >> and C<< $ref->{"A"}->{"B"} >> will spring |
4062 | into existence due to the existence test for the $key element above. | |
4901 | into existence due to the existence test for the C<$key> element above. | |
4063 | 4902 | This happens anywhere the arrow operator is used, including even here: |
4064 | 4903 | |
4065 | 4904 | =end original |
4066 | 4905 | |
4067 | ネストした配列やハッシュの | |
4906 | 最も深くネストした配列やハッシュの要素は、その存在をテストしただけでは | |
4068 | 4907 | 存在するようにはなりませんが、途中のものは存在するようになります。 |
4069 | 従って C<< $ref->{"A"} >> と C<< $ref->{"A"}->{"B"} >> は上記の $key の | |
4908 | 従って C<< $ref->{"A"} >> と C<< $ref->{"A"}->{"B"} >> は上記の C<$key> の | |
4070 | 4909 | 存在をテストしたことによって存在するようになります。 |
4071 | 4910 | これは、矢印演算子が使われるところでは、以下のようなものを含むどこででも |
4072 | 4911 | 起こります。 |
4073 | 4912 | |
4074 | 4913 | undef $ref; |
4075 | 4914 | if (exists $ref->{"Some key"}) { } |
4076 | 4915 | print $ref; # prints HASH(0x80d3d5c) |
4077 | 4916 | |
4078 | 4917 | =begin original |
4079 | 4918 | |
4080 | 4919 | This surprising autovivification in what does not at first--or even |
4081 | 4920 | second--glance appear to be an lvalue context may be fixed in a future |
4082 | 4921 | release. |
4083 | 4922 | |
4084 | 4923 | =end original |
4085 | 4924 | |
4086 | 4925 | 一目見ただけでは -- あるいは二目見ても -- 驚かされる、左辺値コンテキストでの |
4087 | 4926 | 自動有効化は将来のリリースでは修正されるでしょう。 |
4088 | 4927 | |
4089 | 4928 | =begin original |
4090 | 4929 | |
4091 | 4930 | Use of a subroutine call, rather than a subroutine name, as an argument |
4092 | to exists | |
4931 | to L<C<exists>|/exists EXPR> is an error. | |
4093 | 4932 | |
4094 | 4933 | =end original |
4095 | 4934 | |
4096 | exists | |
4935 | L<C<exists>|/exists EXPR> の引数としてサブルーチン名でなくサブルーチン | |
4097 | エラーになります。 | |
4936 | 呼び出しを使うと、エラーになります。 | |
4098 | 4937 | |
4099 | 4938 | exists ⊂ # OK |
4100 | 4939 | exists &sub(); # Error |
4101 | 4940 | |
4102 | 4941 | =item exit EXPR |
4103 | 4942 | X<exit> X<terminate> X<abort> |
4104 | 4943 | |
4105 | 4944 | =item exit |
4106 | 4945 | |
4946 | =for Pod::Functions terminate this program | |
4947 | ||
4107 | 4948 | =begin original |
4108 | 4949 | |
4109 | 4950 | Evaluates EXPR and exits immediately with that value. Example: |
4110 | 4951 | |
4111 | 4952 | =end original |
4112 | 4953 | |
4113 | 4954 | EXPR を評価し、即座にその値を持って終了します。 |
4114 | 4955 | 例: |
4115 | 4956 | |
4116 | $ans = <STDIN>; | |
4957 | my $ans = <STDIN>; | |
4117 | 4958 | exit 0 if $ans =~ /^[Xx]/; |
4118 | 4959 | |
4119 | 4960 | =begin original |
4120 | 4961 | |
4121 | See also C<die>. If EXPR is omitted, exits with C<0> | |
4962 | See also L<C<die>|/die LIST>. If EXPR is omitted, exits with C<0> | |
4963 | status. The only | |
4122 | 4964 | universally recognized values for EXPR are C<0> for success and C<1> |
4123 | 4965 | for error; other values are subject to interpretation depending on the |
4124 | 4966 | environment in which the Perl program is running. For example, exiting |
4125 | 4967 | 69 (EX_UNAVAILABLE) from a I<sendmail> incoming-mail filter will cause |
4126 | 4968 | the mailer to return the item undelivered, but that's not true everywhere. |
4127 | 4969 | |
4128 | 4970 | =end original |
4129 | 4971 | |
4130 | C<die> も参照してください。 | |
4972 | L<C<die>|/die LIST> も参照してください。 | |
4131 | 4973 | EXPR が省略された場合には、ステータスを C<0> として終了します。 |
4132 | EXPR の値として広く利用可能なのは C<0> が成功で C<1> が | |
4974 | EXPR の値として広く利用可能なのは C<0> が成功で C<1> が | |
4133 | その他の値は、 Perl が実行される環境によって異な | |
4975 | エラーということだけです; その他の値は、 Perl が実行される環境によって異なる | |
4134 | 可能性があります。 | |
4976 | 解釈がされる可能性があります。 | |
4135 | 4977 | 例えば、I<sendmail> 到着メールフィルタから 69 (EX_UNAVAILABLE) で終了すると |
4136 | 4978 | メーラーはアイテムを配達せずに差し戻しますが、 |
4137 | 4979 | これはいつでも真ではありません。 |
4138 | 4980 | |
4139 | 4981 | =begin original |
4140 | 4982 | |
4141 | Don't use C<exit> to abort a subroutine if there's any | |
4983 | Don't use L<C<exit>|/exit EXPR> to abort a subroutine if there's any | |
4142 | someone might want to trap whatever error happened. Use | |
4984 | chance that someone might want to trap whatever error happened. Use | |
4143 | which can be trapped by an | |
4985 | L<C<die>|/die LIST> instead, which can be trapped by an | |
4986 | L<C<eval>|/eval EXPR>. | |
4144 | 4987 | |
4145 | 4988 | =end original |
4146 | 4989 | |
4147 | 4990 | 誰かが発生したエラーをトラップしようと考えている可能性がある場合は、 |
4148 | サブルーチンの中断に C<exit> を使わないでください。 | |
4991 | サブルーチンの中断に L<C<exit>|/exit EXPR> を使わないでください。 | |
4149 | 代わりに C<eval> でトラップできる C<die> を | |
4992 | 代わりに L<C<eval>|/eval EXPR> でトラップできる L<C<die>|/die LIST> を | |
4993 | 使ってください。 | |
4150 | 4994 | |
4151 | 4995 | =begin original |
4152 | 4996 | |
4153 | The exit | |
4997 | The L<C<exit>|/exit EXPR> function does not always exit immediately. It | |
4154 | defined C<END> routines first, but these C<END> routines may | |
4998 | calls any defined C<END> routines first, but these C<END> routines may | |
4155 | themselves abort the exit. Likewise any object destructors that | |
4999 | not themselves abort the exit. Likewise any object destructors that | |
4156 | be called are called before the real exit. C<END> routines and | |
5000 | need to be called are called before the real exit. C<END> routines and | |
4157 | can change the exit status by modifying C<$?> | |
5001 | destructors can change the exit status by modifying L<C<$?>|perlvar/$?>. | |
4158 | ||
5002 | If this is a problem, you can call | |
4159 | Se | |
5003 | L<C<POSIX::_exit($status)>|POSIX/C<_exit>> to avoid C<END> and destructor | |
5004 | processing. See L<perlmod> for details. | |
4160 | 5005 | |
4161 | 5006 | =end original |
4162 | 5007 | |
4163 | exit | |
5008 | L<C<exit>|/exit EXPR> 関数は常に直ちに終了するわけではありません。 | |
4164 | まず、定義されている END ルーチンを呼び出しますが、 | |
5009 | まず、定義されている C<END> ルーチンを呼び出しますが、 | |
4165 | 5010 | C<END> ルーチン自身は exit を止められません。 |
4166 | 5011 | 同様に、呼び出す必要のあるオブジェクトデストラクタは |
4167 | 5012 | すべて、実際の終了前に呼び出されます。 |
4168 | C<END> ルーチンとデストラクタは C<$?> を修正することで | |
5013 | C<END> ルーチンとデストラクタは L<C<$?>|perlvar/$?> を修正することで | |
4169 | 変更できます。 | |
5014 | 終了コードを変更できます。 | |
4170 | これが問題になる場合は、END やデストラクタが実行されることを | |
5015 | これが問題になる場合は、C<END> やデストラクタが実行されることを | |
4171 | 防ぐために C<POSIX:_exit($status)> を呼び出してください。 | |
5016 | 防ぐために L<C<POSIX::_exit($status)>|POSIX/C<_exit>> を呼び出してください。 | |
4172 | 5017 | 詳しくは L<perlmod> を参照してください。 |
4173 | 5018 | |
5019 | =begin original | |
5020 | ||
5021 | Portability issues: L<perlport/exit>. | |
5022 | ||
5023 | =end original | |
5024 | ||
5025 | 移植性の問題: L<perlport/exit>。 | |
5026 | ||
4174 | 5027 | =item exp EXPR |
4175 | 5028 | X<exp> X<exponential> X<antilog> X<antilogarithm> X<e> |
4176 | 5029 | |
4177 | 5030 | =item exp |
4178 | 5031 | |
5032 | =for Pod::Functions raise I<e> to a power | |
5033 | ||
4179 | 5034 | =begin original |
4180 | 5035 | |
4181 | 5036 | Returns I<e> (the natural logarithm base) to the power of EXPR. |
4182 | 5037 | If EXPR is omitted, gives C<exp($_)>. |
4183 | 5038 | |
4184 | 5039 | =end original |
4185 | 5040 | |
4186 | I<e> (自然対数の底) の EXPR 乗を返します。 | |
5041 | I<e> (自然対数の底) の EXPR 乗を返します。 | |
4187 | 5042 | EXPR を省略した場合には、C<exp($_)> を返します。 |
4188 | 5043 | |
5044 | =item fc EXPR | |
5045 | X<fc> X<foldcase> X<casefold> X<fold-case> X<case-fold> | |
5046 | ||
5047 | =item fc | |
5048 | ||
5049 | =for Pod::Functions +fc return casefolded version of a string | |
5050 | ||
5051 | =begin original | |
5052 | ||
5053 | Returns the casefolded version of EXPR. This is the internal function | |
5054 | implementing the C<\F> escape in double-quoted strings. | |
5055 | ||
5056 | =end original | |
5057 | ||
5058 | EXPR の畳み込み版を返します。 | |
5059 | これは、ダブルクォート文字列における、C<\F> エスケープを | |
5060 | 実装する内部関数です。 | |
5061 | ||
5062 | =begin original | |
5063 | ||
5064 | Casefolding is the process of mapping strings to a form where case | |
5065 | differences are erased; comparing two strings in their casefolded | |
5066 | form is effectively a way of asking if two strings are equal, | |
5067 | regardless of case. | |
5068 | ||
5069 | =end original | |
5070 | ||
5071 | 畳み込みは大文字小文字の違いを消した形式に文字列をマッピングする処理です; | |
5072 | 畳み込み形式で二つの文字列を比較するのは二つの文字列が大文字小文字に | |
5073 | 関わらず等しいかどうかを比較する効率的な方法です。 | |
5074 | ||
5075 | =begin original | |
5076 | ||
5077 | Roughly, if you ever found yourself writing this | |
5078 | ||
5079 | =end original | |
5080 | ||
5081 | おおよそ、自分自身で以下のように書いていたとしても | |
5082 | ||
5083 | lc($this) eq lc($that) # Wrong! | |
5084 | # or | |
5085 | uc($this) eq uc($that) # Also wrong! | |
5086 | # or | |
5087 | $this =~ /^\Q$that\E\z/i # Right! | |
5088 | ||
5089 | =begin original | |
5090 | ||
5091 | Now you can write | |
5092 | ||
5093 | =end original | |
5094 | ||
5095 | 今では以下のように書けます | |
5096 | ||
5097 | fc($this) eq fc($that) | |
5098 | ||
5099 | =begin original | |
5100 | ||
5101 | And get the correct results. | |
5102 | ||
5103 | =end original | |
5104 | ||
5105 | そして正しい結果を得られます。 | |
5106 | ||
5107 | =begin original | |
5108 | ||
5109 | Perl only implements the full form of casefolding, but you can access | |
5110 | the simple folds using L<Unicode::UCD/B<casefold()>> and | |
5111 | L<Unicode::UCD/B<prop_invmap()>>. | |
5112 | For further information on casefolding, refer to | |
5113 | the Unicode Standard, specifically sections 3.13 C<Default Case Operations>, | |
5114 | 4.2 C<Case-Normative>, and 5.18 C<Case Mappings>, | |
5115 | available at L<http://www.unicode.org/versions/latest/>, as well as the | |
5116 | Case Charts available at L<http://www.unicode.org/charts/case/>. | |
5117 | ||
5118 | =end original | |
5119 | ||
5120 | Perl は完全な形式の畳み込みのみを実装していますが、 | |
5121 | L<Unicode::UCD/B<casefold()>> と L<Unicode::UCD/B<prop_invmap()>> を使って | |
5122 | 単純なたたみ込みにアクセスできます。 | |
5123 | 畳み込みに関するさらなる情報については、 | |
5124 | L<http://www.unicode.org/versions/latest/> で利用可能な Unicode 標準、特に | |
5125 | 3.13 C<Default Case Operations>, 4.2 C<Case-Normative>, 5.18 | |
5126 | C<Case Mappings> および、L<http://www.unicode.org/charts/case/> で | |
5127 | 利用可能なケース表を参照してください。 | |
5128 | ||
5129 | =begin original | |
5130 | ||
5131 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. | |
5132 | ||
5133 | =end original | |
5134 | ||
5135 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
5136 | ||
5137 | =begin original | |
5138 | ||
5139 | This function behaves the same way under various pragmas, such as within | |
5140 | L<S<C<"use feature 'unicode_strings">>|feature/The 'unicode_strings' feature>, | |
5141 | as L<C<lc>|/lc EXPR> does, with the single exception of | |
5142 | L<C<fc>|/fc EXPR> of I<LATIN CAPITAL LETTER SHARP S> (U+1E9E) within the | |
5143 | scope of L<S<C<use locale>>|locale>. The foldcase of this character | |
5144 | would normally be C<"ss">, but as explained in the L<C<lc>|/lc EXPR> | |
5145 | section, case | |
5146 | changes that cross the 255/256 boundary are problematic under locales, | |
5147 | and are hence prohibited. Therefore, this function under locale returns | |
5148 | instead the string C<"\x{17F}\x{17F}">, which is the I<LATIN SMALL LETTER | |
5149 | LONG S>. Since that character itself folds to C<"s">, the string of two | |
5150 | of them together should be equivalent to a single U+1E9E when foldcased. | |
5151 | ||
5152 | =end original | |
5153 | ||
5154 | この関数は、 | |
5155 | L<S<C<"use feature 'unicode_strings">>|feature/The 'unicode_strings' feature> | |
5156 | のようなさまざまなプラグマの影響下では、L<C<lc>|/lc EXPR> と同様に | |
5157 | 振る舞います; | |
5158 | 但し、L<S<C<use locale>>|locale> のスコープ内での | |
5159 | I<LATIN CAPITAL LETTER SHARP S> (U+1E9E) の L<C<fc>|/fc EXPR> は例外です。 | |
5160 | この文字の畳み込み文字は普通は C<"ss"> ですが、L<C<lc>|/lc EXPR> の節で | |
5161 | 説明しているように、ロケールの基での255/256 境界をまたぐ大文字小文字の変更は | |
5162 | 問題があるので、禁止されています。 | |
5163 | 従って、ロケールの基ではこの関数は代わりに I<LATIN SMALL LETTER LONG S> である | |
5164 | C<"\x{17F}\x{17F}"> を返します。 | |
5165 | この文字自体は C<"s"> の畳み込みなので、これら二つを合わせた文字列は | |
5166 | 畳み込まれた場合は単一の U+1E9E と等価になります。 | |
5167 | ||
5168 | =begin original | |
5169 | ||
5170 | While the Unicode Standard defines two additional forms of casefolding, | |
5171 | one for Turkic languages and one that never maps one character into multiple | |
5172 | characters, these are not provided by the Perl core. However, the CPAN module | |
5173 | L<C<Unicode::Casing>|Unicode::Casing> may be used to provide an implementation. | |
5174 | ||
5175 | =end original | |
5176 | ||
5177 | Unicode 標準はさらに二つの畳み込み形式、一つはツルキ語、もう一つは決して | |
5178 | 一つの文字が複数の文字にマッピングされないもの、を定義していますが、 | |
5179 | これらは Perl コアでは提供されません。 | |
5180 | しかし、CPAN モジュール L<C<Unicode::Casing>|Unicode::Casing> が実装を | |
5181 | 提供しています。 | |
5182 | ||
5183 | =begin original | |
5184 | ||
5185 | L<C<fc>|/fc EXPR> is available only if the | |
5186 | L<C<"fc"> feature|feature/The 'fc' feature> is enabled or if it is | |
5187 | prefixed with C<CORE::>. The | |
5188 | L<C<"fc"> feature|feature/The 'fc' feature> is enabled automatically | |
5189 | with a C<use v5.16> (or higher) declaration in the current scope. | |
5190 | ||
5191 | =end original | |
5192 | ||
5193 | L<C<fc>|/fc EXPR> は | |
5194 | L<C<"fc"> 機能|feature/The 'fc' feature> が有効か C<CORE::> が | |
5195 | 前置されたときにのみ利用可能です。 | |
5196 | L<C<"fc"> 機能|feature/The 'fc' feature> は現在のスコープで | |
5197 | C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。 | |
5198 | ||
4189 | 5199 | =item fcntl FILEHANDLE,FUNCTION,SCALAR |
4190 | 5200 | X<fcntl> |
4191 | 5201 | |
5202 | =for Pod::Functions file control system call | |
5203 | ||
4192 | 5204 | =begin original |
4193 | 5205 | |
4194 | Implements the fcntl(2) function. You'll probably have to say | |
5206 | Implements the L<fcntl(2)> function. You'll probably have to say | |
4195 | 5207 | |
4196 | 5208 | =end original |
4197 | 5209 | |
4198 | fcntl(2) 関数を実装します。 | |
5210 | L<fcntl(2)> 関数を実装します。 | |
4199 | 正しい定数定義を得るために、まず | |
5211 | 正しい定数定義を得るために、まず | |
4200 | 5212 | |
4201 | 5213 | use Fcntl; |
4202 | 5214 | |
4203 | 5215 | =begin original |
4204 | 5216 | |
4205 | 5217 | first to get the correct constant definitions. Argument processing and |
4206 | value returned work just like C<ioctl> | |
5218 | value returned work just like L<C<ioctl>|/ioctl | |
4207 | For example: | |
5219 | FILEHANDLE,FUNCTION,SCALAR> below. For example: | |
4208 | 5220 | |
4209 | 5221 | =end original |
4210 | 5222 | |
4211 | 5223 | と書くことが必要でしょう。 |
4212 | 引数の処理と返り値については、下記の | |
5224 | 引数の処理と返り値については、下記の | |
4213 | ||
5225 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同様に動作します。 | |
5226 | 例えば: | |
4214 | 5227 | |
4215 | 5228 | use Fcntl; |
4216 | fcntl($filehandle, F_GETFL, | |
5229 | my $flags = fcntl($filehandle, F_GETFL, 0) | |
4217 | or die " | |
5230 | or die "Can't fcntl F_GETFL: $!"; | |
4218 | 5231 | |
4219 | 5232 | =begin original |
4220 | 5233 | |
4221 | You don't have to check for C<defined> on the return | |
5234 | You don't have to check for L<C<defined>|/defined EXPR> on the return | |
4222 | ||
5235 | from L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>. Like | |
4223 | C< | |
5236 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>, it maps a C<0> return | |
4224 | ||
5237 | from the system call into C<"0 but true"> in Perl. This string is true | |
4225 | on | |
5238 | in boolean context and C<0> in numeric context. It is also exempt from | |
5239 | the normal | |
5240 | L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s> | |
5241 | L<warnings> on improper numeric conversions. | |
4226 | 5242 | |
4227 | 5243 | =end original |
4228 | 5244 | |
4229 | C<fcntl> からの返り値のチェックに | |
5245 | L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> からの返り値のチェックに | |
4230 | ||
5246 | L<C<defined>|/defined EXPR> を使う必要はありません。 | |
4231 | C< | |
5247 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と違って、これは | |
5248 | システムコールの結果が C<0> だった場合は C<"0 だが真"> を返します。 | |
4232 | 5249 | この文字列は真偽値コンテキストでは真となり、 |
4233 | 5250 | 数値コンテキストでは C<0> になります。 |
4234 | これはまた、不適切な数値変換に関する通常の | |
5251 | これはまた、不適切な数値変換に関する通常の | |
5252 | L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s> | |
5253 | L<warnings> を回避します。 | |
4235 | 5254 | |
4236 | 5255 | =begin original |
4237 | 5256 | |
4238 | Note that C<fcntl> raises an | |
5257 | Note that L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> raises an | |
4239 | doesn't implement fcntl(2). See | |
5258 | exception if used on a machine that doesn't implement L<fcntl(2)>. See | |
4240 | manpage to learn what functions | |
5259 | the L<Fcntl> module or your L<fcntl(2)> manpage to learn what functions | |
5260 | are available on your system. | |
4241 | 5261 | |
4242 | 5262 | =end original |
4243 | 5263 | |
4244 | fcntl(2) が実装されていないマシンでは、 | |
5264 | L<fcntl(2)> が実装されていないマシンでは、 | |
5265 | L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> は例外を | |
4245 | 5266 | 引き起こすことに注意してください。 |
4246 | システムでどの関数が利用可能かについては Fcntl モジュールや | |
5267 | システムでどの関数が利用可能かについては L<Fcntl> モジュールや | |
4247 | fcntl(2) man ページを参照してください。 | |
5268 | L<fcntl(2)> man ページを参照してください。 | |
4248 | 5269 | |
4249 | 5270 | =begin original |
4250 | 5271 | |
4251 | Here's an example of setting a filehandle named C<REMOTE> to be | |
5272 | Here's an example of setting a filehandle named C<$REMOTE> to be | |
4252 | non-blocking at the system level. You'll have to negotiate | |
5273 | non-blocking at the system level. You'll have to negotiate | |
4253 | on your own, though. | |
5274 | L<C<$E<verbar>>|perlvar/$E<verbar>> on your own, though. | |
4254 | 5275 | |
4255 | 5276 | =end original |
4256 | 5277 | |
4257 | これは C<REMOTE> というファイルハンドルをシステムレベルで | |
5278 | これは C<$REMOTE> というファイルハンドルをシステムレベルで | |
4258 | 5279 | 非ブロックモードにセットする例です。 |
4259 | ただし、 C<$|> を自分で管理しなければなりません。 | |
5280 | ただし、 L<C<$E<verbar>>|perlvar/$E<verbar>> を自分で管理しなければなりません。 | |
4260 | 5281 | |
4261 | 5282 | use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK); |
4262 | 5283 | |
4263 | $flags = fcntl(REMOTE, F_GETFL, 0) | |
5284 | my $flags = fcntl($REMOTE, F_GETFL, 0) | |
4264 | | |
5285 | or die "Can't get flags for the socket: $!\n"; | |
4265 | 5286 | |
4266 | | |
5287 | fcntl($REMOTE, F_SETFL, $flags | O_NONBLOCK) | |
4267 | | |
5288 | or die "Can't set flags for the socket: $!\n"; | |
4268 | 5289 | |
5290 | =begin original | |
5291 | ||
5292 | Portability issues: L<perlport/fcntl>. | |
5293 | ||
5294 | =end original | |
5295 | ||
5296 | 移植性の問題: L<perlport/fcntl>。 | |
5297 | ||
5298 | =item __FILE__ | |
5299 | X<__FILE__> | |
5300 | ||
5301 | =for Pod::Functions the name of the current source file | |
5302 | ||
5303 | =begin original | |
5304 | ||
5305 | A special token that returns the name of the file in which it occurs. | |
5306 | ||
5307 | =end original | |
5308 | ||
5309 | これが書いてあるファイルの名前を返す特殊トークン。 | |
5310 | ||
4269 | 5311 | =item fileno FILEHANDLE |
4270 | 5312 | X<fileno> |
4271 | 5313 | |
5314 | =for Pod::Functions return file descriptor from filehandle | |
5315 | ||
4272 | 5316 | =begin original |
4273 | 5317 | |
4274 | 5318 | Returns the file descriptor for a filehandle, or undefined if the |
4275 | 5319 | filehandle is not open. If there is no real file descriptor at the OS |
4276 | 5320 | level, as can happen with filehandles connected to memory objects via |
4277 | C<open> with a reference for the third | |
5321 | L<C<open>|/open FILEHANDLE,EXPR> with a reference for the third | |
5322 | argument, -1 is returned. | |
4278 | 5323 | |
4279 | 5324 | =end original |
4280 | 5325 | |
4281 | ファイルハンドルに対するファイル記述子を返します | |
5326 | ファイルハンドルに対するファイル記述子を返します; ファイルハンドルが | |
4282 | ||
5327 | オープンしていない場合は未定義値を返します。 | |
4283 | OS レベルで実際のファイル記述子がない(C<open> | |
5328 | OS レベルで実際のファイル記述子がない(L<C<open>|/open FILEHANDLE,EXPR> の | |
5329 | 第 3 引数にリファレンスを | |
4284 | 5330 | 指定してファイルハンドルがメモリオブジェクトと結びつけられたときに |
4285 | 5331 | 起こります)場合、-1 が返されます。 |
4286 | 5332 | |
4287 | 5333 | =begin original |
4288 | 5334 | |
4289 | This is mainly useful for constructing | |
5335 | This is mainly useful for constructing bitmaps for | |
4290 | ||
5336 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> and low-level POSIX | |
5337 | tty-handling operations. | |
4291 | 5338 | If FILEHANDLE is an expression, the value is taken as an indirect |
4292 | 5339 | filehandle, generally its name. |
4293 | 5340 | |
4294 | 5341 | =end original |
4295 | 5342 | |
4296 | これは主に C<select> や低レベル | |
5343 | これは主に L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> や低レベル | |
4297 | 構成するときに便利です。 | |
5344 | POSIX tty 操作に対する、ビットマップを構成するときに便利です。 | |
4298 | 5345 | FILEHANDLE が式であれば、 |
4299 | 5346 | その値が間接ファイルハンドル(普通は名前)として使われます。 |
4300 | 5347 | |
4301 | 5348 | =begin original |
4302 | 5349 | |
4303 | 5350 | You can use this to find out whether two handles refer to the |
4304 | 5351 | same underlying descriptor: |
4305 | 5352 | |
4306 | 5353 | =end original |
4307 | 5354 | |
4308 | 5355 | これを、二つのハンドルが同じ識別子を参照しているかどうかを見つけるのに |
4309 | 5356 | 使えます: |
4310 | 5357 | |
4311 | if (fileno( | |
5358 | if (fileno($this) != -1 && fileno($this) == fileno($that)) { | |
4312 | print " | |
5359 | print "\$this and \$that are dups\n"; | |
5360 | } elsif (fileno($this) != -1 && fileno($that) != -1) { | |
5361 | print "\$this and \$that have different " . | |
5362 | "underlying file descriptors\n"; | |
5363 | } else { | |
5364 | print "At least one of \$this and \$that does " . | |
5365 | "not have a real file descriptor\n"; | |
4313 | 5366 | } |
4314 | 5367 | |
5368 | =begin original | |
5369 | ||
5370 | The behavior of L<C<fileno>|/fileno FILEHANDLE> on a directory handle | |
5371 | depends on the operating system. On a system with L<dirfd(3)> or | |
5372 | similar, L<C<fileno>|/fileno FILEHANDLE> on a directory | |
5373 | handle returns the underlying file descriptor associated with the | |
5374 | handle; on systems with no such support, it returns the undefined value, | |
5375 | and sets L<C<$!>|perlvar/$!> (errno). | |
5376 | ||
5377 | =end original | |
5378 | ||
5379 | ディレクトリハンドルに対する L<C<fileno>|/fileno FILEHANDLE> の振る舞いは | |
5380 | オペレーティングシステムに依存します。 | |
5381 | L<dirfd(3)> のようなものがあるシステムでは、ディレクトリハンドルに対する | |
5382 | L<C<fileno>|/fileno FILEHANDLE> はハンドルに関連付けられた基となる | |
5383 | ファイル記述子を返します; | |
5384 | そのような対応がないシステムでは、未定義値を返し、 | |
5385 | L<C<$!>|perlvar/$!> (errno) を設定します。 | |
5386 | ||
4315 | 5387 | =item flock FILEHANDLE,OPERATION |
4316 | 5388 | X<flock> X<lock> X<locking> |
4317 | 5389 | |
5390 | =for Pod::Functions lock an entire file with an advisory lock | |
5391 | ||
4318 | 5392 | =begin original |
4319 | 5393 | |
4320 | Calls flock(2), or an emulation of it, on FILEHANDLE. Returns true | |
5394 | Calls L<flock(2)>, or an emulation of it, on FILEHANDLE. Returns true | |
4321 | 5395 | for success, false on failure. Produces a fatal error if used on a |
4322 | machine that doesn't implement flock(2), fcntl(2) locking, or | |
5396 | machine that doesn't implement L<flock(2)>, L<fcntl(2)> locking, or | |
4323 | C<flock> is Perl's portable | |
5397 | L<lockf(3)>. L<C<flock>|/flock FILEHANDLE,OPERATION> is Perl's portable | |
4324 | entire files only, not | |
5398 | file-locking interface, although it locks entire files only, not | |
5399 | records. | |
4325 | 5400 | |
4326 | 5401 | =end original |
4327 | 5402 | |
4328 | FILEHANDLE に対して flock(2)、またはそのエミュレーションを呼び出します。 | |
5403 | FILEHANDLE に対して L<flock(2)>、またはそのエミュレーションを呼び出します。 | |
4329 | 5404 | 成功時には真を、失敗時には偽を返します。 |
4330 | flock(2), fcntl(2) ロック, lockf(3) のいずれかを実装していない | |
5405 | L<flock(2)>, L<fcntl(2)> ロック, L<lockf(3)> のいずれかを実装していない | |
4331 | 5406 | マシンで使うと、致命的エラーが発生します。 |
4332 | C<flock> は Perl の移植性のある | |
5407 | L<C<flock>|/flock FILEHANDLE,OPERATION> は Perl の移植性のある | |
5408 | ファイルロックインターフェースです; | |
4333 | 5409 | しかしレコードではなく、ファイル全体のみをロックします。 |
4334 | 5410 | |
4335 | 5411 | =begin original |
4336 | 5412 | |
4337 | Two potentially non-obvious but traditional C<flock> | |
5413 | Two potentially non-obvious but traditional L<C<flock>|/flock | |
5414 | FILEHANDLE,OPERATION> semantics are | |
4338 | 5415 | that it waits indefinitely until the lock is granted, and that its locks |
4339 | 5416 | are B<merely advisory>. Such discretionary locks are more flexible, but |
4340 | 5417 | offer fewer guarantees. This means that programs that do not also use |
4341 | C<flock> may modify files locked with | |
5418 | L<C<flock>|/flock FILEHANDLE,OPERATION> may modify files locked with | |
5419 | L<C<flock>|/flock FILEHANDLE,OPERATION>. See L<perlport>, | |
4342 | 5420 | your port's specific documentation, and your system-specific local manpages |
4343 | 5421 | for details. It's best to assume traditional behavior if you're writing |
4344 | 5422 | portable programs. (But if you're not, you should as always feel perfectly |
4345 | 5423 | free to write for your own system's idiosyncrasies (sometimes called |
4346 | 5424 | "features"). Slavish adherence to portability concerns shouldn't get |
4347 | 5425 | in the way of your getting your job done.) |
4348 | 5426 | |
4349 | 5427 | =end original |
4350 | 5428 | |
4351 | 明白ではないものの、伝統的な C<flock> の | |
5429 | 明白ではないものの、伝統的な L<C<flock>|/flock FILEHANDLE,OPERATION> の | |
5430 | 動作としては、ロックが得られるまで | |
4352 | 5431 | 無限に待ち続けるものと、B<単に勧告的に> ロックするものの二つがあります。 |
4353 | 5432 | このような自由裁量のロックはより柔軟ですが、保障されるものはより少ないです。 |
4354 | これは、C<flock> を使わないプログラムが | |
5433 | これは、L<C<flock>|/flock FILEHANDLE,OPERATION> を使わないプログラムが | |
5434 | L<C<flock>|/flock FILEHANDLE,OPERATION> でロックされたファイルを | |
4355 | 5435 | 書き換えるかもしれないことを意味します。 |
4356 | 5436 | 詳細については、L<perlport>、システム固有のドキュメント、システム固有の |
4357 | 5437 | ローカルの man ページを参照してください。 |
4358 | 5438 | 移植性のあるプログラムを書く場合は、伝統的な振る舞いを仮定するのが |
4359 | 5439 | ベストです。 |
4360 | 5440 | (しかし移植性のないプログラムを書く場合は、自身のシステムの性癖(しばしば |
4361 | 5441 | 「仕様」と呼ばれます)に合わせて書くことも完全に自由です。 |
4362 | 5442 | 盲目的に移植性に固執することで、あなたの作業を仕上げるのを邪魔するべきでは |
4363 | 5443 | ありません。) |
4364 | 5444 | |
4365 | 5445 | =begin original |
4366 | 5446 | |
4367 | 5447 | OPERATION is one of LOCK_SH, LOCK_EX, or LOCK_UN, possibly combined with |
4368 | 5448 | LOCK_NB. These constants are traditionally valued 1, 2, 8 and 4, but |
4369 | 5449 | you can use the symbolic names if you import them from the L<Fcntl> module, |
4370 | 5450 | either individually, or as a group using the C<:flock> tag. LOCK_SH |
4371 | 5451 | requests a shared lock, LOCK_EX requests an exclusive lock, and LOCK_UN |
4372 | 5452 | releases a previously requested lock. If LOCK_NB is bitwise-or'ed with |
4373 | LOCK_SH or LOCK_EX, then C<flock> returns | |
5453 | LOCK_SH or LOCK_EX, then L<C<flock>|/flock FILEHANDLE,OPERATION> returns | |
4374 | waiting for the lock; check the return | |
5454 | immediately rather than blocking waiting for the lock; check the return | |
5455 | status to see if you got it. | |
4375 | 5456 | |
4376 | 5457 | =end original |
4377 | 5458 | |
4378 | 5459 | OPERATION は LOCK_SH, LOCK_EX, LOCK_UN のいずれかで、LOCK_NB と |
4379 | 5460 | 組み合わされることもあります。 |
4380 | 5461 | これらの定数は伝統的には 1, 2, 8, 4 の値を持ちますが、L<Fcntl> モジュールから |
4381 | 5462 | シンボル名を独立してインポートするか、C<:flock> タグを使うグループとして、 |
4382 | 5463 | シンボル名をを使うことができます。 |
4383 | 5464 | LOCK_SH は共有ロックを要求し、LOCK_EX は排他ロックを要求し、LOCK_UN は |
4384 | 5465 | 前回要求したロックを開放します。 |
4385 | LOCK_NB と LOCK_SH か LOCK_EX がビット単位の論理和されると、 | |
5466 | LOCK_NB と LOCK_SH か LOCK_EX がビット単位の論理和されると、 | |
5467 | L<C<flock>|/flock FILEHANDLE,OPERATION> は | |
4386 | 5468 | ロックを取得するまで待つのではなく、すぐに返ります; |
4387 | 5469 | ロックが取得できたかどうかは返り値を調べます。 |
4388 | 5470 | |
4389 | 5471 | =begin original |
4390 | 5472 | |
4391 | 5473 | To avoid the possibility of miscoordination, Perl now flushes FILEHANDLE |
4392 | 5474 | before locking or unlocking it. |
4393 | 5475 | |
4394 | 5476 | =end original |
4395 | 5477 | |
4396 | 5478 | 不一致の可能性を避けるために、Perl はファイルをロック、アンロックする前に |
4397 | 5479 | FILEHANDLE をフラッシュします。 |
4398 | 5480 | |
4399 | 5481 | =begin original |
4400 | 5482 | |
4401 | Note that the emulation built with lockf(3) doesn't provide shared | |
5483 | Note that the emulation built with L<lockf(3)> doesn't provide shared | |
4402 | 5484 | locks, and it requires that FILEHANDLE be open with write intent. These |
4403 | are the semantics that lockf(3) implements. Most if not all systems | |
5485 | are the semantics that L<lockf(3)> implements. Most if not all systems | |
4404 | implement lockf(3) in terms of fcntl(2) locking, though, so the | |
5486 | implement L<lockf(3)> in terms of L<fcntl(2)> locking, though, so the | |
4405 | 5487 | differing semantics shouldn't bite too many people. |
4406 | 5488 | |
4407 | 5489 | =end original |
4408 | 5490 | |
4409 | lockf(3) で作成されたエミュレーションは共有ロックを提供せず、 | |
5491 | L<lockf(3)> で作成されたエミュレーションは共有ロックを提供せず、 | |
4410 | 5492 | FILEHANDLE が書き込みモードで開いていることを必要とすることに |
4411 | 5493 | 注意してください。 |
4412 | これは lockf(3) が実装している動作です。 | |
5494 | これは L<lockf(3)> が実装している動作です。 | |
4413 | しかし、全てではないにしてもほとんどのシステムでは fcntl(2) を使って | |
5495 | しかし、全てではないにしてもほとんどのシステムでは L<fcntl(2)> を使って | |
4414 | lockf(3) を実装しているので、異なった動作で多くの人々を混乱させることは | |
5496 | L<lockf(3)> を実装しているので、異なった動作で多くの人々を混乱させることは | |
4415 | 5497 | ないはずです。 |
4416 | 5498 | |
4417 | 5499 | =begin original |
4418 | 5500 | |
4419 | Note that the fcntl(2) emulation of flock(3) requires that FILEHANDLE | |
5501 | Note that the L<fcntl(2)> emulation of L<flock(3)> requires that FILEHANDLE | |
4420 | 5502 | be open with read intent to use LOCK_SH and requires that it be open |
4421 | 5503 | with write intent to use LOCK_EX. |
4422 | 5504 | |
4423 | 5505 | =end original |
4424 | 5506 | |
4425 | flock(3) の fcntl(2) エミュレーションは、 LOCK_SH を使うためには | |
5507 | L<flock(3)> の L<fcntl(2)> エミュレーションは、 LOCK_SH を使うためには | |
4426 | 5508 | FILEHANDLE を読み込みで開いている必要があり、LOCK_EX を使うためには |
4427 | 5509 | 書き込みで開いている必要があることに注意してください。 |
4428 | 5510 | |
4429 | 5511 | =begin original |
4430 | 5512 | |
4431 | Note also that some versions of C<flock> | |
5513 | Note also that some versions of L<C<flock>|/flock FILEHANDLE,OPERATION> | |
4432 | network; you would need to use the more | |
5514 | cannot lock things over the network; you would need to use the more | |
4433 | t | |
5515 | system-specific L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> for | |
4434 | ||
5516 | that. If you like you can force Perl to ignore your system's L<flock(2)> | |
5517 | function, and so provide its own L<fcntl(2)>-based emulation, by passing | |
4435 | 5518 | the switch C<-Ud_flock> to the F<Configure> program when you configure |
4436 | 5519 | and build a new Perl. |
4437 | 5520 | |
4438 | 5521 | =end original |
4439 | 5522 | |
4440 | ネットワーク越しにはロックできない C<flock> も | |
5523 | ネットワーク越しにはロックできない L<C<flock>|/flock FILEHANDLE,OPERATION> も | |
4441 | こ | |
5524 | あることに注意してください; | |
4442 | ||
5525 | このためには、よりシステム依存な | |
5526 | L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> を使う必要があります。 | |
5527 | Perl にシステムの L<flock(2)> 関数を無視させ、自身の L<fcntl(2)> ベースの | |
4443 | 5528 | エミュレーションを使う場合は、新しい Perl を設定およびビルドするときに |
4444 | 5529 | F<Configure> プログラムに C<-Ud_flock> オプションを渡してください。 |
4445 | 5530 | |
4446 | 5531 | =begin original |
4447 | 5532 | |
4448 | 5533 | Here's a mailbox appender for BSD systems. |
4449 | 5534 | |
4450 | 5535 | =end original |
4451 | 5536 | |
4452 | 5537 | BSD システムでのメールボックスへの追加処理の例を示します。 |
4453 | 5538 | |
4454 | | |
5539 | # import LOCK_* and SEEK_END constants | |
5540 | use Fcntl qw(:flock SEEK_END); | |
4455 | 5541 | |
4456 | 5542 | sub lock { |
4457 | 5543 | my ($fh) = @_; |
4458 | 5544 | flock($fh, LOCK_EX) or die "Cannot lock mailbox - $!\n"; |
4459 | 5545 | |
4460 | 5546 | # and, in case someone appended while we were waiting... |
4461 | 5547 | seek($fh, 0, SEEK_END) or die "Cannot seek - $!\n"; |
4462 | 5548 | } |
4463 | 5549 | |
4464 | 5550 | sub unlock { |
4465 | 5551 | my ($fh) = @_; |
4466 | 5552 | flock($fh, LOCK_UN) or die "Cannot unlock mailbox - $!\n"; |
4467 | 5553 | } |
4468 | 5554 | |
4469 | 5555 | open(my $mbox, ">>", "/usr/spool/mail/$ENV{'USER'}") |
4470 | 5556 | or die "Can't open mailbox: $!"; |
4471 | 5557 | |
4472 | 5558 | lock($mbox); |
4473 | 5559 | print $mbox $msg,"\n\n"; |
4474 | 5560 | unlock($mbox); |
4475 | 5561 | |
4476 | 5562 | =begin original |
4477 | 5563 | |
4478 | On systems that support a real flock(2), locks are inherited across | |
5564 | On systems that support a real L<flock(2)>, locks are inherited across | |
4479 | calls, whereas those that must resort to the more | |
5565 | L<C<fork>|/fork> calls, whereas those that must resort to the more | |
4480 | function lose their locks, making it seriously | |
5566 | capricious L<fcntl(2)> function lose their locks, making it seriously | |
5567 | harder to write servers. | |
4481 | 5568 | |
4482 | 5569 | =end original |
4483 | 5570 | |
4484 | 真の flock(2) に対応しているシステムではロックは fork | |
5571 | 真の L<flock(2)> に対応しているシステムではロックは L<C<fork>|/fork> を通して | |
4485 | 継承されるのに対して、より不安定な fcntl(2) に頼らなければならない場合、 | |
5572 | 継承されるのに対して、より不安定な L<fcntl(2)> に頼らなければならない場合、 | |
4486 | 5573 | サーバを書くのは本当により難しくなります。 |
4487 | 5574 | |
4488 | 5575 | =begin original |
4489 | 5576 | |
4490 | See also L<DB_File> for other flock | |
5577 | See also L<DB_File> for other L<C<flock>|/flock FILEHANDLE,OPERATION> | |
5578 | examples. | |
4491 | 5579 | |
4492 | 5580 | =end original |
4493 | 5581 | |
4494 | その他の flock | |
5582 | その他の L<C<flock>|/flock FILEHANDLE,OPERATION> の例としては L<DB_File> も | |
5583 | 参照してください。 | |
4495 | 5584 | |
5585 | =begin original | |
5586 | ||
5587 | Portability issues: L<perlport/flock>. | |
5588 | ||
5589 | =end original | |
5590 | ||
5591 | 移植性の問題: L<perlport/flock>。 | |
5592 | ||
4496 | 5593 | =item fork |
4497 | 5594 | X<fork> X<child> X<parent> |
4498 | 5595 | |
5596 | =for Pod::Functions create a new process just like this one | |
5597 | ||
4499 | 5598 | =begin original |
4500 | 5599 | |
4501 | Does a fork(2) system call to create a new process running the | |
5600 | Does a L<fork(2)> system call to create a new process running the | |
4502 | 5601 | same program at the same point. It returns the child pid to the |
4503 | parent process, C<0> to the child process, or C<undef> | |
5602 | parent process, C<0> to the child process, or L<C<undef>|/undef EXPR> if | |
5603 | the fork is | |
4504 | 5604 | unsuccessful. File descriptors (and sometimes locks on those descriptors) |
4505 | 5605 | are shared, while everything else is copied. On most systems supporting |
4506 | fork(), great care has gone into making it extremely efficient (for | |
5606 | L<fork(2)>, great care has gone into making it extremely efficient (for | |
4507 | 5607 | example, using copy-on-write technology on data pages), making it the |
4508 | 5608 | dominant paradigm for multitasking over the last few decades. |
4509 | 5609 | |
4510 | 5610 | =end original |
4511 | 5611 | |
4512 | 5612 | 同じプログラムの同じ地点から開始する新しいプロセスを作成するために |
4513 | システムコール fork(2) を行ないます。 | |
5613 | システムコール L<fork(2)> を行ないます。 | |
4514 | 5614 | 親プロセスには、チャイルドプロセスの pid を、 |
4515 | 5615 | チャイルドプロセスに C<0> を返しますが、 |
4516 | fork に失敗したときには、C<undef>を返します。 | |
5616 | fork に失敗したときには、L<C<undef>|/undef EXPR>を返します。 | |
4517 | 5617 | ファイル記述子(および記述子に関連するロック)は共有され、 |
4518 | 5618 | その他の全てはコピーされます。 |
4519 | fork() に対応するほとんどのシステムでは、 | |
5619 | L<fork(2)> に対応するほとんどのシステムでは、 | |
4520 | 5620 | これを極めて効率的にするために多大な努力が払われてきました |
4521 | (例えば、データページへの copy-on-write テクノロジーなどです) | |
5621 | (例えば、データページへの copy-on-write テクノロジーなどです); | |
4522 | 5622 | これはここ 20 年にわたるマルチタスクに関する主要なパラダイムとなっています。 |
4523 | 5623 | |
4524 | 5624 | =begin original |
4525 | 5625 | |
4526 | ||
5626 | Perl attempts to flush all files opened for output before forking the | |
4527 | ||
5627 | child process, but this may not be supported on some platforms (see | |
4528 | ||
5628 | L<perlport>). To be safe, you may need to set | |
4529 | C<$|> ($AUTOFLUSH in English) or | |
5629 | L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>) or | |
4530 | C< | |
5630 | call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS> on | |
5631 | any open handles to avoid duplicate output. | |
4531 | 5632 | |
4532 | 5633 | =end original |
4533 | 5634 | |
4534 | 5635 | v5.6.0 から、Perl は子プロセスを fork する前に出力用にオープンしている全ての |
4535 | 5636 | ファイルをフラッシュしようとしますが、これに対応していないプラットフォームも |
4536 | 5637 | あります(L<perlport> を参照してください)。 |
4537 | 5638 | 安全のためには、出力が重複するのを避けるために、 |
4538 | 全てのオープンしているハンドルに対して C<$ | |
5639 | 全てのオープンしているハンドルに対して L<C<$E<verbar>>|perlvar/$E<verbar>> | |
4539 | $AUTOFLUSH) を設定するか、 | |
5640 | (L<English> モジュールでは C<$AUTOFLUSH>) を設定するか、 | |
4540 | C<IO::Handle> モジュールの C<autoflush | |
5641 | L<C<IO::Handle>|IO::Handle/METHODS> モジュールの C<autoflush> メソッドを | |
4541 | あるかもしれません。 | |
5642 | 呼ぶ必要があるかもしれません。 | |
4542 | 5643 | |
4543 | 5644 | =begin original |
4544 | 5645 | |
4545 | If you C<fork> without ever waiting on your children, you will | |
5646 | If you L<C<fork>|/fork> without ever waiting on your children, you will | |
4546 | 5647 | accumulate zombies. On some systems, you can avoid this by setting |
4547 | C<$SIG{CHLD}> to C<"IGNORE">. See also L<perlipc> for | |
5648 | L<C<$SIG{CHLD}>|perlvar/%SIG> to C<"IGNORE">. See also L<perlipc> for | |
4548 | forking and reaping moribund children. | |
5649 | more examples of forking and reaping moribund children. | |
4549 | 5650 | |
4550 | 5651 | =end original |
4551 | 5652 | |
4552 | チャイルドプロセスの終了を待たずに、C<fork> を繰り返せば、 | |
5653 | チャイルドプロセスの終了を待たずに、L<C<fork>|/fork> を繰り返せば、 | |
4553 | 5654 | ゾンビをためこむことになります。 |
4554 | C<$SIG{CHLD}> に C<"IGNORE"> を指定することでこれを | |
5655 | L<C<$SIG{CHLD}>|perlvar/%SIG> に C<"IGNORE"> を指定することでこれを | |
5656 | 回避できるシステムもあります。 | |
4555 | 5657 | fork と消滅しかけている子プロセスを回収するための更なる例については |
4556 | 5658 | L<perlipc> も参照してください。 |
4557 | 5659 | |
4558 | 5660 | =begin original |
4559 | 5661 | |
4560 | 5662 | Note that if your forked child inherits system file descriptors like |
4561 | 5663 | STDIN and STDOUT that are actually connected by a pipe or socket, even |
4562 | 5664 | if you exit, then the remote server (such as, say, a CGI script or a |
4563 | 5665 | backgrounded job launched from a remote shell) won't think you're done. |
4564 | 5666 | You should reopen those to F</dev/null> if it's any issue. |
4565 | 5667 | |
4566 | 5668 | =end original |
4567 | 5669 | |
4568 | 5670 | fork した子プロセスが STDIN や STDOUT といったシステムファイル記述子を |
4569 | 5671 | 継承する場合、(CGI スクリプトやリモートシェルといった |
4570 | 5672 | バックグラウンドジョブのような)リモートサーバは考え通りに |
4571 | 5673 | 動かないであろうことに注意してください。 |
4572 | 5674 | このような場合ではこれらを F</dev/null> として再オープンするべきです。 |
4573 | 5675 | |
5676 | =begin original | |
5677 | ||
5678 | On some platforms such as Windows, where the L<fork(2)> system call is | |
5679 | not available, Perl can be built to emulate L<C<fork>|/fork> in the Perl | |
5680 | interpreter. The emulation is designed, at the level of the Perl | |
5681 | program, to be as compatible as possible with the "Unix" L<fork(2)>. | |
5682 | However it has limitations that have to be considered in code intended | |
5683 | to be portable. See L<perlfork> for more details. | |
5684 | ||
5685 | =end original | |
5686 | ||
5687 | Windows のような L<fork(2)> が利用不能なシステムでは、Perl は | |
5688 | L<C<fork>|/fork> を Perl インタプリタでエミュレートします。 | |
5689 | エミュレーションは Perl プログラムのレベルではできるだけ "Unix" L<fork(2)> と | |
5690 | 互換性があるように設計されています。 | |
5691 | しかしコードが移植性があると考えられるように制限があります。 | |
5692 | さらなる詳細については L<perlfork> を参照してください。 | |
5693 | ||
5694 | =begin original | |
5695 | ||
5696 | Portability issues: L<perlport/fork>. | |
5697 | ||
5698 | =end original | |
5699 | ||
5700 | 移植性の問題: L<perlport/fork>。 | |
5701 | ||
4574 | 5702 | =item format |
4575 | 5703 | X<format> |
4576 | 5704 | |
5705 | =for Pod::Functions declare a picture format with use by the write() function | |
5706 | ||
4577 | 5707 | =begin original |
4578 | 5708 | |
4579 | Declare a picture format for use by the C<write> | |
5709 | Declare a picture format for use by the L<C<write>|/write FILEHANDLE> | |
4580 | example: | |
5710 | function. For example: | |
4581 | 5711 | |
4582 | 5712 | =end original |
4583 | 5713 | |
4584 | C<write> 関数で使うピクチャーフォーマットを宣言します。 | |
5714 | L<C<write>|/write FILEHANDLE> 関数で使うピクチャーフォーマットを宣言します。 | |
4585 | 例: | |
5715 | 例えば: | |
4586 | 5716 | |
4587 | 5717 | format Something = |
4588 | 5718 | Test: @<<<<<<<< @||||| @>>>>> |
4589 | 5719 | $str, $%, '$' . int($num) |
4590 | 5720 | . |
4591 | 5721 | |
4592 | 5722 | $str = "widget"; |
4593 | 5723 | $num = $cost/$quantity; |
4594 | 5724 | $~ = 'Something'; |
4595 | 5725 | write; |
4596 | 5726 | |
4597 | 5727 | =begin original |
4598 | 5728 | |
4599 | 5729 | See L<perlform> for many details and examples. |
4600 | 5730 | |
4601 | 5731 | =end original |
4602 | 5732 | |
4603 | 詳細と例については L<perlform> を参照して | |
5733 | 詳細と例については L<perlform> を参照してください。 | |
4604 | 5734 | |
4605 | 5735 | =item formline PICTURE,LIST |
4606 | 5736 | X<formline> |
4607 | 5737 | |
5738 | =for Pod::Functions internal function used for formats | |
5739 | ||
4608 | 5740 | =begin original |
4609 | 5741 | |
4610 | This is an internal function used by C<format>s, though you | |
5742 | This is an internal function used by L<C<format>|/format>s, though you | |
4611 | too. It formats (see L<perlform>) a list of values | |
5743 | may call it, too. It formats (see L<perlform>) a list of values | |
4612 | contents of PICTURE, placing the output into the forma | |
5744 | according to the contents of PICTURE, placing the output into the format | |
4613 | accumulator, C<$^A> (or C<$ACCUMULATOR> in | |
5745 | output accumulator, L<C<$^A>|perlvar/$^A> (or C<$ACCUMULATOR> in | |
4614 | Eventually, when a C<write> is done, | |
5746 | L<English>). Eventually, when a L<C<write>|/write FILEHANDLE> is done, | |
4615 | C<$^A> are written to some filehandle. | |
5747 | the contents of L<C<$^A>|perlvar/$^A> are written to some filehandle. | |
4616 | ||
5748 | You could also read L<C<$^A>|perlvar/$^A> and then set | |
4617 | ||
5749 | L<C<$^A>|perlvar/$^A> back to C<"">. Note that a format typically does | |
4618 | ||
5750 | one L<C<formline>|/formline PICTURE,LIST> per line of form, but the | |
4619 | ||
5751 | L<C<formline>|/formline PICTURE,LIST> function itself doesn't care how | |
4620 | ||
5752 | many newlines are embedded in the PICTURE. This means that the C<~> and | |
4621 | ||
5753 | C<~~> tokens treat the entire PICTURE as a single line. You may | |
5754 | therefore need to use multiple formlines to implement a single record | |
5755 | format, just like the L<C<format>|/format> compiler. | |
4622 | 5756 | |
4623 | 5757 | =end original |
4624 | 5758 | |
4625 | これは、C<format> が使用する内部関数ですが、直接呼び出すことも | |
5759 | これは、L<C<format>|/format> が使用する内部関数ですが、直接呼び出すことも | |
5760 | できます。 | |
4626 | 5761 | これは、PICTURE の内容にしたがって、LIST の値を整形し (L<perlform> を |
4627 | 参照してください)、結果をフォーマット出力アキュムレータC<$^A> | |
5762 | 参照してください)、結果をフォーマット出力アキュムレータL<C<$^A>|perlvar/$^A> | |
4628 | (English モジュールでは C<$ACCUMULATOR>) に納めます。 | |
5763 | (L<English> モジュールでは C<$ACCUMULATOR>) に納めます。 | |
4629 | 最終的に、C<write> が実行されると | |
5764 | 最終的に、L<C<write>|/write FILEHANDLE> が実行されると、 | |
4630 | 何らかのファイルハンドルに書き出されます。 | |
5765 | L<C<$^A>|perlvar/$^A> の中身が、何らかのファイルハンドルに書き出されます。 | |
4631 | また、自分で C<$^A> を読んで、C<$^A> の内容を | |
5766 | また、自分で L<C<$^A>|perlvar/$^A> を読んで、L<C<$^A>|perlvar/$^A> の内容を | |
4632 | ||
5767 | C<""> に戻してもかまいません。 | |
4633 | C<formline> | |
5768 | format は通常、1 行ごとに L<C<formline>|/formline PICTURE,LIST> を | |
4634 | ||
5769 | 行ないますが、L<C<formline>|/formline PICTURE,LIST> 関数自身は、PICTURE の中に | |
5770 | いくつの改行が入っているかは、関係がありません。 | |
4635 | 5771 | これは、C<~> と C<~~>トークンは PICTURE 全体を一行として扱うことを意味します。 |
4636 | 5772 | 従って、1 レコードフォーマットを実装するためには |
4637 | ||
5773 | L<C<format>|/format> コンパイラのような複数 formline を使う必要があります。 | |
4638 | 5774 | |
4639 | 5775 | =begin original |
4640 | 5776 | |
4641 | 5777 | Be careful if you put double quotes around the picture, because an C<@> |
4642 | 5778 | character may be taken to mean the beginning of an array name. |
4643 | C<formline> always returns true. See | |
5779 | L<C<formline>|/formline PICTURE,LIST> always returns true. See | |
5780 | L<perlform> for other examples. | |
4644 | 5781 | |
4645 | 5782 | =end original |
4646 | 5783 | |
4647 | 5784 | ダブルクォートで PICTURE を囲む場合には、C<@> という文字が |
4648 | 5785 | 配列名の始まりと解釈されますので、注意してください。 |
4649 | C<formline> は常に真を返します。 | |
5786 | L<C<formline>|/formline PICTURE,LIST> は常に真を返します。 | |
4650 | 5787 | その他の例については L<perlform> を参照してください。 |
4651 | 5788 | |
4652 | 5789 | =begin original |
4653 | 5790 | |
4654 | If you are trying to use this instead of C<write> | |
5791 | If you are trying to use this instead of L<C<write>|/write FILEHANDLE> | |
4655 | you may find it easier to open a filehandle to a | |
5792 | to capture the output, you may find it easier to open a filehandle to a | |
4656 | (C<< open $fh, ">", \$output >>) and write to that instead. | |
5793 | scalar (C<< open my $fh, ">", \$output >>) and write to that instead. | |
4657 | 5794 | |
4658 | 5795 | =end original |
4659 | 5796 | |
4660 | 出力を捕捉するために C<write> の代わりにこれを | |
5797 | 出力を捕捉するために L<C<write>|/write FILEHANDLE> の代わりにこれを | |
4661 | スカラにファイルハンドルを開いて | |
5798 | 使おうとした場合、スカラにファイルハンドルを開いて | |
5799 | (C<< open my $fh, ">", \$output >>)、 | |
4662 | 5800 | 代わりにここに出力する方が簡単であることに気付くでしょう。 |
4663 | 5801 | |
4664 | 5802 | =item getc FILEHANDLE |
4665 | 5803 | X<getc> X<getchar> X<character> X<file, read> |
4666 | 5804 | |
4667 | 5805 | =item getc |
4668 | 5806 | |
5807 | =for Pod::Functions get the next character from the filehandle | |
5808 | ||
4669 | 5809 | =begin original |
4670 | 5810 | |
4671 | 5811 | Returns the next character from the input file attached to FILEHANDLE, |
4672 | 5812 | or the undefined value at end of file or if there was an error (in |
4673 | the latter case C<$!> is set). If FILEHANDLE is omitted, | |
5813 | the latter case L<C<$!>|perlvar/$!> is set). If FILEHANDLE is omitted, | |
5814 | reads from | |
4674 | 5815 | STDIN. This is not particularly efficient. However, it cannot be |
4675 | 5816 | used by itself to fetch single characters without waiting for the user |
4676 | 5817 | to hit enter. For that, try something more like: |
4677 | 5818 | |
4678 | 5819 | =end original |
4679 | 5820 | |
4680 | FILEHANDLE につながれている入力ファイルから、次の一文字を返します | |
5821 | FILEHANDLE につながれている入力ファイルから、次の一文字を返します; | |
4681 | 5822 | ファイルの最後、またはエラーが発生した場合は、未定義値を返します |
4682 | (後者の場合は C<$!> がセットされます)。 | |
5823 | (後者の場合は L<C<$!>|perlvar/$!> がセットされます)。 | |
4683 | 5824 | FILEHANDLE が省略された場合には、STDIN から読み込みを行ないます。 |
4684 | 5825 | これは特に効率的ではありません。 |
4685 | 5826 | しかし、これはユーザーがリターンキーを押すのを待つことなく |
4686 | 5827 | 一文字を読み込む用途には使えません。 |
4687 | 5828 | そのような場合には、以下のようなものを試して見てください: |
4688 | 5829 | |
4689 | 5830 | if ($BSD_STYLE) { |
4690 | 5831 | system "stty cbreak </dev/tty >/dev/tty 2>&1"; |
4691 | 5832 | } |
4692 | 5833 | else { |
4693 | 5834 | system "stty", '-icanon', 'eol', "\001"; |
4694 | 5835 | } |
4695 | 5836 | |
4696 | $key = getc(STDIN); | |
5837 | my $key = getc(STDIN); | |
4697 | 5838 | |
4698 | 5839 | if ($BSD_STYLE) { |
4699 | 5840 | system "stty -cbreak </dev/tty >/dev/tty 2>&1"; |
4700 | 5841 | } |
4701 | 5842 | else { |
4702 | 5843 | system 'stty', 'icanon', 'eol', '^@'; # ASCII NUL |
4703 | 5844 | } |
4704 | 5845 | print "\n"; |
4705 | 5846 | |
4706 | 5847 | =begin original |
4707 | 5848 | |
4708 | Determination of whether $BSD_STYLE should be set | |
5849 | Determination of whether C<$BSD_STYLE> should be set is left as an | |
4709 | ||
5850 | exercise to the reader. | |
4710 | 5851 | |
4711 | 5852 | =end original |
4712 | 5853 | |
4713 | $BSD_STYLE をセットするべきかどうかを決定する方法については | |
5854 | C<$BSD_STYLE> をセットするべきかどうかを決定する方法については | |
4714 | 5855 | 読者への宿題として残しておきます。 |
4715 | 5856 | |
4716 | 5857 | =begin original |
4717 | 5858 | |
4718 | The C<POSIX::getattr> function can do this more | |
5859 | The L<C<POSIX::getattr>|POSIX/C<getattr>> function can do this more | |
4719 | systems purporting POSIX compliance. See also the | |
5860 | portably on systems purporting POSIX compliance. See also the | |
4720 | ||
5861 | L<C<Term::ReadKey>|Term::ReadKey> module on CPAN. | |
4721 | L<perlmodlib/CPAN>. | |
4722 | 5862 | |
4723 | 5863 | =end original |
4724 | 5864 | |
4725 | C<POSIX::getattr> 関数は POSIX 準拠を主張するシステムで | |
5865 | L<C<POSIX::getattr>|POSIX/C<getattr>> 関数は POSIX 準拠を主張するシステムで | |
4726 | より移植性のある形で行います。 | |
5866 | これをより移植性のある形で行います。 | |
4727 | ||
5867 | CPAN にある L<C<Term::ReadKey>|Term::ReadKey> モジュールも | |
4728 | ||
5868 | 参照してください。 | |
4729 | 5869 | |
4730 | 5870 | =item getlogin |
4731 | 5871 | X<getlogin> X<login> |
4732 | 5872 | |
5873 | =for Pod::Functions return who logged in at this tty | |
5874 | ||
4733 | 5875 | =begin original |
4734 | 5876 | |
4735 | 5877 | This implements the C library function of the same name, which on most |
4736 | 5878 | systems returns the current login from F</etc/utmp>, if any. If it |
4737 | returns the empty string, use C<getpwuid>. | |
5879 | returns the empty string, use L<C<getpwuid>|/getpwuid UID>. | |
4738 | 5880 | |
4739 | 5881 | =end original |
4740 | 5882 | |
4741 | 5883 | これは同じ名前の C ライブラリ関数を実装していて、 |
4742 | 多くのシステムでは、もしあれば、/etc/utmp から現在のログイン名を返します。 | |
5884 | 多くのシステムでは、もしあれば、F</etc/utmp> から現在のログイン名を返します。 | |
4743 | もし空文字列が返ってきた場合は、getpwuid | |
5885 | もし空文字列が返ってきた場合は、L<C<getpwuid>|/getpwuid UID> を | |
5886 | 使ってください。 | |
4744 | 5887 | |
4745 | $login = getlogin || getpwuid($<) || "Kilroy"; | |
5888 | my $login = getlogin || getpwuid($<) || "Kilroy"; | |
4746 | 5889 | |
4747 | 5890 | =begin original |
4748 | 5891 | |
4749 | Do not consider C<getlogin> for authentication: it is not | |
5892 | Do not consider L<C<getlogin>|/getlogin> for authentication: it is not | |
4750 | secure as C<getpwuid>. | |
5893 | as secure as L<C<getpwuid>|/getpwuid UID>. | |
4751 | 5894 | |
4752 | 5895 | =end original |
4753 | 5896 | |
4754 | C<getlogin> を認証に使ってはいけません | |
5897 | L<C<getlogin>|/getlogin> を認証に使ってはいけません: これは | |
4755 | ||
5898 | L<C<getpwuid>|/getpwuid UID> のように安全ではありません。 | |
4756 | 5899 | |
5900 | =begin original | |
5901 | ||
5902 | Portability issues: L<perlport/getlogin>. | |
5903 | ||
5904 | =end original | |
5905 | ||
5906 | 移植性の問題: L<perlport/getlogin>。 | |
5907 | ||
4757 | 5908 | =item getpeername SOCKET |
4758 | 5909 | X<getpeername> X<peer> |
4759 | 5910 | |
5911 | =for Pod::Functions find the other end of a socket connection | |
5912 | ||
4760 | 5913 | =begin original |
4761 | 5914 | |
4762 | 5915 | Returns the packed sockaddr address of the other end of the SOCKET |
4763 | 5916 | connection. |
4764 | 5917 | |
4765 | 5918 | =end original |
4766 | 5919 | |
4767 | 5920 | SOCKET コネクションの向こう側のパックされた aockaddr アドレスを返します。 |
4768 | 5921 | |
4769 | 5922 | use Socket; |
4770 | $hersockaddr = getpeername( | |
5923 | my $hersockaddr = getpeername($sock); | |
4771 | ($port, $iaddr) = sockaddr_in($hersockaddr); | |
5924 | my ($port, $iaddr) = sockaddr_in($hersockaddr); | |
4772 | $herhostname = gethostbyaddr($iaddr, AF_INET); | |
5925 | my $herhostname = gethostbyaddr($iaddr, AF_INET); | |
4773 | $herstraddr = inet_ntoa($iaddr); | |
5926 | my $herstraddr = inet_ntoa($iaddr); | |
4774 | 5927 | |
4775 | 5928 | =item getpgrp PID |
4776 | 5929 | X<getpgrp> X<group> |
4777 | 5930 | |
5931 | =for Pod::Functions get process group | |
5932 | ||
4778 | 5933 | =begin original |
4779 | 5934 | |
4780 | 5935 | Returns the current process group for the specified PID. Use |
4781 | 5936 | a PID of C<0> to get the current process group for the |
4782 | 5937 | current process. Will raise an exception if used on a machine that |
4783 | doesn't implement getpgrp(2). If PID is omitted, returns the process | |
5938 | doesn't implement L<getpgrp(2)>. If PID is omitted, returns the process | |
4784 | group of the current process. Note that the POSIX version of | |
5939 | group of the current process. Note that the POSIX version of | |
4785 | does not accept a PID argument, so only | |
5940 | L<C<getpgrp>|/getpgrp PID> does not accept a PID argument, so only | |
5941 | C<PID==0> is truly portable. | |
4786 | 5942 | |
4787 | 5943 | =end original |
4788 | 5944 | |
4789 | 5945 | 指定された PID の現在のプロセスグループを返します。 |
4790 | 5946 | PID に C<0> を与えるとカレントプロセスの指定となります。 |
4791 | getpgrp(2) を実装していないマシンで実行した場合には、例外が発生します。 | |
5947 | L<getpgrp(2)> を実装していないマシンで実行した場合には、例外が発生します。 | |
4792 | 5948 | PID を省略するとカレントプロセスのプロセスグループを返します。 |
4793 | POSIX 版の C<getpgrp> は PID 引数を受け付けないので、 | |
5949 | POSIX 版の L<C<getpgrp>|/getpgrp PID> は PID 引数を受け付けないので、 | |
4794 | 5950 | C<PID==0> のみが完全に移植性があります。 |
4795 | 5951 | |
5952 | =begin original | |
5953 | ||
5954 | Portability issues: L<perlport/getpgrp>. | |
5955 | ||
5956 | =end original | |
5957 | ||
5958 | 移植性の問題: L<perlport/getpgrp>。 | |
5959 | ||
4796 | 5960 | =item getppid |
4797 | 5961 | X<getppid> X<parent> X<pid> |
4798 | 5962 | |
5963 | =for Pod::Functions get parent process ID | |
5964 | ||
4799 | 5965 | =begin original |
4800 | 5966 | |
4801 | 5967 | Returns the process id of the parent process. |
4802 | 5968 | |
4803 | 5969 | =end original |
4804 | 5970 | |
4805 | 5971 | 親プロセスのプロセス id を返します。 |
4806 | 5972 | |
4807 | 5973 | =begin original |
4808 | 5974 | |
4809 | Note for Linux users: | |
5975 | Note for Linux users: Between v5.8.1 and v5.16.0 Perl would work | |
4810 | ||
5976 | around non-POSIX thread semantics the minority of Linux systems (and | |
4811 | ||
5977 | Debian GNU/kFreeBSD systems) that used LinuxThreads, this emulation | |
4812 | ||
5978 | has since been removed. See the documentation for L<$$|perlvar/$$> for | |
4813 | ||
5979 | details. | |
4814 | C<Linux::Pid>. | |
4815 | 5980 | |
4816 | 5981 | =end original |
4817 | 5982 | |
4818 | Linux ユーザーへの注意: | |
5983 | Linux ユーザーへの注意: v5.8.1 から v5.16.0 の間 Perl は | |
4819 | スレッド | |
5984 | LinuxThreads という非 POSIX なスレッド文法を使っているマイナーな | |
4820 | ||
5985 | Linux システム (および Debian GNU/kFreeBSD システム) に対応していました。 | |
4821 | ||
5986 | このエミュレーションは削除されました; | |
4822 | ||
5987 | 詳しくは L<$$|perlvar/$$> の文書を参照してください。 | |
4823 | C<Linux::Pid> を使ってください。 | |
4824 | 5988 | |
5989 | =begin original | |
5990 | ||
5991 | Portability issues: L<perlport/getppid>. | |
5992 | ||
5993 | =end original | |
5994 | ||
5995 | 移植性の問題: L<perlport/getppid>。 | |
5996 | ||
4825 | 5997 | =item getpriority WHICH,WHO |
4826 | 5998 | X<getpriority> X<priority> X<nice> |
4827 | 5999 | |
6000 | =for Pod::Functions get current nice value | |
6001 | ||
4828 | 6002 | =begin original |
4829 | 6003 | |
4830 | 6004 | Returns the current priority for a process, a process group, or a user. |
4831 | (See | |
6005 | (See L<getpriority(2)>.) Will raise a fatal exception if used on a | |
4832 | machine that doesn't implement getpriority(2). | |
6006 | machine that doesn't implement L<getpriority(2)>. | |
4833 | 6007 | |
4834 | 6008 | =end original |
4835 | 6009 | |
4836 | 6010 | プロセス、プロセスグループ、ユーザに対する現在の優先度を返します。 |
4837 | ( | |
6011 | (L<getpriority(2)> を参照してください。) | |
4838 | getpriority(2) を実装していない | |
6012 | L<getpriority(2)> を実装していない | |
4839 | 6013 | マシンで実行した場合には、致命的例外が発生します。 |
4840 | 6014 | |
6015 | =begin original | |
6016 | ||
6017 | Portability issues: L<perlport/getpriority>. | |
6018 | ||
6019 | =end original | |
6020 | ||
6021 | 移植性の問題: L<perlport/getpriority>。 | |
6022 | ||
4841 | 6023 | =item getpwnam NAME |
4842 | 6024 | X<getpwnam> X<getgrnam> X<gethostbyname> X<getnetbyname> X<getprotobyname> |
4843 | 6025 | X<getpwuid> X<getgrgid> X<getservbyname> X<gethostbyaddr> X<getnetbyaddr> |
4844 | 6026 | X<getprotobynumber> X<getservbyport> X<getpwent> X<getgrent> X<gethostent> |
4845 | 6027 | X<getnetent> X<getprotoent> X<getservent> X<setpwent> X<setgrent> X<sethostent> |
4846 | 6028 | X<setnetent> X<setprotoent> X<setservent> X<endpwent> X<endgrent> X<endhostent> |
4847 | X<endnetent> X<endprotoent> X<endservent> | |
6029 | X<endnetent> X<endprotoent> X<endservent> | |
4848 | 6030 | |
6031 | =for Pod::Functions get passwd record given user login name | |
6032 | ||
4849 | 6033 | =item getgrnam NAME |
4850 | 6034 | |
6035 | =for Pod::Functions get group record given group name | |
6036 | ||
4851 | 6037 | =item gethostbyname NAME |
4852 | 6038 | |
6039 | =for Pod::Functions get host record given name | |
6040 | ||
4853 | 6041 | =item getnetbyname NAME |
4854 | 6042 | |
6043 | =for Pod::Functions get networks record given name | |
6044 | ||
4855 | 6045 | =item getprotobyname NAME |
4856 | 6046 | |
6047 | =for Pod::Functions get protocol record given name | |
6048 | ||
4857 | 6049 | =item getpwuid UID |
4858 | 6050 | |
6051 | =for Pod::Functions get passwd record given user ID | |
6052 | ||
4859 | 6053 | =item getgrgid GID |
4860 | 6054 | |
6055 | =for Pod::Functions get group record given group user ID | |
6056 | ||
4861 | 6057 | =item getservbyname NAME,PROTO |
4862 | 6058 | |
6059 | =for Pod::Functions get services record given its name | |
6060 | ||
4863 | 6061 | =item gethostbyaddr ADDR,ADDRTYPE |
4864 | 6062 | |
6063 | =for Pod::Functions get host record given its address | |
6064 | ||
4865 | 6065 | =item getnetbyaddr ADDR,ADDRTYPE |
4866 | 6066 | |
6067 | =for Pod::Functions get network record given its address | |
6068 | ||
4867 | 6069 | =item getprotobynumber NUMBER |
4868 | 6070 | |
6071 | =for Pod::Functions get protocol record numeric protocol | |
6072 | ||
4869 | 6073 | =item getservbyport PORT,PROTO |
4870 | 6074 | |
6075 | =for Pod::Functions get services record given numeric port | |
6076 | ||
4871 | 6077 | =item getpwent |
4872 | 6078 | |
6079 | =for Pod::Functions get next passwd record | |
6080 | ||
4873 | 6081 | =item getgrent |
4874 | 6082 | |
6083 | =for Pod::Functions get next group record | |
6084 | ||
4875 | 6085 | =item gethostent |
4876 | 6086 | |
6087 | =for Pod::Functions get next hosts record | |
6088 | ||
4877 | 6089 | =item getnetent |
4878 | 6090 | |
6091 | =for Pod::Functions get next networks record | |
6092 | ||
4879 | 6093 | =item getprotoent |
4880 | 6094 | |
6095 | =for Pod::Functions get next protocols record | |
6096 | ||
4881 | 6097 | =item getservent |
4882 | 6098 | |
6099 | =for Pod::Functions get next services record | |
6100 | ||
4883 | 6101 | =item setpwent |
4884 | 6102 | |
6103 | =for Pod::Functions prepare passwd file for use | |
6104 | ||
4885 | 6105 | =item setgrent |
4886 | 6106 | |
6107 | =for Pod::Functions prepare group file for use | |
6108 | ||
4887 | 6109 | =item sethostent STAYOPEN |
4888 | 6110 | |
6111 | =for Pod::Functions prepare hosts file for use | |
6112 | ||
4889 | 6113 | =item setnetent STAYOPEN |
4890 | 6114 | |
6115 | =for Pod::Functions prepare networks file for use | |
6116 | ||
4891 | 6117 | =item setprotoent STAYOPEN |
4892 | 6118 | |
6119 | =for Pod::Functions prepare protocols file for use | |
6120 | ||
4893 | 6121 | =item setservent STAYOPEN |
4894 | 6122 | |
6123 | =for Pod::Functions prepare services file for use | |
6124 | ||
4895 | 6125 | =item endpwent |
4896 | 6126 | |
6127 | =for Pod::Functions be done using passwd file | |
6128 | ||
4897 | 6129 | =item endgrent |
4898 | 6130 | |
6131 | =for Pod::Functions be done using group file | |
6132 | ||
4899 | 6133 | =item endhostent |
4900 | 6134 | |
6135 | =for Pod::Functions be done using hosts file | |
6136 | ||
4901 | 6137 | =item endnetent |
4902 | 6138 | |
6139 | =for Pod::Functions be done using networks file | |
6140 | ||
4903 | 6141 | =item endprotoent |
4904 | 6142 | |
6143 | =for Pod::Functions be done using protocols file | |
6144 | ||
4905 | 6145 | =item endservent |
4906 | 6146 | |
6147 | =for Pod::Functions be done using services file | |
6148 | ||
4907 | 6149 | =begin original |
4908 | 6150 | |
4909 | 6151 | These routines are the same as their counterparts in the |
4910 | 6152 | system C library. In list context, the return values from the |
4911 | 6153 | various get routines are as follows: |
4912 | 6154 | |
4913 | 6155 | =end original |
4914 | 6156 | |
4915 | 6157 | これらのルーチンは、システムの C ライブラリの同名の関数と同じです。 |
4916 | 6158 | リストコンテキストでは、さまざまな |
4917 | 6159 | get ルーチンからの返り値は、次のようになります: |
4918 | 6160 | |
4919 | | |
6161 | # 0 1 2 3 4 | |
4920 | | |
6162 | my ( $name, $passwd, $gid, $members ) = getgr* | |
4921 | | |
6163 | my ( $name, $aliases, $addrtype, $net ) = getnet* | |
4922 | | |
6164 | my ( $name, $aliases, $port, $proto ) = getserv* | |
4923 | | |
6165 | my ( $name, $aliases, $proto ) = getproto* | |
4924 | | |
6166 | my ( $name, $aliases, $addrtype, $length, @addrs ) = gethost* | |
4925 | | |
6167 | my ( $name, $passwd, $uid, $gid, $quota, | |
6168 | $comment, $gcos, $dir, $shell, $expire ) = getpw* | |
6169 | # 5 6 7 8 9 | |
4926 | 6170 | |
4927 | 6171 | =begin original |
4928 | 6172 | |
4929 | (If the entry doesn't exist | |
6173 | (If the entry doesn't exist, the return value is a single meaningless true | |
6174 | value.) | |
4930 | 6175 | |
4931 | 6176 | =end original |
4932 | 6177 | |
4933 | (エントリが存在しなければ、 | |
6178 | (エントリが存在しなければ、返り値は単一の意味のない真の値です。) | |
4934 | 6179 | |
4935 | 6180 | =begin original |
4936 | 6181 | |
4937 | 6182 | The exact meaning of the $gcos field varies but it usually contains |
4938 | 6183 | the real name of the user (as opposed to the login name) and other |
4939 | 6184 | information pertaining to the user. Beware, however, that in many |
4940 | 6185 | system users are able to change this information and therefore it |
4941 | 6186 | cannot be trusted and therefore the $gcos is tainted (see |
4942 | 6187 | L<perlsec>). The $passwd and $shell, user's encrypted password and |
4943 | 6188 | login shell, are also tainted, for the same reason. |
4944 | 6189 | |
4945 | 6190 | =end original |
4946 | 6191 | |
4947 | 6192 | $gcos フィールドの正確な意味はさまざまですが、通常は(ログイン名ではなく) |
4948 | 6193 | ユーザーの実際の名前とユーザーに付随する情報を含みます。 |
4949 | 6194 | 但し、多くのシステムではユーザーがこの情報を変更できるので、この情報は |
4950 | 6195 | 信頼できず、従って $gcos は汚染されます(L<perlsec> を参照してください)。 |
4951 | 6196 | ユーザーの暗号化されたパスワードとログインシェルである $passwd と |
4952 | 6197 | $shell も、同様の理由で汚染されます。 |
4953 | 6198 | |
4954 | 6199 | =begin original |
4955 | 6200 | |
4956 | 6201 | In scalar context, you get the name, unless the function was a |
4957 | 6202 | lookup by name, in which case you get the other thing, whatever it is. |
4958 | 6203 | (If the entry doesn't exist you get the undefined value.) For example: |
4959 | 6204 | |
4960 | 6205 | =end original |
4961 | 6206 | |
4962 | 6207 | スカラコンテキストでは、*nam、*byname といった NAME で検索するもの以外は、 |
4963 | 6208 | name を返し、NAME で検索するものは、何か別のものを返します。 |
4964 | 6209 | (エントリが存在しなければ、未定義値が返ります。) |
4965 | 例: | |
6210 | 例えば: | |
4966 | 6211 | |
4967 | $uid = getpwnam($name); | |
6212 | my $uid = getpwnam($name); | |
4968 | $name = getpwuid($num); | |
6213 | my $name = getpwuid($num); | |
4969 | $name = getpwent(); | |
6214 | my $name = getpwent(); | |
4970 | $gid = getgrnam($name); | |
6215 | my $gid = getgrnam($name); | |
4971 | $name = getgrgid($num); | |
6216 | my $name = getgrgid($num); | |
4972 | $name = getgrent(); | |
6217 | my $name = getgrent(); | |
4973 | #etc. | |
6218 | <#ins> etc. | |
4974 | 6219 | |
4975 | 6220 | =begin original |
4976 | 6221 | |
4977 | 6222 | In I<getpw*()> the fields $quota, $comment, and $expire are special |
4978 | 6223 | in that they are unsupported on many systems. If the |
4979 | 6224 | $quota is unsupported, it is an empty scalar. If it is supported, it |
4980 | 6225 | usually encodes the disk quota. If the $comment field is unsupported, |
4981 | 6226 | it is an empty scalar. If it is supported it usually encodes some |
4982 | 6227 | administrative comment about the user. In some systems the $quota |
4983 | 6228 | field may be $change or $age, fields that have to do with password |
4984 | 6229 | aging. In some systems the $comment field may be $class. The $expire |
4985 | 6230 | field, if present, encodes the expiration period of the account or the |
4986 | 6231 | password. For the availability and the exact meaning of these fields |
4987 | in your system, please consult getpwnam(3) and your system's | |
6232 | in your system, please consult L<getpwnam(3)> and your system's | |
4988 | 6233 | F<pwd.h> file. You can also find out from within Perl what your |
4989 | 6234 | $quota and $comment fields mean and whether you have the $expire field |
4990 | by using the C<Config> module and the values C<d_pwquota>, C<d_pwage>, | |
6235 | by using the L<C<Config>|Config> module and the values C<d_pwquota>, C<d_pwage>, | |
4991 | 6236 | C<d_pwchange>, C<d_pwcomment>, and C<d_pwexpire>. Shadow password |
4992 | 6237 | files are supported only if your vendor has implemented them in the |
4993 | 6238 | intuitive fashion that calling the regular C library routines gets the |
4994 | 6239 | shadow versions if you're running under privilege or if there exists |
4995 | the shadow(3) functions as found in System V (this includes Solaris | |
6240 | the L<shadow(3)> functions as found in System V (this includes Solaris | |
4996 | 6241 | and Linux). Those systems that implement a proprietary shadow password |
4997 | 6242 | facility are unlikely to be supported. |
4998 | 6243 | |
4999 | 6244 | =end original |
5000 | 6245 | |
5001 | 6246 | I<getpw*()> では、$quota, $comment, $expire フィールドは、 |
5002 | 6247 | 多くのシステムでは対応していないので特別な処理がされます。 |
5003 | 6248 | $quota が非対応の場合、空のスカラになります。 |
5004 | 6249 | 対応している場合、通常はディスククォータの値が入ります。 |
5005 | 6250 | $comment フィールドが非対応の場合、空のスカラになります。 |
5006 | 6251 | 対応している場合、通常はユーザーに関する管理上のコメントが入ります。 |
5007 | 6252 | $quota フィールドはパスワードの寿命を示す $change や $age である |
5008 | 6253 | システムもあります。 |
5009 | 6254 | $comment フィールドは $class であるシステムもあります。 |
5010 | 6255 | $expire フィールドがある場合は、アカウントやパスワードが時間切れになる |
5011 | 6256 | 期間が入ります。 |
5012 | 6257 | 動作させるシステムでのこれらのフィールドの有効性と正確な意味については、 |
5013 | getpwnam(3) のドキュメントと F<pwd.h> ファイルを参照してください。 | |
6258 | L<getpwnam(3)> のドキュメントと F<pwd.h> ファイルを参照してください。 | |
5014 | 6259 | $quota と $comment フィールドが何を意味しているかと、$expire フィールドが |
5015 | あるかどうかは、C<Config> モジュールを使って、C<d_pwquota | |
6260 | あるかどうかは、L<C<Config>|Config> モジュールを使って、C<d_pwquota>, | |
5016 | C<d_pwchange>, C<d_pwcomment>, C<d_pwexpire> の値を | |
6261 | C<d_pwage>, C<d_pwchange>, C<d_pwcomment>, C<d_pwexpire> の値を | |
5017 | Perl 自身で調べることも出来ます。 | |
6262 | 調べることによって Perl 自身で調べることも出来ます。 | |
5018 | 6263 | シャドウパスワードは、通常の C ライブラリルーチンを権限がある状態で |
5019 | 6264 | 呼び出すことでシャドウ版が取得できるか、System V にあるような |
5020 | (Solaris と Linux を含みます) shadow(3) 関数があるといった、 | |
6265 | (Solaris と Linux を含みます) L<shadow(3)> 関数があるといった、 | |
5021 | 6266 | 直感的な方法で実装されている場合にのみ対応されます。 |
5022 | 6267 | 独占的なシャドウパスワード機能を実装しているシステムでは、 |
5023 | 6268 | それに対応されることはないでしょう。 |
5024 | 6269 | |
5025 | 6270 | =begin original |
5026 | 6271 | |
5027 | 6272 | The $members value returned by I<getgr*()> is a space-separated list of |
5028 | 6273 | the login names of the members of the group. |
5029 | 6274 | |
5030 | 6275 | =end original |
5031 | 6276 | |
5032 | 6277 | I<getgr*()> によって返る値 $members は、グループのメンバの |
5033 | 6278 | ログイン名をスペースで区切ったものです。 |
5034 | 6279 | |
5035 | 6280 | =begin original |
5036 | 6281 | |
5037 | 6282 | For the I<gethost*()> functions, if the C<h_errno> variable is supported in |
5038 | C, it will be returned to you via C<$?> if the function | |
6283 | C, it will be returned to you via L<C<$?>|perlvar/$?> if the function | |
6284 | call fails. The | |
5039 | 6285 | C<@addrs> value returned by a successful call is a list of raw |
5040 | 6286 | addresses returned by the corresponding library call. In the |
5041 | 6287 | Internet domain, each address is four bytes long; you can unpack it |
5042 | 6288 | by saying something like: |
5043 | 6289 | |
5044 | 6290 | =end original |
5045 | 6291 | |
5046 | 6292 | I<gethost*()> 関数では、C で C<h_errno> 変数がサポートされていれば、 |
5047 | 関数呼出が失敗したときに、C<$?> を通して、その値が返されます。 | |
6293 | 関数呼出が失敗したときに、L<C<$?>|perlvar/$?> を通して、その値が返されます。 | |
5048 | 6294 | 成功時に返される C<@addrs> 値は、対応するシステムコールが返す、 |
5049 | 6295 | 生のアドレスのリストです。 |
5050 | 6296 | インターネットドメインでは、個々のアドレスは、4 バイト長です; |
5051 | 6297 | 以下のようにして unpack することができます: |
5052 | 6298 | |
5053 | ($ | |
6299 | my ($w,$x,$y,$z) = unpack('W4',$addr[0]); | |
5054 | 6300 | |
5055 | 6301 | =begin original |
5056 | 6302 | |
5057 | 6303 | The Socket library makes this slightly easier: |
5058 | 6304 | |
5059 | 6305 | =end original |
5060 | 6306 | |
5061 | 6307 | Socket ライブラリを使うともう少し簡単になります。 |
5062 | 6308 | |
5063 | 6309 | use Socket; |
5064 | $iaddr = inet_aton("127.1"); # or whatever address | |
6310 | my $iaddr = inet_aton("127.1"); # or whatever address | |
5065 | $name = gethostbyaddr($iaddr, AF_INET); | |
6311 | my $name = gethostbyaddr($iaddr, AF_INET); | |
5066 | 6312 | |
5067 | 6313 | # or going the other way |
5068 | $straddr = inet_ntoa($iaddr); | |
6314 | my $straddr = inet_ntoa($iaddr); | |
5069 | 6315 | |
5070 | 6316 | =begin original |
5071 | 6317 | |
5072 | 6318 | In the opposite way, to resolve a hostname to the IP address |
5073 | 6319 | you can write this: |
5074 | 6320 | |
5075 | 6321 | =end original |
5076 | 6322 | |
5077 | 6323 | 逆方向に、ホスト名から IP アドレスを解決するには以下のように書けます: |
5078 | 6324 | |
5079 | 6325 | use Socket; |
5080 | $packed_ip = gethostbyname("www.perl.org"); | |
6326 | my $packed_ip = gethostbyname("www.perl.org"); | |
6327 | my $ip_address; | |
5081 | 6328 | if (defined $packed_ip) { |
5082 | 6329 | $ip_address = inet_ntoa($packed_ip); |
5083 | 6330 | } |
5084 | 6331 | |
5085 | 6332 | =begin original |
5086 | 6333 | |
5087 | Make sure <gethostbyname | |
6334 | Make sure L<C<gethostbyname>|/gethostbyname NAME> is called in SCALAR | |
5088 | its return value is checked for definedness. | |
6335 | context and that its return value is checked for definedness. | |
5089 | 6336 | |
5090 | 6337 | =end original |
5091 | 6338 | |
5092 | C<gethostbyname | |
6339 | L<C<gethostbyname>|/gethostbyname NAME> はスカラコンテキストで | |
5093 | 定義されているかを必ずチェックしてください。 | |
6340 | 呼び出すようにして、返り値が定義されているかを必ずチェックしてください。 | |
5094 | 6341 | |
5095 | 6342 | =begin original |
5096 | 6343 | |
6344 | The L<C<getprotobynumber>|/getprotobynumber NUMBER> function, even | |
6345 | though it only takes one argument, has the precedence of a list | |
6346 | operator, so beware: | |
6347 | ||
6348 | =end original | |
6349 | ||
6350 | L<C<getprotobynumber>|/getprotobynumber NUMBER> 関数は、一つの引数しか | |
6351 | 取らないにも関わらず、リスト演算子の優先順位を持ちます; 従って | |
6352 | 注意してください: | |
6353 | ||
6354 | getprotobynumber $number eq 'icmp' # WRONG | |
6355 | getprotobynumber($number eq 'icmp') # actually means this | |
6356 | getprotobynumber($number) eq 'icmp' # better this way | |
6357 | ||
6358 | =begin original | |
6359 | ||
5097 | 6360 | If you get tired of remembering which element of the return list |
5098 | contains which return value, by-name interfaces are provided | |
6361 | contains which return value, by-name interfaces are provided in standard | |
5099 | ||
6362 | modules: L<C<File::stat>|File::stat>, L<C<Net::hostent>|Net::hostent>, | |
5100 | C<Net:: | |
6363 | L<C<Net::netent>|Net::netent>, L<C<Net::protoent>|Net::protoent>, | |
5101 | ||
6364 | L<C<Net::servent>|Net::servent>, L<C<Time::gmtime>|Time::gmtime>, | |
5102 | ||
6365 | L<C<Time::localtime>|Time::localtime>, and | |
5103 | ||
6366 | L<C<User::grent>|User::grent>. These override the normal built-ins, | |
6367 | supplying versions that return objects with the appropriate names for | |
6368 | each field. For example: | |
5104 | 6369 | |
5105 | 6370 | =end original |
5106 | 6371 | |
5107 | 6372 | 返り値のリストの何番目がどの要素かを覚えるのに疲れたなら、 |
5108 | 6373 | 名前ベースのインターフェースが標準モジュールで提供されています: |
5109 | C<File::stat>, C<Net::hostent> | |
6374 | L<C<File::stat>|File::stat>, L<C<Net::hostent>|Net::hostent>, | |
5110 | C<Net:: | |
6375 | L<C<Net::netent>|Net::netent>, L<C<Net::protoent>|Net::protoent>, | |
5111 | C< | |
6376 | L<C<Net::servent>|Net::servent>, L<C<Time::gmtime>|Time::gmtime>, | |
6377 | L<C<Time::localtime>|Time::localtime>, | |
6378 | L<C<User::grent>|User::grent> です。 | |
5112 | 6379 | これらは通常の組み込みを上書きし、 |
5113 | 6380 | それぞれのフィールドに適切な名前をつけたオブジェクトを返します。 |
5114 | 例: | |
6381 | 例えば: | |
5115 | 6382 | |
5116 | 6383 | use File::stat; |
5117 | 6384 | use User::pwent; |
5118 | $is_his = (stat($filename)->uid == pwent($whoever)->uid); | |
6385 | my $is_his = (stat($filename)->uid == pwent($whoever)->uid); | |
5119 | 6386 | |
5120 | 6387 | =begin original |
5121 | 6388 | |
5122 | 6389 | Even though it looks as though they're the same method calls (uid), |
5123 | 6390 | they aren't, because a C<File::stat> object is different from |
5124 | 6391 | a C<User::pwent> object. |
5125 | 6392 | |
5126 | 6393 | =end original |
5127 | 6394 | |
5128 | 同じメソッド(uid)を呼び出しているように見えますが、違います | |
6395 | 同じメソッド(uid)を呼び出しているように見えますが、違います; | |
5129 | 6396 | なぜなら C<File::stat> オブジェクトは C<User::pwent> オブジェクトとは |
5130 | 6397 | 異なるからです。 |
5131 | 6398 | |
6399 | =begin original | |
6400 | ||
6401 | Portability issues: L<perlport/getpwnam> to L<perlport/endservent>. | |
6402 | ||
6403 | =end original | |
6404 | ||
6405 | 移植性の問題: L<perlport/getpwnam> から L<perlport/endservent>。 | |
6406 | ||
5132 | 6407 | =item getsockname SOCKET |
5133 | 6408 | X<getsockname> |
5134 | 6409 | |
6410 | =for Pod::Functions retrieve the sockaddr for a given socket | |
6411 | ||
5135 | 6412 | =begin original |
5136 | 6413 | |
5137 | 6414 | Returns the packed sockaddr address of this end of the SOCKET connection, |
5138 | 6415 | in case you don't know the address because you have several different |
5139 | 6416 | IPs that the connection might have come in on. |
5140 | 6417 | |
5141 | 6418 | =end original |
5142 | 6419 | |
5143 | SOCKET 接続のこちら側の pack された sockaddr アドレスを返します | |
6420 | SOCKET 接続のこちら側の pack された sockaddr アドレスを返します; | |
5144 | 6421 | 複数の異なる IP から接続されるためにアドレスがわからない場合に使います。 |
5145 | 6422 | |
5146 | 6423 | use Socket; |
5147 | $mysockaddr = getsockname( | |
6424 | my $mysockaddr = getsockname($sock); | |
5148 | ($port, $myaddr) = sockaddr_in($mysockaddr); | |
6425 | my ($port, $myaddr) = sockaddr_in($mysockaddr); | |
5149 | 6426 | printf "Connect to %s [%s]\n", |
5150 | 6427 | scalar gethostbyaddr($myaddr, AF_INET), |
5151 | 6428 | inet_ntoa($myaddr); |
5152 | 6429 | |
5153 | 6430 | =item getsockopt SOCKET,LEVEL,OPTNAME |
5154 | 6431 | X<getsockopt> |
5155 | 6432 | |
6433 | =for Pod::Functions get socket options on a given socket | |
6434 | ||
5156 | 6435 | =begin original |
5157 | 6436 | |
5158 | 6437 | Queries the option named OPTNAME associated with SOCKET at a given LEVEL. |
5159 | 6438 | Options may exist at multiple protocol levels depending on the socket |
5160 | 6439 | type, but at least the uppermost socket level SOL_SOCKET (defined in the |
5161 | C<Socket> module) will exist. To query options at another | |
6440 | L<C<Socket>|Socket> module) will exist. To query options at another | |
5162 | protocol number of the appropriate protocol controlling the | |
6441 | level the protocol number of the appropriate protocol controlling the | |
5163 | should be supplied. For example, to indicate that an option is | |
6442 | option should be supplied. For example, to indicate that an option is | |
5164 | interpreted by the TCP protocol, LEVEL should be set to the | |
6443 | to be interpreted by the TCP protocol, LEVEL should be set to the | |
5165 | number of TCP, which you can get using | |
6444 | protocol number of TCP, which you can get using | |
6445 | L<C<getprotobyname>|/getprotobyname NAME>. | |
5166 | 6446 | |
5167 | 6447 | =end original |
5168 | 6448 | |
5169 | 6449 | 与えられた LEVEL で SOCKET に関連付けられた OPTNAME と言う名前のオプションを |
5170 | 6450 | 問い合わせます。 |
5171 | 6451 | オプションはソケットの種類に依存しした複数のプロトコルレベルに存在することも |
5172 | ありますが、少なくとも最上位ソケットレベル SOL_SOCKET | |
6452 | ありますが、少なくとも最上位ソケットレベル SOL_SOCKET | |
5173 | 定義されています)は存在します。 | |
6453 | (L<C<Socket>|Socket> モジュールで定義されています)は存在します。 | |
5174 | 6454 | その他のレベルのオプションを問い合わせるには、そのオプションを制御する |
5175 | 6455 | 適切なプロトコルのプロトコル番号を指定します。 |
5176 | 6456 | 例えば、オプションが TCP プロトコルで解釈されるべきであることを示すためには、 |
5177 | LEVEL は C<getprotobyname> で得られる TCP の | |
6457 | LEVEL は L<C<getprotobyname>|/getprotobyname NAME> で得られる TCP の | |
6458 | プロトコル番号を設定します。 | |
5178 | 6459 | |
5179 | 6460 | =begin original |
5180 | 6461 | |
5181 | 6462 | The function returns a packed string representing the requested socket |
5182 | option, or C<undef> on error, with the reason for the | |
6463 | option, or L<C<undef>|/undef EXPR> on error, with the reason for the | |
5183 | C<$!>. Just what is in the packed string | |
6464 | error placed in L<C<$!>|perlvar/$!>. Just what is in the packed string | |
5184 | consult getsockopt(2) for details. A | |
6465 | depends on LEVEL and OPTNAME; consult L<getsockopt(2)> for details. A | |
5185 | ||
6466 | common case is that the option is an integer, in which case the result | |
5186 | ||
6467 | is a packed integer, which you can decode using | |
6468 | L<C<unpack>|/unpack TEMPLATE,EXPR> with the C<i> (or C<I>) format. | |
5187 | 6469 | |
5188 | 6470 | =end original |
5189 | 6471 | |
5190 | 6472 | この関数は、要求されたソケットオプションの pack された文字列表現か、 |
5191 | あるいはエラーの場合は C<undef> を返し、エラーの理由は | |
6473 | あるいはエラーの場合は L<C<undef>|/undef EXPR> を返し、エラーの理由は | |
6474 | L<C<$!>|perlvar/$!> にあります。 | |
5192 | 6475 | pack された文字列の中身は LEVEL と OPTNAME に依存します; |
5193 | 詳細については getsockopt(2) を確認してください。 | |
6476 | 詳細については L<getsockopt(2)> を確認してください。 | |
5194 | 一般的な場合はオプションが整数の場合で、この場合結果は | |
6477 | 一般的な場合はオプションが整数の場合で、この場合結果は | |
6478 | L<C<unpack>|/unpack TEMPLATE,EXPR> の C<i> | |
5195 | 6479 | (あるいは C<I>)フォーマットでデコードできる pack された整数です。 |
5196 | 6480 | |
5197 | 6481 | =begin original |
5198 | 6482 | |
5199 | 6483 | Here's an example to test whether Nagle's algorithm is enabled on a socket: |
5200 | 6484 | |
5201 | 6485 | =end original |
5202 | 6486 | |
5203 | 6487 | あるソケットで Nagle のアルゴリズム有効かどうかを調べる例です: |
5204 | 6488 | |
5205 | 6489 | use Socket qw(:all); |
5206 | 6490 | |
5207 | 6491 | defined(my $tcp = getprotobyname("tcp")) |
5208 | 6492 | or die "Could not determine the protocol number for tcp"; |
5209 | 6493 | # my $tcp = IPPROTO_TCP; # Alternative |
5210 | 6494 | my $packed = getsockopt($socket, $tcp, TCP_NODELAY) |
5211 | 6495 | or die "getsockopt TCP_NODELAY: $!"; |
5212 | 6496 | my $nodelay = unpack("I", $packed); |
5213 | print "Nagle's algorithm is turned ", | |
6497 | print "Nagle's algorithm is turned ", | |
6498 | $nodelay ? "off\n" : "on\n"; | |
5214 | 6499 | |
5215 | ||
5216 | =item given EXPR BLOCK | |
5217 | X<given> | |
5218 | ||
5219 | =item given BLOCK | |
5220 | ||
5221 | 6500 | =begin original |
5222 | 6501 | |
5223 | ||
6502 | Portability issues: L<perlport/getsockopt>. | |
5224 | and C<when> are used in Perl to implement C<switch>/C<case> like statements. | |
5225 | Only available after Perl 5.10. For example: | |
5226 | 6503 | |
5227 | 6504 | =end original |
5228 | 6505 | |
5229 | ||
6506 | 移植性の問題: L<perlport/getsockopt>。 | |
5230 | C<given> と C<when> は C<switch>/C<case> 風の構文を実装するために Perl で | |
5231 | 使われます。 | |
5232 | Perl 5.10 以降でのみ利用可能です。 | |
5233 | 例えば: | |
5234 | 6507 | |
5235 | use v5.10; | |
5236 | given ($fruit) { | |
5237 | when (/apples?/) { | |
5238 | print "I like apples." | |
5239 | } | |
5240 | when (/oranges?/) { | |
5241 | print "I don't like oranges." | |
5242 | } | |
5243 | default { | |
5244 | print "I don't like anything" | |
5245 | } | |
5246 | } | |
5247 | ||
5248 | =begin original | |
5249 | ||
5250 | See L<perlsyn/"Switch statements"> for detailed information. | |
5251 | ||
5252 | =end original | |
5253 | ||
5254 | 詳しい情報については L<perlsyn/"Switch statements"> を参照してください。 | |
5255 | ||
5256 | 6508 | =item glob EXPR |
5257 | 6509 | X<glob> X<wildcard> X<filename, expansion> X<expand> |
5258 | 6510 | |
5259 | 6511 | =item glob |
5260 | 6512 | |
6513 | =for Pod::Functions expand filenames using wildcards | |
6514 | ||
5261 | 6515 | =begin original |
5262 | 6516 | |
5263 | 6517 | In list context, returns a (possibly empty) list of filename expansions on |
5264 | the value of EXPR such as the standard Unix shell F</bin/csh> would do. In | |
6518 | the value of EXPR such as the standard Unix shell F</bin/csh> would do. In | |
5265 | 6519 | scalar context, glob iterates through such filename expansions, returning |
5266 | undef when the list is exhausted. This is the internal function | |
6520 | undef when the list is exhausted. This is the internal function | |
5267 | implementing the C<< <*.c> >> operator, but you can use it directly. If | |
6521 | implementing the C<< <*.c> >> operator, but you can use it directly. If | |
5268 | EXPR is omitted, C<$_> is used. The C<< <*.c> >> operator | |
6522 | EXPR is omitted, L<C<$_>|perlvar/$_> is used. The C<< <*.c> >> operator | |
5269 | more detail in L<perlop/"I/O Operators">. | |
6523 | is discussed in more detail in L<perlop/"I/O Operators">. | |
5270 | 6524 | |
5271 | 6525 | =end original |
5272 | 6526 | |
5273 | 6527 | リストコンテキストでは、 |
5274 | 6528 | EXPR の値を、標準 Unix シェル F</bin/csh> が行なうように |
5275 | 6529 | ファイル名の展開を行なった結果のリスト(空かもしれません)を返します。 |
5276 | 6530 | スカラコンテキストでは、glob はこのようなファイル名展開を繰り返し、 |
5277 | 6531 | リストがなくなったら undef を返します。 |
5278 | 6532 | これは、C<< <*.c> >> 演算子を実装する内部関数ですが、 |
5279 | 6533 | 直接使用することもできます。 |
5280 | EXPR | |
6534 | EXPR が省略されると、L<C<$_>|perlvar/$_> が使われます。 | |
5281 | 6535 | C<< <*.c> >>演算子については |
5282 | 6536 | L<perlop/"I/O Operators"> でより詳細に議論しています。 |
5283 | 6537 | |
5284 | 6538 | =begin original |
5285 | 6539 | |
5286 | Note that C<glob> splits its arguments on whitespace and | |
6540 | Note that L<C<glob>|/glob EXPR> splits its arguments on whitespace and | |
5287 | ||
6541 | treats | |
6542 | each segment as separate pattern. As such, C<glob("*.c *.h")> | |
5288 | 6543 | matches all files with a F<.c> or F<.h> extension. The expression |
5289 | 6544 | C<glob(".* *")> matches all files in the current working directory. |
6545 | If you want to glob filenames that might contain whitespace, you'll | |
6546 | have to use extra quotes around the spacey filename to protect it. | |
6547 | For example, to glob filenames that have an C<e> followed by a space | |
6548 | followed by an C<f>, use one of: | |
5290 | 6549 | |
5291 | 6550 | =end original |
5292 | 6551 | |
5293 | C<glob> は引数を空白で分割して、それぞれ | |
6552 | L<C<glob>|/glob EXPR> は引数を空白で分割して、それぞれを分割された | |
5294 | ||
6553 | パターンとして扱います。 | |
5295 | ||
6554 | 従って、C<glob("*.c *.h")> は F<.c> または F<.h> 拡張子を持つ全てのファイルに | |
5296 | ||
6555 | マッチングします。 | |
5297 | C<glob(".* *")> | |
6556 | 式 C<glob(".* *")> はカレントワーキングディレクトリの全てのファイルに | |
5298 | ||
6557 | マッチングします。 | |
6558 | 空白を含んでいるかも知れないファイル名をグロブしたい場合、それを守るために | |
6559 | 空白入りファイル名の周りに追加のクォートを使う必要があります。 | |
6560 | 例えば、C<e> の後に空白、その後に C<f> というファイル名をグロブするには | |
6561 | 以下の一つを使います: | |
5299 | 6562 | |
6563 | my @spacies = <"*e f*">; | |
6564 | my @spacies = glob '"*e f*"'; | |
6565 | my @spacies = glob q("*e f*"); | |
6566 | ||
5300 | 6567 | =begin original |
5301 | 6568 | |
6569 | If you had to get a variable through, you could do this: | |
6570 | ||
6571 | =end original | |
6572 | ||
6573 | 変数を通す必要があった場合、以下のようにできました: | |
6574 | ||
6575 | my @spacies = glob "'*${var}e f*'"; | |
6576 | my @spacies = glob qq("*${var}e f*"); | |
6577 | ||
6578 | =begin original | |
6579 | ||
5302 | 6580 | If non-empty braces are the only wildcard characters used in the |
5303 | C<glob>, no filenames are matched, but potentially many | |
6581 | L<C<glob>|/glob EXPR>, no filenames are matched, but potentially many | |
5304 | are returned. For example, this produces nine strings, one for | |
6582 | strings are returned. For example, this produces nine strings, one for | |
5305 | 6583 | each pairing of fruits and colors: |
5306 | 6584 | |
5307 | 6585 | =end original |
5308 | 6586 | |
5309 | 空でない中かっこが C<glob> で使われている唯一 | |
6587 | 空でない中かっこが L<C<glob>|/glob EXPR> で使われている唯一の | |
5310 | 場合、ファイル名とはマッチングせず、 | |
6588 | ワイルドカード文字列の場合、ファイル名とはマッチングせず、 | |
6589 | 可能性のある文字列が返されます。 | |
5311 | 6590 | 例えば、これは 9 個の文字列を生成し、それぞれは果物と色の組み合わせに |
5312 | 6591 | なります: |
5313 | 6592 | |
5314 | @many = | |
6593 | my @many = glob "{apple,tomato,cherry}={green,yellow,red}"; | |
5315 | 6594 | |
5316 | 6595 | =begin original |
5317 | 6596 | |
5318 | ||
6597 | This operator is implemented using the standard C<File::Glob> extension. | |
5319 | ||
6598 | See L<File::Glob> for details, including | |
5320 | C<bsd_glob> which does not treat whitespace | |
6599 | L<C<bsd_glob>|File::Glob/C<bsd_glob>>, which does not treat whitespace | |
6600 | as a pattern separator. | |
5321 | 6601 | |
5322 | 6602 | =end original |
5323 | 6603 | |
5324 | 6604 | v5.6.0 から、この演算子は標準の C<File::Glob> 拡張を使って |
5325 | 6605 | 実装されています。 |
5326 | 空白をパターンのセパレータとして扱わない | |
6606 | 空白をパターンのセパレータとして扱わない | |
5327 | ||
6607 | L<C<bsd_glob>|File::Glob/C<bsd_glob>> を含めた | |
6608 | 詳細は L<File::Glob> を参照してください。 | |
5328 | 6609 | |
6610 | =begin original | |
6611 | ||
6612 | Portability issues: L<perlport/glob>. | |
6613 | ||
6614 | =end original | |
6615 | ||
6616 | 移植性の問題: L<perlport/glob>。 | |
6617 | ||
5329 | 6618 | =item gmtime EXPR |
5330 | 6619 | X<gmtime> X<UTC> X<Greenwich> |
5331 | 6620 | |
5332 | 6621 | =item gmtime |
5333 | 6622 | |
6623 | =for Pod::Functions convert UNIX time into record or string using Greenwich time | |
6624 | ||
5334 | 6625 | =begin original |
5335 | 6626 | |
5336 | Works just like L<localtime> but the returned values | |
6627 | Works just like L<C<localtime>|/localtime EXPR> but the returned values | |
5337 | localized for the standard Greenwich time zone. | |
6628 | are localized for the standard Greenwich time zone. | |
5338 | 6629 | |
5339 | 6630 | =end original |
5340 | 6631 | |
5341 | L<localtime> と同様に働きますが、返り値はグリニッジ標準時に | |
6632 | L<C<localtime>|/localtime EXPR> と同様に働きますが、返り値はグリニッジ標準時に | |
5342 | 6633 | ローカライズされています。 |
5343 | 6634 | |
5344 | 6635 | =begin original |
5345 | 6636 | |
5346 | 6637 | Note: When called in list context, $isdst, the last value |
5347 | 6638 | returned by gmtime, is always C<0>. There is no |
5348 | 6639 | Daylight Saving Time in GMT. |
5349 | 6640 | |
5350 | 6641 | =end original |
5351 | 6642 | |
5352 | 6643 | 注意: リストコンテキストで呼び出した時、gmtime が返す末尾の値である |
5353 | 6644 | $isdst は常に C<0> です。 |
5354 | 6645 | GMT には夏時間はありません。 |
5355 | 6646 | |
5356 | 6647 | =begin original |
5357 | 6648 | |
5358 | ||
6649 | Portability issues: L<perlport/gmtime>. | |
5359 | 6650 | |
5360 | 6651 | =end original |
5361 | 6652 | |
5362 | 移植性の問題 | |
6653 | 移植性の問題: L<perlport/gmtime>。 | |
5363 | 6654 | |
5364 | 6655 | =item goto LABEL |
5365 | 6656 | X<goto> X<jump> X<jmp> |
5366 | 6657 | |
5367 | 6658 | =item goto EXPR |
5368 | 6659 | |
5369 | 6660 | =item goto &NAME |
5370 | 6661 | |
6662 | =for Pod::Functions create spaghetti code | |
6663 | ||
5371 | 6664 | =begin original |
5372 | 6665 | |
5373 | The C<goto | |
6666 | The C<goto LABEL> form finds the statement labeled with LABEL and | |
5374 | resumes execution there. It can't be used to get out of a block or | |
6667 | resumes execution there. It can't be used to get out of a block or | |
5375 | subroutine given to C<sort>. It can be used to go | |
6668 | subroutine given to L<C<sort>|/sort SUBNAME LIST>. It can be used to go | |
5376 | else within the dynamic scope, including out of | |
6669 | almost anywhere else within the dynamic scope, including out of | |
5377 | usually better to use some other construct such as | |
6670 | subroutines, but it's usually better to use some other construct such as | |
5378 | ||
6671 | L<C<last>|/last LABEL> or L<C<die>|/die LIST>. The author of Perl has | |
5379 | ||
6672 | never felt the need to use this form of L<C<goto>|/goto LABEL> (in Perl, | |
5380 | ||
6673 | that is; C is another matter). (The difference is that C does not offer | |
5381 | ||
6674 | named loops combined with loop control. Perl does, and this replaces | |
6675 | most structured uses of L<C<goto>|/goto LABEL> in other languages.) | |
5382 | 6676 | |
5383 | 6677 | =end original |
5384 | 6678 | |
5385 | C<goto | |
6679 | C<goto LABEL> の形式は、LABEL というラベルの付いた文を | |
5386 | 6680 | 探して、そこへ実行を移すものです。 |
5387 | C<sort> で与えられたブロックやサブルーチンから外へ | |
6681 | L<C<sort>|/sort SUBNAME LIST> で与えられたブロックやサブルーチンから外へ | |
6682 | 出ることはできません。 | |
5388 | 6683 | これ以外は、サブルーチンの外を含む、動的スコープ内の |
5389 | 6684 | ほとんどすべての場所へ行くために使用できますが、普通は、 |
5390 | C<last> や C<die> といった別の構造を使った方が | |
6685 | L<C<last>|/last LABEL> や L<C<die>|/die LIST> といった別の構造を使った方が | |
5391 | ||
6686 | 良いでしょう。 | |
6687 | Perl の作者はこの形式の L<C<goto>|/goto LABEL> を使う必要を感じたことは、 | |
5392 | 6688 | 1 度もありません (Perl では; C は別のお話です)。 |
5393 | 6689 | (違いは、C にはループ制御と結びついた名前つきのループがないことです。 |
5394 | Perl にはあり、これが他の言語でのほとんどの構造的な C<goto> の | |
6690 | Perl にはあり、これが他の言語でのほとんどの構造的な L<C<goto>|/goto LABEL> の | |
5395 | 置き換えます。) | |
6691 | 使用法を置き換えます。) | |
5396 | 6692 | |
5397 | 6693 | =begin original |
5398 | 6694 | |
5399 | The C<goto | |
6695 | The C<goto EXPR> form expects to evaluate C<EXPR> to a code reference or | |
5400 | ||
6696 | a label name. If it evaluates to a code reference, it will be handled | |
5401 | ||
6697 | like C<goto &NAME>, below. This is especially useful for implementing | |
6698 | tail recursion via C<goto __SUB__>. | |
5402 | 6699 | |
5403 | 6700 | =end original |
5404 | 6701 | |
5405 | C<goto | |
6702 | C<goto EXPR> の形式は、C<EXPR> をコードリファレンスまたはラベル名として | |
5406 | こ | |
6703 | 評価することを想定します。 | |
6704 | コードリファレンスとして評価する場合、後述する C<goto &NAME> のように | |
6705 | 扱います。 | |
6706 | これは特に、C<goto __SUB__> による末尾再帰の実装に有用です。 | |
6707 | ||
6708 | =begin original | |
6709 | ||
6710 | If the expression evaluates to a label name, its scope will be resolved | |
6711 | dynamically. This allows for computed L<C<goto>|/goto LABEL>s per | |
6712 | FORTRAN, but isn't necessarily recommended if you're optimizing for | |
6713 | maintainability: | |
6714 | ||
6715 | =end original | |
6716 | ||
6717 | 式がラベル名に評価される場合、このスコープは動的に解決されます。 | |
6718 | これにより FORTRAN のような算術 L<C<goto>|/goto LABEL> が可能になりますが、 | |
5407 | 6719 | 保守性を重視するならお勧めしません。 |
5408 | 6720 | |
5409 | 6721 | goto ("FOO", "BAR", "GLARCH")[$i]; |
5410 | 6722 | |
5411 | 6723 | =begin original |
5412 | 6724 | |
5413 | As shown in this example, C<goto | |
6725 | As shown in this example, C<goto EXPR> is exempt from the "looks like a | |
5414 | function" rule. A pair of parentheses following it does not (necessarily) | |
6726 | function" rule. A pair of parentheses following it does not (necessarily) | |
5415 | delimit its argument. C<goto("NE")."XT"> is equivalent to C<goto NEXT>. | |
6727 | delimit its argument. C<goto("NE")."XT"> is equivalent to C<goto NEXT>. | |
6728 | Also, unlike most named operators, this has the same precedence as | |
6729 | assignment. | |
5416 | 6730 | |
5417 | 6731 | =end original |
5418 | 6732 | |
5419 | この例で示したように、C<goto | |
6733 | この例で示したように、C<goto EXPR> は「関数のように見える」ルールから | |
5420 | 6734 | 除外されます。 |
5421 | 6735 | これに引き続くかっこの組は引数の区切りとは(必ずしも)なりません。 |
5422 | 6736 | C<goto("NE")."XT"> は C<goto NEXT> と等価です。 |
6737 | また、ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 | |
5423 | 6738 | |
5424 | 6739 | =begin original |
5425 | 6740 | |
5426 | Use of C<goto | |
6741 | Use of C<goto LABEL> or C<goto EXPR> to jump into a construct is | |
5427 | 6742 | deprecated and will issue a warning. Even then, it may not be used to |
5428 | 6743 | go into any construct that requires initialization, such as a |
5429 | 6744 | subroutine or a C<foreach> loop. It also can't be used to go into a |
5430 | 6745 | construct that is optimized away. |
5431 | 6746 | |
5432 | 6747 | =end original |
5433 | 6748 | |
5434 | 構造の中に飛び込むために C<goto | |
6749 | 構造の中に飛び込むために C<goto LABEL> や C<goto EXPR> を使うことは | |
5435 | 6750 | 非推奨で、警告が発生します。 |
5436 | 6751 | それでも、サブルーチンや C<foreach> ループのような、初期化が必要な |
5437 | 6752 | 構造の中に入るために使うことは出来ません。 |
5438 | 6753 | また、最適化してなくなってしまった構造の中へ入るために使うことも出来ません。 |
5439 | 6754 | |
5440 | 6755 | =begin original |
5441 | 6756 | |
5442 | The C<goto | |
6757 | The C<goto &NAME> form is quite different from the other forms of | |
5443 | C<goto>. In fact, it isn't a goto in the normal sense at | |
6758 | L<C<goto>|/goto LABEL>. In fact, it isn't a goto in the normal sense at | |
5444 | doesn't have the stigma associated with other gotos. Instead, | |
6759 | all, and doesn't have the stigma associated with other gotos. Instead, | |
5445 | exits the current subroutine (losing any changes set by | |
6760 | it exits the current subroutine (losing any changes set by | |
5446 | immediately calls in its place the named | |
6761 | L<C<local>|/local EXPR>) and immediately calls in its place the named | |
5447 | value of @_. This is used | |
6762 | subroutine using the current value of L<C<@_>|perlvar/@_>. This is used | |
5448 | ||
6763 | by C<AUTOLOAD> subroutines that wish to load another subroutine and then | |
5449 | been called in the first place | |
6764 | pretend that the other subroutine had been called in the first place | |
5450 | ||
6765 | (except that any modifications to L<C<@_>|perlvar/@_> in the current | |
5451 | ||
6766 | subroutine are propagated to the other subroutine.) After the | |
5452 | ||
6767 | L<C<goto>|/goto LABEL>, not even L<C<caller>|/caller EXPR> will be able | |
6768 | to tell that this routine was called first. | |
5453 | 6769 | |
5454 | 6770 | =end original |
5455 | 6771 | |
5456 | C<goto | |
6772 | C<goto &NAME> の形式は、その他の L<C<goto>|/goto LABEL> の形式とはかなり | |
5457 | 6773 | 異なったものです。 |
5458 | 6774 | 実際、これは普通の感覚でいうところのどこかへ行くものでは全くなく、 |
5459 | 6775 | 他の goto が持つ不名誉を持っていません。 |
5460 | 現在のサブルーチンを終了し (local | |
6776 | 現在のサブルーチンを終了し (L<C<local>|/local EXPR> による変更は失われます)、 | |
5461 | 直ちに現在の @_ の値を使って指定された名前のサブルーチンを | |
6777 | 直ちに現在の L<C<@_>|perlvar/@_> の値を使って指定された名前のサブルーチンを | |
6778 | 呼び出します。 | |
5462 | 6779 | これは、C<AUTOLOAD> サブルーチンが別のサブルーチンをロードして、 |
5463 | 6780 | その別のサブルーチンが最初に呼ばれたようにするために使われます |
5464 | (ただし、現在のサブルーチンで C<@_> を修正した場合には、 | |
6781 | (ただし、現在のサブルーチンで L<C<@_>|perlvar/@_> を修正した場合には、 | |
5465 | 6782 | その別のサブルーチンに伝えられます)。 |
5466 | C<goto> のあとは、C<caller> でさえも、現在の | |
6783 | L<C<goto>|/goto LABEL> のあとは、L<C<caller>|/caller EXPR> でさえも、現在の | |
5467 | 最初に呼び出されたと言うことができません。 | |
6784 | サブルーチンが最初に呼び出されたと言うことができません。 | |
5468 | 6785 | |
5469 | 6786 | =begin original |
5470 | 6787 | |
5471 | 6788 | NAME needn't be the name of a subroutine; it can be a scalar variable |
5472 | 6789 | containing a code reference or a block that evaluates to a code |
5473 | 6790 | reference. |
5474 | 6791 | |
5475 | 6792 | =end original |
5476 | 6793 | |
5477 | 6794 | NAME はサブルーチンの名前である必要はありません; コードリファレンスを |
5478 | 6795 | 含むスカラ値や、コードリファレンスと評価されるブロックでも構いません。 |
5479 | 6796 | |
5480 | 6797 | =item grep BLOCK LIST |
5481 | 6798 | X<grep> |
5482 | 6799 | |
5483 | 6800 | =item grep EXPR,LIST |
5484 | 6801 | |
6802 | =for Pod::Functions locate elements in a list test true against a given criterion | |
6803 | ||
5485 | 6804 | =begin original |
5486 | 6805 | |
5487 | This is similar in spirit to, but not the same as, grep(1) and its | |
6806 | This is similar in spirit to, but not the same as, L<grep(1)> and its | |
5488 | 6807 | relatives. In particular, it is not limited to using regular expressions. |
5489 | 6808 | |
5490 | 6809 | =end original |
5491 | 6810 | |
5492 | これは grep(1) とその親類と同じようなものですが、同じではありません。 | |
6811 | これは L<grep(1)> とその親類と同じようなものですが、同じではありません。 | |
5493 | 6812 | 特に、正規表現の使用に制限されません。 |
5494 | 6813 | |
5495 | 6814 | =begin original |
5496 | 6815 | |
5497 | 6816 | Evaluates the BLOCK or EXPR for each element of LIST (locally setting |
5498 | C<$_> to each element) and returns the list valu | |
6817 | L<C<$_>|perlvar/$_> to each element) and returns the list value | |
6818 | consisting of those | |
5499 | 6819 | elements for which the expression evaluated to true. In scalar |
5500 | 6820 | context, returns the number of times the expression was true. |
5501 | 6821 | |
5502 | 6822 | =end original |
5503 | 6823 | |
5504 | 6824 | LIST の個々の要素に対して、BLOCK か EXPR を評価し |
5505 | (C<$_> は、ローカルに個々の要素が設定されます) 、 | |
6825 | (L<C<$_>|perlvar/$_> は、ローカルに個々の要素が設定されます) 、 | |
5506 | 6826 | その要素のうち、評価した式が真となったものからなるリスト値が返されます。 |
5507 | スカラコンテキストでは、式が真となった回数を返します。 | |
6827 | スカラコンテキストでは、式が真となった回数を返します。 | |
5508 | 6828 | |
5509 | @foo = grep(!/^#/, @bar); # weed out comments | |
6829 | my @foo = grep(!/^#/, @bar); # weed out comments | |
5510 | 6830 | |
5511 | 6831 | =begin original |
5512 | 6832 | |
5513 | 6833 | or equivalently, |
5514 | 6834 | |
5515 | 6835 | =end original |
5516 | 6836 | |
5517 | 6837 | あるいは等価な例として: |
5518 | 6838 | |
5519 | @foo = grep {!/^#/} @bar; # weed out comments | |
6839 | my @foo = grep {!/^#/} @bar; # weed out comments | |
5520 | 6840 | |
5521 | 6841 | =begin original |
5522 | 6842 | |
5523 | Note that C<$_> is an alias to the list value, so it can | |
6843 | Note that L<C<$_>|perlvar/$_> is an alias to the list value, so it can | |
6844 | be used to | |
5524 | 6845 | modify the elements of the LIST. While this is useful and supported, |
5525 | 6846 | it can cause bizarre results if the elements of LIST are not variables. |
5526 | 6847 | Similarly, grep returns aliases into the original list, much as a for |
5527 | 6848 | loop's index variable aliases the list elements. That is, modifying an |
5528 | element of a list returned by grep (for example, in a C<foreach>, | |
6849 | element of a list returned by grep (for example, in a C<foreach>, | |
5529 | or another C<grep> | |
6850 | L<C<map>|/map BLOCK LIST> or another L<C<grep>|/grep BLOCK LIST>) | |
6851 | actually modifies the element in the original list. | |
5530 | 6852 | This is usually something to be avoided when writing clear code. |
5531 | 6853 | |
5532 | 6854 | =end original |
5533 | 6855 | |
5534 | C<$_> は、LIST の値へのエイリアスですので、LIST の要素を | |
6856 | L<C<$_>|perlvar/$_> は、LIST の値へのエイリアスですので、LIST の要素を | |
5535 | 6857 | 変更するために使うことができます。 |
5536 | 6858 | これは、便利でサポートされていますが、 |
5537 | 6859 | LIST の要素が変数でないと、おかしな結果になります。 |
5538 | 同様に、grep は元のリストへのエイリアスを返します | |
6860 | 同様に、grep は元のリストへのエイリアスを返します; for ループの | |
5539 | ||
6861 | インデックス変数がリスト要素のエイリアスであるのと同様です。 | |
5540 | 同様です。 | |
5541 | 6862 | つまり、grep で返されたリストの要素を |
5542 | (C<foreach>, C<map>, または他の | |
6863 | (C<foreach>, L<C<map>|/map BLOCK LIST>, または他の | |
5543 | 元のリストの要素が変更されます。 | |
6864 | L<C<grep>|/grep BLOCK LIST> で)修正すると元のリストの要素が変更されます。 | |
5544 | これはきれいなコードを書 | |
6865 | これはきれいなコードを書くときには普通は回避されます。 | |
5545 | 6866 | |
5546 | 6867 | =begin original |
5547 | 6868 | |
5548 | ||
6869 | See also L<C<map>|/map BLOCK LIST> for a list composed of the results of | |
5549 | ||
6870 | the BLOCK or EXPR. | |
5550 | the list elements, C<$_> keeps being lexical inside the block; i.e., it | |
5551 | can't be seen from the outside, avoiding any potential side-effects. | |
5552 | 6871 | |
5553 | 6872 | =end original |
5554 | 6873 | |
5555 | ||
6874 | BLOCK や EXPR の結果をリストの形にしたい場合は L<C<map>|/map BLOCK LIST> を | |
5556 | ||
6875 | 参照してください。 | |
5557 | C<$_> はブロック内でレキシカルでありつづけます; つまり、外側からは見えず、 | |
5558 | 起こりうる副作用を回避します。 | |
5559 | 6876 | |
5560 | =begin original | |
5561 | ||
5562 | See also L</map> for a list composed of the results of the BLOCK or EXPR. | |
5563 | ||
5564 | =end original | |
5565 | ||
5566 | BLOCK や EXPR の結果をリストの形にしたい場合は L</map> を参照してください。 | |
5567 | ||
5568 | 6877 | =item hex EXPR |
5569 | 6878 | X<hex> X<hexadecimal> |
5570 | 6879 | |
5571 | 6880 | =item hex |
5572 | 6881 | |
6882 | =for Pod::Functions convert a hexadecimal string to a number | |
6883 | ||
5573 | 6884 | =begin original |
5574 | 6885 | |
5575 | Interprets EXPR as a hex string and returns the corresponding value. | |
6886 | Interprets EXPR as a hex string and returns the corresponding numeric value. | |
5576 | ||
6887 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. | |
5577 | L</oct>.) If EXPR is omitted, uses C<$_>. | |
5578 | 6888 | |
5579 | 6889 | =end original |
5580 | 6890 | |
5581 | EXPR を 16 進数の文字列と解釈して、対応する値を返します。 | |
6891 | EXPR を 16 進数の文字列と解釈して、対応する数値を返します。 | |
5582 | ||
6892 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
5583 | 参照してください。) | |
5584 | EXPR が省略されると、C<$_> を使用します。 | |
5585 | 6893 | |
5586 | 6894 | print hex '0xAf'; # prints '175' |
5587 | 6895 | print hex 'aF'; # same |
6896 | $valid_input =~ /\A(?:0?[xX])?(?:_?[0-9a-fA-F])*\z/ | |
5588 | 6897 | |
5589 | 6898 | =begin original |
5590 | 6899 | |
5591 | ||
6900 | A hex string consists of hex digits and an optional C<0x> or C<x> prefix. | |
5592 | ||
6901 | Each hex digit may be preceded by a single underscore, which will be ignored. | |
5593 | ||
6902 | Any other character triggers a warning and causes the rest of the string | |
5594 | ||
6903 | to be ignored (even leading whitespace, unlike L<C<oct>|/oct EXPR>). | |
6904 | Only integers can be represented, and integer overflow triggers a warning. | |
5595 | 6905 | |
5596 | 6906 | =end original |
5597 | 6907 | |
5598 | 16 進文字列は | |
6908 | 16 進文字列は 16 進数と、オプションの C<0x> または C<x> 接頭辞からなります。 | |
5599 | ||
6909 | それぞれの 16 進数は一つの下線を前に置くことができ、これは無視されます。 | |
5600 | ||
6910 | その他の文字は警告を引き起こし、(例え先頭の空白でも、L<C<oct>|/oct EXPR> と | |
5601 | ||
6911 | 異なり)文字列の残りの部分は無視されます。 | |
6912 | 整数のみを表現でき、整数オーバーフローは警告を引き起こします。 | |
6913 | ||
6914 | =begin original | |
6915 | ||
6916 | To convert strings that might start with any of C<0>, C<0x>, or C<0b>, | |
6917 | see L<C<oct>|/oct EXPR>. To present something as hex, look into | |
6918 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, | |
6919 | L<C<sprintf>|/sprintf FORMAT, LIST>, and | |
6920 | L<C<unpack>|/unpack TEMPLATE,EXPR>. | |
6921 | ||
6922 | =end original | |
6923 | ||
6924 | C<0>, C<0x>, C<0b> のいずれかで始まるかもしれない文字列を変換するには、 | |
6925 | L<C<oct>|/oct EXPR> を参照してください。 | |
6926 | 何かを 16 進で表現したい場合は、L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, | |
6927 | L<C<sprintf>|/sprintf FORMAT, LIST>, L<C<unpack>|/unpack TEMPLATE,EXPR> を | |
5602 | 6928 | 参照してください。 |
5603 | 6929 | |
5604 | 6930 | =item import LIST |
5605 | 6931 | X<import> |
5606 | 6932 | |
6933 | =for Pod::Functions patch a module's namespace into your own | |
6934 | ||
5607 | 6935 | =begin original |
5608 | 6936 | |
5609 | There is no builtin C<import> function. It is just an | |
6937 | There is no builtin L<C<import>|/import LIST> function. It is just an | |
5610 | method (subroutine) defined (or inherited) by modules that wish | |
6938 | ordinary method (subroutine) defined (or inherited) by modules that wish | |
5611 | names to another module. The | |
6939 | to export names to another module. The | |
5612 | ||
6940 | L<C<use>|/use Module VERSION LIST> function calls the | |
6941 | L<C<import>|/import LIST> method for the package used. See also | |
6942 | L<C<use>|/use Module VERSION LIST>, L<perlmod>, and L<Exporter>. | |
5613 | 6943 | |
5614 | 6944 | =end original |
5615 | 6945 | |
5616 | 組み込みの C<import> 関数というものはありません。 | |
6946 | 組み込みの L<C<import>|/import LIST> 関数というものはありません。 | |
5617 | 6947 | これは単に、別のモジュールに名前をエクスポートしたいモジュールが |
5618 | 6948 | 定義した(または継承した)、通常のメソッド(サブルーチン)です。 |
5619 | C<use> 関数はパッケージを使う時に | |
6949 | L<C<use>|/use Module VERSION LIST> 関数はパッケージを使う時に | |
5620 | L< | |
6950 | L<C<import>|/import LIST> メソッドを呼び出します。 | |
6951 | L<C<use>|/use Module VERSION LIST>, L<perlmod>, L<Exporter> も | |
6952 | 参照してください。 | |
5621 | 6953 | |
5622 | 6954 | =item index STR,SUBSTR,POSITION |
5623 | 6955 | X<index> X<indexOf> X<InStr> |
5624 | 6956 | |
5625 | 6957 | =item index STR,SUBSTR |
5626 | 6958 | |
6959 | =for Pod::Functions find a substring within a string | |
6960 | ||
5627 | 6961 | =begin original |
5628 | 6962 | |
5629 | 6963 | The index function searches for one string within another, but without |
5630 | 6964 | the wildcard-like behavior of a full regular-expression pattern match. |
5631 | 6965 | It returns the position of the first occurrence of SUBSTR in STR at |
5632 | 6966 | or after POSITION. If POSITION is omitted, starts searching from the |
5633 | 6967 | beginning of the string. POSITION before the beginning of the string |
5634 | 6968 | or after its end is treated as if it were the beginning or the end, |
5635 | respectively. POSITION and the return value are based at | |
6969 | respectively. POSITION and the return value are based at zero. | |
5636 | ||
6970 | If the substring is not found, L<C<index>|/index STR,SUBSTR,POSITION> | |
5637 | ||
6971 | returns -1. | |
5638 | 6972 | |
5639 | 6973 | =end original |
5640 | 6974 | |
5641 | 6975 | index 関数は ある文字列をもうひとつの文字列から検索しますが、 |
5642 | 6976 | 完全正規表現パターンマッチのワイルドカード的な振る舞いはしません。 |
5643 | 6977 | STR の中の POSITION の位置以降で、最初に SUBSTR が見つかった位置を返します。 |
5644 | 6978 | POSITION が省略された場合には、STR の最初から探し始めます。 |
5645 | 6979 | POSITION が文字列の先頭より前、あるいは末尾より後ろを指定した場合は、 |
5646 | 6980 | それぞれ先頭と末尾を指定されたものとして扱われます。 |
5647 | POSITION と返り値のベースは、 | |
6981 | POSITION と返り値のベースは、0 です。 | |
5648 | ||
6982 | SUBSTR が見つからなかった場合には、L<C<index>|/index STR,SUBSTR,POSITION> は | |
5649 | ||
6983 | -1 が返されます。 | |
5650 | 通常は C<-1> が返されます。 | |
5651 | 6984 | |
5652 | 6985 | =item int EXPR |
5653 | 6986 | X<int> X<integer> X<truncate> X<trunc> X<floor> |
5654 | 6987 | |
5655 | 6988 | =item int |
5656 | 6989 | |
6990 | =for Pod::Functions get the integer portion of a number | |
6991 | ||
5657 | 6992 | =begin original |
5658 | 6993 | |
5659 | Returns the integer portion of EXPR. If EXPR is omitted, uses | |
6994 | Returns the integer portion of EXPR. If EXPR is omitted, uses | |
6995 | L<C<$_>|perlvar/$_>. | |
5660 | 6996 | You should not use this function for rounding: one because it truncates |
5661 | 6997 | towards C<0>, and two because machine representations of floating-point |
5662 | 6998 | numbers can sometimes produce counterintuitive results. For example, |
5663 | 6999 | C<int(-6.725/0.025)> produces -268 rather than the correct -269; that's |
5664 | 7000 | because it's really more like -268.99999999999994315658 instead. Usually, |
5665 | the C<sprintf> | |
7001 | the L<C<sprintf>|/sprintf FORMAT, LIST>, | |
5666 | ||
7002 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, or the | |
7003 | L<C<POSIX::floor>|POSIX/C<floor>> and L<C<POSIX::ceil>|POSIX/C<ceil>> | |
7004 | functions will serve you better than will L<C<int>|/int EXPR>. | |
5667 | 7005 | |
5668 | 7006 | =end original |
5669 | 7007 | |
5670 | 7008 | EXPR の整数部を返します。 |
5671 | EXPR | |
7009 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
5672 | この関数を丸めのために使うべきではありません | |
7010 | この関数を丸めのために使うべきではありません: 第一の理由として C<0> の | |
5673 | ||
7011 | 方向への切捨てを行うから、第二の理由として浮動小数点数の機械表現は時々直感に | |
5674 | ||
7012 | 反した結果を生み出すからです。 | |
5675 | たとえば、C<int(-6.725/0.025)> は正しい結果である -269 ではなく | |
7013 | たとえば、C<int(-6.725/0.025)> は正しい結果である -269 ではなく -268 を | |
5676 | -268 | |
7014 | 返します: これは実際には -268.99999999999994315658 というような値に | |
5677 | ||
7015 | なっているからです。 | |
5678 | 通常、C<sprintf> | |
7016 | 通常、L<C<sprintf>|/sprintf FORMAT, LIST>, | |
5679 | int | |
7017 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, | |
7018 | L<C<POSIX::floor>|POSIX/C<floor>>, L<C<POSIX::ceil>|POSIX/C<ceil>> の方が | |
7019 | L<C<int>|/int EXPR> より便利です。 | |
5680 | 7020 | |
5681 | 7021 | =item ioctl FILEHANDLE,FUNCTION,SCALAR |
5682 | 7022 | X<ioctl> |
5683 | 7023 | |
7024 | =for Pod::Functions system-dependent device control system call | |
7025 | ||
5684 | 7026 | =begin original |
5685 | 7027 | |
5686 | Implements the ioctl(2) function. You'll probably first have to say | |
7028 | Implements the L<ioctl(2)> function. You'll probably first have to say | |
5687 | 7029 | |
5688 | 7030 | =end original |
5689 | 7031 | |
5690 | ioctl(2) 関数を実装します。 | |
7032 | L<ioctl(2)> 関数を実装します。 | |
5691 | 7033 | 正しい関数の定義を得るために、おそらく最初に |
5692 | 7034 | |
5693 | require "sys/ioctl.ph"; # probably in | |
7035 | require "sys/ioctl.ph"; # probably in | |
7036 | # $Config{archlib}/sys/ioctl.ph | |
5694 | 7037 | |
5695 | 7038 | =begin original |
5696 | 7039 | |
5697 | 7040 | to get the correct function definitions. If F<sys/ioctl.ph> doesn't |
5698 | 7041 | exist or doesn't have the correct definitions you'll have to roll your |
5699 | 7042 | own, based on your C header files such as F<< <sys/ioctl.h> >>. |
5700 | 7043 | (There is a Perl script called B<h2ph> that comes with the Perl kit that |
5701 | 7044 | may help you in this, but it's nontrivial.) SCALAR will be read and/or |
5702 | 7045 | written depending on the FUNCTION; a C pointer to the string value of SCALAR |
5703 | will be passed as the third argument of the actual | |
7046 | will be passed as the third argument of the actual | |
7047 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> call. (If SCALAR | |
5704 | 7048 | has no string value but does have a numeric value, that value will be |
5705 | 7049 | passed rather than a pointer to the string value. To guarantee this to be |
5706 | true, add a C<0> to the scalar before using it.) The | |
7050 | true, add a C<0> to the scalar before using it.) The | |
7051 | L<C<pack>|/pack TEMPLATE,LIST> and L<C<unpack>|/unpack TEMPLATE,EXPR> | |
5707 | 7052 | functions may be needed to manipulate the values of structures used by |
5708 | C<ioctl>. | |
7053 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>. | |
5709 | 7054 | |
5710 | 7055 | =end original |
5711 | 7056 | |
5712 | 7057 | としなくてはならないでしょう。 |
5713 | 7058 | F<sys/ioctl.ph> がないか、間違った定義をしている場合には、 |
5714 | F<< <sys/ioctl. | |
7059 | F<< <sys/ioctl.h> >>のような C のヘッダファイルをもとに、 | |
5715 | 7060 | 自分で作らなければなりません。 |
5716 | (Perl の配布キットに入っている B<h2ph> という | |
7061 | (Perl の配布キットに入っている B<h2ph> という Perl スクリプトが | |
5717 | ||
7062 | これを手助けしてくれるでしょうが、これは自明ではありません。) | |
5718 | 7063 | FOUNCTION に応じて SCALAR が読み書きされます; |
5719 | SCALAR の文字列値へのポインタが、実際の | |
7064 | SCALAR の文字列値へのポインタが、実際の | |
7065 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> コールの | |
5720 | 7066 | 3 番目の引数として渡されます。 |
5721 | 7067 | (SCALAR が文字列値を持っておらず、数値を持っている場合には、 |
5722 | 7068 | 文字列値へのポインタの代わりに、その値が渡されます。 |
5723 | 7069 | このことを保証するためには、使用する前に SCALAR にC<0> を足してください。) |
5724 | C<ioctl> で使われる構造体の値を | |
7070 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> で使われる構造体の値を | |
5725 | C<pack> | |
7071 | 操作するには、L<C<pack>|/pack TEMPLATE,LIST> 関数と | |
7072 | L<C<unpack>|/unpack TEMPLATE,EXPR> 関数が必要となるでしょう。 | |
5726 | 7073 | |
5727 | 7074 | =begin original |
5728 | 7075 | |
5729 | The return value of C<ioctl> | |
7076 | The return value of L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> (and | |
7077 | L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>) is as follows: | |
5730 | 7078 | |
5731 | 7079 | =end original |
5732 | 7080 | |
5733 | C<ioctl> | |
7081 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> | |
7082 | (と L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>) の返り値は、 | |
7083 | 以下のようになります: | |
5734 | 7084 | |
5735 | 7085 | =begin original |
5736 | 7086 | |
5737 | 7087 | if OS returns: then Perl returns: |
5738 | 7088 | -1 undefined value |
5739 | 7089 | 0 string "0 but true" |
5740 | 7090 | anything else that number |
5741 | 7091 | |
5742 | 7092 | =end original |
5743 | 7093 | |
5744 | 7094 | OS が返した値: Perl が返す値: |
5745 | 7095 | -1 未定義値 |
5746 | 7096 | 0 「0 だが真」の文字列 |
5747 | 7097 | その他 その値そのもの |
5748 | 7098 | |
5749 | 7099 | =begin original |
5750 | 7100 | |
5751 | 7101 | Thus Perl returns true on success and false on failure, yet you can |
5752 | 7102 | still easily determine the actual value returned by the operating |
5753 | 7103 | system: |
5754 | 7104 | |
5755 | 7105 | =end original |
5756 | 7106 | |
5757 | 7107 | つまり Perl は、成功時に「真」、失敗時に「偽」を返す |
5758 | 7108 | ことになり、OS が実際に返した値も、以下のように簡単に知ることができます。 |
5759 | 7109 | |
5760 | $retval = ioctl(...) || -1; | |
7110 | my $retval = ioctl(...) || -1; | |
5761 | 7111 | printf "System returned %d\n", $retval; |
5762 | 7112 | |
5763 | 7113 | =begin original |
5764 | 7114 | |
5765 | The special string C<"0 but true"> is exempt from | |
7115 | The special string C<"0 but true"> is exempt from | |
5766 | ||
7116 | L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s> | |
7117 | L<warnings> on improper numeric conversions. | |
5767 | 7118 | |
5768 | 7119 | =end original |
5769 | 7120 | |
5770 | 7121 | 特別な文字列 C<"0 だが真"> は、不適切な数値変換に関する |
5771 | ||
7122 | L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s> | |
7123 | L<warnings> 警告を回避します。 | |
5772 | 7124 | |
7125 | =begin original | |
7126 | ||
7127 | Portability issues: L<perlport/ioctl>. | |
7128 | ||
7129 | =end original | |
7130 | ||
7131 | 移植性の問題: L<perlport/ioctl>。 | |
7132 | ||
5773 | 7133 | =item join EXPR,LIST |
5774 | 7134 | X<join> |
5775 | 7135 | |
7136 | =for Pod::Functions join a list into a string using a separator | |
7137 | ||
5776 | 7138 | =begin original |
5777 | 7139 | |
5778 | 7140 | Joins the separate strings of LIST into a single string with fields |
5779 | 7141 | separated by the value of EXPR, and returns that new string. Example: |
5780 | 7142 | |
5781 | 7143 | =end original |
5782 | 7144 | |
5783 | 7145 | LIST の個別の文字列を、EXPR の値で区切って |
5784 | 7146 | 1 つの文字列につなげ、その文字列を返します。 |
5785 | 7147 | 例: |
5786 | 7148 | |
5787 | $rec = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell); | |
7149 | my $rec = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell); | |
5788 | 7150 | |
5789 | 7151 | =begin original |
5790 | 7152 | |
5791 | Beware that unlike C<split> | |
7153 | Beware that unlike L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>, | |
5792 | ||
7154 | L<C<join>|/join EXPR,LIST> doesn't take a pattern as its first argument. | |
7155 | Compare L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>. | |
5793 | 7156 | |
5794 | 7157 | =end original |
5795 | 7158 | |
5796 | C<split> | |
7159 | L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> と違って、 | |
7160 | L<C<join>|/join EXPR,LIST> は最初の引数にパターンは取れないことに | |
5797 | 7161 | 注意してください。 |
5798 | L</split> と比較してください。 | |
7162 | L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> と比較してください。 | |
5799 | 7163 | |
5800 | 7164 | =item keys HASH |
5801 | 7165 | X<keys> X<key> |
5802 | 7166 | |
5803 | 7167 | =item keys ARRAY |
5804 | 7168 | |
5805 | =ite | |
7169 | =for Pod::Functions retrieve list of indices from a hash | |
5806 | 7170 | |
5807 | 7171 | =begin original |
5808 | 7172 | |
5809 | ||
7173 | Called in list context, returns a list consisting of all the keys of the | |
5810 | ||
7174 | named hash, or in Perl 5.12 or later only, the indices of an array. Perl | |
7175 | releases prior to 5.12 will produce a syntax error if you try to use an | |
7176 | array argument. In scalar context, returns the number of keys or indices. | |
5811 | 7177 | |
5812 | 7178 | =end original |
5813 | 7179 | |
5814 | 指定したハッシュのすべてのキー、あるいは | |
7180 | リストコンテキストで呼び出されると、指定したハッシュのすべてのキー、あるいは | |
5815 | 返します。 | |
7181 | Perl 5.12 以降でのみ、配列のインデックスからなるリストを返します。 | |
5816 | ||
7182 | 5.12 より前の Perl は配列引数を使おうとすると文法エラーを出力します。 | |
7183 | スカラコンテキストでは、キーやインデックスの数を返します。 | |
5817 | 7184 | |
5818 | 7185 | =begin original |
5819 | 7186 | |
5820 | ||
7187 | Hash entries are returned in an apparently random order. The actual random | |
5821 | ||
7188 | order is specific to a given hash; the exact same series of operations | |
5822 | ||
7189 | on two hashes may result in a different order for each hash. Any insertion | |
5823 | ||
7190 | into the hash may change the order, as will any deletion, with the exception | |
5824 | ||
7191 | that the most recent key returned by L<C<each>|/each HASH> or | |
5825 | ||
7192 | L<C<keys>|/keys HASH> may be deleted without changing the order. So | |
5826 | ||
7193 | long as a given hash is unmodified you may rely on | |
7194 | L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and L<C<each>|/each | |
7195 | HASH> to repeatedly return the same order | |
7196 | as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for | |
7197 | details on why hash order is randomized. Aside from the guarantees | |
7198 | provided here the exact details of Perl's hash algorithm and the hash | |
7199 | traversal order are subject to change in any release of Perl. Tied hashes | |
7200 | may behave differently to Perl's hashes with respect to changes in order on | |
7201 | insertion and deletion of items. | |
5827 | 7202 | |
5828 | 7203 | =end original |
5829 | 7204 | |
5830 | ハッシュ | |
7205 | ハッシュ要素は見かけ上、ランダムな順序で返されます。 | |
5831 | 実際のランダムな順 | |
7206 | 実際のランダムな順序はハッシュに固有です; 二つのハッシュに全く同じ一連の | |
5832 | ||
7207 | 操作を行っても、ハッシュによって異なった順序になります。 | |
5833 | ||
7208 | ハッシュへの挿入によって順序が変わることがあります; 削除も同様ですが、 | |
5834 | ||
7209 | L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも | |
5835 | ||
7210 | 最近のキーは順序を変えることなく削除できます。 | |
5836 | ||
7211 | ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>, | |
7212 | L<C<each>|/each HASH> が繰り返し同じ順序で | |
7213 | 返すことに依存してもかまいません。 | |
7214 | なぜハッシュの順序がランダム化されているかの詳細については | |
7215 | L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。 | |
7216 | ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の | |
7217 | 正確な詳細は Perl のリリースによって変更される可能性があります。 | |
7218 | tie されたハッシュは、アイテムの挿入と削除の順序に関して Perl のハッシュと | |
7219 | 異なった振る舞いをします。 | |
5837 | 7220 | |
5838 | 7221 | =begin original |
5839 | 7222 | |
5840 | As a side effect, calling keys | |
7223 | As a side effect, calling L<C<keys>|/keys HASH> resets the internal | |
5841 | (see L</each>). In | |
7224 | iterator of the HASH or ARRAY (see L<C<each>|/each HASH>). In | |
5842 | t | |
7225 | particular, calling L<C<keys>|/keys HASH> in void context resets the | |
7226 | iterator with no other overhead. | |
5843 | 7227 | |
5844 | 7228 | =end original |
5845 | 7229 | |
5846 | 副作用として、HASH や ARRAY の反復子を | |
7230 | 副作用として、L<C<keys>|/keys HASH> の呼び出しは HASH や ARRAY の反復子を | |
5847 | (L</each> を参照してください)。 | |
7231 | 初期化します (L<C<each>|/each HASH> を参照してください)。 | |
5848 | 特に、無効コンテキストで keys | |
7232 | 特に、無効コンテキストで L<C<keys>|/keys HASH> を呼び出すと | |
5849 | 7233 | オーバーヘッドなしで反復子を初期化します。 |
5850 | 7234 | |
5851 | 7235 | =begin original |
5852 | 7236 | |
5853 | 7237 | Here is yet another way to print your environment: |
5854 | 7238 | |
5855 | 7239 | =end original |
5856 | 7240 | |
5857 | 7241 | 環境変数を表示する別の例です: |
5858 | 7242 | |
5859 | @keys = keys %ENV; | |
7243 | my @keys = keys %ENV; | |
5860 | @values = values %ENV; | |
7244 | my @values = values %ENV; | |
5861 | 7245 | while (@keys) { |
5862 | 7246 | print pop(@keys), '=', pop(@values), "\n"; |
5863 | 7247 | } |
5864 | 7248 | |
5865 | 7249 | =begin original |
5866 | 7250 | |
5867 | 7251 | or how about sorted by key: |
5868 | 7252 | |
5869 | 7253 | =end original |
5870 | 7254 | |
5871 | 7255 | key でソートしてもいいでしょう: |
5872 | 7256 | |
5873 | foreach $key (sort(keys %ENV)) { | |
7257 | foreach my $key (sort(keys %ENV)) { | |
5874 | 7258 | print $key, '=', $ENV{$key}, "\n"; |
5875 | 7259 | } |
5876 | 7260 | |
5877 | 7261 | =begin original |
5878 | 7262 | |
5879 | 7263 | The returned values are copies of the original keys in the hash, so |
5880 | modifying them will not affect the original hash. Compare | |
7264 | modifying them will not affect the original hash. Compare | |
7265 | L<C<values>|/values HASH>. | |
5881 | 7266 | |
5882 | 7267 | =end original |
5883 | 7268 | |
5884 | 7269 | 返される値はハッシュにある元のキーのコピーなので、 |
5885 | 7270 | これを変更しても元のハッシュには影響を与えません。 |
5886 | L</values> と比較してください。 | |
7271 | L<C<values>|/values HASH> と比較してください。 | |
5887 | 7272 | |
5888 | 7273 | =begin original |
5889 | 7274 | |
5890 | To sort a hash by value, you'll need to use a | |
7275 | To sort a hash by value, you'll need to use a | |
5891 | Here's a descending numeric | |
7276 | L<C<sort>|/sort SUBNAME LIST> function. Here's a descending numeric | |
7277 | sort of a hash by its values: | |
5892 | 7278 | |
5893 | 7279 | =end original |
5894 | 7280 | |
5895 | ハッシュを値でソートするためには、C<sort> 関数を使う | |
7281 | ハッシュを値でソートするためには、L<C<sort>|/sort SUBNAME LIST> 関数を使う | |
7282 | 必要があります。 | |
5896 | 7283 | 以下ではハッシュの値を数値の降順でソートしています: |
5897 | 7284 | |
5898 | foreach $key (sort { $hash{$b} <=> $hash{$a} } keys %hash) { | |
7285 | foreach my $key (sort { $hash{$b} <=> $hash{$a} } keys %hash) { | |
5899 | 7286 | printf "%4d %s\n", $hash{$key}, $key; |
5900 | 7287 | } |
5901 | 7288 | |
5902 | 7289 | =begin original |
5903 | 7290 | |
5904 | Used as an lvalue, C<keys> allows you to increase the | |
7291 | Used as an lvalue, L<C<keys>|/keys HASH> allows you to increase the | |
7292 | number of hash buckets | |
5905 | 7293 | allocated for the given hash. This can gain you a measure of efficiency if |
5906 | 7294 | you know the hash is going to get big. (This is similar to pre-extending |
5907 | 7295 | an array by assigning a larger number to $#array.) If you say |
5908 | 7296 | |
5909 | 7297 | =end original |
5910 | 7298 | |
5911 | 左辺値として使うことで、C<keys> を使うことで与えられたハッシュに | |
7299 | 左辺値として使うことで、L<C<keys>|/keys HASH> を使うことで与えられたハッシュに | |
5912 | ハッシュ表の大きさを増やすことができます。 | |
7300 | 割り当てられたハッシュ表の大きさを増やすことができます。 | |
5913 | 7301 | これによって、ハッシュが大きくなっていくなっていくときの |
5914 | 7302 | 効率の測定ができます。 |
5915 | 7303 | (これは大きい値を $#array に代入することで配列を予め拡張することに |
5916 | 7304 | 似ています。) |
5917 | 7305 | 以下のようにすると: |
5918 | 7306 | |
5919 | 7307 | keys %hash = 200; |
5920 | 7308 | |
5921 | 7309 | =begin original |
5922 | 7310 | |
5923 | 7311 | then C<%hash> will have at least 200 buckets allocated for it--256 of them, |
5924 | 7312 | in fact, since it rounds up to the next power of two. These |
5925 | 7313 | buckets will be retained even if you do C<%hash = ()>, use C<undef |
5926 | 7314 | %hash> if you want to free the storage while C<%hash> is still in scope. |
5927 | 7315 | You can't shrink the number of buckets allocated for the hash using |
5928 | C<keys> in this way (but you needn't worry about doing | |
7316 | L<C<keys>|/keys HASH> in this way (but you needn't worry about doing | |
5929 | as trying has no effect). C<keys @array> in an lvalue | |
7317 | this by accident, as trying has no effect). C<keys @array> in an lvalue | |
5930 | error. | |
7318 | context is a syntax error. | |
5931 | 7319 | |
5932 | 7320 | =end original |
5933 | 7321 | |
5934 | C<%hash> は少なくとも 200 の大きさの表が割り当てられます -- | |
7322 | C<%hash> は少なくとも 200 の大きさの表が割り当てられます -- | |
5935 | 7323 | 実際には 2 のべき乗に切り上げられるので、256 が割り当てられます。 |
5936 | 7324 | この表はたとえ C<%hash = ()> としても残るので、 |
5937 | 7325 | もし C<%hash> がスコープにいるうちにこの領域を開放したい場合は |
5938 | 7326 | C<undef %hash> を使います。 |
5939 | この方法で C<keys> を使うことで、表の大きさを小さくすることは | |
7327 | この方法で L<C<keys>|/keys HASH> を使うことで、表の大きさを小さくすることは | |
7328 | できません | |
5940 | 7329 | (間違えてそのようなことをしても何も起きないので気にすることはありません)。 |
5941 | 7330 | 左辺値コンテキストでの C<keys @array> は文法エラーとなります。 |
5942 | 7331 | |
5943 | 7332 | =begin original |
5944 | 7333 | |
5945 | Starting with Perl 5.14, | |
7334 | Starting with Perl 5.14, an experimental feature allowed | |
5946 | ||
7335 | L<C<keys>|/keys HASH> to take a scalar expression. This experiment has | |
5947 | ||
7336 | been deemed unsuccessful, and was removed as of Perl 5.24. | |
5948 | experimental. The exact behaviour may change in a future version of Perl. | |
5949 | 7337 | |
5950 | 7338 | =end original |
5951 | 7339 | |
5952 | Perl 5.14 から、C<keys> | |
7340 | Perl 5.14 から、L<C<keys>|/keys HASH> がスカラ式を取ることが出来るという | |
5953 | ||
7341 | 実験的機能がありました。 | |
5954 | ||
7342 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 | |
5955 | C<keys> のこの動作は高度に実験的であると考えられています。 | |
5956 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 | |
5957 | 7343 | |
5958 | | |
7344 | =begin original | |
5959 | for (keys $obj->get_arrayref) { ... } | |
5960 | 7345 | |
7346 | To avoid confusing would-be users of your code who are running earlier | |
7347 | versions of Perl with mysterious syntax errors, put this sort of thing at | |
7348 | the top of your file to signal that your code will work I<only> on Perls of | |
7349 | a recent vintage: | |
7350 | ||
7351 | =end original | |
7352 | ||
7353 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な | |
7354 | 文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で | |
7355 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを | |
7356 | 書いてください: | |
7357 | ||
7358 | use 5.012; # so keys/values/each work on arrays | |
7359 | ||
5961 | 7360 | =begin original |
5962 | 7361 | |
5963 | See also C<each>, C<values>, and | |
7362 | See also L<C<each>|/each HASH>, L<C<values>|/values HASH>, and | |
7363 | L<C<sort>|/sort SUBNAME LIST>. | |
5964 | 7364 | |
5965 | 7365 | =end original |
5966 | 7366 | |
5967 | C<each>, C<values> | |
7367 | L<C<each>|/each HASH>, L<C<values>|/values HASH>, | |
7368 | L<C<sort>|/sort SUBNAME LIST> も参照してください。 | |
5968 | 7369 | |
5969 | 7370 | =item kill SIGNAL, LIST |
7371 | ||
7372 | =item kill SIGNAL | |
5970 | 7373 | X<kill> X<signal> |
5971 | 7374 | |
7375 | =for Pod::Functions send a signal to a process or process group | |
7376 | ||
5972 | 7377 | =begin original |
5973 | 7378 | |
5974 | Sends a signal to a list of processes. Returns the number of | |
7379 | Sends a signal to a list of processes. Returns the number of arguments | |
5975 | ||
7380 | that were successfully used to signal (which is not necessarily the same | |
5976 | ||
7381 | as the number of processes actually killed, e.g. where a process group is | |
7382 | killed). | |
5977 | 7383 | |
5978 | 7384 | =end original |
5979 | 7385 | |
5980 | プロセスのリストにシグナルを送ります。 | |
7386 | プロセスのリストにシグナルを送ります。 | |
5981 | 数を返します | |
7387 | シグナル送信に使われた引数の数を返します | |
5982 | (実際に kill | |
7388 | (例えばプロセスグループが kill された場合のように、実際に kill された | |
7389 | プロセスの数と同じとは限りません)。 | |
5983 | 7390 | |
5984 | $cnt = kill | |
7391 | my $cnt = kill 'HUP', $child1, $child2; | |
5985 | kill | |
7392 | kill 'KILL', @goners; | |
5986 | 7393 | |
5987 | 7394 | =begin original |
5988 | 7395 | |
5989 | ||
7396 | SIGNAL may be either a signal name (a string) or a signal number. A signal | |
5990 | ||
7397 | name may start with a C<SIG> prefix, thus C<FOO> and C<SIGFOO> refer to the | |
5991 | me | |
7398 | same signal. The string form of SIGNAL is recommended for portability because | |
5992 | the s | |
7399 | the same signal may have different numbers in different operating systems. | |
5993 | alive (even if only as a zombie) and hasn't changed its UID. See | |
5994 | L<perlport> for notes on the portability of this construct. | |
5995 | 7400 | |
5996 | 7401 | =end original |
5997 | 7402 | |
5998 | SIGNAL | |
7403 | SIGNAL はシグナル名(文字列)かシグナル番号のどちらかです。 | |
5999 | ||
7404 | シグナル名は C<SIG> 接頭辞で始まることがあるので、C<FOO> と C<SIGFOO> は同じ | |
6000 | ||
7405 | シグナルを意味します。 | |
6001 | ||
7406 | 移植性から文字列形式の SIGNAL が推奨されます; 同じシグナルが異なった | |
6002 | ||
7407 | オペレーティングシステムでは異なった番号になることがあるからです。 | |
6003 | 変わっていないことを調べる時に有用です。 | |
6004 | この構成の移植性に関する注意については L<perlport> を参照して下さい。 | |
6005 | 7408 | |
6006 | 7409 | =begin original |
6007 | 7410 | |
6008 | ||
7411 | A list of signal names supported by the current platform can be found in | |
6009 | of | |
7412 | C<$Config{sig_name}>, which is provided by the L<C<Config>|Config> | |
6010 | ||
7413 | module. See L<Config> for more details. | |
6011 | 7414 | |
6012 | 7415 | =end original |
6013 | 7416 | |
6014 | シ | |
7417 | 現在のプラットフォームが対応しているシグナル名の一覧は、L<C<Config>|Config> | |
7418 | モジュールによって提供される C<$Config{sig_name}> にあります。 | |
7419 | さらなる詳細については L<Config> を参照してください。 | |
7420 | ||
7421 | =begin original | |
7422 | ||
7423 | A negative signal name is the same as a negative signal number, killing process | |
7424 | groups instead of processes. For example, C<kill '-KILL', $pgrp> and | |
7425 | C<kill -9, $pgrp> will send C<SIGKILL> to | |
7426 | the entire process group specified. That | |
7427 | means you usually want to use positive not negative signals. | |
7428 | ||
7429 | =end original | |
7430 | ||
7431 | 負のシグナル名は負のシグナル番号と同じで、 | |
6015 | 7432 | プロセスではなくプロセスグループに対して kill を行ないます。 |
7433 | たとえば、C<kill '-KILL', $pgrp> と C<kill -9, $pgrp> は指定された | |
7434 | プロセスグループ全体に C<SIGKILL> を送ります。 | |
6016 | 7435 | すなわち、通常は、負のシグナルは用いず、正のシグナルを使うことになります。 |
6017 | シグナル名をクォートして使うこともできます。 | |
6018 | 7436 | |
6019 | 7437 | =begin original |
6020 | 7438 | |
7439 | If SIGNAL is either the number 0 or the string C<ZERO> (or C<SIGZERO>), | |
7440 | no signal is sent to the process, but L<C<kill>|/kill SIGNAL, LIST> | |
7441 | checks whether it's I<possible> to send a signal to it | |
7442 | (that means, to be brief, that the process is owned by the same user, or we are | |
7443 | the super-user). This is useful to check that a child process is still | |
7444 | alive (even if only as a zombie) and hasn't changed its UID. See | |
7445 | L<perlport> for notes on the portability of this construct. | |
7446 | ||
7447 | =end original | |
7448 | ||
7449 | SIGNAL が数値 0 か文字列 C<ZERO> (または C<SIGZERO> の場合、プロセスに | |
7450 | シグナルは送られませんが、L<C<kill>|/kill SIGNAL, LIST> は、 | |
7451 | シグナルを送ることが I<可能> かどうかを調べます (これは、簡単に言うと、 | |
7452 | プロセスが同じユーザーに所有されているか、自分がスーパーユーザーであることを | |
7453 | 意味します)。 | |
7454 | これは子プロセスが(ゾンビとしてだけでも)まだ生きていて、 UID が | |
7455 | 変わっていないことを調べる時に有用です。 | |
7456 | この構成の移植性に関する注意については L<perlport> を参照してください。 | |
7457 | ||
7458 | =begin original | |
7459 | ||
6021 | 7460 | The behavior of kill when a I<PROCESS> number is zero or negative depends on |
6022 | 7461 | the operating system. For example, on POSIX-conforming systems, zero will |
6023 | signal the current process group | |
7462 | signal the current process group, -1 will signal all processes, and any | |
7463 | other negative PROCESS number will act as a negative signal number and | |
7464 | kill the entire process group specified. | |
6024 | 7465 | |
6025 | 7466 | =end original |
6026 | 7467 | |
6027 | 7468 | I<PROCESS> 番号が 0 あるいは負数の場合の kill の振る舞いは |
6028 | 7469 | オペレーティングシステムに依存します。 |
6029 | 7470 | 例えば、POSIX 準拠のシステムでは、0 は現在のプロセスグループにシグナルを送り、 |
6030 | -1 は全てのプロセスにシグナルを送り | |
7471 | -1 は全てのプロセスにシグナルを送り、それ以外の負数の PROCESS 番号は | |
7472 | 負数のシグナル番号として動作し、指定されたプロセスグループ全体を kill します。 | |
6031 | 7473 | |
6032 | 7474 | =begin original |
6033 | 7475 | |
7476 | If both the SIGNAL and the PROCESS are negative, the results are undefined. | |
7477 | A warning may be produced in a future version. | |
7478 | ||
7479 | =end original | |
7480 | ||
7481 | SIGNAL と PROCESS の両方が負数の場合、結果は未定義です。 | |
7482 | 将来のバージョンでは警告が出るかも知れません。 | |
7483 | ||
7484 | =begin original | |
7485 | ||
6034 | 7486 | See L<perlipc/"Signals"> for more details. |
6035 | 7487 | |
6036 | 7488 | =end original |
6037 | 7489 | |
6038 | 7490 | 詳細は L<perlipc/"Signals"> を参照してください。 |
6039 | 7491 | |
7492 | =begin original | |
7493 | ||
7494 | On some platforms such as Windows where the L<fork(2)> system call is not | |
7495 | available, Perl can be built to emulate L<C<fork>|/fork> at the | |
7496 | interpreter level. | |
7497 | This emulation has limitations related to kill that have to be considered, | |
7498 | for code running on Windows and in code intended to be portable. | |
7499 | ||
7500 | =end original | |
7501 | ||
7502 | Windows のような L<fork(2)> が利用不能なシステムでは、Perl は | |
7503 | L<C<fork>|/fork> をインタプリタレベルでエミュレートします。 | |
7504 | エミュレーションは kill に関連して、コードが Windows で実行されて | |
7505 | しかしコードが移植性があると考えられるように制限があります。 | |
7506 | ||
7507 | =begin original | |
7508 | ||
7509 | See L<perlfork> for more details. | |
7510 | ||
7511 | =end original | |
7512 | ||
7513 | さらなる詳細については L<perlfork> を参照してください。 | |
7514 | ||
7515 | =begin original | |
7516 | ||
7517 | If there is no I<LIST> of processes, no signal is sent, and the return | |
7518 | value is 0. This form is sometimes used, however, because it causes | |
7519 | tainting checks to be run. But see | |
7520 | L<perlsec/Laundering and Detecting Tainted Data>. | |
7521 | ||
7522 | =end original | |
7523 | ||
7524 | 処理する I<LIST> がない場合、シグナルは送られず、返り値は 0 です。 | |
7525 | しかし、この形式は時々使われます; 実行するために汚染チェックを | |
7526 | 引き起こすからです。 | |
7527 | しかし L<perlsec/Laundering and Detecting Tainted Data> を参照してください。 | |
7528 | ||
7529 | =begin original | |
7530 | ||
7531 | Portability issues: L<perlport/kill>. | |
7532 | ||
7533 | =end original | |
7534 | ||
7535 | 移植性の問題: L<perlport/kill>。 | |
7536 | ||
6040 | 7537 | =item last LABEL |
6041 | 7538 | X<last> X<break> |
6042 | 7539 | |
7540 | =item last EXPR | |
7541 | ||
6043 | 7542 | =item last |
6044 | 7543 | |
7544 | =for Pod::Functions exit a block prematurely | |
7545 | ||
6045 | 7546 | =begin original |
6046 | 7547 | |
6047 | The C<last> command is like the C<break> statement in C | |
7548 | The L<C<last>|/last LABEL> command is like the C<break> statement in C | |
7549 | (as used in | |
6048 | 7550 | loops); it immediately exits the loop in question. If the LABEL is |
6049 | omitted, the command refers to the innermost enclosing | |
7551 | omitted, the command refers to the innermost enclosing | |
6050 | C< | |
7552 | loop. The C<last EXPR> form, available starting in Perl | |
7553 | 5.18.0, allows a label name to be computed at run time, | |
7554 | and is otherwise identical to C<last LABEL>. The | |
7555 | L<C<continue>|/continue BLOCK> block, if any, is not executed: | |
6051 | 7556 | |
6052 | 7557 | =end original |
6053 | 7558 | |
6054 | C<last> コマンドは、(ループ内で使った) C の C<break> 文と | |
7559 | L<C<last>|/last LABEL> コマンドは、(ループ内で使った) C の C<break> 文と | |
6055 | 7560 | 同じようなもので、LABEL で指定されるループを即座に抜けます。 |
6056 | LABEL が省略されると、一番内側のループ | |
7561 | LABEL が省略されると、コマンドは一番内側のループを参照します。 | |
6057 | C< | |
7562 | Perl 5.18.0 から利用可能な C<last EXPR> 形式では、実行時に計算される | |
7563 | ラベル名を使えます; それ以外は C<last LABEL> と同一です。 | |
7564 | L<C<continue>|/continue BLOCK> ブロックがあっても実行されません: | |
6058 | 7565 | |
6059 | 7566 | LINE: while (<STDIN>) { |
6060 | 7567 | last LINE if /^$/; # exit when done with header |
6061 | 7568 | #... |
6062 | 7569 | } |
6063 | 7570 | |
6064 | 7571 | =begin original |
6065 | 7572 | |
6066 | C<last> cannot be used to exit a block that returns a | |
7573 | L<C<last>|/last LABEL> cannot be used to exit a block that returns a | |
6067 | C<eval {}>, C<sub {}>, or C<do {}>, and should not be used | |
7574 | value such as C<eval {}>, C<sub {}>, or C<do {}>, and should not be used | |
6068 | a grep | |
7575 | to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST> | |
7576 | operation. | |
6069 | 7577 | |
6070 | 7578 | =end original |
6071 | 7579 | |
6072 | C<last> は C<eval {}>, C<sub {}>, C<do {}> といった | |
7580 | L<C<last>|/last LABEL> は C<eval {}>, C<sub {}>, C<do {}> といった | |
6073 | 7581 | 値を返すブロックを終了するのには使えませんし、 |
6074 | grep | |
7582 | L<C<grep>|/grep BLOCK LIST> や L<C<map>|/map BLOCK LIST> 操作を終了するのに | |
7583 | 使うべきではありません。 | |
6075 | 7584 | |
6076 | 7585 | =begin original |
6077 | 7586 | |
6078 | 7587 | Note that a block by itself is semantically identical to a loop |
6079 | that executes once. Thus C<last> can be used to effect | |
7588 | that executes once. Thus L<C<last>|/last LABEL> can be used to effect | |
6080 | exit out of such a block. | |
7589 | an early exit out of such a block. | |
6081 | 7590 | |
6082 | 7591 | =end original |
6083 | 7592 | |
6084 | ブロック | |
7593 | ブロック自身は一回だけ実行されるループと文法的に同一であることに | |
6085 | 注意してください。 | |
7594 | 注意してください。 | |
6086 | 途中で | |
7595 | 従って、L<C<last>|/last LABEL> でそのようなブロックを途中で | |
7596 | 抜け出すことができます。 | |
6087 | 7597 | |
6088 | 7598 | =begin original |
6089 | 7599 | |
6090 | See also L</continue> for an illustration of how | |
7600 | See also L<C<continue>|/continue BLOCK> for an illustration of how | |
6091 | C< | |
7601 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and | |
7602 | L<C<redo>|/redo LABEL> work. | |
6092 | 7603 | |
6093 | 7604 | =end original |
6094 | 7605 | |
6095 | C<last>, C<next>, C<redo> が | |
7606 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL> が | |
6096 | L</continue> も参照して | |
7607 | どのように働くかについては L<C<continue>|/continue BLOCK> も参照してください。 | |
6097 | 7608 | |
7609 | =begin original | |
7610 | ||
7611 | Unlike most named operators, this has the same precedence as assignment. | |
7612 | It is also exempt from the looks-like-a-function rule, so | |
7613 | C<last ("foo")."bar"> will cause "bar" to be part of the argument to | |
7614 | L<C<last>|/last LABEL>. | |
7615 | ||
7616 | =end original | |
7617 | ||
7618 | ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 | |
7619 | また、関数のように見えるものの規則からも免れるので、C<last ("foo")."bar"> と | |
7620 | すると "bar" は L<C<last>|/last LABEL> への引数の一部となります。 | |
7621 | ||
6098 | 7622 | =item lc EXPR |
6099 | 7623 | X<lc> X<lowercase> |
6100 | 7624 | |
6101 | 7625 | =item lc |
6102 | 7626 | |
7627 | =for Pod::Functions return lower-case version of a string | |
7628 | ||
6103 | 7629 | =begin original |
6104 | 7630 | |
6105 | 7631 | Returns a lowercased version of EXPR. This is the internal function |
6106 | 7632 | implementing the C<\L> escape in double-quoted strings. |
6107 | 7633 | |
6108 | 7634 | =end original |
6109 | 7635 | |
6110 | 7636 | EXPR を小文字に変換したものを返します。 |
6111 | 7637 | これは、ダブルクォート文字列における、 |
6112 | 7638 | C<\L> エスケープを実装する内部関数です。 |
6113 | 7639 | |
6114 | 7640 | =begin original |
6115 | 7641 | |
6116 | If EXPR is omitted, uses C<$_>. | |
7642 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. | |
6117 | 7643 | |
6118 | 7644 | =end original |
6119 | 7645 | |
6120 | EXPR が省略されると、C<$_> を使います。 | |
7646 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
6121 | 7647 | |
6122 | 7648 | =begin original |
6123 | 7649 | |
6124 | 7650 | What gets returned depends on several factors: |
6125 | 7651 | |
6126 | 7652 | =end original |
6127 | 7653 | |
6128 | 7654 | 返り値として得られるものは色々な要素に依存します: |
6129 | 7655 | |
6130 | 7656 | =over |
6131 | 7657 | |
6132 | 7658 | =item If C<use bytes> is in effect: |
6133 | 7659 | |
6134 | 7660 | (C<use bytes> が有効の場合) |
6135 | 7661 | |
6136 | =over | |
6137 | ||
6138 | =item On EBCDIC platforms | |
6139 | ||
6140 | 7662 | =begin original |
6141 | 7663 | |
6142 | The results | |
7664 | The results follow ASCII rules. Only the characters C<A-Z> change, | |
7665 | to C<a-z> respectively. | |
6143 | 7666 | |
6144 | 7667 | =end original |
6145 | 7668 | |
6146 | 結果は | |
7669 | 結果は ASCII の規則に従います。 | |
7670 | C<A-Z> のみが変換され、それぞれ C<a-z> になります。 | |
6147 | 7671 | |
6148 | =item O | |
7672 | =item Otherwise, if C<use locale> for C<LC_CTYPE> is in effect: | |
6149 | 7673 | |
7674 | (それ以外の場合で、C<LC_CTYPE> に対して C<use locale> が有効の場合) | |
7675 | ||
6150 | 7676 | =begin original |
6151 | 7677 | |
6152 | ||
7678 | Respects current C<LC_CTYPE> locale for code points < 256; and uses Unicode | |
6153 | res | |
7679 | rules for the remaining code points (this last can only happen if | |
7680 | the UTF8 flag is also set). See L<perllocale>. | |
6154 | 7681 | |
6155 | 7682 | =end original |
6156 | 7683 | |
6157 | ||
7684 | 符号位置 < 256 に対しては現在の C<LC_CTYPE> ロケールに従います; そして | |
6158 | ||
7685 | 残りの符号位置に付いては Unicode の規則を使います (これは UTF8 フラグも | |
7686 | 設定されている場合にのみ起こります)。 | |
7687 | L<perllocale> を参照してください。 | |
6159 | 7688 | |
6160 | =back | |
6161 | ||
6162 | =item Otherwise, If EXPR has the UTF8 flag set | |
6163 | ||
6164 | (その他の場合で、EXPR に UTF8 フラグがセットされている場合) | |
6165 | ||
6166 | 7689 | =begin original |
6167 | 7690 | |
6168 | ||
7691 | Starting in v5.20, Perl uses full Unicode rules if the locale is | |
6169 | ||
7692 | UTF-8. Otherwise, there is a deficiency in this scheme, which is that | |
6170 | ||
7693 | case changes that cross the 255/256 | |
6171 | ||
7694 | boundary are not well-defined. For example, the lower case of LATIN CAPITAL | |
7695 | LETTER SHARP S (U+1E9E) in Unicode rules is U+00DF (on ASCII | |
7696 | platforms). But under C<use locale> (prior to v5.20 or not a UTF-8 | |
7697 | locale), the lower case of U+1E9E is | |
7698 | itself, because 0xDF may not be LATIN SMALL LETTER SHARP S in the | |
7699 | current locale, and Perl has no way of knowing if that character even | |
7700 | exists in the locale, much less what code point it is. Perl returns | |
7701 | a result that is above 255 (almost always the input character unchanged), | |
7702 | for all instances (and there aren't many) where the 255/256 boundary | |
7703 | would otherwise be crossed; and starting in v5.22, it raises a | |
7704 | L<locale|perldiag/Can't do %s("%s") on non-UTF-8 locale; resolved to "%s".> warning. | |
6172 | 7705 | |
6173 | 7706 | =end original |
6174 | 7707 | |
6175 | ||
7708 | v5.20 から、ロケールが UTF-8 の場合は Perl は完全な Unicode の規則を使います。 | |
6176 | 大文字小文字 | |
7709 | さもなければ、この手法には、255/266 の境界をまたぐ大文字小文字の変換は | |
6177 | ||
7710 | 未定義であるという欠点があります。 | |
6178 | ||
7711 | 例えば、Unicode での LATIN CAPITAL LETTER SHARP S (U+1E9E) の小文字は | |
6179 | ||
7712 | (ASCII プラットフォームでは) U+00DF です。 | |
7713 | しかし C<use locale> が有効(v5.20 より前か、UTF-8 ロケール以外)なら、U+1E9E の | |
7714 | 小文字は自分自身です; なぜなら 0xDF は現在のロケールでは | |
7715 | LATIN SMALL LETTER SHARP S ではなく、Perl は例えこのロケールに文字が | |
7716 | 存在するかどうかを知る方法がなく、ましてどの符号位置かを知る方法が | |
7717 | ないからです。 | |
7718 | Perl は 255/256 境界をまたぐ全ての(多くはありません)実体については | |
7719 | (ほとんど常に入力文字を変更せずに)256 以上の値を返します; | |
7720 | そして v5.22 から | |
7721 | L<locale|perldiag/Can't do %s("%s") on non-UTF-8 locale; resolved to "%s".> | |
7722 | 警告を出力します。 | |
6180 | 7723 | |
6181 | =item Otherwise, | |
7724 | =item Otherwise, If EXPR has the UTF8 flag set: | |
6182 | 7725 | |
6183 | (そ | |
7726 | (その他の場合で、EXPR に UTF8 フラグがセットされている場合) | |
6184 | 7727 | |
6185 | 7728 | =begin original |
6186 | 7729 | |
6187 | ||
7730 | Unicode rules are used for the case change. | |
6188 | 7731 | |
6189 | 7732 | =end original |
6190 | 7733 | |
6191 | ||
7734 | 大文字小文字変換には Unicode の規則が使われます。 | |
6192 | L<perllocale> を参照してください。 | |
6193 | 7735 | |
6194 | =item Otherwise, if C<use feature 'unicode_strings'> is in effect: | |
7736 | =item Otherwise, if C<use feature 'unicode_strings'> or C<use locale ':not_characters'> is in effect: | |
6195 | 7737 | |
6196 | (それ以外の場合で、C<use feature 'unicode_strings'> が有効の場合) | |
7738 | (それ以外の場合で、C<use feature 'unicode_strings'> か C<use locale ':not_characters'> が有効の場合) | |
6197 | 7739 | |
6198 | 7740 | =begin original |
6199 | 7741 | |
6200 | Unicode | |
7742 | Unicode rules are used for the case change. | |
6201 | C<ToLower> will be ignored. | |
6202 | 7743 | |
6203 | 7744 | =end original |
6204 | 7745 | |
6205 | 大文字小文字変換には Unicode の | |
7746 | 大文字小文字変換には Unicode の規則が使われます。 | |
6206 | C<ToLower> という名前のサブルーチンは無視されます。 | |
6207 | 7747 | |
6208 | 7748 | =item Otherwise: |
6209 | 7749 | |
6210 | 7750 | (それ以外の場合) |
6211 | 7751 | |
6212 | =over | |
6213 | ||
6214 | =item On EBCDIC platforms | |
6215 | ||
6216 | 7752 | =begin original |
6217 | 7753 | |
6218 | ||
7754 | ASCII rules are used for the case change. The lowercase of any character | |
6219 | ||
6220 | =end original | |
6221 | ||
6222 | 結果は、C 言語のシステムコール C<tolower()> が返すものです。 | |
6223 | ||
6224 | =item On ASCII platforms | |
6225 | ||
6226 | =begin original | |
6227 | ||
6228 | ASCII semantics are used for the case change. The lowercase of any character | |
6229 | 7755 | outside the ASCII range is the character itself. |
6230 | 7756 | |
6231 | 7757 | =end original |
6232 | 7758 | |
6233 | 大文字小文字変換には ASCII の | |
7759 | 大文字小文字変換には ASCII の規則が使われます。 | |
6234 | 7760 | ASCII の範囲外の文字の「小文字」はその文字自身です。 |
6235 | 7761 | |
6236 | 7762 | =back |
6237 | 7763 | |
6238 | =back | |
6239 | ||
6240 | 7764 | =item lcfirst EXPR |
6241 | 7765 | X<lcfirst> X<lowercase> |
6242 | 7766 | |
6243 | 7767 | =item lcfirst |
6244 | 7768 | |
7769 | =for Pod::Functions return a string with just the next letter in lower case | |
7770 | ||
6245 | 7771 | =begin original |
6246 | 7772 | |
6247 | 7773 | Returns the value of EXPR with the first character lowercased. This |
6248 | 7774 | is the internal function implementing the C<\l> escape in |
6249 | 7775 | double-quoted strings. |
6250 | 7776 | |
6251 | 7777 | =end original |
6252 | 7778 | |
6253 | 7779 | 最初の文字だけを小文字にした、EXPR を返します。 |
6254 | 7780 | これは、ダブルクォート文字列における、C<\l> エスケープを |
6255 | 7781 | 実装する内部関数です。 |
6256 | 7782 | |
6257 | 7783 | =begin original |
6258 | 7784 | |
6259 | If EXPR is omitted, uses C<$_>. | |
7785 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. | |
6260 | 7786 | |
6261 | 7787 | =end original |
6262 | 7788 | |
6263 | EXPR が省略されると、C<$_> を使います。 | |
7789 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
6264 | 7790 | |
6265 | 7791 | =begin original |
6266 | 7792 | |
6267 | This function behaves the same way under various pragma | |
7793 | This function behaves the same way under various pragmas, such as in a locale, | |
6268 | as L</lc> does. | |
7794 | as L<C<lc>|/lc EXPR> does. | |
6269 | 7795 | |
6270 | 7796 | =end original |
6271 | 7797 | |
6272 | 7798 | この関数は、ロケールのようなさまざまなプラグマの影響下では、 |
6273 | L</lc> と同様に振る舞います。 | |
7799 | L<C<lc>|/lc EXPR> と同様に振る舞います。 | |
6274 | 7800 | |
6275 | 7801 | =item length EXPR |
6276 | 7802 | X<length> X<size> |
6277 | 7803 | |
6278 | 7804 | =item length |
6279 | 7805 | |
7806 | =for Pod::Functions return the number of characters in a string | |
7807 | ||
6280 | 7808 | =begin original |
6281 | 7809 | |
6282 | 7810 | Returns the length in I<characters> of the value of EXPR. If EXPR is |
6283 | omitted, returns the length of C<$_>. If EXPR i | |
7811 | omitted, returns the length of L<C<$_>|perlvar/$_>. If EXPR is | |
6284 | C<undef>. | |
7812 | undefined, returns L<C<undef>|/undef EXPR>. | |
6285 | 7813 | |
6286 | 7814 | =end original |
6287 | 7815 | |
6288 | 7816 | EXPR の値の I<文字> の長さを返します。 |
6289 | EXPR が省略されたときには、C<$_> の長さを返します。 | |
7817 | EXPR が省略されたときには、L<C<$_>|perlvar/$_> の長さを返します。 | |
6290 | EXPR が未定義値の場合、C<undef> を返します。 | |
7818 | EXPR が未定義値の場合、L<C<undef>|/undef EXPR> を返します。 | |
6291 | 7819 | |
6292 | 7820 | =begin original |
6293 | 7821 | |
6294 | 7822 | This function cannot be used on an entire array or hash to find out how |
6295 | 7823 | many elements these have. For that, use C<scalar @array> and C<scalar keys |
6296 | 7824 | %hash>, respectively. |
6297 | 7825 | |
6298 | 7826 | =end original |
6299 | 7827 | |
6300 | 7828 | この関数は配列やハッシュ全体に対してどれだけの要素を含んでいるかを |
6301 | 7829 | 調べるためには使えません。 |
6302 | 7830 | そのような用途には、それぞれ C<scalar @array> と C<scalar keys %hash> を |
6303 | 7831 | 利用してください。 |
6304 | 7832 | |
6305 | 7833 | =begin original |
6306 | 7834 | |
6307 | Like all Perl character operations, length | |
7835 | Like all Perl character operations, L<C<length>|/length EXPR> normally | |
7836 | deals in logical | |
6308 | 7837 | characters, not physical bytes. For how many bytes a string encoded as |
6309 | 7838 | UTF-8 would take up, use C<length(Encode::encode_utf8(EXPR))> (you'll have |
6310 | 7839 | to C<use Encode> first). See L<Encode> and L<perlunicode>. |
6311 | 7840 | |
6312 | 7841 | =end original |
6313 | 7842 | |
6314 | 全ての Perl の文字操作と同様、length | |
7843 | 全ての Perl の文字操作と同様、L<C<length>|/length EXPR> は通常物理的な | |
6315 | 論理文字を扱います。 | |
7844 | バイトではなく論理文字を扱います。 | |
6316 | 7845 | UTF-8 でエンコードされた文字列が何バイトかを知るには、 |
6317 | 7846 | C<length(Encode::encode_utf8(EXPR))> を使ってください (先に |
6318 | 7847 | C<use Encode> する必要があります)。 |
6319 | 7848 | L<Encode> と L<perlunicode> を参照してください。 |
6320 | 7849 | |
7850 | =item __LINE__ | |
7851 | X<__LINE__> | |
7852 | ||
7853 | =for Pod::Functions the current source line number | |
7854 | ||
7855 | =begin original | |
7856 | ||
7857 | A special token that compiles to the current line number. | |
7858 | ||
7859 | =end original | |
7860 | ||
7861 | 現在の行番号にコンパイルされる特殊トークン。 | |
7862 | ||
6321 | 7863 | =item link OLDFILE,NEWFILE |
6322 | 7864 | X<link> |
6323 | 7865 | |
7866 | =for Pod::Functions create a hard link in the filesystem | |
7867 | ||
6324 | 7868 | =begin original |
6325 | 7869 | |
6326 | 7870 | Creates a new filename linked to the old filename. Returns true for |
6327 | 7871 | success, false otherwise. |
6328 | 7872 | |
6329 | 7873 | =end original |
6330 | 7874 | |
6331 | 7875 | OLDFILE にリンクされた、新しいファイル NEWFILE を作ります。 |
6332 | 成功時には | |
7876 | 成功時には真を、さもなければ偽を返します。 | |
6333 | 7877 | |
7878 | =begin original | |
7879 | ||
7880 | Portability issues: L<perlport/link>. | |
7881 | ||
7882 | =end original | |
7883 | ||
7884 | 移植性の問題: L<perlport/link>。 | |
7885 | ||
6334 | 7886 | =item listen SOCKET,QUEUESIZE |
6335 | 7887 | X<listen> |
6336 | 7888 | |
7889 | =for Pod::Functions register your socket as a server | |
7890 | ||
6337 | 7891 | =begin original |
6338 | 7892 | |
6339 | Does the same thing that the listen(2) system call does. Returns true if | |
7893 | Does the same thing that the L<listen(2)> system call does. Returns true if | |
6340 | 7894 | it succeeded, false otherwise. See the example in |
6341 | 7895 | L<perlipc/"Sockets: Client/Server Communication">. |
6342 | 7896 | |
6343 | 7897 | =end original |
6344 | 7898 | |
6345 | listen(2) システムコールと同じことをします。 | |
7899 | L<listen(2)> システムコールと同じことをします。 | |
6346 | ||
7900 | 成功時には真を、さもなければ偽を返します。 | |
6347 | L<perlipc/"Sockets: Client/Server Communication">の例を参照してください。 | |
7901 | L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。 | |
6348 | 7902 | |
6349 | 7903 | =item local EXPR |
6350 | 7904 | X<local> |
6351 | 7905 | |
7906 | =for Pod::Functions create a temporary value for a global variable (dynamic scoping) | |
7907 | ||
6352 | 7908 | =begin original |
6353 | 7909 | |
6354 | You really probably want to be using C<my> instead, | |
7910 | You really probably want to be using L<C<my>|/my VARLIST> instead, | |
6355 | what most people think of as | |
7911 | because L<C<local>|/local EXPR> isn't what most people think of as | |
6356 | L<perlsub/"Private Variables via my()"> for details. | |
7912 | "local". See L<perlsub/"Private Variables via my()"> for details. | |
6357 | 7913 | |
6358 | 7914 | =end original |
6359 | 7915 | |
6360 | あなたはが本当に望んでいるのは C<my> の方でしょう | |
7916 | あなたはが本当に望んでいるのは L<C<my>|/my VARLIST> の方でしょう; | |
6361 | C<local> はほとんどの人々が「ローカル」と考えるものと | |
7917 | L<C<local>|/local EXPR> はほとんどの人々が「ローカル」と考えるものと | |
7918 | 違うからです。 | |
6362 | 7919 | 詳細は L<perlsub/"Private Variables via my()"> を参照してください。 |
6363 | 7920 | |
6364 | 7921 | =begin original |
6365 | 7922 | |
6366 | 7923 | A local modifies the listed variables to be local to the enclosing |
6367 | 7924 | block, file, or eval. If more than one value is listed, the list must |
6368 | 7925 | be placed in parentheses. See L<perlsub/"Temporary Values via local()"> |
6369 | 7926 | for details, including issues with tied arrays and hashes. |
6370 | 7927 | |
6371 | 7928 | =end original |
6372 | 7929 | |
6373 | 7930 | "local" はリストアップされた変数を、囲っているブロック、 |
6374 | 7931 | ファイル、eval の中で、ローカルなものにします。 |
6375 | 複数の値を指定する場合は、リストは | |
7932 | 複数の値を指定する場合は、リストはかっこでくくらなければなりません。 | |
6376 | 7933 | tie した配列とハッシュに関する事項を含む詳細については |
6377 | 7934 | L<perlsub/"Temporary Values via local()"> を参照してください。 |
6378 | 7935 | |
6379 | 7936 | =begin original |
6380 | 7937 | |
6381 | 7938 | The C<delete local EXPR> construct can also be used to localize the deletion |
6382 | 7939 | of array/hash elements to the current block. |
6383 | 7940 | See L<perlsub/"Localized deletion of elements of composite types">. |
6384 | 7941 | |
6385 | 7942 | =end original |
6386 | 7943 | |
6387 | 7944 | C<delete local EXPR> 構文は、配列/ハッシュの要素の削除を現在の |
6388 | 7945 | ブロックにローカル化するためにも使われていました。 |
6389 | 7946 | L<perlsub/"Localized deletion of elements of composite types"> を |
6390 | 7947 | 参照してください。 |
6391 | 7948 | |
6392 | 7949 | =item localtime EXPR |
6393 | 7950 | X<localtime> X<ctime> |
6394 | 7951 | |
6395 | 7952 | =item localtime |
6396 | 7953 | |
7954 | =for Pod::Functions convert UNIX time into record or string using local time | |
7955 | ||
6397 | 7956 | =begin original |
6398 | 7957 | |
6399 | 7958 | Converts a time as returned by the time function to a 9-element list |
6400 | 7959 | with the time analyzed for the local time zone. Typically used as |
6401 | 7960 | follows: |
6402 | 7961 | |
6403 | 7962 | =end original |
6404 | 7963 | |
6405 | 7964 | time 関数が返す時刻を、ローカルなタイムゾーンで測った時刻として、 |
6406 | 7965 | 9 要素の配列に変換します。 |
6407 | 通 | |
7966 | 普通は、以下のようにして使います: | |
6408 | 7967 | |
6409 | # 0 1 2 3 4 5 6 7 8 | |
7968 | # 0 1 2 3 4 5 6 7 8 | |
6410 | ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = | |
7969 | my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = | |
6411 | 7970 | localtime(time); |
6412 | 7971 | |
6413 | 7972 | =begin original |
6414 | 7973 | |
6415 | 7974 | All list elements are numeric and come straight out of the C `struct |
6416 | 7975 | tm'. C<$sec>, C<$min>, and C<$hour> are the seconds, minutes, and hours |
6417 | 7976 | of the specified time. |
6418 | 7977 | |
6419 | 7978 | =end original |
6420 | 7979 | |
6421 | 7980 | すべてのリスト要素は数値で、C の `struct tm' 構造体から |
6422 | 7981 | 直接持ってきます。 |
6423 | 7982 | C<$sec>, C<$min>, C<$hour> は指定された時刻の秒、分、時です。 |
6424 | 7983 | |
6425 | 7984 | =begin original |
6426 | 7985 | |
6427 | 7986 | C<$mday> is the day of the month and C<$mon> the month in |
6428 | 7987 | the range C<0..11>, with 0 indicating January and 11 indicating December. |
6429 | 7988 | This makes it easy to get a month name from a list: |
6430 | 7989 | |
6431 | 7990 | =end original |
6432 | 7991 | |
6433 | C<$mday> は月の何日目か、C<$mon> は月の値です | |
7992 | C<$mday> は月の何日目か、C<$mon> は月の値です; 月の値は C<0..11> で、0 が | |
6434 | ||
7993 | 1 月、11 が 12 月です。 | |
6435 | 7994 | これにより、リストから月の名前を得るのが簡単になります: |
6436 | 7995 | |
6437 | my @abbr = qw( | |
7996 | my @abbr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); | |
6438 | 7997 | print "$abbr[$mon] $mday"; |
6439 | 7998 | # $mon=9, $mday=18 gives "Oct 18" |
6440 | 7999 | |
6441 | 8000 | =begin original |
6442 | 8001 | |
6443 | C<$year> is the number of years since 1900 | |
8002 | C<$year> contains the number of years since 1900. To get a 4-digit | |
6444 | ||
8003 | year write: | |
6445 | to get a 4-digit year is simply: | |
6446 | 8004 | |
6447 | 8005 | =end original |
6448 | 8006 | |
6449 | C<$year> は 1900 年からの年数 | |
8007 | C<$year> は 1900 年からの年数を持ちます。 | |
6450 | ||
8008 | 4 桁の年を得るには以下のようにします: | |
6451 | つまり、$year が C<123> なら 2023 年です。 | |
6452 | 4 桁の西暦を得るには単に以下のようにしてください: | |
6453 | 8009 | |
6454 | 8010 | $year += 1900; |
6455 | 8011 | |
6456 | 8012 | =begin original |
6457 | 8013 | |
6458 | Otherwise you create non-Y2K-compliant programs--and you wouldn't want | |
6459 | to do that, would you? | |
6460 | ||
6461 | =end original | |
6462 | ||
6463 | さもなければ、Y2K 問題を含んだプログラムを作ることになります -- | |
6464 | それはお望みじゃないでしょう? | |
6465 | ||
6466 | =begin original | |
6467 | ||
6468 | 8014 | To get the last two digits of the year (e.g., "01" in 2001) do: |
6469 | 8015 | |
6470 | 8016 | =end original |
6471 | 8017 | |
6472 | 8018 | 西暦の下 2 桁(2001 年では "01")がほしい場合は以下のようにします: |
6473 | 8019 | |
6474 | 8020 | $year = sprintf("%02d", $year % 100); |
6475 | 8021 | |
6476 | 8022 | =begin original |
6477 | 8023 | |
6478 | 8024 | C<$wday> is the day of the week, with 0 indicating Sunday and 3 indicating |
6479 | 8025 | Wednesday. C<$yday> is the day of the year, in the range C<0..364> |
6480 | 8026 | (or C<0..365> in leap years.) |
6481 | 8027 | |
6482 | 8028 | =end original |
6483 | 8029 | |
6484 | 8030 | C<$wday> は曜日で、0 が日曜日、3 が水曜日です。 |
6485 | 8031 | C<$yday> はその年の何日目かで、C<0..364> の値を取ります |
6486 | (うるう年は C<0..365> です | |
8032 | (うるう年は C<0..365> です。) | |
6487 | 8033 | |
6488 | 8034 | =begin original |
6489 | 8035 | |
6490 | 8036 | C<$isdst> is true if the specified time occurs during Daylight Saving |
6491 | 8037 | Time, false otherwise. |
6492 | 8038 | |
6493 | 8039 | =end original |
6494 | 8040 | |
6495 | 8041 | C<$isdst> は指定された時刻が夏時間の場合は真、そうでなければ偽です。 |
6496 | 8042 | |
6497 | 8043 | =begin original |
6498 | 8044 | |
6499 | If EXPR is omitted, C<localtime | |
8045 | If EXPR is omitted, L<C<localtime>|/localtime EXPR> uses the current | |
6500 | by time | |
8046 | time (as returned by L<C<time>|/time>). | |
6501 | 8047 | |
6502 | 8048 | =end original |
6503 | 8049 | |
6504 | EXPR が省略されると、C<localtime | |
8050 | EXPR が省略されると、L<C<localtime>|/localtime EXPR> は | |
6505 | 現在時刻を使います。 | |
8051 | (L<C<time>|/time> によって返される) 現在時刻を使います。 | |
6506 | 8052 | |
6507 | 8053 | =begin original |
6508 | 8054 | |
6509 | In scalar context, C<localtime | |
8055 | In scalar context, L<C<localtime>|/localtime EXPR> returns the | |
8056 | L<ctime(3)> value: | |
6510 | 8057 | |
6511 | 8058 | =end original |
6512 | 8059 | |
6513 | スカラコンテキストでは、C<localtime | |
8060 | スカラコンテキストでは、L<C<localtime>|/localtime EXPR> は L<ctime(3)> の値を | |
8061 | 返します: | |
6514 | 8062 | |
6515 | $now_string = localtime; # e.g., "Thu Oct 13 04:54:34 1994" | |
8063 | my $now_string = localtime; # e.g., "Thu Oct 13 04:54:34 1994" | |
6516 | 8064 | |
6517 | 8065 | =begin original |
6518 | 8066 | |
6519 | This scalar value is B<not> locale-dependent but | |
8067 | The format of this scalar value is B<not> locale-dependent but built | |
6520 | instead of local time use | |
8068 | into Perl. For GMT instead of local time use the | |
6521 | C< | |
8069 | L<C<gmtime>|/gmtime EXPR> builtin. See also the | |
6522 | ||
8070 | L<C<Time::Local>|Time::Local> module (for converting seconds, minutes, | |
6523 | and | |
8071 | hours, and such back to the integer value returned by L<C<time>|/time>), | |
8072 | and the L<POSIX> module's L<C<strftime>|POSIX/C<strftime>> and | |
8073 | L<C<mktime>|POSIX/C<mktime>> functions. | |
6524 | 8074 | |
6525 | 8075 | =end original |
6526 | 8076 | |
6527 | スカラ値はロケール依存 B<ではなく>、Perl の組み込みの値です。 | |
8077 | このスカラ値の形式はロケール依存 B<ではなく>、Perl の組み込みの値です。 | |
6528 | ローカル時刻ではなく GMT がほしい場合は L</gmtime> 組み込み | |
8078 | ローカル時刻ではなく GMT がほしい場合は L<C<gmtime>|/gmtime EXPR> 組み込み | |
6529 | 使ってください。 | |
8079 | 関数を使ってください。 | |
6530 | また、(秒、分、時などの形から、time | |
8080 | また、(秒、分、時などの形から、L<C<time>|/time> が返す値である | |
6531 | 1970 年 1 月 1 日の真夜中からの秒数に変換する) | |
8081 | 1970 年 1 月 1 日の真夜中からの秒数に変換する) | |
6532 | 及び POSIX モジュールで提供される | |
8082 | L<C<Time::Local>|Time::Local> モジュール及び L<POSIX> モジュールで提供される | |
8083 | L<C<strftime>|POSIX/C<strftime>> と L<C<mktime>|POSIX/C<mktime>> 関数も | |
6533 | 8084 | 参照してください。 |
6534 | 8085 | |
6535 | 8086 | =begin original |
6536 | 8087 | |
6537 | 8088 | To get somewhat similar but locale-dependent date strings, set up your |
6538 | 8089 | locale environment variables appropriately (please see L<perllocale>) and |
6539 | 8090 | try for example: |
6540 | 8091 | |
6541 | 8092 | =end original |
6542 | 8093 | |
6543 | 8094 | 似たような、しかしロケール依存の日付文字列がほしい場合は、 |
6544 | 8095 | ロケール環境変数を適切に設定して(L<perllocale> を参照してください)、 |
6545 | 8096 | 以下の例を試してください: |
6546 | 8097 | |
6547 | 8098 | use POSIX qw(strftime); |
6548 | $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime; | |
8099 | my $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime; | |
6549 | 8100 | # or for GMT formatted appropriately for your locale: |
6550 | $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime; | |
8101 | my $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime; | |
6551 | 8102 | |
6552 | 8103 | =begin original |
6553 | 8104 | |
6554 | Note that | |
8105 | Note that C<%a> and C<%b>, the short forms of the day of the week | |
6555 | 8106 | and the month of the year, may not necessarily be three characters wide. |
6556 | 8107 | |
6557 | 8108 | =end original |
6558 | 8109 | |
6559 | 8110 | 曜日と月の短い表現である C<%a> と C<%b> は、3 文字とは限らないことに |
6560 | 8111 | 注意してください。 |
6561 | 8112 | |
6562 | 8113 | =begin original |
6563 | 8114 | |
6564 | See L<perlport/localtime> for portability concerns. | |
6565 | ||
6566 | =end original | |
6567 | ||
6568 | 移植性については L<perlport/localtime> を参照してください。 | |
6569 | ||
6570 | =begin original | |
6571 | ||
6572 | 8115 | The L<Time::gmtime> and L<Time::localtime> modules provide a convenient, |
6573 | by-name access mechanism to the gmtime | |
8116 | by-name access mechanism to the L<C<gmtime>|/gmtime EXPR> and | |
6574 | respectively. | |
8117 | L<C<localtime>|/localtime EXPR> functions, respectively. | |
6575 | 8118 | |
6576 | 8119 | =end original |
6577 | 8120 | |
6578 | 8121 | L<Time::gmtime> モジュールと L<Time::localtime> モジュールは、それぞれ |
6579 | gmtime | |
8122 | L<C<gmtime>|/gmtime EXPR> 関数と L<C<localtime>|/localtime EXPR> 関数に、 | |
6580 | 便利なモジュールです。 | |
8123 | 名前でアクセスする機構を提供する便利なモジュールです。 | |
6581 | 8124 | |
6582 | 8125 | =begin original |
6583 | 8126 | |
6584 | 8127 | For a comprehensive date and time representation look at the |
6585 | 8128 | L<DateTime> module on CPAN. |
6586 | 8129 | |
6587 | 8130 | =end original |
6588 | 8131 | |
6589 | 8132 | 包括的な日付と時刻の表現については、CPAN の L<DateTime> モジュールを |
6590 | 8133 | 参照してください。 |
6591 | 8134 | |
8135 | =begin original | |
8136 | ||
8137 | Portability issues: L<perlport/localtime>. | |
8138 | ||
8139 | =end original | |
8140 | ||
8141 | 移植性の問題: L<perlport/localtime>。 | |
8142 | ||
6592 | 8143 | =item lock THING |
6593 | 8144 | X<lock> |
6594 | 8145 | |
8146 | =for Pod::Functions +5.005 get a thread lock on a variable, subroutine, or method | |
8147 | ||
6595 | 8148 | =begin original |
6596 | 8149 | |
6597 | 8150 | This function places an advisory lock on a shared variable or referenced |
6598 | 8151 | object contained in I<THING> until the lock goes out of scope. |
6599 | 8152 | |
6600 | 8153 | =end original |
6601 | 8154 | |
6602 | 8155 | この関数は I<THING> が含む共有変数またはリファレンスされたオブジェクトに、 |
6603 | 8156 | スコープから出るまでアドバイサリロックを掛けます. |
6604 | 8157 | |
6605 | 8158 | =begin original |
6606 | 8159 | |
6607 | ||
8160 | The value returned is the scalar itself, if the argument is a scalar, or a | |
8161 | reference, if the argument is a hash, array or subroutine. | |
8162 | ||
8163 | =end original | |
8164 | ||
8165 | 返される値は、引数がスカラならそのスカラ自身、引数がハッシュ、配列、 | |
8166 | サブルーチンならリファレンスです。 | |
8167 | ||
8168 | =begin original | |
8169 | ||
8170 | L<C<lock>|/lock THING> is a "weak keyword"; this means that if you've | |
8171 | defined a function | |
6608 | 8172 | by this name (before any calls to it), that function will be called |
6609 | 8173 | instead. If you are not under C<use threads::shared> this does nothing. |
6610 | 8174 | See L<threads::shared>. |
6611 | 8175 | |
6612 | 8176 | =end original |
6613 | 8177 | |
6614 | lock | |
8178 | L<C<lock>|/lock THING> は「弱いキーワード」です; もしユーザーが(呼び出し前に) | |
6615 | 8179 | この名前で関数を定義すると、定義された関数の方が呼び出されます。 |
6616 | 8180 | C<use threads::shared> の影響下でない場合は、これは何もしません。 |
6617 | 8181 | L<threads::shared> を参照してください。 |
6618 | 8182 | |
6619 | 8183 | =item log EXPR |
6620 | 8184 | X<log> X<logarithm> X<e> X<ln> X<base> |
6621 | 8185 | |
6622 | 8186 | =item log |
6623 | 8187 | |
8188 | =for Pod::Functions retrieve the natural logarithm for a number | |
8189 | ||
6624 | 8190 | =begin original |
6625 | 8191 | |
6626 | 8192 | Returns the natural logarithm (base I<e>) of EXPR. If EXPR is omitted, |
6627 | returns the log of C<$_>. To get the | |
8193 | returns the log of L<C<$_>|perlvar/$_>. To get the | |
6628 | 8194 | log of another base, use basic algebra: |
6629 | 8195 | The base-N log of a number is equal to the natural log of that number |
6630 | 8196 | divided by the natural log of N. For example: |
6631 | 8197 | |
6632 | 8198 | =end original |
6633 | 8199 | |
6634 | 8200 | EXPR の (I<e> を底とする) 自然対数を返します。 |
6635 | EXPR が省略されると、C<$_> の対数を返します。 | |
8201 | EXPR が省略されると、L<C<$_>|perlvar/$_> の対数を返します。 | |
6636 | 8202 | 底の異なる対数を求めるためには、基礎代数を利用してください: |
6637 | 8203 | ある数の N を底とする対数は、その数の自然対数を N の自然対数で割ったものです。 |
6638 | 例: | |
8204 | 例えば: | |
6639 | 8205 | |
6640 | 8206 | sub log10 { |
6641 | 8207 | my $n = shift; |
6642 | 8208 | return log($n)/log(10); |
6643 | 8209 | } |
6644 | 8210 | |
6645 | 8211 | =begin original |
6646 | 8212 | |
6647 | See also L</exp> for the inverse operation. | |
8213 | See also L<C<exp>|/exp EXPR> for the inverse operation. | |
6648 | 8214 | |
6649 | 8215 | =end original |
6650 | 8216 | |
6651 | 逆操作については L</exp> を参照して | |
8217 | 逆操作については L<C<exp>|/exp EXPR> を参照してください。 | |
6652 | 8218 | |
6653 | =item lstat E | |
8219 | =item lstat FILEHANDLE | |
6654 | 8220 | X<lstat> |
6655 | 8221 | |
8222 | =item lstat EXPR | |
8223 | ||
8224 | =item lstat DIRHANDLE | |
8225 | ||
6656 | 8226 | =item lstat |
6657 | 8227 | |
8228 | =for Pod::Functions stat a symbolic link | |
8229 | ||
6658 | 8230 | =begin original |
6659 | 8231 | |
6660 | Does the same thing as the C<stat> function | |
8232 | Does the same thing as the L<C<stat>|/stat FILEHANDLE> function | |
6661 | special C<_> filehandle) but stats a symbolic | |
8233 | (including setting the special C<_> filehandle) but stats a symbolic | |
6662 | the symbolic link points to. If symbolic links | |
8234 | link instead of the file the symbolic link points to. If symbolic links | |
6663 | your system, a normal C<stat> | |
8235 | are unimplemented on your system, a normal L<C<stat>|/stat FILEHANDLE> | |
6664 | information, please see the | |
8236 | is done. For much more detailed information, please see the | |
8237 | documentation for L<C<stat>|/stat FILEHANDLE>. | |
6665 | 8238 | |
6666 | 8239 | =end original |
6667 | 8240 | |
6668 | 8241 | (特別なファイルハンドルである C<_> の設定を含めて) |
6669 | C<stat> 関数と同じことをしますが、シンボリックリンクが | |
8242 | L<C<stat>|/stat FILEHANDLE> 関数と同じことをしますが、シンボリックリンクが | |
6670 | 8243 | 指しているファイルではなく、シンボリックリンク自体の stat をとります。 |
6671 | シンボリックリンクがシステムに実装されていないと、通常の | |
8244 | シンボリックリンクがシステムに実装されていないと、通常の | |
6672 | ||
8245 | L<C<stat>|/stat FILEHANDLE> が行なわれます。 | |
8246 | さらにより詳細な情報については、L<C<stat>|/stat FILEHANDLE> の文書を | |
8247 | 参照してください。 | |
6673 | 8248 | |
6674 | 8249 | =begin original |
6675 | 8250 | |
6676 | If EXPR is omitted, stats C<$_>. | |
8251 | If EXPR is omitted, stats L<C<$_>|perlvar/$_>. | |
6677 | 8252 | |
6678 | 8253 | =end original |
6679 | 8254 | |
6680 | EXPR が省略されると、C<$_> の stat をとります。 | |
8255 | EXPR が省略されると、L<C<$_>|perlvar/$_> の stat をとります。 | |
6681 | 8256 | |
8257 | =begin original | |
8258 | ||
8259 | Portability issues: L<perlport/lstat>. | |
8260 | ||
8261 | =end original | |
8262 | ||
8263 | 移植性の問題: L<perlport/lstat>。 | |
8264 | ||
6682 | 8265 | =item m// |
6683 | 8266 | |
8267 | =for Pod::Functions match a string with a regular expression pattern | |
8268 | ||
6684 | 8269 | =begin original |
6685 | 8270 | |
6686 | 8271 | The match operator. See L<perlop/"Regexp Quote-Like Operators">. |
6687 | 8272 | |
6688 | 8273 | =end original |
6689 | 8274 | |
6690 | 8275 | マッチ演算子です。 |
6691 | 8276 | L<perlop/"Regexp Quote-Like Operators"> を参照してください。 |
6692 | 8277 | |
6693 | 8278 | =item map BLOCK LIST |
6694 | 8279 | X<map> |
6695 | 8280 | |
6696 | 8281 | =item map EXPR,LIST |
6697 | 8282 | |
8283 | =for Pod::Functions apply a change to a list to get back a new list with the changes | |
8284 | ||
6698 | 8285 | =begin original |
6699 | 8286 | |
6700 | 8287 | Evaluates the BLOCK or EXPR for each element of LIST (locally setting |
6701 | C<$_> to each element) and returns the list value composed | |
8288 | L<C<$_>|perlvar/$_> to each element) and returns the list value composed | |
8289 | of the | |
6702 | 8290 | results of each such evaluation. In scalar context, returns the |
6703 | 8291 | total number of elements so generated. Evaluates BLOCK or EXPR in |
6704 | 8292 | list context, so each element of LIST may produce zero, one, or |
6705 | 8293 | more elements in the returned value. |
6706 | 8294 | |
6707 | 8295 | =end original |
6708 | 8296 | |
6709 | 8297 | LIST の個々の要素に対して、BLOCK か EXPR を評価し |
6710 | (C<$_> は、ローカルに個々の要素が設定されます) 、 | |
8298 | (L<C<$_>|perlvar/$_> は、ローカルに個々の要素が設定されます) 、 | |
6711 | 8299 | それぞれの評価結果からなるリスト値が返されます。 |
6712 | 8300 | スカラコンテキストでは、生成された要素の数を返します。 |
6713 | 8301 | BLOCK や EXPR をリストコンテキストで評価しますので、LIST の |
6714 | 8302 | 個々の要素によって作られる、返り値であるリストの要素数は、 |
6715 | 8303 | 0 個の場合もあれば、複数の場合もあります。 |
6716 | 8304 | |
6717 | @chars = map(chr, @numbers); | |
8305 | my @chars = map(chr, @numbers); | |
6718 | 8306 | |
6719 | 8307 | =begin original |
6720 | 8308 | |
6721 | 8309 | translates a list of numbers to the corresponding characters. |
6722 | 8310 | |
6723 | 8311 | =end original |
6724 | 8312 | |
6725 | 8313 | は、数のリストを対応する文字に変換します。 |
6726 | 8314 | |
6727 | 8315 | my @squares = map { $_ * $_ } @numbers; |
6728 | 8316 | |
6729 | 8317 | =begin original |
6730 | 8318 | |
6731 | 8319 | translates a list of numbers to their squared values. |
6732 | 8320 | |
6733 | 8321 | =end original |
6734 | 8322 | |
6735 | 8323 | これは数値のリストを、その 2 乗に変換します。 |
6736 | 8324 | |
6737 | 8325 | my @squares = map { $_ > 5 ? ($_ * $_) : () } @numbers; |
6738 | 8326 | |
6739 | 8327 | =begin original |
6740 | 8328 | |
6741 | 8329 | shows that number of returned elements can differ from the number of |
6742 | input elements. To omit an element, return an empty list (). | |
8330 | input elements. To omit an element, return an empty list (). | |
6743 | 8331 | This could also be achieved by writing |
6744 | 8332 | |
6745 | 8333 | =end original |
6746 | 8334 | |
6747 | 8335 | のように、返された要素の数が入力要素の数と異なる場合もあります。 |
6748 | 8336 | 要素を省略するには、空リスト () を返します。 |
6749 | 8337 | これは以下のように書くことでも達成できて |
6750 | 8338 | |
6751 | 8339 | my @squares = map { $_ * $_ } grep { $_ > 5 } @numbers; |
6752 | 8340 | |
6753 | 8341 | =begin original |
6754 | 8342 | |
6755 | 8343 | which makes the intention more clear. |
6756 | 8344 | |
6757 | 8345 | =end original |
6758 | 8346 | |
6759 | 8347 | この方が目的がよりはっきりします。 |
6760 | 8348 | |
6761 | 8349 | =begin original |
6762 | 8350 | |
6763 | 8351 | Map always returns a list, which can be |
6764 | 8352 | assigned to a hash such that the elements |
6765 | become key/value pairs. See L<perldata> for more details. | |
8353 | become key/value pairs. See L<perldata> for more details. | |
6766 | 8354 | |
6767 | 8355 | =end original |
6768 | 8356 | |
6769 | 8357 | map は常にリストを返し、要素がキー/値の組になるようなハッシュに |
6770 | 8358 | 代入できます。 |
6771 | 8359 | さらなる詳細については L<perldata> を参照してください。 |
6772 | 8360 | |
6773 | %hash = map { get_a_key_for($_) => $_ } @array; | |
8361 | my %hash = map { get_a_key_for($_) => $_ } @array; | |
6774 | 8362 | |
6775 | 8363 | =begin original |
6776 | 8364 | |
6777 | 8365 | is just a funny way to write |
6778 | 8366 | |
6779 | 8367 | =end original |
6780 | 8368 | |
6781 | 8369 | は以下のものをちょっと変わった書き方で書いたものです。 |
6782 | 8370 | |
6783 | %hash | |
8371 | my %hash; | |
6784 | 8372 | foreach (@array) { |
6785 | 8373 | $hash{get_a_key_for($_)} = $_; |
6786 | 8374 | } |
6787 | 8375 | |
6788 | 8376 | =begin original |
6789 | 8377 | |
6790 | Note that C<$_> is an alias to the list value, so it can | |
8378 | Note that L<C<$_>|perlvar/$_> is an alias to the list value, so it can | |
6791 | modify the elements of the LIST. While this is useful and | |
8379 | be used to modify the elements of the LIST. While this is useful and | |
6792 | it can cause bizarre results if the elements of LIST are not | |
8380 | supported, it can cause bizarre results if the elements of LIST are not | |
6793 | Using a regular C<foreach> loop for this purpose would be | |
8381 | variables. Using a regular C<foreach> loop for this purpose would be | |
6794 | most cases. See also L</grep> for an | |
8382 | clearer in most cases. See also L<C<grep>|/grep BLOCK LIST> for an | |
6795 | the original list for which the BLOCK | |
8383 | array composed of those items of the original list for which the BLOCK | |
8384 | or EXPR evaluates to true. | |
6796 | 8385 | |
6797 | 8386 | =end original |
6798 | 8387 | |
6799 | C<$_> は、LIST の値へのエイリアスですので、LIST の要素を | |
8388 | L<C<$_>|perlvar/$_> は、LIST の値へのエイリアスですので、LIST の要素を | |
6800 | 8389 | 変更するために使うことができます。 |
6801 | 8390 | これは、便利でサポートされていますが、 |
6802 | 8391 | LIST の要素が変数でないと、おかしな結果になります。 |
6803 | 8392 | この目的には通常の C<foreach> ループを使うことで、ほとんどの場合は |
6804 | 8393 | より明確になります。 |
6805 | 8394 | BLOCK や EXPR が真になる元のリストの要素からなる配列については、 |
6806 | L</grep> も参照してください。 | |
8395 | L<C<grep>|/grep BLOCK LIST> も参照してください。 | |
6807 | 8396 | |
6808 | 8397 | =begin original |
6809 | 8398 | |
6810 | If C<$_> is lexical in the scope where the C<map> appears (because it has | |
6811 | been declared with C<my $_>), then, in addition to being locally aliased to | |
6812 | the list elements, C<$_> keeps being lexical inside the block; that is, it | |
6813 | can't be seen from the outside, avoiding any potential side-effects. | |
6814 | ||
6815 | =end original | |
6816 | ||
6817 | (C<my $_> として宣言されることによって) C<$_> が C<map> が現れるスコープ内で | |
6818 | レキシカルな場合は、ローカルではリスト要素へのエイリアスであることに加えて、 | |
6819 | C<$_> はブロック内でレキシカルでありつづけます; つまり、外側からは見えず、 | |
6820 | 起こりうる副作用を回避します。 | |
6821 | ||
6822 | =begin original | |
6823 | ||
6824 | 8399 | C<{> starts both hash references and blocks, so C<map { ...> could be either |
6825 | the start of map BLOCK LIST or map EXPR, LIST. Because Perl doesn't look | |
8400 | the start of map BLOCK LIST or map EXPR, LIST. Because Perl doesn't look | |
6826 | 8401 | ahead for the closing C<}> it has to take a guess at which it's dealing with |
6827 | based on what it finds just after the | |
8402 | based on what it finds just after the | |
8403 | C<{>. Usually it gets it right, but if it | |
6828 | 8404 | doesn't it won't realize something is wrong until it gets to the C<}> and |
6829 | encounters the missing (or unexpected) comma. The syntax error will be | |
8405 | encounters the missing (or unexpected) comma. The syntax error will be | |
6830 | 8406 | reported close to the C<}>, but you'll need to change something near the C<{> |
6831 | such as using a unary C<+> to give Perl some help: | |
8407 | such as using a unary C<+> or semicolon to give Perl some help: | |
6832 | 8408 | |
6833 | 8409 | =end original |
6834 | 8410 | |
6835 | 8411 | C<{> はハッシュリファレンスとブロックの両方の開始文字なので、 |
6836 | 8412 | C<map { ...> は map BLOCK LIST の場合と map EXPR, LIST の場合があります。 |
6837 | 8413 | Perl は終了文字の C<}> を先読みしないので、C<{> の直後の文字を見て |
6838 | 8414 | どちらとして扱うかを推測します。 |
6839 | 8415 | 通常この推測は正しいですが、もし間違った場合は、C<}> まで読み込んで |
6840 | 8416 | カンマが足りない(または多い)ことがわかるまで、何かがおかしいことに |
6841 | 8417 | 気付きません。 |
6842 | C<}> の近くで文法エラーが出ますが、Perl を助けるために単項の C<+> | |
8418 | C<}> の近くで文法エラーが出ますが、Perl を助けるために単項の C<+> や | |
6843 | 使うというように、C<{> の近くの何かを変更する必要があります。 | |
8419 | セミコロンを使うというように、C<{> の近くの何かを変更する必要があります。 | |
6844 | 8420 | |
6845 | | |
8421 | my %hash = map { "\L$_" => 1 } @array # perl guesses EXPR. wrong | |
6846 | | |
8422 | my %hash = map { +"\L$_" => 1 } @array # perl guesses BLOCK. right | |
6847 | | |
8423 | my %hash = map {; "\L$_" => 1 } @array # this also works | |
6848 | | |
8424 | my %hash = map { ("\L$_" => 1) } @array # as does this | |
6849 | | |
8425 | my %hash = map { lc($_) => 1 } @array # and this. | |
8426 | my %hash = map +( lc($_) => 1 ), @array # this is EXPR and works! | |
6850 | 8427 | |
6851 | | |
8428 | my %hash = map ( lc($_), 1 ), @array # evaluates to (1, @array) | |
6852 | 8429 | |
6853 | 8430 | =begin original |
6854 | 8431 | |
6855 | 8432 | or to force an anon hash constructor use C<+{>: |
6856 | 8433 | |
6857 | 8434 | =end original |
6858 | 8435 | |
6859 | 8436 | または C<+{> を使って無名ハッシュコンストラクタを強制します: |
6860 | 8437 | |
6861 | @hashes = map +{ lc($_) => 1 }, @array # EXPR, so needs | |
8438 | my @hashes = map +{ lc($_) => 1 }, @array # EXPR, so needs | |
8439 | # comma at end | |
6862 | 8440 | |
6863 | 8441 | =begin original |
6864 | 8442 | |
6865 | 8443 | to get a list of anonymous hashes each with only one entry apiece. |
6866 | 8444 | |
6867 | 8445 | =end original |
6868 | 8446 | |
6869 | 8447 | こうするとそれぞれ 1 要素だけの無名ハッシュのリストを得られます。 |
6870 | 8448 | |
6871 | 8449 | =item mkdir FILENAME,MASK |
6872 | 8450 | X<mkdir> X<md> X<directory, create> |
6873 | 8451 | |
6874 | 8452 | =item mkdir FILENAME |
6875 | 8453 | |
6876 | 8454 | =item mkdir |
6877 | 8455 | |
8456 | =for Pod::Functions create a directory | |
8457 | ||
6878 | 8458 | =begin original |
6879 | 8459 | |
6880 | 8460 | Creates the directory specified by FILENAME, with permissions |
6881 | specified by MASK (as modified by C<umask>). If | |
8461 | specified by MASK (as modified by L<C<umask>|/umask EXPR>). If it | |
6882 | returns true; otherwise it returns false and sets | |
8462 | succeeds it returns true; otherwise it returns false and sets | |
8463 | L<C<$!>|perlvar/$!> (errno). | |
6883 | 8464 | MASK defaults to 0777 if omitted, and FILENAME defaults |
6884 | to C<$_> if omitted. | |
8465 | to L<C<$_>|perlvar/$_> if omitted. | |
6885 | 8466 | |
6886 | 8467 | =end original |
6887 | 8468 | |
6888 | 8469 | FILENAME で指定したディレクトリを、MASK で指定した許可モード(を |
6889 | C<umask> で修正したもの) で作成します。 | |
8470 | L<C<umask>|/umask EXPR> で修正したもの) で作成します。 | |
6890 | 成功時には真を返します; | |
8471 | 成功時には真を返します; さもなければ偽を返して | |
8472 | L<C<$!>|perlvar/$!> (errno) を設定します。 | |
6891 | 8473 | MASK を省略すると、0777 とみなし、 |
6892 | FILENAME を省略すると、C<$_> を使います。 | |
8474 | FILENAME を省略すると、L<C<$_>|perlvar/$_> を使います。 | |
6893 | 8475 | |
6894 | 8476 | =begin original |
6895 | 8477 | |
6896 | 8478 | In general, it is better to create directories with a permissive MASK |
6897 | and let the user modify that with their C<umask> than it | |
8479 | and let the user modify that with their L<C<umask>|/umask EXPR> than it | |
8480 | is to supply | |
6898 | 8481 | a restrictive MASK and give the user no way to be more permissive. |
6899 | 8482 | The exceptions to this rule are when the file or directory should be |
6900 | kept private (mail files, for instance). The | |
8483 | kept private (mail files, for instance). The documentation for | |
6901 | C<umask> discusses the choice of MASK in more detail. | |
8484 | L<C<umask>|/umask EXPR> discusses the choice of MASK in more detail. | |
6902 | 8485 | |
6903 | 8486 | =end original |
6904 | 8487 | |
6905 | 8488 | 一般的に、制限された MASK を使ってユーザーがより寛容にする方法を |
6906 | 与えないより、寛容な MASK でディレクトリを作り、ユーザーが自身の | |
8489 | 与えないより、寛容な MASK でディレクトリを作り、ユーザーが自身の | |
6907 | 修正するようにした方がよいです。 | |
8490 | L<C<umask>|/umask EXPR> で修正するようにした方がよいです。 | |
6908 | 8491 | 例外は、(例えばメールファイルのような)プライベートに保つべきファイルや |
6909 | 8492 | ディレクトリを書く場合です。 |
6910 | ||
8493 | L<C<umask>|/umask EXPR> の文書で、MASK の選択に関して詳細に議論しています。 | |
6911 | 8494 | |
6912 | 8495 | =begin original |
6913 | 8496 | |
6914 | 8497 | Note that according to the POSIX 1003.1-1996 the FILENAME may have any |
6915 | 8498 | number of trailing slashes. Some operating and filesystems do not get |
6916 | 8499 | this right, so Perl automatically removes all trailing slashes to keep |
6917 | 8500 | everyone happy. |
6918 | 8501 | |
6919 | 8502 | =end original |
6920 | 8503 | |
6921 | 8504 | POSIX 1003.1-1996 によれば、FILENAME には末尾に任意の数のスラッシュを |
6922 | 8505 | つけることができます。 |
6923 | 8506 | このようには動かない OS やファイルシステムもあるので、Perl はみんなが |
6924 | 8507 | 幸せになれるように、自動的に末尾のスラッシュを削除します。 |
6925 | 8508 | |
6926 | 8509 | =begin original |
6927 | 8510 | |
6928 | 8511 | To recursively create a directory structure, look at |
6929 | the C<mkpath> | |
8512 | the L<C<make_path>|File::Path/make_path( $dir1, $dir2, .... )> function | |
8513 | of the L<File::Path> module. | |
6930 | 8514 | |
6931 | 8515 | =end original |
6932 | 8516 | |
6933 | 8517 | ディレクトリ構造を再帰的に作成するには、L<File::Path> モジュールの |
6934 | C<makepath> 関数を | |
8518 | L<C<make_path>|File::Path/make_path( $dir1, $dir2, .... )> 関数を | |
8519 | 参照してください。 | |
6935 | 8520 | |
6936 | 8521 | =item msgctl ID,CMD,ARG |
6937 | 8522 | X<msgctl> |
6938 | 8523 | |
8524 | =for Pod::Functions SysV IPC message control operations | |
8525 | ||
6939 | 8526 | =begin original |
6940 | 8527 | |
6941 | Calls the System V IPC function msgctl(2). You'll probably have to say | |
8528 | Calls the System V IPC function L<msgctl(2)>. You'll probably have to say | |
6942 | 8529 | |
6943 | 8530 | =end original |
6944 | 8531 | |
6945 | System V IPC 関数 msgctl を呼び出します。 | |
8532 | System V IPC 関数 L<msgctl(2)> を呼び出します。 | |
8533 | 正しい定数定義を得るために、まず | |
6946 | 8534 | |
6947 | 8535 | use IPC::SysV; |
6948 | 8536 | |
6949 | 8537 | =begin original |
6950 | 8538 | |
6951 | 8539 | first to get the correct constant definitions. If CMD is C<IPC_STAT>, |
6952 | 8540 | then ARG must be a variable that will hold the returned C<msqid_ds> |
6953 | structure. Returns like C<ioctl> | |
8541 | structure. Returns like L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>: | |
6954 | C<"0 but true"> for zero, or the actual | |
8542 | the undefined value for error, C<"0 but true"> for zero, or the actual | |
6955 | L<perlipc/"SysV IPC"> and the | |
8543 | return value otherwise. See also L<perlipc/"SysV IPC"> and the | |
6956 | C<IPC::S | |
8544 | documentation for L<C<IPC::SysV>|IPC::SysV> and | |
8545 | L<C<IPC::Semaphore>|IPC::Semaphore>. | |
6957 | 8546 | |
6958 | 8547 | =end original |
6959 | 8548 | |
6960 | と | |
8549 | と書くことが必要でしょう。 | |
6961 | 8550 | CMD が C<IPC_STAT> であれば、ARG は返される C<msqid_ds> 構造体を |
6962 | 8551 | 納める変数でなければなりません。 |
6963 | C<ioctl> と同じように、エラー時には | |
8552 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同じように、エラー時には | |
6964 | ゼロのときは C<"0 but true">、それ以外なら、その値そのものを | |
8553 | 未定義値、ゼロのときは C<"0 but true">、それ以外なら、その値そのものを | |
6965 | ||
8554 | 返します。 | |
6966 | ||
8555 | L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>, | |
8556 | L<C<IPC::Semaphore>|IPC::Semaphore> の文書も参照してください。 | |
6967 | 8557 | |
8558 | =begin original | |
8559 | ||
8560 | Portability issues: L<perlport/msgctl>. | |
8561 | ||
8562 | =end original | |
8563 | ||
8564 | 移植性の問題: L<perlport/msgctl>。 | |
8565 | ||
6968 | 8566 | =item msgget KEY,FLAGS |
6969 | 8567 | X<msgget> |
6970 | 8568 | |
8569 | =for Pod::Functions get SysV IPC message queue | |
8570 | ||
6971 | 8571 | =begin original |
6972 | 8572 | |
6973 | Calls the System V IPC function msgget(2). Returns the message queue | |
8573 | Calls the System V IPC function L<msgget(2)>. Returns the message queue | |
6974 | id, or C<undef> on error. See also | |
8574 | id, or L<C<undef>|/undef EXPR> on error. See also L<perlipc/"SysV IPC"> | |
6975 | ||
8575 | and the documentation for L<C<IPC::SysV>|IPC::SysV> and | |
6976 | C<IPC::Msg>. | |
8576 | L<C<IPC::Msg>|IPC::Msg>. | |
6977 | 8577 | |
6978 | 8578 | =end original |
6979 | 8579 | |
6980 | System V IPC 関数 msgget を呼び出します。 | |
8580 | System V IPC 関数 L<msgget(2)> を呼び出します。 | |
6981 | メッセージキューの ID か、エラー時には C<undef> を返します。 | |
8581 | メッセージキューの ID か、エラー時には L<C<undef>|/undef EXPR> を返します。 | |
6982 | L<perlipc/"SysV IPC"> よ | |
8582 | L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>, | |
6983 | 参照してください。 | |
8583 | L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。 | |
6984 | 8584 | |
8585 | =begin original | |
8586 | ||
8587 | Portability issues: L<perlport/msgget>. | |
8588 | ||
8589 | =end original | |
8590 | ||
8591 | 移植性の問題: L<perlport/msgget>。 | |
8592 | ||
6985 | 8593 | =item msgrcv ID,VAR,SIZE,TYPE,FLAGS |
6986 | 8594 | X<msgrcv> |
6987 | 8595 | |
8596 | =for Pod::Functions receive a SysV IPC message from a message queue | |
8597 | ||
6988 | 8598 | =begin original |
6989 | 8599 | |
6990 | 8600 | Calls the System V IPC function msgrcv to receive a message from |
6991 | 8601 | message queue ID into variable VAR with a maximum message size of |
6992 | 8602 | SIZE. Note that when a message is received, the message type as a |
6993 | 8603 | native long integer will be the first thing in VAR, followed by the |
6994 | 8604 | actual message. This packing may be opened with C<unpack("l! a*")>. |
6995 | Taints the variable. Returns true if successful, false | |
8605 | Taints the variable. Returns true if successful, false | |
6996 | 8606 | on error. See also L<perlipc/"SysV IPC"> and the documentation for |
6997 | C<IPC::SysV> and C<IPC:: | |
8607 | L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Msg>|IPC::Msg>. | |
6998 | 8608 | |
6999 | 8609 | =end original |
7000 | 8610 | |
7001 | 8611 | System V IPC 関数 msgrcv を呼び出し、メッセージキュー ID から、 |
7002 | 8612 | 変数 VAR に最大メッセージ長 SIZE のメッセージを受信します。 |
7003 | 8613 | メッセージが受信された時、ネイティブな long 整数のメッセージタイプが |
7004 | 8614 | VAR の先頭となり、実際のメッセージが続きます。 |
7005 | 8615 | このパッキングは C<unpack("l! a*")> で展開できます。 |
7006 | 8616 | 変数は汚染されます。 |
7007 | 成功時には真を | |
8617 | 成功時には真を、エラー時には偽を返します。 | |
7008 | L<perlipc/"SysV IPC"> および、C<IPC::SysV> | |
8618 | L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>, | |
7009 | 参照してください。 | |
8619 | L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。 | |
7010 | 8620 | |
8621 | =begin original | |
8622 | ||
8623 | Portability issues: L<perlport/msgrcv>. | |
8624 | ||
8625 | =end original | |
8626 | ||
8627 | 移植性の問題: L<perlport/msgrcv>。 | |
8628 | ||
7011 | 8629 | =item msgsnd ID,MSG,FLAGS |
7012 | 8630 | X<msgsnd> |
7013 | 8631 | |
8632 | =for Pod::Functions send a SysV IPC message to a message queue | |
8633 | ||
7014 | 8634 | =begin original |
7015 | 8635 | |
7016 | 8636 | Calls the System V IPC function msgsnd to send the message MSG to the |
7017 | 8637 | message queue ID. MSG must begin with the native long integer message |
7018 | 8638 | type, be followed by the length of the actual message, and then finally |
7019 | 8639 | the message itself. This kind of packing can be achieved with |
7020 | 8640 | C<pack("l! a*", $type, $message)>. Returns true if successful, |
7021 | false on error. See also | |
8641 | false on error. See also L<perlipc/"SysV IPC"> and the documentation | |
7022 | ||
8642 | for L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Msg>|IPC::Msg>. | |
7023 | 8643 | |
7024 | 8644 | =end original |
7025 | 8645 | |
7026 | 8646 | System V IPC 関数 msgsnd を呼び出し、メッセージキュー ID に |
7027 | 8647 | メッセージ MSG を送信します。 |
7028 | MSG の先頭は、ネイティブなlong 整数のメッセージタイプでなければならず、 | |
8648 | MSG の先頭は、ネイティブな long 整数のメッセージタイプでなければならず、 | |
7029 | 8649 | メッセージの長さ、メッセージ本体と続きます。 |
7030 | 8650 | これは、C<pack("l! a*", $type, $message)> として生成できます。 |
7031 | 8651 | 成功時には真を、エラー時には偽を返します。 |
7032 | ||
8652 | L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>, | |
8653 | L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。 | |
7033 | 8654 | |
7034 | = | |
8655 | =begin original | |
8656 | ||
8657 | Portability issues: L<perlport/msgsnd>. | |
8658 | ||
8659 | =end original | |
8660 | ||
8661 | 移植性の問題: L<perlport/msgsnd>。 | |
8662 | ||
8663 | =item my VARLIST | |
7035 | 8664 | X<my> |
7036 | 8665 | |
7037 | =item my TYPE | |
8666 | =item my TYPE VARLIST | |
7038 | 8667 | |
7039 | =item my | |
8668 | =item my VARLIST : ATTRS | |
7040 | 8669 | |
7041 | =item my TYPE | |
8670 | =item my TYPE VARLIST : ATTRS | |
7042 | 8671 | |
8672 | =for Pod::Functions declare and assign a local variable (lexical scoping) | |
8673 | ||
7043 | 8674 | =begin original |
7044 | 8675 | |
7045 | A C<my> declares the listed variables to be local | |
8676 | A L<C<my>|/my VARLIST> declares the listed variables to be local | |
7046 | enclosing block, file, or C<eval> | |
8677 | (lexically) to the enclosing block, file, or L<C<eval>|/eval EXPR>. If | |
7047 | the list must be placed in | |
8678 | more than one variable is listed, the list must be placed in | |
8679 | parentheses. | |
7048 | 8680 | |
7049 | 8681 | =end original |
7050 | 8682 | |
7051 | C<my> はリストアップされた変数を、囲っているブロック、ファイル、 | |
8683 | L<C<my>|/my VARLIST> はリストアップされた変数を、囲っているブロック、ファイル、 | |
7052 | C<eval> の中でローカルな (レキシカルな) ものにします。 | |
8684 | L<C<eval>|/eval EXPR> の中でローカルな (レキシカルな) ものにします。 | |
7053 | 複数の | |
8685 | 複数の変数を指定する場合は、リストはかっこでくくらなければなりません。 | |
7054 | 8686 | |
7055 | 8687 | =begin original |
7056 | 8688 | |
7057 | 8689 | The exact semantics and interface of TYPE and ATTRS are still |
7058 | evolving. TYPE | |
8690 | evolving. TYPE may be a bareword, a constant declared | |
7059 | ||
8691 | with L<C<use constant>|constant>, or L<C<__PACKAGE__>|/__PACKAGE__>. It | |
7060 | ||
8692 | is | |
7061 | ||
8693 | currently bound to the use of the L<fields> pragma, | |
7062 | ||
8694 | and attributes are handled using the L<attributes> pragma, or starting | |
8695 | from Perl 5.8.0 also via the L<Attribute::Handlers> module. See | |
8696 | L<perlsub/"Private Variables via my()"> for details. | |
7063 | 8697 | |
7064 | 8698 | =end original |
7065 | 8699 | |
7066 | 8700 | TYPE と ATTRS の正確な文法とインターフェースは今でも進化しています。 |
7067 | ||
8701 | TYPE は、裸の単語、L<C<use constant>|constant> で宣言された定数、 | |
7068 | ||
8702 | L<C<__PACKAGE__>|/__PACKAGE__> のいずれかです。 | |
7069 | ||
8703 | 現在のところ、TYPE は L<fields> プラグマの使用と結び付けられていて、 | |
7070 | ||
8704 | 属性は L<attributes> プラグマか、Perl 5.8.0 からは | |
7071 | L< | |
8705 | L<Attribute::Handlers> モジュールと結び付けられています。 | |
8706 | 詳しくは L<perlsub/"Private Variables via my()"> を参照してください。 | |
7072 | 8707 | |
8708 | =begin original | |
8709 | ||
8710 | Note that with a parenthesised list, L<C<undef>|/undef EXPR> can be used | |
8711 | as a dummy placeholder, for example to skip assignment of initial | |
8712 | values: | |
8713 | ||
8714 | =end original | |
8715 | ||
8716 | かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> は、例えば初期値の代入を | |
8717 | 飛ばすために、ダミーのプレースホルダとして使えることに注意してください: | |
8718 | ||
8719 | my ( undef, $min, $hour ) = localtime; | |
8720 | ||
7073 | 8721 | =item next LABEL |
7074 | 8722 | X<next> X<continue> |
7075 | 8723 | |
8724 | =item next EXPR | |
8725 | ||
7076 | 8726 | =item next |
7077 | 8727 | |
8728 | =for Pod::Functions iterate a block prematurely | |
8729 | ||
7078 | 8730 | =begin original |
7079 | 8731 | |
7080 | The C<next> command is like the C<continue> statement in | |
8732 | The L<C<next>|/next LABEL> command is like the C<continue> statement in | |
7081 | the next iteration of the loop: | |
8733 | C; it starts the next iteration of the loop: | |
7082 | 8734 | |
7083 | 8735 | =end original |
7084 | 8736 | |
7085 | C<next> コマンドは、C での C<continue> 文のようなもので、 | |
8737 | L<C<next>|/next LABEL> コマンドは、C での C<continue> 文のようなもので、 | |
7086 | 8738 | ループの次の繰り返しを開始します: |
7087 | 8739 | |
7088 | 8740 | LINE: while (<STDIN>) { |
7089 | 8741 | next LINE if /^#/; # discard comments |
7090 | 8742 | #... |
7091 | 8743 | } |
7092 | 8744 | |
7093 | 8745 | =begin original |
7094 | 8746 | |
7095 | Note that if there were a C<continue> block on the | |
8747 | Note that if there were a L<C<continue>|/continue BLOCK> block on the | |
8748 | above, it would get | |
7096 | 8749 | executed even on discarded lines. If LABEL is omitted, the command |
7097 | refers to the innermost enclosing loop. | |
8750 | refers to the innermost enclosing loop. The C<next EXPR> form, available | |
8751 | as of Perl 5.18.0, allows a label name to be computed at run time, being | |
8752 | otherwise identical to C<next LABEL>. | |
7098 | 8753 | |
7099 | 8754 | =end original |
7100 | 8755 | |
7101 | C<continue> ブロックが存在すれば、たとえ捨てられる行に | |
8756 | L<C<continue>|/continue BLOCK> ブロックが存在すれば、たとえ捨てられる行に | |
7102 | 8757 | あっても、それが実行されます。 |
7103 | LABEL が省略されると、 | |
8758 | LABEL が省略されると、コマンドは一番内側のループを参照します。 | |
8759 | Perl 5.18.0 から利用可能な C<next EXPR> 形式では、実行時に計算される | |
8760 | ラベル名が使えます; それ以外は C<next LABEL> と同一です。 | |
7104 | 8761 | |
7105 | 8762 | =begin original |
7106 | 8763 | |
7107 | C<next> cannot be used to exit a block which returns a | |
8764 | L<C<next>|/next LABEL> cannot be used to exit a block which returns a | |
7108 | C<eval {}>, C<sub {}>, or C<do {}>, and should not be used | |
8765 | value such as C<eval {}>, C<sub {}>, or C<do {}>, and should not be used | |
7109 | a grep | |
8766 | to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST> | |
8767 | operation. | |
7110 | 8768 | |
7111 | 8769 | =end original |
7112 | 8770 | |
7113 | C<next> は C<eval {}>, C<sub {}>, C<do {}> のように値を返す | |
8771 | L<C<next>|/next LABEL> は C<eval {}>, C<sub {}>, C<do {}> のように値を返す | |
7114 | ブロックから抜けるのには使えません | |
8772 | ブロックから抜けるのには使えません; また、L<C<grep>|/grep BLOCK LIST> や | |
7115 | ||
8773 | L<C<map>|/map BLOCK LIST> 操作から抜けるのに使うべきではありません。 | |
7116 | 8774 | |
7117 | 8775 | =begin original |
7118 | 8776 | |
7119 | 8777 | Note that a block by itself is semantically identical to a loop |
7120 | that executes once. Thus C<next> will exit such a block | |
8778 | that executes once. Thus L<C<next>|/next LABEL> will exit such a block | |
8779 | early. | |
7121 | 8780 | |
7122 | 8781 | =end original |
7123 | 8782 | |
7124 | 8783 | ブロック自身は一回だけ実行されるループと文法的に同一であることに |
7125 | 8784 | 注意してください。 |
7126 | 従って、C<next> はそのようなブロックから早く抜けるのに使えます。 | |
8785 | 従って、L<C<next>|/next LABEL> はそのようなブロックから早く抜けるのに使えます。 | |
7127 | 8786 | |
7128 | 8787 | =begin original |
7129 | 8788 | |
7130 | See also L</continue> for an illustration of how | |
8789 | See also L<C<continue>|/continue BLOCK> for an illustration of how | |
7131 | C< | |
8790 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and | |
8791 | L<C<redo>|/redo LABEL> work. | |
7132 | 8792 | |
7133 | 8793 | =end original |
7134 | 8794 | |
7135 | C<last>, C<next>, C<redo> が | |
8795 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL> が | |
7136 | L</continue> も参照して | |
8796 | どのように働くかについては L<C<continue>|/continue BLOCK> も参照してください。 | |
7137 | 8797 | |
8798 | =begin original | |
8799 | ||
8800 | Unlike most named operators, this has the same precedence as assignment. | |
8801 | It is also exempt from the looks-like-a-function rule, so | |
8802 | C<next ("foo")."bar"> will cause "bar" to be part of the argument to | |
8803 | L<C<next>|/next LABEL>. | |
8804 | ||
8805 | =end original | |
8806 | ||
8807 | ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 | |
8808 | また、関数のように見えるものの規則からも免れるので、C<next ("foo")."bar"> と | |
8809 | すると "bar" は L<C<next>|/next LABEL> への引数の一部となります。 | |
8810 | ||
7138 | 8811 | =item no MODULE VERSION LIST |
7139 | 8812 | X<no declarations> |
7140 | 8813 | X<unimporting> |
7141 | 8814 | |
7142 | 8815 | =item no MODULE VERSION |
7143 | 8816 | |
7144 | 8817 | =item no MODULE LIST |
7145 | 8818 | |
7146 | 8819 | =item no MODULE |
7147 | 8820 | |
7148 | 8821 | =item no VERSION |
7149 | 8822 | |
8823 | =for Pod::Functions unimport some module symbols or semantics at compile time | |
8824 | ||
7150 | 8825 | =begin original |
7151 | 8826 | |
7152 | See the C<use> function, of which | |
8827 | See the L<C<use>|/use Module VERSION LIST> function, of which | |
8828 | L<C<no>|/no MODULE VERSION LIST> is the opposite. | |
7153 | 8829 | |
7154 | 8830 | =end original |
7155 | 8831 | |
7156 | L<use> 関数を参照してください | |
8832 | L<C<use>|/use Module VERSION LIST> 関数を参照してください; | |
8833 | L<C<no>|/no MODULE VERSION LIST> は、その逆を行なうものです。 | |
7157 | 8834 | |
7158 | 8835 | =item oct EXPR |
7159 | 8836 | X<oct> X<octal> X<hex> X<hexadecimal> X<binary> X<bin> |
7160 | 8837 | |
7161 | 8838 | =item oct |
7162 | 8839 | |
8840 | =for Pod::Functions convert a string to an octal number | |
8841 | ||
7163 | 8842 | =begin original |
7164 | 8843 | |
7165 | 8844 | Interprets EXPR as an octal string and returns the corresponding |
7166 | 8845 | value. (If EXPR happens to start off with C<0x>, interprets it as a |
7167 | 8846 | hex string. If EXPR starts off with C<0b>, it is interpreted as a |
7168 | 8847 | binary string. Leading whitespace is ignored in all three cases.) |
7169 | 8848 | The following will handle decimal, binary, octal, and hex in standard |
7170 | 8849 | Perl notation: |
7171 | 8850 | |
7172 | 8851 | =end original |
7173 | 8852 | |
7174 | 8853 | EXPR を 8 進数文字列と解釈して、対応する値を返します。 |
7175 | 8854 | (EXPR が C<0x> で始まるときには、16 進数文字列と解釈します。 |
7176 | 8855 | EXPR が C<0b>で始まるときは、2 進数文字列と解釈します。 |
7177 | 8856 | どの場合でも、先頭の空白は無視されます。) |
7178 | 8857 | 以下の例は、標準的な Perl の記法での |
7179 | 8858 | 10 進数、2 進数、8 進数、16 進数を扱います: |
7180 | 8859 | |
7181 | 8860 | $val = oct($val) if $val =~ /^0/; |
7182 | 8861 | |
7183 | 8862 | =begin original |
7184 | 8863 | |
7185 | If EXPR is omitted, uses C<$_>. To go the other way | |
8864 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. To go the other way | |
7186 | in octal), use sprintf | |
8865 | (produce a number in octal), use L<C<sprintf>|/sprintf FORMAT, LIST> or | |
8866 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST>: | |
7187 | 8867 | |
7188 | 8868 | =end original |
7189 | 8869 | |
7190 | EXPR | |
8870 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
7191 | (8 進数を扱う)その他の方法としては sprintf | |
8871 | (8 進数を扱う)その他の方法をとしては L<C<sprintf>|/sprintf FORMAT, LIST> や | |
8872 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST> があります: | |
7192 | 8873 | |
7193 | $dec_perms = (stat("filename"))[2] & 07777; | |
8874 | my $dec_perms = (stat("filename"))[2] & 07777; | |
7194 | $oct_perm_str = sprintf "%o", $perms; | |
8875 | my $oct_perm_str = sprintf "%o", $perms; | |
7195 | 8876 | |
7196 | 8877 | =begin original |
7197 | 8878 | |
7198 | The oct | |
8879 | The L<C<oct>|/oct EXPR> function is commonly used when a string such as | |
7199 | ||
8880 | C<644> needs | |
8881 | to be converted into a file mode, for example. Although Perl | |
7200 | 8882 | automatically converts strings into numbers as needed, this automatic |
7201 | 8883 | conversion assumes base 10. |
7202 | 8884 | |
7203 | 8885 | =end original |
7204 | 8886 | |
7205 | oct | |
8887 | L<C<oct>|/oct EXPR> 関数は例えば、 C<644> といった文字列をファイルモードに | |
7206 | よく使います。 | |
8888 | 変換する時によく使います。 | |
7207 | 8889 | Perl は必要に応じて自動的に文字列を数値に変換しますが、 |
7208 | 8890 | この自動変換は十進数を仮定します。 |
7209 | 8891 | |
7210 | 8892 | =begin original |
7211 | 8893 | |
7212 | Leading white space is ignored without warning, as too are any trailing | |
8894 | Leading white space is ignored without warning, as too are any trailing | |
7213 | non-digits, such as a decimal point (C<oct> only handles | |
8895 | non-digits, such as a decimal point (L<C<oct>|/oct EXPR> only handles | |
7214 | integers, not negative integers or floating point). | |
8896 | non-negative integers, not negative integers or floating point). | |
7215 | 8897 | |
7216 | 8898 | =end original |
7217 | 8899 | |
7218 | 8900 | 先頭の空白や、末尾の(小数点のような)非数字は警告なしに無視されます |
7219 | (C<oct> は非負整数のみを扱えます; 負の整数や小数は扱えません)。 | |
8901 | (L<C<oct>|/oct EXPR> は非負整数のみを扱えます; 負の整数や小数は扱えません)。 | |
7220 | 8902 | |
7221 | 8903 | =item open FILEHANDLE,EXPR |
7222 | 8904 | X<open> X<pipe> X<file, open> X<fopen> |
7223 | 8905 | |
7224 | 8906 | =item open FILEHANDLE,MODE,EXPR |
7225 | 8907 | |
7226 | 8908 | =item open FILEHANDLE,MODE,EXPR,LIST |
7227 | 8909 | |
7228 | 8910 | =item open FILEHANDLE,MODE,REFERENCE |
7229 | 8911 | |
7230 | 8912 | =item open FILEHANDLE |
7231 | 8913 | |
8914 | =for Pod::Functions open a file, pipe, or descriptor | |
8915 | ||
7232 | 8916 | =begin original |
7233 | 8917 | |
7234 | 8918 | Opens the file whose filename is given by EXPR, and associates it with |
7235 | 8919 | FILEHANDLE. |
7236 | 8920 | |
7237 | 8921 | =end original |
7238 | 8922 | |
7239 | 8923 | EXPR で与えられたファイル名のファイルを開き、FILEHANDLE と結び付けます。 |
7240 | 8924 | |
7241 | 8925 | =begin original |
7242 | 8926 | |
7243 | 8927 | Simple examples to open a file for reading: |
7244 | 8928 | |
7245 | 8929 | =end original |
7246 | 8930 | |
7247 | 8931 | 読み込みのためにファイルを開くための簡単な例は以下のもので: |
7248 | 8932 | |
7249 | open(my $fh, "<", "input.txt") | |
8933 | open(my $fh, "<", "input.txt") | |
7250 | or die " | |
8934 | or die "Can't open < input.txt: $!"; | |
7251 | 8935 | |
7252 | 8936 | =begin original |
7253 | 8937 | |
7254 | 8938 | and for writing: |
7255 | 8939 | |
7256 | 8940 | =end original |
7257 | 8941 | |
7258 | 8942 | 書き込み用は以下のものです: |
7259 | 8943 | |
7260 | open(my $fh, ">", "output.txt") | |
8944 | open(my $fh, ">", "output.txt") | |
7261 | or die " | |
8945 | or die "Can't open > output.txt: $!"; | |
7262 | 8946 | |
7263 | 8947 | =begin original |
7264 | 8948 | |
7265 | (The following is a comprehensive reference to | |
8949 | (The following is a comprehensive reference to | |
7266 | introduction you may | |
8950 | L<C<open>|/open FILEHANDLE,EXPR>: for a gentler introduction you may | |
8951 | consider L<perlopentut>.) | |
7267 | 8952 | |
7268 | 8953 | =end original |
7269 | 8954 | |
7270 | (以下は総合的な open | |
8955 | (以下は総合的な L<C<open>|/open FILEHANDLE,EXPR> のリファレンスです: | |
7271 | L<perlopentut> を参照してください。) | |
8956 | より親切な説明については L<perlopentut> を参照してください。) | |
7272 | 8957 | |
7273 | 8958 | =begin original |
7274 | 8959 | |
7275 | 8960 | If FILEHANDLE is an undefined scalar variable (or array or hash element), a |
7276 | 8961 | new filehandle is autovivified, meaning that the variable is assigned a |
7277 | 8962 | reference to a newly allocated anonymous filehandle. Otherwise if |
7278 | 8963 | FILEHANDLE is an expression, its value is the real filehandle. (This is |
7279 | 8964 | considered a symbolic reference, so C<use strict "refs"> should I<not> be |
7280 | 8965 | in effect.) |
7281 | 8966 | |
7282 | 8967 | =end original |
7283 | 8968 | |
7284 | 8969 | FILEHANDLE が未定義のスカラ変数(または配列かハッシュの要素)の場合、 |
7285 | 8970 | 新しいファイルハンドルが自動有効化され、その変数は新しく割り当てられた |
7286 | 8971 | 無名ファイルハンドルへのリファレンスが代入されます。 |
7287 | 8972 | さもなければ、もし FILEHANDLE が式なら、その値を求めている実際の |
7288 | 8973 | ファイルハンドルの名前として使います。 |
7289 | 8974 | (これはシンボリックリファレンスとして扱われるので、 |
7290 | 8975 | C<use strict "refs"> の影響を I<受けません>。) |
7291 | 8976 | |
7292 | 8977 | =begin original |
7293 | 8978 | |
7294 | If EXPR is omitted, the global (package) scalar variable of the same | |
7295 | name as the FILEHANDLE contains the filename. (Note that lexical | |
7296 | variables--those declared with C<my> or C<state>--will not work for this | |
7297 | purpose; so if you're using C<my> or C<state>, specify EXPR in your | |
7298 | call to open.) | |
7299 | ||
7300 | =end original | |
7301 | ||
7302 | EXPR が省略された場合、FILEHANDLE と同じ名前のグローバル(パッケージ) | |
7303 | スカラ変数にファイル名が入っています。 | |
7304 | (レキシカル変数 -- C<my> や C<state> で宣言されたもの -- はこの用途には | |
7305 | 使えないことに注意してください; 従って、C<my> や C<state> を使っている場合は、 | |
7306 | open を呼び出すときに EXPR を指定してください。) | |
7307 | ||
7308 | =begin original | |
7309 | ||
7310 | 8979 | If three (or more) arguments are specified, the open mode (including |
7311 | 8980 | optional encoding) in the second argument are distinct from the filename in |
7312 | 8981 | the third. If MODE is C<< < >> or nothing, the file is opened for input. |
7313 | 8982 | If MODE is C<< > >>, the file is opened for output, with existing files |
7314 | 8983 | first being truncated ("clobbered") and nonexisting files newly created. |
7315 | 8984 | If MODE is C<<< >> >>>, the file is opened for appending, again being |
7316 | 8985 | created if necessary. |
7317 | 8986 | |
7318 | 8987 | =end original |
7319 | 8988 | |
7320 | 8989 | 3 (またはそれ以上)の引数が指定された場合、2 番目の引数の(オプションの |
7321 | 8990 | エンコーディングを含む)開く時のモードは、3 番目のファイル名と分離されます。 |
7322 | 8991 | MODE が C<< < >> か空の場合、ファイルは入力用に開かれます。 |
7323 | 8992 | MODE が C<< > >> の場合、ファイルは出力用に開かれ、既にファイルが |
7324 | 8993 | ある場合は切り詰められ(上書きされ)、ない場合は新しく作られます。 |
7325 | 8994 | MODE が C<<< >> >>> の場合、ファイルは追加用に開かれ、やはり必要なら |
7326 | 8995 | 作成されます。 |
7327 | 8996 | |
7328 | 8997 | =begin original |
7329 | 8998 | |
7330 | 8999 | You can put a C<+> in front of the C<< > >> or C<< < >> to |
7331 | 9000 | indicate that you want both read and write access to the file; thus |
7332 | C<< +< >> is almost always preferred for read/write updates--the | |
9001 | C<< +< >> is almost always preferred for read/write updates--the | |
7333 | C<< +> >> mode would clobber the file first. You cant usually use | |
9002 | C<< +> >> mode would clobber the file first. You can't usually use | |
7334 | 9003 | either read-write mode for updating textfiles, since they have |
7335 | 9004 | variable-length records. See the B<-i> switch in L<perlrun> for a |
7336 | 9005 | better approach. The file is created with permissions of C<0666> |
7337 | modified by the process's C<umask> value. | |
9006 | modified by the process's L<C<umask>|/umask EXPR> value. | |
7338 | 9007 | |
7339 | 9008 | =end original |
7340 | 9009 | |
7341 | 9010 | ファイルに読み込みアクセスと書き込みアクセスの両方をしたいことを示すために、 |
7342 | 9011 | C<< > >> や C<< < >> の前に C<+> を付けることができます: |
7343 | 9012 | 従って、ほとんど常に C<< +< >> が読み書き更新のために使われます -- |
7344 | 9013 | C<< +> >> モードはまずファイルを上書きします。 |
7345 | 9014 | 普通はこれらの読み書きモードをテキストファイルの更新のためには使えません; |
7346 | 9015 | なぜなら可変長のレコードで構成されているからです。 |
7347 | 9016 | よりよい手法については L<perlrun> の B<-i> オプションを参照してください。 |
7348 | ファイルは C<0666> をプロセスの C<umask> 値で修正した | |
9017 | ファイルは C<0666> をプロセスの L<C<umask>|/umask EXPR> 値で修正した | |
7349 | 作成されます。 | |
9018 | パーミッションで作成されます。 | |
7350 | 9019 | |
7351 | 9020 | =begin original |
7352 | 9021 | |
7353 | These various prefixes correspond to the fopen(3) modes of C<r>, | |
9022 | These various prefixes correspond to the L<fopen(3)> modes of C<r>, | |
7354 | 9023 | C<r+>, C<w>, C<w+>, C<a>, and C<a+>. |
7355 | 9024 | |
7356 | 9025 | =end original |
7357 | 9026 | |
7358 | これらの様々な前置詞は fopen(3) の C<r>, C<r+>, | |
9027 | これらの様々な前置詞は L<fopen(3)> の C<r>, C<r+>, | |
7359 | 9028 | C<w>, C<w+>, C<a>, C<a+> のモードに対応します。 |
7360 | 9029 | |
7361 | 9030 | =begin original |
7362 | 9031 | |
7363 | 9032 | In the one- and two-argument forms of the call, the mode and filename |
7364 | 9033 | should be concatenated (in that order), preferably separated by white |
7365 | 9034 | space. You can--but shouldn't--omit the mode in these forms when that mode |
7366 | is C<< < >>. It is | |
9035 | is C<< < >>. It is safe to use the two-argument form of | |
7367 | the filename argument is a known literal. | |
9036 | L<C<open>|/open FILEHANDLE,EXPR> if the filename argument is a known literal. | |
7368 | 9037 | |
7369 | 9038 | =end original |
7370 | 9039 | |
7371 | 9040 | 1 引数 と 2 引数の形式ではモードとファイル名は(この順番で) |
7372 | 9041 | 結合されます(空白によって分割されているかもしれません)。 |
7373 | 9042 | この形式で、モードが C<< '<' >> の場合はモードを省略できます (が、 |
7374 | 9043 | するべきではありません)。 |
7375 | ファイル引数が既知のリテラルの場合、2 引数形式の | |
9044 | ファイル引数が既知のリテラルの場合、2 引数形式の | |
9045 | L<C<open>|/open FILEHANDLE,EXPR> は安全です。 | |
7376 | 9046 | |
7377 | 9047 | =begin original |
7378 | 9048 | |
7379 | 9049 | For three or more arguments if MODE is C<|->, the filename is |
7380 | 9050 | interpreted as a command to which output is to be piped, and if MODE |
7381 | 9051 | is C<-|>, the filename is interpreted as a command that pipes |
7382 | 9052 | output to us. In the two-argument (and one-argument) form, one should |
7383 | 9053 | replace dash (C<->) with the command. |
7384 | 9054 | See L<perlipc/"Using open() for IPC"> for more examples of this. |
7385 | (You are not allowed to C<open> to a command | |
9055 | (You are not allowed to L<C<open>|/open FILEHANDLE,EXPR> to a command | |
7386 | out, but see L<IPC::Open2>, L<IPC::Open3>, and | |
9056 | that pipes both in I<and> out, but see L<IPC::Open2>, L<IPC::Open3>, and | |
7387 | 9057 | L<perlipc/"Bidirectional Communication with Another Process"> for |
7388 | 9058 | alternatives.) |
7389 | 9059 | |
7390 | 9060 | =end original |
7391 | 9061 | |
7392 | 9062 | 3 引数以上の形式で |
7393 | 9063 | MODE が C<|-> の場合、ファイル名は出力がパイプされるコマンドとして |
7394 | 9064 | 解釈され、MODE が C<-|> の場合、ファイル名は出力がこちらに |
7395 | 9065 | パイプされるコマンドとして解釈されます。 |
7396 | 2 引数(と 1 引数) の形式ではハイフン(C<->)をコマンドの代わりに | |
9066 | 2 引数(と 1 引数) の形式ではハイフン(C<->)をコマンドの代わりに使えます。 | |
7397 | 使えます。 | |
7398 | 9067 | これに関するさらなる例については L<perlipc/"Using open() for IPC"> を |
7399 | 9068 | 参照してください。 |
7400 | (C<open> を入出力 I<両用> にパイプすることは | |
9069 | (L<C<open>|/open FILEHANDLE,EXPR> を入出力 I<両用> にパイプすることは | |
7401 | 代替案としては L<IPC::Open2>, L<IPC::Open3>, | |
9070 | 出来ませんが、代替案としては L<IPC::Open2>, L<IPC::Open3>, | |
7402 | 9071 | L<perlipc/"Bidirectional Communication with Another Process"> を |
7403 | 9072 | 参照してください。) |
7404 | 9073 | |
7405 | 9074 | =begin original |
7406 | 9075 | |
7407 | 9076 | In the form of pipe opens taking three or more arguments, if LIST is specified |
7408 | 9077 | (extra arguments after the command name) then LIST becomes arguments |
7409 | 9078 | to the command invoked if the platform supports it. The meaning of |
7410 | C<open> with more than three arguments for | |
9079 | L<C<open>|/open FILEHANDLE,EXPR> with more than three arguments for | |
7411 | defined, but experimental "layers" may give | |
9080 | non-pipe modes is not yet defined, but experimental "layers" may give | |
7412 | meaning. | |
9081 | extra LIST arguments meaning. | |
7413 | 9082 | |
7414 | 9083 | =end original |
7415 | 9084 | |
7416 | 9085 | パイプでの三つ以上の引数の形式では、LIST (コマンド名の後の追加の引数) が |
7417 | 9086 | 指定されると、プラットフォームが対応していれば、LIST は起動される |
7418 | 9087 | コマンドへの引数となります。 |
7419 | パイプモードではない C<open> での三つ以上の引数の | |
9088 | パイプモードではない L<C<open>|/open FILEHANDLE,EXPR> での三つ以上の引数の | |
7420 | 実験的な「層」は追加の LIST 引数の意味を与えます。 | |
9089 | 意味はまだ未定義ですが、実験的な「層」は追加の LIST 引数の意味を与えます。 | |
7421 | 9090 | |
7422 | 9091 | =begin original |
7423 | 9092 | |
7424 | In the two-argument (and one-argument) form, opening C<< <- >> | |
9093 | In the two-argument (and one-argument) form, opening C<< <- >> | |
7425 | 9094 | or C<-> opens STDIN and opening C<< >- >> opens STDOUT. |
7426 | 9095 | |
7427 | 9096 | =end original |
7428 | 9097 | |
7429 | 9098 | 2 引数(と 1 引数)で C<< <- >> か C<-> を open すると STDIN が |
7430 | 9099 | オープンされ、C<< >- >> を open すると STDOUT がオープンされます。 |
7431 | 9100 | |
7432 | 9101 | =begin original |
7433 | 9102 | |
7434 | 9103 | You may (and usually should) use the three-argument form of open to specify |
7435 | 9104 | I/O layers (sometimes referred to as "disciplines") to apply to the handle |
7436 | 9105 | that affect how the input and output are processed (see L<open> and |
7437 | L<PerlIO> for more details). For example: | |
9106 | L<PerlIO> for more details). For example: | |
7438 | 9107 | |
7439 | 9108 | =end original |
7440 | 9109 | |
7441 | 9110 | open の 3 引数形式では、どのように入出力が処理されるかに影響を与える |
7442 | 9111 | I/O 層(「ディシプリン」とも呼ばれます)を指定できます |
7443 | 9112 | (そして普通はそうするべきです) |
7444 | 9113 | (詳細については L<open> と L<PerlIO> を参照してください)。 |
7445 | 9114 | 例えば: |
7446 | 9115 | |
7447 | open(my $fh, "<:encoding(UTF-8)", | |
9116 | open(my $fh, "<:encoding(UTF-8)", $filename) | |
7448 | || die " | |
9117 | || die "Can't open UTF-8 encoded $filename: $!"; | |
7449 | 9118 | |
7450 | 9119 | =begin original |
7451 | 9120 | |
7452 | 9121 | opens the UTF8-encoded file containing Unicode characters; |
7453 | see L<perluniintro>. Note that if layers are specified in the | |
9122 | see L<perluniintro>. Note that if layers are specified in the | |
7454 | 9123 | three-argument form, then default layers stored in ${^OPEN} (see L<perlvar>; |
7455 | usually set by the | |
9124 | usually set by the L<open> pragma or the switch C<-CioD>) are ignored. | |
9125 | Those layers will also be ignored if you specifying a colon with no name | |
9126 | following it. In that case the default layer for the operating system | |
9127 | (:raw on Unix, :crlf on Windows) is used. | |
7456 | 9128 | |
7457 | 9129 | =end original |
7458 | 9130 | |
7459 | 9131 | は、Unicode 文字を含む UTF8 エンコードされたファイルを開きます; |
7460 | 9132 | L<perluniintro> を参照してください。 |
7461 | 9133 | 3 引数形式で層を指定すると、${^OPEN} (L<perlvar> を参照してください; |
7462 | 通常は | |
9134 | 通常は L<open> プラグマか C<-CioD> オプションでセットされます) に保存された | |
7463 | ||
9135 | デフォルト層は無視されることに注意してください。 | |
9136 | これらの層は、名前なしでコロンを指定した場合にも無視されます。 | |
9137 | この場合 OS のデフォルトの層 (Unix では :raw、Windows では :crlf) が | |
9138 | 使われます。 | |
7464 | 9139 | |
7465 | 9140 | =begin original |
7466 | 9141 | |
7467 | 9142 | Open returns nonzero on success, the undefined value otherwise. If |
7468 | the C<open> involved a pipe, the return value | |
9143 | the L<C<open>|/open FILEHANDLE,EXPR> involved a pipe, the return value | |
7469 | the subprocess. | |
9144 | happens to be the pid of the subprocess. | |
7470 | 9145 | |
7471 | 9146 | =end original |
7472 | 9147 | |
7473 | 9148 | open は、成功時にはゼロ以外を返し、失敗時には未定義値を返します。 |
7474 | パイプに関る C<open> のときには、返り値は | |
9149 | パイプに関る L<C<open>|/open FILEHANDLE,EXPR> のときには、返り値は | |
9150 | サブプロセスの pid となります。 | |
7475 | 9151 | |
7476 | 9152 | =begin original |
7477 | 9153 | |
7478 | ||
9154 | On some systems (in general, DOS- and Windows-based systems) | |
7479 | ||
9155 | L<C<binmode>|/binmode FILEHANDLE, LAYER> is necessary when you're not | |
7480 | ||
9156 | working with a text file. For the sake of portability it is a good idea | |
7481 | ||
9157 | always to use it when appropriate, and never to use it when it isn't | |
7482 | ||
9158 | appropriate. Also, people can set their I/O to be by default | |
7483 | ||
9159 | UTF8-encoded Unicode, not bytes. | |
7484 | need C<binmode>. The rest need it. | |
7485 | 9160 | |
7486 | 9161 | =end original |
7487 | 9162 | |
7488 | テキストファイル | |
9163 | テキストファイルでないものを扱う場合に | |
7489 | ||
9164 | L<C<binmode>|/binmode FILEHANDLE, LAYER> が必要な | |
7490 | ||
9165 | システムもあります(一般的には DOS と Windows ベースのシステムです)。 | |
7491 | ||
9166 | 移植性のために、適切なときには常にこれを使い、適切でないときには | |
7492 | ||
9167 | 決して使わないというのは良い考えです。 | |
7493 | ||
9168 | また、デフォルトとして I/O を bytes ではなく UTF-8 エンコードされた | |
7494 | ||
9169 | Unicode にセットすることも出来ます。 | |
7495 | 9170 | |
7496 | 9171 | =begin original |
7497 | 9172 | |
7498 | When opening a file, it's seldom a good idea to continue | |
9173 | When opening a file, it's seldom a good idea to continue | |
7499 | if the request failed, so C<open> is frequently | |
9174 | if the request failed, so L<C<open>|/open FILEHANDLE,EXPR> is frequently | |
7500 | C<die>. Even if C<die> won't do | |
9175 | used with L<C<die>|/die LIST>. Even if L<C<die>|/die LIST> won't do | |
9176 | what you want (say, in a CGI script, | |
7501 | 9177 | where you want to format a suitable error message (but there are |
7502 | 9178 | modules that can help with that problem)) always check |
7503 | the return value from opening a file. | |
9179 | the return value from opening a file. | |
7504 | 9180 | |
7505 | 9181 | =end original |
7506 | 9182 | |
7507 | ファイルを開く時、開くのに失敗した時に通常の処理を続けるのは | |
9183 | ファイルを開く時、開くのに失敗した時に通常の処理を続けるのは普通は悪い | |
7508 | ||
9184 | 考えなので、L<C<open>|/open FILEHANDLE,EXPR> はしばしば | |
7509 | 使われます。 | |
9185 | L<C<die>|/die LIST> と結び付けられて使われます。 | |
7510 | 望むものが C<die> でない場合(例えば、CGI スクリプト | |
9186 | 望むものが L<C<die>|/die LIST> でない場合(例えば、CGI スクリプトのように | |
7511 | 9187 | きれいにフォーマットされたエラーメッセージを作りたい場合 |
7512 | 9188 | (但しこの問題を助けるモジュールがあります))でも、 |
7513 | 9189 | ファイルを開いた時の返り値を常にチェックするべきです。 |
7514 | 9190 | |
7515 | 9191 | =begin original |
7516 | 9192 | |
9193 | The filehandle will be closed when its reference count reaches zero. | |
9194 | If it is a lexically scoped variable declared with L<C<my>|/my VARLIST>, | |
9195 | that usually | |
9196 | means the end of the enclosing scope. However, this automatic close | |
9197 | does not check for errors, so it is better to explicitly close | |
9198 | filehandles, especially those used for writing: | |
9199 | ||
9200 | =end original | |
9201 | ||
9202 | ファイルハンドルは、参照カウントが 0 になったときに閉じられます。 | |
9203 | これが L<C<my>|/my VARLIST> で宣言されたレキシカルスコープを持つ変数の場合、 | |
9204 | 普通は囲まれたスコープの終わりを意味します。 | |
9205 | しかし、この自動閉じはエラーをチェックしないので、特に書き込み用の場合は、 | |
9206 | 明示的にファイルハンドルを閉じる方がよいです。 | |
9207 | ||
9208 | close($handle) | |
9209 | || warn "close failed: $!"; | |
9210 | ||
9211 | =begin original | |
9212 | ||
9213 | An older style is to use a bareword as the filehandle, as | |
9214 | ||
9215 | =end original | |
9216 | ||
9217 | より古いスタイルは、次のように、ファイルハンドルとして裸の単語を使います | |
9218 | ||
9219 | open(FH, "<", "input.txt") | |
9220 | or die "Can't open < input.txt: $!"; | |
9221 | ||
9222 | =begin original | |
9223 | ||
9224 | Then you can use C<FH> as the filehandle, in C<< close FH >> and C<< | |
9225 | <FH> >> and so on. Note that it's a global variable, so this form is | |
9226 | not recommended in new code. | |
9227 | ||
9228 | =end original | |
9229 | ||
9230 | それから C<FH> を、C<< close FH >> や C<< <FH> >> などのように、 | |
9231 | ファイルハンドルとして使えます。 | |
9232 | これはグローバル変数なので、新しいコードでは非推奨であることに | |
9233 | 注意してください。 | |
9234 | ||
9235 | =begin original | |
9236 | ||
9237 | As a shortcut a one-argument call takes the filename from the global | |
9238 | scalar variable of the same name as the filehandle: | |
9239 | ||
9240 | =end original | |
9241 | ||
9242 | 短縮版として、1 引数呼び出しでは、ファイル名を、ファイルハンドルと同じ名前の | |
9243 | グローバルなスカラ変数から取ります: | |
9244 | ||
9245 | $ARTICLE = 100; | |
9246 | open(ARTICLE) or die "Can't find article $ARTICLE: $!\n"; | |
9247 | ||
9248 | =begin original | |
9249 | ||
9250 | Here C<$ARTICLE> must be a global (package) scalar variable - not one | |
9251 | declared with L<C<my>|/my VARLIST> or L<C<state>|/state VARLIST>. | |
9252 | ||
9253 | =end original | |
9254 | ||
9255 | ここで C<$ARTICLE> はグローバル(パッケージ)スカラ変数でなければなりません - | |
9256 | L<C<my>|/my VARLIST> や L<C<state>|/state VARLIST> で宣言された | |
9257 | 変数ではありません。 | |
9258 | ||
9259 | =begin original | |
9260 | ||
7517 | 9261 | As a special case the three-argument form with a read/write mode and the third |
7518 | argument being C<undef>: | |
9262 | argument being L<C<undef>|/undef EXPR>: | |
7519 | 9263 | |
7520 | 9264 | =end original |
7521 | 9265 | |
7522 | 特別な場合として、3 引数の形で読み書きモードで 3 番目の引数が | |
9266 | 特別な場合として、3 引数の形で読み書きモードで 3 番目の引数が L<C<undef>|/undef EXPR> の場合: | |
7523 | C<undef> の場合: | |
7524 | 9267 | |
7525 | 9268 | open(my $tmp, "+>", undef) or die ... |
7526 | 9269 | |
7527 | 9270 | =begin original |
7528 | 9271 | |
7529 | 9272 | opens a filehandle to an anonymous temporary file. Also using C<< +< >> |
7530 | 9273 | works for symmetry, but you really should consider writing something |
7531 | to the temporary file first. You will need to | |
9274 | to the temporary file first. You will need to | |
7532 | reading. | |
9275 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> to do the reading. | |
7533 | 9276 | |
7534 | 9277 | =end original |
7535 | 9278 | |
7536 | 9279 | 無名一時ファイルとしてファイルハンドルを開きます。 |
7537 | 9280 | また C<< +< >> も対称性のために動作しますが、 |
7538 | 9281 | 一時ファイルにはまず何かを書き込みたいはずです。 |
7539 | 読み込みを行うためには seek | |
9282 | 読み込みを行うためには L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> が | |
9283 | 必要です。 | |
7540 | 9284 | |
7541 | 9285 | =begin original |
7542 | 9286 | |
7543 | ||
9287 | Perl is built using PerlIO by default. Unless you've | |
7544 | 9288 | changed this (such as building Perl with C<Configure -Uuseperlio>), you can |
7545 | 9289 | open filehandles directly to Perl scalars via: |
7546 | 9290 | |
7547 | 9291 | =end original |
7548 | 9292 | |
7549 | ||
9293 | Perl はデフォルトで PerlIO を使ってビルドされています。 | |
7550 | 9294 | (C<Configure -Uuseperlio> して Perl をビルドするなどして)これを |
7551 | 9295 | 変更していない限り、以下のようにして、Perl スカラを直接ファイルハンドルで |
7552 | 9296 | 開くことができます: |
7553 | 9297 | |
7554 | open($fh, ">", \$variable) || .. | |
9298 | open(my $fh, ">", \$variable) || .. | |
7555 | 9299 | |
7556 | 9300 | =begin original |
7557 | 9301 | |
7558 | 9302 | To (re)open C<STDOUT> or C<STDERR> as an in-memory file, close it first: |
7559 | 9303 | |
7560 | 9304 | =end original |
7561 | 9305 | |
7562 | 9306 | C<STDOUT> や C<STDERR> を「オンメモリの」ファイルとして |
7563 | 9307 | 再び開きたい場合は、先にそれを閉じます: |
7564 | 9308 | |
7565 | 9309 | close STDOUT; |
7566 | 9310 | open(STDOUT, ">", \$variable) |
7567 | 9311 | or die "Can't open STDOUT: $!"; |
7568 | 9312 | |
7569 | 9313 | =begin original |
7570 | 9314 | |
7571 | ||
9315 | See L<perliol> for detailed info on PerlIO. | |
7572 | 9316 | |
7573 | 9317 | =end original |
7574 | 9318 | |
7575 | ||
9319 | PerlIO に関する詳しい情報については L<perliol> を参照してください。 | |
7576 | 9320 | |
7577 | ||
9321 | =begin original | |
7578 | open(ARTICLE) or die "Can't find article $ARTICLE: $!\n"; | |
7579 | while (<ARTICLE>) {... | |
7580 | 9322 | |
7581 | ||
9323 | General examples: | |
7582 | # if the open fails, output is discarded | |
7583 | 9324 | |
7584 | ||
9325 | =end original | |
7585 | or die "Can't open 'dbase.mine' for update: $!"; | |
7586 | 9326 | |
7587 | ||
9327 | 一般的な例: | |
7588 | or die "Can't open 'dbase.mine' for update: $!"; | |
7589 | 9328 | |
7590 | | |
9329 | open(my $log, ">>", "/usr/spool/news/twitlog"); | |
7591 | | |
9330 | # if the open fails, output is discarded | |
7592 | 9331 | |
7593 | | |
9332 | open(my $dbase, "+<", "dbase.mine") # open for update | |
7594 | | |
9333 | or die "Can't open 'dbase.mine' for update: $!"; | |
7595 | 9334 | |
7596 | | |
9335 | open(my $dbase, "+<dbase.mine") # ditto | |
7597 | | |
9336 | or die "Can't open 'dbase.mine' for update: $!"; | |
7598 | 9337 | |
7599 | | |
9338 | open(my $article_fh, "-|", "caesar <$article") # decrypt | |
7600 | | |
9339 | # article | |
7601 | | |
9340 | or die "Can't start caesar: $!"; | |
7602 | print MEMORY "foo!\n"; # output will appear in $var | |
7603 | 9341 | |
7604 | | |
9342 | open(my $article_fh, "caesar <$article |") # ditto | |
9343 | or die "Can't start caesar: $!"; | |
7605 | 9344 | |
7606 | | |
9345 | open(my $out_fh, "|-", "sort >Tmp$$") # $$ is our process id | |
7607 | | |
9346 | or die "Can't start sort: $!"; | |
7608 | } | |
7609 | 9347 | |
7610 | | |
9348 | # in-memory files | |
7611 | | |
9349 | open(my $memory, ">", \$var) | |
7612 | | |
9350 | or die "Can't open memory file: $!"; | |
7613 | | |
9351 | print $memory "foo!\n"; # output will appear in $var | |
7614 | print STDERR "Can't open $filename: $!\n"; | |
7615 | return; | |
7616 | } | |
7617 | 9352 | |
7618 | local $_; | |
7619 | while (<$input>) { # note use of indirection | |
7620 | if (/^#include "(.*)"/) { | |
7621 | process($1, $input); | |
7622 | next; | |
7623 | } | |
7624 | #... # whatever | |
7625 | } | |
7626 | } | |
7627 | ||
7628 | 9353 | =begin original |
7629 | 9354 | |
7630 | See L<perliol> for detailed info on PerlIO. | |
7631 | ||
7632 | =end original | |
7633 | ||
7634 | PerlIO に関する詳しい情報については L<perliol> を参照してください。 | |
7635 | ||
7636 | =begin original | |
7637 | ||
7638 | 9355 | You may also, in the Bourne shell tradition, specify an EXPR beginning |
7639 | 9356 | with C<< >& >>, in which case the rest of the string is interpreted |
7640 | 9357 | as the name of a filehandle (or file descriptor, if numeric) to be |
7641 | duped (as | |
9358 | duped (as in L<dup(2)>) and opened. You may use C<&> after C<< > >>, | |
7642 | 9359 | C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>, and C<< +< >>. |
7643 | 9360 | The mode you specify should match the mode of the original filehandle. |
7644 | 9361 | (Duping a filehandle does not take into account any existing contents |
7645 | of IO buffers.) If you use the three-argument | |
9362 | of IO buffers.) If you use the three-argument | |
9363 | form, then you can pass either a | |
7646 | 9364 | number, the name of a filehandle, or the normal "reference to a glob". |
7647 | 9365 | |
7648 | 9366 | =end original |
7649 | 9367 | |
7650 | 9368 | Bourne シェルの慣例にしたがって、EXPR の先頭に C<< >& >> |
7651 | 9369 | を付けると、EXPR の残りの文字列をファイルハンドル名 |
7652 | (数字であれば、ファイル記述子) と解釈して、それを ( | |
9370 | (数字であれば、ファイル記述子) と解釈して、それを (L<dup(2)> によって) | |
7653 | 9371 | 複製してオープンします。 |
7654 | 9372 | C<&> は、C<< > >>, C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>, |
7655 | 9373 | C<< +< >>というモード指定に付けることができます。 |
7656 | 9374 | 指定するモード指定は、もとのファイルハンドルのモードと |
7657 | 9375 | 合っていないといけません。 |
7658 | 9376 | (ファイルハンドルの複製は既に存在する IO バッファの内容に含めません。) |
7659 | 9377 | 3 引数形式を使う場合は、数値を渡すか、ファイルハンドルの名前を渡すか、 |
7660 | 9378 | 通常の「グロブへのリファレンス」を渡します。 |
7661 | 9379 | |
7662 | 9380 | =begin original |
7663 | 9381 | |
7664 | 9382 | Here is a script that saves, redirects, and restores C<STDOUT> and |
7665 | 9383 | C<STDERR> using various methods: |
7666 | 9384 | |
7667 | 9385 | =end original |
7668 | 9386 | |
7669 | 9387 | C<STDOUT> と C<STDERR> 保存し、リダイレクトし、元に戻すスクリプトを示します: |
7670 | 9388 | |
7671 | 9389 | #!/usr/bin/perl |
7672 | 9390 | open(my $oldout, ">&STDOUT") or die "Can't dup STDOUT: $!"; |
7673 | 9391 | open(OLDERR, ">&", \*STDERR) or die "Can't dup STDERR: $!"; |
7674 | 9392 | |
7675 | 9393 | open(STDOUT, '>', "foo.out") or die "Can't redirect STDOUT: $!"; |
7676 | 9394 | open(STDERR, ">&STDOUT") or die "Can't dup STDOUT: $!"; |
7677 | 9395 | |
7678 | 9396 | select STDERR; $| = 1; # make unbuffered |
7679 | 9397 | select STDOUT; $| = 1; # make unbuffered |
7680 | 9398 | |
7681 | 9399 | print STDOUT "stdout 1\n"; # this works for |
7682 | 9400 | print STDERR "stderr 1\n"; # subprocesses too |
7683 | 9401 | |
7684 | 9402 | open(STDOUT, ">&", $oldout) or die "Can't dup \$oldout: $!"; |
7685 | 9403 | open(STDERR, ">&OLDERR") or die "Can't dup OLDERR: $!"; |
7686 | 9404 | |
7687 | 9405 | print STDOUT "stdout 2\n"; |
7688 | 9406 | print STDERR "stderr 2\n"; |
7689 | 9407 | |
7690 | 9408 | =begin original |
7691 | 9409 | |
7692 | 9410 | If you specify C<< '<&=X' >>, where C<X> is a file descriptor number |
7693 | or a filehandle, then Perl will do an equivalent of C's | |
9411 | or a filehandle, then Perl will do an equivalent of C's L<fdopen(3)> of | |
7694 | that file descriptor (and not call | |
9412 | that file descriptor (and not call L<dup(2)>); this is more | |
7695 | 9413 | parsimonious of file descriptors. For example: |
7696 | 9414 | |
7697 | 9415 | =end original |
7698 | 9416 | |
7699 | 9417 | C<X> をファイル記述子の番号かファイルハンドルとして、 |
7700 | 9418 | C<< '<&=X' >> と指定すると、Perl はそのファイル記述子に対する |
7701 | C の | |
9419 | C の L<fdopen(3)> と同じことを行ないます(そして L<dup(2)> は呼び出しません); | |
7702 | 9420 | これはファイル記述子をより節約します。 |
7703 | 例: | |
9421 | 例えば: | |
7704 | 9422 | |
7705 | 9423 | # open for input, reusing the fileno of $fd |
7706 | open( | |
9424 | open(my $fh, "<&=", $fd) | |
7707 | 9425 | |
7708 | 9426 | =begin original |
7709 | 9427 | |
7710 | 9428 | or |
7711 | 9429 | |
7712 | 9430 | =end original |
7713 | 9431 | |
7714 | 9432 | または |
7715 | 9433 | |
7716 | open( | |
9434 | open(my $fh, "<&=$fd") | |
7717 | 9435 | |
7718 | 9436 | =begin original |
7719 | 9437 | |
7720 | 9438 | or |
7721 | 9439 | |
7722 | 9440 | =end original |
7723 | 9441 | |
7724 | 9442 | または |
7725 | 9443 | |
7726 | # open for append, using the fileno of | |
9444 | # open for append, using the fileno of $oldfh | |
7727 | open( | |
9445 | open(my $fh, ">>&=", $oldfh) | |
7728 | 9446 | |
7729 | 9447 | =begin original |
7730 | 9448 | |
7731 | or | |
7732 | ||
7733 | =end original | |
7734 | ||
7735 | または | |
7736 | ||
7737 | open(FH, ">>&=OLDFH") | |
7738 | ||
7739 | =begin original | |
7740 | ||
7741 | 9449 | Being parsimonious on filehandles is also useful (besides being |
7742 | 9450 | parsimonious) for example when something is dependent on file |
7743 | descriptors, like for example locking using | |
9451 | descriptors, like for example locking using | |
7744 | C< | |
9452 | L<C<flock>|/flock FILEHANDLE,OPERATION>. If you do just | |
7745 | ||
9453 | C<< open(my $A, ">>&", $B) >>, the filehandle C<$A> will not have the | |
7746 | ||
9454 | same file descriptor as C<$B>, and therefore C<flock($A)> will not | |
7747 | ||
9455 | C<flock($B)> nor vice versa. But with C<< open(my $A, ">>&=", $B) >>, | |
9456 | the filehandles will share the same underlying system file descriptor. | |
7748 | 9457 | |
7749 | 9458 | =end original |
7750 | 9459 | |
7751 | ファイルハンドルを倹約することは、何かが | |
9460 | ファイルハンドルを倹約することは、(倹約できること以外に)何かが | |
7752 | ||
9461 | ファイル記述子に依存している場合、例えば | |
7753 | ||
9462 | L<C<flock>|/flock FILEHANDLE,OPERATION> を使った | |
7754 | ||
9463 | ファイルロックといった場合に有用です。 | |
7755 | ||
9464 | C<< open(my $A, ">>&", $B) >> とすると、ファイルハンドル C<$A> は C<$B> と同じ | |
7756 | ||
9465 | ファイル記述子にはならないので、C<flock($A)> と C<flock($B)> は別々になります。 | |
9466 | しかし C<< open(my $A, ">>&=", $B) >> ではファイルハンドルは基礎となるシステムの | |
7757 | 9467 | 同じファイル記述子を共有します。 |
7758 | 9468 | |
7759 | 9469 | =begin original |
7760 | 9470 | |
7761 | 9471 | Note that under Perls older than 5.8.0, Perl uses the standard C library's' |
7762 | fdopen() to implement the C<=> functionality. On many Unix systems, | |
9472 | L<fdopen(3)> to implement the C<=> functionality. On many Unix systems, | |
7763 | fdopen() fails when file descriptors exceed a certain value, typically 255. | |
9473 | L<fdopen(3)> fails when file descriptors exceed a certain value, typically 255. | |
7764 | 9474 | For Perls 5.8.0 and later, PerlIO is (most often) the default. |
7765 | 9475 | |
7766 | 9476 | =end original |
7767 | 9477 | |
7768 | 9478 | 5.8.0 より前の Perl の場合、C<=> 機能の実装は |
7769 | 標準 C ライブラリの fdopen() を使っています。 | |
9479 | 標準 C ライブラリの L<fdopen(3)> を使っています。 | |
7770 | 多くの Unix システムでは、fdopen() はファイル記述子がある値 | |
9480 | 多くの Unix システムでは、L<fdopen(3)> はファイル記述子がある値 | |
7771 | 9481 | (典型的には 255)を超えた場合に失敗することが知られています。 |
7772 | 9482 | 5.8.0 以降の Perl では、(ほとんどの場合) PerlIO がデフォルトです。 |
7773 | 9483 | |
7774 | 9484 | =begin original |
7775 | 9485 | |
7776 | You can see whether your Perl was built with PerlIO by running | |
9486 | You can see whether your Perl was built with PerlIO by running | |
7777 | ||
9487 | C<perl -V:useperlio>. If it says C<'define'>, you have PerlIO; | |
7778 | ||
9488 | otherwise you don't. | |
7779 | 9489 | |
7780 | 9490 | =end original |
7781 | 9491 | |
7782 | 9492 | Perl が PerlIO つきでビルドされているかどうかを確認するには、 |
7783 | C<perl -V | |
9493 | C<perl -V:useperlio> を見ます。 | |
7784 | ||
9494 | これが C<'define'> なら PerlIO を使っています; | |
7785 | 9495 | そうでなければ使っていません。 |
7786 | 9496 | |
7787 | 9497 | =begin original |
7788 | 9498 | |
7789 | 9499 | If you open a pipe on the command C<-> (that is, specify either C<|-> or C<-|> |
7790 | with the one- or two-argument forms of | |
9500 | with the one- or two-argument forms of | |
7791 | an implicit C<fork> is done, | |
9501 | L<C<open>|/open FILEHANDLE,EXPR>), an implicit L<C<fork>|/fork> is done, | |
7792 | p | |
9502 | so L<C<open>|/open FILEHANDLE,EXPR> returns twice: in the parent process | |
9503 | it returns the pid | |
7793 | 9504 | of the child process, and in the child process it returns (a defined) C<0>. |
7794 | 9505 | Use C<defined($pid)> or C<//> to determine whether the open was successful. |
7795 | 9506 | |
7796 | 9507 | =end original |
7797 | 9508 | |
7798 | 1 引数 または 2 引数の形の C<open | |
9509 | 1 引数 または 2 引数の形の L<C<open>|/open FILEHANDLE,EXPR>) で | |
7799 | C<-> というコマンドにパイプを開くと | |
9510 | (C<-|> や C<|-> というふうに) C<-> というコマンドにパイプを開くと、 | |
7800 | C<o | |
9511 | 暗黙の L<C<fork>|/fork> が行なわれるので、 | |
9512 | L<C<open>|/open FILEHANDLE,EXPR> は 2 回返ります; | |
7801 | 9513 | 親プロセスには子プロセスの pid が返され、子プロセスには (定義された) C<0> が |
7802 | 9514 | 返されます。 |
7803 | 9515 | open が成功したかどうかを調べるには、C<defined($pid)> または C<//> を |
7804 | 9516 | 使います。 |
7805 | 9517 | |
7806 | 9518 | =begin original |
7807 | 9519 | |
7808 | 9520 | For example, use either |
7809 | 9521 | |
7810 | 9522 | =end original |
7811 | 9523 | |
7812 | 9524 | 例えば、以下の二つ |
7813 | 9525 | |
7814 | $child_pid = open( | |
9526 | my $child_pid = open(my $from_kid, "-|") // die "Can't fork: $!"; | |
7815 | 9527 | |
7816 | 9528 | =begin original |
7817 | 9529 | |
7818 | 9530 | or |
7819 | 9531 | |
7820 | 9532 | =end original |
7821 | 9533 | |
7822 | 9534 | または |
7823 | 9535 | |
7824 | $child_pid = open( | |
9536 | my $child_pid = open(my $to_kid, "|-") // die "Can't fork: $!"; | |
7825 | 9537 | |
7826 | 9538 | =begin original |
7827 | 9539 | |
7828 | followed by | |
9540 | followed by | |
7829 | 9541 | |
7830 | 9542 | =end original |
7831 | 9543 | |
7832 | 9544 | を使って、後で以下のようにします。 |
7833 | 9545 | |
7834 | 9546 | if ($child_pid) { |
7835 | 9547 | # am the parent: |
7836 | # either write | |
9548 | # either write $to_kid or else read $from_kid | |
7837 | 9549 | ... |
7838 | ||
9550 | waitpid $child_pid, 0; | |
7839 | 9551 | } else { |
7840 | 9552 | # am the child; use STDIN/STDOUT normally |
7841 | 9553 | ... |
7842 | 9554 | exit; |
7843 | } | |
9555 | } | |
7844 | 9556 | |
7845 | 9557 | =begin original |
7846 | 9558 | |
7847 | 9559 | The filehandle behaves normally for the parent, but I/O to that |
7848 | 9560 | filehandle is piped from/to the STDOUT/STDIN of the child process. |
7849 | 9561 | In the child process, the filehandle isn't opened--I/O happens from/to |
7850 | 9562 | the new STDOUT/STDIN. Typically this is used like the normal |
7851 | 9563 | piped open when you want to exercise more control over just how the |
7852 | 9564 | pipe command gets executed, such as when running setuid and |
7853 | 9565 | you don't want to have to scan shell commands for metacharacters. |
7854 | 9566 | |
7855 | 9567 | =end original |
7856 | 9568 | |
7857 | 親プロセスでは、このファイルハンドルは | |
9569 | 親プロセスでは、このファイルハンドルは通常通りに動作しますが、行なわれる | |
7858 | ||
9570 | 入出力は、子プロセスの STDIN/STDOUT にパイプされます。 | |
7859 | ||
9571 | 子プロセス側では、そのファイルハンドルは開かれず、入出力は新しい STDOUT か | |
7860 | ||
9572 | STDIN に対して行なわれます。 | |
7861 | オープンされず、入出力は新しい STDOUT か STDIN に対して行なわれます。 | |
7862 | 9573 | これは、setuid で実行して、シェルコマンドのメタ文字を |
7863 | 9574 | 検索させたくないような場合に、パイプコマンドの起動の仕方を |
7864 | 9575 | 制御したいとき、普通のパイプの open と同じように使います。 |
7865 | 9576 | |
7866 | 9577 | =begin original |
7867 | 9578 | |
7868 | 9579 | The following blocks are more or less equivalent: |
7869 | 9580 | |
7870 | 9581 | =end original |
7871 | 9582 | |
7872 | 9583 | 以下の組み合わせは、だいたい同じものです: |
7873 | 9584 | |
7874 | open( | |
9585 | open(my $fh, "|tr '[a-z]' '[A-Z]'"); | |
7875 | open( | |
9586 | open(my $fh, "|-", "tr '[a-z]' '[A-Z]'"); | |
7876 | open( | |
9587 | open(my $fh, "|-") || exec 'tr', '[a-z]', '[A-Z]'; | |
7877 | open( | |
9588 | open(my $fh, "|-", "tr", '[a-z]', '[A-Z]'); | |
7878 | 9589 | |
7879 | open( | |
9590 | open(my $fh, "cat -n '$file'|"); | |
7880 | open( | |
9591 | open(my $fh, "-|", "cat -n '$file'"); | |
7881 | open( | |
9592 | open(my $fh, "-|") || exec "cat", "-n", $file; | |
7882 | open( | |
9593 | open(my $fh, "-|", "cat", "-n", $file); | |
7883 | 9594 | |
7884 | 9595 | =begin original |
7885 | 9596 | |
7886 | 9597 | The last two examples in each block show the pipe as "list form", which is |
7887 | 9598 | not yet supported on all platforms. A good rule of thumb is that if |
7888 | your platform has a real C<fork | |
9599 | your platform has a real L<C<fork>|/fork> (in other words, if your platform is | |
7889 | Unix, including Linux and MacOS X), you can use the list form. You would | |
9600 | Unix, including Linux and MacOS X), you can use the list form. You would | |
7890 | 9601 | want to use the list form of the pipe so you can pass literal arguments |
7891 | 9602 | to the command without risk of the shell interpreting any shell metacharacters |
7892 | 9603 | in them. However, this also bars you from opening pipes to commands |
7893 | 9604 | that intentionally contain shell metacharacters, such as: |
7894 | 9605 | |
7895 | 9606 | =end original |
7896 | 9607 | |
7897 | 9608 | それぞれのブロックの末尾二つの例ではパイプを「リスト形式」にしていますが、 |
7898 | 9609 | これはまだ全てのプラットフォームで対応しているわけではなりません。 |
7899 | よい経験則としては、もし実行しているプラットフォームで本当の | |
9610 | よい経験則としては、もし実行しているプラットフォームで本当の | |
7900 | あれば(言い換えると、プラットフォームが Linux や | |
9611 | L<C<fork>|/fork> があれば(言い換えると、プラットフォームが Linux や | |
7901 | リスト形式が使えます。 | |
9612 | MacOS X を含む Unix なら)リスト形式が使えます。 | |
7902 | 9613 | パイプのリスト形式を使うことで、コマンドへのリテラルな引数を、 |
7903 | 9614 | シェルのメタ文字をシェルが解釈するリスクなしに渡すことができます。 |
7904 | 9615 | しかし、これは以下のように意図的にシェルメタ文字を含むコマンドをパイプとして |
7905 | 9616 | 開くことを妨げます: |
7906 | 9617 | |
7907 | open( | |
9618 | open(my $fh, "|cat -n | expand -4 | lpr") | |
7908 | | |
9619 | || die "Can't open pipeline to lpr: $!"; | |
7909 | 9620 | |
7910 | 9621 | =begin original |
7911 | 9622 | |
7912 | 9623 | See L<perlipc/"Safe Pipe Opens"> for more examples of this. |
7913 | 9624 | |
7914 | 9625 | =end original |
7915 | 9626 | |
7916 | これに関する更なる例については L<perlipc/"Safe Pipe Opens"> を | |
9627 | これに関する更なる例については L<perlipc/"Safe Pipe Opens"> を | |
9628 | 参照してください。 | |
7917 | 9629 | |
7918 | 9630 | =begin original |
7919 | 9631 | |
7920 | ||
9632 | Perl will attempt to flush all files opened for | |
7921 | 9633 | output before any operation that may do a fork, but this may not be |
7922 | 9634 | supported on some platforms (see L<perlport>). To be safe, you may need |
7923 | to set C<$|> ($AUTOFLUSH in English | |
9635 | to set L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>) | |
7924 | of C<IO::Handle> | |
9636 | or call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS> | |
9637 | on any open handles. | |
7925 | 9638 | |
7926 | 9639 | =end original |
7927 | 9640 | |
7928 | 9641 | v5.6.0 から、Perl は書き込み用に開いている全てのファイルに対して |
7929 | 9642 | fork を行う前にフラッシュしようとしますが、これに対応していない |
7930 | 9643 | プラットフォームもあります(L<perlport> を参照してください)。 |
7931 | 安全のために、C<$|> (English モジュールでは | |
9644 | 安全のために、L<C<$E<verbar>>|perlvar/$E<verbar>> (L<English> モジュールでは | |
7932 | 全ての開いているハンドルに対して | |
9645 | C<$AUTOFLUSH>) をセットするか、全ての開いているハンドルに対して | |
9646 | L<C<IO::Handle>|IO::Handle/METHODS> の C<autoflush> メソッドを | |
7933 | 9647 | 呼び出す必要があるかもしれません。 |
7934 | 9648 | |
7935 | 9649 | =begin original |
7936 | 9650 | |
7937 | 9651 | On systems that support a close-on-exec flag on files, the flag will |
7938 | 9652 | be set for the newly opened file descriptor as determined by the value |
7939 | of C<$^F>. See L<perlvar/$^F>. | |
9653 | of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>. | |
7940 | 9654 | |
7941 | 9655 | =end original |
7942 | 9656 | |
7943 | 9657 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
7944 | フラグは C<$^F> の値で決定される、新しくオープンされた | |
9658 | フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた | |
7945 | セットされます。 | |
9659 | ファイル記述子に対してセットされます。 | |
7946 | 9660 | L<perlvar/$^F> を参照してください。 |
7947 | 9661 | |
7948 | 9662 | =begin original |
7949 | 9663 | |
7950 | 9664 | Closing any piped filehandle causes the parent process to wait for the |
7951 | child to finish, then returns the status value in C<$?> and | |
9665 | child to finish, then returns the status value in L<C<$?>|perlvar/$?> and | |
7952 | C<${^CHILD_ERROR_NATIVE}>. | |
9666 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>. | |
7953 | 9667 | |
7954 | 9668 | =end original |
7955 | 9669 | |
7956 | パイプのファイルハンドルを close することで、 | |
9670 | パイプのファイルハンドルを close することで、親プロセスは、子プロセスの終了を | |
7957 | ||
9671 | 待ち、それから L<C<$?>|perlvar/$?> と | |
7958 | C<${^CHILD_ERROR_NATIVE}> にステータス値を | |
9672 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> にステータス値を | |
9673 | 返します。 | |
7959 | 9674 | |
7960 | 9675 | =begin original |
7961 | 9676 | |
7962 | The filename passed to the one- and two-argument forms of | |
9677 | The filename passed to the one- and two-argument forms of | |
9678 | L<C<open>|/open FILEHANDLE,EXPR> will | |
7963 | 9679 | have leading and trailing whitespace deleted and normal |
7964 | 9680 | redirection characters honored. This property, known as "magic open", |
7965 | 9681 | can often be used to good effect. A user could specify a filename of |
7966 | 9682 | F<"rsh cat file |">, or you could change certain filenames as needed: |
7967 | 9683 | |
7968 | 9684 | =end original |
7969 | 9685 | |
7970 | 1 引数 と 2 引数の形の open | |
9686 | 1 引数 と 2 引数の形の L<C<open>|/open FILEHANDLE,EXPR> に渡された | |
7971 | はじめと終わりの空白が取り除かれ、 | |
9687 | ファイル名は、はじめと終わりの空白が取り除かれ、通常のリダイレクト文字列を | |
7972 | ||
9688 | 受け付けます。 | |
7973 | この機能は "magic open" として知られていますが、 | |
9689 | この機能は "magic open" として知られていますが、普通いい効果をもたらします。 | |
7974 | 普通いい効果をもたらします。 | |
7975 | 9690 | ユーザーは F<"rsh cat file |"> といったファイル名を指定できますし、 |
7976 | 9691 | 特定のファイル名を必要に応じて変更できます。 |
7977 | 9692 | |
7978 | 9693 | $filename =~ s/(.*\.gz)\s*$/gzip -dc < $1|/; |
7979 | open( | |
9694 | open(my $fh, $filename) or die "Can't open $filename: $!"; | |
7980 | 9695 | |
7981 | 9696 | =begin original |
7982 | 9697 | |
7983 | 9698 | Use the three-argument form to open a file with arbitrary weird characters in it, |
7984 | 9699 | |
7985 | 9700 | =end original |
7986 | 9701 | |
7987 | 9702 | 妙な文字が含まれているようなファイル名をオープンするには、 |
7988 | 9703 | 3 引数の形を使います。 |
7989 | 9704 | |
7990 | open( | |
9705 | open(my $fh, "<", $file) | |
7991 | || die " | |
9706 | || die "Can't open $file: $!"; | |
7992 | 9707 | |
7993 | 9708 | =begin original |
7994 | 9709 | |
7995 | 9710 | otherwise it's necessary to protect any leading and trailing whitespace: |
7996 | 9711 | |
7997 | 9712 | =end original |
7998 | 9713 | |
7999 | 9714 | あるいは、次のようにして、最初と最後の空白を保護します: |
8000 | 9715 | |
8001 | 9716 | $file =~ s#^(\s)#./$1#; |
8002 | open( | |
9717 | open(my $fh, "< $file\0") | |
8003 | || die "open f | |
9718 | || die "Can't open $file: $!"; | |
8004 | 9719 | |
8005 | 9720 | =begin original |
8006 | 9721 | |
8007 | 9722 | (this may not work on some bizarre filesystems). One should |
8008 | 9723 | conscientiously choose between the I<magic> and I<three-argument> form |
8009 | of open | |
9724 | of L<C<open>|/open FILEHANDLE,EXPR>: | |
8010 | 9725 | |
8011 | 9726 | =end original |
8012 | 9727 | |
8013 | 9728 | (これは奇妙なファイルシステムでは動作しないかもしれません)。 |
8014 | open | |
9729 | L<C<open>|/open FILEHANDLE,EXPR> の I<magic> と I<3 引数> 形式を誠実に | |
9730 | 選択するべきです。 | |
8015 | 9731 | |
8016 | open( | |
9732 | open(my $in, $ARGV[0]) || die "Can't open $ARGV[0]: $!"; | |
8017 | 9733 | |
8018 | 9734 | =begin original |
8019 | 9735 | |
8020 | 9736 | will allow the user to specify an argument of the form C<"rsh cat file |">, |
8021 | 9737 | but will not work on a filename that happens to have a trailing space, while |
8022 | 9738 | |
8023 | 9739 | =end original |
8024 | 9740 | |
8025 | 9741 | とするとユーザーは C<"rsh cat file |"> という形の引数を指定できますが、 |
8026 | 末尾にスペースがついてしまったファイル名では動作しません | |
9742 | 末尾にスペースがついてしまったファイル名では動作しません; 一方: | |
8027 | 9743 | |
8028 | open( | |
9744 | open(my $in, "<", $ARGV[0]) | |
8029 | || die " | |
9745 | || die "Can't open $ARGV[0]: $!"; | |
8030 | 9746 | |
8031 | 9747 | =begin original |
8032 | 9748 | |
8033 | will have exactly the opposite restrictions. | |
9749 | will have exactly the opposite restrictions. (However, some shells | |
9750 | support the syntax C<< perl your_program.pl <( rsh cat file ) >>, which | |
9751 | produces a filename that can be opened normally.) | |
8034 | 9752 | |
8035 | 9753 | =end original |
8036 | 9754 | |
8037 | 9755 | はまったく逆の制限があります。 |
9756 | (しかし、一部のシェルは C<< perl your_program.pl <( rsh cat file ) >> という | |
9757 | 文法に対応していて、普通に開くことが出来るファイル名を出力します。) | |
8038 | 9758 | |
8039 | 9759 | =begin original |
8040 | 9760 | |
8041 | If you want a "real" C | |
9761 | If you want a "real" C L<open(2)>, then you should use the | |
8042 | s | |
9762 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> function, which involves | |
8043 | ||
9763 | no such magic (but uses different filemodes than Perl | |
8044 | ||
9764 | L<C<open>|/open FILEHANDLE,EXPR>, which corresponds to C L<fopen(3)>). | |
8045 | interpretation. For | |
9765 | This is another way to protect your filenames from interpretation. For | |
9766 | example: | |
8046 | 9767 | |
8047 | 9768 | =end original |
8048 | 9769 | |
8049 | もし「本当の」C 言語の | |
9770 | もし「本当の」C 言語の L<open(2)> が必要なら、このような副作用のない | |
8050 | ||
9771 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> 関数を使うべきです | |
8051 | (ただし、C の fopen() に | |
9772 | (ただし、C の L<fopen(3)> に対応する Perl の | |
8052 | ||
9773 | L<C<open>|/open FILEHANDLE,EXPR> とは違うファイルモードを持ちます)。 | |
8053 | 9774 | これはファイル名を解釈から守るもう一つの方法です。 |
8054 | 9775 | 例えば: |
8055 | 9776 | |
8056 | 9777 | use IO::Handle; |
8057 | sysopen( | |
9778 | sysopen(my $fh, $path, O_RDWR|O_CREAT|O_EXCL) | |
8058 | or die " | |
9779 | or die "Can't open $path: $!"; | |
8059 | $ | |
9780 | $fh->autoflush(1); | |
8060 | print | |
9781 | print $fh "stuff $$\n"; | |
8061 | seek( | |
9782 | seek($fh, 0, 0); | |
8062 | print "File contains: ", | |
9783 | print "File contains: ", readline($fh); | |
8063 | 9784 | |
8064 | 9785 | =begin original |
8065 | 9786 | |
8066 | ||
9787 | See L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> for some details about | |
8067 | ||
9788 | mixing reading and writing. | |
8068 | filehandles that have the scope of the variables used to hold them, then | |
8069 | automatically (but silently) close once their reference counts become | |
8070 | zero, typically at scope exit: | |
8071 | 9789 | |
8072 | 9790 | =end original |
8073 | 9791 | |
8074 | ||
9792 | 読み書きを混ぜる場合の詳細については | |
8075 | ||
9793 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> を参照してください。 | |
8076 | これらへのリファレンスを保持している変数のスコープを持ち、それから | |
8077 | 参照カウントが 0 になると自動的に (しかし暗黙に) 閉じる | |
8078 | 無名ファイルハンドルを作成できます: | |
8079 | 9794 | |
8080 | use IO::File; | |
8081 | #... | |
8082 | sub read_myfile_munged { | |
8083 | my $ALL = shift; | |
8084 | # or just leave it undef to autoviv | |
8085 | my $handle = IO::File->new; | |
8086 | open($handle, "<", "myfile") or die "myfile: $!"; | |
8087 | $first = <$handle> | |
8088 | or return (); # Automatically closed here. | |
8089 | mung($first) or die "mung failed"; # Or here. | |
8090 | return (first, <$handle>) if $ALL; # Or here. | |
8091 | return $first; # Or here. | |
8092 | } | |
8093 | ||
8094 | 9795 | =begin original |
8095 | 9796 | |
8096 | ||
9797 | Portability issues: L<perlport/open>. | |
8097 | close that happens when the refcount on C<handle> does not | |
8098 | properly detect and report failures. I<Always> close the handle | |
8099 | yourself and inspect the return value. | |
8100 | 9798 | |
8101 | 9799 | =end original |
8102 | 9800 | |
8103 | ||
9801 | 移植性の問題: L<perlport/open>。 | |
8104 | ときに失敗が報告されるのでバグがあります。 | |
8105 | I<常に> ハンドルを自分自身で閉じて、返り値を調べてください。 | |
8106 | 9802 | |
8107 | close($handle) | |
8108 | || warn "close failed: $!"; | |
8109 | ||
8110 | =begin original | |
8111 | ||
8112 | See L</seek> for some details about mixing reading and writing. | |
8113 | ||
8114 | =end original | |
8115 | ||
8116 | 読み書きを混ぜる場合の詳細については L</seek> を参照して下さい。 | |
8117 | ||
8118 | 9803 | =item opendir DIRHANDLE,EXPR |
8119 | 9804 | X<opendir> |
8120 | 9805 | |
9806 | =for Pod::Functions open a directory | |
9807 | ||
8121 | 9808 | =begin original |
8122 | 9809 | |
8123 | Opens a directory named EXPR for processing by | |
9810 | Opens a directory named EXPR for processing by | |
8124 | C< | |
9811 | L<C<readdir>|/readdir DIRHANDLE>, L<C<telldir>|/telldir DIRHANDLE>, | |
9812 | L<C<seekdir>|/seekdir DIRHANDLE,POS>, | |
9813 | L<C<rewinddir>|/rewinddir DIRHANDLE>, and | |
9814 | L<C<closedir>|/closedir DIRHANDLE>. Returns true if successful. | |
8125 | 9815 | DIRHANDLE may be an expression whose value can be used as an indirect |
8126 | 9816 | dirhandle, usually the real dirhandle name. If DIRHANDLE is an undefined |
8127 | 9817 | scalar variable (or array or hash element), the variable is assigned a |
8128 | 9818 | reference to a new anonymous dirhandle; that is, it's autovivified. |
8129 | 9819 | DIRHANDLEs have their own namespace separate from FILEHANDLEs. |
8130 | 9820 | |
8131 | 9821 | =end original |
8132 | 9822 | |
8133 | C<readdir> | |
9823 | L<C<readdir>|/readdir DIRHANDLE>、L<C<telldir>|/telldir DIRHANDLE>、 | |
8134 | ||
9824 | L<C<seekdir>|/seekdir DIRHANDLE,POS>、L<C<rewinddir>|/rewinddir DIRHANDLE>、 | |
9825 | L<C<closedir>|/closedir DIRHANDLE> で処理するために、EXPR で指定された名前の | |
9826 | ディレクトリをオープンします。 | |
8135 | 9827 | 成功時には真を返します。 |
8136 | 9828 | DIRHANDLE は間接ディレクトリハンドルとして使える値(普通は実際のディレクトリ |
8137 | 9829 | ハンドルの名前)となる式でも構いません。 |
8138 | 9830 | DIRHANDLE が未定義のスカラ値(または配列かハッシュの要素)の場合、その変数は |
8139 | 9831 | 新しい無名ディレクトリハンドルへのリファレンスが代入されます; つまり、 |
8140 | 9832 | 自動有効化されます。 |
8141 | 9833 | DIRHANDLE は、FILEHANDLE とは別に名前空間を持っています。 |
8142 | 9834 | |
8143 | 9835 | =begin original |
8144 | 9836 | |
8145 | See the example at C<readdir>. | |
9837 | See the example at L<C<readdir>|/readdir DIRHANDLE>. | |
8146 | 9838 | |
8147 | 9839 | =end original |
8148 | 9840 | |
8149 | C<readdir> の例を参照してください。 | |
9841 | L<C<readdir>|/readdir DIRHANDLE> の例を参照してください。 | |
8150 | 9842 | |
8151 | 9843 | =item ord EXPR |
8152 | 9844 | X<ord> X<encoding> |
8153 | 9845 | |
8154 | 9846 | =item ord |
8155 | 9847 | |
9848 | =for Pod::Functions find a character's numeric representation | |
9849 | ||
8156 | 9850 | =begin original |
8157 | 9851 | |
8158 | Returns the numeric | |
9852 | Returns the numeric value of the first character of EXPR. | |
8159 | ||
9853 | If EXPR is an empty string, returns 0. If EXPR is omitted, uses | |
8160 | ||
9854 | L<C<$_>|perlvar/$_>. | |
8161 | 9855 | (Note I<character>, not byte.) |
8162 | 9856 | |
8163 | 9857 | =end original |
8164 | 9858 | |
8165 | EXPR の最初の文字の数値としての | |
9859 | EXPR の最初の文字の数値としての値を返します。 | |
8166 | ネイティブエンコーディングの)値を返します。 | |
8167 | 9860 | EXPR が空文字列の場合は、0 を返します。 |
8168 | EXPR | |
9861 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
8169 | 9862 | (バイトではなく I<文字> であることに注意してください。) |
8170 | 9863 | |
8171 | 9864 | =begin original |
8172 | 9865 | |
8173 | For the reverse, see L</chr>. | |
9866 | For the reverse, see L<C<chr>|/chr NUMBER>. | |
8174 | 9867 | See L<perlunicode> for more about Unicode. |
8175 | 9868 | |
8176 | 9869 | =end original |
8177 | 9870 | |
8178 | 逆のことをするには L</chr> を参照してください。 | |
9871 | 逆のことをするには L<C<chr>|/chr NUMBER> を参照してください。 | |
8179 | 9872 | Unicode については L<perlunicode> を参照してください。 |
8180 | 9873 | |
8181 | =item our | |
9874 | =item our VARLIST | |
8182 | 9875 | X<our> X<global> |
8183 | 9876 | |
8184 | =item our TYPE | |
9877 | =item our TYPE VARLIST | |
8185 | 9878 | |
8186 | =item our | |
9879 | =item our VARLIST : ATTRS | |
8187 | 9880 | |
8188 | =item our TYPE | |
9881 | =item our TYPE VARLIST : ATTRS | |
8189 | 9882 | |
9883 | =for Pod::Functions +5.6.0 declare and assign a package variable (lexical scoping) | |
9884 | ||
8190 | 9885 | =begin original |
8191 | 9886 | |
8192 | C<our> a | |
9887 | L<C<our>|/our VARLIST> makes a lexical alias to a package (i.e. global) | |
8193 | ||
9888 | variable of the same name in the current package for use within the | |
8194 | ||
9889 | current lexical scope. | |
8195 | them with package names, within the lexical scope of the C<our> declaration. | |
8196 | In this way C<our> differs from C<use vars>, which is package-scoped. | |
8197 | 9890 | |
8198 | 9891 | =end original |
8199 | 9892 | |
8200 | C<our> は単純名を、現在のスコープ内で使うために、 | |
9893 | L<C<our>|/our VARLIST> は単純名を、現在のレキシカルスコープ内で使うために、 | |
8201 | パッケージ変数 | |
9894 | 現在のパッケージの同じ名前のパッケージ(つまりグローバルな)変数への | |
8202 | ||
9895 | レキシカルな別名を作ります。 | |
8203 | レキシカルスコープ内で、宣言されたグローバル変数をパッケージ名で | |
8204 | 修飾することなく使うことができます。 | |
8205 | この意味では、C<use vars> はパッケージスコープなので、C<our> とは異なります。 | |
8206 | 9896 | |
8207 | 9897 | =begin original |
8208 | 9898 | |
8209 | ||
9899 | L<C<our>|/our VARLIST> has the same scoping rules as | |
8210 | ||
9900 | L<C<my>|/my VARLIST> or L<C<state>|/state VARLIST>, meaning that it is | |
8211 | ||
9901 | only valid within a lexical scope. Unlike L<C<my>|/my VARLIST> and | |
8212 | ||
9902 | L<C<state>|/state VARLIST>, which both declare new (lexical) variables, | |
8213 | ||
9903 | L<C<our>|/our VARLIST> only creates an alias to an existing variable: a | |
8214 | ||
9904 | package variable of the same name. | |
8215 | 9905 | |
8216 | 9906 | =end original |
8217 | 9907 | |
8218 | ||
9908 | L<C<our>|/our VARLIST> は L<C<my>|/my VARLIST> や | |
8219 | ||
9909 | L<C<state>|/state VARLIST> と同じスコープルールを持ちます; つまり | |
8220 | スコープ | |
9910 | レキシカルスコープの中でだけ有効です。 | |
8221 | 変数 | |
9911 | 新しい(レキシカル)変数を宣言する L<C<my>|/my VARLIST> や | |
8222 | ||
9912 | L<C<state>|/state VARLIST> と異なり、L<C<our>|/our VARLIST> は既に | |
8223 | 変数を作る | |
9913 | 存在する変数への別名を作るだけです: 同じ名前のパッケージ変数です。 | |
8224 | 9914 | |
8225 | 9915 | =begin original |
8226 | 9916 | |
8227 | ||
9917 | This means that when C<use strict 'vars'> is in effect, L<C<our>|/our | |
9918 | VARLIST> lets you use a package variable without qualifying it with the | |
9919 | package name, but only within the lexical scope of the | |
9920 | L<C<our>|/our VARLIST> declaration. This applies immediately--even | |
9921 | within the same statement. | |
9922 | ||
9923 | =end original | |
9924 | ||
9925 | つまり、C<use strict 'vars'> が有効の場合は、L<C<our>|/our VARLIST> を | |
9926 | 使うことで、 | |
9927 | パッケージ変数をパッケージ名で修飾することなく使うことができますが、 | |
9928 | L<C<our>|/our VARLIST> 宣言のレキシカルスコープ内だけということです。 | |
9929 | これは(たとえ同じ文の中でも)直ちに適用されます。 | |
9930 | ||
9931 | package Foo; | |
9932 | use strict; | |
9933 | ||
9934 | $Foo::foo = 23; | |
9935 | ||
9936 | { | |
9937 | our $foo; # alias to $Foo::foo | |
9938 | print $foo; # prints 23 | |
9939 | } | |
9940 | ||
9941 | print $Foo::foo; # prints 23 | |
9942 | ||
9943 | print $foo; # ERROR: requires explicit package name | |
9944 | ||
9945 | =begin original | |
9946 | ||
9947 | This works even if the package variable has not been used before, as | |
9948 | package variables spring into existence when first used. | |
9949 | ||
9950 | =end original | |
9951 | ||
9952 | これはパッケージ変数がまだ使われていなくても動作します; パッケージ変数は、 | |
9953 | 最初に使われた時にひょっこり現れるからです。 | |
9954 | ||
9955 | package Foo; | |
9956 | use strict; | |
9957 | ||
9958 | our $foo = 23; # just like $Foo::foo = 23 | |
9959 | ||
9960 | print $Foo::foo; # prints 23 | |
9961 | ||
9962 | =begin original | |
9963 | ||
9964 | Because the variable becomes legal immediately under C<use strict 'vars'>, so | |
9965 | long as there is no variable with that name is already in scope, you can then | |
9966 | reference the package variable again even within the same statement. | |
9967 | ||
9968 | =end original | |
9969 | ||
9970 | 変数は C<use strict 'vars'> の基で直ちに正当になるので、 | |
9971 | スコープ内に同じ名前の変数がない限り、 | |
9972 | たとえ同じ文の中でもパッケージ変数を再び参照できます。 | |
9973 | ||
9974 | package Foo; | |
9975 | use strict; | |
9976 | ||
9977 | my $foo = $foo; # error, undeclared $foo on right-hand side | |
9978 | our $foo = $foo; # no errors | |
9979 | ||
9980 | =begin original | |
9981 | ||
9982 | If more than one variable is listed, the list must be placed | |
8228 | 9983 | in parentheses. |
8229 | 9984 | |
8230 | 9985 | =end original |
8231 | 9986 | |
8232 | ||
9987 | 複数の変数を指定する場合は、リストはかっこでくくらなければなりません。 | |
8233 | 9988 | |
8234 | our $foo; | |
8235 | 9989 | our($bar, $baz); |
8236 | 9990 | |
8237 | 9991 | =begin original |
8238 | 9992 | |
8239 | An C<our> declaration declares a | |
9993 | An L<C<our>|/our VARLIST> declaration declares an alias for a package | |
9994 | variable that will be visible | |
8240 | 9995 | across its entire lexical scope, even across package boundaries. The |
8241 | 9996 | package in which the variable is entered is determined at the point |
8242 | 9997 | of the declaration, not at the point of use. This means the following |
8243 | 9998 | behavior holds: |
8244 | 9999 | |
8245 | 10000 | =end original |
8246 | 10001 | |
8247 | C<our> 宣言はレキシカルスコープ全体に対して(たとえ | |
10002 | L<C<our>|/our VARLIST> 宣言はレキシカルスコープ全体に対して (たとえ | |
8248 | 越えていても)見える | |
10003 | パッケージ境界を越えていても)見える、パッケージ変数への別名を宣言します。 | |
8249 | 10004 | この変数が入るパッケージは宣言した時点で定義され、 |
8250 | 10005 | 使用した時点ではありません。 |
8251 | 10006 | これにより、以下のような振る舞いになります: |
8252 | 10007 | |
8253 | 10008 | package Foo; |
8254 | 10009 | our $bar; # declares $Foo::bar for rest of lexical scope |
8255 | 10010 | $bar = 20; |
8256 | 10011 | |
8257 | 10012 | package Bar; |
8258 | 10013 | print $bar; # prints 20, as it refers to $Foo::bar |
8259 | 10014 | |
8260 | 10015 | =begin original |
8261 | 10016 | |
8262 | Multiple C<our> declarations with the same name in the | |
10017 | Multiple L<C<our>|/our VARLIST> declarations with the same name in the | |
10018 | same lexical | |
8263 | 10019 | scope are allowed if they are in different packages. If they happen |
8264 | 10020 | to be in the same package, Perl will emit warnings if you have asked |
8265 | for them, just like multiple C<my> declarations. Unlike | |
10021 | for them, just like multiple L<C<my>|/my VARLIST> declarations. Unlike | |
8266 | C<my> declaration, which will bind the name to | |
10022 | a second L<C<my>|/my VARLIST> declaration, which will bind the name to a | |
8267 | second C<our> declaration in the same | |
10023 | fresh variable, a second L<C<our>|/our VARLIST> declaration in the same | |
8268 | merely redundant. | |
10024 | package, in the same scope, is merely redundant. | |
8269 | 10025 | |
8270 | 10026 | =end original |
8271 | 10027 | |
8272 | 10028 | 同じレキシカルスコープでも、パッケージが異なっていれば、同じ名前で複数の |
8273 | C<our> 宣言ができます。 | |
10029 | L<C<our>|/our VARLIST> 宣言ができます。 | |
8274 | 10030 | 同じパッケージになっていると、警告が出力されるようになっていれば |
8275 | 複数の C<my> 宣言がある場合と同じように警告が出力されます。 | |
10031 | 複数の L<C<my>|/my VARLIST> 宣言がある場合と同じように警告が出力されます。 | |
8276 | 新しい変数を名前に割り当てることになる 2 回目の C<my> 宣言と | |
10032 | 新しい変数を名前に割り当てることになる 2 回目の L<C<my>|/my VARLIST> 宣言と | |
8277 | 同じパッケージの同じスコープで 2 回 | |
10033 | 違って、同じパッケージの同じスコープで 2 回 | |
10034 | L<C<our>|/our VARLIST> 宣言するのは単に冗長です。 | |
8278 | 10035 | |
8279 | 10036 | use warnings; |
8280 | 10037 | package Foo; |
8281 | 10038 | our $bar; # declares $Foo::bar for rest of lexical scope |
8282 | 10039 | $bar = 20; |
8283 | 10040 | |
8284 | 10041 | package Bar; |
8285 | 10042 | our $bar = 30; # declares $Bar::bar for rest of lexical scope |
8286 | 10043 | print $bar; # prints 30 |
8287 | 10044 | |
8288 | 10045 | our $bar; # emits warning but has no other effect |
8289 | 10046 | print $bar; # still prints 30 |
8290 | 10047 | |
8291 | 10048 | =begin original |
8292 | 10049 | |
8293 | An C<our> declaration may also have a list of attributes | |
10050 | An L<C<our>|/our VARLIST> declaration may also have a list of attributes | |
8294 | with it. | |
10051 | associated with it. | |
8295 | 10052 | |
8296 | 10053 | =end original |
8297 | 10054 | |
8298 | C<our> 宣言には、それと結び付けられる属性のリストを | |
10055 | L<C<our>|/our VARLIST> 宣言には、それと結び付けられる属性のリストを | |
10056 | 持つこともあります。 | |
8299 | 10057 | |
8300 | 10058 | =begin original |
8301 | 10059 | |
8302 | 10060 | The exact semantics and interface of TYPE and ATTRS are still |
8303 | evolving. TYPE is currently bound to the use of | |
10061 | evolving. TYPE is currently bound to the use of the L<fields> pragma, | |
8304 | and attributes are handled using the | |
10062 | and attributes are handled using the L<attributes> pragma, or, starting | |
8305 | from Perl 5.8.0 also via the | |
10063 | from Perl 5.8.0, also via the L<Attribute::Handlers> module. See | |
8306 | L<perlsub/"Private Variables via my()"> for details | |
10064 | L<perlsub/"Private Variables via my()"> for details. | |
8307 | L<attributes>, and L<Attribute::Handlers>. | |
8308 | 10065 | |
8309 | 10066 | =end original |
8310 | 10067 | |
8311 | 10068 | TYPE と ATTRS の正確な文法とインターフェースは今でも進化しています。 |
8312 | 現在のところ、TYPE は | |
10069 | 現在のところ、TYPE は L<fields> プラグマの使用と結び付けられていて、 | |
8313 | 属性は | |
10070 | 属性は L<attributes> プラグマか、Perl 5.8.0 からは | |
8314 | ||
10071 | L<Attribute::Handlers> モジュールと結び付けられています。 | |
8315 | 詳しくはL<perlsub/"Private Variables via my()"> | |
10072 | 詳しくは L<perlsub/"Private Variables via my()"> を参照してください。 | |
8316 | L<attributes>, L<Attribute::Handlers> を参照してください。 | |
8317 | 10073 | |
10074 | =begin original | |
10075 | ||
10076 | Note that with a parenthesised list, L<C<undef>|/undef EXPR> can be used | |
10077 | as a dummy placeholder, for example to skip assignment of initial | |
10078 | values: | |
10079 | ||
10080 | =end original | |
10081 | ||
10082 | かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> は、例えば初期値の代入を | |
10083 | 飛ばすために、ダミーのプレースホルダとして使えることに注意してください: | |
10084 | ||
10085 | our ( undef, $min, $hour ) = localtime; | |
10086 | ||
10087 | =begin original | |
10088 | ||
10089 | L<C<our>|/our VARLIST> differs from L<C<use vars>|vars>, which allows | |
10090 | use of an unqualified name I<only> within the affected package, but | |
10091 | across scopes. | |
10092 | ||
10093 | =end original | |
10094 | ||
10095 | L<C<our>|/our VARLIST> は L<C<use vars>|vars> と異なります; スコープを | |
10096 | またぐのではなく、影響するパッケージの内側 I<のみ> で完全修飾されていない | |
10097 | 名前を使えるようにします。 | |
10098 | ||
8318 | 10099 | =item pack TEMPLATE,LIST |
8319 | 10100 | X<pack> |
8320 | 10101 | |
10102 | =for Pod::Functions convert a list into a binary representation | |
10103 | ||
8321 | 10104 | =begin original |
8322 | 10105 | |
8323 | 10106 | Takes a LIST of values and converts it into a string using the rules |
8324 | 10107 | given by the TEMPLATE. The resulting string is the concatenation of |
8325 | 10108 | the converted values. Typically, each converted value looks |
8326 | 10109 | like its machine-level representation. For example, on 32-bit machines |
8327 | 10110 | an integer may be represented by a sequence of 4 bytes, which will in |
8328 | Perl be presented as a string that's 4 characters long. | |
10111 | Perl be presented as a string that's 4 characters long. | |
8329 | 10112 | |
8330 | 10113 | =end original |
8331 | 10114 | |
8332 | 10115 | LIST の値を TEMPLATE で与えられたルールを用いて文字列に変換します。 |
8333 | 10116 | 結果の文字列は変換した値を連結したものです。 |
8334 | 10117 | 典型的には、それぞれの変換された値はマシンレベルの表現のように見えます。 |
8335 | 10118 | 例えば、32-bit マシンでは、整数は 4 バイトで表現されるので、 |
8336 | 10119 | Perl では 4 文字の文字列で表現されます。 |
8337 | 10120 | |
8338 | 10121 | =begin original |
8339 | 10122 | |
8340 | 10123 | See L<perlpacktut> for an introduction to this function. |
8341 | 10124 | |
8342 | 10125 | =end original |
8343 | 10126 | |
8344 | 10127 | この関数の説明については L<perlpacktut> を参照してください。 |
8345 | 10128 | |
8346 | 10129 | =begin original |
8347 | 10130 | |
8348 | 10131 | The TEMPLATE is a sequence of characters that give the order and type |
8349 | 10132 | of values, as follows: |
8350 | 10133 | |
8351 | 10134 | =end original |
8352 | 10135 | |
8353 | 10136 | TEMPLATE は、以下のような値の型と順番を指定する文字を並べたものです: |
8354 | 10137 | |
8355 | 10138 | =begin original |
8356 | 10139 | |
8357 | 10140 | a A string with arbitrary binary data, will be null padded. |
8358 | 10141 | A A text (ASCII) string, will be space padded. |
8359 | 10142 | Z A null-terminated (ASCIZ) string, will be null padded. |
8360 | 10143 | |
8361 | 10144 | =end original |
8362 | 10145 | |
8363 | a | |
10146 | a 任意のバイナリデータを含む文字列、ヌル文字で埋める。 | |
8364 | A | |
10147 | A テキスト (ASCII) 文字列、スペース文字で埋める。 | |
8365 | Z | |
10148 | Z ヌル文字終端 (ASCIZ) 文字列、ヌル文字で埋める。 | |
8366 | 10149 | |
8367 | 10150 | =begin original |
8368 | 10151 | |
8369 | b A bit string (ascending bit order inside each byte, | |
10152 | b A bit string (ascending bit order inside each byte, | |
10153 | like vec()). | |
8370 | 10154 | B A bit string (descending bit order inside each byte). |
8371 | 10155 | h A hex string (low nybble first). |
8372 | 10156 | H A hex string (high nybble first). |
8373 | 10157 | |
8374 | 10158 | =end original |
8375 | 10159 | |
8376 | b | |
10160 | b ビット列 (バイトごとに昇ビット順、vec() と同じ)。 | |
8377 | B | |
10161 | B ビット列 (バイトごとに降ビット順)。 | |
8378 | h | |
10162 | h 16 進数文字列 (低位ニブルが先)。 | |
8379 | H | |
10163 | H 16 進数文字列 (高位ニブルが先)。 | |
8380 | 10164 | |
8381 | 10165 | =begin original |
8382 | 10166 | |
8383 | 10167 | c A signed char (8-bit) value. |
8384 | 10168 | C An unsigned char (octet) value. |
8385 | 10169 | W An unsigned char value (can be greater than 255). |
8386 | 10170 | |
8387 | 10171 | =end original |
8388 | 10172 | |
8389 | c | |
10173 | c signed char (8 ビット) 値。 | |
8390 | C | |
10174 | C unsigned char (オクテット) 値。 | |
8391 | W | |
10175 | W unsigned char 値 (255 より大きいかもしれません)。 | |
8392 | 10176 | |
8393 | 10177 | =begin original |
8394 | 10178 | |
8395 | 10179 | s A signed short (16-bit) value. |
8396 | 10180 | S An unsigned short value. |
8397 | 10181 | |
8398 | 10182 | =end original |
8399 | 10183 | |
8400 | s | |
10184 | s signed short (16 ビット) 値。 | |
8401 | S | |
10185 | S unsigned short 値。 | |
8402 | 10186 | |
8403 | 10187 | =begin original |
8404 | 10188 | |
8405 | 10189 | l A signed long (32-bit) value. |
8406 | 10190 | L An unsigned long value. |
8407 | 10191 | |
8408 | 10192 | =end original |
8409 | 10193 | |
8410 | l | |
10194 | l signed long (32 ビット) 値。 | |
8411 | L | |
10195 | L unsigned long 値。 | |
8412 | 10196 | |
8413 | 10197 | =begin original |
8414 | 10198 | |
8415 | 10199 | q A signed quad (64-bit) value. |
8416 | 10200 | Q An unsigned quad value. |
8417 | (Quads are available only if your system supports 64-bit | |
10201 | (Quads are available only if your system supports 64-bit | |
8418 | integer values _and_ if Perl has been compiled to support | |
10202 | integer values _and_ if Perl has been compiled to support | |
8419 | Raises an exception otherwise.) | |
10203 | those. Raises an exception otherwise.) | |
8420 | 10204 | |
8421 | 10205 | =end original |
8422 | 10206 | |
8423 | q 符号付き 64 ビット整数 | |
10207 | q 符号付き 64 ビット整数。 | |
8424 | Q 符号なし 64 ビット整数 | |
10208 | Q 符号なし 64 ビット整数。 | |
8425 | 10209 | (64 ビット整数は、システムが 64 ビット整数に対応していて、かつ Perl が |
8426 | 10210 | 64 ビット整数対応としてコンパイルされている場合にのみ使用可能です。 |
8427 | 10211 | それ以外の場合は例外が発生します。) |
8428 | 10212 | |
8429 | 10213 | =begin original |
8430 | 10214 | |
8431 | 10215 | i A signed integer value. |
8432 | 10216 | I A unsigned integer value. |
8433 | (This 'integer' is _at_least_ 32 bits wide. Its exact | |
10217 | (This 'integer' is _at_least_ 32 bits wide. Its exact | |
8434 | | |
10218 | size depends on what a local C compiler calls 'int'.) | |
8435 | 10219 | |
8436 | 10220 | =end original |
8437 | 10221 | |
8438 | i signed int 値 | |
10222 | i signed int 値。 | |
8439 | I unsigned int 値 | |
10223 | I unsigned int 値。 | |
8440 | (ここでの 'integer' は 「最低」 32 | |
10224 | (ここでの 'integer' は 「最低」 32 ビット幅です。正確なサイズは | |
8441 | | |
10225 | ローカルの C コンパイラの 'int' のサイズに依存します。) | |
8442 | 'int'のサイズに依存します) | |
8443 | 10226 | |
8444 | 10227 | =begin original |
8445 | 10228 | |
8446 | 10229 | n An unsigned short (16-bit) in "network" (big-endian) order. |
8447 | 10230 | N An unsigned long (32-bit) in "network" (big-endian) order. |
8448 | 10231 | v An unsigned short (16-bit) in "VAX" (little-endian) order. |
8449 | 10232 | V An unsigned long (32-bit) in "VAX" (little-endian) order. |
8450 | 10233 | |
8451 | 10234 | =end original |
8452 | 10235 | |
8453 | n "network" 順序 (ビッグエンディアン) の unsigned short (16 ビット) | |
10236 | n "network" 順序 (ビッグエンディアン) の unsigned short (16 ビット)。 | |
8454 | N "network" 順序 (ビッグエンディアン) の unsigned long (32 ビット) | |
10237 | N "network" 順序 (ビッグエンディアン) の unsigned long (32 ビット)。 | |
8455 | v "VAX" 順序 (リトルエンディアン) の unsigned short (16 ビット) | |
10238 | v "VAX" 順序 (リトルエンディアン) の unsigned short (16 ビット)。 | |
8456 | V "VAX" 順序 (リトルエンディアン) の unsigned long (32 ビット) | |
10239 | V "VAX" 順序 (リトルエンディアン) の unsigned long (32 ビット)。 | |
8457 | 10240 | |
8458 | 10241 | =begin original |
8459 | 10242 | |
8460 | j | |
10243 | j A Perl internal signed integer value (IV). | |
8461 | J | |
10244 | J A Perl internal unsigned integer value (UV). | |
8462 | 10245 | |
8463 | 10246 | =end original |
8464 | 10247 | |
8465 | j | |
10248 | j Perl 内部符号付き整数 (IV)。 | |
8466 | J | |
10249 | J Perl 内部符号なし整数 (UV)。 | |
8467 | 10250 | |
8468 | 10251 | =begin original |
8469 | 10252 | |
8470 | 10253 | f A single-precision float in native format. |
8471 | 10254 | d A double-precision float in native format. |
8472 | 10255 | |
8473 | 10256 | =end original |
8474 | 10257 | |
8475 | f 機種依存の単精度浮動小数点数 | |
10258 | f 機種依存の単精度浮動小数点数。 | |
8476 | d 機種依存の倍精度浮動小数点数 | |
10259 | d 機種依存の倍精度浮動小数点数。 | |
8477 | 10260 | |
8478 | 10261 | =begin original |
8479 | 10262 | |
8480 | 10263 | F A Perl internal floating-point value (NV) in native format |
8481 | 10264 | D A float of long-double precision in native format. |
8482 | (Long doubles are available only if your system supports | |
10265 | (Long doubles are available only if your system supports | |
8483 | double values _and_ if Perl has been compiled to | |
10266 | long double values _and_ if Perl has been compiled to | |
8484 | Raises an exception otherwise. | |
10267 | support those. Raises an exception otherwise. | |
10268 | Note that there are different long double formats.) | |
8485 | 10269 | |
8486 | 10270 | =end original |
8487 | 10271 | |
8488 | 10272 | F ネイティブフォーマットの Perl 内部浮動小数点数 (NV) |
8489 | D ネイティブフォーマットの長い倍精度浮動小数点数(long double) | |
10273 | D ネイティブフォーマットの長い倍精度浮動小数点数(long double)。 | |
8490 | 10274 | (long double は、システムが long double に対応していて、かつ Perl が |
8491 | 10275 | long double 対応としてコンパイルされている場合にのみ使用可能です。 |
8492 | | |
10276 | それ以外の場合は例外が発生します。 | |
10277 | long double 型式の場合は異なることに注意してください) | |
8493 | 10278 | |
8494 | 10279 | =begin original |
8495 | 10280 | |
8496 | 10281 | p A pointer to a null-terminated string. |
8497 | 10282 | P A pointer to a structure (fixed-length string). |
8498 | 10283 | |
8499 | 10284 | =end original |
8500 | 10285 | |
8501 | p ヌル文字で終端する文字列へのポインタ | |
10286 | p ヌル文字で終端する文字列へのポインタ。 | |
8502 | P 構造体 (固定長文字列) へのポインタ | |
10287 | P 構造体 (固定長文字列) へのポインタ。 | |
8503 | 10288 | |
8504 | 10289 | =begin original |
8505 | 10290 | |
8506 | 10291 | u A uuencoded string. |
8507 | U A Unicode character number. Encodes to a character in char | |
10292 | U A Unicode character number. Encodes to a character in char- | |
8508 | and UTF-8 (or UTF-EBCDIC in EBCDIC platforms) in | |
10293 | acter mode and UTF-8 (or UTF-EBCDIC in EBCDIC platforms) in | |
10294 | byte mode. | |
8509 | 10295 | |
8510 | 10296 | =end original |
8511 | 10297 | |
8512 | u uuencode 文字列 | |
10298 | u uuencode 文字列。 | |
8513 | 10299 | U Unicode 文字番号。文字モードでは文字に、バイトモードなら UTF-8 に |
8514 | (EBCDIC システムでは UTF-EBCDIC に)エンコードされます | |
10300 | (EBCDIC システムでは UTF-EBCDIC に)エンコードされます。 | |
8515 | 10301 | |
8516 | 10302 | =begin original |
8517 | 10303 | |
8518 | w A BER compressed integer (not an ASN.1 BER, see perlpacktut | |
10304 | w A BER compressed integer (not an ASN.1 BER, see perlpacktut | |
8519 | details). Its bytes represent an unsigned integer in | |
10305 | for details). Its bytes represent an unsigned integer in | |
8520 | most significant digit first, with as few digits | |
10306 | base 128, most significant digit first, with as few digits | |
8521 | eight (the high bit) is set on each byte | |
10307 | as possible. Bit eight (the high bit) is set on each byte | |
10308 | except the last. | |
8522 | 10309 | |
8523 | 10310 | =end original |
8524 | 10311 | |
8525 | w A BER 圧縮変数(ASN.1 BER ではありません | |
10312 | w A BER 圧縮変数(ASN.1 BER ではありません; 詳細については perlpacktut を | |
8526 | 10313 | 参照してください)。このバイト列はできるだけ少ない桁数で表現された |
8527 | 10314 | 128 を基とした符号なし整数で、最上位ビットから順に並びます。 |
8528 | 10315 | 最後のバイト以外の各バイトのビット 8 (上位ビット) がセットされます。 |
8529 | 10316 | |
8530 | 10317 | =begin original |
8531 | 10318 | |
8532 | 10319 | x A null byte (a.k.a ASCII NUL, "\000", chr(0)) |
8533 | 10320 | X Back up a byte. |
8534 | 10321 | @ Null-fill or truncate to absolute position, counted from the |
8535 | 10322 | start of the innermost ()-group. |
8536 | . Null-fill or truncate to absolute position specified by | |
10323 | . Null-fill or truncate to absolute position specified by | |
10324 | the value. | |
8537 | 10325 | ( Start of a ()-group. |
8538 | 10326 | |
8539 | 10327 | =end original |
8540 | 10328 | |
8541 | 10329 | x ヌル文字 (つまり ASCII NUL, "\000", chr(0)) |
8542 | X 1 文字後退 | |
10330 | X 1 文字後退。 | |
8543 | 10331 | @ 一番内側の () の組の開始位置から数えて、絶対位置までヌル文字で |
8544 | 埋めるか切り詰める | |
10332 | 埋めるか切り詰める。 | |
8545 | . 値で指定した絶対位置までヌル文字で埋めるか切り詰める | |
10333 | . 値で指定した絶対位置までヌル文字で埋めるか切り詰める。 | |
8546 | ( () の組の開始 | |
10334 | ( () の組の開始。 | |
8547 | 10335 | |
8548 | 10336 | =begin original |
8549 | 10337 | |
8550 | 10338 | One or more modifiers below may optionally follow certain letters in the |
8551 | 10339 | TEMPLATE (the second column lists letters for which the modifier is valid): |
8552 | 10340 | |
8553 | 10341 | =end original |
8554 | 10342 | |
8555 | 10343 | 以下に示す一つまたは複数の修飾子を、TEMPLATE の文字のいくつかにオプションで |
8556 | 10344 | 付けることができます(表の 2 列目は、その修飾子が有効な文字です): |
8557 | 10345 | |
8558 | 10346 | =begin original |
8559 | 10347 | |
8560 | 10348 | ! sSlLiI Forces native (short, long, int) sizes instead |
8561 | 10349 | of fixed (16-/32-bit) sizes. |
8562 | 10350 | |
8563 | 10351 | =end original |
8564 | 10352 | |
8565 | 10353 | ! sSlLiI 固定の(16/32 ビット)サイズではなく、ネイティブな |
8566 | 10354 | (short, long, int)サイズを強制する。 |
8567 | 10355 | |
8568 | 10356 | =begin original |
8569 | 10357 | |
8570 | | |
10358 | ! xX Make x and X act as alignment commands. | |
8571 | 10359 | |
8572 | 10360 | =end original |
8573 | 10361 | |
8574 | | |
10362 | ! xX x と X をアライメントコマンドとして振舞わせる。 | |
8575 | 10363 | |
8576 | 10364 | =begin original |
8577 | 10365 | |
8578 | | |
10366 | ! nNvV Treat integers as signed instead of unsigned. | |
8579 | 10367 | |
8580 | 10368 | =end original |
8581 | 10369 | |
8582 | | |
10370 | ! nNvV 整数を符号なしではなく符号付きとして扱わせる。 | |
8583 | 10371 | |
8584 | 10372 | =begin original |
8585 | 10373 | |
8586 | | |
10374 | ! @. Specify position as byte offset in the internal | |
8587 | representation of the packed string. Efficien | |
10375 | representation of the packed string. Efficient | |
8588 | dangerous. | |
10376 | but dangerous. | |
8589 | 10377 | |
8590 | 10378 | =end original |
8591 | 10379 | |
8592 | | |
10380 | ! @. pack された内部表現のバイトオフセットとして位置を指定する。 | |
8593 | 10381 | 効率的ですが危険です。 |
8594 | 10382 | |
8595 | 10383 | =begin original |
8596 | 10384 | |
8597 | 10385 | > sSiIlLqQ Force big-endian byte-order on the type. |
8598 | 10386 | jJfFdDpP (The "big end" touches the construct.) |
8599 | 10387 | |
8600 | 10388 | =end original |
8601 | 10389 | |
8602 | > sSiIlLqQ これらの型のバイト順をビッグエンディアンに強制します | |
10390 | > sSiIlLqQ これらの型のバイト順をビッグエンディアンに強制します。 | |
8603 | jJfFdDpP (「大きい端」が構造に触れています) | |
10391 | jJfFdDpP (「大きい端」が構造に触れています。) | |
8604 | 10392 | |
8605 | 10393 | =begin original |
8606 | 10394 | |
8607 | 10395 | < sSiIlLqQ Force little-endian byte-order on the type. |
8608 | 10396 | jJfFdDpP (The "little end" touches the construct.) |
8609 | 10397 | |
8610 | 10398 | =end original |
8611 | 10399 | |
8612 | < sSiIlLqQ これらの型のバイト順をリトルエンディアンに強制します | |
10400 | < sSiIlLqQ これらの型のバイト順をリトルエンディアンに強制します。 | |
8613 | jJfFdDpP (「小さい端」が構造に触れています) | |
10401 | jJfFdDpP (「小さい端」が構造に触れています。) | |
8614 | 10402 | |
8615 | 10403 | =begin original |
8616 | 10404 | |
8617 | The C<< > >> and C<< < >> modifiers can also be used on C<()> groups | |
10405 | The C<< > >> and C<< < >> modifiers can also be used on C<()> groups | |
8618 | to force a particular byte-order on all components in that group, | |
10406 | to force a particular byte-order on all components in that group, | |
8619 | 10407 | including all its subgroups. |
8620 | 10408 | |
8621 | 10409 | =end original |
8622 | 10410 | |
8623 | 10411 | C<< > >> と C<< < >> の修飾子は C<()>-グループでも使えます; |
8624 | 10412 | この場合はそのグループと全ての副グループ内の全ての要素を特定のバイト順に |
8625 | 10413 | 強制します。 |
8626 | 10414 | |
10415 | =begin comment | |
10416 | ||
10417 | Larry recalls that the hex and bit string formats (H, h, B, b) were added to | |
10418 | pack for processing data from NASA's Magellan probe. Magellan was in an | |
10419 | elliptical orbit, using the antenna for the radar mapping when close to | |
10420 | Venus and for communicating data back to Earth for the rest of the orbit. | |
10421 | There were two transmission units, but one of these failed, and then the | |
10422 | other developed a fault whereby it would randomly flip the sense of all the | |
10423 | bits. It was easy to automatically detect complete records with the correct | |
10424 | sense, and complete records with all the bits flipped. However, this didn't | |
10425 | recover the records where the sense flipped midway. A colleague of Larry's | |
10426 | was able to pretty much eyeball where the records flipped, so they wrote an | |
10427 | editor named kybble (a pun on the dog food Kibbles 'n Bits) to enable him to | |
10428 | manually correct the records and recover the data. For this purpose pack | |
10429 | gained the hex and bit string format specifiers. | |
10430 | ||
10431 | git shows that they were added to perl 3.0 in patch #44 (Jan 1991, commit | |
10432 | 27e2fb84680b9cc1), but the patch description makes no mention of their | |
10433 | addition, let alone the story behind them. | |
10434 | ||
10435 | =end comment | |
10436 | ||
8627 | 10437 | =begin original |
8628 | 10438 | |
8629 | 10439 | The following rules apply: |
8630 | 10440 | |
8631 | 10441 | =end original |
8632 | 10442 | |
8633 | 10443 | 以下の条件が適用されます: |
8634 | 10444 | |
8635 | =over | |
10445 | =over | |
8636 | 10446 | |
8637 | 10447 | =item * |
8638 | 10448 | |
8639 | 10449 | =begin original |
8640 | 10450 | |
8641 | 10451 | Each letter may optionally be followed by a number indicating the repeat |
8642 | 10452 | count. A numeric repeat count may optionally be enclosed in brackets, as |
8643 | 10453 | in C<pack("C[80]", @arr)>. The repeat count gobbles that many values from |
8644 | 10454 | the LIST when used with all format types other than C<a>, C<A>, C<Z>, C<b>, |
8645 | 10455 | C<B>, C<h>, C<H>, C<@>, C<.>, C<x>, C<X>, and C<P>, where it means |
8646 | something else, dscribed below. Supplying a C<*> for the repeat count | |
10456 | something else, described below. Supplying a C<*> for the repeat count | |
8647 | 10457 | instead of a number means to use however many items are left, except for: |
8648 | 10458 | |
8649 | 10459 | =end original |
8650 | 10460 | |
8651 | 10461 | これらの文字の後には、繰り返し数を示す数字を付けることができます。 |
8652 | 10462 | 数値の繰り返し数は C<pack "C[80]", @arr> のように大かっこで |
8653 | 10463 | 囲むこともできます。 |
8654 | 10464 | C<a>, C<A>, C<Z>, C<b>, C<B>, C<h>, C<H>, C<@>, C<.>, C<x>, C<X>, C<P> |
8655 | 10465 | 以外の全ての型では、LIST から繰り返し数の値を取り出して使います。 |
8656 | 10466 | 繰り返し数に C<*> を指定すると、以下の例外を除いて、 |
8657 | 10467 | その時点で残っているすべての要素を意味します。 |
8658 | 10468 | |
10469 | =over | |
8659 | 10470 | |
10471 | =item * | |
8660 | 10472 | |
8661 | =over | |
8662 | ||
8663 | =item * | |
8664 | ||
8665 | 10473 | =begin original |
8666 | 10474 | |
8667 | 10475 | C<@>, C<x>, and C<X>, where it is equivalent to C<0>. |
8668 | 10476 | |
8669 | 10477 | =end original |
8670 | 10478 | |
8671 | 10479 | C<@>, C<x>, C<X> では C<0> と等価です。 |
8672 | 10480 | |
8673 | =item * | |
10481 | =item * | |
8674 | 10482 | |
8675 | 10483 | =begin original |
8676 | 10484 | |
8677 | 10485 | <.>, where it means relative to the start of the string. |
8678 | 10486 | |
8679 | 10487 | =end original |
8680 | 10488 | |
8681 | ||
10489 | <.> では文字列の先頭からの相対位置を意味します。 | |
8682 | 10490 | |
8683 | =item * | |
10491 | =item * | |
8684 | 10492 | |
8685 | 10493 | =begin original |
8686 | 10494 | |
8687 | 10495 | C<u>, where it is equivalent to 1 (or 45, which here is equivalent). |
8688 | 10496 | |
8689 | 10497 | =end original |
8690 | 10498 | |
8691 | 10499 | C<u> では 1 (あるいはここでは 45 でも等価です) と等価です。 |
8692 | 10500 | |
8693 | =back | |
10501 | =back | |
8694 | 10502 | |
8695 | 10503 | =begin original |
8696 | 10504 | |
8697 | 10505 | One can replace a numeric repeat count with a template letter enclosed in |
8698 | 10506 | brackets to use the packed byte length of the bracketed template for the |
8699 | 10507 | repeat count. |
8700 | 10508 | |
8701 | 10509 | =end original |
8702 | 10510 | |
8703 | 10511 | このテンプレートでパックされたバイト長を繰り返し数として使うために、 |
8704 | 10512 | 大かっこで囲まれたテンプレートで数値の繰り返し数を置き換えることが |
8705 | 10513 | できます。 |
8706 | 10514 | |
8707 | 10515 | =begin original |
8708 | 10516 | |
8709 | 10517 | For example, the template C<x[L]> skips as many bytes as in a packed long, |
8710 | 10518 | and the template C<"$t X[$t] $t"> unpacks twice whatever $t (when |
8711 | 10519 | variable-expanded) unpacks. If the template in brackets contains alignment |
8712 | 10520 | commands (such as C<x![d]>), its packed length is calculated as if the |
8713 | 10521 | start of the template had the maximal possible alignment. |
8714 | 10522 | |
8715 | 10523 | =end original |
8716 | 10524 | |
8717 | 10525 | 例えば、テンプレート C<x[L]> は long でパックされたバイト数分だけスキップし、 |
8718 | 10526 | テンプレート C<"$t X[$t] $t"> は $t (変数展開された場合)を |
8719 | 10527 | unpack したものの 2 倍を unpack します。 |
8720 | 10528 | (C<x![d]> のように) 大かっこにアライメントコマンドが含まれている場合、 |
8721 | 10529 | パックされた長さは、テンプレートの先頭で最大限可能なアライメントを |
8722 | 10530 | 持っているものとして計算されます。 |
8723 | 10531 | |
8724 | 10532 | =begin original |
8725 | 10533 | |
8726 | 10534 | When used with C<Z>, a C<*> as the repeat count is guaranteed to add a |
8727 | 10535 | trailing null byte, so the resulting string is always one byte longer than |
8728 | 10536 | the byte length of the item itself. |
8729 | 10537 | |
8730 | 10538 | =end original |
8731 | 10539 | |
8732 | 10540 | C<Z> で、繰り返し数として C<*> が使われた場合、末尾にヌルバイトが |
8733 | 保証されるので、 | |
10541 | 保証されるので、結果の文字列は常にアイテム自身のバイト長よりも 1 バイト | |
8734 | ||
10542 | 長くなります。 | |
8735 | 10543 | |
8736 | 10544 | =begin original |
8737 | 10545 | |
8738 | 10546 | When used with C<@>, the repeat count represents an offset from the start |
8739 | 10547 | of the innermost C<()> group. |
8740 | 10548 | |
8741 | 10549 | =end original |
8742 | 10550 | |
8743 | 10551 | C<@> で使うと、繰り返し数は一番内側の C<()> グループの先頭からのオフセットを |
8744 | 10552 | 表現します。 |
8745 | 10553 | |
8746 | 10554 | =begin original |
8747 | 10555 | |
8748 | 10556 | When used with C<.>, the repeat count determines the starting position to |
8749 | 10557 | calculate the value offset as follows: |
8750 | 10558 | |
8751 | 10559 | =end original |
8752 | 10560 | |
8753 | 10561 | C<.> で使われると、繰り返し数は以下のようにして、 |
8754 | 10562 | 値のオフセットを計算するための開始位置を決定するために使われます。 |
8755 | 10563 | |
8756 | =over | |
10564 | =over | |
8757 | 10565 | |
8758 | 10566 | =item * |
8759 | 10567 | |
8760 | 10568 | =begin original |
8761 | 10569 | |
8762 | 10570 | If the repeat count is C<0>, it's relative to the current position. |
8763 | 10571 | |
8764 | 10572 | =end original |
8765 | 10573 | |
8766 | 10574 | 繰り返し数が C<0> なら、現在位置からの相対位置となります。 |
8767 | 10575 | |
8768 | 10576 | =item * |
8769 | 10577 | |
8770 | 10578 | =begin original |
8771 | 10579 | |
8772 | 10580 | If the repeat count is C<*>, the offset is relative to the start of the |
8773 | 10581 | packed string. |
8774 | 10582 | |
8775 | 10583 | =end original |
8776 | 10584 | |
8777 | 繰り返し数が C<*> なら、オフセットは pack された文字列の先頭からの | |
10585 | 繰り返し数が C<*> なら、オフセットは pack された文字列の先頭からの | |
10586 | 相対位置です。 | |
8778 | 10587 | |
8779 | 10588 | =item * |
8780 | 10589 | |
8781 | 10590 | =begin original |
8782 | 10591 | |
8783 | 10592 | And if it's an integer I<n>, the offset is relative to the start of the |
8784 | 10593 | I<n>th innermost C<( )> group, or to the start of the string if I<n> is |
8785 | 10594 | bigger then the group level. |
8786 | 10595 | |
8787 | 10596 | =end original |
8788 | 10597 | |
8789 | 10598 | そして整数 I<n> なら、オフセットは一番内側から I<n> 番目の C<( )> グループの |
8790 | 10599 | 先頭、あるいは I<n> がグループレベルより大きい場合は文字列の先頭からの |
8791 | 10600 | 相対位置です。 |
8792 | 10601 | |
8793 | 10602 | =back |
8794 | 10603 | |
8795 | 10604 | =begin original |
8796 | 10605 | |
8797 | 10606 | The repeat count for C<u> is interpreted as the maximal number of bytes |
8798 | to encode per line of output, with 0, 1 and 2 replaced by 45. The repeat | |
10607 | to encode per line of output, with 0, 1 and 2 replaced by 45. The repeat | |
8799 | 10608 | count should not be more than 65. |
8800 | 10609 | |
8801 | 10610 | =end original |
8802 | 10611 | |
8803 | 10612 | C<u> での繰り返し回数は、出力行毎に最大何バイトまでをエンコードするかを |
8804 | 示します | |
10613 | 示します; 0, 1, 2 は 45 として扱われます。 | |
8805 | 10614 | 繰り返し数は 65 を超えてはなりません。 |
8806 | 10615 | |
8807 | 10616 | =item * |
8808 | 10617 | |
8809 | 10618 | =begin original |
8810 | 10619 | |
8811 | 10620 | The C<a>, C<A>, and C<Z> types gobble just one value, but pack it as a |
8812 | 10621 | string of length count, padding with nulls or spaces as needed. When |
8813 | 10622 | unpacking, C<A> strips trailing whitespace and nulls, C<Z> strips everything |
8814 | 10623 | after the first null, and C<a> returns data with no stripping at all. |
8815 | 10624 | |
8816 | 10625 | =end original |
8817 | 10626 | |
8818 | 10627 | C<a>, C<A>, C<Z> という型を使うと、値を一つだけ取り出して使いますが、 |
8819 | 10628 | 繰り返し数で示す長さの文字列となるように、必要に応じてヌル文字か |
8820 | 10629 | スペース文字を付け足します。 |
8821 | unpack するとき、C<A> は後続の空白やヌル文字を取り除きます | |
10630 | unpack するとき、C<A> は後続の空白やヌル文字を取り除きます; C<Z> は最初の | |
8822 | ||
10631 | ヌル文字以降の全てを取り除きます; C<a> はデータを取り除くことなく | |
8823 | ||
10632 | そのまま返します。 | |
8824 | 10633 | |
8825 | 10634 | =begin original |
8826 | 10635 | |
8827 | 10636 | If the value to pack is too long, the result is truncated. If it's too |
8828 | 10637 | long and an explicit count is provided, C<Z> packs only C<$count-1> bytes, |
8829 | 10638 | followed by a null byte. Thus C<Z> always packs a trailing null, except |
8830 | 10639 | when the count is 0. |
8831 | 10640 | |
8832 | 10641 | =end original |
8833 | 10642 | |
8834 | 10643 | pack する値が長すぎる場合、結果は切り詰められます。 |
8835 | 10644 | 長すぎてかつ明示的に個数が指定されている場合、 |
8836 | 10645 | C<Z> は C<$count-1> バイトまで pack し、その後にヌルバイトがつきます。 |
8837 | 10646 | 従って、C<Z> は、繰り返し数が 0 の場合を除いて、常に末尾にヌルバイトが |
8838 | 10647 | つきます。 |
8839 | 10648 | |
8840 | 10649 | =item * |
8841 | 10650 | |
8842 | 10651 | =begin original |
8843 | 10652 | |
8844 | 10653 | Likewise, the C<b> and C<B> formats pack a string that's that many bits long. |
8845 | 10654 | Each such format generates 1 bit of the result. These are typically followed |
8846 | 10655 | by a repeat count like C<B8> or C<B64>. |
8847 | 10656 | |
8848 | 10657 | =end original |
8849 | 10658 | |
8850 | 10659 | 同様に、C<b> や C<B> は、繰り返し数で示すビット長のビット列に pack します。 |
8851 | 10660 | これらの各文字は結果の 1 ビットを生成します。 |
8852 | 10661 | これらは典型的には C<B8> や C<B64> のような繰り返しカウントが引き続きます。 |
8853 | 10662 | |
8854 | 10663 | =begin original |
8855 | 10664 | |
8856 | 10665 | Each result bit is based on the least-significant bit of the corresponding |
8857 | 10666 | input character, i.e., on C<ord($char)%2>. In particular, characters C<"0"> |
8858 | 10667 | and C<"1"> generate bits 0 and 1, as do characters C<"\000"> and C<"\001">. |
8859 | 10668 | |
8860 | 10669 | =end original |
8861 | 10670 | |
8862 | 10671 | 結果ビットのそれぞれは対応する入力文字の最下位ビットを基にします |
8863 | 10672 | (つまり C<ord($char)%2>)。 |
8864 | 10673 | 特に、文字 C<"0"> と C<"1"> は文字 C<"\000"> と C<"\001"> と同様に、 |
8865 | 10674 | ビット 0 と 1 を生成します。 |
8866 | 10675 | |
8867 | 10676 | =begin original |
8868 | 10677 | |
8869 | 10678 | Starting from the beginning of the input string, each 8-tuple |
8870 | 10679 | of characters is converted to 1 character of output. With format C<b>, |
8871 | 10680 | the first character of the 8-tuple determines the least-significant bit of a |
8872 | 10681 | character; with format C<B>, it determines the most-significant bit of |
8873 | 10682 | a character. |
8874 | 10683 | |
8875 | 10684 | =end original |
8876 | 10685 | |
8877 | pack() の入力文字列の先頭から始めて、8 タプル毎に 1 文字の出力に | |
10686 | pack() の入力文字列の先頭から始めて、8 タプル毎に 1 文字の出力に変換されます。 | |
8878 | 変換されます。 | |
8879 | 10687 | C<b> フォーマットでは 8 タプルの最初の文字が出力の最下位ビットとなります; |
8880 | 10688 | C<B> フォーマットでは出力の最上位ビットとなります。 |
8881 | 10689 | |
8882 | 10690 | =begin original |
8883 | 10691 | |
8884 | 10692 | If the length of the input string is not evenly divisible by 8, the |
8885 | 10693 | remainder is packed as if the input string were padded by null characters |
8886 | 10694 | at the end. Similarly during unpacking, "extra" bits are ignored. |
8887 | 10695 | |
8888 | 10696 | =end original |
8889 | 10697 | |
8890 | 10698 | もし入力文字列の長さが 8 で割り切れない場合、余りの部分は入力文字列の |
8891 | 10699 | 最後にヌル文字がパッディングされているものとしてパックされます。 |
8892 | 10700 | 同様に、unpack 中は「余分な」ビットは無視されます。 |
8893 | 10701 | |
8894 | 10702 | =begin original |
8895 | 10703 | |
8896 | 10704 | If the input string is longer than needed, remaining characters are ignored. |
8897 | 10705 | |
8898 | 10706 | =end original |
8899 | 10707 | |
8900 | 10708 | 入力文字列が必要な分よりも長い場合、余分な文字は無視されます。 |
8901 | 10709 | |
8902 | 10710 | =begin original |
8903 | 10711 | |
8904 | A C<*> for the repeat count uses all characters of the input field. | |
10712 | A C<*> for the repeat count uses all characters of the input field. | |
8905 | 10713 | On unpacking, bits are converted to a string of C<0>s and C<1>s. |
8906 | 10714 | |
8907 | 10715 | =end original |
8908 | 10716 | |
8909 | 繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が | |
10717 | 繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が使われます。 | |
8910 | 使われます。 | |
8911 | 10718 | unpack 時にはビット列は C<0> と C<1> の文字列に変換されます。 |
8912 | 10719 | |
8913 | 10720 | =item * |
8914 | 10721 | |
8915 | 10722 | =begin original |
8916 | 10723 | |
8917 | 10724 | The C<h> and C<H> formats pack a string that many nybbles (4-bit groups, |
8918 | 10725 | representable as hexadecimal digits, C<"0".."9"> C<"a".."f">) long. |
8919 | 10726 | |
8920 | 10727 | =end original |
8921 | 10728 | |
8922 | 10729 | C<h> や C<H> は、多ニブル長(16 進文字である C<"0".."9"> C<"a".."f"> で |
8923 | 10730 | 表現可能な 4 ビットグループ)のニブル列に pack します。 |
8924 | 10731 | |
8925 | 10732 | =begin original |
8926 | 10733 | |
8927 | For each such format, pack | |
10734 | For each such format, L<C<pack>|/pack TEMPLATE,LIST> generates 4 bits of result. | |
8928 | 10735 | With non-alphabetical characters, the result is based on the 4 least-significant |
8929 | 10736 | bits of the input character, i.e., on C<ord($char)%16>. In particular, |
8930 | 10737 | characters C<"0"> and C<"1"> generate nybbles 0 and 1, as do bytes |
8931 | 10738 | C<"\000"> and C<"\001">. For characters C<"a".."f"> and C<"A".."F">, the result |
8932 | 10739 | is compatible with the usual hexadecimal digits, so that C<"a"> and |
8933 | C<"A"> both generate the nybble C<0xA==10>. Use only these specific hex | |
10740 | C<"A"> both generate the nybble C<0xA==10>. Use only these specific hex | |
8934 | 10741 | characters with this format. |
8935 | 10742 | |
8936 | 10743 | =end original |
8937 | 10744 | |
8938 | このようなフォーマット文字のそれぞれについて、pack | |
10745 | このようなフォーマット文字のそれぞれについて、L<C<pack>|/pack TEMPLATE,LIST> は | |
8939 | 10746 | 結果の 4 ビットを生成します。 |
8940 | 10747 | 英字でない文字の場合、結果は入力文字の下位 4 ビットを |
8941 | 10748 | 基にします(つまり C<ord($char)%16>)。 |
8942 | 10749 | 特に、文字 C<"0"> と C<"1"> はバイト C<"\000"> と C<"\001"> と同様に |
8943 | 10750 | ニブル 0 と 1 を生成します。 |
8944 | 文字 C<"a".."f"> と C<"A".."F"> の場合は結果は通常の | |
10751 | 文字 C<"a".."f"> と C<"A".."F"> の場合は結果は通常の 16 進数と同じ結果に | |
8945 | ||
10752 | なるので、C<"a"> と C<"A"> はどちらも ニブル C<0xa==10> を生成します。 | |
8946 | ニブル C<0xa==10> を生成します。 | |
8947 | 10753 | これらの 16 進文字はこの特定のフォーマットでだけ使ってください。 |
8948 | 10754 | |
8949 | 10755 | =begin original |
8950 | 10756 | |
8951 | Starting from the beginning of the template to | |
10757 | Starting from the beginning of the template to | |
10758 | L<C<pack>|/pack TEMPLATE,LIST>, each pair | |
8952 | 10759 | of characters is converted to 1 character of output. With format C<h>, the |
8953 | 10760 | first character of the pair determines the least-significant nybble of the |
8954 | 10761 | output character; with format C<H>, it determines the most-significant |
8955 | 10762 | nybble. |
8956 | 10763 | |
8957 | 10764 | =end original |
8958 | 10765 | |
8959 | pack | |
10766 | L<C<pack>|/pack TEMPLATE,LIST> のテンプレートの先頭から始めて、2 文字毎に | |
8960 | 変換されます。 | |
10767 | 1 文字の出力に変換されます。 | |
8961 | 10768 | C<h> フォーマットでは 1 文字目が出力の最下位ニブルとなり、 |
8962 | 10769 | C<H> フォーマットでは出力の最上位ニブルとなります。 |
8963 | 10770 | |
8964 | 10771 | =begin original |
8965 | 10772 | |
8966 | 10773 | If the length of the input string is not even, it behaves as if padded by |
8967 | 10774 | a null character at the end. Similarly, "extra" nybbles are ignored during |
8968 | 10775 | unpacking. |
8969 | 10776 | |
8970 | 10777 | =end original |
8971 | 10778 | |
8972 | 10779 | 入力文字列の長さが偶数でない場合、最後にヌル文字でパッディングされて |
8973 | 10780 | いるかのように振る舞います。 |
8974 | 10781 | 同様に、unpack 中は「余分な」ニブルは無視されます。 |
8975 | 10782 | |
8976 | 10783 | =begin original |
8977 | 10784 | |
8978 | 10785 | If the input string is longer than needed, extra characters are ignored. |
8979 | 10786 | |
8980 | 10787 | =end original |
8981 | 10788 | |
8982 | 10789 | 入力文字列が必要な分より長い場合、余分な部分は無視されます。 |
8983 | 10790 | |
8984 | 10791 | =begin original |
8985 | 10792 | |
8986 | 10793 | A C<*> for the repeat count uses all characters of the input field. For |
8987 | unpack | |
10794 | L<C<unpack>|/unpack TEMPLATE,EXPR>, nybbles are converted to a string of | |
10795 | hexadecimal digits. | |
8988 | 10796 | |
8989 | 10797 | =end original |
8990 | 10798 | |
8991 | 繰り返し数として C<*> が指定されると、入力フィールドの全ての | |
10799 | 繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が使われます。 | |
8992 | 文字 | |
10800 | L<C<unpack>|/unpack TEMPLATE,EXPR> 時にはニブルは 16 進数の文字列に | |
8993 | ||
10801 | 変換されます。 | |
8994 | 10802 | |
8995 | 10803 | =item * |
8996 | 10804 | |
8997 | 10805 | =begin original |
8998 | 10806 | |
8999 | 10807 | The C<p> format packs a pointer to a null-terminated string. You are |
9000 | 10808 | responsible for ensuring that the string is not a temporary value, as that |
9001 | 10809 | could potentially get deallocated before you got around to using the packed |
9002 | 10810 | result. The C<P> format packs a pointer to a structure of the size indicated |
9003 | 10811 | by the length. A null pointer is created if the corresponding value for |
9004 | C<p> or C<P> is C<undef>; similarly with | |
10812 | C<p> or C<P> is L<C<undef>|/undef EXPR>; similarly with | |
9005 | unpack | |
10813 | L<C<unpack>|/unpack TEMPLATE,EXPR>, where a null pointer unpacks into | |
10814 | L<C<undef>|/undef EXPR>. | |
9006 | 10815 | |
9007 | 10816 | =end original |
9008 | 10817 | |
9009 | 10818 | C<p> は、ヌル文字終端文字列へのポインタを pack します。 |
9010 | 10819 | 文字列が一時的な値でない(つまり pack された結果を使う前に文字列が |
9011 | 解放されない) ことに責任を持つ必要があります | |
10820 | 解放されない) ことに責任を持つ必要があります。 | |
9012 | 10821 | C<P> は、指定した長さの構造体へのポインタを pack します。 |
9013 | C<p> または C<P> に対応する値が C<undef> だった場合、 | |
10822 | C<p> または C<P> に対応する値が L<C<undef>|/undef EXPR> だった場合、 | |
9014 | ヌルポインタが作成されます; ヌルポインタが C<undef> | |
10823 | ヌルポインタが作成されます; ヌルポインタが L<C<undef>|/undef EXPR> に | |
9015 | unpack | |
10824 | unpack される L<C<unpack>|/unpack TEMPLATE,EXPR> と同様です。 | |
9016 | 10825 | |
9017 | 10826 | =begin original |
9018 | 10827 | |
9019 | 10828 | If your system has a strange pointer size--meaning a pointer is neither as |
9020 | 10829 | big as an int nor as big as a long--it may not be possible to pack or |
9021 | 10830 | unpack pointers in big- or little-endian byte order. Attempting to do |
9022 | 10831 | so raises an exception. |
9023 | 10832 | |
9024 | 10833 | =end original |
9025 | 10834 | |
9026 | 10835 | システムのポインタが変わったサイズの場合--つまり、int の大きさでも |
9027 | 10836 | long の大きさでもない場合--ポインタをビッグエンディアンやリトルエンディアンの |
9028 | 10837 | バイト順で pack や unpack することはできません。 |
9029 | 10838 | そうしようとすると例外が発生します。 |
9030 | 10839 | |
9031 | 10840 | =item * |
9032 | 10841 | |
9033 | 10842 | =begin original |
9034 | 10843 | |
9035 | 10844 | The C</> template character allows packing and unpacking of a sequence of |
9036 | 10845 | items where the packed structure contains a packed item count followed by |
9037 | 10846 | the packed items themselves. This is useful when the structure you're |
9038 | 10847 | unpacking has encoded the sizes or repeat counts for some of its fields |
9039 | 10848 | within the structure itself as separate fields. |
9040 | 10849 | |
9041 | 10850 | =end original |
9042 | 10851 | |
9043 | 10852 | C</> テンプレート文字は、アイテムの数の後にアイテムそのものが入っている形の |
9044 | 10853 | アイテム列を pack 及び unpack します。 |
9045 | 10854 | これは、unpack したい構造体が、サイズや繰り返し数が構造体自身の中に |
9046 | 10855 | 独立したフィールドとしてエンコードされている場合に有効です。 |
9047 | 10856 | |
9048 | 10857 | =begin original |
9049 | 10858 | |
9050 | For C<pack>, you writ | |
10859 | For L<C<pack>|/pack TEMPLATE,LIST>, you write | |
9051 | I<length-item> | |
10860 | I<length-item>C</>I<sequence-item>, and the | |
10861 | I<length-item> describes how the length value is packed. Formats likely | |
9052 | 10862 | to be of most use are integer-packing ones like C<n> for Java strings, |
9053 | 10863 | C<w> for ASN.1 or SNMP, and C<N> for Sun XDR. |
9054 | 10864 | |
9055 | 10865 | =end original |
9056 | 10866 | |
9057 | C<pack> では I<length-item>C</>I<string-item> の | |
10867 | L<C<pack>|/pack TEMPLATE,LIST> では I<length-item>C</>I<string-item> の | |
10868 | 形になり、 | |
9058 | 10869 | I<length-item> は長さの値がどのように pack されているかを指定します。 |
9059 | 10870 | もっともよく使われるのは Java 文字列 のための C<n>、ASN.1 や SNMP のための |
9060 | 10871 | C<w>、Sun XDR のための C<N> といった整数型です。 |
9061 | 10872 | |
9062 | 10873 | =begin original |
9063 | 10874 | |
9064 | For C<pack>, I<sequence-item> may have a repeat | |
10875 | For L<C<pack>|/pack TEMPLATE,LIST>, I<sequence-item> may have a repeat | |
10876 | count, in which case | |
9065 | 10877 | the minimum of that and the number of available items is used as the argument |
9066 | for I<length-item>. If it has no repeat count or uses a '*', the number | |
10878 | for I<length-item>. If it has no repeat count or uses a '*', the number | |
9067 | 10879 | of available items is used. |
9068 | 10880 | |
9069 | 10881 | =end original |
9070 | 10882 | |
9071 | C<pack> では、I<sequence-item> は繰り返し数を | |
10883 | L<C<pack>|/pack TEMPLATE,LIST> では、I<sequence-item> は繰り返し数を | |
9072 | その最小値と利用可能なアイテムの数は | |
10884 | 持つことがあり、その場合はその最小値と利用可能なアイテムの数は | |
9073 | 使われます。 | |
10885 | I<length-item> のための引数として使われます。 | |
9074 | 10886 | 繰り返し数がなかったり、'*' を使うと、利用可能なアイテムの数が使われます。 |
9075 | 10887 | |
9076 | 10888 | =begin original |
9077 | 10889 | |
9078 | For C<unpack>, an internal stack of integer | |
10890 | For L<C<unpack>|/unpack TEMPLATE,EXPR>, an internal stack of integer | |
9079 | ||
10891 | arguments unpacked so far is | |
9080 | ||
10892 | used. You write C</>I<sequence-item> and the repeat count is obtained by | |
10893 | popping off the last element from the stack. The I<sequence-item> must not | |
9081 | 10894 | have a repeat count. |
9082 | 10895 | |
9083 | 10896 | =end original |
9084 | 10897 | |
9085 | C<unpack> では、今まで unpack した数値引数の | |
10898 | L<C<unpack>|/unpack TEMPLATE,EXPR> では、今まで unpack した数値引数の | |
10899 | 内部スタックが使われます。 | |
9086 | 10900 | C</>I<sequence-item> と書いて、繰り返し数はスタックから最後の要素を |
9087 | 10901 | 取り出すことで得ます。 |
9088 | 10902 | I<sequence-item> は繰り返し数を持っていてはいけません。 |
9089 | 10903 | |
9090 | 10904 | =begin original |
9091 | 10905 | |
9092 | 10906 | If I<sequence-item> refers to a string type (C<"A">, C<"a">, or C<"Z">), |
9093 | 10907 | the I<length-item> is the string length, not the number of strings. With |
9094 | 10908 | an explicit repeat count for pack, the packed string is adjusted to that |
9095 | 10909 | length. For example: |
9096 | 10910 | |
9097 | 10911 | =end original |
9098 | 10912 | |
9099 | 10913 | I<sequence-item> が文字列型 (C<"A">, C<"a">, C<"Z">) を参照している場合、 |
9100 | 10914 | I<length-item> は文字列の数ではなく、文字列の長さです。 |
9101 | 10915 | pack で明示的な繰り返し数があると、pack された文字列は与えられた |
9102 | 10916 | 長さに調整されます。 |
9103 | 10917 | 例えば: |
9104 | 10918 | |
9105 | | |
10919 | This code: gives this result: | |
9106 | unpack("a3/A A*", "007 Bond J ") gives (" Bond", "J") | |
9107 | unpack("a3 x2 /A A*", "007: Bond, J.") gives ("Bond, J", ".") | |
9108 | 10920 | |
9109 | | |
10921 | unpack("W/a", "\004Gurusamy") ("Guru") | |
9110 | | |
10922 | unpack("a3/A A*", "007 Bond J ") (" Bond", "J") | |
10923 | unpack("a3 x2 /A A*", "007: Bond, J.") ("Bond, J", ".") | |
9111 | 10924 | |
10925 | pack("n/a* w/a","hello,","world") "\000\006hello,\005world" | |
10926 | pack("a/W2", ord("a") .. ord("z")) "2ab" | |
10927 | ||
9112 | 10928 | =begin original |
9113 | 10929 | |
9114 | The I<length-item> is not returned explicitly from | |
10930 | The I<length-item> is not returned explicitly from | |
10931 | L<C<unpack>|/unpack TEMPLATE,EXPR>. | |
9115 | 10932 | |
9116 | 10933 | =end original |
9117 | 10934 | |
9118 | I<length-item> は C<unpack> から明示的には | |
10935 | I<length-item> は L<C<unpack>|/unpack TEMPLATE,EXPR> から明示的には | |
10936 | 返されません。 | |
9119 | 10937 | |
9120 | 10938 | =begin original |
9121 | 10939 | |
9122 | 10940 | Supplying a count to the I<length-item> format letter is only useful with |
9123 | 10941 | C<A>, C<a>, or C<Z>. Packing with a I<length-item> of C<a> or C<Z> may |
9124 | 10942 | introduce C<"\000"> characters, which Perl does not regard as legal in |
9125 | 10943 | numeric strings. |
9126 | 10944 | |
9127 | 10945 | =end original |
9128 | 10946 | |
9129 | 10947 | I<length-item> 文字に繰り返し数をつけるのは、 |
9130 | 10948 | 文字が C<A>, C<a>, C<Z> でない限りは有用ではありません。 |
9131 | 10949 | C<a> や C<Z> を I<length-item> として pack すると C<"\000"> 文字が |
9132 | 10950 | 出力されることがあり、Perl はこれを有効な数値文字列として認識しません。 |
9133 | 10951 | |
9134 | 10952 | =item * |
9135 | 10953 | |
9136 | 10954 | =begin original |
9137 | 10955 | |
9138 | 10956 | The integer types C<s>, C<S>, C<l>, and C<L> may be |
9139 | 10957 | followed by a C<!> modifier to specify native shorts or |
9140 | 10958 | longs. As shown in the example above, a bare C<l> means |
9141 | 10959 | exactly 32 bits, although the native C<long> as seen by the local C compiler |
9142 | 10960 | may be larger. This is mainly an issue on 64-bit platforms. You can |
9143 | 10961 | see whether using C<!> makes any difference this way: |
9144 | 10962 | |
9145 | 10963 | =end original |
9146 | 10964 | |
9147 | 10965 | C<s>, C<S>, C<l>, C<L> の整数タイプに引き続いて C<!> 修飾子を |
9148 | 10966 | つけることで、ネイティブの short や long を指定できます。 |
9149 | 10967 | 上述のように、C<l> は正確に 32 ビットですが、ネイティブな |
9150 | 10968 | (ローカルな C コンパイラによる)C<long> はもっと大きいかもしれません。 |
9151 | 10969 | これは主に 64 ビットプラットフォームで意味があります。 |
9152 | 10970 | C<!> を使うことによって違いがあるかどうかは以下のようにして調べられます: |
9153 | 10971 | |
9154 | printf "format s is %d, s! is %d\n", | |
10972 | printf "format s is %d, s! is %d\n", | |
9155 | 10973 | length pack("s"), length pack("s!"); |
9156 | 10974 | |
9157 | printf "format l is %d, l! is %d\n", | |
10975 | printf "format l is %d, l! is %d\n", | |
9158 | 10976 | length pack("l"), length pack("l!"); |
9159 | 10977 | |
9160 | 10978 | =begin original |
9161 | 10979 | |
9162 | 10980 | C<i!> and C<I!> are also allowed, but only for completeness' sake: |
9163 | 10981 | they are identical to C<i> and C<I>. |
9164 | 10982 | |
9165 | 10983 | =end original |
9166 | 10984 | |
9167 | 10985 | C<i!> と C<I!> も動作しますが、単に完全性のためだけです; |
9168 | 10986 | これは C<i> 及び C<I> と同じです。 |
9169 | 10987 | |
9170 | 10988 | =begin original |
9171 | 10989 | |
9172 | 10990 | The actual sizes (in bytes) of native shorts, ints, longs, and long |
9173 | 10991 | longs on the platform where Perl was built are also available from |
9174 | 10992 | the command line: |
9175 | 10993 | |
9176 | 10994 | =end original |
9177 | 10995 | |
9178 | 10996 | Perl がビルドされたプラットフォームでの short, int, long, long long の |
9179 | 10997 | 実際の(バイト数での)サイズはコマンドラインから: |
9180 | 10998 | |
9181 | 10999 | $ perl -V:{short,int,long{,long}}size |
9182 | 11000 | shortsize='2'; |
9183 | 11001 | intsize='4'; |
9184 | 11002 | longsize='4'; |
9185 | 11003 | longlongsize='8'; |
9186 | 11004 | |
9187 | 11005 | =begin original |
9188 | 11006 | |
9189 | or programmatically via the C<Config> module: | |
11007 | or programmatically via the L<C<Config>|Config> module: | |
9190 | 11008 | |
9191 | 11009 | =end original |
9192 | 11010 | |
9193 | あるいは C<Config> モジュールからプログラムで: | |
11011 | あるいは L<C<Config>|Config> モジュールからプログラムで: | |
9194 | 11012 | |
9195 | 11013 | use Config; |
9196 | 11014 | print $Config{shortsize}, "\n"; |
9197 | 11015 | print $Config{intsize}, "\n"; |
9198 | 11016 | print $Config{longsize}, "\n"; |
9199 | 11017 | print $Config{longlongsize}, "\n"; |
9200 | 11018 | |
9201 | 11019 | =begin original |
9202 | 11020 | |
9203 | C<$Config{longlongsize}> is undefined on systems without | |
11021 | C<$Config{longlongsize}> is undefined on systems without | |
9204 | 11022 | long long support. |
9205 | 11023 | |
9206 | 11024 | =end original |
9207 | 11025 | |
9208 | 11026 | システムが long long に対応していない場合は C<$Config{longlongsize}> は |
9209 | 11027 | 未定義値になります。 |
9210 | 11028 | |
9211 | 11029 | =item * |
9212 | 11030 | |
9213 | 11031 | =begin original |
9214 | 11032 | |
9215 | 11033 | The integer formats C<s>, C<S>, C<i>, C<I>, C<l>, C<L>, C<j>, and C<J> are |
9216 | 11034 | inherently non-portable between processors and operating systems because |
9217 | 11035 | they obey native byteorder and endianness. For example, a 4-byte integer |
9218 | 11036 | 0x12345678 (305419896 decimal) would be ordered natively (arranged in and |
9219 | 11037 | handled by the CPU registers) into bytes as |
9220 | 11038 | |
9221 | 11039 | =end original |
9222 | 11040 | |
9223 | 11041 | 整数フォーマット C<s>, C<S>, C<i>, C<I>, C<l>, C<L>, C<j>, C<J> は |
9224 | 11042 | ネイティブなバイト順序とエンディアンに従っているため、 |
9225 | 11043 | 本質的にプロセッサ間や OS 間で移植性がありません。 |
9226 | 11044 | 例えば 4 バイトの整数 0x12345678 (10 進数では 305419896) は |
9227 | 11045 | 内部では(CPU レジスタによって変換され扱われる形では) |
9228 | 11046 | 以下のようなバイト列に並べられます: |
9229 | 11047 | |
9230 | 11048 | 0x12 0x34 0x56 0x78 # big-endian |
9231 | 11049 | 0x78 0x56 0x34 0x12 # little-endian |
9232 | 11050 | |
9233 | 11051 | =begin original |
9234 | 11052 | |
9235 | 11053 | Basically, Intel and VAX CPUs are little-endian, while everybody else, |
9236 | 11054 | including Motorola m68k/88k, PPC, Sparc, HP PA, Power, and Cray, are |
9237 | big-endian. Alpha and MIPS can be either: Digital/Compaq uses (well, used) | |
11055 | big-endian. Alpha and MIPS can be either: Digital/Compaq uses (well, used) | |
9238 | 11056 | them in little-endian mode, but SGI/Cray uses them in big-endian mode. |
9239 | 11057 | |
9240 | 11058 | =end original |
9241 | 11059 | |
9242 | 基本的に、Intel と VAX の CPU はリトルエンディアンです | |
11060 | 基本的に、Intel と VAX の CPU はリトルエンディアンです; 一方、 | |
9243 | ||
11061 | Motorola m68k/88k, PPC, Sparc, HP PA, Power, Cray などを含むその他の全ては | |
9244 | ||
11062 | ビッグエンディアンです。 | |
9245 | Alpha と MIPS は両方ともあります: | |
11063 | Alpha と MIPS は両方ともあります: Digital/Compaq はリトルエンディアンモードで | |
9246 | ||
11064 | 使っています (えーと、いました) が、SGI/Cray はビッグエンディアンモードで | |
9247 | ||
11065 | 使っています。 | |
9248 | 11066 | |
9249 | 11067 | =begin original |
9250 | 11068 | |
9251 | 11069 | The names I<big-endian> and I<little-endian> are comic references to the |
9252 | 11070 | egg-eating habits of the little-endian Lilliputians and the big-endian |
9253 | 11071 | Blefuscudians from the classic Jonathan Swift satire, I<Gulliver's Travels>. |
9254 | 11072 | This entered computer lingo via the paper "On Holy Wars and a Plea for |
9255 | 11073 | Peace" by Danny Cohen, USC/ISI IEN 137, April 1, 1980. |
9256 | 11074 | |
9257 | 11075 | =end original |
9258 | 11076 | |
9259 | I<ビッグエンディアン> と I<リトルエンディアン> の名前は | |
11077 | I<ビッグエンディアン> と I<リトルエンディアン> の名前は、 | |
9260 | 古典 | |
11078 | ジョナサン=スウィフトによる風刺小説の古典 I<ガリバー旅行記> での、卵を | |
11079 | 小さい方からむくリリパット国と大きい方からむくブレフスキュ国から | |
9261 | 11080 | 取られています。 |
9262 | 11081 | "On Holy Wars and a Plea for Peace" by Danny Cohen, USC/ISI IEN 137, |
9263 | 11082 | April 1, 1980 の文書からコンピュータ用語として取り入れられました。 |
9264 | 11083 | |
9265 | 11084 | =begin original |
9266 | 11085 | |
9267 | 11086 | Some systems may have even weirder byte orders such as |
9268 | 11087 | |
9269 | 11088 | =end original |
9270 | 11089 | |
9271 | 11090 | 以下のような、さらに変わったバイト順序を持つシステムもあるかもしれません: |
9272 | 11091 | |
9273 | 11092 | 0x56 0x78 0x12 0x34 |
9274 | 11093 | 0x34 0x12 0x78 0x56 |
9275 | 11094 | |
9276 | 11095 | =begin original |
9277 | 11096 | |
11097 | These are called mid-endian, middle-endian, mixed-endian, or just weird. | |
11098 | ||
11099 | =end original | |
11100 | ||
11101 | これらは mid-endian, middle-endian, mixed-endian あるいは単におかしなものと | |
11102 | 呼ばれます。 | |
11103 | ||
11104 | =begin original | |
11105 | ||
9278 | 11106 | You can determine your system endianness with this incantation: |
9279 | 11107 | |
9280 | 11108 | =end original |
9281 | 11109 | |
9282 | 11110 | システムの設定は以下のようにして調べられます: |
9283 | 11111 | |
9284 | printf("%#02x ", $_) for unpack("W*", pack L=>0x12345678); | |
11112 | printf("%#02x ", $_) for unpack("W*", pack L=>0x12345678); | |
9285 | 11113 | |
9286 | 11114 | =begin original |
9287 | 11115 | |
9288 | 11116 | The byteorder on the platform where Perl was built is also available |
9289 | 11117 | via L<Config>: |
9290 | 11118 | |
9291 | 11119 | =end original |
9292 | 11120 | |
9293 | 11121 | Perl がビルドされたプラットフォームでのバイト順序は |
9294 | 11122 | L<Config> 経由か: |
9295 | 11123 | |
9296 | 11124 | use Config; |
9297 | 11125 | print "$Config{byteorder}\n"; |
9298 | 11126 | |
9299 | 11127 | =begin original |
9300 | 11128 | |
9301 | 11129 | or from the command line: |
9302 | 11130 | |
9303 | 11131 | =end original |
9304 | 11132 | |
9305 | 11133 | あるいはコマンドラインで: |
9306 | 11134 | |
9307 | 11135 | $ perl -V:byteorder |
9308 | 11136 | |
9309 | 11137 | =begin original |
9310 | 11138 | |
9311 | 11139 | Byteorders C<"1234"> and C<"12345678"> are little-endian; C<"4321"> |
9312 | and C<"87654321"> are big-endian. | |
11140 | and C<"87654321"> are big-endian. Systems with multiarchitecture binaries | |
11141 | will have C<"ffff">, signifying that static information doesn't work, | |
11142 | one must use runtime probing. | |
9313 | 11143 | |
9314 | 11144 | =end original |
9315 | 11145 | |
9316 | 11146 | C<"1234"> と C<"12345678"> はリトルエンディアンです; |
9317 | 11147 | C<"4321"> と C<"87654321"> はビッグエンディアンです。 |
11148 | マルチアーキテクチャバイナリを持つシステムは | |
11149 | C<"ffff"> となります; これは静的な情報は動作せず、実行時調査を使う必要が | |
11150 | あることを示します。 | |
9318 | 11151 | |
9319 | 11152 | =begin original |
9320 | 11153 | |
9321 | For portably packed integers, either use the formats C<n>, C<N>, C<v>, | |
11154 | For portably packed integers, either use the formats C<n>, C<N>, C<v>, | |
9322 | 11155 | and C<V> or else use the C<< > >> and C<< < >> modifiers described |
9323 | 11156 | immediately below. See also L<perlport>. |
9324 | 11157 | |
9325 | 11158 | =end original |
9326 | 11159 | |
9327 | 11160 | 移植性のあるパック化された整数がほしい場合は、 |
9328 | 11161 | C<n>, C<N>, C<v>, C<V> フォーマットを使うか、 |
9329 | 11162 | 直後で説明する C<< > >> と C<< < >> の修飾子が使えます。 |
9330 | L<perlport> も参照して | |
11163 | L<perlport> も参照してください。 | |
9331 | 11164 | |
9332 | 11165 | =item * |
9333 | 11166 | |
9334 | 11167 | =begin original |
9335 | 11168 | |
9336 | ||
11169 | Also floating point numbers have endianness. Usually (but not always) | |
9337 | th | |
11170 | this agrees with the integer endianness. Even though most platforms | |
11171 | these days use the IEEE 754 binary format, there are differences, | |
11172 | especially if the long doubles are involved. You can see the | |
11173 | C<Config> variables C<doublekind> and C<longdblkind> (also C<doublesize>, | |
11174 | C<longdblsize>): the "kind" values are enums, unlike C<byteorder>. | |
11175 | ||
11176 | =end original | |
11177 | ||
11178 | また、浮動小数点数にもエンディアンがあります。 | |
11179 | 通常は(但し常にではありません)これは整数のエンディアンと同じです。 | |
11180 | 最近のほとんどのプラットフォームが IEEE 754 バイナリ形式を使っているにも | |
11181 | 関わらず、(特に long double 関連で) 相違点があります。 | |
11182 | C<Config> 変数 C<doublekind> と C<longdblkind> (および C<doublesize>, | |
11183 | C<longdblsize>) を参照できます: "kind" 値は C<byteorder> と異なり、 | |
11184 | 順序値です。 | |
11185 | ||
11186 | =begin original | |
11187 | ||
11188 | Portability-wise the best option is probably to keep to the IEEE 754 | |
11189 | 64-bit doubles, and of agreed-upon endianness. Another possibility | |
11190 | is the C<"%a">) format of L<C<printf>|/printf FILEHANDLE FORMAT, LIST>. | |
11191 | ||
11192 | =end original | |
11193 | ||
11194 | 移植性を考慮した最良の選択肢はおそらく、IEEE 754 64-bit double と同意した | |
11195 | エンディアンを維持することです。 | |
11196 | もう一つの可能性は L<C<printf>|/printf FILEHANDLE FORMAT, LIST> の | |
11197 | C<"%a"> 型式です。 | |
11198 | ||
11199 | =item * | |
11200 | ||
11201 | =begin original | |
11202 | ||
11203 | Starting with Perl 5.10.0, integer and floating-point formats, along with | |
11204 | the C<p> and C<P> formats and C<()> groups, may all be followed by the | |
9338 | 11205 | C<< > >> or C<< < >> endianness modifiers to respectively enforce big- |
9339 | or little-endian byte-order. These modifiers are especially useful | |
11206 | or little-endian byte-order. These modifiers are especially useful | |
9340 | given how C<n>, C<N>, C<v>, and C<V> don't cover signed integers, | |
11207 | given how C<n>, C<N>, C<v>, and C<V> don't cover signed integers, | |
9341 | 11208 | 64-bit integers, or floating-point values. |
9342 | 11209 | |
9343 | 11210 | =end original |
9344 | 11211 | |
9345 | Perl 5. | |
11212 | Perl 5.10.0 から、C<p> と C<P> フォーマットや C<()> グループと同様、 | |
9346 | 11213 | 全ての整数と浮動小数点数のフォーマットは、C<< > >> や C<< < >> の |
9347 | 11214 | エンディアン修飾子をつけることで、それぞれ |
9348 | 11215 | ビッグエンディアンとリトルエンディアンに強制させることができます。 |
9349 | 11216 | C<n>, C<N>, C<v>, C<V> は符号付き整数、64 ビット整数、浮動小数点数に |
9350 | 11217 | 対応していないので、これは特に有用です。 |
9351 | 11218 | |
9352 | 11219 | =begin original |
9353 | 11220 | |
9354 | 11221 | Here are some concerns to keep in mind when using an endianness modifier: |
9355 | 11222 | |
9356 | 11223 | =end original |
9357 | 11224 | |
9358 | 11225 | エンディアン修飾子を使うときに心に留めておくべきことを記します: |
9359 | 11226 | |
9360 | 11227 | =over |
9361 | 11228 | |
9362 | =item * | |
11229 | =item * | |
9363 | 11230 | |
9364 | 11231 | =begin original |
9365 | 11232 | |
9366 | Exchanging signed integers between different platforms works only | |
11233 | Exchanging signed integers between different platforms works only | |
9367 | 11234 | when all platforms store them in the same format. Most platforms store |
9368 | 11235 | signed integers in two's-complement notation, so usually this is not an issue. |
9369 | 11236 | |
9370 | 11237 | =end original |
9371 | 11238 | |
9372 | 11239 | 異なったプラットフォームで符号付き整数を交換することは、全ての |
9373 | 11240 | プラットフォームで同じフォーマットで保存されている場合にのみうまくいきます。 |
9374 | 11241 | ほとんどのプラットフォームでは符号付き整数は 2 の補数記法で保存するので、 |
9375 | 11242 | 普通はこれは問題になりません。 |
9376 | 11243 | |
9377 | =item * | |
11244 | =item * | |
9378 | 11245 | |
9379 | 11246 | =begin original |
9380 | 11247 | |
9381 | 11248 | The C<< > >> or C<< < >> modifiers can only be used on floating-point |
9382 | 11249 | formats on big- or little-endian machines. Otherwise, attempting to |
9383 | 11250 | use them raises an exception. |
9384 | 11251 | |
9385 | 11252 | =end original |
9386 | 11253 | |
9387 | 11254 | C<< > >> や C<< < >> の修飾子はビッグエンディアンやリトルエンディアンの |
9388 | 11255 | マシンでの浮動小数点フォーマットでのみ使えます。 |
9389 | 11256 | それ以外では、そのようなことをすると例外が発生します。 |
9390 | 11257 | |
9391 | =item * | |
11258 | =item * | |
9392 | 11259 | |
9393 | 11260 | =begin original |
9394 | 11261 | |
9395 | 11262 | Forcing big- or little-endian byte-order on floating-point values for |
9396 | 11263 | data exchange can work only if all platforms use the same |
9397 | 11264 | binary representation such as IEEE floating-point. Even if all |
9398 | 11265 | platforms are using IEEE, there may still be subtle differences. Being able |
9399 | 11266 | to use C<< > >> or C<< < >> on floating-point values can be useful, |
9400 | 11267 | but also dangerous if you don't know exactly what you're doing. |
9401 | 11268 | It is not a general way to portably store floating-point values. |
9402 | 11269 | |
9403 | 11270 | =end original |
9404 | 11271 | |
9405 | 11272 | データ交換のために浮動小数点数のバイト順をビッグエンディアンかリトル |
9406 | 11273 | エンディアンに強制することは、全てのプラットフォームが |
9407 | 11274 | IEEE 浮動小数点フォーマットのような同じバイナリ表現の場合にのみ |
9408 | 11275 | うまくいきます。 |
9409 | 11276 | たとえ全てのプラットフォームが IEEE を使っていても、そこには微妙な違いが |
9410 | 11277 | あるかもしれません。 |
9411 | 浮動小数点数に C<< > >> や C<< < >> が使えることは便利な場合が | |
11278 | 浮動小数点数に C<< > >> や C<< < >> が使えることは便利な場合がありますが、 | |
9412 | ||
11279 | もし自分が何をしているかを正確に理解していなければ、危険です。 | |
9413 | 危険です。 | |
9414 | 11280 | 移植性のある浮動小数点数の保存のための一般的な方法はありません。 |
9415 | 11281 | |
9416 | =item * | |
11282 | =item * | |
9417 | 11283 | |
9418 | 11284 | =begin original |
9419 | 11285 | |
9420 | 11286 | When using C<< > >> or C<< < >> on a C<()> group, this affects |
9421 | 11287 | all types inside the group that accept byte-order modifiers, |
9422 | 11288 | including all subgroups. It is silently ignored for all other |
9423 | 11289 | types. You are not allowed to override the byte-order within a group |
9424 | 11290 | that already has a byte-order modifier suffix. |
9425 | 11291 | |
9426 | 11292 | =end original |
9427 | 11293 | |
9428 | 11294 | C<()> グループで C<< > >> や C<< < >> を使うと、これは、副グループを |
9429 | 11295 | 含む全ての型のうち、バイト順修飾子を受け入れる全てのものに影響与えます。 |
9430 | 11296 | その他の型については沈黙のうちに無視されます。 |
9431 | 11297 | 既にバイト順接尾辞を持っているグループ内のバイト順を上書きすることは |
9432 | 11298 | できません。 |
9433 | 11299 | |
9434 | 11300 | =back |
9435 | 11301 | |
9436 | 11302 | =item * |
9437 | 11303 | |
9438 | 11304 | =begin original |
9439 | 11305 | |
9440 | 11306 | Real numbers (floats and doubles) are in native machine format only. |
9441 | 11307 | Due to the multiplicity of floating-point formats and the lack of a |
9442 | 11308 | standard "network" representation for them, no facility for interchange has been |
9443 | 11309 | made. This means that packed floating-point data written on one machine |
9444 | 11310 | may not be readable on another, even if both use IEEE floating-point |
9445 | 11311 | arithmetic (because the endianness of the memory representation is not part |
9446 | 11312 | of the IEEE spec). See also L<perlport>. |
9447 | 11313 | |
9448 | 11314 | =end original |
9449 | 11315 | |
9450 | 11316 | 実数 (float と double) は、機種依存のフォーマットしかありません。 |
9451 | いろんな浮動小数点数のフォーマットが在り、標準的な | |
11317 | いろんな浮動小数点数のフォーマットが在り、標準的な "network" 表現といったものが | |
9452 | ||
11318 | ないため、データ交換のための機能は用意してありません。 | |
9453 | 用意してありません。 | |
9454 | 11319 | つまり、あるマシンで pack した浮動小数点数は、別のマシンでは |
9455 | 読めないかもしれないということです | |
11320 | 読めないかもしれないということです; たとえ双方で IEEE フォーマットの | |
9456 | ||
11321 | 浮動小数点数演算を行なっていてもです (IEEE の仕様では、メモリ表現上の | |
9457 | ||
11322 | バイト順序までは、規定されていないからです)。 | |
9458 | 規定されていないからです)。 | |
9459 | 11323 | L<perlport> も参照してください。 |
9460 | 11324 | |
9461 | 11325 | =begin original |
9462 | 11326 | |
9463 | 11327 | If you know I<exactly> what you're doing, you can use the C<< > >> or C<< < >> |
9464 | 11328 | modifiers to force big- or little-endian byte-order on floating-point values. |
9465 | 11329 | |
9466 | 11330 | =end original |
9467 | 11331 | |
9468 | 11332 | もし何をしようとしているのかを I<正確に> 理解しているなら、浮動小数点数の |
9469 | 11333 | バイト順をビッグエンディアンやリトルエンディアンに強制するために、 |
9470 | 11334 | C<< > >> と C<< < >> の修飾子が使えます。 |
9471 | 11335 | |
9472 | 11336 | =begin original |
9473 | 11337 | |
9474 | 11338 | Because Perl uses doubles (or long doubles, if configured) internally for |
9475 | all numeric calculation, converting from double into float and thence | |
11339 | all numeric calculation, converting from double into float and thence | |
9476 | 11340 | to double again loses precision, so C<unpack("f", pack("f", $foo)>) |
9477 | 11341 | will not in general equal $foo. |
9478 | 11342 | |
9479 | 11343 | =end original |
9480 | 11344 | |
9481 | Perl では、すべての数値演算のために、内部的に double (または | |
11345 | Perl では、すべての数値演算のために、内部的に double (または設定によっては | |
9482 | ||
11346 | long double) を使用しているので、double から float へ変換し、それから再び | |
9483 | double | |
11347 | double に戻すと精度が落ちることになり、C<unpack("f", pack("f", $foo)>) は、 | |
9484 | 精度が落ちることになり、C<unpack("f", pack("f", $foo)>) は、 | |
9485 | 11348 | 一般には $foo と同じではありません。 |
9486 | 11349 | |
9487 | 11350 | =item * |
9488 | 11351 | |
9489 | 11352 | =begin original |
9490 | 11353 | |
9491 | 11354 | Pack and unpack can operate in two modes: character mode (C<C0> mode) where |
9492 | the packed string is processed per character, and UTF-8 mode (C<U0> mode) | |
11355 | the packed string is processed per character, and UTF-8 byte mode (C<U0> mode) | |
9493 | 11356 | where the packed string is processed in its UTF-8-encoded Unicode form on |
9494 | a byte-by-byte basis. Character mode is the default | |
11357 | a byte-by-byte basis. Character mode is the default | |
9495 | ||
11358 | unless the format string starts with C<U>. You | |
9496 | ||
11359 | can always switch mode mid-format with an explicit | |
11360 | C<C0> or C<U0> in the format. This mode remains in effect until the next | |
9497 | 11361 | mode change, or until the end of the C<()> group it (directly) applies to. |
9498 | 11362 | |
9499 | 11363 | =end original |
9500 | 11364 | |
9501 | 11365 | pack と unpack は二つのモードで操作します: pack された文字列を文字単位で |
9502 | 11366 | 処理する文字モード (C<C0> モード) と、pack された文字列を、バイト毎に、 |
9503 | 11367 | その UTF-8 エンコードされた形式で処理するUTF-8 モード (C<U0> モード) です。 |
9504 | 11368 | 文字モードはフォーマット文字列が C<U> で始まっていない限りはデフォルトです。 |
9505 | 11369 | モードはフォーマット中に明示的に C<C0> または C<U0> と書くことでいつでも |
9506 | 11370 | 切り替えられます。 |
9507 | モードは次のモードに切り替えられるか、(直接)適用された () グループが | |
11371 | モードは次のモードに切り替えられるか、(直接)適用された C<()> グループが | |
9508 | 11372 | 終了するまで有効です。 |
9509 | 11373 | |
9510 | 11374 | =begin original |
9511 | 11375 | |
9512 | Using C<C0> to get Unicode characters while using C<U0> to get I<non>-Unicode | |
11376 | Using C<C0> to get Unicode characters while using C<U0> to get I<non>-Unicode | |
9513 | 11377 | bytes is not necessarily obvious. Probably only the first of these |
9514 | 11378 | is what you want: |
9515 | 11379 | |
9516 | 11380 | =end original |
9517 | 11381 | |
9518 | 11382 | Unicode 文字を取得するのに C<C0> を使い、I<非> Unicode バイトを取得するのに |
9519 | 11383 | C<U0> を使うというのは必ずしも明白ではありません。 |
9520 | 11384 | おそらく、これらのうち最初のものだけが望みのものでしょう: |
9521 | 11385 | |
9522 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | | |
11386 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | | |
9523 | 11387 | perl -CS -ne 'printf "%v04X\n", $_ for unpack("C0A*", $_)' |
9524 | 11388 | 03B1.03C9 |
9525 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | | |
11389 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | | |
9526 | 11390 | perl -CS -ne 'printf "%v02X\n", $_ for unpack("U0A*", $_)' |
9527 | 11391 | CE.B1.CF.89 |
9528 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | | |
11392 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | | |
9529 | 11393 | perl -C0 -ne 'printf "%v02X\n", $_ for unpack("C0A*", $_)' |
9530 | 11394 | CE.B1.CF.89 |
9531 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | | |
11395 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | | |
9532 | 11396 | perl -C0 -ne 'printf "%v02X\n", $_ for unpack("U0A*", $_)' |
9533 | 11397 | C3.8E.C2.B1.C3.8F.C2.89 |
9534 | 11398 | |
9535 | 11399 | =begin original |
9536 | 11400 | |
9537 | 11401 | Those examples also illustrate that you should not try to use |
9538 | C<pack>/C<unpack> | |
11402 | L<C<pack>|/pack TEMPLATE,LIST>/L<C<unpack>|/unpack TEMPLATE,EXPR> as a | |
11403 | substitute for the L<Encode> module. | |
9539 | 11404 | |
9540 | 11405 | =end original |
9541 | 11406 | |
9542 | これらの例は、C<pack>/ | |
11407 | これらの例は、L<C<pack>|/pack TEMPLATE,LIST>/ | |
11408 | L<C<unpack>|/unpack TEMPLATE,EXPR> を L<Encode> モジュールの代わりとして | |
9543 | 11409 | 使おうとするべきではないということも示しています。 |
9544 | 11410 | |
9545 | 11411 | =item * |
9546 | 11412 | |
9547 | 11413 | =begin original |
9548 | 11414 | |
9549 | 11415 | You must yourself do any alignment or padding by inserting, for example, |
9550 | enough C<"x">es while packing. There is no way for | |
11416 | enough C<"x">es while packing. There is no way for | |
9551 | ||
11417 | L<C<pack>|/pack TEMPLATE,LIST> and L<C<unpack>|/unpack TEMPLATE,EXPR> | |
11418 | to know where characters are going to or coming from, so they | |
9552 | 11419 | handle their output and input as flat sequences of characters. |
9553 | 11420 | |
9554 | 11421 | =end original |
9555 | 11422 | |
9556 | 11423 | pack するときに、例えば十分な数の C<"x"> を挿入することによって |
9557 | 11424 | アライメントやパッディングを行うのは全て自分でしなければなりません。 |
9558 | ||
11425 | L<C<pack>|/pack TEMPLATE,LIST> や L<C<unpack>|/unpack TEMPLATE,EXPR> は、 | |
9559 | ||
11426 | 文字列がどこへ行くかやどこから来たかを | |
9560 | 文字列として扱います。 | |
11427 | 知る方法はないので、出力と入力をフラットな文字列として扱います。 | |
9561 | 11428 | |
9562 | 11429 | =item * |
9563 | 11430 | |
9564 | 11431 | =begin original |
9565 | 11432 | |
9566 | 11433 | A C<()> group is a sub-TEMPLATE enclosed in parentheses. A group may |
9567 | take a repeat count either as postfix, or for | |
11434 | take a repeat count either as postfix, or for | |
11435 | L<C<unpack>|/unpack TEMPLATE,EXPR>, also via the C</> | |
9568 | 11436 | template character. Within each repetition of a group, positioning with |
9569 | C<@> starts over at 0. Therefore, the result of | |
11437 | C<@> starts over at 0. Therefore, the result of | |
9570 | 11438 | |
9571 | 11439 | =end original |
9572 | 11440 | |
9573 | 11441 | C<()> のグループはかっこで囲われた副テンプレートです。 |
9574 | グループは繰り返し数を取ることができます; 接尾辞によるか、 | |
11442 | グループは繰り返し数を取ることができます; 接尾辞によるか、 | |
9575 | C</> テンプレート文字によります。 | |
11443 | L<C<unpack>|/unpack TEMPLATE,EXPR> の場合は C</> テンプレート文字によります。 | |
9576 | 11444 | グループの繰り返し毎に、C<@> の位置は 0 になります。 |
9577 | 11445 | 従って、以下の結果は: |
9578 | 11446 | |
9579 | 11447 | pack("@1A((@2A)@3A)", qw[X Y Z]) |
9580 | 11448 | |
9581 | 11449 | =begin original |
9582 | 11450 | |
9583 | 11451 | is the string C<"\0X\0\0YZ">. |
9584 | 11452 | |
9585 | 11453 | =end original |
9586 | 11454 | |
9587 | 11455 | 文字列 C<"\0X\0\0YZ"> です。 |
9588 | 11456 | |
9589 | 11457 | =item * |
9590 | 11458 | |
9591 | 11459 | =begin original |
9592 | 11460 | |
9593 | 11461 | C<x> and C<X> accept the C<!> modifier to act as alignment commands: they |
9594 | 11462 | jump forward or back to the closest position aligned at a multiple of C<count> |
9595 | characters. For example, to pack | |
11463 | characters. For example, to L<C<pack>|/pack TEMPLATE,LIST> or | |
11464 | L<C<unpack>|/unpack TEMPLATE,EXPR> a C structure like | |
9596 | 11465 | |
9597 | 11466 | =end original |
9598 | 11467 | |
9599 | 11468 | C<x> と C<X> にはアライメントコマンドとして C<!> 修飾子を付けることができます: |
9600 | 11469 | これは C<count> 文字の倍数のアライメントとなる、もっとも近い位置に移動します。 |
9601 | 例えば、以下のような構造体を pack | |
11470 | 例えば、以下のような C 構造体を L<C<pack>|/pack TEMPLATE,LIST> または | |
11471 | L<C<unpack>|/unpack TEMPLATE,EXPR> するには | |
9602 | 11472 | |
9603 | 11473 | struct { |
9604 | 11474 | char c; /* one signed, 8-bit character */ |
9605 | double d; | |
11475 | double d; | |
9606 | 11476 | char cc[2]; |
9607 | 11477 | } |
9608 | 11478 | |
9609 | 11479 | =begin original |
9610 | 11480 | |
9611 | 11481 | one may need to use the template C<c x![d] d c[2]>. This assumes that |
9612 | 11482 | doubles must be aligned to the size of double. |
9613 | 11483 | |
9614 | 11484 | =end original |
9615 | 11485 | |
9616 | 11486 | C<W x![d] d W[2]> というテンプレートを使う必要があるかもしれません。 |
9617 | 11487 | これは double が double のサイズでアライメントされていることを |
9618 | 11488 | 仮定しています。 |
9619 | 11489 | |
9620 | 11490 | =begin original |
9621 | 11491 | |
9622 | 11492 | For alignment commands, a C<count> of 0 is equivalent to a C<count> of 1; |
9623 | 11493 | both are no-ops. |
9624 | 11494 | |
9625 | 11495 | =end original |
9626 | 11496 | |
9627 | アライメントコマンドに対しては、C<count> に 0 を指定するのは | |
11497 | アライメントコマンドに対しては、C<count> に 0 を指定するのは | |
9628 | 指定するのと等価です; どちらも何もしません。 | |
11498 | C<count> に 1 を指定するのと等価です; どちらも何もしません。 | |
9629 | 11499 | |
9630 | 11500 | =item * |
9631 | 11501 | |
9632 | 11502 | =begin original |
9633 | 11503 | |
9634 | 11504 | C<n>, C<N>, C<v> and C<V> accept the C<!> modifier to |
9635 | 11505 | represent signed 16-/32-bit integers in big-/little-endian order. |
9636 | 11506 | This is portable only when all platforms sharing packed data use the |
9637 | 11507 | same binary representation for signed integers; for example, when all |
9638 | 11508 | platforms use two's-complement representation. |
9639 | 11509 | |
9640 | 11510 | =end original |
9641 | 11511 | |
9642 | C<n>, C<N>, C<v>, C<V> は | |
11512 | C<n>, C<N>, C<v>, C<V> はビッグ/リトルエンディアンの順序で符号付き 16 または | |
9643 | ビッグ/リトルエンディアンの順序で符号付き 16 または | |
9644 | 11513 | 32 ビット整数で表現するための C<!> 修飾子を受け入れます。 |
9645 | 11514 | これは pack されたデータを共有する全てのプラットフォームが |
9646 | 11515 | 符号付き整数について同じバイナリ表現を使う場合にのみ移植性があります; |
9647 | 11516 | 例えば、全てのプラットフォームで 2 の補数表現を使う場合です。 |
9648 | 11517 | |
9649 | 11518 | =item * |
9650 | 11519 | |
9651 | 11520 | =begin original |
9652 | 11521 | |
9653 | 11522 | Comments can be embedded in a TEMPLATE using C<#> through the end of line. |
9654 | 11523 | White space can separate pack codes from each other, but modifiers and |
9655 | 11524 | repeat counts must follow immediately. Breaking complex templates into |
9656 | 11525 | individual line-by-line components, suitably annotated, can do as much to |
9657 | 11526 | improve legibility and maintainability of pack/unpack formats as C</x> can |
9658 | 11527 | for complicated pattern matches. |
9659 | 11528 | |
9660 | 11529 | =end original |
9661 | 11530 | |
9662 | 11531 | TEMPLATE の中の C<#> から行末まではコメントです。 |
9663 | 11532 | 空白は pack コードをそれぞれ分けるために使えますが、修飾子と |
9664 | 11533 | 繰り返し数は直後に置かなければなりません。 |
9665 | 11534 | 複雑なテンプレートを個々の行単位の要素に分解して適切に注釈をつけると、 |
9666 | 11535 | 複雑なパターンマッチングに対する C</x> と同じぐらい、pack/unpack |
9667 | 11536 | フォーマットの読みやすさと保守性が向上します。 |
9668 | 11537 | |
9669 | 11538 | =item * |
9670 | 11539 | |
9671 | 11540 | =begin original |
9672 | 11541 | |
9673 | If TEMPLATE requires more arguments than pack | |
11542 | If TEMPLATE requires more arguments than L<C<pack>|/pack TEMPLATE,LIST> | |
11543 | is given, L<C<pack>|/pack TEMPLATE,LIST> | |
9674 | 11544 | assumes additional C<""> arguments. If TEMPLATE requires fewer arguments |
9675 | 11545 | than given, extra arguments are ignored. |
9676 | 11546 | |
9677 | 11547 | =end original |
9678 | 11548 | |
9679 | TEMPLATE が要求する引数の数が pack | |
11549 | TEMPLATE が要求する引数の数が L<C<pack>|/pack TEMPLATE,LIST> が実際に | |
9680 | ||
11550 | 与えている数より多い場合、 | |
11551 | L<C<pack>|/pack TEMPLATE,LIST> は追加の C<""> 引数があるものと仮定します。 | |
9681 | 11552 | TEMPLATE が要求する引数の数の方が少ない場合、余分の引数は無視されます。 |
9682 | 11553 | |
11554 | =item * | |
11555 | ||
11556 | =begin original | |
11557 | ||
11558 | Attempting to pack the special floating point values C<Inf> and C<NaN> | |
11559 | (infinity, also in negative, and not-a-number) into packed integer values | |
11560 | (like C<"L">) is a fatal error. The reason for this is that there simply | |
11561 | isn't any sensible mapping for these special values into integers. | |
11562 | ||
11563 | =end original | |
11564 | ||
11565 | 特殊浮動小数点値 C<Inf> と C<NaN> | |
11566 | ((負を含む)無限と非数) を (C<"L"> のような) 整数値に pack しようとすると | |
11567 | 致命的エラーとなります。 | |
11568 | この理由は、単に特殊値を整数に割り当てられないからです。 | |
11569 | ||
9683 | 11570 | =back |
9684 | 11571 | |
9685 | 11572 | =begin original |
9686 | 11573 | |
9687 | 11574 | Examples: |
9688 | 11575 | |
9689 | 11576 | =end original |
9690 | 11577 | |
9691 | 11578 | 例: |
9692 | 11579 | |
9693 | 11580 | $foo = pack("WWWW",65,66,67,68); |
9694 | 11581 | # foo eq "ABCD" |
9695 | 11582 | $foo = pack("W4",65,66,67,68); |
9696 | 11583 | # same thing |
9697 | 11584 | $foo = pack("W4",0x24b6,0x24b7,0x24b8,0x24b9); |
9698 | 11585 | # same thing with Unicode circled letters. |
9699 | 11586 | $foo = pack("U4",0x24b6,0x24b7,0x24b8,0x24b9); |
9700 | # same thing with Unicode circled letters. You don't get the | |
11587 | # same thing with Unicode circled letters. You don't get the | |
9701 | # bytes because the U at the start of the format caused | |
11588 | # UTF-8 bytes because the U at the start of the format caused | |
9702 | # U0-mode, so the UTF-8 bytes get joined into | |
11589 | # a switch to U0-mode, so the UTF-8 bytes get joined into | |
11590 | # characters | |
9703 | 11591 | $foo = pack("C0U4",0x24b6,0x24b7,0x24b8,0x24b9); |
9704 | 11592 | # foo eq "\xe2\x92\xb6\xe2\x92\xb7\xe2\x92\xb8\xe2\x92\xb9" |
9705 | # This is the UTF-8 encoding of the string in the | |
11593 | # This is the UTF-8 encoding of the string in the | |
11594 | # previous example | |
9706 | 11595 | |
9707 | 11596 | $foo = pack("ccxxcc",65,66,67,68); |
9708 | 11597 | # foo eq "AB\0\0CD" |
9709 | 11598 | |
9710 | 11599 | # NOTE: The examples above featuring "W" and "c" are true |
9711 | 11600 | # only on ASCII and ASCII-derived systems such as ISO Latin 1 |
9712 | 11601 | # and UTF-8. On EBCDIC systems, the first example would be |
9713 | 11602 | # $foo = pack("WWWW",193,194,195,196); |
9714 | 11603 | |
9715 | 11604 | $foo = pack("s2",1,2); |
9716 | 11605 | # "\001\000\002\000" on little-endian |
9717 | 11606 | # "\000\001\000\002" on big-endian |
9718 | 11607 | |
9719 | 11608 | $foo = pack("a4","abcd","x","y","z"); |
9720 | 11609 | # "abcd" |
9721 | 11610 | |
9722 | 11611 | $foo = pack("aaaa","abcd","x","y","z"); |
9723 | 11612 | # "axyz" |
9724 | 11613 | |
9725 | 11614 | $foo = pack("a14","abcdefg"); |
9726 | 11615 | # "abcdefg\0\0\0\0\0\0\0" |
9727 | 11616 | |
9728 | 11617 | $foo = pack("i9pl", gmtime); |
9729 | 11618 | # a real struct tm (on my system anyway) |
9730 | 11619 | |
9731 | 11620 | $utmp_template = "Z8 Z8 Z16 L"; |
9732 | 11621 | $utmp = pack($utmp_template, @utmp1); |
9733 | 11622 | # a struct utmp (BSDish) |
9734 | 11623 | |
9735 | 11624 | @utmp2 = unpack($utmp_template, $utmp); |
9736 | 11625 | # "@utmp1" eq "@utmp2" |
9737 | 11626 | |
9738 | 11627 | sub bintodec { |
9739 | 11628 | unpack("N", pack("B32", substr("0" x 32 . shift, -32))); |
9740 | 11629 | } |
9741 | 11630 | |
9742 | 11631 | $foo = pack('sx2l', 12, 34); |
9743 | 11632 | # short 12, two zero bytes padding, long 34 |
9744 | 11633 | $bar = pack('s@4l', 12, 34); |
9745 | 11634 | # short 12, zero fill to position 4, long 34 |
9746 | 11635 | # $foo eq $bar |
9747 | 11636 | $baz = pack('s.l', 12, 4, 34); |
9748 | 11637 | # short 12, zero fill to position 4, long 34 |
9749 | 11638 | |
9750 | 11639 | $foo = pack('nN', 42, 4711); |
9751 | 11640 | # pack big-endian 16- and 32-bit unsigned integers |
9752 | 11641 | $foo = pack('S>L>', 42, 4711); |
9753 | 11642 | # exactly the same |
9754 | 11643 | $foo = pack('s<l<', -42, 4711); |
9755 | 11644 | # pack little-endian 16- and 32-bit signed integers |
9756 | 11645 | $foo = pack('(sl)<', -42, 4711); |
9757 | 11646 | # exactly the same |
9758 | 11647 | |
9759 | 11648 | =begin original |
9760 | 11649 | |
9761 | The same template may generally also be used in | |
11650 | The same template may generally also be used in | |
11651 | L<C<unpack>|/unpack TEMPLATE,EXPR>. | |
9762 | 11652 | |
9763 | 11653 | =end original |
9764 | 11654 | |
9765 | 一般には、 | |
11655 | 一般的には、同じテンプレートが L<C<unpack>|/unpack TEMPLATE,EXPR> でも | |
9766 | ||
11656 | 使用できます。 | |
9767 | 11657 | |
9768 | 11658 | =item package NAMESPACE |
9769 | 11659 | |
9770 | 11660 | =item package NAMESPACE VERSION |
9771 | 11661 | X<package> X<module> X<namespace> X<version> |
9772 | 11662 | |
9773 | 11663 | =item package NAMESPACE BLOCK |
9774 | 11664 | |
9775 | 11665 | =item package NAMESPACE VERSION BLOCK |
9776 | 11666 | X<package> X<module> X<namespace> X<version> |
9777 | 11667 | |
11668 | =for Pod::Functions declare a separate global namespace | |
11669 | ||
9778 | 11670 | =begin original |
9779 | 11671 | |
9780 | 11672 | Declares the BLOCK or the rest of the compilation unit as being in the |
9781 | 11673 | given namespace. The scope of the package declaration is either the |
9782 | 11674 | supplied code BLOCK or, in the absence of a BLOCK, from the declaration |
9783 | 11675 | itself through the end of current scope (the enclosing block, file, or |
9784 | C<eval>). That is, the forms without a BLOCK are | |
11676 | L<C<eval>|/eval EXPR>). That is, the forms without a BLOCK are | |
9785 | of the current scope, just like the | |
11677 | operative through the end of the current scope, just like the | |
9786 | ||
11678 | L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>, and | |
9787 | ||
11679 | L<C<our>|/our VARLIST> operators. All unqualified dynamic identifiers | |
11680 | in this scope will be in the given namespace, except where overridden by | |
11681 | another L<C<package>|/package NAMESPACE> declaration or | |
9788 | 11682 | when they're one of the special identifiers that qualify into C<main::>, |
9789 | 11683 | like C<STDOUT>, C<ARGV>, C<ENV>, and the punctuation variables. |
9790 | 11684 | |
9791 | 11685 | =end original |
9792 | 11686 | |
9793 | 11687 | BLOCK や残りのコンパイル単位を与えられた名前空間として宣言します。 |
9794 | 11688 | パッケージ宣言のスコープは BLOCK か、BLOCK がないばあいは宣言自身から |
9795 | 現在のスコープの末尾 (閉じたブロック、ファイル、C<eval>) です。 | |
11689 | 現在のスコープの末尾 (閉じたブロック、ファイル、L<C<eval>|/eval EXPR>) です。 | |
9796 | つまり、BLOCK なしの形式は、C<my>, C<state> | |
11690 | つまり、BLOCK なしの形式は、L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>, | |
9797 | 現在のスコープの末尾にまで作用します。 | |
11691 | L<C<our>|/our VARLIST> 演算子と同様に現在のスコープの末尾にまで作用します。 | |
9798 | 11692 | このスコープ内の、全ての完全修飾されていない動的識別子は、他の |
9799 | C<package> 宣言によって上書きされるか、 | |
11693 | L<C<package>|/package NAMESPACE> 宣言によって上書きされるか、 | |
9800 | 11694 | C<STDOUT>, C<ARGV>, C<ENV> や句読点変数のように C<main::> に |
9801 | 11695 | 割り当てられる特殊変数でない限り、指定された |
9802 | 11696 | 名前空間になります。 |
9803 | 11697 | |
9804 | 11698 | =begin original |
9805 | 11699 | |
9806 | 11700 | A package statement affects dynamic variables only, including those |
9807 | you've used C<local> on, but I<not> lexical | |
11701 | you've used L<C<local>|/local EXPR> on, but I<not> lexically-scoped | |
9808 | ||
11702 | variables, which are created with L<C<my>|/my VARLIST>, | |
9809 | ||
11703 | L<C<state>|/state VARLIST>, or L<C<our>|/our VARLIST>. Typically it | |
9810 | ||
11704 | would be the first declaration in a file included by | |
11705 | L<C<require>|/require VERSION> or L<C<use>|/use Module VERSION LIST>. | |
11706 | You can switch into a | |
11707 | package in more than one place, since this only determines which default | |
9811 | 11708 | symbol table the compiler uses for the rest of that block. You can refer to |
9812 | 11709 | identifiers in other packages than the current one by prefixing the identifier |
9813 | 11710 | with the package name and a double colon, as in C<$SomePack::var> |
9814 | 11711 | or C<ThatPack::INPUT_HANDLE>. If package name is omitted, the C<main> |
9815 | 11712 | package as assumed. That is, C<$::sail> is equivalent to |
9816 | 11713 | C<$main::sail> (as well as to C<$main'sail>, still seen in ancient |
9817 | 11714 | code, mostly from Perl 4). |
9818 | 11715 | |
9819 | 11716 | =end original |
9820 | 11717 | |
9821 | package 文は動的変数にのみ影響します(C<local> で使ったものも | |
11718 | package 文は動的変数にのみ影響します(L<C<local>|/local EXPR> で使ったものも | |
9822 | 含みます)が、C<my>, C<state> | |
11719 | 含みます)が、L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>, | |
9823 | ||
11720 | L<C<our>|/our VARLIST> のいずれかで作成された | |
9824 | ||
11721 | レキシカルなスコープの変数には I<影響しません>。 | |
11722 | 典型的にはこれは L<C<require>|/require VERSION> や | |
11723 | L<C<use>|/use Module VERSION LIST> 演算子でインクルードされるファイルの | |
9825 | 11724 | 最初に宣言されます。 |
9826 | 11725 | パッケージを複数の場所で切り替えることができます; |
9827 | 11726 | なぜならこれは単にコンパイラがこのブロックの残りに対してどの |
9828 | 11727 | シンボルテーブルを使うかにのみ影響するからです。 |
9829 | 11728 | 他のパッケージの識別子は、C<$SomePack::var> や |
9830 | 11729 | C<ThatPack::INPUT_HANDLE> のように、識別子にパッケージ名と |
9831 | 11730 | コロン二つをつけることで参照できます。 |
9832 | 11731 | パッケージ名が省略された場合、C<main> パッケージが仮定されます。 |
9833 | 11732 | つまり、C<$::sail> は C<$main::sail> と等価です(ほとんどは Perl 4 からの、 |
9834 | 11733 | 古いコードでは C<$main'sail> もまだ見られます)。 |
9835 | 11734 | |
9836 | 11735 | =begin original |
9837 | 11736 | |
9838 | If VERSION is provided, C<package> | |
11737 | If VERSION is provided, L<C<package>|/package NAMESPACE> sets the | |
11738 | C<$VERSION> variable in the given | |
9839 | 11739 | namespace to a L<version> object with the VERSION provided. VERSION must be a |
9840 | 11740 | "strict" style version number as defined by the L<version> module: a positive |
9841 | 11741 | decimal number (integer or decimal-fraction) without exponentiation or else a |
9842 | 11742 | dotted-decimal v-string with a leading 'v' character and at least three |
9843 | 11743 | components. You should set C<$VERSION> only once per package. |
9844 | 11744 | |
9845 | 11745 | =end original |
9846 | 11746 | |
9847 | VERSION が指定されると、C<package> は与えられた | |
11747 | VERSION が指定されると、L<C<package>|/package NAMESPACE> は与えられた | |
11748 | 名前空間の C<$VERSION> 変数に、 | |
9848 | 11749 | 指定された VERSION の L<version> オブジェクトをセットします。 |
9849 | 11750 | VERSION は L<version> で定義されている「厳密な」形式のバージョン番号で |
9850 | 11751 | なければなりません: 指数のない正の 10 進数 (整数か 10 進小数) か、 |
9851 | 11752 | さもなければ先頭に 'v' の文字が付いて、少なくとも三つの部分から |
9852 | 11753 | 構成されるドット付き 10 進v-文字列です。 |
9853 | 11754 | C<$VERSION> はパッケージ毎に 1 回だけセットするべきです。 |
9854 | 11755 | |
9855 | 11756 | =begin original |
9856 | 11757 | |
9857 | 11758 | See L<perlmod/"Packages"> for more information about packages, modules, |
9858 | 11759 | and classes. See L<perlsub> for other scoping issues. |
9859 | 11760 | |
9860 | 11761 | =end original |
9861 | 11762 | |
9862 | 11763 | パッケージ、モジュール、クラスに関するさらなる情報については |
9863 | 11764 | L<perlmod/"Packages"> を参照してください。 |
9864 | 11765 | その他のスコープに関する話題については L<perlsub> を参照してください。 |
9865 | 11766 | |
11767 | =item __PACKAGE__ | |
11768 | X<__PACKAGE__> | |
11769 | ||
11770 | =for Pod::Functions +5.004 the current package | |
11771 | ||
11772 | =begin original | |
11773 | ||
11774 | A special token that returns the name of the package in which it occurs. | |
11775 | ||
11776 | =end original | |
11777 | ||
11778 | これが書いてあるパッケージの名前を返す特殊トークン。 | |
11779 | ||
9866 | 11780 | =item pipe READHANDLE,WRITEHANDLE |
9867 | 11781 | X<pipe> |
9868 | 11782 | |
11783 | =for Pod::Functions open a pair of connected filehandles | |
11784 | ||
9869 | 11785 | =begin original |
9870 | 11786 | |
9871 | 11787 | Opens a pair of connected pipes like the corresponding system call. |
9872 | 11788 | Note that if you set up a loop of piped processes, deadlock can occur |
9873 | 11789 | unless you are very careful. In addition, note that Perl's pipes use |
9874 | IO buffering, so you may need to set C<$ | |
11790 | IO buffering, so you may need to set L<C<$E<verbar>>|perlvar/$E<verbar>> | |
9875 | after each command, depending on the | |
11791 | to flush your WRITEHANDLE after each command, depending on the | |
11792 | application. | |
9876 | 11793 | |
9877 | 11794 | =end original |
9878 | 11795 | |
9879 | 対応するシステムコールと同じように、 | |
11796 | 対応するシステムコールと同じように、接続されたパイプのペアを開きます。 | |
9880 | 接続されたパイプのペアをオープンします。 | |
9881 | 11797 | パイプでプロセスをループにするときには、よほど気を付けないと、 |
9882 | 11798 | デッドロックが起こり得ます。 |
9883 | さらに、Perl のパイプでは、IO のバッファリングを使 | |
11799 | さらに、Perl のパイプでは、IO のバッファリングを使ので、 | |
9884 | 11800 | アプリケーションによっては、コマンドごとに WRITEHANDLE を |
9885 | フラッシュするように、C<$|> を設定することが | |
11801 | フラッシュするように、L<C<$E<verbar>>|perlvar/$E<verbar>> を設定することが | |
11802 | 必要になるかもしれません。 | |
9886 | 11803 | |
9887 | 11804 | =begin original |
9888 | 11805 | |
11806 | Returns true on success. | |
11807 | ||
11808 | =end original | |
11809 | ||
11810 | 成功時には真を返します。 | |
11811 | ||
11812 | =begin original | |
11813 | ||
9889 | 11814 | See L<IPC::Open2>, L<IPC::Open3>, and |
9890 | 11815 | L<perlipc/"Bidirectional Communication with Another Process"> |
9891 | 11816 | for examples of such things. |
9892 | 11817 | |
9893 | 11818 | =end original |
9894 | 11819 | |
9895 | 11820 | これらに関する例については、L<IPC::Open2>, L<IPC::Open3>, |
9896 | 11821 | L<perlipc/"Bidirectional Communication with Another Process"> を |
9897 | 参照して | |
11822 | 参照してください。 | |
9898 | 11823 | |
9899 | 11824 | =begin original |
9900 | 11825 | |
9901 | 11826 | On systems that support a close-on-exec flag on files, that flag is set |
9902 | on all newly opened file descriptors whose | |
11827 | on all newly opened file descriptors whose | |
9903 | ||
11828 | L<C<fileno>|/fileno FILEHANDLE>s are I<higher> than the current value of | |
11829 | L<C<$^F>|perlvar/$^F> (by default 2 for C<STDERR>). See L<perlvar/$^F>. | |
9904 | 11830 | |
9905 | 11831 | =end original |
9906 | 11832 | |
9907 | 11833 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
9908 | 11834 | 新しくオープンされたファイル記述子のうち、 |
9909 | C<fileno> が現在の $^F | |
11835 | L<C<fileno>|/fileno FILEHANDLE> が現在の L<C<$^F>|perlvar/$^F> の値 | |
11836 | (デフォルトでは C<STDERR> の 2) | |
9910 | 11837 | I<よりも大きい> ものに対してフラグがセットされます。 |
9911 | 11838 | L<perlvar/$^F> を参照してください。 |
9912 | 11839 | |
9913 | 11840 | =item pop ARRAY |
9914 | 11841 | X<pop> X<stack> |
9915 | 11842 | |
9916 | =item pop EXPR | |
9917 | ||
9918 | 11843 | =item pop |
9919 | 11844 | |
11845 | =for Pod::Functions remove the last element from an array and return it | |
11846 | ||
9920 | 11847 | =begin original |
9921 | 11848 | |
9922 | 11849 | Pops and returns the last value of the array, shortening the array by |
9923 | 11850 | one element. |
9924 | 11851 | |
9925 | 11852 | =end original |
9926 | 11853 | |
9927 | 11854 | 配列の最後の値をポップして返し、配列の大きさを 1 だけ小さくします。 |
9928 | 11855 | |
9929 | 11856 | =begin original |
9930 | 11857 | |
9931 | Returns the undefined value if the array is empty, although this may | |
11858 | Returns the undefined value if the array is empty, although this may | |
9932 | happen at other times. If ARRAY is omitted, pops | |
11859 | also happen at other times. If ARRAY is omitted, pops the | |
9933 | ||
11860 | L<C<@ARGV>|perlvar/@ARGV> array in the main program, but the | |
11861 | L<C<@_>|perlvar/@_> array in subroutines, just like | |
11862 | L<C<shift>|/shift ARRAY>. | |
9934 | 11863 | |
9935 | 11864 | =end original |
9936 | 11865 | |
9937 | 11866 | 指定された配列に要素がなければ未定義値が返されますが、 |
9938 | 11867 | しかしこれは他の場合にも起こり得ます。 |
9939 | ARRAY が省略されると、C<shift> と同様に、メインプログラムでは | |
11868 | ARRAY が省略されると、L<C<shift>|/shift ARRAY> と同様に、メインプログラムでは | |
9940 | ||
11869 | L<C<@ARGV>|perlvar/@ARGV> が使われますが、 | |
11870 | サブルーチンでは L<C<@_>|perlvar/@_> が使われます。 | |
9941 | 11871 | |
9942 | 11872 | =begin original |
9943 | 11873 | |
9944 | Starting with Perl 5.14, | |
11874 | Starting with Perl 5.14, an experimental feature allowed | |
9945 | ||
11875 | L<C<pop>|/pop ARRAY> to take a | |
9946 | ||
11876 | scalar expression. This experiment has been deemed unsuccessful, and was | |
9947 | ||
11877 | removed as of Perl 5.24. | |
9948 | 11878 | |
9949 | 11879 | =end original |
9950 | 11880 | |
9951 | Perl 5.14 から、C<pop> | |
11881 | Perl 5.14 から、L<C<pop>|/pop ARRAY> がスカラ式を取ることが出来るという | |
9952 | ||
11882 | 実験的機能がありました。 | |
9953 | ||
11883 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 | |
9954 | C<pop> のこの動作は高度に実験的であると考えられています。 | |
9955 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 | |
9956 | 11884 | |
9957 | 11885 | =item pos SCALAR |
9958 | 11886 | X<pos> X<match, position> |
9959 | 11887 | |
9960 | 11888 | =item pos |
9961 | 11889 | |
11890 | =for Pod::Functions find or set the offset for the last/next m//g search | |
11891 | ||
9962 | 11892 | =begin original |
9963 | 11893 | |
9964 | 11894 | Returns the offset of where the last C<m//g> search left off for the |
9965 | variable in question (C<$_> is used when the variable is not | |
11895 | variable in question (L<C<$_>|perlvar/$_> is used when the variable is not | |
9966 | specified). Note that 0 is a valid match offset. | |
11896 | specified). Note that 0 is a valid match offset. | |
11897 | L<C<undef>|/undef EXPR> indicates | |
9967 | 11898 | that the search position is reset (usually due to match failure, but |
9968 | 11899 | can also be because no match has yet been run on the scalar). |
9969 | 11900 | |
9970 | 11901 | =end original |
9971 | 11902 | |
9972 | 11903 | 対象の変数に対して、前回の C<m//g> が終了した場所の |
9973 | オフセットを返します(変数が指定されなかった場合は C<$_> が | |
11904 | オフセットを返します(変数が指定されなかった場合は L<C<$_>|perlvar/$_> が | |
11905 | 使われます)。 | |
9974 | 11906 | 0 は有効なマッチオフセットであることに注意してください。 |
9975 | C<undef> は検索位置がリセットされることを意味します (通常は | |
11907 | L<C<undef>|/undef EXPR> は検索位置がリセットされることを意味します (通常は | |
9976 | 原因ですが、このスカラ値にまだマッチングが | |
11908 | マッチ失敗が原因ですが、このスカラ値にまだマッチングが | |
11909 | 行われていないためかもしれません)。 | |
9977 | 11910 | |
9978 | 11911 | =begin original |
9979 | 11912 | |
9980 | C<pos> directly accesses the location used by the regexp | |
11913 | L<C<pos>|/pos SCALAR> directly accesses the location used by the regexp | |
9981 | store the offset, so assigning to C<pos> will | |
11914 | engine to store the offset, so assigning to L<C<pos>|/pos SCALAR> will | |
9982 | so will also influence the C<\G> zero-width | |
11915 | change that offset, and so will also influence the C<\G> zero-width | |
9983 | expressions. Both of these effects take place for | |
11916 | assertion in regular expressions. Both of these effects take place for | |
9984 | you can't affect the position with | |
11917 | the next match, so you can't affect the position with | |
9985 | ||
11918 | L<C<pos>|/pos SCALAR> during the current match, such as in | |
11919 | C<(?{pos() = 5})> or C<s//pos() = 5/e>. | |
9986 | 11920 | |
9987 | 11921 | =end original |
9988 | 11922 | |
9989 | C<pos> は正規表現エンジンがオフセットを保存するために使う場所を | |
11923 | L<C<pos>|/pos SCALAR> は正規表現エンジンがオフセットを保存するために使う場所を | |
9990 | アクセスするので、C<pos> への代入はオフセットを変更し、 | |
11924 | 直接アクセスするので、L<C<pos>|/pos SCALAR> への代入はオフセットを変更し、 | |
9991 | 正規表現における C<\G> ゼロ幅アサートにも影響を与えます。 | |
11925 | そのような変更は正規表現における C<\G> ゼロ幅アサートにも影響を与えます。 | |
9992 | 11926 | これらの効果の両方は次のマッチングのために行われるので、 |
9993 | 11927 | C<(?{pos() = 5})> や C<s//pos() = 5/e> のように現在のマッチング中の |
9994 | C<pos> の位置には影響を与えません。 | |
11928 | L<C<pos>|/pos SCALAR> の位置には影響を与えません。 | |
9995 | 11929 | |
9996 | 11930 | =begin original |
9997 | 11931 | |
9998 | Setting C<pos> also resets the I<matched with | |
11932 | Setting L<C<pos>|/pos SCALAR> also resets the I<matched with | |
11933 | zero-length> flag, described | |
9999 | 11934 | under L<perlre/"Repeated Patterns Matching a Zero-length Substring">. |
10000 | 11935 | |
10001 | 11936 | =end original |
10002 | 11937 | |
10003 | C<pos> を設定すると、 | |
11938 | L<C<pos>|/pos SCALAR> を設定すると、 | |
10004 | 11939 | L<perlre/"Repeated Patterns Matching a Zero-length Substring"> に |
10005 | 11940 | 記述されている、I<長さ 0 でマッチング> フラグもリセットされます。 |
10006 | 11941 | |
10007 | 11942 | =begin original |
10008 | 11943 | |
10009 | 11944 | Because a failed C<m//gc> match doesn't reset the offset, the return |
10010 | from C<pos> won't change either in this case. See | |
11945 | from L<C<pos>|/pos SCALAR> won't change either in this case. See | |
10011 | L<perlop>. | |
11946 | L<perlre> and L<perlop>. | |
10012 | 11947 | |
10013 | 11948 | =end original |
10014 | 11949 | |
10015 | 11950 | C<m//gc> マッチに失敗してもオフセットはリセットしないので、 |
10016 | C<pos> からの返り値はどちらの場合も変更されません。 | |
11951 | L<C<pos>|/pos SCALAR> からの返り値はどちらの場合も変更されません。 | |
10017 | 11952 | L<perlre> と L<perlop> を参照してください。 |
10018 | 11953 | |
10019 | 11954 | =item print FILEHANDLE LIST |
10020 | 11955 | X<print> |
10021 | 11956 | |
10022 | 11957 | =item print FILEHANDLE |
10023 | 11958 | |
10024 | 11959 | =item print LIST |
10025 | 11960 | |
10026 | 11961 | =item print |
10027 | 11962 | |
11963 | =for Pod::Functions output a list to a filehandle | |
11964 | ||
10028 | 11965 | =begin original |
10029 | 11966 | |
10030 | 11967 | Prints a string or a list of strings. Returns true if successful. |
10031 | 11968 | FILEHANDLE may be a scalar variable containing the name of or a reference |
10032 | 11969 | to the filehandle, thus introducing one level of indirection. (NOTE: If |
10033 | 11970 | FILEHANDLE is a variable and the next token is a term, it may be |
10034 | 11971 | misinterpreted as an operator unless you interpose a C<+> or put |
10035 | parentheses around the arguments.) If FILEHANDLE is omitted, prints to the | |
11972 | parentheses around the arguments.) If FILEHANDLE is omitted, prints to the | |
10036 | last selected (see L</select>) output handle. If | |
11973 | last selected (see L<C<select>|/select FILEHANDLE>) output handle. If | |
10037 | C<$_> to the currently selected | |
11974 | LIST is omitted, prints L<C<$_>|perlvar/$_> to the currently selected | |
10038 | p | |
11975 | output handle. To use FILEHANDLE alone to print the content of | |
11976 | L<C<$_>|perlvar/$_> to it, you must use a bareword filehandle like | |
10039 | 11977 | C<FH>, not an indirect one like C<$fh>. To set the default output handle |
10040 | 11978 | to something other than STDOUT, use the select operation. |
10041 | 11979 | |
10042 | 11980 | =end original |
10043 | 11981 | |
10044 | 11982 | 文字列か文字列のリストを出力します。 |
10045 | 成功時には | |
11983 | 成功時には真を返します。 | |
10046 | ファイルハンドル名またはそのリファレンスが | |
11984 | FILEHANDLE は、ファイルハンドル名またはそのリファレンスが | |
10047 | 11985 | 入っているスカラ変数名でもよいので、一段階の間接指定が行なえます。 |
10048 | 11986 | (注: FILEHANDLE に変数を使い、次のトークンが「項」のときには、 |
10049 | 11987 | 間に C<+> を置くか、引数の前後を括弧で括らなければ、 |
10050 | 11988 | 誤って解釈されることがあります。) |
10051 | FILEHANDLE を省略した場合には、最後に選択された | |
11989 | FILEHANDLE を省略した場合には、最後に選択された | |
10052 | チャネルに出力します。 | |
11990 | (L<C<select>|/select FILEHANDLE> 参照) 出力チャネルに出力します。 | |
10053 | LIST を省略すると、C<$_> が現在選択されている出力ハンドルに | |
11991 | LIST を省略すると、L<C<$_>|perlvar/$_> が現在選択されている出力ハンドルに | |
10054 | ||
11992 | 出力されます。 | |
10055 | C<$ | |
11993 | L<C<$_>|perlvar/$_> の内容を表示するために FILEHANDLE のみを使用するには、 | |
11994 | C<$fh> のような間接ファイルハンドルではなく、C<FH> のような裸の単語の | |
10056 | 11995 | ファイルハンドルを使わなければなりません。 |
10057 | 11996 | デフォルトの出力チャネルを STDOUT 以外にするには、select 演算子を |
10058 | 11997 | 使ってください。 |
10059 | 11998 | |
10060 | 11999 | =begin original |
10061 | 12000 | |
10062 | The current value of C<$,> (if any) is printed between | |
12001 | The current value of L<C<$,>|perlvar/$,> (if any) is printed between | |
10063 | current value of C<$\> (if any) is | |
12002 | each LIST item. The current value of L<C<$\>|perlvar/$\> (if any) is | |
10064 | printed | |
12003 | printed after the entire LIST has been printed. Because print takes a | |
10065 | ||
12004 | LIST, anything in the LIST is evaluated in list context, including any | |
10066 | ||
12005 | subroutines whose return lists you pass to | |
12006 | L<C<print>|/print FILEHANDLE LIST>. Be careful not to follow the print | |
12007 | keyword with a left | |
10067 | 12008 | parenthesis unless you want the corresponding right parenthesis to |
10068 | 12009 | terminate the arguments to the print; put parentheses around all arguments |
10069 | 12010 | (or interpose a C<+>, but that doesn't look as good). |
10070 | 12011 | |
10071 | 12012 | =end original |
10072 | 12013 | |
10073 | C<$,> の値が(もしあれば)各 LIST 要素の間に出力されます。 | |
12014 | L<C<$,>|perlvar/$,> の値が(もしあれば)各 LIST 要素の間に出力されます。 | |
10074 | LIST 全体が出力された後、(もしあれば) C<$\> の現在の値が | |
12015 | LIST 全体が出力された後、(もしあれば) L<C<$\>|perlvar/$\> の現在の値が | |
12016 | 出力されます。 | |
10075 | 12017 | print の引数は LIST なので、LIST の中のものは、すべてリストコンテキストで |
10076 | 評価されます; C<print> に渡した、リストを返す | |
12018 | 評価されます; L<C<print>|/print FILEHANDLE LIST> に渡した、リストを返す | |
12019 | サブルーチンも含みます。 | |
10077 | 12020 | また、すべての引数を括弧で括るのでなければ、print というキーワードの |
10078 | 12021 | 次に開き括弧を書いてはいけません; すべての引数を括弧で括ってください |
10079 | 12022 | (あるいは "print" と引数の間に C<+> を書きますが、これはあまり |
10080 | 12023 | よくありません)。 |
10081 | 12024 | |
10082 | 12025 | =begin original |
10083 | 12026 | |
10084 | 12027 | If you're storing handles in an array or hash, or in general whenever |
10085 | 12028 | you're using any expression more complex than a bareword handle or a plain, |
10086 | 12029 | unsubscripted scalar variable to retrieve it, you will have to use a block |
10087 | 12030 | returning the filehandle value instead, in which case the LIST may not be |
10088 | 12031 | omitted: |
10089 | 12032 | |
10090 | 12033 | =end original |
10091 | 12034 | |
10092 | 12035 | もし FILESHANDLE を配列、ハッシュあるいは一般的には裸の単語のハンドルや |
10093 | 12036 | 普通のスカラ変数よりも複雑な表現を使っている場合、代わりにその値を返す |
10094 | 12037 | ブロックを使う必要があります; この場合 LIST は省略できません: |
10095 | 12038 | |
10096 | 12039 | print { $files[$i] } "stuff\n"; |
10097 | 12040 | print { $OK ? STDOUT : STDERR } "stuff\n"; |
10098 | 12041 | |
10099 | 12042 | =begin original |
10100 | 12043 | |
10101 | 12044 | Printing to a closed pipe or socket will generate a SIGPIPE signal. See |
10102 | 12045 | L<perlipc> for more on signal handling. |
10103 | 12046 | |
10104 | 12047 | =end original |
10105 | 12048 | |
10106 | 12049 | 閉じたパイプやソケットに print すると SIGPIPE シグナルが生成されます。 |
10107 | 12050 | さらなるシグナル操作については L<perlipc> を参照してください。 |
10108 | 12051 | |
10109 | 12052 | =item printf FILEHANDLE FORMAT, LIST |
10110 | 12053 | X<printf> |
10111 | 12054 | |
10112 | 12055 | =item printf FILEHANDLE |
10113 | 12056 | |
10114 | 12057 | =item printf FORMAT, LIST |
10115 | 12058 | |
10116 | 12059 | =item printf |
10117 | 12060 | |
12061 | =for Pod::Functions output a formatted list to a filehandle | |
12062 | ||
10118 | 12063 | =begin original |
10119 | 12064 | |
10120 | Equivalent to C<print FILEHANDLE sprintf(FORMAT, LIST)>, except that | |
12065 | Equivalent to C<print FILEHANDLE sprintf(FORMAT, LIST)>, except that | |
10121 | (the output record separator) is not appended. T | |
12066 | L<C<$\>|perlvar/$\> (the output record separator) is not appended. The | |
10122 | ||
12067 | FORMAT and the LIST are actually parsed as a single list. The first | |
10123 | ||
12068 | argument of the list will be interpreted as the | |
10124 | t | |
12069 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST> format. This means that | |
10125 | C< | |
12070 | C<printf(@_)> will use C<$_[0]> as the format. See | |
10126 | ||
12071 | L<sprintf|/sprintf FORMAT, LIST> for an explanation of the format | |
10127 | ||
12072 | argument. If C<use locale> (including C<use locale ':not_characters'>) | |
10128 | ||
12073 | is in effect and L<C<POSIX::setlocale>|POSIX/C<setlocale>> has been | |
12074 | called, the character used for the decimal separator in formatted | |
12075 | floating-point numbers is affected by the C<LC_NUMERIC> locale setting. | |
12076 | See L<perllocale> and L<POSIX>. | |
10129 | 12077 | |
10130 | 12078 | =end original |
10131 | 12079 | |
10132 | C<$\>(出力レコードセパレータ)を追加しないことを除けば、 | |
12080 | L<C<$\>|perlvar/$\>(出力レコードセパレータ)を追加しないことを除けば、 | |
10133 | 12081 | C<print FILEHANDLE sprintf(FORMAT, LIST)> と等価です。 |
10134 | リスト | |
12082 | FORMAT と LIST は実際には単一のリストとしてパースされます。 | |
10135 | ||
12083 | リストの最初の要素は、L<C<printf>|/printf FILEHANDLE FORMAT, LIST> | |
10136 | ||
12084 | フォーマットと解釈されます。 | |
10137 | ||
12085 | これは、C<printf(@_)> はフォーマットとして C<$_[0]> を使うということです。 | |
10138 | ||
12086 | フォーマット引数の説明については L<sprintf|/sprintf FORMAT, LIST> を | |
10139 | ||
12087 | 参照してください。 | |
10140 | C<use locale> | |
12088 | (C<use locale ':not_characters'> を含む) C<use locale> が有効で、 | |
10141 | ||
12089 | L<C<POSIX::setlocale>|POSIX/C<setlocale>> が呼び出されていれば、 | |
12090 | 小数点に使われる文字は C<LC_NUMERIC> ロケール設定の影響を受けます。 | |
10142 | 12091 | L<perllocale> と L<POSIX> を参照してください。 |
10143 | 12092 | |
10144 | 12093 | =begin original |
10145 | 12094 | |
10146 | ||
12095 | For historical reasons, if you omit the list, L<C<$_>|perlvar/$_> is | |
10147 | ||
12096 | used as the format; | |
10148 | e | |
12097 | to use FILEHANDLE without a list, you must use a bareword filehandle like | |
12098 | C<FH>, not an indirect one like C<$fh>. However, this will rarely do what | |
12099 | you want; if L<C<$_>|perlvar/$_> contains formatting codes, they will be | |
12100 | replaced with the empty string and a warning will be emitted if | |
12101 | L<warnings> are enabled. Just use L<C<print>|/print FILEHANDLE LIST> if | |
12102 | you want to print the contents of L<C<$_>|perlvar/$_>. | |
10149 | 12103 | |
10150 | 12104 | =end original |
10151 | 12105 | |
10152 | ||
12106 | 歴史的な理由により、リストを省略すると、フォーマットとして | |
12107 | L<C<$_>|perlvar/$_> が使われます; | |
12108 | リストなしで FILEHANDLE を使用するには、C<$fh> のような | |
12109 | 間接ファイルハンドルではなく、C<FH> のような裸の単語の | |
12110 | ファイルハンドルを使わなければなりません。 | |
12111 | しかし、これがあなたが求めていることをすることはまれです; | |
12112 | L<C<$_>|perlvar/$_> がフォーマッティングコードの場合、空文字列に置き換えられ、 | |
12113 | L<warnings> が有効なら警告が出力されます。 | |
12114 | L<C<$_>|perlvar/$_> の内容を表示したい場合は、単に | |
12115 | L<C<print>|/print FILEHANDLE LIST> を使ってください。 | |
12116 | ||
12117 | =begin original | |
12118 | ||
12119 | Don't fall into the trap of using a | |
12120 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST> when a simple | |
12121 | L<C<print>|/print FILEHANDLE LIST> would do. The | |
12122 | L<C<print>|/print FILEHANDLE LIST> is more efficient and less error | |
12123 | prone. | |
12124 | ||
12125 | =end original | |
12126 | ||
12127 | 単純な L<C<print>|/print FILEHANDLE LIST> を使うべきところで | |
12128 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST> を使ってしまう | |
10153 | 12129 | 罠にかからないようにしてください。 |
10154 | C<print> はより効率的で、間違いが起こりにくいです。 | |
12130 | L<C<print>|/print FILEHANDLE LIST> はより効率的で、間違いが起こりにくいです。 | |
10155 | 12131 | |
10156 | 12132 | =item prototype FUNCTION |
10157 | 12133 | X<prototype> |
10158 | 12134 | |
12135 | =item prototype | |
12136 | ||
12137 | =for Pod::Functions +5.002 get the prototype (if any) of a subroutine | |
12138 | ||
10159 | 12139 | =begin original |
10160 | 12140 | |
10161 | Returns the prototype of a function as a string (or | |
12141 | Returns the prototype of a function as a string (or | |
12142 | L<C<undef>|/undef EXPR> if the | |
10162 | 12143 | function has no prototype). FUNCTION is a reference to, or the name of, |
10163 | the function whose prototype you want to retrieve. | |
12144 | the function whose prototype you want to retrieve. If FUNCTION is omitted, | |
12145 | L<C<$_>|perlvar/$_> is used. | |
10164 | 12146 | |
10165 | 12147 | =end original |
10166 | 12148 | |
10167 | 12149 | 関数のプロトタイプを文字列として返します(関数にプロトタイプがない場合は |
10168 | C<undef> を返します)。 | |
12150 | L<C<undef>|/undef EXPR> を返します)。 | |
10169 | 12151 | FUNCTION はプロトタイプを得たい関数の名前、またはリファレンスです。 |
12152 | FUNCTION が省略された場合、L<C<$_>|perlvar/$_> が使われます。 | |
10170 | 12153 | |
10171 | 12154 | =begin original |
10172 | 12155 | |
10173 | 12156 | If FUNCTION is a string starting with C<CORE::>, the rest is taken as a |
10174 | name for a Perl builtin. If the builtin | |
12157 | name for a Perl builtin. If the builtin's arguments | |
10175 | ||
12158 | cannot be adequately expressed by a prototype | |
10176 | (such as C<system>), prototype | |
12159 | (such as L<C<system>|/system LIST>), L<C<prototype>|/prototype FUNCTION> | |
12160 | returns L<C<undef>|/undef EXPR>, because the builtin | |
10177 | 12161 | does not really behave like a Perl function. Otherwise, the string |
10178 | 12162 | describing the equivalent prototype is returned. |
10179 | 12163 | |
10180 | 12164 | =end original |
10181 | 12165 | |
10182 | 12166 | FUNCTION が C<CORE::> で始まっている場合、残りは Perl ビルドインの名前として |
10183 | 12167 | 扱われます。 |
10184 | このビルドインが(C< | |
12168 | このビルドインの引数が(L<C<system>|/system LIST> のように)プロトタイプとして | |
10185 | ||
12169 | 適切に記述できない場合、L<C<prototype>|/prototype FUNCTION> は | |
10186 | ||
12170 | L<C<undef>|/undef EXPR> を返します; | |
10187 | 12171 | なぜならビルドインは実際に Perl 関数のように振舞わないからです。 |
10188 | 12172 | それ以外では、等価なプロトタイプを表現した文字列が返されます。 |
10189 | 12173 | |
10190 | 12174 | =item push ARRAY,LIST |
10191 | 12175 | X<push> X<stack> |
10192 | 12176 | |
10193 | = | |
12177 | =for Pod::Functions append one or more elements to an array | |
10194 | 12178 | |
10195 | 12179 | =begin original |
10196 | 12180 | |
10197 | 12181 | Treats ARRAY as a stack by appending the values of LIST to the end of |
10198 | 12182 | ARRAY. The length of ARRAY increases by the length of LIST. Has the same |
10199 | 12183 | effect as |
10200 | 12184 | |
10201 | 12185 | =end original |
10202 | 12186 | |
10203 | 12187 | ARRAY をスタックとして扱い、LIST 内の値を ARRAY の終わりに追加します。 |
10204 | 12188 | ARRAY の大きさは、LIST の長さ分だけ大きくなります。 |
10205 | 12189 | これは、 |
10206 | 12190 | |
10207 | for $value (LIST) { | |
12191 | for my $value (LIST) { | |
10208 | 12192 | $ARRAY[++$#ARRAY] = $value; |
10209 | 12193 | } |
10210 | 12194 | |
10211 | 12195 | =begin original |
10212 | 12196 | |
10213 | 12197 | but is more efficient. Returns the number of elements in the array following |
10214 | the completed C<push>. | |
12198 | the completed L<C<push>|/push ARRAY,LIST>. | |
10215 | 12199 | |
10216 | 12200 | =end original |
10217 | 12201 | |
10218 | 12202 | とするのと同じ効果がありますが、より効率的です。 |
10219 | C<push> の処理終了後の配列の要素数を返します。 | |
12203 | L<C<push>|/push ARRAY,LIST> の処理終了後の配列の要素数を返します。 | |
10220 | 12204 | |
10221 | 12205 | =begin original |
10222 | 12206 | |
10223 | Starting with Perl 5.14, | |
12207 | Starting with Perl 5.14, an experimental feature allowed | |
10224 | ||
12208 | L<C<push>|/push ARRAY,LIST> to take a | |
10225 | ||
12209 | scalar expression. This experiment has been deemed unsuccessful, and was | |
10226 | ||
12210 | removed as of Perl 5.24. | |
10227 | 12211 | |
10228 | 12212 | =end original |
10229 | 12213 | |
10230 | Perl 5.14 から、C<push> | |
12214 | Perl 5.14 から、L<C<push>|/push ARRAY,LIST> がスカラ式を取ることが出来るという | |
10231 | ||
12215 | 実験的機能がありました。 | |
10232 | ||
12216 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 | |
10233 | C<push> のこの動作は高度に実験的であると考えられています。 | |
10234 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 | |
10235 | 12217 | |
10236 | 12218 | =item q/STRING/ |
10237 | 12219 | |
12220 | =for Pod::Functions singly quote a string | |
12221 | ||
10238 | 12222 | =item qq/STRING/ |
10239 | 12223 | |
10240 | =ite | |
12224 | =for Pod::Functions doubly quote a string | |
10241 | 12225 | |
10242 | 12226 | =item qw/STRING/ |
10243 | 12227 | |
12228 | =for Pod::Functions quote a list of words | |
12229 | ||
12230 | =item qx/STRING/ | |
12231 | ||
12232 | =for Pod::Functions backquote quote a string | |
12233 | ||
10244 | 12234 | =begin original |
10245 | 12235 | |
10246 | 12236 | Generalized quotes. See L<perlop/"Quote-Like Operators">. |
10247 | 12237 | |
10248 | 12238 | =end original |
10249 | 12239 | |
10250 | 12240 | 汎用のクォートです。 |
10251 | 12241 | L<perlop/"Quote-Like Operators"> を参照してください。 |
10252 | 12242 | |
10253 | 12243 | =item qr/STRING/ |
10254 | 12244 | |
12245 | =for Pod::Functions +5.005 compile pattern | |
12246 | ||
10255 | 12247 | =begin original |
10256 | 12248 | |
10257 | 12249 | Regexp-like quote. See L<perlop/"Regexp Quote-Like Operators">. |
10258 | 12250 | |
10259 | 12251 | =end original |
10260 | 12252 | |
10261 | 12253 | 正規表現風のクォートです。 |
10262 | 12254 | L<perlop/"Regexp Quote-Like Operators"> を参照してください。 |
10263 | 12255 | |
10264 | 12256 | =item quotemeta EXPR |
10265 | 12257 | X<quotemeta> X<metacharacter> |
10266 | 12258 | |
10267 | 12259 | =item quotemeta |
10268 | 12260 | |
12261 | =for Pod::Functions quote regular expression magic characters | |
12262 | ||
10269 | 12263 | =begin original |
10270 | 12264 | |
10271 | Returns the value of EXPR with all non-"word" | |
12265 | Returns the value of EXPR with all the ASCII non-"word" | |
10272 | characters backslashed. (That is, all characters not matching | |
12266 | characters backslashed. (That is, all ASCII characters not matching | |
10273 | 12267 | C</[A-Za-z_0-9]/> will be preceded by a backslash in the |
10274 | 12268 | returned string, regardless of any locale settings.) |
10275 | 12269 | This is the internal function implementing |
10276 | 12270 | the C<\Q> escape in double-quoted strings. |
12271 | (See below for the behavior on non-ASCII code points.) | |
10277 | 12272 | |
10278 | 12273 | =end original |
10279 | 12274 | |
10280 | EXPR の中のすべての非英数字キャラクタをバックスラッシュで | |
12275 | EXPR の中のすべての ASCII 非英数字キャラクタをバックスラッシュで | |
10281 | エスケープしたものを返します | |
12276 | エスケープしたものを返します。 | |
10282 | (つまり、C</[A-Za-z_0-9]/> にマッチしない全ての文字の前には | |
12277 | (つまり、C</[A-Za-z_0-9]/> にマッチしない全ての ASCII 文字の前には | |
10283 | ロケールに関わらずバックスラッシュが前置されます | |
12278 | ロケールに関わらずバックスラッシュが前置されます。) | |
10284 | これは、ダブルクォート文字列での C<\Q> エスケープを | |
12279 | これは、ダブルクォート文字列での C<\Q> エスケープを実装するための | |
10285 | ||
12280 | 内部関数です。 | |
12281 | (非 ASCII 符号位置での振る舞いについては以下を参照してください。) | |
10286 | 12282 | |
10287 | 12283 | =begin original |
10288 | 12284 | |
10289 | If EXPR is omitted, uses C<$_>. | |
12285 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. | |
10290 | 12286 | |
10291 | 12287 | =end original |
10292 | 12288 | |
10293 | EXPR が省略されると、C<$_> を使います。 | |
12289 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
10294 | 12290 | |
10295 | 12291 | =begin original |
10296 | 12292 | |
10297 | 12293 | quotemeta (and C<\Q> ... C<\E>) are useful when interpolating strings into |
10298 | 12294 | regular expressions, because by default an interpolated variable will be |
10299 | considered a mini-regular expression. For example: | |
12295 | considered a mini-regular expression. For example: | |
10300 | 12296 | |
10301 | 12297 | =end original |
10302 | 12298 | |
10303 | 12299 | クォートメタ (と C<\Q> ... C<\E>) は、文字列を正規表現に展開するのに |
10304 | 12300 | 便利です; なぜなら、デフォルトでは展開された変数は小さな正規表現として |
10305 | 12301 | 扱われるからです。 |
10306 | 12302 | 例えば: |
10307 | 12303 | |
10308 | 12304 | my $sentence = 'The quick brown fox jumped over the lazy dog'; |
10309 | 12305 | my $substring = 'quick.*?fox'; |
10310 | 12306 | $sentence =~ s{$substring}{big bad wolf}; |
10311 | 12307 | |
10312 | 12308 | =begin original |
10313 | 12309 | |
10314 | 12310 | Will cause C<$sentence> to become C<'The big bad wolf jumped over...'>. |
10315 | 12311 | |
10316 | 12312 | =end original |
10317 | 12313 | |
10318 | 12314 | とすると、C<$sentence> は C<'The big bad wolf jumped over...'> になります。 |
10319 | 12315 | |
10320 | 12316 | =begin original |
10321 | 12317 | |
10322 | 12318 | On the other hand: |
10323 | 12319 | |
10324 | 12320 | =end original |
10325 | 12321 | |
10326 | 12322 | 一方: |
10327 | 12323 | |
10328 | 12324 | my $sentence = 'The quick brown fox jumped over the lazy dog'; |
10329 | 12325 | my $substring = 'quick.*?fox'; |
10330 | 12326 | $sentence =~ s{\Q$substring\E}{big bad wolf}; |
10331 | 12327 | |
10332 | 12328 | =begin original |
10333 | 12329 | |
10334 | 12330 | Or: |
10335 | 12331 | |
10336 | 12332 | =end original |
10337 | 12333 | |
10338 | 12334 | あるいは: |
10339 | 12335 | |
10340 | 12336 | my $sentence = 'The quick brown fox jumped over the lazy dog'; |
10341 | 12337 | my $substring = 'quick.*?fox'; |
10342 | 12338 | my $quoted_substring = quotemeta($substring); |
10343 | 12339 | $sentence =~ s{$quoted_substring}{big bad wolf}; |
10344 | 12340 | |
10345 | 12341 | =begin original |
10346 | 12342 | |
10347 | Will both leave the sentence as is. | |
12343 | Will both leave the sentence as is. | |
10348 | ||
12344 | Normally, when accepting literal string input from the user, | |
12345 | L<C<quotemeta>|/quotemeta EXPR> or C<\Q> must be used. | |
10349 | 12346 | |
10350 | 12347 | =end original |
10351 | 12348 | |
10352 | 12349 | とすると、両方ともそのままです。 |
10353 | 12350 | 普通は、ユーザーからのリテラルな文字列入力を受け付ける場合は、 |
10354 | 必ず quotemeta | |
12351 | 必ず L<C<quotemeta>|/quotemeta EXPR> か C<\Q> を使わなければなりません。 | |
10355 | 12352 | |
10356 | 12353 | =begin original |
10357 | 12354 | |
10358 | In Perl 5.14, all characters | |
12355 | In Perl v5.14, all non-ASCII characters are quoted in non-UTF-8-encoded | |
10359 | ||
12356 | strings, but not quoted in UTF-8 strings. | |
10360 | It is planned to change this behavior in 5.16, but the exact rules | |
10361 | haven't been determined yet. | |
10362 | 12357 | |
10363 | 12358 | =end original |
10364 | 12359 | |
10365 | Perl 5.14 では、 | |
12360 | Perl v5.14 では、全ての非 ASCII 文字は非 UTF-8 エンコードされた | |
10366 | 文字列ではクォートされませんが、UTF-8 文字列では | |
12361 | 文字列ではクォートされませんが、UTF-8 文字列ではクォートされます。 | |
10367 | この振る舞いは 5.16 で変更が計画されていますが、正確な規則はまだ | |
10368 | 決定していません。 | |
10369 | 12362 | |
12363 | =begin original | |
12364 | ||
12365 | Starting in Perl v5.16, Perl adopted a Unicode-defined strategy for | |
12366 | quoting non-ASCII characters; the quoting of ASCII characters is | |
12367 | unchanged. | |
12368 | ||
12369 | =end original | |
12370 | ||
12371 | Perl v5.16 から、Perl は非 ASCII 文字をクォートするのに Unicode で | |
12372 | 定義された戦略を採用しました; ASCII 文字のクォートは変わりません。 | |
12373 | ||
12374 | =begin original | |
12375 | ||
12376 | Also unchanged is the quoting of non-UTF-8 strings when outside the | |
12377 | scope of a | |
12378 | L<C<use feature 'unicode_strings'>|feature/The 'unicode_strings' feature>, | |
12379 | which is to quote all | |
12380 | characters in the upper Latin1 range. This provides complete backwards | |
12381 | compatibility for old programs which do not use Unicode. (Note that | |
12382 | C<unicode_strings> is automatically enabled within the scope of a | |
12383 | S<C<use v5.12>> or greater.) | |
12384 | ||
12385 | =end original | |
12386 | ||
12387 | また、 | |
12388 | L<C<use feature 'unicode_strings'>|feature/The 'unicode_strings' feature> の | |
12389 | 範囲外で非 UTF-8 文字列をクォートするのも変わりません; 上位の Latin1 の範囲の | |
12390 | 全ての文字をクォートします。 | |
12391 | これは Unicode を使わない古いプログラムに対して完全な後方互換性を提供します。 | |
12392 | (C<unicode_strings> は S<C<use v5.12>> またはそれ以上のスコープでは | |
12393 | 自動的に有効になることに注意してください。) | |
12394 | ||
12395 | =begin original | |
12396 | ||
12397 | Within the scope of L<C<use locale>|locale>, all non-ASCII Latin1 code | |
12398 | points | |
12399 | are quoted whether the string is encoded as UTF-8 or not. As mentioned | |
12400 | above, locale does not affect the quoting of ASCII-range characters. | |
12401 | This protects against those locales where characters such as C<"|"> are | |
12402 | considered to be word characters. | |
12403 | ||
12404 | =end original | |
12405 | ||
12406 | L<C<use locale>|locale> スコープの内側では、全ての非 ASCII Latin1 符号位置は | |
12407 | 文字列が UTF-8 でエンコードされているかどうかに関わらずクォートされます。 | |
12408 | 上述のように、ロケールは ASCII の範囲の文字のクォートに影響を与えません。 | |
12409 | これは C<"|"> のような文字が単語文字として考えられるロケールから守ります。 | |
12410 | ||
12411 | =begin original | |
12412 | ||
12413 | Otherwise, Perl quotes non-ASCII characters using an adaptation from | |
12414 | Unicode (see L<http://www.unicode.org/reports/tr31/>). | |
12415 | The only code points that are quoted are those that have any of the | |
12416 | Unicode properties: Pattern_Syntax, Pattern_White_Space, White_Space, | |
12417 | Default_Ignorable_Code_Point, or General_Category=Control. | |
12418 | ||
12419 | =end original | |
12420 | ||
12421 | さもなければ、Perl は Unicode からの本版を使って非 ASCII 文字をクォートします | |
12422 | (L<http://www.unicode.org/reports/tr31/> 参照)。 | |
12423 | クォートされる符号位置は以下のどれかの Unicode を特性を持つものだけです: | |
12424 | Pattern_Syntax, Pattern_White_Space, White_Space, | |
12425 | Default_Ignorable_Code_Point, or General_Category=Control。 | |
12426 | ||
12427 | =begin original | |
12428 | ||
12429 | Of these properties, the two important ones are Pattern_Syntax and | |
12430 | Pattern_White_Space. They have been set up by Unicode for exactly this | |
12431 | purpose of deciding which characters in a regular expression pattern | |
12432 | should be quoted. No character that can be in an identifier has these | |
12433 | properties. | |
12434 | ||
12435 | =end original | |
12436 | ||
12437 | これらの特性の中で、重要な二つは Pattern_Syntax と Pattern_White_Space です。 | |
12438 | これらはまさに正規表現中パターン中のどの文字をクォートするべきかを | |
12439 | 決定するという目的のために Unicode によって設定されています。 | |
12440 | 識別子になる文字はこれらの特性はありません。 | |
12441 | ||
12442 | =begin original | |
12443 | ||
12444 | Perl promises, that if we ever add regular expression pattern | |
12445 | metacharacters to the dozen already defined | |
12446 | (C<\ E<verbar> ( ) [ { ^ $ * + ? .>), that we will only use ones that have the | |
12447 | Pattern_Syntax property. Perl also promises, that if we ever add | |
12448 | characters that are considered to be white space in regular expressions | |
12449 | (currently mostly affected by C</x>), they will all have the | |
12450 | Pattern_White_Space property. | |
12451 | ||
12452 | =end original | |
12453 | ||
12454 | Perl は、正規表現メタ文字として既に定義されている | |
12455 | (C<\ E<verbar> ( ) [ { ^ $ * + ? .>) ものに追加するときは、 | |
12456 | Pattern_Syntax 特性を持つものだけを使うことを約束します。 | |
12457 | Perl はまた、(現在の所ほとんどは C</x> よって影響される)正規表現中で空白と | |
12458 | 考えられる文字に追加するときは、Pattern_White_Space 特性を | |
12459 | 持つものであることを約束します。 | |
12460 | ||
12461 | =begin original | |
12462 | ||
12463 | Unicode promises that the set of code points that have these two | |
12464 | properties will never change, so something that is not quoted in v5.16 | |
12465 | will never need to be quoted in any future Perl release. (Not all the | |
12466 | code points that match Pattern_Syntax have actually had characters | |
12467 | assigned to them; so there is room to grow, but they are quoted | |
12468 | whether assigned or not. Perl, of course, would never use an | |
12469 | unassigned code point as an actual metacharacter.) | |
12470 | ||
12471 | =end original | |
12472 | ||
12473 | Unicode はこれら二つの特性を持つ符号位置の集合が決して変わらないことを | |
12474 | 約束しているので、v5.16 でクォートされないものは将来の Perl リリースでも | |
12475 | クォートする必要はありません。 | |
12476 | (Pattern_Syntax にマッチングする全ての符号位置が実際に割り当てられている | |
12477 | 文字を持っているわけではありません; したがって拡張する余地がありますが、 | |
12478 | 割り当てられているかどうかに関わらずクォートされます。 | |
12479 | Perl はもちろん割り当てられていない符号位置を実際のメタ文字として使うことは | |
12480 | ありません。) | |
12481 | ||
12482 | =begin original | |
12483 | ||
12484 | Quoting characters that have the other 3 properties is done to enhance | |
12485 | the readability of the regular expression and not because they actually | |
12486 | need to be quoted for regular expression purposes (characters with the | |
12487 | White_Space property are likely to be indistinguishable on the page or | |
12488 | screen from those with the Pattern_White_Space property; and the other | |
12489 | two properties contain non-printing characters). | |
12490 | ||
12491 | =end original | |
12492 | ||
12493 | その他の 3 特性を持つ文字のクォートは正規表現の可読性を向上させるために | |
12494 | 行われ、実際には正規表現の目的でクォートする必要があるからではありません | |
12495 | (White_Space 特性を持つ文字は表示上は Pattern_White_Space 特性を持つ文字と | |
12496 | おそらく区別が付かないでしょう; そして残りの | |
12497 | 二つの特性は非表示文字を含んでいます). | |
12498 | ||
10370 | 12499 | =item rand EXPR |
10371 | 12500 | X<rand> X<random> |
10372 | 12501 | |
10373 | 12502 | =item rand |
10374 | 12503 | |
12504 | =for Pod::Functions retrieve the next pseudorandom number | |
12505 | ||
10375 | 12506 | =begin original |
10376 | 12507 | |
10377 | 12508 | Returns a random fractional number greater than or equal to C<0> and less |
10378 | 12509 | than the value of EXPR. (EXPR should be positive.) If EXPR is |
10379 | 12510 | omitted, the value C<1> is used. Currently EXPR with the value C<0> is |
10380 | 12511 | also special-cased as C<1> (this was undocumented before Perl 5.8.0 |
10381 | 12512 | and is subject to change in future versions of Perl). Automatically calls |
10382 | C<srand> unless C<srand> has already been | |
12513 | L<C<srand>|/srand EXPR> unless L<C<srand>|/srand EXPR> has already been | |
12514 | called. See also L<C<srand>|/srand EXPR>. | |
10383 | 12515 | |
10384 | 12516 | =end original |
10385 | 12517 | |
10386 | 12518 | C<0> 以上 EXPR の値未満の小数の乱数値を返します。 |
10387 | 12519 | (EXPR は正の数である必要があります。) |
10388 | EXPR | |
12520 | EXPR が省略されると、C<1> が使われます。 | |
10389 | 12521 | 現在のところ、EXPR に値 C<0> をセットすると C<1> として特別扱いされます |
10390 | 12522 | (これは Perl 5.8.0 以前には文書化されておらず、将来のバージョンの perl では |
10391 | 12523 | 変更される可能性があります)。 |
10392 | C<srand> が既に呼ばれている場合以外は、自動的に | |
12524 | L<C<srand>|/srand EXPR> が既に呼ばれている場合以外は、自動的に | |
10393 | 呼び出します。 | |
12525 | L<C<srand>|/srand EXPR> 関数を呼び出します。 | |
10394 | C<srand> も参照してください。 | |
12526 | L<C<srand>|/srand EXPR> も参照してください。 | |
10395 | 12527 | |
10396 | 12528 | =begin original |
10397 | 12529 | |
10398 | Apply C<int | |
12530 | Apply L<C<int>|/int EXPR> to the value returned by L<C<rand>|/rand EXPR> | |
10399 | integers instead of random fractional numbers. For | |
12531 | if you want random integers instead of random fractional numbers. For | |
12532 | example, | |
10400 | 12533 | |
10401 | 12534 | =end original |
10402 | 12535 | |
10403 | ランダムな小数ではなく、ランダムな整数がほしい場合は、 | |
12536 | ランダムな小数ではなく、ランダムな整数がほしい場合は、 | |
10404 | 返された値に C<int | |
12537 | L<C<rand>|/rand EXPR> から返された値に L<C<int>|/int EXPR> を | |
12538 | 適用してください。 | |
12539 | 例えば: | |
10405 | 12540 | |
10406 | 12541 | int(rand(10)) |
10407 | 12542 | |
10408 | 12543 | =begin original |
10409 | 12544 | |
10410 | 12545 | returns a random integer between C<0> and C<9>, inclusive. |
10411 | 12546 | |
10412 | 12547 | =end original |
10413 | 12548 | |
10414 | 12549 | これは C<0> から C<9> の値をランダムに返します。 |
10415 | 12550 | |
10416 | 12551 | =begin original |
10417 | 12552 | |
10418 | 12553 | (Note: If your rand function consistently returns numbers that are too |
10419 | 12554 | large or too small, then your version of Perl was probably compiled |
10420 | 12555 | with the wrong number of RANDBITS.) |
10421 | 12556 | |
10422 | 12557 | =end original |
10423 | 12558 | |
10424 | 12559 | (注: もし、rand 関数が、常に大きい値ばかりや、小さい数ばかりを |
10425 | 12560 | 返すようなら、お使いになっている Perl が、 |
10426 | 12561 | 良くない RANDBITS を使ってコンパイルされている可能性があります。) |
10427 | 12562 | |
10428 | 12563 | =begin original |
10429 | 12564 | |
10430 | B<C<rand | |
12565 | B<L<C<rand>|/rand EXPR> is not cryptographically secure. You should not rely | |
10431 | 12566 | on it in security-sensitive situations.> As of this writing, a |
10432 | 12567 | number of third-party CPAN modules offer random number generators |
10433 | 12568 | intended by their authors to be cryptographically secure, |
10434 | including: L< | |
12569 | including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>, | |
10435 | L<Math::TrulyRandom>. | |
12570 | and L<Math::TrulyRandom>. | |
10436 | 12571 | |
10437 | 12572 | =end original |
10438 | 12573 | |
10439 | B<C<rand | |
12574 | B<L<C<rand>|/rand EXPR> は暗号学的に安全ではありません。 | |
10440 | 12575 | セキュリティ的に重要な状況でこれに頼るべきではありません。> |
10441 | 12576 | これを書いている時点で、いくつかのサードパーティ CPAN モジュールが |
10442 | 12577 | 作者によって暗号学的に安全であることを目的とした乱数生成器を |
10443 | 提供しています: L< | |
12578 | 提供しています: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>, | |
10444 | 12579 | L<Math::TrulyRandom> などです。 |
10445 | 12580 | |
10446 | 12581 | =item read FILEHANDLE,SCALAR,LENGTH,OFFSET |
10447 | 12582 | X<read> X<file, read> |
10448 | 12583 | |
10449 | 12584 | =item read FILEHANDLE,SCALAR,LENGTH |
10450 | 12585 | |
12586 | =for Pod::Functions fixed-length buffered input from a filehandle | |
12587 | ||
10451 | 12588 | =begin original |
10452 | 12589 | |
10453 | 12590 | Attempts to read LENGTH I<characters> of data into variable SCALAR |
10454 | 12591 | from the specified FILEHANDLE. Returns the number of characters |
10455 | 12592 | actually read, C<0> at end of file, or undef if there was an error (in |
10456 | the latter case C<$!> is also set). SCALAR will be grown | |
12593 | the latter case L<C<$!>|perlvar/$!> is also set). SCALAR will be grown | |
12594 | or shrunk | |
10457 | 12595 | so that the last character actually read is the last character of the |
10458 | 12596 | scalar after the read. |
10459 | 12597 | |
10460 | 12598 | =end original |
10461 | 12599 | |
10462 | 指定した FILEHANDLE から、変数 SCALAR に LENGTH I<文字> の | |
12600 | 指定した FILEHANDLE から、変数 SCALAR に LENGTH I<文字> のデータを | |
10463 | ||
12601 | 読み込みます。 | |
10464 | 実際に読み込まれた文字数、 | |
12602 | 実際に読み込まれた文字数、ファイル終端の場合は C<0>、エラーの場合は undef の | |
10465 | ||
12603 | いずれかを返します (後者の場合、L<C<$!>|perlvar/$!> もセットされます)。 | |
10466 | ||
12604 | SCALAR は伸び縮みするので、読み込み後は、実際に読み込んだ最後の文字がスカラの | |
10467 | ||
12605 | 最後の文字になります。 | |
10468 | 読み込み後は、実際に読み込んだ最後の文字がスカラの最後の文字になります。 | |
10469 | 12606 | |
10470 | 12607 | =begin original |
10471 | 12608 | |
10472 | 12609 | An OFFSET may be specified to place the read data at some place in the |
10473 | 12610 | string other than the beginning. A negative OFFSET specifies |
10474 | 12611 | placement at that many characters counting backwards from the end of |
10475 | 12612 | the string. A positive OFFSET greater than the length of SCALAR |
10476 | 12613 | results in the string being padded to the required size with C<"\0"> |
10477 | 12614 | bytes before the result of the read is appended. |
10478 | 12615 | |
10479 | 12616 | =end original |
10480 | 12617 | |
10481 | OFFSET を指定すると、文字列の先頭以外の場所から | |
12618 | OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行なえます。 | |
10482 | できます。 | |
10483 | 12619 | OFFSET に負の値を指定すると、文字列の最後から逆向きに何文字目かで |
10484 | 12620 | 位置を指定します。 |
10485 | OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は | |
12621 | OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は読み込みの結果が | |
10486 | ||
12622 | 追加される前に、必要なサイズまで C<"\0"> のバイトでパッディングされます。 | |
10487 | パッディングされます。 | |
10488 | 12623 | |
10489 | 12624 | =begin original |
10490 | 12625 | |
10491 | 12626 | The call is implemented in terms of either Perl's or your system's native |
10492 | fread(3) library function. To get a true read(2) system call, see | |
12627 | L<fread(3)> library function. To get a true L<read(2)> system call, see | |
12628 | L<sysread|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>. | |
10493 | 12629 | |
10494 | 12630 | =end original |
10495 | 12631 | |
10496 | この関数は、Perl か システムの fread(3) ライブラリ関数を使って | |
12632 | この関数は、Perl か システムの L<fread(3)> ライブラリ関数を使って | |
10497 | ||
12633 | 実装しています。 | |
12634 | 本当の L<read(2)> システムコールを利用するには、 | |
12635 | L<sysread|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を参照してください。 | |
10498 | 12636 | |
10499 | 12637 | =begin original |
10500 | 12638 | |
10501 | 12639 | Note the I<characters>: depending on the status of the filehandle, |
10502 | 12640 | either (8-bit) bytes or characters are read. By default, all |
10503 | 12641 | filehandles operate on bytes, but for example if the filehandle has |
10504 | been opened with the C<:utf8> I/O layer (see | |
12642 | been opened with the C<:utf8> I/O layer (see | |
10505 | ||
12643 | L<C<open>|/open FILEHANDLE,EXPR>, and the L<open> | |
10506 | ||
12644 | pragma), the I/O will operate on UTF8-encoded Unicode | |
12645 | characters, not bytes. Similarly for the C<:encoding> layer: | |
10507 | 12646 | in that case pretty much any characters can be read. |
10508 | 12647 | |
10509 | 12648 | =end original |
10510 | 12649 | |
10511 | 12650 | I<文字> に関する注意: ファイルハンドルの状態によって、(8 ビットの) バイトか |
10512 | 12651 | 文字が読み込まれます。 |
10513 | 12652 | デフォルトでは全てのファイルハンドルはバイトを処理しますが、 |
10514 | 例えばファイルハンドルが C<:utf8> I/O 層(L< | |
12653 | 例えばファイルハンドルが C<:utf8> I/O 層(L<C<open>|/open FILEHANDLE,EXPR>, | |
10515 | L<open> を参照してください) で開かれた場合、I/O はバイトではなく、 | |
12654 | L<open> プラグマを参照してください) で開かれた場合、I/O はバイトではなく、 | |
10516 | 12655 | UTF8 エンコードされた Unicode 文字を操作します。 |
10517 | C<:encoding> | |
12656 | C<:encoding> 層も同様です: | |
10518 | 12657 | この場合、ほとんど大体全ての文字が読み込めます。 |
10519 | 12658 | |
10520 | 12659 | =item readdir DIRHANDLE |
10521 | 12660 | X<readdir> |
10522 | 12661 | |
12662 | =for Pod::Functions get a directory from a directory handle | |
12663 | ||
10523 | 12664 | =begin original |
10524 | 12665 | |
10525 | Returns the next directory entry for a directory opened by | |
12666 | Returns the next directory entry for a directory opened by | |
12667 | L<C<opendir>|/opendir DIRHANDLE,EXPR>. | |
10526 | 12668 | If used in list context, returns all the rest of the entries in the |
10527 | 12669 | directory. If there are no more entries, returns the undefined value in |
10528 | 12670 | scalar context and the empty list in list context. |
10529 | 12671 | |
10530 | 12672 | =end original |
10531 | 12673 | |
10532 | C<opendir> でオープンしたディレクトリで、 | |
12674 | L<C<opendir>|/opendir DIRHANDLE,EXPR> でオープンしたディレクトリで、次の | |
10533 | ||
12675 | ディレクトリエントリを返します。 | |
10534 | リストコンテキストで用いると、 | |
12676 | リストコンテキストで用いると、そのディレクトリの残りのエントリを、すべて | |
10535 | ||
12677 | 返します。 | |
10536 | 12678 | エントリが残っていない場合には、スカラコンテキストでは未定義値を、 |
10537 | 12679 | リストコンテキストでは空リストを返します。 |
10538 | 12680 | |
10539 | 12681 | =begin original |
10540 | 12682 | |
10541 | If you're planning to filetest the return values out of a | |
12683 | If you're planning to filetest the return values out of a | |
10542 | better prepend the directory in | |
12684 | L<C<readdir>|/readdir DIRHANDLE>, you'd better prepend the directory in | |
10543 | ||
12685 | question. Otherwise, because we didn't L<C<chdir>|/chdir EXPR> there, | |
12686 | it would have been testing the wrong file. | |
10544 | 12687 | |
10545 | 12688 | =end original |
10546 | 12689 | |
10547 | C<readdir> の返り値をファイルテストに使おうと | |
12690 | L<C<readdir>|/readdir DIRHANDLE> の返り値をファイルテストに使おうと | |
10548 | 頭にディレクトリをつける必要があります。 | |
12691 | 計画しているなら、頭にディレクトリをつける必要があります。 | |
10549 | さもなければ、ここでは C<chdir> はしないので、 | |
12692 | さもなければ、ここでは L<C<chdir>|/chdir EXPR> はしないので、 | |
10550 | 12693 | 間違ったファイルをテストしてしまうことになるでしょう。 |
10551 | 12694 | |
10552 | opendir(my $dh, $some_dir) || die " | |
12695 | opendir(my $dh, $some_dir) || die "Can't opendir $some_dir: $!"; | |
10553 | @dots = grep { /^\./ && -f "$some_dir/$_" } readdir($dh); | |
12696 | my @dots = grep { /^\./ && -f "$some_dir/$_" } readdir($dh); | |
10554 | 12697 | closedir $dh; |
10555 | 12698 | |
10556 | 12699 | =begin original |
10557 | 12700 | |
10558 | As of Perl 5.1 | |
12701 | As of Perl 5.12 you can use a bare L<C<readdir>|/readdir DIRHANDLE> in a | |
10559 | which will set C<$_> on every iteration. | |
12702 | C<while> loop, which will set L<C<$_>|perlvar/$_> on every iteration. | |
10560 | 12703 | |
10561 | 12704 | =end original |
10562 | 12705 | |
10563 | Perl 5.1 | |
12706 | Perl 5.12 から裸の L<C<readdir>|/readdir DIRHANDLE> を C<while> で | |
10564 | この場合繰り返し毎に C<$_> にセットされます。 | |
12707 | 使うことができ、この場合繰り返し毎に L<C<$_>|perlvar/$_> にセットされます。 | |
10565 | 12708 | |
10566 | opendir(my $dh, $some_dir) || die; | |
12709 | opendir(my $dh, $some_dir) || die "Can't open $some_dir: $!"; | |
10567 | while(readdir $dh) { | |
12710 | while (readdir $dh) { | |
10568 | 12711 | print "$some_dir/$_\n"; |
10569 | 12712 | } |
10570 | 12713 | closedir $dh; |
10571 | 12714 | |
12715 | =begin original | |
12716 | ||
12717 | To avoid confusing would-be users of your code who are running earlier | |
12718 | versions of Perl with mysterious failures, put this sort of thing at the | |
12719 | top of your file to signal that your code will work I<only> on Perls of a | |
12720 | recent vintage: | |
12721 | ||
12722 | =end original | |
12723 | ||
12724 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な | |
12725 | 失敗で混乱することを避けるために、コードが最近のバージョンの Perl で | |
12726 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを | |
12727 | 書いてください: | |
12728 | ||
12729 | use 5.012; # so readdir assigns to $_ in a lone while test | |
12730 | ||
10572 | 12731 | =item readline EXPR |
10573 | 12732 | |
10574 | 12733 | =item readline |
10575 | 12734 | X<readline> X<gets> X<fgets> |
10576 | 12735 | |
12736 | =for Pod::Functions fetch a record from a file | |
12737 | ||
10577 | 12738 | =begin original |
10578 | 12739 | |
10579 | 12740 | Reads from the filehandle whose typeglob is contained in EXPR (or from |
10580 | 12741 | C<*ARGV> if EXPR is not provided). In scalar context, each call reads and |
10581 | 12742 | returns the next line until end-of-file is reached, whereupon the |
10582 | subsequent call returns C<undef>. In list context, reads | |
12743 | subsequent call returns L<C<undef>|/undef EXPR>. In list context, reads | |
10583 | is reached and returns a list of lines. Note that the | |
12744 | until end-of-file is reached and returns a list of lines. Note that the | |
10584 | used here is whatever you may have defined with | |
12745 | notion of "line" used here is whatever you may have defined with | |
10585 | C<$INPUT_RECORD_SEPARATOR> | |
12746 | L<C<$E<sol>>|perlvar/$E<sol>> (or C<$INPUT_RECORD_SEPARATOR> in | |
12747 | L<English>). See L<perlvar/"$/">. | |
10586 | 12748 | |
10587 | 12749 | =end original |
10588 | 12750 | |
10589 | 12751 | 型グロブが EXPR (EXPR がない場合は C<*ARGV>) に含まれている |
10590 | 12752 | ファイルハンドルから読み込みます。 |
10591 | スカラコンテキストでは、呼び出し毎に一行読み込んで返します | |
12753 | スカラコンテキストでは、呼び出し毎に一行読み込んで返します; ファイルの | |
10592 | ||
12754 | 最後まで読み込んだら、以後の呼び出しでは L<C<undef>|/undef EXPR> を返します。 | |
10593 | リストコンテキストでは、ファイルの最後まで読み込んで、 | |
12755 | リストコンテキストでは、ファイルの最後まで読み込んで、行のリストを返します。 | |
10594 | ||
12756 | ここでの「行」とは、L<C<$E<sol>>|perlvar/$E<sol>> (または | |
10595 | ||
12757 | L<English> モジュールでは C<$INPUT_RECORD_SEPARATOR>) で | |
10596 | 12758 | 定義されることに注意してください。 |
10597 | L<perlvar/"$/"> を参照して | |
12759 | L<perlvar/"$/"> を参照してください。 | |
10598 | 12760 | |
10599 | 12761 | =begin original |
10600 | 12762 | |
10601 | When C<$/> is set to C<undef> | |
12763 | When L<C<$E<sol>>|perlvar/$E<sol>> is set to L<C<undef>|/undef EXPR>, | |
10602 | ||
12764 | when L<C<readline>|/readline EXPR> is in scalar context (i.e., file | |
10603 | returns C<''> the first | |
12765 | slurp mode), and when an empty file is read, it returns C<''> the first | |
12766 | time, followed by L<C<undef>|/undef EXPR> subsequently. | |
10604 | 12767 | |
10605 | 12768 | =end original |
10606 | 12769 | |
10607 | C<$/> に C<undef> を設定した場合は、 | |
12770 | L<C<$E<sol>>|perlvar/$E<sol>> に L<C<undef>|/undef EXPR> を設定した場合は、 | |
10608 | (つまりファイル吸い込み | |
12771 | L<C<readline>|/readline EXPR> はスカラコンテキスト (つまりファイル吸い込み | |
10609 | 空のファイルを読み込んだ場合は、最初は C<''> を返し、 | |
12772 | モード)となり、空のファイルを読み込んだ場合は、最初は C<''> を返し、 | |
10610 | それ以降は C<undef> を返します。 | |
12773 | それ以降は L<C<undef>|/undef EXPR> を返します。 | |
10611 | 12774 | |
10612 | 12775 | =begin original |
10613 | 12776 | |
10614 | 12777 | This is the internal function implementing the C<< <EXPR> >> |
10615 | 12778 | operator, but you can use it directly. The C<< <EXPR> >> |
10616 | 12779 | operator is discussed in more detail in L<perlop/"I/O Operators">. |
10617 | 12780 | |
10618 | 12781 | =end original |
10619 | 12782 | |
10620 | 12783 | これは C<< <EXPR> >> 演算子を実装している内部関数ですが、 |
10621 | 12784 | 直接使うこともできます。 |
10622 | 12785 | C<< <EXPR> >> 演算子についてのさらなる詳細については |
10623 | 12786 | L<perlop/"I/O Operators"> で議論されています。 |
10624 | 12787 | |
10625 | $line = <STDIN>; | |
12788 | my $line = <STDIN>; | |
10626 | $line = readline( | |
12789 | my $line = readline(STDIN); # same thing | |
10627 | 12790 | |
10628 | 12791 | =begin original |
10629 | 12792 | |
10630 | If C<readline> encounters an operating system error, | |
12793 | If L<C<readline>|/readline EXPR> encounters an operating system error, | |
10631 | with the corresponding error message. | |
12794 | L<C<$!>|perlvar/$!> will be set with the corresponding error message. | |
10632 | C<$!> when you are reading from | |
12795 | It can be helpful to check L<C<$!>|perlvar/$!> when you are reading from | |
10633 | tty or a socket. The following | |
12796 | filehandles you don't trust, such as a tty or a socket. The following | |
10634 | ||
12797 | example uses the operator form of L<C<readline>|/readline EXPR> and dies | |
12798 | if the result is not defined. | |
10635 | 12799 | |
10636 | 12800 | =end original |
10637 | 12801 | |
10638 | C<readline> が OS のシステムエラーになると、 | |
12802 | L<C<readline>|/readline EXPR> が OS のシステムエラーになると、 | |
10639 | セットされます。 | |
12803 | L<C<$!>|perlvar/$!> に対応するエラーメッセージがセットされます。 | |
10640 | 12804 | tty やソケットといった、信頼できないファイルハンドルから読み込む時には |
10641 | C<$!> をチェックするのが助けになります。 | |
12805 | L<C<$!>|perlvar/$!> をチェックするのが助けになります。 | |
10642 | 以下の例は演算子の形の C<readline> を使っており、結果が | |
12806 | 以下の例は演算子の形の L<C<readline>|/readline EXPR> を使っており、結果が | |
10643 | 12807 | 未定義の場合は die します。 |
10644 | 12808 | |
10645 | 12809 | while ( ! eof($fh) ) { |
10646 | defined( $_ = | |
12810 | defined( $_ = readline $fh ) or die "readline failed: $!"; | |
10647 | 12811 | ... |
10648 | 12812 | } |
10649 | 12813 | |
10650 | 12814 | =begin original |
10651 | 12815 | |
10652 | Note that you have can't handle C<readline> errors | |
12816 | Note that you have can't handle L<C<readline>|/readline EXPR> errors | |
10653 | C<ARGV> filehandle. In that case, you have to open | |
12817 | that way with the C<ARGV> filehandle. In that case, you have to open | |
10654 | C<@ARGV> yourself since | |
12818 | each element of L<C<@ARGV>|perlvar/@ARGV> yourself since | |
12819 | L<C<eof>|/eof FILEHANDLE> handles C<ARGV> differently. | |
10655 | 12820 | |
10656 | 12821 | =end original |
10657 | 12822 | |
10658 | C<readline> のエラーは C<ARGV> ファイルハンドルの方法では | |
12823 | L<C<readline>|/readline EXPR> のエラーは C<ARGV> ファイルハンドルの方法では | |
10659 | 注意してください。 | |
12824 | 扱えないことに注意してください。 | |
10660 | この場合、C<eof> は C<ARGV> を異なった方法で扱うので、 | |
12825 | この場合、L<C<eof>|/eof FILEHANDLE> は C<ARGV> を異なった方法で扱うので、 | |
10661 | C<@ARGV> のそれぞれの要素を自分でオープンする必要があります。 | |
12826 | L<C<@ARGV>|perlvar/@ARGV> のそれぞれの要素を自分でオープンする必要があります。 | |
10662 | 12827 | |
10663 | 12828 | foreach my $arg (@ARGV) { |
10664 | 12829 | open(my $fh, $arg) or warn "Can't open $arg: $!"; |
10665 | 12830 | |
10666 | 12831 | while ( ! eof($fh) ) { |
10667 | defined( $_ = | |
12832 | defined( $_ = readline $fh ) | |
10668 | 12833 | or die "readline failed for $arg: $!"; |
10669 | 12834 | ... |
10670 | 12835 | } |
10671 | 12836 | } |
10672 | 12837 | |
10673 | 12838 | =item readlink EXPR |
10674 | 12839 | X<readlink> |
10675 | 12840 | |
10676 | 12841 | =item readlink |
10677 | 12842 | |
12843 | =for Pod::Functions determine where a symbolic link is pointing | |
12844 | ||
10678 | 12845 | =begin original |
10679 | 12846 | |
10680 | 12847 | Returns the value of a symbolic link, if symbolic links are |
10681 | 12848 | implemented. If not, raises an exception. If there is a system |
10682 | error, returns the undefined value and sets C<$!> (errno). | |
12849 | error, returns the undefined value and sets L<C<$!>|perlvar/$!> (errno). | |
10683 | omitted, uses C<$_>. | |
12850 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. | |
10684 | 12851 | |
10685 | 12852 | =end original |
10686 | 12853 | |
10687 | シンボリックリンクが実装されていれば、 | |
12854 | シンボリックリンクが実装されていれば、シンボリックリンクの値を返します。 | |
10688 | シンボリックリンクの値を返します。 | |
10689 | 12855 | 実装されていないときには、例外が発生します。 |
10690 | 12856 | 何らかのシステムエラーが検出されると、未定義値を返し、 |
10691 | C<$!> (errno) を設定します。 | |
12857 | L<C<$!>|perlvar/$!> (errno) を設定します。 | |
10692 | EXPR が省略されると、C<$_> を使います。 | |
12858 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
10693 | 12859 | |
12860 | =begin original | |
12861 | ||
12862 | Portability issues: L<perlport/readlink>. | |
12863 | ||
12864 | =end original | |
12865 | ||
12866 | 移植性の問題: L<perlport/readlink>。 | |
12867 | ||
10694 | 12868 | =item readpipe EXPR |
10695 | 12869 | |
10696 | 12870 | =item readpipe |
10697 | 12871 | X<readpipe> |
10698 | 12872 | |
12873 | =for Pod::Functions execute a system command and collect standard output | |
12874 | ||
10699 | 12875 | =begin original |
10700 | 12876 | |
10701 | 12877 | EXPR is executed as a system command. |
10702 | 12878 | The collected standard output of the command is returned. |
10703 | 12879 | In scalar context, it comes back as a single (potentially |
10704 | 12880 | multi-line) string. In list context, returns a list of lines |
10705 | (however you've defined lines with C<$ | |
12881 | (however you've defined lines with L<C<$E<sol>>|perlvar/$E<sol>> (or | |
12882 | C<$INPUT_RECORD_SEPARATOR> in L<English>)). | |
10706 | 12883 | This is the internal function implementing the C<qx/EXPR/> |
10707 | 12884 | operator, but you can use it directly. The C<qx/EXPR/> |
10708 | 12885 | operator is discussed in more detail in L<perlop/"I/O Operators">. |
10709 | If EXPR is omitted, uses C<$_>. | |
12886 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. | |
10710 | 12887 | |
10711 | 12888 | =end original |
10712 | 12889 | |
10713 | 12890 | EXPR がシステムコマンドとして実行されます。 |
10714 | 12891 | コマンドの標準出力の内容が返されます。 |
10715 | 12892 | スカラコンテキストでは、単一の(内部的に複数行の)文字列を返します。 |
10716 | 12893 | リストコンテキストでは、行のリストを返します |
10717 | (但し、行は C<$/> または | |
12894 | (但し、行は L<C<$E<sol>>|perlvar/$E<sol>> (または L<English> モジュールでは | |
10718 | ||
12895 | C<$INPUT_RECORD_SEPARATOR> で定義されます)。 | |
10719 | 直接使うことも出来ます。 | |
12896 | これは C<qx/EXPR/> 演算子を実装する内部関数ですが、直接使うことも出来ます。 | |
10720 | C<qx/EXPR/> 演算子は L<perlop/"I/O Operators"> でより詳細に | |
12897 | C<qx/EXPR/> 演算子は L<perlop/"I/O Operators"> でより詳細に述べられています。 | |
10721 | ||
12898 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
10722 | EXPR を省略すると、C<$_> を使用します。 | |
10723 | 12899 | |
10724 | 12900 | =item recv SOCKET,SCALAR,LENGTH,FLAGS |
10725 | 12901 | X<recv> |
10726 | 12902 | |
12903 | =for Pod::Functions receive a message over a Socket | |
12904 | ||
10727 | 12905 | =begin original |
10728 | 12906 | |
10729 | 12907 | Receives a message on a socket. Attempts to receive LENGTH characters |
10730 | 12908 | of data into variable SCALAR from the specified SOCKET filehandle. |
10731 | 12909 | SCALAR will be grown or shrunk to the length actually read. Takes the |
10732 | 12910 | same flags as the system call of the same name. Returns the address |
10733 | 12911 | of the sender if SOCKET's protocol supports this; returns an empty |
10734 | 12912 | string otherwise. If there's an error, returns the undefined value. |
10735 | This call is actually implemented in terms of recvfrom(2) system call. | |
12913 | This call is actually implemented in terms of the L<recvfrom(2)> system call. | |
10736 | 12914 | See L<perlipc/"UDP: Message Passing"> for examples. |
10737 | 12915 | |
10738 | 12916 | =end original |
10739 | 12917 | |
10740 | 12918 | ソケット上のメッセージを受信します。 |
10741 | 12919 | 指定されたファイルハンドル SOCKET から、変数 SCALAR に |
10742 | 12920 | LENGTH 文字のデータを読み込もうとします。 |
10743 | SCALAR は、実際に読まれた長さによって、大きくなったり、 | |
12921 | SCALAR は、実際に読まれた長さによって、大きくなったり、小さくなったりします。 | |
10744 | ||
12922 | 同名のシステムコールと同じフラグが指定できます。 | |
10745 | 同名のシステムコールと同じ FLAGS を使います。 | |
10746 | 12923 | SOCKET のプロトコルが対応していれば、送信側のアドレスを返します。 |
10747 | 12924 | エラー発生時には、未定義値を返します。 |
10748 | 実際には、C のrecvfrom(2) を呼びます。 | |
12925 | 実際には、C の L<recvfrom(2)> を呼びます。 | |
10749 | 例についてはL<perlipc/"UDP: Message Passing">を参照してください。 | |
12926 | 例については L<perlipc/"UDP: Message Passing"> を参照してください。 | |
10750 | 12927 | |
10751 | 12928 | =begin original |
10752 | 12929 | |
10753 | 12930 | Note the I<characters>: depending on the status of the socket, either |
10754 | 12931 | (8-bit) bytes or characters are received. By default all sockets |
10755 | 12932 | operate on bytes, but for example if the socket has been changed using |
10756 | binmode | |
12933 | L<C<binmode>|/binmode FILEHANDLE, LAYER> to operate with the | |
10757 | C< | |
12934 | C<:encoding(utf8)> I/O layer (see the L<open> pragma), the I/O will | |
10758 | ||
12935 | operate on UTF8-encoded Unicode | |
12936 | characters, not bytes. Similarly for the C<:encoding> layer: in that | |
10759 | 12937 | case pretty much any characters can be read. |
10760 | 12938 | |
10761 | 12939 | =end original |
10762 | 12940 | |
10763 | 12941 | I<文字> に関する注意: ソケットの状態によって、(8 ビットの) バイトか |
10764 | 12942 | 文字を受信します。 |
10765 | デフォルトでは全てのソケットはバイトを処理しますが、 | |
12943 | デフォルトでは全てのソケットはバイトを処理しますが、例えばソケットが | |
10766 | ||
12944 | L<C<binmode>|/binmode FILEHANDLE, LAYER> で C<:encoding(utf8)> I/O 層 | |
10767 | L<open> を参照してください) を使うように指定された場合 | |
12945 | (L<open> プラグマを参照してください) を使うように指定された場合、 | |
10768 | UTF8 エンコードされた Unicode 文字を操作します。 | |
12946 | I/O はバイトではなく、UTF8 エンコードされた Unicode 文字を操作します。 | |
10769 | C<:encoding> | |
12947 | C<:encoding> 層も同様です: | |
10770 | 12948 | この場合、ほとんど大体全ての文字が読み込めます。 |
10771 | 12949 | |
10772 | 12950 | =item redo LABEL |
10773 | 12951 | X<redo> |
10774 | 12952 | |
12953 | =item redo EXPR | |
12954 | ||
10775 | 12955 | =item redo |
10776 | 12956 | |
12957 | =for Pod::Functions start this loop iteration over again | |
12958 | ||
10777 | 12959 | =begin original |
10778 | 12960 | |
10779 | The C<redo> command restarts the loop block without | |
12961 | The L<C<redo>|/redo LABEL> command restarts the loop block without | |
10780 | conditional again. The C<continue> | |
12962 | evaluating the conditional again. The L<C<continue>|/continue BLOCK> | |
12963 | block, if any, is not executed. If | |
10781 | 12964 | the LABEL is omitted, the command refers to the innermost enclosing |
10782 | loop. | |
12965 | loop. The C<redo EXPR> form, available starting in Perl 5.18.0, allows a | |
12966 | label name to be computed at run time, and is otherwise identical to C<redo | |
12967 | LABEL>. Programs that want to lie to themselves about what was just input | |
10783 | 12968 | normally use this command: |
10784 | 12969 | |
10785 | 12970 | =end original |
10786 | 12971 | |
10787 | C<redo> コマンドは、条件を再評価しないで、ループブロックの | |
12972 | L<C<redo>|/redo LABEL> コマンドは、条件を再評価しないで、ループブロックの | |
10788 | 実行を開始します。 | |
12973 | 始めからもう一度実行を開始します。 | |
10789 | C<continue> ブロックがあっても、実行されません。 | |
12974 | L<C<continue>|/continue BLOCK> ブロックがあっても、実行されません。 | |
10790 | LABEL が省略されると、 | |
12975 | LABEL が省略されると、コマンドは一番内側のループを参照します。 | |
12976 | Perl 5.18.0 から利用可能な C<redo EXPR> 形式では、実行時に計算されるラベル名が | |
12977 | 使えます; それ以外は C<redo LABEL> と同一です。 | |
10791 | 12978 | このコマンドは通常、自分への入力を欺くために使用します: |
10792 | 12979 | |
10793 | 12980 | # a simpleminded Pascal comment stripper |
10794 | 12981 | # (warning: assumes no { or } in strings) |
10795 | 12982 | LINE: while (<STDIN>) { |
10796 | 12983 | while (s|({.*}.*){.*}|$1 |) {} |
10797 | 12984 | s|{.*}| |; |
10798 | 12985 | if (s|{.*| |) { |
10799 | $front = $_; | |
12986 | my $front = $_; | |
10800 | 12987 | while (<STDIN>) { |
10801 | 12988 | if (/}/) { # end of comment? |
10802 | 12989 | s|^|$front\{|; |
10803 | 12990 | redo LINE; |
10804 | 12991 | } |
10805 | 12992 | } |
10806 | 12993 | } |
10807 | 12994 | print; |
10808 | 12995 | } |
10809 | 12996 | |
10810 | 12997 | =begin original |
10811 | 12998 | |
10812 | C<redo> cannot be used to retry a block that returns a | |
12999 | L<C<redo>|/redo LABEL> cannot be used to retry a block that returns a | |
10813 | C<eval {}>, C<sub {}>, or C<do {}>, and should not be used | |
13000 | value such as C<eval {}>, C<sub {}>, or C<do {}>, and should not be used | |
10814 | a grep | |
13001 | to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST> | |
13002 | operation. | |
10815 | 13003 | |
10816 | 13004 | =end original |
10817 | 13005 | |
10818 | C<redo> は C<eval {}>, C<sub {}>, C<do {}> のように値を返す | |
13006 | L<C<redo>|/redo LABEL> は C<eval {}>, C<sub {}>, C<do {}> のように値を返す | |
10819 | ブロックを繰り返すのには使えません | |
13007 | ブロックを繰り返すのには使えません; また、L<C<grep>|/grep BLOCK LIST> や | |
10820 | ||
13008 | L<C<map>|/map BLOCK LIST> 操作から抜けるのに使うべきではありません。 | |
10821 | 13009 | |
10822 | 13010 | =begin original |
10823 | 13011 | |
10824 | 13012 | Note that a block by itself is semantically identical to a loop |
10825 | that executes once. Thus C<redo> inside such a block | |
13013 | that executes once. Thus L<C<redo>|/redo LABEL> inside such a block | |
10826 | turn it into a looping construct. | |
13014 | will effectively turn it into a looping construct. | |
10827 | 13015 | |
10828 | 13016 | =end original |
10829 | 13017 | |
10830 | 13018 | ブロック自身は一回だけ実行されるループと文法的に同一であることに |
10831 | 13019 | 注意してください。 |
10832 | 従って、ブロックの中で C<redo> を使うことで効果的に | |
13020 | 従って、ブロックの中で L<C<redo>|/redo LABEL> を使うことで効果的に | |
10833 | 13021 | ループ構造に変換します。 |
10834 | 13022 | |
10835 | 13023 | =begin original |
10836 | 13024 | |
10837 | See also L</continue> for an illustration of how | |
13025 | See also L<C<continue>|/continue BLOCK> for an illustration of how | |
10838 | C< | |
13026 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and | |
13027 | L<C<redo>|/redo LABEL> work. | |
10839 | 13028 | |
10840 | 13029 | =end original |
10841 | 13030 | |
10842 | C<last>, C<next>, C<redo> が | |
13031 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL> が | |
10843 | L</continue> も参照して | |
13032 | どのように働くかについては L<C<continue>|/continue BLOCK> も参照してください。 | |
10844 | 13033 | |
13034 | =begin original | |
13035 | ||
13036 | Unlike most named operators, this has the same precedence as assignment. | |
13037 | It is also exempt from the looks-like-a-function rule, so | |
13038 | C<redo ("foo")."bar"> will cause "bar" to be part of the argument to | |
13039 | L<C<redo>|/redo LABEL>. | |
13040 | ||
13041 | =end original | |
13042 | ||
13043 | ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 | |
13044 | また、関数のように見えるものの規則からも免れるので、C<redo ("foo")."bar"> と | |
13045 | すると "bar" は L<C<redo>|/redo LABEL> への引数の一部となります。 | |
13046 | ||
10845 | 13047 | =item ref EXPR |
10846 | 13048 | X<ref> X<reference> |
10847 | 13049 | |
10848 | 13050 | =item ref |
10849 | 13051 | |
13052 | =for Pod::Functions find out the type of thing being referenced | |
13053 | ||
10850 | 13054 | =begin original |
10851 | 13055 | |
10852 | 13056 | Returns a non-empty string if EXPR is a reference, the empty |
10853 | string otherwise. If EXPR | |
13057 | string otherwise. If EXPR is not specified, L<C<$_>|perlvar/$_> will be | |
10854 | ||
13058 | used. The value returned depends on the type of thing the reference is | |
10855 | ||
13059 | a reference to. | |
10856 | Builtin types include: | |
10857 | 13060 | |
10858 | 13061 | =end original |
10859 | 13062 | |
10860 | 13063 | EXPR がリファレンスであれば、空でない文字列を返し、さもなくば、 |
10861 | 13064 | 空文字列を返します。 |
10862 | EXPR が指定されなければ、C<$_> が使われます。 | |
13065 | EXPR が指定されなければ、L<C<$_>|perlvar/$_> が使われます。 | |
10863 | 13066 | 返される値は、リファレンスが参照するものの型に依存します。 |
13067 | ||
13068 | =begin original | |
13069 | ||
13070 | Builtin types include: | |
13071 | ||
13072 | =end original | |
13073 | ||
10864 | 13074 | 組み込みの型には、以下のものがあります。 |
10865 | 13075 | |
10866 | 13076 | SCALAR |
10867 | 13077 | ARRAY |
10868 | 13078 | HASH |
10869 | 13079 | CODE |
10870 | 13080 | REF |
10871 | 13081 | GLOB |
10872 | 13082 | LVALUE |
10873 | 13083 | FORMAT |
10874 | 13084 | IO |
10875 | 13085 | VSTRING |
10876 | 13086 | Regexp |
10877 | 13087 | |
10878 | 13088 | =begin original |
10879 | 13089 | |
10880 | ||
13090 | You can think of L<C<ref>|/ref EXPR> as a C<typeof> operator. | |
10881 | name is returned instead. You can think of C<ref> as a C<typeof> operator. | |
10882 | 13091 | |
10883 | 13092 | =end original |
10884 | 13093 | |
10885 | ||
13094 | L<C<ref>|/ref EXPR> は、C<typeof> 演算子のように考えることができます。 | |
10886 | bless されたものであれば、これらの代わりに、 | |
10887 | そのパッケージ名が返されます。 | |
10888 | C<ref> は、C<typeof> 演算子のように考えることができます。 | |
10889 | 13095 | |
10890 | 13096 | if (ref($r) eq "HASH") { |
10891 | 13097 | print "r is a reference to a hash.\n"; |
10892 | 13098 | } |
10893 | 13099 | unless (ref($r)) { |
10894 | 13100 | print "r is not a reference at all.\n"; |
10895 | 13101 | } |
10896 | 13102 | |
10897 | 13103 | =begin original |
10898 | 13104 | |
10899 | 13105 | The return value C<LVALUE> indicates a reference to an lvalue that is not |
10900 | a variable. You get this from taking the reference of function calls like | |
13106 | a variable. You get this from taking the reference of function calls like | |
10901 | C<pos | |
13107 | L<C<pos>|/pos SCALAR> or | |
10902 | ||
13108 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT>. C<VSTRING> is | |
13109 | returned if the reference points to a | |
13110 | L<version string|perldata/"Version Strings">. | |
10903 | 13111 | |
10904 | 13112 | =end original |
10905 | 13113 | |
10906 | 13114 | 返り値 C<LVALUE> は、変数ではない左辺値へのリファレンスを示します。 |
10907 | これは、C<pos | |
13115 | これは、L<C<pos>|/pos SCALAR> や | |
10908 | ||
13116 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> のような関数呼び出しの | |
13117 | リファレンスから得られます。 | |
10909 | 13118 | C<VSTRING> は、リファレンスが L<version string|perldata/"Version Strings"> を |
10910 | 13119 | 指している場合に返されます。 |
10911 | 13120 | |
10912 | 13121 | =begin original |
10913 | 13122 | |
10914 | 13123 | The result C<Regexp> indicates that the argument is a regular expression |
10915 | resulting from C<qr/ | |
13124 | resulting from L<C<qrE<sol>E<sol>>|/qrE<sol>STRINGE<sol>>. | |
10916 | 13125 | |
10917 | 13126 | =end original |
10918 | 13127 | |
10919 | C<Regexp> という結果は、引数が | |
13128 | C<Regexp> という結果は、引数が | |
13129 | L<C<qrE<sol>E<sol>>|/qrE<sol>STRINGE<sol>> からの結果である | |
10920 | 13130 | 正規表現であることを意味します。 |
10921 | 13131 | |
10922 | 13132 | =begin original |
10923 | 13133 | |
13134 | If the referenced object has been blessed into a package, then that package | |
13135 | name is returned instead. But don't use that, as it's now considered | |
13136 | "bad practice". For one reason, an object could be using a class called | |
13137 | C<Regexp> or C<IO>, or even C<HASH>. Also, L<C<ref>|/ref EXPR> doesn't | |
13138 | take into account subclasses, like | |
13139 | L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>> does. | |
13140 | ||
13141 | =end original | |
13142 | ||
13143 | 参照されるオブジェクトが、何らかのパッケージに bless されたものであれば、 | |
13144 | これらの代わりに、そのパッケージ名が返されます。 | |
13145 | しかし、これは今では「悪い習慣」と考えられているので、しないでください。 | |
13146 | 理由の一つは、オブジェクトは C<Regexp>, C<IO> や C<HASH> などと呼ばれる | |
13147 | クラスを使うかも知れないからです。 | |
13148 | また、L<C<ref>|/ref EXPR> は | |
13149 | L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>> のようにサブクラスを | |
13150 | 考慮したりはしません。 | |
13151 | ||
13152 | =begin original | |
13153 | ||
13154 | Instead, use L<C<blessed>|Scalar::Util/blessed> (in the L<Scalar::Util> | |
13155 | module) for boolean checks, L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>> | |
13156 | for specific class checks and L<C<reftype>|Scalar::Util/reftype> (also | |
13157 | from L<Scalar::Util>) for type checks. (See L<perlobj> for details and | |
13158 | a L<C<blessed>|Scalar::Util/blessed>/L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>> | |
13159 | example.) | |
13160 | ||
13161 | =end original | |
13162 | ||
13163 | 代わりに、真偽値チェックには (L<Scalar::Util> モジュールにある) | |
13164 | L<C<blessed>|Scalar::Util/blessed> を、特定のクラスのチェックには | |
13165 | L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>> を、型のチェックには | |
13166 | (これも L<Scalar::Util> にある) L<C<reftype>|Scalar::Util/reftype> を | |
13167 | 使ってください。 | |
13168 | (詳細と L<C<blessed>|Scalar::Util/blessed>/ | |
13169 | L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>> の例については | |
13170 | L<perlobj> を参照してください。) | |
13171 | ||
13172 | =begin original | |
13173 | ||
10924 | 13174 | See also L<perlref>. |
10925 | 13175 | |
10926 | 13176 | =end original |
10927 | 13177 | |
10928 | 13178 | L<perlref> も参照してください。 |
10929 | 13179 | |
10930 | 13180 | =item rename OLDNAME,NEWNAME |
10931 | 13181 | X<rename> X<move> X<mv> X<ren> |
10932 | 13182 | |
13183 | =for Pod::Functions change a filename | |
13184 | ||
10933 | 13185 | =begin original |
10934 | 13186 | |
10935 | 13187 | Changes the name of a file; an existing file NEWNAME will be |
10936 | 13188 | clobbered. Returns true for success, false otherwise. |
10937 | 13189 | |
10938 | 13190 | =end original |
10939 | 13191 | |
10940 | ファイルの名前を変更します | |
13192 | ファイルの名前を変更します; NEWNAME というファイルが既に存在した場合、 | |
10941 | ||
13193 | 上書きされるかもしれません。 | |
10942 | 成功時には真、 | |
13194 | 成功時には真を、さもなければ偽を返します。 | |
10943 | 13195 | |
10944 | 13196 | =begin original |
10945 | 13197 | |
10946 | 13198 | Behavior of this function varies wildly depending on your system |
10947 | 13199 | implementation. For example, it will usually not work across file system |
10948 | 13200 | boundaries, even though the system I<mv> command sometimes compensates |
10949 | 13201 | for this. Other restrictions include whether it works on directories, |
10950 | 13202 | open files, or pre-existing files. Check L<perlport> and either the |
10951 | rename(2) manpage or equivalent system documentation for details. | |
13203 | L<rename(2)> manpage or equivalent system documentation for details. | |
10952 | 13204 | |
10953 | 13205 | =end original |
10954 | 13206 | |
10955 | 13207 | この関数の振る舞いはシステムの実装に大きく依存して異なります。 |
10956 | 普通はファイルシステムにまたがってパス名を付け替えることはできません | |
13208 | 例えば、普通はファイルシステムにまたがってパス名を付け替えることはできません; | |
10957 | 13209 | システムの I<mv> がこれを補完している場合でもそうです。 |
10958 | 13210 | その他の制限には、ディレクトリ、オープンしているファイル、既に存在している |
10959 | 13211 | ファイルに対して使えるか、といったことを含みます。 |
10960 | 詳しくは、L<perlport> および rename(2) man ページあるいは同様の | |
13212 | 詳しくは、L<perlport> および L<rename(2)> man ページあるいは同様の | |
10961 | 13213 | システムドキュメントを参照してください。 |
10962 | 13214 | |
10963 | 13215 | =begin original |
10964 | 13216 | |
10965 | For a platform independent C<move> function look at | |
13217 | For a platform independent L<C<move>|File::Copy/move> function look at | |
10966 | module. | |
13218 | the L<File::Copy> module. | |
10967 | 13219 | |
10968 | 13220 | =end original |
10969 | 13221 | |
10970 | プラットフォームに依存しない C<move> | |
13222 | プラットフォームに依存しない L<C<move>|File::Copy/move> 関数については | |
10971 | 参照してください。 | |
13223 | L<File::Copy> モジュールを参照してください。 | |
10972 | 13224 | |
13225 | =begin original | |
13226 | ||
13227 | Portability issues: L<perlport/rename>. | |
13228 | ||
13229 | =end original | |
13230 | ||
13231 | 移植性の問題: L<perlport/rename>。 | |
13232 | ||
10973 | 13233 | =item require VERSION |
10974 | 13234 | X<require> |
10975 | 13235 | |
10976 | 13236 | =item require EXPR |
10977 | 13237 | |
10978 | 13238 | =item require |
10979 | 13239 | |
13240 | =for Pod::Functions load in external functions from a library at runtime | |
13241 | ||
10980 | 13242 | =begin original |
10981 | 13243 | |
10982 | 13244 | Demands a version of Perl specified by VERSION, or demands some semantics |
10983 | specified by EXPR or by C<$_> if EXPR is not supplied. | |
13245 | specified by EXPR or by L<C<$_>|perlvar/$_> if EXPR is not supplied. | |
10984 | 13246 | |
10985 | 13247 | =end original |
10986 | 13248 | |
10987 | 13249 | VERSION で指定される Perl のバージョンを要求するか、 |
10988 | EXPR (省略時には C<$_>) によって指定されるいくつかの動作を | |
13250 | EXPR (省略時には L<C<$_>|perlvar/$_>) によって指定されるいくつかの動作を | |
13251 | 要求します。 | |
10989 | 13252 | |
10990 | 13253 | =begin original |
10991 | 13254 | |
10992 | 13255 | VERSION may be either a numeric argument such as 5.006, which will be |
10993 | compared to C<$]>, or a literal of the form v5.6.1, which | |
13256 | compared to L<C<$]>|perlvar/$]>, or a literal of the form v5.6.1, which | |
10994 | to C<$^V> ( | |
13257 | will be compared to L<C<$^V>|perlvar/$^V> (or C<$PERL_VERSION> in | |
10995 | VERSION is greater than the | |
13258 | L<English>). An exception is raised if VERSION is greater than the | |
10996 | ||
13259 | version of the current Perl interpreter. Compare with | |
13260 | L<C<use>|/use Module VERSION LIST>, which can do a similar check at | |
13261 | compile time. | |
10997 | 13262 | |
10998 | 13263 | =end original |
10999 | 13264 | |
11000 | VERSION は 5.006 のような数値(C<$]> と比較されます)か、 | |
13265 | VERSION は 5.006 のような数値(L<C<$]>|perlvar/$]> と比較されます)か、 | |
11001 | (C<$^V> (また | |
13266 | v5.6.1 の形 (L<C<$^V>|perlvar/$^V> (または L<English> モジュールでは | |
13267 | C<$PERL_VERSION>) と比較されます)で指定します。 | |
11002 | 13268 | VERSION が Perl の現在のバージョンより大きいと、例外が発生します。 |
11003 | L</use> と似ていますが、これはコンパイル時に | |
13269 | L<C<use>|/use Module VERSION LIST> と似ていますが、これはコンパイル時に | |
13270 | チェックされます。 | |
11004 | 13271 | |
11005 | 13272 | =begin original |
11006 | 13273 | |
11007 | 13274 | Specifying VERSION as a literal of the form v5.6.1 should generally be |
11008 | 13275 | avoided, because it leads to misleading error messages under earlier |
11009 | 13276 | versions of Perl that do not support this syntax. The equivalent numeric |
11010 | 13277 | version should be used instead. |
11011 | 13278 | |
11012 | 13279 | =end original |
11013 | 13280 | |
11014 | 13281 | VERSION に v5.6.1 の形のリテラルを指定することは一般的には避けるべきです; |
11015 | 13282 | なぜなら、この文法に対応していない Perl の初期のバージョンでは |
11016 | 13283 | 誤解させるようなエラーメッセージが出るからです。 |
11017 | 13284 | 代わりに等価な数値表現を使うべきです。 |
11018 | 13285 | |
11019 | 13286 | =begin original |
11020 | 13287 | |
11021 | 13288 | require v5.6.1; # run time version check |
11022 | 13289 | require 5.6.1; # ditto |
11023 | require 5.006_001; # ditto; preferred for backwards | |
13290 | require 5.006_001; # ditto; preferred for backwards | |
13291 | compatibility | |
11024 | 13292 | |
11025 | 13293 | =end original |
11026 | 13294 | |
11027 | 13295 | require v5.6.1; # 実行時バージョンチェック |
11028 | 13296 | require 5.6.1; # 同様 |
11029 | 13297 | require 5.006_001; # 同様; 後方互換性のためには望ましい |
11030 | 13298 | |
11031 | 13299 | =begin original |
11032 | 13300 | |
11033 | Otherwise, C<require> demands that a library file be | |
13301 | Otherwise, L<C<require>|/require VERSION> demands that a library file be | |
11034 | hasn't already been included. The file is included via | |
13302 | included if it hasn't already been included. The file is included via | |
11035 | mechanism, which is essentially just a variety of | |
13303 | the do-FILE mechanism, which is essentially just a variety of | |
13304 | L<C<eval>|/eval EXPR> with the | |
11036 | 13305 | caveat that lexical variables in the invoking script will be invisible |
11037 | to the included code. | |
13306 | to the included code. If it were implemented in pure Perl, it | |
13307 | would have semantics similar to the following: | |
11038 | 13308 | |
11039 | 13309 | =end original |
11040 | 13310 | |
11041 | それ以外の場合には、C<require> は、既に | |
13311 | それ以外の場合には、L<C<require>|/require VERSION> は、既に | |
11042 | ライブラリファイルを要求するものとなります。 | |
13312 | 読み込まれていないときに読み込むライブラリファイルを要求するものとなります。 | |
11043 | そのファイルは、基本的には C<eval> の一種である、 | |
13313 | そのファイルは、基本的には L<C<eval>|/eval EXPR> の一種である、 | |
11044 | 読み込まれますが、起動したスクリプトのレキシカル変数は | |
13314 | do-FILE によって読み込まれますが、起動したスクリプトのレキシカル変数は | |
11045 | 見えないという欠点があります。 | |
13315 | 読み込まれたコードから見えないという欠点があります。 | |
11046 | 意味的には、次のようなサブルーチンと | |
13316 | ピュア Perl で実装した場合、意味的には、次のようなサブルーチンと | |
13317 | 同じようなものです: | |
11047 | 13318 | |
13319 | use Carp 'croak'; | |
13320 | use version; | |
13321 | ||
11048 | 13322 | sub require { |
11049 | my ($filename) = @_; | |
13323 | my ($filename) = @_; | |
11050 | if (e | |
13324 | if ( my $version = eval { version->parse($filename) } ) { | |
11051 | | |
13325 | if ( $version > $^V ) { | |
11052 | | |
13326 | my $vn = $version->normal; | |
11053 | | |
13327 | croak "Perl $vn required--this is only $^V, stopped"; | |
11054 | | |
13328 | } | |
11055 | | |
13329 | return 1; | |
11056 | | |
13330 | } | |
11057 | ||
11058 | | |
13332 | if (exists $INC{$filename}) { | |
11059 | | |
13333 | return 1 if $INC{$filename}; | |
11060 | | |
13334 | croak "Compilation failed in require"; | |
11061 | | |
13335 | } | |
11062 | ||
11063 | | |
13337 | foreach $prefix (@INC) { | |
11064 | | |
13338 | if (ref($prefix)) { | |
11065 | | |
13339 | #... do other stuff - see text below .... | |
11066 | | |
13340 | } | |
11067 | | |
13341 | # (see text below about possible appending of .pmc | |
11068 | | |
13342 | # suffix to $filename) | |
11069 | | |
13343 | my $realfilename = "$prefix/$filename"; | |
11070 | | |
13344 | next if ! -e $realfilename || -d _ || -b _; | |
11071 | | |
13345 | $INC{$filename} = $realfilename; | |
11072 | | |
13346 | my $result = do($realfilename); | |
11073 | | |
13347 | # but run in caller's namespace | |
11074 | ||
13349 | if (!defined $result) { | |
13350 | $INC{$filename} = undef; | |
13351 | croak $@ ? "$@Compilation failed in require" | |
13352 | : "Can't locate $filename: $!\n"; | |
13353 | } | |
13354 | if (!$result) { | |
13355 | delete $INC{$filename}; | |
13356 | croak "$filename did not return true value"; | |
13357 | } | |
13358 | $! = 0; | |
13359 | return $result; | |
13360 | } | |
13361 | croak "Can't locate $filename in \@INC ..."; | |
11075 | 13362 | } |
11076 | 13363 | |
11077 | 13364 | =begin original |
11078 | 13365 | |
11079 | 13366 | Note that the file will not be included twice under the same specified |
11080 | 13367 | name. |
11081 | 13368 | |
11082 | 13369 | =end original |
11083 | 13370 | |
11084 | 13371 | ファイルは、同じ名前で 2 回読み込まれることはないことに注意してください。 |
11085 | 13372 | |
11086 | 13373 | =begin original |
11087 | 13374 | |
11088 | 13375 | The file must return true as the last statement to indicate |
11089 | 13376 | successful execution of any initialization code, so it's customary to |
11090 | 13377 | end such a file with C<1;> unless you're sure it'll return true |
11091 | 13378 | otherwise. But it's better just to put the C<1;>, in case you add more |
11092 | 13379 | statements. |
11093 | 13380 | |
11094 | 13381 | =end original |
11095 | 13382 | |
11096 | 初期化コードの実行がうまくいったことを示すために、 | |
13383 | 初期化コードの実行がうまくいったことを示すために、ファイルは真を | |
11097 | ||
13384 | 返さなければならないので、真を返すようになっている自信がある場合を除いては、 | |
11098 | 真を返すようになっている自信がある場合を除いては、 | |
11099 | 13385 | ファイルの最後に C<1;> と書くのが習慣です。 |
11100 | 実行文を追加するような場合に備えて、C<1;> と書いておいた方が | |
13386 | しかし、実行文を追加するような場合に備えて、C<1;> と書いておいた方が良いです。 | |
11101 | 良いでしょう。 | |
11102 | 13387 | |
11103 | 13388 | =begin original |
11104 | 13389 | |
11105 | If EXPR is a bareword, | |
13390 | If EXPR is a bareword, L<C<require>|/require VERSION> assumes a F<.pm> | |
11106 | replaces | |
13391 | extension and replaces C<::> with C</> in the filename for you, | |
11107 | 13392 | to make it easy to load standard modules. This form of loading of |
11108 | 13393 | modules does not risk altering your namespace. |
11109 | 13394 | |
11110 | 13395 | =end original |
11111 | 13396 | |
11112 | EXPR が裸の単語であるときには、標準モジュールのロードを | |
13397 | EXPR が裸の単語であるときには、標準モジュールのロードを簡単にするように、 | |
11113 | ||
13398 | L<C<require>|/require VERSION> は拡張子が F<.pm> であり、C<::> を C</> に | |
11114 | ||
13399 | 変えたものがファイル名であると仮定します。 | |
11115 | この形式のモジュールロードは、 | |
13400 | この形式のモジュールロードは、名前空間を変更してしまう危険はありません。 | |
11116 | 名前空間を変更してしまう危険はありません。 | |
11117 | 13401 | |
11118 | 13402 | =begin original |
11119 | 13403 | |
11120 | 13404 | In other words, if you try this: |
11121 | 13405 | |
11122 | 13406 | =end original |
11123 | 13407 | |
11124 | 13408 | 言い換えると、以下のようにすると: |
11125 | 13409 | |
11126 | 13410 | require Foo::Bar; # a splendid bareword |
11127 | 13411 | |
11128 | 13412 | =begin original |
11129 | 13413 | |
11130 | The require function will actually look for the | |
13414 | The require function will actually look for the F<Foo/Bar.pm> file in the | |
11131 | directories specified in the C<@INC> array. | |
13415 | directories specified in the L<C<@INC>|perlvar/@INC> array. | |
11132 | 13416 | |
11133 | 13417 | =end original |
11134 | 13418 | |
11135 | require 関数は C<@INC> 配列で指定されたディレクトリにある | |
13419 | require 関数は L<C<@INC>|perlvar/@INC> 配列で指定されたディレクトリにある | |
11136 | ||
13420 | F<Foo/Bar.pm> ファイルを探します。 | |
11137 | 13421 | |
11138 | 13422 | =begin original |
11139 | 13423 | |
11140 | 13424 | But if you try this: |
11141 | 13425 | |
11142 | 13426 | =end original |
11143 | 13427 | |
11144 | 13428 | しかし、以下のようにすると: |
11145 | 13429 | |
11146 | $class = 'Foo::Bar'; | |
13430 | my $class = 'Foo::Bar'; | |
11147 | 13431 | require $class; # $class is not a bareword |
11148 | 13432 | #or |
11149 | 13433 | require "Foo::Bar"; # not a bareword because of the "" |
11150 | 13434 | |
11151 | 13435 | =begin original |
11152 | 13436 | |
11153 | The require function will look for the | |
13437 | The require function will look for the F<Foo::Bar> file in the | |
11154 | ||
13438 | L<C<@INC>|perlvar/@INC> array and | |
13439 | will complain about not finding F<Foo::Bar> there. In this case you can do: | |
11155 | 13440 | |
11156 | 13441 | =end original |
11157 | 13442 | |
11158 | require 関数は @INC 配列の | |
13443 | require 関数は L<C<@INC>|perlvar/@INC> 配列の F<Foo::Bar> ファイルを探し、 | |
11159 | おそらくそこに | |
13444 | おそらくそこに F<Foo::Bar> がないと文句をいうことになるでしょう。 | |
11160 | 13445 | このような場合には、以下のようにします: |
11161 | 13446 | |
11162 | 13447 | eval "require $class"; |
11163 | 13448 | |
11164 | 13449 | =begin original |
11165 | 13450 | |
11166 | Now that you understand how C<require> looks for | |
13451 | Now that you understand how L<C<require>|/require VERSION> looks for | |
11167 | bareword argument, there is a little extra functionality | |
13452 | files with a bareword argument, there is a little extra functionality | |
11168 | the scenes. Before C<require> | |
13453 | going on behind the scenes. Before L<C<require>|/require VERSION> looks | |
11169 | first look for a similar filename with a | |
13454 | for a F<.pm> extension, it will first look for a similar filename with a | |
11170 | is found, it will be loaded in place of | |
13455 | F<.pmc> extension. If this file is found, it will be loaded in place of | |
11171 | extension. | |
13456 | any file ending in a F<.pm> extension. | |
11172 | 13457 | |
11173 | 13458 | =end original |
11174 | 13459 | |
11175 | 引数が裸の単語の場合、C<require> がどのようにファイル | |
13460 | 引数が裸の単語の場合、L<C<require>|/require VERSION> がどのようにファイルを | |
11176 | 理解してください; 水面下でちょっとした追加の機能があります。 | |
13461 | 探すかを理解してください; 水面下でちょっとした追加の機能があります。 | |
11177 | C<require> が拡張子 | |
13462 | L<C<require>|/require VERSION> が拡張子 F<.pm> のファイルを探す前に、まず | |
11178 | 持つファイルを探します。 | |
13463 | 拡張子 F<.pmc> を持つファイルを探します。 | |
11179 | このファイルが見つかると、このファイルが拡張子 | |
13464 | このファイルが見つかると、このファイルが拡張子 F<.pm> の代わりに | |
11180 | 13465 | 読み込まれます。 |
11181 | 13466 | |
11182 | 13467 | =begin original |
11183 | 13468 | |
11184 | 13469 | You can also insert hooks into the import facility by putting Perl code |
11185 | directly into the @INC array. There are three forms | |
13470 | directly into the L<C<@INC>|perlvar/@INC> array. There are three forms | |
11186 | references, array references, and blessed objects. | |
13471 | of hooks: subroutine references, array references, and blessed objects. | |
11187 | 13472 | |
11188 | 13473 | =end original |
11189 | 13474 | |
11190 | @INC 配列に直接 Perl コードを入れることで、インポート機能に | |
13475 | L<C<@INC>|perlvar/@INC> 配列に直接 Perl コードを入れることで、インポート機能に | |
11191 | 挿入できます。 | |
13476 | フックを挿入できます。 | |
11192 | 13477 | 3 種類のフックがあります: サブルーチンリファレンス、配列リファレンス、 |
11193 | 13478 | bless されたオブジェクトです。 |
11194 | 13479 | |
11195 | 13480 | =begin original |
11196 | 13481 | |
11197 | 13482 | Subroutine references are the simplest case. When the inclusion system |
11198 | walks through @INC and encounters a subroutine, thi | |
13483 | walks through L<C<@INC>|perlvar/@INC> and encounters a subroutine, this | |
11199 | called with two parameters, the first a reference to | |
13484 | subroutine gets called with two parameters, the first a reference to | |
11200 | second the name of the file to be included (e.g., | |
13485 | itself, and the second the name of the file to be included (e.g., | |
11201 | subroutine should return either nothing or else a | |
13486 | F<Foo/Bar.pm>). The subroutine should return either nothing or else a | |
11202 | values in the following order: | |
13487 | list of up to four values in the following order: | |
11203 | 13488 | |
11204 | 13489 | =end original |
11205 | 13490 | |
11206 | 13491 | サブルーチンへのリファレンスは一番単純な場合です。 |
11207 | インクルード機能が @INC を走査してサブルーチンに | |
13492 | インクルード機能が L<C<@INC>|perlvar/@INC> を走査してサブルーチンに | |
11208 | サブルーチンは二つの引数と共に呼び出されます; | |
13493 | 出会った場合、このサブルーチンは二つの引数と共に呼び出されます; | |
11209 | 13494 | 一つ目は自身へのリファレンス、二つ目はインクルードされるファイル名 |
11210 | ( | |
13495 | (F<Foo/Bar.pm> など)です。 | |
11211 | サブルーチンは何も返さないか、以下の順で最大 | |
13496 | サブルーチンは何も返さないか、以下の順で最大四つの値のリストを返します。 | |
11212 | 返します。 | |
11213 | 13497 | |
11214 | 13498 | =over |
11215 | 13499 | |
11216 | 13500 | =item 1 |
11217 | 13501 | |
11218 | 13502 | =begin original |
11219 | 13503 | |
11220 | A f | |
13504 | A reference to a scalar, containing any initial source code to prepend to | |
13505 | the file or generator output. | |
11221 | 13506 | |
11222 | 13507 | =end original |
11223 | 13508 | |
11224 | ファイル | |
13509 | ファイルやジェネレータの出力の前に追加される初期化ソースコードを含む | |
13510 | スカラへのリファレンス。 | |
11225 | 13511 | |
11226 | 13512 | =item 2 |
11227 | 13513 | |
11228 | 13514 | =begin original |
11229 | 13515 | |
11230 | A | |
13516 | A filehandle, from which the file will be read. | |
13517 | ||
13518 | =end original | |
13519 | ||
13520 | ファイルが読み込まれるファイルハンドル。 | |
13521 | ||
13522 | =item 3 | |
13523 | ||
13524 | =begin original | |
13525 | ||
13526 | A reference to a subroutine. If there is no filehandle (previous item), | |
11231 | 13527 | then this subroutine is expected to generate one line of source code per |
11232 | call, writing the line into C<$_> and returning 1, then | |
13528 | call, writing the line into L<C<$_>|perlvar/$_> and returning 1, then | |
11233 | file returning 0. If there is a filehandle, then th | |
13529 | finally at end of file returning 0. If there is a filehandle, then the | |
11234 | called to act as a simple source filter, with the | |
13530 | subroutine will be called to act as a simple source filter, with the | |
13531 | line as read in L<C<$_>|perlvar/$_>. | |
11235 | 13532 | Again, return 1 for each valid line, and 0 after all lines have been |
11236 | 13533 | returned. |
11237 | 13534 | |
11238 | 13535 | =end original |
11239 | 13536 | |
11240 | 13537 | サブルーチンへのリファレンス。 |
11241 | (一つ前のアイテムである)ファイルハンドルがない場合、 | |
13538 | (一つ前のアイテムである)ファイルハンドルがない場合、サブルーチンは呼び出し毎に | |
11242 | ||
13539 | 一行のソースコードを生成し、その行を L<C<$_>|perlvar/$_> に書き込んで 1 を | |
11243 | ||
13540 | 返し、それから最終的にファイル終端で 0 を返すものと想定されます。 | |
11244 | 想定されます。 | |
11245 | 13541 | ファイルハンドルがある場合、サブルーチンは単純なソースフィルタとして |
11246 | 振舞うように呼び出され、行は C<$_> から読み込まれます。 | |
13542 | 振舞うように呼び出され、行は L<C<$_>|perlvar/$_> から読み込まれます。 | |
11247 | 13543 | 再び、有効な行ごとに 1 を返し、全ての行を返した後では 0 を返します。 |
11248 | 13544 | |
11249 | =item | |
13545 | =item 4 | |
11250 | 13546 | |
11251 | 13547 | =begin original |
11252 | 13548 | |
11253 | Optional state for the subroutine. The state is passed in as C<$_[1]>. A | |
13549 | Optional state for the subroutine. The state is passed in as C<$_[1]>. A | |
11254 | 13550 | reference to the subroutine itself is passed in as C<$_[0]>. |
11255 | 13551 | |
11256 | 13552 | =end original |
11257 | 13553 | |
11258 | 13554 | サブルーチンのための状態(オプション)。 |
11259 | 13555 | 状態は C<$_[1]> として渡されます。 |
11260 | 13556 | サブルーチンへのリファレンス自身は C<$_[0]> として渡されます。 |
11261 | 13557 | |
11262 | 13558 | =back |
11263 | 13559 | |
11264 | 13560 | =begin original |
11265 | 13561 | |
11266 | If an empty list, C<undef>, or nothing that matches th | |
13562 | If an empty list, L<C<undef>|/undef EXPR>, or nothing that matches the | |
11267 | is returned, then C<require> | |
13563 | first 3 values above is returned, then L<C<require>|/require VERSION> | |
13564 | looks at the remaining elements of L<C<@INC>|perlvar/@INC>. | |
11268 | 13565 | Note that this filehandle must be a real filehandle (strictly a typeglob |
11269 | or reference to a typeglob, whether blessed or unblessed); tied filehandles | |
13566 | or reference to a typeglob, whether blessed or unblessed); tied filehandles | |
11270 | 13567 | will be ignored and processing will stop there. |
11271 | 13568 | |
11272 | 13569 | =end original |
11273 | 13570 | |
11274 | 空リスト、C<undef>、または上記の最初の三つの値のどれとも | |
13571 | 空リスト、L<C<undef>|/undef EXPR>、または上記の最初の三つの値のどれとも | |
11275 | 返されると、C<require> | |
13572 | 一致しないものが返されると、L<C<require>|/require VERSION> は | |
13573 | L<C<@INC>|perlvar/@INC> の残りの要素を見ます。 | |
11276 | 13574 | このファイルハンドルは実際のファイルハンドル(厳密には型グロブ、型グロブへの |
11277 | 13575 | リファレンス、bless されているかに関わらず)でなければなりません; |
11278 | 13576 | tie されたファイルハンドルは無視され、返り値の処理はそこで停止します。 |
11279 | 13577 | |
11280 | 13578 | =begin original |
11281 | 13579 | |
11282 | 13580 | If the hook is an array reference, its first element must be a subroutine |
11283 | 13581 | reference. This subroutine is called as above, but the first parameter is |
11284 | 13582 | the array reference. This lets you indirectly pass arguments to |
11285 | 13583 | the subroutine. |
11286 | 13584 | |
11287 | 13585 | =end original |
11288 | 13586 | |
11289 | 13587 | フックが配列のリファレンスの場合、その最初の要素はサブルーチンへの |
11290 | 13588 | リファレンスでなければなりません。 |
11291 | 13589 | このサブルーチンは上述のように呼び出されますが、その最初の引数は |
11292 | 13590 | 配列のリファレンスです。 |
11293 | 13591 | これによって、間接的にサブルーチンに引数を渡すことが出来ます。 |
11294 | 13592 | |
11295 | 13593 | =begin original |
11296 | 13594 | |
11297 | 13595 | In other words, you can write: |
11298 | 13596 | |
11299 | 13597 | =end original |
11300 | 13598 | |
11301 | 13599 | 言い換えると、以下のように書いたり: |
11302 | 13600 | |
11303 | 13601 | push @INC, \&my_sub; |
11304 | 13602 | sub my_sub { |
11305 | 13603 | my ($coderef, $filename) = @_; # $coderef is \&my_sub |
11306 | 13604 | ... |
11307 | 13605 | } |
11308 | 13606 | |
11309 | 13607 | =begin original |
11310 | 13608 | |
11311 | 13609 | or: |
11312 | 13610 | |
11313 | 13611 | =end original |
11314 | 13612 | |
11315 | 13613 | または以下のように書けます: |
11316 | 13614 | |
11317 | 13615 | push @INC, [ \&my_sub, $x, $y, ... ]; |
11318 | 13616 | sub my_sub { |
11319 | 13617 | my ($arrayref, $filename) = @_; |
11320 | 13618 | # Retrieve $x, $y, ... |
11321 | my @parameters = @$arrayref | |
13619 | my (undef, @parameters) = @$arrayref; | |
11322 | 13620 | ... |
11323 | 13621 | } |
11324 | 13622 | |
11325 | 13623 | =begin original |
11326 | 13624 | |
11327 | If the hook is an object, it must provide an INC method that will be | |
13625 | If the hook is an object, it must provide an C<INC> method that will be | |
11328 | 13626 | called as above, the first parameter being the object itself. (Note that |
11329 | 13627 | you must fully qualify the sub's name, as unqualified C<INC> is always forced |
11330 | 13628 | into package C<main>.) Here is a typical code layout: |
11331 | 13629 | |
11332 | 13630 | =end original |
11333 | 13631 | |
11334 | フックがオブジェクトの場合、INC メソッドを提供している必要があります; | |
13632 | フックがオブジェクトの場合、C<INC> メソッドを提供している必要があります; | |
11335 | 13633 | それが、最初の引数をオブジェクト自身として上述のように呼び出されます。 |
11336 | 13634 | (修飾されていない C<INC> は常にパッケージ C<main> に強制されるため、 |
11337 | 13635 | サブルーチン名は完全修飾する必要があることに注意してください。) |
11338 | 13636 | 以下は典型的なコードレイアウトです: |
11339 | 13637 | |
11340 | 13638 | # In Foo.pm |
11341 | 13639 | package Foo; |
11342 | 13640 | sub new { ... } |
11343 | 13641 | sub Foo::INC { |
11344 | 13642 | my ($self, $filename) = @_; |
11345 | 13643 | ... |
11346 | 13644 | } |
11347 | 13645 | |
11348 | 13646 | # In the main program |
11349 | 13647 | push @INC, Foo->new(...); |
11350 | 13648 | |
11351 | 13649 | =begin original |
11352 | 13650 | |
11353 | These hooks are also permitted to set the %INC entry | |
13651 | These hooks are also permitted to set the L<C<%INC>|perlvar/%INC> entry | |
11354 | corresponding to the files they have loaded. See L<perlvar/%INC>. | |
13652 | corresponding to the files they have loaded. See L<perlvar/%INC>. | |
11355 | 13653 | |
11356 | 13654 | =end original |
11357 | 13655 | |
11358 | これらのフックは、読み込まれるファイルに対応する | |
13656 | これらのフックは、読み込まれるファイルに対応する | |
11359 | セットすることも許可します。 | |
13657 | L<C<%INC>|perlvar/%INC> エントリをセットすることも許可します。 | |
11360 | 13658 | L<perlvar/%INC> を参照してください。 |
11361 | 13659 | |
11362 | 13660 | =begin original |
11363 | 13661 | |
11364 | For a yet-more-powerful import facility, see | |
13662 | For a yet-more-powerful import facility, see | |
13663 | L<C<use>|/use Module VERSION LIST> and L<perlmod>. | |
11365 | 13664 | |
11366 | 13665 | =end original |
11367 | 13666 | |
11368 | 13667 | より強力な import 機能については、このドキュメントの |
11369 | L</use> の項と、L<perlmod> を参照してください。 | |
13668 | L<C<use>|/use Module VERSION LIST> の項と、L<perlmod> を参照してください。 | |
11370 | 13669 | |
11371 | 13670 | =item reset EXPR |
11372 | 13671 | X<reset> |
11373 | 13672 | |
11374 | 13673 | =item reset |
11375 | 13674 | |
13675 | =for Pod::Functions clear all variables of a given name | |
13676 | ||
11376 | 13677 | =begin original |
11377 | 13678 | |
11378 | Generally used in a C<continue> block at the end of a | |
13679 | Generally used in a L<C<continue>|/continue BLOCK> block at the end of a | |
11379 | variables and reset C<??> searches so that they | |
13680 | loop to clear variables and reset C<m?pattern?> searches so that they | |
13681 | work again. The | |
11380 | 13682 | expression is interpreted as a list of single characters (hyphens |
11381 | 13683 | allowed for ranges). All variables and arrays beginning with one of |
11382 | 13684 | those letters are reset to their pristine state. If the expression is |
11383 | omitted, one-match searches (C<?pattern?>) are reset to match again. | |
13685 | omitted, one-match searches (C<m?pattern?>) are reset to match again. | |
11384 | 13686 | Only resets variables or searches in the current package. Always returns |
11385 | 13687 | 1. Examples: |
11386 | 13688 | |
11387 | 13689 | =end original |
11388 | 13690 | |
11389 | 通常、ループの最後に、変数をクリアし、C<??> 検索を再び | |
13691 | 通常、ループの最後に、変数をクリアし、C<m?pattern?> 検索を再び動作するように | |
11390 | ||
13692 | リセットするため、L<C<continue>|/continue BLOCK> ブロックで使われます。 | |
11391 | 13693 | EXPR は、文字を並べたもの (範囲を指定するのに、ハイフンが使えます) と |
11392 | 13694 | 解釈されます。 |
11393 | 13695 | 名前がその文字のいずれかで始まる変数や配列は、 |
11394 | 13696 | 最初の状態にリセットされます。 |
11395 | EXPR を省略すると、1 回検索 (C<? | |
13697 | EXPR を省略すると、1 回検索 (C<m?pattern?>) を再びマッチするように | |
11396 | 13698 | リセットできます。 |
11397 | 13699 | カレントパッケージの変数もしくは検索だけがリセットされます。 |
11398 | 13700 | 常に 1 を返します。 |
11399 | 13701 | 例: |
11400 | 13702 | |
11401 | 13703 | reset 'X'; # reset all X variables |
11402 | 13704 | reset 'a-z'; # reset lower case variables |
11403 | reset; # just reset ?one-time? searches | |
13705 | reset; # just reset m?one-time? searches | |
11404 | 13706 | |
11405 | 13707 | =begin original |
11406 | 13708 | |
11407 | 13709 | Resetting C<"A-Z"> is not recommended because you'll wipe out your |
11408 | C<@ARGV> and C<@INC> arrays and your | |
13710 | L<C<@ARGV>|perlvar/@ARGV> and L<C<@INC>|perlvar/@INC> arrays and your | |
11409 | ||
13711 | L<C<%ENV>|perlvar/%ENV> hash. | |
11410 | ||
13712 | Resets only package variables; lexical variables are unaffected, but | |
11411 | ||
13713 | they clean themselves up on scope exit anyway, so you'll probably want | |
13714 | to use them instead. See L<C<my>|/my VARLIST>. | |
11412 | 13715 | |
11413 | 13716 | =end original |
11414 | 13717 | |
11415 | reset C<"A-Z"> とすると、C<@ARGV> | |
13718 | reset C<"A-Z"> とすると、L<C<@ARGV>|perlvar/@ARGV>, | |
11416 | ||
13719 | L<C<@INC>|perlvar/@INC> 配列や L<C<%ENV>|perlvar/%ENV> ハッシュも | |
11417 | ||
13720 | なくなってしまうので、止めた方が良いでしょう。 | |
11418 | レキシカル変数は | |
13721 | パッケージ変数だけがリセットされます; レキシカル変数は影響を受けませんが、 | |
11419 | 自動的に綺麗にな | |
13722 | スコープから外れれば自動的に綺麗になるので、これからはこちらを | |
11420 | よいでしょう。 | |
13723 | 使うようにした方がよいでしょう。 | |
11421 | L</my> を参照してください。 | |
13724 | L<C<my>|/my VARLIST> を参照してください。 | |
11422 | 13725 | |
11423 | 13726 | =item return EXPR |
11424 | 13727 | X<return> |
11425 | 13728 | |
11426 | 13729 | =item return |
11427 | 13730 | |
13731 | =for Pod::Functions get out of a function early | |
13732 | ||
11428 | 13733 | =begin original |
11429 | 13734 | |
11430 | Returns from a subroutine, C<eval> | |
13735 | Returns from a subroutine, L<C<eval>|/eval EXPR>, | |
13736 | L<C<do FILE>|/do EXPR>, L<C<sort>|/sort SUBNAME LIST> block or regex | |
13737 | eval block (but not a L<C<grep>|/grep BLOCK LIST> or | |
13738 | L<C<map>|/map BLOCK LIST> block) with the value | |
11431 | 13739 | given in EXPR. Evaluation of EXPR may be in list, scalar, or void |
11432 | 13740 | context, depending on how the return value will be used, and the context |
11433 | may vary from one execution to the next (see | |
13741 | may vary from one execution to the next (see | |
13742 | L<C<wantarray>|/wantarray>). If no EXPR | |
11434 | 13743 | is given, returns an empty list in list context, the undefined value in |
11435 | 13744 | scalar context, and (of course) nothing at all in void context. |
11436 | 13745 | |
11437 | 13746 | =end original |
11438 | 13747 | |
11439 | サブルーチン, C<eval>, C<do FILE> | |
13748 | サブルーチン, L<C<eval>|/eval EXPR>, L<C<do FILE>|/do EXPR>, | |
11440 | ||
13749 | L<C<sort>|/sort SUBNAME LIST> ブロックまたは正規表現 eval ブロック | |
11441 | ||
13750 | (但し L<C<grep>|/grep BLOCK LIST> や | |
11442 | ||
13751 | L<C<map>|/map BLOCK LIST> ブロックではない) から | |
11443 | ||
13752 | EXPR で与えられた値をもって、リターンします。 | |
13753 | EXPR の評価は、返り値がどのように使われるかによってリスト、スカラ、 | |
13754 | 無効コンテキストになります; またコンテキストは実行毎に変わります | |
13755 | (L<C<wantarray>|/wantarray> を参照してください)。 | |
11444 | 13756 | EXPR が指定されなかった場合は、リストコンテキストでは空リストを、 |
11445 | スカラコンテキストでは未定義値を返します | |
13757 | スカラコンテキストでは未定義値を返します; そして(もちろん) | |
11446 | ||
13758 | 無効コンテキストでは何も返しません。 | |
11447 | 13759 | |
11448 | 13760 | =begin original |
11449 | 13761 | |
11450 | (In the absence of an explicit C<return>, a subroutine | |
13762 | (In the absence of an explicit L<C<return>|/return EXPR>, a subroutine, | |
11451 | ||
13763 | L<C<eval>|/eval EXPR>, | |
13764 | or L<C<do FILE>|/do EXPR> automatically returns the value of the last expression | |
11452 | 13765 | evaluated.) |
11453 | 13766 | |
11454 | 13767 | =end original |
11455 | 13768 | |
11456 | (サブルーチン, eval, do FILE に明示的に | |
13769 | (サブルーチン, L<C<eval>|/eval EXPR>, L<C<do FILE>|/do EXPR> に明示的に | |
11457 | なければ、最後に評価された値で、 | |
13770 | L<C<return>|/return EXPR> がなければ、最後に評価された値で、 | |
13771 | 自動的にリターンします。) | |
11458 | 13772 | |
13773 | =begin original | |
13774 | ||
13775 | Unlike most named operators, this is also exempt from the | |
13776 | looks-like-a-function rule, so C<return ("foo")."bar"> will | |
13777 | cause C<"bar"> to be part of the argument to L<C<return>|/return EXPR>. | |
13778 | ||
13779 | =end original | |
13780 | ||
13781 | ほとんどの名前付き演算子と異なり、関数のように見えるものの規則からも | |
13782 | 免れるので、C<return ("foo")."bar"> とすると C<"bar"> は | |
13783 | L<C<return>|/return EXPR> への引数の一部となります。 | |
13784 | ||
11459 | 13785 | =item reverse LIST |
11460 | 13786 | X<reverse> X<rev> X<invert> |
11461 | 13787 | |
13788 | =for Pod::Functions flip a string or a list | |
13789 | ||
11462 | 13790 | =begin original |
11463 | 13791 | |
11464 | 13792 | In list context, returns a list value consisting of the elements |
11465 | 13793 | of LIST in the opposite order. In scalar context, concatenates the |
11466 | 13794 | elements of LIST and returns a string value with all characters |
11467 | 13795 | in the opposite order. |
11468 | 13796 | |
11469 | 13797 | =end original |
11470 | 13798 | |
11471 | 13799 | リストコンテキストでは、LIST を構成する要素を逆順に並べた |
11472 | 13800 | リスト値を返します。 |
11473 | 13801 | スカラコンテキストでは、LIST の要素を連結して、 |
11474 | 13802 | 全ての文字を逆順にした文字列を返します。 |
11475 | 13803 | |
11476 | 13804 | print join(", ", reverse "world", "Hello"); # Hello, world |
11477 | 13805 | |
11478 | 13806 | print scalar reverse "dlrow ,", "olleH"; # Hello, world |
11479 | 13807 | |
11480 | 13808 | =begin original |
11481 | 13809 | |
11482 | Used without arguments in scalar context, reverse | |
13810 | Used without arguments in scalar context, L<C<reverse>|/reverse LIST> | |
13811 | reverses L<C<$_>|perlvar/$_>. | |
11483 | 13812 | |
11484 | 13813 | =end original |
11485 | 13814 | |
11486 | スカラコンテキストで引数なしで使うと、reverse | |
13815 | スカラコンテキストで引数なしで使うと、L<C<reverse>|/reverse LIST> は | |
13816 | L<C<$_>|perlvar/$_> を逆順にします。 | |
11487 | 13817 | |
11488 | 13818 | $_ = "dlrow ,olleH"; |
11489 | print reverse; | |
13819 | print reverse; # No output, list context | |
11490 | print scalar reverse; | |
13820 | print scalar reverse; # Hello, world | |
11491 | 13821 | |
11492 | 13822 | =begin original |
11493 | 13823 | |
11494 | 13824 | Note that reversing an array to itself (as in C<@a = reverse @a>) will |
11495 | preserve non-existent elements whenever possible | |
13825 | preserve non-existent elements whenever possible; i.e., for non-magical | |
11496 | arrays or tied arrays with C<EXISTS> and C<DELETE> methods. | |
13826 | arrays or for tied arrays with C<EXISTS> and C<DELETE> methods. | |
11497 | 13827 | |
11498 | 13828 | =end original |
11499 | 13829 | |
11500 | 13830 | (C<@a = reverse @a> のように) 反転した配列を自分自身に代入すると、 |
11501 | 13831 | 存在しない要素は可能なら(つまりマジカルでない配列や |
11502 | 13832 | C<EXISTS> と C<DELETE> メソッドがある tie された配列) |
11503 | 13833 | いつでも保存されることに注意してください。 |
11504 | 13834 | |
11505 | 13835 | =begin original |
11506 | 13836 | |
11507 | 13837 | This operator is also handy for inverting a hash, although there are some |
11508 | 13838 | caveats. If a value is duplicated in the original hash, only one of those |
11509 | 13839 | can be represented as a key in the inverted hash. Also, this has to |
11510 | 13840 | unwind one hash and build a whole new one, which may take some time |
11511 | 13841 | on a large hash, such as from a DBM file. |
11512 | 13842 | |
11513 | 13843 | =end original |
11514 | 13844 | |
11515 | 13845 | この演算子はハッシュの逆順にするのにも便利ですが、いくつかの弱点があります。 |
11516 | 13846 | 元のハッシュで値が重複していると、それらのうち一つだけが |
11517 | 13847 | 逆順になったハッシュのキーとして表現されます。 |
11518 | 13848 | また、これは一つのハッシュをほどいて完全に新しいハッシュを作るので、 |
11519 | 13849 | DBM ファイルからのような大きなハッシュでは少し時間がかかります。 |
11520 | 13850 | |
11521 | %by_name = reverse %by_address; # Invert the hash | |
13851 | my %by_name = reverse %by_address; # Invert the hash | |
11522 | 13852 | |
11523 | 13853 | =item rewinddir DIRHANDLE |
11524 | 13854 | X<rewinddir> |
11525 | 13855 | |
13856 | =for Pod::Functions reset directory handle | |
13857 | ||
11526 | 13858 | =begin original |
11527 | 13859 | |
11528 | 13860 | Sets the current position to the beginning of the directory for the |
11529 | C<readdir> routine on DIRHANDLE. | |
13861 | L<C<readdir>|/readdir DIRHANDLE> routine on DIRHANDLE. | |
11530 | 13862 | |
11531 | 13863 | =end original |
11532 | 13864 | |
11533 | DIRHANDLE に対する C<readdir> ルーチンの現在位置を | |
13865 | DIRHANDLE に対する L<C<readdir>|/readdir DIRHANDLE> ルーチンの現在位置を | |
11534 | 13866 | ディレクトリの最初に設定します。 |
11535 | 13867 | |
13868 | =begin original | |
13869 | ||
13870 | Portability issues: L<perlport/rewinddir>. | |
13871 | ||
13872 | =end original | |
13873 | ||
13874 | 移植性の問題: L<perlport/rewinddir>。 | |
13875 | ||
11536 | 13876 | =item rindex STR,SUBSTR,POSITION |
11537 | 13877 | X<rindex> |
11538 | 13878 | |
11539 | 13879 | =item rindex STR,SUBSTR |
11540 | 13880 | |
13881 | =for Pod::Functions right-to-left substring search | |
13882 | ||
11541 | 13883 | =begin original |
11542 | 13884 | |
11543 | Works just like index | |
13885 | Works just like L<C<index>|/index STR,SUBSTR,POSITION> except that it | |
13886 | returns the position of the I<last> | |
11544 | 13887 | occurrence of SUBSTR in STR. If POSITION is specified, returns the |
11545 | 13888 | last occurrence beginning at or before that position. |
11546 | 13889 | |
11547 | 13890 | =end original |
11548 | 13891 | |
11549 | 13892 | STR 中で I<最後に> 見つかった SUBSTR の位置を返すことを除いて、 |
11550 | index | |
13893 | L<C<index>|/index STR,SUBSTR,POSITION> と同じように動作します。 | |
11551 | 13894 | POSITION を指定すると、その位置から始まるか、その位置より前の、 |
11552 | 13895 | 最後の位置を返します。 |
11553 | 13896 | |
11554 | 13897 | =item rmdir FILENAME |
11555 | 13898 | X<rmdir> X<rd> X<directory, remove> |
11556 | 13899 | |
11557 | 13900 | =item rmdir |
11558 | 13901 | |
13902 | =for Pod::Functions remove a directory | |
13903 | ||
11559 | 13904 | =begin original |
11560 | 13905 | |
11561 | 13906 | Deletes the directory specified by FILENAME if that directory is |
11562 | 13907 | empty. If it succeeds it returns true; otherwise it returns false and |
11563 | sets C<$!> (errno). If FILENAME is omitted, uses | |
13908 | sets L<C<$!>|perlvar/$!> (errno). If FILENAME is omitted, uses | |
13909 | L<C<$_>|perlvar/$_>. | |
11564 | 13910 | |
11565 | 13911 | =end original |
11566 | 13912 | |
11567 | 13913 | FILENAME で指定したディレクトリが空であれば、 |
11568 | 13914 | そのディレクトリを削除します。 |
11569 | 成功時には真を返します; さもなければ偽を返し | |
13915 | 成功時には真を返します; さもなければ偽を返して L<C<$!>|perlvar/$!> (errno) を | |
11570 | ||
13916 | 設定します。 | |
13917 | FILENAME を省略した場合には、L<C<$_>|perlvar/$_> を使用します。 | |
11571 | 13918 | |
11572 | 13919 | =begin original |
11573 | 13920 | |
11574 | 13921 | To remove a directory tree recursively (C<rm -rf> on Unix) look at |
11575 | the C<rmtree> function of the L<File::Path> | |
13922 | the L<C<rmtree>|File::Path/rmtree( $dir )> function of the L<File::Path> | |
13923 | module. | |
11576 | 13924 | |
11577 | 13925 | =end original |
11578 | 13926 | |
11579 | 13927 | ディレクトリツリーを再帰的に削除したい (Unix での C<rm -rf>) 場合、 |
11580 | L<File::Path> モジュールの C<rmtree> 関数を | |
13928 | L<File::Path> モジュールの L<C<rmtree>|File::Path/rmtree( $dir )> 関数を | |
13929 | 参照してください。 | |
11581 | 13930 | |
11582 | 13931 | =item s/// |
11583 | 13932 | |
13933 | =for Pod::Functions replace a pattern with a string | |
13934 | ||
11584 | 13935 | =begin original |
11585 | 13936 | |
11586 | 13937 | The substitution operator. See L<perlop/"Regexp Quote-Like Operators">. |
11587 | 13938 | |
11588 | 13939 | =end original |
11589 | 13940 | |
11590 | 13941 | 置換演算子。 |
11591 | 13942 | L<perlop/"Regexp Quote-Like Operators"> を参照してください。 |
11592 | 13943 | |
11593 | 13944 | =item say FILEHANDLE LIST |
11594 | 13945 | X<say> |
11595 | 13946 | |
11596 | 13947 | =item say FILEHANDLE |
11597 | 13948 | |
11598 | 13949 | =item say LIST |
11599 | 13950 | |
11600 | 13951 | =item say |
11601 | 13952 | |
13953 | =for Pod::Functions +say output a list to a filehandle, appending a newline | |
13954 | ||
11602 | 13955 | =begin original |
11603 | 13956 | |
11604 | Just like C<print>, but implicitly appends a | |
13957 | Just like L<C<print>|/print FILEHANDLE LIST>, but implicitly appends a | |
11605 | simply an abbreviation for | |
13958 | newline. C<say LIST> is simply an abbreviation for | |
11606 | FILEHANDLE without a LIST to | |
13959 | C<{ local $\ = "\n"; print LIST }>. To use FILEHANDLE without a LIST to | |
11607 | ||
13960 | print the contents of L<C<$_>|perlvar/$_> to it, you must use a bareword | |
13961 | filehandle like C<FH>, not an indirect one like C<$fh>. | |
11608 | 13962 | |
11609 | 13963 | =end original |
11610 | 13964 | |
11611 | C<print> と同様ですが、暗黙に改行が追加されます。 | |
13965 | L<C<print>|/print FILEHANDLE LIST> と同様ですが、暗黙に改行が追加されます。 | |
11612 | 13966 | C<say LIST> は単に C<{ local $\ = "\n"; print LIST }> の省略形です。 |
11613 | C<$_> の内容を表示するために LIST なしで FILEHANDLE を | |
13967 | L<C<$_>|perlvar/$_> の内容を表示するために LIST なしで FILEHANDLE を | |
11614 | C<$fh> のような間接ファイルハンドルではなく、C<FH> のような | |
13968 | 使用するには、C<$fh> のような間接ファイルハンドルではなく、C<FH> のような | |
11615 | ファイルハンドルを使わなければなりません。 | |
13969 | 裸の単語のファイルハンドルを使わなければなりません。 | |
11616 | 13970 | |
11617 | 13971 | =begin original |
11618 | 13972 | |
11619 | ||
13973 | L<C<say>|/say FILEHANDLE LIST> is available only if the | |
11620 | L<feature | |
13974 | L<C<"say"> feature|feature/The 'say' feature> is enabled or if it is | |
11621 | ||
13975 | prefixed with C<CORE::>. The | |
13976 | L<C<"say"> feature|feature/The 'say' feature> is enabled automatically | |
13977 | with a C<use v5.10> (or higher) declaration in the current scope. | |
11622 | 13978 | |
11623 | 13979 | =end original |
11624 | 13980 | |
11625 | ||
13981 | L<C<say>|/say FILEHANDLE LIST> は | |
11626 | L<feature> | |
13982 | L<C<"say"> 機能|feature/The 'say' feature> が有効か C<CORE::> が | |
11627 | ||
13983 | 前置されたときにのみ利用可能です。 | |
13984 | L<C<"say"> 機能|feature/The 'say' feature> は現在のスコープで | |
13985 | C<use v5.10> (またはそれ以上) が宣言されると自動的に有効になります。 | |
11628 | 13986 | |
11629 | 13987 | =item scalar EXPR |
11630 | 13988 | X<scalar> X<context> |
11631 | 13989 | |
13990 | =for Pod::Functions force a scalar context | |
13991 | ||
11632 | 13992 | =begin original |
11633 | 13993 | |
11634 | 13994 | Forces EXPR to be interpreted in scalar context and returns the value |
11635 | 13995 | of EXPR. |
11636 | 13996 | |
11637 | 13997 | =end original |
11638 | 13998 | |
11639 | 13999 | EXPR を強制的にスカラコンテキストで解釈されるようにして、 |
11640 | 14000 | EXPR の値を返します。 |
11641 | 14001 | |
11642 | @counts = ( scalar @a, scalar @b, scalar @c ); | |
14002 | my @counts = ( scalar @a, scalar @b, scalar @c ); | |
11643 | 14003 | |
11644 | 14004 | =begin original |
11645 | 14005 | |
11646 | 14006 | There is no equivalent operator to force an expression to |
11647 | 14007 | be interpolated in list context because in practice, this is never |
11648 | 14008 | needed. If you really wanted to do so, however, you could use |
11649 | 14009 | the construction C<@{[ (some expression) ]}>, but usually a simple |
11650 | 14010 | C<(some expression)> suffices. |
11651 | 14011 | |
11652 | 14012 | =end original |
11653 | 14013 | |
11654 | 式を強制的にリストコンテキストで解釈させるようにする演算子はありません | |
14014 | 式を強制的にリストコンテキストで解釈させるようにする演算子はありません; | |
11655 | 14015 | 理論的には不要だからです。 |
11656 | 14016 | それでも、もしそうしたいのなら、C<@{[ (some expression) ]}> という構造を |
11657 | 使えます。 | |
14017 | 使えます; しかし、普通は単に C<(some expression)> とすれば十分です。 | |
11658 | しかし、普通は単に C<(some expression)> とすれば十分です。 | |
11659 | 14018 | |
11660 | 14019 | =begin original |
11661 | 14020 | |
11662 | Because C<scalar> is a unary operator, if you | |
14021 | Because L<C<scalar>|/scalar EXPR> is a unary operator, if you | |
14022 | accidentally use a | |
11663 | 14023 | parenthesized list for the EXPR, this behaves as a scalar comma expression, |
11664 | 14024 | evaluating all but the last element in void context and returning the final |
11665 | 14025 | element evaluated in scalar context. This is seldom what you want. |
11666 | 14026 | |
11667 | 14027 | =end original |
11668 | 14028 | |
11669 | C<scalar> は単項演算子なので、EXPR として括弧でくくった | |
14029 | L<C<scalar>|/scalar EXPR> は単項演算子なので、EXPR として括弧でくくった | |
11670 | これはスカラカンマ表現として振舞い、最後以外の全ては | |
14030 | リストを使った場合、これはスカラカンマ表現として振舞い、最後以外の全ては | |
11671 | 扱われ、最後の要素をスカラコンテキストとして扱った | |
14031 | 無効コンテキストとして扱われ、最後の要素をスカラコンテキストとして扱った | |
14032 | 結果が返されます。 | |
11672 | 14033 | これがあなたの望むものであることはめったにないでしょう。 |
11673 | 14034 | |
11674 | 14035 | =begin original |
11675 | 14036 | |
11676 | 14037 | The following single statement: |
11677 | 14038 | |
11678 | 14039 | =end original |
11679 | 14040 | |
11680 | 14041 | 以下の一つの文は: |
11681 | 14042 | |
11682 | print uc(scalar( | |
14043 | print uc(scalar(foo(), $bar)), $baz; | |
11683 | 14044 | |
11684 | 14045 | =begin original |
11685 | 14046 | |
11686 | 14047 | is the moral equivalent of these two: |
11687 | 14048 | |
11688 | 14049 | =end original |
11689 | 14050 | |
11690 | 14051 | 以下の二つの文と等価です。 |
11691 | 14052 | |
11692 | | |
14053 | foo(); | |
11693 | print(uc($bar),$baz); | |
14054 | print(uc($bar), $baz); | |
11694 | 14055 | |
11695 | 14056 | =begin original |
11696 | 14057 | |
11697 | See L<perlop> for more details on unary operators and the comma operator | |
14058 | See L<perlop> for more details on unary operators and the comma operator, | |
14059 | and L<perldata> for details on evaluating a hash in scalar contex. | |
11698 | 14060 | |
11699 | 14061 | =end original |
11700 | 14062 | |
11701 | 単項演算子とカンマ演算子に関する詳細については L<perlop> を | |
14063 | 単項演算子とカンマ演算子に関する詳細については L<perlop> を、 | |
14064 | スカラコンテキストでのハッシュの評価に関する詳細については L<perldata> を | |
14065 | 参照してください。 | |
11702 | 14066 | |
11703 | 14067 | =item seek FILEHANDLE,POSITION,WHENCE |
11704 | 14068 | X<seek> X<fseek> X<filehandle, position> |
11705 | 14069 | |
14070 | =for Pod::Functions reposition file pointer for random-access I/O | |
14071 | ||
11706 | 14072 | =begin original |
11707 | 14073 | |
11708 | Sets FILEHANDLE's position, just like the | |
14074 | Sets FILEHANDLE's position, just like the L<fseek(3)> call of C C<stdio>. | |
11709 | 14075 | FILEHANDLE may be an expression whose value gives the name of the |
11710 | 14076 | filehandle. The values for WHENCE are C<0> to set the new position |
11711 | 14077 | I<in bytes> to POSITION; C<1> to set it to the current position plus |
11712 | 14078 | POSITION; and C<2> to set it to EOF plus POSITION, typically |
11713 | 14079 | negative. For WHENCE you may use the constants C<SEEK_SET>, |
11714 | 14080 | C<SEEK_CUR>, and C<SEEK_END> (start of the file, current position, end |
11715 | 14081 | of the file) from the L<Fcntl> module. Returns C<1> on success, false |
11716 | 14082 | otherwise. |
11717 | 14083 | |
11718 | 14084 | =end original |
11719 | 14085 | |
11720 | C<stdio> ライブラリの | |
14086 | C の C<stdio> ライブラリの L<fseek(3)> 関数のように、FILEHANDLE の | |
11721 | 14087 | ファイルポインタを任意の位置に設定します。 |
11722 | 14088 | FILEHANDLE は、実際のファイルハンドル名を与える式でもかまいません。 |
11723 | 14089 | WHENCE の値が、C<0> ならば、新しい位置を I<バイト単位で> POSITION の位置へ |
11724 | 設定します; C<1> ならば、現在位置から | |
14090 | 設定します; C<1> ならば、現在位置から POSITION 加えた位置へ | |
11725 | 14091 | 設定します; C<2> ならば、EOF からPOSITION だけ加えた位置へ、新しい位置を |
11726 | 14092 | 設定します。 |
11727 | 14093 | この値には、L<Fcntl> モジュールで使われている C<SEEK_SET>、C<SEEK_CUR>、 |
11728 | 14094 | C<SEEK_END> (ファイルの先頭、現在位置、ファイルの最後)という定数を |
11729 | 14095 | 使うこともできます。 |
11730 | 成功時には、C<1> を、失敗時には | |
14096 | 成功時には、C<1> を、失敗時にはそれ以外を返します。 | |
11731 | 14097 | |
11732 | 14098 | =begin original |
11733 | 14099 | |
11734 | 14100 | Note the I<in bytes>: even if the filehandle has been set to |
11735 | 14101 | operate on characters (for example by using the C<:encoding(utf8)> open |
11736 | layer), tell | |
14102 | layer), L<C<tell>|/tell FILEHANDLE> will return byte offsets, not | |
11737 | (because implementing that would render | |
14103 | character offsets (because implementing that would render | |
14104 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> and | |
14105 | L<C<tell>|/tell FILEHANDLE> rather slow). | |
11738 | 14106 | |
11739 | 14107 | =end original |
11740 | 14108 | |
11741 | 14109 | I<バイト単位> に関する注意: ファイルハンドルが (例えば C<:encoding(utf8)> 層を |
11742 | 使って)文字を操作するように設定されていたとしても、 | |
14110 | 使って)文字を操作するように設定されていたとしても、 | |
11743 | オフセットではなくバイトのオフセットを | |
14111 | L<C<tell>|/tell FILEHANDLE> は文字のオフセットではなくバイトのオフセットを | |
11744 | ||
14112 | 返すことに注意してください | |
14113 | (なぜならこれを実装すると L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> と | |
14114 | L<C<tell>|/tell FILEHANDLE> が遅くなってしまうからです)。 | |
11745 | 14115 | |
11746 | 14116 | =begin original |
11747 | 14117 | |
11748 | If you want to position the file for | |
14118 | If you want to position the file for | |
11749 | C<s | |
14119 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> or | |
11750 | ||
14120 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, don't use | |
14121 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, because buffering makes its | |
14122 | effect on the file's read-write position unpredictable and non-portable. | |
14123 | Use L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> instead. | |
11751 | 14124 | |
11752 | 14125 | =end original |
11753 | 14126 | |
11754 | C<sysread> | |
14127 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> や | |
11755 | C<see | |
14128 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> のためにファイルの | |
14129 | 位置を指定したい場合は、L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> は | |
14130 | 使えません; なぜならバッファリングのためにファイルの読み込み位置は | |
11756 | 14131 | 動作は予測不能で移植性のないものになってしまいます。 |
11757 | 代わりに C<sysseek> を使ってください。 | |
14132 | 代わりに L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> を使ってください。 | |
11758 | 14133 | |
11759 | 14134 | =begin original |
11760 | 14135 | |
11761 | 14136 | Due to the rules and rigors of ANSI C, on some systems you have to do a |
11762 | 14137 | seek whenever you switch between reading and writing. Amongst other |
11763 | things, this may have the effect of calling stdio's clearerr(3). | |
14138 | things, this may have the effect of calling stdio's L<clearerr(3)>. | |
11764 | 14139 | A WHENCE of C<1> (C<SEEK_CUR>) is useful for not moving the file position: |
11765 | 14140 | |
11766 | 14141 | =end original |
11767 | 14142 | |
11768 | 14143 | ANSI C の規則と困難により、システムによっては読み込みと書き込みを |
11769 | 14144 | 切り替える度にシークしなければならない場合があります。 |
11770 | その他のことの中で、これは stdio の clearerr(3) を呼び出す効果があります。 | |
14145 | その他のことの中で、これは stdio の L<clearerr(3)> を呼び出す効果があります。 | |
11771 | 14146 | WHENCE の C<1> (C<SEEK_CUR>) が、ファイル位置を変えないので有用です: |
11772 | 14147 | |
11773 | seek( | |
14148 | seek($fh, 0, 1); | |
11774 | 14149 | |
11775 | 14150 | =begin original |
11776 | 14151 | |
11777 | 14152 | This is also useful for applications emulating C<tail -f>. Once you hit |
11778 | 14153 | EOF on your read and then sleep for a while, you (probably) have to stick in a |
11779 | dummy seek | |
14154 | dummy L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> to reset things. The | |
14155 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> doesn't change the position, | |
11780 | 14156 | but it I<does> clear the end-of-file condition on the handle, so that the |
11781 | next C< | |
14157 | next C<readline FILE> makes Perl try again to read something. (We hope.) | |
11782 | 14158 | |
11783 | 14159 | =end original |
11784 | 14160 | |
11785 | 14161 | これはアプリケーションで C<tail -f> をエミュレートするのにも有用です。 |
11786 | 14162 | 一度読み込み時に EOF に到達すると、しばらくスリープし、 |
11787 | (おそらく) ダミーの seek | |
14163 | (おそらく) ダミーの L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> をすることで | |
11788 | ||
14164 | リセットする必要があります。 | |
11789 | ||
14165 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> は現在の位置を変更しませんが、 | |
11790 | ||
14166 | ハンドルの EOF 状態をI<クリアします> ので、次の C<readline FILE> で Perl は | |
14167 | 再び何かを読み込もうとします。(そのはずです。) | |
11791 | 14168 | |
11792 | 14169 | =begin original |
11793 | 14170 | |
11794 | 14171 | If that doesn't work (some I/O implementations are particularly |
11795 | 14172 | cantankerous), you might need something like this: |
11796 | 14173 | |
11797 | 14174 | =end original |
11798 | 14175 | |
11799 | 14176 | これが動かない場合(特に意地の悪い I/O 実装もあります)、 |
11800 | 14177 | 以下のようなことをする必要があります: |
11801 | 14178 | |
11802 | 14179 | for (;;) { |
11803 | for ($curpos = tell( | |
14180 | for ($curpos = tell($fh); $_ = readline($fh); | |
11804 | $curpos = tell( | |
14181 | $curpos = tell($fh)) { | |
11805 | 14182 | # search for some stuff and put it into files |
11806 | 14183 | } |
11807 | 14184 | sleep($for_a_while); |
11808 | seek( | |
14185 | seek($fh, $curpos, 0); | |
11809 | 14186 | } |
11810 | 14187 | |
11811 | 14188 | =item seekdir DIRHANDLE,POS |
11812 | 14189 | X<seekdir> |
11813 | 14190 | |
14191 | =for Pod::Functions reposition directory pointer | |
14192 | ||
11814 | 14193 | =begin original |
11815 | 14194 | |
11816 | Sets the current position for the C<readdir> | |
14195 | Sets the current position for the L<C<readdir>|/readdir DIRHANDLE> | |
11817 | must be a value returned by | |
14196 | routine on DIRHANDLE. POS must be a value returned by | |
11818 | ||
14197 | L<C<telldir>|/telldir DIRHANDLE>. L<C<seekdir>|/seekdir DIRHANDLE,POS> | |
11819 | ||
14198 | also has the same caveats about possible directory compaction as the | |
14199 | corresponding system library routine. | |
11820 | 14200 | |
11821 | 14201 | =end original |
11822 | 14202 | |
11823 | DIRHANDLE での C<readdir> ルーチンの現在位置を | |
14203 | DIRHANDLE での L<C<readdir>|/readdir DIRHANDLE> ルーチンの現在位置を | |
11824 | ||
14204 | 設定します。 | |
11825 | C< | |
14205 | POS は、L<C<telldir>|/telldir DIRHANDLE> が返す値でなければなりません。 | |
11826 | ||
14206 | L<C<seekdir>|/seekdir DIRHANDLE,POS> は同名のシステムライブラリルーチンと | |
14207 | 同じく、ディレクトリ縮小時の問題が考えられます。 | |
11827 | 14208 | |
11828 | 14209 | =item select FILEHANDLE |
11829 | 14210 | X<select> X<filehandle, default> |
11830 | 14211 | |
11831 | 14212 | =item select |
11832 | 14213 | |
14214 | =for Pod::Functions reset default output or do I/O multiplexing | |
14215 | ||
11833 | 14216 | =begin original |
11834 | 14217 | |
11835 | 14218 | Returns the currently selected filehandle. If FILEHANDLE is supplied, |
11836 | 14219 | sets the new current default filehandle for output. This has two |
11837 | effects: first, a C<write> or a C<print> | |
14220 | effects: first, a L<C<write>|/write FILEHANDLE> or a L<C<print>|/print | |
14221 | FILEHANDLE LIST> without a filehandle | |
11838 | 14222 | default to this FILEHANDLE. Second, references to variables related to |
11839 | output will refer to this output channel. | |
14223 | output will refer to this output channel. | |
11840 | 14224 | |
11841 | 14225 | =end original |
11842 | 14226 | |
11843 | 14227 | その時点で、選択されていたファイルハンドルを返します。 |
11844 | FILEHANDLE を指定した場合には、その値を出力のデフォルト | |
14228 | FILEHANDLE を指定した場合には、その値を出力のデフォルトファイルハンドルに | |
11845 | ||
14229 | 設定します。 | |
11846 | これには、2 つの効果があります | |
14230 | これには、2 つの効果があります: まず、ファイルハンドルを指定しないで | |
11847 | ||
14231 | L<C<write>|/write FILEHANDLE> や L<C<print>|/print FILEHANDLE LIST> を | |
11848 | ||
14232 | 行なった場合のデフォルトが、この FILEHANDLE になります。 | |
11849 | この | |
14233 | もう一つは、出力関連の変数への参照は、この出力チャネルを | |
11850 | ||
14234 | 参照するようになります。 | |
11851 | この出力チャネルを参照するようになります。 | |
11852 | 14235 | |
11853 | 14236 | =begin original |
11854 | 14237 | |
11855 | 14238 | For example, to set the top-of-form format for more than one |
11856 | 14239 | output channel, you might do the following: |
11857 | 14240 | |
11858 | 14241 | =end original |
11859 | 14242 | |
11860 | 14243 | 例えば、複数の出力チャネルに対して、ページ先頭フォーマットを |
11861 | 14244 | 設定するには: |
11862 | 14245 | |
11863 | 14246 | select(REPORT1); |
11864 | 14247 | $^ = 'report1_top'; |
11865 | 14248 | select(REPORT2); |
11866 | 14249 | $^ = 'report2_top'; |
11867 | 14250 | |
11868 | 14251 | =begin original |
11869 | 14252 | |
11870 | 14253 | FILEHANDLE may be an expression whose value gives the name of the |
11871 | 14254 | actual filehandle. Thus: |
11872 | 14255 | |
11873 | 14256 | =end original |
11874 | 14257 | |
11875 | FILEHANDLE は、実際のファイルハンドル | |
14258 | FILEHANDLE は、実際のファイルハンドル名を示す式でもかまいません。 | |
11876 | 14259 | つまり、以下のようなものです: |
11877 | 14260 | |
11878 | $oldfh = select(STDERR); $| = 1; select($oldfh); | |
14261 | my $oldfh = select(STDERR); $| = 1; select($oldfh); | |
11879 | 14262 | |
11880 | 14263 | =begin original |
11881 | 14264 | |
11882 | 14265 | Some programmers may prefer to think of filehandles as objects with |
11883 | 14266 | methods, preferring to write the last example as: |
11884 | 14267 | |
11885 | 14268 | =end original |
11886 | 14269 | |
11887 | ファイルハンドルはメソッドを持ったオブジェクトであると | |
14270 | ファイルハンドルはメソッドを持ったオブジェクトであると考えることを好む | |
11888 | ||
14271 | プログラマもいるかもしれません; そのような場合のための最後の例は | |
11889 | ||
14272 | 以下のようなものです: | |
11890 | 14273 | |
11891 | use IO::Handle; | |
11892 | 14274 | STDERR->autoflush(1); |
11893 | 14275 | |
14276 | =begin original | |
14277 | ||
14278 | (Prior to Perl version 5.14, you have to C<use IO::Handle;> explicitly | |
14279 | first.) | |
14280 | ||
14281 | =end original | |
14282 | ||
14283 | (Perl バージョン 5.14 以前では、まず明示的に C<use IO::Handle;> とする | |
14284 | 必要があります。) | |
14285 | ||
14286 | =begin original | |
14287 | ||
14288 | Portability issues: L<perlport/select>. | |
14289 | ||
14290 | =end original | |
14291 | ||
14292 | 移植性の問題: L<perlport/select>。 | |
14293 | ||
11894 | 14294 | =item select RBITS,WBITS,EBITS,TIMEOUT |
11895 | 14295 | X<select> |
11896 | 14296 | |
11897 | 14297 | =begin original |
11898 | 14298 | |
11899 | This calls the select(2) syscall with the bit masks specified, which | |
14299 | This calls the L<select(2)> syscall with the bit masks specified, which | |
11900 | can be constructed using C<fileno> | |
14300 | can be constructed using L<C<fileno>|/fileno FILEHANDLE> and | |
14301 | L<C<vec>|/vec EXPR,OFFSET,BITS>, along these lines: | |
11901 | 14302 | |
11902 | 14303 | =end original |
11903 | 14304 | |
11904 | これは、select(2) システムコールを、指定したビットマスクで呼び出します | |
14305 | これは、L<select(2)> システムコールを、指定したビットマスクで呼び出します; | |
11905 | ビットマスクは、C<fileno> | |
14306 | ビットマスクは、L<C<fileno>|/fileno FILEHANDLE> と | |
11906 | 作成できます: | |
14307 | L<C<vec>|/vec EXPR,OFFSET,BITS> を使って、以下のようにして作成できます: | |
11907 | 14308 | |
11908 | $rin = $win = $ein = ''; | |
14309 | my $rin = my $win = my $ein = ''; | |
11909 | vec($rin,fileno(STDIN),1) = 1; | |
14310 | vec($rin, fileno(STDIN), 1) = 1; | |
11910 | vec($win,fileno(STDOUT),1) = 1; | |
14311 | vec($win, fileno(STDOUT), 1) = 1; | |
11911 | 14312 | $ein = $rin | $win; |
11912 | 14313 | |
11913 | 14314 | =begin original |
11914 | 14315 | |
11915 | 14316 | If you want to select on many filehandles, you may wish to write a |
11916 | 14317 | subroutine like this: |
11917 | 14318 | |
11918 | 14319 | =end original |
11919 | 14320 | |
11920 | 14321 | 複数のファイルハンドルに select を行ないたいのであれば、 |
11921 | 14322 | 以下のようにします: |
11922 | 14323 | |
11923 | 14324 | sub fhbits { |
11924 | my | |
14325 | my @fhlist = @_; | |
11925 | my | |
14326 | my $bits = ""; | |
11926 | for (@fhlist) { | |
14327 | for my $fh (@fhlist) { | |
11927 | vec($bits,fileno($ | |
14328 | vec($bits, fileno($fh), 1) = 1; | |
11928 | 14329 | } |
11929 | $bits; | |
14330 | return $bits; | |
11930 | 14331 | } |
11931 | $rin = fhbits( | |
14332 | my $rin = fhbits(\*STDIN, $tty, $mysock); | |
11932 | 14333 | |
11933 | 14334 | =begin original |
11934 | 14335 | |
11935 | 14336 | The usual idiom is: |
11936 | 14337 | |
11937 | 14338 | =end original |
11938 | 14339 | |
11939 | 14340 | 通常は、 |
11940 | 14341 | |
11941 | | |
14342 | my ($nfound, $timeleft) = | |
11942 | | |
14343 | select(my $rout = $rin, my $wout = $win, my $eout = $ein, | |
14344 | $timeout); | |
11943 | 14345 | |
11944 | 14346 | =begin original |
11945 | 14347 | |
11946 | 14348 | or to block until something becomes ready just do this |
11947 | 14349 | |
11948 | 14350 | =end original |
11949 | 14351 | |
11950 | 14352 | のように使い、いずれかの準備が整うまでブロックするには、 |
11951 | 14353 | 以下のようにします。 |
11952 | 14354 | |
11953 | | |
14355 | my $nfound = | |
14356 | select(my $rout = $rin, my $wout = $win, my $eout = $ein, undef); | |
11954 | 14357 | |
11955 | 14358 | =begin original |
11956 | 14359 | |
11957 | Most systems do not bother to return anything useful in $timeleft, so | |
14360 | Most systems do not bother to return anything useful in C<$timeleft>, so | |
11958 | calling select | |
14361 | calling L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> in scalar context | |
14362 | just returns C<$nfound>. | |
11959 | 14363 | |
11960 | 14364 | =end original |
11961 | 14365 | |
11962 | ほとんどのシステムではわざわざ意味のある値を $timeleft に返さないので、 | |
14366 | ほとんどのシステムではわざわざ意味のある値を C<$timeleft> に返さないので、 | |
11963 | select | |
14367 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> をスカラコンテキストで | |
14368 | 呼び出すと、単に C<$nfound> を返します。 | |
11964 | 14369 | |
11965 | 14370 | =begin original |
11966 | 14371 | |
11967 | Any of the bit masks can also be undef. The timeout, | |
14372 | Any of the bit masks can also be L<C<undef>|/undef EXPR>. The timeout, | |
14373 | if specified, is | |
11968 | 14374 | in seconds, which may be fractional. Note: not all implementations are |
11969 | capable of returning the $timeleft. If not, they always return | |
14375 | capable of returning the C<$timeleft>. If not, they always return | |
11970 | $timeleft equal to the supplied $timeout. | |
14376 | C<$timeleft> equal to the supplied C<$timeout>. | |
11971 | 14377 | |
11972 | 14378 | =end original |
11973 | 14379 | |
11974 | どのビットマスクにも undef を設定することができます。 | |
14380 | どのビットマスクにも L<C<undef>|/undef EXPR> を設定することができます。 | |
11975 | 14381 | TIMEOUT を指定するときは、秒数で指定し、小数でかまいません。 |
11976 | 注: すべての実装で、$timeleft が返せるものではありません。 | |
14382 | 注: すべての実装で、C<$timeleft> が返せるものではありません。 | |
11977 | その場合、$timeleft には、常に指定した | |
14383 | その場合、C<$timeleft> には、常に指定した C<$timeout> と同じ値が返されます。 | |
11978 | 14384 | |
11979 | 14385 | =begin original |
11980 | 14386 | |
11981 | 14387 | You can effect a sleep of 250 milliseconds this way: |
11982 | 14388 | |
11983 | 14389 | =end original |
11984 | 14390 | |
11985 | 14391 | 250 ミリ秒の sleep と同じ効果が、以下のようにして得られます。 |
11986 | 14392 | |
11987 | 14393 | select(undef, undef, undef, 0.25); |
11988 | 14394 | |
11989 | 14395 | =begin original |
11990 | 14396 | |
11991 | Note that whether C<select> | |
14397 | Note that whether L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> gets | |
11992 | is implementation-dependent. Se | |
14398 | restarted after signals (say, SIGALRM) is implementation-dependent. See | |
11993 | portability of | |
14399 | also L<perlport> for notes on the portability of | |
14400 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>. | |
11994 | 14401 | |
11995 | 14402 | =end original |
11996 | 14403 | |
11997 | C<select> がシグナル (例えば、SIGALRM) の | |
14404 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> がシグナル (例えば、SIGALRM) の | |
11998 | 実装依存であることに注意してください。 | |
14405 | 後に再起動するかどうかは実装依存であることに注意してください。 | |
11999 | C<select> の移植性に関する | |
14406 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> の移植性に関する | |
14407 | 注意については L<perlport> も参照してください。 | |
12000 | 14408 | |
12001 | 14409 | =begin original |
12002 | 14410 | |
12003 | On error, C<select> | |
14411 | On error, L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> behaves just | |
12004 | -1 and sets C<$!>. | |
14412 | like L<select(2)>: it returns C<-1> and sets L<C<$!>|perlvar/$!>. | |
12005 | 14413 | |
12006 | 14414 | =end original |
12007 | 14415 | |
12008 | エラー時は、C<select> | |
14416 | エラー時は、L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> は | |
12009 | ||
14417 | L<select(2)> のように振舞います: | |
14418 | C<-1> を返し、L<C<$!>|perlvar/$!> をセットします。 | |
12010 | 14419 | |
12011 | 14420 | =begin original |
12012 | 14421 | |
12013 | On some Unixes, select(2) may report a socket file descriptor as | |
14422 | On some Unixes, L<select(2)> may report a socket file descriptor as | |
12014 | reading" even when no data is available, and thus any | |
14423 | "ready for reading" even when no data is available, and thus any | |
12015 | ||
14424 | subsequent L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> would block. | |
12016 | s | |
14425 | This can be avoided if you always use C<O_NONBLOCK> on the socket. See | |
14426 | L<select(2)> and L<fcntl(2)> for further details. | |
12017 | 14427 | |
12018 | 14428 | =end original |
12019 | 14429 | |
12020 | Unix の中には、実際に利用可能なデータがないために引き続く | |
14430 | Unix の中には、実際に利用可能なデータがないために引き続く | |
12021 | ||
14431 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> が | |
14432 | ブロックされる場合でも、L<select(2)> が、ソケットファイル記述子が | |
12022 | 14433 | 「読み込み準備中」であると報告するものもあります。 |
12023 | これは、ソケットに対して常に O_NONBLOCK フラグを使うことで回避できます。 | |
14434 | これは、ソケットに対して常に C<O_NONBLOCK> フラグを使うことで回避できます。 | |
12024 | さらなる詳細については select(2) と fcntl(2) を参照してください。 | |
14435 | さらなる詳細については L<select(2)> と L<fcntl(2)> を参照してください。 | |
12025 | 14436 | |
12026 | 14437 | =begin original |
12027 | 14438 | |
12028 | ||
14439 | The standard L<C<IO::Select>|IO::Select> module provides a | |
12029 | ||
14440 | user-friendlier interface to | |
12030 | t | |
14441 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, mostly because it does | |
14442 | all the bit-mask work for you. | |
12031 | 14443 | |
12032 | 14444 | =end original |
12033 | 14445 | |
12034 | ||
14446 | 標準の L<C<IO::Select>|IO::Select> モジュールは | |
14447 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> へのよりユーザーフレンドリーな | |
14448 | インターフェースを提供します; 主な理由はビットマスクの仕事を | |
14449 | してくれることです。 | |
14450 | ||
14451 | =begin original | |
14452 | ||
14453 | B<WARNING>: One should not attempt to mix buffered I/O (like | |
14454 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> or | |
14455 | L<C<readline>|/readline EXPR>) with | |
14456 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, except as permitted by | |
14457 | POSIX, and even then only on POSIX systems. You have to use | |
14458 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> instead. | |
14459 | ||
14460 | =end original | |
14461 | ||
14462 | B<警告>: バッファ付き I/O (L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> や | |
14463 | L<C<readline>|/readline EXPR>) と | |
14464 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を | |
12035 | 14465 | 混ぜて使ってはいけません(例外: POSIX で認められている形で使い、 |
12036 | 14466 | POSIX システムでだけ動かす場合を除きます)。 |
12037 | 代わりに C<sysread> を | |
14467 | 代わりに L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を | |
14468 | 使わなければなりません。 | |
12038 | 14469 | |
14470 | =begin original | |
14471 | ||
14472 | Portability issues: L<perlport/select>. | |
14473 | ||
14474 | =end original | |
14475 | ||
14476 | 移植性の問題: L<perlport/select>。 | |
14477 | ||
12039 | 14478 | =item semctl ID,SEMNUM,CMD,ARG |
12040 | 14479 | X<semctl> |
12041 | 14480 | |
14481 | =for Pod::Functions SysV semaphore control operations | |
14482 | ||
12042 | 14483 | =begin original |
12043 | 14484 | |
12044 | Calls the System V IPC function semctl(2). You'll probably have to say | |
14485 | Calls the System V IPC function L<semctl(2)>. You'll probably have to say | |
12045 | 14486 | |
12046 | 14487 | =end original |
12047 | 14488 | |
12048 | System V IPC 関数 semctl(2) を呼び出します。 | |
14489 | System V IPC 関数 L<semctl(2)> を呼び出します。 | |
12049 | 14490 | 正しい定数定義を得るために、まず |
12050 | 14491 | |
12051 | 14492 | use IPC::SysV; |
12052 | 14493 | |
12053 | 14494 | =begin original |
12054 | 14495 | |
12055 | 14496 | first to get the correct constant definitions. If CMD is IPC_STAT or |
12056 | 14497 | GETALL, then ARG must be a variable that will hold the returned |
12057 | semid_ds structure or semaphore value array. Returns like | |
14498 | semid_ds structure or semaphore value array. Returns like | |
14499 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>: | |
12058 | 14500 | the undefined value for error, "C<0 but true>" for zero, or the actual |
12059 | 14501 | return value otherwise. The ARG must consist of a vector of native |
12060 | 14502 | short integers, which may be created with C<pack("s!",(0)x$nsem)>. |
12061 | See also L<perlipc/"SysV IPC"> | |
14503 | See also L<perlipc/"SysV IPC"> and the documentation for | |
12062 | d | |
14504 | L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>. | |
12063 | 14505 | |
12064 | 14506 | =end original |
12065 | 14507 | |
12066 | と | |
14508 | と書くことが必要でしょう。 | |
12067 | 14509 | CMD が、IPC_STAT か GETALL のときには、ARG は、返される |
12068 | 14510 | semid_ds 構造体か、セマフォ値の配列を納める変数でなければなりません。 |
12069 | C<ioctl> と同じように、エラー時には | |
14511 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同じように、エラー時には | |
12070 | ゼロのときは C<"0 だが真">、それ以外なら、その値そのものを返します。 | |
14512 | 未定義値、ゼロのときは C<"0 だが真">、それ以外なら、その値そのものを返します。 | |
12071 | ARG はネイティブな short int のベクターから成っていなければなりません | |
14513 | ARG はネイティブな short int のベクターから成っていなければなりません; これは | |
12072 | ||
14514 | C<pack("s!",(0)x$nsem)> で作成できます。 | |
12073 | L<perlipc/"SysV IPC"> | |
14515 | L<perlipc/"SysV IPC"> と、 | |
14516 | L<C<IPC::SysV>|IPC::SysV>, L<C<IPC::Semaphore>|IPC::Semaphore> の文書も | |
14517 | 参照してください。 | |
12074 | 14518 | |
14519 | =begin original | |
14520 | ||
14521 | Portability issues: L<perlport/semctl>. | |
14522 | ||
14523 | =end original | |
14524 | ||
14525 | 移植性の問題: L<perlport/semctl>。 | |
14526 | ||
12075 | 14527 | =item semget KEY,NSEMS,FLAGS |
12076 | 14528 | X<semget> |
12077 | 14529 | |
14530 | =for Pod::Functions get set of SysV semaphores | |
14531 | ||
12078 | 14532 | =begin original |
12079 | 14533 | |
12080 | Calls the System V IPC function semget(2). Returns the semaphore id, or | |
14534 | Calls the System V IPC function L<semget(2)>. Returns the semaphore id, or | |
12081 | 14535 | the undefined value on error. See also |
12082 | L<perlipc/"SysV IPC"> | |
14536 | L<perlipc/"SysV IPC"> and the documentation for | |
12083 | d | |
14537 | L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>. | |
12084 | 14538 | |
12085 | 14539 | =end original |
12086 | 14540 | |
12087 | System V IPC 関数 semget(2) を呼び出します。 | |
14541 | System V IPC 関数 L<semget(2)> を呼び出します。 | |
12088 | 14542 | セマフォ ID か、エラー時には未定義値を返します。 |
12089 | L<perlipc/"SysV IPC"> | |
14543 | L<perlipc/"SysV IPC"> と、L<C<IPC::SysV>|IPC::SysV>, | |
12090 | 参照してください。 | |
14544 | L<C<IPC::Semaphore>|IPC::Semaphore> 文書も参照してください。 | |
12091 | 14545 | |
14546 | =begin original | |
14547 | ||
14548 | Portability issues: L<perlport/semget>. | |
14549 | ||
14550 | =end original | |
14551 | ||
14552 | 移植性の問題: L<perlport/semget>。 | |
14553 | ||
12092 | 14554 | =item semop KEY,OPSTRING |
12093 | 14555 | X<semop> |
12094 | 14556 | |
14557 | =for Pod::Functions SysV semaphore operations | |
14558 | ||
12095 | 14559 | =begin original |
12096 | 14560 | |
12097 | Calls the System V IPC function semop(2) for semaphore operations | |
14561 | Calls the System V IPC function L<semop(2)> for semaphore operations | |
12098 | 14562 | such as signalling and waiting. OPSTRING must be a packed array of |
12099 | 14563 | semop structures. Each semop structure can be generated with |
12100 | C<pack("s!3", $semnum, $semop, $semflag)>. The length of OPSTRING | |
14564 | C<pack("s!3", $semnum, $semop, $semflag)>. The length of OPSTRING | |
12101 | 14565 | implies the number of semaphore operations. Returns true if |
12102 | 14566 | successful, false on error. As an example, the |
12103 | 14567 | following code waits on semaphore $semnum of semaphore id $semid: |
12104 | 14568 | |
12105 | 14569 | =end original |
12106 | 14570 | |
12107 | 14571 | シグナルを送信や、待ち合わせなどのセマフォ操作を行なうために、 |
12108 | System V IPC 関数 semop(2) を呼び出します。 | |
14572 | System V IPC 関数 L<semop(2)> を呼び出します。 | |
12109 | 14573 | OPSTRING は、semop 構造体の pack された配列でなければなりません。 |
12110 | semop 構造体は、それぞれ、 | |
14574 | semop 構造体は、それぞれ、C<pack("s!3", $semnum, $semop, $semflag)> のように | |
12111 | ||
14575 | 作ることができます。 | |
12112 | 14576 | セマフォ操作の数は、OPSTRING の長さからわかります。 |
12113 | 14577 | 成功時には真を、エラー時には偽を返します。 |
12114 | 14578 | 以下の例は、セマフォ ID $semid のセマフォ $semnum で |
12115 | 14579 | 待ち合わせを行ないます。 |
12116 | 14580 | |
12117 | $semop = pack("s!3", $semnum, -1, 0); | |
14581 | my $semop = pack("s!3", $semnum, -1, 0); | |
12118 | 14582 | die "Semaphore trouble: $!\n" unless semop($semid, $semop); |
12119 | 14583 | |
12120 | 14584 | =begin original |
12121 | 14585 | |
12122 | 14586 | To signal the semaphore, replace C<-1> with C<1>. See also |
12123 | L<perlipc/"SysV IPC"> | |
14587 | L<perlipc/"SysV IPC"> and the documentation for | |
12124 | d | |
14588 | L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>. | |
12125 | 14589 | |
12126 | 14590 | =end original |
12127 | 14591 | |
12128 | 14592 | セマフォにシグナルを送るには、C<-1> を C<1> に変更してください。 |
12129 | L<perlipc/"SysV IPC"> | |
14593 | L<perlipc/"SysV IPC"> と L<C<IPC::SysV>|IPC::SysV>, | |
12130 | 参照してください。 | |
14594 | L<C<IPC::Semaphore>|IPC::Semaphore> の文書も参照してください。 | |
12131 | 14595 | |
14596 | =begin original | |
14597 | ||
14598 | Portability issues: L<perlport/semop>. | |
14599 | ||
14600 | =end original | |
14601 | ||
14602 | 移植性の問題: L<perlport/semop>。 | |
14603 | ||
12132 | 14604 | =item send SOCKET,MSG,FLAGS,TO |
12133 | 14605 | X<send> |
12134 | 14606 | |
12135 | 14607 | =item send SOCKET,MSG,FLAGS |
12136 | 14608 | |
14609 | =for Pod::Functions send a message over a socket | |
14610 | ||
12137 | 14611 | =begin original |
12138 | 14612 | |
12139 | 14613 | Sends a message on a socket. Attempts to send the scalar MSG to the SOCKET |
12140 | 14614 | filehandle. Takes the same flags as the system call of the same name. On |
12141 | 14615 | unconnected sockets, you must specify a destination to I<send to>, in which |
12142 | case it does a sendto(2) syscall. Returns the number of characters sent, | |
14616 | case it does a L<sendto(2)> syscall. Returns the number of characters sent, | |
12143 | or the undefined value on error. The sendmsg(2) syscall is currently | |
14617 | or the undefined value on error. The L<sendmsg(2)> syscall is currently | |
12144 | 14618 | unimplemented. See L<perlipc/"UDP: Message Passing"> for examples. |
12145 | 14619 | |
12146 | 14620 | =end original |
12147 | 14621 | |
12148 | 14622 | ソケットにメッセージを送ります。 |
12149 | 14623 | スカラ MSG を ファイルハンドル SOCKET に送ろうとします。 |
12150 | 14624 | 同名のシステムコールと同じフラグが指定できます。 |
12151 | 14625 | 接続していないソケットには、I<send to> に接続先を指定しなければならず、 |
12152 | この場合、sendto(2) を実行します。 | |
14626 | この場合、L<sendto(2)> を実行します。 | |
12153 | 14627 | 送信した文字数か、エラー時には、未定義値を返します。 |
12154 | システムコール sendmsg(2) は現在実装されていません。 | |
14628 | システムコール L<sendmsg(2)> は現在実装されていません。 | |
12155 | 14629 | 例については L<perlipc/"UDP: Message Passing"> を参照してください。 |
12156 | 14630 | |
12157 | 14631 | =begin original |
12158 | 14632 | |
12159 | 14633 | Note the I<characters>: depending on the status of the socket, either |
12160 | 14634 | (8-bit) bytes or characters are sent. By default all sockets operate |
12161 | 14635 | on bytes, but for example if the socket has been changed using |
12162 | binmode | |
14636 | L<C<binmode>|/binmode FILEHANDLE, LAYER> to operate with the | |
12163 | ||
14637 | C<:encoding(utf8)> I/O layer (see L<C<open>|/open FILEHANDLE,EXPR>, or | |
14638 | the L<open> pragma), the I/O will operate on UTF-8 | |
12164 | 14639 | encoded Unicode characters, not bytes. Similarly for the C<:encoding> |
12165 | ||
14640 | layer: in that case pretty much any characters can be sent. | |
12166 | 14641 | |
12167 | 14642 | =end original |
12168 | 14643 | |
12169 | 14644 | I<文字> に関する注意: ソケットの状態によって、(8 ビットの) バイトか |
12170 | 14645 | 文字を送信します。 |
12171 | 14646 | デフォルトでは全てのソケットはバイトを処理しますが、 |
12172 | 例えばソケットが binmode | |
14647 | 例えばソケットが L<C<binmode>|/binmode FILEHANDLE, LAYER> で | |
12173 | C< | |
14648 | C<:encoding(utf8)> I/O 層(L<C<open>|/open FILEHANDLE,EXPR>、 | |
14649 | L<open> プラグマを参照してください) を使うように指定された場合、 | |
12174 | 14650 | I/O はバイトではなく、UTF-8 エンコードされた Unicode 文字を操作します。 |
12175 | C<:encoding> | |
14651 | C<:encoding> 層も同様です: | |
12176 | 14652 | この場合、ほとんど大体全ての文字が書き込めます。 |
12177 | 14653 | |
12178 | 14654 | =item setpgrp PID,PGRP |
12179 | 14655 | X<setpgrp> X<group> |
12180 | 14656 | |
14657 | =for Pod::Functions set the process group of a process | |
14658 | ||
12181 | 14659 | =begin original |
12182 | 14660 | |
12183 | 14661 | Sets the current process group for the specified PID, C<0> for the current |
12184 | 14662 | process. Raises an exception when used on a machine that doesn't |
12185 | implement POSIX setpgid(2) or BSD setpgrp(2). If the arguments | |
14663 | implement POSIX L<setpgid(2)> or BSD L<setpgrp(2)>. If the arguments | |
12186 | it defaults to C<0,0>. Note that the BSD 4.2 version of | |
14664 | are omitted, it defaults to C<0,0>. Note that the BSD 4.2 version of | |
12187 | accept any arguments, so only | |
14665 | L<C<setpgrp>|/setpgrp PID,PGRP> does not accept any arguments, so only | |
12188 | C< | |
14666 | C<setpgrp(0,0)> is portable. See also | |
14667 | L<C<POSIX::setsid()>|POSIX/C<setsid>>. | |
12189 | 14668 | |
12190 | 14669 | =end original |
12191 | 14670 | |
12192 | 14671 | 指定した PID (C<0> を指定するとカレントプロセス) に |
12193 | 14672 | 対するプロセスグループを設定します。 |
12194 | POSIX setpgrp(2) または BSD setpgrp(2) が実装されていないマシンでは、 | |
14673 | POSIX L<setpgrp(2)> または BSD L<setpgrp(2)> が実装されていないマシンでは、 | |
12195 | 14674 | 例外が発生します。 |
12196 | 14675 | 引数が省略された場合は、C<0,0>が使われます。 |
12197 | BSD 4.2 版の C<setpgrp> は引数を取ることができないので、 | |
14676 | BSD 4.2 版の L<C<setpgrp>|/setpgrp PID,PGRP> は引数を取ることができないので、 | |
12198 | 14677 | C<setpgrp(0,0)> のみが移植性があることに注意してください。 |
12199 | C<POSIX::setsid()> も参照してください。 | |
14678 | L<C<POSIX::setsid()>|POSIX/C<setsid>> も参照してください。 | |
12200 | 14679 | |
14680 | =begin original | |
14681 | ||
14682 | Portability issues: L<perlport/setpgrp>. | |
14683 | ||
14684 | =end original | |
14685 | ||
14686 | 移植性の問題: L<perlport/setpgrp>。 | |
14687 | ||
12201 | 14688 | =item setpriority WHICH,WHO,PRIORITY |
12202 | 14689 | X<setpriority> X<priority> X<nice> X<renice> |
12203 | 14690 | |
14691 | =for Pod::Functions set a process's nice value | |
14692 | ||
12204 | 14693 | =begin original |
12205 | 14694 | |
12206 | 14695 | Sets the current priority for a process, a process group, or a user. |
12207 | (See setpriority(2).) Raises an exception when used on a machine | |
14696 | (See L<setpriority(2)>.) Raises an exception when used on a machine | |
12208 | that doesn't implement setpriority(2). | |
14697 | that doesn't implement L<setpriority(2)>. | |
12209 | 14698 | |
12210 | 14699 | =end original |
12211 | 14700 | |
12212 | 14701 | プロセス、プロセスグループ、ユーザに対する優先順位を設定します。 |
12213 | (setpriority(2) を参照してください。) | |
14702 | (L<setpriority(2)> を参照してください。) | |
12214 | setpriority(2) が実装されていないマシンでは、 | |
14703 | L<setpriority(2)> が実装されていないマシンでは、例外が発生します。 | |
12215 | 例外が発生します。 | |
12216 | 14704 | |
14705 | =begin original | |
14706 | ||
14707 | Portability issues: L<perlport/setpriority>. | |
14708 | ||
14709 | =end original | |
14710 | ||
14711 | 移植性の問題: L<perlport/setpriority>。 | |
14712 | ||
12217 | 14713 | =item setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL |
12218 | 14714 | X<setsockopt> |
12219 | 14715 | |
14716 | =for Pod::Functions set some socket options | |
14717 | ||
12220 | 14718 | =begin original |
12221 | 14719 | |
12222 | Sets the socket option requested. Returns C<undef> | |
14720 | Sets the socket option requested. Returns L<C<undef>|/undef EXPR> on | |
12223 | Use integer constants provided by the C<Socket> module | |
14721 | error. Use integer constants provided by the L<C<Socket>|Socket> module | |
14722 | for | |
12224 | 14723 | LEVEL and OPNAME. Values for LEVEL can also be obtained from |
12225 | 14724 | getprotobyname. OPTVAL might either be a packed string or an integer. |
12226 | 14725 | An integer OPTVAL is shorthand for pack("i", OPTVAL). |
12227 | 14726 | |
12228 | 14727 | =end original |
12229 | 14728 | |
12230 | 14729 | 要求したソケットオプションを設定します。 |
12231 | エラー時には、C<undef> を返します。 | |
14730 | エラー時には、L<C<undef>|/undef EXPR> を返します。 | |
12232 | LEVEL と OPNAME には C<Socket> モジュールが提供する | |
14731 | LEVEL と OPNAME には L<C<Socket>|Socket> モジュールが提供する | |
14732 | 整数定数を使います。 | |
12233 | 14733 | LEVEL の値は getprotobyname から得ることもできます。 |
12234 | 14734 | OPTVAL は pack された文字列か整数です。 |
12235 | 14735 | 整数の OPTVAL は pack("i", OPTVAL) の省略表現です。 |
12236 | 14736 | |
12237 | 14737 | =begin original |
12238 | 14738 | |
12239 | 14739 | An example disabling Nagle's algorithm on a socket: |
12240 | 14740 | |
12241 | 14741 | =end original |
12242 | 14742 | |
12243 | 14743 | ソケットに対する Nagle のアルゴリズムを無効にする例です: |
12244 | 14744 | |
12245 | 14745 | use Socket qw(IPPROTO_TCP TCP_NODELAY); |
12246 | 14746 | setsockopt($socket, IPPROTO_TCP, TCP_NODELAY, 1); |
12247 | 14747 | |
14748 | =begin original | |
14749 | ||
14750 | Portability issues: L<perlport/setsockopt>. | |
14751 | ||
14752 | =end original | |
14753 | ||
14754 | 移植性の問題: L<perlport/setsockopt>。 | |
14755 | ||
12248 | 14756 | =item shift ARRAY |
12249 | 14757 | X<shift> |
12250 | 14758 | |
12251 | =item shift EXPR | |
12252 | ||
12253 | 14759 | =item shift |
12254 | 14760 | |
14761 | =for Pod::Functions remove the first element of an array, and return it | |
14762 | ||
12255 | 14763 | =begin original |
12256 | 14764 | |
12257 | 14765 | Shifts the first value of the array off and returns it, shortening the |
12258 | 14766 | array by 1 and moving everything down. If there are no elements in the |
12259 | 14767 | array, returns the undefined value. If ARRAY is omitted, shifts the |
12260 | C<@_> array within the lexical scope of subroutines and | |
14768 | L<C<@_>|perlvar/@_> array within the lexical scope of subroutines and | |
12261 | C<@ARGV> array outside a subroutine | |
14769 | formats, and the L<C<@ARGV>|perlvar/@ARGV> array outside a subroutine | |
14770 | and also within the lexical scopes | |
12262 | 14771 | established by the C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}>, |
12263 | 14772 | C<UNITCHECK {}>, and C<END {}> constructs. |
12264 | 14773 | |
12265 | 14774 | =end original |
12266 | 14775 | |
12267 | 配列の最初の値を取り出して、その値を返し、配列を一つ | |
14776 | 配列の最初の値を取り出して、その値を返し、配列を一つ短くして、すべての要素を | |
12268 | ||
14777 | 前へずらします。 | |
12269 | 14778 | 配列に要素がなければ、未定義値を返します。 |
12270 | ARRAY を省略すると、 | |
14779 | ARRAY を省略すると、サブルーチンやフォーマットのレキシカルスコープでは | |
12271 | サブルーチン | |
14780 | L<C<@_>|perlvar/@_> を、サブルーチンの外側で、C<eval STRING>, C<BEGIN {}>, | |
12272 | ||
14781 | C<INIT {}>, C<CHECK {}>, C<UNITCHECK {}>, C<END {}> で作成された | |
12273 | ||
14782 | レキシカルスコープでは L<C<@ARGV>|perlvar/@ARGV> が用いられます。 | |
12274 | C<@ARGV> が用いられます。 | |
12275 | 14783 | |
12276 | 14784 | =begin original |
12277 | 14785 | |
12278 | Starting with Perl 5.14, | |
14786 | Starting with Perl 5.14, an experimental feature allowed | |
12279 | ||
14787 | L<C<shift>|/shift ARRAY> to take a | |
12280 | ||
14788 | scalar expression. This experiment has been deemed unsuccessful, and was | |
12281 | ||
14789 | removed as of Perl 5.24. | |
12282 | 14790 | |
12283 | 14791 | =end original |
12284 | 14792 | |
12285 | Perl 5.14 から、C<shift> | |
14793 | Perl 5.14 から、L<C<shift>|/shift ARRAY> がスカラ式を取ることが出来るという | |
12286 | ||
14794 | 実験的機能がありました。 | |
12287 | ||
14795 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 | |
12288 | C<shift> のこの動作は高度に実験的であると考えられています。 | |
12289 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 | |
12290 | 14796 | |
12291 | 14797 | =begin original |
12292 | 14798 | |
12293 | See also C<unshift> | |
14799 | See also L<C<unshift>|/unshift ARRAY,LIST>, L<C<push>|/push ARRAY,LIST>, | |
12294 | ||
14800 | and L<C<pop>|/pop ARRAY>. L<C<shift>|/shift ARRAY> and | |
12295 | ||
14801 | L<C<unshift>|/unshift ARRAY,LIST> do the same thing to the left end of | |
14802 | an array that L<C<pop>|/pop ARRAY> and L<C<push>|/push ARRAY,LIST> do to | |
14803 | the right end. | |
12296 | 14804 | |
12297 | 14805 | =end original |
12298 | 14806 | |
12299 | C<unshift> | |
14807 | L<C<unshift>|/unshift ARRAY,LIST>、L<C<push>|/push ARRAY,LIST>、 | |
12300 | ||
14808 | L<C<pop>|/pop ARRAY> も参照してください。 | |
12301 | C< | |
14809 | L<C<shift>|/shift ARRAY> と L<C<unshift>|/unshift ARRAY,LIST> は、 | |
14810 | L<C<pop>|/pop ARRAY> と L<C<push>|/push ARRAY,LIST> が配列の右端で | |
14811 | 行なうことを、左端で行ないます。 | |
12302 | 14812 | |
12303 | 14813 | =item shmctl ID,CMD,ARG |
12304 | 14814 | X<shmctl> |
12305 | 14815 | |
14816 | =for Pod::Functions SysV shared memory operations | |
14817 | ||
12306 | 14818 | =begin original |
12307 | 14819 | |
12308 | 14820 | Calls the System V IPC function shmctl. You'll probably have to say |
12309 | 14821 | |
12310 | 14822 | =end original |
12311 | 14823 | |
12312 | System V IPC 関数 shmctl を呼び出します。 | |
14824 | System V IPC 関数 shmctl を呼び出します。 | |
14825 | 正しい定数定義を得るために、まず | |
12313 | 14826 | |
12314 | 14827 | use IPC::SysV; |
12315 | 14828 | |
12316 | 14829 | =begin original |
12317 | 14830 | |
12318 | 14831 | first to get the correct constant definitions. If CMD is C<IPC_STAT>, |
12319 | 14832 | then ARG must be a variable that will hold the returned C<shmid_ds> |
12320 | structure. Returns like ioctl: C<undef> for error; "C<0> | |
14833 | structure. Returns like ioctl: L<C<undef>|/undef EXPR> for error; "C<0> | |
12321 | true" for zero; and the actual return value otherwise. | |
14834 | but true" for zero; and the actual return value otherwise. | |
12322 | See also L<perlipc/"SysV IPC"> and | |
14835 | See also L<perlipc/"SysV IPC"> and the documentation for | |
14836 | L<C<IPC::SysV>|IPC::SysV>. | |
12323 | 14837 | |
12324 | 14838 | =end original |
12325 | 14839 | |
12326 | と | |
14840 | と書くことが必要でしょう。 | |
12327 | 14841 | CMD が、C<IPC_STAT> ならば、ARG は、返される C<shmid_ds> 構造体を |
12328 | 14842 | 納める変数でなければなりません。 |
12329 | ioctl と同様です: エラー時には C<undef>; ゼロのときは | |
14843 | ioctl と同様です: エラー時には L<C<undef>|/undef EXPR>; ゼロのときは | |
12330 | それ以外なら、その値そのものを返します。 | |
14844 | "C<0> だが真"; それ以外なら、その値そのものを返します。 | |
12331 | L<perlipc/"SysV IPC"> と C<IPC::SysV> も参照してください。 | |
14845 | L<perlipc/"SysV IPC"> と L<C<IPC::SysV>|IPC::SysV> の文書も参照してください。 | |
12332 | 14846 | |
14847 | =begin original | |
14848 | ||
14849 | Portability issues: L<perlport/shmctl>. | |
14850 | ||
14851 | =end original | |
14852 | ||
14853 | 移植性の問題: L<perlport/shmctl>。 | |
14854 | ||
12333 | 14855 | =item shmget KEY,SIZE,FLAGS |
12334 | 14856 | X<shmget> |
12335 | 14857 | |
14858 | =for Pod::Functions get SysV shared memory segment identifier | |
14859 | ||
12336 | 14860 | =begin original |
12337 | 14861 | |
12338 | 14862 | Calls the System V IPC function shmget. Returns the shared memory |
12339 | segment id, or C<undef> on error. | |
14863 | segment id, or L<C<undef>|/undef EXPR> on error. | |
12340 | See also L<perlipc/"SysV IPC"> and | |
14864 | See also L<perlipc/"SysV IPC"> and the documentation for | |
14865 | L<C<IPC::SysV>|IPC::SysV>. | |
12341 | 14866 | |
12342 | 14867 | =end original |
12343 | 14868 | |
12344 | 14869 | System V IPC 関数 shmget を呼び出します。 |
12345 | 共有メモリのセグメント ID か、エラー時には C<undef> を返します。 | |
14870 | 共有メモリのセグメント ID か、エラー時には L<C<undef>|/undef EXPR> を返します。 | |
12346 | L<perlipc/"SysV IPC"> と C<IPC::SysV> も参照してください。 | |
14871 | L<perlipc/"SysV IPC"> と L<C<IPC::SysV>|IPC::SysV> の文書も参照してください。 | |
12347 | 14872 | |
14873 | =begin original | |
14874 | ||
14875 | Portability issues: L<perlport/shmget>. | |
14876 | ||
14877 | =end original | |
14878 | ||
14879 | 移植性の問題: L<perlport/shmget>。 | |
14880 | ||
12348 | 14881 | =item shmread ID,VAR,POS,SIZE |
12349 | 14882 | X<shmread> |
12350 | 14883 | X<shmwrite> |
12351 | 14884 | |
14885 | =for Pod::Functions read SysV shared memory | |
14886 | ||
12352 | 14887 | =item shmwrite ID,STRING,POS,SIZE |
12353 | 14888 | |
14889 | =for Pod::Functions write SysV shared memory | |
14890 | ||
12354 | 14891 | =begin original |
12355 | 14892 | |
12356 | 14893 | Reads or writes the System V shared memory segment ID starting at |
12357 | 14894 | position POS for size SIZE by attaching to it, copying in/out, and |
12358 | 14895 | detaching from it. When reading, VAR must be a variable that will |
12359 | 14896 | hold the data read. When writing, if STRING is too long, only SIZE |
12360 | 14897 | bytes are used; if STRING is too short, nulls are written to fill out |
12361 | 14898 | SIZE bytes. Return true if successful, false on error. |
12362 | shmread | |
14899 | L<C<shmread>|/shmread ID,VAR,POS,SIZE> taints the variable. See also | |
12363 | ||
14900 | L<perlipc/"SysV IPC"> and the documentation for | |
14901 | L<C<IPC::SysV>|IPC::SysV> and the L<C<IPC::Shareable>|IPC::Shareable> | |
14902 | module from CPAN. | |
12364 | 14903 | |
12365 | 14904 | =end original |
12366 | 14905 | |
12367 | System V 共有メモリセグメント ID に対し、アタッチして、 | |
14906 | System V 共有メモリセグメント ID に対し、アタッチして、コピーを行ない、 | |
12368 | ||
14907 | デタッチするという形で、位置 POS から、サイズ SIZE だけ、読み込みか書き込みを | |
12369 | ||
14908 | 行ないます。 | |
12370 | 読み込み時には、VAR は読み込んだデータを納める | |
14909 | 読み込み時には、VAR は読み込んだデータを納める変数でなければなりません。 | |
12371 | ||
14910 | 書き込み時には、STRING が長すぎても、SIZE バイトだけが使われます; STRING が | |
12372 | ||
14911 | 短すぎる場合には、SIZE バイトを埋めるために、ヌル文字が書き込まれます。 | |
12373 | STRING が短すぎる場合には、SIZE バイトを埋めるために、 | |
12374 | ヌル文字が書き込まれます。 | |
12375 | 14912 | 成功時には真を、エラー時には偽を返します。 |
12376 | shmread | |
14913 | L<C<shmread>|/shmread ID,VAR,POS,SIZE> は変数を汚染します。 | |
12377 | L<perlipc/"SysV IPC"> および | |
14914 | L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV> と CPAN の | |
12378 | CP | |
14915 | L<C<IPC::Shareable>|IPC::Shareable> の文書も参照してください。 | |
12379 | 14916 | |
14917 | =begin original | |
14918 | ||
14919 | Portability issues: L<perlport/shmread> and L<perlport/shmwrite>. | |
14920 | ||
14921 | =end original | |
14922 | ||
14923 | 移植性の問題: L<perlport/shmread> と L<perlport/shmwrite>。 | |
14924 | ||
12380 | 14925 | =item shutdown SOCKET,HOW |
12381 | 14926 | X<shutdown> |
12382 | 14927 | |
14928 | =for Pod::Functions close down just half of a socket connection | |
14929 | ||
12383 | 14930 | =begin original |
12384 | 14931 | |
12385 | 14932 | Shuts down a socket connection in the manner indicated by HOW, which |
12386 | 14933 | has the same interpretation as in the syscall of the same name. |
12387 | 14934 | |
12388 | 14935 | =end original |
12389 | 14936 | |
12390 | 14937 | 同名のシステムコールと同じように解釈される HOW によって、 |
12391 | 14938 | 指定された方法でソケット接続のシャットダウンを行ないます。 |
12392 | 14939 | |
12393 | shutdown( | |
14940 | shutdown($socket, 0); # I/we have stopped reading data | |
12394 | shutdown( | |
14941 | shutdown($socket, 1); # I/we have stopped writing data | |
12395 | shutdown( | |
14942 | shutdown($socket, 2); # I/we have stopped using this socket | |
12396 | 14943 | |
12397 | 14944 | =begin original |
12398 | 14945 | |
12399 | 14946 | This is useful with sockets when you want to tell the other |
12400 | 14947 | side you're done writing but not done reading, or vice versa. |
12401 | 14948 | It's also a more insistent form of close because it also |
12402 | 14949 | disables the file descriptor in any forked copies in other |
12403 | 14950 | processes. |
12404 | 14951 | |
12405 | 14952 | =end original |
12406 | 14953 | |
12407 | 14954 | これは、こちらがソケットを書き終わったが読み終わっていない、 |
12408 | 14955 | またはその逆を相手側に伝えたいときに便利です。 |
12409 | 14956 | これはその他のプロセスでフォークしたファイル記述子のコピーも |
12410 | 14957 | 無効にするので、よりしつこい閉じ方です。 |
12411 | 14958 | |
12412 | 14959 | =begin original |
12413 | 14960 | |
12414 | Returns C<1> for success; on error, returns C<undef> if | |
14961 | Returns C<1> for success; on error, returns L<C<undef>|/undef EXPR> if | |
12415 | 14962 | the first argument is not a valid filehandle, or returns C<0> and sets |
12416 | C<$!> for any other failure. | |
14963 | L<C<$!>|perlvar/$!> for any other failure. | |
12417 | 14964 | |
12418 | 14965 | =end original |
12419 | 14966 | |
12420 | 14967 | 成功時には C<1> を返します; |
12421 | エラーの場合、最初の引数が有効なファイルハンドルでない場合は | |
14968 | エラーの場合、最初の引数が有効なファイルハンドルでない場合は | |
12422 | 返し、その他のエラーの場合は C<0> を返して | |
14969 | L<C<undef>|/undef EXPR> を返し、その他のエラーの場合は C<0> を返して | |
14970 | L<C<$!>|perlvar/$!> をセットします。 | |
12423 | 14971 | |
12424 | 14972 | =item sin EXPR |
12425 | 14973 | X<sin> X<sine> X<asin> X<arcsine> |
12426 | 14974 | |
12427 | 14975 | =item sin |
12428 | 14976 | |
14977 | =for Pod::Functions return the sine of a number | |
14978 | ||
12429 | 14979 | =begin original |
12430 | 14980 | |
12431 | 14981 | Returns the sine of EXPR (expressed in radians). If EXPR is omitted, |
12432 | returns sine of C<$_>. | |
14982 | returns sine of L<C<$_>|perlvar/$_>. | |
12433 | 14983 | |
12434 | 14984 | =end original |
12435 | 14985 | |
12436 | 14986 | (ラジアンで示した) EXPR の正弦を返します。 |
12437 | EXPR が省略されたときには、C<$_> の正弦を返します。 | |
14987 | EXPR が省略されたときには、L<C<$_>|perlvar/$_> の正弦を返します。 | |
12438 | 14988 | |
12439 | 14989 | =begin original |
12440 | 14990 | |
12441 | 14991 | For the inverse sine operation, you may use the C<Math::Trig::asin> |
12442 | 14992 | function, or use this relation: |
12443 | 14993 | |
12444 | 14994 | =end original |
12445 | 14995 | |
12446 | 14996 | 逆正弦を求めるためには、C<Math::Trig::asin> 関数を使うか、 |
12447 | 14997 | 以下の関係を使ってください: |
12448 | 14998 | |
12449 | 14999 | sub asin { atan2($_[0], sqrt(1 - $_[0] * $_[0])) } |
12450 | 15000 | |
12451 | 15001 | =item sleep EXPR |
12452 | 15002 | X<sleep> X<pause> |
12453 | 15003 | |
12454 | 15004 | =item sleep |
12455 | 15005 | |
15006 | =for Pod::Functions block for some number of seconds | |
15007 | ||
12456 | 15008 | =begin original |
12457 | 15009 | |
12458 | Causes the script to sleep for (integer) EXPR seconds, or forever if no | |
15010 | Causes the script to sleep for (integer) EXPR seconds, or forever if no | |
12459 | argument is given. Returns the integer number of seconds actually slept. | |
15011 | argument is given. Returns the integer number of seconds actually slept. | |
12460 | 15012 | |
12461 | 15013 | =end original |
12462 | 15014 | |
12463 | 15015 | スクリプトを(整数の) EXPR で指定した秒数 (省略時には、永久に) |
12464 | 15016 | スリープさせます。 |
12465 | 実際にスリープした秒数を返します。 | |
15017 | 実際にスリープした秒数を返します。 | |
12466 | 15018 | |
12467 | 15019 | =begin original |
12468 | 15020 | |
12469 | 15021 | May be interrupted if the process receives a signal such as C<SIGALRM>. |
12470 | 15022 | |
12471 | 15023 | =end original |
12472 | 15024 | |
12473 | 15025 | そのプロセスが C<SIGALRM>のようなシグナルを受信すると、 |
12474 | 15026 | 割り込みがかかります。 |
12475 | 15027 | |
12476 | 15028 | eval { |
12477 | local $SIG{AL | |
15029 | local $SIG{ALRM} = sub { die "Alarm!\n" }; | |
12478 | 15030 | sleep; |
12479 | 15031 | }; |
12480 | 15032 | die $@ unless $@ eq "Alarm!\n"; |
12481 | 15033 | |
12482 | 15034 | =begin original |
12483 | 15035 | |
12484 | You probably cannot mix C<alarm> | |
15036 | You probably cannot mix L<C<alarm>|/alarm SECONDS> and | |
12485 | ||
15037 | L<C<sleep>|/sleep EXPR> calls, because L<C<sleep>|/sleep EXPR> is often | |
15038 | implemented using L<C<alarm>|/alarm SECONDS>. | |
12486 | 15039 | |
12487 | 15040 | =end original |
12488 | 15041 | |
12489 | C<sleep> は、C<alarm> | |
15042 | L<C<sleep>|/sleep EXPR> は、L<C<alarm>|/alarm SECONDS> を使って | |
12490 | C< | |
15043 | 実装されることが多いので、L<C<alarm>|/alarm SECONDS> と | |
15044 | L<C<sleep>|/sleep EXPR> は、混ぜて使用することはおそらくできません。 | |
12491 | 15045 | |
12492 | 15046 | =begin original |
12493 | 15047 | |
12494 | 15048 | On some older systems, it may sleep up to a full second less than what |
12495 | 15049 | you requested, depending on how it counts seconds. Most modern systems |
12496 | 15050 | always sleep the full amount. They may appear to sleep longer than that, |
12497 | 15051 | however, because your process might not be scheduled right away in a |
12498 | 15052 | busy multitasking system. |
12499 | 15053 | |
12500 | 15054 | =end original |
12501 | 15055 | |
12502 | 15056 | 古いシステムでは、どのように秒を数えるかによって、要求した秒数に完全に |
12503 | 15057 | 満たないうちに、スリープから抜ける場合があります。 |
12504 | 15058 | 最近のシステムでは、常に完全にスリープします。 |
12505 | 15059 | しかし、負荷の高いマルチタスクシステムでは |
12506 | 15060 | 正しくスケジューリングされないがために |
12507 | 15061 | より長い時間スリープすることがあります。 |
12508 | 15062 | |
12509 | 15063 | =begin original |
12510 | 15064 | |
12511 | For delays of finer granularity than one second, the Time::HiRes | |
15065 | For delays of finer granularity than one second, the L<Time::HiRes> | |
12512 | (from CPAN, and starting from Perl 5.8 part of the standard | |
15066 | module (from CPAN, and starting from Perl 5.8 part of the standard | |
12513 | distribution) provides usleep | |
15067 | distribution) provides L<C<usleep>|Time::HiRes/usleep ( $useconds )>. | |
12514 | ||
15068 | You may also use Perl's four-argument | |
12515 | ||
15069 | version of L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> leaving the | |
12516 | ||
15070 | first three arguments undefined, or you might be able to use the | |
15071 | L<C<syscall>|/syscall NUMBER, LIST> interface to access L<setitimer(2)> | |
15072 | if your system supports it. See L<perlfaq8> for details. | |
12517 | 15073 | |
12518 | 15074 | =end original |
12519 | 15075 | |
12520 | 1 秒より精度の高いスリープを行なうには、 | |
15076 | 1 秒より精度の高いスリープを行なうには、L<Time::HiRes> モジュール(CPAN から、 | |
12521 | ||
15077 | また Perl 5.8 からは標準配布されています) が | |
12522 | ||
15078 | L<C<usleep>|Time::HiRes/usleep ( $useconds )> を提供します。 | |
12523 | Perl の 4 引数版 select | |
15079 | Perl の 4 引数版 L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を最初の | |
12524 | setitimer(2) をサポートしているシステムでは、 | |
15080 | 3 引数を未定義にして使うか、L<setitimer(2)> をサポートしているシステムでは、 | |
12525 | C<syscall> インタフェースを使って | |
15081 | Perl の L<C<syscall>|/syscall NUMBER, LIST> インタフェースを使って | |
15082 | アクセスすることもできます。 | |
12526 | 15083 | 詳しくは L<perlfaq8> を参照してください。 |
12527 | 15084 | |
12528 | 15085 | =begin original |
12529 | 15086 | |
12530 | See also the POSIX module's C<pause> function. | |
15087 | See also the L<POSIX> module's L<C<pause>|POSIX/C<pause>> function. | |
12531 | 15088 | |
12532 | 15089 | =end original |
12533 | 15090 | |
12534 | POSIX モジュールの C<pause> 関数も参照して | |
15091 | L<POSIX> モジュールの L<C<pause>|POSIX/C<pause>> 関数も参照してください。 | |
12535 | 15092 | |
12536 | 15093 | =item socket SOCKET,DOMAIN,TYPE,PROTOCOL |
12537 | 15094 | X<socket> |
12538 | 15095 | |
15096 | =for Pod::Functions create a socket | |
15097 | ||
12539 | 15098 | =begin original |
12540 | 15099 | |
12541 | 15100 | Opens a socket of the specified kind and attaches it to filehandle |
12542 | 15101 | SOCKET. DOMAIN, TYPE, and PROTOCOL are specified the same as for |
12543 | 15102 | the syscall of the same name. You should C<use Socket> first |
12544 | 15103 | to get the proper definitions imported. See the examples in |
12545 | 15104 | L<perlipc/"Sockets: Client/Server Communication">. |
12546 | 15105 | |
12547 | 15106 | =end original |
12548 | 15107 | |
12549 | 指定した種類のソケットをオープンし、ファイルハンドル | |
15108 | 指定した種類のソケットをオープンし、ファイルハンドル SOCKET にアタッチします。 | |
12550 | ||
15109 | DOMAIN, TYPE, PROTOCOL は、同名のシステムコールと同じように指定します。 | |
12551 | ||
15110 | 適切な定義を import するために、まず、C<use Socket> とするとよいでしょう。 | |
12552 | ||
15111 | L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。 | |
12553 | 適切な定義を import するために、まず、C<use Socket> と | |
12554 | するとよいでしょう。 | |
12555 | 例については L<perlipc/"Sockets: Client/Server Communication"> を | |
12556 | 参照してください。 | |
12557 | 15112 | |
12558 | 15113 | =begin original |
12559 | 15114 | |
12560 | 15115 | On systems that support a close-on-exec flag on files, the flag will |
12561 | 15116 | be set for the newly opened file descriptor, as determined by the |
12562 | value of $^F. See L<perlvar/$^F>. | |
15117 | value of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>. | |
12563 | 15118 | |
12564 | 15119 | =end original |
12565 | 15120 | |
12566 | 15121 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
12567 | フラグは $^F の値で決定される、新しくオープンされた | |
15122 | フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた | |
12568 | セットされます。 | |
15123 | ファイル記述子に対してセットされます。 | |
12569 | 15124 | L<perlvar/$^F> を参照してください。 |
12570 | 15125 | |
12571 | 15126 | =item socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL |
12572 | 15127 | X<socketpair> |
12573 | 15128 | |
15129 | =for Pod::Functions create a pair of sockets | |
15130 | ||
12574 | 15131 | =begin original |
12575 | 15132 | |
12576 | 15133 | Creates an unnamed pair of sockets in the specified domain, of the |
12577 | 15134 | specified type. DOMAIN, TYPE, and PROTOCOL are specified the same as |
12578 | 15135 | for the syscall of the same name. If unimplemented, raises an exception. |
12579 | 15136 | Returns true if successful. |
12580 | 15137 | |
12581 | 15138 | =end original |
12582 | 15139 | |
12583 | 15140 | 指定した DOMAIN に、指定した TYPE で名前の無いソケットのペアを生成します。 |
12584 | DOMAIN | |
15141 | DOMAIN, TYPE, PROTOCOL は、同名のシステムコールと同じように指定します。 | |
12585 | 15142 | 実装されていない場合には、例外が発生します。 |
12586 | 15143 | 成功時には真を返します。 |
12587 | 15144 | |
12588 | 15145 | =begin original |
12589 | 15146 | |
12590 | 15147 | On systems that support a close-on-exec flag on files, the flag will |
12591 | 15148 | be set for the newly opened file descriptors, as determined by the value |
12592 | of $^F. See L<perlvar/$^F>. | |
15149 | of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>. | |
12593 | 15150 | |
12594 | 15151 | =end original |
12595 | 15152 | |
12596 | 15153 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
12597 | フラグは $^F の値で決定される、新しくオープンされた | |
15154 | フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた | |
12598 | セットされます。 | |
15155 | ファイル記述子に対してセットされます。 | |
12599 | 15156 | L<perlvar/$^F> を参照してください。 |
12600 | 15157 | |
12601 | 15158 | =begin original |
12602 | 15159 | |
12603 | Some systems define | |
15160 | Some systems define L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> in terms of | |
12604 | ||
15161 | L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL>, in | |
15162 | which a call to C<pipe($rdr, $wtr)> is essentially: | |
12605 | 15163 | |
12606 | 15164 | =end original |
12607 | 15165 | |
12608 | C<pipe> | |
15166 | L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> を | |
12609 | C<pi | |
15167 | L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL> を使って | |
15168 | 定義しているシステムもあります; | |
15169 | C<pipe($rdr, $wtr)> は本質的には以下のようになります: | |
12610 | 15170 | |
12611 | 15171 | use Socket; |
12612 | socketpair( | |
15172 | socketpair(my $rdr, my $wtr, AF_UNIX, SOCK_STREAM, PF_UNSPEC); | |
12613 | shutdown( | |
15173 | shutdown($rdr, 1); # no more writing for reader | |
12614 | shutdown( | |
15174 | shutdown($wtr, 0); # no more reading for writer | |
12615 | 15175 | |
12616 | 15176 | =begin original |
12617 | 15177 | |
12618 | 15178 | See L<perlipc> for an example of socketpair use. Perl 5.8 and later will |
12619 | 15179 | emulate socketpair using IP sockets to localhost if your system implements |
12620 | 15180 | sockets but not socketpair. |
12621 | 15181 | |
12622 | 15182 | =end original |
12623 | 15183 | |
12624 | 15184 | socketpair の使用例については L<perlipc> を参照してください。 |
12625 | 15185 | Perl 5.8 以降では、システムがソケットを実装しているが socketpair を |
12626 | 15186 | 実装していない場合、localhost に対して IP ソケットを使うことで |
12627 | 15187 | socketpair をエミュレートします。 |
12628 | 15188 | |
15189 | =begin original | |
15190 | ||
15191 | Portability issues: L<perlport/socketpair>. | |
15192 | ||
15193 | =end original | |
15194 | ||
15195 | 移植性の問題: L<perlport/socketpair>。 | |
15196 | ||
12629 | 15197 | =item sort SUBNAME LIST |
12630 | 15198 | X<sort> X<qsort> X<quicksort> X<mergesort> |
12631 | 15199 | |
12632 | 15200 | =item sort BLOCK LIST |
12633 | 15201 | |
12634 | 15202 | =item sort LIST |
12635 | 15203 | |
15204 | =for Pod::Functions sort a list of values | |
15205 | ||
12636 | 15206 | =begin original |
12637 | 15207 | |
12638 | 15208 | In list context, this sorts the LIST and returns the sorted list value. |
12639 | In scalar context, the behaviour of C<sort | |
15209 | In scalar context, the behaviour of L<C<sort>|/sort SUBNAME LIST> is | |
15210 | undefined. | |
12640 | 15211 | |
12641 | 15212 | =end original |
12642 | 15213 | |
12643 | 15214 | リストコンテキストでは、LIST をソートし、ソートされたリスト値を返します。 |
12644 | スカラコンテキストでは、C<sort | |
15215 | スカラコンテキストでは、L<C<sort>|/sort SUBNAME LIST> の振る舞いは未定義です。 | |
12645 | 15216 | |
12646 | 15217 | =begin original |
12647 | 15218 | |
12648 | If SUBNAME or BLOCK is omitted, C<sort>s | |
15219 | If SUBNAME or BLOCK is omitted, L<C<sort>|/sort SUBNAME LIST>s in | |
15220 | standard string comparison | |
12649 | 15221 | order. If SUBNAME is specified, it gives the name of a subroutine |
12650 | 15222 | that returns an integer less than, equal to, or greater than C<0>, |
12651 | depending on how the elements of the list are to be ordered. (The | |
15223 | depending on how the elements of the list are to be ordered. (The | |
12652 | 15224 | C<< <=> >> and C<cmp> operators are extremely useful in such routines.) |
12653 | 15225 | SUBNAME may be a scalar variable name (unsubscripted), in which case |
12654 | 15226 | the value provides the name of (or a reference to) the actual |
12655 | 15227 | subroutine to use. In place of a SUBNAME, you can provide a BLOCK as |
12656 | 15228 | an anonymous, in-line sort subroutine. |
12657 | 15229 | |
12658 | 15230 | =end original |
12659 | 15231 | |
12660 | SUBNAME や BLOCK を省略すると、標準の | |
15232 | SUBNAME や BLOCK を省略すると、L<C<sort>|/sort SUBNAME LIST> は標準の | |
12661 | 行なわれます。 | |
15233 | 文字列比較の順番で行なわれます。 | |
12662 | 15234 | SUBNAME を指定すると、それは、リストの要素をどのような順番に並べるかに |
12663 | 応じて、負、 | |
15235 | 応じて、負の整数、C<0>、正の整数を返すサブルーチンの名前であると解釈されます。 | |
12664 | (このようなルーチンには、C<< <=> >> 演算子や cmp 演算子が、 | |
15236 | (このようなルーチンには、C<< <=> >> 演算子や C<cmp> 演算子が、 | |
12665 | 15237 | たいへん便利です。) |
12666 | SUBNAME は、スカラ変数名(添字なし)でもよく、 | |
15238 | SUBNAME は、スカラ変数名(添字なし)でもよく、その場合には、その値が使用する | |
12667 | ||
15239 | 実際のサブルーチンの名前(またはそのリファレンス)と解釈されます。 | |
12668 | 名 | |
15240 | SUBNAME の代わりに、無名のインラインソートルーチンとして、BLOCK を | |
12669 | ||
15241 | 書くことができます。 | |
12670 | ソートルーチンとして、BLOCK を書くことができます。 | |
12671 | 15242 | |
12672 | 15243 | =begin original |
12673 | 15244 | |
12674 | 15245 | If the subroutine's prototype is C<($$)>, the elements to be compared are |
12675 | passed by reference in C<@_>, as for a normal subroutine. | |
15246 | passed by reference in L<C<@_>|perlvar/@_>, as for a normal subroutine. | |
12676 | than unprototyped subroutines, where the elements to be | |
15247 | This is slower than unprototyped subroutines, where the elements to be | |
12677 | into the subroutine as the package global variables | |
15248 | compared are passed into the subroutine as the package global variables | |
12678 | below). Note that in the latter case, it | |
15249 | C<$a> and C<$b> (see example below). Note that in the latter case, it | |
12679 | to declare $a and $b as | |
15250 | is usually highly counter-productive to declare C<$a> and C<$b> as | |
15251 | lexicals. | |
12680 | 15252 | |
12681 | 15253 | =end original |
12682 | 15254 | |
12683 | サブルーチンのプロトタイプが C<($$)>の場合、 | |
15255 | サブルーチンのプロトタイプが C<($$)>の場合、比較する要素は通常のサブルーチンと | |
12684 | ||
15256 | 同じように L<C<@_>|perlvar/@_> の中にリファレンスとして渡されます。 | |
12685 | ||
15257 | これはプロトタイプなしのサブルーチンより遅いです; この場合は比較のため | |
12686 | ||
15258 | サブルーチンに渡される二つの要素は、パッケージのグローバル変数 C<$a> と | |
12687 | ||
15259 | C<$b> で渡されます(次の例を参照してください)。 | |
12688 | ||
15260 | 後者の場合、レキシカルに C<$a> と C<$b> を宣言するのは普通とても | |
12689 | ||
15261 | 逆効果になります。 | |
12690 | 後者の場合、レキシカルに $a と $b を宣言するのは普通とても逆効果になります。 | |
12691 | 15262 | |
12692 | 15263 | =begin original |
12693 | 15264 | |
15265 | If the subroutine is an XSUB, the elements to be compared are pushed on | |
15266 | to the stack, the way arguments are usually passed to XSUBs. C<$a> and | |
15267 | C<$b> are not set. | |
15268 | ||
15269 | =end original | |
15270 | ||
15271 | サブルーチンが XSUB の場合、比較される要素は、普通に引数を XSUB に渡す形で、 | |
15272 | スタックにプッシュされます。 | |
15273 | C<$a> と C<$b> は設定されません。 | |
15274 | ||
15275 | =begin original | |
15276 | ||
12694 | 15277 | The values to be compared are always passed by reference and should not |
12695 | 15278 | be modified. |
12696 | 15279 | |
12697 | 15280 | =end original |
12698 | 15281 | |
12699 | ||
15282 | 比較される値はリファレンスによって渡されるので、変更するべきではありません。 | |
12700 | 15283 | |
12701 | 15284 | =begin original |
12702 | 15285 | |
12703 | 15286 | You also cannot exit out of the sort block or subroutine using any of the |
12704 | loop control operators described in L<perlsyn> or with | |
15287 | loop control operators described in L<perlsyn> or with | |
15288 | L<C<goto>|/goto LABEL>. | |
12705 | 15289 | |
12706 | 15290 | =end original |
12707 | 15291 | |
12708 | 15292 | また、ソートブロックやサブルーチンから L<perlsyn> で説明されている |
12709 | ループ制御子や C<goto> を使って抜けてはいけません。 | |
15293 | ループ制御子や L<C<goto>|/goto LABEL> を使って抜けてはいけません。 | |
12710 | 15294 | |
12711 | 15295 | =begin original |
12712 | 15296 | |
12713 | When C<use locale> | |
15297 | When L<C<use locale>|locale> (but not C<use locale ':not_characters'>) | |
15298 | is in effect, C<sort LIST> sorts LIST according to the | |
12714 | 15299 | current collation locale. See L<perllocale>. |
12715 | 15300 | |
12716 | 15301 | =end original |
12717 | 15302 | |
12718 | C<use locale> が有効 | |
15303 | L<C<use locale>|locale> が有効(そして C<use locale ':not_characters'> が | |
12719 | ||
15304 | 有効でない)の場合、C<sort LIST> は LIST を現在の比較ロケールに従って | |
15305 | ソートします。 | |
15306 | L<perllocale> を参照してください。 | |
12720 | 15307 | |
12721 | 15308 | =begin original |
12722 | 15309 | |
12723 | sort | |
15310 | L<C<sort>|/sort SUBNAME LIST> returns aliases into the original list, | |
12724 | variable aliases the list elements. That is, | |
15311 | much as a for loop's index variable aliases the list elements. That is, | |
12725 | list returned by sort | |
15312 | modifying an element of a list returned by L<C<sort>|/sort SUBNAME LIST> | |
15313 | (for example, in a C<foreach>, L<C<map>|/map BLOCK LIST> or | |
15314 | L<C<grep>|/grep BLOCK LIST>) | |
12726 | 15315 | actually modifies the element in the original list. This is usually |
12727 | 15316 | something to be avoided when writing clear code. |
12728 | 15317 | |
12729 | 15318 | =end original |
12730 | 15319 | |
12731 | sort | |
15320 | L<C<sort>|/sort SUBNAME LIST> は元のリストへのエイリアスを返します; | |
12732 | リスト要素へのエイリアスと同様です。 | |
15321 | for ループのインデックス変数がリスト要素へのエイリアスと同様です。 | |
12733 | つまり、sort | |
15322 | つまり、L<C<sort>|/sort SUBNAME LIST> で返されるリストの要素を(例えば、 | |
12734 | C< | |
15323 | C<foreach> や L<C<map>|/map BLOCK LIST> や | |
12735 | ||
15324 | L<C<grep>|/grep BLOCK LIST> で)変更すると、実際に元のリストの要素が | |
15325 | 変更されます。 | |
15326 | これはきれいなコードを書くときには普通は回避されます。 | |
12736 | 15327 | |
12737 | 15328 | =begin original |
12738 | 15329 | |
12739 | 15330 | Perl 5.6 and earlier used a quicksort algorithm to implement sort. |
12740 | That algorithm was not stable | |
15331 | That algorithm was not stable and I<could> go quadratic. (A I<stable> sort | |
12741 | 15332 | preserves the input order of elements that compare equal. Although |
12742 | 15333 | quicksort's run time is O(NlogN) when averaged over all arrays of |
12743 | 15334 | length N, the time can be O(N**2), I<quadratic> behavior, for some |
12744 | 15335 | inputs.) In 5.7, the quicksort implementation was replaced with |
12745 | 15336 | a stable mergesort algorithm whose worst-case behavior is O(NlogN). |
12746 | 15337 | But benchmarks indicated that for some inputs, on some platforms, |
12747 | the original quicksort was faster. 5.8 has a sort pragma for | |
15338 | the original quicksort was faster. 5.8 has a L<sort> pragma for | |
12748 | 15339 | limited control of the sort. Its rather blunt control of the |
12749 | 15340 | underlying algorithm may not persist into future Perls, but the |
12750 | 15341 | ability to characterize the input or output in implementation |
12751 | independent ways quite probably will. | |
15342 | independent ways quite probably will. | |
12752 | 15343 | |
12753 | 15344 | =end original |
12754 | 15345 | |
12755 | 15346 | Perl 5.6 以前ではソートの実装にクイックソートアルゴリズムを使っていました。 |
12756 | このアルゴリズムは安定して | |
15347 | このアルゴリズムは安定しておらず、2 乗の時間が掛かる I<可能性があります>。 | |
12757 | I<可能性があります>。 | |
12758 | 15348 | (I<安定した> ソートは、比較した時に同じ要素の入力順が保存されます。 |
12759 | クイックソートの実行時間は、長さ N の全ての配列の平均では | |
15349 | クイックソートの実行時間は、長さ N の全ての配列の平均では O(NlogN) ですが、 | |
12760 | ||
15350 | 入力によっては O(N**2) という I<2 乗の> 振る舞いをすることがあります。) | |
12761 | ||
15351 | 5.7 では、クイックソートによる実装は、最悪の場合の振る舞いも O(NlogN) である、 | |
12762 | ||
15352 | 安定したマージソートアルゴリズムに置き換えられました。 | |
12763 | ||
15353 | しかし、入力とプラットフォームによっては、ベンチマークはクイックソートの方が | |
12764 | ||
15354 | 速くなります。 | |
12765 | ||
15355 | 5.8 ではソートを限定的に制御できる L<sort> プラグマがあります。 | |
12766 | 5.8 ではソートを限定的に制御できる sort プラグマがあります。 | |
12767 | 15356 | この、アルゴリズムの直接的な制御方法は将来の perl では引き継がれないかも |
12768 | 15357 | しれませんが、実装に依存しない形で入力や出力を性格付ける機能は |
12769 | 15358 | おそらくあります。 |
12770 | L<the sort pragma|sort> を参照してください。 | |
12771 | 15359 | |
12772 | 15360 | =begin original |
12773 | 15361 | |
12774 | 15362 | Examples: |
12775 | 15363 | |
12776 | 15364 | =end original |
12777 | 15365 | |
12778 | 15366 | 例: |
12779 | 15367 | |
12780 | 15368 | # sort lexically |
12781 | @articles = sort @files; | |
15369 | my @articles = sort @files; | |
12782 | ||
12783 | 15371 | # same thing, but with explicit sort routine |
12784 | @articles = sort {$a cmp $b} @files; | |
15372 | my @articles = sort {$a cmp $b} @files; | |
12785 | ||
12786 | 15374 | # now case-insensitively |
12787 | @articles = sort { | |
15375 | my @articles = sort {fc($a) cmp fc($b)} @files; | |
12788 | ||
12789 | 15377 | # same thing in reversed order |
12790 | @articles = sort {$b cmp $a} @files; | |
15378 | my @articles = sort {$b cmp $a} @files; | |
12791 | ||
12792 | 15380 | # sort numerically ascending |
12793 | @articles = sort {$a <=> $b} @files; | |
15381 | my @articles = sort {$a <=> $b} @files; | |
12794 | ||
12795 | 15383 | # sort numerically descending |
12796 | @articles = sort {$b <=> $a} @files; | |
15384 | my @articles = sort {$b <=> $a} @files; | |
12797 | ||
12798 | 15386 | # this sorts the %age hash by value instead of key |
12799 | 15387 | # using an in-line function |
12800 | @eldest = sort { $age{$b} <=> $age{$a} } keys %age; | |
15388 | my @eldest = sort { $age{$b} <=> $age{$a} } keys %age; | |
12801 | ||
12802 | 15390 | # sort using explicit subroutine name |
12803 | 15391 | sub byage { |
12804 | $age{$a} <=> $age{$b}; # presuming numeric | |
15392 | $age{$a} <=> $age{$b}; # presuming numeric | |
12805 | 15393 | } |
12806 | @sortedclass = sort byage @class; | |
15394 | my @sortedclass = sort byage @class; | |
12807 | ||
12808 | 15396 | sub backwards { $b cmp $a } |
12809 | @harry = qw(dog cat x Cain Abel); | |
15397 | my @harry = qw(dog cat x Cain Abel); | |
12810 | @george = qw(gone chased yz Punished Axed); | |
15398 | my @george = qw(gone chased yz Punished Axed); | |
12811 | 15399 | print sort @harry; |
12812 | 15400 | # prints AbelCaincatdogx |
12813 | 15401 | print sort backwards @harry; |
12814 | 15402 | # prints xdogcatCainAbel |
12815 | 15403 | print sort @george, 'to', @harry; |
12816 | 15404 | # prints AbelAxedCainPunishedcatchaseddoggonetoxyz |
12817 | 15405 | |
12818 | 15406 | # inefficiently sort by descending numeric compare using |
12819 | 15407 | # the first integer after the first = sign, or the |
12820 | 15408 | # whole record case-insensitively otherwise |
12821 | 15409 | |
12822 | 15410 | my @new = sort { |
12823 | 15411 | ($b =~ /=(\d+)/)[0] <=> ($a =~ /=(\d+)/)[0] |
12824 | || | |
15412 | || | |
12825 | | |
15413 | fc($a) cmp fc($b) | |
12826 | 15414 | } @old; |
12827 | 15415 | |
12828 | 15416 | # same thing, but much more efficiently; |
12829 | 15417 | # we'll build auxiliary indices instead |
12830 | 15418 | # for speed |
12831 | my @nums | |
15419 | my (@nums, @caps); | |
12832 | 15420 | for (@old) { |
12833 | 15421 | push @nums, ( /=(\d+)/ ? $1 : undef ); |
12834 | push @caps, | |
15422 | push @caps, fc($_); | |
12835 | 15423 | } |
12836 | 15424 | |
12837 | 15425 | my @new = @old[ sort { |
12838 | $nums[$b] <=> $nums[$a] | |
15426 | $nums[$b] <=> $nums[$a] | |
12839 | || | |
15427 | || | |
12840 | $caps[$a] cmp $caps[$b] | |
15428 | $caps[$a] cmp $caps[$b] | |
12841 | } 0..$#old | |
15429 | } 0..$#old | |
12842 | ]; | |
15430 | ]; | |
12843 | 15431 | |
12844 | 15432 | # same thing, but without any temps |
12845 | @new = map { $_->[0] } | |
15433 | my @new = map { $_->[0] } | |
12846 | 15434 | sort { $b->[1] <=> $a->[1] |
12847 | || | |
15435 | || | |
12848 | $a->[2] cmp $b->[2] | |
15436 | $a->[2] cmp $b->[2] | |
12849 | } map { [$_, /=(\d+)/, | |
15437 | } map { [$_, /=(\d+)/, fc($_)] } @old; | |
12850 | 15438 | |
12851 | 15439 | # using a prototype allows you to use any comparison subroutine |
12852 | 15440 | # as a sort subroutine (including other package's subroutines) |
12853 | package | |
15441 | package Other; | |
12854 | sub backwards ($$) { $_[1] cmp $_[0]; } # $a and $b are | |
15442 | sub backwards ($$) { $_[1] cmp $_[0]; } # $a and $b are | |
12855 | ||
15443 | # not set here | |
12856 | 15444 | package main; |
12857 | @new = sort | |
15445 | my @new = sort Other::backwards @old; | |
12858 | ||
12859 | 15447 | # guarantee stability, regardless of algorithm |
12860 | 15448 | use sort 'stable'; |
12861 | @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old; | |
15449 | my @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old; | |
12862 | ||
12863 | 15451 | # force use of mergesort (not portable outside Perl 5.8) |
12864 | 15452 | use sort '_mergesort'; # note discouraging _ |
12865 | @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old; | |
15453 | my @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old; | |
12866 | 15454 | |
12867 | 15455 | =begin original |
12868 | 15456 | |
12869 | 15457 | Warning: syntactical care is required when sorting the list returned from |
12870 | a function. If you want to sort the list returned by the function call | |
15458 | a function. If you want to sort the list returned by the function call | |
12871 | 15459 | C<find_records(@key)>, you can use: |
12872 | 15460 | |
12873 | 15461 | =end original |
12874 | 15462 | |
12875 | 15463 | 警告: 関数からかえされたリストをソートするときには文法上の注意が必要です。 |
12876 | 15464 | 関数呼び出し C<find_records(@key)> から返されたリストをソートしたい場合、 |
12877 | 15465 | 以下のように出来ます: |
12878 | 15466 | |
12879 | @contact = sort { $a cmp $b } find_records @key; | |
15467 | my @contact = sort { $a cmp $b } find_records @key; | |
12880 | @contact = sort +find_records(@key); | |
15468 | my @contact = sort +find_records(@key); | |
12881 | @contact = sort &find_records(@key); | |
15469 | my @contact = sort &find_records(@key); | |
12882 | @contact = sort(find_records(@key)); | |
15470 | my @contact = sort(find_records(@key)); | |
12883 | 15471 | |
12884 | 15472 | =begin original |
12885 | 15473 | |
12886 | If instead you want to sort the array @key with the comparison routine | |
15474 | If instead you want to sort the array C<@key> with the comparison routine | |
12887 | 15475 | C<find_records()> then you can use: |
12888 | 15476 | |
12889 | 15477 | =end original |
12890 | 15478 | |
12891 | 一方、配列 @key を比較ルーチン C<find_records()> でソートしたい場合は、 | |
15479 | 一方、配列 C<@key> を比較ルーチン C<find_records()> でソートしたい場合は、 | |
12892 | 15480 | 以下のように出来ます: |
12893 | 15481 | |
12894 | @contact = sort { find_records() } @key; | |
15482 | my @contact = sort { find_records() } @key; | |
12895 | @contact = sort find_records(@key); | |
15483 | my @contact = sort find_records(@key); | |
12896 | @contact = sort(find_records @key); | |
15484 | my @contact = sort(find_records @key); | |
12897 | @contact = sort(find_records (@key)); | |
15485 | my @contact = sort(find_records (@key)); | |
12898 | 15486 | |
12899 | 15487 | =begin original |
12900 | 15488 | |
12901 | ||
15489 | You I<must not> declare C<$a> | |
12902 | and $b as lexicals. They are package globals. That means | |
15490 | and C<$b> as lexicals. They are package globals. That means | |
12903 | 15491 | that if you're in the C<main> package and type |
12904 | 15492 | |
12905 | 15493 | =end original |
12906 | 15494 | |
12907 | ||
15495 | C<$a> と C<$b> をレキシカルとして宣言しては I<いけません>。 | |
12908 | 宣言しては I<いけません>。 | |
12909 | 15496 | これはパッケージグローバルです。 |
12910 | 15497 | つまり、C<main> パッケージで以下のように書いた場合: |
12911 | 15498 | |
12912 | @articles = sort {$b <=> $a} @files; | |
15499 | my @articles = sort {$b <=> $a} @files; | |
12913 | 15500 | |
12914 | 15501 | =begin original |
12915 | 15502 | |
12916 | 15503 | then C<$a> and C<$b> are C<$main::a> and C<$main::b> (or C<$::a> and C<$::b>), |
12917 | 15504 | but if you're in the C<FooPack> package, it's the same as typing |
12918 | 15505 | |
12919 | 15506 | =end original |
12920 | 15507 | |
12921 | 15508 | C<$a> と C<$b> は C<$main::a> と C<$main::b> (または C<$::a> と C<$::b>) を |
12922 | 15509 | 意味しますが、C<FooPack> パッケージ内の場合、これは以下と同じになります: |
12923 | 15510 | |
12924 | @articles = sort {$FooPack::b <=> $FooPack::a} @files; | |
15511 | my @articles = sort {$FooPack::b <=> $FooPack::a} @files; | |
12925 | 15512 | |
12926 | 15513 | =begin original |
12927 | 15514 | |
12928 | 15515 | The comparison function is required to behave. If it returns |
12929 | 15516 | inconsistent results (sometimes saying C<$x[1]> is less than C<$x[2]> and |
12930 | 15517 | sometimes saying the opposite, for example) the results are not |
12931 | 15518 | well-defined. |
12932 | 15519 | |
12933 | 15520 | =end original |
12934 | 15521 | |
12935 | 15522 | 比較関数は一貫した振る舞いをすることが求められます。 |
12936 | 15523 | 一貫しない結果を返す(例えば、あるときは C<$x[1]> が C<$x[2]> より |
12937 | 15524 | 小さいと返し、またあるときは逆を返す)場合、結果は未定義です。 |
12938 | 15525 | |
12939 | 15526 | =begin original |
12940 | 15527 | |
12941 | Because C<< <=> >> returns C<undef> when either operand | |
15528 | Because C<< <=> >> returns L<C<undef>|/undef EXPR> when either operand | |
12942 | (not-a-number), | |
15529 | is C<NaN> (not-a-number), be careful when sorting with a | |
12943 | result of a comparison is defined, be careful when sorting with a | |
12944 | 15530 | comparison function like C<< $a <=> $b >> any lists that might contain a |
12945 | 15531 | C<NaN>. The following example takes advantage that C<NaN != NaN> to |
12946 | 15532 | eliminate any C<NaN>s from the input list. |
12947 | 15533 | |
12948 | 15534 | =end original |
12949 | 15535 | |
12950 | 15536 | C<< <=> >> はどちらかのオペランドが C<NaN> (not-a-number) のときに |
12951 | C<undef> を返 | |
15537 | L<C<undef>|/undef EXPR> を返すので、C<< $a <=> $b >> といった比較関数で | |
12952 | ||
15538 | ソートする場合はリストに C<NaN> が含まれないように注意してください。 | |
12953 | 含まれないように注意してください。 | |
12954 | 15539 | 以下の例は 入力リストから C<NaN> を取り除くために C<NaN != NaN> という性質を |
12955 | 15540 | 利用しています。 |
12956 | 15541 | |
12957 | @result = sort { $a <=> $b } grep { $_ == $_ } @input; | |
15542 | my @result = sort { $a <=> $b } grep { $_ == $_ } @input; | |
12958 | 15543 | |
12959 | =item splice ARRAY | |
15544 | =item splice ARRAY,OFFSET,LENGTH,LIST | |
12960 | 15545 | X<splice> |
12961 | 15546 | |
12962 | =item splice ARRAY | |
15547 | =item splice ARRAY,OFFSET,LENGTH | |
12963 | 15548 | |
12964 | =item splice ARRAY | |
15549 | =item splice ARRAY,OFFSET | |
12965 | 15550 | |
12966 | =item splice ARRAY | |
15551 | =item splice ARRAY | |
12967 | 15552 | |
15553 | =for Pod::Functions add or remove elements anywhere in an array | |
15554 | ||
12968 | 15555 | =begin original |
12969 | 15556 | |
12970 | 15557 | Removes the elements designated by OFFSET and LENGTH from an array, and |
12971 | 15558 | replaces them with the elements of LIST, if any. In list context, |
12972 | 15559 | returns the elements removed from the array. In scalar context, |
12973 | returns the last element removed, or C<undef> if no | |
15560 | returns the last element removed, or L<C<undef>|/undef EXPR> if no | |
15561 | elements are | |
12974 | 15562 | removed. The array grows or shrinks as necessary. |
12975 | 15563 | If OFFSET is negative then it starts that far from the end of the array. |
12976 | 15564 | If LENGTH is omitted, removes everything from OFFSET onward. |
12977 | 15565 | If LENGTH is negative, removes the elements from OFFSET onward |
12978 | 15566 | except for -LENGTH elements at the end of the array. |
12979 | If both OFFSET and LENGTH are omitted, removes everything. If OFFSET is | |
15567 | If both OFFSET and LENGTH are omitted, removes everything. If OFFSET is | |
12980 | past the end of the array, Perl issues a warning, | |
15568 | past the end of the array and a LENGTH was provided, Perl issues a warning, | |
12981 | end of the array. | |
15569 | and splices at the end of the array. | |
12982 | 15570 | |
12983 | 15571 | =end original |
12984 | 15572 | |
12985 | 15573 | ARRAY から OFFSET、LENGTH で指定される要素を取り除き、 |
12986 | 15574 | LIST があれば、それを代わりに挿入します。 |
12987 | 15575 | リストコンテキストでは、配列から取り除かれた要素を返します。 |
12988 | スカラコンテキストでは、取り除かれた最後の要素を返します | |
15576 | スカラコンテキストでは、取り除かれた最後の要素を返します; 要素が | |
12989 | ||
15577 | 取り除かれなかった場合は L<C<undef>|/undef EXPR> を返します。 | |
12990 | 15578 | 配列は、必要に応じて、大きくなったり、小さくなったりします。 |
12991 | 15579 | OFFSET が負の数の場合は、配列の最後からの距離を示します。 |
12992 | 15580 | LENGTH が省略されると、OFFSET 以降のすべての要素を取り除きます。 |
12993 | 15581 | LENGTH が負の数の場合は、OFFSET から前方へ、配列の最後から -LENGTH 要素を |
12994 | 15582 | 除いて取り除きます。 |
12995 | 15583 | OFFSET と LENGTH の両方が省略されると、全ての要素を取り除きます。 |
12996 | OFFSET が配列の最後より後ろ | |
15584 | OFFSET が配列の最後より後ろで、 LENGTH が指定されていると、Perl は警告を出し、 | |
12997 | 処理します。 | |
15585 | 配列の最後に対して処理します。 | |
12998 | 15586 | |
12999 | 15587 | =begin original |
13000 | 15588 | |
13001 | The following equivalences hold (assuming C<< $ | |
15589 | The following equivalences hold (assuming C<< $#a >= $i >> ) | |
13002 | 15590 | |
13003 | 15591 | =end original |
13004 | 15592 | |
13005 | 以下は、(C<< $ | |
15593 | 以下は、(C<< $#a >= $i >> と仮定すると) それぞれ、等価です。 | |
13006 | 15594 | |
13007 | 15595 | push(@a,$x,$y) splice(@a,@a,0,$x,$y) |
13008 | 15596 | pop(@a) splice(@a,-1) |
13009 | 15597 | shift(@a) splice(@a,0,1) |
13010 | 15598 | unshift(@a,$x,$y) splice(@a,0,0,$x,$y) |
13011 | 15599 | $a[$i] = $y splice(@a,$i,1,$y) |
13012 | 15600 | |
13013 | 15601 | =begin original |
13014 | 15602 | |
13015 | ||
15603 | L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> can be used, for example, | |
15604 | to implement n-ary queue processing: | |
13016 | 15605 | |
13017 | 15606 | =end original |
13018 | 15607 | |
13019 | ||
15608 | L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> は、例えば、n-ary キュー処理の | |
15609 | 実装に使えます: | |
13020 | 15610 | |
13021 | sub a | |
15611 | sub nary_print { | |
13022 | | |
15612 | my $n = shift; | |
13023 | | |
15613 | while (my @next_n = splice @_, 0, $n) { | |
13024 | | |
15614 | say join q{ -- }, @next_n; | |
13025 | | |
15615 | } | |
13026 | return 0 if pop(@a) ne pop(@b); | |
13027 | } | |
13028 | return 1; | |
13029 | 15616 | } |
13030 | if (&aeq($len,@foo[1..$len],0+@bar,@bar)) { ... } | |
13031 | 15617 | |
15618 | nary_print(3, qw(a b c d e f g h)); | |
15619 | # prints: | |
15620 | # a -- b -- c | |
15621 | # d -- e -- f | |
15622 | # g -- h | |
15623 | ||
13032 | 15624 | =begin original |
13033 | 15625 | |
13034 | Starting with Perl 5.14, | |
15626 | Starting with Perl 5.14, an experimental feature allowed | |
13035 | ||
15627 | L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> to take a | |
13036 | ||
15628 | scalar expression. This experiment has been deemed unsuccessful, and was | |
13037 | ||
15629 | removed as of Perl 5.24. | |
13038 | 15630 | |
13039 | 15631 | =end original |
13040 | 15632 | |
13041 | Perl 5.14 から、C<splice> | |
15633 | Perl 5.14 から、L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> がスカラ式を | |
13042 | こ | |
15634 | 取ることが出来るという実験的機能がありました。 | |
13043 | ||
15635 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 | |
13044 | C<splice> のこの動作は高度に実験的であると考えられています。 | |
13045 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 | |
13046 | 15636 | |
13047 | 15637 | =item split /PATTERN/,EXPR,LIMIT |
13048 | 15638 | X<split> |
13049 | 15639 | |
13050 | 15640 | =item split /PATTERN/,EXPR |
13051 | 15641 | |
13052 | 15642 | =item split /PATTERN/ |
13053 | 15643 | |
13054 | 15644 | =item split |
13055 | 15645 | |
15646 | =for Pod::Functions split up a string using a regexp delimiter | |
15647 | ||
13056 | 15648 | =begin original |
13057 | 15649 | |
13058 | Splits the string EXPR into a list of strings and returns th | |
15650 | Splits the string EXPR into a list of strings and returns the | |
13059 | ||
15651 | list in list context, or the size of the list in scalar context. | |
13060 | deleted. (If all fields are empty, they are considered to be trailing.) | |
13061 | 15652 | |
13062 | 15653 | =end original |
13063 | 15654 | |
13064 | 文字列 EXPR を文字列のリストに分割して、リストを | |
15655 | 文字列 EXPR を文字列のリストに分割して、リストコンテキストではそのリストを | |
13065 | ||
15656 | 返し、スカラコンテキストではリストの大きさを返します。 | |
13066 | (全てのフィールドが空の場合、これらは末尾であるとして扱われます。) | |
13067 | 15657 | |
13068 | 15658 | =begin original |
13069 | 15659 | |
13070 | In s | |
15660 | If only PATTERN is given, EXPR defaults to L<C<$_>|perlvar/$_>. | |
13071 | 15661 | |
13072 | 15662 | =end original |
13073 | 15663 | |
13074 | ||
15664 | PATTERN のみが与えられた場合、EXPR のデフォルトは L<C<$_>|perlvar/$_> です。 | |
13075 | 15665 | |
13076 | 15666 | =begin original |
13077 | 15667 | |
13078 | ||
15668 | Anything in EXPR that matches PATTERN is taken to be a separator | |
13079 | ||
15669 | that separates the EXPR into substrings (called "I<fields>") that | |
13080 | ||
15670 | do B<not> include the separator. Note that a separator may be | |
13081 | tha | |
15671 | longer than one character or even have no characters at all (the | |
15672 | empty string, which is a zero-width match). | |
13082 | 15673 | |
13083 | 15674 | =end original |
13084 | 15675 | |
13085 | EXPR | |
15676 | EXPR の中で PATTERN にマッチングするものは何でも EXPR を("I<fields>" と | |
13086 | ||
15677 | 呼ばれる)セパレータを B<含まない> 部分文字列に分割するための | |
13087 | ||
15678 | セパレータとなります。 | |
13088 | ||
15679 | セパレータは一文字より長くてもよく、全く文字がなくてもよい(空文字列は | |
13089 | ||
15680 | ゼロ幅マッチングです)ということに注意してください。 | |
13090 | 15681 | |
13091 | 15682 | =begin original |
13092 | 15683 | |
13093 | ||
15684 | The PATTERN need not be constant; an expression may be used | |
13094 | o | |
15685 | to specify a pattern that varies at runtime. | |
13095 | fields returned depends on the number of times PATTERN matches within | |
13096 | EXPR. If LIMIT is unspecified or zero, trailing null fields are | |
13097 | stripped (which potential users of C<pop> would do well to remember). | |
13098 | If LIMIT is negative, it is treated as if an arbitrarily large LIMIT | |
13099 | had been specified. Note that splitting an EXPR that evaluates to the | |
13100 | empty string always returns the empty list, regardless of the LIMIT | |
13101 | specified. | |
13102 | 15686 | |
13103 | 15687 | =end original |
13104 | 15688 | |
13105 | ||
15689 | PATTERN は定数である必要はありません; 実行時に変更されるパターンを | |
13106 | ||
15690 | 指定するために式を使えます。 | |
13107 | マッチするかに依存します。 | |
13108 | LIMIT を指定しないかゼロなら、末尾の空フィールドを捨ててしまいます | |
13109 | (C<pop> を行なうときには気を付けないといけません)。 | |
13110 | LIMIT が負ならば、LIMIT に任意の大きな数を指定したのと同じことになります。 | |
13111 | 空文字列に評価される EXPR を分割する場合、LIMIT での指定に関わらず | |
13112 | 常に空のリストが返ることに注意してください。 | |
13113 | 15691 | |
13114 | 15692 | =begin original |
13115 | 15693 | |
13116 | A | |
15694 | If PATTERN matches the empty string, the EXPR is split at the match | |
13117 | ||
15695 | position (between characters). As an example, the following: | |
13118 | matching the epmty string), splits EXPR into individual | |
13119 | characters. For example: | |
13120 | 15696 | |
13121 | 15697 | =end original |
13122 | 15698 | |
13123 | 空文字列にマッチする | |
15699 | PATTERN が空文字列にマッチングする場合、EXPR はマッチング位置 | |
13124 | ||
15700 | (文字の間)で分割されます。 | |
13125 | ||
15701 | 例えば、以下のものは: | |
13126 | 例えば: | |
13127 | 15702 | |
13128 | print join(':', split(/ | |
15703 | print join(':', split(/b/, 'abc')), "\n"; | |
13129 | 15704 | |
13130 | 15705 | =begin original |
13131 | 15706 | |
13132 | produce | |
15707 | uses the C<b> in C<'abc'> as a separator to produce the output C<a:c>. | |
15708 | However, this: | |
13133 | 15709 | |
13134 | 15710 | =end original |
13135 | 15711 | |
13136 | ||
15712 | C<'abc'> の C<b> をセパレータとして使って出力 C<a:c> を生成します。 | |
15713 | しかし、これは: | |
13137 | 15714 | |
15715 | print join(':', split(//, 'abc')), "\n"; | |
15716 | ||
13138 | 15717 | =begin original |
13139 | 15718 | |
13140 | ||
15719 | uses empty string matches as separators to produce the output | |
13141 | ||
15720 | C<a:b:c>; thus, the empty string may be used to split EXPR into a | |
13142 | of | |
15721 | list of its component characters. | |
13143 | a string into individual characters, the following: | |
13144 | 15722 | |
13145 | 15723 | =end original |
13146 | 15724 | |
13147 | ||
15725 | 空文字列マッチングをセパレータとして使って出力 C<a:b:c> を生成します; 従って、 | |
13148 | ||
15726 | 空文字列は EXPR を構成する文字のリストに分割するために使われます。 | |
13149 | 使用法と混乱しないようにしてください。 | |
13150 | それで、文字列を個々の文字に分割する場合は、以下のようにすると: | |
13151 | 15727 | |
13152 | ||
15728 | =begin original | |
13153 | 15729 | |
15730 | As a special case for L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>, | |
15731 | the empty pattern given in | |
15732 | L<match operator|perlop/"m/PATTERN/msixpodualngc"> syntax (C<//>) | |
15733 | specifically matches the empty string, which is contrary to its usual | |
15734 | interpretation as the last successful match. | |
15735 | ||
15736 | =end original | |
15737 | ||
15738 | L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> の特殊な場合として、 | |
15739 | L<マッチング演算子|perlop/"m/PATTERN/msixpodualngc"> 文法で与えられた | |
15740 | 空パターン (C<//>) は特に空文字列にマッチングし、最後に成功した | |
15741 | マッチングという普通の解釈と異なります。 | |
15742 | ||
13154 | 15743 | =begin original |
13155 | 15744 | |
13156 | ||
15745 | If PATTERN is C</^/>, then it is treated as if it used the | |
15746 | L<multiline modifier|perlreref/OPERATORS> (C</^/m>), since it | |
15747 | isn't much use otherwise. | |
13157 | 15748 | |
13158 | 15749 | =end original |
13159 | 15750 | |
13160 | ||
15751 | PATTERN が C</^/> の場合、L<複数行修飾子|perlreref/OPERATORS> | |
15752 | (C</^/m>) が使われたかのように扱われます; そうでなければほとんど | |
15753 | 使えないからです。 | |
13161 | 15754 | |
13162 | 15755 | =begin original |
13163 | 15756 | |
13164 | ||
15757 | As another special case, | |
13165 | ||
15758 | L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> emulates the default | |
13166 | ||
15759 | behavior of the | |
15760 | command line tool B<awk> when the PATTERN is either omitted or a | |
15761 | string composed of a single space character (such as S<C<' '>> or | |
15762 | S<C<"\x20">>, but not e.g. S<C</ />>). In this case, any leading | |
15763 | whitespace in EXPR is removed before splitting occurs, and the PATTERN is | |
15764 | instead treated as if it were C</\s+/>; in particular, this means that | |
15765 | I<any> contiguous whitespace (not just a single space character) is used as | |
15766 | a separator. However, this special treatment can be avoided by specifying | |
15767 | the pattern S<C</ />> instead of the string S<C<" ">>, thereby allowing | |
15768 | only a single space character to be a separator. In earlier Perls this | |
15769 | special case was restricted to the use of a plain S<C<" ">> as the | |
15770 | pattern argument to split; in Perl 5.18.0 and later this special case is | |
15771 | triggered by any expression which evaluates to the simple string S<C<" ">>. | |
13167 | 15772 | |
13168 | 15773 | =end original |
13169 | 15774 | |
13170 | ||
15775 | もう一つの特別な場合として、 | |
13171 | ||
15776 | L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> は | |
13172 | ||
15777 | PATTERN が省略されるか単一のスペース文字からなる文字列 (つまり例えば | |
13173 | ||
15778 | S<C</ />> ではなく S<C<' '>> や S<C<"\x20">>) の場合、コマンドラインツール | |
15779 | B<awk> のデフォルトの振る舞いをエミュレートします。 | |
15780 | この場合、EXPR の先頭の空白は分割を行う前に削除され、PATTERN は | |
15781 | C</\s+/> であったかのように扱われます; 特に、これは (単に単一の | |
15782 | スペース文字ではなく) I<あらゆる> 連続した空白がセパレータとして | |
15783 | 使われるということです。 | |
15784 | しかし、この特別の扱いは文字列 S<C<" ">> の代わりにパターン S<C</ />> を | |
15785 | 指定することで回避でき、それによってセパレータとして単一の | |
15786 | スペース文字のみが使われます。 | |
15787 | 以前の Perl ではこの特別な場合は split のパターン引数として単に S<C<" ">> を | |
15788 | 使った場合に制限されていました; Perl 5.18.0 以降では、この特別な場合は | |
15789 | 単純な文字列 S<C<" ">> と評価される任意の式によって引き起こされます。 | |
13174 | 15790 | |
13175 | ||
15791 | =begin original | |
13176 | 15792 | |
15793 | If omitted, PATTERN defaults to a single space, S<C<" ">>, triggering | |
15794 | the previously described I<awk> emulation. | |
15795 | ||
15796 | =end original | |
15797 | ||
15798 | 省略されると、PATTERN のデフォルトは単一のスペース S<C<" ">> になり、 | |
15799 | 先に記述した I<awk> エミュレーションを起動します。 | |
15800 | ||
13177 | 15801 | =begin original |
13178 | 15802 | |
13179 | p | |
15803 | If LIMIT is specified and positive, it represents the maximum number | |
13180 | ||
15804 | of fields into which the EXPR may be split; in other words, LIMIT is | |
13181 | ||
15805 | one greater than the maximum number of times EXPR may be split. Thus, | |
13182 | ||
15806 | the LIMIT value C<1> means that EXPR may be split a maximum of zero | |
15807 | times, producing a maximum of one field (namely, the entire value of | |
15808 | EXPR). For instance: | |
13183 | 15809 | |
13184 | 15810 | =end original |
13185 | 15811 | |
13186 | ||
15812 | LIMIT が指定された正数の場合、EXPR が分割されるフィールドの最大数を | |
13187 | ||
15813 | 表現します; 言い換えると、 LIMIT は EXPR が分割される数より一つ大きい数です。 | |
13188 | ||
15814 | 従って、LIMIT の値 C<1> は EXPR が最大 0 回分割されるということで、 | |
13189 | 生成 | |
15815 | 最大で一つのフィールドを生成します (言い換えると、EXPR 全体の値です)。 | |
13190 | 15816 | 例えば: |
13191 | 15817 | |
13192 | print join(':', split(//, | |
15818 | print join(':', split(//, 'abc', 1)), "\n"; | |
13193 | print join(':', split(/\W/, 'hi there!', -1)), "\n"; | |
13194 | 15819 | |
13195 | 15820 | =begin original |
13196 | 15821 | |
13197 | produce the output | |
15822 | produces the output C<abc>, and this: | |
13198 | both with an empty trailing field. | |
13199 | 15823 | |
13200 | 15824 | =end original |
13201 | 15825 | |
13202 | これ | |
15826 | これは C<abc> を出力し、次のものは: | |
13203 | 両方とも末尾に空フィールドが付きます。 | |
13204 | 15827 | |
15828 | print join(':', split(//, 'abc', 2)), "\n"; | |
15829 | ||
13205 | 15830 | =begin original |
13206 | 15831 | |
13207 | ||
15832 | produces the output C<a:bc>, and each of these: | |
13208 | 15833 | |
13209 | 15834 | =end original |
13210 | 15835 | |
13211 | ||
15836 | C<a:bc> を出力し、以下のものそれぞれは: | |
13212 | 15837 | |
13213 | | |
15838 | print join(':', split(//, 'abc', 3)), "\n"; | |
15839 | print join(':', split(//, 'abc', 4)), "\n"; | |
13214 | 15840 | |
13215 | 15841 | =begin original |
13216 | 15842 | |
13217 | ||
15843 | produces the output C<a:b:c>. | |
13218 | a LIMIT one larger than the number of variables in the list, to avoid | |
13219 | unnecessary work. For the list above LIMIT would have been 4 by | |
13220 | default. In time critical applications it behooves you not to split | |
13221 | into more fields than you really need. | |
13222 | 15844 | |
13223 | 15845 | =end original |
13224 | 15846 | |
13225 | ||
15847 | C<a:b:c> を出力します。 | |
13226 | 無駄な仕事を避けるため、そのリストの変数の数より、1 つだけ大きい | |
13227 | LIMIT が与えられたものとして処理を行ないます。 | |
13228 | 上のリストの場合には、LIMIT はデフォルトで 4 になります。 | |
13229 | 時間が問題となるアプリケーションでは、 | |
13230 | 必要以上のフィールドに分けないようにする必要があります。 | |
13231 | 15848 | |
13232 | 15849 | =begin original |
13233 | 15850 | |
13234 | If | |
15851 | If LIMIT is negative, it is treated as if it were instead arbitrarily | |
13235 | ||
15852 | large; as many fields as possible are produced. | |
13236 | 15853 | |
13237 | 15854 | =end original |
13238 | 15855 | |
13239 | ||
15856 | LIMIT が負数なら、非常に大きい数であるかのように扱われます; できるだけ多くの | |
13240 | ||
15857 | フィールドが生成されます。 | |
13241 | 15858 | |
13242 | ||
15859 | =begin original | |
13243 | 15860 | |
15861 | If LIMIT is omitted (or, equivalently, zero), then it is usually | |
15862 | treated as if it were instead negative but with the exception that | |
15863 | trailing empty fields are stripped (empty leading fields are always | |
15864 | preserved); if all fields are empty, then all fields are considered to | |
15865 | be trailing (and are thus stripped in this case). Thus, the following: | |
15866 | ||
15867 | =end original | |
15868 | ||
15869 | LIMIT が省略されると(あるいは等価な 0 なら)、普通は負数が指定されたかのように | |
15870 | 動作しますが、末尾の空フィールドは取り除かれるという例外があります | |
15871 | (先頭の空フィールドは常に保存されます); もし全てのフィールドが空なら、 | |
15872 | 全てのフィールドが末尾として扱われます(そしてこの場合取り除かれます)。 | |
15873 | 従って、以下のようにすると: | |
15874 | ||
15875 | print join(':', split(/,/, 'a,b,c,,,')), "\n"; | |
15876 | ||
13244 | 15877 | =begin original |
13245 | 15878 | |
13246 | produces the | |
15879 | produces the output C<a:b:c>, but the following: | |
13247 | 15880 | |
13248 | 15881 | =end original |
13249 | 15882 | |
13250 | ||
15883 | 出力 C<a:b:c> を生成しますが、以下のようにすると: | |
13251 | 15884 | |
13252 | | |
15885 | print join(':', split(/,/, 'a,b,c,,,', -1)), "\n"; | |
13253 | 15886 | |
13254 | 15887 | =begin original |
13255 | 15888 | |
13256 | ||
15889 | produces the output C<a:b:c:::>. | |
13257 | you could split it up into fields and their values this way: | |
13258 | 15890 | |
13259 | 15891 | =end original |
13260 | 15892 | |
13261 | ||
15893 | 出力 C<a:b:c:::> を生成します。 | |
13262 | 以下のようにしてフィールドとその値に分割できます: | |
13263 | 15894 | |
13264 | ||
15895 | =begin original | |
13265 | %hdrs = (UNIX_FROM => split /^(\S*?):\s*/m, $header); | |
13266 | 15896 | |
15897 | In time-critical applications, it is worthwhile to avoid splitting | |
15898 | into more fields than necessary. Thus, when assigning to a list, | |
15899 | if LIMIT is omitted (or zero), then LIMIT is treated as though it | |
15900 | were one larger than the number of variables in the list; for the | |
15901 | following, LIMIT is implicitly 3: | |
15902 | ||
15903 | =end original | |
15904 | ||
15905 | 時間に厳しいアプリケーションでは、必要でないフィールドの分割を避けるのは | |
15906 | 価値があります。 | |
15907 | 従って、リストに代入される場合に、LIMIT が省略される(または 0)と、 | |
15908 | LIMIT は リストにある変数の数より一つ大きい数のように扱われます; | |
15909 | 次の場合、LIMIT は暗黙に 3 になります: | |
15910 | ||
15911 | my ($login, $passwd) = split(/:/); | |
15912 | ||
13267 | 15913 | =begin original |
13268 | 15914 | |
13269 | ||
15915 | Note that splitting an EXPR that evaluates to the empty string always | |
13270 | p | |
15916 | produces zero fields, regardless of the LIMIT specified. | |
13271 | use C</$variable/o>.) | |
13272 | 15917 | |
13273 | 15918 | =end original |
13274 | 15919 | |
13275 | ||
15920 | LIMIT の指定に関わらず、空文字列に評価される EXPR を分割すると常に 0 個の | |
13276 | ||
15921 | フィールドを生成することに注意してください。 | |
13277 | 15922 | |
13278 | 15923 | =begin original |
13279 | 15924 | |
13280 | A | |
15925 | An empty leading field is produced when there is a positive-width | |
13281 | ||
15926 | match at the beginning of EXPR. For instance: | |
13282 | be used to emulate B<awk>'s default behavior, whereas S<C<split(/ /)>> | |
13283 | will give you as many initial null fields (empty string) as there are leading spaces. | |
13284 | A C<split> on C</\s+/> is like a S<C<split(' ')>> except that any leading | |
13285 | whitespace produces a null first field. A C<split> with no arguments | |
13286 | really does a S<C<split(' ', $_)>> internally. | |
13287 | 15927 | |
13288 | 15928 | =end original |
13289 | 15929 | |
13290 | ||
15930 | EXPR の先頭で正数幅でマッチングしたときには先頭に空のフィールドが | |
13291 | ||
15931 | 生成されます。 | |
13292 | ||
15932 | 例えば: | |
13293 | 使うことができ、S<C<split(/ /)>> は行頭のスペースの数に応じた空フィールド | |
13294 | (空文字列)ができます。 | |
13295 | C<split /\s+/> は S<C<split(' ')>> と同様ですが、 | |
13296 | 先頭の空白は先頭の空フィールドとなります。 | |
13297 | 引数なしの C<split> は内部的には S<C<split(' ', $_)>> を実行します。 | |
13298 | 15933 | |
15934 | print join(':', split(/ /, ' abc')), "\n"; | |
15935 | ||
13299 | 15936 | =begin original |
13300 | 15937 | |
13301 | ||
15938 | produces the output C<:abc>. However, a zero-width match at the | |
13302 | ||
15939 | beginning of EXPR never produces an empty field, so that: | |
13303 | 15940 | |
13304 | 15941 | =end original |
13305 | 15942 | |
13306 | ||
15943 | これは出力 C<:abc> を生成します。 | |
13307 | ||
15944 | しかし、EXPR の先頭でのゼロ幅マッチングは決して空フィールドを生成しないので: | |
13308 | 15945 | |
15946 | print join(':', split(//, ' abc')); | |
15947 | ||
13309 | 15948 | =begin original |
13310 | 15949 | |
13311 | ||
15950 | produces the output S<C< :a:b:c>> (rather than S<C<: :a:b:c>>). | |
13312 | 15951 | |
13313 | 15952 | =end original |
13314 | 15953 | |
13315 | ||
15954 | これは(S<C<: :a:b:c>> ではなく)出力 S<C< :a:b:c>> を生成します。 | |
13316 | 15955 | |
13317 | ||
15956 | =begin original | |
13318 | while (<PASSWD>) { | |
13319 | chomp; | |
13320 | ($login, $passwd, $uid, $gid, | |
13321 | $gcos, $home, $shell) = split(/:/); | |
13322 | #... | |
13323 | } | |
13324 | 15957 | |
15958 | An empty trailing field, on the other hand, is produced when there is a | |
15959 | match at the end of EXPR, regardless of the length of the match | |
15960 | (of course, unless a non-zero LIMIT is given explicitly, such fields are | |
15961 | removed, as in the last example). Thus: | |
15962 | ||
15963 | =end original | |
15964 | ||
15965 | 一方、末尾の空のフィールドは、マッチングの長さに関わらず、EXPR の末尾で | |
15966 | マッチングしたときに生成されます(もちろん非 0 の LIMIT が明示的に | |
15967 | 指定されていない場合です; このようなフィールドは前の例のように | |
15968 | 取り除かれます)。 | |
15969 | 従って: | |
15970 | ||
15971 | print join(':', split(//, ' abc', -1)), "\n"; | |
15972 | ||
13325 | 15973 | =begin original |
13326 | 15974 | |
13327 | ||
15975 | produces the output S<C< :a:b:c:>>. | |
13328 | matched in a C<split()> will be set to C<undef> when returned: | |
13329 | 15976 | |
13330 | 15977 | =end original |
13331 | 15978 | |
13332 | ||
15979 | これは出力 S<C< :a:b:c:>> を生成します。 | |
13333 | 返される時には C<undef> がセットされます。 | |
13334 | 15980 | |
13335 | ||
15981 | =begin original | |
13336 | # @fields is (1, 'A', 2, undef, 3) | |
13337 | 15982 | |
15983 | If the PATTERN contains | |
15984 | L<capturing groups|perlretut/Grouping things and hierarchical matching>, | |
15985 | then for each separator, an additional field is produced for each substring | |
15986 | captured by a group (in the order in which the groups are specified, | |
15987 | as per L<backreferences|perlretut/Backreferences>); if any group does not | |
15988 | match, then it captures the L<C<undef>|/undef EXPR> value instead of a | |
15989 | substring. Also, | |
15990 | note that any such additional field is produced whenever there is a | |
15991 | separator (that is, whenever a split occurs), and such an additional field | |
15992 | does B<not> count towards the LIMIT. Consider the following expressions | |
15993 | evaluated in list context (each returned list is provided in the associated | |
15994 | comment): | |
15995 | ||
15996 | =end original | |
15997 | ||
15998 | PATTERN が | |
15999 | L<捕捉グループ|perlretut/Grouping things and hierarchical matching> を | |
16000 | 含んでいる場合、それぞれのセパレータについて、 | |
16001 | (L<後方参照|perlretut/Backreferences> のようにグループが指定された) | |
16002 | グループによって捕捉されたそれぞれの部分文字列について追加のフィールドが | |
16003 | 生成されます; どのグループもマッチングしなかった場合、部分文字列の代わりに | |
16004 | L<C<undef>|/undef EXPR> 値を捕捉します。 | |
16005 | また、このような追加のフィールドはセパレータがあるとき(つまり、分割が | |
16006 | 行われるとき)はいつでも生成され、このような追加のフィールドは | |
16007 | LIMIT に関してはカウント B<されない> ことに注意してください。 | |
16008 | リストコンテキストで評価される以下のような式を考えます | |
16009 | (それぞれの返されるリストは関連づけられたコメントで提供されます): | |
16010 | ||
16011 | split(/-|,/, "1-10,20", 3) | |
16012 | # ('1', '10', '20') | |
16013 | ||
16014 | split(/(-|,)/, "1-10,20", 3) | |
16015 | # ('1', '-', '10', ',', '20') | |
16016 | ||
16017 | split(/-|(,)/, "1-10,20", 3) | |
16018 | # ('1', undef, '10', ',', '20') | |
16019 | ||
16020 | split(/(-)|,/, "1-10,20", 3) | |
16021 | # ('1', '-', '10', undef, '20') | |
16022 | ||
16023 | split(/(-)|(,)/, "1-10,20", 3) | |
16024 | # ('1', '-', undef, '10', undef, ',', '20') | |
16025 | ||
13338 | 16026 | =item sprintf FORMAT, LIST |
13339 | 16027 | X<sprintf> |
13340 | 16028 | |
16029 | =for Pod::Functions formatted print into a string | |
16030 | ||
13341 | 16031 | =begin original |
13342 | 16032 | |
13343 | Returns a string formatted by the usual | |
16033 | Returns a string formatted by the usual | |
13344 | ||
16034 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST> conventions of the C | |
13345 | an | |
16035 | library function L<C<sprintf>|/sprintf FORMAT, LIST>. See below for | |
13346 | ||
16036 | more details and see L<sprintf(3)> or L<printf(3)> on your system for an | |
16037 | explanation of the general principles. | |
13347 | 16038 | |
13348 | 16039 | =end original |
13349 | 16040 | |
13350 | ||
16041 | C ライブラリ関数 L<C<sprintf>|/sprintf FORMAT, LIST> の | |
16042 | 普通の L<C<printf>|/printf FILEHANDLE FORMAT, LIST> 記法の | |
16043 | 整形された文字列を返します。 | |
13351 | 16044 | 一般的な原則の説明については以下の説明と、システムの |
13352 | ||
16045 | L<sprintf(3)> または L<printf(3)> の説明を参照してください。 | |
13353 | 16046 | |
13354 | 16047 | =begin original |
13355 | 16048 | |
13356 | 16049 | For example: |
13357 | 16050 | |
13358 | 16051 | =end original |
13359 | 16052 | |
13360 | 例: | |
16053 | 例えば: | |
13361 | 16054 | |
13362 | 16055 | # Format number with up to 8 leading zeroes |
13363 | $result = sprintf("%08d", $number); | |
16056 | my $result = sprintf("%08d", $number); | |
13364 | 16057 | |
13365 | 16058 | # Round number to 3 digits after decimal point |
13366 | $rounded = sprintf("%.3f", $number); | |
16059 | my $rounded = sprintf("%.3f", $number); | |
13367 | 16060 | |
13368 | 16061 | =begin original |
13369 | 16062 | |
13370 | Perl does its own C<sprintf> formatting: it | |
16063 | Perl does its own L<C<sprintf>|/sprintf FORMAT, LIST> formatting: it | |
13371 | ||
16064 | emulates the C | |
13372 | ||
16065 | function L<sprintf(3)>, but doesn't use it except for floating-point | |
13373 | ||
16066 | numbers, and even then only standard modifiers are allowed. | |
16067 | Non-standard extensions in your local L<sprintf(3)> are | |
13374 | 16068 | therefore unavailable from Perl. |
13375 | 16069 | |
13376 | 16070 | =end original |
13377 | 16071 | |
13378 | Perl は C<sprintf> フォーマット処理を自力で行います: | |
16072 | Perl は L<C<sprintf>|/sprintf FORMAT, LIST> フォーマット処理を自力で行います: | |
13379 | これは C の sprintf(3) 関数をエミュレートしますが、 | |
16073 | これは C の L<sprintf(3)> 関数をエミュレートしますが、C の関数は使いません | |
13380 | ||
16074 | (浮動小数点を除きますが、それでも標準の記述子のみが利用できます)。 | |
13381 | ||
16075 | 従って、ローカルな非標準の L<sprintf(3)> 拡張機能は Perl では使えません。 | |
13382 | 従って、ローカルな非標準の C<sprintf> 拡張機能は Perl では使えません。 | |
13383 | 16076 | |
13384 | 16077 | =begin original |
13385 | 16078 | |
13386 | Unlike C<printf> | |
16079 | Unlike L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, | |
13387 | p | |
16080 | L<C<sprintf>|/sprintf FORMAT, LIST> does not do what you probably mean | |
16081 | when you pass it an array as your first argument. | |
16082 | The array is given scalar context, | |
13388 | 16083 | and instead of using the 0th element of the array as the format, Perl will |
13389 | 16084 | use the count of elements in the array as the format, which is almost never |
13390 | 16085 | useful. |
13391 | 16086 | |
13392 | 16087 | =end original |
13393 | 16088 | |
13394 | C<printf> | |
16089 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST> と違って、 | |
16090 | L<C<sprintf>|/sprintf FORMAT, LIST> の最初の引数に配列を渡しても | |
13395 | 16091 | あなたが多分望むとおりには動作しません。 |
13396 | 16092 | 配列はスカラコンテキストで渡されるので、配列の 0 番目の要素ではなく、 |
13397 | 配列の要素数をフォーマットとして扱います。 | |
16093 | 配列の要素数をフォーマットとして扱います; これはほとんど役に立ちません。 | |
13398 | これはほとんど役に立ちません。 | |
13399 | 16094 | |
13400 | 16095 | =begin original |
13401 | 16096 | |
13402 | Perl's C<sprintf> permits the following | |
16097 | Perl's L<C<sprintf>|/sprintf FORMAT, LIST> permits the following | |
16098 | universally-known conversions: | |
13403 | 16099 | |
13404 | 16100 | =end original |
13405 | 16101 | |
13406 | Perl の C<sprintf> は以下の一般に知られている変換に | |
16102 | Perl の L<C<sprintf>|/sprintf FORMAT, LIST> は以下の一般に知られている変換に | |
16103 | 対応しています: | |
13407 | 16104 | |
13408 | 16105 | =begin original |
13409 | 16106 | |
13410 | 16107 | %% a percent sign |
13411 | 16108 | %c a character with the given number |
13412 | 16109 | %s a string |
13413 | 16110 | %d a signed integer, in decimal |
13414 | 16111 | %u an unsigned integer, in decimal |
13415 | 16112 | %o an unsigned integer, in octal |
13416 | 16113 | %x an unsigned integer, in hexadecimal |
13417 | 16114 | %e a floating-point number, in scientific notation |
13418 | 16115 | %f a floating-point number, in fixed decimal notation |
13419 | 16116 | %g a floating-point number, in %e or %f notation |
13420 | 16117 | |
13421 | 16118 | =end original |
13422 | 16119 | |
13423 | 16120 | %% パーセントマーク |
13424 | 16121 | %c 与えられた番号の文字 |
13425 | 16122 | %s 文字列 |
13426 | 16123 | %d 符号付き 10 進数 |
13427 | 16124 | %u 符号なし 10 進数 |
13428 | 16125 | %o 符号なし 8 進数 |
13429 | 16126 | %x 符号なし 16 進数 |
13430 | 16127 | %e 科学的表記の浮動小数点数 |
13431 | 16128 | %f 固定 10 進数表記の浮動小数点数 |
13432 | 16129 | %g %e か %f の表記の浮動小数点数 |
13433 | 16130 | |
13434 | 16131 | =begin original |
13435 | 16132 | |
13436 | 16133 | In addition, Perl permits the following widely-supported conversions: |
13437 | 16134 | |
13438 | 16135 | =end original |
13439 | 16136 | |
13440 | 16137 | さらに、Perl では以下のよく使われている変換に対応しています: |
13441 | 16138 | |
13442 | 16139 | =begin original |
13443 | 16140 | |
13444 | 16141 | %X like %x, but using upper-case letters |
13445 | 16142 | %E like %e, but using an upper-case "E" |
13446 | 16143 | %G like %g, but with an upper-case "E" (if applicable) |
13447 | 16144 | %b an unsigned integer, in binary |
13448 | 16145 | %B like %b, but using an upper-case "B" with the # flag |
13449 | 16146 | %p a pointer (outputs the Perl value's address in hexadecimal) |
13450 | 16147 | %n special: *stores* the number of characters output so far |
13451 | into the next | |
16148 | into the next argument in the parameter list | |
16149 | %a hexadecimal floating point | |
16150 | %A like %a, but using upper-case letters | |
13452 | 16151 | |
13453 | 16152 | =end original |
13454 | 16153 | |
13455 | 16154 | %X %x と同様だが大文字を使う |
13456 | 16155 | %E %e と同様だが大文字の "E" を使う |
13457 | 16156 | %G %g と同様だが(適切なら)大文字の "E" を使う |
13458 | 16157 | %b 符号なし 2 進数 |
13459 | 16158 | %B %b と同様だが、# フラグで大文字の "B" を使う |
13460 | 16159 | %p ポインタ (Perl の値のアドレスを 16 進数で出力する) |
13461 | 16160 | %n 特殊: 出力文字数を引数リストの次の変数に「格納」する |
16161 | %a 16 進浮動小数点 | |
16162 | %A %a と同様だが、大文字を使う | |
13462 | 16163 | |
13463 | 16164 | =begin original |
13464 | 16165 | |
13465 | 16166 | Finally, for backward (and we do mean "backward") compatibility, Perl |
13466 | 16167 | permits these unnecessary but widely-supported conversions: |
13467 | 16168 | |
13468 | 16169 | =end original |
13469 | 16170 | |
13470 | 16171 | 最後に、過去との互換性(これは「過去」だと考えています)のために、 |
13471 | 16172 | Perl は以下の不要ではあるけれども広く使われている変換に対応しています。 |
13472 | 16173 | |
13473 | 16174 | =begin original |
13474 | 16175 | |
13475 | 16176 | %i a synonym for %d |
13476 | 16177 | %D a synonym for %ld |
13477 | 16178 | %U a synonym for %lu |
13478 | 16179 | %O a synonym for %lo |
13479 | 16180 | %F a synonym for %f |
13480 | 16181 | |
13481 | 16182 | =end original |
13482 | 16183 | |
13483 | 16184 | %i %d の同義語 |
13484 | 16185 | %D %ld の同義語 |
13485 | 16186 | %U %lu の同義語 |
13486 | 16187 | %O %lo の同義語 |
13487 | 16188 | %F %f の同義語 |
13488 | 16189 | |
13489 | 16190 | =begin original |
13490 | 16191 | |
13491 | 16192 | Note that the number of exponent digits in the scientific notation produced |
13492 | 16193 | by C<%e>, C<%E>, C<%g> and C<%G> for numbers with the modulus of the |
13493 | 16194 | exponent less than 100 is system-dependent: it may be three or less |
13494 | 16195 | (zero-padded as necessary). In other words, 1.23 times ten to the |
13495 | 99th may be either "1.23e99" or "1.23e099". | |
16196 | 99th may be either "1.23e99" or "1.23e099". Similarly for C<%a> and C<%A>: | |
16197 | the exponent or the hexadecimal digits may float: especially the | |
16198 | "long doubles" Perl configuration option may cause surprises. | |
13496 | 16199 | |
13497 | 16200 | =end original |
13498 | 16201 | |
13499 | 16202 | C<%e>, C<%E>, C<%g>, C<%G> において、指数部が 100 未満の場合の |
13500 | 16203 | 指数部の科学的な表記法はシステム依存であることに注意してください: |
13501 | 16204 | 3 桁かもしれませんし、それ以下かもしれません(必要に応じて 0 で |
13502 | 16205 | パッディングされます)。 |
13503 | 16206 | 言い換えると、 1.23 掛ける 10 の 99 乗は "1.23e99" かもしれませんし |
13504 | 16207 | "1.23e099" かもしれません。 |
16208 | 同様に C<%a> と C<%A> の場合: | |
16209 | 指数部と 16 進数が浮動小数点かもしれません: | |
16210 | 特に "long doubles" Perl 設定オプションが驚きを引き起こすかもしれません。 | |
13505 | 16211 | |
13506 | 16212 | =begin original |
13507 | 16213 | |
13508 | 16214 | Between the C<%> and the format letter, you may specify several |
13509 | 16215 | additional attributes controlling the interpretation of the format. |
13510 | 16216 | In order, these are: |
13511 | 16217 | |
13512 | 16218 | =end original |
13513 | 16219 | |
13514 | 16220 | C<%> とフォーマット文字の間に、フォーマットの解釈を制御するための、 |
13515 | 16221 | いくつかの追加の属性を指定できます。 |
13516 | 16222 | 順番に、以下のものがあります: |
13517 | 16223 | |
13518 | 16224 | =over 4 |
13519 | 16225 | |
13520 | 16226 | =item format parameter index |
13521 | 16227 | |
13522 | 16228 | (フォーマットパラメータインデックス) |
13523 | 16229 | |
13524 | 16230 | =begin original |
13525 | 16231 | |
13526 | An explicit format parameter index, such as C<2$>. By default sprintf | |
16232 | An explicit format parameter index, such as C<2$>. By default sprintf | |
13527 | 16233 | will format the next unused argument in the list, but this allows you |
13528 | 16234 | to take the arguments out of order: |
13529 | 16235 | |
13530 | 16236 | =end original |
13531 | 16237 | |
13532 | 16238 | C<2$> のような明示的なフォーマットパラメータインデックス。 |
13533 | 16239 | デフォルトでは sprintf はリストの次の使われていない引数を |
13534 | 16240 | フォーマットしますが、これによって異なった順番の引数を使えるようにします: |
13535 | 16241 | |
13536 | 16242 | printf '%2$d %1$d', 12, 34; # prints "34 12" |
13537 | 16243 | printf '%3$d %d %1$d', 1, 2, 3; # prints "3 1 1" |
13538 | 16244 | |
13539 | 16245 | =item flags |
13540 | 16246 | |
13541 | 16247 | (フラグ) |
13542 | 16248 | |
13543 | 16249 | =begin original |
13544 | 16250 | |
13545 | 16251 | one or more of: |
13546 | 16252 | |
13547 | 16253 | =end original |
13548 | 16254 | |
13549 | 16255 | 以下のうちの一つまたは複数指定できます: |
13550 | 16256 | |
13551 | 16257 | =begin original |
13552 | 16258 | |
13553 | 16259 | space prefix non-negative number with a space |
13554 | 16260 | + prefix non-negative number with a plus sign |
13555 | 16261 | - left-justify within the field |
13556 | 16262 | 0 use zeros, not spaces, to right-justify |
13557 | 16263 | # ensure the leading "0" for any octal, |
13558 | 16264 | prefix non-zero hexadecimal with "0x" or "0X", |
13559 | 16265 | prefix non-zero binary with "0b" or "0B" |
13560 | 16266 | |
13561 | 16267 | =end original |
13562 | 16268 | |
13563 | 16269 | space 非負数の前に空白をつける |
13564 | 16270 | + 非負数の前にプラス記号をつける |
13565 | 16271 | - フィールド内で左詰めする |
13566 | 16272 | 0 右詰めに空白ではなくゼロを使う |
13567 | 16273 | # 8 進数では確実に先頭に "0" をつける; |
13568 | 16274 | 非 0 の 16 進数では "0x" か "0X" をつける; |
13569 | 16275 | 非 0 の 2 進数では "0b" か "0B" をつける |
13570 | 16276 | |
13571 | 16277 | =begin original |
13572 | 16278 | |
13573 | 16279 | For example: |
13574 | 16280 | |
13575 | 16281 | =end original |
13576 | 16282 | |
13577 | 例: | |
16283 | 例えば: | |
13578 | 16284 | |
13579 | 16285 | printf '<% d>', 12; # prints "< 12>" |
16286 | printf '<% d>', 0; # prints "< 0>" | |
16287 | printf '<% d>', -12; # prints "<-12>" | |
13580 | 16288 | printf '<%+d>', 12; # prints "<+12>" |
16289 | printf '<%+d>', 0; # prints "<+0>" | |
16290 | printf '<%+d>', -12; # prints "<-12>" | |
13581 | 16291 | printf '<%6s>', 12; # prints "< 12>" |
13582 | 16292 | printf '<%-6s>', 12; # prints "<12 >" |
13583 | 16293 | printf '<%06s>', 12; # prints "<000012>" |
13584 | 16294 | printf '<%#o>', 12; # prints "<014>" |
13585 | 16295 | printf '<%#x>', 12; # prints "<0xc>" |
13586 | 16296 | printf '<%#X>', 12; # prints "<0XC>" |
13587 | 16297 | printf '<%#b>', 12; # prints "<0b1100>" |
13588 | 16298 | printf '<%#B>', 12; # prints "<0B1100>" |
13589 | 16299 | |
13590 | 16300 | =begin original |
13591 | 16301 | |
13592 | 16302 | When a space and a plus sign are given as the flags at once, |
13593 | ||
16303 | the space is ignored. | |
13594 | 16304 | |
13595 | 16305 | =end original |
13596 | 16306 | |
13597 | 空白とプラス記号がフラグとして同時に与えられると、 | |
16307 | 空白とプラス記号がフラグとして同時に与えられると、 | |
13598 | ||
16308 | 空白は無視されます。 | |
13599 | 16309 | |
13600 | 16310 | printf '<%+ d>', 12; # prints "<+12>" |
13601 | 16311 | printf '<% +d>', 12; # prints "<+12>" |
13602 | 16312 | |
13603 | 16313 | =begin original |
13604 | 16314 | |
13605 | 16315 | When the # flag and a precision are given in the %o conversion, |
13606 | 16316 | the precision is incremented if it's necessary for the leading "0". |
13607 | 16317 | |
13608 | 16318 | =end original |
13609 | 16319 | |
13610 | 16320 | %o 変換に # フラグと精度が与えられると、先頭の "0" が必要な場合は |
13611 | 16321 | 精度に 1 が加えられます。 |
13612 | 16322 | |
13613 | 16323 | printf '<%#.5o>', 012; # prints "<00012>" |
13614 | 16324 | printf '<%#.5o>', 012345; # prints "<012345>" |
13615 | 16325 | printf '<%#.0o>', 0; # prints "<0>" |
13616 | 16326 | |
13617 | 16327 | =item vector flag |
13618 | 16328 | |
13619 | 16329 | (ベクタフラグ) |
13620 | 16330 | |
13621 | 16331 | =begin original |
13622 | 16332 | |
13623 | 16333 | This flag tells Perl to interpret the supplied string as a vector of |
13624 | integers, one for each character in the string. Perl applies the format to | |
16334 | integers, one for each character in the string. Perl applies the format to | |
13625 | 16335 | each integer in turn, then joins the resulting strings with a separator (a |
13626 | dot C<.> by default). This can be useful for displaying ordinal values of | |
16336 | dot C<.> by default). This can be useful for displaying ordinal values of | |
13627 | 16337 | characters in arbitrary strings: |
13628 | 16338 | |
13629 | 16339 | =end original |
13630 | 16340 | |
13631 | 16341 | このフラグは Perl に、与えられた文字列を、文字毎に一つの整数のベクタとして |
13632 | 16342 | 解釈させます。 |
13633 | 16343 | Perl は各数値をフォーマットし、それから結果の文字列をセパレータ |
13634 | 16344 | (デフォルトでは C<.>)で連結します。 |
13635 | 16345 | これは任意の文字列の文字を順序付きの値として表示するのに便利です: |
13636 | 16346 | |
13637 | 16347 | printf "%vd", "AB\x{100}"; # prints "65.66.256" |
13638 | 16348 | printf "version is v%vd\n", $^V; # Perl's version |
13639 | 16349 | |
13640 | 16350 | =begin original |
13641 | 16351 | |
13642 | 16352 | Put an asterisk C<*> before the C<v> to override the string to |
13643 | 16353 | use to separate the numbers: |
13644 | 16354 | |
13645 | 16355 | =end original |
13646 | 16356 | |
13647 | 16357 | アスタリスク C<*> を C<v> の前に置くと、数値を分けるために使われる文字列を |
13648 | 16358 | 上書きします: |
13649 | 16359 | |
13650 | 16360 | printf "address is %*vX\n", ":", $addr; # IPv6 address |
13651 | 16361 | printf "bits are %0*v8b\n", " ", $bits; # random bitstring |
13652 | 16362 | |
13653 | 16363 | =begin original |
13654 | 16364 | |
13655 | 16365 | You can also explicitly specify the argument number to use for |
13656 | 16366 | the join string using something like C<*2$v>; for example: |
13657 | 16367 | |
13658 | 16368 | =end original |
13659 | 16369 | |
13660 | 16370 | また、C<*2$v> のように、連結する文字列として使う引数の番号を明示的に |
13661 | 16371 | 指定できます; 例えば: |
13662 | 16372 | |
13663 | printf '%*4$vX %*4$vX %*4$vX', | |
16373 | printf '%*4$vX %*4$vX %*4$vX', # 3 IPv6 addresses | |
16374 | @addr[1..3], ":"; | |
13664 | 16375 | |
13665 | 16376 | =item (minimum) width |
13666 | 16377 | |
13667 | 16378 | ((最小)幅) |
13668 | 16379 | |
13669 | 16380 | =begin original |
13670 | 16381 | |
13671 | 16382 | Arguments are usually formatted to be only as wide as required to |
13672 | display the given value. You can override the width by putting | |
16383 | display the given value. You can override the width by putting | |
13673 | 16384 | a number here, or get the width from the next argument (with C<*>) |
13674 | 16385 | or from a specified argument (e.g., with C<*2$>): |
13675 | 16386 | |
13676 | 16387 | =end original |
13677 | 16388 | |
13678 | 16389 | 引数は、普通は値を表示するのに必要なちょうどの幅でフォーマットされます。 |
13679 | 16390 | ここに数値を置くか、(C<*> で)次の引数か(C<*2$> で)明示的に指定した引数で |
13680 | 16391 | 幅を上書きできます。 |
13681 | 16392 | |
13682 | | |
16393 | printf "<%s>", "a"; # prints "<a>" | |
13683 | | |
16394 | printf "<%6s>", "a"; # prints "< a>" | |
13684 | | |
16395 | printf "<%*s>", 6, "a"; # prints "< a>" | |
13685 | | |
16396 | printf '<%*2$s>', "a", 6; # prints "< a>" | |
13686 | | |
16397 | printf "<%2s>", "long"; # prints "<long>" (does not truncate) | |
13687 | 16398 | |
13688 | 16399 | =begin original |
13689 | 16400 | |
13690 | 16401 | If a field width obtained through C<*> is negative, it has the same |
13691 | 16402 | effect as the C<-> flag: left-justification. |
13692 | 16403 | |
13693 | 16404 | =end original |
13694 | 16405 | |
13695 | 16406 | C<*> を通して得られたフィールドの値が負数の場合、C<-> フラグと |
13696 | 16407 | 同様の効果 (左詰め) があります。 |
13697 | 16408 | |
13698 | 16409 | =item precision, or maximum width |
13699 | 16410 | X<precision> |
13700 | 16411 | |
13701 | 16412 | (精度あるいは最大幅) |
13702 | 16413 | |
13703 | 16414 | =begin original |
13704 | 16415 | |
13705 | 16416 | You can specify a precision (for numeric conversions) or a maximum |
13706 | 16417 | width (for string conversions) by specifying a C<.> followed by a number. |
13707 | 16418 | For floating-point formats except C<g> and C<G>, this specifies |
13708 | 16419 | how many places right of the decimal point to show (the default being 6). |
13709 | 16420 | For example: |
13710 | 16421 | |
13711 | 16422 | =end original |
13712 | 16423 | |
13713 | 16424 | C<.> の後に数値を指定することで、(数値変換の場合)精度や(文字列変換の場合) |
13714 | 16425 | 最大幅を指定できます。 |
13715 | 16426 | 小数点数フォーマットの場合、C<g> と C<G> を除いて、表示する小数点以下の |
13716 | 16427 | 桁数を指定します(デフォルトは 6 です)。 |
13717 | 例: | |
16428 | 例えば: | |
13718 | 16429 | |
13719 | 16430 | # these examples are subject to system-specific variation |
13720 | 16431 | printf '<%f>', 1; # prints "<1.000000>" |
13721 | 16432 | printf '<%.1f>', 1; # prints "<1.0>" |
13722 | 16433 | printf '<%.0f>', 1; # prints "<1>" |
13723 | 16434 | printf '<%e>', 10; # prints "<1.000000e+01>" |
13724 | 16435 | printf '<%.1e>', 10; # prints "<1.0e+01>" |
13725 | 16436 | |
13726 | 16437 | =begin original |
13727 | 16438 | |
13728 | 16439 | For "g" and "G", this specifies the maximum number of digits to show, |
13729 | including thoe prior to the decimal point and those after it; for | |
16440 | including those prior to the decimal point and those after it; for | |
13730 | 16441 | example: |
13731 | 16442 | |
13732 | 16443 | =end original |
13733 | 16444 | |
13734 | 16445 | "g" と "G" の場合、これは表示する数値の数を指定します; |
13735 | 16446 | これには小数点の前の数値と後の数値を含みます; 例えば: |
13736 | 16447 | |
13737 | 16448 | # These examples are subject to system-specific variation. |
13738 | 16449 | printf '<%g>', 1; # prints "<1>" |
13739 | 16450 | printf '<%.10g>', 1; # prints "<1>" |
13740 | 16451 | printf '<%g>', 100; # prints "<100>" |
13741 | 16452 | printf '<%.1g>', 100; # prints "<1e+02>" |
13742 | 16453 | printf '<%.2g>', 100.01; # prints "<1e+02>" |
13743 | 16454 | printf '<%.5g>', 100.01; # prints "<100.01>" |
13744 | 16455 | printf '<%.4g>', 100.01; # prints "<100>" |
13745 | 16456 | |
13746 | 16457 | =begin original |
13747 | 16458 | |
13748 | 16459 | For integer conversions, specifying a precision implies that the |
13749 | 16460 | output of the number itself should be zero-padded to this width, |
13750 | 16461 | where the 0 flag is ignored: |
13751 | 16462 | |
13752 | 16463 | =end original |
13753 | 16464 | |
13754 | 16465 | 整数変換の場合、精度を指定すると、数値自体の出力はこの幅に 0 で |
13755 | 16466 | パッディングするべきであることを暗に示すことになり、0 フラグは |
13756 | 16467 | 無視されます: |
13757 | 16468 | |
13758 | 16469 | printf '<%.6d>', 1; # prints "<000001>" |
13759 | 16470 | printf '<%+.6d>', 1; # prints "<+000001>" |
13760 | 16471 | printf '<%-10.6d>', 1; # prints "<000001 >" |
13761 | 16472 | printf '<%10.6d>', 1; # prints "< 000001>" |
13762 | 16473 | printf '<%010.6d>', 1; # prints "< 000001>" |
13763 | 16474 | printf '<%+10.6d>', 1; # prints "< +000001>" |
13764 | 16475 | |
13765 | 16476 | printf '<%.6x>', 1; # prints "<000001>" |
13766 | 16477 | printf '<%#.6x>', 1; # prints "<0x000001>" |
13767 | 16478 | printf '<%-10.6x>', 1; # prints "<000001 >" |
13768 | 16479 | printf '<%10.6x>', 1; # prints "< 000001>" |
13769 | 16480 | printf '<%010.6x>', 1; # prints "< 000001>" |
13770 | 16481 | printf '<%#10.6x>', 1; # prints "< 0x000001>" |
13771 | 16482 | |
13772 | 16483 | =begin original |
13773 | 16484 | |
13774 | 16485 | For string conversions, specifying a precision truncates the string |
13775 | 16486 | to fit the specified width: |
13776 | 16487 | |
13777 | 16488 | =end original |
13778 | 16489 | |
13779 | 16490 | 文字列変換の場合、精度を指定すると、指定された幅に収まるように文字列を |
13780 | 16491 | 切り詰めます: |
13781 | 16492 | |
13782 | 16493 | printf '<%.5s>', "truncated"; # prints "<trunc>" |
13783 | 16494 | printf '<%10.5s>', "truncated"; # prints "< trunc>" |
13784 | 16495 | |
13785 | 16496 | =begin original |
13786 | 16497 | |
13787 | You can also get the precision from the next argument using C<.*> | |
16498 | You can also get the precision from the next argument using C<.*>, or from a | |
16499 | specified argument (e.g., with C<.*2$>): | |
13788 | 16500 | |
13789 | 16501 | =end original |
13790 | 16502 | |
13791 | C<.*> を使って精度を次の引数から取 | |
16503 | C<.*> を使って精度を次の引数から取ったり、 | |
16504 | (C<.*2$> のように) 指定した引数から取ったりすることもできます: | |
13792 | 16505 | |
13793 | 16506 | printf '<%.6x>', 1; # prints "<000001>" |
13794 | 16507 | printf '<%.*x>', 6, 1; # prints "<000001>" |
13795 | 16508 | |
16509 | printf '<%.*2$x>', 1, 6; # prints "<000001>" | |
16510 | ||
16511 | printf '<%6.*2$x>', 1, 4; # prints "< 0001>" | |
16512 | ||
13796 | 16513 | =begin original |
13797 | 16514 | |
13798 | 16515 | If a precision obtained through C<*> is negative, it counts |
13799 | 16516 | as having no precision at all. |
13800 | 16517 | |
13801 | 16518 | =end original |
13802 | 16519 | |
13803 | 16520 | C<*> によって得られた精度が負数の場合、精度が指定されなかった場合と |
13804 | 16521 | 同じ効果となります。 |
13805 | 16522 | |
13806 | 16523 | printf '<%.*s>', 7, "string"; # prints "<string>" |
13807 | 16524 | printf '<%.*s>', 3, "string"; # prints "<str>" |
13808 | 16525 | printf '<%.*s>', 0, "string"; # prints "<>" |
13809 | 16526 | printf '<%.*s>', -1, "string"; # prints "<string>" |
13810 | 16527 | |
13811 | 16528 | printf '<%.*d>', 1, 0; # prints "<0>" |
13812 | 16529 | printf '<%.*d>', 0, 0; # prints "<>" |
13813 | 16530 | printf '<%.*d>', -1, 0; # prints "<0>" |
13814 | 16531 | |
13815 | =begin original | |
13816 | ||
13817 | You cannot currently get the precision from a specified number, | |
13818 | but it is intended that this will be possible in the future, for | |
13819 | example using C<.*2$>: | |
13820 | ||
13821 | =end original | |
13822 | ||
13823 | 現在のところ精度を指定した数値から得ることはできませんが、 | |
13824 | 将来は 例えば C<.*2$> のようにして可能にしようとしています: | |
13825 | ||
13826 | printf "<%.*2$x>", 1, 6; # INVALID, but in future will print "<000001>" | |
13827 | ||
13828 | 16532 | =item size |
13829 | 16533 | |
13830 | 16534 | (サイズ) |
13831 | 16535 | |
13832 | 16536 | =begin original |
13833 | 16537 | |
13834 | 16538 | For numeric conversions, you can specify the size to interpret the |
13835 | number as using C<l>, C<h>, C<V>, C<q>, C<L>, or C<ll>. For integer | |
16539 | number as using C<l>, C<h>, C<V>, C<q>, C<L>, or C<ll>. For integer | |
13836 | 16540 | conversions (C<d u o x X b i D U O>), numbers are usually assumed to be |
13837 | 16541 | whatever the default integer size is on your platform (usually 32 or 64 |
13838 | 16542 | bits), but you can override this to use instead one of the standard C types, |
13839 | 16543 | as supported by the compiler used to build Perl: |
13840 | 16544 | |
13841 | 16545 | =end original |
13842 | 16546 | |
13843 | 16547 | 数値変換では、C<l>, C<h>, C<V>, C<q>, C<L>, C<ll> を使って解釈する数値の |
13844 | 16548 | 大きさを指定できます。 |
13845 | 16549 | 整数変換 (C<d u o x X b i D U O>) では、数値は通常プラットフォームの |
13846 | 16550 | デフォルトの整数のサイズ (通常は 32 ビットか 64 ビット) を仮定しますが、 |
13847 | 16551 | これを Perl がビルドされたコンパイラが対応している標準 C の型の一つで |
13848 | 16552 | 上書きできます: |
13849 | 16553 | |
13850 | 16554 | =begin original |
13851 | 16555 | |
13852 | hh interpret integer as C type "char" or "unsigned | |
16556 | hh interpret integer as C type "char" or "unsigned | |
13853 | ||
16557 | char" on Perl 5.14 or later | |
13854 | h interpret integer as C type "short" or | |
16558 | h interpret integer as C type "short" or | |
13855 | | |
16559 | "unsigned short" | |
13856 | ||
16560 | j interpret integer as C type "intmax_t" on Perl | |
13857 | | |
16561 | 5.14 or later, and only with a C99 compiler | |
13858 | | |
16562 | (unportable) | |
13859 | | |
16563 | l interpret integer as C type "long" or | |
13860 | | |
16564 | "unsigned long" | |
13861 | | |
16565 | q, L, or ll interpret integer as C type "long long", | |
16566 | "unsigned long long", or "quad" (typically | |
16567 | 64-bit integers) | |
16568 | t interpret integer as C type "ptrdiff_t" on Perl | |
16569 | 5.14 or later | |
16570 | z interpret integer as C type "size_t" on Perl 5.14 | |
16571 | or later | |
13862 | 16572 | |
13863 | 16573 | =end original |
13864 | 16574 | |
13865 | 16575 | hh Perl 5.14 以降で整数を C の "char" または "unsigned char" |
13866 | ||
16576 | 型として解釈する | |
13867 | 16577 | h 整数を C の "char" または "unsigned char" 型として解釈する |
13868 | j | |
16578 | j Perl 5.14 以降 C99 コンパイラのみで整数を C の "intmax_t" | |
13869 | ||
16579 | 型として解釈する (移植性なし) | |
13870 | 16580 | l 整数を C の "long" または "unsigned long" と解釈する |
13871 | 16581 | h 整数を C の "short" または "unsigned short" と解釈する |
13872 | 16582 | q, L or ll 整数を C の "long long", "unsigned long long", |
13873 | 16583 | "quads"(典型的には 64 ビット整数) のどれかと解釈する |
13874 | t | |
16584 | t Perl 5.14 以降で整数を C の "ptrdiff_t" 型として解釈する | |
13875 | z | |
16585 | z Perl 5.14 以降で整数を C の "size_t" 型として解釈する | |
13876 | 16586 | |
13877 | 16587 | =begin original |
13878 | 16588 | |
13879 | 16589 | As of 5.14, none of these raises an exception if they are not supported on |
13880 | 16590 | your platform. However, if warnings are enabled, a warning of the |
13881 | C<printf> warning class is issued on an unsupported | |
16591 | L<C<printf>|warnings> warning class is issued on an unsupported | |
13882 | Should you instead prefer an exception, do this: | |
16592 | conversion flag. Should you instead prefer an exception, do this: | |
13883 | 16593 | |
13884 | 16594 | =end original |
13885 | 16595 | |
13886 | 16596 | 5.14 から、プラットフォームがこれらに対応していないときでも例外が |
13887 | 16597 | 発生しなくなりました。 |
13888 | 16598 | しかし、もし警告が有効になっているなら、 |
13889 | 非対応変換フラグに関して C<printf> 警告クラスの警告が発生します。 | |
16599 | 非対応変換フラグに関して L<C<printf>|warnings> 警告クラスの警告が発生します。 | |
13890 | 16600 | 例外の方がお好みなら、以下のようにします: |
13891 | 16601 | |
13892 | 16602 | use warnings FATAL => "printf"; |
13893 | 16603 | |
13894 | 16604 | =begin original |
13895 | 16605 | |
13896 | 16606 | If you would like to know about a version dependency before you |
13897 | 16607 | start running the program, put something like this at its top: |
13898 | 16608 | |
13899 | 16609 | =end original |
13900 | 16610 | |
13901 | 16611 | プログラムの実行開始前にバージョン依存について知りたいなら、先頭に |
13902 | 16612 | 以下のようなものを書きます: |
13903 | 16613 | |
13904 | 16614 | use 5.014; # for hh/j/t/z/ printf modifiers |
13905 | 16615 | |
13906 | 16616 | =begin original |
13907 | 16617 | |
13908 | 16618 | You can find out whether your Perl supports quads via L<Config>: |
13909 | 16619 | |
13910 | 16620 | =end original |
13911 | 16621 | |
13912 | 16622 | Perl が 64 ビット整数に対応しているかどうかは L<Config> を使って |
13913 | 16623 | 調べられます: |
13914 | 16624 | |
13915 | 16625 | use Config; |
13916 | if ($Config{use64bitint} eq "define" | |
16626 | if ($Config{use64bitint} eq "define" | |
16627 | || $Config{longsize} >= 8) { | |
13917 | 16628 | print "Nice quads!\n"; |
13918 | 16629 | } |
13919 | 16630 | |
13920 | 16631 | =begin original |
13921 | 16632 | |
13922 | 16633 | For floating-point conversions (C<e f g E F G>), numbers are usually assumed |
13923 | 16634 | to be the default floating-point size on your platform (double or long double), |
13924 | 16635 | but you can force "long double" with C<q>, C<L>, or C<ll> if your |
13925 | platform supports them. You can find out whether your Perl supports long | |
16636 | platform supports them. You can find out whether your Perl supports long | |
13926 | 16637 | doubles via L<Config>: |
13927 | 16638 | |
13928 | 16639 | =end original |
13929 | 16640 | |
13930 | 16641 | 浮動小数点数変換 (C<e f g E F G>) では、普通はプラットフォームのデフォルトの |
13931 | 不動小数点数のサイズ (double か long double) を仮定します | |
16642 | 不動小数点数のサイズ (double か long double) を仮定しますが、 | |
16643 | プラットフォームが対応しているなら、C<q>, C<L>, C<ll> に対して | |
16644 | "long double" を強制できます。 | |
13932 | 16645 | Perl が long double に対応しているかどうかは L<Config> を使って |
13933 | 16646 | 調べられます: |
13934 | 16647 | |
13935 | 16648 | use Config; |
13936 | 16649 | print "long doubles\n" if $Config{d_longdbl} eq "define"; |
13937 | 16650 | |
13938 | 16651 | =begin original |
13939 | 16652 | |
13940 | 16653 | You can find out whether Perl considers "long double" to be the default |
13941 | 16654 | floating-point size to use on your platform via L<Config>: |
13942 | 16655 | |
13943 | 16656 | =end original |
13944 | 16657 | |
13945 | 16658 | Perl が "long double" をデフォルトの浮動小数点数として扱っているかどうかは |
13946 | 16659 | L<Config> を使って調べられます: |
13947 | 16660 | |
13948 | 16661 | use Config; |
13949 | 16662 | if ($Config{uselongdouble} eq "define") { |
13950 | ||
16663 | print "long doubles by default\n"; | |
13951 | 16664 | } |
13952 | 16665 | |
13953 | 16666 | =begin original |
13954 | 16667 | |
13955 | 16668 | It can also be that long doubles and doubles are the same thing: |
13956 | 16669 | |
13957 | 16670 | =end original |
13958 | 16671 | |
13959 | 16672 | long double と double が同じ場合もあります: |
13960 | 16673 | |
13961 | 16674 | use Config; |
13962 | 16675 | ($Config{doublesize} == $Config{longdblsize}) && |
13963 | 16676 | print "doubles are long doubles\n"; |
13964 | 16677 | |
13965 | 16678 | =begin original |
13966 | 16679 | |
13967 | 16680 | The size specifier C<V> has no effect for Perl code, but is supported for |
13968 | 16681 | compatibility with XS code. It means "use the standard size for a Perl |
13969 | 16682 | integer or floating-point number", which is the default. |
13970 | 16683 | |
13971 | 16684 | =end original |
13972 | 16685 | |
13973 | 16686 | サイズ指定子 C<V> は Perl のコードには何の影響もありませんが、これは |
13974 | 16687 | XS コードとの互換性のために対応しています。 |
13975 | 16688 | これは「Perl 整数 (または浮動小数点数) として標準的なサイズを使う」ことを |
13976 | 16689 | 意味し、これはデフォルトです。 |
13977 | 16690 | |
13978 | 16691 | =item order of arguments |
13979 | 16692 | |
13980 | 16693 | (引数の順序) |
13981 | 16694 | |
13982 | 16695 | =begin original |
13983 | 16696 | |
13984 | Normally, sprintf | |
16697 | Normally, L<C<sprintf>|/sprintf FORMAT, LIST> takes the next unused | |
13985 | ||
16698 | argument as the value to | |
16699 | format for each format specification. If the format specification | |
13986 | 16700 | uses C<*> to require additional arguments, these are consumed from |
13987 | 16701 | the argument list in the order they appear in the format |
13988 | 16702 | specification I<before> the value to format. Where an argument is |
13989 | 16703 | specified by an explicit index, this does not affect the normal |
13990 | 16704 | order for the arguments, even when the explicitly specified index |
13991 | 16705 | would have been the next argument. |
13992 | 16706 | |
13993 | 16707 | =end original |
13994 | 16708 | |
13995 | 通常、sprintf | |
16709 | 通常、L<C<sprintf>|/sprintf FORMAT, LIST> は各フォーマット指定について、 | |
16710 | 使われていない次の引数を | |
13996 | 16711 | フォーマットする値として使います。 |
13997 | 16712 | 追加の引数を要求するためにフォーマット指定 C<*> を使うと、 |
13998 | 16713 | これらはフォーマットする値の I<前> のフォーマット指定に現れる順番に |
13999 | 16714 | 引数リストから消費されます。 |
14000 | 16715 | 引数の位置が明示的なインデックスを使って指定された場合、 |
14001 | 16716 | (明示的に指定したインデックスが次の引数の場合でも) |
14002 | 16717 | これは通常の引数の順番に影響を与えません。 |
14003 | 16718 | |
14004 | 16719 | =begin original |
14005 | 16720 | |
14006 | 16721 | So: |
14007 | 16722 | |
14008 | 16723 | =end original |
14009 | 16724 | |
14010 | 16725 | それで: |
14011 | 16726 | |
14012 | 16727 | printf "<%*.*s>", $a, $b, $c; |
14013 | 16728 | |
14014 | 16729 | =begin original |
14015 | 16730 | |
14016 | 16731 | uses C<$a> for the width, C<$b> for the precision, and C<$c> |
14017 | 16732 | as the value to format; while: |
14018 | 16733 | |
14019 | 16734 | =end original |
14020 | 16735 | |
14021 | 16736 | とすると C<$a> を幅に、C<$b> を精度に、C<$c> をフォーマットの値に |
14022 | 16737 | 使います; 一方: |
14023 | 16738 | |
14024 | printf | |
16739 | printf '<%*1$.*s>', $a, $b; | |
14025 | 16740 | |
14026 | 16741 | =begin original |
14027 | 16742 | |
14028 | 16743 | would use C<$a> for the width and precision, and C<$b> as the |
14029 | 16744 | value to format. |
14030 | 16745 | |
14031 | 16746 | =end original |
14032 | 16747 | |
14033 | 16748 | とすると C<$a> を幅と精度に、C<$b> をフォーマットの値に使います。 |
14034 | 16749 | |
14035 | 16750 | =begin original |
14036 | 16751 | |
14037 | 16752 | Here are some more examples; be aware that when using an explicit |
14038 | 16753 | index, the C<$> may need escaping: |
14039 | 16754 | |
14040 | 16755 | =end original |
14041 | 16756 | |
14042 | 16757 | 以下にさらなる例を示します; 明示的にインデックスを使う場合、C<$> は |
14043 | 16758 | エスケープする必要があることに注意してください: |
14044 | 16759 | |
14045 | | |
16760 | printf "%2\$d %d\n", 12, 34; # will print "34 12\n" | |
14046 | | |
16761 | printf "%2\$d %d %d\n", 12, 34; # will print "34 12 34\n" | |
14047 | | |
16762 | printf "%3\$d %d %d\n", 12, 34, 56; # will print "56 12 34\n" | |
14048 | | |
16763 | printf "%2\$*3\$d %d\n", 12, 34, 3; # will print " 34 12\n" | |
16764 | printf "%*1\$.*f\n", 4, 5, 10; # will print "5.0000\n" | |
14049 | 16765 | |
14050 | 16766 | =back |
14051 | 16767 | |
14052 | 16768 | =begin original |
14053 | 16769 | |
14054 | If C<use locale> i | |
16770 | If L<C<use locale>|locale> (including C<use locale ':not_characters'>) | |
16771 | is in effect and L<C<POSIX::setlocale>|POSIX/C<setlocale>> has been | |
16772 | called, | |
14055 | 16773 | the character used for the decimal separator in formatted floating-point |
14056 | numbers is affected by the LC_NUMERIC locale. See L<perllocale> | |
16774 | numbers is affected by the C<LC_NUMERIC> locale. See L<perllocale> | |
14057 | 16775 | and L<POSIX>. |
14058 | 16776 | |
14059 | 16777 | =end original |
14060 | 16778 | |
14061 | C<use locale | |
16779 | (C<use locale ':not_characters'> を含む)L<C<use locale>|locale> が有効で、 | |
16780 | L<C<POSIX::setlocale>|POSIX/C<setlocale>> が呼び出されている場合、 | |
14062 | 16781 | フォーマットされた浮動小数点数の小数点として使われる文字は |
14063 | LC_NUMERIC ロケールの影響を受けます。 | |
16782 | C<LC_NUMERIC> ロケールの影響を受けます。 | |
14064 | 16783 | L<perllocale> と L<POSIX> を参照してください。 |
14065 | 16784 | |
14066 | 16785 | =item sqrt EXPR |
14067 | 16786 | X<sqrt> X<root> X<square root> |
14068 | 16787 | |
14069 | 16788 | =item sqrt |
14070 | 16789 | |
16790 | =for Pod::Functions square root function | |
16791 | ||
14071 | 16792 | =begin original |
14072 | 16793 | |
14073 | 16794 | Return the positive square root of EXPR. If EXPR is omitted, uses |
14074 | C<$_>. Works only for non-negative operands unless you've | |
16795 | L<C<$_>|perlvar/$_>. Works only for non-negative operands unless you've | |
14075 | loaded the C<Math::Complex> module. | |
16796 | loaded the L<C<Math::Complex>|Math::Complex> module. | |
14076 | 16797 | |
14077 | 16798 | =end original |
14078 | 16799 | |
14079 | 16800 | EXPR の正の平方根を返します。 |
14080 | EXPR | |
16801 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
14081 | C<Math::Complex> モジュールを使わない場合は、負の数の引数は | |
16802 | L<C<Math::Complex>|Math::Complex> モジュールを使わない場合は、負の数の引数は | |
16803 | 扱えません。 | |
14082 | 16804 | |
14083 | 16805 | use Math::Complex; |
14084 | 16806 | print sqrt(-4); # prints 2i |
14085 | 16807 | |
14086 | 16808 | =item srand EXPR |
14087 | 16809 | X<srand> X<seed> X<randseed> |
14088 | 16810 | |
14089 | 16811 | =item srand |
14090 | 16812 | |
16813 | =for Pod::Functions seed the random number generator | |
16814 | ||
14091 | 16815 | =begin original |
14092 | 16816 | |
14093 | Sets and returns the random number seed for the C<rand> | |
16817 | Sets and returns the random number seed for the L<C<rand>|/rand EXPR> | |
16818 | operator. | |
14094 | 16819 | |
14095 | 16820 | =end original |
14096 | 16821 | |
14097 | C<rand> 演算子のためのシード値を設定して返します。 | |
16822 | L<C<rand>|/rand EXPR> 演算子のためのシード値を設定して返します。 | |
14098 | 16823 | |
14099 | 16824 | =begin original |
14100 | 16825 | |
14101 | The point of the function is to "seed" the C<rand> | |
16826 | The point of the function is to "seed" the L<C<rand>|/rand EXPR> | |
14102 | C<rand> can produce a different sequence | |
16827 | function so that L<C<rand>|/rand EXPR> can produce a different sequence | |
14103 | program. When called with a parameter, | |
16828 | each time you run your program. When called with a parameter, | |
14104 | ||
16829 | L<C<srand>|/srand EXPR> uses that for the seed; otherwise it | |
14105 | ||
16830 | (semi-)randomly chooses a seed. In either case, starting with Perl 5.14, | |
16831 | it returns the seed. To signal that your code will work I<only> on Perls | |
16832 | of a recent vintage: | |
14106 | 16833 | |
14107 | 16834 | =end original |
14108 | 16835 | |
14109 | この関数のポイントは、プログラムを実行するごとに C<rand> 関数が | |
16836 | この関数のポイントは、プログラムを実行するごとに L<C<rand>|/rand EXPR> 関数が | |
14110 | 異なる乱数列を生成できるように C<rand> 関数の「種」を | |
16837 | 異なる乱数列を生成できるように L<C<rand>|/rand EXPR> 関数の「種」を | |
14111 | ||
16838 | 設定することです。 | |
14112 | ||
16839 | L<C<srand>|/srand EXPR> を引数付きで呼び出すと、これを種として使います; | |
16840 | さもなければ(だいたい)ランダムに種を選びます。 | |
14113 | 16841 | どちらの場合でも、Perl 5.14 からは種を返します。 |
16842 | 特定の時期の Perl I<でのみ> 動作することを知らせるには以下のようにします: | |
14114 | 16843 | |
14115 | ||
16844 | use 5.014; # so srand returns the seed | |
14116 | 16845 | |
14117 | If C<srand()> is not called explicitly, it is called implicitly without a | |
14118 | parameter at the first use of the C<rand> operator. However, this was not true | |
14119 | of versions of Perl before 5.004, so if your script will run under older | |
14120 | Perl versions, it should call C<srand>; otherwise most programs won't call | |
14121 | C<srand()> at all. | |
14122 | ||
14123 | =end original | |
14124 | ||
14125 | C<srand()> が明示的に呼び出されなかった場合、最初に C<rand> 演算子を使った | |
14126 | 時点で暗黙に引数なしで呼び出されます。 | |
14127 | しかし、これは Perl のバージョンが 5.004 より前では行われませんので、 | |
14128 | プログラムが古い Perl で実行される場合は、C<srand> を呼ぶべきです; | |
14129 | さもなければ、ほとんどのプログラムは C<srand()> を一切呼び出す必要は | |
14130 | ありません。 | |
14131 | ||
14132 | 16846 | =begin original |
14133 | 16847 | |
14134 | ||
16848 | If L<C<srand>|/srand EXPR> is not called explicitly, it is called | |
14135 | ||
16849 | implicitly without a parameter at the first use of the | |
14136 | ||
16850 | L<C<rand>|/rand EXPR> operator. However, there are a few situations | |
14137 | ||
16851 | where programs are likely to want to call L<C<srand>|/srand EXPR>. One | |
14138 | s | |
16852 | is for generating predictable results, generally for testing or | |
14139 | ||
16853 | debugging. There, you use C<srand($seed)>, with the same C<$seed> each | |
14140 | i | |
16854 | time. Another case is that you may want to call L<C<srand>|/srand EXPR> | |
14141 | after a C<fork | |
16855 | after a L<C<fork>|/fork> to avoid child processes sharing the same seed | |
14142 | parent (and consequently each other). | |
16856 | value as the parent (and consequently each other). | |
14143 | 16857 | |
14144 | 16858 | =end original |
14145 | 16859 | |
14146 | ||
16860 | L<C<srand>|/srand EXPR> が明示的に呼び出されなかった場合、最初に | |
14147 | ||
16861 | L<C<rand>|/rand EXPR> 演算子を使った時点で暗黙に引数なしで呼び出されます。 | |
16862 | しかし、最近の Perl でプログラムが L<C<srand>|/srand EXPR> を | |
16863 | 呼び出したいであろう状況がいくつかあります。 | |
14148 | 16864 | 一つはテストやデバッグのために予測可能な結果を生成するためです。 |
14149 | 16865 | この場合、C<srand($seed)> (C<$seed> は毎回同じ値を使う) を使います。 |
14150 | もう一つの場合は、時刻、プロセス ID、メモリ配置、(利用可能なら) F</dev/urandom> | |
14151 | デバイスといった、一般的に受け入れられるデフォルトよりも暗号学的に | |
14152 | 強力な開始点が必要な場合です。 | |
14153 | 16866 | もう一つの場合としては、子プロセスが親や他の子プロセスと同じ種の値を |
14154 | 共有することを避けるために、C<fork | |
16867 | 共有することを避けるために、L<C<fork>|/fork> の後に L<C<srand>|/srand EXPR> を | |
14155 | 16868 | 呼び出したいかもしれません。 |
14156 | 16869 | |
14157 | 16870 | =begin original |
14158 | 16871 | |
14159 | 16872 | Do B<not> call C<srand()> (i.e., without an argument) more than once per |
14160 | 16873 | process. The internal state of the random number generator should |
14161 | 16874 | contain more entropy than can be provided by any seed, so calling |
14162 | C<srand | |
16875 | L<C<srand>|/srand EXPR> again actually I<loses> randomness. | |
14163 | 16876 | |
14164 | 16877 | =end original |
14165 | 16878 | |
14166 | C<srand | |
16879 | L<C<srand>|/srand EXPR> (引数なし)をプロセス中で複数回 | |
16880 | 呼び出しては B<いけません>。 | |
14167 | 16881 | 乱数生成器の内部状態はどのような種によって提供されるものよりも |
14168 | 16882 | 高いエントロピーを持っているので、C<srand()> を再び呼び出すと |
14169 | 16883 | ランダム性が I<失われます>。 |
14170 | 16884 | |
14171 | 16885 | =begin original |
14172 | 16886 | |
14173 | Most implementations of C<srand> take an integer and will | |
16887 | Most implementations of L<C<srand>|/srand EXPR> take an integer and will | |
16888 | silently | |
14174 | 16889 | truncate decimal numbers. This means C<srand(42)> will usually |
14175 | 16890 | produce the same results as C<srand(42.1)>. To be safe, always pass |
14176 | C<srand> an integer. | |
16891 | L<C<srand>|/srand EXPR> an integer. | |
14177 | 16892 | |
14178 | 16893 | =end original |
14179 | 16894 | |
14180 | C<srand> のほとんどの実装では整数を取り、小数を暗黙に | |
16895 | L<C<srand>|/srand EXPR> のほとんどの実装では整数を取り、小数を暗黙に | |
14181 | ||
16896 | 切り捨てます。 | |
14182 | 意味します。 | |
16897 | これは、C<srand(42)> は普通 C<srand(42.1)> と同じ結果になることを意味します。 | |
14183 | 安全のために、C<srand> には常に整数を渡しましょう。 | |
16898 | 安全のために、L<C<srand>|/srand EXPR> には常に整数を渡しましょう。 | |
14184 | 16899 | |
14185 | 16900 | =begin original |
14186 | 16901 | |
14187 | In versions of Perl prior to 5.004 the default seed was just the | |
14188 | current C<time>. This isn't a particularly good seed, so many old | |
14189 | programs supply their own seed value (often C<time ^ $$> or C<time ^ | |
14190 | ($$ + ($$ << 15))>), but that isn't necessary any more. | |
14191 | ||
14192 | =end original | |
14193 | ||
14194 | 5.004 以前の Perl では、デフォルトのシード値は現在の C<time> でした。 | |
14195 | これは特によいシード値ではありませんでしたので、 | |
14196 | 多くの古いプログラムは自力でシード値を指定しています | |
14197 | (C<time ^ $$> または C<time ^ ($$ + ($$ << 15))> がよく使われました)が、 | |
14198 | もはやこれは必要ありません。 | |
14199 | ||
14200 | =begin original | |
14201 | ||
14202 | For cryptographic purposes, however, you need something much more random | |
14203 | than the default seed. Checksumming the compressed output of one or more | |
14204 | rapidly changing operating system status programs is the usual method. For | |
14205 | example: | |
14206 | ||
14207 | =end original | |
14208 | ||
14209 | しかし、暗号処理にはもっとランダムな値を使う必要があります。 | |
14210 | 急激に変化する OS のステータス値プログラムの出力をひとつまたは複数用い、 | |
14211 | 圧縮してチェックサムをとる、というようなことが普通行なわれます。 | |
14212 | 例えば: | |
14213 | ||
14214 | srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip -f`); | |
14215 | ||
14216 | =begin original | |
14217 | ||
14218 | If you're particularly concerned with this, search the CPAN for | |
14219 | random number generator modules instead of rolling out your own. | |
14220 | ||
14221 | =end original | |
14222 | ||
14223 | 特にこのようなことに関心がある場合は、自分で処理せずに、 | |
14224 | CPAN の乱数発生モジュールを探してください。 | |
14225 | ||
14226 | =begin original | |
14227 | ||
14228 | Frequently called programs (like CGI scripts) that simply use | |
14229 | ||
14230 | =end original | |
14231 | ||
14232 | (CGI スクリプトのような)頻繁に呼び出されるプログラムで単純に | |
14233 | ||
14234 | time ^ $$ | |
14235 | ||
14236 | =begin original | |
14237 | ||
14238 | for a seed can fall prey to the mathematical property that | |
14239 | ||
14240 | =end original | |
14241 | ||
14242 | を種として使うと、3 回に 1 回は以下の数学特性 | |
14243 | ||
14244 | a^b == (a+1)^(b+1) | |
14245 | ||
14246 | =begin original | |
14247 | ||
14248 | one-third of the time. So don't do that. | |
14249 | ||
14250 | =end original | |
14251 | ||
14252 | の餌食になります。 | |
14253 | 従ってこのようなことはしてはいけません。 | |
14254 | ||
14255 | =begin original | |
14256 | ||
14257 | 16902 | A typical use of the returned seed is for a test program which has too many |
14258 | 16903 | combinations to test comprehensively in the time available to it each run. It |
14259 | 16904 | can test a random subset each time, and should there be a failure, log the seed |
14260 | 16905 | used for that run so that it can later be used to reproduce the same results. |
14261 | 16906 | |
14262 | 16907 | =end original |
14263 | 16908 | |
14264 | 16909 | 返された種の典型的な利用法は、実行毎のテストを利用可能な時間内に完全に |
14265 | 16910 | 行うには組み合わせが多すぎるテストプログラム用です。 |
14266 | 16911 | 毎回ランダムなサブセットをテストし、もし失敗したら、その実行で使った |
14267 | 16912 | 種をログに出力することで、後で同じ結果を再現するために使えます。 |
14268 | 16913 | |
16914 | =begin original | |
16915 | ||
16916 | B<L<C<rand>|/rand EXPR> is not cryptographically secure. You should not rely | |
16917 | on it in security-sensitive situations.> As of this writing, a | |
16918 | number of third-party CPAN modules offer random number generators | |
16919 | intended by their authors to be cryptographically secure, | |
16920 | including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>, | |
16921 | and L<Math::TrulyRandom>. | |
16922 | ||
16923 | =end original | |
16924 | ||
16925 | B<L<C<rand>|/rand EXPR> は暗号学的に安全ではありません。 | |
16926 | セキュリティ的に重要な状況でこれに頼るべきではありません。> | |
16927 | これを書いている時点で、いくつかのサードパーティ CPAN モジュールが | |
16928 | 作者によって暗号学的に安全であることを目的とした乱数生成器を | |
16929 | 提供しています: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>, | |
16930 | L<Math::TrulyRandom> などです。 | |
16931 | ||
14269 | 16932 | =item stat FILEHANDLE |
14270 | 16933 | X<stat> X<file, status> X<ctime> |
14271 | 16934 | |
14272 | 16935 | =item stat EXPR |
14273 | 16936 | |
14274 | 16937 | =item stat DIRHANDLE |
14275 | 16938 | |
14276 | 16939 | =item stat |
14277 | 16940 | |
16941 | =for Pod::Functions get a file's status information | |
16942 | ||
14278 | 16943 | =begin original |
14279 | 16944 | |
14280 | 16945 | Returns a 13-element list giving the status info for a file, either |
14281 | the file opened via FILEHANDLE or DIRHANDLE, or named by EXPR. If EXPR is | |
16946 | the file opened via FILEHANDLE or DIRHANDLE, or named by EXPR. If EXPR is | |
14282 | omitted, it stats C<$_> (not C<_>!). Returns the empt | |
16947 | omitted, it stats L<C<$_>|perlvar/$_> (not C<_>!). Returns the empty | |
16948 | list if L<C<stat>|/stat FILEHANDLE> fails. Typically | |
14283 | 16949 | used as follows: |
14284 | 16950 | |
14285 | 16951 | =end original |
14286 | 16952 | |
14287 | 16953 | FILEHANDLE か DIRHANDLE を通じてオープンされているファイルか、 |
14288 | 16954 | EXPR で指定されるファイルの情報を与える、13 要素のリストを返します。 |
14289 | EXPR が省略されると、 C<$_> が用いられます | |
16955 | EXPR が省略されると、 L<C<$_>|perlvar/$_> が用いられます | |
14290 | C< | |
16956 | (C<_> ではありません!)。 | |
16957 | L<C<stat>|/stat FILEHANDLE> に失敗した場合には、空リストを返します。 | |
14291 | 16958 | 普通は、以下のようにして使います: |
14292 | 16959 | |
14293 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, | |
16960 | my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, | |
14294 | $atime,$mtime,$ctime,$blksize,$blocks) | |
16961 | $atime,$mtime,$ctime,$blksize,$blocks) | |
14295 | 16962 | = stat($filename); |
14296 | 16963 | |
14297 | 16964 | =begin original |
14298 | 16965 | |
14299 | 16966 | Not all fields are supported on all filesystem types. Here are the |
14300 | 16967 | meanings of the fields: |
14301 | 16968 | |
14302 | 16969 | =end original |
14303 | 16970 | |
14304 | 16971 | 全てのファイルシステムで全てのフィールドに対応しているわけではありません。 |
14305 | 16972 | フィールドの意味は以下の通りです。 |
14306 | 16973 | |
14307 | 16974 | =begin original |
14308 | 16975 | |
14309 | 16976 | 0 dev device number of filesystem |
14310 | 16977 | 1 ino inode number |
14311 | 16978 | 2 mode file mode (type and permissions) |
14312 | 16979 | 3 nlink number of (hard) links to the file |
14313 | 16980 | 4 uid numeric user ID of file's owner |
14314 | 16981 | 5 gid numeric group ID of file's owner |
14315 | 16982 | 6 rdev the device identifier (special files only) |
14316 | 16983 | 7 size total size of file, in bytes |
14317 | 16984 | 8 atime last access time in seconds since the epoch |
14318 | 16985 | 9 mtime last modify time in seconds since the epoch |
14319 | 16986 | 10 ctime inode change time in seconds since the epoch (*) |
14320 | 11 blksize preferred | |
16987 | 11 blksize preferred I/O size in bytes for interacting with the | |
14321 | | |
16988 | file (may vary from file to file) | |
16989 | 12 blocks actual number of system-specific blocks allocated | |
16990 | on disk (often, but not always, 512 bytes each) | |
14322 | 16991 | |
14323 | 16992 | =end original |
14324 | 16993 | |
14325 | 16994 | 0 dev ファイルシステムのデバイス番号 |
14326 | 16995 | 1 ino inode 番号 |
14327 | 16996 | 2 mode ファイルモード (タイプとパーミッション) |
14328 | 16997 | 3 nlink ファイルへの(ハード)リンクの数 |
14329 | 16998 | 4 uid ファイル所有者のユーザー ID の数値 |
14330 | 16999 | 5 gid ファイル所有者のグループ ID の数値 |
14331 | 17000 | 6 rdev デバイス識別子(特殊ファイルのみ) |
14332 | 17001 | 7 size ファイルサイズ(バイト単位) |
14333 | 17002 | 8 atime 紀元から、最後にアクセスされた時刻までの秒数 |
14334 | 17003 | 9 mtime 紀元から、最後に修正(modify)された時刻までの秒数 |
14335 | 17004 | 10 ctime 紀元から、inode 変更(change)された時刻までの秒数 (*) |
14336 | 11 blksize ファイル | |
17005 | 11 blksize ファイルとの相互作用のために適した I/O バイト数 | |
14337 | | |
17006 | (ファイルごとに異なるかもしれない) | |
17007 | 12 blocks ディスクに割り当てたシステム依存のブロック(常にでは | |
17008 | ありませんがたいていはそれぞれ 512 バイト)の数 | |
14338 | 17009 | |
14339 | 17010 | =begin original |
14340 | 17011 | |
14341 | 17012 | (The epoch was at 00:00 January 1, 1970 GMT.) |
14342 | 17013 | |
14343 | 17014 | =end original |
14344 | 17015 | |
14345 | (紀元は GMT で 1970/01/01 00:00:00) | |
17016 | (紀元は GMT で 1970/01/01 00:00:00。) | |
14346 | 17017 | |
14347 | 17018 | =begin original |
14348 | 17019 | |
14349 | (*) Not all fields are supported on all filesystem types. Notably, the | |
17020 | (*) Not all fields are supported on all filesystem types. Notably, the | |
14350 | 17021 | ctime field is non-portable. In particular, you cannot expect it to be a |
14351 | 17022 | "creation time"; see L<perlport/"Files and Filesystems"> for details. |
14352 | 17023 | |
14353 | 17024 | =end original |
14354 | 17025 | |
14355 | 17026 | (*) 全てのフィールドが全てのファイルシステムタイプで対応しているわけでは |
14356 | 17027 | ありません。 |
14357 | 17028 | 明らかに、ctime のフィールドは移植性がありません。 |
14358 | 17029 | 特に、これから「作成時刻」を想定することは出来ません; |
14359 | 17030 | 詳細については L<perlport/"Files and Filesystems"> を参照してください。 |
14360 | 17031 | |
14361 | 17032 | =begin original |
14362 | 17033 | |
14363 | If C<stat> is passed the special filehandle | |
17034 | If L<C<stat>|/stat FILEHANDLE> is passed the special filehandle | |
14364 | stat is done, but the current contents of | |
17035 | consisting of an underline, no stat is done, but the current contents of | |
14365 | ||
17036 | the stat structure from the last L<C<stat>|/stat FILEHANDLE>, | |
17037 | L<C<lstat>|/lstat FILEHANDLE>, or filetest are returned. Example: | |
14366 | 17038 | |
14367 | 17039 | =end original |
14368 | 17040 | |
14369 | 下線だけの _ という特別なファイルハンドルを C<stat> に | |
17041 | 下線だけの _ という特別なファイルハンドルを L<C<stat>|/stat FILEHANDLE> に | |
14370 | 実際には stat を行なわず、stat 構造体に残っている | |
17042 | 渡すと、実際には stat を行なわず、stat 構造体に残っている | |
14371 | 前回の stat や | |
17043 | 前回の L<C<stat>|/stat FILEHANDLE>, L<C<lstat>|/lstat FILEHANDLE> や | |
17044 | ファイルテストの情報が返されます。 | |
14372 | 17045 | 例: |
14373 | 17046 | |
14374 | 17047 | if (-x $file && (($d) = stat(_)) && $d < 0) { |
14375 | 17048 | print "$file is executable NFS file\n"; |
14376 | 17049 | } |
14377 | 17050 | |
14378 | 17051 | =begin original |
14379 | 17052 | |
14380 | 17053 | (This works on machines only for which the device number is negative |
14381 | 17054 | under NFS.) |
14382 | 17055 | |
14383 | 17056 | =end original |
14384 | 17057 | |
14385 | (これは、NFS のもとでデバイス番号が負になるマシンで | |
17058 | (これは、NFS のもとでデバイス番号が負になるマシンでのみ動作します。) | |
14386 | のみ動作します。) | |
14387 | 17059 | |
14388 | 17060 | =begin original |
14389 | 17061 | |
14390 | 17062 | Because the mode contains both the file type and its permissions, you |
14391 | 17063 | should mask off the file type portion and (s)printf using a C<"%o"> |
14392 | 17064 | if you want to see the real permissions. |
14393 | 17065 | |
14394 | 17066 | =end original |
14395 | 17067 | |
14396 | 17068 | モードにはファイルタイプとその権限の両方が含まれているので、 |
14397 | 17069 | 本当の権限を見たい場合は、(s)printf で C<"%"> を使うことで |
14398 | 17070 | ファイルタイプをマスクするべきです。 |
14399 | 17071 | |
14400 | $mode = (stat($filename))[2]; | |
17072 | my $mode = (stat($filename))[2]; | |
14401 | 17073 | printf "Permissions are %04o\n", $mode & 07777; |
14402 | 17074 | |
14403 | 17075 | =begin original |
14404 | 17076 | |
14405 | In scalar context, C<stat> returns a boolean value | |
17077 | In scalar context, L<C<stat>|/stat FILEHANDLE> returns a boolean value | |
17078 | indicating success | |
14406 | 17079 | or failure, and, if successful, sets the information associated with |
14407 | 17080 | the special filehandle C<_>. |
14408 | 17081 | |
14409 | 17082 | =end original |
14410 | 17083 | |
14411 | スカラコンテキストでは、C<stat> は成功か失敗を表す真偽値を | |
17084 | スカラコンテキストでは、L<C<stat>|/stat FILEHANDLE> は成功か失敗を表す真偽値を | |
14412 | 成功した場合は、特別なファイルハンドル C<_> に結び付けられた | |
17085 | 返し、成功した場合は、特別なファイルハンドル C<_> に結び付けられた | |
14413 | 17086 | 情報をセットします。 |
14414 | 17087 | |
14415 | 17088 | =begin original |
14416 | 17089 | |
14417 | 17090 | The L<File::stat> module provides a convenient, by-name access mechanism: |
14418 | 17091 | |
14419 | 17092 | =end original |
14420 | 17093 | |
14421 | 17094 | L<File::stat> モジュールは、便利な名前によるアクセス機構を提供します。 |
14422 | 17095 | |
14423 | 17096 | use File::stat; |
14424 | $sb = stat($filename); | |
17097 | my $sb = stat($filename); | |
14425 | 17098 | printf "File is %s, size is %s, perm %04o, mtime %s\n", |
14426 | 17099 | $filename, $sb->size, $sb->mode & 07777, |
14427 | 17100 | scalar localtime $sb->mtime; |
14428 | 17101 | |
14429 | 17102 | =begin original |
14430 | 17103 | |
14431 | 17104 | You can import symbolic mode constants (C<S_IF*>) and functions |
14432 | (C<S_IS*>) from the Fcntl module: | |
17105 | (C<S_IS*>) from the L<Fcntl> module: | |
14433 | 17106 | |
14434 | 17107 | =end original |
14435 | 17108 | |
14436 | モード定数 (C<S_IF*>) と関数 (C<S_IS*>) を Fcntl モジュールから | |
17109 | モード定数 (C<S_IF*>) と関数 (C<S_IS*>) を L<Fcntl> モジュールから | |
14437 | 17110 | インポートできます。 |
14438 | 17111 | |
14439 | 17112 | use Fcntl ':mode'; |
14440 | 17113 | |
14441 | $mode = (stat($filename))[2]; | |
17114 | my $mode = (stat($filename))[2]; | |
14442 | 17115 | |
14443 | $user_rwx = ($mode & S_IRWXU) >> 6; | |
17116 | my $user_rwx = ($mode & S_IRWXU) >> 6; | |
14444 | $group_read = ($mode & S_IRGRP) >> 3; | |
17117 | my $group_read = ($mode & S_IRGRP) >> 3; | |
14445 | $other_execute = $mode & S_IXOTH; | |
17118 | my $other_execute = $mode & S_IXOTH; | |
14446 | 17119 | |
14447 | 17120 | printf "Permissions are %04o\n", S_IMODE($mode), "\n"; |
14448 | 17121 | |
14449 | $is_setuid = $mode & S_ISUID; | |
17122 | my $is_setuid = $mode & S_ISUID; | |
14450 | $is_directory = S_ISDIR($mode); | |
17123 | my $is_directory = S_ISDIR($mode); | |
14451 | 17124 | |
14452 | 17125 | =begin original |
14453 | 17126 | |
14454 | 17127 | You could write the last two using the C<-u> and C<-d> operators. |
14455 | 17128 | Commonly available C<S_IF*> constants are: |
14456 | 17129 | |
14457 | 17130 | =end original |
14458 | 17131 | |
14459 | 17132 | 最後の二つは C<-u> と C<-d> 演算子を使っても書けます。 |
14460 | 17133 | 一般に利用可能な C<S_IF*> 定数は以下のものです。 |
14461 | 17134 | |
14462 | 17135 | # Permissions: read, write, execute, for user, group, others. |
14463 | 17136 | |
14464 | 17137 | S_IRWXU S_IRUSR S_IWUSR S_IXUSR |
14465 | 17138 | S_IRWXG S_IRGRP S_IWGRP S_IXGRP |
14466 | 17139 | S_IRWXO S_IROTH S_IWOTH S_IXOTH |
14467 | 17140 | |
14468 | 17141 | # Setuid/Setgid/Stickiness/SaveText. |
14469 | # Note that the exact meaning of these is system | |
17142 | # Note that the exact meaning of these is system-dependent. | |
14470 | 17143 | |
14471 | 17144 | S_ISUID S_ISGID S_ISVTX S_ISTXT |
14472 | 17145 | |
14473 | # File types. Not necessarily a | |
17146 | # File types. Not all are necessarily available on | |
17147 | # your system. | |
14474 | 17148 | |
14475 | S_IFREG S_IFDIR S_IFLNK S_IFBLK S_IFCHR | |
17149 | S_IFREG S_IFDIR S_IFLNK S_IFBLK S_IFCHR | |
17150 | S_IFIFO S_IFSOCK S_IFWHT S_ENFMT | |
14476 | 17151 | |
14477 | # The following are compatibility aliases for S_IRUSR, | |
17152 | # The following are compatibility aliases for S_IRUSR, | |
17153 | # S_IWUSR, and S_IXUSR. | |
14478 | 17154 | |
14479 | 17155 | S_IREAD S_IWRITE S_IEXEC |
14480 | 17156 | |
14481 | 17157 | =begin original |
14482 | 17158 | |
14483 | 17159 | and the C<S_IF*> functions are |
14484 | 17160 | |
14485 | 17161 | =end original |
14486 | 17162 | |
14487 | 17163 | 一般に利用可能な C<S_IF*> 関数は以下のものです。 |
14488 | 17164 | |
14489 | S_IMODE($mode) the part of $mode containing the permission | |
17165 | S_IMODE($mode) the part of $mode containing the permission | |
14490 | and the setuid/setgid/sticky bits | |
17166 | bits and the setuid/setgid/sticky bits | |
14491 | 17167 | |
14492 | S_IFMT($mode) the part of $mode containing the file type | |
17168 | S_IFMT($mode) the part of $mode containing the file type | |
14493 | which can be bit-anded with (for example) | |
17169 | which can be bit-anded with (for example) | |
14494 | | |
17170 | S_IFREG or with the following functions | |
14495 | 17171 | |
14496 | 17172 | # The operators -f, -d, -l, -b, -c, -p, and -S. |
14497 | 17173 | |
14498 | 17174 | S_ISREG($mode) S_ISDIR($mode) S_ISLNK($mode) |
14499 | 17175 | S_ISBLK($mode) S_ISCHR($mode) S_ISFIFO($mode) S_ISSOCK($mode) |
14500 | 17176 | |
14501 | 17177 | # No direct -X operator counterpart, but for the first one |
14502 | 17178 | # the -g operator is often equivalent. The ENFMT stands for |
14503 | 17179 | # record flocking enforcement, a platform-dependent feature. |
14504 | 17180 | |
14505 | 17181 | S_ISENFMT($mode) S_ISWHT($mode) |
14506 | 17182 | |
14507 | 17183 | =begin original |
14508 | 17184 | |
14509 | See your native chmod(2) and stat(2) documentation for more details | |
17185 | See your native L<chmod(2)> and L<stat(2)> documentation for more details | |
14510 | 17186 | about the C<S_*> constants. To get status info for a symbolic link |
14511 | instead of the target file behind the link, use the | |
17187 | instead of the target file behind the link, use the | |
17188 | L<C<lstat>|/lstat FILEHANDLE> function. | |
14512 | 17189 | |
14513 | 17190 | =end original |
14514 | 17191 | |
14515 | C<S_*> 定数に関する詳細についてはネイティブの chmod(2) と stat(2) の | |
17192 | C<S_*> 定数に関する詳細についてはネイティブの L<chmod(2)> と L<stat(2)> の | |
14516 | ドキュメントを参照して | |
17193 | ドキュメントを参照してください。 | |
14517 | 17194 | リンクの先にあるファイルではなく、シンボリックリンクそのものの情報を |
14518 | 得たい場合は、C<lstat> 関数を使ってください。 | |
17195 | 得たい場合は、L<C<lstat>|/lstat FILEHANDLE> 関数を使ってください。 | |
14519 | 17196 | |
14520 | = | |
17197 | =begin original | |
17198 | ||
17199 | Portability issues: L<perlport/stat>. | |
17200 | ||
17201 | =end original | |
17202 | ||
17203 | 移植性の問題: L<perlport/stat>。 | |
17204 | ||
17205 | =item state VARLIST | |
14521 | 17206 | X<state> |
14522 | 17207 | |
14523 | =item state TYPE | |
17208 | =item state TYPE VARLIST | |
14524 | 17209 | |
14525 | =item state | |
17210 | =item state VARLIST : ATTRS | |
14526 | 17211 | |
14527 | =item state TYPE | |
17212 | =item state TYPE VARLIST : ATTRS | |
14528 | 17213 | |
17214 | =for Pod::Functions +state declare and assign a persistent lexical variable | |
17215 | ||
14529 | 17216 | =begin original |
14530 | 17217 | |
14531 | C<state> declares a lexically scoped variable, just | |
17218 | L<C<state>|/state VARLIST> declares a lexically scoped variable, just | |
17219 | like L<C<my>|/my VARLIST>. | |
14532 | 17220 | However, those variables will never be reinitialized, contrary to |
14533 | 17221 | lexical variables that are reinitialized each time their enclosing block |
14534 | 17222 | is entered. |
17223 | See L<perlsub/"Persistent Private Variables"> for details. | |
14535 | 17224 | |
14536 | 17225 | =end original |
14537 | 17226 | |
14538 | C<state> は C<my> と同様に、 | |
17227 | L<C<state>|/state VARLIST> はちょうど L<C<my>|/my VARLIST> と同様に、 | |
14539 | ||
17228 | レキシカルなスコープの変数を宣言します。 | |
14540 | ||
17229 | しかし、レキシカル変数がブロックに入る毎に再初期化されるのと異なり、 | |
17230 | この変数は決して再初期化されません。 | |
17231 | 詳しくは L<perlsub/"Persistent Private Variables"> を参照してください。 | |
14541 | 17232 | |
14542 | 17233 | =begin original |
14543 | 17234 | |
14544 | ||
17235 | If more than one variable is listed, the list must be placed in | |
14545 | ||
17236 | parentheses. With a parenthesised list, L<C<undef>|/undef EXPR> can be | |
17237 | used as a | |
17238 | dummy placeholder. However, since initialization of state variables in | |
17239 | list context is currently not possible this would serve no purpose. | |
14546 | 17240 | |
14547 | 17241 | =end original |
14548 | 17242 | |
14549 | ||
17243 | 複数の変数を指定する場合、かっこで囲まなければなりません。 | |
14550 | L< | |
17244 | かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> はダミーの | |
17245 | プレースホルダとして使えます。 | |
17246 | しかし、リストコンテキストでの state 変数の初期化は現在のところできないので、 | |
17247 | これは無意味です。 | |
14551 | 17248 | |
17249 | =begin original | |
17250 | ||
17251 | L<C<state>|/state VARLIST> is available only if the | |
17252 | L<C<"state"> feature|feature/The 'state' feature> is enabled or if it is | |
17253 | prefixed with C<CORE::>. The | |
17254 | L<C<"state"> feature|feature/The 'state' feature> is enabled | |
17255 | automatically with a C<use v5.10> (or higher) declaration in the current | |
17256 | scope. | |
17257 | ||
17258 | =end original | |
17259 | ||
17260 | L<C<state>|/state VARLIST> は | |
17261 | L<C<"state"> 機能|feature/The 'state' feature> が有効か C<CORE::> を | |
17262 | 前置した場合にのみ利用可能です。 | |
17263 | L<C<"state"> 機能|feature/The 'state' feature> は現在のスコープで | |
17264 | C<use v5.10> (またはそれ以上) を宣言した場合自動的に有効になります。 | |
17265 | ||
14552 | 17266 | =item study SCALAR |
14553 | 17267 | X<study> |
14554 | 17268 | |
14555 | 17269 | =item study |
14556 | 17270 | |
17271 | =for Pod::Functions optimize input data for repeated searches | |
17272 | ||
14557 | 17273 | =begin original |
14558 | 17274 | |
14559 | ||
17275 | B<Note that since Perl version 5.16 this function has been a no-op, but | |
14560 | ||
17276 | this might change in a future release.> | |
17277 | ||
17278 | =end original | |
17279 | ||
17280 | B<Perl バージョン 5.16 からこの関数は何もしませんが、これは将来のリリースで | |
17281 | 変更されるかもしれないことに注意してください。> | |
17282 | ||
17283 | =begin original | |
17284 | ||
17285 | May take extra time to study SCALAR (L<C<$_>|perlvar/$_> if unspecified) | |
17286 | in anticipation | |
17287 | of doing many pattern matches on the string before it is next modified. | |
14561 | 17288 | This may or may not save time, depending on the nature and number of |
14562 | 17289 | patterns you are searching and the distribution of character |
14563 | 17290 | frequencies in the string to be searched; you probably want to compare |
14564 | 17291 | run times with and without it to see which is faster. Those loops |
14565 | 17292 | that scan for many short constant strings (including the constant |
14566 | parts of more complex patterns) will benefit most. | |
17293 | parts of more complex patterns) will benefit most. | |
14567 | ||
14568 | ||
17295 | =end original | |
17296 | ||
17297 | 次に変更される前に、この文字列で多くのパターンマッチングを行うと予想して | |
17298 | SCALAR (未指定の場合は L<C<$_>|perlvar/$_>) を学習するために追加の時間を | |
17299 | 使います。 | |
17300 | これは、検索するパターンの数と性質、および検索される文字列の文字頻度の | |
17301 | 分散によって、時間短縮になることもならないことにもなります; | |
17302 | おそらくどちらが速いかを調べるためにこれありとなしとで実行時間を | |
17303 | 比較した方がよいでしょう。 | |
17304 | 多くの短い固定文字列(より複雑なパターンの固定部分を含む)をスキャンする | |
17305 | ループで最も効果があります。 | |
17306 | ||
17307 | =begin original | |
17308 | ||
17309 | (The way L<C<study>|/study SCALAR> used to work is this: a linked list | |
17310 | of every | |
14569 | 17311 | character in the string to be searched is made, so we know, for |
14570 | 17312 | example, where all the C<'k'> characters are. From each search string, |
14571 | 17313 | the rarest character is selected, based on some static frequency tables |
14572 | 17314 | constructed from some C programs and English text. Only those places |
14573 | 17315 | that contain this "rarest" character are examined.) |
14574 | 17316 | |
14575 | 17317 | =end original |
14576 | 17318 | |
14577 | 次 | |
17319 | (L<C<study>|/study SCALAR> の動作方法は次のものでした: 検索される文字列の | |
14578 | ||
17320 | 全ての文字のリンクリストが作られるので、例えば、全ての C<'k'> 文字が | |
14579 | ||
17321 | どこにあるかを知ります。 | |
14580 | ||
17322 | 各検索文字列から、いくつかの C プログラムと英文から構築された | |
14581 | ||
17323 | 静的頻度テーブルを基に最も頻度の少ない文字が選ばれます。 | |
14582 | ||
17324 | この「もっとも稀な」文字を含む場所のみが調べられます。) | |
14583 | ことになるかもしれません。 | |
14584 | 予習をした場合と、しない場合の実行時間を比較して、 | |
14585 | どちらが速いか調べることが、必要でしょう。 | |
14586 | 短い固定文字列 (複雑なパターンの固定部分を含みます) をたくさん | |
14587 | 検索するループで、もっとも効果があるでしょう。 | |
14588 | 同時には、一つの C<study>だけが有効です。 | |
14589 | 別のスカラを study した場合には、以前に学習した内容は | |
14590 | 「忘却」されてしまいます。 | |
14591 | (この C<study> の仕組みは、まず、検索される文字列内の | |
14592 | すべての文字のリンクされたリストが作られ、たとえば、 | |
14593 | すべての C<'k'> がどこにあるかがわかるようになります。 | |
14594 | 各々の検索文字列から、C プログラムや英語のテキストから作られた | |
14595 | 頻度の統計情報に基づいて、もっとも珍しい文字が選ばれます。 | |
14596 | この「珍しい」文字を含む場所だけが調べられるのです。) | |
14597 | 17325 | |
14598 | 17326 | =begin original |
14599 | 17327 | |
14600 | 17328 | For example, here is a loop that inserts index producing entries |
14601 | 17329 | before any line containing a certain pattern: |
14602 | 17330 | |
14603 | 17331 | =end original |
14604 | 17332 | |
14605 | 17333 | たとえば、特定のパターンを含む行の前にインデックスを |
14606 | 17334 | 付けるエントリを入れる例を示します。 |
14607 | 17335 | |
14608 | 17336 | while (<>) { |
14609 | 17337 | study; |
14610 | 17338 | print ".IX foo\n" if /\bfoo\b/; |
14611 | 17339 | print ".IX bar\n" if /\bbar\b/; |
14612 | 17340 | print ".IX blurfl\n" if /\bblurfl\b/; |
14613 | 17341 | # ... |
14614 | 17342 | print; |
14615 | 17343 | } |
14616 | 17344 | |
14617 | 17345 | =begin original |
14618 | 17346 | |
14619 | In searching for C</\bfoo\b/>, only locations in C<$_> | |
17347 | In searching for C</\bfoo\b/>, only locations in L<C<$_>|perlvar/$_> | |
17348 | that contain C<f> | |
14620 | 17349 | will be looked at, because C<f> is rarer than C<o>. In general, this is |
14621 | 17350 | a big win except in pathological cases. The only question is whether |
14622 | 17351 | it saves you more time than it took to build the linked list in the |
14623 | 17352 | first place. |
14624 | 17353 | |
14625 | 17354 | =end original |
14626 | 17355 | |
14627 | C<f> は C<o> よりも珍しいので、C</\bfoo\b/> を探すとき、C<$_> | |
17356 | C<f> は C<o> よりも珍しいので、C</\bfoo\b/> を探すとき、L<C<$_>|perlvar/$_> で | |
14628 | 含む場所だけが探されます。 | |
17357 | C<f> を含む場所だけが探されます。 | |
14629 | 17358 | 一般に、病的な場合を除いて、かなりの結果が得られます。 |
14630 | 17359 | 唯一の問題は、節約できる時間が、最初にリンクリストを作る |
14631 | 17360 | 時間よりも多いかどうかです、 |
14632 | 17361 | |
14633 | 17362 | =begin original |
14634 | 17363 | |
14635 | 17364 | Note that if you have to look for strings that you don't know till |
14636 | runtime, you can build an entire loop as a string and C<eval> | |
17365 | runtime, you can build an entire loop as a string and L<C<eval>|/eval | |
14637 | avoid recompiling all your patterns all the time. | |
17366 | EXPR> that to avoid recompiling all your patterns all the time. | |
14638 | undefining C<$/> to input entir | |
17367 | Together with undefining L<C<$E<sol>>|perlvar/$E<sol>> to input entire | |
14639 | fas | |
17368 | files as one record, this can be quite | |
17369 | fast, often faster than specialized programs like L<fgrep(1)>. The following | |
14640 | 17370 | scans a list of files (C<@files>) for a list of words (C<@words>), and prints |
14641 | 17371 | out the names of those files that contain a match: |
14642 | 17372 | |
14643 | 17373 | =end original |
14644 | 17374 | |
14645 | 17375 | 実行時まで、探そうとする文字列がわからないときには、 |
14646 | ループ全体を文字列として組み立てて、C<eval> すれば、 | |
17376 | ループ全体を文字列として組み立てて、L<C<eval>|/eval EXPR> すれば、 | |
14647 | 17377 | いつも、すべてのパターンを再コンパイルするという事態は避けられます。 |
14648 | 17378 | ファイル全体を一つのレコードとして入力するために、 |
14649 | C<$/> を未定義にすれば、かなり速くなり、 | |
17379 | L<C<$E<sol>>|perlvar/$E<sol>> を未定義にすれば、かなり速くなり、 | |
14650 | 多くの場合 fgrep(1) のような専用のプログラムより速くなります。 | |
17380 | 多くの場合 L<fgrep(1)> のような専用のプログラムより速くなります。 | |
14651 | 17381 | 以下の例は、ファイルのリスト (C<@files>) から単語のリスト (C<@words>) を |
14652 | 17382 | 探して、マッチするものがあったファイル名を出力します。 |
14653 | 17383 | |
14654 | $search = 'while (<>) { study;'; | |
17384 | my $search = 'local $/; while (<>) { study;'; | |
14655 | foreach $word (@words) { | |
17385 | foreach my $word (@words) { | |
14656 | 17386 | $search .= "++\$seen{\$ARGV} if /\\b$word\\b/;\n"; |
14657 | 17387 | } |
14658 | 17388 | $search .= "}"; |
14659 | 17389 | @ARGV = @files; |
14660 | | |
17390 | my %seen; | |
14661 | 17391 | eval $search; # this screams |
14662 | | |
17392 | foreach my $file (sort keys(%seen)) { | |
14663 | foreach $file (sort keys(%seen)) { | |
14664 | 17393 | print $file, "\n"; |
14665 | 17394 | } |
14666 | 17395 | |
14667 | 17396 | =item sub NAME BLOCK |
14668 | 17397 | X<sub> |
14669 | 17398 | |
14670 | 17399 | =item sub NAME (PROTO) BLOCK |
14671 | 17400 | |
14672 | 17401 | =item sub NAME : ATTRS BLOCK |
14673 | 17402 | |
14674 | 17403 | =item sub NAME (PROTO) : ATTRS BLOCK |
14675 | 17404 | |
17405 | =for Pod::Functions declare a subroutine, possibly anonymously | |
17406 | ||
14676 | 17407 | =begin original |
14677 | 17408 | |
14678 | 17409 | This is subroutine definition, not a real function I<per se>. Without a |
14679 | 17410 | BLOCK it's just a forward declaration. Without a NAME, it's an anonymous |
14680 | 17411 | function declaration, so does return a value: the CODE ref of the closure |
14681 | 17412 | just created. |
14682 | 17413 | |
14683 | 17414 | =end original |
14684 | 17415 | |
14685 | 17416 | これはサブルーチン定義であり、I<本質的には> 実際の関数ではありません。 |
14686 | 17417 | BLOCK なしの場合、これは単に前方宣言です。 |
14687 | 17418 | NAME なしの場合は、無名関数定義であり、値(作成したブロックの |
14688 | 17419 | コードリファレンス)を返します: 単にクロージャの CODE リファレンスが |
14689 | 17420 | 作成されます。 |
14690 | 17421 | |
14691 | 17422 | =begin original |
14692 | 17423 | |
14693 | 17424 | See L<perlsub> and L<perlref> for details about subroutines and |
14694 | 17425 | references; see L<attributes> and L<Attribute::Handlers> for more |
14695 | 17426 | information about attributes. |
14696 | 17427 | |
14697 | 17428 | =end original |
14698 | 17429 | |
14699 | 17430 | サブルーチンとリファレンスに関する詳細については、L<perlsub> と |
14700 | 17431 | L<perlref> を参照してください; 属性に関する更なる情報については |
14701 | 17432 | L<attributes> と L<Attribute::Handlers> を参照してください。 |
14702 | 17433 | |
17434 | =item __SUB__ | |
17435 | X<__SUB__> | |
17436 | ||
17437 | =for Pod::Functions +current_sub the current subroutine, or C<undef> if not in a subroutine | |
17438 | ||
17439 | =begin original | |
17440 | ||
17441 | A special token that returns a reference to the current subroutine, or | |
17442 | L<C<undef>|/undef EXPR> outside of a subroutine. | |
17443 | ||
17444 | =end original | |
17445 | ||
17446 | 現在のサブルーチンのリファレンスを返す特殊トークン; サブルーチンの外側では | |
17447 | L<C<undef>|/undef EXPR>。 | |
17448 | ||
17449 | =begin original | |
17450 | ||
17451 | The behaviour of L<C<__SUB__>|/__SUB__> within a regex code block (such | |
17452 | as C</(?{...})/>) is subject to change. | |
17453 | ||
17454 | =end original | |
17455 | ||
17456 | (C</(?{...})/> のような) 正規表現コードブロックの中の | |
17457 | L<C<__SUB__>|/__SUB__> の振る舞いは変更される予定です。 | |
17458 | ||
17459 | =begin original | |
17460 | ||
17461 | This token is only available under C<use v5.16> or the | |
17462 | L<C<"current_sub"> feature|feature/The 'current_sub' feature>. | |
17463 | See L<feature>. | |
17464 | ||
17465 | =end original | |
17466 | ||
17467 | このトークンは C<use v5.16> または | |
17468 | L<C<"current_sub"> 機能|feature/The 'current_sub' feature> でのみ | |
17469 | 利用可能です。 | |
17470 | L<feature> を参照してください。 | |
17471 | ||
14703 | 17472 | =item substr EXPR,OFFSET,LENGTH,REPLACEMENT |
14704 | 17473 | X<substr> X<substring> X<mid> X<left> X<right> |
14705 | 17474 | |
14706 | 17475 | =item substr EXPR,OFFSET,LENGTH |
14707 | 17476 | |
14708 | 17477 | =item substr EXPR,OFFSET |
14709 | 17478 | |
17479 | =for Pod::Functions get or alter a portion of a string | |
17480 | ||
14710 | 17481 | =begin original |
14711 | 17482 | |
14712 | 17483 | Extracts a substring out of EXPR and returns it. First character is at |
14713 | offset | |
17484 | offset zero. If OFFSET is negative, starts | |
14714 | If OFFSET is negative (or more precisely, less than C<$[>), starts | |
14715 | 17485 | that far back from the end of the string. If LENGTH is omitted, returns |
14716 | 17486 | everything through the end of the string. If LENGTH is negative, leaves that |
14717 | 17487 | many characters off the end of the string. |
14718 | 17488 | |
14719 | 17489 | =end original |
14720 | 17490 | |
14721 | 17491 | EXPR から、部分文字列を取り出して返します。 |
14722 | 最初の文字がオフセット | |
17492 | 最初の文字がオフセット 0 となります。 | |
14723 | ||
17493 | OFFSET に負の値を設定すると、EXPR の終わりからのオフセットとなります。 | |
14724 | OFFSET に負の値(より厳密には、C<$[>より小さい値)を設定すると、 | |
14725 | EXPR の終わりからのオフセットとなります。 | |
14726 | 17494 | LENGTH を省略すると、EXPR の最後まですべてが返されます。 |
14727 | 17495 | LENGTH が負の値だと、文字列の最後から指定された数だけ文字を取り除きます。 |
14728 | 17496 | |
14729 | 17497 | my $s = "The black cat climbed the green tree"; |
14730 | 17498 | my $color = substr $s, 4, 5; # black |
14731 | 17499 | my $middle = substr $s, 4, -11; # black cat climbed the |
14732 | 17500 | my $end = substr $s, 14; # climbed the green tree |
14733 | 17501 | my $tail = substr $s, -4; # tree |
14734 | 17502 | my $z = substr $s, -4, 2; # tr |
14735 | 17503 | |
14736 | 17504 | =begin original |
14737 | 17505 | |
14738 | You can use the substr | |
17506 | You can use the L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> | |
17507 | function as an lvalue, in which case EXPR | |
14739 | 17508 | must itself be an lvalue. If you assign something shorter than LENGTH, |
14740 | 17509 | the string will shrink, and if you assign something longer than LENGTH, |
14741 | 17510 | the string will grow to accommodate it. To keep the string the same |
14742 | length, you may need to pad or chop your value using | |
17511 | length, you may need to pad or chop your value using | |
17512 | L<C<sprintf>|/sprintf FORMAT, LIST>. | |
14743 | 17513 | |
14744 | 17514 | =end original |
14745 | 17515 | |
14746 | substr | |
17516 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> を左辺値として | |
14747 | EXPR が自身左辺値でなければなりません。 | |
17517 | 使用することも可能で、その場合には、EXPR が自身左辺値でなければなりません。 | |
14748 | 17518 | LENGTH より短いものを代入したときには、 |
14749 | 17519 | EXPR は短くなり、LENGTH より長いものを代入したときには、 |
14750 | 17520 | EXPR はそれに合わせて伸びることになります。 |
14751 | EXPR の長さを一定に保つためには、C<sprintf> を | |
17521 | EXPR の長さを一定に保つためには、L<C<sprintf>|/sprintf FORMAT, LIST> を | |
14752 | 代入する値の長さを調整することが、必要になるかもしれません。 | |
17522 | 使って、代入する値の長さを調整することが、必要になるかもしれません。 | |
14753 | 17523 | |
14754 | 17524 | =begin original |
14755 | 17525 | |
14756 | 17526 | If OFFSET and LENGTH specify a substring that is partly outside the |
14757 | 17527 | string, only the part within the string is returned. If the substring |
14758 | is beyond either end of the string, | |
17528 | is beyond either end of the string, | |
17529 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> returns the undefined | |
14759 | 17530 | value and produces a warning. When used as an lvalue, specifying a |
14760 | 17531 | substring that is entirely outside the string raises an exception. |
14761 | 17532 | Here's an example showing the behavior for boundary cases: |
14762 | 17533 | |
14763 | 17534 | =end original |
14764 | 17535 | |
14765 | 17536 | OFFSET と LENGTH として文字列の外側を含むような部分文字列が指定されると、 |
14766 | 17537 | 文字列の内側の部分だけが返されます。 |
14767 | 部分文字列が文字列の両端の外側の場合、 | |
17538 | 部分文字列が文字列の両端の外側の場合、 | |
17539 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> は未定義値を返し、 | |
14768 | 17540 | 警告が出力されます。 |
14769 | 17541 | 左辺値として使った場合、文字列の完全に外側を部分文字列として指定すると |
14770 | 17542 | 例外が発生します。 |
14771 | 17543 | 以下は境界条件の振る舞いを示す例です: |
14772 | 17544 | |
14773 | 17545 | my $name = 'fred'; |
14774 | 17546 | substr($name, 4) = 'dy'; # $name is now 'freddy' |
14775 | 17547 | my $null = substr $name, 6, 2; # returns "" (no warning) |
14776 | 17548 | my $oops = substr $name, 7; # returns undef, with warning |
14777 | 17549 | substr($name, 7) = 'gap'; # raises an exception |
14778 | 17550 | |
14779 | 17551 | =begin original |
14780 | 17552 | |
14781 | An alternative to using | |
17553 | An alternative to using | |
17554 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> as an lvalue is to | |
17555 | specify the | |
14782 | 17556 | replacement string as the 4th argument. This allows you to replace |
14783 | 17557 | parts of the EXPR and return what was there before in one operation, |
14784 | just as you can with | |
17558 | just as you can with | |
17559 | L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST>. | |
14785 | 17560 | |
14786 | 17561 | =end original |
14787 | 17562 | |
14788 | substr | |
17563 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> を左辺値として使う | |
14789 | 引数として指定することです。 | |
17564 | 代わりの方法は、置き換える文字列を 4 番目の引数として指定することです。 | |
14790 | 17565 | これにより、EXPR の一部を置き換え、置き換える前が何であったかを返す、 |
14791 | ということを(splice | |
17566 | ということを(L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> と同様) | |
17567 | 1 動作で行えます。 | |
14792 | 17568 | |
14793 | 17569 | my $s = "The black cat climbed the green tree"; |
14794 | 17570 | my $z = substr $s, 14, 7, "jumped from"; # climbed |
14795 | 17571 | # $s is now "The black cat jumped from the green tree" |
14796 | 17572 | |
14797 | 17573 | =begin original |
14798 | 17574 | |
14799 | Note that the lvalue returned by the three-argument version of | |
17575 | Note that the lvalue returned by the three-argument version of | |
17576 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> acts as | |
14800 | 17577 | a 'magic bullet'; each time it is assigned to, it remembers which part |
14801 | 17578 | of the original string is being modified; for example: |
14802 | 17579 | |
14803 | 17580 | =end original |
14804 | 17581 | |
14805 | 3 引数の substr | |
17582 | 3 引数の L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> によって返された | |
14806 | 注意してください; | |
17583 | 左辺値は「魔法の弾丸」のように振舞うことに注意してください; | |
14807 | 思い出されます; | |
17584 | これが代入される毎に、元の文字列のどの部分が変更されたかが思い出されます; | |
17585 | 例えば: | |
14808 | 17586 | |
14809 | $x = '1234'; | |
17587 | my $x = '1234'; | |
14810 | 17588 | for (substr($x,1,2)) { |
14811 | 17589 | $_ = 'a'; print $x,"\n"; # prints 1a4 |
14812 | 17590 | $_ = 'xyz'; print $x,"\n"; # prints 1xyz4 |
14813 | 17591 | $x = '56789'; |
14814 | 17592 | $_ = 'pq'; print $x,"\n"; # prints 5pq9 |
14815 | 17593 | } |
14816 | 17594 | |
14817 | 17595 | =begin original |
14818 | 17596 | |
14819 | ||
17597 | With negative offsets, it remembers its position from the end of the string | |
17598 | when the target string is modified: | |
17599 | ||
17600 | =end original | |
17601 | ||
17602 | 負数のオフセットの場合、ターゲット文字列が修正されたときに文字列の末尾からの | |
17603 | 位置を覚えます: | |
17604 | ||
17605 | my $x = '1234'; | |
17606 | for (substr($x, -3, 2)) { | |
17607 | $_ = 'a'; print $x,"\n"; # prints 1a4, as above | |
17608 | $x = 'abcdefg'; | |
17609 | print $_,"\n"; # prints f | |
17610 | } | |
17611 | ||
17612 | =begin original | |
17613 | ||
17614 | Prior to Perl version 5.10, the result of using an lvalue multiple times was | |
17615 | unspecified. Prior to 5.16, the result with negative offsets was | |
14820 | 17616 | unspecified. |
14821 | 17617 | |
14822 | 17618 | =end original |
14823 | 17619 | |
14824 | バージョン 5. | |
17620 | バージョン 5.10 より前の Perl では、複数回左辺値を使った場合の結果は | |
14825 | 17621 | 未定義でした。 |
17622 | 5.16 より前では、負のオフセットの結果は未定義です。 | |
14826 | 17623 | |
14827 | 17624 | =item symlink OLDFILE,NEWFILE |
14828 | 17625 | X<symlink> X<link> X<symbolic link> X<link, symbolic> |
14829 | 17626 | |
17627 | =for Pod::Functions create a symbolic link to a file | |
17628 | ||
14830 | 17629 | =begin original |
14831 | 17630 | |
14832 | 17631 | Creates a new filename symbolically linked to the old filename. |
14833 | 17632 | Returns C<1> for success, C<0> otherwise. On systems that don't support |
14834 | 17633 | symbolic links, raises an exception. To check for that, |
14835 | 17634 | use eval: |
14836 | 17635 | |
14837 | 17636 | =end original |
14838 | 17637 | |
14839 | 17638 | NEWFILE として、OLDFILE へのシンボリックリンクを生成します。 |
14840 | 17639 | 成功時には C<1> を返し、失敗時には C<0> を返します。 |
14841 | 17640 | シンボリックリンクをサポートしていないシステムでは、 |
14842 | 17641 | 例外が発生します。 |
14843 | 17642 | これをチェックするには、eval を使用します: |
14844 | 17643 | |
14845 | $symlink_exists = eval { symlink("",""); 1 }; | |
17644 | my $symlink_exists = eval { symlink("",""); 1 }; | |
14846 | 17645 | |
17646 | =begin original | |
17647 | ||
17648 | Portability issues: L<perlport/symlink>. | |
17649 | ||
17650 | =end original | |
17651 | ||
17652 | 移植性の問題: L<perlport/symlink>。 | |
17653 | ||
14847 | 17654 | =item syscall NUMBER, LIST |
14848 | 17655 | X<syscall> X<system call> |
14849 | 17656 | |
17657 | =for Pod::Functions execute an arbitrary system call | |
17658 | ||
14850 | 17659 | =begin original |
14851 | 17660 | |
14852 | 17661 | Calls the system call specified as the first element of the list, |
14853 | 17662 | passing the remaining elements as arguments to the system call. If |
14854 | 17663 | unimplemented, raises an exception. The arguments are interpreted |
14855 | 17664 | as follows: if a given argument is numeric, the argument is passed as |
14856 | 17665 | an int. If not, the pointer to the string value is passed. You are |
14857 | 17666 | responsible to make sure a string is pre-extended long enough to |
14858 | 17667 | receive any result that might be written into a string. You can't use a |
14859 | string literal (or other read-only string) as an argument to | |
17668 | string literal (or other read-only string) as an argument to | |
14860 | because Perl has to assume that any | |
17669 | L<C<syscall>|/syscall NUMBER, LIST> because Perl has to assume that any | |
14861 | through. If your | |
17670 | string pointer might be written through. If your | |
14862 | 17671 | integer arguments are not literals and have never been interpreted in a |
14863 | 17672 | numeric context, you may need to add C<0> to them to force them to look |
14864 | like numbers. This emulates the | |
17673 | like numbers. This emulates the | |
17674 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> function (or | |
17675 | vice versa): | |
14865 | 17676 | |
14866 | 17677 | =end original |
14867 | 17678 | |
14868 | 17679 | LIST の最初の要素で指定するシステムコールを、残りの要素をその |
14869 | 17680 | システムコールの引数として呼び出します。 |
14870 | 実装されていない | |
17681 | 実装されていない場合には、例外が発生します。 | |
14871 | 17682 | 引数は、以下のように解釈されます: 引数が数字であれば、int として |
14872 | 17683 | 引数を渡します。 |
14873 | 17684 | そうでなければ、文字列値へのポインタが渡されます。 |
14874 | 17685 | 文字列に結果を受け取るときには、その結果を受け取るのに十分なくらいに、 |
14875 | 17686 | 文字列を予め伸ばしておく必要があります。 |
14876 | 文字列リテラル(あるいはその他の読み込み専用の文字列)を | |
17687 | 文字列リテラル(あるいはその他の読み込み専用の文字列)を | |
14877 | 引数として使うことはできません | |
17688 | L<C<syscall>|/syscall NUMBER, LIST> の引数として使うことはできません; | |
14878 | 17689 | Perl は全ての文字列ポインタは書き込まれると仮定しなければならないからです。 |
14879 | 整数引数が、リテラルでなく、数値コンテキストで評価されたことの | |
17690 | 整数引数が、リテラルでなく、数値コンテキストで評価されたことのない | |
14880 | ||
17691 | ものであれば、数値として解釈されるように、 | |
14881 | 17692 | C<0> を足しておく必要があるかもしれません。 |
14882 | 以下は C<syswrite> 関数(あるいは | |
17693 | 以下は L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> 関数(あるいは | |
17694 | その逆)をエミュレートします。 | |
14883 | 17695 | |
14884 | 17696 | require 'syscall.ph'; # may need to run h2ph |
14885 | $s = "hi there\n"; | |
17697 | my $s = "hi there\n"; | |
14886 | syscall( | |
17698 | syscall(SYS_write(), fileno(STDOUT), $s, length $s); | |
14887 | 17699 | |
14888 | 17700 | =begin original |
14889 | 17701 | |
14890 | 17702 | Note that Perl supports passing of up to only 14 arguments to your syscall, |
14891 | 17703 | which in practice should (usually) suffice. |
14892 | 17704 | |
14893 | 17705 | =end original |
14894 | 17706 | |
14895 | 17707 | Perl は、システムコールに最大 14 個の引数しか渡せませんが、 |
14896 | 17708 | (普通は)実用上問題はないでしょう。 |
14897 | 17709 | |
14898 | 17710 | =begin original |
14899 | 17711 | |
14900 | 17712 | Syscall returns whatever value returned by the system call it calls. |
14901 | If the system call fails, C<syscall> | |
17713 | If the system call fails, L<C<syscall>|/syscall NUMBER, LIST> returns | |
17714 | C<-1> and sets L<C<$!>|perlvar/$!> (errno). | |
14902 | 17715 | Note that some system calls I<can> legitimately return C<-1>. The proper |
14903 | way to handle such calls is to assign C<$!=0> before the call, then | |
17716 | way to handle such calls is to assign C<$! = 0> before the call, then | |
14904 | check the value of C<$!> | |
17717 | check the value of L<C<$!>|perlvar/$!> if | |
17718 | L<C<syscall>|/syscall NUMBER, LIST> returns C<-1>. | |
14905 | 17719 | |
14906 | 17720 | =end original |
14907 | 17721 | |
14908 | 17722 | syscall は、呼び出したシステムコールが返した値を返します。 |
14909 | システムコールが失敗すると、C<syscall> は C<-1> を | |
17723 | システムコールが失敗すると、L<C<syscall>|/syscall NUMBER, LIST> は C<-1> を | |
14910 | C<$!>(errno) を設定します。 | |
17724 | 返し、L<C<$!>|perlvar/$!>(errno) を設定します。 | |
14911 | 17725 | システムコールが正常に C<-1> を返す I<場合がある> ことに注意してください。 |
14912 | 17726 | このようなシステムコールを正しく扱うには、 |
14913 | C<$!=0> をシステムコールの前に実行し、それから | |
17727 | C<$! = 0> をシステムコールの前に実行し、それから | |
14914 | C<syscall> が C<-1> を返した時には | |
17728 | L<C<syscall>|/syscall NUMBER, LIST> が C<-1> を返した時には | |
17729 | L<C<$!>|perlvar/$!> の値を調べてください。 | |
14915 | 17730 | |
14916 | 17731 | =begin original |
14917 | 17732 | |
14918 | There's a problem with C<syscall( | |
17733 | There's a problem with C<syscall(SYS_pipe())>: it returns the file | |
14919 | 17734 | number of the read end of the pipe it creates, but there is no way |
14920 | 17735 | to retrieve the file number of the other end. You can avoid this |
14921 | problem by using C<pipe> instead. | |
17736 | problem by using L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> instead. | |
14922 | 17737 | |
14923 | 17738 | =end original |
14924 | 17739 | |
14925 | C<syscall(&SYS_pipe)> には問題があり、 | |
17740 | C<syscall(&SYS_pipe)> には問題があり、作ったパイプの、読み出し側の | |
14926 | ||
17741 | ファイル番号を返しますが、もう一方のファイル番号を得る方法がありません。 | |
14927 | ||
17742 | この問題を避けるためには、代わりに L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> を | |
14928 | ||
17743 | 使ってください。 | |
14929 | 17744 | |
17745 | =begin original | |
17746 | ||
17747 | Portability issues: L<perlport/syscall>. | |
17748 | ||
17749 | =end original | |
17750 | ||
17751 | 移植性の問題: L<perlport/syscall>。 | |
17752 | ||
14930 | 17753 | =item sysopen FILEHANDLE,FILENAME,MODE |
14931 | 17754 | X<sysopen> |
14932 | 17755 | |
14933 | 17756 | =item sysopen FILEHANDLE,FILENAME,MODE,PERMS |
14934 | 17757 | |
17758 | =for Pod::Functions +5.002 open a file, pipe, or descriptor | |
17759 | ||
14935 | 17760 | =begin original |
14936 | 17761 | |
14937 | 17762 | Opens the file whose filename is given by FILENAME, and associates it with |
14938 | 17763 | FILEHANDLE. If FILEHANDLE is an expression, its value is used as the real |
14939 | filehandle wanted; an undefined scalar will be suitably autovivified. This | |
17764 | filehandle wanted; an undefined scalar will be suitably autovivified. This | |
14940 | function calls the underlying operating system's | |
17765 | function calls the underlying operating system's L<open(2)> function with the | |
14941 | 17766 | parameters FILENAME, MODE, and PERMS. |
14942 | 17767 | |
14943 | 17768 | =end original |
14944 | 17769 | |
14945 | 17770 | FILENAME で与えられたファイル名のファイルをオープンし、 |
14946 | 17771 | FILEHANDLE と結び付けます。 |
14947 | 17772 | FILEHANDLE が式の場合、その値は実際の求めているファイルハンドルの名前として |
14948 | 17773 | 扱われます; 未定義のスカラは適切に自動有効化されます。 |
14949 | この関数呼び出しはシステムの | |
17774 | この関数呼び出しはシステムの L<open(2)> 関数を FILENAME, MODE, PERMS の | |
14950 | 17775 | 引数で呼び出すことを基礎としています。 |
14951 | 17776 | |
14952 | 17777 | =begin original |
14953 | 17778 | |
17779 | Returns true on success and L<C<undef>|/undef EXPR> otherwise. | |
17780 | ||
17781 | =end original | |
17782 | ||
17783 | 成功時は真を、さもなければ L<C<undef>|/undef EXPR> を返します。 | |
17784 | ||
17785 | =begin original | |
17786 | ||
14954 | 17787 | The possible values and flag bits of the MODE parameter are |
14955 | system-dependent; they are available via the standard module | |
17788 | system-dependent; they are available via the standard module | |
14956 | the documentation of your operating system's | |
17789 | L<C<Fcntl>|Fcntl>. See the documentation of your operating system's | |
17790 | L<open(2)> syscall to see | |
14957 | 17791 | which values and flag bits are available. You may combine several flags |
14958 | 17792 | using the C<|>-operator. |
14959 | 17793 | |
14960 | 17794 | =end original |
14961 | 17795 | |
14962 | 17796 | MODE パラメータに指定できるフラグビットと値はシステム依存です; |
14963 | これは標準モジュール C<Fcntl> 経由で利用可能です。 | |
17797 | これは標準モジュール L<C<Fcntl>|Fcntl> 経由で利用可能です。 | |
14964 | 17798 | どのようなフラグビットと値が利用可能であるかについては、 |
14965 | OS の | |
17799 | OS の L<open(2)> システムコールに関する文書を参照してください。 | |
14966 | 17800 | C<|> 演算子を使って複数のフラグを結合することができます。 |
14967 | 17801 | |
14968 | 17802 | =begin original |
14969 | 17803 | |
14970 | 17804 | Some of the most common values are C<O_RDONLY> for opening the file in |
14971 | 17805 | read-only mode, C<O_WRONLY> for opening the file in write-only mode, |
14972 | 17806 | and C<O_RDWR> for opening the file in read-write mode. |
14973 | 17807 | X<O_RDONLY> X<O_RDWR> X<O_WRONLY> |
14974 | 17808 | |
14975 | 17809 | =end original |
14976 | 17810 | |
14977 | 17811 | もっともよく使われる値は、ファイルを読み込み専用で開く C<O_RDONLY>、 |
14978 | 17812 | ファイルを書き込み専用で開く C<O_WRONLY>、 |
14979 | 17813 | ファイルを読み書き両用で開く C<O_RDWR> です。 |
14980 | 17814 | X<O_RDONLY> X<O_RDWR> X<O_WRONLY> |
14981 | 17815 | |
14982 | 17816 | =begin original |
14983 | 17817 | |
14984 | 17818 | For historical reasons, some values work on almost every system |
14985 | 17819 | supported by Perl: 0 means read-only, 1 means write-only, and 2 |
14986 | 17820 | means read/write. We know that these values do I<not> work under |
14987 | OS/390 | |
17821 | OS/390 and on the Macintosh; you probably don't want to | |
14988 | 17822 | use them in new code. |
14989 | 17823 | |
14990 | 17824 | =end original |
14991 | 17825 | |
14992 | 歴史的な理由により、Perl が対応しているほとんどのシステムで | |
17826 | 歴史的な理由により、Perl が対応しているほとんどのシステムで使える値が | |
14993 | ||
17827 | あります:0 は読み込み専用、1 は書き込み専用、2 は読み書き両用を意味します。 | |
14994 | 0 | |
17828 | OS/390 と Macintosh では動作 I<しない> ことが分かっています; | |
14995 | OS/390 & VM/ESA Unix と Macintosh では動作 I<しない> ことが分かっています; | |
14996 | 17829 | 新しく書くコードではこれらは使わないほうがよいでしょう。 |
14997 | 17830 | |
14998 | 17831 | =begin original |
14999 | 17832 | |
15000 | If the file named by FILENAME does not exist and the | |
17833 | If the file named by FILENAME does not exist and the | |
17834 | L<C<open>|/open FILEHANDLE,EXPR> call creates | |
15001 | 17835 | it (typically because MODE includes the C<O_CREAT> flag), then the value of |
15002 | 17836 | PERMS specifies the permissions of the newly created file. If you omit |
15003 | the PERMS argument to C<sysopen> | |
17837 | the PERMS argument to L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>, | |
17838 | Perl uses the octal value C<0666>. | |
15004 | 17839 | These permission values need to be in octal, and are modified by your |
15005 | process's current C<umask>. | |
17840 | process's current L<C<umask>|/umask EXPR>. | |
15006 | 17841 | X<O_CREAT> |
15007 | 17842 | |
15008 | 17843 | =end original |
15009 | 17844 | |
15010 | 17845 | FILENAME という名前のファイルが存在せず、(典型的には MODE が |
15011 | C<O_CREAT> フラグを含んでいたために) | |
17846 | C<O_CREAT> フラグを含んでいたために) | |
17847 | L<C<open>|/open FILEHANDLE,EXPR> 呼び出しがそれを作った場合、 | |
15012 | 17848 | PERMS の値は新しく作られたファイルの権限を指定します。 |
15013 | C<sysopen> の PERMS 引数を省略した場合、 | |
17849 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> の PERMS 引数を省略した場合、 | |
15014 | ||
17850 | Perl は 8 進数 C<0666> を使います。 | |
15015 | ||
17851 | これらの権限は 8 進数である必要があり、プロセスの現在の | |
17852 | L<C<umask>|/umask EXPR> で修正されます。 | |
15016 | 17853 | X<O_CREAT> |
15017 | 17854 | |
15018 | 17855 | =begin original |
15019 | 17856 | |
15020 | 17857 | In many systems the C<O_EXCL> flag is available for opening files in |
15021 | 17858 | exclusive mode. This is B<not> locking: exclusiveness means here that |
15022 | if the file already exists, | |
17859 | if the file already exists, | |
17860 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> fails. C<O_EXCL> may | |
17861 | not work | |
15023 | 17862 | on network filesystems, and has no effect unless the C<O_CREAT> flag |
15024 | 17863 | is set as well. Setting C<O_CREAT|O_EXCL> prevents the file from |
15025 | 17864 | being opened if it is a symbolic link. It does not protect against |
15026 | 17865 | symbolic links in the file's path. |
15027 | 17866 | X<O_EXCL> |
15028 | 17867 | |
15029 | 17868 | =end original |
15030 | 17869 | |
15031 | 17870 | 多くのシステムではファイルを排他モードで開くために C<O_EXCL> が |
15032 | 17871 | 利用可能です。 |
15033 | 17872 | これはロック B<ではありません>: 排他性というのは既にファイルが |
15034 | 存在していた場合、sysopen | |
17873 | 存在していた場合、L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> が | |
17874 | 失敗することを意味します。 | |
15035 | 17875 | C<O_EXCL> はネットワークファイルシステムでは動作せず、 |
15036 | 17876 | またC<O_CREAT> フラグも有効でない限りは効果がありません。 |
15037 | 17877 | C<O_CREAT|O_EXCL> をセットすると、これがシンボリックリンクだった場合は |
15038 | 17878 | ファイルを開くことを妨げます。 |
15039 | 17879 | これはファイルパス中のシンボリックリンクは守りません。 |
15040 | 17880 | X<O_EXCL> |
15041 | 17881 | |
15042 | 17882 | =begin original |
15043 | 17883 | |
15044 | 17884 | Sometimes you may want to truncate an already-existing file. This |
15045 | 17885 | can be done using the C<O_TRUNC> flag. The behavior of |
15046 | 17886 | C<O_TRUNC> with C<O_RDONLY> is undefined. |
15047 | 17887 | X<O_TRUNC> |
15048 | 17888 | |
15049 | 17889 | =end original |
15050 | 17890 | |
15051 | 17891 | 既に存在しているファイルを切り詰めたい場合もあるかもしれません。 |
15052 | 17892 | これは C<O_TRUNC> フラグを使うことで行えます。 |
15053 | 17893 | C<O_RDONLY> と C<O_TRUNC> を同時に指定したときの振る舞いは未定義です。 |
15054 | 17894 | X<O_TRUNC> |
15055 | 17895 | |
15056 | 17896 | =begin original |
15057 | 17897 | |
15058 | You should seldom if ever use C<0644> as argument to | |
17898 | You should seldom if ever use C<0644> as argument to | |
17899 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>, because | |
15059 | 17900 | that takes away the user's option to have a more permissive umask. |
15060 | Better to omit it. See | |
17901 | Better to omit it. See L<C<umask>|/umask EXPR> for more on this. | |
15061 | on this. | |
15062 | 17902 | |
15063 | 17903 | =end original |
15064 | 17904 | |
15065 | めったなことでは C<sysopen> の引数に | |
17905 | めったなことでは L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> の引数に | |
17906 | C<0644> を指定するべきではないでしょう: | |
15066 | 17907 | ユーザーがより寛大な umask を指定する選択肢を奪うからです。 |
15067 | 17908 | 省略した方がいいです。 |
15068 | これに関するさらなる情報については | |
17909 | これに関するさらなる情報については L<C<umask>|/umask EXPR> を | |
15069 | 17910 | 参照してください。 |
15070 | 17911 | |
15071 | 17912 | =begin original |
15072 | 17913 | |
15073 | Note that | |
17914 | Note that under Perls older than 5.8.0, | |
15074 | ||
17915 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> depends on the | |
15075 | ||
17916 | L<fdopen(3)> C library function. On many Unix systems, L<fdopen(3)> is known | |
15076 | descriptors | |
17917 | to fail when file descriptors exceed a certain value, typically 255. If | |
15077 | ||
17918 | you need more file descriptors than that, consider using the | |
17919 | L<C<POSIX::open>|POSIX/C<open>> function. For Perls 5.8.0 and later, | |
17920 | PerlIO is (most often) the default. | |
15078 | 17921 | |
15079 | 17922 | =end original |
15080 | 17923 | |
15081 | ||
17924 | 5.8.0 より古い Perl では、 | |
15082 | ||
17925 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> は | |
15083 | ||
17926 | C の L<fdopen(3)> ライブラリ関数に依存していることに注意してください。 | |
17927 | 多くの Unix システムでは、L<fdopen(3)> はファイル記述子がある値(例えば 255)を | |
17928 | 超えると失敗することが知られています。 | |
15084 | 17929 | これより多くのファイル記述子が必要な場合は、 |
15085 | Pe | |
17930 | L<C<POSIX::open>|POSIX/C<open>> 関数を使うことを検討してください。 | |
15086 | P | |
17931 | Perl 5.8.0 以降では、(ほぼ確実に) PerlIO がデフォルトです。 | |
15087 | 17932 | |
15088 | 17933 | =begin original |
15089 | 17934 | |
15090 | 17935 | See L<perlopentut> for a kinder, gentler explanation of opening files. |
15091 | 17936 | |
15092 | 17937 | =end original |
15093 | 17938 | |
15094 | ファイル | |
17939 | ファイルを開くことに関するより親切な説明については L<perlopentut> を | |
17940 | 参照してください。 | |
15095 | 17941 | |
17942 | =begin original | |
17943 | ||
17944 | Portability issues: L<perlport/sysopen>. | |
17945 | ||
17946 | =end original | |
17947 | ||
17948 | 移植性の問題: L<perlport/sysopen>。 | |
17949 | ||
15096 | 17950 | =item sysread FILEHANDLE,SCALAR,LENGTH,OFFSET |
15097 | 17951 | X<sysread> |
15098 | 17952 | |
15099 | 17953 | =item sysread FILEHANDLE,SCALAR,LENGTH |
15100 | 17954 | |
17955 | =for Pod::Functions fixed-length unbuffered input from a filehandle | |
17956 | ||
15101 | 17957 | =begin original |
15102 | 17958 | |
15103 | 17959 | Attempts to read LENGTH bytes of data into variable SCALAR from the |
15104 | specified FILEHANDLE, using | |
17960 | specified FILEHANDLE, using L<read(2)>. It bypasses | |
15105 | buffered IO, so mixing this with other kinds of reads, | |
17961 | buffered IO, so mixing this with other kinds of reads, | |
15106 | C< | |
17962 | L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>, | |
15107 | ||
17963 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
17964 | L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> can cause | |
17965 | confusion because the | |
17966 | perlio or stdio layers usually buffer data. Returns the number of | |
15108 | 17967 | bytes actually read, C<0> at end of file, or undef if there was an |
15109 | error (in the latter case C<$!> is also set). SCALAR will | |
17968 | error (in the latter case L<C<$!>|perlvar/$!> is also set). SCALAR will | |
17969 | be grown or | |
15110 | 17970 | shrunk so that the last byte actually read is the last byte of the |
15111 | 17971 | scalar after the read. |
15112 | 17972 | |
15113 | 17973 | =end original |
15114 | 17974 | |
15115 | read(2) を用いて、指定した FILEHANDLE から、変数 SCALAR へ、LENGTH バイトの | |
17975 | L<read(2)> を用いて、指定した FILEHANDLE から、変数 SCALAR へ、LENGTH バイトの | |
15116 | 17976 | データの読み込みを試みます。 |
15117 | これは、バッファ付き IO ルーチンを通りませんから、 | |
17977 | これは、バッファ付き IO ルーチンを通りませんから、他の入力関数, | |
15118 | ||
17978 | L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>, | |
15119 | C<seek>, C<tell> | |
17979 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>, | |
15120 | し | |
17980 | L<C<eof>|/eof FILEHANDLE> と混ぜて使うと、入力がおかしくなるかも | |
15121 | perlio 層や stdio 層は普通データをバッファリングするからです。 | |
17981 | しれません; perlio 層や stdio 層は普通データをバッファリングするからです。 | |
15122 | ファイルの最後では C<0>が、エラー時には undef が、 | |
17982 | ファイルの最後では C<0>が、エラー時には undef が、それ以外では実際に | |
15123 | ||
17983 | 読み込まれたデータの長さが返されます (後者の場合は L<C<$!>|perlvar/$!> も | |
15124 | ||
17984 | セットされます)。 | |
15125 | 17985 | 実際に読み込んだ最後のバイトが read した後の最後のバイトになるので、 |
15126 | 17986 | SCALAR は伸び縮みします。 |
15127 | 17987 | |
15128 | 17988 | =begin original |
15129 | 17989 | |
15130 | 17990 | An OFFSET may be specified to place the read data at some place in the |
15131 | 17991 | string other than the beginning. A negative OFFSET specifies |
15132 | 17992 | placement at that many characters counting backwards from the end of |
15133 | 17993 | the string. A positive OFFSET greater than the length of SCALAR |
15134 | 17994 | results in the string being padded to the required size with C<"\0"> |
15135 | 17995 | bytes before the result of the read is appended. |
15136 | 17996 | |
15137 | 17997 | =end original |
15138 | 17998 | |
15139 | OFFSET を指定すると、文字列の先頭以外の場所から | |
17999 | OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行なえます。 | |
15140 | できます。 | |
15141 | 18000 | OFFSET に負の値を指定すると、文字列の最後から逆向きに何文字目かで |
15142 | 18001 | 位置を指定します。 |
15143 | OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は | |
18002 | OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は読み込みの結果が | |
15144 | ||
18003 | 追加される前に、必要なサイズまで C<"\0"> のバイトでパッディングされます。 | |
15145 | パッディングされます。 | |
15146 | 18004 | |
15147 | 18005 | =begin original |
15148 | 18006 | |
15149 | There is no syseof() function, which is ok, since | |
18007 | There is no syseof() function, which is ok, since | |
15150 | well on device files (like ttys) | |
18008 | L<C<eof>|/eof FILEHANDLE> doesn't work well on device files (like ttys) | |
15151 | ||
18009 | anyway. Use L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> and | |
18010 | check for a return value for 0 to decide whether you're done. | |
15152 | 18011 | |
15153 | 18012 | =end original |
15154 | 18013 | |
15155 | syseof() 関数はありませんが、問題ありません | |
18014 | syseof() 関数はありませんが、問題ありません; どちらにしろ | |
15156 | ||
18015 | L<C<eof>|/eof FILEHANDLE> は | |
15157 | うまく動作しないからです。 | |
18016 | (tty のような)デバイスファイルに対してはうまく動作しないからです。 | |
15158 | sysread | |
18017 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を使って、 | |
15159 | 判断してください。 | |
18018 | 返り値が 0 かどうかで最後まで読んだかを判断してください。 | |
15160 | 18019 | |
15161 | 18020 | =begin original |
15162 | 18021 | |
15163 | Note that if the filehandle has been marked as C<:utf8> Unicode | |
18022 | Note that if the filehandle has been marked as C<:utf8>, Unicode | |
15164 | 18023 | characters are read instead of bytes (the LENGTH, OFFSET, and the |
15165 | return value of sysread | |
18024 | return value of L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> | |
15166 | The C<:encoding(...)> layer implicitly | |
18025 | are in Unicode characters). The C<:encoding(...)> layer implicitly | |
15167 | ||
18026 | introduces the C<:utf8> layer. See | |
18027 | L<C<binmode>|/binmode FILEHANDLE, LAYER>, | |
18028 | L<C<open>|/open FILEHANDLE,EXPR>, and the L<open> pragma. | |
15168 | 18029 | |
15169 | 18030 | =end original |
15170 | 18031 | |
15171 | 18032 | ファイルハンドルが C<:utf8> であるとマークが付けられると、バイトではなく |
15172 | Unicode 文字が読み込まれます | |
18033 | Unicode 文字が読み込まれます | |
15173 | ||
18034 | (L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> の LENGTH, OFFSET | |
18035 | および返り値は Unicode 文字になります)。 | |
15174 | 18036 | C<:encoding(...)> 層は暗黙のうちに C<:utf8> 層が導入されます。 |
15175 | L< | |
18037 | L<C<binmode>|/binmode FILEHANDLE, LAYER>, L<C<open>|/open FILEHANDLE,EXPR>, | |
18038 | L<open> プラグマを参照してください。 | |
15176 | 18039 | |
15177 | 18040 | =item sysseek FILEHANDLE,POSITION,WHENCE |
15178 | 18041 | X<sysseek> X<lseek> |
15179 | 18042 | |
18043 | =for Pod::Functions +5.004 position I/O pointer on handle used with sysread and syswrite | |
18044 | ||
15180 | 18045 | =begin original |
15181 | 18046 | |
15182 | Sets FILEHANDLE's system position in bytes using lseek(2). FILEHANDLE may | |
18047 | Sets FILEHANDLE's system position in bytes using L<lseek(2)>. FILEHANDLE may | |
15183 | 18048 | be an expression whose value gives the name of the filehandle. The values |
15184 | 18049 | for WHENCE are C<0> to set the new position to POSITION; C<1> to set the it |
15185 | 18050 | to the current position plus POSITION; and C<2> to set it to EOF plus |
15186 | 18051 | POSITION, typically negative. |
15187 | 18052 | |
15188 | 18053 | =end original |
15189 | 18054 | |
15190 | FILEHANDLE のシステム位置をバイト単位で lseek(2) を使って設定します。 | |
18055 | FILEHANDLE のシステム位置をバイト単位で L<lseek(2)> を使って設定します。 | |
15191 | FILEHANDLE は式でも | |
18056 | FILEHANDLE は、実際のファイルハンドル名を与える式でもかまいません。 | |
15192 | その場合はその値がファイルハンドルの名前となります。 | |
15193 | 18057 | WHENCE の値が、C<0> ならば、新しい位置を POSITION の位置へ設定します; |
15194 | 18058 | C<1> ならば、現在位置から POSITION 加えた位置へ設定します; C<2> ならば、 |
15195 | 18059 | EOF から POSITION だけ(普通は負の数です)加えた位置へ、新しい位置を |
15196 | 18060 | 設定します。 |
15197 | 18061 | |
15198 | 18062 | =begin original |
15199 | 18063 | |
15200 | 18064 | Note the I<in bytes>: even if the filehandle has been set to operate |
15201 | 18065 | on characters (for example by using the C<:encoding(utf8)> I/O layer), |
15202 | tell | |
18066 | L<C<tell>|/tell FILEHANDLE> will return byte offsets, not character | |
15203 | implementing that would render | |
18067 | offsets (because implementing that would render | |
18068 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> unacceptably slow). | |
15204 | 18069 | |
15205 | 18070 | =end original |
15206 | 18071 | |
15207 | 18072 | I<バイト単位> に関する注意: 文字単位で扱うようにファイルハンドルが |
15208 | 18073 | 設定されている場合(C<:encoding(utf8)> I/O 層を使っている場合など)でも、 |
15209 | tell | |
18074 | L<C<tell>|/tell FILEHANDLE> は文字のオフセットではなくバイトのオフセットを | |
15210 | (なぜならこれを実装すると | |
18075 | 返します (なぜならこれを実装すると | |
18076 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> が受け入れられないほど | |
15211 | 18077 | 遅くなるからです)。 |
15212 | 18078 | |
15213 | 18079 | =begin original |
15214 | 18080 | |
15215 | sysseek | |
18081 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> bypasses normal | |
15216 | ||
18082 | buffered IO, so mixing it with reads other than | |
15217 | C<se | |
18083 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> (for example | |
18084 | L<C<readline>|/readline EXPR> or | |
18085 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>), | |
18086 | L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>, | |
18087 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
18088 | L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> may cause | |
18089 | confusion. | |
15218 | 18090 | |
15219 | 18091 | =end original |
15220 | 18092 | |
15221 | sysseek | |
18093 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> は普通のバッファ付き IO を | |
15222 | ||
18094 | バイパスしますので、 | |
15223 | ||
18095 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> 以外の (例えば | |
15224 | ||
18096 | L<C<readline>|/readline EXPR> や | |
18097 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> の)読み込み、 | |
18098 | L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>, | |
18099 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>, | |
18100 | L<C<eof>|/eof FILEHANDLE> と混ぜて使うと混乱を引き起こします。 | |
15225 | 18101 | |
15226 | 18102 | =begin original |
15227 | 18103 | |
15228 | 18104 | For WHENCE, you may also use the constants C<SEEK_SET>, C<SEEK_CUR>, |
15229 | 18105 | and C<SEEK_END> (start of the file, current position, end of the file) |
15230 | from the Fcntl module. Use of the constants is also more portable | |
18106 | from the L<Fcntl> module. Use of the constants is also more portable | |
15231 | 18107 | than relying on 0, 1, and 2. For example to define a "systell" function: |
15232 | 18108 | |
15233 | 18109 | =end original |
15234 | 18110 | |
15235 | WHENCE には、Fcntl モジュールで使われている C<SEEK_SET>, C<SEEK_CUR>, | |
18111 | WHENCE には、L<Fcntl> モジュールで使われている C<SEEK_SET>, C<SEEK_CUR>, | |
15236 | 18112 | C<SEEK_END> (ファイルの先頭、現在位置、ファイルの最後)という定数を |
15237 | 18113 | 使うこともできます。 |
15238 | 18114 | 定数の使用は 0, 1, 2 に依存するよりも移植性があります。 |
15239 | 18115 | 例えば "systell" 関数を定義するには: |
15240 | 18116 | |
15241 | 18117 | use Fcntl 'SEEK_CUR'; |
15242 | 18118 | sub systell { sysseek($_[0], 0, SEEK_CUR) } |
15243 | 18119 | |
15244 | 18120 | =begin original |
15245 | 18121 | |
15246 | 18122 | Returns the new position, or the undefined value on failure. A position |
15247 | of zero is returned as the string C<"0 but true">; thus | |
18123 | of zero is returned as the string C<"0 but true">; thus | |
18124 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> returns | |
15248 | 18125 | true on success and false on failure, yet you can still easily determine |
15249 | 18126 | the new position. |
15250 | 18127 | |
15251 | 18128 | =end original |
15252 | 18129 | |
15253 | 新しい位置を返します。 | |
18130 | 新しい位置を返します; 失敗したときは未定義値を返します。 | |
15254 | ||
18131 | 位置がゼロの場合は、C<"0 but true"> の文字列として返されます; 従って | |
15255 | ||
18132 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> は成功時に真を返し、 | |
15256 | ||
18133 | 失敗時に偽を返しますが、簡単に新しい位置を判定できます。 | |
15257 | 簡単に新しい位置を判定できます。 | |
15258 | 18134 | |
15259 | 18135 | =item system LIST |
15260 | 18136 | X<system> X<shell> |
15261 | 18137 | |
15262 | 18138 | =item system PROGRAM LIST |
15263 | 18139 | |
18140 | =for Pod::Functions run a separate program | |
18141 | ||
15264 | 18142 | =begin original |
15265 | 18143 | |
15266 | Does exactly the same thing as C<exec LIST>, except that a fork is | |
18144 | Does exactly the same thing as L<C<exec>|/exec LIST>, except that a fork is | |
15267 | 18145 | done first and the parent process waits for the child process to |
15268 | 18146 | exit. Note that argument processing varies depending on the |
15269 | 18147 | number of arguments. If there is more than one argument in LIST, |
15270 | 18148 | or if LIST is an array with more than one value, starts the program |
15271 | 18149 | given by the first element of the list with arguments given by the |
15272 | 18150 | rest of the list. If there is only one scalar argument, the argument |
15273 | 18151 | is checked for shell metacharacters, and if there are any, the |
15274 | 18152 | entire argument is passed to the system's command shell for parsing |
15275 | 18153 | (this is C</bin/sh -c> on Unix platforms, but varies on other |
15276 | 18154 | platforms). If there are no shell metacharacters in the argument, |
15277 | 18155 | it is split into words and passed directly to C<execvp>, which is |
15278 | more efficient. | |
18156 | more efficient. On Windows, only the C<system PROGRAM LIST> syntax will | |
18157 | reliably avoid using the shell; C<system LIST>, even with more than one | |
18158 | element, will fall back to the shell if the first spawn fails. | |
15279 | 18159 | |
15280 | 18160 | =end original |
15281 | 18161 | |
15282 | C<exec LIST> とほとんど同じですが、まず fork を行ない、 | |
18162 | L<C<exec>|/exec LIST> とほとんど同じですが、まず fork を行ない、 | |
15283 | 18163 | 親プロセスではチャイルドプロセスが終了するのを wait します。 |
15284 | 18164 | exec の項で述べたように、引数の処理は、引数の数によって異なることに |
15285 | 18165 | 注意してください。 |
15286 | 18166 | LIST に複数の引数がある場合、または LIST が複数の要素からなる配列の場合、 |
15287 | リストの最初の要素で与えられるプログラムを、リストの残りの要素を | |
18167 | リストの最初の要素で与えられるプログラムを、リストの残りの要素を引数として | |
15288 | ||
18168 | 起動します。 | |
15289 | スカラの引数が一つだけの場合、 | |
18169 | スカラの引数が一つだけの場合、引数はシェルのメタ文字をチェックされ、もし | |
15290 | 引数 | |
18170 | あればパースのために引数全体がシステムコマンドシェル (これは | |
15291 | ||
18171 | Unix プラットフォームでは C</bin/sh -c> ですが、他のプラットフォームでは | |
15292 | ||
18172 | 異なります)に渡されます。 | |
15293 | ||
18173 | シェルのメタ文字がなかった場合、引数は単語に分解されて直接 C<execvp> に | |
15294 | ||
18174 | 渡されます; この方がより効率的です。 | |
15295 | ||
18175 | Windows では、C<system PROGRAM LIST> 構文のみが安定してシェルの使用を | |
15296 | ||
18176 | 回避します; C<system LIST> は、2 要素以上でも、最初の spawn が失敗すると | |
18177 | シェルにフォールバックします。 | |
15297 | 18178 | |
15298 | 18179 | =begin original |
15299 | 18180 | |
15300 | ||
18181 | Perl will attempt to flush all files opened for | |
15301 | 18182 | output before any operation that may do a fork, but this may not be |
15302 | 18183 | supported on some platforms (see L<perlport>). To be safe, you may need |
15303 | to set C<$|> ($AUTOFLUSH in English | |
18184 | to set L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>) | |
15304 | of C<IO::Handle> | |
18185 | or call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS> | |
18186 | on any open handles. | |
15305 | 18187 | |
15306 | 18188 | =end original |
15307 | 18189 | |
15308 | 18190 | v5.6.0 から、Perl は書き込み用に開いている全てのファイルに対して |
15309 | 18191 | fork を行う前にフラッシュしようとしますが、これに対応していない |
15310 | 18192 | プラットフォームもあります(L<perlport> を参照してください)。 |
15311 | 安全のために、C<$|> (English モジュールでは | |
18193 | 安全のために、L<C<$E<verbar>>|perlvar/$E<verbar>> (L<English> モジュールでは | |
15312 | 全ての開いているハンドルに対して | |
18194 | C<$AUTOFLUSH>) をセットするか、全ての開いているハンドルに対して | |
18195 | L<C<IO::Handle>|IO::Handle/METHODS> の C<autoflush> メソッドを | |
15313 | 18196 | 呼び出す必要があるかもしれません。 |
15314 | 18197 | |
15315 | 18198 | =begin original |
15316 | 18199 | |
15317 | 18200 | The return value is the exit status of the program as returned by the |
15318 | C<wait> call. To get the actual exit value, shift right by | |
18201 | L<C<wait>|/wait> call. To get the actual exit value, shift right by | |
15319 | below). See also L</exec>. This is I<not> what | |
18202 | eight (see below). See also L<C<exec>|/exec LIST>. This is I<not> what | |
15320 | the output from a command; for that you | |
18203 | you want to use to capture the output from a command; for that you | |
15321 | ||
18204 | should use merely backticks or | |
15322 | ||
18205 | L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>>, as described in | |
15323 | ||
18206 | L<perlop/"`STRING`">. Return value of -1 indicates a failure to start | |
18207 | the program or an error of the L<wait(2)> system call (inspect | |
18208 | L<C<$!>|perlvar/$!> for the reason). | |
15324 | 18209 | |
15325 | 18210 | =end original |
15326 | 18211 | |
15327 | 返り値は、C<wait> が返すプログラムの exit 状態です。 | |
18212 | 返り値は、L<C<wait>|/wait> が返すプログラムの exit 状態です。 | |
15328 | 18213 | 実際の exit 値を得るには 右に 8 ビットシフトしてください(後述)。 |
15329 | L</exec> も参照してください。 | |
18214 | L<C<exec>|/exec LIST> も参照してください。 | |
15330 | 18215 | これはコマンドからの出力を捕らえるために使うものI<ではありません>; |
15331 | 18216 | そのような用途には、L<perlop/"`STRING`"> に記述されている |
15332 | 逆クォートや C<qx/ | |
18217 | 逆クォートや L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>> を使用してください。 | |
15333 | -1 の返り値はプログラムを開始させることに失敗したか、wait(2) | |
18218 | -1 の返り値はプログラムを開始させることに失敗したか、L<wait(2)> | |
15334 | 18219 | システムコールがエラーを出したことを示します |
15335 | (理由は $! を調べてください)。 | |
18220 | (理由は L<C<$!>|perlvar/$!> を調べてください)。 | |
15336 | 18221 | |
15337 | 18222 | =begin original |
15338 | 18223 | |
15339 | If you'd like to make C<system> (and many other bits of | |
18224 | If you'd like to make L<C<system>|/system LIST> (and many other bits of | |
15340 | have a look at the L<autodie> pragma. | |
18225 | Perl) die on error, have a look at the L<autodie> pragma. | |
15341 | 18226 | |
15342 | 18227 | =end original |
15343 | 18228 | |
15344 | もし C<system> (及び Perl のその他の多くの部分) でエラー時に | |
18229 | もし L<C<system>|/system LIST> (及び Perl のその他の多くの部分) でエラー時に | |
15345 | 18230 | die したいなら、L<autodie> プラグマを見てみてください。 |
15346 | 18231 | |
15347 | 18232 | =begin original |
15348 | 18233 | |
15349 | Like C<exec>, C<system> allows you to lie | |
18234 | Like L<C<exec>|/exec LIST>, L<C<system>|/system LIST> allows you to lie | |
15350 | you use the C<system PROGRAM LIST> | |
18235 | to a program about its name if you use the C<system PROGRAM LIST> | |
18236 | syntax. Again, see L<C<exec>|/exec LIST>. | |
15351 | 18237 | |
15352 | 18238 | =end original |
15353 | 18239 | |
15354 | C<exec> と同様に、C<system> | |
18240 | L<C<exec>|/exec LIST> と同様に、L<C<system>|/system LIST> でも | |
15355 | 使うことで、プログラムに対してその名前を | |
18241 | C<system PROGRAM LIST> の文法を使うことで、プログラムに対してその名前を | |
15356 | ||
18242 | 嘘をつくことができます。 | |
18243 | 再び、L<C<exec>|/exec LIST> を参照してください。 | |
15357 | 18244 | |
15358 | 18245 | =begin original |
15359 | 18246 | |
15360 | 18247 | Since C<SIGINT> and C<SIGQUIT> are ignored during the execution of |
15361 | C<system>, if you expect your program to terminate on | |
18248 | L<C<system>|/system LIST>, if you expect your program to terminate on | |
15362 | signals you will need to arrange to do so yourself | |
18249 | receipt of these signals you will need to arrange to do so yourself | |
15363 | value. | |
18250 | based on the return value. | |
15364 | 18251 | |
15365 | 18252 | =end original |
15366 | 18253 | |
15367 | C<SIGINT> と C<SIGQUIT> は C<system> の実行中は無視されるので、 | |
18254 | C<SIGINT> と C<SIGQUIT> は L<C<system>|/system LIST> の実行中は無視されるので、 | |
15368 | 18255 | これらのシグナルを受信して終了させることを想定したプログラムの場合、 |
15369 | 18256 | 返り値を利用するように変更する必要があります。 |
15370 | 18257 | |
15371 | @args = ("command", "arg1", "arg2"); | |
18258 | my @args = ("command", "arg1", "arg2"); | |
15372 | 18259 | system(@args) == 0 |
15373 | or die "system @args failed: $?" | |
18260 | or die "system @args failed: $?"; | |
15374 | 18261 | |
15375 | 18262 | =begin original |
15376 | 18263 | |
15377 | If you'd like to manually inspect C<system>'s failure, | |
18264 | If you'd like to manually inspect L<C<system>|/system LIST>'s failure, | |
15378 | possible failure modes by inspecting | |
18265 | you can check all possible failure modes by inspecting | |
18266 | L<C<$?>|perlvar/$?> like this: | |
15379 | 18267 | |
15380 | 18268 | =end original |
15381 | 18269 | |
15382 | C<system> の失敗を手動で検査したいなら、 | |
18270 | L<C<system>|/system LIST> の失敗を手動で検査したいなら、以下のように | |
15383 | ||
18271 | L<C<$?>|perlvar/$?> を調べることで、全ての失敗の可能性をチェックできます: | |
15384 | チェックできます: | |
15385 | 18272 | |
15386 | 18273 | if ($? == -1) { |
15387 | 18274 | print "failed to execute: $!\n"; |
15388 | 18275 | } |
15389 | 18276 | elsif ($? & 127) { |
15390 | 18277 | printf "child died with signal %d, %s coredump\n", |
15391 | 18278 | ($? & 127), ($? & 128) ? 'with' : 'without'; |
15392 | 18279 | } |
15393 | 18280 | else { |
15394 | 18281 | printf "child exited with value %d\n", $? >> 8; |
15395 | 18282 | } |
15396 | 18283 | |
15397 | 18284 | =begin original |
15398 | 18285 | |
15399 | Alternatively, you may inspect the value of | |
18286 | Alternatively, you may inspect the value of | |
15400 | ||
18287 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> with the | |
18288 | L<C<W*()>|POSIX/C<WIFEXITED>> calls from the L<POSIX> module. | |
15401 | 18289 | |
15402 | 18290 | =end original |
15403 | 18291 | |
15404 | または、POSIX モジュールの C<W*()> 呼び出しを使って | |
18292 | または、L<POSIX> モジュールの L<C<W*()>|POSIX/C<WIFEXITED>> 呼び出しを使って | |
15405 | C<${^CHILD_ERROR_NATIVE}> の値を | |
18293 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> の値を | |
18294 | 調べることもできます。 | |
15406 | 18295 | |
15407 | 18296 | =begin original |
15408 | 18297 | |
15409 | When C<system>'s arguments are executed indirectly by | |
18298 | When L<C<system>|/system LIST>'s arguments are executed indirectly by | |
15410 | results and return codes are subject to its quirks. | |
18299 | the shell, results and return codes are subject to its quirks. | |
15411 | See L<perlop/"`STRING`"> and L</exec> for details. | |
18300 | See L<perlop/"`STRING`"> and L<C<exec>|/exec LIST> for details. | |
15412 | 18301 | |
15413 | 18302 | =end original |
15414 | 18303 | |
15415 | C<system> の引数がシェルによって間接的に実行された場合、 | |
18304 | L<C<system>|/system LIST> の引数がシェルによって間接的に実行された場合、 | |
15416 | 18305 | 結果と返り値はシェルの癖によって変更されることがあります。 |
15417 | 詳細については L<perlop/"`STRING`"> と L</exec> を | |
18306 | 詳細については L<perlop/"`STRING`"> と L<C<exec>|/exec LIST> を | |
18307 | 参照してください。 | |
15418 | 18308 | |
15419 | 18309 | =begin original |
15420 | 18310 | |
15421 | Since C<system> does a C<fork> and | |
18311 | Since L<C<system>|/system LIST> does a L<C<fork>|/fork> and | |
15422 | handler. See L<perlipc> for | |
18312 | L<C<wait>|/wait> it may affect a C<SIGCHLD> handler. See L<perlipc> for | |
18313 | details. | |
15423 | 18314 | |
15424 | 18315 | =end original |
15425 | 18316 | |
15426 | C<system> は C<fork> と C<wait> を行うので、 | |
18317 | L<C<system>|/system LIST> は L<C<fork>|/fork> と L<C<wait>|/wait> を行うので、 | |
15427 | 受けます。 | |
18318 | C<SIGCHLD> ハンドラの影響を受けます。 | |
15428 | 18319 | 詳しくは L<perlipc> を参照してください。 |
15429 | 18320 | |
18321 | =begin original | |
18322 | ||
18323 | Portability issues: L<perlport/system>. | |
18324 | ||
18325 | =end original | |
18326 | ||
18327 | 移植性の問題: L<perlport/system>。 | |
18328 | ||
15430 | 18329 | =item syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET |
15431 | 18330 | X<syswrite> |
15432 | 18331 | |
15433 | 18332 | =item syswrite FILEHANDLE,SCALAR,LENGTH |
15434 | 18333 | |
15435 | 18334 | =item syswrite FILEHANDLE,SCALAR |
15436 | 18335 | |
18336 | =for Pod::Functions fixed-length unbuffered output to a filehandle | |
18337 | ||
15437 | 18338 | =begin original |
15438 | 18339 | |
15439 | 18340 | Attempts to write LENGTH bytes of data from variable SCALAR to the |
15440 | specified FILEHANDLE, using write(2). If LENGTH is | |
18341 | specified FILEHANDLE, using L<write(2)>. If LENGTH is | |
15441 | 18342 | not specified, writes whole SCALAR. It bypasses buffered IO, so |
15442 | mixing this with reads (other than C<sysread | |
18343 | mixing this with reads (other than C<sysread)>), | |
15443 | ||
18344 | L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>, | |
15444 | s | |
18345 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
15445 | ||
18346 | L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> may cause | |
15446 | ||
18347 | confusion because the perlio and stdio layers usually buffer data. | |
18348 | Returns the number of bytes actually written, or L<C<undef>|/undef EXPR> | |
18349 | if there was an error (in this case the errno variable | |
18350 | L<C<$!>|perlvar/$!> is also set). If the LENGTH is greater than the | |
15447 | 18351 | data available in the SCALAR after the OFFSET, only as much data as is |
15448 | 18352 | available will be written. |
15449 | 18353 | |
15450 | 18354 | =end original |
15451 | 18355 | |
15452 | write(2) を使って、指定した FILEHANDLEへ、 | |
18356 | L<write(2)> を使って、指定した FILEHANDLEへ、変数 SCALAR から、LENGTH バイトの | |
15453 | ||
18357 | データの書き込みを試みます。 | |
15454 | 18358 | LENGTH が指定されなかった場合、 SCALAR 全体を書き込みます。 |
15455 | これは、バッファ付き IO ルーチンを通りませんから、 | |
18359 | これは、バッファ付き IO ルーチンを通りませんから、他の入力関数 | |
15456 | ||
18360 | (C<sysread> 以外), | |
15457 | C< | |
18361 | L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>, | |
15458 | ||
18362 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>, | |
18363 | L<C<eof>|/eof FILEHANDLE> と混ぜて使うと、出力がおかしくなるかもしれません; | |
15459 | 18364 | perlio 層と stdio 層は普通データをバッファリングするからです。 |
15460 | 実際に読み込まれたデータの長さか、エラー時には C<undef> が | |
18365 | 実際に読み込まれたデータの長さか、エラー時には L<C<undef>|/undef EXPR> が | |
15461 | (この場合エラー変数 C<$!> もセットされます)。 | |
18366 | 返されます(この場合エラー変数 L<C<$!>|perlvar/$!> もセットされます)。 | |
15462 | 18367 | LENGTH が OFFSET 以降の SCALAR の利用可能なデータより大きかった場合、 |
15463 | 18368 | 利用可能なデータのみが書き込まれます。 |
15464 | 18369 | |
15465 | 18370 | =begin original |
15466 | 18371 | |
15467 | 18372 | An OFFSET may be specified to write the data from some part of the |
15468 | 18373 | string other than the beginning. A negative OFFSET specifies writing |
15469 | 18374 | that many characters counting backwards from the end of the string. |
15470 | 18375 | If SCALAR is of length zero, you can only use an OFFSET of 0. |
15471 | 18376 | |
15472 | 18377 | =end original |
15473 | 18378 | |
15474 | 18379 | OFFSET を指定すると、SCALAR の先頭以外の場所から、 |
15475 | 18380 | データを取り出して、書き込みを行なうことができます。 |
15476 | 18381 | OFFSET に負の値を指定すると、文字列の最後から逆向きに数えて |
15477 | 18382 | 何バイト目から書き込むかを示します。 |
15478 | 18383 | SCALAR の長さが 0 の場合、OFFSET は 0 のみ使用できます。 |
15479 | 18384 | |
15480 | 18385 | =begin original |
15481 | 18386 | |
15482 | 18387 | B<WARNING>: If the filehandle is marked C<:utf8>, Unicode characters |
15483 | 18388 | encoded in UTF-8 are written instead of bytes, and the LENGTH, OFFSET, and |
15484 | return value of syswrite | |
18389 | return value of L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> | |
18390 | are in (UTF8-encoded Unicode) characters. | |
15485 | 18391 | The C<:encoding(...)> layer implicitly introduces the C<:utf8> layer. |
15486 | 18392 | Alternately, if the handle is not marked with an encoding but you |
15487 | 18393 | attempt to write characters with code points over 255, raises an exception. |
15488 | See L< | |
18394 | See L<C<binmode>|/binmode FILEHANDLE, LAYER>, | |
18395 | L<C<open>|/open FILEHANDLE,EXPR>, and the L<open> pragma. | |
15489 | 18396 | |
15490 | 18397 | =end original |
15491 | 18398 | |
15492 | 18399 | B<警告>: ファイルハンドルが C<:utf8> であるとマークが付けられると、 |
15493 | 18400 | バイトではなく UTF-8 エンコードされた Unicode 文字が読み込まれ、 |
15494 | syswrite | |
18401 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> の LENGTH, OFFSET | |
15495 | Unicode) 文字単位になります。 | |
18402 | および返り値は (UTF8 エンコードされた Unicode) 文字単位になります。 | |
15496 | 18403 | C<:encoding(...)> 層は暗黙のうちに C<:utf8> 層が導入されます。 |
15497 | 18404 | または、もしハンドルにエンコーディングが記録されていない状態で |
15498 | 18405 | 255 を超える符号位置の文字を書き込もうとすると、例外が発生します。 |
15499 | L< | |
18406 | L<C<binmode>|/binmode FILEHANDLE, LAYER>, L<C<open>|/open FILEHANDLE,EXPR>, | |
18407 | L<open> プラグマを参照してください。 | |
15500 | 18408 | |
15501 | 18409 | =item tell FILEHANDLE |
15502 | 18410 | X<tell> |
15503 | 18411 | |
15504 | 18412 | =item tell |
15505 | 18413 | |
18414 | =for Pod::Functions get current seekpointer on a filehandle | |
18415 | ||
15506 | 18416 | =begin original |
15507 | 18417 | |
15508 | 18418 | Returns the current position I<in bytes> for FILEHANDLE, or -1 on |
15509 | 18419 | error. FILEHANDLE may be an expression whose value gives the name of |
15510 | 18420 | the actual filehandle. If FILEHANDLE is omitted, assumes the file |
15511 | 18421 | last read. |
15512 | 18422 | |
15513 | 18423 | =end original |
15514 | 18424 | |
15515 | FILEHANDLE の現在の位置を I<バイト数で> 返します | |
18425 | FILEHANDLE の現在の位置を I<バイト数で> 返します; エラーの場合は -1 を | |
15516 | ||
18426 | 返します。 | |
15517 | 18427 | FILEHANDLE は、実際のファイルハンドル名を示す式でもかまいません。 |
15518 | FILEHANDLE が省略された場合には、 | |
18428 | FILEHANDLE が省略された場合には、最後に読み込みを行なったファイルについて | |
15519 | ||
18429 | 調べます。 | |
15520 | 18430 | |
15521 | 18431 | =begin original |
15522 | 18432 | |
15523 | 18433 | Note the I<in bytes>: even if the filehandle has been set to |
15524 | 18434 | operate on characters (for example by using the C<:encoding(utf8)> open |
15525 | layer), tell | |
18435 | layer), L<C<tell>|/tell FILEHANDLE> will return byte offsets, not | |
15526 | that would render | |
18436 | character offsets (because that would render | |
18437 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> and | |
18438 | L<C<tell>|/tell FILEHANDLE> rather slow). | |
15527 | 18439 | |
15528 | 18440 | =end original |
15529 | 18441 | |
15530 | 18442 | I<バイト単位> に関する注意: ファイルハンドルが (例えば |
15531 | 18443 | C<:encoding(utf8)> 層を使って) |
15532 | 文字を操作するように設定されていたとしても、tell | |
18444 | 文字を操作するように設定されていたとしても、L<C<tell>|/tell FILEHANDLE> は | |
15533 | オフセットではなくバイトのオフセットを返すことに注意してください | |
18445 | 文字のオフセットではなくバイトのオフセットを返すことに注意してください | |
15534 | (なぜならこれは seek | |
18446 | (なぜならこれは L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> と | |
18447 | L<C<tell>|/tell FILEHANDLE> が遅くなってしまうからです)。 | |
15535 | 18448 | |
15536 | 18449 | =begin original |
15537 | 18450 | |
15538 | The return value of tell | |
18451 | The return value of L<C<tell>|/tell FILEHANDLE> for the standard streams | |
15539 | depends on the operating system: it may return -1 or | |
18452 | like the STDIN depends on the operating system: it may return -1 or | |
15540 | tell | |
18453 | something else. L<C<tell>|/tell FILEHANDLE> on pipes, fifos, and | |
18454 | sockets usually returns -1. | |
15541 | 18455 | |
15542 | 18456 | =end original |
15543 | 18457 | |
15544 | STDIN のような標準ストリームに対する tell | |
18458 | STDIN のような標準ストリームに対する L<C<tell>|/tell FILEHANDLE> の返り値は | |
18459 | OS に依存します: | |
15545 | 18460 | -1 やその他の値が返ってくるかもしれません。 |
15546 | パイプ、FIFO、ソケットに対して tell | |
18461 | パイプ、FIFO、ソケットに対して L<C<tell>|/tell FILEHANDLE> を使うと、普通は | |
18462 | -1 が返ります。 | |
15547 | 18463 | |
15548 | 18464 | =begin original |
15549 | 18465 | |
15550 | There is no C<systell> function. Use C<sysseek( | |
18466 | There is no C<systell> function. Use C<sysseek($fh, 0, 1)> for that. | |
15551 | 18467 | |
15552 | 18468 | =end original |
15553 | 18469 | |
15554 | 18470 | C<systell> 関数はありません。 |
15555 | 代わりに C<sysseek( | |
18471 | 代わりに C<sysseek($fh, 0, 1)> を使ってください。 | |
15556 | 18472 | |
15557 | 18473 | =begin original |
15558 | 18474 | |
15559 | Do not use tell | |
18475 | Do not use L<C<tell>|/tell FILEHANDLE> (or other buffered I/O | |
15560 | that has been manipulated by | |
18476 | operations) on a filehandle that has been manipulated by | |
15561 | ||
18477 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
18478 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, or | |
18479 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>. Those functions | |
18480 | ignore the buffering, while L<C<tell>|/tell FILEHANDLE> does not. | |
15562 | 18481 | |
15563 | 18482 | =end original |
15564 | 18483 | |
15565 | sysread | |
18484 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
18485 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
18486 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> で操作された | |
18487 | ファイルハンドルに L<C<tell>|/tell FILEHANDLE> | |
15566 | 18488 | (またはその他のバッファリング I/O 操作) を使わないでください。 |
15567 | これらの関数はバッファリングを無視しますが、tell | |
18489 | これらの関数はバッファリングを無視しますが、L<C<tell>|/tell FILEHANDLE> は | |
18490 | 違います。 | |
15568 | 18491 | |
15569 | 18492 | =item telldir DIRHANDLE |
15570 | 18493 | X<telldir> |
15571 | 18494 | |
18495 | =for Pod::Functions get current seekpointer on a directory handle | |
18496 | ||
15572 | 18497 | =begin original |
15573 | 18498 | |
15574 | Returns the current position of the C<readdir> | |
18499 | Returns the current position of the L<C<readdir>|/readdir DIRHANDLE> | |
15575 | Value may be given to | |
18500 | routines on DIRHANDLE. Value may be given to | |
15576 | dire | |
18501 | L<C<seekdir>|/seekdir DIRHANDLE,POS> to access a particular location in | |
15577 | ||
18502 | a directory. L<C<telldir>|/telldir DIRHANDLE> has the same caveats | |
18503 | about possible directory compaction as the corresponding system library | |
18504 | routine. | |
15578 | 18505 | |
15579 | 18506 | =end original |
15580 | 18507 | |
15581 | DIRHANDLE 上の C<readdir> ルーチンに対する現在位置を | |
18508 | DIRHANDLE 上の L<C<readdir>|/readdir DIRHANDLE> ルーチンに対する現在位置を | |
18509 | 返します。 | |
15582 | 18510 | 値は、そのディレクトリで特定の位置をアクセスするため、 |
15583 | C<seekdir> に渡すことができます。 | |
18511 | L<C<seekdir>|/seekdir DIRHANDLE,POS> に渡すことができます。 | |
15584 | C<telldir> は同名のシステムライブラリルーチンと同じく、 | |
18512 | L<C<telldir>|/telldir DIRHANDLE> は同名のシステムライブラリルーチンと同じく、 | |
15585 | 18513 | ディレクトリ縮小時の問題が考えられます。 |
15586 | 18514 | |
15587 | 18515 | =item tie VARIABLE,CLASSNAME,LIST |
15588 | 18516 | X<tie> |
15589 | 18517 | |
18518 | =for Pod::Functions +5.002 bind a variable to an object class | |
18519 | ||
15590 | 18520 | =begin original |
15591 | 18521 | |
15592 | 18522 | This function binds a variable to a package class that will provide the |
15593 | 18523 | implementation for the variable. VARIABLE is the name of the variable |
15594 | 18524 | to be enchanted. CLASSNAME is the name of a class implementing objects |
15595 | of correct type. Any additional arguments are passed to the | |
18525 | of correct type. Any additional arguments are passed to the | |
18526 | appropriate constructor | |
15596 | 18527 | method of the class (meaning C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>, |
15597 | 18528 | or C<TIEHASH>). Typically these are arguments such as might be passed |
15598 | to the | |
18529 | to the L<dbm_open(3)> function of C. The object returned by the | |
15599 | ||
18530 | constructor is also returned by the | |
18531 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function, which would be useful | |
15600 | 18532 | if you want to access other methods in CLASSNAME. |
15601 | 18533 | |
15602 | 18534 | =end original |
15603 | 18535 | |
15604 | 18536 | この関数は、変数を、その変数の実装を行なうクラスと結び付けます。 |
15605 | 18537 | VARIABLE は、魔法をかける変数の名前です。 |
15606 | 18538 | CLASSNAME は、正しい型のオブジェクトを実装するクラスの名前です。 |
15607 | 他に引数があれば、そのクラスの | |
18539 | 他に引数があれば、そのクラスの適切なコンストラクタメソッドに渡されます | |
15608 | 18540 | (つまり C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>, C<TIEHASH>)。 |
15609 | 通常、これらは、C の | |
18541 | 通常、これらは、C の L<dbm_open(3)> などの関数に渡す引数となります。 | |
15610 | ||
18542 | コンストラクタで返されるオブジェクトはまた | |
18543 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数でも返されます; | |
15611 | 18544 | これは CLASSNAME の他のメソッドにアクセスしたいときに便利です。 |
15612 | 18545 | |
15613 | 18546 | =begin original |
15614 | 18547 | |
15615 | Note that functions such as C<keys> | |
18548 | Note that functions such as L<C<keys>|/keys HASH> and | |
15616 | ||
18549 | L<C<values>|/values HASH> may return huge lists when used on large | |
15617 | ||
18550 | objects, like DBM files. You may prefer to use the L<C<each>|/each | |
18551 | HASH> function to iterate over such. Example: | |
15618 | 18552 | |
15619 | 18553 | =end original |
15620 | 18554 | |
15621 | DBM ファイルのような大きなオブジェクトでは、C<keys> | |
18555 | DBM ファイルのような大きなオブジェクトでは、L<C<keys>|/keys HASH> や | |
15622 | 関数は、大きなリストを返す可能性があります。 | |
18556 | L<C<values>|/values HASH> のような関数は、大きなリストを返す可能性があります。 | |
15623 | そのような場合では、C<each> 関数を使って繰り返しを行なった方が | |
18557 | そのような場合では、L<C<each>|/each HASH> 関数を使って繰り返しを行なった方が | |
15624 | 18558 | よいかもしれません。 |
15625 | 18559 | 例: |
15626 | 18560 | |
15627 | 18561 | # print out history file offsets |
15628 | 18562 | use NDBM_File; |
15629 | tie(%HIST, 'NDBM_File', '/usr/lib/news/history', 1, 0); | |
18563 | tie(my %HIST, 'NDBM_File', '/usr/lib/news/history', 1, 0); | |
15630 | while (($key,$val) = each %HIST) { | |
18564 | while (my ($key,$val) = each %HIST) { | |
15631 | print $key, ' = ', unpack('L',$val), "\n"; | |
18565 | print $key, ' = ', unpack('L', $val), "\n"; | |
15632 | 18566 | } |
15633 | untie(%HIST); | |
15634 | 18567 | |
15635 | 18568 | =begin original |
15636 | 18569 | |
15637 | 18570 | A class implementing a hash should have the following methods: |
15638 | 18571 | |
15639 | 18572 | =end original |
15640 | 18573 | |
15641 | 18574 | ハッシュを実装するクラスでは、次のようなメソッドを用意します: |
15642 | 18575 | |
15643 | 18576 | TIEHASH classname, LIST |
15644 | 18577 | FETCH this, key |
15645 | 18578 | STORE this, key, value |
15646 | 18579 | DELETE this, key |
15647 | 18580 | CLEAR this |
15648 | 18581 | EXISTS this, key |
15649 | 18582 | FIRSTKEY this |
15650 | 18583 | NEXTKEY this, lastkey |
15651 | 18584 | SCALAR this |
15652 | 18585 | DESTROY this |
15653 | 18586 | UNTIE this |
15654 | 18587 | |
15655 | 18588 | =begin original |
15656 | 18589 | |
15657 | 18590 | A class implementing an ordinary array should have the following methods: |
15658 | 18591 | |
15659 | 18592 | =end original |
15660 | 18593 | |
15661 | 18594 | 通常の配列を実装するクラスでは、次のようなメソッドを用意します: |
15662 | 18595 | |
15663 | 18596 | TIEARRAY classname, LIST |
15664 | 18597 | FETCH this, key |
15665 | 18598 | STORE this, key, value |
15666 | 18599 | FETCHSIZE this |
15667 | 18600 | STORESIZE this, count |
15668 | 18601 | CLEAR this |
15669 | 18602 | PUSH this, LIST |
15670 | 18603 | POP this |
15671 | 18604 | SHIFT this |
15672 | 18605 | UNSHIFT this, LIST |
15673 | 18606 | SPLICE this, offset, length, LIST |
15674 | 18607 | EXTEND this, count |
18608 | DELETE this, key | |
18609 | EXISTS this, key | |
15675 | 18610 | DESTROY this |
15676 | 18611 | UNTIE this |
15677 | 18612 | |
15678 | 18613 | =begin original |
15679 | 18614 | |
15680 | 18615 | A class implementing a filehandle should have the following methods: |
15681 | 18616 | |
15682 | 18617 | =end original |
15683 | 18618 | |
15684 | 18619 | ファイルハンドルを実装するクラスでは、次のようなメソッドを用意します: |
15685 | 18620 | |
15686 | 18621 | TIEHANDLE classname, LIST |
15687 | 18622 | READ this, scalar, length, offset |
15688 | 18623 | READLINE this |
15689 | 18624 | GETC this |
15690 | 18625 | WRITE this, scalar, length, offset |
15691 | 18626 | PRINT this, LIST |
15692 | 18627 | PRINTF this, format, LIST |
15693 | 18628 | BINMODE this |
15694 | 18629 | EOF this |
15695 | 18630 | FILENO this |
15696 | 18631 | SEEK this, position, whence |
15697 | 18632 | TELL this |
15698 | 18633 | OPEN this, mode, LIST |
15699 | 18634 | CLOSE this |
15700 | 18635 | DESTROY this |
15701 | 18636 | UNTIE this |
15702 | 18637 | |
15703 | 18638 | =begin original |
15704 | 18639 | |
15705 | 18640 | A class implementing a scalar should have the following methods: |
15706 | 18641 | |
15707 | 18642 | =end original |
15708 | 18643 | |
15709 | 18644 | スカラ変数を実装するクラスでは、次のようなメソッドを用意します: |
15710 | 18645 | |
15711 | 18646 | TIESCALAR classname, LIST |
15712 | 18647 | FETCH this, |
15713 | 18648 | STORE this, value |
15714 | 18649 | DESTROY this |
15715 | 18650 | UNTIE this |
15716 | 18651 | |
15717 | 18652 | =begin original |
15718 | 18653 | |
15719 | 18654 | Not all methods indicated above need be implemented. See L<perltie>, |
15720 | 18655 | L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>, and L<Tie::Handle>. |
15721 | 18656 | |
15722 | 18657 | =end original |
15723 | 18658 | |
15724 | 18659 | 上記の全てのメソッドを実装する必要はありません。 |
15725 | 18660 | L<perltie>, L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>, |
15726 | L<Tie::Handle> を参照して | |
18661 | L<Tie::Handle> を参照してください。 | |
15727 | 18662 | |
15728 | 18663 | =begin original |
15729 | 18664 | |
15730 | Unlike C<dbmopen> | |
18665 | Unlike L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, the | |
15731 | ||
18666 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function will not | |
15732 | ||
18667 | L<C<use>|/use Module VERSION LIST> or L<C<require>|/require VERSION> a | |
18668 | module for you; you need to do that explicitly yourself. See L<DB_File> | |
18669 | or the L<Config> module for interesting | |
18670 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> implementations. | |
15733 | 18671 | |
15734 | 18672 | =end original |
15735 | 18673 | |
15736 | C<dbmopen> と違い、 | |
18674 | L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> と違い、 | |
15737 | C< | |
18675 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数はモジュールを | |
15738 | C< | |
18676 | L<C<use>|/use Module VERSION LIST> したり | |
15739 | ||
18677 | L<C<require>|/require VERSION> したりしません; | |
18678 | 自分で明示的に行う必要があります。 | |
18679 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> の興味深い実装については | |
18680 | L<DB_File> や L<Config> モジュールを参照してください。 | |
15740 | 18681 | |
15741 | 18682 | =begin original |
15742 | 18683 | |
15743 | For further details see L<perltie>, L< | |
18684 | For further details see L<perltie>, L<C<tied>|/tied VARIABLE>. | |
15744 | 18685 | |
15745 | 18686 | =end original |
15746 | 18687 | |
15747 | 更なる詳細については L<perltie> や L< | |
18688 | 更なる詳細については L<perltie> や L<C<tied>|/tied VARIABLE> を | |
18689 | 参照してください。 | |
15748 | 18690 | |
15749 | 18691 | =item tied VARIABLE |
15750 | 18692 | X<tied> |
15751 | 18693 | |
18694 | =for Pod::Functions get a reference to the object underlying a tied variable | |
18695 | ||
15752 | 18696 | =begin original |
15753 | 18697 | |
15754 | 18698 | Returns a reference to the object underlying VARIABLE (the same value |
15755 | that was originally returned by the | |
18699 | that was originally returned by the | |
18700 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> call that bound the variable | |
15756 | 18701 | to a package.) Returns the undefined value if VARIABLE isn't tied to a |
15757 | 18702 | package. |
15758 | 18703 | |
15759 | 18704 | =end original |
15760 | 18705 | |
15761 | 18706 | VARIABLE の基となるオブジェクトへのリファレンスを返します |
15762 | (変数をパッケージに結びつけるために | |
18707 | (変数をパッケージに結びつけるために | |
18708 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 呼び出しをしたときの | |
15763 | 18709 | 返り値と同じものです)。 |
15764 | 18710 | VARIABLE がパッケージと結び付けられていない場合は未定義値を返します。 |
15765 | 18711 | |
15766 | 18712 | =item time |
15767 | 18713 | X<time> X<epoch> |
15768 | 18714 | |
18715 | =for Pod::Functions return number of seconds since 1970 | |
18716 | ||
15769 | 18717 | =begin original |
15770 | 18718 | |
15771 | 18719 | Returns the number of non-leap seconds since whatever time the system |
15772 | considers to be the epoch, suitable for feeding to | |
18720 | considers to be the epoch, suitable for feeding to | |
15773 | C< | |
18721 | L<C<gmtime>|/gmtime EXPR> and L<C<localtime>|/localtime EXPR>. On most | |
18722 | systems the epoch is 00:00:00 UTC, January 1, 1970; | |
15774 | 18723 | a prominent exception being Mac OS Classic which uses 00:00:00, January 1, |
15775 | 18724 | 1904 in the current local time zone for its epoch. |
15776 | 18725 | |
15777 | 18726 | =end original |
15778 | 18727 | |
15779 | C<gmtime> や C<localtime> への入力形式に | |
18728 | L<C<gmtime>|/gmtime EXPR> や L<C<localtime>|/localtime EXPR> への入力形式に | |
15780 | システムが紀元と考える時点からの連続秒数を返します。 | |
18729 | 合っている、システムが紀元と考える時点からの連続秒数を返します。 | |
15781 | 18730 | ほとんどのシステムでは紀元は UTC 1970 年 1 月 1 日 00:00:00 です; |
15782 | 18731 | 特徴的な例外としては、古い Mac OS ではローカルタイムゾーンの |
15783 | 18732 | 1904 年 1 月 1 日 00:00:00 を紀元として使います。 |
15784 | 18733 | |
15785 | 18734 | =begin original |
15786 | 18735 | |
15787 | 18736 | For measuring time in better granularity than one second, use the |
15788 | 18737 | L<Time::HiRes> module from Perl 5.8 onwards (or from CPAN before then), or, |
15789 | if you have gettimeofday(2), you may be able to use the | |
18738 | if you have L<gettimeofday(2)>, you may be able to use the | |
15790 | interface of Perl. See L<perlfaq8> | |
18739 | L<C<syscall>|/syscall NUMBER, LIST> interface of Perl. See L<perlfaq8> | |
18740 | for details. | |
15791 | 18741 | |
15792 | 18742 | =end original |
15793 | 18743 | |
15794 | 18744 | 1 秒よりも細かい時間を計測するためには、Perl 5.8 以降(それ以前では |
15795 | 18745 | CPANから)の L<Time::HiRes> モジュールを使うか、 |
15796 | gettimeofday(2) があるなら、Perl の | |
18746 | L<gettimeofday(2)> があるなら、Perl の | |
15797 | 使ってください。 | |
18747 | L<C<syscall>|/syscall NUMBER, LIST> インターフェースを使ってください。 | |
15798 | 詳しくは L<perlfaq8> を参照して | |
18748 | 詳しくは L<perlfaq8> を参照してください。 | |
15799 | 18749 | |
15800 | 18750 | =begin original |
15801 | 18751 | |
15802 | 18752 | For date and time processing look at the many related modules on CPAN. |
15803 | 18753 | For a comprehensive date and time representation look at the |
15804 | 18754 | L<DateTime> module. |
15805 | 18755 | |
15806 | 18756 | =end original |
15807 | 18757 | |
15808 | 18758 | 日付と時刻の処理は、多くの関連するモジュールが CPAN にあります。 |
15809 | 18759 | 包括的な日付と時刻の表現については、CPAN の L<DateTime> モジュールを |
15810 | 18760 | 参照してください。 |
15811 | 18761 | |
15812 | 18762 | =item times |
15813 | 18763 | X<times> |
15814 | 18764 | |
18765 | =for Pod::Functions return elapsed time for self and child processes | |
18766 | ||
15815 | 18767 | =begin original |
15816 | 18768 | |
15817 | 18769 | Returns a four-element list giving the user and system times in |
15818 | 18770 | seconds for this process and any exited children of this process. |
15819 | 18771 | |
15820 | 18772 | =end original |
15821 | 18773 | |
15822 | 18774 | 現プロセス及び終了したその子プロセスに対する、ユーザ時間とシステム時間を |
15823 | 18775 | 秒で示した、4 要素のリスト値を返します。 |
15824 | 18776 | |
15825 | ($user,$system,$cuser,$csystem) = times; | |
18777 | my ($user,$system,$cuser,$csystem) = times; | |
15826 | 18778 | |
15827 | 18779 | =begin original |
15828 | 18780 | |
15829 | In scalar context, C<times> returns C<$user>. | |
18781 | In scalar context, L<C<times>|/times> returns C<$user>. | |
15830 | 18782 | |
15831 | 18783 | =end original |
15832 | 18784 | |
15833 | スカラコンテキストでは、C<times> は C<$user> を返します。 | |
18785 | スカラコンテキストでは、L<C<times>|/times> は C<$user> を返します。 | |
15834 | 18786 | |
15835 | 18787 | =begin original |
15836 | 18788 | |
15837 | 18789 | Children's times are only included for terminated children. |
15838 | 18790 | |
15839 | 18791 | =end original |
15840 | 18792 | |
15841 | 18793 | 子プロセスに対する times は、終了した子プロセスのみ含められます。 |
15842 | 18794 | |
18795 | =begin original | |
18796 | ||
18797 | Portability issues: L<perlport/times>. | |
18798 | ||
18799 | =end original | |
18800 | ||
18801 | 移植性の問題: L<perlport/times>。 | |
18802 | ||
15843 | 18803 | =item tr/// |
15844 | 18804 | |
18805 | =for Pod::Functions transliterate a string | |
18806 | ||
15845 | 18807 | =begin original |
15846 | 18808 | |
15847 | The transliteration operator. Same as | |
18809 | The transliteration operator. Same as | |
15848 | L< | |
18810 | L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>>. See | |
18811 | L<perlop/"Quote-Like Operators">. | |
15849 | 18812 | |
15850 | 18813 | =end original |
15851 | 18814 | |
15852 | 変換演算子。 | |
18815 | 文字変換演算子です。 | |
15853 | C<y/ | |
18816 | L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>> と同じです。 | |
15854 | L<perlop/"Quote | |
18817 | L<perlop/"Quote-Like Operators"> を参照してください。 | |
15855 | 18818 | |
15856 | 18819 | =item truncate FILEHANDLE,LENGTH |
15857 | 18820 | X<truncate> |
15858 | 18821 | |
15859 | 18822 | =item truncate EXPR,LENGTH |
15860 | 18823 | |
18824 | =for Pod::Functions shorten a file | |
18825 | ||
15861 | 18826 | =begin original |
15862 | 18827 | |
15863 | 18828 | Truncates the file opened on FILEHANDLE, or named by EXPR, to the |
15864 | 18829 | specified length. Raises an exception if truncate isn't implemented |
15865 | on your system. Returns true if successful, C<undef> | |
18830 | on your system. Returns true if successful, L<C<undef>|/undef EXPR> on | |
18831 | error. | |
15866 | 18832 | |
15867 | 18833 | =end original |
15868 | 18834 | |
15869 | 18835 | FILEHANDLE 上にオープンされたファイルか、EXPR で名前を表わしたファイルを、 |
15870 | 18836 | 指定した長さに切り詰めます。 |
15871 | 18837 | システム上に truncate が実装されていなければ、例外が発生します。 |
15872 | 成功すれば真を、エラー時には C<undef> を返します。 | |
18838 | 成功すれば真を、エラー時には L<C<undef>|/undef EXPR> を返します。 | |
15873 | 18839 | |
15874 | 18840 | =begin original |
15875 | 18841 | |
15876 | 18842 | The behavior is undefined if LENGTH is greater than the length of the |
15877 | 18843 | file. |
15878 | 18844 | |
15879 | 18845 | =end original |
15880 | 18846 | |
15881 | 18847 | LENGTH がファイルの長さより大きい場合の振る舞いは未定義です。 |
15882 | 18848 | |
15883 | 18849 | =begin original |
15884 | 18850 | |
15885 | 18851 | The position in the file of FILEHANDLE is left unchanged. You may want to |
15886 | call L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> before writing to the | |
18852 | call L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> before writing to the | |
18853 | file. | |
15887 | 18854 | |
15888 | 18855 | =end original |
15889 | 18856 | |
15890 | 18857 | FILEHANDLE のファイルの位置は変わりません。 |
15891 | 18858 | ファイルに書き込む前に L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> を |
15892 | 18859 | 呼び出したいかもしれません。 |
15893 | 18860 | |
18861 | =begin original | |
18862 | ||
18863 | Portability issues: L<perlport/truncate>. | |
18864 | ||
18865 | =end original | |
18866 | ||
18867 | 移植性の問題: L<perlport/truncate>。 | |
18868 | ||
15894 | 18869 | =item uc EXPR |
15895 | 18870 | X<uc> X<uppercase> X<toupper> |
15896 | 18871 | |
15897 | 18872 | =item uc |
15898 | 18873 | |
18874 | =for Pod::Functions return upper-case version of a string | |
18875 | ||
15899 | 18876 | =begin original |
15900 | 18877 | |
15901 | 18878 | Returns an uppercased version of EXPR. This is the internal function |
15902 | 18879 | implementing the C<\U> escape in double-quoted strings. |
15903 | 18880 | It does not attempt to do titlecase mapping on initial letters. See |
15904 | L</ucfirst> for that. | |
18881 | L<C<ucfirst>|/ucfirst EXPR> for that. | |
15905 | 18882 | |
15906 | 18883 | =end original |
15907 | 18884 | |
15908 | 18885 | EXPR を大文字に変換したものを返します。 |
15909 | 18886 | これは、ダブルクォート文字列における、C<\U> エスケープを |
15910 | 18887 | 実装する内部関数です。 |
15911 | 18888 | 先頭文字の タイトル文字マッピングは試みません。 |
15912 | このためには L</ucfirst> を参照してください。 | |
18889 | このためには L<C<ucfirst>|/ucfirst EXPR> を参照してください。 | |
15913 | 18890 | |
15914 | 18891 | =begin original |
15915 | 18892 | |
15916 | If EXPR is omitted, uses C<$_>. | |
18893 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. | |
15917 | 18894 | |
15918 | 18895 | =end original |
15919 | 18896 | |
15920 | EXPR が省略されると、C<$_> を使います。 | |
18897 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
15921 | 18898 | |
15922 | 18899 | =begin original |
15923 | 18900 | |
15924 | This function behaves the same way under various pragma, such as in a locale, | |
18901 | This function behaves the same way under various pragmas, such as in a locale, | |
15925 | as L</lc> does. | |
18902 | as L<C<lc>|/lc EXPR> does. | |
15926 | 18903 | |
15927 | 18904 | =end original |
15928 | 18905 | |
15929 | 18906 | この関数は、ロケールのようなさまざまなプラグマの影響下では、 |
15930 | L</lc> と同様に振る舞います。 | |
18907 | L<C<lc>|/lc EXPR> と同様に振る舞います。 | |
15931 | 18908 | |
15932 | 18909 | =item ucfirst EXPR |
15933 | 18910 | X<ucfirst> X<uppercase> |
15934 | 18911 | |
15935 | 18912 | =item ucfirst |
15936 | 18913 | |
18914 | =for Pod::Functions return a string with just the next letter in upper case | |
18915 | ||
15937 | 18916 | =begin original |
15938 | 18917 | |
15939 | 18918 | Returns the value of EXPR with the first character in uppercase |
15940 | 18919 | (titlecase in Unicode). This is the internal function implementing |
15941 | 18920 | the C<\u> escape in double-quoted strings. |
15942 | 18921 | |
15943 | 18922 | =end original |
15944 | 18923 | |
15945 | 18924 | 最初の文字だけを大文字にした、EXPR を返します |
15946 | 18925 | (Unicode では titlecase)。 |
15947 | 18926 | これは、ダブルクォート文字列における、C<\u> エスケープを |
15948 | 18927 | 実装する内部関数です。 |
15949 | 18928 | |
15950 | 18929 | =begin original |
15951 | 18930 | |
15952 | If EXPR is omitted, uses C<$_>. | |
18931 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. | |
15953 | 18932 | |
15954 | 18933 | =end original |
15955 | 18934 | |
15956 | EXPR が省略されると、C<$_> を使います。 | |
18935 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
15957 | 18936 | |
15958 | 18937 | =begin original |
15959 | 18938 | |
15960 | This function behaves the same way under various pragma, such as in a locale, | |
18939 | This function behaves the same way under various pragmas, such as in a locale, | |
15961 | as L</lc> does. | |
18940 | as L<C<lc>|/lc EXPR> does. | |
15962 | 18941 | |
15963 | 18942 | =end original |
15964 | 18943 | |
15965 | 18944 | この関数は、ロケールのようなさまざまなプラグマの影響下では、 |
15966 | L</lc> と同様に振る舞います。 | |
18945 | L<C<lc>|/lc EXPR> と同様に振る舞います。 | |
15967 | 18946 | |
15968 | 18947 | =item umask EXPR |
15969 | 18948 | X<umask> |
15970 | 18949 | |
15971 | 18950 | =item umask |
15972 | 18951 | |
18952 | =for Pod::Functions set file creation mode mask | |
18953 | ||
15973 | 18954 | =begin original |
15974 | 18955 | |
15975 | 18956 | Sets the umask for the process to EXPR and returns the previous value. |
15976 | 18957 | If EXPR is omitted, merely returns the current umask. |
15977 | 18958 | |
15978 | 18959 | =end original |
15979 | 18960 | |
15980 | 18961 | 現在のプロセスの umask を EXPR に設定し、以前の値を返します。 |
15981 | 18962 | EXPR が省略されると、単にその時点の umask の値を返します。 |
15982 | 18963 | |
15983 | 18964 | =begin original |
15984 | 18965 | |
15985 | 18966 | The Unix permission C<rwxr-x---> is represented as three sets of three |
15986 | 18967 | bits, or three octal digits: C<0750> (the leading 0 indicates octal |
15987 | and isn't one of the digits). The C<umask> value is such | |
18968 | and isn't one of the digits). The L<C<umask>|/umask EXPR> value is such | |
15988 | representing disabled permissions bits. The permission (or | |
18969 | a number representing disabled permissions bits. The permission (or | |
15989 | values you pass C<mkdir> | |
18970 | "mode") values you pass L<C<mkdir>|/mkdir FILENAME,MASK> or | |
15990 | ||
18971 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> are modified by your | |
15991 | ||
18972 | umask, so even if you tell | |
15992 | pe | |
18973 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> to create a file with | |
15993 | ||
18974 | permissions C<0777>, if your umask is C<0022>, then the file will | |
15994 | ||
18975 | actually be created with permissions C<0755>. If your | |
15995 | C< | |
18976 | L<C<umask>|/umask EXPR> were C<0027> (group can't write; others can't | |
18977 | read, write, or execute), then passing | |
18978 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> C<0666> would create a | |
18979 | file with mode C<0640> (because C<0666 &~ 027> is C<0640>). | |
15996 | 18980 | |
15997 | 18981 | =end original |
15998 | 18982 | |
15999 | 18983 | Unix パーミッション C<rwxr-x---> は 3 ビットの三つの組、 |
16000 | 18984 | または 3 桁の 8 進数として表現されます: |
16001 | 18985 | C<0750> (先頭の 0 は 8 進数を意味し、実際の値ではありません)。 |
16002 | C<umask> の値は無効にするパーミッションビットのこのような | |
18986 | L<C<umask>|/umask EXPR> の値は無効にするパーミッションビットのこのような | |
16003 | ||
18987 | 数値表現です。 | |
16004 | ||
18988 | L<C<mkdir>|/mkdir FILENAME,MASK> や | |
18989 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> で渡されたパーミッション | |
18990 | (または「モード」)の値は umask で修正され、たとえ | |
18991 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> で C<0777> のパーミッションで | |
16005 | 18992 | ファイルを作るように指定しても、umask が C<0022> なら、 |
16006 | 18993 | 結果としてファイルは C<0755> のパーミッションで作成されます。 |
16007 | C<umask> が C<0027> (グループは書き込めない; その他は読み | |
18994 | L<C<umask>|/umask EXPR> が C<0027> (グループは書き込めない; その他は読み込み、 | |
16008 | 実行できない) のとき | |
18995 | 書き込み、実行できない) のとき | |
18996 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> に C<0666> を渡すと、 | |
16009 | 18997 | ファイルはモード C<0640> (なぜなら C<0666 &~ 027> は C<0640>)で作成されます。 |
16010 | 18998 | |
16011 | 18999 | =begin original |
16012 | 19000 | |
16013 | 19001 | Here's some advice: supply a creation mode of C<0666> for regular |
16014 | files (in C<sysopen>) and one of | |
19002 | files (in L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>) and one of | |
16015 | C< | |
19003 | C<0777> for directories (in L<C<mkdir>|/mkdir FILENAME,MASK>) and | |
19004 | executable files. This gives users the freedom of | |
16016 | 19005 | choice: if they want protected files, they might choose process umasks |
16017 | 19006 | of C<022>, C<027>, or even the particularly antisocial mask of C<077>. |
16018 | 19007 | Programs should rarely if ever make policy decisions better left to |
16019 | 19008 | the user. The exception to this is when writing files that should be |
16020 | kept private: mail files, web browser cookies, | |
19009 | kept private: mail files, web browser cookies, F<.rhosts> files, and | |
16021 | 19010 | so on. |
16022 | 19011 | |
16023 | 19012 | =end original |
16024 | 19013 | |
16025 | 以下は助言です: 作成モードとして、 | |
19014 | 以下は助言です: 作成モードとして、 | |
16026 | C< | |
19015 | (L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> による)通常ファイルでは | |
19016 | C<0666> を、(L<C<mkdir>|/mkdir FILENAME,MASK> による)ディレクトリでは | |
19017 | C<0777> を指定しましょう。 | |
16027 | 19018 | これにより、ユーザーに選択の自由を与えます: もしファイルを守りたいなら、 |
16028 | 19019 | プロセスの umask として C<022>, C<027>, あるいは特に非社交的な |
16029 | 19020 | C<077> を選択できます。 |
16030 | 19021 | プログラムがユーザーより適切なポリシー選択ができることは稀です。 |
16031 | 19022 | 例外は、プライベートに保つべきファイル(メール、ウェブブラウザのクッキー、 |
16032 | ||
19023 | F<.rhosts> ファイルなど)を書く場合です。 | |
16033 | 19024 | |
16034 | 19025 | =begin original |
16035 | 19026 | |
16036 | If umask(2) is not implemented on your system and you are trying to | |
19027 | If L<umask(2)> is not implemented on your system and you are trying to | |
16037 | restrict access for I<yourself> (i.e., C<< (EXPR & 0700) > 0 >>), | |
19028 | restrict access for I<yourself> (i.e., C<< (EXPR & 0700) > 0 >>), | |
16038 | raises an exception. If umask(2) is not implemented and you are | |
19029 | raises an exception. If L<umask(2)> is not implemented and you are | |
16039 | not trying to restrict access for yourself, returns | |
19030 | not trying to restrict access for yourself, returns | |
19031 | L<C<undef>|/undef EXPR>. | |
16040 | 19032 | |
16041 | 19033 | =end original |
16042 | 19034 | |
16043 | umask(2) が実装されていないシステムで、I<自分自身> へのアクセスを | |
19035 | L<umask(2)> が実装されていないシステムで、I<自分自身> へのアクセスを | |
16044 | 19036 | 制限しようとした(つまり C<< (EXPR & 0700) > 0 >>)場合、例外が発生します。 |
16045 | umask(2) が実装されていないシステムで、自分自身へのアクセスは | |
19037 | L<umask(2)> が実装されていないシステムで、自分自身へのアクセスは | |
16046 | 制限しようとしなかった場合、C<undef> を返します。 | |
19038 | 制限しようとしなかった場合、L<C<undef>|/undef EXPR> を返します。 | |
16047 | 19039 | |
16048 | 19040 | =begin original |
16049 | 19041 | |
16050 | 19042 | Remember that a umask is a number, usually given in octal; it is I<not> a |
16051 | string of octal digits. See also L</oct>, if all you have | |
19043 | string of octal digits. See also L<C<oct>|/oct EXPR>, if all you have | |
19044 | is a string. | |
16052 | 19045 | |
16053 | 19046 | =end original |
16054 | 19047 | |
16055 | umask は通常 8 進数で与えられる数値であることを忘れないでください | |
19048 | umask は通常 8 進数で与えられる数値であることを忘れないでください; 8 進数の | |
16056 | ||
19049 | 文字列 I<ではありません>。 | |
16057 | 文字列しかない場合、 L</oct> も参照して | |
19050 | 文字列しかない場合、 L<C<oct>|/oct EXPR> も参照してください。 | |
16058 | 19051 | |
19052 | =begin original | |
19053 | ||
19054 | Portability issues: L<perlport/umask>. | |
19055 | ||
19056 | =end original | |
19057 | ||
19058 | 移植性の問題: L<perlport/umask>。 | |
19059 | ||
16059 | 19060 | =item undef EXPR |
16060 | 19061 | X<undef> X<undefine> |
16061 | 19062 | |
16062 | 19063 | =item undef |
16063 | 19064 | |
19065 | =for Pod::Functions remove a variable or function definition | |
19066 | ||
16064 | 19067 | =begin original |
16065 | 19068 | |
16066 | 19069 | Undefines the value of EXPR, which must be an lvalue. Use only on a |
16067 | 19070 | scalar value, an array (using C<@>), a hash (using C<%>), a subroutine |
16068 | 19071 | (using C<&>), or a typeglob (using C<*>). Saying C<undef $hash{$key}> |
16069 | 19072 | will probably not do what you expect on most predefined variables or |
16070 | DBM list values, so don't do that; see L<delete> | |
19073 | DBM list values, so don't do that; see L<C<delete>|/delete EXPR>. | |
16071 | undefined value. | |
19074 | Always returns the undefined value. | |
19075 | You can omit the EXPR, in which case nothing is | |
16072 | 19076 | undefined, but you still get an undefined value that you could, for |
16073 | 19077 | instance, return from a subroutine, assign to a variable, or pass as a |
16074 | 19078 | parameter. Examples: |
16075 | 19079 | |
16076 | 19080 | =end original |
16077 | 19081 | |
16078 | 19082 | 左辺値である EXPR の値を未定義にします。 |
16079 | スカラ値、(C<@> を使った)配列、(C<%> を使った)ハッシュ、(C<&> を使った) | |
19083 | スカラ値、(C<@> を使った)配列、(C<%> を使った)ハッシュ、(C<&> を使った) | |
16080 | 19084 | サブルーチン、(C<*> を使った)型グロブだけに使用します。 |
16081 | 19085 | 特殊変数や DBM リスト値に C<undef $hash{$key}> などとしても |
16082 | 19086 | おそらく期待通りの結果にはなりませんから、しないでください; |
16083 | L</delete> を参照してください。 | |
19087 | L<C<delete>|/delete EXPR> を参照してください。 | |
16084 | 19088 | 常に未定義値を返します。 |
16085 | 19089 | EXPR は省略することができ、その場合には何も未定義にされませんが |
16086 | 19090 | 未定義値は返されますので、それをたとえば、 |
16087 | 19091 | サブルーチンの返り値、変数への割り当て、引数などとして使うことができます。 |
16088 | 19092 | 例: |
16089 | 19093 | |
16090 | 19094 | undef $foo; |
16091 | 19095 | undef $bar{'blurfl'}; # Compare to: delete $bar{'blurfl'}; |
16092 | 19096 | undef @ary; |
16093 | 19097 | undef %hash; |
16094 | 19098 | undef &mysub; |
16095 | 19099 | undef *xyz; # destroys $xyz, @xyz, %xyz, &xyz, etc. |
16096 | 19100 | return (wantarray ? (undef, $errmsg) : undef) if $they_blew_it; |
16097 | 19101 | select undef, undef, undef, 0.25; |
16098 | ($ | |
19102 | my ($x, $y, undef, $z) = foo(); # Ignore third value returned | |
16099 | 19103 | |
16100 | 19104 | =begin original |
16101 | 19105 | |
16102 | 19106 | Note that this is a unary operator, not a list operator. |
16103 | 19107 | |
16104 | 19108 | =end original |
16105 | 19109 | |
16106 | 19110 | これはリスト演算子ではなく、単項演算子であることに注意してください。 |
16107 | 19111 | |
16108 | 19112 | =item unlink LIST |
16109 | 19113 | X<unlink> X<delete> X<remove> X<rm> X<del> |
16110 | 19114 | |
16111 | 19115 | =item unlink |
16112 | 19116 | |
19117 | =for Pod::Functions remove one link to a file | |
19118 | ||
16113 | 19119 | =begin original |
16114 | 19120 | |
16115 | Deletes a list of files. On success, it returns the number of files | |
19121 | Deletes a list of files. On success, it returns the number of files | |
16116 | it successfully deleted. On failure, it returns false and sets | |
19122 | it successfully deleted. On failure, it returns false and sets | |
16117 | (errno): | |
19123 | L<C<$!>|perlvar/$!> (errno): | |
16118 | 19124 | |
16119 | 19125 | =end original |
16120 | 19126 | |
16121 | 19127 | LIST に含まれるファイルを削除します。 |
16122 | 19128 | 成功時は削除に成功したファイルの数を返します。 |
16123 | 失敗時は偽を返し | |
19129 | 失敗時は偽を返して L<C<$!>|perlvar/$!> (error) をセットします: | |
16124 | 19130 | |
16125 | 19131 | my $unlinked = unlink 'a', 'b', 'c'; |
16126 | 19132 | unlink @goners; |
16127 | 19133 | unlink glob "*.bak"; |
16128 | 19134 | |
16129 | 19135 | =begin original |
16130 | 19136 | |
16131 | On error, C<unlink> will not tell you which files it | |
19137 | On error, L<C<unlink>|/unlink LIST> will not tell you which files it | |
19138 | could not remove. | |
16132 | 19139 | If you want to know which files you could not remove, try them one |
16133 | 19140 | at a time: |
16134 | 19141 | |
16135 | 19142 | =end original |
16136 | 19143 | |
16137 | エラーの場合、C<unlink> はどのファイルが削除できなかったかを | |
19144 | エラーの場合、L<C<unlink>|/unlink LIST> はどのファイルが削除できなかったかを | |
19145 | 知らせません。 | |
16138 | 19146 | どのファイルが削除できなかったかを知りたい場合は、一つずつ削除してください: |
16139 | 19147 | |
16140 | 19148 | foreach my $file ( @goners ) { |
16141 | 19149 | unlink $file or warn "Could not unlink $file: $!"; |
16142 | 19150 | } |
16143 | 19151 | |
16144 | 19152 | =begin original |
16145 | 19153 | |
16146 | Note: C<unlink> will not attempt to delete directories | |
19154 | Note: L<C<unlink>|/unlink LIST> will not attempt to delete directories | |
16147 | ||
19155 | unless you are | |
19156 | superuser and the B<-U> flag is supplied to Perl. Even if these | |
16148 | 19157 | conditions are met, be warned that unlinking a directory can inflict |
16149 | damage on your filesystem. Finally, using C<unlink> | |
19158 | damage on your filesystem. Finally, using L<C<unlink>|/unlink LIST> on | |
16150 | not supported on many operating systems. Use | |
19159 | directories is not supported on many operating systems. Use | |
19160 | L<C<rmdir>|/rmdir FILENAME> instead. | |
16151 | 19161 | |
16152 | 19162 | =end original |
16153 | 19163 | |
16154 | 注: スーパーユーザ権限で、Perl に -U を付けて実行した場合でなければ、 | |
19164 | 注: スーパーユーザ権限で、Perl に B<-U> を付けて実行した場合でなければ、 | |
16155 | C<unlink> はディレクトリを削除しようとすることはありません。 | |
19165 | L<C<unlink>|/unlink LIST> はディレクトリを削除しようとすることはありません。 | |
16156 | 19166 | この条件にあう場合にも、ディレクトリの削除は、 |
16157 | 19167 | ファイルシステムに多大な損害を与える可能性があります。 |
16158 | 最後に、C<unlink> をディレクトリに使うのはほとんどの OS では | |
19168 | 最後に、L<C<unlink>|/unlink LIST> をディレクトリに使うのはほとんどの OS では | |
16159 | 19169 | 対応していません。 |
16160 | 代わりに C<rmdir> を使ってください。 | |
19170 | 代わりに L<C<rmdir>|/rmdir FILENAME> を使ってください。 | |
16161 | 19171 | |
16162 | 19172 | =begin original |
16163 | 19173 | |
16164 | If LIST is omitted, C<unlink> uses C<$_>. | |
19174 | If LIST is omitted, L<C<unlink>|/unlink LIST> uses L<C<$_>|perlvar/$_>. | |
16165 | 19175 | |
16166 | 19176 | =end original |
16167 | 19177 | |
16168 | LIST が省略されると、C<unlink> は C<$_> を | |
19178 | LIST が省略されると、L<C<unlink>|/unlink LIST> は L<C<$_>|perlvar/$_> を | |
19179 | 使います。 | |
16169 | 19180 | |
16170 | 19181 | =item unpack TEMPLATE,EXPR |
16171 | 19182 | X<unpack> |
16172 | 19183 | |
16173 | 19184 | =item unpack TEMPLATE |
16174 | 19185 | |
19186 | =for Pod::Functions convert binary structure into normal perl variables | |
19187 | ||
16175 | 19188 | =begin original |
16176 | 19189 | |
16177 | C<unpack> does the reverse of | |
19190 | L<C<unpack>|/unpack TEMPLATE,EXPR> does the reverse of | |
19191 | L<C<pack>|/pack TEMPLATE,LIST>: it takes a string | |
16178 | 19192 | and expands it out into a list of values. |
16179 | 19193 | (In scalar context, it returns merely the first value produced.) |
16180 | 19194 | |
16181 | 19195 | =end original |
16182 | 19196 | |
16183 | C<unpack> は C<pack> の逆を | |
19197 | L<C<unpack>|/unpack TEMPLATE,EXPR> は L<C<pack>|/pack TEMPLATE,LIST> の逆を | |
19198 | 行ないます: 構造体を表わす文字列をとり、 | |
16184 | 19199 | リスト値に展開し、その配列値を返します。 |
16185 | 19200 | (スカラコンテキストでは、単に最初の値を返します。) |
16186 | 19201 | |
16187 | 19202 | =begin original |
16188 | 19203 | |
16189 | If EXPR is omitted, unpacks the C<$_> string. | |
19204 | If EXPR is omitted, unpacks the L<C<$_>|perlvar/$_> string. | |
16190 | 19205 | See L<perlpacktut> for an introduction to this function. |
16191 | 19206 | |
16192 | 19207 | =end original |
16193 | 19208 | |
16194 | EXPR が省略されると、C<$_> の文字列を unpack します。 | |
19209 | EXPR が省略されると、L<C<$_>|perlvar/$_> の文字列を unpack します。 | |
16195 | この関数 | |
19210 | この関数の説明については L<perlpacktut> を参照してください。 | |
16196 | 19211 | |
16197 | 19212 | =begin original |
16198 | 19213 | |
16199 | 19214 | The string is broken into chunks described by the TEMPLATE. Each chunk |
16200 | 19215 | is converted separately to a value. Typically, either the string is a result |
16201 | of C<pack>, or the characters of the string | |
19216 | of L<C<pack>|/pack TEMPLATE,LIST>, or the characters of the string | |
16202 | kind. | |
19217 | represent a C structure of some kind. | |
16203 | 19218 | |
16204 | 19219 | =end original |
16205 | 19220 | |
16206 | 19221 | 文字列は TEMPLATE で示された固まりに分割されます。 |
16207 | 19222 | それぞれの固まりは別々に値に変換されます。 |
16208 | 典型的には、文字列は C<pack> の結果あるいはある種 | |
19223 | 典型的には、文字列は L<C<pack>|/pack TEMPLATE,LIST> の結果あるいはある種の | |
16209 | 文字列表現の文字列です。 | |
19224 | C の構造体の文字列表現の文字列です。 | |
16210 | 19225 | |
16211 | 19226 | =begin original |
16212 | 19227 | |
16213 | The TEMPLATE has the same format as in the | |
19228 | The TEMPLATE has the same format as in the | |
19229 | L<C<pack>|/pack TEMPLATE,LIST> function. | |
16214 | 19230 | Here's a subroutine that does substring: |
16215 | 19231 | |
16216 | 19232 | =end original |
16217 | 19233 | |
16218 | TEMPLATE は、C<pack> 関数と同じフォーマットを使います。 | |
19234 | TEMPLATE は、L<C<pack>|/pack TEMPLATE,LIST> 関数と同じフォーマットを使います。 | |
16219 | 19235 | 部分文字列を取り出すうサブルーチンの例を示します: |
16220 | 19236 | |
16221 | 19237 | sub substr { |
16222 | my($what,$where,$howmuch) = @_; | |
19238 | my ($what, $where, $howmuch) = @_; | |
16223 | 19239 | unpack("x$where a$howmuch", $what); |
16224 | 19240 | } |
16225 | 19241 | |
16226 | 19242 | =begin original |
16227 | 19243 | |
16228 | 19244 | and then there's |
16229 | 19245 | |
16230 | 19246 | =end original |
16231 | 19247 | |
16232 | 19248 | これもそうです。 |
16233 | 19249 | |
16234 | 19250 | sub ordinal { unpack("W",$_[0]); } # same as ord() |
16235 | 19251 | |
16236 | 19252 | =begin original |
16237 | 19253 | |
16238 | In addition to fields allowed in pack | |
19254 | In addition to fields allowed in L<C<pack>|/pack TEMPLATE,LIST>, you may | |
16239 | a %<number> to indicate that | |
19255 | prefix a field with a %<number> to indicate that | |
16240 | 19256 | you want a <number>-bit checksum of the items instead of the items |
16241 | themselves. Default is a 16-bit checksum. | |
19257 | themselves. Default is a 16-bit checksum. The checksum is calculated by | |
16242 | 19258 | summing numeric values of expanded values (for string fields the sum of |
16243 | 19259 | C<ord($char)> is taken; for bit fields the sum of zeroes and ones). |
16244 | 19260 | |
16245 | 19261 | =end original |
16246 | 19262 | |
16247 | pack | |
19263 | L<C<pack>|/pack TEMPLATE,LIST> で利用可能なフィールドの他に、 | |
16248 | 19264 | フィールドの前に %<数値> というものを付けて、 |
16249 | 19265 | 項目自身の代わりに、その項目の <数値>-ビットのチェックサムを |
16250 | 19266 | 計算させることができます。 |
16251 | 19267 | デフォルトは、16-ビットチェックサムです。 |
16252 | 19268 | チェックサムは展開された値の数値としての値の合計 |
16253 | 19269 | (文字列フィールドの場合は C<ord($char)> の合計; |
16254 | 19270 | ビットフィールドの場合は 0 と 1 の合計) が用いられます。 |
16255 | 19271 | |
16256 | 19272 | =begin original |
16257 | 19273 | |
16258 | 19274 | For example, the following |
16259 | 19275 | computes the same number as the System V sum program: |
16260 | 19276 | |
16261 | 19277 | =end original |
16262 | 19278 | |
16263 | 19279 | たとえば、以下のコードは |
16264 | 19280 | System V の sum プログラムと同じ値を計算します。 |
16265 | 19281 | |
16266 | $checksum = do { | |
19282 | my $checksum = do { | |
16267 | 19283 | local $/; # slurp! |
16268 | unpack("%32W*", | |
19284 | unpack("%32W*", readline) % 65535; | |
16269 | 19285 | }; |
16270 | 19286 | |
16271 | 19287 | =begin original |
16272 | 19288 | |
16273 | 19289 | The following efficiently counts the number of set bits in a bit vector: |
16274 | 19290 | |
16275 | 19291 | =end original |
16276 | 19292 | |
16277 | 19293 | 以下は、効率的にビットベクターの設定されているビットを |
16278 | 19294 | 数えるものです。 |
16279 | 19295 | |
16280 | $setbits = unpack("%32b*", $selectmask); | |
19296 | my $setbits = unpack("%32b*", $selectmask); | |
16281 | 19297 | |
16282 | 19298 | =begin original |
16283 | 19299 | |
16284 | 19300 | The C<p> and C<P> formats should be used with care. Since Perl |
16285 | has no way of checking whether the value passed to | |
19301 | has no way of checking whether the value passed to | |
19302 | L<C<unpack>|/unpack TEMPLATE,EXPR> | |
16286 | 19303 | corresponds to a valid memory location, passing a pointer value that's |
16287 | 19304 | not known to be valid is likely to have disastrous consequences. |
16288 | 19305 | |
16289 | 19306 | =end original |
16290 | 19307 | |
16291 | 19308 | C<p> と C<P> は注意深く使うべきです。 |
16292 | Perl は C<unpack | |
19309 | Perl は L<C<unpack>|/unpack TEMPLATE,EXPR> に渡された値が有効なメモリ位置を | |
16293 | 確認する方法がないので、有効かどうかわからない | |
19310 | 指しているかどうかを確認する方法がないので、有効かどうかわからない | |
16294 | 悲惨な結果を引き起こすかもしれません。 | |
19311 | ポインタ値を渡すと悲惨な結果を引き起こすかもしれません。 | |
16295 | 19312 | |
16296 | 19313 | =begin original |
16297 | 19314 | |
16298 | 19315 | If there are more pack codes or if the repeat count of a field or a group |
16299 | 19316 | is larger than what the remainder of the input string allows, the result |
16300 | 19317 | is not well defined: the repeat count may be decreased, or |
16301 | C<unpack | |
19318 | L<C<unpack>|/unpack TEMPLATE,EXPR> may produce empty strings or zeros, | |
19319 | or it may raise an exception. | |
16302 | 19320 | If the input string is longer than one described by the TEMPLATE, |
16303 | 19321 | the remainder of that input string is ignored. |
16304 | 19322 | |
16305 | 19323 | =end original |
16306 | 19324 | |
16307 | 19325 | 多くの pack コードがある場合や、フィールドやグループの繰り返し回数が |
16308 | 19326 | 入力文字列の残りより大きい場合、結果は未定義です: |
16309 | 繰り返し回数が減らされる場合もありますし、 | |
19327 | 繰り返し回数が減らされる場合もありますし、 | |
19328 | L<C<unpack>|/unpack TEMPLATE,EXPR> が空文字列や 0 を | |
16310 | 19329 | 返すこともありますし、例外が発生します。 |
16311 | 19330 | もし入力文字列が TEMPLATE で表現されているものより大きい場合、 |
16312 | 19331 | 入力文字列の残りは無視されます。 |
16313 | 19332 | |
16314 | 19333 | =begin original |
16315 | 19334 | |
16316 | See L</pack> for more examples and notes. | |
19335 | See L<C<pack>|/pack TEMPLATE,LIST> for more examples and notes. | |
16317 | 19336 | |
16318 | 19337 | =end original |
16319 | 19338 | |
16320 | さらなる例と注意に関しては L</pack> を参照してください。 | |
19339 | さらなる例と注意に関しては L<C<pack>|/pack TEMPLATE,LIST> を参照してください。 | |
16321 | 19340 | |
16322 | =item untie VARIABLE | |
16323 | X<untie> | |
16324 | ||
16325 | =begin original | |
16326 | ||
16327 | Breaks the binding between a variable and a package. (See C<tie>.) | |
16328 | Has no effect if the variable is not tied. | |
16329 | ||
16330 | =end original | |
16331 | ||
16332 | 変数とパッケージの間の結合を解きます。 | |
16333 | (L<tie> を参照してください。) | |
16334 | 結合されていない場合は何も起きません。 | |
16335 | ||
16336 | 19341 | =item unshift ARRAY,LIST |
16337 | 19342 | X<unshift> |
16338 | 19343 | |
16339 | = | |
19344 | =for Pod::Functions prepend more elements to the beginning of a list | |
16340 | 19345 | |
16341 | 19346 | =begin original |
16342 | 19347 | |
16343 | Does the opposite of a C<shift>. Or the opposite of a | |
19348 | Does the opposite of a L<C<shift>|/shift ARRAY>. Or the opposite of a | |
19349 | L<C<push>|/push ARRAY,LIST>, | |
16344 | 19350 | depending on how you look at it. Prepends list to the front of the |
16345 | 19351 | array and returns the new number of elements in the array. |
16346 | 19352 | |
16347 | 19353 | =end original |
16348 | 19354 | |
16349 | C<shift> の逆操作を行ないます。 | |
19355 | L<C<shift>|/shift ARRAY> の逆操作を行ないます。 | |
16350 | 見方を変えれば、C<push> の逆操作とも考えられます。 | |
19356 | 見方を変えれば、L<C<push>|/push ARRAY,LIST> の逆操作とも考えられます。 | |
16351 | 19357 | LIST を ARRAY の先頭に入れて、新しくできた配列の要素の数を返します。 |
16352 | 19358 | |
16353 | 19359 | unshift(@ARGV, '-e') unless $ARGV[0] =~ /^-/; |
16354 | 19360 | |
16355 | 19361 | =begin original |
16356 | 19362 | |
16357 | 19363 | Note the LIST is prepended whole, not one element at a time, so the |
16358 | prepended elements stay in the same order. Use | |
19364 | prepended elements stay in the same order. Use | |
16359 | reverse. | |
19365 | L<C<reverse>|/reverse LIST> to do the reverse. | |
16360 | 19366 | |
16361 | 19367 | =end original |
16362 | 19368 | |
16363 | 19369 | LIST は、はらばらにではなく、一度に登録されるので、順番はそのままです。 |
16364 | 逆順に登録するには、C<reverse> を使ってください。 | |
19370 | 逆順に登録するには、L<C<reverse>|/reverse LIST> を使ってください。 | |
16365 | 19371 | |
16366 | 19372 | =begin original |
16367 | 19373 | |
16368 | Starting with Perl 5.14, | |
19374 | Starting with Perl 5.14, an experimental feature allowed | |
16369 | ||
19375 | L<C<unshift>|/unshift ARRAY,LIST> to take | |
16370 | a | |
19376 | a scalar expression. This experiment has been deemed unsuccessful, and was | |
16371 | ||
19377 | removed as of Perl 5.24. | |
16372 | 19378 | |
16373 | 19379 | =end original |
16374 | 19380 | |
16375 | Perl 5.14 から、C<unshift> | |
19381 | Perl 5.14 から、L<C<unshift>|/unshift ARRAY,LIST> がスカラ式を | |
16376 | こ | |
19382 | 取ることが出来るという実験的機能がありました。 | |
16377 | ||
19383 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 | |
16378 | C<unshift> のこの動作は高度に実験的であると考えられています。 | |
16379 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 | |
16380 | 19384 | |
19385 | =item untie VARIABLE | |
19386 | X<untie> | |
19387 | ||
19388 | =for Pod::Functions break a tie binding to a variable | |
19389 | ||
19390 | =begin original | |
19391 | ||
19392 | Breaks the binding between a variable and a package. | |
19393 | (See L<tie|/tie VARIABLE,CLASSNAME,LIST>.) | |
19394 | Has no effect if the variable is not tied. | |
19395 | ||
19396 | =end original | |
19397 | ||
19398 | 変数とパッケージの間の結合を解きます。 | |
19399 | (L<tie|/tie VARIABLE,CLASSNAME,LIST> を参照してください。) | |
19400 | 結合されていない場合は何も起きません。 | |
19401 | ||
16381 | 19402 | =item use Module VERSION LIST |
16382 | 19403 | X<use> X<module> X<import> |
16383 | 19404 | |
16384 | 19405 | =item use Module VERSION |
16385 | 19406 | |
16386 | 19407 | =item use Module LIST |
16387 | 19408 | |
16388 | 19409 | =item use Module |
16389 | 19410 | |
16390 | 19411 | =item use VERSION |
16391 | 19412 | |
19413 | =for Pod::Functions load in a module at compile time and import its namespace | |
19414 | ||
16392 | 19415 | =begin original |
16393 | 19416 | |
16394 | 19417 | Imports some semantics into the current package from the named module, |
16395 | 19418 | generally by aliasing certain subroutine or variable names into your |
16396 | 19419 | package. It is exactly equivalent to |
16397 | 19420 | |
16398 | 19421 | =end original |
16399 | 19422 | |
16400 | 指定したモジュールから、現在のパッケージにさまざまな内容を | |
19423 | 指定したモジュールから、現在のパッケージにさまざまな内容をインポートします; | |
16401 | インポートします。 | |
16402 | 19424 | 多くは、パッケージのサブルーチン名や、変数名に別名を付けることで、 |
16403 | 実現されています。 | |
19425 | 実現されています。 | |
16404 | 以下は等価ですが: | |
19426 | これは、以下は等価ですが: | |
16405 | 19427 | |
16406 | 19428 | BEGIN { require Module; Module->import( LIST ); } |
16407 | 19429 | |
16408 | 19430 | =begin original |
16409 | 19431 | |
16410 | 19432 | except that Module I<must> be a bareword. |
16411 | The importation can be made conditional | |
19433 | The importation can be made conditional by using the L<if> module. | |
16412 | 19434 | |
16413 | 19435 | =end original |
16414 | 19436 | |
16415 | 19437 | Module が I<裸の単語でなければならない> ことを除けば、です。 |
16416 | インポートは条件付きで行うことができます | |
19438 | インポートは、L<if> を使って条件付きで行うことができます。 | |
16417 | 19439 | |
16418 | 19440 | =begin original |
16419 | 19441 | |
16420 | 19442 | In the peculiar C<use VERSION> form, VERSION may be either a positive |
16421 | decimal fraction such as 5.006, which will be compared to | |
19443 | decimal fraction such as 5.006, which will be compared to | |
16422 | of the form v5.6.1, which will be | |
19444 | L<C<$]>|perlvar/$]>, or a v-string of the form v5.6.1, which will be | |
19445 | compared to L<C<$^V>|perlvar/$^V> (aka $PERL_VERSION). An | |
16423 | 19446 | exception is raised if VERSION is greater than the version of the |
16424 | 19447 | current Perl interpreter; Perl will not attempt to parse the rest of the |
16425 | file. Compare with L</require>, which can do a | |
19448 | file. Compare with L<C<require>|/require VERSION>, which can do a | |
19449 | similar check at run time. | |
16426 | 19450 | Symmetrically, C<no VERSION> allows you to specify that you want a version |
16427 | 19451 | of Perl older than the specified one. |
16428 | 19452 | |
16429 | 19453 | =end original |
16430 | 19454 | |
16431 | 特に C<use VERSION> の形式では、 | |
19455 | 特に C<use VERSION> の形式では、VERSION は 5.006 のような正の 10 進小数 | |
16432 | ||
19456 | (L<C<$]>|perlvar/$]> と比較されます)か、v5.6.1 の形 | |
16433 | (C<$^V> (またの名を $PERL_VERSION) と比較されます) の | |
19457 | (L<C<$^V>|perlvar/$^V> (またの名を $PERL_VERSION) と比較されます) の | |
19458 | v-文字列で指定します。 | |
16434 | 19459 | VERSION が Perl の現在のバージョンより大きいと、例外が発生します; |
16435 | 19460 | Perl はファイルの残りを読み込みません。 |
16436 | L</require> と似ていますが、これは実行時にチェックされます。 | |
19461 | L<C<require>|/require VERSION> と似ていますが、これは実行時にチェックされます。 | |
16437 | 19462 | 対称的に、C<no VERSION> は指定されたバージョンより古いバージョンの Perl で |
16438 | 19463 | 動作させたいことを意味します。 |
16439 | 19464 | |
16440 | 19465 | =begin original |
16441 | 19466 | |
16442 | 19467 | Specifying VERSION as a literal of the form v5.6.1 should generally be |
16443 | 19468 | avoided, because it leads to misleading error messages under earlier |
16444 | 19469 | versions of Perl (that is, prior to 5.6.0) that do not support this |
16445 | 19470 | syntax. The equivalent numeric version should be used instead. |
16446 | 19471 | |
16447 | 19472 | =end original |
16448 | 19473 | |
16449 | 19474 | VERSION に v5.6.1 の形のリテラルを指定することは一般的には避けるべきです; |
16450 | 19475 | なぜなら、この文法に対応していない Perl の初期のバージョン |
16451 | 19476 | (つまり、 5.6.0 以前) では誤解させるようなエラーメッセージが出るからです。 |
16452 | 19477 | 代わりに等価な数値表現を使うべきです。 |
16453 | 19478 | |
16454 | 19479 | use v5.6.1; # compile time version check |
16455 | 19480 | use 5.6.1; # ditto |
16456 | 19481 | use 5.006_001; # ditto; preferred for backwards compatibility |
16457 | 19482 | |
16458 | 19483 | =begin original |
16459 | 19484 | |
16460 | 19485 | This is often useful if you need to check the current Perl version before |
16461 | C<use>ing library modules that won't work | |
19486 | L<C<use>|/use Module VERSION LIST>ing library modules that won't work | |
19487 | with older versions of Perl. | |
16462 | 19488 | (We try not to do this more than we have to.) |
16463 | 19489 | |
16464 | 19490 | =end original |
16465 | 19491 | |
16466 | これは古いバージョンの Perl で動かなくなったライブラリ | |
19492 | これは古いバージョンの Perl で動かなくなったライブラリモジュールを | |
16467 | ||
19493 | L<C<use>|/use Module VERSION LIST> する前に、現在の Perl のバージョンを | |
16468 | 努力していますが)を C<use> する前に、現在の Perl のバージョンを | |
16469 | 19494 | 調べたい場合に有用です。 |
19495 | (我々は必要な場合以外にそのようなことがないように努力していますが。) | |
16470 | 19496 | |
16471 | 19497 | =begin original |
16472 | 19498 | |
16473 | ||
19499 | C<use VERSION> also lexically enables all features available in the requested | |
16474 | ||
19500 | version as defined by the L<feature> pragma, disabling any features | |
16475 | ||
19501 | not in the requested version's feature bundle. See L<feature>. | |
16476 | 19502 | Similarly, if the specified Perl version is greater than or equal to |
16477 | 5.1 | |
19503 | 5.12.0, strictures are enabled lexically as | |
16478 | th | |
19504 | with L<C<use strict>|strict>. Any explicit use of | |
19505 | C<use strict> or C<no strict> overrides C<use VERSION>, even if it comes | |
19506 | before it. Later use of C<use VERSION> | |
19507 | will override all behavior of a previous | |
19508 | C<use VERSION>, possibly removing the C<strict> and C<feature> added by | |
19509 | C<use VERSION>. C<use VERSION> does not | |
19510 | load the F<feature.pm> or F<strict.pm> | |
19511 | files. | |
16479 | 19512 | |
16480 | 19513 | =end original |
16481 | 19514 | |
16482 | ||
19515 | C<use VERSION> は、L<feature> プラグマで定義されたように、指定された | |
16483 | ||
19516 | バージョンで利用可能な全ての機能を有効にし、指定されたバージョンの機能の | |
16484 | ||
19517 | 束にない機能をレキシカルに無効にします。 | |
16485 | 19518 | L<feature> を参照してください。 |
16486 | 同様に、指定された Perl のバージョンが 5.1 | |
19519 | 同様に、指定された Perl のバージョンが 5.12.0 以上の場合、 | |
16487 | 制限は C<use strict> と同様にレキシカルに有効になります | |
19520 | 制限は L<C<use strict>|strict> と同様にレキシカルに有効になります。 | |
16488 | ||
19521 | 明示的に C<use strict> や C<no strict> を使うと、例え先に | |
19522 | 指定されていたとしても、C<use VERSION> を上書きします。 | |
19523 | 後から使った C<use VERSION> は先の | |
19524 | C<use VERSION> の全ての振る舞いを上書きするので、 | |
19525 | C<use VERSION> によって追加された C<strict> と C<feature> を | |
19526 | 削除することがあります。 | |
19527 | C<use VERSION> は F<feature.pm> と F<strict.pm> ファイルは読み込みません。 | |
16489 | 19528 | |
16490 | 19529 | =begin original |
16491 | 19530 | |
16492 | The C<BEGIN> forces the C<require> | |
19531 | The C<BEGIN> forces the L<C<require>|/require VERSION> and | |
16493 | C< | |
19532 | L<C<import>|/import LIST> to happen at compile time. The | |
16494 | ||
19533 | L<C<require>|/require VERSION> makes sure the module is loaded into | |
19534 | memory if it hasn't been yet. The L<C<import>|/import LIST> is not a | |
19535 | builtin; it's just an ordinary static method | |
16495 | 19536 | call into the C<Module> package to tell the module to import the list of |
16496 | 19537 | features back into the current package. The module can implement its |
16497 | C<import> method any way it likes, though most modules | |
19538 | L<C<import>|/import LIST> method any way it likes, though most modules | |
16498 | derive their C<import> method via | |
19539 | just choose to derive their L<C<import>|/import LIST> method via | |
16499 | i | |
19540 | inheritance from the C<Exporter> class that is defined in the | |
16500 | ||
19541 | L<C<Exporter>|Exporter> module. See L<Exporter>. If no | |
16501 | method | |
19542 | L<C<import>|/import LIST> method can be found, then the call is skipped, | |
19543 | even if there is an AUTOLOAD method. | |
16502 | 19544 | |
16503 | 19545 | =end original |
16504 | 19546 | |
16505 | C<BEGIN> によって、C<require> | |
19547 | C<BEGIN> によって、L<C<require>|/require VERSION> や | |
19548 | L<C<import>|/import LIST> は、コンパイル時に | |
16506 | 19549 | 実行されることになります。 |
16507 | C<require> は、モジュールがまだメモリに | |
19550 | L<C<require>|/require VERSION> は、モジュールがまだメモリに | |
16508 | ||
19551 | ロードされていなければ、ロードします。 | |
16509 | ||
19552 | L<C<import>|/import LIST> は、組込みの関数ではありません; さまざまな機能を | |
16510 | ||
19553 | 現在のパッケージにインポートするように C<Module> パッケージに伝えるために | |
16511 | ||
19554 | 呼ばれる、通常の静的メソッドです。 | |
16512 | ||
19555 | モジュール側では、L<C<import>|/import LIST> メソッドをどのようにでも | |
16513 | ||
19556 | 実装することができますが、多くのモジュールでは、 | |
16514 | ||
19557 | L<C<Exporter>|Exporter> モジュールで定義された、 | |
19558 | C<Exporter> クラスからの継承によって、L<C<import>|/import LIST> メソッドを | |
19559 | 行なうようにしています。 | |
16515 | 19560 | L<Exporter>モジュールを参照してください。 |
16516 | C<import>メソッドが見つからなかった場合、AUTOLOAD メソッドが | |
19561 | L<C<import>|/import LIST>メソッドが見つからなかった場合、AUTOLOAD メソッドが | |
16517 | 呼び出しはスキップされます。 | |
19562 | あったとしても呼び出しはスキップされます。 | |
16518 | 19563 | |
16519 | 19564 | =begin original |
16520 | 19565 | |
16521 | If you do not want to call the package's C<import> | |
19566 | If you do not want to call the package's L<C<import>|/import LIST> | |
19567 | method (for instance, | |
16522 | 19568 | to stop your namespace from being altered), explicitly supply the empty list: |
16523 | 19569 | |
16524 | 19570 | =end original |
16525 | 19571 | |
16526 | パッケージの C<import> メソッドを呼び出したくない場合(例えば、 | |
19572 | パッケージの L<C<import>|/import LIST> メソッドを呼び出したくない場合(例えば、 | |
16527 | 変更したくない場合など)は、明示的に空リストを指定してください: | |
19573 | 名前空間を変更したくない場合など)は、明示的に空リストを指定してください: | |
16528 | 19574 | |
16529 | 19575 | use Module (); |
16530 | 19576 | |
16531 | 19577 | =begin original |
16532 | 19578 | |
16533 | 19579 | That is exactly equivalent to |
16534 | 19580 | |
16535 | 19581 | =end original |
16536 | 19582 | |
16537 | 19583 | これは以下と完全に等価です: |
16538 | 19584 | |
16539 | 19585 | BEGIN { require Module } |
16540 | 19586 | |
16541 | 19587 | =begin original |
16542 | 19588 | |
16543 | 19589 | If the VERSION argument is present between Module and LIST, then the |
16544 | C<use> will call the VERSION method i | |
19590 | L<C<use>|/use Module VERSION LIST> will call the C<VERSION> method in | |
16545 | version as an argument | |
19591 | class Module with the given version as an argument: | |
16546 | the UNIVERSAL class, croaks if the given version is larger than the | |
16547 | value of the variable C<$Module::VERSION>. | |
16548 | 19592 | |
16549 | 19593 | =end original |
16550 | 19594 | |
16551 | Module と LIST の間に VERSION 引数がある場合、 | |
19595 | Module と LIST の間に VERSION 引数がある場合、 | |
16552 | VERSION | |
19596 | L<C<use>|/use Module VERSION LIST> は Module クラスの | |
16553 | ||
19597 | C<VERSION> メソッドを、与えられたバージョンを引数として呼び出します: | |
19598 | ||
19599 | use Module 12.34; | |
19600 | ||
19601 | =begin original | |
19602 | ||
19603 | is equivalent to: | |
19604 | ||
19605 | =end original | |
19606 | ||
19607 | は以下と等価です: | |
19608 | ||
19609 | BEGIN { require Module; Module->VERSION(12.34) } | |
19610 | ||
19611 | =begin original | |
19612 | ||
19613 | The L<default C<VERSION> method|UNIVERSAL/C<VERSION ( [ REQUIRE ] )>>, | |
19614 | inherited from the L<C<UNIVERSAL>|UNIVERSAL> class, croaks if the given | |
19615 | version is larger than the value of the variable C<$Module::VERSION>. | |
19616 | ||
19617 | =end original | |
19618 | ||
19619 | デフォルトの | |
19620 | L<default C<VERSION> メソッド|UNIVERSAL/C<VERSION ( [ REQUIRE ] )>> は、 | |
19621 | L<C<UNIVERSAL>|UNIVERSAL> クラスから継承したもので、 | |
16554 | 19622 | 与えられたバージョンが 変数 C<$Module::VERSION> の値より大きい場合に |
16555 | 19623 | 警告を出します。 |
16556 | 19624 | |
16557 | 19625 | =begin original |
16558 | 19626 | |
16559 | Again, there is a distinction between omitting LIST (C<import> | |
19627 | Again, there is a distinction between omitting LIST (L<C<import>|/import | |
16560 | with no arguments) and an explicit empty LIST C<()> | |
19628 | LIST> called with no arguments) and an explicit empty LIST C<()> | |
16561 | called). Note that there is no comma | |
19629 | (L<C<import>|/import LIST> not called). Note that there is no comma | |
19630 | after VERSION! | |
16562 | 19631 | |
16563 | 19632 | =end original |
16564 | 19633 | |
16565 | 繰り返すと、LIST を省略する(C<import> が引数なしで | |
19634 | 繰り返すと、LIST を省略する(L<C<import>|/import LIST> が引数なしで | |
16566 | 明示的に空の LIST C<()> を指定する | |
19635 | 呼び出される)ことと明示的に空の LIST C<()> を指定する | |
16567 | 違います。 | |
19636 | (L<C<import>|/import LIST> は呼び出されない)ことは違います。 | |
16568 | 19637 | VERSION の後ろにカンマが不要なことに注意してください! |
16569 | 19638 | |
16570 | 19639 | =begin original |
16571 | 19640 | |
16572 | 19641 | Because this is a wide-open interface, pragmas (compiler directives) |
16573 | are also implemented this way. | |
19642 | are also implemented this way. Some of the currently implemented | |
19643 | pragmas are: | |
16574 | 19644 | |
16575 | 19645 | =end original |
16576 | 19646 | |
16577 | 19647 | これは、広く公開されているインタフェースですので、 |
16578 | 19648 | プラグマ (コンパイラディレクティブ) も、この方法で実装されています。 |
16579 | 現在実装されているプラグマには、以下のものがあります: | |
19649 | 現在実装されているプラグマには、以下のようなものがあります: | |
16580 | 19650 | |
16581 | 19651 | use constant; |
16582 | 19652 | use diagnostics; |
16583 | 19653 | use integer; |
16584 | 19654 | use sigtrap qw(SEGV BUS); |
16585 | 19655 | use strict qw(subs vars refs); |
16586 | 19656 | use subs qw(afunc blurfl); |
16587 | 19657 | use warnings qw(all); |
16588 | 19658 | use sort qw(stable _quicksort _mergesort); |
16589 | 19659 | |
16590 | 19660 | =begin original |
16591 | 19661 | |
16592 | 19662 | Some of these pseudo-modules import semantics into the current |
16593 | block scope (like C<strict> or C<integer>, unlike | |
19663 | block scope (like L<C<strict>|strict> or L<C<integer>|integer>, unlike | |
16594 | which import symbols into the current package (which | |
19664 | ordinary modules, which import symbols into the current package (which | |
16595 | through the end of the file). | |
19665 | are effective through the end of the file). | |
16596 | 19666 | |
16597 | 19667 | =end original |
16598 | 19668 | |
16599 | 19669 | 通常のモジュールが、現在のパッケージにシンボルをインポートする |
16600 | (これは、ファイルの終わりまで有効です) のに対して、 | |
19670 | (これは、ファイルの終わりまで有効です) のに対して、これらの擬似モジュールの | |
16601 | ||
19671 | 一部(L<C<strict>|strict> や L<C<integer>|integer> など)は、現在の | |
16602 | ||
19672 | ブロックスコープにインポートを行ないます。 | |
16603 | 19673 | |
16604 | 19674 | =begin original |
16605 | 19675 | |
16606 | Because C<use> takes effect at compile time, | |
19676 | Because L<C<use>|/use Module VERSION LIST> takes effect at compile time, | |
16607 | ordinary flow control of the code being compiled. | |
19677 | it doesn't respect the ordinary flow control of the code being compiled. | |
16608 | a C<use> | |
19678 | In particular, putting a L<C<use>|/use Module VERSION LIST> inside the | |
16609 | f | |
19679 | false branch of a conditional doesn't prevent it | |
19680 | from being processed. If a module or pragma only needs to be loaded | |
16610 | 19681 | conditionally, this can be done using the L<if> pragma: |
16611 | 19682 | |
16612 | 19683 | =end original |
16613 | 19684 | |
16614 | C<use> はコンパイル時に有効なので、コードが | |
19685 | L<C<use>|/use Module VERSION LIST> はコンパイル時に有効なので、コードが | |
16615 | 流れ制御には従いません。 | |
19686 | コンパイルされる際の通常の流れ制御には従いません。 | |
16616 | 特に、条件文のうち成立しない側の中に C<use> を | |
19687 | 特に、条件文のうち成立しない側の中に L<C<use>|/use Module VERSION LIST> を | |
16617 | 処理を妨げられません。 | |
19688 | 書いても、処理を妨げられません。 | |
16618 | 19689 | モジュールやプラグマを条件付きでのみ読み込みたい場合、 |
16619 | 19690 | L<if> プラグマを使って実現できます: |
16620 | 19691 | |
16621 | 19692 | use if $] < 5.008, "utf8"; |
16622 | 19693 | use if WANT_WARNINGS, warnings => qw(all); |
16623 | 19694 | |
16624 | 19695 | =begin original |
16625 | 19696 | |
16626 | There's a corresponding C<no> declaration | |
19697 | There's a corresponding L<C<no>|/no MODULE VERSION LIST> declaration | |
16627 | ||
19698 | that unimports meanings imported by L<C<use>|/use Module VERSION LIST>, | |
16628 | ||
19699 | i.e., it calls C<< Module->unimport(LIST) >> instead of | |
19700 | L<C<import>|/import LIST>. It behaves just as L<C<import>|/import LIST> | |
19701 | does with VERSION, an omitted or empty LIST, | |
16629 | 19702 | or no unimport method being found. |
16630 | 19703 | |
16631 | 19704 | =end original |
16632 | 19705 | |
16633 | これに対して、C<no> 宣言という | |
19706 | これに対して、L<C<no>|/no MODULE VERSION LIST> 宣言という、 | |
16634 | インポートされ | |
19707 | L<C<use>|/use Module VERSION LIST> によってインポートされたものを、 | |
16635 | ||
19708 | インポートされていないことにするものがあります; つまり、 | |
19709 | L<C<import>|/import LIST> の代わりに | |
19710 | C<< Module->unimport(LIST) >> を呼び出します。 | |
16636 | 19711 | これは VERSION、省略された LIST、空の LIST、unimport メソッドが見つからない |
16637 | 場合などの観点では、C<import> と同様に振る舞います。 | |
19712 | 場合などの観点では、L<C<import>|/import LIST> と同様に振る舞います。 | |
16638 | 19713 | |
16639 | 19714 | no integer; |
16640 | 19715 | no strict 'refs'; |
16641 | 19716 | no warnings; |
16642 | 19717 | |
16643 | 19718 | =begin original |
16644 | 19719 | |
16645 | Care should be taken when using the C<no VERSION> form of C<no> | |
19720 | Care should be taken when using the C<no VERSION> form of L<C<no>|/no | |
19721 | MODULE VERSION LIST>. It is | |
16646 | 19722 | I<only> meant to be used to assert that the running Perl is of a earlier |
16647 | 19723 | version than its argument and I<not> to undo the feature-enabling side effects |
16648 | 19724 | of C<use VERSION>. |
16649 | 19725 | |
16650 | 19726 | =end original |
16651 | 19727 | |
16652 | C<no> の C<no VERSION> 形式を使うときには | |
19728 | L<C<no>|/no MODULE VERSION LIST> の C<no VERSION> 形式を使うときには | |
19729 | 注意を払うべきです。 | |
16653 | 19730 | これは引数で指定されたバージョンよりも前の Perl で実行されたときに |
16654 | 19731 | アサートされることを意味する I<だけ> で、C<use VERSION> によって |
16655 | 19732 | 有効にされた副作用をなかったことにするもの I<ではありません>。 |
16656 | 19733 | |
16657 | 19734 | =begin original |
16658 | 19735 | |
16659 | 19736 | See L<perlmodlib> for a list of standard modules and pragmas. See L<perlrun> |
16660 | for the C<-M> and C<-m> command-line options to Perl that give | |
19737 | for the C<-M> and C<-m> command-line options to Perl that give | |
16661 | functionality from the command-line. | |
19738 | L<C<use>|/use Module VERSION LIST> functionality from the command-line. | |
16662 | 19739 | |
16663 | 19740 | =end original |
16664 | 19741 | |
16665 | 19742 | 標準モジュールやプラグマの一覧は、L<perlmodlib> を参照してください。 |
16666 | コマンドラインから C<use> | |
19743 | コマンドラインから L<C<use>|/use Module VERSION LIST> 機能を | |
16667 | ||
19744 | 指定するための C<-M> と C<-m> の | |
19745 | コマンドラインオプションについては L<perlrun> を参照してください。 | |
16668 | 19746 | |
16669 | 19747 | =item utime LIST |
16670 | 19748 | X<utime> |
16671 | 19749 | |
19750 | =for Pod::Functions set a file's last access and modify times | |
19751 | ||
16672 | 19752 | =begin original |
16673 | 19753 | |
16674 | 19754 | Changes the access and modification times on each file of a list of |
16675 | 19755 | files. The first two elements of the list must be the NUMERIC access |
16676 | 19756 | and modification times, in that order. Returns the number of files |
16677 | 19757 | successfully changed. The inode change time of each file is set |
16678 | 19758 | to the current time. For example, this code has the same effect as the |
16679 | Unix touch(1) command when the files I<already exist> and belong to | |
19759 | Unix L<touch(1)> command when the files I<already exist> and belong to | |
16680 | 19760 | the user running the program: |
16681 | 19761 | |
16682 | 19762 | =end original |
16683 | 19763 | |
16684 | 19764 | ファイルのアクセス時刻と修正(modification) 時刻を変更します。 |
16685 | 19765 | LIST の最初の二つの要素に、数値で表わしたアクセス時刻と修正時刻を |
16686 | 19766 | 順に指定します。 |
16687 | 19767 | 変更に成功したファイルの数を返します。 |
16688 | 19768 | 各ファイルの inode 変更(change)時刻には、その時点の時刻が設定されます。 |
16689 | 19769 | 例えば、このコードはファイルが I<既に存在して> いて、ユーザーが |
16690 | 19770 | 実行しているプログラムに従っているなら、 |
16691 | Unix の touch(1) コマンドと同じ効果があります。 | |
19771 | Unix の L<touch(1)> コマンドと同じ効果があります。 | |
16692 | 19772 | |
16693 | 19773 | #!/usr/bin/perl |
16694 | $atime = $mtime = time; | |
19774 | my $atime = my $mtime = time; | |
16695 | 19775 | utime $atime, $mtime, @ARGV; |
16696 | 19776 | |
16697 | 19777 | =begin original |
16698 | 19778 | |
16699 | Since Perl 5. | |
19779 | Since Perl 5.8.0, if the first two elements of the list are | |
16700 | ||
19780 | L<C<undef>|/undef EXPR>, | |
16701 | ||
19781 | the L<utime(2)> syscall from your C library is called with a null second | |
19782 | argument. On most systems, this will set the file's access and | |
16702 | 19783 | modification times to the current time (i.e., equivalent to the example |
16703 | 19784 | above) and will work even on files you don't own provided you have write |
16704 | 19785 | permission: |
16705 | 19786 | |
16706 | 19787 | =end original |
16707 | 19788 | |
16708 | Perl 5. | |
19789 | Perl 5.8.0 から、リストの最初の二つの要素が L<C<undef>|/undef EXPR> である | |
16709 | C ライブラリの utime(2) システムコールを、秒の引数を null として | |
19790 | 場合、C ライブラリの L<utime(2)> システムコールを、秒の引数を null として | |
16710 | 19791 | 呼び出します。 |
16711 | 19792 | ほとんどのシステムでは、これによってファイルのアクセス時刻と修正時刻を |
16712 | 19793 | 現在の時刻にセットし(つまり、上記の例と等価です)、 |
16713 | 19794 | 書き込み権限があれば他のユーザーのファイルに対しても動作します。 |
16714 | 19795 | |
16715 | for $file (@ARGV) { | |
19796 | for my $file (@ARGV) { | |
16716 | utime(undef, undef, $file) | |
19797 | utime(undef, undef, $file) | |
16717 | || warn " | |
19798 | || warn "Couldn't touch $file: $!"; | |
16718 | } | |
19799 | } | |
16719 | 19800 | |
16720 | 19801 | =begin original |
16721 | 19802 | |
16722 | 19803 | Under NFS this will use the time of the NFS server, not the time of |
16723 | 19804 | the local machine. If there is a time synchronization problem, the |
16724 | 19805 | NFS server and local machine will have different times. The Unix |
16725 | touch(1) command will in fact normally use this form instead of the | |
19806 | L<touch(1)> command will in fact normally use this form instead of the | |
16726 | 19807 | one shown in the first example. |
16727 | 19808 | |
16728 | 19809 | =end original |
16729 | 19810 | |
16730 | 19811 | NFS では、これはローカルマシンの時刻ではなく、NFS サーバーの時刻が |
16731 | 19812 | 使われます。 |
16732 | 19813 | 時刻同期に問題がある場合、NFS サーバーとローカルマシンで違う時刻に |
16733 | 19814 | なっている場合があります。 |
16734 | 実際のところ、Unix の touch(1) コマンドは普通、最初の例ではなく、 | |
19815 | 実際のところ、Unix の L<touch(1)> コマンドは普通、最初の例ではなく、 | |
16735 | 19816 | この形を使います。 |
16736 | 19817 | |
16737 | 19818 | =begin original |
16738 | 19819 | |
16739 | Passing only one of the first two elements as C<undef> is | |
19820 | Passing only one of the first two elements as L<C<undef>|/undef EXPR> is | |
16740 | equivalent to passing a 0 and will not have the effect | |
19821 | equivalent to passing a 0 and will not have the effect described when | |
16741 | ||
19822 | both are L<C<undef>|/undef EXPR>. This also triggers an | |
16742 | 19823 | uninitialized warning. |
16743 | 19824 | |
16744 | 19825 | =end original |
16745 | 19826 | |
16746 | 最初の二つの要素のうち、一つだけに C<undef> を渡すと、その | |
19827 | 最初の二つの要素のうち、一つだけに L<C<undef>|/undef EXPR> を渡すと、その | |
16747 | 渡すのと等価となり、上述の、両方に C<undef> を | |
19828 | 要素は 0 を渡すのと等価となり、上述の、両方に L<C<undef>|/undef EXPR> を | |
16748 | 効果ではありません。 | |
19829 | 渡した時と同じ効果ではありません。 | |
16749 | 19830 | この場合は、未初期化の警告が出ます。 |
16750 | 19831 | |
16751 | 19832 | =begin original |
16752 | 19833 | |
16753 | On systems that support futimes(2), you may pass filehandles among the | |
19834 | On systems that support L<futimes(2)>, you may pass filehandles among the | |
16754 | files. On systems that don't support futimes(2), passing filehandles raises | |
19835 | files. On systems that don't support L<futimes(2)>, passing filehandles raises | |
16755 | 19836 | an exception. Filehandles must be passed as globs or glob references to be |
16756 | 19837 | recognized; barewords are considered filenames. |
16757 | 19838 | |
16758 | 19839 | =end original |
16759 | 19840 | |
16760 | futimes(2) に対応しているシステムでは、ファイルハンドルを引数として | |
19841 | L<futimes(2)> に対応しているシステムでは、ファイルハンドルを引数として | |
16761 | 19842 | 渡せます。 |
16762 | futimes(2) に対応していないシステムでは、ファイルハンドルを渡すと | |
19843 | L<futimes(2)> に対応していないシステムでは、ファイルハンドルを渡すと | |
16763 | 19844 | 例外が発生します。 |
16764 | 19845 | ファイルハンドルを認識させるためには、グロブまたはリファレンスとして |
16765 | 19846 | 渡されなければなりません; 裸の単語はファイル名として扱われます。 |
16766 | 19847 | |
19848 | =begin original | |
19849 | ||
19850 | Portability issues: L<perlport/utime>. | |
19851 | ||
19852 | =end original | |
19853 | ||
19854 | 移植性の問題: L<perlport/utime>。 | |
19855 | ||
16767 | 19856 | =item values HASH |
16768 | 19857 | X<values> |
16769 | 19858 | |
16770 | 19859 | =item values ARRAY |
16771 | 19860 | |
16772 | =ite | |
19861 | =for Pod::Functions return a list of the values in a hash | |
16773 | 19862 | |
16774 | 19863 | =begin original |
16775 | 19864 | |
16776 | ||
19865 | In list context, returns a list consisting of all the values of the named | |
16777 | ||
19866 | hash. In Perl 5.12 or later only, will also return a list of the values of | |
19867 | an array; prior to that release, attempting to use an array argument will | |
19868 | produce a syntax error. In scalar context, returns the number of values. | |
16778 | 19869 | |
16779 | 19870 | =end original |
16780 | 19871 | |
16781 | 指定したハッシュのすべての値 | |
19872 | リストコンテキストでは、指定したハッシュのすべての値を返します。 | |
16782 | 返します | |
19873 | Perl 5.12 以降でのみ、配列の全ての値からなるリストも返します; | |
16783 | ||
19874 | このリリースの前では、配列要素に使おうとすると文法エラーが発生します。 | |
19875 | スカラコンテキストでは、値の数を返します。 | |
16784 | 19876 | |
16785 | 19877 | =begin original |
16786 | 19878 | |
16787 | ||
19879 | Hash entries are returned in an apparently random order. The actual random | |
16788 | ||
19880 | order is specific to a given hash; the exact same series of operations | |
16789 | ||
19881 | on two hashes may result in a different order for each hash. Any insertion | |
16790 | ||
19882 | into the hash may change the order, as will any deletion, with the exception | |
16791 | ||
19883 | that the most recent key returned by L<C<each>|/each HASH> or | |
16792 | ||
19884 | L<C<keys>|/keys HASH> may be deleted without changing the order. So | |
19885 | long as a given hash is unmodified you may rely on | |
19886 | L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and | |
19887 | L<C<each>|/each HASH> to repeatedly return the same order | |
19888 | as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for | |
19889 | details on why hash order is randomized. Aside from the guarantees | |
19890 | provided here the exact details of Perl's hash algorithm and the hash | |
19891 | traversal order are subject to change in any release of Perl. Tied hashes | |
19892 | may behave differently to Perl's hashes with respect to changes in order on | |
19893 | insertion and deletion of items. | |
16793 | 19894 | |
16794 | 19895 | =end original |
16795 | 19896 | |
16796 | ||
19897 | ハッシュ要素は見かけ上、ランダムな順序で返されます。 | |
16797 | 実際のランダムな順序は | |
19898 | 実際のランダムな順序はハッシュに固有です; 二つのハッシュに全く同じ一連の | |
16798 | ||
19899 | 操作を行っても、ハッシュによって異なった順序になります。 | |
16799 | ||
19900 | ハッシュへの挿入によって順序が変わることがあります; 削除も同様ですが、 | |
16800 | ||
19901 | L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも | |
16801 | ||
19902 | 最近のキーは順序を変えることなく削除できます。 | |
16802 | ||
19903 | ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>, | |
19904 | L<C<each>|/each HASH> が繰り返し同じ順序で返すことに依存してもかまいません。 | |
19905 | なぜハッシュの順序がランダム化されているかの詳細については | |
19906 | L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。 | |
19907 | ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の | |
19908 | 正確な詳細は Perl のリリースによって変更される可能性があります。 | |
19909 | tie されたハッシュは、アイテムの挿入と削除の順序に関して Perl のハッシュと | |
19910 | 異なった振る舞いをします。 | |
16803 | 19911 | |
16804 | 19912 | =begin original |
16805 | 19913 | |
16806 | As a side effect, calling values | |
19914 | As a side effect, calling L<C<values>|/values HASH> resets the HASH or | |
16807 | iterator | |
19915 | ARRAY's internal iterator, see L<C<each>|/each HASH>. (In particular, | |
16808 | ||
19916 | calling L<C<values>|/values HASH> in void context resets the iterator | |
16809 | ||
19917 | with no other overhead. Apart from resetting the iterator, | |
16810 | 19918 | C<values @array> in list context is the same as plain C<@array>. |
16811 | We recommend that you use void context C<keys @array> for this, but | |
19919 | (We recommend that you use void context C<keys @array> for this, but | |
16812 | that | |
19920 | reasoned that taking C<values @array> out would require more | |
16813 | leaving it in.) | |
19921 | documentation than leaving it in.) | |
16814 | 19922 | |
16815 | 19923 | =end original |
16816 | 19924 | |
16817 | 副作用として、values | |
19925 | 副作用として、L<C<values>|/values HASH> を呼び出すと HASH や ARRAY の | |
16818 | リセットします; | |
19926 | 内部反復子をリセットします; L<C<each>|/each HASH> を参照してください。 | |
16819 | C< | |
19927 | (特に、L<C<values>|/values HASH> を無効コンテキストで呼び出すとその他の | |
16820 | ||
19928 | オーバーヘッドなしで反復子をリセットします。 | |
16821 | 反復子をリセットします。 | |
16822 | 19929 | 反復子をリセットするということを除けば、 |
16823 | 19930 | リストコンテキストでの C<values @array> は単なる C<@array> と同じです。 |
16824 | 19931 | この目的のためには無効コンテキストで C<keys @array> を使うことを |
16825 | 19932 | お勧めしますが、C<values @array> を取り出すにはそのままにするよりも |
16826 | 19933 | より多くの文書が必要だと判断しました。) |
16827 | 19934 | |
16828 | 19935 | =begin original |
16829 | 19936 | |
16830 | 19937 | Note that the values are not copied, which means modifying them will |
16831 | 19938 | modify the contents of the hash: |
16832 | 19939 | |
16833 | 19940 | =end original |
16834 | 19941 | |
16835 | 19942 | 値はコピーされないので、返されたリストを変更すると |
16836 | 19943 | ハッシュの中身が変更されることに注意してください。 |
16837 | 19944 | |
16838 | for (values %hash) { s/foo/bar/g } | |
19945 | for (values %hash) { s/foo/bar/g } # modifies %hash values | |
16839 | for (@hash{keys %hash}) { s/foo/bar/g } | |
19946 | for (@hash{keys %hash}) { s/foo/bar/g } # same | |
16840 | 19947 | |
16841 | 19948 | =begin original |
16842 | 19949 | |
16843 | Starting with Perl 5.14, | |
19950 | Starting with Perl 5.14, an experimental feature allowed | |
16844 | a | |
19951 | L<C<values>|/values HASH> to take a | |
16845 | ||
19952 | scalar expression. This experiment has been deemed unsuccessful, and was | |
16846 | ||
19953 | removed as of Perl 5.24. | |
16847 | 19954 | |
16848 | 19955 | =end original |
16849 | 19956 | |
16850 | Perl 5.14 から、C<values> | |
19957 | Perl 5.14 から、L<C<values>|/values HASH> がスカラ式を取ることが出来るという | |
16851 | ||
19958 | 実験的機能がありました。 | |
16852 | ||
19959 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 | |
16853 | C<values> のこの動作は高度に実験的であると考えられています。 | |
16854 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 | |
16855 | 19960 | |
16856 | | |
19961 | =begin original | |
16857 | for (values $obj->get_arrayref) { ... } | |
16858 | 19962 | |
19963 | To avoid confusing would-be users of your code who are running earlier | |
19964 | versions of Perl with mysterious syntax errors, put this sort of thing at | |
19965 | the top of your file to signal that your code will work I<only> on Perls of | |
19966 | a recent vintage: | |
19967 | ||
19968 | =end original | |
19969 | ||
19970 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な | |
19971 | 文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で | |
19972 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを | |
19973 | 書いてください: | |
19974 | ||
19975 | use 5.012; # so keys/values/each work on arrays | |
19976 | ||
16859 | 19977 | =begin original |
16860 | 19978 | |
16861 | See also C<keys>, C<each>, and | |
19979 | See also L<C<keys>|/keys HASH>, L<C<each>|/each HASH>, and | |
19980 | L<C<sort>|/sort SUBNAME LIST>. | |
16862 | 19981 | |
16863 | 19982 | =end original |
16864 | 19983 | |
16865 | C<keys>, C<each>, C<sort> も | |
19984 | L<C<keys>|/keys HASH>, L<C<each>|/each HASH>, L<C<sort>|/sort SUBNAME LIST> も | |
19985 | 参照してください。 | |
16866 | 19986 | |
16867 | 19987 | =item vec EXPR,OFFSET,BITS |
16868 | 19988 | X<vec> X<bit> X<bit vector> |
16869 | 19989 | |
19990 | =for Pod::Functions test or set particular bits in a string | |
19991 | ||
16870 | 19992 | =begin original |
16871 | 19993 | |
16872 | 19994 | Treats the string in EXPR as a bit vector made up of elements of |
16873 | 19995 | width BITS and returns the value of the element specified by OFFSET |
16874 | 19996 | as an unsigned integer. BITS therefore specifies the number of bits |
16875 | 19997 | that are reserved for each element in the bit vector. This must |
16876 | 19998 | be a power of two from 1 to 32 (or 64, if your platform supports |
16877 | 19999 | that). |
16878 | 20000 | |
16879 | 20001 | =end original |
16880 | 20002 | |
16881 | 20003 | 文字列 EXPR を BITS 幅の要素からなるビットベクターとして扱い、 |
16882 | 20004 | OFFSET で指定された要素を符号なし整数として返します。 |
16883 | 20005 | 従って、 BITS はビットベクターの中の各要素について予約されるビット数です。 |
16884 | 20006 | BIT は、1 から 32 まで(プラットホームが |
16885 | 20007 | 対応していれば 64 まで) の 2 のべき乗でなければなりません。 |
16886 | 20008 | |
16887 | 20009 | =begin original |
16888 | 20010 | |
16889 | 20011 | If BITS is 8, "elements" coincide with bytes of the input string. |
16890 | 20012 | |
16891 | 20013 | =end original |
16892 | 20014 | |
16893 | 20015 | BITS が 8 の場合、「要素」は入力文字列の各バイトと一致します。 |
16894 | 20016 | |
16895 | 20017 | =begin original |
16896 | 20018 | |
16897 | 20019 | If BITS is 16 or more, bytes of the input string are grouped into chunks |
16898 | 20020 | of size BITS/8, and each group is converted to a number as with |
16899 | pack | |
20021 | L<C<pack>|/pack TEMPLATE,LIST>/L<C<unpack>|/unpack TEMPLATE,EXPR> with | |
16900 | for BITS==64). See | |
20022 | big-endian formats C<n>/C<N> (and analogously for BITS==64). See | |
20023 | L<C<pack>|/pack TEMPLATE,LIST> for details. | |
16901 | 20024 | |
16902 | 20025 | =end original |
16903 | 20026 | |
16904 | 20027 | BITS が 16 以上の場合、入力のバイト列は BITS/8 のサイズの固まりに |
16905 | グループ化され、各グループは pack | |
20028 | グループ化され、各グループは L<C<pack>|/pack TEMPLATE,LIST>/ | |
20029 | L<C<unpack>|/unpack TEMPLATE,EXPR> のビッグエンディアン | |
16906 | 20030 | フォーマット C<n>/C<N> を用いて(BITS==64 の類似として)数値に変換されます。 |
16907 | 詳細は L< | |
20031 | 詳細は L<C<pack>|/pack TEMPLATE,LIST> を参照してください。 | |
16908 | 20032 | |
16909 | 20033 | =begin original |
16910 | 20034 | |
16911 | 20035 | If bits is 4 or less, the string is broken into bytes, then the bits |
16912 | 20036 | of each byte are broken into 8/BITS groups. Bits of a byte are |
16913 | 20037 | numbered in a little-endian-ish way, as in C<0x01>, C<0x02>, |
16914 | 20038 | C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80>. For example, |
16915 | 20039 | breaking the single input byte C<chr(0x36)> into two groups gives a list |
16916 | 20040 | C<(0x6, 0x3)>; breaking it into 4 groups gives C<(0x2, 0x1, 0x3, 0x0)>. |
16917 | 20041 | |
16918 | 20042 | =end original |
16919 | 20043 | |
16920 | 20044 | BITS が 4 以下の場合、文字列はバイトに分解され、バイトの各ビットは |
16921 | 20045 | 8/BITS 個のグループに分割されます。 |
16922 | 20046 | ビットはリトルエンディアン風に、C<0x01>, C<0x02>, |
16923 | 20047 | C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80> の順になります。 |
16924 | 20048 | 例えば、入力バイト C<chr(0x36)> を二つのグループに分割すると、 |
16925 | C<(0x6, 0x3)> になります | |
20049 | C<(0x6, 0x3)> になります; 4 つに分割すると C<(0x2, 0x1, 0x3, 0x0)> に | |
16926 | ||
20050 | なります。 | |
16927 | 20051 | |
16928 | 20052 | =begin original |
16929 | 20053 | |
16930 | C<vec> may also be assigned to, in which case | |
20054 | L<C<vec>|/vec EXPR,OFFSET,BITS> may also be assigned to, in which case | |
20055 | parentheses are needed | |
16931 | 20056 | to give the expression the correct precedence as in |
16932 | 20057 | |
16933 | 20058 | =end original |
16934 | 20059 | |
16935 | 左辺値として、代入の | |
20060 | L<C<vec>|/vec EXPR,OFFSET,BITS> は左辺値として、代入の | |
16936 | この場合、式を正しく | |
20061 | 対象にすることもできます; この場合、式を正しく | |
20062 | 先行させるために以下のように括弧が必要です: | |
16937 | 20063 | |
16938 | 20064 | vec($image, $max_x * $x + $y, 8) = 3; |
16939 | 20065 | |
16940 | 20066 | =begin original |
16941 | 20067 | |
16942 | 20068 | If the selected element is outside the string, the value 0 is returned. |
16943 | 20069 | If an element off the end of the string is written to, Perl will first |
16944 | 20070 | extend the string with sufficiently many zero bytes. It is an error |
16945 | 20071 | to try to write off the beginning of the string (i.e., negative OFFSET). |
16946 | 20072 | |
16947 | 20073 | =end original |
16948 | 20074 | |
16949 | 20075 | 選択された要素が文字列の外側だった場合、値 0 が返されます。 |
16950 | 20076 | 文字列の最後よりも後ろの要素に書き込もうとした場合、 |
16951 | 20077 | Perl はまず文字列を必要な分だけ 0 のバイトで拡張します。 |
16952 | 20078 | 文字列の先頭より前に書き込もうとした(つまり OFFSET が負の数だった) |
16953 | 20079 | 場合はエラーとなります。 |
16954 | 20080 | |
16955 | 20081 | =begin original |
16956 | 20082 | |
16957 | 20083 | If the string happens to be encoded as UTF-8 internally (and thus has |
16958 | the UTF8 flag set), this is ignored by C<vec> | |
20084 | the UTF8 flag set), this is ignored by L<C<vec>|/vec EXPR,OFFSET,BITS>, | |
20085 | and it operates on the | |
16959 | 20086 | internal byte string, not the conceptual character string, even if you |
16960 | only have characters with values less than 256. | |
20087 | only have characters with values less than 256. | |
16961 | 20088 | |
16962 | 20089 | =end original |
16963 | 20090 | |
16964 | 20091 | 文字列がなぜか内部で UTF-8 でエンコードされている場合(したがって UTF8 フラグが |
16965 | セットされている場合)、これは C<vec> では無視され、 | |
20092 | セットされている場合)、これは L<C<vec>|/vec EXPR,OFFSET,BITS> では無視され、 | |
16966 | 文字だけであったとしても、概念的な | |
20093 | たとえ値が 256 未満の文字だけであったとしても、概念的な文字列ではなく | |
16967 | ||
20094 | 内部バイト文字列で操作されます。 | |
16968 | 20095 | |
16969 | 20096 | =begin original |
16970 | 20097 | |
16971 | Strings created with C<vec> can also be | |
20098 | Strings created with L<C<vec>|/vec EXPR,OFFSET,BITS> can also be | |
20099 | manipulated with the logical | |
16972 | 20100 | operators C<|>, C<&>, C<^>, and C<~>. These operators will assume a bit |
16973 | 20101 | vector operation is desired when both operands are strings. |
16974 | 20102 | See L<perlop/"Bitwise String Operators">. |
16975 | 20103 | |
16976 | 20104 | =end original |
16977 | 20105 | |
16978 | C<vec> で作られた文字列は、論理演算子 C<|>、C<&>、 | |
20106 | L<C<vec>|/vec EXPR,OFFSET,BITS> で作られた文字列は、論理演算子 C<|>、C<&>、 | |
16979 | 扱うこともできます。 | |
20107 | C<^>, C<~> で扱うこともできます。 | |
16980 | 20108 | これらの演算子は、両方の被演算子に文字列を使うと、 |
16981 | 20109 | ビットベクター演算を行ないます。 |
16982 | 20110 | L<perlop/"Bitwise String Operators"> を参照してください。 |
16983 | 20111 | |
16984 | 20112 | =begin original |
16985 | 20113 | |
16986 | 20114 | The following code will build up an ASCII string saying C<'PerlPerlPerl'>. |
16987 | 20115 | The comments show the string after each step. Note that this code works |
16988 | 20116 | in the same way on big-endian or little-endian machines. |
16989 | 20117 | |
16990 | 20118 | =end original |
16991 | 20119 | |
16992 | 20120 | 次のコードは C<'PerlPerlPerl'> という ASCII 文字列を作成します。 |
16993 | 20121 | コメントは各行の実行後の文字列を示します。 |
16994 | 20122 | このコードはビッグエンディアンでもリトルエンディアンでも同じように |
16995 | 20123 | 動作することに注意してください。 |
16996 | 20124 | |
16997 | 20125 | my $foo = ''; |
16998 | 20126 | vec($foo, 0, 32) = 0x5065726C; # 'Perl' |
16999 | 20127 | |
17000 | 20128 | # $foo eq "Perl" eq "\x50\x65\x72\x6C", 32 bits |
17001 | 20129 | print vec($foo, 0, 8); # prints 80 == 0x50 == ord('P') |
17002 | 20130 | |
17003 | 20131 | vec($foo, 2, 16) = 0x5065; # 'PerlPe' |
17004 | 20132 | vec($foo, 3, 16) = 0x726C; # 'PerlPerl' |
17005 | 20133 | vec($foo, 8, 8) = 0x50; # 'PerlPerlP' |
17006 | 20134 | vec($foo, 9, 8) = 0x65; # 'PerlPerlPe' |
17007 | 20135 | vec($foo, 20, 4) = 2; # 'PerlPerlPe' . "\x02" |
17008 | 20136 | vec($foo, 21, 4) = 7; # 'PerlPerlPer' |
17009 | 20137 | # 'r' is "\x72" |
17010 | 20138 | vec($foo, 45, 2) = 3; # 'PerlPerlPer' . "\x0c" |
17011 | 20139 | vec($foo, 93, 1) = 1; # 'PerlPerlPer' . "\x2c" |
17012 | 20140 | vec($foo, 94, 1) = 1; # 'PerlPerlPerl' |
17013 | 20141 | # 'l' is "\x6c" |
17014 | 20142 | |
17015 | 20143 | =begin original |
17016 | 20144 | |
17017 | 20145 | To transform a bit vector into a string or list of 0's and 1's, use these: |
17018 | 20146 | |
17019 | 20147 | =end original |
17020 | 20148 | |
17021 | 20149 | ビットベクターを、0 と 1 の文字列や配列に変換するには、 |
17022 | 20150 | 以下のようにします。 |
17023 | 20151 | |
17024 | $bits = unpack("b*", $vector); | |
20152 | my $bits = unpack("b*", $vector); | |
17025 | @bits = split(//, unpack("b*", $vector)); | |
20153 | my @bits = split(//, unpack("b*", $vector)); | |
17026 | 20154 | |
17027 | 20155 | =begin original |
17028 | 20156 | |
17029 | 20157 | If you know the exact length in bits, it can be used in place of the C<*>. |
17030 | 20158 | |
17031 | 20159 | =end original |
17032 | 20160 | |
17033 | ビット長が分かっていれば、* の代わりにその長さを使うことができます。 | |
20161 | ビット長が分かっていれば、C<*> の代わりにその長さを使うことができます。 | |
17034 | 20162 | |
17035 | 20163 | =begin original |
17036 | 20164 | |
17037 | 20165 | Here is an example to illustrate how the bits actually fall in place: |
17038 | 20166 | |
17039 | 20167 | =end original |
17040 | 20168 | |
17041 | 20169 | これはビットが実際にどのような位置に入るかを図示する例です。 |
17042 | 20170 | |
17043 | | |
20171 | #!/usr/bin/perl -wl | |
17044 | 20172 | |
17045 | | |
20173 | print <<'EOT'; | |
17046 | | |
20174 | 0 1 2 3 | |
17047 | | |
20175 | unpack("V",$_) 01234567890123456789012345678901 | |
17048 | | |
20176 | ------------------------------------------------------------------ | |
17049 | | |
20177 | EOT | |
17050 | 20178 | |
17051 | | |
20179 | for $w (0..3) { | |
17052 | | |
20180 | $width = 2**$w; | |
17053 | | |
20181 | for ($shift=0; $shift < $width; ++$shift) { | |
17054 | | |
20182 | for ($off=0; $off < 32/$width; ++$off) { | |
17055 | | |
20183 | $str = pack("B*", "0"x32); | |
17056 | | |
20184 | $bits = (1<<$shift); | |
17057 | | |
20185 | vec($str, $off, $width) = $bits; | |
17058 | | |
20186 | $res = unpack("b*",$str); | |
17059 | | |
20187 | $val = unpack("V", $str); | |
17060 | | |
20188 | write; | |
17061 | | |
20189 | } | |
17062 | | |
20190 | } | |
17063 | | |
20191 | } | |
17064 | 20192 | |
17065 | | |
20193 | format STDOUT = | |
17066 | | |
20194 | vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
17067 | | |
20195 | $off, $width, $bits, $val, $res | |
17068 | | |
20196 | . | |
17069 | | |
20197 | __END__ | |
17070 | 20198 | |
17071 | 20199 | =begin original |
17072 | 20200 | |
17073 | Regardless of the machine architecture on which it runs, the | |
20201 | Regardless of the machine architecture on which it runs, the | |
17074 | 20202 | example above should print the following table: |
17075 | 20203 | |
17076 | 20204 | =end original |
17077 | 20205 | |
17078 | 20206 | 実行するマシンのアーキテクチャに関わらず、 |
17079 | 20207 | 上記の例は以下の表を出力します。 |
17080 | 20208 | |
17081 | | |
20209 | 0 1 2 3 | |
17082 | | |
20210 | unpack("V",$_) 01234567890123456789012345678901 | |
17083 | | |
20211 | ------------------------------------------------------------------ | |
17084 | | |
20212 | vec($_, 0, 1) = 1 == 1 10000000000000000000000000000000 | |
17085 | | |
20213 | vec($_, 1, 1) = 1 == 2 01000000000000000000000000000000 | |
17086 | | |
20214 | vec($_, 2, 1) = 1 == 4 00100000000000000000000000000000 | |
17087 | | |
20215 | vec($_, 3, 1) = 1 == 8 00010000000000000000000000000000 | |
17088 | | |
20216 | vec($_, 4, 1) = 1 == 16 00001000000000000000000000000000 | |
17089 | | |
20217 | vec($_, 5, 1) = 1 == 32 00000100000000000000000000000000 | |
17090 | | |
20218 | vec($_, 6, 1) = 1 == 64 00000010000000000000000000000000 | |
17091 | | |
20219 | vec($_, 7, 1) = 1 == 128 00000001000000000000000000000000 | |
17092 | | |
20220 | vec($_, 8, 1) = 1 == 256 00000000100000000000000000000000 | |
17093 | | |
20221 | vec($_, 9, 1) = 1 == 512 00000000010000000000000000000000 | |
17094 | | |
20222 | vec($_,10, 1) = 1 == 1024 00000000001000000000000000000000 | |
17095 | | |
20223 | vec($_,11, 1) = 1 == 2048 00000000000100000000000000000000 | |
17096 | | |
20224 | vec($_,12, 1) = 1 == 4096 00000000000010000000000000000000 | |
17097 | | |
20225 | vec($_,13, 1) = 1 == 8192 00000000000001000000000000000000 | |
17098 | | |
20226 | vec($_,14, 1) = 1 == 16384 00000000000000100000000000000000 | |
17099 | | |
20227 | vec($_,15, 1) = 1 == 32768 00000000000000010000000000000000 | |
17100 | | |
20228 | vec($_,16, 1) = 1 == 65536 00000000000000001000000000000000 | |
17101 | | |
20229 | vec($_,17, 1) = 1 == 131072 00000000000000000100000000000000 | |
17102 | | |
20230 | vec($_,18, 1) = 1 == 262144 00000000000000000010000000000000 | |
17103 | | |
20231 | vec($_,19, 1) = 1 == 524288 00000000000000000001000000000000 | |
17104 | | |
20232 | vec($_,20, 1) = 1 == 1048576 00000000000000000000100000000000 | |
17105 | | |
20233 | vec($_,21, 1) = 1 == 2097152 00000000000000000000010000000000 | |
17106 | | |
20234 | vec($_,22, 1) = 1 == 4194304 00000000000000000000001000000000 | |
17107 | | |
20235 | vec($_,23, 1) = 1 == 8388608 00000000000000000000000100000000 | |
17108 | | |
20236 | vec($_,24, 1) = 1 == 16777216 00000000000000000000000010000000 | |
17109 | | |
20237 | vec($_,25, 1) = 1 == 33554432 00000000000000000000000001000000 | |
17110 | | |
20238 | vec($_,26, 1) = 1 == 67108864 00000000000000000000000000100000 | |
17111 | | |
20239 | vec($_,27, 1) = 1 == 134217728 00000000000000000000000000010000 | |
17112 | | |
20240 | vec($_,28, 1) = 1 == 268435456 00000000000000000000000000001000 | |
17113 | | |
20241 | vec($_,29, 1) = 1 == 536870912 00000000000000000000000000000100 | |
17114 | | |
20242 | vec($_,30, 1) = 1 == 1073741824 00000000000000000000000000000010 | |
17115 | | |
20243 | vec($_,31, 1) = 1 == 2147483648 00000000000000000000000000000001 | |
17116 | | |
20244 | vec($_, 0, 2) = 1 == 1 10000000000000000000000000000000 | |
17117 | | |
20245 | vec($_, 1, 2) = 1 == 4 00100000000000000000000000000000 | |
17118 | | |
20246 | vec($_, 2, 2) = 1 == 16 00001000000000000000000000000000 | |
17119 | | |
20247 | vec($_, 3, 2) = 1 == 64 00000010000000000000000000000000 | |
17120 | | |
20248 | vec($_, 4, 2) = 1 == 256 00000000100000000000000000000000 | |
17121 | | |
20249 | vec($_, 5, 2) = 1 == 1024 00000000001000000000000000000000 | |
17122 | | |
20250 | vec($_, 6, 2) = 1 == 4096 00000000000010000000000000000000 | |
17123 | | |
20251 | vec($_, 7, 2) = 1 == 16384 00000000000000100000000000000000 | |
17124 | | |
20252 | vec($_, 8, 2) = 1 == 65536 00000000000000001000000000000000 | |
17125 | | |
20253 | vec($_, 9, 2) = 1 == 262144 00000000000000000010000000000000 | |
17126 | | |
20254 | vec($_,10, 2) = 1 == 1048576 00000000000000000000100000000000 | |
17127 | | |
20255 | vec($_,11, 2) = 1 == 4194304 00000000000000000000001000000000 | |
17128 | | |
20256 | vec($_,12, 2) = 1 == 16777216 00000000000000000000000010000000 | |
17129 | | |
20257 | vec($_,13, 2) = 1 == 67108864 00000000000000000000000000100000 | |
17130 | | |
20258 | vec($_,14, 2) = 1 == 268435456 00000000000000000000000000001000 | |
17131 | | |
20259 | vec($_,15, 2) = 1 == 1073741824 00000000000000000000000000000010 | |
17132 | | |
20260 | vec($_, 0, 2) = 2 == 2 01000000000000000000000000000000 | |
17133 | | |
20261 | vec($_, 1, 2) = 2 == 8 00010000000000000000000000000000 | |
17134 | | |
20262 | vec($_, 2, 2) = 2 == 32 00000100000000000000000000000000 | |
17135 | | |
20263 | vec($_, 3, 2) = 2 == 128 00000001000000000000000000000000 | |
17136 | | |
20264 | vec($_, 4, 2) = 2 == 512 00000000010000000000000000000000 | |
17137 | | |
20265 | vec($_, 5, 2) = 2 == 2048 00000000000100000000000000000000 | |
17138 | | |
20266 | vec($_, 6, 2) = 2 == 8192 00000000000001000000000000000000 | |
17139 | | |
20267 | vec($_, 7, 2) = 2 == 32768 00000000000000010000000000000000 | |
17140 | | |
20268 | vec($_, 8, 2) = 2 == 131072 00000000000000000100000000000000 | |
17141 | | |
20269 | vec($_, 9, 2) = 2 == 524288 00000000000000000001000000000000 | |
17142 | | |
20270 | vec($_,10, 2) = 2 == 2097152 00000000000000000000010000000000 | |
17143 | | |
20271 | vec($_,11, 2) = 2 == 8388608 00000000000000000000000100000000 | |
17144 | | |
20272 | vec($_,12, 2) = 2 == 33554432 00000000000000000000000001000000 | |
17145 | | |
20273 | vec($_,13, 2) = 2 == 134217728 00000000000000000000000000010000 | |
17146 | | |
20274 | vec($_,14, 2) = 2 == 536870912 00000000000000000000000000000100 | |
17147 | | |
20275 | vec($_,15, 2) = 2 == 2147483648 00000000000000000000000000000001 | |
17148 | | |
20276 | vec($_, 0, 4) = 1 == 1 10000000000000000000000000000000 | |
17149 | | |
20277 | vec($_, 1, 4) = 1 == 16 00001000000000000000000000000000 | |
17150 | | |
20278 | vec($_, 2, 4) = 1 == 256 00000000100000000000000000000000 | |
17151 | | |
20279 | vec($_, 3, 4) = 1 == 4096 00000000000010000000000000000000 | |
17152 | | |
20280 | vec($_, 4, 4) = 1 == 65536 00000000000000001000000000000000 | |
17153 | | |
20281 | vec($_, 5, 4) = 1 == 1048576 00000000000000000000100000000000 | |
17154 | | |
20282 | vec($_, 6, 4) = 1 == 16777216 00000000000000000000000010000000 | |
17155 | | |
20283 | vec($_, 7, 4) = 1 == 268435456 00000000000000000000000000001000 | |
17156 | | |
20284 | vec($_, 0, 4) = 2 == 2 01000000000000000000000000000000 | |
17157 | | |
20285 | vec($_, 1, 4) = 2 == 32 00000100000000000000000000000000 | |
17158 | | |
20286 | vec($_, 2, 4) = 2 == 512 00000000010000000000000000000000 | |
17159 | | |
20287 | vec($_, 3, 4) = 2 == 8192 00000000000001000000000000000000 | |
17160 | | |
20288 | vec($_, 4, 4) = 2 == 131072 00000000000000000100000000000000 | |
17161 | | |
20289 | vec($_, 5, 4) = 2 == 2097152 00000000000000000000010000000000 | |
17162 | | |
20290 | vec($_, 6, 4) = 2 == 33554432 00000000000000000000000001000000 | |
17163 | | |
20291 | vec($_, 7, 4) = 2 == 536870912 00000000000000000000000000000100 | |
17164 | | |
20292 | vec($_, 0, 4) = 4 == 4 00100000000000000000000000000000 | |
17165 | | |
20293 | vec($_, 1, 4) = 4 == 64 00000010000000000000000000000000 | |
17166 | | |
20294 | vec($_, 2, 4) = 4 == 1024 00000000001000000000000000000000 | |
17167 | | |
20295 | vec($_, 3, 4) = 4 == 16384 00000000000000100000000000000000 | |
17168 | | |
20296 | vec($_, 4, 4) = 4 == 262144 00000000000000000010000000000000 | |
17169 | | |
20297 | vec($_, 5, 4) = 4 == 4194304 00000000000000000000001000000000 | |
17170 | | |
20298 | vec($_, 6, 4) = 4 == 67108864 00000000000000000000000000100000 | |
17171 | | |
20299 | vec($_, 7, 4) = 4 == 1073741824 00000000000000000000000000000010 | |
17172 | | |
20300 | vec($_, 0, 4) = 8 == 8 00010000000000000000000000000000 | |
17173 | | |
20301 | vec($_, 1, 4) = 8 == 128 00000001000000000000000000000000 | |
17174 | | |
20302 | vec($_, 2, 4) = 8 == 2048 00000000000100000000000000000000 | |
17175 | | |
20303 | vec($_, 3, 4) = 8 == 32768 00000000000000010000000000000000 | |
17176 | | |
20304 | vec($_, 4, 4) = 8 == 524288 00000000000000000001000000000000 | |
17177 | | |
20305 | vec($_, 5, 4) = 8 == 8388608 00000000000000000000000100000000 | |
17178 | | |
20306 | vec($_, 6, 4) = 8 == 134217728 00000000000000000000000000010000 | |
17179 | | |
20307 | vec($_, 7, 4) = 8 == 2147483648 00000000000000000000000000000001 | |
17180 | | |
20308 | vec($_, 0, 8) = 1 == 1 10000000000000000000000000000000 | |
17181 | | |
20309 | vec($_, 1, 8) = 1 == 256 00000000100000000000000000000000 | |
17182 | | |
20310 | vec($_, 2, 8) = 1 == 65536 00000000000000001000000000000000 | |
17183 | | |
20311 | vec($_, 3, 8) = 1 == 16777216 00000000000000000000000010000000 | |
17184 | | |
20312 | vec($_, 0, 8) = 2 == 2 01000000000000000000000000000000 | |
17185 | | |
20313 | vec($_, 1, 8) = 2 == 512 00000000010000000000000000000000 | |
17186 | | |
20314 | vec($_, 2, 8) = 2 == 131072 00000000000000000100000000000000 | |
17187 | | |
20315 | vec($_, 3, 8) = 2 == 33554432 00000000000000000000000001000000 | |
17188 | | |
20316 | vec($_, 0, 8) = 4 == 4 00100000000000000000000000000000 | |
17189 | | |
20317 | vec($_, 1, 8) = 4 == 1024 00000000001000000000000000000000 | |
17190 | | |
20318 | vec($_, 2, 8) = 4 == 262144 00000000000000000010000000000000 | |
17191 | | |
20319 | vec($_, 3, 8) = 4 == 67108864 00000000000000000000000000100000 | |
17192 | | |
20320 | vec($_, 0, 8) = 8 == 8 00010000000000000000000000000000 | |
17193 | | |
20321 | vec($_, 1, 8) = 8 == 2048 00000000000100000000000000000000 | |
17194 | | |
20322 | vec($_, 2, 8) = 8 == 524288 00000000000000000001000000000000 | |
17195 | | |
20323 | vec($_, 3, 8) = 8 == 134217728 00000000000000000000000000010000 | |
17196 | | |
20324 | vec($_, 0, 8) = 16 == 16 00001000000000000000000000000000 | |
17197 | | |
20325 | vec($_, 1, 8) = 16 == 4096 00000000000010000000000000000000 | |
17198 | | |
20326 | vec($_, 2, 8) = 16 == 1048576 00000000000000000000100000000000 | |
17199 | | |
20327 | vec($_, 3, 8) = 16 == 268435456 00000000000000000000000000001000 | |
17200 | | |
20328 | vec($_, 0, 8) = 32 == 32 00000100000000000000000000000000 | |
17201 | | |
20329 | vec($_, 1, 8) = 32 == 8192 00000000000001000000000000000000 | |
17202 | | |
20330 | vec($_, 2, 8) = 32 == 2097152 00000000000000000000010000000000 | |
17203 | | |
20331 | vec($_, 3, 8) = 32 == 536870912 00000000000000000000000000000100 | |
17204 | | |
20332 | vec($_, 0, 8) = 64 == 64 00000010000000000000000000000000 | |
17205 | | |
20333 | vec($_, 1, 8) = 64 == 16384 00000000000000100000000000000000 | |
17206 | | |
20334 | vec($_, 2, 8) = 64 == 4194304 00000000000000000000001000000000 | |
17207 | | |
20335 | vec($_, 3, 8) = 64 == 1073741824 00000000000000000000000000000010 | |
17208 | | |
20336 | vec($_, 0, 8) = 128 == 128 00000001000000000000000000000000 | |
17209 | | |
20337 | vec($_, 1, 8) = 128 == 32768 00000000000000010000000000000000 | |
17210 | | |
20338 | vec($_, 2, 8) = 128 == 8388608 00000000000000000000000100000000 | |
17211 | | |
20339 | vec($_, 3, 8) = 128 == 2147483648 00000000000000000000000000000001 | |
17212 | 20340 | |
17213 | 20341 | =item wait |
17214 | 20342 | X<wait> |
17215 | 20343 | |
20344 | =for Pod::Functions wait for any child process to die | |
20345 | ||
17216 | 20346 | =begin original |
17217 | 20347 | |
17218 | Behaves like wait(2) on your system: it waits for a child | |
20348 | Behaves like L<wait(2)> on your system: it waits for a child | |
17219 | 20349 | process to terminate and returns the pid of the deceased process, or |
17220 | C<-1> if there are no child processes. The status is returned in | |
20350 | C<-1> if there are no child processes. The status is returned in | |
17221 | ||
20351 | L<C<$?>|perlvar/$?> and | |
20352 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>. | |
17222 | 20353 | Note that a return value of C<-1> could mean that child processes are |
17223 | 20354 | being automatically reaped, as described in L<perlipc>. |
17224 | 20355 | |
17225 | 20356 | =end original |
17226 | 20357 | |
17227 | wait(2) と同様に振る舞います | |
20358 | L<wait(2)> と同様に振る舞います: チャイルドプロセスが終了するのを待ち、 | |
17228 | ||
20359 | 消滅したプロセスの pid を返します; チャイルドプロセスが存在しないときには、 | |
17229 | ||
20360 | C<-1> を返します。 | |
17230 | ステータスは C<$?> | |
20361 | ステータスは L<C<$?>|perlvar/$?> と | |
20362 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に返されます。 | |
17231 | 20363 | L<perlipc> に書いているように、返り値が C<-1> の場合は子プロセスが |
17232 | 20364 | 自動的に刈り取られたことを意味するかもしれないことに注意してください。 |
17233 | 20365 | |
17234 | 20366 | =begin original |
17235 | 20367 | |
17236 | If you use wait in your handler for | |
20368 | If you use L<C<wait>|/wait> in your handler for | |
17237 | ||
20369 | L<C<$SIG{CHLD}>|perlvar/%SIG>, it may accidentally wait for the child | |
20370 | created by L<C<qx>|/qxE<sol>STRINGE<sol>> or L<C<system>|/system LIST>. | |
20371 | See L<perlipc> for details. | |
17238 | 20372 | |
17239 | 20373 | =end original |
17240 | 20374 | |
17241 | wait を $SIG{CHLD} のハンドラで使うと、誤って | |
20375 | L<C<wait>|/wait> を L<C<$SIG{CHLD}>|perlvar/%SIG> のハンドラで使うと、誤って | |
17242 | ||
20376 | L<C<qx>|/qxE<sol>STRINGE<sol>> や L<C<system>|/system LIST> によって | |
20377 | 作られた子を待つことになるかも知れません。 | |
17243 | 20378 | 詳しくは L<perlipc> を参照してください。 |
17244 | 20379 | |
20380 | =begin original | |
20381 | ||
20382 | Portability issues: L<perlport/wait>. | |
20383 | ||
20384 | =end original | |
20385 | ||
20386 | 移植性の問題: L<perlport/wait>。 | |
20387 | ||
17245 | 20388 | =item waitpid PID,FLAGS |
17246 | 20389 | X<waitpid> |
17247 | 20390 | |
20391 | =for Pod::Functions wait for a particular child process to die | |
20392 | ||
17248 | 20393 | =begin original |
17249 | 20394 | |
17250 | 20395 | Waits for a particular child process to terminate and returns the pid of |
17251 | the deceased process, or C<-1> if there is no such child process. | |
20396 | the deceased process, or C<-1> if there is no such child process. A | |
17252 | ||
20397 | non-blocking wait (with L<WNOHANG|POSIX/C<WNOHANG>> in FLAGS) can return 0 if | |
17253 | ||
20398 | there are child processes matching PID but none have terminated yet. | |
20399 | The status is returned in L<C<$?>|perlvar/$?> and | |
20400 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>. | |
17254 | 20401 | |
17255 | 20402 | =end original |
17256 | 20403 | |
17257 | 特定の | |
20404 | 特定の子プロセスが終了するのを待ち、消滅したプロセスの pid を | |
17258 | プロセス | |
20405 | 返します; 指定した子プロセスが存在しないときには、C<-1> を返します。 | |
17259 | ||
20406 | (FLAGS に L<WNOHANG|POSIX/C<WNOHANG>> を指定した) 非ブロッキング wait は、 | |
17260 | ||
20407 | PID がマッチングする子プロセスがいてもまだ終了していない場合に 0 を | |
17261 | ||
20408 | 返すことがあります。 | |
20409 | ステータスは L<C<$?>|perlvar/$?> と | |
20410 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に返されます。 | |
17262 | 20411 | |
20412 | =begin original | |
20413 | ||
20414 | A PID of C<0> indicates to wait for any child process whose process group ID is | |
20415 | equal to that of the current process. A PID of less than C<-1> indicates to | |
20416 | wait for any child process whose process group ID is equal to -PID. A PID of | |
20417 | C<-1> indicates to wait for any child process. | |
20418 | ||
20419 | =end original | |
20420 | ||
20421 | PID に C<0> を指定すると、プロセスグループ ID が現在のプロセスと同じである | |
20422 | 任意の子プロセスを wait します。 | |
20423 | PID に C<-1> 以下を指定すると、プロセスグループ ID が -PID に等しい | |
20424 | 任意の子プロセスを wait します。 | |
20425 | PID に C<-1> を指定すると任意の子プロセスを wait します。 | |
20426 | ||
20427 | =begin original | |
20428 | ||
20429 | If you say | |
20430 | ||
20431 | =end original | |
20432 | ||
20433 | 以下のようにするか | |
20434 | ||
17263 | 20435 | use POSIX ":sys_wait_h"; |
17264 | ||
20437 | my $kid; | |
17265 | 20438 | do { |
17266 | 20439 | $kid = waitpid(-1, WNOHANG); |
17267 | 20440 | } while $kid > 0; |
17268 | 20441 | |
17269 | 20442 | =begin original |
17270 | 20443 | |
17271 | ||
20444 | or | |
20445 | ||
20446 | =end original | |
20447 | ||
20448 | または | |
20449 | ||
20450 | 1 while waitpid(-1, WNOHANG) > 0; | |
20451 | ||
20452 | =begin original | |
20453 | ||
20454 | then you can do a non-blocking wait for all pending zombie processes (see | |
20455 | L<POSIX/WAIT>). | |
17272 | 20456 | Non-blocking wait is available on machines supporting either the |
17273 | waitpid(2) or wait4(2) syscalls. However, waiting for a particular | |
20457 | L<waitpid(2)> or L<wait4(2)> syscalls. However, waiting for a particular | |
17274 | 20458 | pid with FLAGS of C<0> is implemented everywhere. (Perl emulates the |
17275 | 20459 | system call by remembering the status values of processes that have |
17276 | 20460 | exited but have not been harvested by the Perl script yet.) |
17277 | 20461 | |
17278 | 20462 | =end original |
17279 | 20463 | |
17280 | 20464 | とすると、ブロックが起こらないようにして、全ての待機中ゾンビプロセスを |
17281 | wait します。 | |
20465 | wait します (L<POSIX/WAIT> を参照してください)。 | |
17282 | ブロックなしの wait は、システムコール wait_pid(2) か、 | |
20466 | ブロックなしの wait は、システムコール L<wait_pid(2)> か、 | |
17283 | システムコール wait4(2) をサポートしているマシンで利用可能です。 | |
20467 | システムコール L<wait4(2)> をサポートしているマシンで利用可能です。 | |
17284 | 20468 | しかしながら、特定の pid を C<0> の FLAGS での wait はどこでも |
17285 | 20469 | 実装されています。 |
17286 | 20470 | (exit したプロセスのステータス値を覚えておいて、Perl がシステムコールを |
17287 | 20471 | エミュレートしますが、Perl スクリプトには取り入れられていません。) |
17288 | 20472 | |
17289 | 20473 | =begin original |
17290 | 20474 | |
17291 | 20475 | Note that on some systems, a return value of C<-1> could mean that child |
17292 | 20476 | processes are being automatically reaped. See L<perlipc> for details, |
17293 | 20477 | and for other examples. |
17294 | 20478 | |
17295 | 20479 | =end original |
17296 | 20480 | |
17297 | 20481 | システムによっては、返り値が C<-1> の場合は子プロセスが自動的に |
17298 | 20482 | 刈り取られたことを意味するかもしれないことに注意してください。 |
17299 | 20483 | 詳細やその他の例については L<perlipc> を参照してください。 |
17300 | 20484 | |
20485 | =begin original | |
20486 | ||
20487 | Portability issues: L<perlport/waitpid>. | |
20488 | ||
20489 | =end original | |
20490 | ||
20491 | 移植性の問題: L<perlport/waitpid>。 | |
20492 | ||
17301 | 20493 | =item wantarray |
17302 | 20494 | X<wantarray> X<context> |
17303 | 20495 | |
20496 | =for Pod::Functions get void vs scalar vs list context of current subroutine call | |
20497 | ||
17304 | 20498 | =begin original |
17305 | 20499 | |
17306 | 20500 | Returns true if the context of the currently executing subroutine or |
17307 | C<eval> is looking for a list value. Returns false if the | |
20501 | L<C<eval>|/eval EXPR> is looking for a list value. Returns false if the | |
20502 | context is | |
17308 | 20503 | looking for a scalar. Returns the undefined value if the context is |
17309 | 20504 | looking for no value (void context). |
17310 | 20505 | |
17311 | 20506 | =end original |
17312 | 20507 | |
17313 | 現在実行中のサブルーチンか eval | |
20508 | 現在実行中のサブルーチンか L<C<eval>|/eval EXPR> ブロックのコンテキストが、 | |
17314 | 要求するものであれば、真を返します。 | |
20509 | リスト値を要求するものであれば、真を返します。 | |
17315 | 20510 | スカラを要求するコンテキストであれば、偽を返します。 |
17316 | 20511 | 何も値を要求しない(無効コンテキスト)場合は未定義値を返します。 |
17317 | 20512 | |
17318 | 20513 | return unless defined wantarray; # don't bother doing more |
17319 | 20514 | my @a = complex_calculation(); |
17320 | 20515 | return wantarray ? @a : "@a"; |
17321 | 20516 | |
17322 | 20517 | =begin original |
17323 | 20518 | |
17324 | C<wantarray | |
20519 | L<C<wantarray>|/wantarray>'s result is unspecified in the top level of a file, | |
17325 | 20520 | in a C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT> or C<END> block, or |
17326 | 20521 | in a C<DESTROY> method. |
17327 | 20522 | |
17328 | 20523 | =end original |
17329 | 20524 | |
17330 | 20525 | ファイルのトップレベル、C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT>, C<END> |
17331 | ブロック内、C<DESTROY> メソッド内では C<wantarray | |
20526 | ブロック内、C<DESTROY> メソッド内では L<C<wantarray>|/wantarray> の結果は | |
20527 | 未定義です。 | |
17332 | 20528 | |
17333 | 20529 | =begin original |
17334 | 20530 | |
17335 | 20531 | This function should have been named wantlist() instead. |
17336 | 20532 | |
17337 | 20533 | =end original |
17338 | 20534 | |
17339 | 20535 | この関数は wantlist() という名前にするべきでした。 |
17340 | 20536 | |
17341 | 20537 | =item warn LIST |
17342 | 20538 | X<warn> X<warning> X<STDERR> |
17343 | 20539 | |
20540 | =for Pod::Functions print debugging info | |
20541 | ||
17344 | 20542 | =begin original |
17345 | 20543 | |
17346 | 20544 | Prints the value of LIST to STDERR. If the last element of LIST does |
17347 | not end in a newline, it appends the same file/line number text as | |
20545 | not end in a newline, it appends the same file/line number text as | |
17348 | does. | |
20546 | L<C<die>|/die LIST> does. | |
17349 | 20547 | |
17350 | 20548 | =end original |
17351 | 20549 | |
17352 | 20550 | LIST の値を STDERR に出力します。 |
17353 | LIST の最後の要素が改行で終わっていない場合、C<die> が行うのと | |
20551 | LIST の最後の要素が改行で終わっていない場合、L<C<die>|/die LIST> が行うのと | |
17354 | ファイル/行番号のテキストが追加されます。 | |
20552 | 同様のファイル/行番号のテキストが追加されます。 | |
17355 | 20553 | |
17356 | 20554 | =begin original |
17357 | 20555 | |
17358 | If the output is empty and C<$@> already contains a value | |
20556 | If the output is empty and L<C<$@>|perlvar/$@> already contains a value | |
17359 | previous eval) that value is used after appending | |
20557 | (typically from a previous eval) that value is used after appending | |
17360 | to C<$@>. This is useful for staying | |
20558 | C<"\t...caught"> to L<C<$@>|perlvar/$@>. This is useful for staying | |
17361 | C<die>. | |
20559 | almost, but not entirely similar to L<C<die>|/die LIST>. | |
17362 | 20560 | |
17363 | 20561 | =end original |
17364 | 20562 | |
17365 | 出力が空かつ、(典型的には以前の eval によって) C<$@> に既に値が | |
20563 | 出力が空かつ、(典型的には以前の eval によって) L<C<$@>|perlvar/$@> に既に値が | |
17366 | 場合、C<$@> に C<"\t...caught"> を追加した値が | |
20564 | 入っている場合、L<C<$@>|perlvar/$@> に C<"\t...caught"> を追加した値が | |
20565 | 用いられます。 | |
17367 | 20566 | これはほとんどそのままにするときに便利ですが、 |
17368 | C<die> と全体的に似ているわけではありません。 | |
20567 | L<C<die>|/die LIST> と全体的に似ているわけではありません。 | |
17369 | 20568 | |
17370 | 20569 | =begin original |
17371 | 20570 | |
17372 | If C<$@> is empty then the string | |
20571 | If L<C<$@>|perlvar/$@> is empty, then the string | |
20572 | C<"Warning: Something's wrong"> is used. | |
17373 | 20573 | |
17374 | 20574 | =end original |
17375 | 20575 | |
17376 | C<$@> が空の場合は、C<"Warning: Something's wrong"> という | |
20576 | L<C<$@>|perlvar/$@> が空の場合は、C<"Warning: Something's wrong"> という | |
17377 | 使われます。 | |
20577 | 文字列が使われます。 | |
17378 | 20578 | |
17379 | 20579 | =begin original |
17380 | 20580 | |
17381 | No message is printed if there is a C<$SIG{__WARN__}> | |
20581 | No message is printed if there is a L<C<$SIG{__WARN__}>|perlvar/%SIG> | |
20582 | handler | |
17382 | 20583 | installed. It is the handler's responsibility to deal with the message |
17383 | as it sees fit (like, for instance, converting it into a | |
20584 | as it sees fit (like, for instance, converting it into a | |
20585 | L<C<die>|/die LIST>). Most | |
17384 | 20586 | handlers must therefore arrange to actually display the |
17385 | warnings that they are not prepared to deal with, by calling | |
20587 | warnings that they are not prepared to deal with, by calling | |
20588 | L<C<warn>|/warn LIST> | |
17386 | 20589 | again in the handler. Note that this is quite safe and will not |
17387 | 20590 | produce an endless loop, since C<__WARN__> hooks are not called from |
17388 | 20591 | inside one. |
17389 | 20592 | |
17390 | 20593 | =end original |
17391 | 20594 | |
17392 | C<$SIG{__WARN__}> ハンドラが設定されている場合は何の | |
20595 | L<C<$SIG{__WARN__}>|perlvar/%SIG> ハンドラが設定されている場合は何の | |
17393 | 表示されません。 | |
20596 | メッセージも表示されません。 | |
17394 | メッセージをどう扱うか(例えば C<die> に変換するか)はハンドラの | |
20597 | メッセージをどう扱うか(例えば L<C<die>|/die LIST> に変換するか)はハンドラの | |
17395 | 20598 | 責任ということです。 |
17396 | 20599 | 従ってほとんどのハンドラは、扱おうと準備していない警告を表示するために、 |
17397 | ハンドラの中で C<warn> を再び呼び出します。 | |
20600 | ハンドラの中で L<C<warn>|/warn LIST> を再び呼び出します。 | |
17398 | 20601 | C<__WARN__> フックはハンドラ内では呼び出されないので、これは十分安全で、 |
17399 | 20602 | 無限ループを引き起こすことはないということに注意してください。 |
17400 | 20603 | |
17401 | 20604 | =begin original |
17402 | 20605 | |
17403 | 20606 | You will find this behavior is slightly different from that of |
17404 | C<$SIG{__DIE__}> handlers (which don't suppress the | |
20607 | L<C<$SIG{__DIE__}>|perlvar/%SIG> handlers (which don't suppress the | |
17405 | instead call C<die> again to change | |
20608 | error text, but can instead call L<C<die>|/die LIST> again to change | |
20609 | it). | |
17406 | 20610 | |
17407 | 20611 | =end original |
17408 | 20612 | |
17409 | この振る舞いは C<$SIG{__DIE__}> ハンドラ(エラーテキストは | |
20613 | この振る舞いは L<C<$SIG{__DIE__}>|perlvar/%SIG> ハンドラ(エラーテキストは | |
17410 | 代わりに C<die> をもう一度呼び出すことで | |
20614 | 削除しませんが、代わりに L<C<die>|/die LIST> をもう一度呼び出すことで | |
17411 | 少し違うことに気付くことでしょう。 | |
20615 | 変更できます)とは少し違うことに気付くことでしょう。 | |
17412 | 20616 | |
17413 | 20617 | =begin original |
17414 | 20618 | |
17415 | 20619 | Using a C<__WARN__> handler provides a powerful way to silence all |
17416 | 20620 | warnings (even the so-called mandatory ones). An example: |
17417 | 20621 | |
17418 | 20622 | =end original |
17419 | 20623 | |
17420 | 20624 | C<__WARN__> ハンドラを使うと、(いわゆる必須のものを含む)全ての |
17421 | 20625 | 警告を黙らせる強力な手段となります。 |
17422 | 20626 | 例: |
17423 | 20627 | |
17424 | 20628 | # wipe out *all* compile-time warnings |
17425 | 20629 | BEGIN { $SIG{'__WARN__'} = sub { warn $_[0] if $DOWARN } } |
17426 | 20630 | my $foo = 10; |
17427 | 20631 | my $foo = 20; # no warning about duplicate my $foo, |
17428 | 20632 | # but hey, you asked for it! |
17429 | 20633 | # no compile-time or run-time warnings before here |
17430 | 20634 | $DOWARN = 1; |
17431 | 20635 | |
17432 | 20636 | # run-time warnings enabled after here |
17433 | 20637 | warn "\$foo is alive and $foo!"; # does show up |
17434 | 20638 | |
17435 | 20639 | =begin original |
17436 | 20640 | |
17437 | See L<perlvar> for details on setting C<%SIG> entries | |
20641 | See L<perlvar> for details on setting L<C<%SIG>|perlvar/%SIG> entries | |
17438 | ||
20642 | and for more | |
17439 | ||
20643 | examples. See the L<Carp> module for other kinds of warnings using its | |
20644 | C<carp> and C<cluck> functions. | |
17440 | 20645 | |
17441 | 20646 | =end original |
17442 | 20647 | |
17443 | C<%SIG> エントリのセットに関する詳細とさらなる例に関しては | |
20648 | L<C<%SIG>|perlvar/%SIG> エントリのセットに関する詳細とさらなる例に関しては | |
17444 | L<perlvar> を参照して | |
20649 | L<perlvar> を参照してください。 | |
17445 | carp | |
20650 | C<carp> 関数と C<cluck> 関数を用いた警告の方法に関しては | |
17446 | Carp モジュールを参照して | |
20651 | L<Carp> モジュールを参照してください。 | |
17447 | 20652 | |
17448 | =item when EXPR BLOCK | |
17449 | X<when> | |
17450 | ||
17451 | =item when BLOCK | |
17452 | ||
17453 | =begin original | |
17454 | ||
17455 | C<when> is analogous to the C<case> keyword in other languages. Used with a | |
17456 | C<foreach> loop or the experimental C<given> block, C<when> can be used in | |
17457 | Perl to implement C<switch>/C<case> like statements. Available as a | |
17458 | statement after Perl 5.10 and as a statement modifier after 5.14. | |
17459 | Here are three examples: | |
17460 | ||
17461 | =end original | |
17462 | ||
17463 | C<when> は他の言語での C<case> キーワードと似ています。 | |
17464 | C<foreach> ループか実験的な C<given> で使って、C<when> は Perl で | |
17465 | C<switch>/C<case> 風の文を実装するのに使われます。 | |
17466 | 文としては Perl 5.10 から利用可能で、文修飾子としては 5.14 から | |
17467 | 利用可能です。 | |
17468 | 以下に三つ例を示します: | |
17469 | ||
17470 | use v5.10; | |
17471 | foreach (@fruits) { | |
17472 | when (/apples?/) { | |
17473 | say "I like apples." | |
17474 | } | |
17475 | when (/oranges?/) { | |
17476 | say "I don't like oranges." | |
17477 | } | |
17478 | default { | |
17479 | say "I don't like anything" | |
17480 | } | |
17481 | } | |
17482 | ||
17483 | # require 5.14 for when as statement modifier | |
17484 | use v5.14; | |
17485 | foreach (@fruits) { | |
17486 | say "I like apples." when /apples?/; | |
17487 | say "I don't like oranges." when /oranges?; | |
17488 | default { say "I don't like anything" } | |
17489 | } | |
17490 | ||
17491 | use v5.10; | |
17492 | given ($fruit) { | |
17493 | when (/apples?/) { | |
17494 | say "I like apples." | |
17495 | } | |
17496 | when (/oranges?/) { | |
17497 | say "I don't like oranges." | |
17498 | } | |
17499 | default { | |
17500 | say "I don't like anything" | |
17501 | } | |
17502 | } | |
17503 | ||
17504 | =begin original | |
17505 | ||
17506 | See L<perlsyn/"Switch statements"> for detailed information. | |
17507 | ||
17508 | =end original | |
17509 | ||
17510 | 詳しい情報については L<perlsyn/"Switch statements"> を参照してください。 | |
17511 | ||
17512 | 20653 | =item write FILEHANDLE |
17513 | 20654 | X<write> |
17514 | 20655 | |
17515 | 20656 | =item write EXPR |
17516 | 20657 | |
17517 | 20658 | =item write |
17518 | 20659 | |
20660 | =for Pod::Functions print a picture record | |
20661 | ||
17519 | 20662 | =begin original |
17520 | 20663 | |
17521 | 20664 | Writes a formatted record (possibly multi-line) to the specified FILEHANDLE, |
17522 | 20665 | using the format associated with that file. By default the format for |
17523 | 20666 | a file is the one having the same name as the filehandle, but the |
17524 | format for the current output channel (see the | |
20667 | format for the current output channel (see the | |
17525 | e | |
20668 | L<C<select>|/select FILEHANDLE> function) may be set explicitly by | |
20669 | assigning the name of the format to the L<C<$~>|perlvar/$~> variable. | |
17526 | 20670 | |
17527 | 20671 | =end original |
17528 | 20672 | |
17529 | 20673 | 指定された FILEHANDLE に対して、そのファイルに対応させた |
17530 | 20674 | フォーマットを使って、(複数行の場合もある) 整形された |
17531 | 20675 | レコードを書き出します。 |
17532 | 20676 | デフォルトでは、ファイルに対応するフォーマットは、ファイルハンドルと |
17533 | 同じ名前のものですが、その時点の出力チャネル | |
20677 | 同じ名前のものですが、その時点の出力チャネル | |
17534 | ||
20678 | (L<C<select>|/select FILEHANDLE> 関数の項を | |
17535 | ||
20679 | 参照してください) のフォーマットは、その名前を明示的に変数 | |
20680 | L<C<$~>|perlvar/$~> に代入することで、変更が可能です。 | |
17536 | 20681 | |
17537 | 20682 | =begin original |
17538 | 20683 | |
17539 | 20684 | Top of form processing is handled automatically: if there is insufficient |
17540 | 20685 | room on the current page for the formatted record, the page is advanced by |
17541 | writing a form feed | |
20686 | writing a form feed and a special top-of-page | |
20687 | format is used to format the new | |
17542 | 20688 | page header before the record is written. By default, the top-of-page |
17543 | format is the name of the filehandle with | |
20689 | format is the name of the filehandle with C<_TOP> appended, or C<top> | |
20690 | in the current package if the former does not exist. This would be a | |
17544 | 20691 | problem with autovivified filehandles, but it may be dynamically set to the |
17545 | format of your choice by assigning the name to the C<$^> | |
20692 | format of your choice by assigning the name to the L<C<$^>|perlvar/$^> | |
17546 | that filehandle is selected. The number of lines | |
20693 | variable while that filehandle is selected. The number of lines | |
17547 | page is in variable C<$->, which | |
20694 | remaining on the current page is in variable L<C<$->|perlvar/$->, which | |
20695 | can be set to C<0> to force a new page. | |
17548 | 20696 | |
17549 | 20697 | =end original |
17550 | 20698 | |
17551 | ページの先頭の処理は、自動的に行なわれます | |
20699 | ページの先頭の処理は、自動的に行なわれます: 現在のページに整形された | |
17552 | ||
20700 | レコードを出力するだけのスペースがない場合には、改ページを行なってページを | |
17553 | ||
20701 | 進め、新しいページヘッダを整形するため、ページ先頭フォーマットが使われ、 | |
17554 | ||
20702 | その後でレコードが書かれます。 | |
17555 | 20703 | デフォルトでは、ページ先頭フォーマットは、ファイルハンドルの名前に |
17556 | ||
20704 | C<_TOP> をつなげたものか、前者が存在しないなら、現在のパッケージの | |
20705 | C<top> です。 | |
17557 | 20706 | これは自動有効化されたファイルハンドルで問題になる可能性がありますが、 |
17558 | 20707 | ファイルハンドルが選択されている間に、 |
17559 | 変数 C<$^> に名前を設定すれば、動的にフォーマットを | |
20708 | 変数 L<C<$^>|perlvar/$^> に名前を設定すれば、動的にフォーマットを | |
17560 | 20709 | 変更することができます。 |
17561 | そのページの残り行数は、変数 C<$-> に入っており、この変数を | |
20710 | そのページの残り行数は、変数 L<C<$->|perlvar/$-> に入っており、この変数を | |
17562 | 設定することで、強制的に改ページを行なうことができます。 | |
20711 | C<0> に設定することで、強制的に改ページを行なうことができます。 | |
17563 | 20712 | |
17564 | 20713 | =begin original |
17565 | 20714 | |
17566 | 20715 | If FILEHANDLE is unspecified, output goes to the current default output |
17567 | 20716 | channel, which starts out as STDOUT but may be changed by the |
17568 | C<select> operator. If the FILEHANDLE is an EXPR, | |
20717 | L<C<select>|/select FILEHANDLE> operator. If the FILEHANDLE is an EXPR, | |
20718 | then the expression | |
17569 | 20719 | is evaluated and the resulting string is used to look up the name of |
17570 | 20720 | the FILEHANDLE at run time. For more on formats, see L<perlform>. |
17571 | 20721 | |
17572 | 20722 | =end original |
17573 | 20723 | |
17574 | FILEHANDLE を指定しないと、出力はその時点のデフォルト | |
20724 | FILEHANDLE を指定しないと、出力はその時点のデフォルト出力チャネルに対して | |
17575 | ||
20725 | 行なわれます; これは、スクリプトの開始時点では STDOUT ですが、 | |
17576 | ||
20726 | L<C<select>|/select FILEHANDLE> 演算子で変更することができます。 | |
17577 | 変更することができます。 | |
17578 | 20727 | FILEHANDLE が EXPR ならば、式が評価され、その結果の文字列が |
17579 | 20728 | 実行時に FILEHANDLE の名前として見られます。 |
17580 | 20729 | フォーマットについて、さらには、L<perlform> を参照してください。 |
17581 | 20730 | |
17582 | 20731 | =begin original |
17583 | 20732 | |
17584 | Note that write is I<not> the opposite of | |
20733 | Note that write is I<not> the opposite of | |
20734 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>. Unfortunately. | |
17585 | 20735 | |
17586 | 20736 | =end original |
17587 | 20737 | |
17588 | ||
20738 | write は L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> の | |
17589 | I<ではありません>。 | |
20739 | 反対のことをするもの I<ではありません>。 | |
20740 | 残念ながら。 | |
17590 | 20741 | |
17591 | 20742 | =item y/// |
17592 | 20743 | |
20744 | =for Pod::Functions transliterate a string | |
20745 | ||
17593 | 20746 | =begin original |
17594 | 20747 | |
17595 | The transliteration operator. Same as | |
20748 | The transliteration operator. Same as | |
17596 | L< | |
20749 | L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>>. See | |
20750 | L<perlop/"Quote-Like Operators">. | |
17597 | 20751 | |
17598 | 20752 | =end original |
17599 | 20753 | |
17600 | 20754 | 文字変換演算子です。 |
17601 | C<tr/ | |
20755 | L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>> と同じです。 | |
17602 | L<perlop/"Quote | |
20756 | L<perlop/"Quote-Like Operators"> を参照してください。 | |
17603 | 20757 | |
17604 | 20758 | =back |
17605 | 20759 | |
20760 | =head2 Non-function Keywords by Cross-reference | |
20761 | ||
20762 | =head3 perldata | |
20763 | ||
20764 | =over | |
20765 | ||
20766 | =item __DATA__ | |
20767 | ||
20768 | =item __END__ | |
20769 | ||
20770 | =begin original | |
20771 | ||
20772 | These keywords are documented in L<perldata/"Special Literals">. | |
20773 | ||
20774 | =end original | |
20775 | ||
20776 | これらのキーワードは L<perldata/"Special Literals"> で文書化されています。 | |
20777 | ||
20778 | =back | |
20779 | ||
20780 | =head3 perlmod | |
20781 | ||
20782 | =over | |
20783 | ||
20784 | =item BEGIN | |
20785 | ||
20786 | =item CHECK | |
20787 | ||
20788 | =item END | |
20789 | ||
20790 | =item INIT | |
20791 | ||
20792 | =item UNITCHECK | |
20793 | ||
20794 | =begin original | |
20795 | ||
20796 | These compile phase keywords are documented in L<perlmod/"BEGIN, UNITCHECK, CHECK, INIT and END">. | |
20797 | ||
20798 | =end original | |
20799 | ||
20800 | これらのコンパイルフェーズキーワードは | |
20801 | L<perlmod/"BEGIN, UNITCHECK, CHECK, INIT and END"> で文書化されています。 | |
20802 | ||
20803 | =back | |
20804 | ||
20805 | =head3 perlobj | |
20806 | ||
20807 | =over | |
20808 | ||
20809 | =item DESTROY | |
20810 | ||
20811 | =begin original | |
20812 | ||
20813 | This method keyword is documented in L<perlobj/"Destructors">. | |
20814 | ||
20815 | =end original | |
20816 | ||
20817 | このメソッドキーワードは L<perlobj/"Destructors"> で文書化されています。 | |
20818 | ||
20819 | =back | |
20820 | ||
20821 | =head3 perlop | |
20822 | ||
20823 | =over | |
20824 | ||
20825 | =item and | |
20826 | ||
20827 | =item cmp | |
20828 | ||
20829 | =item eq | |
20830 | ||
20831 | =item ge | |
20832 | ||
20833 | =item gt | |
20834 | ||
20835 | =item le | |
20836 | ||
20837 | =item lt | |
20838 | ||
20839 | =item ne | |
20840 | ||
20841 | =item not | |
20842 | ||
20843 | =item or | |
20844 | ||
20845 | =item x | |
20846 | ||
20847 | =item xor | |
20848 | ||
20849 | =begin original | |
20850 | ||
20851 | These operators are documented in L<perlop>. | |
20852 | ||
20853 | =end original | |
20854 | ||
20855 | これらの演算子は L<perlop> で文書化されています。 | |
20856 | ||
20857 | =back | |
20858 | ||
20859 | =head3 perlsub | |
20860 | ||
20861 | =over | |
20862 | ||
20863 | =item AUTOLOAD | |
20864 | ||
20865 | =begin original | |
20866 | ||
20867 | This keyword is documented in L<perlsub/"Autoloading">. | |
20868 | ||
20869 | =end original | |
20870 | ||
20871 | このキーワードは L<perlsub/"Autoloading"> で文書化されています。 | |
20872 | ||
20873 | =back | |
20874 | ||
20875 | =head3 perlsyn | |
20876 | ||
20877 | =over | |
20878 | ||
20879 | =item else | |
20880 | ||
20881 | =item elsif | |
20882 | ||
20883 | =item for | |
20884 | ||
20885 | =item foreach | |
20886 | ||
20887 | =item if | |
20888 | ||
20889 | =item unless | |
20890 | ||
20891 | =item until | |
20892 | ||
20893 | =item while | |
20894 | ||
20895 | =begin original | |
20896 | ||
20897 | These flow-control keywords are documented in L<perlsyn/"Compound Statements">. | |
20898 | ||
20899 | =end original | |
20900 | ||
20901 | これらのフロー制御キーワードは L<perlsyn/"Compound Statements"> で | |
20902 | 文書化されています。 | |
20903 | ||
20904 | =item elseif | |
20905 | ||
20906 | =begin original | |
20907 | ||
20908 | The "else if" keyword is spelled C<elsif> in Perl. There's no C<elif> | |
20909 | or C<else if> either. It does parse C<elseif>, but only to warn you | |
20910 | about not using it. | |
20911 | ||
20912 | =end original | |
20913 | ||
20914 | "else if" キーワードは Perl では C<elsif> と綴ります。 | |
20915 | C<elif> や C<else if> はありません。 | |
20916 | C<elseif> はパースされますが、使わないように警告するためだけです。 | |
20917 | ||
20918 | =begin original | |
20919 | ||
20920 | See the documentation for flow-control keywords in L<perlsyn/"Compound | |
20921 | Statements">. | |
20922 | ||
20923 | =end original | |
20924 | ||
20925 | L<perlsyn/"Compound Statements"> のフロー制御キーワードに関する文章を | |
20926 | 参照してください。 | |
20927 | ||
20928 | =back | |
20929 | ||
20930 | =over | |
20931 | ||
20932 | =item default | |
20933 | ||
20934 | =item given | |
20935 | ||
20936 | =item when | |
20937 | ||
20938 | =begin original | |
20939 | ||
20940 | These flow-control keywords related to the experimental switch feature are | |
20941 | documented in L<perlsyn/"Switch Statements">. | |
20942 | ||
20943 | =end original | |
20944 | ||
20945 | これらの実験的な switch 機能に関連するフロー制御キーワードは | |
20946 | L<perlsyn/"Switch Statements"> で文書化されています。 | |
20947 | ||
20948 | =back | |
20949 | ||
20950 | =cut | |
20951 | ||
17606 | 20952 | =begin meta |
17607 | 20953 | |
17608 | 20954 | Translate: 吉村 寿人 <JAE00534@niftyserve.or.jp> |
17609 | 20955 | Update: SHIRAKATA Kentaro <argrath@ub32.org> (5.6.1-) |
17610 | 20956 | Status: completed |
17611 | 20957 | |
17612 | 20958 | =end meta |
17613 | ||
17614 | =cut |